blob: d400aa7c73b4d2d386bedb223746cf4cf9d7f10d [file] [log] [blame]
Ralph Campbellf9315512010-05-23 21:44:54 -07001/*
Michael J. Ruhl581d01a2017-06-09 16:00:06 -07002 * Copyright (c) 2011 - 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 7220 chip (except that specific to the SerDes)
38 */
39
40#include <linux/interrupt.h>
41#include <linux/pci.h>
42#include <linux/delay.h>
Paul Gortmakere4dd23d2011-05-27 15:35:46 -040043#include <linux/module.h>
Ralph Campbellf9315512010-05-23 21:44:54 -070044#include <linux/io.h>
45#include <rdma/ib_verbs.h>
46
47#include "qib.h"
48#include "qib_7220.h"
49
50static void qib_setup_7220_setextled(struct qib_pportdata *, u32);
51static void qib_7220_handle_hwerrors(struct qib_devdata *, char *, size_t);
52static void sendctrl_7220_mod(struct qib_pportdata *ppd, u32 op);
53static u32 qib_7220_iblink_state(u64);
54static u8 qib_7220_phys_portstate(u64);
55static void qib_sdma_update_7220_tail(struct qib_pportdata *, u16);
56static void qib_set_ib_7220_lstate(struct qib_pportdata *, u16, u16);
57
58/*
59 * This file contains almost all the chip-specific register information and
60 * access functions for the QLogic QLogic_IB 7220 PCI-Express chip, with the
61 * exception of SerDes support, which in in qib_sd7220.c.
62 */
63
64/* Below uses machine-generated qib_chipnum_regs.h file */
65#define KREG_IDX(regname) (QIB_7220_##regname##_OFFS / sizeof(u64))
66
67/* Use defines to tie machine-generated names to lower-case names */
68#define kr_control KREG_IDX(Control)
69#define kr_counterregbase KREG_IDX(CntrRegBase)
70#define kr_errclear KREG_IDX(ErrClear)
71#define kr_errmask KREG_IDX(ErrMask)
72#define kr_errstatus KREG_IDX(ErrStatus)
73#define kr_extctrl KREG_IDX(EXTCtrl)
74#define kr_extstatus KREG_IDX(EXTStatus)
75#define kr_gpio_clear KREG_IDX(GPIOClear)
76#define kr_gpio_mask KREG_IDX(GPIOMask)
77#define kr_gpio_out KREG_IDX(GPIOOut)
78#define kr_gpio_status KREG_IDX(GPIOStatus)
79#define kr_hrtbt_guid KREG_IDX(HRTBT_GUID)
80#define kr_hwdiagctrl KREG_IDX(HwDiagCtrl)
81#define kr_hwerrclear KREG_IDX(HwErrClear)
82#define kr_hwerrmask KREG_IDX(HwErrMask)
83#define kr_hwerrstatus KREG_IDX(HwErrStatus)
84#define kr_ibcctrl KREG_IDX(IBCCtrl)
85#define kr_ibcddrctrl KREG_IDX(IBCDDRCtrl)
86#define kr_ibcddrstatus KREG_IDX(IBCDDRStatus)
87#define kr_ibcstatus KREG_IDX(IBCStatus)
88#define kr_ibserdesctrl KREG_IDX(IBSerDesCtrl)
89#define kr_intclear KREG_IDX(IntClear)
90#define kr_intmask KREG_IDX(IntMask)
91#define kr_intstatus KREG_IDX(IntStatus)
92#define kr_ncmodectrl KREG_IDX(IBNCModeCtrl)
93#define kr_palign KREG_IDX(PageAlign)
94#define kr_partitionkey KREG_IDX(RcvPartitionKey)
95#define kr_portcnt KREG_IDX(PortCnt)
96#define kr_rcvbthqp KREG_IDX(RcvBTHQP)
97#define kr_rcvctrl KREG_IDX(RcvCtrl)
98#define kr_rcvegrbase KREG_IDX(RcvEgrBase)
99#define kr_rcvegrcnt KREG_IDX(RcvEgrCnt)
100#define kr_rcvhdrcnt KREG_IDX(RcvHdrCnt)
101#define kr_rcvhdrentsize KREG_IDX(RcvHdrEntSize)
102#define kr_rcvhdrsize KREG_IDX(RcvHdrSize)
103#define kr_rcvpktledcnt KREG_IDX(RcvPktLEDCnt)
104#define kr_rcvtidbase KREG_IDX(RcvTIDBase)
105#define kr_rcvtidcnt KREG_IDX(RcvTIDCnt)
106#define kr_revision KREG_IDX(Revision)
107#define kr_scratch KREG_IDX(Scratch)
108#define kr_sendbuffererror KREG_IDX(SendBufErr0)
109#define kr_sendctrl KREG_IDX(SendCtrl)
110#define kr_senddmabase KREG_IDX(SendDmaBase)
111#define kr_senddmabufmask0 KREG_IDX(SendDmaBufMask0)
112#define kr_senddmabufmask1 (KREG_IDX(SendDmaBufMask0) + 1)
113#define kr_senddmabufmask2 (KREG_IDX(SendDmaBufMask0) + 2)
114#define kr_senddmahead KREG_IDX(SendDmaHead)
115#define kr_senddmaheadaddr KREG_IDX(SendDmaHeadAddr)
116#define kr_senddmalengen KREG_IDX(SendDmaLenGen)
117#define kr_senddmastatus KREG_IDX(SendDmaStatus)
118#define kr_senddmatail KREG_IDX(SendDmaTail)
119#define kr_sendpioavailaddr KREG_IDX(SendBufAvailAddr)
120#define kr_sendpiobufbase KREG_IDX(SendBufBase)
121#define kr_sendpiobufcnt KREG_IDX(SendBufCnt)
122#define kr_sendpiosize KREG_IDX(SendBufSize)
123#define kr_sendregbase KREG_IDX(SendRegBase)
124#define kr_userregbase KREG_IDX(UserRegBase)
125#define kr_xgxs_cfg KREG_IDX(XGXSCfg)
126
127/* These must only be written via qib_write_kreg_ctxt() */
128#define kr_rcvhdraddr KREG_IDX(RcvHdrAddr0)
129#define kr_rcvhdrtailaddr KREG_IDX(RcvHdrTailAddr0)
130
131
132#define CREG_IDX(regname) ((QIB_7220_##regname##_OFFS - \
133 QIB_7220_LBIntCnt_OFFS) / sizeof(u64))
134
135#define cr_badformat CREG_IDX(RxVersionErrCnt)
136#define cr_erricrc CREG_IDX(RxICRCErrCnt)
137#define cr_errlink CREG_IDX(RxLinkMalformCnt)
138#define cr_errlpcrc CREG_IDX(RxLPCRCErrCnt)
139#define cr_errpkey CREG_IDX(RxPKeyMismatchCnt)
140#define cr_rcvflowctrl_err CREG_IDX(RxFlowCtrlViolCnt)
141#define cr_err_rlen CREG_IDX(RxLenErrCnt)
142#define cr_errslen CREG_IDX(TxLenErrCnt)
143#define cr_errtidfull CREG_IDX(RxTIDFullErrCnt)
144#define cr_errtidvalid CREG_IDX(RxTIDValidErrCnt)
145#define cr_errvcrc CREG_IDX(RxVCRCErrCnt)
146#define cr_ibstatuschange CREG_IDX(IBStatusChangeCnt)
147#define cr_lbint CREG_IDX(LBIntCnt)
148#define cr_invalidrlen CREG_IDX(RxMaxMinLenErrCnt)
149#define cr_invalidslen CREG_IDX(TxMaxMinLenErrCnt)
150#define cr_lbflowstall CREG_IDX(LBFlowStallCnt)
151#define cr_pktrcv CREG_IDX(RxDataPktCnt)
152#define cr_pktrcvflowctrl CREG_IDX(RxFlowPktCnt)
153#define cr_pktsend CREG_IDX(TxDataPktCnt)
154#define cr_pktsendflow CREG_IDX(TxFlowPktCnt)
155#define cr_portovfl CREG_IDX(RxP0HdrEgrOvflCnt)
156#define cr_rcvebp CREG_IDX(RxEBPCnt)
157#define cr_rcvovfl CREG_IDX(RxBufOvflCnt)
158#define cr_senddropped CREG_IDX(TxDroppedPktCnt)
159#define cr_sendstall CREG_IDX(TxFlowStallCnt)
160#define cr_sendunderrun CREG_IDX(TxUnderrunCnt)
161#define cr_wordrcv CREG_IDX(RxDwordCnt)
162#define cr_wordsend CREG_IDX(TxDwordCnt)
163#define cr_txunsupvl CREG_IDX(TxUnsupVLErrCnt)
164#define cr_rxdroppkt CREG_IDX(RxDroppedPktCnt)
165#define cr_iblinkerrrecov CREG_IDX(IBLinkErrRecoveryCnt)
166#define cr_iblinkdown CREG_IDX(IBLinkDownedCnt)
167#define cr_ibsymbolerr CREG_IDX(IBSymbolErrCnt)
168#define cr_vl15droppedpkt CREG_IDX(RxVL15DroppedPktCnt)
169#define cr_rxotherlocalphyerr CREG_IDX(RxOtherLocalPhyErrCnt)
170#define cr_excessbufferovfl CREG_IDX(ExcessBufferOvflCnt)
171#define cr_locallinkintegrityerr CREG_IDX(LocalLinkIntegrityErrCnt)
172#define cr_rxvlerr CREG_IDX(RxVlErrCnt)
173#define cr_rxdlidfltr CREG_IDX(RxDlidFltrCnt)
174#define cr_psstat CREG_IDX(PSStat)
175#define cr_psstart CREG_IDX(PSStart)
176#define cr_psinterval CREG_IDX(PSInterval)
177#define cr_psrcvdatacount CREG_IDX(PSRcvDataCount)
178#define cr_psrcvpktscount CREG_IDX(PSRcvPktsCount)
179#define cr_psxmitdatacount CREG_IDX(PSXmitDataCount)
180#define cr_psxmitpktscount CREG_IDX(PSXmitPktsCount)
181#define cr_psxmitwaitcount CREG_IDX(PSXmitWaitCount)
182#define cr_txsdmadesc CREG_IDX(TxSDmaDescCnt)
183#define cr_pcieretrydiag CREG_IDX(PcieRetryBufDiagQwordCnt)
184
185#define SYM_RMASK(regname, fldname) ((u64) \
186 QIB_7220_##regname##_##fldname##_RMASK)
187#define SYM_MASK(regname, fldname) ((u64) \
188 QIB_7220_##regname##_##fldname##_RMASK << \
189 QIB_7220_##regname##_##fldname##_LSB)
190#define SYM_LSB(regname, fldname) (QIB_7220_##regname##_##fldname##_LSB)
191#define SYM_FIELD(value, regname, fldname) ((u64) \
192 (((value) >> SYM_LSB(regname, fldname)) & \
193 SYM_RMASK(regname, fldname)))
194#define ERR_MASK(fldname) SYM_MASK(ErrMask, fldname##Mask)
195#define HWE_MASK(fldname) SYM_MASK(HwErrMask, fldname##Mask)
196
197/* ibcctrl bits */
198#define QLOGIC_IB_IBCC_LINKINITCMD_DISABLE 1
199/* cycle through TS1/TS2 till OK */
200#define QLOGIC_IB_IBCC_LINKINITCMD_POLL 2
201/* wait for TS1, then go on */
202#define QLOGIC_IB_IBCC_LINKINITCMD_SLEEP 3
203#define QLOGIC_IB_IBCC_LINKINITCMD_SHIFT 16
204
205#define QLOGIC_IB_IBCC_LINKCMD_DOWN 1 /* move to 0x11 */
206#define QLOGIC_IB_IBCC_LINKCMD_ARMED 2 /* move to 0x21 */
207#define QLOGIC_IB_IBCC_LINKCMD_ACTIVE 3 /* move to 0x31 */
208
209#define BLOB_7220_IBCHG 0x81
210
211/*
212 * We could have a single register get/put routine, that takes a group type,
213 * but this is somewhat clearer and cleaner. It also gives us some error
214 * checking. 64 bit register reads should always work, but are inefficient
215 * on opteron (the northbridge always generates 2 separate HT 32 bit reads),
216 * so we use kreg32 wherever possible. User register and counter register
217 * reads are always 32 bit reads, so only one form of those routines.
218 */
219
220/**
221 * qib_read_ureg32 - read 32-bit virtualized per-context register
222 * @dd: device
223 * @regno: register number
224 * @ctxt: context number
225 *
226 * Return the contents of a register that is virtualized to be per context.
227 * Returns -1 on errors (not distinguishable from valid contents at
228 * runtime; we may add a separate error variable at some point).
229 */
230static inline u32 qib_read_ureg32(const struct qib_devdata *dd,
231 enum qib_ureg regno, int ctxt)
232{
233 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
234 return 0;
235
236 if (dd->userbase)
237 return readl(regno + (u64 __iomem *)
238 ((char __iomem *)dd->userbase +
239 dd->ureg_align * ctxt));
240 else
241 return readl(regno + (u64 __iomem *)
242 (dd->uregbase +
243 (char __iomem *)dd->kregbase +
244 dd->ureg_align * ctxt));
245}
246
247/**
248 * qib_write_ureg - write 32-bit virtualized per-context register
249 * @dd: device
250 * @regno: register number
251 * @value: value
252 * @ctxt: context
253 *
254 * Write the contents of a register that is virtualized to be per context.
255 */
256static inline void qib_write_ureg(const struct qib_devdata *dd,
257 enum qib_ureg regno, u64 value, int ctxt)
258{
259 u64 __iomem *ubase;
260
261 if (dd->userbase)
262 ubase = (u64 __iomem *)
263 ((char __iomem *) dd->userbase +
264 dd->ureg_align * ctxt);
265 else
266 ubase = (u64 __iomem *)
267 (dd->uregbase +
268 (char __iomem *) dd->kregbase +
269 dd->ureg_align * ctxt);
270
271 if (dd->kregbase && (dd->flags & QIB_PRESENT))
272 writeq(value, &ubase[regno]);
273}
274
275/**
276 * qib_write_kreg_ctxt - write a device's per-ctxt 64-bit kernel register
277 * @dd: the qlogic_ib device
278 * @regno: the register number to write
279 * @ctxt: the context containing the register
280 * @value: the value to write
281 */
282static inline void qib_write_kreg_ctxt(const struct qib_devdata *dd,
283 const u16 regno, unsigned ctxt,
284 u64 value)
285{
286 qib_write_kreg(dd, regno + ctxt, value);
287}
288
289static inline void write_7220_creg(const struct qib_devdata *dd,
290 u16 regno, u64 value)
291{
292 if (dd->cspec->cregbase && (dd->flags & QIB_PRESENT))
293 writeq(value, &dd->cspec->cregbase[regno]);
294}
295
296static inline u64 read_7220_creg(const struct qib_devdata *dd, u16 regno)
297{
298 if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
299 return 0;
300 return readq(&dd->cspec->cregbase[regno]);
301}
302
303static inline u32 read_7220_creg32(const struct qib_devdata *dd, u16 regno)
304{
305 if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
306 return 0;
307 return readl(&dd->cspec->cregbase[regno]);
308}
309
310/* kr_revision bits */
311#define QLOGIC_IB_R_EMULATORREV_MASK ((1ULL << 22) - 1)
312#define QLOGIC_IB_R_EMULATORREV_SHIFT 40
313
314/* kr_control bits */
315#define QLOGIC_IB_C_RESET (1U << 7)
316
317/* kr_intstatus, kr_intclear, kr_intmask bits */
318#define QLOGIC_IB_I_RCVURG_MASK ((1ULL << 17) - 1)
319#define QLOGIC_IB_I_RCVURG_SHIFT 32
320#define QLOGIC_IB_I_RCVAVAIL_MASK ((1ULL << 17) - 1)
321#define QLOGIC_IB_I_RCVAVAIL_SHIFT 0
322#define QLOGIC_IB_I_SERDESTRIMDONE (1ULL << 27)
323
324#define QLOGIC_IB_C_FREEZEMODE 0x00000002
325#define QLOGIC_IB_C_LINKENABLE 0x00000004
326
327#define QLOGIC_IB_I_SDMAINT 0x8000000000000000ULL
328#define QLOGIC_IB_I_SDMADISABLED 0x4000000000000000ULL
329#define QLOGIC_IB_I_ERROR 0x0000000080000000ULL
330#define QLOGIC_IB_I_SPIOSENT 0x0000000040000000ULL
331#define QLOGIC_IB_I_SPIOBUFAVAIL 0x0000000020000000ULL
332#define QLOGIC_IB_I_GPIO 0x0000000010000000ULL
333
334/* variables for sanity checking interrupt and errors */
335#define QLOGIC_IB_I_BITSEXTANT \
336 (QLOGIC_IB_I_SDMAINT | QLOGIC_IB_I_SDMADISABLED | \
337 (QLOGIC_IB_I_RCVURG_MASK << QLOGIC_IB_I_RCVURG_SHIFT) | \
338 (QLOGIC_IB_I_RCVAVAIL_MASK << \
339 QLOGIC_IB_I_RCVAVAIL_SHIFT) | \
340 QLOGIC_IB_I_ERROR | QLOGIC_IB_I_SPIOSENT | \
341 QLOGIC_IB_I_SPIOBUFAVAIL | QLOGIC_IB_I_GPIO | \
342 QLOGIC_IB_I_SERDESTRIMDONE)
343
344#define IB_HWE_BITSEXTANT \
345 (HWE_MASK(RXEMemParityErr) | \
346 HWE_MASK(TXEMemParityErr) | \
347 (QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK << \
348 QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT) | \
349 QLOGIC_IB_HWE_PCIE1PLLFAILED | \
350 QLOGIC_IB_HWE_PCIE0PLLFAILED | \
351 QLOGIC_IB_HWE_PCIEPOISONEDTLP | \
352 QLOGIC_IB_HWE_PCIECPLTIMEOUT | \
353 QLOGIC_IB_HWE_PCIEBUSPARITYXTLH | \
354 QLOGIC_IB_HWE_PCIEBUSPARITYXADM | \
355 QLOGIC_IB_HWE_PCIEBUSPARITYRADM | \
356 HWE_MASK(PowerOnBISTFailed) | \
357 QLOGIC_IB_HWE_COREPLL_FBSLIP | \
358 QLOGIC_IB_HWE_COREPLL_RFSLIP | \
359 QLOGIC_IB_HWE_SERDESPLLFAILED | \
360 HWE_MASK(IBCBusToSPCParityErr) | \
361 HWE_MASK(IBCBusFromSPCParityErr) | \
362 QLOGIC_IB_HWE_PCIECPLDATAQUEUEERR | \
363 QLOGIC_IB_HWE_PCIECPLHDRQUEUEERR | \
364 QLOGIC_IB_HWE_SDMAMEMREADERR | \
365 QLOGIC_IB_HWE_CLK_UC_PLLNOTLOCKED | \
366 QLOGIC_IB_HWE_PCIESERDESQ0PCLKNOTDETECT | \
367 QLOGIC_IB_HWE_PCIESERDESQ1PCLKNOTDETECT | \
368 QLOGIC_IB_HWE_PCIESERDESQ2PCLKNOTDETECT | \
369 QLOGIC_IB_HWE_PCIESERDESQ3PCLKNOTDETECT | \
370 QLOGIC_IB_HWE_DDSRXEQMEMORYPARITYERR | \
371 QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR | \
372 QLOGIC_IB_HWE_PCIE_UC_OCT0MEMORYPARITYERR | \
373 QLOGIC_IB_HWE_PCIE_UC_OCT1MEMORYPARITYERR)
374
375#define IB_E_BITSEXTANT \
376 (ERR_MASK(RcvFormatErr) | ERR_MASK(RcvVCRCErr) | \
377 ERR_MASK(RcvICRCErr) | ERR_MASK(RcvMinPktLenErr) | \
378 ERR_MASK(RcvMaxPktLenErr) | ERR_MASK(RcvLongPktLenErr) | \
379 ERR_MASK(RcvShortPktLenErr) | ERR_MASK(RcvUnexpectedCharErr) | \
380 ERR_MASK(RcvUnsupportedVLErr) | ERR_MASK(RcvEBPErr) | \
381 ERR_MASK(RcvIBFlowErr) | ERR_MASK(RcvBadVersionErr) | \
382 ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr) | \
383 ERR_MASK(RcvBadTidErr) | ERR_MASK(RcvHdrLenErr) | \
384 ERR_MASK(RcvHdrErr) | ERR_MASK(RcvIBLostLinkErr) | \
385 ERR_MASK(SendSpecialTriggerErr) | \
386 ERR_MASK(SDmaDisabledErr) | ERR_MASK(SendMinPktLenErr) | \
387 ERR_MASK(SendMaxPktLenErr) | ERR_MASK(SendUnderRunErr) | \
388 ERR_MASK(SendPktLenErr) | ERR_MASK(SendDroppedSmpPktErr) | \
389 ERR_MASK(SendDroppedDataPktErr) | \
390 ERR_MASK(SendPioArmLaunchErr) | \
391 ERR_MASK(SendUnexpectedPktNumErr) | \
392 ERR_MASK(SendUnsupportedVLErr) | ERR_MASK(SendBufMisuseErr) | \
393 ERR_MASK(SDmaGenMismatchErr) | ERR_MASK(SDmaOutOfBoundErr) | \
394 ERR_MASK(SDmaTailOutOfBoundErr) | ERR_MASK(SDmaBaseErr) | \
395 ERR_MASK(SDma1stDescErr) | ERR_MASK(SDmaRpyTagErr) | \
396 ERR_MASK(SDmaDwEnErr) | ERR_MASK(SDmaMissingDwErr) | \
397 ERR_MASK(SDmaUnexpDataErr) | \
398 ERR_MASK(IBStatusChanged) | ERR_MASK(InvalidAddrErr) | \
399 ERR_MASK(ResetNegated) | ERR_MASK(HardwareErr) | \
400 ERR_MASK(SDmaDescAddrMisalignErr) | \
401 ERR_MASK(InvalidEEPCmd))
402
403/* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
404#define QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK 0x00000000000000ffULL
405#define QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT 0
406#define QLOGIC_IB_HWE_PCIEPOISONEDTLP 0x0000000010000000ULL
407#define QLOGIC_IB_HWE_PCIECPLTIMEOUT 0x0000000020000000ULL
408#define QLOGIC_IB_HWE_PCIEBUSPARITYXTLH 0x0000000040000000ULL
409#define QLOGIC_IB_HWE_PCIEBUSPARITYXADM 0x0000000080000000ULL
410#define QLOGIC_IB_HWE_PCIEBUSPARITYRADM 0x0000000100000000ULL
411#define QLOGIC_IB_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
412#define QLOGIC_IB_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
413#define QLOGIC_IB_HWE_PCIE1PLLFAILED 0x0400000000000000ULL
414#define QLOGIC_IB_HWE_PCIE0PLLFAILED 0x0800000000000000ULL
415#define QLOGIC_IB_HWE_SERDESPLLFAILED 0x1000000000000000ULL
416/* specific to this chip */
417#define QLOGIC_IB_HWE_PCIECPLDATAQUEUEERR 0x0000000000000040ULL
418#define QLOGIC_IB_HWE_PCIECPLHDRQUEUEERR 0x0000000000000080ULL
419#define QLOGIC_IB_HWE_SDMAMEMREADERR 0x0000000010000000ULL
420#define QLOGIC_IB_HWE_CLK_UC_PLLNOTLOCKED 0x2000000000000000ULL
421#define QLOGIC_IB_HWE_PCIESERDESQ0PCLKNOTDETECT 0x0100000000000000ULL
422#define QLOGIC_IB_HWE_PCIESERDESQ1PCLKNOTDETECT 0x0200000000000000ULL
423#define QLOGIC_IB_HWE_PCIESERDESQ2PCLKNOTDETECT 0x0400000000000000ULL
424#define QLOGIC_IB_HWE_PCIESERDESQ3PCLKNOTDETECT 0x0800000000000000ULL
425#define QLOGIC_IB_HWE_DDSRXEQMEMORYPARITYERR 0x0000008000000000ULL
426#define QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR 0x0000004000000000ULL
427#define QLOGIC_IB_HWE_PCIE_UC_OCT0MEMORYPARITYERR 0x0000001000000000ULL
428#define QLOGIC_IB_HWE_PCIE_UC_OCT1MEMORYPARITYERR 0x0000002000000000ULL
429
430#define IBA7220_IBCC_LINKCMD_SHIFT 19
431
432/* kr_ibcddrctrl bits */
433#define IBA7220_IBC_DLIDLMC_MASK 0xFFFFFFFFUL
434#define IBA7220_IBC_DLIDLMC_SHIFT 32
435
436#define IBA7220_IBC_HRTBT_MASK (SYM_RMASK(IBCDDRCtrl, HRTBT_AUTO) | \
437 SYM_RMASK(IBCDDRCtrl, HRTBT_ENB))
438#define IBA7220_IBC_HRTBT_SHIFT SYM_LSB(IBCDDRCtrl, HRTBT_ENB)
439
440#define IBA7220_IBC_LANE_REV_SUPPORTED (1<<8)
441#define IBA7220_IBC_LREV_MASK 1
442#define IBA7220_IBC_LREV_SHIFT 8
443#define IBA7220_IBC_RXPOL_MASK 1
444#define IBA7220_IBC_RXPOL_SHIFT 7
445#define IBA7220_IBC_WIDTH_SHIFT 5
446#define IBA7220_IBC_WIDTH_MASK 0x3
447#define IBA7220_IBC_WIDTH_1X_ONLY (0 << IBA7220_IBC_WIDTH_SHIFT)
448#define IBA7220_IBC_WIDTH_4X_ONLY (1 << IBA7220_IBC_WIDTH_SHIFT)
449#define IBA7220_IBC_WIDTH_AUTONEG (2 << IBA7220_IBC_WIDTH_SHIFT)
450#define IBA7220_IBC_SPEED_AUTONEG (1 << 1)
451#define IBA7220_IBC_SPEED_SDR (1 << 2)
452#define IBA7220_IBC_SPEED_DDR (1 << 3)
453#define IBA7220_IBC_SPEED_AUTONEG_MASK (0x7 << 1)
454#define IBA7220_IBC_IBTA_1_2_MASK (1)
455
456/* kr_ibcddrstatus */
457/* link latency shift is 0, don't bother defining */
458#define IBA7220_DDRSTAT_LINKLAT_MASK 0x3ffffff
459
460/* kr_extstatus bits */
461#define QLOGIC_IB_EXTS_FREQSEL 0x2
462#define QLOGIC_IB_EXTS_SERDESSEL 0x4
463#define QLOGIC_IB_EXTS_MEMBIST_ENDTEST 0x0000000000004000
464#define QLOGIC_IB_EXTS_MEMBIST_DISABLED 0x0000000000008000
465
466/* kr_xgxsconfig bits */
467#define QLOGIC_IB_XGXS_RESET 0x5ULL
468#define QLOGIC_IB_XGXS_FC_SAFE (1ULL << 63)
469
470/* kr_rcvpktledcnt */
471#define IBA7220_LEDBLINK_ON_SHIFT 32 /* 4ns period on after packet */
472#define IBA7220_LEDBLINK_OFF_SHIFT 0 /* 4ns period off before next on */
473
474#define _QIB_GPIO_SDA_NUM 1
475#define _QIB_GPIO_SCL_NUM 0
476#define QIB_TWSI_EEPROM_DEV 0xA2 /* All Production 7220 cards. */
477#define QIB_TWSI_TEMP_DEV 0x98
478
479/* HW counter clock is at 4nsec */
480#define QIB_7220_PSXMITWAIT_CHECK_RATE 4000
481
482#define IBA7220_R_INTRAVAIL_SHIFT 17
483#define IBA7220_R_PKEY_DIS_SHIFT 34
484#define IBA7220_R_TAILUPD_SHIFT 35
485#define IBA7220_R_CTXTCFG_SHIFT 36
486
487#define IBA7220_HDRHEAD_PKTINT_SHIFT 32 /* interrupt cnt in upper 32 bits */
488
489/*
490 * the size bits give us 2^N, in KB units. 0 marks as invalid,
491 * and 7 is reserved. We currently use only 2KB and 4KB
492 */
493#define IBA7220_TID_SZ_SHIFT 37 /* shift to 3bit size selector */
494#define IBA7220_TID_SZ_2K (1UL << IBA7220_TID_SZ_SHIFT) /* 2KB */
495#define IBA7220_TID_SZ_4K (2UL << IBA7220_TID_SZ_SHIFT) /* 4KB */
496#define IBA7220_TID_PA_SHIFT 11U /* TID addr in chip stored w/o low bits */
497#define PBC_7220_VL15_SEND (1ULL << 63) /* pbc; VL15, no credit check */
498#define PBC_7220_VL15_SEND_CTRL (1ULL << 31) /* control version of same */
499
500#define AUTONEG_TRIES 5 /* sequential retries to negotiate DDR */
501
502/* packet rate matching delay multiplier */
503static u8 rate_to_delay[2][2] = {
504 /* 1x, 4x */
505 { 8, 2 }, /* SDR */
506 { 4, 1 } /* DDR */
507};
508
509static u8 ib_rate_to_delay[IB_RATE_120_GBPS + 1] = {
510 [IB_RATE_2_5_GBPS] = 8,
511 [IB_RATE_5_GBPS] = 4,
512 [IB_RATE_10_GBPS] = 2,
513 [IB_RATE_20_GBPS] = 1
514};
515
516#define IBA7220_LINKSPEED_SHIFT SYM_LSB(IBCStatus, LinkSpeedActive)
517#define IBA7220_LINKWIDTH_SHIFT SYM_LSB(IBCStatus, LinkWidthActive)
518
519/* link training states, from IBC */
520#define IB_7220_LT_STATE_DISABLED 0x00
521#define IB_7220_LT_STATE_LINKUP 0x01
522#define IB_7220_LT_STATE_POLLACTIVE 0x02
523#define IB_7220_LT_STATE_POLLQUIET 0x03
524#define IB_7220_LT_STATE_SLEEPDELAY 0x04
525#define IB_7220_LT_STATE_SLEEPQUIET 0x05
526#define IB_7220_LT_STATE_CFGDEBOUNCE 0x08
527#define IB_7220_LT_STATE_CFGRCVFCFG 0x09
528#define IB_7220_LT_STATE_CFGWAITRMT 0x0a
529#define IB_7220_LT_STATE_CFGIDLE 0x0b
530#define IB_7220_LT_STATE_RECOVERRETRAIN 0x0c
531#define IB_7220_LT_STATE_RECOVERWAITRMT 0x0e
532#define IB_7220_LT_STATE_RECOVERIDLE 0x0f
533
534/* link state machine states from IBC */
535#define IB_7220_L_STATE_DOWN 0x0
536#define IB_7220_L_STATE_INIT 0x1
537#define IB_7220_L_STATE_ARM 0x2
538#define IB_7220_L_STATE_ACTIVE 0x3
539#define IB_7220_L_STATE_ACT_DEFER 0x4
540
541static const u8 qib_7220_physportstate[0x20] = {
542 [IB_7220_LT_STATE_DISABLED] = IB_PHYSPORTSTATE_DISABLED,
543 [IB_7220_LT_STATE_LINKUP] = IB_PHYSPORTSTATE_LINKUP,
544 [IB_7220_LT_STATE_POLLACTIVE] = IB_PHYSPORTSTATE_POLL,
545 [IB_7220_LT_STATE_POLLQUIET] = IB_PHYSPORTSTATE_POLL,
546 [IB_7220_LT_STATE_SLEEPDELAY] = IB_PHYSPORTSTATE_SLEEP,
547 [IB_7220_LT_STATE_SLEEPQUIET] = IB_PHYSPORTSTATE_SLEEP,
548 [IB_7220_LT_STATE_CFGDEBOUNCE] =
549 IB_PHYSPORTSTATE_CFG_TRAIN,
550 [IB_7220_LT_STATE_CFGRCVFCFG] =
551 IB_PHYSPORTSTATE_CFG_TRAIN,
552 [IB_7220_LT_STATE_CFGWAITRMT] =
553 IB_PHYSPORTSTATE_CFG_TRAIN,
554 [IB_7220_LT_STATE_CFGIDLE] = IB_PHYSPORTSTATE_CFG_TRAIN,
555 [IB_7220_LT_STATE_RECOVERRETRAIN] =
556 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
557 [IB_7220_LT_STATE_RECOVERWAITRMT] =
558 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
559 [IB_7220_LT_STATE_RECOVERIDLE] =
560 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
561 [0x10] = IB_PHYSPORTSTATE_CFG_TRAIN,
562 [0x11] = IB_PHYSPORTSTATE_CFG_TRAIN,
563 [0x12] = IB_PHYSPORTSTATE_CFG_TRAIN,
564 [0x13] = IB_PHYSPORTSTATE_CFG_TRAIN,
565 [0x14] = IB_PHYSPORTSTATE_CFG_TRAIN,
566 [0x15] = IB_PHYSPORTSTATE_CFG_TRAIN,
567 [0x16] = IB_PHYSPORTSTATE_CFG_TRAIN,
568 [0x17] = IB_PHYSPORTSTATE_CFG_TRAIN
569};
570
571int qib_special_trigger;
572module_param_named(special_trigger, qib_special_trigger, int, S_IRUGO);
573MODULE_PARM_DESC(special_trigger, "Enable SpecialTrigger arm/launch");
574
575#define IBCBUSFRSPCPARITYERR HWE_MASK(IBCBusFromSPCParityErr)
576#define IBCBUSTOSPCPARITYERR HWE_MASK(IBCBusToSPCParityErr)
577
578#define SYM_MASK_BIT(regname, fldname, bit) ((u64) \
579 (1ULL << (SYM_LSB(regname, fldname) + (bit))))
580
581#define TXEMEMPARITYERR_PIOBUF \
582 SYM_MASK_BIT(HwErrMask, TXEMemParityErrMask, 0)
583#define TXEMEMPARITYERR_PIOPBC \
584 SYM_MASK_BIT(HwErrMask, TXEMemParityErrMask, 1)
585#define TXEMEMPARITYERR_PIOLAUNCHFIFO \
586 SYM_MASK_BIT(HwErrMask, TXEMemParityErrMask, 2)
587
588#define RXEMEMPARITYERR_RCVBUF \
589 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 0)
590#define RXEMEMPARITYERR_LOOKUPQ \
591 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 1)
592#define RXEMEMPARITYERR_EXPTID \
593 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 2)
594#define RXEMEMPARITYERR_EAGERTID \
595 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 3)
596#define RXEMEMPARITYERR_FLAGBUF \
597 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 4)
598#define RXEMEMPARITYERR_DATAINFO \
599 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 5)
600#define RXEMEMPARITYERR_HDRINFO \
601 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 6)
602
603/* 7220 specific hardware errors... */
604static const struct qib_hwerror_msgs qib_7220_hwerror_msgs[] = {
605 /* generic hardware errors */
606 QLOGIC_IB_HWE_MSG(IBCBUSFRSPCPARITYERR, "QIB2IB Parity"),
607 QLOGIC_IB_HWE_MSG(IBCBUSTOSPCPARITYERR, "IB2QIB Parity"),
608
609 QLOGIC_IB_HWE_MSG(TXEMEMPARITYERR_PIOBUF,
610 "TXE PIOBUF Memory Parity"),
611 QLOGIC_IB_HWE_MSG(TXEMEMPARITYERR_PIOPBC,
612 "TXE PIOPBC Memory Parity"),
613 QLOGIC_IB_HWE_MSG(TXEMEMPARITYERR_PIOLAUNCHFIFO,
614 "TXE PIOLAUNCHFIFO Memory Parity"),
615
616 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_RCVBUF,
617 "RXE RCVBUF Memory Parity"),
618 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_LOOKUPQ,
619 "RXE LOOKUPQ Memory Parity"),
620 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_EAGERTID,
621 "RXE EAGERTID Memory Parity"),
622 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_EXPTID,
623 "RXE EXPTID Memory Parity"),
624 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_FLAGBUF,
625 "RXE FLAGBUF Memory Parity"),
626 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_DATAINFO,
627 "RXE DATAINFO Memory Parity"),
628 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_HDRINFO,
629 "RXE HDRINFO Memory Parity"),
630
631 /* chip-specific hardware errors */
632 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEPOISONEDTLP,
633 "PCIe Poisoned TLP"),
634 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIECPLTIMEOUT,
635 "PCIe completion timeout"),
636 /*
637 * In practice, it's unlikely wthat we'll see PCIe PLL, or bus
638 * parity or memory parity error failures, because most likely we
639 * won't be able to talk to the core of the chip. Nonetheless, we
640 * might see them, if they are in parts of the PCIe core that aren't
641 * essential.
642 */
643 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIE1PLLFAILED,
644 "PCIePLL1"),
645 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIE0PLLFAILED,
646 "PCIePLL0"),
647 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEBUSPARITYXTLH,
648 "PCIe XTLH core parity"),
649 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEBUSPARITYXADM,
650 "PCIe ADM TX core parity"),
651 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEBUSPARITYRADM,
652 "PCIe ADM RX core parity"),
653 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_SERDESPLLFAILED,
654 "SerDes PLL"),
655 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIECPLDATAQUEUEERR,
656 "PCIe cpl header queue"),
657 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIECPLHDRQUEUEERR,
658 "PCIe cpl data queue"),
659 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_SDMAMEMREADERR,
660 "Send DMA memory read"),
661 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_CLK_UC_PLLNOTLOCKED,
662 "uC PLL clock not locked"),
663 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIESERDESQ0PCLKNOTDETECT,
664 "PCIe serdes Q0 no clock"),
665 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIESERDESQ1PCLKNOTDETECT,
666 "PCIe serdes Q1 no clock"),
667 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIESERDESQ2PCLKNOTDETECT,
668 "PCIe serdes Q2 no clock"),
669 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIESERDESQ3PCLKNOTDETECT,
670 "PCIe serdes Q3 no clock"),
671 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_DDSRXEQMEMORYPARITYERR,
672 "DDS RXEQ memory parity"),
673 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR,
674 "IB uC memory parity"),
675 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIE_UC_OCT0MEMORYPARITYERR,
676 "PCIe uC oct0 memory parity"),
677 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIE_UC_OCT1MEMORYPARITYERR,
678 "PCIe uC oct1 memory parity"),
679};
680
681#define RXE_PARITY (RXEMEMPARITYERR_EAGERTID|RXEMEMPARITYERR_EXPTID)
682
683#define QLOGIC_IB_E_PKTERRS (\
684 ERR_MASK(SendPktLenErr) | \
685 ERR_MASK(SendDroppedDataPktErr) | \
686 ERR_MASK(RcvVCRCErr) | \
687 ERR_MASK(RcvICRCErr) | \
688 ERR_MASK(RcvShortPktLenErr) | \
689 ERR_MASK(RcvEBPErr))
690
691/* Convenience for decoding Send DMA errors */
692#define QLOGIC_IB_E_SDMAERRS ( \
693 ERR_MASK(SDmaGenMismatchErr) | \
694 ERR_MASK(SDmaOutOfBoundErr) | \
695 ERR_MASK(SDmaTailOutOfBoundErr) | ERR_MASK(SDmaBaseErr) | \
696 ERR_MASK(SDma1stDescErr) | ERR_MASK(SDmaRpyTagErr) | \
697 ERR_MASK(SDmaDwEnErr) | ERR_MASK(SDmaMissingDwErr) | \
698 ERR_MASK(SDmaUnexpDataErr) | \
699 ERR_MASK(SDmaDescAddrMisalignErr) | \
700 ERR_MASK(SDmaDisabledErr) | \
701 ERR_MASK(SendBufMisuseErr))
702
703/* These are all rcv-related errors which we want to count for stats */
704#define E_SUM_PKTERRS \
705 (ERR_MASK(RcvHdrLenErr) | ERR_MASK(RcvBadTidErr) | \
706 ERR_MASK(RcvBadVersionErr) | ERR_MASK(RcvHdrErr) | \
707 ERR_MASK(RcvLongPktLenErr) | ERR_MASK(RcvShortPktLenErr) | \
708 ERR_MASK(RcvMaxPktLenErr) | ERR_MASK(RcvMinPktLenErr) | \
709 ERR_MASK(RcvFormatErr) | ERR_MASK(RcvUnsupportedVLErr) | \
710 ERR_MASK(RcvUnexpectedCharErr) | ERR_MASK(RcvEBPErr))
711
712/* These are all send-related errors which we want to count for stats */
713#define E_SUM_ERRS \
714 (ERR_MASK(SendPioArmLaunchErr) | ERR_MASK(SendUnexpectedPktNumErr) | \
715 ERR_MASK(SendDroppedDataPktErr) | ERR_MASK(SendDroppedSmpPktErr) | \
716 ERR_MASK(SendMaxPktLenErr) | ERR_MASK(SendUnsupportedVLErr) | \
717 ERR_MASK(SendMinPktLenErr) | ERR_MASK(SendPktLenErr) | \
718 ERR_MASK(InvalidAddrErr))
719
720/*
721 * this is similar to E_SUM_ERRS, but can't ignore armlaunch, don't ignore
722 * errors not related to freeze and cancelling buffers. Can't ignore
723 * armlaunch because could get more while still cleaning up, and need
724 * to cancel those as they happen.
725 */
726#define E_SPKT_ERRS_IGNORE \
727 (ERR_MASK(SendDroppedDataPktErr) | ERR_MASK(SendDroppedSmpPktErr) | \
728 ERR_MASK(SendMaxPktLenErr) | ERR_MASK(SendMinPktLenErr) | \
729 ERR_MASK(SendPktLenErr))
730
731/*
732 * these are errors that can occur when the link changes state while
733 * a packet is being sent or received. This doesn't cover things
734 * like EBP or VCRC that can be the result of a sending having the
735 * link change state, so we receive a "known bad" packet.
736 */
737#define E_SUM_LINK_PKTERRS \
738 (ERR_MASK(SendDroppedDataPktErr) | ERR_MASK(SendDroppedSmpPktErr) | \
739 ERR_MASK(SendMinPktLenErr) | ERR_MASK(SendPktLenErr) | \
740 ERR_MASK(RcvShortPktLenErr) | ERR_MASK(RcvMinPktLenErr) | \
741 ERR_MASK(RcvUnexpectedCharErr))
742
743static void autoneg_7220_work(struct work_struct *);
744static u32 __iomem *qib_7220_getsendbuf(struct qib_pportdata *, u64, u32 *);
745
746/*
747 * Called when we might have an error that is specific to a particular
748 * PIO buffer, and may need to cancel that buffer, so it can be re-used.
749 * because we don't need to force the update of pioavail.
750 */
751static void qib_disarm_7220_senderrbufs(struct qib_pportdata *ppd)
752{
753 unsigned long sbuf[3];
754 struct qib_devdata *dd = ppd->dd;
755
756 /*
757 * It's possible that sendbuffererror could have bits set; might
758 * have already done this as a result of hardware error handling.
759 */
760 /* read these before writing errorclear */
761 sbuf[0] = qib_read_kreg64(dd, kr_sendbuffererror);
762 sbuf[1] = qib_read_kreg64(dd, kr_sendbuffererror + 1);
763 sbuf[2] = qib_read_kreg64(dd, kr_sendbuffererror + 2);
764
765 if (sbuf[0] || sbuf[1] || sbuf[2])
766 qib_disarm_piobufs_set(dd, sbuf,
767 dd->piobcnt2k + dd->piobcnt4k);
768}
769
770static void qib_7220_txe_recover(struct qib_devdata *dd)
771{
772 qib_devinfo(dd->pcidev, "Recovering from TXE PIO parity error\n");
773 qib_disarm_7220_senderrbufs(dd->pport);
774}
775
776/*
777 * This is called with interrupts disabled and sdma_lock held.
778 */
779static void qib_7220_sdma_sendctrl(struct qib_pportdata *ppd, unsigned op)
780{
781 struct qib_devdata *dd = ppd->dd;
782 u64 set_sendctrl = 0;
783 u64 clr_sendctrl = 0;
784
785 if (op & QIB_SDMA_SENDCTRL_OP_ENABLE)
786 set_sendctrl |= SYM_MASK(SendCtrl, SDmaEnable);
787 else
788 clr_sendctrl |= SYM_MASK(SendCtrl, SDmaEnable);
789
790 if (op & QIB_SDMA_SENDCTRL_OP_INTENABLE)
791 set_sendctrl |= SYM_MASK(SendCtrl, SDmaIntEnable);
792 else
793 clr_sendctrl |= SYM_MASK(SendCtrl, SDmaIntEnable);
794
795 if (op & QIB_SDMA_SENDCTRL_OP_HALT)
796 set_sendctrl |= SYM_MASK(SendCtrl, SDmaHalt);
797 else
798 clr_sendctrl |= SYM_MASK(SendCtrl, SDmaHalt);
799
800 spin_lock(&dd->sendctrl_lock);
801
802 dd->sendctrl |= set_sendctrl;
803 dd->sendctrl &= ~clr_sendctrl;
804
805 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
806 qib_write_kreg(dd, kr_scratch, 0);
807
808 spin_unlock(&dd->sendctrl_lock);
809}
810
811static void qib_decode_7220_sdma_errs(struct qib_pportdata *ppd,
812 u64 err, char *buf, size_t blen)
813{
814 static const struct {
815 u64 err;
816 const char *msg;
817 } errs[] = {
818 { ERR_MASK(SDmaGenMismatchErr),
819 "SDmaGenMismatch" },
820 { ERR_MASK(SDmaOutOfBoundErr),
821 "SDmaOutOfBound" },
822 { ERR_MASK(SDmaTailOutOfBoundErr),
823 "SDmaTailOutOfBound" },
824 { ERR_MASK(SDmaBaseErr),
825 "SDmaBase" },
826 { ERR_MASK(SDma1stDescErr),
827 "SDma1stDesc" },
828 { ERR_MASK(SDmaRpyTagErr),
829 "SDmaRpyTag" },
830 { ERR_MASK(SDmaDwEnErr),
831 "SDmaDwEn" },
832 { ERR_MASK(SDmaMissingDwErr),
833 "SDmaMissingDw" },
834 { ERR_MASK(SDmaUnexpDataErr),
835 "SDmaUnexpData" },
836 { ERR_MASK(SDmaDescAddrMisalignErr),
837 "SDmaDescAddrMisalign" },
838 { ERR_MASK(SendBufMisuseErr),
839 "SendBufMisuse" },
840 { ERR_MASK(SDmaDisabledErr),
841 "SDmaDisabled" },
842 };
843 int i;
844 size_t bidx = 0;
845
846 for (i = 0; i < ARRAY_SIZE(errs); i++) {
847 if (err & errs[i].err)
848 bidx += scnprintf(buf + bidx, blen - bidx,
849 "%s ", errs[i].msg);
850 }
851}
852
853/*
854 * This is called as part of link down clean up so disarm and flush
855 * all send buffers so that SMP packets can be sent.
856 */
857static void qib_7220_sdma_hw_clean_up(struct qib_pportdata *ppd)
858{
859 /* This will trigger the Abort interrupt */
860 sendctrl_7220_mod(ppd, QIB_SENDCTRL_DISARM_ALL | QIB_SENDCTRL_FLUSH |
861 QIB_SENDCTRL_AVAIL_BLIP);
862 ppd->dd->upd_pio_shadow = 1; /* update our idea of what's busy */
863}
864
865static void qib_sdma_7220_setlengen(struct qib_pportdata *ppd)
866{
867 /*
868 * Set SendDmaLenGen and clear and set
869 * the MSB of the generation count to enable generation checking
870 * and load the internal generation counter.
871 */
872 qib_write_kreg(ppd->dd, kr_senddmalengen, ppd->sdma_descq_cnt);
873 qib_write_kreg(ppd->dd, kr_senddmalengen,
874 ppd->sdma_descq_cnt |
875 (1ULL << QIB_7220_SendDmaLenGen_Generation_MSB));
876}
877
878static void qib_7220_sdma_hw_start_up(struct qib_pportdata *ppd)
879{
880 qib_sdma_7220_setlengen(ppd);
881 qib_sdma_update_7220_tail(ppd, 0); /* Set SendDmaTail */
882 ppd->sdma_head_dma[0] = 0;
883}
884
885#define DISABLES_SDMA ( \
886 ERR_MASK(SDmaDisabledErr) | \
887 ERR_MASK(SDmaBaseErr) | \
888 ERR_MASK(SDmaTailOutOfBoundErr) | \
889 ERR_MASK(SDmaOutOfBoundErr) | \
890 ERR_MASK(SDma1stDescErr) | \
891 ERR_MASK(SDmaRpyTagErr) | \
892 ERR_MASK(SDmaGenMismatchErr) | \
893 ERR_MASK(SDmaDescAddrMisalignErr) | \
894 ERR_MASK(SDmaMissingDwErr) | \
895 ERR_MASK(SDmaDwEnErr))
896
897static void sdma_7220_errors(struct qib_pportdata *ppd, u64 errs)
898{
899 unsigned long flags;
900 struct qib_devdata *dd = ppd->dd;
901 char *msg;
902
903 errs &= QLOGIC_IB_E_SDMAERRS;
904
905 msg = dd->cspec->sdmamsgbuf;
Mike Marciniszyn041af0b2015-01-16 10:50:32 -0500906 qib_decode_7220_sdma_errs(ppd, errs, msg,
907 sizeof(dd->cspec->sdmamsgbuf));
Ralph Campbellf9315512010-05-23 21:44:54 -0700908 spin_lock_irqsave(&ppd->sdma_lock, flags);
909
910 if (errs & ERR_MASK(SendBufMisuseErr)) {
911 unsigned long sbuf[3];
912
913 sbuf[0] = qib_read_kreg64(dd, kr_sendbuffererror);
914 sbuf[1] = qib_read_kreg64(dd, kr_sendbuffererror + 1);
915 sbuf[2] = qib_read_kreg64(dd, kr_sendbuffererror + 2);
916
917 qib_dev_err(ppd->dd,
918 "IB%u:%u SendBufMisuse: %04lx %016lx %016lx\n",
919 ppd->dd->unit, ppd->port, sbuf[2], sbuf[1],
920 sbuf[0]);
921 }
922
923 if (errs & ERR_MASK(SDmaUnexpDataErr))
924 qib_dev_err(dd, "IB%u:%u SDmaUnexpData\n", ppd->dd->unit,
925 ppd->port);
926
927 switch (ppd->sdma_state.current_state) {
928 case qib_sdma_state_s00_hw_down:
929 /* not expecting any interrupts */
930 break;
931
932 case qib_sdma_state_s10_hw_start_up_wait:
933 /* handled in intr path */
934 break;
935
936 case qib_sdma_state_s20_idle:
937 /* not expecting any interrupts */
938 break;
939
940 case qib_sdma_state_s30_sw_clean_up_wait:
941 /* not expecting any interrupts */
942 break;
943
944 case qib_sdma_state_s40_hw_clean_up_wait:
945 if (errs & ERR_MASK(SDmaDisabledErr))
946 __qib_sdma_process_event(ppd,
947 qib_sdma_event_e50_hw_cleaned);
948 break;
949
950 case qib_sdma_state_s50_hw_halt_wait:
951 /* handled in intr path */
952 break;
953
954 case qib_sdma_state_s99_running:
955 if (errs & DISABLES_SDMA)
956 __qib_sdma_process_event(ppd,
957 qib_sdma_event_e7220_err_halted);
958 break;
959 }
960
961 spin_unlock_irqrestore(&ppd->sdma_lock, flags);
962}
963
964/*
965 * Decode the error status into strings, deciding whether to always
966 * print * it or not depending on "normal packet errors" vs everything
967 * else. Return 1 if "real" errors, otherwise 0 if only packet
968 * errors, so caller can decide what to print with the string.
969 */
970static int qib_decode_7220_err(struct qib_devdata *dd, char *buf, size_t blen,
971 u64 err)
972{
973 int iserr = 1;
974
975 *buf = '\0';
976 if (err & QLOGIC_IB_E_PKTERRS) {
977 if (!(err & ~QLOGIC_IB_E_PKTERRS))
978 iserr = 0;
979 if ((err & ERR_MASK(RcvICRCErr)) &&
980 !(err & (ERR_MASK(RcvVCRCErr) | ERR_MASK(RcvEBPErr))))
981 strlcat(buf, "CRC ", blen);
982 if (!iserr)
983 goto done;
984 }
985 if (err & ERR_MASK(RcvHdrLenErr))
986 strlcat(buf, "rhdrlen ", blen);
987 if (err & ERR_MASK(RcvBadTidErr))
988 strlcat(buf, "rbadtid ", blen);
989 if (err & ERR_MASK(RcvBadVersionErr))
990 strlcat(buf, "rbadversion ", blen);
991 if (err & ERR_MASK(RcvHdrErr))
992 strlcat(buf, "rhdr ", blen);
993 if (err & ERR_MASK(SendSpecialTriggerErr))
994 strlcat(buf, "sendspecialtrigger ", blen);
995 if (err & ERR_MASK(RcvLongPktLenErr))
996 strlcat(buf, "rlongpktlen ", blen);
997 if (err & ERR_MASK(RcvMaxPktLenErr))
998 strlcat(buf, "rmaxpktlen ", blen);
999 if (err & ERR_MASK(RcvMinPktLenErr))
1000 strlcat(buf, "rminpktlen ", blen);
1001 if (err & ERR_MASK(SendMinPktLenErr))
1002 strlcat(buf, "sminpktlen ", blen);
1003 if (err & ERR_MASK(RcvFormatErr))
1004 strlcat(buf, "rformaterr ", blen);
1005 if (err & ERR_MASK(RcvUnsupportedVLErr))
1006 strlcat(buf, "runsupvl ", blen);
1007 if (err & ERR_MASK(RcvUnexpectedCharErr))
1008 strlcat(buf, "runexpchar ", blen);
1009 if (err & ERR_MASK(RcvIBFlowErr))
1010 strlcat(buf, "ribflow ", blen);
1011 if (err & ERR_MASK(SendUnderRunErr))
1012 strlcat(buf, "sunderrun ", blen);
1013 if (err & ERR_MASK(SendPioArmLaunchErr))
1014 strlcat(buf, "spioarmlaunch ", blen);
1015 if (err & ERR_MASK(SendUnexpectedPktNumErr))
1016 strlcat(buf, "sunexperrpktnum ", blen);
1017 if (err & ERR_MASK(SendDroppedSmpPktErr))
1018 strlcat(buf, "sdroppedsmppkt ", blen);
1019 if (err & ERR_MASK(SendMaxPktLenErr))
1020 strlcat(buf, "smaxpktlen ", blen);
1021 if (err & ERR_MASK(SendUnsupportedVLErr))
1022 strlcat(buf, "sunsupVL ", blen);
1023 if (err & ERR_MASK(InvalidAddrErr))
1024 strlcat(buf, "invalidaddr ", blen);
1025 if (err & ERR_MASK(RcvEgrFullErr))
1026 strlcat(buf, "rcvegrfull ", blen);
1027 if (err & ERR_MASK(RcvHdrFullErr))
1028 strlcat(buf, "rcvhdrfull ", blen);
1029 if (err & ERR_MASK(IBStatusChanged))
1030 strlcat(buf, "ibcstatuschg ", blen);
1031 if (err & ERR_MASK(RcvIBLostLinkErr))
1032 strlcat(buf, "riblostlink ", blen);
1033 if (err & ERR_MASK(HardwareErr))
1034 strlcat(buf, "hardware ", blen);
1035 if (err & ERR_MASK(ResetNegated))
1036 strlcat(buf, "reset ", blen);
1037 if (err & QLOGIC_IB_E_SDMAERRS)
1038 qib_decode_7220_sdma_errs(dd->pport, err, buf, blen);
1039 if (err & ERR_MASK(InvalidEEPCmd))
1040 strlcat(buf, "invalideepromcmd ", blen);
1041done:
1042 return iserr;
1043}
1044
Kees Cook4037c922017-10-04 17:45:35 -07001045static void reenable_7220_chase(struct timer_list *t)
Ralph Campbellf9315512010-05-23 21:44:54 -07001046{
Kees Cook4037c922017-10-04 17:45:35 -07001047 struct qib_chippport_specific *cpspec = from_timer(cpspec, t,
1048 chase_timer);
1049 struct qib_pportdata *ppd = &cpspec->pportdata;
Mike Marciniszynda12c1f2015-01-16 11:23:31 -05001050
Ralph Campbellf9315512010-05-23 21:44:54 -07001051 ppd->cpspec->chase_timer.expires = 0;
1052 qib_set_ib_7220_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
1053 QLOGIC_IB_IBCC_LINKINITCMD_POLL);
1054}
1055
1056static void handle_7220_chase(struct qib_pportdata *ppd, u64 ibcst)
1057{
1058 u8 ibclt;
Mike Marciniszyn8482d5d2011-11-09 13:36:08 -05001059 unsigned long tnow;
Ralph Campbellf9315512010-05-23 21:44:54 -07001060
1061 ibclt = (u8)SYM_FIELD(ibcst, IBCStatus, LinkTrainingState);
1062
1063 /*
1064 * Detect and handle the state chase issue, where we can
1065 * get stuck if we are unlucky on timing on both sides of
1066 * the link. If we are, we disable, set a timer, and
1067 * then re-enable.
1068 */
1069 switch (ibclt) {
1070 case IB_7220_LT_STATE_CFGRCVFCFG:
1071 case IB_7220_LT_STATE_CFGWAITRMT:
1072 case IB_7220_LT_STATE_TXREVLANES:
1073 case IB_7220_LT_STATE_CFGENH:
Mike Marciniszyn8482d5d2011-11-09 13:36:08 -05001074 tnow = jiffies;
Ralph Campbellf9315512010-05-23 21:44:54 -07001075 if (ppd->cpspec->chase_end &&
Mike Marciniszyn8482d5d2011-11-09 13:36:08 -05001076 time_after(tnow, ppd->cpspec->chase_end)) {
Ralph Campbellf9315512010-05-23 21:44:54 -07001077 ppd->cpspec->chase_end = 0;
1078 qib_set_ib_7220_lstate(ppd,
1079 QLOGIC_IB_IBCC_LINKCMD_DOWN,
1080 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
1081 ppd->cpspec->chase_timer.expires = jiffies +
1082 QIB_CHASE_DIS_TIME;
1083 add_timer(&ppd->cpspec->chase_timer);
1084 } else if (!ppd->cpspec->chase_end)
1085 ppd->cpspec->chase_end = tnow + QIB_CHASE_TIME;
1086 break;
1087
1088 default:
1089 ppd->cpspec->chase_end = 0;
1090 break;
1091 }
1092}
1093
1094static void handle_7220_errors(struct qib_devdata *dd, u64 errs)
1095{
1096 char *msg;
1097 u64 ignore_this_time = 0;
1098 u64 iserr = 0;
1099 int log_idx;
1100 struct qib_pportdata *ppd = dd->pport;
1101 u64 mask;
1102
1103 /* don't report errors that are masked */
1104 errs &= dd->cspec->errormask;
1105 msg = dd->cspec->emsgbuf;
1106
1107 /* do these first, they are most important */
1108 if (errs & ERR_MASK(HardwareErr))
Mike Marciniszyn041af0b2015-01-16 10:50:32 -05001109 qib_7220_handle_hwerrors(dd, msg, sizeof(dd->cspec->emsgbuf));
Ralph Campbellf9315512010-05-23 21:44:54 -07001110 else
1111 for (log_idx = 0; log_idx < QIB_EEP_LOG_CNT; ++log_idx)
1112 if (errs & dd->eep_st_masks[log_idx].errs_to_log)
1113 qib_inc_eeprom_err(dd, log_idx, 1);
1114
1115 if (errs & QLOGIC_IB_E_SDMAERRS)
1116 sdma_7220_errors(ppd, errs);
1117
1118 if (errs & ~IB_E_BITSEXTANT)
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001119 qib_dev_err(dd,
1120 "error interrupt with unknown errors %llx set\n",
1121 (unsigned long long) (errs & ~IB_E_BITSEXTANT));
Ralph Campbellf9315512010-05-23 21:44:54 -07001122
1123 if (errs & E_SUM_ERRS) {
1124 qib_disarm_7220_senderrbufs(ppd);
1125 if ((errs & E_SUM_LINK_PKTERRS) &&
1126 !(ppd->lflags & QIBL_LINKACTIVE)) {
1127 /*
1128 * This can happen when trying to bring the link
1129 * up, but the IB link changes state at the "wrong"
1130 * time. The IB logic then complains that the packet
1131 * isn't valid. We don't want to confuse people, so
1132 * we just don't print them, except at debug
1133 */
1134 ignore_this_time = errs & E_SUM_LINK_PKTERRS;
1135 }
1136 } else if ((errs & E_SUM_LINK_PKTERRS) &&
1137 !(ppd->lflags & QIBL_LINKACTIVE)) {
1138 /*
1139 * This can happen when SMA is trying to bring the link
1140 * up, but the IB link changes state at the "wrong" time.
1141 * The IB logic then complains that the packet isn't
1142 * valid. We don't want to confuse people, so we just
1143 * don't print them, except at debug
1144 */
1145 ignore_this_time = errs & E_SUM_LINK_PKTERRS;
1146 }
1147
1148 qib_write_kreg(dd, kr_errclear, errs);
1149
1150 errs &= ~ignore_this_time;
1151 if (!errs)
1152 goto done;
1153
1154 /*
1155 * The ones we mask off are handled specially below
1156 * or above. Also mask SDMADISABLED by default as it
1157 * is too chatty.
1158 */
1159 mask = ERR_MASK(IBStatusChanged) |
1160 ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr) |
1161 ERR_MASK(HardwareErr) | ERR_MASK(SDmaDisabledErr);
1162
Mike Marciniszyn041af0b2015-01-16 10:50:32 -05001163 qib_decode_7220_err(dd, msg, sizeof(dd->cspec->emsgbuf), errs & ~mask);
Ralph Campbellf9315512010-05-23 21:44:54 -07001164
1165 if (errs & E_SUM_PKTERRS)
1166 qib_stats.sps_rcverrs++;
1167 if (errs & E_SUM_ERRS)
1168 qib_stats.sps_txerrs++;
1169 iserr = errs & ~(E_SUM_PKTERRS | QLOGIC_IB_E_PKTERRS |
1170 ERR_MASK(SDmaDisabledErr));
1171
1172 if (errs & ERR_MASK(IBStatusChanged)) {
1173 u64 ibcs;
1174
1175 ibcs = qib_read_kreg64(dd, kr_ibcstatus);
1176 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
1177 handle_7220_chase(ppd, ibcs);
1178
1179 /* Update our picture of width and speed from chip */
1180 ppd->link_width_active =
1181 ((ibcs >> IBA7220_LINKWIDTH_SHIFT) & 1) ?
1182 IB_WIDTH_4X : IB_WIDTH_1X;
1183 ppd->link_speed_active =
1184 ((ibcs >> IBA7220_LINKSPEED_SHIFT) & 1) ?
1185 QIB_IB_DDR : QIB_IB_SDR;
1186
1187 /*
1188 * Since going into a recovery state causes the link state
1189 * to go down and since recovery is transitory, it is better
1190 * if we "miss" ever seeing the link training state go into
1191 * recovery (i.e., ignore this transition for link state
1192 * special handling purposes) without updating lastibcstat.
1193 */
1194 if (qib_7220_phys_portstate(ibcs) !=
1195 IB_PHYSPORTSTATE_LINK_ERR_RECOVER)
1196 qib_handle_e_ibstatuschanged(ppd, ibcs);
1197 }
1198
1199 if (errs & ERR_MASK(ResetNegated)) {
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001200 qib_dev_err(dd,
1201 "Got reset, requires re-init (unload and reload driver)\n");
Ralph Campbellf9315512010-05-23 21:44:54 -07001202 dd->flags &= ~QIB_INITTED; /* needs re-init */
1203 /* mark as having had error */
1204 *dd->devstatusp |= QIB_STATUS_HWERROR;
1205 *dd->pport->statusp &= ~QIB_STATUS_IB_CONF;
1206 }
1207
1208 if (*msg && iserr)
1209 qib_dev_porterr(dd, ppd->port, "%s error\n", msg);
1210
1211 if (ppd->state_wanted & ppd->lflags)
1212 wake_up_interruptible(&ppd->state_wait);
1213
1214 /*
1215 * If there were hdrq or egrfull errors, wake up any processes
1216 * waiting in poll. We used to try to check which contexts had
1217 * the overflow, but given the cost of that and the chip reads
1218 * to support it, it's better to just wake everybody up if we
1219 * get an overflow; waiters can poll again if it's not them.
1220 */
1221 if (errs & (ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr))) {
1222 qib_handle_urcv(dd, ~0U);
1223 if (errs & ERR_MASK(RcvEgrFullErr))
1224 qib_stats.sps_buffull++;
1225 else
1226 qib_stats.sps_hdrfull++;
1227 }
1228done:
1229 return;
1230}
1231
1232/* enable/disable chip from delivering interrupts */
1233static void qib_7220_set_intr_state(struct qib_devdata *dd, u32 enable)
1234{
1235 if (enable) {
1236 if (dd->flags & QIB_BADINTR)
1237 return;
1238 qib_write_kreg(dd, kr_intmask, ~0ULL);
1239 /* force re-interrupt of any pending interrupts. */
1240 qib_write_kreg(dd, kr_intclear, 0ULL);
1241 } else
1242 qib_write_kreg(dd, kr_intmask, 0ULL);
1243}
1244
1245/*
1246 * Try to cleanup as much as possible for anything that might have gone
1247 * wrong while in freeze mode, such as pio buffers being written by user
1248 * processes (causing armlaunch), send errors due to going into freeze mode,
1249 * etc., and try to avoid causing extra interrupts while doing so.
1250 * Forcibly update the in-memory pioavail register copies after cleanup
1251 * because the chip won't do it while in freeze mode (the register values
1252 * themselves are kept correct).
1253 * Make sure that we don't lose any important interrupts by using the chip
1254 * feature that says that writing 0 to a bit in *clear that is set in
1255 * *status will cause an interrupt to be generated again (if allowed by
1256 * the *mask value).
1257 * This is in chip-specific code because of all of the register accesses,
1258 * even though the details are similar on most chips.
1259 */
1260static void qib_7220_clear_freeze(struct qib_devdata *dd)
1261{
1262 /* disable error interrupts, to avoid confusion */
1263 qib_write_kreg(dd, kr_errmask, 0ULL);
1264
Masahiro Yamadab8a14f32017-02-27 14:29:50 -08001265 /* also disable interrupts; errormask is sometimes overwritten */
Ralph Campbellf9315512010-05-23 21:44:54 -07001266 qib_7220_set_intr_state(dd, 0);
1267
1268 qib_cancel_sends(dd->pport);
1269
1270 /* clear the freeze, and be sure chip saw it */
1271 qib_write_kreg(dd, kr_control, dd->control);
1272 qib_read_kreg32(dd, kr_scratch);
1273
1274 /* force in-memory update now we are out of freeze */
1275 qib_force_pio_avail_update(dd);
1276
1277 /*
1278 * force new interrupt if any hwerr, error or interrupt bits are
1279 * still set, and clear "safe" send packet errors related to freeze
1280 * and cancelling sends. Re-enable error interrupts before possible
1281 * force of re-interrupt on pending interrupts.
1282 */
1283 qib_write_kreg(dd, kr_hwerrclear, 0ULL);
1284 qib_write_kreg(dd, kr_errclear, E_SPKT_ERRS_IGNORE);
1285 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
1286 qib_7220_set_intr_state(dd, 1);
1287}
1288
1289/**
1290 * qib_7220_handle_hwerrors - display hardware errors.
1291 * @dd: the qlogic_ib device
1292 * @msg: the output buffer
1293 * @msgl: the size of the output buffer
1294 *
1295 * Use same msg buffer as regular errors to avoid excessive stack
1296 * use. Most hardware errors are catastrophic, but for right now,
1297 * we'll print them and continue. We reuse the same message buffer as
1298 * handle_7220_errors() to avoid excessive stack usage.
1299 */
1300static void qib_7220_handle_hwerrors(struct qib_devdata *dd, char *msg,
1301 size_t msgl)
1302{
1303 u64 hwerrs;
1304 u32 bits, ctrl;
1305 int isfatal = 0;
1306 char *bitsmsg;
1307 int log_idx;
1308
1309 hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
1310 if (!hwerrs)
1311 goto bail;
1312 if (hwerrs == ~0ULL) {
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001313 qib_dev_err(dd,
1314 "Read of hardware error status failed (all bits set); ignoring\n");
Ralph Campbellf9315512010-05-23 21:44:54 -07001315 goto bail;
1316 }
1317 qib_stats.sps_hwerrs++;
1318
1319 /*
1320 * Always clear the error status register, except MEMBISTFAIL,
1321 * regardless of whether we continue or stop using the chip.
1322 * We want that set so we know it failed, even across driver reload.
1323 * We'll still ignore it in the hwerrmask. We do this partly for
1324 * diagnostics, but also for support.
1325 */
1326 qib_write_kreg(dd, kr_hwerrclear,
1327 hwerrs & ~HWE_MASK(PowerOnBISTFailed));
1328
1329 hwerrs &= dd->cspec->hwerrmask;
1330
1331 /* We log some errors to EEPROM, check if we have any of those. */
1332 for (log_idx = 0; log_idx < QIB_EEP_LOG_CNT; ++log_idx)
1333 if (hwerrs & dd->eep_st_masks[log_idx].hwerrs_to_log)
1334 qib_inc_eeprom_err(dd, log_idx, 1);
1335 if (hwerrs & ~(TXEMEMPARITYERR_PIOBUF | TXEMEMPARITYERR_PIOPBC |
1336 RXE_PARITY))
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001337 qib_devinfo(dd->pcidev,
1338 "Hardware error: hwerr=0x%llx (cleared)\n",
1339 (unsigned long long) hwerrs);
Ralph Campbellf9315512010-05-23 21:44:54 -07001340
1341 if (hwerrs & ~IB_HWE_BITSEXTANT)
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001342 qib_dev_err(dd,
1343 "hwerror interrupt with unknown errors %llx set\n",
1344 (unsigned long long) (hwerrs & ~IB_HWE_BITSEXTANT));
Ralph Campbellf9315512010-05-23 21:44:54 -07001345
1346 if (hwerrs & QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR)
1347 qib_sd7220_clr_ibpar(dd);
1348
1349 ctrl = qib_read_kreg32(dd, kr_control);
1350 if ((ctrl & QLOGIC_IB_C_FREEZEMODE) && !dd->diag_client) {
1351 /*
1352 * Parity errors in send memory are recoverable by h/w
1353 * just do housekeeping, exit freeze mode and continue.
1354 */
1355 if (hwerrs & (TXEMEMPARITYERR_PIOBUF |
1356 TXEMEMPARITYERR_PIOPBC)) {
1357 qib_7220_txe_recover(dd);
1358 hwerrs &= ~(TXEMEMPARITYERR_PIOBUF |
1359 TXEMEMPARITYERR_PIOPBC);
1360 }
1361 if (hwerrs)
1362 isfatal = 1;
1363 else
1364 qib_7220_clear_freeze(dd);
1365 }
1366
1367 *msg = '\0';
1368
1369 if (hwerrs & HWE_MASK(PowerOnBISTFailed)) {
1370 isfatal = 1;
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001371 strlcat(msg,
1372 "[Memory BIST test failed, InfiniPath hardware unusable]",
1373 msgl);
Ralph Campbellf9315512010-05-23 21:44:54 -07001374 /* ignore from now on, so disable until driver reloaded */
1375 dd->cspec->hwerrmask &= ~HWE_MASK(PowerOnBISTFailed);
1376 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
1377 }
1378
1379 qib_format_hwerrors(hwerrs, qib_7220_hwerror_msgs,
1380 ARRAY_SIZE(qib_7220_hwerror_msgs), msg, msgl);
1381
1382 bitsmsg = dd->cspec->bitsmsgbuf;
1383 if (hwerrs & (QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK <<
1384 QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT)) {
1385 bits = (u32) ((hwerrs >>
1386 QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT) &
1387 QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK);
Mike Marciniszyn041af0b2015-01-16 10:50:32 -05001388 snprintf(bitsmsg, sizeof(dd->cspec->bitsmsgbuf),
Ralph Campbellf9315512010-05-23 21:44:54 -07001389 "[PCIe Mem Parity Errs %x] ", bits);
1390 strlcat(msg, bitsmsg, msgl);
1391 }
1392
1393#define _QIB_PLL_FAIL (QLOGIC_IB_HWE_COREPLL_FBSLIP | \
1394 QLOGIC_IB_HWE_COREPLL_RFSLIP)
1395
1396 if (hwerrs & _QIB_PLL_FAIL) {
1397 isfatal = 1;
Mike Marciniszyn041af0b2015-01-16 10:50:32 -05001398 snprintf(bitsmsg, sizeof(dd->cspec->bitsmsgbuf),
Ralph Campbellf9315512010-05-23 21:44:54 -07001399 "[PLL failed (%llx), InfiniPath hardware unusable]",
1400 (unsigned long long) hwerrs & _QIB_PLL_FAIL);
1401 strlcat(msg, bitsmsg, msgl);
1402 /* ignore from now on, so disable until driver reloaded */
1403 dd->cspec->hwerrmask &= ~(hwerrs & _QIB_PLL_FAIL);
1404 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
1405 }
1406
1407 if (hwerrs & QLOGIC_IB_HWE_SERDESPLLFAILED) {
1408 /*
1409 * If it occurs, it is left masked since the eternal
1410 * interface is unused.
1411 */
1412 dd->cspec->hwerrmask &= ~QLOGIC_IB_HWE_SERDESPLLFAILED;
1413 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
1414 }
1415
1416 qib_dev_err(dd, "%s hardware error\n", msg);
1417
1418 if (isfatal && !dd->diag_client) {
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001419 qib_dev_err(dd,
1420 "Fatal Hardware Error, no longer usable, SN %.16s\n",
1421 dd->serial);
Ralph Campbellf9315512010-05-23 21:44:54 -07001422 /*
1423 * For /sys status file and user programs to print; if no
1424 * trailing brace is copied, we'll know it was truncated.
1425 */
1426 if (dd->freezemsg)
1427 snprintf(dd->freezemsg, dd->freezelen,
1428 "{%s}", msg);
1429 qib_disable_after_error(dd);
1430 }
1431bail:;
1432}
1433
1434/**
1435 * qib_7220_init_hwerrors - enable hardware errors
1436 * @dd: the qlogic_ib device
1437 *
1438 * now that we have finished initializing everything that might reasonably
1439 * cause a hardware error, and cleared those errors bits as they occur,
1440 * we can enable hardware errors in the mask (potentially enabling
1441 * freeze mode), and enable hardware errors as errors (along with
1442 * everything else) in errormask
1443 */
1444static void qib_7220_init_hwerrors(struct qib_devdata *dd)
1445{
1446 u64 val;
1447 u64 extsval;
1448
1449 extsval = qib_read_kreg64(dd, kr_extstatus);
1450
1451 if (!(extsval & (QLOGIC_IB_EXTS_MEMBIST_ENDTEST |
1452 QLOGIC_IB_EXTS_MEMBIST_DISABLED)))
1453 qib_dev_err(dd, "MemBIST did not complete!\n");
1454 if (extsval & QLOGIC_IB_EXTS_MEMBIST_DISABLED)
1455 qib_devinfo(dd->pcidev, "MemBIST is disabled.\n");
1456
1457 val = ~0ULL; /* default to all hwerrors become interrupts, */
1458
1459 val &= ~QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR;
1460 dd->cspec->hwerrmask = val;
1461
1462 qib_write_kreg(dd, kr_hwerrclear, ~HWE_MASK(PowerOnBISTFailed));
1463 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
1464
1465 /* clear all */
1466 qib_write_kreg(dd, kr_errclear, ~0ULL);
1467 /* enable errors that are masked, at least this first time. */
1468 qib_write_kreg(dd, kr_errmask, ~0ULL);
1469 dd->cspec->errormask = qib_read_kreg64(dd, kr_errmask);
1470 /* clear any interrupts up to this point (ints still not enabled) */
1471 qib_write_kreg(dd, kr_intclear, ~0ULL);
1472}
1473
1474/*
1475 * Disable and enable the armlaunch error. Used for PIO bandwidth testing
1476 * on chips that are count-based, rather than trigger-based. There is no
1477 * reference counting, but that's also fine, given the intended use.
1478 * Only chip-specific because it's all register accesses
1479 */
1480static void qib_set_7220_armlaunch(struct qib_devdata *dd, u32 enable)
1481{
1482 if (enable) {
1483 qib_write_kreg(dd, kr_errclear, ERR_MASK(SendPioArmLaunchErr));
1484 dd->cspec->errormask |= ERR_MASK(SendPioArmLaunchErr);
1485 } else
1486 dd->cspec->errormask &= ~ERR_MASK(SendPioArmLaunchErr);
1487 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
1488}
1489
1490/*
1491 * Formerly took parameter <which> in pre-shifted,
1492 * pre-merged form with LinkCmd and LinkInitCmd
1493 * together, and assuming the zero was NOP.
1494 */
1495static void qib_set_ib_7220_lstate(struct qib_pportdata *ppd, u16 linkcmd,
1496 u16 linitcmd)
1497{
1498 u64 mod_wd;
1499 struct qib_devdata *dd = ppd->dd;
1500 unsigned long flags;
1501
1502 if (linitcmd == QLOGIC_IB_IBCC_LINKINITCMD_DISABLE) {
1503 /*
1504 * If we are told to disable, note that so link-recovery
1505 * code does not attempt to bring us back up.
1506 */
1507 spin_lock_irqsave(&ppd->lflags_lock, flags);
1508 ppd->lflags |= QIBL_IB_LINK_DISABLED;
1509 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
1510 } else if (linitcmd || linkcmd == QLOGIC_IB_IBCC_LINKCMD_DOWN) {
1511 /*
1512 * Any other linkinitcmd will lead to LINKDOWN and then
1513 * to INIT (if all is well), so clear flag to let
1514 * link-recovery code attempt to bring us back up.
1515 */
1516 spin_lock_irqsave(&ppd->lflags_lock, flags);
1517 ppd->lflags &= ~QIBL_IB_LINK_DISABLED;
1518 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
1519 }
1520
1521 mod_wd = (linkcmd << IBA7220_IBCC_LINKCMD_SHIFT) |
1522 (linitcmd << QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
1523
1524 qib_write_kreg(dd, kr_ibcctrl, ppd->cpspec->ibcctrl | mod_wd);
1525 /* write to chip to prevent back-to-back writes of ibc reg */
1526 qib_write_kreg(dd, kr_scratch, 0);
1527}
1528
1529/*
1530 * All detailed interaction with the SerDes has been moved to qib_sd7220.c
1531 *
1532 * The portion of IBA7220-specific bringup_serdes() that actually deals with
1533 * registers and memory within the SerDes itself is qib_sd7220_init().
1534 */
1535
1536/**
1537 * qib_7220_bringup_serdes - bring up the serdes
1538 * @ppd: physical port on the qlogic_ib device
1539 */
1540static int qib_7220_bringup_serdes(struct qib_pportdata *ppd)
1541{
1542 struct qib_devdata *dd = ppd->dd;
1543 u64 val, prev_val, guid, ibc;
1544 int ret = 0;
1545
1546 /* Put IBC in reset, sends disabled */
1547 dd->control &= ~QLOGIC_IB_C_LINKENABLE;
1548 qib_write_kreg(dd, kr_control, 0ULL);
1549
1550 if (qib_compat_ddr_negotiate) {
1551 ppd->cpspec->ibdeltainprog = 1;
1552 ppd->cpspec->ibsymsnap = read_7220_creg32(dd, cr_ibsymbolerr);
1553 ppd->cpspec->iblnkerrsnap =
1554 read_7220_creg32(dd, cr_iblinkerrrecov);
1555 }
1556
1557 /* flowcontrolwatermark is in units of KBytes */
1558 ibc = 0x5ULL << SYM_LSB(IBCCtrl, FlowCtrlWaterMark);
1559 /*
1560 * How often flowctrl sent. More or less in usecs; balance against
1561 * watermark value, so that in theory senders always get a flow
1562 * control update in time to not let the IB link go idle.
1563 */
1564 ibc |= 0x3ULL << SYM_LSB(IBCCtrl, FlowCtrlPeriod);
1565 /* max error tolerance */
1566 ibc |= 0xfULL << SYM_LSB(IBCCtrl, PhyerrThreshold);
1567 /* use "real" buffer space for */
1568 ibc |= 4ULL << SYM_LSB(IBCCtrl, CreditScale);
1569 /* IB credit flow control. */
1570 ibc |= 0xfULL << SYM_LSB(IBCCtrl, OverrunThreshold);
1571 /*
1572 * set initial max size pkt IBC will send, including ICRC; it's the
1573 * PIO buffer size in dwords, less 1; also see qib_set_mtu()
1574 */
1575 ibc |= ((u64)(ppd->ibmaxlen >> 2) + 1) << SYM_LSB(IBCCtrl, MaxPktLen);
1576 ppd->cpspec->ibcctrl = ibc; /* without linkcmd or linkinitcmd! */
1577
1578 /* initially come up waiting for TS1, without sending anything. */
1579 val = ppd->cpspec->ibcctrl | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
1580 QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
1581 qib_write_kreg(dd, kr_ibcctrl, val);
1582
1583 if (!ppd->cpspec->ibcddrctrl) {
1584 /* not on re-init after reset */
1585 ppd->cpspec->ibcddrctrl = qib_read_kreg64(dd, kr_ibcddrctrl);
1586
1587 if (ppd->link_speed_enabled == (QIB_IB_SDR | QIB_IB_DDR))
1588 ppd->cpspec->ibcddrctrl |=
1589 IBA7220_IBC_SPEED_AUTONEG_MASK |
1590 IBA7220_IBC_IBTA_1_2_MASK;
1591 else
1592 ppd->cpspec->ibcddrctrl |=
1593 ppd->link_speed_enabled == QIB_IB_DDR ?
1594 IBA7220_IBC_SPEED_DDR : IBA7220_IBC_SPEED_SDR;
1595 if ((ppd->link_width_enabled & (IB_WIDTH_1X | IB_WIDTH_4X)) ==
1596 (IB_WIDTH_1X | IB_WIDTH_4X))
1597 ppd->cpspec->ibcddrctrl |= IBA7220_IBC_WIDTH_AUTONEG;
1598 else
1599 ppd->cpspec->ibcddrctrl |=
1600 ppd->link_width_enabled == IB_WIDTH_4X ?
1601 IBA7220_IBC_WIDTH_4X_ONLY :
1602 IBA7220_IBC_WIDTH_1X_ONLY;
1603
1604 /* always enable these on driver reload, not sticky */
1605 ppd->cpspec->ibcddrctrl |=
1606 IBA7220_IBC_RXPOL_MASK << IBA7220_IBC_RXPOL_SHIFT;
1607 ppd->cpspec->ibcddrctrl |=
1608 IBA7220_IBC_HRTBT_MASK << IBA7220_IBC_HRTBT_SHIFT;
1609
1610 /* enable automatic lane reversal detection for receive */
1611 ppd->cpspec->ibcddrctrl |= IBA7220_IBC_LANE_REV_SUPPORTED;
1612 } else
1613 /* write to chip to prevent back-to-back writes of ibc reg */
1614 qib_write_kreg(dd, kr_scratch, 0);
1615
1616 qib_write_kreg(dd, kr_ibcddrctrl, ppd->cpspec->ibcddrctrl);
1617 qib_write_kreg(dd, kr_scratch, 0);
1618
1619 qib_write_kreg(dd, kr_ncmodectrl, 0Ull);
1620 qib_write_kreg(dd, kr_scratch, 0);
1621
1622 ret = qib_sd7220_init(dd);
1623
1624 val = qib_read_kreg64(dd, kr_xgxs_cfg);
1625 prev_val = val;
1626 val |= QLOGIC_IB_XGXS_FC_SAFE;
1627 if (val != prev_val) {
1628 qib_write_kreg(dd, kr_xgxs_cfg, val);
1629 qib_read_kreg32(dd, kr_scratch);
1630 }
1631 if (val & QLOGIC_IB_XGXS_RESET)
1632 val &= ~QLOGIC_IB_XGXS_RESET;
1633 if (val != prev_val)
1634 qib_write_kreg(dd, kr_xgxs_cfg, val);
1635
1636 /* first time through, set port guid */
1637 if (!ppd->guid)
1638 ppd->guid = dd->base_guid;
1639 guid = be64_to_cpu(ppd->guid);
1640
1641 qib_write_kreg(dd, kr_hrtbt_guid, guid);
1642 if (!ret) {
1643 dd->control |= QLOGIC_IB_C_LINKENABLE;
1644 qib_write_kreg(dd, kr_control, dd->control);
1645 } else
1646 /* write to chip to prevent back-to-back writes of ibc reg */
1647 qib_write_kreg(dd, kr_scratch, 0);
1648 return ret;
1649}
1650
1651/**
1652 * qib_7220_quiet_serdes - set serdes to txidle
1653 * @ppd: physical port of the qlogic_ib device
1654 * Called when driver is being unloaded
1655 */
1656static void qib_7220_quiet_serdes(struct qib_pportdata *ppd)
1657{
1658 u64 val;
1659 struct qib_devdata *dd = ppd->dd;
1660 unsigned long flags;
1661
1662 /* disable IBC */
1663 dd->control &= ~QLOGIC_IB_C_LINKENABLE;
1664 qib_write_kreg(dd, kr_control,
1665 dd->control | QLOGIC_IB_C_FREEZEMODE);
1666
1667 ppd->cpspec->chase_end = 0;
Kees Cook4037c922017-10-04 17:45:35 -07001668 if (ppd->cpspec->chase_timer.function) /* if initted */
Ralph Campbellf9315512010-05-23 21:44:54 -07001669 del_timer_sync(&ppd->cpspec->chase_timer);
1670
1671 if (ppd->cpspec->ibsymdelta || ppd->cpspec->iblnkerrdelta ||
1672 ppd->cpspec->ibdeltainprog) {
1673 u64 diagc;
1674
1675 /* enable counter writes */
1676 diagc = qib_read_kreg64(dd, kr_hwdiagctrl);
1677 qib_write_kreg(dd, kr_hwdiagctrl,
1678 diagc | SYM_MASK(HwDiagCtrl, CounterWrEnable));
1679
1680 if (ppd->cpspec->ibsymdelta || ppd->cpspec->ibdeltainprog) {
1681 val = read_7220_creg32(dd, cr_ibsymbolerr);
1682 if (ppd->cpspec->ibdeltainprog)
1683 val -= val - ppd->cpspec->ibsymsnap;
1684 val -= ppd->cpspec->ibsymdelta;
1685 write_7220_creg(dd, cr_ibsymbolerr, val);
1686 }
1687 if (ppd->cpspec->iblnkerrdelta || ppd->cpspec->ibdeltainprog) {
1688 val = read_7220_creg32(dd, cr_iblinkerrrecov);
1689 if (ppd->cpspec->ibdeltainprog)
1690 val -= val - ppd->cpspec->iblnkerrsnap;
1691 val -= ppd->cpspec->iblnkerrdelta;
1692 write_7220_creg(dd, cr_iblinkerrrecov, val);
1693 }
1694
1695 /* and disable counter writes */
1696 qib_write_kreg(dd, kr_hwdiagctrl, diagc);
1697 }
1698 qib_set_ib_7220_lstate(ppd, 0, QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
1699
1700 spin_lock_irqsave(&ppd->lflags_lock, flags);
1701 ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
1702 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
1703 wake_up(&ppd->cpspec->autoneg_wait);
Tejun Heof0626712010-10-19 15:24:36 +00001704 cancel_delayed_work_sync(&ppd->cpspec->autoneg_work);
Ralph Campbellf9315512010-05-23 21:44:54 -07001705
1706 shutdown_7220_relock_poll(ppd->dd);
1707 val = qib_read_kreg64(ppd->dd, kr_xgxs_cfg);
1708 val |= QLOGIC_IB_XGXS_RESET;
1709 qib_write_kreg(ppd->dd, kr_xgxs_cfg, val);
1710}
1711
1712/**
1713 * qib_setup_7220_setextled - set the state of the two external LEDs
1714 * @dd: the qlogic_ib device
1715 * @on: whether the link is up or not
1716 *
1717 * The exact combo of LEDs if on is true is determined by looking
1718 * at the ibcstatus.
1719 *
1720 * These LEDs indicate the physical and logical state of IB link.
1721 * For this chip (at least with recommended board pinouts), LED1
1722 * is Yellow (logical state) and LED2 is Green (physical state),
1723 *
1724 * Note: We try to match the Mellanox HCA LED behavior as best
1725 * we can. Green indicates physical link state is OK (something is
1726 * plugged in, and we can train).
1727 * Amber indicates the link is logically up (ACTIVE).
1728 * Mellanox further blinks the amber LED to indicate data packet
1729 * activity, but we have no hardware support for that, so it would
1730 * require waking up every 10-20 msecs and checking the counters
1731 * on the chip, and then turning the LED off if appropriate. That's
1732 * visible overhead, so not something we will do.
1733 *
1734 */
1735static void qib_setup_7220_setextled(struct qib_pportdata *ppd, u32 on)
1736{
1737 struct qib_devdata *dd = ppd->dd;
1738 u64 extctl, ledblink = 0, val, lst, ltst;
1739 unsigned long flags;
1740
1741 /*
1742 * The diags use the LED to indicate diag info, so we leave
1743 * the external LED alone when the diags are running.
1744 */
1745 if (dd->diag_client)
1746 return;
1747
1748 if (ppd->led_override) {
1749 ltst = (ppd->led_override & QIB_LED_PHYS) ?
1750 IB_PHYSPORTSTATE_LINKUP : IB_PHYSPORTSTATE_DISABLED,
1751 lst = (ppd->led_override & QIB_LED_LOG) ?
1752 IB_PORT_ACTIVE : IB_PORT_DOWN;
1753 } else if (on) {
1754 val = qib_read_kreg64(dd, kr_ibcstatus);
1755 ltst = qib_7220_phys_portstate(val);
1756 lst = qib_7220_iblink_state(val);
1757 } else {
1758 ltst = 0;
1759 lst = 0;
1760 }
1761
1762 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
1763 extctl = dd->cspec->extctrl & ~(SYM_MASK(EXTCtrl, LEDPriPortGreenOn) |
1764 SYM_MASK(EXTCtrl, LEDPriPortYellowOn));
1765 if (ltst == IB_PHYSPORTSTATE_LINKUP) {
1766 extctl |= SYM_MASK(EXTCtrl, LEDPriPortGreenOn);
1767 /*
1768 * counts are in chip clock (4ns) periods.
1769 * This is 1/16 sec (66.6ms) on,
1770 * 3/16 sec (187.5 ms) off, with packets rcvd
1771 */
1772 ledblink = ((66600 * 1000UL / 4) << IBA7220_LEDBLINK_ON_SHIFT)
1773 | ((187500 * 1000UL / 4) << IBA7220_LEDBLINK_OFF_SHIFT);
1774 }
1775 if (lst == IB_PORT_ACTIVE)
1776 extctl |= SYM_MASK(EXTCtrl, LEDPriPortYellowOn);
1777 dd->cspec->extctrl = extctl;
1778 qib_write_kreg(dd, kr_extctrl, extctl);
1779 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
1780
1781 if (ledblink) /* blink the LED on packet receive */
1782 qib_write_kreg(dd, kr_rcvpktledcnt, ledblink);
1783}
1784
1785static void qib_7220_free_irq(struct qib_devdata *dd)
1786{
1787 if (dd->cspec->irq) {
1788 free_irq(dd->cspec->irq, dd);
1789 dd->cspec->irq = 0;
1790 }
1791 qib_nomsi(dd);
1792}
1793
1794/*
1795 * qib_setup_7220_cleanup - clean up any per-chip chip-specific stuff
1796 * @dd: the qlogic_ib device
1797 *
1798 * This is called during driver unload.
1799 *
1800 */
1801static void qib_setup_7220_cleanup(struct qib_devdata *dd)
1802{
1803 qib_7220_free_irq(dd);
1804 kfree(dd->cspec->cntrs);
1805 kfree(dd->cspec->portcntrs);
1806}
1807
1808/*
1809 * This is only called for SDmaInt.
1810 * SDmaDisabled is handled on the error path.
1811 */
1812static void sdma_7220_intr(struct qib_pportdata *ppd, u64 istat)
1813{
1814 unsigned long flags;
1815
1816 spin_lock_irqsave(&ppd->sdma_lock, flags);
1817
1818 switch (ppd->sdma_state.current_state) {
1819 case qib_sdma_state_s00_hw_down:
1820 break;
1821
1822 case qib_sdma_state_s10_hw_start_up_wait:
1823 __qib_sdma_process_event(ppd, qib_sdma_event_e20_hw_started);
1824 break;
1825
1826 case qib_sdma_state_s20_idle:
1827 break;
1828
1829 case qib_sdma_state_s30_sw_clean_up_wait:
1830 break;
1831
1832 case qib_sdma_state_s40_hw_clean_up_wait:
1833 break;
1834
1835 case qib_sdma_state_s50_hw_halt_wait:
1836 __qib_sdma_process_event(ppd, qib_sdma_event_e60_hw_halted);
1837 break;
1838
1839 case qib_sdma_state_s99_running:
1840 /* too chatty to print here */
1841 __qib_sdma_intr(ppd);
1842 break;
1843 }
1844 spin_unlock_irqrestore(&ppd->sdma_lock, flags);
1845}
1846
1847static void qib_wantpiobuf_7220_intr(struct qib_devdata *dd, u32 needint)
1848{
1849 unsigned long flags;
1850
1851 spin_lock_irqsave(&dd->sendctrl_lock, flags);
1852 if (needint) {
1853 if (!(dd->sendctrl & SYM_MASK(SendCtrl, SendBufAvailUpd)))
1854 goto done;
1855 /*
1856 * blip the availupd off, next write will be on, so
1857 * we ensure an avail update, regardless of threshold or
1858 * buffers becoming free, whenever we want an interrupt
1859 */
1860 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl &
1861 ~SYM_MASK(SendCtrl, SendBufAvailUpd));
1862 qib_write_kreg(dd, kr_scratch, 0ULL);
1863 dd->sendctrl |= SYM_MASK(SendCtrl, SendIntBufAvail);
1864 } else
1865 dd->sendctrl &= ~SYM_MASK(SendCtrl, SendIntBufAvail);
1866 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
1867 qib_write_kreg(dd, kr_scratch, 0ULL);
1868done:
1869 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
1870}
1871
1872/*
1873 * Handle errors and unusual events first, separate function
1874 * to improve cache hits for fast path interrupt handling.
1875 */
1876static noinline void unlikely_7220_intr(struct qib_devdata *dd, u64 istat)
1877{
1878 if (unlikely(istat & ~QLOGIC_IB_I_BITSEXTANT))
1879 qib_dev_err(dd,
1880 "interrupt with unknown interrupts %Lx set\n",
1881 istat & ~QLOGIC_IB_I_BITSEXTANT);
1882
1883 if (istat & QLOGIC_IB_I_GPIO) {
1884 u32 gpiostatus;
1885
1886 /*
1887 * Boards for this chip currently don't use GPIO interrupts,
1888 * so clear by writing GPIOstatus to GPIOclear, and complain
1889 * to alert developer. To avoid endless repeats, clear
1890 * the bits in the mask, since there is some kind of
1891 * programming error or chip problem.
1892 */
1893 gpiostatus = qib_read_kreg32(dd, kr_gpio_status);
1894 /*
1895 * In theory, writing GPIOstatus to GPIOclear could
1896 * have a bad side-effect on some diagnostic that wanted
1897 * to poll for a status-change, but the various shadows
1898 * make that problematic at best. Diags will just suppress
1899 * all GPIO interrupts during such tests.
1900 */
1901 qib_write_kreg(dd, kr_gpio_clear, gpiostatus);
1902
1903 if (gpiostatus) {
1904 const u32 mask = qib_read_kreg32(dd, kr_gpio_mask);
1905 u32 gpio_irq = mask & gpiostatus;
1906
1907 /*
1908 * A bit set in status and (chip) Mask register
1909 * would cause an interrupt. Since we are not
1910 * expecting any, report it. Also check that the
1911 * chip reflects our shadow, report issues,
1912 * and refresh from the shadow.
1913 */
1914 /*
1915 * Clear any troublemakers, and update chip
1916 * from shadow
1917 */
1918 dd->cspec->gpio_mask &= ~gpio_irq;
1919 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
1920 }
1921 }
1922
1923 if (istat & QLOGIC_IB_I_ERROR) {
1924 u64 estat;
1925
1926 qib_stats.sps_errints++;
1927 estat = qib_read_kreg64(dd, kr_errstatus);
1928 if (!estat)
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00001929 qib_devinfo(dd->pcidev,
1930 "error interrupt (%Lx), but no error bits set!\n",
1931 istat);
Ralph Campbellf9315512010-05-23 21:44:54 -07001932 else
1933 handle_7220_errors(dd, estat);
1934 }
1935}
1936
1937static irqreturn_t qib_7220intr(int irq, void *data)
1938{
1939 struct qib_devdata *dd = data;
1940 irqreturn_t ret;
1941 u64 istat;
1942 u64 ctxtrbits;
1943 u64 rmask;
1944 unsigned i;
1945
1946 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT) {
1947 /*
1948 * This return value is not great, but we do not want the
1949 * interrupt core code to remove our interrupt handler
1950 * because we don't appear to be handling an interrupt
1951 * during a chip reset.
1952 */
1953 ret = IRQ_HANDLED;
1954 goto bail;
1955 }
1956
1957 istat = qib_read_kreg64(dd, kr_intstatus);
1958
1959 if (unlikely(!istat)) {
1960 ret = IRQ_NONE; /* not our interrupt, or already handled */
1961 goto bail;
1962 }
1963 if (unlikely(istat == -1)) {
1964 qib_bad_intrstatus(dd);
1965 /* don't know if it was our interrupt or not */
1966 ret = IRQ_NONE;
1967 goto bail;
1968 }
1969
Mike Marciniszyn1ed88dd2014-03-07 08:40:49 -05001970 this_cpu_inc(*dd->int_counter);
Ralph Campbellf9315512010-05-23 21:44:54 -07001971 if (unlikely(istat & (~QLOGIC_IB_I_BITSEXTANT |
1972 QLOGIC_IB_I_GPIO | QLOGIC_IB_I_ERROR)))
1973 unlikely_7220_intr(dd, istat);
1974
1975 /*
1976 * Clear the interrupt bits we found set, relatively early, so we
1977 * "know" know the chip will have seen this by the time we process
1978 * the queue, and will re-interrupt if necessary. The processor
1979 * itself won't take the interrupt again until we return.
1980 */
1981 qib_write_kreg(dd, kr_intclear, istat);
1982
1983 /*
1984 * Handle kernel receive queues before checking for pio buffers
1985 * available since receives can overflow; piobuf waiters can afford
1986 * a few extra cycles, since they were waiting anyway.
1987 */
1988 ctxtrbits = istat &
1989 ((QLOGIC_IB_I_RCVAVAIL_MASK << QLOGIC_IB_I_RCVAVAIL_SHIFT) |
1990 (QLOGIC_IB_I_RCVURG_MASK << QLOGIC_IB_I_RCVURG_SHIFT));
1991 if (ctxtrbits) {
1992 rmask = (1ULL << QLOGIC_IB_I_RCVAVAIL_SHIFT) |
1993 (1ULL << QLOGIC_IB_I_RCVURG_SHIFT);
1994 for (i = 0; i < dd->first_user_ctxt; i++) {
1995 if (ctxtrbits & rmask) {
1996 ctxtrbits &= ~rmask;
1997 qib_kreceive(dd->rcd[i], NULL, NULL);
1998 }
1999 rmask <<= 1;
2000 }
2001 if (ctxtrbits) {
2002 ctxtrbits =
2003 (ctxtrbits >> QLOGIC_IB_I_RCVAVAIL_SHIFT) |
2004 (ctxtrbits >> QLOGIC_IB_I_RCVURG_SHIFT);
2005 qib_handle_urcv(dd, ctxtrbits);
2006 }
2007 }
2008
2009 /* only call for SDmaInt */
2010 if (istat & QLOGIC_IB_I_SDMAINT)
2011 sdma_7220_intr(dd->pport, istat);
2012
2013 if ((istat & QLOGIC_IB_I_SPIOBUFAVAIL) && (dd->flags & QIB_INITTED))
2014 qib_ib_piobufavail(dd);
2015
2016 ret = IRQ_HANDLED;
2017bail:
2018 return ret;
2019}
2020
2021/*
2022 * Set up our chip-specific interrupt handler.
2023 * The interrupt type has already been setup, so
2024 * we just need to do the registration and error checking.
2025 * If we are using MSI interrupts, we may fall back to
2026 * INTx later, if the interrupt handler doesn't get called
2027 * within 1/2 second (see verify_interrupt()).
2028 */
2029static void qib_setup_7220_interrupt(struct qib_devdata *dd)
2030{
2031 if (!dd->cspec->irq)
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00002032 qib_dev_err(dd,
2033 "irq is 0, BIOS error? Interrupts won't work\n");
Ralph Campbellf9315512010-05-23 21:44:54 -07002034 else {
2035 int ret = request_irq(dd->cspec->irq, qib_7220intr,
2036 dd->msi_lo ? 0 : IRQF_SHARED,
2037 QIB_DRV_NAME, dd);
2038
2039 if (ret)
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00002040 qib_dev_err(dd,
2041 "Couldn't setup %s interrupt (irq=%d): %d\n",
2042 dd->msi_lo ? "MSI" : "INTx",
2043 dd->cspec->irq, ret);
Ralph Campbellf9315512010-05-23 21:44:54 -07002044 }
2045}
2046
2047/**
2048 * qib_7220_boardname - fill in the board name
2049 * @dd: the qlogic_ib device
2050 *
2051 * info is based on the board revision register
2052 */
2053static void qib_7220_boardname(struct qib_devdata *dd)
2054{
Kamenee Arumugam3b716932017-08-21 18:26:26 -07002055 u32 boardid;
Ralph Campbellf9315512010-05-23 21:44:54 -07002056
2057 boardid = SYM_FIELD(dd->revision, Revision,
2058 BoardID);
2059
2060 switch (boardid) {
2061 case 1:
Kamenee Arumugam3b716932017-08-21 18:26:26 -07002062 dd->boardname = "InfiniPath_QLE7240";
Ralph Campbellf9315512010-05-23 21:44:54 -07002063 break;
2064 case 2:
Kamenee Arumugam3b716932017-08-21 18:26:26 -07002065 dd->boardname = "InfiniPath_QLE7280";
Ralph Campbellf9315512010-05-23 21:44:54 -07002066 break;
2067 default:
2068 qib_dev_err(dd, "Unknown 7220 board with ID %u\n", boardid);
Kamenee Arumugam3b716932017-08-21 18:26:26 -07002069 dd->boardname = "Unknown_InfiniPath_7220";
Ralph Campbellf9315512010-05-23 21:44:54 -07002070 break;
2071 }
2072
Ralph Campbellf9315512010-05-23 21:44:54 -07002073 if (dd->majrev != 5 || !dd->minrev || dd->minrev > 2)
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00002074 qib_dev_err(dd,
Kamenee Arumugam3b716932017-08-21 18:26:26 -07002075 "Unsupported InfiniPath hardware revision %u.%u!\n",
2076 dd->majrev, dd->minrev);
Ralph Campbellf9315512010-05-23 21:44:54 -07002077
2078 snprintf(dd->boardversion, sizeof(dd->boardversion),
2079 "ChipABI %u.%u, %s, InfiniPath%u %u.%u, SW Compat %u\n",
2080 QIB_CHIP_VERS_MAJ, QIB_CHIP_VERS_MIN, dd->boardname,
Kamenee Arumugam3b716932017-08-21 18:26:26 -07002081 (unsigned int)SYM_FIELD(dd->revision, Revision_R, Arch),
Ralph Campbellf9315512010-05-23 21:44:54 -07002082 dd->majrev, dd->minrev,
Kamenee Arumugam3b716932017-08-21 18:26:26 -07002083 (unsigned int)SYM_FIELD(dd->revision, Revision_R, SW));
Ralph Campbellf9315512010-05-23 21:44:54 -07002084}
2085
2086/*
2087 * This routine sleeps, so it can only be called from user context, not
2088 * from interrupt context.
2089 */
2090static int qib_setup_7220_reset(struct qib_devdata *dd)
2091{
2092 u64 val;
2093 int i;
2094 int ret;
2095 u16 cmdval;
2096 u8 int_line, clinesz;
2097 unsigned long flags;
2098
2099 qib_pcie_getcmd(dd, &cmdval, &int_line, &clinesz);
2100
2101 /* Use dev_err so it shows up in logs, etc. */
2102 qib_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->unit);
2103
2104 /* no interrupts till re-initted */
2105 qib_7220_set_intr_state(dd, 0);
2106
2107 dd->pport->cpspec->ibdeltainprog = 0;
2108 dd->pport->cpspec->ibsymdelta = 0;
2109 dd->pport->cpspec->iblnkerrdelta = 0;
2110
2111 /*
2112 * Keep chip from being accessed until we are ready. Use
2113 * writeq() directly, to allow the write even though QIB_PRESENT
Lucas De Marchie9c54992011-04-26 23:28:26 -07002114 * isn't set.
Ralph Campbellf9315512010-05-23 21:44:54 -07002115 */
2116 dd->flags &= ~(QIB_INITTED | QIB_PRESENT);
Mike Marciniszyn1ed88dd2014-03-07 08:40:49 -05002117 /* so we check interrupts work again */
2118 dd->z_int_counter = qib_int_counter(dd);
Ralph Campbellf9315512010-05-23 21:44:54 -07002119 val = dd->control | QLOGIC_IB_C_RESET;
2120 writeq(val, &dd->kregbase[kr_control]);
2121 mb(); /* prevent compiler reordering around actual reset */
2122
2123 for (i = 1; i <= 5; i++) {
2124 /*
2125 * Allow MBIST, etc. to complete; longer on each retry.
2126 * We sometimes get machine checks from bus timeout if no
2127 * response, so for now, make it *really* long.
2128 */
2129 msleep(1000 + (1 + i) * 2000);
2130
2131 qib_pcie_reenable(dd, cmdval, int_line, clinesz);
2132
2133 /*
2134 * Use readq directly, so we don't need to mark it as PRESENT
2135 * until we get a successful indication that all is well.
2136 */
2137 val = readq(&dd->kregbase[kr_revision]);
2138 if (val == dd->revision) {
2139 dd->flags |= QIB_PRESENT; /* it's back */
2140 ret = qib_reinit_intr(dd);
2141 goto bail;
2142 }
2143 }
2144 ret = 0; /* failed */
2145
2146bail:
2147 if (ret) {
Michael J. Ruhl581d01a2017-06-09 16:00:06 -07002148 if (qib_pcie_params(dd, dd->lbus_width, NULL))
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00002149 qib_dev_err(dd,
2150 "Reset failed to setup PCIe or interrupts; continuing anyway\n");
Ralph Campbellf9315512010-05-23 21:44:54 -07002151
2152 /* hold IBC in reset, no sends, etc till later */
2153 qib_write_kreg(dd, kr_control, 0ULL);
2154
2155 /* clear the reset error, init error/hwerror mask */
2156 qib_7220_init_hwerrors(dd);
2157
2158 /* do setup similar to speed or link-width changes */
2159 if (dd->pport->cpspec->ibcddrctrl & IBA7220_IBC_IBTA_1_2_MASK)
2160 dd->cspec->presets_needed = 1;
2161 spin_lock_irqsave(&dd->pport->lflags_lock, flags);
2162 dd->pport->lflags |= QIBL_IB_FORCE_NOTIFY;
2163 dd->pport->lflags &= ~QIBL_IB_AUTONEG_FAILED;
2164 spin_unlock_irqrestore(&dd->pport->lflags_lock, flags);
2165 }
2166
2167 return ret;
2168}
2169
2170/**
2171 * qib_7220_put_tid - write a TID to the chip
2172 * @dd: the qlogic_ib device
2173 * @tidptr: pointer to the expected TID (in chip) to update
2174 * @tidtype: 0 for eager, 1 for expected
2175 * @pa: physical address of in memory buffer; tidinvalid if freeing
2176 */
2177static void qib_7220_put_tid(struct qib_devdata *dd, u64 __iomem *tidptr,
2178 u32 type, unsigned long pa)
2179{
2180 if (pa != dd->tidinvalid) {
2181 u64 chippa = pa >> IBA7220_TID_PA_SHIFT;
2182
2183 /* paranoia checks */
2184 if (pa != (chippa << IBA7220_TID_PA_SHIFT)) {
2185 qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
2186 pa);
2187 return;
2188 }
2189 if (chippa >= (1UL << IBA7220_TID_SZ_SHIFT)) {
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00002190 qib_dev_err(dd,
2191 "Physical page address 0x%lx larger than supported\n",
2192 pa);
Ralph Campbellf9315512010-05-23 21:44:54 -07002193 return;
2194 }
2195
2196 if (type == RCVHQ_RCV_TYPE_EAGER)
2197 chippa |= dd->tidtemplate;
2198 else /* for now, always full 4KB page */
2199 chippa |= IBA7220_TID_SZ_4K;
2200 pa = chippa;
2201 }
2202 writeq(pa, tidptr);
2203 mmiowb();
2204}
2205
2206/**
2207 * qib_7220_clear_tids - clear all TID entries for a ctxt, expected and eager
2208 * @dd: the qlogic_ib device
2209 * @ctxt: the ctxt
2210 *
2211 * clear all TID entries for a ctxt, expected and eager.
2212 * Used from qib_close(). On this chip, TIDs are only 32 bits,
2213 * not 64, but they are still on 64 bit boundaries, so tidbase
2214 * is declared as u64 * for the pointer math, even though we write 32 bits
2215 */
2216static void qib_7220_clear_tids(struct qib_devdata *dd,
2217 struct qib_ctxtdata *rcd)
2218{
2219 u64 __iomem *tidbase;
2220 unsigned long tidinv;
2221 u32 ctxt;
2222 int i;
2223
2224 if (!dd->kregbase || !rcd)
2225 return;
2226
2227 ctxt = rcd->ctxt;
2228
2229 tidinv = dd->tidinvalid;
2230 tidbase = (u64 __iomem *)
2231 ((char __iomem *)(dd->kregbase) +
2232 dd->rcvtidbase +
2233 ctxt * dd->rcvtidcnt * sizeof(*tidbase));
2234
2235 for (i = 0; i < dd->rcvtidcnt; i++)
2236 qib_7220_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
2237 tidinv);
2238
2239 tidbase = (u64 __iomem *)
2240 ((char __iomem *)(dd->kregbase) +
2241 dd->rcvegrbase +
2242 rcd->rcvegr_tid_base * sizeof(*tidbase));
2243
2244 for (i = 0; i < rcd->rcvegrcnt; i++)
2245 qib_7220_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
2246 tidinv);
2247}
2248
2249/**
2250 * qib_7220_tidtemplate - setup constants for TID updates
2251 * @dd: the qlogic_ib device
2252 *
2253 * We setup stuff that we use a lot, to avoid calculating each time
2254 */
2255static void qib_7220_tidtemplate(struct qib_devdata *dd)
2256{
2257 if (dd->rcvegrbufsize == 2048)
2258 dd->tidtemplate = IBA7220_TID_SZ_2K;
2259 else if (dd->rcvegrbufsize == 4096)
2260 dd->tidtemplate = IBA7220_TID_SZ_4K;
2261 dd->tidinvalid = 0;
2262}
2263
2264/**
2265 * qib_init_7220_get_base_info - set chip-specific flags for user code
2266 * @rcd: the qlogic_ib ctxt
2267 * @kbase: qib_base_info pointer
2268 *
2269 * We set the PCIE flag because the lower bandwidth on PCIe vs
2270 * HyperTransport can affect some user packet algorithims.
2271 */
2272static int qib_7220_get_base_info(struct qib_ctxtdata *rcd,
2273 struct qib_base_info *kinfo)
2274{
2275 kinfo->spi_runtime_flags |= QIB_RUNTIME_PCIE |
2276 QIB_RUNTIME_NODMA_RTAIL | QIB_RUNTIME_SDMA;
2277
2278 if (rcd->dd->flags & QIB_USE_SPCL_TRIG)
2279 kinfo->spi_runtime_flags |= QIB_RUNTIME_SPECIAL_TRIGGER;
2280
2281 return 0;
2282}
2283
2284static struct qib_message_header *
2285qib_7220_get_msgheader(struct qib_devdata *dd, __le32 *rhf_addr)
2286{
2287 u32 offset = qib_hdrget_offset(rhf_addr);
2288
2289 return (struct qib_message_header *)
2290 (rhf_addr - dd->rhf_offset + offset);
2291}
2292
2293static void qib_7220_config_ctxts(struct qib_devdata *dd)
2294{
2295 unsigned long flags;
2296 u32 nchipctxts;
2297
2298 nchipctxts = qib_read_kreg32(dd, kr_portcnt);
2299 dd->cspec->numctxts = nchipctxts;
2300 if (qib_n_krcv_queues > 1) {
Mike Marciniszyn2528ea62011-01-10 17:42:21 -08002301 dd->qpn_mask = 0x3e;
Ralph Campbellf9315512010-05-23 21:44:54 -07002302 dd->first_user_ctxt = qib_n_krcv_queues * dd->num_pports;
2303 if (dd->first_user_ctxt > nchipctxts)
2304 dd->first_user_ctxt = nchipctxts;
2305 } else
2306 dd->first_user_ctxt = dd->num_pports;
2307 dd->n_krcv_queues = dd->first_user_ctxt;
2308
2309 if (!qib_cfgctxts) {
2310 int nctxts = dd->first_user_ctxt + num_online_cpus();
2311
2312 if (nctxts <= 5)
2313 dd->ctxtcnt = 5;
2314 else if (nctxts <= 9)
2315 dd->ctxtcnt = 9;
2316 else if (nctxts <= nchipctxts)
2317 dd->ctxtcnt = nchipctxts;
2318 } else if (qib_cfgctxts <= nchipctxts)
2319 dd->ctxtcnt = qib_cfgctxts;
2320 if (!dd->ctxtcnt) /* none of the above, set to max */
2321 dd->ctxtcnt = nchipctxts;
2322
2323 /*
2324 * Chip can be configured for 5, 9, or 17 ctxts, and choice
2325 * affects number of eager TIDs per ctxt (1K, 2K, 4K).
2326 * Lock to be paranoid about later motion, etc.
2327 */
2328 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
2329 if (dd->ctxtcnt > 9)
2330 dd->rcvctrl |= 2ULL << IBA7220_R_CTXTCFG_SHIFT;
2331 else if (dd->ctxtcnt > 5)
2332 dd->rcvctrl |= 1ULL << IBA7220_R_CTXTCFG_SHIFT;
2333 /* else configure for default 5 receive ctxts */
2334 if (dd->qpn_mask)
2335 dd->rcvctrl |= 1ULL << QIB_7220_RcvCtrl_RcvQPMapEnable_LSB;
2336 qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
2337 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
2338
2339 /* kr_rcvegrcnt changes based on the number of contexts enabled */
2340 dd->cspec->rcvegrcnt = qib_read_kreg32(dd, kr_rcvegrcnt);
2341 dd->rcvhdrcnt = max(dd->cspec->rcvegrcnt, IBA7220_KRCVEGRCNT);
2342}
2343
2344static int qib_7220_get_ib_cfg(struct qib_pportdata *ppd, int which)
2345{
2346 int lsb, ret = 0;
2347 u64 maskr; /* right-justified mask */
2348
2349 switch (which) {
2350 case QIB_IB_CFG_LWID_ENB: /* Get allowed Link-width */
2351 ret = ppd->link_width_enabled;
2352 goto done;
2353
2354 case QIB_IB_CFG_LWID: /* Get currently active Link-width */
2355 ret = ppd->link_width_active;
2356 goto done;
2357
2358 case QIB_IB_CFG_SPD_ENB: /* Get allowed Link speeds */
2359 ret = ppd->link_speed_enabled;
2360 goto done;
2361
2362 case QIB_IB_CFG_SPD: /* Get current Link spd */
2363 ret = ppd->link_speed_active;
2364 goto done;
2365
2366 case QIB_IB_CFG_RXPOL_ENB: /* Get Auto-RX-polarity enable */
2367 lsb = IBA7220_IBC_RXPOL_SHIFT;
2368 maskr = IBA7220_IBC_RXPOL_MASK;
2369 break;
2370
2371 case QIB_IB_CFG_LREV_ENB: /* Get Auto-Lane-reversal enable */
2372 lsb = IBA7220_IBC_LREV_SHIFT;
2373 maskr = IBA7220_IBC_LREV_MASK;
2374 break;
2375
2376 case QIB_IB_CFG_LINKLATENCY:
2377 ret = qib_read_kreg64(ppd->dd, kr_ibcddrstatus)
2378 & IBA7220_DDRSTAT_LINKLAT_MASK;
2379 goto done;
2380
2381 case QIB_IB_CFG_OP_VLS:
2382 ret = ppd->vls_operational;
2383 goto done;
2384
2385 case QIB_IB_CFG_VL_HIGH_CAP:
2386 ret = 0;
2387 goto done;
2388
2389 case QIB_IB_CFG_VL_LOW_CAP:
2390 ret = 0;
2391 goto done;
2392
2393 case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
2394 ret = SYM_FIELD(ppd->cpspec->ibcctrl, IBCCtrl,
2395 OverrunThreshold);
2396 goto done;
2397
2398 case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
2399 ret = SYM_FIELD(ppd->cpspec->ibcctrl, IBCCtrl,
2400 PhyerrThreshold);
2401 goto done;
2402
2403 case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
2404 /* will only take effect when the link state changes */
2405 ret = (ppd->cpspec->ibcctrl &
2406 SYM_MASK(IBCCtrl, LinkDownDefaultState)) ?
2407 IB_LINKINITCMD_SLEEP : IB_LINKINITCMD_POLL;
2408 goto done;
2409
2410 case QIB_IB_CFG_HRTBT: /* Get Heartbeat off/enable/auto */
2411 lsb = IBA7220_IBC_HRTBT_SHIFT;
2412 maskr = IBA7220_IBC_HRTBT_MASK;
2413 break;
2414
2415 case QIB_IB_CFG_PMA_TICKS:
2416 /*
2417 * 0x00 = 10x link transfer rate or 4 nsec. for 2.5Gbs
2418 * Since the clock is always 250MHz, the value is 1 or 0.
2419 */
2420 ret = (ppd->link_speed_active == QIB_IB_DDR);
2421 goto done;
2422
2423 default:
2424 ret = -EINVAL;
2425 goto done;
2426 }
2427 ret = (int)((ppd->cpspec->ibcddrctrl >> lsb) & maskr);
2428done:
2429 return ret;
2430}
2431
2432static int qib_7220_set_ib_cfg(struct qib_pportdata *ppd, int which, u32 val)
2433{
2434 struct qib_devdata *dd = ppd->dd;
2435 u64 maskr; /* right-justified mask */
2436 int lsb, ret = 0, setforce = 0;
2437 u16 lcmd, licmd;
2438 unsigned long flags;
Mitko Haralanove800bd02011-07-14 13:40:24 +00002439 u32 tmp = 0;
Ralph Campbellf9315512010-05-23 21:44:54 -07002440
2441 switch (which) {
2442 case QIB_IB_CFG_LIDLMC:
2443 /*
2444 * Set LID and LMC. Combined to avoid possible hazard
2445 * caller puts LMC in 16MSbits, DLID in 16LSbits of val
2446 */
2447 lsb = IBA7220_IBC_DLIDLMC_SHIFT;
2448 maskr = IBA7220_IBC_DLIDLMC_MASK;
2449 break;
2450
2451 case QIB_IB_CFG_LWID_ENB: /* set allowed Link-width */
2452 /*
2453 * As with speed, only write the actual register if
2454 * the link is currently down, otherwise takes effect
2455 * on next link change.
2456 */
2457 ppd->link_width_enabled = val;
2458 if (!(ppd->lflags & QIBL_LINKDOWN))
2459 goto bail;
2460 /*
2461 * We set the QIBL_IB_FORCE_NOTIFY bit so updown
2462 * will get called because we want update
2463 * link_width_active, and the change may not take
2464 * effect for some time (if we are in POLL), so this
2465 * flag will force the updown routine to be called
2466 * on the next ibstatuschange down interrupt, even
2467 * if it's not an down->up transition.
2468 */
2469 val--; /* convert from IB to chip */
2470 maskr = IBA7220_IBC_WIDTH_MASK;
2471 lsb = IBA7220_IBC_WIDTH_SHIFT;
2472 setforce = 1;
Ralph Campbellf9315512010-05-23 21:44:54 -07002473 break;
2474
2475 case QIB_IB_CFG_SPD_ENB: /* set allowed Link speeds */
2476 /*
2477 * If we turn off IB1.2, need to preset SerDes defaults,
2478 * but not right now. Set a flag for the next time
2479 * we command the link down. As with width, only write the
2480 * actual register if the link is currently down, otherwise
2481 * takes effect on next link change. Since setting is being
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002482 * explicitly requested (via MAD or sysfs), clear autoneg
Ralph Campbellf9315512010-05-23 21:44:54 -07002483 * failure status if speed autoneg is enabled.
2484 */
2485 ppd->link_speed_enabled = val;
2486 if ((ppd->cpspec->ibcddrctrl & IBA7220_IBC_IBTA_1_2_MASK) &&
2487 !(val & (val - 1)))
2488 dd->cspec->presets_needed = 1;
2489 if (!(ppd->lflags & QIBL_LINKDOWN))
2490 goto bail;
2491 /*
2492 * We set the QIBL_IB_FORCE_NOTIFY bit so updown
2493 * will get called because we want update
2494 * link_speed_active, and the change may not take
2495 * effect for some time (if we are in POLL), so this
2496 * flag will force the updown routine to be called
2497 * on the next ibstatuschange down interrupt, even
2498 * if it's not an down->up transition.
2499 */
2500 if (val == (QIB_IB_SDR | QIB_IB_DDR)) {
2501 val = IBA7220_IBC_SPEED_AUTONEG_MASK |
2502 IBA7220_IBC_IBTA_1_2_MASK;
2503 spin_lock_irqsave(&ppd->lflags_lock, flags);
2504 ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
2505 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
2506 } else
2507 val = val == QIB_IB_DDR ?
2508 IBA7220_IBC_SPEED_DDR : IBA7220_IBC_SPEED_SDR;
2509 maskr = IBA7220_IBC_SPEED_AUTONEG_MASK |
2510 IBA7220_IBC_IBTA_1_2_MASK;
2511 /* IBTA 1.2 mode + speed bits are contiguous */
2512 lsb = SYM_LSB(IBCDDRCtrl, IB_ENHANCED_MODE);
2513 setforce = 1;
2514 break;
2515
2516 case QIB_IB_CFG_RXPOL_ENB: /* set Auto-RX-polarity enable */
2517 lsb = IBA7220_IBC_RXPOL_SHIFT;
2518 maskr = IBA7220_IBC_RXPOL_MASK;
2519 break;
2520
2521 case QIB_IB_CFG_LREV_ENB: /* set Auto-Lane-reversal enable */
2522 lsb = IBA7220_IBC_LREV_SHIFT;
2523 maskr = IBA7220_IBC_LREV_MASK;
2524 break;
2525
2526 case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
2527 maskr = SYM_FIELD(ppd->cpspec->ibcctrl, IBCCtrl,
2528 OverrunThreshold);
2529 if (maskr != val) {
2530 ppd->cpspec->ibcctrl &=
2531 ~SYM_MASK(IBCCtrl, OverrunThreshold);
2532 ppd->cpspec->ibcctrl |= (u64) val <<
2533 SYM_LSB(IBCCtrl, OverrunThreshold);
2534 qib_write_kreg(dd, kr_ibcctrl, ppd->cpspec->ibcctrl);
2535 qib_write_kreg(dd, kr_scratch, 0);
2536 }
2537 goto bail;
2538
2539 case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
2540 maskr = SYM_FIELD(ppd->cpspec->ibcctrl, IBCCtrl,
2541 PhyerrThreshold);
2542 if (maskr != val) {
2543 ppd->cpspec->ibcctrl &=
2544 ~SYM_MASK(IBCCtrl, PhyerrThreshold);
2545 ppd->cpspec->ibcctrl |= (u64) val <<
2546 SYM_LSB(IBCCtrl, PhyerrThreshold);
2547 qib_write_kreg(dd, kr_ibcctrl, ppd->cpspec->ibcctrl);
2548 qib_write_kreg(dd, kr_scratch, 0);
2549 }
2550 goto bail;
2551
2552 case QIB_IB_CFG_PKEYS: /* update pkeys */
2553 maskr = (u64) ppd->pkeys[0] | ((u64) ppd->pkeys[1] << 16) |
2554 ((u64) ppd->pkeys[2] << 32) |
2555 ((u64) ppd->pkeys[3] << 48);
2556 qib_write_kreg(dd, kr_partitionkey, maskr);
2557 goto bail;
2558
2559 case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
2560 /* will only take effect when the link state changes */
2561 if (val == IB_LINKINITCMD_POLL)
2562 ppd->cpspec->ibcctrl &=
2563 ~SYM_MASK(IBCCtrl, LinkDownDefaultState);
2564 else /* SLEEP */
2565 ppd->cpspec->ibcctrl |=
2566 SYM_MASK(IBCCtrl, LinkDownDefaultState);
2567 qib_write_kreg(dd, kr_ibcctrl, ppd->cpspec->ibcctrl);
2568 qib_write_kreg(dd, kr_scratch, 0);
2569 goto bail;
2570
2571 case QIB_IB_CFG_MTU: /* update the MTU in IBC */
2572 /*
2573 * Update our housekeeping variables, and set IBC max
2574 * size, same as init code; max IBC is max we allow in
2575 * buffer, less the qword pbc, plus 1 for ICRC, in dwords
2576 * Set even if it's unchanged, print debug message only
2577 * on changes.
2578 */
2579 val = (ppd->ibmaxlen >> 2) + 1;
2580 ppd->cpspec->ibcctrl &= ~SYM_MASK(IBCCtrl, MaxPktLen);
2581 ppd->cpspec->ibcctrl |= (u64)val << SYM_LSB(IBCCtrl, MaxPktLen);
2582 qib_write_kreg(dd, kr_ibcctrl, ppd->cpspec->ibcctrl);
2583 qib_write_kreg(dd, kr_scratch, 0);
2584 goto bail;
2585
2586 case QIB_IB_CFG_LSTATE: /* set the IB link state */
2587 switch (val & 0xffff0000) {
2588 case IB_LINKCMD_DOWN:
2589 lcmd = QLOGIC_IB_IBCC_LINKCMD_DOWN;
2590 if (!ppd->cpspec->ibdeltainprog &&
2591 qib_compat_ddr_negotiate) {
2592 ppd->cpspec->ibdeltainprog = 1;
2593 ppd->cpspec->ibsymsnap =
2594 read_7220_creg32(dd, cr_ibsymbolerr);
2595 ppd->cpspec->iblnkerrsnap =
2596 read_7220_creg32(dd, cr_iblinkerrrecov);
2597 }
2598 break;
2599
2600 case IB_LINKCMD_ARMED:
2601 lcmd = QLOGIC_IB_IBCC_LINKCMD_ARMED;
2602 break;
2603
2604 case IB_LINKCMD_ACTIVE:
2605 lcmd = QLOGIC_IB_IBCC_LINKCMD_ACTIVE;
2606 break;
2607
2608 default:
2609 ret = -EINVAL;
2610 qib_dev_err(dd, "bad linkcmd req 0x%x\n", val >> 16);
2611 goto bail;
2612 }
2613 switch (val & 0xffff) {
2614 case IB_LINKINITCMD_NOP:
2615 licmd = 0;
2616 break;
2617
2618 case IB_LINKINITCMD_POLL:
2619 licmd = QLOGIC_IB_IBCC_LINKINITCMD_POLL;
2620 break;
2621
2622 case IB_LINKINITCMD_SLEEP:
2623 licmd = QLOGIC_IB_IBCC_LINKINITCMD_SLEEP;
2624 break;
2625
2626 case IB_LINKINITCMD_DISABLE:
2627 licmd = QLOGIC_IB_IBCC_LINKINITCMD_DISABLE;
2628 ppd->cpspec->chase_end = 0;
2629 /*
2630 * stop state chase counter and timer, if running.
2631 * wait forpending timer, but don't clear .data (ppd)!
2632 */
2633 if (ppd->cpspec->chase_timer.expires) {
2634 del_timer_sync(&ppd->cpspec->chase_timer);
2635 ppd->cpspec->chase_timer.expires = 0;
2636 }
2637 break;
2638
2639 default:
2640 ret = -EINVAL;
2641 qib_dev_err(dd, "bad linkinitcmd req 0x%x\n",
2642 val & 0xffff);
2643 goto bail;
2644 }
2645 qib_set_ib_7220_lstate(ppd, lcmd, licmd);
Mitko Haralanove800bd02011-07-14 13:40:24 +00002646
2647 maskr = IBA7220_IBC_WIDTH_MASK;
2648 lsb = IBA7220_IBC_WIDTH_SHIFT;
2649 tmp = (ppd->cpspec->ibcddrctrl >> lsb) & maskr;
2650 /* If the width active on the chip does not match the
2651 * width in the shadow register, write the new active
2652 * width to the chip.
2653 * We don't have to worry about speed as the speed is taken
2654 * care of by set_7220_ibspeed_fast called by ib_updown.
2655 */
2656 if (ppd->link_width_enabled-1 != tmp) {
2657 ppd->cpspec->ibcddrctrl &= ~(maskr << lsb);
2658 ppd->cpspec->ibcddrctrl |=
2659 (((u64)(ppd->link_width_enabled-1) & maskr) <<
2660 lsb);
2661 qib_write_kreg(dd, kr_ibcddrctrl,
2662 ppd->cpspec->ibcddrctrl);
2663 qib_write_kreg(dd, kr_scratch, 0);
2664 spin_lock_irqsave(&ppd->lflags_lock, flags);
2665 ppd->lflags |= QIBL_IB_FORCE_NOTIFY;
2666 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
2667 }
Ralph Campbellf9315512010-05-23 21:44:54 -07002668 goto bail;
2669
2670 case QIB_IB_CFG_HRTBT: /* set Heartbeat off/enable/auto */
2671 if (val > IBA7220_IBC_HRTBT_MASK) {
2672 ret = -EINVAL;
2673 goto bail;
2674 }
2675 lsb = IBA7220_IBC_HRTBT_SHIFT;
2676 maskr = IBA7220_IBC_HRTBT_MASK;
2677 break;
2678
2679 default:
2680 ret = -EINVAL;
2681 goto bail;
2682 }
2683 ppd->cpspec->ibcddrctrl &= ~(maskr << lsb);
2684 ppd->cpspec->ibcddrctrl |= (((u64) val & maskr) << lsb);
2685 qib_write_kreg(dd, kr_ibcddrctrl, ppd->cpspec->ibcddrctrl);
2686 qib_write_kreg(dd, kr_scratch, 0);
2687 if (setforce) {
2688 spin_lock_irqsave(&ppd->lflags_lock, flags);
2689 ppd->lflags |= QIBL_IB_FORCE_NOTIFY;
2690 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
2691 }
2692bail:
2693 return ret;
2694}
2695
2696static int qib_7220_set_loopback(struct qib_pportdata *ppd, const char *what)
2697{
2698 int ret = 0;
2699 u64 val, ddr;
2700
2701 if (!strncmp(what, "ibc", 3)) {
2702 ppd->cpspec->ibcctrl |= SYM_MASK(IBCCtrl, Loopback);
2703 val = 0; /* disable heart beat, so link will come up */
2704 qib_devinfo(ppd->dd->pcidev, "Enabling IB%u:%u IBC loopback\n",
2705 ppd->dd->unit, ppd->port);
2706 } else if (!strncmp(what, "off", 3)) {
2707 ppd->cpspec->ibcctrl &= ~SYM_MASK(IBCCtrl, Loopback);
2708 /* enable heart beat again */
2709 val = IBA7220_IBC_HRTBT_MASK << IBA7220_IBC_HRTBT_SHIFT;
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00002710 qib_devinfo(ppd->dd->pcidev,
2711 "Disabling IB%u:%u IBC loopback (normal)\n",
2712 ppd->dd->unit, ppd->port);
Ralph Campbellf9315512010-05-23 21:44:54 -07002713 } else
2714 ret = -EINVAL;
2715 if (!ret) {
2716 qib_write_kreg(ppd->dd, kr_ibcctrl, ppd->cpspec->ibcctrl);
2717 ddr = ppd->cpspec->ibcddrctrl & ~(IBA7220_IBC_HRTBT_MASK
2718 << IBA7220_IBC_HRTBT_SHIFT);
2719 ppd->cpspec->ibcddrctrl = ddr | val;
2720 qib_write_kreg(ppd->dd, kr_ibcddrctrl,
2721 ppd->cpspec->ibcddrctrl);
2722 qib_write_kreg(ppd->dd, kr_scratch, 0);
2723 }
2724 return ret;
2725}
2726
2727static void qib_update_7220_usrhead(struct qib_ctxtdata *rcd, u64 hd,
Mike Marciniszyn19ede2e2011-01-10 17:42:21 -08002728 u32 updegr, u32 egrhd, u32 npkts)
Ralph Campbellf9315512010-05-23 21:44:54 -07002729{
Ralph Campbellf9315512010-05-23 21:44:54 -07002730 if (updegr)
2731 qib_write_ureg(rcd->dd, ur_rcvegrindexhead, egrhd, rcd->ctxt);
Ram Vepaeddfb672011-12-23 08:01:43 -05002732 mmiowb();
2733 qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
2734 mmiowb();
Ralph Campbellf9315512010-05-23 21:44:54 -07002735}
2736
2737static u32 qib_7220_hdrqempty(struct qib_ctxtdata *rcd)
2738{
2739 u32 head, tail;
2740
2741 head = qib_read_ureg32(rcd->dd, ur_rcvhdrhead, rcd->ctxt);
2742 if (rcd->rcvhdrtail_kvaddr)
2743 tail = qib_get_rcvhdrtail(rcd);
2744 else
2745 tail = qib_read_ureg32(rcd->dd, ur_rcvhdrtail, rcd->ctxt);
2746 return head == tail;
2747}
2748
2749/*
2750 * Modify the RCVCTRL register in chip-specific way. This
2751 * is a function because bit positions and (future) register
2752 * location is chip-specifc, but the needed operations are
2753 * generic. <op> is a bit-mask because we often want to
2754 * do multiple modifications.
2755 */
2756static void rcvctrl_7220_mod(struct qib_pportdata *ppd, unsigned int op,
2757 int ctxt)
2758{
2759 struct qib_devdata *dd = ppd->dd;
2760 u64 mask, val;
2761 unsigned long flags;
2762
2763 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
2764 if (op & QIB_RCVCTRL_TAILUPD_ENB)
2765 dd->rcvctrl |= (1ULL << IBA7220_R_TAILUPD_SHIFT);
2766 if (op & QIB_RCVCTRL_TAILUPD_DIS)
2767 dd->rcvctrl &= ~(1ULL << IBA7220_R_TAILUPD_SHIFT);
2768 if (op & QIB_RCVCTRL_PKEY_ENB)
2769 dd->rcvctrl &= ~(1ULL << IBA7220_R_PKEY_DIS_SHIFT);
2770 if (op & QIB_RCVCTRL_PKEY_DIS)
2771 dd->rcvctrl |= (1ULL << IBA7220_R_PKEY_DIS_SHIFT);
2772 if (ctxt < 0)
2773 mask = (1ULL << dd->ctxtcnt) - 1;
2774 else
2775 mask = (1ULL << ctxt);
2776 if (op & QIB_RCVCTRL_CTXT_ENB) {
2777 /* always done for specific ctxt */
2778 dd->rcvctrl |= (mask << SYM_LSB(RcvCtrl, PortEnable));
2779 if (!(dd->flags & QIB_NODMA_RTAIL))
2780 dd->rcvctrl |= 1ULL << IBA7220_R_TAILUPD_SHIFT;
2781 /* Write these registers before the context is enabled. */
2782 qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr, ctxt,
2783 dd->rcd[ctxt]->rcvhdrqtailaddr_phys);
2784 qib_write_kreg_ctxt(dd, kr_rcvhdraddr, ctxt,
2785 dd->rcd[ctxt]->rcvhdrq_phys);
2786 dd->rcd[ctxt]->seq_cnt = 1;
2787 }
2788 if (op & QIB_RCVCTRL_CTXT_DIS)
2789 dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, PortEnable));
2790 if (op & QIB_RCVCTRL_INTRAVAIL_ENB)
2791 dd->rcvctrl |= (mask << IBA7220_R_INTRAVAIL_SHIFT);
2792 if (op & QIB_RCVCTRL_INTRAVAIL_DIS)
2793 dd->rcvctrl &= ~(mask << IBA7220_R_INTRAVAIL_SHIFT);
2794 qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
2795 if ((op & QIB_RCVCTRL_INTRAVAIL_ENB) && dd->rhdrhead_intr_off) {
2796 /* arm rcv interrupt */
2797 val = qib_read_ureg32(dd, ur_rcvhdrhead, ctxt) |
2798 dd->rhdrhead_intr_off;
2799 qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
2800 }
2801 if (op & QIB_RCVCTRL_CTXT_ENB) {
2802 /*
2803 * Init the context registers also; if we were
2804 * disabled, tail and head should both be zero
2805 * already from the enable, but since we don't
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002806 * know, we have to do it explicitly.
Ralph Campbellf9315512010-05-23 21:44:54 -07002807 */
2808 val = qib_read_ureg32(dd, ur_rcvegrindextail, ctxt);
2809 qib_write_ureg(dd, ur_rcvegrindexhead, val, ctxt);
2810
2811 val = qib_read_ureg32(dd, ur_rcvhdrtail, ctxt);
2812 dd->rcd[ctxt]->head = val;
2813 /* If kctxt, interrupt on next receive. */
2814 if (ctxt < dd->first_user_ctxt)
2815 val |= dd->rhdrhead_intr_off;
2816 qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
2817 }
2818 if (op & QIB_RCVCTRL_CTXT_DIS) {
2819 if (ctxt >= 0) {
2820 qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr, ctxt, 0);
2821 qib_write_kreg_ctxt(dd, kr_rcvhdraddr, ctxt, 0);
2822 } else {
2823 unsigned i;
2824
2825 for (i = 0; i < dd->cfgctxts; i++) {
2826 qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr,
2827 i, 0);
2828 qib_write_kreg_ctxt(dd, kr_rcvhdraddr, i, 0);
2829 }
2830 }
2831 }
2832 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
2833}
2834
2835/*
2836 * Modify the SENDCTRL register in chip-specific way. This
2837 * is a function there may be multiple such registers with
2838 * slightly different layouts. To start, we assume the
2839 * "canonical" register layout of the first chips.
2840 * Chip requires no back-back sendctrl writes, so write
2841 * scratch register after writing sendctrl
2842 */
2843static void sendctrl_7220_mod(struct qib_pportdata *ppd, u32 op)
2844{
2845 struct qib_devdata *dd = ppd->dd;
2846 u64 tmp_dd_sendctrl;
2847 unsigned long flags;
2848
2849 spin_lock_irqsave(&dd->sendctrl_lock, flags);
2850
2851 /* First the ones that are "sticky", saved in shadow */
2852 if (op & QIB_SENDCTRL_CLEAR)
2853 dd->sendctrl = 0;
2854 if (op & QIB_SENDCTRL_SEND_DIS)
2855 dd->sendctrl &= ~SYM_MASK(SendCtrl, SPioEnable);
2856 else if (op & QIB_SENDCTRL_SEND_ENB) {
2857 dd->sendctrl |= SYM_MASK(SendCtrl, SPioEnable);
2858 if (dd->flags & QIB_USE_SPCL_TRIG)
2859 dd->sendctrl |= SYM_MASK(SendCtrl,
2860 SSpecialTriggerEn);
2861 }
2862 if (op & QIB_SENDCTRL_AVAIL_DIS)
2863 dd->sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
2864 else if (op & QIB_SENDCTRL_AVAIL_ENB)
2865 dd->sendctrl |= SYM_MASK(SendCtrl, SendBufAvailUpd);
2866
2867 if (op & QIB_SENDCTRL_DISARM_ALL) {
2868 u32 i, last;
2869
2870 tmp_dd_sendctrl = dd->sendctrl;
2871 /*
2872 * disarm any that are not yet launched, disabling sends
2873 * and updates until done.
2874 */
2875 last = dd->piobcnt2k + dd->piobcnt4k;
2876 tmp_dd_sendctrl &=
2877 ~(SYM_MASK(SendCtrl, SPioEnable) |
2878 SYM_MASK(SendCtrl, SendBufAvailUpd));
2879 for (i = 0; i < last; i++) {
2880 qib_write_kreg(dd, kr_sendctrl,
2881 tmp_dd_sendctrl |
2882 SYM_MASK(SendCtrl, Disarm) | i);
2883 qib_write_kreg(dd, kr_scratch, 0);
2884 }
2885 }
2886
2887 tmp_dd_sendctrl = dd->sendctrl;
2888
2889 if (op & QIB_SENDCTRL_FLUSH)
2890 tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Abort);
2891 if (op & QIB_SENDCTRL_DISARM)
2892 tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Disarm) |
2893 ((op & QIB_7220_SendCtrl_DisarmPIOBuf_RMASK) <<
2894 SYM_LSB(SendCtrl, DisarmPIOBuf));
2895 if ((op & QIB_SENDCTRL_AVAIL_BLIP) &&
2896 (dd->sendctrl & SYM_MASK(SendCtrl, SendBufAvailUpd)))
2897 tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
2898
2899 qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl);
2900 qib_write_kreg(dd, kr_scratch, 0);
2901
2902 if (op & QIB_SENDCTRL_AVAIL_BLIP) {
2903 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
2904 qib_write_kreg(dd, kr_scratch, 0);
2905 }
2906
2907 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
2908
2909 if (op & QIB_SENDCTRL_FLUSH) {
2910 u32 v;
2911 /*
2912 * ensure writes have hit chip, then do a few
2913 * more reads, to allow DMA of pioavail registers
2914 * to occur, so in-memory copy is in sync with
2915 * the chip. Not always safe to sleep.
2916 */
2917 v = qib_read_kreg32(dd, kr_scratch);
2918 qib_write_kreg(dd, kr_scratch, v);
2919 v = qib_read_kreg32(dd, kr_scratch);
2920 qib_write_kreg(dd, kr_scratch, v);
2921 qib_read_kreg32(dd, kr_scratch);
2922 }
2923}
2924
2925/**
2926 * qib_portcntr_7220 - read a per-port counter
2927 * @dd: the qlogic_ib device
2928 * @creg: the counter to snapshot
2929 */
2930static u64 qib_portcntr_7220(struct qib_pportdata *ppd, u32 reg)
2931{
2932 u64 ret = 0ULL;
2933 struct qib_devdata *dd = ppd->dd;
2934 u16 creg;
2935 /* 0xffff for unimplemented or synthesized counters */
2936 static const u16 xlator[] = {
2937 [QIBPORTCNTR_PKTSEND] = cr_pktsend,
2938 [QIBPORTCNTR_WORDSEND] = cr_wordsend,
2939 [QIBPORTCNTR_PSXMITDATA] = cr_psxmitdatacount,
2940 [QIBPORTCNTR_PSXMITPKTS] = cr_psxmitpktscount,
2941 [QIBPORTCNTR_PSXMITWAIT] = cr_psxmitwaitcount,
2942 [QIBPORTCNTR_SENDSTALL] = cr_sendstall,
2943 [QIBPORTCNTR_PKTRCV] = cr_pktrcv,
2944 [QIBPORTCNTR_PSRCVDATA] = cr_psrcvdatacount,
2945 [QIBPORTCNTR_PSRCVPKTS] = cr_psrcvpktscount,
2946 [QIBPORTCNTR_RCVEBP] = cr_rcvebp,
2947 [QIBPORTCNTR_RCVOVFL] = cr_rcvovfl,
2948 [QIBPORTCNTR_WORDRCV] = cr_wordrcv,
2949 [QIBPORTCNTR_RXDROPPKT] = cr_rxdroppkt,
2950 [QIBPORTCNTR_RXLOCALPHYERR] = cr_rxotherlocalphyerr,
2951 [QIBPORTCNTR_RXVLERR] = cr_rxvlerr,
2952 [QIBPORTCNTR_ERRICRC] = cr_erricrc,
2953 [QIBPORTCNTR_ERRVCRC] = cr_errvcrc,
2954 [QIBPORTCNTR_ERRLPCRC] = cr_errlpcrc,
2955 [QIBPORTCNTR_BADFORMAT] = cr_badformat,
2956 [QIBPORTCNTR_ERR_RLEN] = cr_err_rlen,
2957 [QIBPORTCNTR_IBSYMBOLERR] = cr_ibsymbolerr,
2958 [QIBPORTCNTR_INVALIDRLEN] = cr_invalidrlen,
2959 [QIBPORTCNTR_UNSUPVL] = cr_txunsupvl,
2960 [QIBPORTCNTR_EXCESSBUFOVFL] = cr_excessbufferovfl,
2961 [QIBPORTCNTR_ERRLINK] = cr_errlink,
2962 [QIBPORTCNTR_IBLINKDOWN] = cr_iblinkdown,
2963 [QIBPORTCNTR_IBLINKERRRECOV] = cr_iblinkerrrecov,
2964 [QIBPORTCNTR_LLI] = cr_locallinkintegrityerr,
2965 [QIBPORTCNTR_PSINTERVAL] = cr_psinterval,
2966 [QIBPORTCNTR_PSSTART] = cr_psstart,
2967 [QIBPORTCNTR_PSSTAT] = cr_psstat,
2968 [QIBPORTCNTR_VL15PKTDROP] = cr_vl15droppedpkt,
2969 [QIBPORTCNTR_ERRPKEY] = cr_errpkey,
2970 [QIBPORTCNTR_KHDROVFL] = 0xffff,
2971 };
2972
2973 if (reg >= ARRAY_SIZE(xlator)) {
2974 qib_devinfo(ppd->dd->pcidev,
2975 "Unimplemented portcounter %u\n", reg);
2976 goto done;
2977 }
2978 creg = xlator[reg];
2979
2980 if (reg == QIBPORTCNTR_KHDROVFL) {
2981 int i;
2982
2983 /* sum over all kernel contexts */
2984 for (i = 0; i < dd->first_user_ctxt; i++)
2985 ret += read_7220_creg32(dd, cr_portovfl + i);
2986 }
2987 if (creg == 0xffff)
2988 goto done;
2989
2990 /*
2991 * only fast incrementing counters are 64bit; use 32 bit reads to
2992 * avoid two independent reads when on opteron
2993 */
2994 if ((creg == cr_wordsend || creg == cr_wordrcv ||
2995 creg == cr_pktsend || creg == cr_pktrcv))
2996 ret = read_7220_creg(dd, creg);
2997 else
2998 ret = read_7220_creg32(dd, creg);
2999 if (creg == cr_ibsymbolerr) {
3000 if (dd->pport->cpspec->ibdeltainprog)
3001 ret -= ret - ppd->cpspec->ibsymsnap;
3002 ret -= dd->pport->cpspec->ibsymdelta;
3003 } else if (creg == cr_iblinkerrrecov) {
3004 if (dd->pport->cpspec->ibdeltainprog)
3005 ret -= ret - ppd->cpspec->iblnkerrsnap;
3006 ret -= dd->pport->cpspec->iblnkerrdelta;
3007 }
3008done:
3009 return ret;
3010}
3011
3012/*
3013 * Device counter names (not port-specific), one line per stat,
3014 * single string. Used by utilities like ipathstats to print the stats
3015 * in a way which works for different versions of drivers, without changing
3016 * the utility. Names need to be 12 chars or less (w/o newline), for proper
3017 * display by utility.
3018 * Non-error counters are first.
3019 * Start of "error" conters is indicated by a leading "E " on the first
3020 * "error" counter, and doesn't count in label length.
3021 * The EgrOvfl list needs to be last so we truncate them at the configured
3022 * context count for the device.
3023 * cntr7220indices contains the corresponding register indices.
3024 */
3025static const char cntr7220names[] =
3026 "Interrupts\n"
3027 "HostBusStall\n"
3028 "E RxTIDFull\n"
3029 "RxTIDInvalid\n"
3030 "Ctxt0EgrOvfl\n"
3031 "Ctxt1EgrOvfl\n"
3032 "Ctxt2EgrOvfl\n"
3033 "Ctxt3EgrOvfl\n"
3034 "Ctxt4EgrOvfl\n"
3035 "Ctxt5EgrOvfl\n"
3036 "Ctxt6EgrOvfl\n"
3037 "Ctxt7EgrOvfl\n"
3038 "Ctxt8EgrOvfl\n"
3039 "Ctxt9EgrOvfl\n"
3040 "Ctx10EgrOvfl\n"
3041 "Ctx11EgrOvfl\n"
3042 "Ctx12EgrOvfl\n"
3043 "Ctx13EgrOvfl\n"
3044 "Ctx14EgrOvfl\n"
3045 "Ctx15EgrOvfl\n"
3046 "Ctx16EgrOvfl\n";
3047
3048static const size_t cntr7220indices[] = {
3049 cr_lbint,
3050 cr_lbflowstall,
3051 cr_errtidfull,
3052 cr_errtidvalid,
3053 cr_portovfl + 0,
3054 cr_portovfl + 1,
3055 cr_portovfl + 2,
3056 cr_portovfl + 3,
3057 cr_portovfl + 4,
3058 cr_portovfl + 5,
3059 cr_portovfl + 6,
3060 cr_portovfl + 7,
3061 cr_portovfl + 8,
3062 cr_portovfl + 9,
3063 cr_portovfl + 10,
3064 cr_portovfl + 11,
3065 cr_portovfl + 12,
3066 cr_portovfl + 13,
3067 cr_portovfl + 14,
3068 cr_portovfl + 15,
3069 cr_portovfl + 16,
3070};
3071
3072/*
3073 * same as cntr7220names and cntr7220indices, but for port-specific counters.
3074 * portcntr7220indices is somewhat complicated by some registers needing
3075 * adjustments of various kinds, and those are ORed with _PORT_VIRT_FLAG
3076 */
3077static const char portcntr7220names[] =
3078 "TxPkt\n"
3079 "TxFlowPkt\n"
3080 "TxWords\n"
3081 "RxPkt\n"
3082 "RxFlowPkt\n"
3083 "RxWords\n"
3084 "TxFlowStall\n"
3085 "TxDmaDesc\n" /* 7220 and 7322-only */
3086 "E RxDlidFltr\n" /* 7220 and 7322-only */
3087 "IBStatusChng\n"
3088 "IBLinkDown\n"
3089 "IBLnkRecov\n"
3090 "IBRxLinkErr\n"
3091 "IBSymbolErr\n"
3092 "RxLLIErr\n"
3093 "RxBadFormat\n"
3094 "RxBadLen\n"
3095 "RxBufOvrfl\n"
3096 "RxEBP\n"
3097 "RxFlowCtlErr\n"
3098 "RxICRCerr\n"
3099 "RxLPCRCerr\n"
3100 "RxVCRCerr\n"
3101 "RxInvalLen\n"
3102 "RxInvalPKey\n"
3103 "RxPktDropped\n"
3104 "TxBadLength\n"
3105 "TxDropped\n"
3106 "TxInvalLen\n"
3107 "TxUnderrun\n"
3108 "TxUnsupVL\n"
3109 "RxLclPhyErr\n" /* 7220 and 7322-only */
3110 "RxVL15Drop\n" /* 7220 and 7322-only */
3111 "RxVlErr\n" /* 7220 and 7322-only */
3112 "XcessBufOvfl\n" /* 7220 and 7322-only */
3113 ;
3114
3115#define _PORT_VIRT_FLAG 0x8000 /* "virtual", need adjustments */
3116static const size_t portcntr7220indices[] = {
3117 QIBPORTCNTR_PKTSEND | _PORT_VIRT_FLAG,
3118 cr_pktsendflow,
3119 QIBPORTCNTR_WORDSEND | _PORT_VIRT_FLAG,
3120 QIBPORTCNTR_PKTRCV | _PORT_VIRT_FLAG,
3121 cr_pktrcvflowctrl,
3122 QIBPORTCNTR_WORDRCV | _PORT_VIRT_FLAG,
3123 QIBPORTCNTR_SENDSTALL | _PORT_VIRT_FLAG,
3124 cr_txsdmadesc,
3125 cr_rxdlidfltr,
3126 cr_ibstatuschange,
3127 QIBPORTCNTR_IBLINKDOWN | _PORT_VIRT_FLAG,
3128 QIBPORTCNTR_IBLINKERRRECOV | _PORT_VIRT_FLAG,
3129 QIBPORTCNTR_ERRLINK | _PORT_VIRT_FLAG,
3130 QIBPORTCNTR_IBSYMBOLERR | _PORT_VIRT_FLAG,
3131 QIBPORTCNTR_LLI | _PORT_VIRT_FLAG,
3132 QIBPORTCNTR_BADFORMAT | _PORT_VIRT_FLAG,
3133 QIBPORTCNTR_ERR_RLEN | _PORT_VIRT_FLAG,
3134 QIBPORTCNTR_RCVOVFL | _PORT_VIRT_FLAG,
3135 QIBPORTCNTR_RCVEBP | _PORT_VIRT_FLAG,
3136 cr_rcvflowctrl_err,
3137 QIBPORTCNTR_ERRICRC | _PORT_VIRT_FLAG,
3138 QIBPORTCNTR_ERRLPCRC | _PORT_VIRT_FLAG,
3139 QIBPORTCNTR_ERRVCRC | _PORT_VIRT_FLAG,
3140 QIBPORTCNTR_INVALIDRLEN | _PORT_VIRT_FLAG,
3141 QIBPORTCNTR_ERRPKEY | _PORT_VIRT_FLAG,
3142 QIBPORTCNTR_RXDROPPKT | _PORT_VIRT_FLAG,
3143 cr_invalidslen,
3144 cr_senddropped,
3145 cr_errslen,
3146 cr_sendunderrun,
3147 cr_txunsupvl,
3148 QIBPORTCNTR_RXLOCALPHYERR | _PORT_VIRT_FLAG,
3149 QIBPORTCNTR_VL15PKTDROP | _PORT_VIRT_FLAG,
3150 QIBPORTCNTR_RXVLERR | _PORT_VIRT_FLAG,
3151 QIBPORTCNTR_EXCESSBUFOVFL | _PORT_VIRT_FLAG,
3152};
3153
3154/* do all the setup to make the counter reads efficient later */
3155static void init_7220_cntrnames(struct qib_devdata *dd)
3156{
3157 int i, j = 0;
3158 char *s;
3159
3160 for (i = 0, s = (char *)cntr7220names; s && j <= dd->cfgctxts;
3161 i++) {
3162 /* we always have at least one counter before the egrovfl */
3163 if (!j && !strncmp("Ctxt0EgrOvfl", s + 1, 12))
3164 j = 1;
3165 s = strchr(s + 1, '\n');
3166 if (s && j)
3167 j++;
3168 }
3169 dd->cspec->ncntrs = i;
3170 if (!s)
3171 /* full list; size is without terminating null */
3172 dd->cspec->cntrnamelen = sizeof(cntr7220names) - 1;
3173 else
3174 dd->cspec->cntrnamelen = 1 + s - cntr7220names;
3175 dd->cspec->cntrs = kmalloc(dd->cspec->ncntrs
3176 * sizeof(u64), GFP_KERNEL);
Ralph Campbellf9315512010-05-23 21:44:54 -07003177
3178 for (i = 0, s = (char *)portcntr7220names; s; i++)
3179 s = strchr(s + 1, '\n');
3180 dd->cspec->nportcntrs = i - 1;
3181 dd->cspec->portcntrnamelen = sizeof(portcntr7220names) - 1;
3182 dd->cspec->portcntrs = kmalloc(dd->cspec->nportcntrs
3183 * sizeof(u64), GFP_KERNEL);
Ralph Campbellf9315512010-05-23 21:44:54 -07003184}
3185
3186static u32 qib_read_7220cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
3187 u64 **cntrp)
3188{
3189 u32 ret;
3190
3191 if (!dd->cspec->cntrs) {
3192 ret = 0;
3193 goto done;
3194 }
3195
3196 if (namep) {
3197 *namep = (char *)cntr7220names;
3198 ret = dd->cspec->cntrnamelen;
3199 if (pos >= ret)
3200 ret = 0; /* final read after getting everything */
3201 } else {
3202 u64 *cntr = dd->cspec->cntrs;
3203 int i;
3204
3205 ret = dd->cspec->ncntrs * sizeof(u64);
3206 if (!cntr || pos >= ret) {
3207 /* everything read, or couldn't get memory */
3208 ret = 0;
3209 goto done;
3210 }
3211
3212 *cntrp = cntr;
3213 for (i = 0; i < dd->cspec->ncntrs; i++)
3214 *cntr++ = read_7220_creg32(dd, cntr7220indices[i]);
3215 }
3216done:
3217 return ret;
3218}
3219
3220static u32 qib_read_7220portcntrs(struct qib_devdata *dd, loff_t pos, u32 port,
3221 char **namep, u64 **cntrp)
3222{
3223 u32 ret;
3224
3225 if (!dd->cspec->portcntrs) {
3226 ret = 0;
3227 goto done;
3228 }
3229 if (namep) {
3230 *namep = (char *)portcntr7220names;
3231 ret = dd->cspec->portcntrnamelen;
3232 if (pos >= ret)
3233 ret = 0; /* final read after getting everything */
3234 } else {
3235 u64 *cntr = dd->cspec->portcntrs;
3236 struct qib_pportdata *ppd = &dd->pport[port];
3237 int i;
3238
3239 ret = dd->cspec->nportcntrs * sizeof(u64);
3240 if (!cntr || pos >= ret) {
3241 /* everything read, or couldn't get memory */
3242 ret = 0;
3243 goto done;
3244 }
3245 *cntrp = cntr;
3246 for (i = 0; i < dd->cspec->nportcntrs; i++) {
3247 if (portcntr7220indices[i] & _PORT_VIRT_FLAG)
3248 *cntr++ = qib_portcntr_7220(ppd,
3249 portcntr7220indices[i] &
3250 ~_PORT_VIRT_FLAG);
3251 else
3252 *cntr++ = read_7220_creg32(dd,
3253 portcntr7220indices[i]);
3254 }
3255 }
3256done:
3257 return ret;
3258}
3259
3260/**
3261 * qib_get_7220_faststats - get word counters from chip before they overflow
3262 * @opaque - contains a pointer to the qlogic_ib device qib_devdata
3263 *
3264 * This needs more work; in particular, decision on whether we really
3265 * need traffic_wds done the way it is
3266 * called from add_timer
3267 */
Kees Cook4037c922017-10-04 17:45:35 -07003268static void qib_get_7220_faststats(struct timer_list *t)
Ralph Campbellf9315512010-05-23 21:44:54 -07003269{
Kees Cook4037c922017-10-04 17:45:35 -07003270 struct qib_devdata *dd = from_timer(dd, t, stats_timer);
Ralph Campbellf9315512010-05-23 21:44:54 -07003271 struct qib_pportdata *ppd = dd->pport;
3272 unsigned long flags;
3273 u64 traffic_wds;
3274
3275 /*
3276 * don't access the chip while running diags, or memory diags can
3277 * fail
3278 */
3279 if (!(dd->flags & QIB_INITTED) || dd->diag_client)
3280 /* but re-arm the timer, for diags case; won't hurt other */
3281 goto done;
3282
3283 /*
3284 * We now try to maintain an activity timer, based on traffic
3285 * exceeding a threshold, so we need to check the word-counts
3286 * even if they are 64-bit.
3287 */
3288 traffic_wds = qib_portcntr_7220(ppd, cr_wordsend) +
3289 qib_portcntr_7220(ppd, cr_wordrcv);
3290 spin_lock_irqsave(&dd->eep_st_lock, flags);
3291 traffic_wds -= dd->traffic_wds;
3292 dd->traffic_wds += traffic_wds;
Ralph Campbellf9315512010-05-23 21:44:54 -07003293 spin_unlock_irqrestore(&dd->eep_st_lock, flags);
3294done:
3295 mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);
3296}
3297
3298/*
3299 * If we are using MSI, try to fallback to INTx.
3300 */
3301static int qib_7220_intr_fallback(struct qib_devdata *dd)
3302{
3303 if (!dd->msi_lo)
3304 return 0;
3305
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00003306 qib_devinfo(dd->pcidev,
3307 "MSI interrupt not detected, trying INTx interrupts\n");
Ralph Campbellf9315512010-05-23 21:44:54 -07003308 qib_7220_free_irq(dd);
Michael J. Ruhl581d01a2017-06-09 16:00:06 -07003309 qib_enable_intx(dd);
Ralph Campbellf9315512010-05-23 21:44:54 -07003310 /*
3311 * Some newer kernels require free_irq before disable_msi,
3312 * and irq can be changed during disable and INTx enable
3313 * and we need to therefore use the pcidev->irq value,
3314 * not our saved MSI value.
3315 */
3316 dd->cspec->irq = dd->pcidev->irq;
3317 qib_setup_7220_interrupt(dd);
3318 return 1;
3319}
3320
3321/*
3322 * Reset the XGXS (between serdes and IBC). Slightly less intrusive
3323 * than resetting the IBC or external link state, and useful in some
3324 * cases to cause some retraining. To do this right, we reset IBC
3325 * as well.
3326 */
3327static void qib_7220_xgxs_reset(struct qib_pportdata *ppd)
3328{
3329 u64 val, prev_val;
3330 struct qib_devdata *dd = ppd->dd;
3331
3332 prev_val = qib_read_kreg64(dd, kr_xgxs_cfg);
3333 val = prev_val | QLOGIC_IB_XGXS_RESET;
3334 prev_val &= ~QLOGIC_IB_XGXS_RESET; /* be sure */
3335 qib_write_kreg(dd, kr_control,
3336 dd->control & ~QLOGIC_IB_C_LINKENABLE);
3337 qib_write_kreg(dd, kr_xgxs_cfg, val);
3338 qib_read_kreg32(dd, kr_scratch);
3339 qib_write_kreg(dd, kr_xgxs_cfg, prev_val);
3340 qib_write_kreg(dd, kr_control, dd->control);
3341}
3342
3343/*
3344 * For this chip, we want to use the same buffer every time
3345 * when we are trying to bring the link up (they are always VL15
3346 * packets). At that link state the packet should always go out immediately
3347 * (or at least be discarded at the tx interface if the link is down).
3348 * If it doesn't, and the buffer isn't available, that means some other
3349 * sender has gotten ahead of us, and is preventing our packet from going
3350 * out. In that case, we flush all packets, and try again. If that still
3351 * fails, we fail the request, and hope things work the next time around.
3352 *
3353 * We don't need very complicated heuristics on whether the packet had
3354 * time to go out or not, since even at SDR 1X, it goes out in very short
3355 * time periods, covered by the chip reads done here and as part of the
3356 * flush.
3357 */
3358static u32 __iomem *get_7220_link_buf(struct qib_pportdata *ppd, u32 *bnum)
3359{
3360 u32 __iomem *buf;
3361 u32 lbuf = ppd->dd->cspec->lastbuf_for_pio;
3362 int do_cleanup;
3363 unsigned long flags;
3364
3365 /*
3366 * always blip to get avail list updated, since it's almost
3367 * always needed, and is fairly cheap.
3368 */
3369 sendctrl_7220_mod(ppd->dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
3370 qib_read_kreg64(ppd->dd, kr_scratch); /* extra chip flush */
3371 buf = qib_getsendbuf_range(ppd->dd, bnum, lbuf, lbuf);
3372 if (buf)
3373 goto done;
3374
3375 spin_lock_irqsave(&ppd->sdma_lock, flags);
3376 if (ppd->sdma_state.current_state == qib_sdma_state_s20_idle &&
3377 ppd->sdma_state.current_state != qib_sdma_state_s00_hw_down) {
3378 __qib_sdma_process_event(ppd, qib_sdma_event_e00_go_hw_down);
3379 do_cleanup = 0;
3380 } else {
3381 do_cleanup = 1;
3382 qib_7220_sdma_hw_clean_up(ppd);
3383 }
3384 spin_unlock_irqrestore(&ppd->sdma_lock, flags);
3385
3386 if (do_cleanup) {
3387 qib_read_kreg64(ppd->dd, kr_scratch); /* extra chip flush */
3388 buf = qib_getsendbuf_range(ppd->dd, bnum, lbuf, lbuf);
3389 }
3390done:
3391 return buf;
3392}
3393
3394/*
3395 * This code for non-IBTA-compliant IB speed negotiation is only known to
3396 * work for the SDR to DDR transition, and only between an HCA and a switch
3397 * with recent firmware. It is based on observed heuristics, rather than
3398 * actual knowledge of the non-compliant speed negotiation.
3399 * It has a number of hard-coded fields, since the hope is to rewrite this
3400 * when a spec is available on how the negoation is intended to work.
3401 */
3402static void autoneg_7220_sendpkt(struct qib_pportdata *ppd, u32 *hdr,
3403 u32 dcnt, u32 *data)
3404{
3405 int i;
3406 u64 pbc;
3407 u32 __iomem *piobuf;
3408 u32 pnum;
3409 struct qib_devdata *dd = ppd->dd;
3410
3411 i = 0;
3412 pbc = 7 + dcnt + 1; /* 7 dword header, dword data, icrc */
3413 pbc |= PBC_7220_VL15_SEND;
3414 while (!(piobuf = get_7220_link_buf(ppd, &pnum))) {
3415 if (i++ > 5)
3416 return;
3417 udelay(2);
3418 }
3419 sendctrl_7220_mod(dd->pport, QIB_SENDCTRL_DISARM_BUF(pnum));
3420 writeq(pbc, piobuf);
3421 qib_flush_wc();
3422 qib_pio_copy(piobuf + 2, hdr, 7);
3423 qib_pio_copy(piobuf + 9, data, dcnt);
3424 if (dd->flags & QIB_USE_SPCL_TRIG) {
3425 u32 spcl_off = (pnum >= dd->piobcnt2k) ? 2047 : 1023;
3426
3427 qib_flush_wc();
3428 __raw_writel(0xaebecede, piobuf + spcl_off);
3429 }
3430 qib_flush_wc();
3431 qib_sendbuf_done(dd, pnum);
3432}
3433
3434/*
3435 * _start packet gets sent twice at start, _done gets sent twice at end
3436 */
3437static void autoneg_7220_send(struct qib_pportdata *ppd, int which)
3438{
3439 struct qib_devdata *dd = ppd->dd;
3440 static u32 swapped;
3441 u32 dw, i, hcnt, dcnt, *data;
3442 static u32 hdr[7] = { 0xf002ffff, 0x48ffff, 0x6400abba };
3443 static u32 madpayload_start[0x40] = {
3444 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
3445 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
3446 0x1, 0x1388, 0x15e, 0x1, /* rest 0's */
3447 };
3448 static u32 madpayload_done[0x40] = {
3449 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
3450 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
3451 0x40000001, 0x1388, 0x15e, /* rest 0's */
3452 };
3453
3454 dcnt = ARRAY_SIZE(madpayload_start);
3455 hcnt = ARRAY_SIZE(hdr);
3456 if (!swapped) {
3457 /* for maintainability, do it at runtime */
3458 for (i = 0; i < hcnt; i++) {
3459 dw = (__force u32) cpu_to_be32(hdr[i]);
3460 hdr[i] = dw;
3461 }
3462 for (i = 0; i < dcnt; i++) {
3463 dw = (__force u32) cpu_to_be32(madpayload_start[i]);
3464 madpayload_start[i] = dw;
3465 dw = (__force u32) cpu_to_be32(madpayload_done[i]);
3466 madpayload_done[i] = dw;
3467 }
3468 swapped = 1;
3469 }
3470
3471 data = which ? madpayload_done : madpayload_start;
3472
3473 autoneg_7220_sendpkt(ppd, hdr, dcnt, data);
3474 qib_read_kreg64(dd, kr_scratch);
3475 udelay(2);
3476 autoneg_7220_sendpkt(ppd, hdr, dcnt, data);
3477 qib_read_kreg64(dd, kr_scratch);
3478 udelay(2);
3479}
3480
3481/*
3482 * Do the absolute minimum to cause an IB speed change, and make it
3483 * ready, but don't actually trigger the change. The caller will
3484 * do that when ready (if link is in Polling training state, it will
3485 * happen immediately, otherwise when link next goes down)
3486 *
3487 * This routine should only be used as part of the DDR autonegotation
3488 * code for devices that are not compliant with IB 1.2 (or code that
3489 * fixes things up for same).
3490 *
3491 * When link has gone down, and autoneg enabled, or autoneg has
3492 * failed and we give up until next time we set both speeds, and
3493 * then we want IBTA enabled as well as "use max enabled speed.
3494 */
3495static void set_7220_ibspeed_fast(struct qib_pportdata *ppd, u32 speed)
3496{
3497 ppd->cpspec->ibcddrctrl &= ~(IBA7220_IBC_SPEED_AUTONEG_MASK |
3498 IBA7220_IBC_IBTA_1_2_MASK);
3499
3500 if (speed == (QIB_IB_SDR | QIB_IB_DDR))
3501 ppd->cpspec->ibcddrctrl |= IBA7220_IBC_SPEED_AUTONEG_MASK |
3502 IBA7220_IBC_IBTA_1_2_MASK;
3503 else
3504 ppd->cpspec->ibcddrctrl |= speed == QIB_IB_DDR ?
3505 IBA7220_IBC_SPEED_DDR : IBA7220_IBC_SPEED_SDR;
3506
3507 qib_write_kreg(ppd->dd, kr_ibcddrctrl, ppd->cpspec->ibcddrctrl);
3508 qib_write_kreg(ppd->dd, kr_scratch, 0);
3509}
3510
3511/*
3512 * This routine is only used when we are not talking to another
3513 * IB 1.2-compliant device that we think can do DDR.
3514 * (This includes all existing switch chips as of Oct 2007.)
3515 * 1.2-compliant devices go directly to DDR prior to reaching INIT
3516 */
3517static void try_7220_autoneg(struct qib_pportdata *ppd)
3518{
3519 unsigned long flags;
3520
3521 /*
3522 * Required for older non-IB1.2 DDR switches. Newer
3523 * non-IB-compliant switches don't need it, but so far,
3524 * aren't bothered by it either. "Magic constant"
3525 */
3526 qib_write_kreg(ppd->dd, kr_ncmodectrl, 0x3b9dc07);
3527
3528 spin_lock_irqsave(&ppd->lflags_lock, flags);
3529 ppd->lflags |= QIBL_IB_AUTONEG_INPROG;
3530 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
3531 autoneg_7220_send(ppd, 0);
3532 set_7220_ibspeed_fast(ppd, QIB_IB_DDR);
3533
3534 toggle_7220_rclkrls(ppd->dd);
3535 /* 2 msec is minimum length of a poll cycle */
Tejun Heof0626712010-10-19 15:24:36 +00003536 queue_delayed_work(ib_wq, &ppd->cpspec->autoneg_work,
3537 msecs_to_jiffies(2));
Ralph Campbellf9315512010-05-23 21:44:54 -07003538}
3539
3540/*
3541 * Handle the empirically determined mechanism for auto-negotiation
3542 * of DDR speed with switches.
3543 */
3544static void autoneg_7220_work(struct work_struct *work)
3545{
3546 struct qib_pportdata *ppd;
3547 struct qib_devdata *dd;
3548 u64 startms;
3549 u32 i;
3550 unsigned long flags;
3551
3552 ppd = &container_of(work, struct qib_chippport_specific,
3553 autoneg_work.work)->pportdata;
3554 dd = ppd->dd;
3555
3556 startms = jiffies_to_msecs(jiffies);
3557
3558 /*
3559 * Busy wait for this first part, it should be at most a
3560 * few hundred usec, since we scheduled ourselves for 2msec.
3561 */
3562 for (i = 0; i < 25; i++) {
3563 if (SYM_FIELD(ppd->lastibcstat, IBCStatus, LinkTrainingState)
3564 == IB_7220_LT_STATE_POLLQUIET) {
3565 qib_set_linkstate(ppd, QIB_IB_LINKDOWN_DISABLE);
3566 break;
3567 }
3568 udelay(100);
3569 }
3570
3571 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
3572 goto done; /* we got there early or told to stop */
3573
3574 /* we expect this to timeout */
3575 if (wait_event_timeout(ppd->cpspec->autoneg_wait,
3576 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
3577 msecs_to_jiffies(90)))
3578 goto done;
3579
3580 toggle_7220_rclkrls(dd);
3581
3582 /* we expect this to timeout */
3583 if (wait_event_timeout(ppd->cpspec->autoneg_wait,
3584 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
3585 msecs_to_jiffies(1700)))
3586 goto done;
3587
3588 set_7220_ibspeed_fast(ppd, QIB_IB_SDR);
3589 toggle_7220_rclkrls(dd);
3590
3591 /*
3592 * Wait up to 250 msec for link to train and get to INIT at DDR;
3593 * this should terminate early.
3594 */
3595 wait_event_timeout(ppd->cpspec->autoneg_wait,
3596 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
3597 msecs_to_jiffies(250));
3598done:
3599 if (ppd->lflags & QIBL_IB_AUTONEG_INPROG) {
3600 spin_lock_irqsave(&ppd->lflags_lock, flags);
3601 ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
3602 if (dd->cspec->autoneg_tries == AUTONEG_TRIES) {
3603 ppd->lflags |= QIBL_IB_AUTONEG_FAILED;
3604 dd->cspec->autoneg_tries = 0;
3605 }
3606 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
3607 set_7220_ibspeed_fast(ppd, ppd->link_speed_enabled);
3608 }
3609}
3610
3611static u32 qib_7220_iblink_state(u64 ibcs)
3612{
3613 u32 state = (u32)SYM_FIELD(ibcs, IBCStatus, LinkState);
3614
3615 switch (state) {
3616 case IB_7220_L_STATE_INIT:
3617 state = IB_PORT_INIT;
3618 break;
3619 case IB_7220_L_STATE_ARM:
3620 state = IB_PORT_ARMED;
3621 break;
3622 case IB_7220_L_STATE_ACTIVE:
3623 /* fall through */
3624 case IB_7220_L_STATE_ACT_DEFER:
3625 state = IB_PORT_ACTIVE;
3626 break;
3627 default: /* fall through */
3628 case IB_7220_L_STATE_DOWN:
3629 state = IB_PORT_DOWN;
3630 break;
3631 }
3632 return state;
3633}
3634
3635/* returns the IBTA port state, rather than the IBC link training state */
3636static u8 qib_7220_phys_portstate(u64 ibcs)
3637{
3638 u8 state = (u8)SYM_FIELD(ibcs, IBCStatus, LinkTrainingState);
3639 return qib_7220_physportstate[state];
3640}
3641
3642static int qib_7220_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
3643{
3644 int ret = 0, symadj = 0;
3645 struct qib_devdata *dd = ppd->dd;
3646 unsigned long flags;
3647
3648 spin_lock_irqsave(&ppd->lflags_lock, flags);
3649 ppd->lflags &= ~QIBL_IB_FORCE_NOTIFY;
3650 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
3651
3652 if (!ibup) {
3653 /*
3654 * When the link goes down we don't want AEQ running, so it
3655 * won't interfere with IBC training, etc., and we need
3656 * to go back to the static SerDes preset values.
3657 */
3658 if (!(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
3659 QIBL_IB_AUTONEG_INPROG)))
3660 set_7220_ibspeed_fast(ppd, ppd->link_speed_enabled);
3661 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
3662 qib_sd7220_presets(dd);
3663 qib_cancel_sends(ppd); /* initial disarm, etc. */
3664 spin_lock_irqsave(&ppd->sdma_lock, flags);
3665 if (__qib_sdma_running(ppd))
3666 __qib_sdma_process_event(ppd,
3667 qib_sdma_event_e70_go_idle);
3668 spin_unlock_irqrestore(&ppd->sdma_lock, flags);
3669 }
3670 /* this might better in qib_sd7220_presets() */
3671 set_7220_relock_poll(dd, ibup);
3672 } else {
3673 if (qib_compat_ddr_negotiate &&
3674 !(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
3675 QIBL_IB_AUTONEG_INPROG)) &&
3676 ppd->link_speed_active == QIB_IB_SDR &&
3677 (ppd->link_speed_enabled & (QIB_IB_DDR | QIB_IB_SDR)) ==
3678 (QIB_IB_DDR | QIB_IB_SDR) &&
3679 dd->cspec->autoneg_tries < AUTONEG_TRIES) {
3680 /* we are SDR, and DDR auto-negotiation enabled */
3681 ++dd->cspec->autoneg_tries;
3682 if (!ppd->cpspec->ibdeltainprog) {
3683 ppd->cpspec->ibdeltainprog = 1;
3684 ppd->cpspec->ibsymsnap = read_7220_creg32(dd,
3685 cr_ibsymbolerr);
3686 ppd->cpspec->iblnkerrsnap = read_7220_creg32(dd,
3687 cr_iblinkerrrecov);
3688 }
3689 try_7220_autoneg(ppd);
3690 ret = 1; /* no other IB status change processing */
3691 } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
3692 ppd->link_speed_active == QIB_IB_SDR) {
3693 autoneg_7220_send(ppd, 1);
3694 set_7220_ibspeed_fast(ppd, QIB_IB_DDR);
3695 udelay(2);
3696 toggle_7220_rclkrls(dd);
3697 ret = 1; /* no other IB status change processing */
3698 } else {
3699 if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
3700 (ppd->link_speed_active & QIB_IB_DDR)) {
3701 spin_lock_irqsave(&ppd->lflags_lock, flags);
3702 ppd->lflags &= ~(QIBL_IB_AUTONEG_INPROG |
3703 QIBL_IB_AUTONEG_FAILED);
3704 spin_unlock_irqrestore(&ppd->lflags_lock,
3705 flags);
3706 dd->cspec->autoneg_tries = 0;
3707 /* re-enable SDR, for next link down */
3708 set_7220_ibspeed_fast(ppd,
3709 ppd->link_speed_enabled);
3710 wake_up(&ppd->cpspec->autoneg_wait);
3711 symadj = 1;
3712 } else if (ppd->lflags & QIBL_IB_AUTONEG_FAILED) {
3713 /*
3714 * Clear autoneg failure flag, and do setup
3715 * so we'll try next time link goes down and
3716 * back to INIT (possibly connected to a
3717 * different device).
3718 */
3719 spin_lock_irqsave(&ppd->lflags_lock, flags);
3720 ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
3721 spin_unlock_irqrestore(&ppd->lflags_lock,
3722 flags);
3723 ppd->cpspec->ibcddrctrl |=
3724 IBA7220_IBC_IBTA_1_2_MASK;
3725 qib_write_kreg(dd, kr_ncmodectrl, 0);
3726 symadj = 1;
3727 }
3728 }
3729
3730 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
3731 symadj = 1;
3732
3733 if (!ret) {
3734 ppd->delay_mult = rate_to_delay
3735 [(ibcs >> IBA7220_LINKSPEED_SHIFT) & 1]
3736 [(ibcs >> IBA7220_LINKWIDTH_SHIFT) & 1];
3737
3738 set_7220_relock_poll(dd, ibup);
3739 spin_lock_irqsave(&ppd->sdma_lock, flags);
3740 /*
3741 * Unlike 7322, the 7220 needs this, due to lack of
3742 * interrupt in some cases when we have sdma active
3743 * when the link goes down.
3744 */
3745 if (ppd->sdma_state.current_state !=
3746 qib_sdma_state_s20_idle)
3747 __qib_sdma_process_event(ppd,
3748 qib_sdma_event_e00_go_hw_down);
3749 spin_unlock_irqrestore(&ppd->sdma_lock, flags);
3750 }
3751 }
3752
3753 if (symadj) {
3754 if (ppd->cpspec->ibdeltainprog) {
3755 ppd->cpspec->ibdeltainprog = 0;
3756 ppd->cpspec->ibsymdelta += read_7220_creg32(ppd->dd,
3757 cr_ibsymbolerr) - ppd->cpspec->ibsymsnap;
3758 ppd->cpspec->iblnkerrdelta += read_7220_creg32(ppd->dd,
3759 cr_iblinkerrrecov) - ppd->cpspec->iblnkerrsnap;
3760 }
3761 } else if (!ibup && qib_compat_ddr_negotiate &&
3762 !ppd->cpspec->ibdeltainprog &&
3763 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
3764 ppd->cpspec->ibdeltainprog = 1;
3765 ppd->cpspec->ibsymsnap = read_7220_creg32(ppd->dd,
3766 cr_ibsymbolerr);
3767 ppd->cpspec->iblnkerrsnap = read_7220_creg32(ppd->dd,
3768 cr_iblinkerrrecov);
3769 }
3770
3771 if (!ret)
3772 qib_setup_7220_setextled(ppd, ibup);
3773 return ret;
3774}
3775
3776/*
3777 * Does read/modify/write to appropriate registers to
3778 * set output and direction bits selected by mask.
3779 * these are in their canonical postions (e.g. lsb of
3780 * dir will end up in D48 of extctrl on existing chips).
3781 * returns contents of GP Inputs.
3782 */
3783static int gpio_7220_mod(struct qib_devdata *dd, u32 out, u32 dir, u32 mask)
3784{
3785 u64 read_val, new_out;
3786 unsigned long flags;
3787
3788 if (mask) {
3789 /* some bits being written, lock access to GPIO */
3790 dir &= mask;
3791 out &= mask;
3792 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
3793 dd->cspec->extctrl &= ~((u64)mask << SYM_LSB(EXTCtrl, GPIOOe));
3794 dd->cspec->extctrl |= ((u64) dir << SYM_LSB(EXTCtrl, GPIOOe));
3795 new_out = (dd->cspec->gpio_out & ~mask) | out;
3796
3797 qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
3798 qib_write_kreg(dd, kr_gpio_out, new_out);
3799 dd->cspec->gpio_out = new_out;
3800 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
3801 }
3802 /*
3803 * It is unlikely that a read at this time would get valid
3804 * data on a pin whose direction line was set in the same
3805 * call to this function. We include the read here because
3806 * that allows us to potentially combine a change on one pin with
3807 * a read on another, and because the old code did something like
3808 * this.
3809 */
3810 read_val = qib_read_kreg64(dd, kr_extstatus);
3811 return SYM_FIELD(read_val, EXTStatus, GPIOIn);
3812}
3813
3814/*
3815 * Read fundamental info we need to use the chip. These are
3816 * the registers that describe chip capabilities, and are
3817 * saved in shadow registers.
3818 */
3819static void get_7220_chip_params(struct qib_devdata *dd)
3820{
3821 u64 val;
3822 u32 piobufs;
3823 int mtu;
3824
3825 dd->uregbase = qib_read_kreg32(dd, kr_userregbase);
3826
3827 dd->rcvtidcnt = qib_read_kreg32(dd, kr_rcvtidcnt);
3828 dd->rcvtidbase = qib_read_kreg32(dd, kr_rcvtidbase);
3829 dd->rcvegrbase = qib_read_kreg32(dd, kr_rcvegrbase);
3830 dd->palign = qib_read_kreg32(dd, kr_palign);
3831 dd->piobufbase = qib_read_kreg64(dd, kr_sendpiobufbase);
3832 dd->pio2k_bufbase = dd->piobufbase & 0xffffffff;
3833
3834 val = qib_read_kreg64(dd, kr_sendpiosize);
3835 dd->piosize2k = val & ~0U;
3836 dd->piosize4k = val >> 32;
3837
3838 mtu = ib_mtu_enum_to_int(qib_ibmtu);
3839 if (mtu == -1)
3840 mtu = QIB_DEFAULT_MTU;
3841 dd->pport->ibmtu = (u32)mtu;
3842
3843 val = qib_read_kreg64(dd, kr_sendpiobufcnt);
3844 dd->piobcnt2k = val & ~0U;
3845 dd->piobcnt4k = val >> 32;
3846 /* these may be adjusted in init_chip_wc_pat() */
3847 dd->pio2kbase = (u32 __iomem *)
3848 ((char __iomem *) dd->kregbase + dd->pio2k_bufbase);
3849 if (dd->piobcnt4k) {
3850 dd->pio4kbase = (u32 __iomem *)
3851 ((char __iomem *) dd->kregbase +
3852 (dd->piobufbase >> 32));
3853 /*
3854 * 4K buffers take 2 pages; we use roundup just to be
3855 * paranoid; we calculate it once here, rather than on
3856 * ever buf allocate
3857 */
3858 dd->align4k = ALIGN(dd->piosize4k, dd->palign);
3859 }
3860
3861 piobufs = dd->piobcnt4k + dd->piobcnt2k;
3862
3863 dd->pioavregs = ALIGN(piobufs, sizeof(u64) * BITS_PER_BYTE / 2) /
3864 (sizeof(u64) * BITS_PER_BYTE / 2);
3865}
3866
3867/*
3868 * The chip base addresses in cspec and cpspec have to be set
3869 * after possible init_chip_wc_pat(), rather than in
3870 * qib_get_7220_chip_params(), so split out as separate function
3871 */
3872static void set_7220_baseaddrs(struct qib_devdata *dd)
3873{
3874 u32 cregbase;
3875 /* init after possible re-map in init_chip_wc_pat() */
3876 cregbase = qib_read_kreg32(dd, kr_counterregbase);
3877 dd->cspec->cregbase = (u64 __iomem *)
3878 ((char __iomem *) dd->kregbase + cregbase);
3879
3880 dd->egrtidbase = (u64 __iomem *)
3881 ((char __iomem *) dd->kregbase + dd->rcvegrbase);
3882}
3883
3884
3885#define SENDCTRL_SHADOWED (SYM_MASK(SendCtrl, SendIntBufAvail) | \
3886 SYM_MASK(SendCtrl, SPioEnable) | \
3887 SYM_MASK(SendCtrl, SSpecialTriggerEn) | \
3888 SYM_MASK(SendCtrl, SendBufAvailUpd) | \
3889 SYM_MASK(SendCtrl, AvailUpdThld) | \
3890 SYM_MASK(SendCtrl, SDmaEnable) | \
3891 SYM_MASK(SendCtrl, SDmaIntEnable) | \
3892 SYM_MASK(SendCtrl, SDmaHalt) | \
3893 SYM_MASK(SendCtrl, SDmaSingleDescriptor))
3894
3895static int sendctrl_hook(struct qib_devdata *dd,
3896 const struct diag_observer *op,
3897 u32 offs, u64 *data, u64 mask, int only_32)
3898{
3899 unsigned long flags;
3900 unsigned idx = offs / sizeof(u64);
3901 u64 local_data, all_bits;
3902
3903 if (idx != kr_sendctrl) {
3904 qib_dev_err(dd, "SendCtrl Hook called with offs %X, %s-bit\n",
3905 offs, only_32 ? "32" : "64");
3906 return 0;
3907 }
3908
3909 all_bits = ~0ULL;
3910 if (only_32)
3911 all_bits >>= 32;
3912 spin_lock_irqsave(&dd->sendctrl_lock, flags);
3913 if ((mask & all_bits) != all_bits) {
3914 /*
3915 * At least some mask bits are zero, so we need
3916 * to read. The judgement call is whether from
3917 * reg or shadow. First-cut: read reg, and complain
3918 * if any bits which should be shadowed are different
3919 * from their shadowed value.
3920 */
3921 if (only_32)
3922 local_data = (u64)qib_read_kreg32(dd, idx);
3923 else
3924 local_data = qib_read_kreg64(dd, idx);
3925 qib_dev_err(dd, "Sendctrl -> %X, Shad -> %X\n",
3926 (u32)local_data, (u32)dd->sendctrl);
3927 if ((local_data & SENDCTRL_SHADOWED) !=
3928 (dd->sendctrl & SENDCTRL_SHADOWED))
3929 qib_dev_err(dd, "Sendctrl read: %X shadow is %X\n",
3930 (u32)local_data, (u32) dd->sendctrl);
3931 *data = (local_data & ~mask) | (*data & mask);
3932 }
3933 if (mask) {
3934 /*
3935 * At least some mask bits are one, so we need
3936 * to write, but only shadow some bits.
3937 */
3938 u64 sval, tval; /* Shadowed, transient */
3939
3940 /*
3941 * New shadow val is bits we don't want to touch,
3942 * ORed with bits we do, that are intended for shadow.
3943 */
3944 sval = (dd->sendctrl & ~mask);
3945 sval |= *data & SENDCTRL_SHADOWED & mask;
3946 dd->sendctrl = sval;
3947 tval = sval | (*data & ~SENDCTRL_SHADOWED & mask);
3948 qib_dev_err(dd, "Sendctrl <- %X, Shad <- %X\n",
3949 (u32)tval, (u32)sval);
3950 qib_write_kreg(dd, kr_sendctrl, tval);
3951 qib_write_kreg(dd, kr_scratch, 0Ull);
3952 }
3953 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
3954
3955 return only_32 ? 4 : 8;
3956}
3957
3958static const struct diag_observer sendctrl_observer = {
3959 sendctrl_hook, kr_sendctrl * sizeof(u64),
3960 kr_sendctrl * sizeof(u64)
3961};
3962
3963/*
3964 * write the final few registers that depend on some of the
3965 * init setup. Done late in init, just before bringing up
3966 * the serdes.
3967 */
3968static int qib_late_7220_initreg(struct qib_devdata *dd)
3969{
3970 int ret = 0;
3971 u64 val;
3972
3973 qib_write_kreg(dd, kr_rcvhdrentsize, dd->rcvhdrentsize);
3974 qib_write_kreg(dd, kr_rcvhdrsize, dd->rcvhdrsize);
3975 qib_write_kreg(dd, kr_rcvhdrcnt, dd->rcvhdrcnt);
3976 qib_write_kreg(dd, kr_sendpioavailaddr, dd->pioavailregs_phys);
3977 val = qib_read_kreg64(dd, kr_sendpioavailaddr);
3978 if (val != dd->pioavailregs_phys) {
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00003979 qib_dev_err(dd,
3980 "Catastrophic software error, SendPIOAvailAddr written as %lx, read back as %llx\n",
3981 (unsigned long) dd->pioavailregs_phys,
3982 (unsigned long long) val);
Ralph Campbellf9315512010-05-23 21:44:54 -07003983 ret = -EINVAL;
3984 }
3985 qib_register_observer(dd, &sendctrl_observer);
3986 return ret;
3987}
3988
3989static int qib_init_7220_variables(struct qib_devdata *dd)
3990{
3991 struct qib_chippport_specific *cpspec;
3992 struct qib_pportdata *ppd;
3993 int ret = 0;
3994 u32 sbufs, updthresh;
3995
3996 cpspec = (struct qib_chippport_specific *)(dd + 1);
3997 ppd = &cpspec->pportdata;
3998 dd->pport = ppd;
3999 dd->num_pports = 1;
4000
4001 dd->cspec = (struct qib_chip_specific *)(cpspec + dd->num_pports);
Kees Cook4037c922017-10-04 17:45:35 -07004002 dd->cspec->dd = dd;
Ralph Campbellf9315512010-05-23 21:44:54 -07004003 ppd->cpspec = cpspec;
4004
4005 spin_lock_init(&dd->cspec->sdepb_lock);
4006 spin_lock_init(&dd->cspec->rcvmod_lock);
4007 spin_lock_init(&dd->cspec->gpio_lock);
4008
4009 /* we haven't yet set QIB_PRESENT, so use read directly */
4010 dd->revision = readq(&dd->kregbase[kr_revision]);
4011
4012 if ((dd->revision & 0xffffffffU) == 0xffffffffU) {
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00004013 qib_dev_err(dd,
4014 "Revision register read failure, giving up initialization\n");
Ralph Campbellf9315512010-05-23 21:44:54 -07004015 ret = -ENODEV;
4016 goto bail;
4017 }
4018 dd->flags |= QIB_PRESENT; /* now register routines work */
4019
4020 dd->majrev = (u8) SYM_FIELD(dd->revision, Revision_R,
4021 ChipRevMajor);
4022 dd->minrev = (u8) SYM_FIELD(dd->revision, Revision_R,
4023 ChipRevMinor);
4024
4025 get_7220_chip_params(dd);
4026 qib_7220_boardname(dd);
4027
4028 /*
4029 * GPIO bits for TWSI data and clock,
4030 * used for serial EEPROM.
4031 */
4032 dd->gpio_sda_num = _QIB_GPIO_SDA_NUM;
4033 dd->gpio_scl_num = _QIB_GPIO_SCL_NUM;
4034 dd->twsi_eeprom_dev = QIB_TWSI_EEPROM_DEV;
4035
4036 dd->flags |= QIB_HAS_INTX | QIB_HAS_LINK_LATENCY |
4037 QIB_NODMA_RTAIL | QIB_HAS_THRESH_UPDATE;
4038 dd->flags |= qib_special_trigger ?
4039 QIB_USE_SPCL_TRIG : QIB_HAS_SEND_DMA;
4040
4041 /*
4042 * EEPROM error log 0 is TXE Parity errors. 1 is RXE Parity.
4043 * 2 is Some Misc, 3 is reserved for future.
4044 */
4045 dd->eep_st_masks[0].hwerrs_to_log = HWE_MASK(TXEMemParityErr);
4046
4047 dd->eep_st_masks[1].hwerrs_to_log = HWE_MASK(RXEMemParityErr);
4048
4049 dd->eep_st_masks[2].errs_to_log = ERR_MASK(ResetNegated);
4050
4051 init_waitqueue_head(&cpspec->autoneg_wait);
4052 INIT_DELAYED_WORK(&cpspec->autoneg_work, autoneg_7220_work);
4053
Mike Marciniszyn7d7632a2014-03-07 08:40:55 -05004054 ret = qib_init_pportdata(ppd, dd, 0, 1);
4055 if (ret)
4056 goto bail;
Ralph Campbellf9315512010-05-23 21:44:54 -07004057 ppd->link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
4058 ppd->link_speed_supported = QIB_IB_SDR | QIB_IB_DDR;
4059
4060 ppd->link_width_enabled = ppd->link_width_supported;
4061 ppd->link_speed_enabled = ppd->link_speed_supported;
4062 /*
4063 * Set the initial values to reasonable default, will be set
4064 * for real when link is up.
4065 */
4066 ppd->link_width_active = IB_WIDTH_4X;
4067 ppd->link_speed_active = QIB_IB_SDR;
4068 ppd->delay_mult = rate_to_delay[0][1];
4069 ppd->vls_supported = IB_VL_VL0;
4070 ppd->vls_operational = ppd->vls_supported;
4071
4072 if (!qib_mini_init)
4073 qib_write_kreg(dd, kr_rcvbthqp, QIB_KD_QP);
4074
Kees Cook4037c922017-10-04 17:45:35 -07004075 timer_setup(&ppd->cpspec->chase_timer, reenable_7220_chase, 0);
Ralph Campbellf9315512010-05-23 21:44:54 -07004076
4077 qib_num_cfg_vls = 1; /* if any 7220's, only one VL */
4078
4079 dd->rcvhdrentsize = QIB_RCVHDR_ENTSIZE;
4080 dd->rcvhdrsize = QIB_DFLT_RCVHDRSIZE;
4081 dd->rhf_offset =
4082 dd->rcvhdrentsize - sizeof(u64) / sizeof(u32);
4083
4084 /* we always allocate at least 2048 bytes for eager buffers */
4085 ret = ib_mtu_enum_to_int(qib_ibmtu);
4086 dd->rcvegrbufsize = ret != -1 ? max(ret, 2048) : QIB_DEFAULT_MTU;
Mike Marciniszyn9e1c0e42011-09-23 13:16:39 -04004087 BUG_ON(!is_power_of_2(dd->rcvegrbufsize));
4088 dd->rcvegrbufsize_shift = ilog2(dd->rcvegrbufsize);
Ralph Campbellf9315512010-05-23 21:44:54 -07004089
4090 qib_7220_tidtemplate(dd);
4091
4092 /*
4093 * We can request a receive interrupt for 1 or
4094 * more packets from current offset. For now, we set this
4095 * up for a single packet.
4096 */
4097 dd->rhdrhead_intr_off = 1ULL << 32;
4098
4099 /* setup the stats timer; the add_timer is done at end of init */
Kees Cook4037c922017-10-04 17:45:35 -07004100 timer_setup(&dd->stats_timer, qib_get_7220_faststats, 0);
Ralph Campbellf9315512010-05-23 21:44:54 -07004101 dd->stats_timer.expires = jiffies + ACTIVITY_TIMER * HZ;
4102
4103 /*
4104 * Control[4] has been added to change the arbitration within
4105 * the SDMA engine between favoring data fetches over descriptor
4106 * fetches. qib_sdma_fetch_arb==0 gives data fetches priority.
4107 */
4108 if (qib_sdma_fetch_arb)
4109 dd->control |= 1 << 4;
4110
4111 dd->ureg_align = 0x10000; /* 64KB alignment */
4112
4113 dd->piosize2kmax_dwords = (dd->piosize2k >> 2)-1;
4114 qib_7220_config_ctxts(dd);
4115 qib_set_ctxtcnt(dd); /* needed for PAT setup */
4116
Luis R. Rodriguezd4988622015-04-22 11:38:24 -07004117 ret = init_chip_wc_pat(dd, 0);
4118 if (ret)
4119 goto bail;
Ralph Campbellf9315512010-05-23 21:44:54 -07004120 set_7220_baseaddrs(dd); /* set chip access pointers now */
4121
4122 ret = 0;
4123 if (qib_mini_init)
4124 goto bail;
4125
4126 ret = qib_create_ctxts(dd);
4127 init_7220_cntrnames(dd);
4128
4129 /* use all of 4KB buffers for the kernel SDMA, zero if !SDMA.
4130 * reserve the update threshold amount for other kernel use, such
4131 * as sending SMI, MAD, and ACKs, or 3, whichever is greater,
4132 * unless we aren't enabling SDMA, in which case we want to use
4133 * all the 4k bufs for the kernel.
4134 * if this was less than the update threshold, we could wait
4135 * a long time for an update. Coded this way because we
4136 * sometimes change the update threshold for various reasons,
4137 * and we want this to remain robust.
4138 */
4139 updthresh = 8U; /* update threshold */
4140 if (dd->flags & QIB_HAS_SEND_DMA) {
4141 dd->cspec->sdmabufcnt = dd->piobcnt4k;
4142 sbufs = updthresh > 3 ? updthresh : 3;
4143 } else {
4144 dd->cspec->sdmabufcnt = 0;
4145 sbufs = dd->piobcnt4k;
4146 }
4147
4148 dd->cspec->lastbuf_for_pio = dd->piobcnt2k + dd->piobcnt4k -
4149 dd->cspec->sdmabufcnt;
4150 dd->lastctxt_piobuf = dd->cspec->lastbuf_for_pio - sbufs;
4151 dd->cspec->lastbuf_for_pio--; /* range is <= , not < */
Mike Marciniszynbb77a072012-05-07 14:02:42 -04004152 dd->last_pio = dd->cspec->lastbuf_for_pio;
Ralph Campbellf9315512010-05-23 21:44:54 -07004153 dd->pbufsctxt = dd->lastctxt_piobuf /
4154 (dd->cfgctxts - dd->first_user_ctxt);
4155
4156 /*
4157 * if we are at 16 user contexts, we will have one 7 sbufs
4158 * per context, so drop the update threshold to match. We
4159 * want to update before we actually run out, at low pbufs/ctxt
4160 * so give ourselves some margin
4161 */
4162 if ((dd->pbufsctxt - 2) < updthresh)
4163 updthresh = dd->pbufsctxt - 2;
4164
4165 dd->cspec->updthresh_dflt = updthresh;
4166 dd->cspec->updthresh = updthresh;
4167
4168 /* before full enable, no interrupts, no locking needed */
4169 dd->sendctrl |= (updthresh & SYM_RMASK(SendCtrl, AvailUpdThld))
4170 << SYM_LSB(SendCtrl, AvailUpdThld);
4171
4172 dd->psxmitwait_supported = 1;
4173 dd->psxmitwait_check_rate = QIB_7220_PSXMITWAIT_CHECK_RATE;
4174bail:
4175 return ret;
4176}
4177
4178static u32 __iomem *qib_7220_getsendbuf(struct qib_pportdata *ppd, u64 pbc,
4179 u32 *pbufnum)
4180{
4181 u32 first, last, plen = pbc & QIB_PBC_LENGTH_MASK;
4182 struct qib_devdata *dd = ppd->dd;
4183 u32 __iomem *buf;
4184
4185 if (((pbc >> 32) & PBC_7220_VL15_SEND_CTRL) &&
4186 !(ppd->lflags & (QIBL_IB_AUTONEG_INPROG | QIBL_LINKACTIVE)))
4187 buf = get_7220_link_buf(ppd, pbufnum);
4188 else {
4189 if ((plen + 1) > dd->piosize2kmax_dwords)
4190 first = dd->piobcnt2k;
4191 else
4192 first = 0;
4193 /* try 4k if all 2k busy, so same last for both sizes */
4194 last = dd->cspec->lastbuf_for_pio;
4195 buf = qib_getsendbuf_range(dd, pbufnum, first, last);
4196 }
4197 return buf;
4198}
4199
4200/* these 2 "counters" are really control registers, and are always RW */
4201static void qib_set_cntr_7220_sample(struct qib_pportdata *ppd, u32 intv,
4202 u32 start)
4203{
4204 write_7220_creg(ppd->dd, cr_psinterval, intv);
4205 write_7220_creg(ppd->dd, cr_psstart, start);
4206}
4207
4208/*
4209 * NOTE: no real attempt is made to generalize the SDMA stuff.
4210 * At some point "soon" we will have a new more generalized
4211 * set of sdma interface, and then we'll clean this up.
4212 */
4213
4214/* Must be called with sdma_lock held, or before init finished */
4215static void qib_sdma_update_7220_tail(struct qib_pportdata *ppd, u16 tail)
4216{
4217 /* Commit writes to memory and advance the tail on the chip */
4218 wmb();
4219 ppd->sdma_descq_tail = tail;
4220 qib_write_kreg(ppd->dd, kr_senddmatail, tail);
4221}
4222
4223static void qib_sdma_set_7220_desc_cnt(struct qib_pportdata *ppd, unsigned cnt)
4224{
4225}
4226
4227static struct sdma_set_state_action sdma_7220_action_table[] = {
4228 [qib_sdma_state_s00_hw_down] = {
4229 .op_enable = 0,
4230 .op_intenable = 0,
4231 .op_halt = 0,
4232 .go_s99_running_tofalse = 1,
4233 },
4234 [qib_sdma_state_s10_hw_start_up_wait] = {
4235 .op_enable = 1,
4236 .op_intenable = 1,
4237 .op_halt = 1,
4238 },
4239 [qib_sdma_state_s20_idle] = {
4240 .op_enable = 1,
4241 .op_intenable = 1,
4242 .op_halt = 1,
4243 },
4244 [qib_sdma_state_s30_sw_clean_up_wait] = {
4245 .op_enable = 0,
4246 .op_intenable = 1,
4247 .op_halt = 0,
4248 },
4249 [qib_sdma_state_s40_hw_clean_up_wait] = {
4250 .op_enable = 1,
4251 .op_intenable = 1,
4252 .op_halt = 1,
4253 },
4254 [qib_sdma_state_s50_hw_halt_wait] = {
4255 .op_enable = 1,
4256 .op_intenable = 1,
4257 .op_halt = 1,
4258 },
4259 [qib_sdma_state_s99_running] = {
4260 .op_enable = 1,
4261 .op_intenable = 1,
4262 .op_halt = 0,
4263 .go_s99_running_totrue = 1,
4264 },
4265};
4266
4267static void qib_7220_sdma_init_early(struct qib_pportdata *ppd)
4268{
4269 ppd->sdma_state.set_state_action = sdma_7220_action_table;
4270}
4271
4272static int init_sdma_7220_regs(struct qib_pportdata *ppd)
4273{
4274 struct qib_devdata *dd = ppd->dd;
4275 unsigned i, n;
4276 u64 senddmabufmask[3] = { 0 };
4277
4278 /* Set SendDmaBase */
4279 qib_write_kreg(dd, kr_senddmabase, ppd->sdma_descq_phys);
4280 qib_sdma_7220_setlengen(ppd);
4281 qib_sdma_update_7220_tail(ppd, 0); /* Set SendDmaTail */
4282 /* Set SendDmaHeadAddr */
4283 qib_write_kreg(dd, kr_senddmaheadaddr, ppd->sdma_head_phys);
4284
4285 /*
4286 * Reserve all the former "kernel" piobufs, using high number range
4287 * so we get as many 4K buffers as possible
4288 */
4289 n = dd->piobcnt2k + dd->piobcnt4k;
4290 i = n - dd->cspec->sdmabufcnt;
4291
4292 for (; i < n; ++i) {
4293 unsigned word = i / 64;
4294 unsigned bit = i & 63;
4295
4296 BUG_ON(word >= 3);
4297 senddmabufmask[word] |= 1ULL << bit;
4298 }
4299 qib_write_kreg(dd, kr_senddmabufmask0, senddmabufmask[0]);
4300 qib_write_kreg(dd, kr_senddmabufmask1, senddmabufmask[1]);
4301 qib_write_kreg(dd, kr_senddmabufmask2, senddmabufmask[2]);
4302
4303 ppd->sdma_state.first_sendbuf = i;
4304 ppd->sdma_state.last_sendbuf = n;
4305
4306 return 0;
4307}
4308
4309/* sdma_lock must be held */
4310static u16 qib_sdma_7220_gethead(struct qib_pportdata *ppd)
4311{
4312 struct qib_devdata *dd = ppd->dd;
4313 int sane;
4314 int use_dmahead;
4315 u16 swhead;
4316 u16 swtail;
4317 u16 cnt;
4318 u16 hwhead;
4319
4320 use_dmahead = __qib_sdma_running(ppd) &&
4321 (dd->flags & QIB_HAS_SDMA_TIMEOUT);
4322retry:
4323 hwhead = use_dmahead ?
4324 (u16)le64_to_cpu(*ppd->sdma_head_dma) :
4325 (u16)qib_read_kreg32(dd, kr_senddmahead);
4326
4327 swhead = ppd->sdma_descq_head;
4328 swtail = ppd->sdma_descq_tail;
4329 cnt = ppd->sdma_descq_cnt;
4330
4331 if (swhead < swtail) {
4332 /* not wrapped */
4333 sane = (hwhead >= swhead) & (hwhead <= swtail);
4334 } else if (swhead > swtail) {
4335 /* wrapped around */
4336 sane = ((hwhead >= swhead) && (hwhead < cnt)) ||
4337 (hwhead <= swtail);
4338 } else {
4339 /* empty */
4340 sane = (hwhead == swhead);
4341 }
4342
4343 if (unlikely(!sane)) {
4344 if (use_dmahead) {
4345 /* try one more time, directly from the register */
4346 use_dmahead = 0;
4347 goto retry;
4348 }
4349 /* assume no progress */
4350 hwhead = swhead;
4351 }
4352
4353 return hwhead;
4354}
4355
4356static int qib_sdma_7220_busy(struct qib_pportdata *ppd)
4357{
4358 u64 hwstatus = qib_read_kreg64(ppd->dd, kr_senddmastatus);
4359
4360 return (hwstatus & SYM_MASK(SendDmaStatus, ScoreBoardDrainInProg)) ||
4361 (hwstatus & SYM_MASK(SendDmaStatus, AbortInProg)) ||
4362 (hwstatus & SYM_MASK(SendDmaStatus, InternalSDmaEnable)) ||
4363 !(hwstatus & SYM_MASK(SendDmaStatus, ScbEmpty));
4364}
4365
4366/*
4367 * Compute the amount of delay before sending the next packet if the
4368 * port's send rate differs from the static rate set for the QP.
4369 * Since the delay affects this packet but the amount of the delay is
4370 * based on the length of the previous packet, use the last delay computed
4371 * and save the delay count for this packet to be used next time
4372 * we get here.
4373 */
4374static u32 qib_7220_setpbc_control(struct qib_pportdata *ppd, u32 plen,
4375 u8 srate, u8 vl)
4376{
4377 u8 snd_mult = ppd->delay_mult;
4378 u8 rcv_mult = ib_rate_to_delay[srate];
4379 u32 ret = ppd->cpspec->last_delay_mult;
4380
4381 ppd->cpspec->last_delay_mult = (rcv_mult > snd_mult) ?
4382 (plen * (rcv_mult - snd_mult) + 1) >> 1 : 0;
4383
4384 /* Indicate VL15, if necessary */
4385 if (vl == 15)
4386 ret |= PBC_7220_VL15_SEND_CTRL;
4387 return ret;
4388}
4389
4390static void qib_7220_initvl15_bufs(struct qib_devdata *dd)
4391{
4392}
4393
4394static void qib_7220_init_ctxt(struct qib_ctxtdata *rcd)
4395{
4396 if (!rcd->ctxt) {
4397 rcd->rcvegrcnt = IBA7220_KRCVEGRCNT;
4398 rcd->rcvegr_tid_base = 0;
4399 } else {
4400 rcd->rcvegrcnt = rcd->dd->cspec->rcvegrcnt;
4401 rcd->rcvegr_tid_base = IBA7220_KRCVEGRCNT +
4402 (rcd->ctxt - 1) * rcd->rcvegrcnt;
4403 }
4404}
4405
4406static void qib_7220_txchk_change(struct qib_devdata *dd, u32 start,
4407 u32 len, u32 which, struct qib_ctxtdata *rcd)
4408{
4409 int i;
4410 unsigned long flags;
4411
4412 switch (which) {
4413 case TXCHK_CHG_TYPE_KERN:
4414 /* see if we need to raise avail update threshold */
4415 spin_lock_irqsave(&dd->uctxt_lock, flags);
4416 for (i = dd->first_user_ctxt;
4417 dd->cspec->updthresh != dd->cspec->updthresh_dflt
4418 && i < dd->cfgctxts; i++)
4419 if (dd->rcd[i] && dd->rcd[i]->subctxt_cnt &&
4420 ((dd->rcd[i]->piocnt / dd->rcd[i]->subctxt_cnt) - 1)
4421 < dd->cspec->updthresh_dflt)
4422 break;
4423 spin_unlock_irqrestore(&dd->uctxt_lock, flags);
4424 if (i == dd->cfgctxts) {
4425 spin_lock_irqsave(&dd->sendctrl_lock, flags);
4426 dd->cspec->updthresh = dd->cspec->updthresh_dflt;
4427 dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
4428 dd->sendctrl |= (dd->cspec->updthresh &
4429 SYM_RMASK(SendCtrl, AvailUpdThld)) <<
4430 SYM_LSB(SendCtrl, AvailUpdThld);
4431 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
4432 sendctrl_7220_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
4433 }
4434 break;
4435 case TXCHK_CHG_TYPE_USER:
4436 spin_lock_irqsave(&dd->sendctrl_lock, flags);
4437 if (rcd && rcd->subctxt_cnt && ((rcd->piocnt
4438 / rcd->subctxt_cnt) - 1) < dd->cspec->updthresh) {
4439 dd->cspec->updthresh = (rcd->piocnt /
4440 rcd->subctxt_cnt) - 1;
4441 dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
4442 dd->sendctrl |= (dd->cspec->updthresh &
4443 SYM_RMASK(SendCtrl, AvailUpdThld))
4444 << SYM_LSB(SendCtrl, AvailUpdThld);
4445 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
4446 sendctrl_7220_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
4447 } else
4448 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
4449 break;
4450 }
4451}
4452
4453static void writescratch(struct qib_devdata *dd, u32 val)
4454{
4455 qib_write_kreg(dd, kr_scratch, val);
4456}
4457
4458#define VALID_TS_RD_REG_MASK 0xBF
4459/**
4460 * qib_7220_tempsense_read - read register of temp sensor via TWSI
4461 * @dd: the qlogic_ib device
4462 * @regnum: register to read from
4463 *
4464 * returns reg contents (0..255) or < 0 for error
4465 */
4466static int qib_7220_tempsense_rd(struct qib_devdata *dd, int regnum)
4467{
4468 int ret;
4469 u8 rdata;
4470
4471 if (regnum > 7) {
4472 ret = -EINVAL;
4473 goto bail;
4474 }
4475
4476 /* return a bogus value for (the one) register we do not have */
4477 if (!((1 << regnum) & VALID_TS_RD_REG_MASK)) {
4478 ret = 0;
4479 goto bail;
4480 }
4481
4482 ret = mutex_lock_interruptible(&dd->eep_lock);
4483 if (ret)
4484 goto bail;
4485
4486 ret = qib_twsi_blk_rd(dd, QIB_TWSI_TEMP_DEV, regnum, &rdata, 1);
4487 if (!ret)
4488 ret = rdata;
4489
4490 mutex_unlock(&dd->eep_lock);
4491
4492 /*
4493 * There are three possibilities here:
4494 * ret is actual value (0..255)
4495 * ret is -ENXIO or -EINVAL from twsi code or this file
4496 * ret is -EINTR from mutex_lock_interruptible.
4497 */
4498bail:
4499 return ret;
4500}
4501
Mike Marciniszyn8469ba32013-05-30 18:25:25 -04004502#ifdef CONFIG_INFINIBAND_QIB_DCA
4503static int qib_7220_notify_dca(struct qib_devdata *dd, unsigned long event)
4504{
4505 return 0;
4506}
4507#endif
4508
Ralph Campbellf9315512010-05-23 21:44:54 -07004509/* Dummy function, as 7220 boards never disable EEPROM Write */
4510static int qib_7220_eeprom_wen(struct qib_devdata *dd, int wen)
4511{
4512 return 1;
4513}
4514
4515/**
4516 * qib_init_iba7220_funcs - set up the chip-specific function pointers
4517 * @dev: the pci_dev for qlogic_ib device
4518 * @ent: pci_device_id struct for this dev
4519 *
4520 * This is global, and is called directly at init to set up the
4521 * chip-specific function pointers for later use.
4522 */
4523struct qib_devdata *qib_init_iba7220_funcs(struct pci_dev *pdev,
4524 const struct pci_device_id *ent)
4525{
4526 struct qib_devdata *dd;
4527 int ret;
4528 u32 boardid, minwidth;
4529
4530 dd = qib_alloc_devdata(pdev, sizeof(struct qib_chip_specific) +
4531 sizeof(struct qib_chippport_specific));
4532 if (IS_ERR(dd))
4533 goto bail;
4534
4535 dd->f_bringup_serdes = qib_7220_bringup_serdes;
4536 dd->f_cleanup = qib_setup_7220_cleanup;
4537 dd->f_clear_tids = qib_7220_clear_tids;
4538 dd->f_free_irq = qib_7220_free_irq;
4539 dd->f_get_base_info = qib_7220_get_base_info;
4540 dd->f_get_msgheader = qib_7220_get_msgheader;
4541 dd->f_getsendbuf = qib_7220_getsendbuf;
4542 dd->f_gpio_mod = gpio_7220_mod;
4543 dd->f_eeprom_wen = qib_7220_eeprom_wen;
4544 dd->f_hdrqempty = qib_7220_hdrqempty;
4545 dd->f_ib_updown = qib_7220_ib_updown;
4546 dd->f_init_ctxt = qib_7220_init_ctxt;
4547 dd->f_initvl15_bufs = qib_7220_initvl15_bufs;
4548 dd->f_intr_fallback = qib_7220_intr_fallback;
4549 dd->f_late_initreg = qib_late_7220_initreg;
4550 dd->f_setpbc_control = qib_7220_setpbc_control;
4551 dd->f_portcntr = qib_portcntr_7220;
4552 dd->f_put_tid = qib_7220_put_tid;
4553 dd->f_quiet_serdes = qib_7220_quiet_serdes;
4554 dd->f_rcvctrl = rcvctrl_7220_mod;
4555 dd->f_read_cntrs = qib_read_7220cntrs;
4556 dd->f_read_portcntrs = qib_read_7220portcntrs;
4557 dd->f_reset = qib_setup_7220_reset;
4558 dd->f_init_sdma_regs = init_sdma_7220_regs;
4559 dd->f_sdma_busy = qib_sdma_7220_busy;
4560 dd->f_sdma_gethead = qib_sdma_7220_gethead;
4561 dd->f_sdma_sendctrl = qib_7220_sdma_sendctrl;
4562 dd->f_sdma_set_desc_cnt = qib_sdma_set_7220_desc_cnt;
4563 dd->f_sdma_update_tail = qib_sdma_update_7220_tail;
4564 dd->f_sdma_hw_clean_up = qib_7220_sdma_hw_clean_up;
4565 dd->f_sdma_hw_start_up = qib_7220_sdma_hw_start_up;
4566 dd->f_sdma_init_early = qib_7220_sdma_init_early;
4567 dd->f_sendctrl = sendctrl_7220_mod;
4568 dd->f_set_armlaunch = qib_set_7220_armlaunch;
4569 dd->f_set_cntr_sample = qib_set_cntr_7220_sample;
4570 dd->f_iblink_state = qib_7220_iblink_state;
4571 dd->f_ibphys_portstate = qib_7220_phys_portstate;
4572 dd->f_get_ib_cfg = qib_7220_get_ib_cfg;
4573 dd->f_set_ib_cfg = qib_7220_set_ib_cfg;
4574 dd->f_set_ib_loopback = qib_7220_set_loopback;
4575 dd->f_set_intr_state = qib_7220_set_intr_state;
4576 dd->f_setextled = qib_setup_7220_setextled;
4577 dd->f_txchk_change = qib_7220_txchk_change;
4578 dd->f_update_usrhead = qib_update_7220_usrhead;
4579 dd->f_wantpiobuf_intr = qib_wantpiobuf_7220_intr;
4580 dd->f_xgxs_reset = qib_7220_xgxs_reset;
4581 dd->f_writescratch = writescratch;
4582 dd->f_tempsense_rd = qib_7220_tempsense_rd;
Mike Marciniszyn8469ba32013-05-30 18:25:25 -04004583#ifdef CONFIG_INFINIBAND_QIB_DCA
4584 dd->f_notify_dca = qib_7220_notify_dca;
4585#endif
Ralph Campbellf9315512010-05-23 21:44:54 -07004586 /*
4587 * Do remaining pcie setup and save pcie values in dd.
4588 * Any error printing is already done by the init code.
4589 * On return, we have the chip mapped, but chip registers
4590 * are not set up until start of qib_init_7220_variables.
4591 */
4592 ret = qib_pcie_ddinit(dd, pdev, ent);
4593 if (ret < 0)
4594 goto bail_free;
4595
4596 /* initialize chip-specific variables */
4597 ret = qib_init_7220_variables(dd);
4598 if (ret)
4599 goto bail_cleanup;
4600
4601 if (qib_mini_init)
4602 goto bail;
4603
4604 boardid = SYM_FIELD(dd->revision, Revision,
4605 BoardID);
4606 switch (boardid) {
4607 case 0:
4608 case 2:
4609 case 10:
4610 case 12:
4611 minwidth = 16; /* x16 capable boards */
4612 break;
4613 default:
4614 minwidth = 8; /* x8 capable boards */
4615 break;
4616 }
Michael J. Ruhl581d01a2017-06-09 16:00:06 -07004617 if (qib_pcie_params(dd, minwidth, NULL))
Mike Marciniszyn7fac3302012-07-19 13:04:25 +00004618 qib_dev_err(dd,
4619 "Failed to setup PCIe or interrupts; continuing anyway\n");
Ralph Campbellf9315512010-05-23 21:44:54 -07004620
4621 /* save IRQ for possible later use */
4622 dd->cspec->irq = pdev->irq;
4623
4624 if (qib_read_kreg64(dd, kr_hwerrstatus) &
4625 QLOGIC_IB_HWE_SERDESPLLFAILED)
4626 qib_write_kreg(dd, kr_hwerrclear,
4627 QLOGIC_IB_HWE_SERDESPLLFAILED);
4628
4629 /* setup interrupt handler (interrupt type handled above) */
4630 qib_setup_7220_interrupt(dd);
4631 qib_7220_init_hwerrors(dd);
4632
4633 /* clear diagctrl register, in case diags were running and crashed */
4634 qib_write_kreg(dd, kr_hwdiagctrl, 0);
4635
4636 goto bail;
4637
4638bail_cleanup:
4639 qib_pcie_ddcleanup(dd);
4640bail_free:
4641 qib_free_devdata(dd);
4642 dd = ERR_PTR(ret);
4643bail:
4644 return dd;
4645}