]> err.no Git - linux-2.6/blobdiff - drivers/infiniband/hw/ipath/ipath_mad.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[linux-2.6] / drivers / infiniband / hw / ipath / ipath_mad.c
index 25908b02fbe578f57fd6ee7128ea0c9b22169f32..b34b91d3723a58f4a2e58f0d6233ed3e264f9338 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006 QLogic, Inc. All rights reserved.
+ * Copyright (c) 2006, 2007 QLogic Corporation. All rights reserved.
  * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
@@ -103,7 +103,7 @@ static int recv_subn_get_nodeinfo(struct ib_smp *smp,
        /* This is already in network order */
        nip->sys_guid = to_idev(ibdev)->sys_image_guid;
        nip->node_guid = dd->ipath_guid;
-       nip->port_guid = nip->sys_guid;
+       nip->port_guid = dd->ipath_guid;
        nip->partition_cap = cpu_to_be16(ipath_get_npkeys(dd));
        nip->device_id = cpu_to_be16(dd->ipath_deviceid);
        majrev = dd->ipath_majrev;
@@ -245,7 +245,7 @@ static int recv_subn_get_portinfo(struct ib_smp *smp,
 
        /* Only return the mkey if the protection field allows it. */
        if (smp->method == IB_MGMT_METHOD_SET || dev->mkey == smp->mkey ||
-           (dev->mkeyprot_resv_lmc >> 6) == 0)
+           dev->mkeyprot == 0)
                pip->mkey = dev->mkey;
        pip->gid_prefix = dev->gid_prefix;
        lid = dev->dd->ipath_lid;
@@ -264,7 +264,7 @@ static int recv_subn_get_portinfo(struct ib_smp *smp,
        pip->portphysstate_linkdown =
                (ipath_cvt_physportstate[ibcstat & 0xf] << 4) |
                (get_linkdowndefaultstate(dev->dd) ? 1 : 2);
-       pip->mkeyprot_resv_lmc = dev->mkeyprot_resv_lmc;
+       pip->mkeyprot_resv_lmc = (dev->mkeyprot << 6) | dev->dd->ipath_lmc;
        pip->linkspeedactive_enabled = 0x11;    /* 2.5Gbps, 2.5Gbps */
        switch (dev->dd->ipath_ibmtu) {
        case 4096:
@@ -292,7 +292,12 @@ static int recv_subn_get_portinfo(struct ib_smp *smp,
        /* pip->vl_arb_high_cap; // only one VL */
        /* pip->vl_arb_low_cap; // only one VL */
        /* InitTypeReply = 0 */
-       pip->inittypereply_mtucap = IB_MTU_4096;
+       /*
+        * Note: the chips support a maximum MTU of 4096, but the driver
+        * hasn't implemented this feature yet, so set the maximum value
+        * to 2048.
+        */
+       pip->inittypereply_mtucap = IB_MTU_2048;
        // HCAs ignore VLStallCount and HOQLife
        /* pip->vlstallcnt_hoqlife; */
        pip->operationalvl_pei_peo_fpi_fpo = 0x10;      /* OVLs = 1 */
@@ -396,7 +401,7 @@ static int recv_subn_set_portinfo(struct ib_smp *smp,
        struct ib_port_info *pip = (struct ib_port_info *)smp->data;
        struct ib_event event;
        struct ipath_ibdev *dev;
-       u32 flags;
+       struct ipath_devdata *dd;
        char clientrereg = 0;
        u16 lid, smlid;
        u8 lwe;
@@ -410,6 +415,7 @@ static int recv_subn_set_portinfo(struct ib_smp *smp,
                goto err;
 
        dev = to_idev(ibdev);
+       dd = dev->dd;
        event.device = ibdev;
        event.element.port_num = port;
 
@@ -418,11 +424,12 @@ static int recv_subn_set_portinfo(struct ib_smp *smp,
        dev->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
 
        lid = be16_to_cpu(pip->lid);
-       if (lid != dev->dd->ipath_lid) {
+       if (dd->ipath_lid != lid ||
+           dd->ipath_lmc != (pip->mkeyprot_resv_lmc & 7)) {
                /* Must be a valid unicast LID address. */
                if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE)
                        goto err;
-               ipath_set_lid(dev->dd, lid, pip->mkeyprot_resv_lmc & 7);
+               ipath_set_lid(dd, lid, pip->mkeyprot_resv_lmc & 7);
                event.event = IB_EVENT_LID_CHANGE;
                ib_dispatch_event(&event);
        }
@@ -456,18 +463,18 @@ static int recv_subn_set_portinfo(struct ib_smp *smp,
        case 0: /* NOP */
                break;
        case 1: /* SLEEP */
-               if (set_linkdowndefaultstate(dev->dd, 1))
+               if (set_linkdowndefaultstate(dd, 1))
                        goto err;
                break;
        case 2: /* POLL */
-               if (set_linkdowndefaultstate(dev->dd, 0))
+               if (set_linkdowndefaultstate(dd, 0))
                        goto err;
                break;
        default:
                goto err;
        }
 
-       dev->mkeyprot_resv_lmc = pip->mkeyprot_resv_lmc;
+       dev->mkeyprot = pip->mkeyprot_resv_lmc >> 6;
        dev->vl_high_limit = pip->vl_high_limit;
 
        switch ((pip->neighbormtu_mastersmsl >> 4) & 0xF) {
@@ -490,7 +497,7 @@ static int recv_subn_set_portinfo(struct ib_smp *smp,
                /* XXX We have already partially updated our state! */
                goto err;
        }
-       ipath_set_mtu(dev->dd, mtu);
+       ipath_set_mtu(dd, mtu);
 
        dev->sm_sl = pip->neighbormtu_mastersmsl & 0xF;
 
@@ -506,16 +513,16 @@ static int recv_subn_set_portinfo(struct ib_smp *smp,
         * later.
         */
        if (pip->pkey_violations == 0)
-               dev->z_pkey_violations = ipath_get_cr_errpkey(dev->dd);
+               dev->z_pkey_violations = ipath_get_cr_errpkey(dd);
 
        if (pip->qkey_violations == 0)
                dev->qkey_violations = 0;
 
        ore = pip->localphyerrors_overrunerrors;
-       if (set_phyerrthreshold(dev->dd, (ore >> 4) & 0xF))
+       if (set_phyerrthreshold(dd, (ore >> 4) & 0xF))
                goto err;
 
-       if (set_overrunthreshold(dev->dd, (ore & 0xF)))
+       if (set_overrunthreshold(dd, (ore & 0xF)))
                goto err;
 
        dev->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
@@ -533,7 +540,6 @@ static int recv_subn_set_portinfo(struct ib_smp *smp,
         * is down or is being set to down.
         */
        state = pip->linkspeed_portstate & 0xF;
-       flags = dev->dd->ipath_flags;
        lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
        if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
                goto err;
@@ -549,10 +555,7 @@ static int recv_subn_set_portinfo(struct ib_smp *smp,
                /* FALLTHROUGH */
        case IB_PORT_DOWN:
                if (lstate == 0)
-                       if (get_linkdowndefaultstate(dev->dd))
-                               lstate = IPATH_IB_LINKDOWN_SLEEP;
-                       else
-                               lstate = IPATH_IB_LINKDOWN;
+                       lstate = IPATH_IB_LINKDOWN_ONLY;
                else if (lstate == 1)
                        lstate = IPATH_IB_LINKDOWN_SLEEP;
                else if (lstate == 2)
@@ -561,27 +564,15 @@ static int recv_subn_set_portinfo(struct ib_smp *smp,
                        lstate = IPATH_IB_LINKDOWN_DISABLE;
                else
                        goto err;
-               ipath_set_linkstate(dev->dd, lstate);
-               if (flags & IPATH_LINKACTIVE) {
-                       event.event = IB_EVENT_PORT_ERR;
-                       ib_dispatch_event(&event);
-               }
+               ipath_set_linkstate(dd, lstate);
+               ipath_wait_linkstate(dd, IPATH_LINKINIT | IPATH_LINKARMED |
+                               IPATH_LINKACTIVE, 1000);
                break;
        case IB_PORT_ARMED:
-               if (!(flags & (IPATH_LINKINIT | IPATH_LINKACTIVE)))
-                       break;
-               ipath_set_linkstate(dev->dd, IPATH_IB_LINKARM);
-               if (flags & IPATH_LINKACTIVE) {
-                       event.event = IB_EVENT_PORT_ERR;
-                       ib_dispatch_event(&event);
-               }
+               ipath_set_linkstate(dd, IPATH_IB_LINKARM);
                break;
        case IB_PORT_ACTIVE:
-               if (!(flags & IPATH_LINKARMED))
-                       break;
-               ipath_set_linkstate(dev->dd, IPATH_IB_LINKACTIVE);
-               event.event = IB_EVENT_PORT_ACTIVE;
-               ib_dispatch_event(&event);
+               ipath_set_linkstate(dd, IPATH_IB_LINKACTIVE);
                break;
        default:
                /* XXX We have already partially updated our state! */
@@ -942,6 +933,7 @@ static int recv_pma_get_portsamplescontrol(struct ib_perf *pmp,
        struct ib_pma_portsamplescontrol *p =
                (struct ib_pma_portsamplescontrol *)pmp->data;
        struct ipath_ibdev *dev = to_idev(ibdev);
+       struct ipath_cregs const *crp = dev->dd->ipath_cregs;
        unsigned long flags;
        u8 port_select = p->port_select;
 
@@ -963,7 +955,10 @@ static int recv_pma_get_portsamplescontrol(struct ib_perf *pmp,
        p->counter_width = 4;   /* 32 bit counters */
        p->counter_mask0_9 = COUNTER_MASK0_9;
        spin_lock_irqsave(&dev->pending_lock, flags);
-       p->sample_status = dev->pma_sample_status;
+       if (crp->cr_psstat)
+               p->sample_status = ipath_read_creg32(dev->dd, crp->cr_psstat);
+       else
+               p->sample_status = dev->pma_sample_status;
        p->sample_start = cpu_to_be32(dev->pma_sample_start);
        p->sample_interval = cpu_to_be32(dev->pma_sample_interval);
        p->tag = cpu_to_be16(dev->pma_tag);
@@ -983,8 +978,9 @@ static int recv_pma_set_portsamplescontrol(struct ib_perf *pmp,
        struct ib_pma_portsamplescontrol *p =
                (struct ib_pma_portsamplescontrol *)pmp->data;
        struct ipath_ibdev *dev = to_idev(ibdev);
+       struct ipath_cregs const *crp = dev->dd->ipath_cregs;
        unsigned long flags;
-       u32 start;
+       u8 status;
        int ret;
 
        if (pmp->attr_mod != 0 ||
@@ -994,59 +990,67 @@ static int recv_pma_set_portsamplescontrol(struct ib_perf *pmp,
                goto bail;
        }
 
-       start = be32_to_cpu(p->sample_start);
-       if (start != 0) {
-               spin_lock_irqsave(&dev->pending_lock, flags);
-               if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_DONE) {
-                       dev->pma_sample_status =
-                               IB_PMA_SAMPLE_STATUS_STARTED;
-                       dev->pma_sample_start = start;
-                       dev->pma_sample_interval =
-                               be32_to_cpu(p->sample_interval);
-                       dev->pma_tag = be16_to_cpu(p->tag);
-                       if (p->counter_select[0])
-                               dev->pma_counter_select[0] =
-                                       p->counter_select[0];
-                       if (p->counter_select[1])
-                               dev->pma_counter_select[1] =
-                                       p->counter_select[1];
-                       if (p->counter_select[2])
-                               dev->pma_counter_select[2] =
-                                       p->counter_select[2];
-                       if (p->counter_select[3])
-                               dev->pma_counter_select[3] =
-                                       p->counter_select[3];
-                       if (p->counter_select[4])
-                               dev->pma_counter_select[4] =
-                                       p->counter_select[4];
-               }
-               spin_unlock_irqrestore(&dev->pending_lock, flags);
+       spin_lock_irqsave(&dev->pending_lock, flags);
+       if (crp->cr_psstat)
+               status = ipath_read_creg32(dev->dd, crp->cr_psstat);
+       else
+               status = dev->pma_sample_status;
+       if (status == IB_PMA_SAMPLE_STATUS_DONE) {
+               dev->pma_sample_start = be32_to_cpu(p->sample_start);
+               dev->pma_sample_interval = be32_to_cpu(p->sample_interval);
+               dev->pma_tag = be16_to_cpu(p->tag);
+               dev->pma_counter_select[0] = p->counter_select[0];
+               dev->pma_counter_select[1] = p->counter_select[1];
+               dev->pma_counter_select[2] = p->counter_select[2];
+               dev->pma_counter_select[3] = p->counter_select[3];
+               dev->pma_counter_select[4] = p->counter_select[4];
+               if (crp->cr_psstat) {
+                       ipath_write_creg(dev->dd, crp->cr_psinterval,
+                                        dev->pma_sample_interval);
+                       ipath_write_creg(dev->dd, crp->cr_psstart,
+                                        dev->pma_sample_start);
+               } else
+                       dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_STARTED;
        }
+       spin_unlock_irqrestore(&dev->pending_lock, flags);
+
        ret = recv_pma_get_portsamplescontrol(pmp, ibdev, port);
 
 bail:
        return ret;
 }
 
-static u64 get_counter(struct ipath_ibdev *dev, __be16 sel)
+static u64 get_counter(struct ipath_ibdev *dev,
+                      struct ipath_cregs const *crp,
+                      __be16 sel)
 {
        u64 ret;
 
        switch (sel) {
        case IB_PMA_PORT_XMIT_DATA:
-               ret = dev->ipath_sword;
+               ret = (crp->cr_psxmitdatacount) ?
+                       ipath_read_creg32(dev->dd, crp->cr_psxmitdatacount) :
+                       dev->ipath_sword;
                break;
        case IB_PMA_PORT_RCV_DATA:
-               ret = dev->ipath_rword;
+               ret = (crp->cr_psrcvdatacount) ?
+                       ipath_read_creg32(dev->dd, crp->cr_psrcvdatacount) :
+                       dev->ipath_rword;
                break;
        case IB_PMA_PORT_XMIT_PKTS:
-               ret = dev->ipath_spkts;
+               ret = (crp->cr_psxmitpktscount) ?
+                       ipath_read_creg32(dev->dd, crp->cr_psxmitpktscount) :
+                       dev->ipath_spkts;
                break;
        case IB_PMA_PORT_RCV_PKTS:
-               ret = dev->ipath_rpkts;
+               ret = (crp->cr_psrcvpktscount) ?
+                       ipath_read_creg32(dev->dd, crp->cr_psrcvpktscount) :
+                       dev->ipath_rpkts;
                break;
        case IB_PMA_PORT_XMIT_WAIT:
-               ret = dev->ipath_xmit_wait;
+               ret = (crp->cr_psxmitwaitcount) ?
+                       ipath_read_creg32(dev->dd, crp->cr_psxmitwaitcount) :
+                       dev->ipath_xmit_wait;
                break;
        default:
                ret = 0;
@@ -1061,14 +1065,21 @@ static int recv_pma_get_portsamplesresult(struct ib_perf *pmp,
        struct ib_pma_portsamplesresult *p =
                (struct ib_pma_portsamplesresult *)pmp->data;
        struct ipath_ibdev *dev = to_idev(ibdev);
+       struct ipath_cregs const *crp = dev->dd->ipath_cregs;
+       u8 status;
        int i;
 
        memset(pmp->data, 0, sizeof(pmp->data));
        p->tag = cpu_to_be16(dev->pma_tag);
-       p->sample_status = cpu_to_be16(dev->pma_sample_status);
+       if (crp->cr_psstat)
+               status = ipath_read_creg32(dev->dd, crp->cr_psstat);
+       else
+               status = dev->pma_sample_status;
+       p->sample_status = cpu_to_be16(status);
        for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
-               p->counter[i] = cpu_to_be32(
-                       get_counter(dev, dev->pma_counter_select[i]));
+               p->counter[i] = (status != IB_PMA_SAMPLE_STATUS_DONE) ? 0 :
+                   cpu_to_be32(
+                       get_counter(dev, crp, dev->pma_counter_select[i]));
 
        return reply((struct ib_smp *) pmp);
 }
@@ -1079,16 +1090,23 @@ static int recv_pma_get_portsamplesresult_ext(struct ib_perf *pmp,
        struct ib_pma_portsamplesresult_ext *p =
                (struct ib_pma_portsamplesresult_ext *)pmp->data;
        struct ipath_ibdev *dev = to_idev(ibdev);
+       struct ipath_cregs const *crp = dev->dd->ipath_cregs;
+       u8 status;
        int i;
 
        memset(pmp->data, 0, sizeof(pmp->data));
        p->tag = cpu_to_be16(dev->pma_tag);
-       p->sample_status = cpu_to_be16(dev->pma_sample_status);
+       if (crp->cr_psstat)
+               status = ipath_read_creg32(dev->dd, crp->cr_psstat);
+       else
+               status = dev->pma_sample_status;
+       p->sample_status = cpu_to_be16(status);
        /* 64 bits */
        p->extended_width = __constant_cpu_to_be32(0x80000000);
        for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
-               p->counter[i] = cpu_to_be64(
-                       get_counter(dev, dev->pma_counter_select[i]));
+               p->counter[i] = (status != IB_PMA_SAMPLE_STATUS_DONE) ? 0 :
+                   cpu_to_be64(
+                       get_counter(dev, crp, dev->pma_counter_select[i]));
 
        return reply((struct ib_smp *) pmp);
 }
@@ -1121,6 +1139,8 @@ static int recv_pma_get_portcounters(struct ib_perf *pmp,
                dev->z_local_link_integrity_errors;
        cntrs.excessive_buffer_overrun_errors -=
                dev->z_excessive_buffer_overrun_errors;
+       cntrs.vl15_dropped -= dev->z_vl15_dropped;
+       cntrs.vl15_dropped += dev->n_vl15_dropped;
 
        memset(pmp->data, 0, sizeof(pmp->data));
 
@@ -1164,10 +1184,10 @@ static int recv_pma_get_portcounters(struct ib_perf *pmp,
                cntrs.excessive_buffer_overrun_errors = 0xFUL;
        p->lli_ebor_errors = (cntrs.local_link_integrity_errors << 4) |
                cntrs.excessive_buffer_overrun_errors;
-       if (dev->n_vl15_dropped > 0xFFFFUL)
+       if (cntrs.vl15_dropped > 0xFFFFUL)
                p->vl15_dropped = __constant_cpu_to_be16(0xFFFF);
        else
-               p->vl15_dropped = cpu_to_be16((u16)dev->n_vl15_dropped);
+               p->vl15_dropped = cpu_to_be16((u16)cntrs.vl15_dropped);
        if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
                p->port_xmit_data = __constant_cpu_to_be32(0xFFFFFFFF);
        else
@@ -1270,8 +1290,10 @@ static int recv_pma_set_portcounters(struct ib_perf *pmp,
                dev->z_excessive_buffer_overrun_errors =
                        cntrs.excessive_buffer_overrun_errors;
 
-       if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED)
+       if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED) {
                dev->n_vl15_dropped = 0;
+               dev->z_vl15_dropped = cntrs.vl15_dropped;
+       }
 
        if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
                dev->z_port_xmit_data = cntrs.port_xmit_data;
@@ -1345,7 +1367,7 @@ static int process_subn(struct ib_device *ibdev, int mad_flags,
        if (dev->mkey_lease_timeout && jiffies >= dev->mkey_lease_timeout) {
                /* Clear timeout and mkey protection field. */
                dev->mkey_lease_timeout = 0;
-               dev->mkeyprot_resv_lmc &= 0x3F;
+               dev->mkeyprot = 0;
        }
 
        /*
@@ -1356,7 +1378,7 @@ static int process_subn(struct ib_device *ibdev, int mad_flags,
            dev->mkey != smp->mkey &&
            (smp->method == IB_MGMT_METHOD_SET ||
             (smp->method == IB_MGMT_METHOD_GET &&
-             (dev->mkeyprot_resv_lmc >> 7) != 0))) {
+             dev->mkeyprot >= 2))) {
                if (dev->mkey_violations != 0xFFFF)
                        ++dev->mkey_violations;
                if (dev->mkey_lease_timeout ||
@@ -1442,7 +1464,7 @@ static int process_subn(struct ib_device *ibdev, int mad_flags,
                 * before checking for other consumers.
                 * Just tell the caller to process it normally.
                 */
-               ret = IB_MAD_RESULT_FAILURE;
+               ret = IB_MAD_RESULT_SUCCESS;
                goto bail;
        default:
                smp->status |= IB_SMP_UNSUP_METHOD;
@@ -1524,7 +1546,7 @@ static int process_perf(struct ib_device *ibdev, u8 port_num,
                 * before checking for other consumers.
                 * Just tell the caller to process it normally.
                 */
-               ret = IB_MAD_RESULT_FAILURE;
+               ret = IB_MAD_RESULT_SUCCESS;
                goto bail;
        default:
                pmp->status |= IB_SMP_UNSUP_METHOD;