Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-linus' of master.kernel.org:/pub/scm/linux/kernel/git/roland/infiniband

+2680 -1778
+79 -220
drivers/infiniband/core/agent.c
··· 37 37 * $Id: agent.c 1389 2004-12-27 22:56:47Z roland $ 38 38 */ 39 39 40 - #include <linux/dma-mapping.h> 41 - 42 - #include <asm/bug.h> 43 - 44 - #include <rdma/ib_smi.h> 45 - 46 - #include "smi.h" 47 - #include "agent_priv.h" 48 - #include "mad_priv.h" 49 40 #include "agent.h" 41 + #include "smi.h" 50 42 51 - spinlock_t ib_agent_port_list_lock; 43 + #define SPFX "ib_agent: " 44 + 45 + struct ib_agent_port_private { 46 + struct list_head port_list; 47 + struct ib_mad_agent *agent[2]; 48 + }; 49 + 50 + static DEFINE_SPINLOCK(ib_agent_port_list_lock); 52 51 static LIST_HEAD(ib_agent_port_list); 53 52 54 - /* 55 - * Caller must hold ib_agent_port_list_lock 56 - */ 57 - static inline struct ib_agent_port_private * 58 - __ib_get_agent_port(struct ib_device *device, int port_num, 59 - struct ib_mad_agent *mad_agent) 53 + static struct ib_agent_port_private * 54 + __ib_get_agent_port(struct ib_device *device, int port_num) 60 55 { 61 56 struct ib_agent_port_private *entry; 62 57 63 - BUG_ON(!(!!device ^ !!mad_agent)); /* Exactly one MUST be (!NULL) */ 64 - 65 - if (device) { 66 - list_for_each_entry(entry, &ib_agent_port_list, port_list) { 67 - if (entry->smp_agent->device == device && 68 - entry->port_num == port_num) 69 - return entry; 70 - } 71 - } else { 72 - list_for_each_entry(entry, &ib_agent_port_list, port_list) { 73 - if ((entry->smp_agent == mad_agent) || 74 - (entry->perf_mgmt_agent == mad_agent)) 75 - return entry; 76 - } 58 + list_for_each_entry(entry, &ib_agent_port_list, port_list) { 59 + if (entry->agent[0]->device == device && 60 + entry->agent[0]->port_num == port_num) 61 + return entry; 77 62 } 78 63 return NULL; 79 64 } 80 65 81 - static inline struct ib_agent_port_private * 82 - ib_get_agent_port(struct ib_device *device, int port_num, 83 - struct ib_mad_agent *mad_agent) 66 + static struct ib_agent_port_private * 67 + ib_get_agent_port(struct ib_device *device, int port_num) 84 68 { 85 69 struct ib_agent_port_private *entry; 86 70 unsigned long flags; 87 71 88 72 spin_lock_irqsave(&ib_agent_port_list_lock, flags); 89 - entry = __ib_get_agent_port(device, port_num, mad_agent); 73 + entry = __ib_get_agent_port(device, port_num); 90 74 spin_unlock_irqrestore(&ib_agent_port_list_lock, flags); 91 - 92 75 return entry; 93 76 } 94 77 ··· 83 100 84 101 if (smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) 85 102 return 1; 86 - port_priv = ib_get_agent_port(device, port_num, NULL); 103 + 104 + port_priv = ib_get_agent_port(device, port_num); 87 105 if (!port_priv) { 88 106 printk(KERN_DEBUG SPFX "smi_check_local_dr_smp %s port %d " 89 - "not open\n", 90 - device->name, port_num); 107 + "not open\n", device->name, port_num); 91 108 return 1; 92 109 } 93 110 94 - return smi_check_local_smp(port_priv->smp_agent, smp); 111 + return smi_check_local_smp(port_priv->agent[0], smp); 95 112 } 96 113 97 - static int agent_mad_send(struct ib_mad_agent *mad_agent, 98 - struct ib_agent_port_private *port_priv, 99 - struct ib_mad_private *mad_priv, 100 - struct ib_grh *grh, 101 - struct ib_wc *wc) 102 - { 103 - struct ib_agent_send_wr *agent_send_wr; 104 - struct ib_sge gather_list; 105 - struct ib_send_wr send_wr; 106 - struct ib_send_wr *bad_send_wr; 107 - struct ib_ah_attr ah_attr; 108 - unsigned long flags; 109 - int ret = 1; 110 - 111 - agent_send_wr = kmalloc(sizeof(*agent_send_wr), GFP_KERNEL); 112 - if (!agent_send_wr) 113 - goto out; 114 - agent_send_wr->mad = mad_priv; 115 - 116 - gather_list.addr = dma_map_single(mad_agent->device->dma_device, 117 - &mad_priv->mad, 118 - sizeof(mad_priv->mad), 119 - DMA_TO_DEVICE); 120 - gather_list.length = sizeof(mad_priv->mad); 121 - gather_list.lkey = mad_agent->mr->lkey; 122 - 123 - send_wr.next = NULL; 124 - send_wr.opcode = IB_WR_SEND; 125 - send_wr.sg_list = &gather_list; 126 - send_wr.num_sge = 1; 127 - send_wr.wr.ud.remote_qpn = wc->src_qp; /* DQPN */ 128 - send_wr.wr.ud.timeout_ms = 0; 129 - send_wr.send_flags = IB_SEND_SIGNALED | IB_SEND_SOLICITED; 130 - 131 - ah_attr.dlid = wc->slid; 132 - ah_attr.port_num = mad_agent->port_num; 133 - ah_attr.src_path_bits = wc->dlid_path_bits; 134 - ah_attr.sl = wc->sl; 135 - ah_attr.static_rate = 0; 136 - ah_attr.ah_flags = 0; /* No GRH */ 137 - if (mad_priv->mad.mad.mad_hdr.mgmt_class == IB_MGMT_CLASS_PERF_MGMT) { 138 - if (wc->wc_flags & IB_WC_GRH) { 139 - ah_attr.ah_flags = IB_AH_GRH; 140 - /* Should sgid be looked up ? */ 141 - ah_attr.grh.sgid_index = 0; 142 - ah_attr.grh.hop_limit = grh->hop_limit; 143 - ah_attr.grh.flow_label = be32_to_cpu( 144 - grh->version_tclass_flow) & 0xfffff; 145 - ah_attr.grh.traffic_class = (be32_to_cpu( 146 - grh->version_tclass_flow) >> 20) & 0xff; 147 - memcpy(ah_attr.grh.dgid.raw, 148 - grh->sgid.raw, 149 - sizeof(ah_attr.grh.dgid)); 150 - } 151 - } 152 - 153 - agent_send_wr->ah = ib_create_ah(mad_agent->qp->pd, &ah_attr); 154 - if (IS_ERR(agent_send_wr->ah)) { 155 - printk(KERN_ERR SPFX "No memory for address handle\n"); 156 - kfree(agent_send_wr); 157 - goto out; 158 - } 159 - 160 - send_wr.wr.ud.ah = agent_send_wr->ah; 161 - if (mad_priv->mad.mad.mad_hdr.mgmt_class == IB_MGMT_CLASS_PERF_MGMT) { 162 - send_wr.wr.ud.pkey_index = wc->pkey_index; 163 - send_wr.wr.ud.remote_qkey = IB_QP1_QKEY; 164 - } else { /* for SMPs */ 165 - send_wr.wr.ud.pkey_index = 0; 166 - send_wr.wr.ud.remote_qkey = 0; 167 - } 168 - send_wr.wr.ud.mad_hdr = &mad_priv->mad.mad.mad_hdr; 169 - send_wr.wr_id = (unsigned long)agent_send_wr; 170 - 171 - pci_unmap_addr_set(agent_send_wr, mapping, gather_list.addr); 172 - 173 - /* Send */ 174 - spin_lock_irqsave(&port_priv->send_list_lock, flags); 175 - if (ib_post_send_mad(mad_agent, &send_wr, &bad_send_wr)) { 176 - spin_unlock_irqrestore(&port_priv->send_list_lock, flags); 177 - dma_unmap_single(mad_agent->device->dma_device, 178 - pci_unmap_addr(agent_send_wr, mapping), 179 - sizeof(mad_priv->mad), 180 - DMA_TO_DEVICE); 181 - ib_destroy_ah(agent_send_wr->ah); 182 - kfree(agent_send_wr); 183 - } else { 184 - list_add_tail(&agent_send_wr->send_list, 185 - &port_priv->send_posted_list); 186 - spin_unlock_irqrestore(&port_priv->send_list_lock, flags); 187 - ret = 0; 188 - } 189 - 190 - out: 191 - return ret; 192 - } 193 - 194 - int agent_send(struct ib_mad_private *mad, 195 - struct ib_grh *grh, 196 - struct ib_wc *wc, 197 - struct ib_device *device, 198 - int port_num) 114 + int agent_send_response(struct ib_mad *mad, struct ib_grh *grh, 115 + struct ib_wc *wc, struct ib_device *device, 116 + int port_num, int qpn) 199 117 { 200 118 struct ib_agent_port_private *port_priv; 201 - struct ib_mad_agent *mad_agent; 119 + struct ib_mad_agent *agent; 120 + struct ib_mad_send_buf *send_buf; 121 + struct ib_ah *ah; 122 + int ret; 202 123 203 - port_priv = ib_get_agent_port(device, port_num, NULL); 124 + port_priv = ib_get_agent_port(device, port_num); 204 125 if (!port_priv) { 205 - printk(KERN_DEBUG SPFX "agent_send %s port %d not open\n", 206 - device->name, port_num); 207 - return 1; 126 + printk(KERN_ERR SPFX "Unable to find port agent\n"); 127 + return -ENODEV; 208 128 } 209 129 210 - /* Get mad agent based on mgmt_class in MAD */ 211 - switch (mad->mad.mad.mad_hdr.mgmt_class) { 212 - case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE: 213 - case IB_MGMT_CLASS_SUBN_LID_ROUTED: 214 - mad_agent = port_priv->smp_agent; 215 - break; 216 - case IB_MGMT_CLASS_PERF_MGMT: 217 - mad_agent = port_priv->perf_mgmt_agent; 218 - break; 219 - default: 220 - return 1; 130 + agent = port_priv->agent[qpn]; 131 + ah = ib_create_ah_from_wc(agent->qp->pd, wc, grh, port_num); 132 + if (IS_ERR(ah)) { 133 + ret = PTR_ERR(ah); 134 + printk(KERN_ERR SPFX "ib_create_ah_from_wc error:%d\n", ret); 135 + return ret; 221 136 } 222 137 223 - return agent_mad_send(mad_agent, port_priv, mad, grh, wc); 138 + send_buf = ib_create_send_mad(agent, wc->src_qp, wc->pkey_index, 0, 139 + IB_MGMT_MAD_HDR, IB_MGMT_MAD_DATA, 140 + GFP_KERNEL); 141 + if (IS_ERR(send_buf)) { 142 + ret = PTR_ERR(send_buf); 143 + printk(KERN_ERR SPFX "ib_create_send_mad error:%d\n", ret); 144 + goto err1; 145 + } 146 + 147 + memcpy(send_buf->mad, mad, sizeof *mad); 148 + send_buf->ah = ah; 149 + if ((ret = ib_post_send_mad(send_buf, NULL))) { 150 + printk(KERN_ERR SPFX "ib_post_send_mad error:%d\n", ret); 151 + goto err2; 152 + } 153 + return 0; 154 + err2: 155 + ib_free_send_mad(send_buf); 156 + err1: 157 + ib_destroy_ah(ah); 158 + return ret; 224 159 } 225 160 226 161 static void agent_send_handler(struct ib_mad_agent *mad_agent, 227 162 struct ib_mad_send_wc *mad_send_wc) 228 163 { 229 - struct ib_agent_port_private *port_priv; 230 - struct ib_agent_send_wr *agent_send_wr; 231 - unsigned long flags; 232 - 233 - /* Find matching MAD agent */ 234 - port_priv = ib_get_agent_port(NULL, 0, mad_agent); 235 - if (!port_priv) { 236 - printk(KERN_ERR SPFX "agent_send_handler: no matching MAD " 237 - "agent %p\n", mad_agent); 238 - return; 239 - } 240 - 241 - agent_send_wr = (struct ib_agent_send_wr *)(unsigned long)mad_send_wc->wr_id; 242 - spin_lock_irqsave(&port_priv->send_list_lock, flags); 243 - /* Remove completed send from posted send MAD list */ 244 - list_del(&agent_send_wr->send_list); 245 - spin_unlock_irqrestore(&port_priv->send_list_lock, flags); 246 - 247 - dma_unmap_single(mad_agent->device->dma_device, 248 - pci_unmap_addr(agent_send_wr, mapping), 249 - sizeof(agent_send_wr->mad->mad), 250 - DMA_TO_DEVICE); 251 - 252 - ib_destroy_ah(agent_send_wr->ah); 253 - 254 - /* Release allocated memory */ 255 - kmem_cache_free(ib_mad_cache, agent_send_wr->mad); 256 - kfree(agent_send_wr); 164 + ib_destroy_ah(mad_send_wc->send_buf->ah); 165 + ib_free_send_mad(mad_send_wc->send_buf); 257 166 } 258 167 259 168 int ib_agent_port_open(struct ib_device *device, int port_num) 260 169 { 261 - int ret; 262 170 struct ib_agent_port_private *port_priv; 263 171 unsigned long flags; 264 - 265 - /* First, check if port already open for SMI */ 266 - port_priv = ib_get_agent_port(device, port_num, NULL); 267 - if (port_priv) { 268 - printk(KERN_DEBUG SPFX "%s port %d already open\n", 269 - device->name, port_num); 270 - return 0; 271 - } 172 + int ret; 272 173 273 174 /* Create new device info */ 274 175 port_priv = kmalloc(sizeof *port_priv, GFP_KERNEL); ··· 161 294 ret = -ENOMEM; 162 295 goto error1; 163 296 } 164 - 165 297 memset(port_priv, 0, sizeof *port_priv); 166 - port_priv->port_num = port_num; 167 - spin_lock_init(&port_priv->send_list_lock); 168 - INIT_LIST_HEAD(&port_priv->send_posted_list); 169 298 170 - /* Obtain send only MAD agent for SM class (SMI QP) */ 171 - port_priv->smp_agent = ib_register_mad_agent(device, port_num, 172 - IB_QPT_SMI, 173 - NULL, 0, 299 + /* Obtain send only MAD agent for SMI QP */ 300 + port_priv->agent[0] = ib_register_mad_agent(device, port_num, 301 + IB_QPT_SMI, NULL, 0, 174 302 &agent_send_handler, 175 - NULL, NULL); 176 - 177 - if (IS_ERR(port_priv->smp_agent)) { 178 - ret = PTR_ERR(port_priv->smp_agent); 303 + NULL, NULL); 304 + if (IS_ERR(port_priv->agent[0])) { 305 + ret = PTR_ERR(port_priv->agent[0]); 179 306 goto error2; 180 307 } 181 308 182 - /* Obtain send only MAD agent for PerfMgmt class (GSI QP) */ 183 - port_priv->perf_mgmt_agent = ib_register_mad_agent(device, port_num, 184 - IB_QPT_GSI, 185 - NULL, 0, 186 - &agent_send_handler, 187 - NULL, NULL); 188 - if (IS_ERR(port_priv->perf_mgmt_agent)) { 189 - ret = PTR_ERR(port_priv->perf_mgmt_agent); 309 + /* Obtain send only MAD agent for GSI QP */ 310 + port_priv->agent[1] = ib_register_mad_agent(device, port_num, 311 + IB_QPT_GSI, NULL, 0, 312 + &agent_send_handler, 313 + NULL, NULL); 314 + if (IS_ERR(port_priv->agent[1])) { 315 + ret = PTR_ERR(port_priv->agent[1]); 190 316 goto error3; 191 317 } 192 318 ··· 190 330 return 0; 191 331 192 332 error3: 193 - ib_unregister_mad_agent(port_priv->smp_agent); 333 + ib_unregister_mad_agent(port_priv->agent[0]); 194 334 error2: 195 335 kfree(port_priv); 196 336 error1: ··· 203 343 unsigned long flags; 204 344 205 345 spin_lock_irqsave(&ib_agent_port_list_lock, flags); 206 - port_priv = __ib_get_agent_port(device, port_num, NULL); 346 + port_priv = __ib_get_agent_port(device, port_num); 207 347 if (port_priv == NULL) { 208 348 spin_unlock_irqrestore(&ib_agent_port_list_lock, flags); 209 349 printk(KERN_ERR SPFX "Port %d not found\n", port_num); ··· 212 352 list_del(&port_priv->port_list); 213 353 spin_unlock_irqrestore(&ib_agent_port_list_lock, flags); 214 354 215 - ib_unregister_mad_agent(port_priv->perf_mgmt_agent); 216 - ib_unregister_mad_agent(port_priv->smp_agent); 355 + ib_unregister_mad_agent(port_priv->agent[1]); 356 + ib_unregister_mad_agent(port_priv->agent[0]); 217 357 kfree(port_priv); 218 - 219 358 return 0; 220 359 }
+5 -8
drivers/infiniband/core/agent.h
··· 39 39 #ifndef __AGENT_H_ 40 40 #define __AGENT_H_ 41 41 42 - extern spinlock_t ib_agent_port_list_lock; 42 + #include <rdma/ib_mad.h> 43 43 44 - extern int ib_agent_port_open(struct ib_device *device, 45 - int port_num); 44 + extern int ib_agent_port_open(struct ib_device *device, int port_num); 46 45 47 46 extern int ib_agent_port_close(struct ib_device *device, int port_num); 48 47 49 - extern int agent_send(struct ib_mad_private *mad, 50 - struct ib_grh *grh, 51 - struct ib_wc *wc, 52 - struct ib_device *device, 53 - int port_num); 48 + extern int agent_send_response(struct ib_mad *mad, struct ib_grh *grh, 49 + struct ib_wc *wc, struct ib_device *device, 50 + int port_num, int qpn); 54 51 55 52 #endif /* __AGENT_H_ */
-62
drivers/infiniband/core/agent_priv.h
··· 1 - /* 2 - * Copyright (c) 2004, 2005 Mellanox Technologies Ltd. All rights reserved. 3 - * Copyright (c) 2004, 2005 Infinicon Corporation. All rights reserved. 4 - * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved. 5 - * Copyright (c) 2004, 2005 Topspin Corporation. All rights reserved. 6 - * Copyright (c) 2004, 2005 Voltaire Corporation. All rights reserved. 7 - * 8 - * This software is available to you under a choice of one of two 9 - * licenses. You may choose to be licensed under the terms of the GNU 10 - * General Public License (GPL) Version 2, available from the file 11 - * COPYING in the main directory of this source tree, or the 12 - * OpenIB.org BSD license below: 13 - * 14 - * Redistribution and use in source and binary forms, with or 15 - * without modification, are permitted provided that the following 16 - * conditions are met: 17 - * 18 - * - Redistributions of source code must retain the above 19 - * copyright notice, this list of conditions and the following 20 - * disclaimer. 21 - * 22 - * - Redistributions in binary form must reproduce the above 23 - * copyright notice, this list of conditions and the following 24 - * disclaimer in the documentation and/or other materials 25 - * provided with the distribution. 26 - * 27 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 28 - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 29 - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 30 - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 31 - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 32 - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 33 - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 34 - * SOFTWARE. 35 - * 36 - * $Id: agent_priv.h 1640 2005-01-24 22:39:02Z halr $ 37 - */ 38 - 39 - #ifndef __IB_AGENT_PRIV_H__ 40 - #define __IB_AGENT_PRIV_H__ 41 - 42 - #include <linux/pci.h> 43 - 44 - #define SPFX "ib_agent: " 45 - 46 - struct ib_agent_send_wr { 47 - struct list_head send_list; 48 - struct ib_ah *ah; 49 - struct ib_mad_private *mad; 50 - DECLARE_PCI_UNMAP_ADDR(mapping) 51 - }; 52 - 53 - struct ib_agent_port_private { 54 - struct list_head port_list; 55 - struct list_head send_posted_list; 56 - spinlock_t send_list_lock; 57 - int port_num; 58 - struct ib_mad_agent *smp_agent; /* SM class */ 59 - struct ib_mad_agent *perf_mgmt_agent; /* PerfMgmt class */ 60 - }; 61 - 62 - #endif /* __IB_AGENT_PRIV_H__ */
+98 -119
drivers/infiniband/core/cm.c
··· 135 135 __be64 tid; 136 136 __be32 local_qpn; 137 137 __be32 remote_qpn; 138 + enum ib_qp_type qp_type; 138 139 __be32 sq_psn; 139 140 __be32 rq_psn; 140 141 int timeout_ms; ··· 176 175 177 176 m = ib_create_send_mad(mad_agent, cm_id_priv->id.remote_cm_qpn, 178 177 cm_id_priv->av.pkey_index, 179 - ah, 0, sizeof(struct ib_mad_hdr), 180 - sizeof(struct ib_mad)-sizeof(struct ib_mad_hdr), 178 + 0, IB_MGMT_MAD_HDR, IB_MGMT_MAD_DATA, 181 179 GFP_ATOMIC); 182 180 if (IS_ERR(m)) { 183 181 ib_destroy_ah(ah); ··· 184 184 } 185 185 186 186 /* Timeout set by caller if response is expected. */ 187 - m->send_wr.wr.ud.retries = cm_id_priv->max_cm_retries; 187 + m->ah = ah; 188 + m->retries = cm_id_priv->max_cm_retries; 188 189 189 190 atomic_inc(&cm_id_priv->refcount); 190 191 m->context[0] = cm_id_priv; ··· 206 205 return PTR_ERR(ah); 207 206 208 207 m = ib_create_send_mad(port->mad_agent, 1, mad_recv_wc->wc->pkey_index, 209 - ah, 0, sizeof(struct ib_mad_hdr), 210 - sizeof(struct ib_mad)-sizeof(struct ib_mad_hdr), 208 + 0, IB_MGMT_MAD_HDR, IB_MGMT_MAD_DATA, 211 209 GFP_ATOMIC); 212 210 if (IS_ERR(m)) { 213 211 ib_destroy_ah(ah); 214 212 return PTR_ERR(m); 215 213 } 214 + m->ah = ah; 216 215 *msg = m; 217 216 return 0; 218 217 } 219 218 220 219 static void cm_free_msg(struct ib_mad_send_buf *msg) 221 220 { 222 - ib_destroy_ah(msg->send_wr.wr.ud.ah); 221 + ib_destroy_ah(msg->ah); 223 222 if (msg->context[0]) 224 223 cm_deref_id(msg->context[0]); 225 224 ib_free_send_mad(msg); ··· 367 366 cur_cm_id_priv = rb_entry(parent, struct cm_id_private, 368 367 service_node); 369 368 if ((cur_cm_id_priv->id.service_mask & service_id) == 370 - (service_mask & cur_cm_id_priv->id.service_id)) 371 - return cm_id_priv; 372 - if (service_id < cur_cm_id_priv->id.service_id) 369 + (service_mask & cur_cm_id_priv->id.service_id) && 370 + (cm_id_priv->id.device == cur_cm_id_priv->id.device)) 371 + return cur_cm_id_priv; 372 + 373 + if (cm_id_priv->id.device < cur_cm_id_priv->id.device) 374 + link = &(*link)->rb_left; 375 + else if (cm_id_priv->id.device > cur_cm_id_priv->id.device) 376 + link = &(*link)->rb_right; 377 + else if (service_id < cur_cm_id_priv->id.service_id) 373 378 link = &(*link)->rb_left; 374 379 else 375 380 link = &(*link)->rb_right; ··· 385 378 return NULL; 386 379 } 387 380 388 - static struct cm_id_private * cm_find_listen(__be64 service_id) 381 + static struct cm_id_private * cm_find_listen(struct ib_device *device, 382 + __be64 service_id) 389 383 { 390 384 struct rb_node *node = cm.listen_service_table.rb_node; 391 385 struct cm_id_private *cm_id_priv; ··· 394 386 while (node) { 395 387 cm_id_priv = rb_entry(node, struct cm_id_private, service_node); 396 388 if ((cm_id_priv->id.service_mask & service_id) == 397 - (cm_id_priv->id.service_mask & cm_id_priv->id.service_id)) 389 + cm_id_priv->id.service_id && 390 + (cm_id_priv->id.device == device)) 398 391 return cm_id_priv; 399 - if (service_id < cm_id_priv->id.service_id) 392 + 393 + if (device < cm_id_priv->id.device) 394 + node = node->rb_left; 395 + else if (device > cm_id_priv->id.device) 396 + node = node->rb_right; 397 + else if (service_id < cm_id_priv->id.service_id) 400 398 node = node->rb_left; 401 399 else 402 400 node = node->rb_right; ··· 537 523 ib_send_cm_sidr_rep(&cm_id_priv->id, &param); 538 524 } 539 525 540 - struct ib_cm_id *ib_create_cm_id(ib_cm_handler cm_handler, 526 + struct ib_cm_id *ib_create_cm_id(struct ib_device *device, 527 + ib_cm_handler cm_handler, 541 528 void *context) 542 529 { 543 530 struct cm_id_private *cm_id_priv; ··· 550 535 551 536 memset(cm_id_priv, 0, sizeof *cm_id_priv); 552 537 cm_id_priv->id.state = IB_CM_IDLE; 538 + cm_id_priv->id.device = device; 553 539 cm_id_priv->id.cm_handler = cm_handler; 554 540 cm_id_priv->id.context = context; 555 541 cm_id_priv->id.remote_cm_qpn = 1; ··· 678 662 break; 679 663 case IB_CM_SIDR_REQ_SENT: 680 664 cm_id->state = IB_CM_IDLE; 681 - ib_cancel_mad(cm_id_priv->av.port->mad_agent, 682 - (unsigned long) cm_id_priv->msg); 665 + ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 683 666 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 684 667 break; 685 668 case IB_CM_SIDR_REQ_RCVD: ··· 689 674 case IB_CM_MRA_REQ_RCVD: 690 675 case IB_CM_REP_SENT: 691 676 case IB_CM_MRA_REP_RCVD: 692 - ib_cancel_mad(cm_id_priv->av.port->mad_agent, 693 - (unsigned long) cm_id_priv->msg); 677 + ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 694 678 /* Fall through */ 695 679 case IB_CM_REQ_RCVD: 696 680 case IB_CM_MRA_REQ_SENT: ··· 706 692 ib_send_cm_dreq(cm_id, NULL, 0); 707 693 goto retest; 708 694 case IB_CM_DREQ_SENT: 709 - ib_cancel_mad(cm_id_priv->av.port->mad_agent, 710 - (unsigned long) cm_id_priv->msg); 695 + ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 711 696 cm_enter_timewait(cm_id_priv); 712 697 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 713 698 break; ··· 880 867 struct ib_cm_req_param *param) 881 868 { 882 869 struct cm_id_private *cm_id_priv; 883 - struct ib_send_wr *bad_send_wr; 884 870 struct cm_req_msg *req_msg; 885 871 unsigned long flags; 886 872 int ret; ··· 923 911 cm_id_priv->responder_resources = param->responder_resources; 924 912 cm_id_priv->retry_count = param->retry_count; 925 913 cm_id_priv->path_mtu = param->primary_path->mtu; 914 + cm_id_priv->qp_type = param->qp_type; 926 915 927 916 ret = cm_alloc_msg(cm_id_priv, &cm_id_priv->msg); 928 917 if (ret) ··· 932 919 req_msg = (struct cm_req_msg *) cm_id_priv->msg->mad; 933 920 cm_format_req(req_msg, cm_id_priv, param); 934 921 cm_id_priv->tid = req_msg->hdr.tid; 935 - cm_id_priv->msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms; 922 + cm_id_priv->msg->timeout_ms = cm_id_priv->timeout_ms; 936 923 cm_id_priv->msg->context[1] = (void *) (unsigned long) IB_CM_REQ_SENT; 937 924 938 925 cm_id_priv->local_qpn = cm_req_get_local_qpn(req_msg); ··· 941 928 cm_req_get_primary_local_ack_timeout(req_msg); 942 929 943 930 spin_lock_irqsave(&cm_id_priv->lock, flags); 944 - ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 945 - &cm_id_priv->msg->send_wr, &bad_send_wr); 931 + ret = ib_post_send_mad(cm_id_priv->msg, NULL); 946 932 if (ret) { 947 933 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 948 934 goto error2; ··· 964 952 void *ari, u8 ari_length) 965 953 { 966 954 struct ib_mad_send_buf *msg = NULL; 967 - struct ib_send_wr *bad_send_wr; 968 955 struct cm_rej_msg *rej_msg, *rcv_msg; 969 956 int ret; 970 957 ··· 986 975 memcpy(rej_msg->ari, ari, ari_length); 987 976 } 988 977 989 - ret = ib_post_send_mad(port->mad_agent, &msg->send_wr, &bad_send_wr); 978 + ret = ib_post_send_mad(msg, NULL); 990 979 if (ret) 991 980 cm_free_msg(msg); 992 981 ··· 1058 1047 req_msg = (struct cm_req_msg *)work->mad_recv_wc->recv_buf.mad; 1059 1048 param = &work->cm_event.param.req_rcvd; 1060 1049 param->listen_id = listen_id; 1061 - param->device = cm_id_priv->av.port->mad_agent->device; 1062 1050 param->port = cm_id_priv->av.port->port_num; 1063 1051 param->primary_path = &work->path[0]; 1064 1052 if (req_msg->alt_local_lid) ··· 1166 1156 struct cm_id_private *cm_id_priv) 1167 1157 { 1168 1158 struct ib_mad_send_buf *msg = NULL; 1169 - struct ib_send_wr *bad_send_wr; 1170 1159 unsigned long flags; 1171 1160 int ret; 1172 1161 ··· 1194 1185 } 1195 1186 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 1196 1187 1197 - ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, &msg->send_wr, 1198 - &bad_send_wr); 1188 + ret = ib_post_send_mad(msg, NULL); 1199 1189 if (ret) 1200 1190 goto free; 1201 1191 return; ··· 1234 1226 } 1235 1227 1236 1228 /* Find matching listen request. */ 1237 - listen_cm_id_priv = cm_find_listen(req_msg->service_id); 1229 + listen_cm_id_priv = cm_find_listen(cm_id_priv->id.device, 1230 + req_msg->service_id); 1238 1231 if (!listen_cm_id_priv) { 1239 1232 spin_unlock_irqrestore(&cm.lock, flags); 1240 1233 cm_issue_rej(work->port, work->mad_recv_wc, ··· 1263 1254 1264 1255 req_msg = (struct cm_req_msg *)work->mad_recv_wc->recv_buf.mad; 1265 1256 1266 - cm_id = ib_create_cm_id(NULL, NULL); 1257 + cm_id = ib_create_cm_id(work->port->cm_dev->device, NULL, NULL); 1267 1258 if (IS_ERR(cm_id)) 1268 1259 return PTR_ERR(cm_id); 1269 1260 ··· 1314 1305 cm_req_get_primary_local_ack_timeout(req_msg); 1315 1306 cm_id_priv->retry_count = cm_req_get_retry_count(req_msg); 1316 1307 cm_id_priv->rnr_retry_count = cm_req_get_rnr_retry_count(req_msg); 1308 + cm_id_priv->qp_type = cm_req_get_qp_type(req_msg); 1317 1309 1318 1310 cm_format_req_event(work, cm_id_priv, &listen_cm_id_priv->id); 1319 1311 cm_process_work(cm_id_priv, work); ··· 1359 1349 struct cm_id_private *cm_id_priv; 1360 1350 struct ib_mad_send_buf *msg; 1361 1351 struct cm_rep_msg *rep_msg; 1362 - struct ib_send_wr *bad_send_wr; 1363 1352 unsigned long flags; 1364 1353 int ret; 1365 1354 ··· 1380 1371 1381 1372 rep_msg = (struct cm_rep_msg *) msg->mad; 1382 1373 cm_format_rep(rep_msg, cm_id_priv, param); 1383 - msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms; 1374 + msg->timeout_ms = cm_id_priv->timeout_ms; 1384 1375 msg->context[1] = (void *) (unsigned long) IB_CM_REP_SENT; 1385 1376 1386 - ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 1387 - &msg->send_wr, &bad_send_wr); 1377 + ret = ib_post_send_mad(msg, NULL); 1388 1378 if (ret) { 1389 1379 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 1390 1380 cm_free_msg(msg); ··· 1421 1413 { 1422 1414 struct cm_id_private *cm_id_priv; 1423 1415 struct ib_mad_send_buf *msg; 1424 - struct ib_send_wr *bad_send_wr; 1425 1416 unsigned long flags; 1426 1417 void *data; 1427 1418 int ret; ··· 1447 1440 cm_format_rtu((struct cm_rtu_msg *) msg->mad, cm_id_priv, 1448 1441 private_data, private_data_len); 1449 1442 1450 - ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 1451 - &msg->send_wr, &bad_send_wr); 1443 + ret = ib_post_send_mad(msg, NULL); 1452 1444 if (ret) { 1453 1445 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 1454 1446 cm_free_msg(msg); ··· 1492 1486 struct cm_id_private *cm_id_priv; 1493 1487 struct cm_rep_msg *rep_msg; 1494 1488 struct ib_mad_send_buf *msg = NULL; 1495 - struct ib_send_wr *bad_send_wr; 1496 1489 unsigned long flags; 1497 1490 int ret; 1498 1491 ··· 1519 1514 goto unlock; 1520 1515 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 1521 1516 1522 - ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, &msg->send_wr, 1523 - &bad_send_wr); 1517 + ret = ib_post_send_mad(msg, NULL); 1524 1518 if (ret) 1525 1519 goto free; 1526 1520 goto deref; ··· 1587 1583 1588 1584 /* todo: handle peer_to_peer */ 1589 1585 1590 - ib_cancel_mad(cm_id_priv->av.port->mad_agent, 1591 - (unsigned long) cm_id_priv->msg); 1586 + ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 1592 1587 ret = atomic_inc_and_test(&cm_id_priv->work_count); 1593 1588 if (!ret) 1594 1589 list_add_tail(&work->list, &cm_id_priv->work_list); ··· 1621 1618 goto out; 1622 1619 } 1623 1620 1624 - ib_cancel_mad(cm_id_priv->av.port->mad_agent, 1625 - (unsigned long) cm_id_priv->msg); 1621 + ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 1626 1622 ret = atomic_inc_and_test(&cm_id_priv->work_count); 1627 1623 if (!ret) 1628 1624 list_add_tail(&work->list, &cm_id_priv->work_list); ··· 1660 1658 } 1661 1659 cm_id_priv->id.state = IB_CM_ESTABLISHED; 1662 1660 1663 - ib_cancel_mad(cm_id_priv->av.port->mad_agent, 1664 - (unsigned long) cm_id_priv->msg); 1661 + ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 1665 1662 ret = atomic_inc_and_test(&cm_id_priv->work_count); 1666 1663 if (!ret) 1667 1664 list_add_tail(&work->list, &cm_id_priv->work_list); ··· 1697 1696 { 1698 1697 struct cm_id_private *cm_id_priv; 1699 1698 struct ib_mad_send_buf *msg; 1700 - struct ib_send_wr *bad_send_wr; 1701 1699 unsigned long flags; 1702 1700 int ret; 1703 1701 ··· 1718 1718 1719 1719 cm_format_dreq((struct cm_dreq_msg *) msg->mad, cm_id_priv, 1720 1720 private_data, private_data_len); 1721 - msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms; 1721 + msg->timeout_ms = cm_id_priv->timeout_ms; 1722 1722 msg->context[1] = (void *) (unsigned long) IB_CM_DREQ_SENT; 1723 1723 1724 - ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 1725 - &msg->send_wr, &bad_send_wr); 1724 + ret = ib_post_send_mad(msg, NULL); 1726 1725 if (ret) { 1727 1726 cm_enter_timewait(cm_id_priv); 1728 1727 spin_unlock_irqrestore(&cm_id_priv->lock, flags); ··· 1755 1756 { 1756 1757 struct cm_id_private *cm_id_priv; 1757 1758 struct ib_mad_send_buf *msg; 1758 - struct ib_send_wr *bad_send_wr; 1759 1759 unsigned long flags; 1760 1760 void *data; 1761 1761 int ret; ··· 1784 1786 cm_format_drep((struct cm_drep_msg *) msg->mad, cm_id_priv, 1785 1787 private_data, private_data_len); 1786 1788 1787 - ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, &msg->send_wr, 1788 - &bad_send_wr); 1789 + ret = ib_post_send_mad(msg, NULL); 1789 1790 if (ret) { 1790 1791 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 1791 1792 cm_free_msg(msg); ··· 1801 1804 struct cm_id_private *cm_id_priv; 1802 1805 struct cm_dreq_msg *dreq_msg; 1803 1806 struct ib_mad_send_buf *msg = NULL; 1804 - struct ib_send_wr *bad_send_wr; 1805 1807 unsigned long flags; 1806 1808 int ret; 1807 1809 ··· 1819 1823 switch (cm_id_priv->id.state) { 1820 1824 case IB_CM_REP_SENT: 1821 1825 case IB_CM_DREQ_SENT: 1822 - ib_cancel_mad(cm_id_priv->av.port->mad_agent, 1823 - (unsigned long) cm_id_priv->msg); 1826 + ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 1824 1827 break; 1825 1828 case IB_CM_ESTABLISHED: 1826 1829 case IB_CM_MRA_REP_RCVD: ··· 1833 1838 cm_id_priv->private_data_len); 1834 1839 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 1835 1840 1836 - if (ib_post_send_mad(cm_id_priv->av.port->mad_agent, 1837 - &msg->send_wr, &bad_send_wr)) 1841 + if (ib_post_send_mad(msg, NULL)) 1838 1842 cm_free_msg(msg); 1839 1843 goto deref; 1840 1844 default: ··· 1880 1886 } 1881 1887 cm_enter_timewait(cm_id_priv); 1882 1888 1883 - ib_cancel_mad(cm_id_priv->av.port->mad_agent, 1884 - (unsigned long) cm_id_priv->msg); 1889 + ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 1885 1890 ret = atomic_inc_and_test(&cm_id_priv->work_count); 1886 1891 if (!ret) 1887 1892 list_add_tail(&work->list, &cm_id_priv->work_list); ··· 1905 1912 { 1906 1913 struct cm_id_private *cm_id_priv; 1907 1914 struct ib_mad_send_buf *msg; 1908 - struct ib_send_wr *bad_send_wr; 1909 1915 unsigned long flags; 1910 1916 int ret; 1911 1917 ··· 1948 1956 if (ret) 1949 1957 goto out; 1950 1958 1951 - ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 1952 - &msg->send_wr, &bad_send_wr); 1959 + ret = ib_post_send_mad(msg, NULL); 1953 1960 if (ret) 1954 1961 cm_free_msg(msg); 1955 1962 ··· 2024 2033 case IB_CM_MRA_REQ_RCVD: 2025 2034 case IB_CM_REP_SENT: 2026 2035 case IB_CM_MRA_REP_RCVD: 2027 - ib_cancel_mad(cm_id_priv->av.port->mad_agent, 2028 - (unsigned long) cm_id_priv->msg); 2036 + ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 2029 2037 /* fall through */ 2030 2038 case IB_CM_REQ_RCVD: 2031 2039 case IB_CM_MRA_REQ_SENT: ··· 2034 2044 cm_reset_to_idle(cm_id_priv); 2035 2045 break; 2036 2046 case IB_CM_DREQ_SENT: 2037 - ib_cancel_mad(cm_id_priv->av.port->mad_agent, 2038 - (unsigned long) cm_id_priv->msg); 2047 + ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 2039 2048 /* fall through */ 2040 2049 case IB_CM_REP_RCVD: 2041 2050 case IB_CM_MRA_REP_SENT: ··· 2069 2080 { 2070 2081 struct cm_id_private *cm_id_priv; 2071 2082 struct ib_mad_send_buf *msg; 2072 - struct ib_send_wr *bad_send_wr; 2073 2083 void *data; 2074 2084 unsigned long flags; 2075 2085 int ret; ··· 2092 2104 cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv, 2093 2105 CM_MSG_RESPONSE_REQ, service_timeout, 2094 2106 private_data, private_data_len); 2095 - ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2096 - &msg->send_wr, &bad_send_wr); 2107 + ret = ib_post_send_mad(msg, NULL); 2097 2108 if (ret) 2098 2109 goto error2; 2099 2110 cm_id->state = IB_CM_MRA_REQ_SENT; ··· 2105 2118 cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv, 2106 2119 CM_MSG_RESPONSE_REP, service_timeout, 2107 2120 private_data, private_data_len); 2108 - ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2109 - &msg->send_wr, &bad_send_wr); 2121 + ret = ib_post_send_mad(msg, NULL); 2110 2122 if (ret) 2111 2123 goto error2; 2112 2124 cm_id->state = IB_CM_MRA_REP_SENT; ··· 2118 2132 cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv, 2119 2133 CM_MSG_RESPONSE_OTHER, service_timeout, 2120 2134 private_data, private_data_len); 2121 - ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2122 - &msg->send_wr, &bad_send_wr); 2135 + ret = ib_post_send_mad(msg, NULL); 2123 2136 if (ret) 2124 2137 goto error2; 2125 2138 cm_id->lap_state = IB_CM_MRA_LAP_SENT; ··· 2180 2195 case IB_CM_REQ_SENT: 2181 2196 if (cm_mra_get_msg_mraed(mra_msg) != CM_MSG_RESPONSE_REQ || 2182 2197 ib_modify_mad(cm_id_priv->av.port->mad_agent, 2183 - (unsigned long) cm_id_priv->msg, timeout)) 2198 + cm_id_priv->msg, timeout)) 2184 2199 goto out; 2185 2200 cm_id_priv->id.state = IB_CM_MRA_REQ_RCVD; 2186 2201 break; 2187 2202 case IB_CM_REP_SENT: 2188 2203 if (cm_mra_get_msg_mraed(mra_msg) != CM_MSG_RESPONSE_REP || 2189 2204 ib_modify_mad(cm_id_priv->av.port->mad_agent, 2190 - (unsigned long) cm_id_priv->msg, timeout)) 2205 + cm_id_priv->msg, timeout)) 2191 2206 goto out; 2192 2207 cm_id_priv->id.state = IB_CM_MRA_REP_RCVD; 2193 2208 break; ··· 2195 2210 if (cm_mra_get_msg_mraed(mra_msg) != CM_MSG_RESPONSE_OTHER || 2196 2211 cm_id_priv->id.lap_state != IB_CM_LAP_SENT || 2197 2212 ib_modify_mad(cm_id_priv->av.port->mad_agent, 2198 - (unsigned long) cm_id_priv->msg, timeout)) 2213 + cm_id_priv->msg, timeout)) 2199 2214 goto out; 2200 2215 cm_id_priv->id.lap_state = IB_CM_MRA_LAP_RCVD; 2201 2216 break; ··· 2258 2273 { 2259 2274 struct cm_id_private *cm_id_priv; 2260 2275 struct ib_mad_send_buf *msg; 2261 - struct ib_send_wr *bad_send_wr; 2262 2276 unsigned long flags; 2263 2277 int ret; 2264 2278 ··· 2278 2294 2279 2295 cm_format_lap((struct cm_lap_msg *) msg->mad, cm_id_priv, 2280 2296 alternate_path, private_data, private_data_len); 2281 - msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms; 2297 + msg->timeout_ms = cm_id_priv->timeout_ms; 2282 2298 msg->context[1] = (void *) (unsigned long) IB_CM_ESTABLISHED; 2283 2299 2284 - ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2285 - &msg->send_wr, &bad_send_wr); 2300 + ret = ib_post_send_mad(msg, NULL); 2286 2301 if (ret) { 2287 2302 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 2288 2303 cm_free_msg(msg); ··· 2325 2342 struct cm_lap_msg *lap_msg; 2326 2343 struct ib_cm_lap_event_param *param; 2327 2344 struct ib_mad_send_buf *msg = NULL; 2328 - struct ib_send_wr *bad_send_wr; 2329 2345 unsigned long flags; 2330 2346 int ret; 2331 2347 ··· 2358 2376 cm_id_priv->private_data_len); 2359 2377 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 2360 2378 2361 - if (ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2362 - &msg->send_wr, &bad_send_wr)) 2379 + if (ib_post_send_mad(msg, NULL)) 2363 2380 cm_free_msg(msg); 2364 2381 goto deref; 2365 2382 default: ··· 2414 2433 { 2415 2434 struct cm_id_private *cm_id_priv; 2416 2435 struct ib_mad_send_buf *msg; 2417 - struct ib_send_wr *bad_send_wr; 2418 2436 unsigned long flags; 2419 2437 int ret; 2420 2438 ··· 2436 2456 2437 2457 cm_format_apr((struct cm_apr_msg *) msg->mad, cm_id_priv, status, 2438 2458 info, info_length, private_data, private_data_len); 2439 - ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2440 - &msg->send_wr, &bad_send_wr); 2459 + ret = ib_post_send_mad(msg, NULL); 2441 2460 if (ret) { 2442 2461 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 2443 2462 cm_free_msg(msg); ··· 2475 2496 goto out; 2476 2497 } 2477 2498 cm_id_priv->id.lap_state = IB_CM_LAP_IDLE; 2478 - ib_cancel_mad(cm_id_priv->av.port->mad_agent, 2479 - (unsigned long) cm_id_priv->msg); 2499 + ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 2480 2500 cm_id_priv->msg = NULL; 2481 2501 2482 2502 ret = atomic_inc_and_test(&cm_id_priv->work_count); ··· 2550 2572 { 2551 2573 struct cm_id_private *cm_id_priv; 2552 2574 struct ib_mad_send_buf *msg; 2553 - struct ib_send_wr *bad_send_wr; 2554 2575 unsigned long flags; 2555 2576 int ret; 2556 2577 ··· 2572 2595 2573 2596 cm_format_sidr_req((struct cm_sidr_req_msg *) msg->mad, cm_id_priv, 2574 2597 param); 2575 - msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms; 2598 + msg->timeout_ms = cm_id_priv->timeout_ms; 2576 2599 msg->context[1] = (void *) (unsigned long) IB_CM_SIDR_REQ_SENT; 2577 2600 2578 2601 spin_lock_irqsave(&cm_id_priv->lock, flags); 2579 2602 if (cm_id->state == IB_CM_IDLE) 2580 - ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2581 - &msg->send_wr, &bad_send_wr); 2603 + ret = ib_post_send_mad(msg, NULL); 2582 2604 else 2583 2605 ret = -EINVAL; 2584 2606 ··· 2605 2629 param = &work->cm_event.param.sidr_req_rcvd; 2606 2630 param->pkey = __be16_to_cpu(sidr_req_msg->pkey); 2607 2631 param->listen_id = listen_id; 2608 - param->device = work->port->mad_agent->device; 2609 2632 param->port = work->port->port_num; 2610 2633 work->cm_event.private_data = &sidr_req_msg->private_data; 2611 2634 } ··· 2617 2642 struct ib_wc *wc; 2618 2643 unsigned long flags; 2619 2644 2620 - cm_id = ib_create_cm_id(NULL, NULL); 2645 + cm_id = ib_create_cm_id(work->port->cm_dev->device, NULL, NULL); 2621 2646 if (IS_ERR(cm_id)) 2622 2647 return PTR_ERR(cm_id); 2623 2648 cm_id_priv = container_of(cm_id, struct cm_id_private, id); ··· 2641 2666 spin_unlock_irqrestore(&cm.lock, flags); 2642 2667 goto out; /* Duplicate message. */ 2643 2668 } 2644 - cur_cm_id_priv = cm_find_listen(sidr_req_msg->service_id); 2669 + cur_cm_id_priv = cm_find_listen(cm_id->device, 2670 + sidr_req_msg->service_id); 2645 2671 if (!cur_cm_id_priv) { 2646 2672 rb_erase(&cm_id_priv->sidr_id_node, &cm.remote_sidr_table); 2647 2673 spin_unlock_irqrestore(&cm.lock, flags); ··· 2691 2715 { 2692 2716 struct cm_id_private *cm_id_priv; 2693 2717 struct ib_mad_send_buf *msg; 2694 - struct ib_send_wr *bad_send_wr; 2695 2718 unsigned long flags; 2696 2719 int ret; 2697 2720 ··· 2712 2737 2713 2738 cm_format_sidr_rep((struct cm_sidr_rep_msg *) msg->mad, cm_id_priv, 2714 2739 param); 2715 - ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2716 - &msg->send_wr, &bad_send_wr); 2740 + ret = ib_post_send_mad(msg, NULL); 2717 2741 if (ret) { 2718 2742 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 2719 2743 cm_free_msg(msg); ··· 2765 2791 goto out; 2766 2792 } 2767 2793 cm_id_priv->id.state = IB_CM_IDLE; 2768 - ib_cancel_mad(cm_id_priv->av.port->mad_agent, 2769 - (unsigned long) cm_id_priv->msg); 2794 + ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 2770 2795 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 2771 2796 2772 2797 cm_format_sidr_rep_event(work); ··· 2833 2860 static void cm_send_handler(struct ib_mad_agent *mad_agent, 2834 2861 struct ib_mad_send_wc *mad_send_wc) 2835 2862 { 2836 - struct ib_mad_send_buf *msg; 2837 - 2838 - msg = (struct ib_mad_send_buf *)(unsigned long)mad_send_wc->wr_id; 2863 + struct ib_mad_send_buf *msg = mad_send_wc->send_buf; 2839 2864 2840 2865 switch (mad_send_wc->status) { 2841 2866 case IB_WC_SUCCESS: ··· 3035 3064 case IB_CM_ESTABLISHED: 3036 3065 *qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS | 3037 3066 IB_QP_PKEY_INDEX | IB_QP_PORT; 3038 - qp_attr->qp_access_flags = IB_ACCESS_LOCAL_WRITE; 3067 + qp_attr->qp_access_flags = IB_ACCESS_LOCAL_WRITE | 3068 + IB_ACCESS_REMOTE_WRITE; 3039 3069 if (cm_id_priv->responder_resources) 3040 - qp_attr->qp_access_flags |= IB_ACCESS_REMOTE_WRITE | 3041 - IB_ACCESS_REMOTE_READ; 3070 + qp_attr->qp_access_flags |= IB_ACCESS_REMOTE_READ; 3042 3071 qp_attr->pkey_index = cm_id_priv->av.pkey_index; 3043 3072 qp_attr->port_num = cm_id_priv->av.port->port_num; 3044 3073 ret = 0; ··· 3068 3097 case IB_CM_MRA_REP_RCVD: 3069 3098 case IB_CM_ESTABLISHED: 3070 3099 *qp_attr_mask = IB_QP_STATE | IB_QP_AV | IB_QP_PATH_MTU | 3071 - IB_QP_DEST_QPN | IB_QP_RQ_PSN | 3072 - IB_QP_MAX_DEST_RD_ATOMIC | IB_QP_MIN_RNR_TIMER; 3100 + IB_QP_DEST_QPN | IB_QP_RQ_PSN; 3073 3101 qp_attr->ah_attr = cm_id_priv->av.ah_attr; 3074 3102 qp_attr->path_mtu = cm_id_priv->path_mtu; 3075 3103 qp_attr->dest_qp_num = be32_to_cpu(cm_id_priv->remote_qpn); 3076 3104 qp_attr->rq_psn = be32_to_cpu(cm_id_priv->rq_psn); 3077 - qp_attr->max_dest_rd_atomic = cm_id_priv->responder_resources; 3078 - qp_attr->min_rnr_timer = 0; 3105 + if (cm_id_priv->qp_type == IB_QPT_RC) { 3106 + *qp_attr_mask |= IB_QP_MAX_DEST_RD_ATOMIC | 3107 + IB_QP_MIN_RNR_TIMER; 3108 + qp_attr->max_dest_rd_atomic = 3109 + cm_id_priv->responder_resources; 3110 + qp_attr->min_rnr_timer = 0; 3111 + } 3079 3112 if (cm_id_priv->alt_av.ah_attr.dlid) { 3080 3113 *qp_attr_mask |= IB_QP_ALT_PATH; 3081 3114 qp_attr->alt_ah_attr = cm_id_priv->alt_av.ah_attr; ··· 3108 3133 case IB_CM_REP_SENT: 3109 3134 case IB_CM_MRA_REP_RCVD: 3110 3135 case IB_CM_ESTABLISHED: 3111 - *qp_attr_mask = IB_QP_STATE | IB_QP_TIMEOUT | IB_QP_RETRY_CNT | 3112 - IB_QP_RNR_RETRY | IB_QP_SQ_PSN | 3113 - IB_QP_MAX_QP_RD_ATOMIC; 3114 - qp_attr->timeout = cm_id_priv->local_ack_timeout; 3115 - qp_attr->retry_cnt = cm_id_priv->retry_count; 3116 - qp_attr->rnr_retry = cm_id_priv->rnr_retry_count; 3136 + *qp_attr_mask = IB_QP_STATE | IB_QP_SQ_PSN; 3117 3137 qp_attr->sq_psn = be32_to_cpu(cm_id_priv->sq_psn); 3118 - qp_attr->max_rd_atomic = cm_id_priv->initiator_depth; 3138 + if (cm_id_priv->qp_type == IB_QPT_RC) { 3139 + *qp_attr_mask |= IB_QP_TIMEOUT | IB_QP_RETRY_CNT | 3140 + IB_QP_RNR_RETRY | 3141 + IB_QP_MAX_QP_RD_ATOMIC; 3142 + qp_attr->timeout = cm_id_priv->local_ack_timeout; 3143 + qp_attr->retry_cnt = cm_id_priv->retry_count; 3144 + qp_attr->rnr_retry = cm_id_priv->rnr_retry_count; 3145 + qp_attr->max_rd_atomic = cm_id_priv->initiator_depth; 3146 + } 3119 3147 if (cm_id_priv->alt_av.ah_attr.dlid) { 3120 3148 *qp_attr_mask |= IB_QP_PATH_MIG_STATE; 3121 3149 qp_attr->path_mig_state = IB_MIG_REARM; ··· 3301 3323 flush_workqueue(cm.wq); 3302 3324 destroy_workqueue(cm.wq); 3303 3325 ib_unregister_client(&cm_client); 3326 + idr_destroy(&cm.local_id_table); 3304 3327 } 3305 3328 3306 3329 module_init(ib_cm_init);
+1
drivers/infiniband/core/cm_msgs.h
··· 186 186 req_msg->offset40 = cpu_to_be32((be32_to_cpu( 187 187 req_msg->offset40) & 188 188 0xFFFFFFF9) | 0x2); 189 + break; 189 190 default: 190 191 req_msg->offset40 = cpu_to_be32(be32_to_cpu( 191 192 req_msg->offset40) &
+12
drivers/infiniband/core/device.c
··· 514 514 u8 port_num, 515 515 struct ib_port_attr *port_attr) 516 516 { 517 + if (device->node_type == IB_NODE_SWITCH) { 518 + if (port_num) 519 + return -EINVAL; 520 + } else if (port_num < 1 || port_num > device->phys_port_cnt) 521 + return -EINVAL; 522 + 517 523 return device->query_port(device, port_num, port_attr); 518 524 } 519 525 EXPORT_SYMBOL(ib_query_port); ··· 589 583 u8 port_num, int port_modify_mask, 590 584 struct ib_port_modify *port_modify) 591 585 { 586 + if (device->node_type == IB_NODE_SWITCH) { 587 + if (port_num) 588 + return -EINVAL; 589 + } else if (port_num < 1 || port_num > device->phys_port_cnt) 590 + return -EINVAL; 591 + 592 592 return device->modify_port(device, port_num, port_modify_mask, 593 593 port_modify); 594 594 }
+148 -179
drivers/infiniband/core/mad.c
··· 579 579 } 580 580 581 581 static void snoop_send(struct ib_mad_qp_info *qp_info, 582 - struct ib_send_wr *send_wr, 582 + struct ib_mad_send_buf *send_buf, 583 583 struct ib_mad_send_wc *mad_send_wc, 584 584 int mad_snoop_flags) 585 585 { ··· 597 597 atomic_inc(&mad_snoop_priv->refcount); 598 598 spin_unlock_irqrestore(&qp_info->snoop_lock, flags); 599 599 mad_snoop_priv->agent.snoop_handler(&mad_snoop_priv->agent, 600 - send_wr, mad_send_wc); 600 + send_buf, mad_send_wc); 601 601 if (atomic_dec_and_test(&mad_snoop_priv->refcount)) 602 602 wake_up(&mad_snoop_priv->wait); 603 603 spin_lock_irqsave(&qp_info->snoop_lock, flags); ··· 654 654 * Return < 0 if error 655 655 */ 656 656 static int handle_outgoing_dr_smp(struct ib_mad_agent_private *mad_agent_priv, 657 - struct ib_smp *smp, 658 - struct ib_send_wr *send_wr) 657 + struct ib_mad_send_wr_private *mad_send_wr) 659 658 { 660 659 int ret; 660 + struct ib_smp *smp = mad_send_wr->send_buf.mad; 661 661 unsigned long flags; 662 662 struct ib_mad_local_private *local; 663 663 struct ib_mad_private *mad_priv; ··· 666 666 struct ib_device *device = mad_agent_priv->agent.device; 667 667 u8 port_num = mad_agent_priv->agent.port_num; 668 668 struct ib_wc mad_wc; 669 + struct ib_send_wr *send_wr = &mad_send_wr->send_wr; 669 670 670 671 if (!smi_handle_dr_smp_send(smp, device->node_type, port_num)) { 671 672 ret = -EINVAL; ··· 746 745 goto out; 747 746 } 748 747 749 - local->send_wr = *send_wr; 750 - local->send_wr.sg_list = local->sg_list; 751 - memcpy(local->sg_list, send_wr->sg_list, 752 - sizeof *send_wr->sg_list * send_wr->num_sge); 753 - local->send_wr.next = NULL; 754 - local->tid = send_wr->wr.ud.mad_hdr->tid; 755 - local->wr_id = send_wr->wr_id; 748 + local->mad_send_wr = mad_send_wr; 756 749 /* Reference MAD agent until send side of local completion handled */ 757 750 atomic_inc(&mad_agent_priv->refcount); 758 751 /* Queue local completion to local list */ ··· 776 781 777 782 struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent, 778 783 u32 remote_qpn, u16 pkey_index, 779 - struct ib_ah *ah, int rmpp_active, 784 + int rmpp_active, 780 785 int hdr_len, int data_len, 781 786 gfp_t gfp_mask) 782 787 { 783 788 struct ib_mad_agent_private *mad_agent_priv; 784 - struct ib_mad_send_buf *send_buf; 789 + struct ib_mad_send_wr_private *mad_send_wr; 785 790 int buf_size; 786 791 void *buf; 787 792 788 - mad_agent_priv = container_of(mad_agent, 789 - struct ib_mad_agent_private, agent); 793 + mad_agent_priv = container_of(mad_agent, struct ib_mad_agent_private, 794 + agent); 790 795 buf_size = get_buf_length(hdr_len, data_len); 791 796 792 797 if ((!mad_agent->rmpp_version && ··· 794 799 (!rmpp_active && buf_size > sizeof(struct ib_mad))) 795 800 return ERR_PTR(-EINVAL); 796 801 797 - buf = kmalloc(sizeof *send_buf + buf_size, gfp_mask); 802 + buf = kmalloc(sizeof *mad_send_wr + buf_size, gfp_mask); 798 803 if (!buf) 799 804 return ERR_PTR(-ENOMEM); 800 - memset(buf, 0, sizeof *send_buf + buf_size); 805 + memset(buf, 0, sizeof *mad_send_wr + buf_size); 801 806 802 - send_buf = buf + buf_size; 803 - send_buf->mad = buf; 807 + mad_send_wr = buf + buf_size; 808 + mad_send_wr->send_buf.mad = buf; 804 809 805 - send_buf->sge.addr = dma_map_single(mad_agent->device->dma_device, 806 - buf, buf_size, DMA_TO_DEVICE); 807 - pci_unmap_addr_set(send_buf, mapping, send_buf->sge.addr); 808 - send_buf->sge.length = buf_size; 809 - send_buf->sge.lkey = mad_agent->mr->lkey; 810 + mad_send_wr->mad_agent_priv = mad_agent_priv; 811 + mad_send_wr->sg_list[0].length = buf_size; 812 + mad_send_wr->sg_list[0].lkey = mad_agent->mr->lkey; 810 813 811 - send_buf->send_wr.wr_id = (unsigned long) send_buf; 812 - send_buf->send_wr.sg_list = &send_buf->sge; 813 - send_buf->send_wr.num_sge = 1; 814 - send_buf->send_wr.opcode = IB_WR_SEND; 815 - send_buf->send_wr.send_flags = IB_SEND_SIGNALED; 816 - send_buf->send_wr.wr.ud.ah = ah; 817 - send_buf->send_wr.wr.ud.mad_hdr = &send_buf->mad->mad_hdr; 818 - send_buf->send_wr.wr.ud.remote_qpn = remote_qpn; 819 - send_buf->send_wr.wr.ud.remote_qkey = IB_QP_SET_QKEY; 820 - send_buf->send_wr.wr.ud.pkey_index = pkey_index; 814 + mad_send_wr->send_wr.wr_id = (unsigned long) mad_send_wr; 815 + mad_send_wr->send_wr.sg_list = mad_send_wr->sg_list; 816 + mad_send_wr->send_wr.num_sge = 1; 817 + mad_send_wr->send_wr.opcode = IB_WR_SEND; 818 + mad_send_wr->send_wr.send_flags = IB_SEND_SIGNALED; 819 + mad_send_wr->send_wr.wr.ud.remote_qpn = remote_qpn; 820 + mad_send_wr->send_wr.wr.ud.remote_qkey = IB_QP_SET_QKEY; 821 + mad_send_wr->send_wr.wr.ud.pkey_index = pkey_index; 821 822 822 823 if (rmpp_active) { 823 - struct ib_rmpp_mad *rmpp_mad; 824 - rmpp_mad = (struct ib_rmpp_mad *)send_buf->mad; 824 + struct ib_rmpp_mad *rmpp_mad = mad_send_wr->send_buf.mad; 825 825 rmpp_mad->rmpp_hdr.paylen_newwin = cpu_to_be32(hdr_len - 826 - offsetof(struct ib_rmpp_mad, data) + data_len); 826 + IB_MGMT_RMPP_HDR + data_len); 827 827 rmpp_mad->rmpp_hdr.rmpp_version = mad_agent->rmpp_version; 828 828 rmpp_mad->rmpp_hdr.rmpp_type = IB_MGMT_RMPP_TYPE_DATA; 829 829 ib_set_rmpp_flags(&rmpp_mad->rmpp_hdr, 830 830 IB_MGMT_RMPP_FLAG_ACTIVE); 831 831 } 832 832 833 - send_buf->mad_agent = mad_agent; 833 + mad_send_wr->send_buf.mad_agent = mad_agent; 834 834 atomic_inc(&mad_agent_priv->refcount); 835 - return send_buf; 835 + return &mad_send_wr->send_buf; 836 836 } 837 837 EXPORT_SYMBOL(ib_create_send_mad); 838 838 ··· 837 847 838 848 mad_agent_priv = container_of(send_buf->mad_agent, 839 849 struct ib_mad_agent_private, agent); 840 - 841 - dma_unmap_single(send_buf->mad_agent->device->dma_device, 842 - pci_unmap_addr(send_buf, mapping), 843 - send_buf->sge.length, DMA_TO_DEVICE); 844 850 kfree(send_buf->mad); 845 851 846 852 if (atomic_dec_and_test(&mad_agent_priv->refcount)) ··· 847 861 int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr) 848 862 { 849 863 struct ib_mad_qp_info *qp_info; 850 - struct ib_send_wr *bad_send_wr; 851 864 struct list_head *list; 865 + struct ib_send_wr *bad_send_wr; 866 + struct ib_mad_agent *mad_agent; 867 + struct ib_sge *sge; 852 868 unsigned long flags; 853 869 int ret; 854 870 ··· 859 871 mad_send_wr->send_wr.wr_id = (unsigned long)&mad_send_wr->mad_list; 860 872 mad_send_wr->mad_list.mad_queue = &qp_info->send_queue; 861 873 874 + mad_agent = mad_send_wr->send_buf.mad_agent; 875 + sge = mad_send_wr->sg_list; 876 + sge->addr = dma_map_single(mad_agent->device->dma_device, 877 + mad_send_wr->send_buf.mad, sge->length, 878 + DMA_TO_DEVICE); 879 + pci_unmap_addr_set(mad_send_wr, mapping, sge->addr); 880 + 862 881 spin_lock_irqsave(&qp_info->send_queue.lock, flags); 863 882 if (qp_info->send_queue.count < qp_info->send_queue.max_active) { 864 - ret = ib_post_send(mad_send_wr->mad_agent_priv->agent.qp, 865 - &mad_send_wr->send_wr, &bad_send_wr); 883 + ret = ib_post_send(mad_agent->qp, &mad_send_wr->send_wr, 884 + &bad_send_wr); 866 885 list = &qp_info->send_queue.list; 867 886 } else { 868 887 ret = 0; ··· 881 886 list_add_tail(&mad_send_wr->mad_list.list, list); 882 887 } 883 888 spin_unlock_irqrestore(&qp_info->send_queue.lock, flags); 889 + if (ret) 890 + dma_unmap_single(mad_agent->device->dma_device, 891 + pci_unmap_addr(mad_send_wr, mapping), 892 + sge->length, DMA_TO_DEVICE); 893 + 884 894 return ret; 885 895 } 886 896 ··· 893 893 * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated 894 894 * with the registered client 895 895 */ 896 - int ib_post_send_mad(struct ib_mad_agent *mad_agent, 897 - struct ib_send_wr *send_wr, 898 - struct ib_send_wr **bad_send_wr) 896 + int ib_post_send_mad(struct ib_mad_send_buf *send_buf, 897 + struct ib_mad_send_buf **bad_send_buf) 899 898 { 900 - int ret = -EINVAL; 901 899 struct ib_mad_agent_private *mad_agent_priv; 902 - 903 - /* Validate supplied parameters */ 904 - if (!bad_send_wr) 905 - goto error1; 906 - 907 - if (!mad_agent || !send_wr) 908 - goto error2; 909 - 910 - if (!mad_agent->send_handler) 911 - goto error2; 912 - 913 - mad_agent_priv = container_of(mad_agent, 914 - struct ib_mad_agent_private, 915 - agent); 900 + struct ib_mad_send_buf *next_send_buf; 901 + struct ib_mad_send_wr_private *mad_send_wr; 902 + unsigned long flags; 903 + int ret = -EINVAL; 916 904 917 905 /* Walk list of send WRs and post each on send list */ 918 - while (send_wr) { 919 - unsigned long flags; 920 - struct ib_send_wr *next_send_wr; 921 - struct ib_mad_send_wr_private *mad_send_wr; 922 - struct ib_smp *smp; 906 + for (; send_buf; send_buf = next_send_buf) { 923 907 924 - /* Validate more parameters */ 925 - if (send_wr->num_sge > IB_MAD_SEND_REQ_MAX_SG) 926 - goto error2; 908 + mad_send_wr = container_of(send_buf, 909 + struct ib_mad_send_wr_private, 910 + send_buf); 911 + mad_agent_priv = mad_send_wr->mad_agent_priv; 927 912 928 - if (send_wr->wr.ud.timeout_ms && !mad_agent->recv_handler) 929 - goto error2; 930 - 931 - if (!send_wr->wr.ud.mad_hdr) { 932 - printk(KERN_ERR PFX "MAD header must be supplied " 933 - "in WR %p\n", send_wr); 934 - goto error2; 913 + if (!send_buf->mad_agent->send_handler || 914 + (send_buf->timeout_ms && 915 + !send_buf->mad_agent->recv_handler)) { 916 + ret = -EINVAL; 917 + goto error; 935 918 } 936 919 937 920 /* ··· 922 939 * current one completes, and the user modifies the work 923 940 * request associated with the completion 924 941 */ 925 - next_send_wr = (struct ib_send_wr *)send_wr->next; 942 + next_send_buf = send_buf->next; 943 + mad_send_wr->send_wr.wr.ud.ah = send_buf->ah; 926 944 927 - smp = (struct ib_smp *)send_wr->wr.ud.mad_hdr; 928 - if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) { 929 - ret = handle_outgoing_dr_smp(mad_agent_priv, smp, 930 - send_wr); 945 + if (((struct ib_mad_hdr *) send_buf->mad)->mgmt_class == 946 + IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) { 947 + ret = handle_outgoing_dr_smp(mad_agent_priv, 948 + mad_send_wr); 931 949 if (ret < 0) /* error */ 932 - goto error2; 950 + goto error; 933 951 else if (ret == 1) /* locally consumed */ 934 - goto next; 952 + continue; 935 953 } 936 954 937 - /* Allocate MAD send WR tracking structure */ 938 - mad_send_wr = kmalloc(sizeof *mad_send_wr, GFP_ATOMIC); 939 - if (!mad_send_wr) { 940 - printk(KERN_ERR PFX "No memory for " 941 - "ib_mad_send_wr_private\n"); 942 - ret = -ENOMEM; 943 - goto error2; 944 - } 945 - memset(mad_send_wr, 0, sizeof *mad_send_wr); 946 - 947 - mad_send_wr->send_wr = *send_wr; 948 - mad_send_wr->send_wr.sg_list = mad_send_wr->sg_list; 949 - memcpy(mad_send_wr->sg_list, send_wr->sg_list, 950 - sizeof *send_wr->sg_list * send_wr->num_sge); 951 - mad_send_wr->wr_id = send_wr->wr_id; 952 - mad_send_wr->tid = send_wr->wr.ud.mad_hdr->tid; 953 - mad_send_wr->mad_agent_priv = mad_agent_priv; 955 + mad_send_wr->tid = ((struct ib_mad_hdr *) send_buf->mad)->tid; 954 956 /* Timeout will be updated after send completes */ 955 - mad_send_wr->timeout = msecs_to_jiffies(send_wr->wr. 956 - ud.timeout_ms); 957 - mad_send_wr->retries = mad_send_wr->send_wr.wr.ud.retries; 958 - /* One reference for each work request to QP + response */ 957 + mad_send_wr->timeout = msecs_to_jiffies(send_buf->timeout_ms); 958 + mad_send_wr->retries = send_buf->retries; 959 + /* Reference for work request to QP + response */ 959 960 mad_send_wr->refcount = 1 + (mad_send_wr->timeout > 0); 960 961 mad_send_wr->status = IB_WC_SUCCESS; 961 962 ··· 962 995 list_del(&mad_send_wr->agent_list); 963 996 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 964 997 atomic_dec(&mad_agent_priv->refcount); 965 - goto error2; 998 + goto error; 966 999 } 967 - next: 968 - send_wr = next_send_wr; 969 1000 } 970 1001 return 0; 971 - 972 - error2: 973 - *bad_send_wr = send_wr; 974 - error1: 1002 + error: 1003 + if (bad_send_buf) 1004 + *bad_send_buf = send_buf; 975 1005 return ret; 976 1006 } 977 1007 EXPORT_SYMBOL(ib_post_send_mad); ··· 1411 1447 * of MAD. 1412 1448 */ 1413 1449 hi_tid = be64_to_cpu(mad->mad_hdr.tid) >> 32; 1414 - list_for_each_entry(entry, &port_priv->agent_list, 1415 - agent_list) { 1450 + list_for_each_entry(entry, &port_priv->agent_list, agent_list) { 1416 1451 if (entry->agent.hi_tid == hi_tid) { 1417 1452 mad_agent = entry; 1418 1453 break; ··· 1534 1571 */ 1535 1572 list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list, 1536 1573 agent_list) { 1537 - if (is_data_mad(mad_agent_priv, 1538 - mad_send_wr->send_wr.wr.ud.mad_hdr) && 1574 + if (is_data_mad(mad_agent_priv, mad_send_wr->send_buf.mad) && 1539 1575 mad_send_wr->tid == tid && mad_send_wr->timeout) { 1540 1576 /* Verify request has not been canceled */ 1541 1577 return (mad_send_wr->status == IB_WC_SUCCESS) ? ··· 1590 1628 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 1591 1629 1592 1630 /* Defined behavior is to complete response before request */ 1593 - mad_recv_wc->wc->wr_id = mad_send_wr->wr_id; 1631 + mad_recv_wc->wc->wr_id = (unsigned long) &mad_send_wr->send_buf; 1594 1632 mad_agent_priv->agent.recv_handler(&mad_agent_priv->agent, 1595 1633 mad_recv_wc); 1596 1634 atomic_dec(&mad_agent_priv->refcount); 1597 1635 1598 1636 mad_send_wc.status = IB_WC_SUCCESS; 1599 1637 mad_send_wc.vendor_err = 0; 1600 - mad_send_wc.wr_id = mad_send_wr->wr_id; 1638 + mad_send_wc.send_buf = &mad_send_wr->send_buf; 1601 1639 ib_mad_complete_send_wr(mad_send_wr, &mad_send_wc); 1602 1640 } else { 1603 1641 mad_agent_priv->agent.recv_handler(&mad_agent_priv->agent, ··· 1690 1728 if (ret & IB_MAD_RESULT_CONSUMED) 1691 1729 goto out; 1692 1730 if (ret & IB_MAD_RESULT_REPLY) { 1693 - /* Send response */ 1694 - if (!agent_send(response, &recv->grh, wc, 1695 - port_priv->device, 1696 - port_priv->port_num)) 1697 - response = NULL; 1731 + agent_send_response(&response->mad.mad, 1732 + &recv->grh, wc, 1733 + port_priv->device, 1734 + port_priv->port_num, 1735 + qp_info->qp->qp_num); 1698 1736 goto out; 1699 1737 } 1700 1738 } ··· 1828 1866 1829 1867 if (mad_send_wr->status != IB_WC_SUCCESS ) 1830 1868 mad_send_wc->status = mad_send_wr->status; 1831 - if (ret != IB_RMPP_RESULT_INTERNAL) 1869 + if (ret == IB_RMPP_RESULT_INTERNAL) 1870 + ib_rmpp_send_handler(mad_send_wc); 1871 + else 1832 1872 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent, 1833 1873 mad_send_wc); 1834 1874 1835 1875 /* Release reference on agent taken when sending */ 1836 1876 if (atomic_dec_and_test(&mad_agent_priv->refcount)) 1837 1877 wake_up(&mad_agent_priv->wait); 1838 - 1839 - kfree(mad_send_wr); 1840 1878 return; 1841 1879 done: 1842 1880 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); ··· 1850 1888 struct ib_mad_qp_info *qp_info; 1851 1889 struct ib_mad_queue *send_queue; 1852 1890 struct ib_send_wr *bad_send_wr; 1891 + struct ib_mad_send_wc mad_send_wc; 1853 1892 unsigned long flags; 1854 1893 int ret; 1855 1894 ··· 1861 1898 qp_info = send_queue->qp_info; 1862 1899 1863 1900 retry: 1901 + dma_unmap_single(mad_send_wr->send_buf.mad_agent->device->dma_device, 1902 + pci_unmap_addr(mad_send_wr, mapping), 1903 + mad_send_wr->sg_list[0].length, DMA_TO_DEVICE); 1864 1904 queued_send_wr = NULL; 1865 1905 spin_lock_irqsave(&send_queue->lock, flags); 1866 1906 list_del(&mad_list->list); ··· 1880 1914 } 1881 1915 spin_unlock_irqrestore(&send_queue->lock, flags); 1882 1916 1883 - /* Restore client wr_id in WC and complete send */ 1884 - wc->wr_id = mad_send_wr->wr_id; 1917 + mad_send_wc.send_buf = &mad_send_wr->send_buf; 1918 + mad_send_wc.status = wc->status; 1919 + mad_send_wc.vendor_err = wc->vendor_err; 1885 1920 if (atomic_read(&qp_info->snoop_count)) 1886 - snoop_send(qp_info, &mad_send_wr->send_wr, 1887 - (struct ib_mad_send_wc *)wc, 1921 + snoop_send(qp_info, &mad_send_wr->send_buf, &mad_send_wc, 1888 1922 IB_MAD_SNOOP_SEND_COMPLETIONS); 1889 - ib_mad_complete_send_wr(mad_send_wr, (struct ib_mad_send_wc *)wc); 1923 + ib_mad_complete_send_wr(mad_send_wr, &mad_send_wc); 1890 1924 1891 1925 if (queued_send_wr) { 1892 1926 ret = ib_post_send(qp_info->qp, &queued_send_wr->send_wr, 1893 - &bad_send_wr); 1927 + &bad_send_wr); 1894 1928 if (ret) { 1895 1929 printk(KERN_ERR PFX "ib_post_send failed: %d\n", ret); 1896 1930 mad_send_wr = queued_send_wr; ··· 2032 2066 2033 2067 list_for_each_entry_safe(mad_send_wr, temp_mad_send_wr, 2034 2068 &cancel_list, agent_list) { 2035 - mad_send_wc.wr_id = mad_send_wr->wr_id; 2069 + mad_send_wc.send_buf = &mad_send_wr->send_buf; 2070 + list_del(&mad_send_wr->agent_list); 2036 2071 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent, 2037 2072 &mad_send_wc); 2038 - 2039 - list_del(&mad_send_wr->agent_list); 2040 - kfree(mad_send_wr); 2041 2073 atomic_dec(&mad_agent_priv->refcount); 2042 2074 } 2043 2075 } 2044 2076 2045 2077 static struct ib_mad_send_wr_private* 2046 - find_send_by_wr_id(struct ib_mad_agent_private *mad_agent_priv, u64 wr_id) 2078 + find_send_wr(struct ib_mad_agent_private *mad_agent_priv, 2079 + struct ib_mad_send_buf *send_buf) 2047 2080 { 2048 2081 struct ib_mad_send_wr_private *mad_send_wr; 2049 2082 2050 2083 list_for_each_entry(mad_send_wr, &mad_agent_priv->wait_list, 2051 2084 agent_list) { 2052 - if (mad_send_wr->wr_id == wr_id) 2085 + if (&mad_send_wr->send_buf == send_buf) 2053 2086 return mad_send_wr; 2054 2087 } 2055 2088 2056 2089 list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list, 2057 2090 agent_list) { 2058 - if (is_data_mad(mad_agent_priv, 2059 - mad_send_wr->send_wr.wr.ud.mad_hdr) && 2060 - mad_send_wr->wr_id == wr_id) 2091 + if (is_data_mad(mad_agent_priv, mad_send_wr->send_buf.mad) && 2092 + &mad_send_wr->send_buf == send_buf) 2061 2093 return mad_send_wr; 2062 2094 } 2063 2095 return NULL; 2064 2096 } 2065 2097 2066 - int ib_modify_mad(struct ib_mad_agent *mad_agent, u64 wr_id, u32 timeout_ms) 2098 + int ib_modify_mad(struct ib_mad_agent *mad_agent, 2099 + struct ib_mad_send_buf *send_buf, u32 timeout_ms) 2067 2100 { 2068 2101 struct ib_mad_agent_private *mad_agent_priv; 2069 2102 struct ib_mad_send_wr_private *mad_send_wr; ··· 2072 2107 mad_agent_priv = container_of(mad_agent, struct ib_mad_agent_private, 2073 2108 agent); 2074 2109 spin_lock_irqsave(&mad_agent_priv->lock, flags); 2075 - mad_send_wr = find_send_by_wr_id(mad_agent_priv, wr_id); 2110 + mad_send_wr = find_send_wr(mad_agent_priv, send_buf); 2076 2111 if (!mad_send_wr || mad_send_wr->status != IB_WC_SUCCESS) { 2077 2112 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 2078 2113 return -EINVAL; ··· 2084 2119 mad_send_wr->refcount -= (mad_send_wr->timeout > 0); 2085 2120 } 2086 2121 2087 - mad_send_wr->send_wr.wr.ud.timeout_ms = timeout_ms; 2122 + mad_send_wr->send_buf.timeout_ms = timeout_ms; 2088 2123 if (active) 2089 2124 mad_send_wr->timeout = msecs_to_jiffies(timeout_ms); 2090 2125 else ··· 2095 2130 } 2096 2131 EXPORT_SYMBOL(ib_modify_mad); 2097 2132 2098 - void ib_cancel_mad(struct ib_mad_agent *mad_agent, u64 wr_id) 2133 + void ib_cancel_mad(struct ib_mad_agent *mad_agent, 2134 + struct ib_mad_send_buf *send_buf) 2099 2135 { 2100 - ib_modify_mad(mad_agent, wr_id, 0); 2136 + ib_modify_mad(mad_agent, send_buf, 0); 2101 2137 } 2102 2138 EXPORT_SYMBOL(ib_cancel_mad); 2103 2139 ··· 2132 2166 * Defined behavior is to complete response 2133 2167 * before request 2134 2168 */ 2135 - build_smp_wc(local->wr_id, 2169 + build_smp_wc((unsigned long) local->mad_send_wr, 2136 2170 be16_to_cpu(IB_LID_PERMISSIVE), 2137 - 0 /* pkey index */, 2138 - recv_mad_agent->agent.port_num, &wc); 2171 + 0, recv_mad_agent->agent.port_num, &wc); 2139 2172 2140 2173 local->mad_priv->header.recv_wc.wc = &wc; 2141 2174 local->mad_priv->header.recv_wc.mad_len = ··· 2161 2196 /* Complete send */ 2162 2197 mad_send_wc.status = IB_WC_SUCCESS; 2163 2198 mad_send_wc.vendor_err = 0; 2164 - mad_send_wc.wr_id = local->wr_id; 2199 + mad_send_wc.send_buf = &local->mad_send_wr->send_buf; 2165 2200 if (atomic_read(&mad_agent_priv->qp_info->snoop_count)) 2166 - snoop_send(mad_agent_priv->qp_info, &local->send_wr, 2167 - &mad_send_wc, 2168 - IB_MAD_SNOOP_SEND_COMPLETIONS); 2201 + snoop_send(mad_agent_priv->qp_info, 2202 + &local->mad_send_wr->send_buf, 2203 + &mad_send_wc, IB_MAD_SNOOP_SEND_COMPLETIONS); 2169 2204 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent, 2170 2205 &mad_send_wc); 2171 2206 ··· 2186 2221 if (!mad_send_wr->retries--) 2187 2222 return -ETIMEDOUT; 2188 2223 2189 - mad_send_wr->timeout = msecs_to_jiffies(mad_send_wr->send_wr. 2190 - wr.ud.timeout_ms); 2224 + mad_send_wr->timeout = msecs_to_jiffies(mad_send_wr->send_buf.timeout_ms); 2191 2225 2192 2226 if (mad_send_wr->mad_agent_priv->agent.rmpp_version) { 2193 2227 ret = ib_retry_rmpp(mad_send_wr); ··· 2249 2285 mad_send_wc.status = IB_WC_RESP_TIMEOUT_ERR; 2250 2286 else 2251 2287 mad_send_wc.status = mad_send_wr->status; 2252 - mad_send_wc.wr_id = mad_send_wr->wr_id; 2288 + mad_send_wc.send_buf = &mad_send_wr->send_buf; 2253 2289 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent, 2254 2290 &mad_send_wc); 2255 2291 2256 - kfree(mad_send_wr); 2257 2292 atomic_dec(&mad_agent_priv->refcount); 2258 2293 spin_lock_irqsave(&mad_agent_priv->lock, flags); 2259 2294 } ··· 2646 2683 2647 2684 static void ib_mad_init_device(struct ib_device *device) 2648 2685 { 2649 - int num_ports, cur_port, i; 2686 + int start, end, i; 2650 2687 2651 2688 if (device->node_type == IB_NODE_SWITCH) { 2652 - num_ports = 1; 2653 - cur_port = 0; 2689 + start = 0; 2690 + end = 0; 2654 2691 } else { 2655 - num_ports = device->phys_port_cnt; 2656 - cur_port = 1; 2692 + start = 1; 2693 + end = device->phys_port_cnt; 2657 2694 } 2658 - for (i = 0; i < num_ports; i++, cur_port++) { 2659 - if (ib_mad_port_open(device, cur_port)) { 2695 + 2696 + for (i = start; i <= end; i++) { 2697 + if (ib_mad_port_open(device, i)) { 2660 2698 printk(KERN_ERR PFX "Couldn't open %s port %d\n", 2661 - device->name, cur_port); 2662 - goto error_device_open; 2699 + device->name, i); 2700 + goto error; 2663 2701 } 2664 - if (ib_agent_port_open(device, cur_port)) { 2702 + if (ib_agent_port_open(device, i)) { 2665 2703 printk(KERN_ERR PFX "Couldn't open %s port %d " 2666 2704 "for agents\n", 2667 - device->name, cur_port); 2668 - goto error_device_open; 2705 + device->name, i); 2706 + goto error_agent; 2669 2707 } 2670 2708 } 2671 2709 return; 2672 2710 2673 - error_device_open: 2674 - while (i > 0) { 2675 - cur_port--; 2676 - if (ib_agent_port_close(device, cur_port)) 2711 + error_agent: 2712 + if (ib_mad_port_close(device, i)) 2713 + printk(KERN_ERR PFX "Couldn't close %s port %d\n", 2714 + device->name, i); 2715 + 2716 + error: 2717 + i--; 2718 + 2719 + while (i >= start) { 2720 + if (ib_agent_port_close(device, i)) 2677 2721 printk(KERN_ERR PFX "Couldn't close %s port %d " 2678 2722 "for agents\n", 2679 - device->name, cur_port); 2680 - if (ib_mad_port_close(device, cur_port)) 2723 + device->name, i); 2724 + if (ib_mad_port_close(device, i)) 2681 2725 printk(KERN_ERR PFX "Couldn't close %s port %d\n", 2682 - device->name, cur_port); 2726 + device->name, i); 2683 2727 i--; 2684 2728 } 2685 2729 } ··· 2724 2754 int ret; 2725 2755 2726 2756 spin_lock_init(&ib_mad_port_list_lock); 2727 - spin_lock_init(&ib_agent_port_list_lock); 2728 2757 2729 2758 ib_mad_cache = kmem_cache_create("ib_mad", 2730 2759 sizeof(struct ib_mad_private),
+3 -5
drivers/infiniband/core/mad_priv.h
··· 118 118 struct ib_mad_list_head mad_list; 119 119 struct list_head agent_list; 120 120 struct ib_mad_agent_private *mad_agent_priv; 121 + struct ib_mad_send_buf send_buf; 122 + DECLARE_PCI_UNMAP_ADDR(mapping) 121 123 struct ib_send_wr send_wr; 122 124 struct ib_sge sg_list[IB_MAD_SEND_REQ_MAX_SG]; 123 - u64 wr_id; /* client WR ID */ 124 125 __be64 tid; 125 126 unsigned long timeout; 126 127 int retries; ··· 142 141 struct list_head completion_list; 143 142 struct ib_mad_private *mad_priv; 144 143 struct ib_mad_agent_private *recv_mad_agent; 145 - struct ib_send_wr send_wr; 146 - struct ib_sge sg_list[IB_MAD_SEND_REQ_MAX_SG]; 147 - u64 wr_id; /* client WR ID */ 148 - __be64 tid; 144 + struct ib_mad_send_wr_private *mad_send_wr; 149 145 }; 150 146 151 147 struct ib_mad_mgmt_method_table {
+51 -61
drivers/infiniband/core/mad_rmpp.c
··· 103 103 static int data_offset(u8 mgmt_class) 104 104 { 105 105 if (mgmt_class == IB_MGMT_CLASS_SUBN_ADM) 106 - return offsetof(struct ib_sa_mad, data); 106 + return IB_MGMT_SA_HDR; 107 107 else if ((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) && 108 108 (mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END)) 109 - return offsetof(struct ib_vendor_mad, data); 109 + return IB_MGMT_VENDOR_HDR; 110 110 else 111 - return offsetof(struct ib_rmpp_mad, data); 111 + return IB_MGMT_RMPP_HDR; 112 112 } 113 113 114 114 static void format_ack(struct ib_rmpp_mad *ack, ··· 135 135 struct ib_mad_recv_wc *recv_wc) 136 136 { 137 137 struct ib_mad_send_buf *msg; 138 - struct ib_send_wr *bad_send_wr; 139 - int hdr_len, ret; 138 + int ret; 140 139 141 - hdr_len = sizeof(struct ib_mad_hdr) + sizeof(struct ib_rmpp_hdr); 142 140 msg = ib_create_send_mad(&rmpp_recv->agent->agent, recv_wc->wc->src_qp, 143 - recv_wc->wc->pkey_index, rmpp_recv->ah, 1, 144 - hdr_len, sizeof(struct ib_rmpp_mad) - hdr_len, 145 - GFP_KERNEL); 141 + recv_wc->wc->pkey_index, 1, IB_MGMT_RMPP_HDR, 142 + IB_MGMT_RMPP_DATA, GFP_KERNEL); 146 143 if (!msg) 147 144 return; 148 145 149 - format_ack((struct ib_rmpp_mad *) msg->mad, 150 - (struct ib_rmpp_mad *) recv_wc->recv_buf.mad, rmpp_recv); 151 - ret = ib_post_send_mad(&rmpp_recv->agent->agent, &msg->send_wr, 152 - &bad_send_wr); 146 + format_ack(msg->mad, (struct ib_rmpp_mad *) recv_wc->recv_buf.mad, 147 + rmpp_recv); 148 + msg->ah = rmpp_recv->ah; 149 + ret = ib_post_send_mad(msg, NULL); 153 150 if (ret) 154 151 ib_free_send_mad(msg); 155 152 } 156 153 157 - static int alloc_response_msg(struct ib_mad_agent *agent, 158 - struct ib_mad_recv_wc *recv_wc, 159 - struct ib_mad_send_buf **msg) 154 + static struct ib_mad_send_buf *alloc_response_msg(struct ib_mad_agent *agent, 155 + struct ib_mad_recv_wc *recv_wc) 160 156 { 161 - struct ib_mad_send_buf *m; 157 + struct ib_mad_send_buf *msg; 162 158 struct ib_ah *ah; 163 - int hdr_len; 164 159 165 160 ah = ib_create_ah_from_wc(agent->qp->pd, recv_wc->wc, 166 161 recv_wc->recv_buf.grh, agent->port_num); 167 162 if (IS_ERR(ah)) 168 - return PTR_ERR(ah); 163 + return (void *) ah; 169 164 170 - hdr_len = sizeof(struct ib_mad_hdr) + sizeof(struct ib_rmpp_hdr); 171 - m = ib_create_send_mad(agent, recv_wc->wc->src_qp, 172 - recv_wc->wc->pkey_index, ah, 1, hdr_len, 173 - sizeof(struct ib_rmpp_mad) - hdr_len, 174 - GFP_KERNEL); 175 - if (IS_ERR(m)) { 165 + msg = ib_create_send_mad(agent, recv_wc->wc->src_qp, 166 + recv_wc->wc->pkey_index, 1, 167 + IB_MGMT_RMPP_HDR, IB_MGMT_RMPP_DATA, 168 + GFP_KERNEL); 169 + if (IS_ERR(msg)) 176 170 ib_destroy_ah(ah); 177 - return PTR_ERR(m); 178 - } 179 - *msg = m; 180 - return 0; 171 + else 172 + msg->ah = ah; 173 + 174 + return msg; 181 175 } 182 176 183 - static void free_msg(struct ib_mad_send_buf *msg) 177 + void ib_rmpp_send_handler(struct ib_mad_send_wc *mad_send_wc) 184 178 { 185 - ib_destroy_ah(msg->send_wr.wr.ud.ah); 186 - ib_free_send_mad(msg); 179 + struct ib_rmpp_mad *rmpp_mad = mad_send_wc->send_buf->mad; 180 + 181 + if (rmpp_mad->rmpp_hdr.rmpp_type != IB_MGMT_RMPP_TYPE_ACK) 182 + ib_destroy_ah(mad_send_wc->send_buf->ah); 183 + ib_free_send_mad(mad_send_wc->send_buf); 187 184 } 188 185 189 186 static void nack_recv(struct ib_mad_agent_private *agent, ··· 188 191 { 189 192 struct ib_mad_send_buf *msg; 190 193 struct ib_rmpp_mad *rmpp_mad; 191 - struct ib_send_wr *bad_send_wr; 192 194 int ret; 193 195 194 - ret = alloc_response_msg(&agent->agent, recv_wc, &msg); 195 - if (ret) 196 + msg = alloc_response_msg(&agent->agent, recv_wc); 197 + if (IS_ERR(msg)) 196 198 return; 197 199 198 - rmpp_mad = (struct ib_rmpp_mad *) msg->mad; 200 + rmpp_mad = msg->mad; 199 201 memcpy(rmpp_mad, recv_wc->recv_buf.mad, 200 202 data_offset(recv_wc->recv_buf.mad->mad_hdr.mgmt_class)); 201 203 ··· 206 210 rmpp_mad->rmpp_hdr.seg_num = 0; 207 211 rmpp_mad->rmpp_hdr.paylen_newwin = 0; 208 212 209 - ret = ib_post_send_mad(&agent->agent, &msg->send_wr, &bad_send_wr); 210 - if (ret) 211 - free_msg(msg); 213 + ret = ib_post_send_mad(msg, NULL); 214 + if (ret) { 215 + ib_destroy_ah(msg->ah); 216 + ib_free_send_mad(msg); 217 + } 212 218 } 213 219 214 220 static void recv_timeout_handler(void *data) ··· 583 585 int timeout; 584 586 u32 paylen; 585 587 586 - rmpp_mad = (struct ib_rmpp_mad *)mad_send_wr->send_wr.wr.ud.mad_hdr; 588 + rmpp_mad = mad_send_wr->send_buf.mad; 587 589 ib_set_rmpp_flags(&rmpp_mad->rmpp_hdr, IB_MGMT_RMPP_FLAG_ACTIVE); 588 590 rmpp_mad->rmpp_hdr.seg_num = cpu_to_be32(mad_send_wr->seg_num); 589 591 ··· 610 612 } 611 613 612 614 /* 2 seconds for an ACK until we can find the packet lifetime */ 613 - timeout = mad_send_wr->send_wr.wr.ud.timeout_ms; 615 + timeout = mad_send_wr->send_buf.timeout_ms; 614 616 if (!timeout || timeout > 2000) 615 617 mad_send_wr->timeout = msecs_to_jiffies(2000); 616 618 mad_send_wr->seg_num++; ··· 638 640 639 641 wc.status = IB_WC_REM_ABORT_ERR; 640 642 wc.vendor_err = rmpp_status; 641 - wc.wr_id = mad_send_wr->wr_id; 643 + wc.send_buf = &mad_send_wr->send_buf; 642 644 ib_mad_complete_send_wr(mad_send_wr, &wc); 643 645 return; 644 646 out: ··· 692 694 693 695 if (seg_num > mad_send_wr->last_ack) { 694 696 mad_send_wr->last_ack = seg_num; 695 - mad_send_wr->retries = mad_send_wr->send_wr.wr.ud.retries; 697 + mad_send_wr->retries = mad_send_wr->send_buf.retries; 696 698 } 697 699 mad_send_wr->newwin = newwin; 698 700 if (mad_send_wr->last_ack == mad_send_wr->total_seg) { 699 701 /* If no response is expected, the ACK completes the send */ 700 - if (!mad_send_wr->send_wr.wr.ud.timeout_ms) { 702 + if (!mad_send_wr->send_buf.timeout_ms) { 701 703 struct ib_mad_send_wc wc; 702 704 703 705 ib_mark_mad_done(mad_send_wr); ··· 705 707 706 708 wc.status = IB_WC_SUCCESS; 707 709 wc.vendor_err = 0; 708 - wc.wr_id = mad_send_wr->wr_id; 710 + wc.send_buf = &mad_send_wr->send_buf; 709 711 ib_mad_complete_send_wr(mad_send_wr, &wc); 710 712 return; 711 713 } 712 714 if (mad_send_wr->refcount == 1) 713 - ib_reset_mad_timeout(mad_send_wr, mad_send_wr-> 714 - send_wr.wr.ud.timeout_ms); 715 + ib_reset_mad_timeout(mad_send_wr, 716 + mad_send_wr->send_buf.timeout_ms); 715 717 } else if (mad_send_wr->refcount == 1 && 716 718 mad_send_wr->seg_num < mad_send_wr->newwin && 717 719 mad_send_wr->seg_num <= mad_send_wr->total_seg) { ··· 840 842 struct ib_rmpp_mad *rmpp_mad; 841 843 int i, total_len, ret; 842 844 843 - rmpp_mad = (struct ib_rmpp_mad *)mad_send_wr->send_wr.wr.ud.mad_hdr; 845 + rmpp_mad = mad_send_wr->send_buf.mad; 844 846 if (!(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) & 845 847 IB_MGMT_RMPP_FLAG_ACTIVE)) 846 848 return IB_RMPP_RESULT_UNHANDLED; ··· 861 863 862 864 mad_send_wr->total_seg = (total_len - mad_send_wr->data_offset) / 863 865 (sizeof(struct ib_rmpp_mad) - mad_send_wr->data_offset); 864 - mad_send_wr->pad = total_len - offsetof(struct ib_rmpp_mad, data) - 866 + mad_send_wr->pad = total_len - IB_MGMT_RMPP_HDR - 865 867 be32_to_cpu(rmpp_mad->rmpp_hdr.paylen_newwin); 866 868 867 869 /* We need to wait for the final ACK even if there isn't a response */ ··· 876 878 struct ib_mad_send_wc *mad_send_wc) 877 879 { 878 880 struct ib_rmpp_mad *rmpp_mad; 879 - struct ib_mad_send_buf *msg; 880 881 int ret; 881 882 882 - rmpp_mad = (struct ib_rmpp_mad *)mad_send_wr->send_wr.wr.ud.mad_hdr; 883 + rmpp_mad = mad_send_wr->send_buf.mad; 883 884 if (!(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) & 884 885 IB_MGMT_RMPP_FLAG_ACTIVE)) 885 886 return IB_RMPP_RESULT_UNHANDLED; /* RMPP not active */ 886 887 887 - if (rmpp_mad->rmpp_hdr.rmpp_type != IB_MGMT_RMPP_TYPE_DATA) { 888 - msg = (struct ib_mad_send_buf *) (unsigned long) 889 - mad_send_wc->wr_id; 890 - if (rmpp_mad->rmpp_hdr.rmpp_type == IB_MGMT_RMPP_TYPE_ACK) 891 - ib_free_send_mad(msg); 892 - else 893 - free_msg(msg); 888 + if (rmpp_mad->rmpp_hdr.rmpp_type != IB_MGMT_RMPP_TYPE_DATA) 894 889 return IB_RMPP_RESULT_INTERNAL; /* ACK, STOP, or ABORT */ 895 - } 896 890 897 891 if (mad_send_wc->status != IB_WC_SUCCESS || 898 892 mad_send_wr->status != IB_WC_SUCCESS) ··· 895 905 896 906 if (mad_send_wr->last_ack == mad_send_wr->total_seg) { 897 907 mad_send_wr->timeout = 898 - msecs_to_jiffies(mad_send_wr->send_wr.wr.ud.timeout_ms); 908 + msecs_to_jiffies(mad_send_wr->send_buf.timeout_ms); 899 909 return IB_RMPP_RESULT_PROCESSED; /* Send done */ 900 910 } 901 911 ··· 916 926 struct ib_rmpp_mad *rmpp_mad; 917 927 int ret; 918 928 919 - rmpp_mad = (struct ib_rmpp_mad *)mad_send_wr->send_wr.wr.ud.mad_hdr; 929 + rmpp_mad = mad_send_wr->send_buf.mad; 920 930 if (!(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) & 921 931 IB_MGMT_RMPP_FLAG_ACTIVE)) 922 932 return IB_RMPP_RESULT_UNHANDLED; /* RMPP not active */
+2
drivers/infiniband/core/mad_rmpp.h
··· 51 51 int ib_process_rmpp_send_wc(struct ib_mad_send_wr_private *mad_send_wr, 52 52 struct ib_mad_send_wc *mad_send_wc); 53 53 54 + void ib_rmpp_send_handler(struct ib_mad_send_wc *mad_send_wc); 55 + 54 56 void ib_cancel_rmpp_recvs(struct ib_mad_agent_private *agent); 55 57 56 58 int ib_retry_rmpp(struct ib_mad_send_wr_private *mad_send_wr);
+139 -131
drivers/infiniband/core/sa_query.c
··· 73 73 struct ib_sa_query { 74 74 void (*callback)(struct ib_sa_query *, int, struct ib_sa_mad *); 75 75 void (*release)(struct ib_sa_query *); 76 - struct ib_sa_port *port; 77 - struct ib_sa_mad *mad; 78 - struct ib_sa_sm_ah *sm_ah; 79 - DECLARE_PCI_UNMAP_ADDR(mapping) 80 - int id; 76 + struct ib_sa_port *port; 77 + struct ib_mad_send_buf *mad_buf; 78 + struct ib_sa_sm_ah *sm_ah; 79 + int id; 81 80 }; 82 81 83 82 struct ib_sa_service_query { ··· 425 426 { 426 427 unsigned long flags; 427 428 struct ib_mad_agent *agent; 429 + struct ib_mad_send_buf *mad_buf; 428 430 429 431 spin_lock_irqsave(&idr_lock, flags); 430 432 if (idr_find(&query_idr, id) != query) { ··· 433 433 return; 434 434 } 435 435 agent = query->port->agent; 436 + mad_buf = query->mad_buf; 436 437 spin_unlock_irqrestore(&idr_lock, flags); 437 438 438 - ib_cancel_mad(agent, id); 439 + ib_cancel_mad(agent, mad_buf); 439 440 } 440 441 EXPORT_SYMBOL(ib_sa_cancel_query); 441 442 ··· 458 457 459 458 static int send_mad(struct ib_sa_query *query, int timeout_ms) 460 459 { 461 - struct ib_sa_port *port = query->port; 462 460 unsigned long flags; 463 - int ret; 464 - struct ib_sge gather_list; 465 - struct ib_send_wr *bad_wr, wr = { 466 - .opcode = IB_WR_SEND, 467 - .sg_list = &gather_list, 468 - .num_sge = 1, 469 - .send_flags = IB_SEND_SIGNALED, 470 - .wr = { 471 - .ud = { 472 - .mad_hdr = &query->mad->mad_hdr, 473 - .remote_qpn = 1, 474 - .remote_qkey = IB_QP1_QKEY, 475 - .timeout_ms = timeout_ms, 476 - } 477 - } 478 - }; 461 + int ret, id; 479 462 480 463 retry: 481 464 if (!idr_pre_get(&query_idr, GFP_ATOMIC)) 482 465 return -ENOMEM; 483 466 spin_lock_irqsave(&idr_lock, flags); 484 - ret = idr_get_new(&query_idr, query, &query->id); 467 + ret = idr_get_new(&query_idr, query, &id); 485 468 spin_unlock_irqrestore(&idr_lock, flags); 486 469 if (ret == -EAGAIN) 487 470 goto retry; 488 471 if (ret) 489 472 return ret; 490 473 491 - wr.wr_id = query->id; 474 + query->mad_buf->timeout_ms = timeout_ms; 475 + query->mad_buf->context[0] = query; 476 + query->id = id; 492 477 493 - spin_lock_irqsave(&port->ah_lock, flags); 494 - kref_get(&port->sm_ah->ref); 495 - query->sm_ah = port->sm_ah; 496 - wr.wr.ud.ah = port->sm_ah->ah; 497 - spin_unlock_irqrestore(&port->ah_lock, flags); 478 + spin_lock_irqsave(&query->port->ah_lock, flags); 479 + kref_get(&query->port->sm_ah->ref); 480 + query->sm_ah = query->port->sm_ah; 481 + spin_unlock_irqrestore(&query->port->ah_lock, flags); 498 482 499 - gather_list.addr = dma_map_single(port->agent->device->dma_device, 500 - query->mad, 501 - sizeof (struct ib_sa_mad), 502 - DMA_TO_DEVICE); 503 - gather_list.length = sizeof (struct ib_sa_mad); 504 - gather_list.lkey = port->agent->mr->lkey; 505 - pci_unmap_addr_set(query, mapping, gather_list.addr); 483 + query->mad_buf->ah = query->sm_ah->ah; 506 484 507 - ret = ib_post_send_mad(port->agent, &wr, &bad_wr); 485 + ret = ib_post_send_mad(query->mad_buf, NULL); 508 486 if (ret) { 509 - dma_unmap_single(port->agent->device->dma_device, 510 - pci_unmap_addr(query, mapping), 511 - sizeof (struct ib_sa_mad), 512 - DMA_TO_DEVICE); 513 - kref_put(&query->sm_ah->ref, free_sm_ah); 514 487 spin_lock_irqsave(&idr_lock, flags); 515 - idr_remove(&query_idr, query->id); 488 + idr_remove(&query_idr, id); 516 489 spin_unlock_irqrestore(&idr_lock, flags); 490 + 491 + kref_put(&query->sm_ah->ref, free_sm_ah); 517 492 } 518 493 519 494 /* 520 495 * It's not safe to dereference query any more, because the 521 496 * send may already have completed and freed the query in 522 - * another context. So use wr.wr_id, which has a copy of the 523 - * query's id. 497 + * another context. 524 498 */ 525 - return ret ? ret : wr.wr_id; 499 + return ret ? ret : id; 526 500 } 527 501 528 502 static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query, ··· 519 543 520 544 static void ib_sa_path_rec_release(struct ib_sa_query *sa_query) 521 545 { 522 - kfree(sa_query->mad); 523 546 kfree(container_of(sa_query, struct ib_sa_path_query, sa_query)); 524 547 } 525 548 ··· 558 583 { 559 584 struct ib_sa_path_query *query; 560 585 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client); 561 - struct ib_sa_port *port = &sa_dev->port[port_num - sa_dev->start_port]; 562 - struct ib_mad_agent *agent = port->agent; 586 + struct ib_sa_port *port; 587 + struct ib_mad_agent *agent; 588 + struct ib_sa_mad *mad; 563 589 int ret; 590 + 591 + if (!sa_dev) 592 + return -ENODEV; 593 + 594 + port = &sa_dev->port[port_num - sa_dev->start_port]; 595 + agent = port->agent; 564 596 565 597 query = kmalloc(sizeof *query, gfp_mask); 566 598 if (!query) 567 599 return -ENOMEM; 568 - query->sa_query.mad = kmalloc(sizeof *query->sa_query.mad, gfp_mask); 569 - if (!query->sa_query.mad) { 570 - kfree(query); 571 - return -ENOMEM; 600 + 601 + query->sa_query.mad_buf = ib_create_send_mad(agent, 1, 0, 602 + 0, IB_MGMT_SA_HDR, 603 + IB_MGMT_SA_DATA, gfp_mask); 604 + if (!query->sa_query.mad_buf) { 605 + ret = -ENOMEM; 606 + goto err1; 572 607 } 573 608 574 609 query->callback = callback; 575 610 query->context = context; 576 611 577 - init_mad(query->sa_query.mad, agent); 612 + mad = query->sa_query.mad_buf->mad; 613 + init_mad(mad, agent); 578 614 579 - query->sa_query.callback = callback ? ib_sa_path_rec_callback : NULL; 580 - query->sa_query.release = ib_sa_path_rec_release; 581 - query->sa_query.port = port; 582 - query->sa_query.mad->mad_hdr.method = IB_MGMT_METHOD_GET; 583 - query->sa_query.mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_PATH_REC); 584 - query->sa_query.mad->sa_hdr.comp_mask = comp_mask; 615 + query->sa_query.callback = callback ? ib_sa_path_rec_callback : NULL; 616 + query->sa_query.release = ib_sa_path_rec_release; 617 + query->sa_query.port = port; 618 + mad->mad_hdr.method = IB_MGMT_METHOD_GET; 619 + mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_PATH_REC); 620 + mad->sa_hdr.comp_mask = comp_mask; 585 621 586 - ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table), 587 - rec, query->sa_query.mad->data); 622 + ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table), rec, mad->data); 588 623 589 624 *sa_query = &query->sa_query; 590 625 591 626 ret = send_mad(&query->sa_query, timeout_ms); 592 - if (ret < 0) { 593 - *sa_query = NULL; 594 - kfree(query->sa_query.mad); 595 - kfree(query); 596 - } 627 + if (ret < 0) 628 + goto err2; 597 629 630 + return ret; 631 + 632 + err2: 633 + *sa_query = NULL; 634 + ib_free_send_mad(query->sa_query.mad_buf); 635 + 636 + err1: 637 + kfree(query); 598 638 return ret; 599 639 } 600 640 EXPORT_SYMBOL(ib_sa_path_rec_get); ··· 633 643 634 644 static void ib_sa_service_rec_release(struct ib_sa_query *sa_query) 635 645 { 636 - kfree(sa_query->mad); 637 646 kfree(container_of(sa_query, struct ib_sa_service_query, sa_query)); 638 647 } 639 648 ··· 674 685 { 675 686 struct ib_sa_service_query *query; 676 687 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client); 677 - struct ib_sa_port *port = &sa_dev->port[port_num - sa_dev->start_port]; 678 - struct ib_mad_agent *agent = port->agent; 688 + struct ib_sa_port *port; 689 + struct ib_mad_agent *agent; 690 + struct ib_sa_mad *mad; 679 691 int ret; 692 + 693 + if (!sa_dev) 694 + return -ENODEV; 695 + 696 + port = &sa_dev->port[port_num - sa_dev->start_port]; 697 + agent = port->agent; 680 698 681 699 if (method != IB_MGMT_METHOD_GET && 682 700 method != IB_MGMT_METHOD_SET && ··· 693 697 query = kmalloc(sizeof *query, gfp_mask); 694 698 if (!query) 695 699 return -ENOMEM; 696 - query->sa_query.mad = kmalloc(sizeof *query->sa_query.mad, gfp_mask); 697 - if (!query->sa_query.mad) { 698 - kfree(query); 699 - return -ENOMEM; 700 + 701 + query->sa_query.mad_buf = ib_create_send_mad(agent, 1, 0, 702 + 0, IB_MGMT_SA_HDR, 703 + IB_MGMT_SA_DATA, gfp_mask); 704 + if (!query->sa_query.mad_buf) { 705 + ret = -ENOMEM; 706 + goto err1; 700 707 } 701 708 702 709 query->callback = callback; 703 710 query->context = context; 704 711 705 - init_mad(query->sa_query.mad, agent); 712 + mad = query->sa_query.mad_buf->mad; 713 + init_mad(mad, agent); 706 714 707 - query->sa_query.callback = callback ? ib_sa_service_rec_callback : NULL; 708 - query->sa_query.release = ib_sa_service_rec_release; 709 - query->sa_query.port = port; 710 - query->sa_query.mad->mad_hdr.method = method; 711 - query->sa_query.mad->mad_hdr.attr_id = 712 - cpu_to_be16(IB_SA_ATTR_SERVICE_REC); 713 - query->sa_query.mad->sa_hdr.comp_mask = comp_mask; 715 + query->sa_query.callback = callback ? ib_sa_service_rec_callback : NULL; 716 + query->sa_query.release = ib_sa_service_rec_release; 717 + query->sa_query.port = port; 718 + mad->mad_hdr.method = method; 719 + mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_SERVICE_REC); 720 + mad->sa_hdr.comp_mask = comp_mask; 714 721 715 722 ib_pack(service_rec_table, ARRAY_SIZE(service_rec_table), 716 - rec, query->sa_query.mad->data); 723 + rec, mad->data); 717 724 718 725 *sa_query = &query->sa_query; 719 726 720 727 ret = send_mad(&query->sa_query, timeout_ms); 721 - if (ret < 0) { 722 - *sa_query = NULL; 723 - kfree(query->sa_query.mad); 724 - kfree(query); 725 - } 728 + if (ret < 0) 729 + goto err2; 726 730 731 + return ret; 732 + 733 + err2: 734 + *sa_query = NULL; 735 + ib_free_send_mad(query->sa_query.mad_buf); 736 + 737 + err1: 738 + kfree(query); 727 739 return ret; 728 740 } 729 741 EXPORT_SYMBOL(ib_sa_service_rec_query); ··· 755 751 756 752 static void ib_sa_mcmember_rec_release(struct ib_sa_query *sa_query) 757 753 { 758 - kfree(sa_query->mad); 759 754 kfree(container_of(sa_query, struct ib_sa_mcmember_query, sa_query)); 760 755 } 761 756 ··· 771 768 { 772 769 struct ib_sa_mcmember_query *query; 773 770 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client); 774 - struct ib_sa_port *port = &sa_dev->port[port_num - sa_dev->start_port]; 775 - struct ib_mad_agent *agent = port->agent; 771 + struct ib_sa_port *port; 772 + struct ib_mad_agent *agent; 773 + struct ib_sa_mad *mad; 776 774 int ret; 775 + 776 + if (!sa_dev) 777 + return -ENODEV; 778 + 779 + port = &sa_dev->port[port_num - sa_dev->start_port]; 780 + agent = port->agent; 777 781 778 782 query = kmalloc(sizeof *query, gfp_mask); 779 783 if (!query) 780 784 return -ENOMEM; 781 - query->sa_query.mad = kmalloc(sizeof *query->sa_query.mad, gfp_mask); 782 - if (!query->sa_query.mad) { 783 - kfree(query); 784 - return -ENOMEM; 785 + 786 + query->sa_query.mad_buf = ib_create_send_mad(agent, 1, 0, 787 + 0, IB_MGMT_SA_HDR, 788 + IB_MGMT_SA_DATA, gfp_mask); 789 + if (!query->sa_query.mad_buf) { 790 + ret = -ENOMEM; 791 + goto err1; 785 792 } 786 793 787 794 query->callback = callback; 788 795 query->context = context; 789 796 790 - init_mad(query->sa_query.mad, agent); 797 + mad = query->sa_query.mad_buf->mad; 798 + init_mad(mad, agent); 791 799 792 - query->sa_query.callback = callback ? ib_sa_mcmember_rec_callback : NULL; 793 - query->sa_query.release = ib_sa_mcmember_rec_release; 794 - query->sa_query.port = port; 795 - query->sa_query.mad->mad_hdr.method = method; 796 - query->sa_query.mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC); 797 - query->sa_query.mad->sa_hdr.comp_mask = comp_mask; 800 + query->sa_query.callback = callback ? ib_sa_mcmember_rec_callback : NULL; 801 + query->sa_query.release = ib_sa_mcmember_rec_release; 802 + query->sa_query.port = port; 803 + mad->mad_hdr.method = method; 804 + mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC); 805 + mad->sa_hdr.comp_mask = comp_mask; 798 806 799 807 ib_pack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table), 800 - rec, query->sa_query.mad->data); 808 + rec, mad->data); 801 809 802 810 *sa_query = &query->sa_query; 803 811 804 812 ret = send_mad(&query->sa_query, timeout_ms); 805 - if (ret < 0) { 806 - *sa_query = NULL; 807 - kfree(query->sa_query.mad); 808 - kfree(query); 809 - } 813 + if (ret < 0) 814 + goto err2; 810 815 816 + return ret; 817 + 818 + err2: 819 + *sa_query = NULL; 820 + ib_free_send_mad(query->sa_query.mad_buf); 821 + 822 + err1: 823 + kfree(query); 811 824 return ret; 812 825 } 813 826 EXPORT_SYMBOL(ib_sa_mcmember_rec_query); ··· 831 812 static void send_handler(struct ib_mad_agent *agent, 832 813 struct ib_mad_send_wc *mad_send_wc) 833 814 { 834 - struct ib_sa_query *query; 815 + struct ib_sa_query *query = mad_send_wc->send_buf->context[0]; 835 816 unsigned long flags; 836 - 837 - spin_lock_irqsave(&idr_lock, flags); 838 - query = idr_find(&query_idr, mad_send_wc->wr_id); 839 - spin_unlock_irqrestore(&idr_lock, flags); 840 - 841 - if (!query) 842 - return; 843 817 844 818 if (query->callback) 845 819 switch (mad_send_wc->status) { ··· 850 838 break; 851 839 } 852 840 853 - dma_unmap_single(agent->device->dma_device, 854 - pci_unmap_addr(query, mapping), 855 - sizeof (struct ib_sa_mad), 856 - DMA_TO_DEVICE); 857 - kref_put(&query->sm_ah->ref, free_sm_ah); 858 - 859 - query->release(query); 860 - 861 841 spin_lock_irqsave(&idr_lock, flags); 862 - idr_remove(&query_idr, mad_send_wc->wr_id); 842 + idr_remove(&query_idr, query->id); 863 843 spin_unlock_irqrestore(&idr_lock, flags); 844 + 845 + ib_free_send_mad(mad_send_wc->send_buf); 846 + kref_put(&query->sm_ah->ref, free_sm_ah); 847 + query->release(query); 864 848 } 865 849 866 850 static void recv_handler(struct ib_mad_agent *mad_agent, 867 851 struct ib_mad_recv_wc *mad_recv_wc) 868 852 { 869 853 struct ib_sa_query *query; 870 - unsigned long flags; 854 + struct ib_mad_send_buf *mad_buf; 871 855 872 - spin_lock_irqsave(&idr_lock, flags); 873 - query = idr_find(&query_idr, mad_recv_wc->wc->wr_id); 874 - spin_unlock_irqrestore(&idr_lock, flags); 856 + mad_buf = (void *) (unsigned long) mad_recv_wc->wc->wr_id; 857 + query = mad_buf->context[0]; 875 858 876 - if (query && query->callback) { 859 + if (query->callback) { 877 860 if (mad_recv_wc->wc->status == IB_WC_SUCCESS) 878 861 query->callback(query, 879 862 mad_recv_wc->recv_buf.mad->mad_hdr.status ? ··· 982 975 static void __exit ib_sa_cleanup(void) 983 976 { 984 977 ib_unregister_client(&sa_client); 978 + idr_destroy(&query_idr); 985 979 } 986 980 987 981 module_init(ib_sa_init);
+2
drivers/infiniband/core/smi.h
··· 39 39 #ifndef __SMI_H_ 40 40 #define __SMI_H_ 41 41 42 + #include <rdma/ib_smi.h> 43 + 42 44 int smi_handle_dr_smp_recv(struct ib_smp *smp, 43 45 u8 node_type, 44 46 int port_num,
+16
drivers/infiniband/core/sysfs.c
··· 65 65 int index; 66 66 }; 67 67 68 + static inline int ibdev_is_alive(const struct ib_device *dev) 69 + { 70 + return dev->reg_state == IB_DEV_REGISTERED; 71 + } 72 + 68 73 static ssize_t port_attr_show(struct kobject *kobj, 69 74 struct attribute *attr, char *buf) 70 75 { ··· 79 74 80 75 if (!port_attr->show) 81 76 return -EIO; 77 + if (!ibdev_is_alive(p->ibdev)) 78 + return -ENODEV; 82 79 83 80 return port_attr->show(p, port_attr, buf); 84 81 } ··· 588 581 { 589 582 struct ib_device *dev = container_of(cdev, struct ib_device, class_dev); 590 583 584 + if (!ibdev_is_alive(dev)) 585 + return -ENODEV; 586 + 591 587 switch (dev->node_type) { 592 588 case IB_NODE_CA: return sprintf(buf, "%d: CA\n", dev->node_type); 593 589 case IB_NODE_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type); ··· 604 594 struct ib_device *dev = container_of(cdev, struct ib_device, class_dev); 605 595 struct ib_device_attr attr; 606 596 ssize_t ret; 597 + 598 + if (!ibdev_is_alive(dev)) 599 + return -ENODEV; 607 600 608 601 ret = ib_query_device(dev, &attr); 609 602 if (ret) ··· 624 611 struct ib_device *dev = container_of(cdev, struct ib_device, class_dev); 625 612 struct ib_device_attr attr; 626 613 ssize_t ret; 614 + 615 + if (!ibdev_is_alive(dev)) 616 + return -ENODEV; 627 617 628 618 ret = ib_query_device(dev, &attr); 629 619 if (ret)
+200 -69
drivers/infiniband/core/ucm.c
··· 41 41 #include <linux/file.h> 42 42 #include <linux/mount.h> 43 43 #include <linux/cdev.h> 44 + #include <linux/idr.h> 44 45 45 46 #include <asm/uaccess.h> 46 47 47 - #include "ucm.h" 48 + #include <rdma/ib_cm.h> 49 + #include <rdma/ib_user_cm.h> 48 50 49 51 MODULE_AUTHOR("Libor Michalek"); 50 52 MODULE_DESCRIPTION("InfiniBand userspace Connection Manager access"); 51 53 MODULE_LICENSE("Dual BSD/GPL"); 52 54 53 - static int ucm_debug_level; 55 + struct ib_ucm_device { 56 + int devnum; 57 + struct cdev dev; 58 + struct class_device class_dev; 59 + struct ib_device *ib_dev; 60 + }; 54 61 55 - module_param_named(debug_level, ucm_debug_level, int, 0644); 56 - MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0"); 62 + struct ib_ucm_file { 63 + struct semaphore mutex; 64 + struct file *filp; 65 + struct ib_ucm_device *device; 66 + 67 + struct list_head ctxs; 68 + struct list_head events; 69 + wait_queue_head_t poll_wait; 70 + }; 71 + 72 + struct ib_ucm_context { 73 + int id; 74 + wait_queue_head_t wait; 75 + atomic_t ref; 76 + int events_reported; 77 + 78 + struct ib_ucm_file *file; 79 + struct ib_cm_id *cm_id; 80 + __u64 uid; 81 + 82 + struct list_head events; /* list of pending events. */ 83 + struct list_head file_list; /* member in file ctx list */ 84 + }; 85 + 86 + struct ib_ucm_event { 87 + struct ib_ucm_context *ctx; 88 + struct list_head file_list; /* member in file event list */ 89 + struct list_head ctx_list; /* member in ctx event list */ 90 + 91 + struct ib_cm_id *cm_id; 92 + struct ib_ucm_event_resp resp; 93 + void *data; 94 + void *info; 95 + int data_len; 96 + int info_len; 97 + }; 57 98 58 99 enum { 59 100 IB_UCM_MAJOR = 231, 60 - IB_UCM_MINOR = 255 101 + IB_UCM_BASE_MINOR = 224, 102 + IB_UCM_MAX_DEVICES = 32 61 103 }; 62 104 63 - #define IB_UCM_DEV MKDEV(IB_UCM_MAJOR, IB_UCM_MINOR) 105 + #define IB_UCM_BASE_DEV MKDEV(IB_UCM_MAJOR, IB_UCM_BASE_MINOR) 64 106 65 - #define PFX "UCM: " 107 + static void ib_ucm_add_one(struct ib_device *device); 108 + static void ib_ucm_remove_one(struct ib_device *device); 66 109 67 - #define ucm_dbg(format, arg...) \ 68 - do { \ 69 - if (ucm_debug_level > 0) \ 70 - printk(KERN_DEBUG PFX format, ## arg); \ 71 - } while (0) 110 + static struct ib_client ucm_client = { 111 + .name = "ucm", 112 + .add = ib_ucm_add_one, 113 + .remove = ib_ucm_remove_one 114 + }; 72 115 73 - static struct semaphore ctx_id_mutex; 74 - static struct idr ctx_id_table; 116 + static DECLARE_MUTEX(ctx_id_mutex); 117 + static DEFINE_IDR(ctx_id_table); 118 + static DECLARE_BITMAP(dev_map, IB_UCM_MAX_DEVICES); 75 119 76 120 static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id) 77 121 { ··· 196 152 goto error; 197 153 198 154 list_add_tail(&ctx->file_list, &file->ctxs); 199 - ucm_dbg("Allocated CM ID <%d>\n", ctx->id); 200 155 return ctx; 201 156 202 157 error: 203 158 kfree(ctx); 204 159 return NULL; 205 160 } 206 - /* 207 - * Event portion of the API, handle CM events 208 - * and allow event polling. 209 - */ 161 + 210 162 static void ib_ucm_event_path_get(struct ib_ucm_path_rec *upath, 211 163 struct ib_sa_path_rec *kpath) 212 164 { ··· 249 209 ureq->retry_count = kreq->retry_count; 250 210 ureq->rnr_retry_count = kreq->rnr_retry_count; 251 211 ureq->srq = kreq->srq; 212 + ureq->port = kreq->port; 252 213 253 214 ib_ucm_event_path_get(&ureq->primary_path, kreq->primary_path); 254 215 ib_ucm_event_path_get(&ureq->alternate_path, kreq->alternate_path); ··· 336 295 case IB_CM_SIDR_REQ_RECEIVED: 337 296 uvt->resp.u.sidr_req_resp.pkey = 338 297 evt->param.sidr_req_rcvd.pkey; 298 + uvt->resp.u.sidr_req_resp.port = 299 + evt->param.sidr_req_rcvd.port; 339 300 uvt->data_len = IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE; 340 301 break; 341 302 case IB_CM_SIDR_REP_RECEIVED: ··· 430 387 431 388 if (copy_from_user(&cmd, inbuf, sizeof(cmd))) 432 389 return -EFAULT; 433 - /* 434 - * wait 435 - */ 390 + 436 391 down(&file->mutex); 437 392 while (list_empty(&file->events)) { 438 393 ··· 512 471 return result; 513 472 } 514 473 515 - 516 474 static ssize_t ib_ucm_create_id(struct ib_ucm_file *file, 517 475 const char __user *inbuf, 518 476 int in_len, int out_len) ··· 534 494 return -ENOMEM; 535 495 536 496 ctx->uid = cmd.uid; 537 - ctx->cm_id = ib_create_cm_id(ib_ucm_event_handler, ctx); 497 + ctx->cm_id = ib_create_cm_id(file->device->ib_dev, 498 + ib_ucm_event_handler, ctx); 538 499 if (IS_ERR(ctx->cm_id)) { 539 500 result = PTR_ERR(ctx->cm_id); 540 - goto err; 501 + goto err1; 541 502 } 542 503 543 504 resp.id = ctx->id; 544 505 if (copy_to_user((void __user *)(unsigned long)cmd.response, 545 506 &resp, sizeof(resp))) { 546 507 result = -EFAULT; 547 - goto err; 508 + goto err2; 548 509 } 549 - 550 510 return 0; 551 511 552 - err: 512 + err2: 513 + ib_destroy_cm_id(ctx->cm_id); 514 + err1: 553 515 down(&ctx_id_mutex); 554 516 idr_remove(&ctx_id_table, ctx->id); 555 517 up(&ctx_id_mutex); 556 - 557 - if (!IS_ERR(ctx->cm_id)) 558 - ib_destroy_cm_id(ctx->cm_id); 559 - 560 518 kfree(ctx); 561 519 return result; 562 520 } ··· 1222 1184 if (copy_from_user(&hdr, buf, sizeof(hdr))) 1223 1185 return -EFAULT; 1224 1186 1225 - ucm_dbg("Write. cmd <%d> in <%d> out <%d> len <%Zu>\n", 1226 - hdr.cmd, hdr.in, hdr.out, len); 1227 - 1228 1187 if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucm_cmd_table)) 1229 1188 return -EINVAL; 1230 1189 ··· 1266 1231 1267 1232 filp->private_data = file; 1268 1233 file->filp = filp; 1269 - 1270 - ucm_dbg("Created struct\n"); 1234 + file->device = container_of(inode->i_cdev, struct ib_ucm_device, dev); 1271 1235 1272 1236 return 0; 1273 1237 } ··· 1297 1263 return 0; 1298 1264 } 1299 1265 1300 - static struct file_operations ib_ucm_fops = { 1266 + static void ib_ucm_release_class_dev(struct class_device *class_dev) 1267 + { 1268 + struct ib_ucm_device *dev; 1269 + 1270 + dev = container_of(class_dev, struct ib_ucm_device, class_dev); 1271 + cdev_del(&dev->dev); 1272 + clear_bit(dev->devnum, dev_map); 1273 + kfree(dev); 1274 + } 1275 + 1276 + static struct file_operations ucm_fops = { 1301 1277 .owner = THIS_MODULE, 1302 1278 .open = ib_ucm_open, 1303 1279 .release = ib_ucm_close, ··· 1315 1271 .poll = ib_ucm_poll, 1316 1272 }; 1317 1273 1274 + static struct class ucm_class = { 1275 + .name = "infiniband_cm", 1276 + .release = ib_ucm_release_class_dev 1277 + }; 1318 1278 1319 - static struct class *ib_ucm_class; 1320 - static struct cdev ib_ucm_cdev; 1279 + static ssize_t show_dev(struct class_device *class_dev, char *buf) 1280 + { 1281 + struct ib_ucm_device *dev; 1282 + 1283 + dev = container_of(class_dev, struct ib_ucm_device, class_dev); 1284 + return print_dev_t(buf, dev->dev.dev); 1285 + } 1286 + static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL); 1287 + 1288 + static ssize_t show_ibdev(struct class_device *class_dev, char *buf) 1289 + { 1290 + struct ib_ucm_device *dev; 1291 + 1292 + dev = container_of(class_dev, struct ib_ucm_device, class_dev); 1293 + return sprintf(buf, "%s\n", dev->ib_dev->name); 1294 + } 1295 + static CLASS_DEVICE_ATTR(ibdev, S_IRUGO, show_ibdev, NULL); 1296 + 1297 + static void ib_ucm_add_one(struct ib_device *device) 1298 + { 1299 + struct ib_ucm_device *ucm_dev; 1300 + 1301 + if (!device->alloc_ucontext) 1302 + return; 1303 + 1304 + ucm_dev = kmalloc(sizeof *ucm_dev, GFP_KERNEL); 1305 + if (!ucm_dev) 1306 + return; 1307 + 1308 + memset(ucm_dev, 0, sizeof *ucm_dev); 1309 + ucm_dev->ib_dev = device; 1310 + 1311 + ucm_dev->devnum = find_first_zero_bit(dev_map, IB_UCM_MAX_DEVICES); 1312 + if (ucm_dev->devnum >= IB_UCM_MAX_DEVICES) 1313 + goto err; 1314 + 1315 + set_bit(ucm_dev->devnum, dev_map); 1316 + 1317 + cdev_init(&ucm_dev->dev, &ucm_fops); 1318 + ucm_dev->dev.owner = THIS_MODULE; 1319 + kobject_set_name(&ucm_dev->dev.kobj, "ucm%d", ucm_dev->devnum); 1320 + if (cdev_add(&ucm_dev->dev, IB_UCM_BASE_DEV + ucm_dev->devnum, 1)) 1321 + goto err; 1322 + 1323 + ucm_dev->class_dev.class = &ucm_class; 1324 + ucm_dev->class_dev.dev = device->dma_device; 1325 + snprintf(ucm_dev->class_dev.class_id, BUS_ID_SIZE, "ucm%d", 1326 + ucm_dev->devnum); 1327 + if (class_device_register(&ucm_dev->class_dev)) 1328 + goto err_cdev; 1329 + 1330 + if (class_device_create_file(&ucm_dev->class_dev, 1331 + &class_device_attr_dev)) 1332 + goto err_class; 1333 + if (class_device_create_file(&ucm_dev->class_dev, 1334 + &class_device_attr_ibdev)) 1335 + goto err_class; 1336 + 1337 + ib_set_client_data(device, &ucm_client, ucm_dev); 1338 + return; 1339 + 1340 + err_class: 1341 + class_device_unregister(&ucm_dev->class_dev); 1342 + err_cdev: 1343 + cdev_del(&ucm_dev->dev); 1344 + clear_bit(ucm_dev->devnum, dev_map); 1345 + err: 1346 + kfree(ucm_dev); 1347 + return; 1348 + } 1349 + 1350 + static void ib_ucm_remove_one(struct ib_device *device) 1351 + { 1352 + struct ib_ucm_device *ucm_dev = ib_get_client_data(device, &ucm_client); 1353 + 1354 + if (!ucm_dev) 1355 + return; 1356 + 1357 + class_device_unregister(&ucm_dev->class_dev); 1358 + } 1359 + 1360 + static ssize_t show_abi_version(struct class *class, char *buf) 1361 + { 1362 + return sprintf(buf, "%d\n", IB_USER_CM_ABI_VERSION); 1363 + } 1364 + static CLASS_ATTR(abi_version, S_IRUGO, show_abi_version, NULL); 1321 1365 1322 1366 static int __init ib_ucm_init(void) 1323 1367 { 1324 - int result; 1368 + int ret; 1325 1369 1326 - result = register_chrdev_region(IB_UCM_DEV, 1, "infiniband_cm"); 1327 - if (result) { 1328 - ucm_dbg("Error <%d> registering dev\n", result); 1329 - goto err_chr; 1370 + ret = register_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES, 1371 + "infiniband_cm"); 1372 + if (ret) { 1373 + printk(KERN_ERR "ucm: couldn't register device number\n"); 1374 + goto err; 1330 1375 } 1331 1376 1332 - cdev_init(&ib_ucm_cdev, &ib_ucm_fops); 1333 - 1334 - result = cdev_add(&ib_ucm_cdev, IB_UCM_DEV, 1); 1335 - if (result) { 1336 - ucm_dbg("Error <%d> adding cdev\n", result); 1337 - goto err_cdev; 1377 + ret = class_register(&ucm_class); 1378 + if (ret) { 1379 + printk(KERN_ERR "ucm: couldn't create class infiniband_cm\n"); 1380 + goto err_chrdev; 1338 1381 } 1339 1382 1340 - ib_ucm_class = class_create(THIS_MODULE, "infiniband_cm"); 1341 - if (IS_ERR(ib_ucm_class)) { 1342 - result = PTR_ERR(ib_ucm_class); 1343 - ucm_dbg("Error <%d> creating class\n", result); 1383 + ret = class_create_file(&ucm_class, &class_attr_abi_version); 1384 + if (ret) { 1385 + printk(KERN_ERR "ucm: couldn't create abi_version attribute\n"); 1344 1386 goto err_class; 1345 1387 } 1346 1388 1347 - class_device_create(ib_ucm_class, NULL, IB_UCM_DEV, NULL, "ucm"); 1348 - 1349 - idr_init(&ctx_id_table); 1350 - init_MUTEX(&ctx_id_mutex); 1351 - 1389 + ret = ib_register_client(&ucm_client); 1390 + if (ret) { 1391 + printk(KERN_ERR "ucm: couldn't register client\n"); 1392 + goto err_class; 1393 + } 1352 1394 return 0; 1395 + 1353 1396 err_class: 1354 - cdev_del(&ib_ucm_cdev); 1355 - err_cdev: 1356 - unregister_chrdev_region(IB_UCM_DEV, 1); 1357 - err_chr: 1358 - return result; 1397 + class_unregister(&ucm_class); 1398 + err_chrdev: 1399 + unregister_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES); 1400 + err: 1401 + return ret; 1359 1402 } 1360 1403 1361 1404 static void __exit ib_ucm_cleanup(void) 1362 1405 { 1363 - class_device_destroy(ib_ucm_class, IB_UCM_DEV); 1364 - class_destroy(ib_ucm_class); 1365 - cdev_del(&ib_ucm_cdev); 1366 - unregister_chrdev_region(IB_UCM_DEV, 1); 1406 + ib_unregister_client(&ucm_client); 1407 + class_unregister(&ucm_class); 1408 + unregister_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES); 1409 + idr_destroy(&ctx_id_table); 1367 1410 } 1368 1411 1369 1412 module_init(ib_ucm_init);
-83
drivers/infiniband/core/ucm.h
··· 1 - /* 2 - * Copyright (c) 2005 Topspin Communications. All rights reserved. 3 - * Copyright (c) 2005 Intel Corporation. All rights reserved. 4 - * 5 - * This software is available to you under a choice of one of two 6 - * licenses. You may choose to be licensed under the terms of the GNU 7 - * General Public License (GPL) Version 2, available from the file 8 - * COPYING in the main directory of this source tree, or the 9 - * OpenIB.org BSD license below: 10 - * 11 - * Redistribution and use in source and binary forms, with or 12 - * without modification, are permitted provided that the following 13 - * conditions are met: 14 - * 15 - * - Redistributions of source code must retain the above 16 - * copyright notice, this list of conditions and the following 17 - * disclaimer. 18 - * 19 - * - Redistributions in binary form must reproduce the above 20 - * copyright notice, this list of conditions and the following 21 - * disclaimer in the documentation and/or other materials 22 - * provided with the distribution. 23 - * 24 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 28 - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 29 - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 30 - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 - * SOFTWARE. 32 - * 33 - * $Id: ucm.h 2208 2005-04-22 23:24:31Z libor $ 34 - */ 35 - 36 - #ifndef UCM_H 37 - #define UCM_H 38 - 39 - #include <linux/fs.h> 40 - #include <linux/device.h> 41 - #include <linux/cdev.h> 42 - #include <linux/idr.h> 43 - 44 - #include <rdma/ib_cm.h> 45 - #include <rdma/ib_user_cm.h> 46 - 47 - struct ib_ucm_file { 48 - struct semaphore mutex; 49 - struct file *filp; 50 - 51 - struct list_head ctxs; /* list of active connections */ 52 - struct list_head events; /* list of pending events */ 53 - wait_queue_head_t poll_wait; 54 - }; 55 - 56 - struct ib_ucm_context { 57 - int id; 58 - wait_queue_head_t wait; 59 - atomic_t ref; 60 - int events_reported; 61 - 62 - struct ib_ucm_file *file; 63 - struct ib_cm_id *cm_id; 64 - __u64 uid; 65 - 66 - struct list_head events; /* list of pending events. */ 67 - struct list_head file_list; /* member in file ctx list */ 68 - }; 69 - 70 - struct ib_ucm_event { 71 - struct ib_ucm_context *ctx; 72 - struct list_head file_list; /* member in file event list */ 73 - struct list_head ctx_list; /* member in ctx event list */ 74 - 75 - struct ib_cm_id *cm_id; 76 - struct ib_ucm_event_resp resp; 77 - void *data; 78 - void *info; 79 - int data_len; 80 - int info_len; 81 - }; 82 - 83 - #endif /* UCM_H */
+202 -201
drivers/infiniband/core/user_mad.c
··· 64 64 IB_UMAD_MINOR_BASE = 0 65 65 }; 66 66 67 - struct ib_umad_port { 68 - int devnum; 69 - struct cdev dev; 70 - struct class_device class_dev; 67 + /* 68 + * Our lifetime rules for these structs are the following: each time a 69 + * device special file is opened, we look up the corresponding struct 70 + * ib_umad_port by minor in the umad_port[] table while holding the 71 + * port_lock. If this lookup succeeds, we take a reference on the 72 + * ib_umad_port's struct ib_umad_device while still holding the 73 + * port_lock; if the lookup fails, we fail the open(). We drop these 74 + * references in the corresponding close(). 75 + * 76 + * In addition to references coming from open character devices, there 77 + * is one more reference to each ib_umad_device representing the 78 + * module's reference taken when allocating the ib_umad_device in 79 + * ib_umad_add_one(). 80 + * 81 + * When destroying an ib_umad_device, we clear all of its 82 + * ib_umad_ports from umad_port[] while holding port_lock before 83 + * dropping the module's reference to the ib_umad_device. This is 84 + * always safe because any open() calls will either succeed and obtain 85 + * a reference before we clear the umad_port[] entries, or fail after 86 + * we clear the umad_port[] entries. 87 + */ 71 88 72 - int sm_devnum; 73 - struct cdev sm_dev; 74 - struct class_device sm_class_dev; 89 + struct ib_umad_port { 90 + struct cdev *dev; 91 + struct class_device *class_dev; 92 + 93 + struct cdev *sm_dev; 94 + struct class_device *sm_class_dev; 75 95 struct semaphore sm_sem; 76 96 77 97 struct ib_device *ib_dev; 78 98 struct ib_umad_device *umad_dev; 99 + int dev_num; 79 100 u8 port_num; 80 101 }; 81 102 ··· 117 96 }; 118 97 119 98 struct ib_umad_packet { 120 - struct ib_ah *ah; 121 99 struct ib_mad_send_buf *msg; 122 100 struct list_head list; 123 101 int length; 124 - DECLARE_PCI_UNMAP_ADDR(mapping) 125 102 struct ib_user_mad mad; 126 103 }; 127 104 105 + static struct class *umad_class; 106 + 128 107 static const dev_t base_dev = MKDEV(IB_UMAD_MAJOR, IB_UMAD_MINOR_BASE); 129 - static spinlock_t map_lock; 108 + 109 + static DEFINE_SPINLOCK(port_lock); 110 + static struct ib_umad_port *umad_port[IB_UMAD_MAX_PORTS]; 130 111 static DECLARE_BITMAP(dev_map, IB_UMAD_MAX_PORTS * 2); 131 112 132 113 static void ib_umad_add_one(struct ib_device *device); 133 114 static void ib_umad_remove_one(struct ib_device *device); 115 + 116 + static void ib_umad_release_dev(struct kref *ref) 117 + { 118 + struct ib_umad_device *dev = 119 + container_of(ref, struct ib_umad_device, ref); 120 + 121 + kfree(dev); 122 + } 134 123 135 124 static int queue_packet(struct ib_umad_file *file, 136 125 struct ib_mad_agent *agent, ··· 170 139 struct ib_mad_send_wc *send_wc) 171 140 { 172 141 struct ib_umad_file *file = agent->context; 173 - struct ib_umad_packet *timeout, *packet = 174 - (void *) (unsigned long) send_wc->wr_id; 142 + struct ib_umad_packet *timeout; 143 + struct ib_umad_packet *packet = send_wc->send_buf->context[0]; 175 144 176 - ib_destroy_ah(packet->msg->send_wr.wr.ud.ah); 145 + ib_destroy_ah(packet->msg->ah); 177 146 ib_free_send_mad(packet->msg); 178 147 179 148 if (send_wc->status == IB_WC_RESP_TIMEOUT_ERR) { 180 - timeout = kmalloc(sizeof *timeout + sizeof (struct ib_mad_hdr), 181 - GFP_KERNEL); 149 + timeout = kzalloc(sizeof *timeout + IB_MGMT_MAD_HDR, GFP_KERNEL); 182 150 if (!timeout) 183 151 goto out; 184 152 185 - memset(timeout, 0, sizeof *timeout + sizeof (struct ib_mad_hdr)); 186 - 187 - timeout->length = sizeof (struct ib_mad_hdr); 188 - timeout->mad.hdr.id = packet->mad.hdr.id; 153 + timeout->length = IB_MGMT_MAD_HDR; 154 + timeout->mad.hdr.id = packet->mad.hdr.id; 189 155 timeout->mad.hdr.status = ETIMEDOUT; 190 156 memcpy(timeout->mad.data, packet->mad.data, 191 157 sizeof (struct ib_mad_hdr)); ··· 205 177 goto out; 206 178 207 179 length = mad_recv_wc->mad_len; 208 - packet = kmalloc(sizeof *packet + length, GFP_KERNEL); 180 + packet = kzalloc(sizeof *packet + length, GFP_KERNEL); 209 181 if (!packet) 210 182 goto out; 211 183 212 - memset(packet, 0, sizeof *packet + length); 213 184 packet->length = length; 214 185 215 186 ib_coalesce_recv_mad(mad_recv_wc, packet->mad.data); ··· 274 247 else 275 248 ret = -ENOSPC; 276 249 } else if (copy_to_user(buf, &packet->mad, 277 - packet->length + sizeof (struct ib_user_mad))) 250 + packet->length + sizeof (struct ib_user_mad))) 278 251 ret = -EFAULT; 279 252 else 280 253 ret = packet->length + sizeof (struct ib_user_mad); ··· 295 268 struct ib_umad_packet *packet; 296 269 struct ib_mad_agent *agent; 297 270 struct ib_ah_attr ah_attr; 298 - struct ib_send_wr *bad_wr; 271 + struct ib_ah *ah; 299 272 struct ib_rmpp_mad *rmpp_mad; 300 273 u8 method; 301 274 __be64 *tid; 302 - int ret, length, hdr_len, data_len, rmpp_hdr_size; 275 + int ret, length, hdr_len, copy_offset; 303 276 int rmpp_active = 0; 304 277 305 278 if (count < sizeof (struct ib_user_mad)) 306 279 return -EINVAL; 307 280 308 281 length = count - sizeof (struct ib_user_mad); 309 - packet = kmalloc(sizeof *packet + sizeof(struct ib_mad_hdr) + 310 - sizeof(struct ib_rmpp_hdr), GFP_KERNEL); 282 + packet = kmalloc(sizeof *packet + IB_MGMT_RMPP_HDR, GFP_KERNEL); 311 283 if (!packet) 312 284 return -ENOMEM; 313 285 314 286 if (copy_from_user(&packet->mad, buf, 315 - sizeof (struct ib_user_mad) + 316 - sizeof(struct ib_mad_hdr) + 317 - sizeof(struct ib_rmpp_hdr))) { 287 + sizeof (struct ib_user_mad) + IB_MGMT_RMPP_HDR)) { 318 288 ret = -EFAULT; 319 289 goto err; 320 290 } ··· 321 297 ret = -EINVAL; 322 298 goto err; 323 299 } 324 - 325 - packet->length = length; 326 300 327 301 down_read(&file->agent_mutex); 328 302 ··· 343 321 ah_attr.grh.traffic_class = packet->mad.hdr.traffic_class; 344 322 } 345 323 346 - packet->ah = ib_create_ah(agent->qp->pd, &ah_attr); 347 - if (IS_ERR(packet->ah)) { 348 - ret = PTR_ERR(packet->ah); 324 + ah = ib_create_ah(agent->qp->pd, &ah_attr); 325 + if (IS_ERR(ah)) { 326 + ret = PTR_ERR(ah); 349 327 goto err_up; 350 328 } 351 329 ··· 359 337 360 338 /* Validate that the management class can support RMPP */ 361 339 if (rmpp_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_ADM) { 362 - hdr_len = offsetof(struct ib_sa_mad, data); 363 - data_len = length - hdr_len; 340 + hdr_len = IB_MGMT_SA_HDR; 364 341 } else if ((rmpp_mad->mad_hdr.mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) && 365 342 (rmpp_mad->mad_hdr.mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END)) { 366 - hdr_len = offsetof(struct ib_vendor_mad, data); 367 - data_len = length - hdr_len; 343 + hdr_len = IB_MGMT_VENDOR_HDR; 368 344 } else { 369 345 ret = -EINVAL; 370 346 goto err_ah; 371 347 } 372 348 rmpp_active = 1; 349 + copy_offset = IB_MGMT_RMPP_HDR; 373 350 } else { 374 - if (length > sizeof(struct ib_mad)) { 375 - ret = -EINVAL; 376 - goto err_ah; 377 - } 378 - hdr_len = offsetof(struct ib_mad, data); 379 - data_len = length - hdr_len; 351 + hdr_len = IB_MGMT_MAD_HDR; 352 + copy_offset = IB_MGMT_MAD_HDR; 380 353 } 381 354 382 355 packet->msg = ib_create_send_mad(agent, 383 356 be32_to_cpu(packet->mad.hdr.qpn), 384 - 0, packet->ah, rmpp_active, 385 - hdr_len, data_len, 357 + 0, rmpp_active, 358 + hdr_len, length - hdr_len, 386 359 GFP_KERNEL); 387 360 if (IS_ERR(packet->msg)) { 388 361 ret = PTR_ERR(packet->msg); 389 362 goto err_ah; 390 363 } 391 364 392 - packet->msg->send_wr.wr.ud.timeout_ms = packet->mad.hdr.timeout_ms; 393 - packet->msg->send_wr.wr.ud.retries = packet->mad.hdr.retries; 365 + packet->msg->ah = ah; 366 + packet->msg->timeout_ms = packet->mad.hdr.timeout_ms; 367 + packet->msg->retries = packet->mad.hdr.retries; 368 + packet->msg->context[0] = packet; 394 369 395 - /* Override send WR WRID initialized in ib_create_send_mad */ 396 - packet->msg->send_wr.wr_id = (unsigned long) packet; 397 - 398 - if (!rmpp_active) { 399 - /* Copy message from user into send buffer */ 400 - if (copy_from_user(packet->msg->mad, 401 - buf + sizeof(struct ib_user_mad), length)) { 402 - ret = -EFAULT; 403 - goto err_msg; 404 - } 405 - } else { 406 - rmpp_hdr_size = sizeof(struct ib_mad_hdr) + 407 - sizeof(struct ib_rmpp_hdr); 408 - 409 - /* Only copy MAD headers (RMPP header in place) */ 410 - memcpy(packet->msg->mad, packet->mad.data, 411 - sizeof(struct ib_mad_hdr)); 412 - 413 - /* Now, copy rest of message from user into send buffer */ 414 - if (copy_from_user(((struct ib_rmpp_mad *) packet->msg->mad)->data, 415 - buf + sizeof (struct ib_user_mad) + rmpp_hdr_size, 416 - length - rmpp_hdr_size)) { 417 - ret = -EFAULT; 418 - goto err_msg; 419 - } 370 + /* Copy MAD headers (RMPP header in place) */ 371 + memcpy(packet->msg->mad, packet->mad.data, IB_MGMT_MAD_HDR); 372 + /* Now, copy rest of message from user into send buffer */ 373 + if (copy_from_user(packet->msg->mad + copy_offset, 374 + buf + sizeof (struct ib_user_mad) + copy_offset, 375 + length - copy_offset)) { 376 + ret = -EFAULT; 377 + goto err_msg; 420 378 } 421 379 422 380 /* ··· 405 403 * transaction ID matches the agent being used to send the 406 404 * MAD. 407 405 */ 408 - method = packet->msg->mad->mad_hdr.method; 406 + method = ((struct ib_mad_hdr *) packet->msg->mad)->method; 409 407 410 408 if (!(method & IB_MGMT_METHOD_RESP) && 411 409 method != IB_MGMT_METHOD_TRAP_REPRESS && 412 410 method != IB_MGMT_METHOD_SEND) { 413 - tid = &packet->msg->mad->mad_hdr.tid; 411 + tid = &((struct ib_mad_hdr *) packet->msg->mad)->tid; 414 412 *tid = cpu_to_be64(((u64) agent->hi_tid) << 32 | 415 413 (be64_to_cpup(tid) & 0xffffffff)); 416 414 } 417 415 418 - ret = ib_post_send_mad(agent, &packet->msg->send_wr, &bad_wr); 416 + ret = ib_post_send_mad(packet->msg, NULL); 419 417 if (ret) 420 418 goto err_msg; 421 419 422 420 up_read(&file->agent_mutex); 423 421 424 - return sizeof (struct ib_user_mad_hdr) + packet->length; 422 + return count; 425 423 426 424 err_msg: 427 425 ib_free_send_mad(packet->msg); 428 426 429 427 err_ah: 430 - ib_destroy_ah(packet->ah); 428 + ib_destroy_ah(ah); 431 429 432 430 err_up: 433 431 up_read(&file->agent_mutex); ··· 567 565 568 566 static int ib_umad_open(struct inode *inode, struct file *filp) 569 567 { 570 - struct ib_umad_port *port = 571 - container_of(inode->i_cdev, struct ib_umad_port, dev); 568 + struct ib_umad_port *port; 572 569 struct ib_umad_file *file; 573 570 574 - file = kmalloc(sizeof *file, GFP_KERNEL); 575 - if (!file) 576 - return -ENOMEM; 571 + spin_lock(&port_lock); 572 + port = umad_port[iminor(inode) - IB_UMAD_MINOR_BASE]; 573 + if (port) 574 + kref_get(&port->umad_dev->ref); 575 + spin_unlock(&port_lock); 577 576 578 - memset(file, 0, sizeof *file); 577 + if (!port) 578 + return -ENXIO; 579 + 580 + file = kzalloc(sizeof *file, GFP_KERNEL); 581 + if (!file) { 582 + kref_put(&port->umad_dev->ref, ib_umad_release_dev); 583 + return -ENOMEM; 584 + } 579 585 580 586 spin_lock_init(&file->recv_lock); 581 587 init_rwsem(&file->agent_mutex); ··· 599 589 static int ib_umad_close(struct inode *inode, struct file *filp) 600 590 { 601 591 struct ib_umad_file *file = filp->private_data; 592 + struct ib_umad_device *dev = file->port->umad_dev; 602 593 struct ib_umad_packet *packet, *tmp; 603 594 int i; 604 595 ··· 613 602 kfree(packet); 614 603 615 604 kfree(file); 605 + 606 + kref_put(&dev->ref, ib_umad_release_dev); 616 607 617 608 return 0; 618 609 } ··· 632 619 633 620 static int ib_umad_sm_open(struct inode *inode, struct file *filp) 634 621 { 635 - struct ib_umad_port *port = 636 - container_of(inode->i_cdev, struct ib_umad_port, sm_dev); 622 + struct ib_umad_port *port; 637 623 struct ib_port_modify props = { 638 624 .set_port_cap_mask = IB_PORT_SM 639 625 }; 640 626 int ret; 641 627 628 + spin_lock(&port_lock); 629 + port = umad_port[iminor(inode) - IB_UMAD_MINOR_BASE - IB_UMAD_MAX_PORTS]; 630 + if (port) 631 + kref_get(&port->umad_dev->ref); 632 + spin_unlock(&port_lock); 633 + 634 + if (!port) 635 + return -ENXIO; 636 + 642 637 if (filp->f_flags & O_NONBLOCK) { 643 - if (down_trylock(&port->sm_sem)) 644 - return -EAGAIN; 638 + if (down_trylock(&port->sm_sem)) { 639 + ret = -EAGAIN; 640 + goto fail; 641 + } 645 642 } else { 646 - if (down_interruptible(&port->sm_sem)) 647 - return -ERESTARTSYS; 643 + if (down_interruptible(&port->sm_sem)) { 644 + ret = -ERESTARTSYS; 645 + goto fail; 646 + } 648 647 } 649 648 650 649 ret = ib_modify_port(port->ib_dev, port->port_num, 0, &props); 651 650 if (ret) { 652 651 up(&port->sm_sem); 653 - return ret; 652 + goto fail; 654 653 } 655 654 656 655 filp->private_data = port; 657 656 658 657 return 0; 658 + 659 + fail: 660 + kref_put(&port->umad_dev->ref, ib_umad_release_dev); 661 + return ret; 659 662 } 660 663 661 664 static int ib_umad_sm_close(struct inode *inode, struct file *filp) ··· 684 655 685 656 ret = ib_modify_port(port->ib_dev, port->port_num, 0, &props); 686 657 up(&port->sm_sem); 658 + 659 + kref_put(&port->umad_dev->ref, ib_umad_release_dev); 687 660 688 661 return ret; 689 662 } ··· 702 671 .remove = ib_umad_remove_one 703 672 }; 704 673 705 - static ssize_t show_dev(struct class_device *class_dev, char *buf) 706 - { 707 - struct ib_umad_port *port = class_get_devdata(class_dev); 708 - 709 - if (class_dev == &port->class_dev) 710 - return print_dev_t(buf, port->dev.dev); 711 - else 712 - return print_dev_t(buf, port->sm_dev.dev); 713 - } 714 - static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL); 715 - 716 674 static ssize_t show_ibdev(struct class_device *class_dev, char *buf) 717 675 { 718 676 struct ib_umad_port *port = class_get_devdata(class_dev); 677 + 678 + if (!port) 679 + return -ENODEV; 719 680 720 681 return sprintf(buf, "%s\n", port->ib_dev->name); 721 682 } ··· 717 694 { 718 695 struct ib_umad_port *port = class_get_devdata(class_dev); 719 696 697 + if (!port) 698 + return -ENODEV; 699 + 720 700 return sprintf(buf, "%d\n", port->port_num); 721 701 } 722 702 static CLASS_DEVICE_ATTR(port, S_IRUGO, show_port, NULL); 723 - 724 - static void ib_umad_release_dev(struct kref *ref) 725 - { 726 - struct ib_umad_device *dev = 727 - container_of(ref, struct ib_umad_device, ref); 728 - 729 - kfree(dev); 730 - } 731 - 732 - static void ib_umad_release_port(struct class_device *class_dev) 733 - { 734 - struct ib_umad_port *port = class_get_devdata(class_dev); 735 - 736 - if (class_dev == &port->class_dev) { 737 - cdev_del(&port->dev); 738 - clear_bit(port->devnum, dev_map); 739 - } else { 740 - cdev_del(&port->sm_dev); 741 - clear_bit(port->sm_devnum, dev_map); 742 - } 743 - 744 - kref_put(&port->umad_dev->ref, ib_umad_release_dev); 745 - } 746 - 747 - static struct class umad_class = { 748 - .name = "infiniband_mad", 749 - .release = ib_umad_release_port 750 - }; 751 703 752 704 static ssize_t show_abi_version(struct class *class, char *buf) 753 705 { ··· 733 735 static int ib_umad_init_port(struct ib_device *device, int port_num, 734 736 struct ib_umad_port *port) 735 737 { 736 - spin_lock(&map_lock); 737 - port->devnum = find_first_zero_bit(dev_map, IB_UMAD_MAX_PORTS); 738 - if (port->devnum >= IB_UMAD_MAX_PORTS) { 739 - spin_unlock(&map_lock); 738 + spin_lock(&port_lock); 739 + port->dev_num = find_first_zero_bit(dev_map, IB_UMAD_MAX_PORTS); 740 + if (port->dev_num >= IB_UMAD_MAX_PORTS) { 741 + spin_unlock(&port_lock); 740 742 return -1; 741 743 } 742 - port->sm_devnum = find_next_zero_bit(dev_map, IB_UMAD_MAX_PORTS * 2, IB_UMAD_MAX_PORTS); 743 - if (port->sm_devnum >= IB_UMAD_MAX_PORTS * 2) { 744 - spin_unlock(&map_lock); 745 - return -1; 746 - } 747 - set_bit(port->devnum, dev_map); 748 - set_bit(port->sm_devnum, dev_map); 749 - spin_unlock(&map_lock); 744 + set_bit(port->dev_num, dev_map); 745 + spin_unlock(&port_lock); 750 746 751 747 port->ib_dev = device; 752 748 port->port_num = port_num; 753 749 init_MUTEX(&port->sm_sem); 754 750 755 - cdev_init(&port->dev, &umad_fops); 756 - port->dev.owner = THIS_MODULE; 757 - kobject_set_name(&port->dev.kobj, "umad%d", port->devnum); 758 - if (cdev_add(&port->dev, base_dev + port->devnum, 1)) 751 + port->dev = cdev_alloc(); 752 + if (!port->dev) 759 753 return -1; 760 - 761 - port->class_dev.class = &umad_class; 762 - port->class_dev.dev = device->dma_device; 763 - 764 - snprintf(port->class_dev.class_id, BUS_ID_SIZE, "umad%d", port->devnum); 765 - 766 - if (class_device_register(&port->class_dev)) 754 + port->dev->owner = THIS_MODULE; 755 + port->dev->ops = &umad_fops; 756 + kobject_set_name(&port->dev->kobj, "umad%d", port->dev_num); 757 + if (cdev_add(port->dev, base_dev + port->dev_num, 1)) 767 758 goto err_cdev; 768 759 769 - class_set_devdata(&port->class_dev, port); 770 - kref_get(&port->umad_dev->ref); 760 + port->class_dev = class_device_create(umad_class, NULL, port->dev->dev, 761 + device->dma_device, 762 + "umad%d", port->dev_num); 763 + if (IS_ERR(port->class_dev)) 764 + goto err_cdev; 771 765 772 - if (class_device_create_file(&port->class_dev, &class_device_attr_dev)) 766 + if (class_device_create_file(port->class_dev, &class_device_attr_ibdev)) 773 767 goto err_class; 774 - if (class_device_create_file(&port->class_dev, &class_device_attr_ibdev)) 775 - goto err_class; 776 - if (class_device_create_file(&port->class_dev, &class_device_attr_port)) 768 + if (class_device_create_file(port->class_dev, &class_device_attr_port)) 777 769 goto err_class; 778 770 779 - cdev_init(&port->sm_dev, &umad_sm_fops); 780 - port->sm_dev.owner = THIS_MODULE; 781 - kobject_set_name(&port->dev.kobj, "issm%d", port->sm_devnum - IB_UMAD_MAX_PORTS); 782 - if (cdev_add(&port->sm_dev, base_dev + port->sm_devnum, 1)) 783 - return -1; 784 - 785 - port->sm_class_dev.class = &umad_class; 786 - port->sm_class_dev.dev = device->dma_device; 787 - 788 - snprintf(port->sm_class_dev.class_id, BUS_ID_SIZE, "issm%d", port->sm_devnum - IB_UMAD_MAX_PORTS); 789 - 790 - if (class_device_register(&port->sm_class_dev)) 771 + port->sm_dev = cdev_alloc(); 772 + if (!port->sm_dev) 773 + goto err_class; 774 + port->sm_dev->owner = THIS_MODULE; 775 + port->sm_dev->ops = &umad_sm_fops; 776 + kobject_set_name(&port->dev->kobj, "issm%d", port->dev_num); 777 + if (cdev_add(port->sm_dev, base_dev + port->dev_num + IB_UMAD_MAX_PORTS, 1)) 791 778 goto err_sm_cdev; 792 779 793 - class_set_devdata(&port->sm_class_dev, port); 794 - kref_get(&port->umad_dev->ref); 780 + port->sm_class_dev = class_device_create(umad_class, NULL, port->sm_dev->dev, 781 + device->dma_device, 782 + "issm%d", port->dev_num); 783 + if (IS_ERR(port->sm_class_dev)) 784 + goto err_sm_cdev; 795 785 796 - if (class_device_create_file(&port->sm_class_dev, &class_device_attr_dev)) 786 + class_set_devdata(port->class_dev, port); 787 + class_set_devdata(port->sm_class_dev, port); 788 + 789 + if (class_device_create_file(port->sm_class_dev, &class_device_attr_ibdev)) 797 790 goto err_sm_class; 798 - if (class_device_create_file(&port->sm_class_dev, &class_device_attr_ibdev)) 791 + if (class_device_create_file(port->sm_class_dev, &class_device_attr_port)) 799 792 goto err_sm_class; 800 - if (class_device_create_file(&port->sm_class_dev, &class_device_attr_port)) 801 - goto err_sm_class; 793 + 794 + spin_lock(&port_lock); 795 + umad_port[port->dev_num] = port; 796 + spin_unlock(&port_lock); 802 797 803 798 return 0; 804 799 805 800 err_sm_class: 806 - class_device_unregister(&port->sm_class_dev); 801 + class_device_destroy(umad_class, port->sm_dev->dev); 807 802 808 803 err_sm_cdev: 809 - cdev_del(&port->sm_dev); 804 + cdev_del(port->sm_dev); 810 805 811 806 err_class: 812 - class_device_unregister(&port->class_dev); 807 + class_device_destroy(umad_class, port->dev->dev); 813 808 814 809 err_cdev: 815 - cdev_del(&port->dev); 816 - clear_bit(port->devnum, dev_map); 810 + cdev_del(port->dev); 811 + clear_bit(port->dev_num, dev_map); 817 812 818 813 return -1; 814 + } 815 + 816 + static void ib_umad_kill_port(struct ib_umad_port *port) 817 + { 818 + class_set_devdata(port->class_dev, NULL); 819 + class_set_devdata(port->sm_class_dev, NULL); 820 + 821 + class_device_destroy(umad_class, port->dev->dev); 822 + class_device_destroy(umad_class, port->sm_dev->dev); 823 + 824 + cdev_del(port->dev); 825 + cdev_del(port->sm_dev); 826 + 827 + spin_lock(&port_lock); 828 + umad_port[port->dev_num] = NULL; 829 + spin_unlock(&port_lock); 830 + 831 + clear_bit(port->dev_num, dev_map); 819 832 } 820 833 821 834 static void ib_umad_add_one(struct ib_device *device) ··· 841 832 e = device->phys_port_cnt; 842 833 } 843 834 844 - umad_dev = kmalloc(sizeof *umad_dev + 835 + umad_dev = kzalloc(sizeof *umad_dev + 845 836 (e - s + 1) * sizeof (struct ib_umad_port), 846 837 GFP_KERNEL); 847 838 if (!umad_dev) 848 839 return; 849 - 850 - memset(umad_dev, 0, sizeof *umad_dev + 851 - (e - s + 1) * sizeof (struct ib_umad_port)); 852 840 853 841 kref_init(&umad_dev->ref); 854 842 ··· 864 858 return; 865 859 866 860 err: 867 - while (--i >= s) { 868 - class_device_unregister(&umad_dev->port[i - s].class_dev); 869 - class_device_unregister(&umad_dev->port[i - s].sm_class_dev); 870 - } 861 + while (--i >= s) 862 + ib_umad_kill_port(&umad_dev->port[i]); 871 863 872 864 kref_put(&umad_dev->ref, ib_umad_release_dev); 873 865 } ··· 878 874 if (!umad_dev) 879 875 return; 880 876 881 - for (i = 0; i <= umad_dev->end_port - umad_dev->start_port; ++i) { 882 - class_device_unregister(&umad_dev->port[i].class_dev); 883 - class_device_unregister(&umad_dev->port[i].sm_class_dev); 884 - } 877 + for (i = 0; i <= umad_dev->end_port - umad_dev->start_port; ++i) 878 + ib_umad_kill_port(&umad_dev->port[i]); 885 879 886 880 kref_put(&umad_dev->ref, ib_umad_release_dev); 887 881 } ··· 888 886 { 889 887 int ret; 890 888 891 - spin_lock_init(&map_lock); 892 - 893 889 ret = register_chrdev_region(base_dev, IB_UMAD_MAX_PORTS * 2, 894 890 "infiniband_mad"); 895 891 if (ret) { ··· 895 895 goto out; 896 896 } 897 897 898 - ret = class_register(&umad_class); 899 - if (ret) { 898 + umad_class = class_create(THIS_MODULE, "infiniband_mad"); 899 + if (IS_ERR(umad_class)) { 900 + ret = PTR_ERR(umad_class); 900 901 printk(KERN_ERR "user_mad: couldn't create class infiniband_mad\n"); 901 902 goto out_chrdev; 902 903 } 903 904 904 - ret = class_create_file(&umad_class, &class_attr_abi_version); 905 + ret = class_create_file(umad_class, &class_attr_abi_version); 905 906 if (ret) { 906 907 printk(KERN_ERR "user_mad: couldn't create abi_version attribute\n"); 907 908 goto out_class; ··· 917 916 return 0; 918 917 919 918 out_class: 920 - class_unregister(&umad_class); 919 + class_destroy(umad_class); 921 920 922 921 out_chrdev: 923 922 unregister_chrdev_region(base_dev, IB_UMAD_MAX_PORTS * 2); ··· 929 928 static void __exit ib_umad_cleanup(void) 930 929 { 931 930 ib_unregister_client(&umad_client); 932 - class_unregister(&umad_class); 931 + class_destroy(umad_class); 933 932 unregister_chrdev_region(base_dev, IB_UMAD_MAX_PORTS * 2); 934 933 } 935 934
+49 -13
drivers/infiniband/core/uverbs.h
··· 3 3 * Copyright (c) 2005 Cisco Systems. All rights reserved. 4 4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 5 5 * Copyright (c) 2005 Voltaire, Inc. All rights reserved. 6 + * Copyright (c) 2005 PathScale, Inc. All rights reserved. 6 7 * 7 8 * This software is available to you under a choice of one of two 8 9 * licenses. You may choose to be licensed under the terms of the GNU ··· 39 38 #ifndef UVERBS_H 40 39 #define UVERBS_H 41 40 42 - /* Include device.h and fs.h until cdev.h is self-sufficient */ 43 - #include <linux/fs.h> 44 - #include <linux/device.h> 45 - #include <linux/cdev.h> 46 41 #include <linux/kref.h> 47 42 #include <linux/idr.h> 48 43 49 44 #include <rdma/ib_verbs.h> 50 45 #include <rdma/ib_user_verbs.h> 51 46 47 + /* 48 + * Our lifetime rules for these structs are the following: 49 + * 50 + * struct ib_uverbs_device: One reference is held by the module and 51 + * released in ib_uverbs_remove_one(). Another reference is taken by 52 + * ib_uverbs_open() each time the character special file is opened, 53 + * and released in ib_uverbs_release_file() when the file is released. 54 + * 55 + * struct ib_uverbs_file: One reference is held by the VFS and 56 + * released when the file is closed. Another reference is taken when 57 + * an asynchronous event queue file is created and released when the 58 + * event file is closed. 59 + * 60 + * struct ib_uverbs_event_file: One reference is held by the VFS and 61 + * released when the file is closed. For asynchronous event files, 62 + * another reference is held by the corresponding main context file 63 + * and released when that file is closed. For completion event files, 64 + * a reference is taken when a CQ is created that uses the file, and 65 + * released when the CQ is destroyed. 66 + */ 67 + 52 68 struct ib_uverbs_device { 69 + struct kref ref; 53 70 int devnum; 54 - struct cdev dev; 55 - struct class_device class_dev; 71 + struct cdev *dev; 72 + struct class_device *class_dev; 56 73 struct ib_device *ib_dev; 57 - int num_comp; 74 + int num_comp_vectors; 58 75 }; 59 76 60 77 struct ib_uverbs_event_file { 61 78 struct kref ref; 79 + struct file *file; 62 80 struct ib_uverbs_file *uverbs_file; 63 81 spinlock_t lock; 64 - int fd; 65 82 int is_async; 66 83 wait_queue_head_t poll_wait; 67 84 struct fasync_struct *async_queue; ··· 92 73 struct ib_uverbs_device *device; 93 74 struct ib_ucontext *ucontext; 94 75 struct ib_event_handler event_handler; 95 - struct ib_uverbs_event_file async_file; 96 - struct ib_uverbs_event_file comp_file[1]; 76 + struct ib_uverbs_event_file *async_file; 97 77 }; 98 78 99 79 struct ib_uverbs_event { ··· 128 110 extern struct idr ib_uverbs_qp_idr; 129 111 extern struct idr ib_uverbs_srq_idr; 130 112 113 + struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file, 114 + int is_async, int *fd); 115 + void ib_uverbs_release_event_file(struct kref *ref); 116 + struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd); 117 + 118 + void ib_uverbs_release_ucq(struct ib_uverbs_file *file, 119 + struct ib_uverbs_event_file *ev_file, 120 + struct ib_ucq_object *uobj); 121 + void ib_uverbs_release_uevent(struct ib_uverbs_file *file, 122 + struct ib_uevent_object *uobj); 123 + 131 124 void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context); 132 125 void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr); 133 126 void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr); 134 127 void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr); 128 + void ib_uverbs_event_handler(struct ib_event_handler *handler, 129 + struct ib_event *event); 135 130 136 131 int ib_umem_get(struct ib_device *dev, struct ib_umem *mem, 137 132 void *addr, size_t size, int write); ··· 156 125 const char __user *buf, int in_len, \ 157 126 int out_len) 158 127 159 - IB_UVERBS_DECLARE_CMD(query_params); 160 128 IB_UVERBS_DECLARE_CMD(get_context); 161 129 IB_UVERBS_DECLARE_CMD(query_device); 162 130 IB_UVERBS_DECLARE_CMD(query_port); 163 - IB_UVERBS_DECLARE_CMD(query_gid); 164 - IB_UVERBS_DECLARE_CMD(query_pkey); 165 131 IB_UVERBS_DECLARE_CMD(alloc_pd); 166 132 IB_UVERBS_DECLARE_CMD(dealloc_pd); 167 133 IB_UVERBS_DECLARE_CMD(reg_mr); 168 134 IB_UVERBS_DECLARE_CMD(dereg_mr); 135 + IB_UVERBS_DECLARE_CMD(create_comp_channel); 169 136 IB_UVERBS_DECLARE_CMD(create_cq); 137 + IB_UVERBS_DECLARE_CMD(poll_cq); 138 + IB_UVERBS_DECLARE_CMD(req_notify_cq); 170 139 IB_UVERBS_DECLARE_CMD(destroy_cq); 171 140 IB_UVERBS_DECLARE_CMD(create_qp); 172 141 IB_UVERBS_DECLARE_CMD(modify_qp); 173 142 IB_UVERBS_DECLARE_CMD(destroy_qp); 143 + IB_UVERBS_DECLARE_CMD(post_send); 144 + IB_UVERBS_DECLARE_CMD(post_recv); 145 + IB_UVERBS_DECLARE_CMD(post_srq_recv); 146 + IB_UVERBS_DECLARE_CMD(create_ah); 147 + IB_UVERBS_DECLARE_CMD(destroy_ah); 174 148 IB_UVERBS_DECLARE_CMD(attach_mcast); 175 149 IB_UVERBS_DECLARE_CMD(detach_mcast); 176 150 IB_UVERBS_DECLARE_CMD(create_srq);
+677 -181
drivers/infiniband/core/uverbs_cmd.c
··· 1 1 /* 2 2 * Copyright (c) 2005 Topspin Communications. All rights reserved. 3 3 * Copyright (c) 2005 Cisco Systems. All rights reserved. 4 + * Copyright (c) 2005 PathScale, Inc. All rights reserved. 4 5 * 5 6 * This software is available to you under a choice of one of two 6 7 * licenses. You may choose to be licensed under the terms of the GNU ··· 34 33 * $Id: uverbs_cmd.c 2708 2005-06-24 17:27:21Z roland $ 35 34 */ 36 35 36 + #include <linux/file.h> 37 + #include <linux/fs.h> 38 + 37 39 #include <asm/uaccess.h> 38 40 39 41 #include "uverbs.h" ··· 49 45 (udata)->outlen = (olen); \ 50 46 } while (0) 51 47 52 - ssize_t ib_uverbs_query_params(struct ib_uverbs_file *file, 53 - const char __user *buf, 54 - int in_len, int out_len) 55 - { 56 - struct ib_uverbs_query_params cmd; 57 - struct ib_uverbs_query_params_resp resp; 58 - 59 - if (out_len < sizeof resp) 60 - return -ENOSPC; 61 - 62 - if (copy_from_user(&cmd, buf, sizeof cmd)) 63 - return -EFAULT; 64 - 65 - memset(&resp, 0, sizeof resp); 66 - 67 - resp.num_cq_events = file->device->num_comp; 68 - 69 - if (copy_to_user((void __user *) (unsigned long) cmd.response, &resp, sizeof resp)) 70 - return -EFAULT; 71 - 72 - return in_len; 73 - } 74 - 75 48 ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file, 76 49 const char __user *buf, 77 50 int in_len, int out_len) ··· 58 77 struct ib_udata udata; 59 78 struct ib_device *ibdev = file->device->ib_dev; 60 79 struct ib_ucontext *ucontext; 61 - int i; 80 + struct file *filp; 62 81 int ret; 63 82 64 83 if (out_len < sizeof resp) ··· 91 110 INIT_LIST_HEAD(&ucontext->srq_list); 92 111 INIT_LIST_HEAD(&ucontext->ah_list); 93 112 94 - resp.async_fd = file->async_file.fd; 95 - for (i = 0; i < file->device->num_comp; ++i) 96 - if (copy_to_user((void __user *) (unsigned long) cmd.cq_fd_tab + 97 - i * sizeof (__u32), 98 - &file->comp_file[i].fd, sizeof (__u32))) { 99 - ret = -EFAULT; 100 - goto err_free; 101 - } 113 + resp.num_comp_vectors = file->device->num_comp_vectors; 114 + 115 + filp = ib_uverbs_alloc_event_file(file, 1, &resp.async_fd); 116 + if (IS_ERR(filp)) { 117 + ret = PTR_ERR(filp); 118 + goto err_free; 119 + } 102 120 103 121 if (copy_to_user((void __user *) (unsigned long) cmd.response, 104 122 &resp, sizeof resp)) { 105 123 ret = -EFAULT; 106 - goto err_free; 124 + goto err_file; 107 125 } 108 126 127 + file->async_file = filp->private_data; 128 + 129 + INIT_IB_EVENT_HANDLER(&file->event_handler, file->device->ib_dev, 130 + ib_uverbs_event_handler); 131 + ret = ib_register_event_handler(&file->event_handler); 132 + if (ret) 133 + goto err_file; 134 + 135 + kref_get(&file->async_file->ref); 136 + kref_get(&file->ref); 109 137 file->ucontext = ucontext; 138 + 139 + fd_install(resp.async_fd, filp); 140 + 110 141 up(&file->mutex); 111 142 112 143 return in_len; 144 + 145 + err_file: 146 + put_unused_fd(resp.async_fd); 147 + fput(filp); 113 148 114 149 err_free: 115 150 ibdev->dealloc_ucontext(ucontext); ··· 252 255 return in_len; 253 256 } 254 257 255 - ssize_t ib_uverbs_query_gid(struct ib_uverbs_file *file, 256 - const char __user *buf, 257 - int in_len, int out_len) 258 - { 259 - struct ib_uverbs_query_gid cmd; 260 - struct ib_uverbs_query_gid_resp resp; 261 - int ret; 262 - 263 - if (out_len < sizeof resp) 264 - return -ENOSPC; 265 - 266 - if (copy_from_user(&cmd, buf, sizeof cmd)) 267 - return -EFAULT; 268 - 269 - memset(&resp, 0, sizeof resp); 270 - 271 - ret = ib_query_gid(file->device->ib_dev, cmd.port_num, cmd.index, 272 - (union ib_gid *) resp.gid); 273 - if (ret) 274 - return ret; 275 - 276 - if (copy_to_user((void __user *) (unsigned long) cmd.response, 277 - &resp, sizeof resp)) 278 - return -EFAULT; 279 - 280 - return in_len; 281 - } 282 - 283 - ssize_t ib_uverbs_query_pkey(struct ib_uverbs_file *file, 284 - const char __user *buf, 285 - int in_len, int out_len) 286 - { 287 - struct ib_uverbs_query_pkey cmd; 288 - struct ib_uverbs_query_pkey_resp resp; 289 - int ret; 290 - 291 - if (out_len < sizeof resp) 292 - return -ENOSPC; 293 - 294 - if (copy_from_user(&cmd, buf, sizeof cmd)) 295 - return -EFAULT; 296 - 297 - memset(&resp, 0, sizeof resp); 298 - 299 - ret = ib_query_pkey(file->device->ib_dev, cmd.port_num, cmd.index, 300 - &resp.pkey); 301 - if (ret) 302 - return ret; 303 - 304 - if (copy_to_user((void __user *) (unsigned long) cmd.response, 305 - &resp, sizeof resp)) 306 - return -EFAULT; 307 - 308 - return in_len; 309 - } 310 - 311 258 ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file, 312 259 const char __user *buf, 313 260 int in_len, int out_len) ··· 290 349 pd->uobject = uobj; 291 350 atomic_set(&pd->usecnt, 0); 292 351 352 + down(&ib_uverbs_idr_mutex); 353 + 293 354 retry: 294 355 if (!idr_pre_get(&ib_uverbs_pd_idr, GFP_KERNEL)) { 295 356 ret = -ENOMEM; 296 - goto err_pd; 357 + goto err_up; 297 358 } 298 359 299 - down(&ib_uverbs_idr_mutex); 300 360 ret = idr_get_new(&ib_uverbs_pd_idr, pd, &uobj->id); 301 - up(&ib_uverbs_idr_mutex); 302 361 303 362 if (ret == -EAGAIN) 304 363 goto retry; 305 364 if (ret) 306 - goto err_pd; 307 - 308 - down(&file->mutex); 309 - list_add_tail(&uobj->list, &file->ucontext->pd_list); 310 - up(&file->mutex); 365 + goto err_up; 311 366 312 367 memset(&resp, 0, sizeof resp); 313 368 resp.pd_handle = uobj->id; ··· 311 374 if (copy_to_user((void __user *) (unsigned long) cmd.response, 312 375 &resp, sizeof resp)) { 313 376 ret = -EFAULT; 314 - goto err_list; 377 + goto err_idr; 315 378 } 379 + 380 + down(&file->mutex); 381 + list_add_tail(&uobj->list, &file->ucontext->pd_list); 382 + up(&file->mutex); 383 + 384 + up(&ib_uverbs_idr_mutex); 316 385 317 386 return in_len; 318 387 319 - err_list: 320 - down(&file->mutex); 321 - list_del(&uobj->list); 322 - up(&file->mutex); 323 - 324 - down(&ib_uverbs_idr_mutex); 388 + err_idr: 325 389 idr_remove(&ib_uverbs_pd_idr, uobj->id); 326 - up(&ib_uverbs_idr_mutex); 327 390 328 - err_pd: 391 + err_up: 392 + up(&ib_uverbs_idr_mutex); 329 393 ib_dealloc_pd(pd); 330 394 331 395 err: ··· 397 459 if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK)) 398 460 return -EINVAL; 399 461 462 + /* 463 + * Local write permission is required if remote write or 464 + * remote atomic permission is also requested. 465 + */ 466 + if (cmd.access_flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) && 467 + !(cmd.access_flags & IB_ACCESS_LOCAL_WRITE)) 468 + return -EINVAL; 469 + 400 470 obj = kmalloc(sizeof *obj, GFP_KERNEL); 401 471 if (!obj) 402 472 return -ENOMEM; ··· 470 524 471 525 resp.mr_handle = obj->uobject.id; 472 526 473 - down(&file->mutex); 474 - list_add_tail(&obj->uobject.list, &file->ucontext->mr_list); 475 - up(&file->mutex); 476 - 477 527 if (copy_to_user((void __user *) (unsigned long) cmd.response, 478 528 &resp, sizeof resp)) { 479 529 ret = -EFAULT; 480 - goto err_list; 530 + goto err_idr; 481 531 } 532 + 533 + down(&file->mutex); 534 + list_add_tail(&obj->uobject.list, &file->ucontext->mr_list); 535 + up(&file->mutex); 482 536 483 537 up(&ib_uverbs_idr_mutex); 484 538 485 539 return in_len; 486 540 487 - err_list: 488 - down(&file->mutex); 489 - list_del(&obj->uobject.list); 490 - up(&file->mutex); 541 + err_idr: 542 + idr_remove(&ib_uverbs_mr_idr, obj->uobject.id); 491 543 492 544 err_unreg: 493 545 ib_dereg_mr(mr); ··· 539 595 return ret ? ret : in_len; 540 596 } 541 597 598 + ssize_t ib_uverbs_create_comp_channel(struct ib_uverbs_file *file, 599 + const char __user *buf, int in_len, 600 + int out_len) 601 + { 602 + struct ib_uverbs_create_comp_channel cmd; 603 + struct ib_uverbs_create_comp_channel_resp resp; 604 + struct file *filp; 605 + 606 + if (out_len < sizeof resp) 607 + return -ENOSPC; 608 + 609 + if (copy_from_user(&cmd, buf, sizeof cmd)) 610 + return -EFAULT; 611 + 612 + filp = ib_uverbs_alloc_event_file(file, 0, &resp.fd); 613 + if (IS_ERR(filp)) 614 + return PTR_ERR(filp); 615 + 616 + if (copy_to_user((void __user *) (unsigned long) cmd.response, 617 + &resp, sizeof resp)) { 618 + put_unused_fd(resp.fd); 619 + fput(filp); 620 + return -EFAULT; 621 + } 622 + 623 + fd_install(resp.fd, filp); 624 + return in_len; 625 + } 626 + 542 627 ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file, 543 628 const char __user *buf, int in_len, 544 629 int out_len) ··· 576 603 struct ib_uverbs_create_cq_resp resp; 577 604 struct ib_udata udata; 578 605 struct ib_ucq_object *uobj; 606 + struct ib_uverbs_event_file *ev_file = NULL; 579 607 struct ib_cq *cq; 580 608 int ret; 581 609 ··· 590 616 (unsigned long) cmd.response + sizeof resp, 591 617 in_len - sizeof cmd, out_len - sizeof resp); 592 618 593 - if (cmd.event_handler >= file->device->num_comp) 619 + if (cmd.comp_vector >= file->device->num_comp_vectors) 594 620 return -EINVAL; 621 + 622 + if (cmd.comp_channel >= 0) 623 + ev_file = ib_uverbs_lookup_comp_file(cmd.comp_channel); 595 624 596 625 uobj = kmalloc(sizeof *uobj, GFP_KERNEL); 597 626 if (!uobj) ··· 618 641 cq->uobject = &uobj->uobject; 619 642 cq->comp_handler = ib_uverbs_comp_handler; 620 643 cq->event_handler = ib_uverbs_cq_event_handler; 621 - cq->cq_context = file; 644 + cq->cq_context = ev_file; 622 645 atomic_set(&cq->usecnt, 0); 646 + 647 + down(&ib_uverbs_idr_mutex); 623 648 624 649 retry: 625 650 if (!idr_pre_get(&ib_uverbs_cq_idr, GFP_KERNEL)) { 626 651 ret = -ENOMEM; 627 - goto err_cq; 652 + goto err_up; 628 653 } 629 654 630 - down(&ib_uverbs_idr_mutex); 631 655 ret = idr_get_new(&ib_uverbs_cq_idr, cq, &uobj->uobject.id); 632 - up(&ib_uverbs_idr_mutex); 633 656 634 657 if (ret == -EAGAIN) 635 658 goto retry; 636 659 if (ret) 637 - goto err_cq; 638 - 639 - down(&file->mutex); 640 - list_add_tail(&uobj->uobject.list, &file->ucontext->cq_list); 641 - up(&file->mutex); 660 + goto err_up; 642 661 643 662 memset(&resp, 0, sizeof resp); 644 663 resp.cq_handle = uobj->uobject.id; ··· 643 670 if (copy_to_user((void __user *) (unsigned long) cmd.response, 644 671 &resp, sizeof resp)) { 645 672 ret = -EFAULT; 646 - goto err_list; 673 + goto err_idr; 647 674 } 675 + 676 + down(&file->mutex); 677 + list_add_tail(&uobj->uobject.list, &file->ucontext->cq_list); 678 + up(&file->mutex); 679 + 680 + up(&ib_uverbs_idr_mutex); 648 681 649 682 return in_len; 650 683 651 - err_list: 652 - down(&file->mutex); 653 - list_del(&uobj->uobject.list); 654 - up(&file->mutex); 655 - 656 - down(&ib_uverbs_idr_mutex); 684 + err_idr: 657 685 idr_remove(&ib_uverbs_cq_idr, uobj->uobject.id); 658 - up(&ib_uverbs_idr_mutex); 659 686 660 - err_cq: 687 + err_up: 688 + up(&ib_uverbs_idr_mutex); 661 689 ib_destroy_cq(cq); 662 690 663 691 err: 664 692 kfree(uobj); 693 + return ret; 694 + } 695 + 696 + ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file, 697 + const char __user *buf, int in_len, 698 + int out_len) 699 + { 700 + struct ib_uverbs_poll_cq cmd; 701 + struct ib_uverbs_poll_cq_resp *resp; 702 + struct ib_cq *cq; 703 + struct ib_wc *wc; 704 + int ret = 0; 705 + int i; 706 + int rsize; 707 + 708 + if (copy_from_user(&cmd, buf, sizeof cmd)) 709 + return -EFAULT; 710 + 711 + wc = kmalloc(cmd.ne * sizeof *wc, GFP_KERNEL); 712 + if (!wc) 713 + return -ENOMEM; 714 + 715 + rsize = sizeof *resp + cmd.ne * sizeof(struct ib_uverbs_wc); 716 + resp = kmalloc(rsize, GFP_KERNEL); 717 + if (!resp) { 718 + ret = -ENOMEM; 719 + goto out_wc; 720 + } 721 + 722 + down(&ib_uverbs_idr_mutex); 723 + cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle); 724 + if (!cq || cq->uobject->context != file->ucontext) { 725 + ret = -EINVAL; 726 + goto out; 727 + } 728 + 729 + resp->count = ib_poll_cq(cq, cmd.ne, wc); 730 + 731 + for (i = 0; i < resp->count; i++) { 732 + resp->wc[i].wr_id = wc[i].wr_id; 733 + resp->wc[i].status = wc[i].status; 734 + resp->wc[i].opcode = wc[i].opcode; 735 + resp->wc[i].vendor_err = wc[i].vendor_err; 736 + resp->wc[i].byte_len = wc[i].byte_len; 737 + resp->wc[i].imm_data = wc[i].imm_data; 738 + resp->wc[i].qp_num = wc[i].qp_num; 739 + resp->wc[i].src_qp = wc[i].src_qp; 740 + resp->wc[i].wc_flags = wc[i].wc_flags; 741 + resp->wc[i].pkey_index = wc[i].pkey_index; 742 + resp->wc[i].slid = wc[i].slid; 743 + resp->wc[i].sl = wc[i].sl; 744 + resp->wc[i].dlid_path_bits = wc[i].dlid_path_bits; 745 + resp->wc[i].port_num = wc[i].port_num; 746 + } 747 + 748 + if (copy_to_user((void __user *) (unsigned long) cmd.response, resp, rsize)) 749 + ret = -EFAULT; 750 + 751 + out: 752 + up(&ib_uverbs_idr_mutex); 753 + kfree(resp); 754 + 755 + out_wc: 756 + kfree(wc); 757 + return ret ? ret : in_len; 758 + } 759 + 760 + ssize_t ib_uverbs_req_notify_cq(struct ib_uverbs_file *file, 761 + const char __user *buf, int in_len, 762 + int out_len) 763 + { 764 + struct ib_uverbs_req_notify_cq cmd; 765 + struct ib_cq *cq; 766 + int ret = -EINVAL; 767 + 768 + if (copy_from_user(&cmd, buf, sizeof cmd)) 769 + return -EFAULT; 770 + 771 + down(&ib_uverbs_idr_mutex); 772 + cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle); 773 + if (cq && cq->uobject->context == file->ucontext) { 774 + ib_req_notify_cq(cq, cmd.solicited_only ? 775 + IB_CQ_SOLICITED : IB_CQ_NEXT_COMP); 776 + ret = in_len; 777 + } 778 + up(&ib_uverbs_idr_mutex); 779 + 665 780 return ret; 666 781 } 667 782 ··· 761 700 struct ib_uverbs_destroy_cq_resp resp; 762 701 struct ib_cq *cq; 763 702 struct ib_ucq_object *uobj; 764 - struct ib_uverbs_event *evt, *tmp; 703 + struct ib_uverbs_event_file *ev_file; 765 704 u64 user_handle; 766 705 int ret = -EINVAL; 767 706 ··· 777 716 goto out; 778 717 779 718 user_handle = cq->uobject->user_handle; 780 - uobj = container_of(cq->uobject, struct ib_ucq_object, uobject); 719 + uobj = container_of(cq->uobject, struct ib_ucq_object, uobject); 720 + ev_file = cq->cq_context; 781 721 782 722 ret = ib_destroy_cq(cq); 783 723 if (ret) ··· 790 728 list_del(&uobj->uobject.list); 791 729 up(&file->mutex); 792 730 793 - spin_lock_irq(&file->comp_file[0].lock); 794 - list_for_each_entry_safe(evt, tmp, &uobj->comp_list, obj_list) { 795 - list_del(&evt->list); 796 - kfree(evt); 797 - } 798 - spin_unlock_irq(&file->comp_file[0].lock); 799 - 800 - spin_lock_irq(&file->async_file.lock); 801 - list_for_each_entry_safe(evt, tmp, &uobj->async_list, obj_list) { 802 - list_del(&evt->list); 803 - kfree(evt); 804 - } 805 - spin_unlock_irq(&file->async_file.lock); 731 + ib_uverbs_release_ucq(file, ev_file, uobj); 806 732 807 733 resp.comp_events_reported = uobj->comp_events_reported; 808 734 resp.async_events_reported = uobj->async_events_reported; ··· 909 859 910 860 resp.qp_handle = uobj->uobject.id; 911 861 912 - down(&file->mutex); 913 - list_add_tail(&uobj->uobject.list, &file->ucontext->qp_list); 914 - up(&file->mutex); 915 - 916 862 if (copy_to_user((void __user *) (unsigned long) cmd.response, 917 863 &resp, sizeof resp)) { 918 864 ret = -EFAULT; 919 - goto err_list; 865 + goto err_idr; 920 866 } 867 + 868 + down(&file->mutex); 869 + list_add_tail(&uobj->uobject.list, &file->ucontext->qp_list); 870 + up(&file->mutex); 921 871 922 872 up(&ib_uverbs_idr_mutex); 923 873 924 874 return in_len; 925 875 926 - err_list: 927 - down(&file->mutex); 928 - list_del(&uobj->uobject.list); 929 - up(&file->mutex); 876 + err_idr: 877 + idr_remove(&ib_uverbs_qp_idr, uobj->uobject.id); 930 878 931 879 err_destroy: 932 880 ib_destroy_qp(qp); ··· 1027 979 struct ib_uverbs_destroy_qp_resp resp; 1028 980 struct ib_qp *qp; 1029 981 struct ib_uevent_object *uobj; 1030 - struct ib_uverbs_event *evt, *tmp; 1031 982 int ret = -EINVAL; 1032 983 1033 984 if (copy_from_user(&cmd, buf, sizeof cmd)) ··· 1052 1005 list_del(&uobj->uobject.list); 1053 1006 up(&file->mutex); 1054 1007 1055 - spin_lock_irq(&file->async_file.lock); 1056 - list_for_each_entry_safe(evt, tmp, &uobj->event_list, obj_list) { 1057 - list_del(&evt->list); 1058 - kfree(evt); 1059 - } 1060 - spin_unlock_irq(&file->async_file.lock); 1008 + ib_uverbs_release_uevent(file, uobj); 1061 1009 1062 1010 resp.events_reported = uobj->events_reported; 1063 1011 ··· 1061 1019 if (copy_to_user((void __user *) (unsigned long) cmd.response, 1062 1020 &resp, sizeof resp)) 1063 1021 ret = -EFAULT; 1022 + 1023 + out: 1024 + up(&ib_uverbs_idr_mutex); 1025 + 1026 + return ret ? ret : in_len; 1027 + } 1028 + 1029 + ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file, 1030 + const char __user *buf, int in_len, 1031 + int out_len) 1032 + { 1033 + struct ib_uverbs_post_send cmd; 1034 + struct ib_uverbs_post_send_resp resp; 1035 + struct ib_uverbs_send_wr *user_wr; 1036 + struct ib_send_wr *wr = NULL, *last, *next, *bad_wr; 1037 + struct ib_qp *qp; 1038 + int i, sg_ind; 1039 + ssize_t ret = -EINVAL; 1040 + 1041 + if (copy_from_user(&cmd, buf, sizeof cmd)) 1042 + return -EFAULT; 1043 + 1044 + if (in_len < sizeof cmd + cmd.wqe_size * cmd.wr_count + 1045 + cmd.sge_count * sizeof (struct ib_uverbs_sge)) 1046 + return -EINVAL; 1047 + 1048 + if (cmd.wqe_size < sizeof (struct ib_uverbs_send_wr)) 1049 + return -EINVAL; 1050 + 1051 + user_wr = kmalloc(cmd.wqe_size, GFP_KERNEL); 1052 + if (!user_wr) 1053 + return -ENOMEM; 1054 + 1055 + down(&ib_uverbs_idr_mutex); 1056 + 1057 + qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); 1058 + if (!qp || qp->uobject->context != file->ucontext) 1059 + goto out; 1060 + 1061 + sg_ind = 0; 1062 + last = NULL; 1063 + for (i = 0; i < cmd.wr_count; ++i) { 1064 + if (copy_from_user(user_wr, 1065 + buf + sizeof cmd + i * cmd.wqe_size, 1066 + cmd.wqe_size)) { 1067 + ret = -EFAULT; 1068 + goto out; 1069 + } 1070 + 1071 + if (user_wr->num_sge + sg_ind > cmd.sge_count) { 1072 + ret = -EINVAL; 1073 + goto out; 1074 + } 1075 + 1076 + next = kmalloc(ALIGN(sizeof *next, sizeof (struct ib_sge)) + 1077 + user_wr->num_sge * sizeof (struct ib_sge), 1078 + GFP_KERNEL); 1079 + if (!next) { 1080 + ret = -ENOMEM; 1081 + goto out; 1082 + } 1083 + 1084 + if (!last) 1085 + wr = next; 1086 + else 1087 + last->next = next; 1088 + last = next; 1089 + 1090 + next->next = NULL; 1091 + next->wr_id = user_wr->wr_id; 1092 + next->num_sge = user_wr->num_sge; 1093 + next->opcode = user_wr->opcode; 1094 + next->send_flags = user_wr->send_flags; 1095 + next->imm_data = user_wr->imm_data; 1096 + 1097 + if (qp->qp_type == IB_QPT_UD) { 1098 + next->wr.ud.ah = idr_find(&ib_uverbs_ah_idr, 1099 + user_wr->wr.ud.ah); 1100 + if (!next->wr.ud.ah) { 1101 + ret = -EINVAL; 1102 + goto out; 1103 + } 1104 + next->wr.ud.remote_qpn = user_wr->wr.ud.remote_qpn; 1105 + next->wr.ud.remote_qkey = user_wr->wr.ud.remote_qkey; 1106 + } else { 1107 + switch (next->opcode) { 1108 + case IB_WR_RDMA_WRITE: 1109 + case IB_WR_RDMA_WRITE_WITH_IMM: 1110 + case IB_WR_RDMA_READ: 1111 + next->wr.rdma.remote_addr = 1112 + user_wr->wr.rdma.remote_addr; 1113 + next->wr.rdma.rkey = 1114 + user_wr->wr.rdma.rkey; 1115 + break; 1116 + case IB_WR_ATOMIC_CMP_AND_SWP: 1117 + case IB_WR_ATOMIC_FETCH_AND_ADD: 1118 + next->wr.atomic.remote_addr = 1119 + user_wr->wr.atomic.remote_addr; 1120 + next->wr.atomic.compare_add = 1121 + user_wr->wr.atomic.compare_add; 1122 + next->wr.atomic.swap = user_wr->wr.atomic.swap; 1123 + next->wr.atomic.rkey = user_wr->wr.atomic.rkey; 1124 + break; 1125 + default: 1126 + break; 1127 + } 1128 + } 1129 + 1130 + if (next->num_sge) { 1131 + next->sg_list = (void *) next + 1132 + ALIGN(sizeof *next, sizeof (struct ib_sge)); 1133 + if (copy_from_user(next->sg_list, 1134 + buf + sizeof cmd + 1135 + cmd.wr_count * cmd.wqe_size + 1136 + sg_ind * sizeof (struct ib_sge), 1137 + next->num_sge * sizeof (struct ib_sge))) { 1138 + ret = -EFAULT; 1139 + goto out; 1140 + } 1141 + sg_ind += next->num_sge; 1142 + } else 1143 + next->sg_list = NULL; 1144 + } 1145 + 1146 + resp.bad_wr = 0; 1147 + ret = qp->device->post_send(qp, wr, &bad_wr); 1148 + if (ret) 1149 + for (next = wr; next; next = next->next) { 1150 + ++resp.bad_wr; 1151 + if (next == bad_wr) 1152 + break; 1153 + } 1154 + 1155 + if (copy_to_user((void __user *) (unsigned long) cmd.response, 1156 + &resp, sizeof resp)) 1157 + ret = -EFAULT; 1158 + 1159 + out: 1160 + up(&ib_uverbs_idr_mutex); 1161 + 1162 + while (wr) { 1163 + next = wr->next; 1164 + kfree(wr); 1165 + wr = next; 1166 + } 1167 + 1168 + kfree(user_wr); 1169 + 1170 + return ret ? ret : in_len; 1171 + } 1172 + 1173 + static struct ib_recv_wr *ib_uverbs_unmarshall_recv(const char __user *buf, 1174 + int in_len, 1175 + u32 wr_count, 1176 + u32 sge_count, 1177 + u32 wqe_size) 1178 + { 1179 + struct ib_uverbs_recv_wr *user_wr; 1180 + struct ib_recv_wr *wr = NULL, *last, *next; 1181 + int sg_ind; 1182 + int i; 1183 + int ret; 1184 + 1185 + if (in_len < wqe_size * wr_count + 1186 + sge_count * sizeof (struct ib_uverbs_sge)) 1187 + return ERR_PTR(-EINVAL); 1188 + 1189 + if (wqe_size < sizeof (struct ib_uverbs_recv_wr)) 1190 + return ERR_PTR(-EINVAL); 1191 + 1192 + user_wr = kmalloc(wqe_size, GFP_KERNEL); 1193 + if (!user_wr) 1194 + return ERR_PTR(-ENOMEM); 1195 + 1196 + sg_ind = 0; 1197 + last = NULL; 1198 + for (i = 0; i < wr_count; ++i) { 1199 + if (copy_from_user(user_wr, buf + i * wqe_size, 1200 + wqe_size)) { 1201 + ret = -EFAULT; 1202 + goto err; 1203 + } 1204 + 1205 + if (user_wr->num_sge + sg_ind > sge_count) { 1206 + ret = -EINVAL; 1207 + goto err; 1208 + } 1209 + 1210 + next = kmalloc(ALIGN(sizeof *next, sizeof (struct ib_sge)) + 1211 + user_wr->num_sge * sizeof (struct ib_sge), 1212 + GFP_KERNEL); 1213 + if (!next) { 1214 + ret = -ENOMEM; 1215 + goto err; 1216 + } 1217 + 1218 + if (!last) 1219 + wr = next; 1220 + else 1221 + last->next = next; 1222 + last = next; 1223 + 1224 + next->next = NULL; 1225 + next->wr_id = user_wr->wr_id; 1226 + next->num_sge = user_wr->num_sge; 1227 + 1228 + if (next->num_sge) { 1229 + next->sg_list = (void *) next + 1230 + ALIGN(sizeof *next, sizeof (struct ib_sge)); 1231 + if (copy_from_user(next->sg_list, 1232 + buf + wr_count * wqe_size + 1233 + sg_ind * sizeof (struct ib_sge), 1234 + next->num_sge * sizeof (struct ib_sge))) { 1235 + ret = -EFAULT; 1236 + goto err; 1237 + } 1238 + sg_ind += next->num_sge; 1239 + } else 1240 + next->sg_list = NULL; 1241 + } 1242 + 1243 + kfree(user_wr); 1244 + return wr; 1245 + 1246 + err: 1247 + kfree(user_wr); 1248 + 1249 + while (wr) { 1250 + next = wr->next; 1251 + kfree(wr); 1252 + wr = next; 1253 + } 1254 + 1255 + return ERR_PTR(ret); 1256 + } 1257 + 1258 + ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file, 1259 + const char __user *buf, int in_len, 1260 + int out_len) 1261 + { 1262 + struct ib_uverbs_post_recv cmd; 1263 + struct ib_uverbs_post_recv_resp resp; 1264 + struct ib_recv_wr *wr, *next, *bad_wr; 1265 + struct ib_qp *qp; 1266 + ssize_t ret = -EINVAL; 1267 + 1268 + if (copy_from_user(&cmd, buf, sizeof cmd)) 1269 + return -EFAULT; 1270 + 1271 + wr = ib_uverbs_unmarshall_recv(buf + sizeof cmd, 1272 + in_len - sizeof cmd, cmd.wr_count, 1273 + cmd.sge_count, cmd.wqe_size); 1274 + if (IS_ERR(wr)) 1275 + return PTR_ERR(wr); 1276 + 1277 + down(&ib_uverbs_idr_mutex); 1278 + 1279 + qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); 1280 + if (!qp || qp->uobject->context != file->ucontext) 1281 + goto out; 1282 + 1283 + resp.bad_wr = 0; 1284 + ret = qp->device->post_recv(qp, wr, &bad_wr); 1285 + if (ret) 1286 + for (next = wr; next; next = next->next) { 1287 + ++resp.bad_wr; 1288 + if (next == bad_wr) 1289 + break; 1290 + } 1291 + 1292 + 1293 + if (copy_to_user((void __user *) (unsigned long) cmd.response, 1294 + &resp, sizeof resp)) 1295 + ret = -EFAULT; 1296 + 1297 + out: 1298 + up(&ib_uverbs_idr_mutex); 1299 + 1300 + while (wr) { 1301 + next = wr->next; 1302 + kfree(wr); 1303 + wr = next; 1304 + } 1305 + 1306 + return ret ? ret : in_len; 1307 + } 1308 + 1309 + ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file, 1310 + const char __user *buf, int in_len, 1311 + int out_len) 1312 + { 1313 + struct ib_uverbs_post_srq_recv cmd; 1314 + struct ib_uverbs_post_srq_recv_resp resp; 1315 + struct ib_recv_wr *wr, *next, *bad_wr; 1316 + struct ib_srq *srq; 1317 + ssize_t ret = -EINVAL; 1318 + 1319 + if (copy_from_user(&cmd, buf, sizeof cmd)) 1320 + return -EFAULT; 1321 + 1322 + wr = ib_uverbs_unmarshall_recv(buf + sizeof cmd, 1323 + in_len - sizeof cmd, cmd.wr_count, 1324 + cmd.sge_count, cmd.wqe_size); 1325 + if (IS_ERR(wr)) 1326 + return PTR_ERR(wr); 1327 + 1328 + down(&ib_uverbs_idr_mutex); 1329 + 1330 + srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle); 1331 + if (!srq || srq->uobject->context != file->ucontext) 1332 + goto out; 1333 + 1334 + resp.bad_wr = 0; 1335 + ret = srq->device->post_srq_recv(srq, wr, &bad_wr); 1336 + if (ret) 1337 + for (next = wr; next; next = next->next) { 1338 + ++resp.bad_wr; 1339 + if (next == bad_wr) 1340 + break; 1341 + } 1342 + 1343 + 1344 + if (copy_to_user((void __user *) (unsigned long) cmd.response, 1345 + &resp, sizeof resp)) 1346 + ret = -EFAULT; 1347 + 1348 + out: 1349 + up(&ib_uverbs_idr_mutex); 1350 + 1351 + while (wr) { 1352 + next = wr->next; 1353 + kfree(wr); 1354 + wr = next; 1355 + } 1356 + 1357 + return ret ? ret : in_len; 1358 + } 1359 + 1360 + ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file, 1361 + const char __user *buf, int in_len, 1362 + int out_len) 1363 + { 1364 + struct ib_uverbs_create_ah cmd; 1365 + struct ib_uverbs_create_ah_resp resp; 1366 + struct ib_uobject *uobj; 1367 + struct ib_pd *pd; 1368 + struct ib_ah *ah; 1369 + struct ib_ah_attr attr; 1370 + int ret; 1371 + 1372 + if (out_len < sizeof resp) 1373 + return -ENOSPC; 1374 + 1375 + if (copy_from_user(&cmd, buf, sizeof cmd)) 1376 + return -EFAULT; 1377 + 1378 + uobj = kmalloc(sizeof *uobj, GFP_KERNEL); 1379 + if (!uobj) 1380 + return -ENOMEM; 1381 + 1382 + down(&ib_uverbs_idr_mutex); 1383 + 1384 + pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); 1385 + if (!pd || pd->uobject->context != file->ucontext) { 1386 + ret = -EINVAL; 1387 + goto err_up; 1388 + } 1389 + 1390 + uobj->user_handle = cmd.user_handle; 1391 + uobj->context = file->ucontext; 1392 + 1393 + attr.dlid = cmd.attr.dlid; 1394 + attr.sl = cmd.attr.sl; 1395 + attr.src_path_bits = cmd.attr.src_path_bits; 1396 + attr.static_rate = cmd.attr.static_rate; 1397 + attr.port_num = cmd.attr.port_num; 1398 + attr.grh.flow_label = cmd.attr.grh.flow_label; 1399 + attr.grh.sgid_index = cmd.attr.grh.sgid_index; 1400 + attr.grh.hop_limit = cmd.attr.grh.hop_limit; 1401 + attr.grh.traffic_class = cmd.attr.grh.traffic_class; 1402 + memcpy(attr.grh.dgid.raw, cmd.attr.grh.dgid, 16); 1403 + 1404 + ah = ib_create_ah(pd, &attr); 1405 + if (IS_ERR(ah)) { 1406 + ret = PTR_ERR(ah); 1407 + goto err_up; 1408 + } 1409 + 1410 + ah->uobject = uobj; 1411 + 1412 + retry: 1413 + if (!idr_pre_get(&ib_uverbs_ah_idr, GFP_KERNEL)) { 1414 + ret = -ENOMEM; 1415 + goto err_destroy; 1416 + } 1417 + 1418 + ret = idr_get_new(&ib_uverbs_ah_idr, ah, &uobj->id); 1419 + 1420 + if (ret == -EAGAIN) 1421 + goto retry; 1422 + if (ret) 1423 + goto err_destroy; 1424 + 1425 + resp.ah_handle = uobj->id; 1426 + 1427 + if (copy_to_user((void __user *) (unsigned long) cmd.response, 1428 + &resp, sizeof resp)) { 1429 + ret = -EFAULT; 1430 + goto err_idr; 1431 + } 1432 + 1433 + down(&file->mutex); 1434 + list_add_tail(&uobj->list, &file->ucontext->ah_list); 1435 + up(&file->mutex); 1436 + 1437 + up(&ib_uverbs_idr_mutex); 1438 + 1439 + return in_len; 1440 + 1441 + err_idr: 1442 + idr_remove(&ib_uverbs_ah_idr, uobj->id); 1443 + 1444 + err_destroy: 1445 + ib_destroy_ah(ah); 1446 + 1447 + err_up: 1448 + up(&ib_uverbs_idr_mutex); 1449 + 1450 + kfree(uobj); 1451 + return ret; 1452 + } 1453 + 1454 + ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file, 1455 + const char __user *buf, int in_len, int out_len) 1456 + { 1457 + struct ib_uverbs_destroy_ah cmd; 1458 + struct ib_ah *ah; 1459 + struct ib_uobject *uobj; 1460 + int ret = -EINVAL; 1461 + 1462 + if (copy_from_user(&cmd, buf, sizeof cmd)) 1463 + return -EFAULT; 1464 + 1465 + down(&ib_uverbs_idr_mutex); 1466 + 1467 + ah = idr_find(&ib_uverbs_ah_idr, cmd.ah_handle); 1468 + if (!ah || ah->uobject->context != file->ucontext) 1469 + goto out; 1470 + 1471 + uobj = ah->uobject; 1472 + 1473 + ret = ib_destroy_ah(ah); 1474 + if (ret) 1475 + goto out; 1476 + 1477 + idr_remove(&ib_uverbs_ah_idr, cmd.ah_handle); 1478 + 1479 + down(&file->mutex); 1480 + list_del(&uobj->list); 1481 + up(&file->mutex); 1482 + 1483 + kfree(uobj); 1064 1484 1065 1485 out: 1066 1486 up(&ib_uverbs_idr_mutex); ··· 1652 1148 1653 1149 resp.srq_handle = uobj->uobject.id; 1654 1150 1655 - down(&file->mutex); 1656 - list_add_tail(&uobj->uobject.list, &file->ucontext->srq_list); 1657 - up(&file->mutex); 1658 - 1659 1151 if (copy_to_user((void __user *) (unsigned long) cmd.response, 1660 1152 &resp, sizeof resp)) { 1661 1153 ret = -EFAULT; 1662 - goto err_list; 1154 + goto err_idr; 1663 1155 } 1156 + 1157 + down(&file->mutex); 1158 + list_add_tail(&uobj->uobject.list, &file->ucontext->srq_list); 1159 + up(&file->mutex); 1664 1160 1665 1161 up(&ib_uverbs_idr_mutex); 1666 1162 1667 1163 return in_len; 1668 1164 1669 - err_list: 1670 - down(&file->mutex); 1671 - list_del(&uobj->uobject.list); 1672 - up(&file->mutex); 1165 + err_idr: 1166 + idr_remove(&ib_uverbs_srq_idr, uobj->uobject.id); 1673 1167 1674 1168 err_destroy: 1675 1169 ib_destroy_srq(srq); ··· 1719 1217 struct ib_uverbs_destroy_srq_resp resp; 1720 1218 struct ib_srq *srq; 1721 1219 struct ib_uevent_object *uobj; 1722 - struct ib_uverbs_event *evt, *tmp; 1723 1220 int ret = -EINVAL; 1724 1221 1725 1222 if (copy_from_user(&cmd, buf, sizeof cmd)) ··· 1744 1243 list_del(&uobj->uobject.list); 1745 1244 up(&file->mutex); 1746 1245 1747 - spin_lock_irq(&file->async_file.lock); 1748 - list_for_each_entry_safe(evt, tmp, &uobj->event_list, obj_list) { 1749 - list_del(&evt->list); 1750 - kfree(evt); 1751 - } 1752 - spin_unlock_irq(&file->async_file.lock); 1246 + ib_uverbs_release_uevent(file, uobj); 1753 1247 1754 1248 resp.events_reported = uobj->events_reported; 1755 1249
+323 -184
drivers/infiniband/core/uverbs_main.c
··· 3 3 * Copyright (c) 2005 Cisco Systems. All rights reserved. 4 4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 5 5 * Copyright (c) 2005 Voltaire, Inc. All rights reserved. 6 + * Copyright (c) 2005 PathScale, Inc. All rights reserved. 6 7 * 7 8 * This software is available to you under a choice of one of two 8 9 * licenses. You may choose to be licensed under the terms of the GNU ··· 44 43 #include <linux/poll.h> 45 44 #include <linux/file.h> 46 45 #include <linux/mount.h> 46 + #include <linux/cdev.h> 47 47 48 48 #include <asm/uaccess.h> 49 49 ··· 64 62 65 63 #define IB_UVERBS_BASE_DEV MKDEV(IB_UVERBS_MAJOR, IB_UVERBS_BASE_MINOR) 66 64 65 + static struct class *uverbs_class; 66 + 67 67 DECLARE_MUTEX(ib_uverbs_idr_mutex); 68 68 DEFINE_IDR(ib_uverbs_pd_idr); 69 69 DEFINE_IDR(ib_uverbs_mr_idr); ··· 76 72 DEFINE_IDR(ib_uverbs_srq_idr); 77 73 78 74 static spinlock_t map_lock; 75 + static struct ib_uverbs_device *dev_table[IB_UVERBS_MAX_DEVICES]; 79 76 static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES); 80 77 81 78 static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file, 82 79 const char __user *buf, int in_len, 83 80 int out_len) = { 84 - [IB_USER_VERBS_CMD_QUERY_PARAMS] = ib_uverbs_query_params, 85 - [IB_USER_VERBS_CMD_GET_CONTEXT] = ib_uverbs_get_context, 86 - [IB_USER_VERBS_CMD_QUERY_DEVICE] = ib_uverbs_query_device, 87 - [IB_USER_VERBS_CMD_QUERY_PORT] = ib_uverbs_query_port, 88 - [IB_USER_VERBS_CMD_QUERY_GID] = ib_uverbs_query_gid, 89 - [IB_USER_VERBS_CMD_QUERY_PKEY] = ib_uverbs_query_pkey, 90 - [IB_USER_VERBS_CMD_ALLOC_PD] = ib_uverbs_alloc_pd, 91 - [IB_USER_VERBS_CMD_DEALLOC_PD] = ib_uverbs_dealloc_pd, 92 - [IB_USER_VERBS_CMD_REG_MR] = ib_uverbs_reg_mr, 93 - [IB_USER_VERBS_CMD_DEREG_MR] = ib_uverbs_dereg_mr, 94 - [IB_USER_VERBS_CMD_CREATE_CQ] = ib_uverbs_create_cq, 95 - [IB_USER_VERBS_CMD_DESTROY_CQ] = ib_uverbs_destroy_cq, 96 - [IB_USER_VERBS_CMD_CREATE_QP] = ib_uverbs_create_qp, 97 - [IB_USER_VERBS_CMD_MODIFY_QP] = ib_uverbs_modify_qp, 98 - [IB_USER_VERBS_CMD_DESTROY_QP] = ib_uverbs_destroy_qp, 99 - [IB_USER_VERBS_CMD_ATTACH_MCAST] = ib_uverbs_attach_mcast, 100 - [IB_USER_VERBS_CMD_DETACH_MCAST] = ib_uverbs_detach_mcast, 101 - [IB_USER_VERBS_CMD_CREATE_SRQ] = ib_uverbs_create_srq, 102 - [IB_USER_VERBS_CMD_MODIFY_SRQ] = ib_uverbs_modify_srq, 103 - [IB_USER_VERBS_CMD_DESTROY_SRQ] = ib_uverbs_destroy_srq, 81 + [IB_USER_VERBS_CMD_GET_CONTEXT] = ib_uverbs_get_context, 82 + [IB_USER_VERBS_CMD_QUERY_DEVICE] = ib_uverbs_query_device, 83 + [IB_USER_VERBS_CMD_QUERY_PORT] = ib_uverbs_query_port, 84 + [IB_USER_VERBS_CMD_ALLOC_PD] = ib_uverbs_alloc_pd, 85 + [IB_USER_VERBS_CMD_DEALLOC_PD] = ib_uverbs_dealloc_pd, 86 + [IB_USER_VERBS_CMD_REG_MR] = ib_uverbs_reg_mr, 87 + [IB_USER_VERBS_CMD_DEREG_MR] = ib_uverbs_dereg_mr, 88 + [IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL] = ib_uverbs_create_comp_channel, 89 + [IB_USER_VERBS_CMD_CREATE_CQ] = ib_uverbs_create_cq, 90 + [IB_USER_VERBS_CMD_POLL_CQ] = ib_uverbs_poll_cq, 91 + [IB_USER_VERBS_CMD_REQ_NOTIFY_CQ] = ib_uverbs_req_notify_cq, 92 + [IB_USER_VERBS_CMD_DESTROY_CQ] = ib_uverbs_destroy_cq, 93 + [IB_USER_VERBS_CMD_CREATE_QP] = ib_uverbs_create_qp, 94 + [IB_USER_VERBS_CMD_MODIFY_QP] = ib_uverbs_modify_qp, 95 + [IB_USER_VERBS_CMD_DESTROY_QP] = ib_uverbs_destroy_qp, 96 + [IB_USER_VERBS_CMD_POST_SEND] = ib_uverbs_post_send, 97 + [IB_USER_VERBS_CMD_POST_RECV] = ib_uverbs_post_recv, 98 + [IB_USER_VERBS_CMD_POST_SRQ_RECV] = ib_uverbs_post_srq_recv, 99 + [IB_USER_VERBS_CMD_CREATE_AH] = ib_uverbs_create_ah, 100 + [IB_USER_VERBS_CMD_DESTROY_AH] = ib_uverbs_destroy_ah, 101 + [IB_USER_VERBS_CMD_ATTACH_MCAST] = ib_uverbs_attach_mcast, 102 + [IB_USER_VERBS_CMD_DETACH_MCAST] = ib_uverbs_detach_mcast, 103 + [IB_USER_VERBS_CMD_CREATE_SRQ] = ib_uverbs_create_srq, 104 + [IB_USER_VERBS_CMD_MODIFY_SRQ] = ib_uverbs_modify_srq, 105 + [IB_USER_VERBS_CMD_DESTROY_SRQ] = ib_uverbs_destroy_srq, 104 106 }; 105 107 106 108 static struct vfsmount *uverbs_event_mnt; ··· 114 104 static void ib_uverbs_add_one(struct ib_device *device); 115 105 static void ib_uverbs_remove_one(struct ib_device *device); 116 106 117 - static int ib_dealloc_ucontext(struct ib_ucontext *context) 107 + static void ib_uverbs_release_dev(struct kref *ref) 108 + { 109 + struct ib_uverbs_device *dev = 110 + container_of(ref, struct ib_uverbs_device, ref); 111 + 112 + kfree(dev); 113 + } 114 + 115 + void ib_uverbs_release_ucq(struct ib_uverbs_file *file, 116 + struct ib_uverbs_event_file *ev_file, 117 + struct ib_ucq_object *uobj) 118 + { 119 + struct ib_uverbs_event *evt, *tmp; 120 + 121 + if (ev_file) { 122 + spin_lock_irq(&ev_file->lock); 123 + list_for_each_entry_safe(evt, tmp, &uobj->comp_list, obj_list) { 124 + list_del(&evt->list); 125 + kfree(evt); 126 + } 127 + spin_unlock_irq(&ev_file->lock); 128 + 129 + kref_put(&ev_file->ref, ib_uverbs_release_event_file); 130 + } 131 + 132 + spin_lock_irq(&file->async_file->lock); 133 + list_for_each_entry_safe(evt, tmp, &uobj->async_list, obj_list) { 134 + list_del(&evt->list); 135 + kfree(evt); 136 + } 137 + spin_unlock_irq(&file->async_file->lock); 138 + } 139 + 140 + void ib_uverbs_release_uevent(struct ib_uverbs_file *file, 141 + struct ib_uevent_object *uobj) 142 + { 143 + struct ib_uverbs_event *evt, *tmp; 144 + 145 + spin_lock_irq(&file->async_file->lock); 146 + list_for_each_entry_safe(evt, tmp, &uobj->event_list, obj_list) { 147 + list_del(&evt->list); 148 + kfree(evt); 149 + } 150 + spin_unlock_irq(&file->async_file->lock); 151 + } 152 + 153 + static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file, 154 + struct ib_ucontext *context) 118 155 { 119 156 struct ib_uobject *uobj, *tmp; 120 157 ··· 170 113 171 114 down(&ib_uverbs_idr_mutex); 172 115 173 - /* XXX Free AHs */ 116 + list_for_each_entry_safe(uobj, tmp, &context->ah_list, list) { 117 + struct ib_ah *ah = idr_find(&ib_uverbs_ah_idr, uobj->id); 118 + idr_remove(&ib_uverbs_ah_idr, uobj->id); 119 + ib_destroy_ah(ah); 120 + list_del(&uobj->list); 121 + kfree(uobj); 122 + } 174 123 175 124 list_for_each_entry_safe(uobj, tmp, &context->qp_list, list) { 176 125 struct ib_qp *qp = idr_find(&ib_uverbs_qp_idr, uobj->id); 126 + struct ib_uevent_object *uevent = 127 + container_of(uobj, struct ib_uevent_object, uobject); 177 128 idr_remove(&ib_uverbs_qp_idr, uobj->id); 178 129 ib_destroy_qp(qp); 179 130 list_del(&uobj->list); 180 - kfree(container_of(uobj, struct ib_uevent_object, uobject)); 131 + ib_uverbs_release_uevent(file, uevent); 132 + kfree(uevent); 181 133 } 182 134 183 135 list_for_each_entry_safe(uobj, tmp, &context->cq_list, list) { 184 136 struct ib_cq *cq = idr_find(&ib_uverbs_cq_idr, uobj->id); 137 + struct ib_uverbs_event_file *ev_file = cq->cq_context; 138 + struct ib_ucq_object *ucq = 139 + container_of(uobj, struct ib_ucq_object, uobject); 185 140 idr_remove(&ib_uverbs_cq_idr, uobj->id); 186 141 ib_destroy_cq(cq); 187 142 list_del(&uobj->list); 188 - kfree(container_of(uobj, struct ib_ucq_object, uobject)); 143 + ib_uverbs_release_ucq(file, ev_file, ucq); 144 + kfree(ucq); 189 145 } 190 146 191 147 list_for_each_entry_safe(uobj, tmp, &context->srq_list, list) { 192 148 struct ib_srq *srq = idr_find(&ib_uverbs_srq_idr, uobj->id); 149 + struct ib_uevent_object *uevent = 150 + container_of(uobj, struct ib_uevent_object, uobject); 193 151 idr_remove(&ib_uverbs_srq_idr, uobj->id); 194 152 ib_destroy_srq(srq); 195 153 list_del(&uobj->list); 196 - kfree(container_of(uobj, struct ib_uevent_object, uobject)); 154 + ib_uverbs_release_uevent(file, uevent); 155 + kfree(uevent); 197 156 } 198 157 199 158 /* XXX Free MWs */ ··· 248 175 container_of(ref, struct ib_uverbs_file, ref); 249 176 250 177 module_put(file->device->ib_dev->owner); 178 + kref_put(&file->device->ref, ib_uverbs_release_dev); 179 + 251 180 kfree(file); 252 181 } 253 182 ··· 263 188 264 189 spin_lock_irq(&file->lock); 265 190 266 - while (list_empty(&file->event_list) && file->fd >= 0) { 191 + while (list_empty(&file->event_list)) { 267 192 spin_unlock_irq(&file->lock); 268 193 269 194 if (filp->f_flags & O_NONBLOCK) 270 195 return -EAGAIN; 271 196 272 197 if (wait_event_interruptible(file->poll_wait, 273 - !list_empty(&file->event_list) || 274 - file->fd < 0)) 198 + !list_empty(&file->event_list))) 275 199 return -ERESTARTSYS; 276 200 277 201 spin_lock_irq(&file->lock); 278 - } 279 - 280 - if (file->fd < 0) { 281 - spin_unlock_irq(&file->lock); 282 - return -ENODEV; 283 202 } 284 203 285 204 event = list_entry(file->event_list.next, struct ib_uverbs_event, list); ··· 317 248 poll_wait(filp, &file->poll_wait, wait); 318 249 319 250 spin_lock_irq(&file->lock); 320 - if (file->fd < 0) 321 - pollflags = POLLERR; 322 - else if (!list_empty(&file->event_list)) 251 + if (!list_empty(&file->event_list)) 323 252 pollflags = POLLIN | POLLRDNORM; 324 253 spin_unlock_irq(&file->lock); 325 254 326 255 return pollflags; 327 256 } 328 257 329 - static void ib_uverbs_event_release(struct ib_uverbs_event_file *file) 258 + void ib_uverbs_release_event_file(struct kref *ref) 330 259 { 331 - struct ib_uverbs_event *entry, *tmp; 260 + struct ib_uverbs_event_file *file = 261 + container_of(ref, struct ib_uverbs_event_file, ref); 332 262 333 - spin_lock_irq(&file->lock); 334 - if (file->fd != -1) { 335 - file->fd = -1; 336 - list_for_each_entry_safe(entry, tmp, &file->event_list, list) 337 - kfree(entry); 338 - } 339 - spin_unlock_irq(&file->lock); 263 + kfree(file); 340 264 } 341 265 342 266 static int ib_uverbs_event_fasync(int fd, struct file *filp, int on) ··· 342 280 static int ib_uverbs_event_close(struct inode *inode, struct file *filp) 343 281 { 344 282 struct ib_uverbs_event_file *file = filp->private_data; 283 + struct ib_uverbs_event *entry, *tmp; 345 284 346 - ib_uverbs_event_release(file); 285 + spin_lock_irq(&file->lock); 286 + file->file = NULL; 287 + list_for_each_entry_safe(entry, tmp, &file->event_list, list) { 288 + if (entry->counter) 289 + list_del(&entry->obj_list); 290 + kfree(entry); 291 + } 292 + spin_unlock_irq(&file->lock); 293 + 347 294 ib_uverbs_event_fasync(-1, filp, 0); 348 - kref_put(&file->uverbs_file->ref, ib_uverbs_release_file); 295 + 296 + if (file->is_async) { 297 + ib_unregister_event_handler(&file->uverbs_file->event_handler); 298 + kref_put(&file->uverbs_file->ref, ib_uverbs_release_file); 299 + } 300 + kref_put(&file->ref, ib_uverbs_release_event_file); 349 301 350 302 return 0; 351 303 } 352 304 353 305 static struct file_operations uverbs_event_fops = { 354 - /* 355 - * No .owner field since we artificially create event files, 356 - * so there is no increment to the module reference count in 357 - * the open path. All event files come from a uverbs command 358 - * file, which already takes a module reference, so this is OK. 359 - */ 306 + .owner = THIS_MODULE, 360 307 .read = ib_uverbs_event_read, 361 308 .poll = ib_uverbs_event_poll, 362 309 .release = ib_uverbs_event_close, ··· 374 303 375 304 void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context) 376 305 { 377 - struct ib_uverbs_file *file = cq_context; 378 - struct ib_ucq_object *uobj; 379 - struct ib_uverbs_event *entry; 380 - unsigned long flags; 306 + struct ib_uverbs_event_file *file = cq_context; 307 + struct ib_ucq_object *uobj; 308 + struct ib_uverbs_event *entry; 309 + unsigned long flags; 310 + 311 + if (!file) 312 + return; 313 + 314 + spin_lock_irqsave(&file->lock, flags); 315 + if (!file->file) { 316 + spin_unlock_irqrestore(&file->lock, flags); 317 + return; 318 + } 381 319 382 320 entry = kmalloc(sizeof *entry, GFP_ATOMIC); 383 - if (!entry) 321 + if (!entry) { 322 + spin_unlock_irqrestore(&file->lock, flags); 384 323 return; 324 + } 385 325 386 326 uobj = container_of(cq->uobject, struct ib_ucq_object, uobject); 387 327 388 328 entry->desc.comp.cq_handle = cq->uobject->user_handle; 389 329 entry->counter = &uobj->comp_events_reported; 390 330 391 - spin_lock_irqsave(&file->comp_file[0].lock, flags); 392 - list_add_tail(&entry->list, &file->comp_file[0].event_list); 331 + list_add_tail(&entry->list, &file->event_list); 393 332 list_add_tail(&entry->obj_list, &uobj->comp_list); 394 - spin_unlock_irqrestore(&file->comp_file[0].lock, flags); 333 + spin_unlock_irqrestore(&file->lock, flags); 395 334 396 - wake_up_interruptible(&file->comp_file[0].poll_wait); 397 - kill_fasync(&file->comp_file[0].async_queue, SIGIO, POLL_IN); 335 + wake_up_interruptible(&file->poll_wait); 336 + kill_fasync(&file->async_queue, SIGIO, POLL_IN); 398 337 } 399 338 400 339 static void ib_uverbs_async_handler(struct ib_uverbs_file *file, ··· 415 334 struct ib_uverbs_event *entry; 416 335 unsigned long flags; 417 336 418 - entry = kmalloc(sizeof *entry, GFP_ATOMIC); 419 - if (!entry) 337 + spin_lock_irqsave(&file->async_file->lock, flags); 338 + if (!file->async_file->file) { 339 + spin_unlock_irqrestore(&file->async_file->lock, flags); 420 340 return; 341 + } 342 + 343 + entry = kmalloc(sizeof *entry, GFP_ATOMIC); 344 + if (!entry) { 345 + spin_unlock_irqrestore(&file->async_file->lock, flags); 346 + return; 347 + } 421 348 422 349 entry->desc.async.element = element; 423 350 entry->desc.async.event_type = event; 424 351 entry->counter = counter; 425 352 426 - spin_lock_irqsave(&file->async_file.lock, flags); 427 - list_add_tail(&entry->list, &file->async_file.event_list); 353 + list_add_tail(&entry->list, &file->async_file->event_list); 428 354 if (obj_list) 429 355 list_add_tail(&entry->obj_list, obj_list); 430 - spin_unlock_irqrestore(&file->async_file.lock, flags); 356 + spin_unlock_irqrestore(&file->async_file->lock, flags); 431 357 432 - wake_up_interruptible(&file->async_file.poll_wait); 433 - kill_fasync(&file->async_file.async_queue, SIGIO, POLL_IN); 358 + wake_up_interruptible(&file->async_file->poll_wait); 359 + kill_fasync(&file->async_file->async_queue, SIGIO, POLL_IN); 434 360 } 435 361 436 362 void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr) 437 363 { 364 + struct ib_uverbs_event_file *ev_file = context_ptr; 438 365 struct ib_ucq_object *uobj; 439 366 440 367 uobj = container_of(event->element.cq->uobject, 441 368 struct ib_ucq_object, uobject); 442 369 443 - ib_uverbs_async_handler(context_ptr, uobj->uobject.user_handle, 370 + ib_uverbs_async_handler(ev_file->uverbs_file, uobj->uobject.user_handle, 444 371 event->event, &uobj->async_list, 445 372 &uobj->async_events_reported); 446 373 ··· 478 389 &uobj->events_reported); 479 390 } 480 391 481 - static void ib_uverbs_event_handler(struct ib_event_handler *handler, 482 - struct ib_event *event) 392 + void ib_uverbs_event_handler(struct ib_event_handler *handler, 393 + struct ib_event *event) 483 394 { 484 395 struct ib_uverbs_file *file = 485 396 container_of(handler, struct ib_uverbs_file, event_handler); ··· 488 399 NULL, NULL); 489 400 } 490 401 491 - static int ib_uverbs_event_init(struct ib_uverbs_event_file *file, 492 - struct ib_uverbs_file *uverbs_file) 402 + struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file, 403 + int is_async, int *fd) 493 404 { 405 + struct ib_uverbs_event_file *ev_file; 494 406 struct file *filp; 407 + int ret; 495 408 496 - spin_lock_init(&file->lock); 497 - INIT_LIST_HEAD(&file->event_list); 498 - init_waitqueue_head(&file->poll_wait); 499 - file->uverbs_file = uverbs_file; 500 - file->async_queue = NULL; 409 + ev_file = kmalloc(sizeof *ev_file, GFP_KERNEL); 410 + if (!ev_file) 411 + return ERR_PTR(-ENOMEM); 501 412 502 - file->fd = get_unused_fd(); 503 - if (file->fd < 0) 504 - return file->fd; 413 + kref_init(&ev_file->ref); 414 + spin_lock_init(&ev_file->lock); 415 + INIT_LIST_HEAD(&ev_file->event_list); 416 + init_waitqueue_head(&ev_file->poll_wait); 417 + ev_file->uverbs_file = uverbs_file; 418 + ev_file->async_queue = NULL; 419 + ev_file->is_async = is_async; 420 + 421 + *fd = get_unused_fd(); 422 + if (*fd < 0) { 423 + ret = *fd; 424 + goto err; 425 + } 505 426 506 427 filp = get_empty_filp(); 507 428 if (!filp) { 508 - put_unused_fd(file->fd); 509 - return -ENFILE; 429 + ret = -ENFILE; 430 + goto err_fd; 510 431 } 511 432 512 - filp->f_op = &uverbs_event_fops; 433 + ev_file->file = filp; 434 + 435 + /* 436 + * fops_get() can't fail here, because we're coming from a 437 + * system call on a uverbs file, which will already have a 438 + * module reference. 439 + */ 440 + filp->f_op = fops_get(&uverbs_event_fops); 513 441 filp->f_vfsmnt = mntget(uverbs_event_mnt); 514 442 filp->f_dentry = dget(uverbs_event_mnt->mnt_root); 515 443 filp->f_mapping = filp->f_dentry->d_inode->i_mapping; 516 444 filp->f_flags = O_RDONLY; 517 445 filp->f_mode = FMODE_READ; 518 - filp->private_data = file; 446 + filp->private_data = ev_file; 519 447 520 - fd_install(file->fd, filp); 448 + return filp; 521 449 522 - return 0; 450 + err_fd: 451 + put_unused_fd(*fd); 452 + 453 + err: 454 + kfree(ev_file); 455 + return ERR_PTR(ret); 456 + } 457 + 458 + /* 459 + * Look up a completion event file by FD. If lookup is successful, 460 + * takes a ref to the event file struct that it returns; if 461 + * unsuccessful, returns NULL. 462 + */ 463 + struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd) 464 + { 465 + struct ib_uverbs_event_file *ev_file = NULL; 466 + struct file *filp; 467 + 468 + filp = fget(fd); 469 + if (!filp) 470 + return NULL; 471 + 472 + if (filp->f_op != &uverbs_event_fops) 473 + goto out; 474 + 475 + ev_file = filp->private_data; 476 + if (ev_file->is_async) { 477 + ev_file = NULL; 478 + goto out; 479 + } 480 + 481 + kref_get(&ev_file->ref); 482 + 483 + out: 484 + fput(filp); 485 + return ev_file; 523 486 } 524 487 525 488 static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, ··· 591 450 592 451 if (hdr.command < 0 || 593 452 hdr.command >= ARRAY_SIZE(uverbs_cmd_table) || 594 - !uverbs_cmd_table[hdr.command]) 453 + !uverbs_cmd_table[hdr.command] || 454 + !(file->device->ib_dev->uverbs_cmd_mask & (1ull << hdr.command))) 595 455 return -EINVAL; 596 456 597 - if (!file->ucontext && 598 - hdr.command != IB_USER_VERBS_CMD_QUERY_PARAMS && 457 + if (!file->ucontext && 599 458 hdr.command != IB_USER_VERBS_CMD_GET_CONTEXT) 600 459 return -EINVAL; 601 460 ··· 615 474 616 475 static int ib_uverbs_open(struct inode *inode, struct file *filp) 617 476 { 618 - struct ib_uverbs_device *dev = 619 - container_of(inode->i_cdev, struct ib_uverbs_device, dev); 477 + struct ib_uverbs_device *dev; 620 478 struct ib_uverbs_file *file; 621 - int i = 0; 622 479 int ret; 623 480 624 - if (!try_module_get(dev->ib_dev->owner)) 625 - return -ENODEV; 481 + spin_lock(&map_lock); 482 + dev = dev_table[iminor(inode) - IB_UVERBS_BASE_MINOR]; 483 + if (dev) 484 + kref_get(&dev->ref); 485 + spin_unlock(&map_lock); 626 486 627 - file = kmalloc(sizeof *file + 628 - (dev->num_comp - 1) * sizeof (struct ib_uverbs_event_file), 629 - GFP_KERNEL); 630 - if (!file) { 631 - ret = -ENOMEM; 487 + if (!dev) 488 + return -ENXIO; 489 + 490 + if (!try_module_get(dev->ib_dev->owner)) { 491 + ret = -ENODEV; 632 492 goto err; 633 493 } 634 494 635 - file->device = dev; 495 + file = kmalloc(sizeof *file, GFP_KERNEL); 496 + if (!file) { 497 + ret = -ENOMEM; 498 + goto err_module; 499 + } 500 + 501 + file->device = dev; 502 + file->ucontext = NULL; 503 + file->async_file = NULL; 636 504 kref_init(&file->ref); 637 505 init_MUTEX(&file->mutex); 638 506 639 - file->ucontext = NULL; 640 - 641 - kref_get(&file->ref); 642 - ret = ib_uverbs_event_init(&file->async_file, file); 643 - if (ret) 644 - goto err_kref; 645 - 646 - file->async_file.is_async = 1; 647 - 648 - for (i = 0; i < dev->num_comp; ++i) { 649 - kref_get(&file->ref); 650 - ret = ib_uverbs_event_init(&file->comp_file[i], file); 651 - if (ret) 652 - goto err_async; 653 - file->comp_file[i].is_async = 0; 654 - } 655 - 656 - 657 507 filp->private_data = file; 658 - 659 - INIT_IB_EVENT_HANDLER(&file->event_handler, dev->ib_dev, 660 - ib_uverbs_event_handler); 661 - if (ib_register_event_handler(&file->event_handler)) 662 - goto err_async; 663 508 664 509 return 0; 665 510 666 - err_async: 667 - while (i--) 668 - ib_uverbs_event_release(&file->comp_file[i]); 669 - 670 - ib_uverbs_event_release(&file->async_file); 671 - 672 - err_kref: 673 - /* 674 - * One extra kref_put() because we took a reference before the 675 - * event file creation that failed and got us here. 676 - */ 677 - kref_put(&file->ref, ib_uverbs_release_file); 678 - kref_put(&file->ref, ib_uverbs_release_file); 511 + err_module: 512 + module_put(dev->ib_dev->owner); 679 513 680 514 err: 681 - module_put(dev->ib_dev->owner); 515 + kref_put(&dev->ref, ib_uverbs_release_dev); 516 + 682 517 return ret; 683 518 } 684 519 685 520 static int ib_uverbs_close(struct inode *inode, struct file *filp) 686 521 { 687 522 struct ib_uverbs_file *file = filp->private_data; 688 - int i; 689 523 690 - ib_unregister_event_handler(&file->event_handler); 691 - ib_uverbs_event_release(&file->async_file); 692 - ib_dealloc_ucontext(file->ucontext); 524 + ib_uverbs_cleanup_ucontext(file, file->ucontext); 693 525 694 - for (i = 0; i < file->device->num_comp; ++i) 695 - ib_uverbs_event_release(&file->comp_file[i]); 526 + if (file->async_file) 527 + kref_put(&file->async_file->ref, ib_uverbs_release_event_file); 696 528 697 529 kref_put(&file->ref, ib_uverbs_release_file); 698 530 ··· 695 581 696 582 static ssize_t show_ibdev(struct class_device *class_dev, char *buf) 697 583 { 698 - struct ib_uverbs_device *dev = 699 - container_of(class_dev, struct ib_uverbs_device, class_dev); 584 + struct ib_uverbs_device *dev = class_get_devdata(class_dev); 585 + 586 + if (!dev) 587 + return -ENODEV; 700 588 701 589 return sprintf(buf, "%s\n", dev->ib_dev->name); 702 590 } 703 591 static CLASS_DEVICE_ATTR(ibdev, S_IRUGO, show_ibdev, NULL); 704 592 705 - static void ib_uverbs_release_class_dev(struct class_device *class_dev) 593 + static ssize_t show_dev_abi_version(struct class_device *class_dev, char *buf) 706 594 { 707 - struct ib_uverbs_device *dev = 708 - container_of(class_dev, struct ib_uverbs_device, class_dev); 595 + struct ib_uverbs_device *dev = class_get_devdata(class_dev); 709 596 710 - cdev_del(&dev->dev); 711 - clear_bit(dev->devnum, dev_map); 712 - kfree(dev); 597 + if (!dev) 598 + return -ENODEV; 599 + 600 + return sprintf(buf, "%d\n", dev->ib_dev->uverbs_abi_ver); 713 601 } 714 - 715 - static struct class uverbs_class = { 716 - .name = "infiniband_verbs", 717 - .release = ib_uverbs_release_class_dev 718 - }; 602 + static CLASS_DEVICE_ATTR(abi_version, S_IRUGO, show_dev_abi_version, NULL); 719 603 720 604 static ssize_t show_abi_version(struct class *class, char *buf) 721 605 { ··· 734 622 735 623 memset(uverbs_dev, 0, sizeof *uverbs_dev); 736 624 625 + kref_init(&uverbs_dev->ref); 626 + 737 627 spin_lock(&map_lock); 738 628 uverbs_dev->devnum = find_first_zero_bit(dev_map, IB_UVERBS_MAX_DEVICES); 739 629 if (uverbs_dev->devnum >= IB_UVERBS_MAX_DEVICES) { ··· 745 631 set_bit(uverbs_dev->devnum, dev_map); 746 632 spin_unlock(&map_lock); 747 633 748 - uverbs_dev->ib_dev = device; 749 - uverbs_dev->num_comp = 1; 634 + uverbs_dev->ib_dev = device; 635 + uverbs_dev->num_comp_vectors = 1; 750 636 751 - if (device->mmap) 752 - cdev_init(&uverbs_dev->dev, &uverbs_mmap_fops); 753 - else 754 - cdev_init(&uverbs_dev->dev, &uverbs_fops); 755 - uverbs_dev->dev.owner = THIS_MODULE; 756 - kobject_set_name(&uverbs_dev->dev.kobj, "uverbs%d", uverbs_dev->devnum); 757 - if (cdev_add(&uverbs_dev->dev, IB_UVERBS_BASE_DEV + uverbs_dev->devnum, 1)) 637 + uverbs_dev->dev = cdev_alloc(); 638 + if (!uverbs_dev->dev) 758 639 goto err; 759 - 760 - uverbs_dev->class_dev.class = &uverbs_class; 761 - uverbs_dev->class_dev.dev = device->dma_device; 762 - uverbs_dev->class_dev.devt = uverbs_dev->dev.dev; 763 - snprintf(uverbs_dev->class_dev.class_id, BUS_ID_SIZE, "uverbs%d", uverbs_dev->devnum); 764 - if (class_device_register(&uverbs_dev->class_dev)) 640 + uverbs_dev->dev->owner = THIS_MODULE; 641 + uverbs_dev->dev->ops = device->mmap ? &uverbs_mmap_fops : &uverbs_fops; 642 + kobject_set_name(&uverbs_dev->dev->kobj, "uverbs%d", uverbs_dev->devnum); 643 + if (cdev_add(uverbs_dev->dev, IB_UVERBS_BASE_DEV + uverbs_dev->devnum, 1)) 765 644 goto err_cdev; 766 645 767 - if (class_device_create_file(&uverbs_dev->class_dev, &class_device_attr_ibdev)) 646 + uverbs_dev->class_dev = class_device_create(uverbs_class, NULL, 647 + uverbs_dev->dev->dev, 648 + device->dma_device, 649 + "uverbs%d", uverbs_dev->devnum); 650 + if (IS_ERR(uverbs_dev->class_dev)) 651 + goto err_cdev; 652 + 653 + class_set_devdata(uverbs_dev->class_dev, uverbs_dev); 654 + 655 + if (class_device_create_file(uverbs_dev->class_dev, &class_device_attr_ibdev)) 768 656 goto err_class; 657 + if (class_device_create_file(uverbs_dev->class_dev, &class_device_attr_abi_version)) 658 + goto err_class; 659 + 660 + spin_lock(&map_lock); 661 + dev_table[uverbs_dev->devnum] = uverbs_dev; 662 + spin_unlock(&map_lock); 769 663 770 664 ib_set_client_data(device, &uverbs_client, uverbs_dev); 771 665 772 666 return; 773 667 774 668 err_class: 775 - class_device_unregister(&uverbs_dev->class_dev); 669 + class_device_destroy(uverbs_class, uverbs_dev->dev->dev); 776 670 777 671 err_cdev: 778 - cdev_del(&uverbs_dev->dev); 672 + cdev_del(uverbs_dev->dev); 779 673 clear_bit(uverbs_dev->devnum, dev_map); 780 674 781 675 err: 782 - kfree(uverbs_dev); 676 + kref_put(&uverbs_dev->ref, ib_uverbs_release_dev); 783 677 return; 784 678 } 785 679 ··· 798 676 if (!uverbs_dev) 799 677 return; 800 678 801 - class_device_unregister(&uverbs_dev->class_dev); 679 + class_set_devdata(uverbs_dev->class_dev, NULL); 680 + class_device_destroy(uverbs_class, uverbs_dev->dev->dev); 681 + cdev_del(uverbs_dev->dev); 682 + 683 + spin_lock(&map_lock); 684 + dev_table[uverbs_dev->devnum] = NULL; 685 + spin_unlock(&map_lock); 686 + 687 + clear_bit(uverbs_dev->devnum, dev_map); 688 + kref_put(&uverbs_dev->ref, ib_uverbs_release_dev); 802 689 } 803 690 804 691 static struct super_block *uverbs_event_get_sb(struct file_system_type *fs_type, int flags, ··· 837 706 goto out; 838 707 } 839 708 840 - ret = class_register(&uverbs_class); 841 - if (ret) { 709 + uverbs_class = class_create(THIS_MODULE, "infiniband_verbs"); 710 + if (IS_ERR(uverbs_class)) { 711 + ret = PTR_ERR(uverbs_class); 842 712 printk(KERN_ERR "user_verbs: couldn't create class infiniband_verbs\n"); 843 713 goto out_chrdev; 844 714 } 845 715 846 - ret = class_create_file(&uverbs_class, &class_attr_abi_version); 716 + ret = class_create_file(uverbs_class, &class_attr_abi_version); 847 717 if (ret) { 848 718 printk(KERN_ERR "user_verbs: couldn't create abi_version attribute\n"); 849 719 goto out_class; ··· 878 746 unregister_filesystem(&uverbs_event_fs); 879 747 880 748 out_class: 881 - class_unregister(&uverbs_class); 749 + class_destroy(uverbs_class); 882 750 883 751 out_chrdev: 884 752 unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES); ··· 892 760 ib_unregister_client(&uverbs_client); 893 761 mntput(uverbs_event_mnt); 894 762 unregister_filesystem(&uverbs_event_fs); 895 - class_unregister(&uverbs_class); 763 + class_destroy(uverbs_class); 896 764 unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES); 765 + idr_destroy(&ib_uverbs_pd_idr); 766 + idr_destroy(&ib_uverbs_mr_idr); 767 + idr_destroy(&ib_uverbs_mw_idr); 768 + idr_destroy(&ib_uverbs_ah_idr); 769 + idr_destroy(&ib_uverbs_cq_idr); 770 + idr_destroy(&ib_uverbs_qp_idr); 771 + idr_destroy(&ib_uverbs_srq_idr); 897 772 } 898 773 899 774 module_init(ib_uverbs_init);
+12 -6
drivers/infiniband/core/verbs.c
··· 523 523 524 524 int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid) 525 525 { 526 - return qp->device->attach_mcast ? 527 - qp->device->attach_mcast(qp, gid, lid) : 528 - -ENOSYS; 526 + if (!qp->device->attach_mcast) 527 + return -ENOSYS; 528 + if (gid->raw[0] != 0xff || qp->qp_type != IB_QPT_UD) 529 + return -EINVAL; 530 + 531 + return qp->device->attach_mcast(qp, gid, lid); 529 532 } 530 533 EXPORT_SYMBOL(ib_attach_mcast); 531 534 532 535 int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid) 533 536 { 534 - return qp->device->detach_mcast ? 535 - qp->device->detach_mcast(qp, gid, lid) : 536 - -ENOSYS; 537 + if (!qp->device->detach_mcast) 538 + return -ENOSYS; 539 + if (gid->raw[0] != 0xff || qp->qp_type != IB_QPT_UD) 540 + return -EINVAL; 541 + 542 + return qp->device->detach_mcast(qp, gid, lid); 537 543 } 538 544 EXPORT_SYMBOL(ib_detach_mcast);
+2 -1
drivers/infiniband/hw/mthca/Makefile
··· 7 7 ib_mthca-y := mthca_main.o mthca_cmd.o mthca_profile.o mthca_reset.o \ 8 8 mthca_allocator.o mthca_eq.o mthca_pd.o mthca_cq.o \ 9 9 mthca_mr.o mthca_qp.o mthca_av.o mthca_mcg.o mthca_mad.o \ 10 - mthca_provider.o mthca_memfree.o mthca_uar.o mthca_srq.o 10 + mthca_provider.o mthca_memfree.o mthca_uar.o mthca_srq.o \ 11 + mthca_catas.o
+153
drivers/infiniband/hw/mthca/mthca_catas.c
··· 1 + /* 2 + * Copyright (c) 2005 Cisco Systems. All rights reserved. 3 + * 4 + * This software is available to you under a choice of one of two 5 + * licenses. You may choose to be licensed under the terms of the GNU 6 + * General Public License (GPL) Version 2, available from the file 7 + * COPYING in the main directory of this source tree, or the 8 + * OpenIB.org BSD license below: 9 + * 10 + * Redistribution and use in source and binary forms, with or 11 + * without modification, are permitted provided that the following 12 + * conditions are met: 13 + * 14 + * - Redistributions of source code must retain the above 15 + * copyright notice, this list of conditions and the following 16 + * disclaimer. 17 + * 18 + * - Redistributions in binary form must reproduce the above 19 + * copyright notice, this list of conditions and the following 20 + * disclaimer in the documentation and/or other materials 21 + * provided with the distribution. 22 + * 23 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 + * SOFTWARE. 31 + * 32 + * $Id$ 33 + */ 34 + 35 + #include "mthca_dev.h" 36 + 37 + enum { 38 + MTHCA_CATAS_POLL_INTERVAL = 5 * HZ, 39 + 40 + MTHCA_CATAS_TYPE_INTERNAL = 0, 41 + MTHCA_CATAS_TYPE_UPLINK = 3, 42 + MTHCA_CATAS_TYPE_DDR = 4, 43 + MTHCA_CATAS_TYPE_PARITY = 5, 44 + }; 45 + 46 + static DEFINE_SPINLOCK(catas_lock); 47 + 48 + static void handle_catas(struct mthca_dev *dev) 49 + { 50 + struct ib_event event; 51 + const char *type; 52 + int i; 53 + 54 + event.device = &dev->ib_dev; 55 + event.event = IB_EVENT_DEVICE_FATAL; 56 + event.element.port_num = 0; 57 + 58 + ib_dispatch_event(&event); 59 + 60 + switch (swab32(readl(dev->catas_err.map)) >> 24) { 61 + case MTHCA_CATAS_TYPE_INTERNAL: 62 + type = "internal error"; 63 + break; 64 + case MTHCA_CATAS_TYPE_UPLINK: 65 + type = "uplink bus error"; 66 + break; 67 + case MTHCA_CATAS_TYPE_DDR: 68 + type = "DDR data error"; 69 + break; 70 + case MTHCA_CATAS_TYPE_PARITY: 71 + type = "internal parity error"; 72 + break; 73 + default: 74 + type = "unknown error"; 75 + break; 76 + } 77 + 78 + mthca_err(dev, "Catastrophic error detected: %s\n", type); 79 + for (i = 0; i < dev->catas_err.size; ++i) 80 + mthca_err(dev, " buf[%02x]: %08x\n", 81 + i, swab32(readl(dev->catas_err.map + i))); 82 + } 83 + 84 + static void poll_catas(unsigned long dev_ptr) 85 + { 86 + struct mthca_dev *dev = (struct mthca_dev *) dev_ptr; 87 + unsigned long flags; 88 + int i; 89 + 90 + for (i = 0; i < dev->catas_err.size; ++i) 91 + if (readl(dev->catas_err.map + i)) { 92 + handle_catas(dev); 93 + return; 94 + } 95 + 96 + spin_lock_irqsave(&catas_lock, flags); 97 + if (dev->catas_err.stop) 98 + mod_timer(&dev->catas_err.timer, 99 + jiffies + MTHCA_CATAS_POLL_INTERVAL); 100 + spin_unlock_irqrestore(&catas_lock, flags); 101 + 102 + return; 103 + } 104 + 105 + void mthca_start_catas_poll(struct mthca_dev *dev) 106 + { 107 + unsigned long addr; 108 + 109 + init_timer(&dev->catas_err.timer); 110 + dev->catas_err.stop = 0; 111 + dev->catas_err.map = NULL; 112 + 113 + addr = pci_resource_start(dev->pdev, 0) + 114 + ((pci_resource_len(dev->pdev, 0) - 1) & 115 + dev->catas_err.addr); 116 + 117 + if (!request_mem_region(addr, dev->catas_err.size * 4, 118 + DRV_NAME)) { 119 + mthca_warn(dev, "couldn't request catastrophic error region " 120 + "at 0x%lx/0x%x\n", addr, dev->catas_err.size * 4); 121 + return; 122 + } 123 + 124 + dev->catas_err.map = ioremap(addr, dev->catas_err.size * 4); 125 + if (!dev->catas_err.map) { 126 + mthca_warn(dev, "couldn't map catastrophic error region " 127 + "at 0x%lx/0x%x\n", addr, dev->catas_err.size * 4); 128 + release_mem_region(addr, dev->catas_err.size * 4); 129 + return; 130 + } 131 + 132 + dev->catas_err.timer.data = (unsigned long) dev; 133 + dev->catas_err.timer.function = poll_catas; 134 + dev->catas_err.timer.expires = jiffies + MTHCA_CATAS_POLL_INTERVAL; 135 + add_timer(&dev->catas_err.timer); 136 + } 137 + 138 + void mthca_stop_catas_poll(struct mthca_dev *dev) 139 + { 140 + spin_lock_irq(&catas_lock); 141 + dev->catas_err.stop = 1; 142 + spin_unlock_irq(&catas_lock); 143 + 144 + del_timer_sync(&dev->catas_err.timer); 145 + 146 + if (dev->catas_err.map) { 147 + iounmap(dev->catas_err.map); 148 + release_mem_region(pci_resource_start(dev->pdev, 0) + 149 + ((pci_resource_len(dev->pdev, 0) - 1) & 150 + dev->catas_err.addr), 151 + dev->catas_err.size * 4); 152 + } 153 + }
+9 -2
drivers/infiniband/hw/mthca/mthca_cmd.c
··· 1 1 /* 2 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 3 3 * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 4 + * Copyright (c) 2005 Cisco Systems. All rights reserved. 4 5 * 5 6 * This software is available to you under a choice of one of two 6 7 * licenses. You may choose to be licensed under the terms of the GNU ··· 707 706 708 707 MTHCA_GET(lg, outbox, QUERY_FW_MAX_CMD_OFFSET); 709 708 dev->cmd.max_cmds = 1 << lg; 709 + MTHCA_GET(dev->catas_err.addr, outbox, QUERY_FW_ERR_START_OFFSET); 710 + MTHCA_GET(dev->catas_err.size, outbox, QUERY_FW_ERR_SIZE_OFFSET); 710 711 711 712 mthca_dbg(dev, "FW version %012llx, max commands %d\n", 712 713 (unsigned long long) dev->fw_ver, dev->cmd.max_cmds); 714 + mthca_dbg(dev, "Catastrophic error buffer at 0x%llx, size 0x%x\n", 715 + (unsigned long long) dev->catas_err.addr, dev->catas_err.size); 713 716 714 717 if (mthca_is_memfree(dev)) { 715 718 MTHCA_GET(dev->fw.arbel.fw_pages, outbox, QUERY_FW_SIZE_OFFSET); ··· 938 933 goto out; 939 934 940 935 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SRQ_SZ_OFFSET); 941 - dev_lim->max_srq_sz = 1 << field; 936 + dev_lim->max_srq_sz = (1 << field) - 1; 942 937 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_SZ_OFFSET); 943 - dev_lim->max_qp_sz = 1 << field; 938 + dev_lim->max_qp_sz = (1 << field) - 1; 944 939 MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_QP_OFFSET); 945 940 dev_lim->reserved_qps = 1 << (field & 0xf); 946 941 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_OFFSET); ··· 1050 1045 dev_lim->max_pds, dev_lim->reserved_pds, dev_lim->reserved_uars); 1051 1046 mthca_dbg(dev, "Max QP/MCG: %d, reserved MGMs: %d\n", 1052 1047 dev_lim->max_pds, dev_lim->reserved_mgms); 1048 + mthca_dbg(dev, "Max CQEs: %d, max WQEs: %d, max SRQ WQEs: %d\n", 1049 + dev_lim->max_cq_sz, dev_lim->max_qp_sz, dev_lim->max_srq_sz); 1053 1050 1054 1051 mthca_dbg(dev, "Flags: %08x\n", dev_lim->flags); 1055 1052
+22
drivers/infiniband/hw/mthca/mthca_dev.h
··· 83 83 /* Arbel FW gives us these, but we need them for Tavor */ 84 84 MTHCA_MPT_ENTRY_SIZE = 0x40, 85 85 MTHCA_MTT_SEG_SIZE = 0x40, 86 + 87 + MTHCA_QP_PER_MGM = 4 * (MTHCA_MGM_ENTRY_SIZE / 16 - 2) 86 88 }; 87 89 88 90 enum { ··· 130 128 int num_uars; 131 129 int max_sg; 132 130 int num_qps; 131 + int max_wqes; 132 + int max_qp_init_rdma; 133 133 int reserved_qps; 134 134 int num_srqs; 135 + int max_srq_wqes; 135 136 int reserved_srqs; 136 137 int num_eecs; 137 138 int reserved_eecs; 138 139 int num_cqs; 140 + int max_cqes; 139 141 int reserved_cqs; 140 142 int num_eqs; 141 143 int reserved_eqs; ··· 154 148 int reserved_mcgs; 155 149 int num_pds; 156 150 int reserved_pds; 151 + u32 flags; 157 152 u8 port_width_cap; 158 153 }; 159 154 ··· 258 251 struct mthca_icm_table *table; 259 252 }; 260 253 254 + struct mthca_catas_err { 255 + u64 addr; 256 + u32 __iomem *map; 257 + unsigned long stop; 258 + u32 size; 259 + struct timer_list timer; 260 + }; 261 + 261 262 struct mthca_dev { 262 263 struct ib_device ib_dev; 263 264 struct pci_dev *pdev; ··· 325 310 struct mthca_qp_table qp_table; 326 311 struct mthca_av_table av_table; 327 312 struct mthca_mcg_table mcg_table; 313 + 314 + struct mthca_catas_err catas_err; 328 315 329 316 struct mthca_uar driver_uar; 330 317 struct mthca_db_table *db_tab; ··· 415 398 int mthca_register_device(struct mthca_dev *dev); 416 399 void mthca_unregister_device(struct mthca_dev *dev); 417 400 401 + void mthca_start_catas_poll(struct mthca_dev *dev); 402 + void mthca_stop_catas_poll(struct mthca_dev *dev); 403 + 418 404 int mthca_uar_alloc(struct mthca_dev *dev, struct mthca_uar *uar); 419 405 void mthca_uar_free(struct mthca_dev *dev, struct mthca_uar *uar); 420 406 ··· 467 447 int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd, 468 448 struct ib_srq_attr *attr, struct mthca_srq *srq); 469 449 void mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq); 450 + int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, 451 + enum ib_srq_attr_mask attr_mask); 470 452 void mthca_srq_event(struct mthca_dev *dev, u32 srqn, 471 453 enum ib_event_type event_type); 472 454 void mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr);
+18 -3
drivers/infiniband/hw/mthca/mthca_eq.c
··· 83 83 MTHCA_EVENT_TYPE_PATH_MIG = 0x01, 84 84 MTHCA_EVENT_TYPE_COMM_EST = 0x02, 85 85 MTHCA_EVENT_TYPE_SQ_DRAINED = 0x03, 86 - MTHCA_EVENT_TYPE_SRQ_LAST_WQE = 0x13, 86 + MTHCA_EVENT_TYPE_SRQ_QP_LAST_WQE = 0x13, 87 + MTHCA_EVENT_TYPE_SRQ_LIMIT = 0x14, 87 88 MTHCA_EVENT_TYPE_CQ_ERROR = 0x04, 88 89 MTHCA_EVENT_TYPE_WQ_CATAS_ERROR = 0x05, 89 90 MTHCA_EVENT_TYPE_EEC_CATAS_ERROR = 0x06, ··· 111 110 (1ULL << MTHCA_EVENT_TYPE_LOCAL_CATAS_ERROR) | \ 112 111 (1ULL << MTHCA_EVENT_TYPE_PORT_CHANGE) | \ 113 112 (1ULL << MTHCA_EVENT_TYPE_ECC_DETECT)) 114 - #define MTHCA_SRQ_EVENT_MASK (1ULL << MTHCA_EVENT_TYPE_SRQ_CATAS_ERROR) | \ 115 - (1ULL << MTHCA_EVENT_TYPE_SRQ_LAST_WQE) 113 + #define MTHCA_SRQ_EVENT_MASK ((1ULL << MTHCA_EVENT_TYPE_SRQ_CATAS_ERROR) | \ 114 + (1ULL << MTHCA_EVENT_TYPE_SRQ_QP_LAST_WQE) | \ 115 + (1ULL << MTHCA_EVENT_TYPE_SRQ_LIMIT)) 116 116 #define MTHCA_CMD_EVENT_MASK (1ULL << MTHCA_EVENT_TYPE_CMD) 117 117 118 118 #define MTHCA_EQ_DB_INC_CI (1 << 24) ··· 143 141 struct { 144 142 __be32 qpn; 145 143 } __attribute__((packed)) qp; 144 + struct { 145 + __be32 srqn; 146 + } __attribute__((packed)) srq; 146 147 struct { 147 148 __be32 cqn; 148 149 u32 reserved1; ··· 308 303 case MTHCA_EVENT_TYPE_SQ_DRAINED: 309 304 mthca_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff, 310 305 IB_EVENT_SQ_DRAINED); 306 + break; 307 + 308 + case MTHCA_EVENT_TYPE_SRQ_QP_LAST_WQE: 309 + mthca_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff, 310 + IB_EVENT_QP_LAST_WQE_REACHED); 311 + break; 312 + 313 + case MTHCA_EVENT_TYPE_SRQ_LIMIT: 314 + mthca_srq_event(dev, be32_to_cpu(eqe->event.srq.srqn) & 0xffffff, 315 + IB_EVENT_SRQ_LIMIT_REACHED); 311 316 break; 312 317 313 318 case MTHCA_EVENT_TYPE_WQ_CATAS_ERROR:
+9 -63
drivers/infiniband/hw/mthca/mthca_mad.c
··· 46 46 MTHCA_VENDOR_CLASS2 = 0xa 47 47 }; 48 48 49 - struct mthca_trap_mad { 50 - struct ib_mad *mad; 51 - DECLARE_PCI_UNMAP_ADDR(mapping) 52 - }; 53 - 54 49 static void update_sm_ah(struct mthca_dev *dev, 55 50 u8 port_num, u16 lid, u8 sl) 56 51 { ··· 111 116 struct ib_mad *mad) 112 117 { 113 118 int qpn = mad->mad_hdr.mgmt_class != IB_MGMT_CLASS_SUBN_LID_ROUTED; 114 - struct mthca_trap_mad *tmad; 115 - struct ib_sge gather_list; 116 - struct ib_send_wr *bad_wr, wr = { 117 - .opcode = IB_WR_SEND, 118 - .sg_list = &gather_list, 119 - .num_sge = 1, 120 - .send_flags = IB_SEND_SIGNALED, 121 - .wr = { 122 - .ud = { 123 - .remote_qpn = qpn, 124 - .remote_qkey = qpn ? IB_QP1_QKEY : 0, 125 - .timeout_ms = 0 126 - } 127 - } 128 - }; 119 + struct ib_mad_send_buf *send_buf; 129 120 struct ib_mad_agent *agent = dev->send_agent[port_num - 1][qpn]; 130 121 int ret; 131 122 unsigned long flags; 132 123 133 124 if (agent) { 134 - tmad = kmalloc(sizeof *tmad, GFP_KERNEL); 135 - if (!tmad) 136 - return; 137 - 138 - tmad->mad = kmalloc(sizeof *tmad->mad, GFP_KERNEL); 139 - if (!tmad->mad) { 140 - kfree(tmad); 141 - return; 142 - } 143 - 144 - memcpy(tmad->mad, mad, sizeof *mad); 145 - 146 - wr.wr.ud.mad_hdr = &tmad->mad->mad_hdr; 147 - wr.wr_id = (unsigned long) tmad; 148 - 149 - gather_list.addr = dma_map_single(agent->device->dma_device, 150 - tmad->mad, 151 - sizeof *tmad->mad, 152 - DMA_TO_DEVICE); 153 - gather_list.length = sizeof *tmad->mad; 154 - gather_list.lkey = to_mpd(agent->qp->pd)->ntmr.ibmr.lkey; 155 - pci_unmap_addr_set(tmad, mapping, gather_list.addr); 156 - 125 + send_buf = ib_create_send_mad(agent, qpn, 0, 0, IB_MGMT_MAD_HDR, 126 + IB_MGMT_MAD_DATA, GFP_ATOMIC); 157 127 /* 158 128 * We rely here on the fact that MLX QPs don't use the 159 129 * address handle after the send is posted (this is ··· 126 166 * it's OK for our devices). 127 167 */ 128 168 spin_lock_irqsave(&dev->sm_lock, flags); 129 - wr.wr.ud.ah = dev->sm_ah[port_num - 1]; 130 - if (wr.wr.ud.ah) 131 - ret = ib_post_send_mad(agent, &wr, &bad_wr); 169 + memcpy(send_buf->mad, mad, sizeof *mad); 170 + if ((send_buf->ah = dev->sm_ah[port_num - 1])) 171 + ret = ib_post_send_mad(send_buf, NULL); 132 172 else 133 173 ret = -EINVAL; 134 174 spin_unlock_irqrestore(&dev->sm_lock, flags); 135 175 136 - if (ret) { 137 - dma_unmap_single(agent->device->dma_device, 138 - pci_unmap_addr(tmad, mapping), 139 - sizeof *tmad->mad, 140 - DMA_TO_DEVICE); 141 - kfree(tmad->mad); 142 - kfree(tmad); 143 - } 176 + if (ret) 177 + ib_free_send_mad(send_buf); 144 178 } 145 179 } 146 180 ··· 221 267 static void send_handler(struct ib_mad_agent *agent, 222 268 struct ib_mad_send_wc *mad_send_wc) 223 269 { 224 - struct mthca_trap_mad *tmad = 225 - (void *) (unsigned long) mad_send_wc->wr_id; 226 - 227 - dma_unmap_single(agent->device->dma_device, 228 - pci_unmap_addr(tmad, mapping), 229 - sizeof *tmad->mad, 230 - DMA_TO_DEVICE); 231 - kfree(tmad->mad); 232 - kfree(tmad); 270 + ib_free_send_mad(mad_send_wc->send_buf); 233 271 } 234 272 235 273 int mthca_create_agents(struct mthca_dev *dev)
+11
drivers/infiniband/hw/mthca/mthca_main.c
··· 162 162 mdev->limits.pkey_table_len = dev_lim->max_pkeys; 163 163 mdev->limits.local_ca_ack_delay = dev_lim->local_ca_ack_delay; 164 164 mdev->limits.max_sg = dev_lim->max_sg; 165 + mdev->limits.max_wqes = dev_lim->max_qp_sz; 166 + mdev->limits.max_qp_init_rdma = dev_lim->max_requester_per_qp; 165 167 mdev->limits.reserved_qps = dev_lim->reserved_qps; 168 + mdev->limits.max_srq_wqes = dev_lim->max_srq_sz; 166 169 mdev->limits.reserved_srqs = dev_lim->reserved_srqs; 167 170 mdev->limits.reserved_eecs = dev_lim->reserved_eecs; 171 + /* 172 + * Subtract 1 from the limit because we need to allocate a 173 + * spare CQE so the HCA HW can tell the difference between an 174 + * empty CQ and a full CQ. 175 + */ 176 + mdev->limits.max_cqes = dev_lim->max_cq_sz - 1; 168 177 mdev->limits.reserved_cqs = dev_lim->reserved_cqs; 169 178 mdev->limits.reserved_eqs = dev_lim->reserved_eqs; 170 179 mdev->limits.reserved_mtts = dev_lim->reserved_mtts; ··· 181 172 mdev->limits.reserved_uars = dev_lim->reserved_uars; 182 173 mdev->limits.reserved_pds = dev_lim->reserved_pds; 183 174 mdev->limits.port_width_cap = dev_lim->max_port_width; 175 + mdev->limits.flags = dev_lim->flags; 184 176 185 177 /* IB_DEVICE_RESIZE_MAX_WR not supported by driver. 186 178 May be doable since hardware supports it for SRQ. ··· 1196 1186 1197 1187 static struct pci_driver mthca_driver = { 1198 1188 .name = DRV_NAME, 1189 + .owner = THIS_MODULE, 1199 1190 .id_table = mthca_pci_table, 1200 1191 .probe = mthca_init_one, 1201 1192 .remove = __devexit_p(mthca_remove_one)
+6 -5
drivers/infiniband/hw/mthca/mthca_mcg.c
··· 37 37 #include "mthca_dev.h" 38 38 #include "mthca_cmd.h" 39 39 40 - enum { 41 - MTHCA_QP_PER_MGM = 4 * (MTHCA_MGM_ENTRY_SIZE / 16 - 2) 42 - }; 43 - 44 40 struct mthca_mgm { 45 41 __be32 next_gid_index; 46 42 u32 reserved[3]; ··· 185 189 } 186 190 187 191 for (i = 0; i < MTHCA_QP_PER_MGM; ++i) 188 - if (!(mgm->qp[i] & cpu_to_be32(1 << 31))) { 192 + if (mgm->qp[i] == cpu_to_be32(ibqp->qp_num | (1 << 31))) { 193 + mthca_dbg(dev, "QP %06x already a member of MGM\n", 194 + ibqp->qp_num); 195 + err = 0; 196 + goto out; 197 + } else if (!(mgm->qp[i] & cpu_to_be32(1 << 31))) { 189 198 mgm->qp[i] = cpu_to_be32(ibqp->qp_num | (1 << 31)); 190 199 break; 191 200 }
+2 -1
drivers/infiniband/hw/mthca/mthca_memfree.c
··· 487 487 } 488 488 } 489 489 490 - int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, __be32 **db) 490 + int mthca_alloc_db(struct mthca_dev *dev, enum mthca_db_type type, 491 + u32 qn, __be32 **db) 491 492 { 492 493 int group; 493 494 int start, end, dir;
+2 -1
drivers/infiniband/hw/mthca/mthca_memfree.h
··· 173 173 174 174 int mthca_init_db_tab(struct mthca_dev *dev); 175 175 void mthca_cleanup_db_tab(struct mthca_dev *dev); 176 - int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, __be32 **db); 176 + int mthca_alloc_db(struct mthca_dev *dev, enum mthca_db_type type, 177 + u32 qn, __be32 **db); 177 178 void mthca_free_db(struct mthca_dev *dev, int type, int db_index); 178 179 179 180 #endif /* MTHCA_MEMFREE_H */
+46 -3
drivers/infiniband/hw/mthca/mthca_provider.c
··· 37 37 */ 38 38 39 39 #include <rdma/ib_smi.h> 40 + #include <rdma/ib_user_verbs.h> 40 41 #include <linux/mm.h> 41 42 42 43 #include "mthca_dev.h" ··· 91 90 92 91 props->max_mr_size = ~0ull; 93 92 props->max_qp = mdev->limits.num_qps - mdev->limits.reserved_qps; 94 - props->max_qp_wr = 0xffff; 93 + props->max_qp_wr = mdev->limits.max_wqes; 95 94 props->max_sge = mdev->limits.max_sg; 96 95 props->max_cq = mdev->limits.num_cqs - mdev->limits.reserved_cqs; 97 - props->max_cqe = 0xffff; 96 + props->max_cqe = mdev->limits.max_cqes; 98 97 props->max_mr = mdev->limits.num_mpts - mdev->limits.reserved_mrws; 99 98 props->max_pd = mdev->limits.num_pds - mdev->limits.reserved_pds; 100 99 props->max_qp_rd_atom = 1 << mdev->qp_table.rdb_shift; 101 - props->max_qp_init_rd_atom = 1 << mdev->qp_table.rdb_shift; 100 + props->max_qp_init_rd_atom = mdev->limits.max_qp_init_rdma; 101 + props->max_res_rd_atom = props->max_qp_rd_atom * props->max_qp; 102 + props->max_srq = mdev->limits.num_srqs - mdev->limits.reserved_srqs; 103 + props->max_srq_wr = mdev->limits.max_srq_wqes; 104 + props->max_srq_sge = mdev->limits.max_sg; 102 105 props->local_ca_ack_delay = mdev->limits.local_ca_ack_delay; 106 + props->atomic_cap = mdev->limits.flags & DEV_LIM_FLAG_ATOMIC ? 107 + IB_ATOMIC_HCA : IB_ATOMIC_NONE; 108 + props->max_pkeys = mdev->limits.pkey_table_len; 109 + props->max_mcast_grp = mdev->limits.num_mgms + mdev->limits.num_amgms; 110 + props->max_mcast_qp_attach = MTHCA_QP_PER_MGM; 111 + props->max_total_mcast_qp_attach = props->max_mcast_qp_attach * 112 + props->max_mcast_grp; 103 113 104 114 err = 0; 105 115 out: ··· 162 150 props->gid_tbl_len = to_mdev(ibdev)->limits.gid_table_len; 163 151 props->max_msg_sz = 0x80000000; 164 152 props->pkey_tbl_len = to_mdev(ibdev)->limits.pkey_table_len; 153 + props->bad_pkey_cntr = be16_to_cpup((__be16 *) (out_mad->data + 46)); 165 154 props->qkey_viol_cntr = be16_to_cpup((__be16 *) (out_mad->data + 48)); 166 155 props->active_width = out_mad->data[31] & 0xf; 167 156 props->active_speed = out_mad->data[35] >> 4; 157 + props->max_mtu = out_mad->data[41] & 0xf; 158 + props->active_mtu = out_mad->data[36] >> 4; 159 + props->subnet_timeout = out_mad->data[51] & 0x1f; 168 160 169 161 out: 170 162 kfree(in_mad); ··· 650 634 int nent; 651 635 int err; 652 636 637 + if (entries < 1 || entries > to_mdev(ibdev)->limits.max_cqes) 638 + return ERR_PTR(-EINVAL); 639 + 653 640 if (context) { 654 641 if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) 655 642 return ERR_PTR(-EFAULT); ··· 1077 1058 strlcpy(dev->ib_dev.name, "mthca%d", IB_DEVICE_NAME_MAX); 1078 1059 dev->ib_dev.owner = THIS_MODULE; 1079 1060 1061 + dev->ib_dev.uverbs_abi_ver = MTHCA_UVERBS_ABI_VERSION; 1062 + dev->ib_dev.uverbs_cmd_mask = 1063 + (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | 1064 + (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | 1065 + (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | 1066 + (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | 1067 + (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | 1068 + (1ull << IB_USER_VERBS_CMD_REG_MR) | 1069 + (1ull << IB_USER_VERBS_CMD_DEREG_MR) | 1070 + (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | 1071 + (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | 1072 + (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | 1073 + (1ull << IB_USER_VERBS_CMD_CREATE_QP) | 1074 + (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | 1075 + (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | 1076 + (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | 1077 + (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | 1078 + (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | 1079 + (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | 1080 + (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ); 1080 1081 dev->ib_dev.node_type = IB_NODE_CA; 1081 1082 dev->ib_dev.phys_port_cnt = dev->limits.num_ports; 1082 1083 dev->ib_dev.dma_device = &dev->pdev->dev; ··· 1116 1077 1117 1078 if (dev->mthca_flags & MTHCA_FLAG_SRQ) { 1118 1079 dev->ib_dev.create_srq = mthca_create_srq; 1080 + dev->ib_dev.modify_srq = mthca_modify_srq; 1119 1081 dev->ib_dev.destroy_srq = mthca_destroy_srq; 1120 1082 1121 1083 if (mthca_is_memfree(dev)) ··· 1175 1135 } 1176 1136 } 1177 1137 1138 + mthca_start_catas_poll(dev); 1139 + 1178 1140 return 0; 1179 1141 } 1180 1142 1181 1143 void mthca_unregister_device(struct mthca_dev *dev) 1182 1144 { 1145 + mthca_stop_catas_poll(dev); 1183 1146 ib_unregister_device(&dev->ib_dev); 1184 1147 }
+7 -9
drivers/infiniband/hw/mthca/mthca_qp.c
··· 338 338 [UC] = (IB_QP_AV | 339 339 IB_QP_PATH_MTU | 340 340 IB_QP_DEST_QPN | 341 - IB_QP_RQ_PSN | 342 - IB_QP_MAX_DEST_RD_ATOMIC), 341 + IB_QP_RQ_PSN), 343 342 [RC] = (IB_QP_AV | 344 343 IB_QP_PATH_MTU | 345 344 IB_QP_DEST_QPN | ··· 367 368 .trans = MTHCA_TRANS_RTR2RTS, 368 369 .req_param = { 369 370 [UD] = IB_QP_SQ_PSN, 370 - [UC] = (IB_QP_SQ_PSN | 371 - IB_QP_MAX_QP_RD_ATOMIC), 371 + [UC] = IB_QP_SQ_PSN, 372 372 [RC] = (IB_QP_TIMEOUT | 373 373 IB_QP_RETRY_CNT | 374 374 IB_QP_RNR_RETRY | ··· 444 446 [UD] = (IB_QP_PKEY_INDEX | 445 447 IB_QP_QKEY), 446 448 [UC] = (IB_QP_AV | 447 - IB_QP_MAX_QP_RD_ATOMIC | 448 - IB_QP_MAX_DEST_RD_ATOMIC | 449 449 IB_QP_CUR_STATE | 450 450 IB_QP_ALT_PATH | 451 451 IB_QP_ACCESS_FLAGS | ··· 474 478 .opt_param = { 475 479 [UD] = (IB_QP_CUR_STATE | 476 480 IB_QP_QKEY), 477 - [UC] = (IB_QP_CUR_STATE), 481 + [UC] = IB_QP_CUR_STATE, 478 482 [RC] = (IB_QP_CUR_STATE | 479 483 IB_QP_MIN_RNR_TIMER), 480 484 [MLX] = (IB_QP_CUR_STATE | ··· 1108 1112 struct mthca_qp *qp) 1109 1113 { 1110 1114 /* Sanity check QP size before proceeding */ 1111 - if (cap->max_send_wr > 65536 || cap->max_recv_wr > 65536 || 1112 - cap->max_send_sge > 64 || cap->max_recv_sge > 64) 1115 + if (cap->max_send_wr > dev->limits.max_wqes || 1116 + cap->max_recv_wr > dev->limits.max_wqes || 1117 + cap->max_send_sge > dev->limits.max_sg || 1118 + cap->max_recv_sge > dev->limits.max_sg) 1113 1119 return -EINVAL; 1114 1120 1115 1121 if (mthca_is_memfree(dev)) {
+41 -2
drivers/infiniband/hw/mthca/mthca_srq.c
··· 186 186 int err; 187 187 188 188 /* Sanity check SRQ size before proceeding */ 189 - if (attr->max_wr > 16 << 20 || attr->max_sge > 64) 189 + if (attr->max_wr > dev->limits.max_srq_wqes || 190 + attr->max_sge > dev->limits.max_sg) 190 191 return -EINVAL; 191 192 192 193 srq->max = attr->max_wr; ··· 333 332 mthca_free_mailbox(dev, mailbox); 334 333 } 335 334 335 + int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, 336 + enum ib_srq_attr_mask attr_mask) 337 + { 338 + struct mthca_dev *dev = to_mdev(ibsrq->device); 339 + struct mthca_srq *srq = to_msrq(ibsrq); 340 + int ret; 341 + u8 status; 342 + 343 + /* We don't support resizing SRQs (yet?) */ 344 + if (attr_mask & IB_SRQ_MAX_WR) 345 + return -EINVAL; 346 + 347 + if (attr_mask & IB_SRQ_LIMIT) { 348 + ret = mthca_ARM_SRQ(dev, srq->srqn, attr->srq_limit, &status); 349 + if (ret) 350 + return ret; 351 + if (status) 352 + return -EINVAL; 353 + } 354 + 355 + return 0; 356 + } 357 + 336 358 void mthca_srq_event(struct mthca_dev *dev, u32 srqn, 337 359 enum ib_event_type event_type) 338 360 { ··· 378 354 379 355 event.device = &dev->ib_dev; 380 356 event.event = event_type; 381 - event.element.srq = &srq->ibsrq; 357 + event.element.srq = &srq->ibsrq; 382 358 srq->ibsrq.event_handler(&event, srq->ibsrq.srq_context); 383 359 384 360 out: ··· 439 415 440 416 wqe = get_wqe(srq, ind); 441 417 next_ind = *wqe_to_link(wqe); 418 + 419 + if (next_ind < 0) { 420 + mthca_err(dev, "SRQ %06x full\n", srq->srqn); 421 + err = -ENOMEM; 422 + *bad_wr = wr; 423 + break; 424 + } 425 + 442 426 prev_wqe = srq->last; 443 427 srq->last = wqe; 444 428 ··· 537 505 538 506 wqe = get_wqe(srq, ind); 539 507 next_ind = *wqe_to_link(wqe); 508 + 509 + if (next_ind < 0) { 510 + mthca_err(dev, "SRQ %06x full\n", srq->srqn); 511 + err = -ENOMEM; 512 + *bad_wr = wr; 513 + break; 514 + } 540 515 541 516 ((struct mthca_next_seg *) wqe)->nda_op = 542 517 cpu_to_be32((next_ind << srq->wqe_shift) | 1);
+6
drivers/infiniband/hw/mthca/mthca_user.h
··· 38 38 #include <linux/types.h> 39 39 40 40 /* 41 + * Increment this value if any changes that break userspace ABI 42 + * compatibility are made. 43 + */ 44 + #define MTHCA_UVERBS_ABI_VERSION 1 45 + 46 + /* 41 47 * Make sure that all structs defined in this file remain laid out so 42 48 * that they pack the same way on 32-bit and 64-bit architectures (to 43 49 * avoid incompatibility between 32-bit userspace and 64-bit kernels).
+14 -9
drivers/infiniband/ulp/ipoib/ipoib.h
··· 100 100 101 101 struct ipoib_mcast; 102 102 103 - struct ipoib_buf { 103 + struct ipoib_rx_buf { 104 + struct sk_buff *skb; 105 + dma_addr_t mapping; 106 + }; 107 + 108 + struct ipoib_tx_buf { 104 109 struct sk_buff *skb; 105 110 DECLARE_PCI_UNMAP_ADDR(mapping) 106 111 }; ··· 155 150 unsigned int admin_mtu; 156 151 unsigned int mcast_mtu; 157 152 158 - struct ipoib_buf *rx_ring; 153 + struct ipoib_rx_buf *rx_ring; 159 154 160 - spinlock_t tx_lock; 161 - struct ipoib_buf *tx_ring; 162 - unsigned tx_head; 163 - unsigned tx_tail; 164 - struct ib_sge tx_sge; 165 - struct ib_send_wr tx_wr; 155 + spinlock_t tx_lock; 156 + struct ipoib_tx_buf *tx_ring; 157 + unsigned tx_head; 158 + unsigned tx_tail; 159 + struct ib_sge tx_sge; 160 + struct ib_send_wr tx_wr; 166 161 167 162 struct ib_wc ibwc[IPOIB_NUM_WC]; 168 163 ··· 282 277 int ipoib_mcast_detach(struct net_device *dev, u16 mlid, 283 278 union ib_gid *mgid); 284 279 285 - int ipoib_qp_create(struct net_device *dev); 280 + int ipoib_init_qp(struct net_device *dev); 286 281 int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca); 287 282 void ipoib_transport_dev_cleanup(struct net_device *dev); 288 283
+76 -56
drivers/infiniband/ulp/ipoib/ipoib_ib.c
··· 95 95 } 96 96 } 97 97 98 - static inline int ipoib_ib_receive(struct ipoib_dev_priv *priv, 99 - unsigned int wr_id, 100 - dma_addr_t addr) 101 - { 102 - struct ib_sge list = { 103 - .addr = addr, 104 - .length = IPOIB_BUF_SIZE, 105 - .lkey = priv->mr->lkey, 106 - }; 107 - struct ib_recv_wr param = { 108 - .wr_id = wr_id | IPOIB_OP_RECV, 109 - .sg_list = &list, 110 - .num_sge = 1, 111 - }; 112 - struct ib_recv_wr *bad_wr; 113 - 114 - return ib_post_recv(priv->qp, &param, &bad_wr); 115 - } 116 - 117 98 static int ipoib_ib_post_receive(struct net_device *dev, int id) 118 99 { 119 100 struct ipoib_dev_priv *priv = netdev_priv(dev); 120 - struct sk_buff *skb; 121 - dma_addr_t addr; 101 + struct ib_sge list; 102 + struct ib_recv_wr param; 103 + struct ib_recv_wr *bad_wr; 122 104 int ret; 123 105 124 - skb = dev_alloc_skb(IPOIB_BUF_SIZE + 4); 125 - if (!skb) { 126 - ipoib_warn(priv, "failed to allocate receive buffer\n"); 106 + list.addr = priv->rx_ring[id].mapping; 107 + list.length = IPOIB_BUF_SIZE; 108 + list.lkey = priv->mr->lkey; 127 109 128 - priv->rx_ring[id].skb = NULL; 129 - return -ENOMEM; 130 - } 131 - skb_reserve(skb, 4); /* 16 byte align IP header */ 132 - priv->rx_ring[id].skb = skb; 133 - addr = dma_map_single(priv->ca->dma_device, 134 - skb->data, IPOIB_BUF_SIZE, 135 - DMA_FROM_DEVICE); 136 - pci_unmap_addr_set(&priv->rx_ring[id], mapping, addr); 110 + param.next = NULL; 111 + param.wr_id = id | IPOIB_OP_RECV; 112 + param.sg_list = &list; 113 + param.num_sge = 1; 137 114 138 - ret = ipoib_ib_receive(priv, id, addr); 139 - if (ret) { 140 - ipoib_warn(priv, "ipoib_ib_receive failed for buf %d (%d)\n", 141 - id, ret); 142 - dma_unmap_single(priv->ca->dma_device, addr, 115 + ret = ib_post_recv(priv->qp, &param, &bad_wr); 116 + if (unlikely(ret)) { 117 + ipoib_warn(priv, "receive failed for buf %d (%d)\n", id, ret); 118 + dma_unmap_single(priv->ca->dma_device, 119 + priv->rx_ring[id].mapping, 143 120 IPOIB_BUF_SIZE, DMA_FROM_DEVICE); 144 - dev_kfree_skb_any(skb); 121 + dev_kfree_skb_any(priv->rx_ring[id].skb); 145 122 priv->rx_ring[id].skb = NULL; 146 123 } 147 124 148 125 return ret; 126 + } 127 + 128 + static int ipoib_alloc_rx_skb(struct net_device *dev, int id) 129 + { 130 + struct ipoib_dev_priv *priv = netdev_priv(dev); 131 + struct sk_buff *skb; 132 + dma_addr_t addr; 133 + 134 + skb = dev_alloc_skb(IPOIB_BUF_SIZE + 4); 135 + if (!skb) 136 + return -ENOMEM; 137 + 138 + /* 139 + * IB will leave a 40 byte gap for a GRH and IPoIB adds a 4 byte 140 + * header. So we need 4 more bytes to get to 48 and align the 141 + * IP header to a multiple of 16. 142 + */ 143 + skb_reserve(skb, 4); 144 + 145 + addr = dma_map_single(priv->ca->dma_device, 146 + skb->data, IPOIB_BUF_SIZE, 147 + DMA_FROM_DEVICE); 148 + if (unlikely(dma_mapping_error(addr))) { 149 + dev_kfree_skb_any(skb); 150 + return -EIO; 151 + } 152 + 153 + priv->rx_ring[id].skb = skb; 154 + priv->rx_ring[id].mapping = addr; 155 + 156 + return 0; 149 157 } 150 158 151 159 static int ipoib_ib_post_receives(struct net_device *dev) ··· 162 154 int i; 163 155 164 156 for (i = 0; i < IPOIB_RX_RING_SIZE; ++i) { 157 + if (ipoib_alloc_rx_skb(dev, i)) { 158 + ipoib_warn(priv, "failed to allocate receive buffer %d\n", i); 159 + return -ENOMEM; 160 + } 165 161 if (ipoib_ib_post_receive(dev, i)) { 166 162 ipoib_warn(priv, "ipoib_ib_post_receive failed for buf %d\n", i); 167 163 return -EIO; ··· 188 176 wr_id &= ~IPOIB_OP_RECV; 189 177 190 178 if (wr_id < IPOIB_RX_RING_SIZE) { 191 - struct sk_buff *skb = priv->rx_ring[wr_id].skb; 179 + struct sk_buff *skb = priv->rx_ring[wr_id].skb; 180 + dma_addr_t addr = priv->rx_ring[wr_id].mapping; 192 181 193 - priv->rx_ring[wr_id].skb = NULL; 194 - 195 - dma_unmap_single(priv->ca->dma_device, 196 - pci_unmap_addr(&priv->rx_ring[wr_id], 197 - mapping), 198 - IPOIB_BUF_SIZE, 199 - DMA_FROM_DEVICE); 200 - 201 - if (wc->status != IB_WC_SUCCESS) { 182 + if (unlikely(wc->status != IB_WC_SUCCESS)) { 202 183 if (wc->status != IB_WC_WR_FLUSH_ERR) 203 184 ipoib_warn(priv, "failed recv event " 204 185 "(status=%d, wrid=%d vend_err %x)\n", 205 186 wc->status, wr_id, wc->vendor_err); 187 + dma_unmap_single(priv->ca->dma_device, addr, 188 + IPOIB_BUF_SIZE, DMA_FROM_DEVICE); 206 189 dev_kfree_skb_any(skb); 190 + priv->rx_ring[wr_id].skb = NULL; 207 191 return; 192 + } 193 + 194 + /* 195 + * If we can't allocate a new RX buffer, dump 196 + * this packet and reuse the old buffer. 197 + */ 198 + if (unlikely(ipoib_alloc_rx_skb(dev, wr_id))) { 199 + ++priv->stats.rx_dropped; 200 + goto repost; 208 201 } 209 202 210 203 ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n", 211 204 wc->byte_len, wc->slid); 205 + 206 + dma_unmap_single(priv->ca->dma_device, addr, 207 + IPOIB_BUF_SIZE, DMA_FROM_DEVICE); 212 208 213 209 skb_put(skb, wc->byte_len); 214 210 skb_pull(skb, IB_GRH_BYTES); ··· 240 220 dev_kfree_skb_any(skb); 241 221 } 242 222 243 - /* repost receive */ 244 - if (ipoib_ib_post_receive(dev, wr_id)) 223 + repost: 224 + if (unlikely(ipoib_ib_post_receive(dev, wr_id))) 245 225 ipoib_warn(priv, "ipoib_ib_post_receive failed " 246 226 "for buf %d\n", wr_id); 247 227 } else ··· 249 229 wr_id); 250 230 251 231 } else { 252 - struct ipoib_buf *tx_req; 232 + struct ipoib_tx_buf *tx_req; 253 233 unsigned long flags; 254 234 255 235 if (wr_id >= IPOIB_TX_RING_SIZE) { ··· 322 302 struct ipoib_ah *address, u32 qpn) 323 303 { 324 304 struct ipoib_dev_priv *priv = netdev_priv(dev); 325 - struct ipoib_buf *tx_req; 305 + struct ipoib_tx_buf *tx_req; 326 306 dma_addr_t addr; 327 307 328 308 if (skb->len > dev->mtu + INFINIBAND_ALEN) { ··· 407 387 struct ipoib_dev_priv *priv = netdev_priv(dev); 408 388 int ret; 409 389 410 - ret = ipoib_qp_create(dev); 390 + ret = ipoib_init_qp(dev); 411 391 if (ret) { 412 - ipoib_warn(priv, "ipoib_qp_create returned %d\n", ret); 392 + ipoib_warn(priv, "ipoib_init_qp returned %d\n", ret); 413 393 return -1; 414 394 } 415 395 ··· 488 468 struct ib_qp_attr qp_attr; 489 469 int attr_mask; 490 470 unsigned long begin; 491 - struct ipoib_buf *tx_req; 471 + struct ipoib_tx_buf *tx_req; 492 472 int i; 493 473 494 474 /* Kill the existing QP and allocate a new one */
+9 -6
drivers/infiniband/ulp/ipoib/ipoib_main.c
··· 637 637 { 638 638 struct ipoib_dev_priv *priv = netdev_priv(dev); 639 639 640 - ipoib_warn(priv, "transmit timeout: latency %ld\n", 641 - jiffies - dev->trans_start); 640 + ipoib_warn(priv, "transmit timeout: latency %d msecs\n", 641 + jiffies_to_msecs(jiffies - dev->trans_start)); 642 + ipoib_warn(priv, "queue stopped %d, tx_head %u, tx_tail %u\n", 643 + netif_queue_stopped(dev), 644 + priv->tx_head, priv->tx_tail); 642 645 /* XXX reset QP, etc. */ 643 646 } 644 647 ··· 732 729 733 730 /* Allocate RX/TX "rings" to hold queued skbs */ 734 731 735 - priv->rx_ring = kmalloc(IPOIB_RX_RING_SIZE * sizeof (struct ipoib_buf), 732 + priv->rx_ring = kmalloc(IPOIB_RX_RING_SIZE * sizeof (struct ipoib_rx_buf), 736 733 GFP_KERNEL); 737 734 if (!priv->rx_ring) { 738 735 printk(KERN_WARNING "%s: failed to allocate RX ring (%d entries)\n", ··· 740 737 goto out; 741 738 } 742 739 memset(priv->rx_ring, 0, 743 - IPOIB_RX_RING_SIZE * sizeof (struct ipoib_buf)); 740 + IPOIB_RX_RING_SIZE * sizeof (struct ipoib_rx_buf)); 744 741 745 - priv->tx_ring = kmalloc(IPOIB_TX_RING_SIZE * sizeof (struct ipoib_buf), 742 + priv->tx_ring = kmalloc(IPOIB_TX_RING_SIZE * sizeof (struct ipoib_tx_buf), 746 743 GFP_KERNEL); 747 744 if (!priv->tx_ring) { 748 745 printk(KERN_WARNING "%s: failed to allocate TX ring (%d entries)\n", ··· 750 747 goto out_rx_ring_cleanup; 751 748 } 752 749 memset(priv->tx_ring, 0, 753 - IPOIB_TX_RING_SIZE * sizeof (struct ipoib_buf)); 750 + IPOIB_TX_RING_SIZE * sizeof (struct ipoib_tx_buf)); 754 751 755 752 /* priv->tx_head & tx_tail are already 0 */ 756 753
+5 -4
drivers/infiniband/ulp/ipoib/ipoib_verbs.c
··· 92 92 return ret; 93 93 } 94 94 95 - int ipoib_qp_create(struct net_device *dev) 95 + int ipoib_init_qp(struct net_device *dev) 96 96 { 97 97 struct ipoib_dev_priv *priv = netdev_priv(dev); 98 98 int ret; ··· 149 149 return 0; 150 150 151 151 out_fail: 152 - ib_destroy_qp(priv->qp); 153 - priv->qp = NULL; 152 + qp_attr.qp_state = IB_QPS_RESET; 153 + if (ib_modify_qp(priv->qp, &qp_attr, IB_QP_STATE)) 154 + ipoib_warn(priv, "Failed to modify QP to RESET state\n"); 154 155 155 - return -EINVAL; 156 + return ret; 156 157 } 157 158 158 159 int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca)
+6 -4
include/rdma/ib_cm.h
··· 1 1 /* 2 - * Copyright (c) 2004 Intel Corporation. All rights reserved. 2 + * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved. 3 3 * Copyright (c) 2004 Topspin Corporation. All rights reserved. 4 4 * Copyright (c) 2004 Voltaire Corporation. All rights reserved. 5 5 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. ··· 109 109 110 110 struct ib_cm_req_event_param { 111 111 struct ib_cm_id *listen_id; 112 - struct ib_device *device; 113 112 u8 port; 114 113 115 114 struct ib_sa_path_rec *primary_path; ··· 219 220 220 221 struct ib_cm_sidr_req_event_param { 221 222 struct ib_cm_id *listen_id; 222 - struct ib_device *device; 223 223 u8 port; 224 224 u16 pkey; 225 225 }; ··· 282 284 struct ib_cm_id { 283 285 ib_cm_handler cm_handler; 284 286 void *context; 287 + struct ib_device *device; 285 288 __be64 service_id; 286 289 __be64 service_mask; 287 290 enum ib_cm_state state; /* internal CM/debug use */ ··· 294 295 295 296 /** 296 297 * ib_create_cm_id - Allocate a communication identifier. 298 + * @device: Device associated with the cm_id. All related communication will 299 + * be associated with the specified device. 297 300 * @cm_handler: Callback invoked to notify the user of CM events. 298 301 * @context: User specified context associated with the communication 299 302 * identifier. ··· 303 302 * Communication identifiers are used to track connection states, service 304 303 * ID resolution requests, and listen requests. 305 304 */ 306 - struct ib_cm_id *ib_create_cm_id(ib_cm_handler cm_handler, 305 + struct ib_cm_id *ib_create_cm_id(struct ib_device *device, 306 + ib_cm_handler cm_handler, 307 307 void *context); 308 308 309 309 /**
+34 -32
include/rdma/ib_mad.h
··· 109 109 #define IB_QP_SET_QKEY 0x80000000 110 110 111 111 enum { 112 + IB_MGMT_MAD_HDR = 24, 112 113 IB_MGMT_MAD_DATA = 232, 114 + IB_MGMT_RMPP_HDR = 36, 113 115 IB_MGMT_RMPP_DATA = 220, 116 + IB_MGMT_VENDOR_HDR = 40, 114 117 IB_MGMT_VENDOR_DATA = 216, 115 - IB_MGMT_SA_DATA = 200 118 + IB_MGMT_SA_HDR = 56, 119 + IB_MGMT_SA_DATA = 200, 116 120 }; 117 121 118 122 struct ib_mad_hdr { ··· 207 203 208 204 /** 209 205 * ib_mad_send_buf - MAD data buffer and work request for sends. 210 - * @mad: References an allocated MAD data buffer. The size of the data 211 - * buffer is specified in the @send_wr.length field. 212 - * @mapping: DMA mapping information. 206 + * @next: A pointer used to chain together MADs for posting. 207 + * @mad: References an allocated MAD data buffer. 213 208 * @mad_agent: MAD agent that allocated the buffer. 209 + * @ah: The address handle to use when sending the MAD. 214 210 * @context: User-controlled context fields. 215 - * @send_wr: An initialized work request structure used when sending the MAD. 216 - * The wr_id field of the work request is initialized to reference this 217 - * data structure. 218 - * @sge: A scatter-gather list referenced by the work request. 211 + * @timeout_ms: Time to wait for a response. 212 + * @retries: Number of times to retry a request for a response. 219 213 * 220 214 * Users are responsible for initializing the MAD buffer itself, with the 221 215 * exception of specifying the payload length field in any RMPP MAD. 222 216 */ 223 217 struct ib_mad_send_buf { 224 - struct ib_mad *mad; 225 - DECLARE_PCI_UNMAP_ADDR(mapping) 218 + struct ib_mad_send_buf *next; 219 + void *mad; 226 220 struct ib_mad_agent *mad_agent; 221 + struct ib_ah *ah; 227 222 void *context[2]; 228 - struct ib_send_wr send_wr; 229 - struct ib_sge sge; 223 + int timeout_ms; 224 + int retries; 230 225 }; 231 226 232 227 /** ··· 290 287 * or @mad_send_wc. 291 288 */ 292 289 typedef void (*ib_mad_snoop_handler)(struct ib_mad_agent *mad_agent, 293 - struct ib_send_wr *send_wr, 290 + struct ib_mad_send_buf *send_buf, 294 291 struct ib_mad_send_wc *mad_send_wc); 295 292 296 293 /** ··· 337 334 338 335 /** 339 336 * ib_mad_send_wc - MAD send completion information. 340 - * @wr_id: Work request identifier associated with the send MAD request. 337 + * @send_buf: Send MAD data buffer associated with the send MAD request. 341 338 * @status: Completion status. 342 339 * @vendor_err: Optional vendor error information returned with a failed 343 340 * request. 344 341 */ 345 342 struct ib_mad_send_wc { 346 - u64 wr_id; 343 + struct ib_mad_send_buf *send_buf; 347 344 enum ib_wc_status status; 348 345 u32 vendor_err; 349 346 }; ··· 369 366 * @rmpp_list: Specifies a list of RMPP reassembled received MAD buffers. 370 367 * @mad_len: The length of the received MAD, without duplicated headers. 371 368 * 372 - * For received response, the wr_id field of the wc is set to the wr_id 369 + * For received response, the wr_id contains a pointer to the ib_mad_send_buf 373 370 * for the corresponding send request. 374 371 */ 375 372 struct ib_mad_recv_wc { ··· 466 463 /** 467 464 * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated 468 465 * with the registered client. 469 - * @mad_agent: Specifies the associated registration to post the send to. 470 - * @send_wr: Specifies the information needed to send the MAD(s). 471 - * @bad_send_wr: Specifies the MAD on which an error was encountered. 466 + * @send_buf: Specifies the information needed to send the MAD(s). 467 + * @bad_send_buf: Specifies the MAD on which an error was encountered. This 468 + * parameter is optional if only a single MAD is posted. 472 469 * 473 470 * Sent MADs are not guaranteed to complete in the order that they were posted. 474 471 * ··· 482 479 * defined data being transferred. The paylen_newwin field should be 483 480 * specified in network-byte order. 484 481 */ 485 - int ib_post_send_mad(struct ib_mad_agent *mad_agent, 486 - struct ib_send_wr *send_wr, 487 - struct ib_send_wr **bad_send_wr); 482 + int ib_post_send_mad(struct ib_mad_send_buf *send_buf, 483 + struct ib_mad_send_buf **bad_send_buf); 488 484 489 485 /** 490 486 * ib_coalesce_recv_mad - Coalesces received MAD data into a single buffer. ··· 509 507 /** 510 508 * ib_cancel_mad - Cancels an outstanding send MAD operation. 511 509 * @mad_agent: Specifies the registration associated with sent MAD. 512 - * @wr_id: Indicates the work request identifier of the MAD to cancel. 510 + * @send_buf: Indicates the MAD to cancel. 513 511 * 514 512 * MADs will be returned to the user through the corresponding 515 513 * ib_mad_send_handler. 516 514 */ 517 - void ib_cancel_mad(struct ib_mad_agent *mad_agent, u64 wr_id); 515 + void ib_cancel_mad(struct ib_mad_agent *mad_agent, 516 + struct ib_mad_send_buf *send_buf); 518 517 519 518 /** 520 519 * ib_modify_mad - Modifies an outstanding send MAD operation. 521 520 * @mad_agent: Specifies the registration associated with sent MAD. 522 - * @wr_id: Indicates the work request identifier of the MAD to modify. 521 + * @send_buf: Indicates the MAD to modify. 523 522 * @timeout_ms: New timeout value for sent MAD. 524 523 * 525 524 * This call will reset the timeout value for a sent MAD to the specified 526 525 * value. 527 526 */ 528 - int ib_modify_mad(struct ib_mad_agent *mad_agent, u64 wr_id, u32 timeout_ms); 527 + int ib_modify_mad(struct ib_mad_agent *mad_agent, 528 + struct ib_mad_send_buf *send_buf, u32 timeout_ms); 529 529 530 530 /** 531 531 * ib_redirect_mad_qp - Registers a QP for MAD services. ··· 576 572 * @remote_qpn: Specifies the QPN of the receiving node. 577 573 * @pkey_index: Specifies which PKey the MAD will be sent using. This field 578 574 * is valid only if the remote_qpn is QP 1. 579 - * @ah: References the address handle used to transfer to the remote node. 580 575 * @rmpp_active: Indicates if the send will enable RMPP. 581 576 * @hdr_len: Indicates the size of the data header of the MAD. This length 582 577 * should include the common MAD header, RMPP header, plus any class ··· 585 582 * additional padding that may be necessary. 586 583 * @gfp_mask: GFP mask used for the memory allocation. 587 584 * 588 - * This is a helper routine that may be used to allocate a MAD. Users are 589 - * not required to allocate outbound MADs using this call. The returned 590 - * MAD send buffer will reference a data buffer usable for sending a MAD, along 585 + * This routine allocates a MAD for sending. The returned MAD send buffer 586 + * will reference a data buffer usable for sending a MAD, along 591 587 * with an initialized work request structure. Users may modify the returned 592 - * MAD data buffer or work request before posting the send. 588 + * MAD data buffer before posting the send. 593 589 * 594 590 * The returned data buffer will be cleared. Users are responsible for 595 591 * initializing the common MAD and any class specific headers. If @rmpp_active ··· 596 594 */ 597 595 struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent, 598 596 u32 remote_qpn, u16 pkey_index, 599 - struct ib_ah *ah, int rmpp_active, 597 + int rmpp_active, 600 598 int hdr_len, int data_len, 601 599 gfp_t gfp_mask); 602 600
+4 -6
include/rdma/ib_user_cm.h
··· 38 38 39 39 #include <linux/types.h> 40 40 41 - #define IB_USER_CM_ABI_VERSION 2 41 + #define IB_USER_CM_ABI_VERSION 3 42 42 43 43 enum { 44 44 IB_USER_CM_CMD_CREATE_ID, ··· 299 299 }; 300 300 301 301 struct ib_ucm_req_event_resp { 302 - /* device */ 303 - /* port */ 304 302 struct ib_ucm_path_rec primary_path; 305 303 struct ib_ucm_path_rec alternate_path; 306 304 __be64 remote_ca_guid; ··· 314 316 __u8 retry_count; 315 317 __u8 rnr_retry_count; 316 318 __u8 srq; 319 + __u8 port; 317 320 }; 318 321 319 322 struct ib_ucm_rep_event_resp { ··· 352 353 }; 353 354 354 355 struct ib_ucm_sidr_req_event_resp { 355 - /* device */ 356 - /* port */ 357 356 __u16 pkey; 358 - __u8 reserved[2]; 357 + __u8 port; 358 + __u8 reserved; 359 359 }; 360 360 361 361 struct ib_ucm_sidr_rep_event_resp {
+176 -46
include/rdma/ib_user_verbs.h
··· 1 1 /* 2 2 * Copyright (c) 2005 Topspin Communications. All rights reserved. 3 3 * Copyright (c) 2005 Cisco Systems. All rights reserved. 4 + * Copyright (c) 2005 PathScale, Inc. All rights reserved. 4 5 * 5 6 * This software is available to you under a choice of one of two 6 7 * licenses. You may choose to be licensed under the terms of the GNU ··· 43 42 * Increment this value if any changes that break userspace ABI 44 43 * compatibility are made. 45 44 */ 46 - #define IB_USER_VERBS_ABI_VERSION 2 45 + #define IB_USER_VERBS_ABI_VERSION 3 47 46 48 47 enum { 49 - IB_USER_VERBS_CMD_QUERY_PARAMS, 50 48 IB_USER_VERBS_CMD_GET_CONTEXT, 51 49 IB_USER_VERBS_CMD_QUERY_DEVICE, 52 50 IB_USER_VERBS_CMD_QUERY_PORT, 53 - IB_USER_VERBS_CMD_QUERY_GID, 54 - IB_USER_VERBS_CMD_QUERY_PKEY, 55 51 IB_USER_VERBS_CMD_ALLOC_PD, 56 52 IB_USER_VERBS_CMD_DEALLOC_PD, 57 53 IB_USER_VERBS_CMD_CREATE_AH, ··· 63 65 IB_USER_VERBS_CMD_ALLOC_MW, 64 66 IB_USER_VERBS_CMD_BIND_MW, 65 67 IB_USER_VERBS_CMD_DEALLOC_MW, 68 + IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL, 66 69 IB_USER_VERBS_CMD_CREATE_CQ, 67 70 IB_USER_VERBS_CMD_RESIZE_CQ, 68 71 IB_USER_VERBS_CMD_DESTROY_CQ, ··· 89 90 * Make sure that all structs defined in this file remain laid out so 90 91 * that they pack the same way on 32-bit and 64-bit architectures (to 91 92 * avoid incompatibility between 32-bit userspace and 64-bit kernels). 92 - * In particular do not use pointer types -- pass pointers in __u64 93 - * instead. 93 + * Specifically: 94 + * - Do not use pointer types -- pass pointers in __u64 instead. 95 + * - Make sure that any structure larger than 4 bytes is padded to a 96 + * multiple of 8 bytes. Otherwise the structure size will be 97 + * different between 32-bit and 64-bit architectures. 94 98 */ 95 99 96 100 struct ib_uverbs_async_event_desc { ··· 120 118 __u16 out_words; 121 119 }; 122 120 123 - /* 124 - * No driver_data for "query params" command, since this is intended 125 - * to be a core function with no possible device dependence. 126 - */ 127 - struct ib_uverbs_query_params { 128 - __u64 response; 129 - }; 130 - 131 - struct ib_uverbs_query_params_resp { 132 - __u32 num_cq_events; 133 - }; 134 - 135 121 struct ib_uverbs_get_context { 136 122 __u64 response; 137 - __u64 cq_fd_tab; 138 123 __u64 driver_data[0]; 139 124 }; 140 125 141 126 struct ib_uverbs_get_context_resp { 142 127 __u32 async_fd; 143 - __u32 reserved; 128 + __u32 num_comp_vectors; 144 129 }; 145 130 146 131 struct ib_uverbs_query_device { ··· 209 220 __u8 reserved[3]; 210 221 }; 211 222 212 - struct ib_uverbs_query_gid { 213 - __u64 response; 214 - __u8 port_num; 215 - __u8 index; 216 - __u8 reserved[6]; 217 - __u64 driver_data[0]; 218 - }; 219 - 220 - struct ib_uverbs_query_gid_resp { 221 - __u8 gid[16]; 222 - }; 223 - 224 - struct ib_uverbs_query_pkey { 225 - __u64 response; 226 - __u8 port_num; 227 - __u8 index; 228 - __u8 reserved[6]; 229 - __u64 driver_data[0]; 230 - }; 231 - 232 - struct ib_uverbs_query_pkey_resp { 233 - __u16 pkey; 234 - __u16 reserved; 235 - }; 236 - 237 223 struct ib_uverbs_alloc_pd { 238 224 __u64 response; 239 225 __u64 driver_data[0]; ··· 242 278 __u32 mr_handle; 243 279 }; 244 280 281 + struct ib_uverbs_create_comp_channel { 282 + __u64 response; 283 + }; 284 + 285 + struct ib_uverbs_create_comp_channel_resp { 286 + __u32 fd; 287 + }; 288 + 245 289 struct ib_uverbs_create_cq { 246 290 __u64 response; 247 291 __u64 user_handle; 248 292 __u32 cqe; 249 - __u32 event_handler; 293 + __u32 comp_vector; 294 + __s32 comp_channel; 295 + __u32 reserved; 250 296 __u64 driver_data[0]; 251 297 }; 252 298 253 299 struct ib_uverbs_create_cq_resp { 254 300 __u32 cq_handle; 255 301 __u32 cqe; 302 + }; 303 + 304 + struct ib_uverbs_poll_cq { 305 + __u64 response; 306 + __u32 cq_handle; 307 + __u32 ne; 308 + }; 309 + 310 + struct ib_uverbs_wc { 311 + __u64 wr_id; 312 + __u32 status; 313 + __u32 opcode; 314 + __u32 vendor_err; 315 + __u32 byte_len; 316 + __u32 imm_data; 317 + __u32 qp_num; 318 + __u32 src_qp; 319 + __u32 wc_flags; 320 + __u16 pkey_index; 321 + __u16 slid; 322 + __u8 sl; 323 + __u8 dlid_path_bits; 324 + __u8 port_num; 325 + __u8 reserved; 326 + }; 327 + 328 + struct ib_uverbs_poll_cq_resp { 329 + __u32 count; 330 + __u32 reserved; 331 + struct ib_uverbs_wc wc[0]; 332 + }; 333 + 334 + struct ib_uverbs_req_notify_cq { 335 + __u32 cq_handle; 336 + __u32 solicited_only; 256 337 }; 257 338 258 339 struct ib_uverbs_destroy_cq { ··· 395 386 396 387 struct ib_uverbs_destroy_qp_resp { 397 388 __u32 events_reported; 389 + }; 390 + 391 + /* 392 + * The ib_uverbs_sge structure isn't used anywhere, since we assume 393 + * the ib_sge structure is packed the same way on 32-bit and 64-bit 394 + * architectures in both kernel and user space. It's just here to 395 + * document the ABI. 396 + */ 397 + struct ib_uverbs_sge { 398 + __u64 addr; 399 + __u32 length; 400 + __u32 lkey; 401 + }; 402 + 403 + struct ib_uverbs_send_wr { 404 + __u64 wr_id; 405 + __u32 num_sge; 406 + __u32 opcode; 407 + __u32 send_flags; 408 + __u32 imm_data; 409 + union { 410 + struct { 411 + __u64 remote_addr; 412 + __u32 rkey; 413 + __u32 reserved; 414 + } rdma; 415 + struct { 416 + __u64 remote_addr; 417 + __u64 compare_add; 418 + __u64 swap; 419 + __u32 rkey; 420 + __u32 reserved; 421 + } atomic; 422 + struct { 423 + __u32 ah; 424 + __u32 remote_qpn; 425 + __u32 remote_qkey; 426 + __u32 reserved; 427 + } ud; 428 + } wr; 429 + }; 430 + 431 + struct ib_uverbs_post_send { 432 + __u64 response; 433 + __u32 qp_handle; 434 + __u32 wr_count; 435 + __u32 sge_count; 436 + __u32 wqe_size; 437 + struct ib_uverbs_send_wr send_wr[0]; 438 + }; 439 + 440 + struct ib_uverbs_post_send_resp { 441 + __u32 bad_wr; 442 + }; 443 + 444 + struct ib_uverbs_recv_wr { 445 + __u64 wr_id; 446 + __u32 num_sge; 447 + __u32 reserved; 448 + }; 449 + 450 + struct ib_uverbs_post_recv { 451 + __u64 response; 452 + __u32 qp_handle; 453 + __u32 wr_count; 454 + __u32 sge_count; 455 + __u32 wqe_size; 456 + struct ib_uverbs_recv_wr recv_wr[0]; 457 + }; 458 + 459 + struct ib_uverbs_post_recv_resp { 460 + __u32 bad_wr; 461 + }; 462 + 463 + struct ib_uverbs_post_srq_recv { 464 + __u64 response; 465 + __u32 srq_handle; 466 + __u32 wr_count; 467 + __u32 sge_count; 468 + __u32 wqe_size; 469 + struct ib_uverbs_recv_wr recv[0]; 470 + }; 471 + 472 + struct ib_uverbs_post_srq_recv_resp { 473 + __u32 bad_wr; 474 + }; 475 + 476 + struct ib_uverbs_global_route { 477 + __u8 dgid[16]; 478 + __u32 flow_label; 479 + __u8 sgid_index; 480 + __u8 hop_limit; 481 + __u8 traffic_class; 482 + __u8 reserved; 483 + }; 484 + 485 + struct ib_uverbs_ah_attr { 486 + struct ib_uverbs_global_route grh; 487 + __u16 dlid; 488 + __u8 sl; 489 + __u8 src_path_bits; 490 + __u8 static_rate; 491 + __u8 is_global; 492 + __u8 port_num; 493 + __u8 reserved; 494 + }; 495 + 496 + struct ib_uverbs_create_ah { 497 + __u64 response; 498 + __u64 user_handle; 499 + __u32 pd_handle; 500 + __u32 reserved; 501 + struct ib_uverbs_ah_attr attr; 502 + }; 503 + 504 + struct ib_uverbs_create_ah_resp { 505 + __u32 ah_handle; 506 + }; 507 + 508 + struct ib_uverbs_destroy_ah { 509 + __u32 ah_handle; 398 510 }; 399 511 400 512 struct ib_uverbs_attach_mcast {
+3 -3
include/rdma/ib_verbs.h
··· 595 595 } atomic; 596 596 struct { 597 597 struct ib_ah *ah; 598 - struct ib_mad_hdr *mad_hdr; 599 598 u32 remote_qpn; 600 599 u32 remote_qkey; 601 - int timeout_ms; /* valid for MADs only */ 602 - int retries; /* valid for MADs only */ 603 600 u16 pkey_index; /* valid for GSI only */ 604 601 u8 port_num; /* valid for DR SMPs on switch only */ 605 602 } ud; ··· 947 950 IB_DEV_REGISTERED, 948 951 IB_DEV_UNREGISTERED 949 952 } reg_state; 953 + 954 + u64 uverbs_cmd_mask; 955 + int uverbs_abi_ver; 950 956 951 957 u8 node_type; 952 958 u8 phys_port_cnt;