blob: 7befba8fceb2510728d52d70edf9318243bfc641 [file] [log] [blame]
Mike Marciniszyn77241052015-07-30 15:17:43 -04001/*
Michael J. Ruhl5e6e94242017-03-20 17:25:48 -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/*
49 * This file contains all of the code that is specific to the HFI chip
50 */
51
52#include <linux/pci.h>
53#include <linux/delay.h>
54#include <linux/interrupt.h>
55#include <linux/module.h>
56
57#include "hfi.h"
58#include "trace.h"
59#include "mad.h"
60#include "pio.h"
61#include "sdma.h"
62#include "eprom.h"
Dean Luick5d9157a2015-11-16 21:59:34 -050063#include "efivar.h"
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -080064#include "platform.h"
Ashutosh Dixitaffa48d2016-02-03 14:33:06 -080065#include "aspm.h"
Dennis Dalessandro41973442016-07-25 07:52:36 -070066#include "affinity.h"
Don Hiatt243d9f42017-03-20 17:26:20 -070067#include "debugfs.h"
Mike Marciniszyn77241052015-07-30 15:17:43 -040068
69#define NUM_IB_PORTS 1
70
71uint kdeth_qp;
72module_param_named(kdeth_qp, kdeth_qp, uint, S_IRUGO);
73MODULE_PARM_DESC(kdeth_qp, "Set the KDETH queue pair prefix");
74
75uint num_vls = HFI1_MAX_VLS_SUPPORTED;
76module_param(num_vls, uint, S_IRUGO);
77MODULE_PARM_DESC(num_vls, "Set number of Virtual Lanes to use (1-8)");
78
79/*
80 * Default time to aggregate two 10K packets from the idle state
81 * (timer not running). The timer starts at the end of the first packet,
82 * so only the time for one 10K packet and header plus a bit extra is needed.
83 * 10 * 1024 + 64 header byte = 10304 byte
84 * 10304 byte / 12.5 GB/s = 824.32ns
85 */
86uint rcv_intr_timeout = (824 + 16); /* 16 is for coalescing interrupt */
87module_param(rcv_intr_timeout, uint, S_IRUGO);
88MODULE_PARM_DESC(rcv_intr_timeout, "Receive interrupt mitigation timeout in ns");
89
90uint rcv_intr_count = 16; /* same as qib */
91module_param(rcv_intr_count, uint, S_IRUGO);
92MODULE_PARM_DESC(rcv_intr_count, "Receive interrupt mitigation count");
93
94ushort link_crc_mask = SUPPORTED_CRCS;
95module_param(link_crc_mask, ushort, S_IRUGO);
96MODULE_PARM_DESC(link_crc_mask, "CRCs to use on the link");
97
98uint loopback;
99module_param_named(loopback, loopback, uint, S_IRUGO);
100MODULE_PARM_DESC(loopback, "Put into loopback mode (1 = serdes, 3 = external cable");
101
102/* Other driver tunables */
103uint rcv_intr_dynamic = 1; /* enable dynamic mode for rcv int mitigation*/
104static ushort crc_14b_sideband = 1;
105static uint use_flr = 1;
106uint quick_linkup; /* skip LNI */
107
108struct flag_table {
109 u64 flag; /* the flag */
110 char *str; /* description string */
111 u16 extra; /* extra information */
112 u16 unused0;
113 u32 unused1;
114};
115
116/* str must be a string constant */
117#define FLAG_ENTRY(str, extra, flag) {flag, str, extra}
118#define FLAG_ENTRY0(str, flag) {flag, str, 0}
119
120/* Send Error Consequences */
121#define SEC_WRITE_DROPPED 0x1
122#define SEC_PACKET_DROPPED 0x2
123#define SEC_SC_HALTED 0x4 /* per-context only */
124#define SEC_SPC_FREEZE 0x8 /* per-HFI only */
125
Harish Chegondi8784ac02016-07-25 13:38:50 -0700126#define DEFAULT_KRCVQS 2
Mike Marciniszyn77241052015-07-30 15:17:43 -0400127#define MIN_KERNEL_KCTXTS 2
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500128#define FIRST_KERNEL_KCTXT 1
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700129
130/*
131 * RSM instance allocation
132 * 0 - Verbs
133 * 1 - User Fecn Handling
134 * 2 - Vnic
135 */
136#define RSM_INS_VERBS 0
137#define RSM_INS_FECN 1
138#define RSM_INS_VNIC 2
Mike Marciniszyn77241052015-07-30 15:17:43 -0400139
140/* Bit offset into the GUID which carries HFI id information */
141#define GUID_HFI_INDEX_SHIFT 39
142
143/* extract the emulation revision */
144#define emulator_rev(dd) ((dd)->irev >> 8)
145/* parallel and serial emulation versions are 3 and 4 respectively */
146#define is_emulator_p(dd) ((((dd)->irev) & 0xf) == 3)
147#define is_emulator_s(dd) ((((dd)->irev) & 0xf) == 4)
148
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700149/* RSM fields for Verbs */
Mike Marciniszyn77241052015-07-30 15:17:43 -0400150/* packet type */
151#define IB_PACKET_TYPE 2ull
152#define QW_SHIFT 6ull
153/* QPN[7..1] */
154#define QPN_WIDTH 7ull
155
156/* LRH.BTH: QW 0, OFFSET 48 - for match */
157#define LRH_BTH_QW 0ull
158#define LRH_BTH_BIT_OFFSET 48ull
159#define LRH_BTH_OFFSET(off) ((LRH_BTH_QW << QW_SHIFT) | (off))
160#define LRH_BTH_MATCH_OFFSET LRH_BTH_OFFSET(LRH_BTH_BIT_OFFSET)
161#define LRH_BTH_SELECT
162#define LRH_BTH_MASK 3ull
163#define LRH_BTH_VALUE 2ull
164
165/* LRH.SC[3..0] QW 0, OFFSET 56 - for match */
166#define LRH_SC_QW 0ull
167#define LRH_SC_BIT_OFFSET 56ull
168#define LRH_SC_OFFSET(off) ((LRH_SC_QW << QW_SHIFT) | (off))
169#define LRH_SC_MATCH_OFFSET LRH_SC_OFFSET(LRH_SC_BIT_OFFSET)
170#define LRH_SC_MASK 128ull
171#define LRH_SC_VALUE 0ull
172
173/* SC[n..0] QW 0, OFFSET 60 - for select */
174#define LRH_SC_SELECT_OFFSET ((LRH_SC_QW << QW_SHIFT) | (60ull))
175
176/* QPN[m+n:1] QW 1, OFFSET 1 */
177#define QPN_SELECT_OFFSET ((1ull << QW_SHIFT) | (1ull))
178
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700179/* RSM fields for Vnic */
180/* L2_TYPE: QW 0, OFFSET 61 - for match */
181#define L2_TYPE_QW 0ull
182#define L2_TYPE_BIT_OFFSET 61ull
183#define L2_TYPE_OFFSET(off) ((L2_TYPE_QW << QW_SHIFT) | (off))
184#define L2_TYPE_MATCH_OFFSET L2_TYPE_OFFSET(L2_TYPE_BIT_OFFSET)
185#define L2_TYPE_MASK 3ull
186#define L2_16B_VALUE 2ull
187
188/* L4_TYPE QW 1, OFFSET 0 - for match */
189#define L4_TYPE_QW 1ull
190#define L4_TYPE_BIT_OFFSET 0ull
191#define L4_TYPE_OFFSET(off) ((L4_TYPE_QW << QW_SHIFT) | (off))
192#define L4_TYPE_MATCH_OFFSET L4_TYPE_OFFSET(L4_TYPE_BIT_OFFSET)
193#define L4_16B_TYPE_MASK 0xFFull
194#define L4_16B_ETH_VALUE 0x78ull
195
196/* 16B VESWID - for select */
197#define L4_16B_HDR_VESWID_OFFSET ((2 << QW_SHIFT) | (16ull))
198/* 16B ENTROPY - for select */
199#define L2_16B_ENTROPY_OFFSET ((1 << QW_SHIFT) | (32ull))
200
Mike Marciniszyn77241052015-07-30 15:17:43 -0400201/* defines to build power on SC2VL table */
202#define SC2VL_VAL( \
203 num, \
204 sc0, sc0val, \
205 sc1, sc1val, \
206 sc2, sc2val, \
207 sc3, sc3val, \
208 sc4, sc4val, \
209 sc5, sc5val, \
210 sc6, sc6val, \
211 sc7, sc7val) \
212( \
213 ((u64)(sc0val) << SEND_SC2VLT##num##_SC##sc0##_SHIFT) | \
214 ((u64)(sc1val) << SEND_SC2VLT##num##_SC##sc1##_SHIFT) | \
215 ((u64)(sc2val) << SEND_SC2VLT##num##_SC##sc2##_SHIFT) | \
216 ((u64)(sc3val) << SEND_SC2VLT##num##_SC##sc3##_SHIFT) | \
217 ((u64)(sc4val) << SEND_SC2VLT##num##_SC##sc4##_SHIFT) | \
218 ((u64)(sc5val) << SEND_SC2VLT##num##_SC##sc5##_SHIFT) | \
219 ((u64)(sc6val) << SEND_SC2VLT##num##_SC##sc6##_SHIFT) | \
220 ((u64)(sc7val) << SEND_SC2VLT##num##_SC##sc7##_SHIFT) \
221)
222
223#define DC_SC_VL_VAL( \
224 range, \
225 e0, e0val, \
226 e1, e1val, \
227 e2, e2val, \
228 e3, e3val, \
229 e4, e4val, \
230 e5, e5val, \
231 e6, e6val, \
232 e7, e7val, \
233 e8, e8val, \
234 e9, e9val, \
235 e10, e10val, \
236 e11, e11val, \
237 e12, e12val, \
238 e13, e13val, \
239 e14, e14val, \
240 e15, e15val) \
241( \
242 ((u64)(e0val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e0##_SHIFT) | \
243 ((u64)(e1val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e1##_SHIFT) | \
244 ((u64)(e2val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e2##_SHIFT) | \
245 ((u64)(e3val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e3##_SHIFT) | \
246 ((u64)(e4val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e4##_SHIFT) | \
247 ((u64)(e5val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e5##_SHIFT) | \
248 ((u64)(e6val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e6##_SHIFT) | \
249 ((u64)(e7val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e7##_SHIFT) | \
250 ((u64)(e8val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e8##_SHIFT) | \
251 ((u64)(e9val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e9##_SHIFT) | \
252 ((u64)(e10val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e10##_SHIFT) | \
253 ((u64)(e11val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e11##_SHIFT) | \
254 ((u64)(e12val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e12##_SHIFT) | \
255 ((u64)(e13val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e13##_SHIFT) | \
256 ((u64)(e14val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e14##_SHIFT) | \
257 ((u64)(e15val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e15##_SHIFT) \
258)
259
260/* all CceStatus sub-block freeze bits */
261#define ALL_FROZE (CCE_STATUS_SDMA_FROZE_SMASK \
262 | CCE_STATUS_RXE_FROZE_SMASK \
263 | CCE_STATUS_TXE_FROZE_SMASK \
264 | CCE_STATUS_TXE_PIO_FROZE_SMASK)
265/* all CceStatus sub-block TXE pause bits */
266#define ALL_TXE_PAUSE (CCE_STATUS_TXE_PIO_PAUSED_SMASK \
267 | CCE_STATUS_TXE_PAUSED_SMASK \
268 | CCE_STATUS_SDMA_PAUSED_SMASK)
269/* all CceStatus sub-block RXE pause bits */
270#define ALL_RXE_PAUSE CCE_STATUS_RXE_PAUSED_SMASK
271
Jakub Pawlak2b719042016-07-01 16:01:22 -0700272#define CNTR_MAX 0xFFFFFFFFFFFFFFFFULL
273#define CNTR_32BIT_MAX 0x00000000FFFFFFFF
274
Mike Marciniszyn77241052015-07-30 15:17:43 -0400275/*
276 * CCE Error flags.
277 */
278static struct flag_table cce_err_status_flags[] = {
279/* 0*/ FLAG_ENTRY0("CceCsrParityErr",
280 CCE_ERR_STATUS_CCE_CSR_PARITY_ERR_SMASK),
281/* 1*/ FLAG_ENTRY0("CceCsrReadBadAddrErr",
282 CCE_ERR_STATUS_CCE_CSR_READ_BAD_ADDR_ERR_SMASK),
283/* 2*/ FLAG_ENTRY0("CceCsrWriteBadAddrErr",
284 CCE_ERR_STATUS_CCE_CSR_WRITE_BAD_ADDR_ERR_SMASK),
285/* 3*/ FLAG_ENTRY0("CceTrgtAsyncFifoParityErr",
286 CCE_ERR_STATUS_CCE_TRGT_ASYNC_FIFO_PARITY_ERR_SMASK),
287/* 4*/ FLAG_ENTRY0("CceTrgtAccessErr",
288 CCE_ERR_STATUS_CCE_TRGT_ACCESS_ERR_SMASK),
289/* 5*/ FLAG_ENTRY0("CceRspdDataParityErr",
290 CCE_ERR_STATUS_CCE_RSPD_DATA_PARITY_ERR_SMASK),
291/* 6*/ FLAG_ENTRY0("CceCli0AsyncFifoParityErr",
292 CCE_ERR_STATUS_CCE_CLI0_ASYNC_FIFO_PARITY_ERR_SMASK),
293/* 7*/ FLAG_ENTRY0("CceCsrCfgBusParityErr",
294 CCE_ERR_STATUS_CCE_CSR_CFG_BUS_PARITY_ERR_SMASK),
295/* 8*/ FLAG_ENTRY0("CceCli2AsyncFifoParityErr",
296 CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK),
297/* 9*/ FLAG_ENTRY0("CceCli1AsyncFifoPioCrdtParityErr",
298 CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_PIO_CRDT_PARITY_ERR_SMASK),
299/*10*/ FLAG_ENTRY0("CceCli1AsyncFifoPioCrdtParityErr",
300 CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_SDMA_HD_PARITY_ERR_SMASK),
301/*11*/ FLAG_ENTRY0("CceCli1AsyncFifoRxdmaParityError",
302 CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_RXDMA_PARITY_ERROR_SMASK),
303/*12*/ FLAG_ENTRY0("CceCli1AsyncFifoDbgParityError",
304 CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_DBG_PARITY_ERROR_SMASK),
305/*13*/ FLAG_ENTRY0("PcicRetryMemCorErr",
306 CCE_ERR_STATUS_PCIC_RETRY_MEM_COR_ERR_SMASK),
307/*14*/ FLAG_ENTRY0("PcicRetryMemCorErr",
308 CCE_ERR_STATUS_PCIC_RETRY_SOT_MEM_COR_ERR_SMASK),
309/*15*/ FLAG_ENTRY0("PcicPostHdQCorErr",
310 CCE_ERR_STATUS_PCIC_POST_HD_QCOR_ERR_SMASK),
311/*16*/ FLAG_ENTRY0("PcicPostHdQCorErr",
312 CCE_ERR_STATUS_PCIC_POST_DAT_QCOR_ERR_SMASK),
313/*17*/ FLAG_ENTRY0("PcicPostHdQCorErr",
314 CCE_ERR_STATUS_PCIC_CPL_HD_QCOR_ERR_SMASK),
315/*18*/ FLAG_ENTRY0("PcicCplDatQCorErr",
316 CCE_ERR_STATUS_PCIC_CPL_DAT_QCOR_ERR_SMASK),
317/*19*/ FLAG_ENTRY0("PcicNPostHQParityErr",
318 CCE_ERR_STATUS_PCIC_NPOST_HQ_PARITY_ERR_SMASK),
319/*20*/ FLAG_ENTRY0("PcicNPostDatQParityErr",
320 CCE_ERR_STATUS_PCIC_NPOST_DAT_QPARITY_ERR_SMASK),
321/*21*/ FLAG_ENTRY0("PcicRetryMemUncErr",
322 CCE_ERR_STATUS_PCIC_RETRY_MEM_UNC_ERR_SMASK),
323/*22*/ FLAG_ENTRY0("PcicRetrySotMemUncErr",
324 CCE_ERR_STATUS_PCIC_RETRY_SOT_MEM_UNC_ERR_SMASK),
325/*23*/ FLAG_ENTRY0("PcicPostHdQUncErr",
326 CCE_ERR_STATUS_PCIC_POST_HD_QUNC_ERR_SMASK),
327/*24*/ FLAG_ENTRY0("PcicPostDatQUncErr",
328 CCE_ERR_STATUS_PCIC_POST_DAT_QUNC_ERR_SMASK),
329/*25*/ FLAG_ENTRY0("PcicCplHdQUncErr",
330 CCE_ERR_STATUS_PCIC_CPL_HD_QUNC_ERR_SMASK),
331/*26*/ FLAG_ENTRY0("PcicCplDatQUncErr",
332 CCE_ERR_STATUS_PCIC_CPL_DAT_QUNC_ERR_SMASK),
333/*27*/ FLAG_ENTRY0("PcicTransmitFrontParityErr",
334 CCE_ERR_STATUS_PCIC_TRANSMIT_FRONT_PARITY_ERR_SMASK),
335/*28*/ FLAG_ENTRY0("PcicTransmitBackParityErr",
336 CCE_ERR_STATUS_PCIC_TRANSMIT_BACK_PARITY_ERR_SMASK),
337/*29*/ FLAG_ENTRY0("PcicReceiveParityErr",
338 CCE_ERR_STATUS_PCIC_RECEIVE_PARITY_ERR_SMASK),
339/*30*/ FLAG_ENTRY0("CceTrgtCplTimeoutErr",
340 CCE_ERR_STATUS_CCE_TRGT_CPL_TIMEOUT_ERR_SMASK),
341/*31*/ FLAG_ENTRY0("LATriggered",
342 CCE_ERR_STATUS_LA_TRIGGERED_SMASK),
343/*32*/ FLAG_ENTRY0("CceSegReadBadAddrErr",
344 CCE_ERR_STATUS_CCE_SEG_READ_BAD_ADDR_ERR_SMASK),
345/*33*/ FLAG_ENTRY0("CceSegWriteBadAddrErr",
346 CCE_ERR_STATUS_CCE_SEG_WRITE_BAD_ADDR_ERR_SMASK),
347/*34*/ FLAG_ENTRY0("CceRcplAsyncFifoParityErr",
348 CCE_ERR_STATUS_CCE_RCPL_ASYNC_FIFO_PARITY_ERR_SMASK),
349/*35*/ FLAG_ENTRY0("CceRxdmaConvFifoParityErr",
350 CCE_ERR_STATUS_CCE_RXDMA_CONV_FIFO_PARITY_ERR_SMASK),
351/*36*/ FLAG_ENTRY0("CceMsixTableCorErr",
352 CCE_ERR_STATUS_CCE_MSIX_TABLE_COR_ERR_SMASK),
353/*37*/ FLAG_ENTRY0("CceMsixTableUncErr",
354 CCE_ERR_STATUS_CCE_MSIX_TABLE_UNC_ERR_SMASK),
355/*38*/ FLAG_ENTRY0("CceIntMapCorErr",
356 CCE_ERR_STATUS_CCE_INT_MAP_COR_ERR_SMASK),
357/*39*/ FLAG_ENTRY0("CceIntMapUncErr",
358 CCE_ERR_STATUS_CCE_INT_MAP_UNC_ERR_SMASK),
359/*40*/ FLAG_ENTRY0("CceMsixCsrParityErr",
360 CCE_ERR_STATUS_CCE_MSIX_CSR_PARITY_ERR_SMASK),
361/*41-63 reserved*/
362};
363
364/*
365 * Misc Error flags
366 */
367#define MES(text) MISC_ERR_STATUS_MISC_##text##_ERR_SMASK
368static struct flag_table misc_err_status_flags[] = {
369/* 0*/ FLAG_ENTRY0("CSR_PARITY", MES(CSR_PARITY)),
370/* 1*/ FLAG_ENTRY0("CSR_READ_BAD_ADDR", MES(CSR_READ_BAD_ADDR)),
371/* 2*/ FLAG_ENTRY0("CSR_WRITE_BAD_ADDR", MES(CSR_WRITE_BAD_ADDR)),
372/* 3*/ FLAG_ENTRY0("SBUS_WRITE_FAILED", MES(SBUS_WRITE_FAILED)),
373/* 4*/ FLAG_ENTRY0("KEY_MISMATCH", MES(KEY_MISMATCH)),
374/* 5*/ FLAG_ENTRY0("FW_AUTH_FAILED", MES(FW_AUTH_FAILED)),
375/* 6*/ FLAG_ENTRY0("EFUSE_CSR_PARITY", MES(EFUSE_CSR_PARITY)),
376/* 7*/ FLAG_ENTRY0("EFUSE_READ_BAD_ADDR", MES(EFUSE_READ_BAD_ADDR)),
377/* 8*/ FLAG_ENTRY0("EFUSE_WRITE", MES(EFUSE_WRITE)),
378/* 9*/ FLAG_ENTRY0("EFUSE_DONE_PARITY", MES(EFUSE_DONE_PARITY)),
379/*10*/ FLAG_ENTRY0("INVALID_EEP_CMD", MES(INVALID_EEP_CMD)),
380/*11*/ FLAG_ENTRY0("MBIST_FAIL", MES(MBIST_FAIL)),
381/*12*/ FLAG_ENTRY0("PLL_LOCK_FAIL", MES(PLL_LOCK_FAIL))
382};
383
384/*
385 * TXE PIO Error flags and consequences
386 */
387static struct flag_table pio_err_status_flags[] = {
388/* 0*/ FLAG_ENTRY("PioWriteBadCtxt",
389 SEC_WRITE_DROPPED,
390 SEND_PIO_ERR_STATUS_PIO_WRITE_BAD_CTXT_ERR_SMASK),
391/* 1*/ FLAG_ENTRY("PioWriteAddrParity",
392 SEC_SPC_FREEZE,
393 SEND_PIO_ERR_STATUS_PIO_WRITE_ADDR_PARITY_ERR_SMASK),
394/* 2*/ FLAG_ENTRY("PioCsrParity",
395 SEC_SPC_FREEZE,
396 SEND_PIO_ERR_STATUS_PIO_CSR_PARITY_ERR_SMASK),
397/* 3*/ FLAG_ENTRY("PioSbMemFifo0",
398 SEC_SPC_FREEZE,
399 SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO0_ERR_SMASK),
400/* 4*/ FLAG_ENTRY("PioSbMemFifo1",
401 SEC_SPC_FREEZE,
402 SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO1_ERR_SMASK),
403/* 5*/ FLAG_ENTRY("PioPccFifoParity",
404 SEC_SPC_FREEZE,
405 SEND_PIO_ERR_STATUS_PIO_PCC_FIFO_PARITY_ERR_SMASK),
406/* 6*/ FLAG_ENTRY("PioPecFifoParity",
407 SEC_SPC_FREEZE,
408 SEND_PIO_ERR_STATUS_PIO_PEC_FIFO_PARITY_ERR_SMASK),
409/* 7*/ FLAG_ENTRY("PioSbrdctlCrrelParity",
410 SEC_SPC_FREEZE,
411 SEND_PIO_ERR_STATUS_PIO_SBRDCTL_CRREL_PARITY_ERR_SMASK),
412/* 8*/ FLAG_ENTRY("PioSbrdctrlCrrelFifoParity",
413 SEC_SPC_FREEZE,
414 SEND_PIO_ERR_STATUS_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR_SMASK),
415/* 9*/ FLAG_ENTRY("PioPktEvictFifoParityErr",
416 SEC_SPC_FREEZE,
417 SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_FIFO_PARITY_ERR_SMASK),
418/*10*/ FLAG_ENTRY("PioSmPktResetParity",
419 SEC_SPC_FREEZE,
420 SEND_PIO_ERR_STATUS_PIO_SM_PKT_RESET_PARITY_ERR_SMASK),
421/*11*/ FLAG_ENTRY("PioVlLenMemBank0Unc",
422 SEC_SPC_FREEZE,
423 SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_UNC_ERR_SMASK),
424/*12*/ FLAG_ENTRY("PioVlLenMemBank1Unc",
425 SEC_SPC_FREEZE,
426 SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_UNC_ERR_SMASK),
427/*13*/ FLAG_ENTRY("PioVlLenMemBank0Cor",
428 0,
429 SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_COR_ERR_SMASK),
430/*14*/ FLAG_ENTRY("PioVlLenMemBank1Cor",
431 0,
432 SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_COR_ERR_SMASK),
433/*15*/ FLAG_ENTRY("PioCreditRetFifoParity",
434 SEC_SPC_FREEZE,
435 SEND_PIO_ERR_STATUS_PIO_CREDIT_RET_FIFO_PARITY_ERR_SMASK),
436/*16*/ FLAG_ENTRY("PioPpmcPblFifo",
437 SEC_SPC_FREEZE,
438 SEND_PIO_ERR_STATUS_PIO_PPMC_PBL_FIFO_ERR_SMASK),
439/*17*/ FLAG_ENTRY("PioInitSmIn",
440 0,
441 SEND_PIO_ERR_STATUS_PIO_INIT_SM_IN_ERR_SMASK),
442/*18*/ FLAG_ENTRY("PioPktEvictSmOrArbSm",
443 SEC_SPC_FREEZE,
444 SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_SM_OR_ARB_SM_ERR_SMASK),
445/*19*/ FLAG_ENTRY("PioHostAddrMemUnc",
446 SEC_SPC_FREEZE,
447 SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_UNC_ERR_SMASK),
448/*20*/ FLAG_ENTRY("PioHostAddrMemCor",
449 0,
450 SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_COR_ERR_SMASK),
451/*21*/ FLAG_ENTRY("PioWriteDataParity",
452 SEC_SPC_FREEZE,
453 SEND_PIO_ERR_STATUS_PIO_WRITE_DATA_PARITY_ERR_SMASK),
454/*22*/ FLAG_ENTRY("PioStateMachine",
455 SEC_SPC_FREEZE,
456 SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK),
457/*23*/ FLAG_ENTRY("PioWriteQwValidParity",
Jubin John8638b772016-02-14 20:19:24 -0800458 SEC_WRITE_DROPPED | SEC_SPC_FREEZE,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400459 SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK),
460/*24*/ FLAG_ENTRY("PioBlockQwCountParity",
Jubin John8638b772016-02-14 20:19:24 -0800461 SEC_WRITE_DROPPED | SEC_SPC_FREEZE,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400462 SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK),
463/*25*/ FLAG_ENTRY("PioVlfVlLenParity",
464 SEC_SPC_FREEZE,
465 SEND_PIO_ERR_STATUS_PIO_VLF_VL_LEN_PARITY_ERR_SMASK),
466/*26*/ FLAG_ENTRY("PioVlfSopParity",
467 SEC_SPC_FREEZE,
468 SEND_PIO_ERR_STATUS_PIO_VLF_SOP_PARITY_ERR_SMASK),
469/*27*/ FLAG_ENTRY("PioVlFifoParity",
470 SEC_SPC_FREEZE,
471 SEND_PIO_ERR_STATUS_PIO_VL_FIFO_PARITY_ERR_SMASK),
472/*28*/ FLAG_ENTRY("PioPpmcBqcMemParity",
473 SEC_SPC_FREEZE,
474 SEND_PIO_ERR_STATUS_PIO_PPMC_BQC_MEM_PARITY_ERR_SMASK),
475/*29*/ FLAG_ENTRY("PioPpmcSopLen",
476 SEC_SPC_FREEZE,
477 SEND_PIO_ERR_STATUS_PIO_PPMC_SOP_LEN_ERR_SMASK),
478/*30-31 reserved*/
479/*32*/ FLAG_ENTRY("PioCurrentFreeCntParity",
480 SEC_SPC_FREEZE,
481 SEND_PIO_ERR_STATUS_PIO_CURRENT_FREE_CNT_PARITY_ERR_SMASK),
482/*33*/ FLAG_ENTRY("PioLastReturnedCntParity",
483 SEC_SPC_FREEZE,
484 SEND_PIO_ERR_STATUS_PIO_LAST_RETURNED_CNT_PARITY_ERR_SMASK),
485/*34*/ FLAG_ENTRY("PioPccSopHeadParity",
486 SEC_SPC_FREEZE,
487 SEND_PIO_ERR_STATUS_PIO_PCC_SOP_HEAD_PARITY_ERR_SMASK),
488/*35*/ FLAG_ENTRY("PioPecSopHeadParityErr",
489 SEC_SPC_FREEZE,
490 SEND_PIO_ERR_STATUS_PIO_PEC_SOP_HEAD_PARITY_ERR_SMASK),
491/*36-63 reserved*/
492};
493
494/* TXE PIO errors that cause an SPC freeze */
495#define ALL_PIO_FREEZE_ERR \
496 (SEND_PIO_ERR_STATUS_PIO_WRITE_ADDR_PARITY_ERR_SMASK \
497 | SEND_PIO_ERR_STATUS_PIO_CSR_PARITY_ERR_SMASK \
498 | SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO0_ERR_SMASK \
499 | SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO1_ERR_SMASK \
500 | SEND_PIO_ERR_STATUS_PIO_PCC_FIFO_PARITY_ERR_SMASK \
501 | SEND_PIO_ERR_STATUS_PIO_PEC_FIFO_PARITY_ERR_SMASK \
502 | SEND_PIO_ERR_STATUS_PIO_SBRDCTL_CRREL_PARITY_ERR_SMASK \
503 | SEND_PIO_ERR_STATUS_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR_SMASK \
504 | SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_FIFO_PARITY_ERR_SMASK \
505 | SEND_PIO_ERR_STATUS_PIO_SM_PKT_RESET_PARITY_ERR_SMASK \
506 | SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_UNC_ERR_SMASK \
507 | SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_UNC_ERR_SMASK \
508 | SEND_PIO_ERR_STATUS_PIO_CREDIT_RET_FIFO_PARITY_ERR_SMASK \
509 | SEND_PIO_ERR_STATUS_PIO_PPMC_PBL_FIFO_ERR_SMASK \
510 | SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_SM_OR_ARB_SM_ERR_SMASK \
511 | SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_UNC_ERR_SMASK \
512 | SEND_PIO_ERR_STATUS_PIO_WRITE_DATA_PARITY_ERR_SMASK \
513 | SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK \
514 | SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK \
515 | SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK \
516 | SEND_PIO_ERR_STATUS_PIO_VLF_VL_LEN_PARITY_ERR_SMASK \
517 | SEND_PIO_ERR_STATUS_PIO_VLF_SOP_PARITY_ERR_SMASK \
518 | SEND_PIO_ERR_STATUS_PIO_VL_FIFO_PARITY_ERR_SMASK \
519 | SEND_PIO_ERR_STATUS_PIO_PPMC_BQC_MEM_PARITY_ERR_SMASK \
520 | SEND_PIO_ERR_STATUS_PIO_PPMC_SOP_LEN_ERR_SMASK \
521 | SEND_PIO_ERR_STATUS_PIO_CURRENT_FREE_CNT_PARITY_ERR_SMASK \
522 | SEND_PIO_ERR_STATUS_PIO_LAST_RETURNED_CNT_PARITY_ERR_SMASK \
523 | SEND_PIO_ERR_STATUS_PIO_PCC_SOP_HEAD_PARITY_ERR_SMASK \
524 | SEND_PIO_ERR_STATUS_PIO_PEC_SOP_HEAD_PARITY_ERR_SMASK)
525
526/*
527 * TXE SDMA Error flags
528 */
529static struct flag_table sdma_err_status_flags[] = {
530/* 0*/ FLAG_ENTRY0("SDmaRpyTagErr",
531 SEND_DMA_ERR_STATUS_SDMA_RPY_TAG_ERR_SMASK),
532/* 1*/ FLAG_ENTRY0("SDmaCsrParityErr",
533 SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK),
534/* 2*/ FLAG_ENTRY0("SDmaPcieReqTrackingUncErr",
535 SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK),
536/* 3*/ FLAG_ENTRY0("SDmaPcieReqTrackingCorErr",
537 SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_COR_ERR_SMASK),
538/*04-63 reserved*/
539};
540
541/* TXE SDMA errors that cause an SPC freeze */
542#define ALL_SDMA_FREEZE_ERR \
543 (SEND_DMA_ERR_STATUS_SDMA_RPY_TAG_ERR_SMASK \
544 | SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK \
545 | SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK)
546
Mike Marciniszyn69a00b82016-02-03 14:31:49 -0800547/* SendEgressErrInfo bits that correspond to a PortXmitDiscard counter */
548#define PORT_DISCARD_EGRESS_ERRS \
549 (SEND_EGRESS_ERR_INFO_TOO_LONG_IB_PACKET_ERR_SMASK \
550 | SEND_EGRESS_ERR_INFO_VL_MAPPING_ERR_SMASK \
551 | SEND_EGRESS_ERR_INFO_VL_ERR_SMASK)
552
Mike Marciniszyn77241052015-07-30 15:17:43 -0400553/*
554 * TXE Egress Error flags
555 */
556#define SEES(text) SEND_EGRESS_ERR_STATUS_##text##_ERR_SMASK
557static struct flag_table egress_err_status_flags[] = {
558/* 0*/ FLAG_ENTRY0("TxPktIntegrityMemCorErr", SEES(TX_PKT_INTEGRITY_MEM_COR)),
559/* 1*/ FLAG_ENTRY0("TxPktIntegrityMemUncErr", SEES(TX_PKT_INTEGRITY_MEM_UNC)),
560/* 2 reserved */
561/* 3*/ FLAG_ENTRY0("TxEgressFifoUnderrunOrParityErr",
562 SEES(TX_EGRESS_FIFO_UNDERRUN_OR_PARITY)),
563/* 4*/ FLAG_ENTRY0("TxLinkdownErr", SEES(TX_LINKDOWN)),
564/* 5*/ FLAG_ENTRY0("TxIncorrectLinkStateErr", SEES(TX_INCORRECT_LINK_STATE)),
565/* 6 reserved */
566/* 7*/ FLAG_ENTRY0("TxPioLaunchIntfParityErr",
567 SEES(TX_PIO_LAUNCH_INTF_PARITY)),
568/* 8*/ FLAG_ENTRY0("TxSdmaLaunchIntfParityErr",
569 SEES(TX_SDMA_LAUNCH_INTF_PARITY)),
570/* 9-10 reserved */
571/*11*/ FLAG_ENTRY0("TxSbrdCtlStateMachineParityErr",
572 SEES(TX_SBRD_CTL_STATE_MACHINE_PARITY)),
573/*12*/ FLAG_ENTRY0("TxIllegalVLErr", SEES(TX_ILLEGAL_VL)),
574/*13*/ FLAG_ENTRY0("TxLaunchCsrParityErr", SEES(TX_LAUNCH_CSR_PARITY)),
575/*14*/ FLAG_ENTRY0("TxSbrdCtlCsrParityErr", SEES(TX_SBRD_CTL_CSR_PARITY)),
576/*15*/ FLAG_ENTRY0("TxConfigParityErr", SEES(TX_CONFIG_PARITY)),
577/*16*/ FLAG_ENTRY0("TxSdma0DisallowedPacketErr",
578 SEES(TX_SDMA0_DISALLOWED_PACKET)),
579/*17*/ FLAG_ENTRY0("TxSdma1DisallowedPacketErr",
580 SEES(TX_SDMA1_DISALLOWED_PACKET)),
581/*18*/ FLAG_ENTRY0("TxSdma2DisallowedPacketErr",
582 SEES(TX_SDMA2_DISALLOWED_PACKET)),
583/*19*/ FLAG_ENTRY0("TxSdma3DisallowedPacketErr",
584 SEES(TX_SDMA3_DISALLOWED_PACKET)),
585/*20*/ FLAG_ENTRY0("TxSdma4DisallowedPacketErr",
586 SEES(TX_SDMA4_DISALLOWED_PACKET)),
587/*21*/ FLAG_ENTRY0("TxSdma5DisallowedPacketErr",
588 SEES(TX_SDMA5_DISALLOWED_PACKET)),
589/*22*/ FLAG_ENTRY0("TxSdma6DisallowedPacketErr",
590 SEES(TX_SDMA6_DISALLOWED_PACKET)),
591/*23*/ FLAG_ENTRY0("TxSdma7DisallowedPacketErr",
592 SEES(TX_SDMA7_DISALLOWED_PACKET)),
593/*24*/ FLAG_ENTRY0("TxSdma8DisallowedPacketErr",
594 SEES(TX_SDMA8_DISALLOWED_PACKET)),
595/*25*/ FLAG_ENTRY0("TxSdma9DisallowedPacketErr",
596 SEES(TX_SDMA9_DISALLOWED_PACKET)),
597/*26*/ FLAG_ENTRY0("TxSdma10DisallowedPacketErr",
598 SEES(TX_SDMA10_DISALLOWED_PACKET)),
599/*27*/ FLAG_ENTRY0("TxSdma11DisallowedPacketErr",
600 SEES(TX_SDMA11_DISALLOWED_PACKET)),
601/*28*/ FLAG_ENTRY0("TxSdma12DisallowedPacketErr",
602 SEES(TX_SDMA12_DISALLOWED_PACKET)),
603/*29*/ FLAG_ENTRY0("TxSdma13DisallowedPacketErr",
604 SEES(TX_SDMA13_DISALLOWED_PACKET)),
605/*30*/ FLAG_ENTRY0("TxSdma14DisallowedPacketErr",
606 SEES(TX_SDMA14_DISALLOWED_PACKET)),
607/*31*/ FLAG_ENTRY0("TxSdma15DisallowedPacketErr",
608 SEES(TX_SDMA15_DISALLOWED_PACKET)),
609/*32*/ FLAG_ENTRY0("TxLaunchFifo0UncOrParityErr",
610 SEES(TX_LAUNCH_FIFO0_UNC_OR_PARITY)),
611/*33*/ FLAG_ENTRY0("TxLaunchFifo1UncOrParityErr",
612 SEES(TX_LAUNCH_FIFO1_UNC_OR_PARITY)),
613/*34*/ FLAG_ENTRY0("TxLaunchFifo2UncOrParityErr",
614 SEES(TX_LAUNCH_FIFO2_UNC_OR_PARITY)),
615/*35*/ FLAG_ENTRY0("TxLaunchFifo3UncOrParityErr",
616 SEES(TX_LAUNCH_FIFO3_UNC_OR_PARITY)),
617/*36*/ FLAG_ENTRY0("TxLaunchFifo4UncOrParityErr",
618 SEES(TX_LAUNCH_FIFO4_UNC_OR_PARITY)),
619/*37*/ FLAG_ENTRY0("TxLaunchFifo5UncOrParityErr",
620 SEES(TX_LAUNCH_FIFO5_UNC_OR_PARITY)),
621/*38*/ FLAG_ENTRY0("TxLaunchFifo6UncOrParityErr",
622 SEES(TX_LAUNCH_FIFO6_UNC_OR_PARITY)),
623/*39*/ FLAG_ENTRY0("TxLaunchFifo7UncOrParityErr",
624 SEES(TX_LAUNCH_FIFO7_UNC_OR_PARITY)),
625/*40*/ FLAG_ENTRY0("TxLaunchFifo8UncOrParityErr",
626 SEES(TX_LAUNCH_FIFO8_UNC_OR_PARITY)),
627/*41*/ FLAG_ENTRY0("TxCreditReturnParityErr", SEES(TX_CREDIT_RETURN_PARITY)),
628/*42*/ FLAG_ENTRY0("TxSbHdrUncErr", SEES(TX_SB_HDR_UNC)),
629/*43*/ FLAG_ENTRY0("TxReadSdmaMemoryUncErr", SEES(TX_READ_SDMA_MEMORY_UNC)),
630/*44*/ FLAG_ENTRY0("TxReadPioMemoryUncErr", SEES(TX_READ_PIO_MEMORY_UNC)),
631/*45*/ FLAG_ENTRY0("TxEgressFifoUncErr", SEES(TX_EGRESS_FIFO_UNC)),
632/*46*/ FLAG_ENTRY0("TxHcrcInsertionErr", SEES(TX_HCRC_INSERTION)),
633/*47*/ FLAG_ENTRY0("TxCreditReturnVLErr", SEES(TX_CREDIT_RETURN_VL)),
634/*48*/ FLAG_ENTRY0("TxLaunchFifo0CorErr", SEES(TX_LAUNCH_FIFO0_COR)),
635/*49*/ FLAG_ENTRY0("TxLaunchFifo1CorErr", SEES(TX_LAUNCH_FIFO1_COR)),
636/*50*/ FLAG_ENTRY0("TxLaunchFifo2CorErr", SEES(TX_LAUNCH_FIFO2_COR)),
637/*51*/ FLAG_ENTRY0("TxLaunchFifo3CorErr", SEES(TX_LAUNCH_FIFO3_COR)),
638/*52*/ FLAG_ENTRY0("TxLaunchFifo4CorErr", SEES(TX_LAUNCH_FIFO4_COR)),
639/*53*/ FLAG_ENTRY0("TxLaunchFifo5CorErr", SEES(TX_LAUNCH_FIFO5_COR)),
640/*54*/ FLAG_ENTRY0("TxLaunchFifo6CorErr", SEES(TX_LAUNCH_FIFO6_COR)),
641/*55*/ FLAG_ENTRY0("TxLaunchFifo7CorErr", SEES(TX_LAUNCH_FIFO7_COR)),
642/*56*/ FLAG_ENTRY0("TxLaunchFifo8CorErr", SEES(TX_LAUNCH_FIFO8_COR)),
643/*57*/ FLAG_ENTRY0("TxCreditOverrunErr", SEES(TX_CREDIT_OVERRUN)),
644/*58*/ FLAG_ENTRY0("TxSbHdrCorErr", SEES(TX_SB_HDR_COR)),
645/*59*/ FLAG_ENTRY0("TxReadSdmaMemoryCorErr", SEES(TX_READ_SDMA_MEMORY_COR)),
646/*60*/ FLAG_ENTRY0("TxReadPioMemoryCorErr", SEES(TX_READ_PIO_MEMORY_COR)),
647/*61*/ FLAG_ENTRY0("TxEgressFifoCorErr", SEES(TX_EGRESS_FIFO_COR)),
648/*62*/ FLAG_ENTRY0("TxReadSdmaMemoryCsrUncErr",
649 SEES(TX_READ_SDMA_MEMORY_CSR_UNC)),
650/*63*/ FLAG_ENTRY0("TxReadPioMemoryCsrUncErr",
651 SEES(TX_READ_PIO_MEMORY_CSR_UNC)),
652};
653
654/*
655 * TXE Egress Error Info flags
656 */
657#define SEEI(text) SEND_EGRESS_ERR_INFO_##text##_ERR_SMASK
658static struct flag_table egress_err_info_flags[] = {
659/* 0*/ FLAG_ENTRY0("Reserved", 0ull),
660/* 1*/ FLAG_ENTRY0("VLErr", SEEI(VL)),
661/* 2*/ FLAG_ENTRY0("JobKeyErr", SEEI(JOB_KEY)),
662/* 3*/ FLAG_ENTRY0("JobKeyErr", SEEI(JOB_KEY)),
663/* 4*/ FLAG_ENTRY0("PartitionKeyErr", SEEI(PARTITION_KEY)),
664/* 5*/ FLAG_ENTRY0("SLIDErr", SEEI(SLID)),
665/* 6*/ FLAG_ENTRY0("OpcodeErr", SEEI(OPCODE)),
666/* 7*/ FLAG_ENTRY0("VLMappingErr", SEEI(VL_MAPPING)),
667/* 8*/ FLAG_ENTRY0("RawErr", SEEI(RAW)),
668/* 9*/ FLAG_ENTRY0("RawIPv6Err", SEEI(RAW_IPV6)),
669/*10*/ FLAG_ENTRY0("GRHErr", SEEI(GRH)),
670/*11*/ FLAG_ENTRY0("BypassErr", SEEI(BYPASS)),
671/*12*/ FLAG_ENTRY0("KDETHPacketsErr", SEEI(KDETH_PACKETS)),
672/*13*/ FLAG_ENTRY0("NonKDETHPacketsErr", SEEI(NON_KDETH_PACKETS)),
673/*14*/ FLAG_ENTRY0("TooSmallIBPacketsErr", SEEI(TOO_SMALL_IB_PACKETS)),
674/*15*/ FLAG_ENTRY0("TooSmallBypassPacketsErr", SEEI(TOO_SMALL_BYPASS_PACKETS)),
675/*16*/ FLAG_ENTRY0("PbcTestErr", SEEI(PBC_TEST)),
676/*17*/ FLAG_ENTRY0("BadPktLenErr", SEEI(BAD_PKT_LEN)),
677/*18*/ FLAG_ENTRY0("TooLongIBPacketErr", SEEI(TOO_LONG_IB_PACKET)),
678/*19*/ FLAG_ENTRY0("TooLongBypassPacketsErr", SEEI(TOO_LONG_BYPASS_PACKETS)),
679/*20*/ FLAG_ENTRY0("PbcStaticRateControlErr", SEEI(PBC_STATIC_RATE_CONTROL)),
680/*21*/ FLAG_ENTRY0("BypassBadPktLenErr", SEEI(BAD_PKT_LEN)),
681};
682
683/* TXE Egress errors that cause an SPC freeze */
684#define ALL_TXE_EGRESS_FREEZE_ERR \
685 (SEES(TX_EGRESS_FIFO_UNDERRUN_OR_PARITY) \
686 | SEES(TX_PIO_LAUNCH_INTF_PARITY) \
687 | SEES(TX_SDMA_LAUNCH_INTF_PARITY) \
688 | SEES(TX_SBRD_CTL_STATE_MACHINE_PARITY) \
689 | SEES(TX_LAUNCH_CSR_PARITY) \
690 | SEES(TX_SBRD_CTL_CSR_PARITY) \
691 | SEES(TX_CONFIG_PARITY) \
692 | SEES(TX_LAUNCH_FIFO0_UNC_OR_PARITY) \
693 | SEES(TX_LAUNCH_FIFO1_UNC_OR_PARITY) \
694 | SEES(TX_LAUNCH_FIFO2_UNC_OR_PARITY) \
695 | SEES(TX_LAUNCH_FIFO3_UNC_OR_PARITY) \
696 | SEES(TX_LAUNCH_FIFO4_UNC_OR_PARITY) \
697 | SEES(TX_LAUNCH_FIFO5_UNC_OR_PARITY) \
698 | SEES(TX_LAUNCH_FIFO6_UNC_OR_PARITY) \
699 | SEES(TX_LAUNCH_FIFO7_UNC_OR_PARITY) \
700 | SEES(TX_LAUNCH_FIFO8_UNC_OR_PARITY) \
701 | SEES(TX_CREDIT_RETURN_PARITY))
702
703/*
704 * TXE Send error flags
705 */
706#define SES(name) SEND_ERR_STATUS_SEND_##name##_ERR_SMASK
707static struct flag_table send_err_status_flags[] = {
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -0500708/* 0*/ FLAG_ENTRY0("SendCsrParityErr", SES(CSR_PARITY)),
Mike Marciniszyn77241052015-07-30 15:17:43 -0400709/* 1*/ FLAG_ENTRY0("SendCsrReadBadAddrErr", SES(CSR_READ_BAD_ADDR)),
710/* 2*/ FLAG_ENTRY0("SendCsrWriteBadAddrErr", SES(CSR_WRITE_BAD_ADDR))
711};
712
713/*
714 * TXE Send Context Error flags and consequences
715 */
716static struct flag_table sc_err_status_flags[] = {
717/* 0*/ FLAG_ENTRY("InconsistentSop",
718 SEC_PACKET_DROPPED | SEC_SC_HALTED,
719 SEND_CTXT_ERR_STATUS_PIO_INCONSISTENT_SOP_ERR_SMASK),
720/* 1*/ FLAG_ENTRY("DisallowedPacket",
721 SEC_PACKET_DROPPED | SEC_SC_HALTED,
722 SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK),
723/* 2*/ FLAG_ENTRY("WriteCrossesBoundary",
724 SEC_WRITE_DROPPED | SEC_SC_HALTED,
725 SEND_CTXT_ERR_STATUS_PIO_WRITE_CROSSES_BOUNDARY_ERR_SMASK),
726/* 3*/ FLAG_ENTRY("WriteOverflow",
727 SEC_WRITE_DROPPED | SEC_SC_HALTED,
728 SEND_CTXT_ERR_STATUS_PIO_WRITE_OVERFLOW_ERR_SMASK),
729/* 4*/ FLAG_ENTRY("WriteOutOfBounds",
730 SEC_WRITE_DROPPED | SEC_SC_HALTED,
731 SEND_CTXT_ERR_STATUS_PIO_WRITE_OUT_OF_BOUNDS_ERR_SMASK),
732/* 5-63 reserved*/
733};
734
735/*
736 * RXE Receive Error flags
737 */
738#define RXES(name) RCV_ERR_STATUS_RX_##name##_ERR_SMASK
739static struct flag_table rxe_err_status_flags[] = {
740/* 0*/ FLAG_ENTRY0("RxDmaCsrCorErr", RXES(DMA_CSR_COR)),
741/* 1*/ FLAG_ENTRY0("RxDcIntfParityErr", RXES(DC_INTF_PARITY)),
742/* 2*/ FLAG_ENTRY0("RxRcvHdrUncErr", RXES(RCV_HDR_UNC)),
743/* 3*/ FLAG_ENTRY0("RxRcvHdrCorErr", RXES(RCV_HDR_COR)),
744/* 4*/ FLAG_ENTRY0("RxRcvDataUncErr", RXES(RCV_DATA_UNC)),
745/* 5*/ FLAG_ENTRY0("RxRcvDataCorErr", RXES(RCV_DATA_COR)),
746/* 6*/ FLAG_ENTRY0("RxRcvQpMapTableUncErr", RXES(RCV_QP_MAP_TABLE_UNC)),
747/* 7*/ FLAG_ENTRY0("RxRcvQpMapTableCorErr", RXES(RCV_QP_MAP_TABLE_COR)),
748/* 8*/ FLAG_ENTRY0("RxRcvCsrParityErr", RXES(RCV_CSR_PARITY)),
749/* 9*/ FLAG_ENTRY0("RxDcSopEopParityErr", RXES(DC_SOP_EOP_PARITY)),
750/*10*/ FLAG_ENTRY0("RxDmaFlagUncErr", RXES(DMA_FLAG_UNC)),
751/*11*/ FLAG_ENTRY0("RxDmaFlagCorErr", RXES(DMA_FLAG_COR)),
752/*12*/ FLAG_ENTRY0("RxRcvFsmEncodingErr", RXES(RCV_FSM_ENCODING)),
753/*13*/ FLAG_ENTRY0("RxRbufFreeListUncErr", RXES(RBUF_FREE_LIST_UNC)),
754/*14*/ FLAG_ENTRY0("RxRbufFreeListCorErr", RXES(RBUF_FREE_LIST_COR)),
755/*15*/ FLAG_ENTRY0("RxRbufLookupDesRegUncErr", RXES(RBUF_LOOKUP_DES_REG_UNC)),
756/*16*/ FLAG_ENTRY0("RxRbufLookupDesRegUncCorErr",
757 RXES(RBUF_LOOKUP_DES_REG_UNC_COR)),
758/*17*/ FLAG_ENTRY0("RxRbufLookupDesUncErr", RXES(RBUF_LOOKUP_DES_UNC)),
759/*18*/ FLAG_ENTRY0("RxRbufLookupDesCorErr", RXES(RBUF_LOOKUP_DES_COR)),
760/*19*/ FLAG_ENTRY0("RxRbufBlockListReadUncErr",
761 RXES(RBUF_BLOCK_LIST_READ_UNC)),
762/*20*/ FLAG_ENTRY0("RxRbufBlockListReadCorErr",
763 RXES(RBUF_BLOCK_LIST_READ_COR)),
764/*21*/ FLAG_ENTRY0("RxRbufCsrQHeadBufNumParityErr",
765 RXES(RBUF_CSR_QHEAD_BUF_NUM_PARITY)),
766/*22*/ FLAG_ENTRY0("RxRbufCsrQEntCntParityErr",
767 RXES(RBUF_CSR_QENT_CNT_PARITY)),
768/*23*/ FLAG_ENTRY0("RxRbufCsrQNextBufParityErr",
769 RXES(RBUF_CSR_QNEXT_BUF_PARITY)),
770/*24*/ FLAG_ENTRY0("RxRbufCsrQVldBitParityErr",
771 RXES(RBUF_CSR_QVLD_BIT_PARITY)),
772/*25*/ FLAG_ENTRY0("RxRbufCsrQHdPtrParityErr", RXES(RBUF_CSR_QHD_PTR_PARITY)),
773/*26*/ FLAG_ENTRY0("RxRbufCsrQTlPtrParityErr", RXES(RBUF_CSR_QTL_PTR_PARITY)),
774/*27*/ FLAG_ENTRY0("RxRbufCsrQNumOfPktParityErr",
775 RXES(RBUF_CSR_QNUM_OF_PKT_PARITY)),
776/*28*/ FLAG_ENTRY0("RxRbufCsrQEOPDWParityErr", RXES(RBUF_CSR_QEOPDW_PARITY)),
777/*29*/ FLAG_ENTRY0("RxRbufCtxIdParityErr", RXES(RBUF_CTX_ID_PARITY)),
778/*30*/ FLAG_ENTRY0("RxRBufBadLookupErr", RXES(RBUF_BAD_LOOKUP)),
779/*31*/ FLAG_ENTRY0("RxRbufFullErr", RXES(RBUF_FULL)),
780/*32*/ FLAG_ENTRY0("RxRbufEmptyErr", RXES(RBUF_EMPTY)),
781/*33*/ FLAG_ENTRY0("RxRbufFlRdAddrParityErr", RXES(RBUF_FL_RD_ADDR_PARITY)),
782/*34*/ FLAG_ENTRY0("RxRbufFlWrAddrParityErr", RXES(RBUF_FL_WR_ADDR_PARITY)),
783/*35*/ FLAG_ENTRY0("RxRbufFlInitdoneParityErr",
784 RXES(RBUF_FL_INITDONE_PARITY)),
785/*36*/ FLAG_ENTRY0("RxRbufFlInitWrAddrParityErr",
786 RXES(RBUF_FL_INIT_WR_ADDR_PARITY)),
787/*37*/ FLAG_ENTRY0("RxRbufNextFreeBufUncErr", RXES(RBUF_NEXT_FREE_BUF_UNC)),
788/*38*/ FLAG_ENTRY0("RxRbufNextFreeBufCorErr", RXES(RBUF_NEXT_FREE_BUF_COR)),
789/*39*/ FLAG_ENTRY0("RxLookupDesPart1UncErr", RXES(LOOKUP_DES_PART1_UNC)),
790/*40*/ FLAG_ENTRY0("RxLookupDesPart1UncCorErr",
791 RXES(LOOKUP_DES_PART1_UNC_COR)),
792/*41*/ FLAG_ENTRY0("RxLookupDesPart2ParityErr",
793 RXES(LOOKUP_DES_PART2_PARITY)),
794/*42*/ FLAG_ENTRY0("RxLookupRcvArrayUncErr", RXES(LOOKUP_RCV_ARRAY_UNC)),
795/*43*/ FLAG_ENTRY0("RxLookupRcvArrayCorErr", RXES(LOOKUP_RCV_ARRAY_COR)),
796/*44*/ FLAG_ENTRY0("RxLookupCsrParityErr", RXES(LOOKUP_CSR_PARITY)),
797/*45*/ FLAG_ENTRY0("RxHqIntrCsrParityErr", RXES(HQ_INTR_CSR_PARITY)),
798/*46*/ FLAG_ENTRY0("RxHqIntrFsmErr", RXES(HQ_INTR_FSM)),
799/*47*/ FLAG_ENTRY0("RxRbufDescPart1UncErr", RXES(RBUF_DESC_PART1_UNC)),
800/*48*/ FLAG_ENTRY0("RxRbufDescPart1CorErr", RXES(RBUF_DESC_PART1_COR)),
801/*49*/ FLAG_ENTRY0("RxRbufDescPart2UncErr", RXES(RBUF_DESC_PART2_UNC)),
802/*50*/ FLAG_ENTRY0("RxRbufDescPart2CorErr", RXES(RBUF_DESC_PART2_COR)),
803/*51*/ FLAG_ENTRY0("RxDmaHdrFifoRdUncErr", RXES(DMA_HDR_FIFO_RD_UNC)),
804/*52*/ FLAG_ENTRY0("RxDmaHdrFifoRdCorErr", RXES(DMA_HDR_FIFO_RD_COR)),
805/*53*/ FLAG_ENTRY0("RxDmaDataFifoRdUncErr", RXES(DMA_DATA_FIFO_RD_UNC)),
806/*54*/ FLAG_ENTRY0("RxDmaDataFifoRdCorErr", RXES(DMA_DATA_FIFO_RD_COR)),
807/*55*/ FLAG_ENTRY0("RxRbufDataUncErr", RXES(RBUF_DATA_UNC)),
808/*56*/ FLAG_ENTRY0("RxRbufDataCorErr", RXES(RBUF_DATA_COR)),
809/*57*/ FLAG_ENTRY0("RxDmaCsrParityErr", RXES(DMA_CSR_PARITY)),
810/*58*/ FLAG_ENTRY0("RxDmaEqFsmEncodingErr", RXES(DMA_EQ_FSM_ENCODING)),
811/*59*/ FLAG_ENTRY0("RxDmaDqFsmEncodingErr", RXES(DMA_DQ_FSM_ENCODING)),
812/*60*/ FLAG_ENTRY0("RxDmaCsrUncErr", RXES(DMA_CSR_UNC)),
813/*61*/ FLAG_ENTRY0("RxCsrReadBadAddrErr", RXES(CSR_READ_BAD_ADDR)),
814/*62*/ FLAG_ENTRY0("RxCsrWriteBadAddrErr", RXES(CSR_WRITE_BAD_ADDR)),
815/*63*/ FLAG_ENTRY0("RxCsrParityErr", RXES(CSR_PARITY))
816};
817
818/* RXE errors that will trigger an SPC freeze */
819#define ALL_RXE_FREEZE_ERR \
820 (RCV_ERR_STATUS_RX_RCV_QP_MAP_TABLE_UNC_ERR_SMASK \
821 | RCV_ERR_STATUS_RX_RCV_CSR_PARITY_ERR_SMASK \
822 | RCV_ERR_STATUS_RX_DMA_FLAG_UNC_ERR_SMASK \
823 | RCV_ERR_STATUS_RX_RCV_FSM_ENCODING_ERR_SMASK \
824 | RCV_ERR_STATUS_RX_RBUF_FREE_LIST_UNC_ERR_SMASK \
825 | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_REG_UNC_ERR_SMASK \
826 | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_REG_UNC_COR_ERR_SMASK \
827 | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_UNC_ERR_SMASK \
828 | RCV_ERR_STATUS_RX_RBUF_BLOCK_LIST_READ_UNC_ERR_SMASK \
829 | RCV_ERR_STATUS_RX_RBUF_CSR_QHEAD_BUF_NUM_PARITY_ERR_SMASK \
830 | RCV_ERR_STATUS_RX_RBUF_CSR_QENT_CNT_PARITY_ERR_SMASK \
831 | RCV_ERR_STATUS_RX_RBUF_CSR_QNEXT_BUF_PARITY_ERR_SMASK \
832 | RCV_ERR_STATUS_RX_RBUF_CSR_QVLD_BIT_PARITY_ERR_SMASK \
833 | RCV_ERR_STATUS_RX_RBUF_CSR_QHD_PTR_PARITY_ERR_SMASK \
834 | RCV_ERR_STATUS_RX_RBUF_CSR_QTL_PTR_PARITY_ERR_SMASK \
835 | RCV_ERR_STATUS_RX_RBUF_CSR_QNUM_OF_PKT_PARITY_ERR_SMASK \
836 | RCV_ERR_STATUS_RX_RBUF_CSR_QEOPDW_PARITY_ERR_SMASK \
837 | RCV_ERR_STATUS_RX_RBUF_CTX_ID_PARITY_ERR_SMASK \
838 | RCV_ERR_STATUS_RX_RBUF_BAD_LOOKUP_ERR_SMASK \
839 | RCV_ERR_STATUS_RX_RBUF_FULL_ERR_SMASK \
840 | RCV_ERR_STATUS_RX_RBUF_EMPTY_ERR_SMASK \
841 | RCV_ERR_STATUS_RX_RBUF_FL_RD_ADDR_PARITY_ERR_SMASK \
842 | RCV_ERR_STATUS_RX_RBUF_FL_WR_ADDR_PARITY_ERR_SMASK \
843 | RCV_ERR_STATUS_RX_RBUF_FL_INITDONE_PARITY_ERR_SMASK \
844 | RCV_ERR_STATUS_RX_RBUF_FL_INIT_WR_ADDR_PARITY_ERR_SMASK \
845 | RCV_ERR_STATUS_RX_RBUF_NEXT_FREE_BUF_UNC_ERR_SMASK \
846 | RCV_ERR_STATUS_RX_LOOKUP_DES_PART1_UNC_ERR_SMASK \
847 | RCV_ERR_STATUS_RX_LOOKUP_DES_PART1_UNC_COR_ERR_SMASK \
848 | RCV_ERR_STATUS_RX_LOOKUP_DES_PART2_PARITY_ERR_SMASK \
849 | RCV_ERR_STATUS_RX_LOOKUP_RCV_ARRAY_UNC_ERR_SMASK \
850 | RCV_ERR_STATUS_RX_LOOKUP_CSR_PARITY_ERR_SMASK \
851 | RCV_ERR_STATUS_RX_HQ_INTR_CSR_PARITY_ERR_SMASK \
852 | RCV_ERR_STATUS_RX_HQ_INTR_FSM_ERR_SMASK \
853 | RCV_ERR_STATUS_RX_RBUF_DESC_PART1_UNC_ERR_SMASK \
854 | RCV_ERR_STATUS_RX_RBUF_DESC_PART1_COR_ERR_SMASK \
855 | RCV_ERR_STATUS_RX_RBUF_DESC_PART2_UNC_ERR_SMASK \
856 | RCV_ERR_STATUS_RX_DMA_HDR_FIFO_RD_UNC_ERR_SMASK \
857 | RCV_ERR_STATUS_RX_DMA_DATA_FIFO_RD_UNC_ERR_SMASK \
858 | RCV_ERR_STATUS_RX_RBUF_DATA_UNC_ERR_SMASK \
859 | RCV_ERR_STATUS_RX_DMA_CSR_PARITY_ERR_SMASK \
860 | RCV_ERR_STATUS_RX_DMA_EQ_FSM_ENCODING_ERR_SMASK \
861 | RCV_ERR_STATUS_RX_DMA_DQ_FSM_ENCODING_ERR_SMASK \
862 | RCV_ERR_STATUS_RX_DMA_CSR_UNC_ERR_SMASK \
863 | RCV_ERR_STATUS_RX_CSR_PARITY_ERR_SMASK)
864
865#define RXE_FREEZE_ABORT_MASK \
866 (RCV_ERR_STATUS_RX_DMA_CSR_UNC_ERR_SMASK | \
867 RCV_ERR_STATUS_RX_DMA_HDR_FIFO_RD_UNC_ERR_SMASK | \
868 RCV_ERR_STATUS_RX_DMA_DATA_FIFO_RD_UNC_ERR_SMASK)
869
870/*
871 * DCC Error Flags
872 */
873#define DCCE(name) DCC_ERR_FLG_##name##_SMASK
874static struct flag_table dcc_err_flags[] = {
875 FLAG_ENTRY0("bad_l2_err", DCCE(BAD_L2_ERR)),
876 FLAG_ENTRY0("bad_sc_err", DCCE(BAD_SC_ERR)),
877 FLAG_ENTRY0("bad_mid_tail_err", DCCE(BAD_MID_TAIL_ERR)),
878 FLAG_ENTRY0("bad_preemption_err", DCCE(BAD_PREEMPTION_ERR)),
879 FLAG_ENTRY0("preemption_err", DCCE(PREEMPTION_ERR)),
880 FLAG_ENTRY0("preemptionvl15_err", DCCE(PREEMPTIONVL15_ERR)),
881 FLAG_ENTRY0("bad_vl_marker_err", DCCE(BAD_VL_MARKER_ERR)),
882 FLAG_ENTRY0("bad_dlid_target_err", DCCE(BAD_DLID_TARGET_ERR)),
883 FLAG_ENTRY0("bad_lver_err", DCCE(BAD_LVER_ERR)),
884 FLAG_ENTRY0("uncorrectable_err", DCCE(UNCORRECTABLE_ERR)),
885 FLAG_ENTRY0("bad_crdt_ack_err", DCCE(BAD_CRDT_ACK_ERR)),
886 FLAG_ENTRY0("unsup_pkt_type", DCCE(UNSUP_PKT_TYPE)),
887 FLAG_ENTRY0("bad_ctrl_flit_err", DCCE(BAD_CTRL_FLIT_ERR)),
888 FLAG_ENTRY0("event_cntr_parity_err", DCCE(EVENT_CNTR_PARITY_ERR)),
889 FLAG_ENTRY0("event_cntr_rollover_err", DCCE(EVENT_CNTR_ROLLOVER_ERR)),
890 FLAG_ENTRY0("link_err", DCCE(LINK_ERR)),
891 FLAG_ENTRY0("misc_cntr_rollover_err", DCCE(MISC_CNTR_ROLLOVER_ERR)),
892 FLAG_ENTRY0("bad_ctrl_dist_err", DCCE(BAD_CTRL_DIST_ERR)),
893 FLAG_ENTRY0("bad_tail_dist_err", DCCE(BAD_TAIL_DIST_ERR)),
894 FLAG_ENTRY0("bad_head_dist_err", DCCE(BAD_HEAD_DIST_ERR)),
895 FLAG_ENTRY0("nonvl15_state_err", DCCE(NONVL15_STATE_ERR)),
896 FLAG_ENTRY0("vl15_multi_err", DCCE(VL15_MULTI_ERR)),
897 FLAG_ENTRY0("bad_pkt_length_err", DCCE(BAD_PKT_LENGTH_ERR)),
898 FLAG_ENTRY0("unsup_vl_err", DCCE(UNSUP_VL_ERR)),
899 FLAG_ENTRY0("perm_nvl15_err", DCCE(PERM_NVL15_ERR)),
900 FLAG_ENTRY0("slid_zero_err", DCCE(SLID_ZERO_ERR)),
901 FLAG_ENTRY0("dlid_zero_err", DCCE(DLID_ZERO_ERR)),
902 FLAG_ENTRY0("length_mtu_err", DCCE(LENGTH_MTU_ERR)),
903 FLAG_ENTRY0("rx_early_drop_err", DCCE(RX_EARLY_DROP_ERR)),
904 FLAG_ENTRY0("late_short_err", DCCE(LATE_SHORT_ERR)),
905 FLAG_ENTRY0("late_long_err", DCCE(LATE_LONG_ERR)),
906 FLAG_ENTRY0("late_ebp_err", DCCE(LATE_EBP_ERR)),
907 FLAG_ENTRY0("fpe_tx_fifo_ovflw_err", DCCE(FPE_TX_FIFO_OVFLW_ERR)),
908 FLAG_ENTRY0("fpe_tx_fifo_unflw_err", DCCE(FPE_TX_FIFO_UNFLW_ERR)),
909 FLAG_ENTRY0("csr_access_blocked_host", DCCE(CSR_ACCESS_BLOCKED_HOST)),
910 FLAG_ENTRY0("csr_access_blocked_uc", DCCE(CSR_ACCESS_BLOCKED_UC)),
911 FLAG_ENTRY0("tx_ctrl_parity_err", DCCE(TX_CTRL_PARITY_ERR)),
912 FLAG_ENTRY0("tx_ctrl_parity_mbe_err", DCCE(TX_CTRL_PARITY_MBE_ERR)),
913 FLAG_ENTRY0("tx_sc_parity_err", DCCE(TX_SC_PARITY_ERR)),
914 FLAG_ENTRY0("rx_ctrl_parity_mbe_err", DCCE(RX_CTRL_PARITY_MBE_ERR)),
915 FLAG_ENTRY0("csr_parity_err", DCCE(CSR_PARITY_ERR)),
916 FLAG_ENTRY0("csr_inval_addr", DCCE(CSR_INVAL_ADDR)),
917 FLAG_ENTRY0("tx_byte_shft_parity_err", DCCE(TX_BYTE_SHFT_PARITY_ERR)),
918 FLAG_ENTRY0("rx_byte_shft_parity_err", DCCE(RX_BYTE_SHFT_PARITY_ERR)),
919 FLAG_ENTRY0("fmconfig_err", DCCE(FMCONFIG_ERR)),
920 FLAG_ENTRY0("rcvport_err", DCCE(RCVPORT_ERR)),
921};
922
923/*
924 * LCB error flags
925 */
926#define LCBE(name) DC_LCB_ERR_FLG_##name##_SMASK
927static struct flag_table lcb_err_flags[] = {
928/* 0*/ FLAG_ENTRY0("CSR_PARITY_ERR", LCBE(CSR_PARITY_ERR)),
929/* 1*/ FLAG_ENTRY0("INVALID_CSR_ADDR", LCBE(INVALID_CSR_ADDR)),
930/* 2*/ FLAG_ENTRY0("RST_FOR_FAILED_DESKEW", LCBE(RST_FOR_FAILED_DESKEW)),
931/* 3*/ FLAG_ENTRY0("ALL_LNS_FAILED_REINIT_TEST",
932 LCBE(ALL_LNS_FAILED_REINIT_TEST)),
933/* 4*/ FLAG_ENTRY0("LOST_REINIT_STALL_OR_TOS", LCBE(LOST_REINIT_STALL_OR_TOS)),
934/* 5*/ FLAG_ENTRY0("TX_LESS_THAN_FOUR_LNS", LCBE(TX_LESS_THAN_FOUR_LNS)),
935/* 6*/ FLAG_ENTRY0("RX_LESS_THAN_FOUR_LNS", LCBE(RX_LESS_THAN_FOUR_LNS)),
936/* 7*/ FLAG_ENTRY0("SEQ_CRC_ERR", LCBE(SEQ_CRC_ERR)),
937/* 8*/ FLAG_ENTRY0("REINIT_FROM_PEER", LCBE(REINIT_FROM_PEER)),
938/* 9*/ FLAG_ENTRY0("REINIT_FOR_LN_DEGRADE", LCBE(REINIT_FOR_LN_DEGRADE)),
939/*10*/ FLAG_ENTRY0("CRC_ERR_CNT_HIT_LIMIT", LCBE(CRC_ERR_CNT_HIT_LIMIT)),
940/*11*/ FLAG_ENTRY0("RCLK_STOPPED", LCBE(RCLK_STOPPED)),
941/*12*/ FLAG_ENTRY0("UNEXPECTED_REPLAY_MARKER", LCBE(UNEXPECTED_REPLAY_MARKER)),
942/*13*/ FLAG_ENTRY0("UNEXPECTED_ROUND_TRIP_MARKER",
943 LCBE(UNEXPECTED_ROUND_TRIP_MARKER)),
944/*14*/ FLAG_ENTRY0("ILLEGAL_NULL_LTP", LCBE(ILLEGAL_NULL_LTP)),
945/*15*/ FLAG_ENTRY0("ILLEGAL_FLIT_ENCODING", LCBE(ILLEGAL_FLIT_ENCODING)),
946/*16*/ FLAG_ENTRY0("FLIT_INPUT_BUF_OFLW", LCBE(FLIT_INPUT_BUF_OFLW)),
947/*17*/ FLAG_ENTRY0("VL_ACK_INPUT_BUF_OFLW", LCBE(VL_ACK_INPUT_BUF_OFLW)),
948/*18*/ FLAG_ENTRY0("VL_ACK_INPUT_PARITY_ERR", LCBE(VL_ACK_INPUT_PARITY_ERR)),
949/*19*/ FLAG_ENTRY0("VL_ACK_INPUT_WRONG_CRC_MODE",
950 LCBE(VL_ACK_INPUT_WRONG_CRC_MODE)),
951/*20*/ FLAG_ENTRY0("FLIT_INPUT_BUF_MBE", LCBE(FLIT_INPUT_BUF_MBE)),
952/*21*/ FLAG_ENTRY0("FLIT_INPUT_BUF_SBE", LCBE(FLIT_INPUT_BUF_SBE)),
953/*22*/ FLAG_ENTRY0("REPLAY_BUF_MBE", LCBE(REPLAY_BUF_MBE)),
954/*23*/ FLAG_ENTRY0("REPLAY_BUF_SBE", LCBE(REPLAY_BUF_SBE)),
955/*24*/ FLAG_ENTRY0("CREDIT_RETURN_FLIT_MBE", LCBE(CREDIT_RETURN_FLIT_MBE)),
956/*25*/ FLAG_ENTRY0("RST_FOR_LINK_TIMEOUT", LCBE(RST_FOR_LINK_TIMEOUT)),
957/*26*/ FLAG_ENTRY0("RST_FOR_INCOMPLT_RND_TRIP",
958 LCBE(RST_FOR_INCOMPLT_RND_TRIP)),
959/*27*/ FLAG_ENTRY0("HOLD_REINIT", LCBE(HOLD_REINIT)),
960/*28*/ FLAG_ENTRY0("NEG_EDGE_LINK_TRANSFER_ACTIVE",
961 LCBE(NEG_EDGE_LINK_TRANSFER_ACTIVE)),
962/*29*/ FLAG_ENTRY0("REDUNDANT_FLIT_PARITY_ERR",
963 LCBE(REDUNDANT_FLIT_PARITY_ERR))
964};
965
966/*
967 * DC8051 Error Flags
968 */
969#define D8E(name) DC_DC8051_ERR_FLG_##name##_SMASK
970static struct flag_table dc8051_err_flags[] = {
971 FLAG_ENTRY0("SET_BY_8051", D8E(SET_BY_8051)),
972 FLAG_ENTRY0("LOST_8051_HEART_BEAT", D8E(LOST_8051_HEART_BEAT)),
973 FLAG_ENTRY0("CRAM_MBE", D8E(CRAM_MBE)),
974 FLAG_ENTRY0("CRAM_SBE", D8E(CRAM_SBE)),
975 FLAG_ENTRY0("DRAM_MBE", D8E(DRAM_MBE)),
976 FLAG_ENTRY0("DRAM_SBE", D8E(DRAM_SBE)),
977 FLAG_ENTRY0("IRAM_MBE", D8E(IRAM_MBE)),
978 FLAG_ENTRY0("IRAM_SBE", D8E(IRAM_SBE)),
979 FLAG_ENTRY0("UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES",
Jubin John17fb4f22016-02-14 20:21:52 -0800980 D8E(UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES)),
Mike Marciniszyn77241052015-07-30 15:17:43 -0400981 FLAG_ENTRY0("INVALID_CSR_ADDR", D8E(INVALID_CSR_ADDR)),
982};
983
984/*
985 * DC8051 Information Error flags
986 *
987 * Flags in DC8051_DBG_ERR_INFO_SET_BY_8051.ERROR field.
988 */
989static struct flag_table dc8051_info_err_flags[] = {
990 FLAG_ENTRY0("Spico ROM check failed", SPICO_ROM_FAILED),
991 FLAG_ENTRY0("Unknown frame received", UNKNOWN_FRAME),
992 FLAG_ENTRY0("Target BER not met", TARGET_BER_NOT_MET),
993 FLAG_ENTRY0("Serdes internal loopback failure",
Jubin John17fb4f22016-02-14 20:21:52 -0800994 FAILED_SERDES_INTERNAL_LOOPBACK),
Mike Marciniszyn77241052015-07-30 15:17:43 -0400995 FLAG_ENTRY0("Failed SerDes init", FAILED_SERDES_INIT),
996 FLAG_ENTRY0("Failed LNI(Polling)", FAILED_LNI_POLLING),
997 FLAG_ENTRY0("Failed LNI(Debounce)", FAILED_LNI_DEBOUNCE),
998 FLAG_ENTRY0("Failed LNI(EstbComm)", FAILED_LNI_ESTBCOMM),
999 FLAG_ENTRY0("Failed LNI(OptEq)", FAILED_LNI_OPTEQ),
1000 FLAG_ENTRY0("Failed LNI(VerifyCap_1)", FAILED_LNI_VERIFY_CAP1),
1001 FLAG_ENTRY0("Failed LNI(VerifyCap_2)", FAILED_LNI_VERIFY_CAP2),
Jubin John8fefef12016-03-05 08:50:38 -08001002 FLAG_ENTRY0("Failed LNI(ConfigLT)", FAILED_LNI_CONFIGLT),
Dean Luick50921be2016-09-25 07:41:53 -07001003 FLAG_ENTRY0("Host Handshake Timeout", HOST_HANDSHAKE_TIMEOUT),
1004 FLAG_ENTRY0("External Device Request Timeout",
1005 EXTERNAL_DEVICE_REQ_TIMEOUT),
Mike Marciniszyn77241052015-07-30 15:17:43 -04001006};
1007
1008/*
1009 * DC8051 Information Host Information flags
1010 *
1011 * Flags in DC8051_DBG_ERR_INFO_SET_BY_8051.HOST_MSG field.
1012 */
1013static struct flag_table dc8051_info_host_msg_flags[] = {
1014 FLAG_ENTRY0("Host request done", 0x0001),
Bartlomiej Dudekddbf2ef2017-06-09 15:59:26 -07001015 FLAG_ENTRY0("BC PWR_MGM message", 0x0002),
1016 FLAG_ENTRY0("BC SMA message", 0x0004),
Mike Marciniszyn77241052015-07-30 15:17:43 -04001017 FLAG_ENTRY0("BC Unknown message (BCC)", 0x0008),
1018 FLAG_ENTRY0("BC Unknown message (LCB)", 0x0010),
1019 FLAG_ENTRY0("External device config request", 0x0020),
1020 FLAG_ENTRY0("VerifyCap all frames received", 0x0040),
1021 FLAG_ENTRY0("LinkUp achieved", 0x0080),
1022 FLAG_ENTRY0("Link going down", 0x0100),
Bartlomiej Dudekddbf2ef2017-06-09 15:59:26 -07001023 FLAG_ENTRY0("Link width downgraded", 0x0200),
Mike Marciniszyn77241052015-07-30 15:17:43 -04001024};
1025
Mike Marciniszyn77241052015-07-30 15:17:43 -04001026static u32 encoded_size(u32 size);
1027static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate);
1028static int set_physical_link_state(struct hfi1_devdata *dd, u64 state);
1029static void read_vc_remote_phy(struct hfi1_devdata *dd, u8 *power_management,
1030 u8 *continuous);
1031static void read_vc_remote_fabric(struct hfi1_devdata *dd, u8 *vau, u8 *z,
1032 u8 *vcu, u16 *vl15buf, u8 *crc_sizes);
1033static void read_vc_remote_link_width(struct hfi1_devdata *dd,
1034 u8 *remote_tx_rate, u16 *link_widths);
1035static void read_vc_local_link_width(struct hfi1_devdata *dd, u8 *misc_bits,
1036 u8 *flag_bits, u16 *link_widths);
1037static void read_remote_device_id(struct hfi1_devdata *dd, u16 *device_id,
1038 u8 *device_rev);
1039static void read_mgmt_allowed(struct hfi1_devdata *dd, u8 *mgmt_allowed);
1040static void read_local_lni(struct hfi1_devdata *dd, u8 *enable_lane_rx);
1041static int read_tx_settings(struct hfi1_devdata *dd, u8 *enable_lane_tx,
1042 u8 *tx_polarity_inversion,
1043 u8 *rx_polarity_inversion, u8 *max_rate);
1044static void handle_sdma_eng_err(struct hfi1_devdata *dd,
1045 unsigned int context, u64 err_status);
1046static void handle_qsfp_int(struct hfi1_devdata *dd, u32 source, u64 reg);
1047static void handle_dcc_err(struct hfi1_devdata *dd,
1048 unsigned int context, u64 err_status);
1049static void handle_lcb_err(struct hfi1_devdata *dd,
1050 unsigned int context, u64 err_status);
1051static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg);
1052static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
1053static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
1054static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
1055static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
1056static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
1057static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
1058static void handle_txe_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001059static void set_partition_keys(struct hfi1_pportdata *ppd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001060static const char *link_state_name(u32 state);
1061static const char *link_state_reason_name(struct hfi1_pportdata *ppd,
1062 u32 state);
1063static int do_8051_command(struct hfi1_devdata *dd, u32 type, u64 in_data,
1064 u64 *out_data);
1065static int read_idle_sma(struct hfi1_devdata *dd, u64 *data);
1066static int thermal_init(struct hfi1_devdata *dd);
1067
Byczkowski, Jakub02a222c2017-08-04 13:52:26 -07001068static void update_statusp(struct hfi1_pportdata *ppd, u32 state);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001069static int wait_logical_linkstate(struct hfi1_pportdata *ppd, u32 state,
1070 int msecs);
Jakub Byczkowskid392a672017-08-13 08:08:52 -07001071static void log_state_transition(struct hfi1_pportdata *ppd, u32 state);
1072static void log_physical_state(struct hfi1_pportdata *ppd, u32 state);
Byczkowski, Jakubbec7c792017-05-29 17:21:32 -07001073static int wait_physical_linkstate(struct hfi1_pportdata *ppd, u32 state,
1074 int msecs);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001075static void read_planned_down_reason_code(struct hfi1_devdata *dd, u8 *pdrrc);
Dean Luickfeb831d2016-04-14 08:31:36 -07001076static void read_link_down_reason(struct hfi1_devdata *dd, u8 *ldr);
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001077static void handle_temp_err(struct hfi1_devdata *dd);
1078static void dc_shutdown(struct hfi1_devdata *dd);
1079static void dc_start(struct hfi1_devdata *dd);
Dean Luick8f000f72016-04-12 11:32:06 -07001080static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp,
1081 unsigned int *np);
Sebastian Sanchez3ec5fa22016-06-09 07:51:57 -07001082static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd);
Dean Luickec8a1422017-03-20 17:24:39 -07001083static int wait_link_transfer_active(struct hfi1_devdata *dd, int wait_ms);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07001084static void clear_rsm_rule(struct hfi1_devdata *dd, u8 rule_index);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001085
1086/*
1087 * Error interrupt table entry. This is used as input to the interrupt
1088 * "clear down" routine used for all second tier error interrupt register.
1089 * Second tier interrupt registers have a single bit representing them
1090 * in the top-level CceIntStatus.
1091 */
1092struct err_reg_info {
1093 u32 status; /* status CSR offset */
1094 u32 clear; /* clear CSR offset */
1095 u32 mask; /* mask CSR offset */
1096 void (*handler)(struct hfi1_devdata *dd, u32 source, u64 reg);
1097 const char *desc;
1098};
1099
1100#define NUM_MISC_ERRS (IS_GENERAL_ERR_END - IS_GENERAL_ERR_START)
1101#define NUM_DC_ERRS (IS_DC_END - IS_DC_START)
1102#define NUM_VARIOUS (IS_VARIOUS_END - IS_VARIOUS_START)
1103
1104/*
1105 * Helpers for building HFI and DC error interrupt table entries. Different
1106 * helpers are needed because of inconsistent register names.
1107 */
1108#define EE(reg, handler, desc) \
1109 { reg##_STATUS, reg##_CLEAR, reg##_MASK, \
1110 handler, desc }
1111#define DC_EE1(reg, handler, desc) \
1112 { reg##_FLG, reg##_FLG_CLR, reg##_FLG_EN, handler, desc }
1113#define DC_EE2(reg, handler, desc) \
1114 { reg##_FLG, reg##_CLR, reg##_EN, handler, desc }
1115
1116/*
1117 * Table of the "misc" grouping of error interrupts. Each entry refers to
1118 * another register containing more information.
1119 */
1120static const struct err_reg_info misc_errs[NUM_MISC_ERRS] = {
1121/* 0*/ EE(CCE_ERR, handle_cce_err, "CceErr"),
1122/* 1*/ EE(RCV_ERR, handle_rxe_err, "RxeErr"),
1123/* 2*/ EE(MISC_ERR, handle_misc_err, "MiscErr"),
1124/* 3*/ { 0, 0, 0, NULL }, /* reserved */
1125/* 4*/ EE(SEND_PIO_ERR, handle_pio_err, "PioErr"),
1126/* 5*/ EE(SEND_DMA_ERR, handle_sdma_err, "SDmaErr"),
1127/* 6*/ EE(SEND_EGRESS_ERR, handle_egress_err, "EgressErr"),
1128/* 7*/ EE(SEND_ERR, handle_txe_err, "TxeErr")
1129 /* the rest are reserved */
1130};
1131
1132/*
1133 * Index into the Various section of the interrupt sources
1134 * corresponding to the Critical Temperature interrupt.
1135 */
1136#define TCRIT_INT_SOURCE 4
1137
1138/*
1139 * SDMA error interrupt entry - refers to another register containing more
1140 * information.
1141 */
1142static const struct err_reg_info sdma_eng_err =
1143 EE(SEND_DMA_ENG_ERR, handle_sdma_eng_err, "SDmaEngErr");
1144
1145static const struct err_reg_info various_err[NUM_VARIOUS] = {
1146/* 0*/ { 0, 0, 0, NULL }, /* PbcInt */
1147/* 1*/ { 0, 0, 0, NULL }, /* GpioAssertInt */
1148/* 2*/ EE(ASIC_QSFP1, handle_qsfp_int, "QSFP1"),
1149/* 3*/ EE(ASIC_QSFP2, handle_qsfp_int, "QSFP2"),
1150/* 4*/ { 0, 0, 0, NULL }, /* TCritInt */
1151 /* rest are reserved */
1152};
1153
1154/*
1155 * The DC encoding of mtu_cap for 10K MTU in the DCC_CFG_PORT_CONFIG
1156 * register can not be derived from the MTU value because 10K is not
1157 * a power of 2. Therefore, we need a constant. Everything else can
1158 * be calculated.
1159 */
1160#define DCC_CFG_PORT_MTU_CAP_10240 7
1161
1162/*
1163 * Table of the DC grouping of error interrupts. Each entry refers to
1164 * another register containing more information.
1165 */
1166static const struct err_reg_info dc_errs[NUM_DC_ERRS] = {
1167/* 0*/ DC_EE1(DCC_ERR, handle_dcc_err, "DCC Err"),
1168/* 1*/ DC_EE2(DC_LCB_ERR, handle_lcb_err, "LCB Err"),
1169/* 2*/ DC_EE2(DC_DC8051_ERR, handle_8051_interrupt, "DC8051 Interrupt"),
1170/* 3*/ /* dc_lbm_int - special, see is_dc_int() */
1171 /* the rest are reserved */
1172};
1173
1174struct cntr_entry {
1175 /*
1176 * counter name
1177 */
1178 char *name;
1179
1180 /*
1181 * csr to read for name (if applicable)
1182 */
1183 u64 csr;
1184
1185 /*
1186 * offset into dd or ppd to store the counter's value
1187 */
1188 int offset;
1189
1190 /*
1191 * flags
1192 */
1193 u8 flags;
1194
1195 /*
1196 * accessor for stat element, context either dd or ppd
1197 */
Jubin John17fb4f22016-02-14 20:21:52 -08001198 u64 (*rw_cntr)(const struct cntr_entry *, void *context, int vl,
1199 int mode, u64 data);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001200};
1201
1202#define C_RCV_HDR_OVF_FIRST C_RCV_HDR_OVF_0
1203#define C_RCV_HDR_OVF_LAST C_RCV_HDR_OVF_159
1204
1205#define CNTR_ELEM(name, csr, offset, flags, accessor) \
1206{ \
1207 name, \
1208 csr, \
1209 offset, \
1210 flags, \
1211 accessor \
1212}
1213
1214/* 32bit RXE */
1215#define RXE32_PORT_CNTR_ELEM(name, counter, flags) \
1216CNTR_ELEM(#name, \
1217 (counter * 8 + RCV_COUNTER_ARRAY32), \
1218 0, flags | CNTR_32BIT, \
1219 port_access_u32_csr)
1220
1221#define RXE32_DEV_CNTR_ELEM(name, counter, flags) \
1222CNTR_ELEM(#name, \
1223 (counter * 8 + RCV_COUNTER_ARRAY32), \
1224 0, flags | CNTR_32BIT, \
1225 dev_access_u32_csr)
1226
1227/* 64bit RXE */
1228#define RXE64_PORT_CNTR_ELEM(name, counter, flags) \
1229CNTR_ELEM(#name, \
1230 (counter * 8 + RCV_COUNTER_ARRAY64), \
1231 0, flags, \
1232 port_access_u64_csr)
1233
1234#define RXE64_DEV_CNTR_ELEM(name, counter, flags) \
1235CNTR_ELEM(#name, \
1236 (counter * 8 + RCV_COUNTER_ARRAY64), \
1237 0, flags, \
1238 dev_access_u64_csr)
1239
1240#define OVR_LBL(ctx) C_RCV_HDR_OVF_ ## ctx
1241#define OVR_ELM(ctx) \
1242CNTR_ELEM("RcvHdrOvr" #ctx, \
Jubin John8638b772016-02-14 20:19:24 -08001243 (RCV_HDR_OVFL_CNT + ctx * 0x100), \
Mike Marciniszyn77241052015-07-30 15:17:43 -04001244 0, CNTR_NORMAL, port_access_u64_csr)
1245
1246/* 32bit TXE */
1247#define TXE32_PORT_CNTR_ELEM(name, counter, flags) \
1248CNTR_ELEM(#name, \
1249 (counter * 8 + SEND_COUNTER_ARRAY32), \
1250 0, flags | CNTR_32BIT, \
1251 port_access_u32_csr)
1252
1253/* 64bit TXE */
1254#define TXE64_PORT_CNTR_ELEM(name, counter, flags) \
1255CNTR_ELEM(#name, \
1256 (counter * 8 + SEND_COUNTER_ARRAY64), \
1257 0, flags, \
1258 port_access_u64_csr)
1259
1260# define TX64_DEV_CNTR_ELEM(name, counter, flags) \
1261CNTR_ELEM(#name,\
1262 counter * 8 + SEND_COUNTER_ARRAY64, \
1263 0, \
1264 flags, \
1265 dev_access_u64_csr)
1266
1267/* CCE */
1268#define CCE_PERF_DEV_CNTR_ELEM(name, counter, flags) \
1269CNTR_ELEM(#name, \
1270 (counter * 8 + CCE_COUNTER_ARRAY32), \
1271 0, flags | CNTR_32BIT, \
1272 dev_access_u32_csr)
1273
1274#define CCE_INT_DEV_CNTR_ELEM(name, counter, flags) \
1275CNTR_ELEM(#name, \
1276 (counter * 8 + CCE_INT_COUNTER_ARRAY32), \
1277 0, flags | CNTR_32BIT, \
1278 dev_access_u32_csr)
1279
1280/* DC */
1281#define DC_PERF_CNTR(name, counter, flags) \
1282CNTR_ELEM(#name, \
1283 counter, \
1284 0, \
1285 flags, \
1286 dev_access_u64_csr)
1287
1288#define DC_PERF_CNTR_LCB(name, counter, flags) \
1289CNTR_ELEM(#name, \
1290 counter, \
1291 0, \
1292 flags, \
1293 dc_access_lcb_cntr)
1294
1295/* ibp counters */
1296#define SW_IBP_CNTR(name, cntr) \
1297CNTR_ELEM(#name, \
1298 0, \
1299 0, \
1300 CNTR_SYNTH, \
1301 access_ibp_##cntr)
1302
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -07001303/**
1304 * hfi_addr_from_offset - return addr for readq/writeq
1305 * @dd - the dd device
1306 * @offset - the offset of the CSR within bar0
1307 *
1308 * This routine selects the appropriate base address
1309 * based on the indicated offset.
1310 */
1311static inline void __iomem *hfi1_addr_from_offset(
1312 const struct hfi1_devdata *dd,
1313 u32 offset)
1314{
1315 if (offset >= dd->base2_start)
1316 return dd->kregbase2 + (offset - dd->base2_start);
1317 return dd->kregbase1 + offset;
1318}
1319
1320/**
1321 * read_csr - read CSR at the indicated offset
1322 * @dd - the dd device
1323 * @offset - the offset of the CSR within bar0
1324 *
1325 * Return: the value read or all FF's if there
1326 * is no mapping
1327 */
Mike Marciniszyn77241052015-07-30 15:17:43 -04001328u64 read_csr(const struct hfi1_devdata *dd, u32 offset)
1329{
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -07001330 if (dd->flags & HFI1_PRESENT)
1331 return readq(hfi1_addr_from_offset(dd, offset));
Mike Marciniszyn77241052015-07-30 15:17:43 -04001332 return -1;
1333}
1334
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -07001335/**
1336 * write_csr - write CSR at the indicated offset
1337 * @dd - the dd device
1338 * @offset - the offset of the CSR within bar0
1339 * @value - value to write
1340 */
Mike Marciniszyn77241052015-07-30 15:17:43 -04001341void write_csr(const struct hfi1_devdata *dd, u32 offset, u64 value)
1342{
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -07001343 if (dd->flags & HFI1_PRESENT) {
1344 void __iomem *base = hfi1_addr_from_offset(dd, offset);
1345
1346 /* avoid write to RcvArray */
1347 if (WARN_ON(offset >= RCV_ARRAY && offset < dd->base2_start))
1348 return;
1349 writeq(value, base);
1350 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04001351}
1352
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -07001353/**
1354 * get_csr_addr - return te iomem address for offset
1355 * @dd - the dd device
1356 * @offset - the offset of the CSR within bar0
1357 *
1358 * Return: The iomem address to use in subsequent
1359 * writeq/readq operations.
1360 */
Mike Marciniszyn77241052015-07-30 15:17:43 -04001361void __iomem *get_csr_addr(
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -07001362 const struct hfi1_devdata *dd,
Mike Marciniszyn77241052015-07-30 15:17:43 -04001363 u32 offset)
1364{
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -07001365 if (dd->flags & HFI1_PRESENT)
1366 return hfi1_addr_from_offset(dd, offset);
1367 return NULL;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001368}
1369
1370static inline u64 read_write_csr(const struct hfi1_devdata *dd, u32 csr,
1371 int mode, u64 value)
1372{
1373 u64 ret;
1374
Mike Marciniszyn77241052015-07-30 15:17:43 -04001375 if (mode == CNTR_MODE_R) {
1376 ret = read_csr(dd, csr);
1377 } else if (mode == CNTR_MODE_W) {
1378 write_csr(dd, csr, value);
1379 ret = value;
1380 } else {
1381 dd_dev_err(dd, "Invalid cntr register access mode");
1382 return 0;
1383 }
1384
1385 hfi1_cdbg(CNTR, "csr 0x%x val 0x%llx mode %d", csr, ret, mode);
1386 return ret;
1387}
1388
1389/* Dev Access */
1390static u64 dev_access_u32_csr(const struct cntr_entry *entry,
Jubin John17fb4f22016-02-14 20:21:52 -08001391 void *context, int vl, int mode, u64 data)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001392{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301393 struct hfi1_devdata *dd = context;
Vennila Megavannana699c6c2016-01-11 18:30:56 -05001394 u64 csr = entry->csr;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001395
Vennila Megavannana699c6c2016-01-11 18:30:56 -05001396 if (entry->flags & CNTR_SDMA) {
1397 if (vl == CNTR_INVALID_VL)
1398 return 0;
1399 csr += 0x100 * vl;
1400 } else {
1401 if (vl != CNTR_INVALID_VL)
1402 return 0;
1403 }
1404 return read_write_csr(dd, csr, mode, data);
1405}
1406
1407static u64 access_sde_err_cnt(const struct cntr_entry *entry,
1408 void *context, int idx, int mode, u64 data)
1409{
1410 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1411
1412 if (dd->per_sdma && idx < dd->num_sdma)
1413 return dd->per_sdma[idx].err_cnt;
1414 return 0;
1415}
1416
1417static u64 access_sde_int_cnt(const struct cntr_entry *entry,
1418 void *context, int idx, int mode, u64 data)
1419{
1420 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1421
1422 if (dd->per_sdma && idx < dd->num_sdma)
1423 return dd->per_sdma[idx].sdma_int_cnt;
1424 return 0;
1425}
1426
1427static u64 access_sde_idle_int_cnt(const struct cntr_entry *entry,
1428 void *context, int idx, int mode, u64 data)
1429{
1430 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1431
1432 if (dd->per_sdma && idx < dd->num_sdma)
1433 return dd->per_sdma[idx].idle_int_cnt;
1434 return 0;
1435}
1436
1437static u64 access_sde_progress_int_cnt(const struct cntr_entry *entry,
1438 void *context, int idx, int mode,
1439 u64 data)
1440{
1441 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1442
1443 if (dd->per_sdma && idx < dd->num_sdma)
1444 return dd->per_sdma[idx].progress_int_cnt;
1445 return 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001446}
1447
1448static u64 dev_access_u64_csr(const struct cntr_entry *entry, void *context,
Jubin John17fb4f22016-02-14 20:21:52 -08001449 int vl, int mode, u64 data)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001450{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301451 struct hfi1_devdata *dd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001452
1453 u64 val = 0;
1454 u64 csr = entry->csr;
1455
1456 if (entry->flags & CNTR_VL) {
1457 if (vl == CNTR_INVALID_VL)
1458 return 0;
1459 csr += 8 * vl;
1460 } else {
1461 if (vl != CNTR_INVALID_VL)
1462 return 0;
1463 }
1464
1465 val = read_write_csr(dd, csr, mode, data);
1466 return val;
1467}
1468
1469static u64 dc_access_lcb_cntr(const struct cntr_entry *entry, void *context,
Jubin John17fb4f22016-02-14 20:21:52 -08001470 int vl, int mode, u64 data)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001471{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301472 struct hfi1_devdata *dd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001473 u32 csr = entry->csr;
1474 int ret = 0;
1475
1476 if (vl != CNTR_INVALID_VL)
1477 return 0;
1478 if (mode == CNTR_MODE_R)
1479 ret = read_lcb_csr(dd, csr, &data);
1480 else if (mode == CNTR_MODE_W)
1481 ret = write_lcb_csr(dd, csr, data);
1482
1483 if (ret) {
1484 dd_dev_err(dd, "Could not acquire LCB for counter 0x%x", csr);
1485 return 0;
1486 }
1487
1488 hfi1_cdbg(CNTR, "csr 0x%x val 0x%llx mode %d", csr, data, mode);
1489 return data;
1490}
1491
1492/* Port Access */
1493static u64 port_access_u32_csr(const struct cntr_entry *entry, void *context,
Jubin John17fb4f22016-02-14 20:21:52 -08001494 int vl, int mode, u64 data)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001495{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301496 struct hfi1_pportdata *ppd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001497
1498 if (vl != CNTR_INVALID_VL)
1499 return 0;
1500 return read_write_csr(ppd->dd, entry->csr, mode, data);
1501}
1502
1503static u64 port_access_u64_csr(const struct cntr_entry *entry,
Jubin John17fb4f22016-02-14 20:21:52 -08001504 void *context, int vl, int mode, u64 data)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001505{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301506 struct hfi1_pportdata *ppd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001507 u64 val;
1508 u64 csr = entry->csr;
1509
1510 if (entry->flags & CNTR_VL) {
1511 if (vl == CNTR_INVALID_VL)
1512 return 0;
1513 csr += 8 * vl;
1514 } else {
1515 if (vl != CNTR_INVALID_VL)
1516 return 0;
1517 }
1518 val = read_write_csr(ppd->dd, csr, mode, data);
1519 return val;
1520}
1521
1522/* Software defined */
1523static inline u64 read_write_sw(struct hfi1_devdata *dd, u64 *cntr, int mode,
1524 u64 data)
1525{
1526 u64 ret;
1527
1528 if (mode == CNTR_MODE_R) {
1529 ret = *cntr;
1530 } else if (mode == CNTR_MODE_W) {
1531 *cntr = data;
1532 ret = data;
1533 } else {
1534 dd_dev_err(dd, "Invalid cntr sw access mode");
1535 return 0;
1536 }
1537
1538 hfi1_cdbg(CNTR, "val 0x%llx mode %d", ret, mode);
1539
1540 return ret;
1541}
1542
1543static u64 access_sw_link_dn_cnt(const struct cntr_entry *entry, void *context,
Jubin John17fb4f22016-02-14 20:21:52 -08001544 int vl, int mode, u64 data)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001545{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301546 struct hfi1_pportdata *ppd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001547
1548 if (vl != CNTR_INVALID_VL)
1549 return 0;
1550 return read_write_sw(ppd->dd, &ppd->link_downed, mode, data);
1551}
1552
1553static u64 access_sw_link_up_cnt(const struct cntr_entry *entry, void *context,
Jubin John17fb4f22016-02-14 20:21:52 -08001554 int vl, int mode, u64 data)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001555{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301556 struct hfi1_pportdata *ppd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001557
1558 if (vl != CNTR_INVALID_VL)
1559 return 0;
1560 return read_write_sw(ppd->dd, &ppd->link_up, mode, data);
1561}
1562
Dean Luick6d014532015-12-01 15:38:23 -05001563static u64 access_sw_unknown_frame_cnt(const struct cntr_entry *entry,
1564 void *context, int vl, int mode,
1565 u64 data)
1566{
1567 struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
1568
1569 if (vl != CNTR_INVALID_VL)
1570 return 0;
1571 return read_write_sw(ppd->dd, &ppd->unknown_frame_count, mode, data);
1572}
1573
Mike Marciniszyn77241052015-07-30 15:17:43 -04001574static u64 access_sw_xmit_discards(const struct cntr_entry *entry,
Jubin John17fb4f22016-02-14 20:21:52 -08001575 void *context, int vl, int mode, u64 data)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001576{
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08001577 struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
1578 u64 zero = 0;
1579 u64 *counter;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001580
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08001581 if (vl == CNTR_INVALID_VL)
1582 counter = &ppd->port_xmit_discards;
1583 else if (vl >= 0 && vl < C_VL_COUNT)
1584 counter = &ppd->port_xmit_discards_vl[vl];
1585 else
1586 counter = &zero;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001587
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08001588 return read_write_sw(ppd->dd, counter, mode, data);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001589}
1590
1591static u64 access_xmit_constraint_errs(const struct cntr_entry *entry,
Jubin John17fb4f22016-02-14 20:21:52 -08001592 void *context, int vl, int mode,
1593 u64 data)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001594{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301595 struct hfi1_pportdata *ppd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001596
1597 if (vl != CNTR_INVALID_VL)
1598 return 0;
1599
1600 return read_write_sw(ppd->dd, &ppd->port_xmit_constraint_errors,
1601 mode, data);
1602}
1603
1604static u64 access_rcv_constraint_errs(const struct cntr_entry *entry,
Jubin John17fb4f22016-02-14 20:21:52 -08001605 void *context, int vl, int mode, u64 data)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001606{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301607 struct hfi1_pportdata *ppd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001608
1609 if (vl != CNTR_INVALID_VL)
1610 return 0;
1611
1612 return read_write_sw(ppd->dd, &ppd->port_rcv_constraint_errors,
1613 mode, data);
1614}
1615
1616u64 get_all_cpu_total(u64 __percpu *cntr)
1617{
1618 int cpu;
1619 u64 counter = 0;
1620
1621 for_each_possible_cpu(cpu)
1622 counter += *per_cpu_ptr(cntr, cpu);
1623 return counter;
1624}
1625
1626static u64 read_write_cpu(struct hfi1_devdata *dd, u64 *z_val,
1627 u64 __percpu *cntr,
1628 int vl, int mode, u64 data)
1629{
Mike Marciniszyn77241052015-07-30 15:17:43 -04001630 u64 ret = 0;
1631
1632 if (vl != CNTR_INVALID_VL)
1633 return 0;
1634
1635 if (mode == CNTR_MODE_R) {
1636 ret = get_all_cpu_total(cntr) - *z_val;
1637 } else if (mode == CNTR_MODE_W) {
1638 /* A write can only zero the counter */
1639 if (data == 0)
1640 *z_val = get_all_cpu_total(cntr);
1641 else
1642 dd_dev_err(dd, "Per CPU cntrs can only be zeroed");
1643 } else {
1644 dd_dev_err(dd, "Invalid cntr sw cpu access mode");
1645 return 0;
1646 }
1647
1648 return ret;
1649}
1650
1651static u64 access_sw_cpu_intr(const struct cntr_entry *entry,
1652 void *context, int vl, int mode, u64 data)
1653{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301654 struct hfi1_devdata *dd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001655
1656 return read_write_cpu(dd, &dd->z_int_counter, dd->int_counter, vl,
1657 mode, data);
1658}
1659
1660static u64 access_sw_cpu_rcv_limit(const struct cntr_entry *entry,
Jubin John17fb4f22016-02-14 20:21:52 -08001661 void *context, int vl, int mode, u64 data)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001662{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301663 struct hfi1_devdata *dd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001664
1665 return read_write_cpu(dd, &dd->z_rcv_limit, dd->rcv_limit, vl,
1666 mode, data);
1667}
1668
1669static u64 access_sw_pio_wait(const struct cntr_entry *entry,
1670 void *context, int vl, int mode, u64 data)
1671{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301672 struct hfi1_devdata *dd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001673
1674 return dd->verbs_dev.n_piowait;
1675}
1676
Mike Marciniszyn14553ca2016-02-14 12:45:36 -08001677static u64 access_sw_pio_drain(const struct cntr_entry *entry,
1678 void *context, int vl, int mode, u64 data)
1679{
1680 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1681
1682 return dd->verbs_dev.n_piodrain;
1683}
1684
Mike Marciniszyn77241052015-07-30 15:17:43 -04001685static u64 access_sw_vtx_wait(const struct cntr_entry *entry,
1686 void *context, int vl, int mode, u64 data)
1687{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301688 struct hfi1_devdata *dd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001689
1690 return dd->verbs_dev.n_txwait;
1691}
1692
1693static u64 access_sw_kmem_wait(const struct cntr_entry *entry,
1694 void *context, int vl, int mode, u64 data)
1695{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301696 struct hfi1_devdata *dd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001697
1698 return dd->verbs_dev.n_kmem_wait;
1699}
1700
Dean Luickb4219222015-10-26 10:28:35 -04001701static u64 access_sw_send_schedule(const struct cntr_entry *entry,
Jubin John17fb4f22016-02-14 20:21:52 -08001702 void *context, int vl, int mode, u64 data)
Dean Luickb4219222015-10-26 10:28:35 -04001703{
1704 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1705
Vennila Megavannan89abfc82016-02-03 14:34:07 -08001706 return read_write_cpu(dd, &dd->z_send_schedule, dd->send_schedule, vl,
1707 mode, data);
Dean Luickb4219222015-10-26 10:28:35 -04001708}
1709
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05001710/* Software counters for the error status bits within MISC_ERR_STATUS */
1711static u64 access_misc_pll_lock_fail_err_cnt(const struct cntr_entry *entry,
1712 void *context, int vl, int mode,
1713 u64 data)
1714{
1715 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1716
1717 return dd->misc_err_status_cnt[12];
1718}
1719
1720static u64 access_misc_mbist_fail_err_cnt(const struct cntr_entry *entry,
1721 void *context, int vl, int mode,
1722 u64 data)
1723{
1724 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1725
1726 return dd->misc_err_status_cnt[11];
1727}
1728
1729static u64 access_misc_invalid_eep_cmd_err_cnt(const struct cntr_entry *entry,
1730 void *context, int vl, int mode,
1731 u64 data)
1732{
1733 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1734
1735 return dd->misc_err_status_cnt[10];
1736}
1737
1738static u64 access_misc_efuse_done_parity_err_cnt(const struct cntr_entry *entry,
1739 void *context, int vl,
1740 int mode, u64 data)
1741{
1742 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1743
1744 return dd->misc_err_status_cnt[9];
1745}
1746
1747static u64 access_misc_efuse_write_err_cnt(const struct cntr_entry *entry,
1748 void *context, int vl, int mode,
1749 u64 data)
1750{
1751 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1752
1753 return dd->misc_err_status_cnt[8];
1754}
1755
1756static u64 access_misc_efuse_read_bad_addr_err_cnt(
1757 const struct cntr_entry *entry,
1758 void *context, int vl, int mode, u64 data)
1759{
1760 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1761
1762 return dd->misc_err_status_cnt[7];
1763}
1764
1765static u64 access_misc_efuse_csr_parity_err_cnt(const struct cntr_entry *entry,
1766 void *context, int vl,
1767 int mode, u64 data)
1768{
1769 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1770
1771 return dd->misc_err_status_cnt[6];
1772}
1773
1774static u64 access_misc_fw_auth_failed_err_cnt(const struct cntr_entry *entry,
1775 void *context, int vl, int mode,
1776 u64 data)
1777{
1778 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1779
1780 return dd->misc_err_status_cnt[5];
1781}
1782
1783static u64 access_misc_key_mismatch_err_cnt(const struct cntr_entry *entry,
1784 void *context, int vl, int mode,
1785 u64 data)
1786{
1787 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1788
1789 return dd->misc_err_status_cnt[4];
1790}
1791
1792static u64 access_misc_sbus_write_failed_err_cnt(const struct cntr_entry *entry,
1793 void *context, int vl,
1794 int mode, u64 data)
1795{
1796 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1797
1798 return dd->misc_err_status_cnt[3];
1799}
1800
1801static u64 access_misc_csr_write_bad_addr_err_cnt(
1802 const struct cntr_entry *entry,
1803 void *context, int vl, int mode, u64 data)
1804{
1805 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1806
1807 return dd->misc_err_status_cnt[2];
1808}
1809
1810static u64 access_misc_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
1811 void *context, int vl,
1812 int mode, u64 data)
1813{
1814 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1815
1816 return dd->misc_err_status_cnt[1];
1817}
1818
1819static u64 access_misc_csr_parity_err_cnt(const struct cntr_entry *entry,
1820 void *context, int vl, int mode,
1821 u64 data)
1822{
1823 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1824
1825 return dd->misc_err_status_cnt[0];
1826}
1827
1828/*
1829 * Software counter for the aggregate of
1830 * individual CceErrStatus counters
1831 */
1832static u64 access_sw_cce_err_status_aggregated_cnt(
1833 const struct cntr_entry *entry,
1834 void *context, int vl, int mode, u64 data)
1835{
1836 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1837
1838 return dd->sw_cce_err_status_aggregate;
1839}
1840
1841/*
1842 * Software counters corresponding to each of the
1843 * error status bits within CceErrStatus
1844 */
1845static u64 access_cce_msix_csr_parity_err_cnt(const struct cntr_entry *entry,
1846 void *context, int vl, int mode,
1847 u64 data)
1848{
1849 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1850
1851 return dd->cce_err_status_cnt[40];
1852}
1853
1854static u64 access_cce_int_map_unc_err_cnt(const struct cntr_entry *entry,
1855 void *context, int vl, int mode,
1856 u64 data)
1857{
1858 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1859
1860 return dd->cce_err_status_cnt[39];
1861}
1862
1863static u64 access_cce_int_map_cor_err_cnt(const struct cntr_entry *entry,
1864 void *context, int vl, int mode,
1865 u64 data)
1866{
1867 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1868
1869 return dd->cce_err_status_cnt[38];
1870}
1871
1872static u64 access_cce_msix_table_unc_err_cnt(const struct cntr_entry *entry,
1873 void *context, int vl, int mode,
1874 u64 data)
1875{
1876 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1877
1878 return dd->cce_err_status_cnt[37];
1879}
1880
1881static u64 access_cce_msix_table_cor_err_cnt(const struct cntr_entry *entry,
1882 void *context, int vl, int mode,
1883 u64 data)
1884{
1885 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1886
1887 return dd->cce_err_status_cnt[36];
1888}
1889
1890static u64 access_cce_rxdma_conv_fifo_parity_err_cnt(
1891 const struct cntr_entry *entry,
1892 void *context, int vl, int mode, u64 data)
1893{
1894 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1895
1896 return dd->cce_err_status_cnt[35];
1897}
1898
1899static u64 access_cce_rcpl_async_fifo_parity_err_cnt(
1900 const struct cntr_entry *entry,
1901 void *context, int vl, int mode, u64 data)
1902{
1903 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1904
1905 return dd->cce_err_status_cnt[34];
1906}
1907
1908static u64 access_cce_seg_write_bad_addr_err_cnt(const struct cntr_entry *entry,
1909 void *context, int vl,
1910 int mode, u64 data)
1911{
1912 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1913
1914 return dd->cce_err_status_cnt[33];
1915}
1916
1917static u64 access_cce_seg_read_bad_addr_err_cnt(const struct cntr_entry *entry,
1918 void *context, int vl, int mode,
1919 u64 data)
1920{
1921 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1922
1923 return dd->cce_err_status_cnt[32];
1924}
1925
1926static u64 access_la_triggered_cnt(const struct cntr_entry *entry,
1927 void *context, int vl, int mode, u64 data)
1928{
1929 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1930
1931 return dd->cce_err_status_cnt[31];
1932}
1933
1934static u64 access_cce_trgt_cpl_timeout_err_cnt(const struct cntr_entry *entry,
1935 void *context, int vl, int mode,
1936 u64 data)
1937{
1938 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1939
1940 return dd->cce_err_status_cnt[30];
1941}
1942
1943static u64 access_pcic_receive_parity_err_cnt(const struct cntr_entry *entry,
1944 void *context, int vl, int mode,
1945 u64 data)
1946{
1947 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1948
1949 return dd->cce_err_status_cnt[29];
1950}
1951
1952static u64 access_pcic_transmit_back_parity_err_cnt(
1953 const struct cntr_entry *entry,
1954 void *context, int vl, int mode, u64 data)
1955{
1956 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1957
1958 return dd->cce_err_status_cnt[28];
1959}
1960
1961static u64 access_pcic_transmit_front_parity_err_cnt(
1962 const struct cntr_entry *entry,
1963 void *context, int vl, int mode, u64 data)
1964{
1965 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1966
1967 return dd->cce_err_status_cnt[27];
1968}
1969
1970static u64 access_pcic_cpl_dat_q_unc_err_cnt(const struct cntr_entry *entry,
1971 void *context, int vl, int mode,
1972 u64 data)
1973{
1974 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1975
1976 return dd->cce_err_status_cnt[26];
1977}
1978
1979static u64 access_pcic_cpl_hd_q_unc_err_cnt(const struct cntr_entry *entry,
1980 void *context, int vl, int mode,
1981 u64 data)
1982{
1983 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1984
1985 return dd->cce_err_status_cnt[25];
1986}
1987
1988static u64 access_pcic_post_dat_q_unc_err_cnt(const struct cntr_entry *entry,
1989 void *context, int vl, int mode,
1990 u64 data)
1991{
1992 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1993
1994 return dd->cce_err_status_cnt[24];
1995}
1996
1997static u64 access_pcic_post_hd_q_unc_err_cnt(const struct cntr_entry *entry,
1998 void *context, int vl, int mode,
1999 u64 data)
2000{
2001 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2002
2003 return dd->cce_err_status_cnt[23];
2004}
2005
2006static u64 access_pcic_retry_sot_mem_unc_err_cnt(const struct cntr_entry *entry,
2007 void *context, int vl,
2008 int mode, u64 data)
2009{
2010 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2011
2012 return dd->cce_err_status_cnt[22];
2013}
2014
2015static u64 access_pcic_retry_mem_unc_err(const struct cntr_entry *entry,
2016 void *context, int vl, int mode,
2017 u64 data)
2018{
2019 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2020
2021 return dd->cce_err_status_cnt[21];
2022}
2023
2024static u64 access_pcic_n_post_dat_q_parity_err_cnt(
2025 const struct cntr_entry *entry,
2026 void *context, int vl, int mode, u64 data)
2027{
2028 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2029
2030 return dd->cce_err_status_cnt[20];
2031}
2032
2033static u64 access_pcic_n_post_h_q_parity_err_cnt(const struct cntr_entry *entry,
2034 void *context, int vl,
2035 int mode, u64 data)
2036{
2037 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2038
2039 return dd->cce_err_status_cnt[19];
2040}
2041
2042static u64 access_pcic_cpl_dat_q_cor_err_cnt(const struct cntr_entry *entry,
2043 void *context, int vl, int mode,
2044 u64 data)
2045{
2046 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2047
2048 return dd->cce_err_status_cnt[18];
2049}
2050
2051static u64 access_pcic_cpl_hd_q_cor_err_cnt(const struct cntr_entry *entry,
2052 void *context, int vl, int mode,
2053 u64 data)
2054{
2055 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2056
2057 return dd->cce_err_status_cnt[17];
2058}
2059
2060static u64 access_pcic_post_dat_q_cor_err_cnt(const struct cntr_entry *entry,
2061 void *context, int vl, int mode,
2062 u64 data)
2063{
2064 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2065
2066 return dd->cce_err_status_cnt[16];
2067}
2068
2069static u64 access_pcic_post_hd_q_cor_err_cnt(const struct cntr_entry *entry,
2070 void *context, int vl, int mode,
2071 u64 data)
2072{
2073 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2074
2075 return dd->cce_err_status_cnt[15];
2076}
2077
2078static u64 access_pcic_retry_sot_mem_cor_err_cnt(const struct cntr_entry *entry,
2079 void *context, int vl,
2080 int mode, u64 data)
2081{
2082 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2083
2084 return dd->cce_err_status_cnt[14];
2085}
2086
2087static u64 access_pcic_retry_mem_cor_err_cnt(const struct cntr_entry *entry,
2088 void *context, int vl, int mode,
2089 u64 data)
2090{
2091 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2092
2093 return dd->cce_err_status_cnt[13];
2094}
2095
2096static u64 access_cce_cli1_async_fifo_dbg_parity_err_cnt(
2097 const struct cntr_entry *entry,
2098 void *context, int vl, int mode, u64 data)
2099{
2100 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2101
2102 return dd->cce_err_status_cnt[12];
2103}
2104
2105static u64 access_cce_cli1_async_fifo_rxdma_parity_err_cnt(
2106 const struct cntr_entry *entry,
2107 void *context, int vl, int mode, u64 data)
2108{
2109 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2110
2111 return dd->cce_err_status_cnt[11];
2112}
2113
2114static u64 access_cce_cli1_async_fifo_sdma_hd_parity_err_cnt(
2115 const struct cntr_entry *entry,
2116 void *context, int vl, int mode, u64 data)
2117{
2118 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2119
2120 return dd->cce_err_status_cnt[10];
2121}
2122
2123static u64 access_cce_cl1_async_fifo_pio_crdt_parity_err_cnt(
2124 const struct cntr_entry *entry,
2125 void *context, int vl, int mode, u64 data)
2126{
2127 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2128
2129 return dd->cce_err_status_cnt[9];
2130}
2131
2132static u64 access_cce_cli2_async_fifo_parity_err_cnt(
2133 const struct cntr_entry *entry,
2134 void *context, int vl, int mode, u64 data)
2135{
2136 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2137
2138 return dd->cce_err_status_cnt[8];
2139}
2140
2141static u64 access_cce_csr_cfg_bus_parity_err_cnt(const struct cntr_entry *entry,
2142 void *context, int vl,
2143 int mode, u64 data)
2144{
2145 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2146
2147 return dd->cce_err_status_cnt[7];
2148}
2149
2150static u64 access_cce_cli0_async_fifo_parity_err_cnt(
2151 const struct cntr_entry *entry,
2152 void *context, int vl, int mode, u64 data)
2153{
2154 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2155
2156 return dd->cce_err_status_cnt[6];
2157}
2158
2159static u64 access_cce_rspd_data_parity_err_cnt(const struct cntr_entry *entry,
2160 void *context, int vl, int mode,
2161 u64 data)
2162{
2163 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2164
2165 return dd->cce_err_status_cnt[5];
2166}
2167
2168static u64 access_cce_trgt_access_err_cnt(const struct cntr_entry *entry,
2169 void *context, int vl, int mode,
2170 u64 data)
2171{
2172 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2173
2174 return dd->cce_err_status_cnt[4];
2175}
2176
2177static u64 access_cce_trgt_async_fifo_parity_err_cnt(
2178 const struct cntr_entry *entry,
2179 void *context, int vl, int mode, u64 data)
2180{
2181 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2182
2183 return dd->cce_err_status_cnt[3];
2184}
2185
2186static u64 access_cce_csr_write_bad_addr_err_cnt(const struct cntr_entry *entry,
2187 void *context, int vl,
2188 int mode, u64 data)
2189{
2190 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2191
2192 return dd->cce_err_status_cnt[2];
2193}
2194
2195static u64 access_cce_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
2196 void *context, int vl,
2197 int mode, u64 data)
2198{
2199 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2200
2201 return dd->cce_err_status_cnt[1];
2202}
2203
2204static u64 access_ccs_csr_parity_err_cnt(const struct cntr_entry *entry,
2205 void *context, int vl, int mode,
2206 u64 data)
2207{
2208 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2209
2210 return dd->cce_err_status_cnt[0];
2211}
2212
2213/*
2214 * Software counters corresponding to each of the
2215 * error status bits within RcvErrStatus
2216 */
2217static u64 access_rx_csr_parity_err_cnt(const struct cntr_entry *entry,
2218 void *context, int vl, int mode,
2219 u64 data)
2220{
2221 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2222
2223 return dd->rcv_err_status_cnt[63];
2224}
2225
2226static u64 access_rx_csr_write_bad_addr_err_cnt(const struct cntr_entry *entry,
2227 void *context, int vl,
2228 int mode, u64 data)
2229{
2230 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2231
2232 return dd->rcv_err_status_cnt[62];
2233}
2234
2235static u64 access_rx_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
2236 void *context, int vl, int mode,
2237 u64 data)
2238{
2239 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2240
2241 return dd->rcv_err_status_cnt[61];
2242}
2243
2244static u64 access_rx_dma_csr_unc_err_cnt(const struct cntr_entry *entry,
2245 void *context, int vl, int mode,
2246 u64 data)
2247{
2248 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2249
2250 return dd->rcv_err_status_cnt[60];
2251}
2252
2253static u64 access_rx_dma_dq_fsm_encoding_err_cnt(const struct cntr_entry *entry,
2254 void *context, int vl,
2255 int mode, u64 data)
2256{
2257 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2258
2259 return dd->rcv_err_status_cnt[59];
2260}
2261
2262static u64 access_rx_dma_eq_fsm_encoding_err_cnt(const struct cntr_entry *entry,
2263 void *context, int vl,
2264 int mode, u64 data)
2265{
2266 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2267
2268 return dd->rcv_err_status_cnt[58];
2269}
2270
2271static u64 access_rx_dma_csr_parity_err_cnt(const struct cntr_entry *entry,
2272 void *context, int vl, int mode,
2273 u64 data)
2274{
2275 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2276
2277 return dd->rcv_err_status_cnt[57];
2278}
2279
2280static u64 access_rx_rbuf_data_cor_err_cnt(const struct cntr_entry *entry,
2281 void *context, int vl, int mode,
2282 u64 data)
2283{
2284 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2285
2286 return dd->rcv_err_status_cnt[56];
2287}
2288
2289static u64 access_rx_rbuf_data_unc_err_cnt(const struct cntr_entry *entry,
2290 void *context, int vl, int mode,
2291 u64 data)
2292{
2293 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2294
2295 return dd->rcv_err_status_cnt[55];
2296}
2297
2298static u64 access_rx_dma_data_fifo_rd_cor_err_cnt(
2299 const struct cntr_entry *entry,
2300 void *context, int vl, int mode, u64 data)
2301{
2302 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2303
2304 return dd->rcv_err_status_cnt[54];
2305}
2306
2307static u64 access_rx_dma_data_fifo_rd_unc_err_cnt(
2308 const struct cntr_entry *entry,
2309 void *context, int vl, int mode, u64 data)
2310{
2311 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2312
2313 return dd->rcv_err_status_cnt[53];
2314}
2315
2316static u64 access_rx_dma_hdr_fifo_rd_cor_err_cnt(const struct cntr_entry *entry,
2317 void *context, int vl,
2318 int mode, u64 data)
2319{
2320 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2321
2322 return dd->rcv_err_status_cnt[52];
2323}
2324
2325static u64 access_rx_dma_hdr_fifo_rd_unc_err_cnt(const struct cntr_entry *entry,
2326 void *context, int vl,
2327 int mode, u64 data)
2328{
2329 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2330
2331 return dd->rcv_err_status_cnt[51];
2332}
2333
2334static u64 access_rx_rbuf_desc_part2_cor_err_cnt(const struct cntr_entry *entry,
2335 void *context, int vl,
2336 int mode, u64 data)
2337{
2338 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2339
2340 return dd->rcv_err_status_cnt[50];
2341}
2342
2343static u64 access_rx_rbuf_desc_part2_unc_err_cnt(const struct cntr_entry *entry,
2344 void *context, int vl,
2345 int mode, u64 data)
2346{
2347 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2348
2349 return dd->rcv_err_status_cnt[49];
2350}
2351
2352static u64 access_rx_rbuf_desc_part1_cor_err_cnt(const struct cntr_entry *entry,
2353 void *context, int vl,
2354 int mode, u64 data)
2355{
2356 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2357
2358 return dd->rcv_err_status_cnt[48];
2359}
2360
2361static u64 access_rx_rbuf_desc_part1_unc_err_cnt(const struct cntr_entry *entry,
2362 void *context, int vl,
2363 int mode, u64 data)
2364{
2365 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2366
2367 return dd->rcv_err_status_cnt[47];
2368}
2369
2370static u64 access_rx_hq_intr_fsm_err_cnt(const struct cntr_entry *entry,
2371 void *context, int vl, int mode,
2372 u64 data)
2373{
2374 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2375
2376 return dd->rcv_err_status_cnt[46];
2377}
2378
2379static u64 access_rx_hq_intr_csr_parity_err_cnt(
2380 const struct cntr_entry *entry,
2381 void *context, int vl, int mode, u64 data)
2382{
2383 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2384
2385 return dd->rcv_err_status_cnt[45];
2386}
2387
2388static u64 access_rx_lookup_csr_parity_err_cnt(
2389 const struct cntr_entry *entry,
2390 void *context, int vl, int mode, u64 data)
2391{
2392 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2393
2394 return dd->rcv_err_status_cnt[44];
2395}
2396
2397static u64 access_rx_lookup_rcv_array_cor_err_cnt(
2398 const struct cntr_entry *entry,
2399 void *context, int vl, int mode, u64 data)
2400{
2401 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2402
2403 return dd->rcv_err_status_cnt[43];
2404}
2405
2406static u64 access_rx_lookup_rcv_array_unc_err_cnt(
2407 const struct cntr_entry *entry,
2408 void *context, int vl, int mode, u64 data)
2409{
2410 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2411
2412 return dd->rcv_err_status_cnt[42];
2413}
2414
2415static u64 access_rx_lookup_des_part2_parity_err_cnt(
2416 const struct cntr_entry *entry,
2417 void *context, int vl, int mode, u64 data)
2418{
2419 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2420
2421 return dd->rcv_err_status_cnt[41];
2422}
2423
2424static u64 access_rx_lookup_des_part1_unc_cor_err_cnt(
2425 const struct cntr_entry *entry,
2426 void *context, int vl, int mode, u64 data)
2427{
2428 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2429
2430 return dd->rcv_err_status_cnt[40];
2431}
2432
2433static u64 access_rx_lookup_des_part1_unc_err_cnt(
2434 const struct cntr_entry *entry,
2435 void *context, int vl, int mode, u64 data)
2436{
2437 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2438
2439 return dd->rcv_err_status_cnt[39];
2440}
2441
2442static u64 access_rx_rbuf_next_free_buf_cor_err_cnt(
2443 const struct cntr_entry *entry,
2444 void *context, int vl, int mode, u64 data)
2445{
2446 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2447
2448 return dd->rcv_err_status_cnt[38];
2449}
2450
2451static u64 access_rx_rbuf_next_free_buf_unc_err_cnt(
2452 const struct cntr_entry *entry,
2453 void *context, int vl, int mode, u64 data)
2454{
2455 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2456
2457 return dd->rcv_err_status_cnt[37];
2458}
2459
2460static u64 access_rbuf_fl_init_wr_addr_parity_err_cnt(
2461 const struct cntr_entry *entry,
2462 void *context, int vl, int mode, u64 data)
2463{
2464 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2465
2466 return dd->rcv_err_status_cnt[36];
2467}
2468
2469static u64 access_rx_rbuf_fl_initdone_parity_err_cnt(
2470 const struct cntr_entry *entry,
2471 void *context, int vl, int mode, u64 data)
2472{
2473 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2474
2475 return dd->rcv_err_status_cnt[35];
2476}
2477
2478static u64 access_rx_rbuf_fl_write_addr_parity_err_cnt(
2479 const struct cntr_entry *entry,
2480 void *context, int vl, int mode, u64 data)
2481{
2482 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2483
2484 return dd->rcv_err_status_cnt[34];
2485}
2486
2487static u64 access_rx_rbuf_fl_rd_addr_parity_err_cnt(
2488 const struct cntr_entry *entry,
2489 void *context, int vl, int mode, u64 data)
2490{
2491 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2492
2493 return dd->rcv_err_status_cnt[33];
2494}
2495
2496static u64 access_rx_rbuf_empty_err_cnt(const struct cntr_entry *entry,
2497 void *context, int vl, int mode,
2498 u64 data)
2499{
2500 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2501
2502 return dd->rcv_err_status_cnt[32];
2503}
2504
2505static u64 access_rx_rbuf_full_err_cnt(const struct cntr_entry *entry,
2506 void *context, int vl, int mode,
2507 u64 data)
2508{
2509 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2510
2511 return dd->rcv_err_status_cnt[31];
2512}
2513
2514static u64 access_rbuf_bad_lookup_err_cnt(const struct cntr_entry *entry,
2515 void *context, int vl, int mode,
2516 u64 data)
2517{
2518 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2519
2520 return dd->rcv_err_status_cnt[30];
2521}
2522
2523static u64 access_rbuf_ctx_id_parity_err_cnt(const struct cntr_entry *entry,
2524 void *context, int vl, int mode,
2525 u64 data)
2526{
2527 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2528
2529 return dd->rcv_err_status_cnt[29];
2530}
2531
2532static u64 access_rbuf_csr_qeopdw_parity_err_cnt(const struct cntr_entry *entry,
2533 void *context, int vl,
2534 int mode, u64 data)
2535{
2536 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2537
2538 return dd->rcv_err_status_cnt[28];
2539}
2540
2541static u64 access_rx_rbuf_csr_q_num_of_pkt_parity_err_cnt(
2542 const struct cntr_entry *entry,
2543 void *context, int vl, int mode, u64 data)
2544{
2545 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2546
2547 return dd->rcv_err_status_cnt[27];
2548}
2549
2550static u64 access_rx_rbuf_csr_q_t1_ptr_parity_err_cnt(
2551 const struct cntr_entry *entry,
2552 void *context, int vl, int mode, u64 data)
2553{
2554 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2555
2556 return dd->rcv_err_status_cnt[26];
2557}
2558
2559static u64 access_rx_rbuf_csr_q_hd_ptr_parity_err_cnt(
2560 const struct cntr_entry *entry,
2561 void *context, int vl, int mode, u64 data)
2562{
2563 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2564
2565 return dd->rcv_err_status_cnt[25];
2566}
2567
2568static u64 access_rx_rbuf_csr_q_vld_bit_parity_err_cnt(
2569 const struct cntr_entry *entry,
2570 void *context, int vl, int mode, u64 data)
2571{
2572 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2573
2574 return dd->rcv_err_status_cnt[24];
2575}
2576
2577static u64 access_rx_rbuf_csr_q_next_buf_parity_err_cnt(
2578 const struct cntr_entry *entry,
2579 void *context, int vl, int mode, u64 data)
2580{
2581 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2582
2583 return dd->rcv_err_status_cnt[23];
2584}
2585
2586static u64 access_rx_rbuf_csr_q_ent_cnt_parity_err_cnt(
2587 const struct cntr_entry *entry,
2588 void *context, int vl, int mode, u64 data)
2589{
2590 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2591
2592 return dd->rcv_err_status_cnt[22];
2593}
2594
2595static u64 access_rx_rbuf_csr_q_head_buf_num_parity_err_cnt(
2596 const struct cntr_entry *entry,
2597 void *context, int vl, int mode, u64 data)
2598{
2599 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2600
2601 return dd->rcv_err_status_cnt[21];
2602}
2603
2604static u64 access_rx_rbuf_block_list_read_cor_err_cnt(
2605 const struct cntr_entry *entry,
2606 void *context, int vl, int mode, u64 data)
2607{
2608 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2609
2610 return dd->rcv_err_status_cnt[20];
2611}
2612
2613static u64 access_rx_rbuf_block_list_read_unc_err_cnt(
2614 const struct cntr_entry *entry,
2615 void *context, int vl, int mode, u64 data)
2616{
2617 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2618
2619 return dd->rcv_err_status_cnt[19];
2620}
2621
2622static u64 access_rx_rbuf_lookup_des_cor_err_cnt(const struct cntr_entry *entry,
2623 void *context, int vl,
2624 int mode, u64 data)
2625{
2626 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2627
2628 return dd->rcv_err_status_cnt[18];
2629}
2630
2631static u64 access_rx_rbuf_lookup_des_unc_err_cnt(const struct cntr_entry *entry,
2632 void *context, int vl,
2633 int mode, u64 data)
2634{
2635 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2636
2637 return dd->rcv_err_status_cnt[17];
2638}
2639
2640static u64 access_rx_rbuf_lookup_des_reg_unc_cor_err_cnt(
2641 const struct cntr_entry *entry,
2642 void *context, int vl, int mode, u64 data)
2643{
2644 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2645
2646 return dd->rcv_err_status_cnt[16];
2647}
2648
2649static u64 access_rx_rbuf_lookup_des_reg_unc_err_cnt(
2650 const struct cntr_entry *entry,
2651 void *context, int vl, int mode, u64 data)
2652{
2653 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2654
2655 return dd->rcv_err_status_cnt[15];
2656}
2657
2658static u64 access_rx_rbuf_free_list_cor_err_cnt(const struct cntr_entry *entry,
2659 void *context, int vl,
2660 int mode, u64 data)
2661{
2662 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2663
2664 return dd->rcv_err_status_cnt[14];
2665}
2666
2667static u64 access_rx_rbuf_free_list_unc_err_cnt(const struct cntr_entry *entry,
2668 void *context, int vl,
2669 int mode, u64 data)
2670{
2671 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2672
2673 return dd->rcv_err_status_cnt[13];
2674}
2675
2676static u64 access_rx_rcv_fsm_encoding_err_cnt(const struct cntr_entry *entry,
2677 void *context, int vl, int mode,
2678 u64 data)
2679{
2680 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2681
2682 return dd->rcv_err_status_cnt[12];
2683}
2684
2685static u64 access_rx_dma_flag_cor_err_cnt(const struct cntr_entry *entry,
2686 void *context, int vl, int mode,
2687 u64 data)
2688{
2689 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2690
2691 return dd->rcv_err_status_cnt[11];
2692}
2693
2694static u64 access_rx_dma_flag_unc_err_cnt(const struct cntr_entry *entry,
2695 void *context, int vl, int mode,
2696 u64 data)
2697{
2698 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2699
2700 return dd->rcv_err_status_cnt[10];
2701}
2702
2703static u64 access_rx_dc_sop_eop_parity_err_cnt(const struct cntr_entry *entry,
2704 void *context, int vl, int mode,
2705 u64 data)
2706{
2707 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2708
2709 return dd->rcv_err_status_cnt[9];
2710}
2711
2712static u64 access_rx_rcv_csr_parity_err_cnt(const struct cntr_entry *entry,
2713 void *context, int vl, int mode,
2714 u64 data)
2715{
2716 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2717
2718 return dd->rcv_err_status_cnt[8];
2719}
2720
2721static u64 access_rx_rcv_qp_map_table_cor_err_cnt(
2722 const struct cntr_entry *entry,
2723 void *context, int vl, int mode, u64 data)
2724{
2725 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2726
2727 return dd->rcv_err_status_cnt[7];
2728}
2729
2730static u64 access_rx_rcv_qp_map_table_unc_err_cnt(
2731 const struct cntr_entry *entry,
2732 void *context, int vl, int mode, u64 data)
2733{
2734 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2735
2736 return dd->rcv_err_status_cnt[6];
2737}
2738
2739static u64 access_rx_rcv_data_cor_err_cnt(const struct cntr_entry *entry,
2740 void *context, int vl, int mode,
2741 u64 data)
2742{
2743 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2744
2745 return dd->rcv_err_status_cnt[5];
2746}
2747
2748static u64 access_rx_rcv_data_unc_err_cnt(const struct cntr_entry *entry,
2749 void *context, int vl, int mode,
2750 u64 data)
2751{
2752 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2753
2754 return dd->rcv_err_status_cnt[4];
2755}
2756
2757static u64 access_rx_rcv_hdr_cor_err_cnt(const struct cntr_entry *entry,
2758 void *context, int vl, int mode,
2759 u64 data)
2760{
2761 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2762
2763 return dd->rcv_err_status_cnt[3];
2764}
2765
2766static u64 access_rx_rcv_hdr_unc_err_cnt(const struct cntr_entry *entry,
2767 void *context, int vl, int mode,
2768 u64 data)
2769{
2770 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2771
2772 return dd->rcv_err_status_cnt[2];
2773}
2774
2775static u64 access_rx_dc_intf_parity_err_cnt(const struct cntr_entry *entry,
2776 void *context, int vl, int mode,
2777 u64 data)
2778{
2779 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2780
2781 return dd->rcv_err_status_cnt[1];
2782}
2783
2784static u64 access_rx_dma_csr_cor_err_cnt(const struct cntr_entry *entry,
2785 void *context, int vl, int mode,
2786 u64 data)
2787{
2788 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2789
2790 return dd->rcv_err_status_cnt[0];
2791}
2792
2793/*
2794 * Software counters corresponding to each of the
2795 * error status bits within SendPioErrStatus
2796 */
2797static u64 access_pio_pec_sop_head_parity_err_cnt(
2798 const struct cntr_entry *entry,
2799 void *context, int vl, int mode, u64 data)
2800{
2801 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2802
2803 return dd->send_pio_err_status_cnt[35];
2804}
2805
2806static u64 access_pio_pcc_sop_head_parity_err_cnt(
2807 const struct cntr_entry *entry,
2808 void *context, int vl, int mode, u64 data)
2809{
2810 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2811
2812 return dd->send_pio_err_status_cnt[34];
2813}
2814
2815static u64 access_pio_last_returned_cnt_parity_err_cnt(
2816 const struct cntr_entry *entry,
2817 void *context, int vl, int mode, u64 data)
2818{
2819 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2820
2821 return dd->send_pio_err_status_cnt[33];
2822}
2823
2824static u64 access_pio_current_free_cnt_parity_err_cnt(
2825 const struct cntr_entry *entry,
2826 void *context, int vl, int mode, u64 data)
2827{
2828 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2829
2830 return dd->send_pio_err_status_cnt[32];
2831}
2832
2833static u64 access_pio_reserved_31_err_cnt(const struct cntr_entry *entry,
2834 void *context, int vl, int mode,
2835 u64 data)
2836{
2837 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2838
2839 return dd->send_pio_err_status_cnt[31];
2840}
2841
2842static u64 access_pio_reserved_30_err_cnt(const struct cntr_entry *entry,
2843 void *context, int vl, int mode,
2844 u64 data)
2845{
2846 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2847
2848 return dd->send_pio_err_status_cnt[30];
2849}
2850
2851static u64 access_pio_ppmc_sop_len_err_cnt(const struct cntr_entry *entry,
2852 void *context, int vl, int mode,
2853 u64 data)
2854{
2855 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2856
2857 return dd->send_pio_err_status_cnt[29];
2858}
2859
2860static u64 access_pio_ppmc_bqc_mem_parity_err_cnt(
2861 const struct cntr_entry *entry,
2862 void *context, int vl, int mode, u64 data)
2863{
2864 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2865
2866 return dd->send_pio_err_status_cnt[28];
2867}
2868
2869static u64 access_pio_vl_fifo_parity_err_cnt(const struct cntr_entry *entry,
2870 void *context, int vl, int mode,
2871 u64 data)
2872{
2873 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2874
2875 return dd->send_pio_err_status_cnt[27];
2876}
2877
2878static u64 access_pio_vlf_sop_parity_err_cnt(const struct cntr_entry *entry,
2879 void *context, int vl, int mode,
2880 u64 data)
2881{
2882 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2883
2884 return dd->send_pio_err_status_cnt[26];
2885}
2886
2887static u64 access_pio_vlf_v1_len_parity_err_cnt(const struct cntr_entry *entry,
2888 void *context, int vl,
2889 int mode, u64 data)
2890{
2891 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2892
2893 return dd->send_pio_err_status_cnt[25];
2894}
2895
2896static u64 access_pio_block_qw_count_parity_err_cnt(
2897 const struct cntr_entry *entry,
2898 void *context, int vl, int mode, u64 data)
2899{
2900 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2901
2902 return dd->send_pio_err_status_cnt[24];
2903}
2904
2905static u64 access_pio_write_qw_valid_parity_err_cnt(
2906 const struct cntr_entry *entry,
2907 void *context, int vl, int mode, u64 data)
2908{
2909 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2910
2911 return dd->send_pio_err_status_cnt[23];
2912}
2913
2914static u64 access_pio_state_machine_err_cnt(const struct cntr_entry *entry,
2915 void *context, int vl, int mode,
2916 u64 data)
2917{
2918 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2919
2920 return dd->send_pio_err_status_cnt[22];
2921}
2922
2923static u64 access_pio_write_data_parity_err_cnt(const struct cntr_entry *entry,
2924 void *context, int vl,
2925 int mode, u64 data)
2926{
2927 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2928
2929 return dd->send_pio_err_status_cnt[21];
2930}
2931
2932static u64 access_pio_host_addr_mem_cor_err_cnt(const struct cntr_entry *entry,
2933 void *context, int vl,
2934 int mode, u64 data)
2935{
2936 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2937
2938 return dd->send_pio_err_status_cnt[20];
2939}
2940
2941static u64 access_pio_host_addr_mem_unc_err_cnt(const struct cntr_entry *entry,
2942 void *context, int vl,
2943 int mode, u64 data)
2944{
2945 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2946
2947 return dd->send_pio_err_status_cnt[19];
2948}
2949
2950static u64 access_pio_pkt_evict_sm_or_arb_sm_err_cnt(
2951 const struct cntr_entry *entry,
2952 void *context, int vl, int mode, u64 data)
2953{
2954 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2955
2956 return dd->send_pio_err_status_cnt[18];
2957}
2958
2959static u64 access_pio_init_sm_in_err_cnt(const struct cntr_entry *entry,
2960 void *context, int vl, int mode,
2961 u64 data)
2962{
2963 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2964
2965 return dd->send_pio_err_status_cnt[17];
2966}
2967
2968static u64 access_pio_ppmc_pbl_fifo_err_cnt(const struct cntr_entry *entry,
2969 void *context, int vl, int mode,
2970 u64 data)
2971{
2972 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2973
2974 return dd->send_pio_err_status_cnt[16];
2975}
2976
2977static u64 access_pio_credit_ret_fifo_parity_err_cnt(
2978 const struct cntr_entry *entry,
2979 void *context, int vl, int mode, u64 data)
2980{
2981 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2982
2983 return dd->send_pio_err_status_cnt[15];
2984}
2985
2986static u64 access_pio_v1_len_mem_bank1_cor_err_cnt(
2987 const struct cntr_entry *entry,
2988 void *context, int vl, int mode, u64 data)
2989{
2990 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
2991
2992 return dd->send_pio_err_status_cnt[14];
2993}
2994
2995static u64 access_pio_v1_len_mem_bank0_cor_err_cnt(
2996 const struct cntr_entry *entry,
2997 void *context, int vl, int mode, u64 data)
2998{
2999 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3000
3001 return dd->send_pio_err_status_cnt[13];
3002}
3003
3004static u64 access_pio_v1_len_mem_bank1_unc_err_cnt(
3005 const struct cntr_entry *entry,
3006 void *context, int vl, int mode, u64 data)
3007{
3008 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3009
3010 return dd->send_pio_err_status_cnt[12];
3011}
3012
3013static u64 access_pio_v1_len_mem_bank0_unc_err_cnt(
3014 const struct cntr_entry *entry,
3015 void *context, int vl, int mode, u64 data)
3016{
3017 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3018
3019 return dd->send_pio_err_status_cnt[11];
3020}
3021
3022static u64 access_pio_sm_pkt_reset_parity_err_cnt(
3023 const struct cntr_entry *entry,
3024 void *context, int vl, int mode, u64 data)
3025{
3026 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3027
3028 return dd->send_pio_err_status_cnt[10];
3029}
3030
3031static u64 access_pio_pkt_evict_fifo_parity_err_cnt(
3032 const struct cntr_entry *entry,
3033 void *context, int vl, int mode, u64 data)
3034{
3035 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3036
3037 return dd->send_pio_err_status_cnt[9];
3038}
3039
3040static u64 access_pio_sbrdctrl_crrel_fifo_parity_err_cnt(
3041 const struct cntr_entry *entry,
3042 void *context, int vl, int mode, u64 data)
3043{
3044 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3045
3046 return dd->send_pio_err_status_cnt[8];
3047}
3048
3049static u64 access_pio_sbrdctl_crrel_parity_err_cnt(
3050 const struct cntr_entry *entry,
3051 void *context, int vl, int mode, u64 data)
3052{
3053 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3054
3055 return dd->send_pio_err_status_cnt[7];
3056}
3057
3058static u64 access_pio_pec_fifo_parity_err_cnt(const struct cntr_entry *entry,
3059 void *context, int vl, int mode,
3060 u64 data)
3061{
3062 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3063
3064 return dd->send_pio_err_status_cnt[6];
3065}
3066
3067static u64 access_pio_pcc_fifo_parity_err_cnt(const struct cntr_entry *entry,
3068 void *context, int vl, int mode,
3069 u64 data)
3070{
3071 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3072
3073 return dd->send_pio_err_status_cnt[5];
3074}
3075
3076static u64 access_pio_sb_mem_fifo1_err_cnt(const struct cntr_entry *entry,
3077 void *context, int vl, int mode,
3078 u64 data)
3079{
3080 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3081
3082 return dd->send_pio_err_status_cnt[4];
3083}
3084
3085static u64 access_pio_sb_mem_fifo0_err_cnt(const struct cntr_entry *entry,
3086 void *context, int vl, int mode,
3087 u64 data)
3088{
3089 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3090
3091 return dd->send_pio_err_status_cnt[3];
3092}
3093
3094static u64 access_pio_csr_parity_err_cnt(const struct cntr_entry *entry,
3095 void *context, int vl, int mode,
3096 u64 data)
3097{
3098 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3099
3100 return dd->send_pio_err_status_cnt[2];
3101}
3102
3103static u64 access_pio_write_addr_parity_err_cnt(const struct cntr_entry *entry,
3104 void *context, int vl,
3105 int mode, u64 data)
3106{
3107 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3108
3109 return dd->send_pio_err_status_cnt[1];
3110}
3111
3112static u64 access_pio_write_bad_ctxt_err_cnt(const struct cntr_entry *entry,
3113 void *context, int vl, int mode,
3114 u64 data)
3115{
3116 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3117
3118 return dd->send_pio_err_status_cnt[0];
3119}
3120
3121/*
3122 * Software counters corresponding to each of the
3123 * error status bits within SendDmaErrStatus
3124 */
3125static u64 access_sdma_pcie_req_tracking_cor_err_cnt(
3126 const struct cntr_entry *entry,
3127 void *context, int vl, int mode, u64 data)
3128{
3129 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3130
3131 return dd->send_dma_err_status_cnt[3];
3132}
3133
3134static u64 access_sdma_pcie_req_tracking_unc_err_cnt(
3135 const struct cntr_entry *entry,
3136 void *context, int vl, int mode, u64 data)
3137{
3138 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3139
3140 return dd->send_dma_err_status_cnt[2];
3141}
3142
3143static u64 access_sdma_csr_parity_err_cnt(const struct cntr_entry *entry,
3144 void *context, int vl, int mode,
3145 u64 data)
3146{
3147 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3148
3149 return dd->send_dma_err_status_cnt[1];
3150}
3151
3152static u64 access_sdma_rpy_tag_err_cnt(const struct cntr_entry *entry,
3153 void *context, int vl, int mode,
3154 u64 data)
3155{
3156 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3157
3158 return dd->send_dma_err_status_cnt[0];
3159}
3160
3161/*
3162 * Software counters corresponding to each of the
3163 * error status bits within SendEgressErrStatus
3164 */
3165static u64 access_tx_read_pio_memory_csr_unc_err_cnt(
3166 const struct cntr_entry *entry,
3167 void *context, int vl, int mode, u64 data)
3168{
3169 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3170
3171 return dd->send_egress_err_status_cnt[63];
3172}
3173
3174static u64 access_tx_read_sdma_memory_csr_err_cnt(
3175 const struct cntr_entry *entry,
3176 void *context, int vl, int mode, u64 data)
3177{
3178 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3179
3180 return dd->send_egress_err_status_cnt[62];
3181}
3182
3183static u64 access_tx_egress_fifo_cor_err_cnt(const struct cntr_entry *entry,
3184 void *context, int vl, int mode,
3185 u64 data)
3186{
3187 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3188
3189 return dd->send_egress_err_status_cnt[61];
3190}
3191
3192static u64 access_tx_read_pio_memory_cor_err_cnt(const struct cntr_entry *entry,
3193 void *context, int vl,
3194 int mode, u64 data)
3195{
3196 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3197
3198 return dd->send_egress_err_status_cnt[60];
3199}
3200
3201static u64 access_tx_read_sdma_memory_cor_err_cnt(
3202 const struct cntr_entry *entry,
3203 void *context, int vl, int mode, u64 data)
3204{
3205 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3206
3207 return dd->send_egress_err_status_cnt[59];
3208}
3209
3210static u64 access_tx_sb_hdr_cor_err_cnt(const struct cntr_entry *entry,
3211 void *context, int vl, int mode,
3212 u64 data)
3213{
3214 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3215
3216 return dd->send_egress_err_status_cnt[58];
3217}
3218
3219static u64 access_tx_credit_overrun_err_cnt(const struct cntr_entry *entry,
3220 void *context, int vl, int mode,
3221 u64 data)
3222{
3223 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3224
3225 return dd->send_egress_err_status_cnt[57];
3226}
3227
3228static u64 access_tx_launch_fifo8_cor_err_cnt(const struct cntr_entry *entry,
3229 void *context, int vl, int mode,
3230 u64 data)
3231{
3232 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3233
3234 return dd->send_egress_err_status_cnt[56];
3235}
3236
3237static u64 access_tx_launch_fifo7_cor_err_cnt(const struct cntr_entry *entry,
3238 void *context, int vl, int mode,
3239 u64 data)
3240{
3241 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3242
3243 return dd->send_egress_err_status_cnt[55];
3244}
3245
3246static u64 access_tx_launch_fifo6_cor_err_cnt(const struct cntr_entry *entry,
3247 void *context, int vl, int mode,
3248 u64 data)
3249{
3250 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3251
3252 return dd->send_egress_err_status_cnt[54];
3253}
3254
3255static u64 access_tx_launch_fifo5_cor_err_cnt(const struct cntr_entry *entry,
3256 void *context, int vl, int mode,
3257 u64 data)
3258{
3259 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3260
3261 return dd->send_egress_err_status_cnt[53];
3262}
3263
3264static u64 access_tx_launch_fifo4_cor_err_cnt(const struct cntr_entry *entry,
3265 void *context, int vl, int mode,
3266 u64 data)
3267{
3268 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3269
3270 return dd->send_egress_err_status_cnt[52];
3271}
3272
3273static u64 access_tx_launch_fifo3_cor_err_cnt(const struct cntr_entry *entry,
3274 void *context, int vl, int mode,
3275 u64 data)
3276{
3277 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3278
3279 return dd->send_egress_err_status_cnt[51];
3280}
3281
3282static u64 access_tx_launch_fifo2_cor_err_cnt(const struct cntr_entry *entry,
3283 void *context, int vl, int mode,
3284 u64 data)
3285{
3286 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3287
3288 return dd->send_egress_err_status_cnt[50];
3289}
3290
3291static u64 access_tx_launch_fifo1_cor_err_cnt(const struct cntr_entry *entry,
3292 void *context, int vl, int mode,
3293 u64 data)
3294{
3295 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3296
3297 return dd->send_egress_err_status_cnt[49];
3298}
3299
3300static u64 access_tx_launch_fifo0_cor_err_cnt(const struct cntr_entry *entry,
3301 void *context, int vl, int mode,
3302 u64 data)
3303{
3304 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3305
3306 return dd->send_egress_err_status_cnt[48];
3307}
3308
3309static u64 access_tx_credit_return_vl_err_cnt(const struct cntr_entry *entry,
3310 void *context, int vl, int mode,
3311 u64 data)
3312{
3313 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3314
3315 return dd->send_egress_err_status_cnt[47];
3316}
3317
3318static u64 access_tx_hcrc_insertion_err_cnt(const struct cntr_entry *entry,
3319 void *context, int vl, int mode,
3320 u64 data)
3321{
3322 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3323
3324 return dd->send_egress_err_status_cnt[46];
3325}
3326
3327static u64 access_tx_egress_fifo_unc_err_cnt(const struct cntr_entry *entry,
3328 void *context, int vl, int mode,
3329 u64 data)
3330{
3331 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3332
3333 return dd->send_egress_err_status_cnt[45];
3334}
3335
3336static u64 access_tx_read_pio_memory_unc_err_cnt(const struct cntr_entry *entry,
3337 void *context, int vl,
3338 int mode, u64 data)
3339{
3340 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3341
3342 return dd->send_egress_err_status_cnt[44];
3343}
3344
3345static u64 access_tx_read_sdma_memory_unc_err_cnt(
3346 const struct cntr_entry *entry,
3347 void *context, int vl, int mode, u64 data)
3348{
3349 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3350
3351 return dd->send_egress_err_status_cnt[43];
3352}
3353
3354static u64 access_tx_sb_hdr_unc_err_cnt(const struct cntr_entry *entry,
3355 void *context, int vl, int mode,
3356 u64 data)
3357{
3358 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3359
3360 return dd->send_egress_err_status_cnt[42];
3361}
3362
3363static u64 access_tx_credit_return_partiy_err_cnt(
3364 const struct cntr_entry *entry,
3365 void *context, int vl, int mode, u64 data)
3366{
3367 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3368
3369 return dd->send_egress_err_status_cnt[41];
3370}
3371
3372static u64 access_tx_launch_fifo8_unc_or_parity_err_cnt(
3373 const struct cntr_entry *entry,
3374 void *context, int vl, int mode, u64 data)
3375{
3376 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3377
3378 return dd->send_egress_err_status_cnt[40];
3379}
3380
3381static u64 access_tx_launch_fifo7_unc_or_parity_err_cnt(
3382 const struct cntr_entry *entry,
3383 void *context, int vl, int mode, u64 data)
3384{
3385 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3386
3387 return dd->send_egress_err_status_cnt[39];
3388}
3389
3390static u64 access_tx_launch_fifo6_unc_or_parity_err_cnt(
3391 const struct cntr_entry *entry,
3392 void *context, int vl, int mode, u64 data)
3393{
3394 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3395
3396 return dd->send_egress_err_status_cnt[38];
3397}
3398
3399static u64 access_tx_launch_fifo5_unc_or_parity_err_cnt(
3400 const struct cntr_entry *entry,
3401 void *context, int vl, int mode, u64 data)
3402{
3403 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3404
3405 return dd->send_egress_err_status_cnt[37];
3406}
3407
3408static u64 access_tx_launch_fifo4_unc_or_parity_err_cnt(
3409 const struct cntr_entry *entry,
3410 void *context, int vl, int mode, u64 data)
3411{
3412 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3413
3414 return dd->send_egress_err_status_cnt[36];
3415}
3416
3417static u64 access_tx_launch_fifo3_unc_or_parity_err_cnt(
3418 const struct cntr_entry *entry,
3419 void *context, int vl, int mode, u64 data)
3420{
3421 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3422
3423 return dd->send_egress_err_status_cnt[35];
3424}
3425
3426static u64 access_tx_launch_fifo2_unc_or_parity_err_cnt(
3427 const struct cntr_entry *entry,
3428 void *context, int vl, int mode, u64 data)
3429{
3430 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3431
3432 return dd->send_egress_err_status_cnt[34];
3433}
3434
3435static u64 access_tx_launch_fifo1_unc_or_parity_err_cnt(
3436 const struct cntr_entry *entry,
3437 void *context, int vl, int mode, u64 data)
3438{
3439 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3440
3441 return dd->send_egress_err_status_cnt[33];
3442}
3443
3444static u64 access_tx_launch_fifo0_unc_or_parity_err_cnt(
3445 const struct cntr_entry *entry,
3446 void *context, int vl, int mode, u64 data)
3447{
3448 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3449
3450 return dd->send_egress_err_status_cnt[32];
3451}
3452
3453static u64 access_tx_sdma15_disallowed_packet_err_cnt(
3454 const struct cntr_entry *entry,
3455 void *context, int vl, int mode, u64 data)
3456{
3457 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3458
3459 return dd->send_egress_err_status_cnt[31];
3460}
3461
3462static u64 access_tx_sdma14_disallowed_packet_err_cnt(
3463 const struct cntr_entry *entry,
3464 void *context, int vl, int mode, u64 data)
3465{
3466 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3467
3468 return dd->send_egress_err_status_cnt[30];
3469}
3470
3471static u64 access_tx_sdma13_disallowed_packet_err_cnt(
3472 const struct cntr_entry *entry,
3473 void *context, int vl, int mode, u64 data)
3474{
3475 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3476
3477 return dd->send_egress_err_status_cnt[29];
3478}
3479
3480static u64 access_tx_sdma12_disallowed_packet_err_cnt(
3481 const struct cntr_entry *entry,
3482 void *context, int vl, int mode, u64 data)
3483{
3484 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3485
3486 return dd->send_egress_err_status_cnt[28];
3487}
3488
3489static u64 access_tx_sdma11_disallowed_packet_err_cnt(
3490 const struct cntr_entry *entry,
3491 void *context, int vl, int mode, u64 data)
3492{
3493 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3494
3495 return dd->send_egress_err_status_cnt[27];
3496}
3497
3498static u64 access_tx_sdma10_disallowed_packet_err_cnt(
3499 const struct cntr_entry *entry,
3500 void *context, int vl, int mode, u64 data)
3501{
3502 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3503
3504 return dd->send_egress_err_status_cnt[26];
3505}
3506
3507static u64 access_tx_sdma9_disallowed_packet_err_cnt(
3508 const struct cntr_entry *entry,
3509 void *context, int vl, int mode, u64 data)
3510{
3511 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3512
3513 return dd->send_egress_err_status_cnt[25];
3514}
3515
3516static u64 access_tx_sdma8_disallowed_packet_err_cnt(
3517 const struct cntr_entry *entry,
3518 void *context, int vl, int mode, u64 data)
3519{
3520 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3521
3522 return dd->send_egress_err_status_cnt[24];
3523}
3524
3525static u64 access_tx_sdma7_disallowed_packet_err_cnt(
3526 const struct cntr_entry *entry,
3527 void *context, int vl, int mode, u64 data)
3528{
3529 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3530
3531 return dd->send_egress_err_status_cnt[23];
3532}
3533
3534static u64 access_tx_sdma6_disallowed_packet_err_cnt(
3535 const struct cntr_entry *entry,
3536 void *context, int vl, int mode, u64 data)
3537{
3538 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3539
3540 return dd->send_egress_err_status_cnt[22];
3541}
3542
3543static u64 access_tx_sdma5_disallowed_packet_err_cnt(
3544 const struct cntr_entry *entry,
3545 void *context, int vl, int mode, u64 data)
3546{
3547 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3548
3549 return dd->send_egress_err_status_cnt[21];
3550}
3551
3552static u64 access_tx_sdma4_disallowed_packet_err_cnt(
3553 const struct cntr_entry *entry,
3554 void *context, int vl, int mode, u64 data)
3555{
3556 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3557
3558 return dd->send_egress_err_status_cnt[20];
3559}
3560
3561static u64 access_tx_sdma3_disallowed_packet_err_cnt(
3562 const struct cntr_entry *entry,
3563 void *context, int vl, int mode, u64 data)
3564{
3565 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3566
3567 return dd->send_egress_err_status_cnt[19];
3568}
3569
3570static u64 access_tx_sdma2_disallowed_packet_err_cnt(
3571 const struct cntr_entry *entry,
3572 void *context, int vl, int mode, u64 data)
3573{
3574 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3575
3576 return dd->send_egress_err_status_cnt[18];
3577}
3578
3579static u64 access_tx_sdma1_disallowed_packet_err_cnt(
3580 const struct cntr_entry *entry,
3581 void *context, int vl, int mode, u64 data)
3582{
3583 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3584
3585 return dd->send_egress_err_status_cnt[17];
3586}
3587
3588static u64 access_tx_sdma0_disallowed_packet_err_cnt(
3589 const struct cntr_entry *entry,
3590 void *context, int vl, int mode, u64 data)
3591{
3592 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3593
3594 return dd->send_egress_err_status_cnt[16];
3595}
3596
3597static u64 access_tx_config_parity_err_cnt(const struct cntr_entry *entry,
3598 void *context, int vl, int mode,
3599 u64 data)
3600{
3601 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3602
3603 return dd->send_egress_err_status_cnt[15];
3604}
3605
3606static u64 access_tx_sbrd_ctl_csr_parity_err_cnt(const struct cntr_entry *entry,
3607 void *context, int vl,
3608 int mode, u64 data)
3609{
3610 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3611
3612 return dd->send_egress_err_status_cnt[14];
3613}
3614
3615static u64 access_tx_launch_csr_parity_err_cnt(const struct cntr_entry *entry,
3616 void *context, int vl, int mode,
3617 u64 data)
3618{
3619 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3620
3621 return dd->send_egress_err_status_cnt[13];
3622}
3623
3624static u64 access_tx_illegal_vl_err_cnt(const struct cntr_entry *entry,
3625 void *context, int vl, int mode,
3626 u64 data)
3627{
3628 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3629
3630 return dd->send_egress_err_status_cnt[12];
3631}
3632
3633static u64 access_tx_sbrd_ctl_state_machine_parity_err_cnt(
3634 const struct cntr_entry *entry,
3635 void *context, int vl, int mode, u64 data)
3636{
3637 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3638
3639 return dd->send_egress_err_status_cnt[11];
3640}
3641
3642static u64 access_egress_reserved_10_err_cnt(const struct cntr_entry *entry,
3643 void *context, int vl, int mode,
3644 u64 data)
3645{
3646 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3647
3648 return dd->send_egress_err_status_cnt[10];
3649}
3650
3651static u64 access_egress_reserved_9_err_cnt(const struct cntr_entry *entry,
3652 void *context, int vl, int mode,
3653 u64 data)
3654{
3655 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3656
3657 return dd->send_egress_err_status_cnt[9];
3658}
3659
3660static u64 access_tx_sdma_launch_intf_parity_err_cnt(
3661 const struct cntr_entry *entry,
3662 void *context, int vl, int mode, u64 data)
3663{
3664 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3665
3666 return dd->send_egress_err_status_cnt[8];
3667}
3668
3669static u64 access_tx_pio_launch_intf_parity_err_cnt(
3670 const struct cntr_entry *entry,
3671 void *context, int vl, int mode, u64 data)
3672{
3673 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3674
3675 return dd->send_egress_err_status_cnt[7];
3676}
3677
3678static u64 access_egress_reserved_6_err_cnt(const struct cntr_entry *entry,
3679 void *context, int vl, int mode,
3680 u64 data)
3681{
3682 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3683
3684 return dd->send_egress_err_status_cnt[6];
3685}
3686
3687static u64 access_tx_incorrect_link_state_err_cnt(
3688 const struct cntr_entry *entry,
3689 void *context, int vl, int mode, u64 data)
3690{
3691 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3692
3693 return dd->send_egress_err_status_cnt[5];
3694}
3695
3696static u64 access_tx_linkdown_err_cnt(const struct cntr_entry *entry,
3697 void *context, int vl, int mode,
3698 u64 data)
3699{
3700 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3701
3702 return dd->send_egress_err_status_cnt[4];
3703}
3704
3705static u64 access_tx_egress_fifi_underrun_or_parity_err_cnt(
3706 const struct cntr_entry *entry,
3707 void *context, int vl, int mode, u64 data)
3708{
3709 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3710
3711 return dd->send_egress_err_status_cnt[3];
3712}
3713
3714static u64 access_egress_reserved_2_err_cnt(const struct cntr_entry *entry,
3715 void *context, int vl, int mode,
3716 u64 data)
3717{
3718 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3719
3720 return dd->send_egress_err_status_cnt[2];
3721}
3722
3723static u64 access_tx_pkt_integrity_mem_unc_err_cnt(
3724 const struct cntr_entry *entry,
3725 void *context, int vl, int mode, u64 data)
3726{
3727 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3728
3729 return dd->send_egress_err_status_cnt[1];
3730}
3731
3732static u64 access_tx_pkt_integrity_mem_cor_err_cnt(
3733 const struct cntr_entry *entry,
3734 void *context, int vl, int mode, u64 data)
3735{
3736 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3737
3738 return dd->send_egress_err_status_cnt[0];
3739}
3740
3741/*
3742 * Software counters corresponding to each of the
3743 * error status bits within SendErrStatus
3744 */
3745static u64 access_send_csr_write_bad_addr_err_cnt(
3746 const struct cntr_entry *entry,
3747 void *context, int vl, int mode, u64 data)
3748{
3749 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3750
3751 return dd->send_err_status_cnt[2];
3752}
3753
3754static u64 access_send_csr_read_bad_addr_err_cnt(const struct cntr_entry *entry,
3755 void *context, int vl,
3756 int mode, u64 data)
3757{
3758 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3759
3760 return dd->send_err_status_cnt[1];
3761}
3762
3763static u64 access_send_csr_parity_cnt(const struct cntr_entry *entry,
3764 void *context, int vl, int mode,
3765 u64 data)
3766{
3767 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3768
3769 return dd->send_err_status_cnt[0];
3770}
3771
3772/*
3773 * Software counters corresponding to each of the
3774 * error status bits within SendCtxtErrStatus
3775 */
3776static u64 access_pio_write_out_of_bounds_err_cnt(
3777 const struct cntr_entry *entry,
3778 void *context, int vl, int mode, u64 data)
3779{
3780 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3781
3782 return dd->sw_ctxt_err_status_cnt[4];
3783}
3784
3785static u64 access_pio_write_overflow_err_cnt(const struct cntr_entry *entry,
3786 void *context, int vl, int mode,
3787 u64 data)
3788{
3789 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3790
3791 return dd->sw_ctxt_err_status_cnt[3];
3792}
3793
3794static u64 access_pio_write_crosses_boundary_err_cnt(
3795 const struct cntr_entry *entry,
3796 void *context, int vl, int mode, u64 data)
3797{
3798 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3799
3800 return dd->sw_ctxt_err_status_cnt[2];
3801}
3802
3803static u64 access_pio_disallowed_packet_err_cnt(const struct cntr_entry *entry,
3804 void *context, int vl,
3805 int mode, u64 data)
3806{
3807 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3808
3809 return dd->sw_ctxt_err_status_cnt[1];
3810}
3811
3812static u64 access_pio_inconsistent_sop_err_cnt(const struct cntr_entry *entry,
3813 void *context, int vl, int mode,
3814 u64 data)
3815{
3816 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3817
3818 return dd->sw_ctxt_err_status_cnt[0];
3819}
3820
3821/*
3822 * Software counters corresponding to each of the
3823 * error status bits within SendDmaEngErrStatus
3824 */
3825static u64 access_sdma_header_request_fifo_cor_err_cnt(
3826 const struct cntr_entry *entry,
3827 void *context, int vl, int mode, u64 data)
3828{
3829 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3830
3831 return dd->sw_send_dma_eng_err_status_cnt[23];
3832}
3833
3834static u64 access_sdma_header_storage_cor_err_cnt(
3835 const struct cntr_entry *entry,
3836 void *context, int vl, int mode, u64 data)
3837{
3838 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3839
3840 return dd->sw_send_dma_eng_err_status_cnt[22];
3841}
3842
3843static u64 access_sdma_packet_tracking_cor_err_cnt(
3844 const struct cntr_entry *entry,
3845 void *context, int vl, int mode, u64 data)
3846{
3847 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3848
3849 return dd->sw_send_dma_eng_err_status_cnt[21];
3850}
3851
3852static u64 access_sdma_assembly_cor_err_cnt(const struct cntr_entry *entry,
3853 void *context, int vl, int mode,
3854 u64 data)
3855{
3856 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3857
3858 return dd->sw_send_dma_eng_err_status_cnt[20];
3859}
3860
3861static u64 access_sdma_desc_table_cor_err_cnt(const struct cntr_entry *entry,
3862 void *context, int vl, int mode,
3863 u64 data)
3864{
3865 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3866
3867 return dd->sw_send_dma_eng_err_status_cnt[19];
3868}
3869
3870static u64 access_sdma_header_request_fifo_unc_err_cnt(
3871 const struct cntr_entry *entry,
3872 void *context, int vl, int mode, u64 data)
3873{
3874 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3875
3876 return dd->sw_send_dma_eng_err_status_cnt[18];
3877}
3878
3879static u64 access_sdma_header_storage_unc_err_cnt(
3880 const struct cntr_entry *entry,
3881 void *context, int vl, int mode, u64 data)
3882{
3883 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3884
3885 return dd->sw_send_dma_eng_err_status_cnt[17];
3886}
3887
3888static u64 access_sdma_packet_tracking_unc_err_cnt(
3889 const struct cntr_entry *entry,
3890 void *context, int vl, int mode, u64 data)
3891{
3892 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3893
3894 return dd->sw_send_dma_eng_err_status_cnt[16];
3895}
3896
3897static u64 access_sdma_assembly_unc_err_cnt(const struct cntr_entry *entry,
3898 void *context, int vl, int mode,
3899 u64 data)
3900{
3901 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3902
3903 return dd->sw_send_dma_eng_err_status_cnt[15];
3904}
3905
3906static u64 access_sdma_desc_table_unc_err_cnt(const struct cntr_entry *entry,
3907 void *context, int vl, int mode,
3908 u64 data)
3909{
3910 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3911
3912 return dd->sw_send_dma_eng_err_status_cnt[14];
3913}
3914
3915static u64 access_sdma_timeout_err_cnt(const struct cntr_entry *entry,
3916 void *context, int vl, int mode,
3917 u64 data)
3918{
3919 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3920
3921 return dd->sw_send_dma_eng_err_status_cnt[13];
3922}
3923
3924static u64 access_sdma_header_length_err_cnt(const struct cntr_entry *entry,
3925 void *context, int vl, int mode,
3926 u64 data)
3927{
3928 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3929
3930 return dd->sw_send_dma_eng_err_status_cnt[12];
3931}
3932
3933static u64 access_sdma_header_address_err_cnt(const struct cntr_entry *entry,
3934 void *context, int vl, int mode,
3935 u64 data)
3936{
3937 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3938
3939 return dd->sw_send_dma_eng_err_status_cnt[11];
3940}
3941
3942static u64 access_sdma_header_select_err_cnt(const struct cntr_entry *entry,
3943 void *context, int vl, int mode,
3944 u64 data)
3945{
3946 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3947
3948 return dd->sw_send_dma_eng_err_status_cnt[10];
3949}
3950
3951static u64 access_sdma_reserved_9_err_cnt(const struct cntr_entry *entry,
3952 void *context, int vl, int mode,
3953 u64 data)
3954{
3955 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3956
3957 return dd->sw_send_dma_eng_err_status_cnt[9];
3958}
3959
3960static u64 access_sdma_packet_desc_overflow_err_cnt(
3961 const struct cntr_entry *entry,
3962 void *context, int vl, int mode, u64 data)
3963{
3964 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3965
3966 return dd->sw_send_dma_eng_err_status_cnt[8];
3967}
3968
3969static u64 access_sdma_length_mismatch_err_cnt(const struct cntr_entry *entry,
3970 void *context, int vl,
3971 int mode, u64 data)
3972{
3973 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3974
3975 return dd->sw_send_dma_eng_err_status_cnt[7];
3976}
3977
3978static u64 access_sdma_halt_err_cnt(const struct cntr_entry *entry,
3979 void *context, int vl, int mode, u64 data)
3980{
3981 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3982
3983 return dd->sw_send_dma_eng_err_status_cnt[6];
3984}
3985
3986static u64 access_sdma_mem_read_err_cnt(const struct cntr_entry *entry,
3987 void *context, int vl, int mode,
3988 u64 data)
3989{
3990 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
3991
3992 return dd->sw_send_dma_eng_err_status_cnt[5];
3993}
3994
3995static u64 access_sdma_first_desc_err_cnt(const struct cntr_entry *entry,
3996 void *context, int vl, int mode,
3997 u64 data)
3998{
3999 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
4000
4001 return dd->sw_send_dma_eng_err_status_cnt[4];
4002}
4003
4004static u64 access_sdma_tail_out_of_bounds_err_cnt(
4005 const struct cntr_entry *entry,
4006 void *context, int vl, int mode, u64 data)
4007{
4008 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
4009
4010 return dd->sw_send_dma_eng_err_status_cnt[3];
4011}
4012
4013static u64 access_sdma_too_long_err_cnt(const struct cntr_entry *entry,
4014 void *context, int vl, int mode,
4015 u64 data)
4016{
4017 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
4018
4019 return dd->sw_send_dma_eng_err_status_cnt[2];
4020}
4021
4022static u64 access_sdma_gen_mismatch_err_cnt(const struct cntr_entry *entry,
4023 void *context, int vl, int mode,
4024 u64 data)
4025{
4026 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
4027
4028 return dd->sw_send_dma_eng_err_status_cnt[1];
4029}
4030
4031static u64 access_sdma_wrong_dw_err_cnt(const struct cntr_entry *entry,
4032 void *context, int vl, int mode,
4033 u64 data)
4034{
4035 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
4036
4037 return dd->sw_send_dma_eng_err_status_cnt[0];
4038}
4039
Jakub Pawlak2b719042016-07-01 16:01:22 -07004040static u64 access_dc_rcv_err_cnt(const struct cntr_entry *entry,
4041 void *context, int vl, int mode,
4042 u64 data)
4043{
4044 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
4045
4046 u64 val = 0;
4047 u64 csr = entry->csr;
4048
4049 val = read_write_csr(dd, csr, mode, data);
4050 if (mode == CNTR_MODE_R) {
4051 val = val > CNTR_MAX - dd->sw_rcv_bypass_packet_errors ?
4052 CNTR_MAX : val + dd->sw_rcv_bypass_packet_errors;
4053 } else if (mode == CNTR_MODE_W) {
4054 dd->sw_rcv_bypass_packet_errors = 0;
4055 } else {
4056 dd_dev_err(dd, "Invalid cntr register access mode");
4057 return 0;
4058 }
4059 return val;
4060}
4061
Mike Marciniszyn77241052015-07-30 15:17:43 -04004062#define def_access_sw_cpu(cntr) \
4063static u64 access_sw_cpu_##cntr(const struct cntr_entry *entry, \
4064 void *context, int vl, int mode, u64 data) \
4065{ \
4066 struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \
Dennis Dalessandro4eb06882016-01-19 14:42:39 -08004067 return read_write_cpu(ppd->dd, &ppd->ibport_data.rvp.z_ ##cntr, \
4068 ppd->ibport_data.rvp.cntr, vl, \
Mike Marciniszyn77241052015-07-30 15:17:43 -04004069 mode, data); \
4070}
4071
4072def_access_sw_cpu(rc_acks);
4073def_access_sw_cpu(rc_qacks);
4074def_access_sw_cpu(rc_delayed_comp);
4075
4076#define def_access_ibp_counter(cntr) \
4077static u64 access_ibp_##cntr(const struct cntr_entry *entry, \
4078 void *context, int vl, int mode, u64 data) \
4079{ \
4080 struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \
4081 \
4082 if (vl != CNTR_INVALID_VL) \
4083 return 0; \
4084 \
Dennis Dalessandro4eb06882016-01-19 14:42:39 -08004085 return read_write_sw(ppd->dd, &ppd->ibport_data.rvp.n_ ##cntr, \
Mike Marciniszyn77241052015-07-30 15:17:43 -04004086 mode, data); \
4087}
4088
4089def_access_ibp_counter(loop_pkts);
4090def_access_ibp_counter(rc_resends);
4091def_access_ibp_counter(rnr_naks);
4092def_access_ibp_counter(other_naks);
4093def_access_ibp_counter(rc_timeouts);
4094def_access_ibp_counter(pkt_drops);
4095def_access_ibp_counter(dmawait);
4096def_access_ibp_counter(rc_seqnak);
4097def_access_ibp_counter(rc_dupreq);
4098def_access_ibp_counter(rdma_seq);
4099def_access_ibp_counter(unaligned);
4100def_access_ibp_counter(seq_naks);
4101
4102static struct cntr_entry dev_cntrs[DEV_CNTR_LAST] = {
4103[C_RCV_OVF] = RXE32_DEV_CNTR_ELEM(RcvOverflow, RCV_BUF_OVFL_CNT, CNTR_SYNTH),
4104[C_RX_TID_FULL] = RXE32_DEV_CNTR_ELEM(RxTIDFullEr, RCV_TID_FULL_ERR_CNT,
4105 CNTR_NORMAL),
4106[C_RX_TID_INVALID] = RXE32_DEV_CNTR_ELEM(RxTIDInvalid, RCV_TID_VALID_ERR_CNT,
4107 CNTR_NORMAL),
4108[C_RX_TID_FLGMS] = RXE32_DEV_CNTR_ELEM(RxTidFLGMs,
4109 RCV_TID_FLOW_GEN_MISMATCH_CNT,
4110 CNTR_NORMAL),
Mike Marciniszyn77241052015-07-30 15:17:43 -04004111[C_RX_CTX_EGRS] = RXE32_DEV_CNTR_ELEM(RxCtxEgrS, RCV_CONTEXT_EGR_STALL,
4112 CNTR_NORMAL),
4113[C_RCV_TID_FLSMS] = RXE32_DEV_CNTR_ELEM(RxTidFLSMs,
4114 RCV_TID_FLOW_SEQ_MISMATCH_CNT, CNTR_NORMAL),
4115[C_CCE_PCI_CR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePciCrSt,
4116 CCE_PCIE_POSTED_CRDT_STALL_CNT, CNTR_NORMAL),
4117[C_CCE_PCI_TR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePciTrSt, CCE_PCIE_TRGT_STALL_CNT,
4118 CNTR_NORMAL),
4119[C_CCE_PIO_WR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePioWrSt, CCE_PIO_WR_STALL_CNT,
4120 CNTR_NORMAL),
4121[C_CCE_ERR_INT] = CCE_INT_DEV_CNTR_ELEM(CceErrInt, CCE_ERR_INT_CNT,
4122 CNTR_NORMAL),
4123[C_CCE_SDMA_INT] = CCE_INT_DEV_CNTR_ELEM(CceSdmaInt, CCE_SDMA_INT_CNT,
4124 CNTR_NORMAL),
4125[C_CCE_MISC_INT] = CCE_INT_DEV_CNTR_ELEM(CceMiscInt, CCE_MISC_INT_CNT,
4126 CNTR_NORMAL),
4127[C_CCE_RCV_AV_INT] = CCE_INT_DEV_CNTR_ELEM(CceRcvAvInt, CCE_RCV_AVAIL_INT_CNT,
4128 CNTR_NORMAL),
4129[C_CCE_RCV_URG_INT] = CCE_INT_DEV_CNTR_ELEM(CceRcvUrgInt,
4130 CCE_RCV_URGENT_INT_CNT, CNTR_NORMAL),
4131[C_CCE_SEND_CR_INT] = CCE_INT_DEV_CNTR_ELEM(CceSndCrInt,
4132 CCE_SEND_CREDIT_INT_CNT, CNTR_NORMAL),
4133[C_DC_UNC_ERR] = DC_PERF_CNTR(DcUnctblErr, DCC_ERR_UNCORRECTABLE_CNT,
4134 CNTR_SYNTH),
Jakub Pawlak2b719042016-07-01 16:01:22 -07004135[C_DC_RCV_ERR] = CNTR_ELEM("DcRecvErr", DCC_ERR_PORTRCV_ERR_CNT, 0, CNTR_SYNTH,
4136 access_dc_rcv_err_cnt),
Mike Marciniszyn77241052015-07-30 15:17:43 -04004137[C_DC_FM_CFG_ERR] = DC_PERF_CNTR(DcFmCfgErr, DCC_ERR_FMCONFIG_ERR_CNT,
4138 CNTR_SYNTH),
4139[C_DC_RMT_PHY_ERR] = DC_PERF_CNTR(DcRmtPhyErr, DCC_ERR_RCVREMOTE_PHY_ERR_CNT,
4140 CNTR_SYNTH),
4141[C_DC_DROPPED_PKT] = DC_PERF_CNTR(DcDroppedPkt, DCC_ERR_DROPPED_PKT_CNT,
4142 CNTR_SYNTH),
4143[C_DC_MC_XMIT_PKTS] = DC_PERF_CNTR(DcMcXmitPkts,
4144 DCC_PRF_PORT_XMIT_MULTICAST_CNT, CNTR_SYNTH),
4145[C_DC_MC_RCV_PKTS] = DC_PERF_CNTR(DcMcRcvPkts,
4146 DCC_PRF_PORT_RCV_MULTICAST_PKT_CNT,
4147 CNTR_SYNTH),
4148[C_DC_XMIT_CERR] = DC_PERF_CNTR(DcXmitCorr,
4149 DCC_PRF_PORT_XMIT_CORRECTABLE_CNT, CNTR_SYNTH),
4150[C_DC_RCV_CERR] = DC_PERF_CNTR(DcRcvCorrCnt, DCC_PRF_PORT_RCV_CORRECTABLE_CNT,
4151 CNTR_SYNTH),
4152[C_DC_RCV_FCC] = DC_PERF_CNTR(DcRxFCntl, DCC_PRF_RX_FLOW_CRTL_CNT,
4153 CNTR_SYNTH),
4154[C_DC_XMIT_FCC] = DC_PERF_CNTR(DcXmitFCntl, DCC_PRF_TX_FLOW_CRTL_CNT,
4155 CNTR_SYNTH),
4156[C_DC_XMIT_FLITS] = DC_PERF_CNTR(DcXmitFlits, DCC_PRF_PORT_XMIT_DATA_CNT,
4157 CNTR_SYNTH),
4158[C_DC_RCV_FLITS] = DC_PERF_CNTR(DcRcvFlits, DCC_PRF_PORT_RCV_DATA_CNT,
4159 CNTR_SYNTH),
4160[C_DC_XMIT_PKTS] = DC_PERF_CNTR(DcXmitPkts, DCC_PRF_PORT_XMIT_PKTS_CNT,
4161 CNTR_SYNTH),
4162[C_DC_RCV_PKTS] = DC_PERF_CNTR(DcRcvPkts, DCC_PRF_PORT_RCV_PKTS_CNT,
4163 CNTR_SYNTH),
4164[C_DC_RX_FLIT_VL] = DC_PERF_CNTR(DcRxFlitVl, DCC_PRF_PORT_VL_RCV_DATA_CNT,
4165 CNTR_SYNTH | CNTR_VL),
4166[C_DC_RX_PKT_VL] = DC_PERF_CNTR(DcRxPktVl, DCC_PRF_PORT_VL_RCV_PKTS_CNT,
4167 CNTR_SYNTH | CNTR_VL),
4168[C_DC_RCV_FCN] = DC_PERF_CNTR(DcRcvFcn, DCC_PRF_PORT_RCV_FECN_CNT, CNTR_SYNTH),
4169[C_DC_RCV_FCN_VL] = DC_PERF_CNTR(DcRcvFcnVl, DCC_PRF_PORT_VL_RCV_FECN_CNT,
4170 CNTR_SYNTH | CNTR_VL),
4171[C_DC_RCV_BCN] = DC_PERF_CNTR(DcRcvBcn, DCC_PRF_PORT_RCV_BECN_CNT, CNTR_SYNTH),
4172[C_DC_RCV_BCN_VL] = DC_PERF_CNTR(DcRcvBcnVl, DCC_PRF_PORT_VL_RCV_BECN_CNT,
4173 CNTR_SYNTH | CNTR_VL),
4174[C_DC_RCV_BBL] = DC_PERF_CNTR(DcRcvBbl, DCC_PRF_PORT_RCV_BUBBLE_CNT,
4175 CNTR_SYNTH),
4176[C_DC_RCV_BBL_VL] = DC_PERF_CNTR(DcRcvBblVl, DCC_PRF_PORT_VL_RCV_BUBBLE_CNT,
4177 CNTR_SYNTH | CNTR_VL),
4178[C_DC_MARK_FECN] = DC_PERF_CNTR(DcMarkFcn, DCC_PRF_PORT_MARK_FECN_CNT,
4179 CNTR_SYNTH),
4180[C_DC_MARK_FECN_VL] = DC_PERF_CNTR(DcMarkFcnVl, DCC_PRF_PORT_VL_MARK_FECN_CNT,
4181 CNTR_SYNTH | CNTR_VL),
4182[C_DC_TOTAL_CRC] =
4183 DC_PERF_CNTR_LCB(DcTotCrc, DC_LCB_ERR_INFO_TOTAL_CRC_ERR,
4184 CNTR_SYNTH),
4185[C_DC_CRC_LN0] = DC_PERF_CNTR_LCB(DcCrcLn0, DC_LCB_ERR_INFO_CRC_ERR_LN0,
4186 CNTR_SYNTH),
4187[C_DC_CRC_LN1] = DC_PERF_CNTR_LCB(DcCrcLn1, DC_LCB_ERR_INFO_CRC_ERR_LN1,
4188 CNTR_SYNTH),
4189[C_DC_CRC_LN2] = DC_PERF_CNTR_LCB(DcCrcLn2, DC_LCB_ERR_INFO_CRC_ERR_LN2,
4190 CNTR_SYNTH),
4191[C_DC_CRC_LN3] = DC_PERF_CNTR_LCB(DcCrcLn3, DC_LCB_ERR_INFO_CRC_ERR_LN3,
4192 CNTR_SYNTH),
4193[C_DC_CRC_MULT_LN] =
4194 DC_PERF_CNTR_LCB(DcMultLn, DC_LCB_ERR_INFO_CRC_ERR_MULTI_LN,
4195 CNTR_SYNTH),
4196[C_DC_TX_REPLAY] = DC_PERF_CNTR_LCB(DcTxReplay, DC_LCB_ERR_INFO_TX_REPLAY_CNT,
4197 CNTR_SYNTH),
4198[C_DC_RX_REPLAY] = DC_PERF_CNTR_LCB(DcRxReplay, DC_LCB_ERR_INFO_RX_REPLAY_CNT,
4199 CNTR_SYNTH),
4200[C_DC_SEQ_CRC_CNT] =
4201 DC_PERF_CNTR_LCB(DcLinkSeqCrc, DC_LCB_ERR_INFO_SEQ_CRC_CNT,
4202 CNTR_SYNTH),
4203[C_DC_ESC0_ONLY_CNT] =
4204 DC_PERF_CNTR_LCB(DcEsc0, DC_LCB_ERR_INFO_ESCAPE_0_ONLY_CNT,
4205 CNTR_SYNTH),
4206[C_DC_ESC0_PLUS1_CNT] =
4207 DC_PERF_CNTR_LCB(DcEsc1, DC_LCB_ERR_INFO_ESCAPE_0_PLUS1_CNT,
4208 CNTR_SYNTH),
4209[C_DC_ESC0_PLUS2_CNT] =
4210 DC_PERF_CNTR_LCB(DcEsc0Plus2, DC_LCB_ERR_INFO_ESCAPE_0_PLUS2_CNT,
4211 CNTR_SYNTH),
4212[C_DC_REINIT_FROM_PEER_CNT] =
4213 DC_PERF_CNTR_LCB(DcReinitPeer, DC_LCB_ERR_INFO_REINIT_FROM_PEER_CNT,
4214 CNTR_SYNTH),
4215[C_DC_SBE_CNT] = DC_PERF_CNTR_LCB(DcSbe, DC_LCB_ERR_INFO_SBE_CNT,
4216 CNTR_SYNTH),
4217[C_DC_MISC_FLG_CNT] =
4218 DC_PERF_CNTR_LCB(DcMiscFlg, DC_LCB_ERR_INFO_MISC_FLG_CNT,
4219 CNTR_SYNTH),
4220[C_DC_PRF_GOOD_LTP_CNT] =
4221 DC_PERF_CNTR_LCB(DcGoodLTP, DC_LCB_PRF_GOOD_LTP_CNT, CNTR_SYNTH),
4222[C_DC_PRF_ACCEPTED_LTP_CNT] =
4223 DC_PERF_CNTR_LCB(DcAccLTP, DC_LCB_PRF_ACCEPTED_LTP_CNT,
4224 CNTR_SYNTH),
4225[C_DC_PRF_RX_FLIT_CNT] =
4226 DC_PERF_CNTR_LCB(DcPrfRxFlit, DC_LCB_PRF_RX_FLIT_CNT, CNTR_SYNTH),
4227[C_DC_PRF_TX_FLIT_CNT] =
4228 DC_PERF_CNTR_LCB(DcPrfTxFlit, DC_LCB_PRF_TX_FLIT_CNT, CNTR_SYNTH),
4229[C_DC_PRF_CLK_CNTR] =
4230 DC_PERF_CNTR_LCB(DcPrfClk, DC_LCB_PRF_CLK_CNTR, CNTR_SYNTH),
4231[C_DC_PG_DBG_FLIT_CRDTS_CNT] =
4232 DC_PERF_CNTR_LCB(DcFltCrdts, DC_LCB_PG_DBG_FLIT_CRDTS_CNT, CNTR_SYNTH),
4233[C_DC_PG_STS_PAUSE_COMPLETE_CNT] =
4234 DC_PERF_CNTR_LCB(DcPauseComp, DC_LCB_PG_STS_PAUSE_COMPLETE_CNT,
4235 CNTR_SYNTH),
4236[C_DC_PG_STS_TX_SBE_CNT] =
4237 DC_PERF_CNTR_LCB(DcStsTxSbe, DC_LCB_PG_STS_TX_SBE_CNT, CNTR_SYNTH),
4238[C_DC_PG_STS_TX_MBE_CNT] =
4239 DC_PERF_CNTR_LCB(DcStsTxMbe, DC_LCB_PG_STS_TX_MBE_CNT,
4240 CNTR_SYNTH),
4241[C_SW_CPU_INTR] = CNTR_ELEM("Intr", 0, 0, CNTR_NORMAL,
4242 access_sw_cpu_intr),
4243[C_SW_CPU_RCV_LIM] = CNTR_ELEM("RcvLimit", 0, 0, CNTR_NORMAL,
4244 access_sw_cpu_rcv_limit),
4245[C_SW_VTX_WAIT] = CNTR_ELEM("vTxWait", 0, 0, CNTR_NORMAL,
4246 access_sw_vtx_wait),
4247[C_SW_PIO_WAIT] = CNTR_ELEM("PioWait", 0, 0, CNTR_NORMAL,
4248 access_sw_pio_wait),
Mike Marciniszyn14553ca2016-02-14 12:45:36 -08004249[C_SW_PIO_DRAIN] = CNTR_ELEM("PioDrain", 0, 0, CNTR_NORMAL,
4250 access_sw_pio_drain),
Mike Marciniszyn77241052015-07-30 15:17:43 -04004251[C_SW_KMEM_WAIT] = CNTR_ELEM("KmemWait", 0, 0, CNTR_NORMAL,
4252 access_sw_kmem_wait),
Dean Luickb4219222015-10-26 10:28:35 -04004253[C_SW_SEND_SCHED] = CNTR_ELEM("SendSched", 0, 0, CNTR_NORMAL,
4254 access_sw_send_schedule),
Vennila Megavannana699c6c2016-01-11 18:30:56 -05004255[C_SDMA_DESC_FETCHED_CNT] = CNTR_ELEM("SDEDscFdCn",
4256 SEND_DMA_DESC_FETCHED_CNT, 0,
4257 CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
4258 dev_access_u32_csr),
4259[C_SDMA_INT_CNT] = CNTR_ELEM("SDMAInt", 0, 0,
4260 CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
4261 access_sde_int_cnt),
4262[C_SDMA_ERR_CNT] = CNTR_ELEM("SDMAErrCt", 0, 0,
4263 CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
4264 access_sde_err_cnt),
4265[C_SDMA_IDLE_INT_CNT] = CNTR_ELEM("SDMAIdInt", 0, 0,
4266 CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
4267 access_sde_idle_int_cnt),
4268[C_SDMA_PROGRESS_INT_CNT] = CNTR_ELEM("SDMAPrIntCn", 0, 0,
4269 CNTR_NORMAL | CNTR_32BIT | CNTR_SDMA,
4270 access_sde_progress_int_cnt),
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05004271/* MISC_ERR_STATUS */
4272[C_MISC_PLL_LOCK_FAIL_ERR] = CNTR_ELEM("MISC_PLL_LOCK_FAIL_ERR", 0, 0,
4273 CNTR_NORMAL,
4274 access_misc_pll_lock_fail_err_cnt),
4275[C_MISC_MBIST_FAIL_ERR] = CNTR_ELEM("MISC_MBIST_FAIL_ERR", 0, 0,
4276 CNTR_NORMAL,
4277 access_misc_mbist_fail_err_cnt),
4278[C_MISC_INVALID_EEP_CMD_ERR] = CNTR_ELEM("MISC_INVALID_EEP_CMD_ERR", 0, 0,
4279 CNTR_NORMAL,
4280 access_misc_invalid_eep_cmd_err_cnt),
4281[C_MISC_EFUSE_DONE_PARITY_ERR] = CNTR_ELEM("MISC_EFUSE_DONE_PARITY_ERR", 0, 0,
4282 CNTR_NORMAL,
4283 access_misc_efuse_done_parity_err_cnt),
4284[C_MISC_EFUSE_WRITE_ERR] = CNTR_ELEM("MISC_EFUSE_WRITE_ERR", 0, 0,
4285 CNTR_NORMAL,
4286 access_misc_efuse_write_err_cnt),
4287[C_MISC_EFUSE_READ_BAD_ADDR_ERR] = CNTR_ELEM("MISC_EFUSE_READ_BAD_ADDR_ERR", 0,
4288 0, CNTR_NORMAL,
4289 access_misc_efuse_read_bad_addr_err_cnt),
4290[C_MISC_EFUSE_CSR_PARITY_ERR] = CNTR_ELEM("MISC_EFUSE_CSR_PARITY_ERR", 0, 0,
4291 CNTR_NORMAL,
4292 access_misc_efuse_csr_parity_err_cnt),
4293[C_MISC_FW_AUTH_FAILED_ERR] = CNTR_ELEM("MISC_FW_AUTH_FAILED_ERR", 0, 0,
4294 CNTR_NORMAL,
4295 access_misc_fw_auth_failed_err_cnt),
4296[C_MISC_KEY_MISMATCH_ERR] = CNTR_ELEM("MISC_KEY_MISMATCH_ERR", 0, 0,
4297 CNTR_NORMAL,
4298 access_misc_key_mismatch_err_cnt),
4299[C_MISC_SBUS_WRITE_FAILED_ERR] = CNTR_ELEM("MISC_SBUS_WRITE_FAILED_ERR", 0, 0,
4300 CNTR_NORMAL,
4301 access_misc_sbus_write_failed_err_cnt),
4302[C_MISC_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("MISC_CSR_WRITE_BAD_ADDR_ERR", 0, 0,
4303 CNTR_NORMAL,
4304 access_misc_csr_write_bad_addr_err_cnt),
4305[C_MISC_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("MISC_CSR_READ_BAD_ADDR_ERR", 0, 0,
4306 CNTR_NORMAL,
4307 access_misc_csr_read_bad_addr_err_cnt),
4308[C_MISC_CSR_PARITY_ERR] = CNTR_ELEM("MISC_CSR_PARITY_ERR", 0, 0,
4309 CNTR_NORMAL,
4310 access_misc_csr_parity_err_cnt),
4311/* CceErrStatus */
4312[C_CCE_ERR_STATUS_AGGREGATED_CNT] = CNTR_ELEM("CceErrStatusAggregatedCnt", 0, 0,
4313 CNTR_NORMAL,
4314 access_sw_cce_err_status_aggregated_cnt),
4315[C_CCE_MSIX_CSR_PARITY_ERR] = CNTR_ELEM("CceMsixCsrParityErr", 0, 0,
4316 CNTR_NORMAL,
4317 access_cce_msix_csr_parity_err_cnt),
4318[C_CCE_INT_MAP_UNC_ERR] = CNTR_ELEM("CceIntMapUncErr", 0, 0,
4319 CNTR_NORMAL,
4320 access_cce_int_map_unc_err_cnt),
4321[C_CCE_INT_MAP_COR_ERR] = CNTR_ELEM("CceIntMapCorErr", 0, 0,
4322 CNTR_NORMAL,
4323 access_cce_int_map_cor_err_cnt),
4324[C_CCE_MSIX_TABLE_UNC_ERR] = CNTR_ELEM("CceMsixTableUncErr", 0, 0,
4325 CNTR_NORMAL,
4326 access_cce_msix_table_unc_err_cnt),
4327[C_CCE_MSIX_TABLE_COR_ERR] = CNTR_ELEM("CceMsixTableCorErr", 0, 0,
4328 CNTR_NORMAL,
4329 access_cce_msix_table_cor_err_cnt),
4330[C_CCE_RXDMA_CONV_FIFO_PARITY_ERR] = CNTR_ELEM("CceRxdmaConvFifoParityErr", 0,
4331 0, CNTR_NORMAL,
4332 access_cce_rxdma_conv_fifo_parity_err_cnt),
4333[C_CCE_RCPL_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceRcplAsyncFifoParityErr", 0,
4334 0, CNTR_NORMAL,
4335 access_cce_rcpl_async_fifo_parity_err_cnt),
4336[C_CCE_SEG_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("CceSegWriteBadAddrErr", 0, 0,
4337 CNTR_NORMAL,
4338 access_cce_seg_write_bad_addr_err_cnt),
4339[C_CCE_SEG_READ_BAD_ADDR_ERR] = CNTR_ELEM("CceSegReadBadAddrErr", 0, 0,
4340 CNTR_NORMAL,
4341 access_cce_seg_read_bad_addr_err_cnt),
4342[C_LA_TRIGGERED] = CNTR_ELEM("Cce LATriggered", 0, 0,
4343 CNTR_NORMAL,
4344 access_la_triggered_cnt),
4345[C_CCE_TRGT_CPL_TIMEOUT_ERR] = CNTR_ELEM("CceTrgtCplTimeoutErr", 0, 0,
4346 CNTR_NORMAL,
4347 access_cce_trgt_cpl_timeout_err_cnt),
4348[C_PCIC_RECEIVE_PARITY_ERR] = CNTR_ELEM("PcicReceiveParityErr", 0, 0,
4349 CNTR_NORMAL,
4350 access_pcic_receive_parity_err_cnt),
4351[C_PCIC_TRANSMIT_BACK_PARITY_ERR] = CNTR_ELEM("PcicTransmitBackParityErr", 0, 0,
4352 CNTR_NORMAL,
4353 access_pcic_transmit_back_parity_err_cnt),
4354[C_PCIC_TRANSMIT_FRONT_PARITY_ERR] = CNTR_ELEM("PcicTransmitFrontParityErr", 0,
4355 0, CNTR_NORMAL,
4356 access_pcic_transmit_front_parity_err_cnt),
4357[C_PCIC_CPL_DAT_Q_UNC_ERR] = CNTR_ELEM("PcicCplDatQUncErr", 0, 0,
4358 CNTR_NORMAL,
4359 access_pcic_cpl_dat_q_unc_err_cnt),
4360[C_PCIC_CPL_HD_Q_UNC_ERR] = CNTR_ELEM("PcicCplHdQUncErr", 0, 0,
4361 CNTR_NORMAL,
4362 access_pcic_cpl_hd_q_unc_err_cnt),
4363[C_PCIC_POST_DAT_Q_UNC_ERR] = CNTR_ELEM("PcicPostDatQUncErr", 0, 0,
4364 CNTR_NORMAL,
4365 access_pcic_post_dat_q_unc_err_cnt),
4366[C_PCIC_POST_HD_Q_UNC_ERR] = CNTR_ELEM("PcicPostHdQUncErr", 0, 0,
4367 CNTR_NORMAL,
4368 access_pcic_post_hd_q_unc_err_cnt),
4369[C_PCIC_RETRY_SOT_MEM_UNC_ERR] = CNTR_ELEM("PcicRetrySotMemUncErr", 0, 0,
4370 CNTR_NORMAL,
4371 access_pcic_retry_sot_mem_unc_err_cnt),
4372[C_PCIC_RETRY_MEM_UNC_ERR] = CNTR_ELEM("PcicRetryMemUncErr", 0, 0,
4373 CNTR_NORMAL,
4374 access_pcic_retry_mem_unc_err),
4375[C_PCIC_N_POST_DAT_Q_PARITY_ERR] = CNTR_ELEM("PcicNPostDatQParityErr", 0, 0,
4376 CNTR_NORMAL,
4377 access_pcic_n_post_dat_q_parity_err_cnt),
4378[C_PCIC_N_POST_H_Q_PARITY_ERR] = CNTR_ELEM("PcicNPostHQParityErr", 0, 0,
4379 CNTR_NORMAL,
4380 access_pcic_n_post_h_q_parity_err_cnt),
4381[C_PCIC_CPL_DAT_Q_COR_ERR] = CNTR_ELEM("PcicCplDatQCorErr", 0, 0,
4382 CNTR_NORMAL,
4383 access_pcic_cpl_dat_q_cor_err_cnt),
4384[C_PCIC_CPL_HD_Q_COR_ERR] = CNTR_ELEM("PcicCplHdQCorErr", 0, 0,
4385 CNTR_NORMAL,
4386 access_pcic_cpl_hd_q_cor_err_cnt),
4387[C_PCIC_POST_DAT_Q_COR_ERR] = CNTR_ELEM("PcicPostDatQCorErr", 0, 0,
4388 CNTR_NORMAL,
4389 access_pcic_post_dat_q_cor_err_cnt),
4390[C_PCIC_POST_HD_Q_COR_ERR] = CNTR_ELEM("PcicPostHdQCorErr", 0, 0,
4391 CNTR_NORMAL,
4392 access_pcic_post_hd_q_cor_err_cnt),
4393[C_PCIC_RETRY_SOT_MEM_COR_ERR] = CNTR_ELEM("PcicRetrySotMemCorErr", 0, 0,
4394 CNTR_NORMAL,
4395 access_pcic_retry_sot_mem_cor_err_cnt),
4396[C_PCIC_RETRY_MEM_COR_ERR] = CNTR_ELEM("PcicRetryMemCorErr", 0, 0,
4397 CNTR_NORMAL,
4398 access_pcic_retry_mem_cor_err_cnt),
4399[C_CCE_CLI1_ASYNC_FIFO_DBG_PARITY_ERR] = CNTR_ELEM(
4400 "CceCli1AsyncFifoDbgParityError", 0, 0,
4401 CNTR_NORMAL,
4402 access_cce_cli1_async_fifo_dbg_parity_err_cnt),
4403[C_CCE_CLI1_ASYNC_FIFO_RXDMA_PARITY_ERR] = CNTR_ELEM(
4404 "CceCli1AsyncFifoRxdmaParityError", 0, 0,
4405 CNTR_NORMAL,
4406 access_cce_cli1_async_fifo_rxdma_parity_err_cnt
4407 ),
4408[C_CCE_CLI1_ASYNC_FIFO_SDMA_HD_PARITY_ERR] = CNTR_ELEM(
4409 "CceCli1AsyncFifoSdmaHdParityErr", 0, 0,
4410 CNTR_NORMAL,
4411 access_cce_cli1_async_fifo_sdma_hd_parity_err_cnt),
4412[C_CCE_CLI1_ASYNC_FIFO_PIO_CRDT_PARITY_ERR] = CNTR_ELEM(
4413 "CceCli1AsyncFifoPioCrdtParityErr", 0, 0,
4414 CNTR_NORMAL,
4415 access_cce_cl1_async_fifo_pio_crdt_parity_err_cnt),
4416[C_CCE_CLI2_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceCli2AsyncFifoParityErr", 0,
4417 0, CNTR_NORMAL,
4418 access_cce_cli2_async_fifo_parity_err_cnt),
4419[C_CCE_CSR_CFG_BUS_PARITY_ERR] = CNTR_ELEM("CceCsrCfgBusParityErr", 0, 0,
4420 CNTR_NORMAL,
4421 access_cce_csr_cfg_bus_parity_err_cnt),
4422[C_CCE_CLI0_ASYNC_FIFO_PARTIY_ERR] = CNTR_ELEM("CceCli0AsyncFifoParityErr", 0,
4423 0, CNTR_NORMAL,
4424 access_cce_cli0_async_fifo_parity_err_cnt),
4425[C_CCE_RSPD_DATA_PARITY_ERR] = CNTR_ELEM("CceRspdDataParityErr", 0, 0,
4426 CNTR_NORMAL,
4427 access_cce_rspd_data_parity_err_cnt),
4428[C_CCE_TRGT_ACCESS_ERR] = CNTR_ELEM("CceTrgtAccessErr", 0, 0,
4429 CNTR_NORMAL,
4430 access_cce_trgt_access_err_cnt),
4431[C_CCE_TRGT_ASYNC_FIFO_PARITY_ERR] = CNTR_ELEM("CceTrgtAsyncFifoParityErr", 0,
4432 0, CNTR_NORMAL,
4433 access_cce_trgt_async_fifo_parity_err_cnt),
4434[C_CCE_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("CceCsrWriteBadAddrErr", 0, 0,
4435 CNTR_NORMAL,
4436 access_cce_csr_write_bad_addr_err_cnt),
4437[C_CCE_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("CceCsrReadBadAddrErr", 0, 0,
4438 CNTR_NORMAL,
4439 access_cce_csr_read_bad_addr_err_cnt),
4440[C_CCE_CSR_PARITY_ERR] = CNTR_ELEM("CceCsrParityErr", 0, 0,
4441 CNTR_NORMAL,
4442 access_ccs_csr_parity_err_cnt),
4443
4444/* RcvErrStatus */
4445[C_RX_CSR_PARITY_ERR] = CNTR_ELEM("RxCsrParityErr", 0, 0,
4446 CNTR_NORMAL,
4447 access_rx_csr_parity_err_cnt),
4448[C_RX_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("RxCsrWriteBadAddrErr", 0, 0,
4449 CNTR_NORMAL,
4450 access_rx_csr_write_bad_addr_err_cnt),
4451[C_RX_CSR_READ_BAD_ADDR_ERR] = CNTR_ELEM("RxCsrReadBadAddrErr", 0, 0,
4452 CNTR_NORMAL,
4453 access_rx_csr_read_bad_addr_err_cnt),
4454[C_RX_DMA_CSR_UNC_ERR] = CNTR_ELEM("RxDmaCsrUncErr", 0, 0,
4455 CNTR_NORMAL,
4456 access_rx_dma_csr_unc_err_cnt),
4457[C_RX_DMA_DQ_FSM_ENCODING_ERR] = CNTR_ELEM("RxDmaDqFsmEncodingErr", 0, 0,
4458 CNTR_NORMAL,
4459 access_rx_dma_dq_fsm_encoding_err_cnt),
4460[C_RX_DMA_EQ_FSM_ENCODING_ERR] = CNTR_ELEM("RxDmaEqFsmEncodingErr", 0, 0,
4461 CNTR_NORMAL,
4462 access_rx_dma_eq_fsm_encoding_err_cnt),
4463[C_RX_DMA_CSR_PARITY_ERR] = CNTR_ELEM("RxDmaCsrParityErr", 0, 0,
4464 CNTR_NORMAL,
4465 access_rx_dma_csr_parity_err_cnt),
4466[C_RX_RBUF_DATA_COR_ERR] = CNTR_ELEM("RxRbufDataCorErr", 0, 0,
4467 CNTR_NORMAL,
4468 access_rx_rbuf_data_cor_err_cnt),
4469[C_RX_RBUF_DATA_UNC_ERR] = CNTR_ELEM("RxRbufDataUncErr", 0, 0,
4470 CNTR_NORMAL,
4471 access_rx_rbuf_data_unc_err_cnt),
4472[C_RX_DMA_DATA_FIFO_RD_COR_ERR] = CNTR_ELEM("RxDmaDataFifoRdCorErr", 0, 0,
4473 CNTR_NORMAL,
4474 access_rx_dma_data_fifo_rd_cor_err_cnt),
4475[C_RX_DMA_DATA_FIFO_RD_UNC_ERR] = CNTR_ELEM("RxDmaDataFifoRdUncErr", 0, 0,
4476 CNTR_NORMAL,
4477 access_rx_dma_data_fifo_rd_unc_err_cnt),
4478[C_RX_DMA_HDR_FIFO_RD_COR_ERR] = CNTR_ELEM("RxDmaHdrFifoRdCorErr", 0, 0,
4479 CNTR_NORMAL,
4480 access_rx_dma_hdr_fifo_rd_cor_err_cnt),
4481[C_RX_DMA_HDR_FIFO_RD_UNC_ERR] = CNTR_ELEM("RxDmaHdrFifoRdUncErr", 0, 0,
4482 CNTR_NORMAL,
4483 access_rx_dma_hdr_fifo_rd_unc_err_cnt),
4484[C_RX_RBUF_DESC_PART2_COR_ERR] = CNTR_ELEM("RxRbufDescPart2CorErr", 0, 0,
4485 CNTR_NORMAL,
4486 access_rx_rbuf_desc_part2_cor_err_cnt),
4487[C_RX_RBUF_DESC_PART2_UNC_ERR] = CNTR_ELEM("RxRbufDescPart2UncErr", 0, 0,
4488 CNTR_NORMAL,
4489 access_rx_rbuf_desc_part2_unc_err_cnt),
4490[C_RX_RBUF_DESC_PART1_COR_ERR] = CNTR_ELEM("RxRbufDescPart1CorErr", 0, 0,
4491 CNTR_NORMAL,
4492 access_rx_rbuf_desc_part1_cor_err_cnt),
4493[C_RX_RBUF_DESC_PART1_UNC_ERR] = CNTR_ELEM("RxRbufDescPart1UncErr", 0, 0,
4494 CNTR_NORMAL,
4495 access_rx_rbuf_desc_part1_unc_err_cnt),
4496[C_RX_HQ_INTR_FSM_ERR] = CNTR_ELEM("RxHqIntrFsmErr", 0, 0,
4497 CNTR_NORMAL,
4498 access_rx_hq_intr_fsm_err_cnt),
4499[C_RX_HQ_INTR_CSR_PARITY_ERR] = CNTR_ELEM("RxHqIntrCsrParityErr", 0, 0,
4500 CNTR_NORMAL,
4501 access_rx_hq_intr_csr_parity_err_cnt),
4502[C_RX_LOOKUP_CSR_PARITY_ERR] = CNTR_ELEM("RxLookupCsrParityErr", 0, 0,
4503 CNTR_NORMAL,
4504 access_rx_lookup_csr_parity_err_cnt),
4505[C_RX_LOOKUP_RCV_ARRAY_COR_ERR] = CNTR_ELEM("RxLookupRcvArrayCorErr", 0, 0,
4506 CNTR_NORMAL,
4507 access_rx_lookup_rcv_array_cor_err_cnt),
4508[C_RX_LOOKUP_RCV_ARRAY_UNC_ERR] = CNTR_ELEM("RxLookupRcvArrayUncErr", 0, 0,
4509 CNTR_NORMAL,
4510 access_rx_lookup_rcv_array_unc_err_cnt),
4511[C_RX_LOOKUP_DES_PART2_PARITY_ERR] = CNTR_ELEM("RxLookupDesPart2ParityErr", 0,
4512 0, CNTR_NORMAL,
4513 access_rx_lookup_des_part2_parity_err_cnt),
4514[C_RX_LOOKUP_DES_PART1_UNC_COR_ERR] = CNTR_ELEM("RxLookupDesPart1UncCorErr", 0,
4515 0, CNTR_NORMAL,
4516 access_rx_lookup_des_part1_unc_cor_err_cnt),
4517[C_RX_LOOKUP_DES_PART1_UNC_ERR] = CNTR_ELEM("RxLookupDesPart1UncErr", 0, 0,
4518 CNTR_NORMAL,
4519 access_rx_lookup_des_part1_unc_err_cnt),
4520[C_RX_RBUF_NEXT_FREE_BUF_COR_ERR] = CNTR_ELEM("RxRbufNextFreeBufCorErr", 0, 0,
4521 CNTR_NORMAL,
4522 access_rx_rbuf_next_free_buf_cor_err_cnt),
4523[C_RX_RBUF_NEXT_FREE_BUF_UNC_ERR] = CNTR_ELEM("RxRbufNextFreeBufUncErr", 0, 0,
4524 CNTR_NORMAL,
4525 access_rx_rbuf_next_free_buf_unc_err_cnt),
4526[C_RX_RBUF_FL_INIT_WR_ADDR_PARITY_ERR] = CNTR_ELEM(
4527 "RxRbufFlInitWrAddrParityErr", 0, 0,
4528 CNTR_NORMAL,
4529 access_rbuf_fl_init_wr_addr_parity_err_cnt),
4530[C_RX_RBUF_FL_INITDONE_PARITY_ERR] = CNTR_ELEM("RxRbufFlInitdoneParityErr", 0,
4531 0, CNTR_NORMAL,
4532 access_rx_rbuf_fl_initdone_parity_err_cnt),
4533[C_RX_RBUF_FL_WRITE_ADDR_PARITY_ERR] = CNTR_ELEM("RxRbufFlWrAddrParityErr", 0,
4534 0, CNTR_NORMAL,
4535 access_rx_rbuf_fl_write_addr_parity_err_cnt),
4536[C_RX_RBUF_FL_RD_ADDR_PARITY_ERR] = CNTR_ELEM("RxRbufFlRdAddrParityErr", 0, 0,
4537 CNTR_NORMAL,
4538 access_rx_rbuf_fl_rd_addr_parity_err_cnt),
4539[C_RX_RBUF_EMPTY_ERR] = CNTR_ELEM("RxRbufEmptyErr", 0, 0,
4540 CNTR_NORMAL,
4541 access_rx_rbuf_empty_err_cnt),
4542[C_RX_RBUF_FULL_ERR] = CNTR_ELEM("RxRbufFullErr", 0, 0,
4543 CNTR_NORMAL,
4544 access_rx_rbuf_full_err_cnt),
4545[C_RX_RBUF_BAD_LOOKUP_ERR] = CNTR_ELEM("RxRBufBadLookupErr", 0, 0,
4546 CNTR_NORMAL,
4547 access_rbuf_bad_lookup_err_cnt),
4548[C_RX_RBUF_CTX_ID_PARITY_ERR] = CNTR_ELEM("RxRbufCtxIdParityErr", 0, 0,
4549 CNTR_NORMAL,
4550 access_rbuf_ctx_id_parity_err_cnt),
4551[C_RX_RBUF_CSR_QEOPDW_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQEOPDWParityErr", 0, 0,
4552 CNTR_NORMAL,
4553 access_rbuf_csr_qeopdw_parity_err_cnt),
4554[C_RX_RBUF_CSR_Q_NUM_OF_PKT_PARITY_ERR] = CNTR_ELEM(
4555 "RxRbufCsrQNumOfPktParityErr", 0, 0,
4556 CNTR_NORMAL,
4557 access_rx_rbuf_csr_q_num_of_pkt_parity_err_cnt),
4558[C_RX_RBUF_CSR_Q_T1_PTR_PARITY_ERR] = CNTR_ELEM(
4559 "RxRbufCsrQTlPtrParityErr", 0, 0,
4560 CNTR_NORMAL,
4561 access_rx_rbuf_csr_q_t1_ptr_parity_err_cnt),
4562[C_RX_RBUF_CSR_Q_HD_PTR_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQHdPtrParityErr", 0,
4563 0, CNTR_NORMAL,
4564 access_rx_rbuf_csr_q_hd_ptr_parity_err_cnt),
4565[C_RX_RBUF_CSR_Q_VLD_BIT_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQVldBitParityErr", 0,
4566 0, CNTR_NORMAL,
4567 access_rx_rbuf_csr_q_vld_bit_parity_err_cnt),
4568[C_RX_RBUF_CSR_Q_NEXT_BUF_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQNextBufParityErr",
4569 0, 0, CNTR_NORMAL,
4570 access_rx_rbuf_csr_q_next_buf_parity_err_cnt),
4571[C_RX_RBUF_CSR_Q_ENT_CNT_PARITY_ERR] = CNTR_ELEM("RxRbufCsrQEntCntParityErr", 0,
4572 0, CNTR_NORMAL,
4573 access_rx_rbuf_csr_q_ent_cnt_parity_err_cnt),
4574[C_RX_RBUF_CSR_Q_HEAD_BUF_NUM_PARITY_ERR] = CNTR_ELEM(
4575 "RxRbufCsrQHeadBufNumParityErr", 0, 0,
4576 CNTR_NORMAL,
4577 access_rx_rbuf_csr_q_head_buf_num_parity_err_cnt),
4578[C_RX_RBUF_BLOCK_LIST_READ_COR_ERR] = CNTR_ELEM("RxRbufBlockListReadCorErr", 0,
4579 0, CNTR_NORMAL,
4580 access_rx_rbuf_block_list_read_cor_err_cnt),
4581[C_RX_RBUF_BLOCK_LIST_READ_UNC_ERR] = CNTR_ELEM("RxRbufBlockListReadUncErr", 0,
4582 0, CNTR_NORMAL,
4583 access_rx_rbuf_block_list_read_unc_err_cnt),
4584[C_RX_RBUF_LOOKUP_DES_COR_ERR] = CNTR_ELEM("RxRbufLookupDesCorErr", 0, 0,
4585 CNTR_NORMAL,
4586 access_rx_rbuf_lookup_des_cor_err_cnt),
4587[C_RX_RBUF_LOOKUP_DES_UNC_ERR] = CNTR_ELEM("RxRbufLookupDesUncErr", 0, 0,
4588 CNTR_NORMAL,
4589 access_rx_rbuf_lookup_des_unc_err_cnt),
4590[C_RX_RBUF_LOOKUP_DES_REG_UNC_COR_ERR] = CNTR_ELEM(
4591 "RxRbufLookupDesRegUncCorErr", 0, 0,
4592 CNTR_NORMAL,
4593 access_rx_rbuf_lookup_des_reg_unc_cor_err_cnt),
4594[C_RX_RBUF_LOOKUP_DES_REG_UNC_ERR] = CNTR_ELEM("RxRbufLookupDesRegUncErr", 0, 0,
4595 CNTR_NORMAL,
4596 access_rx_rbuf_lookup_des_reg_unc_err_cnt),
4597[C_RX_RBUF_FREE_LIST_COR_ERR] = CNTR_ELEM("RxRbufFreeListCorErr", 0, 0,
4598 CNTR_NORMAL,
4599 access_rx_rbuf_free_list_cor_err_cnt),
4600[C_RX_RBUF_FREE_LIST_UNC_ERR] = CNTR_ELEM("RxRbufFreeListUncErr", 0, 0,
4601 CNTR_NORMAL,
4602 access_rx_rbuf_free_list_unc_err_cnt),
4603[C_RX_RCV_FSM_ENCODING_ERR] = CNTR_ELEM("RxRcvFsmEncodingErr", 0, 0,
4604 CNTR_NORMAL,
4605 access_rx_rcv_fsm_encoding_err_cnt),
4606[C_RX_DMA_FLAG_COR_ERR] = CNTR_ELEM("RxDmaFlagCorErr", 0, 0,
4607 CNTR_NORMAL,
4608 access_rx_dma_flag_cor_err_cnt),
4609[C_RX_DMA_FLAG_UNC_ERR] = CNTR_ELEM("RxDmaFlagUncErr", 0, 0,
4610 CNTR_NORMAL,
4611 access_rx_dma_flag_unc_err_cnt),
4612[C_RX_DC_SOP_EOP_PARITY_ERR] = CNTR_ELEM("RxDcSopEopParityErr", 0, 0,
4613 CNTR_NORMAL,
4614 access_rx_dc_sop_eop_parity_err_cnt),
4615[C_RX_RCV_CSR_PARITY_ERR] = CNTR_ELEM("RxRcvCsrParityErr", 0, 0,
4616 CNTR_NORMAL,
4617 access_rx_rcv_csr_parity_err_cnt),
4618[C_RX_RCV_QP_MAP_TABLE_COR_ERR] = CNTR_ELEM("RxRcvQpMapTableCorErr", 0, 0,
4619 CNTR_NORMAL,
4620 access_rx_rcv_qp_map_table_cor_err_cnt),
4621[C_RX_RCV_QP_MAP_TABLE_UNC_ERR] = CNTR_ELEM("RxRcvQpMapTableUncErr", 0, 0,
4622 CNTR_NORMAL,
4623 access_rx_rcv_qp_map_table_unc_err_cnt),
4624[C_RX_RCV_DATA_COR_ERR] = CNTR_ELEM("RxRcvDataCorErr", 0, 0,
4625 CNTR_NORMAL,
4626 access_rx_rcv_data_cor_err_cnt),
4627[C_RX_RCV_DATA_UNC_ERR] = CNTR_ELEM("RxRcvDataUncErr", 0, 0,
4628 CNTR_NORMAL,
4629 access_rx_rcv_data_unc_err_cnt),
4630[C_RX_RCV_HDR_COR_ERR] = CNTR_ELEM("RxRcvHdrCorErr", 0, 0,
4631 CNTR_NORMAL,
4632 access_rx_rcv_hdr_cor_err_cnt),
4633[C_RX_RCV_HDR_UNC_ERR] = CNTR_ELEM("RxRcvHdrUncErr", 0, 0,
4634 CNTR_NORMAL,
4635 access_rx_rcv_hdr_unc_err_cnt),
4636[C_RX_DC_INTF_PARITY_ERR] = CNTR_ELEM("RxDcIntfParityErr", 0, 0,
4637 CNTR_NORMAL,
4638 access_rx_dc_intf_parity_err_cnt),
4639[C_RX_DMA_CSR_COR_ERR] = CNTR_ELEM("RxDmaCsrCorErr", 0, 0,
4640 CNTR_NORMAL,
4641 access_rx_dma_csr_cor_err_cnt),
4642/* SendPioErrStatus */
4643[C_PIO_PEC_SOP_HEAD_PARITY_ERR] = CNTR_ELEM("PioPecSopHeadParityErr", 0, 0,
4644 CNTR_NORMAL,
4645 access_pio_pec_sop_head_parity_err_cnt),
4646[C_PIO_PCC_SOP_HEAD_PARITY_ERR] = CNTR_ELEM("PioPccSopHeadParityErr", 0, 0,
4647 CNTR_NORMAL,
4648 access_pio_pcc_sop_head_parity_err_cnt),
4649[C_PIO_LAST_RETURNED_CNT_PARITY_ERR] = CNTR_ELEM("PioLastReturnedCntParityErr",
4650 0, 0, CNTR_NORMAL,
4651 access_pio_last_returned_cnt_parity_err_cnt),
4652[C_PIO_CURRENT_FREE_CNT_PARITY_ERR] = CNTR_ELEM("PioCurrentFreeCntParityErr", 0,
4653 0, CNTR_NORMAL,
4654 access_pio_current_free_cnt_parity_err_cnt),
4655[C_PIO_RSVD_31_ERR] = CNTR_ELEM("Pio Reserved 31", 0, 0,
4656 CNTR_NORMAL,
4657 access_pio_reserved_31_err_cnt),
4658[C_PIO_RSVD_30_ERR] = CNTR_ELEM("Pio Reserved 30", 0, 0,
4659 CNTR_NORMAL,
4660 access_pio_reserved_30_err_cnt),
4661[C_PIO_PPMC_SOP_LEN_ERR] = CNTR_ELEM("PioPpmcSopLenErr", 0, 0,
4662 CNTR_NORMAL,
4663 access_pio_ppmc_sop_len_err_cnt),
4664[C_PIO_PPMC_BQC_MEM_PARITY_ERR] = CNTR_ELEM("PioPpmcBqcMemParityErr", 0, 0,
4665 CNTR_NORMAL,
4666 access_pio_ppmc_bqc_mem_parity_err_cnt),
4667[C_PIO_VL_FIFO_PARITY_ERR] = CNTR_ELEM("PioVlFifoParityErr", 0, 0,
4668 CNTR_NORMAL,
4669 access_pio_vl_fifo_parity_err_cnt),
4670[C_PIO_VLF_SOP_PARITY_ERR] = CNTR_ELEM("PioVlfSopParityErr", 0, 0,
4671 CNTR_NORMAL,
4672 access_pio_vlf_sop_parity_err_cnt),
4673[C_PIO_VLF_V1_LEN_PARITY_ERR] = CNTR_ELEM("PioVlfVlLenParityErr", 0, 0,
4674 CNTR_NORMAL,
4675 access_pio_vlf_v1_len_parity_err_cnt),
4676[C_PIO_BLOCK_QW_COUNT_PARITY_ERR] = CNTR_ELEM("PioBlockQwCountParityErr", 0, 0,
4677 CNTR_NORMAL,
4678 access_pio_block_qw_count_parity_err_cnt),
4679[C_PIO_WRITE_QW_VALID_PARITY_ERR] = CNTR_ELEM("PioWriteQwValidParityErr", 0, 0,
4680 CNTR_NORMAL,
4681 access_pio_write_qw_valid_parity_err_cnt),
4682[C_PIO_STATE_MACHINE_ERR] = CNTR_ELEM("PioStateMachineErr", 0, 0,
4683 CNTR_NORMAL,
4684 access_pio_state_machine_err_cnt),
4685[C_PIO_WRITE_DATA_PARITY_ERR] = CNTR_ELEM("PioWriteDataParityErr", 0, 0,
4686 CNTR_NORMAL,
4687 access_pio_write_data_parity_err_cnt),
4688[C_PIO_HOST_ADDR_MEM_COR_ERR] = CNTR_ELEM("PioHostAddrMemCorErr", 0, 0,
4689 CNTR_NORMAL,
4690 access_pio_host_addr_mem_cor_err_cnt),
4691[C_PIO_HOST_ADDR_MEM_UNC_ERR] = CNTR_ELEM("PioHostAddrMemUncErr", 0, 0,
4692 CNTR_NORMAL,
4693 access_pio_host_addr_mem_unc_err_cnt),
4694[C_PIO_PKT_EVICT_SM_OR_ARM_SM_ERR] = CNTR_ELEM("PioPktEvictSmOrArbSmErr", 0, 0,
4695 CNTR_NORMAL,
4696 access_pio_pkt_evict_sm_or_arb_sm_err_cnt),
4697[C_PIO_INIT_SM_IN_ERR] = CNTR_ELEM("PioInitSmInErr", 0, 0,
4698 CNTR_NORMAL,
4699 access_pio_init_sm_in_err_cnt),
4700[C_PIO_PPMC_PBL_FIFO_ERR] = CNTR_ELEM("PioPpmcPblFifoErr", 0, 0,
4701 CNTR_NORMAL,
4702 access_pio_ppmc_pbl_fifo_err_cnt),
4703[C_PIO_CREDIT_RET_FIFO_PARITY_ERR] = CNTR_ELEM("PioCreditRetFifoParityErr", 0,
4704 0, CNTR_NORMAL,
4705 access_pio_credit_ret_fifo_parity_err_cnt),
4706[C_PIO_V1_LEN_MEM_BANK1_COR_ERR] = CNTR_ELEM("PioVlLenMemBank1CorErr", 0, 0,
4707 CNTR_NORMAL,
4708 access_pio_v1_len_mem_bank1_cor_err_cnt),
4709[C_PIO_V1_LEN_MEM_BANK0_COR_ERR] = CNTR_ELEM("PioVlLenMemBank0CorErr", 0, 0,
4710 CNTR_NORMAL,
4711 access_pio_v1_len_mem_bank0_cor_err_cnt),
4712[C_PIO_V1_LEN_MEM_BANK1_UNC_ERR] = CNTR_ELEM("PioVlLenMemBank1UncErr", 0, 0,
4713 CNTR_NORMAL,
4714 access_pio_v1_len_mem_bank1_unc_err_cnt),
4715[C_PIO_V1_LEN_MEM_BANK0_UNC_ERR] = CNTR_ELEM("PioVlLenMemBank0UncErr", 0, 0,
4716 CNTR_NORMAL,
4717 access_pio_v1_len_mem_bank0_unc_err_cnt),
4718[C_PIO_SM_PKT_RESET_PARITY_ERR] = CNTR_ELEM("PioSmPktResetParityErr", 0, 0,
4719 CNTR_NORMAL,
4720 access_pio_sm_pkt_reset_parity_err_cnt),
4721[C_PIO_PKT_EVICT_FIFO_PARITY_ERR] = CNTR_ELEM("PioPktEvictFifoParityErr", 0, 0,
4722 CNTR_NORMAL,
4723 access_pio_pkt_evict_fifo_parity_err_cnt),
4724[C_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR] = CNTR_ELEM(
4725 "PioSbrdctrlCrrelFifoParityErr", 0, 0,
4726 CNTR_NORMAL,
4727 access_pio_sbrdctrl_crrel_fifo_parity_err_cnt),
4728[C_PIO_SBRDCTL_CRREL_PARITY_ERR] = CNTR_ELEM("PioSbrdctlCrrelParityErr", 0, 0,
4729 CNTR_NORMAL,
4730 access_pio_sbrdctl_crrel_parity_err_cnt),
4731[C_PIO_PEC_FIFO_PARITY_ERR] = CNTR_ELEM("PioPecFifoParityErr", 0, 0,
4732 CNTR_NORMAL,
4733 access_pio_pec_fifo_parity_err_cnt),
4734[C_PIO_PCC_FIFO_PARITY_ERR] = CNTR_ELEM("PioPccFifoParityErr", 0, 0,
4735 CNTR_NORMAL,
4736 access_pio_pcc_fifo_parity_err_cnt),
4737[C_PIO_SB_MEM_FIFO1_ERR] = CNTR_ELEM("PioSbMemFifo1Err", 0, 0,
4738 CNTR_NORMAL,
4739 access_pio_sb_mem_fifo1_err_cnt),
4740[C_PIO_SB_MEM_FIFO0_ERR] = CNTR_ELEM("PioSbMemFifo0Err", 0, 0,
4741 CNTR_NORMAL,
4742 access_pio_sb_mem_fifo0_err_cnt),
4743[C_PIO_CSR_PARITY_ERR] = CNTR_ELEM("PioCsrParityErr", 0, 0,
4744 CNTR_NORMAL,
4745 access_pio_csr_parity_err_cnt),
4746[C_PIO_WRITE_ADDR_PARITY_ERR] = CNTR_ELEM("PioWriteAddrParityErr", 0, 0,
4747 CNTR_NORMAL,
4748 access_pio_write_addr_parity_err_cnt),
4749[C_PIO_WRITE_BAD_CTXT_ERR] = CNTR_ELEM("PioWriteBadCtxtErr", 0, 0,
4750 CNTR_NORMAL,
4751 access_pio_write_bad_ctxt_err_cnt),
4752/* SendDmaErrStatus */
4753[C_SDMA_PCIE_REQ_TRACKING_COR_ERR] = CNTR_ELEM("SDmaPcieReqTrackingCorErr", 0,
4754 0, CNTR_NORMAL,
4755 access_sdma_pcie_req_tracking_cor_err_cnt),
4756[C_SDMA_PCIE_REQ_TRACKING_UNC_ERR] = CNTR_ELEM("SDmaPcieReqTrackingUncErr", 0,
4757 0, CNTR_NORMAL,
4758 access_sdma_pcie_req_tracking_unc_err_cnt),
4759[C_SDMA_CSR_PARITY_ERR] = CNTR_ELEM("SDmaCsrParityErr", 0, 0,
4760 CNTR_NORMAL,
4761 access_sdma_csr_parity_err_cnt),
4762[C_SDMA_RPY_TAG_ERR] = CNTR_ELEM("SDmaRpyTagErr", 0, 0,
4763 CNTR_NORMAL,
4764 access_sdma_rpy_tag_err_cnt),
4765/* SendEgressErrStatus */
4766[C_TX_READ_PIO_MEMORY_CSR_UNC_ERR] = CNTR_ELEM("TxReadPioMemoryCsrUncErr", 0, 0,
4767 CNTR_NORMAL,
4768 access_tx_read_pio_memory_csr_unc_err_cnt),
4769[C_TX_READ_SDMA_MEMORY_CSR_UNC_ERR] = CNTR_ELEM("TxReadSdmaMemoryCsrUncErr", 0,
4770 0, CNTR_NORMAL,
4771 access_tx_read_sdma_memory_csr_err_cnt),
4772[C_TX_EGRESS_FIFO_COR_ERR] = CNTR_ELEM("TxEgressFifoCorErr", 0, 0,
4773 CNTR_NORMAL,
4774 access_tx_egress_fifo_cor_err_cnt),
4775[C_TX_READ_PIO_MEMORY_COR_ERR] = CNTR_ELEM("TxReadPioMemoryCorErr", 0, 0,
4776 CNTR_NORMAL,
4777 access_tx_read_pio_memory_cor_err_cnt),
4778[C_TX_READ_SDMA_MEMORY_COR_ERR] = CNTR_ELEM("TxReadSdmaMemoryCorErr", 0, 0,
4779 CNTR_NORMAL,
4780 access_tx_read_sdma_memory_cor_err_cnt),
4781[C_TX_SB_HDR_COR_ERR] = CNTR_ELEM("TxSbHdrCorErr", 0, 0,
4782 CNTR_NORMAL,
4783 access_tx_sb_hdr_cor_err_cnt),
4784[C_TX_CREDIT_OVERRUN_ERR] = CNTR_ELEM("TxCreditOverrunErr", 0, 0,
4785 CNTR_NORMAL,
4786 access_tx_credit_overrun_err_cnt),
4787[C_TX_LAUNCH_FIFO8_COR_ERR] = CNTR_ELEM("TxLaunchFifo8CorErr", 0, 0,
4788 CNTR_NORMAL,
4789 access_tx_launch_fifo8_cor_err_cnt),
4790[C_TX_LAUNCH_FIFO7_COR_ERR] = CNTR_ELEM("TxLaunchFifo7CorErr", 0, 0,
4791 CNTR_NORMAL,
4792 access_tx_launch_fifo7_cor_err_cnt),
4793[C_TX_LAUNCH_FIFO6_COR_ERR] = CNTR_ELEM("TxLaunchFifo6CorErr", 0, 0,
4794 CNTR_NORMAL,
4795 access_tx_launch_fifo6_cor_err_cnt),
4796[C_TX_LAUNCH_FIFO5_COR_ERR] = CNTR_ELEM("TxLaunchFifo5CorErr", 0, 0,
4797 CNTR_NORMAL,
4798 access_tx_launch_fifo5_cor_err_cnt),
4799[C_TX_LAUNCH_FIFO4_COR_ERR] = CNTR_ELEM("TxLaunchFifo4CorErr", 0, 0,
4800 CNTR_NORMAL,
4801 access_tx_launch_fifo4_cor_err_cnt),
4802[C_TX_LAUNCH_FIFO3_COR_ERR] = CNTR_ELEM("TxLaunchFifo3CorErr", 0, 0,
4803 CNTR_NORMAL,
4804 access_tx_launch_fifo3_cor_err_cnt),
4805[C_TX_LAUNCH_FIFO2_COR_ERR] = CNTR_ELEM("TxLaunchFifo2CorErr", 0, 0,
4806 CNTR_NORMAL,
4807 access_tx_launch_fifo2_cor_err_cnt),
4808[C_TX_LAUNCH_FIFO1_COR_ERR] = CNTR_ELEM("TxLaunchFifo1CorErr", 0, 0,
4809 CNTR_NORMAL,
4810 access_tx_launch_fifo1_cor_err_cnt),
4811[C_TX_LAUNCH_FIFO0_COR_ERR] = CNTR_ELEM("TxLaunchFifo0CorErr", 0, 0,
4812 CNTR_NORMAL,
4813 access_tx_launch_fifo0_cor_err_cnt),
4814[C_TX_CREDIT_RETURN_VL_ERR] = CNTR_ELEM("TxCreditReturnVLErr", 0, 0,
4815 CNTR_NORMAL,
4816 access_tx_credit_return_vl_err_cnt),
4817[C_TX_HCRC_INSERTION_ERR] = CNTR_ELEM("TxHcrcInsertionErr", 0, 0,
4818 CNTR_NORMAL,
4819 access_tx_hcrc_insertion_err_cnt),
4820[C_TX_EGRESS_FIFI_UNC_ERR] = CNTR_ELEM("TxEgressFifoUncErr", 0, 0,
4821 CNTR_NORMAL,
4822 access_tx_egress_fifo_unc_err_cnt),
4823[C_TX_READ_PIO_MEMORY_UNC_ERR] = CNTR_ELEM("TxReadPioMemoryUncErr", 0, 0,
4824 CNTR_NORMAL,
4825 access_tx_read_pio_memory_unc_err_cnt),
4826[C_TX_READ_SDMA_MEMORY_UNC_ERR] = CNTR_ELEM("TxReadSdmaMemoryUncErr", 0, 0,
4827 CNTR_NORMAL,
4828 access_tx_read_sdma_memory_unc_err_cnt),
4829[C_TX_SB_HDR_UNC_ERR] = CNTR_ELEM("TxSbHdrUncErr", 0, 0,
4830 CNTR_NORMAL,
4831 access_tx_sb_hdr_unc_err_cnt),
4832[C_TX_CREDIT_RETURN_PARITY_ERR] = CNTR_ELEM("TxCreditReturnParityErr", 0, 0,
4833 CNTR_NORMAL,
4834 access_tx_credit_return_partiy_err_cnt),
4835[C_TX_LAUNCH_FIFO8_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo8UncOrParityErr",
4836 0, 0, CNTR_NORMAL,
4837 access_tx_launch_fifo8_unc_or_parity_err_cnt),
4838[C_TX_LAUNCH_FIFO7_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo7UncOrParityErr",
4839 0, 0, CNTR_NORMAL,
4840 access_tx_launch_fifo7_unc_or_parity_err_cnt),
4841[C_TX_LAUNCH_FIFO6_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo6UncOrParityErr",
4842 0, 0, CNTR_NORMAL,
4843 access_tx_launch_fifo6_unc_or_parity_err_cnt),
4844[C_TX_LAUNCH_FIFO5_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo5UncOrParityErr",
4845 0, 0, CNTR_NORMAL,
4846 access_tx_launch_fifo5_unc_or_parity_err_cnt),
4847[C_TX_LAUNCH_FIFO4_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo4UncOrParityErr",
4848 0, 0, CNTR_NORMAL,
4849 access_tx_launch_fifo4_unc_or_parity_err_cnt),
4850[C_TX_LAUNCH_FIFO3_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo3UncOrParityErr",
4851 0, 0, CNTR_NORMAL,
4852 access_tx_launch_fifo3_unc_or_parity_err_cnt),
4853[C_TX_LAUNCH_FIFO2_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo2UncOrParityErr",
4854 0, 0, CNTR_NORMAL,
4855 access_tx_launch_fifo2_unc_or_parity_err_cnt),
4856[C_TX_LAUNCH_FIFO1_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo1UncOrParityErr",
4857 0, 0, CNTR_NORMAL,
4858 access_tx_launch_fifo1_unc_or_parity_err_cnt),
4859[C_TX_LAUNCH_FIFO0_UNC_OR_PARITY_ERR] = CNTR_ELEM("TxLaunchFifo0UncOrParityErr",
4860 0, 0, CNTR_NORMAL,
4861 access_tx_launch_fifo0_unc_or_parity_err_cnt),
4862[C_TX_SDMA15_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma15DisallowedPacketErr",
4863 0, 0, CNTR_NORMAL,
4864 access_tx_sdma15_disallowed_packet_err_cnt),
4865[C_TX_SDMA14_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma14DisallowedPacketErr",
4866 0, 0, CNTR_NORMAL,
4867 access_tx_sdma14_disallowed_packet_err_cnt),
4868[C_TX_SDMA13_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma13DisallowedPacketErr",
4869 0, 0, CNTR_NORMAL,
4870 access_tx_sdma13_disallowed_packet_err_cnt),
4871[C_TX_SDMA12_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma12DisallowedPacketErr",
4872 0, 0, CNTR_NORMAL,
4873 access_tx_sdma12_disallowed_packet_err_cnt),
4874[C_TX_SDMA11_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma11DisallowedPacketErr",
4875 0, 0, CNTR_NORMAL,
4876 access_tx_sdma11_disallowed_packet_err_cnt),
4877[C_TX_SDMA10_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma10DisallowedPacketErr",
4878 0, 0, CNTR_NORMAL,
4879 access_tx_sdma10_disallowed_packet_err_cnt),
4880[C_TX_SDMA9_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma9DisallowedPacketErr",
4881 0, 0, CNTR_NORMAL,
4882 access_tx_sdma9_disallowed_packet_err_cnt),
4883[C_TX_SDMA8_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma8DisallowedPacketErr",
4884 0, 0, CNTR_NORMAL,
4885 access_tx_sdma8_disallowed_packet_err_cnt),
4886[C_TX_SDMA7_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma7DisallowedPacketErr",
4887 0, 0, CNTR_NORMAL,
4888 access_tx_sdma7_disallowed_packet_err_cnt),
4889[C_TX_SDMA6_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma6DisallowedPacketErr",
4890 0, 0, CNTR_NORMAL,
4891 access_tx_sdma6_disallowed_packet_err_cnt),
4892[C_TX_SDMA5_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma5DisallowedPacketErr",
4893 0, 0, CNTR_NORMAL,
4894 access_tx_sdma5_disallowed_packet_err_cnt),
4895[C_TX_SDMA4_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma4DisallowedPacketErr",
4896 0, 0, CNTR_NORMAL,
4897 access_tx_sdma4_disallowed_packet_err_cnt),
4898[C_TX_SDMA3_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma3DisallowedPacketErr",
4899 0, 0, CNTR_NORMAL,
4900 access_tx_sdma3_disallowed_packet_err_cnt),
4901[C_TX_SDMA2_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma2DisallowedPacketErr",
4902 0, 0, CNTR_NORMAL,
4903 access_tx_sdma2_disallowed_packet_err_cnt),
4904[C_TX_SDMA1_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma1DisallowedPacketErr",
4905 0, 0, CNTR_NORMAL,
4906 access_tx_sdma1_disallowed_packet_err_cnt),
4907[C_TX_SDMA0_DISALLOWED_PACKET_ERR] = CNTR_ELEM("TxSdma0DisallowedPacketErr",
4908 0, 0, CNTR_NORMAL,
4909 access_tx_sdma0_disallowed_packet_err_cnt),
4910[C_TX_CONFIG_PARITY_ERR] = CNTR_ELEM("TxConfigParityErr", 0, 0,
4911 CNTR_NORMAL,
4912 access_tx_config_parity_err_cnt),
4913[C_TX_SBRD_CTL_CSR_PARITY_ERR] = CNTR_ELEM("TxSbrdCtlCsrParityErr", 0, 0,
4914 CNTR_NORMAL,
4915 access_tx_sbrd_ctl_csr_parity_err_cnt),
4916[C_TX_LAUNCH_CSR_PARITY_ERR] = CNTR_ELEM("TxLaunchCsrParityErr", 0, 0,
4917 CNTR_NORMAL,
4918 access_tx_launch_csr_parity_err_cnt),
4919[C_TX_ILLEGAL_CL_ERR] = CNTR_ELEM("TxIllegalVLErr", 0, 0,
4920 CNTR_NORMAL,
4921 access_tx_illegal_vl_err_cnt),
4922[C_TX_SBRD_CTL_STATE_MACHINE_PARITY_ERR] = CNTR_ELEM(
4923 "TxSbrdCtlStateMachineParityErr", 0, 0,
4924 CNTR_NORMAL,
4925 access_tx_sbrd_ctl_state_machine_parity_err_cnt),
4926[C_TX_RESERVED_10] = CNTR_ELEM("Tx Egress Reserved 10", 0, 0,
4927 CNTR_NORMAL,
4928 access_egress_reserved_10_err_cnt),
4929[C_TX_RESERVED_9] = CNTR_ELEM("Tx Egress Reserved 9", 0, 0,
4930 CNTR_NORMAL,
4931 access_egress_reserved_9_err_cnt),
4932[C_TX_SDMA_LAUNCH_INTF_PARITY_ERR] = CNTR_ELEM("TxSdmaLaunchIntfParityErr",
4933 0, 0, CNTR_NORMAL,
4934 access_tx_sdma_launch_intf_parity_err_cnt),
4935[C_TX_PIO_LAUNCH_INTF_PARITY_ERR] = CNTR_ELEM("TxPioLaunchIntfParityErr", 0, 0,
4936 CNTR_NORMAL,
4937 access_tx_pio_launch_intf_parity_err_cnt),
4938[C_TX_RESERVED_6] = CNTR_ELEM("Tx Egress Reserved 6", 0, 0,
4939 CNTR_NORMAL,
4940 access_egress_reserved_6_err_cnt),
4941[C_TX_INCORRECT_LINK_STATE_ERR] = CNTR_ELEM("TxIncorrectLinkStateErr", 0, 0,
4942 CNTR_NORMAL,
4943 access_tx_incorrect_link_state_err_cnt),
4944[C_TX_LINK_DOWN_ERR] = CNTR_ELEM("TxLinkdownErr", 0, 0,
4945 CNTR_NORMAL,
4946 access_tx_linkdown_err_cnt),
4947[C_TX_EGRESS_FIFO_UNDERRUN_OR_PARITY_ERR] = CNTR_ELEM(
4948 "EgressFifoUnderrunOrParityErr", 0, 0,
4949 CNTR_NORMAL,
4950 access_tx_egress_fifi_underrun_or_parity_err_cnt),
4951[C_TX_RESERVED_2] = CNTR_ELEM("Tx Egress Reserved 2", 0, 0,
4952 CNTR_NORMAL,
4953 access_egress_reserved_2_err_cnt),
4954[C_TX_PKT_INTEGRITY_MEM_UNC_ERR] = CNTR_ELEM("TxPktIntegrityMemUncErr", 0, 0,
4955 CNTR_NORMAL,
4956 access_tx_pkt_integrity_mem_unc_err_cnt),
4957[C_TX_PKT_INTEGRITY_MEM_COR_ERR] = CNTR_ELEM("TxPktIntegrityMemCorErr", 0, 0,
4958 CNTR_NORMAL,
4959 access_tx_pkt_integrity_mem_cor_err_cnt),
4960/* SendErrStatus */
4961[C_SEND_CSR_WRITE_BAD_ADDR_ERR] = CNTR_ELEM("SendCsrWriteBadAddrErr", 0, 0,
4962 CNTR_NORMAL,
4963 access_send_csr_write_bad_addr_err_cnt),
4964[C_SEND_CSR_READ_BAD_ADD_ERR] = CNTR_ELEM("SendCsrReadBadAddrErr", 0, 0,
4965 CNTR_NORMAL,
4966 access_send_csr_read_bad_addr_err_cnt),
4967[C_SEND_CSR_PARITY_ERR] = CNTR_ELEM("SendCsrParityErr", 0, 0,
4968 CNTR_NORMAL,
4969 access_send_csr_parity_cnt),
4970/* SendCtxtErrStatus */
4971[C_PIO_WRITE_OUT_OF_BOUNDS_ERR] = CNTR_ELEM("PioWriteOutOfBoundsErr", 0, 0,
4972 CNTR_NORMAL,
4973 access_pio_write_out_of_bounds_err_cnt),
4974[C_PIO_WRITE_OVERFLOW_ERR] = CNTR_ELEM("PioWriteOverflowErr", 0, 0,
4975 CNTR_NORMAL,
4976 access_pio_write_overflow_err_cnt),
4977[C_PIO_WRITE_CROSSES_BOUNDARY_ERR] = CNTR_ELEM("PioWriteCrossesBoundaryErr",
4978 0, 0, CNTR_NORMAL,
4979 access_pio_write_crosses_boundary_err_cnt),
4980[C_PIO_DISALLOWED_PACKET_ERR] = CNTR_ELEM("PioDisallowedPacketErr", 0, 0,
4981 CNTR_NORMAL,
4982 access_pio_disallowed_packet_err_cnt),
4983[C_PIO_INCONSISTENT_SOP_ERR] = CNTR_ELEM("PioInconsistentSopErr", 0, 0,
4984 CNTR_NORMAL,
4985 access_pio_inconsistent_sop_err_cnt),
4986/* SendDmaEngErrStatus */
4987[C_SDMA_HEADER_REQUEST_FIFO_COR_ERR] = CNTR_ELEM("SDmaHeaderRequestFifoCorErr",
4988 0, 0, CNTR_NORMAL,
4989 access_sdma_header_request_fifo_cor_err_cnt),
4990[C_SDMA_HEADER_STORAGE_COR_ERR] = CNTR_ELEM("SDmaHeaderStorageCorErr", 0, 0,
4991 CNTR_NORMAL,
4992 access_sdma_header_storage_cor_err_cnt),
4993[C_SDMA_PACKET_TRACKING_COR_ERR] = CNTR_ELEM("SDmaPacketTrackingCorErr", 0, 0,
4994 CNTR_NORMAL,
4995 access_sdma_packet_tracking_cor_err_cnt),
4996[C_SDMA_ASSEMBLY_COR_ERR] = CNTR_ELEM("SDmaAssemblyCorErr", 0, 0,
4997 CNTR_NORMAL,
4998 access_sdma_assembly_cor_err_cnt),
4999[C_SDMA_DESC_TABLE_COR_ERR] = CNTR_ELEM("SDmaDescTableCorErr", 0, 0,
5000 CNTR_NORMAL,
5001 access_sdma_desc_table_cor_err_cnt),
5002[C_SDMA_HEADER_REQUEST_FIFO_UNC_ERR] = CNTR_ELEM("SDmaHeaderRequestFifoUncErr",
5003 0, 0, CNTR_NORMAL,
5004 access_sdma_header_request_fifo_unc_err_cnt),
5005[C_SDMA_HEADER_STORAGE_UNC_ERR] = CNTR_ELEM("SDmaHeaderStorageUncErr", 0, 0,
5006 CNTR_NORMAL,
5007 access_sdma_header_storage_unc_err_cnt),
5008[C_SDMA_PACKET_TRACKING_UNC_ERR] = CNTR_ELEM("SDmaPacketTrackingUncErr", 0, 0,
5009 CNTR_NORMAL,
5010 access_sdma_packet_tracking_unc_err_cnt),
5011[C_SDMA_ASSEMBLY_UNC_ERR] = CNTR_ELEM("SDmaAssemblyUncErr", 0, 0,
5012 CNTR_NORMAL,
5013 access_sdma_assembly_unc_err_cnt),
5014[C_SDMA_DESC_TABLE_UNC_ERR] = CNTR_ELEM("SDmaDescTableUncErr", 0, 0,
5015 CNTR_NORMAL,
5016 access_sdma_desc_table_unc_err_cnt),
5017[C_SDMA_TIMEOUT_ERR] = CNTR_ELEM("SDmaTimeoutErr", 0, 0,
5018 CNTR_NORMAL,
5019 access_sdma_timeout_err_cnt),
5020[C_SDMA_HEADER_LENGTH_ERR] = CNTR_ELEM("SDmaHeaderLengthErr", 0, 0,
5021 CNTR_NORMAL,
5022 access_sdma_header_length_err_cnt),
5023[C_SDMA_HEADER_ADDRESS_ERR] = CNTR_ELEM("SDmaHeaderAddressErr", 0, 0,
5024 CNTR_NORMAL,
5025 access_sdma_header_address_err_cnt),
5026[C_SDMA_HEADER_SELECT_ERR] = CNTR_ELEM("SDmaHeaderSelectErr", 0, 0,
5027 CNTR_NORMAL,
5028 access_sdma_header_select_err_cnt),
5029[C_SMDA_RESERVED_9] = CNTR_ELEM("SDma Reserved 9", 0, 0,
5030 CNTR_NORMAL,
5031 access_sdma_reserved_9_err_cnt),
5032[C_SDMA_PACKET_DESC_OVERFLOW_ERR] = CNTR_ELEM("SDmaPacketDescOverflowErr", 0, 0,
5033 CNTR_NORMAL,
5034 access_sdma_packet_desc_overflow_err_cnt),
5035[C_SDMA_LENGTH_MISMATCH_ERR] = CNTR_ELEM("SDmaLengthMismatchErr", 0, 0,
5036 CNTR_NORMAL,
5037 access_sdma_length_mismatch_err_cnt),
5038[C_SDMA_HALT_ERR] = CNTR_ELEM("SDmaHaltErr", 0, 0,
5039 CNTR_NORMAL,
5040 access_sdma_halt_err_cnt),
5041[C_SDMA_MEM_READ_ERR] = CNTR_ELEM("SDmaMemReadErr", 0, 0,
5042 CNTR_NORMAL,
5043 access_sdma_mem_read_err_cnt),
5044[C_SDMA_FIRST_DESC_ERR] = CNTR_ELEM("SDmaFirstDescErr", 0, 0,
5045 CNTR_NORMAL,
5046 access_sdma_first_desc_err_cnt),
5047[C_SDMA_TAIL_OUT_OF_BOUNDS_ERR] = CNTR_ELEM("SDmaTailOutOfBoundsErr", 0, 0,
5048 CNTR_NORMAL,
5049 access_sdma_tail_out_of_bounds_err_cnt),
5050[C_SDMA_TOO_LONG_ERR] = CNTR_ELEM("SDmaTooLongErr", 0, 0,
5051 CNTR_NORMAL,
5052 access_sdma_too_long_err_cnt),
5053[C_SDMA_GEN_MISMATCH_ERR] = CNTR_ELEM("SDmaGenMismatchErr", 0, 0,
5054 CNTR_NORMAL,
5055 access_sdma_gen_mismatch_err_cnt),
5056[C_SDMA_WRONG_DW_ERR] = CNTR_ELEM("SDmaWrongDwErr", 0, 0,
5057 CNTR_NORMAL,
5058 access_sdma_wrong_dw_err_cnt),
Mike Marciniszyn77241052015-07-30 15:17:43 -04005059};
5060
5061static struct cntr_entry port_cntrs[PORT_CNTR_LAST] = {
5062[C_TX_UNSUP_VL] = TXE32_PORT_CNTR_ELEM(TxUnVLErr, SEND_UNSUP_VL_ERR_CNT,
5063 CNTR_NORMAL),
5064[C_TX_INVAL_LEN] = TXE32_PORT_CNTR_ELEM(TxInvalLen, SEND_LEN_ERR_CNT,
5065 CNTR_NORMAL),
5066[C_TX_MM_LEN_ERR] = TXE32_PORT_CNTR_ELEM(TxMMLenErr, SEND_MAX_MIN_LEN_ERR_CNT,
5067 CNTR_NORMAL),
5068[C_TX_UNDERRUN] = TXE32_PORT_CNTR_ELEM(TxUnderrun, SEND_UNDERRUN_CNT,
5069 CNTR_NORMAL),
5070[C_TX_FLOW_STALL] = TXE32_PORT_CNTR_ELEM(TxFlowStall, SEND_FLOW_STALL_CNT,
5071 CNTR_NORMAL),
5072[C_TX_DROPPED] = TXE32_PORT_CNTR_ELEM(TxDropped, SEND_DROPPED_PKT_CNT,
5073 CNTR_NORMAL),
5074[C_TX_HDR_ERR] = TXE32_PORT_CNTR_ELEM(TxHdrErr, SEND_HEADERS_ERR_CNT,
5075 CNTR_NORMAL),
5076[C_TX_PKT] = TXE64_PORT_CNTR_ELEM(TxPkt, SEND_DATA_PKT_CNT, CNTR_NORMAL),
5077[C_TX_WORDS] = TXE64_PORT_CNTR_ELEM(TxWords, SEND_DWORD_CNT, CNTR_NORMAL),
5078[C_TX_WAIT] = TXE64_PORT_CNTR_ELEM(TxWait, SEND_WAIT_CNT, CNTR_SYNTH),
5079[C_TX_FLIT_VL] = TXE64_PORT_CNTR_ELEM(TxFlitVL, SEND_DATA_VL0_CNT,
Jubin John17fb4f22016-02-14 20:21:52 -08005080 CNTR_SYNTH | CNTR_VL),
Mike Marciniszyn77241052015-07-30 15:17:43 -04005081[C_TX_PKT_VL] = TXE64_PORT_CNTR_ELEM(TxPktVL, SEND_DATA_PKT_VL0_CNT,
Jubin John17fb4f22016-02-14 20:21:52 -08005082 CNTR_SYNTH | CNTR_VL),
Mike Marciniszyn77241052015-07-30 15:17:43 -04005083[C_TX_WAIT_VL] = TXE64_PORT_CNTR_ELEM(TxWaitVL, SEND_WAIT_VL0_CNT,
Jubin John17fb4f22016-02-14 20:21:52 -08005084 CNTR_SYNTH | CNTR_VL),
Mike Marciniszyn77241052015-07-30 15:17:43 -04005085[C_RX_PKT] = RXE64_PORT_CNTR_ELEM(RxPkt, RCV_DATA_PKT_CNT, CNTR_NORMAL),
5086[C_RX_WORDS] = RXE64_PORT_CNTR_ELEM(RxWords, RCV_DWORD_CNT, CNTR_NORMAL),
5087[C_SW_LINK_DOWN] = CNTR_ELEM("SwLinkDown", 0, 0, CNTR_SYNTH | CNTR_32BIT,
Jubin John17fb4f22016-02-14 20:21:52 -08005088 access_sw_link_dn_cnt),
Mike Marciniszyn77241052015-07-30 15:17:43 -04005089[C_SW_LINK_UP] = CNTR_ELEM("SwLinkUp", 0, 0, CNTR_SYNTH | CNTR_32BIT,
Jubin John17fb4f22016-02-14 20:21:52 -08005090 access_sw_link_up_cnt),
Dean Luick6d014532015-12-01 15:38:23 -05005091[C_SW_UNKNOWN_FRAME] = CNTR_ELEM("UnknownFrame", 0, 0, CNTR_NORMAL,
5092 access_sw_unknown_frame_cnt),
Mike Marciniszyn77241052015-07-30 15:17:43 -04005093[C_SW_XMIT_DSCD] = CNTR_ELEM("XmitDscd", 0, 0, CNTR_SYNTH | CNTR_32BIT,
Jubin John17fb4f22016-02-14 20:21:52 -08005094 access_sw_xmit_discards),
Mike Marciniszyn77241052015-07-30 15:17:43 -04005095[C_SW_XMIT_DSCD_VL] = CNTR_ELEM("XmitDscdVl", 0, 0,
Jubin John17fb4f22016-02-14 20:21:52 -08005096 CNTR_SYNTH | CNTR_32BIT | CNTR_VL,
5097 access_sw_xmit_discards),
Mike Marciniszyn77241052015-07-30 15:17:43 -04005098[C_SW_XMIT_CSTR_ERR] = CNTR_ELEM("XmitCstrErr", 0, 0, CNTR_SYNTH,
Jubin John17fb4f22016-02-14 20:21:52 -08005099 access_xmit_constraint_errs),
Mike Marciniszyn77241052015-07-30 15:17:43 -04005100[C_SW_RCV_CSTR_ERR] = CNTR_ELEM("RcvCstrErr", 0, 0, CNTR_SYNTH,
Jubin John17fb4f22016-02-14 20:21:52 -08005101 access_rcv_constraint_errs),
Mike Marciniszyn77241052015-07-30 15:17:43 -04005102[C_SW_IBP_LOOP_PKTS] = SW_IBP_CNTR(LoopPkts, loop_pkts),
5103[C_SW_IBP_RC_RESENDS] = SW_IBP_CNTR(RcResend, rc_resends),
5104[C_SW_IBP_RNR_NAKS] = SW_IBP_CNTR(RnrNak, rnr_naks),
5105[C_SW_IBP_OTHER_NAKS] = SW_IBP_CNTR(OtherNak, other_naks),
5106[C_SW_IBP_RC_TIMEOUTS] = SW_IBP_CNTR(RcTimeOut, rc_timeouts),
5107[C_SW_IBP_PKT_DROPS] = SW_IBP_CNTR(PktDrop, pkt_drops),
5108[C_SW_IBP_DMA_WAIT] = SW_IBP_CNTR(DmaWait, dmawait),
5109[C_SW_IBP_RC_SEQNAK] = SW_IBP_CNTR(RcSeqNak, rc_seqnak),
5110[C_SW_IBP_RC_DUPREQ] = SW_IBP_CNTR(RcDupRew, rc_dupreq),
5111[C_SW_IBP_RDMA_SEQ] = SW_IBP_CNTR(RdmaSeq, rdma_seq),
5112[C_SW_IBP_UNALIGNED] = SW_IBP_CNTR(Unaligned, unaligned),
5113[C_SW_IBP_SEQ_NAK] = SW_IBP_CNTR(SeqNak, seq_naks),
5114[C_SW_CPU_RC_ACKS] = CNTR_ELEM("RcAcks", 0, 0, CNTR_NORMAL,
5115 access_sw_cpu_rc_acks),
5116[C_SW_CPU_RC_QACKS] = CNTR_ELEM("RcQacks", 0, 0, CNTR_NORMAL,
Jubin John17fb4f22016-02-14 20:21:52 -08005117 access_sw_cpu_rc_qacks),
Mike Marciniszyn77241052015-07-30 15:17:43 -04005118[C_SW_CPU_RC_DELAYED_COMP] = CNTR_ELEM("RcDelayComp", 0, 0, CNTR_NORMAL,
Jubin John17fb4f22016-02-14 20:21:52 -08005119 access_sw_cpu_rc_delayed_comp),
Mike Marciniszyn77241052015-07-30 15:17:43 -04005120[OVR_LBL(0)] = OVR_ELM(0), [OVR_LBL(1)] = OVR_ELM(1),
5121[OVR_LBL(2)] = OVR_ELM(2), [OVR_LBL(3)] = OVR_ELM(3),
5122[OVR_LBL(4)] = OVR_ELM(4), [OVR_LBL(5)] = OVR_ELM(5),
5123[OVR_LBL(6)] = OVR_ELM(6), [OVR_LBL(7)] = OVR_ELM(7),
5124[OVR_LBL(8)] = OVR_ELM(8), [OVR_LBL(9)] = OVR_ELM(9),
5125[OVR_LBL(10)] = OVR_ELM(10), [OVR_LBL(11)] = OVR_ELM(11),
5126[OVR_LBL(12)] = OVR_ELM(12), [OVR_LBL(13)] = OVR_ELM(13),
5127[OVR_LBL(14)] = OVR_ELM(14), [OVR_LBL(15)] = OVR_ELM(15),
5128[OVR_LBL(16)] = OVR_ELM(16), [OVR_LBL(17)] = OVR_ELM(17),
5129[OVR_LBL(18)] = OVR_ELM(18), [OVR_LBL(19)] = OVR_ELM(19),
5130[OVR_LBL(20)] = OVR_ELM(20), [OVR_LBL(21)] = OVR_ELM(21),
5131[OVR_LBL(22)] = OVR_ELM(22), [OVR_LBL(23)] = OVR_ELM(23),
5132[OVR_LBL(24)] = OVR_ELM(24), [OVR_LBL(25)] = OVR_ELM(25),
5133[OVR_LBL(26)] = OVR_ELM(26), [OVR_LBL(27)] = OVR_ELM(27),
5134[OVR_LBL(28)] = OVR_ELM(28), [OVR_LBL(29)] = OVR_ELM(29),
5135[OVR_LBL(30)] = OVR_ELM(30), [OVR_LBL(31)] = OVR_ELM(31),
5136[OVR_LBL(32)] = OVR_ELM(32), [OVR_LBL(33)] = OVR_ELM(33),
5137[OVR_LBL(34)] = OVR_ELM(34), [OVR_LBL(35)] = OVR_ELM(35),
5138[OVR_LBL(36)] = OVR_ELM(36), [OVR_LBL(37)] = OVR_ELM(37),
5139[OVR_LBL(38)] = OVR_ELM(38), [OVR_LBL(39)] = OVR_ELM(39),
5140[OVR_LBL(40)] = OVR_ELM(40), [OVR_LBL(41)] = OVR_ELM(41),
5141[OVR_LBL(42)] = OVR_ELM(42), [OVR_LBL(43)] = OVR_ELM(43),
5142[OVR_LBL(44)] = OVR_ELM(44), [OVR_LBL(45)] = OVR_ELM(45),
5143[OVR_LBL(46)] = OVR_ELM(46), [OVR_LBL(47)] = OVR_ELM(47),
5144[OVR_LBL(48)] = OVR_ELM(48), [OVR_LBL(49)] = OVR_ELM(49),
5145[OVR_LBL(50)] = OVR_ELM(50), [OVR_LBL(51)] = OVR_ELM(51),
5146[OVR_LBL(52)] = OVR_ELM(52), [OVR_LBL(53)] = OVR_ELM(53),
5147[OVR_LBL(54)] = OVR_ELM(54), [OVR_LBL(55)] = OVR_ELM(55),
5148[OVR_LBL(56)] = OVR_ELM(56), [OVR_LBL(57)] = OVR_ELM(57),
5149[OVR_LBL(58)] = OVR_ELM(58), [OVR_LBL(59)] = OVR_ELM(59),
5150[OVR_LBL(60)] = OVR_ELM(60), [OVR_LBL(61)] = OVR_ELM(61),
5151[OVR_LBL(62)] = OVR_ELM(62), [OVR_LBL(63)] = OVR_ELM(63),
5152[OVR_LBL(64)] = OVR_ELM(64), [OVR_LBL(65)] = OVR_ELM(65),
5153[OVR_LBL(66)] = OVR_ELM(66), [OVR_LBL(67)] = OVR_ELM(67),
5154[OVR_LBL(68)] = OVR_ELM(68), [OVR_LBL(69)] = OVR_ELM(69),
5155[OVR_LBL(70)] = OVR_ELM(70), [OVR_LBL(71)] = OVR_ELM(71),
5156[OVR_LBL(72)] = OVR_ELM(72), [OVR_LBL(73)] = OVR_ELM(73),
5157[OVR_LBL(74)] = OVR_ELM(74), [OVR_LBL(75)] = OVR_ELM(75),
5158[OVR_LBL(76)] = OVR_ELM(76), [OVR_LBL(77)] = OVR_ELM(77),
5159[OVR_LBL(78)] = OVR_ELM(78), [OVR_LBL(79)] = OVR_ELM(79),
5160[OVR_LBL(80)] = OVR_ELM(80), [OVR_LBL(81)] = OVR_ELM(81),
5161[OVR_LBL(82)] = OVR_ELM(82), [OVR_LBL(83)] = OVR_ELM(83),
5162[OVR_LBL(84)] = OVR_ELM(84), [OVR_LBL(85)] = OVR_ELM(85),
5163[OVR_LBL(86)] = OVR_ELM(86), [OVR_LBL(87)] = OVR_ELM(87),
5164[OVR_LBL(88)] = OVR_ELM(88), [OVR_LBL(89)] = OVR_ELM(89),
5165[OVR_LBL(90)] = OVR_ELM(90), [OVR_LBL(91)] = OVR_ELM(91),
5166[OVR_LBL(92)] = OVR_ELM(92), [OVR_LBL(93)] = OVR_ELM(93),
5167[OVR_LBL(94)] = OVR_ELM(94), [OVR_LBL(95)] = OVR_ELM(95),
5168[OVR_LBL(96)] = OVR_ELM(96), [OVR_LBL(97)] = OVR_ELM(97),
5169[OVR_LBL(98)] = OVR_ELM(98), [OVR_LBL(99)] = OVR_ELM(99),
5170[OVR_LBL(100)] = OVR_ELM(100), [OVR_LBL(101)] = OVR_ELM(101),
5171[OVR_LBL(102)] = OVR_ELM(102), [OVR_LBL(103)] = OVR_ELM(103),
5172[OVR_LBL(104)] = OVR_ELM(104), [OVR_LBL(105)] = OVR_ELM(105),
5173[OVR_LBL(106)] = OVR_ELM(106), [OVR_LBL(107)] = OVR_ELM(107),
5174[OVR_LBL(108)] = OVR_ELM(108), [OVR_LBL(109)] = OVR_ELM(109),
5175[OVR_LBL(110)] = OVR_ELM(110), [OVR_LBL(111)] = OVR_ELM(111),
5176[OVR_LBL(112)] = OVR_ELM(112), [OVR_LBL(113)] = OVR_ELM(113),
5177[OVR_LBL(114)] = OVR_ELM(114), [OVR_LBL(115)] = OVR_ELM(115),
5178[OVR_LBL(116)] = OVR_ELM(116), [OVR_LBL(117)] = OVR_ELM(117),
5179[OVR_LBL(118)] = OVR_ELM(118), [OVR_LBL(119)] = OVR_ELM(119),
5180[OVR_LBL(120)] = OVR_ELM(120), [OVR_LBL(121)] = OVR_ELM(121),
5181[OVR_LBL(122)] = OVR_ELM(122), [OVR_LBL(123)] = OVR_ELM(123),
5182[OVR_LBL(124)] = OVR_ELM(124), [OVR_LBL(125)] = OVR_ELM(125),
5183[OVR_LBL(126)] = OVR_ELM(126), [OVR_LBL(127)] = OVR_ELM(127),
5184[OVR_LBL(128)] = OVR_ELM(128), [OVR_LBL(129)] = OVR_ELM(129),
5185[OVR_LBL(130)] = OVR_ELM(130), [OVR_LBL(131)] = OVR_ELM(131),
5186[OVR_LBL(132)] = OVR_ELM(132), [OVR_LBL(133)] = OVR_ELM(133),
5187[OVR_LBL(134)] = OVR_ELM(134), [OVR_LBL(135)] = OVR_ELM(135),
5188[OVR_LBL(136)] = OVR_ELM(136), [OVR_LBL(137)] = OVR_ELM(137),
5189[OVR_LBL(138)] = OVR_ELM(138), [OVR_LBL(139)] = OVR_ELM(139),
5190[OVR_LBL(140)] = OVR_ELM(140), [OVR_LBL(141)] = OVR_ELM(141),
5191[OVR_LBL(142)] = OVR_ELM(142), [OVR_LBL(143)] = OVR_ELM(143),
5192[OVR_LBL(144)] = OVR_ELM(144), [OVR_LBL(145)] = OVR_ELM(145),
5193[OVR_LBL(146)] = OVR_ELM(146), [OVR_LBL(147)] = OVR_ELM(147),
5194[OVR_LBL(148)] = OVR_ELM(148), [OVR_LBL(149)] = OVR_ELM(149),
5195[OVR_LBL(150)] = OVR_ELM(150), [OVR_LBL(151)] = OVR_ELM(151),
5196[OVR_LBL(152)] = OVR_ELM(152), [OVR_LBL(153)] = OVR_ELM(153),
5197[OVR_LBL(154)] = OVR_ELM(154), [OVR_LBL(155)] = OVR_ELM(155),
5198[OVR_LBL(156)] = OVR_ELM(156), [OVR_LBL(157)] = OVR_ELM(157),
5199[OVR_LBL(158)] = OVR_ELM(158), [OVR_LBL(159)] = OVR_ELM(159),
5200};
5201
5202/* ======================================================================== */
5203
Mike Marciniszyn77241052015-07-30 15:17:43 -04005204/* return true if this is chip revision revision a */
5205int is_ax(struct hfi1_devdata *dd)
5206{
5207 u8 chip_rev_minor =
5208 dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT
5209 & CCE_REVISION_CHIP_REV_MINOR_MASK;
5210 return (chip_rev_minor & 0xf0) == 0;
5211}
5212
5213/* return true if this is chip revision revision b */
5214int is_bx(struct hfi1_devdata *dd)
5215{
5216 u8 chip_rev_minor =
5217 dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT
5218 & CCE_REVISION_CHIP_REV_MINOR_MASK;
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05005219 return (chip_rev_minor & 0xF0) == 0x10;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005220}
5221
5222/*
5223 * Append string s to buffer buf. Arguments curp and len are the current
5224 * position and remaining length, respectively.
5225 *
5226 * return 0 on success, 1 on out of room
5227 */
5228static int append_str(char *buf, char **curp, int *lenp, const char *s)
5229{
5230 char *p = *curp;
5231 int len = *lenp;
5232 int result = 0; /* success */
5233 char c;
5234
5235 /* add a comma, if first in the buffer */
5236 if (p != buf) {
5237 if (len == 0) {
5238 result = 1; /* out of room */
5239 goto done;
5240 }
5241 *p++ = ',';
5242 len--;
5243 }
5244
5245 /* copy the string */
5246 while ((c = *s++) != 0) {
5247 if (len == 0) {
5248 result = 1; /* out of room */
5249 goto done;
5250 }
5251 *p++ = c;
5252 len--;
5253 }
5254
5255done:
5256 /* write return values */
5257 *curp = p;
5258 *lenp = len;
5259
5260 return result;
5261}
5262
5263/*
5264 * Using the given flag table, print a comma separated string into
5265 * the buffer. End in '*' if the buffer is too short.
5266 */
5267static char *flag_string(char *buf, int buf_len, u64 flags,
Jubin John17fb4f22016-02-14 20:21:52 -08005268 struct flag_table *table, int table_size)
Mike Marciniszyn77241052015-07-30 15:17:43 -04005269{
5270 char extra[32];
5271 char *p = buf;
5272 int len = buf_len;
5273 int no_room = 0;
5274 int i;
5275
5276 /* make sure there is at least 2 so we can form "*" */
5277 if (len < 2)
5278 return "";
5279
5280 len--; /* leave room for a nul */
5281 for (i = 0; i < table_size; i++) {
5282 if (flags & table[i].flag) {
5283 no_room = append_str(buf, &p, &len, table[i].str);
5284 if (no_room)
5285 break;
5286 flags &= ~table[i].flag;
5287 }
5288 }
5289
5290 /* any undocumented bits left? */
5291 if (!no_room && flags) {
5292 snprintf(extra, sizeof(extra), "bits 0x%llx", flags);
5293 no_room = append_str(buf, &p, &len, extra);
5294 }
5295
5296 /* add * if ran out of room */
5297 if (no_room) {
5298 /* may need to back up to add space for a '*' */
5299 if (len == 0)
5300 --p;
5301 *p++ = '*';
5302 }
5303
5304 /* add final nul - space already allocated above */
5305 *p = 0;
5306 return buf;
5307}
5308
5309/* first 8 CCE error interrupt source names */
5310static const char * const cce_misc_names[] = {
5311 "CceErrInt", /* 0 */
5312 "RxeErrInt", /* 1 */
5313 "MiscErrInt", /* 2 */
5314 "Reserved3", /* 3 */
5315 "PioErrInt", /* 4 */
5316 "SDmaErrInt", /* 5 */
5317 "EgressErrInt", /* 6 */
5318 "TxeErrInt" /* 7 */
5319};
5320
5321/*
5322 * Return the miscellaneous error interrupt name.
5323 */
5324static char *is_misc_err_name(char *buf, size_t bsize, unsigned int source)
5325{
5326 if (source < ARRAY_SIZE(cce_misc_names))
5327 strncpy(buf, cce_misc_names[source], bsize);
5328 else
Jubin John17fb4f22016-02-14 20:21:52 -08005329 snprintf(buf, bsize, "Reserved%u",
5330 source + IS_GENERAL_ERR_START);
Mike Marciniszyn77241052015-07-30 15:17:43 -04005331
5332 return buf;
5333}
5334
5335/*
5336 * Return the SDMA engine error interrupt name.
5337 */
5338static char *is_sdma_eng_err_name(char *buf, size_t bsize, unsigned int source)
5339{
5340 snprintf(buf, bsize, "SDmaEngErrInt%u", source);
5341 return buf;
5342}
5343
5344/*
5345 * Return the send context error interrupt name.
5346 */
5347static char *is_sendctxt_err_name(char *buf, size_t bsize, unsigned int source)
5348{
5349 snprintf(buf, bsize, "SendCtxtErrInt%u", source);
5350 return buf;
5351}
5352
5353static const char * const various_names[] = {
5354 "PbcInt",
5355 "GpioAssertInt",
5356 "Qsfp1Int",
5357 "Qsfp2Int",
5358 "TCritInt"
5359};
5360
5361/*
5362 * Return the various interrupt name.
5363 */
5364static char *is_various_name(char *buf, size_t bsize, unsigned int source)
5365{
5366 if (source < ARRAY_SIZE(various_names))
5367 strncpy(buf, various_names[source], bsize);
5368 else
Jubin John8638b772016-02-14 20:19:24 -08005369 snprintf(buf, bsize, "Reserved%u", source + IS_VARIOUS_START);
Mike Marciniszyn77241052015-07-30 15:17:43 -04005370 return buf;
5371}
5372
5373/*
5374 * Return the DC interrupt name.
5375 */
5376static char *is_dc_name(char *buf, size_t bsize, unsigned int source)
5377{
5378 static const char * const dc_int_names[] = {
5379 "common",
5380 "lcb",
5381 "8051",
5382 "lbm" /* local block merge */
5383 };
5384
5385 if (source < ARRAY_SIZE(dc_int_names))
5386 snprintf(buf, bsize, "dc_%s_int", dc_int_names[source]);
5387 else
5388 snprintf(buf, bsize, "DCInt%u", source);
5389 return buf;
5390}
5391
5392static const char * const sdma_int_names[] = {
5393 "SDmaInt",
5394 "SdmaIdleInt",
5395 "SdmaProgressInt",
5396};
5397
5398/*
5399 * Return the SDMA engine interrupt name.
5400 */
5401static char *is_sdma_eng_name(char *buf, size_t bsize, unsigned int source)
5402{
5403 /* what interrupt */
5404 unsigned int what = source / TXE_NUM_SDMA_ENGINES;
5405 /* which engine */
5406 unsigned int which = source % TXE_NUM_SDMA_ENGINES;
5407
5408 if (likely(what < 3))
5409 snprintf(buf, bsize, "%s%u", sdma_int_names[what], which);
5410 else
5411 snprintf(buf, bsize, "Invalid SDMA interrupt %u", source);
5412 return buf;
5413}
5414
5415/*
5416 * Return the receive available interrupt name.
5417 */
5418static char *is_rcv_avail_name(char *buf, size_t bsize, unsigned int source)
5419{
5420 snprintf(buf, bsize, "RcvAvailInt%u", source);
5421 return buf;
5422}
5423
5424/*
5425 * Return the receive urgent interrupt name.
5426 */
5427static char *is_rcv_urgent_name(char *buf, size_t bsize, unsigned int source)
5428{
5429 snprintf(buf, bsize, "RcvUrgentInt%u", source);
5430 return buf;
5431}
5432
5433/*
5434 * Return the send credit interrupt name.
5435 */
5436static char *is_send_credit_name(char *buf, size_t bsize, unsigned int source)
5437{
5438 snprintf(buf, bsize, "SendCreditInt%u", source);
5439 return buf;
5440}
5441
5442/*
5443 * Return the reserved interrupt name.
5444 */
5445static char *is_reserved_name(char *buf, size_t bsize, unsigned int source)
5446{
5447 snprintf(buf, bsize, "Reserved%u", source + IS_RESERVED_START);
5448 return buf;
5449}
5450
5451static char *cce_err_status_string(char *buf, int buf_len, u64 flags)
5452{
5453 return flag_string(buf, buf_len, flags,
Jubin John17fb4f22016-02-14 20:21:52 -08005454 cce_err_status_flags,
5455 ARRAY_SIZE(cce_err_status_flags));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005456}
5457
5458static char *rxe_err_status_string(char *buf, int buf_len, u64 flags)
5459{
5460 return flag_string(buf, buf_len, flags,
Jubin John17fb4f22016-02-14 20:21:52 -08005461 rxe_err_status_flags,
5462 ARRAY_SIZE(rxe_err_status_flags));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005463}
5464
5465static char *misc_err_status_string(char *buf, int buf_len, u64 flags)
5466{
5467 return flag_string(buf, buf_len, flags, misc_err_status_flags,
Jubin John17fb4f22016-02-14 20:21:52 -08005468 ARRAY_SIZE(misc_err_status_flags));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005469}
5470
5471static char *pio_err_status_string(char *buf, int buf_len, u64 flags)
5472{
5473 return flag_string(buf, buf_len, flags,
Jubin John17fb4f22016-02-14 20:21:52 -08005474 pio_err_status_flags,
5475 ARRAY_SIZE(pio_err_status_flags));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005476}
5477
5478static char *sdma_err_status_string(char *buf, int buf_len, u64 flags)
5479{
5480 return flag_string(buf, buf_len, flags,
Jubin John17fb4f22016-02-14 20:21:52 -08005481 sdma_err_status_flags,
5482 ARRAY_SIZE(sdma_err_status_flags));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005483}
5484
5485static char *egress_err_status_string(char *buf, int buf_len, u64 flags)
5486{
5487 return flag_string(buf, buf_len, flags,
Jubin John17fb4f22016-02-14 20:21:52 -08005488 egress_err_status_flags,
5489 ARRAY_SIZE(egress_err_status_flags));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005490}
5491
5492static char *egress_err_info_string(char *buf, int buf_len, u64 flags)
5493{
5494 return flag_string(buf, buf_len, flags,
Jubin John17fb4f22016-02-14 20:21:52 -08005495 egress_err_info_flags,
5496 ARRAY_SIZE(egress_err_info_flags));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005497}
5498
5499static char *send_err_status_string(char *buf, int buf_len, u64 flags)
5500{
5501 return flag_string(buf, buf_len, flags,
Jubin John17fb4f22016-02-14 20:21:52 -08005502 send_err_status_flags,
5503 ARRAY_SIZE(send_err_status_flags));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005504}
5505
5506static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5507{
5508 char buf[96];
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005509 int i = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005510
5511 /*
5512 * For most these errors, there is nothing that can be done except
5513 * report or record it.
5514 */
5515 dd_dev_info(dd, "CCE Error: %s\n",
Jubin John17fb4f22016-02-14 20:21:52 -08005516 cce_err_status_string(buf, sizeof(buf), reg));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005517
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05005518 if ((reg & CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK) &&
5519 is_ax(dd) && (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04005520 /* this error requires a manual drop into SPC freeze mode */
5521 /* then a fix up */
5522 start_freeze_handling(dd->pport, FREEZE_SELF);
5523 }
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005524
5525 for (i = 0; i < NUM_CCE_ERR_STATUS_COUNTERS; i++) {
5526 if (reg & (1ull << i)) {
5527 incr_cntr64(&dd->cce_err_status_cnt[i]);
5528 /* maintain a counter over all cce_err_status errors */
5529 incr_cntr64(&dd->sw_cce_err_status_aggregate);
5530 }
5531 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04005532}
5533
5534/*
5535 * Check counters for receive errors that do not have an interrupt
5536 * associated with them.
5537 */
5538#define RCVERR_CHECK_TIME 10
5539static void update_rcverr_timer(unsigned long opaque)
5540{
5541 struct hfi1_devdata *dd = (struct hfi1_devdata *)opaque;
5542 struct hfi1_pportdata *ppd = dd->pport;
5543 u32 cur_ovfl_cnt = read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL);
5544
5545 if (dd->rcv_ovfl_cnt < cur_ovfl_cnt &&
Jubin John17fb4f22016-02-14 20:21:52 -08005546 ppd->port_error_action & OPA_PI_MASK_EX_BUFFER_OVERRUN) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04005547 dd_dev_info(dd, "%s: PortErrorAction bounce\n", __func__);
Jubin John17fb4f22016-02-14 20:21:52 -08005548 set_link_down_reason(
5549 ppd, OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN, 0,
5550 OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN);
Sebastian Sanchez71d47002017-07-29 08:43:49 -07005551 queue_work(ppd->link_wq, &ppd->link_bounce_work);
Mike Marciniszyn77241052015-07-30 15:17:43 -04005552 }
Jubin John50e5dcb2016-02-14 20:19:41 -08005553 dd->rcv_ovfl_cnt = (u32)cur_ovfl_cnt;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005554
5555 mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
5556}
5557
5558static int init_rcverr(struct hfi1_devdata *dd)
5559{
Muhammad Falak R Wani24523a92015-10-25 16:13:23 +05305560 setup_timer(&dd->rcverr_timer, update_rcverr_timer, (unsigned long)dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04005561 /* Assume the hardware counter has been reset */
5562 dd->rcv_ovfl_cnt = 0;
5563 return mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
5564}
5565
5566static void free_rcverr(struct hfi1_devdata *dd)
5567{
5568 if (dd->rcverr_timer.data)
5569 del_timer_sync(&dd->rcverr_timer);
5570 dd->rcverr_timer.data = 0;
5571}
5572
5573static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5574{
5575 char buf[96];
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005576 int i = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005577
5578 dd_dev_info(dd, "Receive Error: %s\n",
Jubin John17fb4f22016-02-14 20:21:52 -08005579 rxe_err_status_string(buf, sizeof(buf), reg));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005580
5581 if (reg & ALL_RXE_FREEZE_ERR) {
5582 int flags = 0;
5583
5584 /*
5585 * Freeze mode recovery is disabled for the errors
5586 * in RXE_FREEZE_ABORT_MASK
5587 */
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05005588 if (is_ax(dd) && (reg & RXE_FREEZE_ABORT_MASK))
Mike Marciniszyn77241052015-07-30 15:17:43 -04005589 flags = FREEZE_ABORT;
5590
5591 start_freeze_handling(dd->pport, flags);
5592 }
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005593
5594 for (i = 0; i < NUM_RCV_ERR_STATUS_COUNTERS; i++) {
5595 if (reg & (1ull << i))
5596 incr_cntr64(&dd->rcv_err_status_cnt[i]);
5597 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04005598}
5599
5600static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5601{
5602 char buf[96];
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005603 int i = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005604
5605 dd_dev_info(dd, "Misc Error: %s",
Jubin John17fb4f22016-02-14 20:21:52 -08005606 misc_err_status_string(buf, sizeof(buf), reg));
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005607 for (i = 0; i < NUM_MISC_ERR_STATUS_COUNTERS; i++) {
5608 if (reg & (1ull << i))
5609 incr_cntr64(&dd->misc_err_status_cnt[i]);
5610 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04005611}
5612
5613static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5614{
5615 char buf[96];
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005616 int i = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005617
5618 dd_dev_info(dd, "PIO Error: %s\n",
Jubin John17fb4f22016-02-14 20:21:52 -08005619 pio_err_status_string(buf, sizeof(buf), reg));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005620
5621 if (reg & ALL_PIO_FREEZE_ERR)
5622 start_freeze_handling(dd->pport, 0);
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005623
5624 for (i = 0; i < NUM_SEND_PIO_ERR_STATUS_COUNTERS; i++) {
5625 if (reg & (1ull << i))
5626 incr_cntr64(&dd->send_pio_err_status_cnt[i]);
5627 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04005628}
5629
5630static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5631{
5632 char buf[96];
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005633 int i = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005634
5635 dd_dev_info(dd, "SDMA Error: %s\n",
Jubin John17fb4f22016-02-14 20:21:52 -08005636 sdma_err_status_string(buf, sizeof(buf), reg));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005637
5638 if (reg & ALL_SDMA_FREEZE_ERR)
5639 start_freeze_handling(dd->pport, 0);
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005640
5641 for (i = 0; i < NUM_SEND_DMA_ERR_STATUS_COUNTERS; i++) {
5642 if (reg & (1ull << i))
5643 incr_cntr64(&dd->send_dma_err_status_cnt[i]);
5644 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04005645}
5646
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005647static inline void __count_port_discards(struct hfi1_pportdata *ppd)
5648{
5649 incr_cntr64(&ppd->port_xmit_discards);
5650}
5651
Mike Marciniszyn77241052015-07-30 15:17:43 -04005652static void count_port_inactive(struct hfi1_devdata *dd)
5653{
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005654 __count_port_discards(dd->pport);
Mike Marciniszyn77241052015-07-30 15:17:43 -04005655}
5656
5657/*
5658 * We have had a "disallowed packet" error during egress. Determine the
5659 * integrity check which failed, and update relevant error counter, etc.
5660 *
5661 * Note that the SEND_EGRESS_ERR_INFO register has only a single
5662 * bit of state per integrity check, and so we can miss the reason for an
5663 * egress error if more than one packet fails the same integrity check
5664 * since we cleared the corresponding bit in SEND_EGRESS_ERR_INFO.
5665 */
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005666static void handle_send_egress_err_info(struct hfi1_devdata *dd,
5667 int vl)
Mike Marciniszyn77241052015-07-30 15:17:43 -04005668{
5669 struct hfi1_pportdata *ppd = dd->pport;
5670 u64 src = read_csr(dd, SEND_EGRESS_ERR_SOURCE); /* read first */
5671 u64 info = read_csr(dd, SEND_EGRESS_ERR_INFO);
5672 char buf[96];
5673
5674 /* clear down all observed info as quickly as possible after read */
5675 write_csr(dd, SEND_EGRESS_ERR_INFO, info);
5676
5677 dd_dev_info(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08005678 "Egress Error Info: 0x%llx, %s Egress Error Src 0x%llx\n",
5679 info, egress_err_info_string(buf, sizeof(buf), info), src);
Mike Marciniszyn77241052015-07-30 15:17:43 -04005680
5681 /* Eventually add other counters for each bit */
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005682 if (info & PORT_DISCARD_EGRESS_ERRS) {
5683 int weight, i;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005684
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005685 /*
Dean Luick4c9e7aa2016-02-18 11:12:08 -08005686 * Count all applicable bits as individual errors and
5687 * attribute them to the packet that triggered this handler.
5688 * This may not be completely accurate due to limitations
5689 * on the available hardware error information. There is
5690 * a single information register and any number of error
5691 * packets may have occurred and contributed to it before
5692 * this routine is called. This means that:
5693 * a) If multiple packets with the same error occur before
5694 * this routine is called, earlier packets are missed.
5695 * There is only a single bit for each error type.
5696 * b) Errors may not be attributed to the correct VL.
5697 * The driver is attributing all bits in the info register
5698 * to the packet that triggered this call, but bits
5699 * could be an accumulation of different packets with
5700 * different VLs.
5701 * c) A single error packet may have multiple counts attached
5702 * to it. There is no way for the driver to know if
5703 * multiple bits set in the info register are due to a
5704 * single packet or multiple packets. The driver assumes
5705 * multiple packets.
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005706 */
Dean Luick4c9e7aa2016-02-18 11:12:08 -08005707 weight = hweight64(info & PORT_DISCARD_EGRESS_ERRS);
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005708 for (i = 0; i < weight; i++) {
5709 __count_port_discards(ppd);
5710 if (vl >= 0 && vl < TXE_NUM_DATA_VL)
5711 incr_cntr64(&ppd->port_xmit_discards_vl[vl]);
5712 else if (vl == 15)
5713 incr_cntr64(&ppd->port_xmit_discards_vl
5714 [C_VL_15]);
5715 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04005716 }
5717}
5718
5719/*
5720 * Input value is a bit position within the SEND_EGRESS_ERR_STATUS
5721 * register. Does it represent a 'port inactive' error?
5722 */
5723static inline int port_inactive_err(u64 posn)
5724{
5725 return (posn >= SEES(TX_LINKDOWN) &&
5726 posn <= SEES(TX_INCORRECT_LINK_STATE));
5727}
5728
5729/*
5730 * Input value is a bit position within the SEND_EGRESS_ERR_STATUS
5731 * register. Does it represent a 'disallowed packet' error?
5732 */
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005733static inline int disallowed_pkt_err(int posn)
Mike Marciniszyn77241052015-07-30 15:17:43 -04005734{
5735 return (posn >= SEES(TX_SDMA0_DISALLOWED_PACKET) &&
5736 posn <= SEES(TX_SDMA15_DISALLOWED_PACKET));
5737}
5738
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005739/*
5740 * Input value is a bit position of one of the SDMA engine disallowed
5741 * packet errors. Return which engine. Use of this must be guarded by
5742 * disallowed_pkt_err().
5743 */
5744static inline int disallowed_pkt_engine(int posn)
5745{
5746 return posn - SEES(TX_SDMA0_DISALLOWED_PACKET);
5747}
5748
5749/*
5750 * Translate an SDMA engine to a VL. Return -1 if the tranlation cannot
5751 * be done.
5752 */
5753static int engine_to_vl(struct hfi1_devdata *dd, int engine)
5754{
5755 struct sdma_vl_map *m;
5756 int vl;
5757
5758 /* range check */
5759 if (engine < 0 || engine >= TXE_NUM_SDMA_ENGINES)
5760 return -1;
5761
5762 rcu_read_lock();
5763 m = rcu_dereference(dd->sdma_map);
5764 vl = m->engine_to_vl[engine];
5765 rcu_read_unlock();
5766
5767 return vl;
5768}
5769
5770/*
5771 * Translate the send context (sofware index) into a VL. Return -1 if the
5772 * translation cannot be done.
5773 */
5774static int sc_to_vl(struct hfi1_devdata *dd, int sw_index)
5775{
5776 struct send_context_info *sci;
5777 struct send_context *sc;
5778 int i;
5779
5780 sci = &dd->send_contexts[sw_index];
5781
5782 /* there is no information for user (PSM) and ack contexts */
Jianxin Xiong44306f12016-04-12 11:30:28 -07005783 if ((sci->type != SC_KERNEL) && (sci->type != SC_VL15))
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005784 return -1;
5785
5786 sc = sci->sc;
5787 if (!sc)
5788 return -1;
5789 if (dd->vld[15].sc == sc)
5790 return 15;
5791 for (i = 0; i < num_vls; i++)
5792 if (dd->vld[i].sc == sc)
5793 return i;
5794
5795 return -1;
5796}
5797
Mike Marciniszyn77241052015-07-30 15:17:43 -04005798static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5799{
5800 u64 reg_copy = reg, handled = 0;
5801 char buf[96];
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005802 int i = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005803
5804 if (reg & ALL_TXE_EGRESS_FREEZE_ERR)
5805 start_freeze_handling(dd->pport, 0);
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005806 else if (is_ax(dd) &&
5807 (reg & SEND_EGRESS_ERR_STATUS_TX_CREDIT_RETURN_VL_ERR_SMASK) &&
5808 (dd->icode != ICODE_FUNCTIONAL_SIMULATOR))
Mike Marciniszyn77241052015-07-30 15:17:43 -04005809 start_freeze_handling(dd->pport, 0);
5810
5811 while (reg_copy) {
5812 int posn = fls64(reg_copy);
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005813 /* fls64() returns a 1-based offset, we want it zero based */
Mike Marciniszyn77241052015-07-30 15:17:43 -04005814 int shift = posn - 1;
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005815 u64 mask = 1ULL << shift;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005816
5817 if (port_inactive_err(shift)) {
5818 count_port_inactive(dd);
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005819 handled |= mask;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005820 } else if (disallowed_pkt_err(shift)) {
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005821 int vl = engine_to_vl(dd, disallowed_pkt_engine(shift));
5822
5823 handle_send_egress_err_info(dd, vl);
5824 handled |= mask;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005825 }
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005826 reg_copy &= ~mask;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005827 }
5828
5829 reg &= ~handled;
5830
5831 if (reg)
5832 dd_dev_info(dd, "Egress Error: %s\n",
Jubin John17fb4f22016-02-14 20:21:52 -08005833 egress_err_status_string(buf, sizeof(buf), reg));
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005834
5835 for (i = 0; i < NUM_SEND_EGRESS_ERR_STATUS_COUNTERS; i++) {
5836 if (reg & (1ull << i))
5837 incr_cntr64(&dd->send_egress_err_status_cnt[i]);
5838 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04005839}
5840
5841static void handle_txe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
5842{
5843 char buf[96];
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005844 int i = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005845
5846 dd_dev_info(dd, "Send Error: %s\n",
Jubin John17fb4f22016-02-14 20:21:52 -08005847 send_err_status_string(buf, sizeof(buf), reg));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005848
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005849 for (i = 0; i < NUM_SEND_ERR_STATUS_COUNTERS; i++) {
5850 if (reg & (1ull << i))
5851 incr_cntr64(&dd->send_err_status_cnt[i]);
5852 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04005853}
5854
5855/*
5856 * The maximum number of times the error clear down will loop before
5857 * blocking a repeating error. This value is arbitrary.
5858 */
5859#define MAX_CLEAR_COUNT 20
5860
5861/*
5862 * Clear and handle an error register. All error interrupts are funneled
5863 * through here to have a central location to correctly handle single-
5864 * or multi-shot errors.
5865 *
5866 * For non per-context registers, call this routine with a context value
5867 * of 0 so the per-context offset is zero.
5868 *
5869 * If the handler loops too many times, assume that something is wrong
5870 * and can't be fixed, so mask the error bits.
5871 */
5872static void interrupt_clear_down(struct hfi1_devdata *dd,
5873 u32 context,
5874 const struct err_reg_info *eri)
5875{
5876 u64 reg;
5877 u32 count;
5878
5879 /* read in a loop until no more errors are seen */
5880 count = 0;
5881 while (1) {
5882 reg = read_kctxt_csr(dd, context, eri->status);
5883 if (reg == 0)
5884 break;
5885 write_kctxt_csr(dd, context, eri->clear, reg);
5886 if (likely(eri->handler))
5887 eri->handler(dd, context, reg);
5888 count++;
5889 if (count > MAX_CLEAR_COUNT) {
5890 u64 mask;
5891
5892 dd_dev_err(dd, "Repeating %s bits 0x%llx - masking\n",
Jubin John17fb4f22016-02-14 20:21:52 -08005893 eri->desc, reg);
Mike Marciniszyn77241052015-07-30 15:17:43 -04005894 /*
5895 * Read-modify-write so any other masked bits
5896 * remain masked.
5897 */
5898 mask = read_kctxt_csr(dd, context, eri->mask);
5899 mask &= ~reg;
5900 write_kctxt_csr(dd, context, eri->mask, mask);
5901 break;
5902 }
5903 }
5904}
5905
5906/*
5907 * CCE block "misc" interrupt. Source is < 16.
5908 */
5909static void is_misc_err_int(struct hfi1_devdata *dd, unsigned int source)
5910{
5911 const struct err_reg_info *eri = &misc_errs[source];
5912
5913 if (eri->handler) {
5914 interrupt_clear_down(dd, 0, eri);
5915 } else {
5916 dd_dev_err(dd, "Unexpected misc interrupt (%u) - reserved\n",
Jubin John17fb4f22016-02-14 20:21:52 -08005917 source);
Mike Marciniszyn77241052015-07-30 15:17:43 -04005918 }
5919}
5920
5921static char *send_context_err_status_string(char *buf, int buf_len, u64 flags)
5922{
5923 return flag_string(buf, buf_len, flags,
Jubin John17fb4f22016-02-14 20:21:52 -08005924 sc_err_status_flags,
5925 ARRAY_SIZE(sc_err_status_flags));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005926}
5927
5928/*
5929 * Send context error interrupt. Source (hw_context) is < 160.
5930 *
5931 * All send context errors cause the send context to halt. The normal
5932 * clear-down mechanism cannot be used because we cannot clear the
5933 * error bits until several other long-running items are done first.
5934 * This is OK because with the context halted, nothing else is going
5935 * to happen on it anyway.
5936 */
5937static void is_sendctxt_err_int(struct hfi1_devdata *dd,
5938 unsigned int hw_context)
5939{
5940 struct send_context_info *sci;
5941 struct send_context *sc;
5942 char flags[96];
5943 u64 status;
5944 u32 sw_index;
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005945 int i = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005946
5947 sw_index = dd->hw_to_sw[hw_context];
5948 if (sw_index >= dd->num_send_contexts) {
5949 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08005950 "out of range sw index %u for send context %u\n",
5951 sw_index, hw_context);
Mike Marciniszyn77241052015-07-30 15:17:43 -04005952 return;
5953 }
5954 sci = &dd->send_contexts[sw_index];
5955 sc = sci->sc;
5956 if (!sc) {
5957 dd_dev_err(dd, "%s: context %u(%u): no sc?\n", __func__,
Jubin John17fb4f22016-02-14 20:21:52 -08005958 sw_index, hw_context);
Mike Marciniszyn77241052015-07-30 15:17:43 -04005959 return;
5960 }
5961
5962 /* tell the software that a halt has begun */
5963 sc_stop(sc, SCF_HALTED);
5964
5965 status = read_kctxt_csr(dd, hw_context, SEND_CTXT_ERR_STATUS);
5966
5967 dd_dev_info(dd, "Send Context %u(%u) Error: %s\n", sw_index, hw_context,
Jubin John17fb4f22016-02-14 20:21:52 -08005968 send_context_err_status_string(flags, sizeof(flags),
5969 status));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005970
5971 if (status & SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK)
Mike Marciniszyn69a00b82016-02-03 14:31:49 -08005972 handle_send_egress_err_info(dd, sc_to_vl(dd, sw_index));
Mike Marciniszyn77241052015-07-30 15:17:43 -04005973
5974 /*
5975 * Automatically restart halted kernel contexts out of interrupt
5976 * context. User contexts must ask the driver to restart the context.
5977 */
5978 if (sc->type != SC_USER)
5979 queue_work(dd->pport->hfi1_wq, &sc->halt_work);
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005980
5981 /*
5982 * Update the counters for the corresponding status bits.
5983 * Note that these particular counters are aggregated over all
5984 * 160 contexts.
5985 */
5986 for (i = 0; i < NUM_SEND_CTXT_ERR_STATUS_COUNTERS; i++) {
5987 if (status & (1ull << i))
5988 incr_cntr64(&dd->sw_ctxt_err_status_cnt[i]);
5989 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04005990}
5991
5992static void handle_sdma_eng_err(struct hfi1_devdata *dd,
5993 unsigned int source, u64 status)
5994{
5995 struct sdma_engine *sde;
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05005996 int i = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04005997
5998 sde = &dd->per_sdma[source];
5999#ifdef CONFIG_SDMA_VERBOSITY
6000 dd_dev_err(sde->dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
6001 slashstrip(__FILE__), __LINE__, __func__);
6002 dd_dev_err(sde->dd, "CONFIG SDMA(%u) source: %u status 0x%llx\n",
6003 sde->this_idx, source, (unsigned long long)status);
6004#endif
Vennila Megavannana699c6c2016-01-11 18:30:56 -05006005 sde->err_cnt++;
Mike Marciniszyn77241052015-07-30 15:17:43 -04006006 sdma_engine_error(sde, status);
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05006007
6008 /*
6009 * Update the counters for the corresponding status bits.
6010 * Note that these particular counters are aggregated over
6011 * all 16 DMA engines.
6012 */
6013 for (i = 0; i < NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS; i++) {
6014 if (status & (1ull << i))
6015 incr_cntr64(&dd->sw_send_dma_eng_err_status_cnt[i]);
6016 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04006017}
6018
6019/*
6020 * CCE block SDMA error interrupt. Source is < 16.
6021 */
6022static void is_sdma_eng_err_int(struct hfi1_devdata *dd, unsigned int source)
6023{
6024#ifdef CONFIG_SDMA_VERBOSITY
6025 struct sdma_engine *sde = &dd->per_sdma[source];
6026
6027 dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
6028 slashstrip(__FILE__), __LINE__, __func__);
6029 dd_dev_err(dd, "CONFIG SDMA(%u) source: %u\n", sde->this_idx,
6030 source);
6031 sdma_dumpstate(sde);
6032#endif
6033 interrupt_clear_down(dd, source, &sdma_eng_err);
6034}
6035
6036/*
6037 * CCE block "various" interrupt. Source is < 8.
6038 */
6039static void is_various_int(struct hfi1_devdata *dd, unsigned int source)
6040{
6041 const struct err_reg_info *eri = &various_err[source];
6042
6043 /*
6044 * TCritInt cannot go through interrupt_clear_down()
6045 * because it is not a second tier interrupt. The handler
6046 * should be called directly.
6047 */
6048 if (source == TCRIT_INT_SOURCE)
6049 handle_temp_err(dd);
6050 else if (eri->handler)
6051 interrupt_clear_down(dd, 0, eri);
6052 else
6053 dd_dev_info(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08006054 "%s: Unimplemented/reserved interrupt %d\n",
6055 __func__, source);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006056}
6057
6058static void handle_qsfp_int(struct hfi1_devdata *dd, u32 src_ctx, u64 reg)
6059{
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08006060 /* src_ctx is always zero */
Mike Marciniszyn77241052015-07-30 15:17:43 -04006061 struct hfi1_pportdata *ppd = dd->pport;
6062 unsigned long flags;
6063 u64 qsfp_int_mgmt = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
6064
6065 if (reg & QSFP_HFI0_MODPRST_N) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04006066 if (!qsfp_mod_present(ppd)) {
Easwar Hariharane8aa2842016-02-18 11:12:16 -08006067 dd_dev_info(dd, "%s: QSFP module removed\n",
6068 __func__);
6069
Mike Marciniszyn77241052015-07-30 15:17:43 -04006070 ppd->driver_link_ready = 0;
6071 /*
6072 * Cable removed, reset all our information about the
6073 * cache and cable capabilities
6074 */
6075
6076 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
6077 /*
6078 * We don't set cache_refresh_required here as we expect
6079 * an interrupt when a cable is inserted
6080 */
6081 ppd->qsfp_info.cache_valid = 0;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08006082 ppd->qsfp_info.reset_needed = 0;
6083 ppd->qsfp_info.limiting_active = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04006084 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
Jubin John17fb4f22016-02-14 20:21:52 -08006085 flags);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08006086 /* Invert the ModPresent pin now to detect plug-in */
6087 write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
6088 ASIC_QSFP1_INVERT, qsfp_int_mgmt);
Bryan Morgana9c05e32016-02-03 14:30:49 -08006089
6090 if ((ppd->offline_disabled_reason >
6091 HFI1_ODR_MASK(
Easwar Hariharane1bf0d52016-02-03 14:36:58 -08006092 OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED)) ||
Bryan Morgana9c05e32016-02-03 14:30:49 -08006093 (ppd->offline_disabled_reason ==
6094 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE)))
6095 ppd->offline_disabled_reason =
6096 HFI1_ODR_MASK(
Easwar Hariharane1bf0d52016-02-03 14:36:58 -08006097 OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED);
Bryan Morgana9c05e32016-02-03 14:30:49 -08006098
Mike Marciniszyn77241052015-07-30 15:17:43 -04006099 if (ppd->host_link_state == HLS_DN_POLL) {
6100 /*
6101 * The link is still in POLL. This means
6102 * that the normal link down processing
6103 * will not happen. We have to do it here
6104 * before turning the DC off.
6105 */
Sebastian Sanchez71d47002017-07-29 08:43:49 -07006106 queue_work(ppd->link_wq, &ppd->link_down_work);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006107 }
6108 } else {
Easwar Hariharane8aa2842016-02-18 11:12:16 -08006109 dd_dev_info(dd, "%s: QSFP module inserted\n",
6110 __func__);
6111
Mike Marciniszyn77241052015-07-30 15:17:43 -04006112 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
6113 ppd->qsfp_info.cache_valid = 0;
6114 ppd->qsfp_info.cache_refresh_required = 1;
6115 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
Jubin John17fb4f22016-02-14 20:21:52 -08006116 flags);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006117
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08006118 /*
6119 * Stop inversion of ModPresent pin to detect
6120 * removal of the cable
6121 */
Mike Marciniszyn77241052015-07-30 15:17:43 -04006122 qsfp_int_mgmt &= ~(u64)QSFP_HFI0_MODPRST_N;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08006123 write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_INVERT :
6124 ASIC_QSFP1_INVERT, qsfp_int_mgmt);
6125
6126 ppd->offline_disabled_reason =
6127 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006128 }
6129 }
6130
6131 if (reg & QSFP_HFI0_INT_N) {
Easwar Hariharane8aa2842016-02-18 11:12:16 -08006132 dd_dev_info(dd, "%s: Interrupt received from QSFP module\n",
Jubin John17fb4f22016-02-14 20:21:52 -08006133 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006134 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
6135 ppd->qsfp_info.check_interrupt_flags = 1;
Mike Marciniszyn77241052015-07-30 15:17:43 -04006136 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, flags);
6137 }
6138
6139 /* Schedule the QSFP work only if there is a cable attached. */
6140 if (qsfp_mod_present(ppd))
Sebastian Sanchez71d47002017-07-29 08:43:49 -07006141 queue_work(ppd->link_wq, &ppd->qsfp_info.qsfp_work);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006142}
6143
6144static int request_host_lcb_access(struct hfi1_devdata *dd)
6145{
6146 int ret;
6147
6148 ret = do_8051_command(dd, HCMD_MISC,
Jubin John17fb4f22016-02-14 20:21:52 -08006149 (u64)HCMD_MISC_REQUEST_LCB_ACCESS <<
6150 LOAD_DATA_FIELD_ID_SHIFT, NULL);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006151 if (ret != HCMD_SUCCESS) {
6152 dd_dev_err(dd, "%s: command failed with error %d\n",
Jubin John17fb4f22016-02-14 20:21:52 -08006153 __func__, ret);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006154 }
6155 return ret == HCMD_SUCCESS ? 0 : -EBUSY;
6156}
6157
6158static int request_8051_lcb_access(struct hfi1_devdata *dd)
6159{
6160 int ret;
6161
6162 ret = do_8051_command(dd, HCMD_MISC,
Jubin John17fb4f22016-02-14 20:21:52 -08006163 (u64)HCMD_MISC_GRANT_LCB_ACCESS <<
6164 LOAD_DATA_FIELD_ID_SHIFT, NULL);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006165 if (ret != HCMD_SUCCESS) {
6166 dd_dev_err(dd, "%s: command failed with error %d\n",
Jubin John17fb4f22016-02-14 20:21:52 -08006167 __func__, ret);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006168 }
6169 return ret == HCMD_SUCCESS ? 0 : -EBUSY;
6170}
6171
6172/*
6173 * Set the LCB selector - allow host access. The DCC selector always
6174 * points to the host.
6175 */
6176static inline void set_host_lcb_access(struct hfi1_devdata *dd)
6177{
6178 write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
Jubin John17fb4f22016-02-14 20:21:52 -08006179 DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK |
6180 DC_DC8051_CFG_CSR_ACCESS_SEL_LCB_SMASK);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006181}
6182
6183/*
6184 * Clear the LCB selector - allow 8051 access. The DCC selector always
6185 * points to the host.
6186 */
6187static inline void set_8051_lcb_access(struct hfi1_devdata *dd)
6188{
6189 write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
Jubin John17fb4f22016-02-14 20:21:52 -08006190 DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006191}
6192
6193/*
6194 * Acquire LCB access from the 8051. If the host already has access,
6195 * just increment a counter. Otherwise, inform the 8051 that the
6196 * host is taking access.
6197 *
6198 * Returns:
6199 * 0 on success
6200 * -EBUSY if the 8051 has control and cannot be disturbed
6201 * -errno if unable to acquire access from the 8051
6202 */
6203int acquire_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
6204{
6205 struct hfi1_pportdata *ppd = dd->pport;
6206 int ret = 0;
6207
6208 /*
6209 * Use the host link state lock so the operation of this routine
6210 * { link state check, selector change, count increment } can occur
6211 * as a unit against a link state change. Otherwise there is a
6212 * race between the state change and the count increment.
6213 */
6214 if (sleep_ok) {
6215 mutex_lock(&ppd->hls_lock);
6216 } else {
Dan Carpenter951842b2015-09-16 09:22:51 +03006217 while (!mutex_trylock(&ppd->hls_lock))
Mike Marciniszyn77241052015-07-30 15:17:43 -04006218 udelay(1);
6219 }
6220
6221 /* this access is valid only when the link is up */
Easwar Hariharan0c7f77a2016-05-12 10:22:33 -07006222 if (ppd->host_link_state & HLS_DOWN) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04006223 dd_dev_info(dd, "%s: link state %s not up\n",
Jubin John17fb4f22016-02-14 20:21:52 -08006224 __func__, link_state_name(ppd->host_link_state));
Mike Marciniszyn77241052015-07-30 15:17:43 -04006225 ret = -EBUSY;
6226 goto done;
6227 }
6228
6229 if (dd->lcb_access_count == 0) {
6230 ret = request_host_lcb_access(dd);
6231 if (ret) {
6232 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08006233 "%s: unable to acquire LCB access, err %d\n",
6234 __func__, ret);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006235 goto done;
6236 }
6237 set_host_lcb_access(dd);
6238 }
6239 dd->lcb_access_count++;
6240done:
6241 mutex_unlock(&ppd->hls_lock);
6242 return ret;
6243}
6244
6245/*
6246 * Release LCB access by decrementing the use count. If the count is moving
6247 * from 1 to 0, inform 8051 that it has control back.
6248 *
6249 * Returns:
6250 * 0 on success
6251 * -errno if unable to release access to the 8051
6252 */
6253int release_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
6254{
6255 int ret = 0;
6256
6257 /*
6258 * Use the host link state lock because the acquire needed it.
6259 * Here, we only need to keep { selector change, count decrement }
6260 * as a unit.
6261 */
6262 if (sleep_ok) {
6263 mutex_lock(&dd->pport->hls_lock);
6264 } else {
Dan Carpenter951842b2015-09-16 09:22:51 +03006265 while (!mutex_trylock(&dd->pport->hls_lock))
Mike Marciniszyn77241052015-07-30 15:17:43 -04006266 udelay(1);
6267 }
6268
6269 if (dd->lcb_access_count == 0) {
6270 dd_dev_err(dd, "%s: LCB access count is zero. Skipping.\n",
Jubin John17fb4f22016-02-14 20:21:52 -08006271 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006272 goto done;
6273 }
6274
6275 if (dd->lcb_access_count == 1) {
6276 set_8051_lcb_access(dd);
6277 ret = request_8051_lcb_access(dd);
6278 if (ret) {
6279 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08006280 "%s: unable to release LCB access, err %d\n",
6281 __func__, ret);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006282 /* restore host access if the grant didn't work */
6283 set_host_lcb_access(dd);
6284 goto done;
6285 }
6286 }
6287 dd->lcb_access_count--;
6288done:
6289 mutex_unlock(&dd->pport->hls_lock);
6290 return ret;
6291}
6292
6293/*
6294 * Initialize LCB access variables and state. Called during driver load,
6295 * after most of the initialization is finished.
6296 *
6297 * The DC default is LCB access on for the host. The driver defaults to
6298 * leaving access to the 8051. Assign access now - this constrains the call
6299 * to this routine to be after all LCB set-up is done. In particular, after
6300 * hf1_init_dd() -> set_up_interrupts() -> clear_all_interrupts()
6301 */
6302static void init_lcb_access(struct hfi1_devdata *dd)
6303{
6304 dd->lcb_access_count = 0;
6305}
6306
6307/*
6308 * Write a response back to a 8051 request.
6309 */
6310static void hreq_response(struct hfi1_devdata *dd, u8 return_code, u16 rsp_data)
6311{
6312 write_csr(dd, DC_DC8051_CFG_EXT_DEV_0,
Jubin John17fb4f22016-02-14 20:21:52 -08006313 DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK |
6314 (u64)return_code <<
6315 DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT |
6316 (u64)rsp_data << DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006317}
6318
6319/*
Easwar Hariharancbac3862016-02-03 14:31:31 -08006320 * Handle host requests from the 8051.
Mike Marciniszyn77241052015-07-30 15:17:43 -04006321 */
Easwar Hariharan145dd2b2016-04-12 11:25:31 -07006322static void handle_8051_request(struct hfi1_pportdata *ppd)
Mike Marciniszyn77241052015-07-30 15:17:43 -04006323{
Easwar Hariharancbac3862016-02-03 14:31:31 -08006324 struct hfi1_devdata *dd = ppd->dd;
Mike Marciniszyn77241052015-07-30 15:17:43 -04006325 u64 reg;
Easwar Hariharancbac3862016-02-03 14:31:31 -08006326 u16 data = 0;
Easwar Hariharan145dd2b2016-04-12 11:25:31 -07006327 u8 type;
Mike Marciniszyn77241052015-07-30 15:17:43 -04006328
6329 reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_1);
6330 if ((reg & DC_DC8051_CFG_EXT_DEV_1_REQ_NEW_SMASK) == 0)
6331 return; /* no request */
6332
6333 /* zero out COMPLETED so the response is seen */
6334 write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, 0);
6335
6336 /* extract request details */
6337 type = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_SHIFT)
6338 & DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_MASK;
6339 data = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT)
6340 & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_MASK;
6341
6342 switch (type) {
6343 case HREQ_LOAD_CONFIG:
6344 case HREQ_SAVE_CONFIG:
6345 case HREQ_READ_CONFIG:
6346 case HREQ_SET_TX_EQ_ABS:
6347 case HREQ_SET_TX_EQ_REL:
Easwar Hariharan145dd2b2016-04-12 11:25:31 -07006348 case HREQ_ENABLE:
Mike Marciniszyn77241052015-07-30 15:17:43 -04006349 dd_dev_info(dd, "8051 request: request 0x%x not supported\n",
Jubin John17fb4f22016-02-14 20:21:52 -08006350 type);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006351 hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
6352 break;
Mike Marciniszyn77241052015-07-30 15:17:43 -04006353 case HREQ_CONFIG_DONE:
6354 hreq_response(dd, HREQ_SUCCESS, 0);
6355 break;
6356
6357 case HREQ_INTERFACE_TEST:
6358 hreq_response(dd, HREQ_SUCCESS, data);
6359 break;
Mike Marciniszyn77241052015-07-30 15:17:43 -04006360 default:
6361 dd_dev_err(dd, "8051 request: unknown request 0x%x\n", type);
6362 hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
6363 break;
6364 }
6365}
6366
Byczkowski, Jakubb3e6b4b2017-05-12 09:01:37 -07006367/*
6368 * Set up allocation unit vaulue.
6369 */
6370void set_up_vau(struct hfi1_devdata *dd, u8 vau)
Mike Marciniszyn77241052015-07-30 15:17:43 -04006371{
Byczkowski, Jakubb3e6b4b2017-05-12 09:01:37 -07006372 u64 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
6373
6374 /* do not modify other values in the register */
6375 reg &= ~SEND_CM_GLOBAL_CREDIT_AU_SMASK;
6376 reg |= (u64)vau << SEND_CM_GLOBAL_CREDIT_AU_SHIFT;
6377 write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006378}
6379
6380/*
6381 * Set up initial VL15 credits of the remote. Assumes the rest of
Byczkowski, Jakubb3e6b4b2017-05-12 09:01:37 -07006382 * the CM credit registers are zero from a previous global or credit reset.
6383 * Shared limit for VL15 will always be 0.
Mike Marciniszyn77241052015-07-30 15:17:43 -04006384 */
Byczkowski, Jakubb3e6b4b2017-05-12 09:01:37 -07006385void set_up_vl15(struct hfi1_devdata *dd, u16 vl15buf)
Mike Marciniszyn77241052015-07-30 15:17:43 -04006386{
Byczkowski, Jakubb3e6b4b2017-05-12 09:01:37 -07006387 u64 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
6388
6389 /* set initial values for total and shared credit limit */
6390 reg &= ~(SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SMASK |
6391 SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SMASK);
6392
6393 /*
6394 * Set total limit to be equal to VL15 credits.
6395 * Leave shared limit at 0.
6396 */
6397 reg |= (u64)vl15buf << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT;
6398 write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006399
Dennis Dalessandroeacc8302016-10-17 04:19:52 -07006400 write_csr(dd, SEND_CM_CREDIT_VL15, (u64)vl15buf
6401 << SEND_CM_CREDIT_VL15_DEDICATED_LIMIT_VL_SHIFT);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006402}
6403
6404/*
6405 * Zero all credit details from the previous connection and
6406 * reset the CM manager's internal counters.
6407 */
6408void reset_link_credits(struct hfi1_devdata *dd)
6409{
6410 int i;
6411
6412 /* remove all previous VL credit limits */
6413 for (i = 0; i < TXE_NUM_DATA_VL; i++)
Jubin John8638b772016-02-14 20:19:24 -08006414 write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006415 write_csr(dd, SEND_CM_CREDIT_VL15, 0);
Byczkowski, Jakubb3e6b4b2017-05-12 09:01:37 -07006416 write_csr(dd, SEND_CM_GLOBAL_CREDIT, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006417 /* reset the CM block */
6418 pio_send_control(dd, PSC_CM_RESET);
Byczkowski, Jakubb3e6b4b2017-05-12 09:01:37 -07006419 /* reset cached value */
6420 dd->vl15buf_cached = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04006421}
6422
6423/* convert a vCU to a CU */
6424static u32 vcu_to_cu(u8 vcu)
6425{
6426 return 1 << vcu;
6427}
6428
6429/* convert a CU to a vCU */
6430static u8 cu_to_vcu(u32 cu)
6431{
6432 return ilog2(cu);
6433}
6434
6435/* convert a vAU to an AU */
6436static u32 vau_to_au(u8 vau)
6437{
6438 return 8 * (1 << vau);
6439}
6440
6441static void set_linkup_defaults(struct hfi1_pportdata *ppd)
6442{
6443 ppd->sm_trap_qp = 0x0;
6444 ppd->sa_qp = 0x1;
6445}
6446
6447/*
6448 * Graceful LCB shutdown. This leaves the LCB FIFOs in reset.
6449 */
6450static void lcb_shutdown(struct hfi1_devdata *dd, int abort)
6451{
6452 u64 reg;
6453
6454 /* clear lcb run: LCB_CFG_RUN.EN = 0 */
6455 write_csr(dd, DC_LCB_CFG_RUN, 0);
6456 /* set tx fifo reset: LCB_CFG_TX_FIFOS_RESET.VAL = 1 */
6457 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET,
Jubin John17fb4f22016-02-14 20:21:52 -08006458 1ull << DC_LCB_CFG_TX_FIFOS_RESET_VAL_SHIFT);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006459 /* set dcc reset csr: DCC_CFG_RESET.{reset_lcb,reset_rx_fpe} = 1 */
6460 dd->lcb_err_en = read_csr(dd, DC_LCB_ERR_EN);
6461 reg = read_csr(dd, DCC_CFG_RESET);
Jubin John17fb4f22016-02-14 20:21:52 -08006462 write_csr(dd, DCC_CFG_RESET, reg |
6463 (1ull << DCC_CFG_RESET_RESET_LCB_SHIFT) |
6464 (1ull << DCC_CFG_RESET_RESET_RX_FPE_SHIFT));
Jubin John50e5dcb2016-02-14 20:19:41 -08006465 (void)read_csr(dd, DCC_CFG_RESET); /* make sure the write completed */
Mike Marciniszyn77241052015-07-30 15:17:43 -04006466 if (!abort) {
6467 udelay(1); /* must hold for the longer of 16cclks or 20ns */
6468 write_csr(dd, DCC_CFG_RESET, reg);
6469 write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
6470 }
6471}
6472
6473/*
6474 * This routine should be called after the link has been transitioned to
6475 * OFFLINE (OFFLINE state has the side effect of putting the SerDes into
6476 * reset).
6477 *
6478 * The expectation is that the caller of this routine would have taken
6479 * care of properly transitioning the link into the correct state.
Tadeusz Struk22546b72017-04-28 10:40:02 -07006480 * NOTE: the caller needs to acquire the dd->dc8051_lock lock
6481 * before calling this function.
Mike Marciniszyn77241052015-07-30 15:17:43 -04006482 */
Tadeusz Struk22546b72017-04-28 10:40:02 -07006483static void _dc_shutdown(struct hfi1_devdata *dd)
Mike Marciniszyn77241052015-07-30 15:17:43 -04006484{
Tadeusz Struk22546b72017-04-28 10:40:02 -07006485 lockdep_assert_held(&dd->dc8051_lock);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006486
Tadeusz Struk22546b72017-04-28 10:40:02 -07006487 if (dd->dc_shutdown)
Mike Marciniszyn77241052015-07-30 15:17:43 -04006488 return;
Tadeusz Struk22546b72017-04-28 10:40:02 -07006489
Mike Marciniszyn77241052015-07-30 15:17:43 -04006490 dd->dc_shutdown = 1;
Mike Marciniszyn77241052015-07-30 15:17:43 -04006491 /* Shutdown the LCB */
6492 lcb_shutdown(dd, 1);
Jubin John4d114fd2016-02-14 20:21:43 -08006493 /*
6494 * Going to OFFLINE would have causes the 8051 to put the
Mike Marciniszyn77241052015-07-30 15:17:43 -04006495 * SerDes into reset already. Just need to shut down the 8051,
Jubin John4d114fd2016-02-14 20:21:43 -08006496 * itself.
6497 */
Mike Marciniszyn77241052015-07-30 15:17:43 -04006498 write_csr(dd, DC_DC8051_CFG_RST, 0x1);
6499}
6500
Tadeusz Struk22546b72017-04-28 10:40:02 -07006501static void dc_shutdown(struct hfi1_devdata *dd)
6502{
6503 mutex_lock(&dd->dc8051_lock);
6504 _dc_shutdown(dd);
6505 mutex_unlock(&dd->dc8051_lock);
6506}
6507
Jubin John4d114fd2016-02-14 20:21:43 -08006508/*
6509 * Calling this after the DC has been brought out of reset should not
6510 * do any damage.
Tadeusz Struk22546b72017-04-28 10:40:02 -07006511 * NOTE: the caller needs to acquire the dd->dc8051_lock lock
6512 * before calling this function.
Jubin John4d114fd2016-02-14 20:21:43 -08006513 */
Tadeusz Struk22546b72017-04-28 10:40:02 -07006514static void _dc_start(struct hfi1_devdata *dd)
Mike Marciniszyn77241052015-07-30 15:17:43 -04006515{
Tadeusz Struk22546b72017-04-28 10:40:02 -07006516 lockdep_assert_held(&dd->dc8051_lock);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006517
Mike Marciniszyn77241052015-07-30 15:17:43 -04006518 if (!dd->dc_shutdown)
Tadeusz Struk22546b72017-04-28 10:40:02 -07006519 return;
6520
Sebastian Sanchez9be6a5d2017-10-02 11:04:26 -07006521 /*
6522 * Take the 8051 out of reset, wait until 8051 is ready, and set host
6523 * version bit.
6524 */
6525 release_and_wait_ready_8051_firmware(dd);
Tadeusz Struk22546b72017-04-28 10:40:02 -07006526
Mike Marciniszyn77241052015-07-30 15:17:43 -04006527 /* Take away reset for LCB and RX FPE (set in lcb_shutdown). */
6528 write_csr(dd, DCC_CFG_RESET, 0x10);
6529 /* lcb_shutdown() with abort=1 does not restore these */
6530 write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006531 dd->dc_shutdown = 0;
Tadeusz Struk22546b72017-04-28 10:40:02 -07006532}
6533
6534static void dc_start(struct hfi1_devdata *dd)
6535{
6536 mutex_lock(&dd->dc8051_lock);
6537 _dc_start(dd);
6538 mutex_unlock(&dd->dc8051_lock);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006539}
6540
6541/*
6542 * These LCB adjustments are for the Aurora SerDes core in the FPGA.
6543 */
6544static void adjust_lcb_for_fpga_serdes(struct hfi1_devdata *dd)
6545{
6546 u64 rx_radr, tx_radr;
6547 u32 version;
6548
6549 if (dd->icode != ICODE_FPGA_EMULATION)
6550 return;
6551
6552 /*
6553 * These LCB defaults on emulator _s are good, nothing to do here:
6554 * LCB_CFG_TX_FIFOS_RADR
6555 * LCB_CFG_RX_FIFOS_RADR
6556 * LCB_CFG_LN_DCLK
6557 * LCB_CFG_IGNORE_LOST_RCLK
6558 */
6559 if (is_emulator_s(dd))
6560 return;
6561 /* else this is _p */
6562
6563 version = emulator_rev(dd);
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05006564 if (!is_ax(dd))
Mike Marciniszyn77241052015-07-30 15:17:43 -04006565 version = 0x2d; /* all B0 use 0x2d or higher settings */
6566
6567 if (version <= 0x12) {
6568 /* release 0x12 and below */
6569
6570 /*
6571 * LCB_CFG_RX_FIFOS_RADR.RST_VAL = 0x9
6572 * LCB_CFG_RX_FIFOS_RADR.OK_TO_JUMP_VAL = 0x9
6573 * LCB_CFG_RX_FIFOS_RADR.DO_NOT_JUMP_VAL = 0xa
6574 */
6575 rx_radr =
6576 0xaull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
6577 | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
6578 | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
6579 /*
6580 * LCB_CFG_TX_FIFOS_RADR.ON_REINIT = 0 (default)
6581 * LCB_CFG_TX_FIFOS_RADR.RST_VAL = 6
6582 */
6583 tx_radr = 6ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
6584 } else if (version <= 0x18) {
6585 /* release 0x13 up to 0x18 */
6586 /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
6587 rx_radr =
6588 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
6589 | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
6590 | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
6591 tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
6592 } else if (version == 0x19) {
6593 /* release 0x19 */
6594 /* LCB_CFG_RX_FIFOS_RADR = 0xa99 */
6595 rx_radr =
6596 0xAull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
6597 | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
6598 | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
6599 tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
6600 } else if (version == 0x1a) {
6601 /* release 0x1a */
6602 /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
6603 rx_radr =
6604 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
6605 | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
6606 | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
6607 tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
6608 write_csr(dd, DC_LCB_CFG_LN_DCLK, 1ull);
6609 } else {
6610 /* release 0x1b and higher */
6611 /* LCB_CFG_RX_FIFOS_RADR = 0x877 */
6612 rx_radr =
6613 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
6614 | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
6615 | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
6616 tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
6617 }
6618
6619 write_csr(dd, DC_LCB_CFG_RX_FIFOS_RADR, rx_radr);
6620 /* LCB_CFG_IGNORE_LOST_RCLK.EN = 1 */
6621 write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK,
Jubin John17fb4f22016-02-14 20:21:52 -08006622 DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006623 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RADR, tx_radr);
6624}
6625
6626/*
6627 * Handle a SMA idle message
6628 *
6629 * This is a work-queue function outside of the interrupt.
6630 */
6631void handle_sma_message(struct work_struct *work)
6632{
6633 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
6634 sma_message_work);
6635 struct hfi1_devdata *dd = ppd->dd;
6636 u64 msg;
6637 int ret;
6638
Jubin John4d114fd2016-02-14 20:21:43 -08006639 /*
6640 * msg is bytes 1-4 of the 40-bit idle message - the command code
6641 * is stripped off
6642 */
Mike Marciniszyn77241052015-07-30 15:17:43 -04006643 ret = read_idle_sma(dd, &msg);
6644 if (ret)
6645 return;
6646 dd_dev_info(dd, "%s: SMA message 0x%llx\n", __func__, msg);
6647 /*
6648 * React to the SMA message. Byte[1] (0 for us) is the command.
6649 */
6650 switch (msg & 0xff) {
6651 case SMA_IDLE_ARM:
6652 /*
6653 * See OPAv1 table 9-14 - HFI and External Switch Ports Key
6654 * State Transitions
6655 *
6656 * Only expected in INIT or ARMED, discard otherwise.
6657 */
6658 if (ppd->host_link_state & (HLS_UP_INIT | HLS_UP_ARMED))
6659 ppd->neighbor_normal = 1;
6660 break;
6661 case SMA_IDLE_ACTIVE:
6662 /*
6663 * See OPAv1 table 9-14 - HFI and External Switch Ports Key
6664 * State Transitions
6665 *
6666 * Can activate the node. Discard otherwise.
6667 */
Jubin Johnd0d236e2016-02-14 20:20:15 -08006668 if (ppd->host_link_state == HLS_UP_ARMED &&
6669 ppd->is_active_optimize_enabled) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04006670 ppd->neighbor_normal = 1;
6671 ret = set_link_state(ppd, HLS_UP_ACTIVE);
6672 if (ret)
6673 dd_dev_err(
6674 dd,
6675 "%s: received Active SMA idle message, couldn't set link to Active\n",
6676 __func__);
6677 }
6678 break;
6679 default:
6680 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08006681 "%s: received unexpected SMA idle message 0x%llx\n",
6682 __func__, msg);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006683 break;
6684 }
6685}
6686
6687static void adjust_rcvctrl(struct hfi1_devdata *dd, u64 add, u64 clear)
6688{
6689 u64 rcvctrl;
6690 unsigned long flags;
6691
6692 spin_lock_irqsave(&dd->rcvctrl_lock, flags);
6693 rcvctrl = read_csr(dd, RCV_CTRL);
6694 rcvctrl |= add;
6695 rcvctrl &= ~clear;
6696 write_csr(dd, RCV_CTRL, rcvctrl);
6697 spin_unlock_irqrestore(&dd->rcvctrl_lock, flags);
6698}
6699
6700static inline void add_rcvctrl(struct hfi1_devdata *dd, u64 add)
6701{
6702 adjust_rcvctrl(dd, add, 0);
6703}
6704
6705static inline void clear_rcvctrl(struct hfi1_devdata *dd, u64 clear)
6706{
6707 adjust_rcvctrl(dd, 0, clear);
6708}
6709
6710/*
6711 * Called from all interrupt handlers to start handling an SPC freeze.
6712 */
6713void start_freeze_handling(struct hfi1_pportdata *ppd, int flags)
6714{
6715 struct hfi1_devdata *dd = ppd->dd;
6716 struct send_context *sc;
6717 int i;
6718
6719 if (flags & FREEZE_SELF)
6720 write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
6721
6722 /* enter frozen mode */
6723 dd->flags |= HFI1_FROZEN;
6724
6725 /* notify all SDMA engines that they are going into a freeze */
6726 sdma_freeze_notify(dd, !!(flags & FREEZE_LINK_DOWN));
6727
6728 /* do halt pre-handling on all enabled send contexts */
6729 for (i = 0; i < dd->num_send_contexts; i++) {
6730 sc = dd->send_contexts[i].sc;
6731 if (sc && (sc->flags & SCF_ENABLED))
6732 sc_stop(sc, SCF_FROZEN | SCF_HALTED);
6733 }
6734
6735 /* Send context are frozen. Notify user space */
6736 hfi1_set_uevent_bits(ppd, _HFI1_EVENT_FROZEN_BIT);
6737
6738 if (flags & FREEZE_ABORT) {
6739 dd_dev_err(dd,
6740 "Aborted freeze recovery. Please REBOOT system\n");
6741 return;
6742 }
6743 /* queue non-interrupt handler */
6744 queue_work(ppd->hfi1_wq, &ppd->freeze_work);
6745}
6746
6747/*
6748 * Wait until all 4 sub-blocks indicate that they have frozen or unfrozen,
6749 * depending on the "freeze" parameter.
6750 *
6751 * No need to return an error if it times out, our only option
6752 * is to proceed anyway.
6753 */
6754static void wait_for_freeze_status(struct hfi1_devdata *dd, int freeze)
6755{
6756 unsigned long timeout;
6757 u64 reg;
6758
6759 timeout = jiffies + msecs_to_jiffies(FREEZE_STATUS_TIMEOUT);
6760 while (1) {
6761 reg = read_csr(dd, CCE_STATUS);
6762 if (freeze) {
6763 /* waiting until all indicators are set */
6764 if ((reg & ALL_FROZE) == ALL_FROZE)
6765 return; /* all done */
6766 } else {
6767 /* waiting until all indicators are clear */
6768 if ((reg & ALL_FROZE) == 0)
6769 return; /* all done */
6770 }
6771
6772 if (time_after(jiffies, timeout)) {
6773 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08006774 "Time out waiting for SPC %sfreeze, bits 0x%llx, expecting 0x%llx, continuing",
6775 freeze ? "" : "un", reg & ALL_FROZE,
6776 freeze ? ALL_FROZE : 0ull);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006777 return;
6778 }
6779 usleep_range(80, 120);
6780 }
6781}
6782
6783/*
6784 * Do all freeze handling for the RXE block.
6785 */
6786static void rxe_freeze(struct hfi1_devdata *dd)
6787{
6788 int i;
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07006789 struct hfi1_ctxtdata *rcd;
Mike Marciniszyn77241052015-07-30 15:17:43 -04006790
6791 /* disable port */
6792 clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
6793
6794 /* disable all receive contexts */
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07006795 for (i = 0; i < dd->num_rcv_contexts; i++) {
6796 rcd = hfi1_rcd_get_by_index(dd, i);
6797 hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_DIS, rcd);
6798 hfi1_rcd_put(rcd);
6799 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04006800}
6801
6802/*
6803 * Unfreeze handling for the RXE block - kernel contexts only.
6804 * This will also enable the port. User contexts will do unfreeze
6805 * handling on a per-context basis as they call into the driver.
6806 *
6807 */
6808static void rxe_kernel_unfreeze(struct hfi1_devdata *dd)
6809{
Mitko Haralanov566c1572016-02-03 14:32:49 -08006810 u32 rcvmask;
Michael J. Ruhle6f76222017-07-24 07:45:55 -07006811 u16 i;
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07006812 struct hfi1_ctxtdata *rcd;
Mike Marciniszyn77241052015-07-30 15:17:43 -04006813
6814 /* enable all kernel contexts */
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07006815 for (i = 0; i < dd->num_rcv_contexts; i++) {
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07006816 rcd = hfi1_rcd_get_by_index(dd, i);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07006817
6818 /* Ensure all non-user contexts(including vnic) are enabled */
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07006819 if (!rcd || !rcd->sc || (rcd->sc->type == SC_USER)) {
6820 hfi1_rcd_put(rcd);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07006821 continue;
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07006822 }
Mitko Haralanov566c1572016-02-03 14:32:49 -08006823 rcvmask = HFI1_RCVCTRL_CTXT_ENB;
6824 /* HFI1_RCVCTRL_TAILUPD_[ENB|DIS] needs to be set explicitly */
Michael J. Ruhl22505632017-07-24 07:46:06 -07006825 rcvmask |= HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL) ?
Mitko Haralanov566c1572016-02-03 14:32:49 -08006826 HFI1_RCVCTRL_TAILUPD_ENB : HFI1_RCVCTRL_TAILUPD_DIS;
Michael J. Ruhl22505632017-07-24 07:46:06 -07006827 hfi1_rcvctrl(dd, rcvmask, rcd);
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07006828 hfi1_rcd_put(rcd);
Mitko Haralanov566c1572016-02-03 14:32:49 -08006829 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04006830
6831 /* enable port */
6832 add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
6833}
6834
6835/*
6836 * Non-interrupt SPC freeze handling.
6837 *
6838 * This is a work-queue function outside of the triggering interrupt.
6839 */
6840void handle_freeze(struct work_struct *work)
6841{
6842 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
6843 freeze_work);
6844 struct hfi1_devdata *dd = ppd->dd;
6845
6846 /* wait for freeze indicators on all affected blocks */
Mike Marciniszyn77241052015-07-30 15:17:43 -04006847 wait_for_freeze_status(dd, 1);
6848
6849 /* SPC is now frozen */
6850
6851 /* do send PIO freeze steps */
6852 pio_freeze(dd);
6853
6854 /* do send DMA freeze steps */
6855 sdma_freeze(dd);
6856
6857 /* do send egress freeze steps - nothing to do */
6858
6859 /* do receive freeze steps */
6860 rxe_freeze(dd);
6861
6862 /*
6863 * Unfreeze the hardware - clear the freeze, wait for each
6864 * block's frozen bit to clear, then clear the frozen flag.
6865 */
6866 write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
6867 wait_for_freeze_status(dd, 0);
6868
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05006869 if (is_ax(dd)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04006870 write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
6871 wait_for_freeze_status(dd, 1);
6872 write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
6873 wait_for_freeze_status(dd, 0);
6874 }
6875
6876 /* do send PIO unfreeze steps for kernel contexts */
6877 pio_kernel_unfreeze(dd);
6878
6879 /* do send DMA unfreeze steps */
6880 sdma_unfreeze(dd);
6881
6882 /* do send egress unfreeze steps - nothing to do */
6883
6884 /* do receive unfreeze steps for kernel contexts */
6885 rxe_kernel_unfreeze(dd);
6886
6887 /*
6888 * The unfreeze procedure touches global device registers when
6889 * it disables and re-enables RXE. Mark the device unfrozen
6890 * after all that is done so other parts of the driver waiting
6891 * for the device to unfreeze don't do things out of order.
6892 *
6893 * The above implies that the meaning of HFI1_FROZEN flag is
6894 * "Device has gone into freeze mode and freeze mode handling
6895 * is still in progress."
6896 *
6897 * The flag will be removed when freeze mode processing has
6898 * completed.
6899 */
6900 dd->flags &= ~HFI1_FROZEN;
6901 wake_up(&dd->event_queue);
6902
6903 /* no longer frozen */
Mike Marciniszyn77241052015-07-30 15:17:43 -04006904}
6905
6906/*
6907 * Handle a link up interrupt from the 8051.
6908 *
6909 * This is a work-queue function outside of the interrupt.
6910 */
6911void handle_link_up(struct work_struct *work)
6912{
6913 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
Jubin John17fb4f22016-02-14 20:21:52 -08006914 link_up_work);
Byczkowski, Jakubb3e6b4b2017-05-12 09:01:37 -07006915 struct hfi1_devdata *dd = ppd->dd;
6916
Mike Marciniszyn77241052015-07-30 15:17:43 -04006917 set_link_state(ppd, HLS_UP_INIT);
6918
6919 /* cache the read of DC_LCB_STS_ROUND_TRIP_LTP_CNT */
Byczkowski, Jakubb3e6b4b2017-05-12 09:01:37 -07006920 read_ltp_rtt(dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006921 /*
6922 * OPA specifies that certain counters are cleared on a transition
6923 * to link up, so do that.
6924 */
Byczkowski, Jakubb3e6b4b2017-05-12 09:01:37 -07006925 clear_linkup_counters(dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006926 /*
6927 * And (re)set link up default values.
6928 */
6929 set_linkup_defaults(ppd);
6930
Byczkowski, Jakubb3e6b4b2017-05-12 09:01:37 -07006931 /*
6932 * Set VL15 credits. Use cached value from verify cap interrupt.
6933 * In case of quick linkup or simulator, vl15 value will be set by
6934 * handle_linkup_change. VerifyCap interrupt handler will not be
6935 * called in those scenarios.
6936 */
6937 if (!(quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR))
6938 set_up_vl15(dd, dd->vl15buf_cached);
6939
Mike Marciniszyn77241052015-07-30 15:17:43 -04006940 /* enforce link speed enabled */
6941 if ((ppd->link_speed_active & ppd->link_speed_enabled) == 0) {
6942 /* oops - current speed is not enabled, bounce */
Byczkowski, Jakubb3e6b4b2017-05-12 09:01:37 -07006943 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08006944 "Link speed active 0x%x is outside enabled 0x%x, downing link\n",
6945 ppd->link_speed_active, ppd->link_speed_enabled);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006946 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SPEED_POLICY, 0,
Jubin John17fb4f22016-02-14 20:21:52 -08006947 OPA_LINKDOWN_REASON_SPEED_POLICY);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006948 set_link_state(ppd, HLS_DN_OFFLINE);
6949 start_link(ppd);
6950 }
6951}
6952
Jubin John4d114fd2016-02-14 20:21:43 -08006953/*
6954 * Several pieces of LNI information were cached for SMA in ppd.
6955 * Reset these on link down
6956 */
Mike Marciniszyn77241052015-07-30 15:17:43 -04006957static void reset_neighbor_info(struct hfi1_pportdata *ppd)
6958{
6959 ppd->neighbor_guid = 0;
6960 ppd->neighbor_port_number = 0;
6961 ppd->neighbor_type = 0;
6962 ppd->neighbor_fm_security = 0;
6963}
6964
Dean Luickfeb831d2016-04-14 08:31:36 -07006965static const char * const link_down_reason_strs[] = {
6966 [OPA_LINKDOWN_REASON_NONE] = "None",
Dennis Dalessandro67838e62017-05-29 17:18:46 -07006967 [OPA_LINKDOWN_REASON_RCV_ERROR_0] = "Receive error 0",
Dean Luickfeb831d2016-04-14 08:31:36 -07006968 [OPA_LINKDOWN_REASON_BAD_PKT_LEN] = "Bad packet length",
6969 [OPA_LINKDOWN_REASON_PKT_TOO_LONG] = "Packet too long",
6970 [OPA_LINKDOWN_REASON_PKT_TOO_SHORT] = "Packet too short",
6971 [OPA_LINKDOWN_REASON_BAD_SLID] = "Bad SLID",
6972 [OPA_LINKDOWN_REASON_BAD_DLID] = "Bad DLID",
6973 [OPA_LINKDOWN_REASON_BAD_L2] = "Bad L2",
6974 [OPA_LINKDOWN_REASON_BAD_SC] = "Bad SC",
6975 [OPA_LINKDOWN_REASON_RCV_ERROR_8] = "Receive error 8",
6976 [OPA_LINKDOWN_REASON_BAD_MID_TAIL] = "Bad mid tail",
6977 [OPA_LINKDOWN_REASON_RCV_ERROR_10] = "Receive error 10",
6978 [OPA_LINKDOWN_REASON_PREEMPT_ERROR] = "Preempt error",
6979 [OPA_LINKDOWN_REASON_PREEMPT_VL15] = "Preempt vl15",
6980 [OPA_LINKDOWN_REASON_BAD_VL_MARKER] = "Bad VL marker",
6981 [OPA_LINKDOWN_REASON_RCV_ERROR_14] = "Receive error 14",
6982 [OPA_LINKDOWN_REASON_RCV_ERROR_15] = "Receive error 15",
6983 [OPA_LINKDOWN_REASON_BAD_HEAD_DIST] = "Bad head distance",
6984 [OPA_LINKDOWN_REASON_BAD_TAIL_DIST] = "Bad tail distance",
6985 [OPA_LINKDOWN_REASON_BAD_CTRL_DIST] = "Bad control distance",
6986 [OPA_LINKDOWN_REASON_BAD_CREDIT_ACK] = "Bad credit ack",
6987 [OPA_LINKDOWN_REASON_UNSUPPORTED_VL_MARKER] = "Unsupported VL marker",
6988 [OPA_LINKDOWN_REASON_BAD_PREEMPT] = "Bad preempt",
6989 [OPA_LINKDOWN_REASON_BAD_CONTROL_FLIT] = "Bad control flit",
6990 [OPA_LINKDOWN_REASON_EXCEED_MULTICAST_LIMIT] = "Exceed multicast limit",
6991 [OPA_LINKDOWN_REASON_RCV_ERROR_24] = "Receive error 24",
6992 [OPA_LINKDOWN_REASON_RCV_ERROR_25] = "Receive error 25",
6993 [OPA_LINKDOWN_REASON_RCV_ERROR_26] = "Receive error 26",
6994 [OPA_LINKDOWN_REASON_RCV_ERROR_27] = "Receive error 27",
6995 [OPA_LINKDOWN_REASON_RCV_ERROR_28] = "Receive error 28",
6996 [OPA_LINKDOWN_REASON_RCV_ERROR_29] = "Receive error 29",
6997 [OPA_LINKDOWN_REASON_RCV_ERROR_30] = "Receive error 30",
6998 [OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN] =
6999 "Excessive buffer overrun",
7000 [OPA_LINKDOWN_REASON_UNKNOWN] = "Unknown",
7001 [OPA_LINKDOWN_REASON_REBOOT] = "Reboot",
7002 [OPA_LINKDOWN_REASON_NEIGHBOR_UNKNOWN] = "Neighbor unknown",
7003 [OPA_LINKDOWN_REASON_FM_BOUNCE] = "FM bounce",
7004 [OPA_LINKDOWN_REASON_SPEED_POLICY] = "Speed policy",
7005 [OPA_LINKDOWN_REASON_WIDTH_POLICY] = "Width policy",
7006 [OPA_LINKDOWN_REASON_DISCONNECTED] = "Disconnected",
7007 [OPA_LINKDOWN_REASON_LOCAL_MEDIA_NOT_INSTALLED] =
7008 "Local media not installed",
7009 [OPA_LINKDOWN_REASON_NOT_INSTALLED] = "Not installed",
7010 [OPA_LINKDOWN_REASON_CHASSIS_CONFIG] = "Chassis config",
7011 [OPA_LINKDOWN_REASON_END_TO_END_NOT_INSTALLED] =
7012 "End to end not installed",
7013 [OPA_LINKDOWN_REASON_POWER_POLICY] = "Power policy",
7014 [OPA_LINKDOWN_REASON_LINKSPEED_POLICY] = "Link speed policy",
7015 [OPA_LINKDOWN_REASON_LINKWIDTH_POLICY] = "Link width policy",
7016 [OPA_LINKDOWN_REASON_SWITCH_MGMT] = "Switch management",
7017 [OPA_LINKDOWN_REASON_SMA_DISABLED] = "SMA disabled",
7018 [OPA_LINKDOWN_REASON_TRANSIENT] = "Transient"
7019};
7020
7021/* return the neighbor link down reason string */
7022static const char *link_down_reason_str(u8 reason)
7023{
7024 const char *str = NULL;
7025
7026 if (reason < ARRAY_SIZE(link_down_reason_strs))
7027 str = link_down_reason_strs[reason];
7028 if (!str)
7029 str = "(invalid)";
7030
7031 return str;
7032}
7033
Mike Marciniszyn77241052015-07-30 15:17:43 -04007034/*
7035 * Handle a link down interrupt from the 8051.
7036 *
7037 * This is a work-queue function outside of the interrupt.
7038 */
7039void handle_link_down(struct work_struct *work)
7040{
7041 u8 lcl_reason, neigh_reason = 0;
Dean Luickfeb831d2016-04-14 08:31:36 -07007042 u8 link_down_reason;
Mike Marciniszyn77241052015-07-30 15:17:43 -04007043 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
Dean Luickfeb831d2016-04-14 08:31:36 -07007044 link_down_work);
7045 int was_up;
7046 static const char ldr_str[] = "Link down reason: ";
Mike Marciniszyn77241052015-07-30 15:17:43 -04007047
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08007048 if ((ppd->host_link_state &
7049 (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) &&
7050 ppd->port_type == PORT_TYPE_FIXED)
7051 ppd->offline_disabled_reason =
7052 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NOT_INSTALLED);
7053
7054 /* Go offline first, then deal with reading/writing through 8051 */
Dean Luickfeb831d2016-04-14 08:31:36 -07007055 was_up = !!(ppd->host_link_state & HLS_UP);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007056 set_link_state(ppd, HLS_DN_OFFLINE);
Sebastian Sanchez626c0772017-07-29 08:43:55 -07007057 xchg(&ppd->is_link_down_queued, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007058
Dean Luickfeb831d2016-04-14 08:31:36 -07007059 if (was_up) {
7060 lcl_reason = 0;
7061 /* link down reason is only valid if the link was up */
7062 read_link_down_reason(ppd->dd, &link_down_reason);
7063 switch (link_down_reason) {
7064 case LDR_LINK_TRANSFER_ACTIVE_LOW:
7065 /* the link went down, no idle message reason */
7066 dd_dev_info(ppd->dd, "%sUnexpected link down\n",
7067 ldr_str);
7068 break;
7069 case LDR_RECEIVED_LINKDOWN_IDLE_MSG:
7070 /*
7071 * The neighbor reason is only valid if an idle message
7072 * was received for it.
7073 */
7074 read_planned_down_reason_code(ppd->dd, &neigh_reason);
7075 dd_dev_info(ppd->dd,
7076 "%sNeighbor link down message %d, %s\n",
7077 ldr_str, neigh_reason,
7078 link_down_reason_str(neigh_reason));
7079 break;
7080 case LDR_RECEIVED_HOST_OFFLINE_REQ:
7081 dd_dev_info(ppd->dd,
7082 "%sHost requested link to go offline\n",
7083 ldr_str);
7084 break;
7085 default:
7086 dd_dev_info(ppd->dd, "%sUnknown reason 0x%x\n",
7087 ldr_str, link_down_reason);
7088 break;
7089 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04007090
Dean Luickfeb831d2016-04-14 08:31:36 -07007091 /*
7092 * If no reason, assume peer-initiated but missed
7093 * LinkGoingDown idle flits.
7094 */
7095 if (neigh_reason == 0)
7096 lcl_reason = OPA_LINKDOWN_REASON_NEIGHBOR_UNKNOWN;
7097 } else {
7098 /* went down while polling or going up */
7099 lcl_reason = OPA_LINKDOWN_REASON_TRANSIENT;
7100 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04007101
7102 set_link_down_reason(ppd, lcl_reason, neigh_reason, 0);
7103
Dean Luick015e91f2016-04-14 08:31:42 -07007104 /* inform the SMA when the link transitions from up to down */
7105 if (was_up && ppd->local_link_down_reason.sma == 0 &&
7106 ppd->neigh_link_down_reason.sma == 0) {
7107 ppd->local_link_down_reason.sma =
7108 ppd->local_link_down_reason.latest;
7109 ppd->neigh_link_down_reason.sma =
7110 ppd->neigh_link_down_reason.latest;
7111 }
7112
Mike Marciniszyn77241052015-07-30 15:17:43 -04007113 reset_neighbor_info(ppd);
7114
7115 /* disable the port */
7116 clear_rcvctrl(ppd->dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
7117
Jubin John4d114fd2016-02-14 20:21:43 -08007118 /*
7119 * If there is no cable attached, turn the DC off. Otherwise,
7120 * start the link bring up.
7121 */
Dean Luick0db9dec2016-09-06 04:35:20 -07007122 if (ppd->port_type == PORT_TYPE_QSFP && !qsfp_mod_present(ppd))
Mike Marciniszyn77241052015-07-30 15:17:43 -04007123 dc_shutdown(ppd->dd);
Dean Luick0db9dec2016-09-06 04:35:20 -07007124 else
Mike Marciniszyn77241052015-07-30 15:17:43 -04007125 start_link(ppd);
7126}
7127
7128void handle_link_bounce(struct work_struct *work)
7129{
7130 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
7131 link_bounce_work);
7132
7133 /*
7134 * Only do something if the link is currently up.
7135 */
7136 if (ppd->host_link_state & HLS_UP) {
7137 set_link_state(ppd, HLS_DN_OFFLINE);
7138 start_link(ppd);
7139 } else {
7140 dd_dev_info(ppd->dd, "%s: link not up (%s), nothing to do\n",
Jubin John17fb4f22016-02-14 20:21:52 -08007141 __func__, link_state_name(ppd->host_link_state));
Mike Marciniszyn77241052015-07-30 15:17:43 -04007142 }
7143}
7144
7145/*
7146 * Mask conversion: Capability exchange to Port LTP. The capability
7147 * exchange has an implicit 16b CRC that is mandatory.
7148 */
7149static int cap_to_port_ltp(int cap)
7150{
7151 int port_ltp = PORT_LTP_CRC_MODE_16; /* this mode is mandatory */
7152
7153 if (cap & CAP_CRC_14B)
7154 port_ltp |= PORT_LTP_CRC_MODE_14;
7155 if (cap & CAP_CRC_48B)
7156 port_ltp |= PORT_LTP_CRC_MODE_48;
7157 if (cap & CAP_CRC_12B_16B_PER_LANE)
7158 port_ltp |= PORT_LTP_CRC_MODE_PER_LANE;
7159
7160 return port_ltp;
7161}
7162
7163/*
7164 * Convert an OPA Port LTP mask to capability mask
7165 */
7166int port_ltp_to_cap(int port_ltp)
7167{
7168 int cap_mask = 0;
7169
7170 if (port_ltp & PORT_LTP_CRC_MODE_14)
7171 cap_mask |= CAP_CRC_14B;
7172 if (port_ltp & PORT_LTP_CRC_MODE_48)
7173 cap_mask |= CAP_CRC_48B;
7174 if (port_ltp & PORT_LTP_CRC_MODE_PER_LANE)
7175 cap_mask |= CAP_CRC_12B_16B_PER_LANE;
7176
7177 return cap_mask;
7178}
7179
7180/*
7181 * Convert a single DC LCB CRC mode to an OPA Port LTP mask.
7182 */
7183static int lcb_to_port_ltp(int lcb_crc)
7184{
7185 int port_ltp = 0;
7186
7187 if (lcb_crc == LCB_CRC_12B_16B_PER_LANE)
7188 port_ltp = PORT_LTP_CRC_MODE_PER_LANE;
7189 else if (lcb_crc == LCB_CRC_48B)
7190 port_ltp = PORT_LTP_CRC_MODE_48;
7191 else if (lcb_crc == LCB_CRC_14B)
7192 port_ltp = PORT_LTP_CRC_MODE_14;
7193 else
7194 port_ltp = PORT_LTP_CRC_MODE_16;
7195
7196 return port_ltp;
7197}
7198
7199/*
7200 * Our neighbor has indicated that we are allowed to act as a fabric
7201 * manager, so place the full management partition key in the second
7202 * (0-based) pkey array position (see OPAv1, section 20.2.2.6.8). Note
7203 * that we should already have the limited management partition key in
7204 * array element 1, and also that the port is not yet up when
7205 * add_full_mgmt_pkey() is invoked.
7206 */
7207static void add_full_mgmt_pkey(struct hfi1_pportdata *ppd)
7208{
7209 struct hfi1_devdata *dd = ppd->dd;
7210
Dennis Dalessandroa498fbc2017-04-09 10:17:06 -07007211 /* Sanity check - ppd->pkeys[2] should be 0, or already initialized */
Dean Luick87645222015-12-01 15:38:21 -05007212 if (!((ppd->pkeys[2] == 0) || (ppd->pkeys[2] == FULL_MGMT_P_KEY)))
7213 dd_dev_warn(dd, "%s pkey[2] already set to 0x%x, resetting it to 0x%x\n",
7214 __func__, ppd->pkeys[2], FULL_MGMT_P_KEY);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007215 ppd->pkeys[2] = FULL_MGMT_P_KEY;
7216 (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
Sebastian Sanchez34d351f2016-06-09 07:52:03 -07007217 hfi1_event_pkey_change(ppd->dd, ppd->port);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007218}
7219
Sebastian Sanchez3ec5fa22016-06-09 07:51:57 -07007220static void clear_full_mgmt_pkey(struct hfi1_pportdata *ppd)
Sebastian Sanchezce8b2fd2016-05-24 12:50:47 -07007221{
Sebastian Sanchez3ec5fa22016-06-09 07:51:57 -07007222 if (ppd->pkeys[2] != 0) {
7223 ppd->pkeys[2] = 0;
7224 (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
Sebastian Sanchez34d351f2016-06-09 07:52:03 -07007225 hfi1_event_pkey_change(ppd->dd, ppd->port);
Sebastian Sanchez3ec5fa22016-06-09 07:51:57 -07007226 }
Sebastian Sanchezce8b2fd2016-05-24 12:50:47 -07007227}
7228
Mike Marciniszyn77241052015-07-30 15:17:43 -04007229/*
7230 * Convert the given link width to the OPA link width bitmask.
7231 */
7232static u16 link_width_to_bits(struct hfi1_devdata *dd, u16 width)
7233{
7234 switch (width) {
7235 case 0:
7236 /*
7237 * Simulator and quick linkup do not set the width.
7238 * Just set it to 4x without complaint.
7239 */
7240 if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR || quick_linkup)
7241 return OPA_LINK_WIDTH_4X;
7242 return 0; /* no lanes up */
7243 case 1: return OPA_LINK_WIDTH_1X;
7244 case 2: return OPA_LINK_WIDTH_2X;
7245 case 3: return OPA_LINK_WIDTH_3X;
7246 default:
7247 dd_dev_info(dd, "%s: invalid width %d, using 4\n",
Jubin John17fb4f22016-02-14 20:21:52 -08007248 __func__, width);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007249 /* fall through */
7250 case 4: return OPA_LINK_WIDTH_4X;
7251 }
7252}
7253
7254/*
7255 * Do a population count on the bottom nibble.
7256 */
7257static const u8 bit_counts[16] = {
7258 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
7259};
Jubin Johnf4d507c2016-02-14 20:20:25 -08007260
Mike Marciniszyn77241052015-07-30 15:17:43 -04007261static inline u8 nibble_to_count(u8 nibble)
7262{
7263 return bit_counts[nibble & 0xf];
7264}
7265
7266/*
7267 * Read the active lane information from the 8051 registers and return
7268 * their widths.
7269 *
7270 * Active lane information is found in these 8051 registers:
7271 * enable_lane_tx
7272 * enable_lane_rx
7273 */
7274static void get_link_widths(struct hfi1_devdata *dd, u16 *tx_width,
7275 u16 *rx_width)
7276{
7277 u16 tx, rx;
7278 u8 enable_lane_rx;
7279 u8 enable_lane_tx;
7280 u8 tx_polarity_inversion;
7281 u8 rx_polarity_inversion;
7282 u8 max_rate;
7283
7284 /* read the active lanes */
7285 read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
Jubin John17fb4f22016-02-14 20:21:52 -08007286 &rx_polarity_inversion, &max_rate);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007287 read_local_lni(dd, &enable_lane_rx);
7288
7289 /* convert to counts */
7290 tx = nibble_to_count(enable_lane_tx);
7291 rx = nibble_to_count(enable_lane_rx);
7292
7293 /*
7294 * Set link_speed_active here, overriding what was set in
7295 * handle_verify_cap(). The ASIC 8051 firmware does not correctly
7296 * set the max_rate field in handle_verify_cap until v0.19.
7297 */
Jubin Johnd0d236e2016-02-14 20:20:15 -08007298 if ((dd->icode == ICODE_RTL_SILICON) &&
Michael J. Ruhl5e6e94242017-03-20 17:25:48 -07007299 (dd->dc8051_ver < dc8051_ver(0, 19, 0))) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04007300 /* max_rate: 0 = 12.5G, 1 = 25G */
7301 switch (max_rate) {
7302 case 0:
7303 dd->pport[0].link_speed_active = OPA_LINK_SPEED_12_5G;
7304 break;
7305 default:
7306 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08007307 "%s: unexpected max rate %d, using 25Gb\n",
7308 __func__, (int)max_rate);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007309 /* fall through */
7310 case 1:
7311 dd->pport[0].link_speed_active = OPA_LINK_SPEED_25G;
7312 break;
7313 }
7314 }
7315
7316 dd_dev_info(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08007317 "Fabric active lanes (width): tx 0x%x (%d), rx 0x%x (%d)\n",
7318 enable_lane_tx, tx, enable_lane_rx, rx);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007319 *tx_width = link_width_to_bits(dd, tx);
7320 *rx_width = link_width_to_bits(dd, rx);
7321}
7322
7323/*
7324 * Read verify_cap_local_fm_link_width[1] to obtain the link widths.
7325 * Valid after the end of VerifyCap and during LinkUp. Does not change
7326 * after link up. I.e. look elsewhere for downgrade information.
7327 *
7328 * Bits are:
7329 * + bits [7:4] contain the number of active transmitters
7330 * + bits [3:0] contain the number of active receivers
7331 * These are numbers 1 through 4 and can be different values if the
7332 * link is asymmetric.
7333 *
7334 * verify_cap_local_fm_link_width[0] retains its original value.
7335 */
7336static void get_linkup_widths(struct hfi1_devdata *dd, u16 *tx_width,
7337 u16 *rx_width)
7338{
7339 u16 widths, tx, rx;
7340 u8 misc_bits, local_flags;
7341 u16 active_tx, active_rx;
7342
7343 read_vc_local_link_width(dd, &misc_bits, &local_flags, &widths);
7344 tx = widths >> 12;
7345 rx = (widths >> 8) & 0xf;
7346
7347 *tx_width = link_width_to_bits(dd, tx);
7348 *rx_width = link_width_to_bits(dd, rx);
7349
7350 /* print the active widths */
7351 get_link_widths(dd, &active_tx, &active_rx);
7352}
7353
7354/*
7355 * Set ppd->link_width_active and ppd->link_width_downgrade_active using
7356 * hardware information when the link first comes up.
7357 *
7358 * The link width is not available until after VerifyCap.AllFramesReceived
7359 * (the trigger for handle_verify_cap), so this is outside that routine
7360 * and should be called when the 8051 signals linkup.
7361 */
7362void get_linkup_link_widths(struct hfi1_pportdata *ppd)
7363{
7364 u16 tx_width, rx_width;
7365
7366 /* get end-of-LNI link widths */
7367 get_linkup_widths(ppd->dd, &tx_width, &rx_width);
7368
7369 /* use tx_width as the link is supposed to be symmetric on link up */
7370 ppd->link_width_active = tx_width;
7371 /* link width downgrade active (LWD.A) starts out matching LW.A */
7372 ppd->link_width_downgrade_tx_active = ppd->link_width_active;
7373 ppd->link_width_downgrade_rx_active = ppd->link_width_active;
7374 /* per OPA spec, on link up LWD.E resets to LWD.S */
7375 ppd->link_width_downgrade_enabled = ppd->link_width_downgrade_supported;
7376 /* cache the active egress rate (units {10^6 bits/sec]) */
7377 ppd->current_egress_rate = active_egress_rate(ppd);
7378}
7379
7380/*
7381 * Handle a verify capabilities interrupt from the 8051.
7382 *
7383 * This is a work-queue function outside of the interrupt.
7384 */
7385void handle_verify_cap(struct work_struct *work)
7386{
7387 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
7388 link_vc_work);
7389 struct hfi1_devdata *dd = ppd->dd;
7390 u64 reg;
7391 u8 power_management;
Colin Ian Kinga63aa5d2017-07-13 23:13:38 +01007392 u8 continuous;
Mike Marciniszyn77241052015-07-30 15:17:43 -04007393 u8 vcu;
7394 u8 vau;
7395 u8 z;
7396 u16 vl15buf;
7397 u16 link_widths;
7398 u16 crc_mask;
7399 u16 crc_val;
7400 u16 device_id;
7401 u16 active_tx, active_rx;
7402 u8 partner_supported_crc;
7403 u8 remote_tx_rate;
7404 u8 device_rev;
7405
7406 set_link_state(ppd, HLS_VERIFY_CAP);
7407
7408 lcb_shutdown(dd, 0);
7409 adjust_lcb_for_fpga_serdes(dd);
7410
Colin Ian Kinga63aa5d2017-07-13 23:13:38 +01007411 read_vc_remote_phy(dd, &power_management, &continuous);
Jubin John17fb4f22016-02-14 20:21:52 -08007412 read_vc_remote_fabric(dd, &vau, &z, &vcu, &vl15buf,
7413 &partner_supported_crc);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007414 read_vc_remote_link_width(dd, &remote_tx_rate, &link_widths);
7415 read_remote_device_id(dd, &device_id, &device_rev);
7416 /*
7417 * And the 'MgmtAllowed' information, which is exchanged during
7418 * LNI, is also be available at this point.
7419 */
7420 read_mgmt_allowed(dd, &ppd->mgmt_allowed);
7421 /* print the active widths */
7422 get_link_widths(dd, &active_tx, &active_rx);
7423 dd_dev_info(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08007424 "Peer PHY: power management 0x%x, continuous updates 0x%x\n",
Colin Ian Kinga63aa5d2017-07-13 23:13:38 +01007425 (int)power_management, (int)continuous);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007426 dd_dev_info(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08007427 "Peer Fabric: vAU %d, Z %d, vCU %d, vl15 credits 0x%x, CRC sizes 0x%x\n",
7428 (int)vau, (int)z, (int)vcu, (int)vl15buf,
7429 (int)partner_supported_crc);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007430 dd_dev_info(dd, "Peer Link Width: tx rate 0x%x, widths 0x%x\n",
Jubin John17fb4f22016-02-14 20:21:52 -08007431 (u32)remote_tx_rate, (u32)link_widths);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007432 dd_dev_info(dd, "Peer Device ID: 0x%04x, Revision 0x%02x\n",
Jubin John17fb4f22016-02-14 20:21:52 -08007433 (u32)device_id, (u32)device_rev);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007434 /*
7435 * The peer vAU value just read is the peer receiver value. HFI does
7436 * not support a transmit vAU of 0 (AU == 8). We advertised that
7437 * with Z=1 in the fabric capabilities sent to the peer. The peer
7438 * will see our Z=1, and, if it advertised a vAU of 0, will move its
7439 * receive to vAU of 1 (AU == 16). Do the same here. We do not care
7440 * about the peer Z value - our sent vAU is 3 (hardwired) and is not
7441 * subject to the Z value exception.
7442 */
7443 if (vau == 0)
7444 vau = 1;
Byczkowski, Jakubb3e6b4b2017-05-12 09:01:37 -07007445 set_up_vau(dd, vau);
7446
7447 /*
7448 * Set VL15 credits to 0 in global credit register. Cache remote VL15
7449 * credits value and wait for link-up interrupt ot set it.
7450 */
7451 set_up_vl15(dd, 0);
7452 dd->vl15buf_cached = vl15buf;
Mike Marciniszyn77241052015-07-30 15:17:43 -04007453
7454 /* set up the LCB CRC mode */
7455 crc_mask = ppd->port_crc_mode_enabled & partner_supported_crc;
7456
7457 /* order is important: use the lowest bit in common */
7458 if (crc_mask & CAP_CRC_14B)
7459 crc_val = LCB_CRC_14B;
7460 else if (crc_mask & CAP_CRC_48B)
7461 crc_val = LCB_CRC_48B;
7462 else if (crc_mask & CAP_CRC_12B_16B_PER_LANE)
7463 crc_val = LCB_CRC_12B_16B_PER_LANE;
7464 else
7465 crc_val = LCB_CRC_16B;
7466
7467 dd_dev_info(dd, "Final LCB CRC mode: %d\n", (int)crc_val);
7468 write_csr(dd, DC_LCB_CFG_CRC_MODE,
7469 (u64)crc_val << DC_LCB_CFG_CRC_MODE_TX_VAL_SHIFT);
7470
7471 /* set (14b only) or clear sideband credit */
7472 reg = read_csr(dd, SEND_CM_CTRL);
7473 if (crc_val == LCB_CRC_14B && crc_14b_sideband) {
7474 write_csr(dd, SEND_CM_CTRL,
Jubin John17fb4f22016-02-14 20:21:52 -08007475 reg | SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007476 } else {
7477 write_csr(dd, SEND_CM_CTRL,
Jubin John17fb4f22016-02-14 20:21:52 -08007478 reg & ~SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007479 }
7480
7481 ppd->link_speed_active = 0; /* invalid value */
Michael J. Ruhl5e6e94242017-03-20 17:25:48 -07007482 if (dd->dc8051_ver < dc8051_ver(0, 20, 0)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04007483 /* remote_tx_rate: 0 = 12.5G, 1 = 25G */
7484 switch (remote_tx_rate) {
7485 case 0:
7486 ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
7487 break;
7488 case 1:
7489 ppd->link_speed_active = OPA_LINK_SPEED_25G;
7490 break;
7491 }
7492 } else {
7493 /* actual rate is highest bit of the ANDed rates */
7494 u8 rate = remote_tx_rate & ppd->local_tx_rate;
7495
7496 if (rate & 2)
7497 ppd->link_speed_active = OPA_LINK_SPEED_25G;
7498 else if (rate & 1)
7499 ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
7500 }
7501 if (ppd->link_speed_active == 0) {
7502 dd_dev_err(dd, "%s: unexpected remote tx rate %d, using 25Gb\n",
Jubin John17fb4f22016-02-14 20:21:52 -08007503 __func__, (int)remote_tx_rate);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007504 ppd->link_speed_active = OPA_LINK_SPEED_25G;
7505 }
7506
7507 /*
7508 * Cache the values of the supported, enabled, and active
7509 * LTP CRC modes to return in 'portinfo' queries. But the bit
7510 * flags that are returned in the portinfo query differ from
7511 * what's in the link_crc_mask, crc_sizes, and crc_val
7512 * variables. Convert these here.
7513 */
7514 ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
7515 /* supported crc modes */
7516 ppd->port_ltp_crc_mode |=
7517 cap_to_port_ltp(ppd->port_crc_mode_enabled) << 4;
7518 /* enabled crc modes */
7519 ppd->port_ltp_crc_mode |= lcb_to_port_ltp(crc_val);
7520 /* active crc mode */
7521
7522 /* set up the remote credit return table */
7523 assign_remote_cm_au_table(dd, vcu);
7524
7525 /*
7526 * The LCB is reset on entry to handle_verify_cap(), so this must
7527 * be applied on every link up.
7528 *
7529 * Adjust LCB error kill enable to kill the link if
7530 * these RBUF errors are seen:
7531 * REPLAY_BUF_MBE_SMASK
7532 * FLIT_INPUT_BUF_MBE_SMASK
7533 */
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05007534 if (is_ax(dd)) { /* fixed in B0 */
Mike Marciniszyn77241052015-07-30 15:17:43 -04007535 reg = read_csr(dd, DC_LCB_CFG_LINK_KILL_EN);
7536 reg |= DC_LCB_CFG_LINK_KILL_EN_REPLAY_BUF_MBE_SMASK
7537 | DC_LCB_CFG_LINK_KILL_EN_FLIT_INPUT_BUF_MBE_SMASK;
7538 write_csr(dd, DC_LCB_CFG_LINK_KILL_EN, reg);
7539 }
7540
7541 /* pull LCB fifos out of reset - all fifo clocks must be stable */
7542 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
7543
7544 /* give 8051 access to the LCB CSRs */
7545 write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
7546 set_8051_lcb_access(dd);
7547
Mike Marciniszyn77241052015-07-30 15:17:43 -04007548 if (ppd->mgmt_allowed)
7549 add_full_mgmt_pkey(ppd);
7550
7551 /* tell the 8051 to go to LinkUp */
7552 set_link_state(ppd, HLS_GOING_UP);
7553}
7554
7555/*
7556 * Apply the link width downgrade enabled policy against the current active
7557 * link widths.
7558 *
7559 * Called when the enabled policy changes or the active link widths change.
7560 */
7561void apply_link_downgrade_policy(struct hfi1_pportdata *ppd, int refresh_widths)
7562{
Mike Marciniszyn77241052015-07-30 15:17:43 -04007563 int do_bounce = 0;
Dean Luick323fd782015-11-16 21:59:24 -05007564 int tries;
7565 u16 lwde;
Mike Marciniszyn77241052015-07-30 15:17:43 -04007566 u16 tx, rx;
7567
Dean Luick323fd782015-11-16 21:59:24 -05007568 /* use the hls lock to avoid a race with actual link up */
7569 tries = 0;
7570retry:
Mike Marciniszyn77241052015-07-30 15:17:43 -04007571 mutex_lock(&ppd->hls_lock);
7572 /* only apply if the link is up */
Easwar Hariharan0c7f77a2016-05-12 10:22:33 -07007573 if (ppd->host_link_state & HLS_DOWN) {
Dean Luick323fd782015-11-16 21:59:24 -05007574 /* still going up..wait and retry */
7575 if (ppd->host_link_state & HLS_GOING_UP) {
7576 if (++tries < 1000) {
7577 mutex_unlock(&ppd->hls_lock);
7578 usleep_range(100, 120); /* arbitrary */
7579 goto retry;
7580 }
7581 dd_dev_err(ppd->dd,
7582 "%s: giving up waiting for link state change\n",
7583 __func__);
7584 }
7585 goto done;
7586 }
7587
7588 lwde = ppd->link_width_downgrade_enabled;
Mike Marciniszyn77241052015-07-30 15:17:43 -04007589
7590 if (refresh_widths) {
7591 get_link_widths(ppd->dd, &tx, &rx);
7592 ppd->link_width_downgrade_tx_active = tx;
7593 ppd->link_width_downgrade_rx_active = rx;
7594 }
7595
Dean Luickf9b56352016-04-14 08:31:30 -07007596 if (ppd->link_width_downgrade_tx_active == 0 ||
7597 ppd->link_width_downgrade_rx_active == 0) {
7598 /* the 8051 reported a dead link as a downgrade */
7599 dd_dev_err(ppd->dd, "Link downgrade is really a link down, ignoring\n");
7600 } else if (lwde == 0) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04007601 /* downgrade is disabled */
7602
7603 /* bounce if not at starting active width */
7604 if ((ppd->link_width_active !=
Jubin John17fb4f22016-02-14 20:21:52 -08007605 ppd->link_width_downgrade_tx_active) ||
7606 (ppd->link_width_active !=
7607 ppd->link_width_downgrade_rx_active)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04007608 dd_dev_err(ppd->dd,
Jubin John17fb4f22016-02-14 20:21:52 -08007609 "Link downgrade is disabled and link has downgraded, downing link\n");
Mike Marciniszyn77241052015-07-30 15:17:43 -04007610 dd_dev_err(ppd->dd,
Jubin John17fb4f22016-02-14 20:21:52 -08007611 " original 0x%x, tx active 0x%x, rx active 0x%x\n",
7612 ppd->link_width_active,
7613 ppd->link_width_downgrade_tx_active,
7614 ppd->link_width_downgrade_rx_active);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007615 do_bounce = 1;
7616 }
Jubin Johnd0d236e2016-02-14 20:20:15 -08007617 } else if ((lwde & ppd->link_width_downgrade_tx_active) == 0 ||
7618 (lwde & ppd->link_width_downgrade_rx_active) == 0) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04007619 /* Tx or Rx is outside the enabled policy */
7620 dd_dev_err(ppd->dd,
Jubin John17fb4f22016-02-14 20:21:52 -08007621 "Link is outside of downgrade allowed, downing link\n");
Mike Marciniszyn77241052015-07-30 15:17:43 -04007622 dd_dev_err(ppd->dd,
Jubin John17fb4f22016-02-14 20:21:52 -08007623 " enabled 0x%x, tx active 0x%x, rx active 0x%x\n",
7624 lwde, ppd->link_width_downgrade_tx_active,
7625 ppd->link_width_downgrade_rx_active);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007626 do_bounce = 1;
7627 }
7628
Dean Luick323fd782015-11-16 21:59:24 -05007629done:
7630 mutex_unlock(&ppd->hls_lock);
7631
Mike Marciniszyn77241052015-07-30 15:17:43 -04007632 if (do_bounce) {
7633 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_WIDTH_POLICY, 0,
Jubin John17fb4f22016-02-14 20:21:52 -08007634 OPA_LINKDOWN_REASON_WIDTH_POLICY);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007635 set_link_state(ppd, HLS_DN_OFFLINE);
7636 start_link(ppd);
7637 }
7638}
7639
7640/*
7641 * Handle a link downgrade interrupt from the 8051.
7642 *
7643 * This is a work-queue function outside of the interrupt.
7644 */
7645void handle_link_downgrade(struct work_struct *work)
7646{
7647 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
7648 link_downgrade_work);
7649
7650 dd_dev_info(ppd->dd, "8051: Link width downgrade\n");
7651 apply_link_downgrade_policy(ppd, 1);
7652}
7653
7654static char *dcc_err_string(char *buf, int buf_len, u64 flags)
7655{
7656 return flag_string(buf, buf_len, flags, dcc_err_flags,
7657 ARRAY_SIZE(dcc_err_flags));
7658}
7659
7660static char *lcb_err_string(char *buf, int buf_len, u64 flags)
7661{
7662 return flag_string(buf, buf_len, flags, lcb_err_flags,
7663 ARRAY_SIZE(lcb_err_flags));
7664}
7665
7666static char *dc8051_err_string(char *buf, int buf_len, u64 flags)
7667{
7668 return flag_string(buf, buf_len, flags, dc8051_err_flags,
7669 ARRAY_SIZE(dc8051_err_flags));
7670}
7671
7672static char *dc8051_info_err_string(char *buf, int buf_len, u64 flags)
7673{
7674 return flag_string(buf, buf_len, flags, dc8051_info_err_flags,
7675 ARRAY_SIZE(dc8051_info_err_flags));
7676}
7677
7678static char *dc8051_info_host_msg_string(char *buf, int buf_len, u64 flags)
7679{
7680 return flag_string(buf, buf_len, flags, dc8051_info_host_msg_flags,
7681 ARRAY_SIZE(dc8051_info_host_msg_flags));
7682}
7683
7684static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg)
7685{
7686 struct hfi1_pportdata *ppd = dd->pport;
7687 u64 info, err, host_msg;
7688 int queue_link_down = 0;
7689 char buf[96];
7690
7691 /* look at the flags */
7692 if (reg & DC_DC8051_ERR_FLG_SET_BY_8051_SMASK) {
7693 /* 8051 information set by firmware */
7694 /* read DC8051_DBG_ERR_INFO_SET_BY_8051 for details */
7695 info = read_csr(dd, DC_DC8051_DBG_ERR_INFO_SET_BY_8051);
7696 err = (info >> DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_SHIFT)
7697 & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_MASK;
7698 host_msg = (info >>
7699 DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_SHIFT)
7700 & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_MASK;
7701
7702 /*
7703 * Handle error flags.
7704 */
7705 if (err & FAILED_LNI) {
7706 /*
7707 * LNI error indications are cleared by the 8051
7708 * only when starting polling. Only pay attention
7709 * to them when in the states that occur during
7710 * LNI.
7711 */
7712 if (ppd->host_link_state
7713 & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
7714 queue_link_down = 1;
7715 dd_dev_info(dd, "Link error: %s\n",
Jubin John17fb4f22016-02-14 20:21:52 -08007716 dc8051_info_err_string(buf,
7717 sizeof(buf),
7718 err &
7719 FAILED_LNI));
Mike Marciniszyn77241052015-07-30 15:17:43 -04007720 }
7721 err &= ~(u64)FAILED_LNI;
7722 }
Dean Luick6d014532015-12-01 15:38:23 -05007723 /* unknown frames can happen durning LNI, just count */
7724 if (err & UNKNOWN_FRAME) {
7725 ppd->unknown_frame_count++;
7726 err &= ~(u64)UNKNOWN_FRAME;
7727 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04007728 if (err) {
7729 /* report remaining errors, but do not do anything */
7730 dd_dev_err(dd, "8051 info error: %s\n",
Jubin John17fb4f22016-02-14 20:21:52 -08007731 dc8051_info_err_string(buf, sizeof(buf),
7732 err));
Mike Marciniszyn77241052015-07-30 15:17:43 -04007733 }
7734
7735 /*
7736 * Handle host message flags.
7737 */
7738 if (host_msg & HOST_REQ_DONE) {
7739 /*
7740 * Presently, the driver does a busy wait for
7741 * host requests to complete. This is only an
7742 * informational message.
7743 * NOTE: The 8051 clears the host message
7744 * information *on the next 8051 command*.
7745 * Therefore, when linkup is achieved,
7746 * this flag will still be set.
7747 */
7748 host_msg &= ~(u64)HOST_REQ_DONE;
7749 }
7750 if (host_msg & BC_SMA_MSG) {
Sebastian Sanchez71d47002017-07-29 08:43:49 -07007751 queue_work(ppd->link_wq, &ppd->sma_message_work);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007752 host_msg &= ~(u64)BC_SMA_MSG;
7753 }
7754 if (host_msg & LINKUP_ACHIEVED) {
7755 dd_dev_info(dd, "8051: Link up\n");
Sebastian Sanchez71d47002017-07-29 08:43:49 -07007756 queue_work(ppd->link_wq, &ppd->link_up_work);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007757 host_msg &= ~(u64)LINKUP_ACHIEVED;
7758 }
7759 if (host_msg & EXT_DEVICE_CFG_REQ) {
Easwar Hariharan145dd2b2016-04-12 11:25:31 -07007760 handle_8051_request(ppd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007761 host_msg &= ~(u64)EXT_DEVICE_CFG_REQ;
7762 }
7763 if (host_msg & VERIFY_CAP_FRAME) {
Sebastian Sanchez71d47002017-07-29 08:43:49 -07007764 queue_work(ppd->link_wq, &ppd->link_vc_work);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007765 host_msg &= ~(u64)VERIFY_CAP_FRAME;
7766 }
7767 if (host_msg & LINK_GOING_DOWN) {
7768 const char *extra = "";
7769 /* no downgrade action needed if going down */
7770 if (host_msg & LINK_WIDTH_DOWNGRADED) {
7771 host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
7772 extra = " (ignoring downgrade)";
7773 }
7774 dd_dev_info(dd, "8051: Link down%s\n", extra);
7775 queue_link_down = 1;
7776 host_msg &= ~(u64)LINK_GOING_DOWN;
7777 }
7778 if (host_msg & LINK_WIDTH_DOWNGRADED) {
Sebastian Sanchez71d47002017-07-29 08:43:49 -07007779 queue_work(ppd->link_wq, &ppd->link_downgrade_work);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007780 host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
7781 }
7782 if (host_msg) {
7783 /* report remaining messages, but do not do anything */
7784 dd_dev_info(dd, "8051 info host message: %s\n",
Jubin John17fb4f22016-02-14 20:21:52 -08007785 dc8051_info_host_msg_string(buf,
7786 sizeof(buf),
7787 host_msg));
Mike Marciniszyn77241052015-07-30 15:17:43 -04007788 }
7789
7790 reg &= ~DC_DC8051_ERR_FLG_SET_BY_8051_SMASK;
7791 }
7792 if (reg & DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK) {
7793 /*
7794 * Lost the 8051 heartbeat. If this happens, we
7795 * receive constant interrupts about it. Disable
7796 * the interrupt after the first.
7797 */
7798 dd_dev_err(dd, "Lost 8051 heartbeat\n");
7799 write_csr(dd, DC_DC8051_ERR_EN,
Jubin John17fb4f22016-02-14 20:21:52 -08007800 read_csr(dd, DC_DC8051_ERR_EN) &
7801 ~DC_DC8051_ERR_EN_LOST_8051_HEART_BEAT_SMASK);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007802
7803 reg &= ~DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK;
7804 }
7805 if (reg) {
7806 /* report the error, but do not do anything */
7807 dd_dev_err(dd, "8051 error: %s\n",
Jubin John17fb4f22016-02-14 20:21:52 -08007808 dc8051_err_string(buf, sizeof(buf), reg));
Mike Marciniszyn77241052015-07-30 15:17:43 -04007809 }
7810
7811 if (queue_link_down) {
Jubin John4d114fd2016-02-14 20:21:43 -08007812 /*
7813 * if the link is already going down or disabled, do not
Sebastian Sanchezb6422bc2017-08-13 08:08:22 -07007814 * queue another. If there's a link down entry already
7815 * queued, don't queue another one.
Jubin John4d114fd2016-02-14 20:21:43 -08007816 */
Jubin Johnd0d236e2016-02-14 20:20:15 -08007817 if ((ppd->host_link_state &
7818 (HLS_GOING_OFFLINE | HLS_LINK_COOLDOWN)) ||
Sebastian Sanchezb6422bc2017-08-13 08:08:22 -07007819 ppd->link_enabled == 0) {
7820 dd_dev_info(dd, "%s: not queuing link down. host_link_state %x, link_enabled %x\n",
7821 __func__, ppd->host_link_state,
7822 ppd->link_enabled);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007823 } else {
Sebastian Sanchezb6422bc2017-08-13 08:08:22 -07007824 if (xchg(&ppd->is_link_down_queued, 1) == 1)
7825 dd_dev_info(dd,
7826 "%s: link down request already queued\n",
7827 __func__);
7828 else
7829 queue_work(ppd->link_wq, &ppd->link_down_work);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007830 }
7831 }
7832}
7833
7834static const char * const fm_config_txt[] = {
7835[0] =
7836 "BadHeadDist: Distance violation between two head flits",
7837[1] =
7838 "BadTailDist: Distance violation between two tail flits",
7839[2] =
7840 "BadCtrlDist: Distance violation between two credit control flits",
7841[3] =
7842 "BadCrdAck: Credits return for unsupported VL",
7843[4] =
7844 "UnsupportedVLMarker: Received VL Marker",
7845[5] =
7846 "BadPreempt: Exceeded the preemption nesting level",
7847[6] =
7848 "BadControlFlit: Received unsupported control flit",
7849/* no 7 */
7850[8] =
7851 "UnsupportedVLMarker: Received VL Marker for unconfigured or disabled VL",
7852};
7853
7854static const char * const port_rcv_txt[] = {
7855[1] =
7856 "BadPktLen: Illegal PktLen",
7857[2] =
7858 "PktLenTooLong: Packet longer than PktLen",
7859[3] =
7860 "PktLenTooShort: Packet shorter than PktLen",
7861[4] =
7862 "BadSLID: Illegal SLID (0, using multicast as SLID, does not include security validation of SLID)",
7863[5] =
7864 "BadDLID: Illegal DLID (0, doesn't match HFI)",
7865[6] =
7866 "BadL2: Illegal L2 opcode",
7867[7] =
7868 "BadSC: Unsupported SC",
7869[9] =
7870 "BadRC: Illegal RC",
7871[11] =
7872 "PreemptError: Preempting with same VL",
7873[12] =
7874 "PreemptVL15: Preempting a VL15 packet",
7875};
7876
7877#define OPA_LDR_FMCONFIG_OFFSET 16
7878#define OPA_LDR_PORTRCV_OFFSET 0
7879static void handle_dcc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
7880{
7881 u64 info, hdr0, hdr1;
7882 const char *extra;
7883 char buf[96];
7884 struct hfi1_pportdata *ppd = dd->pport;
7885 u8 lcl_reason = 0;
7886 int do_bounce = 0;
7887
7888 if (reg & DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK) {
7889 if (!(dd->err_info_uncorrectable & OPA_EI_STATUS_SMASK)) {
7890 info = read_csr(dd, DCC_ERR_INFO_UNCORRECTABLE);
7891 dd->err_info_uncorrectable = info & OPA_EI_CODE_SMASK;
7892 /* set status bit */
7893 dd->err_info_uncorrectable |= OPA_EI_STATUS_SMASK;
7894 }
7895 reg &= ~DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK;
7896 }
7897
7898 if (reg & DCC_ERR_FLG_LINK_ERR_SMASK) {
7899 struct hfi1_pportdata *ppd = dd->pport;
7900 /* this counter saturates at (2^32) - 1 */
7901 if (ppd->link_downed < (u32)UINT_MAX)
7902 ppd->link_downed++;
7903 reg &= ~DCC_ERR_FLG_LINK_ERR_SMASK;
7904 }
7905
7906 if (reg & DCC_ERR_FLG_FMCONFIG_ERR_SMASK) {
7907 u8 reason_valid = 1;
7908
7909 info = read_csr(dd, DCC_ERR_INFO_FMCONFIG);
7910 if (!(dd->err_info_fmconfig & OPA_EI_STATUS_SMASK)) {
7911 dd->err_info_fmconfig = info & OPA_EI_CODE_SMASK;
7912 /* set status bit */
7913 dd->err_info_fmconfig |= OPA_EI_STATUS_SMASK;
7914 }
7915 switch (info) {
7916 case 0:
7917 case 1:
7918 case 2:
7919 case 3:
7920 case 4:
7921 case 5:
7922 case 6:
7923 extra = fm_config_txt[info];
7924 break;
7925 case 8:
7926 extra = fm_config_txt[info];
7927 if (ppd->port_error_action &
7928 OPA_PI_MASK_FM_CFG_UNSUPPORTED_VL_MARKER) {
7929 do_bounce = 1;
7930 /*
7931 * lcl_reason cannot be derived from info
7932 * for this error
7933 */
7934 lcl_reason =
7935 OPA_LINKDOWN_REASON_UNSUPPORTED_VL_MARKER;
7936 }
7937 break;
7938 default:
7939 reason_valid = 0;
7940 snprintf(buf, sizeof(buf), "reserved%lld", info);
7941 extra = buf;
7942 break;
7943 }
7944
7945 if (reason_valid && !do_bounce) {
7946 do_bounce = ppd->port_error_action &
7947 (1 << (OPA_LDR_FMCONFIG_OFFSET + info));
7948 lcl_reason = info + OPA_LINKDOWN_REASON_BAD_HEAD_DIST;
7949 }
7950
7951 /* just report this */
Jakub Byczkowskic27aad02017-02-08 05:27:55 -08007952 dd_dev_info_ratelimited(dd, "DCC Error: fmconfig error: %s\n",
7953 extra);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007954 reg &= ~DCC_ERR_FLG_FMCONFIG_ERR_SMASK;
7955 }
7956
7957 if (reg & DCC_ERR_FLG_RCVPORT_ERR_SMASK) {
7958 u8 reason_valid = 1;
7959
7960 info = read_csr(dd, DCC_ERR_INFO_PORTRCV);
7961 hdr0 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR0);
7962 hdr1 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR1);
7963 if (!(dd->err_info_rcvport.status_and_code &
7964 OPA_EI_STATUS_SMASK)) {
7965 dd->err_info_rcvport.status_and_code =
7966 info & OPA_EI_CODE_SMASK;
7967 /* set status bit */
7968 dd->err_info_rcvport.status_and_code |=
7969 OPA_EI_STATUS_SMASK;
Jubin John4d114fd2016-02-14 20:21:43 -08007970 /*
7971 * save first 2 flits in the packet that caused
7972 * the error
7973 */
Bart Van Assche48a0cc132016-06-03 12:09:56 -07007974 dd->err_info_rcvport.packet_flit1 = hdr0;
7975 dd->err_info_rcvport.packet_flit2 = hdr1;
Mike Marciniszyn77241052015-07-30 15:17:43 -04007976 }
7977 switch (info) {
7978 case 1:
7979 case 2:
7980 case 3:
7981 case 4:
7982 case 5:
7983 case 6:
7984 case 7:
7985 case 9:
7986 case 11:
7987 case 12:
7988 extra = port_rcv_txt[info];
7989 break;
7990 default:
7991 reason_valid = 0;
7992 snprintf(buf, sizeof(buf), "reserved%lld", info);
7993 extra = buf;
7994 break;
7995 }
7996
7997 if (reason_valid && !do_bounce) {
7998 do_bounce = ppd->port_error_action &
7999 (1 << (OPA_LDR_PORTRCV_OFFSET + info));
8000 lcl_reason = info + OPA_LINKDOWN_REASON_RCV_ERROR_0;
8001 }
8002
8003 /* just report this */
Jakub Byczkowskic27aad02017-02-08 05:27:55 -08008004 dd_dev_info_ratelimited(dd, "DCC Error: PortRcv error: %s\n"
8005 " hdr0 0x%llx, hdr1 0x%llx\n",
8006 extra, hdr0, hdr1);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008007
8008 reg &= ~DCC_ERR_FLG_RCVPORT_ERR_SMASK;
8009 }
8010
8011 if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK) {
8012 /* informative only */
Jakub Byczkowskic27aad02017-02-08 05:27:55 -08008013 dd_dev_info_ratelimited(dd, "8051 access to LCB blocked\n");
Mike Marciniszyn77241052015-07-30 15:17:43 -04008014 reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK;
8015 }
8016 if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK) {
8017 /* informative only */
Jakub Byczkowskic27aad02017-02-08 05:27:55 -08008018 dd_dev_info_ratelimited(dd, "host access to LCB blocked\n");
Mike Marciniszyn77241052015-07-30 15:17:43 -04008019 reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK;
8020 }
8021
Don Hiatt243d9f42017-03-20 17:26:20 -07008022 if (unlikely(hfi1_dbg_fault_suppress_err(&dd->verbs_dev)))
8023 reg &= ~DCC_ERR_FLG_LATE_EBP_ERR_SMASK;
8024
Mike Marciniszyn77241052015-07-30 15:17:43 -04008025 /* report any remaining errors */
8026 if (reg)
Jakub Byczkowskic27aad02017-02-08 05:27:55 -08008027 dd_dev_info_ratelimited(dd, "DCC Error: %s\n",
8028 dcc_err_string(buf, sizeof(buf), reg));
Mike Marciniszyn77241052015-07-30 15:17:43 -04008029
8030 if (lcl_reason == 0)
8031 lcl_reason = OPA_LINKDOWN_REASON_UNKNOWN;
8032
8033 if (do_bounce) {
Jakub Byczkowskic27aad02017-02-08 05:27:55 -08008034 dd_dev_info_ratelimited(dd, "%s: PortErrorAction bounce\n",
8035 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008036 set_link_down_reason(ppd, lcl_reason, 0, lcl_reason);
Sebastian Sanchez71d47002017-07-29 08:43:49 -07008037 queue_work(ppd->link_wq, &ppd->link_bounce_work);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008038 }
8039}
8040
8041static void handle_lcb_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
8042{
8043 char buf[96];
8044
8045 dd_dev_info(dd, "LCB Error: %s\n",
Jubin John17fb4f22016-02-14 20:21:52 -08008046 lcb_err_string(buf, sizeof(buf), reg));
Mike Marciniszyn77241052015-07-30 15:17:43 -04008047}
8048
8049/*
8050 * CCE block DC interrupt. Source is < 8.
8051 */
8052static void is_dc_int(struct hfi1_devdata *dd, unsigned int source)
8053{
8054 const struct err_reg_info *eri = &dc_errs[source];
8055
8056 if (eri->handler) {
8057 interrupt_clear_down(dd, 0, eri);
8058 } else if (source == 3 /* dc_lbm_int */) {
8059 /*
8060 * This indicates that a parity error has occurred on the
8061 * address/control lines presented to the LBM. The error
8062 * is a single pulse, there is no associated error flag,
8063 * and it is non-maskable. This is because if a parity
8064 * error occurs on the request the request is dropped.
8065 * This should never occur, but it is nice to know if it
8066 * ever does.
8067 */
8068 dd_dev_err(dd, "Parity error in DC LBM block\n");
8069 } else {
8070 dd_dev_err(dd, "Invalid DC interrupt %u\n", source);
8071 }
8072}
8073
8074/*
8075 * TX block send credit interrupt. Source is < 160.
8076 */
8077static void is_send_credit_int(struct hfi1_devdata *dd, unsigned int source)
8078{
8079 sc_group_release_update(dd, source);
8080}
8081
8082/*
8083 * TX block SDMA interrupt. Source is < 48.
8084 *
8085 * SDMA interrupts are grouped by type:
8086 *
8087 * 0 - N-1 = SDma
8088 * N - 2N-1 = SDmaProgress
8089 * 2N - 3N-1 = SDmaIdle
8090 */
8091static void is_sdma_eng_int(struct hfi1_devdata *dd, unsigned int source)
8092{
8093 /* what interrupt */
8094 unsigned int what = source / TXE_NUM_SDMA_ENGINES;
8095 /* which engine */
8096 unsigned int which = source % TXE_NUM_SDMA_ENGINES;
8097
8098#ifdef CONFIG_SDMA_VERBOSITY
8099 dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", which,
8100 slashstrip(__FILE__), __LINE__, __func__);
8101 sdma_dumpstate(&dd->per_sdma[which]);
8102#endif
8103
8104 if (likely(what < 3 && which < dd->num_sdma)) {
8105 sdma_engine_interrupt(&dd->per_sdma[which], 1ull << source);
8106 } else {
8107 /* should not happen */
8108 dd_dev_err(dd, "Invalid SDMA interrupt 0x%x\n", source);
8109 }
8110}
8111
8112/*
8113 * RX block receive available interrupt. Source is < 160.
8114 */
8115static void is_rcv_avail_int(struct hfi1_devdata *dd, unsigned int source)
8116{
8117 struct hfi1_ctxtdata *rcd;
8118 char *err_detail;
8119
8120 if (likely(source < dd->num_rcv_contexts)) {
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07008121 rcd = hfi1_rcd_get_by_index(dd, source);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008122 if (rcd) {
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07008123 /* Check for non-user contexts, including vnic */
8124 if ((source < dd->first_dyn_alloc_ctxt) ||
8125 (rcd->sc && (rcd->sc->type == SC_KERNEL)))
Dean Luickf4f30031c2015-10-26 10:28:44 -04008126 rcd->do_interrupt(rcd, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008127 else
8128 handle_user_interrupt(rcd);
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07008129
8130 hfi1_rcd_put(rcd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008131 return; /* OK */
8132 }
8133 /* received an interrupt, but no rcd */
8134 err_detail = "dataless";
8135 } else {
8136 /* received an interrupt, but are not using that context */
8137 err_detail = "out of range";
8138 }
8139 dd_dev_err(dd, "unexpected %s receive available context interrupt %u\n",
Jubin John17fb4f22016-02-14 20:21:52 -08008140 err_detail, source);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008141}
8142
8143/*
8144 * RX block receive urgent interrupt. Source is < 160.
8145 */
8146static void is_rcv_urgent_int(struct hfi1_devdata *dd, unsigned int source)
8147{
8148 struct hfi1_ctxtdata *rcd;
8149 char *err_detail;
8150
8151 if (likely(source < dd->num_rcv_contexts)) {
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07008152 rcd = hfi1_rcd_get_by_index(dd, source);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008153 if (rcd) {
8154 /* only pay attention to user urgent interrupts */
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07008155 if ((source >= dd->first_dyn_alloc_ctxt) &&
8156 (!rcd->sc || (rcd->sc->type == SC_USER)))
Mike Marciniszyn77241052015-07-30 15:17:43 -04008157 handle_user_interrupt(rcd);
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07008158
8159 hfi1_rcd_put(rcd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008160 return; /* OK */
8161 }
8162 /* received an interrupt, but no rcd */
8163 err_detail = "dataless";
8164 } else {
8165 /* received an interrupt, but are not using that context */
8166 err_detail = "out of range";
8167 }
8168 dd_dev_err(dd, "unexpected %s receive urgent context interrupt %u\n",
Jubin John17fb4f22016-02-14 20:21:52 -08008169 err_detail, source);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008170}
8171
8172/*
8173 * Reserved range interrupt. Should not be called in normal operation.
8174 */
8175static void is_reserved_int(struct hfi1_devdata *dd, unsigned int source)
8176{
8177 char name[64];
8178
8179 dd_dev_err(dd, "unexpected %s interrupt\n",
Jubin John17fb4f22016-02-14 20:21:52 -08008180 is_reserved_name(name, sizeof(name), source));
Mike Marciniszyn77241052015-07-30 15:17:43 -04008181}
8182
8183static const struct is_table is_table[] = {
Jubin John4d114fd2016-02-14 20:21:43 -08008184/*
8185 * start end
8186 * name func interrupt func
8187 */
Mike Marciniszyn77241052015-07-30 15:17:43 -04008188{ IS_GENERAL_ERR_START, IS_GENERAL_ERR_END,
8189 is_misc_err_name, is_misc_err_int },
8190{ IS_SDMAENG_ERR_START, IS_SDMAENG_ERR_END,
8191 is_sdma_eng_err_name, is_sdma_eng_err_int },
8192{ IS_SENDCTXT_ERR_START, IS_SENDCTXT_ERR_END,
8193 is_sendctxt_err_name, is_sendctxt_err_int },
8194{ IS_SDMA_START, IS_SDMA_END,
8195 is_sdma_eng_name, is_sdma_eng_int },
8196{ IS_VARIOUS_START, IS_VARIOUS_END,
8197 is_various_name, is_various_int },
8198{ IS_DC_START, IS_DC_END,
8199 is_dc_name, is_dc_int },
8200{ IS_RCVAVAIL_START, IS_RCVAVAIL_END,
8201 is_rcv_avail_name, is_rcv_avail_int },
8202{ IS_RCVURGENT_START, IS_RCVURGENT_END,
8203 is_rcv_urgent_name, is_rcv_urgent_int },
8204{ IS_SENDCREDIT_START, IS_SENDCREDIT_END,
8205 is_send_credit_name, is_send_credit_int},
8206{ IS_RESERVED_START, IS_RESERVED_END,
8207 is_reserved_name, is_reserved_int},
8208};
8209
8210/*
8211 * Interrupt source interrupt - called when the given source has an interrupt.
8212 * Source is a bit index into an array of 64-bit integers.
8213 */
8214static void is_interrupt(struct hfi1_devdata *dd, unsigned int source)
8215{
8216 const struct is_table *entry;
8217
8218 /* avoids a double compare by walking the table in-order */
8219 for (entry = &is_table[0]; entry->is_name; entry++) {
8220 if (source < entry->end) {
8221 trace_hfi1_interrupt(dd, entry, source);
8222 entry->is_int(dd, source - entry->start);
8223 return;
8224 }
8225 }
8226 /* fell off the end */
8227 dd_dev_err(dd, "invalid interrupt source %u\n", source);
8228}
8229
8230/*
8231 * General interrupt handler. This is able to correctly handle
8232 * all interrupts in case INTx is used.
8233 */
8234static irqreturn_t general_interrupt(int irq, void *data)
8235{
8236 struct hfi1_devdata *dd = data;
8237 u64 regs[CCE_NUM_INT_CSRS];
8238 u32 bit;
8239 int i;
8240
8241 this_cpu_inc(*dd->int_counter);
8242
8243 /* phase 1: scan and clear all handled interrupts */
8244 for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
8245 if (dd->gi_mask[i] == 0) {
8246 regs[i] = 0; /* used later */
8247 continue;
8248 }
8249 regs[i] = read_csr(dd, CCE_INT_STATUS + (8 * i)) &
8250 dd->gi_mask[i];
8251 /* only clear if anything is set */
8252 if (regs[i])
8253 write_csr(dd, CCE_INT_CLEAR + (8 * i), regs[i]);
8254 }
8255
8256 /* phase 2: call the appropriate handler */
8257 for_each_set_bit(bit, (unsigned long *)&regs[0],
Jubin John17fb4f22016-02-14 20:21:52 -08008258 CCE_NUM_INT_CSRS * 64) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04008259 is_interrupt(dd, bit);
8260 }
8261
8262 return IRQ_HANDLED;
8263}
8264
8265static irqreturn_t sdma_interrupt(int irq, void *data)
8266{
8267 struct sdma_engine *sde = data;
8268 struct hfi1_devdata *dd = sde->dd;
8269 u64 status;
8270
8271#ifdef CONFIG_SDMA_VERBOSITY
8272 dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
8273 slashstrip(__FILE__), __LINE__, __func__);
8274 sdma_dumpstate(sde);
8275#endif
8276
8277 this_cpu_inc(*dd->int_counter);
8278
8279 /* This read_csr is really bad in the hot path */
8280 status = read_csr(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08008281 CCE_INT_STATUS + (8 * (IS_SDMA_START / 64)))
8282 & sde->imask;
Mike Marciniszyn77241052015-07-30 15:17:43 -04008283 if (likely(status)) {
8284 /* clear the interrupt(s) */
8285 write_csr(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08008286 CCE_INT_CLEAR + (8 * (IS_SDMA_START / 64)),
8287 status);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008288
8289 /* handle the interrupt(s) */
8290 sdma_engine_interrupt(sde, status);
Dennis Dalessandroee495ad2017-04-09 10:17:18 -07008291 } else {
Grzegorz Morysde42de82017-08-21 18:26:38 -07008292 dd_dev_err_ratelimited(dd, "SDMA engine %u interrupt, but no status bits set\n",
8293 sde->this_idx);
Dennis Dalessandroee495ad2017-04-09 10:17:18 -07008294 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04008295 return IRQ_HANDLED;
8296}
8297
8298/*
Dean Luickecd42f82016-02-03 14:35:14 -08008299 * Clear the receive interrupt. Use a read of the interrupt clear CSR
8300 * to insure that the write completed. This does NOT guarantee that
8301 * queued DMA writes to memory from the chip are pushed.
Dean Luickf4f30031c2015-10-26 10:28:44 -04008302 */
8303static inline void clear_recv_intr(struct hfi1_ctxtdata *rcd)
8304{
8305 struct hfi1_devdata *dd = rcd->dd;
8306 u32 addr = CCE_INT_CLEAR + (8 * rcd->ireg);
8307
8308 mmiowb(); /* make sure everything before is written */
8309 write_csr(dd, addr, rcd->imask);
8310 /* force the above write on the chip and get a value back */
8311 (void)read_csr(dd, addr);
8312}
8313
8314/* force the receive interrupt */
Jim Snowfb9036d2016-01-11 18:32:21 -05008315void force_recv_intr(struct hfi1_ctxtdata *rcd)
Dean Luickf4f30031c2015-10-26 10:28:44 -04008316{
8317 write_csr(rcd->dd, CCE_INT_FORCE + (8 * rcd->ireg), rcd->imask);
8318}
8319
Dean Luickecd42f82016-02-03 14:35:14 -08008320/*
8321 * Return non-zero if a packet is present.
8322 *
8323 * This routine is called when rechecking for packets after the RcvAvail
8324 * interrupt has been cleared down. First, do a quick check of memory for
8325 * a packet present. If not found, use an expensive CSR read of the context
8326 * tail to determine the actual tail. The CSR read is necessary because there
8327 * is no method to push pending DMAs to memory other than an interrupt and we
8328 * are trying to determine if we need to force an interrupt.
8329 */
Dean Luickf4f30031c2015-10-26 10:28:44 -04008330static inline int check_packet_present(struct hfi1_ctxtdata *rcd)
8331{
Dean Luickecd42f82016-02-03 14:35:14 -08008332 u32 tail;
8333 int present;
Dean Luickf4f30031c2015-10-26 10:28:44 -04008334
Dean Luickecd42f82016-02-03 14:35:14 -08008335 if (!HFI1_CAP_IS_KSET(DMA_RTAIL))
8336 present = (rcd->seq_cnt ==
8337 rhf_rcv_seq(rhf_to_cpu(get_rhf_addr(rcd))));
8338 else /* is RDMA rtail */
8339 present = (rcd->head != get_rcvhdrtail(rcd));
8340
8341 if (present)
8342 return 1;
8343
8344 /* fall back to a CSR read, correct indpendent of DMA_RTAIL */
8345 tail = (u32)read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
8346 return rcd->head != tail;
Dean Luickf4f30031c2015-10-26 10:28:44 -04008347}
8348
8349/*
8350 * Receive packet IRQ handler. This routine expects to be on its own IRQ.
8351 * This routine will try to handle packets immediately (latency), but if
8352 * it finds too many, it will invoke the thread handler (bandwitdh). The
Jubin John16733b82016-02-14 20:20:58 -08008353 * chip receive interrupt is *not* cleared down until this or the thread (if
Dean Luickf4f30031c2015-10-26 10:28:44 -04008354 * invoked) is finished. The intent is to avoid extra interrupts while we
8355 * are processing packets anyway.
Mike Marciniszyn77241052015-07-30 15:17:43 -04008356 */
8357static irqreturn_t receive_context_interrupt(int irq, void *data)
8358{
8359 struct hfi1_ctxtdata *rcd = data;
8360 struct hfi1_devdata *dd = rcd->dd;
Dean Luickf4f30031c2015-10-26 10:28:44 -04008361 int disposition;
8362 int present;
Mike Marciniszyn77241052015-07-30 15:17:43 -04008363
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07008364 trace_hfi1_receive_interrupt(dd, rcd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008365 this_cpu_inc(*dd->int_counter);
Ashutosh Dixitaffa48d2016-02-03 14:33:06 -08008366 aspm_ctx_disable(rcd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008367
Dean Luickf4f30031c2015-10-26 10:28:44 -04008368 /* receive interrupt remains blocked while processing packets */
8369 disposition = rcd->do_interrupt(rcd, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008370
Dean Luickf4f30031c2015-10-26 10:28:44 -04008371 /*
8372 * Too many packets were seen while processing packets in this
8373 * IRQ handler. Invoke the handler thread. The receive interrupt
8374 * remains blocked.
8375 */
8376 if (disposition == RCV_PKT_LIMIT)
8377 return IRQ_WAKE_THREAD;
8378
8379 /*
8380 * The packet processor detected no more packets. Clear the receive
8381 * interrupt and recheck for a packet packet that may have arrived
8382 * after the previous check and interrupt clear. If a packet arrived,
8383 * force another interrupt.
8384 */
8385 clear_recv_intr(rcd);
8386 present = check_packet_present(rcd);
8387 if (present)
8388 force_recv_intr(rcd);
8389
8390 return IRQ_HANDLED;
8391}
8392
8393/*
8394 * Receive packet thread handler. This expects to be invoked with the
8395 * receive interrupt still blocked.
8396 */
8397static irqreturn_t receive_context_thread(int irq, void *data)
8398{
8399 struct hfi1_ctxtdata *rcd = data;
8400 int present;
8401
8402 /* receive interrupt is still blocked from the IRQ handler */
8403 (void)rcd->do_interrupt(rcd, 1);
8404
8405 /*
8406 * The packet processor will only return if it detected no more
8407 * packets. Hold IRQs here so we can safely clear the interrupt and
8408 * recheck for a packet that may have arrived after the previous
8409 * check and the interrupt clear. If a packet arrived, force another
8410 * interrupt.
8411 */
8412 local_irq_disable();
8413 clear_recv_intr(rcd);
8414 present = check_packet_present(rcd);
8415 if (present)
8416 force_recv_intr(rcd);
8417 local_irq_enable();
Mike Marciniszyn77241052015-07-30 15:17:43 -04008418
8419 return IRQ_HANDLED;
8420}
8421
8422/* ========================================================================= */
8423
8424u32 read_physical_state(struct hfi1_devdata *dd)
8425{
8426 u64 reg;
8427
8428 reg = read_csr(dd, DC_DC8051_STS_CUR_STATE);
8429 return (reg >> DC_DC8051_STS_CUR_STATE_PORT_SHIFT)
8430 & DC_DC8051_STS_CUR_STATE_PORT_MASK;
8431}
8432
Jim Snowfb9036d2016-01-11 18:32:21 -05008433u32 read_logical_state(struct hfi1_devdata *dd)
Mike Marciniszyn77241052015-07-30 15:17:43 -04008434{
8435 u64 reg;
8436
8437 reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
8438 return (reg >> DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT)
8439 & DCC_CFG_PORT_CONFIG_LINK_STATE_MASK;
8440}
8441
8442static void set_logical_state(struct hfi1_devdata *dd, u32 chip_lstate)
8443{
8444 u64 reg;
8445
8446 reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
8447 /* clear current state, set new state */
8448 reg &= ~DCC_CFG_PORT_CONFIG_LINK_STATE_SMASK;
8449 reg |= (u64)chip_lstate << DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT;
8450 write_csr(dd, DCC_CFG_PORT_CONFIG, reg);
8451}
8452
8453/*
8454 * Use the 8051 to read a LCB CSR.
8455 */
8456static int read_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 *data)
8457{
8458 u32 regno;
8459 int ret;
8460
8461 if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
8462 if (acquire_lcb_access(dd, 0) == 0) {
8463 *data = read_csr(dd, addr);
8464 release_lcb_access(dd, 0);
8465 return 0;
8466 }
8467 return -EBUSY;
8468 }
8469
8470 /* register is an index of LCB registers: (offset - base) / 8 */
8471 regno = (addr - DC_LCB_CFG_RUN) >> 3;
8472 ret = do_8051_command(dd, HCMD_READ_LCB_CSR, regno, data);
8473 if (ret != HCMD_SUCCESS)
8474 return -EBUSY;
8475 return 0;
8476}
8477
8478/*
Michael J. Ruhl86884262017-03-20 17:24:51 -07008479 * Provide a cache for some of the LCB registers in case the LCB is
8480 * unavailable.
8481 * (The LCB is unavailable in certain link states, for example.)
8482 */
8483struct lcb_datum {
8484 u32 off;
8485 u64 val;
8486};
8487
8488static struct lcb_datum lcb_cache[] = {
8489 { DC_LCB_ERR_INFO_RX_REPLAY_CNT, 0},
8490 { DC_LCB_ERR_INFO_SEQ_CRC_CNT, 0 },
8491 { DC_LCB_ERR_INFO_REINIT_FROM_PEER_CNT, 0 },
8492};
8493
8494static void update_lcb_cache(struct hfi1_devdata *dd)
8495{
8496 int i;
8497 int ret;
8498 u64 val;
8499
8500 for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) {
8501 ret = read_lcb_csr(dd, lcb_cache[i].off, &val);
8502
8503 /* Update if we get good data */
8504 if (likely(ret != -EBUSY))
8505 lcb_cache[i].val = val;
8506 }
8507}
8508
8509static int read_lcb_cache(u32 off, u64 *val)
8510{
8511 int i;
8512
8513 for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) {
8514 if (lcb_cache[i].off == off) {
8515 *val = lcb_cache[i].val;
8516 return 0;
8517 }
8518 }
8519
8520 pr_warn("%s bad offset 0x%x\n", __func__, off);
8521 return -1;
8522}
8523
8524/*
Mike Marciniszyn77241052015-07-30 15:17:43 -04008525 * Read an LCB CSR. Access may not be in host control, so check.
8526 * Return 0 on success, -EBUSY on failure.
8527 */
8528int read_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 *data)
8529{
8530 struct hfi1_pportdata *ppd = dd->pport;
8531
8532 /* if up, go through the 8051 for the value */
8533 if (ppd->host_link_state & HLS_UP)
8534 return read_lcb_via_8051(dd, addr, data);
Michael J. Ruhl86884262017-03-20 17:24:51 -07008535 /* if going up or down, check the cache, otherwise, no access */
8536 if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE)) {
8537 if (read_lcb_cache(addr, data))
8538 return -EBUSY;
8539 return 0;
8540 }
8541
Mike Marciniszyn77241052015-07-30 15:17:43 -04008542 /* otherwise, host has access */
8543 *data = read_csr(dd, addr);
8544 return 0;
8545}
8546
8547/*
8548 * Use the 8051 to write a LCB CSR.
8549 */
8550static int write_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 data)
8551{
Dean Luick3bf40d62015-11-06 20:07:04 -05008552 u32 regno;
8553 int ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -04008554
Dean Luick3bf40d62015-11-06 20:07:04 -05008555 if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR ||
Michael J. Ruhl5e6e94242017-03-20 17:25:48 -07008556 (dd->dc8051_ver < dc8051_ver(0, 20, 0))) {
Dean Luick3bf40d62015-11-06 20:07:04 -05008557 if (acquire_lcb_access(dd, 0) == 0) {
8558 write_csr(dd, addr, data);
8559 release_lcb_access(dd, 0);
8560 return 0;
8561 }
8562 return -EBUSY;
Mike Marciniszyn77241052015-07-30 15:17:43 -04008563 }
Dean Luick3bf40d62015-11-06 20:07:04 -05008564
8565 /* register is an index of LCB registers: (offset - base) / 8 */
8566 regno = (addr - DC_LCB_CFG_RUN) >> 3;
8567 ret = do_8051_command(dd, HCMD_WRITE_LCB_CSR, regno, &data);
8568 if (ret != HCMD_SUCCESS)
8569 return -EBUSY;
8570 return 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04008571}
8572
8573/*
8574 * Write an LCB CSR. Access may not be in host control, so check.
8575 * Return 0 on success, -EBUSY on failure.
8576 */
8577int write_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 data)
8578{
8579 struct hfi1_pportdata *ppd = dd->pport;
8580
8581 /* if up, go through the 8051 for the value */
8582 if (ppd->host_link_state & HLS_UP)
8583 return write_lcb_via_8051(dd, addr, data);
8584 /* if going up or down, no access */
8585 if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE))
8586 return -EBUSY;
8587 /* otherwise, host has access */
8588 write_csr(dd, addr, data);
8589 return 0;
8590}
8591
8592/*
Sebastian Sanchez9be6a5d2017-10-02 11:04:26 -07008593 * If the 8051 is in reset mode (dd->dc_shutdown == 1), this function
8594 * will still continue executing.
8595 *
Mike Marciniszyn77241052015-07-30 15:17:43 -04008596 * Returns:
8597 * < 0 = Linux error, not able to get access
8598 * > 0 = 8051 command RETURN_CODE
8599 */
Sebastian Sanchez9be6a5d2017-10-02 11:04:26 -07008600static int _do_8051_command(struct hfi1_devdata *dd, u32 type, u64 in_data,
8601 u64 *out_data)
Mike Marciniszyn77241052015-07-30 15:17:43 -04008602{
8603 u64 reg, completed;
8604 int return_code;
Mike Marciniszyn77241052015-07-30 15:17:43 -04008605 unsigned long timeout;
8606
Sebastian Sanchez9be6a5d2017-10-02 11:04:26 -07008607 lockdep_assert_held(&dd->dc8051_lock);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008608 hfi1_cdbg(DC8051, "type %d, data 0x%012llx", type, in_data);
8609
Mike Marciniszyn77241052015-07-30 15:17:43 -04008610 /*
8611 * If an 8051 host command timed out previously, then the 8051 is
8612 * stuck.
8613 *
8614 * On first timeout, attempt to reset and restart the entire DC
8615 * block (including 8051). (Is this too big of a hammer?)
8616 *
8617 * If the 8051 times out a second time, the reset did not bring it
8618 * back to healthy life. In that case, fail any subsequent commands.
8619 */
8620 if (dd->dc8051_timed_out) {
8621 if (dd->dc8051_timed_out > 1) {
8622 dd_dev_err(dd,
8623 "Previous 8051 host command timed out, skipping command %u\n",
8624 type);
8625 return_code = -ENXIO;
8626 goto fail;
8627 }
Tadeusz Struk22546b72017-04-28 10:40:02 -07008628 _dc_shutdown(dd);
8629 _dc_start(dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008630 }
8631
8632 /*
8633 * If there is no timeout, then the 8051 command interface is
8634 * waiting for a command.
8635 */
8636
8637 /*
Dean Luick3bf40d62015-11-06 20:07:04 -05008638 * When writing a LCB CSR, out_data contains the full value to
8639 * to be written, while in_data contains the relative LCB
8640 * address in 7:0. Do the work here, rather than the caller,
8641 * of distrubting the write data to where it needs to go:
8642 *
8643 * Write data
8644 * 39:00 -> in_data[47:8]
8645 * 47:40 -> DC8051_CFG_EXT_DEV_0.RETURN_CODE
8646 * 63:48 -> DC8051_CFG_EXT_DEV_0.RSP_DATA
8647 */
8648 if (type == HCMD_WRITE_LCB_CSR) {
8649 in_data |= ((*out_data) & 0xffffffffffull) << 8;
Dean Luick00801672016-12-07 19:33:40 -08008650 /* must preserve COMPLETED - it is tied to hardware */
8651 reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_0);
8652 reg &= DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK;
8653 reg |= ((((*out_data) >> 40) & 0xff) <<
Dean Luick3bf40d62015-11-06 20:07:04 -05008654 DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT)
8655 | ((((*out_data) >> 48) & 0xffff) <<
8656 DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
8657 write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, reg);
8658 }
8659
8660 /*
Mike Marciniszyn77241052015-07-30 15:17:43 -04008661 * Do two writes: the first to stabilize the type and req_data, the
8662 * second to activate.
8663 */
8664 reg = ((u64)type & DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_MASK)
8665 << DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_SHIFT
8666 | (in_data & DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_MASK)
8667 << DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_SHIFT;
8668 write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
8669 reg |= DC_DC8051_CFG_HOST_CMD_0_REQ_NEW_SMASK;
8670 write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
8671
8672 /* wait for completion, alternate: interrupt */
8673 timeout = jiffies + msecs_to_jiffies(DC8051_COMMAND_TIMEOUT);
8674 while (1) {
8675 reg = read_csr(dd, DC_DC8051_CFG_HOST_CMD_1);
8676 completed = reg & DC_DC8051_CFG_HOST_CMD_1_COMPLETED_SMASK;
8677 if (completed)
8678 break;
8679 if (time_after(jiffies, timeout)) {
8680 dd->dc8051_timed_out++;
8681 dd_dev_err(dd, "8051 host command %u timeout\n", type);
8682 if (out_data)
8683 *out_data = 0;
8684 return_code = -ETIMEDOUT;
8685 goto fail;
8686 }
8687 udelay(2);
8688 }
8689
8690 if (out_data) {
8691 *out_data = (reg >> DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_SHIFT)
8692 & DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_MASK;
8693 if (type == HCMD_READ_LCB_CSR) {
8694 /* top 16 bits are in a different register */
8695 *out_data |= (read_csr(dd, DC_DC8051_CFG_EXT_DEV_1)
8696 & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SMASK)
8697 << (48
8698 - DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT);
8699 }
8700 }
8701 return_code = (reg >> DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_SHIFT)
8702 & DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_MASK;
8703 dd->dc8051_timed_out = 0;
8704 /*
8705 * Clear command for next user.
8706 */
8707 write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, 0);
8708
8709fail:
Sebastian Sanchez9be6a5d2017-10-02 11:04:26 -07008710 return return_code;
8711}
8712
8713/*
8714 * Returns:
8715 * < 0 = Linux error, not able to get access
8716 * > 0 = 8051 command RETURN_CODE
8717 */
8718static int do_8051_command(struct hfi1_devdata *dd, u32 type, u64 in_data,
8719 u64 *out_data)
8720{
8721 int return_code;
8722
8723 mutex_lock(&dd->dc8051_lock);
8724 /* We can't send any commands to the 8051 if it's in reset */
8725 if (dd->dc_shutdown) {
8726 return_code = -ENODEV;
8727 goto fail;
8728 }
8729
8730 return_code = _do_8051_command(dd, type, in_data, out_data);
8731
8732fail:
Tadeusz Struk22546b72017-04-28 10:40:02 -07008733 mutex_unlock(&dd->dc8051_lock);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008734 return return_code;
8735}
8736
8737static int set_physical_link_state(struct hfi1_devdata *dd, u64 state)
8738{
8739 return do_8051_command(dd, HCMD_CHANGE_PHY_STATE, state, NULL);
8740}
8741
Sebastian Sanchez7ebfc932017-10-02 11:04:41 -07008742static int _load_8051_config(struct hfi1_devdata *dd, u8 field_id,
8743 u8 lane_id, u32 config_data)
Mike Marciniszyn77241052015-07-30 15:17:43 -04008744{
8745 u64 data;
8746 int ret;
8747
Sebastian Sanchez9be6a5d2017-10-02 11:04:26 -07008748 lockdep_assert_held(&dd->dc8051_lock);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008749 data = (u64)field_id << LOAD_DATA_FIELD_ID_SHIFT
8750 | (u64)lane_id << LOAD_DATA_LANE_ID_SHIFT
8751 | (u64)config_data << LOAD_DATA_DATA_SHIFT;
Sebastian Sanchez9be6a5d2017-10-02 11:04:26 -07008752 ret = _do_8051_command(dd, HCMD_LOAD_CONFIG_DATA, data, NULL);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008753 if (ret != HCMD_SUCCESS) {
8754 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08008755 "load 8051 config: field id %d, lane %d, err %d\n",
8756 (int)field_id, (int)lane_id, ret);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008757 }
8758 return ret;
8759}
8760
Sebastian Sanchez9be6a5d2017-10-02 11:04:26 -07008761int load_8051_config(struct hfi1_devdata *dd, u8 field_id,
8762 u8 lane_id, u32 config_data)
8763{
8764 int return_code;
8765
8766 mutex_lock(&dd->dc8051_lock);
8767 return_code = _load_8051_config(dd, field_id, lane_id, config_data);
8768 mutex_unlock(&dd->dc8051_lock);
8769
8770 return return_code;
8771}
8772
Mike Marciniszyn77241052015-07-30 15:17:43 -04008773/*
8774 * Read the 8051 firmware "registers". Use the RAM directly. Always
8775 * set the result, even on error.
8776 * Return 0 on success, -errno on failure
8777 */
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08008778int read_8051_config(struct hfi1_devdata *dd, u8 field_id, u8 lane_id,
8779 u32 *result)
Mike Marciniszyn77241052015-07-30 15:17:43 -04008780{
8781 u64 big_data;
8782 u32 addr;
8783 int ret;
8784
8785 /* address start depends on the lane_id */
8786 if (lane_id < 4)
8787 addr = (4 * NUM_GENERAL_FIELDS)
8788 + (lane_id * 4 * NUM_LANE_FIELDS);
8789 else
8790 addr = 0;
8791 addr += field_id * 4;
8792
8793 /* read is in 8-byte chunks, hardware will truncate the address down */
8794 ret = read_8051_data(dd, addr, 8, &big_data);
8795
8796 if (ret == 0) {
8797 /* extract the 4 bytes we want */
8798 if (addr & 0x4)
8799 *result = (u32)(big_data >> 32);
8800 else
8801 *result = (u32)big_data;
8802 } else {
8803 *result = 0;
8804 dd_dev_err(dd, "%s: direct read failed, lane %d, field %d!\n",
Jubin John17fb4f22016-02-14 20:21:52 -08008805 __func__, lane_id, field_id);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008806 }
8807
8808 return ret;
8809}
8810
8811static int write_vc_local_phy(struct hfi1_devdata *dd, u8 power_management,
8812 u8 continuous)
8813{
8814 u32 frame;
8815
8816 frame = continuous << CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT
8817 | power_management << POWER_MANAGEMENT_SHIFT;
8818 return load_8051_config(dd, VERIFY_CAP_LOCAL_PHY,
8819 GENERAL_CONFIG, frame);
8820}
8821
8822static int write_vc_local_fabric(struct hfi1_devdata *dd, u8 vau, u8 z, u8 vcu,
8823 u16 vl15buf, u8 crc_sizes)
8824{
8825 u32 frame;
8826
8827 frame = (u32)vau << VAU_SHIFT
8828 | (u32)z << Z_SHIFT
8829 | (u32)vcu << VCU_SHIFT
8830 | (u32)vl15buf << VL15BUF_SHIFT
8831 | (u32)crc_sizes << CRC_SIZES_SHIFT;
8832 return load_8051_config(dd, VERIFY_CAP_LOCAL_FABRIC,
8833 GENERAL_CONFIG, frame);
8834}
8835
8836static void read_vc_local_link_width(struct hfi1_devdata *dd, u8 *misc_bits,
8837 u8 *flag_bits, u16 *link_widths)
8838{
8839 u32 frame;
8840
8841 read_8051_config(dd, VERIFY_CAP_LOCAL_LINK_WIDTH, GENERAL_CONFIG,
Jubin John17fb4f22016-02-14 20:21:52 -08008842 &frame);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008843 *misc_bits = (frame >> MISC_CONFIG_BITS_SHIFT) & MISC_CONFIG_BITS_MASK;
8844 *flag_bits = (frame >> LOCAL_FLAG_BITS_SHIFT) & LOCAL_FLAG_BITS_MASK;
8845 *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
8846}
8847
8848static int write_vc_local_link_width(struct hfi1_devdata *dd,
8849 u8 misc_bits,
8850 u8 flag_bits,
8851 u16 link_widths)
8852{
8853 u32 frame;
8854
8855 frame = (u32)misc_bits << MISC_CONFIG_BITS_SHIFT
8856 | (u32)flag_bits << LOCAL_FLAG_BITS_SHIFT
8857 | (u32)link_widths << LINK_WIDTH_SHIFT;
8858 return load_8051_config(dd, VERIFY_CAP_LOCAL_LINK_WIDTH, GENERAL_CONFIG,
8859 frame);
8860}
8861
8862static int write_local_device_id(struct hfi1_devdata *dd, u16 device_id,
8863 u8 device_rev)
8864{
8865 u32 frame;
8866
8867 frame = ((u32)device_id << LOCAL_DEVICE_ID_SHIFT)
8868 | ((u32)device_rev << LOCAL_DEVICE_REV_SHIFT);
8869 return load_8051_config(dd, LOCAL_DEVICE_ID, GENERAL_CONFIG, frame);
8870}
8871
8872static void read_remote_device_id(struct hfi1_devdata *dd, u16 *device_id,
8873 u8 *device_rev)
8874{
8875 u32 frame;
8876
8877 read_8051_config(dd, REMOTE_DEVICE_ID, GENERAL_CONFIG, &frame);
8878 *device_id = (frame >> REMOTE_DEVICE_ID_SHIFT) & REMOTE_DEVICE_ID_MASK;
8879 *device_rev = (frame >> REMOTE_DEVICE_REV_SHIFT)
8880 & REMOTE_DEVICE_REV_MASK;
8881}
8882
Sebastian Sanchez913cc672017-07-29 08:44:01 -07008883int write_host_interface_version(struct hfi1_devdata *dd, u8 version)
8884{
8885 u32 frame;
8886 u32 mask;
8887
Sebastian Sanchez9be6a5d2017-10-02 11:04:26 -07008888 lockdep_assert_held(&dd->dc8051_lock);
Sebastian Sanchez913cc672017-07-29 08:44:01 -07008889 mask = (HOST_INTERFACE_VERSION_MASK << HOST_INTERFACE_VERSION_SHIFT);
8890 read_8051_config(dd, RESERVED_REGISTERS, GENERAL_CONFIG, &frame);
8891 /* Clear, then set field */
8892 frame &= ~mask;
8893 frame |= ((u32)version << HOST_INTERFACE_VERSION_SHIFT);
Sebastian Sanchez9be6a5d2017-10-02 11:04:26 -07008894 return _load_8051_config(dd, RESERVED_REGISTERS, GENERAL_CONFIG,
8895 frame);
Sebastian Sanchez913cc672017-07-29 08:44:01 -07008896}
8897
Michael J. Ruhl5e6e94242017-03-20 17:25:48 -07008898void read_misc_status(struct hfi1_devdata *dd, u8 *ver_major, u8 *ver_minor,
8899 u8 *ver_patch)
Mike Marciniszyn77241052015-07-30 15:17:43 -04008900{
8901 u32 frame;
8902
8903 read_8051_config(dd, MISC_STATUS, GENERAL_CONFIG, &frame);
Michael J. Ruhl5e6e94242017-03-20 17:25:48 -07008904 *ver_major = (frame >> STS_FM_VERSION_MAJOR_SHIFT) &
8905 STS_FM_VERSION_MAJOR_MASK;
8906 *ver_minor = (frame >> STS_FM_VERSION_MINOR_SHIFT) &
8907 STS_FM_VERSION_MINOR_MASK;
8908
8909 read_8051_config(dd, VERSION_PATCH, GENERAL_CONFIG, &frame);
8910 *ver_patch = (frame >> STS_FM_VERSION_PATCH_SHIFT) &
8911 STS_FM_VERSION_PATCH_MASK;
Mike Marciniszyn77241052015-07-30 15:17:43 -04008912}
8913
8914static void read_vc_remote_phy(struct hfi1_devdata *dd, u8 *power_management,
8915 u8 *continuous)
8916{
8917 u32 frame;
8918
8919 read_8051_config(dd, VERIFY_CAP_REMOTE_PHY, GENERAL_CONFIG, &frame);
8920 *power_management = (frame >> POWER_MANAGEMENT_SHIFT)
8921 & POWER_MANAGEMENT_MASK;
8922 *continuous = (frame >> CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT)
8923 & CONTINIOUS_REMOTE_UPDATE_SUPPORT_MASK;
8924}
8925
8926static void read_vc_remote_fabric(struct hfi1_devdata *dd, u8 *vau, u8 *z,
8927 u8 *vcu, u16 *vl15buf, u8 *crc_sizes)
8928{
8929 u32 frame;
8930
8931 read_8051_config(dd, VERIFY_CAP_REMOTE_FABRIC, GENERAL_CONFIG, &frame);
8932 *vau = (frame >> VAU_SHIFT) & VAU_MASK;
8933 *z = (frame >> Z_SHIFT) & Z_MASK;
8934 *vcu = (frame >> VCU_SHIFT) & VCU_MASK;
8935 *vl15buf = (frame >> VL15BUF_SHIFT) & VL15BUF_MASK;
8936 *crc_sizes = (frame >> CRC_SIZES_SHIFT) & CRC_SIZES_MASK;
8937}
8938
8939static void read_vc_remote_link_width(struct hfi1_devdata *dd,
8940 u8 *remote_tx_rate,
8941 u16 *link_widths)
8942{
8943 u32 frame;
8944
8945 read_8051_config(dd, VERIFY_CAP_REMOTE_LINK_WIDTH, GENERAL_CONFIG,
Jubin John17fb4f22016-02-14 20:21:52 -08008946 &frame);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008947 *remote_tx_rate = (frame >> REMOTE_TX_RATE_SHIFT)
8948 & REMOTE_TX_RATE_MASK;
8949 *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
8950}
8951
8952static void read_local_lni(struct hfi1_devdata *dd, u8 *enable_lane_rx)
8953{
8954 u32 frame;
8955
8956 read_8051_config(dd, LOCAL_LNI_INFO, GENERAL_CONFIG, &frame);
8957 *enable_lane_rx = (frame >> ENABLE_LANE_RX_SHIFT) & ENABLE_LANE_RX_MASK;
8958}
8959
8960static void read_mgmt_allowed(struct hfi1_devdata *dd, u8 *mgmt_allowed)
8961{
8962 u32 frame;
8963
8964 read_8051_config(dd, REMOTE_LNI_INFO, GENERAL_CONFIG, &frame);
8965 *mgmt_allowed = (frame >> MGMT_ALLOWED_SHIFT) & MGMT_ALLOWED_MASK;
8966}
8967
8968static void read_last_local_state(struct hfi1_devdata *dd, u32 *lls)
8969{
8970 read_8051_config(dd, LAST_LOCAL_STATE_COMPLETE, GENERAL_CONFIG, lls);
8971}
8972
8973static void read_last_remote_state(struct hfi1_devdata *dd, u32 *lrs)
8974{
8975 read_8051_config(dd, LAST_REMOTE_STATE_COMPLETE, GENERAL_CONFIG, lrs);
8976}
8977
8978void hfi1_read_link_quality(struct hfi1_devdata *dd, u8 *link_quality)
8979{
8980 u32 frame;
8981 int ret;
8982
8983 *link_quality = 0;
8984 if (dd->pport->host_link_state & HLS_UP) {
8985 ret = read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG,
Jubin John17fb4f22016-02-14 20:21:52 -08008986 &frame);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008987 if (ret == 0)
8988 *link_quality = (frame >> LINK_QUALITY_SHIFT)
8989 & LINK_QUALITY_MASK;
8990 }
8991}
8992
8993static void read_planned_down_reason_code(struct hfi1_devdata *dd, u8 *pdrrc)
8994{
8995 u32 frame;
8996
8997 read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG, &frame);
8998 *pdrrc = (frame >> DOWN_REMOTE_REASON_SHIFT) & DOWN_REMOTE_REASON_MASK;
8999}
9000
Dean Luickfeb831d2016-04-14 08:31:36 -07009001static void read_link_down_reason(struct hfi1_devdata *dd, u8 *ldr)
9002{
9003 u32 frame;
9004
9005 read_8051_config(dd, LINK_DOWN_REASON, GENERAL_CONFIG, &frame);
9006 *ldr = (frame & 0xff);
9007}
9008
Mike Marciniszyn77241052015-07-30 15:17:43 -04009009static int read_tx_settings(struct hfi1_devdata *dd,
9010 u8 *enable_lane_tx,
9011 u8 *tx_polarity_inversion,
9012 u8 *rx_polarity_inversion,
9013 u8 *max_rate)
9014{
9015 u32 frame;
9016 int ret;
9017
9018 ret = read_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, &frame);
9019 *enable_lane_tx = (frame >> ENABLE_LANE_TX_SHIFT)
9020 & ENABLE_LANE_TX_MASK;
9021 *tx_polarity_inversion = (frame >> TX_POLARITY_INVERSION_SHIFT)
9022 & TX_POLARITY_INVERSION_MASK;
9023 *rx_polarity_inversion = (frame >> RX_POLARITY_INVERSION_SHIFT)
9024 & RX_POLARITY_INVERSION_MASK;
9025 *max_rate = (frame >> MAX_RATE_SHIFT) & MAX_RATE_MASK;
9026 return ret;
9027}
9028
9029static int write_tx_settings(struct hfi1_devdata *dd,
9030 u8 enable_lane_tx,
9031 u8 tx_polarity_inversion,
9032 u8 rx_polarity_inversion,
9033 u8 max_rate)
9034{
9035 u32 frame;
9036
9037 /* no need to mask, all variable sizes match field widths */
9038 frame = enable_lane_tx << ENABLE_LANE_TX_SHIFT
9039 | tx_polarity_inversion << TX_POLARITY_INVERSION_SHIFT
9040 | rx_polarity_inversion << RX_POLARITY_INVERSION_SHIFT
9041 | max_rate << MAX_RATE_SHIFT;
9042 return load_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, frame);
9043}
9044
Mike Marciniszyn77241052015-07-30 15:17:43 -04009045/*
9046 * Read an idle LCB message.
9047 *
9048 * Returns 0 on success, -EINVAL on error
9049 */
9050static int read_idle_message(struct hfi1_devdata *dd, u64 type, u64 *data_out)
9051{
9052 int ret;
9053
Jubin John17fb4f22016-02-14 20:21:52 -08009054 ret = do_8051_command(dd, HCMD_READ_LCB_IDLE_MSG, type, data_out);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009055 if (ret != HCMD_SUCCESS) {
9056 dd_dev_err(dd, "read idle message: type %d, err %d\n",
Jubin John17fb4f22016-02-14 20:21:52 -08009057 (u32)type, ret);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009058 return -EINVAL;
9059 }
9060 dd_dev_info(dd, "%s: read idle message 0x%llx\n", __func__, *data_out);
9061 /* return only the payload as we already know the type */
9062 *data_out >>= IDLE_PAYLOAD_SHIFT;
9063 return 0;
9064}
9065
9066/*
9067 * Read an idle SMA message. To be done in response to a notification from
9068 * the 8051.
9069 *
9070 * Returns 0 on success, -EINVAL on error
9071 */
9072static int read_idle_sma(struct hfi1_devdata *dd, u64 *data)
9073{
Jubin John17fb4f22016-02-14 20:21:52 -08009074 return read_idle_message(dd, (u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT,
9075 data);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009076}
9077
9078/*
9079 * Send an idle LCB message.
9080 *
9081 * Returns 0 on success, -EINVAL on error
9082 */
9083static int send_idle_message(struct hfi1_devdata *dd, u64 data)
9084{
9085 int ret;
9086
9087 dd_dev_info(dd, "%s: sending idle message 0x%llx\n", __func__, data);
9088 ret = do_8051_command(dd, HCMD_SEND_LCB_IDLE_MSG, data, NULL);
9089 if (ret != HCMD_SUCCESS) {
9090 dd_dev_err(dd, "send idle message: data 0x%llx, err %d\n",
Jubin John17fb4f22016-02-14 20:21:52 -08009091 data, ret);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009092 return -EINVAL;
9093 }
9094 return 0;
9095}
9096
9097/*
9098 * Send an idle SMA message.
9099 *
9100 * Returns 0 on success, -EINVAL on error
9101 */
9102int send_idle_sma(struct hfi1_devdata *dd, u64 message)
9103{
9104 u64 data;
9105
Jubin John17fb4f22016-02-14 20:21:52 -08009106 data = ((message & IDLE_PAYLOAD_MASK) << IDLE_PAYLOAD_SHIFT) |
9107 ((u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009108 return send_idle_message(dd, data);
9109}
9110
9111/*
9112 * Initialize the LCB then do a quick link up. This may or may not be
9113 * in loopback.
9114 *
9115 * return 0 on success, -errno on error
9116 */
9117static int do_quick_linkup(struct hfi1_devdata *dd)
9118{
Mike Marciniszyn77241052015-07-30 15:17:43 -04009119 int ret;
9120
9121 lcb_shutdown(dd, 0);
9122
9123 if (loopback) {
9124 /* LCB_CFG_LOOPBACK.VAL = 2 */
9125 /* LCB_CFG_LANE_WIDTH.VAL = 0 */
9126 write_csr(dd, DC_LCB_CFG_LOOPBACK,
Jubin John17fb4f22016-02-14 20:21:52 -08009127 IB_PACKET_TYPE << DC_LCB_CFG_LOOPBACK_VAL_SHIFT);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009128 write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
9129 }
9130
9131 /* start the LCBs */
9132 /* LCB_CFG_TX_FIFOS_RESET.VAL = 0 */
9133 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
9134
9135 /* simulator only loopback steps */
9136 if (loopback && dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
9137 /* LCB_CFG_RUN.EN = 1 */
9138 write_csr(dd, DC_LCB_CFG_RUN,
Jubin John17fb4f22016-02-14 20:21:52 -08009139 1ull << DC_LCB_CFG_RUN_EN_SHIFT);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009140
Dean Luickec8a1422017-03-20 17:24:39 -07009141 ret = wait_link_transfer_active(dd, 10);
9142 if (ret)
9143 return ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -04009144
9145 write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP,
Jubin John17fb4f22016-02-14 20:21:52 -08009146 1ull << DC_LCB_CFG_ALLOW_LINK_UP_VAL_SHIFT);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009147 }
9148
9149 if (!loopback) {
9150 /*
9151 * When doing quick linkup and not in loopback, both
9152 * sides must be done with LCB set-up before either
9153 * starts the quick linkup. Put a delay here so that
9154 * both sides can be started and have a chance to be
9155 * done with LCB set up before resuming.
9156 */
9157 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08009158 "Pausing for peer to be finished with LCB set up\n");
Mike Marciniszyn77241052015-07-30 15:17:43 -04009159 msleep(5000);
Jubin John17fb4f22016-02-14 20:21:52 -08009160 dd_dev_err(dd, "Continuing with quick linkup\n");
Mike Marciniszyn77241052015-07-30 15:17:43 -04009161 }
9162
9163 write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
9164 set_8051_lcb_access(dd);
9165
9166 /*
9167 * State "quick" LinkUp request sets the physical link state to
9168 * LinkUp without a verify capability sequence.
9169 * This state is in simulator v37 and later.
9170 */
9171 ret = set_physical_link_state(dd, PLS_QUICK_LINKUP);
9172 if (ret != HCMD_SUCCESS) {
9173 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08009174 "%s: set physical link state to quick LinkUp failed with return %d\n",
9175 __func__, ret);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009176
9177 set_host_lcb_access(dd);
9178 write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
9179
9180 if (ret >= 0)
9181 ret = -EINVAL;
9182 return ret;
9183 }
9184
9185 return 0; /* success */
9186}
9187
9188/*
9189 * Set the SerDes to internal loopback mode.
9190 * Returns 0 on success, -errno on error.
9191 */
9192static int set_serdes_loopback_mode(struct hfi1_devdata *dd)
9193{
9194 int ret;
9195
9196 ret = set_physical_link_state(dd, PLS_INTERNAL_SERDES_LOOPBACK);
9197 if (ret == HCMD_SUCCESS)
9198 return 0;
9199 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08009200 "Set physical link state to SerDes Loopback failed with return %d\n",
9201 ret);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009202 if (ret >= 0)
9203 ret = -EINVAL;
9204 return ret;
9205}
9206
9207/*
9208 * Do all special steps to set up loopback.
9209 */
9210static int init_loopback(struct hfi1_devdata *dd)
9211{
9212 dd_dev_info(dd, "Entering loopback mode\n");
9213
9214 /* all loopbacks should disable self GUID check */
9215 write_csr(dd, DC_DC8051_CFG_MODE,
Jubin John17fb4f22016-02-14 20:21:52 -08009216 (read_csr(dd, DC_DC8051_CFG_MODE) | DISABLE_SELF_GUID_CHECK));
Mike Marciniszyn77241052015-07-30 15:17:43 -04009217
9218 /*
9219 * The simulator has only one loopback option - LCB. Switch
9220 * to that option, which includes quick link up.
9221 *
9222 * Accept all valid loopback values.
9223 */
Jubin Johnd0d236e2016-02-14 20:20:15 -08009224 if ((dd->icode == ICODE_FUNCTIONAL_SIMULATOR) &&
9225 (loopback == LOOPBACK_SERDES || loopback == LOOPBACK_LCB ||
9226 loopback == LOOPBACK_CABLE)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04009227 loopback = LOOPBACK_LCB;
9228 quick_linkup = 1;
9229 return 0;
9230 }
9231
9232 /* handle serdes loopback */
9233 if (loopback == LOOPBACK_SERDES) {
9234 /* internal serdes loopack needs quick linkup on RTL */
9235 if (dd->icode == ICODE_RTL_SILICON)
9236 quick_linkup = 1;
9237 return set_serdes_loopback_mode(dd);
9238 }
9239
9240 /* LCB loopback - handled at poll time */
9241 if (loopback == LOOPBACK_LCB) {
9242 quick_linkup = 1; /* LCB is always quick linkup */
9243
9244 /* not supported in emulation due to emulation RTL changes */
9245 if (dd->icode == ICODE_FPGA_EMULATION) {
9246 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08009247 "LCB loopback not supported in emulation\n");
Mike Marciniszyn77241052015-07-30 15:17:43 -04009248 return -EINVAL;
9249 }
9250 return 0;
9251 }
9252
9253 /* external cable loopback requires no extra steps */
9254 if (loopback == LOOPBACK_CABLE)
9255 return 0;
9256
9257 dd_dev_err(dd, "Invalid loopback mode %d\n", loopback);
9258 return -EINVAL;
9259}
9260
9261/*
9262 * Translate from the OPA_LINK_WIDTH handed to us by the FM to bits
9263 * used in the Verify Capability link width attribute.
9264 */
9265static u16 opa_to_vc_link_widths(u16 opa_widths)
9266{
9267 int i;
9268 u16 result = 0;
9269
9270 static const struct link_bits {
9271 u16 from;
9272 u16 to;
9273 } opa_link_xlate[] = {
Jubin John8638b772016-02-14 20:19:24 -08009274 { OPA_LINK_WIDTH_1X, 1 << (1 - 1) },
9275 { OPA_LINK_WIDTH_2X, 1 << (2 - 1) },
9276 { OPA_LINK_WIDTH_3X, 1 << (3 - 1) },
9277 { OPA_LINK_WIDTH_4X, 1 << (4 - 1) },
Mike Marciniszyn77241052015-07-30 15:17:43 -04009278 };
9279
9280 for (i = 0; i < ARRAY_SIZE(opa_link_xlate); i++) {
9281 if (opa_widths & opa_link_xlate[i].from)
9282 result |= opa_link_xlate[i].to;
9283 }
9284 return result;
9285}
9286
9287/*
9288 * Set link attributes before moving to polling.
9289 */
9290static int set_local_link_attributes(struct hfi1_pportdata *ppd)
9291{
9292 struct hfi1_devdata *dd = ppd->dd;
9293 u8 enable_lane_tx;
9294 u8 tx_polarity_inversion;
9295 u8 rx_polarity_inversion;
9296 int ret;
9297
9298 /* reset our fabric serdes to clear any lingering problems */
9299 fabric_serdes_reset(dd);
9300
9301 /* set the local tx rate - need to read-modify-write */
9302 ret = read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
Jubin John17fb4f22016-02-14 20:21:52 -08009303 &rx_polarity_inversion, &ppd->local_tx_rate);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009304 if (ret)
9305 goto set_local_link_attributes_fail;
9306
Michael J. Ruhl5e6e94242017-03-20 17:25:48 -07009307 if (dd->dc8051_ver < dc8051_ver(0, 20, 0)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04009308 /* set the tx rate to the fastest enabled */
9309 if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
9310 ppd->local_tx_rate = 1;
9311 else
9312 ppd->local_tx_rate = 0;
9313 } else {
9314 /* set the tx rate to all enabled */
9315 ppd->local_tx_rate = 0;
9316 if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
9317 ppd->local_tx_rate |= 2;
9318 if (ppd->link_speed_enabled & OPA_LINK_SPEED_12_5G)
9319 ppd->local_tx_rate |= 1;
9320 }
Easwar Hariharanfebffe22015-10-26 10:28:36 -04009321
9322 enable_lane_tx = 0xF; /* enable all four lanes */
Mike Marciniszyn77241052015-07-30 15:17:43 -04009323 ret = write_tx_settings(dd, enable_lane_tx, tx_polarity_inversion,
Jubin John17fb4f22016-02-14 20:21:52 -08009324 rx_polarity_inversion, ppd->local_tx_rate);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009325 if (ret != HCMD_SUCCESS)
9326 goto set_local_link_attributes_fail;
9327
9328 /*
9329 * DC supports continuous updates.
9330 */
Jubin John17fb4f22016-02-14 20:21:52 -08009331 ret = write_vc_local_phy(dd,
9332 0 /* no power management */,
9333 1 /* continuous updates */);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009334 if (ret != HCMD_SUCCESS)
9335 goto set_local_link_attributes_fail;
9336
9337 /* z=1 in the next call: AU of 0 is not supported by the hardware */
9338 ret = write_vc_local_fabric(dd, dd->vau, 1, dd->vcu, dd->vl15_init,
9339 ppd->port_crc_mode_enabled);
9340 if (ret != HCMD_SUCCESS)
9341 goto set_local_link_attributes_fail;
9342
9343 ret = write_vc_local_link_width(dd, 0, 0,
Jubin John17fb4f22016-02-14 20:21:52 -08009344 opa_to_vc_link_widths(
9345 ppd->link_width_enabled));
Mike Marciniszyn77241052015-07-30 15:17:43 -04009346 if (ret != HCMD_SUCCESS)
9347 goto set_local_link_attributes_fail;
9348
9349 /* let peer know who we are */
9350 ret = write_local_device_id(dd, dd->pcidev->device, dd->minrev);
9351 if (ret == HCMD_SUCCESS)
9352 return 0;
9353
9354set_local_link_attributes_fail:
9355 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08009356 "Failed to set local link attributes, return 0x%x\n",
9357 ret);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009358 return ret;
9359}
9360
9361/*
Easwar Hariharan623bba22016-04-12 11:25:57 -07009362 * Call this to start the link.
9363 * Do not do anything if the link is disabled.
9364 * Returns 0 if link is disabled, moved to polling, or the driver is not ready.
Mike Marciniszyn77241052015-07-30 15:17:43 -04009365 */
9366int start_link(struct hfi1_pportdata *ppd)
9367{
Dean Luick0db9dec2016-09-06 04:35:20 -07009368 /*
9369 * Tune the SerDes to a ballpark setting for optimal signal and bit
9370 * error rate. Needs to be done before starting the link.
9371 */
9372 tune_serdes(ppd);
9373
Mike Marciniszyn77241052015-07-30 15:17:43 -04009374 if (!ppd->driver_link_ready) {
9375 dd_dev_info(ppd->dd,
Jubin John17fb4f22016-02-14 20:21:52 -08009376 "%s: stopping link start because driver is not ready\n",
9377 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009378 return 0;
9379 }
9380
Sebastian Sanchez3ec5fa22016-06-09 07:51:57 -07009381 /*
9382 * FULL_MGMT_P_KEY is cleared from the pkey table, so that the
9383 * pkey table can be configured properly if the HFI unit is connected
9384 * to switch port with MgmtAllowed=NO
9385 */
9386 clear_full_mgmt_pkey(ppd);
9387
Easwar Hariharan623bba22016-04-12 11:25:57 -07009388 return set_link_state(ppd, HLS_DN_POLL);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009389}
9390
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009391static void wait_for_qsfp_init(struct hfi1_pportdata *ppd)
9392{
9393 struct hfi1_devdata *dd = ppd->dd;
9394 u64 mask;
9395 unsigned long timeout;
9396
9397 /*
Easwar Hariharan5fbd98d2016-07-25 13:39:57 -07009398 * Some QSFP cables have a quirk that asserts the IntN line as a side
9399 * effect of power up on plug-in. We ignore this false positive
9400 * interrupt until the module has finished powering up by waiting for
9401 * a minimum timeout of the module inrush initialization time of
9402 * 500 ms (SFF 8679 Table 5-6) to ensure the voltage rails in the
9403 * module have stabilized.
9404 */
9405 msleep(500);
9406
9407 /*
9408 * Check for QSFP interrupt for t_init (SFF 8679 Table 8-1)
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009409 */
9410 timeout = jiffies + msecs_to_jiffies(2000);
9411 while (1) {
9412 mask = read_csr(dd, dd->hfi1_id ?
9413 ASIC_QSFP2_IN : ASIC_QSFP1_IN);
Easwar Hariharan5fbd98d2016-07-25 13:39:57 -07009414 if (!(mask & QSFP_HFI0_INT_N))
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009415 break;
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009416 if (time_after(jiffies, timeout)) {
9417 dd_dev_info(dd, "%s: No IntN detected, reset complete\n",
9418 __func__);
9419 break;
9420 }
9421 udelay(2);
9422 }
9423}
9424
9425static void set_qsfp_int_n(struct hfi1_pportdata *ppd, u8 enable)
9426{
9427 struct hfi1_devdata *dd = ppd->dd;
9428 u64 mask;
9429
9430 mask = read_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK);
Easwar Hariharan5fbd98d2016-07-25 13:39:57 -07009431 if (enable) {
9432 /*
9433 * Clear the status register to avoid an immediate interrupt
9434 * when we re-enable the IntN pin
9435 */
9436 write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR : ASIC_QSFP1_CLEAR,
9437 QSFP_HFI0_INT_N);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009438 mask |= (u64)QSFP_HFI0_INT_N;
Easwar Hariharan5fbd98d2016-07-25 13:39:57 -07009439 } else {
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009440 mask &= ~(u64)QSFP_HFI0_INT_N;
Easwar Hariharan5fbd98d2016-07-25 13:39:57 -07009441 }
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009442 write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK, mask);
9443}
9444
9445void reset_qsfp(struct hfi1_pportdata *ppd)
Mike Marciniszyn77241052015-07-30 15:17:43 -04009446{
9447 struct hfi1_devdata *dd = ppd->dd;
9448 u64 mask, qsfp_mask;
9449
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009450 /* Disable INT_N from triggering QSFP interrupts */
9451 set_qsfp_int_n(ppd, 0);
9452
9453 /* Reset the QSFP */
Mike Marciniszyn77241052015-07-30 15:17:43 -04009454 mask = (u64)QSFP_HFI0_RESET_N;
Mike Marciniszyn77241052015-07-30 15:17:43 -04009455
9456 qsfp_mask = read_csr(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08009457 dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009458 qsfp_mask &= ~mask;
9459 write_csr(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08009460 dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009461
9462 udelay(10);
9463
9464 qsfp_mask |= mask;
9465 write_csr(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08009466 dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT, qsfp_mask);
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009467
9468 wait_for_qsfp_init(ppd);
9469
9470 /*
9471 * Allow INT_N to trigger the QSFP interrupt to watch
9472 * for alarms and warnings
9473 */
9474 set_qsfp_int_n(ppd, 1);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009475}
9476
9477static int handle_qsfp_error_conditions(struct hfi1_pportdata *ppd,
9478 u8 *qsfp_interrupt_status)
9479{
9480 struct hfi1_devdata *dd = ppd->dd;
9481
9482 if ((qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009483 (qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009484 dd_dev_err(dd, "%s: QSFP cable temperature too high\n",
9485 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009486
9487 if ((qsfp_interrupt_status[0] & QSFP_LOW_TEMP_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009488 (qsfp_interrupt_status[0] & QSFP_LOW_TEMP_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009489 dd_dev_err(dd, "%s: QSFP cable temperature too low\n",
9490 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009491
Easwar Hariharan0c7f77a2016-05-12 10:22:33 -07009492 /*
9493 * The remaining alarms/warnings don't matter if the link is down.
9494 */
9495 if (ppd->host_link_state & HLS_DOWN)
9496 return 0;
9497
Mike Marciniszyn77241052015-07-30 15:17:43 -04009498 if ((qsfp_interrupt_status[1] & QSFP_HIGH_VCC_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009499 (qsfp_interrupt_status[1] & QSFP_HIGH_VCC_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009500 dd_dev_err(dd, "%s: QSFP supply voltage too high\n",
9501 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009502
9503 if ((qsfp_interrupt_status[1] & QSFP_LOW_VCC_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009504 (qsfp_interrupt_status[1] & QSFP_LOW_VCC_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009505 dd_dev_err(dd, "%s: QSFP supply voltage too low\n",
9506 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009507
9508 /* Byte 2 is vendor specific */
9509
9510 if ((qsfp_interrupt_status[3] & QSFP_HIGH_POWER_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009511 (qsfp_interrupt_status[3] & QSFP_HIGH_POWER_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009512 dd_dev_err(dd, "%s: Cable RX channel 1/2 power too high\n",
9513 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009514
9515 if ((qsfp_interrupt_status[3] & QSFP_LOW_POWER_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009516 (qsfp_interrupt_status[3] & QSFP_LOW_POWER_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009517 dd_dev_err(dd, "%s: Cable RX channel 1/2 power too low\n",
9518 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009519
9520 if ((qsfp_interrupt_status[4] & QSFP_HIGH_POWER_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009521 (qsfp_interrupt_status[4] & QSFP_HIGH_POWER_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009522 dd_dev_err(dd, "%s: Cable RX channel 3/4 power too high\n",
9523 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009524
9525 if ((qsfp_interrupt_status[4] & QSFP_LOW_POWER_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009526 (qsfp_interrupt_status[4] & QSFP_LOW_POWER_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009527 dd_dev_err(dd, "%s: Cable RX channel 3/4 power too low\n",
9528 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009529
9530 if ((qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009531 (qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009532 dd_dev_err(dd, "%s: Cable TX channel 1/2 bias too high\n",
9533 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009534
9535 if ((qsfp_interrupt_status[5] & QSFP_LOW_BIAS_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009536 (qsfp_interrupt_status[5] & QSFP_LOW_BIAS_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009537 dd_dev_err(dd, "%s: Cable TX channel 1/2 bias too low\n",
9538 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009539
9540 if ((qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009541 (qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009542 dd_dev_err(dd, "%s: Cable TX channel 3/4 bias too high\n",
9543 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009544
9545 if ((qsfp_interrupt_status[6] & QSFP_LOW_BIAS_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009546 (qsfp_interrupt_status[6] & QSFP_LOW_BIAS_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009547 dd_dev_err(dd, "%s: Cable TX channel 3/4 bias too low\n",
9548 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009549
9550 if ((qsfp_interrupt_status[7] & QSFP_HIGH_POWER_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009551 (qsfp_interrupt_status[7] & QSFP_HIGH_POWER_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009552 dd_dev_err(dd, "%s: Cable TX channel 1/2 power too high\n",
9553 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009554
9555 if ((qsfp_interrupt_status[7] & QSFP_LOW_POWER_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009556 (qsfp_interrupt_status[7] & QSFP_LOW_POWER_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009557 dd_dev_err(dd, "%s: Cable TX channel 1/2 power too low\n",
9558 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009559
9560 if ((qsfp_interrupt_status[8] & QSFP_HIGH_POWER_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009561 (qsfp_interrupt_status[8] & QSFP_HIGH_POWER_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009562 dd_dev_err(dd, "%s: Cable TX channel 3/4 power too high\n",
9563 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009564
9565 if ((qsfp_interrupt_status[8] & QSFP_LOW_POWER_ALARM) ||
Jubin John17fb4f22016-02-14 20:21:52 -08009566 (qsfp_interrupt_status[8] & QSFP_LOW_POWER_WARNING))
Jan Sokolowski702265f2017-06-09 15:59:33 -07009567 dd_dev_err(dd, "%s: Cable TX channel 3/4 power too low\n",
9568 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009569
9570 /* Bytes 9-10 and 11-12 are reserved */
9571 /* Bytes 13-15 are vendor specific */
9572
9573 return 0;
9574}
9575
Easwar Hariharan623bba22016-04-12 11:25:57 -07009576/* This routine will only be scheduled if the QSFP module present is asserted */
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009577void qsfp_event(struct work_struct *work)
Mike Marciniszyn77241052015-07-30 15:17:43 -04009578{
9579 struct qsfp_data *qd;
9580 struct hfi1_pportdata *ppd;
9581 struct hfi1_devdata *dd;
9582
9583 qd = container_of(work, struct qsfp_data, qsfp_work);
9584 ppd = qd->ppd;
9585 dd = ppd->dd;
9586
9587 /* Sanity check */
9588 if (!qsfp_mod_present(ppd))
9589 return;
9590
Jan Sokolowski96603ed2017-07-29 08:43:26 -07009591 if (ppd->host_link_state == HLS_DN_DISABLE) {
9592 dd_dev_info(ppd->dd,
9593 "%s: stopping link start because link is disabled\n",
9594 __func__);
9595 return;
9596 }
9597
Mike Marciniszyn77241052015-07-30 15:17:43 -04009598 /*
Easwar Hariharan0c7f77a2016-05-12 10:22:33 -07009599 * Turn DC back on after cable has been re-inserted. Up until
9600 * now, the DC has been in reset to save power.
Mike Marciniszyn77241052015-07-30 15:17:43 -04009601 */
9602 dc_start(dd);
9603
9604 if (qd->cache_refresh_required) {
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009605 set_qsfp_int_n(ppd, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009606
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009607 wait_for_qsfp_init(ppd);
9608
9609 /*
9610 * Allow INT_N to trigger the QSFP interrupt to watch
9611 * for alarms and warnings
Mike Marciniszyn77241052015-07-30 15:17:43 -04009612 */
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009613 set_qsfp_int_n(ppd, 1);
9614
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009615 start_link(ppd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009616 }
9617
9618 if (qd->check_interrupt_flags) {
9619 u8 qsfp_interrupt_status[16] = {0,};
9620
Dean Luick765a6fa2016-03-05 08:50:06 -08009621 if (one_qsfp_read(ppd, dd->hfi1_id, 6,
9622 &qsfp_interrupt_status[0], 16) != 16) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04009623 dd_dev_info(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08009624 "%s: Failed to read status of QSFP module\n",
9625 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009626 } else {
9627 unsigned long flags;
Mike Marciniszyn77241052015-07-30 15:17:43 -04009628
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009629 handle_qsfp_error_conditions(
9630 ppd, qsfp_interrupt_status);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009631 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
9632 ppd->qsfp_info.check_interrupt_flags = 0;
9633 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
Jubin John17fb4f22016-02-14 20:21:52 -08009634 flags);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009635 }
9636 }
9637}
9638
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009639static void init_qsfp_int(struct hfi1_devdata *dd)
Mike Marciniszyn77241052015-07-30 15:17:43 -04009640{
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009641 struct hfi1_pportdata *ppd = dd->pport;
9642 u64 qsfp_mask, cce_int_mask;
9643 const int qsfp1_int_smask = QSFP1_INT % 64;
9644 const int qsfp2_int_smask = QSFP2_INT % 64;
Mike Marciniszyn77241052015-07-30 15:17:43 -04009645
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009646 /*
9647 * disable QSFP1 interrupts for HFI1, QSFP2 interrupts for HFI0
9648 * Qsfp1Int and Qsfp2Int are adjacent bits in the same CSR,
9649 * therefore just one of QSFP1_INT/QSFP2_INT can be used to find
9650 * the index of the appropriate CSR in the CCEIntMask CSR array
9651 */
9652 cce_int_mask = read_csr(dd, CCE_INT_MASK +
9653 (8 * (QSFP1_INT / 64)));
9654 if (dd->hfi1_id) {
9655 cce_int_mask &= ~((u64)1 << qsfp1_int_smask);
9656 write_csr(dd, CCE_INT_MASK + (8 * (QSFP1_INT / 64)),
9657 cce_int_mask);
9658 } else {
9659 cce_int_mask &= ~((u64)1 << qsfp2_int_smask);
9660 write_csr(dd, CCE_INT_MASK + (8 * (QSFP2_INT / 64)),
9661 cce_int_mask);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009662 }
9663
Mike Marciniszyn77241052015-07-30 15:17:43 -04009664 qsfp_mask = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
9665 /* Clear current status to avoid spurious interrupts */
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009666 write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_CLEAR : ASIC_QSFP1_CLEAR,
9667 qsfp_mask);
9668 write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK,
9669 qsfp_mask);
9670
9671 set_qsfp_int_n(ppd, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009672
9673 /* Handle active low nature of INT_N and MODPRST_N pins */
9674 if (qsfp_mod_present(ppd))
9675 qsfp_mask &= ~(u64)QSFP_HFI0_MODPRST_N;
9676 write_csr(dd,
9677 dd->hfi1_id ? ASIC_QSFP2_INVERT : ASIC_QSFP1_INVERT,
9678 qsfp_mask);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009679}
9680
Dean Luickbbdeb332015-12-01 15:38:15 -05009681/*
9682 * Do a one-time initialize of the LCB block.
9683 */
9684static void init_lcb(struct hfi1_devdata *dd)
9685{
Dean Luicka59329d2016-02-03 14:32:31 -08009686 /* simulator does not correctly handle LCB cclk loopback, skip */
9687 if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
9688 return;
9689
Dean Luickbbdeb332015-12-01 15:38:15 -05009690 /* the DC has been reset earlier in the driver load */
9691
9692 /* set LCB for cclk loopback on the port */
9693 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x01);
9694 write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0x00);
9695 write_csr(dd, DC_LCB_CFG_REINIT_AS_SLAVE, 0x00);
9696 write_csr(dd, DC_LCB_CFG_CNT_FOR_SKIP_STALL, 0x110);
9697 write_csr(dd, DC_LCB_CFG_CLK_CNTR, 0x08);
9698 write_csr(dd, DC_LCB_CFG_LOOPBACK, 0x02);
9699 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x00);
9700}
9701
Dean Luick673b9752016-08-31 07:24:33 -07009702/*
9703 * Perform a test read on the QSFP. Return 0 on success, -ERRNO
9704 * on error.
9705 */
9706static int test_qsfp_read(struct hfi1_pportdata *ppd)
9707{
9708 int ret;
9709 u8 status;
9710
Easwar Hariharanfb897ad2017-03-20 17:25:42 -07009711 /*
9712 * Report success if not a QSFP or, if it is a QSFP, but the cable is
9713 * not present
9714 */
9715 if (ppd->port_type != PORT_TYPE_QSFP || !qsfp_mod_present(ppd))
Dean Luick673b9752016-08-31 07:24:33 -07009716 return 0;
9717
9718 /* read byte 2, the status byte */
9719 ret = one_qsfp_read(ppd, ppd->dd->hfi1_id, 2, &status, 1);
9720 if (ret < 0)
9721 return ret;
9722 if (ret != 1)
9723 return -EIO;
9724
9725 return 0; /* success */
9726}
9727
9728/*
9729 * Values for QSFP retry.
9730 *
9731 * Give up after 10s (20 x 500ms). The overall timeout was empirically
9732 * arrived at from experience on a large cluster.
9733 */
9734#define MAX_QSFP_RETRIES 20
9735#define QSFP_RETRY_WAIT 500 /* msec */
9736
9737/*
9738 * Try a QSFP read. If it fails, schedule a retry for later.
9739 * Called on first link activation after driver load.
9740 */
9741static void try_start_link(struct hfi1_pportdata *ppd)
9742{
9743 if (test_qsfp_read(ppd)) {
9744 /* read failed */
9745 if (ppd->qsfp_retry_count >= MAX_QSFP_RETRIES) {
9746 dd_dev_err(ppd->dd, "QSFP not responding, giving up\n");
9747 return;
9748 }
9749 dd_dev_info(ppd->dd,
9750 "QSFP not responding, waiting and retrying %d\n",
9751 (int)ppd->qsfp_retry_count);
9752 ppd->qsfp_retry_count++;
Sebastian Sanchez71d47002017-07-29 08:43:49 -07009753 queue_delayed_work(ppd->link_wq, &ppd->start_link_work,
Dean Luick673b9752016-08-31 07:24:33 -07009754 msecs_to_jiffies(QSFP_RETRY_WAIT));
9755 return;
9756 }
9757 ppd->qsfp_retry_count = 0;
9758
Dean Luick673b9752016-08-31 07:24:33 -07009759 start_link(ppd);
9760}
9761
9762/*
9763 * Workqueue function to start the link after a delay.
9764 */
9765void handle_start_link(struct work_struct *work)
9766{
9767 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
9768 start_link_work.work);
9769 try_start_link(ppd);
9770}
9771
Mike Marciniszyn77241052015-07-30 15:17:43 -04009772int bringup_serdes(struct hfi1_pportdata *ppd)
9773{
9774 struct hfi1_devdata *dd = ppd->dd;
9775 u64 guid;
9776 int ret;
9777
9778 if (HFI1_CAP_IS_KSET(EXTENDED_PSN))
9779 add_rcvctrl(dd, RCV_CTRL_RCV_EXTENDED_PSN_ENABLE_SMASK);
9780
Jakub Pawlaka6cd5f02016-10-17 04:19:30 -07009781 guid = ppd->guids[HFI1_PORT_GUID_INDEX];
Mike Marciniszyn77241052015-07-30 15:17:43 -04009782 if (!guid) {
9783 if (dd->base_guid)
9784 guid = dd->base_guid + ppd->port - 1;
Jakub Pawlaka6cd5f02016-10-17 04:19:30 -07009785 ppd->guids[HFI1_PORT_GUID_INDEX] = guid;
Mike Marciniszyn77241052015-07-30 15:17:43 -04009786 }
9787
Mike Marciniszyn77241052015-07-30 15:17:43 -04009788 /* Set linkinit_reason on power up per OPA spec */
9789 ppd->linkinit_reason = OPA_LINKINIT_REASON_LINKUP;
9790
Dean Luickbbdeb332015-12-01 15:38:15 -05009791 /* one-time init of the LCB */
9792 init_lcb(dd);
9793
Mike Marciniszyn77241052015-07-30 15:17:43 -04009794 if (loopback) {
9795 ret = init_loopback(dd);
9796 if (ret < 0)
9797 return ret;
9798 }
9799
Easwar Hariharan9775a992016-05-12 10:22:39 -07009800 get_port_type(ppd);
9801 if (ppd->port_type == PORT_TYPE_QSFP) {
9802 set_qsfp_int_n(ppd, 0);
9803 wait_for_qsfp_init(ppd);
9804 set_qsfp_int_n(ppd, 1);
9805 }
9806
Dean Luick673b9752016-08-31 07:24:33 -07009807 try_start_link(ppd);
9808 return 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04009809}
9810
9811void hfi1_quiet_serdes(struct hfi1_pportdata *ppd)
9812{
9813 struct hfi1_devdata *dd = ppd->dd;
9814
9815 /*
9816 * Shut down the link and keep it down. First turn off that the
9817 * driver wants to allow the link to be up (driver_link_ready).
9818 * Then make sure the link is not automatically restarted
9819 * (link_enabled). Cancel any pending restart. And finally
9820 * go offline.
9821 */
9822 ppd->driver_link_ready = 0;
9823 ppd->link_enabled = 0;
9824
Dean Luick673b9752016-08-31 07:24:33 -07009825 ppd->qsfp_retry_count = MAX_QSFP_RETRIES; /* prevent more retries */
9826 flush_delayed_work(&ppd->start_link_work);
9827 cancel_delayed_work_sync(&ppd->start_link_work);
9828
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -08009829 ppd->offline_disabled_reason =
9830 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009831 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SMA_DISABLED, 0,
Jubin John17fb4f22016-02-14 20:21:52 -08009832 OPA_LINKDOWN_REASON_SMA_DISABLED);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009833 set_link_state(ppd, HLS_DN_OFFLINE);
9834
9835 /* disable the port */
9836 clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
9837}
9838
9839static inline int init_cpu_counters(struct hfi1_devdata *dd)
9840{
9841 struct hfi1_pportdata *ppd;
9842 int i;
9843
9844 ppd = (struct hfi1_pportdata *)(dd + 1);
9845 for (i = 0; i < dd->num_pports; i++, ppd++) {
Dennis Dalessandro4eb06882016-01-19 14:42:39 -08009846 ppd->ibport_data.rvp.rc_acks = NULL;
9847 ppd->ibport_data.rvp.rc_qacks = NULL;
9848 ppd->ibport_data.rvp.rc_acks = alloc_percpu(u64);
9849 ppd->ibport_data.rvp.rc_qacks = alloc_percpu(u64);
9850 ppd->ibport_data.rvp.rc_delayed_comp = alloc_percpu(u64);
9851 if (!ppd->ibport_data.rvp.rc_acks ||
9852 !ppd->ibport_data.rvp.rc_delayed_comp ||
9853 !ppd->ibport_data.rvp.rc_qacks)
Mike Marciniszyn77241052015-07-30 15:17:43 -04009854 return -ENOMEM;
9855 }
9856
9857 return 0;
9858}
9859
Mike Marciniszyn77241052015-07-30 15:17:43 -04009860/*
9861 * index is the index into the receive array
9862 */
9863void hfi1_put_tid(struct hfi1_devdata *dd, u32 index,
9864 u32 type, unsigned long pa, u16 order)
9865{
9866 u64 reg;
Mike Marciniszyn77241052015-07-30 15:17:43 -04009867
9868 if (!(dd->flags & HFI1_PRESENT))
9869 goto done;
9870
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -07009871 if (type == PT_INVALID || type == PT_INVALID_FLUSH) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04009872 pa = 0;
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -07009873 order = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04009874 } else if (type > PT_INVALID) {
9875 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08009876 "unexpected receive array type %u for index %u, not handled\n",
9877 type, index);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009878 goto done;
9879 }
Mike Marciniszyn8cb10212017-06-09 15:59:59 -07009880 trace_hfi1_put_tid(dd, index, type, pa, order);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009881
9882#define RT_ADDR_SHIFT 12 /* 4KB kernel address boundary */
9883 reg = RCV_ARRAY_RT_WRITE_ENABLE_SMASK
9884 | (u64)order << RCV_ARRAY_RT_BUF_SIZE_SHIFT
9885 | ((pa >> RT_ADDR_SHIFT) & RCV_ARRAY_RT_ADDR_MASK)
9886 << RCV_ARRAY_RT_ADDR_SHIFT;
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -07009887 trace_hfi1_write_rcvarray(dd->rcvarray_wc + (index * 8), reg);
9888 writeq(reg, dd->rcvarray_wc + (index * 8));
Mike Marciniszyn77241052015-07-30 15:17:43 -04009889
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -07009890 if (type == PT_EAGER || type == PT_INVALID_FLUSH || (index & 3) == 3)
Mike Marciniszyn77241052015-07-30 15:17:43 -04009891 /*
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -07009892 * Eager entries are written and flushed
9893 *
9894 * Expected entries are flushed every 4 writes
Mike Marciniszyn77241052015-07-30 15:17:43 -04009895 */
9896 flush_wc();
9897done:
9898 return;
9899}
9900
9901void hfi1_clear_tids(struct hfi1_ctxtdata *rcd)
9902{
9903 struct hfi1_devdata *dd = rcd->dd;
9904 u32 i;
9905
9906 /* this could be optimized */
9907 for (i = rcd->eager_base; i < rcd->eager_base +
9908 rcd->egrbufs.alloced; i++)
9909 hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
9910
9911 for (i = rcd->expected_base;
9912 i < rcd->expected_base + rcd->expected_count; i++)
9913 hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
9914}
9915
Mike Marciniszyn77241052015-07-30 15:17:43 -04009916static const char * const ib_cfg_name_strings[] = {
9917 "HFI1_IB_CFG_LIDLMC",
9918 "HFI1_IB_CFG_LWID_DG_ENB",
9919 "HFI1_IB_CFG_LWID_ENB",
9920 "HFI1_IB_CFG_LWID",
9921 "HFI1_IB_CFG_SPD_ENB",
9922 "HFI1_IB_CFG_SPD",
9923 "HFI1_IB_CFG_RXPOL_ENB",
9924 "HFI1_IB_CFG_LREV_ENB",
9925 "HFI1_IB_CFG_LINKLATENCY",
9926 "HFI1_IB_CFG_HRTBT",
9927 "HFI1_IB_CFG_OP_VLS",
9928 "HFI1_IB_CFG_VL_HIGH_CAP",
9929 "HFI1_IB_CFG_VL_LOW_CAP",
9930 "HFI1_IB_CFG_OVERRUN_THRESH",
9931 "HFI1_IB_CFG_PHYERR_THRESH",
9932 "HFI1_IB_CFG_LINKDEFAULT",
9933 "HFI1_IB_CFG_PKEYS",
9934 "HFI1_IB_CFG_MTU",
9935 "HFI1_IB_CFG_LSTATE",
9936 "HFI1_IB_CFG_VL_HIGH_LIMIT",
9937 "HFI1_IB_CFG_PMA_TICKS",
9938 "HFI1_IB_CFG_PORT"
9939};
9940
9941static const char *ib_cfg_name(int which)
9942{
9943 if (which < 0 || which >= ARRAY_SIZE(ib_cfg_name_strings))
9944 return "invalid";
9945 return ib_cfg_name_strings[which];
9946}
9947
9948int hfi1_get_ib_cfg(struct hfi1_pportdata *ppd, int which)
9949{
9950 struct hfi1_devdata *dd = ppd->dd;
9951 int val = 0;
9952
9953 switch (which) {
9954 case HFI1_IB_CFG_LWID_ENB: /* allowed Link-width */
9955 val = ppd->link_width_enabled;
9956 break;
9957 case HFI1_IB_CFG_LWID: /* currently active Link-width */
9958 val = ppd->link_width_active;
9959 break;
9960 case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
9961 val = ppd->link_speed_enabled;
9962 break;
9963 case HFI1_IB_CFG_SPD: /* current Link speed */
9964 val = ppd->link_speed_active;
9965 break;
9966
9967 case HFI1_IB_CFG_RXPOL_ENB: /* Auto-RX-polarity enable */
9968 case HFI1_IB_CFG_LREV_ENB: /* Auto-Lane-reversal enable */
9969 case HFI1_IB_CFG_LINKLATENCY:
9970 goto unimplemented;
9971
9972 case HFI1_IB_CFG_OP_VLS:
9973 val = ppd->vls_operational;
9974 break;
9975 case HFI1_IB_CFG_VL_HIGH_CAP: /* VL arb high priority table size */
9976 val = VL_ARB_HIGH_PRIO_TABLE_SIZE;
9977 break;
9978 case HFI1_IB_CFG_VL_LOW_CAP: /* VL arb low priority table size */
9979 val = VL_ARB_LOW_PRIO_TABLE_SIZE;
9980 break;
9981 case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
9982 val = ppd->overrun_threshold;
9983 break;
9984 case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
9985 val = ppd->phy_error_threshold;
9986 break;
9987 case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
Ira Weiny156d24d2017-09-26 07:00:43 -07009988 val = HLS_DEFAULT;
Mike Marciniszyn77241052015-07-30 15:17:43 -04009989 break;
9990
9991 case HFI1_IB_CFG_HRTBT: /* Heartbeat off/enable/auto */
9992 case HFI1_IB_CFG_PMA_TICKS:
9993 default:
9994unimplemented:
9995 if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
9996 dd_dev_info(
9997 dd,
9998 "%s: which %s: not implemented\n",
9999 __func__,
10000 ib_cfg_name(which));
10001 break;
10002 }
10003
10004 return val;
10005}
10006
10007/*
10008 * The largest MAD packet size.
10009 */
10010#define MAX_MAD_PACKET 2048
10011
10012/*
10013 * Return the maximum header bytes that can go on the _wire_
10014 * for this device. This count includes the ICRC which is
10015 * not part of the packet held in memory but it is appended
10016 * by the HW.
10017 * This is dependent on the device's receive header entry size.
10018 * HFI allows this to be set per-receive context, but the
10019 * driver presently enforces a global value.
10020 */
10021u32 lrh_max_header_bytes(struct hfi1_devdata *dd)
10022{
10023 /*
10024 * The maximum non-payload (MTU) bytes in LRH.PktLen are
10025 * the Receive Header Entry Size minus the PBC (or RHF) size
10026 * plus one DW for the ICRC appended by HW.
10027 *
10028 * dd->rcd[0].rcvhdrqentsize is in DW.
10029 * We use rcd[0] as all context will have the same value. Also,
10030 * the first kernel context would have been allocated by now so
10031 * we are guaranteed a valid value.
10032 */
10033 return (dd->rcd[0]->rcvhdrqentsize - 2/*PBC/RHF*/ + 1/*ICRC*/) << 2;
10034}
10035
10036/*
10037 * Set Send Length
10038 * @ppd - per port data
10039 *
10040 * Set the MTU by limiting how many DWs may be sent. The SendLenCheck*
10041 * registers compare against LRH.PktLen, so use the max bytes included
10042 * in the LRH.
10043 *
10044 * This routine changes all VL values except VL15, which it maintains at
10045 * the same value.
10046 */
10047static void set_send_length(struct hfi1_pportdata *ppd)
10048{
10049 struct hfi1_devdata *dd = ppd->dd;
Harish Chegondi6cc6ad22015-12-01 15:38:24 -050010050 u32 max_hb = lrh_max_header_bytes(dd), dcmtu;
10051 u32 maxvlmtu = dd->vld[15].mtu;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010052 u64 len1 = 0, len2 = (((dd->vld[15].mtu + max_hb) >> 2)
10053 & SEND_LEN_CHECK1_LEN_VL15_MASK) <<
10054 SEND_LEN_CHECK1_LEN_VL15_SHIFT;
Jubin Johnb4ba6632016-06-09 07:51:08 -070010055 int i, j;
Jianxin Xiong44306f12016-04-12 11:30:28 -070010056 u32 thres;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010057
10058 for (i = 0; i < ppd->vls_supported; i++) {
10059 if (dd->vld[i].mtu > maxvlmtu)
10060 maxvlmtu = dd->vld[i].mtu;
10061 if (i <= 3)
10062 len1 |= (((dd->vld[i].mtu + max_hb) >> 2)
10063 & SEND_LEN_CHECK0_LEN_VL0_MASK) <<
10064 ((i % 4) * SEND_LEN_CHECK0_LEN_VL1_SHIFT);
10065 else
10066 len2 |= (((dd->vld[i].mtu + max_hb) >> 2)
10067 & SEND_LEN_CHECK1_LEN_VL4_MASK) <<
10068 ((i % 4) * SEND_LEN_CHECK1_LEN_VL5_SHIFT);
10069 }
10070 write_csr(dd, SEND_LEN_CHECK0, len1);
10071 write_csr(dd, SEND_LEN_CHECK1, len2);
10072 /* adjust kernel credit return thresholds based on new MTUs */
10073 /* all kernel receive contexts have the same hdrqentsize */
10074 for (i = 0; i < ppd->vls_supported; i++) {
Jianxin Xiong44306f12016-04-12 11:30:28 -070010075 thres = min(sc_percent_to_threshold(dd->vld[i].sc, 50),
10076 sc_mtu_to_threshold(dd->vld[i].sc,
10077 dd->vld[i].mtu,
Jubin John17fb4f22016-02-14 20:21:52 -080010078 dd->rcd[0]->rcvhdrqentsize));
Jubin Johnb4ba6632016-06-09 07:51:08 -070010079 for (j = 0; j < INIT_SC_PER_VL; j++)
10080 sc_set_cr_threshold(
10081 pio_select_send_context_vl(dd, j, i),
10082 thres);
Jianxin Xiong44306f12016-04-12 11:30:28 -070010083 }
10084 thres = min(sc_percent_to_threshold(dd->vld[15].sc, 50),
10085 sc_mtu_to_threshold(dd->vld[15].sc,
10086 dd->vld[15].mtu,
10087 dd->rcd[0]->rcvhdrqentsize));
10088 sc_set_cr_threshold(dd->vld[15].sc, thres);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010089
10090 /* Adjust maximum MTU for the port in DC */
10091 dcmtu = maxvlmtu == 10240 ? DCC_CFG_PORT_MTU_CAP_10240 :
10092 (ilog2(maxvlmtu >> 8) + 1);
10093 len1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG);
10094 len1 &= ~DCC_CFG_PORT_CONFIG_MTU_CAP_SMASK;
10095 len1 |= ((u64)dcmtu & DCC_CFG_PORT_CONFIG_MTU_CAP_MASK) <<
10096 DCC_CFG_PORT_CONFIG_MTU_CAP_SHIFT;
10097 write_csr(ppd->dd, DCC_CFG_PORT_CONFIG, len1);
10098}
10099
10100static void set_lidlmc(struct hfi1_pportdata *ppd)
10101{
10102 int i;
10103 u64 sreg = 0;
10104 struct hfi1_devdata *dd = ppd->dd;
10105 u32 mask = ~((1U << ppd->lmc) - 1);
10106 u64 c1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG1);
Dasaratharaman Chandramouli51e658f52017-08-04 13:54:35 -070010107 u32 lid;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010108
Dasaratharaman Chandramouli51e658f52017-08-04 13:54:35 -070010109 /*
10110 * Program 0 in CSR if port lid is extended. This prevents
10111 * 9B packets being sent out for large lids.
10112 */
10113 lid = (ppd->lid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) ? 0 : ppd->lid;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010114 c1 &= ~(DCC_CFG_PORT_CONFIG1_TARGET_DLID_SMASK
10115 | DCC_CFG_PORT_CONFIG1_DLID_MASK_SMASK);
Dasaratharaman Chandramouli51e658f52017-08-04 13:54:35 -070010116 c1 |= ((lid & DCC_CFG_PORT_CONFIG1_TARGET_DLID_MASK)
Jubin John8638b772016-02-14 20:19:24 -080010117 << DCC_CFG_PORT_CONFIG1_TARGET_DLID_SHIFT) |
Mike Marciniszyn77241052015-07-30 15:17:43 -040010118 ((mask & DCC_CFG_PORT_CONFIG1_DLID_MASK_MASK)
10119 << DCC_CFG_PORT_CONFIG1_DLID_MASK_SHIFT);
10120 write_csr(ppd->dd, DCC_CFG_PORT_CONFIG1, c1);
10121
10122 /*
10123 * Iterate over all the send contexts and set their SLID check
10124 */
10125 sreg = ((mask & SEND_CTXT_CHECK_SLID_MASK_MASK) <<
10126 SEND_CTXT_CHECK_SLID_MASK_SHIFT) |
Dasaratharaman Chandramouli51e658f52017-08-04 13:54:35 -070010127 (((lid & mask) & SEND_CTXT_CHECK_SLID_VALUE_MASK) <<
Mike Marciniszyn77241052015-07-30 15:17:43 -040010128 SEND_CTXT_CHECK_SLID_VALUE_SHIFT);
10129
10130 for (i = 0; i < dd->chip_send_contexts; i++) {
10131 hfi1_cdbg(LINKVERB, "SendContext[%d].SLID_CHECK = 0x%x",
10132 i, (u32)sreg);
10133 write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, sreg);
10134 }
10135
10136 /* Now we have to do the same thing for the sdma engines */
Dasaratharaman Chandramouli51e658f52017-08-04 13:54:35 -070010137 sdma_update_lmc(dd, mask, lid);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010138}
10139
Dean Luick6854c692016-07-25 13:38:56 -070010140static const char *state_completed_string(u32 completed)
10141{
10142 static const char * const state_completed[] = {
10143 "EstablishComm",
10144 "OptimizeEQ",
10145 "VerifyCap"
10146 };
10147
10148 if (completed < ARRAY_SIZE(state_completed))
10149 return state_completed[completed];
10150
10151 return "unknown";
10152}
10153
10154static const char all_lanes_dead_timeout_expired[] =
10155 "All lanes were inactive – was the interconnect media removed?";
10156static const char tx_out_of_policy[] =
10157 "Passing lanes on local port do not meet the local link width policy";
10158static const char no_state_complete[] =
10159 "State timeout occurred before link partner completed the state";
10160static const char * const state_complete_reasons[] = {
10161 [0x00] = "Reason unknown",
10162 [0x01] = "Link was halted by driver, refer to LinkDownReason",
10163 [0x02] = "Link partner reported failure",
10164 [0x10] = "Unable to achieve frame sync on any lane",
10165 [0x11] =
10166 "Unable to find a common bit rate with the link partner",
10167 [0x12] =
10168 "Unable to achieve frame sync on sufficient lanes to meet the local link width policy",
10169 [0x13] =
10170 "Unable to identify preset equalization on sufficient lanes to meet the local link width policy",
10171 [0x14] = no_state_complete,
10172 [0x15] =
10173 "State timeout occurred before link partner identified equalization presets",
10174 [0x16] =
10175 "Link partner completed the EstablishComm state, but the passing lanes do not meet the local link width policy",
10176 [0x17] = tx_out_of_policy,
10177 [0x20] = all_lanes_dead_timeout_expired,
10178 [0x21] =
10179 "Unable to achieve acceptable BER on sufficient lanes to meet the local link width policy",
10180 [0x22] = no_state_complete,
10181 [0x23] =
10182 "Link partner completed the OptimizeEq state, but the passing lanes do not meet the local link width policy",
10183 [0x24] = tx_out_of_policy,
10184 [0x30] = all_lanes_dead_timeout_expired,
10185 [0x31] =
10186 "State timeout occurred waiting for host to process received frames",
10187 [0x32] = no_state_complete,
10188 [0x33] =
10189 "Link partner completed the VerifyCap state, but the passing lanes do not meet the local link width policy",
10190 [0x34] = tx_out_of_policy,
Jakub Byczkowskie870b4a2017-09-26 07:00:04 -070010191 [0x35] = "Negotiated link width is mutually exclusive",
10192 [0x36] =
10193 "Timed out before receiving verifycap frames in VerifyCap.Exchange",
10194 [0x37] = "Unable to resolve secure data exchange",
Dean Luick6854c692016-07-25 13:38:56 -070010195};
10196
10197static const char *state_complete_reason_code_string(struct hfi1_pportdata *ppd,
10198 u32 code)
10199{
10200 const char *str = NULL;
10201
10202 if (code < ARRAY_SIZE(state_complete_reasons))
10203 str = state_complete_reasons[code];
10204
10205 if (str)
10206 return str;
10207 return "Reserved";
10208}
10209
10210/* describe the given last state complete frame */
10211static void decode_state_complete(struct hfi1_pportdata *ppd, u32 frame,
10212 const char *prefix)
10213{
10214 struct hfi1_devdata *dd = ppd->dd;
10215 u32 success;
10216 u32 state;
10217 u32 reason;
10218 u32 lanes;
10219
10220 /*
10221 * Decode frame:
10222 * [ 0: 0] - success
10223 * [ 3: 1] - state
10224 * [ 7: 4] - next state timeout
10225 * [15: 8] - reason code
10226 * [31:16] - lanes
10227 */
10228 success = frame & 0x1;
10229 state = (frame >> 1) & 0x7;
10230 reason = (frame >> 8) & 0xff;
10231 lanes = (frame >> 16) & 0xffff;
10232
10233 dd_dev_err(dd, "Last %s LNI state complete frame 0x%08x:\n",
10234 prefix, frame);
10235 dd_dev_err(dd, " last reported state state: %s (0x%x)\n",
10236 state_completed_string(state), state);
10237 dd_dev_err(dd, " state successfully completed: %s\n",
10238 success ? "yes" : "no");
10239 dd_dev_err(dd, " fail reason 0x%x: %s\n",
10240 reason, state_complete_reason_code_string(ppd, reason));
10241 dd_dev_err(dd, " passing lane mask: 0x%x", lanes);
10242}
10243
10244/*
10245 * Read the last state complete frames and explain them. This routine
10246 * expects to be called if the link went down during link negotiation
10247 * and initialization (LNI). That is, anywhere between polling and link up.
10248 */
10249static void check_lni_states(struct hfi1_pportdata *ppd)
10250{
10251 u32 last_local_state;
10252 u32 last_remote_state;
10253
10254 read_last_local_state(ppd->dd, &last_local_state);
10255 read_last_remote_state(ppd->dd, &last_remote_state);
10256
10257 /*
10258 * Don't report anything if there is nothing to report. A value of
10259 * 0 means the link was taken down while polling and there was no
10260 * training in-process.
10261 */
10262 if (last_local_state == 0 && last_remote_state == 0)
10263 return;
10264
10265 decode_state_complete(ppd, last_local_state, "transmitted");
10266 decode_state_complete(ppd, last_remote_state, "received");
10267}
10268
Dean Luickec8a1422017-03-20 17:24:39 -070010269/* wait for wait_ms for LINK_TRANSFER_ACTIVE to go to 1 */
10270static int wait_link_transfer_active(struct hfi1_devdata *dd, int wait_ms)
10271{
10272 u64 reg;
10273 unsigned long timeout;
10274
10275 /* watch LCB_STS_LINK_TRANSFER_ACTIVE */
10276 timeout = jiffies + msecs_to_jiffies(wait_ms);
10277 while (1) {
10278 reg = read_csr(dd, DC_LCB_STS_LINK_TRANSFER_ACTIVE);
10279 if (reg)
10280 break;
10281 if (time_after(jiffies, timeout)) {
10282 dd_dev_err(dd,
10283 "timeout waiting for LINK_TRANSFER_ACTIVE\n");
10284 return -ETIMEDOUT;
10285 }
10286 udelay(2);
10287 }
10288 return 0;
10289}
10290
10291/* called when the logical link state is not down as it should be */
10292static void force_logical_link_state_down(struct hfi1_pportdata *ppd)
10293{
10294 struct hfi1_devdata *dd = ppd->dd;
10295
10296 /*
10297 * Bring link up in LCB loopback
10298 */
10299 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 1);
10300 write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK,
10301 DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK);
10302
10303 write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
10304 write_csr(dd, DC_LCB_CFG_REINIT_AS_SLAVE, 0);
10305 write_csr(dd, DC_LCB_CFG_CNT_FOR_SKIP_STALL, 0x110);
10306 write_csr(dd, DC_LCB_CFG_LOOPBACK, 0x2);
10307
10308 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
10309 (void)read_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET);
10310 udelay(3);
10311 write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP, 1);
10312 write_csr(dd, DC_LCB_CFG_RUN, 1ull << DC_LCB_CFG_RUN_EN_SHIFT);
10313
10314 wait_link_transfer_active(dd, 100);
10315
10316 /*
10317 * Bring the link down again.
10318 */
10319 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 1);
10320 write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP, 0);
10321 write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK, 0);
10322
Byczkowski, Jakub02a222c2017-08-04 13:52:26 -070010323 /* adjust ppd->statusp, if needed */
10324 update_statusp(ppd, IB_PORT_DOWN);
10325
10326 dd_dev_info(ppd->dd, "logical state forced to LINK_DOWN\n");
Dean Luickec8a1422017-03-20 17:24:39 -070010327}
10328
Mike Marciniszyn77241052015-07-30 15:17:43 -040010329/*
10330 * Helper for set_link_state(). Do not call except from that routine.
10331 * Expects ppd->hls_mutex to be held.
10332 *
10333 * @rem_reason value to be sent to the neighbor
10334 *
10335 * LinkDownReasons only set if transition succeeds.
10336 */
10337static int goto_offline(struct hfi1_pportdata *ppd, u8 rem_reason)
10338{
10339 struct hfi1_devdata *dd = ppd->dd;
Sebastian Sanchez913cc672017-07-29 08:44:01 -070010340 u32 previous_state;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010341 int ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010342
Michael J. Ruhl86884262017-03-20 17:24:51 -070010343 update_lcb_cache(dd);
10344
Mike Marciniszyn77241052015-07-30 15:17:43 -040010345 previous_state = ppd->host_link_state;
10346 ppd->host_link_state = HLS_GOING_OFFLINE;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010347
Sebastian Sanchez913cc672017-07-29 08:44:01 -070010348 /* start offline transition */
10349 ret = set_physical_link_state(dd, (rem_reason << 8) | PLS_OFFLINE);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010350
Sebastian Sanchez913cc672017-07-29 08:44:01 -070010351 if (ret != HCMD_SUCCESS) {
10352 dd_dev_err(dd,
10353 "Failed to transition to Offline link state, return %d\n",
10354 ret);
10355 return -EINVAL;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010356 }
Sebastian Sanchez913cc672017-07-29 08:44:01 -070010357 if (ppd->offline_disabled_reason ==
10358 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE))
10359 ppd->offline_disabled_reason =
10360 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_TRANSIENT);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010361
Sebastian Sanchez913cc672017-07-29 08:44:01 -070010362 /*
10363 * Wait for offline transition. It can take a while for
10364 * the link to go down.
10365 */
10366 ret = wait_physical_linkstate(ppd, PLS_OFFLINE, 10000);
10367 if (ret < 0)
10368 return ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010369
Mike Marciniszyn77241052015-07-30 15:17:43 -040010370 /*
10371 * Now in charge of LCB - must be after the physical state is
10372 * offline.quiet and before host_link_state is changed.
10373 */
10374 set_host_lcb_access(dd);
10375 write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
Dean Luickec8a1422017-03-20 17:24:39 -070010376
10377 /* make sure the logical state is also down */
10378 ret = wait_logical_linkstate(ppd, IB_PORT_DOWN, 1000);
10379 if (ret)
10380 force_logical_link_state_down(ppd);
10381
Mike Marciniszyn77241052015-07-30 15:17:43 -040010382 ppd->host_link_state = HLS_LINK_COOLDOWN; /* LCB access allowed */
10383
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -080010384 if (ppd->port_type == PORT_TYPE_QSFP &&
10385 ppd->qsfp_info.limiting_active &&
10386 qsfp_mod_present(ppd)) {
Dean Luick765a6fa2016-03-05 08:50:06 -080010387 int ret;
10388
10389 ret = acquire_chip_resource(dd, qsfp_resource(dd), QSFP_WAIT);
10390 if (ret == 0) {
10391 set_qsfp_tx(ppd, 0);
10392 release_chip_resource(dd, qsfp_resource(dd));
10393 } else {
10394 /* not fatal, but should warn */
10395 dd_dev_err(dd,
10396 "Unable to acquire lock to turn off QSFP TX\n");
10397 }
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -080010398 }
10399
Mike Marciniszyn77241052015-07-30 15:17:43 -040010400 /*
10401 * The LNI has a mandatory wait time after the physical state
10402 * moves to Offline.Quiet. The wait time may be different
10403 * depending on how the link went down. The 8051 firmware
10404 * will observe the needed wait time and only move to ready
10405 * when that is completed. The largest of the quiet timeouts
Dean Luick05087f3b2015-12-01 15:38:16 -050010406 * is 6s, so wait that long and then at least 0.5s more for
10407 * other transitions, and another 0.5s for a buffer.
Mike Marciniszyn77241052015-07-30 15:17:43 -040010408 */
Dean Luick05087f3b2015-12-01 15:38:16 -050010409 ret = wait_fm_ready(dd, 7000);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010410 if (ret) {
10411 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -080010412 "After going offline, timed out waiting for the 8051 to become ready to accept host requests\n");
Mike Marciniszyn77241052015-07-30 15:17:43 -040010413 /* state is really offline, so make it so */
10414 ppd->host_link_state = HLS_DN_OFFLINE;
10415 return ret;
10416 }
10417
10418 /*
10419 * The state is now offline and the 8051 is ready to accept host
10420 * requests.
10421 * - change our state
10422 * - notify others if we were previously in a linkup state
10423 */
10424 ppd->host_link_state = HLS_DN_OFFLINE;
10425 if (previous_state & HLS_UP) {
10426 /* went down while link was up */
10427 handle_linkup_change(dd, 0);
10428 } else if (previous_state
10429 & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
10430 /* went down while attempting link up */
Dean Luick6854c692016-07-25 13:38:56 -070010431 check_lni_states(ppd);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010432 }
10433
10434 /* the active link width (downgrade) is 0 on link down */
10435 ppd->link_width_active = 0;
10436 ppd->link_width_downgrade_tx_active = 0;
10437 ppd->link_width_downgrade_rx_active = 0;
10438 ppd->current_egress_rate = 0;
10439 return 0;
10440}
10441
10442/* return the link state name */
10443static const char *link_state_name(u32 state)
10444{
10445 const char *name;
10446 int n = ilog2(state);
10447 static const char * const names[] = {
10448 [__HLS_UP_INIT_BP] = "INIT",
10449 [__HLS_UP_ARMED_BP] = "ARMED",
10450 [__HLS_UP_ACTIVE_BP] = "ACTIVE",
10451 [__HLS_DN_DOWNDEF_BP] = "DOWNDEF",
10452 [__HLS_DN_POLL_BP] = "POLL",
10453 [__HLS_DN_DISABLE_BP] = "DISABLE",
10454 [__HLS_DN_OFFLINE_BP] = "OFFLINE",
10455 [__HLS_VERIFY_CAP_BP] = "VERIFY_CAP",
10456 [__HLS_GOING_UP_BP] = "GOING_UP",
10457 [__HLS_GOING_OFFLINE_BP] = "GOING_OFFLINE",
10458 [__HLS_LINK_COOLDOWN_BP] = "LINK_COOLDOWN"
10459 };
10460
10461 name = n < ARRAY_SIZE(names) ? names[n] : NULL;
10462 return name ? name : "unknown";
10463}
10464
10465/* return the link state reason name */
10466static const char *link_state_reason_name(struct hfi1_pportdata *ppd, u32 state)
10467{
10468 if (state == HLS_UP_INIT) {
10469 switch (ppd->linkinit_reason) {
10470 case OPA_LINKINIT_REASON_LINKUP:
10471 return "(LINKUP)";
10472 case OPA_LINKINIT_REASON_FLAPPING:
10473 return "(FLAPPING)";
10474 case OPA_LINKINIT_OUTSIDE_POLICY:
10475 return "(OUTSIDE_POLICY)";
10476 case OPA_LINKINIT_QUARANTINED:
10477 return "(QUARANTINED)";
10478 case OPA_LINKINIT_INSUFIC_CAPABILITY:
10479 return "(INSUFIC_CAPABILITY)";
10480 default:
10481 break;
10482 }
10483 }
10484 return "";
10485}
10486
10487/*
Jakub Byczkowskid392a672017-08-13 08:08:52 -070010488 * driver_pstate - convert the driver's notion of a port's
Mike Marciniszyn77241052015-07-30 15:17:43 -040010489 * state (an HLS_*) into a physical state (a {IB,OPA}_PORTPHYSSTATE_*).
10490 * Return -1 (converted to a u32) to indicate error.
10491 */
Jakub Byczkowskid392a672017-08-13 08:08:52 -070010492u32 driver_pstate(struct hfi1_pportdata *ppd)
Mike Marciniszyn77241052015-07-30 15:17:43 -040010493{
10494 switch (ppd->host_link_state) {
10495 case HLS_UP_INIT:
10496 case HLS_UP_ARMED:
10497 case HLS_UP_ACTIVE:
10498 return IB_PORTPHYSSTATE_LINKUP;
10499 case HLS_DN_POLL:
10500 return IB_PORTPHYSSTATE_POLLING;
10501 case HLS_DN_DISABLE:
10502 return IB_PORTPHYSSTATE_DISABLED;
10503 case HLS_DN_OFFLINE:
10504 return OPA_PORTPHYSSTATE_OFFLINE;
10505 case HLS_VERIFY_CAP:
10506 return IB_PORTPHYSSTATE_POLLING;
10507 case HLS_GOING_UP:
10508 return IB_PORTPHYSSTATE_POLLING;
10509 case HLS_GOING_OFFLINE:
10510 return OPA_PORTPHYSSTATE_OFFLINE;
10511 case HLS_LINK_COOLDOWN:
10512 return OPA_PORTPHYSSTATE_OFFLINE;
10513 case HLS_DN_DOWNDEF:
10514 default:
10515 dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
10516 ppd->host_link_state);
10517 return -1;
10518 }
10519}
10520
10521/*
Byczkowski, Jakub02a222c2017-08-04 13:52:26 -070010522 * driver_lstate - convert the driver's notion of a port's
Mike Marciniszyn77241052015-07-30 15:17:43 -040010523 * state (an HLS_*) into a logical state (a IB_PORT_*). Return -1
10524 * (converted to a u32) to indicate error.
10525 */
Byczkowski, Jakub02a222c2017-08-04 13:52:26 -070010526u32 driver_lstate(struct hfi1_pportdata *ppd)
Mike Marciniszyn77241052015-07-30 15:17:43 -040010527{
Easwar Hariharan0c7f77a2016-05-12 10:22:33 -070010528 if (ppd->host_link_state && (ppd->host_link_state & HLS_DOWN))
Mike Marciniszyn77241052015-07-30 15:17:43 -040010529 return IB_PORT_DOWN;
10530
10531 switch (ppd->host_link_state & HLS_UP) {
10532 case HLS_UP_INIT:
10533 return IB_PORT_INIT;
10534 case HLS_UP_ARMED:
10535 return IB_PORT_ARMED;
10536 case HLS_UP_ACTIVE:
10537 return IB_PORT_ACTIVE;
10538 default:
10539 dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
10540 ppd->host_link_state);
10541 return -1;
10542 }
10543}
10544
10545void set_link_down_reason(struct hfi1_pportdata *ppd, u8 lcl_reason,
10546 u8 neigh_reason, u8 rem_reason)
10547{
10548 if (ppd->local_link_down_reason.latest == 0 &&
10549 ppd->neigh_link_down_reason.latest == 0) {
10550 ppd->local_link_down_reason.latest = lcl_reason;
10551 ppd->neigh_link_down_reason.latest = neigh_reason;
10552 ppd->remote_link_down_reason = rem_reason;
10553 }
10554}
10555
10556/*
Alex Estrin5e2d6762017-07-24 07:46:36 -070010557 * Verify if BCT for data VLs is non-zero.
10558 */
10559static inline bool data_vls_operational(struct hfi1_pportdata *ppd)
10560{
10561 return !!ppd->actual_vls_operational;
10562}
10563
10564/*
Mike Marciniszyn77241052015-07-30 15:17:43 -040010565 * Change the physical and/or logical link state.
10566 *
10567 * Do not call this routine while inside an interrupt. It contains
10568 * calls to routines that can take multiple seconds to finish.
10569 *
10570 * Returns 0 on success, -errno on failure.
10571 */
10572int set_link_state(struct hfi1_pportdata *ppd, u32 state)
10573{
10574 struct hfi1_devdata *dd = ppd->dd;
10575 struct ib_event event = {.device = NULL};
10576 int ret1, ret = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010577 int orig_new_state, poll_bounce;
10578
10579 mutex_lock(&ppd->hls_lock);
10580
10581 orig_new_state = state;
10582 if (state == HLS_DN_DOWNDEF)
Ira Weiny156d24d2017-09-26 07:00:43 -070010583 state = HLS_DEFAULT;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010584
10585 /* interpret poll -> poll as a link bounce */
Jubin Johnd0d236e2016-02-14 20:20:15 -080010586 poll_bounce = ppd->host_link_state == HLS_DN_POLL &&
10587 state == HLS_DN_POLL;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010588
10589 dd_dev_info(dd, "%s: current %s, new %s %s%s\n", __func__,
Jubin John17fb4f22016-02-14 20:21:52 -080010590 link_state_name(ppd->host_link_state),
10591 link_state_name(orig_new_state),
10592 poll_bounce ? "(bounce) " : "",
10593 link_state_reason_name(ppd, state));
Mike Marciniszyn77241052015-07-30 15:17:43 -040010594
Mike Marciniszyn77241052015-07-30 15:17:43 -040010595 /*
10596 * If we're going to a (HLS_*) link state that implies the logical
10597 * link state is neither of (IB_PORT_ARMED, IB_PORT_ACTIVE), then
10598 * reset is_sm_config_started to 0.
10599 */
10600 if (!(state & (HLS_UP_ARMED | HLS_UP_ACTIVE)))
10601 ppd->is_sm_config_started = 0;
10602
10603 /*
10604 * Do nothing if the states match. Let a poll to poll link bounce
10605 * go through.
10606 */
10607 if (ppd->host_link_state == state && !poll_bounce)
10608 goto done;
10609
10610 switch (state) {
10611 case HLS_UP_INIT:
Jubin Johnd0d236e2016-02-14 20:20:15 -080010612 if (ppd->host_link_state == HLS_DN_POLL &&
10613 (quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040010614 /*
10615 * Quick link up jumps from polling to here.
10616 *
10617 * Whether in normal or loopback mode, the
10618 * simulator jumps from polling to link up.
10619 * Accept that here.
10620 */
Jubin John17fb4f22016-02-14 20:21:52 -080010621 /* OK */
Mike Marciniszyn77241052015-07-30 15:17:43 -040010622 } else if (ppd->host_link_state != HLS_GOING_UP) {
10623 goto unexpected;
10624 }
10625
Byczkowski, Jakubbec7c792017-05-29 17:21:32 -070010626 /*
10627 * Wait for Link_Up physical state.
10628 * Physical and Logical states should already be
10629 * be transitioned to LinkUp and LinkInit respectively.
10630 */
10631 ret = wait_physical_linkstate(ppd, PLS_LINKUP, 1000);
10632 if (ret) {
10633 dd_dev_err(dd,
10634 "%s: physical state did not change to LINK-UP\n",
10635 __func__);
10636 break;
10637 }
10638
Mike Marciniszyn77241052015-07-30 15:17:43 -040010639 ret = wait_logical_linkstate(ppd, IB_PORT_INIT, 1000);
10640 if (ret) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040010641 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -080010642 "%s: logical state did not change to INIT\n",
10643 __func__);
Jan Sokolowski59ec8732017-07-24 07:46:18 -070010644 break;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010645 }
Jan Sokolowski59ec8732017-07-24 07:46:18 -070010646
10647 /* clear old transient LINKINIT_REASON code */
10648 if (ppd->linkinit_reason >= OPA_LINKINIT_REASON_CLEAR)
10649 ppd->linkinit_reason =
10650 OPA_LINKINIT_REASON_LINKUP;
10651
10652 /* enable the port */
10653 add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
10654
10655 handle_linkup_change(dd, 1);
10656 ppd->host_link_state = HLS_UP_INIT;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010657 break;
10658 case HLS_UP_ARMED:
10659 if (ppd->host_link_state != HLS_UP_INIT)
10660 goto unexpected;
10661
Alex Estrin5e2d6762017-07-24 07:46:36 -070010662 if (!data_vls_operational(ppd)) {
10663 dd_dev_err(dd,
10664 "%s: data VLs not operational\n", __func__);
10665 ret = -EINVAL;
10666 break;
10667 }
10668
Mike Marciniszyn77241052015-07-30 15:17:43 -040010669 set_logical_state(dd, LSTATE_ARMED);
10670 ret = wait_logical_linkstate(ppd, IB_PORT_ARMED, 1000);
10671 if (ret) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040010672 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -080010673 "%s: logical state did not change to ARMED\n",
10674 __func__);
Alex Estrin5efd40c2017-07-29 08:43:20 -070010675 break;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010676 }
Alex Estrin5efd40c2017-07-29 08:43:20 -070010677 ppd->host_link_state = HLS_UP_ARMED;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010678 /*
10679 * The simulator does not currently implement SMA messages,
10680 * so neighbor_normal is not set. Set it here when we first
10681 * move to Armed.
10682 */
10683 if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
10684 ppd->neighbor_normal = 1;
10685 break;
10686 case HLS_UP_ACTIVE:
10687 if (ppd->host_link_state != HLS_UP_ARMED)
10688 goto unexpected;
10689
Mike Marciniszyn77241052015-07-30 15:17:43 -040010690 set_logical_state(dd, LSTATE_ACTIVE);
10691 ret = wait_logical_linkstate(ppd, IB_PORT_ACTIVE, 1000);
10692 if (ret) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040010693 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -080010694 "%s: logical state did not change to ACTIVE\n",
10695 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010696 } else {
Mike Marciniszyn77241052015-07-30 15:17:43 -040010697 /* tell all engines to go running */
10698 sdma_all_running(dd);
Alex Estrin5efd40c2017-07-29 08:43:20 -070010699 ppd->host_link_state = HLS_UP_ACTIVE;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010700
10701 /* Signal the IB layer that the port has went active */
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -080010702 event.device = &dd->verbs_dev.rdi.ibdev;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010703 event.element.port_num = ppd->port;
10704 event.event = IB_EVENT_PORT_ACTIVE;
10705 }
10706 break;
10707 case HLS_DN_POLL:
10708 if ((ppd->host_link_state == HLS_DN_DISABLE ||
10709 ppd->host_link_state == HLS_DN_OFFLINE) &&
10710 dd->dc_shutdown)
10711 dc_start(dd);
10712 /* Hand LED control to the DC */
10713 write_csr(dd, DCC_CFG_LED_CNTRL, 0);
10714
10715 if (ppd->host_link_state != HLS_DN_OFFLINE) {
10716 u8 tmp = ppd->link_enabled;
10717
10718 ret = goto_offline(ppd, ppd->remote_link_down_reason);
10719 if (ret) {
10720 ppd->link_enabled = tmp;
10721 break;
10722 }
10723 ppd->remote_link_down_reason = 0;
10724
10725 if (ppd->driver_link_ready)
10726 ppd->link_enabled = 1;
10727 }
10728
Jim Snowfb9036d2016-01-11 18:32:21 -050010729 set_all_slowpath(ppd->dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010730 ret = set_local_link_attributes(ppd);
10731 if (ret)
10732 break;
10733
10734 ppd->port_error_action = 0;
10735 ppd->host_link_state = HLS_DN_POLL;
10736
10737 if (quick_linkup) {
10738 /* quick linkup does not go into polling */
10739 ret = do_quick_linkup(dd);
10740 } else {
10741 ret1 = set_physical_link_state(dd, PLS_POLLING);
10742 if (ret1 != HCMD_SUCCESS) {
10743 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -080010744 "Failed to transition to Polling link state, return 0x%x\n",
10745 ret1);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010746 ret = -EINVAL;
10747 }
10748 }
Bryan Morgana9c05e32016-02-03 14:30:49 -080010749 ppd->offline_disabled_reason =
10750 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010751 /*
10752 * If an error occurred above, go back to offline. The
10753 * caller may reschedule another attempt.
10754 */
10755 if (ret)
10756 goto_offline(ppd, 0);
Byczkowski, Jakubbec7c792017-05-29 17:21:32 -070010757 else
Jakub Byczkowskid392a672017-08-13 08:08:52 -070010758 log_physical_state(ppd, PLS_POLLING);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010759 break;
10760 case HLS_DN_DISABLE:
10761 /* link is disabled */
10762 ppd->link_enabled = 0;
10763
10764 /* allow any state to transition to disabled */
10765
10766 /* must transition to offline first */
10767 if (ppd->host_link_state != HLS_DN_OFFLINE) {
10768 ret = goto_offline(ppd, ppd->remote_link_down_reason);
10769 if (ret)
10770 break;
10771 ppd->remote_link_down_reason = 0;
10772 }
10773
Michael J. Ruhldb069ec2017-02-08 05:28:13 -080010774 if (!dd->dc_shutdown) {
10775 ret1 = set_physical_link_state(dd, PLS_DISABLED);
10776 if (ret1 != HCMD_SUCCESS) {
10777 dd_dev_err(dd,
10778 "Failed to transition to Disabled link state, return 0x%x\n",
10779 ret1);
10780 ret = -EINVAL;
10781 break;
10782 }
Byczkowski, Jakubbec7c792017-05-29 17:21:32 -070010783 ret = wait_physical_linkstate(ppd, PLS_DISABLED, 10000);
10784 if (ret) {
10785 dd_dev_err(dd,
10786 "%s: physical state did not change to DISABLED\n",
10787 __func__);
10788 break;
10789 }
Michael J. Ruhldb069ec2017-02-08 05:28:13 -080010790 dc_shutdown(dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010791 }
10792 ppd->host_link_state = HLS_DN_DISABLE;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010793 break;
10794 case HLS_DN_OFFLINE:
10795 if (ppd->host_link_state == HLS_DN_DISABLE)
10796 dc_start(dd);
10797
10798 /* allow any state to transition to offline */
10799 ret = goto_offline(ppd, ppd->remote_link_down_reason);
10800 if (!ret)
10801 ppd->remote_link_down_reason = 0;
10802 break;
10803 case HLS_VERIFY_CAP:
10804 if (ppd->host_link_state != HLS_DN_POLL)
10805 goto unexpected;
10806 ppd->host_link_state = HLS_VERIFY_CAP;
Jakub Byczkowskid392a672017-08-13 08:08:52 -070010807 log_physical_state(ppd, PLS_CONFIGPHY_VERIFYCAP);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010808 break;
10809 case HLS_GOING_UP:
10810 if (ppd->host_link_state != HLS_VERIFY_CAP)
10811 goto unexpected;
10812
10813 ret1 = set_physical_link_state(dd, PLS_LINKUP);
10814 if (ret1 != HCMD_SUCCESS) {
10815 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -080010816 "Failed to transition to link up state, return 0x%x\n",
10817 ret1);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010818 ret = -EINVAL;
10819 break;
10820 }
10821 ppd->host_link_state = HLS_GOING_UP;
10822 break;
10823
10824 case HLS_GOING_OFFLINE: /* transient within goto_offline() */
10825 case HLS_LINK_COOLDOWN: /* transient within goto_offline() */
10826 default:
10827 dd_dev_info(dd, "%s: state 0x%x: not supported\n",
Jubin John17fb4f22016-02-14 20:21:52 -080010828 __func__, state);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010829 ret = -EINVAL;
10830 break;
10831 }
10832
Mike Marciniszyn77241052015-07-30 15:17:43 -040010833 goto done;
10834
10835unexpected:
10836 dd_dev_err(dd, "%s: unexpected state transition from %s to %s\n",
Jubin John17fb4f22016-02-14 20:21:52 -080010837 __func__, link_state_name(ppd->host_link_state),
10838 link_state_name(state));
Mike Marciniszyn77241052015-07-30 15:17:43 -040010839 ret = -EINVAL;
10840
10841done:
10842 mutex_unlock(&ppd->hls_lock);
10843
10844 if (event.device)
10845 ib_dispatch_event(&event);
10846
10847 return ret;
10848}
10849
10850int hfi1_set_ib_cfg(struct hfi1_pportdata *ppd, int which, u32 val)
10851{
10852 u64 reg;
10853 int ret = 0;
10854
10855 switch (which) {
10856 case HFI1_IB_CFG_LIDLMC:
10857 set_lidlmc(ppd);
10858 break;
10859 case HFI1_IB_CFG_VL_HIGH_LIMIT:
10860 /*
10861 * The VL Arbitrator high limit is sent in units of 4k
10862 * bytes, while HFI stores it in units of 64 bytes.
10863 */
Jubin John8638b772016-02-14 20:19:24 -080010864 val *= 4096 / 64;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010865 reg = ((u64)val & SEND_HIGH_PRIORITY_LIMIT_LIMIT_MASK)
10866 << SEND_HIGH_PRIORITY_LIMIT_LIMIT_SHIFT;
10867 write_csr(ppd->dd, SEND_HIGH_PRIORITY_LIMIT, reg);
10868 break;
10869 case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
10870 /* HFI only supports POLL as the default link down state */
10871 if (val != HLS_DN_POLL)
10872 ret = -EINVAL;
10873 break;
10874 case HFI1_IB_CFG_OP_VLS:
10875 if (ppd->vls_operational != val) {
10876 ppd->vls_operational = val;
10877 if (!ppd->port)
10878 ret = -EINVAL;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010879 }
10880 break;
10881 /*
10882 * For link width, link width downgrade, and speed enable, always AND
10883 * the setting with what is actually supported. This has two benefits.
10884 * First, enabled can't have unsupported values, no matter what the
10885 * SM or FM might want. Second, the ALL_SUPPORTED wildcards that mean
10886 * "fill in with your supported value" have all the bits in the
10887 * field set, so simply ANDing with supported has the desired result.
10888 */
10889 case HFI1_IB_CFG_LWID_ENB: /* set allowed Link-width */
10890 ppd->link_width_enabled = val & ppd->link_width_supported;
10891 break;
10892 case HFI1_IB_CFG_LWID_DG_ENB: /* set allowed link width downgrade */
10893 ppd->link_width_downgrade_enabled =
10894 val & ppd->link_width_downgrade_supported;
10895 break;
10896 case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
10897 ppd->link_speed_enabled = val & ppd->link_speed_supported;
10898 break;
10899 case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
10900 /*
10901 * HFI does not follow IB specs, save this value
10902 * so we can report it, if asked.
10903 */
10904 ppd->overrun_threshold = val;
10905 break;
10906 case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
10907 /*
10908 * HFI does not follow IB specs, save this value
10909 * so we can report it, if asked.
10910 */
10911 ppd->phy_error_threshold = val;
10912 break;
10913
10914 case HFI1_IB_CFG_MTU:
10915 set_send_length(ppd);
10916 break;
10917
10918 case HFI1_IB_CFG_PKEYS:
10919 if (HFI1_CAP_IS_KSET(PKEY_CHECK))
10920 set_partition_keys(ppd);
10921 break;
10922
10923 default:
10924 if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
10925 dd_dev_info(ppd->dd,
Jubin John17fb4f22016-02-14 20:21:52 -080010926 "%s: which %s, val 0x%x: not implemented\n",
10927 __func__, ib_cfg_name(which), val);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010928 break;
10929 }
10930 return ret;
10931}
10932
10933/* begin functions related to vl arbitration table caching */
10934static void init_vl_arb_caches(struct hfi1_pportdata *ppd)
10935{
10936 int i;
10937
10938 BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
10939 VL_ARB_LOW_PRIO_TABLE_SIZE);
10940 BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
10941 VL_ARB_HIGH_PRIO_TABLE_SIZE);
10942
10943 /*
10944 * Note that we always return values directly from the
10945 * 'vl_arb_cache' (and do no CSR reads) in response to a
10946 * 'Get(VLArbTable)'. This is obviously correct after a
10947 * 'Set(VLArbTable)', since the cache will then be up to
10948 * date. But it's also correct prior to any 'Set(VLArbTable)'
10949 * since then both the cache, and the relevant h/w registers
10950 * will be zeroed.
10951 */
10952
10953 for (i = 0; i < MAX_PRIO_TABLE; i++)
10954 spin_lock_init(&ppd->vl_arb_cache[i].lock);
10955}
10956
10957/*
10958 * vl_arb_lock_cache
10959 *
10960 * All other vl_arb_* functions should be called only after locking
10961 * the cache.
10962 */
10963static inline struct vl_arb_cache *
10964vl_arb_lock_cache(struct hfi1_pportdata *ppd, int idx)
10965{
10966 if (idx != LO_PRIO_TABLE && idx != HI_PRIO_TABLE)
10967 return NULL;
10968 spin_lock(&ppd->vl_arb_cache[idx].lock);
10969 return &ppd->vl_arb_cache[idx];
10970}
10971
10972static inline void vl_arb_unlock_cache(struct hfi1_pportdata *ppd, int idx)
10973{
10974 spin_unlock(&ppd->vl_arb_cache[idx].lock);
10975}
10976
10977static void vl_arb_get_cache(struct vl_arb_cache *cache,
10978 struct ib_vl_weight_elem *vl)
10979{
10980 memcpy(vl, cache->table, VL_ARB_TABLE_SIZE * sizeof(*vl));
10981}
10982
10983static void vl_arb_set_cache(struct vl_arb_cache *cache,
10984 struct ib_vl_weight_elem *vl)
10985{
10986 memcpy(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
10987}
10988
10989static int vl_arb_match_cache(struct vl_arb_cache *cache,
10990 struct ib_vl_weight_elem *vl)
10991{
10992 return !memcmp(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
10993}
Jubin Johnf4d507c2016-02-14 20:20:25 -080010994
Mike Marciniszyn77241052015-07-30 15:17:43 -040010995/* end functions related to vl arbitration table caching */
10996
10997static int set_vl_weights(struct hfi1_pportdata *ppd, u32 target,
10998 u32 size, struct ib_vl_weight_elem *vl)
10999{
11000 struct hfi1_devdata *dd = ppd->dd;
11001 u64 reg;
11002 unsigned int i, is_up = 0;
11003 int drain, ret = 0;
11004
11005 mutex_lock(&ppd->hls_lock);
11006
11007 if (ppd->host_link_state & HLS_UP)
11008 is_up = 1;
11009
11010 drain = !is_ax(dd) && is_up;
11011
11012 if (drain)
11013 /*
11014 * Before adjusting VL arbitration weights, empty per-VL
11015 * FIFOs, otherwise a packet whose VL weight is being
11016 * set to 0 could get stuck in a FIFO with no chance to
11017 * egress.
11018 */
11019 ret = stop_drain_data_vls(dd);
11020
11021 if (ret) {
11022 dd_dev_err(
11023 dd,
11024 "%s: cannot stop/drain VLs - refusing to change VL arbitration weights\n",
11025 __func__);
11026 goto err;
11027 }
11028
11029 for (i = 0; i < size; i++, vl++) {
11030 /*
11031 * NOTE: The low priority shift and mask are used here, but
11032 * they are the same for both the low and high registers.
11033 */
11034 reg = (((u64)vl->vl & SEND_LOW_PRIORITY_LIST_VL_MASK)
11035 << SEND_LOW_PRIORITY_LIST_VL_SHIFT)
11036 | (((u64)vl->weight
11037 & SEND_LOW_PRIORITY_LIST_WEIGHT_MASK)
11038 << SEND_LOW_PRIORITY_LIST_WEIGHT_SHIFT);
11039 write_csr(dd, target + (i * 8), reg);
11040 }
11041 pio_send_control(dd, PSC_GLOBAL_VLARB_ENABLE);
11042
11043 if (drain)
11044 open_fill_data_vls(dd); /* reopen all VLs */
11045
11046err:
11047 mutex_unlock(&ppd->hls_lock);
11048
11049 return ret;
11050}
11051
11052/*
11053 * Read one credit merge VL register.
11054 */
11055static void read_one_cm_vl(struct hfi1_devdata *dd, u32 csr,
11056 struct vl_limit *vll)
11057{
11058 u64 reg = read_csr(dd, csr);
11059
11060 vll->dedicated = cpu_to_be16(
11061 (reg >> SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT)
11062 & SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_MASK);
11063 vll->shared = cpu_to_be16(
11064 (reg >> SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT)
11065 & SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_MASK);
11066}
11067
11068/*
11069 * Read the current credit merge limits.
11070 */
11071static int get_buffer_control(struct hfi1_devdata *dd,
11072 struct buffer_control *bc, u16 *overall_limit)
11073{
11074 u64 reg;
11075 int i;
11076
11077 /* not all entries are filled in */
11078 memset(bc, 0, sizeof(*bc));
11079
11080 /* OPA and HFI have a 1-1 mapping */
11081 for (i = 0; i < TXE_NUM_DATA_VL; i++)
Jubin John8638b772016-02-14 20:19:24 -080011082 read_one_cm_vl(dd, SEND_CM_CREDIT_VL + (8 * i), &bc->vl[i]);
Mike Marciniszyn77241052015-07-30 15:17:43 -040011083
11084 /* NOTE: assumes that VL* and VL15 CSRs are bit-wise identical */
11085 read_one_cm_vl(dd, SEND_CM_CREDIT_VL15, &bc->vl[15]);
11086
11087 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
11088 bc->overall_shared_limit = cpu_to_be16(
11089 (reg >> SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT)
11090 & SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_MASK);
11091 if (overall_limit)
11092 *overall_limit = (reg
11093 >> SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT)
11094 & SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_MASK;
11095 return sizeof(struct buffer_control);
11096}
11097
11098static int get_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
11099{
11100 u64 reg;
11101 int i;
11102
11103 /* each register contains 16 SC->VLnt mappings, 4 bits each */
11104 reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_15_0);
11105 for (i = 0; i < sizeof(u64); i++) {
11106 u8 byte = *(((u8 *)&reg) + i);
11107
11108 dp->vlnt[2 * i] = byte & 0xf;
11109 dp->vlnt[(2 * i) + 1] = (byte & 0xf0) >> 4;
11110 }
11111
11112 reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_31_16);
11113 for (i = 0; i < sizeof(u64); i++) {
11114 u8 byte = *(((u8 *)&reg) + i);
11115
11116 dp->vlnt[16 + (2 * i)] = byte & 0xf;
11117 dp->vlnt[16 + (2 * i) + 1] = (byte & 0xf0) >> 4;
11118 }
11119 return sizeof(struct sc2vlnt);
11120}
11121
11122static void get_vlarb_preempt(struct hfi1_devdata *dd, u32 nelems,
11123 struct ib_vl_weight_elem *vl)
11124{
11125 unsigned int i;
11126
11127 for (i = 0; i < nelems; i++, vl++) {
11128 vl->vl = 0xf;
11129 vl->weight = 0;
11130 }
11131}
11132
11133static void set_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
11134{
11135 write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0,
Jubin John17fb4f22016-02-14 20:21:52 -080011136 DC_SC_VL_VAL(15_0,
11137 0, dp->vlnt[0] & 0xf,
11138 1, dp->vlnt[1] & 0xf,
11139 2, dp->vlnt[2] & 0xf,
11140 3, dp->vlnt[3] & 0xf,
11141 4, dp->vlnt[4] & 0xf,
11142 5, dp->vlnt[5] & 0xf,
11143 6, dp->vlnt[6] & 0xf,
11144 7, dp->vlnt[7] & 0xf,
11145 8, dp->vlnt[8] & 0xf,
11146 9, dp->vlnt[9] & 0xf,
11147 10, dp->vlnt[10] & 0xf,
11148 11, dp->vlnt[11] & 0xf,
11149 12, dp->vlnt[12] & 0xf,
11150 13, dp->vlnt[13] & 0xf,
11151 14, dp->vlnt[14] & 0xf,
11152 15, dp->vlnt[15] & 0xf));
Mike Marciniszyn77241052015-07-30 15:17:43 -040011153 write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16,
Jubin John17fb4f22016-02-14 20:21:52 -080011154 DC_SC_VL_VAL(31_16,
11155 16, dp->vlnt[16] & 0xf,
11156 17, dp->vlnt[17] & 0xf,
11157 18, dp->vlnt[18] & 0xf,
11158 19, dp->vlnt[19] & 0xf,
11159 20, dp->vlnt[20] & 0xf,
11160 21, dp->vlnt[21] & 0xf,
11161 22, dp->vlnt[22] & 0xf,
11162 23, dp->vlnt[23] & 0xf,
11163 24, dp->vlnt[24] & 0xf,
11164 25, dp->vlnt[25] & 0xf,
11165 26, dp->vlnt[26] & 0xf,
11166 27, dp->vlnt[27] & 0xf,
11167 28, dp->vlnt[28] & 0xf,
11168 29, dp->vlnt[29] & 0xf,
11169 30, dp->vlnt[30] & 0xf,
11170 31, dp->vlnt[31] & 0xf));
Mike Marciniszyn77241052015-07-30 15:17:43 -040011171}
11172
11173static void nonzero_msg(struct hfi1_devdata *dd, int idx, const char *what,
11174 u16 limit)
11175{
11176 if (limit != 0)
11177 dd_dev_info(dd, "Invalid %s limit %d on VL %d, ignoring\n",
Jubin John17fb4f22016-02-14 20:21:52 -080011178 what, (int)limit, idx);
Mike Marciniszyn77241052015-07-30 15:17:43 -040011179}
11180
11181/* change only the shared limit portion of SendCmGLobalCredit */
11182static void set_global_shared(struct hfi1_devdata *dd, u16 limit)
11183{
11184 u64 reg;
11185
11186 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
11187 reg &= ~SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SMASK;
11188 reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT;
11189 write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
11190}
11191
11192/* change only the total credit limit portion of SendCmGLobalCredit */
11193static void set_global_limit(struct hfi1_devdata *dd, u16 limit)
11194{
11195 u64 reg;
11196
11197 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
11198 reg &= ~SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SMASK;
11199 reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT;
11200 write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
11201}
11202
11203/* set the given per-VL shared limit */
11204static void set_vl_shared(struct hfi1_devdata *dd, int vl, u16 limit)
11205{
11206 u64 reg;
11207 u32 addr;
11208
11209 if (vl < TXE_NUM_DATA_VL)
11210 addr = SEND_CM_CREDIT_VL + (8 * vl);
11211 else
11212 addr = SEND_CM_CREDIT_VL15;
11213
11214 reg = read_csr(dd, addr);
11215 reg &= ~SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SMASK;
11216 reg |= (u64)limit << SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT;
11217 write_csr(dd, addr, reg);
11218}
11219
11220/* set the given per-VL dedicated limit */
11221static void set_vl_dedicated(struct hfi1_devdata *dd, int vl, u16 limit)
11222{
11223 u64 reg;
11224 u32 addr;
11225
11226 if (vl < TXE_NUM_DATA_VL)
11227 addr = SEND_CM_CREDIT_VL + (8 * vl);
11228 else
11229 addr = SEND_CM_CREDIT_VL15;
11230
11231 reg = read_csr(dd, addr);
11232 reg &= ~SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SMASK;
11233 reg |= (u64)limit << SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT;
11234 write_csr(dd, addr, reg);
11235}
11236
11237/* spin until the given per-VL status mask bits clear */
11238static void wait_for_vl_status_clear(struct hfi1_devdata *dd, u64 mask,
11239 const char *which)
11240{
11241 unsigned long timeout;
11242 u64 reg;
11243
11244 timeout = jiffies + msecs_to_jiffies(VL_STATUS_CLEAR_TIMEOUT);
11245 while (1) {
11246 reg = read_csr(dd, SEND_CM_CREDIT_USED_STATUS) & mask;
11247
11248 if (reg == 0)
11249 return; /* success */
11250 if (time_after(jiffies, timeout))
11251 break; /* timed out */
11252 udelay(1);
11253 }
11254
11255 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -080011256 "%s credit change status not clearing after %dms, mask 0x%llx, not clear 0x%llx\n",
11257 which, VL_STATUS_CLEAR_TIMEOUT, mask, reg);
Mike Marciniszyn77241052015-07-30 15:17:43 -040011258 /*
11259 * If this occurs, it is likely there was a credit loss on the link.
11260 * The only recovery from that is a link bounce.
11261 */
11262 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -080011263 "Continuing anyway. A credit loss may occur. Suggest a link bounce\n");
Mike Marciniszyn77241052015-07-30 15:17:43 -040011264}
11265
11266/*
11267 * The number of credits on the VLs may be changed while everything
11268 * is "live", but the following algorithm must be followed due to
11269 * how the hardware is actually implemented. In particular,
11270 * Return_Credit_Status[] is the only correct status check.
11271 *
11272 * if (reducing Global_Shared_Credit_Limit or any shared limit changing)
11273 * set Global_Shared_Credit_Limit = 0
11274 * use_all_vl = 1
11275 * mask0 = all VLs that are changing either dedicated or shared limits
11276 * set Shared_Limit[mask0] = 0
11277 * spin until Return_Credit_Status[use_all_vl ? all VL : mask0] == 0
11278 * if (changing any dedicated limit)
11279 * mask1 = all VLs that are lowering dedicated limits
11280 * lower Dedicated_Limit[mask1]
11281 * spin until Return_Credit_Status[mask1] == 0
11282 * raise Dedicated_Limits
11283 * raise Shared_Limits
11284 * raise Global_Shared_Credit_Limit
11285 *
11286 * lower = if the new limit is lower, set the limit to the new value
11287 * raise = if the new limit is higher than the current value (may be changed
11288 * earlier in the algorithm), set the new limit to the new value
11289 */
Mike Marciniszyn8a4d3442016-02-14 12:46:01 -080011290int set_buffer_control(struct hfi1_pportdata *ppd,
11291 struct buffer_control *new_bc)
Mike Marciniszyn77241052015-07-30 15:17:43 -040011292{
Mike Marciniszyn8a4d3442016-02-14 12:46:01 -080011293 struct hfi1_devdata *dd = ppd->dd;
Mike Marciniszyn77241052015-07-30 15:17:43 -040011294 u64 changing_mask, ld_mask, stat_mask;
11295 int change_count;
11296 int i, use_all_mask;
11297 int this_shared_changing;
Mike Marciniszyn8a4d3442016-02-14 12:46:01 -080011298 int vl_count = 0, ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -040011299 /*
11300 * A0: add the variable any_shared_limit_changing below and in the
11301 * algorithm above. If removing A0 support, it can be removed.
11302 */
11303 int any_shared_limit_changing;
11304 struct buffer_control cur_bc;
11305 u8 changing[OPA_MAX_VLS];
11306 u8 lowering_dedicated[OPA_MAX_VLS];
11307 u16 cur_total;
11308 u32 new_total = 0;
11309 const u64 all_mask =
11310 SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK
11311 | SEND_CM_CREDIT_USED_STATUS_VL1_RETURN_CREDIT_STATUS_SMASK
11312 | SEND_CM_CREDIT_USED_STATUS_VL2_RETURN_CREDIT_STATUS_SMASK
11313 | SEND_CM_CREDIT_USED_STATUS_VL3_RETURN_CREDIT_STATUS_SMASK
11314 | SEND_CM_CREDIT_USED_STATUS_VL4_RETURN_CREDIT_STATUS_SMASK
11315 | SEND_CM_CREDIT_USED_STATUS_VL5_RETURN_CREDIT_STATUS_SMASK
11316 | SEND_CM_CREDIT_USED_STATUS_VL6_RETURN_CREDIT_STATUS_SMASK
11317 | SEND_CM_CREDIT_USED_STATUS_VL7_RETURN_CREDIT_STATUS_SMASK
11318 | SEND_CM_CREDIT_USED_STATUS_VL15_RETURN_CREDIT_STATUS_SMASK;
11319
11320#define valid_vl(idx) ((idx) < TXE_NUM_DATA_VL || (idx) == 15)
11321#define NUM_USABLE_VLS 16 /* look at VL15 and less */
11322
Mike Marciniszyn77241052015-07-30 15:17:43 -040011323 /* find the new total credits, do sanity check on unused VLs */
11324 for (i = 0; i < OPA_MAX_VLS; i++) {
11325 if (valid_vl(i)) {
11326 new_total += be16_to_cpu(new_bc->vl[i].dedicated);
11327 continue;
11328 }
11329 nonzero_msg(dd, i, "dedicated",
Jubin John17fb4f22016-02-14 20:21:52 -080011330 be16_to_cpu(new_bc->vl[i].dedicated));
Mike Marciniszyn77241052015-07-30 15:17:43 -040011331 nonzero_msg(dd, i, "shared",
Jubin John17fb4f22016-02-14 20:21:52 -080011332 be16_to_cpu(new_bc->vl[i].shared));
Mike Marciniszyn77241052015-07-30 15:17:43 -040011333 new_bc->vl[i].dedicated = 0;
11334 new_bc->vl[i].shared = 0;
11335 }
11336 new_total += be16_to_cpu(new_bc->overall_shared_limit);
Dean Luickbff14bb2015-12-17 19:24:13 -050011337
Mike Marciniszyn77241052015-07-30 15:17:43 -040011338 /* fetch the current values */
11339 get_buffer_control(dd, &cur_bc, &cur_total);
11340
11341 /*
11342 * Create the masks we will use.
11343 */
11344 memset(changing, 0, sizeof(changing));
11345 memset(lowering_dedicated, 0, sizeof(lowering_dedicated));
Jubin John4d114fd2016-02-14 20:21:43 -080011346 /*
11347 * NOTE: Assumes that the individual VL bits are adjacent and in
11348 * increasing order
11349 */
Mike Marciniszyn77241052015-07-30 15:17:43 -040011350 stat_mask =
11351 SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK;
11352 changing_mask = 0;
11353 ld_mask = 0;
11354 change_count = 0;
11355 any_shared_limit_changing = 0;
11356 for (i = 0; i < NUM_USABLE_VLS; i++, stat_mask <<= 1) {
11357 if (!valid_vl(i))
11358 continue;
11359 this_shared_changing = new_bc->vl[i].shared
11360 != cur_bc.vl[i].shared;
11361 if (this_shared_changing)
11362 any_shared_limit_changing = 1;
Jubin Johnd0d236e2016-02-14 20:20:15 -080011363 if (new_bc->vl[i].dedicated != cur_bc.vl[i].dedicated ||
11364 this_shared_changing) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040011365 changing[i] = 1;
11366 changing_mask |= stat_mask;
11367 change_count++;
11368 }
11369 if (be16_to_cpu(new_bc->vl[i].dedicated) <
11370 be16_to_cpu(cur_bc.vl[i].dedicated)) {
11371 lowering_dedicated[i] = 1;
11372 ld_mask |= stat_mask;
11373 }
11374 }
11375
11376 /* bracket the credit change with a total adjustment */
11377 if (new_total > cur_total)
11378 set_global_limit(dd, new_total);
11379
11380 /*
11381 * Start the credit change algorithm.
11382 */
11383 use_all_mask = 0;
11384 if ((be16_to_cpu(new_bc->overall_shared_limit) <
Mike Marciniszyn995deaf2015-11-16 21:59:29 -050011385 be16_to_cpu(cur_bc.overall_shared_limit)) ||
11386 (is_ax(dd) && any_shared_limit_changing)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040011387 set_global_shared(dd, 0);
11388 cur_bc.overall_shared_limit = 0;
11389 use_all_mask = 1;
11390 }
11391
11392 for (i = 0; i < NUM_USABLE_VLS; i++) {
11393 if (!valid_vl(i))
11394 continue;
11395
11396 if (changing[i]) {
11397 set_vl_shared(dd, i, 0);
11398 cur_bc.vl[i].shared = 0;
11399 }
11400 }
11401
11402 wait_for_vl_status_clear(dd, use_all_mask ? all_mask : changing_mask,
Jubin John17fb4f22016-02-14 20:21:52 -080011403 "shared");
Mike Marciniszyn77241052015-07-30 15:17:43 -040011404
11405 if (change_count > 0) {
11406 for (i = 0; i < NUM_USABLE_VLS; i++) {
11407 if (!valid_vl(i))
11408 continue;
11409
11410 if (lowering_dedicated[i]) {
11411 set_vl_dedicated(dd, i,
Jubin John17fb4f22016-02-14 20:21:52 -080011412 be16_to_cpu(new_bc->
11413 vl[i].dedicated));
Mike Marciniszyn77241052015-07-30 15:17:43 -040011414 cur_bc.vl[i].dedicated =
11415 new_bc->vl[i].dedicated;
11416 }
11417 }
11418
11419 wait_for_vl_status_clear(dd, ld_mask, "dedicated");
11420
11421 /* now raise all dedicated that are going up */
11422 for (i = 0; i < NUM_USABLE_VLS; i++) {
11423 if (!valid_vl(i))
11424 continue;
11425
11426 if (be16_to_cpu(new_bc->vl[i].dedicated) >
11427 be16_to_cpu(cur_bc.vl[i].dedicated))
11428 set_vl_dedicated(dd, i,
Jubin John17fb4f22016-02-14 20:21:52 -080011429 be16_to_cpu(new_bc->
11430 vl[i].dedicated));
Mike Marciniszyn77241052015-07-30 15:17:43 -040011431 }
11432 }
11433
11434 /* next raise all shared that are going up */
11435 for (i = 0; i < NUM_USABLE_VLS; i++) {
11436 if (!valid_vl(i))
11437 continue;
11438
11439 if (be16_to_cpu(new_bc->vl[i].shared) >
11440 be16_to_cpu(cur_bc.vl[i].shared))
11441 set_vl_shared(dd, i, be16_to_cpu(new_bc->vl[i].shared));
11442 }
11443
11444 /* finally raise the global shared */
11445 if (be16_to_cpu(new_bc->overall_shared_limit) >
Jubin John17fb4f22016-02-14 20:21:52 -080011446 be16_to_cpu(cur_bc.overall_shared_limit))
Mike Marciniszyn77241052015-07-30 15:17:43 -040011447 set_global_shared(dd,
Jubin John17fb4f22016-02-14 20:21:52 -080011448 be16_to_cpu(new_bc->overall_shared_limit));
Mike Marciniszyn77241052015-07-30 15:17:43 -040011449
11450 /* bracket the credit change with a total adjustment */
11451 if (new_total < cur_total)
11452 set_global_limit(dd, new_total);
Mike Marciniszyn8a4d3442016-02-14 12:46:01 -080011453
11454 /*
11455 * Determine the actual number of operational VLS using the number of
11456 * dedicated and shared credits for each VL.
11457 */
11458 if (change_count > 0) {
11459 for (i = 0; i < TXE_NUM_DATA_VL; i++)
11460 if (be16_to_cpu(new_bc->vl[i].dedicated) > 0 ||
11461 be16_to_cpu(new_bc->vl[i].shared) > 0)
11462 vl_count++;
11463 ppd->actual_vls_operational = vl_count;
11464 ret = sdma_map_init(dd, ppd->port - 1, vl_count ?
11465 ppd->actual_vls_operational :
11466 ppd->vls_operational,
11467 NULL);
11468 if (ret == 0)
11469 ret = pio_map_init(dd, ppd->port - 1, vl_count ?
11470 ppd->actual_vls_operational :
11471 ppd->vls_operational, NULL);
11472 if (ret)
11473 return ret;
11474 }
Mike Marciniszyn77241052015-07-30 15:17:43 -040011475 return 0;
11476}
11477
11478/*
11479 * Read the given fabric manager table. Return the size of the
11480 * table (in bytes) on success, and a negative error code on
11481 * failure.
11482 */
11483int fm_get_table(struct hfi1_pportdata *ppd, int which, void *t)
11484
11485{
11486 int size;
11487 struct vl_arb_cache *vlc;
11488
11489 switch (which) {
11490 case FM_TBL_VL_HIGH_ARB:
11491 size = 256;
11492 /*
11493 * OPA specifies 128 elements (of 2 bytes each), though
11494 * HFI supports only 16 elements in h/w.
11495 */
11496 vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
11497 vl_arb_get_cache(vlc, t);
11498 vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
11499 break;
11500 case FM_TBL_VL_LOW_ARB:
11501 size = 256;
11502 /*
11503 * OPA specifies 128 elements (of 2 bytes each), though
11504 * HFI supports only 16 elements in h/w.
11505 */
11506 vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
11507 vl_arb_get_cache(vlc, t);
11508 vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
11509 break;
11510 case FM_TBL_BUFFER_CONTROL:
11511 size = get_buffer_control(ppd->dd, t, NULL);
11512 break;
11513 case FM_TBL_SC2VLNT:
11514 size = get_sc2vlnt(ppd->dd, t);
11515 break;
11516 case FM_TBL_VL_PREEMPT_ELEMS:
11517 size = 256;
11518 /* OPA specifies 128 elements, of 2 bytes each */
11519 get_vlarb_preempt(ppd->dd, OPA_MAX_VLS, t);
11520 break;
11521 case FM_TBL_VL_PREEMPT_MATRIX:
11522 size = 256;
11523 /*
11524 * OPA specifies that this is the same size as the VL
11525 * arbitration tables (i.e., 256 bytes).
11526 */
11527 break;
11528 default:
11529 return -EINVAL;
11530 }
11531 return size;
11532}
11533
11534/*
11535 * Write the given fabric manager table.
11536 */
11537int fm_set_table(struct hfi1_pportdata *ppd, int which, void *t)
11538{
11539 int ret = 0;
11540 struct vl_arb_cache *vlc;
11541
11542 switch (which) {
11543 case FM_TBL_VL_HIGH_ARB:
11544 vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
11545 if (vl_arb_match_cache(vlc, t)) {
11546 vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
11547 break;
11548 }
11549 vl_arb_set_cache(vlc, t);
11550 vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
11551 ret = set_vl_weights(ppd, SEND_HIGH_PRIORITY_LIST,
11552 VL_ARB_HIGH_PRIO_TABLE_SIZE, t);
11553 break;
11554 case FM_TBL_VL_LOW_ARB:
11555 vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
11556 if (vl_arb_match_cache(vlc, t)) {
11557 vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
11558 break;
11559 }
11560 vl_arb_set_cache(vlc, t);
11561 vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
11562 ret = set_vl_weights(ppd, SEND_LOW_PRIORITY_LIST,
11563 VL_ARB_LOW_PRIO_TABLE_SIZE, t);
11564 break;
11565 case FM_TBL_BUFFER_CONTROL:
Mike Marciniszyn8a4d3442016-02-14 12:46:01 -080011566 ret = set_buffer_control(ppd, t);
Mike Marciniszyn77241052015-07-30 15:17:43 -040011567 break;
11568 case FM_TBL_SC2VLNT:
11569 set_sc2vlnt(ppd->dd, t);
11570 break;
11571 default:
11572 ret = -EINVAL;
11573 }
11574 return ret;
11575}
11576
11577/*
11578 * Disable all data VLs.
11579 *
11580 * Return 0 if disabled, non-zero if the VLs cannot be disabled.
11581 */
11582static int disable_data_vls(struct hfi1_devdata *dd)
11583{
Mike Marciniszyn995deaf2015-11-16 21:59:29 -050011584 if (is_ax(dd))
Mike Marciniszyn77241052015-07-30 15:17:43 -040011585 return 1;
11586
11587 pio_send_control(dd, PSC_DATA_VL_DISABLE);
11588
11589 return 0;
11590}
11591
11592/*
11593 * open_fill_data_vls() - the counterpart to stop_drain_data_vls().
11594 * Just re-enables all data VLs (the "fill" part happens
11595 * automatically - the name was chosen for symmetry with
11596 * stop_drain_data_vls()).
11597 *
11598 * Return 0 if successful, non-zero if the VLs cannot be enabled.
11599 */
11600int open_fill_data_vls(struct hfi1_devdata *dd)
11601{
Mike Marciniszyn995deaf2015-11-16 21:59:29 -050011602 if (is_ax(dd))
Mike Marciniszyn77241052015-07-30 15:17:43 -040011603 return 1;
11604
11605 pio_send_control(dd, PSC_DATA_VL_ENABLE);
11606
11607 return 0;
11608}
11609
11610/*
11611 * drain_data_vls() - assumes that disable_data_vls() has been called,
11612 * wait for occupancy (of per-VL FIFOs) for all contexts, and SDMA
11613 * engines to drop to 0.
11614 */
11615static void drain_data_vls(struct hfi1_devdata *dd)
11616{
11617 sc_wait(dd);
11618 sdma_wait(dd);
11619 pause_for_credit_return(dd);
11620}
11621
11622/*
11623 * stop_drain_data_vls() - disable, then drain all per-VL fifos.
11624 *
11625 * Use open_fill_data_vls() to resume using data VLs. This pair is
11626 * meant to be used like this:
11627 *
11628 * stop_drain_data_vls(dd);
11629 * // do things with per-VL resources
11630 * open_fill_data_vls(dd);
11631 */
11632int stop_drain_data_vls(struct hfi1_devdata *dd)
11633{
11634 int ret;
11635
11636 ret = disable_data_vls(dd);
11637 if (ret == 0)
11638 drain_data_vls(dd);
11639
11640 return ret;
11641}
11642
11643/*
11644 * Convert a nanosecond time to a cclock count. No matter how slow
11645 * the cclock, a non-zero ns will always have a non-zero result.
11646 */
11647u32 ns_to_cclock(struct hfi1_devdata *dd, u32 ns)
11648{
11649 u32 cclocks;
11650
11651 if (dd->icode == ICODE_FPGA_EMULATION)
11652 cclocks = (ns * 1000) / FPGA_CCLOCK_PS;
11653 else /* simulation pretends to be ASIC */
11654 cclocks = (ns * 1000) / ASIC_CCLOCK_PS;
11655 if (ns && !cclocks) /* if ns nonzero, must be at least 1 */
11656 cclocks = 1;
11657 return cclocks;
11658}
11659
11660/*
11661 * Convert a cclock count to nanoseconds. Not matter how slow
11662 * the cclock, a non-zero cclocks will always have a non-zero result.
11663 */
11664u32 cclock_to_ns(struct hfi1_devdata *dd, u32 cclocks)
11665{
11666 u32 ns;
11667
11668 if (dd->icode == ICODE_FPGA_EMULATION)
11669 ns = (cclocks * FPGA_CCLOCK_PS) / 1000;
11670 else /* simulation pretends to be ASIC */
11671 ns = (cclocks * ASIC_CCLOCK_PS) / 1000;
11672 if (cclocks && !ns)
11673 ns = 1;
11674 return ns;
11675}
11676
11677/*
11678 * Dynamically adjust the receive interrupt timeout for a context based on
11679 * incoming packet rate.
11680 *
11681 * NOTE: Dynamic adjustment does not allow rcv_intr_count to be zero.
11682 */
11683static void adjust_rcv_timeout(struct hfi1_ctxtdata *rcd, u32 npkts)
11684{
11685 struct hfi1_devdata *dd = rcd->dd;
11686 u32 timeout = rcd->rcvavail_timeout;
11687
11688 /*
11689 * This algorithm doubles or halves the timeout depending on whether
11690 * the number of packets received in this interrupt were less than or
11691 * greater equal the interrupt count.
11692 *
11693 * The calculations below do not allow a steady state to be achieved.
11694 * Only at the endpoints it is possible to have an unchanging
11695 * timeout.
11696 */
11697 if (npkts < rcv_intr_count) {
11698 /*
11699 * Not enough packets arrived before the timeout, adjust
11700 * timeout downward.
11701 */
11702 if (timeout < 2) /* already at minimum? */
11703 return;
11704 timeout >>= 1;
11705 } else {
11706 /*
11707 * More than enough packets arrived before the timeout, adjust
11708 * timeout upward.
11709 */
11710 if (timeout >= dd->rcv_intr_timeout_csr) /* already at max? */
11711 return;
11712 timeout = min(timeout << 1, dd->rcv_intr_timeout_csr);
11713 }
11714
11715 rcd->rcvavail_timeout = timeout;
Jubin John4d114fd2016-02-14 20:21:43 -080011716 /*
11717 * timeout cannot be larger than rcv_intr_timeout_csr which has already
11718 * been verified to be in range
11719 */
Mike Marciniszyn77241052015-07-30 15:17:43 -040011720 write_kctxt_csr(dd, rcd->ctxt, RCV_AVAIL_TIME_OUT,
Jubin John17fb4f22016-02-14 20:21:52 -080011721 (u64)timeout <<
11722 RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
Mike Marciniszyn77241052015-07-30 15:17:43 -040011723}
11724
11725void update_usrhead(struct hfi1_ctxtdata *rcd, u32 hd, u32 updegr, u32 egrhd,
11726 u32 intr_adjust, u32 npkts)
11727{
11728 struct hfi1_devdata *dd = rcd->dd;
11729 u64 reg;
11730 u32 ctxt = rcd->ctxt;
11731
11732 /*
11733 * Need to write timeout register before updating RcvHdrHead to ensure
11734 * that a new value is used when the HW decides to restart counting.
11735 */
11736 if (intr_adjust)
11737 adjust_rcv_timeout(rcd, npkts);
11738 if (updegr) {
11739 reg = (egrhd & RCV_EGR_INDEX_HEAD_HEAD_MASK)
11740 << RCV_EGR_INDEX_HEAD_HEAD_SHIFT;
11741 write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, reg);
11742 }
11743 mmiowb();
11744 reg = ((u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT) |
11745 (((u64)hd & RCV_HDR_HEAD_HEAD_MASK)
11746 << RCV_HDR_HEAD_HEAD_SHIFT);
11747 write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
11748 mmiowb();
11749}
11750
11751u32 hdrqempty(struct hfi1_ctxtdata *rcd)
11752{
11753 u32 head, tail;
11754
11755 head = (read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_HEAD)
11756 & RCV_HDR_HEAD_HEAD_SMASK) >> RCV_HDR_HEAD_HEAD_SHIFT;
11757
11758 if (rcd->rcvhdrtail_kvaddr)
11759 tail = get_rcvhdrtail(rcd);
11760 else
11761 tail = read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
11762
11763 return head == tail;
11764}
11765
11766/*
11767 * Context Control and Receive Array encoding for buffer size:
11768 * 0x0 invalid
11769 * 0x1 4 KB
11770 * 0x2 8 KB
11771 * 0x3 16 KB
11772 * 0x4 32 KB
11773 * 0x5 64 KB
11774 * 0x6 128 KB
11775 * 0x7 256 KB
11776 * 0x8 512 KB (Receive Array only)
11777 * 0x9 1 MB (Receive Array only)
11778 * 0xa 2 MB (Receive Array only)
11779 *
11780 * 0xB-0xF - reserved (Receive Array only)
11781 *
11782 *
11783 * This routine assumes that the value has already been sanity checked.
11784 */
11785static u32 encoded_size(u32 size)
11786{
11787 switch (size) {
Jubin John8638b772016-02-14 20:19:24 -080011788 case 4 * 1024: return 0x1;
11789 case 8 * 1024: return 0x2;
11790 case 16 * 1024: return 0x3;
11791 case 32 * 1024: return 0x4;
11792 case 64 * 1024: return 0x5;
11793 case 128 * 1024: return 0x6;
11794 case 256 * 1024: return 0x7;
11795 case 512 * 1024: return 0x8;
11796 case 1 * 1024 * 1024: return 0x9;
11797 case 2 * 1024 * 1024: return 0xa;
Mike Marciniszyn77241052015-07-30 15:17:43 -040011798 }
11799 return 0x1; /* if invalid, go with the minimum size */
11800}
11801
Michael J. Ruhl22505632017-07-24 07:46:06 -070011802void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op,
11803 struct hfi1_ctxtdata *rcd)
Mike Marciniszyn77241052015-07-30 15:17:43 -040011804{
Mike Marciniszyn77241052015-07-30 15:17:43 -040011805 u64 rcvctrl, reg;
11806 int did_enable = 0;
Michael J. Ruhl22505632017-07-24 07:46:06 -070011807 u16 ctxt;
Mike Marciniszyn77241052015-07-30 15:17:43 -040011808
Mike Marciniszyn77241052015-07-30 15:17:43 -040011809 if (!rcd)
11810 return;
11811
Michael J. Ruhl22505632017-07-24 07:46:06 -070011812 ctxt = rcd->ctxt;
11813
Mike Marciniszyn77241052015-07-30 15:17:43 -040011814 hfi1_cdbg(RCVCTRL, "ctxt %d op 0x%x", ctxt, op);
11815
11816 rcvctrl = read_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL);
11817 /* if the context already enabled, don't do the extra steps */
Jubin Johnd0d236e2016-02-14 20:20:15 -080011818 if ((op & HFI1_RCVCTRL_CTXT_ENB) &&
11819 !(rcvctrl & RCV_CTXT_CTRL_ENABLE_SMASK)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040011820 /* reset the tail and hdr addresses, and sequence count */
11821 write_kctxt_csr(dd, ctxt, RCV_HDR_ADDR,
Tymoteusz Kielan60368182016-09-06 04:35:54 -070011822 rcd->rcvhdrq_dma);
Mike Marciniszyn77241052015-07-30 15:17:43 -040011823 if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL))
11824 write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
Tymoteusz Kielan60368182016-09-06 04:35:54 -070011825 rcd->rcvhdrqtailaddr_dma);
Mike Marciniszyn77241052015-07-30 15:17:43 -040011826 rcd->seq_cnt = 1;
11827
11828 /* reset the cached receive header queue head value */
11829 rcd->head = 0;
11830
11831 /*
11832 * Zero the receive header queue so we don't get false
11833 * positives when checking the sequence number. The
11834 * sequence numbers could land exactly on the same spot.
11835 * E.g. a rcd restart before the receive header wrapped.
11836 */
11837 memset(rcd->rcvhdrq, 0, rcd->rcvhdrq_size);
11838
11839 /* starting timeout */
11840 rcd->rcvavail_timeout = dd->rcv_intr_timeout_csr;
11841
11842 /* enable the context */
11843 rcvctrl |= RCV_CTXT_CTRL_ENABLE_SMASK;
11844
11845 /* clean the egr buffer size first */
11846 rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
11847 rcvctrl |= ((u64)encoded_size(rcd->egrbufs.rcvtid_size)
11848 & RCV_CTXT_CTRL_EGR_BUF_SIZE_MASK)
11849 << RCV_CTXT_CTRL_EGR_BUF_SIZE_SHIFT;
11850
11851 /* zero RcvHdrHead - set RcvHdrHead.Counter after enable */
11852 write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0);
11853 did_enable = 1;
11854
11855 /* zero RcvEgrIndexHead */
11856 write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, 0);
11857
11858 /* set eager count and base index */
11859 reg = (((u64)(rcd->egrbufs.alloced >> RCV_SHIFT)
11860 & RCV_EGR_CTRL_EGR_CNT_MASK)
11861 << RCV_EGR_CTRL_EGR_CNT_SHIFT) |
11862 (((rcd->eager_base >> RCV_SHIFT)
11863 & RCV_EGR_CTRL_EGR_BASE_INDEX_MASK)
11864 << RCV_EGR_CTRL_EGR_BASE_INDEX_SHIFT);
11865 write_kctxt_csr(dd, ctxt, RCV_EGR_CTRL, reg);
11866
11867 /*
11868 * Set TID (expected) count and base index.
11869 * rcd->expected_count is set to individual RcvArray entries,
11870 * not pairs, and the CSR takes a pair-count in groups of
11871 * four, so divide by 8.
11872 */
11873 reg = (((rcd->expected_count >> RCV_SHIFT)
11874 & RCV_TID_CTRL_TID_PAIR_CNT_MASK)
11875 << RCV_TID_CTRL_TID_PAIR_CNT_SHIFT) |
11876 (((rcd->expected_base >> RCV_SHIFT)
11877 & RCV_TID_CTRL_TID_BASE_INDEX_MASK)
11878 << RCV_TID_CTRL_TID_BASE_INDEX_SHIFT);
11879 write_kctxt_csr(dd, ctxt, RCV_TID_CTRL, reg);
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -050011880 if (ctxt == HFI1_CTRL_CTXT)
11881 write_csr(dd, RCV_VL15, HFI1_CTRL_CTXT);
Mike Marciniszyn77241052015-07-30 15:17:43 -040011882 }
11883 if (op & HFI1_RCVCTRL_CTXT_DIS) {
11884 write_csr(dd, RCV_VL15, 0);
Mark F. Brown46b010d2015-11-09 19:18:20 -050011885 /*
11886 * When receive context is being disabled turn on tail
11887 * update with a dummy tail address and then disable
11888 * receive context.
11889 */
Tymoteusz Kielan60368182016-09-06 04:35:54 -070011890 if (dd->rcvhdrtail_dummy_dma) {
Mark F. Brown46b010d2015-11-09 19:18:20 -050011891 write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
Tymoteusz Kielan60368182016-09-06 04:35:54 -070011892 dd->rcvhdrtail_dummy_dma);
Mitko Haralanov566c1572016-02-03 14:32:49 -080011893 /* Enabling RcvCtxtCtrl.TailUpd is intentional. */
Mark F. Brown46b010d2015-11-09 19:18:20 -050011894 rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
11895 }
11896
Mike Marciniszyn77241052015-07-30 15:17:43 -040011897 rcvctrl &= ~RCV_CTXT_CTRL_ENABLE_SMASK;
11898 }
11899 if (op & HFI1_RCVCTRL_INTRAVAIL_ENB)
11900 rcvctrl |= RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
11901 if (op & HFI1_RCVCTRL_INTRAVAIL_DIS)
11902 rcvctrl &= ~RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
Tymoteusz Kielan60368182016-09-06 04:35:54 -070011903 if (op & HFI1_RCVCTRL_TAILUPD_ENB && rcd->rcvhdrqtailaddr_dma)
Mike Marciniszyn77241052015-07-30 15:17:43 -040011904 rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
Mitko Haralanov566c1572016-02-03 14:32:49 -080011905 if (op & HFI1_RCVCTRL_TAILUPD_DIS) {
11906 /* See comment on RcvCtxtCtrl.TailUpd above */
11907 if (!(op & HFI1_RCVCTRL_CTXT_DIS))
11908 rcvctrl &= ~RCV_CTXT_CTRL_TAIL_UPD_SMASK;
11909 }
Mike Marciniszyn77241052015-07-30 15:17:43 -040011910 if (op & HFI1_RCVCTRL_TIDFLOW_ENB)
11911 rcvctrl |= RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
11912 if (op & HFI1_RCVCTRL_TIDFLOW_DIS)
11913 rcvctrl &= ~RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
11914 if (op & HFI1_RCVCTRL_ONE_PKT_EGR_ENB) {
Jubin John4d114fd2016-02-14 20:21:43 -080011915 /*
11916 * In one-packet-per-eager mode, the size comes from
11917 * the RcvArray entry.
11918 */
Mike Marciniszyn77241052015-07-30 15:17:43 -040011919 rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
11920 rcvctrl |= RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
11921 }
11922 if (op & HFI1_RCVCTRL_ONE_PKT_EGR_DIS)
11923 rcvctrl &= ~RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
11924 if (op & HFI1_RCVCTRL_NO_RHQ_DROP_ENB)
11925 rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
11926 if (op & HFI1_RCVCTRL_NO_RHQ_DROP_DIS)
11927 rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
11928 if (op & HFI1_RCVCTRL_NO_EGR_DROP_ENB)
11929 rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
11930 if (op & HFI1_RCVCTRL_NO_EGR_DROP_DIS)
11931 rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
11932 rcd->rcvctrl = rcvctrl;
11933 hfi1_cdbg(RCVCTRL, "ctxt %d rcvctrl 0x%llx\n", ctxt, rcvctrl);
11934 write_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL, rcd->rcvctrl);
11935
11936 /* work around sticky RcvCtxtStatus.BlockedRHQFull */
Jubin Johnd0d236e2016-02-14 20:20:15 -080011937 if (did_enable &&
11938 (rcvctrl & RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040011939 reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
11940 if (reg != 0) {
11941 dd_dev_info(dd, "ctxt %d status %lld (blocked)\n",
Jubin John17fb4f22016-02-14 20:21:52 -080011942 ctxt, reg);
Mike Marciniszyn77241052015-07-30 15:17:43 -040011943 read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
11944 write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x10);
11945 write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x00);
11946 read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
11947 reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
11948 dd_dev_info(dd, "ctxt %d status %lld (%s blocked)\n",
Jubin John17fb4f22016-02-14 20:21:52 -080011949 ctxt, reg, reg == 0 ? "not" : "still");
Mike Marciniszyn77241052015-07-30 15:17:43 -040011950 }
11951 }
11952
11953 if (did_enable) {
11954 /*
11955 * The interrupt timeout and count must be set after
11956 * the context is enabled to take effect.
11957 */
11958 /* set interrupt timeout */
11959 write_kctxt_csr(dd, ctxt, RCV_AVAIL_TIME_OUT,
Jubin John17fb4f22016-02-14 20:21:52 -080011960 (u64)rcd->rcvavail_timeout <<
Mike Marciniszyn77241052015-07-30 15:17:43 -040011961 RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
11962
11963 /* set RcvHdrHead.Counter, zero RcvHdrHead.Head (again) */
11964 reg = (u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT;
11965 write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
11966 }
11967
11968 if (op & (HFI1_RCVCTRL_TAILUPD_DIS | HFI1_RCVCTRL_CTXT_DIS))
11969 /*
11970 * If the context has been disabled and the Tail Update has
Mark F. Brown46b010d2015-11-09 19:18:20 -050011971 * been cleared, set the RCV_HDR_TAIL_ADDR CSR to dummy address
11972 * so it doesn't contain an address that is invalid.
Mike Marciniszyn77241052015-07-30 15:17:43 -040011973 */
Mark F. Brown46b010d2015-11-09 19:18:20 -050011974 write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
Tymoteusz Kielan60368182016-09-06 04:35:54 -070011975 dd->rcvhdrtail_dummy_dma);
Mike Marciniszyn77241052015-07-30 15:17:43 -040011976}
11977
Dean Luick582e05c2016-02-18 11:13:01 -080011978u32 hfi1_read_cntrs(struct hfi1_devdata *dd, char **namep, u64 **cntrp)
Mike Marciniszyn77241052015-07-30 15:17:43 -040011979{
11980 int ret;
11981 u64 val = 0;
11982
11983 if (namep) {
11984 ret = dd->cntrnameslen;
Mike Marciniszyn77241052015-07-30 15:17:43 -040011985 *namep = dd->cntrnames;
11986 } else {
11987 const struct cntr_entry *entry;
11988 int i, j;
11989
11990 ret = (dd->ndevcntrs) * sizeof(u64);
Mike Marciniszyn77241052015-07-30 15:17:43 -040011991
11992 /* Get the start of the block of counters */
11993 *cntrp = dd->cntrs;
11994
11995 /*
11996 * Now go and fill in each counter in the block.
11997 */
11998 for (i = 0; i < DEV_CNTR_LAST; i++) {
11999 entry = &dev_cntrs[i];
12000 hfi1_cdbg(CNTR, "reading %s", entry->name);
12001 if (entry->flags & CNTR_DISABLED) {
12002 /* Nothing */
12003 hfi1_cdbg(CNTR, "\tDisabled\n");
12004 } else {
12005 if (entry->flags & CNTR_VL) {
12006 hfi1_cdbg(CNTR, "\tPer VL\n");
12007 for (j = 0; j < C_VL_COUNT; j++) {
12008 val = entry->rw_cntr(entry,
12009 dd, j,
12010 CNTR_MODE_R,
12011 0);
12012 hfi1_cdbg(
12013 CNTR,
12014 "\t\tRead 0x%llx for %d\n",
12015 val, j);
12016 dd->cntrs[entry->offset + j] =
12017 val;
12018 }
Vennila Megavannana699c6c2016-01-11 18:30:56 -050012019 } else if (entry->flags & CNTR_SDMA) {
12020 hfi1_cdbg(CNTR,
12021 "\t Per SDMA Engine\n");
12022 for (j = 0; j < dd->chip_sdma_engines;
12023 j++) {
12024 val =
12025 entry->rw_cntr(entry, dd, j,
12026 CNTR_MODE_R, 0);
12027 hfi1_cdbg(CNTR,
12028 "\t\tRead 0x%llx for %d\n",
12029 val, j);
12030 dd->cntrs[entry->offset + j] =
12031 val;
12032 }
Mike Marciniszyn77241052015-07-30 15:17:43 -040012033 } else {
12034 val = entry->rw_cntr(entry, dd,
12035 CNTR_INVALID_VL,
12036 CNTR_MODE_R, 0);
12037 dd->cntrs[entry->offset] = val;
12038 hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
12039 }
12040 }
12041 }
12042 }
12043 return ret;
12044}
12045
12046/*
12047 * Used by sysfs to create files for hfi stats to read
12048 */
Dean Luick582e05c2016-02-18 11:13:01 -080012049u32 hfi1_read_portcntrs(struct hfi1_pportdata *ppd, char **namep, u64 **cntrp)
Mike Marciniszyn77241052015-07-30 15:17:43 -040012050{
12051 int ret;
12052 u64 val = 0;
12053
12054 if (namep) {
Dean Luick582e05c2016-02-18 11:13:01 -080012055 ret = ppd->dd->portcntrnameslen;
12056 *namep = ppd->dd->portcntrnames;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012057 } else {
12058 const struct cntr_entry *entry;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012059 int i, j;
12060
Dean Luick582e05c2016-02-18 11:13:01 -080012061 ret = ppd->dd->nportcntrs * sizeof(u64);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012062 *cntrp = ppd->cntrs;
12063
12064 for (i = 0; i < PORT_CNTR_LAST; i++) {
12065 entry = &port_cntrs[i];
12066 hfi1_cdbg(CNTR, "reading %s", entry->name);
12067 if (entry->flags & CNTR_DISABLED) {
12068 /* Nothing */
12069 hfi1_cdbg(CNTR, "\tDisabled\n");
12070 continue;
12071 }
12072
12073 if (entry->flags & CNTR_VL) {
12074 hfi1_cdbg(CNTR, "\tPer VL");
12075 for (j = 0; j < C_VL_COUNT; j++) {
12076 val = entry->rw_cntr(entry, ppd, j,
12077 CNTR_MODE_R,
12078 0);
12079 hfi1_cdbg(
12080 CNTR,
12081 "\t\tRead 0x%llx for %d",
12082 val, j);
12083 ppd->cntrs[entry->offset + j] = val;
12084 }
12085 } else {
12086 val = entry->rw_cntr(entry, ppd,
12087 CNTR_INVALID_VL,
12088 CNTR_MODE_R,
12089 0);
12090 ppd->cntrs[entry->offset] = val;
12091 hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
12092 }
12093 }
12094 }
12095 return ret;
12096}
12097
12098static void free_cntrs(struct hfi1_devdata *dd)
12099{
12100 struct hfi1_pportdata *ppd;
12101 int i;
12102
12103 if (dd->synth_stats_timer.data)
12104 del_timer_sync(&dd->synth_stats_timer);
12105 dd->synth_stats_timer.data = 0;
12106 ppd = (struct hfi1_pportdata *)(dd + 1);
12107 for (i = 0; i < dd->num_pports; i++, ppd++) {
12108 kfree(ppd->cntrs);
12109 kfree(ppd->scntrs);
Dennis Dalessandro4eb06882016-01-19 14:42:39 -080012110 free_percpu(ppd->ibport_data.rvp.rc_acks);
12111 free_percpu(ppd->ibport_data.rvp.rc_qacks);
12112 free_percpu(ppd->ibport_data.rvp.rc_delayed_comp);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012113 ppd->cntrs = NULL;
12114 ppd->scntrs = NULL;
Dennis Dalessandro4eb06882016-01-19 14:42:39 -080012115 ppd->ibport_data.rvp.rc_acks = NULL;
12116 ppd->ibport_data.rvp.rc_qacks = NULL;
12117 ppd->ibport_data.rvp.rc_delayed_comp = NULL;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012118 }
12119 kfree(dd->portcntrnames);
12120 dd->portcntrnames = NULL;
12121 kfree(dd->cntrs);
12122 dd->cntrs = NULL;
12123 kfree(dd->scntrs);
12124 dd->scntrs = NULL;
12125 kfree(dd->cntrnames);
12126 dd->cntrnames = NULL;
Tadeusz Struk22546b72017-04-28 10:40:02 -070012127 if (dd->update_cntr_wq) {
12128 destroy_workqueue(dd->update_cntr_wq);
12129 dd->update_cntr_wq = NULL;
12130 }
Mike Marciniszyn77241052015-07-30 15:17:43 -040012131}
12132
Mike Marciniszyn77241052015-07-30 15:17:43 -040012133static u64 read_dev_port_cntr(struct hfi1_devdata *dd, struct cntr_entry *entry,
12134 u64 *psval, void *context, int vl)
12135{
12136 u64 val;
12137 u64 sval = *psval;
12138
12139 if (entry->flags & CNTR_DISABLED) {
12140 dd_dev_err(dd, "Counter %s not enabled", entry->name);
12141 return 0;
12142 }
12143
12144 hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
12145
12146 val = entry->rw_cntr(entry, context, vl, CNTR_MODE_R, 0);
12147
12148 /* If its a synthetic counter there is more work we need to do */
12149 if (entry->flags & CNTR_SYNTH) {
12150 if (sval == CNTR_MAX) {
12151 /* No need to read already saturated */
12152 return CNTR_MAX;
12153 }
12154
12155 if (entry->flags & CNTR_32BIT) {
12156 /* 32bit counters can wrap multiple times */
12157 u64 upper = sval >> 32;
12158 u64 lower = (sval << 32) >> 32;
12159
12160 if (lower > val) { /* hw wrapped */
12161 if (upper == CNTR_32BIT_MAX)
12162 val = CNTR_MAX;
12163 else
12164 upper++;
12165 }
12166
12167 if (val != CNTR_MAX)
12168 val = (upper << 32) | val;
12169
12170 } else {
12171 /* If we rolled we are saturated */
12172 if ((val < sval) || (val > CNTR_MAX))
12173 val = CNTR_MAX;
12174 }
12175 }
12176
12177 *psval = val;
12178
12179 hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
12180
12181 return val;
12182}
12183
12184static u64 write_dev_port_cntr(struct hfi1_devdata *dd,
12185 struct cntr_entry *entry,
12186 u64 *psval, void *context, int vl, u64 data)
12187{
12188 u64 val;
12189
12190 if (entry->flags & CNTR_DISABLED) {
12191 dd_dev_err(dd, "Counter %s not enabled", entry->name);
12192 return 0;
12193 }
12194
12195 hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
12196
12197 if (entry->flags & CNTR_SYNTH) {
12198 *psval = data;
12199 if (entry->flags & CNTR_32BIT) {
12200 val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
12201 (data << 32) >> 32);
12202 val = data; /* return the full 64bit value */
12203 } else {
12204 val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
12205 data);
12206 }
12207 } else {
12208 val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W, data);
12209 }
12210
12211 *psval = val;
12212
12213 hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
12214
12215 return val;
12216}
12217
12218u64 read_dev_cntr(struct hfi1_devdata *dd, int index, int vl)
12219{
12220 struct cntr_entry *entry;
12221 u64 *sval;
12222
12223 entry = &dev_cntrs[index];
12224 sval = dd->scntrs + entry->offset;
12225
12226 if (vl != CNTR_INVALID_VL)
12227 sval += vl;
12228
12229 return read_dev_port_cntr(dd, entry, sval, dd, vl);
12230}
12231
12232u64 write_dev_cntr(struct hfi1_devdata *dd, int index, int vl, u64 data)
12233{
12234 struct cntr_entry *entry;
12235 u64 *sval;
12236
12237 entry = &dev_cntrs[index];
12238 sval = dd->scntrs + entry->offset;
12239
12240 if (vl != CNTR_INVALID_VL)
12241 sval += vl;
12242
12243 return write_dev_port_cntr(dd, entry, sval, dd, vl, data);
12244}
12245
12246u64 read_port_cntr(struct hfi1_pportdata *ppd, int index, int vl)
12247{
12248 struct cntr_entry *entry;
12249 u64 *sval;
12250
12251 entry = &port_cntrs[index];
12252 sval = ppd->scntrs + entry->offset;
12253
12254 if (vl != CNTR_INVALID_VL)
12255 sval += vl;
12256
12257 if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
12258 (index <= C_RCV_HDR_OVF_LAST)) {
12259 /* We do not want to bother for disabled contexts */
12260 return 0;
12261 }
12262
12263 return read_dev_port_cntr(ppd->dd, entry, sval, ppd, vl);
12264}
12265
12266u64 write_port_cntr(struct hfi1_pportdata *ppd, int index, int vl, u64 data)
12267{
12268 struct cntr_entry *entry;
12269 u64 *sval;
12270
12271 entry = &port_cntrs[index];
12272 sval = ppd->scntrs + entry->offset;
12273
12274 if (vl != CNTR_INVALID_VL)
12275 sval += vl;
12276
12277 if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
12278 (index <= C_RCV_HDR_OVF_LAST)) {
12279 /* We do not want to bother for disabled contexts */
12280 return 0;
12281 }
12282
12283 return write_dev_port_cntr(ppd->dd, entry, sval, ppd, vl, data);
12284}
12285
Tadeusz Struk22546b72017-04-28 10:40:02 -070012286static void do_update_synth_timer(struct work_struct *work)
Mike Marciniszyn77241052015-07-30 15:17:43 -040012287{
12288 u64 cur_tx;
12289 u64 cur_rx;
12290 u64 total_flits;
12291 u8 update = 0;
12292 int i, j, vl;
12293 struct hfi1_pportdata *ppd;
12294 struct cntr_entry *entry;
Tadeusz Struk22546b72017-04-28 10:40:02 -070012295 struct hfi1_devdata *dd = container_of(work, struct hfi1_devdata,
12296 update_cntr_work);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012297
12298 /*
12299 * Rather than keep beating on the CSRs pick a minimal set that we can
12300 * check to watch for potential roll over. We can do this by looking at
12301 * the number of flits sent/recv. If the total flits exceeds 32bits then
12302 * we have to iterate all the counters and update.
12303 */
12304 entry = &dev_cntrs[C_DC_RCV_FLITS];
12305 cur_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
12306
12307 entry = &dev_cntrs[C_DC_XMIT_FLITS];
12308 cur_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
12309
12310 hfi1_cdbg(
12311 CNTR,
12312 "[%d] curr tx=0x%llx rx=0x%llx :: last tx=0x%llx rx=0x%llx\n",
12313 dd->unit, cur_tx, cur_rx, dd->last_tx, dd->last_rx);
12314
12315 if ((cur_tx < dd->last_tx) || (cur_rx < dd->last_rx)) {
12316 /*
12317 * May not be strictly necessary to update but it won't hurt and
12318 * simplifies the logic here.
12319 */
12320 update = 1;
12321 hfi1_cdbg(CNTR, "[%d] Tripwire counter rolled, updating",
12322 dd->unit);
12323 } else {
12324 total_flits = (cur_tx - dd->last_tx) + (cur_rx - dd->last_rx);
12325 hfi1_cdbg(CNTR,
12326 "[%d] total flits 0x%llx limit 0x%llx\n", dd->unit,
12327 total_flits, (u64)CNTR_32BIT_MAX);
12328 if (total_flits >= CNTR_32BIT_MAX) {
12329 hfi1_cdbg(CNTR, "[%d] 32bit limit hit, updating",
12330 dd->unit);
12331 update = 1;
12332 }
12333 }
12334
12335 if (update) {
12336 hfi1_cdbg(CNTR, "[%d] Updating dd and ppd counters", dd->unit);
12337 for (i = 0; i < DEV_CNTR_LAST; i++) {
12338 entry = &dev_cntrs[i];
12339 if (entry->flags & CNTR_VL) {
12340 for (vl = 0; vl < C_VL_COUNT; vl++)
12341 read_dev_cntr(dd, i, vl);
12342 } else {
12343 read_dev_cntr(dd, i, CNTR_INVALID_VL);
12344 }
12345 }
12346 ppd = (struct hfi1_pportdata *)(dd + 1);
12347 for (i = 0; i < dd->num_pports; i++, ppd++) {
12348 for (j = 0; j < PORT_CNTR_LAST; j++) {
12349 entry = &port_cntrs[j];
12350 if (entry->flags & CNTR_VL) {
12351 for (vl = 0; vl < C_VL_COUNT; vl++)
12352 read_port_cntr(ppd, j, vl);
12353 } else {
12354 read_port_cntr(ppd, j, CNTR_INVALID_VL);
12355 }
12356 }
12357 }
12358
12359 /*
12360 * We want the value in the register. The goal is to keep track
12361 * of the number of "ticks" not the counter value. In other
12362 * words if the register rolls we want to notice it and go ahead
12363 * and force an update.
12364 */
12365 entry = &dev_cntrs[C_DC_XMIT_FLITS];
12366 dd->last_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
12367 CNTR_MODE_R, 0);
12368
12369 entry = &dev_cntrs[C_DC_RCV_FLITS];
12370 dd->last_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
12371 CNTR_MODE_R, 0);
12372
12373 hfi1_cdbg(CNTR, "[%d] setting last tx/rx to 0x%llx 0x%llx",
12374 dd->unit, dd->last_tx, dd->last_rx);
12375
12376 } else {
12377 hfi1_cdbg(CNTR, "[%d] No update necessary", dd->unit);
12378 }
Tadeusz Struk22546b72017-04-28 10:40:02 -070012379}
Mike Marciniszyn77241052015-07-30 15:17:43 -040012380
Tadeusz Struk22546b72017-04-28 10:40:02 -070012381static void update_synth_timer(unsigned long opaque)
12382{
12383 struct hfi1_devdata *dd = (struct hfi1_devdata *)opaque;
12384
12385 queue_work(dd->update_cntr_wq, &dd->update_cntr_work);
Bart Van Assche48a0cc132016-06-03 12:09:56 -070012386 mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012387}
12388
Jianxin Xiong09a79082016-10-25 13:12:40 -070012389#define C_MAX_NAME 16 /* 15 chars + one for /0 */
Mike Marciniszyn77241052015-07-30 15:17:43 -040012390static int init_cntrs(struct hfi1_devdata *dd)
12391{
Dean Luickc024c552016-01-11 18:30:57 -050012392 int i, rcv_ctxts, j;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012393 size_t sz;
12394 char *p;
12395 char name[C_MAX_NAME];
12396 struct hfi1_pportdata *ppd;
Sebastian Sanchez11d2b112016-02-03 14:32:40 -080012397 const char *bit_type_32 = ",32";
12398 const int bit_type_32_sz = strlen(bit_type_32);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012399
12400 /* set up the stats timer; the add_timer is done at the end */
Muhammad Falak R Wani24523a92015-10-25 16:13:23 +053012401 setup_timer(&dd->synth_stats_timer, update_synth_timer,
12402 (unsigned long)dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012403
12404 /***********************/
12405 /* per device counters */
12406 /***********************/
12407
12408 /* size names and determine how many we have*/
12409 dd->ndevcntrs = 0;
12410 sz = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012411
12412 for (i = 0; i < DEV_CNTR_LAST; i++) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040012413 if (dev_cntrs[i].flags & CNTR_DISABLED) {
12414 hfi1_dbg_early("\tSkipping %s\n", dev_cntrs[i].name);
12415 continue;
12416 }
12417
12418 if (dev_cntrs[i].flags & CNTR_VL) {
Dean Luickc024c552016-01-11 18:30:57 -050012419 dev_cntrs[i].offset = dd->ndevcntrs;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012420 for (j = 0; j < C_VL_COUNT; j++) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040012421 snprintf(name, C_MAX_NAME, "%s%d",
Jubin John17fb4f22016-02-14 20:21:52 -080012422 dev_cntrs[i].name, vl_from_idx(j));
Mike Marciniszyn77241052015-07-30 15:17:43 -040012423 sz += strlen(name);
Sebastian Sanchez11d2b112016-02-03 14:32:40 -080012424 /* Add ",32" for 32-bit counters */
12425 if (dev_cntrs[i].flags & CNTR_32BIT)
12426 sz += bit_type_32_sz;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012427 sz++;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012428 dd->ndevcntrs++;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012429 }
Vennila Megavannana699c6c2016-01-11 18:30:56 -050012430 } else if (dev_cntrs[i].flags & CNTR_SDMA) {
Dean Luickc024c552016-01-11 18:30:57 -050012431 dev_cntrs[i].offset = dd->ndevcntrs;
Vennila Megavannana699c6c2016-01-11 18:30:56 -050012432 for (j = 0; j < dd->chip_sdma_engines; j++) {
Vennila Megavannana699c6c2016-01-11 18:30:56 -050012433 snprintf(name, C_MAX_NAME, "%s%d",
12434 dev_cntrs[i].name, j);
12435 sz += strlen(name);
Sebastian Sanchez11d2b112016-02-03 14:32:40 -080012436 /* Add ",32" for 32-bit counters */
12437 if (dev_cntrs[i].flags & CNTR_32BIT)
12438 sz += bit_type_32_sz;
Vennila Megavannana699c6c2016-01-11 18:30:56 -050012439 sz++;
Vennila Megavannana699c6c2016-01-11 18:30:56 -050012440 dd->ndevcntrs++;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012441 }
12442 } else {
Sebastian Sanchez11d2b112016-02-03 14:32:40 -080012443 /* +1 for newline. */
Mike Marciniszyn77241052015-07-30 15:17:43 -040012444 sz += strlen(dev_cntrs[i].name) + 1;
Sebastian Sanchez11d2b112016-02-03 14:32:40 -080012445 /* Add ",32" for 32-bit counters */
12446 if (dev_cntrs[i].flags & CNTR_32BIT)
12447 sz += bit_type_32_sz;
Dean Luickc024c552016-01-11 18:30:57 -050012448 dev_cntrs[i].offset = dd->ndevcntrs;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012449 dd->ndevcntrs++;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012450 }
12451 }
12452
12453 /* allocate space for the counter values */
Dean Luickc024c552016-01-11 18:30:57 -050012454 dd->cntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012455 if (!dd->cntrs)
12456 goto bail;
12457
Dean Luickc024c552016-01-11 18:30:57 -050012458 dd->scntrs = kcalloc(dd->ndevcntrs, sizeof(u64), GFP_KERNEL);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012459 if (!dd->scntrs)
12460 goto bail;
12461
Mike Marciniszyn77241052015-07-30 15:17:43 -040012462 /* allocate space for the counter names */
12463 dd->cntrnameslen = sz;
12464 dd->cntrnames = kmalloc(sz, GFP_KERNEL);
12465 if (!dd->cntrnames)
12466 goto bail;
12467
12468 /* fill in the names */
Dean Luickc024c552016-01-11 18:30:57 -050012469 for (p = dd->cntrnames, i = 0; i < DEV_CNTR_LAST; i++) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040012470 if (dev_cntrs[i].flags & CNTR_DISABLED) {
12471 /* Nothing */
Sebastian Sanchez11d2b112016-02-03 14:32:40 -080012472 } else if (dev_cntrs[i].flags & CNTR_VL) {
12473 for (j = 0; j < C_VL_COUNT; j++) {
Sebastian Sanchez11d2b112016-02-03 14:32:40 -080012474 snprintf(name, C_MAX_NAME, "%s%d",
12475 dev_cntrs[i].name,
12476 vl_from_idx(j));
12477 memcpy(p, name, strlen(name));
12478 p += strlen(name);
12479
12480 /* Counter is 32 bits */
12481 if (dev_cntrs[i].flags & CNTR_32BIT) {
12482 memcpy(p, bit_type_32, bit_type_32_sz);
12483 p += bit_type_32_sz;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012484 }
Sebastian Sanchez11d2b112016-02-03 14:32:40 -080012485
Mike Marciniszyn77241052015-07-30 15:17:43 -040012486 *p++ = '\n';
12487 }
Sebastian Sanchez11d2b112016-02-03 14:32:40 -080012488 } else if (dev_cntrs[i].flags & CNTR_SDMA) {
12489 for (j = 0; j < dd->chip_sdma_engines; j++) {
Sebastian Sanchez11d2b112016-02-03 14:32:40 -080012490 snprintf(name, C_MAX_NAME, "%s%d",
12491 dev_cntrs[i].name, j);
12492 memcpy(p, name, strlen(name));
12493 p += strlen(name);
12494
12495 /* Counter is 32 bits */
12496 if (dev_cntrs[i].flags & CNTR_32BIT) {
12497 memcpy(p, bit_type_32, bit_type_32_sz);
12498 p += bit_type_32_sz;
12499 }
12500
12501 *p++ = '\n';
12502 }
12503 } else {
12504 memcpy(p, dev_cntrs[i].name, strlen(dev_cntrs[i].name));
12505 p += strlen(dev_cntrs[i].name);
12506
12507 /* Counter is 32 bits */
12508 if (dev_cntrs[i].flags & CNTR_32BIT) {
12509 memcpy(p, bit_type_32, bit_type_32_sz);
12510 p += bit_type_32_sz;
12511 }
12512
12513 *p++ = '\n';
Mike Marciniszyn77241052015-07-30 15:17:43 -040012514 }
12515 }
12516
12517 /*********************/
12518 /* per port counters */
12519 /*********************/
12520
12521 /*
12522 * Go through the counters for the overflows and disable the ones we
12523 * don't need. This varies based on platform so we need to do it
12524 * dynamically here.
12525 */
12526 rcv_ctxts = dd->num_rcv_contexts;
12527 for (i = C_RCV_HDR_OVF_FIRST + rcv_ctxts;
12528 i <= C_RCV_HDR_OVF_LAST; i++) {
12529 port_cntrs[i].flags |= CNTR_DISABLED;
12530 }
12531
12532 /* size port counter names and determine how many we have*/
12533 sz = 0;
12534 dd->nportcntrs = 0;
12535 for (i = 0; i < PORT_CNTR_LAST; i++) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040012536 if (port_cntrs[i].flags & CNTR_DISABLED) {
12537 hfi1_dbg_early("\tSkipping %s\n", port_cntrs[i].name);
12538 continue;
12539 }
12540
12541 if (port_cntrs[i].flags & CNTR_VL) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040012542 port_cntrs[i].offset = dd->nportcntrs;
12543 for (j = 0; j < C_VL_COUNT; j++) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040012544 snprintf(name, C_MAX_NAME, "%s%d",
Jubin John17fb4f22016-02-14 20:21:52 -080012545 port_cntrs[i].name, vl_from_idx(j));
Mike Marciniszyn77241052015-07-30 15:17:43 -040012546 sz += strlen(name);
Sebastian Sanchez11d2b112016-02-03 14:32:40 -080012547 /* Add ",32" for 32-bit counters */
12548 if (port_cntrs[i].flags & CNTR_32BIT)
12549 sz += bit_type_32_sz;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012550 sz++;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012551 dd->nportcntrs++;
12552 }
12553 } else {
Sebastian Sanchez11d2b112016-02-03 14:32:40 -080012554 /* +1 for newline */
Mike Marciniszyn77241052015-07-30 15:17:43 -040012555 sz += strlen(port_cntrs[i].name) + 1;
Sebastian Sanchez11d2b112016-02-03 14:32:40 -080012556 /* Add ",32" for 32-bit counters */
12557 if (port_cntrs[i].flags & CNTR_32BIT)
12558 sz += bit_type_32_sz;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012559 port_cntrs[i].offset = dd->nportcntrs;
12560 dd->nportcntrs++;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012561 }
12562 }
12563
12564 /* allocate space for the counter names */
12565 dd->portcntrnameslen = sz;
12566 dd->portcntrnames = kmalloc(sz, GFP_KERNEL);
12567 if (!dd->portcntrnames)
12568 goto bail;
12569
12570 /* fill in port cntr names */
12571 for (p = dd->portcntrnames, i = 0; i < PORT_CNTR_LAST; i++) {
12572 if (port_cntrs[i].flags & CNTR_DISABLED)
12573 continue;
12574
12575 if (port_cntrs[i].flags & CNTR_VL) {
12576 for (j = 0; j < C_VL_COUNT; j++) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040012577 snprintf(name, C_MAX_NAME, "%s%d",
Jubin John17fb4f22016-02-14 20:21:52 -080012578 port_cntrs[i].name, vl_from_idx(j));
Mike Marciniszyn77241052015-07-30 15:17:43 -040012579 memcpy(p, name, strlen(name));
12580 p += strlen(name);
Sebastian Sanchez11d2b112016-02-03 14:32:40 -080012581
12582 /* Counter is 32 bits */
12583 if (port_cntrs[i].flags & CNTR_32BIT) {
12584 memcpy(p, bit_type_32, bit_type_32_sz);
12585 p += bit_type_32_sz;
12586 }
12587
Mike Marciniszyn77241052015-07-30 15:17:43 -040012588 *p++ = '\n';
12589 }
12590 } else {
12591 memcpy(p, port_cntrs[i].name,
12592 strlen(port_cntrs[i].name));
12593 p += strlen(port_cntrs[i].name);
Sebastian Sanchez11d2b112016-02-03 14:32:40 -080012594
12595 /* Counter is 32 bits */
12596 if (port_cntrs[i].flags & CNTR_32BIT) {
12597 memcpy(p, bit_type_32, bit_type_32_sz);
12598 p += bit_type_32_sz;
12599 }
12600
Mike Marciniszyn77241052015-07-30 15:17:43 -040012601 *p++ = '\n';
12602 }
12603 }
12604
12605 /* allocate per port storage for counter values */
12606 ppd = (struct hfi1_pportdata *)(dd + 1);
12607 for (i = 0; i < dd->num_pports; i++, ppd++) {
12608 ppd->cntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
12609 if (!ppd->cntrs)
12610 goto bail;
12611
12612 ppd->scntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
12613 if (!ppd->scntrs)
12614 goto bail;
12615 }
12616
12617 /* CPU counters need to be allocated and zeroed */
12618 if (init_cpu_counters(dd))
12619 goto bail;
12620
Tadeusz Struk22546b72017-04-28 10:40:02 -070012621 dd->update_cntr_wq = alloc_ordered_workqueue("hfi1_update_cntr_%d",
12622 WQ_MEM_RECLAIM, dd->unit);
12623 if (!dd->update_cntr_wq)
12624 goto bail;
12625
12626 INIT_WORK(&dd->update_cntr_work, do_update_synth_timer);
12627
Mike Marciniszyn77241052015-07-30 15:17:43 -040012628 mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
12629 return 0;
12630bail:
12631 free_cntrs(dd);
12632 return -ENOMEM;
12633}
12634
Mike Marciniszyn77241052015-07-30 15:17:43 -040012635static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate)
12636{
12637 switch (chip_lstate) {
12638 default:
12639 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -080012640 "Unknown logical state 0x%x, reporting IB_PORT_DOWN\n",
12641 chip_lstate);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012642 /* fall through */
12643 case LSTATE_DOWN:
12644 return IB_PORT_DOWN;
12645 case LSTATE_INIT:
12646 return IB_PORT_INIT;
12647 case LSTATE_ARMED:
12648 return IB_PORT_ARMED;
12649 case LSTATE_ACTIVE:
12650 return IB_PORT_ACTIVE;
12651 }
12652}
12653
12654u32 chip_to_opa_pstate(struct hfi1_devdata *dd, u32 chip_pstate)
12655{
12656 /* look at the HFI meta-states only */
12657 switch (chip_pstate & 0xf0) {
12658 default:
12659 dd_dev_err(dd, "Unexpected chip physical state of 0x%x\n",
Jubin John17fb4f22016-02-14 20:21:52 -080012660 chip_pstate);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012661 /* fall through */
12662 case PLS_DISABLED:
12663 return IB_PORTPHYSSTATE_DISABLED;
12664 case PLS_OFFLINE:
12665 return OPA_PORTPHYSSTATE_OFFLINE;
12666 case PLS_POLLING:
12667 return IB_PORTPHYSSTATE_POLLING;
12668 case PLS_CONFIGPHY:
12669 return IB_PORTPHYSSTATE_TRAINING;
12670 case PLS_LINKUP:
12671 return IB_PORTPHYSSTATE_LINKUP;
12672 case PLS_PHYTEST:
12673 return IB_PORTPHYSSTATE_PHY_TEST;
12674 }
12675}
12676
12677/* return the OPA port logical state name */
12678const char *opa_lstate_name(u32 lstate)
12679{
12680 static const char * const port_logical_names[] = {
12681 "PORT_NOP",
12682 "PORT_DOWN",
12683 "PORT_INIT",
12684 "PORT_ARMED",
12685 "PORT_ACTIVE",
12686 "PORT_ACTIVE_DEFER",
12687 };
12688 if (lstate < ARRAY_SIZE(port_logical_names))
12689 return port_logical_names[lstate];
12690 return "unknown";
12691}
12692
12693/* return the OPA port physical state name */
12694const char *opa_pstate_name(u32 pstate)
12695{
12696 static const char * const port_physical_names[] = {
12697 "PHYS_NOP",
12698 "reserved1",
12699 "PHYS_POLL",
12700 "PHYS_DISABLED",
12701 "PHYS_TRAINING",
12702 "PHYS_LINKUP",
12703 "PHYS_LINK_ERR_RECOVER",
12704 "PHYS_PHY_TEST",
12705 "reserved8",
12706 "PHYS_OFFLINE",
12707 "PHYS_GANGED",
12708 "PHYS_TEST",
12709 };
12710 if (pstate < ARRAY_SIZE(port_physical_names))
12711 return port_physical_names[pstate];
12712 return "unknown";
12713}
12714
Byczkowski, Jakub02a222c2017-08-04 13:52:26 -070012715static void update_statusp(struct hfi1_pportdata *ppd, u32 state)
Mike Marciniszyn77241052015-07-30 15:17:43 -040012716{
Mike Marciniszyn77241052015-07-30 15:17:43 -040012717 /*
12718 * Set port status flags in the page mapped into userspace
12719 * memory. Do it here to ensure a reliable state - this is
12720 * the only function called by all state handling code.
12721 * Always set the flags due to the fact that the cache value
12722 * might have been changed explicitly outside of this
12723 * function.
12724 */
12725 if (ppd->statusp) {
Byczkowski, Jakub02a222c2017-08-04 13:52:26 -070012726 switch (state) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040012727 case IB_PORT_DOWN:
12728 case IB_PORT_INIT:
12729 *ppd->statusp &= ~(HFI1_STATUS_IB_CONF |
12730 HFI1_STATUS_IB_READY);
12731 break;
12732 case IB_PORT_ARMED:
12733 *ppd->statusp |= HFI1_STATUS_IB_CONF;
12734 break;
12735 case IB_PORT_ACTIVE:
12736 *ppd->statusp |= HFI1_STATUS_IB_READY;
12737 break;
12738 }
12739 }
Mike Marciniszyn77241052015-07-30 15:17:43 -040012740}
12741
Byczkowski, Jakub02a222c2017-08-04 13:52:26 -070012742/*
Mike Marciniszyn77241052015-07-30 15:17:43 -040012743 * wait_logical_linkstate - wait for an IB link state change to occur
12744 * @ppd: port device
12745 * @state: the state to wait for
12746 * @msecs: the number of milliseconds to wait
12747 *
12748 * Wait up to msecs milliseconds for IB link state change to occur.
12749 * For now, take the easy polling route.
12750 * Returns 0 if state reached, otherwise -ETIMEDOUT.
12751 */
12752static int wait_logical_linkstate(struct hfi1_pportdata *ppd, u32 state,
12753 int msecs)
12754{
12755 unsigned long timeout;
Byczkowski, Jakub02a222c2017-08-04 13:52:26 -070012756 u32 new_state;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012757
12758 timeout = jiffies + msecs_to_jiffies(msecs);
12759 while (1) {
Byczkowski, Jakub02a222c2017-08-04 13:52:26 -070012760 new_state = chip_to_opa_lstate(ppd->dd,
12761 read_logical_state(ppd->dd));
12762 if (new_state == state)
Mike Marciniszyn77241052015-07-30 15:17:43 -040012763 break;
Byczkowski, Jakub02a222c2017-08-04 13:52:26 -070012764 if (time_after(jiffies, timeout)) {
12765 dd_dev_err(ppd->dd,
12766 "timeout waiting for link state 0x%x\n",
12767 state);
12768 return -ETIMEDOUT;
12769 }
Mike Marciniszyn77241052015-07-30 15:17:43 -040012770 msleep(20);
12771 }
Mike Marciniszyn77241052015-07-30 15:17:43 -040012772
Byczkowski, Jakub02a222c2017-08-04 13:52:26 -070012773 update_statusp(ppd, state);
12774 dd_dev_info(ppd->dd,
12775 "logical state changed to %s (0x%x)\n",
12776 opa_lstate_name(state),
12777 state);
12778 return 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012779}
12780
Jakub Byczkowskid392a672017-08-13 08:08:52 -070012781static void log_state_transition(struct hfi1_pportdata *ppd, u32 state)
Mike Marciniszyn77241052015-07-30 15:17:43 -040012782{
Jakub Byczkowskid392a672017-08-13 08:08:52 -070012783 u32 ib_pstate = chip_to_opa_pstate(ppd->dd, state);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012784
Jakub Byczkowskid392a672017-08-13 08:08:52 -070012785 dd_dev_info(ppd->dd,
12786 "physical state changed to %s (0x%x), phy 0x%x\n",
12787 opa_pstate_name(ib_pstate), ib_pstate, state);
12788}
12789
12790/*
12791 * Read the physical hardware link state and check if it matches host
12792 * drivers anticipated state.
12793 */
12794static void log_physical_state(struct hfi1_pportdata *ppd, u32 state)
12795{
12796 u32 read_state = read_physical_state(ppd->dd);
12797
12798 if (read_state == state) {
12799 log_state_transition(ppd, state);
12800 } else {
12801 dd_dev_err(ppd->dd,
12802 "anticipated phy link state 0x%x, read 0x%x\n",
12803 state, read_state);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012804 }
Byczkowski, Jakubbec7c792017-05-29 17:21:32 -070012805}
12806
12807/*
12808 * wait_physical_linkstate - wait for an physical link state change to occur
12809 * @ppd: port device
12810 * @state: the state to wait for
12811 * @msecs: the number of milliseconds to wait
12812 *
12813 * Wait up to msecs milliseconds for physical link state change to occur.
12814 * Returns 0 if state reached, otherwise -ETIMEDOUT.
12815 */
12816static int wait_physical_linkstate(struct hfi1_pportdata *ppd, u32 state,
12817 int msecs)
12818{
Jakub Byczkowskid392a672017-08-13 08:08:52 -070012819 u32 read_state;
Byczkowski, Jakubbec7c792017-05-29 17:21:32 -070012820 unsigned long timeout;
12821
12822 timeout = jiffies + msecs_to_jiffies(msecs);
12823 while (1) {
Jakub Byczkowskid392a672017-08-13 08:08:52 -070012824 read_state = read_physical_state(ppd->dd);
12825 if (read_state == state)
Byczkowski, Jakubbec7c792017-05-29 17:21:32 -070012826 break;
12827 if (time_after(jiffies, timeout)) {
12828 dd_dev_err(ppd->dd,
Jakub Byczkowskid392a672017-08-13 08:08:52 -070012829 "timeout waiting for phy link state 0x%x\n",
12830 state);
Byczkowski, Jakubbec7c792017-05-29 17:21:32 -070012831 return -ETIMEDOUT;
12832 }
12833 usleep_range(1950, 2050); /* sleep 2ms-ish */
12834 }
12835
Jakub Byczkowskid392a672017-08-13 08:08:52 -070012836 log_state_transition(ppd, state);
Byczkowski, Jakubbec7c792017-05-29 17:21:32 -070012837 return 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012838}
12839
Mike Marciniszyn77241052015-07-30 15:17:43 -040012840#define CLEAR_STATIC_RATE_CONTROL_SMASK(r) \
12841(r &= ~SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
12842
12843#define SET_STATIC_RATE_CONTROL_SMASK(r) \
12844(r |= SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
12845
Michael J. Ruhl9b60d2c2017-05-04 05:15:09 -070012846void hfi1_init_ctxt(struct send_context *sc)
Mike Marciniszyn77241052015-07-30 15:17:43 -040012847{
Jubin Johnd125a6c2016-02-14 20:19:49 -080012848 if (sc) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040012849 struct hfi1_devdata *dd = sc->dd;
12850 u64 reg;
12851 u8 set = (sc->type == SC_USER ?
12852 HFI1_CAP_IS_USET(STATIC_RATE_CTRL) :
12853 HFI1_CAP_IS_KSET(STATIC_RATE_CTRL));
12854 reg = read_kctxt_csr(dd, sc->hw_context,
12855 SEND_CTXT_CHECK_ENABLE);
12856 if (set)
12857 CLEAR_STATIC_RATE_CONTROL_SMASK(reg);
12858 else
12859 SET_STATIC_RATE_CONTROL_SMASK(reg);
12860 write_kctxt_csr(dd, sc->hw_context,
12861 SEND_CTXT_CHECK_ENABLE, reg);
12862 }
Mike Marciniszyn77241052015-07-30 15:17:43 -040012863}
12864
12865int hfi1_tempsense_rd(struct hfi1_devdata *dd, struct hfi1_temp *temp)
12866{
12867 int ret = 0;
12868 u64 reg;
12869
12870 if (dd->icode != ICODE_RTL_SILICON) {
12871 if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
12872 dd_dev_info(dd, "%s: tempsense not supported by HW\n",
12873 __func__);
12874 return -EINVAL;
12875 }
12876 reg = read_csr(dd, ASIC_STS_THERM);
12877 temp->curr = ((reg >> ASIC_STS_THERM_CURR_TEMP_SHIFT) &
12878 ASIC_STS_THERM_CURR_TEMP_MASK);
12879 temp->lo_lim = ((reg >> ASIC_STS_THERM_LO_TEMP_SHIFT) &
12880 ASIC_STS_THERM_LO_TEMP_MASK);
12881 temp->hi_lim = ((reg >> ASIC_STS_THERM_HI_TEMP_SHIFT) &
12882 ASIC_STS_THERM_HI_TEMP_MASK);
12883 temp->crit_lim = ((reg >> ASIC_STS_THERM_CRIT_TEMP_SHIFT) &
12884 ASIC_STS_THERM_CRIT_TEMP_MASK);
12885 /* triggers is a 3-bit value - 1 bit per trigger. */
12886 temp->triggers = (u8)((reg >> ASIC_STS_THERM_LOW_SHIFT) & 0x7);
12887
12888 return ret;
12889}
12890
12891/* ========================================================================= */
12892
12893/*
12894 * Enable/disable chip from delivering interrupts.
12895 */
12896void set_intr_state(struct hfi1_devdata *dd, u32 enable)
12897{
12898 int i;
12899
12900 /*
12901 * In HFI, the mask needs to be 1 to allow interrupts.
12902 */
12903 if (enable) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040012904 /* enable all interrupts */
12905 for (i = 0; i < CCE_NUM_INT_CSRS; i++)
Jubin John8638b772016-02-14 20:19:24 -080012906 write_csr(dd, CCE_INT_MASK + (8 * i), ~(u64)0);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012907
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -080012908 init_qsfp_int(dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012909 } else {
12910 for (i = 0; i < CCE_NUM_INT_CSRS; i++)
Jubin John8638b772016-02-14 20:19:24 -080012911 write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012912 }
12913}
12914
12915/*
12916 * Clear all interrupt sources on the chip.
12917 */
12918static void clear_all_interrupts(struct hfi1_devdata *dd)
12919{
12920 int i;
12921
12922 for (i = 0; i < CCE_NUM_INT_CSRS; i++)
Jubin John8638b772016-02-14 20:19:24 -080012923 write_csr(dd, CCE_INT_CLEAR + (8 * i), ~(u64)0);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012924
12925 write_csr(dd, CCE_ERR_CLEAR, ~(u64)0);
12926 write_csr(dd, MISC_ERR_CLEAR, ~(u64)0);
12927 write_csr(dd, RCV_ERR_CLEAR, ~(u64)0);
12928 write_csr(dd, SEND_ERR_CLEAR, ~(u64)0);
12929 write_csr(dd, SEND_PIO_ERR_CLEAR, ~(u64)0);
12930 write_csr(dd, SEND_DMA_ERR_CLEAR, ~(u64)0);
12931 write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~(u64)0);
12932 for (i = 0; i < dd->chip_send_contexts; i++)
12933 write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~(u64)0);
12934 for (i = 0; i < dd->chip_sdma_engines; i++)
12935 write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~(u64)0);
12936
12937 write_csr(dd, DCC_ERR_FLG_CLR, ~(u64)0);
12938 write_csr(dd, DC_LCB_ERR_CLR, ~(u64)0);
12939 write_csr(dd, DC_DC8051_ERR_CLR, ~(u64)0);
12940}
12941
12942/* Move to pcie.c? */
12943static void disable_intx(struct pci_dev *pdev)
12944{
12945 pci_intx(pdev, 0);
12946}
12947
12948static void clean_up_interrupts(struct hfi1_devdata *dd)
12949{
12950 int i;
12951
12952 /* remove irqs - must happen before disabling/turning off */
12953 if (dd->num_msix_entries) {
12954 /* MSI-X */
12955 struct hfi1_msix_entry *me = dd->msix_entries;
12956
12957 for (i = 0; i < dd->num_msix_entries; i++, me++) {
Jubin Johnd125a6c2016-02-14 20:19:49 -080012958 if (!me->arg) /* => no irq, no affinity */
Mitko Haralanov957558c2016-02-03 14:33:40 -080012959 continue;
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -070012960 hfi1_put_irq_affinity(dd, me);
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070012961 pci_free_irq(dd->pcidev, i, me->arg);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012962 }
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -070012963
12964 /* clean structures */
12965 kfree(dd->msix_entries);
12966 dd->msix_entries = NULL;
12967 dd->num_msix_entries = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -040012968 } else {
12969 /* INTx */
12970 if (dd->requested_intx_irq) {
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070012971 pci_free_irq(dd->pcidev, 0, dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012972 dd->requested_intx_irq = 0;
12973 }
Mike Marciniszyn77241052015-07-30 15:17:43 -040012974 disable_intx(dd->pcidev);
12975 }
12976
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -070012977 pci_free_irq_vectors(dd->pcidev);
Mike Marciniszyn77241052015-07-30 15:17:43 -040012978}
12979
12980/*
12981 * Remap the interrupt source from the general handler to the given MSI-X
12982 * interrupt.
12983 */
12984static void remap_intr(struct hfi1_devdata *dd, int isrc, int msix_intr)
12985{
12986 u64 reg;
12987 int m, n;
12988
12989 /* clear from the handled mask of the general interrupt */
12990 m = isrc / 64;
12991 n = isrc % 64;
Dennis Dalessandrobc54f672017-05-29 17:18:14 -070012992 if (likely(m < CCE_NUM_INT_CSRS)) {
12993 dd->gi_mask[m] &= ~((u64)1 << n);
12994 } else {
12995 dd_dev_err(dd, "remap interrupt err\n");
12996 return;
12997 }
Mike Marciniszyn77241052015-07-30 15:17:43 -040012998
12999 /* direct the chip source to the given MSI-X interrupt */
13000 m = isrc / 8;
13001 n = isrc % 8;
Jubin John8638b772016-02-14 20:19:24 -080013002 reg = read_csr(dd, CCE_INT_MAP + (8 * m));
13003 reg &= ~((u64)0xff << (8 * n));
13004 reg |= ((u64)msix_intr & 0xff) << (8 * n);
13005 write_csr(dd, CCE_INT_MAP + (8 * m), reg);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013006}
13007
13008static void remap_sdma_interrupts(struct hfi1_devdata *dd,
13009 int engine, int msix_intr)
13010{
13011 /*
13012 * SDMA engine interrupt sources grouped by type, rather than
13013 * engine. Per-engine interrupts are as follows:
13014 * SDMA
13015 * SDMAProgress
13016 * SDMAIdle
13017 */
Jubin John8638b772016-02-14 20:19:24 -080013018 remap_intr(dd, IS_SDMA_START + 0 * TXE_NUM_SDMA_ENGINES + engine,
Jubin John17fb4f22016-02-14 20:21:52 -080013019 msix_intr);
Jubin John8638b772016-02-14 20:19:24 -080013020 remap_intr(dd, IS_SDMA_START + 1 * TXE_NUM_SDMA_ENGINES + engine,
Jubin John17fb4f22016-02-14 20:21:52 -080013021 msix_intr);
Jubin John8638b772016-02-14 20:19:24 -080013022 remap_intr(dd, IS_SDMA_START + 2 * TXE_NUM_SDMA_ENGINES + engine,
Jubin John17fb4f22016-02-14 20:21:52 -080013023 msix_intr);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013024}
13025
Mike Marciniszyn77241052015-07-30 15:17:43 -040013026static int request_intx_irq(struct hfi1_devdata *dd)
13027{
13028 int ret;
13029
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070013030 ret = pci_request_irq(dd->pcidev, 0, general_interrupt, NULL, dd,
13031 DRIVER_NAME "_%d", dd->unit);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013032 if (ret)
13033 dd_dev_err(dd, "unable to request INTx interrupt, err %d\n",
Jubin John17fb4f22016-02-14 20:21:52 -080013034 ret);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013035 else
13036 dd->requested_intx_irq = 1;
13037 return ret;
13038}
13039
13040static int request_msix_irqs(struct hfi1_devdata *dd)
13041{
Mike Marciniszyn77241052015-07-30 15:17:43 -040013042 int first_general, last_general;
13043 int first_sdma, last_sdma;
13044 int first_rx, last_rx;
Mitko Haralanov957558c2016-02-03 14:33:40 -080013045 int i, ret = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013046
13047 /* calculate the ranges we are going to use */
13048 first_general = 0;
Jubin Johnf3ff8182016-02-14 20:20:50 -080013049 last_general = first_general + 1;
13050 first_sdma = last_general;
13051 last_sdma = first_sdma + dd->num_sdma;
13052 first_rx = last_sdma;
Michael J. Ruhld7d62612017-10-02 11:04:19 -070013053 last_rx = first_rx + dd->n_krcv_queues + dd->num_vnic_contexts;
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013054
13055 /* VNIC MSIx interrupts get mapped when VNIC contexts are created */
13056 dd->first_dyn_msix_idx = first_rx + dd->n_krcv_queues;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013057
13058 /*
Mike Marciniszyn77241052015-07-30 15:17:43 -040013059 * Sanity check - the code expects all SDMA chip source
13060 * interrupts to be in the same CSR, starting at bit 0. Verify
13061 * that this is true by checking the bit location of the start.
13062 */
13063 BUILD_BUG_ON(IS_SDMA_START % 64);
13064
13065 for (i = 0; i < dd->num_msix_entries; i++) {
13066 struct hfi1_msix_entry *me = &dd->msix_entries[i];
13067 const char *err_info;
13068 irq_handler_t handler;
Dean Luickf4f30031c2015-10-26 10:28:44 -040013069 irq_handler_t thread = NULL;
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013070 void *arg = NULL;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013071 int idx;
13072 struct hfi1_ctxtdata *rcd = NULL;
13073 struct sdma_engine *sde = NULL;
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070013074 char name[MAX_NAME_SIZE];
Mike Marciniszyn77241052015-07-30 15:17:43 -040013075
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070013076 /* obtain the arguments to pci_request_irq */
Mike Marciniszyn77241052015-07-30 15:17:43 -040013077 if (first_general <= i && i < last_general) {
13078 idx = i - first_general;
13079 handler = general_interrupt;
13080 arg = dd;
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070013081 snprintf(name, sizeof(name),
Jubin John98050712015-11-16 21:59:27 -050013082 DRIVER_NAME "_%d", dd->unit);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013083 err_info = "general";
Mitko Haralanov957558c2016-02-03 14:33:40 -080013084 me->type = IRQ_GENERAL;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013085 } else if (first_sdma <= i && i < last_sdma) {
13086 idx = i - first_sdma;
13087 sde = &dd->per_sdma[idx];
13088 handler = sdma_interrupt;
13089 arg = sde;
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070013090 snprintf(name, sizeof(name),
Jubin John98050712015-11-16 21:59:27 -050013091 DRIVER_NAME "_%d sdma%d", dd->unit, idx);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013092 err_info = "sdma";
13093 remap_sdma_interrupts(dd, idx, i);
Mitko Haralanov957558c2016-02-03 14:33:40 -080013094 me->type = IRQ_SDMA;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013095 } else if (first_rx <= i && i < last_rx) {
13096 idx = i - first_rx;
Michael J. Ruhld59075a2017-09-26 07:01:16 -070013097 rcd = hfi1_rcd_get_by_index_safe(dd, idx);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013098 if (rcd) {
13099 /*
13100 * Set the interrupt register and mask for this
13101 * context's interrupt.
13102 */
13103 rcd->ireg = (IS_RCVAVAIL_START + idx) / 64;
13104 rcd->imask = ((u64)1) <<
13105 ((IS_RCVAVAIL_START + idx) % 64);
13106 handler = receive_context_interrupt;
13107 thread = receive_context_thread;
13108 arg = rcd;
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070013109 snprintf(name, sizeof(name),
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013110 DRIVER_NAME "_%d kctxt%d",
13111 dd->unit, idx);
13112 err_info = "receive context";
13113 remap_intr(dd, IS_RCVAVAIL_START + idx, i);
13114 me->type = IRQ_RCVCTXT;
13115 rcd->msix_intr = i;
Michael J. Ruhld295dbe2017-08-04 13:52:44 -070013116 hfi1_rcd_put(rcd);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013117 }
Mike Marciniszyn77241052015-07-30 15:17:43 -040013118 } else {
13119 /* not in our expected range - complain, then
Jubin John4d114fd2016-02-14 20:21:43 -080013120 * ignore it
13121 */
Mike Marciniszyn77241052015-07-30 15:17:43 -040013122 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -080013123 "Unexpected extra MSI-X interrupt %d\n", i);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013124 continue;
13125 }
13126 /* no argument, no interrupt */
Jubin Johnd125a6c2016-02-14 20:19:49 -080013127 if (!arg)
Mike Marciniszyn77241052015-07-30 15:17:43 -040013128 continue;
13129 /* make sure the name is terminated */
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070013130 name[sizeof(name) - 1] = 0;
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -070013131 me->irq = pci_irq_vector(dd->pcidev, i);
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070013132 ret = pci_request_irq(dd->pcidev, i, handler, thread, arg,
13133 name);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013134 if (ret) {
13135 dd_dev_err(dd,
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -070013136 "unable to allocate %s interrupt, irq %d, index %d, err %d\n",
13137 err_info, me->irq, idx, ret);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013138 return ret;
13139 }
13140 /*
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070013141 * assign arg after pci_request_irq call, so it will be
Mike Marciniszyn77241052015-07-30 15:17:43 -040013142 * cleaned up
13143 */
13144 me->arg = arg;
13145
Mitko Haralanov957558c2016-02-03 14:33:40 -080013146 ret = hfi1_get_irq_affinity(dd, me);
13147 if (ret)
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -070013148 dd_dev_err(dd, "unable to pin IRQ %d\n", ret);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013149 }
13150
Mike Marciniszyn77241052015-07-30 15:17:43 -040013151 return ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013152}
13153
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013154void hfi1_vnic_synchronize_irq(struct hfi1_devdata *dd)
13155{
13156 int i;
13157
13158 if (!dd->num_msix_entries) {
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070013159 synchronize_irq(pci_irq_vector(dd->pcidev, 0));
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013160 return;
13161 }
13162
13163 for (i = 0; i < dd->vnic.num_ctxt; i++) {
13164 struct hfi1_ctxtdata *rcd = dd->vnic.ctxt[i];
13165 struct hfi1_msix_entry *me = &dd->msix_entries[rcd->msix_intr];
13166
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -070013167 synchronize_irq(me->irq);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013168 }
13169}
13170
13171void hfi1_reset_vnic_msix_info(struct hfi1_ctxtdata *rcd)
13172{
13173 struct hfi1_devdata *dd = rcd->dd;
13174 struct hfi1_msix_entry *me = &dd->msix_entries[rcd->msix_intr];
13175
13176 if (!me->arg) /* => no irq, no affinity */
13177 return;
13178
13179 hfi1_put_irq_affinity(dd, me);
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070013180 pci_free_irq(dd->pcidev, rcd->msix_intr, me->arg);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013181
13182 me->arg = NULL;
13183}
13184
13185void hfi1_set_vnic_msix_info(struct hfi1_ctxtdata *rcd)
13186{
13187 struct hfi1_devdata *dd = rcd->dd;
13188 struct hfi1_msix_entry *me;
13189 int idx = rcd->ctxt;
13190 void *arg = rcd;
13191 int ret;
13192
13193 rcd->msix_intr = dd->vnic.msix_idx++;
13194 me = &dd->msix_entries[rcd->msix_intr];
13195
13196 /*
13197 * Set the interrupt register and mask for this
13198 * context's interrupt.
13199 */
13200 rcd->ireg = (IS_RCVAVAIL_START + idx) / 64;
13201 rcd->imask = ((u64)1) <<
13202 ((IS_RCVAVAIL_START + idx) % 64);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013203 me->type = IRQ_RCVCTXT;
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -070013204 me->irq = pci_irq_vector(dd->pcidev, rcd->msix_intr);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013205 remap_intr(dd, IS_RCVAVAIL_START + idx, rcd->msix_intr);
13206
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070013207 ret = pci_request_irq(dd->pcidev, rcd->msix_intr,
13208 receive_context_interrupt,
13209 receive_context_thread, arg,
13210 DRIVER_NAME "_%d kctxt%d", dd->unit, idx);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013211 if (ret) {
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -070013212 dd_dev_err(dd, "vnic irq request (irq %d, idx %d) fail %d\n",
13213 me->irq, idx, ret);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013214 return;
13215 }
13216 /*
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070013217 * assign arg after pci_request_irq call, so it will be
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013218 * cleaned up
13219 */
13220 me->arg = arg;
13221
13222 ret = hfi1_get_irq_affinity(dd, me);
13223 if (ret) {
13224 dd_dev_err(dd,
13225 "unable to pin IRQ %d\n", ret);
Michael J. Ruhl05cb18f2017-09-26 07:00:30 -070013226 pci_free_irq(dd->pcidev, rcd->msix_intr, me->arg);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013227 }
13228}
13229
Mike Marciniszyn77241052015-07-30 15:17:43 -040013230/*
13231 * Set the general handler to accept all interrupts, remap all
13232 * chip interrupts back to MSI-X 0.
13233 */
13234static void reset_interrupts(struct hfi1_devdata *dd)
13235{
13236 int i;
13237
13238 /* all interrupts handled by the general handler */
13239 for (i = 0; i < CCE_NUM_INT_CSRS; i++)
13240 dd->gi_mask[i] = ~(u64)0;
13241
13242 /* all chip interrupts map to MSI-X 0 */
13243 for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
Jubin John8638b772016-02-14 20:19:24 -080013244 write_csr(dd, CCE_INT_MAP + (8 * i), 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013245}
13246
13247static int set_up_interrupts(struct hfi1_devdata *dd)
13248{
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -070013249 u32 total;
13250 int ret, request;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013251 int single_interrupt = 0; /* we expect to have all the interrupts */
13252
13253 /*
13254 * Interrupt count:
13255 * 1 general, "slow path" interrupt (includes the SDMA engines
13256 * slow source, SDMACleanupDone)
13257 * N interrupts - one per used SDMA engine
13258 * M interrupt - one per kernel receive context
Michael J. Ruhld7d62612017-10-02 11:04:19 -070013259 * V interrupt - one for each VNIC context
Mike Marciniszyn77241052015-07-30 15:17:43 -040013260 */
Michael J. Ruhld7d62612017-10-02 11:04:19 -070013261 total = 1 + dd->num_sdma + dd->n_krcv_queues + dd->num_vnic_contexts;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013262
Mike Marciniszyn77241052015-07-30 15:17:43 -040013263 /* ask for MSI-X interrupts */
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -070013264 request = request_msix(dd, total);
13265 if (request < 0) {
13266 ret = request;
13267 goto fail;
13268 } else if (request == 0) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040013269 /* using INTx */
13270 /* dd->num_msix_entries already zero */
Mike Marciniszyn77241052015-07-30 15:17:43 -040013271 single_interrupt = 1;
13272 dd_dev_err(dd, "MSI-X failed, using INTx interrupts\n");
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -070013273 } else if (request < total) {
13274 /* using MSI-X, with reduced interrupts */
13275 dd_dev_err(dd, "reduced interrupt found, wanted %u, got %u\n",
13276 total, request);
13277 ret = -EINVAL;
13278 goto fail;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013279 } else {
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -070013280 dd->msix_entries = kcalloc(total, sizeof(*dd->msix_entries),
13281 GFP_KERNEL);
13282 if (!dd->msix_entries) {
13283 ret = -ENOMEM;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013284 goto fail;
13285 }
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -070013286 /* using MSI-X */
13287 dd->num_msix_entries = total;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013288 dd_dev_info(dd, "%u MSI-X interrupts allocated\n", total);
13289 }
13290
13291 /* mask all interrupts */
13292 set_intr_state(dd, 0);
13293 /* clear all pending interrupts */
13294 clear_all_interrupts(dd);
13295
13296 /* reset general handler mask, chip MSI-X mappings */
13297 reset_interrupts(dd);
13298
13299 if (single_interrupt)
13300 ret = request_intx_irq(dd);
13301 else
13302 ret = request_msix_irqs(dd);
13303 if (ret)
13304 goto fail;
13305
13306 return 0;
13307
13308fail:
13309 clean_up_interrupts(dd);
13310 return ret;
13311}
13312
13313/*
13314 * Set up context values in dd. Sets:
13315 *
13316 * num_rcv_contexts - number of contexts being used
13317 * n_krcv_queues - number of kernel contexts
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013318 * first_dyn_alloc_ctxt - first dynamically allocated context
13319 * in array of contexts
Mike Marciniszyn77241052015-07-30 15:17:43 -040013320 * freectxts - number of free user contexts
13321 * num_send_contexts - number of PIO send contexts being used
Michael J. Ruhld7d62612017-10-02 11:04:19 -070013322 * num_vnic_contexts - number of contexts reserved for VNIC
Mike Marciniszyn77241052015-07-30 15:17:43 -040013323 */
13324static int set_up_context_variables(struct hfi1_devdata *dd)
13325{
Harish Chegondi429b6a72016-08-31 07:24:40 -070013326 unsigned long num_kernel_contexts;
Michael J. Ruhld7d62612017-10-02 11:04:19 -070013327 u16 num_vnic_contexts = HFI1_NUM_VNIC_CTXT;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013328 int total_contexts;
13329 int ret;
13330 unsigned ngroups;
Dean Luick8f000f72016-04-12 11:32:06 -070013331 int qos_rmt_count;
13332 int user_rmt_reduced;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013333
13334 /*
Dean Luick33a9eb52016-04-12 10:50:22 -070013335 * Kernel receive contexts:
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -050013336 * - Context 0 - control context (VL15/multicast/error)
Dean Luick33a9eb52016-04-12 10:50:22 -070013337 * - Context 1 - first kernel context
13338 * - Context 2 - second kernel context
13339 * ...
Mike Marciniszyn77241052015-07-30 15:17:43 -040013340 */
13341 if (n_krcvqs)
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -050013342 /*
Dean Luick33a9eb52016-04-12 10:50:22 -070013343 * n_krcvqs is the sum of module parameter kernel receive
13344 * contexts, krcvqs[]. It does not include the control
13345 * context, so add that.
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -050013346 */
Dean Luick33a9eb52016-04-12 10:50:22 -070013347 num_kernel_contexts = n_krcvqs + 1;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013348 else
Harish Chegondi8784ac02016-07-25 13:38:50 -070013349 num_kernel_contexts = DEFAULT_KRCVQS + 1;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013350 /*
13351 * Every kernel receive context needs an ACK send context.
13352 * one send context is allocated for each VL{0-7} and VL15
13353 */
13354 if (num_kernel_contexts > (dd->chip_send_contexts - num_vls - 1)) {
13355 dd_dev_err(dd,
Harish Chegondi429b6a72016-08-31 07:24:40 -070013356 "Reducing # kernel rcv contexts to: %d, from %lu\n",
Mike Marciniszyn77241052015-07-30 15:17:43 -040013357 (int)(dd->chip_send_contexts - num_vls - 1),
Harish Chegondi429b6a72016-08-31 07:24:40 -070013358 num_kernel_contexts);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013359 num_kernel_contexts = dd->chip_send_contexts - num_vls - 1;
13360 }
Michael J. Ruhld7d62612017-10-02 11:04:19 -070013361
13362 /* Accommodate VNIC contexts if possible */
13363 if ((num_kernel_contexts + num_vnic_contexts) > dd->chip_rcv_contexts) {
13364 dd_dev_err(dd, "No receive contexts available for VNIC\n");
13365 num_vnic_contexts = 0;
13366 }
13367 total_contexts = num_kernel_contexts + num_vnic_contexts;
13368
Mike Marciniszyn77241052015-07-30 15:17:43 -040013369 /*
Jubin John0852d242016-04-12 11:30:08 -070013370 * User contexts:
13371 * - default to 1 user context per real (non-HT) CPU core if
13372 * num_user_contexts is negative
Mike Marciniszyn77241052015-07-30 15:17:43 -040013373 */
Sebastian Sanchez2ce6bf22015-12-11 08:44:48 -050013374 if (num_user_contexts < 0)
Jubin John0852d242016-04-12 11:30:08 -070013375 num_user_contexts =
Dennis Dalessandro41973442016-07-25 07:52:36 -070013376 cpumask_weight(&node_affinity.real_cpu_mask);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013377
Mike Marciniszyn77241052015-07-30 15:17:43 -040013378 /*
13379 * Adjust the counts given a global max.
13380 */
Michael J. Ruhld7d62612017-10-02 11:04:19 -070013381 if (total_contexts + num_user_contexts > dd->chip_rcv_contexts) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040013382 dd_dev_err(dd,
13383 "Reducing # user receive contexts to: %d, from %d\n",
Michael J. Ruhld7d62612017-10-02 11:04:19 -070013384 (int)(dd->chip_rcv_contexts - total_contexts),
Mike Marciniszyn77241052015-07-30 15:17:43 -040013385 (int)num_user_contexts);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013386 /* recalculate */
Michael J. Ruhld7d62612017-10-02 11:04:19 -070013387 num_user_contexts = dd->chip_rcv_contexts - total_contexts;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013388 }
13389
Dean Luick8f000f72016-04-12 11:32:06 -070013390 /* each user context requires an entry in the RMT */
13391 qos_rmt_count = qos_rmt_entries(dd, NULL, NULL);
13392 if (qos_rmt_count + num_user_contexts > NUM_MAP_ENTRIES) {
13393 user_rmt_reduced = NUM_MAP_ENTRIES - qos_rmt_count;
13394 dd_dev_err(dd,
13395 "RMT size is reducing the number of user receive contexts from %d to %d\n",
13396 (int)num_user_contexts,
13397 user_rmt_reduced);
13398 /* recalculate */
13399 num_user_contexts = user_rmt_reduced;
Dean Luick8f000f72016-04-12 11:32:06 -070013400 }
13401
Michael J. Ruhld7d62612017-10-02 11:04:19 -070013402 total_contexts += num_user_contexts;
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013403
13404 /* the first N are kernel contexts, the rest are user/vnic contexts */
Mike Marciniszyn77241052015-07-30 15:17:43 -040013405 dd->num_rcv_contexts = total_contexts;
13406 dd->n_krcv_queues = num_kernel_contexts;
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013407 dd->first_dyn_alloc_ctxt = num_kernel_contexts;
Michael J. Ruhld7d62612017-10-02 11:04:19 -070013408 dd->num_vnic_contexts = num_vnic_contexts;
Ashutosh Dixitaffa48d2016-02-03 14:33:06 -080013409 dd->num_user_contexts = num_user_contexts;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013410 dd->freectxts = num_user_contexts;
13411 dd_dev_info(dd,
Michael J. Ruhld7d62612017-10-02 11:04:19 -070013412 "rcv contexts: chip %d, used %d (kernel %d, vnic %u, user %u)\n",
Jubin John17fb4f22016-02-14 20:21:52 -080013413 (int)dd->chip_rcv_contexts,
13414 (int)dd->num_rcv_contexts,
13415 (int)dd->n_krcv_queues,
Michael J. Ruhld7d62612017-10-02 11:04:19 -070013416 dd->num_vnic_contexts,
13417 dd->num_user_contexts);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013418
13419 /*
13420 * Receive array allocation:
13421 * All RcvArray entries are divided into groups of 8. This
13422 * is required by the hardware and will speed up writes to
13423 * consecutive entries by using write-combining of the entire
13424 * cacheline.
13425 *
13426 * The number of groups are evenly divided among all contexts.
13427 * any left over groups will be given to the first N user
13428 * contexts.
13429 */
13430 dd->rcv_entries.group_size = RCV_INCREMENT;
13431 ngroups = dd->chip_rcv_array_count / dd->rcv_entries.group_size;
13432 dd->rcv_entries.ngroups = ngroups / dd->num_rcv_contexts;
13433 dd->rcv_entries.nctxt_extra = ngroups -
13434 (dd->num_rcv_contexts * dd->rcv_entries.ngroups);
13435 dd_dev_info(dd, "RcvArray groups %u, ctxts extra %u\n",
13436 dd->rcv_entries.ngroups,
13437 dd->rcv_entries.nctxt_extra);
13438 if (dd->rcv_entries.ngroups * dd->rcv_entries.group_size >
13439 MAX_EAGER_ENTRIES * 2) {
13440 dd->rcv_entries.ngroups = (MAX_EAGER_ENTRIES * 2) /
13441 dd->rcv_entries.group_size;
13442 dd_dev_info(dd,
Jubin John17fb4f22016-02-14 20:21:52 -080013443 "RcvArray group count too high, change to %u\n",
13444 dd->rcv_entries.ngroups);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013445 dd->rcv_entries.nctxt_extra = 0;
13446 }
13447 /*
13448 * PIO send contexts
13449 */
13450 ret = init_sc_pools_and_sizes(dd);
13451 if (ret >= 0) { /* success */
13452 dd->num_send_contexts = ret;
13453 dd_dev_info(
13454 dd,
Jianxin Xiong44306f12016-04-12 11:30:28 -070013455 "send contexts: chip %d, used %d (kernel %d, ack %d, user %d, vl15 %d)\n",
Mike Marciniszyn77241052015-07-30 15:17:43 -040013456 dd->chip_send_contexts,
13457 dd->num_send_contexts,
13458 dd->sc_sizes[SC_KERNEL].count,
13459 dd->sc_sizes[SC_ACK].count,
Jianxin Xiong44306f12016-04-12 11:30:28 -070013460 dd->sc_sizes[SC_USER].count,
13461 dd->sc_sizes[SC_VL15].count);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013462 ret = 0; /* success */
13463 }
13464
13465 return ret;
13466}
13467
13468/*
13469 * Set the device/port partition key table. The MAD code
13470 * will ensure that, at least, the partial management
13471 * partition key is present in the table.
13472 */
13473static void set_partition_keys(struct hfi1_pportdata *ppd)
13474{
13475 struct hfi1_devdata *dd = ppd->dd;
13476 u64 reg = 0;
13477 int i;
13478
13479 dd_dev_info(dd, "Setting partition keys\n");
13480 for (i = 0; i < hfi1_get_npkeys(dd); i++) {
13481 reg |= (ppd->pkeys[i] &
13482 RCV_PARTITION_KEY_PARTITION_KEY_A_MASK) <<
13483 ((i % 4) *
13484 RCV_PARTITION_KEY_PARTITION_KEY_B_SHIFT);
13485 /* Each register holds 4 PKey values. */
13486 if ((i % 4) == 3) {
13487 write_csr(dd, RCV_PARTITION_KEY +
13488 ((i - 3) * 2), reg);
13489 reg = 0;
13490 }
13491 }
13492
13493 /* Always enable HW pkeys check when pkeys table is set */
13494 add_rcvctrl(dd, RCV_CTRL_RCV_PARTITION_KEY_ENABLE_SMASK);
13495}
13496
13497/*
13498 * These CSRs and memories are uninitialized on reset and must be
13499 * written before reading to set the ECC/parity bits.
13500 *
13501 * NOTE: All user context CSRs that are not mmaped write-only
13502 * (e.g. the TID flows) must be initialized even if the driver never
13503 * reads them.
13504 */
13505static void write_uninitialized_csrs_and_memories(struct hfi1_devdata *dd)
13506{
13507 int i, j;
13508
13509 /* CceIntMap */
13510 for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
Jubin John8638b772016-02-14 20:19:24 -080013511 write_csr(dd, CCE_INT_MAP + (8 * i), 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013512
13513 /* SendCtxtCreditReturnAddr */
13514 for (i = 0; i < dd->chip_send_contexts; i++)
13515 write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
13516
13517 /* PIO Send buffers */
13518 /* SDMA Send buffers */
Jubin John4d114fd2016-02-14 20:21:43 -080013519 /*
13520 * These are not normally read, and (presently) have no method
13521 * to be read, so are not pre-initialized
13522 */
Mike Marciniszyn77241052015-07-30 15:17:43 -040013523
13524 /* RcvHdrAddr */
13525 /* RcvHdrTailAddr */
13526 /* RcvTidFlowTable */
13527 for (i = 0; i < dd->chip_rcv_contexts; i++) {
13528 write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
13529 write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
13530 for (j = 0; j < RXE_NUM_TID_FLOWS; j++)
Jubin John8638b772016-02-14 20:19:24 -080013531 write_uctxt_csr(dd, i, RCV_TID_FLOW_TABLE + (8 * j), 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013532 }
13533
13534 /* RcvArray */
13535 for (i = 0; i < dd->chip_rcv_array_count; i++)
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -070013536 hfi1_put_tid(dd, i, PT_INVALID_FLUSH, 0, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013537
13538 /* RcvQPMapTable */
13539 for (i = 0; i < 32; i++)
13540 write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
13541}
13542
13543/*
13544 * Use the ctrl_bits in CceCtrl to clear the status_bits in CceStatus.
13545 */
13546static void clear_cce_status(struct hfi1_devdata *dd, u64 status_bits,
13547 u64 ctrl_bits)
13548{
13549 unsigned long timeout;
13550 u64 reg;
13551
13552 /* is the condition present? */
13553 reg = read_csr(dd, CCE_STATUS);
13554 if ((reg & status_bits) == 0)
13555 return;
13556
13557 /* clear the condition */
13558 write_csr(dd, CCE_CTRL, ctrl_bits);
13559
13560 /* wait for the condition to clear */
13561 timeout = jiffies + msecs_to_jiffies(CCE_STATUS_TIMEOUT);
13562 while (1) {
13563 reg = read_csr(dd, CCE_STATUS);
13564 if ((reg & status_bits) == 0)
13565 return;
13566 if (time_after(jiffies, timeout)) {
13567 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -080013568 "Timeout waiting for CceStatus to clear bits 0x%llx, remaining 0x%llx\n",
13569 status_bits, reg & status_bits);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013570 return;
13571 }
13572 udelay(1);
13573 }
13574}
13575
13576/* set CCE CSRs to chip reset defaults */
13577static void reset_cce_csrs(struct hfi1_devdata *dd)
13578{
13579 int i;
13580
13581 /* CCE_REVISION read-only */
13582 /* CCE_REVISION2 read-only */
13583 /* CCE_CTRL - bits clear automatically */
13584 /* CCE_STATUS read-only, use CceCtrl to clear */
13585 clear_cce_status(dd, ALL_FROZE, CCE_CTRL_SPC_UNFREEZE_SMASK);
13586 clear_cce_status(dd, ALL_TXE_PAUSE, CCE_CTRL_TXE_RESUME_SMASK);
13587 clear_cce_status(dd, ALL_RXE_PAUSE, CCE_CTRL_RXE_RESUME_SMASK);
13588 for (i = 0; i < CCE_NUM_SCRATCH; i++)
13589 write_csr(dd, CCE_SCRATCH + (8 * i), 0);
13590 /* CCE_ERR_STATUS read-only */
13591 write_csr(dd, CCE_ERR_MASK, 0);
13592 write_csr(dd, CCE_ERR_CLEAR, ~0ull);
13593 /* CCE_ERR_FORCE leave alone */
13594 for (i = 0; i < CCE_NUM_32_BIT_COUNTERS; i++)
13595 write_csr(dd, CCE_COUNTER_ARRAY32 + (8 * i), 0);
13596 write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_RESETCSR);
13597 /* CCE_PCIE_CTRL leave alone */
13598 for (i = 0; i < CCE_NUM_MSIX_VECTORS; i++) {
13599 write_csr(dd, CCE_MSIX_TABLE_LOWER + (8 * i), 0);
13600 write_csr(dd, CCE_MSIX_TABLE_UPPER + (8 * i),
Jubin John17fb4f22016-02-14 20:21:52 -080013601 CCE_MSIX_TABLE_UPPER_RESETCSR);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013602 }
13603 for (i = 0; i < CCE_NUM_MSIX_PBAS; i++) {
13604 /* CCE_MSIX_PBA read-only */
13605 write_csr(dd, CCE_MSIX_INT_GRANTED, ~0ull);
13606 write_csr(dd, CCE_MSIX_VEC_CLR_WITHOUT_INT, ~0ull);
13607 }
13608 for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
13609 write_csr(dd, CCE_INT_MAP, 0);
13610 for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
13611 /* CCE_INT_STATUS read-only */
13612 write_csr(dd, CCE_INT_MASK + (8 * i), 0);
13613 write_csr(dd, CCE_INT_CLEAR + (8 * i), ~0ull);
13614 /* CCE_INT_FORCE leave alone */
13615 /* CCE_INT_BLOCKED read-only */
13616 }
13617 for (i = 0; i < CCE_NUM_32_BIT_INT_COUNTERS; i++)
13618 write_csr(dd, CCE_INT_COUNTER_ARRAY32 + (8 * i), 0);
13619}
13620
Mike Marciniszyn77241052015-07-30 15:17:43 -040013621/* set MISC CSRs to chip reset defaults */
13622static void reset_misc_csrs(struct hfi1_devdata *dd)
13623{
13624 int i;
13625
13626 for (i = 0; i < 32; i++) {
13627 write_csr(dd, MISC_CFG_RSA_R2 + (8 * i), 0);
13628 write_csr(dd, MISC_CFG_RSA_SIGNATURE + (8 * i), 0);
13629 write_csr(dd, MISC_CFG_RSA_MODULUS + (8 * i), 0);
13630 }
Jubin John4d114fd2016-02-14 20:21:43 -080013631 /*
13632 * MISC_CFG_SHA_PRELOAD leave alone - always reads 0 and can
13633 * only be written 128-byte chunks
13634 */
Mike Marciniszyn77241052015-07-30 15:17:43 -040013635 /* init RSA engine to clear lingering errors */
13636 write_csr(dd, MISC_CFG_RSA_CMD, 1);
13637 write_csr(dd, MISC_CFG_RSA_MU, 0);
13638 write_csr(dd, MISC_CFG_FW_CTRL, 0);
13639 /* MISC_STS_8051_DIGEST read-only */
13640 /* MISC_STS_SBM_DIGEST read-only */
13641 /* MISC_STS_PCIE_DIGEST read-only */
13642 /* MISC_STS_FAB_DIGEST read-only */
13643 /* MISC_ERR_STATUS read-only */
13644 write_csr(dd, MISC_ERR_MASK, 0);
13645 write_csr(dd, MISC_ERR_CLEAR, ~0ull);
13646 /* MISC_ERR_FORCE leave alone */
13647}
13648
13649/* set TXE CSRs to chip reset defaults */
13650static void reset_txe_csrs(struct hfi1_devdata *dd)
13651{
13652 int i;
13653
13654 /*
13655 * TXE Kernel CSRs
13656 */
13657 write_csr(dd, SEND_CTRL, 0);
13658 __cm_reset(dd, 0); /* reset CM internal state */
13659 /* SEND_CONTEXTS read-only */
13660 /* SEND_DMA_ENGINES read-only */
13661 /* SEND_PIO_MEM_SIZE read-only */
13662 /* SEND_DMA_MEM_SIZE read-only */
13663 write_csr(dd, SEND_HIGH_PRIORITY_LIMIT, 0);
13664 pio_reset_all(dd); /* SEND_PIO_INIT_CTXT */
13665 /* SEND_PIO_ERR_STATUS read-only */
13666 write_csr(dd, SEND_PIO_ERR_MASK, 0);
13667 write_csr(dd, SEND_PIO_ERR_CLEAR, ~0ull);
13668 /* SEND_PIO_ERR_FORCE leave alone */
13669 /* SEND_DMA_ERR_STATUS read-only */
13670 write_csr(dd, SEND_DMA_ERR_MASK, 0);
13671 write_csr(dd, SEND_DMA_ERR_CLEAR, ~0ull);
13672 /* SEND_DMA_ERR_FORCE leave alone */
13673 /* SEND_EGRESS_ERR_STATUS read-only */
13674 write_csr(dd, SEND_EGRESS_ERR_MASK, 0);
13675 write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~0ull);
13676 /* SEND_EGRESS_ERR_FORCE leave alone */
13677 write_csr(dd, SEND_BTH_QP, 0);
13678 write_csr(dd, SEND_STATIC_RATE_CONTROL, 0);
13679 write_csr(dd, SEND_SC2VLT0, 0);
13680 write_csr(dd, SEND_SC2VLT1, 0);
13681 write_csr(dd, SEND_SC2VLT2, 0);
13682 write_csr(dd, SEND_SC2VLT3, 0);
13683 write_csr(dd, SEND_LEN_CHECK0, 0);
13684 write_csr(dd, SEND_LEN_CHECK1, 0);
13685 /* SEND_ERR_STATUS read-only */
13686 write_csr(dd, SEND_ERR_MASK, 0);
13687 write_csr(dd, SEND_ERR_CLEAR, ~0ull);
13688 /* SEND_ERR_FORCE read-only */
13689 for (i = 0; i < VL_ARB_LOW_PRIO_TABLE_SIZE; i++)
Jubin John8638b772016-02-14 20:19:24 -080013690 write_csr(dd, SEND_LOW_PRIORITY_LIST + (8 * i), 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013691 for (i = 0; i < VL_ARB_HIGH_PRIO_TABLE_SIZE; i++)
Jubin John8638b772016-02-14 20:19:24 -080013692 write_csr(dd, SEND_HIGH_PRIORITY_LIST + (8 * i), 0);
13693 for (i = 0; i < dd->chip_send_contexts / NUM_CONTEXTS_PER_SET; i++)
13694 write_csr(dd, SEND_CONTEXT_SET_CTRL + (8 * i), 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013695 for (i = 0; i < TXE_NUM_32_BIT_COUNTER; i++)
Jubin John8638b772016-02-14 20:19:24 -080013696 write_csr(dd, SEND_COUNTER_ARRAY32 + (8 * i), 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013697 for (i = 0; i < TXE_NUM_64_BIT_COUNTER; i++)
Jubin John8638b772016-02-14 20:19:24 -080013698 write_csr(dd, SEND_COUNTER_ARRAY64 + (8 * i), 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013699 write_csr(dd, SEND_CM_CTRL, SEND_CM_CTRL_RESETCSR);
Jubin John17fb4f22016-02-14 20:21:52 -080013700 write_csr(dd, SEND_CM_GLOBAL_CREDIT, SEND_CM_GLOBAL_CREDIT_RESETCSR);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013701 /* SEND_CM_CREDIT_USED_STATUS read-only */
13702 write_csr(dd, SEND_CM_TIMER_CTRL, 0);
13703 write_csr(dd, SEND_CM_LOCAL_AU_TABLE0_TO3, 0);
13704 write_csr(dd, SEND_CM_LOCAL_AU_TABLE4_TO7, 0);
13705 write_csr(dd, SEND_CM_REMOTE_AU_TABLE0_TO3, 0);
13706 write_csr(dd, SEND_CM_REMOTE_AU_TABLE4_TO7, 0);
13707 for (i = 0; i < TXE_NUM_DATA_VL; i++)
Jubin John8638b772016-02-14 20:19:24 -080013708 write_csr(dd, SEND_CM_CREDIT_VL + (8 * i), 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013709 write_csr(dd, SEND_CM_CREDIT_VL15, 0);
13710 /* SEND_CM_CREDIT_USED_VL read-only */
13711 /* SEND_CM_CREDIT_USED_VL15 read-only */
13712 /* SEND_EGRESS_CTXT_STATUS read-only */
13713 /* SEND_EGRESS_SEND_DMA_STATUS read-only */
13714 write_csr(dd, SEND_EGRESS_ERR_INFO, ~0ull);
13715 /* SEND_EGRESS_ERR_INFO read-only */
13716 /* SEND_EGRESS_ERR_SOURCE read-only */
13717
13718 /*
13719 * TXE Per-Context CSRs
13720 */
13721 for (i = 0; i < dd->chip_send_contexts; i++) {
13722 write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
13723 write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_CTRL, 0);
13724 write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
13725 write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_FORCE, 0);
13726 write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, 0);
13727 write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~0ull);
13728 write_kctxt_csr(dd, i, SEND_CTXT_CHECK_ENABLE, 0);
13729 write_kctxt_csr(dd, i, SEND_CTXT_CHECK_VL, 0);
13730 write_kctxt_csr(dd, i, SEND_CTXT_CHECK_JOB_KEY, 0);
13731 write_kctxt_csr(dd, i, SEND_CTXT_CHECK_PARTITION_KEY, 0);
13732 write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, 0);
13733 write_kctxt_csr(dd, i, SEND_CTXT_CHECK_OPCODE, 0);
13734 }
13735
13736 /*
13737 * TXE Per-SDMA CSRs
13738 */
13739 for (i = 0; i < dd->chip_sdma_engines; i++) {
13740 write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
13741 /* SEND_DMA_STATUS read-only */
13742 write_kctxt_csr(dd, i, SEND_DMA_BASE_ADDR, 0);
13743 write_kctxt_csr(dd, i, SEND_DMA_LEN_GEN, 0);
13744 write_kctxt_csr(dd, i, SEND_DMA_TAIL, 0);
13745 /* SEND_DMA_HEAD read-only */
13746 write_kctxt_csr(dd, i, SEND_DMA_HEAD_ADDR, 0);
13747 write_kctxt_csr(dd, i, SEND_DMA_PRIORITY_THLD, 0);
13748 /* SEND_DMA_IDLE_CNT read-only */
13749 write_kctxt_csr(dd, i, SEND_DMA_RELOAD_CNT, 0);
13750 write_kctxt_csr(dd, i, SEND_DMA_DESC_CNT, 0);
13751 /* SEND_DMA_DESC_FETCHED_CNT read-only */
13752 /* SEND_DMA_ENG_ERR_STATUS read-only */
13753 write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, 0);
13754 write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~0ull);
13755 /* SEND_DMA_ENG_ERR_FORCE leave alone */
13756 write_kctxt_csr(dd, i, SEND_DMA_CHECK_ENABLE, 0);
13757 write_kctxt_csr(dd, i, SEND_DMA_CHECK_VL, 0);
13758 write_kctxt_csr(dd, i, SEND_DMA_CHECK_JOB_KEY, 0);
13759 write_kctxt_csr(dd, i, SEND_DMA_CHECK_PARTITION_KEY, 0);
13760 write_kctxt_csr(dd, i, SEND_DMA_CHECK_SLID, 0);
13761 write_kctxt_csr(dd, i, SEND_DMA_CHECK_OPCODE, 0);
13762 write_kctxt_csr(dd, i, SEND_DMA_MEMORY, 0);
13763 }
13764}
13765
13766/*
13767 * Expect on entry:
13768 * o Packet ingress is disabled, i.e. RcvCtrl.RcvPortEnable == 0
13769 */
13770static void init_rbufs(struct hfi1_devdata *dd)
13771{
13772 u64 reg;
13773 int count;
13774
13775 /*
13776 * Wait for DMA to stop: RxRbufPktPending and RxPktInProgress are
13777 * clear.
13778 */
13779 count = 0;
13780 while (1) {
13781 reg = read_csr(dd, RCV_STATUS);
13782 if ((reg & (RCV_STATUS_RX_RBUF_PKT_PENDING_SMASK
13783 | RCV_STATUS_RX_PKT_IN_PROGRESS_SMASK)) == 0)
13784 break;
13785 /*
13786 * Give up after 1ms - maximum wait time.
13787 *
Harish Chegondie8a70af2016-09-25 07:42:01 -070013788 * RBuf size is 136KiB. Slowest possible is PCIe Gen1 x1 at
Mike Marciniszyn77241052015-07-30 15:17:43 -040013789 * 250MB/s bandwidth. Lower rate to 66% for overhead to get:
Harish Chegondie8a70af2016-09-25 07:42:01 -070013790 * 136 KB / (66% * 250MB/s) = 844us
Mike Marciniszyn77241052015-07-30 15:17:43 -040013791 */
13792 if (count++ > 500) {
13793 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -080013794 "%s: in-progress DMA not clearing: RcvStatus 0x%llx, continuing\n",
13795 __func__, reg);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013796 break;
13797 }
13798 udelay(2); /* do not busy-wait the CSR */
13799 }
13800
13801 /* start the init - expect RcvCtrl to be 0 */
13802 write_csr(dd, RCV_CTRL, RCV_CTRL_RX_RBUF_INIT_SMASK);
13803
13804 /*
13805 * Read to force the write of Rcvtrl.RxRbufInit. There is a brief
13806 * period after the write before RcvStatus.RxRbufInitDone is valid.
13807 * The delay in the first run through the loop below is sufficient and
13808 * required before the first read of RcvStatus.RxRbufInintDone.
13809 */
13810 read_csr(dd, RCV_CTRL);
13811
13812 /* wait for the init to finish */
13813 count = 0;
13814 while (1) {
13815 /* delay is required first time through - see above */
13816 udelay(2); /* do not busy-wait the CSR */
13817 reg = read_csr(dd, RCV_STATUS);
13818 if (reg & (RCV_STATUS_RX_RBUF_INIT_DONE_SMASK))
13819 break;
13820
13821 /* give up after 100us - slowest possible at 33MHz is 73us */
13822 if (count++ > 50) {
13823 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -080013824 "%s: RcvStatus.RxRbufInit not set, continuing\n",
13825 __func__);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013826 break;
13827 }
13828 }
13829}
13830
13831/* set RXE CSRs to chip reset defaults */
13832static void reset_rxe_csrs(struct hfi1_devdata *dd)
13833{
13834 int i, j;
13835
13836 /*
13837 * RXE Kernel CSRs
13838 */
13839 write_csr(dd, RCV_CTRL, 0);
13840 init_rbufs(dd);
13841 /* RCV_STATUS read-only */
13842 /* RCV_CONTEXTS read-only */
13843 /* RCV_ARRAY_CNT read-only */
13844 /* RCV_BUF_SIZE read-only */
13845 write_csr(dd, RCV_BTH_QP, 0);
13846 write_csr(dd, RCV_MULTICAST, 0);
13847 write_csr(dd, RCV_BYPASS, 0);
13848 write_csr(dd, RCV_VL15, 0);
13849 /* this is a clear-down */
13850 write_csr(dd, RCV_ERR_INFO,
Jubin John17fb4f22016-02-14 20:21:52 -080013851 RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013852 /* RCV_ERR_STATUS read-only */
13853 write_csr(dd, RCV_ERR_MASK, 0);
13854 write_csr(dd, RCV_ERR_CLEAR, ~0ull);
13855 /* RCV_ERR_FORCE leave alone */
13856 for (i = 0; i < 32; i++)
13857 write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
13858 for (i = 0; i < 4; i++)
13859 write_csr(dd, RCV_PARTITION_KEY + (8 * i), 0);
13860 for (i = 0; i < RXE_NUM_32_BIT_COUNTERS; i++)
13861 write_csr(dd, RCV_COUNTER_ARRAY32 + (8 * i), 0);
13862 for (i = 0; i < RXE_NUM_64_BIT_COUNTERS; i++)
13863 write_csr(dd, RCV_COUNTER_ARRAY64 + (8 * i), 0);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070013864 for (i = 0; i < RXE_NUM_RSM_INSTANCES; i++)
13865 clear_rsm_rule(dd, i);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013866 for (i = 0; i < 32; i++)
13867 write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), 0);
13868
13869 /*
13870 * RXE Kernel and User Per-Context CSRs
13871 */
13872 for (i = 0; i < dd->chip_rcv_contexts; i++) {
13873 /* kernel */
13874 write_kctxt_csr(dd, i, RCV_CTXT_CTRL, 0);
13875 /* RCV_CTXT_STATUS read-only */
13876 write_kctxt_csr(dd, i, RCV_EGR_CTRL, 0);
13877 write_kctxt_csr(dd, i, RCV_TID_CTRL, 0);
13878 write_kctxt_csr(dd, i, RCV_KEY_CTRL, 0);
13879 write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
13880 write_kctxt_csr(dd, i, RCV_HDR_CNT, 0);
13881 write_kctxt_csr(dd, i, RCV_HDR_ENT_SIZE, 0);
13882 write_kctxt_csr(dd, i, RCV_HDR_SIZE, 0);
13883 write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
13884 write_kctxt_csr(dd, i, RCV_AVAIL_TIME_OUT, 0);
13885 write_kctxt_csr(dd, i, RCV_HDR_OVFL_CNT, 0);
13886
13887 /* user */
13888 /* RCV_HDR_TAIL read-only */
13889 write_uctxt_csr(dd, i, RCV_HDR_HEAD, 0);
13890 /* RCV_EGR_INDEX_TAIL read-only */
13891 write_uctxt_csr(dd, i, RCV_EGR_INDEX_HEAD, 0);
13892 /* RCV_EGR_OFFSET_TAIL read-only */
13893 for (j = 0; j < RXE_NUM_TID_FLOWS; j++) {
Jubin John17fb4f22016-02-14 20:21:52 -080013894 write_uctxt_csr(dd, i,
13895 RCV_TID_FLOW_TABLE + (8 * j), 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013896 }
13897 }
13898}
13899
13900/*
13901 * Set sc2vl tables.
13902 *
13903 * They power on to zeros, so to avoid send context errors
13904 * they need to be set:
13905 *
13906 * SC 0-7 -> VL 0-7 (respectively)
13907 * SC 15 -> VL 15
13908 * otherwise
13909 * -> VL 0
13910 */
13911static void init_sc2vl_tables(struct hfi1_devdata *dd)
13912{
13913 int i;
13914 /* init per architecture spec, constrained by hardware capability */
13915
13916 /* HFI maps sent packets */
13917 write_csr(dd, SEND_SC2VLT0, SC2VL_VAL(
13918 0,
13919 0, 0, 1, 1,
13920 2, 2, 3, 3,
13921 4, 4, 5, 5,
13922 6, 6, 7, 7));
13923 write_csr(dd, SEND_SC2VLT1, SC2VL_VAL(
13924 1,
13925 8, 0, 9, 0,
13926 10, 0, 11, 0,
13927 12, 0, 13, 0,
13928 14, 0, 15, 15));
13929 write_csr(dd, SEND_SC2VLT2, SC2VL_VAL(
13930 2,
13931 16, 0, 17, 0,
13932 18, 0, 19, 0,
13933 20, 0, 21, 0,
13934 22, 0, 23, 0));
13935 write_csr(dd, SEND_SC2VLT3, SC2VL_VAL(
13936 3,
13937 24, 0, 25, 0,
13938 26, 0, 27, 0,
13939 28, 0, 29, 0,
13940 30, 0, 31, 0));
13941
13942 /* DC maps received packets */
13943 write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0, DC_SC_VL_VAL(
13944 15_0,
13945 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7,
13946 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 15));
13947 write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16, DC_SC_VL_VAL(
13948 31_16,
13949 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0,
13950 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0));
13951
13952 /* initialize the cached sc2vl values consistently with h/w */
13953 for (i = 0; i < 32; i++) {
13954 if (i < 8 || i == 15)
13955 *((u8 *)(dd->sc2vl) + i) = (u8)i;
13956 else
13957 *((u8 *)(dd->sc2vl) + i) = 0;
13958 }
13959}
13960
13961/*
13962 * Read chip sizes and then reset parts to sane, disabled, values. We cannot
13963 * depend on the chip going through a power-on reset - a driver may be loaded
13964 * and unloaded many times.
13965 *
13966 * Do not write any CSR values to the chip in this routine - there may be
13967 * a reset following the (possible) FLR in this routine.
13968 *
13969 */
Bartlomiej Dudekc53df622017-06-30 13:14:40 -070013970static int init_chip(struct hfi1_devdata *dd)
Mike Marciniszyn77241052015-07-30 15:17:43 -040013971{
13972 int i;
Bartlomiej Dudekc53df622017-06-30 13:14:40 -070013973 int ret = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -040013974
13975 /*
13976 * Put the HFI CSRs in a known state.
13977 * Combine this with a DC reset.
13978 *
13979 * Stop the device from doing anything while we do a
13980 * reset. We know there are no other active users of
13981 * the device since we are now in charge. Turn off
13982 * off all outbound and inbound traffic and make sure
13983 * the device does not generate any interrupts.
13984 */
13985
13986 /* disable send contexts and SDMA engines */
13987 write_csr(dd, SEND_CTRL, 0);
13988 for (i = 0; i < dd->chip_send_contexts; i++)
13989 write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
13990 for (i = 0; i < dd->chip_sdma_engines; i++)
13991 write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
13992 /* disable port (turn off RXE inbound traffic) and contexts */
13993 write_csr(dd, RCV_CTRL, 0);
13994 for (i = 0; i < dd->chip_rcv_contexts; i++)
13995 write_csr(dd, RCV_CTXT_CTRL, 0);
13996 /* mask all interrupt sources */
13997 for (i = 0; i < CCE_NUM_INT_CSRS; i++)
Jubin John8638b772016-02-14 20:19:24 -080013998 write_csr(dd, CCE_INT_MASK + (8 * i), 0ull);
Mike Marciniszyn77241052015-07-30 15:17:43 -040013999
14000 /*
14001 * DC Reset: do a full DC reset before the register clear.
14002 * A recommended length of time to hold is one CSR read,
14003 * so reread the CceDcCtrl. Then, hold the DC in reset
14004 * across the clear.
14005 */
14006 write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_DC_RESET_SMASK);
Jubin John50e5dcb2016-02-14 20:19:41 -080014007 (void)read_csr(dd, CCE_DC_CTRL);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014008
14009 if (use_flr) {
14010 /*
14011 * A FLR will reset the SPC core and part of the PCIe.
14012 * The parts that need to be restored have already been
14013 * saved.
14014 */
14015 dd_dev_info(dd, "Resetting CSRs with FLR\n");
14016
14017 /* do the FLR, the DC reset will remain */
Christoph Hellwig21c433a2017-04-25 14:36:19 -050014018 pcie_flr(dd->pcidev);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014019
14020 /* restore command and BARs */
Bartlomiej Dudekc53df622017-06-30 13:14:40 -070014021 ret = restore_pci_variables(dd);
14022 if (ret) {
14023 dd_dev_err(dd, "%s: Could not restore PCI variables\n",
14024 __func__);
14025 return ret;
14026 }
Mike Marciniszyn77241052015-07-30 15:17:43 -040014027
Mike Marciniszyn995deaf2015-11-16 21:59:29 -050014028 if (is_ax(dd)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040014029 dd_dev_info(dd, "Resetting CSRs with FLR\n");
Christoph Hellwig21c433a2017-04-25 14:36:19 -050014030 pcie_flr(dd->pcidev);
Bartlomiej Dudekc53df622017-06-30 13:14:40 -070014031 ret = restore_pci_variables(dd);
14032 if (ret) {
14033 dd_dev_err(dd, "%s: Could not restore PCI variables\n",
14034 __func__);
14035 return ret;
14036 }
Mike Marciniszyn77241052015-07-30 15:17:43 -040014037 }
Mike Marciniszyn77241052015-07-30 15:17:43 -040014038 } else {
14039 dd_dev_info(dd, "Resetting CSRs with writes\n");
14040 reset_cce_csrs(dd);
14041 reset_txe_csrs(dd);
14042 reset_rxe_csrs(dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014043 reset_misc_csrs(dd);
14044 }
14045 /* clear the DC reset */
14046 write_csr(dd, CCE_DC_CTRL, 0);
Easwar Hariharan7c03ed82015-10-26 10:28:28 -040014047
Mike Marciniszyn77241052015-07-30 15:17:43 -040014048 /* Set the LED off */
Sebastian Sanchez773d04512016-02-09 14:29:40 -080014049 setextled(dd, 0);
14050
Mike Marciniszyn77241052015-07-30 15:17:43 -040014051 /*
14052 * Clear the QSFP reset.
Easwar Hariharan72a67ba2015-11-06 20:06:57 -050014053 * An FLR enforces a 0 on all out pins. The driver does not touch
Mike Marciniszyn77241052015-07-30 15:17:43 -040014054 * ASIC_QSFPn_OUT otherwise. This leaves RESET_N low and
Easwar Hariharan72a67ba2015-11-06 20:06:57 -050014055 * anything plugged constantly in reset, if it pays attention
Mike Marciniszyn77241052015-07-30 15:17:43 -040014056 * to RESET_N.
Easwar Hariharan72a67ba2015-11-06 20:06:57 -050014057 * Prime examples of this are optical cables. Set all pins high.
Mike Marciniszyn77241052015-07-30 15:17:43 -040014058 * I2CCLK and I2CDAT will change per direction, and INT_N and
14059 * MODPRS_N are input only and their value is ignored.
14060 */
Easwar Hariharan72a67ba2015-11-06 20:06:57 -050014061 write_csr(dd, ASIC_QSFP1_OUT, 0x1f);
14062 write_csr(dd, ASIC_QSFP2_OUT, 0x1f);
Dean Luicka2ee27a2016-03-05 08:49:50 -080014063 init_chip_resources(dd);
Bartlomiej Dudekc53df622017-06-30 13:14:40 -070014064 return ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014065}
14066
14067static void init_early_variables(struct hfi1_devdata *dd)
14068{
14069 int i;
14070
14071 /* assign link credit variables */
14072 dd->vau = CM_VAU;
14073 dd->link_credits = CM_GLOBAL_CREDITS;
Mike Marciniszyn995deaf2015-11-16 21:59:29 -050014074 if (is_ax(dd))
Mike Marciniszyn77241052015-07-30 15:17:43 -040014075 dd->link_credits--;
14076 dd->vcu = cu_to_vcu(hfi1_cu);
14077 /* enough room for 8 MAD packets plus header - 17K */
14078 dd->vl15_init = (8 * (2048 + 128)) / vau_to_au(dd->vau);
14079 if (dd->vl15_init > dd->link_credits)
14080 dd->vl15_init = dd->link_credits;
14081
14082 write_uninitialized_csrs_and_memories(dd);
14083
14084 if (HFI1_CAP_IS_KSET(PKEY_CHECK))
14085 for (i = 0; i < dd->num_pports; i++) {
14086 struct hfi1_pportdata *ppd = &dd->pport[i];
14087
14088 set_partition_keys(ppd);
14089 }
14090 init_sc2vl_tables(dd);
14091}
14092
14093static void init_kdeth_qp(struct hfi1_devdata *dd)
14094{
14095 /* user changed the KDETH_QP */
14096 if (kdeth_qp != 0 && kdeth_qp >= 0xff) {
14097 /* out of range or illegal value */
14098 dd_dev_err(dd, "Invalid KDETH queue pair prefix, ignoring");
14099 kdeth_qp = 0;
14100 }
14101 if (kdeth_qp == 0) /* not set, or failed range check */
14102 kdeth_qp = DEFAULT_KDETH_QP;
14103
14104 write_csr(dd, SEND_BTH_QP,
Jubin John17fb4f22016-02-14 20:21:52 -080014105 (kdeth_qp & SEND_BTH_QP_KDETH_QP_MASK) <<
14106 SEND_BTH_QP_KDETH_QP_SHIFT);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014107
14108 write_csr(dd, RCV_BTH_QP,
Jubin John17fb4f22016-02-14 20:21:52 -080014109 (kdeth_qp & RCV_BTH_QP_KDETH_QP_MASK) <<
14110 RCV_BTH_QP_KDETH_QP_SHIFT);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014111}
14112
14113/**
14114 * init_qpmap_table
14115 * @dd - device data
14116 * @first_ctxt - first context
14117 * @last_ctxt - first context
14118 *
14119 * This return sets the qpn mapping table that
14120 * is indexed by qpn[8:1].
14121 *
14122 * The routine will round robin the 256 settings
14123 * from first_ctxt to last_ctxt.
14124 *
14125 * The first/last looks ahead to having specialized
14126 * receive contexts for mgmt and bypass. Normal
14127 * verbs traffic will assumed to be on a range
14128 * of receive contexts.
14129 */
14130static void init_qpmap_table(struct hfi1_devdata *dd,
14131 u32 first_ctxt,
14132 u32 last_ctxt)
14133{
14134 u64 reg = 0;
14135 u64 regno = RCV_QP_MAP_TABLE;
14136 int i;
14137 u64 ctxt = first_ctxt;
14138
Dean Luick60d585ad2016-04-12 10:50:35 -070014139 for (i = 0; i < 256; i++) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040014140 reg |= ctxt << (8 * (i % 8));
Mike Marciniszyn77241052015-07-30 15:17:43 -040014141 ctxt++;
14142 if (ctxt > last_ctxt)
14143 ctxt = first_ctxt;
Dean Luick60d585ad2016-04-12 10:50:35 -070014144 if (i % 8 == 7) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040014145 write_csr(dd, regno, reg);
14146 reg = 0;
14147 regno += 8;
14148 }
14149 }
Mike Marciniszyn77241052015-07-30 15:17:43 -040014150
14151 add_rcvctrl(dd, RCV_CTRL_RCV_QP_MAP_ENABLE_SMASK
14152 | RCV_CTRL_RCV_BYPASS_ENABLE_SMASK);
14153}
14154
Dean Luick372cc85a2016-04-12 11:30:51 -070014155struct rsm_map_table {
14156 u64 map[NUM_MAP_REGS];
14157 unsigned int used;
14158};
14159
Dean Luickb12349a2016-04-12 11:31:33 -070014160struct rsm_rule_data {
14161 u8 offset;
14162 u8 pkt_type;
14163 u32 field1_off;
14164 u32 field2_off;
14165 u32 index1_off;
14166 u32 index1_width;
14167 u32 index2_off;
14168 u32 index2_width;
14169 u32 mask1;
14170 u32 value1;
14171 u32 mask2;
14172 u32 value2;
14173};
14174
Dean Luick372cc85a2016-04-12 11:30:51 -070014175/*
14176 * Return an initialized RMT map table for users to fill in. OK if it
14177 * returns NULL, indicating no table.
14178 */
14179static struct rsm_map_table *alloc_rsm_map_table(struct hfi1_devdata *dd)
14180{
14181 struct rsm_map_table *rmt;
14182 u8 rxcontext = is_ax(dd) ? 0 : 0xff; /* 0 is default if a0 ver. */
14183
14184 rmt = kmalloc(sizeof(*rmt), GFP_KERNEL);
14185 if (rmt) {
14186 memset(rmt->map, rxcontext, sizeof(rmt->map));
14187 rmt->used = 0;
14188 }
14189
14190 return rmt;
14191}
14192
14193/*
14194 * Write the final RMT map table to the chip and free the table. OK if
14195 * table is NULL.
14196 */
14197static void complete_rsm_map_table(struct hfi1_devdata *dd,
14198 struct rsm_map_table *rmt)
14199{
14200 int i;
14201
14202 if (rmt) {
14203 /* write table to chip */
14204 for (i = 0; i < NUM_MAP_REGS; i++)
14205 write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), rmt->map[i]);
14206
14207 /* enable RSM */
14208 add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
14209 }
14210}
14211
Dean Luickb12349a2016-04-12 11:31:33 -070014212/*
14213 * Add a receive side mapping rule.
14214 */
14215static void add_rsm_rule(struct hfi1_devdata *dd, u8 rule_index,
14216 struct rsm_rule_data *rrd)
14217{
14218 write_csr(dd, RCV_RSM_CFG + (8 * rule_index),
14219 (u64)rrd->offset << RCV_RSM_CFG_OFFSET_SHIFT |
14220 1ull << rule_index | /* enable bit */
14221 (u64)rrd->pkt_type << RCV_RSM_CFG_PACKET_TYPE_SHIFT);
14222 write_csr(dd, RCV_RSM_SELECT + (8 * rule_index),
14223 (u64)rrd->field1_off << RCV_RSM_SELECT_FIELD1_OFFSET_SHIFT |
14224 (u64)rrd->field2_off << RCV_RSM_SELECT_FIELD2_OFFSET_SHIFT |
14225 (u64)rrd->index1_off << RCV_RSM_SELECT_INDEX1_OFFSET_SHIFT |
14226 (u64)rrd->index1_width << RCV_RSM_SELECT_INDEX1_WIDTH_SHIFT |
14227 (u64)rrd->index2_off << RCV_RSM_SELECT_INDEX2_OFFSET_SHIFT |
14228 (u64)rrd->index2_width << RCV_RSM_SELECT_INDEX2_WIDTH_SHIFT);
14229 write_csr(dd, RCV_RSM_MATCH + (8 * rule_index),
14230 (u64)rrd->mask1 << RCV_RSM_MATCH_MASK1_SHIFT |
14231 (u64)rrd->value1 << RCV_RSM_MATCH_VALUE1_SHIFT |
14232 (u64)rrd->mask2 << RCV_RSM_MATCH_MASK2_SHIFT |
14233 (u64)rrd->value2 << RCV_RSM_MATCH_VALUE2_SHIFT);
14234}
14235
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070014236/*
14237 * Clear a receive side mapping rule.
14238 */
14239static void clear_rsm_rule(struct hfi1_devdata *dd, u8 rule_index)
14240{
14241 write_csr(dd, RCV_RSM_CFG + (8 * rule_index), 0);
14242 write_csr(dd, RCV_RSM_SELECT + (8 * rule_index), 0);
14243 write_csr(dd, RCV_RSM_MATCH + (8 * rule_index), 0);
14244}
14245
Dean Luick4a818be2016-04-12 11:31:11 -070014246/* return the number of RSM map table entries that will be used for QOS */
14247static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp,
14248 unsigned int *np)
14249{
14250 int i;
14251 unsigned int m, n;
14252 u8 max_by_vl = 0;
14253
14254 /* is QOS active at all? */
14255 if (dd->n_krcv_queues <= MIN_KERNEL_KCTXTS ||
14256 num_vls == 1 ||
14257 krcvqsset <= 1)
14258 goto no_qos;
14259
14260 /* determine bits for qpn */
14261 for (i = 0; i < min_t(unsigned int, num_vls, krcvqsset); i++)
14262 if (krcvqs[i] > max_by_vl)
14263 max_by_vl = krcvqs[i];
14264 if (max_by_vl > 32)
14265 goto no_qos;
14266 m = ilog2(__roundup_pow_of_two(max_by_vl));
14267
14268 /* determine bits for vl */
14269 n = ilog2(__roundup_pow_of_two(num_vls));
14270
14271 /* reject if too much is used */
14272 if ((m + n) > 7)
14273 goto no_qos;
14274
14275 if (mp)
14276 *mp = m;
14277 if (np)
14278 *np = n;
14279
14280 return 1 << (m + n);
14281
14282no_qos:
14283 if (mp)
14284 *mp = 0;
14285 if (np)
14286 *np = 0;
14287 return 0;
14288}
14289
Mike Marciniszyn77241052015-07-30 15:17:43 -040014290/**
14291 * init_qos - init RX qos
14292 * @dd - device data
Dean Luick372cc85a2016-04-12 11:30:51 -070014293 * @rmt - RSM map table
Mike Marciniszyn77241052015-07-30 15:17:43 -040014294 *
Dean Luick33a9eb52016-04-12 10:50:22 -070014295 * This routine initializes Rule 0 and the RSM map table to implement
14296 * quality of service (qos).
Mike Marciniszyn77241052015-07-30 15:17:43 -040014297 *
Dean Luick33a9eb52016-04-12 10:50:22 -070014298 * If all of the limit tests succeed, qos is applied based on the array
14299 * interpretation of krcvqs where entry 0 is VL0.
Mike Marciniszyn77241052015-07-30 15:17:43 -040014300 *
Dean Luick33a9eb52016-04-12 10:50:22 -070014301 * The number of vl bits (n) and the number of qpn bits (m) are computed to
14302 * feed both the RSM map table and the single rule.
Mike Marciniszyn77241052015-07-30 15:17:43 -040014303 */
Dean Luick372cc85a2016-04-12 11:30:51 -070014304static void init_qos(struct hfi1_devdata *dd, struct rsm_map_table *rmt)
Mike Marciniszyn77241052015-07-30 15:17:43 -040014305{
Dean Luickb12349a2016-04-12 11:31:33 -070014306 struct rsm_rule_data rrd;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014307 unsigned qpns_per_vl, ctxt, i, qpn, n = 1, m;
Dean Luick372cc85a2016-04-12 11:30:51 -070014308 unsigned int rmt_entries;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014309 u64 reg;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014310
Dean Luick4a818be2016-04-12 11:31:11 -070014311 if (!rmt)
Mike Marciniszyn77241052015-07-30 15:17:43 -040014312 goto bail;
Dean Luick4a818be2016-04-12 11:31:11 -070014313 rmt_entries = qos_rmt_entries(dd, &m, &n);
14314 if (rmt_entries == 0)
Mike Marciniszyn77241052015-07-30 15:17:43 -040014315 goto bail;
Dean Luick4a818be2016-04-12 11:31:11 -070014316 qpns_per_vl = 1 << m;
14317
Dean Luick372cc85a2016-04-12 11:30:51 -070014318 /* enough room in the map table? */
14319 rmt_entries = 1 << (m + n);
14320 if (rmt->used + rmt_entries >= NUM_MAP_ENTRIES)
Easwar Hariharan859bcad2015-12-10 11:13:38 -050014321 goto bail;
Dean Luick4a818be2016-04-12 11:31:11 -070014322
Dean Luick372cc85a2016-04-12 11:30:51 -070014323 /* add qos entries to the the RSM map table */
Dean Luick33a9eb52016-04-12 10:50:22 -070014324 for (i = 0, ctxt = FIRST_KERNEL_KCTXT; i < num_vls; i++) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040014325 unsigned tctxt;
14326
14327 for (qpn = 0, tctxt = ctxt;
14328 krcvqs[i] && qpn < qpns_per_vl; qpn++) {
14329 unsigned idx, regoff, regidx;
14330
Dean Luick372cc85a2016-04-12 11:30:51 -070014331 /* generate the index the hardware will produce */
14332 idx = rmt->used + ((qpn << n) ^ i);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014333 regoff = (idx % 8) * 8;
14334 regidx = idx / 8;
Dean Luick372cc85a2016-04-12 11:30:51 -070014335 /* replace default with context number */
14336 reg = rmt->map[regidx];
Mike Marciniszyn77241052015-07-30 15:17:43 -040014337 reg &= ~(RCV_RSM_MAP_TABLE_RCV_CONTEXT_A_MASK
14338 << regoff);
14339 reg |= (u64)(tctxt++) << regoff;
Dean Luick372cc85a2016-04-12 11:30:51 -070014340 rmt->map[regidx] = reg;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014341 if (tctxt == ctxt + krcvqs[i])
14342 tctxt = ctxt;
14343 }
14344 ctxt += krcvqs[i];
14345 }
Dean Luickb12349a2016-04-12 11:31:33 -070014346
14347 rrd.offset = rmt->used;
14348 rrd.pkt_type = 2;
14349 rrd.field1_off = LRH_BTH_MATCH_OFFSET;
14350 rrd.field2_off = LRH_SC_MATCH_OFFSET;
14351 rrd.index1_off = LRH_SC_SELECT_OFFSET;
14352 rrd.index1_width = n;
14353 rrd.index2_off = QPN_SELECT_OFFSET;
14354 rrd.index2_width = m + n;
14355 rrd.mask1 = LRH_BTH_MASK;
14356 rrd.value1 = LRH_BTH_VALUE;
14357 rrd.mask2 = LRH_SC_MASK;
14358 rrd.value2 = LRH_SC_VALUE;
14359
14360 /* add rule 0 */
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070014361 add_rsm_rule(dd, RSM_INS_VERBS, &rrd);
Dean Luickb12349a2016-04-12 11:31:33 -070014362
Dean Luick372cc85a2016-04-12 11:30:51 -070014363 /* mark RSM map entries as used */
14364 rmt->used += rmt_entries;
Dean Luick33a9eb52016-04-12 10:50:22 -070014365 /* map everything else to the mcast/err/vl15 context */
14366 init_qpmap_table(dd, HFI1_CTRL_CTXT, HFI1_CTRL_CTXT);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014367 dd->qos_shift = n + 1;
14368 return;
14369bail:
14370 dd->qos_shift = 1;
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -050014371 init_qpmap_table(dd, FIRST_KERNEL_KCTXT, dd->n_krcv_queues - 1);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014372}
14373
Dean Luick8f000f72016-04-12 11:32:06 -070014374static void init_user_fecn_handling(struct hfi1_devdata *dd,
14375 struct rsm_map_table *rmt)
14376{
14377 struct rsm_rule_data rrd;
14378 u64 reg;
14379 int i, idx, regoff, regidx;
14380 u8 offset;
14381
14382 /* there needs to be enough room in the map table */
14383 if (rmt->used + dd->num_user_contexts >= NUM_MAP_ENTRIES) {
14384 dd_dev_err(dd, "User FECN handling disabled - too many user contexts allocated\n");
14385 return;
14386 }
14387
14388 /*
14389 * RSM will extract the destination context as an index into the
14390 * map table. The destination contexts are a sequential block
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070014391 * in the range first_dyn_alloc_ctxt...num_rcv_contexts-1 (inclusive).
Dean Luick8f000f72016-04-12 11:32:06 -070014392 * Map entries are accessed as offset + extracted value. Adjust
14393 * the added offset so this sequence can be placed anywhere in
14394 * the table - as long as the entries themselves do not wrap.
14395 * There are only enough bits in offset for the table size, so
14396 * start with that to allow for a "negative" offset.
14397 */
14398 offset = (u8)(NUM_MAP_ENTRIES + (int)rmt->used -
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070014399 (int)dd->first_dyn_alloc_ctxt);
Dean Luick8f000f72016-04-12 11:32:06 -070014400
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070014401 for (i = dd->first_dyn_alloc_ctxt, idx = rmt->used;
Dean Luick8f000f72016-04-12 11:32:06 -070014402 i < dd->num_rcv_contexts; i++, idx++) {
14403 /* replace with identity mapping */
14404 regoff = (idx % 8) * 8;
14405 regidx = idx / 8;
14406 reg = rmt->map[regidx];
14407 reg &= ~(RCV_RSM_MAP_TABLE_RCV_CONTEXT_A_MASK << regoff);
14408 reg |= (u64)i << regoff;
14409 rmt->map[regidx] = reg;
14410 }
14411
14412 /*
14413 * For RSM intercept of Expected FECN packets:
14414 * o packet type 0 - expected
14415 * o match on F (bit 95), using select/match 1, and
14416 * o match on SH (bit 133), using select/match 2.
14417 *
14418 * Use index 1 to extract the 8-bit receive context from DestQP
14419 * (start at bit 64). Use that as the RSM map table index.
14420 */
14421 rrd.offset = offset;
14422 rrd.pkt_type = 0;
14423 rrd.field1_off = 95;
14424 rrd.field2_off = 133;
14425 rrd.index1_off = 64;
14426 rrd.index1_width = 8;
14427 rrd.index2_off = 0;
14428 rrd.index2_width = 0;
14429 rrd.mask1 = 1;
14430 rrd.value1 = 1;
14431 rrd.mask2 = 1;
14432 rrd.value2 = 1;
14433
14434 /* add rule 1 */
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070014435 add_rsm_rule(dd, RSM_INS_FECN, &rrd);
Dean Luick8f000f72016-04-12 11:32:06 -070014436
14437 rmt->used += dd->num_user_contexts;
14438}
14439
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070014440/* Initialize RSM for VNIC */
14441void hfi1_init_vnic_rsm(struct hfi1_devdata *dd)
14442{
14443 u8 i, j;
14444 u8 ctx_id = 0;
14445 u64 reg;
14446 u32 regoff;
14447 struct rsm_rule_data rrd;
14448
14449 if (hfi1_vnic_is_rsm_full(dd, NUM_VNIC_MAP_ENTRIES)) {
14450 dd_dev_err(dd, "Vnic RSM disabled, rmt entries used = %d\n",
14451 dd->vnic.rmt_start);
14452 return;
14453 }
14454
14455 dev_dbg(&(dd)->pcidev->dev, "Vnic rsm start = %d, end %d\n",
14456 dd->vnic.rmt_start,
14457 dd->vnic.rmt_start + NUM_VNIC_MAP_ENTRIES);
14458
14459 /* Update RSM mapping table, 32 regs, 256 entries - 1 ctx per byte */
14460 regoff = RCV_RSM_MAP_TABLE + (dd->vnic.rmt_start / 8) * 8;
14461 reg = read_csr(dd, regoff);
14462 for (i = 0; i < NUM_VNIC_MAP_ENTRIES; i++) {
14463 /* Update map register with vnic context */
14464 j = (dd->vnic.rmt_start + i) % 8;
14465 reg &= ~(0xffllu << (j * 8));
14466 reg |= (u64)dd->vnic.ctxt[ctx_id++]->ctxt << (j * 8);
14467 /* Wrap up vnic ctx index */
14468 ctx_id %= dd->vnic.num_ctxt;
14469 /* Write back map register */
14470 if (j == 7 || ((i + 1) == NUM_VNIC_MAP_ENTRIES)) {
14471 dev_dbg(&(dd)->pcidev->dev,
14472 "Vnic rsm map reg[%d] =0x%llx\n",
14473 regoff - RCV_RSM_MAP_TABLE, reg);
14474
14475 write_csr(dd, regoff, reg);
14476 regoff += 8;
14477 if (i < (NUM_VNIC_MAP_ENTRIES - 1))
14478 reg = read_csr(dd, regoff);
14479 }
14480 }
14481
14482 /* Add rule for vnic */
14483 rrd.offset = dd->vnic.rmt_start;
14484 rrd.pkt_type = 4;
14485 /* Match 16B packets */
14486 rrd.field1_off = L2_TYPE_MATCH_OFFSET;
14487 rrd.mask1 = L2_TYPE_MASK;
14488 rrd.value1 = L2_16B_VALUE;
14489 /* Match ETH L4 packets */
14490 rrd.field2_off = L4_TYPE_MATCH_OFFSET;
14491 rrd.mask2 = L4_16B_TYPE_MASK;
14492 rrd.value2 = L4_16B_ETH_VALUE;
14493 /* Calc context from veswid and entropy */
14494 rrd.index1_off = L4_16B_HDR_VESWID_OFFSET;
14495 rrd.index1_width = ilog2(NUM_VNIC_MAP_ENTRIES);
14496 rrd.index2_off = L2_16B_ENTROPY_OFFSET;
14497 rrd.index2_width = ilog2(NUM_VNIC_MAP_ENTRIES);
14498 add_rsm_rule(dd, RSM_INS_VNIC, &rrd);
14499
14500 /* Enable RSM if not already enabled */
14501 add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
14502}
14503
14504void hfi1_deinit_vnic_rsm(struct hfi1_devdata *dd)
14505{
14506 clear_rsm_rule(dd, RSM_INS_VNIC);
14507
14508 /* Disable RSM if used only by vnic */
14509 if (dd->vnic.rmt_start == 0)
14510 clear_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
14511}
14512
Mike Marciniszyn77241052015-07-30 15:17:43 -040014513static void init_rxe(struct hfi1_devdata *dd)
14514{
Dean Luick372cc85a2016-04-12 11:30:51 -070014515 struct rsm_map_table *rmt;
Don Hiatt72c07e22017-08-04 13:53:58 -070014516 u64 val;
Dean Luick372cc85a2016-04-12 11:30:51 -070014517
Mike Marciniszyn77241052015-07-30 15:17:43 -040014518 /* enable all receive errors */
14519 write_csr(dd, RCV_ERR_MASK, ~0ull);
Dean Luick372cc85a2016-04-12 11:30:51 -070014520
14521 rmt = alloc_rsm_map_table(dd);
14522 /* set up QOS, including the QPN map table */
14523 init_qos(dd, rmt);
Dean Luick8f000f72016-04-12 11:32:06 -070014524 init_user_fecn_handling(dd, rmt);
Dean Luick372cc85a2016-04-12 11:30:51 -070014525 complete_rsm_map_table(dd, rmt);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070014526 /* record number of used rsm map entries for vnic */
14527 dd->vnic.rmt_start = rmt->used;
Dean Luick372cc85a2016-04-12 11:30:51 -070014528 kfree(rmt);
14529
Mike Marciniszyn77241052015-07-30 15:17:43 -040014530 /*
14531 * make sure RcvCtrl.RcvWcb <= PCIe Device Control
14532 * Register Max_Payload_Size (PCI_EXP_DEVCTL in Linux PCIe config
14533 * space, PciCfgCap2.MaxPayloadSize in HFI). There is only one
14534 * invalid configuration: RcvCtrl.RcvWcb set to its max of 256 and
14535 * Max_PayLoad_Size set to its minimum of 128.
14536 *
14537 * Presently, RcvCtrl.RcvWcb is not modified from its default of 0
14538 * (64 bytes). Max_Payload_Size is possibly modified upward in
14539 * tune_pcie_caps() which is called after this routine.
14540 */
Don Hiatt72c07e22017-08-04 13:53:58 -070014541
14542 /* Have 16 bytes (4DW) of bypass header available in header queue */
14543 val = read_csr(dd, RCV_BYPASS);
14544 val |= (4ull << 16);
14545 write_csr(dd, RCV_BYPASS, val);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014546}
14547
14548static void init_other(struct hfi1_devdata *dd)
14549{
14550 /* enable all CCE errors */
14551 write_csr(dd, CCE_ERR_MASK, ~0ull);
14552 /* enable *some* Misc errors */
14553 write_csr(dd, MISC_ERR_MASK, DRIVER_MISC_MASK);
14554 /* enable all DC errors, except LCB */
14555 write_csr(dd, DCC_ERR_FLG_EN, ~0ull);
14556 write_csr(dd, DC_DC8051_ERR_EN, ~0ull);
14557}
14558
14559/*
14560 * Fill out the given AU table using the given CU. A CU is defined in terms
14561 * AUs. The table is a an encoding: given the index, how many AUs does that
14562 * represent?
14563 *
14564 * NOTE: Assumes that the register layout is the same for the
14565 * local and remote tables.
14566 */
14567static void assign_cm_au_table(struct hfi1_devdata *dd, u32 cu,
14568 u32 csr0to3, u32 csr4to7)
14569{
14570 write_csr(dd, csr0to3,
Jubin John17fb4f22016-02-14 20:21:52 -080014571 0ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE0_SHIFT |
14572 1ull << SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE1_SHIFT |
14573 2ull * cu <<
14574 SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE2_SHIFT |
14575 4ull * cu <<
14576 SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE3_SHIFT);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014577 write_csr(dd, csr4to7,
Jubin John17fb4f22016-02-14 20:21:52 -080014578 8ull * cu <<
14579 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE4_SHIFT |
14580 16ull * cu <<
14581 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE5_SHIFT |
14582 32ull * cu <<
14583 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE6_SHIFT |
14584 64ull * cu <<
14585 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE7_SHIFT);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014586}
14587
14588static void assign_local_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
14589{
14590 assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_LOCAL_AU_TABLE0_TO3,
Jubin John17fb4f22016-02-14 20:21:52 -080014591 SEND_CM_LOCAL_AU_TABLE4_TO7);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014592}
14593
14594void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
14595{
14596 assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_REMOTE_AU_TABLE0_TO3,
Jubin John17fb4f22016-02-14 20:21:52 -080014597 SEND_CM_REMOTE_AU_TABLE4_TO7);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014598}
14599
14600static void init_txe(struct hfi1_devdata *dd)
14601{
14602 int i;
14603
14604 /* enable all PIO, SDMA, general, and Egress errors */
14605 write_csr(dd, SEND_PIO_ERR_MASK, ~0ull);
14606 write_csr(dd, SEND_DMA_ERR_MASK, ~0ull);
14607 write_csr(dd, SEND_ERR_MASK, ~0ull);
14608 write_csr(dd, SEND_EGRESS_ERR_MASK, ~0ull);
14609
14610 /* enable all per-context and per-SDMA engine errors */
14611 for (i = 0; i < dd->chip_send_contexts; i++)
14612 write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, ~0ull);
14613 for (i = 0; i < dd->chip_sdma_engines; i++)
14614 write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, ~0ull);
14615
14616 /* set the local CU to AU mapping */
14617 assign_local_cm_au_table(dd, dd->vcu);
14618
14619 /*
14620 * Set reasonable default for Credit Return Timer
14621 * Don't set on Simulator - causes it to choke.
14622 */
14623 if (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)
14624 write_csr(dd, SEND_CM_TIMER_CTRL, HFI1_CREDIT_RETURN_RATE);
14625}
14626
Michael J. Ruhl17573972017-07-24 07:46:01 -070014627int hfi1_set_ctxt_jkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd,
14628 u16 jkey)
Mike Marciniszyn77241052015-07-30 15:17:43 -040014629{
Michael J. Ruhl17573972017-07-24 07:46:01 -070014630 u8 hw_ctxt;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014631 u64 reg;
14632
Michael J. Ruhl17573972017-07-24 07:46:01 -070014633 if (!rcd || !rcd->sc)
14634 return -EINVAL;
14635
14636 hw_ctxt = rcd->sc->hw_context;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014637 reg = SEND_CTXT_CHECK_JOB_KEY_MASK_SMASK | /* mask is always 1's */
14638 ((jkey & SEND_CTXT_CHECK_JOB_KEY_VALUE_MASK) <<
14639 SEND_CTXT_CHECK_JOB_KEY_VALUE_SHIFT);
14640 /* JOB_KEY_ALLOW_PERMISSIVE is not allowed by default */
14641 if (HFI1_CAP_KGET_MASK(rcd->flags, ALLOW_PERM_JKEY))
14642 reg |= SEND_CTXT_CHECK_JOB_KEY_ALLOW_PERMISSIVE_SMASK;
Michael J. Ruhl17573972017-07-24 07:46:01 -070014643 write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_JOB_KEY, reg);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014644 /*
14645 * Enable send-side J_KEY integrity check, unless this is A0 h/w
Mike Marciniszyn77241052015-07-30 15:17:43 -040014646 */
Mike Marciniszyn995deaf2015-11-16 21:59:29 -050014647 if (!is_ax(dd)) {
Michael J. Ruhl17573972017-07-24 07:46:01 -070014648 reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014649 reg |= SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
Michael J. Ruhl17573972017-07-24 07:46:01 -070014650 write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014651 }
14652
14653 /* Enable J_KEY check on receive context. */
14654 reg = RCV_KEY_CTRL_JOB_KEY_ENABLE_SMASK |
14655 ((jkey & RCV_KEY_CTRL_JOB_KEY_VALUE_MASK) <<
14656 RCV_KEY_CTRL_JOB_KEY_VALUE_SHIFT);
Michael J. Ruhl17573972017-07-24 07:46:01 -070014657 write_kctxt_csr(dd, rcd->ctxt, RCV_KEY_CTRL, reg);
14658
14659 return 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014660}
14661
Michael J. Ruhl17573972017-07-24 07:46:01 -070014662int hfi1_clear_ctxt_jkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd)
Mike Marciniszyn77241052015-07-30 15:17:43 -040014663{
Michael J. Ruhl17573972017-07-24 07:46:01 -070014664 u8 hw_ctxt;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014665 u64 reg;
14666
Michael J. Ruhl17573972017-07-24 07:46:01 -070014667 if (!rcd || !rcd->sc)
14668 return -EINVAL;
14669
14670 hw_ctxt = rcd->sc->hw_context;
14671 write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_JOB_KEY, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014672 /*
14673 * Disable send-side J_KEY integrity check, unless this is A0 h/w.
14674 * This check would not have been enabled for A0 h/w, see
14675 * set_ctxt_jkey().
14676 */
Mike Marciniszyn995deaf2015-11-16 21:59:29 -050014677 if (!is_ax(dd)) {
Michael J. Ruhl17573972017-07-24 07:46:01 -070014678 reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014679 reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
Michael J. Ruhl17573972017-07-24 07:46:01 -070014680 write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014681 }
14682 /* Turn off the J_KEY on the receive side */
Michael J. Ruhl17573972017-07-24 07:46:01 -070014683 write_kctxt_csr(dd, rcd->ctxt, RCV_KEY_CTRL, 0);
14684
14685 return 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014686}
14687
Michael J. Ruhl17573972017-07-24 07:46:01 -070014688int hfi1_set_ctxt_pkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd,
14689 u16 pkey)
Mike Marciniszyn77241052015-07-30 15:17:43 -040014690{
Michael J. Ruhl17573972017-07-24 07:46:01 -070014691 u8 hw_ctxt;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014692 u64 reg;
14693
Michael J. Ruhl17573972017-07-24 07:46:01 -070014694 if (!rcd || !rcd->sc)
14695 return -EINVAL;
14696
14697 hw_ctxt = rcd->sc->hw_context;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014698 reg = ((u64)pkey & SEND_CTXT_CHECK_PARTITION_KEY_VALUE_MASK) <<
14699 SEND_CTXT_CHECK_PARTITION_KEY_VALUE_SHIFT;
Michael J. Ruhl17573972017-07-24 07:46:01 -070014700 write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_PARTITION_KEY, reg);
14701 reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014702 reg |= SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
Sebastian Sancheze38d1e42016-04-12 11:22:21 -070014703 reg &= ~SEND_CTXT_CHECK_ENABLE_DISALLOW_KDETH_PACKETS_SMASK;
Michael J. Ruhl17573972017-07-24 07:46:01 -070014704 write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
14705
14706 return 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014707}
14708
Michael J. Ruhl637a9a72017-05-04 05:15:03 -070014709int hfi1_clear_ctxt_pkey(struct hfi1_devdata *dd, struct hfi1_ctxtdata *ctxt)
Mike Marciniszyn77241052015-07-30 15:17:43 -040014710{
Michael J. Ruhl637a9a72017-05-04 05:15:03 -070014711 u8 hw_ctxt;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014712 u64 reg;
14713
Michael J. Ruhl637a9a72017-05-04 05:15:03 -070014714 if (!ctxt || !ctxt->sc)
14715 return -EINVAL;
14716
Michael J. Ruhl637a9a72017-05-04 05:15:03 -070014717 hw_ctxt = ctxt->sc->hw_context;
14718 reg = read_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014719 reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
Michael J. Ruhl637a9a72017-05-04 05:15:03 -070014720 write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_ENABLE, reg);
14721 write_kctxt_csr(dd, hw_ctxt, SEND_CTXT_CHECK_PARTITION_KEY, 0);
14722
14723 return 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014724}
14725
14726/*
14727 * Start doing the clean up the the chip. Our clean up happens in multiple
14728 * stages and this is just the first.
14729 */
14730void hfi1_start_cleanup(struct hfi1_devdata *dd)
14731{
Ashutosh Dixitaffa48d2016-02-03 14:33:06 -080014732 aspm_exit(dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014733 free_cntrs(dd);
14734 free_rcverr(dd);
14735 clean_up_interrupts(dd);
Dean Luicka2ee27a2016-03-05 08:49:50 -080014736 finish_chip_resources(dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014737}
14738
14739#define HFI_BASE_GUID(dev) \
14740 ((dev)->base_guid & ~(1ULL << GUID_HFI_INDEX_SHIFT))
14741
14742/*
Dean Luick78eb1292016-03-05 08:49:45 -080014743 * Information can be shared between the two HFIs on the same ASIC
14744 * in the same OS. This function finds the peer device and sets
14745 * up a shared structure.
Mike Marciniszyn77241052015-07-30 15:17:43 -040014746 */
Dean Luick78eb1292016-03-05 08:49:45 -080014747static int init_asic_data(struct hfi1_devdata *dd)
Mike Marciniszyn77241052015-07-30 15:17:43 -040014748{
14749 unsigned long flags;
14750 struct hfi1_devdata *tmp, *peer = NULL;
Tadeusz Struk98f179a2016-07-06 17:14:47 -040014751 struct hfi1_asic_data *asic_data;
Dean Luick78eb1292016-03-05 08:49:45 -080014752 int ret = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014753
Tadeusz Struk98f179a2016-07-06 17:14:47 -040014754 /* pre-allocate the asic structure in case we are the first device */
14755 asic_data = kzalloc(sizeof(*dd->asic_data), GFP_KERNEL);
14756 if (!asic_data)
14757 return -ENOMEM;
14758
Mike Marciniszyn77241052015-07-30 15:17:43 -040014759 spin_lock_irqsave(&hfi1_devs_lock, flags);
14760 /* Find our peer device */
14761 list_for_each_entry(tmp, &hfi1_dev_list, list) {
14762 if ((HFI_BASE_GUID(dd) == HFI_BASE_GUID(tmp)) &&
14763 dd->unit != tmp->unit) {
14764 peer = tmp;
14765 break;
14766 }
14767 }
14768
Dean Luick78eb1292016-03-05 08:49:45 -080014769 if (peer) {
Tadeusz Struk98f179a2016-07-06 17:14:47 -040014770 /* use already allocated structure */
Dean Luick78eb1292016-03-05 08:49:45 -080014771 dd->asic_data = peer->asic_data;
Tadeusz Struk98f179a2016-07-06 17:14:47 -040014772 kfree(asic_data);
Dean Luick78eb1292016-03-05 08:49:45 -080014773 } else {
Tadeusz Struk98f179a2016-07-06 17:14:47 -040014774 dd->asic_data = asic_data;
Dean Luick78eb1292016-03-05 08:49:45 -080014775 mutex_init(&dd->asic_data->asic_resource_mutex);
14776 }
14777 dd->asic_data->dds[dd->hfi1_id] = dd; /* self back-pointer */
Mike Marciniszyn77241052015-07-30 15:17:43 -040014778 spin_unlock_irqrestore(&hfi1_devs_lock, flags);
Dean Luickdba715f2016-07-06 17:28:52 -040014779
14780 /* first one through - set up i2c devices */
14781 if (!peer)
14782 ret = set_up_i2c(dd, dd->asic_data);
14783
Dean Luick78eb1292016-03-05 08:49:45 -080014784 return ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014785}
14786
Dean Luick5d9157a2015-11-16 21:59:34 -050014787/*
14788 * Set dd->boardname. Use a generic name if a name is not returned from
14789 * EFI variable space.
14790 *
14791 * Return 0 on success, -ENOMEM if space could not be allocated.
14792 */
14793static int obtain_boardname(struct hfi1_devdata *dd)
14794{
14795 /* generic board description */
14796 const char generic[] =
14797 "Intel Omni-Path Host Fabric Interface Adapter 100 Series";
14798 unsigned long size;
14799 int ret;
14800
14801 ret = read_hfi1_efi_var(dd, "description", &size,
14802 (void **)&dd->boardname);
14803 if (ret) {
Dean Luick845f8762016-02-03 14:31:57 -080014804 dd_dev_info(dd, "Board description not found\n");
Dean Luick5d9157a2015-11-16 21:59:34 -050014805 /* use generic description */
14806 dd->boardname = kstrdup(generic, GFP_KERNEL);
14807 if (!dd->boardname)
14808 return -ENOMEM;
14809 }
14810 return 0;
14811}
14812
Kaike Wan24487dd2016-02-26 13:33:23 -080014813/*
14814 * Check the interrupt registers to make sure that they are mapped correctly.
14815 * It is intended to help user identify any mismapping by VMM when the driver
14816 * is running in a VM. This function should only be called before interrupt
14817 * is set up properly.
14818 *
14819 * Return 0 on success, -EINVAL on failure.
14820 */
14821static int check_int_registers(struct hfi1_devdata *dd)
14822{
14823 u64 reg;
14824 u64 all_bits = ~(u64)0;
14825 u64 mask;
14826
14827 /* Clear CceIntMask[0] to avoid raising any interrupts */
14828 mask = read_csr(dd, CCE_INT_MASK);
14829 write_csr(dd, CCE_INT_MASK, 0ull);
14830 reg = read_csr(dd, CCE_INT_MASK);
14831 if (reg)
14832 goto err_exit;
14833
14834 /* Clear all interrupt status bits */
14835 write_csr(dd, CCE_INT_CLEAR, all_bits);
14836 reg = read_csr(dd, CCE_INT_STATUS);
14837 if (reg)
14838 goto err_exit;
14839
14840 /* Set all interrupt status bits */
14841 write_csr(dd, CCE_INT_FORCE, all_bits);
14842 reg = read_csr(dd, CCE_INT_STATUS);
14843 if (reg != all_bits)
14844 goto err_exit;
14845
14846 /* Restore the interrupt mask */
14847 write_csr(dd, CCE_INT_CLEAR, all_bits);
14848 write_csr(dd, CCE_INT_MASK, mask);
14849
14850 return 0;
14851err_exit:
14852 write_csr(dd, CCE_INT_MASK, mask);
14853 dd_dev_err(dd, "Interrupt registers not properly mapped by VMM\n");
14854 return -EINVAL;
14855}
14856
Mike Marciniszyn77241052015-07-30 15:17:43 -040014857/**
Easwar Hariharan7c03ed82015-10-26 10:28:28 -040014858 * Allocate and initialize the device structure for the hfi.
Mike Marciniszyn77241052015-07-30 15:17:43 -040014859 * @dev: the pci_dev for hfi1_ib device
14860 * @ent: pci_device_id struct for this dev
14861 *
14862 * Also allocates, initializes, and returns the devdata struct for this
14863 * device instance
14864 *
14865 * This is global, and is called directly at init to set up the
14866 * chip-specific function pointers for later use.
14867 */
14868struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
14869 const struct pci_device_id *ent)
14870{
14871 struct hfi1_devdata *dd;
14872 struct hfi1_pportdata *ppd;
14873 u64 reg;
14874 int i, ret;
14875 static const char * const inames[] = { /* implementation names */
14876 "RTL silicon",
14877 "RTL VCS simulation",
14878 "RTL FPGA emulation",
14879 "Functional simulator"
14880 };
Kaike Wan24487dd2016-02-26 13:33:23 -080014881 struct pci_dev *parent = pdev->bus->self;
Mike Marciniszyn77241052015-07-30 15:17:43 -040014882
Jubin John17fb4f22016-02-14 20:21:52 -080014883 dd = hfi1_alloc_devdata(pdev, NUM_IB_PORTS *
14884 sizeof(struct hfi1_pportdata));
Mike Marciniszyn77241052015-07-30 15:17:43 -040014885 if (IS_ERR(dd))
14886 goto bail;
14887 ppd = dd->pport;
14888 for (i = 0; i < dd->num_pports; i++, ppd++) {
14889 int vl;
14890 /* init common fields */
14891 hfi1_init_pportdata(pdev, ppd, dd, 0, 1);
14892 /* DC supports 4 link widths */
14893 ppd->link_width_supported =
14894 OPA_LINK_WIDTH_1X | OPA_LINK_WIDTH_2X |
14895 OPA_LINK_WIDTH_3X | OPA_LINK_WIDTH_4X;
14896 ppd->link_width_downgrade_supported =
14897 ppd->link_width_supported;
14898 /* start out enabling only 4X */
14899 ppd->link_width_enabled = OPA_LINK_WIDTH_4X;
14900 ppd->link_width_downgrade_enabled =
14901 ppd->link_width_downgrade_supported;
14902 /* link width active is 0 when link is down */
14903 /* link width downgrade active is 0 when link is down */
14904
Jubin Johnd0d236e2016-02-14 20:20:15 -080014905 if (num_vls < HFI1_MIN_VLS_SUPPORTED ||
14906 num_vls > HFI1_MAX_VLS_SUPPORTED) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040014907 hfi1_early_err(&pdev->dev,
14908 "Invalid num_vls %u, using %u VLs\n",
14909 num_vls, HFI1_MAX_VLS_SUPPORTED);
14910 num_vls = HFI1_MAX_VLS_SUPPORTED;
14911 }
14912 ppd->vls_supported = num_vls;
14913 ppd->vls_operational = ppd->vls_supported;
14914 /* Set the default MTU. */
14915 for (vl = 0; vl < num_vls; vl++)
14916 dd->vld[vl].mtu = hfi1_max_mtu;
14917 dd->vld[15].mtu = MAX_MAD_PACKET;
14918 /*
14919 * Set the initial values to reasonable default, will be set
14920 * for real when link is up.
14921 */
Mike Marciniszyn77241052015-07-30 15:17:43 -040014922 ppd->overrun_threshold = 0x4;
14923 ppd->phy_error_threshold = 0xf;
14924 ppd->port_crc_mode_enabled = link_crc_mask;
14925 /* initialize supported LTP CRC mode */
14926 ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
14927 /* initialize enabled LTP CRC mode */
14928 ppd->port_ltp_crc_mode |= cap_to_port_ltp(link_crc_mask) << 4;
14929 /* start in offline */
14930 ppd->host_link_state = HLS_DN_OFFLINE;
14931 init_vl_arb_caches(ppd);
14932 }
14933
Mike Marciniszyn77241052015-07-30 15:17:43 -040014934 /*
14935 * Do remaining PCIe setup and save PCIe values in dd.
14936 * Any error printing is already done by the init code.
14937 * On return, we have the chip mapped.
14938 */
Easwar Hariharan26ea2542016-10-17 04:19:58 -070014939 ret = hfi1_pcie_ddinit(dd, pdev);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014940 if (ret < 0)
14941 goto bail_free;
14942
Bartlomiej Dudeka618b7e2017-07-24 07:46:30 -070014943 /* Save PCI space registers to rewrite after device reset */
14944 ret = save_pci_variables(dd);
14945 if (ret < 0)
14946 goto bail_cleanup;
14947
Mike Marciniszyn77241052015-07-30 15:17:43 -040014948 /* verify that reads actually work, save revision for reset check */
14949 dd->revision = read_csr(dd, CCE_REVISION);
14950 if (dd->revision == ~(u64)0) {
14951 dd_dev_err(dd, "cannot read chip CSRs\n");
14952 ret = -EINVAL;
14953 goto bail_cleanup;
14954 }
14955 dd->majrev = (dd->revision >> CCE_REVISION_CHIP_REV_MAJOR_SHIFT)
14956 & CCE_REVISION_CHIP_REV_MAJOR_MASK;
14957 dd->minrev = (dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT)
14958 & CCE_REVISION_CHIP_REV_MINOR_MASK;
14959
Jubin John4d114fd2016-02-14 20:21:43 -080014960 /*
Kaike Wan24487dd2016-02-26 13:33:23 -080014961 * Check interrupt registers mapping if the driver has no access to
14962 * the upstream component. In this case, it is likely that the driver
14963 * is running in a VM.
14964 */
14965 if (!parent) {
14966 ret = check_int_registers(dd);
14967 if (ret)
14968 goto bail_cleanup;
14969 }
14970
14971 /*
Jubin John4d114fd2016-02-14 20:21:43 -080014972 * obtain the hardware ID - NOT related to unit, which is a
14973 * software enumeration
14974 */
Mike Marciniszyn77241052015-07-30 15:17:43 -040014975 reg = read_csr(dd, CCE_REVISION2);
14976 dd->hfi1_id = (reg >> CCE_REVISION2_HFI_ID_SHIFT)
14977 & CCE_REVISION2_HFI_ID_MASK;
14978 /* the variable size will remove unwanted bits */
14979 dd->icode = reg >> CCE_REVISION2_IMPL_CODE_SHIFT;
14980 dd->irev = reg >> CCE_REVISION2_IMPL_REVISION_SHIFT;
14981 dd_dev_info(dd, "Implementation: %s, revision 0x%x\n",
Jubin John17fb4f22016-02-14 20:21:52 -080014982 dd->icode < ARRAY_SIZE(inames) ?
14983 inames[dd->icode] : "unknown", (int)dd->irev);
Mike Marciniszyn77241052015-07-30 15:17:43 -040014984
14985 /* speeds the hardware can support */
14986 dd->pport->link_speed_supported = OPA_LINK_SPEED_25G;
14987 /* speeds allowed to run at */
14988 dd->pport->link_speed_enabled = dd->pport->link_speed_supported;
14989 /* give a reasonable active value, will be set on link up */
14990 dd->pport->link_speed_active = OPA_LINK_SPEED_25G;
14991
14992 dd->chip_rcv_contexts = read_csr(dd, RCV_CONTEXTS);
14993 dd->chip_send_contexts = read_csr(dd, SEND_CONTEXTS);
14994 dd->chip_sdma_engines = read_csr(dd, SEND_DMA_ENGINES);
14995 dd->chip_pio_mem_size = read_csr(dd, SEND_PIO_MEM_SIZE);
14996 dd->chip_sdma_mem_size = read_csr(dd, SEND_DMA_MEM_SIZE);
14997 /* fix up link widths for emulation _p */
14998 ppd = dd->pport;
14999 if (dd->icode == ICODE_FPGA_EMULATION && is_emulator_p(dd)) {
15000 ppd->link_width_supported =
15001 ppd->link_width_enabled =
15002 ppd->link_width_downgrade_supported =
15003 ppd->link_width_downgrade_enabled =
15004 OPA_LINK_WIDTH_1X;
15005 }
15006 /* insure num_vls isn't larger than number of sdma engines */
15007 if (HFI1_CAP_IS_KSET(SDMA) && num_vls > dd->chip_sdma_engines) {
15008 dd_dev_err(dd, "num_vls %u too large, using %u VLs\n",
Dean Luick11a59092015-12-01 15:38:18 -050015009 num_vls, dd->chip_sdma_engines);
15010 num_vls = dd->chip_sdma_engines;
15011 ppd->vls_supported = dd->chip_sdma_engines;
Mike Marciniszyn8a4d3442016-02-14 12:46:01 -080015012 ppd->vls_operational = ppd->vls_supported;
Mike Marciniszyn77241052015-07-30 15:17:43 -040015013 }
15014
15015 /*
15016 * Convert the ns parameter to the 64 * cclocks used in the CSR.
15017 * Limit the max if larger than the field holds. If timeout is
15018 * non-zero, then the calculated field will be at least 1.
15019 *
15020 * Must be after icode is set up - the cclock rate depends
15021 * on knowing the hardware being used.
15022 */
15023 dd->rcv_intr_timeout_csr = ns_to_cclock(dd, rcv_intr_timeout) / 64;
15024 if (dd->rcv_intr_timeout_csr >
15025 RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK)
15026 dd->rcv_intr_timeout_csr =
15027 RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK;
15028 else if (dd->rcv_intr_timeout_csr == 0 && rcv_intr_timeout)
15029 dd->rcv_intr_timeout_csr = 1;
15030
Easwar Hariharan7c03ed82015-10-26 10:28:28 -040015031 /* needs to be done before we look for the peer device */
15032 read_guid(dd);
15033
Dean Luick78eb1292016-03-05 08:49:45 -080015034 /* set up shared ASIC data with peer device */
15035 ret = init_asic_data(dd);
15036 if (ret)
15037 goto bail_cleanup;
Easwar Hariharan7c03ed82015-10-26 10:28:28 -040015038
Mike Marciniszyn77241052015-07-30 15:17:43 -040015039 /* obtain chip sizes, reset chip CSRs */
Bartlomiej Dudekc53df622017-06-30 13:14:40 -070015040 ret = init_chip(dd);
15041 if (ret)
15042 goto bail_cleanup;
Mike Marciniszyn77241052015-07-30 15:17:43 -040015043
15044 /* read in the PCIe link speed information */
15045 ret = pcie_speeds(dd);
15046 if (ret)
15047 goto bail_cleanup;
15048
Dean Luicke83eba22016-09-30 04:41:45 -070015049 /* call before get_platform_config(), after init_chip_resources() */
15050 ret = eprom_init(dd);
15051 if (ret)
15052 goto bail_free_rcverr;
15053
Easwar Hariharanc3838b32016-02-09 14:29:13 -080015054 /* Needs to be called before hfi1_firmware_init */
15055 get_platform_config(dd);
15056
Mike Marciniszyn77241052015-07-30 15:17:43 -040015057 /* read in firmware */
15058 ret = hfi1_firmware_init(dd);
15059 if (ret)
15060 goto bail_cleanup;
15061
15062 /*
15063 * In general, the PCIe Gen3 transition must occur after the
15064 * chip has been idled (so it won't initiate any PCIe transactions
15065 * e.g. an interrupt) and before the driver changes any registers
15066 * (the transition will reset the registers).
15067 *
15068 * In particular, place this call after:
15069 * - init_chip() - the chip will not initiate any PCIe transactions
15070 * - pcie_speeds() - reads the current link speed
15071 * - hfi1_firmware_init() - the needed firmware is ready to be
15072 * downloaded
15073 */
15074 ret = do_pcie_gen3_transition(dd);
15075 if (ret)
15076 goto bail_cleanup;
15077
15078 /* start setting dd values and adjusting CSRs */
15079 init_early_variables(dd);
15080
15081 parse_platform_config(dd);
15082
Dean Luick5d9157a2015-11-16 21:59:34 -050015083 ret = obtain_boardname(dd);
15084 if (ret)
Mike Marciniszyn77241052015-07-30 15:17:43 -040015085 goto bail_cleanup;
Mike Marciniszyn77241052015-07-30 15:17:43 -040015086
15087 snprintf(dd->boardversion, BOARD_VERS_MAX,
Dean Luick5d9157a2015-11-16 21:59:34 -050015088 "ChipABI %u.%u, ChipRev %u.%u, SW Compat %llu\n",
Mike Marciniszyn77241052015-07-30 15:17:43 -040015089 HFI1_CHIP_VERS_MAJ, HFI1_CHIP_VERS_MIN,
Mike Marciniszyn77241052015-07-30 15:17:43 -040015090 (u32)dd->majrev,
15091 (u32)dd->minrev,
15092 (dd->revision >> CCE_REVISION_SW_SHIFT)
15093 & CCE_REVISION_SW_MASK);
15094
15095 ret = set_up_context_variables(dd);
15096 if (ret)
15097 goto bail_cleanup;
15098
15099 /* set initial RXE CSRs */
15100 init_rxe(dd);
15101 /* set initial TXE CSRs */
15102 init_txe(dd);
15103 /* set initial non-RXE, non-TXE CSRs */
15104 init_other(dd);
15105 /* set up KDETH QP prefix in both RX and TX CSRs */
15106 init_kdeth_qp(dd);
15107
Dennis Dalessandro41973442016-07-25 07:52:36 -070015108 ret = hfi1_dev_affinity_init(dd);
15109 if (ret)
15110 goto bail_cleanup;
Mitko Haralanov957558c2016-02-03 14:33:40 -080015111
Mike Marciniszyn77241052015-07-30 15:17:43 -040015112 /* send contexts must be set up before receive contexts */
15113 ret = init_send_contexts(dd);
15114 if (ret)
15115 goto bail_cleanup;
15116
Michael J. Ruhlf2a3bc02017-08-04 13:52:38 -070015117 ret = hfi1_create_kctxts(dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -040015118 if (ret)
15119 goto bail_cleanup;
15120
Michael J. Ruhlf2a3bc02017-08-04 13:52:38 -070015121 /*
15122 * Initialize aspm, to be done after gen3 transition and setting up
15123 * contexts and before enabling interrupts
15124 */
15125 aspm_init(dd);
15126
Mike Marciniszyn77241052015-07-30 15:17:43 -040015127 dd->rcvhdrsize = DEFAULT_RCVHDRSIZE;
15128 /*
15129 * rcd[0] is guaranteed to be valid by this point. Also, all
15130 * context are using the same value, as per the module parameter.
15131 */
15132 dd->rhf_offset = dd->rcd[0]->rcvhdrqentsize - sizeof(u64) / sizeof(u32);
15133
15134 ret = init_pervl_scs(dd);
15135 if (ret)
15136 goto bail_cleanup;
15137
15138 /* sdma init */
15139 for (i = 0; i < dd->num_pports; ++i) {
15140 ret = sdma_init(dd, i);
15141 if (ret)
15142 goto bail_cleanup;
15143 }
15144
Michael J. Ruhlf2a3bc02017-08-04 13:52:38 -070015145 /* use contexts created by hfi1_create_kctxts */
Mike Marciniszyn77241052015-07-30 15:17:43 -040015146 ret = set_up_interrupts(dd);
15147 if (ret)
15148 goto bail_cleanup;
15149
15150 /* set up LCB access - must be after set_up_interrupts() */
15151 init_lcb_access(dd);
15152
Ira Weinyfc0b76c2016-07-27 21:09:40 -040015153 /*
15154 * Serial number is created from the base guid:
15155 * [27:24] = base guid [38:35]
15156 * [23: 0] = base guid [23: 0]
15157 */
Mike Marciniszyn77241052015-07-30 15:17:43 -040015158 snprintf(dd->serial, SERIAL_MAX, "0x%08llx\n",
Ira Weinyfc0b76c2016-07-27 21:09:40 -040015159 (dd->base_guid & 0xFFFFFF) |
15160 ((dd->base_guid >> 11) & 0xF000000));
Mike Marciniszyn77241052015-07-30 15:17:43 -040015161
15162 dd->oui1 = dd->base_guid >> 56 & 0xFF;
15163 dd->oui2 = dd->base_guid >> 48 & 0xFF;
15164 dd->oui3 = dd->base_guid >> 40 & 0xFF;
15165
15166 ret = load_firmware(dd); /* asymmetric with dispose_firmware() */
15167 if (ret)
15168 goto bail_clear_intr;
Mike Marciniszyn77241052015-07-30 15:17:43 -040015169
15170 thermal_init(dd);
15171
15172 ret = init_cntrs(dd);
15173 if (ret)
15174 goto bail_clear_intr;
15175
15176 ret = init_rcverr(dd);
15177 if (ret)
15178 goto bail_free_cntrs;
15179
Tadeusz Strukacd7c8f2016-10-25 08:57:55 -070015180 init_completion(&dd->user_comp);
15181
15182 /* The user refcount starts with one to inidicate an active device */
15183 atomic_set(&dd->user_refcount, 1);
15184
Mike Marciniszyn77241052015-07-30 15:17:43 -040015185 goto bail;
15186
15187bail_free_rcverr:
15188 free_rcverr(dd);
15189bail_free_cntrs:
15190 free_cntrs(dd);
15191bail_clear_intr:
15192 clean_up_interrupts(dd);
15193bail_cleanup:
15194 hfi1_pcie_ddcleanup(dd);
15195bail_free:
15196 hfi1_free_devdata(dd);
15197 dd = ERR_PTR(ret);
15198bail:
15199 return dd;
15200}
15201
15202static u16 delay_cycles(struct hfi1_pportdata *ppd, u32 desired_egress_rate,
15203 u32 dw_len)
15204{
15205 u32 delta_cycles;
15206 u32 current_egress_rate = ppd->current_egress_rate;
15207 /* rates here are in units of 10^6 bits/sec */
15208
15209 if (desired_egress_rate == -1)
15210 return 0; /* shouldn't happen */
15211
15212 if (desired_egress_rate >= current_egress_rate)
15213 return 0; /* we can't help go faster, only slower */
15214
15215 delta_cycles = egress_cycles(dw_len * 4, desired_egress_rate) -
15216 egress_cycles(dw_len * 4, current_egress_rate);
15217
15218 return (u16)delta_cycles;
15219}
15220
Mike Marciniszyn77241052015-07-30 15:17:43 -040015221/**
15222 * create_pbc - build a pbc for transmission
15223 * @flags: special case flags or-ed in built pbc
15224 * @srate: static rate
15225 * @vl: vl
15226 * @dwlen: dword length (header words + data words + pbc words)
15227 *
15228 * Create a PBC with the given flags, rate, VL, and length.
15229 *
15230 * NOTE: The PBC created will not insert any HCRC - all callers but one are
15231 * for verbs, which does not use this PSM feature. The lone other caller
15232 * is for the diagnostic interface which calls this if the user does not
15233 * supply their own PBC.
15234 */
15235u64 create_pbc(struct hfi1_pportdata *ppd, u64 flags, int srate_mbs, u32 vl,
15236 u32 dw_len)
15237{
15238 u64 pbc, delay = 0;
15239
15240 if (unlikely(srate_mbs))
15241 delay = delay_cycles(ppd, srate_mbs, dw_len);
15242
15243 pbc = flags
15244 | (delay << PBC_STATIC_RATE_CONTROL_COUNT_SHIFT)
15245 | ((u64)PBC_IHCRC_NONE << PBC_INSERT_HCRC_SHIFT)
15246 | (vl & PBC_VL_MASK) << PBC_VL_SHIFT
15247 | (dw_len & PBC_LENGTH_DWS_MASK)
15248 << PBC_LENGTH_DWS_SHIFT;
15249
15250 return pbc;
15251}
15252
15253#define SBUS_THERMAL 0x4f
15254#define SBUS_THERM_MONITOR_MODE 0x1
15255
15256#define THERM_FAILURE(dev, ret, reason) \
15257 dd_dev_err((dd), \
15258 "Thermal sensor initialization failed: %s (%d)\n", \
15259 (reason), (ret))
15260
15261/*
Jakub Pawlakcde10af2016-05-12 10:23:35 -070015262 * Initialize the thermal sensor.
Mike Marciniszyn77241052015-07-30 15:17:43 -040015263 *
15264 * After initialization, enable polling of thermal sensor through
15265 * SBus interface. In order for this to work, the SBus Master
15266 * firmware has to be loaded due to the fact that the HW polling
15267 * logic uses SBus interrupts, which are not supported with
15268 * default firmware. Otherwise, no data will be returned through
15269 * the ASIC_STS_THERM CSR.
15270 */
15271static int thermal_init(struct hfi1_devdata *dd)
15272{
15273 int ret = 0;
15274
15275 if (dd->icode != ICODE_RTL_SILICON ||
Dean Luicka4536982016-03-05 08:50:11 -080015276 check_chip_resource(dd, CR_THERM_INIT, NULL))
Mike Marciniszyn77241052015-07-30 15:17:43 -040015277 return ret;
15278
Dean Luick576531f2016-03-05 08:50:01 -080015279 ret = acquire_chip_resource(dd, CR_SBUS, SBUS_TIMEOUT);
15280 if (ret) {
15281 THERM_FAILURE(dd, ret, "Acquire SBus");
15282 return ret;
15283 }
15284
Mike Marciniszyn77241052015-07-30 15:17:43 -040015285 dd_dev_info(dd, "Initializing thermal sensor\n");
Jareer Abdel-Qader4ef98982015-11-06 20:07:00 -050015286 /* Disable polling of thermal readings */
15287 write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x0);
15288 msleep(100);
Mike Marciniszyn77241052015-07-30 15:17:43 -040015289 /* Thermal Sensor Initialization */
15290 /* Step 1: Reset the Thermal SBus Receiver */
15291 ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
15292 RESET_SBUS_RECEIVER, 0);
15293 if (ret) {
15294 THERM_FAILURE(dd, ret, "Bus Reset");
15295 goto done;
15296 }
15297 /* Step 2: Set Reset bit in Thermal block */
15298 ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
15299 WRITE_SBUS_RECEIVER, 0x1);
15300 if (ret) {
15301 THERM_FAILURE(dd, ret, "Therm Block Reset");
15302 goto done;
15303 }
15304 /* Step 3: Write clock divider value (100MHz -> 2MHz) */
15305 ret = sbus_request_slow(dd, SBUS_THERMAL, 0x1,
15306 WRITE_SBUS_RECEIVER, 0x32);
15307 if (ret) {
15308 THERM_FAILURE(dd, ret, "Write Clock Div");
15309 goto done;
15310 }
15311 /* Step 4: Select temperature mode */
15312 ret = sbus_request_slow(dd, SBUS_THERMAL, 0x3,
15313 WRITE_SBUS_RECEIVER,
15314 SBUS_THERM_MONITOR_MODE);
15315 if (ret) {
15316 THERM_FAILURE(dd, ret, "Write Mode Sel");
15317 goto done;
15318 }
15319 /* Step 5: De-assert block reset and start conversion */
15320 ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
15321 WRITE_SBUS_RECEIVER, 0x2);
15322 if (ret) {
15323 THERM_FAILURE(dd, ret, "Write Reset Deassert");
15324 goto done;
15325 }
15326 /* Step 5.1: Wait for first conversion (21.5ms per spec) */
15327 msleep(22);
15328
15329 /* Enable polling of thermal readings */
15330 write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x1);
Dean Luicka4536982016-03-05 08:50:11 -080015331
15332 /* Set initialized flag */
15333 ret = acquire_chip_resource(dd, CR_THERM_INIT, 0);
15334 if (ret)
15335 THERM_FAILURE(dd, ret, "Unable to set thermal init flag");
15336
Mike Marciniszyn77241052015-07-30 15:17:43 -040015337done:
Dean Luick576531f2016-03-05 08:50:01 -080015338 release_chip_resource(dd, CR_SBUS);
Mike Marciniszyn77241052015-07-30 15:17:43 -040015339 return ret;
15340}
15341
15342static void handle_temp_err(struct hfi1_devdata *dd)
15343{
15344 struct hfi1_pportdata *ppd = &dd->pport[0];
15345 /*
15346 * Thermal Critical Interrupt
15347 * Put the device into forced freeze mode, take link down to
15348 * offline, and put DC into reset.
15349 */
15350 dd_dev_emerg(dd,
15351 "Critical temperature reached! Forcing device into freeze mode!\n");
15352 dd->flags |= HFI1_FORCED_FREEZE;
Jubin John8638b772016-02-14 20:19:24 -080015353 start_freeze_handling(ppd, FREEZE_SELF | FREEZE_ABORT);
Mike Marciniszyn77241052015-07-30 15:17:43 -040015354 /*
15355 * Shut DC down as much and as quickly as possible.
15356 *
15357 * Step 1: Take the link down to OFFLINE. This will cause the
15358 * 8051 to put the Serdes in reset. However, we don't want to
15359 * go through the entire link state machine since we want to
15360 * shutdown ASAP. Furthermore, this is not a graceful shutdown
15361 * but rather an attempt to save the chip.
15362 * Code below is almost the same as quiet_serdes() but avoids
15363 * all the extra work and the sleeps.
15364 */
15365 ppd->driver_link_ready = 0;
15366 ppd->link_enabled = 0;
Harish Chegondibf640092016-03-05 08:49:29 -080015367 set_physical_link_state(dd, (OPA_LINKDOWN_REASON_SMA_DISABLED << 8) |
15368 PLS_OFFLINE);
Mike Marciniszyn77241052015-07-30 15:17:43 -040015369 /*
15370 * Step 2: Shutdown LCB and 8051
15371 * After shutdown, do not restore DC_CFG_RESET value.
15372 */
15373 dc_shutdown(dd);
15374}