blob: 62813052fc9977bb4292745951892fc5a1720390 [file] [log] [blame]
Mike Marciniszyn77241052015-07-30 15:17:43 -04001/*
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2015 Intel Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * BSD LICENSE
20 *
21 * Copyright(c) 2015 Intel Corporation.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
32 * distribution.
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 */
50
51/*
52 * This file contains all of the code that is specific to the HFI chip
53 */
54
55#include <linux/pci.h>
56#include <linux/delay.h>
57#include <linux/interrupt.h>
58#include <linux/module.h>
59
60#include "hfi.h"
61#include "trace.h"
62#include "mad.h"
63#include "pio.h"
64#include "sdma.h"
65#include "eprom.h"
Dean Luick5d9157a2015-11-16 21:59:34 -050066#include "efivar.h"
Mike Marciniszyn77241052015-07-30 15:17:43 -040067
68#define NUM_IB_PORTS 1
69
70uint kdeth_qp;
71module_param_named(kdeth_qp, kdeth_qp, uint, S_IRUGO);
72MODULE_PARM_DESC(kdeth_qp, "Set the KDETH queue pair prefix");
73
74uint num_vls = HFI1_MAX_VLS_SUPPORTED;
75module_param(num_vls, uint, S_IRUGO);
76MODULE_PARM_DESC(num_vls, "Set number of Virtual Lanes to use (1-8)");
77
78/*
79 * Default time to aggregate two 10K packets from the idle state
80 * (timer not running). The timer starts at the end of the first packet,
81 * so only the time for one 10K packet and header plus a bit extra is needed.
82 * 10 * 1024 + 64 header byte = 10304 byte
83 * 10304 byte / 12.5 GB/s = 824.32ns
84 */
85uint rcv_intr_timeout = (824 + 16); /* 16 is for coalescing interrupt */
86module_param(rcv_intr_timeout, uint, S_IRUGO);
87MODULE_PARM_DESC(rcv_intr_timeout, "Receive interrupt mitigation timeout in ns");
88
89uint rcv_intr_count = 16; /* same as qib */
90module_param(rcv_intr_count, uint, S_IRUGO);
91MODULE_PARM_DESC(rcv_intr_count, "Receive interrupt mitigation count");
92
93ushort link_crc_mask = SUPPORTED_CRCS;
94module_param(link_crc_mask, ushort, S_IRUGO);
95MODULE_PARM_DESC(link_crc_mask, "CRCs to use on the link");
96
97uint loopback;
98module_param_named(loopback, loopback, uint, S_IRUGO);
99MODULE_PARM_DESC(loopback, "Put into loopback mode (1 = serdes, 3 = external cable");
100
101/* Other driver tunables */
102uint rcv_intr_dynamic = 1; /* enable dynamic mode for rcv int mitigation*/
103static ushort crc_14b_sideband = 1;
104static uint use_flr = 1;
105uint quick_linkup; /* skip LNI */
106
107struct flag_table {
108 u64 flag; /* the flag */
109 char *str; /* description string */
110 u16 extra; /* extra information */
111 u16 unused0;
112 u32 unused1;
113};
114
115/* str must be a string constant */
116#define FLAG_ENTRY(str, extra, flag) {flag, str, extra}
117#define FLAG_ENTRY0(str, flag) {flag, str, 0}
118
119/* Send Error Consequences */
120#define SEC_WRITE_DROPPED 0x1
121#define SEC_PACKET_DROPPED 0x2
122#define SEC_SC_HALTED 0x4 /* per-context only */
123#define SEC_SPC_FREEZE 0x8 /* per-HFI only */
124
Mike Marciniszyn77241052015-07-30 15:17:43 -0400125#define MIN_KERNEL_KCTXTS 2
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500126#define FIRST_KERNEL_KCTXT 1
Mike Marciniszyn77241052015-07-30 15:17:43 -0400127#define NUM_MAP_REGS 32
128
129/* Bit offset into the GUID which carries HFI id information */
130#define GUID_HFI_INDEX_SHIFT 39
131
132/* extract the emulation revision */
133#define emulator_rev(dd) ((dd)->irev >> 8)
134/* parallel and serial emulation versions are 3 and 4 respectively */
135#define is_emulator_p(dd) ((((dd)->irev) & 0xf) == 3)
136#define is_emulator_s(dd) ((((dd)->irev) & 0xf) == 4)
137
138/* RSM fields */
139
140/* packet type */
141#define IB_PACKET_TYPE 2ull
142#define QW_SHIFT 6ull
143/* QPN[7..1] */
144#define QPN_WIDTH 7ull
145
146/* LRH.BTH: QW 0, OFFSET 48 - for match */
147#define LRH_BTH_QW 0ull
148#define LRH_BTH_BIT_OFFSET 48ull
149#define LRH_BTH_OFFSET(off) ((LRH_BTH_QW << QW_SHIFT) | (off))
150#define LRH_BTH_MATCH_OFFSET LRH_BTH_OFFSET(LRH_BTH_BIT_OFFSET)
151#define LRH_BTH_SELECT
152#define LRH_BTH_MASK 3ull
153#define LRH_BTH_VALUE 2ull
154
155/* LRH.SC[3..0] QW 0, OFFSET 56 - for match */
156#define LRH_SC_QW 0ull
157#define LRH_SC_BIT_OFFSET 56ull
158#define LRH_SC_OFFSET(off) ((LRH_SC_QW << QW_SHIFT) | (off))
159#define LRH_SC_MATCH_OFFSET LRH_SC_OFFSET(LRH_SC_BIT_OFFSET)
160#define LRH_SC_MASK 128ull
161#define LRH_SC_VALUE 0ull
162
163/* SC[n..0] QW 0, OFFSET 60 - for select */
164#define LRH_SC_SELECT_OFFSET ((LRH_SC_QW << QW_SHIFT) | (60ull))
165
166/* QPN[m+n:1] QW 1, OFFSET 1 */
167#define QPN_SELECT_OFFSET ((1ull << QW_SHIFT) | (1ull))
168
169/* defines to build power on SC2VL table */
170#define SC2VL_VAL( \
171 num, \
172 sc0, sc0val, \
173 sc1, sc1val, \
174 sc2, sc2val, \
175 sc3, sc3val, \
176 sc4, sc4val, \
177 sc5, sc5val, \
178 sc6, sc6val, \
179 sc7, sc7val) \
180( \
181 ((u64)(sc0val) << SEND_SC2VLT##num##_SC##sc0##_SHIFT) | \
182 ((u64)(sc1val) << SEND_SC2VLT##num##_SC##sc1##_SHIFT) | \
183 ((u64)(sc2val) << SEND_SC2VLT##num##_SC##sc2##_SHIFT) | \
184 ((u64)(sc3val) << SEND_SC2VLT##num##_SC##sc3##_SHIFT) | \
185 ((u64)(sc4val) << SEND_SC2VLT##num##_SC##sc4##_SHIFT) | \
186 ((u64)(sc5val) << SEND_SC2VLT##num##_SC##sc5##_SHIFT) | \
187 ((u64)(sc6val) << SEND_SC2VLT##num##_SC##sc6##_SHIFT) | \
188 ((u64)(sc7val) << SEND_SC2VLT##num##_SC##sc7##_SHIFT) \
189)
190
191#define DC_SC_VL_VAL( \
192 range, \
193 e0, e0val, \
194 e1, e1val, \
195 e2, e2val, \
196 e3, e3val, \
197 e4, e4val, \
198 e5, e5val, \
199 e6, e6val, \
200 e7, e7val, \
201 e8, e8val, \
202 e9, e9val, \
203 e10, e10val, \
204 e11, e11val, \
205 e12, e12val, \
206 e13, e13val, \
207 e14, e14val, \
208 e15, e15val) \
209( \
210 ((u64)(e0val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e0##_SHIFT) | \
211 ((u64)(e1val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e1##_SHIFT) | \
212 ((u64)(e2val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e2##_SHIFT) | \
213 ((u64)(e3val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e3##_SHIFT) | \
214 ((u64)(e4val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e4##_SHIFT) | \
215 ((u64)(e5val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e5##_SHIFT) | \
216 ((u64)(e6val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e6##_SHIFT) | \
217 ((u64)(e7val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e7##_SHIFT) | \
218 ((u64)(e8val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e8##_SHIFT) | \
219 ((u64)(e9val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e9##_SHIFT) | \
220 ((u64)(e10val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e10##_SHIFT) | \
221 ((u64)(e11val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e11##_SHIFT) | \
222 ((u64)(e12val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e12##_SHIFT) | \
223 ((u64)(e13val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e13##_SHIFT) | \
224 ((u64)(e14val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e14##_SHIFT) | \
225 ((u64)(e15val) << DCC_CFG_SC_VL_TABLE_##range##_ENTRY##e15##_SHIFT) \
226)
227
228/* all CceStatus sub-block freeze bits */
229#define ALL_FROZE (CCE_STATUS_SDMA_FROZE_SMASK \
230 | CCE_STATUS_RXE_FROZE_SMASK \
231 | CCE_STATUS_TXE_FROZE_SMASK \
232 | CCE_STATUS_TXE_PIO_FROZE_SMASK)
233/* all CceStatus sub-block TXE pause bits */
234#define ALL_TXE_PAUSE (CCE_STATUS_TXE_PIO_PAUSED_SMASK \
235 | CCE_STATUS_TXE_PAUSED_SMASK \
236 | CCE_STATUS_SDMA_PAUSED_SMASK)
237/* all CceStatus sub-block RXE pause bits */
238#define ALL_RXE_PAUSE CCE_STATUS_RXE_PAUSED_SMASK
239
240/*
241 * CCE Error flags.
242 */
243static struct flag_table cce_err_status_flags[] = {
244/* 0*/ FLAG_ENTRY0("CceCsrParityErr",
245 CCE_ERR_STATUS_CCE_CSR_PARITY_ERR_SMASK),
246/* 1*/ FLAG_ENTRY0("CceCsrReadBadAddrErr",
247 CCE_ERR_STATUS_CCE_CSR_READ_BAD_ADDR_ERR_SMASK),
248/* 2*/ FLAG_ENTRY0("CceCsrWriteBadAddrErr",
249 CCE_ERR_STATUS_CCE_CSR_WRITE_BAD_ADDR_ERR_SMASK),
250/* 3*/ FLAG_ENTRY0("CceTrgtAsyncFifoParityErr",
251 CCE_ERR_STATUS_CCE_TRGT_ASYNC_FIFO_PARITY_ERR_SMASK),
252/* 4*/ FLAG_ENTRY0("CceTrgtAccessErr",
253 CCE_ERR_STATUS_CCE_TRGT_ACCESS_ERR_SMASK),
254/* 5*/ FLAG_ENTRY0("CceRspdDataParityErr",
255 CCE_ERR_STATUS_CCE_RSPD_DATA_PARITY_ERR_SMASK),
256/* 6*/ FLAG_ENTRY0("CceCli0AsyncFifoParityErr",
257 CCE_ERR_STATUS_CCE_CLI0_ASYNC_FIFO_PARITY_ERR_SMASK),
258/* 7*/ FLAG_ENTRY0("CceCsrCfgBusParityErr",
259 CCE_ERR_STATUS_CCE_CSR_CFG_BUS_PARITY_ERR_SMASK),
260/* 8*/ FLAG_ENTRY0("CceCli2AsyncFifoParityErr",
261 CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK),
262/* 9*/ FLAG_ENTRY0("CceCli1AsyncFifoPioCrdtParityErr",
263 CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_PIO_CRDT_PARITY_ERR_SMASK),
264/*10*/ FLAG_ENTRY0("CceCli1AsyncFifoPioCrdtParityErr",
265 CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_SDMA_HD_PARITY_ERR_SMASK),
266/*11*/ FLAG_ENTRY0("CceCli1AsyncFifoRxdmaParityError",
267 CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_RXDMA_PARITY_ERROR_SMASK),
268/*12*/ FLAG_ENTRY0("CceCli1AsyncFifoDbgParityError",
269 CCE_ERR_STATUS_CCE_CLI1_ASYNC_FIFO_DBG_PARITY_ERROR_SMASK),
270/*13*/ FLAG_ENTRY0("PcicRetryMemCorErr",
271 CCE_ERR_STATUS_PCIC_RETRY_MEM_COR_ERR_SMASK),
272/*14*/ FLAG_ENTRY0("PcicRetryMemCorErr",
273 CCE_ERR_STATUS_PCIC_RETRY_SOT_MEM_COR_ERR_SMASK),
274/*15*/ FLAG_ENTRY0("PcicPostHdQCorErr",
275 CCE_ERR_STATUS_PCIC_POST_HD_QCOR_ERR_SMASK),
276/*16*/ FLAG_ENTRY0("PcicPostHdQCorErr",
277 CCE_ERR_STATUS_PCIC_POST_DAT_QCOR_ERR_SMASK),
278/*17*/ FLAG_ENTRY0("PcicPostHdQCorErr",
279 CCE_ERR_STATUS_PCIC_CPL_HD_QCOR_ERR_SMASK),
280/*18*/ FLAG_ENTRY0("PcicCplDatQCorErr",
281 CCE_ERR_STATUS_PCIC_CPL_DAT_QCOR_ERR_SMASK),
282/*19*/ FLAG_ENTRY0("PcicNPostHQParityErr",
283 CCE_ERR_STATUS_PCIC_NPOST_HQ_PARITY_ERR_SMASK),
284/*20*/ FLAG_ENTRY0("PcicNPostDatQParityErr",
285 CCE_ERR_STATUS_PCIC_NPOST_DAT_QPARITY_ERR_SMASK),
286/*21*/ FLAG_ENTRY0("PcicRetryMemUncErr",
287 CCE_ERR_STATUS_PCIC_RETRY_MEM_UNC_ERR_SMASK),
288/*22*/ FLAG_ENTRY0("PcicRetrySotMemUncErr",
289 CCE_ERR_STATUS_PCIC_RETRY_SOT_MEM_UNC_ERR_SMASK),
290/*23*/ FLAG_ENTRY0("PcicPostHdQUncErr",
291 CCE_ERR_STATUS_PCIC_POST_HD_QUNC_ERR_SMASK),
292/*24*/ FLAG_ENTRY0("PcicPostDatQUncErr",
293 CCE_ERR_STATUS_PCIC_POST_DAT_QUNC_ERR_SMASK),
294/*25*/ FLAG_ENTRY0("PcicCplHdQUncErr",
295 CCE_ERR_STATUS_PCIC_CPL_HD_QUNC_ERR_SMASK),
296/*26*/ FLAG_ENTRY0("PcicCplDatQUncErr",
297 CCE_ERR_STATUS_PCIC_CPL_DAT_QUNC_ERR_SMASK),
298/*27*/ FLAG_ENTRY0("PcicTransmitFrontParityErr",
299 CCE_ERR_STATUS_PCIC_TRANSMIT_FRONT_PARITY_ERR_SMASK),
300/*28*/ FLAG_ENTRY0("PcicTransmitBackParityErr",
301 CCE_ERR_STATUS_PCIC_TRANSMIT_BACK_PARITY_ERR_SMASK),
302/*29*/ FLAG_ENTRY0("PcicReceiveParityErr",
303 CCE_ERR_STATUS_PCIC_RECEIVE_PARITY_ERR_SMASK),
304/*30*/ FLAG_ENTRY0("CceTrgtCplTimeoutErr",
305 CCE_ERR_STATUS_CCE_TRGT_CPL_TIMEOUT_ERR_SMASK),
306/*31*/ FLAG_ENTRY0("LATriggered",
307 CCE_ERR_STATUS_LA_TRIGGERED_SMASK),
308/*32*/ FLAG_ENTRY0("CceSegReadBadAddrErr",
309 CCE_ERR_STATUS_CCE_SEG_READ_BAD_ADDR_ERR_SMASK),
310/*33*/ FLAG_ENTRY0("CceSegWriteBadAddrErr",
311 CCE_ERR_STATUS_CCE_SEG_WRITE_BAD_ADDR_ERR_SMASK),
312/*34*/ FLAG_ENTRY0("CceRcplAsyncFifoParityErr",
313 CCE_ERR_STATUS_CCE_RCPL_ASYNC_FIFO_PARITY_ERR_SMASK),
314/*35*/ FLAG_ENTRY0("CceRxdmaConvFifoParityErr",
315 CCE_ERR_STATUS_CCE_RXDMA_CONV_FIFO_PARITY_ERR_SMASK),
316/*36*/ FLAG_ENTRY0("CceMsixTableCorErr",
317 CCE_ERR_STATUS_CCE_MSIX_TABLE_COR_ERR_SMASK),
318/*37*/ FLAG_ENTRY0("CceMsixTableUncErr",
319 CCE_ERR_STATUS_CCE_MSIX_TABLE_UNC_ERR_SMASK),
320/*38*/ FLAG_ENTRY0("CceIntMapCorErr",
321 CCE_ERR_STATUS_CCE_INT_MAP_COR_ERR_SMASK),
322/*39*/ FLAG_ENTRY0("CceIntMapUncErr",
323 CCE_ERR_STATUS_CCE_INT_MAP_UNC_ERR_SMASK),
324/*40*/ FLAG_ENTRY0("CceMsixCsrParityErr",
325 CCE_ERR_STATUS_CCE_MSIX_CSR_PARITY_ERR_SMASK),
326/*41-63 reserved*/
327};
328
329/*
330 * Misc Error flags
331 */
332#define MES(text) MISC_ERR_STATUS_MISC_##text##_ERR_SMASK
333static struct flag_table misc_err_status_flags[] = {
334/* 0*/ FLAG_ENTRY0("CSR_PARITY", MES(CSR_PARITY)),
335/* 1*/ FLAG_ENTRY0("CSR_READ_BAD_ADDR", MES(CSR_READ_BAD_ADDR)),
336/* 2*/ FLAG_ENTRY0("CSR_WRITE_BAD_ADDR", MES(CSR_WRITE_BAD_ADDR)),
337/* 3*/ FLAG_ENTRY0("SBUS_WRITE_FAILED", MES(SBUS_WRITE_FAILED)),
338/* 4*/ FLAG_ENTRY0("KEY_MISMATCH", MES(KEY_MISMATCH)),
339/* 5*/ FLAG_ENTRY0("FW_AUTH_FAILED", MES(FW_AUTH_FAILED)),
340/* 6*/ FLAG_ENTRY0("EFUSE_CSR_PARITY", MES(EFUSE_CSR_PARITY)),
341/* 7*/ FLAG_ENTRY0("EFUSE_READ_BAD_ADDR", MES(EFUSE_READ_BAD_ADDR)),
342/* 8*/ FLAG_ENTRY0("EFUSE_WRITE", MES(EFUSE_WRITE)),
343/* 9*/ FLAG_ENTRY0("EFUSE_DONE_PARITY", MES(EFUSE_DONE_PARITY)),
344/*10*/ FLAG_ENTRY0("INVALID_EEP_CMD", MES(INVALID_EEP_CMD)),
345/*11*/ FLAG_ENTRY0("MBIST_FAIL", MES(MBIST_FAIL)),
346/*12*/ FLAG_ENTRY0("PLL_LOCK_FAIL", MES(PLL_LOCK_FAIL))
347};
348
349/*
350 * TXE PIO Error flags and consequences
351 */
352static struct flag_table pio_err_status_flags[] = {
353/* 0*/ FLAG_ENTRY("PioWriteBadCtxt",
354 SEC_WRITE_DROPPED,
355 SEND_PIO_ERR_STATUS_PIO_WRITE_BAD_CTXT_ERR_SMASK),
356/* 1*/ FLAG_ENTRY("PioWriteAddrParity",
357 SEC_SPC_FREEZE,
358 SEND_PIO_ERR_STATUS_PIO_WRITE_ADDR_PARITY_ERR_SMASK),
359/* 2*/ FLAG_ENTRY("PioCsrParity",
360 SEC_SPC_FREEZE,
361 SEND_PIO_ERR_STATUS_PIO_CSR_PARITY_ERR_SMASK),
362/* 3*/ FLAG_ENTRY("PioSbMemFifo0",
363 SEC_SPC_FREEZE,
364 SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO0_ERR_SMASK),
365/* 4*/ FLAG_ENTRY("PioSbMemFifo1",
366 SEC_SPC_FREEZE,
367 SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO1_ERR_SMASK),
368/* 5*/ FLAG_ENTRY("PioPccFifoParity",
369 SEC_SPC_FREEZE,
370 SEND_PIO_ERR_STATUS_PIO_PCC_FIFO_PARITY_ERR_SMASK),
371/* 6*/ FLAG_ENTRY("PioPecFifoParity",
372 SEC_SPC_FREEZE,
373 SEND_PIO_ERR_STATUS_PIO_PEC_FIFO_PARITY_ERR_SMASK),
374/* 7*/ FLAG_ENTRY("PioSbrdctlCrrelParity",
375 SEC_SPC_FREEZE,
376 SEND_PIO_ERR_STATUS_PIO_SBRDCTL_CRREL_PARITY_ERR_SMASK),
377/* 8*/ FLAG_ENTRY("PioSbrdctrlCrrelFifoParity",
378 SEC_SPC_FREEZE,
379 SEND_PIO_ERR_STATUS_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR_SMASK),
380/* 9*/ FLAG_ENTRY("PioPktEvictFifoParityErr",
381 SEC_SPC_FREEZE,
382 SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_FIFO_PARITY_ERR_SMASK),
383/*10*/ FLAG_ENTRY("PioSmPktResetParity",
384 SEC_SPC_FREEZE,
385 SEND_PIO_ERR_STATUS_PIO_SM_PKT_RESET_PARITY_ERR_SMASK),
386/*11*/ FLAG_ENTRY("PioVlLenMemBank0Unc",
387 SEC_SPC_FREEZE,
388 SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_UNC_ERR_SMASK),
389/*12*/ FLAG_ENTRY("PioVlLenMemBank1Unc",
390 SEC_SPC_FREEZE,
391 SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_UNC_ERR_SMASK),
392/*13*/ FLAG_ENTRY("PioVlLenMemBank0Cor",
393 0,
394 SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_COR_ERR_SMASK),
395/*14*/ FLAG_ENTRY("PioVlLenMemBank1Cor",
396 0,
397 SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_COR_ERR_SMASK),
398/*15*/ FLAG_ENTRY("PioCreditRetFifoParity",
399 SEC_SPC_FREEZE,
400 SEND_PIO_ERR_STATUS_PIO_CREDIT_RET_FIFO_PARITY_ERR_SMASK),
401/*16*/ FLAG_ENTRY("PioPpmcPblFifo",
402 SEC_SPC_FREEZE,
403 SEND_PIO_ERR_STATUS_PIO_PPMC_PBL_FIFO_ERR_SMASK),
404/*17*/ FLAG_ENTRY("PioInitSmIn",
405 0,
406 SEND_PIO_ERR_STATUS_PIO_INIT_SM_IN_ERR_SMASK),
407/*18*/ FLAG_ENTRY("PioPktEvictSmOrArbSm",
408 SEC_SPC_FREEZE,
409 SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_SM_OR_ARB_SM_ERR_SMASK),
410/*19*/ FLAG_ENTRY("PioHostAddrMemUnc",
411 SEC_SPC_FREEZE,
412 SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_UNC_ERR_SMASK),
413/*20*/ FLAG_ENTRY("PioHostAddrMemCor",
414 0,
415 SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_COR_ERR_SMASK),
416/*21*/ FLAG_ENTRY("PioWriteDataParity",
417 SEC_SPC_FREEZE,
418 SEND_PIO_ERR_STATUS_PIO_WRITE_DATA_PARITY_ERR_SMASK),
419/*22*/ FLAG_ENTRY("PioStateMachine",
420 SEC_SPC_FREEZE,
421 SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK),
422/*23*/ FLAG_ENTRY("PioWriteQwValidParity",
423 SEC_WRITE_DROPPED|SEC_SPC_FREEZE,
424 SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK),
425/*24*/ FLAG_ENTRY("PioBlockQwCountParity",
426 SEC_WRITE_DROPPED|SEC_SPC_FREEZE,
427 SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK),
428/*25*/ FLAG_ENTRY("PioVlfVlLenParity",
429 SEC_SPC_FREEZE,
430 SEND_PIO_ERR_STATUS_PIO_VLF_VL_LEN_PARITY_ERR_SMASK),
431/*26*/ FLAG_ENTRY("PioVlfSopParity",
432 SEC_SPC_FREEZE,
433 SEND_PIO_ERR_STATUS_PIO_VLF_SOP_PARITY_ERR_SMASK),
434/*27*/ FLAG_ENTRY("PioVlFifoParity",
435 SEC_SPC_FREEZE,
436 SEND_PIO_ERR_STATUS_PIO_VL_FIFO_PARITY_ERR_SMASK),
437/*28*/ FLAG_ENTRY("PioPpmcBqcMemParity",
438 SEC_SPC_FREEZE,
439 SEND_PIO_ERR_STATUS_PIO_PPMC_BQC_MEM_PARITY_ERR_SMASK),
440/*29*/ FLAG_ENTRY("PioPpmcSopLen",
441 SEC_SPC_FREEZE,
442 SEND_PIO_ERR_STATUS_PIO_PPMC_SOP_LEN_ERR_SMASK),
443/*30-31 reserved*/
444/*32*/ FLAG_ENTRY("PioCurrentFreeCntParity",
445 SEC_SPC_FREEZE,
446 SEND_PIO_ERR_STATUS_PIO_CURRENT_FREE_CNT_PARITY_ERR_SMASK),
447/*33*/ FLAG_ENTRY("PioLastReturnedCntParity",
448 SEC_SPC_FREEZE,
449 SEND_PIO_ERR_STATUS_PIO_LAST_RETURNED_CNT_PARITY_ERR_SMASK),
450/*34*/ FLAG_ENTRY("PioPccSopHeadParity",
451 SEC_SPC_FREEZE,
452 SEND_PIO_ERR_STATUS_PIO_PCC_SOP_HEAD_PARITY_ERR_SMASK),
453/*35*/ FLAG_ENTRY("PioPecSopHeadParityErr",
454 SEC_SPC_FREEZE,
455 SEND_PIO_ERR_STATUS_PIO_PEC_SOP_HEAD_PARITY_ERR_SMASK),
456/*36-63 reserved*/
457};
458
459/* TXE PIO errors that cause an SPC freeze */
460#define ALL_PIO_FREEZE_ERR \
461 (SEND_PIO_ERR_STATUS_PIO_WRITE_ADDR_PARITY_ERR_SMASK \
462 | SEND_PIO_ERR_STATUS_PIO_CSR_PARITY_ERR_SMASK \
463 | SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO0_ERR_SMASK \
464 | SEND_PIO_ERR_STATUS_PIO_SB_MEM_FIFO1_ERR_SMASK \
465 | SEND_PIO_ERR_STATUS_PIO_PCC_FIFO_PARITY_ERR_SMASK \
466 | SEND_PIO_ERR_STATUS_PIO_PEC_FIFO_PARITY_ERR_SMASK \
467 | SEND_PIO_ERR_STATUS_PIO_SBRDCTL_CRREL_PARITY_ERR_SMASK \
468 | SEND_PIO_ERR_STATUS_PIO_SBRDCTRL_CRREL_FIFO_PARITY_ERR_SMASK \
469 | SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_FIFO_PARITY_ERR_SMASK \
470 | SEND_PIO_ERR_STATUS_PIO_SM_PKT_RESET_PARITY_ERR_SMASK \
471 | SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK0_UNC_ERR_SMASK \
472 | SEND_PIO_ERR_STATUS_PIO_VL_LEN_MEM_BANK1_UNC_ERR_SMASK \
473 | SEND_PIO_ERR_STATUS_PIO_CREDIT_RET_FIFO_PARITY_ERR_SMASK \
474 | SEND_PIO_ERR_STATUS_PIO_PPMC_PBL_FIFO_ERR_SMASK \
475 | SEND_PIO_ERR_STATUS_PIO_PKT_EVICT_SM_OR_ARB_SM_ERR_SMASK \
476 | SEND_PIO_ERR_STATUS_PIO_HOST_ADDR_MEM_UNC_ERR_SMASK \
477 | SEND_PIO_ERR_STATUS_PIO_WRITE_DATA_PARITY_ERR_SMASK \
478 | SEND_PIO_ERR_STATUS_PIO_STATE_MACHINE_ERR_SMASK \
479 | SEND_PIO_ERR_STATUS_PIO_WRITE_QW_VALID_PARITY_ERR_SMASK \
480 | SEND_PIO_ERR_STATUS_PIO_BLOCK_QW_COUNT_PARITY_ERR_SMASK \
481 | SEND_PIO_ERR_STATUS_PIO_VLF_VL_LEN_PARITY_ERR_SMASK \
482 | SEND_PIO_ERR_STATUS_PIO_VLF_SOP_PARITY_ERR_SMASK \
483 | SEND_PIO_ERR_STATUS_PIO_VL_FIFO_PARITY_ERR_SMASK \
484 | SEND_PIO_ERR_STATUS_PIO_PPMC_BQC_MEM_PARITY_ERR_SMASK \
485 | SEND_PIO_ERR_STATUS_PIO_PPMC_SOP_LEN_ERR_SMASK \
486 | SEND_PIO_ERR_STATUS_PIO_CURRENT_FREE_CNT_PARITY_ERR_SMASK \
487 | SEND_PIO_ERR_STATUS_PIO_LAST_RETURNED_CNT_PARITY_ERR_SMASK \
488 | SEND_PIO_ERR_STATUS_PIO_PCC_SOP_HEAD_PARITY_ERR_SMASK \
489 | SEND_PIO_ERR_STATUS_PIO_PEC_SOP_HEAD_PARITY_ERR_SMASK)
490
491/*
492 * TXE SDMA Error flags
493 */
494static struct flag_table sdma_err_status_flags[] = {
495/* 0*/ FLAG_ENTRY0("SDmaRpyTagErr",
496 SEND_DMA_ERR_STATUS_SDMA_RPY_TAG_ERR_SMASK),
497/* 1*/ FLAG_ENTRY0("SDmaCsrParityErr",
498 SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK),
499/* 2*/ FLAG_ENTRY0("SDmaPcieReqTrackingUncErr",
500 SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK),
501/* 3*/ FLAG_ENTRY0("SDmaPcieReqTrackingCorErr",
502 SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_COR_ERR_SMASK),
503/*04-63 reserved*/
504};
505
506/* TXE SDMA errors that cause an SPC freeze */
507#define ALL_SDMA_FREEZE_ERR \
508 (SEND_DMA_ERR_STATUS_SDMA_RPY_TAG_ERR_SMASK \
509 | SEND_DMA_ERR_STATUS_SDMA_CSR_PARITY_ERR_SMASK \
510 | SEND_DMA_ERR_STATUS_SDMA_PCIE_REQ_TRACKING_UNC_ERR_SMASK)
511
512/*
513 * TXE Egress Error flags
514 */
515#define SEES(text) SEND_EGRESS_ERR_STATUS_##text##_ERR_SMASK
516static struct flag_table egress_err_status_flags[] = {
517/* 0*/ FLAG_ENTRY0("TxPktIntegrityMemCorErr", SEES(TX_PKT_INTEGRITY_MEM_COR)),
518/* 1*/ FLAG_ENTRY0("TxPktIntegrityMemUncErr", SEES(TX_PKT_INTEGRITY_MEM_UNC)),
519/* 2 reserved */
520/* 3*/ FLAG_ENTRY0("TxEgressFifoUnderrunOrParityErr",
521 SEES(TX_EGRESS_FIFO_UNDERRUN_OR_PARITY)),
522/* 4*/ FLAG_ENTRY0("TxLinkdownErr", SEES(TX_LINKDOWN)),
523/* 5*/ FLAG_ENTRY0("TxIncorrectLinkStateErr", SEES(TX_INCORRECT_LINK_STATE)),
524/* 6 reserved */
525/* 7*/ FLAG_ENTRY0("TxPioLaunchIntfParityErr",
526 SEES(TX_PIO_LAUNCH_INTF_PARITY)),
527/* 8*/ FLAG_ENTRY0("TxSdmaLaunchIntfParityErr",
528 SEES(TX_SDMA_LAUNCH_INTF_PARITY)),
529/* 9-10 reserved */
530/*11*/ FLAG_ENTRY0("TxSbrdCtlStateMachineParityErr",
531 SEES(TX_SBRD_CTL_STATE_MACHINE_PARITY)),
532/*12*/ FLAG_ENTRY0("TxIllegalVLErr", SEES(TX_ILLEGAL_VL)),
533/*13*/ FLAG_ENTRY0("TxLaunchCsrParityErr", SEES(TX_LAUNCH_CSR_PARITY)),
534/*14*/ FLAG_ENTRY0("TxSbrdCtlCsrParityErr", SEES(TX_SBRD_CTL_CSR_PARITY)),
535/*15*/ FLAG_ENTRY0("TxConfigParityErr", SEES(TX_CONFIG_PARITY)),
536/*16*/ FLAG_ENTRY0("TxSdma0DisallowedPacketErr",
537 SEES(TX_SDMA0_DISALLOWED_PACKET)),
538/*17*/ FLAG_ENTRY0("TxSdma1DisallowedPacketErr",
539 SEES(TX_SDMA1_DISALLOWED_PACKET)),
540/*18*/ FLAG_ENTRY0("TxSdma2DisallowedPacketErr",
541 SEES(TX_SDMA2_DISALLOWED_PACKET)),
542/*19*/ FLAG_ENTRY0("TxSdma3DisallowedPacketErr",
543 SEES(TX_SDMA3_DISALLOWED_PACKET)),
544/*20*/ FLAG_ENTRY0("TxSdma4DisallowedPacketErr",
545 SEES(TX_SDMA4_DISALLOWED_PACKET)),
546/*21*/ FLAG_ENTRY0("TxSdma5DisallowedPacketErr",
547 SEES(TX_SDMA5_DISALLOWED_PACKET)),
548/*22*/ FLAG_ENTRY0("TxSdma6DisallowedPacketErr",
549 SEES(TX_SDMA6_DISALLOWED_PACKET)),
550/*23*/ FLAG_ENTRY0("TxSdma7DisallowedPacketErr",
551 SEES(TX_SDMA7_DISALLOWED_PACKET)),
552/*24*/ FLAG_ENTRY0("TxSdma8DisallowedPacketErr",
553 SEES(TX_SDMA8_DISALLOWED_PACKET)),
554/*25*/ FLAG_ENTRY0("TxSdma9DisallowedPacketErr",
555 SEES(TX_SDMA9_DISALLOWED_PACKET)),
556/*26*/ FLAG_ENTRY0("TxSdma10DisallowedPacketErr",
557 SEES(TX_SDMA10_DISALLOWED_PACKET)),
558/*27*/ FLAG_ENTRY0("TxSdma11DisallowedPacketErr",
559 SEES(TX_SDMA11_DISALLOWED_PACKET)),
560/*28*/ FLAG_ENTRY0("TxSdma12DisallowedPacketErr",
561 SEES(TX_SDMA12_DISALLOWED_PACKET)),
562/*29*/ FLAG_ENTRY0("TxSdma13DisallowedPacketErr",
563 SEES(TX_SDMA13_DISALLOWED_PACKET)),
564/*30*/ FLAG_ENTRY0("TxSdma14DisallowedPacketErr",
565 SEES(TX_SDMA14_DISALLOWED_PACKET)),
566/*31*/ FLAG_ENTRY0("TxSdma15DisallowedPacketErr",
567 SEES(TX_SDMA15_DISALLOWED_PACKET)),
568/*32*/ FLAG_ENTRY0("TxLaunchFifo0UncOrParityErr",
569 SEES(TX_LAUNCH_FIFO0_UNC_OR_PARITY)),
570/*33*/ FLAG_ENTRY0("TxLaunchFifo1UncOrParityErr",
571 SEES(TX_LAUNCH_FIFO1_UNC_OR_PARITY)),
572/*34*/ FLAG_ENTRY0("TxLaunchFifo2UncOrParityErr",
573 SEES(TX_LAUNCH_FIFO2_UNC_OR_PARITY)),
574/*35*/ FLAG_ENTRY0("TxLaunchFifo3UncOrParityErr",
575 SEES(TX_LAUNCH_FIFO3_UNC_OR_PARITY)),
576/*36*/ FLAG_ENTRY0("TxLaunchFifo4UncOrParityErr",
577 SEES(TX_LAUNCH_FIFO4_UNC_OR_PARITY)),
578/*37*/ FLAG_ENTRY0("TxLaunchFifo5UncOrParityErr",
579 SEES(TX_LAUNCH_FIFO5_UNC_OR_PARITY)),
580/*38*/ FLAG_ENTRY0("TxLaunchFifo6UncOrParityErr",
581 SEES(TX_LAUNCH_FIFO6_UNC_OR_PARITY)),
582/*39*/ FLAG_ENTRY0("TxLaunchFifo7UncOrParityErr",
583 SEES(TX_LAUNCH_FIFO7_UNC_OR_PARITY)),
584/*40*/ FLAG_ENTRY0("TxLaunchFifo8UncOrParityErr",
585 SEES(TX_LAUNCH_FIFO8_UNC_OR_PARITY)),
586/*41*/ FLAG_ENTRY0("TxCreditReturnParityErr", SEES(TX_CREDIT_RETURN_PARITY)),
587/*42*/ FLAG_ENTRY0("TxSbHdrUncErr", SEES(TX_SB_HDR_UNC)),
588/*43*/ FLAG_ENTRY0("TxReadSdmaMemoryUncErr", SEES(TX_READ_SDMA_MEMORY_UNC)),
589/*44*/ FLAG_ENTRY0("TxReadPioMemoryUncErr", SEES(TX_READ_PIO_MEMORY_UNC)),
590/*45*/ FLAG_ENTRY0("TxEgressFifoUncErr", SEES(TX_EGRESS_FIFO_UNC)),
591/*46*/ FLAG_ENTRY0("TxHcrcInsertionErr", SEES(TX_HCRC_INSERTION)),
592/*47*/ FLAG_ENTRY0("TxCreditReturnVLErr", SEES(TX_CREDIT_RETURN_VL)),
593/*48*/ FLAG_ENTRY0("TxLaunchFifo0CorErr", SEES(TX_LAUNCH_FIFO0_COR)),
594/*49*/ FLAG_ENTRY0("TxLaunchFifo1CorErr", SEES(TX_LAUNCH_FIFO1_COR)),
595/*50*/ FLAG_ENTRY0("TxLaunchFifo2CorErr", SEES(TX_LAUNCH_FIFO2_COR)),
596/*51*/ FLAG_ENTRY0("TxLaunchFifo3CorErr", SEES(TX_LAUNCH_FIFO3_COR)),
597/*52*/ FLAG_ENTRY0("TxLaunchFifo4CorErr", SEES(TX_LAUNCH_FIFO4_COR)),
598/*53*/ FLAG_ENTRY0("TxLaunchFifo5CorErr", SEES(TX_LAUNCH_FIFO5_COR)),
599/*54*/ FLAG_ENTRY0("TxLaunchFifo6CorErr", SEES(TX_LAUNCH_FIFO6_COR)),
600/*55*/ FLAG_ENTRY0("TxLaunchFifo7CorErr", SEES(TX_LAUNCH_FIFO7_COR)),
601/*56*/ FLAG_ENTRY0("TxLaunchFifo8CorErr", SEES(TX_LAUNCH_FIFO8_COR)),
602/*57*/ FLAG_ENTRY0("TxCreditOverrunErr", SEES(TX_CREDIT_OVERRUN)),
603/*58*/ FLAG_ENTRY0("TxSbHdrCorErr", SEES(TX_SB_HDR_COR)),
604/*59*/ FLAG_ENTRY0("TxReadSdmaMemoryCorErr", SEES(TX_READ_SDMA_MEMORY_COR)),
605/*60*/ FLAG_ENTRY0("TxReadPioMemoryCorErr", SEES(TX_READ_PIO_MEMORY_COR)),
606/*61*/ FLAG_ENTRY0("TxEgressFifoCorErr", SEES(TX_EGRESS_FIFO_COR)),
607/*62*/ FLAG_ENTRY0("TxReadSdmaMemoryCsrUncErr",
608 SEES(TX_READ_SDMA_MEMORY_CSR_UNC)),
609/*63*/ FLAG_ENTRY0("TxReadPioMemoryCsrUncErr",
610 SEES(TX_READ_PIO_MEMORY_CSR_UNC)),
611};
612
613/*
614 * TXE Egress Error Info flags
615 */
616#define SEEI(text) SEND_EGRESS_ERR_INFO_##text##_ERR_SMASK
617static struct flag_table egress_err_info_flags[] = {
618/* 0*/ FLAG_ENTRY0("Reserved", 0ull),
619/* 1*/ FLAG_ENTRY0("VLErr", SEEI(VL)),
620/* 2*/ FLAG_ENTRY0("JobKeyErr", SEEI(JOB_KEY)),
621/* 3*/ FLAG_ENTRY0("JobKeyErr", SEEI(JOB_KEY)),
622/* 4*/ FLAG_ENTRY0("PartitionKeyErr", SEEI(PARTITION_KEY)),
623/* 5*/ FLAG_ENTRY0("SLIDErr", SEEI(SLID)),
624/* 6*/ FLAG_ENTRY0("OpcodeErr", SEEI(OPCODE)),
625/* 7*/ FLAG_ENTRY0("VLMappingErr", SEEI(VL_MAPPING)),
626/* 8*/ FLAG_ENTRY0("RawErr", SEEI(RAW)),
627/* 9*/ FLAG_ENTRY0("RawIPv6Err", SEEI(RAW_IPV6)),
628/*10*/ FLAG_ENTRY0("GRHErr", SEEI(GRH)),
629/*11*/ FLAG_ENTRY0("BypassErr", SEEI(BYPASS)),
630/*12*/ FLAG_ENTRY0("KDETHPacketsErr", SEEI(KDETH_PACKETS)),
631/*13*/ FLAG_ENTRY0("NonKDETHPacketsErr", SEEI(NON_KDETH_PACKETS)),
632/*14*/ FLAG_ENTRY0("TooSmallIBPacketsErr", SEEI(TOO_SMALL_IB_PACKETS)),
633/*15*/ FLAG_ENTRY0("TooSmallBypassPacketsErr", SEEI(TOO_SMALL_BYPASS_PACKETS)),
634/*16*/ FLAG_ENTRY0("PbcTestErr", SEEI(PBC_TEST)),
635/*17*/ FLAG_ENTRY0("BadPktLenErr", SEEI(BAD_PKT_LEN)),
636/*18*/ FLAG_ENTRY0("TooLongIBPacketErr", SEEI(TOO_LONG_IB_PACKET)),
637/*19*/ FLAG_ENTRY0("TooLongBypassPacketsErr", SEEI(TOO_LONG_BYPASS_PACKETS)),
638/*20*/ FLAG_ENTRY0("PbcStaticRateControlErr", SEEI(PBC_STATIC_RATE_CONTROL)),
639/*21*/ FLAG_ENTRY0("BypassBadPktLenErr", SEEI(BAD_PKT_LEN)),
640};
641
642/* TXE Egress errors that cause an SPC freeze */
643#define ALL_TXE_EGRESS_FREEZE_ERR \
644 (SEES(TX_EGRESS_FIFO_UNDERRUN_OR_PARITY) \
645 | SEES(TX_PIO_LAUNCH_INTF_PARITY) \
646 | SEES(TX_SDMA_LAUNCH_INTF_PARITY) \
647 | SEES(TX_SBRD_CTL_STATE_MACHINE_PARITY) \
648 | SEES(TX_LAUNCH_CSR_PARITY) \
649 | SEES(TX_SBRD_CTL_CSR_PARITY) \
650 | SEES(TX_CONFIG_PARITY) \
651 | SEES(TX_LAUNCH_FIFO0_UNC_OR_PARITY) \
652 | SEES(TX_LAUNCH_FIFO1_UNC_OR_PARITY) \
653 | SEES(TX_LAUNCH_FIFO2_UNC_OR_PARITY) \
654 | SEES(TX_LAUNCH_FIFO3_UNC_OR_PARITY) \
655 | SEES(TX_LAUNCH_FIFO4_UNC_OR_PARITY) \
656 | SEES(TX_LAUNCH_FIFO5_UNC_OR_PARITY) \
657 | SEES(TX_LAUNCH_FIFO6_UNC_OR_PARITY) \
658 | SEES(TX_LAUNCH_FIFO7_UNC_OR_PARITY) \
659 | SEES(TX_LAUNCH_FIFO8_UNC_OR_PARITY) \
660 | SEES(TX_CREDIT_RETURN_PARITY))
661
662/*
663 * TXE Send error flags
664 */
665#define SES(name) SEND_ERR_STATUS_SEND_##name##_ERR_SMASK
666static struct flag_table send_err_status_flags[] = {
667/* 0*/ FLAG_ENTRY0("SDmaRpyTagErr", SES(CSR_PARITY)),
668/* 1*/ FLAG_ENTRY0("SendCsrReadBadAddrErr", SES(CSR_READ_BAD_ADDR)),
669/* 2*/ FLAG_ENTRY0("SendCsrWriteBadAddrErr", SES(CSR_WRITE_BAD_ADDR))
670};
671
672/*
673 * TXE Send Context Error flags and consequences
674 */
675static struct flag_table sc_err_status_flags[] = {
676/* 0*/ FLAG_ENTRY("InconsistentSop",
677 SEC_PACKET_DROPPED | SEC_SC_HALTED,
678 SEND_CTXT_ERR_STATUS_PIO_INCONSISTENT_SOP_ERR_SMASK),
679/* 1*/ FLAG_ENTRY("DisallowedPacket",
680 SEC_PACKET_DROPPED | SEC_SC_HALTED,
681 SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK),
682/* 2*/ FLAG_ENTRY("WriteCrossesBoundary",
683 SEC_WRITE_DROPPED | SEC_SC_HALTED,
684 SEND_CTXT_ERR_STATUS_PIO_WRITE_CROSSES_BOUNDARY_ERR_SMASK),
685/* 3*/ FLAG_ENTRY("WriteOverflow",
686 SEC_WRITE_DROPPED | SEC_SC_HALTED,
687 SEND_CTXT_ERR_STATUS_PIO_WRITE_OVERFLOW_ERR_SMASK),
688/* 4*/ FLAG_ENTRY("WriteOutOfBounds",
689 SEC_WRITE_DROPPED | SEC_SC_HALTED,
690 SEND_CTXT_ERR_STATUS_PIO_WRITE_OUT_OF_BOUNDS_ERR_SMASK),
691/* 5-63 reserved*/
692};
693
694/*
695 * RXE Receive Error flags
696 */
697#define RXES(name) RCV_ERR_STATUS_RX_##name##_ERR_SMASK
698static struct flag_table rxe_err_status_flags[] = {
699/* 0*/ FLAG_ENTRY0("RxDmaCsrCorErr", RXES(DMA_CSR_COR)),
700/* 1*/ FLAG_ENTRY0("RxDcIntfParityErr", RXES(DC_INTF_PARITY)),
701/* 2*/ FLAG_ENTRY0("RxRcvHdrUncErr", RXES(RCV_HDR_UNC)),
702/* 3*/ FLAG_ENTRY0("RxRcvHdrCorErr", RXES(RCV_HDR_COR)),
703/* 4*/ FLAG_ENTRY0("RxRcvDataUncErr", RXES(RCV_DATA_UNC)),
704/* 5*/ FLAG_ENTRY0("RxRcvDataCorErr", RXES(RCV_DATA_COR)),
705/* 6*/ FLAG_ENTRY0("RxRcvQpMapTableUncErr", RXES(RCV_QP_MAP_TABLE_UNC)),
706/* 7*/ FLAG_ENTRY0("RxRcvQpMapTableCorErr", RXES(RCV_QP_MAP_TABLE_COR)),
707/* 8*/ FLAG_ENTRY0("RxRcvCsrParityErr", RXES(RCV_CSR_PARITY)),
708/* 9*/ FLAG_ENTRY0("RxDcSopEopParityErr", RXES(DC_SOP_EOP_PARITY)),
709/*10*/ FLAG_ENTRY0("RxDmaFlagUncErr", RXES(DMA_FLAG_UNC)),
710/*11*/ FLAG_ENTRY0("RxDmaFlagCorErr", RXES(DMA_FLAG_COR)),
711/*12*/ FLAG_ENTRY0("RxRcvFsmEncodingErr", RXES(RCV_FSM_ENCODING)),
712/*13*/ FLAG_ENTRY0("RxRbufFreeListUncErr", RXES(RBUF_FREE_LIST_UNC)),
713/*14*/ FLAG_ENTRY0("RxRbufFreeListCorErr", RXES(RBUF_FREE_LIST_COR)),
714/*15*/ FLAG_ENTRY0("RxRbufLookupDesRegUncErr", RXES(RBUF_LOOKUP_DES_REG_UNC)),
715/*16*/ FLAG_ENTRY0("RxRbufLookupDesRegUncCorErr",
716 RXES(RBUF_LOOKUP_DES_REG_UNC_COR)),
717/*17*/ FLAG_ENTRY0("RxRbufLookupDesUncErr", RXES(RBUF_LOOKUP_DES_UNC)),
718/*18*/ FLAG_ENTRY0("RxRbufLookupDesCorErr", RXES(RBUF_LOOKUP_DES_COR)),
719/*19*/ FLAG_ENTRY0("RxRbufBlockListReadUncErr",
720 RXES(RBUF_BLOCK_LIST_READ_UNC)),
721/*20*/ FLAG_ENTRY0("RxRbufBlockListReadCorErr",
722 RXES(RBUF_BLOCK_LIST_READ_COR)),
723/*21*/ FLAG_ENTRY0("RxRbufCsrQHeadBufNumParityErr",
724 RXES(RBUF_CSR_QHEAD_BUF_NUM_PARITY)),
725/*22*/ FLAG_ENTRY0("RxRbufCsrQEntCntParityErr",
726 RXES(RBUF_CSR_QENT_CNT_PARITY)),
727/*23*/ FLAG_ENTRY0("RxRbufCsrQNextBufParityErr",
728 RXES(RBUF_CSR_QNEXT_BUF_PARITY)),
729/*24*/ FLAG_ENTRY0("RxRbufCsrQVldBitParityErr",
730 RXES(RBUF_CSR_QVLD_BIT_PARITY)),
731/*25*/ FLAG_ENTRY0("RxRbufCsrQHdPtrParityErr", RXES(RBUF_CSR_QHD_PTR_PARITY)),
732/*26*/ FLAG_ENTRY0("RxRbufCsrQTlPtrParityErr", RXES(RBUF_CSR_QTL_PTR_PARITY)),
733/*27*/ FLAG_ENTRY0("RxRbufCsrQNumOfPktParityErr",
734 RXES(RBUF_CSR_QNUM_OF_PKT_PARITY)),
735/*28*/ FLAG_ENTRY0("RxRbufCsrQEOPDWParityErr", RXES(RBUF_CSR_QEOPDW_PARITY)),
736/*29*/ FLAG_ENTRY0("RxRbufCtxIdParityErr", RXES(RBUF_CTX_ID_PARITY)),
737/*30*/ FLAG_ENTRY0("RxRBufBadLookupErr", RXES(RBUF_BAD_LOOKUP)),
738/*31*/ FLAG_ENTRY0("RxRbufFullErr", RXES(RBUF_FULL)),
739/*32*/ FLAG_ENTRY0("RxRbufEmptyErr", RXES(RBUF_EMPTY)),
740/*33*/ FLAG_ENTRY0("RxRbufFlRdAddrParityErr", RXES(RBUF_FL_RD_ADDR_PARITY)),
741/*34*/ FLAG_ENTRY0("RxRbufFlWrAddrParityErr", RXES(RBUF_FL_WR_ADDR_PARITY)),
742/*35*/ FLAG_ENTRY0("RxRbufFlInitdoneParityErr",
743 RXES(RBUF_FL_INITDONE_PARITY)),
744/*36*/ FLAG_ENTRY0("RxRbufFlInitWrAddrParityErr",
745 RXES(RBUF_FL_INIT_WR_ADDR_PARITY)),
746/*37*/ FLAG_ENTRY0("RxRbufNextFreeBufUncErr", RXES(RBUF_NEXT_FREE_BUF_UNC)),
747/*38*/ FLAG_ENTRY0("RxRbufNextFreeBufCorErr", RXES(RBUF_NEXT_FREE_BUF_COR)),
748/*39*/ FLAG_ENTRY0("RxLookupDesPart1UncErr", RXES(LOOKUP_DES_PART1_UNC)),
749/*40*/ FLAG_ENTRY0("RxLookupDesPart1UncCorErr",
750 RXES(LOOKUP_DES_PART1_UNC_COR)),
751/*41*/ FLAG_ENTRY0("RxLookupDesPart2ParityErr",
752 RXES(LOOKUP_DES_PART2_PARITY)),
753/*42*/ FLAG_ENTRY0("RxLookupRcvArrayUncErr", RXES(LOOKUP_RCV_ARRAY_UNC)),
754/*43*/ FLAG_ENTRY0("RxLookupRcvArrayCorErr", RXES(LOOKUP_RCV_ARRAY_COR)),
755/*44*/ FLAG_ENTRY0("RxLookupCsrParityErr", RXES(LOOKUP_CSR_PARITY)),
756/*45*/ FLAG_ENTRY0("RxHqIntrCsrParityErr", RXES(HQ_INTR_CSR_PARITY)),
757/*46*/ FLAG_ENTRY0("RxHqIntrFsmErr", RXES(HQ_INTR_FSM)),
758/*47*/ FLAG_ENTRY0("RxRbufDescPart1UncErr", RXES(RBUF_DESC_PART1_UNC)),
759/*48*/ FLAG_ENTRY0("RxRbufDescPart1CorErr", RXES(RBUF_DESC_PART1_COR)),
760/*49*/ FLAG_ENTRY0("RxRbufDescPart2UncErr", RXES(RBUF_DESC_PART2_UNC)),
761/*50*/ FLAG_ENTRY0("RxRbufDescPart2CorErr", RXES(RBUF_DESC_PART2_COR)),
762/*51*/ FLAG_ENTRY0("RxDmaHdrFifoRdUncErr", RXES(DMA_HDR_FIFO_RD_UNC)),
763/*52*/ FLAG_ENTRY0("RxDmaHdrFifoRdCorErr", RXES(DMA_HDR_FIFO_RD_COR)),
764/*53*/ FLAG_ENTRY0("RxDmaDataFifoRdUncErr", RXES(DMA_DATA_FIFO_RD_UNC)),
765/*54*/ FLAG_ENTRY0("RxDmaDataFifoRdCorErr", RXES(DMA_DATA_FIFO_RD_COR)),
766/*55*/ FLAG_ENTRY0("RxRbufDataUncErr", RXES(RBUF_DATA_UNC)),
767/*56*/ FLAG_ENTRY0("RxRbufDataCorErr", RXES(RBUF_DATA_COR)),
768/*57*/ FLAG_ENTRY0("RxDmaCsrParityErr", RXES(DMA_CSR_PARITY)),
769/*58*/ FLAG_ENTRY0("RxDmaEqFsmEncodingErr", RXES(DMA_EQ_FSM_ENCODING)),
770/*59*/ FLAG_ENTRY0("RxDmaDqFsmEncodingErr", RXES(DMA_DQ_FSM_ENCODING)),
771/*60*/ FLAG_ENTRY0("RxDmaCsrUncErr", RXES(DMA_CSR_UNC)),
772/*61*/ FLAG_ENTRY0("RxCsrReadBadAddrErr", RXES(CSR_READ_BAD_ADDR)),
773/*62*/ FLAG_ENTRY0("RxCsrWriteBadAddrErr", RXES(CSR_WRITE_BAD_ADDR)),
774/*63*/ FLAG_ENTRY0("RxCsrParityErr", RXES(CSR_PARITY))
775};
776
777/* RXE errors that will trigger an SPC freeze */
778#define ALL_RXE_FREEZE_ERR \
779 (RCV_ERR_STATUS_RX_RCV_QP_MAP_TABLE_UNC_ERR_SMASK \
780 | RCV_ERR_STATUS_RX_RCV_CSR_PARITY_ERR_SMASK \
781 | RCV_ERR_STATUS_RX_DMA_FLAG_UNC_ERR_SMASK \
782 | RCV_ERR_STATUS_RX_RCV_FSM_ENCODING_ERR_SMASK \
783 | RCV_ERR_STATUS_RX_RBUF_FREE_LIST_UNC_ERR_SMASK \
784 | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_REG_UNC_ERR_SMASK \
785 | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_REG_UNC_COR_ERR_SMASK \
786 | RCV_ERR_STATUS_RX_RBUF_LOOKUP_DES_UNC_ERR_SMASK \
787 | RCV_ERR_STATUS_RX_RBUF_BLOCK_LIST_READ_UNC_ERR_SMASK \
788 | RCV_ERR_STATUS_RX_RBUF_CSR_QHEAD_BUF_NUM_PARITY_ERR_SMASK \
789 | RCV_ERR_STATUS_RX_RBUF_CSR_QENT_CNT_PARITY_ERR_SMASK \
790 | RCV_ERR_STATUS_RX_RBUF_CSR_QNEXT_BUF_PARITY_ERR_SMASK \
791 | RCV_ERR_STATUS_RX_RBUF_CSR_QVLD_BIT_PARITY_ERR_SMASK \
792 | RCV_ERR_STATUS_RX_RBUF_CSR_QHD_PTR_PARITY_ERR_SMASK \
793 | RCV_ERR_STATUS_RX_RBUF_CSR_QTL_PTR_PARITY_ERR_SMASK \
794 | RCV_ERR_STATUS_RX_RBUF_CSR_QNUM_OF_PKT_PARITY_ERR_SMASK \
795 | RCV_ERR_STATUS_RX_RBUF_CSR_QEOPDW_PARITY_ERR_SMASK \
796 | RCV_ERR_STATUS_RX_RBUF_CTX_ID_PARITY_ERR_SMASK \
797 | RCV_ERR_STATUS_RX_RBUF_BAD_LOOKUP_ERR_SMASK \
798 | RCV_ERR_STATUS_RX_RBUF_FULL_ERR_SMASK \
799 | RCV_ERR_STATUS_RX_RBUF_EMPTY_ERR_SMASK \
800 | RCV_ERR_STATUS_RX_RBUF_FL_RD_ADDR_PARITY_ERR_SMASK \
801 | RCV_ERR_STATUS_RX_RBUF_FL_WR_ADDR_PARITY_ERR_SMASK \
802 | RCV_ERR_STATUS_RX_RBUF_FL_INITDONE_PARITY_ERR_SMASK \
803 | RCV_ERR_STATUS_RX_RBUF_FL_INIT_WR_ADDR_PARITY_ERR_SMASK \
804 | RCV_ERR_STATUS_RX_RBUF_NEXT_FREE_BUF_UNC_ERR_SMASK \
805 | RCV_ERR_STATUS_RX_LOOKUP_DES_PART1_UNC_ERR_SMASK \
806 | RCV_ERR_STATUS_RX_LOOKUP_DES_PART1_UNC_COR_ERR_SMASK \
807 | RCV_ERR_STATUS_RX_LOOKUP_DES_PART2_PARITY_ERR_SMASK \
808 | RCV_ERR_STATUS_RX_LOOKUP_RCV_ARRAY_UNC_ERR_SMASK \
809 | RCV_ERR_STATUS_RX_LOOKUP_CSR_PARITY_ERR_SMASK \
810 | RCV_ERR_STATUS_RX_HQ_INTR_CSR_PARITY_ERR_SMASK \
811 | RCV_ERR_STATUS_RX_HQ_INTR_FSM_ERR_SMASK \
812 | RCV_ERR_STATUS_RX_RBUF_DESC_PART1_UNC_ERR_SMASK \
813 | RCV_ERR_STATUS_RX_RBUF_DESC_PART1_COR_ERR_SMASK \
814 | RCV_ERR_STATUS_RX_RBUF_DESC_PART2_UNC_ERR_SMASK \
815 | RCV_ERR_STATUS_RX_DMA_HDR_FIFO_RD_UNC_ERR_SMASK \
816 | RCV_ERR_STATUS_RX_DMA_DATA_FIFO_RD_UNC_ERR_SMASK \
817 | RCV_ERR_STATUS_RX_RBUF_DATA_UNC_ERR_SMASK \
818 | RCV_ERR_STATUS_RX_DMA_CSR_PARITY_ERR_SMASK \
819 | RCV_ERR_STATUS_RX_DMA_EQ_FSM_ENCODING_ERR_SMASK \
820 | RCV_ERR_STATUS_RX_DMA_DQ_FSM_ENCODING_ERR_SMASK \
821 | RCV_ERR_STATUS_RX_DMA_CSR_UNC_ERR_SMASK \
822 | RCV_ERR_STATUS_RX_CSR_PARITY_ERR_SMASK)
823
824#define RXE_FREEZE_ABORT_MASK \
825 (RCV_ERR_STATUS_RX_DMA_CSR_UNC_ERR_SMASK | \
826 RCV_ERR_STATUS_RX_DMA_HDR_FIFO_RD_UNC_ERR_SMASK | \
827 RCV_ERR_STATUS_RX_DMA_DATA_FIFO_RD_UNC_ERR_SMASK)
828
829/*
830 * DCC Error Flags
831 */
832#define DCCE(name) DCC_ERR_FLG_##name##_SMASK
833static struct flag_table dcc_err_flags[] = {
834 FLAG_ENTRY0("bad_l2_err", DCCE(BAD_L2_ERR)),
835 FLAG_ENTRY0("bad_sc_err", DCCE(BAD_SC_ERR)),
836 FLAG_ENTRY0("bad_mid_tail_err", DCCE(BAD_MID_TAIL_ERR)),
837 FLAG_ENTRY0("bad_preemption_err", DCCE(BAD_PREEMPTION_ERR)),
838 FLAG_ENTRY0("preemption_err", DCCE(PREEMPTION_ERR)),
839 FLAG_ENTRY0("preemptionvl15_err", DCCE(PREEMPTIONVL15_ERR)),
840 FLAG_ENTRY0("bad_vl_marker_err", DCCE(BAD_VL_MARKER_ERR)),
841 FLAG_ENTRY0("bad_dlid_target_err", DCCE(BAD_DLID_TARGET_ERR)),
842 FLAG_ENTRY0("bad_lver_err", DCCE(BAD_LVER_ERR)),
843 FLAG_ENTRY0("uncorrectable_err", DCCE(UNCORRECTABLE_ERR)),
844 FLAG_ENTRY0("bad_crdt_ack_err", DCCE(BAD_CRDT_ACK_ERR)),
845 FLAG_ENTRY0("unsup_pkt_type", DCCE(UNSUP_PKT_TYPE)),
846 FLAG_ENTRY0("bad_ctrl_flit_err", DCCE(BAD_CTRL_FLIT_ERR)),
847 FLAG_ENTRY0("event_cntr_parity_err", DCCE(EVENT_CNTR_PARITY_ERR)),
848 FLAG_ENTRY0("event_cntr_rollover_err", DCCE(EVENT_CNTR_ROLLOVER_ERR)),
849 FLAG_ENTRY0("link_err", DCCE(LINK_ERR)),
850 FLAG_ENTRY0("misc_cntr_rollover_err", DCCE(MISC_CNTR_ROLLOVER_ERR)),
851 FLAG_ENTRY0("bad_ctrl_dist_err", DCCE(BAD_CTRL_DIST_ERR)),
852 FLAG_ENTRY0("bad_tail_dist_err", DCCE(BAD_TAIL_DIST_ERR)),
853 FLAG_ENTRY0("bad_head_dist_err", DCCE(BAD_HEAD_DIST_ERR)),
854 FLAG_ENTRY0("nonvl15_state_err", DCCE(NONVL15_STATE_ERR)),
855 FLAG_ENTRY0("vl15_multi_err", DCCE(VL15_MULTI_ERR)),
856 FLAG_ENTRY0("bad_pkt_length_err", DCCE(BAD_PKT_LENGTH_ERR)),
857 FLAG_ENTRY0("unsup_vl_err", DCCE(UNSUP_VL_ERR)),
858 FLAG_ENTRY0("perm_nvl15_err", DCCE(PERM_NVL15_ERR)),
859 FLAG_ENTRY0("slid_zero_err", DCCE(SLID_ZERO_ERR)),
860 FLAG_ENTRY0("dlid_zero_err", DCCE(DLID_ZERO_ERR)),
861 FLAG_ENTRY0("length_mtu_err", DCCE(LENGTH_MTU_ERR)),
862 FLAG_ENTRY0("rx_early_drop_err", DCCE(RX_EARLY_DROP_ERR)),
863 FLAG_ENTRY0("late_short_err", DCCE(LATE_SHORT_ERR)),
864 FLAG_ENTRY0("late_long_err", DCCE(LATE_LONG_ERR)),
865 FLAG_ENTRY0("late_ebp_err", DCCE(LATE_EBP_ERR)),
866 FLAG_ENTRY0("fpe_tx_fifo_ovflw_err", DCCE(FPE_TX_FIFO_OVFLW_ERR)),
867 FLAG_ENTRY0("fpe_tx_fifo_unflw_err", DCCE(FPE_TX_FIFO_UNFLW_ERR)),
868 FLAG_ENTRY0("csr_access_blocked_host", DCCE(CSR_ACCESS_BLOCKED_HOST)),
869 FLAG_ENTRY0("csr_access_blocked_uc", DCCE(CSR_ACCESS_BLOCKED_UC)),
870 FLAG_ENTRY0("tx_ctrl_parity_err", DCCE(TX_CTRL_PARITY_ERR)),
871 FLAG_ENTRY0("tx_ctrl_parity_mbe_err", DCCE(TX_CTRL_PARITY_MBE_ERR)),
872 FLAG_ENTRY0("tx_sc_parity_err", DCCE(TX_SC_PARITY_ERR)),
873 FLAG_ENTRY0("rx_ctrl_parity_mbe_err", DCCE(RX_CTRL_PARITY_MBE_ERR)),
874 FLAG_ENTRY0("csr_parity_err", DCCE(CSR_PARITY_ERR)),
875 FLAG_ENTRY0("csr_inval_addr", DCCE(CSR_INVAL_ADDR)),
876 FLAG_ENTRY0("tx_byte_shft_parity_err", DCCE(TX_BYTE_SHFT_PARITY_ERR)),
877 FLAG_ENTRY0("rx_byte_shft_parity_err", DCCE(RX_BYTE_SHFT_PARITY_ERR)),
878 FLAG_ENTRY0("fmconfig_err", DCCE(FMCONFIG_ERR)),
879 FLAG_ENTRY0("rcvport_err", DCCE(RCVPORT_ERR)),
880};
881
882/*
883 * LCB error flags
884 */
885#define LCBE(name) DC_LCB_ERR_FLG_##name##_SMASK
886static struct flag_table lcb_err_flags[] = {
887/* 0*/ FLAG_ENTRY0("CSR_PARITY_ERR", LCBE(CSR_PARITY_ERR)),
888/* 1*/ FLAG_ENTRY0("INVALID_CSR_ADDR", LCBE(INVALID_CSR_ADDR)),
889/* 2*/ FLAG_ENTRY0("RST_FOR_FAILED_DESKEW", LCBE(RST_FOR_FAILED_DESKEW)),
890/* 3*/ FLAG_ENTRY0("ALL_LNS_FAILED_REINIT_TEST",
891 LCBE(ALL_LNS_FAILED_REINIT_TEST)),
892/* 4*/ FLAG_ENTRY0("LOST_REINIT_STALL_OR_TOS", LCBE(LOST_REINIT_STALL_OR_TOS)),
893/* 5*/ FLAG_ENTRY0("TX_LESS_THAN_FOUR_LNS", LCBE(TX_LESS_THAN_FOUR_LNS)),
894/* 6*/ FLAG_ENTRY0("RX_LESS_THAN_FOUR_LNS", LCBE(RX_LESS_THAN_FOUR_LNS)),
895/* 7*/ FLAG_ENTRY0("SEQ_CRC_ERR", LCBE(SEQ_CRC_ERR)),
896/* 8*/ FLAG_ENTRY0("REINIT_FROM_PEER", LCBE(REINIT_FROM_PEER)),
897/* 9*/ FLAG_ENTRY0("REINIT_FOR_LN_DEGRADE", LCBE(REINIT_FOR_LN_DEGRADE)),
898/*10*/ FLAG_ENTRY0("CRC_ERR_CNT_HIT_LIMIT", LCBE(CRC_ERR_CNT_HIT_LIMIT)),
899/*11*/ FLAG_ENTRY0("RCLK_STOPPED", LCBE(RCLK_STOPPED)),
900/*12*/ FLAG_ENTRY0("UNEXPECTED_REPLAY_MARKER", LCBE(UNEXPECTED_REPLAY_MARKER)),
901/*13*/ FLAG_ENTRY0("UNEXPECTED_ROUND_TRIP_MARKER",
902 LCBE(UNEXPECTED_ROUND_TRIP_MARKER)),
903/*14*/ FLAG_ENTRY0("ILLEGAL_NULL_LTP", LCBE(ILLEGAL_NULL_LTP)),
904/*15*/ FLAG_ENTRY0("ILLEGAL_FLIT_ENCODING", LCBE(ILLEGAL_FLIT_ENCODING)),
905/*16*/ FLAG_ENTRY0("FLIT_INPUT_BUF_OFLW", LCBE(FLIT_INPUT_BUF_OFLW)),
906/*17*/ FLAG_ENTRY0("VL_ACK_INPUT_BUF_OFLW", LCBE(VL_ACK_INPUT_BUF_OFLW)),
907/*18*/ FLAG_ENTRY0("VL_ACK_INPUT_PARITY_ERR", LCBE(VL_ACK_INPUT_PARITY_ERR)),
908/*19*/ FLAG_ENTRY0("VL_ACK_INPUT_WRONG_CRC_MODE",
909 LCBE(VL_ACK_INPUT_WRONG_CRC_MODE)),
910/*20*/ FLAG_ENTRY0("FLIT_INPUT_BUF_MBE", LCBE(FLIT_INPUT_BUF_MBE)),
911/*21*/ FLAG_ENTRY0("FLIT_INPUT_BUF_SBE", LCBE(FLIT_INPUT_BUF_SBE)),
912/*22*/ FLAG_ENTRY0("REPLAY_BUF_MBE", LCBE(REPLAY_BUF_MBE)),
913/*23*/ FLAG_ENTRY0("REPLAY_BUF_SBE", LCBE(REPLAY_BUF_SBE)),
914/*24*/ FLAG_ENTRY0("CREDIT_RETURN_FLIT_MBE", LCBE(CREDIT_RETURN_FLIT_MBE)),
915/*25*/ FLAG_ENTRY0("RST_FOR_LINK_TIMEOUT", LCBE(RST_FOR_LINK_TIMEOUT)),
916/*26*/ FLAG_ENTRY0("RST_FOR_INCOMPLT_RND_TRIP",
917 LCBE(RST_FOR_INCOMPLT_RND_TRIP)),
918/*27*/ FLAG_ENTRY0("HOLD_REINIT", LCBE(HOLD_REINIT)),
919/*28*/ FLAG_ENTRY0("NEG_EDGE_LINK_TRANSFER_ACTIVE",
920 LCBE(NEG_EDGE_LINK_TRANSFER_ACTIVE)),
921/*29*/ FLAG_ENTRY0("REDUNDANT_FLIT_PARITY_ERR",
922 LCBE(REDUNDANT_FLIT_PARITY_ERR))
923};
924
925/*
926 * DC8051 Error Flags
927 */
928#define D8E(name) DC_DC8051_ERR_FLG_##name##_SMASK
929static struct flag_table dc8051_err_flags[] = {
930 FLAG_ENTRY0("SET_BY_8051", D8E(SET_BY_8051)),
931 FLAG_ENTRY0("LOST_8051_HEART_BEAT", D8E(LOST_8051_HEART_BEAT)),
932 FLAG_ENTRY0("CRAM_MBE", D8E(CRAM_MBE)),
933 FLAG_ENTRY0("CRAM_SBE", D8E(CRAM_SBE)),
934 FLAG_ENTRY0("DRAM_MBE", D8E(DRAM_MBE)),
935 FLAG_ENTRY0("DRAM_SBE", D8E(DRAM_SBE)),
936 FLAG_ENTRY0("IRAM_MBE", D8E(IRAM_MBE)),
937 FLAG_ENTRY0("IRAM_SBE", D8E(IRAM_SBE)),
938 FLAG_ENTRY0("UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES",
939 D8E(UNMATCHED_SECURE_MSG_ACROSS_BCC_LANES)),
940 FLAG_ENTRY0("INVALID_CSR_ADDR", D8E(INVALID_CSR_ADDR)),
941};
942
943/*
944 * DC8051 Information Error flags
945 *
946 * Flags in DC8051_DBG_ERR_INFO_SET_BY_8051.ERROR field.
947 */
948static struct flag_table dc8051_info_err_flags[] = {
949 FLAG_ENTRY0("Spico ROM check failed", SPICO_ROM_FAILED),
950 FLAG_ENTRY0("Unknown frame received", UNKNOWN_FRAME),
951 FLAG_ENTRY0("Target BER not met", TARGET_BER_NOT_MET),
952 FLAG_ENTRY0("Serdes internal loopback failure",
953 FAILED_SERDES_INTERNAL_LOOPBACK),
954 FLAG_ENTRY0("Failed SerDes init", FAILED_SERDES_INIT),
955 FLAG_ENTRY0("Failed LNI(Polling)", FAILED_LNI_POLLING),
956 FLAG_ENTRY0("Failed LNI(Debounce)", FAILED_LNI_DEBOUNCE),
957 FLAG_ENTRY0("Failed LNI(EstbComm)", FAILED_LNI_ESTBCOMM),
958 FLAG_ENTRY0("Failed LNI(OptEq)", FAILED_LNI_OPTEQ),
959 FLAG_ENTRY0("Failed LNI(VerifyCap_1)", FAILED_LNI_VERIFY_CAP1),
960 FLAG_ENTRY0("Failed LNI(VerifyCap_2)", FAILED_LNI_VERIFY_CAP2),
961 FLAG_ENTRY0("Failed LNI(ConfigLT)", FAILED_LNI_CONFIGLT)
962};
963
964/*
965 * DC8051 Information Host Information flags
966 *
967 * Flags in DC8051_DBG_ERR_INFO_SET_BY_8051.HOST_MSG field.
968 */
969static struct flag_table dc8051_info_host_msg_flags[] = {
970 FLAG_ENTRY0("Host request done", 0x0001),
971 FLAG_ENTRY0("BC SMA message", 0x0002),
972 FLAG_ENTRY0("BC PWR_MGM message", 0x0004),
973 FLAG_ENTRY0("BC Unknown message (BCC)", 0x0008),
974 FLAG_ENTRY0("BC Unknown message (LCB)", 0x0010),
975 FLAG_ENTRY0("External device config request", 0x0020),
976 FLAG_ENTRY0("VerifyCap all frames received", 0x0040),
977 FLAG_ENTRY0("LinkUp achieved", 0x0080),
978 FLAG_ENTRY0("Link going down", 0x0100),
979};
980
981
982static u32 encoded_size(u32 size);
983static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate);
984static int set_physical_link_state(struct hfi1_devdata *dd, u64 state);
985static void read_vc_remote_phy(struct hfi1_devdata *dd, u8 *power_management,
986 u8 *continuous);
987static void read_vc_remote_fabric(struct hfi1_devdata *dd, u8 *vau, u8 *z,
988 u8 *vcu, u16 *vl15buf, u8 *crc_sizes);
989static void read_vc_remote_link_width(struct hfi1_devdata *dd,
990 u8 *remote_tx_rate, u16 *link_widths);
991static void read_vc_local_link_width(struct hfi1_devdata *dd, u8 *misc_bits,
992 u8 *flag_bits, u16 *link_widths);
993static void read_remote_device_id(struct hfi1_devdata *dd, u16 *device_id,
994 u8 *device_rev);
995static void read_mgmt_allowed(struct hfi1_devdata *dd, u8 *mgmt_allowed);
996static void read_local_lni(struct hfi1_devdata *dd, u8 *enable_lane_rx);
997static int read_tx_settings(struct hfi1_devdata *dd, u8 *enable_lane_tx,
998 u8 *tx_polarity_inversion,
999 u8 *rx_polarity_inversion, u8 *max_rate);
1000static void handle_sdma_eng_err(struct hfi1_devdata *dd,
1001 unsigned int context, u64 err_status);
1002static void handle_qsfp_int(struct hfi1_devdata *dd, u32 source, u64 reg);
1003static void handle_dcc_err(struct hfi1_devdata *dd,
1004 unsigned int context, u64 err_status);
1005static void handle_lcb_err(struct hfi1_devdata *dd,
1006 unsigned int context, u64 err_status);
1007static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg);
1008static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
1009static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
1010static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
1011static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
1012static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
1013static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
1014static void handle_txe_err(struct hfi1_devdata *dd, u32 unused, u64 reg);
1015static void set_partition_keys(struct hfi1_pportdata *);
1016static const char *link_state_name(u32 state);
1017static const char *link_state_reason_name(struct hfi1_pportdata *ppd,
1018 u32 state);
1019static int do_8051_command(struct hfi1_devdata *dd, u32 type, u64 in_data,
1020 u64 *out_data);
1021static int read_idle_sma(struct hfi1_devdata *dd, u64 *data);
1022static int thermal_init(struct hfi1_devdata *dd);
1023
1024static int wait_logical_linkstate(struct hfi1_pportdata *ppd, u32 state,
1025 int msecs);
1026static void read_planned_down_reason_code(struct hfi1_devdata *dd, u8 *pdrrc);
1027static void handle_temp_err(struct hfi1_devdata *);
1028static void dc_shutdown(struct hfi1_devdata *);
1029static void dc_start(struct hfi1_devdata *);
1030
1031/*
1032 * Error interrupt table entry. This is used as input to the interrupt
1033 * "clear down" routine used for all second tier error interrupt register.
1034 * Second tier interrupt registers have a single bit representing them
1035 * in the top-level CceIntStatus.
1036 */
1037struct err_reg_info {
1038 u32 status; /* status CSR offset */
1039 u32 clear; /* clear CSR offset */
1040 u32 mask; /* mask CSR offset */
1041 void (*handler)(struct hfi1_devdata *dd, u32 source, u64 reg);
1042 const char *desc;
1043};
1044
1045#define NUM_MISC_ERRS (IS_GENERAL_ERR_END - IS_GENERAL_ERR_START)
1046#define NUM_DC_ERRS (IS_DC_END - IS_DC_START)
1047#define NUM_VARIOUS (IS_VARIOUS_END - IS_VARIOUS_START)
1048
1049/*
1050 * Helpers for building HFI and DC error interrupt table entries. Different
1051 * helpers are needed because of inconsistent register names.
1052 */
1053#define EE(reg, handler, desc) \
1054 { reg##_STATUS, reg##_CLEAR, reg##_MASK, \
1055 handler, desc }
1056#define DC_EE1(reg, handler, desc) \
1057 { reg##_FLG, reg##_FLG_CLR, reg##_FLG_EN, handler, desc }
1058#define DC_EE2(reg, handler, desc) \
1059 { reg##_FLG, reg##_CLR, reg##_EN, handler, desc }
1060
1061/*
1062 * Table of the "misc" grouping of error interrupts. Each entry refers to
1063 * another register containing more information.
1064 */
1065static const struct err_reg_info misc_errs[NUM_MISC_ERRS] = {
1066/* 0*/ EE(CCE_ERR, handle_cce_err, "CceErr"),
1067/* 1*/ EE(RCV_ERR, handle_rxe_err, "RxeErr"),
1068/* 2*/ EE(MISC_ERR, handle_misc_err, "MiscErr"),
1069/* 3*/ { 0, 0, 0, NULL }, /* reserved */
1070/* 4*/ EE(SEND_PIO_ERR, handle_pio_err, "PioErr"),
1071/* 5*/ EE(SEND_DMA_ERR, handle_sdma_err, "SDmaErr"),
1072/* 6*/ EE(SEND_EGRESS_ERR, handle_egress_err, "EgressErr"),
1073/* 7*/ EE(SEND_ERR, handle_txe_err, "TxeErr")
1074 /* the rest are reserved */
1075};
1076
1077/*
1078 * Index into the Various section of the interrupt sources
1079 * corresponding to the Critical Temperature interrupt.
1080 */
1081#define TCRIT_INT_SOURCE 4
1082
1083/*
1084 * SDMA error interrupt entry - refers to another register containing more
1085 * information.
1086 */
1087static const struct err_reg_info sdma_eng_err =
1088 EE(SEND_DMA_ENG_ERR, handle_sdma_eng_err, "SDmaEngErr");
1089
1090static const struct err_reg_info various_err[NUM_VARIOUS] = {
1091/* 0*/ { 0, 0, 0, NULL }, /* PbcInt */
1092/* 1*/ { 0, 0, 0, NULL }, /* GpioAssertInt */
1093/* 2*/ EE(ASIC_QSFP1, handle_qsfp_int, "QSFP1"),
1094/* 3*/ EE(ASIC_QSFP2, handle_qsfp_int, "QSFP2"),
1095/* 4*/ { 0, 0, 0, NULL }, /* TCritInt */
1096 /* rest are reserved */
1097};
1098
1099/*
1100 * The DC encoding of mtu_cap for 10K MTU in the DCC_CFG_PORT_CONFIG
1101 * register can not be derived from the MTU value because 10K is not
1102 * a power of 2. Therefore, we need a constant. Everything else can
1103 * be calculated.
1104 */
1105#define DCC_CFG_PORT_MTU_CAP_10240 7
1106
1107/*
1108 * Table of the DC grouping of error interrupts. Each entry refers to
1109 * another register containing more information.
1110 */
1111static const struct err_reg_info dc_errs[NUM_DC_ERRS] = {
1112/* 0*/ DC_EE1(DCC_ERR, handle_dcc_err, "DCC Err"),
1113/* 1*/ DC_EE2(DC_LCB_ERR, handle_lcb_err, "LCB Err"),
1114/* 2*/ DC_EE2(DC_DC8051_ERR, handle_8051_interrupt, "DC8051 Interrupt"),
1115/* 3*/ /* dc_lbm_int - special, see is_dc_int() */
1116 /* the rest are reserved */
1117};
1118
1119struct cntr_entry {
1120 /*
1121 * counter name
1122 */
1123 char *name;
1124
1125 /*
1126 * csr to read for name (if applicable)
1127 */
1128 u64 csr;
1129
1130 /*
1131 * offset into dd or ppd to store the counter's value
1132 */
1133 int offset;
1134
1135 /*
1136 * flags
1137 */
1138 u8 flags;
1139
1140 /*
1141 * accessor for stat element, context either dd or ppd
1142 */
1143 u64 (*rw_cntr)(const struct cntr_entry *,
1144 void *context,
1145 int vl,
1146 int mode,
1147 u64 data);
1148};
1149
1150#define C_RCV_HDR_OVF_FIRST C_RCV_HDR_OVF_0
1151#define C_RCV_HDR_OVF_LAST C_RCV_HDR_OVF_159
1152
1153#define CNTR_ELEM(name, csr, offset, flags, accessor) \
1154{ \
1155 name, \
1156 csr, \
1157 offset, \
1158 flags, \
1159 accessor \
1160}
1161
1162/* 32bit RXE */
1163#define RXE32_PORT_CNTR_ELEM(name, counter, flags) \
1164CNTR_ELEM(#name, \
1165 (counter * 8 + RCV_COUNTER_ARRAY32), \
1166 0, flags | CNTR_32BIT, \
1167 port_access_u32_csr)
1168
1169#define RXE32_DEV_CNTR_ELEM(name, counter, flags) \
1170CNTR_ELEM(#name, \
1171 (counter * 8 + RCV_COUNTER_ARRAY32), \
1172 0, flags | CNTR_32BIT, \
1173 dev_access_u32_csr)
1174
1175/* 64bit RXE */
1176#define RXE64_PORT_CNTR_ELEM(name, counter, flags) \
1177CNTR_ELEM(#name, \
1178 (counter * 8 + RCV_COUNTER_ARRAY64), \
1179 0, flags, \
1180 port_access_u64_csr)
1181
1182#define RXE64_DEV_CNTR_ELEM(name, counter, flags) \
1183CNTR_ELEM(#name, \
1184 (counter * 8 + RCV_COUNTER_ARRAY64), \
1185 0, flags, \
1186 dev_access_u64_csr)
1187
1188#define OVR_LBL(ctx) C_RCV_HDR_OVF_ ## ctx
1189#define OVR_ELM(ctx) \
1190CNTR_ELEM("RcvHdrOvr" #ctx, \
1191 (RCV_HDR_OVFL_CNT + ctx*0x100), \
1192 0, CNTR_NORMAL, port_access_u64_csr)
1193
1194/* 32bit TXE */
1195#define TXE32_PORT_CNTR_ELEM(name, counter, flags) \
1196CNTR_ELEM(#name, \
1197 (counter * 8 + SEND_COUNTER_ARRAY32), \
1198 0, flags | CNTR_32BIT, \
1199 port_access_u32_csr)
1200
1201/* 64bit TXE */
1202#define TXE64_PORT_CNTR_ELEM(name, counter, flags) \
1203CNTR_ELEM(#name, \
1204 (counter * 8 + SEND_COUNTER_ARRAY64), \
1205 0, flags, \
1206 port_access_u64_csr)
1207
1208# define TX64_DEV_CNTR_ELEM(name, counter, flags) \
1209CNTR_ELEM(#name,\
1210 counter * 8 + SEND_COUNTER_ARRAY64, \
1211 0, \
1212 flags, \
1213 dev_access_u64_csr)
1214
1215/* CCE */
1216#define CCE_PERF_DEV_CNTR_ELEM(name, counter, flags) \
1217CNTR_ELEM(#name, \
1218 (counter * 8 + CCE_COUNTER_ARRAY32), \
1219 0, flags | CNTR_32BIT, \
1220 dev_access_u32_csr)
1221
1222#define CCE_INT_DEV_CNTR_ELEM(name, counter, flags) \
1223CNTR_ELEM(#name, \
1224 (counter * 8 + CCE_INT_COUNTER_ARRAY32), \
1225 0, flags | CNTR_32BIT, \
1226 dev_access_u32_csr)
1227
1228/* DC */
1229#define DC_PERF_CNTR(name, counter, flags) \
1230CNTR_ELEM(#name, \
1231 counter, \
1232 0, \
1233 flags, \
1234 dev_access_u64_csr)
1235
1236#define DC_PERF_CNTR_LCB(name, counter, flags) \
1237CNTR_ELEM(#name, \
1238 counter, \
1239 0, \
1240 flags, \
1241 dc_access_lcb_cntr)
1242
1243/* ibp counters */
1244#define SW_IBP_CNTR(name, cntr) \
1245CNTR_ELEM(#name, \
1246 0, \
1247 0, \
1248 CNTR_SYNTH, \
1249 access_ibp_##cntr)
1250
1251u64 read_csr(const struct hfi1_devdata *dd, u32 offset)
1252{
1253 u64 val;
1254
1255 if (dd->flags & HFI1_PRESENT) {
1256 val = readq((void __iomem *)dd->kregbase + offset);
1257 return val;
1258 }
1259 return -1;
1260}
1261
1262void write_csr(const struct hfi1_devdata *dd, u32 offset, u64 value)
1263{
1264 if (dd->flags & HFI1_PRESENT)
1265 writeq(value, (void __iomem *)dd->kregbase + offset);
1266}
1267
1268void __iomem *get_csr_addr(
1269 struct hfi1_devdata *dd,
1270 u32 offset)
1271{
1272 return (void __iomem *)dd->kregbase + offset;
1273}
1274
1275static inline u64 read_write_csr(const struct hfi1_devdata *dd, u32 csr,
1276 int mode, u64 value)
1277{
1278 u64 ret;
1279
1280
1281 if (mode == CNTR_MODE_R) {
1282 ret = read_csr(dd, csr);
1283 } else if (mode == CNTR_MODE_W) {
1284 write_csr(dd, csr, value);
1285 ret = value;
1286 } else {
1287 dd_dev_err(dd, "Invalid cntr register access mode");
1288 return 0;
1289 }
1290
1291 hfi1_cdbg(CNTR, "csr 0x%x val 0x%llx mode %d", csr, ret, mode);
1292 return ret;
1293}
1294
1295/* Dev Access */
1296static u64 dev_access_u32_csr(const struct cntr_entry *entry,
1297 void *context, int vl, int mode, u64 data)
1298{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301299 struct hfi1_devdata *dd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001300
1301 if (vl != CNTR_INVALID_VL)
1302 return 0;
1303 return read_write_csr(dd, entry->csr, mode, data);
1304}
1305
1306static u64 dev_access_u64_csr(const struct cntr_entry *entry, void *context,
1307 int vl, int mode, u64 data)
1308{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301309 struct hfi1_devdata *dd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001310
1311 u64 val = 0;
1312 u64 csr = entry->csr;
1313
1314 if (entry->flags & CNTR_VL) {
1315 if (vl == CNTR_INVALID_VL)
1316 return 0;
1317 csr += 8 * vl;
1318 } else {
1319 if (vl != CNTR_INVALID_VL)
1320 return 0;
1321 }
1322
1323 val = read_write_csr(dd, csr, mode, data);
1324 return val;
1325}
1326
1327static u64 dc_access_lcb_cntr(const struct cntr_entry *entry, void *context,
1328 int vl, int mode, u64 data)
1329{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301330 struct hfi1_devdata *dd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001331 u32 csr = entry->csr;
1332 int ret = 0;
1333
1334 if (vl != CNTR_INVALID_VL)
1335 return 0;
1336 if (mode == CNTR_MODE_R)
1337 ret = read_lcb_csr(dd, csr, &data);
1338 else if (mode == CNTR_MODE_W)
1339 ret = write_lcb_csr(dd, csr, data);
1340
1341 if (ret) {
1342 dd_dev_err(dd, "Could not acquire LCB for counter 0x%x", csr);
1343 return 0;
1344 }
1345
1346 hfi1_cdbg(CNTR, "csr 0x%x val 0x%llx mode %d", csr, data, mode);
1347 return data;
1348}
1349
1350/* Port Access */
1351static u64 port_access_u32_csr(const struct cntr_entry *entry, void *context,
1352 int vl, int mode, u64 data)
1353{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301354 struct hfi1_pportdata *ppd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001355
1356 if (vl != CNTR_INVALID_VL)
1357 return 0;
1358 return read_write_csr(ppd->dd, entry->csr, mode, data);
1359}
1360
1361static u64 port_access_u64_csr(const struct cntr_entry *entry,
1362 void *context, int vl, int mode, u64 data)
1363{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301364 struct hfi1_pportdata *ppd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001365 u64 val;
1366 u64 csr = entry->csr;
1367
1368 if (entry->flags & CNTR_VL) {
1369 if (vl == CNTR_INVALID_VL)
1370 return 0;
1371 csr += 8 * vl;
1372 } else {
1373 if (vl != CNTR_INVALID_VL)
1374 return 0;
1375 }
1376 val = read_write_csr(ppd->dd, csr, mode, data);
1377 return val;
1378}
1379
1380/* Software defined */
1381static inline u64 read_write_sw(struct hfi1_devdata *dd, u64 *cntr, int mode,
1382 u64 data)
1383{
1384 u64 ret;
1385
1386 if (mode == CNTR_MODE_R) {
1387 ret = *cntr;
1388 } else if (mode == CNTR_MODE_W) {
1389 *cntr = data;
1390 ret = data;
1391 } else {
1392 dd_dev_err(dd, "Invalid cntr sw access mode");
1393 return 0;
1394 }
1395
1396 hfi1_cdbg(CNTR, "val 0x%llx mode %d", ret, mode);
1397
1398 return ret;
1399}
1400
1401static u64 access_sw_link_dn_cnt(const struct cntr_entry *entry, void *context,
1402 int vl, int mode, u64 data)
1403{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301404 struct hfi1_pportdata *ppd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001405
1406 if (vl != CNTR_INVALID_VL)
1407 return 0;
1408 return read_write_sw(ppd->dd, &ppd->link_downed, mode, data);
1409}
1410
1411static u64 access_sw_link_up_cnt(const struct cntr_entry *entry, void *context,
1412 int vl, int mode, u64 data)
1413{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301414 struct hfi1_pportdata *ppd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001415
1416 if (vl != CNTR_INVALID_VL)
1417 return 0;
1418 return read_write_sw(ppd->dd, &ppd->link_up, mode, data);
1419}
1420
1421static u64 access_sw_xmit_discards(const struct cntr_entry *entry,
1422 void *context, int vl, int mode, u64 data)
1423{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301424 struct hfi1_pportdata *ppd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001425
1426 if (vl != CNTR_INVALID_VL)
1427 return 0;
1428
1429 return read_write_sw(ppd->dd, &ppd->port_xmit_discards, mode, data);
1430}
1431
1432static u64 access_xmit_constraint_errs(const struct cntr_entry *entry,
1433 void *context, int vl, int mode, u64 data)
1434{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301435 struct hfi1_pportdata *ppd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001436
1437 if (vl != CNTR_INVALID_VL)
1438 return 0;
1439
1440 return read_write_sw(ppd->dd, &ppd->port_xmit_constraint_errors,
1441 mode, data);
1442}
1443
1444static u64 access_rcv_constraint_errs(const struct cntr_entry *entry,
1445 void *context, int vl, int mode, u64 data)
1446{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301447 struct hfi1_pportdata *ppd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001448
1449 if (vl != CNTR_INVALID_VL)
1450 return 0;
1451
1452 return read_write_sw(ppd->dd, &ppd->port_rcv_constraint_errors,
1453 mode, data);
1454}
1455
1456u64 get_all_cpu_total(u64 __percpu *cntr)
1457{
1458 int cpu;
1459 u64 counter = 0;
1460
1461 for_each_possible_cpu(cpu)
1462 counter += *per_cpu_ptr(cntr, cpu);
1463 return counter;
1464}
1465
1466static u64 read_write_cpu(struct hfi1_devdata *dd, u64 *z_val,
1467 u64 __percpu *cntr,
1468 int vl, int mode, u64 data)
1469{
1470
1471 u64 ret = 0;
1472
1473 if (vl != CNTR_INVALID_VL)
1474 return 0;
1475
1476 if (mode == CNTR_MODE_R) {
1477 ret = get_all_cpu_total(cntr) - *z_val;
1478 } else if (mode == CNTR_MODE_W) {
1479 /* A write can only zero the counter */
1480 if (data == 0)
1481 *z_val = get_all_cpu_total(cntr);
1482 else
1483 dd_dev_err(dd, "Per CPU cntrs can only be zeroed");
1484 } else {
1485 dd_dev_err(dd, "Invalid cntr sw cpu access mode");
1486 return 0;
1487 }
1488
1489 return ret;
1490}
1491
1492static u64 access_sw_cpu_intr(const struct cntr_entry *entry,
1493 void *context, int vl, int mode, u64 data)
1494{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301495 struct hfi1_devdata *dd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001496
1497 return read_write_cpu(dd, &dd->z_int_counter, dd->int_counter, vl,
1498 mode, data);
1499}
1500
1501static u64 access_sw_cpu_rcv_limit(const struct cntr_entry *entry,
1502 void *context, int vl, int mode, u64 data)
1503{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301504 struct hfi1_devdata *dd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001505
1506 return read_write_cpu(dd, &dd->z_rcv_limit, dd->rcv_limit, vl,
1507 mode, data);
1508}
1509
1510static u64 access_sw_pio_wait(const struct cntr_entry *entry,
1511 void *context, int vl, int mode, u64 data)
1512{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301513 struct hfi1_devdata *dd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001514
1515 return dd->verbs_dev.n_piowait;
1516}
1517
1518static u64 access_sw_vtx_wait(const struct cntr_entry *entry,
1519 void *context, int vl, int mode, u64 data)
1520{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301521 struct hfi1_devdata *dd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001522
1523 return dd->verbs_dev.n_txwait;
1524}
1525
1526static u64 access_sw_kmem_wait(const struct cntr_entry *entry,
1527 void *context, int vl, int mode, u64 data)
1528{
Shraddha Barkea787bde2015-10-15 00:58:29 +05301529 struct hfi1_devdata *dd = context;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001530
1531 return dd->verbs_dev.n_kmem_wait;
1532}
1533
Dean Luickb4219222015-10-26 10:28:35 -04001534static u64 access_sw_send_schedule(const struct cntr_entry *entry,
1535 void *context, int vl, int mode, u64 data)
1536{
1537 struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
1538
1539 return dd->verbs_dev.n_send_schedule;
1540}
1541
Mike Marciniszyn77241052015-07-30 15:17:43 -04001542#define def_access_sw_cpu(cntr) \
1543static u64 access_sw_cpu_##cntr(const struct cntr_entry *entry, \
1544 void *context, int vl, int mode, u64 data) \
1545{ \
1546 struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \
1547 return read_write_cpu(ppd->dd, &ppd->ibport_data.z_ ##cntr, \
1548 ppd->ibport_data.cntr, vl, \
1549 mode, data); \
1550}
1551
1552def_access_sw_cpu(rc_acks);
1553def_access_sw_cpu(rc_qacks);
1554def_access_sw_cpu(rc_delayed_comp);
1555
1556#define def_access_ibp_counter(cntr) \
1557static u64 access_ibp_##cntr(const struct cntr_entry *entry, \
1558 void *context, int vl, int mode, u64 data) \
1559{ \
1560 struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context; \
1561 \
1562 if (vl != CNTR_INVALID_VL) \
1563 return 0; \
1564 \
1565 return read_write_sw(ppd->dd, &ppd->ibport_data.n_ ##cntr, \
1566 mode, data); \
1567}
1568
1569def_access_ibp_counter(loop_pkts);
1570def_access_ibp_counter(rc_resends);
1571def_access_ibp_counter(rnr_naks);
1572def_access_ibp_counter(other_naks);
1573def_access_ibp_counter(rc_timeouts);
1574def_access_ibp_counter(pkt_drops);
1575def_access_ibp_counter(dmawait);
1576def_access_ibp_counter(rc_seqnak);
1577def_access_ibp_counter(rc_dupreq);
1578def_access_ibp_counter(rdma_seq);
1579def_access_ibp_counter(unaligned);
1580def_access_ibp_counter(seq_naks);
1581
1582static struct cntr_entry dev_cntrs[DEV_CNTR_LAST] = {
1583[C_RCV_OVF] = RXE32_DEV_CNTR_ELEM(RcvOverflow, RCV_BUF_OVFL_CNT, CNTR_SYNTH),
1584[C_RX_TID_FULL] = RXE32_DEV_CNTR_ELEM(RxTIDFullEr, RCV_TID_FULL_ERR_CNT,
1585 CNTR_NORMAL),
1586[C_RX_TID_INVALID] = RXE32_DEV_CNTR_ELEM(RxTIDInvalid, RCV_TID_VALID_ERR_CNT,
1587 CNTR_NORMAL),
1588[C_RX_TID_FLGMS] = RXE32_DEV_CNTR_ELEM(RxTidFLGMs,
1589 RCV_TID_FLOW_GEN_MISMATCH_CNT,
1590 CNTR_NORMAL),
Mike Marciniszyn77241052015-07-30 15:17:43 -04001591[C_RX_CTX_EGRS] = RXE32_DEV_CNTR_ELEM(RxCtxEgrS, RCV_CONTEXT_EGR_STALL,
1592 CNTR_NORMAL),
1593[C_RCV_TID_FLSMS] = RXE32_DEV_CNTR_ELEM(RxTidFLSMs,
1594 RCV_TID_FLOW_SEQ_MISMATCH_CNT, CNTR_NORMAL),
1595[C_CCE_PCI_CR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePciCrSt,
1596 CCE_PCIE_POSTED_CRDT_STALL_CNT, CNTR_NORMAL),
1597[C_CCE_PCI_TR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePciTrSt, CCE_PCIE_TRGT_STALL_CNT,
1598 CNTR_NORMAL),
1599[C_CCE_PIO_WR_ST] = CCE_PERF_DEV_CNTR_ELEM(CcePioWrSt, CCE_PIO_WR_STALL_CNT,
1600 CNTR_NORMAL),
1601[C_CCE_ERR_INT] = CCE_INT_DEV_CNTR_ELEM(CceErrInt, CCE_ERR_INT_CNT,
1602 CNTR_NORMAL),
1603[C_CCE_SDMA_INT] = CCE_INT_DEV_CNTR_ELEM(CceSdmaInt, CCE_SDMA_INT_CNT,
1604 CNTR_NORMAL),
1605[C_CCE_MISC_INT] = CCE_INT_DEV_CNTR_ELEM(CceMiscInt, CCE_MISC_INT_CNT,
1606 CNTR_NORMAL),
1607[C_CCE_RCV_AV_INT] = CCE_INT_DEV_CNTR_ELEM(CceRcvAvInt, CCE_RCV_AVAIL_INT_CNT,
1608 CNTR_NORMAL),
1609[C_CCE_RCV_URG_INT] = CCE_INT_DEV_CNTR_ELEM(CceRcvUrgInt,
1610 CCE_RCV_URGENT_INT_CNT, CNTR_NORMAL),
1611[C_CCE_SEND_CR_INT] = CCE_INT_DEV_CNTR_ELEM(CceSndCrInt,
1612 CCE_SEND_CREDIT_INT_CNT, CNTR_NORMAL),
1613[C_DC_UNC_ERR] = DC_PERF_CNTR(DcUnctblErr, DCC_ERR_UNCORRECTABLE_CNT,
1614 CNTR_SYNTH),
1615[C_DC_RCV_ERR] = DC_PERF_CNTR(DcRecvErr, DCC_ERR_PORTRCV_ERR_CNT, CNTR_SYNTH),
1616[C_DC_FM_CFG_ERR] = DC_PERF_CNTR(DcFmCfgErr, DCC_ERR_FMCONFIG_ERR_CNT,
1617 CNTR_SYNTH),
1618[C_DC_RMT_PHY_ERR] = DC_PERF_CNTR(DcRmtPhyErr, DCC_ERR_RCVREMOTE_PHY_ERR_CNT,
1619 CNTR_SYNTH),
1620[C_DC_DROPPED_PKT] = DC_PERF_CNTR(DcDroppedPkt, DCC_ERR_DROPPED_PKT_CNT,
1621 CNTR_SYNTH),
1622[C_DC_MC_XMIT_PKTS] = DC_PERF_CNTR(DcMcXmitPkts,
1623 DCC_PRF_PORT_XMIT_MULTICAST_CNT, CNTR_SYNTH),
1624[C_DC_MC_RCV_PKTS] = DC_PERF_CNTR(DcMcRcvPkts,
1625 DCC_PRF_PORT_RCV_MULTICAST_PKT_CNT,
1626 CNTR_SYNTH),
1627[C_DC_XMIT_CERR] = DC_PERF_CNTR(DcXmitCorr,
1628 DCC_PRF_PORT_XMIT_CORRECTABLE_CNT, CNTR_SYNTH),
1629[C_DC_RCV_CERR] = DC_PERF_CNTR(DcRcvCorrCnt, DCC_PRF_PORT_RCV_CORRECTABLE_CNT,
1630 CNTR_SYNTH),
1631[C_DC_RCV_FCC] = DC_PERF_CNTR(DcRxFCntl, DCC_PRF_RX_FLOW_CRTL_CNT,
1632 CNTR_SYNTH),
1633[C_DC_XMIT_FCC] = DC_PERF_CNTR(DcXmitFCntl, DCC_PRF_TX_FLOW_CRTL_CNT,
1634 CNTR_SYNTH),
1635[C_DC_XMIT_FLITS] = DC_PERF_CNTR(DcXmitFlits, DCC_PRF_PORT_XMIT_DATA_CNT,
1636 CNTR_SYNTH),
1637[C_DC_RCV_FLITS] = DC_PERF_CNTR(DcRcvFlits, DCC_PRF_PORT_RCV_DATA_CNT,
1638 CNTR_SYNTH),
1639[C_DC_XMIT_PKTS] = DC_PERF_CNTR(DcXmitPkts, DCC_PRF_PORT_XMIT_PKTS_CNT,
1640 CNTR_SYNTH),
1641[C_DC_RCV_PKTS] = DC_PERF_CNTR(DcRcvPkts, DCC_PRF_PORT_RCV_PKTS_CNT,
1642 CNTR_SYNTH),
1643[C_DC_RX_FLIT_VL] = DC_PERF_CNTR(DcRxFlitVl, DCC_PRF_PORT_VL_RCV_DATA_CNT,
1644 CNTR_SYNTH | CNTR_VL),
1645[C_DC_RX_PKT_VL] = DC_PERF_CNTR(DcRxPktVl, DCC_PRF_PORT_VL_RCV_PKTS_CNT,
1646 CNTR_SYNTH | CNTR_VL),
1647[C_DC_RCV_FCN] = DC_PERF_CNTR(DcRcvFcn, DCC_PRF_PORT_RCV_FECN_CNT, CNTR_SYNTH),
1648[C_DC_RCV_FCN_VL] = DC_PERF_CNTR(DcRcvFcnVl, DCC_PRF_PORT_VL_RCV_FECN_CNT,
1649 CNTR_SYNTH | CNTR_VL),
1650[C_DC_RCV_BCN] = DC_PERF_CNTR(DcRcvBcn, DCC_PRF_PORT_RCV_BECN_CNT, CNTR_SYNTH),
1651[C_DC_RCV_BCN_VL] = DC_PERF_CNTR(DcRcvBcnVl, DCC_PRF_PORT_VL_RCV_BECN_CNT,
1652 CNTR_SYNTH | CNTR_VL),
1653[C_DC_RCV_BBL] = DC_PERF_CNTR(DcRcvBbl, DCC_PRF_PORT_RCV_BUBBLE_CNT,
1654 CNTR_SYNTH),
1655[C_DC_RCV_BBL_VL] = DC_PERF_CNTR(DcRcvBblVl, DCC_PRF_PORT_VL_RCV_BUBBLE_CNT,
1656 CNTR_SYNTH | CNTR_VL),
1657[C_DC_MARK_FECN] = DC_PERF_CNTR(DcMarkFcn, DCC_PRF_PORT_MARK_FECN_CNT,
1658 CNTR_SYNTH),
1659[C_DC_MARK_FECN_VL] = DC_PERF_CNTR(DcMarkFcnVl, DCC_PRF_PORT_VL_MARK_FECN_CNT,
1660 CNTR_SYNTH | CNTR_VL),
1661[C_DC_TOTAL_CRC] =
1662 DC_PERF_CNTR_LCB(DcTotCrc, DC_LCB_ERR_INFO_TOTAL_CRC_ERR,
1663 CNTR_SYNTH),
1664[C_DC_CRC_LN0] = DC_PERF_CNTR_LCB(DcCrcLn0, DC_LCB_ERR_INFO_CRC_ERR_LN0,
1665 CNTR_SYNTH),
1666[C_DC_CRC_LN1] = DC_PERF_CNTR_LCB(DcCrcLn1, DC_LCB_ERR_INFO_CRC_ERR_LN1,
1667 CNTR_SYNTH),
1668[C_DC_CRC_LN2] = DC_PERF_CNTR_LCB(DcCrcLn2, DC_LCB_ERR_INFO_CRC_ERR_LN2,
1669 CNTR_SYNTH),
1670[C_DC_CRC_LN3] = DC_PERF_CNTR_LCB(DcCrcLn3, DC_LCB_ERR_INFO_CRC_ERR_LN3,
1671 CNTR_SYNTH),
1672[C_DC_CRC_MULT_LN] =
1673 DC_PERF_CNTR_LCB(DcMultLn, DC_LCB_ERR_INFO_CRC_ERR_MULTI_LN,
1674 CNTR_SYNTH),
1675[C_DC_TX_REPLAY] = DC_PERF_CNTR_LCB(DcTxReplay, DC_LCB_ERR_INFO_TX_REPLAY_CNT,
1676 CNTR_SYNTH),
1677[C_DC_RX_REPLAY] = DC_PERF_CNTR_LCB(DcRxReplay, DC_LCB_ERR_INFO_RX_REPLAY_CNT,
1678 CNTR_SYNTH),
1679[C_DC_SEQ_CRC_CNT] =
1680 DC_PERF_CNTR_LCB(DcLinkSeqCrc, DC_LCB_ERR_INFO_SEQ_CRC_CNT,
1681 CNTR_SYNTH),
1682[C_DC_ESC0_ONLY_CNT] =
1683 DC_PERF_CNTR_LCB(DcEsc0, DC_LCB_ERR_INFO_ESCAPE_0_ONLY_CNT,
1684 CNTR_SYNTH),
1685[C_DC_ESC0_PLUS1_CNT] =
1686 DC_PERF_CNTR_LCB(DcEsc1, DC_LCB_ERR_INFO_ESCAPE_0_PLUS1_CNT,
1687 CNTR_SYNTH),
1688[C_DC_ESC0_PLUS2_CNT] =
1689 DC_PERF_CNTR_LCB(DcEsc0Plus2, DC_LCB_ERR_INFO_ESCAPE_0_PLUS2_CNT,
1690 CNTR_SYNTH),
1691[C_DC_REINIT_FROM_PEER_CNT] =
1692 DC_PERF_CNTR_LCB(DcReinitPeer, DC_LCB_ERR_INFO_REINIT_FROM_PEER_CNT,
1693 CNTR_SYNTH),
1694[C_DC_SBE_CNT] = DC_PERF_CNTR_LCB(DcSbe, DC_LCB_ERR_INFO_SBE_CNT,
1695 CNTR_SYNTH),
1696[C_DC_MISC_FLG_CNT] =
1697 DC_PERF_CNTR_LCB(DcMiscFlg, DC_LCB_ERR_INFO_MISC_FLG_CNT,
1698 CNTR_SYNTH),
1699[C_DC_PRF_GOOD_LTP_CNT] =
1700 DC_PERF_CNTR_LCB(DcGoodLTP, DC_LCB_PRF_GOOD_LTP_CNT, CNTR_SYNTH),
1701[C_DC_PRF_ACCEPTED_LTP_CNT] =
1702 DC_PERF_CNTR_LCB(DcAccLTP, DC_LCB_PRF_ACCEPTED_LTP_CNT,
1703 CNTR_SYNTH),
1704[C_DC_PRF_RX_FLIT_CNT] =
1705 DC_PERF_CNTR_LCB(DcPrfRxFlit, DC_LCB_PRF_RX_FLIT_CNT, CNTR_SYNTH),
1706[C_DC_PRF_TX_FLIT_CNT] =
1707 DC_PERF_CNTR_LCB(DcPrfTxFlit, DC_LCB_PRF_TX_FLIT_CNT, CNTR_SYNTH),
1708[C_DC_PRF_CLK_CNTR] =
1709 DC_PERF_CNTR_LCB(DcPrfClk, DC_LCB_PRF_CLK_CNTR, CNTR_SYNTH),
1710[C_DC_PG_DBG_FLIT_CRDTS_CNT] =
1711 DC_PERF_CNTR_LCB(DcFltCrdts, DC_LCB_PG_DBG_FLIT_CRDTS_CNT, CNTR_SYNTH),
1712[C_DC_PG_STS_PAUSE_COMPLETE_CNT] =
1713 DC_PERF_CNTR_LCB(DcPauseComp, DC_LCB_PG_STS_PAUSE_COMPLETE_CNT,
1714 CNTR_SYNTH),
1715[C_DC_PG_STS_TX_SBE_CNT] =
1716 DC_PERF_CNTR_LCB(DcStsTxSbe, DC_LCB_PG_STS_TX_SBE_CNT, CNTR_SYNTH),
1717[C_DC_PG_STS_TX_MBE_CNT] =
1718 DC_PERF_CNTR_LCB(DcStsTxMbe, DC_LCB_PG_STS_TX_MBE_CNT,
1719 CNTR_SYNTH),
1720[C_SW_CPU_INTR] = CNTR_ELEM("Intr", 0, 0, CNTR_NORMAL,
1721 access_sw_cpu_intr),
1722[C_SW_CPU_RCV_LIM] = CNTR_ELEM("RcvLimit", 0, 0, CNTR_NORMAL,
1723 access_sw_cpu_rcv_limit),
1724[C_SW_VTX_WAIT] = CNTR_ELEM("vTxWait", 0, 0, CNTR_NORMAL,
1725 access_sw_vtx_wait),
1726[C_SW_PIO_WAIT] = CNTR_ELEM("PioWait", 0, 0, CNTR_NORMAL,
1727 access_sw_pio_wait),
1728[C_SW_KMEM_WAIT] = CNTR_ELEM("KmemWait", 0, 0, CNTR_NORMAL,
1729 access_sw_kmem_wait),
Dean Luickb4219222015-10-26 10:28:35 -04001730[C_SW_SEND_SCHED] = CNTR_ELEM("SendSched", 0, 0, CNTR_NORMAL,
1731 access_sw_send_schedule),
Mike Marciniszyn77241052015-07-30 15:17:43 -04001732};
1733
1734static struct cntr_entry port_cntrs[PORT_CNTR_LAST] = {
1735[C_TX_UNSUP_VL] = TXE32_PORT_CNTR_ELEM(TxUnVLErr, SEND_UNSUP_VL_ERR_CNT,
1736 CNTR_NORMAL),
1737[C_TX_INVAL_LEN] = TXE32_PORT_CNTR_ELEM(TxInvalLen, SEND_LEN_ERR_CNT,
1738 CNTR_NORMAL),
1739[C_TX_MM_LEN_ERR] = TXE32_PORT_CNTR_ELEM(TxMMLenErr, SEND_MAX_MIN_LEN_ERR_CNT,
1740 CNTR_NORMAL),
1741[C_TX_UNDERRUN] = TXE32_PORT_CNTR_ELEM(TxUnderrun, SEND_UNDERRUN_CNT,
1742 CNTR_NORMAL),
1743[C_TX_FLOW_STALL] = TXE32_PORT_CNTR_ELEM(TxFlowStall, SEND_FLOW_STALL_CNT,
1744 CNTR_NORMAL),
1745[C_TX_DROPPED] = TXE32_PORT_CNTR_ELEM(TxDropped, SEND_DROPPED_PKT_CNT,
1746 CNTR_NORMAL),
1747[C_TX_HDR_ERR] = TXE32_PORT_CNTR_ELEM(TxHdrErr, SEND_HEADERS_ERR_CNT,
1748 CNTR_NORMAL),
1749[C_TX_PKT] = TXE64_PORT_CNTR_ELEM(TxPkt, SEND_DATA_PKT_CNT, CNTR_NORMAL),
1750[C_TX_WORDS] = TXE64_PORT_CNTR_ELEM(TxWords, SEND_DWORD_CNT, CNTR_NORMAL),
1751[C_TX_WAIT] = TXE64_PORT_CNTR_ELEM(TxWait, SEND_WAIT_CNT, CNTR_SYNTH),
1752[C_TX_FLIT_VL] = TXE64_PORT_CNTR_ELEM(TxFlitVL, SEND_DATA_VL0_CNT,
1753 CNTR_SYNTH | CNTR_VL),
1754[C_TX_PKT_VL] = TXE64_PORT_CNTR_ELEM(TxPktVL, SEND_DATA_PKT_VL0_CNT,
1755 CNTR_SYNTH | CNTR_VL),
1756[C_TX_WAIT_VL] = TXE64_PORT_CNTR_ELEM(TxWaitVL, SEND_WAIT_VL0_CNT,
1757 CNTR_SYNTH | CNTR_VL),
1758[C_RX_PKT] = RXE64_PORT_CNTR_ELEM(RxPkt, RCV_DATA_PKT_CNT, CNTR_NORMAL),
1759[C_RX_WORDS] = RXE64_PORT_CNTR_ELEM(RxWords, RCV_DWORD_CNT, CNTR_NORMAL),
1760[C_SW_LINK_DOWN] = CNTR_ELEM("SwLinkDown", 0, 0, CNTR_SYNTH | CNTR_32BIT,
1761 access_sw_link_dn_cnt),
1762[C_SW_LINK_UP] = CNTR_ELEM("SwLinkUp", 0, 0, CNTR_SYNTH | CNTR_32BIT,
1763 access_sw_link_up_cnt),
1764[C_SW_XMIT_DSCD] = CNTR_ELEM("XmitDscd", 0, 0, CNTR_SYNTH | CNTR_32BIT,
1765 access_sw_xmit_discards),
1766[C_SW_XMIT_DSCD_VL] = CNTR_ELEM("XmitDscdVl", 0, 0,
1767 CNTR_SYNTH | CNTR_32BIT | CNTR_VL,
1768 access_sw_xmit_discards),
1769[C_SW_XMIT_CSTR_ERR] = CNTR_ELEM("XmitCstrErr", 0, 0, CNTR_SYNTH,
1770 access_xmit_constraint_errs),
1771[C_SW_RCV_CSTR_ERR] = CNTR_ELEM("RcvCstrErr", 0, 0, CNTR_SYNTH,
1772 access_rcv_constraint_errs),
1773[C_SW_IBP_LOOP_PKTS] = SW_IBP_CNTR(LoopPkts, loop_pkts),
1774[C_SW_IBP_RC_RESENDS] = SW_IBP_CNTR(RcResend, rc_resends),
1775[C_SW_IBP_RNR_NAKS] = SW_IBP_CNTR(RnrNak, rnr_naks),
1776[C_SW_IBP_OTHER_NAKS] = SW_IBP_CNTR(OtherNak, other_naks),
1777[C_SW_IBP_RC_TIMEOUTS] = SW_IBP_CNTR(RcTimeOut, rc_timeouts),
1778[C_SW_IBP_PKT_DROPS] = SW_IBP_CNTR(PktDrop, pkt_drops),
1779[C_SW_IBP_DMA_WAIT] = SW_IBP_CNTR(DmaWait, dmawait),
1780[C_SW_IBP_RC_SEQNAK] = SW_IBP_CNTR(RcSeqNak, rc_seqnak),
1781[C_SW_IBP_RC_DUPREQ] = SW_IBP_CNTR(RcDupRew, rc_dupreq),
1782[C_SW_IBP_RDMA_SEQ] = SW_IBP_CNTR(RdmaSeq, rdma_seq),
1783[C_SW_IBP_UNALIGNED] = SW_IBP_CNTR(Unaligned, unaligned),
1784[C_SW_IBP_SEQ_NAK] = SW_IBP_CNTR(SeqNak, seq_naks),
1785[C_SW_CPU_RC_ACKS] = CNTR_ELEM("RcAcks", 0, 0, CNTR_NORMAL,
1786 access_sw_cpu_rc_acks),
1787[C_SW_CPU_RC_QACKS] = CNTR_ELEM("RcQacks", 0, 0, CNTR_NORMAL,
1788 access_sw_cpu_rc_qacks),
1789[C_SW_CPU_RC_DELAYED_COMP] = CNTR_ELEM("RcDelayComp", 0, 0, CNTR_NORMAL,
1790 access_sw_cpu_rc_delayed_comp),
1791[OVR_LBL(0)] = OVR_ELM(0), [OVR_LBL(1)] = OVR_ELM(1),
1792[OVR_LBL(2)] = OVR_ELM(2), [OVR_LBL(3)] = OVR_ELM(3),
1793[OVR_LBL(4)] = OVR_ELM(4), [OVR_LBL(5)] = OVR_ELM(5),
1794[OVR_LBL(6)] = OVR_ELM(6), [OVR_LBL(7)] = OVR_ELM(7),
1795[OVR_LBL(8)] = OVR_ELM(8), [OVR_LBL(9)] = OVR_ELM(9),
1796[OVR_LBL(10)] = OVR_ELM(10), [OVR_LBL(11)] = OVR_ELM(11),
1797[OVR_LBL(12)] = OVR_ELM(12), [OVR_LBL(13)] = OVR_ELM(13),
1798[OVR_LBL(14)] = OVR_ELM(14), [OVR_LBL(15)] = OVR_ELM(15),
1799[OVR_LBL(16)] = OVR_ELM(16), [OVR_LBL(17)] = OVR_ELM(17),
1800[OVR_LBL(18)] = OVR_ELM(18), [OVR_LBL(19)] = OVR_ELM(19),
1801[OVR_LBL(20)] = OVR_ELM(20), [OVR_LBL(21)] = OVR_ELM(21),
1802[OVR_LBL(22)] = OVR_ELM(22), [OVR_LBL(23)] = OVR_ELM(23),
1803[OVR_LBL(24)] = OVR_ELM(24), [OVR_LBL(25)] = OVR_ELM(25),
1804[OVR_LBL(26)] = OVR_ELM(26), [OVR_LBL(27)] = OVR_ELM(27),
1805[OVR_LBL(28)] = OVR_ELM(28), [OVR_LBL(29)] = OVR_ELM(29),
1806[OVR_LBL(30)] = OVR_ELM(30), [OVR_LBL(31)] = OVR_ELM(31),
1807[OVR_LBL(32)] = OVR_ELM(32), [OVR_LBL(33)] = OVR_ELM(33),
1808[OVR_LBL(34)] = OVR_ELM(34), [OVR_LBL(35)] = OVR_ELM(35),
1809[OVR_LBL(36)] = OVR_ELM(36), [OVR_LBL(37)] = OVR_ELM(37),
1810[OVR_LBL(38)] = OVR_ELM(38), [OVR_LBL(39)] = OVR_ELM(39),
1811[OVR_LBL(40)] = OVR_ELM(40), [OVR_LBL(41)] = OVR_ELM(41),
1812[OVR_LBL(42)] = OVR_ELM(42), [OVR_LBL(43)] = OVR_ELM(43),
1813[OVR_LBL(44)] = OVR_ELM(44), [OVR_LBL(45)] = OVR_ELM(45),
1814[OVR_LBL(46)] = OVR_ELM(46), [OVR_LBL(47)] = OVR_ELM(47),
1815[OVR_LBL(48)] = OVR_ELM(48), [OVR_LBL(49)] = OVR_ELM(49),
1816[OVR_LBL(50)] = OVR_ELM(50), [OVR_LBL(51)] = OVR_ELM(51),
1817[OVR_LBL(52)] = OVR_ELM(52), [OVR_LBL(53)] = OVR_ELM(53),
1818[OVR_LBL(54)] = OVR_ELM(54), [OVR_LBL(55)] = OVR_ELM(55),
1819[OVR_LBL(56)] = OVR_ELM(56), [OVR_LBL(57)] = OVR_ELM(57),
1820[OVR_LBL(58)] = OVR_ELM(58), [OVR_LBL(59)] = OVR_ELM(59),
1821[OVR_LBL(60)] = OVR_ELM(60), [OVR_LBL(61)] = OVR_ELM(61),
1822[OVR_LBL(62)] = OVR_ELM(62), [OVR_LBL(63)] = OVR_ELM(63),
1823[OVR_LBL(64)] = OVR_ELM(64), [OVR_LBL(65)] = OVR_ELM(65),
1824[OVR_LBL(66)] = OVR_ELM(66), [OVR_LBL(67)] = OVR_ELM(67),
1825[OVR_LBL(68)] = OVR_ELM(68), [OVR_LBL(69)] = OVR_ELM(69),
1826[OVR_LBL(70)] = OVR_ELM(70), [OVR_LBL(71)] = OVR_ELM(71),
1827[OVR_LBL(72)] = OVR_ELM(72), [OVR_LBL(73)] = OVR_ELM(73),
1828[OVR_LBL(74)] = OVR_ELM(74), [OVR_LBL(75)] = OVR_ELM(75),
1829[OVR_LBL(76)] = OVR_ELM(76), [OVR_LBL(77)] = OVR_ELM(77),
1830[OVR_LBL(78)] = OVR_ELM(78), [OVR_LBL(79)] = OVR_ELM(79),
1831[OVR_LBL(80)] = OVR_ELM(80), [OVR_LBL(81)] = OVR_ELM(81),
1832[OVR_LBL(82)] = OVR_ELM(82), [OVR_LBL(83)] = OVR_ELM(83),
1833[OVR_LBL(84)] = OVR_ELM(84), [OVR_LBL(85)] = OVR_ELM(85),
1834[OVR_LBL(86)] = OVR_ELM(86), [OVR_LBL(87)] = OVR_ELM(87),
1835[OVR_LBL(88)] = OVR_ELM(88), [OVR_LBL(89)] = OVR_ELM(89),
1836[OVR_LBL(90)] = OVR_ELM(90), [OVR_LBL(91)] = OVR_ELM(91),
1837[OVR_LBL(92)] = OVR_ELM(92), [OVR_LBL(93)] = OVR_ELM(93),
1838[OVR_LBL(94)] = OVR_ELM(94), [OVR_LBL(95)] = OVR_ELM(95),
1839[OVR_LBL(96)] = OVR_ELM(96), [OVR_LBL(97)] = OVR_ELM(97),
1840[OVR_LBL(98)] = OVR_ELM(98), [OVR_LBL(99)] = OVR_ELM(99),
1841[OVR_LBL(100)] = OVR_ELM(100), [OVR_LBL(101)] = OVR_ELM(101),
1842[OVR_LBL(102)] = OVR_ELM(102), [OVR_LBL(103)] = OVR_ELM(103),
1843[OVR_LBL(104)] = OVR_ELM(104), [OVR_LBL(105)] = OVR_ELM(105),
1844[OVR_LBL(106)] = OVR_ELM(106), [OVR_LBL(107)] = OVR_ELM(107),
1845[OVR_LBL(108)] = OVR_ELM(108), [OVR_LBL(109)] = OVR_ELM(109),
1846[OVR_LBL(110)] = OVR_ELM(110), [OVR_LBL(111)] = OVR_ELM(111),
1847[OVR_LBL(112)] = OVR_ELM(112), [OVR_LBL(113)] = OVR_ELM(113),
1848[OVR_LBL(114)] = OVR_ELM(114), [OVR_LBL(115)] = OVR_ELM(115),
1849[OVR_LBL(116)] = OVR_ELM(116), [OVR_LBL(117)] = OVR_ELM(117),
1850[OVR_LBL(118)] = OVR_ELM(118), [OVR_LBL(119)] = OVR_ELM(119),
1851[OVR_LBL(120)] = OVR_ELM(120), [OVR_LBL(121)] = OVR_ELM(121),
1852[OVR_LBL(122)] = OVR_ELM(122), [OVR_LBL(123)] = OVR_ELM(123),
1853[OVR_LBL(124)] = OVR_ELM(124), [OVR_LBL(125)] = OVR_ELM(125),
1854[OVR_LBL(126)] = OVR_ELM(126), [OVR_LBL(127)] = OVR_ELM(127),
1855[OVR_LBL(128)] = OVR_ELM(128), [OVR_LBL(129)] = OVR_ELM(129),
1856[OVR_LBL(130)] = OVR_ELM(130), [OVR_LBL(131)] = OVR_ELM(131),
1857[OVR_LBL(132)] = OVR_ELM(132), [OVR_LBL(133)] = OVR_ELM(133),
1858[OVR_LBL(134)] = OVR_ELM(134), [OVR_LBL(135)] = OVR_ELM(135),
1859[OVR_LBL(136)] = OVR_ELM(136), [OVR_LBL(137)] = OVR_ELM(137),
1860[OVR_LBL(138)] = OVR_ELM(138), [OVR_LBL(139)] = OVR_ELM(139),
1861[OVR_LBL(140)] = OVR_ELM(140), [OVR_LBL(141)] = OVR_ELM(141),
1862[OVR_LBL(142)] = OVR_ELM(142), [OVR_LBL(143)] = OVR_ELM(143),
1863[OVR_LBL(144)] = OVR_ELM(144), [OVR_LBL(145)] = OVR_ELM(145),
1864[OVR_LBL(146)] = OVR_ELM(146), [OVR_LBL(147)] = OVR_ELM(147),
1865[OVR_LBL(148)] = OVR_ELM(148), [OVR_LBL(149)] = OVR_ELM(149),
1866[OVR_LBL(150)] = OVR_ELM(150), [OVR_LBL(151)] = OVR_ELM(151),
1867[OVR_LBL(152)] = OVR_ELM(152), [OVR_LBL(153)] = OVR_ELM(153),
1868[OVR_LBL(154)] = OVR_ELM(154), [OVR_LBL(155)] = OVR_ELM(155),
1869[OVR_LBL(156)] = OVR_ELM(156), [OVR_LBL(157)] = OVR_ELM(157),
1870[OVR_LBL(158)] = OVR_ELM(158), [OVR_LBL(159)] = OVR_ELM(159),
1871};
1872
1873/* ======================================================================== */
1874
Mike Marciniszyn77241052015-07-30 15:17:43 -04001875/* return true if this is chip revision revision a */
1876int is_ax(struct hfi1_devdata *dd)
1877{
1878 u8 chip_rev_minor =
1879 dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT
1880 & CCE_REVISION_CHIP_REV_MINOR_MASK;
1881 return (chip_rev_minor & 0xf0) == 0;
1882}
1883
1884/* return true if this is chip revision revision b */
1885int is_bx(struct hfi1_devdata *dd)
1886{
1887 u8 chip_rev_minor =
1888 dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT
1889 & CCE_REVISION_CHIP_REV_MINOR_MASK;
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05001890 return (chip_rev_minor & 0xF0) == 0x10;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001891}
1892
1893/*
1894 * Append string s to buffer buf. Arguments curp and len are the current
1895 * position and remaining length, respectively.
1896 *
1897 * return 0 on success, 1 on out of room
1898 */
1899static int append_str(char *buf, char **curp, int *lenp, const char *s)
1900{
1901 char *p = *curp;
1902 int len = *lenp;
1903 int result = 0; /* success */
1904 char c;
1905
1906 /* add a comma, if first in the buffer */
1907 if (p != buf) {
1908 if (len == 0) {
1909 result = 1; /* out of room */
1910 goto done;
1911 }
1912 *p++ = ',';
1913 len--;
1914 }
1915
1916 /* copy the string */
1917 while ((c = *s++) != 0) {
1918 if (len == 0) {
1919 result = 1; /* out of room */
1920 goto done;
1921 }
1922 *p++ = c;
1923 len--;
1924 }
1925
1926done:
1927 /* write return values */
1928 *curp = p;
1929 *lenp = len;
1930
1931 return result;
1932}
1933
1934/*
1935 * Using the given flag table, print a comma separated string into
1936 * the buffer. End in '*' if the buffer is too short.
1937 */
1938static char *flag_string(char *buf, int buf_len, u64 flags,
1939 struct flag_table *table, int table_size)
1940{
1941 char extra[32];
1942 char *p = buf;
1943 int len = buf_len;
1944 int no_room = 0;
1945 int i;
1946
1947 /* make sure there is at least 2 so we can form "*" */
1948 if (len < 2)
1949 return "";
1950
1951 len--; /* leave room for a nul */
1952 for (i = 0; i < table_size; i++) {
1953 if (flags & table[i].flag) {
1954 no_room = append_str(buf, &p, &len, table[i].str);
1955 if (no_room)
1956 break;
1957 flags &= ~table[i].flag;
1958 }
1959 }
1960
1961 /* any undocumented bits left? */
1962 if (!no_room && flags) {
1963 snprintf(extra, sizeof(extra), "bits 0x%llx", flags);
1964 no_room = append_str(buf, &p, &len, extra);
1965 }
1966
1967 /* add * if ran out of room */
1968 if (no_room) {
1969 /* may need to back up to add space for a '*' */
1970 if (len == 0)
1971 --p;
1972 *p++ = '*';
1973 }
1974
1975 /* add final nul - space already allocated above */
1976 *p = 0;
1977 return buf;
1978}
1979
1980/* first 8 CCE error interrupt source names */
1981static const char * const cce_misc_names[] = {
1982 "CceErrInt", /* 0 */
1983 "RxeErrInt", /* 1 */
1984 "MiscErrInt", /* 2 */
1985 "Reserved3", /* 3 */
1986 "PioErrInt", /* 4 */
1987 "SDmaErrInt", /* 5 */
1988 "EgressErrInt", /* 6 */
1989 "TxeErrInt" /* 7 */
1990};
1991
1992/*
1993 * Return the miscellaneous error interrupt name.
1994 */
1995static char *is_misc_err_name(char *buf, size_t bsize, unsigned int source)
1996{
1997 if (source < ARRAY_SIZE(cce_misc_names))
1998 strncpy(buf, cce_misc_names[source], bsize);
1999 else
2000 snprintf(buf,
2001 bsize,
2002 "Reserved%u",
2003 source + IS_GENERAL_ERR_START);
2004
2005 return buf;
2006}
2007
2008/*
2009 * Return the SDMA engine error interrupt name.
2010 */
2011static char *is_sdma_eng_err_name(char *buf, size_t bsize, unsigned int source)
2012{
2013 snprintf(buf, bsize, "SDmaEngErrInt%u", source);
2014 return buf;
2015}
2016
2017/*
2018 * Return the send context error interrupt name.
2019 */
2020static char *is_sendctxt_err_name(char *buf, size_t bsize, unsigned int source)
2021{
2022 snprintf(buf, bsize, "SendCtxtErrInt%u", source);
2023 return buf;
2024}
2025
2026static const char * const various_names[] = {
2027 "PbcInt",
2028 "GpioAssertInt",
2029 "Qsfp1Int",
2030 "Qsfp2Int",
2031 "TCritInt"
2032};
2033
2034/*
2035 * Return the various interrupt name.
2036 */
2037static char *is_various_name(char *buf, size_t bsize, unsigned int source)
2038{
2039 if (source < ARRAY_SIZE(various_names))
2040 strncpy(buf, various_names[source], bsize);
2041 else
2042 snprintf(buf, bsize, "Reserved%u", source+IS_VARIOUS_START);
2043 return buf;
2044}
2045
2046/*
2047 * Return the DC interrupt name.
2048 */
2049static char *is_dc_name(char *buf, size_t bsize, unsigned int source)
2050{
2051 static const char * const dc_int_names[] = {
2052 "common",
2053 "lcb",
2054 "8051",
2055 "lbm" /* local block merge */
2056 };
2057
2058 if (source < ARRAY_SIZE(dc_int_names))
2059 snprintf(buf, bsize, "dc_%s_int", dc_int_names[source]);
2060 else
2061 snprintf(buf, bsize, "DCInt%u", source);
2062 return buf;
2063}
2064
2065static const char * const sdma_int_names[] = {
2066 "SDmaInt",
2067 "SdmaIdleInt",
2068 "SdmaProgressInt",
2069};
2070
2071/*
2072 * Return the SDMA engine interrupt name.
2073 */
2074static char *is_sdma_eng_name(char *buf, size_t bsize, unsigned int source)
2075{
2076 /* what interrupt */
2077 unsigned int what = source / TXE_NUM_SDMA_ENGINES;
2078 /* which engine */
2079 unsigned int which = source % TXE_NUM_SDMA_ENGINES;
2080
2081 if (likely(what < 3))
2082 snprintf(buf, bsize, "%s%u", sdma_int_names[what], which);
2083 else
2084 snprintf(buf, bsize, "Invalid SDMA interrupt %u", source);
2085 return buf;
2086}
2087
2088/*
2089 * Return the receive available interrupt name.
2090 */
2091static char *is_rcv_avail_name(char *buf, size_t bsize, unsigned int source)
2092{
2093 snprintf(buf, bsize, "RcvAvailInt%u", source);
2094 return buf;
2095}
2096
2097/*
2098 * Return the receive urgent interrupt name.
2099 */
2100static char *is_rcv_urgent_name(char *buf, size_t bsize, unsigned int source)
2101{
2102 snprintf(buf, bsize, "RcvUrgentInt%u", source);
2103 return buf;
2104}
2105
2106/*
2107 * Return the send credit interrupt name.
2108 */
2109static char *is_send_credit_name(char *buf, size_t bsize, unsigned int source)
2110{
2111 snprintf(buf, bsize, "SendCreditInt%u", source);
2112 return buf;
2113}
2114
2115/*
2116 * Return the reserved interrupt name.
2117 */
2118static char *is_reserved_name(char *buf, size_t bsize, unsigned int source)
2119{
2120 snprintf(buf, bsize, "Reserved%u", source + IS_RESERVED_START);
2121 return buf;
2122}
2123
2124static char *cce_err_status_string(char *buf, int buf_len, u64 flags)
2125{
2126 return flag_string(buf, buf_len, flags,
2127 cce_err_status_flags, ARRAY_SIZE(cce_err_status_flags));
2128}
2129
2130static char *rxe_err_status_string(char *buf, int buf_len, u64 flags)
2131{
2132 return flag_string(buf, buf_len, flags,
2133 rxe_err_status_flags, ARRAY_SIZE(rxe_err_status_flags));
2134}
2135
2136static char *misc_err_status_string(char *buf, int buf_len, u64 flags)
2137{
2138 return flag_string(buf, buf_len, flags, misc_err_status_flags,
2139 ARRAY_SIZE(misc_err_status_flags));
2140}
2141
2142static char *pio_err_status_string(char *buf, int buf_len, u64 flags)
2143{
2144 return flag_string(buf, buf_len, flags,
2145 pio_err_status_flags, ARRAY_SIZE(pio_err_status_flags));
2146}
2147
2148static char *sdma_err_status_string(char *buf, int buf_len, u64 flags)
2149{
2150 return flag_string(buf, buf_len, flags,
2151 sdma_err_status_flags,
2152 ARRAY_SIZE(sdma_err_status_flags));
2153}
2154
2155static char *egress_err_status_string(char *buf, int buf_len, u64 flags)
2156{
2157 return flag_string(buf, buf_len, flags,
2158 egress_err_status_flags, ARRAY_SIZE(egress_err_status_flags));
2159}
2160
2161static char *egress_err_info_string(char *buf, int buf_len, u64 flags)
2162{
2163 return flag_string(buf, buf_len, flags,
2164 egress_err_info_flags, ARRAY_SIZE(egress_err_info_flags));
2165}
2166
2167static char *send_err_status_string(char *buf, int buf_len, u64 flags)
2168{
2169 return flag_string(buf, buf_len, flags,
2170 send_err_status_flags,
2171 ARRAY_SIZE(send_err_status_flags));
2172}
2173
2174static void handle_cce_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
2175{
2176 char buf[96];
2177
2178 /*
2179 * For most these errors, there is nothing that can be done except
2180 * report or record it.
2181 */
2182 dd_dev_info(dd, "CCE Error: %s\n",
2183 cce_err_status_string(buf, sizeof(buf), reg));
2184
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05002185 if ((reg & CCE_ERR_STATUS_CCE_CLI2_ASYNC_FIFO_PARITY_ERR_SMASK) &&
2186 is_ax(dd) && (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04002187 /* this error requires a manual drop into SPC freeze mode */
2188 /* then a fix up */
2189 start_freeze_handling(dd->pport, FREEZE_SELF);
2190 }
2191}
2192
2193/*
2194 * Check counters for receive errors that do not have an interrupt
2195 * associated with them.
2196 */
2197#define RCVERR_CHECK_TIME 10
2198static void update_rcverr_timer(unsigned long opaque)
2199{
2200 struct hfi1_devdata *dd = (struct hfi1_devdata *)opaque;
2201 struct hfi1_pportdata *ppd = dd->pport;
2202 u32 cur_ovfl_cnt = read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL);
2203
2204 if (dd->rcv_ovfl_cnt < cur_ovfl_cnt &&
2205 ppd->port_error_action & OPA_PI_MASK_EX_BUFFER_OVERRUN) {
2206 dd_dev_info(dd, "%s: PortErrorAction bounce\n", __func__);
2207 set_link_down_reason(ppd,
2208 OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN, 0,
2209 OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN);
2210 queue_work(ppd->hfi1_wq, &ppd->link_bounce_work);
2211 }
2212 dd->rcv_ovfl_cnt = (u32) cur_ovfl_cnt;
2213
2214 mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
2215}
2216
2217static int init_rcverr(struct hfi1_devdata *dd)
2218{
Muhammad Falak R Wani24523a92015-10-25 16:13:23 +05302219 setup_timer(&dd->rcverr_timer, update_rcverr_timer, (unsigned long)dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04002220 /* Assume the hardware counter has been reset */
2221 dd->rcv_ovfl_cnt = 0;
2222 return mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
2223}
2224
2225static void free_rcverr(struct hfi1_devdata *dd)
2226{
2227 if (dd->rcverr_timer.data)
2228 del_timer_sync(&dd->rcverr_timer);
2229 dd->rcverr_timer.data = 0;
2230}
2231
2232static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
2233{
2234 char buf[96];
2235
2236 dd_dev_info(dd, "Receive Error: %s\n",
2237 rxe_err_status_string(buf, sizeof(buf), reg));
2238
2239 if (reg & ALL_RXE_FREEZE_ERR) {
2240 int flags = 0;
2241
2242 /*
2243 * Freeze mode recovery is disabled for the errors
2244 * in RXE_FREEZE_ABORT_MASK
2245 */
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05002246 if (is_ax(dd) && (reg & RXE_FREEZE_ABORT_MASK))
Mike Marciniszyn77241052015-07-30 15:17:43 -04002247 flags = FREEZE_ABORT;
2248
2249 start_freeze_handling(dd->pport, flags);
2250 }
2251}
2252
2253static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
2254{
2255 char buf[96];
2256
2257 dd_dev_info(dd, "Misc Error: %s",
2258 misc_err_status_string(buf, sizeof(buf), reg));
2259}
2260
2261static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
2262{
2263 char buf[96];
2264
2265 dd_dev_info(dd, "PIO Error: %s\n",
2266 pio_err_status_string(buf, sizeof(buf), reg));
2267
2268 if (reg & ALL_PIO_FREEZE_ERR)
2269 start_freeze_handling(dd->pport, 0);
2270}
2271
2272static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
2273{
2274 char buf[96];
2275
2276 dd_dev_info(dd, "SDMA Error: %s\n",
2277 sdma_err_status_string(buf, sizeof(buf), reg));
2278
2279 if (reg & ALL_SDMA_FREEZE_ERR)
2280 start_freeze_handling(dd->pport, 0);
2281}
2282
2283static void count_port_inactive(struct hfi1_devdata *dd)
2284{
2285 struct hfi1_pportdata *ppd = dd->pport;
2286
2287 if (ppd->port_xmit_discards < ~(u64)0)
2288 ppd->port_xmit_discards++;
2289}
2290
2291/*
2292 * We have had a "disallowed packet" error during egress. Determine the
2293 * integrity check which failed, and update relevant error counter, etc.
2294 *
2295 * Note that the SEND_EGRESS_ERR_INFO register has only a single
2296 * bit of state per integrity check, and so we can miss the reason for an
2297 * egress error if more than one packet fails the same integrity check
2298 * since we cleared the corresponding bit in SEND_EGRESS_ERR_INFO.
2299 */
2300static void handle_send_egress_err_info(struct hfi1_devdata *dd)
2301{
2302 struct hfi1_pportdata *ppd = dd->pport;
2303 u64 src = read_csr(dd, SEND_EGRESS_ERR_SOURCE); /* read first */
2304 u64 info = read_csr(dd, SEND_EGRESS_ERR_INFO);
2305 char buf[96];
2306
2307 /* clear down all observed info as quickly as possible after read */
2308 write_csr(dd, SEND_EGRESS_ERR_INFO, info);
2309
2310 dd_dev_info(dd,
2311 "Egress Error Info: 0x%llx, %s Egress Error Src 0x%llx\n",
2312 info, egress_err_info_string(buf, sizeof(buf), info), src);
2313
2314 /* Eventually add other counters for each bit */
2315
2316 if (info & SEND_EGRESS_ERR_INFO_TOO_LONG_IB_PACKET_ERR_SMASK) {
2317 if (ppd->port_xmit_discards < ~(u64)0)
2318 ppd->port_xmit_discards++;
2319 }
2320}
2321
2322/*
2323 * Input value is a bit position within the SEND_EGRESS_ERR_STATUS
2324 * register. Does it represent a 'port inactive' error?
2325 */
2326static inline int port_inactive_err(u64 posn)
2327{
2328 return (posn >= SEES(TX_LINKDOWN) &&
2329 posn <= SEES(TX_INCORRECT_LINK_STATE));
2330}
2331
2332/*
2333 * Input value is a bit position within the SEND_EGRESS_ERR_STATUS
2334 * register. Does it represent a 'disallowed packet' error?
2335 */
2336static inline int disallowed_pkt_err(u64 posn)
2337{
2338 return (posn >= SEES(TX_SDMA0_DISALLOWED_PACKET) &&
2339 posn <= SEES(TX_SDMA15_DISALLOWED_PACKET));
2340}
2341
2342static void handle_egress_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
2343{
2344 u64 reg_copy = reg, handled = 0;
2345 char buf[96];
2346
2347 if (reg & ALL_TXE_EGRESS_FREEZE_ERR)
2348 start_freeze_handling(dd->pport, 0);
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05002349 if (is_ax(dd) && (reg &
Mike Marciniszyn77241052015-07-30 15:17:43 -04002350 SEND_EGRESS_ERR_STATUS_TX_CREDIT_RETURN_VL_ERR_SMASK)
2351 && (dd->icode != ICODE_FUNCTIONAL_SIMULATOR))
2352 start_freeze_handling(dd->pport, 0);
2353
2354 while (reg_copy) {
2355 int posn = fls64(reg_copy);
2356 /*
2357 * fls64() returns a 1-based offset, but we generally
2358 * want 0-based offsets.
2359 */
2360 int shift = posn - 1;
2361
2362 if (port_inactive_err(shift)) {
2363 count_port_inactive(dd);
2364 handled |= (1ULL << shift);
2365 } else if (disallowed_pkt_err(shift)) {
2366 handle_send_egress_err_info(dd);
2367 handled |= (1ULL << shift);
2368 }
2369 clear_bit(shift, (unsigned long *)&reg_copy);
2370 }
2371
2372 reg &= ~handled;
2373
2374 if (reg)
2375 dd_dev_info(dd, "Egress Error: %s\n",
2376 egress_err_status_string(buf, sizeof(buf), reg));
2377}
2378
2379static void handle_txe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
2380{
2381 char buf[96];
2382
2383 dd_dev_info(dd, "Send Error: %s\n",
2384 send_err_status_string(buf, sizeof(buf), reg));
2385
2386}
2387
2388/*
2389 * The maximum number of times the error clear down will loop before
2390 * blocking a repeating error. This value is arbitrary.
2391 */
2392#define MAX_CLEAR_COUNT 20
2393
2394/*
2395 * Clear and handle an error register. All error interrupts are funneled
2396 * through here to have a central location to correctly handle single-
2397 * or multi-shot errors.
2398 *
2399 * For non per-context registers, call this routine with a context value
2400 * of 0 so the per-context offset is zero.
2401 *
2402 * If the handler loops too many times, assume that something is wrong
2403 * and can't be fixed, so mask the error bits.
2404 */
2405static void interrupt_clear_down(struct hfi1_devdata *dd,
2406 u32 context,
2407 const struct err_reg_info *eri)
2408{
2409 u64 reg;
2410 u32 count;
2411
2412 /* read in a loop until no more errors are seen */
2413 count = 0;
2414 while (1) {
2415 reg = read_kctxt_csr(dd, context, eri->status);
2416 if (reg == 0)
2417 break;
2418 write_kctxt_csr(dd, context, eri->clear, reg);
2419 if (likely(eri->handler))
2420 eri->handler(dd, context, reg);
2421 count++;
2422 if (count > MAX_CLEAR_COUNT) {
2423 u64 mask;
2424
2425 dd_dev_err(dd, "Repeating %s bits 0x%llx - masking\n",
2426 eri->desc, reg);
2427 /*
2428 * Read-modify-write so any other masked bits
2429 * remain masked.
2430 */
2431 mask = read_kctxt_csr(dd, context, eri->mask);
2432 mask &= ~reg;
2433 write_kctxt_csr(dd, context, eri->mask, mask);
2434 break;
2435 }
2436 }
2437}
2438
2439/*
2440 * CCE block "misc" interrupt. Source is < 16.
2441 */
2442static void is_misc_err_int(struct hfi1_devdata *dd, unsigned int source)
2443{
2444 const struct err_reg_info *eri = &misc_errs[source];
2445
2446 if (eri->handler) {
2447 interrupt_clear_down(dd, 0, eri);
2448 } else {
2449 dd_dev_err(dd, "Unexpected misc interrupt (%u) - reserved\n",
2450 source);
2451 }
2452}
2453
2454static char *send_context_err_status_string(char *buf, int buf_len, u64 flags)
2455{
2456 return flag_string(buf, buf_len, flags,
2457 sc_err_status_flags, ARRAY_SIZE(sc_err_status_flags));
2458}
2459
2460/*
2461 * Send context error interrupt. Source (hw_context) is < 160.
2462 *
2463 * All send context errors cause the send context to halt. The normal
2464 * clear-down mechanism cannot be used because we cannot clear the
2465 * error bits until several other long-running items are done first.
2466 * This is OK because with the context halted, nothing else is going
2467 * to happen on it anyway.
2468 */
2469static void is_sendctxt_err_int(struct hfi1_devdata *dd,
2470 unsigned int hw_context)
2471{
2472 struct send_context_info *sci;
2473 struct send_context *sc;
2474 char flags[96];
2475 u64 status;
2476 u32 sw_index;
2477
2478 sw_index = dd->hw_to_sw[hw_context];
2479 if (sw_index >= dd->num_send_contexts) {
2480 dd_dev_err(dd,
2481 "out of range sw index %u for send context %u\n",
2482 sw_index, hw_context);
2483 return;
2484 }
2485 sci = &dd->send_contexts[sw_index];
2486 sc = sci->sc;
2487 if (!sc) {
2488 dd_dev_err(dd, "%s: context %u(%u): no sc?\n", __func__,
2489 sw_index, hw_context);
2490 return;
2491 }
2492
2493 /* tell the software that a halt has begun */
2494 sc_stop(sc, SCF_HALTED);
2495
2496 status = read_kctxt_csr(dd, hw_context, SEND_CTXT_ERR_STATUS);
2497
2498 dd_dev_info(dd, "Send Context %u(%u) Error: %s\n", sw_index, hw_context,
2499 send_context_err_status_string(flags, sizeof(flags), status));
2500
2501 if (status & SEND_CTXT_ERR_STATUS_PIO_DISALLOWED_PACKET_ERR_SMASK)
2502 handle_send_egress_err_info(dd);
2503
2504 /*
2505 * Automatically restart halted kernel contexts out of interrupt
2506 * context. User contexts must ask the driver to restart the context.
2507 */
2508 if (sc->type != SC_USER)
2509 queue_work(dd->pport->hfi1_wq, &sc->halt_work);
2510}
2511
2512static void handle_sdma_eng_err(struct hfi1_devdata *dd,
2513 unsigned int source, u64 status)
2514{
2515 struct sdma_engine *sde;
2516
2517 sde = &dd->per_sdma[source];
2518#ifdef CONFIG_SDMA_VERBOSITY
2519 dd_dev_err(sde->dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
2520 slashstrip(__FILE__), __LINE__, __func__);
2521 dd_dev_err(sde->dd, "CONFIG SDMA(%u) source: %u status 0x%llx\n",
2522 sde->this_idx, source, (unsigned long long)status);
2523#endif
2524 sdma_engine_error(sde, status);
2525}
2526
2527/*
2528 * CCE block SDMA error interrupt. Source is < 16.
2529 */
2530static void is_sdma_eng_err_int(struct hfi1_devdata *dd, unsigned int source)
2531{
2532#ifdef CONFIG_SDMA_VERBOSITY
2533 struct sdma_engine *sde = &dd->per_sdma[source];
2534
2535 dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
2536 slashstrip(__FILE__), __LINE__, __func__);
2537 dd_dev_err(dd, "CONFIG SDMA(%u) source: %u\n", sde->this_idx,
2538 source);
2539 sdma_dumpstate(sde);
2540#endif
2541 interrupt_clear_down(dd, source, &sdma_eng_err);
2542}
2543
2544/*
2545 * CCE block "various" interrupt. Source is < 8.
2546 */
2547static void is_various_int(struct hfi1_devdata *dd, unsigned int source)
2548{
2549 const struct err_reg_info *eri = &various_err[source];
2550
2551 /*
2552 * TCritInt cannot go through interrupt_clear_down()
2553 * because it is not a second tier interrupt. The handler
2554 * should be called directly.
2555 */
2556 if (source == TCRIT_INT_SOURCE)
2557 handle_temp_err(dd);
2558 else if (eri->handler)
2559 interrupt_clear_down(dd, 0, eri);
2560 else
2561 dd_dev_info(dd,
2562 "%s: Unimplemented/reserved interrupt %d\n",
2563 __func__, source);
2564}
2565
2566static void handle_qsfp_int(struct hfi1_devdata *dd, u32 src_ctx, u64 reg)
2567{
2568 /* source is always zero */
2569 struct hfi1_pportdata *ppd = dd->pport;
2570 unsigned long flags;
2571 u64 qsfp_int_mgmt = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
2572
2573 if (reg & QSFP_HFI0_MODPRST_N) {
2574
2575 dd_dev_info(dd, "%s: ModPresent triggered QSFP interrupt\n",
2576 __func__);
2577
2578 if (!qsfp_mod_present(ppd)) {
2579 ppd->driver_link_ready = 0;
2580 /*
2581 * Cable removed, reset all our information about the
2582 * cache and cable capabilities
2583 */
2584
2585 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
2586 /*
2587 * We don't set cache_refresh_required here as we expect
2588 * an interrupt when a cable is inserted
2589 */
2590 ppd->qsfp_info.cache_valid = 0;
2591 ppd->qsfp_info.qsfp_interrupt_functional = 0;
2592 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
2593 flags);
2594 write_csr(dd,
2595 dd->hfi1_id ?
2596 ASIC_QSFP2_INVERT :
2597 ASIC_QSFP1_INVERT,
2598 qsfp_int_mgmt);
2599 if (ppd->host_link_state == HLS_DN_POLL) {
2600 /*
2601 * The link is still in POLL. This means
2602 * that the normal link down processing
2603 * will not happen. We have to do it here
2604 * before turning the DC off.
2605 */
2606 queue_work(ppd->hfi1_wq, &ppd->link_down_work);
2607 }
2608 } else {
2609 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
2610 ppd->qsfp_info.cache_valid = 0;
2611 ppd->qsfp_info.cache_refresh_required = 1;
2612 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
2613 flags);
2614
2615 qsfp_int_mgmt &= ~(u64)QSFP_HFI0_MODPRST_N;
2616 write_csr(dd,
2617 dd->hfi1_id ?
2618 ASIC_QSFP2_INVERT :
2619 ASIC_QSFP1_INVERT,
2620 qsfp_int_mgmt);
2621 }
2622 }
2623
2624 if (reg & QSFP_HFI0_INT_N) {
2625
2626 dd_dev_info(dd, "%s: IntN triggered QSFP interrupt\n",
2627 __func__);
2628 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
2629 ppd->qsfp_info.check_interrupt_flags = 1;
2630 ppd->qsfp_info.qsfp_interrupt_functional = 1;
2631 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, flags);
2632 }
2633
2634 /* Schedule the QSFP work only if there is a cable attached. */
2635 if (qsfp_mod_present(ppd))
2636 queue_work(ppd->hfi1_wq, &ppd->qsfp_info.qsfp_work);
2637}
2638
2639static int request_host_lcb_access(struct hfi1_devdata *dd)
2640{
2641 int ret;
2642
2643 ret = do_8051_command(dd, HCMD_MISC,
2644 (u64)HCMD_MISC_REQUEST_LCB_ACCESS << LOAD_DATA_FIELD_ID_SHIFT,
2645 NULL);
2646 if (ret != HCMD_SUCCESS) {
2647 dd_dev_err(dd, "%s: command failed with error %d\n",
2648 __func__, ret);
2649 }
2650 return ret == HCMD_SUCCESS ? 0 : -EBUSY;
2651}
2652
2653static int request_8051_lcb_access(struct hfi1_devdata *dd)
2654{
2655 int ret;
2656
2657 ret = do_8051_command(dd, HCMD_MISC,
2658 (u64)HCMD_MISC_GRANT_LCB_ACCESS << LOAD_DATA_FIELD_ID_SHIFT,
2659 NULL);
2660 if (ret != HCMD_SUCCESS) {
2661 dd_dev_err(dd, "%s: command failed with error %d\n",
2662 __func__, ret);
2663 }
2664 return ret == HCMD_SUCCESS ? 0 : -EBUSY;
2665}
2666
2667/*
2668 * Set the LCB selector - allow host access. The DCC selector always
2669 * points to the host.
2670 */
2671static inline void set_host_lcb_access(struct hfi1_devdata *dd)
2672{
2673 write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
2674 DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK
2675 | DC_DC8051_CFG_CSR_ACCESS_SEL_LCB_SMASK);
2676}
2677
2678/*
2679 * Clear the LCB selector - allow 8051 access. The DCC selector always
2680 * points to the host.
2681 */
2682static inline void set_8051_lcb_access(struct hfi1_devdata *dd)
2683{
2684 write_csr(dd, DC_DC8051_CFG_CSR_ACCESS_SEL,
2685 DC_DC8051_CFG_CSR_ACCESS_SEL_DCC_SMASK);
2686}
2687
2688/*
2689 * Acquire LCB access from the 8051. If the host already has access,
2690 * just increment a counter. Otherwise, inform the 8051 that the
2691 * host is taking access.
2692 *
2693 * Returns:
2694 * 0 on success
2695 * -EBUSY if the 8051 has control and cannot be disturbed
2696 * -errno if unable to acquire access from the 8051
2697 */
2698int acquire_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
2699{
2700 struct hfi1_pportdata *ppd = dd->pport;
2701 int ret = 0;
2702
2703 /*
2704 * Use the host link state lock so the operation of this routine
2705 * { link state check, selector change, count increment } can occur
2706 * as a unit against a link state change. Otherwise there is a
2707 * race between the state change and the count increment.
2708 */
2709 if (sleep_ok) {
2710 mutex_lock(&ppd->hls_lock);
2711 } else {
Dan Carpenter951842b2015-09-16 09:22:51 +03002712 while (!mutex_trylock(&ppd->hls_lock))
Mike Marciniszyn77241052015-07-30 15:17:43 -04002713 udelay(1);
2714 }
2715
2716 /* this access is valid only when the link is up */
2717 if ((ppd->host_link_state & HLS_UP) == 0) {
2718 dd_dev_info(dd, "%s: link state %s not up\n",
2719 __func__, link_state_name(ppd->host_link_state));
2720 ret = -EBUSY;
2721 goto done;
2722 }
2723
2724 if (dd->lcb_access_count == 0) {
2725 ret = request_host_lcb_access(dd);
2726 if (ret) {
2727 dd_dev_err(dd,
2728 "%s: unable to acquire LCB access, err %d\n",
2729 __func__, ret);
2730 goto done;
2731 }
2732 set_host_lcb_access(dd);
2733 }
2734 dd->lcb_access_count++;
2735done:
2736 mutex_unlock(&ppd->hls_lock);
2737 return ret;
2738}
2739
2740/*
2741 * Release LCB access by decrementing the use count. If the count is moving
2742 * from 1 to 0, inform 8051 that it has control back.
2743 *
2744 * Returns:
2745 * 0 on success
2746 * -errno if unable to release access to the 8051
2747 */
2748int release_lcb_access(struct hfi1_devdata *dd, int sleep_ok)
2749{
2750 int ret = 0;
2751
2752 /*
2753 * Use the host link state lock because the acquire needed it.
2754 * Here, we only need to keep { selector change, count decrement }
2755 * as a unit.
2756 */
2757 if (sleep_ok) {
2758 mutex_lock(&dd->pport->hls_lock);
2759 } else {
Dan Carpenter951842b2015-09-16 09:22:51 +03002760 while (!mutex_trylock(&dd->pport->hls_lock))
Mike Marciniszyn77241052015-07-30 15:17:43 -04002761 udelay(1);
2762 }
2763
2764 if (dd->lcb_access_count == 0) {
2765 dd_dev_err(dd, "%s: LCB access count is zero. Skipping.\n",
2766 __func__);
2767 goto done;
2768 }
2769
2770 if (dd->lcb_access_count == 1) {
2771 set_8051_lcb_access(dd);
2772 ret = request_8051_lcb_access(dd);
2773 if (ret) {
2774 dd_dev_err(dd,
2775 "%s: unable to release LCB access, err %d\n",
2776 __func__, ret);
2777 /* restore host access if the grant didn't work */
2778 set_host_lcb_access(dd);
2779 goto done;
2780 }
2781 }
2782 dd->lcb_access_count--;
2783done:
2784 mutex_unlock(&dd->pport->hls_lock);
2785 return ret;
2786}
2787
2788/*
2789 * Initialize LCB access variables and state. Called during driver load,
2790 * after most of the initialization is finished.
2791 *
2792 * The DC default is LCB access on for the host. The driver defaults to
2793 * leaving access to the 8051. Assign access now - this constrains the call
2794 * to this routine to be after all LCB set-up is done. In particular, after
2795 * hf1_init_dd() -> set_up_interrupts() -> clear_all_interrupts()
2796 */
2797static void init_lcb_access(struct hfi1_devdata *dd)
2798{
2799 dd->lcb_access_count = 0;
2800}
2801
2802/*
2803 * Write a response back to a 8051 request.
2804 */
2805static void hreq_response(struct hfi1_devdata *dd, u8 return_code, u16 rsp_data)
2806{
2807 write_csr(dd, DC_DC8051_CFG_EXT_DEV_0,
2808 DC_DC8051_CFG_EXT_DEV_0_COMPLETED_SMASK
2809 | (u64)return_code << DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT
2810 | (u64)rsp_data << DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
2811}
2812
2813/*
2814 * Handle requests from the 8051.
2815 */
2816static void handle_8051_request(struct hfi1_devdata *dd)
2817{
2818 u64 reg;
2819 u16 data;
2820 u8 type;
2821
2822 reg = read_csr(dd, DC_DC8051_CFG_EXT_DEV_1);
2823 if ((reg & DC_DC8051_CFG_EXT_DEV_1_REQ_NEW_SMASK) == 0)
2824 return; /* no request */
2825
2826 /* zero out COMPLETED so the response is seen */
2827 write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, 0);
2828
2829 /* extract request details */
2830 type = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_SHIFT)
2831 & DC_DC8051_CFG_EXT_DEV_1_REQ_TYPE_MASK;
2832 data = (reg >> DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT)
2833 & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_MASK;
2834
2835 switch (type) {
2836 case HREQ_LOAD_CONFIG:
2837 case HREQ_SAVE_CONFIG:
2838 case HREQ_READ_CONFIG:
2839 case HREQ_SET_TX_EQ_ABS:
2840 case HREQ_SET_TX_EQ_REL:
2841 case HREQ_ENABLE:
2842 dd_dev_info(dd, "8051 request: request 0x%x not supported\n",
2843 type);
2844 hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
2845 break;
2846
2847 case HREQ_CONFIG_DONE:
2848 hreq_response(dd, HREQ_SUCCESS, 0);
2849 break;
2850
2851 case HREQ_INTERFACE_TEST:
2852 hreq_response(dd, HREQ_SUCCESS, data);
2853 break;
2854
2855 default:
2856 dd_dev_err(dd, "8051 request: unknown request 0x%x\n", type);
2857 hreq_response(dd, HREQ_NOT_SUPPORTED, 0);
2858 break;
2859 }
2860}
2861
2862static void write_global_credit(struct hfi1_devdata *dd,
2863 u8 vau, u16 total, u16 shared)
2864{
2865 write_csr(dd, SEND_CM_GLOBAL_CREDIT,
2866 ((u64)total
2867 << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT)
2868 | ((u64)shared
2869 << SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT)
2870 | ((u64)vau << SEND_CM_GLOBAL_CREDIT_AU_SHIFT));
2871}
2872
2873/*
2874 * Set up initial VL15 credits of the remote. Assumes the rest of
2875 * the CM credit registers are zero from a previous global or credit reset .
2876 */
2877void set_up_vl15(struct hfi1_devdata *dd, u8 vau, u16 vl15buf)
2878{
2879 /* leave shared count at zero for both global and VL15 */
2880 write_global_credit(dd, vau, vl15buf, 0);
2881
2882 /* We may need some credits for another VL when sending packets
2883 * with the snoop interface. Dividing it down the middle for VL15
2884 * and VL0 should suffice.
2885 */
2886 if (unlikely(dd->hfi1_snoop.mode_flag == HFI1_PORT_SNOOP_MODE)) {
2887 write_csr(dd, SEND_CM_CREDIT_VL15, (u64)(vl15buf >> 1)
2888 << SEND_CM_CREDIT_VL15_DEDICATED_LIMIT_VL_SHIFT);
2889 write_csr(dd, SEND_CM_CREDIT_VL, (u64)(vl15buf >> 1)
2890 << SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT);
2891 } else {
2892 write_csr(dd, SEND_CM_CREDIT_VL15, (u64)vl15buf
2893 << SEND_CM_CREDIT_VL15_DEDICATED_LIMIT_VL_SHIFT);
2894 }
2895}
2896
2897/*
2898 * Zero all credit details from the previous connection and
2899 * reset the CM manager's internal counters.
2900 */
2901void reset_link_credits(struct hfi1_devdata *dd)
2902{
2903 int i;
2904
2905 /* remove all previous VL credit limits */
2906 for (i = 0; i < TXE_NUM_DATA_VL; i++)
2907 write_csr(dd, SEND_CM_CREDIT_VL + (8*i), 0);
2908 write_csr(dd, SEND_CM_CREDIT_VL15, 0);
2909 write_global_credit(dd, 0, 0, 0);
2910 /* reset the CM block */
2911 pio_send_control(dd, PSC_CM_RESET);
2912}
2913
2914/* convert a vCU to a CU */
2915static u32 vcu_to_cu(u8 vcu)
2916{
2917 return 1 << vcu;
2918}
2919
2920/* convert a CU to a vCU */
2921static u8 cu_to_vcu(u32 cu)
2922{
2923 return ilog2(cu);
2924}
2925
2926/* convert a vAU to an AU */
2927static u32 vau_to_au(u8 vau)
2928{
2929 return 8 * (1 << vau);
2930}
2931
2932static void set_linkup_defaults(struct hfi1_pportdata *ppd)
2933{
2934 ppd->sm_trap_qp = 0x0;
2935 ppd->sa_qp = 0x1;
2936}
2937
2938/*
2939 * Graceful LCB shutdown. This leaves the LCB FIFOs in reset.
2940 */
2941static void lcb_shutdown(struct hfi1_devdata *dd, int abort)
2942{
2943 u64 reg;
2944
2945 /* clear lcb run: LCB_CFG_RUN.EN = 0 */
2946 write_csr(dd, DC_LCB_CFG_RUN, 0);
2947 /* set tx fifo reset: LCB_CFG_TX_FIFOS_RESET.VAL = 1 */
2948 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET,
2949 1ull << DC_LCB_CFG_TX_FIFOS_RESET_VAL_SHIFT);
2950 /* set dcc reset csr: DCC_CFG_RESET.{reset_lcb,reset_rx_fpe} = 1 */
2951 dd->lcb_err_en = read_csr(dd, DC_LCB_ERR_EN);
2952 reg = read_csr(dd, DCC_CFG_RESET);
2953 write_csr(dd, DCC_CFG_RESET,
2954 reg
2955 | (1ull << DCC_CFG_RESET_RESET_LCB_SHIFT)
2956 | (1ull << DCC_CFG_RESET_RESET_RX_FPE_SHIFT));
2957 (void) read_csr(dd, DCC_CFG_RESET); /* make sure the write completed */
2958 if (!abort) {
2959 udelay(1); /* must hold for the longer of 16cclks or 20ns */
2960 write_csr(dd, DCC_CFG_RESET, reg);
2961 write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
2962 }
2963}
2964
2965/*
2966 * This routine should be called after the link has been transitioned to
2967 * OFFLINE (OFFLINE state has the side effect of putting the SerDes into
2968 * reset).
2969 *
2970 * The expectation is that the caller of this routine would have taken
2971 * care of properly transitioning the link into the correct state.
2972 */
2973static void dc_shutdown(struct hfi1_devdata *dd)
2974{
2975 unsigned long flags;
2976
2977 spin_lock_irqsave(&dd->dc8051_lock, flags);
2978 if (dd->dc_shutdown) {
2979 spin_unlock_irqrestore(&dd->dc8051_lock, flags);
2980 return;
2981 }
2982 dd->dc_shutdown = 1;
2983 spin_unlock_irqrestore(&dd->dc8051_lock, flags);
2984 /* Shutdown the LCB */
2985 lcb_shutdown(dd, 1);
2986 /* Going to OFFLINE would have causes the 8051 to put the
2987 * SerDes into reset already. Just need to shut down the 8051,
2988 * itself. */
2989 write_csr(dd, DC_DC8051_CFG_RST, 0x1);
2990}
2991
2992/* Calling this after the DC has been brought out of reset should not
2993 * do any damage. */
2994static void dc_start(struct hfi1_devdata *dd)
2995{
2996 unsigned long flags;
2997 int ret;
2998
2999 spin_lock_irqsave(&dd->dc8051_lock, flags);
3000 if (!dd->dc_shutdown)
3001 goto done;
3002 spin_unlock_irqrestore(&dd->dc8051_lock, flags);
3003 /* Take the 8051 out of reset */
3004 write_csr(dd, DC_DC8051_CFG_RST, 0ull);
3005 /* Wait until 8051 is ready */
3006 ret = wait_fm_ready(dd, TIMEOUT_8051_START);
3007 if (ret) {
3008 dd_dev_err(dd, "%s: timeout starting 8051 firmware\n",
3009 __func__);
3010 }
3011 /* Take away reset for LCB and RX FPE (set in lcb_shutdown). */
3012 write_csr(dd, DCC_CFG_RESET, 0x10);
3013 /* lcb_shutdown() with abort=1 does not restore these */
3014 write_csr(dd, DC_LCB_ERR_EN, dd->lcb_err_en);
3015 spin_lock_irqsave(&dd->dc8051_lock, flags);
3016 dd->dc_shutdown = 0;
3017done:
3018 spin_unlock_irqrestore(&dd->dc8051_lock, flags);
3019}
3020
3021/*
3022 * These LCB adjustments are for the Aurora SerDes core in the FPGA.
3023 */
3024static void adjust_lcb_for_fpga_serdes(struct hfi1_devdata *dd)
3025{
3026 u64 rx_radr, tx_radr;
3027 u32 version;
3028
3029 if (dd->icode != ICODE_FPGA_EMULATION)
3030 return;
3031
3032 /*
3033 * These LCB defaults on emulator _s are good, nothing to do here:
3034 * LCB_CFG_TX_FIFOS_RADR
3035 * LCB_CFG_RX_FIFOS_RADR
3036 * LCB_CFG_LN_DCLK
3037 * LCB_CFG_IGNORE_LOST_RCLK
3038 */
3039 if (is_emulator_s(dd))
3040 return;
3041 /* else this is _p */
3042
3043 version = emulator_rev(dd);
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05003044 if (!is_ax(dd))
Mike Marciniszyn77241052015-07-30 15:17:43 -04003045 version = 0x2d; /* all B0 use 0x2d or higher settings */
3046
3047 if (version <= 0x12) {
3048 /* release 0x12 and below */
3049
3050 /*
3051 * LCB_CFG_RX_FIFOS_RADR.RST_VAL = 0x9
3052 * LCB_CFG_RX_FIFOS_RADR.OK_TO_JUMP_VAL = 0x9
3053 * LCB_CFG_RX_FIFOS_RADR.DO_NOT_JUMP_VAL = 0xa
3054 */
3055 rx_radr =
3056 0xaull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
3057 | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
3058 | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
3059 /*
3060 * LCB_CFG_TX_FIFOS_RADR.ON_REINIT = 0 (default)
3061 * LCB_CFG_TX_FIFOS_RADR.RST_VAL = 6
3062 */
3063 tx_radr = 6ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
3064 } else if (version <= 0x18) {
3065 /* release 0x13 up to 0x18 */
3066 /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
3067 rx_radr =
3068 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
3069 | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
3070 | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
3071 tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
3072 } else if (version == 0x19) {
3073 /* release 0x19 */
3074 /* LCB_CFG_RX_FIFOS_RADR = 0xa99 */
3075 rx_radr =
3076 0xAull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
3077 | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
3078 | 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
3079 tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
3080 } else if (version == 0x1a) {
3081 /* release 0x1a */
3082 /* LCB_CFG_RX_FIFOS_RADR = 0x988 */
3083 rx_radr =
3084 0x9ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
3085 | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
3086 | 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
3087 tx_radr = 7ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
3088 write_csr(dd, DC_LCB_CFG_LN_DCLK, 1ull);
3089 } else {
3090 /* release 0x1b and higher */
3091 /* LCB_CFG_RX_FIFOS_RADR = 0x877 */
3092 rx_radr =
3093 0x8ull << DC_LCB_CFG_RX_FIFOS_RADR_DO_NOT_JUMP_VAL_SHIFT
3094 | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_OK_TO_JUMP_VAL_SHIFT
3095 | 0x7ull << DC_LCB_CFG_RX_FIFOS_RADR_RST_VAL_SHIFT;
3096 tx_radr = 3ull << DC_LCB_CFG_TX_FIFOS_RADR_RST_VAL_SHIFT;
3097 }
3098
3099 write_csr(dd, DC_LCB_CFG_RX_FIFOS_RADR, rx_radr);
3100 /* LCB_CFG_IGNORE_LOST_RCLK.EN = 1 */
3101 write_csr(dd, DC_LCB_CFG_IGNORE_LOST_RCLK,
3102 DC_LCB_CFG_IGNORE_LOST_RCLK_EN_SMASK);
3103 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RADR, tx_radr);
3104}
3105
3106/*
3107 * Handle a SMA idle message
3108 *
3109 * This is a work-queue function outside of the interrupt.
3110 */
3111void handle_sma_message(struct work_struct *work)
3112{
3113 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
3114 sma_message_work);
3115 struct hfi1_devdata *dd = ppd->dd;
3116 u64 msg;
3117 int ret;
3118
3119 /* msg is bytes 1-4 of the 40-bit idle message - the command code
3120 is stripped off */
3121 ret = read_idle_sma(dd, &msg);
3122 if (ret)
3123 return;
3124 dd_dev_info(dd, "%s: SMA message 0x%llx\n", __func__, msg);
3125 /*
3126 * React to the SMA message. Byte[1] (0 for us) is the command.
3127 */
3128 switch (msg & 0xff) {
3129 case SMA_IDLE_ARM:
3130 /*
3131 * See OPAv1 table 9-14 - HFI and External Switch Ports Key
3132 * State Transitions
3133 *
3134 * Only expected in INIT or ARMED, discard otherwise.
3135 */
3136 if (ppd->host_link_state & (HLS_UP_INIT | HLS_UP_ARMED))
3137 ppd->neighbor_normal = 1;
3138 break;
3139 case SMA_IDLE_ACTIVE:
3140 /*
3141 * See OPAv1 table 9-14 - HFI and External Switch Ports Key
3142 * State Transitions
3143 *
3144 * Can activate the node. Discard otherwise.
3145 */
3146 if (ppd->host_link_state == HLS_UP_ARMED
3147 && ppd->is_active_optimize_enabled) {
3148 ppd->neighbor_normal = 1;
3149 ret = set_link_state(ppd, HLS_UP_ACTIVE);
3150 if (ret)
3151 dd_dev_err(
3152 dd,
3153 "%s: received Active SMA idle message, couldn't set link to Active\n",
3154 __func__);
3155 }
3156 break;
3157 default:
3158 dd_dev_err(dd,
3159 "%s: received unexpected SMA idle message 0x%llx\n",
3160 __func__, msg);
3161 break;
3162 }
3163}
3164
3165static void adjust_rcvctrl(struct hfi1_devdata *dd, u64 add, u64 clear)
3166{
3167 u64 rcvctrl;
3168 unsigned long flags;
3169
3170 spin_lock_irqsave(&dd->rcvctrl_lock, flags);
3171 rcvctrl = read_csr(dd, RCV_CTRL);
3172 rcvctrl |= add;
3173 rcvctrl &= ~clear;
3174 write_csr(dd, RCV_CTRL, rcvctrl);
3175 spin_unlock_irqrestore(&dd->rcvctrl_lock, flags);
3176}
3177
3178static inline void add_rcvctrl(struct hfi1_devdata *dd, u64 add)
3179{
3180 adjust_rcvctrl(dd, add, 0);
3181}
3182
3183static inline void clear_rcvctrl(struct hfi1_devdata *dd, u64 clear)
3184{
3185 adjust_rcvctrl(dd, 0, clear);
3186}
3187
3188/*
3189 * Called from all interrupt handlers to start handling an SPC freeze.
3190 */
3191void start_freeze_handling(struct hfi1_pportdata *ppd, int flags)
3192{
3193 struct hfi1_devdata *dd = ppd->dd;
3194 struct send_context *sc;
3195 int i;
3196
3197 if (flags & FREEZE_SELF)
3198 write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
3199
3200 /* enter frozen mode */
3201 dd->flags |= HFI1_FROZEN;
3202
3203 /* notify all SDMA engines that they are going into a freeze */
3204 sdma_freeze_notify(dd, !!(flags & FREEZE_LINK_DOWN));
3205
3206 /* do halt pre-handling on all enabled send contexts */
3207 for (i = 0; i < dd->num_send_contexts; i++) {
3208 sc = dd->send_contexts[i].sc;
3209 if (sc && (sc->flags & SCF_ENABLED))
3210 sc_stop(sc, SCF_FROZEN | SCF_HALTED);
3211 }
3212
3213 /* Send context are frozen. Notify user space */
3214 hfi1_set_uevent_bits(ppd, _HFI1_EVENT_FROZEN_BIT);
3215
3216 if (flags & FREEZE_ABORT) {
3217 dd_dev_err(dd,
3218 "Aborted freeze recovery. Please REBOOT system\n");
3219 return;
3220 }
3221 /* queue non-interrupt handler */
3222 queue_work(ppd->hfi1_wq, &ppd->freeze_work);
3223}
3224
3225/*
3226 * Wait until all 4 sub-blocks indicate that they have frozen or unfrozen,
3227 * depending on the "freeze" parameter.
3228 *
3229 * No need to return an error if it times out, our only option
3230 * is to proceed anyway.
3231 */
3232static void wait_for_freeze_status(struct hfi1_devdata *dd, int freeze)
3233{
3234 unsigned long timeout;
3235 u64 reg;
3236
3237 timeout = jiffies + msecs_to_jiffies(FREEZE_STATUS_TIMEOUT);
3238 while (1) {
3239 reg = read_csr(dd, CCE_STATUS);
3240 if (freeze) {
3241 /* waiting until all indicators are set */
3242 if ((reg & ALL_FROZE) == ALL_FROZE)
3243 return; /* all done */
3244 } else {
3245 /* waiting until all indicators are clear */
3246 if ((reg & ALL_FROZE) == 0)
3247 return; /* all done */
3248 }
3249
3250 if (time_after(jiffies, timeout)) {
3251 dd_dev_err(dd,
3252 "Time out waiting for SPC %sfreeze, bits 0x%llx, expecting 0x%llx, continuing",
3253 freeze ? "" : "un",
3254 reg & ALL_FROZE,
3255 freeze ? ALL_FROZE : 0ull);
3256 return;
3257 }
3258 usleep_range(80, 120);
3259 }
3260}
3261
3262/*
3263 * Do all freeze handling for the RXE block.
3264 */
3265static void rxe_freeze(struct hfi1_devdata *dd)
3266{
3267 int i;
3268
3269 /* disable port */
3270 clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
3271
3272 /* disable all receive contexts */
3273 for (i = 0; i < dd->num_rcv_contexts; i++)
3274 hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_DIS, i);
3275}
3276
3277/*
3278 * Unfreeze handling for the RXE block - kernel contexts only.
3279 * This will also enable the port. User contexts will do unfreeze
3280 * handling on a per-context basis as they call into the driver.
3281 *
3282 */
3283static void rxe_kernel_unfreeze(struct hfi1_devdata *dd)
3284{
3285 int i;
3286
3287 /* enable all kernel contexts */
3288 for (i = 0; i < dd->n_krcv_queues; i++)
3289 hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_ENB, i);
3290
3291 /* enable port */
3292 add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
3293}
3294
3295/*
3296 * Non-interrupt SPC freeze handling.
3297 *
3298 * This is a work-queue function outside of the triggering interrupt.
3299 */
3300void handle_freeze(struct work_struct *work)
3301{
3302 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
3303 freeze_work);
3304 struct hfi1_devdata *dd = ppd->dd;
3305
3306 /* wait for freeze indicators on all affected blocks */
3307 dd_dev_info(dd, "Entering SPC freeze\n");
3308 wait_for_freeze_status(dd, 1);
3309
3310 /* SPC is now frozen */
3311
3312 /* do send PIO freeze steps */
3313 pio_freeze(dd);
3314
3315 /* do send DMA freeze steps */
3316 sdma_freeze(dd);
3317
3318 /* do send egress freeze steps - nothing to do */
3319
3320 /* do receive freeze steps */
3321 rxe_freeze(dd);
3322
3323 /*
3324 * Unfreeze the hardware - clear the freeze, wait for each
3325 * block's frozen bit to clear, then clear the frozen flag.
3326 */
3327 write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
3328 wait_for_freeze_status(dd, 0);
3329
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05003330 if (is_ax(dd)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04003331 write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_FREEZE_SMASK);
3332 wait_for_freeze_status(dd, 1);
3333 write_csr(dd, CCE_CTRL, CCE_CTRL_SPC_UNFREEZE_SMASK);
3334 wait_for_freeze_status(dd, 0);
3335 }
3336
3337 /* do send PIO unfreeze steps for kernel contexts */
3338 pio_kernel_unfreeze(dd);
3339
3340 /* do send DMA unfreeze steps */
3341 sdma_unfreeze(dd);
3342
3343 /* do send egress unfreeze steps - nothing to do */
3344
3345 /* do receive unfreeze steps for kernel contexts */
3346 rxe_kernel_unfreeze(dd);
3347
3348 /*
3349 * The unfreeze procedure touches global device registers when
3350 * it disables and re-enables RXE. Mark the device unfrozen
3351 * after all that is done so other parts of the driver waiting
3352 * for the device to unfreeze don't do things out of order.
3353 *
3354 * The above implies that the meaning of HFI1_FROZEN flag is
3355 * "Device has gone into freeze mode and freeze mode handling
3356 * is still in progress."
3357 *
3358 * The flag will be removed when freeze mode processing has
3359 * completed.
3360 */
3361 dd->flags &= ~HFI1_FROZEN;
3362 wake_up(&dd->event_queue);
3363
3364 /* no longer frozen */
3365 dd_dev_err(dd, "Exiting SPC freeze\n");
3366}
3367
3368/*
3369 * Handle a link up interrupt from the 8051.
3370 *
3371 * This is a work-queue function outside of the interrupt.
3372 */
3373void handle_link_up(struct work_struct *work)
3374{
3375 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
3376 link_up_work);
3377 set_link_state(ppd, HLS_UP_INIT);
3378
3379 /* cache the read of DC_LCB_STS_ROUND_TRIP_LTP_CNT */
3380 read_ltp_rtt(ppd->dd);
3381 /*
3382 * OPA specifies that certain counters are cleared on a transition
3383 * to link up, so do that.
3384 */
3385 clear_linkup_counters(ppd->dd);
3386 /*
3387 * And (re)set link up default values.
3388 */
3389 set_linkup_defaults(ppd);
3390
3391 /* enforce link speed enabled */
3392 if ((ppd->link_speed_active & ppd->link_speed_enabled) == 0) {
3393 /* oops - current speed is not enabled, bounce */
3394 dd_dev_err(ppd->dd,
3395 "Link speed active 0x%x is outside enabled 0x%x, downing link\n",
3396 ppd->link_speed_active, ppd->link_speed_enabled);
3397 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SPEED_POLICY, 0,
3398 OPA_LINKDOWN_REASON_SPEED_POLICY);
3399 set_link_state(ppd, HLS_DN_OFFLINE);
3400 start_link(ppd);
3401 }
3402}
3403
3404/* Several pieces of LNI information were cached for SMA in ppd.
3405 * Reset these on link down */
3406static void reset_neighbor_info(struct hfi1_pportdata *ppd)
3407{
3408 ppd->neighbor_guid = 0;
3409 ppd->neighbor_port_number = 0;
3410 ppd->neighbor_type = 0;
3411 ppd->neighbor_fm_security = 0;
3412}
3413
3414/*
3415 * Handle a link down interrupt from the 8051.
3416 *
3417 * This is a work-queue function outside of the interrupt.
3418 */
3419void handle_link_down(struct work_struct *work)
3420{
3421 u8 lcl_reason, neigh_reason = 0;
3422 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
3423 link_down_work);
3424
3425 /* go offline first, then deal with reasons */
3426 set_link_state(ppd, HLS_DN_OFFLINE);
3427
3428 lcl_reason = 0;
3429 read_planned_down_reason_code(ppd->dd, &neigh_reason);
3430
3431 /*
3432 * If no reason, assume peer-initiated but missed
3433 * LinkGoingDown idle flits.
3434 */
3435 if (neigh_reason == 0)
3436 lcl_reason = OPA_LINKDOWN_REASON_NEIGHBOR_UNKNOWN;
3437
3438 set_link_down_reason(ppd, lcl_reason, neigh_reason, 0);
3439
3440 reset_neighbor_info(ppd);
3441
3442 /* disable the port */
3443 clear_rcvctrl(ppd->dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
3444
3445 /* If there is no cable attached, turn the DC off. Otherwise,
3446 * start the link bring up. */
3447 if (!qsfp_mod_present(ppd))
3448 dc_shutdown(ppd->dd);
3449 else
3450 start_link(ppd);
3451}
3452
3453void handle_link_bounce(struct work_struct *work)
3454{
3455 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
3456 link_bounce_work);
3457
3458 /*
3459 * Only do something if the link is currently up.
3460 */
3461 if (ppd->host_link_state & HLS_UP) {
3462 set_link_state(ppd, HLS_DN_OFFLINE);
3463 start_link(ppd);
3464 } else {
3465 dd_dev_info(ppd->dd, "%s: link not up (%s), nothing to do\n",
3466 __func__, link_state_name(ppd->host_link_state));
3467 }
3468}
3469
3470/*
3471 * Mask conversion: Capability exchange to Port LTP. The capability
3472 * exchange has an implicit 16b CRC that is mandatory.
3473 */
3474static int cap_to_port_ltp(int cap)
3475{
3476 int port_ltp = PORT_LTP_CRC_MODE_16; /* this mode is mandatory */
3477
3478 if (cap & CAP_CRC_14B)
3479 port_ltp |= PORT_LTP_CRC_MODE_14;
3480 if (cap & CAP_CRC_48B)
3481 port_ltp |= PORT_LTP_CRC_MODE_48;
3482 if (cap & CAP_CRC_12B_16B_PER_LANE)
3483 port_ltp |= PORT_LTP_CRC_MODE_PER_LANE;
3484
3485 return port_ltp;
3486}
3487
3488/*
3489 * Convert an OPA Port LTP mask to capability mask
3490 */
3491int port_ltp_to_cap(int port_ltp)
3492{
3493 int cap_mask = 0;
3494
3495 if (port_ltp & PORT_LTP_CRC_MODE_14)
3496 cap_mask |= CAP_CRC_14B;
3497 if (port_ltp & PORT_LTP_CRC_MODE_48)
3498 cap_mask |= CAP_CRC_48B;
3499 if (port_ltp & PORT_LTP_CRC_MODE_PER_LANE)
3500 cap_mask |= CAP_CRC_12B_16B_PER_LANE;
3501
3502 return cap_mask;
3503}
3504
3505/*
3506 * Convert a single DC LCB CRC mode to an OPA Port LTP mask.
3507 */
3508static int lcb_to_port_ltp(int lcb_crc)
3509{
3510 int port_ltp = 0;
3511
3512 if (lcb_crc == LCB_CRC_12B_16B_PER_LANE)
3513 port_ltp = PORT_LTP_CRC_MODE_PER_LANE;
3514 else if (lcb_crc == LCB_CRC_48B)
3515 port_ltp = PORT_LTP_CRC_MODE_48;
3516 else if (lcb_crc == LCB_CRC_14B)
3517 port_ltp = PORT_LTP_CRC_MODE_14;
3518 else
3519 port_ltp = PORT_LTP_CRC_MODE_16;
3520
3521 return port_ltp;
3522}
3523
3524/*
3525 * Our neighbor has indicated that we are allowed to act as a fabric
3526 * manager, so place the full management partition key in the second
3527 * (0-based) pkey array position (see OPAv1, section 20.2.2.6.8). Note
3528 * that we should already have the limited management partition key in
3529 * array element 1, and also that the port is not yet up when
3530 * add_full_mgmt_pkey() is invoked.
3531 */
3532static void add_full_mgmt_pkey(struct hfi1_pportdata *ppd)
3533{
3534 struct hfi1_devdata *dd = ppd->dd;
3535
3536 /* Sanity check - ppd->pkeys[2] should be 0 */
3537 if (ppd->pkeys[2] != 0)
3538 dd_dev_err(dd, "%s pkey[2] already set to 0x%x, resetting it to 0x%x\n",
3539 __func__, ppd->pkeys[2], FULL_MGMT_P_KEY);
3540 ppd->pkeys[2] = FULL_MGMT_P_KEY;
3541 (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
3542}
3543
3544/*
3545 * Convert the given link width to the OPA link width bitmask.
3546 */
3547static u16 link_width_to_bits(struct hfi1_devdata *dd, u16 width)
3548{
3549 switch (width) {
3550 case 0:
3551 /*
3552 * Simulator and quick linkup do not set the width.
3553 * Just set it to 4x without complaint.
3554 */
3555 if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR || quick_linkup)
3556 return OPA_LINK_WIDTH_4X;
3557 return 0; /* no lanes up */
3558 case 1: return OPA_LINK_WIDTH_1X;
3559 case 2: return OPA_LINK_WIDTH_2X;
3560 case 3: return OPA_LINK_WIDTH_3X;
3561 default:
3562 dd_dev_info(dd, "%s: invalid width %d, using 4\n",
3563 __func__, width);
3564 /* fall through */
3565 case 4: return OPA_LINK_WIDTH_4X;
3566 }
3567}
3568
3569/*
3570 * Do a population count on the bottom nibble.
3571 */
3572static const u8 bit_counts[16] = {
3573 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
3574};
3575static inline u8 nibble_to_count(u8 nibble)
3576{
3577 return bit_counts[nibble & 0xf];
3578}
3579
3580/*
3581 * Read the active lane information from the 8051 registers and return
3582 * their widths.
3583 *
3584 * Active lane information is found in these 8051 registers:
3585 * enable_lane_tx
3586 * enable_lane_rx
3587 */
3588static void get_link_widths(struct hfi1_devdata *dd, u16 *tx_width,
3589 u16 *rx_width)
3590{
3591 u16 tx, rx;
3592 u8 enable_lane_rx;
3593 u8 enable_lane_tx;
3594 u8 tx_polarity_inversion;
3595 u8 rx_polarity_inversion;
3596 u8 max_rate;
3597
3598 /* read the active lanes */
3599 read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
3600 &rx_polarity_inversion, &max_rate);
3601 read_local_lni(dd, &enable_lane_rx);
3602
3603 /* convert to counts */
3604 tx = nibble_to_count(enable_lane_tx);
3605 rx = nibble_to_count(enable_lane_rx);
3606
3607 /*
3608 * Set link_speed_active here, overriding what was set in
3609 * handle_verify_cap(). The ASIC 8051 firmware does not correctly
3610 * set the max_rate field in handle_verify_cap until v0.19.
3611 */
3612 if ((dd->icode == ICODE_RTL_SILICON)
3613 && (dd->dc8051_ver < dc8051_ver(0, 19))) {
3614 /* max_rate: 0 = 12.5G, 1 = 25G */
3615 switch (max_rate) {
3616 case 0:
3617 dd->pport[0].link_speed_active = OPA_LINK_SPEED_12_5G;
3618 break;
3619 default:
3620 dd_dev_err(dd,
3621 "%s: unexpected max rate %d, using 25Gb\n",
3622 __func__, (int)max_rate);
3623 /* fall through */
3624 case 1:
3625 dd->pport[0].link_speed_active = OPA_LINK_SPEED_25G;
3626 break;
3627 }
3628 }
3629
3630 dd_dev_info(dd,
3631 "Fabric active lanes (width): tx 0x%x (%d), rx 0x%x (%d)\n",
3632 enable_lane_tx, tx, enable_lane_rx, rx);
3633 *tx_width = link_width_to_bits(dd, tx);
3634 *rx_width = link_width_to_bits(dd, rx);
3635}
3636
3637/*
3638 * Read verify_cap_local_fm_link_width[1] to obtain the link widths.
3639 * Valid after the end of VerifyCap and during LinkUp. Does not change
3640 * after link up. I.e. look elsewhere for downgrade information.
3641 *
3642 * Bits are:
3643 * + bits [7:4] contain the number of active transmitters
3644 * + bits [3:0] contain the number of active receivers
3645 * These are numbers 1 through 4 and can be different values if the
3646 * link is asymmetric.
3647 *
3648 * verify_cap_local_fm_link_width[0] retains its original value.
3649 */
3650static void get_linkup_widths(struct hfi1_devdata *dd, u16 *tx_width,
3651 u16 *rx_width)
3652{
3653 u16 widths, tx, rx;
3654 u8 misc_bits, local_flags;
3655 u16 active_tx, active_rx;
3656
3657 read_vc_local_link_width(dd, &misc_bits, &local_flags, &widths);
3658 tx = widths >> 12;
3659 rx = (widths >> 8) & 0xf;
3660
3661 *tx_width = link_width_to_bits(dd, tx);
3662 *rx_width = link_width_to_bits(dd, rx);
3663
3664 /* print the active widths */
3665 get_link_widths(dd, &active_tx, &active_rx);
3666}
3667
3668/*
3669 * Set ppd->link_width_active and ppd->link_width_downgrade_active using
3670 * hardware information when the link first comes up.
3671 *
3672 * The link width is not available until after VerifyCap.AllFramesReceived
3673 * (the trigger for handle_verify_cap), so this is outside that routine
3674 * and should be called when the 8051 signals linkup.
3675 */
3676void get_linkup_link_widths(struct hfi1_pportdata *ppd)
3677{
3678 u16 tx_width, rx_width;
3679
3680 /* get end-of-LNI link widths */
3681 get_linkup_widths(ppd->dd, &tx_width, &rx_width);
3682
3683 /* use tx_width as the link is supposed to be symmetric on link up */
3684 ppd->link_width_active = tx_width;
3685 /* link width downgrade active (LWD.A) starts out matching LW.A */
3686 ppd->link_width_downgrade_tx_active = ppd->link_width_active;
3687 ppd->link_width_downgrade_rx_active = ppd->link_width_active;
3688 /* per OPA spec, on link up LWD.E resets to LWD.S */
3689 ppd->link_width_downgrade_enabled = ppd->link_width_downgrade_supported;
3690 /* cache the active egress rate (units {10^6 bits/sec]) */
3691 ppd->current_egress_rate = active_egress_rate(ppd);
3692}
3693
3694/*
3695 * Handle a verify capabilities interrupt from the 8051.
3696 *
3697 * This is a work-queue function outside of the interrupt.
3698 */
3699void handle_verify_cap(struct work_struct *work)
3700{
3701 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
3702 link_vc_work);
3703 struct hfi1_devdata *dd = ppd->dd;
3704 u64 reg;
3705 u8 power_management;
3706 u8 continious;
3707 u8 vcu;
3708 u8 vau;
3709 u8 z;
3710 u16 vl15buf;
3711 u16 link_widths;
3712 u16 crc_mask;
3713 u16 crc_val;
3714 u16 device_id;
3715 u16 active_tx, active_rx;
3716 u8 partner_supported_crc;
3717 u8 remote_tx_rate;
3718 u8 device_rev;
3719
3720 set_link_state(ppd, HLS_VERIFY_CAP);
3721
3722 lcb_shutdown(dd, 0);
3723 adjust_lcb_for_fpga_serdes(dd);
3724
3725 /*
3726 * These are now valid:
3727 * remote VerifyCap fields in the general LNI config
3728 * CSR DC8051_STS_REMOTE_GUID
3729 * CSR DC8051_STS_REMOTE_NODE_TYPE
3730 * CSR DC8051_STS_REMOTE_FM_SECURITY
3731 * CSR DC8051_STS_REMOTE_PORT_NO
3732 */
3733
3734 read_vc_remote_phy(dd, &power_management, &continious);
3735 read_vc_remote_fabric(
3736 dd,
3737 &vau,
3738 &z,
3739 &vcu,
3740 &vl15buf,
3741 &partner_supported_crc);
3742 read_vc_remote_link_width(dd, &remote_tx_rate, &link_widths);
3743 read_remote_device_id(dd, &device_id, &device_rev);
3744 /*
3745 * And the 'MgmtAllowed' information, which is exchanged during
3746 * LNI, is also be available at this point.
3747 */
3748 read_mgmt_allowed(dd, &ppd->mgmt_allowed);
3749 /* print the active widths */
3750 get_link_widths(dd, &active_tx, &active_rx);
3751 dd_dev_info(dd,
3752 "Peer PHY: power management 0x%x, continuous updates 0x%x\n",
3753 (int)power_management, (int)continious);
3754 dd_dev_info(dd,
3755 "Peer Fabric: vAU %d, Z %d, vCU %d, vl15 credits 0x%x, CRC sizes 0x%x\n",
3756 (int)vau,
3757 (int)z,
3758 (int)vcu,
3759 (int)vl15buf,
3760 (int)partner_supported_crc);
3761 dd_dev_info(dd, "Peer Link Width: tx rate 0x%x, widths 0x%x\n",
3762 (u32)remote_tx_rate, (u32)link_widths);
3763 dd_dev_info(dd, "Peer Device ID: 0x%04x, Revision 0x%02x\n",
3764 (u32)device_id, (u32)device_rev);
3765 /*
3766 * The peer vAU value just read is the peer receiver value. HFI does
3767 * not support a transmit vAU of 0 (AU == 8). We advertised that
3768 * with Z=1 in the fabric capabilities sent to the peer. The peer
3769 * will see our Z=1, and, if it advertised a vAU of 0, will move its
3770 * receive to vAU of 1 (AU == 16). Do the same here. We do not care
3771 * about the peer Z value - our sent vAU is 3 (hardwired) and is not
3772 * subject to the Z value exception.
3773 */
3774 if (vau == 0)
3775 vau = 1;
3776 set_up_vl15(dd, vau, vl15buf);
3777
3778 /* set up the LCB CRC mode */
3779 crc_mask = ppd->port_crc_mode_enabled & partner_supported_crc;
3780
3781 /* order is important: use the lowest bit in common */
3782 if (crc_mask & CAP_CRC_14B)
3783 crc_val = LCB_CRC_14B;
3784 else if (crc_mask & CAP_CRC_48B)
3785 crc_val = LCB_CRC_48B;
3786 else if (crc_mask & CAP_CRC_12B_16B_PER_LANE)
3787 crc_val = LCB_CRC_12B_16B_PER_LANE;
3788 else
3789 crc_val = LCB_CRC_16B;
3790
3791 dd_dev_info(dd, "Final LCB CRC mode: %d\n", (int)crc_val);
3792 write_csr(dd, DC_LCB_CFG_CRC_MODE,
3793 (u64)crc_val << DC_LCB_CFG_CRC_MODE_TX_VAL_SHIFT);
3794
3795 /* set (14b only) or clear sideband credit */
3796 reg = read_csr(dd, SEND_CM_CTRL);
3797 if (crc_val == LCB_CRC_14B && crc_14b_sideband) {
3798 write_csr(dd, SEND_CM_CTRL,
3799 reg | SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
3800 } else {
3801 write_csr(dd, SEND_CM_CTRL,
3802 reg & ~SEND_CM_CTRL_FORCE_CREDIT_MODE_SMASK);
3803 }
3804
3805 ppd->link_speed_active = 0; /* invalid value */
3806 if (dd->dc8051_ver < dc8051_ver(0, 20)) {
3807 /* remote_tx_rate: 0 = 12.5G, 1 = 25G */
3808 switch (remote_tx_rate) {
3809 case 0:
3810 ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
3811 break;
3812 case 1:
3813 ppd->link_speed_active = OPA_LINK_SPEED_25G;
3814 break;
3815 }
3816 } else {
3817 /* actual rate is highest bit of the ANDed rates */
3818 u8 rate = remote_tx_rate & ppd->local_tx_rate;
3819
3820 if (rate & 2)
3821 ppd->link_speed_active = OPA_LINK_SPEED_25G;
3822 else if (rate & 1)
3823 ppd->link_speed_active = OPA_LINK_SPEED_12_5G;
3824 }
3825 if (ppd->link_speed_active == 0) {
3826 dd_dev_err(dd, "%s: unexpected remote tx rate %d, using 25Gb\n",
3827 __func__, (int)remote_tx_rate);
3828 ppd->link_speed_active = OPA_LINK_SPEED_25G;
3829 }
3830
3831 /*
3832 * Cache the values of the supported, enabled, and active
3833 * LTP CRC modes to return in 'portinfo' queries. But the bit
3834 * flags that are returned in the portinfo query differ from
3835 * what's in the link_crc_mask, crc_sizes, and crc_val
3836 * variables. Convert these here.
3837 */
3838 ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
3839 /* supported crc modes */
3840 ppd->port_ltp_crc_mode |=
3841 cap_to_port_ltp(ppd->port_crc_mode_enabled) << 4;
3842 /* enabled crc modes */
3843 ppd->port_ltp_crc_mode |= lcb_to_port_ltp(crc_val);
3844 /* active crc mode */
3845
3846 /* set up the remote credit return table */
3847 assign_remote_cm_au_table(dd, vcu);
3848
3849 /*
3850 * The LCB is reset on entry to handle_verify_cap(), so this must
3851 * be applied on every link up.
3852 *
3853 * Adjust LCB error kill enable to kill the link if
3854 * these RBUF errors are seen:
3855 * REPLAY_BUF_MBE_SMASK
3856 * FLIT_INPUT_BUF_MBE_SMASK
3857 */
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05003858 if (is_ax(dd)) { /* fixed in B0 */
Mike Marciniszyn77241052015-07-30 15:17:43 -04003859 reg = read_csr(dd, DC_LCB_CFG_LINK_KILL_EN);
3860 reg |= DC_LCB_CFG_LINK_KILL_EN_REPLAY_BUF_MBE_SMASK
3861 | DC_LCB_CFG_LINK_KILL_EN_FLIT_INPUT_BUF_MBE_SMASK;
3862 write_csr(dd, DC_LCB_CFG_LINK_KILL_EN, reg);
3863 }
3864
3865 /* pull LCB fifos out of reset - all fifo clocks must be stable */
3866 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
3867
3868 /* give 8051 access to the LCB CSRs */
3869 write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
3870 set_8051_lcb_access(dd);
3871
3872 ppd->neighbor_guid =
3873 read_csr(dd, DC_DC8051_STS_REMOTE_GUID);
3874 ppd->neighbor_port_number = read_csr(dd, DC_DC8051_STS_REMOTE_PORT_NO) &
3875 DC_DC8051_STS_REMOTE_PORT_NO_VAL_SMASK;
3876 ppd->neighbor_type =
3877 read_csr(dd, DC_DC8051_STS_REMOTE_NODE_TYPE) &
3878 DC_DC8051_STS_REMOTE_NODE_TYPE_VAL_MASK;
3879 ppd->neighbor_fm_security =
3880 read_csr(dd, DC_DC8051_STS_REMOTE_FM_SECURITY) &
3881 DC_DC8051_STS_LOCAL_FM_SECURITY_DISABLED_MASK;
3882 dd_dev_info(dd,
3883 "Neighbor Guid: %llx Neighbor type %d MgmtAllowed %d FM security bypass %d\n",
3884 ppd->neighbor_guid, ppd->neighbor_type,
3885 ppd->mgmt_allowed, ppd->neighbor_fm_security);
3886 if (ppd->mgmt_allowed)
3887 add_full_mgmt_pkey(ppd);
3888
3889 /* tell the 8051 to go to LinkUp */
3890 set_link_state(ppd, HLS_GOING_UP);
3891}
3892
3893/*
3894 * Apply the link width downgrade enabled policy against the current active
3895 * link widths.
3896 *
3897 * Called when the enabled policy changes or the active link widths change.
3898 */
3899void apply_link_downgrade_policy(struct hfi1_pportdata *ppd, int refresh_widths)
3900{
Mike Marciniszyn77241052015-07-30 15:17:43 -04003901 int do_bounce = 0;
Dean Luick323fd782015-11-16 21:59:24 -05003902 int tries;
3903 u16 lwde;
Mike Marciniszyn77241052015-07-30 15:17:43 -04003904 u16 tx, rx;
3905
Dean Luick323fd782015-11-16 21:59:24 -05003906 /* use the hls lock to avoid a race with actual link up */
3907 tries = 0;
3908retry:
Mike Marciniszyn77241052015-07-30 15:17:43 -04003909 mutex_lock(&ppd->hls_lock);
3910 /* only apply if the link is up */
Dean Luick323fd782015-11-16 21:59:24 -05003911 if (!(ppd->host_link_state & HLS_UP)) {
3912 /* still going up..wait and retry */
3913 if (ppd->host_link_state & HLS_GOING_UP) {
3914 if (++tries < 1000) {
3915 mutex_unlock(&ppd->hls_lock);
3916 usleep_range(100, 120); /* arbitrary */
3917 goto retry;
3918 }
3919 dd_dev_err(ppd->dd,
3920 "%s: giving up waiting for link state change\n",
3921 __func__);
3922 }
3923 goto done;
3924 }
3925
3926 lwde = ppd->link_width_downgrade_enabled;
Mike Marciniszyn77241052015-07-30 15:17:43 -04003927
3928 if (refresh_widths) {
3929 get_link_widths(ppd->dd, &tx, &rx);
3930 ppd->link_width_downgrade_tx_active = tx;
3931 ppd->link_width_downgrade_rx_active = rx;
3932 }
3933
3934 if (lwde == 0) {
3935 /* downgrade is disabled */
3936
3937 /* bounce if not at starting active width */
3938 if ((ppd->link_width_active !=
3939 ppd->link_width_downgrade_tx_active)
3940 || (ppd->link_width_active !=
3941 ppd->link_width_downgrade_rx_active)) {
3942 dd_dev_err(ppd->dd,
3943 "Link downgrade is disabled and link has downgraded, downing link\n");
3944 dd_dev_err(ppd->dd,
3945 " original 0x%x, tx active 0x%x, rx active 0x%x\n",
3946 ppd->link_width_active,
3947 ppd->link_width_downgrade_tx_active,
3948 ppd->link_width_downgrade_rx_active);
3949 do_bounce = 1;
3950 }
3951 } else if ((lwde & ppd->link_width_downgrade_tx_active) == 0
3952 || (lwde & ppd->link_width_downgrade_rx_active) == 0) {
3953 /* Tx or Rx is outside the enabled policy */
3954 dd_dev_err(ppd->dd,
3955 "Link is outside of downgrade allowed, downing link\n");
3956 dd_dev_err(ppd->dd,
3957 " enabled 0x%x, tx active 0x%x, rx active 0x%x\n",
3958 lwde,
3959 ppd->link_width_downgrade_tx_active,
3960 ppd->link_width_downgrade_rx_active);
3961 do_bounce = 1;
3962 }
3963
Dean Luick323fd782015-11-16 21:59:24 -05003964done:
3965 mutex_unlock(&ppd->hls_lock);
3966
Mike Marciniszyn77241052015-07-30 15:17:43 -04003967 if (do_bounce) {
3968 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_WIDTH_POLICY, 0,
3969 OPA_LINKDOWN_REASON_WIDTH_POLICY);
3970 set_link_state(ppd, HLS_DN_OFFLINE);
3971 start_link(ppd);
3972 }
3973}
3974
3975/*
3976 * Handle a link downgrade interrupt from the 8051.
3977 *
3978 * This is a work-queue function outside of the interrupt.
3979 */
3980void handle_link_downgrade(struct work_struct *work)
3981{
3982 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
3983 link_downgrade_work);
3984
3985 dd_dev_info(ppd->dd, "8051: Link width downgrade\n");
3986 apply_link_downgrade_policy(ppd, 1);
3987}
3988
3989static char *dcc_err_string(char *buf, int buf_len, u64 flags)
3990{
3991 return flag_string(buf, buf_len, flags, dcc_err_flags,
3992 ARRAY_SIZE(dcc_err_flags));
3993}
3994
3995static char *lcb_err_string(char *buf, int buf_len, u64 flags)
3996{
3997 return flag_string(buf, buf_len, flags, lcb_err_flags,
3998 ARRAY_SIZE(lcb_err_flags));
3999}
4000
4001static char *dc8051_err_string(char *buf, int buf_len, u64 flags)
4002{
4003 return flag_string(buf, buf_len, flags, dc8051_err_flags,
4004 ARRAY_SIZE(dc8051_err_flags));
4005}
4006
4007static char *dc8051_info_err_string(char *buf, int buf_len, u64 flags)
4008{
4009 return flag_string(buf, buf_len, flags, dc8051_info_err_flags,
4010 ARRAY_SIZE(dc8051_info_err_flags));
4011}
4012
4013static char *dc8051_info_host_msg_string(char *buf, int buf_len, u64 flags)
4014{
4015 return flag_string(buf, buf_len, flags, dc8051_info_host_msg_flags,
4016 ARRAY_SIZE(dc8051_info_host_msg_flags));
4017}
4018
4019static void handle_8051_interrupt(struct hfi1_devdata *dd, u32 unused, u64 reg)
4020{
4021 struct hfi1_pportdata *ppd = dd->pport;
4022 u64 info, err, host_msg;
4023 int queue_link_down = 0;
4024 char buf[96];
4025
4026 /* look at the flags */
4027 if (reg & DC_DC8051_ERR_FLG_SET_BY_8051_SMASK) {
4028 /* 8051 information set by firmware */
4029 /* read DC8051_DBG_ERR_INFO_SET_BY_8051 for details */
4030 info = read_csr(dd, DC_DC8051_DBG_ERR_INFO_SET_BY_8051);
4031 err = (info >> DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_SHIFT)
4032 & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_ERROR_MASK;
4033 host_msg = (info >>
4034 DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_SHIFT)
4035 & DC_DC8051_DBG_ERR_INFO_SET_BY_8051_HOST_MSG_MASK;
4036
4037 /*
4038 * Handle error flags.
4039 */
4040 if (err & FAILED_LNI) {
4041 /*
4042 * LNI error indications are cleared by the 8051
4043 * only when starting polling. Only pay attention
4044 * to them when in the states that occur during
4045 * LNI.
4046 */
4047 if (ppd->host_link_state
4048 & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
4049 queue_link_down = 1;
4050 dd_dev_info(dd, "Link error: %s\n",
4051 dc8051_info_err_string(buf,
4052 sizeof(buf),
4053 err & FAILED_LNI));
4054 }
4055 err &= ~(u64)FAILED_LNI;
4056 }
4057 if (err) {
4058 /* report remaining errors, but do not do anything */
4059 dd_dev_err(dd, "8051 info error: %s\n",
4060 dc8051_info_err_string(buf, sizeof(buf), err));
4061 }
4062
4063 /*
4064 * Handle host message flags.
4065 */
4066 if (host_msg & HOST_REQ_DONE) {
4067 /*
4068 * Presently, the driver does a busy wait for
4069 * host requests to complete. This is only an
4070 * informational message.
4071 * NOTE: The 8051 clears the host message
4072 * information *on the next 8051 command*.
4073 * Therefore, when linkup is achieved,
4074 * this flag will still be set.
4075 */
4076 host_msg &= ~(u64)HOST_REQ_DONE;
4077 }
4078 if (host_msg & BC_SMA_MSG) {
4079 queue_work(ppd->hfi1_wq, &ppd->sma_message_work);
4080 host_msg &= ~(u64)BC_SMA_MSG;
4081 }
4082 if (host_msg & LINKUP_ACHIEVED) {
4083 dd_dev_info(dd, "8051: Link up\n");
4084 queue_work(ppd->hfi1_wq, &ppd->link_up_work);
4085 host_msg &= ~(u64)LINKUP_ACHIEVED;
4086 }
4087 if (host_msg & EXT_DEVICE_CFG_REQ) {
4088 handle_8051_request(dd);
4089 host_msg &= ~(u64)EXT_DEVICE_CFG_REQ;
4090 }
4091 if (host_msg & VERIFY_CAP_FRAME) {
4092 queue_work(ppd->hfi1_wq, &ppd->link_vc_work);
4093 host_msg &= ~(u64)VERIFY_CAP_FRAME;
4094 }
4095 if (host_msg & LINK_GOING_DOWN) {
4096 const char *extra = "";
4097 /* no downgrade action needed if going down */
4098 if (host_msg & LINK_WIDTH_DOWNGRADED) {
4099 host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
4100 extra = " (ignoring downgrade)";
4101 }
4102 dd_dev_info(dd, "8051: Link down%s\n", extra);
4103 queue_link_down = 1;
4104 host_msg &= ~(u64)LINK_GOING_DOWN;
4105 }
4106 if (host_msg & LINK_WIDTH_DOWNGRADED) {
4107 queue_work(ppd->hfi1_wq, &ppd->link_downgrade_work);
4108 host_msg &= ~(u64)LINK_WIDTH_DOWNGRADED;
4109 }
4110 if (host_msg) {
4111 /* report remaining messages, but do not do anything */
4112 dd_dev_info(dd, "8051 info host message: %s\n",
4113 dc8051_info_host_msg_string(buf, sizeof(buf),
4114 host_msg));
4115 }
4116
4117 reg &= ~DC_DC8051_ERR_FLG_SET_BY_8051_SMASK;
4118 }
4119 if (reg & DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK) {
4120 /*
4121 * Lost the 8051 heartbeat. If this happens, we
4122 * receive constant interrupts about it. Disable
4123 * the interrupt after the first.
4124 */
4125 dd_dev_err(dd, "Lost 8051 heartbeat\n");
4126 write_csr(dd, DC_DC8051_ERR_EN,
4127 read_csr(dd, DC_DC8051_ERR_EN)
4128 & ~DC_DC8051_ERR_EN_LOST_8051_HEART_BEAT_SMASK);
4129
4130 reg &= ~DC_DC8051_ERR_FLG_LOST_8051_HEART_BEAT_SMASK;
4131 }
4132 if (reg) {
4133 /* report the error, but do not do anything */
4134 dd_dev_err(dd, "8051 error: %s\n",
4135 dc8051_err_string(buf, sizeof(buf), reg));
4136 }
4137
4138 if (queue_link_down) {
4139 /* if the link is already going down or disabled, do not
4140 * queue another */
4141 if ((ppd->host_link_state
4142 & (HLS_GOING_OFFLINE|HLS_LINK_COOLDOWN))
4143 || ppd->link_enabled == 0) {
4144 dd_dev_info(dd, "%s: not queuing link down\n",
4145 __func__);
4146 } else {
4147 queue_work(ppd->hfi1_wq, &ppd->link_down_work);
4148 }
4149 }
4150}
4151
4152static const char * const fm_config_txt[] = {
4153[0] =
4154 "BadHeadDist: Distance violation between two head flits",
4155[1] =
4156 "BadTailDist: Distance violation between two tail flits",
4157[2] =
4158 "BadCtrlDist: Distance violation between two credit control flits",
4159[3] =
4160 "BadCrdAck: Credits return for unsupported VL",
4161[4] =
4162 "UnsupportedVLMarker: Received VL Marker",
4163[5] =
4164 "BadPreempt: Exceeded the preemption nesting level",
4165[6] =
4166 "BadControlFlit: Received unsupported control flit",
4167/* no 7 */
4168[8] =
4169 "UnsupportedVLMarker: Received VL Marker for unconfigured or disabled VL",
4170};
4171
4172static const char * const port_rcv_txt[] = {
4173[1] =
4174 "BadPktLen: Illegal PktLen",
4175[2] =
4176 "PktLenTooLong: Packet longer than PktLen",
4177[3] =
4178 "PktLenTooShort: Packet shorter than PktLen",
4179[4] =
4180 "BadSLID: Illegal SLID (0, using multicast as SLID, does not include security validation of SLID)",
4181[5] =
4182 "BadDLID: Illegal DLID (0, doesn't match HFI)",
4183[6] =
4184 "BadL2: Illegal L2 opcode",
4185[7] =
4186 "BadSC: Unsupported SC",
4187[9] =
4188 "BadRC: Illegal RC",
4189[11] =
4190 "PreemptError: Preempting with same VL",
4191[12] =
4192 "PreemptVL15: Preempting a VL15 packet",
4193};
4194
4195#define OPA_LDR_FMCONFIG_OFFSET 16
4196#define OPA_LDR_PORTRCV_OFFSET 0
4197static void handle_dcc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
4198{
4199 u64 info, hdr0, hdr1;
4200 const char *extra;
4201 char buf[96];
4202 struct hfi1_pportdata *ppd = dd->pport;
4203 u8 lcl_reason = 0;
4204 int do_bounce = 0;
4205
4206 if (reg & DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK) {
4207 if (!(dd->err_info_uncorrectable & OPA_EI_STATUS_SMASK)) {
4208 info = read_csr(dd, DCC_ERR_INFO_UNCORRECTABLE);
4209 dd->err_info_uncorrectable = info & OPA_EI_CODE_SMASK;
4210 /* set status bit */
4211 dd->err_info_uncorrectable |= OPA_EI_STATUS_SMASK;
4212 }
4213 reg &= ~DCC_ERR_FLG_UNCORRECTABLE_ERR_SMASK;
4214 }
4215
4216 if (reg & DCC_ERR_FLG_LINK_ERR_SMASK) {
4217 struct hfi1_pportdata *ppd = dd->pport;
4218 /* this counter saturates at (2^32) - 1 */
4219 if (ppd->link_downed < (u32)UINT_MAX)
4220 ppd->link_downed++;
4221 reg &= ~DCC_ERR_FLG_LINK_ERR_SMASK;
4222 }
4223
4224 if (reg & DCC_ERR_FLG_FMCONFIG_ERR_SMASK) {
4225 u8 reason_valid = 1;
4226
4227 info = read_csr(dd, DCC_ERR_INFO_FMCONFIG);
4228 if (!(dd->err_info_fmconfig & OPA_EI_STATUS_SMASK)) {
4229 dd->err_info_fmconfig = info & OPA_EI_CODE_SMASK;
4230 /* set status bit */
4231 dd->err_info_fmconfig |= OPA_EI_STATUS_SMASK;
4232 }
4233 switch (info) {
4234 case 0:
4235 case 1:
4236 case 2:
4237 case 3:
4238 case 4:
4239 case 5:
4240 case 6:
4241 extra = fm_config_txt[info];
4242 break;
4243 case 8:
4244 extra = fm_config_txt[info];
4245 if (ppd->port_error_action &
4246 OPA_PI_MASK_FM_CFG_UNSUPPORTED_VL_MARKER) {
4247 do_bounce = 1;
4248 /*
4249 * lcl_reason cannot be derived from info
4250 * for this error
4251 */
4252 lcl_reason =
4253 OPA_LINKDOWN_REASON_UNSUPPORTED_VL_MARKER;
4254 }
4255 break;
4256 default:
4257 reason_valid = 0;
4258 snprintf(buf, sizeof(buf), "reserved%lld", info);
4259 extra = buf;
4260 break;
4261 }
4262
4263 if (reason_valid && !do_bounce) {
4264 do_bounce = ppd->port_error_action &
4265 (1 << (OPA_LDR_FMCONFIG_OFFSET + info));
4266 lcl_reason = info + OPA_LINKDOWN_REASON_BAD_HEAD_DIST;
4267 }
4268
4269 /* just report this */
4270 dd_dev_info(dd, "DCC Error: fmconfig error: %s\n", extra);
4271 reg &= ~DCC_ERR_FLG_FMCONFIG_ERR_SMASK;
4272 }
4273
4274 if (reg & DCC_ERR_FLG_RCVPORT_ERR_SMASK) {
4275 u8 reason_valid = 1;
4276
4277 info = read_csr(dd, DCC_ERR_INFO_PORTRCV);
4278 hdr0 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR0);
4279 hdr1 = read_csr(dd, DCC_ERR_INFO_PORTRCV_HDR1);
4280 if (!(dd->err_info_rcvport.status_and_code &
4281 OPA_EI_STATUS_SMASK)) {
4282 dd->err_info_rcvport.status_and_code =
4283 info & OPA_EI_CODE_SMASK;
4284 /* set status bit */
4285 dd->err_info_rcvport.status_and_code |=
4286 OPA_EI_STATUS_SMASK;
4287 /* save first 2 flits in the packet that caused
4288 * the error */
4289 dd->err_info_rcvport.packet_flit1 = hdr0;
4290 dd->err_info_rcvport.packet_flit2 = hdr1;
4291 }
4292 switch (info) {
4293 case 1:
4294 case 2:
4295 case 3:
4296 case 4:
4297 case 5:
4298 case 6:
4299 case 7:
4300 case 9:
4301 case 11:
4302 case 12:
4303 extra = port_rcv_txt[info];
4304 break;
4305 default:
4306 reason_valid = 0;
4307 snprintf(buf, sizeof(buf), "reserved%lld", info);
4308 extra = buf;
4309 break;
4310 }
4311
4312 if (reason_valid && !do_bounce) {
4313 do_bounce = ppd->port_error_action &
4314 (1 << (OPA_LDR_PORTRCV_OFFSET + info));
4315 lcl_reason = info + OPA_LINKDOWN_REASON_RCV_ERROR_0;
4316 }
4317
4318 /* just report this */
4319 dd_dev_info(dd, "DCC Error: PortRcv error: %s\n", extra);
4320 dd_dev_info(dd, " hdr0 0x%llx, hdr1 0x%llx\n",
4321 hdr0, hdr1);
4322
4323 reg &= ~DCC_ERR_FLG_RCVPORT_ERR_SMASK;
4324 }
4325
4326 if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK) {
4327 /* informative only */
4328 dd_dev_info(dd, "8051 access to LCB blocked\n");
4329 reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_UC_SMASK;
4330 }
4331 if (reg & DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK) {
4332 /* informative only */
4333 dd_dev_info(dd, "host access to LCB blocked\n");
4334 reg &= ~DCC_ERR_FLG_EN_CSR_ACCESS_BLOCKED_HOST_SMASK;
4335 }
4336
4337 /* report any remaining errors */
4338 if (reg)
4339 dd_dev_info(dd, "DCC Error: %s\n",
4340 dcc_err_string(buf, sizeof(buf), reg));
4341
4342 if (lcl_reason == 0)
4343 lcl_reason = OPA_LINKDOWN_REASON_UNKNOWN;
4344
4345 if (do_bounce) {
4346 dd_dev_info(dd, "%s: PortErrorAction bounce\n", __func__);
4347 set_link_down_reason(ppd, lcl_reason, 0, lcl_reason);
4348 queue_work(ppd->hfi1_wq, &ppd->link_bounce_work);
4349 }
4350}
4351
4352static void handle_lcb_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
4353{
4354 char buf[96];
4355
4356 dd_dev_info(dd, "LCB Error: %s\n",
4357 lcb_err_string(buf, sizeof(buf), reg));
4358}
4359
4360/*
4361 * CCE block DC interrupt. Source is < 8.
4362 */
4363static void is_dc_int(struct hfi1_devdata *dd, unsigned int source)
4364{
4365 const struct err_reg_info *eri = &dc_errs[source];
4366
4367 if (eri->handler) {
4368 interrupt_clear_down(dd, 0, eri);
4369 } else if (source == 3 /* dc_lbm_int */) {
4370 /*
4371 * This indicates that a parity error has occurred on the
4372 * address/control lines presented to the LBM. The error
4373 * is a single pulse, there is no associated error flag,
4374 * and it is non-maskable. This is because if a parity
4375 * error occurs on the request the request is dropped.
4376 * This should never occur, but it is nice to know if it
4377 * ever does.
4378 */
4379 dd_dev_err(dd, "Parity error in DC LBM block\n");
4380 } else {
4381 dd_dev_err(dd, "Invalid DC interrupt %u\n", source);
4382 }
4383}
4384
4385/*
4386 * TX block send credit interrupt. Source is < 160.
4387 */
4388static void is_send_credit_int(struct hfi1_devdata *dd, unsigned int source)
4389{
4390 sc_group_release_update(dd, source);
4391}
4392
4393/*
4394 * TX block SDMA interrupt. Source is < 48.
4395 *
4396 * SDMA interrupts are grouped by type:
4397 *
4398 * 0 - N-1 = SDma
4399 * N - 2N-1 = SDmaProgress
4400 * 2N - 3N-1 = SDmaIdle
4401 */
4402static void is_sdma_eng_int(struct hfi1_devdata *dd, unsigned int source)
4403{
4404 /* what interrupt */
4405 unsigned int what = source / TXE_NUM_SDMA_ENGINES;
4406 /* which engine */
4407 unsigned int which = source % TXE_NUM_SDMA_ENGINES;
4408
4409#ifdef CONFIG_SDMA_VERBOSITY
4410 dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", which,
4411 slashstrip(__FILE__), __LINE__, __func__);
4412 sdma_dumpstate(&dd->per_sdma[which]);
4413#endif
4414
4415 if (likely(what < 3 && which < dd->num_sdma)) {
4416 sdma_engine_interrupt(&dd->per_sdma[which], 1ull << source);
4417 } else {
4418 /* should not happen */
4419 dd_dev_err(dd, "Invalid SDMA interrupt 0x%x\n", source);
4420 }
4421}
4422
4423/*
4424 * RX block receive available interrupt. Source is < 160.
4425 */
4426static void is_rcv_avail_int(struct hfi1_devdata *dd, unsigned int source)
4427{
4428 struct hfi1_ctxtdata *rcd;
4429 char *err_detail;
4430
4431 if (likely(source < dd->num_rcv_contexts)) {
4432 rcd = dd->rcd[source];
4433 if (rcd) {
4434 if (source < dd->first_user_ctxt)
Dean Luickf4f30031c2015-10-26 10:28:44 -04004435 rcd->do_interrupt(rcd, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -04004436 else
4437 handle_user_interrupt(rcd);
4438 return; /* OK */
4439 }
4440 /* received an interrupt, but no rcd */
4441 err_detail = "dataless";
4442 } else {
4443 /* received an interrupt, but are not using that context */
4444 err_detail = "out of range";
4445 }
4446 dd_dev_err(dd, "unexpected %s receive available context interrupt %u\n",
4447 err_detail, source);
4448}
4449
4450/*
4451 * RX block receive urgent interrupt. Source is < 160.
4452 */
4453static void is_rcv_urgent_int(struct hfi1_devdata *dd, unsigned int source)
4454{
4455 struct hfi1_ctxtdata *rcd;
4456 char *err_detail;
4457
4458 if (likely(source < dd->num_rcv_contexts)) {
4459 rcd = dd->rcd[source];
4460 if (rcd) {
4461 /* only pay attention to user urgent interrupts */
4462 if (source >= dd->first_user_ctxt)
4463 handle_user_interrupt(rcd);
4464 return; /* OK */
4465 }
4466 /* received an interrupt, but no rcd */
4467 err_detail = "dataless";
4468 } else {
4469 /* received an interrupt, but are not using that context */
4470 err_detail = "out of range";
4471 }
4472 dd_dev_err(dd, "unexpected %s receive urgent context interrupt %u\n",
4473 err_detail, source);
4474}
4475
4476/*
4477 * Reserved range interrupt. Should not be called in normal operation.
4478 */
4479static void is_reserved_int(struct hfi1_devdata *dd, unsigned int source)
4480{
4481 char name[64];
4482
4483 dd_dev_err(dd, "unexpected %s interrupt\n",
4484 is_reserved_name(name, sizeof(name), source));
4485}
4486
4487static const struct is_table is_table[] = {
4488/* start end
4489 name func interrupt func */
4490{ IS_GENERAL_ERR_START, IS_GENERAL_ERR_END,
4491 is_misc_err_name, is_misc_err_int },
4492{ IS_SDMAENG_ERR_START, IS_SDMAENG_ERR_END,
4493 is_sdma_eng_err_name, is_sdma_eng_err_int },
4494{ IS_SENDCTXT_ERR_START, IS_SENDCTXT_ERR_END,
4495 is_sendctxt_err_name, is_sendctxt_err_int },
4496{ IS_SDMA_START, IS_SDMA_END,
4497 is_sdma_eng_name, is_sdma_eng_int },
4498{ IS_VARIOUS_START, IS_VARIOUS_END,
4499 is_various_name, is_various_int },
4500{ IS_DC_START, IS_DC_END,
4501 is_dc_name, is_dc_int },
4502{ IS_RCVAVAIL_START, IS_RCVAVAIL_END,
4503 is_rcv_avail_name, is_rcv_avail_int },
4504{ IS_RCVURGENT_START, IS_RCVURGENT_END,
4505 is_rcv_urgent_name, is_rcv_urgent_int },
4506{ IS_SENDCREDIT_START, IS_SENDCREDIT_END,
4507 is_send_credit_name, is_send_credit_int},
4508{ IS_RESERVED_START, IS_RESERVED_END,
4509 is_reserved_name, is_reserved_int},
4510};
4511
4512/*
4513 * Interrupt source interrupt - called when the given source has an interrupt.
4514 * Source is a bit index into an array of 64-bit integers.
4515 */
4516static void is_interrupt(struct hfi1_devdata *dd, unsigned int source)
4517{
4518 const struct is_table *entry;
4519
4520 /* avoids a double compare by walking the table in-order */
4521 for (entry = &is_table[0]; entry->is_name; entry++) {
4522 if (source < entry->end) {
4523 trace_hfi1_interrupt(dd, entry, source);
4524 entry->is_int(dd, source - entry->start);
4525 return;
4526 }
4527 }
4528 /* fell off the end */
4529 dd_dev_err(dd, "invalid interrupt source %u\n", source);
4530}
4531
4532/*
4533 * General interrupt handler. This is able to correctly handle
4534 * all interrupts in case INTx is used.
4535 */
4536static irqreturn_t general_interrupt(int irq, void *data)
4537{
4538 struct hfi1_devdata *dd = data;
4539 u64 regs[CCE_NUM_INT_CSRS];
4540 u32 bit;
4541 int i;
4542
4543 this_cpu_inc(*dd->int_counter);
4544
4545 /* phase 1: scan and clear all handled interrupts */
4546 for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
4547 if (dd->gi_mask[i] == 0) {
4548 regs[i] = 0; /* used later */
4549 continue;
4550 }
4551 regs[i] = read_csr(dd, CCE_INT_STATUS + (8 * i)) &
4552 dd->gi_mask[i];
4553 /* only clear if anything is set */
4554 if (regs[i])
4555 write_csr(dd, CCE_INT_CLEAR + (8 * i), regs[i]);
4556 }
4557
4558 /* phase 2: call the appropriate handler */
4559 for_each_set_bit(bit, (unsigned long *)&regs[0],
4560 CCE_NUM_INT_CSRS*64) {
4561 is_interrupt(dd, bit);
4562 }
4563
4564 return IRQ_HANDLED;
4565}
4566
4567static irqreturn_t sdma_interrupt(int irq, void *data)
4568{
4569 struct sdma_engine *sde = data;
4570 struct hfi1_devdata *dd = sde->dd;
4571 u64 status;
4572
4573#ifdef CONFIG_SDMA_VERBOSITY
4574 dd_dev_err(dd, "CONFIG SDMA(%u) %s:%d %s()\n", sde->this_idx,
4575 slashstrip(__FILE__), __LINE__, __func__);
4576 sdma_dumpstate(sde);
4577#endif
4578
4579 this_cpu_inc(*dd->int_counter);
4580
4581 /* This read_csr is really bad in the hot path */
4582 status = read_csr(dd,
4583 CCE_INT_STATUS + (8*(IS_SDMA_START/64)))
4584 & sde->imask;
4585 if (likely(status)) {
4586 /* clear the interrupt(s) */
4587 write_csr(dd,
4588 CCE_INT_CLEAR + (8*(IS_SDMA_START/64)),
4589 status);
4590
4591 /* handle the interrupt(s) */
4592 sdma_engine_interrupt(sde, status);
4593 } else
4594 dd_dev_err(dd, "SDMA engine %u interrupt, but no status bits set\n",
4595 sde->this_idx);
4596
4597 return IRQ_HANDLED;
4598}
4599
4600/*
Dean Luickf4f30031c2015-10-26 10:28:44 -04004601 * Clear the receive interrupt, forcing the write and making sure
4602 * we have data from the chip, pushing everything in front of it
4603 * back to the host.
4604 */
4605static inline void clear_recv_intr(struct hfi1_ctxtdata *rcd)
4606{
4607 struct hfi1_devdata *dd = rcd->dd;
4608 u32 addr = CCE_INT_CLEAR + (8 * rcd->ireg);
4609
4610 mmiowb(); /* make sure everything before is written */
4611 write_csr(dd, addr, rcd->imask);
4612 /* force the above write on the chip and get a value back */
4613 (void)read_csr(dd, addr);
4614}
4615
4616/* force the receive interrupt */
4617static inline void force_recv_intr(struct hfi1_ctxtdata *rcd)
4618{
4619 write_csr(rcd->dd, CCE_INT_FORCE + (8 * rcd->ireg), rcd->imask);
4620}
4621
4622/* return non-zero if a packet is present */
4623static inline int check_packet_present(struct hfi1_ctxtdata *rcd)
4624{
4625 if (!HFI1_CAP_IS_KSET(DMA_RTAIL))
4626 return (rcd->seq_cnt ==
4627 rhf_rcv_seq(rhf_to_cpu(get_rhf_addr(rcd))));
4628
4629 /* else is RDMA rtail */
4630 return (rcd->head != get_rcvhdrtail(rcd));
4631}
4632
4633/*
4634 * Receive packet IRQ handler. This routine expects to be on its own IRQ.
4635 * This routine will try to handle packets immediately (latency), but if
4636 * it finds too many, it will invoke the thread handler (bandwitdh). The
4637 * chip receive interupt is *not* cleared down until this or the thread (if
4638 * invoked) is finished. The intent is to avoid extra interrupts while we
4639 * are processing packets anyway.
Mike Marciniszyn77241052015-07-30 15:17:43 -04004640 */
4641static irqreturn_t receive_context_interrupt(int irq, void *data)
4642{
4643 struct hfi1_ctxtdata *rcd = data;
4644 struct hfi1_devdata *dd = rcd->dd;
Dean Luickf4f30031c2015-10-26 10:28:44 -04004645 int disposition;
4646 int present;
Mike Marciniszyn77241052015-07-30 15:17:43 -04004647
4648 trace_hfi1_receive_interrupt(dd, rcd->ctxt);
4649 this_cpu_inc(*dd->int_counter);
4650
Dean Luickf4f30031c2015-10-26 10:28:44 -04004651 /* receive interrupt remains blocked while processing packets */
4652 disposition = rcd->do_interrupt(rcd, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -04004653
Dean Luickf4f30031c2015-10-26 10:28:44 -04004654 /*
4655 * Too many packets were seen while processing packets in this
4656 * IRQ handler. Invoke the handler thread. The receive interrupt
4657 * remains blocked.
4658 */
4659 if (disposition == RCV_PKT_LIMIT)
4660 return IRQ_WAKE_THREAD;
4661
4662 /*
4663 * The packet processor detected no more packets. Clear the receive
4664 * interrupt and recheck for a packet packet that may have arrived
4665 * after the previous check and interrupt clear. If a packet arrived,
4666 * force another interrupt.
4667 */
4668 clear_recv_intr(rcd);
4669 present = check_packet_present(rcd);
4670 if (present)
4671 force_recv_intr(rcd);
4672
4673 return IRQ_HANDLED;
4674}
4675
4676/*
4677 * Receive packet thread handler. This expects to be invoked with the
4678 * receive interrupt still blocked.
4679 */
4680static irqreturn_t receive_context_thread(int irq, void *data)
4681{
4682 struct hfi1_ctxtdata *rcd = data;
4683 int present;
4684
4685 /* receive interrupt is still blocked from the IRQ handler */
4686 (void)rcd->do_interrupt(rcd, 1);
4687
4688 /*
4689 * The packet processor will only return if it detected no more
4690 * packets. Hold IRQs here so we can safely clear the interrupt and
4691 * recheck for a packet that may have arrived after the previous
4692 * check and the interrupt clear. If a packet arrived, force another
4693 * interrupt.
4694 */
4695 local_irq_disable();
4696 clear_recv_intr(rcd);
4697 present = check_packet_present(rcd);
4698 if (present)
4699 force_recv_intr(rcd);
4700 local_irq_enable();
Mike Marciniszyn77241052015-07-30 15:17:43 -04004701
4702 return IRQ_HANDLED;
4703}
4704
4705/* ========================================================================= */
4706
4707u32 read_physical_state(struct hfi1_devdata *dd)
4708{
4709 u64 reg;
4710
4711 reg = read_csr(dd, DC_DC8051_STS_CUR_STATE);
4712 return (reg >> DC_DC8051_STS_CUR_STATE_PORT_SHIFT)
4713 & DC_DC8051_STS_CUR_STATE_PORT_MASK;
4714}
4715
4716static u32 read_logical_state(struct hfi1_devdata *dd)
4717{
4718 u64 reg;
4719
4720 reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
4721 return (reg >> DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT)
4722 & DCC_CFG_PORT_CONFIG_LINK_STATE_MASK;
4723}
4724
4725static void set_logical_state(struct hfi1_devdata *dd, u32 chip_lstate)
4726{
4727 u64 reg;
4728
4729 reg = read_csr(dd, DCC_CFG_PORT_CONFIG);
4730 /* clear current state, set new state */
4731 reg &= ~DCC_CFG_PORT_CONFIG_LINK_STATE_SMASK;
4732 reg |= (u64)chip_lstate << DCC_CFG_PORT_CONFIG_LINK_STATE_SHIFT;
4733 write_csr(dd, DCC_CFG_PORT_CONFIG, reg);
4734}
4735
4736/*
4737 * Use the 8051 to read a LCB CSR.
4738 */
4739static int read_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 *data)
4740{
4741 u32 regno;
4742 int ret;
4743
4744 if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
4745 if (acquire_lcb_access(dd, 0) == 0) {
4746 *data = read_csr(dd, addr);
4747 release_lcb_access(dd, 0);
4748 return 0;
4749 }
4750 return -EBUSY;
4751 }
4752
4753 /* register is an index of LCB registers: (offset - base) / 8 */
4754 regno = (addr - DC_LCB_CFG_RUN) >> 3;
4755 ret = do_8051_command(dd, HCMD_READ_LCB_CSR, regno, data);
4756 if (ret != HCMD_SUCCESS)
4757 return -EBUSY;
4758 return 0;
4759}
4760
4761/*
4762 * Read an LCB CSR. Access may not be in host control, so check.
4763 * Return 0 on success, -EBUSY on failure.
4764 */
4765int read_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 *data)
4766{
4767 struct hfi1_pportdata *ppd = dd->pport;
4768
4769 /* if up, go through the 8051 for the value */
4770 if (ppd->host_link_state & HLS_UP)
4771 return read_lcb_via_8051(dd, addr, data);
4772 /* if going up or down, no access */
4773 if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE))
4774 return -EBUSY;
4775 /* otherwise, host has access */
4776 *data = read_csr(dd, addr);
4777 return 0;
4778}
4779
4780/*
4781 * Use the 8051 to write a LCB CSR.
4782 */
4783static int write_lcb_via_8051(struct hfi1_devdata *dd, u32 addr, u64 data)
4784{
Dean Luick3bf40d62015-11-06 20:07:04 -05004785 u32 regno;
4786 int ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -04004787
Dean Luick3bf40d62015-11-06 20:07:04 -05004788 if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR ||
4789 (dd->dc8051_ver < dc8051_ver(0, 20))) {
4790 if (acquire_lcb_access(dd, 0) == 0) {
4791 write_csr(dd, addr, data);
4792 release_lcb_access(dd, 0);
4793 return 0;
4794 }
4795 return -EBUSY;
Mike Marciniszyn77241052015-07-30 15:17:43 -04004796 }
Dean Luick3bf40d62015-11-06 20:07:04 -05004797
4798 /* register is an index of LCB registers: (offset - base) / 8 */
4799 regno = (addr - DC_LCB_CFG_RUN) >> 3;
4800 ret = do_8051_command(dd, HCMD_WRITE_LCB_CSR, regno, &data);
4801 if (ret != HCMD_SUCCESS)
4802 return -EBUSY;
4803 return 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04004804}
4805
4806/*
4807 * Write an LCB CSR. Access may not be in host control, so check.
4808 * Return 0 on success, -EBUSY on failure.
4809 */
4810int write_lcb_csr(struct hfi1_devdata *dd, u32 addr, u64 data)
4811{
4812 struct hfi1_pportdata *ppd = dd->pport;
4813
4814 /* if up, go through the 8051 for the value */
4815 if (ppd->host_link_state & HLS_UP)
4816 return write_lcb_via_8051(dd, addr, data);
4817 /* if going up or down, no access */
4818 if (ppd->host_link_state & (HLS_GOING_UP | HLS_GOING_OFFLINE))
4819 return -EBUSY;
4820 /* otherwise, host has access */
4821 write_csr(dd, addr, data);
4822 return 0;
4823}
4824
4825/*
4826 * Returns:
4827 * < 0 = Linux error, not able to get access
4828 * > 0 = 8051 command RETURN_CODE
4829 */
4830static int do_8051_command(
4831 struct hfi1_devdata *dd,
4832 u32 type,
4833 u64 in_data,
4834 u64 *out_data)
4835{
4836 u64 reg, completed;
4837 int return_code;
4838 unsigned long flags;
4839 unsigned long timeout;
4840
4841 hfi1_cdbg(DC8051, "type %d, data 0x%012llx", type, in_data);
4842
4843 /*
4844 * Alternative to holding the lock for a long time:
4845 * - keep busy wait - have other users bounce off
4846 */
4847 spin_lock_irqsave(&dd->dc8051_lock, flags);
4848
4849 /* We can't send any commands to the 8051 if it's in reset */
4850 if (dd->dc_shutdown) {
4851 return_code = -ENODEV;
4852 goto fail;
4853 }
4854
4855 /*
4856 * If an 8051 host command timed out previously, then the 8051 is
4857 * stuck.
4858 *
4859 * On first timeout, attempt to reset and restart the entire DC
4860 * block (including 8051). (Is this too big of a hammer?)
4861 *
4862 * If the 8051 times out a second time, the reset did not bring it
4863 * back to healthy life. In that case, fail any subsequent commands.
4864 */
4865 if (dd->dc8051_timed_out) {
4866 if (dd->dc8051_timed_out > 1) {
4867 dd_dev_err(dd,
4868 "Previous 8051 host command timed out, skipping command %u\n",
4869 type);
4870 return_code = -ENXIO;
4871 goto fail;
4872 }
4873 spin_unlock_irqrestore(&dd->dc8051_lock, flags);
4874 dc_shutdown(dd);
4875 dc_start(dd);
4876 spin_lock_irqsave(&dd->dc8051_lock, flags);
4877 }
4878
4879 /*
4880 * If there is no timeout, then the 8051 command interface is
4881 * waiting for a command.
4882 */
4883
4884 /*
Dean Luick3bf40d62015-11-06 20:07:04 -05004885 * When writing a LCB CSR, out_data contains the full value to
4886 * to be written, while in_data contains the relative LCB
4887 * address in 7:0. Do the work here, rather than the caller,
4888 * of distrubting the write data to where it needs to go:
4889 *
4890 * Write data
4891 * 39:00 -> in_data[47:8]
4892 * 47:40 -> DC8051_CFG_EXT_DEV_0.RETURN_CODE
4893 * 63:48 -> DC8051_CFG_EXT_DEV_0.RSP_DATA
4894 */
4895 if (type == HCMD_WRITE_LCB_CSR) {
4896 in_data |= ((*out_data) & 0xffffffffffull) << 8;
4897 reg = ((((*out_data) >> 40) & 0xff) <<
4898 DC_DC8051_CFG_EXT_DEV_0_RETURN_CODE_SHIFT)
4899 | ((((*out_data) >> 48) & 0xffff) <<
4900 DC_DC8051_CFG_EXT_DEV_0_RSP_DATA_SHIFT);
4901 write_csr(dd, DC_DC8051_CFG_EXT_DEV_0, reg);
4902 }
4903
4904 /*
Mike Marciniszyn77241052015-07-30 15:17:43 -04004905 * Do two writes: the first to stabilize the type and req_data, the
4906 * second to activate.
4907 */
4908 reg = ((u64)type & DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_MASK)
4909 << DC_DC8051_CFG_HOST_CMD_0_REQ_TYPE_SHIFT
4910 | (in_data & DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_MASK)
4911 << DC_DC8051_CFG_HOST_CMD_0_REQ_DATA_SHIFT;
4912 write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
4913 reg |= DC_DC8051_CFG_HOST_CMD_0_REQ_NEW_SMASK;
4914 write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, reg);
4915
4916 /* wait for completion, alternate: interrupt */
4917 timeout = jiffies + msecs_to_jiffies(DC8051_COMMAND_TIMEOUT);
4918 while (1) {
4919 reg = read_csr(dd, DC_DC8051_CFG_HOST_CMD_1);
4920 completed = reg & DC_DC8051_CFG_HOST_CMD_1_COMPLETED_SMASK;
4921 if (completed)
4922 break;
4923 if (time_after(jiffies, timeout)) {
4924 dd->dc8051_timed_out++;
4925 dd_dev_err(dd, "8051 host command %u timeout\n", type);
4926 if (out_data)
4927 *out_data = 0;
4928 return_code = -ETIMEDOUT;
4929 goto fail;
4930 }
4931 udelay(2);
4932 }
4933
4934 if (out_data) {
4935 *out_data = (reg >> DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_SHIFT)
4936 & DC_DC8051_CFG_HOST_CMD_1_RSP_DATA_MASK;
4937 if (type == HCMD_READ_LCB_CSR) {
4938 /* top 16 bits are in a different register */
4939 *out_data |= (read_csr(dd, DC_DC8051_CFG_EXT_DEV_1)
4940 & DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SMASK)
4941 << (48
4942 - DC_DC8051_CFG_EXT_DEV_1_REQ_DATA_SHIFT);
4943 }
4944 }
4945 return_code = (reg >> DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_SHIFT)
4946 & DC_DC8051_CFG_HOST_CMD_1_RETURN_CODE_MASK;
4947 dd->dc8051_timed_out = 0;
4948 /*
4949 * Clear command for next user.
4950 */
4951 write_csr(dd, DC_DC8051_CFG_HOST_CMD_0, 0);
4952
4953fail:
4954 spin_unlock_irqrestore(&dd->dc8051_lock, flags);
4955
4956 return return_code;
4957}
4958
4959static int set_physical_link_state(struct hfi1_devdata *dd, u64 state)
4960{
4961 return do_8051_command(dd, HCMD_CHANGE_PHY_STATE, state, NULL);
4962}
4963
4964static int load_8051_config(struct hfi1_devdata *dd, u8 field_id,
4965 u8 lane_id, u32 config_data)
4966{
4967 u64 data;
4968 int ret;
4969
4970 data = (u64)field_id << LOAD_DATA_FIELD_ID_SHIFT
4971 | (u64)lane_id << LOAD_DATA_LANE_ID_SHIFT
4972 | (u64)config_data << LOAD_DATA_DATA_SHIFT;
4973 ret = do_8051_command(dd, HCMD_LOAD_CONFIG_DATA, data, NULL);
4974 if (ret != HCMD_SUCCESS) {
4975 dd_dev_err(dd,
4976 "load 8051 config: field id %d, lane %d, err %d\n",
4977 (int)field_id, (int)lane_id, ret);
4978 }
4979 return ret;
4980}
4981
4982/*
4983 * Read the 8051 firmware "registers". Use the RAM directly. Always
4984 * set the result, even on error.
4985 * Return 0 on success, -errno on failure
4986 */
4987static int read_8051_config(struct hfi1_devdata *dd, u8 field_id, u8 lane_id,
4988 u32 *result)
4989{
4990 u64 big_data;
4991 u32 addr;
4992 int ret;
4993
4994 /* address start depends on the lane_id */
4995 if (lane_id < 4)
4996 addr = (4 * NUM_GENERAL_FIELDS)
4997 + (lane_id * 4 * NUM_LANE_FIELDS);
4998 else
4999 addr = 0;
5000 addr += field_id * 4;
5001
5002 /* read is in 8-byte chunks, hardware will truncate the address down */
5003 ret = read_8051_data(dd, addr, 8, &big_data);
5004
5005 if (ret == 0) {
5006 /* extract the 4 bytes we want */
5007 if (addr & 0x4)
5008 *result = (u32)(big_data >> 32);
5009 else
5010 *result = (u32)big_data;
5011 } else {
5012 *result = 0;
5013 dd_dev_err(dd, "%s: direct read failed, lane %d, field %d!\n",
5014 __func__, lane_id, field_id);
5015 }
5016
5017 return ret;
5018}
5019
5020static int write_vc_local_phy(struct hfi1_devdata *dd, u8 power_management,
5021 u8 continuous)
5022{
5023 u32 frame;
5024
5025 frame = continuous << CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT
5026 | power_management << POWER_MANAGEMENT_SHIFT;
5027 return load_8051_config(dd, VERIFY_CAP_LOCAL_PHY,
5028 GENERAL_CONFIG, frame);
5029}
5030
5031static int write_vc_local_fabric(struct hfi1_devdata *dd, u8 vau, u8 z, u8 vcu,
5032 u16 vl15buf, u8 crc_sizes)
5033{
5034 u32 frame;
5035
5036 frame = (u32)vau << VAU_SHIFT
5037 | (u32)z << Z_SHIFT
5038 | (u32)vcu << VCU_SHIFT
5039 | (u32)vl15buf << VL15BUF_SHIFT
5040 | (u32)crc_sizes << CRC_SIZES_SHIFT;
5041 return load_8051_config(dd, VERIFY_CAP_LOCAL_FABRIC,
5042 GENERAL_CONFIG, frame);
5043}
5044
5045static void read_vc_local_link_width(struct hfi1_devdata *dd, u8 *misc_bits,
5046 u8 *flag_bits, u16 *link_widths)
5047{
5048 u32 frame;
5049
5050 read_8051_config(dd, VERIFY_CAP_LOCAL_LINK_WIDTH, GENERAL_CONFIG,
5051 &frame);
5052 *misc_bits = (frame >> MISC_CONFIG_BITS_SHIFT) & MISC_CONFIG_BITS_MASK;
5053 *flag_bits = (frame >> LOCAL_FLAG_BITS_SHIFT) & LOCAL_FLAG_BITS_MASK;
5054 *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
5055}
5056
5057static int write_vc_local_link_width(struct hfi1_devdata *dd,
5058 u8 misc_bits,
5059 u8 flag_bits,
5060 u16 link_widths)
5061{
5062 u32 frame;
5063
5064 frame = (u32)misc_bits << MISC_CONFIG_BITS_SHIFT
5065 | (u32)flag_bits << LOCAL_FLAG_BITS_SHIFT
5066 | (u32)link_widths << LINK_WIDTH_SHIFT;
5067 return load_8051_config(dd, VERIFY_CAP_LOCAL_LINK_WIDTH, GENERAL_CONFIG,
5068 frame);
5069}
5070
5071static int write_local_device_id(struct hfi1_devdata *dd, u16 device_id,
5072 u8 device_rev)
5073{
5074 u32 frame;
5075
5076 frame = ((u32)device_id << LOCAL_DEVICE_ID_SHIFT)
5077 | ((u32)device_rev << LOCAL_DEVICE_REV_SHIFT);
5078 return load_8051_config(dd, LOCAL_DEVICE_ID, GENERAL_CONFIG, frame);
5079}
5080
5081static void read_remote_device_id(struct hfi1_devdata *dd, u16 *device_id,
5082 u8 *device_rev)
5083{
5084 u32 frame;
5085
5086 read_8051_config(dd, REMOTE_DEVICE_ID, GENERAL_CONFIG, &frame);
5087 *device_id = (frame >> REMOTE_DEVICE_ID_SHIFT) & REMOTE_DEVICE_ID_MASK;
5088 *device_rev = (frame >> REMOTE_DEVICE_REV_SHIFT)
5089 & REMOTE_DEVICE_REV_MASK;
5090}
5091
5092void read_misc_status(struct hfi1_devdata *dd, u8 *ver_a, u8 *ver_b)
5093{
5094 u32 frame;
5095
5096 read_8051_config(dd, MISC_STATUS, GENERAL_CONFIG, &frame);
5097 *ver_a = (frame >> STS_FM_VERSION_A_SHIFT) & STS_FM_VERSION_A_MASK;
5098 *ver_b = (frame >> STS_FM_VERSION_B_SHIFT) & STS_FM_VERSION_B_MASK;
5099}
5100
5101static void read_vc_remote_phy(struct hfi1_devdata *dd, u8 *power_management,
5102 u8 *continuous)
5103{
5104 u32 frame;
5105
5106 read_8051_config(dd, VERIFY_CAP_REMOTE_PHY, GENERAL_CONFIG, &frame);
5107 *power_management = (frame >> POWER_MANAGEMENT_SHIFT)
5108 & POWER_MANAGEMENT_MASK;
5109 *continuous = (frame >> CONTINIOUS_REMOTE_UPDATE_SUPPORT_SHIFT)
5110 & CONTINIOUS_REMOTE_UPDATE_SUPPORT_MASK;
5111}
5112
5113static void read_vc_remote_fabric(struct hfi1_devdata *dd, u8 *vau, u8 *z,
5114 u8 *vcu, u16 *vl15buf, u8 *crc_sizes)
5115{
5116 u32 frame;
5117
5118 read_8051_config(dd, VERIFY_CAP_REMOTE_FABRIC, GENERAL_CONFIG, &frame);
5119 *vau = (frame >> VAU_SHIFT) & VAU_MASK;
5120 *z = (frame >> Z_SHIFT) & Z_MASK;
5121 *vcu = (frame >> VCU_SHIFT) & VCU_MASK;
5122 *vl15buf = (frame >> VL15BUF_SHIFT) & VL15BUF_MASK;
5123 *crc_sizes = (frame >> CRC_SIZES_SHIFT) & CRC_SIZES_MASK;
5124}
5125
5126static void read_vc_remote_link_width(struct hfi1_devdata *dd,
5127 u8 *remote_tx_rate,
5128 u16 *link_widths)
5129{
5130 u32 frame;
5131
5132 read_8051_config(dd, VERIFY_CAP_REMOTE_LINK_WIDTH, GENERAL_CONFIG,
5133 &frame);
5134 *remote_tx_rate = (frame >> REMOTE_TX_RATE_SHIFT)
5135 & REMOTE_TX_RATE_MASK;
5136 *link_widths = (frame >> LINK_WIDTH_SHIFT) & LINK_WIDTH_MASK;
5137}
5138
5139static void read_local_lni(struct hfi1_devdata *dd, u8 *enable_lane_rx)
5140{
5141 u32 frame;
5142
5143 read_8051_config(dd, LOCAL_LNI_INFO, GENERAL_CONFIG, &frame);
5144 *enable_lane_rx = (frame >> ENABLE_LANE_RX_SHIFT) & ENABLE_LANE_RX_MASK;
5145}
5146
5147static void read_mgmt_allowed(struct hfi1_devdata *dd, u8 *mgmt_allowed)
5148{
5149 u32 frame;
5150
5151 read_8051_config(dd, REMOTE_LNI_INFO, GENERAL_CONFIG, &frame);
5152 *mgmt_allowed = (frame >> MGMT_ALLOWED_SHIFT) & MGMT_ALLOWED_MASK;
5153}
5154
5155static void read_last_local_state(struct hfi1_devdata *dd, u32 *lls)
5156{
5157 read_8051_config(dd, LAST_LOCAL_STATE_COMPLETE, GENERAL_CONFIG, lls);
5158}
5159
5160static void read_last_remote_state(struct hfi1_devdata *dd, u32 *lrs)
5161{
5162 read_8051_config(dd, LAST_REMOTE_STATE_COMPLETE, GENERAL_CONFIG, lrs);
5163}
5164
5165void hfi1_read_link_quality(struct hfi1_devdata *dd, u8 *link_quality)
5166{
5167 u32 frame;
5168 int ret;
5169
5170 *link_quality = 0;
5171 if (dd->pport->host_link_state & HLS_UP) {
5172 ret = read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG,
5173 &frame);
5174 if (ret == 0)
5175 *link_quality = (frame >> LINK_QUALITY_SHIFT)
5176 & LINK_QUALITY_MASK;
5177 }
5178}
5179
5180static void read_planned_down_reason_code(struct hfi1_devdata *dd, u8 *pdrrc)
5181{
5182 u32 frame;
5183
5184 read_8051_config(dd, LINK_QUALITY_INFO, GENERAL_CONFIG, &frame);
5185 *pdrrc = (frame >> DOWN_REMOTE_REASON_SHIFT) & DOWN_REMOTE_REASON_MASK;
5186}
5187
5188static int read_tx_settings(struct hfi1_devdata *dd,
5189 u8 *enable_lane_tx,
5190 u8 *tx_polarity_inversion,
5191 u8 *rx_polarity_inversion,
5192 u8 *max_rate)
5193{
5194 u32 frame;
5195 int ret;
5196
5197 ret = read_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, &frame);
5198 *enable_lane_tx = (frame >> ENABLE_LANE_TX_SHIFT)
5199 & ENABLE_LANE_TX_MASK;
5200 *tx_polarity_inversion = (frame >> TX_POLARITY_INVERSION_SHIFT)
5201 & TX_POLARITY_INVERSION_MASK;
5202 *rx_polarity_inversion = (frame >> RX_POLARITY_INVERSION_SHIFT)
5203 & RX_POLARITY_INVERSION_MASK;
5204 *max_rate = (frame >> MAX_RATE_SHIFT) & MAX_RATE_MASK;
5205 return ret;
5206}
5207
5208static int write_tx_settings(struct hfi1_devdata *dd,
5209 u8 enable_lane_tx,
5210 u8 tx_polarity_inversion,
5211 u8 rx_polarity_inversion,
5212 u8 max_rate)
5213{
5214 u32 frame;
5215
5216 /* no need to mask, all variable sizes match field widths */
5217 frame = enable_lane_tx << ENABLE_LANE_TX_SHIFT
5218 | tx_polarity_inversion << TX_POLARITY_INVERSION_SHIFT
5219 | rx_polarity_inversion << RX_POLARITY_INVERSION_SHIFT
5220 | max_rate << MAX_RATE_SHIFT;
5221 return load_8051_config(dd, TX_SETTINGS, GENERAL_CONFIG, frame);
5222}
5223
5224static void check_fabric_firmware_versions(struct hfi1_devdata *dd)
5225{
5226 u32 frame, version, prod_id;
5227 int ret, lane;
5228
5229 /* 4 lanes */
5230 for (lane = 0; lane < 4; lane++) {
5231 ret = read_8051_config(dd, SPICO_FW_VERSION, lane, &frame);
5232 if (ret) {
5233 dd_dev_err(
5234 dd,
5235 "Unable to read lane %d firmware details\n",
5236 lane);
5237 continue;
5238 }
5239 version = (frame >> SPICO_ROM_VERSION_SHIFT)
5240 & SPICO_ROM_VERSION_MASK;
5241 prod_id = (frame >> SPICO_ROM_PROD_ID_SHIFT)
5242 & SPICO_ROM_PROD_ID_MASK;
5243 dd_dev_info(dd,
5244 "Lane %d firmware: version 0x%04x, prod_id 0x%04x\n",
5245 lane, version, prod_id);
5246 }
5247}
5248
5249/*
5250 * Read an idle LCB message.
5251 *
5252 * Returns 0 on success, -EINVAL on error
5253 */
5254static int read_idle_message(struct hfi1_devdata *dd, u64 type, u64 *data_out)
5255{
5256 int ret;
5257
5258 ret = do_8051_command(dd, HCMD_READ_LCB_IDLE_MSG,
5259 type, data_out);
5260 if (ret != HCMD_SUCCESS) {
5261 dd_dev_err(dd, "read idle message: type %d, err %d\n",
5262 (u32)type, ret);
5263 return -EINVAL;
5264 }
5265 dd_dev_info(dd, "%s: read idle message 0x%llx\n", __func__, *data_out);
5266 /* return only the payload as we already know the type */
5267 *data_out >>= IDLE_PAYLOAD_SHIFT;
5268 return 0;
5269}
5270
5271/*
5272 * Read an idle SMA message. To be done in response to a notification from
5273 * the 8051.
5274 *
5275 * Returns 0 on success, -EINVAL on error
5276 */
5277static int read_idle_sma(struct hfi1_devdata *dd, u64 *data)
5278{
5279 return read_idle_message(dd,
5280 (u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT, data);
5281}
5282
5283/*
5284 * Send an idle LCB message.
5285 *
5286 * Returns 0 on success, -EINVAL on error
5287 */
5288static int send_idle_message(struct hfi1_devdata *dd, u64 data)
5289{
5290 int ret;
5291
5292 dd_dev_info(dd, "%s: sending idle message 0x%llx\n", __func__, data);
5293 ret = do_8051_command(dd, HCMD_SEND_LCB_IDLE_MSG, data, NULL);
5294 if (ret != HCMD_SUCCESS) {
5295 dd_dev_err(dd, "send idle message: data 0x%llx, err %d\n",
5296 data, ret);
5297 return -EINVAL;
5298 }
5299 return 0;
5300}
5301
5302/*
5303 * Send an idle SMA message.
5304 *
5305 * Returns 0 on success, -EINVAL on error
5306 */
5307int send_idle_sma(struct hfi1_devdata *dd, u64 message)
5308{
5309 u64 data;
5310
5311 data = ((message & IDLE_PAYLOAD_MASK) << IDLE_PAYLOAD_SHIFT)
5312 | ((u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT);
5313 return send_idle_message(dd, data);
5314}
5315
5316/*
5317 * Initialize the LCB then do a quick link up. This may or may not be
5318 * in loopback.
5319 *
5320 * return 0 on success, -errno on error
5321 */
5322static int do_quick_linkup(struct hfi1_devdata *dd)
5323{
5324 u64 reg;
5325 unsigned long timeout;
5326 int ret;
5327
5328 lcb_shutdown(dd, 0);
5329
5330 if (loopback) {
5331 /* LCB_CFG_LOOPBACK.VAL = 2 */
5332 /* LCB_CFG_LANE_WIDTH.VAL = 0 */
5333 write_csr(dd, DC_LCB_CFG_LOOPBACK,
5334 IB_PACKET_TYPE << DC_LCB_CFG_LOOPBACK_VAL_SHIFT);
5335 write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
5336 }
5337
5338 /* start the LCBs */
5339 /* LCB_CFG_TX_FIFOS_RESET.VAL = 0 */
5340 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
5341
5342 /* simulator only loopback steps */
5343 if (loopback && dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
5344 /* LCB_CFG_RUN.EN = 1 */
5345 write_csr(dd, DC_LCB_CFG_RUN,
5346 1ull << DC_LCB_CFG_RUN_EN_SHIFT);
5347
5348 /* watch LCB_STS_LINK_TRANSFER_ACTIVE */
5349 timeout = jiffies + msecs_to_jiffies(10);
5350 while (1) {
5351 reg = read_csr(dd,
5352 DC_LCB_STS_LINK_TRANSFER_ACTIVE);
5353 if (reg)
5354 break;
5355 if (time_after(jiffies, timeout)) {
5356 dd_dev_err(dd,
5357 "timeout waiting for LINK_TRANSFER_ACTIVE\n");
5358 return -ETIMEDOUT;
5359 }
5360 udelay(2);
5361 }
5362
5363 write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP,
5364 1ull << DC_LCB_CFG_ALLOW_LINK_UP_VAL_SHIFT);
5365 }
5366
5367 if (!loopback) {
5368 /*
5369 * When doing quick linkup and not in loopback, both
5370 * sides must be done with LCB set-up before either
5371 * starts the quick linkup. Put a delay here so that
5372 * both sides can be started and have a chance to be
5373 * done with LCB set up before resuming.
5374 */
5375 dd_dev_err(dd,
5376 "Pausing for peer to be finished with LCB set up\n");
5377 msleep(5000);
5378 dd_dev_err(dd,
5379 "Continuing with quick linkup\n");
5380 }
5381
5382 write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
5383 set_8051_lcb_access(dd);
5384
5385 /*
5386 * State "quick" LinkUp request sets the physical link state to
5387 * LinkUp without a verify capability sequence.
5388 * This state is in simulator v37 and later.
5389 */
5390 ret = set_physical_link_state(dd, PLS_QUICK_LINKUP);
5391 if (ret != HCMD_SUCCESS) {
5392 dd_dev_err(dd,
5393 "%s: set physical link state to quick LinkUp failed with return %d\n",
5394 __func__, ret);
5395
5396 set_host_lcb_access(dd);
5397 write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
5398
5399 if (ret >= 0)
5400 ret = -EINVAL;
5401 return ret;
5402 }
5403
5404 return 0; /* success */
5405}
5406
5407/*
5408 * Set the SerDes to internal loopback mode.
5409 * Returns 0 on success, -errno on error.
5410 */
5411static int set_serdes_loopback_mode(struct hfi1_devdata *dd)
5412{
5413 int ret;
5414
5415 ret = set_physical_link_state(dd, PLS_INTERNAL_SERDES_LOOPBACK);
5416 if (ret == HCMD_SUCCESS)
5417 return 0;
5418 dd_dev_err(dd,
5419 "Set physical link state to SerDes Loopback failed with return %d\n",
5420 ret);
5421 if (ret >= 0)
5422 ret = -EINVAL;
5423 return ret;
5424}
5425
5426/*
5427 * Do all special steps to set up loopback.
5428 */
5429static int init_loopback(struct hfi1_devdata *dd)
5430{
5431 dd_dev_info(dd, "Entering loopback mode\n");
5432
5433 /* all loopbacks should disable self GUID check */
5434 write_csr(dd, DC_DC8051_CFG_MODE,
5435 (read_csr(dd, DC_DC8051_CFG_MODE) | DISABLE_SELF_GUID_CHECK));
5436
5437 /*
5438 * The simulator has only one loopback option - LCB. Switch
5439 * to that option, which includes quick link up.
5440 *
5441 * Accept all valid loopback values.
5442 */
5443 if ((dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
5444 && (loopback == LOOPBACK_SERDES
5445 || loopback == LOOPBACK_LCB
5446 || loopback == LOOPBACK_CABLE)) {
5447 loopback = LOOPBACK_LCB;
5448 quick_linkup = 1;
5449 return 0;
5450 }
5451
5452 /* handle serdes loopback */
5453 if (loopback == LOOPBACK_SERDES) {
5454 /* internal serdes loopack needs quick linkup on RTL */
5455 if (dd->icode == ICODE_RTL_SILICON)
5456 quick_linkup = 1;
5457 return set_serdes_loopback_mode(dd);
5458 }
5459
5460 /* LCB loopback - handled at poll time */
5461 if (loopback == LOOPBACK_LCB) {
5462 quick_linkup = 1; /* LCB is always quick linkup */
5463
5464 /* not supported in emulation due to emulation RTL changes */
5465 if (dd->icode == ICODE_FPGA_EMULATION) {
5466 dd_dev_err(dd,
5467 "LCB loopback not supported in emulation\n");
5468 return -EINVAL;
5469 }
5470 return 0;
5471 }
5472
5473 /* external cable loopback requires no extra steps */
5474 if (loopback == LOOPBACK_CABLE)
5475 return 0;
5476
5477 dd_dev_err(dd, "Invalid loopback mode %d\n", loopback);
5478 return -EINVAL;
5479}
5480
5481/*
5482 * Translate from the OPA_LINK_WIDTH handed to us by the FM to bits
5483 * used in the Verify Capability link width attribute.
5484 */
5485static u16 opa_to_vc_link_widths(u16 opa_widths)
5486{
5487 int i;
5488 u16 result = 0;
5489
5490 static const struct link_bits {
5491 u16 from;
5492 u16 to;
5493 } opa_link_xlate[] = {
5494 { OPA_LINK_WIDTH_1X, 1 << (1-1) },
5495 { OPA_LINK_WIDTH_2X, 1 << (2-1) },
5496 { OPA_LINK_WIDTH_3X, 1 << (3-1) },
5497 { OPA_LINK_WIDTH_4X, 1 << (4-1) },
5498 };
5499
5500 for (i = 0; i < ARRAY_SIZE(opa_link_xlate); i++) {
5501 if (opa_widths & opa_link_xlate[i].from)
5502 result |= opa_link_xlate[i].to;
5503 }
5504 return result;
5505}
5506
5507/*
5508 * Set link attributes before moving to polling.
5509 */
5510static int set_local_link_attributes(struct hfi1_pportdata *ppd)
5511{
5512 struct hfi1_devdata *dd = ppd->dd;
5513 u8 enable_lane_tx;
5514 u8 tx_polarity_inversion;
5515 u8 rx_polarity_inversion;
5516 int ret;
5517
5518 /* reset our fabric serdes to clear any lingering problems */
5519 fabric_serdes_reset(dd);
5520
5521 /* set the local tx rate - need to read-modify-write */
5522 ret = read_tx_settings(dd, &enable_lane_tx, &tx_polarity_inversion,
5523 &rx_polarity_inversion, &ppd->local_tx_rate);
5524 if (ret)
5525 goto set_local_link_attributes_fail;
5526
5527 if (dd->dc8051_ver < dc8051_ver(0, 20)) {
5528 /* set the tx rate to the fastest enabled */
5529 if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
5530 ppd->local_tx_rate = 1;
5531 else
5532 ppd->local_tx_rate = 0;
5533 } else {
5534 /* set the tx rate to all enabled */
5535 ppd->local_tx_rate = 0;
5536 if (ppd->link_speed_enabled & OPA_LINK_SPEED_25G)
5537 ppd->local_tx_rate |= 2;
5538 if (ppd->link_speed_enabled & OPA_LINK_SPEED_12_5G)
5539 ppd->local_tx_rate |= 1;
5540 }
Easwar Hariharanfebffe22015-10-26 10:28:36 -04005541
5542 enable_lane_tx = 0xF; /* enable all four lanes */
Mike Marciniszyn77241052015-07-30 15:17:43 -04005543 ret = write_tx_settings(dd, enable_lane_tx, tx_polarity_inversion,
5544 rx_polarity_inversion, ppd->local_tx_rate);
5545 if (ret != HCMD_SUCCESS)
5546 goto set_local_link_attributes_fail;
5547
5548 /*
5549 * DC supports continuous updates.
5550 */
5551 ret = write_vc_local_phy(dd, 0 /* no power management */,
5552 1 /* continuous updates */);
5553 if (ret != HCMD_SUCCESS)
5554 goto set_local_link_attributes_fail;
5555
5556 /* z=1 in the next call: AU of 0 is not supported by the hardware */
5557 ret = write_vc_local_fabric(dd, dd->vau, 1, dd->vcu, dd->vl15_init,
5558 ppd->port_crc_mode_enabled);
5559 if (ret != HCMD_SUCCESS)
5560 goto set_local_link_attributes_fail;
5561
5562 ret = write_vc_local_link_width(dd, 0, 0,
5563 opa_to_vc_link_widths(ppd->link_width_enabled));
5564 if (ret != HCMD_SUCCESS)
5565 goto set_local_link_attributes_fail;
5566
5567 /* let peer know who we are */
5568 ret = write_local_device_id(dd, dd->pcidev->device, dd->minrev);
5569 if (ret == HCMD_SUCCESS)
5570 return 0;
5571
5572set_local_link_attributes_fail:
5573 dd_dev_err(dd,
5574 "Failed to set local link attributes, return 0x%x\n",
5575 ret);
5576 return ret;
5577}
5578
5579/*
5580 * Call this to start the link. Schedule a retry if the cable is not
5581 * present or if unable to start polling. Do not do anything if the
5582 * link is disabled. Returns 0 if link is disabled or moved to polling
5583 */
5584int start_link(struct hfi1_pportdata *ppd)
5585{
5586 if (!ppd->link_enabled) {
5587 dd_dev_info(ppd->dd,
5588 "%s: stopping link start because link is disabled\n",
5589 __func__);
5590 return 0;
5591 }
5592 if (!ppd->driver_link_ready) {
5593 dd_dev_info(ppd->dd,
5594 "%s: stopping link start because driver is not ready\n",
5595 __func__);
5596 return 0;
5597 }
5598
5599 if (qsfp_mod_present(ppd) || loopback == LOOPBACK_SERDES ||
5600 loopback == LOOPBACK_LCB ||
5601 ppd->dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
5602 return set_link_state(ppd, HLS_DN_POLL);
5603
5604 dd_dev_info(ppd->dd,
5605 "%s: stopping link start because no cable is present\n",
5606 __func__);
5607 return -EAGAIN;
5608}
5609
5610static void reset_qsfp(struct hfi1_pportdata *ppd)
5611{
5612 struct hfi1_devdata *dd = ppd->dd;
5613 u64 mask, qsfp_mask;
5614
5615 mask = (u64)QSFP_HFI0_RESET_N;
5616 qsfp_mask = read_csr(dd,
5617 dd->hfi1_id ? ASIC_QSFP2_OE : ASIC_QSFP1_OE);
5618 qsfp_mask |= mask;
5619 write_csr(dd,
5620 dd->hfi1_id ? ASIC_QSFP2_OE : ASIC_QSFP1_OE,
5621 qsfp_mask);
5622
5623 qsfp_mask = read_csr(dd,
5624 dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT);
5625 qsfp_mask &= ~mask;
5626 write_csr(dd,
5627 dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT,
5628 qsfp_mask);
5629
5630 udelay(10);
5631
5632 qsfp_mask |= mask;
5633 write_csr(dd,
5634 dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT,
5635 qsfp_mask);
5636}
5637
5638static int handle_qsfp_error_conditions(struct hfi1_pportdata *ppd,
5639 u8 *qsfp_interrupt_status)
5640{
5641 struct hfi1_devdata *dd = ppd->dd;
5642
5643 if ((qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_ALARM) ||
5644 (qsfp_interrupt_status[0] & QSFP_HIGH_TEMP_WARNING))
5645 dd_dev_info(dd,
5646 "%s: QSFP cable on fire\n",
5647 __func__);
5648
5649 if ((qsfp_interrupt_status[0] & QSFP_LOW_TEMP_ALARM) ||
5650 (qsfp_interrupt_status[0] & QSFP_LOW_TEMP_WARNING))
5651 dd_dev_info(dd,
5652 "%s: QSFP cable temperature too low\n",
5653 __func__);
5654
5655 if ((qsfp_interrupt_status[1] & QSFP_HIGH_VCC_ALARM) ||
5656 (qsfp_interrupt_status[1] & QSFP_HIGH_VCC_WARNING))
5657 dd_dev_info(dd,
5658 "%s: QSFP supply voltage too high\n",
5659 __func__);
5660
5661 if ((qsfp_interrupt_status[1] & QSFP_LOW_VCC_ALARM) ||
5662 (qsfp_interrupt_status[1] & QSFP_LOW_VCC_WARNING))
5663 dd_dev_info(dd,
5664 "%s: QSFP supply voltage too low\n",
5665 __func__);
5666
5667 /* Byte 2 is vendor specific */
5668
5669 if ((qsfp_interrupt_status[3] & QSFP_HIGH_POWER_ALARM) ||
5670 (qsfp_interrupt_status[3] & QSFP_HIGH_POWER_WARNING))
5671 dd_dev_info(dd,
5672 "%s: Cable RX channel 1/2 power too high\n",
5673 __func__);
5674
5675 if ((qsfp_interrupt_status[3] & QSFP_LOW_POWER_ALARM) ||
5676 (qsfp_interrupt_status[3] & QSFP_LOW_POWER_WARNING))
5677 dd_dev_info(dd,
5678 "%s: Cable RX channel 1/2 power too low\n",
5679 __func__);
5680
5681 if ((qsfp_interrupt_status[4] & QSFP_HIGH_POWER_ALARM) ||
5682 (qsfp_interrupt_status[4] & QSFP_HIGH_POWER_WARNING))
5683 dd_dev_info(dd,
5684 "%s: Cable RX channel 3/4 power too high\n",
5685 __func__);
5686
5687 if ((qsfp_interrupt_status[4] & QSFP_LOW_POWER_ALARM) ||
5688 (qsfp_interrupt_status[4] & QSFP_LOW_POWER_WARNING))
5689 dd_dev_info(dd,
5690 "%s: Cable RX channel 3/4 power too low\n",
5691 __func__);
5692
5693 if ((qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_ALARM) ||
5694 (qsfp_interrupt_status[5] & QSFP_HIGH_BIAS_WARNING))
5695 dd_dev_info(dd,
5696 "%s: Cable TX channel 1/2 bias too high\n",
5697 __func__);
5698
5699 if ((qsfp_interrupt_status[5] & QSFP_LOW_BIAS_ALARM) ||
5700 (qsfp_interrupt_status[5] & QSFP_LOW_BIAS_WARNING))
5701 dd_dev_info(dd,
5702 "%s: Cable TX channel 1/2 bias too low\n",
5703 __func__);
5704
5705 if ((qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_ALARM) ||
5706 (qsfp_interrupt_status[6] & QSFP_HIGH_BIAS_WARNING))
5707 dd_dev_info(dd,
5708 "%s: Cable TX channel 3/4 bias too high\n",
5709 __func__);
5710
5711 if ((qsfp_interrupt_status[6] & QSFP_LOW_BIAS_ALARM) ||
5712 (qsfp_interrupt_status[6] & QSFP_LOW_BIAS_WARNING))
5713 dd_dev_info(dd,
5714 "%s: Cable TX channel 3/4 bias too low\n",
5715 __func__);
5716
5717 if ((qsfp_interrupt_status[7] & QSFP_HIGH_POWER_ALARM) ||
5718 (qsfp_interrupt_status[7] & QSFP_HIGH_POWER_WARNING))
5719 dd_dev_info(dd,
5720 "%s: Cable TX channel 1/2 power too high\n",
5721 __func__);
5722
5723 if ((qsfp_interrupt_status[7] & QSFP_LOW_POWER_ALARM) ||
5724 (qsfp_interrupt_status[7] & QSFP_LOW_POWER_WARNING))
5725 dd_dev_info(dd,
5726 "%s: Cable TX channel 1/2 power too low\n",
5727 __func__);
5728
5729 if ((qsfp_interrupt_status[8] & QSFP_HIGH_POWER_ALARM) ||
5730 (qsfp_interrupt_status[8] & QSFP_HIGH_POWER_WARNING))
5731 dd_dev_info(dd,
5732 "%s: Cable TX channel 3/4 power too high\n",
5733 __func__);
5734
5735 if ((qsfp_interrupt_status[8] & QSFP_LOW_POWER_ALARM) ||
5736 (qsfp_interrupt_status[8] & QSFP_LOW_POWER_WARNING))
5737 dd_dev_info(dd,
5738 "%s: Cable TX channel 3/4 power too low\n",
5739 __func__);
5740
5741 /* Bytes 9-10 and 11-12 are reserved */
5742 /* Bytes 13-15 are vendor specific */
5743
5744 return 0;
5745}
5746
5747static int do_pre_lni_host_behaviors(struct hfi1_pportdata *ppd)
5748{
5749 refresh_qsfp_cache(ppd, &ppd->qsfp_info);
5750
5751 return 0;
5752}
5753
5754static int do_qsfp_intr_fallback(struct hfi1_pportdata *ppd)
5755{
5756 struct hfi1_devdata *dd = ppd->dd;
5757 u8 qsfp_interrupt_status = 0;
5758
5759 if (qsfp_read(ppd, dd->hfi1_id, 2, &qsfp_interrupt_status, 1)
5760 != 1) {
5761 dd_dev_info(dd,
5762 "%s: Failed to read status of QSFP module\n",
5763 __func__);
5764 return -EIO;
5765 }
5766
5767 /* We don't care about alarms & warnings with a non-functional INT_N */
5768 if (!(qsfp_interrupt_status & QSFP_DATA_NOT_READY))
5769 do_pre_lni_host_behaviors(ppd);
5770
5771 return 0;
5772}
5773
5774/* This routine will only be scheduled if the QSFP module is present */
5775static void qsfp_event(struct work_struct *work)
5776{
5777 struct qsfp_data *qd;
5778 struct hfi1_pportdata *ppd;
5779 struct hfi1_devdata *dd;
5780
5781 qd = container_of(work, struct qsfp_data, qsfp_work);
5782 ppd = qd->ppd;
5783 dd = ppd->dd;
5784
5785 /* Sanity check */
5786 if (!qsfp_mod_present(ppd))
5787 return;
5788
5789 /*
5790 * Turn DC back on after cables has been
5791 * re-inserted. Up until now, the DC has been in
5792 * reset to save power.
5793 */
5794 dc_start(dd);
5795
5796 if (qd->cache_refresh_required) {
5797 msleep(3000);
5798 reset_qsfp(ppd);
5799
5800 /* Check for QSFP interrupt after t_init (SFF 8679)
5801 * + extra
5802 */
5803 msleep(3000);
5804 if (!qd->qsfp_interrupt_functional) {
5805 if (do_qsfp_intr_fallback(ppd) < 0)
5806 dd_dev_info(dd, "%s: QSFP fallback failed\n",
5807 __func__);
5808 ppd->driver_link_ready = 1;
5809 start_link(ppd);
5810 }
5811 }
5812
5813 if (qd->check_interrupt_flags) {
5814 u8 qsfp_interrupt_status[16] = {0,};
5815
5816 if (qsfp_read(ppd, dd->hfi1_id, 6,
5817 &qsfp_interrupt_status[0], 16) != 16) {
5818 dd_dev_info(dd,
5819 "%s: Failed to read status of QSFP module\n",
5820 __func__);
5821 } else {
5822 unsigned long flags;
5823 u8 data_status;
5824
5825 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags);
5826 ppd->qsfp_info.check_interrupt_flags = 0;
5827 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock,
5828 flags);
5829
5830 if (qsfp_read(ppd, dd->hfi1_id, 2, &data_status, 1)
5831 != 1) {
5832 dd_dev_info(dd,
5833 "%s: Failed to read status of QSFP module\n",
5834 __func__);
5835 }
5836 if (!(data_status & QSFP_DATA_NOT_READY)) {
5837 do_pre_lni_host_behaviors(ppd);
5838 start_link(ppd);
5839 } else
5840 handle_qsfp_error_conditions(ppd,
5841 qsfp_interrupt_status);
5842 }
5843 }
5844}
5845
5846void init_qsfp(struct hfi1_pportdata *ppd)
5847{
5848 struct hfi1_devdata *dd = ppd->dd;
5849 u64 qsfp_mask;
5850
5851 if (loopback == LOOPBACK_SERDES || loopback == LOOPBACK_LCB ||
Easwar Hariharan3c2f85b2015-10-26 10:28:31 -04005852 ppd->dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04005853 ppd->driver_link_ready = 1;
5854 return;
5855 }
5856
5857 ppd->qsfp_info.ppd = ppd;
5858 INIT_WORK(&ppd->qsfp_info.qsfp_work, qsfp_event);
5859
5860 qsfp_mask = (u64)(QSFP_HFI0_INT_N | QSFP_HFI0_MODPRST_N);
5861 /* Clear current status to avoid spurious interrupts */
5862 write_csr(dd,
5863 dd->hfi1_id ?
5864 ASIC_QSFP2_CLEAR :
5865 ASIC_QSFP1_CLEAR,
5866 qsfp_mask);
5867
5868 /* Handle active low nature of INT_N and MODPRST_N pins */
5869 if (qsfp_mod_present(ppd))
5870 qsfp_mask &= ~(u64)QSFP_HFI0_MODPRST_N;
5871 write_csr(dd,
5872 dd->hfi1_id ? ASIC_QSFP2_INVERT : ASIC_QSFP1_INVERT,
5873 qsfp_mask);
5874
5875 /* Allow only INT_N and MODPRST_N to trigger QSFP interrupts */
5876 qsfp_mask |= (u64)QSFP_HFI0_MODPRST_N;
5877 write_csr(dd,
5878 dd->hfi1_id ? ASIC_QSFP2_MASK : ASIC_QSFP1_MASK,
5879 qsfp_mask);
5880
5881 if (qsfp_mod_present(ppd)) {
5882 msleep(3000);
5883 reset_qsfp(ppd);
5884
5885 /* Check for QSFP interrupt after t_init (SFF 8679)
5886 * + extra
5887 */
5888 msleep(3000);
5889 if (!ppd->qsfp_info.qsfp_interrupt_functional) {
5890 if (do_qsfp_intr_fallback(ppd) < 0)
5891 dd_dev_info(dd,
5892 "%s: QSFP fallback failed\n",
5893 __func__);
5894 ppd->driver_link_ready = 1;
5895 }
5896 }
5897}
5898
Dean Luickbbdeb332015-12-01 15:38:15 -05005899/*
5900 * Do a one-time initialize of the LCB block.
5901 */
5902static void init_lcb(struct hfi1_devdata *dd)
5903{
5904 /* the DC has been reset earlier in the driver load */
5905
5906 /* set LCB for cclk loopback on the port */
5907 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x01);
5908 write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0x00);
5909 write_csr(dd, DC_LCB_CFG_REINIT_AS_SLAVE, 0x00);
5910 write_csr(dd, DC_LCB_CFG_CNT_FOR_SKIP_STALL, 0x110);
5911 write_csr(dd, DC_LCB_CFG_CLK_CNTR, 0x08);
5912 write_csr(dd, DC_LCB_CFG_LOOPBACK, 0x02);
5913 write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0x00);
5914}
5915
Mike Marciniszyn77241052015-07-30 15:17:43 -04005916int bringup_serdes(struct hfi1_pportdata *ppd)
5917{
5918 struct hfi1_devdata *dd = ppd->dd;
5919 u64 guid;
5920 int ret;
5921
5922 if (HFI1_CAP_IS_KSET(EXTENDED_PSN))
5923 add_rcvctrl(dd, RCV_CTRL_RCV_EXTENDED_PSN_ENABLE_SMASK);
5924
5925 guid = ppd->guid;
5926 if (!guid) {
5927 if (dd->base_guid)
5928 guid = dd->base_guid + ppd->port - 1;
5929 ppd->guid = guid;
5930 }
5931
5932 /* the link defaults to enabled */
5933 ppd->link_enabled = 1;
5934 /* Set linkinit_reason on power up per OPA spec */
5935 ppd->linkinit_reason = OPA_LINKINIT_REASON_LINKUP;
5936
Dean Luickbbdeb332015-12-01 15:38:15 -05005937 /* one-time init of the LCB */
5938 init_lcb(dd);
5939
Mike Marciniszyn77241052015-07-30 15:17:43 -04005940 if (loopback) {
5941 ret = init_loopback(dd);
5942 if (ret < 0)
5943 return ret;
5944 }
5945
5946 return start_link(ppd);
5947}
5948
5949void hfi1_quiet_serdes(struct hfi1_pportdata *ppd)
5950{
5951 struct hfi1_devdata *dd = ppd->dd;
5952
5953 /*
5954 * Shut down the link and keep it down. First turn off that the
5955 * driver wants to allow the link to be up (driver_link_ready).
5956 * Then make sure the link is not automatically restarted
5957 * (link_enabled). Cancel any pending restart. And finally
5958 * go offline.
5959 */
5960 ppd->driver_link_ready = 0;
5961 ppd->link_enabled = 0;
5962
5963 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_SMA_DISABLED, 0,
5964 OPA_LINKDOWN_REASON_SMA_DISABLED);
5965 set_link_state(ppd, HLS_DN_OFFLINE);
5966
5967 /* disable the port */
5968 clear_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
5969}
5970
5971static inline int init_cpu_counters(struct hfi1_devdata *dd)
5972{
5973 struct hfi1_pportdata *ppd;
5974 int i;
5975
5976 ppd = (struct hfi1_pportdata *)(dd + 1);
5977 for (i = 0; i < dd->num_pports; i++, ppd++) {
5978 ppd->ibport_data.rc_acks = NULL;
5979 ppd->ibport_data.rc_qacks = NULL;
5980 ppd->ibport_data.rc_acks = alloc_percpu(u64);
5981 ppd->ibport_data.rc_qacks = alloc_percpu(u64);
5982 ppd->ibport_data.rc_delayed_comp = alloc_percpu(u64);
5983 if ((ppd->ibport_data.rc_acks == NULL) ||
5984 (ppd->ibport_data.rc_delayed_comp == NULL) ||
5985 (ppd->ibport_data.rc_qacks == NULL))
5986 return -ENOMEM;
5987 }
5988
5989 return 0;
5990}
5991
5992static const char * const pt_names[] = {
5993 "expected",
5994 "eager",
5995 "invalid"
5996};
5997
5998static const char *pt_name(u32 type)
5999{
6000 return type >= ARRAY_SIZE(pt_names) ? "unknown" : pt_names[type];
6001}
6002
6003/*
6004 * index is the index into the receive array
6005 */
6006void hfi1_put_tid(struct hfi1_devdata *dd, u32 index,
6007 u32 type, unsigned long pa, u16 order)
6008{
6009 u64 reg;
6010 void __iomem *base = (dd->rcvarray_wc ? dd->rcvarray_wc :
6011 (dd->kregbase + RCV_ARRAY));
6012
6013 if (!(dd->flags & HFI1_PRESENT))
6014 goto done;
6015
6016 if (type == PT_INVALID) {
6017 pa = 0;
6018 } else if (type > PT_INVALID) {
6019 dd_dev_err(dd,
6020 "unexpected receive array type %u for index %u, not handled\n",
6021 type, index);
6022 goto done;
6023 }
6024
6025 hfi1_cdbg(TID, "type %s, index 0x%x, pa 0x%lx, bsize 0x%lx",
6026 pt_name(type), index, pa, (unsigned long)order);
6027
6028#define RT_ADDR_SHIFT 12 /* 4KB kernel address boundary */
6029 reg = RCV_ARRAY_RT_WRITE_ENABLE_SMASK
6030 | (u64)order << RCV_ARRAY_RT_BUF_SIZE_SHIFT
6031 | ((pa >> RT_ADDR_SHIFT) & RCV_ARRAY_RT_ADDR_MASK)
6032 << RCV_ARRAY_RT_ADDR_SHIFT;
6033 writeq(reg, base + (index * 8));
6034
6035 if (type == PT_EAGER)
6036 /*
6037 * Eager entries are written one-by-one so we have to push them
6038 * after we write the entry.
6039 */
6040 flush_wc();
6041done:
6042 return;
6043}
6044
6045void hfi1_clear_tids(struct hfi1_ctxtdata *rcd)
6046{
6047 struct hfi1_devdata *dd = rcd->dd;
6048 u32 i;
6049
6050 /* this could be optimized */
6051 for (i = rcd->eager_base; i < rcd->eager_base +
6052 rcd->egrbufs.alloced; i++)
6053 hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
6054
6055 for (i = rcd->expected_base;
6056 i < rcd->expected_base + rcd->expected_count; i++)
6057 hfi1_put_tid(dd, i, PT_INVALID, 0, 0);
6058}
6059
6060int hfi1_get_base_kinfo(struct hfi1_ctxtdata *rcd,
6061 struct hfi1_ctxt_info *kinfo)
6062{
6063 kinfo->runtime_flags = (HFI1_MISC_GET() << HFI1_CAP_USER_SHIFT) |
6064 HFI1_CAP_UGET(MASK) | HFI1_CAP_KGET(K2U);
6065 return 0;
6066}
6067
6068struct hfi1_message_header *hfi1_get_msgheader(
6069 struct hfi1_devdata *dd, __le32 *rhf_addr)
6070{
6071 u32 offset = rhf_hdrq_offset(rhf_to_cpu(rhf_addr));
6072
6073 return (struct hfi1_message_header *)
6074 (rhf_addr - dd->rhf_offset + offset);
6075}
6076
6077static const char * const ib_cfg_name_strings[] = {
6078 "HFI1_IB_CFG_LIDLMC",
6079 "HFI1_IB_CFG_LWID_DG_ENB",
6080 "HFI1_IB_CFG_LWID_ENB",
6081 "HFI1_IB_CFG_LWID",
6082 "HFI1_IB_CFG_SPD_ENB",
6083 "HFI1_IB_CFG_SPD",
6084 "HFI1_IB_CFG_RXPOL_ENB",
6085 "HFI1_IB_CFG_LREV_ENB",
6086 "HFI1_IB_CFG_LINKLATENCY",
6087 "HFI1_IB_CFG_HRTBT",
6088 "HFI1_IB_CFG_OP_VLS",
6089 "HFI1_IB_CFG_VL_HIGH_CAP",
6090 "HFI1_IB_CFG_VL_LOW_CAP",
6091 "HFI1_IB_CFG_OVERRUN_THRESH",
6092 "HFI1_IB_CFG_PHYERR_THRESH",
6093 "HFI1_IB_CFG_LINKDEFAULT",
6094 "HFI1_IB_CFG_PKEYS",
6095 "HFI1_IB_CFG_MTU",
6096 "HFI1_IB_CFG_LSTATE",
6097 "HFI1_IB_CFG_VL_HIGH_LIMIT",
6098 "HFI1_IB_CFG_PMA_TICKS",
6099 "HFI1_IB_CFG_PORT"
6100};
6101
6102static const char *ib_cfg_name(int which)
6103{
6104 if (which < 0 || which >= ARRAY_SIZE(ib_cfg_name_strings))
6105 return "invalid";
6106 return ib_cfg_name_strings[which];
6107}
6108
6109int hfi1_get_ib_cfg(struct hfi1_pportdata *ppd, int which)
6110{
6111 struct hfi1_devdata *dd = ppd->dd;
6112 int val = 0;
6113
6114 switch (which) {
6115 case HFI1_IB_CFG_LWID_ENB: /* allowed Link-width */
6116 val = ppd->link_width_enabled;
6117 break;
6118 case HFI1_IB_CFG_LWID: /* currently active Link-width */
6119 val = ppd->link_width_active;
6120 break;
6121 case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
6122 val = ppd->link_speed_enabled;
6123 break;
6124 case HFI1_IB_CFG_SPD: /* current Link speed */
6125 val = ppd->link_speed_active;
6126 break;
6127
6128 case HFI1_IB_CFG_RXPOL_ENB: /* Auto-RX-polarity enable */
6129 case HFI1_IB_CFG_LREV_ENB: /* Auto-Lane-reversal enable */
6130 case HFI1_IB_CFG_LINKLATENCY:
6131 goto unimplemented;
6132
6133 case HFI1_IB_CFG_OP_VLS:
6134 val = ppd->vls_operational;
6135 break;
6136 case HFI1_IB_CFG_VL_HIGH_CAP: /* VL arb high priority table size */
6137 val = VL_ARB_HIGH_PRIO_TABLE_SIZE;
6138 break;
6139 case HFI1_IB_CFG_VL_LOW_CAP: /* VL arb low priority table size */
6140 val = VL_ARB_LOW_PRIO_TABLE_SIZE;
6141 break;
6142 case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
6143 val = ppd->overrun_threshold;
6144 break;
6145 case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
6146 val = ppd->phy_error_threshold;
6147 break;
6148 case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
6149 val = dd->link_default;
6150 break;
6151
6152 case HFI1_IB_CFG_HRTBT: /* Heartbeat off/enable/auto */
6153 case HFI1_IB_CFG_PMA_TICKS:
6154 default:
6155unimplemented:
6156 if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
6157 dd_dev_info(
6158 dd,
6159 "%s: which %s: not implemented\n",
6160 __func__,
6161 ib_cfg_name(which));
6162 break;
6163 }
6164
6165 return val;
6166}
6167
6168/*
6169 * The largest MAD packet size.
6170 */
6171#define MAX_MAD_PACKET 2048
6172
6173/*
6174 * Return the maximum header bytes that can go on the _wire_
6175 * for this device. This count includes the ICRC which is
6176 * not part of the packet held in memory but it is appended
6177 * by the HW.
6178 * This is dependent on the device's receive header entry size.
6179 * HFI allows this to be set per-receive context, but the
6180 * driver presently enforces a global value.
6181 */
6182u32 lrh_max_header_bytes(struct hfi1_devdata *dd)
6183{
6184 /*
6185 * The maximum non-payload (MTU) bytes in LRH.PktLen are
6186 * the Receive Header Entry Size minus the PBC (or RHF) size
6187 * plus one DW for the ICRC appended by HW.
6188 *
6189 * dd->rcd[0].rcvhdrqentsize is in DW.
6190 * We use rcd[0] as all context will have the same value. Also,
6191 * the first kernel context would have been allocated by now so
6192 * we are guaranteed a valid value.
6193 */
6194 return (dd->rcd[0]->rcvhdrqentsize - 2/*PBC/RHF*/ + 1/*ICRC*/) << 2;
6195}
6196
6197/*
6198 * Set Send Length
6199 * @ppd - per port data
6200 *
6201 * Set the MTU by limiting how many DWs may be sent. The SendLenCheck*
6202 * registers compare against LRH.PktLen, so use the max bytes included
6203 * in the LRH.
6204 *
6205 * This routine changes all VL values except VL15, which it maintains at
6206 * the same value.
6207 */
6208static void set_send_length(struct hfi1_pportdata *ppd)
6209{
6210 struct hfi1_devdata *dd = ppd->dd;
6211 u32 max_hb = lrh_max_header_bytes(dd), maxvlmtu = 0, dcmtu;
6212 u64 len1 = 0, len2 = (((dd->vld[15].mtu + max_hb) >> 2)
6213 & SEND_LEN_CHECK1_LEN_VL15_MASK) <<
6214 SEND_LEN_CHECK1_LEN_VL15_SHIFT;
6215 int i;
6216
6217 for (i = 0; i < ppd->vls_supported; i++) {
6218 if (dd->vld[i].mtu > maxvlmtu)
6219 maxvlmtu = dd->vld[i].mtu;
6220 if (i <= 3)
6221 len1 |= (((dd->vld[i].mtu + max_hb) >> 2)
6222 & SEND_LEN_CHECK0_LEN_VL0_MASK) <<
6223 ((i % 4) * SEND_LEN_CHECK0_LEN_VL1_SHIFT);
6224 else
6225 len2 |= (((dd->vld[i].mtu + max_hb) >> 2)
6226 & SEND_LEN_CHECK1_LEN_VL4_MASK) <<
6227 ((i % 4) * SEND_LEN_CHECK1_LEN_VL5_SHIFT);
6228 }
6229 write_csr(dd, SEND_LEN_CHECK0, len1);
6230 write_csr(dd, SEND_LEN_CHECK1, len2);
6231 /* adjust kernel credit return thresholds based on new MTUs */
6232 /* all kernel receive contexts have the same hdrqentsize */
6233 for (i = 0; i < ppd->vls_supported; i++) {
6234 sc_set_cr_threshold(dd->vld[i].sc,
6235 sc_mtu_to_threshold(dd->vld[i].sc, dd->vld[i].mtu,
6236 dd->rcd[0]->rcvhdrqentsize));
6237 }
6238 sc_set_cr_threshold(dd->vld[15].sc,
6239 sc_mtu_to_threshold(dd->vld[15].sc, dd->vld[15].mtu,
6240 dd->rcd[0]->rcvhdrqentsize));
6241
6242 /* Adjust maximum MTU for the port in DC */
6243 dcmtu = maxvlmtu == 10240 ? DCC_CFG_PORT_MTU_CAP_10240 :
6244 (ilog2(maxvlmtu >> 8) + 1);
6245 len1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG);
6246 len1 &= ~DCC_CFG_PORT_CONFIG_MTU_CAP_SMASK;
6247 len1 |= ((u64)dcmtu & DCC_CFG_PORT_CONFIG_MTU_CAP_MASK) <<
6248 DCC_CFG_PORT_CONFIG_MTU_CAP_SHIFT;
6249 write_csr(ppd->dd, DCC_CFG_PORT_CONFIG, len1);
6250}
6251
6252static void set_lidlmc(struct hfi1_pportdata *ppd)
6253{
6254 int i;
6255 u64 sreg = 0;
6256 struct hfi1_devdata *dd = ppd->dd;
6257 u32 mask = ~((1U << ppd->lmc) - 1);
6258 u64 c1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG1);
6259
6260 if (dd->hfi1_snoop.mode_flag)
6261 dd_dev_info(dd, "Set lid/lmc while snooping");
6262
6263 c1 &= ~(DCC_CFG_PORT_CONFIG1_TARGET_DLID_SMASK
6264 | DCC_CFG_PORT_CONFIG1_DLID_MASK_SMASK);
6265 c1 |= ((ppd->lid & DCC_CFG_PORT_CONFIG1_TARGET_DLID_MASK)
6266 << DCC_CFG_PORT_CONFIG1_TARGET_DLID_SHIFT)|
6267 ((mask & DCC_CFG_PORT_CONFIG1_DLID_MASK_MASK)
6268 << DCC_CFG_PORT_CONFIG1_DLID_MASK_SHIFT);
6269 write_csr(ppd->dd, DCC_CFG_PORT_CONFIG1, c1);
6270
6271 /*
6272 * Iterate over all the send contexts and set their SLID check
6273 */
6274 sreg = ((mask & SEND_CTXT_CHECK_SLID_MASK_MASK) <<
6275 SEND_CTXT_CHECK_SLID_MASK_SHIFT) |
6276 (((ppd->lid & mask) & SEND_CTXT_CHECK_SLID_VALUE_MASK) <<
6277 SEND_CTXT_CHECK_SLID_VALUE_SHIFT);
6278
6279 for (i = 0; i < dd->chip_send_contexts; i++) {
6280 hfi1_cdbg(LINKVERB, "SendContext[%d].SLID_CHECK = 0x%x",
6281 i, (u32)sreg);
6282 write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, sreg);
6283 }
6284
6285 /* Now we have to do the same thing for the sdma engines */
6286 sdma_update_lmc(dd, mask, ppd->lid);
6287}
6288
6289static int wait_phy_linkstate(struct hfi1_devdata *dd, u32 state, u32 msecs)
6290{
6291 unsigned long timeout;
6292 u32 curr_state;
6293
6294 timeout = jiffies + msecs_to_jiffies(msecs);
6295 while (1) {
6296 curr_state = read_physical_state(dd);
6297 if (curr_state == state)
6298 break;
6299 if (time_after(jiffies, timeout)) {
6300 dd_dev_err(dd,
6301 "timeout waiting for phy link state 0x%x, current state is 0x%x\n",
6302 state, curr_state);
6303 return -ETIMEDOUT;
6304 }
6305 usleep_range(1950, 2050); /* sleep 2ms-ish */
6306 }
6307
6308 return 0;
6309}
6310
6311/*
6312 * Helper for set_link_state(). Do not call except from that routine.
6313 * Expects ppd->hls_mutex to be held.
6314 *
6315 * @rem_reason value to be sent to the neighbor
6316 *
6317 * LinkDownReasons only set if transition succeeds.
6318 */
6319static int goto_offline(struct hfi1_pportdata *ppd, u8 rem_reason)
6320{
6321 struct hfi1_devdata *dd = ppd->dd;
6322 u32 pstate, previous_state;
6323 u32 last_local_state;
6324 u32 last_remote_state;
6325 int ret;
6326 int do_transition;
6327 int do_wait;
6328
6329 previous_state = ppd->host_link_state;
6330 ppd->host_link_state = HLS_GOING_OFFLINE;
6331 pstate = read_physical_state(dd);
6332 if (pstate == PLS_OFFLINE) {
6333 do_transition = 0; /* in right state */
6334 do_wait = 0; /* ...no need to wait */
6335 } else if ((pstate & 0xff) == PLS_OFFLINE) {
6336 do_transition = 0; /* in an offline transient state */
6337 do_wait = 1; /* ...wait for it to settle */
6338 } else {
6339 do_transition = 1; /* need to move to offline */
6340 do_wait = 1; /* ...will need to wait */
6341 }
6342
6343 if (do_transition) {
6344 ret = set_physical_link_state(dd,
6345 PLS_OFFLINE | (rem_reason << 8));
6346
6347 if (ret != HCMD_SUCCESS) {
6348 dd_dev_err(dd,
6349 "Failed to transition to Offline link state, return %d\n",
6350 ret);
6351 return -EINVAL;
6352 }
6353 if (ppd->offline_disabled_reason == OPA_LINKDOWN_REASON_NONE)
6354 ppd->offline_disabled_reason =
6355 OPA_LINKDOWN_REASON_TRANSIENT;
6356 }
6357
6358 if (do_wait) {
6359 /* it can take a while for the link to go down */
Dean Luickdc060242015-10-26 10:28:29 -04006360 ret = wait_phy_linkstate(dd, PLS_OFFLINE, 10000);
Mike Marciniszyn77241052015-07-30 15:17:43 -04006361 if (ret < 0)
6362 return ret;
6363 }
6364
6365 /* make sure the logical state is also down */
6366 wait_logical_linkstate(ppd, IB_PORT_DOWN, 1000);
6367
6368 /*
6369 * Now in charge of LCB - must be after the physical state is
6370 * offline.quiet and before host_link_state is changed.
6371 */
6372 set_host_lcb_access(dd);
6373 write_csr(dd, DC_LCB_ERR_EN, ~0ull); /* watch LCB errors */
6374 ppd->host_link_state = HLS_LINK_COOLDOWN; /* LCB access allowed */
6375
6376 /*
6377 * The LNI has a mandatory wait time after the physical state
6378 * moves to Offline.Quiet. The wait time may be different
6379 * depending on how the link went down. The 8051 firmware
6380 * will observe the needed wait time and only move to ready
6381 * when that is completed. The largest of the quiet timeouts
6382 * is 2.5s, so wait that long and then a bit more.
6383 */
6384 ret = wait_fm_ready(dd, 3000);
6385 if (ret) {
6386 dd_dev_err(dd,
6387 "After going offline, timed out waiting for the 8051 to become ready to accept host requests\n");
6388 /* state is really offline, so make it so */
6389 ppd->host_link_state = HLS_DN_OFFLINE;
6390 return ret;
6391 }
6392
6393 /*
6394 * The state is now offline and the 8051 is ready to accept host
6395 * requests.
6396 * - change our state
6397 * - notify others if we were previously in a linkup state
6398 */
6399 ppd->host_link_state = HLS_DN_OFFLINE;
6400 if (previous_state & HLS_UP) {
6401 /* went down while link was up */
6402 handle_linkup_change(dd, 0);
6403 } else if (previous_state
6404 & (HLS_DN_POLL | HLS_VERIFY_CAP | HLS_GOING_UP)) {
6405 /* went down while attempting link up */
6406 /* byte 1 of last_*_state is the failure reason */
6407 read_last_local_state(dd, &last_local_state);
6408 read_last_remote_state(dd, &last_remote_state);
6409 dd_dev_err(dd,
6410 "LNI failure last states: local 0x%08x, remote 0x%08x\n",
6411 last_local_state, last_remote_state);
6412 }
6413
6414 /* the active link width (downgrade) is 0 on link down */
6415 ppd->link_width_active = 0;
6416 ppd->link_width_downgrade_tx_active = 0;
6417 ppd->link_width_downgrade_rx_active = 0;
6418 ppd->current_egress_rate = 0;
6419 return 0;
6420}
6421
6422/* return the link state name */
6423static const char *link_state_name(u32 state)
6424{
6425 const char *name;
6426 int n = ilog2(state);
6427 static const char * const names[] = {
6428 [__HLS_UP_INIT_BP] = "INIT",
6429 [__HLS_UP_ARMED_BP] = "ARMED",
6430 [__HLS_UP_ACTIVE_BP] = "ACTIVE",
6431 [__HLS_DN_DOWNDEF_BP] = "DOWNDEF",
6432 [__HLS_DN_POLL_BP] = "POLL",
6433 [__HLS_DN_DISABLE_BP] = "DISABLE",
6434 [__HLS_DN_OFFLINE_BP] = "OFFLINE",
6435 [__HLS_VERIFY_CAP_BP] = "VERIFY_CAP",
6436 [__HLS_GOING_UP_BP] = "GOING_UP",
6437 [__HLS_GOING_OFFLINE_BP] = "GOING_OFFLINE",
6438 [__HLS_LINK_COOLDOWN_BP] = "LINK_COOLDOWN"
6439 };
6440
6441 name = n < ARRAY_SIZE(names) ? names[n] : NULL;
6442 return name ? name : "unknown";
6443}
6444
6445/* return the link state reason name */
6446static const char *link_state_reason_name(struct hfi1_pportdata *ppd, u32 state)
6447{
6448 if (state == HLS_UP_INIT) {
6449 switch (ppd->linkinit_reason) {
6450 case OPA_LINKINIT_REASON_LINKUP:
6451 return "(LINKUP)";
6452 case OPA_LINKINIT_REASON_FLAPPING:
6453 return "(FLAPPING)";
6454 case OPA_LINKINIT_OUTSIDE_POLICY:
6455 return "(OUTSIDE_POLICY)";
6456 case OPA_LINKINIT_QUARANTINED:
6457 return "(QUARANTINED)";
6458 case OPA_LINKINIT_INSUFIC_CAPABILITY:
6459 return "(INSUFIC_CAPABILITY)";
6460 default:
6461 break;
6462 }
6463 }
6464 return "";
6465}
6466
6467/*
6468 * driver_physical_state - convert the driver's notion of a port's
6469 * state (an HLS_*) into a physical state (a {IB,OPA}_PORTPHYSSTATE_*).
6470 * Return -1 (converted to a u32) to indicate error.
6471 */
6472u32 driver_physical_state(struct hfi1_pportdata *ppd)
6473{
6474 switch (ppd->host_link_state) {
6475 case HLS_UP_INIT:
6476 case HLS_UP_ARMED:
6477 case HLS_UP_ACTIVE:
6478 return IB_PORTPHYSSTATE_LINKUP;
6479 case HLS_DN_POLL:
6480 return IB_PORTPHYSSTATE_POLLING;
6481 case HLS_DN_DISABLE:
6482 return IB_PORTPHYSSTATE_DISABLED;
6483 case HLS_DN_OFFLINE:
6484 return OPA_PORTPHYSSTATE_OFFLINE;
6485 case HLS_VERIFY_CAP:
6486 return IB_PORTPHYSSTATE_POLLING;
6487 case HLS_GOING_UP:
6488 return IB_PORTPHYSSTATE_POLLING;
6489 case HLS_GOING_OFFLINE:
6490 return OPA_PORTPHYSSTATE_OFFLINE;
6491 case HLS_LINK_COOLDOWN:
6492 return OPA_PORTPHYSSTATE_OFFLINE;
6493 case HLS_DN_DOWNDEF:
6494 default:
6495 dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
6496 ppd->host_link_state);
6497 return -1;
6498 }
6499}
6500
6501/*
6502 * driver_logical_state - convert the driver's notion of a port's
6503 * state (an HLS_*) into a logical state (a IB_PORT_*). Return -1
6504 * (converted to a u32) to indicate error.
6505 */
6506u32 driver_logical_state(struct hfi1_pportdata *ppd)
6507{
6508 if (ppd->host_link_state && !(ppd->host_link_state & HLS_UP))
6509 return IB_PORT_DOWN;
6510
6511 switch (ppd->host_link_state & HLS_UP) {
6512 case HLS_UP_INIT:
6513 return IB_PORT_INIT;
6514 case HLS_UP_ARMED:
6515 return IB_PORT_ARMED;
6516 case HLS_UP_ACTIVE:
6517 return IB_PORT_ACTIVE;
6518 default:
6519 dd_dev_err(ppd->dd, "invalid host_link_state 0x%x\n",
6520 ppd->host_link_state);
6521 return -1;
6522 }
6523}
6524
6525void set_link_down_reason(struct hfi1_pportdata *ppd, u8 lcl_reason,
6526 u8 neigh_reason, u8 rem_reason)
6527{
6528 if (ppd->local_link_down_reason.latest == 0 &&
6529 ppd->neigh_link_down_reason.latest == 0) {
6530 ppd->local_link_down_reason.latest = lcl_reason;
6531 ppd->neigh_link_down_reason.latest = neigh_reason;
6532 ppd->remote_link_down_reason = rem_reason;
6533 }
6534}
6535
6536/*
6537 * Change the physical and/or logical link state.
6538 *
6539 * Do not call this routine while inside an interrupt. It contains
6540 * calls to routines that can take multiple seconds to finish.
6541 *
6542 * Returns 0 on success, -errno on failure.
6543 */
6544int set_link_state(struct hfi1_pportdata *ppd, u32 state)
6545{
6546 struct hfi1_devdata *dd = ppd->dd;
6547 struct ib_event event = {.device = NULL};
6548 int ret1, ret = 0;
6549 int was_up, is_down;
6550 int orig_new_state, poll_bounce;
6551
6552 mutex_lock(&ppd->hls_lock);
6553
6554 orig_new_state = state;
6555 if (state == HLS_DN_DOWNDEF)
6556 state = dd->link_default;
6557
6558 /* interpret poll -> poll as a link bounce */
6559 poll_bounce = ppd->host_link_state == HLS_DN_POLL
6560 && state == HLS_DN_POLL;
6561
6562 dd_dev_info(dd, "%s: current %s, new %s %s%s\n", __func__,
6563 link_state_name(ppd->host_link_state),
6564 link_state_name(orig_new_state),
6565 poll_bounce ? "(bounce) " : "",
6566 link_state_reason_name(ppd, state));
6567
6568 was_up = !!(ppd->host_link_state & HLS_UP);
6569
6570 /*
6571 * If we're going to a (HLS_*) link state that implies the logical
6572 * link state is neither of (IB_PORT_ARMED, IB_PORT_ACTIVE), then
6573 * reset is_sm_config_started to 0.
6574 */
6575 if (!(state & (HLS_UP_ARMED | HLS_UP_ACTIVE)))
6576 ppd->is_sm_config_started = 0;
6577
6578 /*
6579 * Do nothing if the states match. Let a poll to poll link bounce
6580 * go through.
6581 */
6582 if (ppd->host_link_state == state && !poll_bounce)
6583 goto done;
6584
6585 switch (state) {
6586 case HLS_UP_INIT:
6587 if (ppd->host_link_state == HLS_DN_POLL && (quick_linkup
6588 || dd->icode == ICODE_FUNCTIONAL_SIMULATOR)) {
6589 /*
6590 * Quick link up jumps from polling to here.
6591 *
6592 * Whether in normal or loopback mode, the
6593 * simulator jumps from polling to link up.
6594 * Accept that here.
6595 */
6596 /* OK */;
6597 } else if (ppd->host_link_state != HLS_GOING_UP) {
6598 goto unexpected;
6599 }
6600
6601 ppd->host_link_state = HLS_UP_INIT;
6602 ret = wait_logical_linkstate(ppd, IB_PORT_INIT, 1000);
6603 if (ret) {
6604 /* logical state didn't change, stay at going_up */
6605 ppd->host_link_state = HLS_GOING_UP;
6606 dd_dev_err(dd,
6607 "%s: logical state did not change to INIT\n",
6608 __func__);
6609 } else {
6610 /* clear old transient LINKINIT_REASON code */
6611 if (ppd->linkinit_reason >= OPA_LINKINIT_REASON_CLEAR)
6612 ppd->linkinit_reason =
6613 OPA_LINKINIT_REASON_LINKUP;
6614
6615 /* enable the port */
6616 add_rcvctrl(dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK);
6617
6618 handle_linkup_change(dd, 1);
6619 }
6620 break;
6621 case HLS_UP_ARMED:
6622 if (ppd->host_link_state != HLS_UP_INIT)
6623 goto unexpected;
6624
6625 ppd->host_link_state = HLS_UP_ARMED;
6626 set_logical_state(dd, LSTATE_ARMED);
6627 ret = wait_logical_linkstate(ppd, IB_PORT_ARMED, 1000);
6628 if (ret) {
6629 /* logical state didn't change, stay at init */
6630 ppd->host_link_state = HLS_UP_INIT;
6631 dd_dev_err(dd,
6632 "%s: logical state did not change to ARMED\n",
6633 __func__);
6634 }
6635 /*
6636 * The simulator does not currently implement SMA messages,
6637 * so neighbor_normal is not set. Set it here when we first
6638 * move to Armed.
6639 */
6640 if (dd->icode == ICODE_FUNCTIONAL_SIMULATOR)
6641 ppd->neighbor_normal = 1;
6642 break;
6643 case HLS_UP_ACTIVE:
6644 if (ppd->host_link_state != HLS_UP_ARMED)
6645 goto unexpected;
6646
6647 ppd->host_link_state = HLS_UP_ACTIVE;
6648 set_logical_state(dd, LSTATE_ACTIVE);
6649 ret = wait_logical_linkstate(ppd, IB_PORT_ACTIVE, 1000);
6650 if (ret) {
6651 /* logical state didn't change, stay at armed */
6652 ppd->host_link_state = HLS_UP_ARMED;
6653 dd_dev_err(dd,
6654 "%s: logical state did not change to ACTIVE\n",
6655 __func__);
6656 } else {
6657
6658 /* tell all engines to go running */
6659 sdma_all_running(dd);
6660
6661 /* Signal the IB layer that the port has went active */
6662 event.device = &dd->verbs_dev.ibdev;
6663 event.element.port_num = ppd->port;
6664 event.event = IB_EVENT_PORT_ACTIVE;
6665 }
6666 break;
6667 case HLS_DN_POLL:
6668 if ((ppd->host_link_state == HLS_DN_DISABLE ||
6669 ppd->host_link_state == HLS_DN_OFFLINE) &&
6670 dd->dc_shutdown)
6671 dc_start(dd);
6672 /* Hand LED control to the DC */
6673 write_csr(dd, DCC_CFG_LED_CNTRL, 0);
6674
6675 if (ppd->host_link_state != HLS_DN_OFFLINE) {
6676 u8 tmp = ppd->link_enabled;
6677
6678 ret = goto_offline(ppd, ppd->remote_link_down_reason);
6679 if (ret) {
6680 ppd->link_enabled = tmp;
6681 break;
6682 }
6683 ppd->remote_link_down_reason = 0;
6684
6685 if (ppd->driver_link_ready)
6686 ppd->link_enabled = 1;
6687 }
6688
6689 ret = set_local_link_attributes(ppd);
6690 if (ret)
6691 break;
6692
6693 ppd->port_error_action = 0;
6694 ppd->host_link_state = HLS_DN_POLL;
6695
6696 if (quick_linkup) {
6697 /* quick linkup does not go into polling */
6698 ret = do_quick_linkup(dd);
6699 } else {
6700 ret1 = set_physical_link_state(dd, PLS_POLLING);
6701 if (ret1 != HCMD_SUCCESS) {
6702 dd_dev_err(dd,
6703 "Failed to transition to Polling link state, return 0x%x\n",
6704 ret1);
6705 ret = -EINVAL;
6706 }
6707 }
6708 ppd->offline_disabled_reason = OPA_LINKDOWN_REASON_NONE;
6709 /*
6710 * If an error occurred above, go back to offline. The
6711 * caller may reschedule another attempt.
6712 */
6713 if (ret)
6714 goto_offline(ppd, 0);
6715 break;
6716 case HLS_DN_DISABLE:
6717 /* link is disabled */
6718 ppd->link_enabled = 0;
6719
6720 /* allow any state to transition to disabled */
6721
6722 /* must transition to offline first */
6723 if (ppd->host_link_state != HLS_DN_OFFLINE) {
6724 ret = goto_offline(ppd, ppd->remote_link_down_reason);
6725 if (ret)
6726 break;
6727 ppd->remote_link_down_reason = 0;
6728 }
6729
6730 ret1 = set_physical_link_state(dd, PLS_DISABLED);
6731 if (ret1 != HCMD_SUCCESS) {
6732 dd_dev_err(dd,
6733 "Failed to transition to Disabled link state, return 0x%x\n",
6734 ret1);
6735 ret = -EINVAL;
6736 break;
6737 }
6738 ppd->host_link_state = HLS_DN_DISABLE;
6739 dc_shutdown(dd);
6740 break;
6741 case HLS_DN_OFFLINE:
6742 if (ppd->host_link_state == HLS_DN_DISABLE)
6743 dc_start(dd);
6744
6745 /* allow any state to transition to offline */
6746 ret = goto_offline(ppd, ppd->remote_link_down_reason);
6747 if (!ret)
6748 ppd->remote_link_down_reason = 0;
6749 break;
6750 case HLS_VERIFY_CAP:
6751 if (ppd->host_link_state != HLS_DN_POLL)
6752 goto unexpected;
6753 ppd->host_link_state = HLS_VERIFY_CAP;
6754 break;
6755 case HLS_GOING_UP:
6756 if (ppd->host_link_state != HLS_VERIFY_CAP)
6757 goto unexpected;
6758
6759 ret1 = set_physical_link_state(dd, PLS_LINKUP);
6760 if (ret1 != HCMD_SUCCESS) {
6761 dd_dev_err(dd,
6762 "Failed to transition to link up state, return 0x%x\n",
6763 ret1);
6764 ret = -EINVAL;
6765 break;
6766 }
6767 ppd->host_link_state = HLS_GOING_UP;
6768 break;
6769
6770 case HLS_GOING_OFFLINE: /* transient within goto_offline() */
6771 case HLS_LINK_COOLDOWN: /* transient within goto_offline() */
6772 default:
6773 dd_dev_info(dd, "%s: state 0x%x: not supported\n",
6774 __func__, state);
6775 ret = -EINVAL;
6776 break;
6777 }
6778
6779 is_down = !!(ppd->host_link_state & (HLS_DN_POLL |
6780 HLS_DN_DISABLE | HLS_DN_OFFLINE));
6781
6782 if (was_up && is_down && ppd->local_link_down_reason.sma == 0 &&
6783 ppd->neigh_link_down_reason.sma == 0) {
6784 ppd->local_link_down_reason.sma =
6785 ppd->local_link_down_reason.latest;
6786 ppd->neigh_link_down_reason.sma =
6787 ppd->neigh_link_down_reason.latest;
6788 }
6789
6790 goto done;
6791
6792unexpected:
6793 dd_dev_err(dd, "%s: unexpected state transition from %s to %s\n",
6794 __func__, link_state_name(ppd->host_link_state),
6795 link_state_name(state));
6796 ret = -EINVAL;
6797
6798done:
6799 mutex_unlock(&ppd->hls_lock);
6800
6801 if (event.device)
6802 ib_dispatch_event(&event);
6803
6804 return ret;
6805}
6806
6807int hfi1_set_ib_cfg(struct hfi1_pportdata *ppd, int which, u32 val)
6808{
6809 u64 reg;
6810 int ret = 0;
6811
6812 switch (which) {
6813 case HFI1_IB_CFG_LIDLMC:
6814 set_lidlmc(ppd);
6815 break;
6816 case HFI1_IB_CFG_VL_HIGH_LIMIT:
6817 /*
6818 * The VL Arbitrator high limit is sent in units of 4k
6819 * bytes, while HFI stores it in units of 64 bytes.
6820 */
6821 val *= 4096/64;
6822 reg = ((u64)val & SEND_HIGH_PRIORITY_LIMIT_LIMIT_MASK)
6823 << SEND_HIGH_PRIORITY_LIMIT_LIMIT_SHIFT;
6824 write_csr(ppd->dd, SEND_HIGH_PRIORITY_LIMIT, reg);
6825 break;
6826 case HFI1_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
6827 /* HFI only supports POLL as the default link down state */
6828 if (val != HLS_DN_POLL)
6829 ret = -EINVAL;
6830 break;
6831 case HFI1_IB_CFG_OP_VLS:
6832 if (ppd->vls_operational != val) {
6833 ppd->vls_operational = val;
6834 if (!ppd->port)
6835 ret = -EINVAL;
6836 else
6837 ret = sdma_map_init(
6838 ppd->dd,
6839 ppd->port - 1,
6840 val,
6841 NULL);
6842 }
6843 break;
6844 /*
6845 * For link width, link width downgrade, and speed enable, always AND
6846 * the setting with what is actually supported. This has two benefits.
6847 * First, enabled can't have unsupported values, no matter what the
6848 * SM or FM might want. Second, the ALL_SUPPORTED wildcards that mean
6849 * "fill in with your supported value" have all the bits in the
6850 * field set, so simply ANDing with supported has the desired result.
6851 */
6852 case HFI1_IB_CFG_LWID_ENB: /* set allowed Link-width */
6853 ppd->link_width_enabled = val & ppd->link_width_supported;
6854 break;
6855 case HFI1_IB_CFG_LWID_DG_ENB: /* set allowed link width downgrade */
6856 ppd->link_width_downgrade_enabled =
6857 val & ppd->link_width_downgrade_supported;
6858 break;
6859 case HFI1_IB_CFG_SPD_ENB: /* allowed Link speeds */
6860 ppd->link_speed_enabled = val & ppd->link_speed_supported;
6861 break;
6862 case HFI1_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
6863 /*
6864 * HFI does not follow IB specs, save this value
6865 * so we can report it, if asked.
6866 */
6867 ppd->overrun_threshold = val;
6868 break;
6869 case HFI1_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
6870 /*
6871 * HFI does not follow IB specs, save this value
6872 * so we can report it, if asked.
6873 */
6874 ppd->phy_error_threshold = val;
6875 break;
6876
6877 case HFI1_IB_CFG_MTU:
6878 set_send_length(ppd);
6879 break;
6880
6881 case HFI1_IB_CFG_PKEYS:
6882 if (HFI1_CAP_IS_KSET(PKEY_CHECK))
6883 set_partition_keys(ppd);
6884 break;
6885
6886 default:
6887 if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
6888 dd_dev_info(ppd->dd,
6889 "%s: which %s, val 0x%x: not implemented\n",
6890 __func__, ib_cfg_name(which), val);
6891 break;
6892 }
6893 return ret;
6894}
6895
6896/* begin functions related to vl arbitration table caching */
6897static void init_vl_arb_caches(struct hfi1_pportdata *ppd)
6898{
6899 int i;
6900
6901 BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
6902 VL_ARB_LOW_PRIO_TABLE_SIZE);
6903 BUILD_BUG_ON(VL_ARB_TABLE_SIZE !=
6904 VL_ARB_HIGH_PRIO_TABLE_SIZE);
6905
6906 /*
6907 * Note that we always return values directly from the
6908 * 'vl_arb_cache' (and do no CSR reads) in response to a
6909 * 'Get(VLArbTable)'. This is obviously correct after a
6910 * 'Set(VLArbTable)', since the cache will then be up to
6911 * date. But it's also correct prior to any 'Set(VLArbTable)'
6912 * since then both the cache, and the relevant h/w registers
6913 * will be zeroed.
6914 */
6915
6916 for (i = 0; i < MAX_PRIO_TABLE; i++)
6917 spin_lock_init(&ppd->vl_arb_cache[i].lock);
6918}
6919
6920/*
6921 * vl_arb_lock_cache
6922 *
6923 * All other vl_arb_* functions should be called only after locking
6924 * the cache.
6925 */
6926static inline struct vl_arb_cache *
6927vl_arb_lock_cache(struct hfi1_pportdata *ppd, int idx)
6928{
6929 if (idx != LO_PRIO_TABLE && idx != HI_PRIO_TABLE)
6930 return NULL;
6931 spin_lock(&ppd->vl_arb_cache[idx].lock);
6932 return &ppd->vl_arb_cache[idx];
6933}
6934
6935static inline void vl_arb_unlock_cache(struct hfi1_pportdata *ppd, int idx)
6936{
6937 spin_unlock(&ppd->vl_arb_cache[idx].lock);
6938}
6939
6940static void vl_arb_get_cache(struct vl_arb_cache *cache,
6941 struct ib_vl_weight_elem *vl)
6942{
6943 memcpy(vl, cache->table, VL_ARB_TABLE_SIZE * sizeof(*vl));
6944}
6945
6946static void vl_arb_set_cache(struct vl_arb_cache *cache,
6947 struct ib_vl_weight_elem *vl)
6948{
6949 memcpy(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
6950}
6951
6952static int vl_arb_match_cache(struct vl_arb_cache *cache,
6953 struct ib_vl_weight_elem *vl)
6954{
6955 return !memcmp(cache->table, vl, VL_ARB_TABLE_SIZE * sizeof(*vl));
6956}
6957/* end functions related to vl arbitration table caching */
6958
6959static int set_vl_weights(struct hfi1_pportdata *ppd, u32 target,
6960 u32 size, struct ib_vl_weight_elem *vl)
6961{
6962 struct hfi1_devdata *dd = ppd->dd;
6963 u64 reg;
6964 unsigned int i, is_up = 0;
6965 int drain, ret = 0;
6966
6967 mutex_lock(&ppd->hls_lock);
6968
6969 if (ppd->host_link_state & HLS_UP)
6970 is_up = 1;
6971
6972 drain = !is_ax(dd) && is_up;
6973
6974 if (drain)
6975 /*
6976 * Before adjusting VL arbitration weights, empty per-VL
6977 * FIFOs, otherwise a packet whose VL weight is being
6978 * set to 0 could get stuck in a FIFO with no chance to
6979 * egress.
6980 */
6981 ret = stop_drain_data_vls(dd);
6982
6983 if (ret) {
6984 dd_dev_err(
6985 dd,
6986 "%s: cannot stop/drain VLs - refusing to change VL arbitration weights\n",
6987 __func__);
6988 goto err;
6989 }
6990
6991 for (i = 0; i < size; i++, vl++) {
6992 /*
6993 * NOTE: The low priority shift and mask are used here, but
6994 * they are the same for both the low and high registers.
6995 */
6996 reg = (((u64)vl->vl & SEND_LOW_PRIORITY_LIST_VL_MASK)
6997 << SEND_LOW_PRIORITY_LIST_VL_SHIFT)
6998 | (((u64)vl->weight
6999 & SEND_LOW_PRIORITY_LIST_WEIGHT_MASK)
7000 << SEND_LOW_PRIORITY_LIST_WEIGHT_SHIFT);
7001 write_csr(dd, target + (i * 8), reg);
7002 }
7003 pio_send_control(dd, PSC_GLOBAL_VLARB_ENABLE);
7004
7005 if (drain)
7006 open_fill_data_vls(dd); /* reopen all VLs */
7007
7008err:
7009 mutex_unlock(&ppd->hls_lock);
7010
7011 return ret;
7012}
7013
7014/*
7015 * Read one credit merge VL register.
7016 */
7017static void read_one_cm_vl(struct hfi1_devdata *dd, u32 csr,
7018 struct vl_limit *vll)
7019{
7020 u64 reg = read_csr(dd, csr);
7021
7022 vll->dedicated = cpu_to_be16(
7023 (reg >> SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT)
7024 & SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_MASK);
7025 vll->shared = cpu_to_be16(
7026 (reg >> SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT)
7027 & SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_MASK);
7028}
7029
7030/*
7031 * Read the current credit merge limits.
7032 */
7033static int get_buffer_control(struct hfi1_devdata *dd,
7034 struct buffer_control *bc, u16 *overall_limit)
7035{
7036 u64 reg;
7037 int i;
7038
7039 /* not all entries are filled in */
7040 memset(bc, 0, sizeof(*bc));
7041
7042 /* OPA and HFI have a 1-1 mapping */
7043 for (i = 0; i < TXE_NUM_DATA_VL; i++)
7044 read_one_cm_vl(dd, SEND_CM_CREDIT_VL + (8*i), &bc->vl[i]);
7045
7046 /* NOTE: assumes that VL* and VL15 CSRs are bit-wise identical */
7047 read_one_cm_vl(dd, SEND_CM_CREDIT_VL15, &bc->vl[15]);
7048
7049 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
7050 bc->overall_shared_limit = cpu_to_be16(
7051 (reg >> SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT)
7052 & SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_MASK);
7053 if (overall_limit)
7054 *overall_limit = (reg
7055 >> SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT)
7056 & SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_MASK;
7057 return sizeof(struct buffer_control);
7058}
7059
7060static int get_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
7061{
7062 u64 reg;
7063 int i;
7064
7065 /* each register contains 16 SC->VLnt mappings, 4 bits each */
7066 reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_15_0);
7067 for (i = 0; i < sizeof(u64); i++) {
7068 u8 byte = *(((u8 *)&reg) + i);
7069
7070 dp->vlnt[2 * i] = byte & 0xf;
7071 dp->vlnt[(2 * i) + 1] = (byte & 0xf0) >> 4;
7072 }
7073
7074 reg = read_csr(dd, DCC_CFG_SC_VL_TABLE_31_16);
7075 for (i = 0; i < sizeof(u64); i++) {
7076 u8 byte = *(((u8 *)&reg) + i);
7077
7078 dp->vlnt[16 + (2 * i)] = byte & 0xf;
7079 dp->vlnt[16 + (2 * i) + 1] = (byte & 0xf0) >> 4;
7080 }
7081 return sizeof(struct sc2vlnt);
7082}
7083
7084static void get_vlarb_preempt(struct hfi1_devdata *dd, u32 nelems,
7085 struct ib_vl_weight_elem *vl)
7086{
7087 unsigned int i;
7088
7089 for (i = 0; i < nelems; i++, vl++) {
7090 vl->vl = 0xf;
7091 vl->weight = 0;
7092 }
7093}
7094
7095static void set_sc2vlnt(struct hfi1_devdata *dd, struct sc2vlnt *dp)
7096{
7097 write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0,
7098 DC_SC_VL_VAL(15_0,
7099 0, dp->vlnt[0] & 0xf,
7100 1, dp->vlnt[1] & 0xf,
7101 2, dp->vlnt[2] & 0xf,
7102 3, dp->vlnt[3] & 0xf,
7103 4, dp->vlnt[4] & 0xf,
7104 5, dp->vlnt[5] & 0xf,
7105 6, dp->vlnt[6] & 0xf,
7106 7, dp->vlnt[7] & 0xf,
7107 8, dp->vlnt[8] & 0xf,
7108 9, dp->vlnt[9] & 0xf,
7109 10, dp->vlnt[10] & 0xf,
7110 11, dp->vlnt[11] & 0xf,
7111 12, dp->vlnt[12] & 0xf,
7112 13, dp->vlnt[13] & 0xf,
7113 14, dp->vlnt[14] & 0xf,
7114 15, dp->vlnt[15] & 0xf));
7115 write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16,
7116 DC_SC_VL_VAL(31_16,
7117 16, dp->vlnt[16] & 0xf,
7118 17, dp->vlnt[17] & 0xf,
7119 18, dp->vlnt[18] & 0xf,
7120 19, dp->vlnt[19] & 0xf,
7121 20, dp->vlnt[20] & 0xf,
7122 21, dp->vlnt[21] & 0xf,
7123 22, dp->vlnt[22] & 0xf,
7124 23, dp->vlnt[23] & 0xf,
7125 24, dp->vlnt[24] & 0xf,
7126 25, dp->vlnt[25] & 0xf,
7127 26, dp->vlnt[26] & 0xf,
7128 27, dp->vlnt[27] & 0xf,
7129 28, dp->vlnt[28] & 0xf,
7130 29, dp->vlnt[29] & 0xf,
7131 30, dp->vlnt[30] & 0xf,
7132 31, dp->vlnt[31] & 0xf));
7133}
7134
7135static void nonzero_msg(struct hfi1_devdata *dd, int idx, const char *what,
7136 u16 limit)
7137{
7138 if (limit != 0)
7139 dd_dev_info(dd, "Invalid %s limit %d on VL %d, ignoring\n",
7140 what, (int)limit, idx);
7141}
7142
7143/* change only the shared limit portion of SendCmGLobalCredit */
7144static void set_global_shared(struct hfi1_devdata *dd, u16 limit)
7145{
7146 u64 reg;
7147
7148 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
7149 reg &= ~SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SMASK;
7150 reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_SHARED_LIMIT_SHIFT;
7151 write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
7152}
7153
7154/* change only the total credit limit portion of SendCmGLobalCredit */
7155static void set_global_limit(struct hfi1_devdata *dd, u16 limit)
7156{
7157 u64 reg;
7158
7159 reg = read_csr(dd, SEND_CM_GLOBAL_CREDIT);
7160 reg &= ~SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SMASK;
7161 reg |= (u64)limit << SEND_CM_GLOBAL_CREDIT_TOTAL_CREDIT_LIMIT_SHIFT;
7162 write_csr(dd, SEND_CM_GLOBAL_CREDIT, reg);
7163}
7164
7165/* set the given per-VL shared limit */
7166static void set_vl_shared(struct hfi1_devdata *dd, int vl, u16 limit)
7167{
7168 u64 reg;
7169 u32 addr;
7170
7171 if (vl < TXE_NUM_DATA_VL)
7172 addr = SEND_CM_CREDIT_VL + (8 * vl);
7173 else
7174 addr = SEND_CM_CREDIT_VL15;
7175
7176 reg = read_csr(dd, addr);
7177 reg &= ~SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SMASK;
7178 reg |= (u64)limit << SEND_CM_CREDIT_VL_SHARED_LIMIT_VL_SHIFT;
7179 write_csr(dd, addr, reg);
7180}
7181
7182/* set the given per-VL dedicated limit */
7183static void set_vl_dedicated(struct hfi1_devdata *dd, int vl, u16 limit)
7184{
7185 u64 reg;
7186 u32 addr;
7187
7188 if (vl < TXE_NUM_DATA_VL)
7189 addr = SEND_CM_CREDIT_VL + (8 * vl);
7190 else
7191 addr = SEND_CM_CREDIT_VL15;
7192
7193 reg = read_csr(dd, addr);
7194 reg &= ~SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SMASK;
7195 reg |= (u64)limit << SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT;
7196 write_csr(dd, addr, reg);
7197}
7198
7199/* spin until the given per-VL status mask bits clear */
7200static void wait_for_vl_status_clear(struct hfi1_devdata *dd, u64 mask,
7201 const char *which)
7202{
7203 unsigned long timeout;
7204 u64 reg;
7205
7206 timeout = jiffies + msecs_to_jiffies(VL_STATUS_CLEAR_TIMEOUT);
7207 while (1) {
7208 reg = read_csr(dd, SEND_CM_CREDIT_USED_STATUS) & mask;
7209
7210 if (reg == 0)
7211 return; /* success */
7212 if (time_after(jiffies, timeout))
7213 break; /* timed out */
7214 udelay(1);
7215 }
7216
7217 dd_dev_err(dd,
7218 "%s credit change status not clearing after %dms, mask 0x%llx, not clear 0x%llx\n",
7219 which, VL_STATUS_CLEAR_TIMEOUT, mask, reg);
7220 /*
7221 * If this occurs, it is likely there was a credit loss on the link.
7222 * The only recovery from that is a link bounce.
7223 */
7224 dd_dev_err(dd,
7225 "Continuing anyway. A credit loss may occur. Suggest a link bounce\n");
7226}
7227
7228/*
7229 * The number of credits on the VLs may be changed while everything
7230 * is "live", but the following algorithm must be followed due to
7231 * how the hardware is actually implemented. In particular,
7232 * Return_Credit_Status[] is the only correct status check.
7233 *
7234 * if (reducing Global_Shared_Credit_Limit or any shared limit changing)
7235 * set Global_Shared_Credit_Limit = 0
7236 * use_all_vl = 1
7237 * mask0 = all VLs that are changing either dedicated or shared limits
7238 * set Shared_Limit[mask0] = 0
7239 * spin until Return_Credit_Status[use_all_vl ? all VL : mask0] == 0
7240 * if (changing any dedicated limit)
7241 * mask1 = all VLs that are lowering dedicated limits
7242 * lower Dedicated_Limit[mask1]
7243 * spin until Return_Credit_Status[mask1] == 0
7244 * raise Dedicated_Limits
7245 * raise Shared_Limits
7246 * raise Global_Shared_Credit_Limit
7247 *
7248 * lower = if the new limit is lower, set the limit to the new value
7249 * raise = if the new limit is higher than the current value (may be changed
7250 * earlier in the algorithm), set the new limit to the new value
7251 */
7252static int set_buffer_control(struct hfi1_devdata *dd,
7253 struct buffer_control *new_bc)
7254{
7255 u64 changing_mask, ld_mask, stat_mask;
7256 int change_count;
7257 int i, use_all_mask;
7258 int this_shared_changing;
7259 /*
7260 * A0: add the variable any_shared_limit_changing below and in the
7261 * algorithm above. If removing A0 support, it can be removed.
7262 */
7263 int any_shared_limit_changing;
7264 struct buffer_control cur_bc;
7265 u8 changing[OPA_MAX_VLS];
7266 u8 lowering_dedicated[OPA_MAX_VLS];
7267 u16 cur_total;
7268 u32 new_total = 0;
7269 const u64 all_mask =
7270 SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK
7271 | SEND_CM_CREDIT_USED_STATUS_VL1_RETURN_CREDIT_STATUS_SMASK
7272 | SEND_CM_CREDIT_USED_STATUS_VL2_RETURN_CREDIT_STATUS_SMASK
7273 | SEND_CM_CREDIT_USED_STATUS_VL3_RETURN_CREDIT_STATUS_SMASK
7274 | SEND_CM_CREDIT_USED_STATUS_VL4_RETURN_CREDIT_STATUS_SMASK
7275 | SEND_CM_CREDIT_USED_STATUS_VL5_RETURN_CREDIT_STATUS_SMASK
7276 | SEND_CM_CREDIT_USED_STATUS_VL6_RETURN_CREDIT_STATUS_SMASK
7277 | SEND_CM_CREDIT_USED_STATUS_VL7_RETURN_CREDIT_STATUS_SMASK
7278 | SEND_CM_CREDIT_USED_STATUS_VL15_RETURN_CREDIT_STATUS_SMASK;
7279
7280#define valid_vl(idx) ((idx) < TXE_NUM_DATA_VL || (idx) == 15)
7281#define NUM_USABLE_VLS 16 /* look at VL15 and less */
7282
7283
7284 /* find the new total credits, do sanity check on unused VLs */
7285 for (i = 0; i < OPA_MAX_VLS; i++) {
7286 if (valid_vl(i)) {
7287 new_total += be16_to_cpu(new_bc->vl[i].dedicated);
7288 continue;
7289 }
7290 nonzero_msg(dd, i, "dedicated",
7291 be16_to_cpu(new_bc->vl[i].dedicated));
7292 nonzero_msg(dd, i, "shared",
7293 be16_to_cpu(new_bc->vl[i].shared));
7294 new_bc->vl[i].dedicated = 0;
7295 new_bc->vl[i].shared = 0;
7296 }
7297 new_total += be16_to_cpu(new_bc->overall_shared_limit);
7298 if (new_total > (u32)dd->link_credits)
7299 return -EINVAL;
7300 /* fetch the current values */
7301 get_buffer_control(dd, &cur_bc, &cur_total);
7302
7303 /*
7304 * Create the masks we will use.
7305 */
7306 memset(changing, 0, sizeof(changing));
7307 memset(lowering_dedicated, 0, sizeof(lowering_dedicated));
7308 /* NOTE: Assumes that the individual VL bits are adjacent and in
7309 increasing order */
7310 stat_mask =
7311 SEND_CM_CREDIT_USED_STATUS_VL0_RETURN_CREDIT_STATUS_SMASK;
7312 changing_mask = 0;
7313 ld_mask = 0;
7314 change_count = 0;
7315 any_shared_limit_changing = 0;
7316 for (i = 0; i < NUM_USABLE_VLS; i++, stat_mask <<= 1) {
7317 if (!valid_vl(i))
7318 continue;
7319 this_shared_changing = new_bc->vl[i].shared
7320 != cur_bc.vl[i].shared;
7321 if (this_shared_changing)
7322 any_shared_limit_changing = 1;
7323 if (new_bc->vl[i].dedicated != cur_bc.vl[i].dedicated
7324 || this_shared_changing) {
7325 changing[i] = 1;
7326 changing_mask |= stat_mask;
7327 change_count++;
7328 }
7329 if (be16_to_cpu(new_bc->vl[i].dedicated) <
7330 be16_to_cpu(cur_bc.vl[i].dedicated)) {
7331 lowering_dedicated[i] = 1;
7332 ld_mask |= stat_mask;
7333 }
7334 }
7335
7336 /* bracket the credit change with a total adjustment */
7337 if (new_total > cur_total)
7338 set_global_limit(dd, new_total);
7339
7340 /*
7341 * Start the credit change algorithm.
7342 */
7343 use_all_mask = 0;
7344 if ((be16_to_cpu(new_bc->overall_shared_limit) <
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05007345 be16_to_cpu(cur_bc.overall_shared_limit)) ||
7346 (is_ax(dd) && any_shared_limit_changing)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04007347 set_global_shared(dd, 0);
7348 cur_bc.overall_shared_limit = 0;
7349 use_all_mask = 1;
7350 }
7351
7352 for (i = 0; i < NUM_USABLE_VLS; i++) {
7353 if (!valid_vl(i))
7354 continue;
7355
7356 if (changing[i]) {
7357 set_vl_shared(dd, i, 0);
7358 cur_bc.vl[i].shared = 0;
7359 }
7360 }
7361
7362 wait_for_vl_status_clear(dd, use_all_mask ? all_mask : changing_mask,
7363 "shared");
7364
7365 if (change_count > 0) {
7366 for (i = 0; i < NUM_USABLE_VLS; i++) {
7367 if (!valid_vl(i))
7368 continue;
7369
7370 if (lowering_dedicated[i]) {
7371 set_vl_dedicated(dd, i,
7372 be16_to_cpu(new_bc->vl[i].dedicated));
7373 cur_bc.vl[i].dedicated =
7374 new_bc->vl[i].dedicated;
7375 }
7376 }
7377
7378 wait_for_vl_status_clear(dd, ld_mask, "dedicated");
7379
7380 /* now raise all dedicated that are going up */
7381 for (i = 0; i < NUM_USABLE_VLS; i++) {
7382 if (!valid_vl(i))
7383 continue;
7384
7385 if (be16_to_cpu(new_bc->vl[i].dedicated) >
7386 be16_to_cpu(cur_bc.vl[i].dedicated))
7387 set_vl_dedicated(dd, i,
7388 be16_to_cpu(new_bc->vl[i].dedicated));
7389 }
7390 }
7391
7392 /* next raise all shared that are going up */
7393 for (i = 0; i < NUM_USABLE_VLS; i++) {
7394 if (!valid_vl(i))
7395 continue;
7396
7397 if (be16_to_cpu(new_bc->vl[i].shared) >
7398 be16_to_cpu(cur_bc.vl[i].shared))
7399 set_vl_shared(dd, i, be16_to_cpu(new_bc->vl[i].shared));
7400 }
7401
7402 /* finally raise the global shared */
7403 if (be16_to_cpu(new_bc->overall_shared_limit) >
7404 be16_to_cpu(cur_bc.overall_shared_limit))
7405 set_global_shared(dd,
7406 be16_to_cpu(new_bc->overall_shared_limit));
7407
7408 /* bracket the credit change with a total adjustment */
7409 if (new_total < cur_total)
7410 set_global_limit(dd, new_total);
7411 return 0;
7412}
7413
7414/*
7415 * Read the given fabric manager table. Return the size of the
7416 * table (in bytes) on success, and a negative error code on
7417 * failure.
7418 */
7419int fm_get_table(struct hfi1_pportdata *ppd, int which, void *t)
7420
7421{
7422 int size;
7423 struct vl_arb_cache *vlc;
7424
7425 switch (which) {
7426 case FM_TBL_VL_HIGH_ARB:
7427 size = 256;
7428 /*
7429 * OPA specifies 128 elements (of 2 bytes each), though
7430 * HFI supports only 16 elements in h/w.
7431 */
7432 vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
7433 vl_arb_get_cache(vlc, t);
7434 vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
7435 break;
7436 case FM_TBL_VL_LOW_ARB:
7437 size = 256;
7438 /*
7439 * OPA specifies 128 elements (of 2 bytes each), though
7440 * HFI supports only 16 elements in h/w.
7441 */
7442 vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
7443 vl_arb_get_cache(vlc, t);
7444 vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
7445 break;
7446 case FM_TBL_BUFFER_CONTROL:
7447 size = get_buffer_control(ppd->dd, t, NULL);
7448 break;
7449 case FM_TBL_SC2VLNT:
7450 size = get_sc2vlnt(ppd->dd, t);
7451 break;
7452 case FM_TBL_VL_PREEMPT_ELEMS:
7453 size = 256;
7454 /* OPA specifies 128 elements, of 2 bytes each */
7455 get_vlarb_preempt(ppd->dd, OPA_MAX_VLS, t);
7456 break;
7457 case FM_TBL_VL_PREEMPT_MATRIX:
7458 size = 256;
7459 /*
7460 * OPA specifies that this is the same size as the VL
7461 * arbitration tables (i.e., 256 bytes).
7462 */
7463 break;
7464 default:
7465 return -EINVAL;
7466 }
7467 return size;
7468}
7469
7470/*
7471 * Write the given fabric manager table.
7472 */
7473int fm_set_table(struct hfi1_pportdata *ppd, int which, void *t)
7474{
7475 int ret = 0;
7476 struct vl_arb_cache *vlc;
7477
7478 switch (which) {
7479 case FM_TBL_VL_HIGH_ARB:
7480 vlc = vl_arb_lock_cache(ppd, HI_PRIO_TABLE);
7481 if (vl_arb_match_cache(vlc, t)) {
7482 vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
7483 break;
7484 }
7485 vl_arb_set_cache(vlc, t);
7486 vl_arb_unlock_cache(ppd, HI_PRIO_TABLE);
7487 ret = set_vl_weights(ppd, SEND_HIGH_PRIORITY_LIST,
7488 VL_ARB_HIGH_PRIO_TABLE_SIZE, t);
7489 break;
7490 case FM_TBL_VL_LOW_ARB:
7491 vlc = vl_arb_lock_cache(ppd, LO_PRIO_TABLE);
7492 if (vl_arb_match_cache(vlc, t)) {
7493 vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
7494 break;
7495 }
7496 vl_arb_set_cache(vlc, t);
7497 vl_arb_unlock_cache(ppd, LO_PRIO_TABLE);
7498 ret = set_vl_weights(ppd, SEND_LOW_PRIORITY_LIST,
7499 VL_ARB_LOW_PRIO_TABLE_SIZE, t);
7500 break;
7501 case FM_TBL_BUFFER_CONTROL:
7502 ret = set_buffer_control(ppd->dd, t);
7503 break;
7504 case FM_TBL_SC2VLNT:
7505 set_sc2vlnt(ppd->dd, t);
7506 break;
7507 default:
7508 ret = -EINVAL;
7509 }
7510 return ret;
7511}
7512
7513/*
7514 * Disable all data VLs.
7515 *
7516 * Return 0 if disabled, non-zero if the VLs cannot be disabled.
7517 */
7518static int disable_data_vls(struct hfi1_devdata *dd)
7519{
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05007520 if (is_ax(dd))
Mike Marciniszyn77241052015-07-30 15:17:43 -04007521 return 1;
7522
7523 pio_send_control(dd, PSC_DATA_VL_DISABLE);
7524
7525 return 0;
7526}
7527
7528/*
7529 * open_fill_data_vls() - the counterpart to stop_drain_data_vls().
7530 * Just re-enables all data VLs (the "fill" part happens
7531 * automatically - the name was chosen for symmetry with
7532 * stop_drain_data_vls()).
7533 *
7534 * Return 0 if successful, non-zero if the VLs cannot be enabled.
7535 */
7536int open_fill_data_vls(struct hfi1_devdata *dd)
7537{
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05007538 if (is_ax(dd))
Mike Marciniszyn77241052015-07-30 15:17:43 -04007539 return 1;
7540
7541 pio_send_control(dd, PSC_DATA_VL_ENABLE);
7542
7543 return 0;
7544}
7545
7546/*
7547 * drain_data_vls() - assumes that disable_data_vls() has been called,
7548 * wait for occupancy (of per-VL FIFOs) for all contexts, and SDMA
7549 * engines to drop to 0.
7550 */
7551static void drain_data_vls(struct hfi1_devdata *dd)
7552{
7553 sc_wait(dd);
7554 sdma_wait(dd);
7555 pause_for_credit_return(dd);
7556}
7557
7558/*
7559 * stop_drain_data_vls() - disable, then drain all per-VL fifos.
7560 *
7561 * Use open_fill_data_vls() to resume using data VLs. This pair is
7562 * meant to be used like this:
7563 *
7564 * stop_drain_data_vls(dd);
7565 * // do things with per-VL resources
7566 * open_fill_data_vls(dd);
7567 */
7568int stop_drain_data_vls(struct hfi1_devdata *dd)
7569{
7570 int ret;
7571
7572 ret = disable_data_vls(dd);
7573 if (ret == 0)
7574 drain_data_vls(dd);
7575
7576 return ret;
7577}
7578
7579/*
7580 * Convert a nanosecond time to a cclock count. No matter how slow
7581 * the cclock, a non-zero ns will always have a non-zero result.
7582 */
7583u32 ns_to_cclock(struct hfi1_devdata *dd, u32 ns)
7584{
7585 u32 cclocks;
7586
7587 if (dd->icode == ICODE_FPGA_EMULATION)
7588 cclocks = (ns * 1000) / FPGA_CCLOCK_PS;
7589 else /* simulation pretends to be ASIC */
7590 cclocks = (ns * 1000) / ASIC_CCLOCK_PS;
7591 if (ns && !cclocks) /* if ns nonzero, must be at least 1 */
7592 cclocks = 1;
7593 return cclocks;
7594}
7595
7596/*
7597 * Convert a cclock count to nanoseconds. Not matter how slow
7598 * the cclock, a non-zero cclocks will always have a non-zero result.
7599 */
7600u32 cclock_to_ns(struct hfi1_devdata *dd, u32 cclocks)
7601{
7602 u32 ns;
7603
7604 if (dd->icode == ICODE_FPGA_EMULATION)
7605 ns = (cclocks * FPGA_CCLOCK_PS) / 1000;
7606 else /* simulation pretends to be ASIC */
7607 ns = (cclocks * ASIC_CCLOCK_PS) / 1000;
7608 if (cclocks && !ns)
7609 ns = 1;
7610 return ns;
7611}
7612
7613/*
7614 * Dynamically adjust the receive interrupt timeout for a context based on
7615 * incoming packet rate.
7616 *
7617 * NOTE: Dynamic adjustment does not allow rcv_intr_count to be zero.
7618 */
7619static void adjust_rcv_timeout(struct hfi1_ctxtdata *rcd, u32 npkts)
7620{
7621 struct hfi1_devdata *dd = rcd->dd;
7622 u32 timeout = rcd->rcvavail_timeout;
7623
7624 /*
7625 * This algorithm doubles or halves the timeout depending on whether
7626 * the number of packets received in this interrupt were less than or
7627 * greater equal the interrupt count.
7628 *
7629 * The calculations below do not allow a steady state to be achieved.
7630 * Only at the endpoints it is possible to have an unchanging
7631 * timeout.
7632 */
7633 if (npkts < rcv_intr_count) {
7634 /*
7635 * Not enough packets arrived before the timeout, adjust
7636 * timeout downward.
7637 */
7638 if (timeout < 2) /* already at minimum? */
7639 return;
7640 timeout >>= 1;
7641 } else {
7642 /*
7643 * More than enough packets arrived before the timeout, adjust
7644 * timeout upward.
7645 */
7646 if (timeout >= dd->rcv_intr_timeout_csr) /* already at max? */
7647 return;
7648 timeout = min(timeout << 1, dd->rcv_intr_timeout_csr);
7649 }
7650
7651 rcd->rcvavail_timeout = timeout;
7652 /* timeout cannot be larger than rcv_intr_timeout_csr which has already
7653 been verified to be in range */
7654 write_kctxt_csr(dd, rcd->ctxt, RCV_AVAIL_TIME_OUT,
7655 (u64)timeout << RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
7656}
7657
7658void update_usrhead(struct hfi1_ctxtdata *rcd, u32 hd, u32 updegr, u32 egrhd,
7659 u32 intr_adjust, u32 npkts)
7660{
7661 struct hfi1_devdata *dd = rcd->dd;
7662 u64 reg;
7663 u32 ctxt = rcd->ctxt;
7664
7665 /*
7666 * Need to write timeout register before updating RcvHdrHead to ensure
7667 * that a new value is used when the HW decides to restart counting.
7668 */
7669 if (intr_adjust)
7670 adjust_rcv_timeout(rcd, npkts);
7671 if (updegr) {
7672 reg = (egrhd & RCV_EGR_INDEX_HEAD_HEAD_MASK)
7673 << RCV_EGR_INDEX_HEAD_HEAD_SHIFT;
7674 write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, reg);
7675 }
7676 mmiowb();
7677 reg = ((u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT) |
7678 (((u64)hd & RCV_HDR_HEAD_HEAD_MASK)
7679 << RCV_HDR_HEAD_HEAD_SHIFT);
7680 write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
7681 mmiowb();
7682}
7683
7684u32 hdrqempty(struct hfi1_ctxtdata *rcd)
7685{
7686 u32 head, tail;
7687
7688 head = (read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_HEAD)
7689 & RCV_HDR_HEAD_HEAD_SMASK) >> RCV_HDR_HEAD_HEAD_SHIFT;
7690
7691 if (rcd->rcvhdrtail_kvaddr)
7692 tail = get_rcvhdrtail(rcd);
7693 else
7694 tail = read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL);
7695
7696 return head == tail;
7697}
7698
7699/*
7700 * Context Control and Receive Array encoding for buffer size:
7701 * 0x0 invalid
7702 * 0x1 4 KB
7703 * 0x2 8 KB
7704 * 0x3 16 KB
7705 * 0x4 32 KB
7706 * 0x5 64 KB
7707 * 0x6 128 KB
7708 * 0x7 256 KB
7709 * 0x8 512 KB (Receive Array only)
7710 * 0x9 1 MB (Receive Array only)
7711 * 0xa 2 MB (Receive Array only)
7712 *
7713 * 0xB-0xF - reserved (Receive Array only)
7714 *
7715 *
7716 * This routine assumes that the value has already been sanity checked.
7717 */
7718static u32 encoded_size(u32 size)
7719{
7720 switch (size) {
7721 case 4*1024: return 0x1;
7722 case 8*1024: return 0x2;
7723 case 16*1024: return 0x3;
7724 case 32*1024: return 0x4;
7725 case 64*1024: return 0x5;
7726 case 128*1024: return 0x6;
7727 case 256*1024: return 0x7;
7728 case 512*1024: return 0x8;
7729 case 1*1024*1024: return 0x9;
7730 case 2*1024*1024: return 0xa;
7731 }
7732 return 0x1; /* if invalid, go with the minimum size */
7733}
7734
7735void hfi1_rcvctrl(struct hfi1_devdata *dd, unsigned int op, int ctxt)
7736{
7737 struct hfi1_ctxtdata *rcd;
7738 u64 rcvctrl, reg;
7739 int did_enable = 0;
7740
7741 rcd = dd->rcd[ctxt];
7742 if (!rcd)
7743 return;
7744
7745 hfi1_cdbg(RCVCTRL, "ctxt %d op 0x%x", ctxt, op);
7746
7747 rcvctrl = read_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL);
7748 /* if the context already enabled, don't do the extra steps */
7749 if ((op & HFI1_RCVCTRL_CTXT_ENB)
7750 && !(rcvctrl & RCV_CTXT_CTRL_ENABLE_SMASK)) {
7751 /* reset the tail and hdr addresses, and sequence count */
7752 write_kctxt_csr(dd, ctxt, RCV_HDR_ADDR,
7753 rcd->rcvhdrq_phys);
7754 if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL))
7755 write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
7756 rcd->rcvhdrqtailaddr_phys);
7757 rcd->seq_cnt = 1;
7758
7759 /* reset the cached receive header queue head value */
7760 rcd->head = 0;
7761
7762 /*
7763 * Zero the receive header queue so we don't get false
7764 * positives when checking the sequence number. The
7765 * sequence numbers could land exactly on the same spot.
7766 * E.g. a rcd restart before the receive header wrapped.
7767 */
7768 memset(rcd->rcvhdrq, 0, rcd->rcvhdrq_size);
7769
7770 /* starting timeout */
7771 rcd->rcvavail_timeout = dd->rcv_intr_timeout_csr;
7772
7773 /* enable the context */
7774 rcvctrl |= RCV_CTXT_CTRL_ENABLE_SMASK;
7775
7776 /* clean the egr buffer size first */
7777 rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
7778 rcvctrl |= ((u64)encoded_size(rcd->egrbufs.rcvtid_size)
7779 & RCV_CTXT_CTRL_EGR_BUF_SIZE_MASK)
7780 << RCV_CTXT_CTRL_EGR_BUF_SIZE_SHIFT;
7781
7782 /* zero RcvHdrHead - set RcvHdrHead.Counter after enable */
7783 write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0);
7784 did_enable = 1;
7785
7786 /* zero RcvEgrIndexHead */
7787 write_uctxt_csr(dd, ctxt, RCV_EGR_INDEX_HEAD, 0);
7788
7789 /* set eager count and base index */
7790 reg = (((u64)(rcd->egrbufs.alloced >> RCV_SHIFT)
7791 & RCV_EGR_CTRL_EGR_CNT_MASK)
7792 << RCV_EGR_CTRL_EGR_CNT_SHIFT) |
7793 (((rcd->eager_base >> RCV_SHIFT)
7794 & RCV_EGR_CTRL_EGR_BASE_INDEX_MASK)
7795 << RCV_EGR_CTRL_EGR_BASE_INDEX_SHIFT);
7796 write_kctxt_csr(dd, ctxt, RCV_EGR_CTRL, reg);
7797
7798 /*
7799 * Set TID (expected) count and base index.
7800 * rcd->expected_count is set to individual RcvArray entries,
7801 * not pairs, and the CSR takes a pair-count in groups of
7802 * four, so divide by 8.
7803 */
7804 reg = (((rcd->expected_count >> RCV_SHIFT)
7805 & RCV_TID_CTRL_TID_PAIR_CNT_MASK)
7806 << RCV_TID_CTRL_TID_PAIR_CNT_SHIFT) |
7807 (((rcd->expected_base >> RCV_SHIFT)
7808 & RCV_TID_CTRL_TID_BASE_INDEX_MASK)
7809 << RCV_TID_CTRL_TID_BASE_INDEX_SHIFT);
7810 write_kctxt_csr(dd, ctxt, RCV_TID_CTRL, reg);
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -05007811 if (ctxt == HFI1_CTRL_CTXT)
7812 write_csr(dd, RCV_VL15, HFI1_CTRL_CTXT);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007813 }
7814 if (op & HFI1_RCVCTRL_CTXT_DIS) {
7815 write_csr(dd, RCV_VL15, 0);
Mark F. Brown46b010d2015-11-09 19:18:20 -05007816 /*
7817 * When receive context is being disabled turn on tail
7818 * update with a dummy tail address and then disable
7819 * receive context.
7820 */
7821 if (dd->rcvhdrtail_dummy_physaddr) {
7822 write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
7823 dd->rcvhdrtail_dummy_physaddr);
7824 rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
7825 }
7826
Mike Marciniszyn77241052015-07-30 15:17:43 -04007827 rcvctrl &= ~RCV_CTXT_CTRL_ENABLE_SMASK;
7828 }
7829 if (op & HFI1_RCVCTRL_INTRAVAIL_ENB)
7830 rcvctrl |= RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
7831 if (op & HFI1_RCVCTRL_INTRAVAIL_DIS)
7832 rcvctrl &= ~RCV_CTXT_CTRL_INTR_AVAIL_SMASK;
7833 if (op & HFI1_RCVCTRL_TAILUPD_ENB && rcd->rcvhdrqtailaddr_phys)
7834 rcvctrl |= RCV_CTXT_CTRL_TAIL_UPD_SMASK;
7835 if (op & HFI1_RCVCTRL_TAILUPD_DIS)
7836 rcvctrl &= ~RCV_CTXT_CTRL_TAIL_UPD_SMASK;
7837 if (op & HFI1_RCVCTRL_TIDFLOW_ENB)
7838 rcvctrl |= RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
7839 if (op & HFI1_RCVCTRL_TIDFLOW_DIS)
7840 rcvctrl &= ~RCV_CTXT_CTRL_TID_FLOW_ENABLE_SMASK;
7841 if (op & HFI1_RCVCTRL_ONE_PKT_EGR_ENB) {
7842 /* In one-packet-per-eager mode, the size comes from
7843 the RcvArray entry. */
7844 rcvctrl &= ~RCV_CTXT_CTRL_EGR_BUF_SIZE_SMASK;
7845 rcvctrl |= RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
7846 }
7847 if (op & HFI1_RCVCTRL_ONE_PKT_EGR_DIS)
7848 rcvctrl &= ~RCV_CTXT_CTRL_ONE_PACKET_PER_EGR_BUFFER_SMASK;
7849 if (op & HFI1_RCVCTRL_NO_RHQ_DROP_ENB)
7850 rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
7851 if (op & HFI1_RCVCTRL_NO_RHQ_DROP_DIS)
7852 rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK;
7853 if (op & HFI1_RCVCTRL_NO_EGR_DROP_ENB)
7854 rcvctrl |= RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
7855 if (op & HFI1_RCVCTRL_NO_EGR_DROP_DIS)
7856 rcvctrl &= ~RCV_CTXT_CTRL_DONT_DROP_EGR_FULL_SMASK;
7857 rcd->rcvctrl = rcvctrl;
7858 hfi1_cdbg(RCVCTRL, "ctxt %d rcvctrl 0x%llx\n", ctxt, rcvctrl);
7859 write_kctxt_csr(dd, ctxt, RCV_CTXT_CTRL, rcd->rcvctrl);
7860
7861 /* work around sticky RcvCtxtStatus.BlockedRHQFull */
7862 if (did_enable
7863 && (rcvctrl & RCV_CTXT_CTRL_DONT_DROP_RHQ_FULL_SMASK)) {
7864 reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
7865 if (reg != 0) {
7866 dd_dev_info(dd, "ctxt %d status %lld (blocked)\n",
7867 ctxt, reg);
7868 read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
7869 write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x10);
7870 write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, 0x00);
7871 read_uctxt_csr(dd, ctxt, RCV_HDR_HEAD);
7872 reg = read_kctxt_csr(dd, ctxt, RCV_CTXT_STATUS);
7873 dd_dev_info(dd, "ctxt %d status %lld (%s blocked)\n",
7874 ctxt, reg, reg == 0 ? "not" : "still");
7875 }
7876 }
7877
7878 if (did_enable) {
7879 /*
7880 * The interrupt timeout and count must be set after
7881 * the context is enabled to take effect.
7882 */
7883 /* set interrupt timeout */
7884 write_kctxt_csr(dd, ctxt, RCV_AVAIL_TIME_OUT,
7885 (u64)rcd->rcvavail_timeout <<
7886 RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_SHIFT);
7887
7888 /* set RcvHdrHead.Counter, zero RcvHdrHead.Head (again) */
7889 reg = (u64)rcv_intr_count << RCV_HDR_HEAD_COUNTER_SHIFT;
7890 write_uctxt_csr(dd, ctxt, RCV_HDR_HEAD, reg);
7891 }
7892
7893 if (op & (HFI1_RCVCTRL_TAILUPD_DIS | HFI1_RCVCTRL_CTXT_DIS))
7894 /*
7895 * If the context has been disabled and the Tail Update has
Mark F. Brown46b010d2015-11-09 19:18:20 -05007896 * been cleared, set the RCV_HDR_TAIL_ADDR CSR to dummy address
7897 * so it doesn't contain an address that is invalid.
Mike Marciniszyn77241052015-07-30 15:17:43 -04007898 */
Mark F. Brown46b010d2015-11-09 19:18:20 -05007899 write_kctxt_csr(dd, ctxt, RCV_HDR_TAIL_ADDR,
7900 dd->rcvhdrtail_dummy_physaddr);
Mike Marciniszyn77241052015-07-30 15:17:43 -04007901}
7902
7903u32 hfi1_read_cntrs(struct hfi1_devdata *dd, loff_t pos, char **namep,
7904 u64 **cntrp)
7905{
7906 int ret;
7907 u64 val = 0;
7908
7909 if (namep) {
7910 ret = dd->cntrnameslen;
7911 if (pos != 0) {
7912 dd_dev_err(dd, "read_cntrs does not support indexing");
7913 return 0;
7914 }
7915 *namep = dd->cntrnames;
7916 } else {
7917 const struct cntr_entry *entry;
7918 int i, j;
7919
7920 ret = (dd->ndevcntrs) * sizeof(u64);
7921 if (pos != 0) {
7922 dd_dev_err(dd, "read_cntrs does not support indexing");
7923 return 0;
7924 }
7925
7926 /* Get the start of the block of counters */
7927 *cntrp = dd->cntrs;
7928
7929 /*
7930 * Now go and fill in each counter in the block.
7931 */
7932 for (i = 0; i < DEV_CNTR_LAST; i++) {
7933 entry = &dev_cntrs[i];
7934 hfi1_cdbg(CNTR, "reading %s", entry->name);
7935 if (entry->flags & CNTR_DISABLED) {
7936 /* Nothing */
7937 hfi1_cdbg(CNTR, "\tDisabled\n");
7938 } else {
7939 if (entry->flags & CNTR_VL) {
7940 hfi1_cdbg(CNTR, "\tPer VL\n");
7941 for (j = 0; j < C_VL_COUNT; j++) {
7942 val = entry->rw_cntr(entry,
7943 dd, j,
7944 CNTR_MODE_R,
7945 0);
7946 hfi1_cdbg(
7947 CNTR,
7948 "\t\tRead 0x%llx for %d\n",
7949 val, j);
7950 dd->cntrs[entry->offset + j] =
7951 val;
7952 }
7953 } else {
7954 val = entry->rw_cntr(entry, dd,
7955 CNTR_INVALID_VL,
7956 CNTR_MODE_R, 0);
7957 dd->cntrs[entry->offset] = val;
7958 hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
7959 }
7960 }
7961 }
7962 }
7963 return ret;
7964}
7965
7966/*
7967 * Used by sysfs to create files for hfi stats to read
7968 */
7969u32 hfi1_read_portcntrs(struct hfi1_devdata *dd, loff_t pos, u32 port,
7970 char **namep, u64 **cntrp)
7971{
7972 int ret;
7973 u64 val = 0;
7974
7975 if (namep) {
7976 ret = dd->portcntrnameslen;
7977 if (pos != 0) {
7978 dd_dev_err(dd, "index not supported");
7979 return 0;
7980 }
7981 *namep = dd->portcntrnames;
7982 } else {
7983 const struct cntr_entry *entry;
7984 struct hfi1_pportdata *ppd;
7985 int i, j;
7986
7987 ret = (dd->nportcntrs) * sizeof(u64);
7988 if (pos != 0) {
7989 dd_dev_err(dd, "indexing not supported");
7990 return 0;
7991 }
7992 ppd = (struct hfi1_pportdata *)(dd + 1 + port);
7993 *cntrp = ppd->cntrs;
7994
7995 for (i = 0; i < PORT_CNTR_LAST; i++) {
7996 entry = &port_cntrs[i];
7997 hfi1_cdbg(CNTR, "reading %s", entry->name);
7998 if (entry->flags & CNTR_DISABLED) {
7999 /* Nothing */
8000 hfi1_cdbg(CNTR, "\tDisabled\n");
8001 continue;
8002 }
8003
8004 if (entry->flags & CNTR_VL) {
8005 hfi1_cdbg(CNTR, "\tPer VL");
8006 for (j = 0; j < C_VL_COUNT; j++) {
8007 val = entry->rw_cntr(entry, ppd, j,
8008 CNTR_MODE_R,
8009 0);
8010 hfi1_cdbg(
8011 CNTR,
8012 "\t\tRead 0x%llx for %d",
8013 val, j);
8014 ppd->cntrs[entry->offset + j] = val;
8015 }
8016 } else {
8017 val = entry->rw_cntr(entry, ppd,
8018 CNTR_INVALID_VL,
8019 CNTR_MODE_R,
8020 0);
8021 ppd->cntrs[entry->offset] = val;
8022 hfi1_cdbg(CNTR, "\tRead 0x%llx", val);
8023 }
8024 }
8025 }
8026 return ret;
8027}
8028
8029static void free_cntrs(struct hfi1_devdata *dd)
8030{
8031 struct hfi1_pportdata *ppd;
8032 int i;
8033
8034 if (dd->synth_stats_timer.data)
8035 del_timer_sync(&dd->synth_stats_timer);
8036 dd->synth_stats_timer.data = 0;
8037 ppd = (struct hfi1_pportdata *)(dd + 1);
8038 for (i = 0; i < dd->num_pports; i++, ppd++) {
8039 kfree(ppd->cntrs);
8040 kfree(ppd->scntrs);
8041 free_percpu(ppd->ibport_data.rc_acks);
8042 free_percpu(ppd->ibport_data.rc_qacks);
8043 free_percpu(ppd->ibport_data.rc_delayed_comp);
8044 ppd->cntrs = NULL;
8045 ppd->scntrs = NULL;
8046 ppd->ibport_data.rc_acks = NULL;
8047 ppd->ibport_data.rc_qacks = NULL;
8048 ppd->ibport_data.rc_delayed_comp = NULL;
8049 }
8050 kfree(dd->portcntrnames);
8051 dd->portcntrnames = NULL;
8052 kfree(dd->cntrs);
8053 dd->cntrs = NULL;
8054 kfree(dd->scntrs);
8055 dd->scntrs = NULL;
8056 kfree(dd->cntrnames);
8057 dd->cntrnames = NULL;
8058}
8059
8060#define CNTR_MAX 0xFFFFFFFFFFFFFFFFULL
8061#define CNTR_32BIT_MAX 0x00000000FFFFFFFF
8062
8063static u64 read_dev_port_cntr(struct hfi1_devdata *dd, struct cntr_entry *entry,
8064 u64 *psval, void *context, int vl)
8065{
8066 u64 val;
8067 u64 sval = *psval;
8068
8069 if (entry->flags & CNTR_DISABLED) {
8070 dd_dev_err(dd, "Counter %s not enabled", entry->name);
8071 return 0;
8072 }
8073
8074 hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
8075
8076 val = entry->rw_cntr(entry, context, vl, CNTR_MODE_R, 0);
8077
8078 /* If its a synthetic counter there is more work we need to do */
8079 if (entry->flags & CNTR_SYNTH) {
8080 if (sval == CNTR_MAX) {
8081 /* No need to read already saturated */
8082 return CNTR_MAX;
8083 }
8084
8085 if (entry->flags & CNTR_32BIT) {
8086 /* 32bit counters can wrap multiple times */
8087 u64 upper = sval >> 32;
8088 u64 lower = (sval << 32) >> 32;
8089
8090 if (lower > val) { /* hw wrapped */
8091 if (upper == CNTR_32BIT_MAX)
8092 val = CNTR_MAX;
8093 else
8094 upper++;
8095 }
8096
8097 if (val != CNTR_MAX)
8098 val = (upper << 32) | val;
8099
8100 } else {
8101 /* If we rolled we are saturated */
8102 if ((val < sval) || (val > CNTR_MAX))
8103 val = CNTR_MAX;
8104 }
8105 }
8106
8107 *psval = val;
8108
8109 hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
8110
8111 return val;
8112}
8113
8114static u64 write_dev_port_cntr(struct hfi1_devdata *dd,
8115 struct cntr_entry *entry,
8116 u64 *psval, void *context, int vl, u64 data)
8117{
8118 u64 val;
8119
8120 if (entry->flags & CNTR_DISABLED) {
8121 dd_dev_err(dd, "Counter %s not enabled", entry->name);
8122 return 0;
8123 }
8124
8125 hfi1_cdbg(CNTR, "cntr: %s vl %d psval 0x%llx", entry->name, vl, *psval);
8126
8127 if (entry->flags & CNTR_SYNTH) {
8128 *psval = data;
8129 if (entry->flags & CNTR_32BIT) {
8130 val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
8131 (data << 32) >> 32);
8132 val = data; /* return the full 64bit value */
8133 } else {
8134 val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W,
8135 data);
8136 }
8137 } else {
8138 val = entry->rw_cntr(entry, context, vl, CNTR_MODE_W, data);
8139 }
8140
8141 *psval = val;
8142
8143 hfi1_cdbg(CNTR, "\tNew val=0x%llx", val);
8144
8145 return val;
8146}
8147
8148u64 read_dev_cntr(struct hfi1_devdata *dd, int index, int vl)
8149{
8150 struct cntr_entry *entry;
8151 u64 *sval;
8152
8153 entry = &dev_cntrs[index];
8154 sval = dd->scntrs + entry->offset;
8155
8156 if (vl != CNTR_INVALID_VL)
8157 sval += vl;
8158
8159 return read_dev_port_cntr(dd, entry, sval, dd, vl);
8160}
8161
8162u64 write_dev_cntr(struct hfi1_devdata *dd, int index, int vl, u64 data)
8163{
8164 struct cntr_entry *entry;
8165 u64 *sval;
8166
8167 entry = &dev_cntrs[index];
8168 sval = dd->scntrs + entry->offset;
8169
8170 if (vl != CNTR_INVALID_VL)
8171 sval += vl;
8172
8173 return write_dev_port_cntr(dd, entry, sval, dd, vl, data);
8174}
8175
8176u64 read_port_cntr(struct hfi1_pportdata *ppd, int index, int vl)
8177{
8178 struct cntr_entry *entry;
8179 u64 *sval;
8180
8181 entry = &port_cntrs[index];
8182 sval = ppd->scntrs + entry->offset;
8183
8184 if (vl != CNTR_INVALID_VL)
8185 sval += vl;
8186
8187 if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
8188 (index <= C_RCV_HDR_OVF_LAST)) {
8189 /* We do not want to bother for disabled contexts */
8190 return 0;
8191 }
8192
8193 return read_dev_port_cntr(ppd->dd, entry, sval, ppd, vl);
8194}
8195
8196u64 write_port_cntr(struct hfi1_pportdata *ppd, int index, int vl, u64 data)
8197{
8198 struct cntr_entry *entry;
8199 u64 *sval;
8200
8201 entry = &port_cntrs[index];
8202 sval = ppd->scntrs + entry->offset;
8203
8204 if (vl != CNTR_INVALID_VL)
8205 sval += vl;
8206
8207 if ((index >= C_RCV_HDR_OVF_FIRST + ppd->dd->num_rcv_contexts) &&
8208 (index <= C_RCV_HDR_OVF_LAST)) {
8209 /* We do not want to bother for disabled contexts */
8210 return 0;
8211 }
8212
8213 return write_dev_port_cntr(ppd->dd, entry, sval, ppd, vl, data);
8214}
8215
8216static void update_synth_timer(unsigned long opaque)
8217{
8218 u64 cur_tx;
8219 u64 cur_rx;
8220 u64 total_flits;
8221 u8 update = 0;
8222 int i, j, vl;
8223 struct hfi1_pportdata *ppd;
8224 struct cntr_entry *entry;
8225
8226 struct hfi1_devdata *dd = (struct hfi1_devdata *)opaque;
8227
8228 /*
8229 * Rather than keep beating on the CSRs pick a minimal set that we can
8230 * check to watch for potential roll over. We can do this by looking at
8231 * the number of flits sent/recv. If the total flits exceeds 32bits then
8232 * we have to iterate all the counters and update.
8233 */
8234 entry = &dev_cntrs[C_DC_RCV_FLITS];
8235 cur_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
8236
8237 entry = &dev_cntrs[C_DC_XMIT_FLITS];
8238 cur_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL, CNTR_MODE_R, 0);
8239
8240 hfi1_cdbg(
8241 CNTR,
8242 "[%d] curr tx=0x%llx rx=0x%llx :: last tx=0x%llx rx=0x%llx\n",
8243 dd->unit, cur_tx, cur_rx, dd->last_tx, dd->last_rx);
8244
8245 if ((cur_tx < dd->last_tx) || (cur_rx < dd->last_rx)) {
8246 /*
8247 * May not be strictly necessary to update but it won't hurt and
8248 * simplifies the logic here.
8249 */
8250 update = 1;
8251 hfi1_cdbg(CNTR, "[%d] Tripwire counter rolled, updating",
8252 dd->unit);
8253 } else {
8254 total_flits = (cur_tx - dd->last_tx) + (cur_rx - dd->last_rx);
8255 hfi1_cdbg(CNTR,
8256 "[%d] total flits 0x%llx limit 0x%llx\n", dd->unit,
8257 total_flits, (u64)CNTR_32BIT_MAX);
8258 if (total_flits >= CNTR_32BIT_MAX) {
8259 hfi1_cdbg(CNTR, "[%d] 32bit limit hit, updating",
8260 dd->unit);
8261 update = 1;
8262 }
8263 }
8264
8265 if (update) {
8266 hfi1_cdbg(CNTR, "[%d] Updating dd and ppd counters", dd->unit);
8267 for (i = 0; i < DEV_CNTR_LAST; i++) {
8268 entry = &dev_cntrs[i];
8269 if (entry->flags & CNTR_VL) {
8270 for (vl = 0; vl < C_VL_COUNT; vl++)
8271 read_dev_cntr(dd, i, vl);
8272 } else {
8273 read_dev_cntr(dd, i, CNTR_INVALID_VL);
8274 }
8275 }
8276 ppd = (struct hfi1_pportdata *)(dd + 1);
8277 for (i = 0; i < dd->num_pports; i++, ppd++) {
8278 for (j = 0; j < PORT_CNTR_LAST; j++) {
8279 entry = &port_cntrs[j];
8280 if (entry->flags & CNTR_VL) {
8281 for (vl = 0; vl < C_VL_COUNT; vl++)
8282 read_port_cntr(ppd, j, vl);
8283 } else {
8284 read_port_cntr(ppd, j, CNTR_INVALID_VL);
8285 }
8286 }
8287 }
8288
8289 /*
8290 * We want the value in the register. The goal is to keep track
8291 * of the number of "ticks" not the counter value. In other
8292 * words if the register rolls we want to notice it and go ahead
8293 * and force an update.
8294 */
8295 entry = &dev_cntrs[C_DC_XMIT_FLITS];
8296 dd->last_tx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
8297 CNTR_MODE_R, 0);
8298
8299 entry = &dev_cntrs[C_DC_RCV_FLITS];
8300 dd->last_rx = entry->rw_cntr(entry, dd, CNTR_INVALID_VL,
8301 CNTR_MODE_R, 0);
8302
8303 hfi1_cdbg(CNTR, "[%d] setting last tx/rx to 0x%llx 0x%llx",
8304 dd->unit, dd->last_tx, dd->last_rx);
8305
8306 } else {
8307 hfi1_cdbg(CNTR, "[%d] No update necessary", dd->unit);
8308 }
8309
8310mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
8311}
8312
8313#define C_MAX_NAME 13 /* 12 chars + one for /0 */
8314static int init_cntrs(struct hfi1_devdata *dd)
8315{
8316 int i, rcv_ctxts, index, j;
8317 size_t sz;
8318 char *p;
8319 char name[C_MAX_NAME];
8320 struct hfi1_pportdata *ppd;
8321
8322 /* set up the stats timer; the add_timer is done at the end */
Muhammad Falak R Wani24523a92015-10-25 16:13:23 +05308323 setup_timer(&dd->synth_stats_timer, update_synth_timer,
8324 (unsigned long)dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008325
8326 /***********************/
8327 /* per device counters */
8328 /***********************/
8329
8330 /* size names and determine how many we have*/
8331 dd->ndevcntrs = 0;
8332 sz = 0;
8333 index = 0;
8334
8335 for (i = 0; i < DEV_CNTR_LAST; i++) {
8336 hfi1_dbg_early("Init cntr %s\n", dev_cntrs[i].name);
8337 if (dev_cntrs[i].flags & CNTR_DISABLED) {
8338 hfi1_dbg_early("\tSkipping %s\n", dev_cntrs[i].name);
8339 continue;
8340 }
8341
8342 if (dev_cntrs[i].flags & CNTR_VL) {
8343 hfi1_dbg_early("\tProcessing VL cntr\n");
8344 dev_cntrs[i].offset = index;
8345 for (j = 0; j < C_VL_COUNT; j++) {
8346 memset(name, '\0', C_MAX_NAME);
8347 snprintf(name, C_MAX_NAME, "%s%d",
8348 dev_cntrs[i].name,
8349 vl_from_idx(j));
8350 sz += strlen(name);
8351 sz++;
8352 hfi1_dbg_early("\t\t%s\n", name);
8353 dd->ndevcntrs++;
8354 index++;
8355 }
8356 } else {
8357 /* +1 for newline */
8358 sz += strlen(dev_cntrs[i].name) + 1;
8359 dd->ndevcntrs++;
8360 dev_cntrs[i].offset = index;
8361 index++;
8362 hfi1_dbg_early("\tAdding %s\n", dev_cntrs[i].name);
8363 }
8364 }
8365
8366 /* allocate space for the counter values */
8367 dd->cntrs = kcalloc(index, sizeof(u64), GFP_KERNEL);
8368 if (!dd->cntrs)
8369 goto bail;
8370
8371 dd->scntrs = kcalloc(index, sizeof(u64), GFP_KERNEL);
8372 if (!dd->scntrs)
8373 goto bail;
8374
8375
8376 /* allocate space for the counter names */
8377 dd->cntrnameslen = sz;
8378 dd->cntrnames = kmalloc(sz, GFP_KERNEL);
8379 if (!dd->cntrnames)
8380 goto bail;
8381
8382 /* fill in the names */
8383 for (p = dd->cntrnames, i = 0, index = 0; i < DEV_CNTR_LAST; i++) {
8384 if (dev_cntrs[i].flags & CNTR_DISABLED) {
8385 /* Nothing */
8386 } else {
8387 if (dev_cntrs[i].flags & CNTR_VL) {
8388 for (j = 0; j < C_VL_COUNT; j++) {
8389 memset(name, '\0', C_MAX_NAME);
8390 snprintf(name, C_MAX_NAME, "%s%d",
8391 dev_cntrs[i].name,
8392 vl_from_idx(j));
8393 memcpy(p, name, strlen(name));
8394 p += strlen(name);
8395 *p++ = '\n';
8396 }
8397 } else {
8398 memcpy(p, dev_cntrs[i].name,
8399 strlen(dev_cntrs[i].name));
8400 p += strlen(dev_cntrs[i].name);
8401 *p++ = '\n';
8402 }
8403 index++;
8404 }
8405 }
8406
8407 /*********************/
8408 /* per port counters */
8409 /*********************/
8410
8411 /*
8412 * Go through the counters for the overflows and disable the ones we
8413 * don't need. This varies based on platform so we need to do it
8414 * dynamically here.
8415 */
8416 rcv_ctxts = dd->num_rcv_contexts;
8417 for (i = C_RCV_HDR_OVF_FIRST + rcv_ctxts;
8418 i <= C_RCV_HDR_OVF_LAST; i++) {
8419 port_cntrs[i].flags |= CNTR_DISABLED;
8420 }
8421
8422 /* size port counter names and determine how many we have*/
8423 sz = 0;
8424 dd->nportcntrs = 0;
8425 for (i = 0; i < PORT_CNTR_LAST; i++) {
8426 hfi1_dbg_early("Init pcntr %s\n", port_cntrs[i].name);
8427 if (port_cntrs[i].flags & CNTR_DISABLED) {
8428 hfi1_dbg_early("\tSkipping %s\n", port_cntrs[i].name);
8429 continue;
8430 }
8431
8432 if (port_cntrs[i].flags & CNTR_VL) {
8433 hfi1_dbg_early("\tProcessing VL cntr\n");
8434 port_cntrs[i].offset = dd->nportcntrs;
8435 for (j = 0; j < C_VL_COUNT; j++) {
8436 memset(name, '\0', C_MAX_NAME);
8437 snprintf(name, C_MAX_NAME, "%s%d",
8438 port_cntrs[i].name,
8439 vl_from_idx(j));
8440 sz += strlen(name);
8441 sz++;
8442 hfi1_dbg_early("\t\t%s\n", name);
8443 dd->nportcntrs++;
8444 }
8445 } else {
8446 /* +1 for newline */
8447 sz += strlen(port_cntrs[i].name) + 1;
8448 port_cntrs[i].offset = dd->nportcntrs;
8449 dd->nportcntrs++;
8450 hfi1_dbg_early("\tAdding %s\n", port_cntrs[i].name);
8451 }
8452 }
8453
8454 /* allocate space for the counter names */
8455 dd->portcntrnameslen = sz;
8456 dd->portcntrnames = kmalloc(sz, GFP_KERNEL);
8457 if (!dd->portcntrnames)
8458 goto bail;
8459
8460 /* fill in port cntr names */
8461 for (p = dd->portcntrnames, i = 0; i < PORT_CNTR_LAST; i++) {
8462 if (port_cntrs[i].flags & CNTR_DISABLED)
8463 continue;
8464
8465 if (port_cntrs[i].flags & CNTR_VL) {
8466 for (j = 0; j < C_VL_COUNT; j++) {
8467 memset(name, '\0', C_MAX_NAME);
8468 snprintf(name, C_MAX_NAME, "%s%d",
8469 port_cntrs[i].name,
8470 vl_from_idx(j));
8471 memcpy(p, name, strlen(name));
8472 p += strlen(name);
8473 *p++ = '\n';
8474 }
8475 } else {
8476 memcpy(p, port_cntrs[i].name,
8477 strlen(port_cntrs[i].name));
8478 p += strlen(port_cntrs[i].name);
8479 *p++ = '\n';
8480 }
8481 }
8482
8483 /* allocate per port storage for counter values */
8484 ppd = (struct hfi1_pportdata *)(dd + 1);
8485 for (i = 0; i < dd->num_pports; i++, ppd++) {
8486 ppd->cntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
8487 if (!ppd->cntrs)
8488 goto bail;
8489
8490 ppd->scntrs = kcalloc(dd->nportcntrs, sizeof(u64), GFP_KERNEL);
8491 if (!ppd->scntrs)
8492 goto bail;
8493 }
8494
8495 /* CPU counters need to be allocated and zeroed */
8496 if (init_cpu_counters(dd))
8497 goto bail;
8498
8499 mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
8500 return 0;
8501bail:
8502 free_cntrs(dd);
8503 return -ENOMEM;
8504}
8505
8506
8507static u32 chip_to_opa_lstate(struct hfi1_devdata *dd, u32 chip_lstate)
8508{
8509 switch (chip_lstate) {
8510 default:
8511 dd_dev_err(dd,
8512 "Unknown logical state 0x%x, reporting IB_PORT_DOWN\n",
8513 chip_lstate);
8514 /* fall through */
8515 case LSTATE_DOWN:
8516 return IB_PORT_DOWN;
8517 case LSTATE_INIT:
8518 return IB_PORT_INIT;
8519 case LSTATE_ARMED:
8520 return IB_PORT_ARMED;
8521 case LSTATE_ACTIVE:
8522 return IB_PORT_ACTIVE;
8523 }
8524}
8525
8526u32 chip_to_opa_pstate(struct hfi1_devdata *dd, u32 chip_pstate)
8527{
8528 /* look at the HFI meta-states only */
8529 switch (chip_pstate & 0xf0) {
8530 default:
8531 dd_dev_err(dd, "Unexpected chip physical state of 0x%x\n",
8532 chip_pstate);
8533 /* fall through */
8534 case PLS_DISABLED:
8535 return IB_PORTPHYSSTATE_DISABLED;
8536 case PLS_OFFLINE:
8537 return OPA_PORTPHYSSTATE_OFFLINE;
8538 case PLS_POLLING:
8539 return IB_PORTPHYSSTATE_POLLING;
8540 case PLS_CONFIGPHY:
8541 return IB_PORTPHYSSTATE_TRAINING;
8542 case PLS_LINKUP:
8543 return IB_PORTPHYSSTATE_LINKUP;
8544 case PLS_PHYTEST:
8545 return IB_PORTPHYSSTATE_PHY_TEST;
8546 }
8547}
8548
8549/* return the OPA port logical state name */
8550const char *opa_lstate_name(u32 lstate)
8551{
8552 static const char * const port_logical_names[] = {
8553 "PORT_NOP",
8554 "PORT_DOWN",
8555 "PORT_INIT",
8556 "PORT_ARMED",
8557 "PORT_ACTIVE",
8558 "PORT_ACTIVE_DEFER",
8559 };
8560 if (lstate < ARRAY_SIZE(port_logical_names))
8561 return port_logical_names[lstate];
8562 return "unknown";
8563}
8564
8565/* return the OPA port physical state name */
8566const char *opa_pstate_name(u32 pstate)
8567{
8568 static const char * const port_physical_names[] = {
8569 "PHYS_NOP",
8570 "reserved1",
8571 "PHYS_POLL",
8572 "PHYS_DISABLED",
8573 "PHYS_TRAINING",
8574 "PHYS_LINKUP",
8575 "PHYS_LINK_ERR_RECOVER",
8576 "PHYS_PHY_TEST",
8577 "reserved8",
8578 "PHYS_OFFLINE",
8579 "PHYS_GANGED",
8580 "PHYS_TEST",
8581 };
8582 if (pstate < ARRAY_SIZE(port_physical_names))
8583 return port_physical_names[pstate];
8584 return "unknown";
8585}
8586
8587/*
8588 * Read the hardware link state and set the driver's cached value of it.
8589 * Return the (new) current value.
8590 */
8591u32 get_logical_state(struct hfi1_pportdata *ppd)
8592{
8593 u32 new_state;
8594
8595 new_state = chip_to_opa_lstate(ppd->dd, read_logical_state(ppd->dd));
8596 if (new_state != ppd->lstate) {
8597 dd_dev_info(ppd->dd, "logical state changed to %s (0x%x)\n",
8598 opa_lstate_name(new_state), new_state);
8599 ppd->lstate = new_state;
8600 }
8601 /*
8602 * Set port status flags in the page mapped into userspace
8603 * memory. Do it here to ensure a reliable state - this is
8604 * the only function called by all state handling code.
8605 * Always set the flags due to the fact that the cache value
8606 * might have been changed explicitly outside of this
8607 * function.
8608 */
8609 if (ppd->statusp) {
8610 switch (ppd->lstate) {
8611 case IB_PORT_DOWN:
8612 case IB_PORT_INIT:
8613 *ppd->statusp &= ~(HFI1_STATUS_IB_CONF |
8614 HFI1_STATUS_IB_READY);
8615 break;
8616 case IB_PORT_ARMED:
8617 *ppd->statusp |= HFI1_STATUS_IB_CONF;
8618 break;
8619 case IB_PORT_ACTIVE:
8620 *ppd->statusp |= HFI1_STATUS_IB_READY;
8621 break;
8622 }
8623 }
8624 return ppd->lstate;
8625}
8626
8627/**
8628 * wait_logical_linkstate - wait for an IB link state change to occur
8629 * @ppd: port device
8630 * @state: the state to wait for
8631 * @msecs: the number of milliseconds to wait
8632 *
8633 * Wait up to msecs milliseconds for IB link state change to occur.
8634 * For now, take the easy polling route.
8635 * Returns 0 if state reached, otherwise -ETIMEDOUT.
8636 */
8637static int wait_logical_linkstate(struct hfi1_pportdata *ppd, u32 state,
8638 int msecs)
8639{
8640 unsigned long timeout;
8641
8642 timeout = jiffies + msecs_to_jiffies(msecs);
8643 while (1) {
8644 if (get_logical_state(ppd) == state)
8645 return 0;
8646 if (time_after(jiffies, timeout))
8647 break;
8648 msleep(20);
8649 }
8650 dd_dev_err(ppd->dd, "timeout waiting for link state 0x%x\n", state);
8651
8652 return -ETIMEDOUT;
8653}
8654
8655u8 hfi1_ibphys_portstate(struct hfi1_pportdata *ppd)
8656{
8657 static u32 remembered_state = 0xff;
8658 u32 pstate;
8659 u32 ib_pstate;
8660
8661 pstate = read_physical_state(ppd->dd);
8662 ib_pstate = chip_to_opa_pstate(ppd->dd, pstate);
8663 if (remembered_state != ib_pstate) {
8664 dd_dev_info(ppd->dd,
8665 "%s: physical state changed to %s (0x%x), phy 0x%x\n",
8666 __func__, opa_pstate_name(ib_pstate), ib_pstate,
8667 pstate);
8668 remembered_state = ib_pstate;
8669 }
8670 return ib_pstate;
8671}
8672
8673/*
8674 * Read/modify/write ASIC_QSFP register bits as selected by mask
8675 * data: 0 or 1 in the positions depending on what needs to be written
8676 * dir: 0 for read, 1 for write
8677 * mask: select by setting
8678 * I2CCLK (bit 0)
8679 * I2CDATA (bit 1)
8680 */
8681u64 hfi1_gpio_mod(struct hfi1_devdata *dd, u32 target, u32 data, u32 dir,
8682 u32 mask)
8683{
8684 u64 qsfp_oe, target_oe;
8685
8686 target_oe = target ? ASIC_QSFP2_OE : ASIC_QSFP1_OE;
8687 if (mask) {
8688 /* We are writing register bits, so lock access */
8689 dir &= mask;
8690 data &= mask;
8691
8692 qsfp_oe = read_csr(dd, target_oe);
8693 qsfp_oe = (qsfp_oe & ~(u64)mask) | (u64)dir;
8694 write_csr(dd, target_oe, qsfp_oe);
8695 }
8696 /* We are exclusively reading bits here, but it is unlikely
8697 * we'll get valid data when we set the direction of the pin
8698 * in the same call, so read should call this function again
8699 * to get valid data
8700 */
8701 return read_csr(dd, target ? ASIC_QSFP2_IN : ASIC_QSFP1_IN);
8702}
8703
8704#define CLEAR_STATIC_RATE_CONTROL_SMASK(r) \
8705(r &= ~SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
8706
8707#define SET_STATIC_RATE_CONTROL_SMASK(r) \
8708(r |= SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
8709
8710int hfi1_init_ctxt(struct send_context *sc)
8711{
8712 if (sc != NULL) {
8713 struct hfi1_devdata *dd = sc->dd;
8714 u64 reg;
8715 u8 set = (sc->type == SC_USER ?
8716 HFI1_CAP_IS_USET(STATIC_RATE_CTRL) :
8717 HFI1_CAP_IS_KSET(STATIC_RATE_CTRL));
8718 reg = read_kctxt_csr(dd, sc->hw_context,
8719 SEND_CTXT_CHECK_ENABLE);
8720 if (set)
8721 CLEAR_STATIC_RATE_CONTROL_SMASK(reg);
8722 else
8723 SET_STATIC_RATE_CONTROL_SMASK(reg);
8724 write_kctxt_csr(dd, sc->hw_context,
8725 SEND_CTXT_CHECK_ENABLE, reg);
8726 }
8727 return 0;
8728}
8729
8730int hfi1_tempsense_rd(struct hfi1_devdata *dd, struct hfi1_temp *temp)
8731{
8732 int ret = 0;
8733 u64 reg;
8734
8735 if (dd->icode != ICODE_RTL_SILICON) {
8736 if (HFI1_CAP_IS_KSET(PRINT_UNIMPL))
8737 dd_dev_info(dd, "%s: tempsense not supported by HW\n",
8738 __func__);
8739 return -EINVAL;
8740 }
8741 reg = read_csr(dd, ASIC_STS_THERM);
8742 temp->curr = ((reg >> ASIC_STS_THERM_CURR_TEMP_SHIFT) &
8743 ASIC_STS_THERM_CURR_TEMP_MASK);
8744 temp->lo_lim = ((reg >> ASIC_STS_THERM_LO_TEMP_SHIFT) &
8745 ASIC_STS_THERM_LO_TEMP_MASK);
8746 temp->hi_lim = ((reg >> ASIC_STS_THERM_HI_TEMP_SHIFT) &
8747 ASIC_STS_THERM_HI_TEMP_MASK);
8748 temp->crit_lim = ((reg >> ASIC_STS_THERM_CRIT_TEMP_SHIFT) &
8749 ASIC_STS_THERM_CRIT_TEMP_MASK);
8750 /* triggers is a 3-bit value - 1 bit per trigger. */
8751 temp->triggers = (u8)((reg >> ASIC_STS_THERM_LOW_SHIFT) & 0x7);
8752
8753 return ret;
8754}
8755
8756/* ========================================================================= */
8757
8758/*
8759 * Enable/disable chip from delivering interrupts.
8760 */
8761void set_intr_state(struct hfi1_devdata *dd, u32 enable)
8762{
8763 int i;
8764
8765 /*
8766 * In HFI, the mask needs to be 1 to allow interrupts.
8767 */
8768 if (enable) {
8769 u64 cce_int_mask;
8770 const int qsfp1_int_smask = QSFP1_INT % 64;
8771 const int qsfp2_int_smask = QSFP2_INT % 64;
8772
8773 /* enable all interrupts */
8774 for (i = 0; i < CCE_NUM_INT_CSRS; i++)
8775 write_csr(dd, CCE_INT_MASK + (8*i), ~(u64)0);
8776
8777 /*
8778 * disable QSFP1 interrupts for HFI1, QSFP2 interrupts for HFI0
8779 * Qsfp1Int and Qsfp2Int are adjacent bits in the same CSR,
8780 * therefore just one of QSFP1_INT/QSFP2_INT can be used to find
8781 * the index of the appropriate CSR in the CCEIntMask CSR array
8782 */
8783 cce_int_mask = read_csr(dd, CCE_INT_MASK +
8784 (8*(QSFP1_INT/64)));
8785 if (dd->hfi1_id) {
8786 cce_int_mask &= ~((u64)1 << qsfp1_int_smask);
8787 write_csr(dd, CCE_INT_MASK + (8*(QSFP1_INT/64)),
8788 cce_int_mask);
8789 } else {
8790 cce_int_mask &= ~((u64)1 << qsfp2_int_smask);
8791 write_csr(dd, CCE_INT_MASK + (8*(QSFP2_INT/64)),
8792 cce_int_mask);
8793 }
8794 } else {
8795 for (i = 0; i < CCE_NUM_INT_CSRS; i++)
8796 write_csr(dd, CCE_INT_MASK + (8*i), 0ull);
8797 }
8798}
8799
8800/*
8801 * Clear all interrupt sources on the chip.
8802 */
8803static void clear_all_interrupts(struct hfi1_devdata *dd)
8804{
8805 int i;
8806
8807 for (i = 0; i < CCE_NUM_INT_CSRS; i++)
8808 write_csr(dd, CCE_INT_CLEAR + (8*i), ~(u64)0);
8809
8810 write_csr(dd, CCE_ERR_CLEAR, ~(u64)0);
8811 write_csr(dd, MISC_ERR_CLEAR, ~(u64)0);
8812 write_csr(dd, RCV_ERR_CLEAR, ~(u64)0);
8813 write_csr(dd, SEND_ERR_CLEAR, ~(u64)0);
8814 write_csr(dd, SEND_PIO_ERR_CLEAR, ~(u64)0);
8815 write_csr(dd, SEND_DMA_ERR_CLEAR, ~(u64)0);
8816 write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~(u64)0);
8817 for (i = 0; i < dd->chip_send_contexts; i++)
8818 write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~(u64)0);
8819 for (i = 0; i < dd->chip_sdma_engines; i++)
8820 write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~(u64)0);
8821
8822 write_csr(dd, DCC_ERR_FLG_CLR, ~(u64)0);
8823 write_csr(dd, DC_LCB_ERR_CLR, ~(u64)0);
8824 write_csr(dd, DC_DC8051_ERR_CLR, ~(u64)0);
8825}
8826
8827/* Move to pcie.c? */
8828static void disable_intx(struct pci_dev *pdev)
8829{
8830 pci_intx(pdev, 0);
8831}
8832
8833static void clean_up_interrupts(struct hfi1_devdata *dd)
8834{
8835 int i;
8836
8837 /* remove irqs - must happen before disabling/turning off */
8838 if (dd->num_msix_entries) {
8839 /* MSI-X */
8840 struct hfi1_msix_entry *me = dd->msix_entries;
8841
8842 for (i = 0; i < dd->num_msix_entries; i++, me++) {
8843 if (me->arg == NULL) /* => no irq, no affinity */
8844 break;
8845 irq_set_affinity_hint(dd->msix_entries[i].msix.vector,
8846 NULL);
8847 free_irq(me->msix.vector, me->arg);
8848 }
8849 } else {
8850 /* INTx */
8851 if (dd->requested_intx_irq) {
8852 free_irq(dd->pcidev->irq, dd);
8853 dd->requested_intx_irq = 0;
8854 }
8855 }
8856
8857 /* turn off interrupts */
8858 if (dd->num_msix_entries) {
8859 /* MSI-X */
Amitoj Kaur Chawla6e5b6132015-11-01 16:14:32 +05308860 pci_disable_msix(dd->pcidev);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008861 } else {
8862 /* INTx */
8863 disable_intx(dd->pcidev);
8864 }
8865
8866 /* clean structures */
8867 for (i = 0; i < dd->num_msix_entries; i++)
8868 free_cpumask_var(dd->msix_entries[i].mask);
8869 kfree(dd->msix_entries);
8870 dd->msix_entries = NULL;
8871 dd->num_msix_entries = 0;
8872}
8873
8874/*
8875 * Remap the interrupt source from the general handler to the given MSI-X
8876 * interrupt.
8877 */
8878static void remap_intr(struct hfi1_devdata *dd, int isrc, int msix_intr)
8879{
8880 u64 reg;
8881 int m, n;
8882
8883 /* clear from the handled mask of the general interrupt */
8884 m = isrc / 64;
8885 n = isrc % 64;
8886 dd->gi_mask[m] &= ~((u64)1 << n);
8887
8888 /* direct the chip source to the given MSI-X interrupt */
8889 m = isrc / 8;
8890 n = isrc % 8;
8891 reg = read_csr(dd, CCE_INT_MAP + (8*m));
8892 reg &= ~((u64)0xff << (8*n));
8893 reg |= ((u64)msix_intr & 0xff) << (8*n);
8894 write_csr(dd, CCE_INT_MAP + (8*m), reg);
8895}
8896
8897static void remap_sdma_interrupts(struct hfi1_devdata *dd,
8898 int engine, int msix_intr)
8899{
8900 /*
8901 * SDMA engine interrupt sources grouped by type, rather than
8902 * engine. Per-engine interrupts are as follows:
8903 * SDMA
8904 * SDMAProgress
8905 * SDMAIdle
8906 */
8907 remap_intr(dd, IS_SDMA_START + 0*TXE_NUM_SDMA_ENGINES + engine,
8908 msix_intr);
8909 remap_intr(dd, IS_SDMA_START + 1*TXE_NUM_SDMA_ENGINES + engine,
8910 msix_intr);
8911 remap_intr(dd, IS_SDMA_START + 2*TXE_NUM_SDMA_ENGINES + engine,
8912 msix_intr);
8913}
8914
Mike Marciniszyn77241052015-07-30 15:17:43 -04008915static int request_intx_irq(struct hfi1_devdata *dd)
8916{
8917 int ret;
8918
Jubin John98050712015-11-16 21:59:27 -05008919 snprintf(dd->intx_name, sizeof(dd->intx_name), DRIVER_NAME "_%d",
8920 dd->unit);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008921 ret = request_irq(dd->pcidev->irq, general_interrupt,
8922 IRQF_SHARED, dd->intx_name, dd);
8923 if (ret)
8924 dd_dev_err(dd, "unable to request INTx interrupt, err %d\n",
8925 ret);
8926 else
8927 dd->requested_intx_irq = 1;
8928 return ret;
8929}
8930
8931static int request_msix_irqs(struct hfi1_devdata *dd)
8932{
8933 const struct cpumask *local_mask;
8934 cpumask_var_t def, rcv;
8935 bool def_ret, rcv_ret;
8936 int first_general, last_general;
8937 int first_sdma, last_sdma;
8938 int first_rx, last_rx;
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -05008939 int first_cpu, curr_cpu;
Mike Marciniszyn77241052015-07-30 15:17:43 -04008940 int rcv_cpu, sdma_cpu;
8941 int i, ret = 0, possible;
8942 int ht;
8943
8944 /* calculate the ranges we are going to use */
8945 first_general = 0;
8946 first_sdma = last_general = first_general + 1;
8947 first_rx = last_sdma = first_sdma + dd->num_sdma;
8948 last_rx = first_rx + dd->n_krcv_queues;
8949
8950 /*
8951 * Interrupt affinity.
8952 *
8953 * non-rcv avail gets a default mask that
8954 * starts as possible cpus with threads reset
8955 * and each rcv avail reset.
8956 *
8957 * rcv avail gets node relative 1 wrapping back
8958 * to the node relative 1 as necessary.
8959 *
8960 */
8961 local_mask = cpumask_of_pcibus(dd->pcidev->bus);
8962 /* if first cpu is invalid, use NUMA 0 */
8963 if (cpumask_first(local_mask) >= nr_cpu_ids)
8964 local_mask = topology_core_cpumask(0);
8965
8966 def_ret = zalloc_cpumask_var(&def, GFP_KERNEL);
8967 rcv_ret = zalloc_cpumask_var(&rcv, GFP_KERNEL);
8968 if (!def_ret || !rcv_ret)
8969 goto bail;
8970 /* use local mask as default */
8971 cpumask_copy(def, local_mask);
8972 possible = cpumask_weight(def);
8973 /* disarm threads from default */
8974 ht = cpumask_weight(
8975 topology_sibling_cpumask(cpumask_first(local_mask)));
8976 for (i = possible/ht; i < possible; i++)
8977 cpumask_clear_cpu(i, def);
Mike Marciniszyn77241052015-07-30 15:17:43 -04008978 /* def now has full cores on chosen node*/
8979 first_cpu = cpumask_first(def);
8980 if (nr_cpu_ids >= first_cpu)
8981 first_cpu++;
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -05008982 curr_cpu = first_cpu;
Mike Marciniszyn77241052015-07-30 15:17:43 -04008983
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -05008984 /* One context is reserved as control context */
8985 for (i = first_cpu; i < dd->n_krcv_queues + first_cpu - 1; i++) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04008986 cpumask_clear_cpu(curr_cpu, def);
8987 cpumask_set_cpu(curr_cpu, rcv);
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -05008988 curr_cpu = cpumask_next(curr_cpu, def);
8989 if (curr_cpu >= nr_cpu_ids)
8990 break;
Mike Marciniszyn77241052015-07-30 15:17:43 -04008991 }
8992 /* def mask has non-rcv, rcv has recv mask */
8993 rcv_cpu = cpumask_first(rcv);
8994 sdma_cpu = cpumask_first(def);
8995
8996 /*
8997 * Sanity check - the code expects all SDMA chip source
8998 * interrupts to be in the same CSR, starting at bit 0. Verify
8999 * that this is true by checking the bit location of the start.
9000 */
9001 BUILD_BUG_ON(IS_SDMA_START % 64);
9002
9003 for (i = 0; i < dd->num_msix_entries; i++) {
9004 struct hfi1_msix_entry *me = &dd->msix_entries[i];
9005 const char *err_info;
9006 irq_handler_t handler;
Dean Luickf4f30031c2015-10-26 10:28:44 -04009007 irq_handler_t thread = NULL;
Mike Marciniszyn77241052015-07-30 15:17:43 -04009008 void *arg;
9009 int idx;
9010 struct hfi1_ctxtdata *rcd = NULL;
9011 struct sdma_engine *sde = NULL;
9012
9013 /* obtain the arguments to request_irq */
9014 if (first_general <= i && i < last_general) {
9015 idx = i - first_general;
9016 handler = general_interrupt;
9017 arg = dd;
9018 snprintf(me->name, sizeof(me->name),
Jubin John98050712015-11-16 21:59:27 -05009019 DRIVER_NAME "_%d", dd->unit);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009020 err_info = "general";
9021 } else if (first_sdma <= i && i < last_sdma) {
9022 idx = i - first_sdma;
9023 sde = &dd->per_sdma[idx];
9024 handler = sdma_interrupt;
9025 arg = sde;
9026 snprintf(me->name, sizeof(me->name),
Jubin John98050712015-11-16 21:59:27 -05009027 DRIVER_NAME "_%d sdma%d", dd->unit, idx);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009028 err_info = "sdma";
9029 remap_sdma_interrupts(dd, idx, i);
9030 } else if (first_rx <= i && i < last_rx) {
9031 idx = i - first_rx;
9032 rcd = dd->rcd[idx];
9033 /* no interrupt if no rcd */
9034 if (!rcd)
9035 continue;
9036 /*
9037 * Set the interrupt register and mask for this
9038 * context's interrupt.
9039 */
9040 rcd->ireg = (IS_RCVAVAIL_START+idx) / 64;
9041 rcd->imask = ((u64)1) <<
9042 ((IS_RCVAVAIL_START+idx) % 64);
9043 handler = receive_context_interrupt;
Dean Luickf4f30031c2015-10-26 10:28:44 -04009044 thread = receive_context_thread;
Mike Marciniszyn77241052015-07-30 15:17:43 -04009045 arg = rcd;
9046 snprintf(me->name, sizeof(me->name),
Jubin John98050712015-11-16 21:59:27 -05009047 DRIVER_NAME "_%d kctxt%d", dd->unit, idx);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009048 err_info = "receive context";
Amitoj Kaur Chawla66c09332015-11-01 16:18:18 +05309049 remap_intr(dd, IS_RCVAVAIL_START + idx, i);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009050 } else {
9051 /* not in our expected range - complain, then
9052 ignore it */
9053 dd_dev_err(dd,
9054 "Unexpected extra MSI-X interrupt %d\n", i);
9055 continue;
9056 }
9057 /* no argument, no interrupt */
9058 if (arg == NULL)
9059 continue;
9060 /* make sure the name is terminated */
9061 me->name[sizeof(me->name)-1] = 0;
9062
Dean Luickf4f30031c2015-10-26 10:28:44 -04009063 ret = request_threaded_irq(me->msix.vector, handler, thread, 0,
9064 me->name, arg);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009065 if (ret) {
9066 dd_dev_err(dd,
9067 "unable to allocate %s interrupt, vector %d, index %d, err %d\n",
9068 err_info, me->msix.vector, idx, ret);
9069 return ret;
9070 }
9071 /*
9072 * assign arg after request_irq call, so it will be
9073 * cleaned up
9074 */
9075 me->arg = arg;
9076
9077 if (!zalloc_cpumask_var(
9078 &dd->msix_entries[i].mask,
9079 GFP_KERNEL))
9080 goto bail;
9081 if (handler == sdma_interrupt) {
9082 dd_dev_info(dd, "sdma engine %d cpu %d\n",
9083 sde->this_idx, sdma_cpu);
Mike Marciniszyn0a226ed2015-11-09 19:13:58 -05009084 sde->cpu = sdma_cpu;
Mike Marciniszyn77241052015-07-30 15:17:43 -04009085 cpumask_set_cpu(sdma_cpu, dd->msix_entries[i].mask);
9086 sdma_cpu = cpumask_next(sdma_cpu, def);
9087 if (sdma_cpu >= nr_cpu_ids)
9088 sdma_cpu = cpumask_first(def);
9089 } else if (handler == receive_context_interrupt) {
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -05009090 dd_dev_info(dd, "rcv ctxt %d cpu %d\n", rcd->ctxt,
9091 (rcd->ctxt == HFI1_CTRL_CTXT) ?
9092 cpumask_first(def) : rcv_cpu);
9093 if (rcd->ctxt == HFI1_CTRL_CTXT) {
9094 /* map to first default */
9095 cpumask_set_cpu(cpumask_first(def),
9096 dd->msix_entries[i].mask);
9097 } else {
9098 cpumask_set_cpu(rcv_cpu,
9099 dd->msix_entries[i].mask);
9100 rcv_cpu = cpumask_next(rcv_cpu, rcv);
9101 if (rcv_cpu >= nr_cpu_ids)
9102 rcv_cpu = cpumask_first(rcv);
9103 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04009104 } else {
9105 /* otherwise first def */
9106 dd_dev_info(dd, "%s cpu %d\n",
9107 err_info, cpumask_first(def));
9108 cpumask_set_cpu(
9109 cpumask_first(def), dd->msix_entries[i].mask);
9110 }
9111 irq_set_affinity_hint(
9112 dd->msix_entries[i].msix.vector,
9113 dd->msix_entries[i].mask);
9114 }
9115
9116out:
9117 free_cpumask_var(def);
9118 free_cpumask_var(rcv);
9119 return ret;
9120bail:
9121 ret = -ENOMEM;
9122 goto out;
9123}
9124
9125/*
9126 * Set the general handler to accept all interrupts, remap all
9127 * chip interrupts back to MSI-X 0.
9128 */
9129static void reset_interrupts(struct hfi1_devdata *dd)
9130{
9131 int i;
9132
9133 /* all interrupts handled by the general handler */
9134 for (i = 0; i < CCE_NUM_INT_CSRS; i++)
9135 dd->gi_mask[i] = ~(u64)0;
9136
9137 /* all chip interrupts map to MSI-X 0 */
9138 for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
9139 write_csr(dd, CCE_INT_MAP + (8*i), 0);
9140}
9141
9142static int set_up_interrupts(struct hfi1_devdata *dd)
9143{
9144 struct hfi1_msix_entry *entries;
9145 u32 total, request;
9146 int i, ret;
9147 int single_interrupt = 0; /* we expect to have all the interrupts */
9148
9149 /*
9150 * Interrupt count:
9151 * 1 general, "slow path" interrupt (includes the SDMA engines
9152 * slow source, SDMACleanupDone)
9153 * N interrupts - one per used SDMA engine
9154 * M interrupt - one per kernel receive context
9155 */
9156 total = 1 + dd->num_sdma + dd->n_krcv_queues;
9157
9158 entries = kcalloc(total, sizeof(*entries), GFP_KERNEL);
9159 if (!entries) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04009160 ret = -ENOMEM;
9161 goto fail;
9162 }
9163 /* 1-1 MSI-X entry assignment */
9164 for (i = 0; i < total; i++)
9165 entries[i].msix.entry = i;
9166
9167 /* ask for MSI-X interrupts */
9168 request = total;
9169 request_msix(dd, &request, entries);
9170
9171 if (request == 0) {
9172 /* using INTx */
9173 /* dd->num_msix_entries already zero */
9174 kfree(entries);
9175 single_interrupt = 1;
9176 dd_dev_err(dd, "MSI-X failed, using INTx interrupts\n");
9177 } else {
9178 /* using MSI-X */
9179 dd->num_msix_entries = request;
9180 dd->msix_entries = entries;
9181
9182 if (request != total) {
9183 /* using MSI-X, with reduced interrupts */
9184 dd_dev_err(
9185 dd,
9186 "cannot handle reduced interrupt case, want %u, got %u\n",
9187 total, request);
9188 ret = -EINVAL;
9189 goto fail;
9190 }
9191 dd_dev_info(dd, "%u MSI-X interrupts allocated\n", total);
9192 }
9193
9194 /* mask all interrupts */
9195 set_intr_state(dd, 0);
9196 /* clear all pending interrupts */
9197 clear_all_interrupts(dd);
9198
9199 /* reset general handler mask, chip MSI-X mappings */
9200 reset_interrupts(dd);
9201
9202 if (single_interrupt)
9203 ret = request_intx_irq(dd);
9204 else
9205 ret = request_msix_irqs(dd);
9206 if (ret)
9207 goto fail;
9208
9209 return 0;
9210
9211fail:
9212 clean_up_interrupts(dd);
9213 return ret;
9214}
9215
9216/*
9217 * Set up context values in dd. Sets:
9218 *
9219 * num_rcv_contexts - number of contexts being used
9220 * n_krcv_queues - number of kernel contexts
9221 * first_user_ctxt - first non-kernel context in array of contexts
9222 * freectxts - number of free user contexts
9223 * num_send_contexts - number of PIO send contexts being used
9224 */
9225static int set_up_context_variables(struct hfi1_devdata *dd)
9226{
9227 int num_kernel_contexts;
9228 int num_user_contexts;
9229 int total_contexts;
9230 int ret;
9231 unsigned ngroups;
9232
9233 /*
9234 * Kernel contexts: (to be fixed later):
9235 * - min or 2 or 1 context/numa
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -05009236 * - Context 0 - control context (VL15/multicast/error)
9237 * - Context 1 - default context
Mike Marciniszyn77241052015-07-30 15:17:43 -04009238 */
9239 if (n_krcvqs)
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -05009240 /*
9241 * Don't count context 0 in n_krcvqs since
9242 * is isn't used for normal verbs traffic.
9243 *
9244 * krcvqs will reflect number of kernel
9245 * receive contexts above 0.
9246 */
9247 num_kernel_contexts = n_krcvqs + MIN_KERNEL_KCTXTS - 1;
Mike Marciniszyn77241052015-07-30 15:17:43 -04009248 else
9249 num_kernel_contexts = num_online_nodes();
9250 num_kernel_contexts =
9251 max_t(int, MIN_KERNEL_KCTXTS, num_kernel_contexts);
9252 /*
9253 * Every kernel receive context needs an ACK send context.
9254 * one send context is allocated for each VL{0-7} and VL15
9255 */
9256 if (num_kernel_contexts > (dd->chip_send_contexts - num_vls - 1)) {
9257 dd_dev_err(dd,
9258 "Reducing # kernel rcv contexts to: %d, from %d\n",
9259 (int)(dd->chip_send_contexts - num_vls - 1),
9260 (int)num_kernel_contexts);
9261 num_kernel_contexts = dd->chip_send_contexts - num_vls - 1;
9262 }
9263 /*
9264 * User contexts: (to be fixed later)
9265 * - set to num_rcv_contexts if non-zero
9266 * - default to 1 user context per CPU
9267 */
9268 if (num_rcv_contexts)
9269 num_user_contexts = num_rcv_contexts;
9270 else
9271 num_user_contexts = num_online_cpus();
9272
9273 total_contexts = num_kernel_contexts + num_user_contexts;
9274
9275 /*
9276 * Adjust the counts given a global max.
9277 */
9278 if (total_contexts > dd->chip_rcv_contexts) {
9279 dd_dev_err(dd,
9280 "Reducing # user receive contexts to: %d, from %d\n",
9281 (int)(dd->chip_rcv_contexts - num_kernel_contexts),
9282 (int)num_user_contexts);
9283 num_user_contexts = dd->chip_rcv_contexts - num_kernel_contexts;
9284 /* recalculate */
9285 total_contexts = num_kernel_contexts + num_user_contexts;
9286 }
9287
9288 /* the first N are kernel contexts, the rest are user contexts */
9289 dd->num_rcv_contexts = total_contexts;
9290 dd->n_krcv_queues = num_kernel_contexts;
9291 dd->first_user_ctxt = num_kernel_contexts;
9292 dd->freectxts = num_user_contexts;
9293 dd_dev_info(dd,
9294 "rcv contexts: chip %d, used %d (kernel %d, user %d)\n",
9295 (int)dd->chip_rcv_contexts,
9296 (int)dd->num_rcv_contexts,
9297 (int)dd->n_krcv_queues,
9298 (int)dd->num_rcv_contexts - dd->n_krcv_queues);
9299
9300 /*
9301 * Receive array allocation:
9302 * All RcvArray entries are divided into groups of 8. This
9303 * is required by the hardware and will speed up writes to
9304 * consecutive entries by using write-combining of the entire
9305 * cacheline.
9306 *
9307 * The number of groups are evenly divided among all contexts.
9308 * any left over groups will be given to the first N user
9309 * contexts.
9310 */
9311 dd->rcv_entries.group_size = RCV_INCREMENT;
9312 ngroups = dd->chip_rcv_array_count / dd->rcv_entries.group_size;
9313 dd->rcv_entries.ngroups = ngroups / dd->num_rcv_contexts;
9314 dd->rcv_entries.nctxt_extra = ngroups -
9315 (dd->num_rcv_contexts * dd->rcv_entries.ngroups);
9316 dd_dev_info(dd, "RcvArray groups %u, ctxts extra %u\n",
9317 dd->rcv_entries.ngroups,
9318 dd->rcv_entries.nctxt_extra);
9319 if (dd->rcv_entries.ngroups * dd->rcv_entries.group_size >
9320 MAX_EAGER_ENTRIES * 2) {
9321 dd->rcv_entries.ngroups = (MAX_EAGER_ENTRIES * 2) /
9322 dd->rcv_entries.group_size;
9323 dd_dev_info(dd,
9324 "RcvArray group count too high, change to %u\n",
9325 dd->rcv_entries.ngroups);
9326 dd->rcv_entries.nctxt_extra = 0;
9327 }
9328 /*
9329 * PIO send contexts
9330 */
9331 ret = init_sc_pools_and_sizes(dd);
9332 if (ret >= 0) { /* success */
9333 dd->num_send_contexts = ret;
9334 dd_dev_info(
9335 dd,
9336 "send contexts: chip %d, used %d (kernel %d, ack %d, user %d)\n",
9337 dd->chip_send_contexts,
9338 dd->num_send_contexts,
9339 dd->sc_sizes[SC_KERNEL].count,
9340 dd->sc_sizes[SC_ACK].count,
9341 dd->sc_sizes[SC_USER].count);
9342 ret = 0; /* success */
9343 }
9344
9345 return ret;
9346}
9347
9348/*
9349 * Set the device/port partition key table. The MAD code
9350 * will ensure that, at least, the partial management
9351 * partition key is present in the table.
9352 */
9353static void set_partition_keys(struct hfi1_pportdata *ppd)
9354{
9355 struct hfi1_devdata *dd = ppd->dd;
9356 u64 reg = 0;
9357 int i;
9358
9359 dd_dev_info(dd, "Setting partition keys\n");
9360 for (i = 0; i < hfi1_get_npkeys(dd); i++) {
9361 reg |= (ppd->pkeys[i] &
9362 RCV_PARTITION_KEY_PARTITION_KEY_A_MASK) <<
9363 ((i % 4) *
9364 RCV_PARTITION_KEY_PARTITION_KEY_B_SHIFT);
9365 /* Each register holds 4 PKey values. */
9366 if ((i % 4) == 3) {
9367 write_csr(dd, RCV_PARTITION_KEY +
9368 ((i - 3) * 2), reg);
9369 reg = 0;
9370 }
9371 }
9372
9373 /* Always enable HW pkeys check when pkeys table is set */
9374 add_rcvctrl(dd, RCV_CTRL_RCV_PARTITION_KEY_ENABLE_SMASK);
9375}
9376
9377/*
9378 * These CSRs and memories are uninitialized on reset and must be
9379 * written before reading to set the ECC/parity bits.
9380 *
9381 * NOTE: All user context CSRs that are not mmaped write-only
9382 * (e.g. the TID flows) must be initialized even if the driver never
9383 * reads them.
9384 */
9385static void write_uninitialized_csrs_and_memories(struct hfi1_devdata *dd)
9386{
9387 int i, j;
9388
9389 /* CceIntMap */
9390 for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
9391 write_csr(dd, CCE_INT_MAP+(8*i), 0);
9392
9393 /* SendCtxtCreditReturnAddr */
9394 for (i = 0; i < dd->chip_send_contexts; i++)
9395 write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
9396
9397 /* PIO Send buffers */
9398 /* SDMA Send buffers */
9399 /* These are not normally read, and (presently) have no method
9400 to be read, so are not pre-initialized */
9401
9402 /* RcvHdrAddr */
9403 /* RcvHdrTailAddr */
9404 /* RcvTidFlowTable */
9405 for (i = 0; i < dd->chip_rcv_contexts; i++) {
9406 write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
9407 write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
9408 for (j = 0; j < RXE_NUM_TID_FLOWS; j++)
9409 write_uctxt_csr(dd, i, RCV_TID_FLOW_TABLE+(8*j), 0);
9410 }
9411
9412 /* RcvArray */
9413 for (i = 0; i < dd->chip_rcv_array_count; i++)
9414 write_csr(dd, RCV_ARRAY + (8*i),
9415 RCV_ARRAY_RT_WRITE_ENABLE_SMASK);
9416
9417 /* RcvQPMapTable */
9418 for (i = 0; i < 32; i++)
9419 write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
9420}
9421
9422/*
9423 * Use the ctrl_bits in CceCtrl to clear the status_bits in CceStatus.
9424 */
9425static void clear_cce_status(struct hfi1_devdata *dd, u64 status_bits,
9426 u64 ctrl_bits)
9427{
9428 unsigned long timeout;
9429 u64 reg;
9430
9431 /* is the condition present? */
9432 reg = read_csr(dd, CCE_STATUS);
9433 if ((reg & status_bits) == 0)
9434 return;
9435
9436 /* clear the condition */
9437 write_csr(dd, CCE_CTRL, ctrl_bits);
9438
9439 /* wait for the condition to clear */
9440 timeout = jiffies + msecs_to_jiffies(CCE_STATUS_TIMEOUT);
9441 while (1) {
9442 reg = read_csr(dd, CCE_STATUS);
9443 if ((reg & status_bits) == 0)
9444 return;
9445 if (time_after(jiffies, timeout)) {
9446 dd_dev_err(dd,
9447 "Timeout waiting for CceStatus to clear bits 0x%llx, remaining 0x%llx\n",
9448 status_bits, reg & status_bits);
9449 return;
9450 }
9451 udelay(1);
9452 }
9453}
9454
9455/* set CCE CSRs to chip reset defaults */
9456static void reset_cce_csrs(struct hfi1_devdata *dd)
9457{
9458 int i;
9459
9460 /* CCE_REVISION read-only */
9461 /* CCE_REVISION2 read-only */
9462 /* CCE_CTRL - bits clear automatically */
9463 /* CCE_STATUS read-only, use CceCtrl to clear */
9464 clear_cce_status(dd, ALL_FROZE, CCE_CTRL_SPC_UNFREEZE_SMASK);
9465 clear_cce_status(dd, ALL_TXE_PAUSE, CCE_CTRL_TXE_RESUME_SMASK);
9466 clear_cce_status(dd, ALL_RXE_PAUSE, CCE_CTRL_RXE_RESUME_SMASK);
9467 for (i = 0; i < CCE_NUM_SCRATCH; i++)
9468 write_csr(dd, CCE_SCRATCH + (8 * i), 0);
9469 /* CCE_ERR_STATUS read-only */
9470 write_csr(dd, CCE_ERR_MASK, 0);
9471 write_csr(dd, CCE_ERR_CLEAR, ~0ull);
9472 /* CCE_ERR_FORCE leave alone */
9473 for (i = 0; i < CCE_NUM_32_BIT_COUNTERS; i++)
9474 write_csr(dd, CCE_COUNTER_ARRAY32 + (8 * i), 0);
9475 write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_RESETCSR);
9476 /* CCE_PCIE_CTRL leave alone */
9477 for (i = 0; i < CCE_NUM_MSIX_VECTORS; i++) {
9478 write_csr(dd, CCE_MSIX_TABLE_LOWER + (8 * i), 0);
9479 write_csr(dd, CCE_MSIX_TABLE_UPPER + (8 * i),
9480 CCE_MSIX_TABLE_UPPER_RESETCSR);
9481 }
9482 for (i = 0; i < CCE_NUM_MSIX_PBAS; i++) {
9483 /* CCE_MSIX_PBA read-only */
9484 write_csr(dd, CCE_MSIX_INT_GRANTED, ~0ull);
9485 write_csr(dd, CCE_MSIX_VEC_CLR_WITHOUT_INT, ~0ull);
9486 }
9487 for (i = 0; i < CCE_NUM_INT_MAP_CSRS; i++)
9488 write_csr(dd, CCE_INT_MAP, 0);
9489 for (i = 0; i < CCE_NUM_INT_CSRS; i++) {
9490 /* CCE_INT_STATUS read-only */
9491 write_csr(dd, CCE_INT_MASK + (8 * i), 0);
9492 write_csr(dd, CCE_INT_CLEAR + (8 * i), ~0ull);
9493 /* CCE_INT_FORCE leave alone */
9494 /* CCE_INT_BLOCKED read-only */
9495 }
9496 for (i = 0; i < CCE_NUM_32_BIT_INT_COUNTERS; i++)
9497 write_csr(dd, CCE_INT_COUNTER_ARRAY32 + (8 * i), 0);
9498}
9499
9500/* set ASIC CSRs to chip reset defaults */
9501static void reset_asic_csrs(struct hfi1_devdata *dd)
9502{
Mike Marciniszyn77241052015-07-30 15:17:43 -04009503 int i;
9504
9505 /*
9506 * If the HFIs are shared between separate nodes or VMs,
9507 * then more will need to be done here. One idea is a module
9508 * parameter that returns early, letting the first power-on or
9509 * a known first load do the reset and blocking all others.
9510 */
9511
Easwar Hariharan7c03ed82015-10-26 10:28:28 -04009512 if (!(dd->flags & HFI1_DO_INIT_ASIC))
9513 return;
Mike Marciniszyn77241052015-07-30 15:17:43 -04009514
9515 if (dd->icode != ICODE_FPGA_EMULATION) {
9516 /* emulation does not have an SBus - leave these alone */
9517 /*
9518 * All writes to ASIC_CFG_SBUS_REQUEST do something.
9519 * Notes:
9520 * o The reset is not zero if aimed at the core. See the
9521 * SBus documentation for details.
9522 * o If the SBus firmware has been updated (e.g. by the BIOS),
9523 * will the reset revert that?
9524 */
9525 /* ASIC_CFG_SBUS_REQUEST leave alone */
9526 write_csr(dd, ASIC_CFG_SBUS_EXECUTE, 0);
9527 }
9528 /* ASIC_SBUS_RESULT read-only */
9529 write_csr(dd, ASIC_STS_SBUS_COUNTERS, 0);
9530 for (i = 0; i < ASIC_NUM_SCRATCH; i++)
9531 write_csr(dd, ASIC_CFG_SCRATCH + (8 * i), 0);
9532 write_csr(dd, ASIC_CFG_MUTEX, 0); /* this will clear it */
Easwar Hariharan7c03ed82015-10-26 10:28:28 -04009533
9534 /* We might want to retain this state across FLR if we ever use it */
Mike Marciniszyn77241052015-07-30 15:17:43 -04009535 write_csr(dd, ASIC_CFG_DRV_STR, 0);
Easwar Hariharan7c03ed82015-10-26 10:28:28 -04009536
Jareer Abdel-Qader4ef98982015-11-06 20:07:00 -05009537 /* ASIC_CFG_THERM_POLL_EN leave alone */
Mike Marciniszyn77241052015-07-30 15:17:43 -04009538 /* ASIC_STS_THERM read-only */
9539 /* ASIC_CFG_RESET leave alone */
9540
9541 write_csr(dd, ASIC_PCIE_SD_HOST_CMD, 0);
9542 /* ASIC_PCIE_SD_HOST_STATUS read-only */
9543 write_csr(dd, ASIC_PCIE_SD_INTRPT_DATA_CODE, 0);
9544 write_csr(dd, ASIC_PCIE_SD_INTRPT_ENABLE, 0);
9545 /* ASIC_PCIE_SD_INTRPT_PROGRESS read-only */
9546 write_csr(dd, ASIC_PCIE_SD_INTRPT_STATUS, ~0ull); /* clear */
9547 /* ASIC_HFI0_PCIE_SD_INTRPT_RSPD_DATA read-only */
9548 /* ASIC_HFI1_PCIE_SD_INTRPT_RSPD_DATA read-only */
9549 for (i = 0; i < 16; i++)
9550 write_csr(dd, ASIC_PCIE_SD_INTRPT_LIST + (8 * i), 0);
9551
9552 /* ASIC_GPIO_IN read-only */
9553 write_csr(dd, ASIC_GPIO_OE, 0);
9554 write_csr(dd, ASIC_GPIO_INVERT, 0);
9555 write_csr(dd, ASIC_GPIO_OUT, 0);
9556 write_csr(dd, ASIC_GPIO_MASK, 0);
9557 /* ASIC_GPIO_STATUS read-only */
9558 write_csr(dd, ASIC_GPIO_CLEAR, ~0ull);
9559 /* ASIC_GPIO_FORCE leave alone */
9560
9561 /* ASIC_QSFP1_IN read-only */
9562 write_csr(dd, ASIC_QSFP1_OE, 0);
9563 write_csr(dd, ASIC_QSFP1_INVERT, 0);
9564 write_csr(dd, ASIC_QSFP1_OUT, 0);
9565 write_csr(dd, ASIC_QSFP1_MASK, 0);
9566 /* ASIC_QSFP1_STATUS read-only */
9567 write_csr(dd, ASIC_QSFP1_CLEAR, ~0ull);
9568 /* ASIC_QSFP1_FORCE leave alone */
9569
9570 /* ASIC_QSFP2_IN read-only */
9571 write_csr(dd, ASIC_QSFP2_OE, 0);
9572 write_csr(dd, ASIC_QSFP2_INVERT, 0);
9573 write_csr(dd, ASIC_QSFP2_OUT, 0);
9574 write_csr(dd, ASIC_QSFP2_MASK, 0);
9575 /* ASIC_QSFP2_STATUS read-only */
9576 write_csr(dd, ASIC_QSFP2_CLEAR, ~0ull);
9577 /* ASIC_QSFP2_FORCE leave alone */
9578
9579 write_csr(dd, ASIC_EEP_CTL_STAT, ASIC_EEP_CTL_STAT_RESETCSR);
9580 /* this also writes a NOP command, clearing paging mode */
9581 write_csr(dd, ASIC_EEP_ADDR_CMD, 0);
9582 write_csr(dd, ASIC_EEP_DATA, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009583}
9584
9585/* set MISC CSRs to chip reset defaults */
9586static void reset_misc_csrs(struct hfi1_devdata *dd)
9587{
9588 int i;
9589
9590 for (i = 0; i < 32; i++) {
9591 write_csr(dd, MISC_CFG_RSA_R2 + (8 * i), 0);
9592 write_csr(dd, MISC_CFG_RSA_SIGNATURE + (8 * i), 0);
9593 write_csr(dd, MISC_CFG_RSA_MODULUS + (8 * i), 0);
9594 }
9595 /* MISC_CFG_SHA_PRELOAD leave alone - always reads 0 and can
9596 only be written 128-byte chunks */
9597 /* init RSA engine to clear lingering errors */
9598 write_csr(dd, MISC_CFG_RSA_CMD, 1);
9599 write_csr(dd, MISC_CFG_RSA_MU, 0);
9600 write_csr(dd, MISC_CFG_FW_CTRL, 0);
9601 /* MISC_STS_8051_DIGEST read-only */
9602 /* MISC_STS_SBM_DIGEST read-only */
9603 /* MISC_STS_PCIE_DIGEST read-only */
9604 /* MISC_STS_FAB_DIGEST read-only */
9605 /* MISC_ERR_STATUS read-only */
9606 write_csr(dd, MISC_ERR_MASK, 0);
9607 write_csr(dd, MISC_ERR_CLEAR, ~0ull);
9608 /* MISC_ERR_FORCE leave alone */
9609}
9610
9611/* set TXE CSRs to chip reset defaults */
9612static void reset_txe_csrs(struct hfi1_devdata *dd)
9613{
9614 int i;
9615
9616 /*
9617 * TXE Kernel CSRs
9618 */
9619 write_csr(dd, SEND_CTRL, 0);
9620 __cm_reset(dd, 0); /* reset CM internal state */
9621 /* SEND_CONTEXTS read-only */
9622 /* SEND_DMA_ENGINES read-only */
9623 /* SEND_PIO_MEM_SIZE read-only */
9624 /* SEND_DMA_MEM_SIZE read-only */
9625 write_csr(dd, SEND_HIGH_PRIORITY_LIMIT, 0);
9626 pio_reset_all(dd); /* SEND_PIO_INIT_CTXT */
9627 /* SEND_PIO_ERR_STATUS read-only */
9628 write_csr(dd, SEND_PIO_ERR_MASK, 0);
9629 write_csr(dd, SEND_PIO_ERR_CLEAR, ~0ull);
9630 /* SEND_PIO_ERR_FORCE leave alone */
9631 /* SEND_DMA_ERR_STATUS read-only */
9632 write_csr(dd, SEND_DMA_ERR_MASK, 0);
9633 write_csr(dd, SEND_DMA_ERR_CLEAR, ~0ull);
9634 /* SEND_DMA_ERR_FORCE leave alone */
9635 /* SEND_EGRESS_ERR_STATUS read-only */
9636 write_csr(dd, SEND_EGRESS_ERR_MASK, 0);
9637 write_csr(dd, SEND_EGRESS_ERR_CLEAR, ~0ull);
9638 /* SEND_EGRESS_ERR_FORCE leave alone */
9639 write_csr(dd, SEND_BTH_QP, 0);
9640 write_csr(dd, SEND_STATIC_RATE_CONTROL, 0);
9641 write_csr(dd, SEND_SC2VLT0, 0);
9642 write_csr(dd, SEND_SC2VLT1, 0);
9643 write_csr(dd, SEND_SC2VLT2, 0);
9644 write_csr(dd, SEND_SC2VLT3, 0);
9645 write_csr(dd, SEND_LEN_CHECK0, 0);
9646 write_csr(dd, SEND_LEN_CHECK1, 0);
9647 /* SEND_ERR_STATUS read-only */
9648 write_csr(dd, SEND_ERR_MASK, 0);
9649 write_csr(dd, SEND_ERR_CLEAR, ~0ull);
9650 /* SEND_ERR_FORCE read-only */
9651 for (i = 0; i < VL_ARB_LOW_PRIO_TABLE_SIZE; i++)
9652 write_csr(dd, SEND_LOW_PRIORITY_LIST + (8*i), 0);
9653 for (i = 0; i < VL_ARB_HIGH_PRIO_TABLE_SIZE; i++)
9654 write_csr(dd, SEND_HIGH_PRIORITY_LIST + (8*i), 0);
9655 for (i = 0; i < dd->chip_send_contexts/NUM_CONTEXTS_PER_SET; i++)
9656 write_csr(dd, SEND_CONTEXT_SET_CTRL + (8*i), 0);
9657 for (i = 0; i < TXE_NUM_32_BIT_COUNTER; i++)
9658 write_csr(dd, SEND_COUNTER_ARRAY32 + (8*i), 0);
9659 for (i = 0; i < TXE_NUM_64_BIT_COUNTER; i++)
9660 write_csr(dd, SEND_COUNTER_ARRAY64 + (8*i), 0);
9661 write_csr(dd, SEND_CM_CTRL, SEND_CM_CTRL_RESETCSR);
9662 write_csr(dd, SEND_CM_GLOBAL_CREDIT,
9663 SEND_CM_GLOBAL_CREDIT_RESETCSR);
9664 /* SEND_CM_CREDIT_USED_STATUS read-only */
9665 write_csr(dd, SEND_CM_TIMER_CTRL, 0);
9666 write_csr(dd, SEND_CM_LOCAL_AU_TABLE0_TO3, 0);
9667 write_csr(dd, SEND_CM_LOCAL_AU_TABLE4_TO7, 0);
9668 write_csr(dd, SEND_CM_REMOTE_AU_TABLE0_TO3, 0);
9669 write_csr(dd, SEND_CM_REMOTE_AU_TABLE4_TO7, 0);
9670 for (i = 0; i < TXE_NUM_DATA_VL; i++)
9671 write_csr(dd, SEND_CM_CREDIT_VL + (8*i), 0);
9672 write_csr(dd, SEND_CM_CREDIT_VL15, 0);
9673 /* SEND_CM_CREDIT_USED_VL read-only */
9674 /* SEND_CM_CREDIT_USED_VL15 read-only */
9675 /* SEND_EGRESS_CTXT_STATUS read-only */
9676 /* SEND_EGRESS_SEND_DMA_STATUS read-only */
9677 write_csr(dd, SEND_EGRESS_ERR_INFO, ~0ull);
9678 /* SEND_EGRESS_ERR_INFO read-only */
9679 /* SEND_EGRESS_ERR_SOURCE read-only */
9680
9681 /*
9682 * TXE Per-Context CSRs
9683 */
9684 for (i = 0; i < dd->chip_send_contexts; i++) {
9685 write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
9686 write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_CTRL, 0);
9687 write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_RETURN_ADDR, 0);
9688 write_kctxt_csr(dd, i, SEND_CTXT_CREDIT_FORCE, 0);
9689 write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, 0);
9690 write_kctxt_csr(dd, i, SEND_CTXT_ERR_CLEAR, ~0ull);
9691 write_kctxt_csr(dd, i, SEND_CTXT_CHECK_ENABLE, 0);
9692 write_kctxt_csr(dd, i, SEND_CTXT_CHECK_VL, 0);
9693 write_kctxt_csr(dd, i, SEND_CTXT_CHECK_JOB_KEY, 0);
9694 write_kctxt_csr(dd, i, SEND_CTXT_CHECK_PARTITION_KEY, 0);
9695 write_kctxt_csr(dd, i, SEND_CTXT_CHECK_SLID, 0);
9696 write_kctxt_csr(dd, i, SEND_CTXT_CHECK_OPCODE, 0);
9697 }
9698
9699 /*
9700 * TXE Per-SDMA CSRs
9701 */
9702 for (i = 0; i < dd->chip_sdma_engines; i++) {
9703 write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
9704 /* SEND_DMA_STATUS read-only */
9705 write_kctxt_csr(dd, i, SEND_DMA_BASE_ADDR, 0);
9706 write_kctxt_csr(dd, i, SEND_DMA_LEN_GEN, 0);
9707 write_kctxt_csr(dd, i, SEND_DMA_TAIL, 0);
9708 /* SEND_DMA_HEAD read-only */
9709 write_kctxt_csr(dd, i, SEND_DMA_HEAD_ADDR, 0);
9710 write_kctxt_csr(dd, i, SEND_DMA_PRIORITY_THLD, 0);
9711 /* SEND_DMA_IDLE_CNT read-only */
9712 write_kctxt_csr(dd, i, SEND_DMA_RELOAD_CNT, 0);
9713 write_kctxt_csr(dd, i, SEND_DMA_DESC_CNT, 0);
9714 /* SEND_DMA_DESC_FETCHED_CNT read-only */
9715 /* SEND_DMA_ENG_ERR_STATUS read-only */
9716 write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, 0);
9717 write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_CLEAR, ~0ull);
9718 /* SEND_DMA_ENG_ERR_FORCE leave alone */
9719 write_kctxt_csr(dd, i, SEND_DMA_CHECK_ENABLE, 0);
9720 write_kctxt_csr(dd, i, SEND_DMA_CHECK_VL, 0);
9721 write_kctxt_csr(dd, i, SEND_DMA_CHECK_JOB_KEY, 0);
9722 write_kctxt_csr(dd, i, SEND_DMA_CHECK_PARTITION_KEY, 0);
9723 write_kctxt_csr(dd, i, SEND_DMA_CHECK_SLID, 0);
9724 write_kctxt_csr(dd, i, SEND_DMA_CHECK_OPCODE, 0);
9725 write_kctxt_csr(dd, i, SEND_DMA_MEMORY, 0);
9726 }
9727}
9728
9729/*
9730 * Expect on entry:
9731 * o Packet ingress is disabled, i.e. RcvCtrl.RcvPortEnable == 0
9732 */
9733static void init_rbufs(struct hfi1_devdata *dd)
9734{
9735 u64 reg;
9736 int count;
9737
9738 /*
9739 * Wait for DMA to stop: RxRbufPktPending and RxPktInProgress are
9740 * clear.
9741 */
9742 count = 0;
9743 while (1) {
9744 reg = read_csr(dd, RCV_STATUS);
9745 if ((reg & (RCV_STATUS_RX_RBUF_PKT_PENDING_SMASK
9746 | RCV_STATUS_RX_PKT_IN_PROGRESS_SMASK)) == 0)
9747 break;
9748 /*
9749 * Give up after 1ms - maximum wait time.
9750 *
9751 * RBuf size is 148KiB. Slowest possible is PCIe Gen1 x1 at
9752 * 250MB/s bandwidth. Lower rate to 66% for overhead to get:
9753 * 148 KB / (66% * 250MB/s) = 920us
9754 */
9755 if (count++ > 500) {
9756 dd_dev_err(dd,
9757 "%s: in-progress DMA not clearing: RcvStatus 0x%llx, continuing\n",
9758 __func__, reg);
9759 break;
9760 }
9761 udelay(2); /* do not busy-wait the CSR */
9762 }
9763
9764 /* start the init - expect RcvCtrl to be 0 */
9765 write_csr(dd, RCV_CTRL, RCV_CTRL_RX_RBUF_INIT_SMASK);
9766
9767 /*
9768 * Read to force the write of Rcvtrl.RxRbufInit. There is a brief
9769 * period after the write before RcvStatus.RxRbufInitDone is valid.
9770 * The delay in the first run through the loop below is sufficient and
9771 * required before the first read of RcvStatus.RxRbufInintDone.
9772 */
9773 read_csr(dd, RCV_CTRL);
9774
9775 /* wait for the init to finish */
9776 count = 0;
9777 while (1) {
9778 /* delay is required first time through - see above */
9779 udelay(2); /* do not busy-wait the CSR */
9780 reg = read_csr(dd, RCV_STATUS);
9781 if (reg & (RCV_STATUS_RX_RBUF_INIT_DONE_SMASK))
9782 break;
9783
9784 /* give up after 100us - slowest possible at 33MHz is 73us */
9785 if (count++ > 50) {
9786 dd_dev_err(dd,
9787 "%s: RcvStatus.RxRbufInit not set, continuing\n",
9788 __func__);
9789 break;
9790 }
9791 }
9792}
9793
9794/* set RXE CSRs to chip reset defaults */
9795static void reset_rxe_csrs(struct hfi1_devdata *dd)
9796{
9797 int i, j;
9798
9799 /*
9800 * RXE Kernel CSRs
9801 */
9802 write_csr(dd, RCV_CTRL, 0);
9803 init_rbufs(dd);
9804 /* RCV_STATUS read-only */
9805 /* RCV_CONTEXTS read-only */
9806 /* RCV_ARRAY_CNT read-only */
9807 /* RCV_BUF_SIZE read-only */
9808 write_csr(dd, RCV_BTH_QP, 0);
9809 write_csr(dd, RCV_MULTICAST, 0);
9810 write_csr(dd, RCV_BYPASS, 0);
9811 write_csr(dd, RCV_VL15, 0);
9812 /* this is a clear-down */
9813 write_csr(dd, RCV_ERR_INFO,
9814 RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK);
9815 /* RCV_ERR_STATUS read-only */
9816 write_csr(dd, RCV_ERR_MASK, 0);
9817 write_csr(dd, RCV_ERR_CLEAR, ~0ull);
9818 /* RCV_ERR_FORCE leave alone */
9819 for (i = 0; i < 32; i++)
9820 write_csr(dd, RCV_QP_MAP_TABLE + (8 * i), 0);
9821 for (i = 0; i < 4; i++)
9822 write_csr(dd, RCV_PARTITION_KEY + (8 * i), 0);
9823 for (i = 0; i < RXE_NUM_32_BIT_COUNTERS; i++)
9824 write_csr(dd, RCV_COUNTER_ARRAY32 + (8 * i), 0);
9825 for (i = 0; i < RXE_NUM_64_BIT_COUNTERS; i++)
9826 write_csr(dd, RCV_COUNTER_ARRAY64 + (8 * i), 0);
9827 for (i = 0; i < RXE_NUM_RSM_INSTANCES; i++) {
9828 write_csr(dd, RCV_RSM_CFG + (8 * i), 0);
9829 write_csr(dd, RCV_RSM_SELECT + (8 * i), 0);
9830 write_csr(dd, RCV_RSM_MATCH + (8 * i), 0);
9831 }
9832 for (i = 0; i < 32; i++)
9833 write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), 0);
9834
9835 /*
9836 * RXE Kernel and User Per-Context CSRs
9837 */
9838 for (i = 0; i < dd->chip_rcv_contexts; i++) {
9839 /* kernel */
9840 write_kctxt_csr(dd, i, RCV_CTXT_CTRL, 0);
9841 /* RCV_CTXT_STATUS read-only */
9842 write_kctxt_csr(dd, i, RCV_EGR_CTRL, 0);
9843 write_kctxt_csr(dd, i, RCV_TID_CTRL, 0);
9844 write_kctxt_csr(dd, i, RCV_KEY_CTRL, 0);
9845 write_kctxt_csr(dd, i, RCV_HDR_ADDR, 0);
9846 write_kctxt_csr(dd, i, RCV_HDR_CNT, 0);
9847 write_kctxt_csr(dd, i, RCV_HDR_ENT_SIZE, 0);
9848 write_kctxt_csr(dd, i, RCV_HDR_SIZE, 0);
9849 write_kctxt_csr(dd, i, RCV_HDR_TAIL_ADDR, 0);
9850 write_kctxt_csr(dd, i, RCV_AVAIL_TIME_OUT, 0);
9851 write_kctxt_csr(dd, i, RCV_HDR_OVFL_CNT, 0);
9852
9853 /* user */
9854 /* RCV_HDR_TAIL read-only */
9855 write_uctxt_csr(dd, i, RCV_HDR_HEAD, 0);
9856 /* RCV_EGR_INDEX_TAIL read-only */
9857 write_uctxt_csr(dd, i, RCV_EGR_INDEX_HEAD, 0);
9858 /* RCV_EGR_OFFSET_TAIL read-only */
9859 for (j = 0; j < RXE_NUM_TID_FLOWS; j++) {
9860 write_uctxt_csr(dd, i, RCV_TID_FLOW_TABLE + (8 * j),
9861 0);
9862 }
9863 }
9864}
9865
9866/*
9867 * Set sc2vl tables.
9868 *
9869 * They power on to zeros, so to avoid send context errors
9870 * they need to be set:
9871 *
9872 * SC 0-7 -> VL 0-7 (respectively)
9873 * SC 15 -> VL 15
9874 * otherwise
9875 * -> VL 0
9876 */
9877static void init_sc2vl_tables(struct hfi1_devdata *dd)
9878{
9879 int i;
9880 /* init per architecture spec, constrained by hardware capability */
9881
9882 /* HFI maps sent packets */
9883 write_csr(dd, SEND_SC2VLT0, SC2VL_VAL(
9884 0,
9885 0, 0, 1, 1,
9886 2, 2, 3, 3,
9887 4, 4, 5, 5,
9888 6, 6, 7, 7));
9889 write_csr(dd, SEND_SC2VLT1, SC2VL_VAL(
9890 1,
9891 8, 0, 9, 0,
9892 10, 0, 11, 0,
9893 12, 0, 13, 0,
9894 14, 0, 15, 15));
9895 write_csr(dd, SEND_SC2VLT2, SC2VL_VAL(
9896 2,
9897 16, 0, 17, 0,
9898 18, 0, 19, 0,
9899 20, 0, 21, 0,
9900 22, 0, 23, 0));
9901 write_csr(dd, SEND_SC2VLT3, SC2VL_VAL(
9902 3,
9903 24, 0, 25, 0,
9904 26, 0, 27, 0,
9905 28, 0, 29, 0,
9906 30, 0, 31, 0));
9907
9908 /* DC maps received packets */
9909 write_csr(dd, DCC_CFG_SC_VL_TABLE_15_0, DC_SC_VL_VAL(
9910 15_0,
9911 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7,
9912 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 15));
9913 write_csr(dd, DCC_CFG_SC_VL_TABLE_31_16, DC_SC_VL_VAL(
9914 31_16,
9915 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0,
9916 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0));
9917
9918 /* initialize the cached sc2vl values consistently with h/w */
9919 for (i = 0; i < 32; i++) {
9920 if (i < 8 || i == 15)
9921 *((u8 *)(dd->sc2vl) + i) = (u8)i;
9922 else
9923 *((u8 *)(dd->sc2vl) + i) = 0;
9924 }
9925}
9926
9927/*
9928 * Read chip sizes and then reset parts to sane, disabled, values. We cannot
9929 * depend on the chip going through a power-on reset - a driver may be loaded
9930 * and unloaded many times.
9931 *
9932 * Do not write any CSR values to the chip in this routine - there may be
9933 * a reset following the (possible) FLR in this routine.
9934 *
9935 */
9936static void init_chip(struct hfi1_devdata *dd)
9937{
9938 int i;
9939
9940 /*
9941 * Put the HFI CSRs in a known state.
9942 * Combine this with a DC reset.
9943 *
9944 * Stop the device from doing anything while we do a
9945 * reset. We know there are no other active users of
9946 * the device since we are now in charge. Turn off
9947 * off all outbound and inbound traffic and make sure
9948 * the device does not generate any interrupts.
9949 */
9950
9951 /* disable send contexts and SDMA engines */
9952 write_csr(dd, SEND_CTRL, 0);
9953 for (i = 0; i < dd->chip_send_contexts; i++)
9954 write_kctxt_csr(dd, i, SEND_CTXT_CTRL, 0);
9955 for (i = 0; i < dd->chip_sdma_engines; i++)
9956 write_kctxt_csr(dd, i, SEND_DMA_CTRL, 0);
9957 /* disable port (turn off RXE inbound traffic) and contexts */
9958 write_csr(dd, RCV_CTRL, 0);
9959 for (i = 0; i < dd->chip_rcv_contexts; i++)
9960 write_csr(dd, RCV_CTXT_CTRL, 0);
9961 /* mask all interrupt sources */
9962 for (i = 0; i < CCE_NUM_INT_CSRS; i++)
9963 write_csr(dd, CCE_INT_MASK + (8*i), 0ull);
9964
9965 /*
9966 * DC Reset: do a full DC reset before the register clear.
9967 * A recommended length of time to hold is one CSR read,
9968 * so reread the CceDcCtrl. Then, hold the DC in reset
9969 * across the clear.
9970 */
9971 write_csr(dd, CCE_DC_CTRL, CCE_DC_CTRL_DC_RESET_SMASK);
9972 (void) read_csr(dd, CCE_DC_CTRL);
9973
9974 if (use_flr) {
9975 /*
9976 * A FLR will reset the SPC core and part of the PCIe.
9977 * The parts that need to be restored have already been
9978 * saved.
9979 */
9980 dd_dev_info(dd, "Resetting CSRs with FLR\n");
9981
9982 /* do the FLR, the DC reset will remain */
9983 hfi1_pcie_flr(dd);
9984
9985 /* restore command and BARs */
9986 restore_pci_variables(dd);
9987
Mike Marciniszyn995deaf2015-11-16 21:59:29 -05009988 if (is_ax(dd)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04009989 dd_dev_info(dd, "Resetting CSRs with FLR\n");
9990 hfi1_pcie_flr(dd);
9991 restore_pci_variables(dd);
9992 }
9993
Easwar Hariharan7c03ed82015-10-26 10:28:28 -04009994 reset_asic_csrs(dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04009995 } else {
9996 dd_dev_info(dd, "Resetting CSRs with writes\n");
9997 reset_cce_csrs(dd);
9998 reset_txe_csrs(dd);
9999 reset_rxe_csrs(dd);
10000 reset_asic_csrs(dd);
10001 reset_misc_csrs(dd);
10002 }
10003 /* clear the DC reset */
10004 write_csr(dd, CCE_DC_CTRL, 0);
Easwar Hariharan7c03ed82015-10-26 10:28:28 -040010005
Mike Marciniszyn77241052015-07-30 15:17:43 -040010006 /* Set the LED off */
Mike Marciniszyn995deaf2015-11-16 21:59:29 -050010007 if (is_ax(dd))
Mike Marciniszyn77241052015-07-30 15:17:43 -040010008 setextled(dd, 0);
10009 /*
10010 * Clear the QSFP reset.
Easwar Hariharan72a67ba2015-11-06 20:06:57 -050010011 * An FLR enforces a 0 on all out pins. The driver does not touch
Mike Marciniszyn77241052015-07-30 15:17:43 -040010012 * ASIC_QSFPn_OUT otherwise. This leaves RESET_N low and
Easwar Hariharan72a67ba2015-11-06 20:06:57 -050010013 * anything plugged constantly in reset, if it pays attention
Mike Marciniszyn77241052015-07-30 15:17:43 -040010014 * to RESET_N.
Easwar Hariharan72a67ba2015-11-06 20:06:57 -050010015 * Prime examples of this are optical cables. Set all pins high.
Mike Marciniszyn77241052015-07-30 15:17:43 -040010016 * I2CCLK and I2CDAT will change per direction, and INT_N and
10017 * MODPRS_N are input only and their value is ignored.
10018 */
Easwar Hariharan72a67ba2015-11-06 20:06:57 -050010019 write_csr(dd, ASIC_QSFP1_OUT, 0x1f);
10020 write_csr(dd, ASIC_QSFP2_OUT, 0x1f);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010021}
10022
10023static void init_early_variables(struct hfi1_devdata *dd)
10024{
10025 int i;
10026
10027 /* assign link credit variables */
10028 dd->vau = CM_VAU;
10029 dd->link_credits = CM_GLOBAL_CREDITS;
Mike Marciniszyn995deaf2015-11-16 21:59:29 -050010030 if (is_ax(dd))
Mike Marciniszyn77241052015-07-30 15:17:43 -040010031 dd->link_credits--;
10032 dd->vcu = cu_to_vcu(hfi1_cu);
10033 /* enough room for 8 MAD packets plus header - 17K */
10034 dd->vl15_init = (8 * (2048 + 128)) / vau_to_au(dd->vau);
10035 if (dd->vl15_init > dd->link_credits)
10036 dd->vl15_init = dd->link_credits;
10037
10038 write_uninitialized_csrs_and_memories(dd);
10039
10040 if (HFI1_CAP_IS_KSET(PKEY_CHECK))
10041 for (i = 0; i < dd->num_pports; i++) {
10042 struct hfi1_pportdata *ppd = &dd->pport[i];
10043
10044 set_partition_keys(ppd);
10045 }
10046 init_sc2vl_tables(dd);
10047}
10048
10049static void init_kdeth_qp(struct hfi1_devdata *dd)
10050{
10051 /* user changed the KDETH_QP */
10052 if (kdeth_qp != 0 && kdeth_qp >= 0xff) {
10053 /* out of range or illegal value */
10054 dd_dev_err(dd, "Invalid KDETH queue pair prefix, ignoring");
10055 kdeth_qp = 0;
10056 }
10057 if (kdeth_qp == 0) /* not set, or failed range check */
10058 kdeth_qp = DEFAULT_KDETH_QP;
10059
10060 write_csr(dd, SEND_BTH_QP,
10061 (kdeth_qp & SEND_BTH_QP_KDETH_QP_MASK)
10062 << SEND_BTH_QP_KDETH_QP_SHIFT);
10063
10064 write_csr(dd, RCV_BTH_QP,
10065 (kdeth_qp & RCV_BTH_QP_KDETH_QP_MASK)
10066 << RCV_BTH_QP_KDETH_QP_SHIFT);
10067}
10068
10069/**
10070 * init_qpmap_table
10071 * @dd - device data
10072 * @first_ctxt - first context
10073 * @last_ctxt - first context
10074 *
10075 * This return sets the qpn mapping table that
10076 * is indexed by qpn[8:1].
10077 *
10078 * The routine will round robin the 256 settings
10079 * from first_ctxt to last_ctxt.
10080 *
10081 * The first/last looks ahead to having specialized
10082 * receive contexts for mgmt and bypass. Normal
10083 * verbs traffic will assumed to be on a range
10084 * of receive contexts.
10085 */
10086static void init_qpmap_table(struct hfi1_devdata *dd,
10087 u32 first_ctxt,
10088 u32 last_ctxt)
10089{
10090 u64 reg = 0;
10091 u64 regno = RCV_QP_MAP_TABLE;
10092 int i;
10093 u64 ctxt = first_ctxt;
10094
10095 for (i = 0; i < 256;) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040010096 reg |= ctxt << (8 * (i % 8));
10097 i++;
10098 ctxt++;
10099 if (ctxt > last_ctxt)
10100 ctxt = first_ctxt;
10101 if (i % 8 == 0) {
10102 write_csr(dd, regno, reg);
10103 reg = 0;
10104 regno += 8;
10105 }
10106 }
10107 if (i % 8)
10108 write_csr(dd, regno, reg);
10109
10110 add_rcvctrl(dd, RCV_CTRL_RCV_QP_MAP_ENABLE_SMASK
10111 | RCV_CTRL_RCV_BYPASS_ENABLE_SMASK);
10112}
10113
10114/**
10115 * init_qos - init RX qos
10116 * @dd - device data
10117 * @first_context
10118 *
10119 * This routine initializes Rule 0 and the
10120 * RSM map table to implement qos.
10121 *
10122 * If all of the limit tests succeed,
10123 * qos is applied based on the array
10124 * interpretation of krcvqs where
10125 * entry 0 is VL0.
10126 *
10127 * The number of vl bits (n) and the number of qpn
10128 * bits (m) are computed to feed both the RSM map table
10129 * and the single rule.
10130 *
10131 */
10132static void init_qos(struct hfi1_devdata *dd, u32 first_ctxt)
10133{
10134 u8 max_by_vl = 0;
10135 unsigned qpns_per_vl, ctxt, i, qpn, n = 1, m;
10136 u64 *rsmmap;
10137 u64 reg;
Mike Marciniszyn995deaf2015-11-16 21:59:29 -050010138 u8 rxcontext = is_ax(dd) ? 0 : 0xff; /* 0 is default if a0 ver. */
Mike Marciniszyn77241052015-07-30 15:17:43 -040010139
10140 /* validate */
10141 if (dd->n_krcv_queues <= MIN_KERNEL_KCTXTS ||
10142 num_vls == 1 ||
10143 krcvqsset <= 1)
10144 goto bail;
10145 for (i = 0; i < min_t(unsigned, num_vls, krcvqsset); i++)
10146 if (krcvqs[i] > max_by_vl)
10147 max_by_vl = krcvqs[i];
10148 if (max_by_vl > 32)
10149 goto bail;
10150 qpns_per_vl = __roundup_pow_of_two(max_by_vl);
10151 /* determine bits vl */
10152 n = ilog2(num_vls);
10153 /* determine bits for qpn */
10154 m = ilog2(qpns_per_vl);
10155 if ((m + n) > 7)
10156 goto bail;
10157 if (num_vls * qpns_per_vl > dd->chip_rcv_contexts)
10158 goto bail;
10159 rsmmap = kmalloc_array(NUM_MAP_REGS, sizeof(u64), GFP_KERNEL);
10160 memset(rsmmap, rxcontext, NUM_MAP_REGS * sizeof(u64));
10161 /* init the local copy of the table */
10162 for (i = 0, ctxt = first_ctxt; i < num_vls; i++) {
10163 unsigned tctxt;
10164
10165 for (qpn = 0, tctxt = ctxt;
10166 krcvqs[i] && qpn < qpns_per_vl; qpn++) {
10167 unsigned idx, regoff, regidx;
10168
10169 /* generate index <= 128 */
10170 idx = (qpn << n) ^ i;
10171 regoff = (idx % 8) * 8;
10172 regidx = idx / 8;
10173 reg = rsmmap[regidx];
10174 /* replace 0xff with context number */
10175 reg &= ~(RCV_RSM_MAP_TABLE_RCV_CONTEXT_A_MASK
10176 << regoff);
10177 reg |= (u64)(tctxt++) << regoff;
10178 rsmmap[regidx] = reg;
10179 if (tctxt == ctxt + krcvqs[i])
10180 tctxt = ctxt;
10181 }
10182 ctxt += krcvqs[i];
10183 }
10184 /* flush cached copies to chip */
10185 for (i = 0; i < NUM_MAP_REGS; i++)
10186 write_csr(dd, RCV_RSM_MAP_TABLE + (8 * i), rsmmap[i]);
10187 /* add rule0 */
10188 write_csr(dd, RCV_RSM_CFG /* + (8 * 0) */,
10189 RCV_RSM_CFG_ENABLE_OR_CHAIN_RSM0_MASK
10190 << RCV_RSM_CFG_ENABLE_OR_CHAIN_RSM0_SHIFT |
10191 2ull << RCV_RSM_CFG_PACKET_TYPE_SHIFT);
10192 write_csr(dd, RCV_RSM_SELECT /* + (8 * 0) */,
10193 LRH_BTH_MATCH_OFFSET
10194 << RCV_RSM_SELECT_FIELD1_OFFSET_SHIFT |
10195 LRH_SC_MATCH_OFFSET << RCV_RSM_SELECT_FIELD2_OFFSET_SHIFT |
10196 LRH_SC_SELECT_OFFSET << RCV_RSM_SELECT_INDEX1_OFFSET_SHIFT |
10197 ((u64)n) << RCV_RSM_SELECT_INDEX1_WIDTH_SHIFT |
10198 QPN_SELECT_OFFSET << RCV_RSM_SELECT_INDEX2_OFFSET_SHIFT |
10199 ((u64)m + (u64)n) << RCV_RSM_SELECT_INDEX2_WIDTH_SHIFT);
10200 write_csr(dd, RCV_RSM_MATCH /* + (8 * 0) */,
10201 LRH_BTH_MASK << RCV_RSM_MATCH_MASK1_SHIFT |
10202 LRH_BTH_VALUE << RCV_RSM_MATCH_VALUE1_SHIFT |
10203 LRH_SC_MASK << RCV_RSM_MATCH_MASK2_SHIFT |
10204 LRH_SC_VALUE << RCV_RSM_MATCH_VALUE2_SHIFT);
10205 /* Enable RSM */
10206 add_rcvctrl(dd, RCV_CTRL_RCV_RSM_ENABLE_SMASK);
10207 kfree(rsmmap);
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -050010208 /* map everything else to first context */
10209 init_qpmap_table(dd, FIRST_KERNEL_KCTXT, MIN_KERNEL_KCTXTS - 1);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010210 dd->qos_shift = n + 1;
10211 return;
10212bail:
10213 dd->qos_shift = 1;
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -050010214 init_qpmap_table(dd, FIRST_KERNEL_KCTXT, dd->n_krcv_queues - 1);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010215}
10216
10217static void init_rxe(struct hfi1_devdata *dd)
10218{
10219 /* enable all receive errors */
10220 write_csr(dd, RCV_ERR_MASK, ~0ull);
10221 /* setup QPN map table - start where VL15 context leaves off */
10222 init_qos(
10223 dd,
10224 dd->n_krcv_queues > MIN_KERNEL_KCTXTS ? MIN_KERNEL_KCTXTS : 0);
10225 /*
10226 * make sure RcvCtrl.RcvWcb <= PCIe Device Control
10227 * Register Max_Payload_Size (PCI_EXP_DEVCTL in Linux PCIe config
10228 * space, PciCfgCap2.MaxPayloadSize in HFI). There is only one
10229 * invalid configuration: RcvCtrl.RcvWcb set to its max of 256 and
10230 * Max_PayLoad_Size set to its minimum of 128.
10231 *
10232 * Presently, RcvCtrl.RcvWcb is not modified from its default of 0
10233 * (64 bytes). Max_Payload_Size is possibly modified upward in
10234 * tune_pcie_caps() which is called after this routine.
10235 */
10236}
10237
10238static void init_other(struct hfi1_devdata *dd)
10239{
10240 /* enable all CCE errors */
10241 write_csr(dd, CCE_ERR_MASK, ~0ull);
10242 /* enable *some* Misc errors */
10243 write_csr(dd, MISC_ERR_MASK, DRIVER_MISC_MASK);
10244 /* enable all DC errors, except LCB */
10245 write_csr(dd, DCC_ERR_FLG_EN, ~0ull);
10246 write_csr(dd, DC_DC8051_ERR_EN, ~0ull);
10247}
10248
10249/*
10250 * Fill out the given AU table using the given CU. A CU is defined in terms
10251 * AUs. The table is a an encoding: given the index, how many AUs does that
10252 * represent?
10253 *
10254 * NOTE: Assumes that the register layout is the same for the
10255 * local and remote tables.
10256 */
10257static void assign_cm_au_table(struct hfi1_devdata *dd, u32 cu,
10258 u32 csr0to3, u32 csr4to7)
10259{
10260 write_csr(dd, csr0to3,
10261 0ull <<
10262 SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE0_SHIFT
10263 | 1ull <<
10264 SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE1_SHIFT
10265 | 2ull * cu <<
10266 SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE2_SHIFT
10267 | 4ull * cu <<
10268 SEND_CM_LOCAL_AU_TABLE0_TO3_LOCAL_AU_TABLE3_SHIFT);
10269 write_csr(dd, csr4to7,
10270 8ull * cu <<
10271 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE4_SHIFT
10272 | 16ull * cu <<
10273 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE5_SHIFT
10274 | 32ull * cu <<
10275 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE6_SHIFT
10276 | 64ull * cu <<
10277 SEND_CM_LOCAL_AU_TABLE4_TO7_LOCAL_AU_TABLE7_SHIFT);
10278
10279}
10280
10281static void assign_local_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
10282{
10283 assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_LOCAL_AU_TABLE0_TO3,
10284 SEND_CM_LOCAL_AU_TABLE4_TO7);
10285}
10286
10287void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu)
10288{
10289 assign_cm_au_table(dd, vcu_to_cu(vcu), SEND_CM_REMOTE_AU_TABLE0_TO3,
10290 SEND_CM_REMOTE_AU_TABLE4_TO7);
10291}
10292
10293static void init_txe(struct hfi1_devdata *dd)
10294{
10295 int i;
10296
10297 /* enable all PIO, SDMA, general, and Egress errors */
10298 write_csr(dd, SEND_PIO_ERR_MASK, ~0ull);
10299 write_csr(dd, SEND_DMA_ERR_MASK, ~0ull);
10300 write_csr(dd, SEND_ERR_MASK, ~0ull);
10301 write_csr(dd, SEND_EGRESS_ERR_MASK, ~0ull);
10302
10303 /* enable all per-context and per-SDMA engine errors */
10304 for (i = 0; i < dd->chip_send_contexts; i++)
10305 write_kctxt_csr(dd, i, SEND_CTXT_ERR_MASK, ~0ull);
10306 for (i = 0; i < dd->chip_sdma_engines; i++)
10307 write_kctxt_csr(dd, i, SEND_DMA_ENG_ERR_MASK, ~0ull);
10308
10309 /* set the local CU to AU mapping */
10310 assign_local_cm_au_table(dd, dd->vcu);
10311
10312 /*
10313 * Set reasonable default for Credit Return Timer
10314 * Don't set on Simulator - causes it to choke.
10315 */
10316 if (dd->icode != ICODE_FUNCTIONAL_SIMULATOR)
10317 write_csr(dd, SEND_CM_TIMER_CTRL, HFI1_CREDIT_RETURN_RATE);
10318}
10319
10320int hfi1_set_ctxt_jkey(struct hfi1_devdata *dd, unsigned ctxt, u16 jkey)
10321{
10322 struct hfi1_ctxtdata *rcd = dd->rcd[ctxt];
10323 unsigned sctxt;
10324 int ret = 0;
10325 u64 reg;
10326
10327 if (!rcd || !rcd->sc) {
10328 ret = -EINVAL;
10329 goto done;
10330 }
10331 sctxt = rcd->sc->hw_context;
10332 reg = SEND_CTXT_CHECK_JOB_KEY_MASK_SMASK | /* mask is always 1's */
10333 ((jkey & SEND_CTXT_CHECK_JOB_KEY_VALUE_MASK) <<
10334 SEND_CTXT_CHECK_JOB_KEY_VALUE_SHIFT);
10335 /* JOB_KEY_ALLOW_PERMISSIVE is not allowed by default */
10336 if (HFI1_CAP_KGET_MASK(rcd->flags, ALLOW_PERM_JKEY))
10337 reg |= SEND_CTXT_CHECK_JOB_KEY_ALLOW_PERMISSIVE_SMASK;
10338 write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_JOB_KEY, reg);
10339 /*
10340 * Enable send-side J_KEY integrity check, unless this is A0 h/w
10341 * (due to A0 erratum).
10342 */
Mike Marciniszyn995deaf2015-11-16 21:59:29 -050010343 if (!is_ax(dd)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040010344 reg = read_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE);
10345 reg |= SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
10346 write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE, reg);
10347 }
10348
10349 /* Enable J_KEY check on receive context. */
10350 reg = RCV_KEY_CTRL_JOB_KEY_ENABLE_SMASK |
10351 ((jkey & RCV_KEY_CTRL_JOB_KEY_VALUE_MASK) <<
10352 RCV_KEY_CTRL_JOB_KEY_VALUE_SHIFT);
10353 write_kctxt_csr(dd, ctxt, RCV_KEY_CTRL, reg);
10354done:
10355 return ret;
10356}
10357
10358int hfi1_clear_ctxt_jkey(struct hfi1_devdata *dd, unsigned ctxt)
10359{
10360 struct hfi1_ctxtdata *rcd = dd->rcd[ctxt];
10361 unsigned sctxt;
10362 int ret = 0;
10363 u64 reg;
10364
10365 if (!rcd || !rcd->sc) {
10366 ret = -EINVAL;
10367 goto done;
10368 }
10369 sctxt = rcd->sc->hw_context;
10370 write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_JOB_KEY, 0);
10371 /*
10372 * Disable send-side J_KEY integrity check, unless this is A0 h/w.
10373 * This check would not have been enabled for A0 h/w, see
10374 * set_ctxt_jkey().
10375 */
Mike Marciniszyn995deaf2015-11-16 21:59:29 -050010376 if (!is_ax(dd)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040010377 reg = read_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE);
10378 reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
10379 write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE, reg);
10380 }
10381 /* Turn off the J_KEY on the receive side */
10382 write_kctxt_csr(dd, ctxt, RCV_KEY_CTRL, 0);
10383done:
10384 return ret;
10385}
10386
10387int hfi1_set_ctxt_pkey(struct hfi1_devdata *dd, unsigned ctxt, u16 pkey)
10388{
10389 struct hfi1_ctxtdata *rcd;
10390 unsigned sctxt;
10391 int ret = 0;
10392 u64 reg;
10393
10394 if (ctxt < dd->num_rcv_contexts)
10395 rcd = dd->rcd[ctxt];
10396 else {
10397 ret = -EINVAL;
10398 goto done;
10399 }
10400 if (!rcd || !rcd->sc) {
10401 ret = -EINVAL;
10402 goto done;
10403 }
10404 sctxt = rcd->sc->hw_context;
10405 reg = ((u64)pkey & SEND_CTXT_CHECK_PARTITION_KEY_VALUE_MASK) <<
10406 SEND_CTXT_CHECK_PARTITION_KEY_VALUE_SHIFT;
10407 write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_PARTITION_KEY, reg);
10408 reg = read_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE);
10409 reg |= SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
10410 write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE, reg);
10411done:
10412 return ret;
10413}
10414
10415int hfi1_clear_ctxt_pkey(struct hfi1_devdata *dd, unsigned ctxt)
10416{
10417 struct hfi1_ctxtdata *rcd;
10418 unsigned sctxt;
10419 int ret = 0;
10420 u64 reg;
10421
10422 if (ctxt < dd->num_rcv_contexts)
10423 rcd = dd->rcd[ctxt];
10424 else {
10425 ret = -EINVAL;
10426 goto done;
10427 }
10428 if (!rcd || !rcd->sc) {
10429 ret = -EINVAL;
10430 goto done;
10431 }
10432 sctxt = rcd->sc->hw_context;
10433 reg = read_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE);
10434 reg &= ~SEND_CTXT_CHECK_ENABLE_CHECK_PARTITION_KEY_SMASK;
10435 write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_ENABLE, reg);
10436 write_kctxt_csr(dd, sctxt, SEND_CTXT_CHECK_PARTITION_KEY, 0);
10437done:
10438 return ret;
10439}
10440
10441/*
10442 * Start doing the clean up the the chip. Our clean up happens in multiple
10443 * stages and this is just the first.
10444 */
10445void hfi1_start_cleanup(struct hfi1_devdata *dd)
10446{
10447 free_cntrs(dd);
10448 free_rcverr(dd);
10449 clean_up_interrupts(dd);
10450}
10451
10452#define HFI_BASE_GUID(dev) \
10453 ((dev)->base_guid & ~(1ULL << GUID_HFI_INDEX_SHIFT))
10454
10455/*
10456 * Certain chip functions need to be initialized only once per asic
10457 * instead of per-device. This function finds the peer device and
10458 * checks whether that chip initialization needs to be done by this
10459 * device.
10460 */
10461static void asic_should_init(struct hfi1_devdata *dd)
10462{
10463 unsigned long flags;
10464 struct hfi1_devdata *tmp, *peer = NULL;
10465
10466 spin_lock_irqsave(&hfi1_devs_lock, flags);
10467 /* Find our peer device */
10468 list_for_each_entry(tmp, &hfi1_dev_list, list) {
10469 if ((HFI_BASE_GUID(dd) == HFI_BASE_GUID(tmp)) &&
10470 dd->unit != tmp->unit) {
10471 peer = tmp;
10472 break;
10473 }
10474 }
10475
10476 /*
10477 * "Claim" the ASIC for initialization if it hasn't been
10478 " "claimed" yet.
10479 */
10480 if (!peer || !(peer->flags & HFI1_DO_INIT_ASIC))
10481 dd->flags |= HFI1_DO_INIT_ASIC;
10482 spin_unlock_irqrestore(&hfi1_devs_lock, flags);
10483}
10484
Dean Luick5d9157a2015-11-16 21:59:34 -050010485/*
10486 * Set dd->boardname. Use a generic name if a name is not returned from
10487 * EFI variable space.
10488 *
10489 * Return 0 on success, -ENOMEM if space could not be allocated.
10490 */
10491static int obtain_boardname(struct hfi1_devdata *dd)
10492{
10493 /* generic board description */
10494 const char generic[] =
10495 "Intel Omni-Path Host Fabric Interface Adapter 100 Series";
10496 unsigned long size;
10497 int ret;
10498
10499 ret = read_hfi1_efi_var(dd, "description", &size,
10500 (void **)&dd->boardname);
10501 if (ret) {
10502 dd_dev_err(dd, "Board description not found\n");
10503 /* use generic description */
10504 dd->boardname = kstrdup(generic, GFP_KERNEL);
10505 if (!dd->boardname)
10506 return -ENOMEM;
10507 }
10508 return 0;
10509}
10510
Mike Marciniszyn77241052015-07-30 15:17:43 -040010511/**
Easwar Hariharan7c03ed82015-10-26 10:28:28 -040010512 * Allocate and initialize the device structure for the hfi.
Mike Marciniszyn77241052015-07-30 15:17:43 -040010513 * @dev: the pci_dev for hfi1_ib device
10514 * @ent: pci_device_id struct for this dev
10515 *
10516 * Also allocates, initializes, and returns the devdata struct for this
10517 * device instance
10518 *
10519 * This is global, and is called directly at init to set up the
10520 * chip-specific function pointers for later use.
10521 */
10522struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
10523 const struct pci_device_id *ent)
10524{
10525 struct hfi1_devdata *dd;
10526 struct hfi1_pportdata *ppd;
10527 u64 reg;
10528 int i, ret;
10529 static const char * const inames[] = { /* implementation names */
10530 "RTL silicon",
10531 "RTL VCS simulation",
10532 "RTL FPGA emulation",
10533 "Functional simulator"
10534 };
10535
10536 dd = hfi1_alloc_devdata(pdev,
10537 NUM_IB_PORTS * sizeof(struct hfi1_pportdata));
10538 if (IS_ERR(dd))
10539 goto bail;
10540 ppd = dd->pport;
10541 for (i = 0; i < dd->num_pports; i++, ppd++) {
10542 int vl;
10543 /* init common fields */
10544 hfi1_init_pportdata(pdev, ppd, dd, 0, 1);
10545 /* DC supports 4 link widths */
10546 ppd->link_width_supported =
10547 OPA_LINK_WIDTH_1X | OPA_LINK_WIDTH_2X |
10548 OPA_LINK_WIDTH_3X | OPA_LINK_WIDTH_4X;
10549 ppd->link_width_downgrade_supported =
10550 ppd->link_width_supported;
10551 /* start out enabling only 4X */
10552 ppd->link_width_enabled = OPA_LINK_WIDTH_4X;
10553 ppd->link_width_downgrade_enabled =
10554 ppd->link_width_downgrade_supported;
10555 /* link width active is 0 when link is down */
10556 /* link width downgrade active is 0 when link is down */
10557
10558 if (num_vls < HFI1_MIN_VLS_SUPPORTED
10559 || num_vls > HFI1_MAX_VLS_SUPPORTED) {
10560 hfi1_early_err(&pdev->dev,
10561 "Invalid num_vls %u, using %u VLs\n",
10562 num_vls, HFI1_MAX_VLS_SUPPORTED);
10563 num_vls = HFI1_MAX_VLS_SUPPORTED;
10564 }
10565 ppd->vls_supported = num_vls;
10566 ppd->vls_operational = ppd->vls_supported;
10567 /* Set the default MTU. */
10568 for (vl = 0; vl < num_vls; vl++)
10569 dd->vld[vl].mtu = hfi1_max_mtu;
10570 dd->vld[15].mtu = MAX_MAD_PACKET;
10571 /*
10572 * Set the initial values to reasonable default, will be set
10573 * for real when link is up.
10574 */
10575 ppd->lstate = IB_PORT_DOWN;
10576 ppd->overrun_threshold = 0x4;
10577 ppd->phy_error_threshold = 0xf;
10578 ppd->port_crc_mode_enabled = link_crc_mask;
10579 /* initialize supported LTP CRC mode */
10580 ppd->port_ltp_crc_mode = cap_to_port_ltp(link_crc_mask) << 8;
10581 /* initialize enabled LTP CRC mode */
10582 ppd->port_ltp_crc_mode |= cap_to_port_ltp(link_crc_mask) << 4;
10583 /* start in offline */
10584 ppd->host_link_state = HLS_DN_OFFLINE;
10585 init_vl_arb_caches(ppd);
10586 }
10587
10588 dd->link_default = HLS_DN_POLL;
10589
10590 /*
10591 * Do remaining PCIe setup and save PCIe values in dd.
10592 * Any error printing is already done by the init code.
10593 * On return, we have the chip mapped.
10594 */
10595 ret = hfi1_pcie_ddinit(dd, pdev, ent);
10596 if (ret < 0)
10597 goto bail_free;
10598
10599 /* verify that reads actually work, save revision for reset check */
10600 dd->revision = read_csr(dd, CCE_REVISION);
10601 if (dd->revision == ~(u64)0) {
10602 dd_dev_err(dd, "cannot read chip CSRs\n");
10603 ret = -EINVAL;
10604 goto bail_cleanup;
10605 }
10606 dd->majrev = (dd->revision >> CCE_REVISION_CHIP_REV_MAJOR_SHIFT)
10607 & CCE_REVISION_CHIP_REV_MAJOR_MASK;
10608 dd->minrev = (dd->revision >> CCE_REVISION_CHIP_REV_MINOR_SHIFT)
10609 & CCE_REVISION_CHIP_REV_MINOR_MASK;
10610
10611 /* obtain the hardware ID - NOT related to unit, which is a
10612 software enumeration */
10613 reg = read_csr(dd, CCE_REVISION2);
10614 dd->hfi1_id = (reg >> CCE_REVISION2_HFI_ID_SHIFT)
10615 & CCE_REVISION2_HFI_ID_MASK;
10616 /* the variable size will remove unwanted bits */
10617 dd->icode = reg >> CCE_REVISION2_IMPL_CODE_SHIFT;
10618 dd->irev = reg >> CCE_REVISION2_IMPL_REVISION_SHIFT;
10619 dd_dev_info(dd, "Implementation: %s, revision 0x%x\n",
10620 dd->icode < ARRAY_SIZE(inames) ? inames[dd->icode] : "unknown",
10621 (int)dd->irev);
10622
10623 /* speeds the hardware can support */
10624 dd->pport->link_speed_supported = OPA_LINK_SPEED_25G;
10625 /* speeds allowed to run at */
10626 dd->pport->link_speed_enabled = dd->pport->link_speed_supported;
10627 /* give a reasonable active value, will be set on link up */
10628 dd->pport->link_speed_active = OPA_LINK_SPEED_25G;
10629
10630 dd->chip_rcv_contexts = read_csr(dd, RCV_CONTEXTS);
10631 dd->chip_send_contexts = read_csr(dd, SEND_CONTEXTS);
10632 dd->chip_sdma_engines = read_csr(dd, SEND_DMA_ENGINES);
10633 dd->chip_pio_mem_size = read_csr(dd, SEND_PIO_MEM_SIZE);
10634 dd->chip_sdma_mem_size = read_csr(dd, SEND_DMA_MEM_SIZE);
10635 /* fix up link widths for emulation _p */
10636 ppd = dd->pport;
10637 if (dd->icode == ICODE_FPGA_EMULATION && is_emulator_p(dd)) {
10638 ppd->link_width_supported =
10639 ppd->link_width_enabled =
10640 ppd->link_width_downgrade_supported =
10641 ppd->link_width_downgrade_enabled =
10642 OPA_LINK_WIDTH_1X;
10643 }
10644 /* insure num_vls isn't larger than number of sdma engines */
10645 if (HFI1_CAP_IS_KSET(SDMA) && num_vls > dd->chip_sdma_engines) {
10646 dd_dev_err(dd, "num_vls %u too large, using %u VLs\n",
10647 num_vls, HFI1_MAX_VLS_SUPPORTED);
10648 ppd->vls_supported = num_vls = HFI1_MAX_VLS_SUPPORTED;
10649 ppd->vls_operational = ppd->vls_supported;
10650 }
10651
10652 /*
10653 * Convert the ns parameter to the 64 * cclocks used in the CSR.
10654 * Limit the max if larger than the field holds. If timeout is
10655 * non-zero, then the calculated field will be at least 1.
10656 *
10657 * Must be after icode is set up - the cclock rate depends
10658 * on knowing the hardware being used.
10659 */
10660 dd->rcv_intr_timeout_csr = ns_to_cclock(dd, rcv_intr_timeout) / 64;
10661 if (dd->rcv_intr_timeout_csr >
10662 RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK)
10663 dd->rcv_intr_timeout_csr =
10664 RCV_AVAIL_TIME_OUT_TIME_OUT_RELOAD_MASK;
10665 else if (dd->rcv_intr_timeout_csr == 0 && rcv_intr_timeout)
10666 dd->rcv_intr_timeout_csr = 1;
10667
Easwar Hariharan7c03ed82015-10-26 10:28:28 -040010668 /* needs to be done before we look for the peer device */
10669 read_guid(dd);
10670
10671 /* should this device init the ASIC block? */
10672 asic_should_init(dd);
10673
Mike Marciniszyn77241052015-07-30 15:17:43 -040010674 /* obtain chip sizes, reset chip CSRs */
10675 init_chip(dd);
10676
10677 /* read in the PCIe link speed information */
10678 ret = pcie_speeds(dd);
10679 if (ret)
10680 goto bail_cleanup;
10681
Mike Marciniszyn77241052015-07-30 15:17:43 -040010682 /* read in firmware */
10683 ret = hfi1_firmware_init(dd);
10684 if (ret)
10685 goto bail_cleanup;
10686
10687 /*
10688 * In general, the PCIe Gen3 transition must occur after the
10689 * chip has been idled (so it won't initiate any PCIe transactions
10690 * e.g. an interrupt) and before the driver changes any registers
10691 * (the transition will reset the registers).
10692 *
10693 * In particular, place this call after:
10694 * - init_chip() - the chip will not initiate any PCIe transactions
10695 * - pcie_speeds() - reads the current link speed
10696 * - hfi1_firmware_init() - the needed firmware is ready to be
10697 * downloaded
10698 */
10699 ret = do_pcie_gen3_transition(dd);
10700 if (ret)
10701 goto bail_cleanup;
10702
10703 /* start setting dd values and adjusting CSRs */
10704 init_early_variables(dd);
10705
10706 parse_platform_config(dd);
10707
Dean Luick5d9157a2015-11-16 21:59:34 -050010708 ret = obtain_boardname(dd);
10709 if (ret)
Mike Marciniszyn77241052015-07-30 15:17:43 -040010710 goto bail_cleanup;
Mike Marciniszyn77241052015-07-30 15:17:43 -040010711
10712 snprintf(dd->boardversion, BOARD_VERS_MAX,
Dean Luick5d9157a2015-11-16 21:59:34 -050010713 "ChipABI %u.%u, ChipRev %u.%u, SW Compat %llu\n",
Mike Marciniszyn77241052015-07-30 15:17:43 -040010714 HFI1_CHIP_VERS_MAJ, HFI1_CHIP_VERS_MIN,
Mike Marciniszyn77241052015-07-30 15:17:43 -040010715 (u32)dd->majrev,
10716 (u32)dd->minrev,
10717 (dd->revision >> CCE_REVISION_SW_SHIFT)
10718 & CCE_REVISION_SW_MASK);
10719
10720 ret = set_up_context_variables(dd);
10721 if (ret)
10722 goto bail_cleanup;
10723
10724 /* set initial RXE CSRs */
10725 init_rxe(dd);
10726 /* set initial TXE CSRs */
10727 init_txe(dd);
10728 /* set initial non-RXE, non-TXE CSRs */
10729 init_other(dd);
10730 /* set up KDETH QP prefix in both RX and TX CSRs */
10731 init_kdeth_qp(dd);
10732
10733 /* send contexts must be set up before receive contexts */
10734 ret = init_send_contexts(dd);
10735 if (ret)
10736 goto bail_cleanup;
10737
10738 ret = hfi1_create_ctxts(dd);
10739 if (ret)
10740 goto bail_cleanup;
10741
10742 dd->rcvhdrsize = DEFAULT_RCVHDRSIZE;
10743 /*
10744 * rcd[0] is guaranteed to be valid by this point. Also, all
10745 * context are using the same value, as per the module parameter.
10746 */
10747 dd->rhf_offset = dd->rcd[0]->rcvhdrqentsize - sizeof(u64) / sizeof(u32);
10748
10749 ret = init_pervl_scs(dd);
10750 if (ret)
10751 goto bail_cleanup;
10752
10753 /* sdma init */
10754 for (i = 0; i < dd->num_pports; ++i) {
10755 ret = sdma_init(dd, i);
10756 if (ret)
10757 goto bail_cleanup;
10758 }
10759
10760 /* use contexts created by hfi1_create_ctxts */
10761 ret = set_up_interrupts(dd);
10762 if (ret)
10763 goto bail_cleanup;
10764
10765 /* set up LCB access - must be after set_up_interrupts() */
10766 init_lcb_access(dd);
10767
10768 snprintf(dd->serial, SERIAL_MAX, "0x%08llx\n",
10769 dd->base_guid & 0xFFFFFF);
10770
10771 dd->oui1 = dd->base_guid >> 56 & 0xFF;
10772 dd->oui2 = dd->base_guid >> 48 & 0xFF;
10773 dd->oui3 = dd->base_guid >> 40 & 0xFF;
10774
10775 ret = load_firmware(dd); /* asymmetric with dispose_firmware() */
10776 if (ret)
10777 goto bail_clear_intr;
10778 check_fabric_firmware_versions(dd);
10779
10780 thermal_init(dd);
10781
10782 ret = init_cntrs(dd);
10783 if (ret)
10784 goto bail_clear_intr;
10785
10786 ret = init_rcverr(dd);
10787 if (ret)
10788 goto bail_free_cntrs;
10789
10790 ret = eprom_init(dd);
10791 if (ret)
10792 goto bail_free_rcverr;
10793
10794 goto bail;
10795
10796bail_free_rcverr:
10797 free_rcverr(dd);
10798bail_free_cntrs:
10799 free_cntrs(dd);
10800bail_clear_intr:
10801 clean_up_interrupts(dd);
10802bail_cleanup:
10803 hfi1_pcie_ddcleanup(dd);
10804bail_free:
10805 hfi1_free_devdata(dd);
10806 dd = ERR_PTR(ret);
10807bail:
10808 return dd;
10809}
10810
10811static u16 delay_cycles(struct hfi1_pportdata *ppd, u32 desired_egress_rate,
10812 u32 dw_len)
10813{
10814 u32 delta_cycles;
10815 u32 current_egress_rate = ppd->current_egress_rate;
10816 /* rates here are in units of 10^6 bits/sec */
10817
10818 if (desired_egress_rate == -1)
10819 return 0; /* shouldn't happen */
10820
10821 if (desired_egress_rate >= current_egress_rate)
10822 return 0; /* we can't help go faster, only slower */
10823
10824 delta_cycles = egress_cycles(dw_len * 4, desired_egress_rate) -
10825 egress_cycles(dw_len * 4, current_egress_rate);
10826
10827 return (u16)delta_cycles;
10828}
10829
10830
10831/**
10832 * create_pbc - build a pbc for transmission
10833 * @flags: special case flags or-ed in built pbc
10834 * @srate: static rate
10835 * @vl: vl
10836 * @dwlen: dword length (header words + data words + pbc words)
10837 *
10838 * Create a PBC with the given flags, rate, VL, and length.
10839 *
10840 * NOTE: The PBC created will not insert any HCRC - all callers but one are
10841 * for verbs, which does not use this PSM feature. The lone other caller
10842 * is for the diagnostic interface which calls this if the user does not
10843 * supply their own PBC.
10844 */
10845u64 create_pbc(struct hfi1_pportdata *ppd, u64 flags, int srate_mbs, u32 vl,
10846 u32 dw_len)
10847{
10848 u64 pbc, delay = 0;
10849
10850 if (unlikely(srate_mbs))
10851 delay = delay_cycles(ppd, srate_mbs, dw_len);
10852
10853 pbc = flags
10854 | (delay << PBC_STATIC_RATE_CONTROL_COUNT_SHIFT)
10855 | ((u64)PBC_IHCRC_NONE << PBC_INSERT_HCRC_SHIFT)
10856 | (vl & PBC_VL_MASK) << PBC_VL_SHIFT
10857 | (dw_len & PBC_LENGTH_DWS_MASK)
10858 << PBC_LENGTH_DWS_SHIFT;
10859
10860 return pbc;
10861}
10862
10863#define SBUS_THERMAL 0x4f
10864#define SBUS_THERM_MONITOR_MODE 0x1
10865
10866#define THERM_FAILURE(dev, ret, reason) \
10867 dd_dev_err((dd), \
10868 "Thermal sensor initialization failed: %s (%d)\n", \
10869 (reason), (ret))
10870
10871/*
10872 * Initialize the Avago Thermal sensor.
10873 *
10874 * After initialization, enable polling of thermal sensor through
10875 * SBus interface. In order for this to work, the SBus Master
10876 * firmware has to be loaded due to the fact that the HW polling
10877 * logic uses SBus interrupts, which are not supported with
10878 * default firmware. Otherwise, no data will be returned through
10879 * the ASIC_STS_THERM CSR.
10880 */
10881static int thermal_init(struct hfi1_devdata *dd)
10882{
10883 int ret = 0;
10884
10885 if (dd->icode != ICODE_RTL_SILICON ||
10886 !(dd->flags & HFI1_DO_INIT_ASIC))
10887 return ret;
10888
10889 acquire_hw_mutex(dd);
10890 dd_dev_info(dd, "Initializing thermal sensor\n");
Jareer Abdel-Qader4ef98982015-11-06 20:07:00 -050010891 /* Disable polling of thermal readings */
10892 write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x0);
10893 msleep(100);
Mike Marciniszyn77241052015-07-30 15:17:43 -040010894 /* Thermal Sensor Initialization */
10895 /* Step 1: Reset the Thermal SBus Receiver */
10896 ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
10897 RESET_SBUS_RECEIVER, 0);
10898 if (ret) {
10899 THERM_FAILURE(dd, ret, "Bus Reset");
10900 goto done;
10901 }
10902 /* Step 2: Set Reset bit in Thermal block */
10903 ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
10904 WRITE_SBUS_RECEIVER, 0x1);
10905 if (ret) {
10906 THERM_FAILURE(dd, ret, "Therm Block Reset");
10907 goto done;
10908 }
10909 /* Step 3: Write clock divider value (100MHz -> 2MHz) */
10910 ret = sbus_request_slow(dd, SBUS_THERMAL, 0x1,
10911 WRITE_SBUS_RECEIVER, 0x32);
10912 if (ret) {
10913 THERM_FAILURE(dd, ret, "Write Clock Div");
10914 goto done;
10915 }
10916 /* Step 4: Select temperature mode */
10917 ret = sbus_request_slow(dd, SBUS_THERMAL, 0x3,
10918 WRITE_SBUS_RECEIVER,
10919 SBUS_THERM_MONITOR_MODE);
10920 if (ret) {
10921 THERM_FAILURE(dd, ret, "Write Mode Sel");
10922 goto done;
10923 }
10924 /* Step 5: De-assert block reset and start conversion */
10925 ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
10926 WRITE_SBUS_RECEIVER, 0x2);
10927 if (ret) {
10928 THERM_FAILURE(dd, ret, "Write Reset Deassert");
10929 goto done;
10930 }
10931 /* Step 5.1: Wait for first conversion (21.5ms per spec) */
10932 msleep(22);
10933
10934 /* Enable polling of thermal readings */
10935 write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0x1);
10936done:
10937 release_hw_mutex(dd);
10938 return ret;
10939}
10940
10941static void handle_temp_err(struct hfi1_devdata *dd)
10942{
10943 struct hfi1_pportdata *ppd = &dd->pport[0];
10944 /*
10945 * Thermal Critical Interrupt
10946 * Put the device into forced freeze mode, take link down to
10947 * offline, and put DC into reset.
10948 */
10949 dd_dev_emerg(dd,
10950 "Critical temperature reached! Forcing device into freeze mode!\n");
10951 dd->flags |= HFI1_FORCED_FREEZE;
10952 start_freeze_handling(ppd, FREEZE_SELF|FREEZE_ABORT);
10953 /*
10954 * Shut DC down as much and as quickly as possible.
10955 *
10956 * Step 1: Take the link down to OFFLINE. This will cause the
10957 * 8051 to put the Serdes in reset. However, we don't want to
10958 * go through the entire link state machine since we want to
10959 * shutdown ASAP. Furthermore, this is not a graceful shutdown
10960 * but rather an attempt to save the chip.
10961 * Code below is almost the same as quiet_serdes() but avoids
10962 * all the extra work and the sleeps.
10963 */
10964 ppd->driver_link_ready = 0;
10965 ppd->link_enabled = 0;
10966 set_physical_link_state(dd, PLS_OFFLINE |
10967 (OPA_LINKDOWN_REASON_SMA_DISABLED << 8));
10968 /*
10969 * Step 2: Shutdown LCB and 8051
10970 * After shutdown, do not restore DC_CFG_RESET value.
10971 */
10972 dc_shutdown(dd);
10973}