Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004 Topspin Communications. All rights reserved. |
Roland Dreier | 43506d9 | 2007-07-09 16:17:32 -0700 | [diff] [blame] | 3 | * Copyright (c) 2005 Voltaire, Inc. All rights reserved. |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 4 | * Copyright (c) 2006 Intel Corporation. All rights reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * This software is available to you under a choice of one of two |
| 7 | * licenses. You may choose to be licensed under the terms of the GNU |
| 8 | * General Public License (GPL) Version 2, available from the file |
| 9 | * COPYING in the main directory of this source tree, or the |
| 10 | * OpenIB.org BSD license below: |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or |
| 13 | * without modification, are permitted provided that the following |
| 14 | * conditions are met: |
| 15 | * |
| 16 | * - Redistributions of source code must retain the above |
| 17 | * copyright notice, this list of conditions and the following |
| 18 | * disclaimer. |
| 19 | * |
| 20 | * - Redistributions in binary form must reproduce the above |
| 21 | * copyright notice, this list of conditions and the following |
| 22 | * disclaimer in the documentation and/or other materials |
| 23 | * provided with the distribution. |
| 24 | * |
| 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 29 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 30 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 31 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 32 | * SOFTWARE. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | */ |
| 34 | |
| 35 | #include <linux/module.h> |
| 36 | #include <linux/init.h> |
| 37 | #include <linux/err.h> |
| 38 | #include <linux/random.h> |
| 39 | #include <linux/spinlock.h> |
| 40 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/dma-mapping.h> |
| 42 | #include <linux/kref.h> |
| 43 | #include <linux/idr.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 44 | #include <linux/workqueue.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Roland Dreier | a4d61e8 | 2005-08-25 13:40:04 -0700 | [diff] [blame] | 46 | #include <rdma/ib_pack.h> |
Sean Hefty | 6d969a4 | 2006-06-17 20:37:39 -0700 | [diff] [blame] | 47 | #include <rdma/ib_cache.h> |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 48 | #include "sa.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | MODULE_AUTHOR("Roland Dreier"); |
| 51 | MODULE_DESCRIPTION("InfiniBand subnet administration query support"); |
| 52 | MODULE_LICENSE("Dual BSD/GPL"); |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | struct ib_sa_sm_ah { |
| 55 | struct ib_ah *ah; |
| 56 | struct kref ref; |
Sean Hefty | 2aec5c6 | 2007-06-18 11:03:58 -0700 | [diff] [blame] | 57 | u16 pkey_index; |
Sean Hefty | d0e7bb1 | 2007-04-05 10:51:10 -0700 | [diff] [blame] | 58 | u8 src_path_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | struct ib_sa_port { |
| 62 | struct ib_mad_agent *agent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | struct ib_sa_sm_ah *sm_ah; |
| 64 | struct work_struct update_task; |
| 65 | spinlock_t ah_lock; |
| 66 | u8 port_num; |
| 67 | }; |
| 68 | |
| 69 | struct ib_sa_device { |
| 70 | int start_port, end_port; |
| 71 | struct ib_event_handler event_handler; |
| 72 | struct ib_sa_port port[0]; |
| 73 | }; |
| 74 | |
| 75 | struct ib_sa_query { |
| 76 | void (*callback)(struct ib_sa_query *, int, struct ib_sa_mad *); |
| 77 | void (*release)(struct ib_sa_query *); |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 78 | struct ib_sa_client *client; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 79 | struct ib_sa_port *port; |
| 80 | struct ib_mad_send_buf *mad_buf; |
| 81 | struct ib_sa_sm_ah *sm_ah; |
| 82 | int id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 85 | struct ib_sa_service_query { |
| 86 | void (*callback)(int, struct ib_sa_service_rec *, void *); |
| 87 | void *context; |
| 88 | struct ib_sa_query sa_query; |
| 89 | }; |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | struct ib_sa_path_query { |
| 92 | void (*callback)(int, struct ib_sa_path_rec *, void *); |
| 93 | void *context; |
| 94 | struct ib_sa_query sa_query; |
| 95 | }; |
| 96 | |
| 97 | struct ib_sa_mcmember_query { |
| 98 | void (*callback)(int, struct ib_sa_mcmember_rec *, void *); |
| 99 | void *context; |
| 100 | struct ib_sa_query sa_query; |
| 101 | }; |
| 102 | |
| 103 | static void ib_sa_add_one(struct ib_device *device); |
| 104 | static void ib_sa_remove_one(struct ib_device *device); |
| 105 | |
| 106 | static struct ib_client sa_client = { |
| 107 | .name = "sa", |
| 108 | .add = ib_sa_add_one, |
| 109 | .remove = ib_sa_remove_one |
| 110 | }; |
| 111 | |
| 112 | static spinlock_t idr_lock; |
| 113 | static DEFINE_IDR(query_idr); |
| 114 | |
| 115 | static spinlock_t tid_lock; |
| 116 | static u32 tid; |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #define PATH_REC_FIELD(field) \ |
| 119 | .struct_offset_bytes = offsetof(struct ib_sa_path_rec, field), \ |
| 120 | .struct_size_bytes = sizeof ((struct ib_sa_path_rec *) 0)->field, \ |
| 121 | .field_name = "sa_path_rec:" #field |
| 122 | |
| 123 | static const struct ib_field path_rec_table[] = { |
Sean Hefty | 733d65f | 2007-08-08 15:41:28 -0700 | [diff] [blame] | 124 | { PATH_REC_FIELD(service_id), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | .offset_words = 0, |
| 126 | .offset_bits = 0, |
Sean Hefty | 733d65f | 2007-08-08 15:41:28 -0700 | [diff] [blame] | 127 | .size_bits = 64 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { PATH_REC_FIELD(dgid), |
| 129 | .offset_words = 2, |
| 130 | .offset_bits = 0, |
| 131 | .size_bits = 128 }, |
| 132 | { PATH_REC_FIELD(sgid), |
| 133 | .offset_words = 6, |
| 134 | .offset_bits = 0, |
| 135 | .size_bits = 128 }, |
| 136 | { PATH_REC_FIELD(dlid), |
| 137 | .offset_words = 10, |
| 138 | .offset_bits = 0, |
| 139 | .size_bits = 16 }, |
| 140 | { PATH_REC_FIELD(slid), |
| 141 | .offset_words = 10, |
| 142 | .offset_bits = 16, |
| 143 | .size_bits = 16 }, |
| 144 | { PATH_REC_FIELD(raw_traffic), |
| 145 | .offset_words = 11, |
| 146 | .offset_bits = 0, |
| 147 | .size_bits = 1 }, |
| 148 | { RESERVED, |
| 149 | .offset_words = 11, |
| 150 | .offset_bits = 1, |
| 151 | .size_bits = 3 }, |
| 152 | { PATH_REC_FIELD(flow_label), |
| 153 | .offset_words = 11, |
| 154 | .offset_bits = 4, |
| 155 | .size_bits = 20 }, |
| 156 | { PATH_REC_FIELD(hop_limit), |
| 157 | .offset_words = 11, |
| 158 | .offset_bits = 24, |
| 159 | .size_bits = 8 }, |
| 160 | { PATH_REC_FIELD(traffic_class), |
| 161 | .offset_words = 12, |
| 162 | .offset_bits = 0, |
| 163 | .size_bits = 8 }, |
| 164 | { PATH_REC_FIELD(reversible), |
| 165 | .offset_words = 12, |
| 166 | .offset_bits = 8, |
| 167 | .size_bits = 1 }, |
| 168 | { PATH_REC_FIELD(numb_path), |
| 169 | .offset_words = 12, |
| 170 | .offset_bits = 9, |
| 171 | .size_bits = 7 }, |
| 172 | { PATH_REC_FIELD(pkey), |
| 173 | .offset_words = 12, |
| 174 | .offset_bits = 16, |
| 175 | .size_bits = 16 }, |
Sean Hefty | 733d65f | 2007-08-08 15:41:28 -0700 | [diff] [blame] | 176 | { PATH_REC_FIELD(qos_class), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | .offset_words = 13, |
| 178 | .offset_bits = 0, |
| 179 | .size_bits = 12 }, |
| 180 | { PATH_REC_FIELD(sl), |
| 181 | .offset_words = 13, |
| 182 | .offset_bits = 12, |
| 183 | .size_bits = 4 }, |
| 184 | { PATH_REC_FIELD(mtu_selector), |
| 185 | .offset_words = 13, |
| 186 | .offset_bits = 16, |
| 187 | .size_bits = 2 }, |
| 188 | { PATH_REC_FIELD(mtu), |
| 189 | .offset_words = 13, |
| 190 | .offset_bits = 18, |
| 191 | .size_bits = 6 }, |
| 192 | { PATH_REC_FIELD(rate_selector), |
| 193 | .offset_words = 13, |
| 194 | .offset_bits = 24, |
| 195 | .size_bits = 2 }, |
| 196 | { PATH_REC_FIELD(rate), |
| 197 | .offset_words = 13, |
| 198 | .offset_bits = 26, |
| 199 | .size_bits = 6 }, |
| 200 | { PATH_REC_FIELD(packet_life_time_selector), |
| 201 | .offset_words = 14, |
| 202 | .offset_bits = 0, |
| 203 | .size_bits = 2 }, |
| 204 | { PATH_REC_FIELD(packet_life_time), |
| 205 | .offset_words = 14, |
| 206 | .offset_bits = 2, |
| 207 | .size_bits = 6 }, |
| 208 | { PATH_REC_FIELD(preference), |
| 209 | .offset_words = 14, |
| 210 | .offset_bits = 8, |
| 211 | .size_bits = 8 }, |
| 212 | { RESERVED, |
| 213 | .offset_words = 14, |
| 214 | .offset_bits = 16, |
| 215 | .size_bits = 48 }, |
| 216 | }; |
| 217 | |
| 218 | #define MCMEMBER_REC_FIELD(field) \ |
| 219 | .struct_offset_bytes = offsetof(struct ib_sa_mcmember_rec, field), \ |
| 220 | .struct_size_bytes = sizeof ((struct ib_sa_mcmember_rec *) 0)->field, \ |
| 221 | .field_name = "sa_mcmember_rec:" #field |
| 222 | |
| 223 | static const struct ib_field mcmember_rec_table[] = { |
| 224 | { MCMEMBER_REC_FIELD(mgid), |
| 225 | .offset_words = 0, |
| 226 | .offset_bits = 0, |
| 227 | .size_bits = 128 }, |
| 228 | { MCMEMBER_REC_FIELD(port_gid), |
| 229 | .offset_words = 4, |
| 230 | .offset_bits = 0, |
| 231 | .size_bits = 128 }, |
| 232 | { MCMEMBER_REC_FIELD(qkey), |
| 233 | .offset_words = 8, |
| 234 | .offset_bits = 0, |
| 235 | .size_bits = 32 }, |
| 236 | { MCMEMBER_REC_FIELD(mlid), |
| 237 | .offset_words = 9, |
| 238 | .offset_bits = 0, |
| 239 | .size_bits = 16 }, |
| 240 | { MCMEMBER_REC_FIELD(mtu_selector), |
| 241 | .offset_words = 9, |
| 242 | .offset_bits = 16, |
| 243 | .size_bits = 2 }, |
| 244 | { MCMEMBER_REC_FIELD(mtu), |
| 245 | .offset_words = 9, |
| 246 | .offset_bits = 18, |
| 247 | .size_bits = 6 }, |
| 248 | { MCMEMBER_REC_FIELD(traffic_class), |
| 249 | .offset_words = 9, |
| 250 | .offset_bits = 24, |
| 251 | .size_bits = 8 }, |
| 252 | { MCMEMBER_REC_FIELD(pkey), |
| 253 | .offset_words = 10, |
| 254 | .offset_bits = 0, |
| 255 | .size_bits = 16 }, |
| 256 | { MCMEMBER_REC_FIELD(rate_selector), |
| 257 | .offset_words = 10, |
| 258 | .offset_bits = 16, |
| 259 | .size_bits = 2 }, |
| 260 | { MCMEMBER_REC_FIELD(rate), |
| 261 | .offset_words = 10, |
| 262 | .offset_bits = 18, |
| 263 | .size_bits = 6 }, |
| 264 | { MCMEMBER_REC_FIELD(packet_life_time_selector), |
| 265 | .offset_words = 10, |
| 266 | .offset_bits = 24, |
| 267 | .size_bits = 2 }, |
| 268 | { MCMEMBER_REC_FIELD(packet_life_time), |
| 269 | .offset_words = 10, |
| 270 | .offset_bits = 26, |
| 271 | .size_bits = 6 }, |
| 272 | { MCMEMBER_REC_FIELD(sl), |
| 273 | .offset_words = 11, |
| 274 | .offset_bits = 0, |
| 275 | .size_bits = 4 }, |
| 276 | { MCMEMBER_REC_FIELD(flow_label), |
| 277 | .offset_words = 11, |
| 278 | .offset_bits = 4, |
| 279 | .size_bits = 20 }, |
| 280 | { MCMEMBER_REC_FIELD(hop_limit), |
| 281 | .offset_words = 11, |
| 282 | .offset_bits = 24, |
| 283 | .size_bits = 8 }, |
| 284 | { MCMEMBER_REC_FIELD(scope), |
| 285 | .offset_words = 12, |
| 286 | .offset_bits = 0, |
| 287 | .size_bits = 4 }, |
| 288 | { MCMEMBER_REC_FIELD(join_state), |
| 289 | .offset_words = 12, |
| 290 | .offset_bits = 4, |
| 291 | .size_bits = 4 }, |
| 292 | { MCMEMBER_REC_FIELD(proxy_join), |
| 293 | .offset_words = 12, |
| 294 | .offset_bits = 8, |
| 295 | .size_bits = 1 }, |
| 296 | { RESERVED, |
| 297 | .offset_words = 12, |
| 298 | .offset_bits = 9, |
| 299 | .size_bits = 23 }, |
| 300 | }; |
| 301 | |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 302 | #define SERVICE_REC_FIELD(field) \ |
| 303 | .struct_offset_bytes = offsetof(struct ib_sa_service_rec, field), \ |
| 304 | .struct_size_bytes = sizeof ((struct ib_sa_service_rec *) 0)->field, \ |
| 305 | .field_name = "sa_service_rec:" #field |
| 306 | |
| 307 | static const struct ib_field service_rec_table[] = { |
| 308 | { SERVICE_REC_FIELD(id), |
| 309 | .offset_words = 0, |
| 310 | .offset_bits = 0, |
| 311 | .size_bits = 64 }, |
| 312 | { SERVICE_REC_FIELD(gid), |
| 313 | .offset_words = 2, |
| 314 | .offset_bits = 0, |
| 315 | .size_bits = 128 }, |
| 316 | { SERVICE_REC_FIELD(pkey), |
| 317 | .offset_words = 6, |
| 318 | .offset_bits = 0, |
| 319 | .size_bits = 16 }, |
| 320 | { SERVICE_REC_FIELD(lease), |
| 321 | .offset_words = 7, |
| 322 | .offset_bits = 0, |
| 323 | .size_bits = 32 }, |
| 324 | { SERVICE_REC_FIELD(key), |
| 325 | .offset_words = 8, |
| 326 | .offset_bits = 0, |
| 327 | .size_bits = 128 }, |
| 328 | { SERVICE_REC_FIELD(name), |
| 329 | .offset_words = 12, |
| 330 | .offset_bits = 0, |
| 331 | .size_bits = 64*8 }, |
| 332 | { SERVICE_REC_FIELD(data8), |
| 333 | .offset_words = 28, |
| 334 | .offset_bits = 0, |
| 335 | .size_bits = 16*8 }, |
| 336 | { SERVICE_REC_FIELD(data16), |
| 337 | .offset_words = 32, |
| 338 | .offset_bits = 0, |
| 339 | .size_bits = 8*16 }, |
| 340 | { SERVICE_REC_FIELD(data32), |
| 341 | .offset_words = 36, |
| 342 | .offset_bits = 0, |
| 343 | .size_bits = 4*32 }, |
| 344 | { SERVICE_REC_FIELD(data64), |
| 345 | .offset_words = 40, |
| 346 | .offset_bits = 0, |
| 347 | .size_bits = 2*64 }, |
| 348 | }; |
| 349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | static void free_sm_ah(struct kref *kref) |
| 351 | { |
| 352 | struct ib_sa_sm_ah *sm_ah = container_of(kref, struct ib_sa_sm_ah, ref); |
| 353 | |
| 354 | ib_destroy_ah(sm_ah->ah); |
| 355 | kfree(sm_ah); |
| 356 | } |
| 357 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 358 | static void update_sm_ah(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 360 | struct ib_sa_port *port = |
| 361 | container_of(work, struct ib_sa_port, update_task); |
Moni Shoua | 164ba08 | 2008-07-14 23:48:43 -0700 | [diff] [blame] | 362 | struct ib_sa_sm_ah *new_ah; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | struct ib_port_attr port_attr; |
| 364 | struct ib_ah_attr ah_attr; |
| 365 | |
| 366 | if (ib_query_port(port->agent->device, port->port_num, &port_attr)) { |
| 367 | printk(KERN_WARNING "Couldn't query port\n"); |
| 368 | return; |
| 369 | } |
| 370 | |
| 371 | new_ah = kmalloc(sizeof *new_ah, GFP_KERNEL); |
| 372 | if (!new_ah) { |
| 373 | printk(KERN_WARNING "Couldn't allocate new SM AH\n"); |
| 374 | return; |
| 375 | } |
| 376 | |
| 377 | kref_init(&new_ah->ref); |
Sean Hefty | d0e7bb1 | 2007-04-05 10:51:10 -0700 | [diff] [blame] | 378 | new_ah->src_path_mask = (1 << port_attr.lmc) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Sean Hefty | 2aec5c6 | 2007-06-18 11:03:58 -0700 | [diff] [blame] | 380 | new_ah->pkey_index = 0; |
| 381 | if (ib_find_pkey(port->agent->device, port->port_num, |
Roland Dreier | 5399891 | 2007-08-03 10:45:17 -0700 | [diff] [blame] | 382 | IB_DEFAULT_PKEY_FULL, &new_ah->pkey_index)) |
Sean Hefty | 2aec5c6 | 2007-06-18 11:03:58 -0700 | [diff] [blame] | 383 | printk(KERN_ERR "Couldn't find index for default PKey\n"); |
| 384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | memset(&ah_attr, 0, sizeof ah_attr); |
| 386 | ah_attr.dlid = port_attr.sm_lid; |
| 387 | ah_attr.sl = port_attr.sm_sl; |
| 388 | ah_attr.port_num = port->port_num; |
| 389 | |
| 390 | new_ah->ah = ib_create_ah(port->agent->qp->pd, &ah_attr); |
| 391 | if (IS_ERR(new_ah->ah)) { |
| 392 | printk(KERN_WARNING "Couldn't create new SM AH\n"); |
| 393 | kfree(new_ah); |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | spin_lock_irq(&port->ah_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | port->sm_ah = new_ah; |
| 399 | spin_unlock_irq(&port->ah_lock); |
| 400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | static void ib_sa_event(struct ib_event_handler *handler, struct ib_event *event) |
| 404 | { |
| 405 | if (event->event == IB_EVENT_PORT_ERR || |
| 406 | event->event == IB_EVENT_PORT_ACTIVE || |
| 407 | event->event == IB_EVENT_LID_CHANGE || |
| 408 | event->event == IB_EVENT_PKEY_CHANGE || |
Jack Morgenstein | acaea9e | 2006-08-15 17:20:50 +0300 | [diff] [blame] | 409 | event->event == IB_EVENT_SM_CHANGE || |
| 410 | event->event == IB_EVENT_CLIENT_REREGISTER) { |
Moni Shoua | 164ba08 | 2008-07-14 23:48:43 -0700 | [diff] [blame] | 411 | unsigned long flags; |
| 412 | struct ib_sa_device *sa_dev = |
| 413 | container_of(handler, typeof(*sa_dev), event_handler); |
| 414 | struct ib_sa_port *port = |
| 415 | &sa_dev->port[event->element.port_num - sa_dev->start_port]; |
| 416 | |
| 417 | spin_lock_irqsave(&port->ah_lock, flags); |
| 418 | if (port->sm_ah) |
| 419 | kref_put(&port->sm_ah->ref, free_sm_ah); |
| 420 | port->sm_ah = NULL; |
| 421 | spin_unlock_irqrestore(&port->ah_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
| 423 | schedule_work(&sa_dev->port[event->element.port_num - |
| 424 | sa_dev->start_port].update_task); |
| 425 | } |
| 426 | } |
| 427 | |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 428 | void ib_sa_register_client(struct ib_sa_client *client) |
| 429 | { |
| 430 | atomic_set(&client->users, 1); |
| 431 | init_completion(&client->comp); |
| 432 | } |
| 433 | EXPORT_SYMBOL(ib_sa_register_client); |
| 434 | |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 435 | void ib_sa_unregister_client(struct ib_sa_client *client) |
| 436 | { |
| 437 | ib_sa_client_put(client); |
| 438 | wait_for_completion(&client->comp); |
| 439 | } |
| 440 | EXPORT_SYMBOL(ib_sa_unregister_client); |
| 441 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | /** |
| 443 | * ib_sa_cancel_query - try to cancel an SA query |
| 444 | * @id:ID of query to cancel |
| 445 | * @query:query pointer to cancel |
| 446 | * |
| 447 | * Try to cancel an SA query. If the id and query don't match up or |
| 448 | * the query has already completed, nothing is done. Otherwise the |
| 449 | * query is canceled and will complete with a status of -EINTR. |
| 450 | */ |
| 451 | void ib_sa_cancel_query(int id, struct ib_sa_query *query) |
| 452 | { |
| 453 | unsigned long flags; |
| 454 | struct ib_mad_agent *agent; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 455 | struct ib_mad_send_buf *mad_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | |
| 457 | spin_lock_irqsave(&idr_lock, flags); |
| 458 | if (idr_find(&query_idr, id) != query) { |
| 459 | spin_unlock_irqrestore(&idr_lock, flags); |
| 460 | return; |
| 461 | } |
| 462 | agent = query->port->agent; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 463 | mad_buf = query->mad_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | spin_unlock_irqrestore(&idr_lock, flags); |
| 465 | |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 466 | ib_cancel_mad(agent, mad_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
| 468 | EXPORT_SYMBOL(ib_sa_cancel_query); |
| 469 | |
Sean Hefty | d0e7bb1 | 2007-04-05 10:51:10 -0700 | [diff] [blame] | 470 | static u8 get_src_path_mask(struct ib_device *device, u8 port_num) |
| 471 | { |
| 472 | struct ib_sa_device *sa_dev; |
| 473 | struct ib_sa_port *port; |
| 474 | unsigned long flags; |
| 475 | u8 src_path_mask; |
| 476 | |
| 477 | sa_dev = ib_get_client_data(device, &sa_client); |
| 478 | if (!sa_dev) |
| 479 | return 0x7f; |
| 480 | |
| 481 | port = &sa_dev->port[port_num - sa_dev->start_port]; |
| 482 | spin_lock_irqsave(&port->ah_lock, flags); |
| 483 | src_path_mask = port->sm_ah ? port->sm_ah->src_path_mask : 0x7f; |
| 484 | spin_unlock_irqrestore(&port->ah_lock, flags); |
| 485 | |
| 486 | return src_path_mask; |
| 487 | } |
| 488 | |
Sean Hefty | 6d969a4 | 2006-06-17 20:37:39 -0700 | [diff] [blame] | 489 | int ib_init_ah_from_path(struct ib_device *device, u8 port_num, |
| 490 | struct ib_sa_path_rec *rec, struct ib_ah_attr *ah_attr) |
| 491 | { |
| 492 | int ret; |
| 493 | u16 gid_index; |
| 494 | |
| 495 | memset(ah_attr, 0, sizeof *ah_attr); |
| 496 | ah_attr->dlid = be16_to_cpu(rec->dlid); |
| 497 | ah_attr->sl = rec->sl; |
Sean Hefty | d0e7bb1 | 2007-04-05 10:51:10 -0700 | [diff] [blame] | 498 | ah_attr->src_path_bits = be16_to_cpu(rec->slid) & |
| 499 | get_src_path_mask(device, port_num); |
Sean Hefty | 6d969a4 | 2006-06-17 20:37:39 -0700 | [diff] [blame] | 500 | ah_attr->port_num = port_num; |
Roland Dreier | 7084f84 | 2007-02-16 15:31:24 -0800 | [diff] [blame] | 501 | ah_attr->static_rate = rec->rate; |
Sean Hefty | 6d969a4 | 2006-06-17 20:37:39 -0700 | [diff] [blame] | 502 | |
| 503 | if (rec->hop_limit > 1) { |
| 504 | ah_attr->ah_flags = IB_AH_GRH; |
| 505 | ah_attr->grh.dgid = rec->dgid; |
| 506 | |
| 507 | ret = ib_find_cached_gid(device, &rec->sgid, &port_num, |
| 508 | &gid_index); |
| 509 | if (ret) |
| 510 | return ret; |
| 511 | |
Sean Hefty | ca222c6 | 2006-06-17 20:37:40 -0700 | [diff] [blame] | 512 | ah_attr->grh.sgid_index = gid_index; |
| 513 | ah_attr->grh.flow_label = be32_to_cpu(rec->flow_label); |
| 514 | ah_attr->grh.hop_limit = rec->hop_limit; |
Sean Hefty | 6d969a4 | 2006-06-17 20:37:39 -0700 | [diff] [blame] | 515 | ah_attr->grh.traffic_class = rec->traffic_class; |
| 516 | } |
| 517 | return 0; |
| 518 | } |
| 519 | EXPORT_SYMBOL(ib_init_ah_from_path); |
| 520 | |
Sean Hefty | 2aec5c6 | 2007-06-18 11:03:58 -0700 | [diff] [blame] | 521 | static int alloc_mad(struct ib_sa_query *query, gfp_t gfp_mask) |
| 522 | { |
| 523 | unsigned long flags; |
| 524 | |
| 525 | spin_lock_irqsave(&query->port->ah_lock, flags); |
Moni Shoua | 164ba08 | 2008-07-14 23:48:43 -0700 | [diff] [blame] | 526 | if (!query->port->sm_ah) { |
| 527 | spin_unlock_irqrestore(&query->port->ah_lock, flags); |
| 528 | return -EAGAIN; |
| 529 | } |
Sean Hefty | 2aec5c6 | 2007-06-18 11:03:58 -0700 | [diff] [blame] | 530 | kref_get(&query->port->sm_ah->ref); |
| 531 | query->sm_ah = query->port->sm_ah; |
| 532 | spin_unlock_irqrestore(&query->port->ah_lock, flags); |
| 533 | |
| 534 | query->mad_buf = ib_create_send_mad(query->port->agent, 1, |
| 535 | query->sm_ah->pkey_index, |
| 536 | 0, IB_MGMT_SA_HDR, IB_MGMT_SA_DATA, |
| 537 | gfp_mask); |
Ali Ayoub | 3c10c7c | 2007-09-09 14:55:11 +0300 | [diff] [blame] | 538 | if (IS_ERR(query->mad_buf)) { |
Sean Hefty | 2aec5c6 | 2007-06-18 11:03:58 -0700 | [diff] [blame] | 539 | kref_put(&query->sm_ah->ref, free_sm_ah); |
| 540 | return -ENOMEM; |
| 541 | } |
| 542 | |
| 543 | query->mad_buf->ah = query->sm_ah->ah; |
| 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | static void free_mad(struct ib_sa_query *query) |
| 549 | { |
| 550 | ib_free_send_mad(query->mad_buf); |
| 551 | kref_put(&query->sm_ah->ref, free_sm_ah); |
| 552 | } |
| 553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | static void init_mad(struct ib_sa_mad *mad, struct ib_mad_agent *agent) |
| 555 | { |
| 556 | unsigned long flags; |
| 557 | |
| 558 | memset(mad, 0, sizeof *mad); |
| 559 | |
| 560 | mad->mad_hdr.base_version = IB_MGMT_BASE_VERSION; |
| 561 | mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_SUBN_ADM; |
| 562 | mad->mad_hdr.class_version = IB_SA_CLASS_VERSION; |
| 563 | |
| 564 | spin_lock_irqsave(&tid_lock, flags); |
| 565 | mad->mad_hdr.tid = |
| 566 | cpu_to_be64(((u64) agent->hi_tid) << 32 | tid++); |
| 567 | spin_unlock_irqrestore(&tid_lock, flags); |
| 568 | } |
| 569 | |
Michael S. Tsirkin | e322fed | 2006-07-14 00:23:56 -0700 | [diff] [blame] | 570 | static int send_mad(struct ib_sa_query *query, int timeout_ms, gfp_t gfp_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | unsigned long flags; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 573 | int ret, id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
| 575 | retry: |
Michael S. Tsirkin | e322fed | 2006-07-14 00:23:56 -0700 | [diff] [blame] | 576 | if (!idr_pre_get(&query_idr, gfp_mask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | return -ENOMEM; |
| 578 | spin_lock_irqsave(&idr_lock, flags); |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 579 | ret = idr_get_new(&query_idr, query, &id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | spin_unlock_irqrestore(&idr_lock, flags); |
| 581 | if (ret == -EAGAIN) |
| 582 | goto retry; |
| 583 | if (ret) |
| 584 | return ret; |
| 585 | |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 586 | query->mad_buf->timeout_ms = timeout_ms; |
| 587 | query->mad_buf->context[0] = query; |
| 588 | query->id = id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 590 | ret = ib_post_send_mad(query->mad_buf, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | if (ret) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | spin_lock_irqsave(&idr_lock, flags); |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 593 | idr_remove(&query_idr, id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | spin_unlock_irqrestore(&idr_lock, flags); |
| 595 | } |
| 596 | |
Roland Dreier | dae4c1d | 2005-06-27 14:36:46 -0700 | [diff] [blame] | 597 | /* |
| 598 | * It's not safe to dereference query any more, because the |
| 599 | * send may already have completed and freed the query in |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 600 | * another context. |
Roland Dreier | dae4c1d | 2005-06-27 14:36:46 -0700 | [diff] [blame] | 601 | */ |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 602 | return ret ? ret : id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query, |
| 606 | int status, |
| 607 | struct ib_sa_mad *mad) |
| 608 | { |
| 609 | struct ib_sa_path_query *query = |
| 610 | container_of(sa_query, struct ib_sa_path_query, sa_query); |
| 611 | |
| 612 | if (mad) { |
| 613 | struct ib_sa_path_rec rec; |
| 614 | |
| 615 | ib_unpack(path_rec_table, ARRAY_SIZE(path_rec_table), |
| 616 | mad->data, &rec); |
| 617 | query->callback(status, &rec, query->context); |
| 618 | } else |
| 619 | query->callback(status, NULL, query->context); |
| 620 | } |
| 621 | |
| 622 | static void ib_sa_path_rec_release(struct ib_sa_query *sa_query) |
| 623 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | kfree(container_of(sa_query, struct ib_sa_path_query, sa_query)); |
| 625 | } |
| 626 | |
| 627 | /** |
| 628 | * ib_sa_path_rec_get - Start a Path get query |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 629 | * @client:SA client |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | * @device:device to send query on |
| 631 | * @port_num: port number to send query on |
| 632 | * @rec:Path Record to send in query |
| 633 | * @comp_mask:component mask to send in query |
| 634 | * @timeout_ms:time to wait for response |
| 635 | * @gfp_mask:GFP mask to use for internal allocations |
| 636 | * @callback:function called when query completes, times out or is |
| 637 | * canceled |
| 638 | * @context:opaque user context passed to callback |
| 639 | * @sa_query:query context, used to cancel query |
| 640 | * |
| 641 | * Send a Path Record Get query to the SA to look up a path. The |
| 642 | * callback function will be called when the query completes (or |
| 643 | * fails); status is 0 for a successful response, -EINTR if the query |
| 644 | * is canceled, -ETIMEDOUT is the query timed out, or -EIO if an error |
| 645 | * occurred sending the query. The resp parameter of the callback is |
| 646 | * only valid if status is 0. |
| 647 | * |
| 648 | * If the return value of ib_sa_path_rec_get() is negative, it is an |
| 649 | * error code. Otherwise it is a query ID that can be used to cancel |
| 650 | * the query. |
| 651 | */ |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 652 | int ib_sa_path_rec_get(struct ib_sa_client *client, |
| 653 | struct ib_device *device, u8 port_num, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | struct ib_sa_path_rec *rec, |
| 655 | ib_sa_comp_mask comp_mask, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 656 | int timeout_ms, gfp_t gfp_mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | void (*callback)(int status, |
| 658 | struct ib_sa_path_rec *resp, |
| 659 | void *context), |
| 660 | void *context, |
| 661 | struct ib_sa_query **sa_query) |
| 662 | { |
| 663 | struct ib_sa_path_query *query; |
| 664 | struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client); |
Roland Dreier | 56c202d | 2005-10-13 10:45:02 -0700 | [diff] [blame] | 665 | struct ib_sa_port *port; |
| 666 | struct ib_mad_agent *agent; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 667 | struct ib_sa_mad *mad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | int ret; |
| 669 | |
Roland Dreier | 56c202d | 2005-10-13 10:45:02 -0700 | [diff] [blame] | 670 | if (!sa_dev) |
| 671 | return -ENODEV; |
| 672 | |
| 673 | port = &sa_dev->port[port_num - sa_dev->start_port]; |
| 674 | agent = port->agent; |
| 675 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | query = kmalloc(sizeof *query, gfp_mask); |
| 677 | if (!query) |
| 678 | return -ENOMEM; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 679 | |
Sean Hefty | 2aec5c6 | 2007-06-18 11:03:58 -0700 | [diff] [blame] | 680 | query->sa_query.port = port; |
| 681 | ret = alloc_mad(&query->sa_query, gfp_mask); |
| 682 | if (ret) |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 683 | goto err1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 685 | ib_sa_client_get(client); |
| 686 | query->sa_query.client = client; |
| 687 | query->callback = callback; |
| 688 | query->context = context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 690 | mad = query->sa_query.mad_buf->mad; |
| 691 | init_mad(mad, agent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 693 | query->sa_query.callback = callback ? ib_sa_path_rec_callback : NULL; |
| 694 | query->sa_query.release = ib_sa_path_rec_release; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 695 | mad->mad_hdr.method = IB_MGMT_METHOD_GET; |
| 696 | mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_PATH_REC); |
| 697 | mad->sa_hdr.comp_mask = comp_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 699 | ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table), rec, mad->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
| 701 | *sa_query = &query->sa_query; |
Roland Dreier | dae4c1d | 2005-06-27 14:36:46 -0700 | [diff] [blame] | 702 | |
Michael S. Tsirkin | e322fed | 2006-07-14 00:23:56 -0700 | [diff] [blame] | 703 | ret = send_mad(&query->sa_query, timeout_ms, gfp_mask); |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 704 | if (ret < 0) |
| 705 | goto err2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
Roland Dreier | dae4c1d | 2005-06-27 14:36:46 -0700 | [diff] [blame] | 707 | return ret; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 708 | |
| 709 | err2: |
| 710 | *sa_query = NULL; |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 711 | ib_sa_client_put(query->sa_query.client); |
Sean Hefty | 2aec5c6 | 2007-06-18 11:03:58 -0700 | [diff] [blame] | 712 | free_mad(&query->sa_query); |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 713 | |
| 714 | err1: |
| 715 | kfree(query); |
| 716 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | EXPORT_SYMBOL(ib_sa_path_rec_get); |
| 719 | |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 720 | static void ib_sa_service_rec_callback(struct ib_sa_query *sa_query, |
| 721 | int status, |
| 722 | struct ib_sa_mad *mad) |
| 723 | { |
| 724 | struct ib_sa_service_query *query = |
| 725 | container_of(sa_query, struct ib_sa_service_query, sa_query); |
| 726 | |
| 727 | if (mad) { |
| 728 | struct ib_sa_service_rec rec; |
| 729 | |
| 730 | ib_unpack(service_rec_table, ARRAY_SIZE(service_rec_table), |
| 731 | mad->data, &rec); |
| 732 | query->callback(status, &rec, query->context); |
| 733 | } else |
| 734 | query->callback(status, NULL, query->context); |
| 735 | } |
| 736 | |
| 737 | static void ib_sa_service_rec_release(struct ib_sa_query *sa_query) |
| 738 | { |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 739 | kfree(container_of(sa_query, struct ib_sa_service_query, sa_query)); |
| 740 | } |
| 741 | |
| 742 | /** |
| 743 | * ib_sa_service_rec_query - Start Service Record operation |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 744 | * @client:SA client |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 745 | * @device:device to send request on |
| 746 | * @port_num: port number to send request on |
| 747 | * @method:SA method - should be get, set, or delete |
| 748 | * @rec:Service Record to send in request |
| 749 | * @comp_mask:component mask to send in request |
| 750 | * @timeout_ms:time to wait for response |
| 751 | * @gfp_mask:GFP mask to use for internal allocations |
| 752 | * @callback:function called when request completes, times out or is |
| 753 | * canceled |
| 754 | * @context:opaque user context passed to callback |
| 755 | * @sa_query:request context, used to cancel request |
| 756 | * |
| 757 | * Send a Service Record set/get/delete to the SA to register, |
| 758 | * unregister or query a service record. |
| 759 | * The callback function will be called when the request completes (or |
| 760 | * fails); status is 0 for a successful response, -EINTR if the query |
| 761 | * is canceled, -ETIMEDOUT is the query timed out, or -EIO if an error |
| 762 | * occurred sending the query. The resp parameter of the callback is |
| 763 | * only valid if status is 0. |
| 764 | * |
| 765 | * If the return value of ib_sa_service_rec_query() is negative, it is an |
| 766 | * error code. Otherwise it is a request ID that can be used to cancel |
| 767 | * the query. |
| 768 | */ |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 769 | int ib_sa_service_rec_query(struct ib_sa_client *client, |
| 770 | struct ib_device *device, u8 port_num, u8 method, |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 771 | struct ib_sa_service_rec *rec, |
| 772 | ib_sa_comp_mask comp_mask, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 773 | int timeout_ms, gfp_t gfp_mask, |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 774 | void (*callback)(int status, |
| 775 | struct ib_sa_service_rec *resp, |
| 776 | void *context), |
| 777 | void *context, |
| 778 | struct ib_sa_query **sa_query) |
| 779 | { |
| 780 | struct ib_sa_service_query *query; |
| 781 | struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client); |
Roland Dreier | 56c202d | 2005-10-13 10:45:02 -0700 | [diff] [blame] | 782 | struct ib_sa_port *port; |
| 783 | struct ib_mad_agent *agent; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 784 | struct ib_sa_mad *mad; |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 785 | int ret; |
| 786 | |
Roland Dreier | 56c202d | 2005-10-13 10:45:02 -0700 | [diff] [blame] | 787 | if (!sa_dev) |
| 788 | return -ENODEV; |
| 789 | |
| 790 | port = &sa_dev->port[port_num - sa_dev->start_port]; |
| 791 | agent = port->agent; |
| 792 | |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 793 | if (method != IB_MGMT_METHOD_GET && |
| 794 | method != IB_MGMT_METHOD_SET && |
| 795 | method != IB_SA_METHOD_DELETE) |
| 796 | return -EINVAL; |
| 797 | |
| 798 | query = kmalloc(sizeof *query, gfp_mask); |
| 799 | if (!query) |
| 800 | return -ENOMEM; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 801 | |
Sean Hefty | 2aec5c6 | 2007-06-18 11:03:58 -0700 | [diff] [blame] | 802 | query->sa_query.port = port; |
| 803 | ret = alloc_mad(&query->sa_query, gfp_mask); |
| 804 | if (ret) |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 805 | goto err1; |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 806 | |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 807 | ib_sa_client_get(client); |
| 808 | query->sa_query.client = client; |
| 809 | query->callback = callback; |
| 810 | query->context = context; |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 811 | |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 812 | mad = query->sa_query.mad_buf->mad; |
| 813 | init_mad(mad, agent); |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 814 | |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 815 | query->sa_query.callback = callback ? ib_sa_service_rec_callback : NULL; |
| 816 | query->sa_query.release = ib_sa_service_rec_release; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 817 | mad->mad_hdr.method = method; |
| 818 | mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_SERVICE_REC); |
| 819 | mad->sa_hdr.comp_mask = comp_mask; |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 820 | |
| 821 | ib_pack(service_rec_table, ARRAY_SIZE(service_rec_table), |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 822 | rec, mad->data); |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 823 | |
| 824 | *sa_query = &query->sa_query; |
| 825 | |
Michael S. Tsirkin | e322fed | 2006-07-14 00:23:56 -0700 | [diff] [blame] | 826 | ret = send_mad(&query->sa_query, timeout_ms, gfp_mask); |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 827 | if (ret < 0) |
| 828 | goto err2; |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 829 | |
| 830 | return ret; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 831 | |
| 832 | err2: |
| 833 | *sa_query = NULL; |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 834 | ib_sa_client_put(query->sa_query.client); |
Sean Hefty | 2aec5c6 | 2007-06-18 11:03:58 -0700 | [diff] [blame] | 835 | free_mad(&query->sa_query); |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 836 | |
| 837 | err1: |
| 838 | kfree(query); |
| 839 | return ret; |
Hal Rosenstock | cbae32c | 2005-07-27 11:45:38 -0700 | [diff] [blame] | 840 | } |
| 841 | EXPORT_SYMBOL(ib_sa_service_rec_query); |
| 842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | static void ib_sa_mcmember_rec_callback(struct ib_sa_query *sa_query, |
| 844 | int status, |
| 845 | struct ib_sa_mad *mad) |
| 846 | { |
| 847 | struct ib_sa_mcmember_query *query = |
| 848 | container_of(sa_query, struct ib_sa_mcmember_query, sa_query); |
| 849 | |
| 850 | if (mad) { |
| 851 | struct ib_sa_mcmember_rec rec; |
| 852 | |
| 853 | ib_unpack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table), |
| 854 | mad->data, &rec); |
| 855 | query->callback(status, &rec, query->context); |
| 856 | } else |
| 857 | query->callback(status, NULL, query->context); |
| 858 | } |
| 859 | |
| 860 | static void ib_sa_mcmember_rec_release(struct ib_sa_query *sa_query) |
| 861 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | kfree(container_of(sa_query, struct ib_sa_mcmember_query, sa_query)); |
| 863 | } |
| 864 | |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 865 | int ib_sa_mcmember_rec_query(struct ib_sa_client *client, |
| 866 | struct ib_device *device, u8 port_num, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | u8 method, |
| 868 | struct ib_sa_mcmember_rec *rec, |
| 869 | ib_sa_comp_mask comp_mask, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 870 | int timeout_ms, gfp_t gfp_mask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | void (*callback)(int status, |
| 872 | struct ib_sa_mcmember_rec *resp, |
| 873 | void *context), |
| 874 | void *context, |
| 875 | struct ib_sa_query **sa_query) |
| 876 | { |
| 877 | struct ib_sa_mcmember_query *query; |
| 878 | struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client); |
Roland Dreier | 56c202d | 2005-10-13 10:45:02 -0700 | [diff] [blame] | 879 | struct ib_sa_port *port; |
| 880 | struct ib_mad_agent *agent; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 881 | struct ib_sa_mad *mad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | int ret; |
| 883 | |
Roland Dreier | 56c202d | 2005-10-13 10:45:02 -0700 | [diff] [blame] | 884 | if (!sa_dev) |
| 885 | return -ENODEV; |
| 886 | |
| 887 | port = &sa_dev->port[port_num - sa_dev->start_port]; |
| 888 | agent = port->agent; |
| 889 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | query = kmalloc(sizeof *query, gfp_mask); |
| 891 | if (!query) |
| 892 | return -ENOMEM; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 893 | |
Sean Hefty | 2aec5c6 | 2007-06-18 11:03:58 -0700 | [diff] [blame] | 894 | query->sa_query.port = port; |
| 895 | ret = alloc_mad(&query->sa_query, gfp_mask); |
| 896 | if (ret) |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 897 | goto err1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 899 | ib_sa_client_get(client); |
| 900 | query->sa_query.client = client; |
| 901 | query->callback = callback; |
| 902 | query->context = context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 904 | mad = query->sa_query.mad_buf->mad; |
| 905 | init_mad(mad, agent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 907 | query->sa_query.callback = callback ? ib_sa_mcmember_rec_callback : NULL; |
| 908 | query->sa_query.release = ib_sa_mcmember_rec_release; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 909 | mad->mad_hdr.method = method; |
| 910 | mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC); |
| 911 | mad->sa_hdr.comp_mask = comp_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | |
| 913 | ib_pack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table), |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 914 | rec, mad->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
| 916 | *sa_query = &query->sa_query; |
Roland Dreier | dae4c1d | 2005-06-27 14:36:46 -0700 | [diff] [blame] | 917 | |
Michael S. Tsirkin | e322fed | 2006-07-14 00:23:56 -0700 | [diff] [blame] | 918 | ret = send_mad(&query->sa_query, timeout_ms, gfp_mask); |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 919 | if (ret < 0) |
| 920 | goto err2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
Roland Dreier | dae4c1d | 2005-06-27 14:36:46 -0700 | [diff] [blame] | 922 | return ret; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 923 | |
| 924 | err2: |
| 925 | *sa_query = NULL; |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 926 | ib_sa_client_put(query->sa_query.client); |
Sean Hefty | 2aec5c6 | 2007-06-18 11:03:58 -0700 | [diff] [blame] | 927 | free_mad(&query->sa_query); |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 928 | |
| 929 | err1: |
| 930 | kfree(query); |
| 931 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | |
| 934 | static void send_handler(struct ib_mad_agent *agent, |
| 935 | struct ib_mad_send_wc *mad_send_wc) |
| 936 | { |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 937 | struct ib_sa_query *query = mad_send_wc->send_buf->context[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | unsigned long flags; |
| 939 | |
Roland Dreier | e4f50f0 | 2005-05-25 12:31:29 -0700 | [diff] [blame] | 940 | if (query->callback) |
| 941 | switch (mad_send_wc->status) { |
| 942 | case IB_WC_SUCCESS: |
| 943 | /* No callback -- already got recv */ |
| 944 | break; |
| 945 | case IB_WC_RESP_TIMEOUT_ERR: |
| 946 | query->callback(query, -ETIMEDOUT, NULL); |
| 947 | break; |
| 948 | case IB_WC_WR_FLUSH_ERR: |
| 949 | query->callback(query, -EINTR, NULL); |
| 950 | break; |
| 951 | default: |
| 952 | query->callback(query, -EIO, NULL); |
| 953 | break; |
| 954 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | spin_lock_irqsave(&idr_lock, flags); |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 957 | idr_remove(&query_idr, query->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | spin_unlock_irqrestore(&idr_lock, flags); |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 959 | |
Sean Hefty | 2aec5c6 | 2007-06-18 11:03:58 -0700 | [diff] [blame] | 960 | free_mad(query); |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 961 | ib_sa_client_put(query->client); |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 962 | query->release(query); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | static void recv_handler(struct ib_mad_agent *mad_agent, |
| 966 | struct ib_mad_recv_wc *mad_recv_wc) |
| 967 | { |
| 968 | struct ib_sa_query *query; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 969 | struct ib_mad_send_buf *mad_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 971 | mad_buf = (void *) (unsigned long) mad_recv_wc->wc->wr_id; |
| 972 | query = mad_buf->context[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 974 | if (query->callback) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | if (mad_recv_wc->wc->status == IB_WC_SUCCESS) |
| 976 | query->callback(query, |
| 977 | mad_recv_wc->recv_buf.mad->mad_hdr.status ? |
| 978 | -EINVAL : 0, |
| 979 | (struct ib_sa_mad *) mad_recv_wc->recv_buf.mad); |
| 980 | else |
| 981 | query->callback(query, -EIO, NULL); |
| 982 | } |
| 983 | |
| 984 | ib_free_recv_mad(mad_recv_wc); |
| 985 | } |
| 986 | |
| 987 | static void ib_sa_add_one(struct ib_device *device) |
| 988 | { |
| 989 | struct ib_sa_device *sa_dev; |
| 990 | int s, e, i; |
| 991 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 992 | if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB) |
| 993 | return; |
| 994 | |
| 995 | if (device->node_type == RDMA_NODE_IB_SWITCH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | s = e = 0; |
| 997 | else { |
| 998 | s = 1; |
| 999 | e = device->phys_port_cnt; |
| 1000 | } |
| 1001 | |
| 1002 | sa_dev = kmalloc(sizeof *sa_dev + |
| 1003 | (e - s + 1) * sizeof (struct ib_sa_port), |
| 1004 | GFP_KERNEL); |
| 1005 | if (!sa_dev) |
| 1006 | return; |
| 1007 | |
| 1008 | sa_dev->start_port = s; |
| 1009 | sa_dev->end_port = e; |
| 1010 | |
| 1011 | for (i = 0; i <= e - s; ++i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | sa_dev->port[i].sm_ah = NULL; |
| 1013 | sa_dev->port[i].port_num = i + s; |
| 1014 | spin_lock_init(&sa_dev->port[i].ah_lock); |
| 1015 | |
| 1016 | sa_dev->port[i].agent = |
| 1017 | ib_register_mad_agent(device, i + s, IB_QPT_GSI, |
| 1018 | NULL, 0, send_handler, |
| 1019 | recv_handler, sa_dev); |
| 1020 | if (IS_ERR(sa_dev->port[i].agent)) |
| 1021 | goto err; |
| 1022 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1023 | INIT_WORK(&sa_dev->port[i].update_task, update_sm_ah); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | ib_set_client_data(device, &sa_client, sa_dev); |
| 1027 | |
| 1028 | /* |
| 1029 | * We register our event handler after everything is set up, |
| 1030 | * and then update our cached info after the event handler is |
| 1031 | * registered to avoid any problems if a port changes state |
| 1032 | * during our initialization. |
| 1033 | */ |
| 1034 | |
| 1035 | INIT_IB_EVENT_HANDLER(&sa_dev->event_handler, device, ib_sa_event); |
| 1036 | if (ib_register_event_handler(&sa_dev->event_handler)) |
| 1037 | goto err; |
| 1038 | |
| 1039 | for (i = 0; i <= e - s; ++i) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1040 | update_sm_ah(&sa_dev->port[i].update_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | |
| 1042 | return; |
| 1043 | |
| 1044 | err: |
Hal Rosenstock | b82cab6 | 2005-07-27 11:45:22 -0700 | [diff] [blame] | 1045 | while (--i >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | ib_unregister_mad_agent(sa_dev->port[i].agent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | |
| 1048 | kfree(sa_dev); |
| 1049 | |
| 1050 | return; |
| 1051 | } |
| 1052 | |
| 1053 | static void ib_sa_remove_one(struct ib_device *device) |
| 1054 | { |
| 1055 | struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client); |
| 1056 | int i; |
| 1057 | |
| 1058 | if (!sa_dev) |
| 1059 | return; |
| 1060 | |
| 1061 | ib_unregister_event_handler(&sa_dev->event_handler); |
| 1062 | |
Michael S. Tsirkin | 0f47ae0 | 2006-01-17 09:53:51 -0800 | [diff] [blame] | 1063 | flush_scheduled_work(); |
| 1064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | for (i = 0; i <= sa_dev->end_port - sa_dev->start_port; ++i) { |
| 1066 | ib_unregister_mad_agent(sa_dev->port[i].agent); |
Ralph Campbell | 64b784b | 2008-07-22 14:18:33 -0700 | [diff] [blame] | 1067 | if (sa_dev->port[i].sm_ah) |
| 1068 | kref_put(&sa_dev->port[i].sm_ah->ref, free_sm_ah); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | kfree(sa_dev); |
| 1072 | } |
| 1073 | |
| 1074 | static int __init ib_sa_init(void) |
| 1075 | { |
| 1076 | int ret; |
| 1077 | |
| 1078 | spin_lock_init(&idr_lock); |
| 1079 | spin_lock_init(&tid_lock); |
| 1080 | |
| 1081 | get_random_bytes(&tid, sizeof tid); |
| 1082 | |
| 1083 | ret = ib_register_client(&sa_client); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 1084 | if (ret) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | printk(KERN_ERR "Couldn't register ib_sa client\n"); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 1086 | goto err1; |
| 1087 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 1089 | ret = mcast_init(); |
| 1090 | if (ret) { |
| 1091 | printk(KERN_ERR "Couldn't initialize multicast handling\n"); |
| 1092 | goto err2; |
| 1093 | } |
| 1094 | |
| 1095 | return 0; |
| 1096 | err2: |
| 1097 | ib_unregister_client(&sa_client); |
| 1098 | err1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | return ret; |
| 1100 | } |
| 1101 | |
| 1102 | static void __exit ib_sa_cleanup(void) |
| 1103 | { |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 1104 | mcast_cleanup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | ib_unregister_client(&sa_client); |
Roland Dreier | 5d7edb3 | 2005-10-24 10:53:25 -0700 | [diff] [blame] | 1106 | idr_destroy(&query_idr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | module_init(ib_sa_init); |
| 1110 | module_exit(ib_sa_cleanup); |