Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1 | /* |
Vishwanathapura, Niranjana | d4829ea | 2017-04-12 20:29:28 -0700 | [diff] [blame^] | 2 | * Copyright(c) 2015-2017 Intel Corporation. |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 3 | * |
| 4 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 5 | * redistributing this file, you may do so under either license. |
| 6 | * |
| 7 | * GPL LICENSE SUMMARY |
| 8 | * |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of version 2 of the GNU General Public License as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * BSD LICENSE |
| 19 | * |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 20 | * Redistribution and use in source and binary forms, with or without |
| 21 | * modification, are permitted provided that the following conditions |
| 22 | * are met: |
| 23 | * |
| 24 | * - Redistributions of source code must retain the above copyright |
| 25 | * notice, this list of conditions and the following disclaimer. |
| 26 | * - Redistributions in binary form must reproduce the above copyright |
| 27 | * notice, this list of conditions and the following disclaimer in |
| 28 | * the documentation and/or other materials provided with the |
| 29 | * distribution. |
| 30 | * - Neither the name of Intel Corporation nor the names of its |
| 31 | * contributors may be used to endorse or promote products derived |
| 32 | * from this software without specific prior written permission. |
| 33 | * |
| 34 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 35 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 37 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 38 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 39 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 40 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 41 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 42 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 43 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 44 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 45 | * |
| 46 | */ |
| 47 | |
| 48 | #include <linux/pci.h> |
| 49 | #include <linux/netdevice.h> |
| 50 | #include <linux/vmalloc.h> |
| 51 | #include <linux/delay.h> |
| 52 | #include <linux/idr.h> |
| 53 | #include <linux/module.h> |
| 54 | #include <linux/printk.h> |
| 55 | #include <linux/hrtimer.h> |
Dennis Dalessandro | ec3f2c1 | 2016-01-19 14:41:33 -0800 | [diff] [blame] | 56 | #include <rdma/rdma_vt.h> |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 57 | |
| 58 | #include "hfi.h" |
| 59 | #include "device.h" |
| 60 | #include "common.h" |
Sebastian Sanchez | 6c63e42 | 2015-11-06 20:06:56 -0500 | [diff] [blame] | 61 | #include "trace.h" |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 62 | #include "mad.h" |
| 63 | #include "sdma.h" |
| 64 | #include "debugfs.h" |
| 65 | #include "verbs.h" |
Ashutosh Dixit | affa48d | 2016-02-03 14:33:06 -0800 | [diff] [blame] | 66 | #include "aspm.h" |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 67 | #include "affinity.h" |
Vishwanathapura, Niranjana | d4829ea | 2017-04-12 20:29:28 -0700 | [diff] [blame^] | 68 | #include "vnic.h" |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 69 | |
| 70 | #undef pr_fmt |
| 71 | #define pr_fmt(fmt) DRIVER_NAME ": " fmt |
| 72 | |
| 73 | /* |
| 74 | * min buffers we want to have per context, after driver |
| 75 | */ |
| 76 | #define HFI1_MIN_USER_CTXT_BUFCNT 7 |
| 77 | |
| 78 | #define HFI1_MIN_HDRQ_EGRBUF_CNT 2 |
Sebastian Sanchez | e002dcc | 2016-02-03 14:34:32 -0800 | [diff] [blame] | 79 | #define HFI1_MAX_HDRQ_EGRBUF_CNT 16352 |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 80 | #define HFI1_MIN_EAGER_BUFFER_SIZE (4 * 1024) /* 4KB */ |
| 81 | #define HFI1_MAX_EAGER_BUFFER_SIZE (256 * 1024) /* 256KB */ |
| 82 | |
| 83 | /* |
| 84 | * Number of user receive contexts we are configured to use (to allow for more |
| 85 | * pio buffers per ctxt, etc.) Zero means use one user context per CPU. |
| 86 | */ |
Sebastian Sanchez | 2ce6bf2 | 2015-12-11 08:44:48 -0500 | [diff] [blame] | 87 | int num_user_contexts = -1; |
| 88 | module_param_named(num_user_contexts, num_user_contexts, uint, S_IRUGO); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 89 | MODULE_PARM_DESC( |
Sebastian Sanchez | 2ce6bf2 | 2015-12-11 08:44:48 -0500 | [diff] [blame] | 90 | num_user_contexts, "Set max number of user contexts to use"); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 91 | |
Mark F. Brown | 5b55ea3 | 2016-01-11 18:30:54 -0500 | [diff] [blame] | 92 | uint krcvqs[RXE_NUM_DATA_VL]; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 93 | int krcvqsset; |
Mark F. Brown | 5b55ea3 | 2016-01-11 18:30:54 -0500 | [diff] [blame] | 94 | module_param_array(krcvqs, uint, &krcvqsset, S_IRUGO); |
Niranjana Vishwanathapura | 82c2611 | 2015-11-11 00:35:19 -0500 | [diff] [blame] | 95 | MODULE_PARM_DESC(krcvqs, "Array of the number of non-control kernel receive queues by VL"); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 96 | |
| 97 | /* computed based on above array */ |
Harish Chegondi | 429b6a7 | 2016-08-31 07:24:40 -0700 | [diff] [blame] | 98 | unsigned long n_krcvqs; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 99 | |
| 100 | static unsigned hfi1_rcvarr_split = 25; |
| 101 | module_param_named(rcvarr_split, hfi1_rcvarr_split, uint, S_IRUGO); |
| 102 | MODULE_PARM_DESC(rcvarr_split, "Percent of context's RcvArray entries used for Eager buffers"); |
| 103 | |
| 104 | static uint eager_buffer_size = (2 << 20); /* 2MB */ |
| 105 | module_param(eager_buffer_size, uint, S_IRUGO); |
| 106 | MODULE_PARM_DESC(eager_buffer_size, "Size of the eager buffers, default: 2MB"); |
| 107 | |
| 108 | static uint rcvhdrcnt = 2048; /* 2x the max eager buffer count */ |
| 109 | module_param_named(rcvhdrcnt, rcvhdrcnt, uint, S_IRUGO); |
| 110 | MODULE_PARM_DESC(rcvhdrcnt, "Receive header queue count (default 2048)"); |
| 111 | |
| 112 | static uint hfi1_hdrq_entsize = 32; |
| 113 | module_param_named(hdrq_entsize, hfi1_hdrq_entsize, uint, S_IRUGO); |
| 114 | MODULE_PARM_DESC(hdrq_entsize, "Size of header queue entries: 2 - 8B, 16 - 64B (default), 32 - 128B"); |
| 115 | |
| 116 | unsigned int user_credit_return_threshold = 33; /* default is 33% */ |
| 117 | module_param(user_credit_return_threshold, uint, S_IRUGO); |
Jubin John | ecb95a0 | 2015-12-17 19:24:14 -0500 | [diff] [blame] | 118 | MODULE_PARM_DESC(user_credit_return_threshold, "Credit return threshold for user send contexts, return when unreturned credits passes this many blocks (in percent of allocated blocks, 0 is off)"); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 119 | |
| 120 | static inline u64 encode_rcv_header_entry_size(u16); |
| 121 | |
| 122 | static struct idr hfi1_unit_table; |
| 123 | u32 hfi1_cpulist_count; |
| 124 | unsigned long *hfi1_cpulist; |
| 125 | |
| 126 | /* |
| 127 | * Common code for creating the receive context array. |
| 128 | */ |
| 129 | int hfi1_create_ctxts(struct hfi1_devdata *dd) |
| 130 | { |
| 131 | unsigned i; |
| 132 | int ret; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 133 | |
Niranjana Vishwanathapura | 82c2611 | 2015-11-11 00:35:19 -0500 | [diff] [blame] | 134 | /* Control context has to be always 0 */ |
| 135 | BUILD_BUG_ON(HFI1_CTRL_CTXT != 0); |
| 136 | |
Mitko Haralanov | 377f111 | 2016-02-03 14:33:58 -0800 | [diff] [blame] | 137 | dd->rcd = kzalloc_node(dd->num_rcv_contexts * sizeof(*dd->rcd), |
| 138 | GFP_KERNEL, dd->node); |
Alison Schofield | 806e6e1 | 2015-10-12 14:28:36 -0700 | [diff] [blame] | 139 | if (!dd->rcd) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 140 | goto nomem; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 141 | |
| 142 | /* create one or more kernel contexts */ |
| 143 | for (i = 0; i < dd->first_user_ctxt; ++i) { |
| 144 | struct hfi1_pportdata *ppd; |
| 145 | struct hfi1_ctxtdata *rcd; |
| 146 | |
| 147 | ppd = dd->pport + (i % dd->num_pports); |
Jianxin Xiong | 4dfe7cc | 2016-10-17 04:19:41 -0700 | [diff] [blame] | 148 | |
| 149 | /* dd->rcd[i] gets assigned inside the callee */ |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 150 | rcd = hfi1_create_ctxtdata(ppd, i, dd->node); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 151 | if (!rcd) { |
| 152 | dd_dev_err(dd, |
Jubin John | 17fb4f2 | 2016-02-14 20:21:52 -0800 | [diff] [blame] | 153 | "Unable to allocate kernel receive context, failing\n"); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 154 | goto nomem; |
| 155 | } |
| 156 | /* |
| 157 | * Set up the kernel context flags here and now because they |
| 158 | * use default values for all receive side memories. User |
| 159 | * contexts will be handled as they are created. |
| 160 | */ |
| 161 | rcd->flags = HFI1_CAP_KGET(MULTI_PKT_EGR) | |
| 162 | HFI1_CAP_KGET(NODROP_RHQ_FULL) | |
| 163 | HFI1_CAP_KGET(NODROP_EGR_FULL) | |
| 164 | HFI1_CAP_KGET(DMA_RTAIL); |
Niranjana Vishwanathapura | 82c2611 | 2015-11-11 00:35:19 -0500 | [diff] [blame] | 165 | |
| 166 | /* Control context must use DMA_RTAIL */ |
| 167 | if (rcd->ctxt == HFI1_CTRL_CTXT) |
| 168 | rcd->flags |= HFI1_CAP_DMA_RTAIL; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 169 | rcd->seq_cnt = 1; |
| 170 | |
| 171 | rcd->sc = sc_alloc(dd, SC_ACK, rcd->rcvhdrqentsize, dd->node); |
| 172 | if (!rcd->sc) { |
| 173 | dd_dev_err(dd, |
Jubin John | 17fb4f2 | 2016-02-14 20:21:52 -0800 | [diff] [blame] | 174 | "Unable to allocate kernel send context, failing\n"); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 175 | goto nomem; |
| 176 | } |
| 177 | |
| 178 | ret = hfi1_init_ctxt(rcd->sc); |
| 179 | if (ret < 0) { |
| 180 | dd_dev_err(dd, |
| 181 | "Failed to setup kernel receive context, failing\n"); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 182 | ret = -EFAULT; |
| 183 | goto bail; |
| 184 | } |
| 185 | } |
| 186 | |
Ashutosh Dixit | affa48d | 2016-02-03 14:33:06 -0800 | [diff] [blame] | 187 | /* |
| 188 | * Initialize aspm, to be done after gen3 transition and setting up |
| 189 | * contexts and before enabling interrupts |
| 190 | */ |
| 191 | aspm_init(dd); |
| 192 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 193 | return 0; |
| 194 | nomem: |
| 195 | ret = -ENOMEM; |
| 196 | bail: |
Jianxin Xiong | 4dfe7cc | 2016-10-17 04:19:41 -0700 | [diff] [blame] | 197 | if (dd->rcd) { |
| 198 | for (i = 0; i < dd->num_rcv_contexts; ++i) |
| 199 | hfi1_free_ctxtdata(dd, dd->rcd[i]); |
| 200 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 201 | kfree(dd->rcd); |
| 202 | dd->rcd = NULL; |
| 203 | return ret; |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * Common code for user and kernel context setup. |
| 208 | */ |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 209 | struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt, |
| 210 | int numa) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 211 | { |
| 212 | struct hfi1_devdata *dd = ppd->dd; |
| 213 | struct hfi1_ctxtdata *rcd; |
| 214 | unsigned kctxt_ngroups = 0; |
| 215 | u32 base; |
| 216 | |
| 217 | if (dd->rcv_entries.nctxt_extra > |
| 218 | dd->num_rcv_contexts - dd->first_user_ctxt) |
| 219 | kctxt_ngroups = (dd->rcv_entries.nctxt_extra - |
| 220 | (dd->num_rcv_contexts - dd->first_user_ctxt)); |
Jianxin Xiong | 4dfe7cc | 2016-10-17 04:19:41 -0700 | [diff] [blame] | 221 | rcd = kzalloc_node(sizeof(*rcd), GFP_KERNEL, numa); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 222 | if (rcd) { |
| 223 | u32 rcvtids, max_entries; |
| 224 | |
Sebastian Sanchez | 6c63e42 | 2015-11-06 20:06:56 -0500 | [diff] [blame] | 225 | hfi1_cdbg(PROC, "setting up context %u\n", ctxt); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 226 | |
| 227 | INIT_LIST_HEAD(&rcd->qp_wait_list); |
| 228 | rcd->ppd = ppd; |
| 229 | rcd->dd = dd; |
| 230 | rcd->cnt = 1; |
| 231 | rcd->ctxt = ctxt; |
| 232 | dd->rcd[ctxt] = rcd; |
Mitko Haralanov | 957558c | 2016-02-03 14:33:40 -0800 | [diff] [blame] | 233 | rcd->numa_id = numa; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 234 | rcd->rcv_array_groups = dd->rcv_entries.ngroups; |
| 235 | |
Mitko Haralanov | 463e6eb | 2016-02-05 11:57:53 -0500 | [diff] [blame] | 236 | mutex_init(&rcd->exp_lock); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 237 | |
| 238 | /* |
| 239 | * Calculate the context's RcvArray entry starting point. |
| 240 | * We do this here because we have to take into account all |
| 241 | * the RcvArray entries that previous context would have |
| 242 | * taken and we have to account for any extra groups |
| 243 | * assigned to the kernel or user contexts. |
| 244 | */ |
| 245 | if (ctxt < dd->first_user_ctxt) { |
| 246 | if (ctxt < kctxt_ngroups) { |
| 247 | base = ctxt * (dd->rcv_entries.ngroups + 1); |
| 248 | rcd->rcv_array_groups++; |
| 249 | } else |
| 250 | base = kctxt_ngroups + |
| 251 | (ctxt * dd->rcv_entries.ngroups); |
| 252 | } else { |
| 253 | u16 ct = ctxt - dd->first_user_ctxt; |
| 254 | |
| 255 | base = ((dd->n_krcv_queues * dd->rcv_entries.ngroups) + |
| 256 | kctxt_ngroups); |
| 257 | if (ct < dd->rcv_entries.nctxt_extra) { |
| 258 | base += ct * (dd->rcv_entries.ngroups + 1); |
| 259 | rcd->rcv_array_groups++; |
| 260 | } else |
| 261 | base += dd->rcv_entries.nctxt_extra + |
| 262 | (ct * dd->rcv_entries.ngroups); |
| 263 | } |
| 264 | rcd->eager_base = base * dd->rcv_entries.group_size; |
| 265 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 266 | rcd->rcvhdrq_cnt = rcvhdrcnt; |
| 267 | rcd->rcvhdrqentsize = hfi1_hdrq_entsize; |
| 268 | /* |
| 269 | * Simple Eager buffer allocation: we have already pre-allocated |
| 270 | * the number of RcvArray entry groups. Each ctxtdata structure |
| 271 | * holds the number of groups for that context. |
| 272 | * |
| 273 | * To follow CSR requirements and maintain cacheline alignment, |
| 274 | * make sure all sizes and bases are multiples of group_size. |
| 275 | * |
| 276 | * The expected entry count is what is left after assigning |
| 277 | * eager. |
| 278 | */ |
| 279 | max_entries = rcd->rcv_array_groups * |
| 280 | dd->rcv_entries.group_size; |
| 281 | rcvtids = ((max_entries * hfi1_rcvarr_split) / 100); |
| 282 | rcd->egrbufs.count = round_down(rcvtids, |
| 283 | dd->rcv_entries.group_size); |
| 284 | if (rcd->egrbufs.count > MAX_EAGER_ENTRIES) { |
| 285 | dd_dev_err(dd, "ctxt%u: requested too many RcvArray entries.\n", |
| 286 | rcd->ctxt); |
| 287 | rcd->egrbufs.count = MAX_EAGER_ENTRIES; |
| 288 | } |
Sebastian Sanchez | 6c63e42 | 2015-11-06 20:06:56 -0500 | [diff] [blame] | 289 | hfi1_cdbg(PROC, |
| 290 | "ctxt%u: max Eager buffer RcvArray entries: %u\n", |
| 291 | rcd->ctxt, rcd->egrbufs.count); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 292 | |
| 293 | /* |
| 294 | * Allocate array that will hold the eager buffer accounting |
| 295 | * data. |
| 296 | * This will allocate the maximum possible buffer count based |
| 297 | * on the value of the RcvArray split parameter. |
| 298 | * The resulting value will be rounded down to the closest |
| 299 | * multiple of dd->rcv_entries.group_size. |
| 300 | */ |
Sebastian Sanchez | b448bf9 | 2017-02-08 05:26:37 -0800 | [diff] [blame] | 301 | rcd->egrbufs.buffers = kzalloc_node( |
| 302 | rcd->egrbufs.count * sizeof(*rcd->egrbufs.buffers), |
| 303 | GFP_KERNEL, numa); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 304 | if (!rcd->egrbufs.buffers) |
| 305 | goto bail; |
Sebastian Sanchez | b448bf9 | 2017-02-08 05:26:37 -0800 | [diff] [blame] | 306 | rcd->egrbufs.rcvtids = kzalloc_node( |
| 307 | rcd->egrbufs.count * |
| 308 | sizeof(*rcd->egrbufs.rcvtids), |
| 309 | GFP_KERNEL, numa); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 310 | if (!rcd->egrbufs.rcvtids) |
| 311 | goto bail; |
| 312 | rcd->egrbufs.size = eager_buffer_size; |
| 313 | /* |
| 314 | * The size of the buffers programmed into the RcvArray |
| 315 | * entries needs to be big enough to handle the highest |
| 316 | * MTU supported. |
| 317 | */ |
| 318 | if (rcd->egrbufs.size < hfi1_max_mtu) { |
| 319 | rcd->egrbufs.size = __roundup_pow_of_two(hfi1_max_mtu); |
Sebastian Sanchez | 6c63e42 | 2015-11-06 20:06:56 -0500 | [diff] [blame] | 320 | hfi1_cdbg(PROC, |
| 321 | "ctxt%u: eager bufs size too small. Adjusting to %zu\n", |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 322 | rcd->ctxt, rcd->egrbufs.size); |
| 323 | } |
| 324 | rcd->egrbufs.rcvtid_size = HFI1_MAX_EAGER_BUFFER_SIZE; |
| 325 | |
| 326 | if (ctxt < dd->first_user_ctxt) { /* N/A for PSM contexts */ |
Sebastian Sanchez | b448bf9 | 2017-02-08 05:26:37 -0800 | [diff] [blame] | 327 | rcd->opstats = kzalloc_node(sizeof(*rcd->opstats), |
| 328 | GFP_KERNEL, numa); |
Alison Schofield | 806e6e1 | 2015-10-12 14:28:36 -0700 | [diff] [blame] | 329 | if (!rcd->opstats) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 330 | goto bail; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | return rcd; |
| 334 | bail: |
Jakub Pawlak | 3a6982d | 2016-09-25 07:42:23 -0700 | [diff] [blame] | 335 | dd->rcd[ctxt] = NULL; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 336 | kfree(rcd->egrbufs.rcvtids); |
| 337 | kfree(rcd->egrbufs.buffers); |
| 338 | kfree(rcd); |
| 339 | return NULL; |
| 340 | } |
| 341 | |
| 342 | /* |
| 343 | * Convert a receive header entry size that to the encoding used in the CSR. |
| 344 | * |
| 345 | * Return a zero if the given size is invalid. |
| 346 | */ |
| 347 | static inline u64 encode_rcv_header_entry_size(u16 size) |
| 348 | { |
| 349 | /* there are only 3 valid receive header entry sizes */ |
| 350 | if (size == 2) |
| 351 | return 1; |
| 352 | if (size == 16) |
| 353 | return 2; |
| 354 | else if (size == 32) |
| 355 | return 4; |
| 356 | return 0; /* invalid */ |
| 357 | } |
| 358 | |
| 359 | /* |
| 360 | * Select the largest ccti value over all SLs to determine the intra- |
| 361 | * packet gap for the link. |
| 362 | * |
| 363 | * called with cca_timer_lock held (to protect access to cca_timer |
| 364 | * array), and rcu_read_lock() (to protect access to cc_state). |
| 365 | */ |
| 366 | void set_link_ipg(struct hfi1_pportdata *ppd) |
| 367 | { |
| 368 | struct hfi1_devdata *dd = ppd->dd; |
| 369 | struct cc_state *cc_state; |
| 370 | int i; |
| 371 | u16 cce, ccti_limit, max_ccti = 0; |
| 372 | u16 shift, mult; |
| 373 | u64 src; |
| 374 | u32 current_egress_rate; /* Mbits /sec */ |
| 375 | u32 max_pkt_time; |
| 376 | /* |
| 377 | * max_pkt_time is the maximum packet egress time in units |
| 378 | * of the fabric clock period 1/(805 MHz). |
| 379 | */ |
| 380 | |
| 381 | cc_state = get_cc_state(ppd); |
| 382 | |
Jubin John | d125a6c | 2016-02-14 20:19:49 -0800 | [diff] [blame] | 383 | if (!cc_state) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 384 | /* |
| 385 | * This should _never_ happen - rcu_read_lock() is held, |
| 386 | * and set_link_ipg() should not be called if cc_state |
| 387 | * is NULL. |
| 388 | */ |
| 389 | return; |
| 390 | |
| 391 | for (i = 0; i < OPA_MAX_SLS; i++) { |
| 392 | u16 ccti = ppd->cca_timer[i].ccti; |
| 393 | |
| 394 | if (ccti > max_ccti) |
| 395 | max_ccti = ccti; |
| 396 | } |
| 397 | |
| 398 | ccti_limit = cc_state->cct.ccti_limit; |
| 399 | if (max_ccti > ccti_limit) |
| 400 | max_ccti = ccti_limit; |
| 401 | |
| 402 | cce = cc_state->cct.entries[max_ccti].entry; |
| 403 | shift = (cce & 0xc000) >> 14; |
| 404 | mult = (cce & 0x3fff); |
| 405 | |
| 406 | current_egress_rate = active_egress_rate(ppd); |
| 407 | |
| 408 | max_pkt_time = egress_cycles(ppd->ibmaxlen, current_egress_rate); |
| 409 | |
| 410 | src = (max_pkt_time >> shift) * mult; |
| 411 | |
| 412 | src &= SEND_STATIC_RATE_CONTROL_CSR_SRC_RELOAD_SMASK; |
| 413 | src <<= SEND_STATIC_RATE_CONTROL_CSR_SRC_RELOAD_SHIFT; |
| 414 | |
| 415 | write_csr(dd, SEND_STATIC_RATE_CONTROL, src); |
| 416 | } |
| 417 | |
| 418 | static enum hrtimer_restart cca_timer_fn(struct hrtimer *t) |
| 419 | { |
| 420 | struct cca_timer *cca_timer; |
| 421 | struct hfi1_pportdata *ppd; |
| 422 | int sl; |
Jubin John | d35cf744 | 2016-04-14 08:31:53 -0700 | [diff] [blame] | 423 | u16 ccti_timer, ccti_min; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 424 | struct cc_state *cc_state; |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 425 | unsigned long flags; |
Jubin John | d35cf744 | 2016-04-14 08:31:53 -0700 | [diff] [blame] | 426 | enum hrtimer_restart ret = HRTIMER_NORESTART; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 427 | |
| 428 | cca_timer = container_of(t, struct cca_timer, hrtimer); |
| 429 | ppd = cca_timer->ppd; |
| 430 | sl = cca_timer->sl; |
| 431 | |
| 432 | rcu_read_lock(); |
| 433 | |
| 434 | cc_state = get_cc_state(ppd); |
| 435 | |
Jubin John | d125a6c | 2016-02-14 20:19:49 -0800 | [diff] [blame] | 436 | if (!cc_state) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 437 | rcu_read_unlock(); |
| 438 | return HRTIMER_NORESTART; |
| 439 | } |
| 440 | |
| 441 | /* |
| 442 | * 1) decrement ccti for SL |
| 443 | * 2) calculate IPG for link (set_link_ipg()) |
| 444 | * 3) restart timer, unless ccti is at min value |
| 445 | */ |
| 446 | |
| 447 | ccti_min = cc_state->cong_setting.entries[sl].ccti_min; |
| 448 | ccti_timer = cc_state->cong_setting.entries[sl].ccti_timer; |
| 449 | |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 450 | spin_lock_irqsave(&ppd->cca_timer_lock, flags); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 451 | |
Jubin John | d35cf744 | 2016-04-14 08:31:53 -0700 | [diff] [blame] | 452 | if (cca_timer->ccti > ccti_min) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 453 | cca_timer->ccti--; |
| 454 | set_link_ipg(ppd); |
| 455 | } |
| 456 | |
Jubin John | d35cf744 | 2016-04-14 08:31:53 -0700 | [diff] [blame] | 457 | if (cca_timer->ccti > ccti_min) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 458 | unsigned long nsec = 1024 * ccti_timer; |
| 459 | /* ccti_timer is in units of 1.024 usec */ |
| 460 | hrtimer_forward_now(t, ns_to_ktime(nsec)); |
Jubin John | d35cf744 | 2016-04-14 08:31:53 -0700 | [diff] [blame] | 461 | ret = HRTIMER_RESTART; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 462 | } |
Jubin John | d35cf744 | 2016-04-14 08:31:53 -0700 | [diff] [blame] | 463 | |
| 464 | spin_unlock_irqrestore(&ppd->cca_timer_lock, flags); |
| 465 | rcu_read_unlock(); |
| 466 | return ret; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | /* |
| 470 | * Common code for initializing the physical port structure. |
| 471 | */ |
| 472 | void hfi1_init_pportdata(struct pci_dev *pdev, struct hfi1_pportdata *ppd, |
| 473 | struct hfi1_devdata *dd, u8 hw_pidx, u8 port) |
| 474 | { |
Jianxin Xiong | 8adf71f | 2016-07-25 13:39:14 -0700 | [diff] [blame] | 475 | int i; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 476 | uint default_pkey_idx; |
Jianxin Xiong | 8adf71f | 2016-07-25 13:39:14 -0700 | [diff] [blame] | 477 | struct cc_state *cc_state; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 478 | |
| 479 | ppd->dd = dd; |
| 480 | ppd->hw_pidx = hw_pidx; |
| 481 | ppd->port = port; /* IB port number, not index */ |
| 482 | |
| 483 | default_pkey_idx = 1; |
| 484 | |
| 485 | ppd->pkeys[default_pkey_idx] = DEFAULT_P_KEY; |
| 486 | if (loopback) { |
| 487 | hfi1_early_err(&pdev->dev, |
| 488 | "Faking data partition 0x8001 in idx %u\n", |
| 489 | !default_pkey_idx); |
| 490 | ppd->pkeys[!default_pkey_idx] = 0x8001; |
| 491 | } |
| 492 | |
| 493 | INIT_WORK(&ppd->link_vc_work, handle_verify_cap); |
| 494 | INIT_WORK(&ppd->link_up_work, handle_link_up); |
| 495 | INIT_WORK(&ppd->link_down_work, handle_link_down); |
| 496 | INIT_WORK(&ppd->freeze_work, handle_freeze); |
| 497 | INIT_WORK(&ppd->link_downgrade_work, handle_link_downgrade); |
| 498 | INIT_WORK(&ppd->sma_message_work, handle_sma_message); |
| 499 | INIT_WORK(&ppd->link_bounce_work, handle_link_bounce); |
Dean Luick | 673b975 | 2016-08-31 07:24:33 -0700 | [diff] [blame] | 500 | INIT_DELAYED_WORK(&ppd->start_link_work, handle_start_link); |
Jim Snow | fb9036d | 2016-01-11 18:32:21 -0500 | [diff] [blame] | 501 | INIT_WORK(&ppd->linkstate_active_work, receive_interrupt_work); |
Easwar Hariharan | 8ebd4cf | 2016-02-03 14:31:14 -0800 | [diff] [blame] | 502 | INIT_WORK(&ppd->qsfp_info.qsfp_work, qsfp_event); |
| 503 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 504 | mutex_init(&ppd->hls_lock); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 505 | spin_lock_init(&ppd->qsfp_info.qsfp_lock); |
| 506 | |
Easwar Hariharan | 8ebd4cf | 2016-02-03 14:31:14 -0800 | [diff] [blame] | 507 | ppd->qsfp_info.ppd = ppd; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 508 | ppd->sm_trap_qp = 0x0; |
| 509 | ppd->sa_qp = 0x1; |
| 510 | |
| 511 | ppd->hfi1_wq = NULL; |
| 512 | |
| 513 | spin_lock_init(&ppd->cca_timer_lock); |
| 514 | |
| 515 | for (i = 0; i < OPA_MAX_SLS; i++) { |
| 516 | hrtimer_init(&ppd->cca_timer[i].hrtimer, CLOCK_MONOTONIC, |
| 517 | HRTIMER_MODE_REL); |
| 518 | ppd->cca_timer[i].ppd = ppd; |
| 519 | ppd->cca_timer[i].sl = i; |
| 520 | ppd->cca_timer[i].ccti = 0; |
| 521 | ppd->cca_timer[i].hrtimer.function = cca_timer_fn; |
| 522 | } |
| 523 | |
| 524 | ppd->cc_max_table_entries = IB_CC_TABLE_CAP_DEFAULT; |
| 525 | |
| 526 | spin_lock_init(&ppd->cc_state_lock); |
| 527 | spin_lock_init(&ppd->cc_log_lock); |
Jianxin Xiong | 8adf71f | 2016-07-25 13:39:14 -0700 | [diff] [blame] | 528 | cc_state = kzalloc(sizeof(*cc_state), GFP_KERNEL); |
| 529 | RCU_INIT_POINTER(ppd->cc_state, cc_state); |
| 530 | if (!cc_state) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 531 | goto bail; |
| 532 | return; |
| 533 | |
| 534 | bail: |
| 535 | |
| 536 | hfi1_early_err(&pdev->dev, |
| 537 | "Congestion Control Agent disabled for port %d\n", port); |
| 538 | } |
| 539 | |
| 540 | /* |
| 541 | * Do initialization for device that is only needed on |
| 542 | * first detect, not on resets. |
| 543 | */ |
| 544 | static int loadtime_init(struct hfi1_devdata *dd) |
| 545 | { |
| 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * init_after_reset - re-initialize after a reset |
| 551 | * @dd: the hfi1_ib device |
| 552 | * |
| 553 | * sanity check at least some of the values after reset, and |
| 554 | * ensure no receive or transmit (explicitly, in case reset |
| 555 | * failed |
| 556 | */ |
| 557 | static int init_after_reset(struct hfi1_devdata *dd) |
| 558 | { |
| 559 | int i; |
| 560 | |
| 561 | /* |
| 562 | * Ensure chip does no sends or receives, tail updates, or |
| 563 | * pioavail updates while we re-initialize. This is mostly |
| 564 | * for the driver data structures, not chip registers. |
| 565 | */ |
| 566 | for (i = 0; i < dd->num_rcv_contexts; i++) |
| 567 | hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_DIS | |
| 568 | HFI1_RCVCTRL_INTRAVAIL_DIS | |
| 569 | HFI1_RCVCTRL_TAILUPD_DIS, i); |
| 570 | pio_send_control(dd, PSC_GLOBAL_DISABLE); |
| 571 | for (i = 0; i < dd->num_send_contexts; i++) |
| 572 | sc_disable(dd->send_contexts[i].sc); |
| 573 | |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | static void enable_chip(struct hfi1_devdata *dd) |
| 578 | { |
| 579 | u32 rcvmask; |
| 580 | u32 i; |
| 581 | |
| 582 | /* enable PIO send */ |
| 583 | pio_send_control(dd, PSC_GLOBAL_ENABLE); |
| 584 | |
| 585 | /* |
| 586 | * Enable kernel ctxts' receive and receive interrupt. |
| 587 | * Other ctxts done as user opens and initializes them. |
| 588 | */ |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 589 | for (i = 0; i < dd->first_user_ctxt; ++i) { |
Mitko Haralanov | 566c157 | 2016-02-03 14:32:49 -0800 | [diff] [blame] | 590 | rcvmask = HFI1_RCVCTRL_CTXT_ENB | HFI1_RCVCTRL_INTRAVAIL_ENB; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 591 | rcvmask |= HFI1_CAP_KGET_MASK(dd->rcd[i]->flags, DMA_RTAIL) ? |
| 592 | HFI1_RCVCTRL_TAILUPD_ENB : HFI1_RCVCTRL_TAILUPD_DIS; |
| 593 | if (!HFI1_CAP_KGET_MASK(dd->rcd[i]->flags, MULTI_PKT_EGR)) |
| 594 | rcvmask |= HFI1_RCVCTRL_ONE_PKT_EGR_ENB; |
| 595 | if (HFI1_CAP_KGET_MASK(dd->rcd[i]->flags, NODROP_RHQ_FULL)) |
| 596 | rcvmask |= HFI1_RCVCTRL_NO_RHQ_DROP_ENB; |
| 597 | if (HFI1_CAP_KGET_MASK(dd->rcd[i]->flags, NODROP_EGR_FULL)) |
| 598 | rcvmask |= HFI1_RCVCTRL_NO_EGR_DROP_ENB; |
| 599 | hfi1_rcvctrl(dd, rcvmask, i); |
| 600 | sc_enable(dd->rcd[i]->sc); |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | /** |
| 605 | * create_workqueues - create per port workqueues |
| 606 | * @dd: the hfi1_ib device |
| 607 | */ |
| 608 | static int create_workqueues(struct hfi1_devdata *dd) |
| 609 | { |
| 610 | int pidx; |
| 611 | struct hfi1_pportdata *ppd; |
| 612 | |
| 613 | for (pidx = 0; pidx < dd->num_pports; ++pidx) { |
| 614 | ppd = dd->pport + pidx; |
| 615 | if (!ppd->hfi1_wq) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 616 | ppd->hfi1_wq = |
Mike Marciniszyn | 0a226ed | 2015-11-09 19:13:58 -0500 | [diff] [blame] | 617 | alloc_workqueue( |
| 618 | "hfi%d_%d", |
| 619 | WQ_SYSFS | WQ_HIGHPRI | WQ_CPU_INTENSIVE, |
| 620 | dd->num_sdma, |
| 621 | dd->unit, pidx); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 622 | if (!ppd->hfi1_wq) |
| 623 | goto wq_error; |
| 624 | } |
| 625 | } |
| 626 | return 0; |
| 627 | wq_error: |
Mike Marciniszyn | 0a226ed | 2015-11-09 19:13:58 -0500 | [diff] [blame] | 628 | pr_err("alloc_workqueue failed for port %d\n", pidx + 1); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 629 | for (pidx = 0; pidx < dd->num_pports; ++pidx) { |
| 630 | ppd = dd->pport + pidx; |
| 631 | if (ppd->hfi1_wq) { |
| 632 | destroy_workqueue(ppd->hfi1_wq); |
| 633 | ppd->hfi1_wq = NULL; |
| 634 | } |
| 635 | } |
| 636 | return -ENOMEM; |
| 637 | } |
| 638 | |
| 639 | /** |
| 640 | * hfi1_init - do the actual initialization sequence on the chip |
| 641 | * @dd: the hfi1_ib device |
| 642 | * @reinit: re-initializing, so don't allocate new memory |
| 643 | * |
| 644 | * Do the actual initialization sequence on the chip. This is done |
| 645 | * both from the init routine called from the PCI infrastructure, and |
| 646 | * when we reset the chip, or detect that it was reset internally, |
| 647 | * or it's administratively re-enabled. |
| 648 | * |
| 649 | * Memory allocation here and in called routines is only done in |
| 650 | * the first case (reinit == 0). We have to be careful, because even |
| 651 | * without memory allocation, we need to re-write all the chip registers |
| 652 | * TIDs, etc. after the reset or enable has completed. |
| 653 | */ |
| 654 | int hfi1_init(struct hfi1_devdata *dd, int reinit) |
| 655 | { |
| 656 | int ret = 0, pidx, lastfail = 0; |
| 657 | unsigned i, len; |
| 658 | struct hfi1_ctxtdata *rcd; |
| 659 | struct hfi1_pportdata *ppd; |
| 660 | |
| 661 | /* Set up recv low level handlers */ |
| 662 | dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_EXPECTED] = |
| 663 | kdeth_process_expected; |
| 664 | dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_EAGER] = |
| 665 | kdeth_process_eager; |
| 666 | dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_IB] = process_receive_ib; |
| 667 | dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_ERROR] = |
| 668 | process_receive_error; |
| 669 | dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_BYPASS] = |
| 670 | process_receive_bypass; |
| 671 | dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_INVALID5] = |
| 672 | process_receive_invalid; |
| 673 | dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_INVALID6] = |
| 674 | process_receive_invalid; |
| 675 | dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_INVALID7] = |
| 676 | process_receive_invalid; |
| 677 | dd->rhf_rcv_function_map = dd->normal_rhf_rcv_functions; |
| 678 | |
| 679 | /* Set up send low level handlers */ |
| 680 | dd->process_pio_send = hfi1_verbs_send_pio; |
| 681 | dd->process_dma_send = hfi1_verbs_send_dma; |
| 682 | dd->pio_inline_send = pio_copy; |
| 683 | |
Mike Marciniszyn | 995deaf | 2015-11-16 21:59:29 -0500 | [diff] [blame] | 684 | if (is_ax(dd)) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 685 | atomic_set(&dd->drop_packet, DROP_PACKET_ON); |
| 686 | dd->do_drop = 1; |
| 687 | } else { |
| 688 | atomic_set(&dd->drop_packet, DROP_PACKET_OFF); |
| 689 | dd->do_drop = 0; |
| 690 | } |
| 691 | |
| 692 | /* make sure the link is not "up" */ |
| 693 | for (pidx = 0; pidx < dd->num_pports; ++pidx) { |
| 694 | ppd = dd->pport + pidx; |
| 695 | ppd->linkup = 0; |
| 696 | } |
| 697 | |
| 698 | if (reinit) |
| 699 | ret = init_after_reset(dd); |
| 700 | else |
| 701 | ret = loadtime_init(dd); |
| 702 | if (ret) |
| 703 | goto done; |
| 704 | |
Mark F. Brown | 46b010d | 2015-11-09 19:18:20 -0500 | [diff] [blame] | 705 | /* allocate dummy tail memory for all receive contexts */ |
| 706 | dd->rcvhdrtail_dummy_kvaddr = dma_zalloc_coherent( |
| 707 | &dd->pcidev->dev, sizeof(u64), |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 708 | &dd->rcvhdrtail_dummy_dma, |
Mark F. Brown | 46b010d | 2015-11-09 19:18:20 -0500 | [diff] [blame] | 709 | GFP_KERNEL); |
| 710 | |
| 711 | if (!dd->rcvhdrtail_dummy_kvaddr) { |
| 712 | dd_dev_err(dd, "cannot allocate dummy tail memory\n"); |
| 713 | ret = -ENOMEM; |
| 714 | goto done; |
| 715 | } |
| 716 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 717 | /* dd->rcd can be NULL if early initialization failed */ |
| 718 | for (i = 0; dd->rcd && i < dd->first_user_ctxt; ++i) { |
| 719 | /* |
| 720 | * Set up the (kernel) rcvhdr queue and egr TIDs. If doing |
| 721 | * re-init, the simplest way to handle this is to free |
| 722 | * existing, and re-allocate. |
| 723 | * Need to re-create rest of ctxt 0 ctxtdata as well. |
| 724 | */ |
| 725 | rcd = dd->rcd[i]; |
| 726 | if (!rcd) |
| 727 | continue; |
| 728 | |
| 729 | rcd->do_interrupt = &handle_receive_interrupt; |
| 730 | |
| 731 | lastfail = hfi1_create_rcvhdrq(dd, rcd); |
| 732 | if (!lastfail) |
| 733 | lastfail = hfi1_setup_eagerbufs(rcd); |
Ashutosh Dixit | 3923979 | 2016-05-12 10:24:00 -0700 | [diff] [blame] | 734 | if (lastfail) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 735 | dd_dev_err(dd, |
Jubin John | 17fb4f2 | 2016-02-14 20:21:52 -0800 | [diff] [blame] | 736 | "failed to allocate kernel ctxt's rcvhdrq and/or egr bufs\n"); |
Ashutosh Dixit | 3923979 | 2016-05-12 10:24:00 -0700 | [diff] [blame] | 737 | ret = lastfail; |
| 738 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 739 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 740 | |
| 741 | /* Allocate enough memory for user event notification. */ |
Amitoj Kaur Chawla | 8444991 | 2016-03-04 22:30:43 +0530 | [diff] [blame] | 742 | len = PAGE_ALIGN(dd->chip_rcv_contexts * HFI1_MAX_SHARED_CTXTS * |
| 743 | sizeof(*dd->events)); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 744 | dd->events = vmalloc_user(len); |
| 745 | if (!dd->events) |
| 746 | dd_dev_err(dd, "Failed to allocate user events page\n"); |
| 747 | /* |
| 748 | * Allocate a page for device and port status. |
| 749 | * Page will be shared amongst all user processes. |
| 750 | */ |
| 751 | dd->status = vmalloc_user(PAGE_SIZE); |
| 752 | if (!dd->status) |
| 753 | dd_dev_err(dd, "Failed to allocate dev status page\n"); |
| 754 | else |
| 755 | dd->freezelen = PAGE_SIZE - (sizeof(*dd->status) - |
| 756 | sizeof(dd->status->freezemsg)); |
| 757 | for (pidx = 0; pidx < dd->num_pports; ++pidx) { |
| 758 | ppd = dd->pport + pidx; |
| 759 | if (dd->status) |
| 760 | /* Currently, we only have one port */ |
| 761 | ppd->statusp = &dd->status->port; |
| 762 | |
| 763 | set_mtu(ppd); |
| 764 | } |
| 765 | |
| 766 | /* enable chip even if we have an error, so we can debug cause */ |
| 767 | enable_chip(dd); |
| 768 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 769 | done: |
| 770 | /* |
| 771 | * Set status even if port serdes is not initialized |
| 772 | * so that diags will work. |
| 773 | */ |
| 774 | if (dd->status) |
| 775 | dd->status->dev |= HFI1_STATUS_CHIP_PRESENT | |
| 776 | HFI1_STATUS_INITTED; |
| 777 | if (!ret) { |
| 778 | /* enable all interrupts from the chip */ |
| 779 | set_intr_state(dd, 1); |
| 780 | |
| 781 | /* chip is OK for user apps; mark it as initialized */ |
| 782 | for (pidx = 0; pidx < dd->num_pports; ++pidx) { |
| 783 | ppd = dd->pport + pidx; |
| 784 | |
Jubin John | 4d114fd | 2016-02-14 20:21:43 -0800 | [diff] [blame] | 785 | /* |
| 786 | * start the serdes - must be after interrupts are |
| 787 | * enabled so we are notified when the link goes up |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 788 | */ |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 789 | lastfail = bringup_serdes(ppd); |
| 790 | if (lastfail) |
| 791 | dd_dev_info(dd, |
Jubin John | 17fb4f2 | 2016-02-14 20:21:52 -0800 | [diff] [blame] | 792 | "Failed to bring up port %u\n", |
| 793 | ppd->port); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 794 | |
| 795 | /* |
| 796 | * Set status even if port serdes is not initialized |
| 797 | * so that diags will work. |
| 798 | */ |
| 799 | if (ppd->statusp) |
| 800 | *ppd->statusp |= HFI1_STATUS_CHIP_PRESENT | |
| 801 | HFI1_STATUS_INITTED; |
| 802 | if (!ppd->link_speed_enabled) |
| 803 | continue; |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | /* if ret is non-zero, we probably should do some cleanup here... */ |
| 808 | return ret; |
| 809 | } |
| 810 | |
| 811 | static inline struct hfi1_devdata *__hfi1_lookup(int unit) |
| 812 | { |
| 813 | return idr_find(&hfi1_unit_table, unit); |
| 814 | } |
| 815 | |
| 816 | struct hfi1_devdata *hfi1_lookup(int unit) |
| 817 | { |
| 818 | struct hfi1_devdata *dd; |
| 819 | unsigned long flags; |
| 820 | |
| 821 | spin_lock_irqsave(&hfi1_devs_lock, flags); |
| 822 | dd = __hfi1_lookup(unit); |
| 823 | spin_unlock_irqrestore(&hfi1_devs_lock, flags); |
| 824 | |
| 825 | return dd; |
| 826 | } |
| 827 | |
| 828 | /* |
| 829 | * Stop the timers during unit shutdown, or after an error late |
| 830 | * in initialization. |
| 831 | */ |
| 832 | static void stop_timers(struct hfi1_devdata *dd) |
| 833 | { |
| 834 | struct hfi1_pportdata *ppd; |
| 835 | int pidx; |
| 836 | |
| 837 | for (pidx = 0; pidx < dd->num_pports; ++pidx) { |
| 838 | ppd = dd->pport + pidx; |
| 839 | if (ppd->led_override_timer.data) { |
| 840 | del_timer_sync(&ppd->led_override_timer); |
| 841 | atomic_set(&ppd->led_override_timer_active, 0); |
| 842 | } |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | /** |
| 847 | * shutdown_device - shut down a device |
| 848 | * @dd: the hfi1_ib device |
| 849 | * |
| 850 | * This is called to make the device quiet when we are about to |
| 851 | * unload the driver, and also when the device is administratively |
| 852 | * disabled. It does not free any data structures. |
| 853 | * Everything it does has to be setup again by hfi1_init(dd, 1) |
| 854 | */ |
| 855 | static void shutdown_device(struct hfi1_devdata *dd) |
| 856 | { |
| 857 | struct hfi1_pportdata *ppd; |
| 858 | unsigned pidx; |
| 859 | int i; |
| 860 | |
| 861 | for (pidx = 0; pidx < dd->num_pports; ++pidx) { |
| 862 | ppd = dd->pport + pidx; |
| 863 | |
| 864 | ppd->linkup = 0; |
| 865 | if (ppd->statusp) |
| 866 | *ppd->statusp &= ~(HFI1_STATUS_IB_CONF | |
| 867 | HFI1_STATUS_IB_READY); |
| 868 | } |
| 869 | dd->flags &= ~HFI1_INITTED; |
| 870 | |
| 871 | /* mask interrupts, but not errors */ |
| 872 | set_intr_state(dd, 0); |
| 873 | |
| 874 | for (pidx = 0; pidx < dd->num_pports; ++pidx) { |
| 875 | ppd = dd->pport + pidx; |
| 876 | for (i = 0; i < dd->num_rcv_contexts; i++) |
| 877 | hfi1_rcvctrl(dd, HFI1_RCVCTRL_TAILUPD_DIS | |
| 878 | HFI1_RCVCTRL_CTXT_DIS | |
| 879 | HFI1_RCVCTRL_INTRAVAIL_DIS | |
| 880 | HFI1_RCVCTRL_PKEY_DIS | |
| 881 | HFI1_RCVCTRL_ONE_PKT_EGR_DIS, i); |
| 882 | /* |
| 883 | * Gracefully stop all sends allowing any in progress to |
| 884 | * trickle out first. |
| 885 | */ |
| 886 | for (i = 0; i < dd->num_send_contexts; i++) |
| 887 | sc_flush(dd->send_contexts[i].sc); |
| 888 | } |
| 889 | |
| 890 | /* |
| 891 | * Enough for anything that's going to trickle out to have actually |
| 892 | * done so. |
| 893 | */ |
| 894 | udelay(20); |
| 895 | |
| 896 | for (pidx = 0; pidx < dd->num_pports; ++pidx) { |
| 897 | ppd = dd->pport + pidx; |
| 898 | |
| 899 | /* disable all contexts */ |
| 900 | for (i = 0; i < dd->num_send_contexts; i++) |
| 901 | sc_disable(dd->send_contexts[i].sc); |
| 902 | /* disable the send device */ |
| 903 | pio_send_control(dd, PSC_GLOBAL_DISABLE); |
| 904 | |
Easwar Hariharan | 91ab4ed | 2016-02-03 14:35:57 -0800 | [diff] [blame] | 905 | shutdown_led_override(ppd); |
| 906 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 907 | /* |
| 908 | * Clear SerdesEnable. |
| 909 | * We can't count on interrupts since we are stopping. |
| 910 | */ |
| 911 | hfi1_quiet_serdes(ppd); |
| 912 | |
| 913 | if (ppd->hfi1_wq) { |
| 914 | destroy_workqueue(ppd->hfi1_wq); |
| 915 | ppd->hfi1_wq = NULL; |
| 916 | } |
| 917 | } |
| 918 | sdma_exit(dd); |
| 919 | } |
| 920 | |
| 921 | /** |
| 922 | * hfi1_free_ctxtdata - free a context's allocated data |
| 923 | * @dd: the hfi1_ib device |
| 924 | * @rcd: the ctxtdata structure |
| 925 | * |
| 926 | * free up any allocated data for a context |
| 927 | * This should not touch anything that would affect a simultaneous |
| 928 | * re-allocation of context data, because it is called after hfi1_mutex |
| 929 | * is released (and can be called from reinit as well). |
| 930 | * It should never change any chip state, or global driver state. |
| 931 | */ |
| 932 | void hfi1_free_ctxtdata(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd) |
| 933 | { |
| 934 | unsigned e; |
| 935 | |
| 936 | if (!rcd) |
| 937 | return; |
| 938 | |
| 939 | if (rcd->rcvhdrq) { |
| 940 | dma_free_coherent(&dd->pcidev->dev, rcd->rcvhdrq_size, |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 941 | rcd->rcvhdrq, rcd->rcvhdrq_dma); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 942 | rcd->rcvhdrq = NULL; |
| 943 | if (rcd->rcvhdrtail_kvaddr) { |
| 944 | dma_free_coherent(&dd->pcidev->dev, PAGE_SIZE, |
| 945 | (void *)rcd->rcvhdrtail_kvaddr, |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 946 | rcd->rcvhdrqtailaddr_dma); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 947 | rcd->rcvhdrtail_kvaddr = NULL; |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | /* all the RcvArray entries should have been cleared by now */ |
| 952 | kfree(rcd->egrbufs.rcvtids); |
| 953 | |
| 954 | for (e = 0; e < rcd->egrbufs.alloced; e++) { |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 955 | if (rcd->egrbufs.buffers[e].dma) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 956 | dma_free_coherent(&dd->pcidev->dev, |
| 957 | rcd->egrbufs.buffers[e].len, |
| 958 | rcd->egrbufs.buffers[e].addr, |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 959 | rcd->egrbufs.buffers[e].dma); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 960 | } |
| 961 | kfree(rcd->egrbufs.buffers); |
| 962 | |
| 963 | sc_free(rcd->sc); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 964 | vfree(rcd->user_event_mask); |
| 965 | vfree(rcd->subctxt_uregbase); |
| 966 | vfree(rcd->subctxt_rcvegrbuf); |
| 967 | vfree(rcd->subctxt_rcvhdr_base); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 968 | kfree(rcd->opstats); |
| 969 | kfree(rcd); |
| 970 | } |
| 971 | |
Dean Luick | 78eb129 | 2016-03-05 08:49:45 -0800 | [diff] [blame] | 972 | /* |
| 973 | * Release our hold on the shared asic data. If we are the last one, |
Dean Luick | dba715f | 2016-07-06 17:28:52 -0400 | [diff] [blame] | 974 | * return the structure to be finalized outside the lock. Must be |
| 975 | * holding hfi1_devs_lock. |
Dean Luick | 78eb129 | 2016-03-05 08:49:45 -0800 | [diff] [blame] | 976 | */ |
Dean Luick | dba715f | 2016-07-06 17:28:52 -0400 | [diff] [blame] | 977 | static struct hfi1_asic_data *release_asic_data(struct hfi1_devdata *dd) |
Dean Luick | 78eb129 | 2016-03-05 08:49:45 -0800 | [diff] [blame] | 978 | { |
Dean Luick | dba715f | 2016-07-06 17:28:52 -0400 | [diff] [blame] | 979 | struct hfi1_asic_data *ad; |
Dean Luick | 78eb129 | 2016-03-05 08:49:45 -0800 | [diff] [blame] | 980 | int other; |
| 981 | |
| 982 | if (!dd->asic_data) |
Dean Luick | dba715f | 2016-07-06 17:28:52 -0400 | [diff] [blame] | 983 | return NULL; |
Dean Luick | 78eb129 | 2016-03-05 08:49:45 -0800 | [diff] [blame] | 984 | dd->asic_data->dds[dd->hfi1_id] = NULL; |
| 985 | other = dd->hfi1_id ? 0 : 1; |
Dean Luick | dba715f | 2016-07-06 17:28:52 -0400 | [diff] [blame] | 986 | ad = dd->asic_data; |
Dean Luick | 78eb129 | 2016-03-05 08:49:45 -0800 | [diff] [blame] | 987 | dd->asic_data = NULL; |
Dean Luick | dba715f | 2016-07-06 17:28:52 -0400 | [diff] [blame] | 988 | /* return NULL if the other dd still has a link */ |
| 989 | return ad->dds[other] ? NULL : ad; |
| 990 | } |
| 991 | |
| 992 | static void finalize_asic_data(struct hfi1_devdata *dd, |
| 993 | struct hfi1_asic_data *ad) |
| 994 | { |
| 995 | clean_up_i2c(dd, ad); |
| 996 | kfree(ad); |
Dean Luick | 78eb129 | 2016-03-05 08:49:45 -0800 | [diff] [blame] | 997 | } |
| 998 | |
Dennis Dalessandro | e11ffbd | 2016-05-19 05:26:44 -0700 | [diff] [blame] | 999 | static void __hfi1_free_devdata(struct kobject *kobj) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1000 | { |
Dennis Dalessandro | e11ffbd | 2016-05-19 05:26:44 -0700 | [diff] [blame] | 1001 | struct hfi1_devdata *dd = |
| 1002 | container_of(kobj, struct hfi1_devdata, kobj); |
Dean Luick | dba715f | 2016-07-06 17:28:52 -0400 | [diff] [blame] | 1003 | struct hfi1_asic_data *ad; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1004 | unsigned long flags; |
| 1005 | |
| 1006 | spin_lock_irqsave(&hfi1_devs_lock, flags); |
| 1007 | idr_remove(&hfi1_unit_table, dd->unit); |
| 1008 | list_del(&dd->list); |
Dean Luick | dba715f | 2016-07-06 17:28:52 -0400 | [diff] [blame] | 1009 | ad = release_asic_data(dd); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1010 | spin_unlock_irqrestore(&hfi1_devs_lock, flags); |
Dean Luick | dba715f | 2016-07-06 17:28:52 -0400 | [diff] [blame] | 1011 | if (ad) |
| 1012 | finalize_asic_data(dd, ad); |
Easwar Hariharan | c3838b3 | 2016-02-09 14:29:13 -0800 | [diff] [blame] | 1013 | free_platform_config(dd); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1014 | rcu_barrier(); /* wait for rcu callbacks to complete */ |
| 1015 | free_percpu(dd->int_counter); |
| 1016 | free_percpu(dd->rcv_limit); |
Vennila Megavannan | 89abfc8 | 2016-02-03 14:34:07 -0800 | [diff] [blame] | 1017 | free_percpu(dd->send_schedule); |
Jubin John | ea0e4ce | 2016-04-20 06:05:24 -0700 | [diff] [blame] | 1018 | rvt_dealloc_device(&dd->verbs_dev.rdi); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1019 | } |
| 1020 | |
Dennis Dalessandro | e11ffbd | 2016-05-19 05:26:44 -0700 | [diff] [blame] | 1021 | static struct kobj_type hfi1_devdata_type = { |
| 1022 | .release = __hfi1_free_devdata, |
| 1023 | }; |
| 1024 | |
| 1025 | void hfi1_free_devdata(struct hfi1_devdata *dd) |
| 1026 | { |
| 1027 | kobject_put(&dd->kobj); |
| 1028 | } |
| 1029 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1030 | /* |
| 1031 | * Allocate our primary per-unit data structure. Must be done via verbs |
| 1032 | * allocator, because the verbs cleanup process both does cleanup and |
| 1033 | * free of the data structure. |
| 1034 | * "extra" is for chip-specific data. |
| 1035 | * |
| 1036 | * Use the idr mechanism to get a unit number for this unit. |
| 1037 | */ |
| 1038 | struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra) |
| 1039 | { |
| 1040 | unsigned long flags; |
| 1041 | struct hfi1_devdata *dd; |
Dennis Dalessandro | 7af6d00 | 2016-01-19 14:44:06 -0800 | [diff] [blame] | 1042 | int ret, nports; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1043 | |
Dennis Dalessandro | 7af6d00 | 2016-01-19 14:44:06 -0800 | [diff] [blame] | 1044 | /* extra is * number of ports */ |
| 1045 | nports = extra / sizeof(struct hfi1_pportdata); |
| 1046 | |
| 1047 | dd = (struct hfi1_devdata *)rvt_alloc_device(sizeof(*dd) + extra, |
| 1048 | nports); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1049 | if (!dd) |
| 1050 | return ERR_PTR(-ENOMEM); |
Dennis Dalessandro | 7af6d00 | 2016-01-19 14:44:06 -0800 | [diff] [blame] | 1051 | dd->num_pports = nports; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1052 | dd->pport = (struct hfi1_pportdata *)(dd + 1); |
| 1053 | |
| 1054 | INIT_LIST_HEAD(&dd->list); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1055 | idr_preload(GFP_KERNEL); |
| 1056 | spin_lock_irqsave(&hfi1_devs_lock, flags); |
| 1057 | |
| 1058 | ret = idr_alloc(&hfi1_unit_table, dd, 0, 0, GFP_NOWAIT); |
| 1059 | if (ret >= 0) { |
| 1060 | dd->unit = ret; |
| 1061 | list_add(&dd->list, &hfi1_dev_list); |
| 1062 | } |
| 1063 | |
| 1064 | spin_unlock_irqrestore(&hfi1_devs_lock, flags); |
| 1065 | idr_preload_end(); |
| 1066 | |
| 1067 | if (ret < 0) { |
| 1068 | hfi1_early_err(&pdev->dev, |
| 1069 | "Could not allocate unit ID: error %d\n", -ret); |
| 1070 | goto bail; |
| 1071 | } |
| 1072 | /* |
| 1073 | * Initialize all locks for the device. This needs to be as early as |
| 1074 | * possible so locks are usable. |
| 1075 | */ |
| 1076 | spin_lock_init(&dd->sc_lock); |
| 1077 | spin_lock_init(&dd->sendctrl_lock); |
| 1078 | spin_lock_init(&dd->rcvctrl_lock); |
| 1079 | spin_lock_init(&dd->uctxt_lock); |
| 1080 | spin_lock_init(&dd->hfi1_diag_trans_lock); |
| 1081 | spin_lock_init(&dd->sc_init_lock); |
| 1082 | spin_lock_init(&dd->dc8051_lock); |
| 1083 | spin_lock_init(&dd->dc8051_memlock); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1084 | seqlock_init(&dd->sc2vl_lock); |
| 1085 | spin_lock_init(&dd->sde_map_lock); |
Jubin John | 35f6bef | 2016-02-14 12:46:10 -0800 | [diff] [blame] | 1086 | spin_lock_init(&dd->pio_map_lock); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1087 | init_waitqueue_head(&dd->event_queue); |
| 1088 | |
| 1089 | dd->int_counter = alloc_percpu(u64); |
| 1090 | if (!dd->int_counter) { |
| 1091 | ret = -ENOMEM; |
| 1092 | hfi1_early_err(&pdev->dev, |
| 1093 | "Could not allocate per-cpu int_counter\n"); |
| 1094 | goto bail; |
| 1095 | } |
| 1096 | |
| 1097 | dd->rcv_limit = alloc_percpu(u64); |
| 1098 | if (!dd->rcv_limit) { |
| 1099 | ret = -ENOMEM; |
| 1100 | hfi1_early_err(&pdev->dev, |
| 1101 | "Could not allocate per-cpu rcv_limit\n"); |
| 1102 | goto bail; |
| 1103 | } |
| 1104 | |
Vennila Megavannan | 89abfc8 | 2016-02-03 14:34:07 -0800 | [diff] [blame] | 1105 | dd->send_schedule = alloc_percpu(u64); |
| 1106 | if (!dd->send_schedule) { |
| 1107 | ret = -ENOMEM; |
| 1108 | hfi1_early_err(&pdev->dev, |
| 1109 | "Could not allocate per-cpu int_counter\n"); |
| 1110 | goto bail; |
| 1111 | } |
| 1112 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1113 | if (!hfi1_cpulist_count) { |
| 1114 | u32 count = num_online_cpus(); |
| 1115 | |
Shraddha Barke | 314fcc0 | 2015-10-09 21:03:26 +0530 | [diff] [blame] | 1116 | hfi1_cpulist = kcalloc(BITS_TO_LONGS(count), sizeof(long), |
| 1117 | GFP_KERNEL); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1118 | if (hfi1_cpulist) |
| 1119 | hfi1_cpulist_count = count; |
| 1120 | else |
| 1121 | hfi1_early_err( |
| 1122 | &pdev->dev, |
| 1123 | "Could not alloc cpulist info, cpu affinity might be wrong\n"); |
| 1124 | } |
Dennis Dalessandro | e11ffbd | 2016-05-19 05:26:44 -0700 | [diff] [blame] | 1125 | kobject_init(&dd->kobj, &hfi1_devdata_type); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1126 | return dd; |
| 1127 | |
| 1128 | bail: |
| 1129 | if (!list_empty(&dd->list)) |
| 1130 | list_del_init(&dd->list); |
Jubin John | ea0e4ce | 2016-04-20 06:05:24 -0700 | [diff] [blame] | 1131 | rvt_dealloc_device(&dd->verbs_dev.rdi); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1132 | return ERR_PTR(ret); |
| 1133 | } |
| 1134 | |
| 1135 | /* |
| 1136 | * Called from freeze mode handlers, and from PCI error |
| 1137 | * reporting code. Should be paranoid about state of |
| 1138 | * system and data structures. |
| 1139 | */ |
| 1140 | void hfi1_disable_after_error(struct hfi1_devdata *dd) |
| 1141 | { |
| 1142 | if (dd->flags & HFI1_INITTED) { |
| 1143 | u32 pidx; |
| 1144 | |
| 1145 | dd->flags &= ~HFI1_INITTED; |
| 1146 | if (dd->pport) |
| 1147 | for (pidx = 0; pidx < dd->num_pports; ++pidx) { |
| 1148 | struct hfi1_pportdata *ppd; |
| 1149 | |
| 1150 | ppd = dd->pport + pidx; |
| 1151 | if (dd->flags & HFI1_PRESENT) |
| 1152 | set_link_state(ppd, HLS_DN_DISABLE); |
| 1153 | |
| 1154 | if (ppd->statusp) |
| 1155 | *ppd->statusp &= ~HFI1_STATUS_IB_READY; |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | /* |
| 1160 | * Mark as having had an error for driver, and also |
| 1161 | * for /sys and status word mapped to user programs. |
| 1162 | * This marks unit as not usable, until reset. |
| 1163 | */ |
| 1164 | if (dd->status) |
| 1165 | dd->status->dev |= HFI1_STATUS_HWERROR; |
| 1166 | } |
| 1167 | |
| 1168 | static void remove_one(struct pci_dev *); |
| 1169 | static int init_one(struct pci_dev *, const struct pci_device_id *); |
| 1170 | |
| 1171 | #define DRIVER_LOAD_MSG "Intel " DRIVER_NAME " loaded: " |
| 1172 | #define PFX DRIVER_NAME ": " |
| 1173 | |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 1174 | const struct pci_device_id hfi1_pci_tbl[] = { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1175 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL0) }, |
| 1176 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL1) }, |
| 1177 | { 0, } |
| 1178 | }; |
| 1179 | |
| 1180 | MODULE_DEVICE_TABLE(pci, hfi1_pci_tbl); |
| 1181 | |
| 1182 | static struct pci_driver hfi1_pci_driver = { |
| 1183 | .name = DRIVER_NAME, |
| 1184 | .probe = init_one, |
| 1185 | .remove = remove_one, |
| 1186 | .id_table = hfi1_pci_tbl, |
| 1187 | .err_handler = &hfi1_pci_err_handler, |
| 1188 | }; |
| 1189 | |
| 1190 | static void __init compute_krcvqs(void) |
| 1191 | { |
| 1192 | int i; |
| 1193 | |
| 1194 | for (i = 0; i < krcvqsset; i++) |
| 1195 | n_krcvqs += krcvqs[i]; |
| 1196 | } |
| 1197 | |
| 1198 | /* |
| 1199 | * Do all the generic driver unit- and chip-independent memory |
| 1200 | * allocation and initialization. |
| 1201 | */ |
| 1202 | static int __init hfi1_mod_init(void) |
| 1203 | { |
| 1204 | int ret; |
| 1205 | |
| 1206 | ret = dev_init(); |
| 1207 | if (ret) |
| 1208 | goto bail; |
| 1209 | |
Sebastian Sanchez | d637301 | 2016-07-25 07:54:48 -0700 | [diff] [blame] | 1210 | ret = node_affinity_init(); |
| 1211 | if (ret) |
| 1212 | goto bail; |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 1213 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1214 | /* validate max MTU before any devices start */ |
| 1215 | if (!valid_opa_max_mtu(hfi1_max_mtu)) { |
| 1216 | pr_err("Invalid max_mtu 0x%x, using 0x%x instead\n", |
| 1217 | hfi1_max_mtu, HFI1_DEFAULT_MAX_MTU); |
| 1218 | hfi1_max_mtu = HFI1_DEFAULT_MAX_MTU; |
| 1219 | } |
| 1220 | /* valid CUs run from 1-128 in powers of 2 */ |
| 1221 | if (hfi1_cu > 128 || !is_power_of_2(hfi1_cu)) |
| 1222 | hfi1_cu = 1; |
| 1223 | /* valid credit return threshold is 0-100, variable is unsigned */ |
| 1224 | if (user_credit_return_threshold > 100) |
| 1225 | user_credit_return_threshold = 100; |
| 1226 | |
| 1227 | compute_krcvqs(); |
Jubin John | 4d114fd | 2016-02-14 20:21:43 -0800 | [diff] [blame] | 1228 | /* |
| 1229 | * sanitize receive interrupt count, time must wait until after |
| 1230 | * the hardware type is known |
| 1231 | */ |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1232 | if (rcv_intr_count > RCV_HDR_HEAD_COUNTER_MASK) |
| 1233 | rcv_intr_count = RCV_HDR_HEAD_COUNTER_MASK; |
| 1234 | /* reject invalid combinations */ |
| 1235 | if (rcv_intr_count == 0 && rcv_intr_timeout == 0) { |
| 1236 | pr_err("Invalid mode: both receive interrupt count and available timeout are zero - setting interrupt count to 1\n"); |
| 1237 | rcv_intr_count = 1; |
| 1238 | } |
| 1239 | if (rcv_intr_count > 1 && rcv_intr_timeout == 0) { |
| 1240 | /* |
| 1241 | * Avoid indefinite packet delivery by requiring a timeout |
| 1242 | * if count is > 1. |
| 1243 | */ |
| 1244 | pr_err("Invalid mode: receive interrupt count greater than 1 and available timeout is zero - setting available timeout to 1\n"); |
| 1245 | rcv_intr_timeout = 1; |
| 1246 | } |
| 1247 | if (rcv_intr_dynamic && !(rcv_intr_count > 1 && rcv_intr_timeout > 0)) { |
| 1248 | /* |
| 1249 | * The dynamic algorithm expects a non-zero timeout |
| 1250 | * and a count > 1. |
| 1251 | */ |
| 1252 | pr_err("Invalid mode: dynamic receive interrupt mitigation with invalid count and timeout - turning dynamic off\n"); |
| 1253 | rcv_intr_dynamic = 0; |
| 1254 | } |
| 1255 | |
| 1256 | /* sanitize link CRC options */ |
| 1257 | link_crc_mask &= SUPPORTED_CRCS; |
| 1258 | |
| 1259 | /* |
| 1260 | * These must be called before the driver is registered with |
| 1261 | * the PCI subsystem. |
| 1262 | */ |
| 1263 | idr_init(&hfi1_unit_table); |
| 1264 | |
| 1265 | hfi1_dbg_init(); |
Dean Luick | 528ee9f | 2016-03-05 08:50:43 -0800 | [diff] [blame] | 1266 | ret = hfi1_wss_init(); |
| 1267 | if (ret < 0) |
| 1268 | goto bail_wss; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1269 | ret = pci_register_driver(&hfi1_pci_driver); |
| 1270 | if (ret < 0) { |
| 1271 | pr_err("Unable to register driver: error %d\n", -ret); |
| 1272 | goto bail_dev; |
| 1273 | } |
| 1274 | goto bail; /* all OK */ |
| 1275 | |
| 1276 | bail_dev: |
Dean Luick | 528ee9f | 2016-03-05 08:50:43 -0800 | [diff] [blame] | 1277 | hfi1_wss_exit(); |
| 1278 | bail_wss: |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1279 | hfi1_dbg_exit(); |
| 1280 | idr_destroy(&hfi1_unit_table); |
| 1281 | dev_cleanup(); |
| 1282 | bail: |
| 1283 | return ret; |
| 1284 | } |
| 1285 | |
| 1286 | module_init(hfi1_mod_init); |
| 1287 | |
| 1288 | /* |
| 1289 | * Do the non-unit driver cleanup, memory free, etc. at unload. |
| 1290 | */ |
| 1291 | static void __exit hfi1_mod_cleanup(void) |
| 1292 | { |
| 1293 | pci_unregister_driver(&hfi1_pci_driver); |
Dennis Dalessandro | 4197344 | 2016-07-25 07:52:36 -0700 | [diff] [blame] | 1294 | node_affinity_destroy(); |
Dean Luick | 528ee9f | 2016-03-05 08:50:43 -0800 | [diff] [blame] | 1295 | hfi1_wss_exit(); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1296 | hfi1_dbg_exit(); |
| 1297 | hfi1_cpulist_count = 0; |
| 1298 | kfree(hfi1_cpulist); |
| 1299 | |
| 1300 | idr_destroy(&hfi1_unit_table); |
| 1301 | dispose_firmware(); /* asymmetric with obtain_firmware() */ |
| 1302 | dev_cleanup(); |
| 1303 | } |
| 1304 | |
| 1305 | module_exit(hfi1_mod_cleanup); |
| 1306 | |
| 1307 | /* this can only be called after a successful initialization */ |
| 1308 | static void cleanup_device_data(struct hfi1_devdata *dd) |
| 1309 | { |
| 1310 | int ctxt; |
| 1311 | int pidx; |
| 1312 | struct hfi1_ctxtdata **tmp; |
| 1313 | unsigned long flags; |
| 1314 | |
| 1315 | /* users can't do anything more with chip */ |
| 1316 | for (pidx = 0; pidx < dd->num_pports; ++pidx) { |
| 1317 | struct hfi1_pportdata *ppd = &dd->pport[pidx]; |
| 1318 | struct cc_state *cc_state; |
| 1319 | int i; |
| 1320 | |
| 1321 | if (ppd->statusp) |
| 1322 | *ppd->statusp &= ~HFI1_STATUS_CHIP_PRESENT; |
| 1323 | |
| 1324 | for (i = 0; i < OPA_MAX_SLS; i++) |
| 1325 | hrtimer_cancel(&ppd->cca_timer[i].hrtimer); |
| 1326 | |
| 1327 | spin_lock(&ppd->cc_state_lock); |
Jianxin Xiong | 8adf71f | 2016-07-25 13:39:14 -0700 | [diff] [blame] | 1328 | cc_state = get_cc_state_protected(ppd); |
Muhammad Falak R Wani | eea5707 | 2016-05-01 18:05:31 +0530 | [diff] [blame] | 1329 | RCU_INIT_POINTER(ppd->cc_state, NULL); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1330 | spin_unlock(&ppd->cc_state_lock); |
| 1331 | |
| 1332 | if (cc_state) |
Wei Yongjun | 476d95b | 2016-08-10 03:14:04 +0000 | [diff] [blame] | 1333 | kfree_rcu(cc_state, rcu); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | free_credit_return(dd); |
| 1337 | |
| 1338 | /* |
| 1339 | * Free any resources still in use (usually just kernel contexts) |
| 1340 | * at unload; we do for ctxtcnt, because that's what we allocate. |
| 1341 | * We acquire lock to be really paranoid that rcd isn't being |
| 1342 | * accessed from some interrupt-related code (that should not happen, |
| 1343 | * but best to be sure). |
| 1344 | */ |
| 1345 | spin_lock_irqsave(&dd->uctxt_lock, flags); |
| 1346 | tmp = dd->rcd; |
| 1347 | dd->rcd = NULL; |
| 1348 | spin_unlock_irqrestore(&dd->uctxt_lock, flags); |
Mark F. Brown | 46b010d | 2015-11-09 19:18:20 -0500 | [diff] [blame] | 1349 | |
| 1350 | if (dd->rcvhdrtail_dummy_kvaddr) { |
| 1351 | dma_free_coherent(&dd->pcidev->dev, sizeof(u64), |
| 1352 | (void *)dd->rcvhdrtail_dummy_kvaddr, |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 1353 | dd->rcvhdrtail_dummy_dma); |
Dan Carpenter | a8b7da5 | 2016-05-28 08:01:20 +0300 | [diff] [blame] | 1354 | dd->rcvhdrtail_dummy_kvaddr = NULL; |
Mark F. Brown | 46b010d | 2015-11-09 19:18:20 -0500 | [diff] [blame] | 1355 | } |
| 1356 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1357 | for (ctxt = 0; tmp && ctxt < dd->num_rcv_contexts; ctxt++) { |
| 1358 | struct hfi1_ctxtdata *rcd = tmp[ctxt]; |
| 1359 | |
| 1360 | tmp[ctxt] = NULL; /* debugging paranoia */ |
| 1361 | if (rcd) { |
| 1362 | hfi1_clear_tids(rcd); |
| 1363 | hfi1_free_ctxtdata(dd, rcd); |
| 1364 | } |
| 1365 | } |
| 1366 | kfree(tmp); |
Jubin John | 35f6bef | 2016-02-14 12:46:10 -0800 | [diff] [blame] | 1367 | free_pio_map(dd); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1368 | /* must follow rcv context free - need to remove rcv's hooks */ |
| 1369 | for (ctxt = 0; ctxt < dd->num_send_contexts; ctxt++) |
| 1370 | sc_free(dd->send_contexts[ctxt].sc); |
| 1371 | dd->num_send_contexts = 0; |
| 1372 | kfree(dd->send_contexts); |
| 1373 | dd->send_contexts = NULL; |
Jubin John | 79d0c08 | 2016-02-26 13:33:33 -0800 | [diff] [blame] | 1374 | kfree(dd->hw_to_sw); |
| 1375 | dd->hw_to_sw = NULL; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1376 | kfree(dd->boardname); |
| 1377 | vfree(dd->events); |
| 1378 | vfree(dd->status); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | /* |
| 1382 | * Clean up on unit shutdown, or error during unit load after |
| 1383 | * successful initialization. |
| 1384 | */ |
| 1385 | static void postinit_cleanup(struct hfi1_devdata *dd) |
| 1386 | { |
| 1387 | hfi1_start_cleanup(dd); |
| 1388 | |
| 1389 | hfi1_pcie_ddcleanup(dd); |
| 1390 | hfi1_pcie_cleanup(dd->pcidev); |
| 1391 | |
| 1392 | cleanup_device_data(dd); |
| 1393 | |
| 1394 | hfi1_free_devdata(dd); |
| 1395 | } |
| 1396 | |
Krzysztof Blaszkowski | 11501ab | 2016-10-25 13:12:11 -0700 | [diff] [blame] | 1397 | static int init_validate_rcvhdrcnt(struct device *dev, uint thecnt) |
| 1398 | { |
| 1399 | if (thecnt <= HFI1_MIN_HDRQ_EGRBUF_CNT) { |
| 1400 | hfi1_early_err(dev, "Receive header queue count too small\n"); |
| 1401 | return -EINVAL; |
| 1402 | } |
| 1403 | |
| 1404 | if (thecnt > HFI1_MAX_HDRQ_EGRBUF_CNT) { |
| 1405 | hfi1_early_err(dev, |
| 1406 | "Receive header queue count cannot be greater than %u\n", |
| 1407 | HFI1_MAX_HDRQ_EGRBUF_CNT); |
| 1408 | return -EINVAL; |
| 1409 | } |
| 1410 | |
| 1411 | if (thecnt % HDRQ_INCREMENT) { |
| 1412 | hfi1_early_err(dev, "Receive header queue count %d must be divisible by %lu\n", |
| 1413 | thecnt, HDRQ_INCREMENT); |
| 1414 | return -EINVAL; |
| 1415 | } |
| 1416 | |
| 1417 | return 0; |
| 1418 | } |
| 1419 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1420 | static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 1421 | { |
| 1422 | int ret = 0, j, pidx, initfail; |
Krzysztof Blaszkowski | 83fb4af | 2016-10-17 04:19:24 -0700 | [diff] [blame] | 1423 | struct hfi1_devdata *dd; |
Harish Chegondi | e8597eb | 2015-12-01 15:38:20 -0500 | [diff] [blame] | 1424 | struct hfi1_pportdata *ppd; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1425 | |
| 1426 | /* First, lock the non-writable module parameters */ |
| 1427 | HFI1_CAP_LOCK(); |
| 1428 | |
Tadeusz Struk | 5d6f08a | 2017-03-20 17:25:29 -0700 | [diff] [blame] | 1429 | /* Validate dev ids */ |
| 1430 | if (!(ent->device == PCI_DEVICE_ID_INTEL0 || |
| 1431 | ent->device == PCI_DEVICE_ID_INTEL1)) { |
| 1432 | hfi1_early_err(&pdev->dev, |
| 1433 | "Failing on unknown Intel deviceid 0x%x\n", |
| 1434 | ent->device); |
| 1435 | ret = -ENODEV; |
| 1436 | goto bail; |
| 1437 | } |
| 1438 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1439 | /* Validate some global module parameters */ |
Krzysztof Blaszkowski | 11501ab | 2016-10-25 13:12:11 -0700 | [diff] [blame] | 1440 | ret = init_validate_rcvhdrcnt(&pdev->dev, rcvhdrcnt); |
| 1441 | if (ret) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1442 | goto bail; |
Krzysztof Blaszkowski | 11501ab | 2016-10-25 13:12:11 -0700 | [diff] [blame] | 1443 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1444 | /* use the encoding function as a sanitization check */ |
| 1445 | if (!encode_rcv_header_entry_size(hfi1_hdrq_entsize)) { |
| 1446 | hfi1_early_err(&pdev->dev, "Invalid HdrQ Entry size %u\n", |
| 1447 | hfi1_hdrq_entsize); |
Sebastian Sanchez | 07859de | 2015-12-10 16:02:49 -0500 | [diff] [blame] | 1448 | ret = -EINVAL; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1449 | goto bail; |
| 1450 | } |
| 1451 | |
| 1452 | /* The receive eager buffer size must be set before the receive |
| 1453 | * contexts are created. |
| 1454 | * |
| 1455 | * Set the eager buffer size. Validate that it falls in a range |
| 1456 | * allowed by the hardware - all powers of 2 between the min and |
| 1457 | * max. The maximum valid MTU is within the eager buffer range |
| 1458 | * so we do not need to cap the max_mtu by an eager buffer size |
| 1459 | * setting. |
| 1460 | */ |
| 1461 | if (eager_buffer_size) { |
| 1462 | if (!is_power_of_2(eager_buffer_size)) |
| 1463 | eager_buffer_size = |
| 1464 | roundup_pow_of_two(eager_buffer_size); |
| 1465 | eager_buffer_size = |
| 1466 | clamp_val(eager_buffer_size, |
| 1467 | MIN_EAGER_BUFFER * 8, |
| 1468 | MAX_EAGER_BUFFER_TOTAL); |
| 1469 | hfi1_early_info(&pdev->dev, "Eager buffer size %u\n", |
| 1470 | eager_buffer_size); |
| 1471 | } else { |
| 1472 | hfi1_early_err(&pdev->dev, "Invalid Eager buffer size of 0\n"); |
| 1473 | ret = -EINVAL; |
| 1474 | goto bail; |
| 1475 | } |
| 1476 | |
| 1477 | /* restrict value of hfi1_rcvarr_split */ |
| 1478 | hfi1_rcvarr_split = clamp_val(hfi1_rcvarr_split, 0, 100); |
| 1479 | |
| 1480 | ret = hfi1_pcie_init(pdev, ent); |
| 1481 | if (ret) |
| 1482 | goto bail; |
| 1483 | |
Krzysztof Blaszkowski | 83fb4af | 2016-10-17 04:19:24 -0700 | [diff] [blame] | 1484 | /* |
| 1485 | * Do device-specific initialization, function table setup, dd |
| 1486 | * allocation, etc. |
| 1487 | */ |
| 1488 | dd = hfi1_init_dd(pdev, ent); |
| 1489 | |
| 1490 | if (IS_ERR(dd)) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1491 | ret = PTR_ERR(dd); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1492 | goto clean_bail; /* error already printed */ |
Krzysztof Blaszkowski | 83fb4af | 2016-10-17 04:19:24 -0700 | [diff] [blame] | 1493 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1494 | |
| 1495 | ret = create_workqueues(dd); |
| 1496 | if (ret) |
| 1497 | goto clean_bail; |
| 1498 | |
| 1499 | /* do the generic initialization */ |
| 1500 | initfail = hfi1_init(dd, 0); |
| 1501 | |
Vishwanathapura, Niranjana | d4829ea | 2017-04-12 20:29:28 -0700 | [diff] [blame^] | 1502 | /* setup vnic */ |
| 1503 | hfi1_vnic_setup(dd); |
| 1504 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1505 | ret = hfi1_register_ib_device(dd); |
| 1506 | |
| 1507 | /* |
| 1508 | * Now ready for use. this should be cleared whenever we |
| 1509 | * detect a reset, or initiate one. If earlier failure, |
| 1510 | * we still create devices, so diags, etc. can be used |
| 1511 | * to determine cause of problem. |
| 1512 | */ |
Dean Luick | ed6f653 | 2016-02-18 11:12:25 -0800 | [diff] [blame] | 1513 | if (!initfail && !ret) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1514 | dd->flags |= HFI1_INITTED; |
Dean Luick | ed6f653 | 2016-02-18 11:12:25 -0800 | [diff] [blame] | 1515 | /* create debufs files after init and ib register */ |
| 1516 | hfi1_dbg_ibdev_init(&dd->verbs_dev); |
| 1517 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1518 | |
| 1519 | j = hfi1_device_create(dd); |
| 1520 | if (j) |
| 1521 | dd_dev_err(dd, "Failed to create /dev devices: %d\n", -j); |
| 1522 | |
| 1523 | if (initfail || ret) { |
| 1524 | stop_timers(dd); |
| 1525 | flush_workqueue(ib_wq); |
Harish Chegondi | e8597eb | 2015-12-01 15:38:20 -0500 | [diff] [blame] | 1526 | for (pidx = 0; pidx < dd->num_pports; ++pidx) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1527 | hfi1_quiet_serdes(dd->pport + pidx); |
Harish Chegondi | e8597eb | 2015-12-01 15:38:20 -0500 | [diff] [blame] | 1528 | ppd = dd->pport + pidx; |
| 1529 | if (ppd->hfi1_wq) { |
| 1530 | destroy_workqueue(ppd->hfi1_wq); |
| 1531 | ppd->hfi1_wq = NULL; |
| 1532 | } |
| 1533 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1534 | if (!j) |
| 1535 | hfi1_device_remove(dd); |
| 1536 | if (!ret) |
| 1537 | hfi1_unregister_ib_device(dd); |
| 1538 | postinit_cleanup(dd); |
| 1539 | if (initfail) |
| 1540 | ret = initfail; |
| 1541 | goto bail; /* everything already cleaned */ |
| 1542 | } |
| 1543 | |
| 1544 | sdma_start(dd); |
| 1545 | |
| 1546 | return 0; |
| 1547 | |
| 1548 | clean_bail: |
| 1549 | hfi1_pcie_cleanup(pdev); |
| 1550 | bail: |
| 1551 | return ret; |
| 1552 | } |
| 1553 | |
Tadeusz Struk | acd7c8f | 2016-10-25 08:57:55 -0700 | [diff] [blame] | 1554 | static void wait_for_clients(struct hfi1_devdata *dd) |
| 1555 | { |
| 1556 | /* |
| 1557 | * Remove the device init value and complete the device if there is |
| 1558 | * no clients or wait for active clients to finish. |
| 1559 | */ |
| 1560 | if (atomic_dec_and_test(&dd->user_refcount)) |
| 1561 | complete(&dd->user_comp); |
| 1562 | |
| 1563 | wait_for_completion(&dd->user_comp); |
| 1564 | } |
| 1565 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1566 | static void remove_one(struct pci_dev *pdev) |
| 1567 | { |
| 1568 | struct hfi1_devdata *dd = pci_get_drvdata(pdev); |
| 1569 | |
Dean Luick | ed6f653 | 2016-02-18 11:12:25 -0800 | [diff] [blame] | 1570 | /* close debugfs files before ib unregister */ |
| 1571 | hfi1_dbg_ibdev_exit(&dd->verbs_dev); |
Tadeusz Struk | acd7c8f | 2016-10-25 08:57:55 -0700 | [diff] [blame] | 1572 | |
| 1573 | /* remove the /dev hfi1 interface */ |
| 1574 | hfi1_device_remove(dd); |
| 1575 | |
| 1576 | /* wait for existing user space clients to finish */ |
| 1577 | wait_for_clients(dd); |
| 1578 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1579 | /* unregister from IB core */ |
| 1580 | hfi1_unregister_ib_device(dd); |
| 1581 | |
Vishwanathapura, Niranjana | d4829ea | 2017-04-12 20:29:28 -0700 | [diff] [blame^] | 1582 | /* cleanup vnic */ |
| 1583 | hfi1_vnic_cleanup(dd); |
| 1584 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1585 | /* |
| 1586 | * Disable the IB link, disable interrupts on the device, |
| 1587 | * clear dma engines, etc. |
| 1588 | */ |
| 1589 | shutdown_device(dd); |
| 1590 | |
| 1591 | stop_timers(dd); |
| 1592 | |
| 1593 | /* wait until all of our (qsfp) queue_work() calls complete */ |
| 1594 | flush_workqueue(ib_wq); |
| 1595 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1596 | postinit_cleanup(dd); |
| 1597 | } |
| 1598 | |
| 1599 | /** |
| 1600 | * hfi1_create_rcvhdrq - create a receive header queue |
| 1601 | * @dd: the hfi1_ib device |
| 1602 | * @rcd: the context data |
| 1603 | * |
| 1604 | * This must be contiguous memory (from an i/o perspective), and must be |
| 1605 | * DMA'able (which means for some systems, it will go through an IOMMU, |
| 1606 | * or be forced into a low address range). |
| 1607 | */ |
| 1608 | int hfi1_create_rcvhdrq(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd) |
| 1609 | { |
| 1610 | unsigned amt; |
| 1611 | u64 reg; |
| 1612 | |
| 1613 | if (!rcd->rcvhdrq) { |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 1614 | dma_addr_t dma_hdrqtail; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1615 | gfp_t gfp_flags; |
| 1616 | |
| 1617 | /* |
| 1618 | * rcvhdrqentsize is in DWs, so we have to convert to bytes |
| 1619 | * (* sizeof(u32)). |
| 1620 | */ |
Amitoj Kaur Chawla | 8444991 | 2016-03-04 22:30:43 +0530 | [diff] [blame] | 1621 | amt = PAGE_ALIGN(rcd->rcvhdrq_cnt * rcd->rcvhdrqentsize * |
| 1622 | sizeof(u32)); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1623 | |
| 1624 | gfp_flags = (rcd->ctxt >= dd->first_user_ctxt) ? |
| 1625 | GFP_USER : GFP_KERNEL; |
| 1626 | rcd->rcvhdrq = dma_zalloc_coherent( |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 1627 | &dd->pcidev->dev, amt, &rcd->rcvhdrq_dma, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1628 | gfp_flags | __GFP_COMP); |
| 1629 | |
| 1630 | if (!rcd->rcvhdrq) { |
| 1631 | dd_dev_err(dd, |
Jubin John | 17fb4f2 | 2016-02-14 20:21:52 -0800 | [diff] [blame] | 1632 | "attempt to allocate %d bytes for ctxt %u rcvhdrq failed\n", |
| 1633 | amt, rcd->ctxt); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1634 | goto bail; |
| 1635 | } |
| 1636 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1637 | if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) { |
| 1638 | rcd->rcvhdrtail_kvaddr = dma_zalloc_coherent( |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 1639 | &dd->pcidev->dev, PAGE_SIZE, &dma_hdrqtail, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1640 | gfp_flags); |
| 1641 | if (!rcd->rcvhdrtail_kvaddr) |
| 1642 | goto bail_free; |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 1643 | rcd->rcvhdrqtailaddr_dma = dma_hdrqtail; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | rcd->rcvhdrq_size = amt; |
| 1647 | } |
| 1648 | /* |
| 1649 | * These values are per-context: |
| 1650 | * RcvHdrCnt |
| 1651 | * RcvHdrEntSize |
| 1652 | * RcvHdrSize |
| 1653 | */ |
| 1654 | reg = ((u64)(rcd->rcvhdrq_cnt >> HDRQ_SIZE_SHIFT) |
| 1655 | & RCV_HDR_CNT_CNT_MASK) |
| 1656 | << RCV_HDR_CNT_CNT_SHIFT; |
| 1657 | write_kctxt_csr(dd, rcd->ctxt, RCV_HDR_CNT, reg); |
| 1658 | reg = (encode_rcv_header_entry_size(rcd->rcvhdrqentsize) |
| 1659 | & RCV_HDR_ENT_SIZE_ENT_SIZE_MASK) |
| 1660 | << RCV_HDR_ENT_SIZE_ENT_SIZE_SHIFT; |
| 1661 | write_kctxt_csr(dd, rcd->ctxt, RCV_HDR_ENT_SIZE, reg); |
| 1662 | reg = (dd->rcvhdrsize & RCV_HDR_SIZE_HDR_SIZE_MASK) |
| 1663 | << RCV_HDR_SIZE_HDR_SIZE_SHIFT; |
| 1664 | write_kctxt_csr(dd, rcd->ctxt, RCV_HDR_SIZE, reg); |
Mark F. Brown | 46b010d | 2015-11-09 19:18:20 -0500 | [diff] [blame] | 1665 | |
| 1666 | /* |
| 1667 | * Program dummy tail address for every receive context |
| 1668 | * before enabling any receive context |
| 1669 | */ |
| 1670 | write_kctxt_csr(dd, rcd->ctxt, RCV_HDR_TAIL_ADDR, |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 1671 | dd->rcvhdrtail_dummy_dma); |
Mark F. Brown | 46b010d | 2015-11-09 19:18:20 -0500 | [diff] [blame] | 1672 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1673 | return 0; |
| 1674 | |
| 1675 | bail_free: |
| 1676 | dd_dev_err(dd, |
Jubin John | 17fb4f2 | 2016-02-14 20:21:52 -0800 | [diff] [blame] | 1677 | "attempt to allocate 1 page for ctxt %u rcvhdrqtailaddr failed\n", |
| 1678 | rcd->ctxt); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1679 | vfree(rcd->user_event_mask); |
| 1680 | rcd->user_event_mask = NULL; |
| 1681 | dma_free_coherent(&dd->pcidev->dev, amt, rcd->rcvhdrq, |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 1682 | rcd->rcvhdrq_dma); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1683 | rcd->rcvhdrq = NULL; |
| 1684 | bail: |
| 1685 | return -ENOMEM; |
| 1686 | } |
| 1687 | |
| 1688 | /** |
| 1689 | * allocate eager buffers, both kernel and user contexts. |
| 1690 | * @rcd: the context we are setting up. |
| 1691 | * |
| 1692 | * Allocate the eager TID buffers and program them into hip. |
| 1693 | * They are no longer completely contiguous, we do multiple allocation |
| 1694 | * calls. Otherwise we get the OOM code involved, by asking for too |
| 1695 | * much per call, with disastrous results on some kernels. |
| 1696 | */ |
| 1697 | int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd) |
| 1698 | { |
| 1699 | struct hfi1_devdata *dd = rcd->dd; |
| 1700 | u32 max_entries, egrtop, alloced_bytes = 0, idx = 0; |
| 1701 | gfp_t gfp_flags; |
| 1702 | u16 order; |
| 1703 | int ret = 0; |
| 1704 | u16 round_mtu = roundup_pow_of_two(hfi1_max_mtu); |
| 1705 | |
| 1706 | /* |
| 1707 | * GFP_USER, but without GFP_FS, so buffer cache can be |
| 1708 | * coalesced (we hope); otherwise, even at order 4, |
| 1709 | * heavy filesystem activity makes these fail, and we can |
| 1710 | * use compound pages. |
| 1711 | */ |
Mel Gorman | 71baba4 | 2015-11-06 16:28:28 -0800 | [diff] [blame] | 1712 | gfp_flags = __GFP_RECLAIM | __GFP_IO | __GFP_COMP; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1713 | |
| 1714 | /* |
| 1715 | * The minimum size of the eager buffers is a groups of MTU-sized |
| 1716 | * buffers. |
| 1717 | * The global eager_buffer_size parameter is checked against the |
| 1718 | * theoretical lower limit of the value. Here, we check against the |
| 1719 | * MTU. |
| 1720 | */ |
| 1721 | if (rcd->egrbufs.size < (round_mtu * dd->rcv_entries.group_size)) |
| 1722 | rcd->egrbufs.size = round_mtu * dd->rcv_entries.group_size; |
| 1723 | /* |
| 1724 | * If using one-pkt-per-egr-buffer, lower the eager buffer |
| 1725 | * size to the max MTU (page-aligned). |
| 1726 | */ |
| 1727 | if (!HFI1_CAP_KGET_MASK(rcd->flags, MULTI_PKT_EGR)) |
| 1728 | rcd->egrbufs.rcvtid_size = round_mtu; |
| 1729 | |
| 1730 | /* |
| 1731 | * Eager buffers sizes of 1MB or less require smaller TID sizes |
| 1732 | * to satisfy the "multiple of 8 RcvArray entries" requirement. |
| 1733 | */ |
| 1734 | if (rcd->egrbufs.size <= (1 << 20)) |
| 1735 | rcd->egrbufs.rcvtid_size = max((unsigned long)round_mtu, |
| 1736 | rounddown_pow_of_two(rcd->egrbufs.size / 8)); |
| 1737 | |
| 1738 | while (alloced_bytes < rcd->egrbufs.size && |
| 1739 | rcd->egrbufs.alloced < rcd->egrbufs.count) { |
| 1740 | rcd->egrbufs.buffers[idx].addr = |
| 1741 | dma_zalloc_coherent(&dd->pcidev->dev, |
| 1742 | rcd->egrbufs.rcvtid_size, |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 1743 | &rcd->egrbufs.buffers[idx].dma, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1744 | gfp_flags); |
| 1745 | if (rcd->egrbufs.buffers[idx].addr) { |
| 1746 | rcd->egrbufs.buffers[idx].len = |
| 1747 | rcd->egrbufs.rcvtid_size; |
| 1748 | rcd->egrbufs.rcvtids[rcd->egrbufs.alloced].addr = |
| 1749 | rcd->egrbufs.buffers[idx].addr; |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 1750 | rcd->egrbufs.rcvtids[rcd->egrbufs.alloced].dma = |
| 1751 | rcd->egrbufs.buffers[idx].dma; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1752 | rcd->egrbufs.alloced++; |
| 1753 | alloced_bytes += rcd->egrbufs.rcvtid_size; |
| 1754 | idx++; |
| 1755 | } else { |
| 1756 | u32 new_size, i, j; |
| 1757 | u64 offset = 0; |
| 1758 | |
| 1759 | /* |
| 1760 | * Fail the eager buffer allocation if: |
| 1761 | * - we are already using the lowest acceptable size |
| 1762 | * - we are using one-pkt-per-egr-buffer (this implies |
| 1763 | * that we are accepting only one size) |
| 1764 | */ |
| 1765 | if (rcd->egrbufs.rcvtid_size == round_mtu || |
| 1766 | !HFI1_CAP_KGET_MASK(rcd->flags, MULTI_PKT_EGR)) { |
| 1767 | dd_dev_err(dd, "ctxt%u: Failed to allocate eager buffers\n", |
Jubin John | 17fb4f2 | 2016-02-14 20:21:52 -0800 | [diff] [blame] | 1768 | rcd->ctxt); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1769 | goto bail_rcvegrbuf_phys; |
| 1770 | } |
| 1771 | |
| 1772 | new_size = rcd->egrbufs.rcvtid_size / 2; |
| 1773 | |
| 1774 | /* |
| 1775 | * If the first attempt to allocate memory failed, don't |
| 1776 | * fail everything but continue with the next lower |
| 1777 | * size. |
| 1778 | */ |
| 1779 | if (idx == 0) { |
| 1780 | rcd->egrbufs.rcvtid_size = new_size; |
| 1781 | continue; |
| 1782 | } |
| 1783 | |
| 1784 | /* |
| 1785 | * Re-partition already allocated buffers to a smaller |
| 1786 | * size. |
| 1787 | */ |
| 1788 | rcd->egrbufs.alloced = 0; |
| 1789 | for (i = 0, j = 0, offset = 0; j < idx; i++) { |
| 1790 | if (i >= rcd->egrbufs.count) |
| 1791 | break; |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 1792 | rcd->egrbufs.rcvtids[i].dma = |
| 1793 | rcd->egrbufs.buffers[j].dma + offset; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1794 | rcd->egrbufs.rcvtids[i].addr = |
| 1795 | rcd->egrbufs.buffers[j].addr + offset; |
| 1796 | rcd->egrbufs.alloced++; |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 1797 | if ((rcd->egrbufs.buffers[j].dma + offset + |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1798 | new_size) == |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 1799 | (rcd->egrbufs.buffers[j].dma + |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1800 | rcd->egrbufs.buffers[j].len)) { |
| 1801 | j++; |
| 1802 | offset = 0; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 1803 | } else { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1804 | offset += new_size; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 1805 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1806 | } |
| 1807 | rcd->egrbufs.rcvtid_size = new_size; |
| 1808 | } |
| 1809 | } |
| 1810 | rcd->egrbufs.numbufs = idx; |
| 1811 | rcd->egrbufs.size = alloced_bytes; |
| 1812 | |
Sebastian Sanchez | 6c63e42 | 2015-11-06 20:06:56 -0500 | [diff] [blame] | 1813 | hfi1_cdbg(PROC, |
| 1814 | "ctxt%u: Alloced %u rcv tid entries @ %uKB, total %zuKB\n", |
Grzegorz Heldt | 23002d5 | 2016-07-25 13:39:33 -0700 | [diff] [blame] | 1815 | rcd->ctxt, rcd->egrbufs.alloced, |
| 1816 | rcd->egrbufs.rcvtid_size / 1024, rcd->egrbufs.size / 1024); |
Sebastian Sanchez | 6c63e42 | 2015-11-06 20:06:56 -0500 | [diff] [blame] | 1817 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1818 | /* |
| 1819 | * Set the contexts rcv array head update threshold to the closest |
| 1820 | * power of 2 (so we can use a mask instead of modulo) below half |
| 1821 | * the allocated entries. |
| 1822 | */ |
| 1823 | rcd->egrbufs.threshold = |
| 1824 | rounddown_pow_of_two(rcd->egrbufs.alloced / 2); |
| 1825 | /* |
| 1826 | * Compute the expected RcvArray entry base. This is done after |
| 1827 | * allocating the eager buffers in order to maximize the |
| 1828 | * expected RcvArray entries for the context. |
| 1829 | */ |
| 1830 | max_entries = rcd->rcv_array_groups * dd->rcv_entries.group_size; |
| 1831 | egrtop = roundup(rcd->egrbufs.alloced, dd->rcv_entries.group_size); |
| 1832 | rcd->expected_count = max_entries - egrtop; |
| 1833 | if (rcd->expected_count > MAX_TID_PAIR_ENTRIES * 2) |
| 1834 | rcd->expected_count = MAX_TID_PAIR_ENTRIES * 2; |
| 1835 | |
| 1836 | rcd->expected_base = rcd->eager_base + egrtop; |
Sebastian Sanchez | 6c63e42 | 2015-11-06 20:06:56 -0500 | [diff] [blame] | 1837 | hfi1_cdbg(PROC, "ctxt%u: eager:%u, exp:%u, egrbase:%u, expbase:%u\n", |
| 1838 | rcd->ctxt, rcd->egrbufs.alloced, rcd->expected_count, |
| 1839 | rcd->eager_base, rcd->expected_base); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1840 | |
| 1841 | if (!hfi1_rcvbuf_validate(rcd->egrbufs.rcvtid_size, PT_EAGER, &order)) { |
Sebastian Sanchez | 6c63e42 | 2015-11-06 20:06:56 -0500 | [diff] [blame] | 1842 | hfi1_cdbg(PROC, |
| 1843 | "ctxt%u: current Eager buffer size is invalid %u\n", |
| 1844 | rcd->ctxt, rcd->egrbufs.rcvtid_size); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1845 | ret = -EINVAL; |
| 1846 | goto bail; |
| 1847 | } |
| 1848 | |
| 1849 | for (idx = 0; idx < rcd->egrbufs.alloced; idx++) { |
| 1850 | hfi1_put_tid(dd, rcd->eager_base + idx, PT_EAGER, |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 1851 | rcd->egrbufs.rcvtids[idx].dma, order); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1852 | cond_resched(); |
| 1853 | } |
| 1854 | goto bail; |
| 1855 | |
| 1856 | bail_rcvegrbuf_phys: |
| 1857 | for (idx = 0; idx < rcd->egrbufs.alloced && |
Jubin John | 17fb4f2 | 2016-02-14 20:21:52 -0800 | [diff] [blame] | 1858 | rcd->egrbufs.buffers[idx].addr; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1859 | idx++) { |
| 1860 | dma_free_coherent(&dd->pcidev->dev, |
| 1861 | rcd->egrbufs.buffers[idx].len, |
| 1862 | rcd->egrbufs.buffers[idx].addr, |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 1863 | rcd->egrbufs.buffers[idx].dma); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1864 | rcd->egrbufs.buffers[idx].addr = NULL; |
Tymoteusz Kielan | 6036818 | 2016-09-06 04:35:54 -0700 | [diff] [blame] | 1865 | rcd->egrbufs.buffers[idx].dma = 0; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1866 | rcd->egrbufs.buffers[idx].len = 0; |
| 1867 | } |
| 1868 | bail: |
| 1869 | return ret; |
| 1870 | } |