aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband/hw/ipath/ipath_verbs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/infiniband/hw/ipath/ipath_verbs.c')
-rw-r--r--drivers/infiniband/hw/ipath/ipath_verbs.c413
1 files changed, 388 insertions, 25 deletions
diff --git a/drivers/infiniband/hw/ipath/ipath_verbs.c b/drivers/infiniband/hw/ipath/ipath_verbs.c
index 32d8f882e56c..320a6d018de7 100644
--- a/drivers/infiniband/hw/ipath/ipath_verbs.c
+++ b/drivers/infiniband/hw/ipath/ipath_verbs.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006, 2007 QLogic Corporation. All rights reserved. 2 * Copyright (c) 2006, 2007, 2008 QLogic Corporation. All rights reserved.
3 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved. 3 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
4 * 4 *
5 * This software is available to you under a choice of one of two 5 * This software is available to you under a choice of one of two
@@ -242,6 +242,93 @@ static void ipath_flush_wqe(struct ipath_qp *qp, struct ib_send_wr *wr)
242 ipath_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 1); 242 ipath_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 1);
243} 243}
244 244
245/*
246 * Count the number of DMA descriptors needed to send length bytes of data.
247 * Don't modify the ipath_sge_state to get the count.
248 * Return zero if any of the segments is not aligned.
249 */
250static u32 ipath_count_sge(struct ipath_sge_state *ss, u32 length)
251{
252 struct ipath_sge *sg_list = ss->sg_list;
253 struct ipath_sge sge = ss->sge;
254 u8 num_sge = ss->num_sge;
255 u32 ndesc = 1; /* count the header */
256
257 while (length) {
258 u32 len = sge.length;
259
260 if (len > length)
261 len = length;
262 if (len > sge.sge_length)
263 len = sge.sge_length;
264 BUG_ON(len == 0);
265 if (((long) sge.vaddr & (sizeof(u32) - 1)) ||
266 (len != length && (len & (sizeof(u32) - 1)))) {
267 ndesc = 0;
268 break;
269 }
270 ndesc++;
271 sge.vaddr += len;
272 sge.length -= len;
273 sge.sge_length -= len;
274 if (sge.sge_length == 0) {
275 if (--num_sge)
276 sge = *sg_list++;
277 } else if (sge.length == 0 && sge.mr != NULL) {
278 if (++sge.n >= IPATH_SEGSZ) {
279 if (++sge.m >= sge.mr->mapsz)
280 break;
281 sge.n = 0;
282 }
283 sge.vaddr =
284 sge.mr->map[sge.m]->segs[sge.n].vaddr;
285 sge.length =
286 sge.mr->map[sge.m]->segs[sge.n].length;
287 }
288 length -= len;
289 }
290 return ndesc;
291}
292
293/*
294 * Copy from the SGEs to the data buffer.
295 */
296static void ipath_copy_from_sge(void *data, struct ipath_sge_state *ss,
297 u32 length)
298{
299 struct ipath_sge *sge = &ss->sge;
300
301 while (length) {
302 u32 len = sge->length;
303
304 if (len > length)
305 len = length;
306 if (len > sge->sge_length)
307 len = sge->sge_length;
308 BUG_ON(len == 0);
309 memcpy(data, sge->vaddr, len);
310 sge->vaddr += len;
311 sge->length -= len;
312 sge->sge_length -= len;
313 if (sge->sge_length == 0) {
314 if (--ss->num_sge)
315 *sge = *ss->sg_list++;
316 } else if (sge->length == 0 && sge->mr != NULL) {
317 if (++sge->n >= IPATH_SEGSZ) {
318 if (++sge->m >= sge->mr->mapsz)
319 break;
320 sge->n = 0;
321 }
322 sge->vaddr =
323 sge->mr->map[sge->m]->segs[sge->n].vaddr;
324 sge->length =
325 sge->mr->map[sge->m]->segs[sge->n].length;
326 }
327 data += len;
328 length -= len;
329 }
330}
331
245/** 332/**
246 * ipath_post_one_send - post one RC, UC, or UD send work request 333 * ipath_post_one_send - post one RC, UC, or UD send work request
247 * @qp: the QP to post on 334 * @qp: the QP to post on
@@ -866,27 +953,257 @@ static void copy_io(u32 __iomem *piobuf, struct ipath_sge_state *ss,
866 __raw_writel(last, piobuf); 953 __raw_writel(last, piobuf);
867} 954}
868 955
869static int ipath_verbs_send_pio(struct ipath_qp *qp, u32 *hdr, u32 hdrwords, 956/*
957 * Convert IB rate to delay multiplier.
958 */
959unsigned ipath_ib_rate_to_mult(enum ib_rate rate)
960{
961 switch (rate) {
962 case IB_RATE_2_5_GBPS: return 8;
963 case IB_RATE_5_GBPS: return 4;
964 case IB_RATE_10_GBPS: return 2;
965 case IB_RATE_20_GBPS: return 1;
966 default: return 0;
967 }
968}
969
970/*
971 * Convert delay multiplier to IB rate
972 */
973static enum ib_rate ipath_mult_to_ib_rate(unsigned mult)
974{
975 switch (mult) {
976 case 8: return IB_RATE_2_5_GBPS;
977 case 4: return IB_RATE_5_GBPS;
978 case 2: return IB_RATE_10_GBPS;
979 case 1: return IB_RATE_20_GBPS;
980 default: return IB_RATE_PORT_CURRENT;
981 }
982}
983
984static inline struct ipath_verbs_txreq *get_txreq(struct ipath_ibdev *dev)
985{
986 struct ipath_verbs_txreq *tx = NULL;
987 unsigned long flags;
988
989 spin_lock_irqsave(&dev->pending_lock, flags);
990 if (!list_empty(&dev->txreq_free)) {
991 struct list_head *l = dev->txreq_free.next;
992
993 list_del(l);
994 tx = list_entry(l, struct ipath_verbs_txreq, txreq.list);
995 }
996 spin_unlock_irqrestore(&dev->pending_lock, flags);
997 return tx;
998}
999
1000static inline void put_txreq(struct ipath_ibdev *dev,
1001 struct ipath_verbs_txreq *tx)
1002{
1003 unsigned long flags;
1004
1005 spin_lock_irqsave(&dev->pending_lock, flags);
1006 list_add(&tx->txreq.list, &dev->txreq_free);
1007 spin_unlock_irqrestore(&dev->pending_lock, flags);
1008}
1009
1010static void sdma_complete(void *cookie, int status)
1011{
1012 struct ipath_verbs_txreq *tx = cookie;
1013 struct ipath_qp *qp = tx->qp;
1014 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
1015
1016 /* Generate a completion queue entry if needed */
1017 if (qp->ibqp.qp_type != IB_QPT_RC && tx->wqe) {
1018 enum ib_wc_status ibs = status == IPATH_SDMA_TXREQ_S_OK ?
1019 IB_WC_SUCCESS : IB_WC_WR_FLUSH_ERR;
1020
1021 ipath_send_complete(qp, tx->wqe, ibs);
1022 }
1023
1024 if (tx->txreq.flags & IPATH_SDMA_TXREQ_F_FREEBUF)
1025 kfree(tx->txreq.map_addr);
1026 put_txreq(dev, tx);
1027
1028 if (atomic_dec_and_test(&qp->refcount))
1029 wake_up(&qp->wait);
1030}
1031
1032/*
1033 * Compute the number of clock cycles of delay before sending the next packet.
1034 * The multipliers reflect the number of clocks for the fastest rate so
1035 * one tick at 4xDDR is 8 ticks at 1xSDR.
1036 * If the destination port will take longer to receive a packet than
1037 * the outgoing link can send it, we need to delay sending the next packet
1038 * by the difference in time it takes the receiver to receive and the sender
1039 * to send this packet.
1040 * Note that this delay is always correct for UC and RC but not always
1041 * optimal for UD. For UD, the destination HCA can be different for each
1042 * packet, in which case, we could send packets to a different destination
1043 * while "waiting" for the delay. The overhead for doing this without
1044 * HW support is more than just paying the cost of delaying some packets
1045 * unnecessarily.
1046 */
1047static inline unsigned ipath_pkt_delay(u32 plen, u8 snd_mult, u8 rcv_mult)
1048{
1049 return (rcv_mult > snd_mult) ?
1050 (plen * (rcv_mult - snd_mult) + 1) >> 1 : 0;
1051}
1052
1053static int ipath_verbs_send_dma(struct ipath_qp *qp,
1054 struct ipath_ib_header *hdr, u32 hdrwords,
1055 struct ipath_sge_state *ss, u32 len,
1056 u32 plen, u32 dwords)
1057{
1058 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
1059 struct ipath_devdata *dd = dev->dd;
1060 struct ipath_verbs_txreq *tx;
1061 u32 *piobuf;
1062 u32 control;
1063 u32 ndesc;
1064 int ret;
1065
1066 tx = qp->s_tx;
1067 if (tx) {
1068 qp->s_tx = NULL;
1069 /* resend previously constructed packet */
1070 ret = ipath_sdma_verbs_send(dd, tx->ss, tx->len, tx);
1071 if (ret)
1072 qp->s_tx = tx;
1073 goto bail;
1074 }
1075
1076 tx = get_txreq(dev);
1077 if (!tx) {
1078 ret = -EBUSY;
1079 goto bail;
1080 }
1081
1082 /*
1083 * Get the saved delay count we computed for the previous packet
1084 * and save the delay count for this packet to be used next time
1085 * we get here.
1086 */
1087 control = qp->s_pkt_delay;
1088 qp->s_pkt_delay = ipath_pkt_delay(plen, dd->delay_mult, qp->s_dmult);
1089
1090 tx->qp = qp;
1091 atomic_inc(&qp->refcount);
1092 tx->wqe = qp->s_wqe;
1093 tx->txreq.callback = sdma_complete;
1094 tx->txreq.callback_cookie = tx;
1095 tx->txreq.flags = IPATH_SDMA_TXREQ_F_HEADTOHOST |
1096 IPATH_SDMA_TXREQ_F_INTREQ | IPATH_SDMA_TXREQ_F_FREEDESC;
1097 if (plen + 1 >= IPATH_SMALLBUF_DWORDS)
1098 tx->txreq.flags |= IPATH_SDMA_TXREQ_F_USELARGEBUF;
1099
1100 /* VL15 packets bypass credit check */
1101 if ((be16_to_cpu(hdr->lrh[0]) >> 12) == 15) {
1102 control |= 1ULL << 31;
1103 tx->txreq.flags |= IPATH_SDMA_TXREQ_F_VL15;
1104 }
1105
1106 if (len) {
1107 /*
1108 * Don't try to DMA if it takes more descriptors than
1109 * the queue holds.
1110 */
1111 ndesc = ipath_count_sge(ss, len);
1112 if (ndesc >= dd->ipath_sdma_descq_cnt)
1113 ndesc = 0;
1114 } else
1115 ndesc = 1;
1116 if (ndesc) {
1117 tx->hdr.pbc[0] = cpu_to_le32(plen);
1118 tx->hdr.pbc[1] = cpu_to_le32(control);
1119 memcpy(&tx->hdr.hdr, hdr, hdrwords << 2);
1120 tx->txreq.sg_count = ndesc;
1121 tx->map_len = (hdrwords + 2) << 2;
1122 tx->txreq.map_addr = &tx->hdr;
1123 ret = ipath_sdma_verbs_send(dd, ss, dwords, tx);
1124 if (ret) {
1125 /* save ss and length in dwords */
1126 tx->ss = ss;
1127 tx->len = dwords;
1128 qp->s_tx = tx;
1129 }
1130 goto bail;
1131 }
1132
1133 /* Allocate a buffer and copy the header and payload to it. */
1134 tx->map_len = (plen + 1) << 2;
1135 piobuf = kmalloc(tx->map_len, GFP_ATOMIC);
1136 if (unlikely(piobuf == NULL)) {
1137 ret = -EBUSY;
1138 goto err_tx;
1139 }
1140 tx->txreq.map_addr = piobuf;
1141 tx->txreq.flags |= IPATH_SDMA_TXREQ_F_FREEBUF;
1142 tx->txreq.sg_count = 1;
1143
1144 *piobuf++ = (__force u32) cpu_to_le32(plen);
1145 *piobuf++ = (__force u32) cpu_to_le32(control);
1146 memcpy(piobuf, hdr, hdrwords << 2);
1147 ipath_copy_from_sge(piobuf + hdrwords, ss, len);
1148
1149 ret = ipath_sdma_verbs_send(dd, NULL, 0, tx);
1150 /*
1151 * If we couldn't queue the DMA request, save the info
1152 * and try again later rather than destroying the
1153 * buffer and undoing the side effects of the copy.
1154 */
1155 if (ret) {
1156 tx->ss = NULL;
1157 tx->len = 0;
1158 qp->s_tx = tx;
1159 }
1160 dev->n_unaligned++;
1161 goto bail;
1162
1163err_tx:
1164 if (atomic_dec_and_test(&qp->refcount))
1165 wake_up(&qp->wait);
1166 put_txreq(dev, tx);
1167bail:
1168 return ret;
1169}
1170
1171static int ipath_verbs_send_pio(struct ipath_qp *qp,
1172 struct ipath_ib_header *ibhdr, u32 hdrwords,
870 struct ipath_sge_state *ss, u32 len, 1173 struct ipath_sge_state *ss, u32 len,
871 u32 plen, u32 dwords) 1174 u32 plen, u32 dwords)
872{ 1175{
873 struct ipath_devdata *dd = to_idev(qp->ibqp.device)->dd; 1176 struct ipath_devdata *dd = to_idev(qp->ibqp.device)->dd;
1177 u32 *hdr = (u32 *) ibhdr;
874 u32 __iomem *piobuf; 1178 u32 __iomem *piobuf;
875 unsigned flush_wc; 1179 unsigned flush_wc;
1180 u32 control;
876 int ret; 1181 int ret;
877 1182
878 piobuf = ipath_getpiobuf(dd, NULL); 1183 piobuf = ipath_getpiobuf(dd, plen, NULL);
879 if (unlikely(piobuf == NULL)) { 1184 if (unlikely(piobuf == NULL)) {
880 ret = -EBUSY; 1185 ret = -EBUSY;
881 goto bail; 1186 goto bail;
882 } 1187 }
883 1188
884 /* 1189 /*
885 * Write len to control qword, no flags. 1190 * Get the saved delay count we computed for the previous packet
1191 * and save the delay count for this packet to be used next time
1192 * we get here.
1193 */
1194 control = qp->s_pkt_delay;
1195 qp->s_pkt_delay = ipath_pkt_delay(plen, dd->delay_mult, qp->s_dmult);
1196
1197 /* VL15 packets bypass credit check */
1198 if ((be16_to_cpu(ibhdr->lrh[0]) >> 12) == 15)
1199 control |= 1ULL << 31;
1200
1201 /*
1202 * Write the length to the control qword plus any needed flags.
886 * We have to flush after the PBC for correctness on some cpus 1203 * We have to flush after the PBC for correctness on some cpus
887 * or WC buffer can be written out of order. 1204 * or WC buffer can be written out of order.
888 */ 1205 */
889 writeq(plen, piobuf); 1206 writeq(((u64) control << 32) | plen, piobuf);
890 piobuf += 2; 1207 piobuf += 2;
891 1208
892 flush_wc = dd->ipath_flags & IPATH_PIO_FLUSH_WC; 1209 flush_wc = dd->ipath_flags & IPATH_PIO_FLUSH_WC;
@@ -961,15 +1278,25 @@ int ipath_verbs_send(struct ipath_qp *qp, struct ipath_ib_header *hdr,
961 */ 1278 */
962 plen = hdrwords + dwords + 1; 1279 plen = hdrwords + dwords + 1;
963 1280
964 /* Drop non-VL15 packets if we are not in the active state */ 1281 /*
965 if (!(dd->ipath_flags & IPATH_LINKACTIVE) && 1282 * VL15 packets (IB_QPT_SMI) will always use PIO, so we
966 qp->ibqp.qp_type != IB_QPT_SMI) { 1283 * can defer SDMA restart until link goes ACTIVE without
1284 * worrying about just how we got there.
1285 */
1286 if (qp->ibqp.qp_type == IB_QPT_SMI)
1287 ret = ipath_verbs_send_pio(qp, hdr, hdrwords, ss, len,
1288 plen, dwords);
1289 /* All non-VL15 packets are dropped if link is not ACTIVE */
1290 else if (!(dd->ipath_flags & IPATH_LINKACTIVE)) {
967 if (qp->s_wqe) 1291 if (qp->s_wqe)
968 ipath_send_complete(qp, qp->s_wqe, IB_WC_SUCCESS); 1292 ipath_send_complete(qp, qp->s_wqe, IB_WC_SUCCESS);
969 ret = 0; 1293 ret = 0;
970 } else 1294 } else if (dd->ipath_flags & IPATH_HAS_SEND_DMA)
971 ret = ipath_verbs_send_pio(qp, (u32 *) hdr, hdrwords, 1295 ret = ipath_verbs_send_dma(qp, hdr, hdrwords, ss, len,
972 ss, len, plen, dwords); 1296 plen, dwords);
1297 else
1298 ret = ipath_verbs_send_pio(qp, hdr, hdrwords, ss, len,
1299 plen, dwords);
973 1300
974 return ret; 1301 return ret;
975} 1302}
@@ -1038,6 +1365,12 @@ int ipath_get_counters(struct ipath_devdata *dd,
1038 ipath_snap_cntr(dd, crp->cr_errlpcrccnt) + 1365 ipath_snap_cntr(dd, crp->cr_errlpcrccnt) +
1039 ipath_snap_cntr(dd, crp->cr_badformatcnt) + 1366 ipath_snap_cntr(dd, crp->cr_badformatcnt) +
1040 dd->ipath_rxfc_unsupvl_errs; 1367 dd->ipath_rxfc_unsupvl_errs;
1368 if (crp->cr_rxotherlocalphyerrcnt)
1369 cntrs->port_rcv_errors +=
1370 ipath_snap_cntr(dd, crp->cr_rxotherlocalphyerrcnt);
1371 if (crp->cr_rxvlerrcnt)
1372 cntrs->port_rcv_errors +=
1373 ipath_snap_cntr(dd, crp->cr_rxvlerrcnt);
1041 cntrs->port_rcv_remphys_errors = 1374 cntrs->port_rcv_remphys_errors =
1042 ipath_snap_cntr(dd, crp->cr_rcvebpcnt); 1375 ipath_snap_cntr(dd, crp->cr_rcvebpcnt);
1043 cntrs->port_xmit_discards = ipath_snap_cntr(dd, crp->cr_unsupvlcnt); 1376 cntrs->port_xmit_discards = ipath_snap_cntr(dd, crp->cr_unsupvlcnt);
@@ -1046,9 +1379,16 @@ int ipath_get_counters(struct ipath_devdata *dd,
1046 cntrs->port_xmit_packets = ipath_snap_cntr(dd, crp->cr_pktsendcnt); 1379 cntrs->port_xmit_packets = ipath_snap_cntr(dd, crp->cr_pktsendcnt);
1047 cntrs->port_rcv_packets = ipath_snap_cntr(dd, crp->cr_pktrcvcnt); 1380 cntrs->port_rcv_packets = ipath_snap_cntr(dd, crp->cr_pktrcvcnt);
1048 cntrs->local_link_integrity_errors = 1381 cntrs->local_link_integrity_errors =
1049 (dd->ipath_flags & IPATH_GPIO_ERRINTRS) ? 1382 crp->cr_locallinkintegrityerrcnt ?
1050 dd->ipath_lli_errs : dd->ipath_lli_errors; 1383 ipath_snap_cntr(dd, crp->cr_locallinkintegrityerrcnt) :
1051 cntrs->excessive_buffer_overrun_errors = dd->ipath_overrun_thresh_errs; 1384 ((dd->ipath_flags & IPATH_GPIO_ERRINTRS) ?
1385 dd->ipath_lli_errs : dd->ipath_lli_errors);
1386 cntrs->excessive_buffer_overrun_errors =
1387 crp->cr_excessbufferovflcnt ?
1388 ipath_snap_cntr(dd, crp->cr_excessbufferovflcnt) :
1389 dd->ipath_overrun_thresh_errs;
1390 cntrs->vl15_dropped = crp->cr_vl15droppedpktcnt ?
1391 ipath_snap_cntr(dd, crp->cr_vl15droppedpktcnt) : 0;
1052 1392
1053 ret = 0; 1393 ret = 0;
1054 1394
@@ -1183,7 +1523,9 @@ static int ipath_query_port(struct ib_device *ibdev,
1183 props->sm_lid = dev->sm_lid; 1523 props->sm_lid = dev->sm_lid;
1184 props->sm_sl = dev->sm_sl; 1524 props->sm_sl = dev->sm_sl;
1185 ibcstat = dd->ipath_lastibcstat; 1525 ibcstat = dd->ipath_lastibcstat;
1186 props->state = ((ibcstat >> 4) & 0x3) + 1; 1526 /* map LinkState to IB portinfo values. */
1527 props->state = ipath_ib_linkstate(dd, ibcstat) + 1;
1528
1187 /* See phys_state_show() */ 1529 /* See phys_state_show() */
1188 props->phys_state = /* MEA: assumes shift == 0 */ 1530 props->phys_state = /* MEA: assumes shift == 0 */
1189 ipath_cvt_physportstate[dd->ipath_lastibcstat & 1531 ipath_cvt_physportstate[dd->ipath_lastibcstat &
@@ -1195,18 +1537,13 @@ static int ipath_query_port(struct ib_device *ibdev,
1195 props->bad_pkey_cntr = ipath_get_cr_errpkey(dd) - 1537 props->bad_pkey_cntr = ipath_get_cr_errpkey(dd) -
1196 dev->z_pkey_violations; 1538 dev->z_pkey_violations;
1197 props->qkey_viol_cntr = dev->qkey_violations; 1539 props->qkey_viol_cntr = dev->qkey_violations;
1198 props->active_width = IB_WIDTH_4X; 1540 props->active_width = dd->ipath_link_width_active;
1199 /* See rate_show() */ 1541 /* See rate_show() */
1200 props->active_speed = 1; /* Regular 10Mbs speed. */ 1542 props->active_speed = dd->ipath_link_speed_active;
1201 props->max_vl_num = 1; /* VLCap = VL0 */ 1543 props->max_vl_num = 1; /* VLCap = VL0 */
1202 props->init_type_reply = 0; 1544 props->init_type_reply = 0;
1203 1545
1204 /* 1546 props->max_mtu = ipath_mtu4096 ? IB_MTU_4096 : IB_MTU_2048;
1205 * Note: the chip supports a maximum MTU of 4096, but the driver
1206 * hasn't implemented this feature yet, so set the maximum value
1207 * to 2048.
1208 */
1209 props->max_mtu = IB_MTU_2048;
1210 switch (dd->ipath_ibmtu) { 1547 switch (dd->ipath_ibmtu) {
1211 case 4096: 1548 case 4096:
1212 mtu = IB_MTU_4096; 1549 mtu = IB_MTU_4096;
@@ -1399,6 +1736,7 @@ static struct ib_ah *ipath_create_ah(struct ib_pd *pd,
1399 1736
1400 /* ib_create_ah() will initialize ah->ibah. */ 1737 /* ib_create_ah() will initialize ah->ibah. */
1401 ah->attr = *ah_attr; 1738 ah->attr = *ah_attr;
1739 ah->attr.static_rate = ipath_ib_rate_to_mult(ah_attr->static_rate);
1402 1740
1403 ret = &ah->ibah; 1741 ret = &ah->ibah;
1404 1742
@@ -1432,6 +1770,7 @@ static int ipath_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
1432 struct ipath_ah *ah = to_iah(ibah); 1770 struct ipath_ah *ah = to_iah(ibah);
1433 1771
1434 *ah_attr = ah->attr; 1772 *ah_attr = ah->attr;
1773 ah_attr->static_rate = ipath_mult_to_ib_rate(ah->attr.static_rate);
1435 1774
1436 return 0; 1775 return 0;
1437} 1776}
@@ -1581,6 +1920,8 @@ int ipath_register_ib_device(struct ipath_devdata *dd)
1581 struct ipath_verbs_counters cntrs; 1920 struct ipath_verbs_counters cntrs;
1582 struct ipath_ibdev *idev; 1921 struct ipath_ibdev *idev;
1583 struct ib_device *dev; 1922 struct ib_device *dev;
1923 struct ipath_verbs_txreq *tx;
1924 unsigned i;
1584 int ret; 1925 int ret;
1585 1926
1586 idev = (struct ipath_ibdev *)ib_alloc_device(sizeof *idev); 1927 idev = (struct ipath_ibdev *)ib_alloc_device(sizeof *idev);
@@ -1591,6 +1932,17 @@ int ipath_register_ib_device(struct ipath_devdata *dd)
1591 1932
1592 dev = &idev->ibdev; 1933 dev = &idev->ibdev;
1593 1934
1935 if (dd->ipath_sdma_descq_cnt) {
1936 tx = kmalloc(dd->ipath_sdma_descq_cnt * sizeof *tx,
1937 GFP_KERNEL);
1938 if (tx == NULL) {
1939 ret = -ENOMEM;
1940 goto err_tx;
1941 }
1942 } else
1943 tx = NULL;
1944 idev->txreq_bufs = tx;
1945
1594 /* Only need to initialize non-zero fields. */ 1946 /* Only need to initialize non-zero fields. */
1595 spin_lock_init(&idev->n_pds_lock); 1947 spin_lock_init(&idev->n_pds_lock);
1596 spin_lock_init(&idev->n_ahs_lock); 1948 spin_lock_init(&idev->n_ahs_lock);
@@ -1631,15 +1983,17 @@ int ipath_register_ib_device(struct ipath_devdata *dd)
1631 INIT_LIST_HEAD(&idev->pending[2]); 1983 INIT_LIST_HEAD(&idev->pending[2]);
1632 INIT_LIST_HEAD(&idev->piowait); 1984 INIT_LIST_HEAD(&idev->piowait);
1633 INIT_LIST_HEAD(&idev->rnrwait); 1985 INIT_LIST_HEAD(&idev->rnrwait);
1986 INIT_LIST_HEAD(&idev->txreq_free);
1634 idev->pending_index = 0; 1987 idev->pending_index = 0;
1635 idev->port_cap_flags = 1988 idev->port_cap_flags =
1636 IB_PORT_SYS_IMAGE_GUID_SUP | IB_PORT_CLIENT_REG_SUP; 1989 IB_PORT_SYS_IMAGE_GUID_SUP | IB_PORT_CLIENT_REG_SUP;
1990 if (dd->ipath_flags & IPATH_HAS_LINK_LATENCY)
1991 idev->port_cap_flags |= IB_PORT_LINK_LATENCY_SUP;
1637 idev->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA; 1992 idev->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
1638 idev->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA; 1993 idev->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
1639 idev->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS; 1994 idev->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
1640 idev->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS; 1995 idev->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
1641 idev->pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT; 1996 idev->pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT;
1642 idev->link_width_enabled = 3; /* 1x or 4x */
1643 1997
1644 /* Snapshot current HW counters to "clear" them. */ 1998 /* Snapshot current HW counters to "clear" them. */
1645 ipath_get_counters(dd, &cntrs); 1999 ipath_get_counters(dd, &cntrs);
@@ -1661,6 +2015,9 @@ int ipath_register_ib_device(struct ipath_devdata *dd)
1661 cntrs.excessive_buffer_overrun_errors; 2015 cntrs.excessive_buffer_overrun_errors;
1662 idev->z_vl15_dropped = cntrs.vl15_dropped; 2016 idev->z_vl15_dropped = cntrs.vl15_dropped;
1663 2017
2018 for (i = 0; i < dd->ipath_sdma_descq_cnt; i++, tx++)
2019 list_add(&tx->txreq.list, &idev->txreq_free);
2020
1664 /* 2021 /*
1665 * The system image GUID is supposed to be the same for all 2022 * The system image GUID is supposed to be the same for all
1666 * IB HCAs in a single system but since there can be other 2023 * IB HCAs in a single system but since there can be other
@@ -1710,6 +2067,7 @@ int ipath_register_ib_device(struct ipath_devdata *dd)
1710 dev->phys_port_cnt = 1; 2067 dev->phys_port_cnt = 1;
1711 dev->num_comp_vectors = 1; 2068 dev->num_comp_vectors = 1;
1712 dev->dma_device = &dd->pcidev->dev; 2069 dev->dma_device = &dd->pcidev->dev;
2070 dev->class_dev.dev = dev->dma_device;
1713 dev->query_device = ipath_query_device; 2071 dev->query_device = ipath_query_device;
1714 dev->modify_device = ipath_modify_device; 2072 dev->modify_device = ipath_modify_device;
1715 dev->query_port = ipath_query_port; 2073 dev->query_port = ipath_query_port;
@@ -1774,6 +2132,8 @@ err_reg:
1774err_lk: 2132err_lk:
1775 kfree(idev->qp_table.table); 2133 kfree(idev->qp_table.table);
1776err_qp: 2134err_qp:
2135 kfree(idev->txreq_bufs);
2136err_tx:
1777 ib_dealloc_device(dev); 2137 ib_dealloc_device(dev);
1778 ipath_dev_err(dd, "cannot register verbs: %d!\n", -ret); 2138 ipath_dev_err(dd, "cannot register verbs: %d!\n", -ret);
1779 idev = NULL; 2139 idev = NULL;
@@ -1808,6 +2168,7 @@ void ipath_unregister_ib_device(struct ipath_ibdev *dev)
1808 ipath_free_all_qps(&dev->qp_table); 2168 ipath_free_all_qps(&dev->qp_table);
1809 kfree(dev->qp_table.table); 2169 kfree(dev->qp_table.table);
1810 kfree(dev->lk_table.table); 2170 kfree(dev->lk_table.table);
2171 kfree(dev->txreq_bufs);
1811 ib_dealloc_device(ibdev); 2172 ib_dealloc_device(ibdev);
1812} 2173}
1813 2174
@@ -1855,13 +2216,15 @@ static ssize_t show_stats(struct class_device *cdev, char *buf)
1855 "RC stalls %d\n" 2216 "RC stalls %d\n"
1856 "piobuf wait %d\n" 2217 "piobuf wait %d\n"
1857 "no piobuf %d\n" 2218 "no piobuf %d\n"
2219 "unaligned %d\n"
1858 "PKT drops %d\n" 2220 "PKT drops %d\n"
1859 "WQE errs %d\n", 2221 "WQE errs %d\n",
1860 dev->n_rc_resends, dev->n_rc_qacks, dev->n_rc_acks, 2222 dev->n_rc_resends, dev->n_rc_qacks, dev->n_rc_acks,
1861 dev->n_seq_naks, dev->n_rdma_seq, dev->n_rnr_naks, 2223 dev->n_seq_naks, dev->n_rdma_seq, dev->n_rnr_naks,
1862 dev->n_other_naks, dev->n_timeouts, 2224 dev->n_other_naks, dev->n_timeouts,
1863 dev->n_rdma_dup_busy, dev->n_rc_stalls, dev->n_piowait, 2225 dev->n_rdma_dup_busy, dev->n_rc_stalls, dev->n_piowait,
1864 dev->n_no_piobuf, dev->n_pkt_drops, dev->n_wqe_errs); 2226 dev->n_no_piobuf, dev->n_unaligned,
2227 dev->n_pkt_drops, dev->n_wqe_errs);
1865 for (i = 0; i < ARRAY_SIZE(dev->opstats); i++) { 2228 for (i = 0; i < ARRAY_SIZE(dev->opstats); i++) {
1866 const struct ipath_opcode_stats *si = &dev->opstats[i]; 2229 const struct ipath_opcode_stats *si = &dev->opstats[i];
1867 2230