blob: a00308ccf016af63e60681954c2d4a0d8a34d4db [file] [log] [blame]
Mike Marciniszyn77241052015-07-30 15:17:43 -04001/*
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -07002 * Copyright(c) 2015-2017 Intel Corporation.
Mike Marciniszyn77241052015-07-30 15:17:43 -04003 *
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 Marciniszyn77241052015-07-30 15:17:43 -04009 * 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 Marciniszyn77241052015-07-30 15:17:43 -040020 * 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>
Michael J. Ruhl8737ce92017-05-04 05:15:15 -070056#include <linux/bitmap.h>
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -080057#include <rdma/rdma_vt.h>
Mike Marciniszyn77241052015-07-30 15:17:43 -040058
59#include "hfi.h"
60#include "device.h"
61#include "common.h"
Sebastian Sanchez6c63e422015-11-06 20:06:56 -050062#include "trace.h"
Mike Marciniszyn77241052015-07-30 15:17:43 -040063#include "mad.h"
64#include "sdma.h"
65#include "debugfs.h"
66#include "verbs.h"
Ashutosh Dixitaffa48d2016-02-03 14:33:06 -080067#include "aspm.h"
Dennis Dalessandro41973442016-07-25 07:52:36 -070068#include "affinity.h"
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -070069#include "vnic.h"
Michael J. Ruhlfe4e74e2017-06-09 16:00:12 -070070#include "exp_rcv.h"
Mike Marciniszyn77241052015-07-30 15:17:43 -040071
72#undef pr_fmt
73#define pr_fmt(fmt) DRIVER_NAME ": " fmt
74
Mike Marciniszyndd1ed102017-05-04 05:14:10 -070075#define HFI1_MAX_ACTIVE_WORKQUEUE_ENTRIES 5
Mike Marciniszyn77241052015-07-30 15:17:43 -040076/*
77 * min buffers we want to have per context, after driver
78 */
79#define HFI1_MIN_USER_CTXT_BUFCNT 7
80
81#define HFI1_MIN_HDRQ_EGRBUF_CNT 2
Sebastian Sancheze002dcc2016-02-03 14:34:32 -080082#define HFI1_MAX_HDRQ_EGRBUF_CNT 16352
Mike Marciniszyn77241052015-07-30 15:17:43 -040083#define HFI1_MIN_EAGER_BUFFER_SIZE (4 * 1024) /* 4KB */
84#define HFI1_MAX_EAGER_BUFFER_SIZE (256 * 1024) /* 256KB */
85
86/*
87 * Number of user receive contexts we are configured to use (to allow for more
88 * pio buffers per ctxt, etc.) Zero means use one user context per CPU.
89 */
Sebastian Sanchez2ce6bf22015-12-11 08:44:48 -050090int num_user_contexts = -1;
91module_param_named(num_user_contexts, num_user_contexts, uint, S_IRUGO);
Mike Marciniszyn77241052015-07-30 15:17:43 -040092MODULE_PARM_DESC(
Sebastian Sanchez2ce6bf22015-12-11 08:44:48 -050093 num_user_contexts, "Set max number of user contexts to use");
Mike Marciniszyn77241052015-07-30 15:17:43 -040094
Mark F. Brown5b55ea32016-01-11 18:30:54 -050095uint krcvqs[RXE_NUM_DATA_VL];
Mike Marciniszyn77241052015-07-30 15:17:43 -040096int krcvqsset;
Mark F. Brown5b55ea32016-01-11 18:30:54 -050097module_param_array(krcvqs, uint, &krcvqsset, S_IRUGO);
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -050098MODULE_PARM_DESC(krcvqs, "Array of the number of non-control kernel receive queues by VL");
Mike Marciniszyn77241052015-07-30 15:17:43 -040099
100/* computed based on above array */
Harish Chegondi429b6a72016-08-31 07:24:40 -0700101unsigned long n_krcvqs;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400102
103static unsigned hfi1_rcvarr_split = 25;
104module_param_named(rcvarr_split, hfi1_rcvarr_split, uint, S_IRUGO);
105MODULE_PARM_DESC(rcvarr_split, "Percent of context's RcvArray entries used for Eager buffers");
106
Tymoteusz Kielan9746fa42017-05-04 05:14:22 -0700107static uint eager_buffer_size = (8 << 20); /* 8MB */
Mike Marciniszyn77241052015-07-30 15:17:43 -0400108module_param(eager_buffer_size, uint, S_IRUGO);
Tymoteusz Kielan9746fa42017-05-04 05:14:22 -0700109MODULE_PARM_DESC(eager_buffer_size, "Size of the eager buffers, default: 8MB");
Mike Marciniszyn77241052015-07-30 15:17:43 -0400110
111static uint rcvhdrcnt = 2048; /* 2x the max eager buffer count */
112module_param_named(rcvhdrcnt, rcvhdrcnt, uint, S_IRUGO);
113MODULE_PARM_DESC(rcvhdrcnt, "Receive header queue count (default 2048)");
114
115static uint hfi1_hdrq_entsize = 32;
116module_param_named(hdrq_entsize, hfi1_hdrq_entsize, uint, S_IRUGO);
117MODULE_PARM_DESC(hdrq_entsize, "Size of header queue entries: 2 - 8B, 16 - 64B (default), 32 - 128B");
118
119unsigned int user_credit_return_threshold = 33; /* default is 33% */
120module_param(user_credit_return_threshold, uint, S_IRUGO);
Jubin Johnecb95a02015-12-17 19:24:14 -0500121MODULE_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 Marciniszyn77241052015-07-30 15:17:43 -0400122
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -0700123static inline u64 encode_rcv_header_entry_size(u16 size);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400124
125static struct idr hfi1_unit_table;
126u32 hfi1_cpulist_count;
127unsigned long *hfi1_cpulist;
128
129/*
130 * Common code for creating the receive context array.
131 */
132int hfi1_create_ctxts(struct hfi1_devdata *dd)
133{
134 unsigned i;
135 int ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400136
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500137 /* Control context has to be always 0 */
138 BUILD_BUG_ON(HFI1_CTRL_CTXT != 0);
139
Mitko Haralanov377f1112016-02-03 14:33:58 -0800140 dd->rcd = kzalloc_node(dd->num_rcv_contexts * sizeof(*dd->rcd),
141 GFP_KERNEL, dd->node);
Alison Schofield806e6e12015-10-12 14:28:36 -0700142 if (!dd->rcd)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400143 goto nomem;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400144
145 /* create one or more kernel contexts */
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700146 for (i = 0; i < dd->first_dyn_alloc_ctxt; ++i) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400147 struct hfi1_pportdata *ppd;
148 struct hfi1_ctxtdata *rcd;
149
150 ppd = dd->pport + (i % dd->num_pports);
Jianxin Xiong4dfe7cc2016-10-17 04:19:41 -0700151
152 /* dd->rcd[i] gets assigned inside the callee */
Mitko Haralanov957558c2016-02-03 14:33:40 -0800153 rcd = hfi1_create_ctxtdata(ppd, i, dd->node);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400154 if (!rcd) {
155 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -0800156 "Unable to allocate kernel receive context, failing\n");
Mike Marciniszyn77241052015-07-30 15:17:43 -0400157 goto nomem;
158 }
159 /*
160 * Set up the kernel context flags here and now because they
161 * use default values for all receive side memories. User
162 * contexts will be handled as they are created.
163 */
164 rcd->flags = HFI1_CAP_KGET(MULTI_PKT_EGR) |
165 HFI1_CAP_KGET(NODROP_RHQ_FULL) |
166 HFI1_CAP_KGET(NODROP_EGR_FULL) |
167 HFI1_CAP_KGET(DMA_RTAIL);
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500168
169 /* Control context must use DMA_RTAIL */
170 if (rcd->ctxt == HFI1_CTRL_CTXT)
171 rcd->flags |= HFI1_CAP_DMA_RTAIL;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400172 rcd->seq_cnt = 1;
173
174 rcd->sc = sc_alloc(dd, SC_ACK, rcd->rcvhdrqentsize, dd->node);
175 if (!rcd->sc) {
176 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -0800177 "Unable to allocate kernel send context, failing\n");
Mike Marciniszyn77241052015-07-30 15:17:43 -0400178 goto nomem;
179 }
180
Michael J. Ruhl9b60d2c2017-05-04 05:15:09 -0700181 hfi1_init_ctxt(rcd->sc);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400182 }
183
Ashutosh Dixitaffa48d2016-02-03 14:33:06 -0800184 /*
185 * Initialize aspm, to be done after gen3 transition and setting up
186 * contexts and before enabling interrupts
187 */
188 aspm_init(dd);
189
Mike Marciniszyn77241052015-07-30 15:17:43 -0400190 return 0;
191nomem:
192 ret = -ENOMEM;
Michael J. Ruhl9b60d2c2017-05-04 05:15:09 -0700193
Jianxin Xiong4dfe7cc2016-10-17 04:19:41 -0700194 if (dd->rcd) {
195 for (i = 0; i < dd->num_rcv_contexts; ++i)
196 hfi1_free_ctxtdata(dd, dd->rcd[i]);
197 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400198 kfree(dd->rcd);
199 dd->rcd = NULL;
200 return ret;
201}
202
203/*
204 * Common code for user and kernel context setup.
205 */
Mitko Haralanov957558c2016-02-03 14:33:40 -0800206struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt,
207 int numa)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400208{
209 struct hfi1_devdata *dd = ppd->dd;
210 struct hfi1_ctxtdata *rcd;
211 unsigned kctxt_ngroups = 0;
212 u32 base;
213
214 if (dd->rcv_entries.nctxt_extra >
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700215 dd->num_rcv_contexts - dd->first_dyn_alloc_ctxt)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400216 kctxt_ngroups = (dd->rcv_entries.nctxt_extra -
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700217 (dd->num_rcv_contexts - dd->first_dyn_alloc_ctxt));
Jianxin Xiong4dfe7cc2016-10-17 04:19:41 -0700218 rcd = kzalloc_node(sizeof(*rcd), GFP_KERNEL, numa);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400219 if (rcd) {
220 u32 rcvtids, max_entries;
221
Sebastian Sanchez6c63e422015-11-06 20:06:56 -0500222 hfi1_cdbg(PROC, "setting up context %u\n", ctxt);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400223
224 INIT_LIST_HEAD(&rcd->qp_wait_list);
Michael J. Ruhlfe4e74e2017-06-09 16:00:12 -0700225 hfi1_exp_tid_group_init(&rcd->tid_group_list);
226 hfi1_exp_tid_group_init(&rcd->tid_used_list);
227 hfi1_exp_tid_group_init(&rcd->tid_full_list);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400228 rcd->ppd = ppd;
229 rcd->dd = dd;
Michael J. Ruhl8737ce92017-05-04 05:15:15 -0700230 __set_bit(0, rcd->in_use_ctxts);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400231 rcd->ctxt = ctxt;
232 dd->rcd[ctxt] = rcd;
Mitko Haralanov957558c2016-02-03 14:33:40 -0800233 rcd->numa_id = numa;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400234 rcd->rcv_array_groups = dd->rcv_entries.ngroups;
235
Mitko Haralanov463e6eb2016-02-05 11:57:53 -0500236 mutex_init(&rcd->exp_lock);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400237
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
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700242 * taken and we have to account for any extra groups assigned
243 * to the static (kernel) or dynamic (vnic/user) contexts.
Mike Marciniszyn77241052015-07-30 15:17:43 -0400244 */
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700245 if (ctxt < dd->first_dyn_alloc_ctxt) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400246 if (ctxt < kctxt_ngroups) {
247 base = ctxt * (dd->rcv_entries.ngroups + 1);
248 rcd->rcv_array_groups++;
Dennis Dalessandroee495ad2017-04-09 10:17:18 -0700249 } else {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400250 base = kctxt_ngroups +
251 (ctxt * dd->rcv_entries.ngroups);
Dennis Dalessandroee495ad2017-04-09 10:17:18 -0700252 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400253 } else {
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700254 u16 ct = ctxt - dd->first_dyn_alloc_ctxt;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400255
256 base = ((dd->n_krcv_queues * dd->rcv_entries.ngroups) +
257 kctxt_ngroups);
258 if (ct < dd->rcv_entries.nctxt_extra) {
259 base += ct * (dd->rcv_entries.ngroups + 1);
260 rcd->rcv_array_groups++;
Dennis Dalessandroee495ad2017-04-09 10:17:18 -0700261 } else {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400262 base += dd->rcv_entries.nctxt_extra +
263 (ct * dd->rcv_entries.ngroups);
Dennis Dalessandroee495ad2017-04-09 10:17:18 -0700264 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400265 }
266 rcd->eager_base = base * dd->rcv_entries.group_size;
267
Mike Marciniszyn77241052015-07-30 15:17:43 -0400268 rcd->rcvhdrq_cnt = rcvhdrcnt;
269 rcd->rcvhdrqentsize = hfi1_hdrq_entsize;
270 /*
271 * Simple Eager buffer allocation: we have already pre-allocated
272 * the number of RcvArray entry groups. Each ctxtdata structure
273 * holds the number of groups for that context.
274 *
275 * To follow CSR requirements and maintain cacheline alignment,
276 * make sure all sizes and bases are multiples of group_size.
277 *
278 * The expected entry count is what is left after assigning
279 * eager.
280 */
281 max_entries = rcd->rcv_array_groups *
282 dd->rcv_entries.group_size;
283 rcvtids = ((max_entries * hfi1_rcvarr_split) / 100);
284 rcd->egrbufs.count = round_down(rcvtids,
285 dd->rcv_entries.group_size);
286 if (rcd->egrbufs.count > MAX_EAGER_ENTRIES) {
287 dd_dev_err(dd, "ctxt%u: requested too many RcvArray entries.\n",
288 rcd->ctxt);
289 rcd->egrbufs.count = MAX_EAGER_ENTRIES;
290 }
Sebastian Sanchez6c63e422015-11-06 20:06:56 -0500291 hfi1_cdbg(PROC,
292 "ctxt%u: max Eager buffer RcvArray entries: %u\n",
293 rcd->ctxt, rcd->egrbufs.count);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400294
295 /*
296 * Allocate array that will hold the eager buffer accounting
297 * data.
298 * This will allocate the maximum possible buffer count based
299 * on the value of the RcvArray split parameter.
300 * The resulting value will be rounded down to the closest
301 * multiple of dd->rcv_entries.group_size.
302 */
Sebastian Sanchezb448bf92017-02-08 05:26:37 -0800303 rcd->egrbufs.buffers = kzalloc_node(
304 rcd->egrbufs.count * sizeof(*rcd->egrbufs.buffers),
305 GFP_KERNEL, numa);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400306 if (!rcd->egrbufs.buffers)
307 goto bail;
Sebastian Sanchezb448bf92017-02-08 05:26:37 -0800308 rcd->egrbufs.rcvtids = kzalloc_node(
309 rcd->egrbufs.count *
310 sizeof(*rcd->egrbufs.rcvtids),
311 GFP_KERNEL, numa);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400312 if (!rcd->egrbufs.rcvtids)
313 goto bail;
314 rcd->egrbufs.size = eager_buffer_size;
315 /*
316 * The size of the buffers programmed into the RcvArray
317 * entries needs to be big enough to handle the highest
318 * MTU supported.
319 */
320 if (rcd->egrbufs.size < hfi1_max_mtu) {
321 rcd->egrbufs.size = __roundup_pow_of_two(hfi1_max_mtu);
Sebastian Sanchez6c63e422015-11-06 20:06:56 -0500322 hfi1_cdbg(PROC,
323 "ctxt%u: eager bufs size too small. Adjusting to %zu\n",
Mike Marciniszyn77241052015-07-30 15:17:43 -0400324 rcd->ctxt, rcd->egrbufs.size);
325 }
326 rcd->egrbufs.rcvtid_size = HFI1_MAX_EAGER_BUFFER_SIZE;
327
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700328 /* Applicable only for statically created kernel contexts */
329 if (ctxt < dd->first_dyn_alloc_ctxt) {
Sebastian Sanchezb448bf92017-02-08 05:26:37 -0800330 rcd->opstats = kzalloc_node(sizeof(*rcd->opstats),
331 GFP_KERNEL, numa);
Alison Schofield806e6e12015-10-12 14:28:36 -0700332 if (!rcd->opstats)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400333 goto bail;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400334 }
335 }
336 return rcd;
337bail:
Jakub Pawlak3a6982d2016-09-25 07:42:23 -0700338 dd->rcd[ctxt] = NULL;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400339 kfree(rcd->egrbufs.rcvtids);
340 kfree(rcd->egrbufs.buffers);
341 kfree(rcd);
342 return NULL;
343}
344
345/*
346 * Convert a receive header entry size that to the encoding used in the CSR.
347 *
348 * Return a zero if the given size is invalid.
349 */
350static inline u64 encode_rcv_header_entry_size(u16 size)
351{
352 /* there are only 3 valid receive header entry sizes */
353 if (size == 2)
354 return 1;
355 if (size == 16)
356 return 2;
357 else if (size == 32)
358 return 4;
359 return 0; /* invalid */
360}
361
362/*
363 * Select the largest ccti value over all SLs to determine the intra-
364 * packet gap for the link.
365 *
366 * called with cca_timer_lock held (to protect access to cca_timer
367 * array), and rcu_read_lock() (to protect access to cc_state).
368 */
369void set_link_ipg(struct hfi1_pportdata *ppd)
370{
371 struct hfi1_devdata *dd = ppd->dd;
372 struct cc_state *cc_state;
373 int i;
374 u16 cce, ccti_limit, max_ccti = 0;
375 u16 shift, mult;
376 u64 src;
377 u32 current_egress_rate; /* Mbits /sec */
378 u32 max_pkt_time;
379 /*
380 * max_pkt_time is the maximum packet egress time in units
381 * of the fabric clock period 1/(805 MHz).
382 */
383
384 cc_state = get_cc_state(ppd);
385
Jubin Johnd125a6c2016-02-14 20:19:49 -0800386 if (!cc_state)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400387 /*
388 * This should _never_ happen - rcu_read_lock() is held,
389 * and set_link_ipg() should not be called if cc_state
390 * is NULL.
391 */
392 return;
393
394 for (i = 0; i < OPA_MAX_SLS; i++) {
395 u16 ccti = ppd->cca_timer[i].ccti;
396
397 if (ccti > max_ccti)
398 max_ccti = ccti;
399 }
400
401 ccti_limit = cc_state->cct.ccti_limit;
402 if (max_ccti > ccti_limit)
403 max_ccti = ccti_limit;
404
405 cce = cc_state->cct.entries[max_ccti].entry;
406 shift = (cce & 0xc000) >> 14;
407 mult = (cce & 0x3fff);
408
409 current_egress_rate = active_egress_rate(ppd);
410
411 max_pkt_time = egress_cycles(ppd->ibmaxlen, current_egress_rate);
412
413 src = (max_pkt_time >> shift) * mult;
414
415 src &= SEND_STATIC_RATE_CONTROL_CSR_SRC_RELOAD_SMASK;
416 src <<= SEND_STATIC_RATE_CONTROL_CSR_SRC_RELOAD_SHIFT;
417
418 write_csr(dd, SEND_STATIC_RATE_CONTROL, src);
419}
420
421static enum hrtimer_restart cca_timer_fn(struct hrtimer *t)
422{
423 struct cca_timer *cca_timer;
424 struct hfi1_pportdata *ppd;
425 int sl;
Jubin Johnd35cf7442016-04-14 08:31:53 -0700426 u16 ccti_timer, ccti_min;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400427 struct cc_state *cc_state;
Dean Luickb77d7132015-10-26 10:28:43 -0400428 unsigned long flags;
Jubin Johnd35cf7442016-04-14 08:31:53 -0700429 enum hrtimer_restart ret = HRTIMER_NORESTART;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400430
431 cca_timer = container_of(t, struct cca_timer, hrtimer);
432 ppd = cca_timer->ppd;
433 sl = cca_timer->sl;
434
435 rcu_read_lock();
436
437 cc_state = get_cc_state(ppd);
438
Jubin Johnd125a6c2016-02-14 20:19:49 -0800439 if (!cc_state) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400440 rcu_read_unlock();
441 return HRTIMER_NORESTART;
442 }
443
444 /*
445 * 1) decrement ccti for SL
446 * 2) calculate IPG for link (set_link_ipg())
447 * 3) restart timer, unless ccti is at min value
448 */
449
450 ccti_min = cc_state->cong_setting.entries[sl].ccti_min;
451 ccti_timer = cc_state->cong_setting.entries[sl].ccti_timer;
452
Dean Luickb77d7132015-10-26 10:28:43 -0400453 spin_lock_irqsave(&ppd->cca_timer_lock, flags);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400454
Jubin Johnd35cf7442016-04-14 08:31:53 -0700455 if (cca_timer->ccti > ccti_min) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400456 cca_timer->ccti--;
457 set_link_ipg(ppd);
458 }
459
Jubin Johnd35cf7442016-04-14 08:31:53 -0700460 if (cca_timer->ccti > ccti_min) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400461 unsigned long nsec = 1024 * ccti_timer;
462 /* ccti_timer is in units of 1.024 usec */
463 hrtimer_forward_now(t, ns_to_ktime(nsec));
Jubin Johnd35cf7442016-04-14 08:31:53 -0700464 ret = HRTIMER_RESTART;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400465 }
Jubin Johnd35cf7442016-04-14 08:31:53 -0700466
467 spin_unlock_irqrestore(&ppd->cca_timer_lock, flags);
468 rcu_read_unlock();
469 return ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400470}
471
472/*
473 * Common code for initializing the physical port structure.
474 */
475void hfi1_init_pportdata(struct pci_dev *pdev, struct hfi1_pportdata *ppd,
476 struct hfi1_devdata *dd, u8 hw_pidx, u8 port)
477{
Jianxin Xiong8adf71f2016-07-25 13:39:14 -0700478 int i;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400479 uint default_pkey_idx;
Jianxin Xiong8adf71f2016-07-25 13:39:14 -0700480 struct cc_state *cc_state;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400481
482 ppd->dd = dd;
483 ppd->hw_pidx = hw_pidx;
484 ppd->port = port; /* IB port number, not index */
485
486 default_pkey_idx = 1;
487
488 ppd->pkeys[default_pkey_idx] = DEFAULT_P_KEY;
Neel Desai53526502017-04-09 10:16:59 -0700489 ppd->part_enforce |= HFI1_PART_ENFORCE_IN;
490 ppd->part_enforce |= HFI1_PART_ENFORCE_OUT;
491
Mike Marciniszyn77241052015-07-30 15:17:43 -0400492 if (loopback) {
493 hfi1_early_err(&pdev->dev,
494 "Faking data partition 0x8001 in idx %u\n",
495 !default_pkey_idx);
496 ppd->pkeys[!default_pkey_idx] = 0x8001;
497 }
498
499 INIT_WORK(&ppd->link_vc_work, handle_verify_cap);
500 INIT_WORK(&ppd->link_up_work, handle_link_up);
501 INIT_WORK(&ppd->link_down_work, handle_link_down);
502 INIT_WORK(&ppd->freeze_work, handle_freeze);
503 INIT_WORK(&ppd->link_downgrade_work, handle_link_downgrade);
504 INIT_WORK(&ppd->sma_message_work, handle_sma_message);
505 INIT_WORK(&ppd->link_bounce_work, handle_link_bounce);
Dean Luick673b9752016-08-31 07:24:33 -0700506 INIT_DELAYED_WORK(&ppd->start_link_work, handle_start_link);
Jim Snowfb9036d2016-01-11 18:32:21 -0500507 INIT_WORK(&ppd->linkstate_active_work, receive_interrupt_work);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800508 INIT_WORK(&ppd->qsfp_info.qsfp_work, qsfp_event);
509
Mike Marciniszyn77241052015-07-30 15:17:43 -0400510 mutex_init(&ppd->hls_lock);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400511 spin_lock_init(&ppd->qsfp_info.qsfp_lock);
512
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800513 ppd->qsfp_info.ppd = ppd;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400514 ppd->sm_trap_qp = 0x0;
515 ppd->sa_qp = 0x1;
516
517 ppd->hfi1_wq = NULL;
518
519 spin_lock_init(&ppd->cca_timer_lock);
520
521 for (i = 0; i < OPA_MAX_SLS; i++) {
522 hrtimer_init(&ppd->cca_timer[i].hrtimer, CLOCK_MONOTONIC,
523 HRTIMER_MODE_REL);
524 ppd->cca_timer[i].ppd = ppd;
525 ppd->cca_timer[i].sl = i;
526 ppd->cca_timer[i].ccti = 0;
527 ppd->cca_timer[i].hrtimer.function = cca_timer_fn;
528 }
529
530 ppd->cc_max_table_entries = IB_CC_TABLE_CAP_DEFAULT;
531
532 spin_lock_init(&ppd->cc_state_lock);
533 spin_lock_init(&ppd->cc_log_lock);
Jianxin Xiong8adf71f2016-07-25 13:39:14 -0700534 cc_state = kzalloc(sizeof(*cc_state), GFP_KERNEL);
535 RCU_INIT_POINTER(ppd->cc_state, cc_state);
536 if (!cc_state)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400537 goto bail;
538 return;
539
540bail:
541
542 hfi1_early_err(&pdev->dev,
543 "Congestion Control Agent disabled for port %d\n", port);
544}
545
546/*
547 * Do initialization for device that is only needed on
548 * first detect, not on resets.
549 */
550static int loadtime_init(struct hfi1_devdata *dd)
551{
552 return 0;
553}
554
555/**
556 * init_after_reset - re-initialize after a reset
557 * @dd: the hfi1_ib device
558 *
559 * sanity check at least some of the values after reset, and
560 * ensure no receive or transmit (explicitly, in case reset
561 * failed
562 */
563static int init_after_reset(struct hfi1_devdata *dd)
564{
565 int i;
566
567 /*
568 * Ensure chip does no sends or receives, tail updates, or
569 * pioavail updates while we re-initialize. This is mostly
570 * for the driver data structures, not chip registers.
571 */
572 for (i = 0; i < dd->num_rcv_contexts; i++)
573 hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_DIS |
574 HFI1_RCVCTRL_INTRAVAIL_DIS |
575 HFI1_RCVCTRL_TAILUPD_DIS, i);
576 pio_send_control(dd, PSC_GLOBAL_DISABLE);
577 for (i = 0; i < dd->num_send_contexts; i++)
578 sc_disable(dd->send_contexts[i].sc);
579
580 return 0;
581}
582
583static void enable_chip(struct hfi1_devdata *dd)
584{
585 u32 rcvmask;
586 u32 i;
587
588 /* enable PIO send */
589 pio_send_control(dd, PSC_GLOBAL_ENABLE);
590
591 /*
592 * Enable kernel ctxts' receive and receive interrupt.
593 * Other ctxts done as user opens and initializes them.
594 */
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700595 for (i = 0; i < dd->first_dyn_alloc_ctxt; ++i) {
Mitko Haralanov566c1572016-02-03 14:32:49 -0800596 rcvmask = HFI1_RCVCTRL_CTXT_ENB | HFI1_RCVCTRL_INTRAVAIL_ENB;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400597 rcvmask |= HFI1_CAP_KGET_MASK(dd->rcd[i]->flags, DMA_RTAIL) ?
598 HFI1_RCVCTRL_TAILUPD_ENB : HFI1_RCVCTRL_TAILUPD_DIS;
599 if (!HFI1_CAP_KGET_MASK(dd->rcd[i]->flags, MULTI_PKT_EGR))
600 rcvmask |= HFI1_RCVCTRL_ONE_PKT_EGR_ENB;
601 if (HFI1_CAP_KGET_MASK(dd->rcd[i]->flags, NODROP_RHQ_FULL))
602 rcvmask |= HFI1_RCVCTRL_NO_RHQ_DROP_ENB;
603 if (HFI1_CAP_KGET_MASK(dd->rcd[i]->flags, NODROP_EGR_FULL))
604 rcvmask |= HFI1_RCVCTRL_NO_EGR_DROP_ENB;
605 hfi1_rcvctrl(dd, rcvmask, i);
606 sc_enable(dd->rcd[i]->sc);
607 }
608}
609
610/**
611 * create_workqueues - create per port workqueues
612 * @dd: the hfi1_ib device
613 */
614static int create_workqueues(struct hfi1_devdata *dd)
615{
616 int pidx;
617 struct hfi1_pportdata *ppd;
618
619 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
620 ppd = dd->pport + pidx;
621 if (!ppd->hfi1_wq) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400622 ppd->hfi1_wq =
Mike Marciniszyn0a226ed2015-11-09 19:13:58 -0500623 alloc_workqueue(
624 "hfi%d_%d",
625 WQ_SYSFS | WQ_HIGHPRI | WQ_CPU_INTENSIVE,
Mike Marciniszyndd1ed102017-05-04 05:14:10 -0700626 HFI1_MAX_ACTIVE_WORKQUEUE_ENTRIES,
Mike Marciniszyn0a226ed2015-11-09 19:13:58 -0500627 dd->unit, pidx);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400628 if (!ppd->hfi1_wq)
629 goto wq_error;
630 }
631 }
632 return 0;
633wq_error:
Mike Marciniszyn0a226ed2015-11-09 19:13:58 -0500634 pr_err("alloc_workqueue failed for port %d\n", pidx + 1);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400635 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
636 ppd = dd->pport + pidx;
637 if (ppd->hfi1_wq) {
638 destroy_workqueue(ppd->hfi1_wq);
639 ppd->hfi1_wq = NULL;
640 }
641 }
642 return -ENOMEM;
643}
644
645/**
646 * hfi1_init - do the actual initialization sequence on the chip
647 * @dd: the hfi1_ib device
648 * @reinit: re-initializing, so don't allocate new memory
649 *
650 * Do the actual initialization sequence on the chip. This is done
651 * both from the init routine called from the PCI infrastructure, and
652 * when we reset the chip, or detect that it was reset internally,
653 * or it's administratively re-enabled.
654 *
655 * Memory allocation here and in called routines is only done in
656 * the first case (reinit == 0). We have to be careful, because even
657 * without memory allocation, we need to re-write all the chip registers
658 * TIDs, etc. after the reset or enable has completed.
659 */
660int hfi1_init(struct hfi1_devdata *dd, int reinit)
661{
662 int ret = 0, pidx, lastfail = 0;
663 unsigned i, len;
664 struct hfi1_ctxtdata *rcd;
665 struct hfi1_pportdata *ppd;
666
667 /* Set up recv low level handlers */
668 dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_EXPECTED] =
669 kdeth_process_expected;
670 dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_EAGER] =
671 kdeth_process_eager;
672 dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_IB] = process_receive_ib;
673 dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_ERROR] =
674 process_receive_error;
675 dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_BYPASS] =
676 process_receive_bypass;
677 dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_INVALID5] =
678 process_receive_invalid;
679 dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_INVALID6] =
680 process_receive_invalid;
681 dd->normal_rhf_rcv_functions[RHF_RCV_TYPE_INVALID7] =
682 process_receive_invalid;
683 dd->rhf_rcv_function_map = dd->normal_rhf_rcv_functions;
684
685 /* Set up send low level handlers */
686 dd->process_pio_send = hfi1_verbs_send_pio;
687 dd->process_dma_send = hfi1_verbs_send_dma;
688 dd->pio_inline_send = pio_copy;
Vishwanathapura, Niranjana64551ed2017-04-12 20:29:30 -0700689 dd->process_vnic_dma_send = hfi1_vnic_send_dma;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400690
Mike Marciniszyn995deaf2015-11-16 21:59:29 -0500691 if (is_ax(dd)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400692 atomic_set(&dd->drop_packet, DROP_PACKET_ON);
693 dd->do_drop = 1;
694 } else {
695 atomic_set(&dd->drop_packet, DROP_PACKET_OFF);
696 dd->do_drop = 0;
697 }
698
699 /* make sure the link is not "up" */
700 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
701 ppd = dd->pport + pidx;
702 ppd->linkup = 0;
703 }
704
705 if (reinit)
706 ret = init_after_reset(dd);
707 else
708 ret = loadtime_init(dd);
709 if (ret)
710 goto done;
711
Mark F. Brown46b010d2015-11-09 19:18:20 -0500712 /* allocate dummy tail memory for all receive contexts */
713 dd->rcvhdrtail_dummy_kvaddr = dma_zalloc_coherent(
714 &dd->pcidev->dev, sizeof(u64),
Tymoteusz Kielan60368182016-09-06 04:35:54 -0700715 &dd->rcvhdrtail_dummy_dma,
Mark F. Brown46b010d2015-11-09 19:18:20 -0500716 GFP_KERNEL);
717
718 if (!dd->rcvhdrtail_dummy_kvaddr) {
719 dd_dev_err(dd, "cannot allocate dummy tail memory\n");
720 ret = -ENOMEM;
721 goto done;
722 }
723
Mike Marciniszyn77241052015-07-30 15:17:43 -0400724 /* dd->rcd can be NULL if early initialization failed */
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700725 for (i = 0; dd->rcd && i < dd->first_dyn_alloc_ctxt; ++i) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400726 /*
727 * Set up the (kernel) rcvhdr queue and egr TIDs. If doing
728 * re-init, the simplest way to handle this is to free
729 * existing, and re-allocate.
730 * Need to re-create rest of ctxt 0 ctxtdata as well.
731 */
732 rcd = dd->rcd[i];
733 if (!rcd)
734 continue;
735
736 rcd->do_interrupt = &handle_receive_interrupt;
737
738 lastfail = hfi1_create_rcvhdrq(dd, rcd);
739 if (!lastfail)
740 lastfail = hfi1_setup_eagerbufs(rcd);
Ashutosh Dixit39239792016-05-12 10:24:00 -0700741 if (lastfail) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400742 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -0800743 "failed to allocate kernel ctxt's rcvhdrq and/or egr bufs\n");
Ashutosh Dixit39239792016-05-12 10:24:00 -0700744 ret = lastfail;
745 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400746 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400747
748 /* Allocate enough memory for user event notification. */
Amitoj Kaur Chawla84449912016-03-04 22:30:43 +0530749 len = PAGE_ALIGN(dd->chip_rcv_contexts * HFI1_MAX_SHARED_CTXTS *
750 sizeof(*dd->events));
Mike Marciniszyn77241052015-07-30 15:17:43 -0400751 dd->events = vmalloc_user(len);
752 if (!dd->events)
753 dd_dev_err(dd, "Failed to allocate user events page\n");
754 /*
755 * Allocate a page for device and port status.
756 * Page will be shared amongst all user processes.
757 */
758 dd->status = vmalloc_user(PAGE_SIZE);
759 if (!dd->status)
760 dd_dev_err(dd, "Failed to allocate dev status page\n");
761 else
762 dd->freezelen = PAGE_SIZE - (sizeof(*dd->status) -
763 sizeof(dd->status->freezemsg));
764 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
765 ppd = dd->pport + pidx;
766 if (dd->status)
767 /* Currently, we only have one port */
768 ppd->statusp = &dd->status->port;
769
770 set_mtu(ppd);
771 }
772
773 /* enable chip even if we have an error, so we can debug cause */
774 enable_chip(dd);
775
Mike Marciniszyn77241052015-07-30 15:17:43 -0400776done:
777 /*
778 * Set status even if port serdes is not initialized
779 * so that diags will work.
780 */
781 if (dd->status)
782 dd->status->dev |= HFI1_STATUS_CHIP_PRESENT |
783 HFI1_STATUS_INITTED;
784 if (!ret) {
785 /* enable all interrupts from the chip */
786 set_intr_state(dd, 1);
787
788 /* chip is OK for user apps; mark it as initialized */
789 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
790 ppd = dd->pport + pidx;
791
Jubin John4d114fd2016-02-14 20:21:43 -0800792 /*
793 * start the serdes - must be after interrupts are
794 * enabled so we are notified when the link goes up
Mike Marciniszyn77241052015-07-30 15:17:43 -0400795 */
Mike Marciniszyn77241052015-07-30 15:17:43 -0400796 lastfail = bringup_serdes(ppd);
797 if (lastfail)
798 dd_dev_info(dd,
Jubin John17fb4f22016-02-14 20:21:52 -0800799 "Failed to bring up port %u\n",
800 ppd->port);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400801
802 /*
803 * Set status even if port serdes is not initialized
804 * so that diags will work.
805 */
806 if (ppd->statusp)
807 *ppd->statusp |= HFI1_STATUS_CHIP_PRESENT |
808 HFI1_STATUS_INITTED;
809 if (!ppd->link_speed_enabled)
810 continue;
811 }
812 }
813
814 /* if ret is non-zero, we probably should do some cleanup here... */
815 return ret;
816}
817
818static inline struct hfi1_devdata *__hfi1_lookup(int unit)
819{
820 return idr_find(&hfi1_unit_table, unit);
821}
822
823struct hfi1_devdata *hfi1_lookup(int unit)
824{
825 struct hfi1_devdata *dd;
826 unsigned long flags;
827
828 spin_lock_irqsave(&hfi1_devs_lock, flags);
829 dd = __hfi1_lookup(unit);
830 spin_unlock_irqrestore(&hfi1_devs_lock, flags);
831
832 return dd;
833}
834
835/*
836 * Stop the timers during unit shutdown, or after an error late
837 * in initialization.
838 */
839static void stop_timers(struct hfi1_devdata *dd)
840{
841 struct hfi1_pportdata *ppd;
842 int pidx;
843
844 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
845 ppd = dd->pport + pidx;
846 if (ppd->led_override_timer.data) {
847 del_timer_sync(&ppd->led_override_timer);
848 atomic_set(&ppd->led_override_timer_active, 0);
849 }
850 }
851}
852
853/**
854 * shutdown_device - shut down a device
855 * @dd: the hfi1_ib device
856 *
857 * This is called to make the device quiet when we are about to
858 * unload the driver, and also when the device is administratively
859 * disabled. It does not free any data structures.
860 * Everything it does has to be setup again by hfi1_init(dd, 1)
861 */
862static void shutdown_device(struct hfi1_devdata *dd)
863{
864 struct hfi1_pportdata *ppd;
865 unsigned pidx;
866 int i;
867
868 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
869 ppd = dd->pport + pidx;
870
871 ppd->linkup = 0;
872 if (ppd->statusp)
873 *ppd->statusp &= ~(HFI1_STATUS_IB_CONF |
874 HFI1_STATUS_IB_READY);
875 }
876 dd->flags &= ~HFI1_INITTED;
877
878 /* mask interrupts, but not errors */
879 set_intr_state(dd, 0);
880
881 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
882 ppd = dd->pport + pidx;
883 for (i = 0; i < dd->num_rcv_contexts; i++)
884 hfi1_rcvctrl(dd, HFI1_RCVCTRL_TAILUPD_DIS |
885 HFI1_RCVCTRL_CTXT_DIS |
886 HFI1_RCVCTRL_INTRAVAIL_DIS |
887 HFI1_RCVCTRL_PKEY_DIS |
888 HFI1_RCVCTRL_ONE_PKT_EGR_DIS, i);
889 /*
890 * Gracefully stop all sends allowing any in progress to
891 * trickle out first.
892 */
893 for (i = 0; i < dd->num_send_contexts; i++)
894 sc_flush(dd->send_contexts[i].sc);
895 }
896
897 /*
898 * Enough for anything that's going to trickle out to have actually
899 * done so.
900 */
901 udelay(20);
902
903 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
904 ppd = dd->pport + pidx;
905
906 /* disable all contexts */
907 for (i = 0; i < dd->num_send_contexts; i++)
908 sc_disable(dd->send_contexts[i].sc);
909 /* disable the send device */
910 pio_send_control(dd, PSC_GLOBAL_DISABLE);
911
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -0800912 shutdown_led_override(ppd);
913
Mike Marciniszyn77241052015-07-30 15:17:43 -0400914 /*
915 * Clear SerdesEnable.
916 * We can't count on interrupts since we are stopping.
917 */
918 hfi1_quiet_serdes(ppd);
919
920 if (ppd->hfi1_wq) {
921 destroy_workqueue(ppd->hfi1_wq);
922 ppd->hfi1_wq = NULL;
923 }
924 }
925 sdma_exit(dd);
926}
927
928/**
929 * hfi1_free_ctxtdata - free a context's allocated data
930 * @dd: the hfi1_ib device
931 * @rcd: the ctxtdata structure
932 *
933 * free up any allocated data for a context
934 * This should not touch anything that would affect a simultaneous
935 * re-allocation of context data, because it is called after hfi1_mutex
936 * is released (and can be called from reinit as well).
937 * It should never change any chip state, or global driver state.
938 */
939void hfi1_free_ctxtdata(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd)
940{
941 unsigned e;
942
943 if (!rcd)
944 return;
945
946 if (rcd->rcvhdrq) {
947 dma_free_coherent(&dd->pcidev->dev, rcd->rcvhdrq_size,
Tymoteusz Kielan60368182016-09-06 04:35:54 -0700948 rcd->rcvhdrq, rcd->rcvhdrq_dma);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400949 rcd->rcvhdrq = NULL;
950 if (rcd->rcvhdrtail_kvaddr) {
951 dma_free_coherent(&dd->pcidev->dev, PAGE_SIZE,
952 (void *)rcd->rcvhdrtail_kvaddr,
Tymoteusz Kielan60368182016-09-06 04:35:54 -0700953 rcd->rcvhdrqtailaddr_dma);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400954 rcd->rcvhdrtail_kvaddr = NULL;
955 }
956 }
957
958 /* all the RcvArray entries should have been cleared by now */
959 kfree(rcd->egrbufs.rcvtids);
960
961 for (e = 0; e < rcd->egrbufs.alloced; e++) {
Tymoteusz Kielan60368182016-09-06 04:35:54 -0700962 if (rcd->egrbufs.buffers[e].dma)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400963 dma_free_coherent(&dd->pcidev->dev,
964 rcd->egrbufs.buffers[e].len,
965 rcd->egrbufs.buffers[e].addr,
Tymoteusz Kielan60368182016-09-06 04:35:54 -0700966 rcd->egrbufs.buffers[e].dma);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400967 }
968 kfree(rcd->egrbufs.buffers);
969
970 sc_free(rcd->sc);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400971 vfree(rcd->subctxt_uregbase);
972 vfree(rcd->subctxt_rcvegrbuf);
973 vfree(rcd->subctxt_rcvhdr_base);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400974 kfree(rcd->opstats);
975 kfree(rcd);
976}
977
Dean Luick78eb1292016-03-05 08:49:45 -0800978/*
979 * Release our hold on the shared asic data. If we are the last one,
Dean Luickdba715f2016-07-06 17:28:52 -0400980 * return the structure to be finalized outside the lock. Must be
981 * holding hfi1_devs_lock.
Dean Luick78eb1292016-03-05 08:49:45 -0800982 */
Dean Luickdba715f2016-07-06 17:28:52 -0400983static struct hfi1_asic_data *release_asic_data(struct hfi1_devdata *dd)
Dean Luick78eb1292016-03-05 08:49:45 -0800984{
Dean Luickdba715f2016-07-06 17:28:52 -0400985 struct hfi1_asic_data *ad;
Dean Luick78eb1292016-03-05 08:49:45 -0800986 int other;
987
988 if (!dd->asic_data)
Dean Luickdba715f2016-07-06 17:28:52 -0400989 return NULL;
Dean Luick78eb1292016-03-05 08:49:45 -0800990 dd->asic_data->dds[dd->hfi1_id] = NULL;
991 other = dd->hfi1_id ? 0 : 1;
Dean Luickdba715f2016-07-06 17:28:52 -0400992 ad = dd->asic_data;
Dean Luick78eb1292016-03-05 08:49:45 -0800993 dd->asic_data = NULL;
Dean Luickdba715f2016-07-06 17:28:52 -0400994 /* return NULL if the other dd still has a link */
995 return ad->dds[other] ? NULL : ad;
996}
997
998static void finalize_asic_data(struct hfi1_devdata *dd,
999 struct hfi1_asic_data *ad)
1000{
1001 clean_up_i2c(dd, ad);
1002 kfree(ad);
Dean Luick78eb1292016-03-05 08:49:45 -08001003}
1004
Dennis Dalessandroe11ffbd2016-05-19 05:26:44 -07001005static void __hfi1_free_devdata(struct kobject *kobj)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001006{
Dennis Dalessandroe11ffbd2016-05-19 05:26:44 -07001007 struct hfi1_devdata *dd =
1008 container_of(kobj, struct hfi1_devdata, kobj);
Dean Luickdba715f2016-07-06 17:28:52 -04001009 struct hfi1_asic_data *ad;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001010 unsigned long flags;
1011
1012 spin_lock_irqsave(&hfi1_devs_lock, flags);
1013 idr_remove(&hfi1_unit_table, dd->unit);
1014 list_del(&dd->list);
Dean Luickdba715f2016-07-06 17:28:52 -04001015 ad = release_asic_data(dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001016 spin_unlock_irqrestore(&hfi1_devs_lock, flags);
Dean Luickdba715f2016-07-06 17:28:52 -04001017 if (ad)
1018 finalize_asic_data(dd, ad);
Easwar Hariharanc3838b32016-02-09 14:29:13 -08001019 free_platform_config(dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001020 rcu_barrier(); /* wait for rcu callbacks to complete */
1021 free_percpu(dd->int_counter);
1022 free_percpu(dd->rcv_limit);
Vennila Megavannan89abfc82016-02-03 14:34:07 -08001023 free_percpu(dd->send_schedule);
Jubin Johnea0e4ce2016-04-20 06:05:24 -07001024 rvt_dealloc_device(&dd->verbs_dev.rdi);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001025}
1026
Dennis Dalessandroe11ffbd2016-05-19 05:26:44 -07001027static struct kobj_type hfi1_devdata_type = {
1028 .release = __hfi1_free_devdata,
1029};
1030
1031void hfi1_free_devdata(struct hfi1_devdata *dd)
1032{
1033 kobject_put(&dd->kobj);
1034}
1035
Mike Marciniszyn77241052015-07-30 15:17:43 -04001036/*
1037 * Allocate our primary per-unit data structure. Must be done via verbs
1038 * allocator, because the verbs cleanup process both does cleanup and
1039 * free of the data structure.
1040 * "extra" is for chip-specific data.
1041 *
1042 * Use the idr mechanism to get a unit number for this unit.
1043 */
1044struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra)
1045{
1046 unsigned long flags;
1047 struct hfi1_devdata *dd;
Dennis Dalessandro7af6d002016-01-19 14:44:06 -08001048 int ret, nports;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001049
Dennis Dalessandro7af6d002016-01-19 14:44:06 -08001050 /* extra is * number of ports */
1051 nports = extra / sizeof(struct hfi1_pportdata);
1052
1053 dd = (struct hfi1_devdata *)rvt_alloc_device(sizeof(*dd) + extra,
1054 nports);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001055 if (!dd)
1056 return ERR_PTR(-ENOMEM);
Dennis Dalessandro7af6d002016-01-19 14:44:06 -08001057 dd->num_pports = nports;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001058 dd->pport = (struct hfi1_pportdata *)(dd + 1);
1059
1060 INIT_LIST_HEAD(&dd->list);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001061 idr_preload(GFP_KERNEL);
1062 spin_lock_irqsave(&hfi1_devs_lock, flags);
1063
1064 ret = idr_alloc(&hfi1_unit_table, dd, 0, 0, GFP_NOWAIT);
1065 if (ret >= 0) {
1066 dd->unit = ret;
1067 list_add(&dd->list, &hfi1_dev_list);
1068 }
1069
1070 spin_unlock_irqrestore(&hfi1_devs_lock, flags);
1071 idr_preload_end();
1072
1073 if (ret < 0) {
1074 hfi1_early_err(&pdev->dev,
1075 "Could not allocate unit ID: error %d\n", -ret);
1076 goto bail;
1077 }
1078 /*
1079 * Initialize all locks for the device. This needs to be as early as
1080 * possible so locks are usable.
1081 */
1082 spin_lock_init(&dd->sc_lock);
1083 spin_lock_init(&dd->sendctrl_lock);
1084 spin_lock_init(&dd->rcvctrl_lock);
1085 spin_lock_init(&dd->uctxt_lock);
1086 spin_lock_init(&dd->hfi1_diag_trans_lock);
1087 spin_lock_init(&dd->sc_init_lock);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001088 spin_lock_init(&dd->dc8051_memlock);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001089 seqlock_init(&dd->sc2vl_lock);
1090 spin_lock_init(&dd->sde_map_lock);
Jubin John35f6bef2016-02-14 12:46:10 -08001091 spin_lock_init(&dd->pio_map_lock);
Tadeusz Struk22546b72017-04-28 10:40:02 -07001092 mutex_init(&dd->dc8051_lock);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001093 init_waitqueue_head(&dd->event_queue);
1094
1095 dd->int_counter = alloc_percpu(u64);
1096 if (!dd->int_counter) {
1097 ret = -ENOMEM;
1098 hfi1_early_err(&pdev->dev,
1099 "Could not allocate per-cpu int_counter\n");
1100 goto bail;
1101 }
1102
1103 dd->rcv_limit = alloc_percpu(u64);
1104 if (!dd->rcv_limit) {
1105 ret = -ENOMEM;
1106 hfi1_early_err(&pdev->dev,
1107 "Could not allocate per-cpu rcv_limit\n");
1108 goto bail;
1109 }
1110
Vennila Megavannan89abfc82016-02-03 14:34:07 -08001111 dd->send_schedule = alloc_percpu(u64);
1112 if (!dd->send_schedule) {
1113 ret = -ENOMEM;
1114 hfi1_early_err(&pdev->dev,
1115 "Could not allocate per-cpu int_counter\n");
1116 goto bail;
1117 }
1118
Mike Marciniszyn77241052015-07-30 15:17:43 -04001119 if (!hfi1_cpulist_count) {
1120 u32 count = num_online_cpus();
1121
Shraddha Barke314fcc02015-10-09 21:03:26 +05301122 hfi1_cpulist = kcalloc(BITS_TO_LONGS(count), sizeof(long),
1123 GFP_KERNEL);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001124 if (hfi1_cpulist)
1125 hfi1_cpulist_count = count;
1126 else
1127 hfi1_early_err(
1128 &pdev->dev,
1129 "Could not alloc cpulist info, cpu affinity might be wrong\n");
1130 }
Dennis Dalessandroe11ffbd2016-05-19 05:26:44 -07001131 kobject_init(&dd->kobj, &hfi1_devdata_type);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001132 return dd;
1133
1134bail:
1135 if (!list_empty(&dd->list))
1136 list_del_init(&dd->list);
Jubin Johnea0e4ce2016-04-20 06:05:24 -07001137 rvt_dealloc_device(&dd->verbs_dev.rdi);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001138 return ERR_PTR(ret);
1139}
1140
1141/*
1142 * Called from freeze mode handlers, and from PCI error
1143 * reporting code. Should be paranoid about state of
1144 * system and data structures.
1145 */
1146void hfi1_disable_after_error(struct hfi1_devdata *dd)
1147{
1148 if (dd->flags & HFI1_INITTED) {
1149 u32 pidx;
1150
1151 dd->flags &= ~HFI1_INITTED;
1152 if (dd->pport)
1153 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
1154 struct hfi1_pportdata *ppd;
1155
1156 ppd = dd->pport + pidx;
1157 if (dd->flags & HFI1_PRESENT)
1158 set_link_state(ppd, HLS_DN_DISABLE);
1159
1160 if (ppd->statusp)
1161 *ppd->statusp &= ~HFI1_STATUS_IB_READY;
1162 }
1163 }
1164
1165 /*
1166 * Mark as having had an error for driver, and also
1167 * for /sys and status word mapped to user programs.
1168 * This marks unit as not usable, until reset.
1169 */
1170 if (dd->status)
1171 dd->status->dev |= HFI1_STATUS_HWERROR;
1172}
1173
1174static void remove_one(struct pci_dev *);
1175static int init_one(struct pci_dev *, const struct pci_device_id *);
1176
1177#define DRIVER_LOAD_MSG "Intel " DRIVER_NAME " loaded: "
1178#define PFX DRIVER_NAME ": "
1179
Sebastian Sanchezd6373012016-07-25 07:54:48 -07001180const struct pci_device_id hfi1_pci_tbl[] = {
Mike Marciniszyn77241052015-07-30 15:17:43 -04001181 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL0) },
1182 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL1) },
1183 { 0, }
1184};
1185
1186MODULE_DEVICE_TABLE(pci, hfi1_pci_tbl);
1187
1188static struct pci_driver hfi1_pci_driver = {
1189 .name = DRIVER_NAME,
1190 .probe = init_one,
1191 .remove = remove_one,
1192 .id_table = hfi1_pci_tbl,
1193 .err_handler = &hfi1_pci_err_handler,
1194};
1195
1196static void __init compute_krcvqs(void)
1197{
1198 int i;
1199
1200 for (i = 0; i < krcvqsset; i++)
1201 n_krcvqs += krcvqs[i];
1202}
1203
1204/*
1205 * Do all the generic driver unit- and chip-independent memory
1206 * allocation and initialization.
1207 */
1208static int __init hfi1_mod_init(void)
1209{
1210 int ret;
1211
1212 ret = dev_init();
1213 if (ret)
1214 goto bail;
1215
Sebastian Sanchezd6373012016-07-25 07:54:48 -07001216 ret = node_affinity_init();
1217 if (ret)
1218 goto bail;
Dennis Dalessandro41973442016-07-25 07:52:36 -07001219
Mike Marciniszyn77241052015-07-30 15:17:43 -04001220 /* validate max MTU before any devices start */
1221 if (!valid_opa_max_mtu(hfi1_max_mtu)) {
1222 pr_err("Invalid max_mtu 0x%x, using 0x%x instead\n",
1223 hfi1_max_mtu, HFI1_DEFAULT_MAX_MTU);
1224 hfi1_max_mtu = HFI1_DEFAULT_MAX_MTU;
1225 }
1226 /* valid CUs run from 1-128 in powers of 2 */
1227 if (hfi1_cu > 128 || !is_power_of_2(hfi1_cu))
1228 hfi1_cu = 1;
1229 /* valid credit return threshold is 0-100, variable is unsigned */
1230 if (user_credit_return_threshold > 100)
1231 user_credit_return_threshold = 100;
1232
1233 compute_krcvqs();
Jubin John4d114fd2016-02-14 20:21:43 -08001234 /*
1235 * sanitize receive interrupt count, time must wait until after
1236 * the hardware type is known
1237 */
Mike Marciniszyn77241052015-07-30 15:17:43 -04001238 if (rcv_intr_count > RCV_HDR_HEAD_COUNTER_MASK)
1239 rcv_intr_count = RCV_HDR_HEAD_COUNTER_MASK;
1240 /* reject invalid combinations */
1241 if (rcv_intr_count == 0 && rcv_intr_timeout == 0) {
1242 pr_err("Invalid mode: both receive interrupt count and available timeout are zero - setting interrupt count to 1\n");
1243 rcv_intr_count = 1;
1244 }
1245 if (rcv_intr_count > 1 && rcv_intr_timeout == 0) {
1246 /*
1247 * Avoid indefinite packet delivery by requiring a timeout
1248 * if count is > 1.
1249 */
1250 pr_err("Invalid mode: receive interrupt count greater than 1 and available timeout is zero - setting available timeout to 1\n");
1251 rcv_intr_timeout = 1;
1252 }
1253 if (rcv_intr_dynamic && !(rcv_intr_count > 1 && rcv_intr_timeout > 0)) {
1254 /*
1255 * The dynamic algorithm expects a non-zero timeout
1256 * and a count > 1.
1257 */
1258 pr_err("Invalid mode: dynamic receive interrupt mitigation with invalid count and timeout - turning dynamic off\n");
1259 rcv_intr_dynamic = 0;
1260 }
1261
1262 /* sanitize link CRC options */
1263 link_crc_mask &= SUPPORTED_CRCS;
1264
1265 /*
1266 * These must be called before the driver is registered with
1267 * the PCI subsystem.
1268 */
1269 idr_init(&hfi1_unit_table);
1270
1271 hfi1_dbg_init();
Dean Luick528ee9f2016-03-05 08:50:43 -08001272 ret = hfi1_wss_init();
1273 if (ret < 0)
1274 goto bail_wss;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001275 ret = pci_register_driver(&hfi1_pci_driver);
1276 if (ret < 0) {
1277 pr_err("Unable to register driver: error %d\n", -ret);
1278 goto bail_dev;
1279 }
1280 goto bail; /* all OK */
1281
1282bail_dev:
Dean Luick528ee9f2016-03-05 08:50:43 -08001283 hfi1_wss_exit();
1284bail_wss:
Mike Marciniszyn77241052015-07-30 15:17:43 -04001285 hfi1_dbg_exit();
1286 idr_destroy(&hfi1_unit_table);
1287 dev_cleanup();
1288bail:
1289 return ret;
1290}
1291
1292module_init(hfi1_mod_init);
1293
1294/*
1295 * Do the non-unit driver cleanup, memory free, etc. at unload.
1296 */
1297static void __exit hfi1_mod_cleanup(void)
1298{
1299 pci_unregister_driver(&hfi1_pci_driver);
Dennis Dalessandro41973442016-07-25 07:52:36 -07001300 node_affinity_destroy();
Dean Luick528ee9f2016-03-05 08:50:43 -08001301 hfi1_wss_exit();
Mike Marciniszyn77241052015-07-30 15:17:43 -04001302 hfi1_dbg_exit();
1303 hfi1_cpulist_count = 0;
1304 kfree(hfi1_cpulist);
1305
1306 idr_destroy(&hfi1_unit_table);
1307 dispose_firmware(); /* asymmetric with obtain_firmware() */
1308 dev_cleanup();
1309}
1310
1311module_exit(hfi1_mod_cleanup);
1312
1313/* this can only be called after a successful initialization */
1314static void cleanup_device_data(struct hfi1_devdata *dd)
1315{
1316 int ctxt;
1317 int pidx;
1318 struct hfi1_ctxtdata **tmp;
1319 unsigned long flags;
1320
1321 /* users can't do anything more with chip */
1322 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
1323 struct hfi1_pportdata *ppd = &dd->pport[pidx];
1324 struct cc_state *cc_state;
1325 int i;
1326
1327 if (ppd->statusp)
1328 *ppd->statusp &= ~HFI1_STATUS_CHIP_PRESENT;
1329
1330 for (i = 0; i < OPA_MAX_SLS; i++)
1331 hrtimer_cancel(&ppd->cca_timer[i].hrtimer);
1332
1333 spin_lock(&ppd->cc_state_lock);
Jianxin Xiong8adf71f2016-07-25 13:39:14 -07001334 cc_state = get_cc_state_protected(ppd);
Muhammad Falak R Wanieea57072016-05-01 18:05:31 +05301335 RCU_INIT_POINTER(ppd->cc_state, NULL);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001336 spin_unlock(&ppd->cc_state_lock);
1337
1338 if (cc_state)
Wei Yongjun476d95b2016-08-10 03:14:04 +00001339 kfree_rcu(cc_state, rcu);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001340 }
1341
1342 free_credit_return(dd);
1343
1344 /*
1345 * Free any resources still in use (usually just kernel contexts)
1346 * at unload; we do for ctxtcnt, because that's what we allocate.
1347 * We acquire lock to be really paranoid that rcd isn't being
1348 * accessed from some interrupt-related code (that should not happen,
1349 * but best to be sure).
1350 */
1351 spin_lock_irqsave(&dd->uctxt_lock, flags);
1352 tmp = dd->rcd;
1353 dd->rcd = NULL;
1354 spin_unlock_irqrestore(&dd->uctxt_lock, flags);
Mark F. Brown46b010d2015-11-09 19:18:20 -05001355
1356 if (dd->rcvhdrtail_dummy_kvaddr) {
1357 dma_free_coherent(&dd->pcidev->dev, sizeof(u64),
1358 (void *)dd->rcvhdrtail_dummy_kvaddr,
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001359 dd->rcvhdrtail_dummy_dma);
Dan Carpentera8b7da52016-05-28 08:01:20 +03001360 dd->rcvhdrtail_dummy_kvaddr = NULL;
Mark F. Brown46b010d2015-11-09 19:18:20 -05001361 }
1362
Mike Marciniszyn77241052015-07-30 15:17:43 -04001363 for (ctxt = 0; tmp && ctxt < dd->num_rcv_contexts; ctxt++) {
1364 struct hfi1_ctxtdata *rcd = tmp[ctxt];
1365
1366 tmp[ctxt] = NULL; /* debugging paranoia */
1367 if (rcd) {
1368 hfi1_clear_tids(rcd);
1369 hfi1_free_ctxtdata(dd, rcd);
1370 }
1371 }
1372 kfree(tmp);
Jubin John35f6bef2016-02-14 12:46:10 -08001373 free_pio_map(dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001374 /* must follow rcv context free - need to remove rcv's hooks */
1375 for (ctxt = 0; ctxt < dd->num_send_contexts; ctxt++)
1376 sc_free(dd->send_contexts[ctxt].sc);
1377 dd->num_send_contexts = 0;
1378 kfree(dd->send_contexts);
1379 dd->send_contexts = NULL;
Jubin John79d0c082016-02-26 13:33:33 -08001380 kfree(dd->hw_to_sw);
1381 dd->hw_to_sw = NULL;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001382 kfree(dd->boardname);
1383 vfree(dd->events);
1384 vfree(dd->status);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001385}
1386
1387/*
1388 * Clean up on unit shutdown, or error during unit load after
1389 * successful initialization.
1390 */
1391static void postinit_cleanup(struct hfi1_devdata *dd)
1392{
1393 hfi1_start_cleanup(dd);
1394
1395 hfi1_pcie_ddcleanup(dd);
1396 hfi1_pcie_cleanup(dd->pcidev);
1397
1398 cleanup_device_data(dd);
1399
1400 hfi1_free_devdata(dd);
1401}
1402
Krzysztof Blaszkowski11501ab2016-10-25 13:12:11 -07001403static int init_validate_rcvhdrcnt(struct device *dev, uint thecnt)
1404{
1405 if (thecnt <= HFI1_MIN_HDRQ_EGRBUF_CNT) {
1406 hfi1_early_err(dev, "Receive header queue count too small\n");
1407 return -EINVAL;
1408 }
1409
1410 if (thecnt > HFI1_MAX_HDRQ_EGRBUF_CNT) {
1411 hfi1_early_err(dev,
1412 "Receive header queue count cannot be greater than %u\n",
1413 HFI1_MAX_HDRQ_EGRBUF_CNT);
1414 return -EINVAL;
1415 }
1416
1417 if (thecnt % HDRQ_INCREMENT) {
1418 hfi1_early_err(dev, "Receive header queue count %d must be divisible by %lu\n",
1419 thecnt, HDRQ_INCREMENT);
1420 return -EINVAL;
1421 }
1422
1423 return 0;
1424}
1425
Mike Marciniszyn77241052015-07-30 15:17:43 -04001426static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1427{
1428 int ret = 0, j, pidx, initfail;
Krzysztof Blaszkowski83fb4af2016-10-17 04:19:24 -07001429 struct hfi1_devdata *dd;
Harish Chegondie8597eb2015-12-01 15:38:20 -05001430 struct hfi1_pportdata *ppd;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001431
1432 /* First, lock the non-writable module parameters */
1433 HFI1_CAP_LOCK();
1434
Tadeusz Struk5d6f08a2017-03-20 17:25:29 -07001435 /* Validate dev ids */
1436 if (!(ent->device == PCI_DEVICE_ID_INTEL0 ||
1437 ent->device == PCI_DEVICE_ID_INTEL1)) {
1438 hfi1_early_err(&pdev->dev,
1439 "Failing on unknown Intel deviceid 0x%x\n",
1440 ent->device);
1441 ret = -ENODEV;
1442 goto bail;
1443 }
1444
Mike Marciniszyn77241052015-07-30 15:17:43 -04001445 /* Validate some global module parameters */
Krzysztof Blaszkowski11501ab2016-10-25 13:12:11 -07001446 ret = init_validate_rcvhdrcnt(&pdev->dev, rcvhdrcnt);
1447 if (ret)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001448 goto bail;
Krzysztof Blaszkowski11501ab2016-10-25 13:12:11 -07001449
Mike Marciniszyn77241052015-07-30 15:17:43 -04001450 /* use the encoding function as a sanitization check */
1451 if (!encode_rcv_header_entry_size(hfi1_hdrq_entsize)) {
1452 hfi1_early_err(&pdev->dev, "Invalid HdrQ Entry size %u\n",
1453 hfi1_hdrq_entsize);
Sebastian Sanchez07859de2015-12-10 16:02:49 -05001454 ret = -EINVAL;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001455 goto bail;
1456 }
1457
1458 /* The receive eager buffer size must be set before the receive
1459 * contexts are created.
1460 *
1461 * Set the eager buffer size. Validate that it falls in a range
1462 * allowed by the hardware - all powers of 2 between the min and
1463 * max. The maximum valid MTU is within the eager buffer range
1464 * so we do not need to cap the max_mtu by an eager buffer size
1465 * setting.
1466 */
1467 if (eager_buffer_size) {
1468 if (!is_power_of_2(eager_buffer_size))
1469 eager_buffer_size =
1470 roundup_pow_of_two(eager_buffer_size);
1471 eager_buffer_size =
1472 clamp_val(eager_buffer_size,
1473 MIN_EAGER_BUFFER * 8,
1474 MAX_EAGER_BUFFER_TOTAL);
1475 hfi1_early_info(&pdev->dev, "Eager buffer size %u\n",
1476 eager_buffer_size);
1477 } else {
1478 hfi1_early_err(&pdev->dev, "Invalid Eager buffer size of 0\n");
1479 ret = -EINVAL;
1480 goto bail;
1481 }
1482
1483 /* restrict value of hfi1_rcvarr_split */
1484 hfi1_rcvarr_split = clamp_val(hfi1_rcvarr_split, 0, 100);
1485
1486 ret = hfi1_pcie_init(pdev, ent);
1487 if (ret)
1488 goto bail;
1489
Krzysztof Blaszkowski83fb4af2016-10-17 04:19:24 -07001490 /*
1491 * Do device-specific initialization, function table setup, dd
1492 * allocation, etc.
1493 */
1494 dd = hfi1_init_dd(pdev, ent);
1495
1496 if (IS_ERR(dd)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04001497 ret = PTR_ERR(dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001498 goto clean_bail; /* error already printed */
Krzysztof Blaszkowski83fb4af2016-10-17 04:19:24 -07001499 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04001500
1501 ret = create_workqueues(dd);
1502 if (ret)
1503 goto clean_bail;
1504
1505 /* do the generic initialization */
1506 initfail = hfi1_init(dd, 0);
1507
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -07001508 /* setup vnic */
1509 hfi1_vnic_setup(dd);
1510
Mike Marciniszyn77241052015-07-30 15:17:43 -04001511 ret = hfi1_register_ib_device(dd);
1512
1513 /*
1514 * Now ready for use. this should be cleared whenever we
1515 * detect a reset, or initiate one. If earlier failure,
1516 * we still create devices, so diags, etc. can be used
1517 * to determine cause of problem.
1518 */
Dean Luicked6f6532016-02-18 11:12:25 -08001519 if (!initfail && !ret) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04001520 dd->flags |= HFI1_INITTED;
Dean Luicked6f6532016-02-18 11:12:25 -08001521 /* create debufs files after init and ib register */
1522 hfi1_dbg_ibdev_init(&dd->verbs_dev);
1523 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04001524
1525 j = hfi1_device_create(dd);
1526 if (j)
1527 dd_dev_err(dd, "Failed to create /dev devices: %d\n", -j);
1528
1529 if (initfail || ret) {
1530 stop_timers(dd);
1531 flush_workqueue(ib_wq);
Harish Chegondie8597eb2015-12-01 15:38:20 -05001532 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04001533 hfi1_quiet_serdes(dd->pport + pidx);
Harish Chegondie8597eb2015-12-01 15:38:20 -05001534 ppd = dd->pport + pidx;
1535 if (ppd->hfi1_wq) {
1536 destroy_workqueue(ppd->hfi1_wq);
1537 ppd->hfi1_wq = NULL;
1538 }
1539 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04001540 if (!j)
1541 hfi1_device_remove(dd);
1542 if (!ret)
1543 hfi1_unregister_ib_device(dd);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07001544 hfi1_vnic_cleanup(dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001545 postinit_cleanup(dd);
1546 if (initfail)
1547 ret = initfail;
1548 goto bail; /* everything already cleaned */
1549 }
1550
1551 sdma_start(dd);
1552
1553 return 0;
1554
1555clean_bail:
1556 hfi1_pcie_cleanup(pdev);
1557bail:
1558 return ret;
1559}
1560
Tadeusz Strukacd7c8f2016-10-25 08:57:55 -07001561static void wait_for_clients(struct hfi1_devdata *dd)
1562{
1563 /*
1564 * Remove the device init value and complete the device if there is
1565 * no clients or wait for active clients to finish.
1566 */
1567 if (atomic_dec_and_test(&dd->user_refcount))
1568 complete(&dd->user_comp);
1569
1570 wait_for_completion(&dd->user_comp);
1571}
1572
Mike Marciniszyn77241052015-07-30 15:17:43 -04001573static void remove_one(struct pci_dev *pdev)
1574{
1575 struct hfi1_devdata *dd = pci_get_drvdata(pdev);
1576
Dean Luicked6f6532016-02-18 11:12:25 -08001577 /* close debugfs files before ib unregister */
1578 hfi1_dbg_ibdev_exit(&dd->verbs_dev);
Tadeusz Strukacd7c8f2016-10-25 08:57:55 -07001579
1580 /* remove the /dev hfi1 interface */
1581 hfi1_device_remove(dd);
1582
1583 /* wait for existing user space clients to finish */
1584 wait_for_clients(dd);
1585
Mike Marciniszyn77241052015-07-30 15:17:43 -04001586 /* unregister from IB core */
1587 hfi1_unregister_ib_device(dd);
1588
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -07001589 /* cleanup vnic */
1590 hfi1_vnic_cleanup(dd);
1591
Mike Marciniszyn77241052015-07-30 15:17:43 -04001592 /*
1593 * Disable the IB link, disable interrupts on the device,
1594 * clear dma engines, etc.
1595 */
1596 shutdown_device(dd);
1597
1598 stop_timers(dd);
1599
1600 /* wait until all of our (qsfp) queue_work() calls complete */
1601 flush_workqueue(ib_wq);
1602
Mike Marciniszyn77241052015-07-30 15:17:43 -04001603 postinit_cleanup(dd);
1604}
1605
1606/**
1607 * hfi1_create_rcvhdrq - create a receive header queue
1608 * @dd: the hfi1_ib device
1609 * @rcd: the context data
1610 *
1611 * This must be contiguous memory (from an i/o perspective), and must be
1612 * DMA'able (which means for some systems, it will go through an IOMMU,
1613 * or be forced into a low address range).
1614 */
1615int hfi1_create_rcvhdrq(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd)
1616{
1617 unsigned amt;
1618 u64 reg;
1619
1620 if (!rcd->rcvhdrq) {
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001621 dma_addr_t dma_hdrqtail;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001622 gfp_t gfp_flags;
1623
1624 /*
1625 * rcvhdrqentsize is in DWs, so we have to convert to bytes
1626 * (* sizeof(u32)).
1627 */
Amitoj Kaur Chawla84449912016-03-04 22:30:43 +05301628 amt = PAGE_ALIGN(rcd->rcvhdrq_cnt * rcd->rcvhdrqentsize *
1629 sizeof(u32));
Mike Marciniszyn77241052015-07-30 15:17:43 -04001630
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07001631 if ((rcd->ctxt < dd->first_dyn_alloc_ctxt) ||
1632 (rcd->sc && (rcd->sc->type == SC_KERNEL)))
1633 gfp_flags = GFP_KERNEL;
1634 else
1635 gfp_flags = GFP_USER;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001636 rcd->rcvhdrq = dma_zalloc_coherent(
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001637 &dd->pcidev->dev, amt, &rcd->rcvhdrq_dma,
Mike Marciniszyn77241052015-07-30 15:17:43 -04001638 gfp_flags | __GFP_COMP);
1639
1640 if (!rcd->rcvhdrq) {
1641 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08001642 "attempt to allocate %d bytes for ctxt %u rcvhdrq failed\n",
1643 amt, rcd->ctxt);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001644 goto bail;
1645 }
1646
Mike Marciniszyn77241052015-07-30 15:17:43 -04001647 if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) {
1648 rcd->rcvhdrtail_kvaddr = dma_zalloc_coherent(
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001649 &dd->pcidev->dev, PAGE_SIZE, &dma_hdrqtail,
Mike Marciniszyn77241052015-07-30 15:17:43 -04001650 gfp_flags);
1651 if (!rcd->rcvhdrtail_kvaddr)
1652 goto bail_free;
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001653 rcd->rcvhdrqtailaddr_dma = dma_hdrqtail;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001654 }
1655
1656 rcd->rcvhdrq_size = amt;
1657 }
1658 /*
1659 * These values are per-context:
1660 * RcvHdrCnt
1661 * RcvHdrEntSize
1662 * RcvHdrSize
1663 */
1664 reg = ((u64)(rcd->rcvhdrq_cnt >> HDRQ_SIZE_SHIFT)
1665 & RCV_HDR_CNT_CNT_MASK)
1666 << RCV_HDR_CNT_CNT_SHIFT;
1667 write_kctxt_csr(dd, rcd->ctxt, RCV_HDR_CNT, reg);
1668 reg = (encode_rcv_header_entry_size(rcd->rcvhdrqentsize)
1669 & RCV_HDR_ENT_SIZE_ENT_SIZE_MASK)
1670 << RCV_HDR_ENT_SIZE_ENT_SIZE_SHIFT;
1671 write_kctxt_csr(dd, rcd->ctxt, RCV_HDR_ENT_SIZE, reg);
1672 reg = (dd->rcvhdrsize & RCV_HDR_SIZE_HDR_SIZE_MASK)
1673 << RCV_HDR_SIZE_HDR_SIZE_SHIFT;
1674 write_kctxt_csr(dd, rcd->ctxt, RCV_HDR_SIZE, reg);
Mark F. Brown46b010d2015-11-09 19:18:20 -05001675
1676 /*
1677 * Program dummy tail address for every receive context
1678 * before enabling any receive context
1679 */
1680 write_kctxt_csr(dd, rcd->ctxt, RCV_HDR_TAIL_ADDR,
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001681 dd->rcvhdrtail_dummy_dma);
Mark F. Brown46b010d2015-11-09 19:18:20 -05001682
Mike Marciniszyn77241052015-07-30 15:17:43 -04001683 return 0;
1684
1685bail_free:
1686 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08001687 "attempt to allocate 1 page for ctxt %u rcvhdrqtailaddr failed\n",
1688 rcd->ctxt);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001689 dma_free_coherent(&dd->pcidev->dev, amt, rcd->rcvhdrq,
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001690 rcd->rcvhdrq_dma);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001691 rcd->rcvhdrq = NULL;
1692bail:
1693 return -ENOMEM;
1694}
1695
1696/**
1697 * allocate eager buffers, both kernel and user contexts.
1698 * @rcd: the context we are setting up.
1699 *
1700 * Allocate the eager TID buffers and program them into hip.
1701 * They are no longer completely contiguous, we do multiple allocation
1702 * calls. Otherwise we get the OOM code involved, by asking for too
1703 * much per call, with disastrous results on some kernels.
1704 */
1705int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd)
1706{
1707 struct hfi1_devdata *dd = rcd->dd;
1708 u32 max_entries, egrtop, alloced_bytes = 0, idx = 0;
1709 gfp_t gfp_flags;
1710 u16 order;
1711 int ret = 0;
1712 u16 round_mtu = roundup_pow_of_two(hfi1_max_mtu);
1713
1714 /*
1715 * GFP_USER, but without GFP_FS, so buffer cache can be
1716 * coalesced (we hope); otherwise, even at order 4,
1717 * heavy filesystem activity makes these fail, and we can
1718 * use compound pages.
1719 */
Mel Gorman71baba42015-11-06 16:28:28 -08001720 gfp_flags = __GFP_RECLAIM | __GFP_IO | __GFP_COMP;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001721
1722 /*
1723 * The minimum size of the eager buffers is a groups of MTU-sized
1724 * buffers.
1725 * The global eager_buffer_size parameter is checked against the
1726 * theoretical lower limit of the value. Here, we check against the
1727 * MTU.
1728 */
1729 if (rcd->egrbufs.size < (round_mtu * dd->rcv_entries.group_size))
1730 rcd->egrbufs.size = round_mtu * dd->rcv_entries.group_size;
1731 /*
1732 * If using one-pkt-per-egr-buffer, lower the eager buffer
1733 * size to the max MTU (page-aligned).
1734 */
1735 if (!HFI1_CAP_KGET_MASK(rcd->flags, MULTI_PKT_EGR))
1736 rcd->egrbufs.rcvtid_size = round_mtu;
1737
1738 /*
1739 * Eager buffers sizes of 1MB or less require smaller TID sizes
1740 * to satisfy the "multiple of 8 RcvArray entries" requirement.
1741 */
1742 if (rcd->egrbufs.size <= (1 << 20))
1743 rcd->egrbufs.rcvtid_size = max((unsigned long)round_mtu,
1744 rounddown_pow_of_two(rcd->egrbufs.size / 8));
1745
1746 while (alloced_bytes < rcd->egrbufs.size &&
1747 rcd->egrbufs.alloced < rcd->egrbufs.count) {
1748 rcd->egrbufs.buffers[idx].addr =
1749 dma_zalloc_coherent(&dd->pcidev->dev,
1750 rcd->egrbufs.rcvtid_size,
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001751 &rcd->egrbufs.buffers[idx].dma,
Mike Marciniszyn77241052015-07-30 15:17:43 -04001752 gfp_flags);
1753 if (rcd->egrbufs.buffers[idx].addr) {
1754 rcd->egrbufs.buffers[idx].len =
1755 rcd->egrbufs.rcvtid_size;
1756 rcd->egrbufs.rcvtids[rcd->egrbufs.alloced].addr =
1757 rcd->egrbufs.buffers[idx].addr;
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001758 rcd->egrbufs.rcvtids[rcd->egrbufs.alloced].dma =
1759 rcd->egrbufs.buffers[idx].dma;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001760 rcd->egrbufs.alloced++;
1761 alloced_bytes += rcd->egrbufs.rcvtid_size;
1762 idx++;
1763 } else {
1764 u32 new_size, i, j;
1765 u64 offset = 0;
1766
1767 /*
1768 * Fail the eager buffer allocation if:
1769 * - we are already using the lowest acceptable size
1770 * - we are using one-pkt-per-egr-buffer (this implies
1771 * that we are accepting only one size)
1772 */
1773 if (rcd->egrbufs.rcvtid_size == round_mtu ||
1774 !HFI1_CAP_KGET_MASK(rcd->flags, MULTI_PKT_EGR)) {
1775 dd_dev_err(dd, "ctxt%u: Failed to allocate eager buffers\n",
Jubin John17fb4f22016-02-14 20:21:52 -08001776 rcd->ctxt);
Michael J. Ruhl94679062017-05-04 05:14:28 -07001777 ret = -ENOMEM;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001778 goto bail_rcvegrbuf_phys;
1779 }
1780
1781 new_size = rcd->egrbufs.rcvtid_size / 2;
1782
1783 /*
1784 * If the first attempt to allocate memory failed, don't
1785 * fail everything but continue with the next lower
1786 * size.
1787 */
1788 if (idx == 0) {
1789 rcd->egrbufs.rcvtid_size = new_size;
1790 continue;
1791 }
1792
1793 /*
1794 * Re-partition already allocated buffers to a smaller
1795 * size.
1796 */
1797 rcd->egrbufs.alloced = 0;
1798 for (i = 0, j = 0, offset = 0; j < idx; i++) {
1799 if (i >= rcd->egrbufs.count)
1800 break;
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001801 rcd->egrbufs.rcvtids[i].dma =
1802 rcd->egrbufs.buffers[j].dma + offset;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001803 rcd->egrbufs.rcvtids[i].addr =
1804 rcd->egrbufs.buffers[j].addr + offset;
1805 rcd->egrbufs.alloced++;
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001806 if ((rcd->egrbufs.buffers[j].dma + offset +
Mike Marciniszyn77241052015-07-30 15:17:43 -04001807 new_size) ==
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001808 (rcd->egrbufs.buffers[j].dma +
Mike Marciniszyn77241052015-07-30 15:17:43 -04001809 rcd->egrbufs.buffers[j].len)) {
1810 j++;
1811 offset = 0;
Jubin Johne4909742016-02-14 20:22:00 -08001812 } else {
Mike Marciniszyn77241052015-07-30 15:17:43 -04001813 offset += new_size;
Jubin Johne4909742016-02-14 20:22:00 -08001814 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04001815 }
1816 rcd->egrbufs.rcvtid_size = new_size;
1817 }
1818 }
1819 rcd->egrbufs.numbufs = idx;
1820 rcd->egrbufs.size = alloced_bytes;
1821
Sebastian Sanchez6c63e422015-11-06 20:06:56 -05001822 hfi1_cdbg(PROC,
1823 "ctxt%u: Alloced %u rcv tid entries @ %uKB, total %zuKB\n",
Grzegorz Heldt23002d52016-07-25 13:39:33 -07001824 rcd->ctxt, rcd->egrbufs.alloced,
1825 rcd->egrbufs.rcvtid_size / 1024, rcd->egrbufs.size / 1024);
Sebastian Sanchez6c63e422015-11-06 20:06:56 -05001826
Mike Marciniszyn77241052015-07-30 15:17:43 -04001827 /*
1828 * Set the contexts rcv array head update threshold to the closest
1829 * power of 2 (so we can use a mask instead of modulo) below half
1830 * the allocated entries.
1831 */
1832 rcd->egrbufs.threshold =
1833 rounddown_pow_of_two(rcd->egrbufs.alloced / 2);
1834 /*
1835 * Compute the expected RcvArray entry base. This is done after
1836 * allocating the eager buffers in order to maximize the
1837 * expected RcvArray entries for the context.
1838 */
1839 max_entries = rcd->rcv_array_groups * dd->rcv_entries.group_size;
1840 egrtop = roundup(rcd->egrbufs.alloced, dd->rcv_entries.group_size);
1841 rcd->expected_count = max_entries - egrtop;
1842 if (rcd->expected_count > MAX_TID_PAIR_ENTRIES * 2)
1843 rcd->expected_count = MAX_TID_PAIR_ENTRIES * 2;
1844
1845 rcd->expected_base = rcd->eager_base + egrtop;
Sebastian Sanchez6c63e422015-11-06 20:06:56 -05001846 hfi1_cdbg(PROC, "ctxt%u: eager:%u, exp:%u, egrbase:%u, expbase:%u\n",
1847 rcd->ctxt, rcd->egrbufs.alloced, rcd->expected_count,
1848 rcd->eager_base, rcd->expected_base);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001849
1850 if (!hfi1_rcvbuf_validate(rcd->egrbufs.rcvtid_size, PT_EAGER, &order)) {
Sebastian Sanchez6c63e422015-11-06 20:06:56 -05001851 hfi1_cdbg(PROC,
1852 "ctxt%u: current Eager buffer size is invalid %u\n",
1853 rcd->ctxt, rcd->egrbufs.rcvtid_size);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001854 ret = -EINVAL;
Michael J. Ruhl62239fc2017-05-04 05:15:21 -07001855 goto bail_rcvegrbuf_phys;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001856 }
1857
1858 for (idx = 0; idx < rcd->egrbufs.alloced; idx++) {
1859 hfi1_put_tid(dd, rcd->eager_base + idx, PT_EAGER,
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001860 rcd->egrbufs.rcvtids[idx].dma, order);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001861 cond_resched();
1862 }
Michael J. Ruhl62239fc2017-05-04 05:15:21 -07001863
1864 return 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001865
1866bail_rcvegrbuf_phys:
1867 for (idx = 0; idx < rcd->egrbufs.alloced &&
Jubin John17fb4f22016-02-14 20:21:52 -08001868 rcd->egrbufs.buffers[idx].addr;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001869 idx++) {
1870 dma_free_coherent(&dd->pcidev->dev,
1871 rcd->egrbufs.buffers[idx].len,
1872 rcd->egrbufs.buffers[idx].addr,
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001873 rcd->egrbufs.buffers[idx].dma);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001874 rcd->egrbufs.buffers[idx].addr = NULL;
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001875 rcd->egrbufs.buffers[idx].dma = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001876 rcd->egrbufs.buffers[idx].len = 0;
1877 }
Michael J. Ruhl62239fc2017-05-04 05:15:21 -07001878
Mike Marciniszyn77241052015-07-30 15:17:43 -04001879 return ret;
1880}