Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 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. |
| 31 | * |
| 32 | * $Id$ |
| 33 | */ |
| 34 | |
| 35 | #include <rdma/ib_cm.h> |
| 36 | #include <rdma/ib_cache.h> |
| 37 | #include <net/dst.h> |
| 38 | #include <net/icmp.h> |
| 39 | #include <linux/icmpv6.h> |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 40 | #include <linux/delay.h> |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 41 | |
| 42 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA |
| 43 | static int data_debug_level; |
| 44 | |
| 45 | module_param_named(cm_data_debug_level, data_debug_level, int, 0644); |
| 46 | MODULE_PARM_DESC(cm_data_debug_level, |
| 47 | "Enable data path debug tracing for connected mode if > 0"); |
| 48 | #endif |
| 49 | |
| 50 | #include "ipoib.h" |
| 51 | |
| 52 | #define IPOIB_CM_IETF_ID 0x1000000000000000ULL |
| 53 | |
| 54 | #define IPOIB_CM_RX_UPDATE_TIME (256 * HZ) |
| 55 | #define IPOIB_CM_RX_TIMEOUT (2 * 256 * HZ) |
| 56 | #define IPOIB_CM_RX_DELAY (3 * 256 * HZ) |
| 57 | #define IPOIB_CM_RX_UPDATE_MASK (0x3) |
| 58 | |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 59 | static struct ib_qp_attr ipoib_cm_err_attr = { |
| 60 | .qp_state = IB_QPS_ERR |
| 61 | }; |
| 62 | |
Roland Dreier | 09f60f8 | 2007-10-26 13:44:25 -0700 | [diff] [blame] | 63 | #define IPOIB_CM_RX_DRAIN_WRID 0xffffffff |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 64 | |
Michael S. Tsirkin | ec56dc0 | 2007-05-28 14:37:27 +0300 | [diff] [blame] | 65 | static struct ib_send_wr ipoib_cm_rx_drain_wr = { |
| 66 | .wr_id = IPOIB_CM_RX_DRAIN_WRID, |
| 67 | .opcode = IB_WR_SEND, |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 68 | }; |
| 69 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 70 | static int ipoib_cm_tx_handler(struct ib_cm_id *cm_id, |
| 71 | struct ib_cm_event *event); |
| 72 | |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 73 | static void ipoib_cm_dma_unmap_rx(struct ipoib_dev_priv *priv, int frags, |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 74 | u64 mapping[IPOIB_CM_RX_SG]) |
| 75 | { |
| 76 | int i; |
| 77 | |
| 78 | ib_dma_unmap_single(priv->ca, mapping[0], IPOIB_CM_HEAD_SIZE, DMA_FROM_DEVICE); |
| 79 | |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 80 | for (i = 0; i < frags; ++i) |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 81 | ib_dma_unmap_single(priv->ca, mapping[i + 1], PAGE_SIZE, DMA_FROM_DEVICE); |
| 82 | } |
| 83 | |
| 84 | static int ipoib_cm_post_receive(struct net_device *dev, int id) |
| 85 | { |
| 86 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 87 | struct ib_recv_wr *bad_wr; |
| 88 | int i, ret; |
| 89 | |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 90 | priv->cm.rx_wr.wr_id = id | IPOIB_OP_CM | IPOIB_OP_RECV; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 91 | |
| 92 | for (i = 0; i < IPOIB_CM_RX_SG; ++i) |
| 93 | priv->cm.rx_sge[i].addr = priv->cm.srq_ring[id].mapping[i]; |
| 94 | |
| 95 | ret = ib_post_srq_recv(priv->cm.srq, &priv->cm.rx_wr, &bad_wr); |
| 96 | if (unlikely(ret)) { |
| 97 | ipoib_warn(priv, "post srq failed for buf %d (%d)\n", id, ret); |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 98 | ipoib_cm_dma_unmap_rx(priv, IPOIB_CM_RX_SG - 1, |
| 99 | priv->cm.srq_ring[id].mapping); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 100 | dev_kfree_skb_any(priv->cm.srq_ring[id].skb); |
| 101 | priv->cm.srq_ring[id].skb = NULL; |
| 102 | } |
| 103 | |
| 104 | return ret; |
| 105 | } |
| 106 | |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 107 | static struct sk_buff *ipoib_cm_alloc_rx_skb(struct net_device *dev, int id, int frags, |
| 108 | u64 mapping[IPOIB_CM_RX_SG]) |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 109 | { |
| 110 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 111 | struct sk_buff *skb; |
| 112 | int i; |
| 113 | |
| 114 | skb = dev_alloc_skb(IPOIB_CM_HEAD_SIZE + 12); |
| 115 | if (unlikely(!skb)) |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 116 | return NULL; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 117 | |
| 118 | /* |
| 119 | * IPoIB adds a 4 byte header. So we need 12 more bytes to align the |
| 120 | * IP header to a multiple of 16. |
| 121 | */ |
| 122 | skb_reserve(skb, 12); |
| 123 | |
| 124 | mapping[0] = ib_dma_map_single(priv->ca, skb->data, IPOIB_CM_HEAD_SIZE, |
| 125 | DMA_FROM_DEVICE); |
| 126 | if (unlikely(ib_dma_mapping_error(priv->ca, mapping[0]))) { |
| 127 | dev_kfree_skb_any(skb); |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 128 | return NULL; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 129 | } |
| 130 | |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 131 | for (i = 0; i < frags; i++) { |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 132 | struct page *page = alloc_page(GFP_ATOMIC); |
| 133 | |
| 134 | if (!page) |
| 135 | goto partial_error; |
| 136 | skb_fill_page_desc(skb, i, page, 0, PAGE_SIZE); |
| 137 | |
| 138 | mapping[i + 1] = ib_dma_map_page(priv->ca, skb_shinfo(skb)->frags[i].page, |
Michael S. Tsirkin | 6371ea3 | 2007-04-10 18:32:42 +0300 | [diff] [blame] | 139 | 0, PAGE_SIZE, DMA_FROM_DEVICE); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 140 | if (unlikely(ib_dma_mapping_error(priv->ca, mapping[i + 1]))) |
| 141 | goto partial_error; |
| 142 | } |
| 143 | |
| 144 | priv->cm.srq_ring[id].skb = skb; |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 145 | return skb; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 146 | |
| 147 | partial_error: |
| 148 | |
| 149 | ib_dma_unmap_single(priv->ca, mapping[0], IPOIB_CM_HEAD_SIZE, DMA_FROM_DEVICE); |
| 150 | |
Ralph Campbell | 841adfc | 2007-06-29 11:37:56 -0700 | [diff] [blame] | 151 | for (; i > 0; --i) |
| 152 | ib_dma_unmap_single(priv->ca, mapping[i], PAGE_SIZE, DMA_FROM_DEVICE); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 153 | |
Michael S. Tsirkin | 8a2e65f | 2007-02-16 00:16:13 +0200 | [diff] [blame] | 154 | dev_kfree_skb_any(skb); |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 155 | return NULL; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 156 | } |
| 157 | |
Roland Dreier | 1efb614 | 2008-01-25 14:15:24 -0800 | [diff] [blame] | 158 | static void ipoib_cm_free_rx_ring(struct net_device *dev, |
| 159 | struct ipoib_cm_rx_buf *rx_ring) |
| 160 | { |
| 161 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 162 | int i; |
| 163 | |
| 164 | for (i = 0; i < ipoib_recvq_size; ++i) |
| 165 | if (rx_ring[i].skb) { |
| 166 | ipoib_cm_dma_unmap_rx(priv, IPOIB_CM_RX_SG - 1, |
| 167 | rx_ring[i].mapping); |
| 168 | dev_kfree_skb_any(rx_ring[i].skb); |
| 169 | } |
| 170 | |
| 171 | kfree(rx_ring); |
| 172 | } |
| 173 | |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 174 | static void ipoib_cm_start_rx_drain(struct ipoib_dev_priv *priv) |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 175 | { |
Michael S. Tsirkin | ec56dc0 | 2007-05-28 14:37:27 +0300 | [diff] [blame] | 176 | struct ib_send_wr *bad_wr; |
| 177 | struct ipoib_cm_rx *p; |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 178 | |
Michael S. Tsirkin | ec56dc0 | 2007-05-28 14:37:27 +0300 | [diff] [blame] | 179 | /* We only reserved 1 extra slot in CQ for drain WRs, so |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 180 | * make sure we have at most 1 outstanding WR. */ |
| 181 | if (list_empty(&priv->cm.rx_flush_list) || |
| 182 | !list_empty(&priv->cm.rx_drain_list)) |
| 183 | return; |
| 184 | |
Michael S. Tsirkin | ec56dc0 | 2007-05-28 14:37:27 +0300 | [diff] [blame] | 185 | /* |
| 186 | * QPs on flush list are error state. This way, a "flush |
| 187 | * error" WC will be immediately generated for each WR we post. |
| 188 | */ |
| 189 | p = list_entry(priv->cm.rx_flush_list.next, typeof(*p), list); |
| 190 | if (ib_post_send(p->qp, &ipoib_cm_rx_drain_wr, &bad_wr)) |
| 191 | ipoib_warn(priv, "failed to post drain wr\n"); |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 192 | |
| 193 | list_splice_init(&priv->cm.rx_flush_list, &priv->cm.rx_drain_list); |
| 194 | } |
| 195 | |
| 196 | static void ipoib_cm_rx_event_handler(struct ib_event *event, void *ctx) |
| 197 | { |
| 198 | struct ipoib_cm_rx *p = ctx; |
| 199 | struct ipoib_dev_priv *priv = netdev_priv(p->dev); |
| 200 | unsigned long flags; |
| 201 | |
| 202 | if (event->event != IB_EVENT_QP_LAST_WQE_REACHED) |
| 203 | return; |
| 204 | |
| 205 | spin_lock_irqsave(&priv->lock, flags); |
| 206 | list_move(&p->list, &priv->cm.rx_flush_list); |
| 207 | p->state = IPOIB_CM_RX_FLUSH; |
| 208 | ipoib_cm_start_rx_drain(priv); |
| 209 | spin_unlock_irqrestore(&priv->lock, flags); |
| 210 | } |
| 211 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 212 | static struct ib_qp *ipoib_cm_create_rx_qp(struct net_device *dev, |
| 213 | struct ipoib_cm_rx *p) |
| 214 | { |
| 215 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 216 | struct ib_qp_init_attr attr = { |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 217 | .event_handler = ipoib_cm_rx_event_handler, |
Michael S. Tsirkin | ec56dc0 | 2007-05-28 14:37:27 +0300 | [diff] [blame] | 218 | .send_cq = priv->cq, /* For drain WR */ |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 219 | .recv_cq = priv->cq, |
| 220 | .srq = priv->cm.srq, |
Michael S. Tsirkin | ec56dc0 | 2007-05-28 14:37:27 +0300 | [diff] [blame] | 221 | .cap.max_send_wr = 1, /* For drain WR */ |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 222 | .cap.max_send_sge = 1, /* FIXME: 0 Seems not to work */ |
| 223 | .sq_sig_type = IB_SIGNAL_ALL_WR, |
| 224 | .qp_type = IB_QPT_RC, |
| 225 | .qp_context = p, |
| 226 | }; |
| 227 | return ib_create_qp(priv->pd, &attr); |
| 228 | } |
| 229 | |
| 230 | static int ipoib_cm_modify_rx_qp(struct net_device *dev, |
| 231 | struct ib_cm_id *cm_id, struct ib_qp *qp, |
| 232 | unsigned psn) |
| 233 | { |
| 234 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 235 | struct ib_qp_attr qp_attr; |
| 236 | int qp_attr_mask, ret; |
| 237 | |
| 238 | qp_attr.qp_state = IB_QPS_INIT; |
| 239 | ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask); |
| 240 | if (ret) { |
| 241 | ipoib_warn(priv, "failed to init QP attr for INIT: %d\n", ret); |
| 242 | return ret; |
| 243 | } |
| 244 | ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask); |
| 245 | if (ret) { |
| 246 | ipoib_warn(priv, "failed to modify QP to INIT: %d\n", ret); |
| 247 | return ret; |
| 248 | } |
| 249 | qp_attr.qp_state = IB_QPS_RTR; |
| 250 | ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask); |
| 251 | if (ret) { |
| 252 | ipoib_warn(priv, "failed to init QP attr for RTR: %d\n", ret); |
| 253 | return ret; |
| 254 | } |
| 255 | qp_attr.rq_psn = psn; |
| 256 | ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask); |
| 257 | if (ret) { |
| 258 | ipoib_warn(priv, "failed to modify QP to RTR: %d\n", ret); |
| 259 | return ret; |
| 260 | } |
Michael S. Tsirkin | ec56dc0 | 2007-05-28 14:37:27 +0300 | [diff] [blame] | 261 | |
| 262 | /* |
| 263 | * Current Mellanox HCA firmware won't generate completions |
| 264 | * with error for drain WRs unless the QP has been moved to |
| 265 | * RTS first. This work-around leaves a window where a QP has |
| 266 | * moved to error asynchronously, but this will eventually get |
| 267 | * fixed in firmware, so let's not error out if modify QP |
| 268 | * fails. |
| 269 | */ |
| 270 | qp_attr.qp_state = IB_QPS_RTS; |
| 271 | ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask); |
| 272 | if (ret) { |
| 273 | ipoib_warn(priv, "failed to init QP attr for RTS: %d\n", ret); |
| 274 | return 0; |
| 275 | } |
| 276 | ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask); |
| 277 | if (ret) { |
| 278 | ipoib_warn(priv, "failed to modify QP to RTS: %d\n", ret); |
| 279 | return 0; |
| 280 | } |
| 281 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | static int ipoib_cm_send_rep(struct net_device *dev, struct ib_cm_id *cm_id, |
| 286 | struct ib_qp *qp, struct ib_cm_req_event_param *req, |
| 287 | unsigned psn) |
| 288 | { |
| 289 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 290 | struct ipoib_cm_data data = {}; |
| 291 | struct ib_cm_rep_param rep = {}; |
| 292 | |
| 293 | data.qpn = cpu_to_be32(priv->qp->qp_num); |
| 294 | data.mtu = cpu_to_be32(IPOIB_CM_BUF_SIZE); |
| 295 | |
| 296 | rep.private_data = &data; |
| 297 | rep.private_data_len = sizeof data; |
| 298 | rep.flow_control = 0; |
| 299 | rep.rnr_retry_count = req->rnr_retry_count; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 300 | rep.srq = 1; |
| 301 | rep.qp_num = qp->qp_num; |
| 302 | rep.starting_psn = psn; |
| 303 | return ib_send_cm_rep(cm_id, &rep); |
| 304 | } |
| 305 | |
| 306 | static int ipoib_cm_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event) |
| 307 | { |
| 308 | struct net_device *dev = cm_id->context; |
| 309 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 310 | struct ipoib_cm_rx *p; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 311 | unsigned psn; |
| 312 | int ret; |
| 313 | |
| 314 | ipoib_dbg(priv, "REQ arrived\n"); |
| 315 | p = kzalloc(sizeof *p, GFP_KERNEL); |
| 316 | if (!p) |
| 317 | return -ENOMEM; |
| 318 | p->dev = dev; |
| 319 | p->id = cm_id; |
Michael S. Tsirkin | 3ec7393 | 2007-06-19 13:40:41 +0300 | [diff] [blame] | 320 | cm_id->context = p; |
| 321 | p->state = IPOIB_CM_RX_LIVE; |
| 322 | p->jiffies = jiffies; |
| 323 | INIT_LIST_HEAD(&p->list); |
| 324 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 325 | p->qp = ipoib_cm_create_rx_qp(dev, p); |
| 326 | if (IS_ERR(p->qp)) { |
| 327 | ret = PTR_ERR(p->qp); |
| 328 | goto err_qp; |
| 329 | } |
| 330 | |
| 331 | psn = random32() & 0xffffff; |
| 332 | ret = ipoib_cm_modify_rx_qp(dev, cm_id, p->qp, psn); |
| 333 | if (ret) |
| 334 | goto err_modify; |
| 335 | |
Michael S. Tsirkin | 3ec7393 | 2007-06-19 13:40:41 +0300 | [diff] [blame] | 336 | spin_lock_irq(&priv->lock); |
| 337 | queue_delayed_work(ipoib_workqueue, |
| 338 | &priv->cm.stale_task, IPOIB_CM_RX_DELAY); |
| 339 | /* Add this entry to passive ids list head, but do not re-add it |
| 340 | * if IB_EVENT_QP_LAST_WQE_REACHED has moved it to flush list. */ |
| 341 | p->jiffies = jiffies; |
| 342 | if (p->state == IPOIB_CM_RX_LIVE) |
| 343 | list_move(&p->list, &priv->cm.passive_ids); |
| 344 | spin_unlock_irq(&priv->lock); |
| 345 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 346 | ret = ipoib_cm_send_rep(dev, cm_id, p->qp, &event->param.req_rcvd, psn); |
| 347 | if (ret) { |
| 348 | ipoib_warn(priv, "failed to send REP: %d\n", ret); |
Michael S. Tsirkin | 3ec7393 | 2007-06-19 13:40:41 +0300 | [diff] [blame] | 349 | if (ib_modify_qp(p->qp, &ipoib_cm_err_attr, IB_QP_STATE)) |
| 350 | ipoib_warn(priv, "unable to move qp to error state\n"); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 351 | } |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 352 | return 0; |
| 353 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 354 | err_modify: |
| 355 | ib_destroy_qp(p->qp); |
| 356 | err_qp: |
| 357 | kfree(p); |
| 358 | return ret; |
| 359 | } |
| 360 | |
| 361 | static int ipoib_cm_rx_handler(struct ib_cm_id *cm_id, |
| 362 | struct ib_cm_event *event) |
| 363 | { |
| 364 | struct ipoib_cm_rx *p; |
| 365 | struct ipoib_dev_priv *priv; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 366 | |
| 367 | switch (event->event) { |
| 368 | case IB_CM_REQ_RECEIVED: |
| 369 | return ipoib_cm_req_handler(cm_id, event); |
| 370 | case IB_CM_DREQ_RECEIVED: |
| 371 | p = cm_id->context; |
| 372 | ib_send_cm_drep(cm_id, NULL, 0); |
| 373 | /* Fall through */ |
| 374 | case IB_CM_REJ_RECEIVED: |
| 375 | p = cm_id->context; |
| 376 | priv = netdev_priv(p->dev); |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 377 | if (ib_modify_qp(p->qp, &ipoib_cm_err_attr, IB_QP_STATE)) |
| 378 | ipoib_warn(priv, "unable to move qp to error state\n"); |
| 379 | /* Fall through */ |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 380 | default: |
| 381 | return 0; |
| 382 | } |
| 383 | } |
| 384 | /* Adjust length of skb with fragments to match received data */ |
| 385 | static void skb_put_frags(struct sk_buff *skb, unsigned int hdr_space, |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 386 | unsigned int length, struct sk_buff *toskb) |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 387 | { |
| 388 | int i, num_frags; |
| 389 | unsigned int size; |
| 390 | |
| 391 | /* put header into skb */ |
| 392 | size = min(length, hdr_space); |
| 393 | skb->tail += size; |
| 394 | skb->len += size; |
| 395 | length -= size; |
| 396 | |
| 397 | num_frags = skb_shinfo(skb)->nr_frags; |
| 398 | for (i = 0; i < num_frags; i++) { |
| 399 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 400 | |
| 401 | if (length == 0) { |
| 402 | /* don't need this page */ |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 403 | skb_fill_page_desc(toskb, i, frag->page, 0, PAGE_SIZE); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 404 | --skb_shinfo(skb)->nr_frags; |
| 405 | } else { |
| 406 | size = min(length, (unsigned) PAGE_SIZE); |
| 407 | |
| 408 | frag->size = size; |
| 409 | skb->data_len += size; |
| 410 | skb->truesize += size; |
| 411 | skb->len += size; |
| 412 | length -= size; |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc) |
| 418 | { |
| 419 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 420 | unsigned int wr_id = wc->wr_id & ~(IPOIB_OP_CM | IPOIB_OP_RECV); |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 421 | struct sk_buff *skb, *newskb; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 422 | struct ipoib_cm_rx *p; |
| 423 | unsigned long flags; |
| 424 | u64 mapping[IPOIB_CM_RX_SG]; |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 425 | int frags; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 426 | |
Roland Dreier | a89875f | 2007-04-18 20:20:53 -0700 | [diff] [blame] | 427 | ipoib_dbg_data(priv, "cm recv completion: id %d, status: %d\n", |
| 428 | wr_id, wc->status); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 429 | |
| 430 | if (unlikely(wr_id >= ipoib_recvq_size)) { |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 431 | if (wr_id == (IPOIB_CM_RX_DRAIN_WRID & ~(IPOIB_OP_CM | IPOIB_OP_RECV))) { |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 432 | spin_lock_irqsave(&priv->lock, flags); |
| 433 | list_splice_init(&priv->cm.rx_drain_list, &priv->cm.rx_reap_list); |
| 434 | ipoib_cm_start_rx_drain(priv); |
| 435 | queue_work(ipoib_workqueue, &priv->cm.rx_reap_task); |
| 436 | spin_unlock_irqrestore(&priv->lock, flags); |
| 437 | } else |
| 438 | ipoib_warn(priv, "cm recv completion event with wrid %d (> %d)\n", |
| 439 | wr_id, ipoib_recvq_size); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 440 | return; |
| 441 | } |
| 442 | |
| 443 | skb = priv->cm.srq_ring[wr_id].skb; |
| 444 | |
| 445 | if (unlikely(wc->status != IB_WC_SUCCESS)) { |
| 446 | ipoib_dbg(priv, "cm recv error " |
| 447 | "(status=%d, wrid=%d vend_err %x)\n", |
| 448 | wc->status, wr_id, wc->vendor_err); |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 449 | ++dev->stats.rx_dropped; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 450 | goto repost; |
| 451 | } |
| 452 | |
Roland Dreier | fd31256 | 2007-10-17 21:54:44 -0700 | [diff] [blame] | 453 | if (unlikely(!(wr_id & IPOIB_CM_RX_UPDATE_MASK))) { |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 454 | p = wc->qp->qp_context; |
Michael S. Tsirkin | d6ef7d6 | 2007-05-02 15:31:12 +0300 | [diff] [blame] | 455 | if (p && time_after_eq(jiffies, p->jiffies + IPOIB_CM_RX_UPDATE_TIME)) { |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 456 | spin_lock_irqsave(&priv->lock, flags); |
| 457 | p->jiffies = jiffies; |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 458 | /* Move this entry to list head, but do not re-add it |
| 459 | * if it has been moved out of list. */ |
| 460 | if (p->state == IPOIB_CM_RX_LIVE) |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 461 | list_move(&p->list, &priv->cm.passive_ids); |
| 462 | spin_unlock_irqrestore(&priv->lock, flags); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 466 | frags = PAGE_ALIGN(wc->byte_len - min(wc->byte_len, |
| 467 | (unsigned)IPOIB_CM_HEAD_SIZE)) / PAGE_SIZE; |
| 468 | |
| 469 | newskb = ipoib_cm_alloc_rx_skb(dev, wr_id, frags, mapping); |
| 470 | if (unlikely(!newskb)) { |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 471 | /* |
| 472 | * If we can't allocate a new RX buffer, dump |
| 473 | * this packet and reuse the old buffer. |
| 474 | */ |
| 475 | ipoib_dbg(priv, "failed to allocate receive buffer %d\n", wr_id); |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 476 | ++dev->stats.rx_dropped; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 477 | goto repost; |
| 478 | } |
| 479 | |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 480 | ipoib_cm_dma_unmap_rx(priv, frags, priv->cm.srq_ring[wr_id].mapping); |
| 481 | memcpy(priv->cm.srq_ring[wr_id].mapping, mapping, (frags + 1) * sizeof *mapping); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 482 | |
| 483 | ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n", |
| 484 | wc->byte_len, wc->slid); |
| 485 | |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 486 | skb_put_frags(skb, IPOIB_CM_HEAD_SIZE, wc->byte_len, newskb); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 487 | |
| 488 | skb->protocol = ((struct ipoib_header *) skb->data)->proto; |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 489 | skb_reset_mac_header(skb); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 490 | skb_pull(skb, IPOIB_ENCAP_LEN); |
| 491 | |
| 492 | dev->last_rx = jiffies; |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 493 | ++dev->stats.rx_packets; |
| 494 | dev->stats.rx_bytes += skb->len; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 495 | |
| 496 | skb->dev = dev; |
| 497 | /* XXX get correct PACKET_ type here */ |
| 498 | skb->pkt_type = PACKET_HOST; |
Roland Dreier | 8d1cc86 | 2007-05-06 21:05:32 -0700 | [diff] [blame] | 499 | netif_receive_skb(skb); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 500 | |
| 501 | repost: |
| 502 | if (unlikely(ipoib_cm_post_receive(dev, wr_id))) |
| 503 | ipoib_warn(priv, "ipoib_cm_post_receive failed " |
| 504 | "for buf %d\n", wr_id); |
| 505 | } |
| 506 | |
| 507 | static inline int post_send(struct ipoib_dev_priv *priv, |
| 508 | struct ipoib_cm_tx *tx, |
| 509 | unsigned int wr_id, |
| 510 | u64 addr, int len) |
| 511 | { |
| 512 | struct ib_send_wr *bad_wr; |
| 513 | |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 514 | priv->tx_sge.addr = addr; |
| 515 | priv->tx_sge.length = len; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 516 | |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 517 | priv->tx_wr.wr_id = wr_id | IPOIB_OP_CM; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 518 | |
| 519 | return ib_post_send(tx->qp, &priv->tx_wr, &bad_wr); |
| 520 | } |
| 521 | |
| 522 | void ipoib_cm_send(struct net_device *dev, struct sk_buff *skb, struct ipoib_cm_tx *tx) |
| 523 | { |
| 524 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 525 | struct ipoib_tx_buf *tx_req; |
| 526 | u64 addr; |
| 527 | |
| 528 | if (unlikely(skb->len > tx->mtu)) { |
| 529 | ipoib_warn(priv, "packet len %d (> %d) too long to send, dropping\n", |
| 530 | skb->len, tx->mtu); |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 531 | ++dev->stats.tx_dropped; |
| 532 | ++dev->stats.tx_errors; |
Michael S. Tsirkin | 77d8e1e | 2007-03-21 15:45:05 +0200 | [diff] [blame] | 533 | ipoib_cm_skb_too_long(dev, skb, tx->mtu - IPOIB_ENCAP_LEN); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 534 | return; |
| 535 | } |
| 536 | |
| 537 | ipoib_dbg_data(priv, "sending packet: head 0x%x length %d connection 0x%x\n", |
| 538 | tx->tx_head, skb->len, tx->qp->qp_num); |
| 539 | |
| 540 | /* |
| 541 | * We put the skb into the tx_ring _before_ we call post_send() |
| 542 | * because it's entirely possible that the completion handler will |
| 543 | * run before we execute anything after the post_send(). That |
| 544 | * means we have to make sure everything is properly recorded and |
| 545 | * our state is consistent before we call post_send(). |
| 546 | */ |
| 547 | tx_req = &tx->tx_ring[tx->tx_head & (ipoib_sendq_size - 1)]; |
| 548 | tx_req->skb = skb; |
| 549 | addr = ib_dma_map_single(priv->ca, skb->data, skb->len, DMA_TO_DEVICE); |
| 550 | if (unlikely(ib_dma_mapping_error(priv->ca, addr))) { |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 551 | ++dev->stats.tx_errors; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 552 | dev_kfree_skb_any(skb); |
| 553 | return; |
| 554 | } |
| 555 | |
| 556 | tx_req->mapping = addr; |
| 557 | |
| 558 | if (unlikely(post_send(priv, tx, tx->tx_head & (ipoib_sendq_size - 1), |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 559 | addr, skb->len))) { |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 560 | ipoib_warn(priv, "post_send failed\n"); |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 561 | ++dev->stats.tx_errors; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 562 | ib_dma_unmap_single(priv->ca, addr, skb->len, DMA_TO_DEVICE); |
| 563 | dev_kfree_skb_any(skb); |
| 564 | } else { |
| 565 | dev->trans_start = jiffies; |
| 566 | ++tx->tx_head; |
| 567 | |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 568 | if (++priv->tx_outstanding == ipoib_sendq_size) { |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 569 | ipoib_dbg(priv, "TX ring 0x%x full, stopping kernel net queue\n", |
| 570 | tx->qp->qp_num); |
| 571 | netif_stop_queue(dev); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 576 | void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ib_wc *wc) |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 577 | { |
| 578 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 579 | struct ipoib_cm_tx *tx = wc->qp->qp_context; |
| 580 | unsigned int wr_id = wc->wr_id & ~IPOIB_OP_CM; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 581 | struct ipoib_tx_buf *tx_req; |
| 582 | unsigned long flags; |
| 583 | |
Roland Dreier | a89875f | 2007-04-18 20:20:53 -0700 | [diff] [blame] | 584 | ipoib_dbg_data(priv, "cm send completion: id %d, status: %d\n", |
| 585 | wr_id, wc->status); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 586 | |
| 587 | if (unlikely(wr_id >= ipoib_sendq_size)) { |
| 588 | ipoib_warn(priv, "cm send completion event with wrid %d (> %d)\n", |
| 589 | wr_id, ipoib_sendq_size); |
| 590 | return; |
| 591 | } |
| 592 | |
| 593 | tx_req = &tx->tx_ring[wr_id]; |
| 594 | |
| 595 | ib_dma_unmap_single(priv->ca, tx_req->mapping, tx_req->skb->len, DMA_TO_DEVICE); |
| 596 | |
| 597 | /* FIXME: is this right? Shouldn't we only increment on success? */ |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 598 | ++dev->stats.tx_packets; |
| 599 | dev->stats.tx_bytes += tx_req->skb->len; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 600 | |
| 601 | dev_kfree_skb_any(tx_req->skb); |
| 602 | |
| 603 | spin_lock_irqsave(&priv->tx_lock, flags); |
| 604 | ++tx->tx_tail; |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 605 | if (unlikely(--priv->tx_outstanding == ipoib_sendq_size >> 1) && |
| 606 | netif_queue_stopped(dev) && |
| 607 | test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 608 | netif_wake_queue(dev); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 609 | |
| 610 | if (wc->status != IB_WC_SUCCESS && |
| 611 | wc->status != IB_WC_WR_FLUSH_ERR) { |
| 612 | struct ipoib_neigh *neigh; |
| 613 | |
| 614 | ipoib_dbg(priv, "failed cm send event " |
| 615 | "(status=%d, wrid=%d vend_err %x)\n", |
| 616 | wc->status, wr_id, wc->vendor_err); |
| 617 | |
| 618 | spin_lock(&priv->lock); |
| 619 | neigh = tx->neigh; |
| 620 | |
| 621 | if (neigh) { |
| 622 | neigh->cm = NULL; |
| 623 | list_del(&neigh->list); |
| 624 | if (neigh->ah) |
| 625 | ipoib_put_ah(neigh->ah); |
| 626 | ipoib_neigh_free(dev, neigh); |
| 627 | |
| 628 | tx->neigh = NULL; |
| 629 | } |
| 630 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 631 | if (test_and_clear_bit(IPOIB_FLAG_INITIALIZED, &tx->flags)) { |
| 632 | list_move(&tx->list, &priv->cm.reap_list); |
| 633 | queue_work(ipoib_workqueue, &priv->cm.reap_task); |
| 634 | } |
| 635 | |
| 636 | clear_bit(IPOIB_FLAG_OPER_UP, &tx->flags); |
| 637 | |
| 638 | spin_unlock(&priv->lock); |
| 639 | } |
| 640 | |
| 641 | spin_unlock_irqrestore(&priv->tx_lock, flags); |
| 642 | } |
| 643 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 644 | int ipoib_cm_dev_open(struct net_device *dev) |
| 645 | { |
| 646 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 647 | int ret; |
| 648 | |
| 649 | if (!IPOIB_CM_SUPPORTED(dev->dev_addr)) |
| 650 | return 0; |
| 651 | |
| 652 | priv->cm.id = ib_create_cm_id(priv->ca, ipoib_cm_rx_handler, dev); |
| 653 | if (IS_ERR(priv->cm.id)) { |
| 654 | printk(KERN_WARNING "%s: failed to create CM ID\n", priv->ca->name); |
Michael S. Tsirkin | 347fcfb | 2007-04-30 17:30:28 -0700 | [diff] [blame] | 655 | ret = PTR_ERR(priv->cm.id); |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 656 | goto err_cm; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | ret = ib_cm_listen(priv->cm.id, cpu_to_be64(IPOIB_CM_IETF_ID | priv->qp->qp_num), |
| 660 | 0, NULL); |
| 661 | if (ret) { |
| 662 | printk(KERN_WARNING "%s: failed to listen on ID 0x%llx\n", priv->ca->name, |
| 663 | IPOIB_CM_IETF_ID | priv->qp->qp_num); |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 664 | goto err_listen; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 665 | } |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 666 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 667 | return 0; |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 668 | |
| 669 | err_listen: |
| 670 | ib_destroy_cm_id(priv->cm.id); |
| 671 | err_cm: |
| 672 | priv->cm.id = NULL; |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 673 | return ret; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 674 | } |
| 675 | |
Roland Dreier | efcd997 | 2008-01-25 14:15:24 -0800 | [diff] [blame^] | 676 | static void ipoib_cm_free_rx_reap_list(struct net_device *dev) |
| 677 | { |
| 678 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 679 | struct ipoib_cm_rx *rx, *n; |
| 680 | LIST_HEAD(list); |
| 681 | |
| 682 | spin_lock_irq(&priv->lock); |
| 683 | list_splice_init(&priv->cm.rx_reap_list, &list); |
| 684 | spin_unlock_irq(&priv->lock); |
| 685 | |
| 686 | list_for_each_entry_safe(rx, n, &list, list) { |
| 687 | ib_destroy_cm_id(rx->id); |
| 688 | ib_destroy_qp(rx->qp); |
| 689 | kfree(rx); |
| 690 | } |
| 691 | } |
| 692 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 693 | void ipoib_cm_dev_stop(struct net_device *dev) |
| 694 | { |
| 695 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Roland Dreier | efcd997 | 2008-01-25 14:15:24 -0800 | [diff] [blame^] | 696 | struct ipoib_cm_rx *p; |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 697 | unsigned long begin; |
| 698 | LIST_HEAD(list); |
| 699 | int ret; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 700 | |
Michael S. Tsirkin | 347fcfb | 2007-04-30 17:30:28 -0700 | [diff] [blame] | 701 | if (!IPOIB_CM_SUPPORTED(dev->dev_addr) || !priv->cm.id) |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 702 | return; |
| 703 | |
| 704 | ib_destroy_cm_id(priv->cm.id); |
Michael S. Tsirkin | 347fcfb | 2007-04-30 17:30:28 -0700 | [diff] [blame] | 705 | priv->cm.id = NULL; |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 706 | |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 707 | spin_lock_irq(&priv->lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 708 | while (!list_empty(&priv->cm.passive_ids)) { |
| 709 | p = list_entry(priv->cm.passive_ids.next, typeof(*p), list); |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 710 | list_move(&p->list, &priv->cm.rx_error_list); |
| 711 | p->state = IPOIB_CM_RX_ERROR; |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 712 | spin_unlock_irq(&priv->lock); |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 713 | ret = ib_modify_qp(p->qp, &ipoib_cm_err_attr, IB_QP_STATE); |
| 714 | if (ret) |
| 715 | ipoib_warn(priv, "unable to move qp to error state: %d\n", ret); |
| 716 | spin_lock_irq(&priv->lock); |
| 717 | } |
| 718 | |
| 719 | /* Wait for all RX to be drained */ |
| 720 | begin = jiffies; |
| 721 | |
| 722 | while (!list_empty(&priv->cm.rx_error_list) || |
| 723 | !list_empty(&priv->cm.rx_flush_list) || |
| 724 | !list_empty(&priv->cm.rx_drain_list)) { |
Michael S. Tsirkin | 8fd357a | 2007-05-24 14:02:39 -0700 | [diff] [blame] | 725 | if (time_after(jiffies, begin + 5 * HZ)) { |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 726 | ipoib_warn(priv, "RX drain timing out\n"); |
| 727 | |
| 728 | /* |
| 729 | * assume the HW is wedged and just free up everything. |
| 730 | */ |
| 731 | list_splice_init(&priv->cm.rx_flush_list, &list); |
| 732 | list_splice_init(&priv->cm.rx_error_list, &list); |
| 733 | list_splice_init(&priv->cm.rx_drain_list, &list); |
| 734 | break; |
| 735 | } |
| 736 | spin_unlock_irq(&priv->lock); |
| 737 | msleep(1); |
Michael S. Tsirkin | 2dfbfc3 | 2007-05-24 18:32:46 +0300 | [diff] [blame] | 738 | ipoib_drain_cq(dev); |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 739 | spin_lock_irq(&priv->lock); |
| 740 | } |
| 741 | |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 742 | spin_unlock_irq(&priv->lock); |
| 743 | |
Roland Dreier | efcd997 | 2008-01-25 14:15:24 -0800 | [diff] [blame^] | 744 | ipoib_cm_free_rx_reap_list(dev); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 745 | |
| 746 | cancel_delayed_work(&priv->cm.stale_task); |
| 747 | } |
| 748 | |
| 749 | static int ipoib_cm_rep_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event) |
| 750 | { |
| 751 | struct ipoib_cm_tx *p = cm_id->context; |
| 752 | struct ipoib_dev_priv *priv = netdev_priv(p->dev); |
| 753 | struct ipoib_cm_data *data = event->private_data; |
| 754 | struct sk_buff_head skqueue; |
| 755 | struct ib_qp_attr qp_attr; |
| 756 | int qp_attr_mask, ret; |
| 757 | struct sk_buff *skb; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 758 | |
| 759 | p->mtu = be32_to_cpu(data->mtu); |
| 760 | |
Michael S. Tsirkin | 82c3aca | 2007-06-20 19:22:15 +0300 | [diff] [blame] | 761 | if (p->mtu <= IPOIB_ENCAP_LEN) { |
| 762 | ipoib_warn(priv, "Rejecting connection: mtu %d <= %d\n", |
| 763 | p->mtu, IPOIB_ENCAP_LEN); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 764 | return -EINVAL; |
| 765 | } |
| 766 | |
| 767 | qp_attr.qp_state = IB_QPS_RTR; |
| 768 | ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask); |
| 769 | if (ret) { |
| 770 | ipoib_warn(priv, "failed to init QP attr for RTR: %d\n", ret); |
| 771 | return ret; |
| 772 | } |
| 773 | |
| 774 | qp_attr.rq_psn = 0 /* FIXME */; |
| 775 | ret = ib_modify_qp(p->qp, &qp_attr, qp_attr_mask); |
| 776 | if (ret) { |
| 777 | ipoib_warn(priv, "failed to modify QP to RTR: %d\n", ret); |
| 778 | return ret; |
| 779 | } |
| 780 | |
| 781 | qp_attr.qp_state = IB_QPS_RTS; |
| 782 | ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask); |
| 783 | if (ret) { |
| 784 | ipoib_warn(priv, "failed to init QP attr for RTS: %d\n", ret); |
| 785 | return ret; |
| 786 | } |
| 787 | ret = ib_modify_qp(p->qp, &qp_attr, qp_attr_mask); |
| 788 | if (ret) { |
| 789 | ipoib_warn(priv, "failed to modify QP to RTS: %d\n", ret); |
| 790 | return ret; |
| 791 | } |
| 792 | |
| 793 | skb_queue_head_init(&skqueue); |
| 794 | |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 795 | spin_lock_irq(&priv->lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 796 | set_bit(IPOIB_FLAG_OPER_UP, &p->flags); |
| 797 | if (p->neigh) |
| 798 | while ((skb = __skb_dequeue(&p->neigh->queue))) |
| 799 | __skb_queue_tail(&skqueue, skb); |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 800 | spin_unlock_irq(&priv->lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 801 | |
| 802 | while ((skb = __skb_dequeue(&skqueue))) { |
| 803 | skb->dev = p->dev; |
| 804 | if (dev_queue_xmit(skb)) |
| 805 | ipoib_warn(priv, "dev_queue_xmit failed " |
| 806 | "to requeue packet\n"); |
| 807 | } |
| 808 | |
| 809 | ret = ib_send_cm_rtu(cm_id, NULL, 0); |
| 810 | if (ret) { |
| 811 | ipoib_warn(priv, "failed to send RTU: %d\n", ret); |
| 812 | return ret; |
| 813 | } |
| 814 | return 0; |
| 815 | } |
| 816 | |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 817 | static struct ib_qp *ipoib_cm_create_tx_qp(struct net_device *dev, struct ipoib_cm_tx *tx) |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 818 | { |
| 819 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Dotan Barak | ede6bc0 | 2007-10-07 09:30:48 +0200 | [diff] [blame] | 820 | struct ib_qp_init_attr attr = { |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 821 | .send_cq = priv->cq, |
Dotan Barak | ede6bc0 | 2007-10-07 09:30:48 +0200 | [diff] [blame] | 822 | .recv_cq = priv->cq, |
| 823 | .srq = priv->cm.srq, |
| 824 | .cap.max_send_wr = ipoib_sendq_size, |
| 825 | .cap.max_send_sge = 1, |
| 826 | .sq_sig_type = IB_SIGNAL_ALL_WR, |
| 827 | .qp_type = IB_QPT_RC, |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 828 | .qp_context = tx |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 829 | }; |
Dotan Barak | ede6bc0 | 2007-10-07 09:30:48 +0200 | [diff] [blame] | 830 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 831 | return ib_create_qp(priv->pd, &attr); |
| 832 | } |
| 833 | |
| 834 | static int ipoib_cm_send_req(struct net_device *dev, |
| 835 | struct ib_cm_id *id, struct ib_qp *qp, |
| 836 | u32 qpn, |
| 837 | struct ib_sa_path_rec *pathrec) |
| 838 | { |
| 839 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 840 | struct ipoib_cm_data data = {}; |
| 841 | struct ib_cm_req_param req = {}; |
| 842 | |
| 843 | data.qpn = cpu_to_be32(priv->qp->qp_num); |
| 844 | data.mtu = cpu_to_be32(IPOIB_CM_BUF_SIZE); |
| 845 | |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 846 | req.primary_path = pathrec; |
| 847 | req.alternate_path = NULL; |
| 848 | req.service_id = cpu_to_be64(IPOIB_CM_IETF_ID | qpn); |
| 849 | req.qp_num = qp->qp_num; |
| 850 | req.qp_type = qp->qp_type; |
| 851 | req.private_data = &data; |
| 852 | req.private_data_len = sizeof data; |
| 853 | req.flow_control = 0; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 854 | |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 855 | req.starting_psn = 0; /* FIXME */ |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 856 | |
| 857 | /* |
| 858 | * Pick some arbitrary defaults here; we could make these |
| 859 | * module parameters if anyone cared about setting them. |
| 860 | */ |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 861 | req.responder_resources = 4; |
| 862 | req.remote_cm_response_timeout = 20; |
| 863 | req.local_cm_response_timeout = 20; |
| 864 | req.retry_count = 0; /* RFC draft warns against retries */ |
| 865 | req.rnr_retry_count = 0; /* RFC draft warns against retries */ |
| 866 | req.max_cm_retries = 15; |
| 867 | req.srq = 1; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 868 | return ib_send_cm_req(id, &req); |
| 869 | } |
| 870 | |
| 871 | static int ipoib_cm_modify_tx_init(struct net_device *dev, |
| 872 | struct ib_cm_id *cm_id, struct ib_qp *qp) |
| 873 | { |
| 874 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 875 | struct ib_qp_attr qp_attr; |
| 876 | int qp_attr_mask, ret; |
| 877 | ret = ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &qp_attr.pkey_index); |
| 878 | if (ret) { |
| 879 | ipoib_warn(priv, "pkey 0x%x not in cache: %d\n", priv->pkey, ret); |
| 880 | return ret; |
| 881 | } |
| 882 | |
| 883 | qp_attr.qp_state = IB_QPS_INIT; |
| 884 | qp_attr.qp_access_flags = IB_ACCESS_LOCAL_WRITE; |
| 885 | qp_attr.port_num = priv->port; |
| 886 | qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS | IB_QP_PKEY_INDEX | IB_QP_PORT; |
| 887 | |
| 888 | ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask); |
| 889 | if (ret) { |
| 890 | ipoib_warn(priv, "failed to modify tx QP to INIT: %d\n", ret); |
| 891 | return ret; |
| 892 | } |
| 893 | return 0; |
| 894 | } |
| 895 | |
| 896 | static int ipoib_cm_tx_init(struct ipoib_cm_tx *p, u32 qpn, |
| 897 | struct ib_sa_path_rec *pathrec) |
| 898 | { |
| 899 | struct ipoib_dev_priv *priv = netdev_priv(p->dev); |
| 900 | int ret; |
| 901 | |
| 902 | p->tx_ring = kzalloc(ipoib_sendq_size * sizeof *p->tx_ring, |
| 903 | GFP_KERNEL); |
| 904 | if (!p->tx_ring) { |
| 905 | ipoib_warn(priv, "failed to allocate tx ring\n"); |
| 906 | ret = -ENOMEM; |
| 907 | goto err_tx; |
| 908 | } |
| 909 | |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 910 | p->qp = ipoib_cm_create_tx_qp(p->dev, p); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 911 | if (IS_ERR(p->qp)) { |
| 912 | ret = PTR_ERR(p->qp); |
| 913 | ipoib_warn(priv, "failed to allocate tx qp: %d\n", ret); |
| 914 | goto err_qp; |
| 915 | } |
| 916 | |
| 917 | p->id = ib_create_cm_id(priv->ca, ipoib_cm_tx_handler, p); |
| 918 | if (IS_ERR(p->id)) { |
| 919 | ret = PTR_ERR(p->id); |
| 920 | ipoib_warn(priv, "failed to create tx cm id: %d\n", ret); |
| 921 | goto err_id; |
| 922 | } |
| 923 | |
| 924 | ret = ipoib_cm_modify_tx_init(p->dev, p->id, p->qp); |
| 925 | if (ret) { |
| 926 | ipoib_warn(priv, "failed to modify tx qp to rtr: %d\n", ret); |
| 927 | goto err_modify; |
| 928 | } |
| 929 | |
| 930 | ret = ipoib_cm_send_req(p->dev, p->id, p->qp, qpn, pathrec); |
| 931 | if (ret) { |
| 932 | ipoib_warn(priv, "failed to send cm req: %d\n", ret); |
| 933 | goto err_send_cm; |
| 934 | } |
| 935 | |
| 936 | ipoib_dbg(priv, "Request connection 0x%x for gid " IPOIB_GID_FMT " qpn 0x%x\n", |
| 937 | p->qp->qp_num, IPOIB_GID_ARG(pathrec->dgid), qpn); |
| 938 | |
| 939 | return 0; |
| 940 | |
| 941 | err_send_cm: |
| 942 | err_modify: |
| 943 | ib_destroy_cm_id(p->id); |
| 944 | err_id: |
| 945 | p->id = NULL; |
| 946 | ib_destroy_qp(p->qp); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 947 | err_qp: |
| 948 | p->qp = NULL; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 949 | err_tx: |
| 950 | return ret; |
| 951 | } |
| 952 | |
| 953 | static void ipoib_cm_tx_destroy(struct ipoib_cm_tx *p) |
| 954 | { |
| 955 | struct ipoib_dev_priv *priv = netdev_priv(p->dev); |
| 956 | struct ipoib_tx_buf *tx_req; |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 957 | unsigned long flags; |
| 958 | unsigned long begin; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 959 | |
| 960 | ipoib_dbg(priv, "Destroy active connection 0x%x head 0x%x tail 0x%x\n", |
| 961 | p->qp ? p->qp->qp_num : 0, p->tx_head, p->tx_tail); |
| 962 | |
| 963 | if (p->id) |
| 964 | ib_destroy_cm_id(p->id); |
| 965 | |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 966 | if (p->tx_ring) { |
| 967 | /* Wait for all sends to complete */ |
| 968 | begin = jiffies; |
| 969 | while ((int) p->tx_tail - (int) p->tx_head < 0) { |
| 970 | if (time_after(jiffies, begin + 5 * HZ)) { |
| 971 | ipoib_warn(priv, "timing out; %d sends not completed\n", |
| 972 | p->tx_head - p->tx_tail); |
| 973 | goto timeout; |
| 974 | } |
| 975 | |
| 976 | msleep(1); |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | timeout: |
| 981 | |
| 982 | while ((int) p->tx_tail - (int) p->tx_head < 0) { |
| 983 | tx_req = &p->tx_ring[p->tx_tail & (ipoib_sendq_size - 1)]; |
| 984 | ib_dma_unmap_single(priv->ca, tx_req->mapping, tx_req->skb->len, |
| 985 | DMA_TO_DEVICE); |
| 986 | dev_kfree_skb_any(tx_req->skb); |
| 987 | ++p->tx_tail; |
| 988 | spin_lock_irqsave(&priv->tx_lock, flags); |
| 989 | if (unlikely(--priv->tx_outstanding == ipoib_sendq_size >> 1) && |
| 990 | netif_queue_stopped(p->dev) && |
| 991 | test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) |
| 992 | netif_wake_queue(p->dev); |
| 993 | spin_unlock_irqrestore(&priv->tx_lock, flags); |
| 994 | } |
| 995 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 996 | if (p->qp) |
| 997 | ib_destroy_qp(p->qp); |
| 998 | |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 999 | kfree(p->tx_ring); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1000 | kfree(p); |
| 1001 | } |
| 1002 | |
| 1003 | static int ipoib_cm_tx_handler(struct ib_cm_id *cm_id, |
| 1004 | struct ib_cm_event *event) |
| 1005 | { |
| 1006 | struct ipoib_cm_tx *tx = cm_id->context; |
| 1007 | struct ipoib_dev_priv *priv = netdev_priv(tx->dev); |
| 1008 | struct net_device *dev = priv->dev; |
| 1009 | struct ipoib_neigh *neigh; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1010 | int ret; |
| 1011 | |
| 1012 | switch (event->event) { |
| 1013 | case IB_CM_DREQ_RECEIVED: |
| 1014 | ipoib_dbg(priv, "DREQ received.\n"); |
| 1015 | ib_send_cm_drep(cm_id, NULL, 0); |
| 1016 | break; |
| 1017 | case IB_CM_REP_RECEIVED: |
| 1018 | ipoib_dbg(priv, "REP received.\n"); |
| 1019 | ret = ipoib_cm_rep_handler(cm_id, event); |
| 1020 | if (ret) |
| 1021 | ib_send_cm_rej(cm_id, IB_CM_REJ_CONSUMER_DEFINED, |
| 1022 | NULL, 0, NULL, 0); |
| 1023 | break; |
| 1024 | case IB_CM_REQ_ERROR: |
| 1025 | case IB_CM_REJ_RECEIVED: |
| 1026 | case IB_CM_TIMEWAIT_EXIT: |
| 1027 | ipoib_dbg(priv, "CM error %d.\n", event->event); |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 1028 | spin_lock_irq(&priv->tx_lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1029 | spin_lock(&priv->lock); |
| 1030 | neigh = tx->neigh; |
| 1031 | |
| 1032 | if (neigh) { |
| 1033 | neigh->cm = NULL; |
| 1034 | list_del(&neigh->list); |
| 1035 | if (neigh->ah) |
| 1036 | ipoib_put_ah(neigh->ah); |
| 1037 | ipoib_neigh_free(dev, neigh); |
| 1038 | |
| 1039 | tx->neigh = NULL; |
| 1040 | } |
| 1041 | |
| 1042 | if (test_and_clear_bit(IPOIB_FLAG_INITIALIZED, &tx->flags)) { |
| 1043 | list_move(&tx->list, &priv->cm.reap_list); |
| 1044 | queue_work(ipoib_workqueue, &priv->cm.reap_task); |
| 1045 | } |
| 1046 | |
| 1047 | spin_unlock(&priv->lock); |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 1048 | spin_unlock_irq(&priv->tx_lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1049 | break; |
| 1050 | default: |
| 1051 | break; |
| 1052 | } |
| 1053 | |
| 1054 | return 0; |
| 1055 | } |
| 1056 | |
| 1057 | struct ipoib_cm_tx *ipoib_cm_create_tx(struct net_device *dev, struct ipoib_path *path, |
| 1058 | struct ipoib_neigh *neigh) |
| 1059 | { |
| 1060 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1061 | struct ipoib_cm_tx *tx; |
| 1062 | |
| 1063 | tx = kzalloc(sizeof *tx, GFP_ATOMIC); |
| 1064 | if (!tx) |
| 1065 | return NULL; |
| 1066 | |
| 1067 | neigh->cm = tx; |
| 1068 | tx->neigh = neigh; |
| 1069 | tx->path = path; |
| 1070 | tx->dev = dev; |
| 1071 | list_add(&tx->list, &priv->cm.start_list); |
| 1072 | set_bit(IPOIB_FLAG_INITIALIZED, &tx->flags); |
| 1073 | queue_work(ipoib_workqueue, &priv->cm.start_task); |
| 1074 | return tx; |
| 1075 | } |
| 1076 | |
| 1077 | void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx) |
| 1078 | { |
| 1079 | struct ipoib_dev_priv *priv = netdev_priv(tx->dev); |
| 1080 | if (test_and_clear_bit(IPOIB_FLAG_INITIALIZED, &tx->flags)) { |
| 1081 | list_move(&tx->list, &priv->cm.reap_list); |
| 1082 | queue_work(ipoib_workqueue, &priv->cm.reap_task); |
| 1083 | ipoib_dbg(priv, "Reap connection for gid " IPOIB_GID_FMT "\n", |
| 1084 | IPOIB_GID_ARG(tx->neigh->dgid)); |
| 1085 | tx->neigh = NULL; |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | static void ipoib_cm_tx_start(struct work_struct *work) |
| 1090 | { |
| 1091 | struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv, |
| 1092 | cm.start_task); |
| 1093 | struct net_device *dev = priv->dev; |
| 1094 | struct ipoib_neigh *neigh; |
| 1095 | struct ipoib_cm_tx *p; |
| 1096 | unsigned long flags; |
| 1097 | int ret; |
| 1098 | |
| 1099 | struct ib_sa_path_rec pathrec; |
| 1100 | u32 qpn; |
| 1101 | |
| 1102 | spin_lock_irqsave(&priv->tx_lock, flags); |
| 1103 | spin_lock(&priv->lock); |
| 1104 | while (!list_empty(&priv->cm.start_list)) { |
| 1105 | p = list_entry(priv->cm.start_list.next, typeof(*p), list); |
| 1106 | list_del_init(&p->list); |
| 1107 | neigh = p->neigh; |
| 1108 | qpn = IPOIB_QPN(neigh->neighbour->ha); |
| 1109 | memcpy(&pathrec, &p->path->pathrec, sizeof pathrec); |
| 1110 | spin_unlock(&priv->lock); |
| 1111 | spin_unlock_irqrestore(&priv->tx_lock, flags); |
| 1112 | ret = ipoib_cm_tx_init(p, qpn, &pathrec); |
| 1113 | spin_lock_irqsave(&priv->tx_lock, flags); |
| 1114 | spin_lock(&priv->lock); |
| 1115 | if (ret) { |
| 1116 | neigh = p->neigh; |
| 1117 | if (neigh) { |
| 1118 | neigh->cm = NULL; |
| 1119 | list_del(&neigh->list); |
| 1120 | if (neigh->ah) |
| 1121 | ipoib_put_ah(neigh->ah); |
| 1122 | ipoib_neigh_free(dev, neigh); |
| 1123 | } |
| 1124 | list_del(&p->list); |
| 1125 | kfree(p); |
| 1126 | } |
| 1127 | } |
| 1128 | spin_unlock(&priv->lock); |
| 1129 | spin_unlock_irqrestore(&priv->tx_lock, flags); |
| 1130 | } |
| 1131 | |
| 1132 | static void ipoib_cm_tx_reap(struct work_struct *work) |
| 1133 | { |
| 1134 | struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv, |
| 1135 | cm.reap_task); |
| 1136 | struct ipoib_cm_tx *p; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1137 | |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 1138 | spin_lock_irq(&priv->tx_lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1139 | spin_lock(&priv->lock); |
| 1140 | while (!list_empty(&priv->cm.reap_list)) { |
| 1141 | p = list_entry(priv->cm.reap_list.next, typeof(*p), list); |
| 1142 | list_del(&p->list); |
| 1143 | spin_unlock(&priv->lock); |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 1144 | spin_unlock_irq(&priv->tx_lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1145 | ipoib_cm_tx_destroy(p); |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 1146 | spin_lock_irq(&priv->tx_lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1147 | spin_lock(&priv->lock); |
| 1148 | } |
| 1149 | spin_unlock(&priv->lock); |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 1150 | spin_unlock_irq(&priv->tx_lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | static void ipoib_cm_skb_reap(struct work_struct *work) |
| 1154 | { |
| 1155 | struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv, |
| 1156 | cm.skb_task); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1157 | struct sk_buff *skb; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1158 | |
| 1159 | unsigned mtu = priv->mcast_mtu; |
| 1160 | |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 1161 | spin_lock_irq(&priv->tx_lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1162 | spin_lock(&priv->lock); |
| 1163 | while ((skb = skb_dequeue(&priv->cm.skb_queue))) { |
| 1164 | spin_unlock(&priv->lock); |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 1165 | spin_unlock_irq(&priv->tx_lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1166 | if (skb->protocol == htons(ETH_P_IP)) |
| 1167 | icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu)); |
| 1168 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
| 1169 | else if (skb->protocol == htons(ETH_P_IPV6)) |
Roland Dreier | 20089ca | 2007-07-10 11:18:34 -0700 | [diff] [blame] | 1170 | icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, priv->dev); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1171 | #endif |
| 1172 | dev_kfree_skb_any(skb); |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 1173 | spin_lock_irq(&priv->tx_lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1174 | spin_lock(&priv->lock); |
| 1175 | } |
| 1176 | spin_unlock(&priv->lock); |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 1177 | spin_unlock_irq(&priv->tx_lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1178 | } |
| 1179 | |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 1180 | void ipoib_cm_skb_too_long(struct net_device *dev, struct sk_buff *skb, |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1181 | unsigned int mtu) |
| 1182 | { |
| 1183 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1184 | int e = skb_queue_empty(&priv->cm.skb_queue); |
| 1185 | |
| 1186 | if (skb->dst) |
| 1187 | skb->dst->ops->update_pmtu(skb->dst, mtu); |
| 1188 | |
| 1189 | skb_queue_tail(&priv->cm.skb_queue, skb); |
| 1190 | if (e) |
| 1191 | queue_work(ipoib_workqueue, &priv->cm.skb_task); |
| 1192 | } |
| 1193 | |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 1194 | static void ipoib_cm_rx_reap(struct work_struct *work) |
| 1195 | { |
Roland Dreier | efcd997 | 2008-01-25 14:15:24 -0800 | [diff] [blame^] | 1196 | ipoib_cm_free_rx_reap_list(container_of(work, struct ipoib_dev_priv, |
| 1197 | cm.rx_reap_task)->dev); |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 1198 | } |
| 1199 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1200 | static void ipoib_cm_stale_task(struct work_struct *work) |
| 1201 | { |
| 1202 | struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv, |
| 1203 | cm.stale_task.work); |
| 1204 | struct ipoib_cm_rx *p; |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 1205 | int ret; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1206 | |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 1207 | spin_lock_irq(&priv->lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1208 | while (!list_empty(&priv->cm.passive_ids)) { |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 1209 | /* List is sorted by LRU, start from tail, |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1210 | * stop when we see a recently used entry */ |
| 1211 | p = list_entry(priv->cm.passive_ids.prev, typeof(*p), list); |
Michael S. Tsirkin | 60a596d | 2007-03-22 14:32:09 -0700 | [diff] [blame] | 1212 | if (time_before_eq(jiffies, p->jiffies + IPOIB_CM_RX_TIMEOUT)) |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1213 | break; |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 1214 | list_move(&p->list, &priv->cm.rx_error_list); |
| 1215 | p->state = IPOIB_CM_RX_ERROR; |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 1216 | spin_unlock_irq(&priv->lock); |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 1217 | ret = ib_modify_qp(p->qp, &ipoib_cm_err_attr, IB_QP_STATE); |
| 1218 | if (ret) |
| 1219 | ipoib_warn(priv, "unable to move qp to error state: %d\n", ret); |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 1220 | spin_lock_irq(&priv->lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1221 | } |
Michael S. Tsirkin | 7c5b9ef | 2007-05-14 07:26:51 +0300 | [diff] [blame] | 1222 | |
| 1223 | if (!list_empty(&priv->cm.passive_ids)) |
| 1224 | queue_delayed_work(ipoib_workqueue, |
| 1225 | &priv->cm.stale_task, IPOIB_CM_RX_DELAY); |
Roland Dreier | 37aebbde | 2007-04-24 21:30:37 -0700 | [diff] [blame] | 1226 | spin_unlock_irq(&priv->lock); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 1230 | static ssize_t show_mode(struct device *d, struct device_attribute *attr, |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1231 | char *buf) |
| 1232 | { |
| 1233 | struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(d)); |
| 1234 | |
| 1235 | if (test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags)) |
| 1236 | return sprintf(buf, "connected\n"); |
| 1237 | else |
| 1238 | return sprintf(buf, "datagram\n"); |
| 1239 | } |
| 1240 | |
| 1241 | static ssize_t set_mode(struct device *d, struct device_attribute *attr, |
| 1242 | const char *buf, size_t count) |
| 1243 | { |
| 1244 | struct net_device *dev = to_net_dev(d); |
| 1245 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1246 | |
| 1247 | /* flush paths if we switch modes so that connections are restarted */ |
| 1248 | if (IPOIB_CM_SUPPORTED(dev->dev_addr) && !strcmp(buf, "connected\n")) { |
| 1249 | set_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags); |
| 1250 | ipoib_warn(priv, "enabling connected mode " |
| 1251 | "will cause multicast packet drops\n"); |
| 1252 | ipoib_flush_paths(dev); |
| 1253 | return count; |
| 1254 | } |
| 1255 | |
| 1256 | if (!strcmp(buf, "datagram\n")) { |
| 1257 | clear_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags); |
| 1258 | dev->mtu = min(priv->mcast_mtu, dev->mtu); |
| 1259 | ipoib_flush_paths(dev); |
| 1260 | return count; |
| 1261 | } |
| 1262 | |
| 1263 | return -EINVAL; |
| 1264 | } |
| 1265 | |
Roland Dreier | 551fd61 | 2007-02-16 13:57:33 -0800 | [diff] [blame] | 1266 | static DEVICE_ATTR(mode, S_IWUSR | S_IRUGO, show_mode, set_mode); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1267 | |
| 1268 | int ipoib_cm_add_mode_attr(struct net_device *dev) |
| 1269 | { |
| 1270 | return device_create_file(&dev->dev, &dev_attr_mode); |
| 1271 | } |
| 1272 | |
Roland Dreier | 7b3687d | 2008-01-25 14:15:24 -0800 | [diff] [blame] | 1273 | static int ipoib_cm_create_srq(struct net_device *dev) |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1274 | { |
| 1275 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1276 | struct ib_srq_init_attr srq_init_attr = { |
| 1277 | .attr = { |
| 1278 | .max_wr = ipoib_recvq_size, |
| 1279 | .max_sge = IPOIB_CM_RX_SG |
| 1280 | } |
| 1281 | }; |
Roland Dreier | 7b3687d | 2008-01-25 14:15:24 -0800 | [diff] [blame] | 1282 | int ret; |
| 1283 | |
| 1284 | priv->cm.srq = ib_create_srq(priv->pd, &srq_init_attr); |
| 1285 | if (IS_ERR(priv->cm.srq)) { |
| 1286 | ret = PTR_ERR(priv->cm.srq); |
| 1287 | priv->cm.srq = NULL; |
| 1288 | return ret; |
| 1289 | } |
| 1290 | |
| 1291 | priv->cm.srq_ring = kzalloc(ipoib_recvq_size * sizeof *priv->cm.srq_ring, |
| 1292 | GFP_KERNEL); |
| 1293 | if (!priv->cm.srq_ring) { |
| 1294 | printk(KERN_WARNING "%s: failed to allocate CM ring (%d entries)\n", |
| 1295 | priv->ca->name, ipoib_recvq_size); |
| 1296 | ib_destroy_srq(priv->cm.srq); |
| 1297 | priv->cm.srq = NULL; |
| 1298 | return -ENOMEM; |
| 1299 | } |
| 1300 | |
| 1301 | return 0; |
| 1302 | } |
| 1303 | |
| 1304 | int ipoib_cm_dev_init(struct net_device *dev) |
| 1305 | { |
| 1306 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1307 | int ret, i; |
| 1308 | |
| 1309 | INIT_LIST_HEAD(&priv->cm.passive_ids); |
| 1310 | INIT_LIST_HEAD(&priv->cm.reap_list); |
| 1311 | INIT_LIST_HEAD(&priv->cm.start_list); |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 1312 | INIT_LIST_HEAD(&priv->cm.rx_error_list); |
| 1313 | INIT_LIST_HEAD(&priv->cm.rx_flush_list); |
| 1314 | INIT_LIST_HEAD(&priv->cm.rx_drain_list); |
| 1315 | INIT_LIST_HEAD(&priv->cm.rx_reap_list); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1316 | INIT_WORK(&priv->cm.start_task, ipoib_cm_tx_start); |
| 1317 | INIT_WORK(&priv->cm.reap_task, ipoib_cm_tx_reap); |
| 1318 | INIT_WORK(&priv->cm.skb_task, ipoib_cm_skb_reap); |
Michael S. Tsirkin | 518b164 | 2007-05-21 15:04:59 +0300 | [diff] [blame] | 1319 | INIT_WORK(&priv->cm.rx_reap_task, ipoib_cm_rx_reap); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1320 | INIT_DELAYED_WORK(&priv->cm.stale_task, ipoib_cm_stale_task); |
| 1321 | |
| 1322 | skb_queue_head_init(&priv->cm.skb_queue); |
| 1323 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1324 | for (i = 0; i < IPOIB_CM_RX_SG; ++i) |
| 1325 | priv->cm.rx_sge[i].lkey = priv->mr->lkey; |
| 1326 | |
| 1327 | priv->cm.rx_sge[0].length = IPOIB_CM_HEAD_SIZE; |
| 1328 | for (i = 1; i < IPOIB_CM_RX_SG; ++i) |
| 1329 | priv->cm.rx_sge[i].length = PAGE_SIZE; |
| 1330 | priv->cm.rx_wr.next = NULL; |
| 1331 | priv->cm.rx_wr.sg_list = priv->cm.rx_sge; |
| 1332 | priv->cm.rx_wr.num_sge = IPOIB_CM_RX_SG; |
| 1333 | |
Roland Dreier | 7b3687d | 2008-01-25 14:15:24 -0800 | [diff] [blame] | 1334 | ret = ipoib_cm_create_srq(dev); |
| 1335 | if (ret) |
| 1336 | return ret; |
| 1337 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1338 | for (i = 0; i < ipoib_recvq_size; ++i) { |
Michael S. Tsirkin | 1812063 | 2007-02-20 20:17:55 +0200 | [diff] [blame] | 1339 | if (!ipoib_cm_alloc_rx_skb(dev, i, IPOIB_CM_RX_SG - 1, |
| 1340 | priv->cm.srq_ring[i].mapping)) { |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1341 | ipoib_warn(priv, "failed to allocate receive buffer %d\n", i); |
| 1342 | ipoib_cm_dev_cleanup(dev); |
| 1343 | return -ENOMEM; |
| 1344 | } |
| 1345 | if (ipoib_cm_post_receive(dev, i)) { |
| 1346 | ipoib_warn(priv, "ipoib_ib_post_receive failed for buf %d\n", i); |
| 1347 | ipoib_cm_dev_cleanup(dev); |
| 1348 | return -EIO; |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | priv->dev->dev_addr[0] = IPOIB_FLAGS_RC; |
| 1353 | return 0; |
| 1354 | } |
| 1355 | |
| 1356 | void ipoib_cm_dev_cleanup(struct net_device *dev) |
| 1357 | { |
| 1358 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Roland Dreier | 1efb614 | 2008-01-25 14:15:24 -0800 | [diff] [blame] | 1359 | int ret; |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1360 | |
| 1361 | if (!priv->cm.srq) |
| 1362 | return; |
| 1363 | |
| 1364 | ipoib_dbg(priv, "Cleanup ipoib connected mode.\n"); |
| 1365 | |
| 1366 | ret = ib_destroy_srq(priv->cm.srq); |
| 1367 | if (ret) |
| 1368 | ipoib_warn(priv, "ib_destroy_srq failed: %d\n", ret); |
| 1369 | |
| 1370 | priv->cm.srq = NULL; |
| 1371 | if (!priv->cm.srq_ring) |
| 1372 | return; |
Roland Dreier | 1efb614 | 2008-01-25 14:15:24 -0800 | [diff] [blame] | 1373 | |
| 1374 | ipoib_cm_free_rx_ring(dev, priv->cm.srq_ring); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1375 | priv->cm.srq_ring = NULL; |
| 1376 | } |