aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband/hw/ipath/ipath_verbs.c
diff options
context:
space:
mode:
authorRalph Campbell <ralph.campbell@qlogic.com>2007-07-25 14:08:28 -0400
committerRoland Dreier <rolandd@cisco.com>2007-10-09 23:05:49 -0400
commit4ee97180ac76deb5a715ac45b7d7516e6ee82ae7 (patch)
tree6683d1c34d3f36271a9d8275a645ce67222ffc56 /drivers/infiniband/hw/ipath/ipath_verbs.c
parent210d6ca3db058cd1d6e6fd235ee3e25d6ac221cd (diff)
IB/ipath: Change UD to queue work requests like RC & UC
The code to post UD sends tried to process work requests at the time ib_post_send() is called without using a WQE queue. This was fine as long as HW resources were available for sending a packet. This patch changes UD to be handled more like RC and UC and shares more code. Signed-off-by: Ralph Campbell <ralph.campbell@qlogic.com> Signed-off-by: Roland Dreier <rolandd@cisco.com>
Diffstat (limited to 'drivers/infiniband/hw/ipath/ipath_verbs.c')
-rw-r--r--drivers/infiniband/hw/ipath/ipath_verbs.c241
1 files changed, 161 insertions, 80 deletions
diff --git a/drivers/infiniband/hw/ipath/ipath_verbs.c b/drivers/infiniband/hw/ipath/ipath_verbs.c
index 559d4a662937..3cc82b62b3c5 100644
--- a/drivers/infiniband/hw/ipath/ipath_verbs.c
+++ b/drivers/infiniband/hw/ipath/ipath_verbs.c
@@ -231,6 +231,103 @@ void ipath_skip_sge(struct ipath_sge_state *ss, u32 length)
231} 231}
232 232
233/** 233/**
234 * ipath_post_one_send - post one RC, UC, or UD send work request
235 * @qp: the QP to post on
236 * @wr: the work request to send
237 */
238static int ipath_post_one_send(struct ipath_qp *qp, struct ib_send_wr *wr)
239{
240 struct ipath_swqe *wqe;
241 u32 next;
242 int i;
243 int j;
244 int acc;
245 int ret;
246 unsigned long flags;
247
248 spin_lock_irqsave(&qp->s_lock, flags);
249
250 /* Check that state is OK to post send. */
251 if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_SEND_OK))
252 goto bail_inval;
253
254 /* IB spec says that num_sge == 0 is OK. */
255 if (wr->num_sge > qp->s_max_sge)
256 goto bail_inval;
257
258 /*
259 * Don't allow RDMA reads or atomic operations on UC or
260 * undefined operations.
261 * Make sure buffer is large enough to hold the result for atomics.
262 */
263 if (qp->ibqp.qp_type == IB_QPT_UC) {
264 if ((unsigned) wr->opcode >= IB_WR_RDMA_READ)
265 goto bail_inval;
266 } else if (qp->ibqp.qp_type == IB_QPT_UD) {
267 /* Check UD opcode */
268 if (wr->opcode != IB_WR_SEND &&
269 wr->opcode != IB_WR_SEND_WITH_IMM)
270 goto bail_inval;
271 /* Check UD destination address PD */
272 if (qp->ibqp.pd != wr->wr.ud.ah->pd)
273 goto bail_inval;
274 } else if ((unsigned) wr->opcode > IB_WR_ATOMIC_FETCH_AND_ADD)
275 goto bail_inval;
276 else if (wr->opcode >= IB_WR_ATOMIC_CMP_AND_SWP &&
277 (wr->num_sge == 0 ||
278 wr->sg_list[0].length < sizeof(u64) ||
279 wr->sg_list[0].addr & (sizeof(u64) - 1)))
280 goto bail_inval;
281 else if (wr->opcode >= IB_WR_RDMA_READ && !qp->s_max_rd_atomic)
282 goto bail_inval;
283
284 next = qp->s_head + 1;
285 if (next >= qp->s_size)
286 next = 0;
287 if (next == qp->s_last)
288 goto bail_inval;
289
290 wqe = get_swqe_ptr(qp, qp->s_head);
291 wqe->wr = *wr;
292 wqe->ssn = qp->s_ssn++;
293 wqe->length = 0;
294 if (wr->num_sge) {
295 acc = wr->opcode >= IB_WR_RDMA_READ ?
296 IB_ACCESS_LOCAL_WRITE : 0;
297 for (i = 0, j = 0; i < wr->num_sge; i++) {
298 u32 length = wr->sg_list[i].length;
299 int ok;
300
301 if (length == 0)
302 continue;
303 ok = ipath_lkey_ok(qp, &wqe->sg_list[j],
304 &wr->sg_list[i], acc);
305 if (!ok)
306 goto bail_inval;
307 wqe->length += length;
308 j++;
309 }
310 wqe->wr.num_sge = j;
311 }
312 if (qp->ibqp.qp_type == IB_QPT_UC ||
313 qp->ibqp.qp_type == IB_QPT_RC) {
314 if (wqe->length > 0x80000000U)
315 goto bail_inval;
316 } else if (wqe->length > to_idev(qp->ibqp.device)->dd->ipath_ibmtu)
317 goto bail_inval;
318 qp->s_head = next;
319
320 ret = 0;
321 goto bail;
322
323bail_inval:
324 ret = -EINVAL;
325bail:
326 spin_unlock_irqrestore(&qp->s_lock, flags);
327 return ret;
328}
329
330/**
234 * ipath_post_send - post a send on a QP 331 * ipath_post_send - post a send on a QP
235 * @ibqp: the QP to post the send on 332 * @ibqp: the QP to post the send on
236 * @wr: the list of work requests to post 333 * @wr: the list of work requests to post
@@ -244,35 +341,17 @@ static int ipath_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
244 struct ipath_qp *qp = to_iqp(ibqp); 341 struct ipath_qp *qp = to_iqp(ibqp);
245 int err = 0; 342 int err = 0;
246 343
247 /* Check that state is OK to post send. */
248 if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_SEND_OK)) {
249 *bad_wr = wr;
250 err = -EINVAL;
251 goto bail;
252 }
253
254 for (; wr; wr = wr->next) { 344 for (; wr; wr = wr->next) {
255 switch (qp->ibqp.qp_type) { 345 err = ipath_post_one_send(qp, wr);
256 case IB_QPT_UC:
257 case IB_QPT_RC:
258 err = ipath_post_ruc_send(qp, wr);
259 break;
260
261 case IB_QPT_SMI:
262 case IB_QPT_GSI:
263 case IB_QPT_UD:
264 err = ipath_post_ud_send(qp, wr);
265 break;
266
267 default:
268 err = -EINVAL;
269 }
270 if (err) { 346 if (err) {
271 *bad_wr = wr; 347 *bad_wr = wr;
272 break; 348 goto bail;
273 } 349 }
274 } 350 }
275 351
352 /* Try to do the send work in the caller's context. */
353 ipath_do_send((unsigned long) qp);
354
276bail: 355bail:
277 return err; 356 return err;
278} 357}
@@ -641,11 +720,11 @@ static void copy_io(u32 __iomem *piobuf, struct ipath_sge_state *ss,
641 u32 len = ss->sge.length; 720 u32 len = ss->sge.length;
642 u32 off; 721 u32 off;
643 722
644 BUG_ON(len == 0);
645 if (len > length) 723 if (len > length)
646 len = length; 724 len = length;
647 if (len > ss->sge.sge_length) 725 if (len > ss->sge.sge_length)
648 len = ss->sge.sge_length; 726 len = ss->sge.sge_length;
727 BUG_ON(len == 0);
649 /* If the source address is not aligned, try to align it. */ 728 /* If the source address is not aligned, try to align it. */
650 off = (unsigned long)ss->sge.vaddr & (sizeof(u32) - 1); 729 off = (unsigned long)ss->sge.vaddr & (sizeof(u32) - 1);
651 if (off) { 730 if (off) {
@@ -767,30 +846,15 @@ static void copy_io(u32 __iomem *piobuf, struct ipath_sge_state *ss,
767 __raw_writel(last, piobuf); 846 __raw_writel(last, piobuf);
768} 847}
769 848
770/** 849static int ipath_verbs_send_pio(struct ipath_qp *qp, u32 *hdr, u32 hdrwords,
771 * ipath_verbs_send - send a packet 850 struct ipath_sge_state *ss, u32 len,
772 * @dd: the infinipath device 851 u32 plen, u32 dwords)
773 * @hdrwords: the number of words in the header
774 * @hdr: the packet header
775 * @len: the length of the packet in bytes
776 * @ss: the SGE to send
777 */
778int ipath_verbs_send(struct ipath_devdata *dd, u32 hdrwords,
779 u32 *hdr, u32 len, struct ipath_sge_state *ss)
780{ 852{
853 struct ipath_devdata *dd = to_idev(qp->ibqp.device)->dd;
781 u32 __iomem *piobuf; 854 u32 __iomem *piobuf;
782 unsigned flush_wc; 855 unsigned flush_wc;
783 u32 plen;
784 int ret; 856 int ret;
785 857
786 /* +1 is for the qword padding of pbc */
787 plen = hdrwords + ((len + 3) >> 2) + 1;
788 if (unlikely((plen << 2) > dd->ipath_ibmaxlen)) {
789 ret = -EINVAL;
790 goto bail;
791 }
792
793 /* Get a PIO buffer to use. */
794 piobuf = ipath_getpiobuf(dd, NULL); 858 piobuf = ipath_getpiobuf(dd, NULL);
795 if (unlikely(piobuf == NULL)) { 859 if (unlikely(piobuf == NULL)) {
796 ret = -EBUSY; 860 ret = -EBUSY;
@@ -831,13 +895,10 @@ int ipath_verbs_send(struct ipath_devdata *dd, u32 hdrwords,
831 /* The common case is aligned and contained in one segment. */ 895 /* The common case is aligned and contained in one segment. */
832 if (likely(ss->num_sge == 1 && len <= ss->sge.length && 896 if (likely(ss->num_sge == 1 && len <= ss->sge.length &&
833 !((unsigned long)ss->sge.vaddr & (sizeof(u32) - 1)))) { 897 !((unsigned long)ss->sge.vaddr & (sizeof(u32) - 1)))) {
834 u32 dwords;
835 u32 *addr = (u32 *) ss->sge.vaddr; 898 u32 *addr = (u32 *) ss->sge.vaddr;
836 899
837 /* Update address before sending packet. */ 900 /* Update address before sending packet. */
838 update_sge(ss, len); 901 update_sge(ss, len);
839 /* Need to round up for the last dword in the packet. */
840 dwords = (len + 3) >> 2;
841 if (flush_wc) { 902 if (flush_wc) {
842 __iowrite32_copy(piobuf, addr, dwords - 1); 903 __iowrite32_copy(piobuf, addr, dwords - 1);
843 /* must flush early everything before trigger word */ 904 /* must flush early everything before trigger word */
@@ -851,11 +912,37 @@ int ipath_verbs_send(struct ipath_devdata *dd, u32 hdrwords,
851 } 912 }
852 copy_io(piobuf, ss, len, flush_wc); 913 copy_io(piobuf, ss, len, flush_wc);
853done: 914done:
915 if (qp->s_wqe)
916 ipath_send_complete(qp, qp->s_wqe, IB_WC_SUCCESS);
854 ret = 0; 917 ret = 0;
855bail: 918bail:
856 return ret; 919 return ret;
857} 920}
858 921
922/**
923 * ipath_verbs_send - send a packet
924 * @qp: the QP to send on
925 * @hdr: the packet header
926 * @hdrwords: the number of words in the header
927 * @ss: the SGE to send
928 * @len: the length of the packet in bytes
929 */
930int ipath_verbs_send(struct ipath_qp *qp, struct ipath_ib_header *hdr,
931 u32 hdrwords, struct ipath_sge_state *ss, u32 len)
932{
933 u32 plen;
934 int ret;
935 u32 dwords = (len + 3) >> 2;
936
937 /* +1 is for the qword padding of pbc */
938 plen = hdrwords + dwords + 1;
939
940 ret = ipath_verbs_send_pio(qp, (u32 *) hdr, hdrwords,
941 ss, len, plen, dwords);
942
943 return ret;
944}
945
859int ipath_snapshot_counters(struct ipath_devdata *dd, u64 *swords, 946int ipath_snapshot_counters(struct ipath_devdata *dd, u64 *swords,
860 u64 *rwords, u64 *spkts, u64 *rpkts, 947 u64 *rwords, u64 *spkts, u64 *rpkts,
861 u64 *xmit_wait) 948 u64 *xmit_wait)
@@ -864,7 +951,6 @@ int ipath_snapshot_counters(struct ipath_devdata *dd, u64 *swords,
864 951
865 if (!(dd->ipath_flags & IPATH_INITTED)) { 952 if (!(dd->ipath_flags & IPATH_INITTED)) {
866 /* no hardware, freeze, etc. */ 953 /* no hardware, freeze, etc. */
867 ipath_dbg("unit %u not usable\n", dd->ipath_unit);
868 ret = -EINVAL; 954 ret = -EINVAL;
869 goto bail; 955 goto bail;
870 } 956 }
@@ -890,48 +976,44 @@ bail:
890int ipath_get_counters(struct ipath_devdata *dd, 976int ipath_get_counters(struct ipath_devdata *dd,
891 struct ipath_verbs_counters *cntrs) 977 struct ipath_verbs_counters *cntrs)
892{ 978{
979 struct ipath_cregs const *crp = dd->ipath_cregs;
893 int ret; 980 int ret;
894 981
895 if (!(dd->ipath_flags & IPATH_INITTED)) { 982 if (!(dd->ipath_flags & IPATH_INITTED)) {
896 /* no hardware, freeze, etc. */ 983 /* no hardware, freeze, etc. */
897 ipath_dbg("unit %u not usable\n", dd->ipath_unit);
898 ret = -EINVAL; 984 ret = -EINVAL;
899 goto bail; 985 goto bail;
900 } 986 }
901 cntrs->symbol_error_counter = 987 cntrs->symbol_error_counter =
902 ipath_snap_cntr(dd, dd->ipath_cregs->cr_ibsymbolerrcnt); 988 ipath_snap_cntr(dd, crp->cr_ibsymbolerrcnt);
903 cntrs->link_error_recovery_counter = 989 cntrs->link_error_recovery_counter =
904 ipath_snap_cntr(dd, dd->ipath_cregs->cr_iblinkerrrecovcnt); 990 ipath_snap_cntr(dd, crp->cr_iblinkerrrecovcnt);
905 /* 991 /*
906 * The link downed counter counts when the other side downs the 992 * The link downed counter counts when the other side downs the
907 * connection. We add in the number of times we downed the link 993 * connection. We add in the number of times we downed the link
908 * due to local link integrity errors to compensate. 994 * due to local link integrity errors to compensate.
909 */ 995 */
910 cntrs->link_downed_counter = 996 cntrs->link_downed_counter =
911 ipath_snap_cntr(dd, dd->ipath_cregs->cr_iblinkdowncnt); 997 ipath_snap_cntr(dd, crp->cr_iblinkdowncnt);
912 cntrs->port_rcv_errors = 998 cntrs->port_rcv_errors =
913 ipath_snap_cntr(dd, dd->ipath_cregs->cr_rxdroppktcnt) + 999 ipath_snap_cntr(dd, crp->cr_rxdroppktcnt) +
914 ipath_snap_cntr(dd, dd->ipath_cregs->cr_rcvovflcnt) + 1000 ipath_snap_cntr(dd, crp->cr_rcvovflcnt) +
915 ipath_snap_cntr(dd, dd->ipath_cregs->cr_portovflcnt) + 1001 ipath_snap_cntr(dd, crp->cr_portovflcnt) +
916 ipath_snap_cntr(dd, dd->ipath_cregs->cr_err_rlencnt) + 1002 ipath_snap_cntr(dd, crp->cr_err_rlencnt) +
917 ipath_snap_cntr(dd, dd->ipath_cregs->cr_invalidrlencnt) + 1003 ipath_snap_cntr(dd, crp->cr_invalidrlencnt) +
918 ipath_snap_cntr(dd, dd->ipath_cregs->cr_erricrccnt) + 1004 ipath_snap_cntr(dd, crp->cr_errlinkcnt) +
919 ipath_snap_cntr(dd, dd->ipath_cregs->cr_errvcrccnt) + 1005 ipath_snap_cntr(dd, crp->cr_erricrccnt) +
920 ipath_snap_cntr(dd, dd->ipath_cregs->cr_errlpcrccnt) + 1006 ipath_snap_cntr(dd, crp->cr_errvcrccnt) +
921 ipath_snap_cntr(dd, dd->ipath_cregs->cr_badformatcnt) + 1007 ipath_snap_cntr(dd, crp->cr_errlpcrccnt) +
1008 ipath_snap_cntr(dd, crp->cr_badformatcnt) +
922 dd->ipath_rxfc_unsupvl_errs; 1009 dd->ipath_rxfc_unsupvl_errs;
923 cntrs->port_rcv_remphys_errors = 1010 cntrs->port_rcv_remphys_errors =
924 ipath_snap_cntr(dd, dd->ipath_cregs->cr_rcvebpcnt); 1011 ipath_snap_cntr(dd, crp->cr_rcvebpcnt);
925 cntrs->port_xmit_discards = 1012 cntrs->port_xmit_discards = ipath_snap_cntr(dd, crp->cr_unsupvlcnt);
926 ipath_snap_cntr(dd, dd->ipath_cregs->cr_unsupvlcnt); 1013 cntrs->port_xmit_data = ipath_snap_cntr(dd, crp->cr_wordsendcnt);
927 cntrs->port_xmit_data = 1014 cntrs->port_rcv_data = ipath_snap_cntr(dd, crp->cr_wordrcvcnt);
928 ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt); 1015 cntrs->port_xmit_packets = ipath_snap_cntr(dd, crp->cr_pktsendcnt);
929 cntrs->port_rcv_data = 1016 cntrs->port_rcv_packets = ipath_snap_cntr(dd, crp->cr_pktrcvcnt);
930 ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
931 cntrs->port_xmit_packets =
932 ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
933 cntrs->port_rcv_packets =
934 ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
935 cntrs->local_link_integrity_errors = 1017 cntrs->local_link_integrity_errors =
936 (dd->ipath_flags & IPATH_GPIO_ERRINTRS) ? 1018 (dd->ipath_flags & IPATH_GPIO_ERRINTRS) ?
937 dd->ipath_lli_errs : dd->ipath_lli_errors; 1019 dd->ipath_lli_errs : dd->ipath_lli_errors;
@@ -1045,8 +1127,9 @@ static int ipath_query_port(struct ib_device *ibdev,
1045 u8 port, struct ib_port_attr *props) 1127 u8 port, struct ib_port_attr *props)
1046{ 1128{
1047 struct ipath_ibdev *dev = to_idev(ibdev); 1129 struct ipath_ibdev *dev = to_idev(ibdev);
1130 struct ipath_devdata *dd = dev->dd;
1048 enum ib_mtu mtu; 1131 enum ib_mtu mtu;
1049 u16 lid = dev->dd->ipath_lid; 1132 u16 lid = dd->ipath_lid;
1050 u64 ibcstat; 1133 u64 ibcstat;
1051 1134
1052 memset(props, 0, sizeof(*props)); 1135 memset(props, 0, sizeof(*props));
@@ -1054,16 +1137,16 @@ static int ipath_query_port(struct ib_device *ibdev,
1054 props->lmc = dev->mkeyprot_resv_lmc & 7; 1137 props->lmc = dev->mkeyprot_resv_lmc & 7;
1055 props->sm_lid = dev->sm_lid; 1138 props->sm_lid = dev->sm_lid;
1056 props->sm_sl = dev->sm_sl; 1139 props->sm_sl = dev->sm_sl;
1057 ibcstat = dev->dd->ipath_lastibcstat; 1140 ibcstat = dd->ipath_lastibcstat;
1058 props->state = ((ibcstat >> 4) & 0x3) + 1; 1141 props->state = ((ibcstat >> 4) & 0x3) + 1;
1059 /* See phys_state_show() */ 1142 /* See phys_state_show() */
1060 props->phys_state = ipath_cvt_physportstate[ 1143 props->phys_state = ipath_cvt_physportstate[
1061 dev->dd->ipath_lastibcstat & 0xf]; 1144 dd->ipath_lastibcstat & 0xf];
1062 props->port_cap_flags = dev->port_cap_flags; 1145 props->port_cap_flags = dev->port_cap_flags;
1063 props->gid_tbl_len = 1; 1146 props->gid_tbl_len = 1;
1064 props->max_msg_sz = 0x80000000; 1147 props->max_msg_sz = 0x80000000;
1065 props->pkey_tbl_len = ipath_get_npkeys(dev->dd); 1148 props->pkey_tbl_len = ipath_get_npkeys(dd);
1066 props->bad_pkey_cntr = ipath_get_cr_errpkey(dev->dd) - 1149 props->bad_pkey_cntr = ipath_get_cr_errpkey(dd) -
1067 dev->z_pkey_violations; 1150 dev->z_pkey_violations;
1068 props->qkey_viol_cntr = dev->qkey_violations; 1151 props->qkey_viol_cntr = dev->qkey_violations;
1069 props->active_width = IB_WIDTH_4X; 1152 props->active_width = IB_WIDTH_4X;
@@ -1073,12 +1156,12 @@ static int ipath_query_port(struct ib_device *ibdev,
1073 props->init_type_reply = 0; 1156 props->init_type_reply = 0;
1074 1157
1075 /* 1158 /*
1076 * Note: the chips support a maximum MTU of 4096, but the driver 1159 * Note: the chip supports a maximum MTU of 4096, but the driver
1077 * hasn't implemented this feature yet, so set the maximum value 1160 * hasn't implemented this feature yet, so set the maximum value
1078 * to 2048. 1161 * to 2048.
1079 */ 1162 */
1080 props->max_mtu = IB_MTU_2048; 1163 props->max_mtu = IB_MTU_2048;
1081 switch (dev->dd->ipath_ibmtu) { 1164 switch (dd->ipath_ibmtu) {
1082 case 4096: 1165 case 4096:
1083 mtu = IB_MTU_4096; 1166 mtu = IB_MTU_4096;
1084 break; 1167 break;
@@ -1427,9 +1510,7 @@ static int disable_timer(struct ipath_devdata *dd)
1427{ 1510{
1428 /* Disable GPIO bit 2 interrupt */ 1511 /* Disable GPIO bit 2 interrupt */
1429 if (dd->ipath_flags & IPATH_GPIO_INTR) { 1512 if (dd->ipath_flags & IPATH_GPIO_INTR) {
1430 u64 val;
1431 /* Disable GPIO bit 2 interrupt */ 1513 /* Disable GPIO bit 2 interrupt */
1432 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_gpio_mask);
1433 dd->ipath_gpio_mask &= ~((u64) (1 << IPATH_GPIO_PORT0_BIT)); 1514 dd->ipath_gpio_mask &= ~((u64) (1 << IPATH_GPIO_PORT0_BIT));
1434 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask, 1515 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
1435 dd->ipath_gpio_mask); 1516 dd->ipath_gpio_mask);