Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1 | /* |
Mike Marciniszyn | f7cf9a6 | 2013-06-15 17:06:58 -0400 | [diff] [blame] | 2 | * Copyright (c) 2012, 2013 Intel Corporation. All rights reserved. |
Mike Marciniszyn | 1fb9fed | 2012-07-16 17:11:06 +0000 | [diff] [blame] | 3 | * Copyright (c) 2006 - 2012 QLogic Corporation. * All rights reserved. |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 4 | * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved. |
| 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. |
| 33 | */ |
| 34 | |
| 35 | #include <linux/err.h> |
| 36 | #include <linux/vmalloc.h> |
Dennis Dalessandro | 869a2a9 | 2016-01-22 12:45:02 -0800 | [diff] [blame] | 37 | #include <rdma/rdma_vt.h> |
Mike Marciniszyn | 1dd173b | 2013-06-15 17:07:14 -0400 | [diff] [blame] | 38 | #ifdef CONFIG_DEBUG_FS |
| 39 | #include <linux/seq_file.h> |
| 40 | #endif |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 41 | |
| 42 | #include "qib.h" |
| 43 | |
Harish Chegondi | 898fa52 | 2016-01-22 12:56:27 -0800 | [diff] [blame] | 44 | static inline unsigned mk_qpn(struct rvt_qpn_table *qpt, |
| 45 | struct rvt_qpn_map *map, unsigned off) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 46 | { |
Harish Chegondi | 898fa52 | 2016-01-22 12:56:27 -0800 | [diff] [blame] | 47 | return (map - qpt->map) * RVT_BITS_PER_PAGE + off; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Harish Chegondi | 898fa52 | 2016-01-22 12:56:27 -0800 | [diff] [blame] | 50 | static inline unsigned find_next_offset(struct rvt_qpn_table *qpt, |
| 51 | struct rvt_qpn_map *map, unsigned off, |
Dennis Dalessandro | 84b3adc | 2016-09-25 07:41:05 -0700 | [diff] [blame^] | 52 | unsigned n, u16 qpt_mask) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 53 | { |
Harish Chegondi | 898fa52 | 2016-01-22 12:56:27 -0800 | [diff] [blame] | 54 | if (qpt_mask) { |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 55 | off++; |
Harish Chegondi | 898fa52 | 2016-01-22 12:56:27 -0800 | [diff] [blame] | 56 | if (((off & qpt_mask) >> 1) >= n) |
| 57 | off = (off | qpt_mask) + 2; |
| 58 | } else { |
| 59 | off = find_next_zero_bit(map->page, RVT_BITS_PER_PAGE, off); |
| 60 | } |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 61 | return off; |
| 62 | } |
| 63 | |
| 64 | /* |
| 65 | * Convert the AETH credit code into the number of credits. |
| 66 | */ |
| 67 | static u32 credit_table[31] = { |
| 68 | 0, /* 0 */ |
| 69 | 1, /* 1 */ |
| 70 | 2, /* 2 */ |
| 71 | 3, /* 3 */ |
| 72 | 4, /* 4 */ |
| 73 | 6, /* 5 */ |
| 74 | 8, /* 6 */ |
| 75 | 12, /* 7 */ |
| 76 | 16, /* 8 */ |
| 77 | 24, /* 9 */ |
| 78 | 32, /* A */ |
| 79 | 48, /* B */ |
| 80 | 64, /* C */ |
| 81 | 96, /* D */ |
| 82 | 128, /* E */ |
| 83 | 192, /* F */ |
| 84 | 256, /* 10 */ |
| 85 | 384, /* 11 */ |
| 86 | 512, /* 12 */ |
| 87 | 768, /* 13 */ |
| 88 | 1024, /* 14 */ |
| 89 | 1536, /* 15 */ |
| 90 | 2048, /* 16 */ |
| 91 | 3072, /* 17 */ |
| 92 | 4096, /* 18 */ |
| 93 | 6144, /* 19 */ |
| 94 | 8192, /* 1A */ |
| 95 | 12288, /* 1B */ |
| 96 | 16384, /* 1C */ |
| 97 | 24576, /* 1D */ |
| 98 | 32768 /* 1E */ |
| 99 | }; |
| 100 | |
Mike Marciniszyn | 9ec4faa | 2016-07-01 16:02:18 -0700 | [diff] [blame] | 101 | const struct rvt_operation_params qib_post_parms[RVT_OPERATION_MAX] = { |
| 102 | [IB_WR_RDMA_WRITE] = { |
| 103 | .length = sizeof(struct ib_rdma_wr), |
| 104 | .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC), |
| 105 | }, |
| 106 | |
| 107 | [IB_WR_RDMA_READ] = { |
| 108 | .length = sizeof(struct ib_rdma_wr), |
| 109 | .qpt_support = BIT(IB_QPT_RC), |
| 110 | .flags = RVT_OPERATION_ATOMIC, |
| 111 | }, |
| 112 | |
| 113 | [IB_WR_ATOMIC_CMP_AND_SWP] = { |
| 114 | .length = sizeof(struct ib_atomic_wr), |
| 115 | .qpt_support = BIT(IB_QPT_RC), |
| 116 | .flags = RVT_OPERATION_ATOMIC | RVT_OPERATION_ATOMIC_SGE, |
| 117 | }, |
| 118 | |
| 119 | [IB_WR_ATOMIC_FETCH_AND_ADD] = { |
| 120 | .length = sizeof(struct ib_atomic_wr), |
| 121 | .qpt_support = BIT(IB_QPT_RC), |
| 122 | .flags = RVT_OPERATION_ATOMIC | RVT_OPERATION_ATOMIC_SGE, |
| 123 | }, |
| 124 | |
| 125 | [IB_WR_RDMA_WRITE_WITH_IMM] = { |
| 126 | .length = sizeof(struct ib_rdma_wr), |
| 127 | .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC), |
| 128 | }, |
| 129 | |
| 130 | [IB_WR_SEND] = { |
| 131 | .length = sizeof(struct ib_send_wr), |
| 132 | .qpt_support = BIT(IB_QPT_UD) | BIT(IB_QPT_SMI) | BIT(IB_QPT_GSI) | |
| 133 | BIT(IB_QPT_UC) | BIT(IB_QPT_RC), |
| 134 | }, |
| 135 | |
| 136 | [IB_WR_SEND_WITH_IMM] = { |
| 137 | .length = sizeof(struct ib_send_wr), |
| 138 | .qpt_support = BIT(IB_QPT_UD) | BIT(IB_QPT_SMI) | BIT(IB_QPT_GSI) | |
| 139 | BIT(IB_QPT_UC) | BIT(IB_QPT_RC), |
| 140 | }, |
| 141 | |
| 142 | }; |
| 143 | |
Harish Chegondi | 898fa52 | 2016-01-22 12:56:27 -0800 | [diff] [blame] | 144 | static void get_map_page(struct rvt_qpn_table *qpt, struct rvt_qpn_map *map, |
Vinit Agnihotri | fbbeb86 | 2016-01-11 12:57:25 -0500 | [diff] [blame] | 145 | gfp_t gfp) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 146 | { |
Vinit Agnihotri | fbbeb86 | 2016-01-11 12:57:25 -0500 | [diff] [blame] | 147 | unsigned long page = get_zeroed_page(gfp); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 148 | |
| 149 | /* |
| 150 | * Free the page if someone raced with us installing it. |
| 151 | */ |
| 152 | |
| 153 | spin_lock(&qpt->lock); |
| 154 | if (map->page) |
| 155 | free_page(page); |
| 156 | else |
| 157 | map->page = (void *)page; |
| 158 | spin_unlock(&qpt->lock); |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * Allocate the next available QPN or |
| 163 | * zero/one for QP type IB_QPT_SMI/IB_QPT_GSI. |
| 164 | */ |
Harish Chegondi | 20f333b | 2016-02-14 12:09:55 -0800 | [diff] [blame] | 165 | int qib_alloc_qpn(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt, |
| 166 | enum ib_qp_type type, u8 port, gfp_t gfp) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 167 | { |
| 168 | u32 i, offset, max_scan, qpn; |
Harish Chegondi | 898fa52 | 2016-01-22 12:56:27 -0800 | [diff] [blame] | 169 | struct rvt_qpn_map *map; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 170 | u32 ret; |
Harish Chegondi | 47c7ea6 | 2016-01-22 12:56:52 -0800 | [diff] [blame] | 171 | struct qib_ibdev *verbs_dev = container_of(rdi, struct qib_ibdev, rdi); |
| 172 | struct qib_devdata *dd = container_of(verbs_dev, struct qib_devdata, |
| 173 | verbs_dev); |
Dennis Dalessandro | 84b3adc | 2016-09-25 07:41:05 -0700 | [diff] [blame^] | 174 | u16 qpt_mask = dd->qpn_mask; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 175 | |
| 176 | if (type == IB_QPT_SMI || type == IB_QPT_GSI) { |
| 177 | unsigned n; |
| 178 | |
| 179 | ret = type == IB_QPT_GSI; |
| 180 | n = 1 << (ret + 2 * (port - 1)); |
| 181 | spin_lock(&qpt->lock); |
| 182 | if (qpt->flags & n) |
| 183 | ret = -EINVAL; |
| 184 | else |
| 185 | qpt->flags |= n; |
| 186 | spin_unlock(&qpt->lock); |
| 187 | goto bail; |
| 188 | } |
| 189 | |
Mike Marciniszyn | 7c3edd3 | 2011-01-10 17:42:22 -0800 | [diff] [blame] | 190 | qpn = qpt->last + 2; |
Harish Chegondi | 898fa52 | 2016-01-22 12:56:27 -0800 | [diff] [blame] | 191 | if (qpn >= RVT_QPN_MAX) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 192 | qpn = 2; |
Harish Chegondi | 898fa52 | 2016-01-22 12:56:27 -0800 | [diff] [blame] | 193 | if (qpt_mask && ((qpn & qpt_mask) >> 1) >= dd->n_krcv_queues) |
| 194 | qpn = (qpn | qpt_mask) + 2; |
| 195 | offset = qpn & RVT_BITS_PER_PAGE_MASK; |
| 196 | map = &qpt->map[qpn / RVT_BITS_PER_PAGE]; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 197 | max_scan = qpt->nmaps - !offset; |
| 198 | for (i = 0;;) { |
| 199 | if (unlikely(!map->page)) { |
Vinit Agnihotri | fbbeb86 | 2016-01-11 12:57:25 -0500 | [diff] [blame] | 200 | get_map_page(qpt, map, gfp); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 201 | if (unlikely(!map->page)) |
| 202 | break; |
| 203 | } |
| 204 | do { |
| 205 | if (!test_and_set_bit(offset, map->page)) { |
| 206 | qpt->last = qpn; |
| 207 | ret = qpn; |
| 208 | goto bail; |
| 209 | } |
Mike Marciniszyn | 2528ea6 | 2011-01-10 17:42:21 -0800 | [diff] [blame] | 210 | offset = find_next_offset(qpt, map, offset, |
Dennis Dalessandro | 84b3adc | 2016-09-25 07:41:05 -0700 | [diff] [blame^] | 211 | dd->n_krcv_queues, qpt_mask); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 212 | qpn = mk_qpn(qpt, map, offset); |
| 213 | /* |
| 214 | * This test differs from alloc_pidmap(). |
| 215 | * If find_next_offset() does find a zero |
| 216 | * bit, we don't need to check for QPN |
| 217 | * wrapping around past our starting QPN. |
| 218 | * We just need to be sure we don't loop |
| 219 | * forever. |
| 220 | */ |
Harish Chegondi | 898fa52 | 2016-01-22 12:56:27 -0800 | [diff] [blame] | 221 | } while (offset < RVT_BITS_PER_PAGE && qpn < RVT_QPN_MAX); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 222 | /* |
| 223 | * In order to keep the number of pages allocated to a |
| 224 | * minimum, we scan the all existing pages before increasing |
| 225 | * the size of the bitmap table. |
| 226 | */ |
| 227 | if (++i > max_scan) { |
Harish Chegondi | 898fa52 | 2016-01-22 12:56:27 -0800 | [diff] [blame] | 228 | if (qpt->nmaps == RVT_QPNMAP_ENTRIES) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 229 | break; |
| 230 | map = &qpt->map[qpt->nmaps++]; |
Mike Marciniszyn | 2528ea6 | 2011-01-10 17:42:21 -0800 | [diff] [blame] | 231 | offset = 0; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 232 | } else if (map < &qpt->map[qpt->nmaps]) { |
| 233 | ++map; |
Mike Marciniszyn | 2528ea6 | 2011-01-10 17:42:21 -0800 | [diff] [blame] | 234 | offset = 0; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 235 | } else { |
| 236 | map = &qpt->map[0]; |
Mike Marciniszyn | 2528ea6 | 2011-01-10 17:42:21 -0800 | [diff] [blame] | 237 | offset = 2; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 238 | } |
| 239 | qpn = mk_qpn(qpt, map, offset); |
| 240 | } |
| 241 | |
| 242 | ret = -ENOMEM; |
| 243 | |
| 244 | bail: |
| 245 | return ret; |
| 246 | } |
| 247 | |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 248 | /** |
| 249 | * qib_free_all_qps - check for QPs still in use |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 250 | */ |
Harish Chegondi | 47c7ea6 | 2016-01-22 12:56:52 -0800 | [diff] [blame] | 251 | unsigned qib_free_all_qps(struct rvt_dev_info *rdi) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 252 | { |
Harish Chegondi | 47c7ea6 | 2016-01-22 12:56:52 -0800 | [diff] [blame] | 253 | struct qib_ibdev *verbs_dev = container_of(rdi, struct qib_ibdev, rdi); |
| 254 | struct qib_devdata *dd = container_of(verbs_dev, struct qib_devdata, |
| 255 | verbs_dev); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 256 | unsigned n, qp_inuse = 0; |
| 257 | |
| 258 | for (n = 0; n < dd->num_pports; n++) { |
| 259 | struct qib_ibport *ibp = &dd->pport[n].ibport_data; |
| 260 | |
Mike Marciniszyn | af061a6 | 2011-09-23 13:16:44 -0400 | [diff] [blame] | 261 | rcu_read_lock(); |
Harish Chegondi | f24a6d4 | 2016-01-22 12:56:02 -0800 | [diff] [blame] | 262 | if (rcu_dereference(ibp->rvp.qp[0])) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 263 | qp_inuse++; |
Harish Chegondi | f24a6d4 | 2016-01-22 12:56:02 -0800 | [diff] [blame] | 264 | if (rcu_dereference(ibp->rvp.qp[1])) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 265 | qp_inuse++; |
Mike Marciniszyn | af061a6 | 2011-09-23 13:16:44 -0400 | [diff] [blame] | 266 | rcu_read_unlock(); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 267 | } |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 268 | return qp_inuse; |
| 269 | } |
| 270 | |
Harish Chegondi | 20f333b | 2016-02-14 12:09:55 -0800 | [diff] [blame] | 271 | void qib_notify_qp_reset(struct rvt_qp *qp) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 272 | { |
Dennis Dalessandro | ffc2690 | 2016-01-22 12:45:11 -0800 | [diff] [blame] | 273 | struct qib_qp_priv *priv = qp->priv; |
Harish Chegondi | 47c7ea6 | 2016-01-22 12:56:52 -0800 | [diff] [blame] | 274 | |
Dennis Dalessandro | ffc2690 | 2016-01-22 12:45:11 -0800 | [diff] [blame] | 275 | atomic_set(&priv->s_dma_busy, 0); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Harish Chegondi | 20f333b | 2016-02-14 12:09:55 -0800 | [diff] [blame] | 278 | void qib_notify_error_qp(struct rvt_qp *qp) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 279 | { |
Dennis Dalessandro | ffc2690 | 2016-01-22 12:45:11 -0800 | [diff] [blame] | 280 | struct qib_qp_priv *priv = qp->priv; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 281 | struct qib_ibdev *dev = to_idev(qp->ibqp.device); |
Mike Marciniszyn | 16028f2 | 2011-01-10 17:42:20 -0800 | [diff] [blame] | 282 | |
Harish Chegondi | cd18201 | 2016-01-22 12:56:14 -0800 | [diff] [blame] | 283 | spin_lock(&dev->rdi.pending_lock); |
Harish Chegondi | 01ba79d | 2016-01-22 12:56:46 -0800 | [diff] [blame] | 284 | if (!list_empty(&priv->iowait) && !(qp->s_flags & RVT_S_BUSY)) { |
| 285 | qp->s_flags &= ~RVT_S_ANY_WAIT_IO; |
Dennis Dalessandro | ffc2690 | 2016-01-22 12:45:11 -0800 | [diff] [blame] | 286 | list_del_init(&priv->iowait); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 287 | } |
Harish Chegondi | cd18201 | 2016-01-22 12:56:14 -0800 | [diff] [blame] | 288 | spin_unlock(&dev->rdi.pending_lock); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 289 | |
Harish Chegondi | 01ba79d | 2016-01-22 12:56:46 -0800 | [diff] [blame] | 290 | if (!(qp->s_flags & RVT_S_BUSY)) { |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 291 | qp->s_hdrwords = 0; |
| 292 | if (qp->s_rdma_mr) { |
Dennis Dalessandro | 7c2e11f | 2016-01-22 12:45:59 -0800 | [diff] [blame] | 293 | rvt_put_mr(qp->s_rdma_mr); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 294 | qp->s_rdma_mr = NULL; |
| 295 | } |
Dennis Dalessandro | ffc2690 | 2016-01-22 12:45:11 -0800 | [diff] [blame] | 296 | if (priv->s_tx) { |
| 297 | qib_put_txreq(priv->s_tx); |
| 298 | priv->s_tx = NULL; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 303 | static int mtu_to_enum(u32 mtu) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 304 | { |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 305 | int enum_mtu; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 306 | |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 307 | switch (mtu) { |
| 308 | case 4096: |
| 309 | enum_mtu = IB_MTU_4096; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 310 | break; |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 311 | case 2048: |
| 312 | enum_mtu = IB_MTU_2048; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 313 | break; |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 314 | case 1024: |
| 315 | enum_mtu = IB_MTU_1024; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 316 | break; |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 317 | case 512: |
| 318 | enum_mtu = IB_MTU_512; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 319 | break; |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 320 | case 256: |
| 321 | enum_mtu = IB_MTU_256; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 322 | break; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 323 | default: |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 324 | enum_mtu = IB_MTU_2048; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 325 | } |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 326 | return enum_mtu; |
| 327 | } |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 328 | |
Harish Chegondi | 20f333b | 2016-02-14 12:09:55 -0800 | [diff] [blame] | 329 | int qib_get_pmtu_from_attr(struct rvt_dev_info *rdi, struct rvt_qp *qp, |
| 330 | struct ib_qp_attr *attr) |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 331 | { |
| 332 | int mtu, pmtu, pidx = qp->port_num - 1; |
| 333 | struct qib_ibdev *verbs_dev = container_of(rdi, struct qib_ibdev, rdi); |
| 334 | struct qib_devdata *dd = container_of(verbs_dev, struct qib_devdata, |
| 335 | verbs_dev); |
| 336 | mtu = ib_mtu_enum_to_int(attr->path_mtu); |
| 337 | if (mtu == -1) |
| 338 | return -EINVAL; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 339 | |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 340 | if (mtu > dd->pport[pidx].ibmtu) |
| 341 | pmtu = mtu_to_enum(dd->pport[pidx].ibmtu); |
| 342 | else |
| 343 | pmtu = attr->path_mtu; |
| 344 | return pmtu; |
| 345 | } |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 346 | |
Harish Chegondi | 20f333b | 2016-02-14 12:09:55 -0800 | [diff] [blame] | 347 | int qib_mtu_to_path_mtu(u32 mtu) |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 348 | { |
| 349 | return mtu_to_enum(mtu); |
| 350 | } |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 351 | |
Harish Chegondi | 20f333b | 2016-02-14 12:09:55 -0800 | [diff] [blame] | 352 | u32 qib_mtu_from_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp, u32 pmtu) |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 353 | { |
| 354 | return ib_mtu_enum_to_int(pmtu); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 357 | /** |
| 358 | * qib_compute_aeth - compute the AETH (syndrome + MSN) |
| 359 | * @qp: the queue pair to compute the AETH for |
| 360 | * |
| 361 | * Returns the AETH. |
| 362 | */ |
Dennis Dalessandro | 7c2e11f | 2016-01-22 12:45:59 -0800 | [diff] [blame] | 363 | __be32 qib_compute_aeth(struct rvt_qp *qp) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 364 | { |
| 365 | u32 aeth = qp->r_msn & QIB_MSN_MASK; |
| 366 | |
| 367 | if (qp->ibqp.srq) { |
| 368 | /* |
| 369 | * Shared receive queues don't generate credits. |
| 370 | * Set the credit field to the invalid value. |
| 371 | */ |
| 372 | aeth |= QIB_AETH_CREDIT_INVAL << QIB_AETH_CREDIT_SHIFT; |
| 373 | } else { |
| 374 | u32 min, max, x; |
| 375 | u32 credits; |
Dennis Dalessandro | 7c2e11f | 2016-01-22 12:45:59 -0800 | [diff] [blame] | 376 | struct rvt_rwq *wq = qp->r_rq.wq; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 377 | u32 head; |
| 378 | u32 tail; |
| 379 | |
| 380 | /* sanity check pointers before trusting them */ |
| 381 | head = wq->head; |
| 382 | if (head >= qp->r_rq.size) |
| 383 | head = 0; |
| 384 | tail = wq->tail; |
| 385 | if (tail >= qp->r_rq.size) |
| 386 | tail = 0; |
| 387 | /* |
| 388 | * Compute the number of credits available (RWQEs). |
| 389 | * XXX Not holding the r_rq.lock here so there is a small |
| 390 | * chance that the pair of reads are not atomic. |
| 391 | */ |
| 392 | credits = head - tail; |
| 393 | if ((int)credits < 0) |
| 394 | credits += qp->r_rq.size; |
| 395 | /* |
| 396 | * Binary search the credit table to find the code to |
| 397 | * use. |
| 398 | */ |
| 399 | min = 0; |
| 400 | max = 31; |
| 401 | for (;;) { |
| 402 | x = (min + max) / 2; |
| 403 | if (credit_table[x] == credits) |
| 404 | break; |
| 405 | if (credit_table[x] > credits) |
| 406 | max = x; |
| 407 | else if (min == x) |
| 408 | break; |
| 409 | else |
| 410 | min = x; |
| 411 | } |
| 412 | aeth |= x << QIB_AETH_CREDIT_SHIFT; |
| 413 | } |
| 414 | return cpu_to_be32(aeth); |
| 415 | } |
| 416 | |
Harish Chegondi | 20f333b | 2016-02-14 12:09:55 -0800 | [diff] [blame] | 417 | void *qib_qp_priv_alloc(struct rvt_dev_info *rdi, struct rvt_qp *qp, gfp_t gfp) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 418 | { |
Dennis Dalessandro | ffc2690 | 2016-01-22 12:45:11 -0800 | [diff] [blame] | 419 | struct qib_qp_priv *priv; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 420 | |
Harish Chegondi | 47c7ea6 | 2016-01-22 12:56:52 -0800 | [diff] [blame] | 421 | priv = kzalloc(sizeof(*priv), gfp); |
| 422 | if (!priv) |
| 423 | return ERR_PTR(-ENOMEM); |
| 424 | priv->owner = qp; |
Vinit Agnihotri | fbbeb86 | 2016-01-11 12:57:25 -0500 | [diff] [blame] | 425 | |
Harish Chegondi | 47c7ea6 | 2016-01-22 12:56:52 -0800 | [diff] [blame] | 426 | priv->s_hdr = kzalloc(sizeof(*priv->s_hdr), gfp); |
| 427 | if (!priv->s_hdr) { |
| 428 | kfree(priv); |
| 429 | return ERR_PTR(-ENOMEM); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 430 | } |
Harish Chegondi | 47c7ea6 | 2016-01-22 12:56:52 -0800 | [diff] [blame] | 431 | init_waitqueue_head(&priv->wait_dma); |
Harish Chegondi | db3ef0e | 2016-01-22 13:07:42 -0800 | [diff] [blame] | 432 | INIT_WORK(&priv->s_work, _qib_do_send); |
Harish Chegondi | 47c7ea6 | 2016-01-22 12:56:52 -0800 | [diff] [blame] | 433 | INIT_LIST_HEAD(&priv->iowait); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 434 | |
Harish Chegondi | 47c7ea6 | 2016-01-22 12:56:52 -0800 | [diff] [blame] | 435 | return priv; |
| 436 | } |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 437 | |
Harish Chegondi | 20f333b | 2016-02-14 12:09:55 -0800 | [diff] [blame] | 438 | void qib_qp_priv_free(struct rvt_dev_info *rdi, struct rvt_qp *qp) |
Harish Chegondi | 47c7ea6 | 2016-01-22 12:56:52 -0800 | [diff] [blame] | 439 | { |
| 440 | struct qib_qp_priv *priv = qp->priv; |
Vinit Agnihotri | fbbeb86 | 2016-01-11 12:57:25 -0500 | [diff] [blame] | 441 | |
Dennis Dalessandro | ffc2690 | 2016-01-22 12:45:11 -0800 | [diff] [blame] | 442 | kfree(priv->s_hdr); |
| 443 | kfree(priv); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Harish Chegondi | 20f333b | 2016-02-14 12:09:55 -0800 | [diff] [blame] | 446 | void qib_stop_send_queue(struct rvt_qp *qp) |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 447 | { |
| 448 | struct qib_qp_priv *priv = qp->priv; |
| 449 | |
| 450 | cancel_work_sync(&priv->s_work); |
Mike Marciniszyn | 08279d5 | 2016-02-04 10:59:36 -0800 | [diff] [blame] | 451 | del_timer_sync(&qp->s_timer); |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 452 | } |
| 453 | |
Harish Chegondi | 20f333b | 2016-02-14 12:09:55 -0800 | [diff] [blame] | 454 | void qib_quiesce_qp(struct rvt_qp *qp) |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 455 | { |
| 456 | struct qib_qp_priv *priv = qp->priv; |
| 457 | |
| 458 | wait_event(priv->wait_dma, !atomic_read(&priv->s_dma_busy)); |
| 459 | if (priv->s_tx) { |
| 460 | qib_put_txreq(priv->s_tx); |
| 461 | priv->s_tx = NULL; |
| 462 | } |
| 463 | } |
| 464 | |
Harish Chegondi | 20f333b | 2016-02-14 12:09:55 -0800 | [diff] [blame] | 465 | void qib_flush_qp_waiters(struct rvt_qp *qp) |
Harish Chegondi | 70696ea | 2016-02-03 14:20:27 -0800 | [diff] [blame] | 466 | { |
| 467 | struct qib_qp_priv *priv = qp->priv; |
| 468 | struct qib_ibdev *dev = to_idev(qp->ibqp.device); |
| 469 | |
| 470 | spin_lock(&dev->rdi.pending_lock); |
| 471 | if (!list_empty(&priv->iowait)) |
| 472 | list_del_init(&priv->iowait); |
| 473 | spin_unlock(&dev->rdi.pending_lock); |
| 474 | } |
| 475 | |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 476 | /** |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 477 | * qib_get_credit - flush the send work queue of a QP |
| 478 | * @qp: the qp who's send work queue to flush |
| 479 | * @aeth: the Acknowledge Extended Transport Header |
| 480 | * |
| 481 | * The QP s_lock should be held. |
| 482 | */ |
Dennis Dalessandro | 7c2e11f | 2016-01-22 12:45:59 -0800 | [diff] [blame] | 483 | void qib_get_credit(struct rvt_qp *qp, u32 aeth) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 484 | { |
| 485 | u32 credit = (aeth >> QIB_AETH_CREDIT_SHIFT) & QIB_AETH_CREDIT_MASK; |
| 486 | |
| 487 | /* |
| 488 | * If the credit is invalid, we can send |
| 489 | * as many packets as we like. Otherwise, we have to |
| 490 | * honor the credit field. |
| 491 | */ |
| 492 | if (credit == QIB_AETH_CREDIT_INVAL) { |
Harish Chegondi | 01ba79d | 2016-01-22 12:56:46 -0800 | [diff] [blame] | 493 | if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT)) { |
| 494 | qp->s_flags |= RVT_S_UNLIMITED_CREDIT; |
| 495 | if (qp->s_flags & RVT_S_WAIT_SSN_CREDIT) { |
| 496 | qp->s_flags &= ~RVT_S_WAIT_SSN_CREDIT; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 497 | qib_schedule_send(qp); |
| 498 | } |
| 499 | } |
Harish Chegondi | 01ba79d | 2016-01-22 12:56:46 -0800 | [diff] [blame] | 500 | } else if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT)) { |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 501 | /* Compute new LSN (i.e., MSN + credit) */ |
| 502 | credit = (aeth + credit_table[credit]) & QIB_MSN_MASK; |
| 503 | if (qib_cmp24(credit, qp->s_lsn) > 0) { |
| 504 | qp->s_lsn = credit; |
Harish Chegondi | 01ba79d | 2016-01-22 12:56:46 -0800 | [diff] [blame] | 505 | if (qp->s_flags & RVT_S_WAIT_SSN_CREDIT) { |
| 506 | qp->s_flags &= ~RVT_S_WAIT_SSN_CREDIT; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 507 | qib_schedule_send(qp); |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | } |
Mike Marciniszyn | 1dd173b | 2013-06-15 17:07:14 -0400 | [diff] [blame] | 512 | |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 513 | /** |
| 514 | * qib_check_send_wqe - validate wr/wqe |
| 515 | * @qp - The qp |
| 516 | * @wqe - The built wqe |
| 517 | * |
| 518 | * validate wr/wqe. This is called |
| 519 | * prior to inserting the wqe into |
| 520 | * the ring but after the wqe has been |
| 521 | * setup. |
| 522 | * |
Mike Marciniszyn | 91702b4 | 2016-02-14 12:45:44 -0800 | [diff] [blame] | 523 | * Returns 1 to force direct progress, 0 otherwise, -EINVAL on failure |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 524 | */ |
| 525 | int qib_check_send_wqe(struct rvt_qp *qp, |
| 526 | struct rvt_swqe *wqe) |
| 527 | { |
| 528 | struct rvt_ah *ah; |
Mike Marciniszyn | 91702b4 | 2016-02-14 12:45:44 -0800 | [diff] [blame] | 529 | int ret = 0; |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 530 | |
| 531 | switch (qp->ibqp.qp_type) { |
| 532 | case IB_QPT_RC: |
| 533 | case IB_QPT_UC: |
| 534 | if (wqe->length > 0x80000000U) |
| 535 | return -EINVAL; |
| 536 | break; |
| 537 | case IB_QPT_SMI: |
| 538 | case IB_QPT_GSI: |
| 539 | case IB_QPT_UD: |
| 540 | ah = ibah_to_rvtah(wqe->ud_wr.ah); |
| 541 | if (wqe->length > (1 << ah->log_pmtu)) |
| 542 | return -EINVAL; |
Mike Marciniszyn | 91702b4 | 2016-02-14 12:45:44 -0800 | [diff] [blame] | 543 | /* progress hint */ |
| 544 | ret = 1; |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 545 | break; |
| 546 | default: |
| 547 | break; |
| 548 | } |
Mike Marciniszyn | 91702b4 | 2016-02-14 12:45:44 -0800 | [diff] [blame] | 549 | return ret; |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 550 | } |
| 551 | |
Mike Marciniszyn | 1dd173b | 2013-06-15 17:07:14 -0400 | [diff] [blame] | 552 | #ifdef CONFIG_DEBUG_FS |
| 553 | |
| 554 | struct qib_qp_iter { |
| 555 | struct qib_ibdev *dev; |
Dennis Dalessandro | 7c2e11f | 2016-01-22 12:45:59 -0800 | [diff] [blame] | 556 | struct rvt_qp *qp; |
Mike Marciniszyn | 1dd173b | 2013-06-15 17:07:14 -0400 | [diff] [blame] | 557 | int n; |
| 558 | }; |
| 559 | |
| 560 | struct qib_qp_iter *qib_qp_iter_init(struct qib_ibdev *dev) |
| 561 | { |
| 562 | struct qib_qp_iter *iter; |
| 563 | |
| 564 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 565 | if (!iter) |
| 566 | return NULL; |
| 567 | |
| 568 | iter->dev = dev; |
Mike Marciniszyn | 1dd173b | 2013-06-15 17:07:14 -0400 | [diff] [blame] | 569 | |
| 570 | return iter; |
| 571 | } |
| 572 | |
| 573 | int qib_qp_iter_next(struct qib_qp_iter *iter) |
| 574 | { |
| 575 | struct qib_ibdev *dev = iter->dev; |
| 576 | int n = iter->n; |
| 577 | int ret = 1; |
Dennis Dalessandro | 7c2e11f | 2016-01-22 12:45:59 -0800 | [diff] [blame] | 578 | struct rvt_qp *pqp = iter->qp; |
| 579 | struct rvt_qp *qp; |
Mike Marciniszyn | 1dd173b | 2013-06-15 17:07:14 -0400 | [diff] [blame] | 580 | |
Harish Chegondi | 898fa52 | 2016-01-22 12:56:27 -0800 | [diff] [blame] | 581 | for (; n < dev->rdi.qp_dev->qp_table_size; n++) { |
Mike Marciniszyn | 1dd173b | 2013-06-15 17:07:14 -0400 | [diff] [blame] | 582 | if (pqp) |
| 583 | qp = rcu_dereference(pqp->next); |
| 584 | else |
Harish Chegondi | 898fa52 | 2016-01-22 12:56:27 -0800 | [diff] [blame] | 585 | qp = rcu_dereference(dev->rdi.qp_dev->qp_table[n]); |
Mike Marciniszyn | 1dd173b | 2013-06-15 17:07:14 -0400 | [diff] [blame] | 586 | pqp = qp; |
| 587 | if (qp) { |
Mike Marciniszyn | 1dd173b | 2013-06-15 17:07:14 -0400 | [diff] [blame] | 588 | iter->qp = qp; |
| 589 | iter->n = n; |
| 590 | return 0; |
| 591 | } |
| 592 | } |
Mike Marciniszyn | 1dd173b | 2013-06-15 17:07:14 -0400 | [diff] [blame] | 593 | return ret; |
| 594 | } |
| 595 | |
| 596 | static const char * const qp_type_str[] = { |
| 597 | "SMI", "GSI", "RC", "UC", "UD", |
| 598 | }; |
| 599 | |
| 600 | void qib_qp_iter_print(struct seq_file *s, struct qib_qp_iter *iter) |
| 601 | { |
Dennis Dalessandro | 7c2e11f | 2016-01-22 12:45:59 -0800 | [diff] [blame] | 602 | struct rvt_swqe *wqe; |
| 603 | struct rvt_qp *qp = iter->qp; |
Dennis Dalessandro | ffc2690 | 2016-01-22 12:45:11 -0800 | [diff] [blame] | 604 | struct qib_qp_priv *priv = qp->priv; |
Mike Marciniszyn | 1dd173b | 2013-06-15 17:07:14 -0400 | [diff] [blame] | 605 | |
Harish Chegondi | db3ef0e | 2016-01-22 13:07:42 -0800 | [diff] [blame] | 606 | wqe = rvt_get_swqe_ptr(qp, qp->s_last); |
Mike Marciniszyn | 1dd173b | 2013-06-15 17:07:14 -0400 | [diff] [blame] | 607 | seq_printf(s, |
| 608 | "N %d QP%u %s %u %u %u f=%x %u %u %u %u %u PSN %x %x %x %x %x (%u %u %u %u %u %u) QP%u LID %x\n", |
| 609 | iter->n, |
| 610 | qp->ibqp.qp_num, |
| 611 | qp_type_str[qp->ibqp.qp_type], |
| 612 | qp->state, |
| 613 | wqe->wr.opcode, |
| 614 | qp->s_hdrwords, |
| 615 | qp->s_flags, |
Dennis Dalessandro | ffc2690 | 2016-01-22 12:45:11 -0800 | [diff] [blame] | 616 | atomic_read(&priv->s_dma_busy), |
| 617 | !list_empty(&priv->iowait), |
Mike Marciniszyn | 1dd173b | 2013-06-15 17:07:14 -0400 | [diff] [blame] | 618 | qp->timeout, |
| 619 | wqe->ssn, |
| 620 | qp->s_lsn, |
| 621 | qp->s_last_psn, |
| 622 | qp->s_psn, qp->s_next_psn, |
| 623 | qp->s_sending_psn, qp->s_sending_hpsn, |
| 624 | qp->s_last, qp->s_acked, qp->s_cur, |
| 625 | qp->s_tail, qp->s_head, qp->s_size, |
| 626 | qp->remote_qpn, |
| 627 | qp->remote_ah_attr.dlid); |
| 628 | } |
| 629 | |
| 630 | #endif |