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