Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1 | /* |
Bryan O'Sullivan | 759d576 | 2006-07-01 04:35:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2006 QLogic, Inc. All rights reserved. |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 3 | * Copyright (c) 2005, 2006 PathScale, Inc. 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 | |
| 34 | #include <rdma/ib_mad.h> |
| 35 | #include <rdma/ib_user_verbs.h> |
| 36 | #include <linux/utsname.h> |
| 37 | |
| 38 | #include "ipath_kernel.h" |
| 39 | #include "ipath_verbs.h" |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 40 | #include "ipath_common.h" |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 41 | |
| 42 | /* Not static, because we don't want the compiler removing it */ |
| 43 | const char ipath_verbs_version[] = "ipath_verbs " IPATH_IDSTR; |
| 44 | |
Roland Dreier | ac2ae4c | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 45 | static unsigned int ib_ipath_qp_table_size = 251; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 46 | module_param_named(qp_table_size, ib_ipath_qp_table_size, uint, S_IRUGO); |
| 47 | MODULE_PARM_DESC(qp_table_size, "QP table size"); |
| 48 | |
| 49 | unsigned int ib_ipath_lkey_table_size = 12; |
| 50 | module_param_named(lkey_table_size, ib_ipath_lkey_table_size, uint, |
| 51 | S_IRUGO); |
| 52 | MODULE_PARM_DESC(lkey_table_size, |
| 53 | "LKEY table size in bits (2^n, 1 <= n <= 23)"); |
| 54 | |
| 55 | unsigned int ib_ipath_debug; /* debug mask */ |
| 56 | module_param_named(debug, ib_ipath_debug, uint, S_IWUSR | S_IRUGO); |
| 57 | MODULE_PARM_DESC(debug, "Verbs debug mask"); |
| 58 | |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 59 | static unsigned int ib_ipath_max_pds = 0xFFFF; |
| 60 | module_param_named(max_pds, ib_ipath_max_pds, uint, S_IWUSR | S_IRUGO); |
| 61 | MODULE_PARM_DESC(max_pds, |
| 62 | "Maximum number of protection domains to support"); |
| 63 | |
| 64 | static unsigned int ib_ipath_max_ahs = 0xFFFF; |
| 65 | module_param_named(max_ahs, ib_ipath_max_ahs, uint, S_IWUSR | S_IRUGO); |
| 66 | MODULE_PARM_DESC(max_ahs, "Maximum number of address handles to support"); |
| 67 | |
| 68 | unsigned int ib_ipath_max_cqes = 0x2FFFF; |
| 69 | module_param_named(max_cqes, ib_ipath_max_cqes, uint, S_IWUSR | S_IRUGO); |
| 70 | MODULE_PARM_DESC(max_cqes, |
| 71 | "Maximum number of completion queue entries to support"); |
| 72 | |
| 73 | unsigned int ib_ipath_max_cqs = 0x1FFFF; |
| 74 | module_param_named(max_cqs, ib_ipath_max_cqs, uint, S_IWUSR | S_IRUGO); |
| 75 | MODULE_PARM_DESC(max_cqs, "Maximum number of completion queues to support"); |
| 76 | |
| 77 | unsigned int ib_ipath_max_qp_wrs = 0x3FFF; |
| 78 | module_param_named(max_qp_wrs, ib_ipath_max_qp_wrs, uint, |
| 79 | S_IWUSR | S_IRUGO); |
| 80 | MODULE_PARM_DESC(max_qp_wrs, "Maximum number of QP WRs to support"); |
| 81 | |
| 82 | unsigned int ib_ipath_max_sges = 0x60; |
| 83 | module_param_named(max_sges, ib_ipath_max_sges, uint, S_IWUSR | S_IRUGO); |
| 84 | MODULE_PARM_DESC(max_sges, "Maximum number of SGEs to support"); |
| 85 | |
| 86 | unsigned int ib_ipath_max_mcast_grps = 16384; |
| 87 | module_param_named(max_mcast_grps, ib_ipath_max_mcast_grps, uint, |
| 88 | S_IWUSR | S_IRUGO); |
| 89 | MODULE_PARM_DESC(max_mcast_grps, |
| 90 | "Maximum number of multicast groups to support"); |
| 91 | |
| 92 | unsigned int ib_ipath_max_mcast_qp_attached = 16; |
| 93 | module_param_named(max_mcast_qp_attached, ib_ipath_max_mcast_qp_attached, |
| 94 | uint, S_IWUSR | S_IRUGO); |
| 95 | MODULE_PARM_DESC(max_mcast_qp_attached, |
| 96 | "Maximum number of attached QPs to support"); |
| 97 | |
| 98 | unsigned int ib_ipath_max_srqs = 1024; |
| 99 | module_param_named(max_srqs, ib_ipath_max_srqs, uint, S_IWUSR | S_IRUGO); |
| 100 | MODULE_PARM_DESC(max_srqs, "Maximum number of SRQs to support"); |
| 101 | |
| 102 | unsigned int ib_ipath_max_srq_sges = 128; |
| 103 | module_param_named(max_srq_sges, ib_ipath_max_srq_sges, |
| 104 | uint, S_IWUSR | S_IRUGO); |
| 105 | MODULE_PARM_DESC(max_srq_sges, "Maximum number of SRQ SGEs to support"); |
| 106 | |
| 107 | unsigned int ib_ipath_max_srq_wrs = 0x1FFFF; |
| 108 | module_param_named(max_srq_wrs, ib_ipath_max_srq_wrs, |
| 109 | uint, S_IWUSR | S_IRUGO); |
| 110 | MODULE_PARM_DESC(max_srq_wrs, "Maximum number of SRQ WRs support"); |
| 111 | |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 112 | MODULE_LICENSE("GPL"); |
Bryan O'Sullivan | 759d576 | 2006-07-01 04:35:49 -0700 | [diff] [blame] | 113 | MODULE_AUTHOR("QLogic <support@pathscale.com>"); |
| 114 | MODULE_DESCRIPTION("QLogic InfiniPath driver"); |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 115 | |
| 116 | const int ib_ipath_state_ops[IB_QPS_ERR + 1] = { |
| 117 | [IB_QPS_RESET] = 0, |
| 118 | [IB_QPS_INIT] = IPATH_POST_RECV_OK, |
| 119 | [IB_QPS_RTR] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK, |
| 120 | [IB_QPS_RTS] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK | |
| 121 | IPATH_POST_SEND_OK | IPATH_PROCESS_SEND_OK, |
| 122 | [IB_QPS_SQD] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK | |
| 123 | IPATH_POST_SEND_OK, |
| 124 | [IB_QPS_SQE] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK, |
| 125 | [IB_QPS_ERR] = 0, |
| 126 | }; |
| 127 | |
| 128 | /* |
| 129 | * Translate ib_wr_opcode into ib_wc_opcode. |
| 130 | */ |
| 131 | const enum ib_wc_opcode ib_ipath_wc_opcode[] = { |
| 132 | [IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE, |
| 133 | [IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE, |
| 134 | [IB_WR_SEND] = IB_WC_SEND, |
| 135 | [IB_WR_SEND_WITH_IMM] = IB_WC_SEND, |
| 136 | [IB_WR_RDMA_READ] = IB_WC_RDMA_READ, |
| 137 | [IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP, |
| 138 | [IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD |
| 139 | }; |
| 140 | |
| 141 | /* |
| 142 | * System image GUID. |
| 143 | */ |
Roland Dreier | ac2ae4c | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 144 | static __be64 sys_image_guid; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 145 | |
| 146 | /** |
| 147 | * ipath_copy_sge - copy data to SGE memory |
| 148 | * @ss: the SGE state |
| 149 | * @data: the data to copy |
| 150 | * @length: the length of the data |
| 151 | */ |
| 152 | void ipath_copy_sge(struct ipath_sge_state *ss, void *data, u32 length) |
| 153 | { |
| 154 | struct ipath_sge *sge = &ss->sge; |
| 155 | |
| 156 | while (length) { |
| 157 | u32 len = sge->length; |
| 158 | |
| 159 | BUG_ON(len == 0); |
| 160 | if (len > length) |
| 161 | len = length; |
| 162 | memcpy(sge->vaddr, data, len); |
| 163 | sge->vaddr += len; |
| 164 | sge->length -= len; |
| 165 | sge->sge_length -= len; |
| 166 | if (sge->sge_length == 0) { |
| 167 | if (--ss->num_sge) |
| 168 | *sge = *ss->sg_list++; |
| 169 | } else if (sge->length == 0 && sge->mr != NULL) { |
| 170 | if (++sge->n >= IPATH_SEGSZ) { |
| 171 | if (++sge->m >= sge->mr->mapsz) |
| 172 | break; |
| 173 | sge->n = 0; |
| 174 | } |
| 175 | sge->vaddr = |
| 176 | sge->mr->map[sge->m]->segs[sge->n].vaddr; |
| 177 | sge->length = |
| 178 | sge->mr->map[sge->m]->segs[sge->n].length; |
| 179 | } |
| 180 | data += len; |
| 181 | length -= len; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * ipath_skip_sge - skip over SGE memory - XXX almost dup of prev func |
| 187 | * @ss: the SGE state |
| 188 | * @length: the number of bytes to skip |
| 189 | */ |
| 190 | void ipath_skip_sge(struct ipath_sge_state *ss, u32 length) |
| 191 | { |
| 192 | struct ipath_sge *sge = &ss->sge; |
| 193 | |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 194 | while (length) { |
| 195 | u32 len = sge->length; |
| 196 | |
| 197 | BUG_ON(len == 0); |
| 198 | if (len > length) |
| 199 | len = length; |
| 200 | sge->vaddr += len; |
| 201 | sge->length -= len; |
| 202 | sge->sge_length -= len; |
| 203 | if (sge->sge_length == 0) { |
| 204 | if (--ss->num_sge) |
| 205 | *sge = *ss->sg_list++; |
| 206 | } else if (sge->length == 0 && sge->mr != NULL) { |
| 207 | if (++sge->n >= IPATH_SEGSZ) { |
| 208 | if (++sge->m >= sge->mr->mapsz) |
| 209 | break; |
| 210 | sge->n = 0; |
| 211 | } |
| 212 | sge->vaddr = |
| 213 | sge->mr->map[sge->m]->segs[sge->n].vaddr; |
| 214 | sge->length = |
| 215 | sge->mr->map[sge->m]->segs[sge->n].length; |
| 216 | } |
| 217 | length -= len; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * ipath_post_send - post a send on a QP |
| 223 | * @ibqp: the QP to post the send on |
| 224 | * @wr: the list of work requests to post |
| 225 | * @bad_wr: the first bad WR is put here |
| 226 | * |
| 227 | * This may be called from interrupt context. |
| 228 | */ |
| 229 | static int ipath_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr, |
| 230 | struct ib_send_wr **bad_wr) |
| 231 | { |
| 232 | struct ipath_qp *qp = to_iqp(ibqp); |
| 233 | int err = 0; |
| 234 | |
| 235 | /* Check that state is OK to post send. */ |
| 236 | if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_SEND_OK)) { |
| 237 | *bad_wr = wr; |
| 238 | err = -EINVAL; |
| 239 | goto bail; |
| 240 | } |
| 241 | |
| 242 | for (; wr; wr = wr->next) { |
| 243 | switch (qp->ibqp.qp_type) { |
| 244 | case IB_QPT_UC: |
| 245 | case IB_QPT_RC: |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 246 | err = ipath_post_ruc_send(qp, wr); |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 247 | break; |
| 248 | |
| 249 | case IB_QPT_SMI: |
| 250 | case IB_QPT_GSI: |
| 251 | case IB_QPT_UD: |
| 252 | err = ipath_post_ud_send(qp, wr); |
| 253 | break; |
| 254 | |
| 255 | default: |
| 256 | err = -EINVAL; |
| 257 | } |
| 258 | if (err) { |
| 259 | *bad_wr = wr; |
| 260 | break; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | bail: |
| 265 | return err; |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * ipath_post_receive - post a receive on a QP |
| 270 | * @ibqp: the QP to post the receive on |
| 271 | * @wr: the WR to post |
| 272 | * @bad_wr: the first bad WR is put here |
| 273 | * |
| 274 | * This may be called from interrupt context. |
| 275 | */ |
| 276 | static int ipath_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr, |
| 277 | struct ib_recv_wr **bad_wr) |
| 278 | { |
| 279 | struct ipath_qp *qp = to_iqp(ibqp); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 280 | struct ipath_rwq *wq = qp->r_rq.wq; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 281 | unsigned long flags; |
| 282 | int ret; |
| 283 | |
| 284 | /* Check that state is OK to post receive. */ |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 285 | if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_RECV_OK) || !wq) { |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 286 | *bad_wr = wr; |
| 287 | ret = -EINVAL; |
| 288 | goto bail; |
| 289 | } |
| 290 | |
| 291 | for (; wr; wr = wr->next) { |
| 292 | struct ipath_rwqe *wqe; |
| 293 | u32 next; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 294 | int i; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 295 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 296 | if ((unsigned) wr->num_sge > qp->r_rq.max_sge) { |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 297 | *bad_wr = wr; |
| 298 | ret = -ENOMEM; |
| 299 | goto bail; |
| 300 | } |
| 301 | |
| 302 | spin_lock_irqsave(&qp->r_rq.lock, flags); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 303 | next = wq->head + 1; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 304 | if (next >= qp->r_rq.size) |
| 305 | next = 0; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 306 | if (next == wq->tail) { |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 307 | spin_unlock_irqrestore(&qp->r_rq.lock, flags); |
| 308 | *bad_wr = wr; |
| 309 | ret = -ENOMEM; |
| 310 | goto bail; |
| 311 | } |
| 312 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 313 | wqe = get_rwqe_ptr(&qp->r_rq, wq->head); |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 314 | wqe->wr_id = wr->wr_id; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 315 | wqe->num_sge = wr->num_sge; |
| 316 | for (i = 0; i < wr->num_sge; i++) |
| 317 | wqe->sg_list[i] = wr->sg_list[i]; |
| 318 | wq->head = next; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 319 | spin_unlock_irqrestore(&qp->r_rq.lock, flags); |
| 320 | } |
| 321 | ret = 0; |
| 322 | |
| 323 | bail: |
| 324 | return ret; |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * ipath_qp_rcv - processing an incoming packet on a QP |
| 329 | * @dev: the device the packet came on |
| 330 | * @hdr: the packet header |
| 331 | * @has_grh: true if the packet has a GRH |
| 332 | * @data: the packet data |
| 333 | * @tlen: the packet length |
| 334 | * @qp: the QP the packet came on |
| 335 | * |
| 336 | * This is called from ipath_ib_rcv() to process an incoming packet |
| 337 | * for the given QP. |
| 338 | * Called at interrupt level. |
| 339 | */ |
| 340 | static void ipath_qp_rcv(struct ipath_ibdev *dev, |
| 341 | struct ipath_ib_header *hdr, int has_grh, |
| 342 | void *data, u32 tlen, struct ipath_qp *qp) |
| 343 | { |
| 344 | /* Check for valid receive state. */ |
| 345 | if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_RECV_OK)) { |
| 346 | dev->n_pkt_drops++; |
| 347 | return; |
| 348 | } |
| 349 | |
| 350 | switch (qp->ibqp.qp_type) { |
| 351 | case IB_QPT_SMI: |
| 352 | case IB_QPT_GSI: |
| 353 | case IB_QPT_UD: |
| 354 | ipath_ud_rcv(dev, hdr, has_grh, data, tlen, qp); |
| 355 | break; |
| 356 | |
| 357 | case IB_QPT_RC: |
| 358 | ipath_rc_rcv(dev, hdr, has_grh, data, tlen, qp); |
| 359 | break; |
| 360 | |
| 361 | case IB_QPT_UC: |
| 362 | ipath_uc_rcv(dev, hdr, has_grh, data, tlen, qp); |
| 363 | break; |
| 364 | |
| 365 | default: |
| 366 | break; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | /** |
Bryan O'Sullivan | b1c1b6a | 2006-08-25 11:24:31 -0700 | [diff] [blame^] | 371 | * ipath_ib_rcv - process an incoming packet |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 372 | * @arg: the device pointer |
| 373 | * @rhdr: the header of the packet |
| 374 | * @data: the packet data |
| 375 | * @tlen: the packet length |
| 376 | * |
| 377 | * This is called from ipath_kreceive() to process an incoming packet at |
| 378 | * interrupt level. Tlen is the length of the header + data + CRC in bytes. |
| 379 | */ |
Bryan O'Sullivan | b1c1b6a | 2006-08-25 11:24:31 -0700 | [diff] [blame^] | 380 | void ipath_ib_rcv(struct ipath_ibdev *dev, void *rhdr, void *data, |
| 381 | u32 tlen) |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 382 | { |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 383 | struct ipath_ib_header *hdr = rhdr; |
| 384 | struct ipath_other_headers *ohdr; |
| 385 | struct ipath_qp *qp; |
| 386 | u32 qp_num; |
| 387 | int lnh; |
| 388 | u8 opcode; |
| 389 | u16 lid; |
| 390 | |
| 391 | if (unlikely(dev == NULL)) |
| 392 | goto bail; |
| 393 | |
| 394 | if (unlikely(tlen < 24)) { /* LRH+BTH+CRC */ |
| 395 | dev->rcv_errors++; |
| 396 | goto bail; |
| 397 | } |
| 398 | |
| 399 | /* Check for a valid destination LID (see ch. 7.11.1). */ |
| 400 | lid = be16_to_cpu(hdr->lrh[1]); |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 401 | if (lid < IPATH_MULTICAST_LID_BASE) { |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 402 | lid &= ~((1 << (dev->mkeyprot_resv_lmc & 7)) - 1); |
| 403 | if (unlikely(lid != ipath_layer_get_lid(dev->dd))) { |
| 404 | dev->rcv_errors++; |
| 405 | goto bail; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /* Check for GRH */ |
| 410 | lnh = be16_to_cpu(hdr->lrh[0]) & 3; |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 411 | if (lnh == IPATH_LRH_BTH) |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 412 | ohdr = &hdr->u.oth; |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 413 | else if (lnh == IPATH_LRH_GRH) |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 414 | ohdr = &hdr->u.l.oth; |
| 415 | else { |
| 416 | dev->rcv_errors++; |
| 417 | goto bail; |
| 418 | } |
| 419 | |
| 420 | opcode = be32_to_cpu(ohdr->bth[0]) >> 24; |
| 421 | dev->opstats[opcode].n_bytes += tlen; |
| 422 | dev->opstats[opcode].n_packets++; |
| 423 | |
| 424 | /* Get the destination QP number. */ |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 425 | qp_num = be32_to_cpu(ohdr->bth[1]) & IPATH_QPN_MASK; |
| 426 | if (qp_num == IPATH_MULTICAST_QPN) { |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 427 | struct ipath_mcast *mcast; |
| 428 | struct ipath_mcast_qp *p; |
| 429 | |
| 430 | mcast = ipath_mcast_find(&hdr->u.l.grh.dgid); |
| 431 | if (mcast == NULL) { |
| 432 | dev->n_pkt_drops++; |
| 433 | goto bail; |
| 434 | } |
| 435 | dev->n_multicast_rcv++; |
| 436 | list_for_each_entry_rcu(p, &mcast->qp_list, list) |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 437 | ipath_qp_rcv(dev, hdr, lnh == IPATH_LRH_GRH, data, |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 438 | tlen, p->qp); |
| 439 | /* |
| 440 | * Notify ipath_multicast_detach() if it is waiting for us |
| 441 | * to finish. |
| 442 | */ |
| 443 | if (atomic_dec_return(&mcast->refcount) <= 1) |
| 444 | wake_up(&mcast->wait); |
| 445 | } else { |
| 446 | qp = ipath_lookup_qpn(&dev->qp_table, qp_num); |
| 447 | if (qp) { |
| 448 | dev->n_unicast_rcv++; |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 449 | ipath_qp_rcv(dev, hdr, lnh == IPATH_LRH_GRH, data, |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 450 | tlen, qp); |
| 451 | /* |
| 452 | * Notify ipath_destroy_qp() if it is waiting |
| 453 | * for us to finish. |
| 454 | */ |
| 455 | if (atomic_dec_and_test(&qp->refcount)) |
| 456 | wake_up(&qp->wait); |
| 457 | } else |
| 458 | dev->n_pkt_drops++; |
| 459 | } |
| 460 | |
| 461 | bail:; |
| 462 | } |
| 463 | |
| 464 | /** |
| 465 | * ipath_ib_timer - verbs timer |
| 466 | * @arg: the device pointer |
| 467 | * |
| 468 | * This is called from ipath_do_rcv_timer() at interrupt level to check for |
| 469 | * QPs which need retransmits and to collect performance numbers. |
| 470 | */ |
Bryan O'Sullivan | b1c1b6a | 2006-08-25 11:24:31 -0700 | [diff] [blame^] | 471 | void ipath_ib_timer(struct ipath_ibdev *dev) |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 472 | { |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 473 | struct ipath_qp *resend = NULL; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 474 | struct list_head *last; |
| 475 | struct ipath_qp *qp; |
| 476 | unsigned long flags; |
| 477 | |
| 478 | if (dev == NULL) |
| 479 | return; |
| 480 | |
| 481 | spin_lock_irqsave(&dev->pending_lock, flags); |
| 482 | /* Start filling the next pending queue. */ |
| 483 | if (++dev->pending_index >= ARRAY_SIZE(dev->pending)) |
| 484 | dev->pending_index = 0; |
| 485 | /* Save any requests still in the new queue, they have timed out. */ |
| 486 | last = &dev->pending[dev->pending_index]; |
| 487 | while (!list_empty(last)) { |
| 488 | qp = list_entry(last->next, struct ipath_qp, timerwait); |
Bryan O'Sullivan | 94b8d9f | 2006-05-23 11:32:32 -0700 | [diff] [blame] | 489 | list_del_init(&qp->timerwait); |
Bryan O'Sullivan | 9b2017f | 2006-04-24 14:23:06 -0700 | [diff] [blame] | 490 | qp->timer_next = resend; |
| 491 | resend = qp; |
| 492 | atomic_inc(&qp->refcount); |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 493 | } |
| 494 | last = &dev->rnrwait; |
| 495 | if (!list_empty(last)) { |
| 496 | qp = list_entry(last->next, struct ipath_qp, timerwait); |
| 497 | if (--qp->s_rnr_timeout == 0) { |
| 498 | do { |
Bryan O'Sullivan | 94b8d9f | 2006-05-23 11:32:32 -0700 | [diff] [blame] | 499 | list_del_init(&qp->timerwait); |
Bryan O'Sullivan | 9b2017f | 2006-04-24 14:23:06 -0700 | [diff] [blame] | 500 | tasklet_hi_schedule(&qp->s_task); |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 501 | if (list_empty(last)) |
| 502 | break; |
| 503 | qp = list_entry(last->next, struct ipath_qp, |
| 504 | timerwait); |
| 505 | } while (qp->s_rnr_timeout == 0); |
| 506 | } |
| 507 | } |
| 508 | /* |
| 509 | * We should only be in the started state if pma_sample_start != 0 |
| 510 | */ |
| 511 | if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_STARTED && |
| 512 | --dev->pma_sample_start == 0) { |
| 513 | dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING; |
| 514 | ipath_layer_snapshot_counters(dev->dd, &dev->ipath_sword, |
| 515 | &dev->ipath_rword, |
| 516 | &dev->ipath_spkts, |
| 517 | &dev->ipath_rpkts, |
| 518 | &dev->ipath_xmit_wait); |
| 519 | } |
| 520 | if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_RUNNING) { |
| 521 | if (dev->pma_sample_interval == 0) { |
| 522 | u64 ta, tb, tc, td, te; |
| 523 | |
| 524 | dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE; |
| 525 | ipath_layer_snapshot_counters(dev->dd, &ta, &tb, |
| 526 | &tc, &td, &te); |
| 527 | |
| 528 | dev->ipath_sword = ta - dev->ipath_sword; |
| 529 | dev->ipath_rword = tb - dev->ipath_rword; |
| 530 | dev->ipath_spkts = tc - dev->ipath_spkts; |
| 531 | dev->ipath_rpkts = td - dev->ipath_rpkts; |
| 532 | dev->ipath_xmit_wait = te - dev->ipath_xmit_wait; |
| 533 | } |
| 534 | else |
| 535 | dev->pma_sample_interval--; |
| 536 | } |
| 537 | spin_unlock_irqrestore(&dev->pending_lock, flags); |
| 538 | |
| 539 | /* XXX What if timer fires again while this is running? */ |
Bryan O'Sullivan | 9b2017f | 2006-04-24 14:23:06 -0700 | [diff] [blame] | 540 | for (qp = resend; qp != NULL; qp = qp->timer_next) { |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 541 | struct ib_wc wc; |
| 542 | |
| 543 | spin_lock_irqsave(&qp->s_lock, flags); |
| 544 | if (qp->s_last != qp->s_tail && qp->state == IB_QPS_RTS) { |
| 545 | dev->n_timeouts++; |
| 546 | ipath_restart_rc(qp, qp->s_last_psn + 1, &wc); |
| 547 | } |
| 548 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 549 | |
| 550 | /* Notify ipath_destroy_qp() if it is waiting. */ |
| 551 | if (atomic_dec_and_test(&qp->refcount)) |
| 552 | wake_up(&qp->wait); |
| 553 | } |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | /** |
| 557 | * ipath_ib_piobufavail - callback when a PIO buffer is available |
| 558 | * @arg: the device pointer |
| 559 | * |
| 560 | * This is called from ipath_intr() at interrupt level when a PIO buffer is |
| 561 | * available after ipath_verbs_send() returned an error that no buffers were |
Bryan O'Sullivan | 9b2017f | 2006-04-24 14:23:06 -0700 | [diff] [blame] | 562 | * available. Return 1 if we consumed all the PIO buffers and we still have |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 563 | * QPs waiting for buffers (for now, just do a tasklet_hi_schedule and |
Bryan O'Sullivan | 9b2017f | 2006-04-24 14:23:06 -0700 | [diff] [blame] | 564 | * return zero). |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 565 | */ |
Bryan O'Sullivan | b1c1b6a | 2006-08-25 11:24:31 -0700 | [diff] [blame^] | 566 | int ipath_ib_piobufavail(struct ipath_ibdev *dev) |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 567 | { |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 568 | struct ipath_qp *qp; |
| 569 | unsigned long flags; |
| 570 | |
| 571 | if (dev == NULL) |
| 572 | goto bail; |
| 573 | |
| 574 | spin_lock_irqsave(&dev->pending_lock, flags); |
| 575 | while (!list_empty(&dev->piowait)) { |
| 576 | qp = list_entry(dev->piowait.next, struct ipath_qp, |
| 577 | piowait); |
Bryan O'Sullivan | 94b8d9f | 2006-05-23 11:32:32 -0700 | [diff] [blame] | 578 | list_del_init(&qp->piowait); |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 579 | tasklet_hi_schedule(&qp->s_task); |
| 580 | } |
| 581 | spin_unlock_irqrestore(&dev->pending_lock, flags); |
| 582 | |
| 583 | bail: |
Bryan O'Sullivan | 9b2017f | 2006-04-24 14:23:06 -0700 | [diff] [blame] | 584 | return 0; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | static int ipath_query_device(struct ib_device *ibdev, |
| 588 | struct ib_device_attr *props) |
| 589 | { |
| 590 | struct ipath_ibdev *dev = to_idev(ibdev); |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 591 | |
| 592 | memset(props, 0, sizeof(*props)); |
| 593 | |
| 594 | props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR | |
| 595 | IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT | |
| 596 | IB_DEVICE_SYS_IMAGE_GUID; |
Ralph Campbell | c9f79bd | 2006-07-17 18:19:54 -0700 | [diff] [blame] | 597 | props->page_size_cap = PAGE_SIZE; |
Bryan O'Sullivan | e8a88f0 | 2006-07-01 04:35:57 -0700 | [diff] [blame] | 598 | props->vendor_id = ipath_layer_get_vendorid(dev->dd); |
| 599 | props->vendor_part_id = ipath_layer_get_deviceid(dev->dd); |
| 600 | props->hw_ver = ipath_layer_get_pcirev(dev->dd); |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 601 | |
| 602 | props->sys_image_guid = dev->sys_image_guid; |
| 603 | |
| 604 | props->max_mr_size = ~0ull; |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 605 | props->max_qp = dev->qp_table.max; |
| 606 | props->max_qp_wr = ib_ipath_max_qp_wrs; |
| 607 | props->max_sge = ib_ipath_max_sges; |
| 608 | props->max_cq = ib_ipath_max_cqs; |
| 609 | props->max_ah = ib_ipath_max_ahs; |
| 610 | props->max_cqe = ib_ipath_max_cqes; |
| 611 | props->max_mr = dev->lk_table.max; |
| 612 | props->max_pd = ib_ipath_max_pds; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 613 | props->max_qp_rd_atom = 1; |
| 614 | props->max_qp_init_rd_atom = 1; |
| 615 | /* props->max_res_rd_atom */ |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 616 | props->max_srq = ib_ipath_max_srqs; |
| 617 | props->max_srq_wr = ib_ipath_max_srq_wrs; |
| 618 | props->max_srq_sge = ib_ipath_max_srq_sges; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 619 | /* props->local_ca_ack_delay */ |
| 620 | props->atomic_cap = IB_ATOMIC_HCA; |
| 621 | props->max_pkeys = ipath_layer_get_npkeys(dev->dd); |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 622 | props->max_mcast_grp = ib_ipath_max_mcast_grps; |
| 623 | props->max_mcast_qp_attach = ib_ipath_max_mcast_qp_attached; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 624 | props->max_total_mcast_qp_attach = props->max_mcast_qp_attach * |
| 625 | props->max_mcast_grp; |
| 626 | |
| 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | const u8 ipath_cvt_physportstate[16] = { |
| 631 | [INFINIPATH_IBCS_LT_STATE_DISABLED] = 3, |
| 632 | [INFINIPATH_IBCS_LT_STATE_LINKUP] = 5, |
| 633 | [INFINIPATH_IBCS_LT_STATE_POLLACTIVE] = 2, |
| 634 | [INFINIPATH_IBCS_LT_STATE_POLLQUIET] = 2, |
| 635 | [INFINIPATH_IBCS_LT_STATE_SLEEPDELAY] = 1, |
| 636 | [INFINIPATH_IBCS_LT_STATE_SLEEPQUIET] = 1, |
| 637 | [INFINIPATH_IBCS_LT_STATE_CFGDEBOUNCE] = 4, |
| 638 | [INFINIPATH_IBCS_LT_STATE_CFGRCVFCFG] = 4, |
| 639 | [INFINIPATH_IBCS_LT_STATE_CFGWAITRMT] = 4, |
| 640 | [INFINIPATH_IBCS_LT_STATE_CFGIDLE] = 4, |
| 641 | [INFINIPATH_IBCS_LT_STATE_RECOVERRETRAIN] = 6, |
| 642 | [INFINIPATH_IBCS_LT_STATE_RECOVERWAITRMT] = 6, |
| 643 | [INFINIPATH_IBCS_LT_STATE_RECOVERIDLE] = 6, |
| 644 | }; |
| 645 | |
| 646 | static int ipath_query_port(struct ib_device *ibdev, |
| 647 | u8 port, struct ib_port_attr *props) |
| 648 | { |
| 649 | struct ipath_ibdev *dev = to_idev(ibdev); |
| 650 | enum ib_mtu mtu; |
| 651 | u16 lid = ipath_layer_get_lid(dev->dd); |
| 652 | u64 ibcstat; |
| 653 | |
| 654 | memset(props, 0, sizeof(*props)); |
| 655 | props->lid = lid ? lid : __constant_be16_to_cpu(IB_LID_PERMISSIVE); |
| 656 | props->lmc = dev->mkeyprot_resv_lmc & 7; |
| 657 | props->sm_lid = dev->sm_lid; |
| 658 | props->sm_sl = dev->sm_sl; |
| 659 | ibcstat = ipath_layer_get_lastibcstat(dev->dd); |
| 660 | props->state = ((ibcstat >> 4) & 0x3) + 1; |
| 661 | /* See phys_state_show() */ |
| 662 | props->phys_state = ipath_cvt_physportstate[ |
| 663 | ipath_layer_get_lastibcstat(dev->dd) & 0xf]; |
| 664 | props->port_cap_flags = dev->port_cap_flags; |
| 665 | props->gid_tbl_len = 1; |
Bryan O'Sullivan | c100f62 | 2006-07-01 04:36:07 -0700 | [diff] [blame] | 666 | props->max_msg_sz = 0x80000000; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 667 | props->pkey_tbl_len = ipath_layer_get_npkeys(dev->dd); |
| 668 | props->bad_pkey_cntr = ipath_layer_get_cr_errpkey(dev->dd) - |
Bryan O'Sullivan | 443a64a | 2006-07-01 04:35:48 -0700 | [diff] [blame] | 669 | dev->z_pkey_violations; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 670 | props->qkey_viol_cntr = dev->qkey_violations; |
| 671 | props->active_width = IB_WIDTH_4X; |
| 672 | /* See rate_show() */ |
| 673 | props->active_speed = 1; /* Regular 10Mbs speed. */ |
| 674 | props->max_vl_num = 1; /* VLCap = VL0 */ |
| 675 | props->init_type_reply = 0; |
| 676 | |
| 677 | props->max_mtu = IB_MTU_4096; |
| 678 | switch (ipath_layer_get_ibmtu(dev->dd)) { |
| 679 | case 4096: |
| 680 | mtu = IB_MTU_4096; |
| 681 | break; |
| 682 | case 2048: |
| 683 | mtu = IB_MTU_2048; |
| 684 | break; |
| 685 | case 1024: |
| 686 | mtu = IB_MTU_1024; |
| 687 | break; |
| 688 | case 512: |
| 689 | mtu = IB_MTU_512; |
| 690 | break; |
| 691 | case 256: |
| 692 | mtu = IB_MTU_256; |
| 693 | break; |
| 694 | default: |
| 695 | mtu = IB_MTU_2048; |
| 696 | } |
| 697 | props->active_mtu = mtu; |
| 698 | props->subnet_timeout = dev->subnet_timeout; |
| 699 | |
| 700 | return 0; |
| 701 | } |
| 702 | |
| 703 | static int ipath_modify_device(struct ib_device *device, |
| 704 | int device_modify_mask, |
| 705 | struct ib_device_modify *device_modify) |
| 706 | { |
| 707 | int ret; |
| 708 | |
| 709 | if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID | |
| 710 | IB_DEVICE_MODIFY_NODE_DESC)) { |
| 711 | ret = -EOPNOTSUPP; |
| 712 | goto bail; |
| 713 | } |
| 714 | |
| 715 | if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC) |
| 716 | memcpy(device->node_desc, device_modify->node_desc, 64); |
| 717 | |
| 718 | if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID) |
| 719 | to_idev(device)->sys_image_guid = |
| 720 | cpu_to_be64(device_modify->sys_image_guid); |
| 721 | |
| 722 | ret = 0; |
| 723 | |
| 724 | bail: |
| 725 | return ret; |
| 726 | } |
| 727 | |
| 728 | static int ipath_modify_port(struct ib_device *ibdev, |
| 729 | u8 port, int port_modify_mask, |
| 730 | struct ib_port_modify *props) |
| 731 | { |
| 732 | struct ipath_ibdev *dev = to_idev(ibdev); |
| 733 | |
| 734 | dev->port_cap_flags |= props->set_port_cap_mask; |
| 735 | dev->port_cap_flags &= ~props->clr_port_cap_mask; |
| 736 | if (port_modify_mask & IB_PORT_SHUTDOWN) |
| 737 | ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKDOWN); |
| 738 | if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR) |
| 739 | dev->qkey_violations = 0; |
| 740 | return 0; |
| 741 | } |
| 742 | |
| 743 | static int ipath_query_gid(struct ib_device *ibdev, u8 port, |
| 744 | int index, union ib_gid *gid) |
| 745 | { |
| 746 | struct ipath_ibdev *dev = to_idev(ibdev); |
| 747 | int ret; |
| 748 | |
| 749 | if (index >= 1) { |
| 750 | ret = -EINVAL; |
| 751 | goto bail; |
| 752 | } |
| 753 | gid->global.subnet_prefix = dev->gid_prefix; |
| 754 | gid->global.interface_id = ipath_layer_get_guid(dev->dd); |
| 755 | |
| 756 | ret = 0; |
| 757 | |
| 758 | bail: |
| 759 | return ret; |
| 760 | } |
| 761 | |
| 762 | static struct ib_pd *ipath_alloc_pd(struct ib_device *ibdev, |
| 763 | struct ib_ucontext *context, |
| 764 | struct ib_udata *udata) |
| 765 | { |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 766 | struct ipath_ibdev *dev = to_idev(ibdev); |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 767 | struct ipath_pd *pd; |
| 768 | struct ib_pd *ret; |
| 769 | |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 770 | /* |
| 771 | * This is actually totally arbitrary. Some correctness tests |
| 772 | * assume there's a maximum number of PDs that can be allocated. |
| 773 | * We don't actually have this limit, but we fail the test if |
| 774 | * we allow allocations of more than we report for this value. |
| 775 | */ |
| 776 | |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 777 | pd = kmalloc(sizeof *pd, GFP_KERNEL); |
| 778 | if (!pd) { |
| 779 | ret = ERR_PTR(-ENOMEM); |
| 780 | goto bail; |
| 781 | } |
| 782 | |
Bryan O'Sullivan | c27fef2 | 2006-08-25 11:24:27 -0700 | [diff] [blame] | 783 | spin_lock(&dev->n_pds_lock); |
| 784 | if (dev->n_pds_allocated == ib_ipath_max_pds) { |
| 785 | spin_unlock(&dev->n_pds_lock); |
| 786 | kfree(pd); |
| 787 | ret = ERR_PTR(-ENOMEM); |
| 788 | goto bail; |
| 789 | } |
| 790 | |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 791 | dev->n_pds_allocated++; |
Bryan O'Sullivan | c27fef2 | 2006-08-25 11:24:27 -0700 | [diff] [blame] | 792 | spin_unlock(&dev->n_pds_lock); |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 793 | |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 794 | /* ib_alloc_pd() will initialize pd->ibpd. */ |
| 795 | pd->user = udata != NULL; |
| 796 | |
| 797 | ret = &pd->ibpd; |
| 798 | |
| 799 | bail: |
| 800 | return ret; |
| 801 | } |
| 802 | |
| 803 | static int ipath_dealloc_pd(struct ib_pd *ibpd) |
| 804 | { |
| 805 | struct ipath_pd *pd = to_ipd(ibpd); |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 806 | struct ipath_ibdev *dev = to_idev(ibpd->device); |
| 807 | |
Bryan O'Sullivan | c27fef2 | 2006-08-25 11:24:27 -0700 | [diff] [blame] | 808 | spin_lock(&dev->n_pds_lock); |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 809 | dev->n_pds_allocated--; |
Bryan O'Sullivan | c27fef2 | 2006-08-25 11:24:27 -0700 | [diff] [blame] | 810 | spin_unlock(&dev->n_pds_lock); |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 811 | |
| 812 | kfree(pd); |
| 813 | |
| 814 | return 0; |
| 815 | } |
| 816 | |
| 817 | /** |
| 818 | * ipath_create_ah - create an address handle |
| 819 | * @pd: the protection domain |
| 820 | * @ah_attr: the attributes of the AH |
| 821 | * |
| 822 | * This may be called from interrupt context. |
| 823 | */ |
| 824 | static struct ib_ah *ipath_create_ah(struct ib_pd *pd, |
| 825 | struct ib_ah_attr *ah_attr) |
| 826 | { |
| 827 | struct ipath_ah *ah; |
| 828 | struct ib_ah *ret; |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 829 | struct ipath_ibdev *dev = to_idev(pd->device); |
| 830 | |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 831 | /* A multicast address requires a GRH (see ch. 8.4.1). */ |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 832 | if (ah_attr->dlid >= IPATH_MULTICAST_LID_BASE && |
| 833 | ah_attr->dlid != IPATH_PERMISSIVE_LID && |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 834 | !(ah_attr->ah_flags & IB_AH_GRH)) { |
| 835 | ret = ERR_PTR(-EINVAL); |
| 836 | goto bail; |
| 837 | } |
| 838 | |
Bryan O'Sullivan | 4a45b7d | 2006-07-01 04:35:55 -0700 | [diff] [blame] | 839 | if (ah_attr->dlid == 0) { |
| 840 | ret = ERR_PTR(-EINVAL); |
| 841 | goto bail; |
| 842 | } |
| 843 | |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 844 | if (ah_attr->port_num < 1 || |
Bryan O'Sullivan | 4a45b7d | 2006-07-01 04:35:55 -0700 | [diff] [blame] | 845 | ah_attr->port_num > pd->device->phys_port_cnt) { |
| 846 | ret = ERR_PTR(-EINVAL); |
| 847 | goto bail; |
| 848 | } |
| 849 | |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 850 | ah = kmalloc(sizeof *ah, GFP_ATOMIC); |
| 851 | if (!ah) { |
| 852 | ret = ERR_PTR(-ENOMEM); |
| 853 | goto bail; |
| 854 | } |
| 855 | |
Bryan O'Sullivan | c27fef2 | 2006-08-25 11:24:27 -0700 | [diff] [blame] | 856 | spin_lock(&dev->n_ahs_lock); |
| 857 | if (dev->n_ahs_allocated == ib_ipath_max_ahs) { |
| 858 | spin_unlock(&dev->n_ahs_lock); |
| 859 | kfree(ah); |
| 860 | ret = ERR_PTR(-ENOMEM); |
| 861 | goto bail; |
| 862 | } |
| 863 | |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 864 | dev->n_ahs_allocated++; |
Bryan O'Sullivan | c27fef2 | 2006-08-25 11:24:27 -0700 | [diff] [blame] | 865 | spin_unlock(&dev->n_ahs_lock); |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 866 | |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 867 | /* ib_create_ah() will initialize ah->ibah. */ |
| 868 | ah->attr = *ah_attr; |
| 869 | |
| 870 | ret = &ah->ibah; |
| 871 | |
| 872 | bail: |
| 873 | return ret; |
| 874 | } |
| 875 | |
| 876 | /** |
| 877 | * ipath_destroy_ah - destroy an address handle |
| 878 | * @ibah: the AH to destroy |
| 879 | * |
| 880 | * This may be called from interrupt context. |
| 881 | */ |
| 882 | static int ipath_destroy_ah(struct ib_ah *ibah) |
| 883 | { |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 884 | struct ipath_ibdev *dev = to_idev(ibah->device); |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 885 | struct ipath_ah *ah = to_iah(ibah); |
| 886 | |
Bryan O'Sullivan | c27fef2 | 2006-08-25 11:24:27 -0700 | [diff] [blame] | 887 | spin_lock(&dev->n_ahs_lock); |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 888 | dev->n_ahs_allocated--; |
Bryan O'Sullivan | c27fef2 | 2006-08-25 11:24:27 -0700 | [diff] [blame] | 889 | spin_unlock(&dev->n_ahs_lock); |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 890 | |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 891 | kfree(ah); |
| 892 | |
| 893 | return 0; |
| 894 | } |
| 895 | |
| 896 | static int ipath_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr) |
| 897 | { |
| 898 | struct ipath_ah *ah = to_iah(ibah); |
| 899 | |
| 900 | *ah_attr = ah->attr; |
| 901 | |
| 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | static int ipath_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 906 | u16 *pkey) |
| 907 | { |
| 908 | struct ipath_ibdev *dev = to_idev(ibdev); |
| 909 | int ret; |
| 910 | |
| 911 | if (index >= ipath_layer_get_npkeys(dev->dd)) { |
| 912 | ret = -EINVAL; |
| 913 | goto bail; |
| 914 | } |
| 915 | |
| 916 | *pkey = ipath_layer_get_pkey(dev->dd, index); |
| 917 | ret = 0; |
| 918 | |
| 919 | bail: |
| 920 | return ret; |
| 921 | } |
| 922 | |
| 923 | |
| 924 | /** |
| 925 | * ipath_alloc_ucontext - allocate a ucontest |
| 926 | * @ibdev: the infiniband device |
| 927 | * @udata: not used by the InfiniPath driver |
| 928 | */ |
| 929 | |
| 930 | static struct ib_ucontext *ipath_alloc_ucontext(struct ib_device *ibdev, |
| 931 | struct ib_udata *udata) |
| 932 | { |
| 933 | struct ipath_ucontext *context; |
| 934 | struct ib_ucontext *ret; |
| 935 | |
| 936 | context = kmalloc(sizeof *context, GFP_KERNEL); |
| 937 | if (!context) { |
| 938 | ret = ERR_PTR(-ENOMEM); |
| 939 | goto bail; |
| 940 | } |
| 941 | |
| 942 | ret = &context->ibucontext; |
| 943 | |
| 944 | bail: |
| 945 | return ret; |
| 946 | } |
| 947 | |
| 948 | static int ipath_dealloc_ucontext(struct ib_ucontext *context) |
| 949 | { |
| 950 | kfree(to_iucontext(context)); |
| 951 | return 0; |
| 952 | } |
| 953 | |
| 954 | static int ipath_verbs_register_sysfs(struct ib_device *dev); |
| 955 | |
| 956 | /** |
| 957 | * ipath_register_ib_device - register our device with the infiniband core |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 958 | * @dd: the device data structure |
| 959 | * Return the allocated ipath_ibdev pointer or NULL on error. |
| 960 | */ |
Bryan O'Sullivan | b1c1b6a | 2006-08-25 11:24:31 -0700 | [diff] [blame^] | 961 | int ipath_register_ib_device(struct ipath_devdata *dd) |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 962 | { |
Bryan O'Sullivan | fba7520 | 2006-07-01 04:36:09 -0700 | [diff] [blame] | 963 | struct ipath_layer_counters cntrs; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 964 | struct ipath_ibdev *idev; |
| 965 | struct ib_device *dev; |
| 966 | int ret; |
| 967 | |
| 968 | idev = (struct ipath_ibdev *)ib_alloc_device(sizeof *idev); |
Bryan O'Sullivan | b1c1b6a | 2006-08-25 11:24:31 -0700 | [diff] [blame^] | 969 | if (idev == NULL) { |
| 970 | ret = -ENOMEM; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 971 | goto bail; |
Bryan O'Sullivan | b1c1b6a | 2006-08-25 11:24:31 -0700 | [diff] [blame^] | 972 | } |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 973 | |
| 974 | dev = &idev->ibdev; |
| 975 | |
| 976 | /* Only need to initialize non-zero fields. */ |
Bryan O'Sullivan | c27fef2 | 2006-08-25 11:24:27 -0700 | [diff] [blame] | 977 | spin_lock_init(&idev->n_pds_lock); |
| 978 | spin_lock_init(&idev->n_ahs_lock); |
| 979 | spin_lock_init(&idev->n_cqs_lock); |
| 980 | spin_lock_init(&idev->n_srqs_lock); |
| 981 | spin_lock_init(&idev->n_mcast_grps_lock); |
| 982 | |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 983 | spin_lock_init(&idev->qp_table.lock); |
| 984 | spin_lock_init(&idev->lk_table.lock); |
| 985 | idev->sm_lid = __constant_be16_to_cpu(IB_LID_PERMISSIVE); |
| 986 | /* Set the prefix to the default value (see ch. 4.1.1) */ |
| 987 | idev->gid_prefix = __constant_cpu_to_be64(0xfe80000000000000ULL); |
| 988 | |
| 989 | ret = ipath_init_qp_table(idev, ib_ipath_qp_table_size); |
| 990 | if (ret) |
| 991 | goto err_qp; |
| 992 | |
| 993 | /* |
| 994 | * The top ib_ipath_lkey_table_size bits are used to index the |
| 995 | * table. The lower 8 bits can be owned by the user (copied from |
| 996 | * the LKEY). The remaining bits act as a generation number or tag. |
| 997 | */ |
| 998 | idev->lk_table.max = 1 << ib_ipath_lkey_table_size; |
| 999 | idev->lk_table.table = kzalloc(idev->lk_table.max * |
| 1000 | sizeof(*idev->lk_table.table), |
| 1001 | GFP_KERNEL); |
| 1002 | if (idev->lk_table.table == NULL) { |
| 1003 | ret = -ENOMEM; |
| 1004 | goto err_lk; |
| 1005 | } |
| 1006 | spin_lock_init(&idev->pending_lock); |
| 1007 | INIT_LIST_HEAD(&idev->pending[0]); |
| 1008 | INIT_LIST_HEAD(&idev->pending[1]); |
| 1009 | INIT_LIST_HEAD(&idev->pending[2]); |
| 1010 | INIT_LIST_HEAD(&idev->piowait); |
| 1011 | INIT_LIST_HEAD(&idev->rnrwait); |
| 1012 | idev->pending_index = 0; |
| 1013 | idev->port_cap_flags = |
| 1014 | IB_PORT_SYS_IMAGE_GUID_SUP | IB_PORT_CLIENT_REG_SUP; |
| 1015 | idev->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA; |
| 1016 | idev->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA; |
| 1017 | idev->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS; |
| 1018 | idev->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS; |
| 1019 | idev->pma_counter_select[5] = IB_PMA_PORT_XMIT_WAIT; |
| 1020 | idev->link_width_enabled = 3; /* 1x or 4x */ |
| 1021 | |
Bryan O'Sullivan | fba7520 | 2006-07-01 04:36:09 -0700 | [diff] [blame] | 1022 | /* Snapshot current HW counters to "clear" them. */ |
| 1023 | ipath_layer_get_counters(dd, &cntrs); |
| 1024 | idev->z_symbol_error_counter = cntrs.symbol_error_counter; |
| 1025 | idev->z_link_error_recovery_counter = |
| 1026 | cntrs.link_error_recovery_counter; |
| 1027 | idev->z_link_downed_counter = cntrs.link_downed_counter; |
| 1028 | idev->z_port_rcv_errors = cntrs.port_rcv_errors; |
| 1029 | idev->z_port_rcv_remphys_errors = |
| 1030 | cntrs.port_rcv_remphys_errors; |
| 1031 | idev->z_port_xmit_discards = cntrs.port_xmit_discards; |
| 1032 | idev->z_port_xmit_data = cntrs.port_xmit_data; |
| 1033 | idev->z_port_rcv_data = cntrs.port_rcv_data; |
| 1034 | idev->z_port_xmit_packets = cntrs.port_xmit_packets; |
| 1035 | idev->z_port_rcv_packets = cntrs.port_rcv_packets; |
| 1036 | idev->z_local_link_integrity_errors = |
| 1037 | cntrs.local_link_integrity_errors; |
| 1038 | idev->z_excessive_buffer_overrun_errors = |
| 1039 | cntrs.excessive_buffer_overrun_errors; |
| 1040 | |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1041 | /* |
| 1042 | * The system image GUID is supposed to be the same for all |
| 1043 | * IB HCAs in a single system but since there can be other |
| 1044 | * device types in the system, we can't be sure this is unique. |
| 1045 | */ |
| 1046 | if (!sys_image_guid) |
| 1047 | sys_image_guid = ipath_layer_get_guid(dd); |
| 1048 | idev->sys_image_guid = sys_image_guid; |
Bryan O'Sullivan | b1c1b6a | 2006-08-25 11:24:31 -0700 | [diff] [blame^] | 1049 | idev->ib_unit = dd->ipath_unit; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1050 | idev->dd = dd; |
| 1051 | |
| 1052 | strlcpy(dev->name, "ipath%d", IB_DEVICE_NAME_MAX); |
Bryan O'Sullivan | 41c75a1 | 2006-05-23 11:32:36 -0700 | [diff] [blame] | 1053 | dev->owner = THIS_MODULE; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1054 | dev->node_guid = ipath_layer_get_guid(dd); |
| 1055 | dev->uverbs_abi_ver = IPATH_UVERBS_ABI_VERSION; |
| 1056 | dev->uverbs_cmd_mask = |
| 1057 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 1058 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 1059 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 1060 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 1061 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
| 1062 | (1ull << IB_USER_VERBS_CMD_CREATE_AH) | |
| 1063 | (1ull << IB_USER_VERBS_CMD_DESTROY_AH) | |
| 1064 | (1ull << IB_USER_VERBS_CMD_QUERY_AH) | |
| 1065 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
| 1066 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 1067 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 1068 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 1069 | (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) | |
| 1070 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 1071 | (1ull << IB_USER_VERBS_CMD_POLL_CQ) | |
| 1072 | (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) | |
| 1073 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 1074 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
| 1075 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
| 1076 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 1077 | (1ull << IB_USER_VERBS_CMD_POST_SEND) | |
| 1078 | (1ull << IB_USER_VERBS_CMD_POST_RECV) | |
| 1079 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | |
| 1080 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) | |
| 1081 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | |
| 1082 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | |
| 1083 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | |
| 1084 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) | |
| 1085 | (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV); |
| 1086 | dev->node_type = IB_NODE_CA; |
| 1087 | dev->phys_port_cnt = 1; |
| 1088 | dev->dma_device = ipath_layer_get_device(dd); |
| 1089 | dev->class_dev.dev = dev->dma_device; |
| 1090 | dev->query_device = ipath_query_device; |
| 1091 | dev->modify_device = ipath_modify_device; |
| 1092 | dev->query_port = ipath_query_port; |
| 1093 | dev->modify_port = ipath_modify_port; |
| 1094 | dev->query_pkey = ipath_query_pkey; |
| 1095 | dev->query_gid = ipath_query_gid; |
| 1096 | dev->alloc_ucontext = ipath_alloc_ucontext; |
| 1097 | dev->dealloc_ucontext = ipath_dealloc_ucontext; |
| 1098 | dev->alloc_pd = ipath_alloc_pd; |
| 1099 | dev->dealloc_pd = ipath_dealloc_pd; |
| 1100 | dev->create_ah = ipath_create_ah; |
| 1101 | dev->destroy_ah = ipath_destroy_ah; |
| 1102 | dev->query_ah = ipath_query_ah; |
| 1103 | dev->create_srq = ipath_create_srq; |
| 1104 | dev->modify_srq = ipath_modify_srq; |
| 1105 | dev->query_srq = ipath_query_srq; |
| 1106 | dev->destroy_srq = ipath_destroy_srq; |
| 1107 | dev->create_qp = ipath_create_qp; |
| 1108 | dev->modify_qp = ipath_modify_qp; |
| 1109 | dev->query_qp = ipath_query_qp; |
| 1110 | dev->destroy_qp = ipath_destroy_qp; |
| 1111 | dev->post_send = ipath_post_send; |
| 1112 | dev->post_recv = ipath_post_receive; |
| 1113 | dev->post_srq_recv = ipath_post_srq_receive; |
| 1114 | dev->create_cq = ipath_create_cq; |
| 1115 | dev->destroy_cq = ipath_destroy_cq; |
| 1116 | dev->resize_cq = ipath_resize_cq; |
| 1117 | dev->poll_cq = ipath_poll_cq; |
| 1118 | dev->req_notify_cq = ipath_req_notify_cq; |
| 1119 | dev->get_dma_mr = ipath_get_dma_mr; |
| 1120 | dev->reg_phys_mr = ipath_reg_phys_mr; |
| 1121 | dev->reg_user_mr = ipath_reg_user_mr; |
| 1122 | dev->dereg_mr = ipath_dereg_mr; |
| 1123 | dev->alloc_fmr = ipath_alloc_fmr; |
| 1124 | dev->map_phys_fmr = ipath_map_phys_fmr; |
| 1125 | dev->unmap_fmr = ipath_unmap_fmr; |
| 1126 | dev->dealloc_fmr = ipath_dealloc_fmr; |
| 1127 | dev->attach_mcast = ipath_multicast_attach; |
| 1128 | dev->detach_mcast = ipath_multicast_detach; |
| 1129 | dev->process_mad = ipath_process_mad; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 1130 | dev->mmap = ipath_mmap; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1131 | |
| 1132 | snprintf(dev->node_desc, sizeof(dev->node_desc), |
| 1133 | IPATH_IDSTR " %s kernel_SMA", system_utsname.nodename); |
| 1134 | |
| 1135 | ret = ib_register_device(dev); |
| 1136 | if (ret) |
| 1137 | goto err_reg; |
| 1138 | |
| 1139 | if (ipath_verbs_register_sysfs(dev)) |
| 1140 | goto err_class; |
| 1141 | |
| 1142 | ipath_layer_enable_timer(dd); |
| 1143 | |
| 1144 | goto bail; |
| 1145 | |
| 1146 | err_class: |
| 1147 | ib_unregister_device(dev); |
| 1148 | err_reg: |
| 1149 | kfree(idev->lk_table.table); |
| 1150 | err_lk: |
| 1151 | kfree(idev->qp_table.table); |
| 1152 | err_qp: |
| 1153 | ib_dealloc_device(dev); |
| 1154 | _VERBS_ERROR("ib_ipath%d cannot register verbs (%d)!\n", |
Bryan O'Sullivan | b1c1b6a | 2006-08-25 11:24:31 -0700 | [diff] [blame^] | 1155 | dd->ipath_unit, -ret); |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1156 | idev = NULL; |
| 1157 | |
| 1158 | bail: |
Bryan O'Sullivan | b1c1b6a | 2006-08-25 11:24:31 -0700 | [diff] [blame^] | 1159 | dd->verbs_dev = idev; |
| 1160 | return ret; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1161 | } |
| 1162 | |
Bryan O'Sullivan | b1c1b6a | 2006-08-25 11:24:31 -0700 | [diff] [blame^] | 1163 | void ipath_unregister_ib_device(struct ipath_ibdev *dev) |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1164 | { |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1165 | struct ib_device *ibdev = &dev->ibdev; |
| 1166 | |
| 1167 | ipath_layer_disable_timer(dev->dd); |
| 1168 | |
| 1169 | ib_unregister_device(ibdev); |
| 1170 | |
| 1171 | if (!list_empty(&dev->pending[0]) || |
| 1172 | !list_empty(&dev->pending[1]) || |
| 1173 | !list_empty(&dev->pending[2])) |
| 1174 | _VERBS_ERROR("ipath%d pending list not empty!\n", |
| 1175 | dev->ib_unit); |
| 1176 | if (!list_empty(&dev->piowait)) |
| 1177 | _VERBS_ERROR("ipath%d piowait list not empty!\n", |
| 1178 | dev->ib_unit); |
| 1179 | if (!list_empty(&dev->rnrwait)) |
| 1180 | _VERBS_ERROR("ipath%d rnrwait list not empty!\n", |
| 1181 | dev->ib_unit); |
| 1182 | if (!ipath_mcast_tree_empty()) |
| 1183 | _VERBS_ERROR("ipath%d multicast table memory leak!\n", |
| 1184 | dev->ib_unit); |
| 1185 | /* |
| 1186 | * Note that ipath_unregister_ib_device() can be called before all |
| 1187 | * the QPs are destroyed! |
| 1188 | */ |
| 1189 | ipath_free_all_qps(&dev->qp_table); |
| 1190 | kfree(dev->qp_table.table); |
| 1191 | kfree(dev->lk_table.table); |
| 1192 | ib_dealloc_device(ibdev); |
| 1193 | } |
| 1194 | |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1195 | static ssize_t show_rev(struct class_device *cdev, char *buf) |
| 1196 | { |
Roland Dreier | 5494c22 | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 1197 | struct ipath_ibdev *dev = |
| 1198 | container_of(cdev, struct ipath_ibdev, ibdev.class_dev); |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1199 | |
Bryan O'Sullivan | e8a88f0 | 2006-07-01 04:35:57 -0700 | [diff] [blame] | 1200 | return sprintf(buf, "%x\n", ipath_layer_get_pcirev(dev->dd)); |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | static ssize_t show_hca(struct class_device *cdev, char *buf) |
| 1204 | { |
Roland Dreier | 5494c22 | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 1205 | struct ipath_ibdev *dev = |
| 1206 | container_of(cdev, struct ipath_ibdev, ibdev.class_dev); |
| 1207 | int ret; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1208 | |
Roland Dreier | 5494c22 | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 1209 | ret = ipath_layer_get_boardname(dev->dd, buf, 128); |
| 1210 | if (ret < 0) |
| 1211 | goto bail; |
| 1212 | strcat(buf, "\n"); |
| 1213 | ret = strlen(buf); |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1214 | |
| 1215 | bail: |
| 1216 | return ret; |
| 1217 | } |
| 1218 | |
| 1219 | static ssize_t show_stats(struct class_device *cdev, char *buf) |
| 1220 | { |
Roland Dreier | 5494c22 | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 1221 | struct ipath_ibdev *dev = |
| 1222 | container_of(cdev, struct ipath_ibdev, ibdev.class_dev); |
| 1223 | int i; |
| 1224 | int len; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1225 | |
Roland Dreier | 5494c22 | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 1226 | len = sprintf(buf, |
| 1227 | "RC resends %d\n" |
Bryan O'Sullivan | 9b2017f | 2006-04-24 14:23:06 -0700 | [diff] [blame] | 1228 | "RC no QACK %d\n" |
Roland Dreier | 5494c22 | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 1229 | "RC ACKs %d\n" |
| 1230 | "RC SEQ NAKs %d\n" |
| 1231 | "RC RDMA seq %d\n" |
| 1232 | "RC RNR NAKs %d\n" |
| 1233 | "RC OTH NAKs %d\n" |
| 1234 | "RC timeouts %d\n" |
| 1235 | "RC RDMA dup %d\n" |
| 1236 | "piobuf wait %d\n" |
| 1237 | "no piobuf %d\n" |
| 1238 | "PKT drops %d\n" |
| 1239 | "WQE errs %d\n", |
| 1240 | dev->n_rc_resends, dev->n_rc_qacks, dev->n_rc_acks, |
| 1241 | dev->n_seq_naks, dev->n_rdma_seq, dev->n_rnr_naks, |
| 1242 | dev->n_other_naks, dev->n_timeouts, |
| 1243 | dev->n_rdma_dup_busy, dev->n_piowait, |
| 1244 | dev->n_no_piobuf, dev->n_pkt_drops, dev->n_wqe_errs); |
| 1245 | for (i = 0; i < ARRAY_SIZE(dev->opstats); i++) { |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1246 | const struct ipath_opcode_stats *si = &dev->opstats[i]; |
| 1247 | |
Roland Dreier | 5494c22 | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 1248 | if (!si->n_packets && !si->n_bytes) |
| 1249 | continue; |
| 1250 | len += sprintf(buf + len, "%02x %llu/%llu\n", i, |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1251 | (unsigned long long) si->n_packets, |
Roland Dreier | 5494c22 | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 1252 | (unsigned long long) si->n_bytes); |
| 1253 | } |
| 1254 | return len; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); |
| 1258 | static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); |
| 1259 | static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL); |
| 1260 | static CLASS_DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL); |
| 1261 | |
| 1262 | static struct class_device_attribute *ipath_class_attributes[] = { |
Roland Dreier | 5494c22 | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 1263 | &class_device_attr_hw_rev, |
| 1264 | &class_device_attr_hca_type, |
| 1265 | &class_device_attr_board_id, |
| 1266 | &class_device_attr_stats |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1267 | }; |
| 1268 | |
| 1269 | static int ipath_verbs_register_sysfs(struct ib_device *dev) |
| 1270 | { |
Roland Dreier | 5494c22 | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 1271 | int i; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1272 | int ret; |
| 1273 | |
Roland Dreier | 5494c22 | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 1274 | for (i = 0; i < ARRAY_SIZE(ipath_class_attributes); ++i) |
| 1275 | if (class_device_create_file(&dev->class_dev, |
| 1276 | ipath_class_attributes[i])) { |
| 1277 | ret = 1; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1278 | goto bail; |
| 1279 | } |
| 1280 | |
Roland Dreier | 5494c22 | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 1281 | ret = 0; |
Bryan O'Sullivan | 6522108 | 2006-03-29 15:23:38 -0800 | [diff] [blame] | 1282 | |
| 1283 | bail: |
| 1284 | return ret; |
| 1285 | } |