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