aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband/hw/qib
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/infiniband/hw/qib')
-rw-r--r--drivers/infiniband/hw/qib/qib.h35
-rw-r--r--drivers/infiniband/hw/qib/qib_driver.c5
-rw-r--r--drivers/infiniband/hw/qib/qib_iba6120.c1
-rw-r--r--drivers/infiniband/hw/qib/qib_iba7220.c1
-rw-r--r--drivers/infiniband/hw/qib/qib_iba7322.c3
-rw-r--r--drivers/infiniband/hw/qib/qib_init.c3
-rw-r--r--drivers/infiniband/hw/qib/qib_mad.c63
-rw-r--r--drivers/infiniband/hw/qib/qib_qp.c7
-rw-r--r--drivers/infiniband/hw/qib/qib_rc.c4
-rw-r--r--drivers/infiniband/hw/qib/qib_ruc.c12
-rw-r--r--drivers/infiniband/hw/qib/qib_sysfs.c7
-rw-r--r--drivers/infiniband/hw/qib/qib_tx.c25
-rw-r--r--drivers/infiniband/hw/qib/qib_uc.c4
-rw-r--r--drivers/infiniband/hw/qib/qib_ud.c16
-rw-r--r--drivers/infiniband/hw/qib/qib_verbs.h145
15 files changed, 199 insertions, 132 deletions
diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
index 6b811e3e8bd1..7e62f4137148 100644
--- a/drivers/infiniband/hw/qib/qib.h
+++ b/drivers/infiniband/hw/qib/qib.h
@@ -530,8 +530,6 @@ struct qib_pportdata {
530 /* qib_lflags driver is waiting for */ 530 /* qib_lflags driver is waiting for */
531 u32 state_wanted; 531 u32 state_wanted;
532 spinlock_t lflags_lock; 532 spinlock_t lflags_lock;
533 /* number of (port-specific) interrupts for this port -- saturates... */
534 u32 int_counter;
535 533
536 /* ref count for each pkey */ 534 /* ref count for each pkey */
537 atomic_t pkeyrefs[4]; 535 atomic_t pkeyrefs[4];
@@ -543,24 +541,26 @@ struct qib_pportdata {
543 u64 *statusp; 541 u64 *statusp;
544 542
545 /* SendDMA related entries */ 543 /* SendDMA related entries */
546 spinlock_t sdma_lock; 544
547 struct qib_sdma_state sdma_state; 545 /* read mostly */
548 unsigned long sdma_buf_jiffies;
549 struct qib_sdma_desc *sdma_descq; 546 struct qib_sdma_desc *sdma_descq;
547 struct qib_sdma_state sdma_state;
548 dma_addr_t sdma_descq_phys;
549 volatile __le64 *sdma_head_dma; /* DMA'ed by chip */
550 dma_addr_t sdma_head_phys;
551 u16 sdma_descq_cnt;
552
553 /* read/write using lock */
554 spinlock_t sdma_lock ____cacheline_aligned_in_smp;
555 struct list_head sdma_activelist;
550 u64 sdma_descq_added; 556 u64 sdma_descq_added;
551 u64 sdma_descq_removed; 557 u64 sdma_descq_removed;
552 u16 sdma_descq_cnt;
553 u16 sdma_descq_tail; 558 u16 sdma_descq_tail;
554 u16 sdma_descq_head; 559 u16 sdma_descq_head;
555 u16 sdma_next_intr;
556 u16 sdma_reset_wait;
557 u8 sdma_generation; 560 u8 sdma_generation;
558 struct tasklet_struct sdma_sw_clean_up_task;
559 struct list_head sdma_activelist;
560 561
561 dma_addr_t sdma_descq_phys; 562 struct tasklet_struct sdma_sw_clean_up_task
562 volatile __le64 *sdma_head_dma; /* DMA'ed by chip */ 563 ____cacheline_aligned_in_smp;
563 dma_addr_t sdma_head_phys;
564 564
565 wait_queue_head_t state_wait; /* for state_wanted */ 565 wait_queue_head_t state_wait; /* for state_wanted */
566 566
@@ -873,7 +873,14 @@ struct qib_devdata {
873 * pio_writing. 873 * pio_writing.
874 */ 874 */
875 spinlock_t pioavail_lock; 875 spinlock_t pioavail_lock;
876 876 /*
877 * index of last buffer to optimize search for next
878 */
879 u32 last_pio;
880 /*
881 * min kernel pio buffer to optimize search
882 */
883 u32 min_kernel_pio;
877 /* 884 /*
878 * Shadow copies of registers; size indicates read access size. 885 * Shadow copies of registers; size indicates read access size.
879 * Most of them are readonly, but some are write-only register, 886 * Most of them are readonly, but some are write-only register,
diff --git a/drivers/infiniband/hw/qib/qib_driver.c b/drivers/infiniband/hw/qib/qib_driver.c
index 6fc9365ba8a6..8895cfec5019 100644
--- a/drivers/infiniband/hw/qib/qib_driver.c
+++ b/drivers/infiniband/hw/qib/qib_driver.c
@@ -38,6 +38,7 @@
38#include <linux/netdevice.h> 38#include <linux/netdevice.h>
39#include <linux/vmalloc.h> 39#include <linux/vmalloc.h>
40#include <linux/module.h> 40#include <linux/module.h>
41#include <linux/prefetch.h>
41 42
42#include "qib.h" 43#include "qib.h"
43 44
@@ -481,8 +482,10 @@ u32 qib_kreceive(struct qib_ctxtdata *rcd, u32 *llic, u32 *npkts)
481 etail = qib_hdrget_index(rhf_addr); 482 etail = qib_hdrget_index(rhf_addr);
482 updegr = 1; 483 updegr = 1;
483 if (tlen > sizeof(*hdr) || 484 if (tlen > sizeof(*hdr) ||
484 etype >= RCVHQ_RCV_TYPE_NON_KD) 485 etype >= RCVHQ_RCV_TYPE_NON_KD) {
485 ebuf = qib_get_egrbuf(rcd, etail); 486 ebuf = qib_get_egrbuf(rcd, etail);
487 prefetch_range(ebuf, tlen - sizeof(*hdr));
488 }
486 } 489 }
487 if (!eflags) { 490 if (!eflags) {
488 u16 lrh_len = be16_to_cpu(hdr->lrh[2]) << 2; 491 u16 lrh_len = be16_to_cpu(hdr->lrh[2]) << 2;
diff --git a/drivers/infiniband/hw/qib/qib_iba6120.c b/drivers/infiniband/hw/qib/qib_iba6120.c
index d0c64d514813..4d352b90750a 100644
--- a/drivers/infiniband/hw/qib/qib_iba6120.c
+++ b/drivers/infiniband/hw/qib/qib_iba6120.c
@@ -3132,6 +3132,7 @@ static void get_6120_chip_params(struct qib_devdata *dd)
3132 val = qib_read_kreg64(dd, kr_sendpiobufcnt); 3132 val = qib_read_kreg64(dd, kr_sendpiobufcnt);
3133 dd->piobcnt2k = val & ~0U; 3133 dd->piobcnt2k = val & ~0U;
3134 dd->piobcnt4k = val >> 32; 3134 dd->piobcnt4k = val >> 32;
3135 dd->last_pio = dd->piobcnt4k + dd->piobcnt2k - 1;
3135 /* these may be adjusted in init_chip_wc_pat() */ 3136 /* these may be adjusted in init_chip_wc_pat() */
3136 dd->pio2kbase = (u32 __iomem *) 3137 dd->pio2kbase = (u32 __iomem *)
3137 (((char __iomem *)dd->kregbase) + dd->pio2k_bufbase); 3138 (((char __iomem *)dd->kregbase) + dd->pio2k_bufbase);
diff --git a/drivers/infiniband/hw/qib/qib_iba7220.c b/drivers/infiniband/hw/qib/qib_iba7220.c
index 3c722f79d6f6..86a0ba7ca0c2 100644
--- a/drivers/infiniband/hw/qib/qib_iba7220.c
+++ b/drivers/infiniband/hw/qib/qib_iba7220.c
@@ -4157,6 +4157,7 @@ static int qib_init_7220_variables(struct qib_devdata *dd)
4157 dd->cspec->sdmabufcnt; 4157 dd->cspec->sdmabufcnt;
4158 dd->lastctxt_piobuf = dd->cspec->lastbuf_for_pio - sbufs; 4158 dd->lastctxt_piobuf = dd->cspec->lastbuf_for_pio - sbufs;
4159 dd->cspec->lastbuf_for_pio--; /* range is <= , not < */ 4159 dd->cspec->lastbuf_for_pio--; /* range is <= , not < */
4160 dd->last_pio = dd->cspec->lastbuf_for_pio;
4160 dd->pbufsctxt = dd->lastctxt_piobuf / 4161 dd->pbufsctxt = dd->lastctxt_piobuf /
4161 (dd->cfgctxts - dd->first_user_ctxt); 4162 (dd->cfgctxts - dd->first_user_ctxt);
4162 4163
diff --git a/drivers/infiniband/hw/qib/qib_iba7322.c b/drivers/infiniband/hw/qib/qib_iba7322.c
index 060b96064469..c881e744c091 100644
--- a/drivers/infiniband/hw/qib/qib_iba7322.c
+++ b/drivers/infiniband/hw/qib/qib_iba7322.c
@@ -6379,6 +6379,7 @@ static int qib_init_7322_variables(struct qib_devdata *dd)
6379 dd->cspec->sdmabufcnt; 6379 dd->cspec->sdmabufcnt;
6380 dd->lastctxt_piobuf = dd->cspec->lastbuf_for_pio - sbufs; 6380 dd->lastctxt_piobuf = dd->cspec->lastbuf_for_pio - sbufs;
6381 dd->cspec->lastbuf_for_pio--; /* range is <= , not < */ 6381 dd->cspec->lastbuf_for_pio--; /* range is <= , not < */
6382 dd->last_pio = dd->cspec->lastbuf_for_pio;
6382 dd->pbufsctxt = (dd->cfgctxts > dd->first_user_ctxt) ? 6383 dd->pbufsctxt = (dd->cfgctxts > dd->first_user_ctxt) ?
6383 dd->lastctxt_piobuf / (dd->cfgctxts - dd->first_user_ctxt) : 0; 6384 dd->lastctxt_piobuf / (dd->cfgctxts - dd->first_user_ctxt) : 0;
6384 6385
@@ -7708,7 +7709,7 @@ static int serdes_7322_init_new(struct qib_pportdata *ppd)
7708 ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0)); 7709 ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0));
7709 msleep(20); 7710 msleep(20);
7710 /* Set Frequency Loop Bandwidth */ 7711 /* Set Frequency Loop Bandwidth */
7711 ibsd_wr_allchans(ppd, 2, (7 << 5), BMASK(8, 5)); 7712 ibsd_wr_allchans(ppd, 2, (15 << 5), BMASK(8, 5));
7712 /* Enable Frequency Loop */ 7713 /* Enable Frequency Loop */
7713 ibsd_wr_allchans(ppd, 2, (1 << 4), BMASK(4, 4)); 7714 ibsd_wr_allchans(ppd, 2, (1 << 4), BMASK(4, 4));
7714 /* Set Timing Loop Bandwidth */ 7715 /* Set Timing Loop Bandwidth */
diff --git a/drivers/infiniband/hw/qib/qib_init.c b/drivers/infiniband/hw/qib/qib_init.c
index cf0cd30adc8d..dc14e100a7f1 100644
--- a/drivers/infiniband/hw/qib/qib_init.c
+++ b/drivers/infiniband/hw/qib/qib_init.c
@@ -102,6 +102,8 @@ void qib_set_ctxtcnt(struct qib_devdata *dd)
102 dd->cfgctxts = qib_cfgctxts; 102 dd->cfgctxts = qib_cfgctxts;
103 else 103 else
104 dd->cfgctxts = dd->ctxtcnt; 104 dd->cfgctxts = dd->ctxtcnt;
105 dd->freectxts = (dd->first_user_ctxt > dd->cfgctxts) ? 0 :
106 dd->cfgctxts - dd->first_user_ctxt;
105} 107}
106 108
107/* 109/*
@@ -402,7 +404,6 @@ static void enable_chip(struct qib_devdata *dd)
402 if (rcd) 404 if (rcd)
403 dd->f_rcvctrl(rcd->ppd, rcvmask, i); 405 dd->f_rcvctrl(rcd->ppd, rcvmask, i);
404 } 406 }
405 dd->freectxts = dd->cfgctxts - dd->first_user_ctxt;
406} 407}
407 408
408static void verify_interrupt(unsigned long opaque) 409static void verify_interrupt(unsigned long opaque)
diff --git a/drivers/infiniband/hw/qib/qib_mad.c b/drivers/infiniband/hw/qib/qib_mad.c
index c4ff788823b5..43390217a026 100644
--- a/drivers/infiniband/hw/qib/qib_mad.c
+++ b/drivers/infiniband/hw/qib/qib_mad.c
@@ -396,6 +396,7 @@ static int get_linkdowndefaultstate(struct qib_pportdata *ppd)
396 396
397static int check_mkey(struct qib_ibport *ibp, struct ib_smp *smp, int mad_flags) 397static int check_mkey(struct qib_ibport *ibp, struct ib_smp *smp, int mad_flags)
398{ 398{
399 int valid_mkey = 0;
399 int ret = 0; 400 int ret = 0;
400 401
401 /* Is the mkey in the process of expiring? */ 402 /* Is the mkey in the process of expiring? */
@@ -406,23 +407,36 @@ static int check_mkey(struct qib_ibport *ibp, struct ib_smp *smp, int mad_flags)
406 ibp->mkeyprot = 0; 407 ibp->mkeyprot = 0;
407 } 408 }
408 409
409 /* M_Key checking depends on Portinfo:M_Key_protect_bits */ 410 if ((mad_flags & IB_MAD_IGNORE_MKEY) || ibp->mkey == 0 ||
410 if ((mad_flags & IB_MAD_IGNORE_MKEY) == 0 && ibp->mkey != 0 && 411 ibp->mkey == smp->mkey)
411 ibp->mkey != smp->mkey && 412 valid_mkey = 1;
412 (smp->method == IB_MGMT_METHOD_SET || 413
413 smp->method == IB_MGMT_METHOD_TRAP_REPRESS || 414 /* Unset lease timeout on any valid Get/Set/TrapRepress */
414 (smp->method == IB_MGMT_METHOD_GET && ibp->mkeyprot >= 2))) { 415 if (valid_mkey && ibp->mkey_lease_timeout &&
415 if (ibp->mkey_violations != 0xFFFF) 416 (smp->method == IB_MGMT_METHOD_GET ||
416 ++ibp->mkey_violations; 417 smp->method == IB_MGMT_METHOD_SET ||
417 if (!ibp->mkey_lease_timeout && ibp->mkey_lease_period) 418 smp->method == IB_MGMT_METHOD_TRAP_REPRESS))
418 ibp->mkey_lease_timeout = jiffies +
419 ibp->mkey_lease_period * HZ;
420 /* Generate a trap notice. */
421 qib_bad_mkey(ibp, smp);
422 ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
423 } else if (ibp->mkey_lease_timeout)
424 ibp->mkey_lease_timeout = 0; 419 ibp->mkey_lease_timeout = 0;
425 420
421 if (!valid_mkey) {
422 switch (smp->method) {
423 case IB_MGMT_METHOD_GET:
424 /* Bad mkey not a violation below level 2 */
425 if (ibp->mkeyprot < 2)
426 break;
427 case IB_MGMT_METHOD_SET:
428 case IB_MGMT_METHOD_TRAP_REPRESS:
429 if (ibp->mkey_violations != 0xFFFF)
430 ++ibp->mkey_violations;
431 if (!ibp->mkey_lease_timeout && ibp->mkey_lease_period)
432 ibp->mkey_lease_timeout = jiffies +
433 ibp->mkey_lease_period * HZ;
434 /* Generate a trap notice. */
435 qib_bad_mkey(ibp, smp);
436 ret = 1;
437 }
438 }
439
426 return ret; 440 return ret;
427} 441}
428 442
@@ -450,6 +464,7 @@ static int subn_get_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
450 ibp = to_iport(ibdev, port_num); 464 ibp = to_iport(ibdev, port_num);
451 ret = check_mkey(ibp, smp, 0); 465 ret = check_mkey(ibp, smp, 0);
452 if (ret) 466 if (ret)
467 ret = IB_MAD_RESULT_FAILURE;
453 goto bail; 468 goto bail;
454 } 469 }
455 } 470 }
@@ -631,7 +646,7 @@ static int subn_set_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
631 struct qib_devdata *dd; 646 struct qib_devdata *dd;
632 struct qib_pportdata *ppd; 647 struct qib_pportdata *ppd;
633 struct qib_ibport *ibp; 648 struct qib_ibport *ibp;
634 char clientrereg = 0; 649 u8 clientrereg = (pip->clientrereg_resv_subnetto & 0x80);
635 unsigned long flags; 650 unsigned long flags;
636 u16 lid, smlid; 651 u16 lid, smlid;
637 u8 lwe; 652 u8 lwe;
@@ -781,12 +796,6 @@ static int subn_set_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
781 796
782 ibp->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F; 797 ibp->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
783 798
784 if (pip->clientrereg_resv_subnetto & 0x80) {
785 clientrereg = 1;
786 event.event = IB_EVENT_CLIENT_REREGISTER;
787 ib_dispatch_event(&event);
788 }
789
790 /* 799 /*
791 * Do the port state change now that the other link parameters 800 * Do the port state change now that the other link parameters
792 * have been set. 801 * have been set.
@@ -844,10 +853,15 @@ static int subn_set_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
844 smp->status |= IB_SMP_INVALID_FIELD; 853 smp->status |= IB_SMP_INVALID_FIELD;
845 } 854 }
846 855
856 if (clientrereg) {
857 event.event = IB_EVENT_CLIENT_REREGISTER;
858 ib_dispatch_event(&event);
859 }
860
847 ret = subn_get_portinfo(smp, ibdev, port); 861 ret = subn_get_portinfo(smp, ibdev, port);
848 862
849 if (clientrereg) 863 /* restore re-reg bit per o14-12.2.1 */
850 pip->clientrereg_resv_subnetto |= 0x80; 864 pip->clientrereg_resv_subnetto |= clientrereg;
851 865
852 goto get_only; 866 goto get_only;
853 867
@@ -1835,6 +1849,7 @@ static int process_subn(struct ib_device *ibdev, int mad_flags,
1835 port_num && port_num <= ibdev->phys_port_cnt && 1849 port_num && port_num <= ibdev->phys_port_cnt &&
1836 port != port_num) 1850 port != port_num)
1837 (void) check_mkey(to_iport(ibdev, port_num), smp, 0); 1851 (void) check_mkey(to_iport(ibdev, port_num), smp, 0);
1852 ret = IB_MAD_RESULT_FAILURE;
1838 goto bail; 1853 goto bail;
1839 } 1854 }
1840 1855
diff --git a/drivers/infiniband/hw/qib/qib_qp.c b/drivers/infiniband/hw/qib/qib_qp.c
index 7e7e16fbee99..1ce56b51ab1a 100644
--- a/drivers/infiniband/hw/qib/qib_qp.c
+++ b/drivers/infiniband/hw/qib/qib_qp.c
@@ -1038,6 +1038,11 @@ struct ib_qp *qib_create_qp(struct ib_pd *ibpd,
1038 goto bail_swq; 1038 goto bail_swq;
1039 } 1039 }
1040 RCU_INIT_POINTER(qp->next, NULL); 1040 RCU_INIT_POINTER(qp->next, NULL);
1041 qp->s_hdr = kzalloc(sizeof(*qp->s_hdr), GFP_KERNEL);
1042 if (!qp->s_hdr) {
1043 ret = ERR_PTR(-ENOMEM);
1044 goto bail_qp;
1045 }
1041 qp->timeout_jiffies = 1046 qp->timeout_jiffies =
1042 usecs_to_jiffies((4096UL * (1UL << qp->timeout)) / 1047 usecs_to_jiffies((4096UL * (1UL << qp->timeout)) /
1043 1000UL); 1048 1000UL);
@@ -1159,6 +1164,7 @@ bail_ip:
1159 vfree(qp->r_rq.wq); 1164 vfree(qp->r_rq.wq);
1160 free_qpn(&dev->qpn_table, qp->ibqp.qp_num); 1165 free_qpn(&dev->qpn_table, qp->ibqp.qp_num);
1161bail_qp: 1166bail_qp:
1167 kfree(qp->s_hdr);
1162 kfree(qp); 1168 kfree(qp);
1163bail_swq: 1169bail_swq:
1164 vfree(swq); 1170 vfree(swq);
@@ -1214,6 +1220,7 @@ int qib_destroy_qp(struct ib_qp *ibqp)
1214 else 1220 else
1215 vfree(qp->r_rq.wq); 1221 vfree(qp->r_rq.wq);
1216 vfree(qp->s_wq); 1222 vfree(qp->s_wq);
1223 kfree(qp->s_hdr);
1217 kfree(qp); 1224 kfree(qp);
1218 return 0; 1225 return 0;
1219} 1226}
diff --git a/drivers/infiniband/hw/qib/qib_rc.c b/drivers/infiniband/hw/qib/qib_rc.c
index 765b4cbaa020..b641416148eb 100644
--- a/drivers/infiniband/hw/qib/qib_rc.c
+++ b/drivers/infiniband/hw/qib/qib_rc.c
@@ -244,9 +244,9 @@ int qib_make_rc_req(struct qib_qp *qp)
244 int ret = 0; 244 int ret = 0;
245 int delta; 245 int delta;
246 246
247 ohdr = &qp->s_hdr.u.oth; 247 ohdr = &qp->s_hdr->u.oth;
248 if (qp->remote_ah_attr.ah_flags & IB_AH_GRH) 248 if (qp->remote_ah_attr.ah_flags & IB_AH_GRH)
249 ohdr = &qp->s_hdr.u.l.oth; 249 ohdr = &qp->s_hdr->u.l.oth;
250 250
251 /* 251 /*
252 * The lock is needed to synchronize between the sending tasklet, 252 * The lock is needed to synchronize between the sending tasklet,
diff --git a/drivers/infiniband/hw/qib/qib_ruc.c b/drivers/infiniband/hw/qib/qib_ruc.c
index b4b37e47321a..c0ee7e095d81 100644
--- a/drivers/infiniband/hw/qib/qib_ruc.c
+++ b/drivers/infiniband/hw/qib/qib_ruc.c
@@ -688,17 +688,17 @@ void qib_make_ruc_header(struct qib_qp *qp, struct qib_other_headers *ohdr,
688 nwords = (qp->s_cur_size + extra_bytes) >> 2; 688 nwords = (qp->s_cur_size + extra_bytes) >> 2;
689 lrh0 = QIB_LRH_BTH; 689 lrh0 = QIB_LRH_BTH;
690 if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) { 690 if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) {
691 qp->s_hdrwords += qib_make_grh(ibp, &qp->s_hdr.u.l.grh, 691 qp->s_hdrwords += qib_make_grh(ibp, &qp->s_hdr->u.l.grh,
692 &qp->remote_ah_attr.grh, 692 &qp->remote_ah_attr.grh,
693 qp->s_hdrwords, nwords); 693 qp->s_hdrwords, nwords);
694 lrh0 = QIB_LRH_GRH; 694 lrh0 = QIB_LRH_GRH;
695 } 695 }
696 lrh0 |= ibp->sl_to_vl[qp->remote_ah_attr.sl] << 12 | 696 lrh0 |= ibp->sl_to_vl[qp->remote_ah_attr.sl] << 12 |
697 qp->remote_ah_attr.sl << 4; 697 qp->remote_ah_attr.sl << 4;
698 qp->s_hdr.lrh[0] = cpu_to_be16(lrh0); 698 qp->s_hdr->lrh[0] = cpu_to_be16(lrh0);
699 qp->s_hdr.lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid); 699 qp->s_hdr->lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid);
700 qp->s_hdr.lrh[2] = cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC); 700 qp->s_hdr->lrh[2] = cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC);
701 qp->s_hdr.lrh[3] = cpu_to_be16(ppd_from_ibp(ibp)->lid | 701 qp->s_hdr->lrh[3] = cpu_to_be16(ppd_from_ibp(ibp)->lid |
702 qp->remote_ah_attr.src_path_bits); 702 qp->remote_ah_attr.src_path_bits);
703 bth0 |= qib_get_pkey(ibp, qp->s_pkey_index); 703 bth0 |= qib_get_pkey(ibp, qp->s_pkey_index);
704 bth0 |= extra_bytes << 20; 704 bth0 |= extra_bytes << 20;
@@ -758,7 +758,7 @@ void qib_do_send(struct work_struct *work)
758 * If the packet cannot be sent now, return and 758 * If the packet cannot be sent now, return and
759 * the send tasklet will be woken up later. 759 * the send tasklet will be woken up later.
760 */ 760 */
761 if (qib_verbs_send(qp, &qp->s_hdr, qp->s_hdrwords, 761 if (qib_verbs_send(qp, qp->s_hdr, qp->s_hdrwords,
762 qp->s_cur_sge, qp->s_cur_size)) 762 qp->s_cur_sge, qp->s_cur_size))
763 break; 763 break;
764 /* Record that s_hdr is empty. */ 764 /* Record that s_hdr is empty. */
diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c
index dae51604cfcd..dd9cd49d0979 100644
--- a/drivers/infiniband/hw/qib/qib_sysfs.c
+++ b/drivers/infiniband/hw/qib/qib_sysfs.c
@@ -503,8 +503,11 @@ static ssize_t show_nctxts(struct device *device,
503 struct qib_devdata *dd = dd_from_dev(dev); 503 struct qib_devdata *dd = dd_from_dev(dev);
504 504
505 /* Return the number of user ports (contexts) available. */ 505 /* Return the number of user ports (contexts) available. */
506 return scnprintf(buf, PAGE_SIZE, "%u\n", dd->cfgctxts - 506 /* The calculation below deals with a special case where
507 dd->first_user_ctxt); 507 * cfgctxts is set to 1 on a single-port board. */
508 return scnprintf(buf, PAGE_SIZE, "%u\n",
509 (dd->first_user_ctxt > dd->cfgctxts) ? 0 :
510 (dd->cfgctxts - dd->first_user_ctxt));
508} 511}
509 512
510static ssize_t show_nfreectxts(struct device *device, 513static ssize_t show_nfreectxts(struct device *device,
diff --git a/drivers/infiniband/hw/qib/qib_tx.c b/drivers/infiniband/hw/qib/qib_tx.c
index 1bf626c40172..31d3561400a4 100644
--- a/drivers/infiniband/hw/qib/qib_tx.c
+++ b/drivers/infiniband/hw/qib/qib_tx.c
@@ -295,6 +295,7 @@ u32 __iomem *qib_getsendbuf_range(struct qib_devdata *dd, u32 *pbufnum,
295 295
296 nbufs = last - first + 1; /* number in range to check */ 296 nbufs = last - first + 1; /* number in range to check */
297 if (dd->upd_pio_shadow) { 297 if (dd->upd_pio_shadow) {
298update_shadow:
298 /* 299 /*
299 * Minor optimization. If we had no buffers on last call, 300 * Minor optimization. If we had no buffers on last call,
300 * start out by doing the update; continue and do scan even 301 * start out by doing the update; continue and do scan even
@@ -304,37 +305,39 @@ u32 __iomem *qib_getsendbuf_range(struct qib_devdata *dd, u32 *pbufnum,
304 updated++; 305 updated++;
305 } 306 }
306 i = first; 307 i = first;
307rescan:
308 /* 308 /*
309 * While test_and_set_bit() is atomic, we do that and then the 309 * While test_and_set_bit() is atomic, we do that and then the
310 * change_bit(), and the pair is not. See if this is the cause 310 * change_bit(), and the pair is not. See if this is the cause
311 * of the remaining armlaunch errors. 311 * of the remaining armlaunch errors.
312 */ 312 */
313 spin_lock_irqsave(&dd->pioavail_lock, flags); 313 spin_lock_irqsave(&dd->pioavail_lock, flags);
314 if (dd->last_pio >= first && dd->last_pio <= last)
315 i = dd->last_pio + 1;
316 if (!first)
317 /* adjust to min possible */
318 nbufs = last - dd->min_kernel_pio + 1;
314 for (j = 0; j < nbufs; j++, i++) { 319 for (j = 0; j < nbufs; j++, i++) {
315 if (i > last) 320 if (i > last)
316 i = first; 321 i = !first ? dd->min_kernel_pio : first;
317 if (__test_and_set_bit((2 * i) + 1, shadow)) 322 if (__test_and_set_bit((2 * i) + 1, shadow))
318 continue; 323 continue;
319 /* flip generation bit */ 324 /* flip generation bit */
320 __change_bit(2 * i, shadow); 325 __change_bit(2 * i, shadow);
321 /* remember that the buffer can be written to now */ 326 /* remember that the buffer can be written to now */
322 __set_bit(i, dd->pio_writing); 327 __set_bit(i, dd->pio_writing);
328 if (!first && first != last) /* first == last on VL15, avoid */
329 dd->last_pio = i;
323 break; 330 break;
324 } 331 }
325 spin_unlock_irqrestore(&dd->pioavail_lock, flags); 332 spin_unlock_irqrestore(&dd->pioavail_lock, flags);
326 333
327 if (j == nbufs) { 334 if (j == nbufs) {
328 if (!updated) { 335 if (!updated)
329 /* 336 /*
330 * First time through; shadow exhausted, but may be 337 * First time through; shadow exhausted, but may be
331 * buffers available, try an update and then rescan. 338 * buffers available, try an update and then rescan.
332 */ 339 */
333 update_send_bufs(dd); 340 goto update_shadow;
334 updated++;
335 i = first;
336 goto rescan;
337 }
338 no_send_bufs(dd); 341 no_send_bufs(dd);
339 buf = NULL; 342 buf = NULL;
340 } else { 343 } else {
@@ -422,14 +425,20 @@ void qib_chg_pioavailkernel(struct qib_devdata *dd, unsigned start,
422 __clear_bit(QLOGIC_IB_SENDPIOAVAIL_CHECK_SHIFT 425 __clear_bit(QLOGIC_IB_SENDPIOAVAIL_CHECK_SHIFT
423 + start, dd->pioavailshadow); 426 + start, dd->pioavailshadow);
424 __set_bit(start, dd->pioavailkernel); 427 __set_bit(start, dd->pioavailkernel);
428 if ((start >> 1) < dd->min_kernel_pio)
429 dd->min_kernel_pio = start >> 1;
425 } else { 430 } else {
426 __set_bit(start + QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT, 431 __set_bit(start + QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT,
427 dd->pioavailshadow); 432 dd->pioavailshadow);
428 __clear_bit(start, dd->pioavailkernel); 433 __clear_bit(start, dd->pioavailkernel);
434 if ((start >> 1) > dd->min_kernel_pio)
435 dd->min_kernel_pio = start >> 1;
429 } 436 }
430 start += 2; 437 start += 2;
431 } 438 }
432 439
440 if (dd->min_kernel_pio > 0 && dd->last_pio < dd->min_kernel_pio - 1)
441 dd->last_pio = dd->min_kernel_pio - 1;
433 spin_unlock_irqrestore(&dd->pioavail_lock, flags); 442 spin_unlock_irqrestore(&dd->pioavail_lock, flags);
434 443
435 dd->f_txchk_change(dd, ostart, len, avail, rcd); 444 dd->f_txchk_change(dd, ostart, len, avail, rcd);
diff --git a/drivers/infiniband/hw/qib/qib_uc.c b/drivers/infiniband/hw/qib/qib_uc.c
index 7ce2ac2ed219..ce7387ff5d91 100644
--- a/drivers/infiniband/hw/qib/qib_uc.c
+++ b/drivers/infiniband/hw/qib/qib_uc.c
@@ -72,9 +72,9 @@ int qib_make_uc_req(struct qib_qp *qp)
72 goto done; 72 goto done;
73 } 73 }
74 74
75 ohdr = &qp->s_hdr.u.oth; 75 ohdr = &qp->s_hdr->u.oth;
76 if (qp->remote_ah_attr.ah_flags & IB_AH_GRH) 76 if (qp->remote_ah_attr.ah_flags & IB_AH_GRH)
77 ohdr = &qp->s_hdr.u.l.oth; 77 ohdr = &qp->s_hdr->u.l.oth;
78 78
79 /* header size in 32-bit words LRH+BTH = (8+12)/4. */ 79 /* header size in 32-bit words LRH+BTH = (8+12)/4. */
80 hwords = 5; 80 hwords = 5;
diff --git a/drivers/infiniband/hw/qib/qib_ud.c b/drivers/infiniband/hw/qib/qib_ud.c
index 828609fa4d28..a468bf2d4465 100644
--- a/drivers/infiniband/hw/qib/qib_ud.c
+++ b/drivers/infiniband/hw/qib/qib_ud.c
@@ -321,11 +321,11 @@ int qib_make_ud_req(struct qib_qp *qp)
321 321
322 if (ah_attr->ah_flags & IB_AH_GRH) { 322 if (ah_attr->ah_flags & IB_AH_GRH) {
323 /* Header size in 32-bit words. */ 323 /* Header size in 32-bit words. */
324 qp->s_hdrwords += qib_make_grh(ibp, &qp->s_hdr.u.l.grh, 324 qp->s_hdrwords += qib_make_grh(ibp, &qp->s_hdr->u.l.grh,
325 &ah_attr->grh, 325 &ah_attr->grh,
326 qp->s_hdrwords, nwords); 326 qp->s_hdrwords, nwords);
327 lrh0 = QIB_LRH_GRH; 327 lrh0 = QIB_LRH_GRH;
328 ohdr = &qp->s_hdr.u.l.oth; 328 ohdr = &qp->s_hdr->u.l.oth;
329 /* 329 /*
330 * Don't worry about sending to locally attached multicast 330 * Don't worry about sending to locally attached multicast
331 * QPs. It is unspecified by the spec. what happens. 331 * QPs. It is unspecified by the spec. what happens.
@@ -333,7 +333,7 @@ int qib_make_ud_req(struct qib_qp *qp)
333 } else { 333 } else {
334 /* Header size in 32-bit words. */ 334 /* Header size in 32-bit words. */
335 lrh0 = QIB_LRH_BTH; 335 lrh0 = QIB_LRH_BTH;
336 ohdr = &qp->s_hdr.u.oth; 336 ohdr = &qp->s_hdr->u.oth;
337 } 337 }
338 if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM) { 338 if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM) {
339 qp->s_hdrwords++; 339 qp->s_hdrwords++;
@@ -346,15 +346,15 @@ int qib_make_ud_req(struct qib_qp *qp)
346 lrh0 |= 0xF000; /* Set VL (see ch. 13.5.3.1) */ 346 lrh0 |= 0xF000; /* Set VL (see ch. 13.5.3.1) */
347 else 347 else
348 lrh0 |= ibp->sl_to_vl[ah_attr->sl] << 12; 348 lrh0 |= ibp->sl_to_vl[ah_attr->sl] << 12;
349 qp->s_hdr.lrh[0] = cpu_to_be16(lrh0); 349 qp->s_hdr->lrh[0] = cpu_to_be16(lrh0);
350 qp->s_hdr.lrh[1] = cpu_to_be16(ah_attr->dlid); /* DEST LID */ 350 qp->s_hdr->lrh[1] = cpu_to_be16(ah_attr->dlid); /* DEST LID */
351 qp->s_hdr.lrh[2] = cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC); 351 qp->s_hdr->lrh[2] = cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC);
352 lid = ppd->lid; 352 lid = ppd->lid;
353 if (lid) { 353 if (lid) {
354 lid |= ah_attr->src_path_bits & ((1 << ppd->lmc) - 1); 354 lid |= ah_attr->src_path_bits & ((1 << ppd->lmc) - 1);
355 qp->s_hdr.lrh[3] = cpu_to_be16(lid); 355 qp->s_hdr->lrh[3] = cpu_to_be16(lid);
356 } else 356 } else
357 qp->s_hdr.lrh[3] = IB_LID_PERMISSIVE; 357 qp->s_hdr->lrh[3] = IB_LID_PERMISSIVE;
358 if (wqe->wr.send_flags & IB_SEND_SOLICITED) 358 if (wqe->wr.send_flags & IB_SEND_SOLICITED)
359 bth0 |= IB_BTH_SOLICITED; 359 bth0 |= IB_BTH_SOLICITED;
360 bth0 |= extra_bytes << 20; 360 bth0 |= extra_bytes << 20;
diff --git a/drivers/infiniband/hw/qib/qib_verbs.h b/drivers/infiniband/hw/qib/qib_verbs.h
index 0c19ef0c4123..487606024659 100644
--- a/drivers/infiniband/hw/qib/qib_verbs.h
+++ b/drivers/infiniband/hw/qib/qib_verbs.h
@@ -367,9 +367,10 @@ struct qib_rwq {
367 367
368struct qib_rq { 368struct qib_rq {
369 struct qib_rwq *wq; 369 struct qib_rwq *wq;
370 spinlock_t lock; /* protect changes in this struct */
371 u32 size; /* size of RWQE array */ 370 u32 size; /* size of RWQE array */
372 u8 max_sge; 371 u8 max_sge;
372 spinlock_t lock /* protect changes in this struct */
373 ____cacheline_aligned_in_smp;
373}; 374};
374 375
375struct qib_srq { 376struct qib_srq {
@@ -412,31 +413,75 @@ struct qib_ack_entry {
412 */ 413 */
413struct qib_qp { 414struct qib_qp {
414 struct ib_qp ibqp; 415 struct ib_qp ibqp;
415 struct qib_qp *next; /* link list for QPN hash table */ 416 /* read mostly fields above and below */
416 struct qib_qp *timer_next; /* link list for qib_ib_timer() */
417 struct list_head iowait; /* link for wait PIO buf */
418 struct list_head rspwait; /* link for waititing to respond */
419 struct ib_ah_attr remote_ah_attr; 417 struct ib_ah_attr remote_ah_attr;
420 struct ib_ah_attr alt_ah_attr; 418 struct ib_ah_attr alt_ah_attr;
421 struct qib_ib_header s_hdr; /* next packet header to send */ 419 struct qib_qp *next; /* link list for QPN hash table */
422 atomic_t refcount; 420 struct qib_swqe *s_wq; /* send work queue */
423 wait_queue_head_t wait;
424 wait_queue_head_t wait_dma;
425 struct timer_list s_timer;
426 struct work_struct s_work;
427 struct qib_mmap_info *ip; 421 struct qib_mmap_info *ip;
422 struct qib_ib_header *s_hdr; /* next packet header to send */
423 unsigned long timeout_jiffies; /* computed from timeout */
424
425 enum ib_mtu path_mtu;
426 u32 remote_qpn;
427 u32 pmtu; /* decoded from path_mtu */
428 u32 qkey; /* QKEY for this QP (for UD or RD) */
429 u32 s_size; /* send work queue size */
430 u32 s_rnr_timeout; /* number of milliseconds for RNR timeout */
431
432 u8 state; /* QP state */
433 u8 qp_access_flags;
434 u8 alt_timeout; /* Alternate path timeout for this QP */
435 u8 timeout; /* Timeout for this QP */
436 u8 s_srate;
437 u8 s_mig_state;
438 u8 port_num;
439 u8 s_pkey_index; /* PKEY index to use */
440 u8 s_alt_pkey_index; /* Alternate path PKEY index to use */
441 u8 r_max_rd_atomic; /* max number of RDMA read/atomic to receive */
442 u8 s_max_rd_atomic; /* max number of RDMA read/atomic to send */
443 u8 s_retry_cnt; /* number of times to retry */
444 u8 s_rnr_retry_cnt;
445 u8 r_min_rnr_timer; /* retry timeout value for RNR NAKs */
446 u8 s_max_sge; /* size of s_wq->sg_list */
447 u8 s_draining;
448
449 /* start of read/write fields */
450
451 atomic_t refcount ____cacheline_aligned_in_smp;
452 wait_queue_head_t wait;
453
454
455 struct qib_ack_entry s_ack_queue[QIB_MAX_RDMA_ATOMIC + 1]
456 ____cacheline_aligned_in_smp;
457 struct qib_sge_state s_rdma_read_sge;
458
459 spinlock_t r_lock ____cacheline_aligned_in_smp; /* used for APM */
460 unsigned long r_aflags;
461 u64 r_wr_id; /* ID for current receive WQE */
462 u32 r_ack_psn; /* PSN for next ACK or atomic ACK */
463 u32 r_len; /* total length of r_sge */
464 u32 r_rcv_len; /* receive data len processed */
465 u32 r_psn; /* expected rcv packet sequence number */
466 u32 r_msn; /* message sequence number */
467
468 u8 r_state; /* opcode of last packet received */
469 u8 r_flags;
470 u8 r_head_ack_queue; /* index into s_ack_queue[] */
471
472 struct list_head rspwait; /* link for waititing to respond */
473
474 struct qib_sge_state r_sge; /* current receive data */
475 struct qib_rq r_rq; /* receive work queue */
476
477 spinlock_t s_lock ____cacheline_aligned_in_smp;
428 struct qib_sge_state *s_cur_sge; 478 struct qib_sge_state *s_cur_sge;
479 u32 s_flags;
429 struct qib_verbs_txreq *s_tx; 480 struct qib_verbs_txreq *s_tx;
430 struct qib_mregion *s_rdma_mr; 481 struct qib_swqe *s_wqe;
431 struct qib_sge_state s_sge; /* current send request data */ 482 struct qib_sge_state s_sge; /* current send request data */
432 struct qib_ack_entry s_ack_queue[QIB_MAX_RDMA_ATOMIC + 1]; 483 struct qib_mregion *s_rdma_mr;
433 struct qib_sge_state s_ack_rdma_sge;
434 struct qib_sge_state s_rdma_read_sge;
435 struct qib_sge_state r_sge; /* current receive data */
436 spinlock_t r_lock; /* used for APM */
437 spinlock_t s_lock;
438 atomic_t s_dma_busy; 484 atomic_t s_dma_busy;
439 u32 s_flags;
440 u32 s_cur_size; /* size of send packet in bytes */ 485 u32 s_cur_size; /* size of send packet in bytes */
441 u32 s_len; /* total length of s_sge */ 486 u32 s_len; /* total length of s_sge */
442 u32 s_rdma_read_len; /* total length of s_rdma_read_sge */ 487 u32 s_rdma_read_len; /* total length of s_rdma_read_sge */
@@ -447,60 +492,34 @@ struct qib_qp {
447 u32 s_psn; /* current packet sequence number */ 492 u32 s_psn; /* current packet sequence number */
448 u32 s_ack_rdma_psn; /* PSN for sending RDMA read responses */ 493 u32 s_ack_rdma_psn; /* PSN for sending RDMA read responses */
449 u32 s_ack_psn; /* PSN for acking sends and RDMA writes */ 494 u32 s_ack_psn; /* PSN for acking sends and RDMA writes */
450 u32 s_rnr_timeout; /* number of milliseconds for RNR timeout */ 495 u32 s_head; /* new entries added here */
451 u32 r_ack_psn; /* PSN for next ACK or atomic ACK */ 496 u32 s_tail; /* next entry to process */
452 u64 r_wr_id; /* ID for current receive WQE */ 497 u32 s_cur; /* current work queue entry */
453 unsigned long r_aflags; 498 u32 s_acked; /* last un-ACK'ed entry */
454 u32 r_len; /* total length of r_sge */ 499 u32 s_last; /* last completed entry */
455 u32 r_rcv_len; /* receive data len processed */ 500 u32 s_ssn; /* SSN of tail entry */
456 u32 r_psn; /* expected rcv packet sequence number */ 501 u32 s_lsn; /* limit sequence number (credit) */
457 u32 r_msn; /* message sequence number */
458 u16 s_hdrwords; /* size of s_hdr in 32 bit words */ 502 u16 s_hdrwords; /* size of s_hdr in 32 bit words */
459 u16 s_rdma_ack_cnt; 503 u16 s_rdma_ack_cnt;
460 u8 state; /* QP state */
461 u8 s_state; /* opcode of last packet sent */ 504 u8 s_state; /* opcode of last packet sent */
462 u8 s_ack_state; /* opcode of packet to ACK */ 505 u8 s_ack_state; /* opcode of packet to ACK */
463 u8 s_nak_state; /* non-zero if NAK is pending */ 506 u8 s_nak_state; /* non-zero if NAK is pending */
464 u8 r_state; /* opcode of last packet received */
465 u8 r_nak_state; /* non-zero if NAK is pending */ 507 u8 r_nak_state; /* non-zero if NAK is pending */
466 u8 r_min_rnr_timer; /* retry timeout value for RNR NAKs */
467 u8 r_flags;
468 u8 r_max_rd_atomic; /* max number of RDMA read/atomic to receive */
469 u8 r_head_ack_queue; /* index into s_ack_queue[] */
470 u8 qp_access_flags;
471 u8 s_max_sge; /* size of s_wq->sg_list */
472 u8 s_retry_cnt; /* number of times to retry */
473 u8 s_rnr_retry_cnt;
474 u8 s_retry; /* requester retry counter */ 508 u8 s_retry; /* requester retry counter */
475 u8 s_rnr_retry; /* requester RNR retry counter */ 509 u8 s_rnr_retry; /* requester RNR retry counter */
476 u8 s_pkey_index; /* PKEY index to use */
477 u8 s_alt_pkey_index; /* Alternate path PKEY index to use */
478 u8 s_max_rd_atomic; /* max number of RDMA read/atomic to send */
479 u8 s_num_rd_atomic; /* number of RDMA read/atomic pending */ 510 u8 s_num_rd_atomic; /* number of RDMA read/atomic pending */
480 u8 s_tail_ack_queue; /* index into s_ack_queue[] */ 511 u8 s_tail_ack_queue; /* index into s_ack_queue[] */
481 u8 s_srate; 512
482 u8 s_draining; 513 struct qib_sge_state s_ack_rdma_sge;
483 u8 s_mig_state; 514 struct timer_list s_timer;
484 u8 timeout; /* Timeout for this QP */ 515 struct list_head iowait; /* link for wait PIO buf */
485 u8 alt_timeout; /* Alternate path timeout for this QP */ 516
486 u8 port_num; 517 struct work_struct s_work;
487 enum ib_mtu path_mtu; 518
488 u32 pmtu; /* decoded from path_mtu */ 519 wait_queue_head_t wait_dma;
489 u32 remote_qpn; 520
490 u32 qkey; /* QKEY for this QP (for UD or RD) */ 521 struct qib_sge r_sg_list[0] /* verified SGEs */
491 u32 s_size; /* send work queue size */ 522 ____cacheline_aligned_in_smp;
492 u32 s_head; /* new entries added here */
493 u32 s_tail; /* next entry to process */
494 u32 s_cur; /* current work queue entry */
495 u32 s_acked; /* last un-ACK'ed entry */
496 u32 s_last; /* last completed entry */
497 u32 s_ssn; /* SSN of tail entry */
498 u32 s_lsn; /* limit sequence number (credit) */
499 unsigned long timeout_jiffies; /* computed from timeout */
500 struct qib_swqe *s_wq; /* send work queue */
501 struct qib_swqe *s_wqe;
502 struct qib_rq r_rq; /* receive work queue */
503 struct qib_sge r_sg_list[0]; /* verified SGEs */
504}; 523};
505 524
506/* 525/*