]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/infiniband/ulp/ipoib/ipoib_cm.c
infiniband: add in export.h for files using EXPORT_SYMBOL/THIS_MODULE
[mirror_ubuntu-artful-kernel.git] / drivers / infiniband / ulp / ipoib / ipoib_cm.c
CommitLineData
839fcaba
MT
1/*
2 * Copyright (c) 2006 Mellanox Technologies. All rights reserved
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
839fcaba
MT
31 */
32
33#include <rdma/ib_cm.h>
839fcaba
MT
34#include <net/dst.h>
35#include <net/icmp.h>
36#include <linux/icmpv6.h>
518b1646 37#include <linux/delay.h>
5a0e3ad6 38#include <linux/slab.h>
10313cbb 39#include <linux/vmalloc.h>
839fcaba 40
68e995a2
PS
41#include "ipoib.h"
42
43int ipoib_max_conn_qp = 128;
44
45module_param_named(max_nonsrq_conn_qp, ipoib_max_conn_qp, int, 0444);
46MODULE_PARM_DESC(max_nonsrq_conn_qp,
47 "Max number of connected-mode QPs per interface "
48 "(applied only if shared receive queue is not available)");
49
839fcaba
MT
50#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
51static int data_debug_level;
52
53module_param_named(cm_data_debug_level, data_debug_level, int, 0644);
54MODULE_PARM_DESC(cm_data_debug_level,
55 "Enable data path debug tracing for connected mode if > 0");
56#endif
57
839fcaba
MT
58#define IPOIB_CM_IETF_ID 0x1000000000000000ULL
59
60#define IPOIB_CM_RX_UPDATE_TIME (256 * HZ)
61#define IPOIB_CM_RX_TIMEOUT (2 * 256 * HZ)
62#define IPOIB_CM_RX_DELAY (3 * 256 * HZ)
63#define IPOIB_CM_RX_UPDATE_MASK (0x3)
64
518b1646
MT
65static struct ib_qp_attr ipoib_cm_err_attr = {
66 .qp_state = IB_QPS_ERR
67};
68
09f60f8f 69#define IPOIB_CM_RX_DRAIN_WRID 0xffffffff
518b1646 70
ec56dc0b
MT
71static struct ib_send_wr ipoib_cm_rx_drain_wr = {
72 .wr_id = IPOIB_CM_RX_DRAIN_WRID,
73 .opcode = IB_WR_SEND,
518b1646
MT
74};
75
839fcaba
MT
76static int ipoib_cm_tx_handler(struct ib_cm_id *cm_id,
77 struct ib_cm_event *event);
78
1812063b 79static void ipoib_cm_dma_unmap_rx(struct ipoib_dev_priv *priv, int frags,
839fcaba
MT
80 u64 mapping[IPOIB_CM_RX_SG])
81{
82 int i;
83
84 ib_dma_unmap_single(priv->ca, mapping[0], IPOIB_CM_HEAD_SIZE, DMA_FROM_DEVICE);
85
1812063b 86 for (i = 0; i < frags; ++i)
839fcaba
MT
87 ib_dma_unmap_single(priv->ca, mapping[i + 1], PAGE_SIZE, DMA_FROM_DEVICE);
88}
89
68e995a2 90static int ipoib_cm_post_receive_srq(struct net_device *dev, int id)
839fcaba
MT
91{
92 struct ipoib_dev_priv *priv = netdev_priv(dev);
93 struct ib_recv_wr *bad_wr;
94 int i, ret;
95
1b524963 96 priv->cm.rx_wr.wr_id = id | IPOIB_OP_CM | IPOIB_OP_RECV;
839fcaba 97
586a6934 98 for (i = 0; i < priv->cm.num_frags; ++i)
839fcaba
MT
99 priv->cm.rx_sge[i].addr = priv->cm.srq_ring[id].mapping[i];
100
101 ret = ib_post_srq_recv(priv->cm.srq, &priv->cm.rx_wr, &bad_wr);
102 if (unlikely(ret)) {
103 ipoib_warn(priv, "post srq failed for buf %d (%d)\n", id, ret);
586a6934 104 ipoib_cm_dma_unmap_rx(priv, priv->cm.num_frags - 1,
1812063b 105 priv->cm.srq_ring[id].mapping);
839fcaba
MT
106 dev_kfree_skb_any(priv->cm.srq_ring[id].skb);
107 priv->cm.srq_ring[id].skb = NULL;
108 }
109
110 return ret;
111}
112
68e995a2 113static int ipoib_cm_post_receive_nonsrq(struct net_device *dev,
a7d834c4
RD
114 struct ipoib_cm_rx *rx,
115 struct ib_recv_wr *wr,
116 struct ib_sge *sge, int id)
68e995a2
PS
117{
118 struct ipoib_dev_priv *priv = netdev_priv(dev);
119 struct ib_recv_wr *bad_wr;
120 int i, ret;
121
a7d834c4 122 wr->wr_id = id | IPOIB_OP_CM | IPOIB_OP_RECV;
68e995a2
PS
123
124 for (i = 0; i < IPOIB_CM_RX_SG; ++i)
a7d834c4 125 sge[i].addr = rx->rx_ring[id].mapping[i];
68e995a2 126
a7d834c4 127 ret = ib_post_recv(rx->qp, wr, &bad_wr);
68e995a2
PS
128 if (unlikely(ret)) {
129 ipoib_warn(priv, "post recv failed for buf %d (%d)\n", id, ret);
130 ipoib_cm_dma_unmap_rx(priv, IPOIB_CM_RX_SG - 1,
131 rx->rx_ring[id].mapping);
132 dev_kfree_skb_any(rx->rx_ring[id].skb);
133 rx->rx_ring[id].skb = NULL;
134 }
135
136 return ret;
137}
138
139static struct sk_buff *ipoib_cm_alloc_rx_skb(struct net_device *dev,
140 struct ipoib_cm_rx_buf *rx_ring,
141 int id, int frags,
1812063b 142 u64 mapping[IPOIB_CM_RX_SG])
839fcaba
MT
143{
144 struct ipoib_dev_priv *priv = netdev_priv(dev);
145 struct sk_buff *skb;
146 int i;
147
148 skb = dev_alloc_skb(IPOIB_CM_HEAD_SIZE + 12);
149 if (unlikely(!skb))
1812063b 150 return NULL;
839fcaba
MT
151
152 /*
153 * IPoIB adds a 4 byte header. So we need 12 more bytes to align the
154 * IP header to a multiple of 16.
155 */
156 skb_reserve(skb, 12);
157
158 mapping[0] = ib_dma_map_single(priv->ca, skb->data, IPOIB_CM_HEAD_SIZE,
159 DMA_FROM_DEVICE);
160 if (unlikely(ib_dma_mapping_error(priv->ca, mapping[0]))) {
161 dev_kfree_skb_any(skb);
1812063b 162 return NULL;
839fcaba
MT
163 }
164
1812063b 165 for (i = 0; i < frags; i++) {
839fcaba
MT
166 struct page *page = alloc_page(GFP_ATOMIC);
167
168 if (!page)
169 goto partial_error;
170 skb_fill_page_desc(skb, i, page, 0, PAGE_SIZE);
171
5581be3b 172 mapping[i + 1] = ib_dma_map_page(priv->ca, page,
6371ea3d 173 0, PAGE_SIZE, DMA_FROM_DEVICE);
839fcaba
MT
174 if (unlikely(ib_dma_mapping_error(priv->ca, mapping[i + 1])))
175 goto partial_error;
176 }
177
68e995a2 178 rx_ring[id].skb = skb;
1812063b 179 return skb;
839fcaba
MT
180
181partial_error:
182
183 ib_dma_unmap_single(priv->ca, mapping[0], IPOIB_CM_HEAD_SIZE, DMA_FROM_DEVICE);
184
841adfca
RC
185 for (; i > 0; --i)
186 ib_dma_unmap_single(priv->ca, mapping[i], PAGE_SIZE, DMA_FROM_DEVICE);
839fcaba 187
8a2e65f8 188 dev_kfree_skb_any(skb);
1812063b 189 return NULL;
839fcaba
MT
190}
191
1efb6144
RD
192static void ipoib_cm_free_rx_ring(struct net_device *dev,
193 struct ipoib_cm_rx_buf *rx_ring)
194{
195 struct ipoib_dev_priv *priv = netdev_priv(dev);
196 int i;
197
198 for (i = 0; i < ipoib_recvq_size; ++i)
199 if (rx_ring[i].skb) {
200 ipoib_cm_dma_unmap_rx(priv, IPOIB_CM_RX_SG - 1,
201 rx_ring[i].mapping);
202 dev_kfree_skb_any(rx_ring[i].skb);
203 }
204
b1404069 205 vfree(rx_ring);
1efb6144
RD
206}
207
2337f809 208static void ipoib_cm_start_rx_drain(struct ipoib_dev_priv *priv)
518b1646 209{
ec56dc0b
MT
210 struct ib_send_wr *bad_wr;
211 struct ipoib_cm_rx *p;
518b1646 212
ec56dc0b 213 /* We only reserved 1 extra slot in CQ for drain WRs, so
518b1646
MT
214 * make sure we have at most 1 outstanding WR. */
215 if (list_empty(&priv->cm.rx_flush_list) ||
216 !list_empty(&priv->cm.rx_drain_list))
217 return;
218
ec56dc0b
MT
219 /*
220 * QPs on flush list are error state. This way, a "flush
221 * error" WC will be immediately generated for each WR we post.
222 */
223 p = list_entry(priv->cm.rx_flush_list.next, typeof(*p), list);
224 if (ib_post_send(p->qp, &ipoib_cm_rx_drain_wr, &bad_wr))
225 ipoib_warn(priv, "failed to post drain wr\n");
518b1646
MT
226
227 list_splice_init(&priv->cm.rx_flush_list, &priv->cm.rx_drain_list);
228}
229
230static void ipoib_cm_rx_event_handler(struct ib_event *event, void *ctx)
231{
232 struct ipoib_cm_rx *p = ctx;
233 struct ipoib_dev_priv *priv = netdev_priv(p->dev);
234 unsigned long flags;
235
236 if (event->event != IB_EVENT_QP_LAST_WQE_REACHED)
237 return;
238
239 spin_lock_irqsave(&priv->lock, flags);
240 list_move(&p->list, &priv->cm.rx_flush_list);
241 p->state = IPOIB_CM_RX_FLUSH;
242 ipoib_cm_start_rx_drain(priv);
243 spin_unlock_irqrestore(&priv->lock, flags);
244}
245
839fcaba
MT
246static struct ib_qp *ipoib_cm_create_rx_qp(struct net_device *dev,
247 struct ipoib_cm_rx *p)
248{
249 struct ipoib_dev_priv *priv = netdev_priv(dev);
250 struct ib_qp_init_attr attr = {
518b1646 251 .event_handler = ipoib_cm_rx_event_handler,
f56bcd80
EC
252 .send_cq = priv->recv_cq, /* For drain WR */
253 .recv_cq = priv->recv_cq,
839fcaba 254 .srq = priv->cm.srq,
ec56dc0b 255 .cap.max_send_wr = 1, /* For drain WR */
839fcaba
MT
256 .cap.max_send_sge = 1, /* FIXME: 0 Seems not to work */
257 .sq_sig_type = IB_SIGNAL_ALL_WR,
258 .qp_type = IB_QPT_RC,
259 .qp_context = p,
260 };
68e995a2
PS
261
262 if (!ipoib_cm_has_srq(dev)) {
263 attr.cap.max_recv_wr = ipoib_recvq_size;
264 attr.cap.max_recv_sge = IPOIB_CM_RX_SG;
265 }
266
839fcaba
MT
267 return ib_create_qp(priv->pd, &attr);
268}
269
270static int ipoib_cm_modify_rx_qp(struct net_device *dev,
68e995a2
PS
271 struct ib_cm_id *cm_id, struct ib_qp *qp,
272 unsigned psn)
839fcaba
MT
273{
274 struct ipoib_dev_priv *priv = netdev_priv(dev);
275 struct ib_qp_attr qp_attr;
276 int qp_attr_mask, ret;
277
278 qp_attr.qp_state = IB_QPS_INIT;
279 ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask);
280 if (ret) {
281 ipoib_warn(priv, "failed to init QP attr for INIT: %d\n", ret);
282 return ret;
283 }
284 ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask);
285 if (ret) {
286 ipoib_warn(priv, "failed to modify QP to INIT: %d\n", ret);
287 return ret;
288 }
289 qp_attr.qp_state = IB_QPS_RTR;
290 ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask);
291 if (ret) {
292 ipoib_warn(priv, "failed to init QP attr for RTR: %d\n", ret);
293 return ret;
294 }
295 qp_attr.rq_psn = psn;
296 ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask);
297 if (ret) {
298 ipoib_warn(priv, "failed to modify QP to RTR: %d\n", ret);
299 return ret;
300 }
ec56dc0b
MT
301
302 /*
303 * Current Mellanox HCA firmware won't generate completions
304 * with error for drain WRs unless the QP has been moved to
305 * RTS first. This work-around leaves a window where a QP has
306 * moved to error asynchronously, but this will eventually get
307 * fixed in firmware, so let's not error out if modify QP
308 * fails.
309 */
310 qp_attr.qp_state = IB_QPS_RTS;
311 ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask);
312 if (ret) {
313 ipoib_warn(priv, "failed to init QP attr for RTS: %d\n", ret);
314 return 0;
315 }
316 ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask);
317 if (ret) {
318 ipoib_warn(priv, "failed to modify QP to RTS: %d\n", ret);
319 return 0;
320 }
321
839fcaba
MT
322 return 0;
323}
324
a7d834c4
RD
325static void ipoib_cm_init_rx_wr(struct net_device *dev,
326 struct ib_recv_wr *wr,
327 struct ib_sge *sge)
328{
329 struct ipoib_dev_priv *priv = netdev_priv(dev);
330 int i;
331
332 for (i = 0; i < priv->cm.num_frags; ++i)
333 sge[i].lkey = priv->mr->lkey;
334
335 sge[0].length = IPOIB_CM_HEAD_SIZE;
336 for (i = 1; i < priv->cm.num_frags; ++i)
337 sge[i].length = PAGE_SIZE;
338
339 wr->next = NULL;
e0819816 340 wr->sg_list = sge;
a7d834c4
RD
341 wr->num_sge = priv->cm.num_frags;
342}
343
68e995a2
PS
344static int ipoib_cm_nonsrq_init_rx(struct net_device *dev, struct ib_cm_id *cm_id,
345 struct ipoib_cm_rx *rx)
346{
347 struct ipoib_dev_priv *priv = netdev_priv(dev);
a7d834c4
RD
348 struct {
349 struct ib_recv_wr wr;
350 struct ib_sge sge[IPOIB_CM_RX_SG];
351 } *t;
68e995a2
PS
352 int ret;
353 int i;
354
948579cd 355 rx->rx_ring = vzalloc(ipoib_recvq_size * sizeof *rx->rx_ring);
b1404069
DW
356 if (!rx->rx_ring) {
357 printk(KERN_WARNING "%s: failed to allocate CM non-SRQ ring (%d entries)\n",
358 priv->ca->name, ipoib_recvq_size);
68e995a2 359 return -ENOMEM;
b1404069
DW
360 }
361
a7d834c4
RD
362 t = kmalloc(sizeof *t, GFP_KERNEL);
363 if (!t) {
364 ret = -ENOMEM;
365 goto err_free;
366 }
367
368 ipoib_cm_init_rx_wr(dev, &t->wr, t->sge);
369
68e995a2
PS
370 spin_lock_irq(&priv->lock);
371
372 if (priv->cm.nonsrq_conn_qp >= ipoib_max_conn_qp) {
373 spin_unlock_irq(&priv->lock);
374 ib_send_cm_rej(cm_id, IB_CM_REJ_NO_QP, NULL, 0, NULL, 0);
375 ret = -EINVAL;
376 goto err_free;
377 } else
378 ++priv->cm.nonsrq_conn_qp;
379
380 spin_unlock_irq(&priv->lock);
381
382 for (i = 0; i < ipoib_recvq_size; ++i) {
383 if (!ipoib_cm_alloc_rx_skb(dev, rx->rx_ring, i, IPOIB_CM_RX_SG - 1,
384 rx->rx_ring[i].mapping)) {
385 ipoib_warn(priv, "failed to allocate receive buffer %d\n", i);
386 ret = -ENOMEM;
387 goto err_count;
a7d834c4
RD
388 }
389 ret = ipoib_cm_post_receive_nonsrq(dev, rx, &t->wr, t->sge, i);
68e995a2
PS
390 if (ret) {
391 ipoib_warn(priv, "ipoib_cm_post_receive_nonsrq "
392 "failed for buf %d\n", i);
393 ret = -EIO;
394 goto err_count;
395 }
396 }
397
398 rx->recv_count = ipoib_recvq_size;
399
a7d834c4
RD
400 kfree(t);
401
68e995a2
PS
402 return 0;
403
404err_count:
405 spin_lock_irq(&priv->lock);
406 --priv->cm.nonsrq_conn_qp;
407 spin_unlock_irq(&priv->lock);
408
409err_free:
a7d834c4 410 kfree(t);
68e995a2
PS
411 ipoib_cm_free_rx_ring(dev, rx->rx_ring);
412
413 return ret;
414}
415
839fcaba
MT
416static int ipoib_cm_send_rep(struct net_device *dev, struct ib_cm_id *cm_id,
417 struct ib_qp *qp, struct ib_cm_req_event_param *req,
418 unsigned psn)
419{
420 struct ipoib_dev_priv *priv = netdev_priv(dev);
421 struct ipoib_cm_data data = {};
422 struct ib_cm_rep_param rep = {};
423
424 data.qpn = cpu_to_be32(priv->qp->qp_num);
425 data.mtu = cpu_to_be32(IPOIB_CM_BUF_SIZE);
426
427 rep.private_data = &data;
428 rep.private_data_len = sizeof data;
429 rep.flow_control = 0;
430 rep.rnr_retry_count = req->rnr_retry_count;
68e995a2 431 rep.srq = ipoib_cm_has_srq(dev);
839fcaba
MT
432 rep.qp_num = qp->qp_num;
433 rep.starting_psn = psn;
434 return ib_send_cm_rep(cm_id, &rep);
435}
436
437static int ipoib_cm_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
438{
439 struct net_device *dev = cm_id->context;
440 struct ipoib_dev_priv *priv = netdev_priv(dev);
441 struct ipoib_cm_rx *p;
839fcaba
MT
442 unsigned psn;
443 int ret;
444
445 ipoib_dbg(priv, "REQ arrived\n");
446 p = kzalloc(sizeof *p, GFP_KERNEL);
447 if (!p)
448 return -ENOMEM;
449 p->dev = dev;
450 p->id = cm_id;
3ec7393a
MT
451 cm_id->context = p;
452 p->state = IPOIB_CM_RX_LIVE;
453 p->jiffies = jiffies;
454 INIT_LIST_HEAD(&p->list);
455
839fcaba
MT
456 p->qp = ipoib_cm_create_rx_qp(dev, p);
457 if (IS_ERR(p->qp)) {
458 ret = PTR_ERR(p->qp);
459 goto err_qp;
460 }
461
462 psn = random32() & 0xffffff;
463 ret = ipoib_cm_modify_rx_qp(dev, cm_id, p->qp, psn);
464 if (ret)
465 goto err_modify;
466
68e995a2
PS
467 if (!ipoib_cm_has_srq(dev)) {
468 ret = ipoib_cm_nonsrq_init_rx(dev, cm_id, p);
469 if (ret)
470 goto err_modify;
471 }
472
3ec7393a
MT
473 spin_lock_irq(&priv->lock);
474 queue_delayed_work(ipoib_workqueue,
475 &priv->cm.stale_task, IPOIB_CM_RX_DELAY);
476 /* Add this entry to passive ids list head, but do not re-add it
477 * if IB_EVENT_QP_LAST_WQE_REACHED has moved it to flush list. */
478 p->jiffies = jiffies;
479 if (p->state == IPOIB_CM_RX_LIVE)
480 list_move(&p->list, &priv->cm.passive_ids);
481 spin_unlock_irq(&priv->lock);
482
839fcaba
MT
483 ret = ipoib_cm_send_rep(dev, cm_id, p->qp, &event->param.req_rcvd, psn);
484 if (ret) {
485 ipoib_warn(priv, "failed to send REP: %d\n", ret);
3ec7393a
MT
486 if (ib_modify_qp(p->qp, &ipoib_cm_err_attr, IB_QP_STATE))
487 ipoib_warn(priv, "unable to move qp to error state\n");
839fcaba 488 }
839fcaba
MT
489 return 0;
490
839fcaba
MT
491err_modify:
492 ib_destroy_qp(p->qp);
493err_qp:
494 kfree(p);
495 return ret;
496}
497
498static int ipoib_cm_rx_handler(struct ib_cm_id *cm_id,
499 struct ib_cm_event *event)
500{
501 struct ipoib_cm_rx *p;
502 struct ipoib_dev_priv *priv;
839fcaba
MT
503
504 switch (event->event) {
505 case IB_CM_REQ_RECEIVED:
506 return ipoib_cm_req_handler(cm_id, event);
507 case IB_CM_DREQ_RECEIVED:
508 p = cm_id->context;
509 ib_send_cm_drep(cm_id, NULL, 0);
510 /* Fall through */
511 case IB_CM_REJ_RECEIVED:
512 p = cm_id->context;
513 priv = netdev_priv(p->dev);
518b1646
MT
514 if (ib_modify_qp(p->qp, &ipoib_cm_err_attr, IB_QP_STATE))
515 ipoib_warn(priv, "unable to move qp to error state\n");
516 /* Fall through */
839fcaba
MT
517 default:
518 return 0;
519 }
520}
521/* Adjust length of skb with fragments to match received data */
522static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space,
1812063b 523 unsigned int length, struct sk_buff *toskb)
839fcaba
MT
524{
525 int i, num_frags;
526 unsigned int size;
527
528 /* put header into skb */
529 size = min(length, hdr_space);
530 skb->tail += size;
531 skb->len += size;
532 length -= size;
533
534 num_frags = skb_shinfo(skb)->nr_frags;
535 for (i = 0; i < num_frags; i++) {
536 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
537
538 if (length == 0) {
539 /* don't need this page */
5581be3b
IC
540 skb_fill_page_desc(toskb, i, skb_frag_page(frag),
541 0, PAGE_SIZE);
839fcaba
MT
542 --skb_shinfo(skb)->nr_frags;
543 } else {
544 size = min(length, (unsigned) PAGE_SIZE);
545
9e903e08 546 skb_frag_size_set(frag, size);
839fcaba
MT
547 skb->data_len += size;
548 skb->truesize += size;
549 skb->len += size;
550 length -= size;
551 }
552 }
553}
554
555void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
556{
557 struct ipoib_dev_priv *priv = netdev_priv(dev);
68e995a2 558 struct ipoib_cm_rx_buf *rx_ring;
1b524963 559 unsigned int wr_id = wc->wr_id & ~(IPOIB_OP_CM | IPOIB_OP_RECV);
1812063b 560 struct sk_buff *skb, *newskb;
839fcaba
MT
561 struct ipoib_cm_rx *p;
562 unsigned long flags;
563 u64 mapping[IPOIB_CM_RX_SG];
1812063b 564 int frags;
68e995a2 565 int has_srq;
f89271da 566 struct sk_buff *small_skb;
839fcaba 567
a89875fc
RD
568 ipoib_dbg_data(priv, "cm recv completion: id %d, status: %d\n",
569 wr_id, wc->status);
839fcaba
MT
570
571 if (unlikely(wr_id >= ipoib_recvq_size)) {
1b524963 572 if (wr_id == (IPOIB_CM_RX_DRAIN_WRID & ~(IPOIB_OP_CM | IPOIB_OP_RECV))) {
518b1646
MT
573 spin_lock_irqsave(&priv->lock, flags);
574 list_splice_init(&priv->cm.rx_drain_list, &priv->cm.rx_reap_list);
575 ipoib_cm_start_rx_drain(priv);
576 queue_work(ipoib_workqueue, &priv->cm.rx_reap_task);
577 spin_unlock_irqrestore(&priv->lock, flags);
578 } else
579 ipoib_warn(priv, "cm recv completion event with wrid %d (> %d)\n",
580 wr_id, ipoib_recvq_size);
839fcaba
MT
581 return;
582 }
583
68e995a2
PS
584 p = wc->qp->qp_context;
585
586 has_srq = ipoib_cm_has_srq(dev);
587 rx_ring = has_srq ? priv->cm.srq_ring : p->rx_ring;
588
589 skb = rx_ring[wr_id].skb;
839fcaba
MT
590
591 if (unlikely(wc->status != IB_WC_SUCCESS)) {
592 ipoib_dbg(priv, "cm recv error "
593 "(status=%d, wrid=%d vend_err %x)\n",
594 wc->status, wr_id, wc->vendor_err);
de903512 595 ++dev->stats.rx_dropped;
68e995a2
PS
596 if (has_srq)
597 goto repost;
598 else {
599 if (!--p->recv_count) {
600 spin_lock_irqsave(&priv->lock, flags);
601 list_move(&p->list, &priv->cm.rx_reap_list);
602 spin_unlock_irqrestore(&priv->lock, flags);
603 queue_work(ipoib_workqueue, &priv->cm.rx_reap_task);
604 }
605 return;
606 }
839fcaba
MT
607 }
608
fd312561 609 if (unlikely(!(wr_id & IPOIB_CM_RX_UPDATE_MASK))) {
d6ef7d68 610 if (p && time_after_eq(jiffies, p->jiffies + IPOIB_CM_RX_UPDATE_TIME)) {
839fcaba
MT
611 spin_lock_irqsave(&priv->lock, flags);
612 p->jiffies = jiffies;
518b1646
MT
613 /* Move this entry to list head, but do not re-add it
614 * if it has been moved out of list. */
615 if (p->state == IPOIB_CM_RX_LIVE)
839fcaba
MT
616 list_move(&p->list, &priv->cm.passive_ids);
617 spin_unlock_irqrestore(&priv->lock, flags);
839fcaba
MT
618 }
619 }
620
f89271da
EC
621 if (wc->byte_len < IPOIB_CM_COPYBREAK) {
622 int dlen = wc->byte_len;
623
624 small_skb = dev_alloc_skb(dlen + 12);
625 if (small_skb) {
626 skb_reserve(small_skb, 12);
627 ib_dma_sync_single_for_cpu(priv->ca, rx_ring[wr_id].mapping[0],
628 dlen, DMA_FROM_DEVICE);
629 skb_copy_from_linear_data(skb, small_skb->data, dlen);
630 ib_dma_sync_single_for_device(priv->ca, rx_ring[wr_id].mapping[0],
631 dlen, DMA_FROM_DEVICE);
632 skb_put(small_skb, dlen);
633 skb = small_skb;
634 goto copied;
635 }
636 }
637
1812063b
MT
638 frags = PAGE_ALIGN(wc->byte_len - min(wc->byte_len,
639 (unsigned)IPOIB_CM_HEAD_SIZE)) / PAGE_SIZE;
640
68e995a2 641 newskb = ipoib_cm_alloc_rx_skb(dev, rx_ring, wr_id, frags, mapping);
1812063b 642 if (unlikely(!newskb)) {
839fcaba
MT
643 /*
644 * If we can't allocate a new RX buffer, dump
645 * this packet and reuse the old buffer.
646 */
647 ipoib_dbg(priv, "failed to allocate receive buffer %d\n", wr_id);
de903512 648 ++dev->stats.rx_dropped;
839fcaba
MT
649 goto repost;
650 }
651
68e995a2
PS
652 ipoib_cm_dma_unmap_rx(priv, frags, rx_ring[wr_id].mapping);
653 memcpy(rx_ring[wr_id].mapping, mapping, (frags + 1) * sizeof *mapping);
839fcaba
MT
654
655 ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n",
656 wc->byte_len, wc->slid);
657
1812063b 658 skb_put_frags(skb, IPOIB_CM_HEAD_SIZE, wc->byte_len, newskb);
839fcaba 659
f89271da 660copied:
839fcaba 661 skb->protocol = ((struct ipoib_header *) skb->data)->proto;
459a98ed 662 skb_reset_mac_header(skb);
839fcaba
MT
663 skb_pull(skb, IPOIB_ENCAP_LEN);
664
de903512
RD
665 ++dev->stats.rx_packets;
666 dev->stats.rx_bytes += skb->len;
839fcaba
MT
667
668 skb->dev = dev;
669 /* XXX get correct PACKET_ type here */
670 skb->pkt_type = PACKET_HOST;
8d1cc86a 671 netif_receive_skb(skb);
839fcaba
MT
672
673repost:
68e995a2
PS
674 if (has_srq) {
675 if (unlikely(ipoib_cm_post_receive_srq(dev, wr_id)))
676 ipoib_warn(priv, "ipoib_cm_post_receive_srq failed "
677 "for buf %d\n", wr_id);
678 } else {
a7d834c4
RD
679 if (unlikely(ipoib_cm_post_receive_nonsrq(dev, p,
680 &priv->cm.rx_wr,
681 priv->cm.rx_sge,
682 wr_id))) {
68e995a2
PS
683 --p->recv_count;
684 ipoib_warn(priv, "ipoib_cm_post_receive_nonsrq failed "
685 "for buf %d\n", wr_id);
686 }
687 }
839fcaba
MT
688}
689
690static inline int post_send(struct ipoib_dev_priv *priv,
691 struct ipoib_cm_tx *tx,
692 unsigned int wr_id,
693 u64 addr, int len)
694{
695 struct ib_send_wr *bad_wr;
696
7143740d
EC
697 priv->tx_sge[0].addr = addr;
698 priv->tx_sge[0].length = len;
839fcaba 699
4200406b 700 priv->tx_wr.num_sge = 1;
2337f809 701 priv->tx_wr.wr_id = wr_id | IPOIB_OP_CM;
839fcaba
MT
702
703 return ib_post_send(tx->qp, &priv->tx_wr, &bad_wr);
704}
705
706void ipoib_cm_send(struct net_device *dev, struct sk_buff *skb, struct ipoib_cm_tx *tx)
707{
708 struct ipoib_dev_priv *priv = netdev_priv(dev);
e112373f 709 struct ipoib_cm_tx_buf *tx_req;
839fcaba 710 u64 addr;
a48f509b 711 int rc;
839fcaba
MT
712
713 if (unlikely(skb->len > tx->mtu)) {
714 ipoib_warn(priv, "packet len %d (> %d) too long to send, dropping\n",
715 skb->len, tx->mtu);
de903512
RD
716 ++dev->stats.tx_dropped;
717 ++dev->stats.tx_errors;
77d8e1ef 718 ipoib_cm_skb_too_long(dev, skb, tx->mtu - IPOIB_ENCAP_LEN);
839fcaba
MT
719 return;
720 }
721
722 ipoib_dbg_data(priv, "sending packet: head 0x%x length %d connection 0x%x\n",
723 tx->tx_head, skb->len, tx->qp->qp_num);
724
725 /*
726 * We put the skb into the tx_ring _before_ we call post_send()
727 * because it's entirely possible that the completion handler will
728 * run before we execute anything after the post_send(). That
729 * means we have to make sure everything is properly recorded and
730 * our state is consistent before we call post_send().
731 */
732 tx_req = &tx->tx_ring[tx->tx_head & (ipoib_sendq_size - 1)];
733 tx_req->skb = skb;
734 addr = ib_dma_map_single(priv->ca, skb->data, skb->len, DMA_TO_DEVICE);
735 if (unlikely(ib_dma_mapping_error(priv->ca, addr))) {
de903512 736 ++dev->stats.tx_errors;
839fcaba
MT
737 dev_kfree_skb_any(skb);
738 return;
739 }
740
e112373f 741 tx_req->mapping = addr;
839fcaba 742
a48f509b
OG
743 rc = post_send(priv, tx, tx->tx_head & (ipoib_sendq_size - 1),
744 addr, skb->len);
745 if (unlikely(rc)) {
746 ipoib_warn(priv, "post_send failed, error %d\n", rc);
de903512 747 ++dev->stats.tx_errors;
839fcaba
MT
748 ib_dma_unmap_single(priv->ca, addr, skb->len, DMA_TO_DEVICE);
749 dev_kfree_skb_any(skb);
750 } else {
751 dev->trans_start = jiffies;
752 ++tx->tx_head;
753
1b524963 754 if (++priv->tx_outstanding == ipoib_sendq_size) {
839fcaba
MT
755 ipoib_dbg(priv, "TX ring 0x%x full, stopping kernel net queue\n",
756 tx->qp->qp_num);
f0dc117a
EC
757 if (ib_req_notify_cq(priv->send_cq, IB_CQ_NEXT_COMP))
758 ipoib_warn(priv, "request notify on send CQ failed\n");
839fcaba 759 netif_stop_queue(dev);
839fcaba
MT
760 }
761 }
762}
763
1b524963 764void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
839fcaba
MT
765{
766 struct ipoib_dev_priv *priv = netdev_priv(dev);
1b524963
MT
767 struct ipoib_cm_tx *tx = wc->qp->qp_context;
768 unsigned int wr_id = wc->wr_id & ~IPOIB_OP_CM;
e112373f 769 struct ipoib_cm_tx_buf *tx_req;
839fcaba
MT
770 unsigned long flags;
771
a89875fc
RD
772 ipoib_dbg_data(priv, "cm send completion: id %d, status: %d\n",
773 wr_id, wc->status);
839fcaba
MT
774
775 if (unlikely(wr_id >= ipoib_sendq_size)) {
776 ipoib_warn(priv, "cm send completion event with wrid %d (> %d)\n",
777 wr_id, ipoib_sendq_size);
778 return;
779 }
780
781 tx_req = &tx->tx_ring[wr_id];
782
e112373f 783 ib_dma_unmap_single(priv->ca, tx_req->mapping, tx_req->skb->len, DMA_TO_DEVICE);
839fcaba
MT
784
785 /* FIXME: is this right? Shouldn't we only increment on success? */
de903512
RD
786 ++dev->stats.tx_packets;
787 dev->stats.tx_bytes += tx_req->skb->len;
839fcaba
MT
788
789 dev_kfree_skb_any(tx_req->skb);
790
943c246e
RD
791 netif_tx_lock(dev);
792
839fcaba 793 ++tx->tx_tail;
1b524963
MT
794 if (unlikely(--priv->tx_outstanding == ipoib_sendq_size >> 1) &&
795 netif_queue_stopped(dev) &&
796 test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
839fcaba 797 netif_wake_queue(dev);
839fcaba
MT
798
799 if (wc->status != IB_WC_SUCCESS &&
800 wc->status != IB_WC_WR_FLUSH_ERR) {
801 struct ipoib_neigh *neigh;
802
803 ipoib_dbg(priv, "failed cm send event "
804 "(status=%d, wrid=%d vend_err %x)\n",
805 wc->status, wr_id, wc->vendor_err);
806
943c246e 807 spin_lock_irqsave(&priv->lock, flags);
839fcaba
MT
808 neigh = tx->neigh;
809
810 if (neigh) {
811 neigh->cm = NULL;
812 list_del(&neigh->list);
813 if (neigh->ah)
814 ipoib_put_ah(neigh->ah);
815 ipoib_neigh_free(dev, neigh);
816
817 tx->neigh = NULL;
818 }
819
839fcaba
MT
820 if (test_and_clear_bit(IPOIB_FLAG_INITIALIZED, &tx->flags)) {
821 list_move(&tx->list, &priv->cm.reap_list);
822 queue_work(ipoib_workqueue, &priv->cm.reap_task);
823 }
824
825 clear_bit(IPOIB_FLAG_OPER_UP, &tx->flags);
826
943c246e 827 spin_unlock_irqrestore(&priv->lock, flags);
839fcaba
MT
828 }
829
943c246e 830 netif_tx_unlock(dev);
839fcaba
MT
831}
832
839fcaba
MT
833int ipoib_cm_dev_open(struct net_device *dev)
834{
835 struct ipoib_dev_priv *priv = netdev_priv(dev);
836 int ret;
837
838 if (!IPOIB_CM_SUPPORTED(dev->dev_addr))
839 return 0;
840
841 priv->cm.id = ib_create_cm_id(priv->ca, ipoib_cm_rx_handler, dev);
842 if (IS_ERR(priv->cm.id)) {
843 printk(KERN_WARNING "%s: failed to create CM ID\n", priv->ca->name);
347fcfbe 844 ret = PTR_ERR(priv->cm.id);
518b1646 845 goto err_cm;
839fcaba
MT
846 }
847
848 ret = ib_cm_listen(priv->cm.id, cpu_to_be64(IPOIB_CM_IETF_ID | priv->qp->qp_num),
849 0, NULL);
850 if (ret) {
851 printk(KERN_WARNING "%s: failed to listen on ID 0x%llx\n", priv->ca->name,
852 IPOIB_CM_IETF_ID | priv->qp->qp_num);
518b1646 853 goto err_listen;
839fcaba 854 }
518b1646 855
839fcaba 856 return 0;
518b1646
MT
857
858err_listen:
859 ib_destroy_cm_id(priv->cm.id);
860err_cm:
861 priv->cm.id = NULL;
518b1646 862 return ret;
839fcaba
MT
863}
864
efcd9971
RD
865static void ipoib_cm_free_rx_reap_list(struct net_device *dev)
866{
867 struct ipoib_dev_priv *priv = netdev_priv(dev);
868 struct ipoib_cm_rx *rx, *n;
869 LIST_HEAD(list);
870
871 spin_lock_irq(&priv->lock);
872 list_splice_init(&priv->cm.rx_reap_list, &list);
873 spin_unlock_irq(&priv->lock);
874
875 list_for_each_entry_safe(rx, n, &list, list) {
876 ib_destroy_cm_id(rx->id);
877 ib_destroy_qp(rx->qp);
68e995a2
PS
878 if (!ipoib_cm_has_srq(dev)) {
879 ipoib_cm_free_rx_ring(priv->dev, rx->rx_ring);
880 spin_lock_irq(&priv->lock);
881 --priv->cm.nonsrq_conn_qp;
882 spin_unlock_irq(&priv->lock);
883 }
efcd9971
RD
884 kfree(rx);
885 }
886}
887
839fcaba
MT
888void ipoib_cm_dev_stop(struct net_device *dev)
889{
890 struct ipoib_dev_priv *priv = netdev_priv(dev);
efcd9971 891 struct ipoib_cm_rx *p;
518b1646 892 unsigned long begin;
518b1646 893 int ret;
839fcaba 894
347fcfbe 895 if (!IPOIB_CM_SUPPORTED(dev->dev_addr) || !priv->cm.id)
839fcaba
MT
896 return;
897
898 ib_destroy_cm_id(priv->cm.id);
347fcfbe 899 priv->cm.id = NULL;
518b1646 900
37aebbde 901 spin_lock_irq(&priv->lock);
839fcaba
MT
902 while (!list_empty(&priv->cm.passive_ids)) {
903 p = list_entry(priv->cm.passive_ids.next, typeof(*p), list);
518b1646
MT
904 list_move(&p->list, &priv->cm.rx_error_list);
905 p->state = IPOIB_CM_RX_ERROR;
37aebbde 906 spin_unlock_irq(&priv->lock);
518b1646
MT
907 ret = ib_modify_qp(p->qp, &ipoib_cm_err_attr, IB_QP_STATE);
908 if (ret)
909 ipoib_warn(priv, "unable to move qp to error state: %d\n", ret);
910 spin_lock_irq(&priv->lock);
911 }
912
913 /* Wait for all RX to be drained */
914 begin = jiffies;
915
916 while (!list_empty(&priv->cm.rx_error_list) ||
917 !list_empty(&priv->cm.rx_flush_list) ||
918 !list_empty(&priv->cm.rx_drain_list)) {
8fd357a6 919 if (time_after(jiffies, begin + 5 * HZ)) {
518b1646
MT
920 ipoib_warn(priv, "RX drain timing out\n");
921
922 /*
923 * assume the HW is wedged and just free up everything.
924 */
ec229e5e
PS
925 list_splice_init(&priv->cm.rx_flush_list,
926 &priv->cm.rx_reap_list);
927 list_splice_init(&priv->cm.rx_error_list,
928 &priv->cm.rx_reap_list);
929 list_splice_init(&priv->cm.rx_drain_list,
930 &priv->cm.rx_reap_list);
518b1646
MT
931 break;
932 }
933 spin_unlock_irq(&priv->lock);
934 msleep(1);
2dfbfc37 935 ipoib_drain_cq(dev);
518b1646
MT
936 spin_lock_irq(&priv->lock);
937 }
938
518b1646
MT
939 spin_unlock_irq(&priv->lock);
940
efcd9971 941 ipoib_cm_free_rx_reap_list(dev);
839fcaba
MT
942
943 cancel_delayed_work(&priv->cm.stale_task);
944}
945
946static int ipoib_cm_rep_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
947{
948 struct ipoib_cm_tx *p = cm_id->context;
949 struct ipoib_dev_priv *priv = netdev_priv(p->dev);
950 struct ipoib_cm_data *data = event->private_data;
951 struct sk_buff_head skqueue;
952 struct ib_qp_attr qp_attr;
953 int qp_attr_mask, ret;
954 struct sk_buff *skb;
839fcaba
MT
955
956 p->mtu = be32_to_cpu(data->mtu);
957
82c3aca6
MT
958 if (p->mtu <= IPOIB_ENCAP_LEN) {
959 ipoib_warn(priv, "Rejecting connection: mtu %d <= %d\n",
960 p->mtu, IPOIB_ENCAP_LEN);
839fcaba
MT
961 return -EINVAL;
962 }
963
964 qp_attr.qp_state = IB_QPS_RTR;
965 ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask);
966 if (ret) {
967 ipoib_warn(priv, "failed to init QP attr for RTR: %d\n", ret);
968 return ret;
969 }
970
971 qp_attr.rq_psn = 0 /* FIXME */;
972 ret = ib_modify_qp(p->qp, &qp_attr, qp_attr_mask);
973 if (ret) {
974 ipoib_warn(priv, "failed to modify QP to RTR: %d\n", ret);
975 return ret;
976 }
977
978 qp_attr.qp_state = IB_QPS_RTS;
979 ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask);
980 if (ret) {
981 ipoib_warn(priv, "failed to init QP attr for RTS: %d\n", ret);
982 return ret;
983 }
984 ret = ib_modify_qp(p->qp, &qp_attr, qp_attr_mask);
985 if (ret) {
986 ipoib_warn(priv, "failed to modify QP to RTS: %d\n", ret);
987 return ret;
988 }
989
990 skb_queue_head_init(&skqueue);
991
37aebbde 992 spin_lock_irq(&priv->lock);
839fcaba
MT
993 set_bit(IPOIB_FLAG_OPER_UP, &p->flags);
994 if (p->neigh)
995 while ((skb = __skb_dequeue(&p->neigh->queue)))
996 __skb_queue_tail(&skqueue, skb);
37aebbde 997 spin_unlock_irq(&priv->lock);
839fcaba
MT
998
999 while ((skb = __skb_dequeue(&skqueue))) {
1000 skb->dev = p->dev;
1001 if (dev_queue_xmit(skb))
1002 ipoib_warn(priv, "dev_queue_xmit failed "
1003 "to requeue packet\n");
1004 }
1005
1006 ret = ib_send_cm_rtu(cm_id, NULL, 0);
1007 if (ret) {
1008 ipoib_warn(priv, "failed to send RTU: %d\n", ret);
1009 return ret;
1010 }
1011 return 0;
1012}
1013
1b524963 1014static struct ib_qp *ipoib_cm_create_tx_qp(struct net_device *dev, struct ipoib_cm_tx *tx)
839fcaba
MT
1015{
1016 struct ipoib_dev_priv *priv = netdev_priv(dev);
ede6bc04 1017 struct ib_qp_init_attr attr = {
f56bcd80
EC
1018 .send_cq = priv->recv_cq,
1019 .recv_cq = priv->recv_cq,
ede6bc04
DB
1020 .srq = priv->cm.srq,
1021 .cap.max_send_wr = ipoib_sendq_size,
1022 .cap.max_send_sge = 1,
1023 .sq_sig_type = IB_SIGNAL_ALL_WR,
1024 .qp_type = IB_QPT_RC,
1b524963 1025 .qp_context = tx
2337f809 1026 };
ede6bc04 1027
839fcaba
MT
1028 return ib_create_qp(priv->pd, &attr);
1029}
1030
1031static int ipoib_cm_send_req(struct net_device *dev,
1032 struct ib_cm_id *id, struct ib_qp *qp,
1033 u32 qpn,
1034 struct ib_sa_path_rec *pathrec)
1035{
1036 struct ipoib_dev_priv *priv = netdev_priv(dev);
1037 struct ipoib_cm_data data = {};
1038 struct ib_cm_req_param req = {};
1039
1040 data.qpn = cpu_to_be32(priv->qp->qp_num);
1041 data.mtu = cpu_to_be32(IPOIB_CM_BUF_SIZE);
1042
2337f809
RD
1043 req.primary_path = pathrec;
1044 req.alternate_path = NULL;
1045 req.service_id = cpu_to_be64(IPOIB_CM_IETF_ID | qpn);
1046 req.qp_num = qp->qp_num;
1047 req.qp_type = qp->qp_type;
1048 req.private_data = &data;
1049 req.private_data_len = sizeof data;
1050 req.flow_control = 0;
839fcaba 1051
2337f809 1052 req.starting_psn = 0; /* FIXME */
839fcaba
MT
1053
1054 /*
1055 * Pick some arbitrary defaults here; we could make these
1056 * module parameters if anyone cared about setting them.
1057 */
2337f809
RD
1058 req.responder_resources = 4;
1059 req.remote_cm_response_timeout = 20;
1060 req.local_cm_response_timeout = 20;
1061 req.retry_count = 0; /* RFC draft warns against retries */
1062 req.rnr_retry_count = 0; /* RFC draft warns against retries */
1063 req.max_cm_retries = 15;
68e995a2 1064 req.srq = ipoib_cm_has_srq(dev);
839fcaba
MT
1065 return ib_send_cm_req(id, &req);
1066}
1067
1068static int ipoib_cm_modify_tx_init(struct net_device *dev,
1069 struct ib_cm_id *cm_id, struct ib_qp *qp)
1070{
1071 struct ipoib_dev_priv *priv = netdev_priv(dev);
1072 struct ib_qp_attr qp_attr;
1073 int qp_attr_mask, ret;
9fdd5e5b 1074 ret = ib_find_pkey(priv->ca, priv->port, priv->pkey, &qp_attr.pkey_index);
839fcaba 1075 if (ret) {
9fdd5e5b 1076 ipoib_warn(priv, "pkey 0x%x not found: %d\n", priv->pkey, ret);
839fcaba
MT
1077 return ret;
1078 }
1079
1080 qp_attr.qp_state = IB_QPS_INIT;
1081 qp_attr.qp_access_flags = IB_ACCESS_LOCAL_WRITE;
1082 qp_attr.port_num = priv->port;
1083 qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS | IB_QP_PKEY_INDEX | IB_QP_PORT;
1084
1085 ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask);
1086 if (ret) {
1087 ipoib_warn(priv, "failed to modify tx QP to INIT: %d\n", ret);
1088 return ret;
1089 }
1090 return 0;
1091}
1092
1093static int ipoib_cm_tx_init(struct ipoib_cm_tx *p, u32 qpn,
1094 struct ib_sa_path_rec *pathrec)
1095{
1096 struct ipoib_dev_priv *priv = netdev_priv(p->dev);
1097 int ret;
1098
948579cd 1099 p->tx_ring = vzalloc(ipoib_sendq_size * sizeof *p->tx_ring);
839fcaba
MT
1100 if (!p->tx_ring) {
1101 ipoib_warn(priv, "failed to allocate tx ring\n");
1102 ret = -ENOMEM;
1103 goto err_tx;
1104 }
1105
1b524963 1106 p->qp = ipoib_cm_create_tx_qp(p->dev, p);
839fcaba
MT
1107 if (IS_ERR(p->qp)) {
1108 ret = PTR_ERR(p->qp);
1109 ipoib_warn(priv, "failed to allocate tx qp: %d\n", ret);
1110 goto err_qp;
1111 }
1112
1113 p->id = ib_create_cm_id(priv->ca, ipoib_cm_tx_handler, p);
1114 if (IS_ERR(p->id)) {
1115 ret = PTR_ERR(p->id);
1116 ipoib_warn(priv, "failed to create tx cm id: %d\n", ret);
1117 goto err_id;
1118 }
1119
1120 ret = ipoib_cm_modify_tx_init(p->dev, p->id, p->qp);
1121 if (ret) {
1122 ipoib_warn(priv, "failed to modify tx qp to rtr: %d\n", ret);
1123 goto err_modify;
1124 }
1125
1126 ret = ipoib_cm_send_req(p->dev, p->id, p->qp, qpn, pathrec);
1127 if (ret) {
1128 ipoib_warn(priv, "failed to send cm req: %d\n", ret);
1129 goto err_send_cm;
1130 }
1131
5b095d98 1132 ipoib_dbg(priv, "Request connection 0x%x for gid %pI6 qpn 0x%x\n",
fcace2fe 1133 p->qp->qp_num, pathrec->dgid.raw, qpn);
839fcaba
MT
1134
1135 return 0;
1136
1137err_send_cm:
1138err_modify:
1139 ib_destroy_cm_id(p->id);
1140err_id:
1141 p->id = NULL;
1142 ib_destroy_qp(p->qp);
839fcaba
MT
1143err_qp:
1144 p->qp = NULL;
10313cbb 1145 vfree(p->tx_ring);
839fcaba
MT
1146err_tx:
1147 return ret;
1148}
1149
1150static void ipoib_cm_tx_destroy(struct ipoib_cm_tx *p)
1151{
1152 struct ipoib_dev_priv *priv = netdev_priv(p->dev);
e112373f 1153 struct ipoib_cm_tx_buf *tx_req;
1b524963 1154 unsigned long begin;
839fcaba
MT
1155
1156 ipoib_dbg(priv, "Destroy active connection 0x%x head 0x%x tail 0x%x\n",
1157 p->qp ? p->qp->qp_num : 0, p->tx_head, p->tx_tail);
1158
1159 if (p->id)
1160 ib_destroy_cm_id(p->id);
1161
839fcaba 1162 if (p->tx_ring) {
1b524963
MT
1163 /* Wait for all sends to complete */
1164 begin = jiffies;
839fcaba 1165 while ((int) p->tx_tail - (int) p->tx_head < 0) {
1b524963
MT
1166 if (time_after(jiffies, begin + 5 * HZ)) {
1167 ipoib_warn(priv, "timing out; %d sends not completed\n",
1168 p->tx_head - p->tx_tail);
1169 goto timeout;
1170 }
1171
1172 msleep(1);
839fcaba 1173 }
1b524963
MT
1174 }
1175
1176timeout:
839fcaba 1177
1b524963
MT
1178 while ((int) p->tx_tail - (int) p->tx_head < 0) {
1179 tx_req = &p->tx_ring[p->tx_tail & (ipoib_sendq_size - 1)];
e112373f 1180 ib_dma_unmap_single(priv->ca, tx_req->mapping, tx_req->skb->len,
1b524963
MT
1181 DMA_TO_DEVICE);
1182 dev_kfree_skb_any(tx_req->skb);
1183 ++p->tx_tail;
943c246e 1184 netif_tx_lock_bh(p->dev);
1b524963
MT
1185 if (unlikely(--priv->tx_outstanding == ipoib_sendq_size >> 1) &&
1186 netif_queue_stopped(p->dev) &&
1187 test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
1188 netif_wake_queue(p->dev);
943c246e 1189 netif_tx_unlock_bh(p->dev);
839fcaba
MT
1190 }
1191
1b524963
MT
1192 if (p->qp)
1193 ib_destroy_qp(p->qp);
1194
10313cbb 1195 vfree(p->tx_ring);
839fcaba
MT
1196 kfree(p);
1197}
1198
1199static int ipoib_cm_tx_handler(struct ib_cm_id *cm_id,
1200 struct ib_cm_event *event)
1201{
1202 struct ipoib_cm_tx *tx = cm_id->context;
1203 struct ipoib_dev_priv *priv = netdev_priv(tx->dev);
1204 struct net_device *dev = priv->dev;
1205 struct ipoib_neigh *neigh;
943c246e 1206 unsigned long flags;
839fcaba
MT
1207 int ret;
1208
1209 switch (event->event) {
1210 case IB_CM_DREQ_RECEIVED:
1211 ipoib_dbg(priv, "DREQ received.\n");
1212 ib_send_cm_drep(cm_id, NULL, 0);
1213 break;
1214 case IB_CM_REP_RECEIVED:
1215 ipoib_dbg(priv, "REP received.\n");
1216 ret = ipoib_cm_rep_handler(cm_id, event);
1217 if (ret)
1218 ib_send_cm_rej(cm_id, IB_CM_REJ_CONSUMER_DEFINED,
1219 NULL, 0, NULL, 0);
1220 break;
1221 case IB_CM_REQ_ERROR:
1222 case IB_CM_REJ_RECEIVED:
1223 case IB_CM_TIMEWAIT_EXIT:
1224 ipoib_dbg(priv, "CM error %d.\n", event->event);
943c246e
RD
1225 netif_tx_lock_bh(dev);
1226 spin_lock_irqsave(&priv->lock, flags);
839fcaba
MT
1227 neigh = tx->neigh;
1228
1229 if (neigh) {
1230 neigh->cm = NULL;
1231 list_del(&neigh->list);
1232 if (neigh->ah)
1233 ipoib_put_ah(neigh->ah);
1234 ipoib_neigh_free(dev, neigh);
1235
1236 tx->neigh = NULL;
1237 }
1238
1239 if (test_and_clear_bit(IPOIB_FLAG_INITIALIZED, &tx->flags)) {
1240 list_move(&tx->list, &priv->cm.reap_list);
1241 queue_work(ipoib_workqueue, &priv->cm.reap_task);
1242 }
1243
943c246e
RD
1244 spin_unlock_irqrestore(&priv->lock, flags);
1245 netif_tx_unlock_bh(dev);
839fcaba
MT
1246 break;
1247 default:
1248 break;
1249 }
1250
1251 return 0;
1252}
1253
1254struct ipoib_cm_tx *ipoib_cm_create_tx(struct net_device *dev, struct ipoib_path *path,
1255 struct ipoib_neigh *neigh)
1256{
1257 struct ipoib_dev_priv *priv = netdev_priv(dev);
1258 struct ipoib_cm_tx *tx;
1259
1260 tx = kzalloc(sizeof *tx, GFP_ATOMIC);
1261 if (!tx)
1262 return NULL;
1263
1264 neigh->cm = tx;
1265 tx->neigh = neigh;
1266 tx->path = path;
1267 tx->dev = dev;
1268 list_add(&tx->list, &priv->cm.start_list);
1269 set_bit(IPOIB_FLAG_INITIALIZED, &tx->flags);
1270 queue_work(ipoib_workqueue, &priv->cm.start_task);
1271 return tx;
1272}
1273
1274void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx)
1275{
1276 struct ipoib_dev_priv *priv = netdev_priv(tx->dev);
1277 if (test_and_clear_bit(IPOIB_FLAG_INITIALIZED, &tx->flags)) {
1278 list_move(&tx->list, &priv->cm.reap_list);
1279 queue_work(ipoib_workqueue, &priv->cm.reap_task);
5b095d98 1280 ipoib_dbg(priv, "Reap connection for gid %pI6\n",
fcace2fe 1281 tx->neigh->dgid.raw);
839fcaba
MT
1282 tx->neigh = NULL;
1283 }
1284}
1285
1286static void ipoib_cm_tx_start(struct work_struct *work)
1287{
1288 struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv,
1289 cm.start_task);
1290 struct net_device *dev = priv->dev;
1291 struct ipoib_neigh *neigh;
1292 struct ipoib_cm_tx *p;
1293 unsigned long flags;
1294 int ret;
1295
1296 struct ib_sa_path_rec pathrec;
1297 u32 qpn;
1298
943c246e
RD
1299 netif_tx_lock_bh(dev);
1300 spin_lock_irqsave(&priv->lock, flags);
1301
839fcaba
MT
1302 while (!list_empty(&priv->cm.start_list)) {
1303 p = list_entry(priv->cm.start_list.next, typeof(*p), list);
1304 list_del_init(&p->list);
1305 neigh = p->neigh;
1306 qpn = IPOIB_QPN(neigh->neighbour->ha);
1307 memcpy(&pathrec, &p->path->pathrec, sizeof pathrec);
943c246e
RD
1308
1309 spin_unlock_irqrestore(&priv->lock, flags);
1310 netif_tx_unlock_bh(dev);
1311
839fcaba 1312 ret = ipoib_cm_tx_init(p, qpn, &pathrec);
943c246e
RD
1313
1314 netif_tx_lock_bh(dev);
1315 spin_lock_irqsave(&priv->lock, flags);
1316
839fcaba
MT
1317 if (ret) {
1318 neigh = p->neigh;
1319 if (neigh) {
1320 neigh->cm = NULL;
1321 list_del(&neigh->list);
1322 if (neigh->ah)
1323 ipoib_put_ah(neigh->ah);
1324 ipoib_neigh_free(dev, neigh);
1325 }
1326 list_del(&p->list);
1327 kfree(p);
1328 }
1329 }
943c246e
RD
1330
1331 spin_unlock_irqrestore(&priv->lock, flags);
1332 netif_tx_unlock_bh(dev);
839fcaba
MT
1333}
1334
1335static void ipoib_cm_tx_reap(struct work_struct *work)
1336{
1337 struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv,
1338 cm.reap_task);
943c246e 1339 struct net_device *dev = priv->dev;
839fcaba 1340 struct ipoib_cm_tx *p;
943c246e
RD
1341 unsigned long flags;
1342
1343 netif_tx_lock_bh(dev);
1344 spin_lock_irqsave(&priv->lock, flags);
839fcaba 1345
839fcaba
MT
1346 while (!list_empty(&priv->cm.reap_list)) {
1347 p = list_entry(priv->cm.reap_list.next, typeof(*p), list);
1348 list_del(&p->list);
943c246e
RD
1349 spin_unlock_irqrestore(&priv->lock, flags);
1350 netif_tx_unlock_bh(dev);
839fcaba 1351 ipoib_cm_tx_destroy(p);
943c246e
RD
1352 netif_tx_lock_bh(dev);
1353 spin_lock_irqsave(&priv->lock, flags);
839fcaba 1354 }
943c246e
RD
1355
1356 spin_unlock_irqrestore(&priv->lock, flags);
1357 netif_tx_unlock_bh(dev);
839fcaba
MT
1358}
1359
1360static void ipoib_cm_skb_reap(struct work_struct *work)
1361{
1362 struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv,
1363 cm.skb_task);
943c246e 1364 struct net_device *dev = priv->dev;
839fcaba 1365 struct sk_buff *skb;
943c246e 1366 unsigned long flags;
839fcaba
MT
1367 unsigned mtu = priv->mcast_mtu;
1368
943c246e
RD
1369 netif_tx_lock_bh(dev);
1370 spin_lock_irqsave(&priv->lock, flags);
1371
839fcaba 1372 while ((skb = skb_dequeue(&priv->cm.skb_queue))) {
943c246e
RD
1373 spin_unlock_irqrestore(&priv->lock, flags);
1374 netif_tx_unlock_bh(dev);
1375
839fcaba
MT
1376 if (skb->protocol == htons(ETH_P_IP))
1377 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
1378#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1379 else if (skb->protocol == htons(ETH_P_IPV6))
3ffe533c 1380 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
839fcaba
MT
1381#endif
1382 dev_kfree_skb_any(skb);
943c246e
RD
1383
1384 netif_tx_lock_bh(dev);
1385 spin_lock_irqsave(&priv->lock, flags);
839fcaba 1386 }
943c246e
RD
1387
1388 spin_unlock_irqrestore(&priv->lock, flags);
1389 netif_tx_unlock_bh(dev);
839fcaba
MT
1390}
1391
2337f809 1392void ipoib_cm_skb_too_long(struct net_device *dev, struct sk_buff *skb,
839fcaba
MT
1393 unsigned int mtu)
1394{
1395 struct ipoib_dev_priv *priv = netdev_priv(dev);
1396 int e = skb_queue_empty(&priv->cm.skb_queue);
1397
adf30907
ED
1398 if (skb_dst(skb))
1399 skb_dst(skb)->ops->update_pmtu(skb_dst(skb), mtu);
839fcaba
MT
1400
1401 skb_queue_tail(&priv->cm.skb_queue, skb);
1402 if (e)
1403 queue_work(ipoib_workqueue, &priv->cm.skb_task);
1404}
1405
518b1646
MT
1406static void ipoib_cm_rx_reap(struct work_struct *work)
1407{
efcd9971
RD
1408 ipoib_cm_free_rx_reap_list(container_of(work, struct ipoib_dev_priv,
1409 cm.rx_reap_task)->dev);
518b1646
MT
1410}
1411
839fcaba
MT
1412static void ipoib_cm_stale_task(struct work_struct *work)
1413{
1414 struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv,
1415 cm.stale_task.work);
1416 struct ipoib_cm_rx *p;
518b1646 1417 int ret;
839fcaba 1418
37aebbde 1419 spin_lock_irq(&priv->lock);
839fcaba 1420 while (!list_empty(&priv->cm.passive_ids)) {
518b1646 1421 /* List is sorted by LRU, start from tail,
839fcaba
MT
1422 * stop when we see a recently used entry */
1423 p = list_entry(priv->cm.passive_ids.prev, typeof(*p), list);
60a596da 1424 if (time_before_eq(jiffies, p->jiffies + IPOIB_CM_RX_TIMEOUT))
839fcaba 1425 break;
518b1646
MT
1426 list_move(&p->list, &priv->cm.rx_error_list);
1427 p->state = IPOIB_CM_RX_ERROR;
37aebbde 1428 spin_unlock_irq(&priv->lock);
518b1646
MT
1429 ret = ib_modify_qp(p->qp, &ipoib_cm_err_attr, IB_QP_STATE);
1430 if (ret)
1431 ipoib_warn(priv, "unable to move qp to error state: %d\n", ret);
37aebbde 1432 spin_lock_irq(&priv->lock);
839fcaba 1433 }
7c5b9ef8
MT
1434
1435 if (!list_empty(&priv->cm.passive_ids))
1436 queue_delayed_work(ipoib_workqueue,
1437 &priv->cm.stale_task, IPOIB_CM_RX_DELAY);
37aebbde 1438 spin_unlock_irq(&priv->lock);
839fcaba
MT
1439}
1440
1441
2337f809 1442static ssize_t show_mode(struct device *d, struct device_attribute *attr,
839fcaba
MT
1443 char *buf)
1444{
1445 struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(d));
1446
1447 if (test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags))
1448 return sprintf(buf, "connected\n");
1449 else
1450 return sprintf(buf, "datagram\n");
1451}
1452
1453static ssize_t set_mode(struct device *d, struct device_attribute *attr,
1454 const char *buf, size_t count)
1455{
1456 struct net_device *dev = to_net_dev(d);
1457 struct ipoib_dev_priv *priv = netdev_priv(dev);
1458
26574401
EB
1459 if (!rtnl_trylock())
1460 return restart_syscall();
1461
839fcaba
MT
1462 /* flush paths if we switch modes so that connections are restarted */
1463 if (IPOIB_CM_SUPPORTED(dev->dev_addr) && !strcmp(buf, "connected\n")) {
1464 set_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
1465 ipoib_warn(priv, "enabling connected mode "
1466 "will cause multicast packet drops\n");
3d96c74d 1467 netdev_update_features(dev);
c8c2afe3 1468 rtnl_unlock();
6046136c
EC
1469 priv->tx_wr.send_flags &= ~IB_SEND_IP_CSUM;
1470
839fcaba
MT
1471 ipoib_flush_paths(dev);
1472 return count;
1473 }
1474
1475 if (!strcmp(buf, "datagram\n")) {
1476 clear_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
3d96c74d 1477 netdev_update_features(dev);
bd360671 1478 dev_set_mtu(dev, min(priv->mcast_mtu, dev->mtu));
c8c2afe3
EC
1479 rtnl_unlock();
1480 ipoib_flush_paths(dev);
6046136c 1481
839fcaba
MT
1482 return count;
1483 }
26574401 1484 rtnl_unlock();
839fcaba
MT
1485
1486 return -EINVAL;
1487}
1488
551fd612 1489static DEVICE_ATTR(mode, S_IWUSR | S_IRUGO, show_mode, set_mode);
839fcaba
MT
1490
1491int ipoib_cm_add_mode_attr(struct net_device *dev)
1492{
1493 return device_create_file(&dev->dev, &dev_attr_mode);
1494}
1495
586a6934 1496static void ipoib_cm_create_srq(struct net_device *dev, int max_sge)
839fcaba
MT
1497{
1498 struct ipoib_dev_priv *priv = netdev_priv(dev);
1499 struct ib_srq_init_attr srq_init_attr = {
1500 .attr = {
1501 .max_wr = ipoib_recvq_size,
586a6934 1502 .max_sge = max_sge
839fcaba
MT
1503 }
1504 };
7b3687df
RD
1505
1506 priv->cm.srq = ib_create_srq(priv->pd, &srq_init_attr);
1507 if (IS_ERR(priv->cm.srq)) {
68e995a2
PS
1508 if (PTR_ERR(priv->cm.srq) != -ENOSYS)
1509 printk(KERN_WARNING "%s: failed to allocate SRQ, error %ld\n",
1510 priv->ca->name, PTR_ERR(priv->cm.srq));
7b3687df 1511 priv->cm.srq = NULL;
68e995a2 1512 return;
7b3687df
RD
1513 }
1514
948579cd 1515 priv->cm.srq_ring = vzalloc(ipoib_recvq_size * sizeof *priv->cm.srq_ring);
7b3687df 1516 if (!priv->cm.srq_ring) {
68e995a2 1517 printk(KERN_WARNING "%s: failed to allocate CM SRQ ring (%d entries)\n",
7b3687df
RD
1518 priv->ca->name, ipoib_recvq_size);
1519 ib_destroy_srq(priv->cm.srq);
1520 priv->cm.srq = NULL;
b1404069 1521 return;
7b3687df 1522 }
b1404069 1523
7b3687df
RD
1524}
1525
1526int ipoib_cm_dev_init(struct net_device *dev)
1527{
1528 struct ipoib_dev_priv *priv = netdev_priv(dev);
586a6934
PS
1529 int i, ret;
1530 struct ib_device_attr attr;
839fcaba
MT
1531
1532 INIT_LIST_HEAD(&priv->cm.passive_ids);
1533 INIT_LIST_HEAD(&priv->cm.reap_list);
1534 INIT_LIST_HEAD(&priv->cm.start_list);
518b1646
MT
1535 INIT_LIST_HEAD(&priv->cm.rx_error_list);
1536 INIT_LIST_HEAD(&priv->cm.rx_flush_list);
1537 INIT_LIST_HEAD(&priv->cm.rx_drain_list);
1538 INIT_LIST_HEAD(&priv->cm.rx_reap_list);
839fcaba
MT
1539 INIT_WORK(&priv->cm.start_task, ipoib_cm_tx_start);
1540 INIT_WORK(&priv->cm.reap_task, ipoib_cm_tx_reap);
1541 INIT_WORK(&priv->cm.skb_task, ipoib_cm_skb_reap);
518b1646 1542 INIT_WORK(&priv->cm.rx_reap_task, ipoib_cm_rx_reap);
839fcaba
MT
1543 INIT_DELAYED_WORK(&priv->cm.stale_task, ipoib_cm_stale_task);
1544
1545 skb_queue_head_init(&priv->cm.skb_queue);
1546
586a6934
PS
1547 ret = ib_query_device(priv->ca, &attr);
1548 if (ret) {
1549 printk(KERN_WARNING "ib_query_device() failed with %d\n", ret);
1550 return ret;
1551 }
1552
1553 ipoib_dbg(priv, "max_srq_sge=%d\n", attr.max_srq_sge);
1554
1555 attr.max_srq_sge = min_t(int, IPOIB_CM_RX_SG, attr.max_srq_sge);
1556 ipoib_cm_create_srq(dev, attr.max_srq_sge);
1557 if (ipoib_cm_has_srq(dev)) {
1558 priv->cm.max_cm_mtu = attr.max_srq_sge * PAGE_SIZE - 0x10;
1559 priv->cm.num_frags = attr.max_srq_sge;
1560 ipoib_dbg(priv, "max_cm_mtu = 0x%x, num_frags=%d\n",
1561 priv->cm.max_cm_mtu, priv->cm.num_frags);
1562 } else {
1563 priv->cm.max_cm_mtu = IPOIB_CM_MTU;
1564 priv->cm.num_frags = IPOIB_CM_RX_SG;
1565 }
1566
a7d834c4 1567 ipoib_cm_init_rx_wr(dev, &priv->cm.rx_wr, priv->cm.rx_sge);
68e995a2
PS
1568
1569 if (ipoib_cm_has_srq(dev)) {
1570 for (i = 0; i < ipoib_recvq_size; ++i) {
1571 if (!ipoib_cm_alloc_rx_skb(dev, priv->cm.srq_ring, i,
586a6934 1572 priv->cm.num_frags - 1,
68e995a2
PS
1573 priv->cm.srq_ring[i].mapping)) {
1574 ipoib_warn(priv, "failed to allocate "
1575 "receive buffer %d\n", i);
1576 ipoib_cm_dev_cleanup(dev);
1577 return -ENOMEM;
1578 }
7b3687df 1579
68e995a2
PS
1580 if (ipoib_cm_post_receive_srq(dev, i)) {
1581 ipoib_warn(priv, "ipoib_cm_post_receive_srq "
1582 "failed for buf %d\n", i);
1583 ipoib_cm_dev_cleanup(dev);
1584 return -EIO;
1585 }
839fcaba
MT
1586 }
1587 }
1588
1589 priv->dev->dev_addr[0] = IPOIB_FLAGS_RC;
1590 return 0;
1591}
1592
1593void ipoib_cm_dev_cleanup(struct net_device *dev)
1594{
1595 struct ipoib_dev_priv *priv = netdev_priv(dev);
1efb6144 1596 int ret;
839fcaba
MT
1597
1598 if (!priv->cm.srq)
1599 return;
1600
1601 ipoib_dbg(priv, "Cleanup ipoib connected mode.\n");
1602
1603 ret = ib_destroy_srq(priv->cm.srq);
1604 if (ret)
1605 ipoib_warn(priv, "ib_destroy_srq failed: %d\n", ret);
1606
1607 priv->cm.srq = NULL;
1608 if (!priv->cm.srq_ring)
1609 return;
1efb6144
RD
1610
1611 ipoib_cm_free_rx_ring(dev, priv->cm.srq_ring);
839fcaba
MT
1612 priv->cm.srq_ring = NULL;
1613}