1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40#include <linux/interrupt.h>
41#include <linux/pci.h>
42#include <linux/delay.h>
43#include <rdma/ib_verbs.h>
44
45#include "qib.h"
46#include "qib_6120_regs.h"
47
48static void qib_6120_setup_setextled(struct qib_pportdata *, u32);
49static void sendctrl_6120_mod(struct qib_pportdata *ppd, u32 op);
50static u8 qib_6120_phys_portstate(u64);
51static u32 qib_6120_iblink_state(u64);
52
53
54
55
56
57
58
59
60#define KREG_IDX(regname) (QIB_6120_##regname##_OFFS / sizeof(u64))
61
62
63#define kr_extctrl KREG_IDX(EXTCtrl)
64#define kr_extstatus KREG_IDX(EXTStatus)
65#define kr_gpio_clear KREG_IDX(GPIOClear)
66#define kr_gpio_mask KREG_IDX(GPIOMask)
67#define kr_gpio_out KREG_IDX(GPIOOut)
68#define kr_gpio_status KREG_IDX(GPIOStatus)
69#define kr_rcvctrl KREG_IDX(RcvCtrl)
70#define kr_sendctrl KREG_IDX(SendCtrl)
71#define kr_partitionkey KREG_IDX(RcvPartitionKey)
72#define kr_hwdiagctrl KREG_IDX(HwDiagCtrl)
73#define kr_ibcstatus KREG_IDX(IBCStatus)
74#define kr_ibcctrl KREG_IDX(IBCCtrl)
75#define kr_sendbuffererror KREG_IDX(SendBufErr0)
76#define kr_rcvbthqp KREG_IDX(RcvBTHQP)
77#define kr_counterregbase KREG_IDX(CntrRegBase)
78#define kr_palign KREG_IDX(PageAlign)
79#define kr_rcvegrbase KREG_IDX(RcvEgrBase)
80#define kr_rcvegrcnt KREG_IDX(RcvEgrCnt)
81#define kr_rcvhdrcnt KREG_IDX(RcvHdrCnt)
82#define kr_rcvhdrentsize KREG_IDX(RcvHdrEntSize)
83#define kr_rcvhdrsize KREG_IDX(RcvHdrSize)
84#define kr_rcvtidbase KREG_IDX(RcvTIDBase)
85#define kr_rcvtidcnt KREG_IDX(RcvTIDCnt)
86#define kr_scratch KREG_IDX(Scratch)
87#define kr_sendctrl KREG_IDX(SendCtrl)
88#define kr_sendpioavailaddr KREG_IDX(SendPIOAvailAddr)
89#define kr_sendpiobufbase KREG_IDX(SendPIOBufBase)
90#define kr_sendpiobufcnt KREG_IDX(SendPIOBufCnt)
91#define kr_sendpiosize KREG_IDX(SendPIOSize)
92#define kr_sendregbase KREG_IDX(SendRegBase)
93#define kr_userregbase KREG_IDX(UserRegBase)
94#define kr_control KREG_IDX(Control)
95#define kr_intclear KREG_IDX(IntClear)
96#define kr_intmask KREG_IDX(IntMask)
97#define kr_intstatus KREG_IDX(IntStatus)
98#define kr_errclear KREG_IDX(ErrClear)
99#define kr_errmask KREG_IDX(ErrMask)
100#define kr_errstatus KREG_IDX(ErrStatus)
101#define kr_hwerrclear KREG_IDX(HwErrClear)
102#define kr_hwerrmask KREG_IDX(HwErrMask)
103#define kr_hwerrstatus KREG_IDX(HwErrStatus)
104#define kr_revision KREG_IDX(Revision)
105#define kr_portcnt KREG_IDX(PortCnt)
106#define kr_serdes_cfg0 KREG_IDX(SerdesCfg0)
107#define kr_serdes_cfg1 (kr_serdes_cfg0 + 1)
108#define kr_serdes_stat KREG_IDX(SerdesStat)
109#define kr_xgxs_cfg KREG_IDX(XGXSCfg)
110
111
112#define kr_rcvhdraddr KREG_IDX(RcvHdrAddr0)
113#define kr_rcvhdrtailaddr KREG_IDX(RcvHdrTailAddr0)
114
115#define CREG_IDX(regname) ((QIB_6120_##regname##_OFFS - \
116 QIB_6120_LBIntCnt_OFFS) / sizeof(u64))
117
118#define cr_badformat CREG_IDX(RxBadFormatCnt)
119#define cr_erricrc CREG_IDX(RxICRCErrCnt)
120#define cr_errlink CREG_IDX(RxLinkProblemCnt)
121#define cr_errlpcrc CREG_IDX(RxLPCRCErrCnt)
122#define cr_errpkey CREG_IDX(RxPKeyMismatchCnt)
123#define cr_rcvflowctrl_err CREG_IDX(RxFlowCtrlErrCnt)
124#define cr_err_rlen CREG_IDX(RxLenErrCnt)
125#define cr_errslen CREG_IDX(TxLenErrCnt)
126#define cr_errtidfull CREG_IDX(RxTIDFullErrCnt)
127#define cr_errtidvalid CREG_IDX(RxTIDValidErrCnt)
128#define cr_errvcrc CREG_IDX(RxVCRCErrCnt)
129#define cr_ibstatuschange CREG_IDX(IBStatusChangeCnt)
130#define cr_lbint CREG_IDX(LBIntCnt)
131#define cr_invalidrlen CREG_IDX(RxMaxMinLenErrCnt)
132#define cr_invalidslen CREG_IDX(TxMaxMinLenErrCnt)
133#define cr_lbflowstall CREG_IDX(LBFlowStallCnt)
134#define cr_pktrcv CREG_IDX(RxDataPktCnt)
135#define cr_pktrcvflowctrl CREG_IDX(RxFlowPktCnt)
136#define cr_pktsend CREG_IDX(TxDataPktCnt)
137#define cr_pktsendflow CREG_IDX(TxFlowPktCnt)
138#define cr_portovfl CREG_IDX(RxP0HdrEgrOvflCnt)
139#define cr_rcvebp CREG_IDX(RxEBPCnt)
140#define cr_rcvovfl CREG_IDX(RxBufOvflCnt)
141#define cr_senddropped CREG_IDX(TxDroppedPktCnt)
142#define cr_sendstall CREG_IDX(TxFlowStallCnt)
143#define cr_sendunderrun CREG_IDX(TxUnderrunCnt)
144#define cr_wordrcv CREG_IDX(RxDwordCnt)
145#define cr_wordsend CREG_IDX(TxDwordCnt)
146#define cr_txunsupvl CREG_IDX(TxUnsupVLErrCnt)
147#define cr_rxdroppkt CREG_IDX(RxDroppedPktCnt)
148#define cr_iblinkerrrecov CREG_IDX(IBLinkErrRecoveryCnt)
149#define cr_iblinkdown CREG_IDX(IBLinkDownedCnt)
150#define cr_ibsymbolerr CREG_IDX(IBSymbolErrCnt)
151
152#define SYM_RMASK(regname, fldname) ((u64) \
153 QIB_6120_##regname##_##fldname##_RMASK)
154#define SYM_MASK(regname, fldname) ((u64) \
155 QIB_6120_##regname##_##fldname##_RMASK << \
156 QIB_6120_##regname##_##fldname##_LSB)
157#define SYM_LSB(regname, fldname) (QIB_6120_##regname##_##fldname##_LSB)
158
159#define SYM_FIELD(value, regname, fldname) ((u64) \
160 (((value) >> SYM_LSB(regname, fldname)) & \
161 SYM_RMASK(regname, fldname)))
162#define ERR_MASK(fldname) SYM_MASK(ErrMask, fldname##Mask)
163#define HWE_MASK(fldname) SYM_MASK(HwErrMask, fldname##Mask)
164
165
166#define IB_6120_LT_STATE_DISABLED 0x00
167#define IB_6120_LT_STATE_LINKUP 0x01
168#define IB_6120_LT_STATE_POLLACTIVE 0x02
169#define IB_6120_LT_STATE_POLLQUIET 0x03
170#define IB_6120_LT_STATE_SLEEPDELAY 0x04
171#define IB_6120_LT_STATE_SLEEPQUIET 0x05
172#define IB_6120_LT_STATE_CFGDEBOUNCE 0x08
173#define IB_6120_LT_STATE_CFGRCVFCFG 0x09
174#define IB_6120_LT_STATE_CFGWAITRMT 0x0a
175#define IB_6120_LT_STATE_CFGIDLE 0x0b
176#define IB_6120_LT_STATE_RECOVERRETRAIN 0x0c
177#define IB_6120_LT_STATE_RECOVERWAITRMT 0x0e
178#define IB_6120_LT_STATE_RECOVERIDLE 0x0f
179
180
181#define IB_6120_L_STATE_DOWN 0x0
182#define IB_6120_L_STATE_INIT 0x1
183#define IB_6120_L_STATE_ARM 0x2
184#define IB_6120_L_STATE_ACTIVE 0x3
185#define IB_6120_L_STATE_ACT_DEFER 0x4
186
187static const u8 qib_6120_physportstate[0x20] = {
188 [IB_6120_LT_STATE_DISABLED] = IB_PHYSPORTSTATE_DISABLED,
189 [IB_6120_LT_STATE_LINKUP] = IB_PHYSPORTSTATE_LINKUP,
190 [IB_6120_LT_STATE_POLLACTIVE] = IB_PHYSPORTSTATE_POLL,
191 [IB_6120_LT_STATE_POLLQUIET] = IB_PHYSPORTSTATE_POLL,
192 [IB_6120_LT_STATE_SLEEPDELAY] = IB_PHYSPORTSTATE_SLEEP,
193 [IB_6120_LT_STATE_SLEEPQUIET] = IB_PHYSPORTSTATE_SLEEP,
194 [IB_6120_LT_STATE_CFGDEBOUNCE] =
195 IB_PHYSPORTSTATE_CFG_TRAIN,
196 [IB_6120_LT_STATE_CFGRCVFCFG] =
197 IB_PHYSPORTSTATE_CFG_TRAIN,
198 [IB_6120_LT_STATE_CFGWAITRMT] =
199 IB_PHYSPORTSTATE_CFG_TRAIN,
200 [IB_6120_LT_STATE_CFGIDLE] = IB_PHYSPORTSTATE_CFG_TRAIN,
201 [IB_6120_LT_STATE_RECOVERRETRAIN] =
202 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
203 [IB_6120_LT_STATE_RECOVERWAITRMT] =
204 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
205 [IB_6120_LT_STATE_RECOVERIDLE] =
206 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
207 [0x10] = IB_PHYSPORTSTATE_CFG_TRAIN,
208 [0x11] = IB_PHYSPORTSTATE_CFG_TRAIN,
209 [0x12] = IB_PHYSPORTSTATE_CFG_TRAIN,
210 [0x13] = IB_PHYSPORTSTATE_CFG_TRAIN,
211 [0x14] = IB_PHYSPORTSTATE_CFG_TRAIN,
212 [0x15] = IB_PHYSPORTSTATE_CFG_TRAIN,
213 [0x16] = IB_PHYSPORTSTATE_CFG_TRAIN,
214 [0x17] = IB_PHYSPORTSTATE_CFG_TRAIN
215};
216
217
218struct qib_chip_specific {
219 u64 __iomem *cregbase;
220 u64 *cntrs;
221 u64 *portcntrs;
222 void *dummy_hdrq;
223 dma_addr_t dummy_hdrq_phys;
224 spinlock_t kernel_tid_lock;
225 spinlock_t user_tid_lock;
226 spinlock_t rcvmod_lock;
227 spinlock_t gpio_lock;
228 u64 hwerrmask;
229 u64 errormask;
230 u64 gpio_out;
231 u64 gpio_mask;
232 u64 extctrl;
233
234
235
236
237
238
239
240
241 u64 ibdeltainprog;
242 u64 ibsymdelta;
243 u64 ibsymsnap;
244 u64 iblnkerrdelta;
245 u64 iblnkerrsnap;
246 u64 ibcctrl;
247 u32 lastlinkrecov;
248 int irq;
249 u32 cntrnamelen;
250 u32 portcntrnamelen;
251 u32 ncntrs;
252 u32 nportcntrs;
253
254 u32 rxfc_unsupvl_errs;
255 u32 overrun_thresh_errs;
256
257
258
259
260 u32 lli_errs;
261 u32 lli_counter;
262 u64 lli_thresh;
263 u64 sword;
264 u64 rword;
265 u64 spkts;
266 u64 rpkts;
267 u64 xmit_wait;
268 struct timer_list pma_timer;
269 char emsgbuf[128];
270 char bitsmsgbuf[64];
271 u8 pma_sample_status;
272};
273
274
275#define QLOGIC_IB_IBCC_LINKINITCMD_DISABLE 1
276
277#define QLOGIC_IB_IBCC_LINKINITCMD_POLL 2
278
279#define QLOGIC_IB_IBCC_LINKINITCMD_SLEEP 3
280#define QLOGIC_IB_IBCC_LINKINITCMD_SHIFT 16
281
282#define QLOGIC_IB_IBCC_LINKCMD_DOWN 1
283#define QLOGIC_IB_IBCC_LINKCMD_ARMED 2
284#define QLOGIC_IB_IBCC_LINKCMD_ACTIVE 3
285#define QLOGIC_IB_IBCC_LINKCMD_SHIFT 18
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306static inline u32 qib_read_ureg32(const struct qib_devdata *dd,
307 enum qib_ureg regno, int ctxt)
308{
309 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
310 return 0;
311
312 if (dd->userbase)
313 return readl(regno + (u64 __iomem *)
314 ((char __iomem *)dd->userbase +
315 dd->ureg_align * ctxt));
316 else
317 return readl(regno + (u64 __iomem *)
318 (dd->uregbase +
319 (char __iomem *)dd->kregbase +
320 dd->ureg_align * ctxt));
321}
322
323
324
325
326
327
328
329
330
331
332static inline void qib_write_ureg(const struct qib_devdata *dd,
333 enum qib_ureg regno, u64 value, int ctxt)
334{
335 u64 __iomem *ubase;
336 if (dd->userbase)
337 ubase = (u64 __iomem *)
338 ((char __iomem *) dd->userbase +
339 dd->ureg_align * ctxt);
340 else
341 ubase = (u64 __iomem *)
342 (dd->uregbase +
343 (char __iomem *) dd->kregbase +
344 dd->ureg_align * ctxt);
345
346 if (dd->kregbase && (dd->flags & QIB_PRESENT))
347 writeq(value, &ubase[regno]);
348}
349
350static inline u32 qib_read_kreg32(const struct qib_devdata *dd,
351 const u16 regno)
352{
353 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
354 return -1;
355 return readl((u32 __iomem *)&dd->kregbase[regno]);
356}
357
358static inline u64 qib_read_kreg64(const struct qib_devdata *dd,
359 const u16 regno)
360{
361 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
362 return -1;
363
364 return readq(&dd->kregbase[regno]);
365}
366
367static inline void qib_write_kreg(const struct qib_devdata *dd,
368 const u16 regno, u64 value)
369{
370 if (dd->kregbase && (dd->flags & QIB_PRESENT))
371 writeq(value, &dd->kregbase[regno]);
372}
373
374
375
376
377
378
379
380
381static inline void qib_write_kreg_ctxt(const struct qib_devdata *dd,
382 const u16 regno, unsigned ctxt,
383 u64 value)
384{
385 qib_write_kreg(dd, regno + ctxt, value);
386}
387
388static inline void write_6120_creg(const struct qib_devdata *dd,
389 u16 regno, u64 value)
390{
391 if (dd->cspec->cregbase && (dd->flags & QIB_PRESENT))
392 writeq(value, &dd->cspec->cregbase[regno]);
393}
394
395static inline u64 read_6120_creg(const struct qib_devdata *dd, u16 regno)
396{
397 if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
398 return 0;
399 return readq(&dd->cspec->cregbase[regno]);
400}
401
402static inline u32 read_6120_creg32(const struct qib_devdata *dd, u16 regno)
403{
404 if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
405 return 0;
406 return readl(&dd->cspec->cregbase[regno]);
407}
408
409
410#define QLOGIC_IB_C_RESET 1U
411
412
413#define QLOGIC_IB_I_RCVURG_MASK ((1U << 5) - 1)
414#define QLOGIC_IB_I_RCVURG_SHIFT 0
415#define QLOGIC_IB_I_RCVAVAIL_MASK ((1U << 5) - 1)
416#define QLOGIC_IB_I_RCVAVAIL_SHIFT 12
417
418#define QLOGIC_IB_C_FREEZEMODE 0x00000002
419#define QLOGIC_IB_C_LINKENABLE 0x00000004
420#define QLOGIC_IB_I_ERROR 0x0000000080000000ULL
421#define QLOGIC_IB_I_SPIOSENT 0x0000000040000000ULL
422#define QLOGIC_IB_I_SPIOBUFAVAIL 0x0000000020000000ULL
423#define QLOGIC_IB_I_GPIO 0x0000000010000000ULL
424#define QLOGIC_IB_I_BITSEXTANT \
425 ((QLOGIC_IB_I_RCVURG_MASK << QLOGIC_IB_I_RCVURG_SHIFT) | \
426 (QLOGIC_IB_I_RCVAVAIL_MASK << \
427 QLOGIC_IB_I_RCVAVAIL_SHIFT) | \
428 QLOGIC_IB_I_ERROR | QLOGIC_IB_I_SPIOSENT | \
429 QLOGIC_IB_I_SPIOBUFAVAIL | QLOGIC_IB_I_GPIO)
430
431
432#define QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK 0x000000000000003fULL
433#define QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT 0
434#define QLOGIC_IB_HWE_PCIEPOISONEDTLP 0x0000000010000000ULL
435#define QLOGIC_IB_HWE_PCIECPLTIMEOUT 0x0000000020000000ULL
436#define QLOGIC_IB_HWE_PCIEBUSPARITYXTLH 0x0000000040000000ULL
437#define QLOGIC_IB_HWE_PCIEBUSPARITYXADM 0x0000000080000000ULL
438#define QLOGIC_IB_HWE_PCIEBUSPARITYRADM 0x0000000100000000ULL
439#define QLOGIC_IB_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
440#define QLOGIC_IB_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
441#define QLOGIC_IB_HWE_PCIE1PLLFAILED 0x0400000000000000ULL
442#define QLOGIC_IB_HWE_PCIE0PLLFAILED 0x0800000000000000ULL
443#define QLOGIC_IB_HWE_SERDESPLLFAILED 0x1000000000000000ULL
444
445
446
447#define QLOGIC_IB_EXTS_FREQSEL 0x2
448#define QLOGIC_IB_EXTS_SERDESSEL 0x4
449#define QLOGIC_IB_EXTS_MEMBIST_ENDTEST 0x0000000000004000
450#define QLOGIC_IB_EXTS_MEMBIST_FOUND 0x0000000000008000
451
452
453#define QLOGIC_IB_XGXS_RESET 0x5ULL
454
455#define _QIB_GPIO_SDA_NUM 1
456#define _QIB_GPIO_SCL_NUM 0
457
458
459#define GPIO_RXUVL_BIT 3
460#define GPIO_OVRUN_BIT 4
461#define GPIO_LLI_BIT 5
462#define GPIO_ERRINTR_MASK 0x38
463
464
465#define QLOGIC_IB_RT_BUFSIZE_MASK 0xe0000000ULL
466#define QLOGIC_IB_RT_BUFSIZE_SHIFTVAL(tid) \
467 ((((tid) & QLOGIC_IB_RT_BUFSIZE_MASK) >> 29) + 11 - 1)
468#define QLOGIC_IB_RT_BUFSIZE(tid) (1 << QLOGIC_IB_RT_BUFSIZE_SHIFTVAL(tid))
469#define QLOGIC_IB_RT_IS_VALID(tid) \
470 (((tid) & QLOGIC_IB_RT_BUFSIZE_MASK) && \
471 ((((tid) & QLOGIC_IB_RT_BUFSIZE_MASK) != QLOGIC_IB_RT_BUFSIZE_MASK)))
472#define QLOGIC_IB_RT_ADDR_MASK 0x1FFFFFFFULL
473#define QLOGIC_IB_RT_ADDR_SHIFT 10
474
475#define QLOGIC_IB_R_INTRAVAIL_SHIFT 16
476#define QLOGIC_IB_R_TAILUPD_SHIFT 31
477#define IBA6120_R_PKEY_DIS_SHIFT 30
478
479#define PBC_6120_VL15_SEND_CTRL (1ULL << 31)
480
481#define IBCBUSFRSPCPARITYERR HWE_MASK(IBCBusFromSPCParityErr)
482#define IBCBUSTOSPCPARITYERR HWE_MASK(IBCBusToSPCParityErr)
483
484#define SYM_MASK_BIT(regname, fldname, bit) ((u64) \
485 ((1ULL << (SYM_LSB(regname, fldname) + (bit)))))
486
487#define TXEMEMPARITYERR_PIOBUF \
488 SYM_MASK_BIT(HwErrMask, TXEMemParityErrMask, 0)
489#define TXEMEMPARITYERR_PIOPBC \
490 SYM_MASK_BIT(HwErrMask, TXEMemParityErrMask, 1)
491#define TXEMEMPARITYERR_PIOLAUNCHFIFO \
492 SYM_MASK_BIT(HwErrMask, TXEMemParityErrMask, 2)
493
494#define RXEMEMPARITYERR_RCVBUF \
495 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 0)
496#define RXEMEMPARITYERR_LOOKUPQ \
497 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 1)
498#define RXEMEMPARITYERR_EXPTID \
499 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 2)
500#define RXEMEMPARITYERR_EAGERTID \
501 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 3)
502#define RXEMEMPARITYERR_FLAGBUF \
503 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 4)
504#define RXEMEMPARITYERR_DATAINFO \
505 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 5)
506#define RXEMEMPARITYERR_HDRINFO \
507 SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 6)
508
509
510static const struct qib_hwerror_msgs qib_6120_hwerror_msgs[] = {
511
512 QLOGIC_IB_HWE_MSG(IBCBUSFRSPCPARITYERR, "QIB2IB Parity"),
513 QLOGIC_IB_HWE_MSG(IBCBUSTOSPCPARITYERR, "IB2QIB Parity"),
514
515 QLOGIC_IB_HWE_MSG(TXEMEMPARITYERR_PIOBUF,
516 "TXE PIOBUF Memory Parity"),
517 QLOGIC_IB_HWE_MSG(TXEMEMPARITYERR_PIOPBC,
518 "TXE PIOPBC Memory Parity"),
519 QLOGIC_IB_HWE_MSG(TXEMEMPARITYERR_PIOLAUNCHFIFO,
520 "TXE PIOLAUNCHFIFO Memory Parity"),
521
522 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_RCVBUF,
523 "RXE RCVBUF Memory Parity"),
524 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_LOOKUPQ,
525 "RXE LOOKUPQ Memory Parity"),
526 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_EAGERTID,
527 "RXE EAGERTID Memory Parity"),
528 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_EXPTID,
529 "RXE EXPTID Memory Parity"),
530 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_FLAGBUF,
531 "RXE FLAGBUF Memory Parity"),
532 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_DATAINFO,
533 "RXE DATAINFO Memory Parity"),
534 QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_HDRINFO,
535 "RXE HDRINFO Memory Parity"),
536
537
538 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEPOISONEDTLP,
539 "PCIe Poisoned TLP"),
540 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIECPLTIMEOUT,
541 "PCIe completion timeout"),
542
543
544
545
546
547
548
549 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIE1PLLFAILED,
550 "PCIePLL1"),
551 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIE0PLLFAILED,
552 "PCIePLL0"),
553 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEBUSPARITYXTLH,
554 "PCIe XTLH core parity"),
555 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEBUSPARITYXADM,
556 "PCIe ADM TX core parity"),
557 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEBUSPARITYRADM,
558 "PCIe ADM RX core parity"),
559 QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_SERDESPLLFAILED,
560 "SerDes PLL"),
561};
562
563#define TXE_PIO_PARITY (TXEMEMPARITYERR_PIOBUF | TXEMEMPARITYERR_PIOPBC)
564#define _QIB_PLL_FAIL (QLOGIC_IB_HWE_COREPLL_FBSLIP | \
565 QLOGIC_IB_HWE_COREPLL_RFSLIP)
566
567
568#define IB_HWE_BITSEXTANT \
569 (HWE_MASK(RXEMemParityErr) | \
570 HWE_MASK(TXEMemParityErr) | \
571 (QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK << \
572 QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT) | \
573 QLOGIC_IB_HWE_PCIE1PLLFAILED | \
574 QLOGIC_IB_HWE_PCIE0PLLFAILED | \
575 QLOGIC_IB_HWE_PCIEPOISONEDTLP | \
576 QLOGIC_IB_HWE_PCIECPLTIMEOUT | \
577 QLOGIC_IB_HWE_PCIEBUSPARITYXTLH | \
578 QLOGIC_IB_HWE_PCIEBUSPARITYXADM | \
579 QLOGIC_IB_HWE_PCIEBUSPARITYRADM | \
580 HWE_MASK(PowerOnBISTFailed) | \
581 QLOGIC_IB_HWE_COREPLL_FBSLIP | \
582 QLOGIC_IB_HWE_COREPLL_RFSLIP | \
583 QLOGIC_IB_HWE_SERDESPLLFAILED | \
584 HWE_MASK(IBCBusToSPCParityErr) | \
585 HWE_MASK(IBCBusFromSPCParityErr))
586
587#define IB_E_BITSEXTANT \
588 (ERR_MASK(RcvFormatErr) | ERR_MASK(RcvVCRCErr) | \
589 ERR_MASK(RcvICRCErr) | ERR_MASK(RcvMinPktLenErr) | \
590 ERR_MASK(RcvMaxPktLenErr) | ERR_MASK(RcvLongPktLenErr) | \
591 ERR_MASK(RcvShortPktLenErr) | ERR_MASK(RcvUnexpectedCharErr) | \
592 ERR_MASK(RcvUnsupportedVLErr) | ERR_MASK(RcvEBPErr) | \
593 ERR_MASK(RcvIBFlowErr) | ERR_MASK(RcvBadVersionErr) | \
594 ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr) | \
595 ERR_MASK(RcvBadTidErr) | ERR_MASK(RcvHdrLenErr) | \
596 ERR_MASK(RcvHdrErr) | ERR_MASK(RcvIBLostLinkErr) | \
597 ERR_MASK(SendMinPktLenErr) | ERR_MASK(SendMaxPktLenErr) | \
598 ERR_MASK(SendUnderRunErr) | ERR_MASK(SendPktLenErr) | \
599 ERR_MASK(SendDroppedSmpPktErr) | \
600 ERR_MASK(SendDroppedDataPktErr) | \
601 ERR_MASK(SendPioArmLaunchErr) | \
602 ERR_MASK(SendUnexpectedPktNumErr) | \
603 ERR_MASK(SendUnsupportedVLErr) | ERR_MASK(IBStatusChanged) | \
604 ERR_MASK(InvalidAddrErr) | ERR_MASK(ResetNegated) | \
605 ERR_MASK(HardwareErr))
606
607#define QLOGIC_IB_E_PKTERRS ( \
608 ERR_MASK(SendPktLenErr) | \
609 ERR_MASK(SendDroppedDataPktErr) | \
610 ERR_MASK(RcvVCRCErr) | \
611 ERR_MASK(RcvICRCErr) | \
612 ERR_MASK(RcvShortPktLenErr) | \
613 ERR_MASK(RcvEBPErr))
614
615
616#define E_SUM_PKTERRS \
617 (ERR_MASK(RcvHdrLenErr) | ERR_MASK(RcvBadTidErr) | \
618 ERR_MASK(RcvBadVersionErr) | ERR_MASK(RcvHdrErr) | \
619 ERR_MASK(RcvLongPktLenErr) | ERR_MASK(RcvShortPktLenErr) | \
620 ERR_MASK(RcvMaxPktLenErr) | ERR_MASK(RcvMinPktLenErr) | \
621 ERR_MASK(RcvFormatErr) | ERR_MASK(RcvUnsupportedVLErr) | \
622 ERR_MASK(RcvUnexpectedCharErr) | ERR_MASK(RcvEBPErr))
623
624
625#define E_SUM_ERRS \
626 (ERR_MASK(SendPioArmLaunchErr) | \
627 ERR_MASK(SendUnexpectedPktNumErr) | \
628 ERR_MASK(SendDroppedDataPktErr) | \
629 ERR_MASK(SendDroppedSmpPktErr) | \
630 ERR_MASK(SendMaxPktLenErr) | ERR_MASK(SendUnsupportedVLErr) | \
631 ERR_MASK(SendMinPktLenErr) | ERR_MASK(SendPktLenErr) | \
632 ERR_MASK(InvalidAddrErr))
633
634
635
636
637
638
639
640#define E_SPKT_ERRS_IGNORE \
641 (ERR_MASK(SendDroppedDataPktErr) | \
642 ERR_MASK(SendDroppedSmpPktErr) | \
643 ERR_MASK(SendMaxPktLenErr) | ERR_MASK(SendMinPktLenErr) | \
644 ERR_MASK(SendPktLenErr))
645
646
647
648
649
650
651
652#define E_SUM_LINK_PKTERRS \
653 (ERR_MASK(SendDroppedDataPktErr) | \
654 ERR_MASK(SendDroppedSmpPktErr) | \
655 ERR_MASK(SendMinPktLenErr) | ERR_MASK(SendPktLenErr) | \
656 ERR_MASK(RcvShortPktLenErr) | ERR_MASK(RcvMinPktLenErr) | \
657 ERR_MASK(RcvUnexpectedCharErr))
658
659static void qib_6120_put_tid_2(struct qib_devdata *, u64 __iomem *,
660 u32, unsigned long);
661
662
663
664
665
666
667
668
669static void qib_6120_txe_recover(struct qib_devdata *dd)
670{
671 if (!qib_unordered_wc())
672 qib_devinfo(dd->pcidev,
673 "Recovering from TXE PIO parity error\n");
674}
675
676
677static void qib_6120_set_intr_state(struct qib_devdata *dd, u32 enable)
678{
679 if (enable) {
680 if (dd->flags & QIB_BADINTR)
681 return;
682 qib_write_kreg(dd, kr_intmask, ~0ULL);
683
684 qib_write_kreg(dd, kr_intclear, 0ULL);
685 } else
686 qib_write_kreg(dd, kr_intmask, 0ULL);
687}
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704static void qib_6120_clear_freeze(struct qib_devdata *dd)
705{
706
707 qib_write_kreg(dd, kr_errmask, 0ULL);
708
709
710 qib_6120_set_intr_state(dd, 0);
711
712 qib_cancel_sends(dd->pport);
713
714
715 qib_write_kreg(dd, kr_control, dd->control);
716 qib_read_kreg32(dd, kr_scratch);
717
718
719 qib_force_pio_avail_update(dd);
720
721
722
723
724
725
726
727 qib_write_kreg(dd, kr_hwerrclear, 0ULL);
728 qib_write_kreg(dd, kr_errclear, E_SPKT_ERRS_IGNORE);
729 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
730 qib_6120_set_intr_state(dd, 1);
731}
732
733
734
735
736
737
738
739
740
741
742
743
744static void qib_handle_6120_hwerrors(struct qib_devdata *dd, char *msg,
745 size_t msgl)
746{
747 u64 hwerrs;
748 u32 bits, ctrl;
749 int isfatal = 0;
750 char *bitsmsg;
751 int log_idx;
752
753 hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
754 if (!hwerrs)
755 return;
756 if (hwerrs == ~0ULL) {
757 qib_dev_err(dd,
758 "Read of hardware error status failed (all bits set); ignoring\n");
759 return;
760 }
761 qib_stats.sps_hwerrs++;
762
763
764
765
766
767
768 qib_write_kreg(dd, kr_hwerrclear,
769 hwerrs & ~HWE_MASK(PowerOnBISTFailed));
770
771 hwerrs &= dd->cspec->hwerrmask;
772
773
774 for (log_idx = 0; log_idx < QIB_EEP_LOG_CNT; ++log_idx)
775 if (hwerrs & dd->eep_st_masks[log_idx].hwerrs_to_log)
776 qib_inc_eeprom_err(dd, log_idx, 1);
777
778
779
780
781
782 if (hwerrs & ~(TXE_PIO_PARITY | RXEMEMPARITYERR_EAGERTID))
783 qib_devinfo(dd->pcidev,
784 "Hardware error: hwerr=0x%llx (cleared)\n",
785 (unsigned long long) hwerrs);
786
787 if (hwerrs & ~IB_HWE_BITSEXTANT)
788 qib_dev_err(dd,
789 "hwerror interrupt with unknown errors %llx set\n",
790 (unsigned long long)(hwerrs & ~IB_HWE_BITSEXTANT));
791
792 ctrl = qib_read_kreg32(dd, kr_control);
793 if ((ctrl & QLOGIC_IB_C_FREEZEMODE) && !dd->diag_client) {
794
795
796
797
798
799
800
801
802 if (hwerrs & TXE_PIO_PARITY) {
803 qib_6120_txe_recover(dd);
804 hwerrs &= ~TXE_PIO_PARITY;
805 }
806
807 if (!hwerrs) {
808 static u32 freeze_cnt;
809
810 freeze_cnt++;
811 qib_6120_clear_freeze(dd);
812 } else
813 isfatal = 1;
814 }
815
816 *msg = '\0';
817
818 if (hwerrs & HWE_MASK(PowerOnBISTFailed)) {
819 isfatal = 1;
820 strlcat(msg,
821 "[Memory BIST test failed, InfiniPath hardware unusable]",
822 msgl);
823
824 dd->cspec->hwerrmask &= ~HWE_MASK(PowerOnBISTFailed);
825 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
826 }
827
828 qib_format_hwerrors(hwerrs, qib_6120_hwerror_msgs,
829 ARRAY_SIZE(qib_6120_hwerror_msgs), msg, msgl);
830
831 bitsmsg = dd->cspec->bitsmsgbuf;
832 if (hwerrs & (QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK <<
833 QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT)) {
834 bits = (u32) ((hwerrs >>
835 QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT) &
836 QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK);
837 snprintf(bitsmsg, sizeof dd->cspec->bitsmsgbuf,
838 "[PCIe Mem Parity Errs %x] ", bits);
839 strlcat(msg, bitsmsg, msgl);
840 }
841
842 if (hwerrs & _QIB_PLL_FAIL) {
843 isfatal = 1;
844 snprintf(bitsmsg, sizeof dd->cspec->bitsmsgbuf,
845 "[PLL failed (%llx), InfiniPath hardware unusable]",
846 (unsigned long long) hwerrs & _QIB_PLL_FAIL);
847 strlcat(msg, bitsmsg, msgl);
848
849 dd->cspec->hwerrmask &= ~(hwerrs & _QIB_PLL_FAIL);
850 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
851 }
852
853 if (hwerrs & QLOGIC_IB_HWE_SERDESPLLFAILED) {
854
855
856
857
858 dd->cspec->hwerrmask &= ~QLOGIC_IB_HWE_SERDESPLLFAILED;
859 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
860 }
861
862 if (hwerrs)
863
864
865
866
867
868
869 qib_dev_err(dd, "%s hardware error\n", msg);
870 else
871 *msg = 0;
872
873 if (isfatal && !dd->diag_client) {
874 qib_dev_err(dd,
875 "Fatal Hardware Error, no longer usable, SN %.16s\n",
876 dd->serial);
877
878
879
880
881 if (dd->freezemsg)
882 snprintf(dd->freezemsg, dd->freezelen,
883 "{%s}", msg);
884 qib_disable_after_error(dd);
885 }
886}
887
888
889
890
891
892
893
894static int qib_decode_6120_err(struct qib_devdata *dd, char *buf, size_t blen,
895 u64 err)
896{
897 int iserr = 1;
898
899 *buf = '\0';
900 if (err & QLOGIC_IB_E_PKTERRS) {
901 if (!(err & ~QLOGIC_IB_E_PKTERRS))
902 iserr = 0;
903 if ((err & ERR_MASK(RcvICRCErr)) &&
904 !(err&(ERR_MASK(RcvVCRCErr)|ERR_MASK(RcvEBPErr))))
905 strlcat(buf, "CRC ", blen);
906 if (!iserr)
907 goto done;
908 }
909 if (err & ERR_MASK(RcvHdrLenErr))
910 strlcat(buf, "rhdrlen ", blen);
911 if (err & ERR_MASK(RcvBadTidErr))
912 strlcat(buf, "rbadtid ", blen);
913 if (err & ERR_MASK(RcvBadVersionErr))
914 strlcat(buf, "rbadversion ", blen);
915 if (err & ERR_MASK(RcvHdrErr))
916 strlcat(buf, "rhdr ", blen);
917 if (err & ERR_MASK(RcvLongPktLenErr))
918 strlcat(buf, "rlongpktlen ", blen);
919 if (err & ERR_MASK(RcvMaxPktLenErr))
920 strlcat(buf, "rmaxpktlen ", blen);
921 if (err & ERR_MASK(RcvMinPktLenErr))
922 strlcat(buf, "rminpktlen ", blen);
923 if (err & ERR_MASK(SendMinPktLenErr))
924 strlcat(buf, "sminpktlen ", blen);
925 if (err & ERR_MASK(RcvFormatErr))
926 strlcat(buf, "rformaterr ", blen);
927 if (err & ERR_MASK(RcvUnsupportedVLErr))
928 strlcat(buf, "runsupvl ", blen);
929 if (err & ERR_MASK(RcvUnexpectedCharErr))
930 strlcat(buf, "runexpchar ", blen);
931 if (err & ERR_MASK(RcvIBFlowErr))
932 strlcat(buf, "ribflow ", blen);
933 if (err & ERR_MASK(SendUnderRunErr))
934 strlcat(buf, "sunderrun ", blen);
935 if (err & ERR_MASK(SendPioArmLaunchErr))
936 strlcat(buf, "spioarmlaunch ", blen);
937 if (err & ERR_MASK(SendUnexpectedPktNumErr))
938 strlcat(buf, "sunexperrpktnum ", blen);
939 if (err & ERR_MASK(SendDroppedSmpPktErr))
940 strlcat(buf, "sdroppedsmppkt ", blen);
941 if (err & ERR_MASK(SendMaxPktLenErr))
942 strlcat(buf, "smaxpktlen ", blen);
943 if (err & ERR_MASK(SendUnsupportedVLErr))
944 strlcat(buf, "sunsupVL ", blen);
945 if (err & ERR_MASK(InvalidAddrErr))
946 strlcat(buf, "invalidaddr ", blen);
947 if (err & ERR_MASK(RcvEgrFullErr))
948 strlcat(buf, "rcvegrfull ", blen);
949 if (err & ERR_MASK(RcvHdrFullErr))
950 strlcat(buf, "rcvhdrfull ", blen);
951 if (err & ERR_MASK(IBStatusChanged))
952 strlcat(buf, "ibcstatuschg ", blen);
953 if (err & ERR_MASK(RcvIBLostLinkErr))
954 strlcat(buf, "riblostlink ", blen);
955 if (err & ERR_MASK(HardwareErr))
956 strlcat(buf, "hardware ", blen);
957 if (err & ERR_MASK(ResetNegated))
958 strlcat(buf, "reset ", blen);
959done:
960 return iserr;
961}
962
963
964
965
966
967static void qib_disarm_6120_senderrbufs(struct qib_pportdata *ppd)
968{
969 unsigned long sbuf[2];
970 struct qib_devdata *dd = ppd->dd;
971
972
973
974
975
976 sbuf[0] = qib_read_kreg64(dd, kr_sendbuffererror);
977 sbuf[1] = qib_read_kreg64(dd, kr_sendbuffererror + 1);
978
979 if (sbuf[0] || sbuf[1])
980 qib_disarm_piobufs_set(dd, sbuf,
981 dd->piobcnt2k + dd->piobcnt4k);
982}
983
984static int chk_6120_linkrecovery(struct qib_devdata *dd, u64 ibcs)
985{
986 int ret = 1;
987 u32 ibstate = qib_6120_iblink_state(ibcs);
988 u32 linkrecov = read_6120_creg32(dd, cr_iblinkerrrecov);
989
990 if (linkrecov != dd->cspec->lastlinkrecov) {
991
992 dd->cspec->lastlinkrecov = 0;
993 qib_set_linkstate(dd->pport, QIB_IB_LINKDOWN);
994 ret = 0;
995 }
996 if (ibstate == IB_PORT_ACTIVE)
997 dd->cspec->lastlinkrecov =
998 read_6120_creg32(dd, cr_iblinkerrrecov);
999 return ret;
1000}
1001
1002static void handle_6120_errors(struct qib_devdata *dd, u64 errs)
1003{
1004 char *msg;
1005 u64 ignore_this_time = 0;
1006 u64 iserr = 0;
1007 int log_idx;
1008 struct qib_pportdata *ppd = dd->pport;
1009 u64 mask;
1010
1011
1012 errs &= dd->cspec->errormask;
1013 msg = dd->cspec->emsgbuf;
1014
1015
1016 if (errs & ERR_MASK(HardwareErr))
1017 qib_handle_6120_hwerrors(dd, msg, sizeof dd->cspec->emsgbuf);
1018 else
1019 for (log_idx = 0; log_idx < QIB_EEP_LOG_CNT; ++log_idx)
1020 if (errs & dd->eep_st_masks[log_idx].errs_to_log)
1021 qib_inc_eeprom_err(dd, log_idx, 1);
1022
1023 if (errs & ~IB_E_BITSEXTANT)
1024 qib_dev_err(dd,
1025 "error interrupt with unknown errors %llx set\n",
1026 (unsigned long long) (errs & ~IB_E_BITSEXTANT));
1027
1028 if (errs & E_SUM_ERRS) {
1029 qib_disarm_6120_senderrbufs(ppd);
1030 if ((errs & E_SUM_LINK_PKTERRS) &&
1031 !(ppd->lflags & QIBL_LINKACTIVE)) {
1032
1033
1034
1035
1036
1037
1038
1039 ignore_this_time = errs & E_SUM_LINK_PKTERRS;
1040 }
1041 } else if ((errs & E_SUM_LINK_PKTERRS) &&
1042 !(ppd->lflags & QIBL_LINKACTIVE)) {
1043
1044
1045
1046
1047
1048
1049
1050 ignore_this_time = errs & E_SUM_LINK_PKTERRS;
1051 }
1052
1053 qib_write_kreg(dd, kr_errclear, errs);
1054
1055 errs &= ~ignore_this_time;
1056 if (!errs)
1057 goto done;
1058
1059
1060
1061
1062
1063 mask = ERR_MASK(IBStatusChanged) | ERR_MASK(RcvEgrFullErr) |
1064 ERR_MASK(RcvHdrFullErr) | ERR_MASK(HardwareErr);
1065 qib_decode_6120_err(dd, msg, sizeof dd->cspec->emsgbuf, errs & ~mask);
1066
1067 if (errs & E_SUM_PKTERRS)
1068 qib_stats.sps_rcverrs++;
1069 if (errs & E_SUM_ERRS)
1070 qib_stats.sps_txerrs++;
1071
1072 iserr = errs & ~(E_SUM_PKTERRS | QLOGIC_IB_E_PKTERRS);
1073
1074 if (errs & ERR_MASK(IBStatusChanged)) {
1075 u64 ibcs = qib_read_kreg64(dd, kr_ibcstatus);
1076 u32 ibstate = qib_6120_iblink_state(ibcs);
1077 int handle = 1;
1078
1079 if (ibstate != IB_PORT_INIT && dd->cspec->lastlinkrecov)
1080 handle = chk_6120_linkrecovery(dd, ibcs);
1081
1082
1083
1084
1085
1086
1087
1088 if (handle && qib_6120_phys_portstate(ibcs) ==
1089 IB_PHYSPORTSTATE_LINK_ERR_RECOVER)
1090 handle = 0;
1091 if (handle)
1092 qib_handle_e_ibstatuschanged(ppd, ibcs);
1093 }
1094
1095 if (errs & ERR_MASK(ResetNegated)) {
1096 qib_dev_err(dd,
1097 "Got reset, requires re-init (unload and reload driver)\n");
1098 dd->flags &= ~QIB_INITTED;
1099
1100 *dd->devstatusp |= QIB_STATUS_HWERROR;
1101 *dd->pport->statusp &= ~QIB_STATUS_IB_CONF;
1102 }
1103
1104 if (*msg && iserr)
1105 qib_dev_porterr(dd, ppd->port, "%s error\n", msg);
1106
1107 if (ppd->state_wanted & ppd->lflags)
1108 wake_up_interruptible(&ppd->state_wait);
1109
1110
1111
1112
1113
1114
1115
1116
1117 if (errs & (ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr))) {
1118 qib_handle_urcv(dd, ~0U);
1119 if (errs & ERR_MASK(RcvEgrFullErr))
1120 qib_stats.sps_buffull++;
1121 else
1122 qib_stats.sps_hdrfull++;
1123 }
1124done:
1125 return;
1126}
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138static void qib_6120_init_hwerrors(struct qib_devdata *dd)
1139{
1140 u64 val;
1141 u64 extsval;
1142
1143 extsval = qib_read_kreg64(dd, kr_extstatus);
1144
1145 if (!(extsval & QLOGIC_IB_EXTS_MEMBIST_ENDTEST))
1146 qib_dev_err(dd, "MemBIST did not complete!\n");
1147
1148
1149 val = ~0ULL;
1150 if (dd->minrev < 2) {
1151
1152
1153
1154
1155 val &= ~QLOGIC_IB_HWE_PCIEBUSPARITYRADM;
1156 }
1157
1158 val &= ~TXEMEMPARITYERR_PIOBUF;
1159
1160 dd->cspec->hwerrmask = val;
1161
1162 qib_write_kreg(dd, kr_hwerrclear, ~HWE_MASK(PowerOnBISTFailed));
1163 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
1164
1165
1166 qib_write_kreg(dd, kr_errclear, ~0ULL);
1167
1168 qib_write_kreg(dd, kr_errmask, ~0ULL);
1169 dd->cspec->errormask = qib_read_kreg64(dd, kr_errmask);
1170
1171 qib_write_kreg(dd, kr_intclear, ~0ULL);
1172
1173 qib_write_kreg(dd, kr_rcvbthqp,
1174 dd->qpn_mask << (QIB_6120_RcvBTHQP_BTHQP_Mask_LSB - 1) |
1175 QIB_KD_QP);
1176}
1177
1178
1179
1180
1181
1182
1183
1184static void qib_set_6120_armlaunch(struct qib_devdata *dd, u32 enable)
1185{
1186 if (enable) {
1187 qib_write_kreg(dd, kr_errclear,
1188 ERR_MASK(SendPioArmLaunchErr));
1189 dd->cspec->errormask |= ERR_MASK(SendPioArmLaunchErr);
1190 } else
1191 dd->cspec->errormask &= ~ERR_MASK(SendPioArmLaunchErr);
1192 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
1193}
1194
1195
1196
1197
1198
1199
1200static void qib_set_ib_6120_lstate(struct qib_pportdata *ppd, u16 linkcmd,
1201 u16 linitcmd)
1202{
1203 u64 mod_wd;
1204 struct qib_devdata *dd = ppd->dd;
1205 unsigned long flags;
1206
1207 if (linitcmd == QLOGIC_IB_IBCC_LINKINITCMD_DISABLE) {
1208
1209
1210
1211
1212 spin_lock_irqsave(&ppd->lflags_lock, flags);
1213 ppd->lflags |= QIBL_IB_LINK_DISABLED;
1214 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
1215 } else if (linitcmd || linkcmd == QLOGIC_IB_IBCC_LINKCMD_DOWN) {
1216
1217
1218
1219
1220
1221 spin_lock_irqsave(&ppd->lflags_lock, flags);
1222 ppd->lflags &= ~QIBL_IB_LINK_DISABLED;
1223 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
1224 }
1225
1226 mod_wd = (linkcmd << QLOGIC_IB_IBCC_LINKCMD_SHIFT) |
1227 (linitcmd << QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
1228
1229 qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl | mod_wd);
1230
1231 qib_write_kreg(dd, kr_scratch, 0);
1232}
1233
1234
1235
1236
1237
1238static int qib_6120_bringup_serdes(struct qib_pportdata *ppd)
1239{
1240 struct qib_devdata *dd = ppd->dd;
1241 u64 val, config1, prev_val, hwstat, ibc;
1242
1243
1244 dd->control &= ~QLOGIC_IB_C_LINKENABLE;
1245 qib_write_kreg(dd, kr_control, 0ULL);
1246
1247 dd->cspec->ibdeltainprog = 1;
1248 dd->cspec->ibsymsnap = read_6120_creg32(dd, cr_ibsymbolerr);
1249 dd->cspec->iblnkerrsnap = read_6120_creg32(dd, cr_iblinkerrrecov);
1250
1251
1252 ibc = 0x5ULL << SYM_LSB(IBCCtrl, FlowCtrlWaterMark);
1253
1254
1255
1256
1257
1258 ibc |= 0x3ULL << SYM_LSB(IBCCtrl, FlowCtrlPeriod);
1259
1260 dd->cspec->lli_thresh = 0xf;
1261 ibc |= (u64) dd->cspec->lli_thresh << SYM_LSB(IBCCtrl, PhyerrThreshold);
1262
1263 ibc |= 4ULL << SYM_LSB(IBCCtrl, CreditScale);
1264
1265 ibc |= 0xfULL << SYM_LSB(IBCCtrl, OverrunThreshold);
1266
1267
1268
1269
1270 ibc |= ((u64)(ppd->ibmaxlen >> 2) + 1) << SYM_LSB(IBCCtrl, MaxPktLen);
1271 dd->cspec->ibcctrl = ibc;
1272
1273
1274 val = dd->cspec->ibcctrl | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
1275 QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
1276 qib_write_kreg(dd, kr_ibcctrl, val);
1277
1278 val = qib_read_kreg64(dd, kr_serdes_cfg0);
1279 config1 = qib_read_kreg64(dd, kr_serdes_cfg1);
1280
1281
1282
1283
1284
1285
1286
1287 val |= SYM_MASK(SerdesCfg0, ResetPLL) |
1288 SYM_MASK(SerdesCfg0, RxDetEnX) |
1289 (SYM_MASK(SerdesCfg0, L1PwrDnA) |
1290 SYM_MASK(SerdesCfg0, L1PwrDnB) |
1291 SYM_MASK(SerdesCfg0, L1PwrDnC) |
1292 SYM_MASK(SerdesCfg0, L1PwrDnD));
1293 qib_write_kreg(dd, kr_serdes_cfg0, val);
1294
1295 qib_read_kreg64(dd, kr_scratch);
1296 udelay(5);
1297
1298
1299
1300
1301
1302 val &= ~(SYM_MASK(SerdesCfg0, RxDetEnX) |
1303 SYM_MASK(SerdesCfg0, ResetPLL) |
1304 (SYM_MASK(SerdesCfg0, L1PwrDnA) |
1305 SYM_MASK(SerdesCfg0, L1PwrDnB) |
1306 SYM_MASK(SerdesCfg0, L1PwrDnC) |
1307 SYM_MASK(SerdesCfg0, L1PwrDnD)));
1308 val |= (SYM_MASK(SerdesCfg0, ResetA) |
1309 SYM_MASK(SerdesCfg0, ResetB) |
1310 SYM_MASK(SerdesCfg0, ResetC) |
1311 SYM_MASK(SerdesCfg0, ResetD)) |
1312 SYM_MASK(SerdesCfg0, TxIdeEnX);
1313 qib_write_kreg(dd, kr_serdes_cfg0, val);
1314
1315 (void) qib_read_kreg64(dd, kr_scratch);
1316
1317
1318 udelay(15);
1319 val &= ~((SYM_MASK(SerdesCfg0, ResetA) |
1320 SYM_MASK(SerdesCfg0, ResetB) |
1321 SYM_MASK(SerdesCfg0, ResetC) |
1322 SYM_MASK(SerdesCfg0, ResetD)) |
1323 SYM_MASK(SerdesCfg0, TxIdeEnX));
1324
1325 qib_write_kreg(dd, kr_serdes_cfg0, val);
1326
1327 (void) qib_read_kreg64(dd, kr_scratch);
1328
1329 val = qib_read_kreg64(dd, kr_xgxs_cfg);
1330 prev_val = val;
1331 if (val & QLOGIC_IB_XGXS_RESET)
1332 val &= ~QLOGIC_IB_XGXS_RESET;
1333 if (SYM_FIELD(val, XGXSCfg, polarity_inv) != ppd->rx_pol_inv) {
1334
1335 val &= ~SYM_MASK(XGXSCfg, polarity_inv);
1336 val |= (u64)ppd->rx_pol_inv << SYM_LSB(XGXSCfg, polarity_inv);
1337 }
1338 if (val != prev_val)
1339 qib_write_kreg(dd, kr_xgxs_cfg, val);
1340
1341 val = qib_read_kreg64(dd, kr_serdes_cfg0);
1342
1343
1344 config1 &= ~0x0ffffffff00ULL;
1345
1346 config1 |= 0x00000000000ULL;
1347
1348 config1 |= 0x0cccc000000ULL;
1349 qib_write_kreg(dd, kr_serdes_cfg1, config1);
1350
1351
1352 ppd->guid = dd->base_guid;
1353
1354
1355
1356
1357
1358
1359 hwstat = qib_read_kreg64(dd, kr_hwerrstatus);
1360 if (hwstat) {
1361
1362 qib_write_kreg(dd, kr_hwerrclear, hwstat);
1363 qib_write_kreg(dd, kr_errclear, ERR_MASK(HardwareErr));
1364 }
1365
1366 dd->control |= QLOGIC_IB_C_LINKENABLE;
1367 dd->control &= ~QLOGIC_IB_C_FREEZEMODE;
1368 qib_write_kreg(dd, kr_control, dd->control);
1369
1370 return 0;
1371}
1372
1373
1374
1375
1376
1377
1378static void qib_6120_quiet_serdes(struct qib_pportdata *ppd)
1379{
1380 struct qib_devdata *dd = ppd->dd;
1381 u64 val;
1382
1383 qib_set_ib_6120_lstate(ppd, 0, QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
1384
1385
1386 dd->control &= ~QLOGIC_IB_C_LINKENABLE;
1387 qib_write_kreg(dd, kr_control,
1388 dd->control | QLOGIC_IB_C_FREEZEMODE);
1389
1390 if (dd->cspec->ibsymdelta || dd->cspec->iblnkerrdelta ||
1391 dd->cspec->ibdeltainprog) {
1392 u64 diagc;
1393
1394
1395 diagc = qib_read_kreg64(dd, kr_hwdiagctrl);
1396 qib_write_kreg(dd, kr_hwdiagctrl,
1397 diagc | SYM_MASK(HwDiagCtrl, CounterWrEnable));
1398
1399 if (dd->cspec->ibsymdelta || dd->cspec->ibdeltainprog) {
1400 val = read_6120_creg32(dd, cr_ibsymbolerr);
1401 if (dd->cspec->ibdeltainprog)
1402 val -= val - dd->cspec->ibsymsnap;
1403 val -= dd->cspec->ibsymdelta;
1404 write_6120_creg(dd, cr_ibsymbolerr, val);
1405 }
1406 if (dd->cspec->iblnkerrdelta || dd->cspec->ibdeltainprog) {
1407 val = read_6120_creg32(dd, cr_iblinkerrrecov);
1408 if (dd->cspec->ibdeltainprog)
1409 val -= val - dd->cspec->iblnkerrsnap;
1410 val -= dd->cspec->iblnkerrdelta;
1411 write_6120_creg(dd, cr_iblinkerrrecov, val);
1412 }
1413
1414
1415 qib_write_kreg(dd, kr_hwdiagctrl, diagc);
1416 }
1417
1418 val = qib_read_kreg64(dd, kr_serdes_cfg0);
1419 val |= SYM_MASK(SerdesCfg0, TxIdeEnX);
1420 qib_write_kreg(dd, kr_serdes_cfg0, val);
1421}
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446static void qib_6120_setup_setextled(struct qib_pportdata *ppd, u32 on)
1447{
1448 u64 extctl, val, lst, ltst;
1449 unsigned long flags;
1450 struct qib_devdata *dd = ppd->dd;
1451
1452
1453
1454
1455
1456 if (dd->diag_client)
1457 return;
1458
1459
1460 if (ppd->led_override) {
1461 ltst = (ppd->led_override & QIB_LED_PHYS) ?
1462 IB_PHYSPORTSTATE_LINKUP : IB_PHYSPORTSTATE_DISABLED,
1463 lst = (ppd->led_override & QIB_LED_LOG) ?
1464 IB_PORT_ACTIVE : IB_PORT_DOWN;
1465 } else if (on) {
1466 val = qib_read_kreg64(dd, kr_ibcstatus);
1467 ltst = qib_6120_phys_portstate(val);
1468 lst = qib_6120_iblink_state(val);
1469 } else {
1470 ltst = 0;
1471 lst = 0;
1472 }
1473
1474 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
1475 extctl = dd->cspec->extctrl & ~(SYM_MASK(EXTCtrl, LEDPriPortGreenOn) |
1476 SYM_MASK(EXTCtrl, LEDPriPortYellowOn));
1477
1478 if (ltst == IB_PHYSPORTSTATE_LINKUP)
1479 extctl |= SYM_MASK(EXTCtrl, LEDPriPortYellowOn);
1480 if (lst == IB_PORT_ACTIVE)
1481 extctl |= SYM_MASK(EXTCtrl, LEDPriPortGreenOn);
1482 dd->cspec->extctrl = extctl;
1483 qib_write_kreg(dd, kr_extctrl, extctl);
1484 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
1485}
1486
1487static void qib_6120_free_irq(struct qib_devdata *dd)
1488{
1489 if (dd->cspec->irq) {
1490 free_irq(dd->cspec->irq, dd);
1491 dd->cspec->irq = 0;
1492 }
1493 qib_nomsi(dd);
1494}
1495
1496
1497
1498
1499
1500
1501
1502static void qib_6120_setup_cleanup(struct qib_devdata *dd)
1503{
1504 qib_6120_free_irq(dd);
1505 kfree(dd->cspec->cntrs);
1506 kfree(dd->cspec->portcntrs);
1507 if (dd->cspec->dummy_hdrq) {
1508 dma_free_coherent(&dd->pcidev->dev,
1509 ALIGN(dd->rcvhdrcnt *
1510 dd->rcvhdrentsize *
1511 sizeof(u32), PAGE_SIZE),
1512 dd->cspec->dummy_hdrq,
1513 dd->cspec->dummy_hdrq_phys);
1514 dd->cspec->dummy_hdrq = NULL;
1515 }
1516}
1517
1518static void qib_wantpiobuf_6120_intr(struct qib_devdata *dd, u32 needint)
1519{
1520 unsigned long flags;
1521
1522 spin_lock_irqsave(&dd->sendctrl_lock, flags);
1523 if (needint)
1524 dd->sendctrl |= SYM_MASK(SendCtrl, PIOIntBufAvail);
1525 else
1526 dd->sendctrl &= ~SYM_MASK(SendCtrl, PIOIntBufAvail);
1527 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
1528 qib_write_kreg(dd, kr_scratch, 0ULL);
1529 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
1530}
1531
1532
1533
1534
1535
1536static noinline void unlikely_6120_intr(struct qib_devdata *dd, u64 istat)
1537{
1538 if (unlikely(istat & ~QLOGIC_IB_I_BITSEXTANT))
1539 qib_dev_err(dd, "interrupt with unknown interrupts %Lx set\n",
1540 istat & ~QLOGIC_IB_I_BITSEXTANT);
1541
1542 if (istat & QLOGIC_IB_I_ERROR) {
1543 u64 estat = 0;
1544
1545 qib_stats.sps_errints++;
1546 estat = qib_read_kreg64(dd, kr_errstatus);
1547 if (!estat)
1548 qib_devinfo(dd->pcidev,
1549 "error interrupt (%Lx), but no error bits set!\n",
1550 istat);
1551 handle_6120_errors(dd, estat);
1552 }
1553
1554 if (istat & QLOGIC_IB_I_GPIO) {
1555 u32 gpiostatus;
1556 u32 to_clear = 0;
1557
1558
1559
1560
1561
1562 gpiostatus = qib_read_kreg32(dd, kr_gpio_status);
1563
1564 if (gpiostatus & GPIO_ERRINTR_MASK) {
1565
1566 to_clear |= (gpiostatus & GPIO_ERRINTR_MASK);
1567
1568
1569
1570
1571
1572 if (gpiostatus & (1 << GPIO_RXUVL_BIT))
1573 dd->cspec->rxfc_unsupvl_errs++;
1574 if (gpiostatus & (1 << GPIO_OVRUN_BIT))
1575 dd->cspec->overrun_thresh_errs++;
1576 if (gpiostatus & (1 << GPIO_LLI_BIT))
1577 dd->cspec->lli_errs++;
1578 gpiostatus &= ~GPIO_ERRINTR_MASK;
1579 }
1580 if (gpiostatus) {
1581
1582
1583
1584
1585
1586
1587 const u32 mask = qib_read_kreg32(dd, kr_gpio_mask);
1588
1589
1590
1591
1592
1593
1594 if (mask & gpiostatus) {
1595 to_clear |= (gpiostatus & mask);
1596 dd->cspec->gpio_mask &= ~(gpiostatus & mask);
1597 qib_write_kreg(dd, kr_gpio_mask,
1598 dd->cspec->gpio_mask);
1599 }
1600 }
1601 if (to_clear)
1602 qib_write_kreg(dd, kr_gpio_clear, (u64) to_clear);
1603 }
1604}
1605
1606static irqreturn_t qib_6120intr(int irq, void *data)
1607{
1608 struct qib_devdata *dd = data;
1609 irqreturn_t ret;
1610 u32 istat, ctxtrbits, rmask, crcs = 0;
1611 unsigned i;
1612
1613 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT) {
1614
1615
1616
1617
1618
1619
1620 ret = IRQ_HANDLED;
1621 goto bail;
1622 }
1623
1624 istat = qib_read_kreg32(dd, kr_intstatus);
1625
1626 if (unlikely(!istat)) {
1627 ret = IRQ_NONE;
1628 goto bail;
1629 }
1630 if (unlikely(istat == -1)) {
1631 qib_bad_intrstatus(dd);
1632
1633 ret = IRQ_NONE;
1634 goto bail;
1635 }
1636
1637 qib_stats.sps_ints++;
1638 if (dd->int_counter != (u32) -1)
1639 dd->int_counter++;
1640
1641 if (unlikely(istat & (~QLOGIC_IB_I_BITSEXTANT |
1642 QLOGIC_IB_I_GPIO | QLOGIC_IB_I_ERROR)))
1643 unlikely_6120_intr(dd, istat);
1644
1645
1646
1647
1648
1649
1650
1651 qib_write_kreg(dd, kr_intclear, istat);
1652
1653
1654
1655
1656
1657
1658 ctxtrbits = istat &
1659 ((QLOGIC_IB_I_RCVAVAIL_MASK << QLOGIC_IB_I_RCVAVAIL_SHIFT) |
1660 (QLOGIC_IB_I_RCVURG_MASK << QLOGIC_IB_I_RCVURG_SHIFT));
1661 if (ctxtrbits) {
1662 rmask = (1U << QLOGIC_IB_I_RCVAVAIL_SHIFT) |
1663 (1U << QLOGIC_IB_I_RCVURG_SHIFT);
1664 for (i = 0; i < dd->first_user_ctxt; i++) {
1665 if (ctxtrbits & rmask) {
1666 ctxtrbits &= ~rmask;
1667 crcs += qib_kreceive(dd->rcd[i],
1668 &dd->cspec->lli_counter,
1669 NULL);
1670 }
1671 rmask <<= 1;
1672 }
1673 if (crcs) {
1674 u32 cntr = dd->cspec->lli_counter;
1675 cntr += crcs;
1676 if (cntr) {
1677 if (cntr > dd->cspec->lli_thresh) {
1678 dd->cspec->lli_counter = 0;
1679 dd->cspec->lli_errs++;
1680 } else
1681 dd->cspec->lli_counter += cntr;
1682 }
1683 }
1684
1685
1686 if (ctxtrbits) {
1687 ctxtrbits =
1688 (ctxtrbits >> QLOGIC_IB_I_RCVAVAIL_SHIFT) |
1689 (ctxtrbits >> QLOGIC_IB_I_RCVURG_SHIFT);
1690 qib_handle_urcv(dd, ctxtrbits);
1691 }
1692 }
1693
1694 if ((istat & QLOGIC_IB_I_SPIOBUFAVAIL) && (dd->flags & QIB_INITTED))
1695 qib_ib_piobufavail(dd);
1696
1697 ret = IRQ_HANDLED;
1698bail:
1699 return ret;
1700}
1701
1702
1703
1704
1705
1706
1707static void qib_setup_6120_interrupt(struct qib_devdata *dd)
1708{
1709
1710
1711
1712
1713
1714
1715 if (SYM_FIELD(dd->revision, Revision_R,
1716 ChipRevMinor) > 1) {
1717
1718 dd->cspec->gpio_mask |= GPIO_ERRINTR_MASK;
1719 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
1720 }
1721
1722 if (!dd->cspec->irq)
1723 qib_dev_err(dd,
1724 "irq is 0, BIOS error? Interrupts won't work\n");
1725 else {
1726 int ret;
1727 ret = request_irq(dd->cspec->irq, qib_6120intr, 0,
1728 QIB_DRV_NAME, dd);
1729 if (ret)
1730 qib_dev_err(dd,
1731 "Couldn't setup interrupt (irq=%d): %d\n",
1732 dd->cspec->irq, ret);
1733 }
1734}
1735
1736
1737
1738
1739
1740
1741
1742static void pe_boardname(struct qib_devdata *dd)
1743{
1744 char *n;
1745 u32 boardid, namelen;
1746
1747 boardid = SYM_FIELD(dd->revision, Revision,
1748 BoardID);
1749
1750 switch (boardid) {
1751 case 2:
1752 n = "InfiniPath_QLE7140";
1753 break;
1754 default:
1755 qib_dev_err(dd, "Unknown 6120 board with ID %u\n", boardid);
1756 n = "Unknown_InfiniPath_6120";
1757 break;
1758 }
1759 namelen = strlen(n) + 1;
1760 dd->boardname = kmalloc(namelen, GFP_KERNEL);
1761 if (!dd->boardname)
1762 qib_dev_err(dd, "Failed allocation for board name: %s\n", n);
1763 else
1764 snprintf(dd->boardname, namelen, "%s", n);
1765
1766 if (dd->majrev != 4 || !dd->minrev || dd->minrev > 2)
1767 qib_dev_err(dd,
1768 "Unsupported InfiniPath hardware revision %u.%u!\n",
1769 dd->majrev, dd->minrev);
1770
1771 snprintf(dd->boardversion, sizeof(dd->boardversion),
1772 "ChipABI %u.%u, %s, InfiniPath%u %u.%u, SW Compat %u\n",
1773 QIB_CHIP_VERS_MAJ, QIB_CHIP_VERS_MIN, dd->boardname,
1774 (unsigned)SYM_FIELD(dd->revision, Revision_R, Arch),
1775 dd->majrev, dd->minrev,
1776 (unsigned)SYM_FIELD(dd->revision, Revision_R, SW));
1777
1778}
1779
1780
1781
1782
1783
1784
1785static int qib_6120_setup_reset(struct qib_devdata *dd)
1786{
1787 u64 val;
1788 int i;
1789 int ret;
1790 u16 cmdval;
1791 u8 int_line, clinesz;
1792
1793 qib_pcie_getcmd(dd, &cmdval, &int_line, &clinesz);
1794
1795
1796 qib_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->unit);
1797
1798
1799 qib_6120_set_intr_state(dd, 0);
1800
1801 dd->cspec->ibdeltainprog = 0;
1802 dd->cspec->ibsymdelta = 0;
1803 dd->cspec->iblnkerrdelta = 0;
1804
1805
1806
1807
1808
1809
1810 dd->flags &= ~(QIB_INITTED | QIB_PRESENT);
1811 dd->int_counter = 0;
1812 val = dd->control | QLOGIC_IB_C_RESET;
1813 writeq(val, &dd->kregbase[kr_control]);
1814 mb();
1815
1816 for (i = 1; i <= 5; i++) {
1817
1818
1819
1820
1821
1822 msleep(1000 + (1 + i) * 2000);
1823
1824 qib_pcie_reenable(dd, cmdval, int_line, clinesz);
1825
1826
1827
1828
1829
1830 val = readq(&dd->kregbase[kr_revision]);
1831 if (val == dd->revision) {
1832 dd->flags |= QIB_PRESENT;
1833 ret = qib_reinit_intr(dd);
1834 goto bail;
1835 }
1836 }
1837 ret = 0;
1838
1839bail:
1840 if (ret) {
1841 if (qib_pcie_params(dd, dd->lbus_width, NULL, NULL))
1842 qib_dev_err(dd,
1843 "Reset failed to setup PCIe or interrupts; continuing anyway\n");
1844
1845 qib_6120_init_hwerrors(dd);
1846
1847 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
1848
1849 qib_6120_init_hwerrors(dd);
1850 }
1851 return ret;
1852}
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866static void qib_6120_put_tid(struct qib_devdata *dd, u64 __iomem *tidptr,
1867 u32 type, unsigned long pa)
1868{
1869 u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
1870 unsigned long flags;
1871 int tidx;
1872 spinlock_t *tidlockp;
1873
1874 if (!dd->kregbase)
1875 return;
1876
1877 if (pa != dd->tidinvalid) {
1878 if (pa & ((1U << 11) - 1)) {
1879 qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
1880 pa);
1881 return;
1882 }
1883 pa >>= 11;
1884 if (pa & ~QLOGIC_IB_RT_ADDR_MASK) {
1885 qib_dev_err(dd,
1886 "Physical page address 0x%lx larger than supported\n",
1887 pa);
1888 return;
1889 }
1890
1891 if (type == RCVHQ_RCV_TYPE_EAGER)
1892 pa |= dd->tidtemplate;
1893 else
1894 pa |= 2 << 29;
1895 }
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910 tidx = tidptr - dd->egrtidbase;
1911
1912 tidlockp = (type == RCVHQ_RCV_TYPE_EAGER && tidx < dd->rcvhdrcnt)
1913 ? &dd->cspec->kernel_tid_lock : &dd->cspec->user_tid_lock;
1914 spin_lock_irqsave(tidlockp, flags);
1915 qib_write_kreg(dd, kr_scratch, 0xfeeddeaf);
1916 writel(pa, tidp32);
1917 qib_write_kreg(dd, kr_scratch, 0xdeadbeef);
1918 mmiowb();
1919 spin_unlock_irqrestore(tidlockp, flags);
1920}
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934static void qib_6120_put_tid_2(struct qib_devdata *dd, u64 __iomem *tidptr,
1935 u32 type, unsigned long pa)
1936{
1937 u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
1938 u32 tidx;
1939
1940 if (!dd->kregbase)
1941 return;
1942
1943 if (pa != dd->tidinvalid) {
1944 if (pa & ((1U << 11) - 1)) {
1945 qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
1946 pa);
1947 return;
1948 }
1949 pa >>= 11;
1950 if (pa & ~QLOGIC_IB_RT_ADDR_MASK) {
1951 qib_dev_err(dd,
1952 "Physical page address 0x%lx larger than supported\n",
1953 pa);
1954 return;
1955 }
1956
1957 if (type == RCVHQ_RCV_TYPE_EAGER)
1958 pa |= dd->tidtemplate;
1959 else
1960 pa |= 2 << 29;
1961 }
1962 tidx = tidptr - dd->egrtidbase;
1963 writel(pa, tidp32);
1964 mmiowb();
1965}
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978static void qib_6120_clear_tids(struct qib_devdata *dd,
1979 struct qib_ctxtdata *rcd)
1980{
1981 u64 __iomem *tidbase;
1982 unsigned long tidinv;
1983 u32 ctxt;
1984 int i;
1985
1986 if (!dd->kregbase || !rcd)
1987 return;
1988
1989 ctxt = rcd->ctxt;
1990
1991 tidinv = dd->tidinvalid;
1992 tidbase = (u64 __iomem *)
1993 ((char __iomem *)(dd->kregbase) +
1994 dd->rcvtidbase +
1995 ctxt * dd->rcvtidcnt * sizeof(*tidbase));
1996
1997 for (i = 0; i < dd->rcvtidcnt; i++)
1998
1999 dd->f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
2000 tidinv);
2001
2002 tidbase = (u64 __iomem *)
2003 ((char __iomem *)(dd->kregbase) +
2004 dd->rcvegrbase +
2005 rcd->rcvegr_tid_base * sizeof(*tidbase));
2006
2007 for (i = 0; i < rcd->rcvegrcnt; i++)
2008
2009 dd->f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
2010 tidinv);
2011}
2012
2013
2014
2015
2016
2017
2018
2019static void qib_6120_tidtemplate(struct qib_devdata *dd)
2020{
2021 u32 egrsize = dd->rcvegrbufsize;
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032 if (egrsize == 2048)
2033 dd->tidtemplate = 1U << 29;
2034 else if (egrsize == 4096)
2035 dd->tidtemplate = 2U << 29;
2036 dd->tidinvalid = 0;
2037}
2038
2039int __attribute__((weak)) qib_unordered_wc(void)
2040{
2041 return 0;
2042}
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052static int qib_6120_get_base_info(struct qib_ctxtdata *rcd,
2053 struct qib_base_info *kinfo)
2054{
2055 if (qib_unordered_wc())
2056 kinfo->spi_runtime_flags |= QIB_RUNTIME_FORCE_WC_ORDER;
2057
2058 kinfo->spi_runtime_flags |= QIB_RUNTIME_PCIE |
2059 QIB_RUNTIME_FORCE_PIOAVAIL | QIB_RUNTIME_PIO_REGSWAPPED;
2060 return 0;
2061}
2062
2063
2064static struct qib_message_header *
2065qib_6120_get_msgheader(struct qib_devdata *dd, __le32 *rhf_addr)
2066{
2067 return (struct qib_message_header *)
2068 &rhf_addr[sizeof(u64) / sizeof(u32)];
2069}
2070
2071static void qib_6120_config_ctxts(struct qib_devdata *dd)
2072{
2073 dd->ctxtcnt = qib_read_kreg32(dd, kr_portcnt);
2074 if (qib_n_krcv_queues > 1) {
2075 dd->first_user_ctxt = qib_n_krcv_queues * dd->num_pports;
2076 if (dd->first_user_ctxt > dd->ctxtcnt)
2077 dd->first_user_ctxt = dd->ctxtcnt;
2078 dd->qpn_mask = dd->first_user_ctxt <= 2 ? 2 : 6;
2079 } else
2080 dd->first_user_ctxt = dd->num_pports;
2081 dd->n_krcv_queues = dd->first_user_ctxt;
2082}
2083
2084static void qib_update_6120_usrhead(struct qib_ctxtdata *rcd, u64 hd,
2085 u32 updegr, u32 egrhd, u32 npkts)
2086{
2087 if (updegr)
2088 qib_write_ureg(rcd->dd, ur_rcvegrindexhead, egrhd, rcd->ctxt);
2089 mmiowb();
2090 qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
2091 mmiowb();
2092}
2093
2094static u32 qib_6120_hdrqempty(struct qib_ctxtdata *rcd)
2095{
2096 u32 head, tail;
2097
2098 head = qib_read_ureg32(rcd->dd, ur_rcvhdrhead, rcd->ctxt);
2099 if (rcd->rcvhdrtail_kvaddr)
2100 tail = qib_get_rcvhdrtail(rcd);
2101 else
2102 tail = qib_read_ureg32(rcd->dd, ur_rcvhdrtail, rcd->ctxt);
2103 return head == tail;
2104}
2105
2106
2107
2108
2109
2110
2111static void alloc_dummy_hdrq(struct qib_devdata *dd)
2112{
2113 dd->cspec->dummy_hdrq = dma_alloc_coherent(&dd->pcidev->dev,
2114 dd->rcd[0]->rcvhdrq_size,
2115 &dd->cspec->dummy_hdrq_phys,
2116 GFP_ATOMIC | __GFP_COMP);
2117 if (!dd->cspec->dummy_hdrq) {
2118 qib_devinfo(dd->pcidev, "Couldn't allocate dummy hdrq\n");
2119
2120 dd->cspec->dummy_hdrq_phys = 0UL;
2121 }
2122}
2123
2124
2125
2126
2127
2128
2129
2130
2131static void rcvctrl_6120_mod(struct qib_pportdata *ppd, unsigned int op,
2132 int ctxt)
2133{
2134 struct qib_devdata *dd = ppd->dd;
2135 u64 mask, val;
2136 unsigned long flags;
2137
2138 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
2139
2140 if (op & QIB_RCVCTRL_TAILUPD_ENB)
2141 dd->rcvctrl |= (1ULL << QLOGIC_IB_R_TAILUPD_SHIFT);
2142 if (op & QIB_RCVCTRL_TAILUPD_DIS)
2143 dd->rcvctrl &= ~(1ULL << QLOGIC_IB_R_TAILUPD_SHIFT);
2144 if (op & QIB_RCVCTRL_PKEY_ENB)
2145 dd->rcvctrl &= ~(1ULL << IBA6120_R_PKEY_DIS_SHIFT);
2146 if (op & QIB_RCVCTRL_PKEY_DIS)
2147 dd->rcvctrl |= (1ULL << IBA6120_R_PKEY_DIS_SHIFT);
2148 if (ctxt < 0)
2149 mask = (1ULL << dd->ctxtcnt) - 1;
2150 else
2151 mask = (1ULL << ctxt);
2152 if (op & QIB_RCVCTRL_CTXT_ENB) {
2153
2154 dd->rcvctrl |= (mask << SYM_LSB(RcvCtrl, PortEnable));
2155 if (!(dd->flags & QIB_NODMA_RTAIL))
2156 dd->rcvctrl |= 1ULL << QLOGIC_IB_R_TAILUPD_SHIFT;
2157
2158 qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr, ctxt,
2159 dd->rcd[ctxt]->rcvhdrqtailaddr_phys);
2160 qib_write_kreg_ctxt(dd, kr_rcvhdraddr, ctxt,
2161 dd->rcd[ctxt]->rcvhdrq_phys);
2162
2163 if (ctxt == 0 && !dd->cspec->dummy_hdrq)
2164 alloc_dummy_hdrq(dd);
2165 }
2166 if (op & QIB_RCVCTRL_CTXT_DIS)
2167 dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, PortEnable));
2168 if (op & QIB_RCVCTRL_INTRAVAIL_ENB)
2169 dd->rcvctrl |= (mask << QLOGIC_IB_R_INTRAVAIL_SHIFT);
2170 if (op & QIB_RCVCTRL_INTRAVAIL_DIS)
2171 dd->rcvctrl &= ~(mask << QLOGIC_IB_R_INTRAVAIL_SHIFT);
2172 qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
2173 if ((op & QIB_RCVCTRL_INTRAVAIL_ENB) && dd->rhdrhead_intr_off) {
2174
2175 val = qib_read_ureg32(dd, ur_rcvhdrhead, ctxt) |
2176 dd->rhdrhead_intr_off;
2177 qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
2178 }
2179 if (op & QIB_RCVCTRL_CTXT_ENB) {
2180
2181
2182
2183
2184
2185
2186 val = qib_read_ureg32(dd, ur_rcvegrindextail, ctxt);
2187 qib_write_ureg(dd, ur_rcvegrindexhead, val, ctxt);
2188
2189 val = qib_read_ureg32(dd, ur_rcvhdrtail, ctxt);
2190 dd->rcd[ctxt]->head = val;
2191
2192 if (ctxt < dd->first_user_ctxt)
2193 val |= dd->rhdrhead_intr_off;
2194 qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
2195 }
2196 if (op & QIB_RCVCTRL_CTXT_DIS) {
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206 if (ctxt >= 0) {
2207 qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr, ctxt,
2208 dd->cspec->dummy_hdrq_phys);
2209 qib_write_kreg_ctxt(dd, kr_rcvhdraddr, ctxt,
2210 dd->cspec->dummy_hdrq_phys);
2211 } else {
2212 unsigned i;
2213
2214 for (i = 0; i < dd->cfgctxts; i++) {
2215 qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr,
2216 i, dd->cspec->dummy_hdrq_phys);
2217 qib_write_kreg_ctxt(dd, kr_rcvhdraddr,
2218 i, dd->cspec->dummy_hdrq_phys);
2219 }
2220 }
2221 }
2222 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
2223}
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233static void sendctrl_6120_mod(struct qib_pportdata *ppd, u32 op)
2234{
2235 struct qib_devdata *dd = ppd->dd;
2236 u64 tmp_dd_sendctrl;
2237 unsigned long flags;
2238
2239 spin_lock_irqsave(&dd->sendctrl_lock, flags);
2240
2241
2242 if (op & QIB_SENDCTRL_CLEAR)
2243 dd->sendctrl = 0;
2244 if (op & QIB_SENDCTRL_SEND_DIS)
2245 dd->sendctrl &= ~SYM_MASK(SendCtrl, PIOEnable);
2246 else if (op & QIB_SENDCTRL_SEND_ENB)
2247 dd->sendctrl |= SYM_MASK(SendCtrl, PIOEnable);
2248 if (op & QIB_SENDCTRL_AVAIL_DIS)
2249 dd->sendctrl &= ~SYM_MASK(SendCtrl, PIOBufAvailUpd);
2250 else if (op & QIB_SENDCTRL_AVAIL_ENB)
2251 dd->sendctrl |= SYM_MASK(SendCtrl, PIOBufAvailUpd);
2252
2253 if (op & QIB_SENDCTRL_DISARM_ALL) {
2254 u32 i, last;
2255
2256 tmp_dd_sendctrl = dd->sendctrl;
2257
2258
2259
2260
2261 last = dd->piobcnt2k + dd->piobcnt4k;
2262 tmp_dd_sendctrl &=
2263 ~(SYM_MASK(SendCtrl, PIOEnable) |
2264 SYM_MASK(SendCtrl, PIOBufAvailUpd));
2265 for (i = 0; i < last; i++) {
2266 qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl |
2267 SYM_MASK(SendCtrl, Disarm) | i);
2268 qib_write_kreg(dd, kr_scratch, 0);
2269 }
2270 }
2271
2272 tmp_dd_sendctrl = dd->sendctrl;
2273
2274 if (op & QIB_SENDCTRL_FLUSH)
2275 tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Abort);
2276 if (op & QIB_SENDCTRL_DISARM)
2277 tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Disarm) |
2278 ((op & QIB_6120_SendCtrl_DisarmPIOBuf_RMASK) <<
2279 SYM_LSB(SendCtrl, DisarmPIOBuf));
2280 if (op & QIB_SENDCTRL_AVAIL_BLIP)
2281 tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, PIOBufAvailUpd);
2282
2283 qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl);
2284 qib_write_kreg(dd, kr_scratch, 0);
2285
2286 if (op & QIB_SENDCTRL_AVAIL_BLIP) {
2287 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
2288 qib_write_kreg(dd, kr_scratch, 0);
2289 }
2290
2291 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
2292
2293 if (op & QIB_SENDCTRL_FLUSH) {
2294 u32 v;
2295
2296
2297
2298
2299
2300
2301 v = qib_read_kreg32(dd, kr_scratch);
2302 qib_write_kreg(dd, kr_scratch, v);
2303 v = qib_read_kreg32(dd, kr_scratch);
2304 qib_write_kreg(dd, kr_scratch, v);
2305 qib_read_kreg32(dd, kr_scratch);
2306 }
2307}
2308
2309
2310
2311
2312
2313
2314static u64 qib_portcntr_6120(struct qib_pportdata *ppd, u32 reg)
2315{
2316 u64 ret = 0ULL;
2317 struct qib_devdata *dd = ppd->dd;
2318 u16 creg;
2319
2320 static const u16 xlator[] = {
2321 [QIBPORTCNTR_PKTSEND] = cr_pktsend,
2322 [QIBPORTCNTR_WORDSEND] = cr_wordsend,
2323 [QIBPORTCNTR_PSXMITDATA] = 0xffff,
2324 [QIBPORTCNTR_PSXMITPKTS] = 0xffff,
2325 [QIBPORTCNTR_PSXMITWAIT] = 0xffff,
2326 [QIBPORTCNTR_SENDSTALL] = cr_sendstall,
2327 [QIBPORTCNTR_PKTRCV] = cr_pktrcv,
2328 [QIBPORTCNTR_PSRCVDATA] = 0xffff,
2329 [QIBPORTCNTR_PSRCVPKTS] = 0xffff,
2330 [QIBPORTCNTR_RCVEBP] = cr_rcvebp,
2331 [QIBPORTCNTR_RCVOVFL] = cr_rcvovfl,
2332 [QIBPORTCNTR_WORDRCV] = cr_wordrcv,
2333 [QIBPORTCNTR_RXDROPPKT] = cr_rxdroppkt,
2334 [QIBPORTCNTR_RXLOCALPHYERR] = 0xffff,
2335 [QIBPORTCNTR_RXVLERR] = 0xffff,
2336 [QIBPORTCNTR_ERRICRC] = cr_erricrc,
2337 [QIBPORTCNTR_ERRVCRC] = cr_errvcrc,
2338 [QIBPORTCNTR_ERRLPCRC] = cr_errlpcrc,
2339 [QIBPORTCNTR_BADFORMAT] = cr_badformat,
2340 [QIBPORTCNTR_ERR_RLEN] = cr_err_rlen,
2341 [QIBPORTCNTR_IBSYMBOLERR] = cr_ibsymbolerr,
2342 [QIBPORTCNTR_INVALIDRLEN] = cr_invalidrlen,
2343 [QIBPORTCNTR_UNSUPVL] = cr_txunsupvl,
2344 [QIBPORTCNTR_EXCESSBUFOVFL] = 0xffff,
2345 [QIBPORTCNTR_ERRLINK] = cr_errlink,
2346 [QIBPORTCNTR_IBLINKDOWN] = cr_iblinkdown,
2347 [QIBPORTCNTR_IBLINKERRRECOV] = cr_iblinkerrrecov,
2348 [QIBPORTCNTR_LLI] = 0xffff,
2349 [QIBPORTCNTR_PSINTERVAL] = 0xffff,
2350 [QIBPORTCNTR_PSSTART] = 0xffff,
2351 [QIBPORTCNTR_PSSTAT] = 0xffff,
2352 [QIBPORTCNTR_VL15PKTDROP] = 0xffff,
2353 [QIBPORTCNTR_ERRPKEY] = cr_errpkey,
2354 [QIBPORTCNTR_KHDROVFL] = 0xffff,
2355 };
2356
2357 if (reg >= ARRAY_SIZE(xlator)) {
2358 qib_devinfo(ppd->dd->pcidev,
2359 "Unimplemented portcounter %u\n", reg);
2360 goto done;
2361 }
2362 creg = xlator[reg];
2363
2364
2365 if (reg == QIBPORTCNTR_LLI)
2366 ret = dd->cspec->lli_errs;
2367 else if (reg == QIBPORTCNTR_EXCESSBUFOVFL)
2368 ret = dd->cspec->overrun_thresh_errs;
2369 else if (reg == QIBPORTCNTR_KHDROVFL) {
2370 int i;
2371
2372
2373 for (i = 0; i < dd->first_user_ctxt; i++)
2374 ret += read_6120_creg32(dd, cr_portovfl + i);
2375 } else if (reg == QIBPORTCNTR_PSSTAT)
2376 ret = dd->cspec->pma_sample_status;
2377 if (creg == 0xffff)
2378 goto done;
2379
2380
2381
2382
2383
2384 if (creg == cr_wordsend || creg == cr_wordrcv ||
2385 creg == cr_pktsend || creg == cr_pktrcv)
2386 ret = read_6120_creg(dd, creg);
2387 else
2388 ret = read_6120_creg32(dd, creg);
2389 if (creg == cr_ibsymbolerr) {
2390 if (dd->cspec->ibdeltainprog)
2391 ret -= ret - dd->cspec->ibsymsnap;
2392 ret -= dd->cspec->ibsymdelta;
2393 } else if (creg == cr_iblinkerrrecov) {
2394 if (dd->cspec->ibdeltainprog)
2395 ret -= ret - dd->cspec->iblnkerrsnap;
2396 ret -= dd->cspec->iblnkerrdelta;
2397 }
2398 if (reg == QIBPORTCNTR_RXDROPPKT)
2399 ret += dd->cspec->rxfc_unsupvl_errs;
2400
2401done:
2402 return ret;
2403}
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418static const char cntr6120names[] =
2419 "Interrupts\n"
2420 "HostBusStall\n"
2421 "E RxTIDFull\n"
2422 "RxTIDInvalid\n"
2423 "Ctxt0EgrOvfl\n"
2424 "Ctxt1EgrOvfl\n"
2425 "Ctxt2EgrOvfl\n"
2426 "Ctxt3EgrOvfl\n"
2427 "Ctxt4EgrOvfl\n";
2428
2429static const size_t cntr6120indices[] = {
2430 cr_lbint,
2431 cr_lbflowstall,
2432 cr_errtidfull,
2433 cr_errtidvalid,
2434 cr_portovfl + 0,
2435 cr_portovfl + 1,
2436 cr_portovfl + 2,
2437 cr_portovfl + 3,
2438 cr_portovfl + 4,
2439};
2440
2441
2442
2443
2444
2445
2446static const char portcntr6120names[] =
2447 "TxPkt\n"
2448 "TxFlowPkt\n"
2449 "TxWords\n"
2450 "RxPkt\n"
2451 "RxFlowPkt\n"
2452 "RxWords\n"
2453 "TxFlowStall\n"
2454 "E IBStatusChng\n"
2455 "IBLinkDown\n"
2456 "IBLnkRecov\n"
2457 "IBRxLinkErr\n"
2458 "IBSymbolErr\n"
2459 "RxLLIErr\n"
2460 "RxBadFormat\n"
2461 "RxBadLen\n"
2462 "RxBufOvrfl\n"
2463 "RxEBP\n"
2464 "RxFlowCtlErr\n"
2465 "RxICRCerr\n"
2466 "RxLPCRCerr\n"
2467 "RxVCRCerr\n"
2468 "RxInvalLen\n"
2469 "RxInvalPKey\n"
2470 "RxPktDropped\n"
2471 "TxBadLength\n"
2472 "TxDropped\n"
2473 "TxInvalLen\n"
2474 "TxUnderrun\n"
2475 "TxUnsupVL\n"
2476 ;
2477
2478#define _PORT_VIRT_FLAG 0x8000
2479static const size_t portcntr6120indices[] = {
2480 QIBPORTCNTR_PKTSEND | _PORT_VIRT_FLAG,
2481 cr_pktsendflow,
2482 QIBPORTCNTR_WORDSEND | _PORT_VIRT_FLAG,
2483 QIBPORTCNTR_PKTRCV | _PORT_VIRT_FLAG,
2484 cr_pktrcvflowctrl,
2485 QIBPORTCNTR_WORDRCV | _PORT_VIRT_FLAG,
2486 QIBPORTCNTR_SENDSTALL | _PORT_VIRT_FLAG,
2487 cr_ibstatuschange,
2488 QIBPORTCNTR_IBLINKDOWN | _PORT_VIRT_FLAG,
2489 QIBPORTCNTR_IBLINKERRRECOV | _PORT_VIRT_FLAG,
2490 QIBPORTCNTR_ERRLINK | _PORT_VIRT_FLAG,
2491 QIBPORTCNTR_IBSYMBOLERR | _PORT_VIRT_FLAG,
2492 QIBPORTCNTR_LLI | _PORT_VIRT_FLAG,
2493 QIBPORTCNTR_BADFORMAT | _PORT_VIRT_FLAG,
2494 QIBPORTCNTR_ERR_RLEN | _PORT_VIRT_FLAG,
2495 QIBPORTCNTR_RCVOVFL | _PORT_VIRT_FLAG,
2496 QIBPORTCNTR_RCVEBP | _PORT_VIRT_FLAG,
2497 cr_rcvflowctrl_err,
2498 QIBPORTCNTR_ERRICRC | _PORT_VIRT_FLAG,
2499 QIBPORTCNTR_ERRLPCRC | _PORT_VIRT_FLAG,
2500 QIBPORTCNTR_ERRVCRC | _PORT_VIRT_FLAG,
2501 QIBPORTCNTR_INVALIDRLEN | _PORT_VIRT_FLAG,
2502 QIBPORTCNTR_ERRPKEY | _PORT_VIRT_FLAG,
2503 QIBPORTCNTR_RXDROPPKT | _PORT_VIRT_FLAG,
2504 cr_invalidslen,
2505 cr_senddropped,
2506 cr_errslen,
2507 cr_sendunderrun,
2508 cr_txunsupvl,
2509};
2510
2511
2512static void init_6120_cntrnames(struct qib_devdata *dd)
2513{
2514 int i, j = 0;
2515 char *s;
2516
2517 for (i = 0, s = (char *)cntr6120names; s && j <= dd->cfgctxts;
2518 i++) {
2519
2520 if (!j && !strncmp("Ctxt0EgrOvfl", s + 1, 12))
2521 j = 1;
2522 s = strchr(s + 1, '\n');
2523 if (s && j)
2524 j++;
2525 }
2526 dd->cspec->ncntrs = i;
2527 if (!s)
2528
2529 dd->cspec->cntrnamelen = sizeof(cntr6120names) - 1;
2530 else
2531 dd->cspec->cntrnamelen = 1 + s - cntr6120names;
2532 dd->cspec->cntrs = kmalloc(dd->cspec->ncntrs
2533 * sizeof(u64), GFP_KERNEL);
2534 if (!dd->cspec->cntrs)
2535 qib_dev_err(dd, "Failed allocation for counters\n");
2536
2537 for (i = 0, s = (char *)portcntr6120names; s; i++)
2538 s = strchr(s + 1, '\n');
2539 dd->cspec->nportcntrs = i - 1;
2540 dd->cspec->portcntrnamelen = sizeof(portcntr6120names) - 1;
2541 dd->cspec->portcntrs = kmalloc(dd->cspec->nportcntrs
2542 * sizeof(u64), GFP_KERNEL);
2543 if (!dd->cspec->portcntrs)
2544 qib_dev_err(dd, "Failed allocation for portcounters\n");
2545}
2546
2547static u32 qib_read_6120cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
2548 u64 **cntrp)
2549{
2550 u32 ret;
2551
2552 if (namep) {
2553 ret = dd->cspec->cntrnamelen;
2554 if (pos >= ret)
2555 ret = 0;
2556 else
2557 *namep = (char *)cntr6120names;
2558 } else {
2559 u64 *cntr = dd->cspec->cntrs;
2560 int i;
2561
2562 ret = dd->cspec->ncntrs * sizeof(u64);
2563 if (!cntr || pos >= ret) {
2564
2565 ret = 0;
2566 goto done;
2567 }
2568 if (pos >= ret) {
2569 ret = 0;
2570 goto done;
2571 }
2572 *cntrp = cntr;
2573 for (i = 0; i < dd->cspec->ncntrs; i++)
2574 *cntr++ = read_6120_creg32(dd, cntr6120indices[i]);
2575 }
2576done:
2577 return ret;
2578}
2579
2580static u32 qib_read_6120portcntrs(struct qib_devdata *dd, loff_t pos, u32 port,
2581 char **namep, u64 **cntrp)
2582{
2583 u32 ret;
2584
2585 if (namep) {
2586 ret = dd->cspec->portcntrnamelen;
2587 if (pos >= ret)
2588 ret = 0;
2589 else
2590 *namep = (char *)portcntr6120names;
2591 } else {
2592 u64 *cntr = dd->cspec->portcntrs;
2593 struct qib_pportdata *ppd = &dd->pport[port];
2594 int i;
2595
2596 ret = dd->cspec->nportcntrs * sizeof(u64);
2597 if (!cntr || pos >= ret) {
2598
2599 ret = 0;
2600 goto done;
2601 }
2602 *cntrp = cntr;
2603 for (i = 0; i < dd->cspec->nportcntrs; i++) {
2604 if (portcntr6120indices[i] & _PORT_VIRT_FLAG)
2605 *cntr++ = qib_portcntr_6120(ppd,
2606 portcntr6120indices[i] &
2607 ~_PORT_VIRT_FLAG);
2608 else
2609 *cntr++ = read_6120_creg32(dd,
2610 portcntr6120indices[i]);
2611 }
2612 }
2613done:
2614 return ret;
2615}
2616
2617static void qib_chk_6120_errormask(struct qib_devdata *dd)
2618{
2619 static u32 fixed;
2620 u32 ctrl;
2621 unsigned long errormask;
2622 unsigned long hwerrs;
2623
2624 if (!dd->cspec->errormask || !(dd->flags & QIB_INITTED))
2625 return;
2626
2627 errormask = qib_read_kreg64(dd, kr_errmask);
2628
2629 if (errormask == dd->cspec->errormask)
2630 return;
2631 fixed++;
2632
2633 hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
2634 ctrl = qib_read_kreg32(dd, kr_control);
2635
2636 qib_write_kreg(dd, kr_errmask,
2637 dd->cspec->errormask);
2638
2639 if ((hwerrs & dd->cspec->hwerrmask) ||
2640 (ctrl & QLOGIC_IB_C_FREEZEMODE)) {
2641 qib_write_kreg(dd, kr_hwerrclear, 0ULL);
2642 qib_write_kreg(dd, kr_errclear, 0ULL);
2643
2644 qib_write_kreg(dd, kr_intclear, 0ULL);
2645 qib_devinfo(dd->pcidev,
2646 "errormask fixed(%u) %lx->%lx, ctrl %x hwerr %lx\n",
2647 fixed, errormask, (unsigned long)dd->cspec->errormask,
2648 ctrl, hwerrs);
2649 }
2650}
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660static void qib_get_6120_faststats(unsigned long opaque)
2661{
2662 struct qib_devdata *dd = (struct qib_devdata *) opaque;
2663 struct qib_pportdata *ppd = dd->pport;
2664 unsigned long flags;
2665 u64 traffic_wds;
2666
2667
2668
2669
2670
2671 if (!(dd->flags & QIB_INITTED) || dd->diag_client)
2672
2673 goto done;
2674
2675
2676
2677
2678
2679
2680 traffic_wds = qib_portcntr_6120(ppd, cr_wordsend) +
2681 qib_portcntr_6120(ppd, cr_wordrcv);
2682 spin_lock_irqsave(&dd->eep_st_lock, flags);
2683 traffic_wds -= dd->traffic_wds;
2684 dd->traffic_wds += traffic_wds;
2685 if (traffic_wds >= QIB_TRAFFIC_ACTIVE_THRESHOLD)
2686 atomic_add(5, &dd->active_time);
2687 spin_unlock_irqrestore(&dd->eep_st_lock, flags);
2688
2689 qib_chk_6120_errormask(dd);
2690done:
2691 mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);
2692}
2693
2694
2695static int qib_6120_nointr_fallback(struct qib_devdata *dd)
2696{
2697 return 0;
2698}
2699
2700
2701
2702
2703
2704
2705
2706static void qib_6120_xgxs_reset(struct qib_pportdata *ppd)
2707{
2708 u64 val, prev_val;
2709 struct qib_devdata *dd = ppd->dd;
2710
2711 prev_val = qib_read_kreg64(dd, kr_xgxs_cfg);
2712 val = prev_val | QLOGIC_IB_XGXS_RESET;
2713 prev_val &= ~QLOGIC_IB_XGXS_RESET;
2714 qib_write_kreg(dd, kr_control,
2715 dd->control & ~QLOGIC_IB_C_LINKENABLE);
2716 qib_write_kreg(dd, kr_xgxs_cfg, val);
2717 qib_read_kreg32(dd, kr_scratch);
2718 qib_write_kreg(dd, kr_xgxs_cfg, prev_val);
2719 qib_write_kreg(dd, kr_control, dd->control);
2720}
2721
2722static int qib_6120_get_ib_cfg(struct qib_pportdata *ppd, int which)
2723{
2724 int ret;
2725
2726 switch (which) {
2727 case QIB_IB_CFG_LWID:
2728 ret = ppd->link_width_active;
2729 break;
2730
2731 case QIB_IB_CFG_SPD:
2732 ret = ppd->link_speed_active;
2733 break;
2734
2735 case QIB_IB_CFG_LWID_ENB:
2736 ret = ppd->link_width_enabled;
2737 break;
2738
2739 case QIB_IB_CFG_SPD_ENB:
2740 ret = ppd->link_speed_enabled;
2741 break;
2742
2743 case QIB_IB_CFG_OP_VLS:
2744 ret = ppd->vls_operational;
2745 break;
2746
2747 case QIB_IB_CFG_VL_HIGH_CAP:
2748 ret = 0;
2749 break;
2750
2751 case QIB_IB_CFG_VL_LOW_CAP:
2752 ret = 0;
2753 break;
2754
2755 case QIB_IB_CFG_OVERRUN_THRESH:
2756 ret = SYM_FIELD(ppd->dd->cspec->ibcctrl, IBCCtrl,
2757 OverrunThreshold);
2758 break;
2759
2760 case QIB_IB_CFG_PHYERR_THRESH:
2761 ret = SYM_FIELD(ppd->dd->cspec->ibcctrl, IBCCtrl,
2762 PhyerrThreshold);
2763 break;
2764
2765 case QIB_IB_CFG_LINKDEFAULT:
2766
2767 ret = (ppd->dd->cspec->ibcctrl &
2768 SYM_MASK(IBCCtrl, LinkDownDefaultState)) ?
2769 IB_LINKINITCMD_SLEEP : IB_LINKINITCMD_POLL;
2770 break;
2771
2772 case QIB_IB_CFG_HRTBT:
2773 ret = 0;
2774 break;
2775
2776 case QIB_IB_CFG_PMA_TICKS:
2777 ret = 250;
2778 break;
2779
2780 default:
2781 ret = -EINVAL;
2782 break;
2783 }
2784 return ret;
2785}
2786
2787
2788
2789
2790static int qib_6120_set_ib_cfg(struct qib_pportdata *ppd, int which, u32 val)
2791{
2792 struct qib_devdata *dd = ppd->dd;
2793 int ret = 0;
2794 u64 val64;
2795 u16 lcmd, licmd;
2796
2797 switch (which) {
2798 case QIB_IB_CFG_LWID_ENB:
2799 ppd->link_width_enabled = val;
2800 break;
2801
2802 case QIB_IB_CFG_SPD_ENB:
2803 ppd->link_speed_enabled = val;
2804 break;
2805
2806 case QIB_IB_CFG_OVERRUN_THRESH:
2807 val64 = SYM_FIELD(dd->cspec->ibcctrl, IBCCtrl,
2808 OverrunThreshold);
2809 if (val64 != val) {
2810 dd->cspec->ibcctrl &=
2811 ~SYM_MASK(IBCCtrl, OverrunThreshold);
2812 dd->cspec->ibcctrl |= (u64) val <<
2813 SYM_LSB(IBCCtrl, OverrunThreshold);
2814 qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
2815 qib_write_kreg(dd, kr_scratch, 0);
2816 }
2817 break;
2818
2819 case QIB_IB_CFG_PHYERR_THRESH:
2820 val64 = SYM_FIELD(dd->cspec->ibcctrl, IBCCtrl,
2821 PhyerrThreshold);
2822 if (val64 != val) {
2823 dd->cspec->ibcctrl &=
2824 ~SYM_MASK(IBCCtrl, PhyerrThreshold);
2825 dd->cspec->ibcctrl |= (u64) val <<
2826 SYM_LSB(IBCCtrl, PhyerrThreshold);
2827 qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
2828 qib_write_kreg(dd, kr_scratch, 0);
2829 }
2830 break;
2831
2832 case QIB_IB_CFG_PKEYS:
2833 val64 = (u64) ppd->pkeys[0] | ((u64) ppd->pkeys[1] << 16) |
2834 ((u64) ppd->pkeys[2] << 32) |
2835 ((u64) ppd->pkeys[3] << 48);
2836 qib_write_kreg(dd, kr_partitionkey, val64);
2837 break;
2838
2839 case QIB_IB_CFG_LINKDEFAULT:
2840
2841 if (val == IB_LINKINITCMD_POLL)
2842 dd->cspec->ibcctrl &=
2843 ~SYM_MASK(IBCCtrl, LinkDownDefaultState);
2844 else
2845 dd->cspec->ibcctrl |=
2846 SYM_MASK(IBCCtrl, LinkDownDefaultState);
2847 qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
2848 qib_write_kreg(dd, kr_scratch, 0);
2849 break;
2850
2851 case QIB_IB_CFG_MTU:
2852
2853
2854
2855
2856
2857
2858
2859 val = (ppd->ibmaxlen >> 2) + 1;
2860 dd->cspec->ibcctrl &= ~SYM_MASK(IBCCtrl, MaxPktLen);
2861 dd->cspec->ibcctrl |= (u64)val <<
2862 SYM_LSB(IBCCtrl, MaxPktLen);
2863 qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
2864 qib_write_kreg(dd, kr_scratch, 0);
2865 break;
2866
2867 case QIB_IB_CFG_LSTATE:
2868 switch (val & 0xffff0000) {
2869 case IB_LINKCMD_DOWN:
2870 lcmd = QLOGIC_IB_IBCC_LINKCMD_DOWN;
2871 if (!dd->cspec->ibdeltainprog) {
2872 dd->cspec->ibdeltainprog = 1;
2873 dd->cspec->ibsymsnap =
2874 read_6120_creg32(dd, cr_ibsymbolerr);
2875 dd->cspec->iblnkerrsnap =
2876 read_6120_creg32(dd, cr_iblinkerrrecov);
2877 }
2878 break;
2879
2880 case IB_LINKCMD_ARMED:
2881 lcmd = QLOGIC_IB_IBCC_LINKCMD_ARMED;
2882 break;
2883
2884 case IB_LINKCMD_ACTIVE:
2885 lcmd = QLOGIC_IB_IBCC_LINKCMD_ACTIVE;
2886 break;
2887
2888 default:
2889 ret = -EINVAL;
2890 qib_dev_err(dd, "bad linkcmd req 0x%x\n", val >> 16);
2891 goto bail;
2892 }
2893 switch (val & 0xffff) {
2894 case IB_LINKINITCMD_NOP:
2895 licmd = 0;
2896 break;
2897
2898 case IB_LINKINITCMD_POLL:
2899 licmd = QLOGIC_IB_IBCC_LINKINITCMD_POLL;
2900 break;
2901
2902 case IB_LINKINITCMD_SLEEP:
2903 licmd = QLOGIC_IB_IBCC_LINKINITCMD_SLEEP;
2904 break;
2905
2906 case IB_LINKINITCMD_DISABLE:
2907 licmd = QLOGIC_IB_IBCC_LINKINITCMD_DISABLE;
2908 break;
2909
2910 default:
2911 ret = -EINVAL;
2912 qib_dev_err(dd, "bad linkinitcmd req 0x%x\n",
2913 val & 0xffff);
2914 goto bail;
2915 }
2916 qib_set_ib_6120_lstate(ppd, lcmd, licmd);
2917 goto bail;
2918
2919 case QIB_IB_CFG_HRTBT:
2920 ret = -EINVAL;
2921 break;
2922
2923 default:
2924 ret = -EINVAL;
2925 }
2926bail:
2927 return ret;
2928}
2929
2930static int qib_6120_set_loopback(struct qib_pportdata *ppd, const char *what)
2931{
2932 int ret = 0;
2933 if (!strncmp(what, "ibc", 3)) {
2934 ppd->dd->cspec->ibcctrl |= SYM_MASK(IBCCtrl, Loopback);
2935 qib_devinfo(ppd->dd->pcidev, "Enabling IB%u:%u IBC loopback\n",
2936 ppd->dd->unit, ppd->port);
2937 } else if (!strncmp(what, "off", 3)) {
2938 ppd->dd->cspec->ibcctrl &= ~SYM_MASK(IBCCtrl, Loopback);
2939 qib_devinfo(ppd->dd->pcidev,
2940 "Disabling IB%u:%u IBC loopback (normal)\n",
2941 ppd->dd->unit, ppd->port);
2942 } else
2943 ret = -EINVAL;
2944 if (!ret) {
2945 qib_write_kreg(ppd->dd, kr_ibcctrl, ppd->dd->cspec->ibcctrl);
2946 qib_write_kreg(ppd->dd, kr_scratch, 0);
2947 }
2948 return ret;
2949}
2950
2951static void pma_6120_timer(unsigned long data)
2952{
2953 struct qib_pportdata *ppd = (struct qib_pportdata *)data;
2954 struct qib_chip_specific *cs = ppd->dd->cspec;
2955 struct qib_ibport *ibp = &ppd->ibport_data;
2956 unsigned long flags;
2957
2958 spin_lock_irqsave(&ibp->lock, flags);
2959 if (cs->pma_sample_status == IB_PMA_SAMPLE_STATUS_STARTED) {
2960 cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
2961 qib_snapshot_counters(ppd, &cs->sword, &cs->rword,
2962 &cs->spkts, &cs->rpkts, &cs->xmit_wait);
2963 mod_timer(&cs->pma_timer,
2964 jiffies + usecs_to_jiffies(ibp->pma_sample_interval));
2965 } else if (cs->pma_sample_status == IB_PMA_SAMPLE_STATUS_RUNNING) {
2966 u64 ta, tb, tc, td, te;
2967
2968 cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
2969 qib_snapshot_counters(ppd, &ta, &tb, &tc, &td, &te);
2970
2971 cs->sword = ta - cs->sword;
2972 cs->rword = tb - cs->rword;
2973 cs->spkts = tc - cs->spkts;
2974 cs->rpkts = td - cs->rpkts;
2975 cs->xmit_wait = te - cs->xmit_wait;
2976 }
2977 spin_unlock_irqrestore(&ibp->lock, flags);
2978}
2979
2980
2981
2982
2983static void qib_set_cntr_6120_sample(struct qib_pportdata *ppd, u32 intv,
2984 u32 start)
2985{
2986 struct qib_chip_specific *cs = ppd->dd->cspec;
2987
2988 if (start && intv) {
2989 cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_STARTED;
2990 mod_timer(&cs->pma_timer, jiffies + usecs_to_jiffies(start));
2991 } else if (intv) {
2992 cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
2993 qib_snapshot_counters(ppd, &cs->sword, &cs->rword,
2994 &cs->spkts, &cs->rpkts, &cs->xmit_wait);
2995 mod_timer(&cs->pma_timer, jiffies + usecs_to_jiffies(intv));
2996 } else {
2997 cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
2998 cs->sword = 0;
2999 cs->rword = 0;
3000 cs->spkts = 0;
3001 cs->rpkts = 0;
3002 cs->xmit_wait = 0;
3003 }
3004}
3005
3006static u32 qib_6120_iblink_state(u64 ibcs)
3007{
3008 u32 state = (u32)SYM_FIELD(ibcs, IBCStatus, LinkState);
3009
3010 switch (state) {
3011 case IB_6120_L_STATE_INIT:
3012 state = IB_PORT_INIT;
3013 break;
3014 case IB_6120_L_STATE_ARM:
3015 state = IB_PORT_ARMED;
3016 break;
3017 case IB_6120_L_STATE_ACTIVE:
3018
3019 case IB_6120_L_STATE_ACT_DEFER:
3020 state = IB_PORT_ACTIVE;
3021 break;
3022 default:
3023 case IB_6120_L_STATE_DOWN:
3024 state = IB_PORT_DOWN;
3025 break;
3026 }
3027 return state;
3028}
3029
3030
3031static u8 qib_6120_phys_portstate(u64 ibcs)
3032{
3033 u8 state = (u8)SYM_FIELD(ibcs, IBCStatus, LinkTrainingState);
3034 return qib_6120_physportstate[state];
3035}
3036
3037static int qib_6120_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
3038{
3039 unsigned long flags;
3040
3041 spin_lock_irqsave(&ppd->lflags_lock, flags);
3042 ppd->lflags &= ~QIBL_IB_FORCE_NOTIFY;
3043 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
3044
3045 if (ibup) {
3046 if (ppd->dd->cspec->ibdeltainprog) {
3047 ppd->dd->cspec->ibdeltainprog = 0;
3048 ppd->dd->cspec->ibsymdelta +=
3049 read_6120_creg32(ppd->dd, cr_ibsymbolerr) -
3050 ppd->dd->cspec->ibsymsnap;
3051 ppd->dd->cspec->iblnkerrdelta +=
3052 read_6120_creg32(ppd->dd, cr_iblinkerrrecov) -
3053 ppd->dd->cspec->iblnkerrsnap;
3054 }
3055 qib_hol_init(ppd);
3056 } else {
3057 ppd->dd->cspec->lli_counter = 0;
3058 if (!ppd->dd->cspec->ibdeltainprog) {
3059 ppd->dd->cspec->ibdeltainprog = 1;
3060 ppd->dd->cspec->ibsymsnap =
3061 read_6120_creg32(ppd->dd, cr_ibsymbolerr);
3062 ppd->dd->cspec->iblnkerrsnap =
3063 read_6120_creg32(ppd->dd, cr_iblinkerrrecov);
3064 }
3065 qib_hol_down(ppd);
3066 }
3067
3068 qib_6120_setup_setextled(ppd, ibup);
3069
3070 return 0;
3071}
3072
3073
3074
3075
3076
3077
3078
3079static int gpio_6120_mod(struct qib_devdata *dd, u32 out, u32 dir, u32 mask)
3080{
3081 u64 read_val, new_out;
3082 unsigned long flags;
3083
3084 if (mask) {
3085
3086 dir &= mask;
3087 out &= mask;
3088 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
3089 dd->cspec->extctrl &= ~((u64)mask << SYM_LSB(EXTCtrl, GPIOOe));
3090 dd->cspec->extctrl |= ((u64) dir << SYM_LSB(EXTCtrl, GPIOOe));
3091 new_out = (dd->cspec->gpio_out & ~mask) | out;
3092
3093 qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
3094 qib_write_kreg(dd, kr_gpio_out, new_out);
3095 dd->cspec->gpio_out = new_out;
3096 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
3097 }
3098
3099
3100
3101
3102
3103
3104
3105
3106 read_val = qib_read_kreg64(dd, kr_extstatus);
3107 return SYM_FIELD(read_val, EXTStatus, GPIOIn);
3108}
3109
3110
3111
3112
3113
3114
3115static void get_6120_chip_params(struct qib_devdata *dd)
3116{
3117 u64 val;
3118 u32 piobufs;
3119 int mtu;
3120
3121 dd->uregbase = qib_read_kreg32(dd, kr_userregbase);
3122
3123 dd->rcvtidcnt = qib_read_kreg32(dd, kr_rcvtidcnt);
3124 dd->rcvtidbase = qib_read_kreg32(dd, kr_rcvtidbase);
3125 dd->rcvegrbase = qib_read_kreg32(dd, kr_rcvegrbase);
3126 dd->palign = qib_read_kreg32(dd, kr_palign);
3127 dd->piobufbase = qib_read_kreg64(dd, kr_sendpiobufbase);
3128 dd->pio2k_bufbase = dd->piobufbase & 0xffffffff;
3129
3130 dd->rcvhdrcnt = qib_read_kreg32(dd, kr_rcvegrcnt);
3131
3132 val = qib_read_kreg64(dd, kr_sendpiosize);
3133 dd->piosize2k = val & ~0U;
3134 dd->piosize4k = val >> 32;
3135
3136 mtu = ib_mtu_enum_to_int(qib_ibmtu);
3137 if (mtu == -1)
3138 mtu = QIB_DEFAULT_MTU;
3139 dd->pport->ibmtu = (u32)mtu;
3140
3141 val = qib_read_kreg64(dd, kr_sendpiobufcnt);
3142 dd->piobcnt2k = val & ~0U;
3143 dd->piobcnt4k = val >> 32;
3144 dd->last_pio = dd->piobcnt4k + dd->piobcnt2k - 1;
3145
3146 dd->pio2kbase = (u32 __iomem *)
3147 (((char __iomem *)dd->kregbase) + dd->pio2k_bufbase);
3148 if (dd->piobcnt4k) {
3149 dd->pio4kbase = (u32 __iomem *)
3150 (((char __iomem *) dd->kregbase) +
3151 (dd->piobufbase >> 32));
3152
3153
3154
3155
3156
3157 dd->align4k = ALIGN(dd->piosize4k, dd->palign);
3158 }
3159
3160 piobufs = dd->piobcnt4k + dd->piobcnt2k;
3161
3162 dd->pioavregs = ALIGN(piobufs, sizeof(u64) * BITS_PER_BYTE / 2) /
3163 (sizeof(u64) * BITS_PER_BYTE / 2);
3164}
3165
3166
3167
3168
3169
3170
3171static void set_6120_baseaddrs(struct qib_devdata *dd)
3172{
3173 u32 cregbase;
3174 cregbase = qib_read_kreg32(dd, kr_counterregbase);
3175 dd->cspec->cregbase = (u64 __iomem *)
3176 ((char __iomem *) dd->kregbase + cregbase);
3177
3178 dd->egrtidbase = (u64 __iomem *)
3179 ((char __iomem *) dd->kregbase + dd->rcvegrbase);
3180}
3181
3182
3183
3184
3185
3186
3187static int qib_late_6120_initreg(struct qib_devdata *dd)
3188{
3189 int ret = 0;
3190 u64 val;
3191
3192 qib_write_kreg(dd, kr_rcvhdrentsize, dd->rcvhdrentsize);
3193 qib_write_kreg(dd, kr_rcvhdrsize, dd->rcvhdrsize);
3194 qib_write_kreg(dd, kr_rcvhdrcnt, dd->rcvhdrcnt);
3195 qib_write_kreg(dd, kr_sendpioavailaddr, dd->pioavailregs_phys);
3196 val = qib_read_kreg64(dd, kr_sendpioavailaddr);
3197 if (val != dd->pioavailregs_phys) {
3198 qib_dev_err(dd,
3199 "Catastrophic software error, SendPIOAvailAddr written as %lx, read back as %llx\n",
3200 (unsigned long) dd->pioavailregs_phys,
3201 (unsigned long long) val);
3202 ret = -EINVAL;
3203 }
3204 return ret;
3205}
3206
3207static int init_6120_variables(struct qib_devdata *dd)
3208{
3209 int ret = 0;
3210 struct qib_pportdata *ppd;
3211 u32 sbufs;
3212
3213 ppd = (struct qib_pportdata *)(dd + 1);
3214 dd->pport = ppd;
3215 dd->num_pports = 1;
3216
3217 dd->cspec = (struct qib_chip_specific *)(ppd + dd->num_pports);
3218 ppd->cpspec = NULL;
3219
3220 spin_lock_init(&dd->cspec->kernel_tid_lock);
3221 spin_lock_init(&dd->cspec->user_tid_lock);
3222 spin_lock_init(&dd->cspec->rcvmod_lock);
3223 spin_lock_init(&dd->cspec->gpio_lock);
3224
3225
3226 dd->revision = readq(&dd->kregbase[kr_revision]);
3227
3228 if ((dd->revision & 0xffffffffU) == 0xffffffffU) {
3229 qib_dev_err(dd,
3230 "Revision register read failure, giving up initialization\n");
3231 ret = -ENODEV;
3232 goto bail;
3233 }
3234 dd->flags |= QIB_PRESENT;
3235
3236 dd->majrev = (u8) SYM_FIELD(dd->revision, Revision_R,
3237 ChipRevMajor);
3238 dd->minrev = (u8) SYM_FIELD(dd->revision, Revision_R,
3239 ChipRevMinor);
3240
3241 get_6120_chip_params(dd);
3242 pe_boardname(dd);
3243
3244
3245
3246
3247
3248 dd->gpio_sda_num = _QIB_GPIO_SDA_NUM;
3249 dd->gpio_scl_num = _QIB_GPIO_SCL_NUM;
3250 dd->twsi_eeprom_dev = QIB_TWSI_NO_DEV;
3251
3252 if (qib_unordered_wc())
3253 dd->flags |= QIB_PIO_FLUSH_WC;
3254
3255
3256
3257
3258
3259 dd->eep_st_masks[0].hwerrs_to_log = HWE_MASK(TXEMemParityErr);
3260
3261
3262 if (qib_unordered_wc())
3263 dd->eep_st_masks[0].hwerrs_to_log &= ~TXE_PIO_PARITY;
3264
3265 dd->eep_st_masks[1].hwerrs_to_log = HWE_MASK(RXEMemParityErr);
3266
3267 dd->eep_st_masks[2].errs_to_log = ERR_MASK(ResetNegated);
3268
3269 qib_init_pportdata(ppd, dd, 0, 1);
3270 ppd->link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
3271 ppd->link_speed_supported = QIB_IB_SDR;
3272 ppd->link_width_enabled = IB_WIDTH_4X;
3273 ppd->link_speed_enabled = ppd->link_speed_supported;
3274
3275 ppd->link_width_active = ppd->link_width_enabled;
3276 ppd->link_speed_active = ppd->link_speed_enabled;
3277 ppd->vls_supported = IB_VL_VL0;
3278 ppd->vls_operational = ppd->vls_supported;
3279
3280 dd->rcvhdrentsize = QIB_RCVHDR_ENTSIZE;
3281 dd->rcvhdrsize = QIB_DFLT_RCVHDRSIZE;
3282 dd->rhf_offset = 0;
3283
3284
3285 ret = ib_mtu_enum_to_int(qib_ibmtu);
3286 dd->rcvegrbufsize = ret != -1 ? max(ret, 2048) : QIB_DEFAULT_MTU;
3287 BUG_ON(!is_power_of_2(dd->rcvegrbufsize));
3288 dd->rcvegrbufsize_shift = ilog2(dd->rcvegrbufsize);
3289
3290 qib_6120_tidtemplate(dd);
3291
3292
3293
3294
3295
3296
3297 dd->rhdrhead_intr_off = 1ULL << 32;
3298
3299
3300 init_timer(&dd->stats_timer);
3301 dd->stats_timer.function = qib_get_6120_faststats;
3302 dd->stats_timer.data = (unsigned long) dd;
3303
3304 init_timer(&dd->cspec->pma_timer);
3305 dd->cspec->pma_timer.function = pma_6120_timer;
3306 dd->cspec->pma_timer.data = (unsigned long) ppd;
3307
3308 dd->ureg_align = qib_read_kreg32(dd, kr_palign);
3309
3310 dd->piosize2kmax_dwords = dd->piosize2k >> 2;
3311 qib_6120_config_ctxts(dd);
3312 qib_set_ctxtcnt(dd);
3313
3314 if (qib_wc_pat) {
3315 ret = init_chip_wc_pat(dd, 0);
3316 if (ret)
3317 goto bail;
3318 }
3319 set_6120_baseaddrs(dd);
3320
3321 ret = 0;
3322 if (qib_mini_init)
3323 goto bail;
3324
3325 qib_num_cfg_vls = 1;
3326
3327 ret = qib_create_ctxts(dd);
3328 init_6120_cntrnames(dd);
3329
3330
3331 sbufs = dd->piobcnt4k ? dd->piobcnt4k : 16;
3332
3333 dd->lastctxt_piobuf = dd->piobcnt2k + dd->piobcnt4k - sbufs;
3334 dd->pbufsctxt = dd->lastctxt_piobuf /
3335 (dd->cfgctxts - dd->first_user_ctxt);
3336
3337 if (ret)
3338 goto bail;
3339bail:
3340 return ret;
3341}
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358static u32 __iomem *get_6120_link_buf(struct qib_pportdata *ppd, u32 *bnum)
3359{
3360 u32 __iomem *buf;
3361 u32 lbuf = ppd->dd->piobcnt2k + ppd->dd->piobcnt4k - 1;
3362
3363
3364
3365
3366
3367 sendctrl_6120_mod(ppd->dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
3368 qib_read_kreg64(ppd->dd, kr_scratch);
3369 buf = qib_getsendbuf_range(ppd->dd, bnum, lbuf, lbuf);
3370 if (buf)
3371 goto done;
3372
3373 sendctrl_6120_mod(ppd, QIB_SENDCTRL_DISARM_ALL | QIB_SENDCTRL_FLUSH |
3374 QIB_SENDCTRL_AVAIL_BLIP);
3375 ppd->dd->upd_pio_shadow = 1;
3376 qib_read_kreg64(ppd->dd, kr_scratch);
3377 buf = qib_getsendbuf_range(ppd->dd, bnum, lbuf, lbuf);
3378done:
3379 return buf;
3380}
3381
3382static u32 __iomem *qib_6120_getsendbuf(struct qib_pportdata *ppd, u64 pbc,
3383 u32 *pbufnum)
3384{
3385 u32 first, last, plen = pbc & QIB_PBC_LENGTH_MASK;
3386 struct qib_devdata *dd = ppd->dd;
3387 u32 __iomem *buf;
3388
3389 if (((pbc >> 32) & PBC_6120_VL15_SEND_CTRL) &&
3390 !(ppd->lflags & (QIBL_IB_AUTONEG_INPROG | QIBL_LINKACTIVE)))
3391 buf = get_6120_link_buf(ppd, pbufnum);
3392 else {
3393
3394 if ((plen + 1) > dd->piosize2kmax_dwords)
3395 first = dd->piobcnt2k;
3396 else
3397 first = 0;
3398
3399 last = dd->piobcnt2k + dd->piobcnt4k - 1;
3400 buf = qib_getsendbuf_range(dd, pbufnum, first, last);
3401 }
3402 return buf;
3403}
3404
3405static int init_sdma_6120_regs(struct qib_pportdata *ppd)
3406{
3407 return -ENODEV;
3408}
3409
3410static u16 qib_sdma_6120_gethead(struct qib_pportdata *ppd)
3411{
3412 return 0;
3413}
3414
3415static int qib_sdma_6120_busy(struct qib_pportdata *ppd)
3416{
3417 return 0;
3418}
3419
3420static void qib_sdma_update_6120_tail(struct qib_pportdata *ppd, u16 tail)
3421{
3422}
3423
3424static void qib_6120_sdma_sendctrl(struct qib_pportdata *ppd, unsigned op)
3425{
3426}
3427
3428static void qib_sdma_set_6120_desc_cnt(struct qib_pportdata *ppd, unsigned cnt)
3429{
3430}
3431
3432
3433
3434
3435
3436static u32 qib_6120_setpbc_control(struct qib_pportdata *ppd, u32 plen,
3437 u8 srate, u8 vl)
3438{
3439 return vl == 15 ? PBC_6120_VL15_SEND_CTRL : 0;
3440}
3441
3442static void qib_6120_initvl15_bufs(struct qib_devdata *dd)
3443{
3444}
3445
3446static void qib_6120_init_ctxt(struct qib_ctxtdata *rcd)
3447{
3448 rcd->rcvegrcnt = rcd->dd->rcvhdrcnt;
3449 rcd->rcvegr_tid_base = rcd->ctxt * rcd->rcvegrcnt;
3450}
3451
3452static void qib_6120_txchk_change(struct qib_devdata *dd, u32 start,
3453 u32 len, u32 avail, struct qib_ctxtdata *rcd)
3454{
3455}
3456
3457static void writescratch(struct qib_devdata *dd, u32 val)
3458{
3459 (void) qib_write_kreg(dd, kr_scratch, val);
3460}
3461
3462static int qib_6120_tempsense_rd(struct qib_devdata *dd, int regnum)
3463{
3464 return -ENXIO;
3465}
3466
3467#ifdef CONFIG_INFINIBAND_QIB_DCA
3468static int qib_6120_notify_dca(struct qib_devdata *dd, unsigned long event)
3469{
3470 return 0;
3471}
3472#endif
3473
3474
3475static int qib_6120_eeprom_wen(struct qib_devdata *dd, int wen)
3476{
3477 return 1;
3478}
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491struct qib_devdata *qib_init_iba6120_funcs(struct pci_dev *pdev,
3492 const struct pci_device_id *ent)
3493{
3494 struct qib_devdata *dd;
3495 int ret;
3496
3497 dd = qib_alloc_devdata(pdev, sizeof(struct qib_pportdata) +
3498 sizeof(struct qib_chip_specific));
3499 if (IS_ERR(dd))
3500 goto bail;
3501
3502 dd->f_bringup_serdes = qib_6120_bringup_serdes;
3503 dd->f_cleanup = qib_6120_setup_cleanup;
3504 dd->f_clear_tids = qib_6120_clear_tids;
3505 dd->f_free_irq = qib_6120_free_irq;
3506 dd->f_get_base_info = qib_6120_get_base_info;
3507 dd->f_get_msgheader = qib_6120_get_msgheader;
3508 dd->f_getsendbuf = qib_6120_getsendbuf;
3509 dd->f_gpio_mod = gpio_6120_mod;
3510 dd->f_eeprom_wen = qib_6120_eeprom_wen;
3511 dd->f_hdrqempty = qib_6120_hdrqempty;
3512 dd->f_ib_updown = qib_6120_ib_updown;
3513 dd->f_init_ctxt = qib_6120_init_ctxt;
3514 dd->f_initvl15_bufs = qib_6120_initvl15_bufs;
3515 dd->f_intr_fallback = qib_6120_nointr_fallback;
3516 dd->f_late_initreg = qib_late_6120_initreg;
3517 dd->f_setpbc_control = qib_6120_setpbc_control;
3518 dd->f_portcntr = qib_portcntr_6120;
3519 dd->f_put_tid = (dd->minrev >= 2) ?
3520 qib_6120_put_tid_2 :
3521 qib_6120_put_tid;
3522 dd->f_quiet_serdes = qib_6120_quiet_serdes;
3523 dd->f_rcvctrl = rcvctrl_6120_mod;
3524 dd->f_read_cntrs = qib_read_6120cntrs;
3525 dd->f_read_portcntrs = qib_read_6120portcntrs;
3526 dd->f_reset = qib_6120_setup_reset;
3527 dd->f_init_sdma_regs = init_sdma_6120_regs;
3528 dd->f_sdma_busy = qib_sdma_6120_busy;
3529 dd->f_sdma_gethead = qib_sdma_6120_gethead;
3530 dd->f_sdma_sendctrl = qib_6120_sdma_sendctrl;
3531 dd->f_sdma_set_desc_cnt = qib_sdma_set_6120_desc_cnt;
3532 dd->f_sdma_update_tail = qib_sdma_update_6120_tail;
3533 dd->f_sendctrl = sendctrl_6120_mod;
3534 dd->f_set_armlaunch = qib_set_6120_armlaunch;
3535 dd->f_set_cntr_sample = qib_set_cntr_6120_sample;
3536 dd->f_iblink_state = qib_6120_iblink_state;
3537 dd->f_ibphys_portstate = qib_6120_phys_portstate;
3538 dd->f_get_ib_cfg = qib_6120_get_ib_cfg;
3539 dd->f_set_ib_cfg = qib_6120_set_ib_cfg;
3540 dd->f_set_ib_loopback = qib_6120_set_loopback;
3541 dd->f_set_intr_state = qib_6120_set_intr_state;
3542 dd->f_setextled = qib_6120_setup_setextled;
3543 dd->f_txchk_change = qib_6120_txchk_change;
3544 dd->f_update_usrhead = qib_update_6120_usrhead;
3545 dd->f_wantpiobuf_intr = qib_wantpiobuf_6120_intr;
3546 dd->f_xgxs_reset = qib_6120_xgxs_reset;
3547 dd->f_writescratch = writescratch;
3548 dd->f_tempsense_rd = qib_6120_tempsense_rd;
3549#ifdef CONFIG_INFINIBAND_QIB_DCA
3550 dd->f_notify_dca = qib_6120_notify_dca;
3551#endif
3552
3553
3554
3555
3556
3557
3558
3559 ret = qib_pcie_ddinit(dd, pdev, ent);
3560 if (ret < 0)
3561 goto bail_free;
3562
3563
3564 ret = init_6120_variables(dd);
3565 if (ret)
3566 goto bail_cleanup;
3567
3568 if (qib_mini_init)
3569 goto bail;
3570
3571 if (qib_pcie_params(dd, 8, NULL, NULL))
3572 qib_dev_err(dd,
3573 "Failed to setup PCIe or interrupts; continuing anyway\n");
3574 dd->cspec->irq = pdev->irq;
3575
3576
3577 qib_write_kreg(dd, kr_hwdiagctrl, 0);
3578
3579 if (qib_read_kreg64(dd, kr_hwerrstatus) &
3580 QLOGIC_IB_HWE_SERDESPLLFAILED)
3581 qib_write_kreg(dd, kr_hwerrclear,
3582 QLOGIC_IB_HWE_SERDESPLLFAILED);
3583
3584
3585 qib_setup_6120_interrupt(dd);
3586
3587 qib_6120_init_hwerrors(dd);
3588
3589 goto bail;
3590
3591bail_cleanup:
3592 qib_pcie_ddcleanup(dd);
3593bail_free:
3594 qib_free_devdata(dd);
3595 dd = ERR_PTR(ret);
3596bail:
3597 return dd;
3598}
3599