blob: 0113b4e60447e6fb925f4dc9231f09fd2b8c4d19 [file] [log] [blame]
Ralph Campbellf9315512010-05-23 21:44:54 -07001/*
Michael J. Ruhl581d01a2017-06-09 16:00:06 -07002 * Copyright (c) 2013 - 2017 Intel Corporation. All rights reserved.
Ralph Campbellf9315512010-05-23 21:44:54 -07003 * Copyright (c) 2006, 2007, 2008, 2009, 2010 QLogic Corporation.
4 * All rights reserved.
5 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
6 *
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
12 *
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
15 * conditions are met:
16 *
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer.
20 *
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 * SOFTWARE.
34 */
35/*
36 * This file contains all of the code that is specific to the
37 * QLogic_IB 6120 PCIe chip.
38 */
39
40#include <linux/interrupt.h>
41#include <linux/pci.h>
42#include <linux/delay.h>
43#include <rdma/ib_verbs.h>
44
45#include "qib.h"
46#include "qib_6120_regs.h"
47
48static void qib_6120_setup_setextled(struct qib_pportdata *, u32);
49static void sendctrl_6120_mod(struct qib_pportdata *ppd, u32 op);
50static u8 qib_6120_phys_portstate(u64);
51static u32 qib_6120_iblink_state(u64);
52
53/*
54 * This file contains all the chip-specific register information and
Vinit Agnihotrie2eed582013-03-14 18:13:41 +000055 * access functions for the Intel Intel_IB PCI-Express chip.
Ralph Campbellf9315512010-05-23 21:44:54 -070056 *
57 */
58
59/* KREG_IDX uses machine-generated #defines */
60#define KREG_IDX(regname) (QIB_6120_##regname##_OFFS / sizeof(u64))
61
62/* Use defines to tie machine-generated names to lower-case names */
63#define kr_extctrl KREG_IDX(EXTCtrl)
64#define kr_extstatus KREG_IDX(EXTStatus)
65#define kr_gpio_clear KREG_IDX(GPIOClear)
66#define kr_gpio_mask KREG_IDX(GPIOMask)
67#define kr_gpio_out KREG_IDX(GPIOOut)
68#define kr_gpio_status KREG_IDX(GPIOStatus)
69#define kr_rcvctrl KREG_IDX(RcvCtrl)
70#define kr_sendctrl KREG_IDX(SendCtrl)
71#define kr_partitionkey KREG_IDX(RcvPartitionKey)
72#define kr_hwdiagctrl KREG_IDX(HwDiagCtrl)
73#define kr_ibcstatus KREG_IDX(IBCStatus)
74#define kr_ibcctrl KREG_IDX(IBCCtrl)
75#define kr_sendbuffererror KREG_IDX(SendBufErr0)
76#define kr_rcvbthqp KREG_IDX(RcvBTHQP)
77#define kr_counterregbase KREG_IDX(CntrRegBase)
78#define kr_palign KREG_IDX(PageAlign)
79#define kr_rcvegrbase KREG_IDX(RcvEgrBase)
80#define kr_rcvegrcnt KREG_IDX(RcvEgrCnt)
81#define kr_rcvhdrcnt KREG_IDX(RcvHdrCnt)
82#define kr_rcvhdrentsize KREG_IDX(RcvHdrEntSize)
83#define kr_rcvhdrsize KREG_IDX(RcvHdrSize)
84#define kr_rcvtidbase KREG_IDX(RcvTIDBase)
85#define kr_rcvtidcnt KREG_IDX(RcvTIDCnt)
86#define kr_scratch KREG_IDX(Scratch)
87#define kr_sendctrl KREG_IDX(SendCtrl)
88#define kr_sendpioavailaddr KREG_IDX(SendPIOAvailAddr)
89#define kr_sendpiobufbase KREG_IDX(SendPIOBufBase)
90#define kr_sendpiobufcnt KREG_IDX(SendPIOBufCnt)
91#define kr_sendpiosize KREG_IDX(SendPIOSize)
92#define kr_sendregbase KREG_IDX(SendRegBase)
93#define kr_userregbase KREG_IDX(UserRegBase)
94#define kr_control KREG_IDX(Control)
95#define kr_intclear KREG_IDX(IntClear)
96#define kr_intmask KREG_IDX(IntMask)
97#define kr_intstatus KREG_IDX(IntStatus)
98#define kr_errclear KREG_IDX(ErrClear)
99#define kr_errmask KREG_IDX(ErrMask)
100#define kr_errstatus KREG_IDX(ErrStatus)
101#define kr_hwerrclear KREG_IDX(HwErrClear)
102#define kr_hwerrmask KREG_IDX(HwErrMask)
103#define kr_hwerrstatus KREG_IDX(HwErrStatus)
104#define kr_revision KREG_IDX(Revision)
105#define kr_portcnt KREG_IDX(PortCnt)
106#define kr_serdes_cfg0 KREG_IDX(SerdesCfg0)
107#define kr_serdes_cfg1 (kr_serdes_cfg0 + 1)
108#define kr_serdes_stat KREG_IDX(SerdesStat)
109#define kr_xgxs_cfg KREG_IDX(XGXSCfg)
110
111/* These must only be written via qib_write_kreg_ctxt() */
112#define kr_rcvhdraddr KREG_IDX(RcvHdrAddr0)
113#define kr_rcvhdrtailaddr KREG_IDX(RcvHdrTailAddr0)
114
115#define CREG_IDX(regname) ((QIB_6120_##regname##_OFFS - \
116 QIB_6120_LBIntCnt_OFFS) / sizeof(u64))
117
118#define cr_badformat CREG_IDX(RxBadFormatCnt)
119#define cr_erricrc CREG_IDX(RxICRCErrCnt)
120#define cr_errlink CREG_IDX(RxLinkProblemCnt)
121#define cr_errlpcrc CREG_IDX(RxLPCRCErrCnt)
122#define cr_errpkey CREG_IDX(RxPKeyMismatchCnt)
123#define cr_rcvflowctrl_err CREG_IDX(RxFlowCtrlErrCnt)
124#define cr_err_rlen CREG_IDX(RxLenErrCnt)
125#define cr_errslen CREG_IDX(TxLenErrCnt)
126#define cr_errtidfull CREG_IDX(RxTIDFullErrCnt)
127#define cr_errtidvalid CREG_IDX(RxTIDValidErrCnt)
128#define cr_errvcrc CREG_IDX(RxVCRCErrCnt)
129#define cr_ibstatuschange CREG_IDX(IBStatusChangeCnt)
130#define cr_lbint CREG_IDX(LBIntCnt)
131#define cr_invalidrlen CREG_IDX(RxMaxMinLenErrCnt)
132#define cr_invalidslen CREG_IDX(TxMaxMinLenErrCnt)
133#define cr_lbflowstall CREG_IDX(LBFlowStallCnt)
134#define cr_pktrcv CREG_IDX(RxDataPktCnt)
135#define cr_pktrcvflowctrl CREG_IDX(RxFlowPktCnt)
136#define cr_pktsend CREG_IDX(TxDataPktCnt)
137#define cr_pktsendflow CREG_IDX(TxFlowPktCnt)
138#define cr_portovfl CREG_IDX(RxP0HdrEgrOvflCnt)
139#define cr_rcvebp CREG_IDX(RxEBPCnt)
140#define cr_rcvovfl CREG_IDX(RxBufOvflCnt)
141#define cr_senddropped CREG_IDX(TxDroppedPktCnt)
142#define cr_sendstall CREG_IDX(TxFlowStallCnt)
143#define cr_sendunderrun CREG_IDX(TxUnderrunCnt)
144#define cr_wordrcv CREG_IDX(RxDwordCnt)
145#define cr_wordsend CREG_IDX(TxDwordCnt)
146#define cr_txunsupvl CREG_IDX(TxUnsupVLErrCnt)
147#define cr_rxdroppkt CREG_IDX(RxDroppedPktCnt)
148#define cr_iblinkerrrecov CREG_IDX(IBLinkErrRecoveryCnt)
149#define cr_iblinkdown CREG_IDX(IBLinkDownedCnt)
150#define cr_ibsymbolerr CREG_IDX(IBSymbolErrCnt)
151
152#define SYM_RMASK(regname, fldname) ((u64) \
153 QIB_6120_##regname##_##fldname##_RMASK)
154#define SYM_MASK(regname, fldname) ((u64) \
155 QIB_6120_##regname##_##fldname##_RMASK << \
156 QIB_6120_##regname##_##fldname##_LSB)
157#define SYM_LSB(regname, fldname) (QIB_6120_##regname##_##fldname##_LSB)
158
159#define SYM_FIELD(value, regname, fldname) ((u64) \
160 (((value) >> SYM_LSB(regname, fldname)) & \
161 SYM_RMASK(regname, fldname)))
162#define ERR_MASK(fldname) SYM_MASK(ErrMask, fldname##Mask)
163#define HWE_MASK(fldname) SYM_MASK(HwErrMask, fldname##Mask)
164
165/* link training states, from IBC */
166#define IB_6120_LT_STATE_DISABLED 0x00
167#define IB_6120_LT_STATE_LINKUP 0x01
168#define IB_6120_LT_STATE_POLLACTIVE 0x02
169#define IB_6120_LT_STATE_POLLQUIET 0x03
170#define IB_6120_LT_STATE_SLEEPDELAY 0x04
171#define IB_6120_LT_STATE_SLEEPQUIET 0x05
172#define IB_6120_LT_STATE_CFGDEBOUNCE 0x08
173#define IB_6120_LT_STATE_CFGRCVFCFG 0x09
174#define IB_6120_LT_STATE_CFGWAITRMT 0x0a
175#define IB_6120_LT_STATE_CFGIDLE 0x0b
176#define IB_6120_LT_STATE_RECOVERRETRAIN 0x0c
177#define IB_6120_LT_STATE_RECOVERWAITRMT 0x0e
178#define IB_6120_LT_STATE_RECOVERIDLE 0x0f
179
180/* link state machine states from IBC */
181#define IB_6120_L_STATE_DOWN 0x0
182#define IB_6120_L_STATE_INIT 0x1
183#define IB_6120_L_STATE_ARM 0x2
184#define IB_6120_L_STATE_ACTIVE 0x3
185#define IB_6120_L_STATE_ACT_DEFER 0x4
186
187static const u8 qib_6120_physportstate[0x20] = {
188 [IB_6120_LT_STATE_DISABLED] = IB_PHYSPORTSTATE_DISABLED,
189 [IB_6120_LT_STATE_LINKUP] = IB_PHYSPORTSTATE_LINKUP,
190 [IB_6120_LT_STATE_POLLACTIVE] = IB_PHYSPORTSTATE_POLL,
191 [IB_6120_LT_STATE_POLLQUIET] = IB_PHYSPORTSTATE_POLL,
192 [IB_6120_LT_STATE_SLEEPDELAY] = IB_PHYSPORTSTATE_SLEEP,
193 [IB_6120_LT_STATE_SLEEPQUIET] = IB_PHYSPORTSTATE_SLEEP,
194 [IB_6120_LT_STATE_CFGDEBOUNCE] =
195 IB_PHYSPORTSTATE_CFG_TRAIN,
196 [IB_6120_LT_STATE_CFGRCVFCFG] =
197 IB_PHYSPORTSTATE_CFG_TRAIN,
198 [IB_6120_LT_STATE_CFGWAITRMT] =
199 IB_PHYSPORTSTATE_CFG_TRAIN,
200 [IB_6120_LT_STATE_CFGIDLE] = IB_PHYSPORTSTATE_CFG_TRAIN,
201 [IB_6120_LT_STATE_RECOVERRETRAIN] =
202 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
203 [IB_6120_LT_STATE_RECOVERWAITRMT] =
204 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
205 [IB_6120_LT_STATE_RECOVERIDLE] =
206 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
207 [0x10] = IB_PHYSPORTSTATE_CFG_TRAIN,
208 [0x11] = IB_PHYSPORTSTATE_CFG_TRAIN,
209 [0x12] = IB_PHYSPORTSTATE_CFG_TRAIN,
210 [0x13] = IB_PHYSPORTSTATE_CFG_TRAIN,
211 [0x14] = IB_PHYSPORTSTATE_CFG_TRAIN,
212 [0x15] = IB_PHYSPORTSTATE_CFG_TRAIN,
213 [0x16] = IB_PHYSPORTSTATE_CFG_TRAIN,
214 [0x17] = IB_PHYSPORTSTATE_CFG_TRAIN
215};
216
217
218struct qib_chip_specific {
219 u64 __iomem *cregbase;
220 u64 *cntrs;
221 u64 *portcntrs;
222 void *dummy_hdrq; /* used after ctxt close */
223 dma_addr_t dummy_hdrq_phys;
224 spinlock_t kernel_tid_lock; /* no back to back kernel TID writes */
225 spinlock_t user_tid_lock; /* no back to back user TID writes */
226 spinlock_t rcvmod_lock; /* protect rcvctrl shadow changes */
227 spinlock_t gpio_lock; /* RMW of shadows/regs for ExtCtrl and GPIO */
228 u64 hwerrmask;
229 u64 errormask;
230 u64 gpio_out; /* shadow of kr_gpio_out, for rmw ops */
231 u64 gpio_mask; /* shadow the gpio mask register */
232 u64 extctrl; /* shadow the gpio output enable, etc... */
233 /*
234 * these 5 fields are used to establish deltas for IB symbol
235 * errors and linkrecovery errors. They can be reported on
236 * some chips during link negotiation prior to INIT, and with
237 * DDR when faking DDR negotiations with non-IBTA switches.
238 * The chip counters are adjusted at driver unload if there is
239 * a non-zero delta.
240 */
241 u64 ibdeltainprog;
242 u64 ibsymdelta;
243 u64 ibsymsnap;
244 u64 iblnkerrdelta;
245 u64 iblnkerrsnap;
246 u64 ibcctrl; /* shadow for kr_ibcctrl */
247 u32 lastlinkrecov; /* link recovery issue */
248 int irq;
249 u32 cntrnamelen;
250 u32 portcntrnamelen;
251 u32 ncntrs;
252 u32 nportcntrs;
253 /* used with gpio interrupts to implement IB counters */
254 u32 rxfc_unsupvl_errs;
255 u32 overrun_thresh_errs;
256 /*
257 * these count only cases where _successive_ LocalLinkIntegrity
258 * errors were seen in the receive headers of IB standard packets
259 */
260 u32 lli_errs;
261 u32 lli_counter;
262 u64 lli_thresh;
263 u64 sword; /* total dwords sent (sample result) */
264 u64 rword; /* total dwords received (sample result) */
265 u64 spkts; /* total packets sent (sample result) */
266 u64 rpkts; /* total packets received (sample result) */
267 u64 xmit_wait; /* # of ticks no data sent (sample result) */
268 struct timer_list pma_timer;
Kees Cook4037c922017-10-04 17:45:35 -0700269 struct qib_pportdata *ppd;
Ralph Campbellf9315512010-05-23 21:44:54 -0700270 char emsgbuf[128];
271 char bitsmsgbuf[64];
272 u8 pma_sample_status;
273};
274
275/* ibcctrl bits */
276#define QLOGIC_IB_IBCC_LINKINITCMD_DISABLE 1
277/* cycle through TS1/TS2 till OK */
278#define QLOGIC_IB_IBCC_LINKINITCMD_POLL 2
279/* wait for TS1, then go on */
280#define QLOGIC_IB_IBCC_LINKINITCMD_SLEEP 3
281#define QLOGIC_IB_IBCC_LINKINITCMD_SHIFT 16
282
283#define QLOGIC_IB_IBCC_LINKCMD_DOWN 1 /* move to 0x11 */
284#define QLOGIC_IB_IBCC_LINKCMD_ARMED 2 /* move to 0x21 */
285#define QLOGIC_IB_IBCC_LINKCMD_ACTIVE 3 /* move to 0x31 */
286#define QLOGIC_IB_IBCC_LINKCMD_SHIFT 18
287
288/*
289 * We could have a single register get/put routine, that takes a group type,
290 * but this is somewhat clearer and cleaner. It also gives us some error
291 * checking. 64 bit register reads should always work, but are inefficient
292 * on opteron (the northbridge always generates 2 separate HT 32 bit reads),
293 * so we use kreg32 wherever possible. User register and counter register
294 * reads are always 32 bit reads, so only one form of those routines.
295 */
296
297/**
298 * qib_read_ureg32 - read 32-bit virtualized per-context register
299 * @dd: device
300 * @regno: register number
301 * @ctxt: context number
302 *
303 * Return the contents of a register that is virtualized to be per context.
304 * Returns -1 on errors (not distinguishable from valid contents at
305 * runtime; we may add a separate error variable at some point).
306 */
307static inline u32 qib_read_ureg32(const struct qib_devdata *dd,
308 enum qib_ureg regno, int ctxt)
309{
310 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
311 return 0;
312
313 if (dd->userbase)
314 return readl(regno + (u64 __iomem *)
315 ((char __iomem *)dd->userbase +
316 dd->ureg_align * ctxt));
317 else
318 return readl(regno + (u64 __iomem *)
319 (dd->uregbase +
320 (char __iomem *)dd->kregbase +
321 dd->ureg_align * ctxt));
322}
323
324/**
325 * qib_write_ureg - write 32-bit virtualized per-context register
326 * @dd: device
327 * @regno: register number
328 * @value: value
329 * @ctxt: context
330 *
331 * Write the contents of a register that is virtualized to be per context.
332 */
333static inline void qib_write_ureg(const struct qib_devdata *dd,
334 enum qib_ureg regno, u64 value, int ctxt)
335{
336 u64 __iomem *ubase;
Mike Marciniszynda12c1f2015-01-16 11:23:31 -0500337
Ralph Campbellf9315512010-05-23 21:44:54 -0700338 if (dd->userbase)
339 ubase = (u64 __iomem *)
340 ((char __iomem *) dd->userbase +
341 dd->ureg_align * ctxt);
342 else
343 ubase = (u64 __iomem *)
344 (dd->uregbase +
345 (char __iomem *) dd->kregbase +
346 dd->ureg_align * ctxt);
347
348 if (dd->kregbase && (dd->flags & QIB_PRESENT))
349 writeq(value, &ubase[regno]);
350}
351
352static inline u32 qib_read_kreg32(const struct qib_devdata *dd,
353 const u16 regno)
354{
355 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
356 return -1;
357 return readl((u32 __iomem *)&dd->kregbase[regno]);
358}
359
360static inline u64 qib_read_kreg64(const struct qib_devdata *dd,
361 const u16 regno)
362{
363 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
364 return -1;
365
366 return readq(&dd->kregbase[regno]);
367}
368
369static inline void qib_write_kreg(const struct qib_devdata *dd,
370 const u16 regno, u64 value)
371{
372 if (dd->kregbase && (dd->flags & QIB_PRESENT))
373 writeq(value, &dd->kregbase[regno]);
374}
375
376/**
377 * qib_write_kreg_ctxt - write a device's per-ctxt 64-bit kernel register
378 * @dd: the qlogic_ib device
379 * @regno: the register number to write
380 * @ctxt: the context containing the register
381 * @value: the value to write
382 */
383static inline void qib_write_kreg_ctxt(const struct qib_devdata *dd,
384 const u16 regno, unsigned ctxt,
385 u64 value)
386{
387 qib_write_kreg(dd, regno + ctxt, value);
388}
389
390static inline void write_6120_creg(const struct qib_devdata *dd,
391 u16 regno, u64 value)
392{
393 if (dd->cspec->cregbase && (dd->flags & QIB_PRESENT))
394 writeq(value, &dd->cspec->cregbase[regno]);
395}
396
397static inline u64 read_6120_creg(const struct qib_devdata *dd, u16 regno)
398{
399 if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
400 return 0;
401 return readq(&dd->cspec->cregbase[regno]);
402}
403
404static inline u32 read_6120_creg32(const struct qib_devdata *dd, u16 regno)
405{
406 if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
407 return 0;
408 return readl(&dd->cspec->cregbase[regno]);
409}
410
411/* kr_control bits */
412#define QLOGIC_IB_C_RESET 1U
413
414/* kr_intstatus, kr_intclear, kr_intmask bits */
415#define QLOGIC_IB_I_RCVURG_MASK ((1U << 5) - 1)
416#define QLOGIC_IB_I_RCVURG_SHIFT 0
417#define QLOGIC_IB_I_RCVAVAIL_MASK ((1U << 5) - 1)
418#define QLOGIC_IB_I_RCVAVAIL_SHIFT 12
419
420#define QLOGIC_IB_C_FREEZEMODE 0x00000002
421#define QLOGIC_IB_C_LINKENABLE 0x00000004
422#define QLOGIC_IB_I_ERROR 0x0000000080000000ULL
423#define QLOGIC_IB_I_SPIOSENT 0x0000000040000000ULL
424#define QLOGIC_IB_I_SPIOBUFAVAIL 0x0000000020000000ULL
425#define QLOGIC_IB_I_GPIO 0x0000000010000000ULL
426#define QLOGIC_IB_I_BITSEXTANT \
427 ((QLOGIC_IB_I_RCVURG_MASK << QLOGIC_IB_I_RCVURG_SHIFT) | \
428 (QLOGIC_IB_I_RCVAVAIL_MASK << \
429 QLOGIC_IB_I_RCVAVAIL_SHIFT) | \
430 QLOGIC_IB_I_ERROR | QLOGIC_IB_I_SPIOSENT | \
431 QLOGIC_IB_I_SPIOBUFAVAIL | QLOGIC_IB_I_GPIO)
432
433/* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
434#define QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK 0x000000000000003fULL
435#define QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT 0
436#define QLOGIC_IB_HWE_PCIEPOISONEDTLP 0x0000000010000000ULL
437#define QLOGIC_IB_HWE_PCIECPLTIMEOUT 0x0000000020000000ULL
438#define QLOGIC_IB_HWE_PCIEBUSPARITYXTLH 0x0000000040000000ULL
439#define QLOGIC_IB_HWE_PCIEBUSPARITYXADM 0x0000000080000000ULL
440#define QLOGIC_IB_HWE_PCIEBUSPARITYRADM 0x0000000100000000ULL
441#define QLOGIC_IB_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
442#define QLOGIC_IB_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
443#define QLOGIC_IB_HWE_PCIE1PLLFAILED 0x0400000000000000ULL
444#define QLOGIC_IB_HWE_PCIE0PLLFAILED 0x0800000000000000ULL
445#define QLOGIC_IB_HWE_SERDESPLLFAILED 0x1000000000000000ULL
446
447
448/* kr_extstatus bits */
449#define QLOGIC_IB_EXTS_FREQSEL 0x2
450#define QLOGIC_IB_EXTS_SERDESSEL 0x4
451#define QLOGIC_IB_EXTS_MEMBIST_ENDTEST 0x0000000000004000
452#define QLOGIC_IB_EXTS_MEMBIST_FOUND 0x0000000000008000
453
454/* kr_xgxsconfig bits */
455#define QLOGIC_IB_XGXS_RESET 0x5ULL
456
457#define _QIB_GPIO_SDA_NUM 1
458#define _QIB_GPIO_SCL_NUM 0
459
460/* Bits in GPIO for the added IB link interrupts */
461#define GPIO_RXUVL_BIT 3
462#define GPIO_OVRUN_BIT 4
463#define GPIO_LLI_BIT 5
464#define GPIO_ERRINTR_MASK 0x38
465
466
467#define QLOGIC_IB_RT_BUFSIZE_MASK 0xe0000000ULL
468#define QLOGIC_IB_RT_BUFSIZE_SHIFTVAL(tid) \
469 ((((tid) & QLOGIC_IB_RT_BUFSIZE_MASK) >> 29) + 11 - 1)
470#define QLOGIC_IB_RT_BUFSIZE(tid) (1 << QLOGIC_IB_RT_BUFSIZE_SHIFTVAL(tid))
471#define QLOGIC_IB_RT_IS_VALID(tid) \
472 (((tid) & QLOGIC_IB_RT_BUFSIZE_MASK) && \
473 ((((tid) & QLOGIC_IB_RT_BUFSIZE_MASK) != QLOGIC_IB_RT_BUFSIZE_MASK)))
474#define QLOGIC_IB_RT_ADDR_MASK 0x1FFFFFFFULL /* 29 bits valid */
475#define QLOGIC_IB_RT_ADDR_SHIFT 10
476
477#define QLOGIC_IB_R_INTRAVAIL_SHIFT 16
478#define QLOGIC_IB_R_TAILUPD_SHIFT 31
479#define IBA6120_R_PKEY_DIS_SHIFT 30
480
481#define PBC_6120_VL15_SEND_CTRL (1ULL << 31) /* pbc; VL15; link_buf only */
482
483#define IBCBUSFRSPCPARITYERR HWE_MASK(IBCBusFromSPCParityErr)
484#define IBCBUSTOSPCPARITYERR HWE_MASK(IBCBusToSPCParityErr)
485
486#define SYM_MASK_BIT(regname, fldname, bit) ((u64) \
487 ((1ULL << (SYM_LSB(regname, fldname) + (bit)))))
488
489#define TXEMEMPARITYERR_PIOBUF \
490 SYM_MASK_BIT(HwErrMask, TXEMemParityErrMask, 0)
491#define TXEMEMPARITYERR_PIOPBC \
492 SYM_MASK_BIT(HwErrMask, TXEMemParityErrMask, 1)
493#define TXEMEMPARITYERR_PIOLAUNCHFIFO \
494 SYM_MASK_BIT(HwErrMask, TXEMemParityErrMask, 2)
495
496#define RXEMEMPARITYERR_RCVBUF \
497 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 0)
498#define RXEMEMPARITYERR_LOOKUPQ \
499 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 1)
500#define RXEMEMPARITYERR_EXPTID \
501 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 2)
502#define RXEMEMPARITYERR_EAGERTID \
503 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 3)
504#define RXEMEMPARITYERR_FLAGBUF \
505 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 4)
506#define RXEMEMPARITYERR_DATAINFO \
507 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 5)
508#define RXEMEMPARITYERR_HDRINFO \
509 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 6)
510
511/* 6120 specific hardware errors... */
512static const struct qib_hwerror_msgs qib_6120_hwerror_msgs[] = {
513 /* generic hardware errors */
514 QLOGIC_IB_HWE_MSG(IBCBUSFRSPCPARITYERR, "QIB2IB Parity"),
515 QLOGIC_IB_HWE_MSG(IBCBUSTOSPCPARITYERR, "IB2QIB Parity"),
516
517 QLOGIC_IB_HWE_MSG(TXEMEMPARITYERR_PIOBUF,
518 "TXE PIOBUF Memory Parity"),
519 QLOGIC_IB_HWE_MSG(TXEMEMPARITYERR_PIOPBC,
520 "TXE PIOPBC Memory Parity"),
521 QLOGIC_IB_HWE_MSG(TXEMEMPARITYERR_PIOLAUNCHFIFO,
522 "TXE PIOLAUNCHFIFO Memory Parity"),
523
524 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_RCVBUF,
525 "RXE RCVBUF Memory Parity"),
526 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_LOOKUPQ,
527 "RXE LOOKUPQ Memory Parity"),
528 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_EAGERTID,
529 "RXE EAGERTID Memory Parity"),
530 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_EXPTID,
531 "RXE EXPTID Memory Parity"),
532 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_FLAGBUF,
533 "RXE FLAGBUF Memory Parity"),
534 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_DATAINFO,
535 "RXE DATAINFO Memory Parity"),
536 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_HDRINFO,
537 "RXE HDRINFO Memory Parity"),
538
539 /* chip-specific hardware errors */
540 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEPOISONEDTLP,
541 "PCIe Poisoned TLP"),
542 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIECPLTIMEOUT,
543 "PCIe completion timeout"),
544 /*
545 * In practice, it's unlikely wthat we'll see PCIe PLL, or bus
546 * parity or memory parity error failures, because most likely we
547 * won't be able to talk to the core of the chip. Nonetheless, we
548 * might see them, if they are in parts of the PCIe core that aren't
549 * essential.
550 */
551 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIE1PLLFAILED,
552 "PCIePLL1"),
553 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIE0PLLFAILED,
554 "PCIePLL0"),
555 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEBUSPARITYXTLH,
556 "PCIe XTLH core parity"),
557 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEBUSPARITYXADM,
558 "PCIe ADM TX core parity"),
559 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEBUSPARITYRADM,
560 "PCIe ADM RX core parity"),
561 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_SERDESPLLFAILED,
562 "SerDes PLL"),
563};
564
565#define TXE_PIO_PARITY (TXEMEMPARITYERR_PIOBUF | TXEMEMPARITYERR_PIOPBC)
566#define _QIB_PLL_FAIL (QLOGIC_IB_HWE_COREPLL_FBSLIP | \
567 QLOGIC_IB_HWE_COREPLL_RFSLIP)
568
569 /* variables for sanity checking interrupt and errors */
570#define IB_HWE_BITSEXTANT \
571 (HWE_MASK(RXEMemParityErr) | \
572 HWE_MASK(TXEMemParityErr) | \
573 (QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK << \
574 QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT) | \
575 QLOGIC_IB_HWE_PCIE1PLLFAILED | \
576 QLOGIC_IB_HWE_PCIE0PLLFAILED | \
577 QLOGIC_IB_HWE_PCIEPOISONEDTLP | \
578 QLOGIC_IB_HWE_PCIECPLTIMEOUT | \
579 QLOGIC_IB_HWE_PCIEBUSPARITYXTLH | \
580 QLOGIC_IB_HWE_PCIEBUSPARITYXADM | \
581 QLOGIC_IB_HWE_PCIEBUSPARITYRADM | \
582 HWE_MASK(PowerOnBISTFailed) | \
583 QLOGIC_IB_HWE_COREPLL_FBSLIP | \
584 QLOGIC_IB_HWE_COREPLL_RFSLIP | \
585 QLOGIC_IB_HWE_SERDESPLLFAILED | \
586 HWE_MASK(IBCBusToSPCParityErr) | \
587 HWE_MASK(IBCBusFromSPCParityErr))
588
589#define IB_E_BITSEXTANT \
590 (ERR_MASK(RcvFormatErr) | ERR_MASK(RcvVCRCErr) | \
591 ERR_MASK(RcvICRCErr) | ERR_MASK(RcvMinPktLenErr) | \
592 ERR_MASK(RcvMaxPktLenErr) | ERR_MASK(RcvLongPktLenErr) | \
593 ERR_MASK(RcvShortPktLenErr) | ERR_MASK(RcvUnexpectedCharErr) | \
594 ERR_MASK(RcvUnsupportedVLErr) | ERR_MASK(RcvEBPErr) | \
595 ERR_MASK(RcvIBFlowErr) | ERR_MASK(RcvBadVersionErr) | \
596 ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr) | \
597 ERR_MASK(RcvBadTidErr) | ERR_MASK(RcvHdrLenErr) | \
598 ERR_MASK(RcvHdrErr) | ERR_MASK(RcvIBLostLinkErr) | \
599 ERR_MASK(SendMinPktLenErr) | ERR_MASK(SendMaxPktLenErr) | \
600 ERR_MASK(SendUnderRunErr) | ERR_MASK(SendPktLenErr) | \
601 ERR_MASK(SendDroppedSmpPktErr) | \
602 ERR_MASK(SendDroppedDataPktErr) | \
603 ERR_MASK(SendPioArmLaunchErr) | \
604 ERR_MASK(SendUnexpectedPktNumErr) | \
605 ERR_MASK(SendUnsupportedVLErr) | ERR_MASK(IBStatusChanged) | \
606 ERR_MASK(InvalidAddrErr) | ERR_MASK(ResetNegated) | \
607 ERR_MASK(HardwareErr))
608
609#define QLOGIC_IB_E_PKTERRS ( \
610 ERR_MASK(SendPktLenErr) | \
611 ERR_MASK(SendDroppedDataPktErr) | \
612 ERR_MASK(RcvVCRCErr) | \
613 ERR_MASK(RcvICRCErr) | \
614 ERR_MASK(RcvShortPktLenErr) | \
615 ERR_MASK(RcvEBPErr))
616
617/* These are all rcv-related errors which we want to count for stats */
618#define E_SUM_PKTERRS \
619 (ERR_MASK(RcvHdrLenErr) | ERR_MASK(RcvBadTidErr) | \
620 ERR_MASK(RcvBadVersionErr) | ERR_MASK(RcvHdrErr) | \
621 ERR_MASK(RcvLongPktLenErr) | ERR_MASK(RcvShortPktLenErr) | \
622 ERR_MASK(RcvMaxPktLenErr) | ERR_MASK(RcvMinPktLenErr) | \
623 ERR_MASK(RcvFormatErr) | ERR_MASK(RcvUnsupportedVLErr) | \
624 ERR_MASK(RcvUnexpectedCharErr) | ERR_MASK(RcvEBPErr))
625
626/* These are all send-related errors which we want to count for stats */
627#define E_SUM_ERRS \
628 (ERR_MASK(SendPioArmLaunchErr) | \
629 ERR_MASK(SendUnexpectedPktNumErr) | \
630 ERR_MASK(SendDroppedDataPktErr) | \
631 ERR_MASK(SendDroppedSmpPktErr) | \
632 ERR_MASK(SendMaxPktLenErr) | ERR_MASK(SendUnsupportedVLErr) | \
633 ERR_MASK(SendMinPktLenErr) | ERR_MASK(SendPktLenErr) | \
634 ERR_MASK(InvalidAddrErr))
635
636/*
637 * this is similar to E_SUM_ERRS, but can't ignore armlaunch, don't ignore
638 * errors not related to freeze and cancelling buffers. Can't ignore
639 * armlaunch because could get more while still cleaning up, and need
640 * to cancel those as they happen.
641 */
642#define E_SPKT_ERRS_IGNORE \
643 (ERR_MASK(SendDroppedDataPktErr) | \
644 ERR_MASK(SendDroppedSmpPktErr) | \
645 ERR_MASK(SendMaxPktLenErr) | ERR_MASK(SendMinPktLenErr) | \
646 ERR_MASK(SendPktLenErr))
647
648/*
649 * these are errors that can occur when the link changes state while
650 * a packet is being sent or received. This doesn't cover things
651 * like EBP or VCRC that can be the result of a sending having the
652 * link change state, so we receive a "known bad" packet.
653 */
654#define E_SUM_LINK_PKTERRS \
655 (ERR_MASK(SendDroppedDataPktErr) | \
656 ERR_MASK(SendDroppedSmpPktErr) | \
657 ERR_MASK(SendMinPktLenErr) | ERR_MASK(SendPktLenErr) | \
658 ERR_MASK(RcvShortPktLenErr) | ERR_MASK(RcvMinPktLenErr) | \
659 ERR_MASK(RcvUnexpectedCharErr))
660
661static void qib_6120_put_tid_2(struct qib_devdata *, u64 __iomem *,
662 u32, unsigned long);
663
664/*
665 * On platforms using this chip, and not having ordered WC stores, we
666 * can get TXE parity errors due to speculative reads to the PIO buffers,
667 * and this, due to a chip issue can result in (many) false parity error
668 * reports. So it's a debug print on those, and an info print on systems
669 * where the speculative reads don't occur.
670 */
671static void qib_6120_txe_recover(struct qib_devdata *dd)
672{
673 if (!qib_unordered_wc())
674 qib_devinfo(dd->pcidev,
675 "Recovering from TXE PIO parity error\n");
676}
677
678/* enable/disable chip from delivering interrupts */
679static void qib_6120_set_intr_state(struct qib_devdata *dd, u32 enable)
680{
681 if (enable) {
682 if (dd->flags & QIB_BADINTR)
683 return;
684 qib_write_kreg(dd, kr_intmask, ~0ULL);
685 /* force re-interrupt of any pending interrupts. */
686 qib_write_kreg(dd, kr_intclear, 0ULL);
687 } else
688 qib_write_kreg(dd, kr_intmask, 0ULL);
689}
690
691/*
692 * Try to cleanup as much as possible for anything that might have gone
693 * wrong while in freeze mode, such as pio buffers being written by user
694 * processes (causing armlaunch), send errors due to going into freeze mode,
695 * etc., and try to avoid causing extra interrupts while doing so.
696 * Forcibly update the in-memory pioavail register copies after cleanup
697 * because the chip won't do it while in freeze mode (the register values
698 * themselves are kept correct).
699 * Make sure that we don't lose any important interrupts by using the chip
700 * feature that says that writing 0 to a bit in *clear that is set in
701 * *status will cause an interrupt to be generated again (if allowed by
702 * the *mask value).
703 * This is in chip-specific code because of all of the register accesses,
704 * even though the details are similar on most chips
705 */
706static void qib_6120_clear_freeze(struct qib_devdata *dd)
707{
708 /* disable error interrupts, to avoid confusion */
709 qib_write_kreg(dd, kr_errmask, 0ULL);
710
Masahiro Yamadab8a14f32017-02-27 14:29:50 -0800711 /* also disable interrupts; errormask is sometimes overwritten */
Ralph Campbellf9315512010-05-23 21:44:54 -0700712 qib_6120_set_intr_state(dd, 0);
713
714 qib_cancel_sends(dd->pport);
715
716 /* clear the freeze, and be sure chip saw it */
717 qib_write_kreg(dd, kr_control, dd->control);
718 qib_read_kreg32(dd, kr_scratch);
719
720 /* force in-memory update now we are out of freeze */
721 qib_force_pio_avail_update(dd);
722
723 /*
724 * force new interrupt if any hwerr, error or interrupt bits are
725 * still set, and clear "safe" send packet errors related to freeze
726 * and cancelling sends. Re-enable error interrupts before possible
727 * force of re-interrupt on pending interrupts.
728 */
729 qib_write_kreg(dd, kr_hwerrclear, 0ULL);
730 qib_write_kreg(dd, kr_errclear, E_SPKT_ERRS_IGNORE);
731 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
732 qib_6120_set_intr_state(dd, 1);
733}
734
735/**
736 * qib_handle_6120_hwerrors - display hardware errors.
737 * @dd: the qlogic_ib device
738 * @msg: the output buffer
739 * @msgl: the size of the output buffer
740 *
741 * Use same msg buffer as regular errors to avoid excessive stack
742 * use. Most hardware errors are catastrophic, but for right now,
743 * we'll print them and continue. Reuse the same message buffer as
744 * handle_6120_errors() to avoid excessive stack usage.
745 */
746static void qib_handle_6120_hwerrors(struct qib_devdata *dd, char *msg,
747 size_t msgl)
748{
749 u64 hwerrs;
750 u32 bits, ctrl;
751 int isfatal = 0;
752 char *bitsmsg;
753 int log_idx;
754
755 hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
756 if (!hwerrs)
757 return;
758 if (hwerrs == ~0ULL) {
Mike Marciniszyn7fac3302012-07-19 13:04:25 +0000759 qib_dev_err(dd,
760 "Read of hardware error status failed (all bits set); ignoring\n");
Ralph Campbellf9315512010-05-23 21:44:54 -0700761 return;
762 }
763 qib_stats.sps_hwerrs++;
764
765 /* Always clear the error status register, except MEMBISTFAIL,
766 * regardless of whether we continue or stop using the chip.
767 * We want that set so we know it failed, even across driver reload.
768 * We'll still ignore it in the hwerrmask. We do this partly for
769 * diagnostics, but also for support */
770 qib_write_kreg(dd, kr_hwerrclear,
771 hwerrs & ~HWE_MASK(PowerOnBISTFailed));
772
773 hwerrs &= dd->cspec->hwerrmask;
774
775 /* We log some errors to EEPROM, check if we have any of those. */
776 for (log_idx = 0; log_idx < QIB_EEP_LOG_CNT; ++log_idx)
777 if (hwerrs & dd->eep_st_masks[log_idx].hwerrs_to_log)
778 qib_inc_eeprom_err(dd, log_idx, 1);
779
780 /*
781 * Make sure we get this much out, unless told to be quiet,
782 * or it's occurred within the last 5 seconds.
783 */
784 if (hwerrs & ~(TXE_PIO_PARITY | RXEMEMPARITYERR_EAGERTID))
Mike Marciniszyn7fac3302012-07-19 13:04:25 +0000785 qib_devinfo(dd->pcidev,
786 "Hardware error: hwerr=0x%llx (cleared)\n",
787 (unsigned long long) hwerrs);
Ralph Campbellf9315512010-05-23 21:44:54 -0700788
789 if (hwerrs & ~IB_HWE_BITSEXTANT)
Mike Marciniszyn7fac3302012-07-19 13:04:25 +0000790 qib_dev_err(dd,
791 "hwerror interrupt with unknown errors %llx set\n",
792 (unsigned long long)(hwerrs & ~IB_HWE_BITSEXTANT));
Ralph Campbellf9315512010-05-23 21:44:54 -0700793
794 ctrl = qib_read_kreg32(dd, kr_control);
795 if ((ctrl & QLOGIC_IB_C_FREEZEMODE) && !dd->diag_client) {
796 /*
797 * Parity errors in send memory are recoverable,
798 * just cancel the send (if indicated in * sendbuffererror),
799 * count the occurrence, unfreeze (if no other handled
800 * hardware error bits are set), and continue. They can
801 * occur if a processor speculative read is done to the PIO
802 * buffer while we are sending a packet, for example.
803 */
804 if (hwerrs & TXE_PIO_PARITY) {
805 qib_6120_txe_recover(dd);
806 hwerrs &= ~TXE_PIO_PARITY;
807 }
808
809 if (!hwerrs) {
810 static u32 freeze_cnt;
811
812 freeze_cnt++;
813 qib_6120_clear_freeze(dd);
814 } else
815 isfatal = 1;
816 }
817
818 *msg = '\0';
819
820 if (hwerrs & HWE_MASK(PowerOnBISTFailed)) {
821 isfatal = 1;
Mike Marciniszyn7fac3302012-07-19 13:04:25 +0000822 strlcat(msg,
823 "[Memory BIST test failed, InfiniPath hardware unusable]",
824 msgl);
Ralph Campbellf9315512010-05-23 21:44:54 -0700825 /* ignore from now on, so disable until driver reloaded */
826 dd->cspec->hwerrmask &= ~HWE_MASK(PowerOnBISTFailed);
827 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
828 }
829
830 qib_format_hwerrors(hwerrs, qib_6120_hwerror_msgs,
831 ARRAY_SIZE(qib_6120_hwerror_msgs), msg, msgl);
832
833 bitsmsg = dd->cspec->bitsmsgbuf;
834 if (hwerrs & (QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK <<
835 QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT)) {
836 bits = (u32) ((hwerrs >>
837 QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT) &
838 QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK);
Mike Marciniszyn041af0b2015-01-16 10:50:32 -0500839 snprintf(bitsmsg, sizeof(dd->cspec->bitsmsgbuf),
Ralph Campbellf9315512010-05-23 21:44:54 -0700840 "[PCIe Mem Parity Errs %x] ", bits);
841 strlcat(msg, bitsmsg, msgl);
842 }
843
844 if (hwerrs & _QIB_PLL_FAIL) {
845 isfatal = 1;
Mike Marciniszyn041af0b2015-01-16 10:50:32 -0500846 snprintf(bitsmsg, sizeof(dd->cspec->bitsmsgbuf),
Ralph Campbellf9315512010-05-23 21:44:54 -0700847 "[PLL failed (%llx), InfiniPath hardware unusable]",
848 (unsigned long long) hwerrs & _QIB_PLL_FAIL);
849 strlcat(msg, bitsmsg, msgl);
850 /* ignore from now on, so disable until driver reloaded */
851 dd->cspec->hwerrmask &= ~(hwerrs & _QIB_PLL_FAIL);
852 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
853 }
854
855 if (hwerrs & QLOGIC_IB_HWE_SERDESPLLFAILED) {
856 /*
857 * If it occurs, it is left masked since the external
858 * interface is unused
859 */
860 dd->cspec->hwerrmask &= ~QLOGIC_IB_HWE_SERDESPLLFAILED;
861 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
862 }
863
864 if (hwerrs)
865 /*
866 * if any set that we aren't ignoring; only
867 * make the complaint once, in case it's stuck
868 * or recurring, and we get here multiple
869 * times.
870 */
871 qib_dev_err(dd, "%s hardware error\n", msg);
872 else
873 *msg = 0; /* recovered from all of them */
874
875 if (isfatal && !dd->diag_client) {
Mike Marciniszyn7fac3302012-07-19 13:04:25 +0000876 qib_dev_err(dd,
877 "Fatal Hardware Error, no longer usable, SN %.16s\n",
878 dd->serial);
Ralph Campbellf9315512010-05-23 21:44:54 -0700879 /*
880 * for /sys status file and user programs to print; if no
881 * trailing brace is copied, we'll know it was truncated.
882 */
883 if (dd->freezemsg)
884 snprintf(dd->freezemsg, dd->freezelen,
885 "{%s}", msg);
886 qib_disable_after_error(dd);
887 }
888}
889
890/*
891 * Decode the error status into strings, deciding whether to always
892 * print * it or not depending on "normal packet errors" vs everything
893 * else. Return 1 if "real" errors, otherwise 0 if only packet
894 * errors, so caller can decide what to print with the string.
895 */
896static int qib_decode_6120_err(struct qib_devdata *dd, char *buf, size_t blen,
897 u64 err)
898{
899 int iserr = 1;
900
901 *buf = '\0';
902 if (err & QLOGIC_IB_E_PKTERRS) {
903 if (!(err & ~QLOGIC_IB_E_PKTERRS))
904 iserr = 0;
905 if ((err & ERR_MASK(RcvICRCErr)) &&
906 !(err&(ERR_MASK(RcvVCRCErr)|ERR_MASK(RcvEBPErr))))
907 strlcat(buf, "CRC ", blen);
908 if (!iserr)
909 goto done;
910 }
911 if (err & ERR_MASK(RcvHdrLenErr))
912 strlcat(buf, "rhdrlen ", blen);
913 if (err & ERR_MASK(RcvBadTidErr))
914 strlcat(buf, "rbadtid ", blen);
915 if (err & ERR_MASK(RcvBadVersionErr))
916 strlcat(buf, "rbadversion ", blen);
917 if (err & ERR_MASK(RcvHdrErr))
918 strlcat(buf, "rhdr ", blen);
919 if (err & ERR_MASK(RcvLongPktLenErr))
920 strlcat(buf, "rlongpktlen ", blen);
921 if (err & ERR_MASK(RcvMaxPktLenErr))
922 strlcat(buf, "rmaxpktlen ", blen);
923 if (err & ERR_MASK(RcvMinPktLenErr))
924 strlcat(buf, "rminpktlen ", blen);
925 if (err & ERR_MASK(SendMinPktLenErr))
926 strlcat(buf, "sminpktlen ", blen);
927 if (err & ERR_MASK(RcvFormatErr))
928 strlcat(buf, "rformaterr ", blen);
929 if (err & ERR_MASK(RcvUnsupportedVLErr))
930 strlcat(buf, "runsupvl ", blen);
931 if (err & ERR_MASK(RcvUnexpectedCharErr))
932 strlcat(buf, "runexpchar ", blen);
933 if (err & ERR_MASK(RcvIBFlowErr))
934 strlcat(buf, "ribflow ", blen);
935 if (err & ERR_MASK(SendUnderRunErr))
936 strlcat(buf, "sunderrun ", blen);
937 if (err & ERR_MASK(SendPioArmLaunchErr))
938 strlcat(buf, "spioarmlaunch ", blen);
939 if (err & ERR_MASK(SendUnexpectedPktNumErr))
940 strlcat(buf, "sunexperrpktnum ", blen);
941 if (err & ERR_MASK(SendDroppedSmpPktErr))
942 strlcat(buf, "sdroppedsmppkt ", blen);
943 if (err & ERR_MASK(SendMaxPktLenErr))
944 strlcat(buf, "smaxpktlen ", blen);
945 if (err & ERR_MASK(SendUnsupportedVLErr))
946 strlcat(buf, "sunsupVL ", blen);
947 if (err & ERR_MASK(InvalidAddrErr))
948 strlcat(buf, "invalidaddr ", blen);
949 if (err & ERR_MASK(RcvEgrFullErr))
950 strlcat(buf, "rcvegrfull ", blen);
951 if (err & ERR_MASK(RcvHdrFullErr))
952 strlcat(buf, "rcvhdrfull ", blen);
953 if (err & ERR_MASK(IBStatusChanged))
954 strlcat(buf, "ibcstatuschg ", blen);
955 if (err & ERR_MASK(RcvIBLostLinkErr))
956 strlcat(buf, "riblostlink ", blen);
957 if (err & ERR_MASK(HardwareErr))
958 strlcat(buf, "hardware ", blen);
959 if (err & ERR_MASK(ResetNegated))
960 strlcat(buf, "reset ", blen);
961done:
962 return iserr;
963}
964
965/*
966 * Called when we might have an error that is specific to a particular
967 * PIO buffer, and may need to cancel that buffer, so it can be re-used.
968 */
969static void qib_disarm_6120_senderrbufs(struct qib_pportdata *ppd)
970{
971 unsigned long sbuf[2];
972 struct qib_devdata *dd = ppd->dd;
973
974 /*
975 * It's possible that sendbuffererror could have bits set; might
976 * have already done this as a result of hardware error handling.
977 */
978 sbuf[0] = qib_read_kreg64(dd, kr_sendbuffererror);
979 sbuf[1] = qib_read_kreg64(dd, kr_sendbuffererror + 1);
980
981 if (sbuf[0] || sbuf[1])
982 qib_disarm_piobufs_set(dd, sbuf,
983 dd->piobcnt2k + dd->piobcnt4k);
984}
985
986static int chk_6120_linkrecovery(struct qib_devdata *dd, u64 ibcs)
987{
988 int ret = 1;
989 u32 ibstate = qib_6120_iblink_state(ibcs);
990 u32 linkrecov = read_6120_creg32(dd, cr_iblinkerrrecov);
991
992 if (linkrecov != dd->cspec->lastlinkrecov) {
993 /* and no more until active again */
994 dd->cspec->lastlinkrecov = 0;
995 qib_set_linkstate(dd->pport, QIB_IB_LINKDOWN);
996 ret = 0;
997 }
998 if (ibstate == IB_PORT_ACTIVE)
999 dd->cspec->lastlinkrecov =
1000 read_6120_creg32(dd, cr_iblinkerrrecov);
1001 return ret;
1002}
1003
1004static void handle_6120_errors(struct qib_devdata *dd, u64 errs)
1005{
1006 char *msg;
1007 u64 ignore_this_time = 0;
1008 u64 iserr = 0;
1009 int log_idx;
1010 struct qib_pportdata *ppd = dd->pport;
1011 u64 mask;
1012
1013 /* don't report errors that are masked */
1014 errs &= dd->cspec->errormask;
1015 msg = dd->cspec->emsgbuf;
1016
1017 /* do these first, they are most important */
1018 if (errs & ERR_MASK(HardwareErr))
Mike Marciniszyn041af0b2015-01-16 10:50:32 -05001019 qib_handle_6120_hwerrors(dd, msg, sizeof(dd->cspec->emsgbuf));
Ralph Campbellf9315512010-05-23 21:44:54 -07001020 else
1021 for (log_idx = 0; log_idx < QIB_EEP_LOG_CNT; ++log_idx)
1022 if (errs & dd->eep_st_masks[log_idx].errs_to_log)
1023 qib_inc_eeprom_err(dd, log_idx, 1);
1024
1025 if (errs & ~IB_E_BITSEXTANT)
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001026 qib_dev_err(dd,
1027 "error interrupt with unknown errors %llx set\n",
1028 (unsigned long long) (errs & ~IB_E_BITSEXTANT));
Ralph Campbellf9315512010-05-23 21:44:54 -07001029
1030 if (errs & E_SUM_ERRS) {
1031 qib_disarm_6120_senderrbufs(ppd);
1032 if ((errs & E_SUM_LINK_PKTERRS) &&
1033 !(ppd->lflags & QIBL_LINKACTIVE)) {
1034 /*
1035 * This can happen when trying to bring the link
1036 * up, but the IB link changes state at the "wrong"
1037 * time. The IB logic then complains that the packet
1038 * isn't valid. We don't want to confuse people, so
1039 * we just don't print them, except at debug
1040 */
1041 ignore_this_time = errs & E_SUM_LINK_PKTERRS;
1042 }
1043 } else if ((errs & E_SUM_LINK_PKTERRS) &&
1044 !(ppd->lflags & QIBL_LINKACTIVE)) {
1045 /*
1046 * This can happen when SMA is trying to bring the link
1047 * up, but the IB link changes state at the "wrong" time.
1048 * The IB logic then complains that the packet isn't
1049 * valid. We don't want to confuse people, so we just
1050 * don't print them, except at debug
1051 */
1052 ignore_this_time = errs & E_SUM_LINK_PKTERRS;
1053 }
1054
1055 qib_write_kreg(dd, kr_errclear, errs);
1056
1057 errs &= ~ignore_this_time;
1058 if (!errs)
1059 goto done;
1060
1061 /*
1062 * The ones we mask off are handled specially below
1063 * or above.
1064 */
1065 mask = ERR_MASK(IBStatusChanged) | ERR_MASK(RcvEgrFullErr) |
1066 ERR_MASK(RcvHdrFullErr) | ERR_MASK(HardwareErr);
Mike Marciniszyn041af0b2015-01-16 10:50:32 -05001067 qib_decode_6120_err(dd, msg, sizeof(dd->cspec->emsgbuf), errs & ~mask);
Ralph Campbellf9315512010-05-23 21:44:54 -07001068
1069 if (errs & E_SUM_PKTERRS)
1070 qib_stats.sps_rcverrs++;
1071 if (errs & E_SUM_ERRS)
1072 qib_stats.sps_txerrs++;
1073
1074 iserr = errs & ~(E_SUM_PKTERRS | QLOGIC_IB_E_PKTERRS);
1075
1076 if (errs & ERR_MASK(IBStatusChanged)) {
1077 u64 ibcs = qib_read_kreg64(dd, kr_ibcstatus);
1078 u32 ibstate = qib_6120_iblink_state(ibcs);
1079 int handle = 1;
1080
1081 if (ibstate != IB_PORT_INIT && dd->cspec->lastlinkrecov)
1082 handle = chk_6120_linkrecovery(dd, ibcs);
1083 /*
1084 * Since going into a recovery state causes the link state
1085 * to go down and since recovery is transitory, it is better
1086 * if we "miss" ever seeing the link training state go into
1087 * recovery (i.e., ignore this transition for link state
1088 * special handling purposes) without updating lastibcstat.
1089 */
1090 if (handle && qib_6120_phys_portstate(ibcs) ==
1091 IB_PHYSPORTSTATE_LINK_ERR_RECOVER)
1092 handle = 0;
1093 if (handle)
1094 qib_handle_e_ibstatuschanged(ppd, ibcs);
1095 }
1096
1097 if (errs & ERR_MASK(ResetNegated)) {
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001098 qib_dev_err(dd,
1099 "Got reset, requires re-init (unload and reload driver)\n");
Ralph Campbellf9315512010-05-23 21:44:54 -07001100 dd->flags &= ~QIB_INITTED; /* needs re-init */
1101 /* mark as having had error */
1102 *dd->devstatusp |= QIB_STATUS_HWERROR;
1103 *dd->pport->statusp &= ~QIB_STATUS_IB_CONF;
1104 }
1105
1106 if (*msg && iserr)
1107 qib_dev_porterr(dd, ppd->port, "%s error\n", msg);
1108
1109 if (ppd->state_wanted & ppd->lflags)
1110 wake_up_interruptible(&ppd->state_wait);
1111
1112 /*
1113 * If there were hdrq or egrfull errors, wake up any processes
1114 * waiting in poll. We used to try to check which contexts had
1115 * the overflow, but given the cost of that and the chip reads
1116 * to support it, it's better to just wake everybody up if we
1117 * get an overflow; waiters can poll again if it's not them.
1118 */
1119 if (errs & (ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr))) {
1120 qib_handle_urcv(dd, ~0U);
1121 if (errs & ERR_MASK(RcvEgrFullErr))
1122 qib_stats.sps_buffull++;
1123 else
1124 qib_stats.sps_hdrfull++;
1125 }
1126done:
1127 return;
1128}
1129
1130/**
1131 * qib_6120_init_hwerrors - enable hardware errors
1132 * @dd: the qlogic_ib device
1133 *
1134 * now that we have finished initializing everything that might reasonably
1135 * cause a hardware error, and cleared those errors bits as they occur,
1136 * we can enable hardware errors in the mask (potentially enabling
1137 * freeze mode), and enable hardware errors as errors (along with
1138 * everything else) in errormask
1139 */
1140static void qib_6120_init_hwerrors(struct qib_devdata *dd)
1141{
1142 u64 val;
1143 u64 extsval;
1144
1145 extsval = qib_read_kreg64(dd, kr_extstatus);
1146
1147 if (!(extsval & QLOGIC_IB_EXTS_MEMBIST_ENDTEST))
1148 qib_dev_err(dd, "MemBIST did not complete!\n");
1149
1150 /* init so all hwerrors interrupt, and enter freeze, ajdust below */
1151 val = ~0ULL;
1152 if (dd->minrev < 2) {
1153 /*
1154 * Avoid problem with internal interface bus parity
1155 * checking. Fixed in Rev2.
1156 */
1157 val &= ~QLOGIC_IB_HWE_PCIEBUSPARITYRADM;
1158 }
1159 /* avoid some intel cpu's speculative read freeze mode issue */
1160 val &= ~TXEMEMPARITYERR_PIOBUF;
1161
1162 dd->cspec->hwerrmask = val;
1163
1164 qib_write_kreg(dd, kr_hwerrclear, ~HWE_MASK(PowerOnBISTFailed));
1165 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
1166
1167 /* clear all */
1168 qib_write_kreg(dd, kr_errclear, ~0ULL);
1169 /* enable errors that are masked, at least this first time. */
1170 qib_write_kreg(dd, kr_errmask, ~0ULL);
1171 dd->cspec->errormask = qib_read_kreg64(dd, kr_errmask);
1172 /* clear any interrupts up to this point (ints still not enabled) */
1173 qib_write_kreg(dd, kr_intclear, ~0ULL);
1174
1175 qib_write_kreg(dd, kr_rcvbthqp,
1176 dd->qpn_mask << (QIB_6120_RcvBTHQP_BTHQP_Mask_LSB - 1) |
1177 QIB_KD_QP);
1178}
1179
1180/*
1181 * Disable and enable the armlaunch error. Used for PIO bandwidth testing
1182 * on chips that are count-based, rather than trigger-based. There is no
1183 * reference counting, but that's also fine, given the intended use.
1184 * Only chip-specific because it's all register accesses
1185 */
1186static void qib_set_6120_armlaunch(struct qib_devdata *dd, u32 enable)
1187{
1188 if (enable) {
1189 qib_write_kreg(dd, kr_errclear,
1190 ERR_MASK(SendPioArmLaunchErr));
1191 dd->cspec->errormask |= ERR_MASK(SendPioArmLaunchErr);
1192 } else
1193 dd->cspec->errormask &= ~ERR_MASK(SendPioArmLaunchErr);
1194 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
1195}
1196
1197/*
1198 * Formerly took parameter <which> in pre-shifted,
1199 * pre-merged form with LinkCmd and LinkInitCmd
1200 * together, and assuming the zero was NOP.
1201 */
1202static void qib_set_ib_6120_lstate(struct qib_pportdata *ppd, u16 linkcmd,
1203 u16 linitcmd)
1204{
1205 u64 mod_wd;
1206 struct qib_devdata *dd = ppd->dd;
1207 unsigned long flags;
1208
1209 if (linitcmd == QLOGIC_IB_IBCC_LINKINITCMD_DISABLE) {
1210 /*
1211 * If we are told to disable, note that so link-recovery
1212 * code does not attempt to bring us back up.
1213 */
1214 spin_lock_irqsave(&ppd->lflags_lock, flags);
1215 ppd->lflags |= QIBL_IB_LINK_DISABLED;
1216 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
1217 } else if (linitcmd || linkcmd == QLOGIC_IB_IBCC_LINKCMD_DOWN) {
1218 /*
1219 * Any other linkinitcmd will lead to LINKDOWN and then
1220 * to INIT (if all is well), so clear flag to let
1221 * link-recovery code attempt to bring us back up.
1222 */
1223 spin_lock_irqsave(&ppd->lflags_lock, flags);
1224 ppd->lflags &= ~QIBL_IB_LINK_DISABLED;
1225 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
1226 }
1227
1228 mod_wd = (linkcmd << QLOGIC_IB_IBCC_LINKCMD_SHIFT) |
1229 (linitcmd << QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
1230
1231 qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl | mod_wd);
1232 /* write to chip to prevent back-to-back writes of control reg */
1233 qib_write_kreg(dd, kr_scratch, 0);
1234}
1235
1236/**
1237 * qib_6120_bringup_serdes - bring up the serdes
1238 * @dd: the qlogic_ib device
1239 */
1240static int qib_6120_bringup_serdes(struct qib_pportdata *ppd)
1241{
1242 struct qib_devdata *dd = ppd->dd;
1243 u64 val, config1, prev_val, hwstat, ibc;
1244
1245 /* Put IBC in reset, sends disabled */
1246 dd->control &= ~QLOGIC_IB_C_LINKENABLE;
1247 qib_write_kreg(dd, kr_control, 0ULL);
1248
1249 dd->cspec->ibdeltainprog = 1;
1250 dd->cspec->ibsymsnap = read_6120_creg32(dd, cr_ibsymbolerr);
1251 dd->cspec->iblnkerrsnap = read_6120_creg32(dd, cr_iblinkerrrecov);
1252
1253 /* flowcontrolwatermark is in units of KBytes */
1254 ibc = 0x5ULL << SYM_LSB(IBCCtrl, FlowCtrlWaterMark);
1255 /*
1256 * How often flowctrl sent. More or less in usecs; balance against
1257 * watermark value, so that in theory senders always get a flow
1258 * control update in time to not let the IB link go idle.
1259 */
1260 ibc |= 0x3ULL << SYM_LSB(IBCCtrl, FlowCtrlPeriod);
1261 /* max error tolerance */
1262 dd->cspec->lli_thresh = 0xf;
1263 ibc |= (u64) dd->cspec->lli_thresh << SYM_LSB(IBCCtrl, PhyerrThreshold);
1264 /* use "real" buffer space for */
1265 ibc |= 4ULL << SYM_LSB(IBCCtrl, CreditScale);
1266 /* IB credit flow control. */
1267 ibc |= 0xfULL << SYM_LSB(IBCCtrl, OverrunThreshold);
1268 /*
1269 * set initial max size pkt IBC will send, including ICRC; it's the
1270 * PIO buffer size in dwords, less 1; also see qib_set_mtu()
1271 */
1272 ibc |= ((u64)(ppd->ibmaxlen >> 2) + 1) << SYM_LSB(IBCCtrl, MaxPktLen);
1273 dd->cspec->ibcctrl = ibc; /* without linkcmd or linkinitcmd! */
1274
1275 /* initially come up waiting for TS1, without sending anything. */
1276 val = dd->cspec->ibcctrl | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
1277 QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
1278 qib_write_kreg(dd, kr_ibcctrl, val);
1279
1280 val = qib_read_kreg64(dd, kr_serdes_cfg0);
1281 config1 = qib_read_kreg64(dd, kr_serdes_cfg1);
1282
1283 /*
1284 * Force reset on, also set rxdetect enable. Must do before reading
1285 * serdesstatus at least for simulation, or some of the bits in
1286 * serdes status will come back as undefined and cause simulation
1287 * failures
1288 */
1289 val |= SYM_MASK(SerdesCfg0, ResetPLL) |
1290 SYM_MASK(SerdesCfg0, RxDetEnX) |
1291 (SYM_MASK(SerdesCfg0, L1PwrDnA) |
1292 SYM_MASK(SerdesCfg0, L1PwrDnB) |
1293 SYM_MASK(SerdesCfg0, L1PwrDnC) |
1294 SYM_MASK(SerdesCfg0, L1PwrDnD));
1295 qib_write_kreg(dd, kr_serdes_cfg0, val);
1296 /* be sure chip saw it */
1297 qib_read_kreg64(dd, kr_scratch);
1298 udelay(5); /* need pll reset set at least for a bit */
1299 /*
1300 * after PLL is reset, set the per-lane Resets and TxIdle and
1301 * clear the PLL reset and rxdetect (to get falling edge).
1302 * Leave L1PWR bits set (permanently)
1303 */
1304 val &= ~(SYM_MASK(SerdesCfg0, RxDetEnX) |
1305 SYM_MASK(SerdesCfg0, ResetPLL) |
1306 (SYM_MASK(SerdesCfg0, L1PwrDnA) |
1307 SYM_MASK(SerdesCfg0, L1PwrDnB) |
1308 SYM_MASK(SerdesCfg0, L1PwrDnC) |
1309 SYM_MASK(SerdesCfg0, L1PwrDnD)));
1310 val |= (SYM_MASK(SerdesCfg0, ResetA) |
1311 SYM_MASK(SerdesCfg0, ResetB) |
1312 SYM_MASK(SerdesCfg0, ResetC) |
1313 SYM_MASK(SerdesCfg0, ResetD)) |
1314 SYM_MASK(SerdesCfg0, TxIdeEnX);
1315 qib_write_kreg(dd, kr_serdes_cfg0, val);
1316 /* be sure chip saw it */
1317 (void) qib_read_kreg64(dd, kr_scratch);
1318 /* need PLL reset clear for at least 11 usec before lane
1319 * resets cleared; give it a few more to be sure */
1320 udelay(15);
1321 val &= ~((SYM_MASK(SerdesCfg0, ResetA) |
1322 SYM_MASK(SerdesCfg0, ResetB) |
1323 SYM_MASK(SerdesCfg0, ResetC) |
1324 SYM_MASK(SerdesCfg0, ResetD)) |
1325 SYM_MASK(SerdesCfg0, TxIdeEnX));
1326
1327 qib_write_kreg(dd, kr_serdes_cfg0, val);
1328 /* be sure chip saw it */
1329 (void) qib_read_kreg64(dd, kr_scratch);
1330
1331 val = qib_read_kreg64(dd, kr_xgxs_cfg);
1332 prev_val = val;
1333 if (val & QLOGIC_IB_XGXS_RESET)
1334 val &= ~QLOGIC_IB_XGXS_RESET;
1335 if (SYM_FIELD(val, XGXSCfg, polarity_inv) != ppd->rx_pol_inv) {
1336 /* need to compensate for Tx inversion in partner */
1337 val &= ~SYM_MASK(XGXSCfg, polarity_inv);
1338 val |= (u64)ppd->rx_pol_inv << SYM_LSB(XGXSCfg, polarity_inv);
1339 }
1340 if (val != prev_val)
1341 qib_write_kreg(dd, kr_xgxs_cfg, val);
1342
1343 val = qib_read_kreg64(dd, kr_serdes_cfg0);
1344
1345 /* clear current and de-emphasis bits */
1346 config1 &= ~0x0ffffffff00ULL;
1347 /* set current to 20ma */
1348 config1 |= 0x00000000000ULL;
1349 /* set de-emphasis to -5.68dB */
1350 config1 |= 0x0cccc000000ULL;
1351 qib_write_kreg(dd, kr_serdes_cfg1, config1);
1352
1353 /* base and port guid same for single port */
1354 ppd->guid = dd->base_guid;
1355
1356 /*
1357 * the process of setting and un-resetting the serdes normally
1358 * causes a serdes PLL error, so check for that and clear it
1359 * here. Also clearr hwerr bit in errstatus, but not others.
1360 */
1361 hwstat = qib_read_kreg64(dd, kr_hwerrstatus);
1362 if (hwstat) {
1363 /* should just have PLL, clear all set, in an case */
Ralph Campbell2d757a72010-06-17 23:14:04 +00001364 qib_write_kreg(dd, kr_hwerrclear, hwstat);
Ralph Campbellf9315512010-05-23 21:44:54 -07001365 qib_write_kreg(dd, kr_errclear, ERR_MASK(HardwareErr));
1366 }
1367
1368 dd->control |= QLOGIC_IB_C_LINKENABLE;
1369 dd->control &= ~QLOGIC_IB_C_FREEZEMODE;
1370 qib_write_kreg(dd, kr_control, dd->control);
1371
1372 return 0;
1373}
1374
1375/**
1376 * qib_6120_quiet_serdes - set serdes to txidle
1377 * @ppd: physical port of the qlogic_ib device
1378 * Called when driver is being unloaded
1379 */
1380static void qib_6120_quiet_serdes(struct qib_pportdata *ppd)
1381{
1382 struct qib_devdata *dd = ppd->dd;
1383 u64 val;
1384
1385 qib_set_ib_6120_lstate(ppd, 0, QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
1386
1387 /* disable IBC */
1388 dd->control &= ~QLOGIC_IB_C_LINKENABLE;
1389 qib_write_kreg(dd, kr_control,
1390 dd->control | QLOGIC_IB_C_FREEZEMODE);
1391
1392 if (dd->cspec->ibsymdelta || dd->cspec->iblnkerrdelta ||
1393 dd->cspec->ibdeltainprog) {
1394 u64 diagc;
1395
1396 /* enable counter writes */
1397 diagc = qib_read_kreg64(dd, kr_hwdiagctrl);
1398 qib_write_kreg(dd, kr_hwdiagctrl,
1399 diagc | SYM_MASK(HwDiagCtrl, CounterWrEnable));
1400
1401 if (dd->cspec->ibsymdelta || dd->cspec->ibdeltainprog) {
1402 val = read_6120_creg32(dd, cr_ibsymbolerr);
1403 if (dd->cspec->ibdeltainprog)
1404 val -= val - dd->cspec->ibsymsnap;
1405 val -= dd->cspec->ibsymdelta;
1406 write_6120_creg(dd, cr_ibsymbolerr, val);
1407 }
1408 if (dd->cspec->iblnkerrdelta || dd->cspec->ibdeltainprog) {
1409 val = read_6120_creg32(dd, cr_iblinkerrrecov);
1410 if (dd->cspec->ibdeltainprog)
1411 val -= val - dd->cspec->iblnkerrsnap;
1412 val -= dd->cspec->iblnkerrdelta;
1413 write_6120_creg(dd, cr_iblinkerrrecov, val);
1414 }
1415
1416 /* and disable counter writes */
1417 qib_write_kreg(dd, kr_hwdiagctrl, diagc);
1418 }
1419
1420 val = qib_read_kreg64(dd, kr_serdes_cfg0);
1421 val |= SYM_MASK(SerdesCfg0, TxIdeEnX);
1422 qib_write_kreg(dd, kr_serdes_cfg0, val);
1423}
1424
1425/**
1426 * qib_6120_setup_setextled - set the state of the two external LEDs
1427 * @dd: the qlogic_ib device
1428 * @on: whether the link is up or not
1429 *
1430 * The exact combo of LEDs if on is true is determined by looking
1431 * at the ibcstatus.
1432
1433 * These LEDs indicate the physical and logical state of IB link.
1434 * For this chip (at least with recommended board pinouts), LED1
1435 * is Yellow (logical state) and LED2 is Green (physical state),
1436 *
1437 * Note: We try to match the Mellanox HCA LED behavior as best
1438 * we can. Green indicates physical link state is OK (something is
1439 * plugged in, and we can train).
1440 * Amber indicates the link is logically up (ACTIVE).
1441 * Mellanox further blinks the amber LED to indicate data packet
1442 * activity, but we have no hardware support for that, so it would
1443 * require waking up every 10-20 msecs and checking the counters
1444 * on the chip, and then turning the LED off if appropriate. That's
1445 * visible overhead, so not something we will do.
1446 *
1447 */
1448static void qib_6120_setup_setextled(struct qib_pportdata *ppd, u32 on)
1449{
1450 u64 extctl, val, lst, ltst;
1451 unsigned long flags;
1452 struct qib_devdata *dd = ppd->dd;
1453
1454 /*
1455 * The diags use the LED to indicate diag info, so we leave
1456 * the external LED alone when the diags are running.
1457 */
1458 if (dd->diag_client)
1459 return;
1460
1461 /* Allow override of LED display for, e.g. Locating system in rack */
1462 if (ppd->led_override) {
1463 ltst = (ppd->led_override & QIB_LED_PHYS) ?
1464 IB_PHYSPORTSTATE_LINKUP : IB_PHYSPORTSTATE_DISABLED,
1465 lst = (ppd->led_override & QIB_LED_LOG) ?
1466 IB_PORT_ACTIVE : IB_PORT_DOWN;
1467 } else if (on) {
1468 val = qib_read_kreg64(dd, kr_ibcstatus);
1469 ltst = qib_6120_phys_portstate(val);
1470 lst = qib_6120_iblink_state(val);
1471 } else {
1472 ltst = 0;
1473 lst = 0;
1474 }
1475
1476 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
1477 extctl = dd->cspec->extctrl & ~(SYM_MASK(EXTCtrl, LEDPriPortGreenOn) |
1478 SYM_MASK(EXTCtrl, LEDPriPortYellowOn));
1479
1480 if (ltst == IB_PHYSPORTSTATE_LINKUP)
1481 extctl |= SYM_MASK(EXTCtrl, LEDPriPortYellowOn);
1482 if (lst == IB_PORT_ACTIVE)
1483 extctl |= SYM_MASK(EXTCtrl, LEDPriPortGreenOn);
1484 dd->cspec->extctrl = extctl;
1485 qib_write_kreg(dd, kr_extctrl, extctl);
1486 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
1487}
1488
1489static void qib_6120_free_irq(struct qib_devdata *dd)
1490{
1491 if (dd->cspec->irq) {
1492 free_irq(dd->cspec->irq, dd);
1493 dd->cspec->irq = 0;
1494 }
1495 qib_nomsi(dd);
1496}
1497
1498/**
1499 * qib_6120_setup_cleanup - clean up any per-chip chip-specific stuff
1500 * @dd: the qlogic_ib device
1501 *
1502 * This is called during driver unload.
1503*/
1504static void qib_6120_setup_cleanup(struct qib_devdata *dd)
1505{
1506 qib_6120_free_irq(dd);
1507 kfree(dd->cspec->cntrs);
1508 kfree(dd->cspec->portcntrs);
1509 if (dd->cspec->dummy_hdrq) {
1510 dma_free_coherent(&dd->pcidev->dev,
1511 ALIGN(dd->rcvhdrcnt *
1512 dd->rcvhdrentsize *
1513 sizeof(u32), PAGE_SIZE),
1514 dd->cspec->dummy_hdrq,
1515 dd->cspec->dummy_hdrq_phys);
1516 dd->cspec->dummy_hdrq = NULL;
1517 }
1518}
1519
1520static void qib_wantpiobuf_6120_intr(struct qib_devdata *dd, u32 needint)
1521{
1522 unsigned long flags;
1523
1524 spin_lock_irqsave(&dd->sendctrl_lock, flags);
1525 if (needint)
1526 dd->sendctrl |= SYM_MASK(SendCtrl, PIOIntBufAvail);
1527 else
1528 dd->sendctrl &= ~SYM_MASK(SendCtrl, PIOIntBufAvail);
1529 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
1530 qib_write_kreg(dd, kr_scratch, 0ULL);
1531 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
1532}
1533
1534/*
1535 * handle errors and unusual events first, separate function
1536 * to improve cache hits for fast path interrupt handling
1537 */
1538static noinline void unlikely_6120_intr(struct qib_devdata *dd, u64 istat)
1539{
1540 if (unlikely(istat & ~QLOGIC_IB_I_BITSEXTANT))
1541 qib_dev_err(dd, "interrupt with unknown interrupts %Lx set\n",
1542 istat & ~QLOGIC_IB_I_BITSEXTANT);
1543
1544 if (istat & QLOGIC_IB_I_ERROR) {
1545 u64 estat = 0;
1546
1547 qib_stats.sps_errints++;
1548 estat = qib_read_kreg64(dd, kr_errstatus);
1549 if (!estat)
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001550 qib_devinfo(dd->pcidev,
1551 "error interrupt (%Lx), but no error bits set!\n",
1552 istat);
Ralph Campbellf9315512010-05-23 21:44:54 -07001553 handle_6120_errors(dd, estat);
1554 }
1555
1556 if (istat & QLOGIC_IB_I_GPIO) {
1557 u32 gpiostatus;
1558 u32 to_clear = 0;
1559
1560 /*
1561 * GPIO_3..5 on IBA6120 Rev2 chips indicate
1562 * errors that we need to count.
1563 */
1564 gpiostatus = qib_read_kreg32(dd, kr_gpio_status);
1565 /* First the error-counter case. */
1566 if (gpiostatus & GPIO_ERRINTR_MASK) {
1567 /* want to clear the bits we see asserted. */
1568 to_clear |= (gpiostatus & GPIO_ERRINTR_MASK);
1569
1570 /*
1571 * Count appropriately, clear bits out of our copy,
1572 * as they have been "handled".
1573 */
1574 if (gpiostatus & (1 << GPIO_RXUVL_BIT))
1575 dd->cspec->rxfc_unsupvl_errs++;
1576 if (gpiostatus & (1 << GPIO_OVRUN_BIT))
1577 dd->cspec->overrun_thresh_errs++;
1578 if (gpiostatus & (1 << GPIO_LLI_BIT))
1579 dd->cspec->lli_errs++;
1580 gpiostatus &= ~GPIO_ERRINTR_MASK;
1581 }
1582 if (gpiostatus) {
1583 /*
1584 * Some unexpected bits remain. If they could have
1585 * caused the interrupt, complain and clear.
1586 * To avoid repetition of this condition, also clear
1587 * the mask. It is almost certainly due to error.
1588 */
1589 const u32 mask = qib_read_kreg32(dd, kr_gpio_mask);
1590
1591 /*
1592 * Also check that the chip reflects our shadow,
1593 * and report issues, If they caused the interrupt.
1594 * we will suppress by refreshing from the shadow.
1595 */
1596 if (mask & gpiostatus) {
1597 to_clear |= (gpiostatus & mask);
1598 dd->cspec->gpio_mask &= ~(gpiostatus & mask);
1599 qib_write_kreg(dd, kr_gpio_mask,
1600 dd->cspec->gpio_mask);
1601 }
1602 }
1603 if (to_clear)
1604 qib_write_kreg(dd, kr_gpio_clear, (u64) to_clear);
1605 }
1606}
1607
1608static irqreturn_t qib_6120intr(int irq, void *data)
1609{
1610 struct qib_devdata *dd = data;
1611 irqreturn_t ret;
1612 u32 istat, ctxtrbits, rmask, crcs = 0;
1613 unsigned i;
1614
1615 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT) {
1616 /*
1617 * This return value is not great, but we do not want the
1618 * interrupt core code to remove our interrupt handler
1619 * because we don't appear to be handling an interrupt
1620 * during a chip reset.
1621 */
1622 ret = IRQ_HANDLED;
1623 goto bail;
1624 }
1625
1626 istat = qib_read_kreg32(dd, kr_intstatus);
1627
1628 if (unlikely(!istat)) {
1629 ret = IRQ_NONE; /* not our interrupt, or already handled */
1630 goto bail;
1631 }
1632 if (unlikely(istat == -1)) {
1633 qib_bad_intrstatus(dd);
1634 /* don't know if it was our interrupt or not */
1635 ret = IRQ_NONE;
1636 goto bail;
1637 }
1638
Mike Marciniszyn1ed88dd2014-03-07 08:40:49 -05001639 this_cpu_inc(*dd->int_counter);
Ralph Campbellf9315512010-05-23 21:44:54 -07001640
1641 if (unlikely(istat & (~QLOGIC_IB_I_BITSEXTANT |
1642 QLOGIC_IB_I_GPIO | QLOGIC_IB_I_ERROR)))
1643 unlikely_6120_intr(dd, istat);
1644
1645 /*
1646 * Clear the interrupt bits we found set, relatively early, so we
1647 * "know" know the chip will have seen this by the time we process
1648 * the queue, and will re-interrupt if necessary. The processor
1649 * itself won't take the interrupt again until we return.
1650 */
1651 qib_write_kreg(dd, kr_intclear, istat);
1652
1653 /*
1654 * Handle kernel receive queues before checking for pio buffers
1655 * available since receives can overflow; piobuf waiters can afford
1656 * a few extra cycles, since they were waiting anyway.
1657 */
1658 ctxtrbits = istat &
1659 ((QLOGIC_IB_I_RCVAVAIL_MASK << QLOGIC_IB_I_RCVAVAIL_SHIFT) |
1660 (QLOGIC_IB_I_RCVURG_MASK << QLOGIC_IB_I_RCVURG_SHIFT));
1661 if (ctxtrbits) {
1662 rmask = (1U << QLOGIC_IB_I_RCVAVAIL_SHIFT) |
1663 (1U << QLOGIC_IB_I_RCVURG_SHIFT);
1664 for (i = 0; i < dd->first_user_ctxt; i++) {
1665 if (ctxtrbits & rmask) {
1666 ctxtrbits &= ~rmask;
1667 crcs += qib_kreceive(dd->rcd[i],
1668 &dd->cspec->lli_counter,
1669 NULL);
1670 }
1671 rmask <<= 1;
1672 }
1673 if (crcs) {
1674 u32 cntr = dd->cspec->lli_counter;
Mike Marciniszynda12c1f2015-01-16 11:23:31 -05001675
Ralph Campbellf9315512010-05-23 21:44:54 -07001676 cntr += crcs;
1677 if (cntr) {
1678 if (cntr > dd->cspec->lli_thresh) {
1679 dd->cspec->lli_counter = 0;
1680 dd->cspec->lli_errs++;
1681 } else
1682 dd->cspec->lli_counter += cntr;
1683 }
1684 }
1685
1686
1687 if (ctxtrbits) {
1688 ctxtrbits =
1689 (ctxtrbits >> QLOGIC_IB_I_RCVAVAIL_SHIFT) |
1690 (ctxtrbits >> QLOGIC_IB_I_RCVURG_SHIFT);
1691 qib_handle_urcv(dd, ctxtrbits);
1692 }
1693 }
1694
1695 if ((istat & QLOGIC_IB_I_SPIOBUFAVAIL) && (dd->flags & QIB_INITTED))
1696 qib_ib_piobufavail(dd);
1697
1698 ret = IRQ_HANDLED;
1699bail:
1700 return ret;
1701}
1702
1703/*
1704 * Set up our chip-specific interrupt handler
1705 * The interrupt type has already been setup, so
1706 * we just need to do the registration and error checking.
1707 */
1708static void qib_setup_6120_interrupt(struct qib_devdata *dd)
1709{
1710 /*
1711 * If the chip supports added error indication via GPIO pins,
1712 * enable interrupts on those bits so the interrupt routine
1713 * can count the events. Also set flag so interrupt routine
1714 * can know they are expected.
1715 */
1716 if (SYM_FIELD(dd->revision, Revision_R,
1717 ChipRevMinor) > 1) {
1718 /* Rev2+ reports extra errors via internal GPIO pins */
1719 dd->cspec->gpio_mask |= GPIO_ERRINTR_MASK;
1720 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
1721 }
1722
1723 if (!dd->cspec->irq)
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001724 qib_dev_err(dd,
1725 "irq is 0, BIOS error? Interrupts won't work\n");
Ralph Campbellf9315512010-05-23 21:44:54 -07001726 else {
1727 int ret;
Mike Marciniszynda12c1f2015-01-16 11:23:31 -05001728
Ralph Campbellf9315512010-05-23 21:44:54 -07001729 ret = request_irq(dd->cspec->irq, qib_6120intr, 0,
1730 QIB_DRV_NAME, dd);
1731 if (ret)
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001732 qib_dev_err(dd,
1733 "Couldn't setup interrupt (irq=%d): %d\n",
1734 dd->cspec->irq, ret);
Ralph Campbellf9315512010-05-23 21:44:54 -07001735 }
1736}
1737
1738/**
1739 * pe_boardname - fill in the board name
1740 * @dd: the qlogic_ib device
1741 *
1742 * info is based on the board revision register
1743 */
1744static void pe_boardname(struct qib_devdata *dd)
1745{
Kamenee Arumugam3b716932017-08-21 18:26:26 -07001746 u32 boardid;
Ralph Campbellf9315512010-05-23 21:44:54 -07001747
1748 boardid = SYM_FIELD(dd->revision, Revision,
1749 BoardID);
1750
1751 switch (boardid) {
1752 case 2:
Kamenee Arumugam3b716932017-08-21 18:26:26 -07001753 dd->boardname = "InfiniPath_QLE7140";
Ralph Campbellf9315512010-05-23 21:44:54 -07001754 break;
1755 default:
1756 qib_dev_err(dd, "Unknown 6120 board with ID %u\n", boardid);
Kamenee Arumugam3b716932017-08-21 18:26:26 -07001757 dd->boardname = "Unknown_InfiniPath_6120";
Ralph Campbellf9315512010-05-23 21:44:54 -07001758 break;
1759 }
Ralph Campbellf9315512010-05-23 21:44:54 -07001760
1761 if (dd->majrev != 4 || !dd->minrev || dd->minrev > 2)
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001762 qib_dev_err(dd,
Kamenee Arumugam3b716932017-08-21 18:26:26 -07001763 "Unsupported InfiniPath hardware revision %u.%u!\n",
1764 dd->majrev, dd->minrev);
Ralph Campbellf9315512010-05-23 21:44:54 -07001765
1766 snprintf(dd->boardversion, sizeof(dd->boardversion),
1767 "ChipABI %u.%u, %s, InfiniPath%u %u.%u, SW Compat %u\n",
1768 QIB_CHIP_VERS_MAJ, QIB_CHIP_VERS_MIN, dd->boardname,
Kamenee Arumugam3b716932017-08-21 18:26:26 -07001769 (unsigned int)SYM_FIELD(dd->revision, Revision_R, Arch),
Ralph Campbellf9315512010-05-23 21:44:54 -07001770 dd->majrev, dd->minrev,
Kamenee Arumugam3b716932017-08-21 18:26:26 -07001771 (unsigned int)SYM_FIELD(dd->revision, Revision_R, SW));
Ralph Campbellf9315512010-05-23 21:44:54 -07001772}
1773
1774/*
1775 * This routine sleeps, so it can only be called from user context, not
1776 * from interrupt context. If we need interrupt context, we can split
1777 * it into two routines.
1778 */
1779static int qib_6120_setup_reset(struct qib_devdata *dd)
1780{
1781 u64 val;
1782 int i;
1783 int ret;
1784 u16 cmdval;
1785 u8 int_line, clinesz;
1786
1787 qib_pcie_getcmd(dd, &cmdval, &int_line, &clinesz);
1788
1789 /* Use ERROR so it shows up in logs, etc. */
1790 qib_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->unit);
1791
1792 /* no interrupts till re-initted */
1793 qib_6120_set_intr_state(dd, 0);
1794
1795 dd->cspec->ibdeltainprog = 0;
1796 dd->cspec->ibsymdelta = 0;
1797 dd->cspec->iblnkerrdelta = 0;
1798
1799 /*
1800 * Keep chip from being accessed until we are ready. Use
1801 * writeq() directly, to allow the write even though QIB_PRESENT
Lucas De Marchie9c54992011-04-26 23:28:26 -07001802 * isn't set.
Ralph Campbellf9315512010-05-23 21:44:54 -07001803 */
1804 dd->flags &= ~(QIB_INITTED | QIB_PRESENT);
Mike Marciniszyn1ed88dd2014-03-07 08:40:49 -05001805 /* so we check interrupts work again */
1806 dd->z_int_counter = qib_int_counter(dd);
Ralph Campbellf9315512010-05-23 21:44:54 -07001807 val = dd->control | QLOGIC_IB_C_RESET;
1808 writeq(val, &dd->kregbase[kr_control]);
1809 mb(); /* prevent compiler re-ordering around actual reset */
1810
1811 for (i = 1; i <= 5; i++) {
1812 /*
1813 * Allow MBIST, etc. to complete; longer on each retry.
1814 * We sometimes get machine checks from bus timeout if no
1815 * response, so for now, make it *really* long.
1816 */
1817 msleep(1000 + (1 + i) * 2000);
1818
1819 qib_pcie_reenable(dd, cmdval, int_line, clinesz);
1820
1821 /*
1822 * Use readq directly, so we don't need to mark it as PRESENT
1823 * until we get a successful indication that all is well.
1824 */
1825 val = readq(&dd->kregbase[kr_revision]);
1826 if (val == dd->revision) {
1827 dd->flags |= QIB_PRESENT; /* it's back */
1828 ret = qib_reinit_intr(dd);
1829 goto bail;
1830 }
1831 }
1832 ret = 0; /* failed */
1833
1834bail:
1835 if (ret) {
Michael J. Ruhl581d01a2017-06-09 16:00:06 -07001836 if (qib_pcie_params(dd, dd->lbus_width, NULL))
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001837 qib_dev_err(dd,
1838 "Reset failed to setup PCIe or interrupts; continuing anyway\n");
Ralph Campbellf9315512010-05-23 21:44:54 -07001839 /* clear the reset error, init error/hwerror mask */
1840 qib_6120_init_hwerrors(dd);
1841 /* for Rev2 error interrupts; nop for rev 1 */
1842 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
1843 /* clear the reset error, init error/hwerror mask */
1844 qib_6120_init_hwerrors(dd);
1845 }
1846 return ret;
1847}
1848
1849/**
1850 * qib_6120_put_tid - write a TID in chip
1851 * @dd: the qlogic_ib device
1852 * @tidptr: pointer to the expected TID (in chip) to update
1853 * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0)
1854 * for expected
1855 * @pa: physical address of in memory buffer; tidinvalid if freeing
1856 *
1857 * This exists as a separate routine to allow for special locking etc.
1858 * It's used for both the full cleanup on exit, as well as the normal
1859 * setup and teardown.
1860 */
1861static void qib_6120_put_tid(struct qib_devdata *dd, u64 __iomem *tidptr,
1862 u32 type, unsigned long pa)
1863{
1864 u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
1865 unsigned long flags;
1866 int tidx;
1867 spinlock_t *tidlockp; /* select appropriate spinlock */
1868
1869 if (!dd->kregbase)
1870 return;
1871
1872 if (pa != dd->tidinvalid) {
1873 if (pa & ((1U << 11) - 1)) {
1874 qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
1875 pa);
1876 return;
1877 }
1878 pa >>= 11;
1879 if (pa & ~QLOGIC_IB_RT_ADDR_MASK) {
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001880 qib_dev_err(dd,
1881 "Physical page address 0x%lx larger than supported\n",
1882 pa);
Ralph Campbellf9315512010-05-23 21:44:54 -07001883 return;
1884 }
1885
1886 if (type == RCVHQ_RCV_TYPE_EAGER)
1887 pa |= dd->tidtemplate;
1888 else /* for now, always full 4KB page */
1889 pa |= 2 << 29;
1890 }
1891
1892 /*
1893 * Avoid chip issue by writing the scratch register
1894 * before and after the TID, and with an io write barrier.
1895 * We use a spinlock around the writes, so they can't intermix
1896 * with other TID (eager or expected) writes (the chip problem
1897 * is triggered by back to back TID writes). Unfortunately, this
1898 * call can be done from interrupt level for the ctxt 0 eager TIDs,
1899 * so we have to use irqsave locks.
1900 */
1901 /*
1902 * Assumes tidptr always > egrtidbase
1903 * if type == RCVHQ_RCV_TYPE_EAGER.
1904 */
1905 tidx = tidptr - dd->egrtidbase;
1906
1907 tidlockp = (type == RCVHQ_RCV_TYPE_EAGER && tidx < dd->rcvhdrcnt)
1908 ? &dd->cspec->kernel_tid_lock : &dd->cspec->user_tid_lock;
1909 spin_lock_irqsave(tidlockp, flags);
1910 qib_write_kreg(dd, kr_scratch, 0xfeeddeaf);
1911 writel(pa, tidp32);
1912 qib_write_kreg(dd, kr_scratch, 0xdeadbeef);
1913 mmiowb();
1914 spin_unlock_irqrestore(tidlockp, flags);
1915}
1916
1917/**
1918 * qib_6120_put_tid_2 - write a TID in chip, Revision 2 or higher
1919 * @dd: the qlogic_ib device
1920 * @tidptr: pointer to the expected TID (in chip) to update
1921 * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0)
1922 * for expected
1923 * @pa: physical address of in memory buffer; tidinvalid if freeing
1924 *
1925 * This exists as a separate routine to allow for selection of the
1926 * appropriate "flavor". The static calls in cleanup just use the
1927 * revision-agnostic form, as they are not performance critical.
1928 */
1929static void qib_6120_put_tid_2(struct qib_devdata *dd, u64 __iomem *tidptr,
1930 u32 type, unsigned long pa)
1931{
1932 u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
1933 u32 tidx;
1934
1935 if (!dd->kregbase)
1936 return;
1937
1938 if (pa != dd->tidinvalid) {
1939 if (pa & ((1U << 11) - 1)) {
1940 qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
1941 pa);
1942 return;
1943 }
1944 pa >>= 11;
1945 if (pa & ~QLOGIC_IB_RT_ADDR_MASK) {
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001946 qib_dev_err(dd,
1947 "Physical page address 0x%lx larger than supported\n",
1948 pa);
Ralph Campbellf9315512010-05-23 21:44:54 -07001949 return;
1950 }
1951
1952 if (type == RCVHQ_RCV_TYPE_EAGER)
1953 pa |= dd->tidtemplate;
1954 else /* for now, always full 4KB page */
1955 pa |= 2 << 29;
1956 }
1957 tidx = tidptr - dd->egrtidbase;
1958 writel(pa, tidp32);
1959 mmiowb();
1960}
1961
1962
1963/**
1964 * qib_6120_clear_tids - clear all TID entries for a context, expected and eager
1965 * @dd: the qlogic_ib device
1966 * @ctxt: the context
1967 *
1968 * clear all TID entries for a context, expected and eager.
1969 * Used from qib_close(). On this chip, TIDs are only 32 bits,
1970 * not 64, but they are still on 64 bit boundaries, so tidbase
1971 * is declared as u64 * for the pointer math, even though we write 32 bits
1972 */
1973static void qib_6120_clear_tids(struct qib_devdata *dd,
1974 struct qib_ctxtdata *rcd)
1975{
1976 u64 __iomem *tidbase;
1977 unsigned long tidinv;
1978 u32 ctxt;
1979 int i;
1980
1981 if (!dd->kregbase || !rcd)
1982 return;
1983
1984 ctxt = rcd->ctxt;
1985
1986 tidinv = dd->tidinvalid;
1987 tidbase = (u64 __iomem *)
1988 ((char __iomem *)(dd->kregbase) +
1989 dd->rcvtidbase +
1990 ctxt * dd->rcvtidcnt * sizeof(*tidbase));
1991
1992 for (i = 0; i < dd->rcvtidcnt; i++)
1993 /* use func pointer because could be one of two funcs */
1994 dd->f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
1995 tidinv);
1996
1997 tidbase = (u64 __iomem *)
1998 ((char __iomem *)(dd->kregbase) +
1999 dd->rcvegrbase +
2000 rcd->rcvegr_tid_base * sizeof(*tidbase));
2001
2002 for (i = 0; i < rcd->rcvegrcnt; i++)
2003 /* use func pointer because could be one of two funcs */
2004 dd->f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
2005 tidinv);
2006}
2007
2008/**
2009 * qib_6120_tidtemplate - setup constants for TID updates
2010 * @dd: the qlogic_ib device
2011 *
2012 * We setup stuff that we use a lot, to avoid calculating each time
2013 */
2014static void qib_6120_tidtemplate(struct qib_devdata *dd)
2015{
2016 u32 egrsize = dd->rcvegrbufsize;
2017
2018 /*
2019 * For now, we always allocate 4KB buffers (at init) so we can
2020 * receive max size packets. We may want a module parameter to
2021 * specify 2KB or 4KB and/or make be per ctxt instead of per device
2022 * for those who want to reduce memory footprint. Note that the
2023 * rcvhdrentsize size must be large enough to hold the largest
2024 * IB header (currently 96 bytes) that we expect to handle (plus of
2025 * course the 2 dwords of RHF).
2026 */
2027 if (egrsize == 2048)
2028 dd->tidtemplate = 1U << 29;
2029 else if (egrsize == 4096)
2030 dd->tidtemplate = 2U << 29;
2031 dd->tidinvalid = 0;
2032}
2033
2034int __attribute__((weak)) qib_unordered_wc(void)
2035{
2036 return 0;
2037}
2038
2039/**
2040 * qib_6120_get_base_info - set chip-specific flags for user code
2041 * @rcd: the qlogic_ib ctxt
2042 * @kbase: qib_base_info pointer
2043 *
2044 * We set the PCIE flag because the lower bandwidth on PCIe vs
2045 * HyperTransport can affect some user packet algorithms.
2046 */
2047static int qib_6120_get_base_info(struct qib_ctxtdata *rcd,
2048 struct qib_base_info *kinfo)
2049{
2050 if (qib_unordered_wc())
2051 kinfo->spi_runtime_flags |= QIB_RUNTIME_FORCE_WC_ORDER;
2052
2053 kinfo->spi_runtime_flags |= QIB_RUNTIME_PCIE |
2054 QIB_RUNTIME_FORCE_PIOAVAIL | QIB_RUNTIME_PIO_REGSWAPPED;
2055 return 0;
2056}
2057
2058
2059static struct qib_message_header *
2060qib_6120_get_msgheader(struct qib_devdata *dd, __le32 *rhf_addr)
2061{
2062 return (struct qib_message_header *)
2063 &rhf_addr[sizeof(u64) / sizeof(u32)];
2064}
2065
2066static void qib_6120_config_ctxts(struct qib_devdata *dd)
2067{
2068 dd->ctxtcnt = qib_read_kreg32(dd, kr_portcnt);
2069 if (qib_n_krcv_queues > 1) {
2070 dd->first_user_ctxt = qib_n_krcv_queues * dd->num_pports;
2071 if (dd->first_user_ctxt > dd->ctxtcnt)
2072 dd->first_user_ctxt = dd->ctxtcnt;
2073 dd->qpn_mask = dd->first_user_ctxt <= 2 ? 2 : 6;
2074 } else
2075 dd->first_user_ctxt = dd->num_pports;
2076 dd->n_krcv_queues = dd->first_user_ctxt;
2077}
2078
2079static void qib_update_6120_usrhead(struct qib_ctxtdata *rcd, u64 hd,
Mike Marciniszyn19ede2e2011-01-10 17:42:21 -08002080 u32 updegr, u32 egrhd, u32 npkts)
Ralph Campbellf9315512010-05-23 21:44:54 -07002081{
Ralph Campbellf9315512010-05-23 21:44:54 -07002082 if (updegr)
2083 qib_write_ureg(rcd->dd, ur_rcvegrindexhead, egrhd, rcd->ctxt);
Ram Vepaeddfb672011-12-23 08:01:43 -05002084 mmiowb();
2085 qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
2086 mmiowb();
Ralph Campbellf9315512010-05-23 21:44:54 -07002087}
2088
2089static u32 qib_6120_hdrqempty(struct qib_ctxtdata *rcd)
2090{
2091 u32 head, tail;
2092
2093 head = qib_read_ureg32(rcd->dd, ur_rcvhdrhead, rcd->ctxt);
2094 if (rcd->rcvhdrtail_kvaddr)
2095 tail = qib_get_rcvhdrtail(rcd);
2096 else
2097 tail = qib_read_ureg32(rcd->dd, ur_rcvhdrtail, rcd->ctxt);
2098 return head == tail;
2099}
2100
2101/*
2102 * Used when we close any ctxt, for DMA already in flight
2103 * at close. Can't be done until we know hdrq size, so not
2104 * early in chip init.
2105 */
2106static void alloc_dummy_hdrq(struct qib_devdata *dd)
2107{
2108 dd->cspec->dummy_hdrq = dma_alloc_coherent(&dd->pcidev->dev,
2109 dd->rcd[0]->rcvhdrq_size,
2110 &dd->cspec->dummy_hdrq_phys,
Julia Lawall0f3696e2012-01-09 10:40:47 +01002111 GFP_ATOMIC | __GFP_COMP);
Ralph Campbellf9315512010-05-23 21:44:54 -07002112 if (!dd->cspec->dummy_hdrq) {
2113 qib_devinfo(dd->pcidev, "Couldn't allocate dummy hdrq\n");
2114 /* fallback to just 0'ing */
2115 dd->cspec->dummy_hdrq_phys = 0UL;
2116 }
2117}
2118
2119/*
2120 * Modify the RCVCTRL register in chip-specific way. This
2121 * is a function because bit positions and (future) register
2122 * location is chip-specific, but the needed operations are
2123 * generic. <op> is a bit-mask because we often want to
2124 * do multiple modifications.
2125 */
2126static void rcvctrl_6120_mod(struct qib_pportdata *ppd, unsigned int op,
2127 int ctxt)
2128{
2129 struct qib_devdata *dd = ppd->dd;
2130 u64 mask, val;
2131 unsigned long flags;
2132
2133 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
2134
2135 if (op & QIB_RCVCTRL_TAILUPD_ENB)
2136 dd->rcvctrl |= (1ULL << QLOGIC_IB_R_TAILUPD_SHIFT);
2137 if (op & QIB_RCVCTRL_TAILUPD_DIS)
2138 dd->rcvctrl &= ~(1ULL << QLOGIC_IB_R_TAILUPD_SHIFT);
2139 if (op & QIB_RCVCTRL_PKEY_ENB)
2140 dd->rcvctrl &= ~(1ULL << IBA6120_R_PKEY_DIS_SHIFT);
2141 if (op & QIB_RCVCTRL_PKEY_DIS)
2142 dd->rcvctrl |= (1ULL << IBA6120_R_PKEY_DIS_SHIFT);
2143 if (ctxt < 0)
2144 mask = (1ULL << dd->ctxtcnt) - 1;
2145 else
2146 mask = (1ULL << ctxt);
2147 if (op & QIB_RCVCTRL_CTXT_ENB) {
2148 /* always done for specific ctxt */
2149 dd->rcvctrl |= (mask << SYM_LSB(RcvCtrl, PortEnable));
2150 if (!(dd->flags & QIB_NODMA_RTAIL))
2151 dd->rcvctrl |= 1ULL << QLOGIC_IB_R_TAILUPD_SHIFT;
2152 /* Write these registers before the context is enabled. */
2153 qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr, ctxt,
2154 dd->rcd[ctxt]->rcvhdrqtailaddr_phys);
2155 qib_write_kreg_ctxt(dd, kr_rcvhdraddr, ctxt,
2156 dd->rcd[ctxt]->rcvhdrq_phys);
2157
2158 if (ctxt == 0 && !dd->cspec->dummy_hdrq)
2159 alloc_dummy_hdrq(dd);
2160 }
2161 if (op & QIB_RCVCTRL_CTXT_DIS)
2162 dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, PortEnable));
2163 if (op & QIB_RCVCTRL_INTRAVAIL_ENB)
2164 dd->rcvctrl |= (mask << QLOGIC_IB_R_INTRAVAIL_SHIFT);
2165 if (op & QIB_RCVCTRL_INTRAVAIL_DIS)
2166 dd->rcvctrl &= ~(mask << QLOGIC_IB_R_INTRAVAIL_SHIFT);
2167 qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
2168 if ((op & QIB_RCVCTRL_INTRAVAIL_ENB) && dd->rhdrhead_intr_off) {
2169 /* arm rcv interrupt */
2170 val = qib_read_ureg32(dd, ur_rcvhdrhead, ctxt) |
2171 dd->rhdrhead_intr_off;
2172 qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
2173 }
2174 if (op & QIB_RCVCTRL_CTXT_ENB) {
2175 /*
2176 * Init the context registers also; if we were
2177 * disabled, tail and head should both be zero
2178 * already from the enable, but since we don't
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002179 * know, we have to do it explicitly.
Ralph Campbellf9315512010-05-23 21:44:54 -07002180 */
2181 val = qib_read_ureg32(dd, ur_rcvegrindextail, ctxt);
2182 qib_write_ureg(dd, ur_rcvegrindexhead, val, ctxt);
2183
2184 val = qib_read_ureg32(dd, ur_rcvhdrtail, ctxt);
2185 dd->rcd[ctxt]->head = val;
2186 /* If kctxt, interrupt on next receive. */
2187 if (ctxt < dd->first_user_ctxt)
2188 val |= dd->rhdrhead_intr_off;
2189 qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
2190 }
2191 if (op & QIB_RCVCTRL_CTXT_DIS) {
2192 /*
2193 * Be paranoid, and never write 0's to these, just use an
2194 * unused page. Of course,
2195 * rcvhdraddr points to a large chunk of memory, so this
2196 * could still trash things, but at least it won't trash
2197 * page 0, and by disabling the ctxt, it should stop "soon",
2198 * even if a packet or two is in already in flight after we
2199 * disabled the ctxt. Only 6120 has this issue.
2200 */
2201 if (ctxt >= 0) {
2202 qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr, ctxt,
2203 dd->cspec->dummy_hdrq_phys);
2204 qib_write_kreg_ctxt(dd, kr_rcvhdraddr, ctxt,
2205 dd->cspec->dummy_hdrq_phys);
2206 } else {
2207 unsigned i;
2208
2209 for (i = 0; i < dd->cfgctxts; i++) {
2210 qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr,
2211 i, dd->cspec->dummy_hdrq_phys);
2212 qib_write_kreg_ctxt(dd, kr_rcvhdraddr,
2213 i, dd->cspec->dummy_hdrq_phys);
2214 }
2215 }
2216 }
2217 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
2218}
2219
2220/*
2221 * Modify the SENDCTRL register in chip-specific way. This
2222 * is a function there may be multiple such registers with
2223 * slightly different layouts. Only operations actually used
2224 * are implemented yet.
2225 * Chip requires no back-back sendctrl writes, so write
2226 * scratch register after writing sendctrl
2227 */
2228static void sendctrl_6120_mod(struct qib_pportdata *ppd, u32 op)
2229{
2230 struct qib_devdata *dd = ppd->dd;
2231 u64 tmp_dd_sendctrl;
2232 unsigned long flags;
2233
2234 spin_lock_irqsave(&dd->sendctrl_lock, flags);
2235
2236 /* First the ones that are "sticky", saved in shadow */
2237 if (op & QIB_SENDCTRL_CLEAR)
2238 dd->sendctrl = 0;
2239 if (op & QIB_SENDCTRL_SEND_DIS)
2240 dd->sendctrl &= ~SYM_MASK(SendCtrl, PIOEnable);
2241 else if (op & QIB_SENDCTRL_SEND_ENB)
2242 dd->sendctrl |= SYM_MASK(SendCtrl, PIOEnable);
2243 if (op & QIB_SENDCTRL_AVAIL_DIS)
2244 dd->sendctrl &= ~SYM_MASK(SendCtrl, PIOBufAvailUpd);
2245 else if (op & QIB_SENDCTRL_AVAIL_ENB)
2246 dd->sendctrl |= SYM_MASK(SendCtrl, PIOBufAvailUpd);
2247
2248 if (op & QIB_SENDCTRL_DISARM_ALL) {
2249 u32 i, last;
2250
2251 tmp_dd_sendctrl = dd->sendctrl;
2252 /*
2253 * disarm any that are not yet launched, disabling sends
2254 * and updates until done.
2255 */
2256 last = dd->piobcnt2k + dd->piobcnt4k;
2257 tmp_dd_sendctrl &=
2258 ~(SYM_MASK(SendCtrl, PIOEnable) |
2259 SYM_MASK(SendCtrl, PIOBufAvailUpd));
2260 for (i = 0; i < last; i++) {
2261 qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl |
2262 SYM_MASK(SendCtrl, Disarm) | i);
2263 qib_write_kreg(dd, kr_scratch, 0);
2264 }
2265 }
2266
2267 tmp_dd_sendctrl = dd->sendctrl;
2268
2269 if (op & QIB_SENDCTRL_FLUSH)
2270 tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Abort);
2271 if (op & QIB_SENDCTRL_DISARM)
2272 tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Disarm) |
2273 ((op & QIB_6120_SendCtrl_DisarmPIOBuf_RMASK) <<
2274 SYM_LSB(SendCtrl, DisarmPIOBuf));
2275 if (op & QIB_SENDCTRL_AVAIL_BLIP)
2276 tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, PIOBufAvailUpd);
2277
2278 qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl);
2279 qib_write_kreg(dd, kr_scratch, 0);
2280
2281 if (op & QIB_SENDCTRL_AVAIL_BLIP) {
2282 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
2283 qib_write_kreg(dd, kr_scratch, 0);
2284 }
2285
2286 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
2287
2288 if (op & QIB_SENDCTRL_FLUSH) {
2289 u32 v;
2290 /*
2291 * ensure writes have hit chip, then do a few
2292 * more reads, to allow DMA of pioavail registers
2293 * to occur, so in-memory copy is in sync with
2294 * the chip. Not always safe to sleep.
2295 */
2296 v = qib_read_kreg32(dd, kr_scratch);
2297 qib_write_kreg(dd, kr_scratch, v);
2298 v = qib_read_kreg32(dd, kr_scratch);
2299 qib_write_kreg(dd, kr_scratch, v);
2300 qib_read_kreg32(dd, kr_scratch);
2301 }
2302}
2303
2304/**
2305 * qib_portcntr_6120 - read a per-port counter
2306 * @dd: the qlogic_ib device
2307 * @creg: the counter to snapshot
2308 */
2309static u64 qib_portcntr_6120(struct qib_pportdata *ppd, u32 reg)
2310{
2311 u64 ret = 0ULL;
2312 struct qib_devdata *dd = ppd->dd;
2313 u16 creg;
2314 /* 0xffff for unimplemented or synthesized counters */
2315 static const u16 xlator[] = {
2316 [QIBPORTCNTR_PKTSEND] = cr_pktsend,
2317 [QIBPORTCNTR_WORDSEND] = cr_wordsend,
2318 [QIBPORTCNTR_PSXMITDATA] = 0xffff,
2319 [QIBPORTCNTR_PSXMITPKTS] = 0xffff,
2320 [QIBPORTCNTR_PSXMITWAIT] = 0xffff,
2321 [QIBPORTCNTR_SENDSTALL] = cr_sendstall,
2322 [QIBPORTCNTR_PKTRCV] = cr_pktrcv,
2323 [QIBPORTCNTR_PSRCVDATA] = 0xffff,
2324 [QIBPORTCNTR_PSRCVPKTS] = 0xffff,
2325 [QIBPORTCNTR_RCVEBP] = cr_rcvebp,
2326 [QIBPORTCNTR_RCVOVFL] = cr_rcvovfl,
2327 [QIBPORTCNTR_WORDRCV] = cr_wordrcv,
2328 [QIBPORTCNTR_RXDROPPKT] = cr_rxdroppkt,
2329 [QIBPORTCNTR_RXLOCALPHYERR] = 0xffff,
2330 [QIBPORTCNTR_RXVLERR] = 0xffff,
2331 [QIBPORTCNTR_ERRICRC] = cr_erricrc,
2332 [QIBPORTCNTR_ERRVCRC] = cr_errvcrc,
2333 [QIBPORTCNTR_ERRLPCRC] = cr_errlpcrc,
2334 [QIBPORTCNTR_BADFORMAT] = cr_badformat,
2335 [QIBPORTCNTR_ERR_RLEN] = cr_err_rlen,
2336 [QIBPORTCNTR_IBSYMBOLERR] = cr_ibsymbolerr,
2337 [QIBPORTCNTR_INVALIDRLEN] = cr_invalidrlen,
2338 [QIBPORTCNTR_UNSUPVL] = cr_txunsupvl,
2339 [QIBPORTCNTR_EXCESSBUFOVFL] = 0xffff,
2340 [QIBPORTCNTR_ERRLINK] = cr_errlink,
2341 [QIBPORTCNTR_IBLINKDOWN] = cr_iblinkdown,
2342 [QIBPORTCNTR_IBLINKERRRECOV] = cr_iblinkerrrecov,
2343 [QIBPORTCNTR_LLI] = 0xffff,
2344 [QIBPORTCNTR_PSINTERVAL] = 0xffff,
2345 [QIBPORTCNTR_PSSTART] = 0xffff,
2346 [QIBPORTCNTR_PSSTAT] = 0xffff,
2347 [QIBPORTCNTR_VL15PKTDROP] = 0xffff,
2348 [QIBPORTCNTR_ERRPKEY] = cr_errpkey,
2349 [QIBPORTCNTR_KHDROVFL] = 0xffff,
2350 };
2351
2352 if (reg >= ARRAY_SIZE(xlator)) {
2353 qib_devinfo(ppd->dd->pcidev,
2354 "Unimplemented portcounter %u\n", reg);
2355 goto done;
2356 }
2357 creg = xlator[reg];
2358
2359 /* handle counters requests not implemented as chip counters */
2360 if (reg == QIBPORTCNTR_LLI)
2361 ret = dd->cspec->lli_errs;
2362 else if (reg == QIBPORTCNTR_EXCESSBUFOVFL)
2363 ret = dd->cspec->overrun_thresh_errs;
2364 else if (reg == QIBPORTCNTR_KHDROVFL) {
2365 int i;
2366
2367 /* sum over all kernel contexts */
2368 for (i = 0; i < dd->first_user_ctxt; i++)
2369 ret += read_6120_creg32(dd, cr_portovfl + i);
2370 } else if (reg == QIBPORTCNTR_PSSTAT)
2371 ret = dd->cspec->pma_sample_status;
2372 if (creg == 0xffff)
2373 goto done;
2374
2375 /*
2376 * only fast incrementing counters are 64bit; use 32 bit reads to
2377 * avoid two independent reads when on opteron
2378 */
2379 if (creg == cr_wordsend || creg == cr_wordrcv ||
2380 creg == cr_pktsend || creg == cr_pktrcv)
2381 ret = read_6120_creg(dd, creg);
2382 else
2383 ret = read_6120_creg32(dd, creg);
2384 if (creg == cr_ibsymbolerr) {
2385 if (dd->cspec->ibdeltainprog)
2386 ret -= ret - dd->cspec->ibsymsnap;
2387 ret -= dd->cspec->ibsymdelta;
2388 } else if (creg == cr_iblinkerrrecov) {
2389 if (dd->cspec->ibdeltainprog)
2390 ret -= ret - dd->cspec->iblnkerrsnap;
2391 ret -= dd->cspec->iblnkerrdelta;
2392 }
2393 if (reg == QIBPORTCNTR_RXDROPPKT) /* add special cased count */
2394 ret += dd->cspec->rxfc_unsupvl_errs;
2395
2396done:
2397 return ret;
2398}
2399
2400/*
2401 * Device counter names (not port-specific), one line per stat,
2402 * single string. Used by utilities like ipathstats to print the stats
2403 * in a way which works for different versions of drivers, without changing
2404 * the utility. Names need to be 12 chars or less (w/o newline), for proper
2405 * display by utility.
2406 * Non-error counters are first.
2407 * Start of "error" conters is indicated by a leading "E " on the first
2408 * "error" counter, and doesn't count in label length.
2409 * The EgrOvfl list needs to be last so we truncate them at the configured
2410 * context count for the device.
2411 * cntr6120indices contains the corresponding register indices.
2412 */
2413static const char cntr6120names[] =
2414 "Interrupts\n"
2415 "HostBusStall\n"
2416 "E RxTIDFull\n"
2417 "RxTIDInvalid\n"
2418 "Ctxt0EgrOvfl\n"
2419 "Ctxt1EgrOvfl\n"
2420 "Ctxt2EgrOvfl\n"
2421 "Ctxt3EgrOvfl\n"
2422 "Ctxt4EgrOvfl\n";
2423
2424static const size_t cntr6120indices[] = {
2425 cr_lbint,
2426 cr_lbflowstall,
2427 cr_errtidfull,
2428 cr_errtidvalid,
2429 cr_portovfl + 0,
2430 cr_portovfl + 1,
2431 cr_portovfl + 2,
2432 cr_portovfl + 3,
2433 cr_portovfl + 4,
2434};
2435
2436/*
2437 * same as cntr6120names and cntr6120indices, but for port-specific counters.
2438 * portcntr6120indices is somewhat complicated by some registers needing
2439 * adjustments of various kinds, and those are ORed with _PORT_VIRT_FLAG
2440 */
2441static const char portcntr6120names[] =
2442 "TxPkt\n"
2443 "TxFlowPkt\n"
2444 "TxWords\n"
2445 "RxPkt\n"
2446 "RxFlowPkt\n"
2447 "RxWords\n"
2448 "TxFlowStall\n"
2449 "E IBStatusChng\n"
2450 "IBLinkDown\n"
2451 "IBLnkRecov\n"
2452 "IBRxLinkErr\n"
2453 "IBSymbolErr\n"
2454 "RxLLIErr\n"
2455 "RxBadFormat\n"
2456 "RxBadLen\n"
2457 "RxBufOvrfl\n"
2458 "RxEBP\n"
2459 "RxFlowCtlErr\n"
2460 "RxICRCerr\n"
2461 "RxLPCRCerr\n"
2462 "RxVCRCerr\n"
2463 "RxInvalLen\n"
2464 "RxInvalPKey\n"
2465 "RxPktDropped\n"
2466 "TxBadLength\n"
2467 "TxDropped\n"
2468 "TxInvalLen\n"
2469 "TxUnderrun\n"
2470 "TxUnsupVL\n"
2471 ;
2472
2473#define _PORT_VIRT_FLAG 0x8000 /* "virtual", need adjustments */
2474static const size_t portcntr6120indices[] = {
2475 QIBPORTCNTR_PKTSEND | _PORT_VIRT_FLAG,
2476 cr_pktsendflow,
2477 QIBPORTCNTR_WORDSEND | _PORT_VIRT_FLAG,
2478 QIBPORTCNTR_PKTRCV | _PORT_VIRT_FLAG,
2479 cr_pktrcvflowctrl,
2480 QIBPORTCNTR_WORDRCV | _PORT_VIRT_FLAG,
2481 QIBPORTCNTR_SENDSTALL | _PORT_VIRT_FLAG,
2482 cr_ibstatuschange,
2483 QIBPORTCNTR_IBLINKDOWN | _PORT_VIRT_FLAG,
2484 QIBPORTCNTR_IBLINKERRRECOV | _PORT_VIRT_FLAG,
2485 QIBPORTCNTR_ERRLINK | _PORT_VIRT_FLAG,
2486 QIBPORTCNTR_IBSYMBOLERR | _PORT_VIRT_FLAG,
2487 QIBPORTCNTR_LLI | _PORT_VIRT_FLAG,
2488 QIBPORTCNTR_BADFORMAT | _PORT_VIRT_FLAG,
2489 QIBPORTCNTR_ERR_RLEN | _PORT_VIRT_FLAG,
2490 QIBPORTCNTR_RCVOVFL | _PORT_VIRT_FLAG,
2491 QIBPORTCNTR_RCVEBP | _PORT_VIRT_FLAG,
2492 cr_rcvflowctrl_err,
2493 QIBPORTCNTR_ERRICRC | _PORT_VIRT_FLAG,
2494 QIBPORTCNTR_ERRLPCRC | _PORT_VIRT_FLAG,
2495 QIBPORTCNTR_ERRVCRC | _PORT_VIRT_FLAG,
2496 QIBPORTCNTR_INVALIDRLEN | _PORT_VIRT_FLAG,
2497 QIBPORTCNTR_ERRPKEY | _PORT_VIRT_FLAG,
2498 QIBPORTCNTR_RXDROPPKT | _PORT_VIRT_FLAG,
2499 cr_invalidslen,
2500 cr_senddropped,
2501 cr_errslen,
2502 cr_sendunderrun,
2503 cr_txunsupvl,
2504};
2505
2506/* do all the setup to make the counter reads efficient later */
2507static void init_6120_cntrnames(struct qib_devdata *dd)
2508{
2509 int i, j = 0;
2510 char *s;
2511
2512 for (i = 0, s = (char *)cntr6120names; s && j <= dd->cfgctxts;
2513 i++) {
2514 /* we always have at least one counter before the egrovfl */
2515 if (!j && !strncmp("Ctxt0EgrOvfl", s + 1, 12))
2516 j = 1;
2517 s = strchr(s + 1, '\n');
2518 if (s && j)
2519 j++;
2520 }
2521 dd->cspec->ncntrs = i;
2522 if (!s)
2523 /* full list; size is without terminating null */
2524 dd->cspec->cntrnamelen = sizeof(cntr6120names) - 1;
2525 else
2526 dd->cspec->cntrnamelen = 1 + s - cntr6120names;
2527 dd->cspec->cntrs = kmalloc(dd->cspec->ncntrs
2528 * sizeof(u64), GFP_KERNEL);
Ralph Campbellf9315512010-05-23 21:44:54 -07002529
2530 for (i = 0, s = (char *)portcntr6120names; s; i++)
2531 s = strchr(s + 1, '\n');
2532 dd->cspec->nportcntrs = i - 1;
2533 dd->cspec->portcntrnamelen = sizeof(portcntr6120names) - 1;
2534 dd->cspec->portcntrs = kmalloc(dd->cspec->nportcntrs
2535 * sizeof(u64), GFP_KERNEL);
Ralph Campbellf9315512010-05-23 21:44:54 -07002536}
2537
2538static u32 qib_read_6120cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
2539 u64 **cntrp)
2540{
2541 u32 ret;
2542
2543 if (namep) {
2544 ret = dd->cspec->cntrnamelen;
2545 if (pos >= ret)
2546 ret = 0; /* final read after getting everything */
2547 else
2548 *namep = (char *)cntr6120names;
2549 } else {
2550 u64 *cntr = dd->cspec->cntrs;
2551 int i;
2552
2553 ret = dd->cspec->ncntrs * sizeof(u64);
2554 if (!cntr || pos >= ret) {
2555 /* everything read, or couldn't get memory */
2556 ret = 0;
2557 goto done;
2558 }
2559 if (pos >= ret) {
2560 ret = 0; /* final read after getting everything */
2561 goto done;
2562 }
2563 *cntrp = cntr;
2564 for (i = 0; i < dd->cspec->ncntrs; i++)
2565 *cntr++ = read_6120_creg32(dd, cntr6120indices[i]);
2566 }
2567done:
2568 return ret;
2569}
2570
2571static u32 qib_read_6120portcntrs(struct qib_devdata *dd, loff_t pos, u32 port,
2572 char **namep, u64 **cntrp)
2573{
2574 u32 ret;
2575
2576 if (namep) {
2577 ret = dd->cspec->portcntrnamelen;
2578 if (pos >= ret)
2579 ret = 0; /* final read after getting everything */
2580 else
2581 *namep = (char *)portcntr6120names;
2582 } else {
2583 u64 *cntr = dd->cspec->portcntrs;
2584 struct qib_pportdata *ppd = &dd->pport[port];
2585 int i;
2586
2587 ret = dd->cspec->nportcntrs * sizeof(u64);
2588 if (!cntr || pos >= ret) {
2589 /* everything read, or couldn't get memory */
2590 ret = 0;
2591 goto done;
2592 }
2593 *cntrp = cntr;
2594 for (i = 0; i < dd->cspec->nportcntrs; i++) {
2595 if (portcntr6120indices[i] & _PORT_VIRT_FLAG)
2596 *cntr++ = qib_portcntr_6120(ppd,
2597 portcntr6120indices[i] &
2598 ~_PORT_VIRT_FLAG);
2599 else
2600 *cntr++ = read_6120_creg32(dd,
2601 portcntr6120indices[i]);
2602 }
2603 }
2604done:
2605 return ret;
2606}
2607
2608static void qib_chk_6120_errormask(struct qib_devdata *dd)
2609{
2610 static u32 fixed;
2611 u32 ctrl;
2612 unsigned long errormask;
2613 unsigned long hwerrs;
2614
2615 if (!dd->cspec->errormask || !(dd->flags & QIB_INITTED))
2616 return;
2617
2618 errormask = qib_read_kreg64(dd, kr_errmask);
2619
2620 if (errormask == dd->cspec->errormask)
2621 return;
2622 fixed++;
2623
2624 hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
2625 ctrl = qib_read_kreg32(dd, kr_control);
2626
2627 qib_write_kreg(dd, kr_errmask,
2628 dd->cspec->errormask);
2629
2630 if ((hwerrs & dd->cspec->hwerrmask) ||
2631 (ctrl & QLOGIC_IB_C_FREEZEMODE)) {
2632 qib_write_kreg(dd, kr_hwerrclear, 0ULL);
2633 qib_write_kreg(dd, kr_errclear, 0ULL);
2634 /* force re-interrupt of pending events, just in case */
2635 qib_write_kreg(dd, kr_intclear, 0ULL);
2636 qib_devinfo(dd->pcidev,
2637 "errormask fixed(%u) %lx->%lx, ctrl %x hwerr %lx\n",
2638 fixed, errormask, (unsigned long)dd->cspec->errormask,
2639 ctrl, hwerrs);
2640 }
2641}
2642
2643/**
2644 * qib_get_faststats - get word counters from chip before they overflow
2645 * @opaque - contains a pointer to the qlogic_ib device qib_devdata
2646 *
2647 * This needs more work; in particular, decision on whether we really
2648 * need traffic_wds done the way it is
2649 * called from add_timer
2650 */
Kees Cook4037c922017-10-04 17:45:35 -07002651static void qib_get_6120_faststats(struct timer_list *t)
Ralph Campbellf9315512010-05-23 21:44:54 -07002652{
Kees Cook4037c922017-10-04 17:45:35 -07002653 struct qib_devdata *dd = from_timer(dd, t, stats_timer);
Ralph Campbellf9315512010-05-23 21:44:54 -07002654 struct qib_pportdata *ppd = dd->pport;
2655 unsigned long flags;
2656 u64 traffic_wds;
2657
2658 /*
2659 * don't access the chip while running diags, or memory diags can
2660 * fail
2661 */
2662 if (!(dd->flags & QIB_INITTED) || dd->diag_client)
2663 /* but re-arm the timer, for diags case; won't hurt other */
2664 goto done;
2665
2666 /*
2667 * We now try to maintain an activity timer, based on traffic
2668 * exceeding a threshold, so we need to check the word-counts
2669 * even if they are 64-bit.
2670 */
2671 traffic_wds = qib_portcntr_6120(ppd, cr_wordsend) +
2672 qib_portcntr_6120(ppd, cr_wordrcv);
2673 spin_lock_irqsave(&dd->eep_st_lock, flags);
2674 traffic_wds -= dd->traffic_wds;
2675 dd->traffic_wds += traffic_wds;
Ralph Campbellf9315512010-05-23 21:44:54 -07002676 spin_unlock_irqrestore(&dd->eep_st_lock, flags);
2677
2678 qib_chk_6120_errormask(dd);
2679done:
2680 mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);
2681}
2682
2683/* no interrupt fallback for these chips */
2684static int qib_6120_nointr_fallback(struct qib_devdata *dd)
2685{
2686 return 0;
2687}
2688
2689/*
2690 * reset the XGXS (between serdes and IBC). Slightly less intrusive
2691 * than resetting the IBC or external link state, and useful in some
2692 * cases to cause some retraining. To do this right, we reset IBC
2693 * as well.
2694 */
2695static void qib_6120_xgxs_reset(struct qib_pportdata *ppd)
2696{
2697 u64 val, prev_val;
2698 struct qib_devdata *dd = ppd->dd;
2699
2700 prev_val = qib_read_kreg64(dd, kr_xgxs_cfg);
2701 val = prev_val | QLOGIC_IB_XGXS_RESET;
2702 prev_val &= ~QLOGIC_IB_XGXS_RESET; /* be sure */
2703 qib_write_kreg(dd, kr_control,
2704 dd->control & ~QLOGIC_IB_C_LINKENABLE);
2705 qib_write_kreg(dd, kr_xgxs_cfg, val);
2706 qib_read_kreg32(dd, kr_scratch);
2707 qib_write_kreg(dd, kr_xgxs_cfg, prev_val);
2708 qib_write_kreg(dd, kr_control, dd->control);
2709}
2710
2711static int qib_6120_get_ib_cfg(struct qib_pportdata *ppd, int which)
2712{
2713 int ret;
2714
2715 switch (which) {
2716 case QIB_IB_CFG_LWID:
2717 ret = ppd->link_width_active;
2718 break;
2719
2720 case QIB_IB_CFG_SPD:
2721 ret = ppd->link_speed_active;
2722 break;
2723
2724 case QIB_IB_CFG_LWID_ENB:
2725 ret = ppd->link_width_enabled;
2726 break;
2727
2728 case QIB_IB_CFG_SPD_ENB:
2729 ret = ppd->link_speed_enabled;
2730 break;
2731
2732 case QIB_IB_CFG_OP_VLS:
2733 ret = ppd->vls_operational;
2734 break;
2735
2736 case QIB_IB_CFG_VL_HIGH_CAP:
2737 ret = 0;
2738 break;
2739
2740 case QIB_IB_CFG_VL_LOW_CAP:
2741 ret = 0;
2742 break;
2743
2744 case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
2745 ret = SYM_FIELD(ppd->dd->cspec->ibcctrl, IBCCtrl,
2746 OverrunThreshold);
2747 break;
2748
2749 case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
2750 ret = SYM_FIELD(ppd->dd->cspec->ibcctrl, IBCCtrl,
2751 PhyerrThreshold);
2752 break;
2753
2754 case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
2755 /* will only take effect when the link state changes */
2756 ret = (ppd->dd->cspec->ibcctrl &
2757 SYM_MASK(IBCCtrl, LinkDownDefaultState)) ?
2758 IB_LINKINITCMD_SLEEP : IB_LINKINITCMD_POLL;
2759 break;
2760
2761 case QIB_IB_CFG_HRTBT: /* Get Heartbeat off/enable/auto */
2762 ret = 0; /* no heartbeat on this chip */
2763 break;
2764
2765 case QIB_IB_CFG_PMA_TICKS:
2766 ret = 250; /* 1 usec. */
2767 break;
2768
2769 default:
2770 ret = -EINVAL;
2771 break;
2772 }
2773 return ret;
2774}
2775
2776/*
2777 * We assume range checking is already done, if needed.
2778 */
2779static int qib_6120_set_ib_cfg(struct qib_pportdata *ppd, int which, u32 val)
2780{
2781 struct qib_devdata *dd = ppd->dd;
2782 int ret = 0;
2783 u64 val64;
2784 u16 lcmd, licmd;
2785
2786 switch (which) {
2787 case QIB_IB_CFG_LWID_ENB:
2788 ppd->link_width_enabled = val;
2789 break;
2790
2791 case QIB_IB_CFG_SPD_ENB:
2792 ppd->link_speed_enabled = val;
2793 break;
2794
2795 case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
2796 val64 = SYM_FIELD(dd->cspec->ibcctrl, IBCCtrl,
2797 OverrunThreshold);
2798 if (val64 != val) {
2799 dd->cspec->ibcctrl &=
2800 ~SYM_MASK(IBCCtrl, OverrunThreshold);
2801 dd->cspec->ibcctrl |= (u64) val <<
2802 SYM_LSB(IBCCtrl, OverrunThreshold);
2803 qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
2804 qib_write_kreg(dd, kr_scratch, 0);
2805 }
2806 break;
2807
2808 case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
2809 val64 = SYM_FIELD(dd->cspec->ibcctrl, IBCCtrl,
2810 PhyerrThreshold);
2811 if (val64 != val) {
2812 dd->cspec->ibcctrl &=
2813 ~SYM_MASK(IBCCtrl, PhyerrThreshold);
2814 dd->cspec->ibcctrl |= (u64) val <<
2815 SYM_LSB(IBCCtrl, PhyerrThreshold);
2816 qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
2817 qib_write_kreg(dd, kr_scratch, 0);
2818 }
2819 break;
2820
2821 case QIB_IB_CFG_PKEYS: /* update pkeys */
2822 val64 = (u64) ppd->pkeys[0] | ((u64) ppd->pkeys[1] << 16) |
2823 ((u64) ppd->pkeys[2] << 32) |
2824 ((u64) ppd->pkeys[3] << 48);
2825 qib_write_kreg(dd, kr_partitionkey, val64);
2826 break;
2827
2828 case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
2829 /* will only take effect when the link state changes */
2830 if (val == IB_LINKINITCMD_POLL)
2831 dd->cspec->ibcctrl &=
2832 ~SYM_MASK(IBCCtrl, LinkDownDefaultState);
2833 else /* SLEEP */
2834 dd->cspec->ibcctrl |=
2835 SYM_MASK(IBCCtrl, LinkDownDefaultState);
2836 qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
2837 qib_write_kreg(dd, kr_scratch, 0);
2838 break;
2839
2840 case QIB_IB_CFG_MTU: /* update the MTU in IBC */
2841 /*
2842 * Update our housekeeping variables, and set IBC max
2843 * size, same as init code; max IBC is max we allow in
2844 * buffer, less the qword pbc, plus 1 for ICRC, in dwords
2845 * Set even if it's unchanged, print debug message only
2846 * on changes.
2847 */
2848 val = (ppd->ibmaxlen >> 2) + 1;
2849 dd->cspec->ibcctrl &= ~SYM_MASK(IBCCtrl, MaxPktLen);
2850 dd->cspec->ibcctrl |= (u64)val <<
2851 SYM_LSB(IBCCtrl, MaxPktLen);
2852 qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
2853 qib_write_kreg(dd, kr_scratch, 0);
2854 break;
2855
2856 case QIB_IB_CFG_LSTATE: /* set the IB link state */
2857 switch (val & 0xffff0000) {
2858 case IB_LINKCMD_DOWN:
2859 lcmd = QLOGIC_IB_IBCC_LINKCMD_DOWN;
2860 if (!dd->cspec->ibdeltainprog) {
2861 dd->cspec->ibdeltainprog = 1;
2862 dd->cspec->ibsymsnap =
2863 read_6120_creg32(dd, cr_ibsymbolerr);
2864 dd->cspec->iblnkerrsnap =
2865 read_6120_creg32(dd, cr_iblinkerrrecov);
2866 }
2867 break;
2868
2869 case IB_LINKCMD_ARMED:
2870 lcmd = QLOGIC_IB_IBCC_LINKCMD_ARMED;
2871 break;
2872
2873 case IB_LINKCMD_ACTIVE:
2874 lcmd = QLOGIC_IB_IBCC_LINKCMD_ACTIVE;
2875 break;
2876
2877 default:
2878 ret = -EINVAL;
2879 qib_dev_err(dd, "bad linkcmd req 0x%x\n", val >> 16);
2880 goto bail;
2881 }
2882 switch (val & 0xffff) {
2883 case IB_LINKINITCMD_NOP:
2884 licmd = 0;
2885 break;
2886
2887 case IB_LINKINITCMD_POLL:
2888 licmd = QLOGIC_IB_IBCC_LINKINITCMD_POLL;
2889 break;
2890
2891 case IB_LINKINITCMD_SLEEP:
2892 licmd = QLOGIC_IB_IBCC_LINKINITCMD_SLEEP;
2893 break;
2894
2895 case IB_LINKINITCMD_DISABLE:
2896 licmd = QLOGIC_IB_IBCC_LINKINITCMD_DISABLE;
2897 break;
2898
2899 default:
2900 ret = -EINVAL;
2901 qib_dev_err(dd, "bad linkinitcmd req 0x%x\n",
2902 val & 0xffff);
2903 goto bail;
2904 }
2905 qib_set_ib_6120_lstate(ppd, lcmd, licmd);
2906 goto bail;
2907
2908 case QIB_IB_CFG_HRTBT:
2909 ret = -EINVAL;
2910 break;
2911
2912 default:
2913 ret = -EINVAL;
2914 }
2915bail:
2916 return ret;
2917}
2918
2919static int qib_6120_set_loopback(struct qib_pportdata *ppd, const char *what)
2920{
2921 int ret = 0;
Mike Marciniszynda12c1f2015-01-16 11:23:31 -05002922
Ralph Campbellf9315512010-05-23 21:44:54 -07002923 if (!strncmp(what, "ibc", 3)) {
2924 ppd->dd->cspec->ibcctrl |= SYM_MASK(IBCCtrl, Loopback);
2925 qib_devinfo(ppd->dd->pcidev, "Enabling IB%u:%u IBC loopback\n",
2926 ppd->dd->unit, ppd->port);
2927 } else if (!strncmp(what, "off", 3)) {
2928 ppd->dd->cspec->ibcctrl &= ~SYM_MASK(IBCCtrl, Loopback);
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00002929 qib_devinfo(ppd->dd->pcidev,
2930 "Disabling IB%u:%u IBC loopback (normal)\n",
2931 ppd->dd->unit, ppd->port);
Ralph Campbellf9315512010-05-23 21:44:54 -07002932 } else
2933 ret = -EINVAL;
2934 if (!ret) {
2935 qib_write_kreg(ppd->dd, kr_ibcctrl, ppd->dd->cspec->ibcctrl);
2936 qib_write_kreg(ppd->dd, kr_scratch, 0);
2937 }
2938 return ret;
2939}
2940
Kees Cook4037c922017-10-04 17:45:35 -07002941static void pma_6120_timer(struct timer_list *t)
Ralph Campbellf9315512010-05-23 21:44:54 -07002942{
Kees Cook4037c922017-10-04 17:45:35 -07002943 struct qib_chip_specific *cs = from_timer(cs, t, pma_timer);
2944 struct qib_pportdata *ppd = cs->ppd;
Ralph Campbellf9315512010-05-23 21:44:54 -07002945 struct qib_ibport *ibp = &ppd->ibport_data;
2946 unsigned long flags;
2947
Harish Chegondif24a6d42016-01-22 12:56:02 -08002948 spin_lock_irqsave(&ibp->rvp.lock, flags);
Ralph Campbellf9315512010-05-23 21:44:54 -07002949 if (cs->pma_sample_status == IB_PMA_SAMPLE_STATUS_STARTED) {
2950 cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
2951 qib_snapshot_counters(ppd, &cs->sword, &cs->rword,
2952 &cs->spkts, &cs->rpkts, &cs->xmit_wait);
2953 mod_timer(&cs->pma_timer,
Harish Chegondif24a6d42016-01-22 12:56:02 -08002954 jiffies + usecs_to_jiffies(ibp->rvp.pma_sample_interval));
Ralph Campbellf9315512010-05-23 21:44:54 -07002955 } else if (cs->pma_sample_status == IB_PMA_SAMPLE_STATUS_RUNNING) {
2956 u64 ta, tb, tc, td, te;
2957
2958 cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
2959 qib_snapshot_counters(ppd, &ta, &tb, &tc, &td, &te);
2960
2961 cs->sword = ta - cs->sword;
2962 cs->rword = tb - cs->rword;
2963 cs->spkts = tc - cs->spkts;
2964 cs->rpkts = td - cs->rpkts;
2965 cs->xmit_wait = te - cs->xmit_wait;
2966 }
Harish Chegondif24a6d42016-01-22 12:56:02 -08002967 spin_unlock_irqrestore(&ibp->rvp.lock, flags);
Ralph Campbellf9315512010-05-23 21:44:54 -07002968}
2969
2970/*
Harish Chegondif24a6d42016-01-22 12:56:02 -08002971 * Note that the caller has the ibp->rvp.lock held.
Ralph Campbellf9315512010-05-23 21:44:54 -07002972 */
2973static void qib_set_cntr_6120_sample(struct qib_pportdata *ppd, u32 intv,
2974 u32 start)
2975{
2976 struct qib_chip_specific *cs = ppd->dd->cspec;
2977
2978 if (start && intv) {
2979 cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_STARTED;
2980 mod_timer(&cs->pma_timer, jiffies + usecs_to_jiffies(start));
2981 } else if (intv) {
2982 cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
2983 qib_snapshot_counters(ppd, &cs->sword, &cs->rword,
2984 &cs->spkts, &cs->rpkts, &cs->xmit_wait);
2985 mod_timer(&cs->pma_timer, jiffies + usecs_to_jiffies(intv));
2986 } else {
2987 cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
2988 cs->sword = 0;
2989 cs->rword = 0;
2990 cs->spkts = 0;
2991 cs->rpkts = 0;
2992 cs->xmit_wait = 0;
2993 }
2994}
2995
2996static u32 qib_6120_iblink_state(u64 ibcs)
2997{
2998 u32 state = (u32)SYM_FIELD(ibcs, IBCStatus, LinkState);
2999
3000 switch (state) {
3001 case IB_6120_L_STATE_INIT:
3002 state = IB_PORT_INIT;
3003 break;
3004 case IB_6120_L_STATE_ARM:
3005 state = IB_PORT_ARMED;
3006 break;
3007 case IB_6120_L_STATE_ACTIVE:
3008 /* fall through */
3009 case IB_6120_L_STATE_ACT_DEFER:
3010 state = IB_PORT_ACTIVE;
3011 break;
3012 default: /* fall through */
3013 case IB_6120_L_STATE_DOWN:
3014 state = IB_PORT_DOWN;
3015 break;
3016 }
3017 return state;
3018}
3019
3020/* returns the IBTA port state, rather than the IBC link training state */
3021static u8 qib_6120_phys_portstate(u64 ibcs)
3022{
3023 u8 state = (u8)SYM_FIELD(ibcs, IBCStatus, LinkTrainingState);
3024 return qib_6120_physportstate[state];
3025}
3026
3027static int qib_6120_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
3028{
3029 unsigned long flags;
3030
3031 spin_lock_irqsave(&ppd->lflags_lock, flags);
3032 ppd->lflags &= ~QIBL_IB_FORCE_NOTIFY;
3033 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
3034
3035 if (ibup) {
3036 if (ppd->dd->cspec->ibdeltainprog) {
3037 ppd->dd->cspec->ibdeltainprog = 0;
3038 ppd->dd->cspec->ibsymdelta +=
3039 read_6120_creg32(ppd->dd, cr_ibsymbolerr) -
3040 ppd->dd->cspec->ibsymsnap;
3041 ppd->dd->cspec->iblnkerrdelta +=
3042 read_6120_creg32(ppd->dd, cr_iblinkerrrecov) -
3043 ppd->dd->cspec->iblnkerrsnap;
3044 }
3045 qib_hol_init(ppd);
3046 } else {
3047 ppd->dd->cspec->lli_counter = 0;
3048 if (!ppd->dd->cspec->ibdeltainprog) {
3049 ppd->dd->cspec->ibdeltainprog = 1;
3050 ppd->dd->cspec->ibsymsnap =
3051 read_6120_creg32(ppd->dd, cr_ibsymbolerr);
3052 ppd->dd->cspec->iblnkerrsnap =
3053 read_6120_creg32(ppd->dd, cr_iblinkerrrecov);
3054 }
3055 qib_hol_down(ppd);
3056 }
3057
3058 qib_6120_setup_setextled(ppd, ibup);
3059
3060 return 0;
3061}
3062
3063/* Does read/modify/write to appropriate registers to
3064 * set output and direction bits selected by mask.
3065 * these are in their canonical postions (e.g. lsb of
3066 * dir will end up in D48 of extctrl on existing chips).
3067 * returns contents of GP Inputs.
3068 */
3069static int gpio_6120_mod(struct qib_devdata *dd, u32 out, u32 dir, u32 mask)
3070{
3071 u64 read_val, new_out;
3072 unsigned long flags;
3073
3074 if (mask) {
3075 /* some bits being written, lock access to GPIO */
3076 dir &= mask;
3077 out &= mask;
3078 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
3079 dd->cspec->extctrl &= ~((u64)mask << SYM_LSB(EXTCtrl, GPIOOe));
3080 dd->cspec->extctrl |= ((u64) dir << SYM_LSB(EXTCtrl, GPIOOe));
3081 new_out = (dd->cspec->gpio_out & ~mask) | out;
3082
3083 qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
3084 qib_write_kreg(dd, kr_gpio_out, new_out);
3085 dd->cspec->gpio_out = new_out;
3086 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
3087 }
3088 /*
3089 * It is unlikely that a read at this time would get valid
3090 * data on a pin whose direction line was set in the same
3091 * call to this function. We include the read here because
3092 * that allows us to potentially combine a change on one pin with
3093 * a read on another, and because the old code did something like
3094 * this.
3095 */
3096 read_val = qib_read_kreg64(dd, kr_extstatus);
3097 return SYM_FIELD(read_val, EXTStatus, GPIOIn);
3098}
3099
3100/*
3101 * Read fundamental info we need to use the chip. These are
3102 * the registers that describe chip capabilities, and are
3103 * saved in shadow registers.
3104 */
3105static void get_6120_chip_params(struct qib_devdata *dd)
3106{
3107 u64 val;
3108 u32 piobufs;
3109 int mtu;
3110
3111 dd->uregbase = qib_read_kreg32(dd, kr_userregbase);
3112
3113 dd->rcvtidcnt = qib_read_kreg32(dd, kr_rcvtidcnt);
3114 dd->rcvtidbase = qib_read_kreg32(dd, kr_rcvtidbase);
3115 dd->rcvegrbase = qib_read_kreg32(dd, kr_rcvegrbase);
3116 dd->palign = qib_read_kreg32(dd, kr_palign);
3117 dd->piobufbase = qib_read_kreg64(dd, kr_sendpiobufbase);
3118 dd->pio2k_bufbase = dd->piobufbase & 0xffffffff;
3119
3120 dd->rcvhdrcnt = qib_read_kreg32(dd, kr_rcvegrcnt);
3121
3122 val = qib_read_kreg64(dd, kr_sendpiosize);
3123 dd->piosize2k = val & ~0U;
3124 dd->piosize4k = val >> 32;
3125
3126 mtu = ib_mtu_enum_to_int(qib_ibmtu);
3127 if (mtu == -1)
3128 mtu = QIB_DEFAULT_MTU;
3129 dd->pport->ibmtu = (u32)mtu;
3130
3131 val = qib_read_kreg64(dd, kr_sendpiobufcnt);
3132 dd->piobcnt2k = val & ~0U;
3133 dd->piobcnt4k = val >> 32;
Mike Marciniszynbb77a072012-05-07 14:02:42 -04003134 dd->last_pio = dd->piobcnt4k + dd->piobcnt2k - 1;
Ralph Campbellf9315512010-05-23 21:44:54 -07003135 /* these may be adjusted in init_chip_wc_pat() */
3136 dd->pio2kbase = (u32 __iomem *)
3137 (((char __iomem *)dd->kregbase) + dd->pio2k_bufbase);
3138 if (dd->piobcnt4k) {
3139 dd->pio4kbase = (u32 __iomem *)
3140 (((char __iomem *) dd->kregbase) +
3141 (dd->piobufbase >> 32));
3142 /*
3143 * 4K buffers take 2 pages; we use roundup just to be
3144 * paranoid; we calculate it once here, rather than on
3145 * ever buf allocate
3146 */
3147 dd->align4k = ALIGN(dd->piosize4k, dd->palign);
3148 }
3149
3150 piobufs = dd->piobcnt4k + dd->piobcnt2k;
3151
3152 dd->pioavregs = ALIGN(piobufs, sizeof(u64) * BITS_PER_BYTE / 2) /
3153 (sizeof(u64) * BITS_PER_BYTE / 2);
3154}
3155
3156/*
3157 * The chip base addresses in cspec and cpspec have to be set
3158 * after possible init_chip_wc_pat(), rather than in
3159 * get_6120_chip_params(), so split out as separate function
3160 */
3161static void set_6120_baseaddrs(struct qib_devdata *dd)
3162{
3163 u32 cregbase;
Mike Marciniszynda12c1f2015-01-16 11:23:31 -05003164
Ralph Campbellf9315512010-05-23 21:44:54 -07003165 cregbase = qib_read_kreg32(dd, kr_counterregbase);
3166 dd->cspec->cregbase = (u64 __iomem *)
3167 ((char __iomem *) dd->kregbase + cregbase);
3168
3169 dd->egrtidbase = (u64 __iomem *)
3170 ((char __iomem *) dd->kregbase + dd->rcvegrbase);
3171}
3172
3173/*
3174 * Write the final few registers that depend on some of the
3175 * init setup. Done late in init, just before bringing up
3176 * the serdes.
3177 */
3178static int qib_late_6120_initreg(struct qib_devdata *dd)
3179{
3180 int ret = 0;
3181 u64 val;
3182
3183 qib_write_kreg(dd, kr_rcvhdrentsize, dd->rcvhdrentsize);
3184 qib_write_kreg(dd, kr_rcvhdrsize, dd->rcvhdrsize);
3185 qib_write_kreg(dd, kr_rcvhdrcnt, dd->rcvhdrcnt);
3186 qib_write_kreg(dd, kr_sendpioavailaddr, dd->pioavailregs_phys);
3187 val = qib_read_kreg64(dd, kr_sendpioavailaddr);
3188 if (val != dd->pioavailregs_phys) {
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00003189 qib_dev_err(dd,
3190 "Catastrophic software error, SendPIOAvailAddr written as %lx, read back as %llx\n",
3191 (unsigned long) dd->pioavailregs_phys,
3192 (unsigned long long) val);
Ralph Campbellf9315512010-05-23 21:44:54 -07003193 ret = -EINVAL;
3194 }
3195 return ret;
3196}
3197
3198static int init_6120_variables(struct qib_devdata *dd)
3199{
3200 int ret = 0;
3201 struct qib_pportdata *ppd;
3202 u32 sbufs;
3203
3204 ppd = (struct qib_pportdata *)(dd + 1);
3205 dd->pport = ppd;
3206 dd->num_pports = 1;
3207
3208 dd->cspec = (struct qib_chip_specific *)(ppd + dd->num_pports);
Kees Cook4037c922017-10-04 17:45:35 -07003209 dd->cspec->ppd = ppd;
Ralph Campbellf9315512010-05-23 21:44:54 -07003210 ppd->cpspec = NULL; /* not used in this chip */
3211
3212 spin_lock_init(&dd->cspec->kernel_tid_lock);
3213 spin_lock_init(&dd->cspec->user_tid_lock);
3214 spin_lock_init(&dd->cspec->rcvmod_lock);
3215 spin_lock_init(&dd->cspec->gpio_lock);
3216
3217 /* we haven't yet set QIB_PRESENT, so use read directly */
3218 dd->revision = readq(&dd->kregbase[kr_revision]);
3219
3220 if ((dd->revision & 0xffffffffU) == 0xffffffffU) {
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00003221 qib_dev_err(dd,
3222 "Revision register read failure, giving up initialization\n");
Ralph Campbellf9315512010-05-23 21:44:54 -07003223 ret = -ENODEV;
3224 goto bail;
3225 }
3226 dd->flags |= QIB_PRESENT; /* now register routines work */
3227
3228 dd->majrev = (u8) SYM_FIELD(dd->revision, Revision_R,
3229 ChipRevMajor);
3230 dd->minrev = (u8) SYM_FIELD(dd->revision, Revision_R,
3231 ChipRevMinor);
3232
3233 get_6120_chip_params(dd);
3234 pe_boardname(dd); /* fill in boardname */
3235
3236 /*
3237 * GPIO bits for TWSI data and clock,
3238 * used for serial EEPROM.
3239 */
3240 dd->gpio_sda_num = _QIB_GPIO_SDA_NUM;
3241 dd->gpio_scl_num = _QIB_GPIO_SCL_NUM;
3242 dd->twsi_eeprom_dev = QIB_TWSI_NO_DEV;
3243
3244 if (qib_unordered_wc())
3245 dd->flags |= QIB_PIO_FLUSH_WC;
3246
3247 /*
3248 * EEPROM error log 0 is TXE Parity errors. 1 is RXE Parity.
3249 * 2 is Some Misc, 3 is reserved for future.
3250 */
3251 dd->eep_st_masks[0].hwerrs_to_log = HWE_MASK(TXEMemParityErr);
3252
3253 /* Ignore errors in PIO/PBC on systems with unordered write-combining */
3254 if (qib_unordered_wc())
3255 dd->eep_st_masks[0].hwerrs_to_log &= ~TXE_PIO_PARITY;
3256
3257 dd->eep_st_masks[1].hwerrs_to_log = HWE_MASK(RXEMemParityErr);
3258
3259 dd->eep_st_masks[2].errs_to_log = ERR_MASK(ResetNegated);
3260
Mike Marciniszyn7d7632a2014-03-07 08:40:55 -05003261 ret = qib_init_pportdata(ppd, dd, 0, 1);
3262 if (ret)
3263 goto bail;
Ralph Campbellf9315512010-05-23 21:44:54 -07003264 ppd->link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
3265 ppd->link_speed_supported = QIB_IB_SDR;
3266 ppd->link_width_enabled = IB_WIDTH_4X;
3267 ppd->link_speed_enabled = ppd->link_speed_supported;
3268 /* these can't change for this chip, so set once */
3269 ppd->link_width_active = ppd->link_width_enabled;
3270 ppd->link_speed_active = ppd->link_speed_enabled;
3271 ppd->vls_supported = IB_VL_VL0;
3272 ppd->vls_operational = ppd->vls_supported;
3273
3274 dd->rcvhdrentsize = QIB_RCVHDR_ENTSIZE;
3275 dd->rcvhdrsize = QIB_DFLT_RCVHDRSIZE;
3276 dd->rhf_offset = 0;
3277
3278 /* we always allocate at least 2048 bytes for eager buffers */
3279 ret = ib_mtu_enum_to_int(qib_ibmtu);
3280 dd->rcvegrbufsize = ret != -1 ? max(ret, 2048) : QIB_DEFAULT_MTU;
Mike Marciniszyn9e1c0e42011-09-23 13:16:39 -04003281 BUG_ON(!is_power_of_2(dd->rcvegrbufsize));
3282 dd->rcvegrbufsize_shift = ilog2(dd->rcvegrbufsize);
Ralph Campbellf9315512010-05-23 21:44:54 -07003283
3284 qib_6120_tidtemplate(dd);
3285
3286 /*
3287 * We can request a receive interrupt for 1 or
3288 * more packets from current offset. For now, we set this
3289 * up for a single packet.
3290 */
3291 dd->rhdrhead_intr_off = 1ULL << 32;
3292
3293 /* setup the stats timer; the add_timer is done at end of init */
Kees Cook4037c922017-10-04 17:45:35 -07003294 timer_setup(&dd->stats_timer, qib_get_6120_faststats, 0);
3295 timer_setup(&dd->cspec->pma_timer, pma_6120_timer, 0);
Ralph Campbellf9315512010-05-23 21:44:54 -07003296
3297 dd->ureg_align = qib_read_kreg32(dd, kr_palign);
3298
3299 dd->piosize2kmax_dwords = dd->piosize2k >> 2;
3300 qib_6120_config_ctxts(dd);
3301 qib_set_ctxtcnt(dd);
3302
Luis R. Rodriguezd4988622015-04-22 11:38:24 -07003303 ret = init_chip_wc_pat(dd, 0);
3304 if (ret)
3305 goto bail;
Ralph Campbellf9315512010-05-23 21:44:54 -07003306 set_6120_baseaddrs(dd); /* set chip access pointers now */
3307
3308 ret = 0;
3309 if (qib_mini_init)
3310 goto bail;
3311
3312 qib_num_cfg_vls = 1; /* if any 6120's, only one VL */
3313
3314 ret = qib_create_ctxts(dd);
3315 init_6120_cntrnames(dd);
3316
3317 /* use all of 4KB buffers for the kernel, otherwise 16 */
3318 sbufs = dd->piobcnt4k ? dd->piobcnt4k : 16;
3319
3320 dd->lastctxt_piobuf = dd->piobcnt2k + dd->piobcnt4k - sbufs;
3321 dd->pbufsctxt = dd->lastctxt_piobuf /
3322 (dd->cfgctxts - dd->first_user_ctxt);
3323
3324 if (ret)
3325 goto bail;
3326bail:
3327 return ret;
3328}
3329
3330/*
3331 * For this chip, we want to use the same buffer every time
3332 * when we are trying to bring the link up (they are always VL15
3333 * packets). At that link state the packet should always go out immediately
3334 * (or at least be discarded at the tx interface if the link is down).
3335 * If it doesn't, and the buffer isn't available, that means some other
3336 * sender has gotten ahead of us, and is preventing our packet from going
3337 * out. In that case, we flush all packets, and try again. If that still
3338 * fails, we fail the request, and hope things work the next time around.
3339 *
3340 * We don't need very complicated heuristics on whether the packet had
3341 * time to go out or not, since even at SDR 1X, it goes out in very short
3342 * time periods, covered by the chip reads done here and as part of the
3343 * flush.
3344 */
3345static u32 __iomem *get_6120_link_buf(struct qib_pportdata *ppd, u32 *bnum)
3346{
3347 u32 __iomem *buf;
3348 u32 lbuf = ppd->dd->piobcnt2k + ppd->dd->piobcnt4k - 1;
3349
3350 /*
3351 * always blip to get avail list updated, since it's almost
3352 * always needed, and is fairly cheap.
3353 */
3354 sendctrl_6120_mod(ppd->dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
3355 qib_read_kreg64(ppd->dd, kr_scratch); /* extra chip flush */
3356 buf = qib_getsendbuf_range(ppd->dd, bnum, lbuf, lbuf);
3357 if (buf)
3358 goto done;
3359
3360 sendctrl_6120_mod(ppd, QIB_SENDCTRL_DISARM_ALL | QIB_SENDCTRL_FLUSH |
3361 QIB_SENDCTRL_AVAIL_BLIP);
3362 ppd->dd->upd_pio_shadow = 1; /* update our idea of what's busy */
3363 qib_read_kreg64(ppd->dd, kr_scratch); /* extra chip flush */
3364 buf = qib_getsendbuf_range(ppd->dd, bnum, lbuf, lbuf);
3365done:
3366 return buf;
3367}
3368
3369static u32 __iomem *qib_6120_getsendbuf(struct qib_pportdata *ppd, u64 pbc,
3370 u32 *pbufnum)
3371{
3372 u32 first, last, plen = pbc & QIB_PBC_LENGTH_MASK;
3373 struct qib_devdata *dd = ppd->dd;
3374 u32 __iomem *buf;
3375
3376 if (((pbc >> 32) & PBC_6120_VL15_SEND_CTRL) &&
3377 !(ppd->lflags & (QIBL_IB_AUTONEG_INPROG | QIBL_LINKACTIVE)))
3378 buf = get_6120_link_buf(ppd, pbufnum);
3379 else {
3380
3381 if ((plen + 1) > dd->piosize2kmax_dwords)
3382 first = dd->piobcnt2k;
3383 else
3384 first = 0;
3385 /* try 4k if all 2k busy, so same last for both sizes */
3386 last = dd->piobcnt2k + dd->piobcnt4k - 1;
3387 buf = qib_getsendbuf_range(dd, pbufnum, first, last);
3388 }
3389 return buf;
3390}
3391
3392static int init_sdma_6120_regs(struct qib_pportdata *ppd)
3393{
3394 return -ENODEV;
3395}
3396
3397static u16 qib_sdma_6120_gethead(struct qib_pportdata *ppd)
3398{
3399 return 0;
3400}
3401
3402static int qib_sdma_6120_busy(struct qib_pportdata *ppd)
3403{
3404 return 0;
3405}
3406
3407static void qib_sdma_update_6120_tail(struct qib_pportdata *ppd, u16 tail)
3408{
3409}
3410
3411static void qib_6120_sdma_sendctrl(struct qib_pportdata *ppd, unsigned op)
3412{
3413}
3414
3415static void qib_sdma_set_6120_desc_cnt(struct qib_pportdata *ppd, unsigned cnt)
3416{
3417}
3418
3419/*
3420 * the pbc doesn't need a VL15 indicator, but we need it for link_buf.
3421 * The chip ignores the bit if set.
3422 */
3423static u32 qib_6120_setpbc_control(struct qib_pportdata *ppd, u32 plen,
3424 u8 srate, u8 vl)
3425{
3426 return vl == 15 ? PBC_6120_VL15_SEND_CTRL : 0;
3427}
3428
3429static void qib_6120_initvl15_bufs(struct qib_devdata *dd)
3430{
3431}
3432
3433static void qib_6120_init_ctxt(struct qib_ctxtdata *rcd)
3434{
3435 rcd->rcvegrcnt = rcd->dd->rcvhdrcnt;
3436 rcd->rcvegr_tid_base = rcd->ctxt * rcd->rcvegrcnt;
3437}
3438
3439static void qib_6120_txchk_change(struct qib_devdata *dd, u32 start,
3440 u32 len, u32 avail, struct qib_ctxtdata *rcd)
3441{
3442}
3443
3444static void writescratch(struct qib_devdata *dd, u32 val)
3445{
3446 (void) qib_write_kreg(dd, kr_scratch, val);
3447}
3448
3449static int qib_6120_tempsense_rd(struct qib_devdata *dd, int regnum)
3450{
3451 return -ENXIO;
3452}
3453
Mike Marciniszyn8469ba32013-05-30 18:25:25 -04003454#ifdef CONFIG_INFINIBAND_QIB_DCA
3455static int qib_6120_notify_dca(struct qib_devdata *dd, unsigned long event)
3456{
3457 return 0;
3458}
3459#endif
3460
Ralph Campbellf9315512010-05-23 21:44:54 -07003461/* Dummy function, as 6120 boards never disable EEPROM Write */
3462static int qib_6120_eeprom_wen(struct qib_devdata *dd, int wen)
3463{
3464 return 1;
3465}
3466
3467/**
3468 * qib_init_iba6120_funcs - set up the chip-specific function pointers
3469 * @pdev: pci_dev of the qlogic_ib device
3470 * @ent: pci_device_id matching this chip
3471 *
3472 * This is global, and is called directly at init to set up the
3473 * chip-specific function pointers for later use.
3474 *
3475 * It also allocates/partially-inits the qib_devdata struct for
3476 * this device.
3477 */
3478struct qib_devdata *qib_init_iba6120_funcs(struct pci_dev *pdev,
3479 const struct pci_device_id *ent)
3480{
3481 struct qib_devdata *dd;
3482 int ret;
3483
Ralph Campbellf9315512010-05-23 21:44:54 -07003484 dd = qib_alloc_devdata(pdev, sizeof(struct qib_pportdata) +
3485 sizeof(struct qib_chip_specific));
3486 if (IS_ERR(dd))
3487 goto bail;
3488
3489 dd->f_bringup_serdes = qib_6120_bringup_serdes;
3490 dd->f_cleanup = qib_6120_setup_cleanup;
3491 dd->f_clear_tids = qib_6120_clear_tids;
3492 dd->f_free_irq = qib_6120_free_irq;
3493 dd->f_get_base_info = qib_6120_get_base_info;
3494 dd->f_get_msgheader = qib_6120_get_msgheader;
3495 dd->f_getsendbuf = qib_6120_getsendbuf;
3496 dd->f_gpio_mod = gpio_6120_mod;
3497 dd->f_eeprom_wen = qib_6120_eeprom_wen;
3498 dd->f_hdrqempty = qib_6120_hdrqempty;
3499 dd->f_ib_updown = qib_6120_ib_updown;
3500 dd->f_init_ctxt = qib_6120_init_ctxt;
3501 dd->f_initvl15_bufs = qib_6120_initvl15_bufs;
3502 dd->f_intr_fallback = qib_6120_nointr_fallback;
3503 dd->f_late_initreg = qib_late_6120_initreg;
3504 dd->f_setpbc_control = qib_6120_setpbc_control;
3505 dd->f_portcntr = qib_portcntr_6120;
3506 dd->f_put_tid = (dd->minrev >= 2) ?
3507 qib_6120_put_tid_2 :
3508 qib_6120_put_tid;
3509 dd->f_quiet_serdes = qib_6120_quiet_serdes;
3510 dd->f_rcvctrl = rcvctrl_6120_mod;
3511 dd->f_read_cntrs = qib_read_6120cntrs;
3512 dd->f_read_portcntrs = qib_read_6120portcntrs;
3513 dd->f_reset = qib_6120_setup_reset;
3514 dd->f_init_sdma_regs = init_sdma_6120_regs;
3515 dd->f_sdma_busy = qib_sdma_6120_busy;
3516 dd->f_sdma_gethead = qib_sdma_6120_gethead;
3517 dd->f_sdma_sendctrl = qib_6120_sdma_sendctrl;
3518 dd->f_sdma_set_desc_cnt = qib_sdma_set_6120_desc_cnt;
3519 dd->f_sdma_update_tail = qib_sdma_update_6120_tail;
3520 dd->f_sendctrl = sendctrl_6120_mod;
3521 dd->f_set_armlaunch = qib_set_6120_armlaunch;
3522 dd->f_set_cntr_sample = qib_set_cntr_6120_sample;
3523 dd->f_iblink_state = qib_6120_iblink_state;
3524 dd->f_ibphys_portstate = qib_6120_phys_portstate;
3525 dd->f_get_ib_cfg = qib_6120_get_ib_cfg;
3526 dd->f_set_ib_cfg = qib_6120_set_ib_cfg;
3527 dd->f_set_ib_loopback = qib_6120_set_loopback;
3528 dd->f_set_intr_state = qib_6120_set_intr_state;
3529 dd->f_setextled = qib_6120_setup_setextled;
3530 dd->f_txchk_change = qib_6120_txchk_change;
3531 dd->f_update_usrhead = qib_update_6120_usrhead;
3532 dd->f_wantpiobuf_intr = qib_wantpiobuf_6120_intr;
3533 dd->f_xgxs_reset = qib_6120_xgxs_reset;
3534 dd->f_writescratch = writescratch;
3535 dd->f_tempsense_rd = qib_6120_tempsense_rd;
Mike Marciniszyn8469ba32013-05-30 18:25:25 -04003536#ifdef CONFIG_INFINIBAND_QIB_DCA
3537 dd->f_notify_dca = qib_6120_notify_dca;
3538#endif
Ralph Campbellf9315512010-05-23 21:44:54 -07003539 /*
3540 * Do remaining pcie setup and save pcie values in dd.
3541 * Any error printing is already done by the init code.
3542 * On return, we have the chip mapped and accessible,
3543 * but chip registers are not set up until start of
3544 * init_6120_variables.
3545 */
3546 ret = qib_pcie_ddinit(dd, pdev, ent);
3547 if (ret < 0)
3548 goto bail_free;
3549
3550 /* initialize chip-specific variables */
3551 ret = init_6120_variables(dd);
3552 if (ret)
3553 goto bail_cleanup;
3554
3555 if (qib_mini_init)
3556 goto bail;
3557
Michael J. Ruhl581d01a2017-06-09 16:00:06 -07003558 if (qib_pcie_params(dd, 8, NULL))
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00003559 qib_dev_err(dd,
3560 "Failed to setup PCIe or interrupts; continuing anyway\n");
Ralph Campbellf9315512010-05-23 21:44:54 -07003561 dd->cspec->irq = pdev->irq; /* save IRQ */
3562
3563 /* clear diagctrl register, in case diags were running and crashed */
3564 qib_write_kreg(dd, kr_hwdiagctrl, 0);
3565
3566 if (qib_read_kreg64(dd, kr_hwerrstatus) &
3567 QLOGIC_IB_HWE_SERDESPLLFAILED)
3568 qib_write_kreg(dd, kr_hwerrclear,
3569 QLOGIC_IB_HWE_SERDESPLLFAILED);
3570
3571 /* setup interrupt handler (interrupt type handled above) */
3572 qib_setup_6120_interrupt(dd);
3573 /* Note that qpn_mask is set by qib_6120_config_ctxts() first */
3574 qib_6120_init_hwerrors(dd);
3575
3576 goto bail;
3577
3578bail_cleanup:
3579 qib_pcie_ddcleanup(dd);
3580bail_free:
3581 qib_free_devdata(dd);
3582 dd = ERR_PTR(ret);
3583bail:
3584 return dd;
3585}