staging/rdma/hfi1: Support query gid in rdmavt
[linux-2.6-block.git] / drivers / staging / rdma / hfi1 / mad.c
index 4f5dbd14b5de8a689f84caa8432a3d77357d611e..6976f93bd36f16de62dc88428d5763eb98b559b9 100644 (file)
@@ -5,7 +5,7 @@
  *
  * GPL LICENSE SUMMARY
  *
- * Copyright(c) 2015 Intel Corporation.
+ * Copyright(c) 2015, 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of version 2 of the GNU General Public License as
@@ -18,7 +18,7 @@
  *
  * BSD LICENSE
  *
- * Copyright(c) 2015 Intel Corporation.
+ * Copyright(c) 2015, 2016 Intel Corporation.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -91,7 +91,7 @@ static void send_trap(struct hfi1_ibport *ibp, void *data, unsigned len)
        int pkey_idx;
        u32 qpn = ppd_from_ibp(ibp)->sm_trap_qp;
 
-       agent = ibp->send_agent;
+       agent = ibp->rvp.send_agent;
        if (!agent)
                return;
 
@@ -100,7 +100,8 @@ static void send_trap(struct hfi1_ibport *ibp, void *data, unsigned len)
                return;
 
        /* o14-2 */
-       if (ibp->trap_timeout && time_before(jiffies, ibp->trap_timeout))
+       if (ibp->rvp.trap_timeout && time_before(jiffies,
+                                                ibp->rvp.trap_timeout))
                return;
 
        pkey_idx = hfi1_lookup_pkey_idx(ibp, LIM_MGMT_P_KEY);
@@ -121,42 +122,42 @@ static void send_trap(struct hfi1_ibport *ibp, void *data, unsigned len)
        smp->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
        smp->class_version = OPA_SMI_CLASS_VERSION;
        smp->method = IB_MGMT_METHOD_TRAP;
-       ibp->tid++;
-       smp->tid = cpu_to_be64(ibp->tid);
+       ibp->rvp.tid++;
+       smp->tid = cpu_to_be64(ibp->rvp.tid);
        smp->attr_id = IB_SMP_ATTR_NOTICE;
        /* o14-1: smp->mkey = 0; */
        memcpy(smp->route.lid.data, data, len);
 
-       spin_lock_irqsave(&ibp->lock, flags);
-       if (!ibp->sm_ah) {
-               if (ibp->sm_lid != be16_to_cpu(IB_LID_PERMISSIVE)) {
+       spin_lock_irqsave(&ibp->rvp.lock, flags);
+       if (!ibp->rvp.sm_ah) {
+               if (ibp->rvp.sm_lid != be16_to_cpu(IB_LID_PERMISSIVE)) {
                        struct ib_ah *ah;
 
-                       ah = hfi1_create_qp0_ah(ibp, ibp->sm_lid);
+                       ah = hfi1_create_qp0_ah(ibp, ibp->rvp.sm_lid);
                        if (IS_ERR(ah))
                                ret = PTR_ERR(ah);
                        else {
                                send_buf->ah = ah;
-                               ibp->sm_ah = to_iah(ah);
+                               ibp->rvp.sm_ah = ibah_to_rvtah(ah);
                                ret = 0;
                        }
                } else
                        ret = -EINVAL;
        } else {
-               send_buf->ah = &ibp->sm_ah->ibah;
+               send_buf->ah = &ibp->rvp.sm_ah->ibah;
                ret = 0;
        }
-       spin_unlock_irqrestore(&ibp->lock, flags);
+       spin_unlock_irqrestore(&ibp->rvp.lock, flags);
 
        if (!ret)
                ret = ib_post_send_mad(send_buf, NULL);
        if (!ret) {
                /* 4.096 usec. */
-               timeout = (4096 * (1UL << ibp->subnet_timeout)) / 1000;
-               ibp->trap_timeout = jiffies + usecs_to_jiffies(timeout);
+               timeout = (4096 * (1UL << ibp->rvp.subnet_timeout)) / 1000;
+               ibp->rvp.trap_timeout = jiffies + usecs_to_jiffies(timeout);
        } else {
                ib_free_send_mad(send_buf);
-               ibp->trap_timeout = 0;
+               ibp->rvp.trap_timeout = 0;
        }
 }
 
@@ -174,10 +175,10 @@ void hfi1_bad_pqkey(struct hfi1_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
        memset(&data, 0, sizeof(data));
 
        if (trap_num == OPA_TRAP_BAD_P_KEY)
-               ibp->pkey_violations++;
+               ibp->rvp.pkey_violations++;
        else
-               ibp->qkey_violations++;
-       ibp->n_pkt_drops++;
+               ibp->rvp.qkey_violations++;
+       ibp->rvp.n_pkt_drops++;
 
        /* Send violation trap */
        data.generic_type = IB_NOTICE_TYPE_SECURITY;
@@ -245,7 +246,7 @@ void hfi1_cap_mask_chg(struct hfi1_ibport *ibp)
        data.trap_num = OPA_TRAP_CHANGE_CAPABILITY;
        data.issuer_lid = cpu_to_be32(lid);
        data.ntc_144.lid = data.issuer_lid;
-       data.ntc_144.new_cap_mask = cpu_to_be32(ibp->port_cap_flags);
+       data.ntc_144.new_cap_mask = cpu_to_be32(ibp->rvp.port_cap_flags);
 
        send_trap(ibp, &data, sizeof(data));
 }
@@ -407,37 +408,38 @@ static int check_mkey(struct hfi1_ibport *ibp, struct ib_mad_hdr *mad,
        int ret = 0;
 
        /* Is the mkey in the process of expiring? */
-       if (ibp->mkey_lease_timeout &&
-           time_after_eq(jiffies, ibp->mkey_lease_timeout)) {
+       if (ibp->rvp.mkey_lease_timeout &&
+           time_after_eq(jiffies, ibp->rvp.mkey_lease_timeout)) {
                /* Clear timeout and mkey protection field. */
-               ibp->mkey_lease_timeout = 0;
-               ibp->mkeyprot = 0;
+               ibp->rvp.mkey_lease_timeout = 0;
+               ibp->rvp.mkeyprot = 0;
        }
 
-       if ((mad_flags & IB_MAD_IGNORE_MKEY) ||  ibp->mkey == 0 ||
-           ibp->mkey == mkey)
+       if ((mad_flags & IB_MAD_IGNORE_MKEY) ||  ibp->rvp.mkey == 0 ||
+           ibp->rvp.mkey == mkey)
                valid_mkey = 1;
 
        /* Unset lease timeout on any valid Get/Set/TrapRepress */
-       if (valid_mkey && ibp->mkey_lease_timeout &&
+       if (valid_mkey && ibp->rvp.mkey_lease_timeout &&
            (mad->method == IB_MGMT_METHOD_GET ||
             mad->method == IB_MGMT_METHOD_SET ||
             mad->method == IB_MGMT_METHOD_TRAP_REPRESS))
-               ibp->mkey_lease_timeout = 0;
+               ibp->rvp.mkey_lease_timeout = 0;
 
        if (!valid_mkey) {
                switch (mad->method) {
                case IB_MGMT_METHOD_GET:
                        /* Bad mkey not a violation below level 2 */
-                       if (ibp->mkeyprot < 2)
+                       if (ibp->rvp.mkeyprot < 2)
                                break;
                case IB_MGMT_METHOD_SET:
                case IB_MGMT_METHOD_TRAP_REPRESS:
-                       if (ibp->mkey_violations != 0xFFFF)
-                               ++ibp->mkey_violations;
-                       if (!ibp->mkey_lease_timeout && ibp->mkey_lease_period)
-                               ibp->mkey_lease_timeout = jiffies +
-                                       ibp->mkey_lease_period * HZ;
+                       if (ibp->rvp.mkey_violations != 0xFFFF)
+                               ++ibp->rvp.mkey_violations;
+                       if (!ibp->rvp.mkey_lease_timeout &&
+                           ibp->rvp.mkey_lease_period)
+                               ibp->rvp.mkey_lease_timeout = jiffies +
+                                       ibp->rvp.mkey_lease_period * HZ;
                        /* Generate a trap notice. */
                        bad_mkey(ibp, mad, mkey, dr_slid, return_path,
                                 hop_cnt);
@@ -501,16 +503,6 @@ void read_ltp_rtt(struct hfi1_devdata *dd)
                write_lcb_cache(DC_LCB_STS_ROUND_TRIP_LTP_CNT, reg);
 }
 
-static u8 __opa_porttype(struct hfi1_pportdata *ppd)
-{
-       if (qsfp_mod_present(ppd)) {
-               if (ppd->qsfp_info.cache_valid)
-                       return OPA_PORT_TYPE_STANDARD;
-               return OPA_PORT_TYPE_DISCONNECTED;
-       }
-       return OPA_PORT_TYPE_UNKNOWN;
-}
-
 static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
                                   struct ib_device *ibdev, u8 port,
                                   u32 *resp_len)
@@ -548,14 +540,14 @@ static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
 
        /* Only return the mkey if the protection field allows it. */
        if (!(smp->method == IB_MGMT_METHOD_GET &&
-             ibp->mkey != smp->mkey &&
-             ibp->mkeyprot == 1))
-               pi->mkey = ibp->mkey;
-
-       pi->subnet_prefix = ibp->gid_prefix;
-       pi->sm_lid = cpu_to_be32(ibp->sm_lid);
-       pi->ib_cap_mask = cpu_to_be32(ibp->port_cap_flags);
-       pi->mkey_lease_period = cpu_to_be16(ibp->mkey_lease_period);
+             ibp->rvp.mkey != smp->mkey &&
+             ibp->rvp.mkeyprot == 1))
+               pi->mkey = ibp->rvp.mkey;
+
+       pi->subnet_prefix = ibp->rvp.gid_prefix;
+       pi->sm_lid = cpu_to_be32(ibp->rvp.sm_lid);
+       pi->ib_cap_mask = cpu_to_be32(ibp->rvp.port_cap_flags);
+       pi->mkey_lease_period = cpu_to_be16(ibp->rvp.mkey_lease_period);
        pi->sm_trap_qp = cpu_to_be32(ppd->sm_trap_qp);
        pi->sa_qp = cpu_to_be32(ppd->sa_qp);
 
@@ -581,25 +573,24 @@ static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
        if (start_of_sm_config && (state == IB_PORT_INIT))
                ppd->is_sm_config_started = 1;
 
-       pi->port_phys_conf = __opa_porttype(ppd) & 0xf;
+       pi->port_phys_conf = (ppd->port_type & 0xf);
 
 #if PI_LED_ENABLE_SUP
        pi->port_states.ledenable_offlinereason = ppd->neighbor_normal << 4;
        pi->port_states.ledenable_offlinereason |=
                ppd->is_sm_config_started << 5;
        pi->port_states.ledenable_offlinereason |=
-               ppd->offline_disabled_reason & OPA_PI_MASK_OFFLINE_REASON;
+               ppd->offline_disabled_reason;
 #else
        pi->port_states.offline_reason = ppd->neighbor_normal << 4;
        pi->port_states.offline_reason |= ppd->is_sm_config_started << 5;
-       pi->port_states.offline_reason |= ppd->offline_disabled_reason &
-                                               OPA_PI_MASK_OFFLINE_REASON;
+       pi->port_states.offline_reason |= ppd->offline_disabled_reason;
 #endif /* PI_LED_ENABLE_SUP */
 
        pi->port_states.portphysstate_portstate =
                (hfi1_ibphys_portstate(ppd) << 4) | state;
 
-       pi->mkeyprotect_lmc = (ibp->mkeyprot << 6) | ppd->lmc;
+       pi->mkeyprotect_lmc = (ibp->rvp.mkeyprot << 6) | ppd->lmc;
 
        memset(pi->neigh_mtu.pvlx_to_mtu, 0, sizeof(pi->neigh_mtu.pvlx_to_mtu));
        for (i = 0; i < ppd->vls_supported; i++) {
@@ -612,7 +603,7 @@ static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
        /* don't forget VL 15 */
        mtu = mtu_to_enum(dd->vld[15].mtu, 2048);
        pi->neigh_mtu.pvlx_to_mtu[15/2] |= mtu;
-       pi->smsl = ibp->sm_sl & OPA_PI_MASK_SMSL;
+       pi->smsl = ibp->rvp.sm_sl & OPA_PI_MASK_SMSL;
        pi->operational_vls = hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_OP_VLS);
        pi->partenforce_filterraw |=
                (ppd->linkinit_reason & OPA_PI_MASK_LINKINIT_REASON);
@@ -620,17 +611,17 @@ static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
                pi->partenforce_filterraw |= OPA_PI_MASK_PARTITION_ENFORCE_IN;
        if (ppd->part_enforce & HFI1_PART_ENFORCE_OUT)
                pi->partenforce_filterraw |= OPA_PI_MASK_PARTITION_ENFORCE_OUT;
-       pi->mkey_violations = cpu_to_be16(ibp->mkey_violations);
+       pi->mkey_violations = cpu_to_be16(ibp->rvp.mkey_violations);
        /* P_KeyViolations are counted by hardware. */
-       pi->pkey_violations = cpu_to_be16(ibp->pkey_violations);
-       pi->qkey_violations = cpu_to_be16(ibp->qkey_violations);
+       pi->pkey_violations = cpu_to_be16(ibp->rvp.pkey_violations);
+       pi->qkey_violations = cpu_to_be16(ibp->rvp.qkey_violations);
 
        pi->vl.cap = ppd->vls_supported;
-       pi->vl.high_limit = cpu_to_be16(ibp->vl_high_limit);
+       pi->vl.high_limit = cpu_to_be16(ibp->rvp.vl_high_limit);
        pi->vl.arb_high_cap = (u8)hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_VL_HIGH_CAP);
        pi->vl.arb_low_cap = (u8)hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_VL_LOW_CAP);
 
-       pi->clientrereg_subnettimeout = ibp->subnet_timeout;
+       pi->clientrereg_subnettimeout = ibp->rvp.subnet_timeout;
 
        pi->port_link_mode  = cpu_to_be16(OPA_PORT_LINK_MODE_OPA << 10 |
                                          OPA_PORT_LINK_MODE_OPA << 5 |
@@ -927,6 +918,14 @@ static int port_states_transition_allowed(struct hfi1_pportdata *ppd,
            physical_allowed == HFI_TRANSITION_IGNORED)
                return HFI_TRANSITION_IGNORED;
 
+       /*
+        * A change request of Physical Port State from
+        * 'Offline' to 'Polling' should be ignored.
+        */
+       if ((physical_old == OPA_PORTPHYSSTATE_OFFLINE) &&
+           (physical_new == IB_PORTPHYSSTATE_POLLING))
+               return HFI_TRANSITION_IGNORED;
+
        /*
         * Either physical_allowed or logical_allowed is
         * HFI_TRANSITION_ALLOWED.
@@ -991,11 +990,11 @@ static int set_port_states(struct hfi1_pportdata *ppd, struct opa_smp *smp,
                set_link_state(ppd, link_state);
                if (link_state == HLS_DN_DISABLE &&
                    (ppd->offline_disabled_reason >
-                    OPA_LINKDOWN_REASON_SMA_DISABLED ||
+                    HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED) ||
                     ppd->offline_disabled_reason ==
-                    OPA_LINKDOWN_REASON_NONE))
+                    HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE)))
                        ppd->offline_disabled_reason =
-                       OPA_LINKDOWN_REASON_SMA_DISABLED;
+                       HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED);
                /*
                 * Don't send a reply if the response would be sent
                 * through the disabled port.
@@ -1091,13 +1090,13 @@ static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
 
        ls_old = driver_lstate(ppd);
 
-       ibp->mkey = pi->mkey;
-       ibp->gid_prefix = pi->subnet_prefix;
-       ibp->mkey_lease_period = be16_to_cpu(pi->mkey_lease_period);
+       ibp->rvp.mkey = pi->mkey;
+       ibp->rvp.gid_prefix = pi->subnet_prefix;
+       ibp->rvp.mkey_lease_period = be16_to_cpu(pi->mkey_lease_period);
 
        /* Must be a valid unicast LID address. */
        if ((lid == 0 && ls_old > IB_PORT_INIT) ||
-            lid >= HFI1_MULTICAST_LID_BASE) {
+            lid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) {
                smp->status |= IB_SMP_INVALID_FIELD;
                pr_warn("SubnSet(OPA_PortInfo) lid invalid 0x%x\n",
                        lid);
@@ -1130,23 +1129,23 @@ static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
 
        /* Must be a valid unicast LID address. */
        if ((smlid == 0 && ls_old > IB_PORT_INIT) ||
-            smlid >= HFI1_MULTICAST_LID_BASE) {
+            smlid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) {
                smp->status |= IB_SMP_INVALID_FIELD;
                pr_warn("SubnSet(OPA_PortInfo) smlid invalid 0x%x\n", smlid);
-       } else if (smlid != ibp->sm_lid || msl != ibp->sm_sl) {
+       } else if (smlid != ibp->rvp.sm_lid || msl != ibp->rvp.sm_sl) {
                pr_warn("SubnSet(OPA_PortInfo) smlid 0x%x\n", smlid);
-               spin_lock_irqsave(&ibp->lock, flags);
-               if (ibp->sm_ah) {
-                       if (smlid != ibp->sm_lid)
-                               ibp->sm_ah->attr.dlid = smlid;
-                       if (msl != ibp->sm_sl)
-                               ibp->sm_ah->attr.sl = msl;
+               spin_lock_irqsave(&ibp->rvp.lock, flags);
+               if (ibp->rvp.sm_ah) {
+                       if (smlid != ibp->rvp.sm_lid)
+                               ibp->rvp.sm_ah->attr.dlid = smlid;
+                       if (msl != ibp->rvp.sm_sl)
+                               ibp->rvp.sm_ah->attr.sl = msl;
                }
-               spin_unlock_irqrestore(&ibp->lock, flags);
-               if (smlid != ibp->sm_lid)
-                       ibp->sm_lid = smlid;
-               if (msl != ibp->sm_sl)
-                       ibp->sm_sl = msl;
+               spin_unlock_irqrestore(&ibp->rvp.lock, flags);
+               if (smlid != ibp->rvp.sm_lid)
+                       ibp->rvp.sm_lid = smlid;
+               if (msl != ibp->rvp.sm_sl)
+                       ibp->rvp.sm_sl = msl;
                event.event = IB_EVENT_SM_CHANGE;
                ib_dispatch_event(&event);
        }
@@ -1198,10 +1197,11 @@ static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
                        smp->status |= IB_SMP_INVALID_FIELD;
        }
 
-       ibp->mkeyprot = (pi->mkeyprotect_lmc & OPA_PI_MASK_MKEY_PROT_BIT) >> 6;
-       ibp->vl_high_limit = be16_to_cpu(pi->vl.high_limit) & 0xFF;
+       ibp->rvp.mkeyprot =
+               (pi->mkeyprotect_lmc & OPA_PI_MASK_MKEY_PROT_BIT) >> 6;
+       ibp->rvp.vl_high_limit = be16_to_cpu(pi->vl.high_limit) & 0xFF;
        (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_VL_HIGH_LIMIT,
-                                   ibp->vl_high_limit);
+                                   ibp->rvp.vl_high_limit);
 
        if (ppd->vls_supported/2 > ARRAY_SIZE(pi->neigh_mtu.pvlx_to_mtu) ||
                ppd->vls_supported > ARRAY_SIZE(dd->vld)) {
@@ -1260,15 +1260,15 @@ static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
        }
 
        if (pi->mkey_violations == 0)
-               ibp->mkey_violations = 0;
+               ibp->rvp.mkey_violations = 0;
 
        if (pi->pkey_violations == 0)
-               ibp->pkey_violations = 0;
+               ibp->rvp.pkey_violations = 0;
 
        if (pi->qkey_violations == 0)
-               ibp->qkey_violations = 0;
+               ibp->rvp.qkey_violations = 0;
 
-       ibp->subnet_timeout =
+       ibp->rvp.subnet_timeout =
                pi->clientrereg_subnettimeout & OPA_PI_MASK_SUBNET_TIMEOUT;
 
        crc_enabled = be16_to_cpu(pi->port_ltp_crc_mode);
@@ -1388,7 +1388,7 @@ static int set_pkeys(struct hfi1_devdata *dd, u8 port, u16 *pkeys)
                (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
 
                event.event = IB_EVENT_PKEY_CHANGE;
-               event.device = &dd->verbs_dev.ibdev;
+               event.device = &dd->verbs_dev.rdi.ibdev;
                event.element.port_num = port;
                ib_dispatch_event(&event);
        }
@@ -1707,12 +1707,11 @@ static int __subn_get_opa_psi(struct opa_smp *smp, u32 am, u8 *data,
        psi->port_states.ledenable_offlinereason |=
                ppd->is_sm_config_started << 5;
        psi->port_states.ledenable_offlinereason |=
-               ppd->offline_disabled_reason & OPA_PI_MASK_OFFLINE_REASON;
+               ppd->offline_disabled_reason;
 #else
        psi->port_states.offline_reason = ppd->neighbor_normal << 4;
        psi->port_states.offline_reason |= ppd->is_sm_config_started << 5;
-       psi->port_states.offline_reason |= ppd->offline_disabled_reason &
-                               OPA_PI_MASK_OFFLINE_REASON;
+       psi->port_states.offline_reason |= ppd->offline_disabled_reason;
 #endif /* PI_LED_ENABLE_SUP */
 
        psi->port_states.portphysstate_portstate =
@@ -1782,7 +1781,7 @@ static int __subn_get_opa_cable_info(struct opa_smp *smp, u32 am, u8 *data,
        u32 len = OPA_AM_CI_LEN(am) + 1;
        int ret;
 
-#define __CI_PAGE_SIZE (1 << 7) /* 128 bytes */
+#define __CI_PAGE_SIZE BIT(7) /* 128 bytes */
 #define __CI_PAGE_MASK ~(__CI_PAGE_SIZE - 1)
 #define __CI_PAGE_NUM(a) ((a) & __CI_PAGE_MASK)
 
@@ -2279,17 +2278,23 @@ static void a0_portstatus(struct hfi1_pportdata *ppd,
 {
        if (!is_bx(ppd->dd)) {
                unsigned long vl;
-               u64 max_vl_xmit_wait = 0, tmp;
+               u64 sum_vl_xmit_wait = 0;
                u32 vl_all_mask = VL_MASK_ALL;
 
                for_each_set_bit(vl, (unsigned long *)&(vl_all_mask),
                                 8 * sizeof(vl_all_mask)) {
-                       tmp = read_port_cntr(ppd, C_TX_WAIT_VL,
-                                            idx_from_vl(vl));
-                       if (tmp > max_vl_xmit_wait)
-                               max_vl_xmit_wait = tmp;
+                       u64 tmp = sum_vl_xmit_wait +
+                                 read_port_cntr(ppd, C_TX_WAIT_VL,
+                                                idx_from_vl(vl));
+                       if (tmp < sum_vl_xmit_wait) {
+                               /* we wrapped */
+                               sum_vl_xmit_wait = (u64)~0;
+                               break;
+                       }
+                       sum_vl_xmit_wait = tmp;
                }
-               rsp->port_xmit_wait = cpu_to_be64(max_vl_xmit_wait);
+               if (be64_to_cpu(rsp->port_xmit_wait) > sum_vl_xmit_wait)
+                       rsp->port_xmit_wait = cpu_to_be64(sum_vl_xmit_wait);
        }
 }
 
@@ -2491,18 +2496,19 @@ static u64 get_error_counter_summary(struct ib_device *ibdev, u8 port,
        return error_counter_summary;
 }
 
-static void a0_datacounters(struct hfi1_devdata *dd, struct _port_dctrs *rsp,
+static void a0_datacounters(struct hfi1_pportdata *ppd, struct _port_dctrs *rsp,
                            u32 vl_select_mask)
 {
-       if (!is_bx(dd)) {
+       if (!is_bx(ppd->dd)) {
                unsigned long vl;
-               int vfi = 0;
                u64 sum_vl_xmit_wait = 0;
+               u32 vl_all_mask = VL_MASK_ALL;
 
-               for_each_set_bit(vl, (unsigned long *)&(vl_select_mask),
-                               8 * sizeof(vl_select_mask)) {
+               for_each_set_bit(vl, (unsigned long *)&(vl_all_mask),
+                                8 * sizeof(vl_all_mask)) {
                        u64 tmp = sum_vl_xmit_wait +
-                               be64_to_cpu(rsp->vls[vfi++].port_vl_xmit_wait);
+                                 read_port_cntr(ppd, C_TX_WAIT_VL,
+                                                idx_from_vl(vl));
                        if (tmp < sum_vl_xmit_wait) {
                                /* we wrapped */
                                sum_vl_xmit_wait = (u64) ~0;
@@ -2665,7 +2671,7 @@ static int pma_get_opa_datacounters(struct opa_pma_mad *pmp,
                vfi++;
        }
 
-       a0_datacounters(dd, rsp, vl_select_mask);
+       a0_datacounters(ppd, rsp, vl_select_mask);
 
        if (resp_len)
                *resp_len += response_data_size;
@@ -3402,7 +3408,7 @@ struct opa_led_info {
 };
 
 #define OPA_LED_SHIFT  31
-#define OPA_LED_MASK   (1 << OPA_LED_SHIFT)
+#define OPA_LED_MASK   BIT(OPA_LED_SHIFT)
 
 static int __subn_get_opa_led_info(struct opa_smp *smp, u32 am, u8 *data,
                                   struct ib_device *ibdev, u8 port,
@@ -3443,7 +3449,10 @@ static int __subn_set_opa_led_info(struct opa_smp *smp, u32 am, u8 *data,
                return reply((struct ib_mad_hdr *)smp);
        }
 
-       setextled(dd, on);
+       if (on)
+               hfi1_set_led_override(dd->pport, 2000, 1500);
+       else
+               hfi1_set_led_override(dd->pport, 0, 0);
 
        return __subn_get_opa_led_info(smp, am, data, ibdev, port, resp_len);
 }
@@ -3525,9 +3534,9 @@ static int subn_get_opa_sma(__be16 attr_id, struct opa_smp *smp, u32 am,
                                              resp_len);
                break;
        case IB_SMP_ATTR_SM_INFO:
-               if (ibp->port_cap_flags & IB_PORT_SM_DISABLED)
+               if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED)
                        return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
-               if (ibp->port_cap_flags & IB_PORT_SM)
+               if (ibp->rvp.port_cap_flags & IB_PORT_SM)
                        return IB_MAD_RESULT_SUCCESS;
                /* FALLTHROUGH */
        default:
@@ -3595,9 +3604,9 @@ static int subn_set_opa_sma(__be16 attr_id, struct opa_smp *smp, u32 am,
                                              resp_len);
                break;
        case IB_SMP_ATTR_SM_INFO:
-               if (ibp->port_cap_flags & IB_PORT_SM_DISABLED)
+               if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED)
                        return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
-               if (ibp->port_cap_flags & IB_PORT_SM)
+               if (ibp->rvp.port_cap_flags & IB_PORT_SM)
                        return IB_MAD_RESULT_SUCCESS;
                /* FALLTHROUGH */
        default:
@@ -4147,66 +4156,3 @@ int hfi1_process_mad(struct ib_device *ibdev, int mad_flags, u8 port,
 
        return IB_MAD_RESULT_FAILURE;
 }
-
-static void send_handler(struct ib_mad_agent *agent,
-                        struct ib_mad_send_wc *mad_send_wc)
-{
-       ib_free_send_mad(mad_send_wc->send_buf);
-}
-
-int hfi1_create_agents(struct hfi1_ibdev *dev)
-{
-       struct hfi1_devdata *dd = dd_from_dev(dev);
-       struct ib_mad_agent *agent;
-       struct hfi1_ibport *ibp;
-       int p;
-       int ret;
-
-       for (p = 0; p < dd->num_pports; p++) {
-               ibp = &dd->pport[p].ibport_data;
-               agent = ib_register_mad_agent(&dev->ibdev, p + 1, IB_QPT_SMI,
-                                             NULL, 0, send_handler,
-                                             NULL, NULL, 0);
-               if (IS_ERR(agent)) {
-                       ret = PTR_ERR(agent);
-                       goto err;
-               }
-
-               ibp->send_agent = agent;
-       }
-
-       return 0;
-
-err:
-       for (p = 0; p < dd->num_pports; p++) {
-               ibp = &dd->pport[p].ibport_data;
-               if (ibp->send_agent) {
-                       agent = ibp->send_agent;
-                       ibp->send_agent = NULL;
-                       ib_unregister_mad_agent(agent);
-               }
-       }
-
-       return ret;
-}
-
-void hfi1_free_agents(struct hfi1_ibdev *dev)
-{
-       struct hfi1_devdata *dd = dd_from_dev(dev);
-       struct ib_mad_agent *agent;
-       struct hfi1_ibport *ibp;
-       int p;
-
-       for (p = 0; p < dd->num_pports; p++) {
-               ibp = &dd->pport[p].ibport_data;
-               if (ibp->send_agent) {
-                       agent = ibp->send_agent;
-                       ibp->send_agent = NULL;
-                       ib_unregister_mad_agent(agent);
-               }
-               if (ibp->sm_ah) {
-                       ib_destroy_ah(&ibp->sm_ah->ibah);
-                       ibp->sm_ah = NULL;
-               }
-       }
-}