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#include <linux/interrupt.h>
40#include <linux/pci.h>
41#include <linux/delay.h>
42#include <linux/io.h>
43#include <linux/jiffies.h>
44#include <linux/module.h>
45#include <rdma/ib_verbs.h>
46#include <rdma/ib_smi.h>
47#ifdef CONFIG_INFINIBAND_QIB_DCA
48#include <linux/dca.h>
49#endif
50
51#include "qib.h"
52#include "qib_7322_regs.h"
53#include "qib_qsfp.h"
54
55#include "qib_mad.h"
56#include "qib_verbs.h"
57
58#undef pr_fmt
59#define pr_fmt(fmt) QIB_DRV_NAME " " fmt
60
61static void qib_setup_7322_setextled(struct qib_pportdata *, u32);
62static void qib_7322_handle_hwerrors(struct qib_devdata *, char *, size_t);
63static void sendctrl_7322_mod(struct qib_pportdata *ppd, u32 op);
64static irqreturn_t qib_7322intr(int irq, void *data);
65static irqreturn_t qib_7322bufavail(int irq, void *data);
66static irqreturn_t sdma_intr(int irq, void *data);
67static irqreturn_t sdma_idle_intr(int irq, void *data);
68static irqreturn_t sdma_progress_intr(int irq, void *data);
69static irqreturn_t sdma_cleanup_intr(int irq, void *data);
70static void qib_7322_txchk_change(struct qib_devdata *, u32, u32, u32,
71 struct qib_ctxtdata *rcd);
72static u8 qib_7322_phys_portstate(u64);
73static u32 qib_7322_iblink_state(u64);
74static void qib_set_ib_7322_lstate(struct qib_pportdata *ppd, u16 linkcmd,
75 u16 linitcmd);
76static void force_h1(struct qib_pportdata *);
77static void adj_tx_serdes(struct qib_pportdata *);
78static u32 qib_7322_setpbc_control(struct qib_pportdata *, u32, u8, u8);
79static void qib_7322_mini_pcs_reset(struct qib_pportdata *);
80
81static u32 ahb_mod(struct qib_devdata *, int, int, int, u32, u32);
82static void ibsd_wr_allchans(struct qib_pportdata *, int, unsigned, unsigned);
83static void serdes_7322_los_enable(struct qib_pportdata *, int);
84static int serdes_7322_init_old(struct qib_pportdata *);
85static int serdes_7322_init_new(struct qib_pportdata *);
86static void dump_sdma_7322_state(struct qib_pportdata *);
87
88#define BMASK(msb, lsb) (((1 << ((msb) + 1 - (lsb))) - 1) << (lsb))
89
90
91#define LE2_DEFAULT 5
92#define LE2_5m 4
93#define LE2_QME 0
94
95
96#define IBSD(hw_pidx) (hw_pidx + 2)
97
98
99static const unsigned rcv_int_timeout = 375;
100static const unsigned rcv_int_count = 16;
101static const unsigned sdma_idle_cnt = 64;
102
103
104#define RXEQ_DISABLE_MSECS 2500
105
106
107
108
109
110ushort qib_num_cfg_vls = 2;
111module_param_named(num_vls, qib_num_cfg_vls, ushort, S_IRUGO);
112MODULE_PARM_DESC(num_vls, "Set number of Virtual Lanes to use (1-8)");
113
114static ushort qib_chase = 1;
115module_param_named(chase, qib_chase, ushort, S_IRUGO);
116MODULE_PARM_DESC(chase, "Enable state chase handling");
117
118static ushort qib_long_atten = 10;
119module_param_named(long_attenuation, qib_long_atten, ushort, S_IRUGO);
120MODULE_PARM_DESC(long_attenuation, \
121 "attenuation cutoff (dB) for long copper cable setup");
122
123static ushort qib_singleport;
124module_param_named(singleport, qib_singleport, ushort, S_IRUGO);
125MODULE_PARM_DESC(singleport, "Use only IB port 1; more per-port buffer space");
126
127static ushort qib_krcvq01_no_msi;
128module_param_named(krcvq01_no_msi, qib_krcvq01_no_msi, ushort, S_IRUGO);
129MODULE_PARM_DESC(krcvq01_no_msi, "No MSI for kctx < 2");
130
131
132
133
134static unsigned qib_rcvhdrcnt;
135module_param_named(rcvhdrcnt, qib_rcvhdrcnt, uint, S_IRUGO);
136MODULE_PARM_DESC(rcvhdrcnt, "receive header count");
137
138static unsigned qib_rcvhdrsize;
139module_param_named(rcvhdrsize, qib_rcvhdrsize, uint, S_IRUGO);
140MODULE_PARM_DESC(rcvhdrsize, "receive header size in 32-bit words");
141
142static unsigned qib_rcvhdrentsize;
143module_param_named(rcvhdrentsize, qib_rcvhdrentsize, uint, S_IRUGO);
144MODULE_PARM_DESC(rcvhdrentsize, "receive header entry size in 32-bit words");
145
146#define MAX_ATTEN_LEN 64
147
148static char txselect_list[MAX_ATTEN_LEN] = "10";
149static struct kparam_string kp_txselect = {
150 .string = txselect_list,
151 .maxlen = MAX_ATTEN_LEN
152};
153static int setup_txselect(const char *, struct kernel_param *);
154module_param_call(txselect, setup_txselect, param_get_string,
155 &kp_txselect, S_IWUSR | S_IRUGO);
156MODULE_PARM_DESC(txselect, \
157 "Tx serdes indices (for no QSFP or invalid QSFP data)");
158
159#define BOARD_QME7342 5
160#define BOARD_QMH7342 6
161#define IS_QMH(dd) (SYM_FIELD((dd)->revision, Revision, BoardID) == \
162 BOARD_QMH7342)
163#define IS_QME(dd) (SYM_FIELD((dd)->revision, Revision, BoardID) == \
164 BOARD_QME7342)
165
166#define KREG_IDX(regname) (QIB_7322_##regname##_OFFS / sizeof(u64))
167
168#define KREG_IBPORT_IDX(regname) ((QIB_7322_##regname##_0_OFFS / sizeof(u64)))
169
170#define MASK_ACROSS(lsb, msb) \
171 (((1ULL << ((msb) + 1 - (lsb))) - 1) << (lsb))
172
173#define SYM_RMASK(regname, fldname) ((u64) \
174 QIB_7322_##regname##_##fldname##_RMASK)
175
176#define SYM_MASK(regname, fldname) ((u64) \
177 QIB_7322_##regname##_##fldname##_RMASK << \
178 QIB_7322_##regname##_##fldname##_LSB)
179
180#define SYM_FIELD(value, regname, fldname) ((u64) \
181 (((value) >> SYM_LSB(regname, fldname)) & \
182 SYM_RMASK(regname, fldname)))
183
184
185#define SYM_FIELD_ACROSS(value, regname, fldname, nbits) \
186 (((value) >> SYM_LSB(regname, fldname)) & MASK_ACROSS(0, nbits))
187
188#define HWE_MASK(fldname) SYM_MASK(HwErrMask, fldname##Mask)
189#define ERR_MASK(fldname) SYM_MASK(ErrMask, fldname##Mask)
190#define ERR_MASK_N(fldname) SYM_MASK(ErrMask_0, fldname##Mask)
191#define INT_MASK(fldname) SYM_MASK(IntMask, fldname##IntMask)
192#define INT_MASK_P(fldname, port) SYM_MASK(IntMask, fldname##IntMask##_##port)
193
194#define INT_MASK_PM(fldname, port) SYM_MASK(IntMask, fldname##Mask##_##port)
195
196
197#define SYM_LSB(regname, fldname) (QIB_7322_##regname##_##fldname##_LSB)
198
199
200
201
202
203#define IBA7322_TID_SZ_SHIFT QIB_7322_RcvTIDArray0_RT_BufSize_LSB
204#define IBA7322_TID_SZ_2K (1UL<<IBA7322_TID_SZ_SHIFT)
205#define IBA7322_TID_SZ_4K (2UL<<IBA7322_TID_SZ_SHIFT)
206#define IBA7322_TID_PA_SHIFT 11U
207
208#define SendIBSLIDAssignMask \
209 QIB_7322_SendIBSLIDAssign_0_SendIBSLIDAssign_15_0_RMASK
210#define SendIBSLMCMask \
211 QIB_7322_SendIBSLIDMask_0_SendIBSLIDMask_15_0_RMASK
212
213#define ExtLED_IB1_YEL SYM_MASK(EXTCtrl, LEDPort0YellowOn)
214#define ExtLED_IB1_GRN SYM_MASK(EXTCtrl, LEDPort0GreenOn)
215#define ExtLED_IB2_YEL SYM_MASK(EXTCtrl, LEDPort1YellowOn)
216#define ExtLED_IB2_GRN SYM_MASK(EXTCtrl, LEDPort1GreenOn)
217#define ExtLED_IB1_MASK (ExtLED_IB1_YEL | ExtLED_IB1_GRN)
218#define ExtLED_IB2_MASK (ExtLED_IB2_YEL | ExtLED_IB2_GRN)
219
220#define _QIB_GPIO_SDA_NUM 1
221#define _QIB_GPIO_SCL_NUM 0
222#define QIB_EEPROM_WEN_NUM 14
223#define QIB_TWSI_EEPROM_DEV 0xA2
224
225
226#define QIB_7322_PSXMITWAIT_CHECK_RATE 4000
227
228
229#define PORT_SPD_CAP (QIB_IB_SDR | QIB_IB_DDR | QIB_IB_QDR)
230#define PORT_SPD_CAP_SHIFT 3
231
232
233#define DUAL_PORT_CAP (PORT_SPD_CAP | (PORT_SPD_CAP << PORT_SPD_CAP_SHIFT))
234
235
236
237
238
239
240
241#define kr_contextcnt KREG_IDX(ContextCnt)
242#define kr_control KREG_IDX(Control)
243#define kr_counterregbase KREG_IDX(CntrRegBase)
244#define kr_errclear KREG_IDX(ErrClear)
245#define kr_errmask KREG_IDX(ErrMask)
246#define kr_errstatus KREG_IDX(ErrStatus)
247#define kr_extctrl KREG_IDX(EXTCtrl)
248#define kr_extstatus KREG_IDX(EXTStatus)
249#define kr_gpio_clear KREG_IDX(GPIOClear)
250#define kr_gpio_mask KREG_IDX(GPIOMask)
251#define kr_gpio_out KREG_IDX(GPIOOut)
252#define kr_gpio_status KREG_IDX(GPIOStatus)
253#define kr_hwdiagctrl KREG_IDX(HwDiagCtrl)
254#define kr_debugportval KREG_IDX(DebugPortValueReg)
255#define kr_fmask KREG_IDX(feature_mask)
256#define kr_act_fmask KREG_IDX(active_feature_mask)
257#define kr_hwerrclear KREG_IDX(HwErrClear)
258#define kr_hwerrmask KREG_IDX(HwErrMask)
259#define kr_hwerrstatus KREG_IDX(HwErrStatus)
260#define kr_intclear KREG_IDX(IntClear)
261#define kr_intmask KREG_IDX(IntMask)
262#define kr_intredirect KREG_IDX(IntRedirect0)
263#define kr_intstatus KREG_IDX(IntStatus)
264#define kr_pagealign KREG_IDX(PageAlign)
265#define kr_rcvavailtimeout KREG_IDX(RcvAvailTimeOut0)
266#define kr_rcvctrl KREG_IDX(RcvCtrl)
267#define kr_rcvegrbase KREG_IDX(RcvEgrBase)
268#define kr_rcvegrcnt KREG_IDX(RcvEgrCnt)
269#define kr_rcvhdrcnt KREG_IDX(RcvHdrCnt)
270#define kr_rcvhdrentsize KREG_IDX(RcvHdrEntSize)
271#define kr_rcvhdrsize KREG_IDX(RcvHdrSize)
272#define kr_rcvtidbase KREG_IDX(RcvTIDBase)
273#define kr_rcvtidcnt KREG_IDX(RcvTIDCnt)
274#define kr_revision KREG_IDX(Revision)
275#define kr_scratch KREG_IDX(Scratch)
276#define kr_sendbuffererror KREG_IDX(SendBufErr0)
277#define kr_sendcheckmask KREG_IDX(SendCheckMask0)
278#define kr_sendctrl KREG_IDX(SendCtrl)
279#define kr_sendgrhcheckmask KREG_IDX(SendGRHCheckMask0)
280#define kr_sendibpktmask KREG_IDX(SendIBPacketMask0)
281#define kr_sendpioavailaddr KREG_IDX(SendBufAvailAddr)
282#define kr_sendpiobufbase KREG_IDX(SendBufBase)
283#define kr_sendpiobufcnt KREG_IDX(SendBufCnt)
284#define kr_sendpiosize KREG_IDX(SendBufSize)
285#define kr_sendregbase KREG_IDX(SendRegBase)
286#define kr_sendbufavail0 KREG_IDX(SendBufAvail0)
287#define kr_userregbase KREG_IDX(UserRegBase)
288#define kr_intgranted KREG_IDX(Int_Granted)
289#define kr_vecclr_wo_int KREG_IDX(vec_clr_without_int)
290#define kr_intblocked KREG_IDX(IntBlocked)
291#define kr_r_access KREG_IDX(SPC_JTAG_ACCESS_REG)
292
293
294
295
296
297#define krp_errclear KREG_IBPORT_IDX(ErrClear)
298#define krp_errmask KREG_IBPORT_IDX(ErrMask)
299#define krp_errstatus KREG_IBPORT_IDX(ErrStatus)
300#define krp_highprio_0 KREG_IBPORT_IDX(HighPriority0)
301#define krp_highprio_limit KREG_IBPORT_IDX(HighPriorityLimit)
302#define krp_hrtbt_guid KREG_IBPORT_IDX(HRTBT_GUID)
303#define krp_ib_pcsconfig KREG_IBPORT_IDX(IBPCSConfig)
304#define krp_ibcctrl_a KREG_IBPORT_IDX(IBCCtrlA)
305#define krp_ibcctrl_b KREG_IBPORT_IDX(IBCCtrlB)
306#define krp_ibcctrl_c KREG_IBPORT_IDX(IBCCtrlC)
307#define krp_ibcstatus_a KREG_IBPORT_IDX(IBCStatusA)
308#define krp_ibcstatus_b KREG_IBPORT_IDX(IBCStatusB)
309#define krp_txestatus KREG_IBPORT_IDX(TXEStatus)
310#define krp_lowprio_0 KREG_IBPORT_IDX(LowPriority0)
311#define krp_ncmodectrl KREG_IBPORT_IDX(IBNCModeCtrl)
312#define krp_partitionkey KREG_IBPORT_IDX(RcvPartitionKey)
313#define krp_psinterval KREG_IBPORT_IDX(PSInterval)
314#define krp_psstart KREG_IBPORT_IDX(PSStart)
315#define krp_psstat KREG_IBPORT_IDX(PSStat)
316#define krp_rcvbthqp KREG_IBPORT_IDX(RcvBTHQP)
317#define krp_rcvctrl KREG_IBPORT_IDX(RcvCtrl)
318#define krp_rcvpktledcnt KREG_IBPORT_IDX(RcvPktLEDCnt)
319#define krp_rcvqpmaptable KREG_IBPORT_IDX(RcvQPMapTableA)
320#define krp_rxcreditvl0 KREG_IBPORT_IDX(RxCreditVL0)
321#define krp_rxcreditvl15 (KREG_IBPORT_IDX(RxCreditVL0)+15)
322#define krp_sendcheckcontrol KREG_IBPORT_IDX(SendCheckControl)
323#define krp_sendctrl KREG_IBPORT_IDX(SendCtrl)
324#define krp_senddmabase KREG_IBPORT_IDX(SendDmaBase)
325#define krp_senddmabufmask0 KREG_IBPORT_IDX(SendDmaBufMask0)
326#define krp_senddmabufmask1 (KREG_IBPORT_IDX(SendDmaBufMask0) + 1)
327#define krp_senddmabufmask2 (KREG_IBPORT_IDX(SendDmaBufMask0) + 2)
328#define krp_senddmabuf_use0 KREG_IBPORT_IDX(SendDmaBufUsed0)
329#define krp_senddmabuf_use1 (KREG_IBPORT_IDX(SendDmaBufUsed0) + 1)
330#define krp_senddmabuf_use2 (KREG_IBPORT_IDX(SendDmaBufUsed0) + 2)
331#define krp_senddmadesccnt KREG_IBPORT_IDX(SendDmaDescCnt)
332#define krp_senddmahead KREG_IBPORT_IDX(SendDmaHead)
333#define krp_senddmaheadaddr KREG_IBPORT_IDX(SendDmaHeadAddr)
334#define krp_senddmaidlecnt KREG_IBPORT_IDX(SendDmaIdleCnt)
335#define krp_senddmalengen KREG_IBPORT_IDX(SendDmaLenGen)
336#define krp_senddmaprioritythld KREG_IBPORT_IDX(SendDmaPriorityThld)
337#define krp_senddmareloadcnt KREG_IBPORT_IDX(SendDmaReloadCnt)
338#define krp_senddmastatus KREG_IBPORT_IDX(SendDmaStatus)
339#define krp_senddmatail KREG_IBPORT_IDX(SendDmaTail)
340#define krp_sendhdrsymptom KREG_IBPORT_IDX(SendHdrErrSymptom)
341#define krp_sendslid KREG_IBPORT_IDX(SendIBSLIDAssign)
342#define krp_sendslidmask KREG_IBPORT_IDX(SendIBSLIDMask)
343#define krp_ibsdtestiftx KREG_IBPORT_IDX(IB_SDTEST_IF_TX)
344#define krp_adapt_dis_timer KREG_IBPORT_IDX(ADAPT_DISABLE_TIMER_THRESHOLD)
345#define krp_tx_deemph_override KREG_IBPORT_IDX(IBSD_TX_DEEMPHASIS_OVERRIDE)
346#define krp_serdesctrl KREG_IBPORT_IDX(IBSerdesCtrl)
347
348
349
350
351
352#define krc_rcvhdraddr KREG_IDX(RcvHdrAddr0)
353#define krc_rcvhdrtailaddr KREG_IDX(RcvHdrTailAddr0)
354
355
356
357
358
359
360
361
362
363#define NUM_TIDFLOWS_CTXT 0x20
364#define ur_rcvflowtable (KREG_IDX(RcvTIDFlowTable0) - KREG_IDX(RcvHdrTail0))
365
366
367#define TIDFLOW_ERRBITS ( \
368 (SYM_MASK(RcvTIDFlowTable0, GenMismatch) << \
369 SYM_LSB(RcvTIDFlowTable0, GenMismatch)) | \
370 (SYM_MASK(RcvTIDFlowTable0, SeqMismatch) << \
371 SYM_LSB(RcvTIDFlowTable0, SeqMismatch)))
372
373
374
375
376#define CREG_IDX(regname) \
377((QIB_7322_##regname##_0_OFFS - QIB_7322_LBIntCnt_OFFS) / sizeof(u64))
378
379#define crp_badformat CREG_IDX(RxVersionErrCnt)
380#define crp_err_rlen CREG_IDX(RxLenErrCnt)
381#define crp_erricrc CREG_IDX(RxICRCErrCnt)
382#define crp_errlink CREG_IDX(RxLinkMalformCnt)
383#define crp_errlpcrc CREG_IDX(RxLPCRCErrCnt)
384#define crp_errpkey CREG_IDX(RxPKeyMismatchCnt)
385#define crp_errvcrc CREG_IDX(RxVCRCErrCnt)
386#define crp_excessbufferovfl CREG_IDX(ExcessBufferOvflCnt)
387#define crp_iblinkdown CREG_IDX(IBLinkDownedCnt)
388#define crp_iblinkerrrecov CREG_IDX(IBLinkErrRecoveryCnt)
389#define crp_ibstatuschange CREG_IDX(IBStatusChangeCnt)
390#define crp_ibsymbolerr CREG_IDX(IBSymbolErrCnt)
391#define crp_invalidrlen CREG_IDX(RxMaxMinLenErrCnt)
392#define crp_locallinkintegrityerr CREG_IDX(LocalLinkIntegrityErrCnt)
393#define crp_pktrcv CREG_IDX(RxDataPktCnt)
394#define crp_pktrcvflowctrl CREG_IDX(RxFlowPktCnt)
395#define crp_pktsend CREG_IDX(TxDataPktCnt)
396#define crp_pktsendflow CREG_IDX(TxFlowPktCnt)
397#define crp_psrcvdatacount CREG_IDX(PSRcvDataCount)
398#define crp_psrcvpktscount CREG_IDX(PSRcvPktsCount)
399#define crp_psxmitdatacount CREG_IDX(PSXmitDataCount)
400#define crp_psxmitpktscount CREG_IDX(PSXmitPktsCount)
401#define crp_psxmitwaitcount CREG_IDX(PSXmitWaitCount)
402#define crp_rcvebp CREG_IDX(RxEBPCnt)
403#define crp_rcvflowctrlviol CREG_IDX(RxFlowCtrlViolCnt)
404#define crp_rcvovfl CREG_IDX(RxBufOvflCnt)
405#define crp_rxdlidfltr CREG_IDX(RxDlidFltrCnt)
406#define crp_rxdroppkt CREG_IDX(RxDroppedPktCnt)
407#define crp_rxotherlocalphyerr CREG_IDX(RxOtherLocalPhyErrCnt)
408#define crp_rxqpinvalidctxt CREG_IDX(RxQPInvalidContextCnt)
409#define crp_rxvlerr CREG_IDX(RxVlErrCnt)
410#define crp_sendstall CREG_IDX(TxFlowStallCnt)
411#define crp_txdroppedpkt CREG_IDX(TxDroppedPktCnt)
412#define crp_txhdrerr CREG_IDX(TxHeadersErrCnt)
413#define crp_txlenerr CREG_IDX(TxLenErrCnt)
414#define crp_txminmaxlenerr CREG_IDX(TxMaxMinLenErrCnt)
415#define crp_txsdmadesc CREG_IDX(TxSDmaDescCnt)
416#define crp_txunderrun CREG_IDX(TxUnderrunCnt)
417#define crp_txunsupvl CREG_IDX(TxUnsupVLErrCnt)
418#define crp_vl15droppedpkt CREG_IDX(RxVL15DroppedPktCnt)
419#define crp_wordrcv CREG_IDX(RxDwordCnt)
420#define crp_wordsend CREG_IDX(TxDwordCnt)
421#define crp_tx_creditstalls CREG_IDX(TxCreditUpToDateTimeOut)
422
423
424#define CREG_DEVIDX(regname) ((QIB_7322_##regname##_OFFS - \
425 QIB_7322_LBIntCnt_OFFS) / sizeof(u64))
426#define cr_base_egrovfl CREG_DEVIDX(RxP0HdrEgrOvflCnt)
427#define cr_lbint CREG_DEVIDX(LBIntCnt)
428#define cr_lbstall CREG_DEVIDX(LBFlowStallCnt)
429#define cr_pcieretrydiag CREG_DEVIDX(PcieRetryBufDiagQwordCnt)
430#define cr_rxtidflowdrop CREG_DEVIDX(RxTidFlowDropCnt)
431#define cr_tidfull CREG_DEVIDX(RxTIDFullErrCnt)
432#define cr_tidinvalid CREG_DEVIDX(RxTIDValidErrCnt)
433
434
435#define NUM_IB_PORTS 2
436
437
438#define NUM_VL15_BUFS NUM_IB_PORTS
439
440
441
442
443
444
445
446#define KCTXT0_EGRCNT 2048
447
448
449#define PBC_PORT_SEL_LSB 26
450#define PBC_PORT_SEL_RMASK 1
451#define PBC_VL_NUM_LSB 27
452#define PBC_VL_NUM_RMASK 7
453#define PBC_7322_VL15_SEND (1ULL << 63)
454#define PBC_7322_VL15_SEND_CTRL (1ULL << 31)
455
456static u8 ib_rate_to_delay[IB_RATE_120_GBPS + 1] = {
457 [IB_RATE_2_5_GBPS] = 16,
458 [IB_RATE_5_GBPS] = 8,
459 [IB_RATE_10_GBPS] = 4,
460 [IB_RATE_20_GBPS] = 2,
461 [IB_RATE_30_GBPS] = 2,
462 [IB_RATE_40_GBPS] = 1
463};
464
465#define IBA7322_LINKSPEED_SHIFT SYM_LSB(IBCStatusA_0, LinkSpeedActive)
466#define IBA7322_LINKWIDTH_SHIFT SYM_LSB(IBCStatusA_0, LinkWidthActive)
467
468
469#define IB_7322_LT_STATE_DISABLED 0x00
470#define IB_7322_LT_STATE_LINKUP 0x01
471#define IB_7322_LT_STATE_POLLACTIVE 0x02
472#define IB_7322_LT_STATE_POLLQUIET 0x03
473#define IB_7322_LT_STATE_SLEEPDELAY 0x04
474#define IB_7322_LT_STATE_SLEEPQUIET 0x05
475#define IB_7322_LT_STATE_CFGDEBOUNCE 0x08
476#define IB_7322_LT_STATE_CFGRCVFCFG 0x09
477#define IB_7322_LT_STATE_CFGWAITRMT 0x0a
478#define IB_7322_LT_STATE_CFGIDLE 0x0b
479#define IB_7322_LT_STATE_RECOVERRETRAIN 0x0c
480#define IB_7322_LT_STATE_TXREVLANES 0x0d
481#define IB_7322_LT_STATE_RECOVERWAITRMT 0x0e
482#define IB_7322_LT_STATE_RECOVERIDLE 0x0f
483#define IB_7322_LT_STATE_CFGENH 0x10
484#define IB_7322_LT_STATE_CFGTEST 0x11
485#define IB_7322_LT_STATE_CFGWAITRMTTEST 0x12
486#define IB_7322_LT_STATE_CFGWAITENH 0x13
487
488
489#define IB_7322_L_STATE_DOWN 0x0
490#define IB_7322_L_STATE_INIT 0x1
491#define IB_7322_L_STATE_ARM 0x2
492#define IB_7322_L_STATE_ACTIVE 0x3
493#define IB_7322_L_STATE_ACT_DEFER 0x4
494
495static const u8 qib_7322_physportstate[0x20] = {
496 [IB_7322_LT_STATE_DISABLED] = IB_PHYSPORTSTATE_DISABLED,
497 [IB_7322_LT_STATE_LINKUP] = IB_PHYSPORTSTATE_LINKUP,
498 [IB_7322_LT_STATE_POLLACTIVE] = IB_PHYSPORTSTATE_POLL,
499 [IB_7322_LT_STATE_POLLQUIET] = IB_PHYSPORTSTATE_POLL,
500 [IB_7322_LT_STATE_SLEEPDELAY] = IB_PHYSPORTSTATE_SLEEP,
501 [IB_7322_LT_STATE_SLEEPQUIET] = IB_PHYSPORTSTATE_SLEEP,
502 [IB_7322_LT_STATE_CFGDEBOUNCE] = IB_PHYSPORTSTATE_CFG_TRAIN,
503 [IB_7322_LT_STATE_CFGRCVFCFG] =
504 IB_PHYSPORTSTATE_CFG_TRAIN,
505 [IB_7322_LT_STATE_CFGWAITRMT] =
506 IB_PHYSPORTSTATE_CFG_TRAIN,
507 [IB_7322_LT_STATE_CFGIDLE] = IB_PHYSPORTSTATE_CFG_IDLE,
508 [IB_7322_LT_STATE_RECOVERRETRAIN] =
509 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
510 [IB_7322_LT_STATE_RECOVERWAITRMT] =
511 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
512 [IB_7322_LT_STATE_RECOVERIDLE] =
513 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
514 [IB_7322_LT_STATE_CFGENH] = IB_PHYSPORTSTATE_CFG_ENH,
515 [IB_7322_LT_STATE_CFGTEST] = IB_PHYSPORTSTATE_CFG_TRAIN,
516 [IB_7322_LT_STATE_CFGWAITRMTTEST] =
517 IB_PHYSPORTSTATE_CFG_TRAIN,
518 [IB_7322_LT_STATE_CFGWAITENH] =
519 IB_PHYSPORTSTATE_CFG_WAIT_ENH,
520 [0x14] = IB_PHYSPORTSTATE_CFG_TRAIN,
521 [0x15] = IB_PHYSPORTSTATE_CFG_TRAIN,
522 [0x16] = IB_PHYSPORTSTATE_CFG_TRAIN,
523 [0x17] = IB_PHYSPORTSTATE_CFG_TRAIN
524};
525
526#ifdef CONFIG_INFINIBAND_QIB_DCA
527struct qib_irq_notify {
528 int rcv;
529 void *arg;
530 struct irq_affinity_notify notify;
531};
532#endif
533
534struct qib_chip_specific {
535 u64 __iomem *cregbase;
536 u64 *cntrs;
537 spinlock_t rcvmod_lock;
538 spinlock_t gpio_lock;
539 u64 main_int_mask;
540 u64 int_enable_mask;
541 u64 errormask;
542 u64 hwerrmask;
543 u64 gpio_out;
544 u64 gpio_mask;
545 u64 extctrl;
546 u32 ncntrs;
547 u32 nportcntrs;
548 u32 cntrnamelen;
549 u32 portcntrnamelen;
550 u32 numctxts;
551 u32 rcvegrcnt;
552 u32 updthresh;
553 u32 updthresh_dflt;
554 u32 r1;
555 int irq;
556 u32 num_msix_entries;
557 u32 sdmabufcnt;
558 u32 lastbuf_for_pio;
559 u32 stay_in_freeze;
560 u32 recovery_ports_initted;
561#ifdef CONFIG_INFINIBAND_QIB_DCA
562 u32 dca_ctrl;
563 int rhdr_cpu[18];
564 int sdma_cpu[2];
565 u64 dca_rcvhdr_ctrl[5];
566#endif
567 struct qib_msix_entry *msix_entries;
568 unsigned long *sendchkenable;
569 unsigned long *sendgrhchk;
570 unsigned long *sendibchk;
571 u32 rcvavail_timeout[18];
572 char emsgbuf[128];
573};
574
575
576struct txdds_ent {
577 u8 amp;
578 u8 pre;
579 u8 main;
580 u8 post;
581};
582
583struct vendor_txdds_ent {
584 u8 oui[QSFP_VOUI_LEN];
585 u8 *partnum;
586 struct txdds_ent sdr;
587 struct txdds_ent ddr;
588 struct txdds_ent qdr;
589};
590
591static void write_tx_serdes_param(struct qib_pportdata *, struct txdds_ent *);
592
593#define TXDDS_TABLE_SZ 16
594#define TXDDS_EXTRA_SZ 18
595#define TXDDS_MFG_SZ 2
596#define SERDES_CHANS 4
597
598#define H1_FORCE_VAL 8
599#define H1_FORCE_QME 1
600#define H1_FORCE_QMH 7
601
602
603#define krp_static_adapt_dis(spd) (KREG_IBPORT_IDX(ADAPT_DISABLE_STATIC_SDR) \
604 + ((spd) * 2))
605
606#define QDR_DFE_DISABLE_DELAY 4000
607#define QDR_STATIC_ADAPT_DOWN 0xf0f0f0f0ULL
608#define QDR_STATIC_ADAPT_DOWN_R1 0ULL
609#define QDR_STATIC_ADAPT_INIT 0xffffffffffULL
610#define QDR_STATIC_ADAPT_INIT_R1 0xf0ffffffffULL
611
612struct qib_chippport_specific {
613 u64 __iomem *kpregbase;
614 u64 __iomem *cpregbase;
615 u64 *portcntrs;
616 struct qib_pportdata *ppd;
617 wait_queue_head_t autoneg_wait;
618 struct delayed_work autoneg_work;
619 struct delayed_work ipg_work;
620 struct timer_list chase_timer;
621
622
623
624
625
626
627
628
629 u64 ibdeltainprog;
630 u64 ibsymdelta;
631 u64 ibsymsnap;
632 u64 iblnkerrdelta;
633 u64 iblnkerrsnap;
634 u64 iblnkdownsnap;
635 u64 iblnkdowndelta;
636 u64 ibmalfdelta;
637 u64 ibmalfsnap;
638 u64 ibcctrl_a;
639 u64 ibcctrl_b;
640 unsigned long qdr_dfe_time;
641 unsigned long chase_end;
642 u32 autoneg_tries;
643 u32 recovery_init;
644 u32 qdr_dfe_on;
645 u32 qdr_reforce;
646
647
648
649
650 u8 h1_val;
651 u8 no_eep;
652 u8 ipg_tries;
653 u8 ibmalfusesnap;
654 struct qib_qsfp_data qsfp_data;
655 char epmsgbuf[192];
656 char sdmamsgbuf[192];
657};
658
659static struct {
660 const char *name;
661 irq_handler_t handler;
662 int lsb;
663 int port;
664 int dca;
665} irq_table[] = {
666 { "", qib_7322intr, -1, 0, 0 },
667 { " (buf avail)", qib_7322bufavail,
668 SYM_LSB(IntStatus, SendBufAvail), 0, 0},
669 { " (sdma 0)", sdma_intr,
670 SYM_LSB(IntStatus, SDmaInt_0), 1, 1 },
671 { " (sdma 1)", sdma_intr,
672 SYM_LSB(IntStatus, SDmaInt_1), 2, 1 },
673 { " (sdmaI 0)", sdma_idle_intr,
674 SYM_LSB(IntStatus, SDmaIdleInt_0), 1, 1},
675 { " (sdmaI 1)", sdma_idle_intr,
676 SYM_LSB(IntStatus, SDmaIdleInt_1), 2, 1},
677 { " (sdmaP 0)", sdma_progress_intr,
678 SYM_LSB(IntStatus, SDmaProgressInt_0), 1, 1 },
679 { " (sdmaP 1)", sdma_progress_intr,
680 SYM_LSB(IntStatus, SDmaProgressInt_1), 2, 1 },
681 { " (sdmaC 0)", sdma_cleanup_intr,
682 SYM_LSB(IntStatus, SDmaCleanupDone_0), 1, 0 },
683 { " (sdmaC 1)", sdma_cleanup_intr,
684 SYM_LSB(IntStatus, SDmaCleanupDone_1), 2 , 0},
685};
686
687#ifdef CONFIG_INFINIBAND_QIB_DCA
688
689static const struct dca_reg_map {
690 int shadow_inx;
691 int lsb;
692 u64 mask;
693 u16 regno;
694} dca_rcvhdr_reg_map[] = {
695 { 0, SYM_LSB(DCACtrlB, RcvHdrq0DCAOPH),
696 ~SYM_MASK(DCACtrlB, RcvHdrq0DCAOPH) , KREG_IDX(DCACtrlB) },
697 { 0, SYM_LSB(DCACtrlB, RcvHdrq1DCAOPH),
698 ~SYM_MASK(DCACtrlB, RcvHdrq1DCAOPH) , KREG_IDX(DCACtrlB) },
699 { 0, SYM_LSB(DCACtrlB, RcvHdrq2DCAOPH),
700 ~SYM_MASK(DCACtrlB, RcvHdrq2DCAOPH) , KREG_IDX(DCACtrlB) },
701 { 0, SYM_LSB(DCACtrlB, RcvHdrq3DCAOPH),
702 ~SYM_MASK(DCACtrlB, RcvHdrq3DCAOPH) , KREG_IDX(DCACtrlB) },
703 { 1, SYM_LSB(DCACtrlC, RcvHdrq4DCAOPH),
704 ~SYM_MASK(DCACtrlC, RcvHdrq4DCAOPH) , KREG_IDX(DCACtrlC) },
705 { 1, SYM_LSB(DCACtrlC, RcvHdrq5DCAOPH),
706 ~SYM_MASK(DCACtrlC, RcvHdrq5DCAOPH) , KREG_IDX(DCACtrlC) },
707 { 1, SYM_LSB(DCACtrlC, RcvHdrq6DCAOPH),
708 ~SYM_MASK(DCACtrlC, RcvHdrq6DCAOPH) , KREG_IDX(DCACtrlC) },
709 { 1, SYM_LSB(DCACtrlC, RcvHdrq7DCAOPH),
710 ~SYM_MASK(DCACtrlC, RcvHdrq7DCAOPH) , KREG_IDX(DCACtrlC) },
711 { 2, SYM_LSB(DCACtrlD, RcvHdrq8DCAOPH),
712 ~SYM_MASK(DCACtrlD, RcvHdrq8DCAOPH) , KREG_IDX(DCACtrlD) },
713 { 2, SYM_LSB(DCACtrlD, RcvHdrq9DCAOPH),
714 ~SYM_MASK(DCACtrlD, RcvHdrq9DCAOPH) , KREG_IDX(DCACtrlD) },
715 { 2, SYM_LSB(DCACtrlD, RcvHdrq10DCAOPH),
716 ~SYM_MASK(DCACtrlD, RcvHdrq10DCAOPH) , KREG_IDX(DCACtrlD) },
717 { 2, SYM_LSB(DCACtrlD, RcvHdrq11DCAOPH),
718 ~SYM_MASK(DCACtrlD, RcvHdrq11DCAOPH) , KREG_IDX(DCACtrlD) },
719 { 3, SYM_LSB(DCACtrlE, RcvHdrq12DCAOPH),
720 ~SYM_MASK(DCACtrlE, RcvHdrq12DCAOPH) , KREG_IDX(DCACtrlE) },
721 { 3, SYM_LSB(DCACtrlE, RcvHdrq13DCAOPH),
722 ~SYM_MASK(DCACtrlE, RcvHdrq13DCAOPH) , KREG_IDX(DCACtrlE) },
723 { 3, SYM_LSB(DCACtrlE, RcvHdrq14DCAOPH),
724 ~SYM_MASK(DCACtrlE, RcvHdrq14DCAOPH) , KREG_IDX(DCACtrlE) },
725 { 3, SYM_LSB(DCACtrlE, RcvHdrq15DCAOPH),
726 ~SYM_MASK(DCACtrlE, RcvHdrq15DCAOPH) , KREG_IDX(DCACtrlE) },
727 { 4, SYM_LSB(DCACtrlF, RcvHdrq16DCAOPH),
728 ~SYM_MASK(DCACtrlF, RcvHdrq16DCAOPH) , KREG_IDX(DCACtrlF) },
729 { 4, SYM_LSB(DCACtrlF, RcvHdrq17DCAOPH),
730 ~SYM_MASK(DCACtrlF, RcvHdrq17DCAOPH) , KREG_IDX(DCACtrlF) },
731};
732#endif
733
734
735#define QLOGIC_IB_IBCC_LINKINITCMD_DISABLE 1
736
737#define QLOGIC_IB_IBCC_LINKINITCMD_POLL 2
738
739#define QLOGIC_IB_IBCC_LINKINITCMD_SLEEP 3
740#define QLOGIC_IB_IBCC_LINKINITCMD_SHIFT 16
741
742#define QLOGIC_IB_IBCC_LINKCMD_DOWN 1
743#define QLOGIC_IB_IBCC_LINKCMD_ARMED 2
744#define QLOGIC_IB_IBCC_LINKCMD_ACTIVE 3
745
746#define BLOB_7322_IBCHG 0x101
747
748static inline void qib_write_kreg(const struct qib_devdata *dd,
749 const u32 regno, u64 value);
750static inline u32 qib_read_kreg32(const struct qib_devdata *, const u32);
751static void write_7322_initregs(struct qib_devdata *);
752static void write_7322_init_portregs(struct qib_pportdata *);
753static void setup_7322_link_recovery(struct qib_pportdata *, u32);
754static void check_7322_rxe_status(struct qib_pportdata *);
755static u32 __iomem *qib_7322_getsendbuf(struct qib_pportdata *, u64, u32 *);
756#ifdef CONFIG_INFINIBAND_QIB_DCA
757static void qib_setup_dca(struct qib_devdata *dd);
758static void setup_dca_notifier(struct qib_devdata *dd,
759 struct qib_msix_entry *m);
760static void reset_dca_notifier(struct qib_devdata *dd,
761 struct qib_msix_entry *m);
762#endif
763
764
765
766
767
768
769
770
771
772
773
774static inline u32 qib_read_ureg32(const struct qib_devdata *dd,
775 enum qib_ureg regno, int ctxt)
776{
777 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
778 return 0;
779 return readl(regno + (u64 __iomem *)(
780 (dd->ureg_align * ctxt) + (dd->userbase ?
781 (char __iomem *)dd->userbase :
782 (char __iomem *)dd->kregbase + dd->uregbase)));
783}
784
785
786
787
788
789
790
791
792
793
794
795static inline u64 qib_read_ureg(const struct qib_devdata *dd,
796 enum qib_ureg regno, int ctxt)
797{
798
799 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
800 return 0;
801 return readq(regno + (u64 __iomem *)(
802 (dd->ureg_align * ctxt) + (dd->userbase ?
803 (char __iomem *)dd->userbase :
804 (char __iomem *)dd->kregbase + dd->uregbase)));
805}
806
807
808
809
810
811
812
813
814
815
816static inline void qib_write_ureg(const struct qib_devdata *dd,
817 enum qib_ureg regno, u64 value, int ctxt)
818{
819 u64 __iomem *ubase;
820 if (dd->userbase)
821 ubase = (u64 __iomem *)
822 ((char __iomem *) dd->userbase +
823 dd->ureg_align * ctxt);
824 else
825 ubase = (u64 __iomem *)
826 (dd->uregbase +
827 (char __iomem *) dd->kregbase +
828 dd->ureg_align * ctxt);
829
830 if (dd->kregbase && (dd->flags & QIB_PRESENT))
831 writeq(value, &ubase[regno]);
832}
833
834static inline u32 qib_read_kreg32(const struct qib_devdata *dd,
835 const u32 regno)
836{
837 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
838 return -1;
839 return readl((u32 __iomem *) &dd->kregbase[regno]);
840}
841
842static inline u64 qib_read_kreg64(const struct qib_devdata *dd,
843 const u32 regno)
844{
845 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
846 return -1;
847 return readq(&dd->kregbase[regno]);
848}
849
850static inline void qib_write_kreg(const struct qib_devdata *dd,
851 const u32 regno, u64 value)
852{
853 if (dd->kregbase && (dd->flags & QIB_PRESENT))
854 writeq(value, &dd->kregbase[regno]);
855}
856
857
858
859
860
861static inline u64 qib_read_kreg_port(const struct qib_pportdata *ppd,
862 const u16 regno)
863{
864 if (!ppd->cpspec->kpregbase || !(ppd->dd->flags & QIB_PRESENT))
865 return 0ULL;
866 return readq(&ppd->cpspec->kpregbase[regno]);
867}
868
869static inline void qib_write_kreg_port(const struct qib_pportdata *ppd,
870 const u16 regno, u64 value)
871{
872 if (ppd->cpspec && ppd->dd && ppd->cpspec->kpregbase &&
873 (ppd->dd->flags & QIB_PRESENT))
874 writeq(value, &ppd->cpspec->kpregbase[regno]);
875}
876
877
878
879
880
881
882
883
884static inline void qib_write_kreg_ctxt(const struct qib_devdata *dd,
885 const u16 regno, unsigned ctxt,
886 u64 value)
887{
888 qib_write_kreg(dd, regno + ctxt, value);
889}
890
891static inline u64 read_7322_creg(const struct qib_devdata *dd, u16 regno)
892{
893 if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
894 return 0;
895 return readq(&dd->cspec->cregbase[regno]);
896
897
898}
899
900static inline u32 read_7322_creg32(const struct qib_devdata *dd, u16 regno)
901{
902 if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
903 return 0;
904 return readl(&dd->cspec->cregbase[regno]);
905
906
907}
908
909static inline void write_7322_creg_port(const struct qib_pportdata *ppd,
910 u16 regno, u64 value)
911{
912 if (ppd->cpspec && ppd->cpspec->cpregbase &&
913 (ppd->dd->flags & QIB_PRESENT))
914 writeq(value, &ppd->cpspec->cpregbase[regno]);
915}
916
917static inline u64 read_7322_creg_port(const struct qib_pportdata *ppd,
918 u16 regno)
919{
920 if (!ppd->cpspec || !ppd->cpspec->cpregbase ||
921 !(ppd->dd->flags & QIB_PRESENT))
922 return 0;
923 return readq(&ppd->cpspec->cpregbase[regno]);
924}
925
926static inline u32 read_7322_creg32_port(const struct qib_pportdata *ppd,
927 u16 regno)
928{
929 if (!ppd->cpspec || !ppd->cpspec->cpregbase ||
930 !(ppd->dd->flags & QIB_PRESENT))
931 return 0;
932 return readl(&ppd->cpspec->cpregbase[regno]);
933}
934
935
936#define QLOGIC_IB_C_RESET SYM_MASK(Control, SyncReset)
937#define QLOGIC_IB_C_SDMAFETCHPRIOEN SYM_MASK(Control, SDmaDescFetchPriorityEn)
938
939
940#define QIB_I_RCVURG_LSB SYM_LSB(IntMask, RcvUrg0IntMask)
941#define QIB_I_RCVURG_RMASK MASK_ACROSS(0, 17)
942#define QIB_I_RCVURG_MASK (QIB_I_RCVURG_RMASK << QIB_I_RCVURG_LSB)
943#define QIB_I_RCVAVAIL_LSB SYM_LSB(IntMask, RcvAvail0IntMask)
944#define QIB_I_RCVAVAIL_RMASK MASK_ACROSS(0, 17)
945#define QIB_I_RCVAVAIL_MASK (QIB_I_RCVAVAIL_RMASK << QIB_I_RCVAVAIL_LSB)
946#define QIB_I_C_ERROR INT_MASK(Err)
947
948#define QIB_I_SPIOSENT (INT_MASK_P(SendDone, 0) | INT_MASK_P(SendDone, 1))
949#define QIB_I_SPIOBUFAVAIL INT_MASK(SendBufAvail)
950#define QIB_I_GPIO INT_MASK(AssertGPIO)
951#define QIB_I_P_SDMAINT(pidx) \
952 (INT_MASK_P(SDma, pidx) | INT_MASK_P(SDmaIdle, pidx) | \
953 INT_MASK_P(SDmaProgress, pidx) | \
954 INT_MASK_PM(SDmaCleanupDone, pidx))
955
956
957#define QIB_I_P_BITSEXTANT(pidx) \
958 (INT_MASK_P(Err, pidx) | INT_MASK_P(SendDone, pidx) | \
959 INT_MASK_P(SDma, pidx) | INT_MASK_P(SDmaIdle, pidx) | \
960 INT_MASK_P(SDmaProgress, pidx) | \
961 INT_MASK_PM(SDmaCleanupDone, pidx))
962
963
964
965#define QIB_I_C_BITSEXTANT \
966 (QIB_I_RCVURG_MASK | QIB_I_RCVAVAIL_MASK | \
967 QIB_I_SPIOSENT | \
968 QIB_I_C_ERROR | QIB_I_SPIOBUFAVAIL | QIB_I_GPIO)
969
970#define QIB_I_BITSEXTANT (QIB_I_C_BITSEXTANT | \
971 QIB_I_P_BITSEXTANT(0) | QIB_I_P_BITSEXTANT(1))
972
973
974
975
976#define QIB_E_P_IBSTATUSCHANGED ERR_MASK_N(IBStatusChanged)
977#define QIB_E_P_SHDR ERR_MASK_N(SHeadersErr)
978#define QIB_E_P_VL15_BUF_MISUSE ERR_MASK_N(VL15BufMisuseErr)
979#define QIB_E_P_SND_BUF_MISUSE ERR_MASK_N(SendBufMisuseErr)
980#define QIB_E_P_SUNSUPVL ERR_MASK_N(SendUnsupportedVLErr)
981#define QIB_E_P_SUNEXP_PKTNUM ERR_MASK_N(SendUnexpectedPktNumErr)
982#define QIB_E_P_SDROP_DATA ERR_MASK_N(SendDroppedDataPktErr)
983#define QIB_E_P_SDROP_SMP ERR_MASK_N(SendDroppedSmpPktErr)
984#define QIB_E_P_SPKTLEN ERR_MASK_N(SendPktLenErr)
985#define QIB_E_P_SUNDERRUN ERR_MASK_N(SendUnderRunErr)
986#define QIB_E_P_SMAXPKTLEN ERR_MASK_N(SendMaxPktLenErr)
987#define QIB_E_P_SMINPKTLEN ERR_MASK_N(SendMinPktLenErr)
988#define QIB_E_P_RIBLOSTLINK ERR_MASK_N(RcvIBLostLinkErr)
989#define QIB_E_P_RHDR ERR_MASK_N(RcvHdrErr)
990#define QIB_E_P_RHDRLEN ERR_MASK_N(RcvHdrLenErr)
991#define QIB_E_P_RBADTID ERR_MASK_N(RcvBadTidErr)
992#define QIB_E_P_RBADVERSION ERR_MASK_N(RcvBadVersionErr)
993#define QIB_E_P_RIBFLOW ERR_MASK_N(RcvIBFlowErr)
994#define QIB_E_P_REBP ERR_MASK_N(RcvEBPErr)
995#define QIB_E_P_RUNSUPVL ERR_MASK_N(RcvUnsupportedVLErr)
996#define QIB_E_P_RUNEXPCHAR ERR_MASK_N(RcvUnexpectedCharErr)
997#define QIB_E_P_RSHORTPKTLEN ERR_MASK_N(RcvShortPktLenErr)
998#define QIB_E_P_RLONGPKTLEN ERR_MASK_N(RcvLongPktLenErr)
999#define QIB_E_P_RMAXPKTLEN ERR_MASK_N(RcvMaxPktLenErr)
1000#define QIB_E_P_RMINPKTLEN ERR_MASK_N(RcvMinPktLenErr)
1001#define QIB_E_P_RICRC ERR_MASK_N(RcvICRCErr)
1002#define QIB_E_P_RVCRC ERR_MASK_N(RcvVCRCErr)
1003#define QIB_E_P_RFORMATERR ERR_MASK_N(RcvFormatErr)
1004
1005#define QIB_E_P_SDMA1STDESC ERR_MASK_N(SDma1stDescErr)
1006#define QIB_E_P_SDMABASE ERR_MASK_N(SDmaBaseErr)
1007#define QIB_E_P_SDMADESCADDRMISALIGN ERR_MASK_N(SDmaDescAddrMisalignErr)
1008#define QIB_E_P_SDMADWEN ERR_MASK_N(SDmaDwEnErr)
1009#define QIB_E_P_SDMAGENMISMATCH ERR_MASK_N(SDmaGenMismatchErr)
1010#define QIB_E_P_SDMAHALT ERR_MASK_N(SDmaHaltErr)
1011#define QIB_E_P_SDMAMISSINGDW ERR_MASK_N(SDmaMissingDwErr)
1012#define QIB_E_P_SDMAOUTOFBOUND ERR_MASK_N(SDmaOutOfBoundErr)
1013#define QIB_E_P_SDMARPYTAG ERR_MASK_N(SDmaRpyTagErr)
1014#define QIB_E_P_SDMATAILOUTOFBOUND ERR_MASK_N(SDmaTailOutOfBoundErr)
1015#define QIB_E_P_SDMAUNEXPDATA ERR_MASK_N(SDmaUnexpDataErr)
1016
1017
1018#define QIB_E_RESET ERR_MASK(ResetNegated)
1019#define QIB_E_HARDWARE ERR_MASK(HardwareErr)
1020#define QIB_E_INVALIDADDR ERR_MASK(InvalidAddrErr)
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030#define QIB_E_SBUF_VL15_MISUSE ERR_MASK(SBufVL15MisUseErr)
1031#define QIB_E_BADEEP ERR_MASK(InvalidEEPCmd)
1032#define QIB_E_VLMISMATCH ERR_MASK(SendVLMismatchErr)
1033#define QIB_E_ARMLAUNCH ERR_MASK(SendArmLaunchErr)
1034#define QIB_E_SPCLTRIG ERR_MASK(SendSpecialTriggerErr)
1035#define QIB_E_RRCVHDRFULL ERR_MASK(RcvHdrFullErr)
1036#define QIB_E_RRCVEGRFULL ERR_MASK(RcvEgrFullErr)
1037#define QIB_E_RCVCTXTSHARE ERR_MASK(RcvContextShareErr)
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048#define QIB_E_SDMA_VL15 ERR_MASK(SDmaVL15Err)
1049#define QIB_E_SDMA_WRONG_PORT ERR_MASK(SDmaWrongPortErr)
1050#define QIB_E_SDMA_BUF_DUP ERR_MASK(SDmaBufMaskDuplicateErr)
1051
1052
1053
1054
1055
1056#define QIB_E_P_PKTERRS (QIB_E_P_SPKTLEN |\
1057 QIB_E_P_SDROP_DATA | QIB_E_P_RVCRC |\
1058 QIB_E_P_RICRC | QIB_E_P_RSHORTPKTLEN |\
1059 QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SHDR | \
1060 QIB_E_P_REBP)
1061
1062
1063#define QIB_E_P_RPKTERRS (\
1064 QIB_E_P_RHDRLEN | QIB_E_P_RBADTID | \
1065 QIB_E_P_RBADVERSION | QIB_E_P_RHDR | \
1066 QIB_E_P_RLONGPKTLEN | QIB_E_P_RSHORTPKTLEN |\
1067 QIB_E_P_RMAXPKTLEN | QIB_E_P_RMINPKTLEN | \
1068 QIB_E_P_RFORMATERR | QIB_E_P_RUNSUPVL | \
1069 QIB_E_P_RUNEXPCHAR | QIB_E_P_RIBFLOW | QIB_E_P_REBP)
1070
1071
1072
1073
1074
1075
1076#define QIB_E_P_SPKTERRS (\
1077 QIB_E_P_SUNEXP_PKTNUM |\
1078 QIB_E_P_SDROP_DATA | QIB_E_P_SDROP_SMP |\
1079 QIB_E_P_SMAXPKTLEN |\
1080 QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SHDR | \
1081 QIB_E_P_SMINPKTLEN | QIB_E_P_SPKTLEN | \
1082 QIB_E_P_SND_BUF_MISUSE | QIB_E_P_SUNSUPVL)
1083
1084#define QIB_E_SPKTERRS ( \
1085 QIB_E_SBUF_VL15_MISUSE | QIB_E_VLMISMATCH | \
1086 ERR_MASK_N(SendUnsupportedVLErr) | \
1087 QIB_E_SPCLTRIG | QIB_E_SDMA_VL15 | QIB_E_SDMA_WRONG_PORT)
1088
1089#define QIB_E_P_SDMAERRS ( \
1090 QIB_E_P_SDMAHALT | \
1091 QIB_E_P_SDMADESCADDRMISALIGN | \
1092 QIB_E_P_SDMAUNEXPDATA | \
1093 QIB_E_P_SDMAMISSINGDW | \
1094 QIB_E_P_SDMADWEN | \
1095 QIB_E_P_SDMARPYTAG | \
1096 QIB_E_P_SDMA1STDESC | \
1097 QIB_E_P_SDMABASE | \
1098 QIB_E_P_SDMATAILOUTOFBOUND | \
1099 QIB_E_P_SDMAOUTOFBOUND | \
1100 QIB_E_P_SDMAGENMISMATCH)
1101
1102
1103
1104
1105
1106
1107#define QIB_E_P_BITSEXTANT ( \
1108 QIB_E_P_SPKTERRS | QIB_E_P_PKTERRS | QIB_E_P_RPKTERRS | \
1109 QIB_E_P_RIBLOSTLINK | QIB_E_P_IBSTATUSCHANGED | \
1110 QIB_E_P_SND_BUF_MISUSE | QIB_E_P_SUNDERRUN | \
1111 QIB_E_P_SHDR | QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SDMAERRS \
1112 )
1113
1114
1115
1116
1117
1118
1119
1120
1121#define QIB_E_P_LINK_PKTERRS (\
1122 QIB_E_P_SDROP_DATA | QIB_E_P_SDROP_SMP |\
1123 QIB_E_P_SMINPKTLEN | QIB_E_P_SPKTLEN |\
1124 QIB_E_P_RSHORTPKTLEN | QIB_E_P_RMINPKTLEN |\
1125 QIB_E_P_RUNEXPCHAR)
1126
1127
1128
1129
1130
1131
1132#define QIB_E_C_BITSEXTANT (\
1133 QIB_E_HARDWARE | QIB_E_INVALIDADDR | QIB_E_BADEEP |\
1134 QIB_E_ARMLAUNCH | QIB_E_VLMISMATCH | QIB_E_RRCVHDRFULL |\
1135 QIB_E_RRCVEGRFULL | QIB_E_RESET | QIB_E_SBUF_VL15_MISUSE)
1136
1137
1138#define E_SPKT_ERRS_IGNORE 0
1139
1140#define QIB_EXTS_MEMBIST_DISABLED \
1141 SYM_MASK(EXTStatus, MemBISTDisabled)
1142#define QIB_EXTS_MEMBIST_ENDTEST \
1143 SYM_MASK(EXTStatus, MemBISTEndTest)
1144
1145#define QIB_E_SPIOARMLAUNCH \
1146 ERR_MASK(SendArmLaunchErr)
1147
1148#define IBA7322_IBCC_LINKINITCMD_MASK SYM_RMASK(IBCCtrlA_0, LinkInitCmd)
1149#define IBA7322_IBCC_LINKCMD_SHIFT SYM_LSB(IBCCtrlA_0, LinkCmd)
1150
1151
1152
1153
1154
1155
1156
1157#define IBA7322_IBC_IBTA_1_2_MASK SYM_MASK(IBCCtrlB_0, IB_ENHANCED_MODE)
1158#define IBA7322_IBC_MAX_SPEED_MASK SYM_MASK(IBCCtrlB_0, SD_SPEED)
1159#define IBA7322_IBC_SPEED_QDR SYM_MASK(IBCCtrlB_0, SD_SPEED_QDR)
1160#define IBA7322_IBC_SPEED_DDR SYM_MASK(IBCCtrlB_0, SD_SPEED_DDR)
1161#define IBA7322_IBC_SPEED_SDR SYM_MASK(IBCCtrlB_0, SD_SPEED_SDR)
1162#define IBA7322_IBC_SPEED_MASK (SYM_MASK(IBCCtrlB_0, SD_SPEED_SDR) | \
1163 SYM_MASK(IBCCtrlB_0, SD_SPEED_DDR) | SYM_MASK(IBCCtrlB_0, SD_SPEED_QDR))
1164#define IBA7322_IBC_SPEED_LSB SYM_LSB(IBCCtrlB_0, SD_SPEED_SDR)
1165
1166#define IBA7322_LEDBLINK_OFF_SHIFT SYM_LSB(RcvPktLEDCnt_0, OFFperiod)
1167#define IBA7322_LEDBLINK_ON_SHIFT SYM_LSB(RcvPktLEDCnt_0, ONperiod)
1168
1169#define IBA7322_IBC_WIDTH_AUTONEG SYM_MASK(IBCCtrlB_0, IB_NUM_CHANNELS)
1170#define IBA7322_IBC_WIDTH_4X_ONLY (1<<SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS))
1171#define IBA7322_IBC_WIDTH_1X_ONLY (0<<SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS))
1172
1173#define IBA7322_IBC_RXPOL_MASK SYM_MASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP)
1174#define IBA7322_IBC_RXPOL_LSB SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP)
1175#define IBA7322_IBC_HRTBT_MASK (SYM_MASK(IBCCtrlB_0, HRTBT_AUTO) | \
1176 SYM_MASK(IBCCtrlB_0, HRTBT_ENB))
1177#define IBA7322_IBC_HRTBT_RMASK (IBA7322_IBC_HRTBT_MASK >> \
1178 SYM_LSB(IBCCtrlB_0, HRTBT_ENB))
1179#define IBA7322_IBC_HRTBT_LSB SYM_LSB(IBCCtrlB_0, HRTBT_ENB)
1180
1181#define IBA7322_REDIRECT_VEC_PER_REG 12
1182
1183#define IBA7322_SENDCHK_PKEY SYM_MASK(SendCheckControl_0, PKey_En)
1184#define IBA7322_SENDCHK_BTHQP SYM_MASK(SendCheckControl_0, BTHQP_En)
1185#define IBA7322_SENDCHK_SLID SYM_MASK(SendCheckControl_0, SLID_En)
1186#define IBA7322_SENDCHK_RAW_IPV6 SYM_MASK(SendCheckControl_0, RawIPV6_En)
1187#define IBA7322_SENDCHK_MINSZ SYM_MASK(SendCheckControl_0, PacketTooSmall_En)
1188
1189#define AUTONEG_TRIES 3
1190
1191#define HWE_AUTO(fldname) { .mask = SYM_MASK(HwErrMask, fldname##Mask), \
1192 .msg = #fldname , .sz = sizeof(#fldname) }
1193#define HWE_AUTO_P(fldname, port) { .mask = SYM_MASK(HwErrMask, \
1194 fldname##Mask##_##port), .msg = #fldname , .sz = sizeof(#fldname) }
1195static const struct qib_hwerror_msgs qib_7322_hwerror_msgs[] = {
1196 HWE_AUTO_P(IBSerdesPClkNotDetect, 1),
1197 HWE_AUTO_P(IBSerdesPClkNotDetect, 0),
1198 HWE_AUTO(PCIESerdesPClkNotDetect),
1199 HWE_AUTO(PowerOnBISTFailed),
1200 HWE_AUTO(TempsenseTholdReached),
1201 HWE_AUTO(MemoryErr),
1202 HWE_AUTO(PCIeBusParityErr),
1203 HWE_AUTO(PcieCplTimeout),
1204 HWE_AUTO(PciePoisonedTLP),
1205 HWE_AUTO_P(SDmaMemReadErr, 1),
1206 HWE_AUTO_P(SDmaMemReadErr, 0),
1207 HWE_AUTO_P(IBCBusFromSPCParityErr, 1),
1208 HWE_AUTO_P(IBCBusToSPCParityErr, 1),
1209 HWE_AUTO_P(IBCBusFromSPCParityErr, 0),
1210 HWE_AUTO(statusValidNoEop),
1211 HWE_AUTO(LATriggered),
1212 { .mask = 0, .sz = 0 }
1213};
1214
1215#define E_AUTO(fldname) { .mask = SYM_MASK(ErrMask, fldname##Mask), \
1216 .msg = #fldname, .sz = sizeof(#fldname) }
1217#define E_P_AUTO(fldname) { .mask = SYM_MASK(ErrMask_0, fldname##Mask), \
1218 .msg = #fldname, .sz = sizeof(#fldname) }
1219static const struct qib_hwerror_msgs qib_7322error_msgs[] = {
1220 E_AUTO(RcvEgrFullErr),
1221 E_AUTO(RcvHdrFullErr),
1222 E_AUTO(ResetNegated),
1223 E_AUTO(HardwareErr),
1224 E_AUTO(InvalidAddrErr),
1225 E_AUTO(SDmaVL15Err),
1226 E_AUTO(SBufVL15MisUseErr),
1227 E_AUTO(InvalidEEPCmd),
1228 E_AUTO(RcvContextShareErr),
1229 E_AUTO(SendVLMismatchErr),
1230 E_AUTO(SendArmLaunchErr),
1231 E_AUTO(SendSpecialTriggerErr),
1232 E_AUTO(SDmaWrongPortErr),
1233 E_AUTO(SDmaBufMaskDuplicateErr),
1234 { .mask = 0, .sz = 0 }
1235};
1236
1237static const struct qib_hwerror_msgs qib_7322p_error_msgs[] = {
1238 E_P_AUTO(IBStatusChanged),
1239 E_P_AUTO(SHeadersErr),
1240 E_P_AUTO(VL15BufMisuseErr),
1241
1242
1243
1244 {.mask = SYM_MASK(ErrMask_0, SDmaHaltErrMask), .msg = "SDmaHalted",
1245 .sz = 11},
1246 E_P_AUTO(SDmaDescAddrMisalignErr),
1247 E_P_AUTO(SDmaUnexpDataErr),
1248 E_P_AUTO(SDmaMissingDwErr),
1249 E_P_AUTO(SDmaDwEnErr),
1250 E_P_AUTO(SDmaRpyTagErr),
1251 E_P_AUTO(SDma1stDescErr),
1252 E_P_AUTO(SDmaBaseErr),
1253 E_P_AUTO(SDmaTailOutOfBoundErr),
1254 E_P_AUTO(SDmaOutOfBoundErr),
1255 E_P_AUTO(SDmaGenMismatchErr),
1256 E_P_AUTO(SendBufMisuseErr),
1257 E_P_AUTO(SendUnsupportedVLErr),
1258 E_P_AUTO(SendUnexpectedPktNumErr),
1259 E_P_AUTO(SendDroppedDataPktErr),
1260 E_P_AUTO(SendDroppedSmpPktErr),
1261 E_P_AUTO(SendPktLenErr),
1262 E_P_AUTO(SendUnderRunErr),
1263 E_P_AUTO(SendMaxPktLenErr),
1264 E_P_AUTO(SendMinPktLenErr),
1265 E_P_AUTO(RcvIBLostLinkErr),
1266 E_P_AUTO(RcvHdrErr),
1267 E_P_AUTO(RcvHdrLenErr),
1268 E_P_AUTO(RcvBadTidErr),
1269 E_P_AUTO(RcvBadVersionErr),
1270 E_P_AUTO(RcvIBFlowErr),
1271 E_P_AUTO(RcvEBPErr),
1272 E_P_AUTO(RcvUnsupportedVLErr),
1273 E_P_AUTO(RcvUnexpectedCharErr),
1274 E_P_AUTO(RcvShortPktLenErr),
1275 E_P_AUTO(RcvLongPktLenErr),
1276 E_P_AUTO(RcvMaxPktLenErr),
1277 E_P_AUTO(RcvMinPktLenErr),
1278 E_P_AUTO(RcvICRCErr),
1279 E_P_AUTO(RcvVCRCErr),
1280 E_P_AUTO(RcvFormatErr),
1281 { .mask = 0, .sz = 0 }
1282};
1283
1284
1285
1286
1287
1288#define INTR_AUTO(fldname) { .mask = SYM_MASK(IntMask, fldname##Mask), \
1289 .msg = #fldname, .sz = sizeof(#fldname) }
1290
1291#define INTR_AUTO_P(fldname) { .mask = MASK_ACROSS(\
1292 SYM_LSB(IntMask, fldname##Mask##_0), \
1293 SYM_LSB(IntMask, fldname##Mask##_1)), \
1294 .msg = #fldname "_P", .sz = sizeof(#fldname "_P") }
1295
1296#define INTR_AUTO_PI(fldname) { .mask = MASK_ACROSS(\
1297 SYM_LSB(IntMask, fldname##Mask##_1), \
1298 SYM_LSB(IntMask, fldname##Mask##_0)), \
1299 .msg = #fldname "_P", .sz = sizeof(#fldname "_P") }
1300
1301
1302
1303
1304#define INTR_AUTO_C(fldname) { .mask = MASK_ACROSS(\
1305 SYM_LSB(IntMask, fldname##0IntMask), \
1306 SYM_LSB(IntMask, fldname##17IntMask)), \
1307 .msg = #fldname "_C", .sz = sizeof(#fldname "_C") }
1308
1309static const struct qib_hwerror_msgs qib_7322_intr_msgs[] = {
1310 INTR_AUTO_P(SDmaInt),
1311 INTR_AUTO_P(SDmaProgressInt),
1312 INTR_AUTO_P(SDmaIdleInt),
1313 INTR_AUTO_P(SDmaCleanupDone),
1314 INTR_AUTO_C(RcvUrg),
1315 INTR_AUTO_P(ErrInt),
1316 INTR_AUTO(ErrInt),
1317 INTR_AUTO(AssertGPIOInt),
1318 INTR_AUTO_P(SendDoneInt),
1319 INTR_AUTO(SendBufAvailInt),
1320 INTR_AUTO_C(RcvAvail),
1321 { .mask = 0, .sz = 0 }
1322};
1323
1324#define TXSYMPTOM_AUTO_P(fldname) \
1325 { .mask = SYM_MASK(SendHdrErrSymptom_0, fldname), \
1326 .msg = #fldname, .sz = sizeof(#fldname) }
1327static const struct qib_hwerror_msgs hdrchk_msgs[] = {
1328 TXSYMPTOM_AUTO_P(NonKeyPacket),
1329 TXSYMPTOM_AUTO_P(GRHFail),
1330 TXSYMPTOM_AUTO_P(PkeyFail),
1331 TXSYMPTOM_AUTO_P(QPFail),
1332 TXSYMPTOM_AUTO_P(SLIDFail),
1333 TXSYMPTOM_AUTO_P(RawIPV6),
1334 TXSYMPTOM_AUTO_P(PacketTooSmall),
1335 { .mask = 0, .sz = 0 }
1336};
1337
1338#define IBA7322_HDRHEAD_PKTINT_SHIFT 32
1339
1340
1341
1342
1343
1344
1345static void qib_disarm_7322_senderrbufs(struct qib_pportdata *ppd)
1346{
1347 struct qib_devdata *dd = ppd->dd;
1348 u32 i;
1349 int any;
1350 u32 piobcnt = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
1351 u32 regcnt = (piobcnt + BITS_PER_LONG - 1) / BITS_PER_LONG;
1352 unsigned long sbuf[4];
1353
1354
1355
1356
1357
1358 any = 0;
1359 for (i = 0; i < regcnt; ++i) {
1360 sbuf[i] = qib_read_kreg64(dd, kr_sendbuffererror + i);
1361 if (sbuf[i]) {
1362 any = 1;
1363 qib_write_kreg(dd, kr_sendbuffererror + i, sbuf[i]);
1364 }
1365 }
1366
1367 if (any)
1368 qib_disarm_piobufs_set(dd, sbuf, piobcnt);
1369}
1370
1371
1372
1373
1374static void err_decode(char *msg, size_t len, u64 errs,
1375 const struct qib_hwerror_msgs *msp)
1376{
1377 u64 these, lmask;
1378 int took, multi, n = 0;
1379
1380 while (errs && msp && msp->mask) {
1381 multi = (msp->mask & (msp->mask - 1));
1382 while (errs & msp->mask) {
1383 these = (errs & msp->mask);
1384 lmask = (these & (these - 1)) ^ these;
1385 if (len) {
1386 if (n++) {
1387
1388 *msg++ = ',';
1389 len--;
1390 }
1391 BUG_ON(!msp->sz);
1392
1393 took = min_t(size_t, msp->sz - (size_t)1, len);
1394 memcpy(msg, msp->msg, took);
1395 len -= took;
1396 msg += took;
1397 if (len)
1398 *msg = '\0';
1399 }
1400 errs &= ~lmask;
1401 if (len && multi) {
1402
1403 int idx = -1;
1404
1405 while (lmask & msp->mask) {
1406 ++idx;
1407 lmask >>= 1;
1408 }
1409 took = scnprintf(msg, len, "_%d", idx);
1410 len -= took;
1411 msg += took;
1412 }
1413 }
1414 ++msp;
1415 }
1416
1417 if (len && errs)
1418 snprintf(msg, len, "%sMORE:%llX", n ? "," : "",
1419 (unsigned long long) errs);
1420}
1421
1422
1423static void flush_fifo(struct qib_pportdata *ppd)
1424{
1425 struct qib_devdata *dd = ppd->dd;
1426 u32 __iomem *piobuf;
1427 u32 bufn;
1428 u32 *hdr;
1429 u64 pbc;
1430 const unsigned hdrwords = 7;
1431 static struct qib_ib_header ibhdr = {
1432 .lrh[0] = cpu_to_be16(0xF000 | QIB_LRH_BTH),
1433 .lrh[1] = IB_LID_PERMISSIVE,
1434 .lrh[2] = cpu_to_be16(hdrwords + SIZE_OF_CRC),
1435 .lrh[3] = IB_LID_PERMISSIVE,
1436 .u.oth.bth[0] = cpu_to_be32(
1437 (IB_OPCODE_UD_SEND_ONLY << 24) | QIB_DEFAULT_P_KEY),
1438 .u.oth.bth[1] = cpu_to_be32(0),
1439 .u.oth.bth[2] = cpu_to_be32(0),
1440 .u.oth.u.ud.deth[0] = cpu_to_be32(0),
1441 .u.oth.u.ud.deth[1] = cpu_to_be32(0),
1442 };
1443
1444
1445
1446
1447
1448 pbc = PBC_7322_VL15_SEND |
1449 (((u64)ppd->hw_pidx) << (PBC_PORT_SEL_LSB + 32)) |
1450 (hdrwords + SIZE_OF_CRC);
1451 piobuf = qib_7322_getsendbuf(ppd, pbc, &bufn);
1452 if (!piobuf)
1453 return;
1454 writeq(pbc, piobuf);
1455 hdr = (u32 *) &ibhdr;
1456 if (dd->flags & QIB_PIO_FLUSH_WC) {
1457 qib_flush_wc();
1458 qib_pio_copy(piobuf + 2, hdr, hdrwords - 1);
1459 qib_flush_wc();
1460 __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords + 1);
1461 qib_flush_wc();
1462 } else
1463 qib_pio_copy(piobuf + 2, hdr, hdrwords);
1464 qib_sendbuf_done(dd, bufn);
1465}
1466
1467
1468
1469
1470static void qib_7322_sdma_sendctrl(struct qib_pportdata *ppd, unsigned op)
1471{
1472 struct qib_devdata *dd = ppd->dd;
1473 u64 set_sendctrl = 0;
1474 u64 clr_sendctrl = 0;
1475
1476 if (op & QIB_SDMA_SENDCTRL_OP_ENABLE)
1477 set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaEnable);
1478 else
1479 clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaEnable);
1480
1481 if (op & QIB_SDMA_SENDCTRL_OP_INTENABLE)
1482 set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaIntEnable);
1483 else
1484 clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaIntEnable);
1485
1486 if (op & QIB_SDMA_SENDCTRL_OP_HALT)
1487 set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaHalt);
1488 else
1489 clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaHalt);
1490
1491 if (op & QIB_SDMA_SENDCTRL_OP_DRAIN)
1492 set_sendctrl |= SYM_MASK(SendCtrl_0, TxeBypassIbc) |
1493 SYM_MASK(SendCtrl_0, TxeAbortIbc) |
1494 SYM_MASK(SendCtrl_0, TxeDrainRmFifo);
1495 else
1496 clr_sendctrl |= SYM_MASK(SendCtrl_0, TxeBypassIbc) |
1497 SYM_MASK(SendCtrl_0, TxeAbortIbc) |
1498 SYM_MASK(SendCtrl_0, TxeDrainRmFifo);
1499
1500 spin_lock(&dd->sendctrl_lock);
1501
1502
1503 if (op & QIB_SDMA_SENDCTRL_OP_DRAIN) {
1504 ppd->p_sendctrl &= ~SYM_MASK(SendCtrl_0, SendEnable);
1505 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
1506 qib_write_kreg(dd, kr_scratch, 0);
1507 }
1508
1509 ppd->p_sendctrl |= set_sendctrl;
1510 ppd->p_sendctrl &= ~clr_sendctrl;
1511
1512 if (op & QIB_SDMA_SENDCTRL_OP_CLEANUP)
1513 qib_write_kreg_port(ppd, krp_sendctrl,
1514 ppd->p_sendctrl |
1515 SYM_MASK(SendCtrl_0, SDmaCleanup));
1516 else
1517 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
1518 qib_write_kreg(dd, kr_scratch, 0);
1519
1520 if (op & QIB_SDMA_SENDCTRL_OP_DRAIN) {
1521 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, SendEnable);
1522 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
1523 qib_write_kreg(dd, kr_scratch, 0);
1524 }
1525
1526 spin_unlock(&dd->sendctrl_lock);
1527
1528 if ((op & QIB_SDMA_SENDCTRL_OP_DRAIN) && ppd->dd->cspec->r1)
1529 flush_fifo(ppd);
1530}
1531
1532static void qib_7322_sdma_hw_clean_up(struct qib_pportdata *ppd)
1533{
1534 __qib_sdma_process_event(ppd, qib_sdma_event_e50_hw_cleaned);
1535}
1536
1537static void qib_sdma_7322_setlengen(struct qib_pportdata *ppd)
1538{
1539
1540
1541
1542
1543
1544 qib_write_kreg_port(ppd, krp_senddmalengen, ppd->sdma_descq_cnt);
1545 qib_write_kreg_port(ppd, krp_senddmalengen,
1546 ppd->sdma_descq_cnt |
1547 (1ULL << QIB_7322_SendDmaLenGen_0_Generation_MSB));
1548}
1549
1550
1551
1552
1553static void qib_sdma_update_7322_tail(struct qib_pportdata *ppd, u16 tail)
1554{
1555
1556 wmb();
1557 ppd->sdma_descq_tail = tail;
1558 qib_write_kreg_port(ppd, krp_senddmatail, tail);
1559}
1560
1561
1562
1563
1564static void qib_7322_sdma_hw_start_up(struct qib_pportdata *ppd)
1565{
1566
1567
1568
1569
1570
1571
1572 sendctrl_7322_mod(ppd, QIB_SENDCTRL_FLUSH);
1573
1574 qib_sdma_7322_setlengen(ppd);
1575 qib_sdma_update_7322_tail(ppd, 0);
1576 ppd->sdma_head_dma[0] = 0;
1577 qib_7322_sdma_sendctrl(ppd,
1578 ppd->sdma_state.current_op | QIB_SDMA_SENDCTRL_OP_CLEANUP);
1579}
1580
1581#define DISABLES_SDMA ( \
1582 QIB_E_P_SDMAHALT | \
1583 QIB_E_P_SDMADESCADDRMISALIGN | \
1584 QIB_E_P_SDMAMISSINGDW | \
1585 QIB_E_P_SDMADWEN | \
1586 QIB_E_P_SDMARPYTAG | \
1587 QIB_E_P_SDMA1STDESC | \
1588 QIB_E_P_SDMABASE | \
1589 QIB_E_P_SDMATAILOUTOFBOUND | \
1590 QIB_E_P_SDMAOUTOFBOUND | \
1591 QIB_E_P_SDMAGENMISMATCH)
1592
1593static void sdma_7322_p_errors(struct qib_pportdata *ppd, u64 errs)
1594{
1595 unsigned long flags;
1596 struct qib_devdata *dd = ppd->dd;
1597
1598 errs &= QIB_E_P_SDMAERRS;
1599 err_decode(ppd->cpspec->sdmamsgbuf, sizeof(ppd->cpspec->sdmamsgbuf),
1600 errs, qib_7322p_error_msgs);
1601
1602 if (errs & QIB_E_P_SDMAUNEXPDATA)
1603 qib_dev_err(dd, "IB%u:%u SDmaUnexpData\n", dd->unit,
1604 ppd->port);
1605
1606 spin_lock_irqsave(&ppd->sdma_lock, flags);
1607
1608 if (errs != QIB_E_P_SDMAHALT) {
1609
1610 qib_dev_porterr(dd, ppd->port,
1611 "SDMA %s 0x%016llx %s\n",
1612 qib_sdma_state_names[ppd->sdma_state.current_state],
1613 errs, ppd->cpspec->sdmamsgbuf);
1614 dump_sdma_7322_state(ppd);
1615 }
1616
1617 switch (ppd->sdma_state.current_state) {
1618 case qib_sdma_state_s00_hw_down:
1619 break;
1620
1621 case qib_sdma_state_s10_hw_start_up_wait:
1622 if (errs & QIB_E_P_SDMAHALT)
1623 __qib_sdma_process_event(ppd,
1624 qib_sdma_event_e20_hw_started);
1625 break;
1626
1627 case qib_sdma_state_s20_idle:
1628 break;
1629
1630 case qib_sdma_state_s30_sw_clean_up_wait:
1631 break;
1632
1633 case qib_sdma_state_s40_hw_clean_up_wait:
1634 if (errs & QIB_E_P_SDMAHALT)
1635 __qib_sdma_process_event(ppd,
1636 qib_sdma_event_e50_hw_cleaned);
1637 break;
1638
1639 case qib_sdma_state_s50_hw_halt_wait:
1640 if (errs & QIB_E_P_SDMAHALT)
1641 __qib_sdma_process_event(ppd,
1642 qib_sdma_event_e60_hw_halted);
1643 break;
1644
1645 case qib_sdma_state_s99_running:
1646 __qib_sdma_process_event(ppd, qib_sdma_event_e7322_err_halted);
1647 __qib_sdma_process_event(ppd, qib_sdma_event_e60_hw_halted);
1648 break;
1649 }
1650
1651 spin_unlock_irqrestore(&ppd->sdma_lock, flags);
1652}
1653
1654
1655
1656
1657static noinline void handle_7322_errors(struct qib_devdata *dd)
1658{
1659 char *msg;
1660 u64 iserr = 0;
1661 u64 errs;
1662 u64 mask;
1663 int log_idx;
1664
1665 qib_stats.sps_errints++;
1666 errs = qib_read_kreg64(dd, kr_errstatus);
1667 if (!errs) {
1668 qib_devinfo(dd->pcidev,
1669 "device error interrupt, but no error bits set!\n");
1670 goto done;
1671 }
1672
1673
1674 errs &= dd->cspec->errormask;
1675 msg = dd->cspec->emsgbuf;
1676
1677
1678 if (errs & QIB_E_HARDWARE) {
1679 *msg = '\0';
1680 qib_7322_handle_hwerrors(dd, msg, sizeof dd->cspec->emsgbuf);
1681 } else
1682 for (log_idx = 0; log_idx < QIB_EEP_LOG_CNT; ++log_idx)
1683 if (errs & dd->eep_st_masks[log_idx].errs_to_log)
1684 qib_inc_eeprom_err(dd, log_idx, 1);
1685
1686 if (errs & QIB_E_SPKTERRS) {
1687 qib_disarm_7322_senderrbufs(dd->pport);
1688 qib_stats.sps_txerrs++;
1689 } else if (errs & QIB_E_INVALIDADDR)
1690 qib_stats.sps_txerrs++;
1691 else if (errs & QIB_E_ARMLAUNCH) {
1692 qib_stats.sps_txerrs++;
1693 qib_disarm_7322_senderrbufs(dd->pport);
1694 }
1695 qib_write_kreg(dd, kr_errclear, errs);
1696
1697
1698
1699
1700
1701
1702 mask = QIB_E_HARDWARE;
1703 *msg = '\0';
1704
1705 err_decode(msg, sizeof dd->cspec->emsgbuf, errs & ~mask,
1706 qib_7322error_msgs);
1707
1708
1709
1710
1711
1712 if (errs & QIB_E_RESET) {
1713 int pidx;
1714
1715 qib_dev_err(dd,
1716 "Got reset, requires re-init (unload and reload driver)\n");
1717 dd->flags &= ~QIB_INITTED;
1718
1719 *dd->devstatusp |= QIB_STATUS_HWERROR;
1720 for (pidx = 0; pidx < dd->num_pports; ++pidx)
1721 if (dd->pport[pidx].link_speed_supported)
1722 *dd->pport[pidx].statusp &= ~QIB_STATUS_IB_CONF;
1723 }
1724
1725 if (*msg && iserr)
1726 qib_dev_err(dd, "%s error\n", msg);
1727
1728
1729
1730
1731
1732
1733
1734
1735 if (errs & (ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr))) {
1736 qib_handle_urcv(dd, ~0U);
1737 if (errs & ERR_MASK(RcvEgrFullErr))
1738 qib_stats.sps_buffull++;
1739 else
1740 qib_stats.sps_hdrfull++;
1741 }
1742
1743done:
1744 return;
1745}
1746
1747static void qib_error_tasklet(unsigned long data)
1748{
1749 struct qib_devdata *dd = (struct qib_devdata *)data;
1750
1751 handle_7322_errors(dd);
1752 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
1753}
1754
1755static void reenable_chase(unsigned long opaque)
1756{
1757 struct qib_pportdata *ppd = (struct qib_pportdata *)opaque;
1758
1759 ppd->cpspec->chase_timer.expires = 0;
1760 qib_set_ib_7322_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
1761 QLOGIC_IB_IBCC_LINKINITCMD_POLL);
1762}
1763
1764static void disable_chase(struct qib_pportdata *ppd, unsigned long tnow,
1765 u8 ibclt)
1766{
1767 ppd->cpspec->chase_end = 0;
1768
1769 if (!qib_chase)
1770 return;
1771
1772 qib_set_ib_7322_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
1773 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
1774 ppd->cpspec->chase_timer.expires = jiffies + QIB_CHASE_DIS_TIME;
1775 add_timer(&ppd->cpspec->chase_timer);
1776}
1777
1778static void handle_serdes_issues(struct qib_pportdata *ppd, u64 ibcst)
1779{
1780 u8 ibclt;
1781 unsigned long tnow;
1782
1783 ibclt = (u8)SYM_FIELD(ibcst, IBCStatusA_0, LinkTrainingState);
1784
1785
1786
1787
1788
1789
1790
1791 switch (ibclt) {
1792 case IB_7322_LT_STATE_CFGRCVFCFG:
1793 case IB_7322_LT_STATE_CFGWAITRMT:
1794 case IB_7322_LT_STATE_TXREVLANES:
1795 case IB_7322_LT_STATE_CFGENH:
1796 tnow = jiffies;
1797 if (ppd->cpspec->chase_end &&
1798 time_after(tnow, ppd->cpspec->chase_end))
1799 disable_chase(ppd, tnow, ibclt);
1800 else if (!ppd->cpspec->chase_end)
1801 ppd->cpspec->chase_end = tnow + QIB_CHASE_TIME;
1802 break;
1803 default:
1804 ppd->cpspec->chase_end = 0;
1805 break;
1806 }
1807
1808 if (((ibclt >= IB_7322_LT_STATE_CFGTEST &&
1809 ibclt <= IB_7322_LT_STATE_CFGWAITENH) ||
1810 ibclt == IB_7322_LT_STATE_LINKUP) &&
1811 (ibcst & SYM_MASK(IBCStatusA_0, LinkSpeedQDR))) {
1812 force_h1(ppd);
1813 ppd->cpspec->qdr_reforce = 1;
1814 if (!ppd->dd->cspec->r1)
1815 serdes_7322_los_enable(ppd, 0);
1816 } else if (ppd->cpspec->qdr_reforce &&
1817 (ibcst & SYM_MASK(IBCStatusA_0, LinkSpeedQDR)) &&
1818 (ibclt == IB_7322_LT_STATE_CFGENH ||
1819 ibclt == IB_7322_LT_STATE_CFGIDLE ||
1820 ibclt == IB_7322_LT_STATE_LINKUP))
1821 force_h1(ppd);
1822
1823 if ((IS_QMH(ppd->dd) || IS_QME(ppd->dd)) &&
1824 ppd->link_speed_enabled == QIB_IB_QDR &&
1825 (ibclt == IB_7322_LT_STATE_CFGTEST ||
1826 ibclt == IB_7322_LT_STATE_CFGENH ||
1827 (ibclt >= IB_7322_LT_STATE_POLLACTIVE &&
1828 ibclt <= IB_7322_LT_STATE_SLEEPQUIET)))
1829 adj_tx_serdes(ppd);
1830
1831 if (ibclt != IB_7322_LT_STATE_LINKUP) {
1832 u8 ltstate = qib_7322_phys_portstate(ibcst);
1833 u8 pibclt = (u8)SYM_FIELD(ppd->lastibcstat, IBCStatusA_0,
1834 LinkTrainingState);
1835 if (!ppd->dd->cspec->r1 &&
1836 pibclt == IB_7322_LT_STATE_LINKUP &&
1837 ltstate != IB_PHYSPORTSTATE_LINK_ERR_RECOVER &&
1838 ltstate != IB_PHYSPORTSTATE_RECOVERY_RETRAIN &&
1839 ltstate != IB_PHYSPORTSTATE_RECOVERY_WAITRMT &&
1840 ltstate != IB_PHYSPORTSTATE_RECOVERY_IDLE)
1841
1842
1843 serdes_7322_los_enable(ppd, 1);
1844 if (!ppd->cpspec->qdr_dfe_on &&
1845 ibclt <= IB_7322_LT_STATE_SLEEPQUIET) {
1846 ppd->cpspec->qdr_dfe_on = 1;
1847 ppd->cpspec->qdr_dfe_time = 0;
1848
1849 qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
1850 ppd->dd->cspec->r1 ?
1851 QDR_STATIC_ADAPT_DOWN_R1 :
1852 QDR_STATIC_ADAPT_DOWN);
1853 pr_info(
1854 "IB%u:%u re-enabled QDR adaptation ibclt %x\n",
1855 ppd->dd->unit, ppd->port, ibclt);
1856 }
1857 }
1858}
1859
1860static int qib_7322_set_ib_cfg(struct qib_pportdata *, int, u32);
1861
1862
1863
1864
1865
1866
1867static noinline void handle_7322_p_errors(struct qib_pportdata *ppd)
1868{
1869 char *msg;
1870 u64 ignore_this_time = 0, iserr = 0, errs, fmask;
1871 struct qib_devdata *dd = ppd->dd;
1872
1873
1874 fmask = qib_read_kreg64(dd, kr_act_fmask);
1875 if (!fmask)
1876 check_7322_rxe_status(ppd);
1877
1878 errs = qib_read_kreg_port(ppd, krp_errstatus);
1879 if (!errs)
1880 qib_devinfo(dd->pcidev,
1881 "Port%d error interrupt, but no error bits set!\n",
1882 ppd->port);
1883 if (!fmask)
1884 errs &= ~QIB_E_P_IBSTATUSCHANGED;
1885 if (!errs)
1886 goto done;
1887
1888 msg = ppd->cpspec->epmsgbuf;
1889 *msg = '\0';
1890
1891 if (errs & ~QIB_E_P_BITSEXTANT) {
1892 err_decode(msg, sizeof ppd->cpspec->epmsgbuf,
1893 errs & ~QIB_E_P_BITSEXTANT, qib_7322p_error_msgs);
1894 if (!*msg)
1895 snprintf(msg, sizeof ppd->cpspec->epmsgbuf,
1896 "no others");
1897 qib_dev_porterr(dd, ppd->port,
1898 "error interrupt with unknown errors 0x%016Lx set (and %s)\n",
1899 (errs & ~QIB_E_P_BITSEXTANT), msg);
1900 *msg = '\0';
1901 }
1902
1903 if (errs & QIB_E_P_SHDR) {
1904 u64 symptom;
1905
1906
1907 symptom = qib_read_kreg_port(ppd, krp_sendhdrsymptom);
1908 qib_write_kreg_port(ppd, krp_sendhdrsymptom, 0);
1909 err_decode(msg, sizeof ppd->cpspec->epmsgbuf, symptom,
1910 hdrchk_msgs);
1911 *msg = '\0';
1912
1913 }
1914
1915 if (errs & QIB_E_P_SPKTERRS) {
1916 if ((errs & QIB_E_P_LINK_PKTERRS) &&
1917 !(ppd->lflags & QIBL_LINKACTIVE)) {
1918
1919
1920
1921
1922
1923
1924
1925 err_decode(msg, sizeof ppd->cpspec->epmsgbuf,
1926 (errs & QIB_E_P_LINK_PKTERRS),
1927 qib_7322p_error_msgs);
1928 *msg = '\0';
1929 ignore_this_time = errs & QIB_E_P_LINK_PKTERRS;
1930 }
1931 qib_disarm_7322_senderrbufs(ppd);
1932 } else if ((errs & QIB_E_P_LINK_PKTERRS) &&
1933 !(ppd->lflags & QIBL_LINKACTIVE)) {
1934
1935
1936
1937
1938
1939
1940
1941 err_decode(msg, sizeof ppd->cpspec->epmsgbuf, errs,
1942 qib_7322p_error_msgs);
1943 ignore_this_time = errs & QIB_E_P_LINK_PKTERRS;
1944 *msg = '\0';
1945 }
1946
1947 qib_write_kreg_port(ppd, krp_errclear, errs);
1948
1949 errs &= ~ignore_this_time;
1950 if (!errs)
1951 goto done;
1952
1953 if (errs & QIB_E_P_RPKTERRS)
1954 qib_stats.sps_rcverrs++;
1955 if (errs & QIB_E_P_SPKTERRS)
1956 qib_stats.sps_txerrs++;
1957
1958 iserr = errs & ~(QIB_E_P_RPKTERRS | QIB_E_P_PKTERRS);
1959
1960 if (errs & QIB_E_P_SDMAERRS)
1961 sdma_7322_p_errors(ppd, errs);
1962
1963 if (errs & QIB_E_P_IBSTATUSCHANGED) {
1964 u64 ibcs;
1965 u8 ltstate;
1966
1967 ibcs = qib_read_kreg_port(ppd, krp_ibcstatus_a);
1968 ltstate = qib_7322_phys_portstate(ibcs);
1969
1970 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
1971 handle_serdes_issues(ppd, ibcs);
1972 if (!(ppd->cpspec->ibcctrl_a &
1973 SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn))) {
1974
1975
1976
1977
1978
1979 ppd->cpspec->ibcctrl_a |=
1980 SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
1981 qib_write_kreg_port(ppd, krp_ibcctrl_a,
1982 ppd->cpspec->ibcctrl_a);
1983 }
1984
1985
1986 ppd->link_width_active =
1987 (ibcs & SYM_MASK(IBCStatusA_0, LinkWidthActive)) ?
1988 IB_WIDTH_4X : IB_WIDTH_1X;
1989 ppd->link_speed_active = (ibcs & SYM_MASK(IBCStatusA_0,
1990 LinkSpeedQDR)) ? QIB_IB_QDR : (ibcs &
1991 SYM_MASK(IBCStatusA_0, LinkSpeedActive)) ?
1992 QIB_IB_DDR : QIB_IB_SDR;
1993
1994 if ((ppd->lflags & QIBL_IB_LINK_DISABLED) && ltstate !=
1995 IB_PHYSPORTSTATE_DISABLED)
1996 qib_set_ib_7322_lstate(ppd, 0,
1997 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
1998 else
1999
2000
2001
2002
2003
2004
2005
2006
2007 if (ltstate != IB_PHYSPORTSTATE_LINK_ERR_RECOVER &&
2008 ltstate != IB_PHYSPORTSTATE_RECOVERY_RETRAIN &&
2009 ltstate != IB_PHYSPORTSTATE_RECOVERY_WAITRMT &&
2010 ltstate != IB_PHYSPORTSTATE_RECOVERY_IDLE)
2011 qib_handle_e_ibstatuschanged(ppd, ibcs);
2012 }
2013 if (*msg && iserr)
2014 qib_dev_porterr(dd, ppd->port, "%s error\n", msg);
2015
2016 if (ppd->state_wanted & ppd->lflags)
2017 wake_up_interruptible(&ppd->state_wait);
2018done:
2019 return;
2020}
2021
2022
2023static void qib_7322_set_intr_state(struct qib_devdata *dd, u32 enable)
2024{
2025 if (enable) {
2026 if (dd->flags & QIB_BADINTR)
2027 return;
2028 qib_write_kreg(dd, kr_intmask, dd->cspec->int_enable_mask);
2029
2030 qib_write_kreg(dd, kr_intclear, 0ULL);
2031 if (dd->cspec->num_msix_entries) {
2032
2033 u64 val = qib_read_kreg64(dd, kr_intgranted);
2034 if (val)
2035 qib_write_kreg(dd, kr_intgranted, val);
2036 }
2037 } else
2038 qib_write_kreg(dd, kr_intmask, 0ULL);
2039}
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056static void qib_7322_clear_freeze(struct qib_devdata *dd)
2057{
2058 int pidx;
2059
2060
2061 qib_write_kreg(dd, kr_errmask, 0ULL);
2062
2063 for (pidx = 0; pidx < dd->num_pports; ++pidx)
2064 if (dd->pport[pidx].link_speed_supported)
2065 qib_write_kreg_port(dd->pport + pidx, krp_errmask,
2066 0ULL);
2067
2068
2069 qib_7322_set_intr_state(dd, 0);
2070
2071
2072 qib_write_kreg(dd, kr_control, dd->control);
2073 qib_read_kreg32(dd, kr_scratch);
2074
2075
2076
2077
2078
2079
2080
2081 qib_write_kreg(dd, kr_hwerrclear, 0ULL);
2082 qib_write_kreg(dd, kr_errclear, E_SPKT_ERRS_IGNORE);
2083 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
2084
2085 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
2086 if (!dd->pport[pidx].link_speed_supported)
2087 continue;
2088 qib_write_kreg_port(dd->pport + pidx, krp_errclear, ~0Ull);
2089 qib_write_kreg_port(dd->pport + pidx, krp_errmask, ~0Ull);
2090 }
2091 qib_7322_set_intr_state(dd, 1);
2092}
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106static void qib_7322_handle_hwerrors(struct qib_devdata *dd, char *msg,
2107 size_t msgl)
2108{
2109 u64 hwerrs;
2110 u32 ctrl;
2111 int isfatal = 0;
2112
2113 hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
2114 if (!hwerrs)
2115 goto bail;
2116 if (hwerrs == ~0ULL) {
2117 qib_dev_err(dd,
2118 "Read of hardware error status failed (all bits set); ignoring\n");
2119 goto bail;
2120 }
2121 qib_stats.sps_hwerrs++;
2122
2123
2124 qib_write_kreg(dd, kr_hwerrclear, hwerrs &
2125 ~HWE_MASK(PowerOnBISTFailed));
2126
2127 hwerrs &= dd->cspec->hwerrmask;
2128
2129
2130
2131 if (hwerrs)
2132 qib_devinfo(dd->pcidev,
2133 "Hardware error: hwerr=0x%llx (cleared)\n",
2134 (unsigned long long) hwerrs);
2135
2136 ctrl = qib_read_kreg32(dd, kr_control);
2137 if ((ctrl & SYM_MASK(Control, FreezeMode)) && !dd->diag_client) {
2138
2139
2140
2141 if ((hwerrs & ~HWE_MASK(LATriggered)) ||
2142 dd->cspec->stay_in_freeze) {
2143
2144
2145
2146
2147
2148
2149
2150 if (dd->flags & QIB_INITTED)
2151 isfatal = 1;
2152 } else
2153 qib_7322_clear_freeze(dd);
2154 }
2155
2156 if (hwerrs & HWE_MASK(PowerOnBISTFailed)) {
2157 isfatal = 1;
2158 strlcpy(msg,
2159 "[Memory BIST test failed, InfiniPath hardware unusable]",
2160 msgl);
2161
2162 dd->cspec->hwerrmask &= ~HWE_MASK(PowerOnBISTFailed);
2163 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
2164 }
2165
2166 err_decode(msg, msgl, hwerrs, qib_7322_hwerror_msgs);
2167
2168
2169
2170 qib_dev_err(dd, "%s hardware error\n", msg);
2171
2172 if (hwerrs &
2173 (SYM_MASK(HwErrMask, SDmaMemReadErrMask_0) |
2174 SYM_MASK(HwErrMask, SDmaMemReadErrMask_1))) {
2175 int pidx = 0;
2176 int err;
2177 unsigned long flags;
2178 struct qib_pportdata *ppd = dd->pport;
2179 for (; pidx < dd->num_pports; ++pidx, ppd++) {
2180 err = 0;
2181 if (pidx == 0 && (hwerrs &
2182 SYM_MASK(HwErrMask, SDmaMemReadErrMask_0)))
2183 err++;
2184 if (pidx == 1 && (hwerrs &
2185 SYM_MASK(HwErrMask, SDmaMemReadErrMask_1)))
2186 err++;
2187 if (err) {
2188 spin_lock_irqsave(&ppd->sdma_lock, flags);
2189 dump_sdma_7322_state(ppd);
2190 spin_unlock_irqrestore(&ppd->sdma_lock, flags);
2191 }
2192 }
2193 }
2194
2195 if (isfatal && !dd->diag_client) {
2196 qib_dev_err(dd,
2197 "Fatal Hardware Error, no longer usable, SN %.16s\n",
2198 dd->serial);
2199
2200
2201
2202
2203 if (dd->freezemsg)
2204 snprintf(dd->freezemsg, dd->freezelen,
2205 "{%s}", msg);
2206 qib_disable_after_error(dd);
2207 }
2208bail:;
2209}
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221static void qib_7322_init_hwerrors(struct qib_devdata *dd)
2222{
2223 int pidx;
2224 u64 extsval;
2225
2226 extsval = qib_read_kreg64(dd, kr_extstatus);
2227 if (!(extsval & (QIB_EXTS_MEMBIST_DISABLED |
2228 QIB_EXTS_MEMBIST_ENDTEST)))
2229 qib_dev_err(dd, "MemBIST did not complete!\n");
2230
2231
2232 qib_write_kreg(dd, kr_hwerrclear, ~HWE_MASK(PowerOnBISTFailed));
2233 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
2234
2235
2236 qib_write_kreg(dd, kr_errclear, ~0ULL);
2237
2238 qib_write_kreg(dd, kr_errmask, ~0ULL);
2239 dd->cspec->errormask = qib_read_kreg64(dd, kr_errmask);
2240 for (pidx = 0; pidx < dd->num_pports; ++pidx)
2241 if (dd->pport[pidx].link_speed_supported)
2242 qib_write_kreg_port(dd->pport + pidx, krp_errmask,
2243 ~0ULL);
2244}
2245
2246
2247
2248
2249
2250
2251
2252static void qib_set_7322_armlaunch(struct qib_devdata *dd, u32 enable)
2253{
2254 if (enable) {
2255 qib_write_kreg(dd, kr_errclear, QIB_E_SPIOARMLAUNCH);
2256 dd->cspec->errormask |= QIB_E_SPIOARMLAUNCH;
2257 } else
2258 dd->cspec->errormask &= ~QIB_E_SPIOARMLAUNCH;
2259 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
2260}
2261
2262
2263
2264
2265
2266
2267static void qib_set_ib_7322_lstate(struct qib_pportdata *ppd, u16 linkcmd,
2268 u16 linitcmd)
2269{
2270 u64 mod_wd;
2271 struct qib_devdata *dd = ppd->dd;
2272 unsigned long flags;
2273
2274 if (linitcmd == QLOGIC_IB_IBCC_LINKINITCMD_DISABLE) {
2275
2276
2277
2278
2279
2280
2281
2282 qib_7322_mini_pcs_reset(ppd);
2283 spin_lock_irqsave(&ppd->lflags_lock, flags);
2284 ppd->lflags |= QIBL_IB_LINK_DISABLED;
2285 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
2286 } else if (linitcmd || linkcmd == QLOGIC_IB_IBCC_LINKCMD_DOWN) {
2287
2288
2289
2290
2291
2292 spin_lock_irqsave(&ppd->lflags_lock, flags);
2293 ppd->lflags &= ~QIBL_IB_LINK_DISABLED;
2294 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
2295
2296
2297
2298
2299 ppd->cpspec->ibcctrl_a &=
2300 ~SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
2301 }
2302
2303 mod_wd = (linkcmd << IBA7322_IBCC_LINKCMD_SHIFT) |
2304 (linitcmd << QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
2305
2306 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a |
2307 mod_wd);
2308
2309 qib_write_kreg(dd, kr_scratch, 0);
2310
2311}
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321#define RCV_BUF_UNITSZ 64
2322#define NUM_RCV_BUF_UNITS(dd) ((64 * 1024) / (RCV_BUF_UNITSZ * dd->num_pports))
2323
2324static void set_vls(struct qib_pportdata *ppd)
2325{
2326 int i, numvls, totcred, cred_vl, vl0extra;
2327 struct qib_devdata *dd = ppd->dd;
2328 u64 val;
2329
2330 numvls = qib_num_vls(ppd->vls_operational);
2331
2332
2333
2334
2335
2336
2337
2338
2339 totcred = NUM_RCV_BUF_UNITS(dd);
2340 cred_vl = (2 * 288 + RCV_BUF_UNITSZ - 1) / RCV_BUF_UNITSZ;
2341 totcred -= cred_vl;
2342 qib_write_kreg_port(ppd, krp_rxcreditvl15, (u64) cred_vl);
2343 cred_vl = totcred / numvls;
2344 vl0extra = totcred - cred_vl * numvls;
2345 qib_write_kreg_port(ppd, krp_rxcreditvl0, cred_vl + vl0extra);
2346 for (i = 1; i < numvls; i++)
2347 qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, cred_vl);
2348 for (; i < 8; i++)
2349 qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, 0);
2350
2351
2352 val = qib_read_kreg_port(ppd, krp_ibsdtestiftx);
2353 val |= SYM_MASK(IB_SDTEST_IF_TX_0, CREDIT_CHANGE);
2354 qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
2355 qib_write_kreg(dd, kr_scratch, 0ULL);
2356 val &= ~SYM_MASK(IB_SDTEST_IF_TX_0, CREDIT_CHANGE);
2357 qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
2358
2359 for (i = 0; i < numvls; i++)
2360 val = qib_read_kreg_port(ppd, krp_rxcreditvl0 + i);
2361 val = qib_read_kreg_port(ppd, krp_rxcreditvl15);
2362
2363
2364 ppd->cpspec->ibcctrl_a = (ppd->cpspec->ibcctrl_a &
2365 ~SYM_MASK(IBCCtrlA_0, NumVLane)) |
2366 ((u64)(numvls - 1) << SYM_LSB(IBCCtrlA_0, NumVLane));
2367 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
2368 qib_write_kreg(dd, kr_scratch, 0ULL);
2369}
2370
2371
2372
2373
2374
2375static int serdes_7322_init(struct qib_pportdata *ppd);
2376
2377
2378
2379
2380
2381static int qib_7322_bringup_serdes(struct qib_pportdata *ppd)
2382{
2383 struct qib_devdata *dd = ppd->dd;
2384 u64 val, guid, ibc;
2385 unsigned long flags;
2386 int ret = 0;
2387
2388
2389
2390
2391
2392
2393
2394 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, IBLinkEn);
2395 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
2396 qib_write_kreg(dd, kr_scratch, 0ULL);
2397
2398 if (qib_compat_ddr_negotiate) {
2399 ppd->cpspec->ibdeltainprog = 1;
2400 ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
2401 crp_ibsymbolerr);
2402 ppd->cpspec->iblnkerrsnap = read_7322_creg32_port(ppd,
2403 crp_iblinkerrrecov);
2404 }
2405
2406
2407 ibc = 0x5ULL << SYM_LSB(IBCCtrlA_0, FlowCtrlWaterMark);
2408
2409
2410
2411
2412
2413 ibc |= 24ULL << SYM_LSB(IBCCtrlA_0, FlowCtrlPeriod);
2414
2415 ibc |= 0xfULL << SYM_LSB(IBCCtrlA_0, PhyerrThreshold);
2416
2417 ibc |= 0xfULL << SYM_LSB(IBCCtrlA_0, OverrunThreshold);
2418
2419
2420
2421
2422 ibc |= ((u64)(ppd->ibmaxlen >> 2) + 1) <<
2423 SYM_LSB(IBCCtrlA_0, MaxPktLen);
2424 ppd->cpspec->ibcctrl_a = ibc;
2425
2426
2427
2428
2429
2430 qib_7322_mini_pcs_reset(ppd);
2431
2432 if (!ppd->cpspec->ibcctrl_b) {
2433 unsigned lse = ppd->link_speed_enabled;
2434
2435
2436
2437
2438
2439 ppd->cpspec->ibcctrl_b = qib_read_kreg_port(ppd,
2440 krp_ibcctrl_b);
2441 ppd->cpspec->ibcctrl_b &= ~(IBA7322_IBC_SPEED_QDR |
2442 IBA7322_IBC_SPEED_DDR |
2443 IBA7322_IBC_SPEED_SDR |
2444 IBA7322_IBC_WIDTH_AUTONEG |
2445 SYM_MASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED));
2446 if (lse & (lse - 1))
2447 ppd->cpspec->ibcctrl_b |=
2448 (lse << IBA7322_IBC_SPEED_LSB) |
2449 IBA7322_IBC_IBTA_1_2_MASK |
2450 IBA7322_IBC_MAX_SPEED_MASK;
2451 else
2452 ppd->cpspec->ibcctrl_b |= (lse == QIB_IB_QDR) ?
2453 IBA7322_IBC_SPEED_QDR |
2454 IBA7322_IBC_IBTA_1_2_MASK :
2455 (lse == QIB_IB_DDR) ?
2456 IBA7322_IBC_SPEED_DDR :
2457 IBA7322_IBC_SPEED_SDR;
2458 if ((ppd->link_width_enabled & (IB_WIDTH_1X | IB_WIDTH_4X)) ==
2459 (IB_WIDTH_1X | IB_WIDTH_4X))
2460 ppd->cpspec->ibcctrl_b |= IBA7322_IBC_WIDTH_AUTONEG;
2461 else
2462 ppd->cpspec->ibcctrl_b |=
2463 ppd->link_width_enabled == IB_WIDTH_4X ?
2464 IBA7322_IBC_WIDTH_4X_ONLY :
2465 IBA7322_IBC_WIDTH_1X_ONLY;
2466
2467
2468 ppd->cpspec->ibcctrl_b |= (IBA7322_IBC_RXPOL_MASK |
2469 IBA7322_IBC_HRTBT_MASK);
2470 }
2471 qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
2472
2473
2474 val = qib_read_kreg_port(ppd, krp_ibcctrl_c);
2475 val &= ~SYM_MASK(IBCCtrlC_0, IB_FRONT_PORCH);
2476 val |= 0xfULL << SYM_LSB(IBCCtrlC_0, IB_FRONT_PORCH);
2477 qib_write_kreg_port(ppd, krp_ibcctrl_c, val);
2478
2479 serdes_7322_init(ppd);
2480
2481 guid = be64_to_cpu(ppd->guid);
2482 if (!guid) {
2483 if (dd->base_guid)
2484 guid = be64_to_cpu(dd->base_guid) + ppd->port - 1;
2485 ppd->guid = cpu_to_be64(guid);
2486 }
2487
2488 qib_write_kreg_port(ppd, krp_hrtbt_guid, guid);
2489
2490 qib_write_kreg(dd, kr_scratch, 0);
2491
2492
2493 ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0, IBLinkEn);
2494 set_vls(ppd);
2495
2496
2497 val = ppd->cpspec->ibcctrl_a | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
2498 QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
2499 qib_write_kreg_port(ppd, krp_ibcctrl_a, val);
2500 qib_write_kreg(dd, kr_scratch, 0ULL);
2501
2502 ppd->cpspec->ibcctrl_a = val & ~SYM_MASK(IBCCtrlA_0, LinkInitCmd);
2503
2504
2505 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
2506 ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvIBPortEnable);
2507 qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
2508 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
2509
2510
2511 val = qib_read_kreg_port(ppd, krp_errmask);
2512 qib_write_kreg_port(ppd, krp_errmask,
2513 val | ERR_MASK_N(IBStatusChanged));
2514
2515
2516 return ret;
2517}
2518
2519
2520
2521
2522
2523
2524static void qib_7322_mini_quiet_serdes(struct qib_pportdata *ppd)
2525{
2526 u64 val;
2527 unsigned long flags;
2528
2529 qib_set_ib_7322_lstate(ppd, 0, QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
2530
2531 spin_lock_irqsave(&ppd->lflags_lock, flags);
2532 ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
2533 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
2534 wake_up(&ppd->cpspec->autoneg_wait);
2535 cancel_delayed_work_sync(&ppd->cpspec->autoneg_work);
2536 if (ppd->dd->cspec->r1)
2537 cancel_delayed_work_sync(&ppd->cpspec->ipg_work);
2538
2539 ppd->cpspec->chase_end = 0;
2540 if (ppd->cpspec->chase_timer.data)
2541 del_timer_sync(&ppd->cpspec->chase_timer);
2542
2543
2544
2545
2546
2547
2548
2549
2550 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, IBLinkEn);
2551 qib_7322_mini_pcs_reset(ppd);
2552
2553
2554
2555
2556
2557 if (ppd->cpspec->ibsymdelta || ppd->cpspec->iblnkerrdelta ||
2558 ppd->cpspec->ibdeltainprog || ppd->cpspec->iblnkdowndelta) {
2559 struct qib_devdata *dd = ppd->dd;
2560 u64 diagc;
2561
2562
2563 diagc = qib_read_kreg64(dd, kr_hwdiagctrl);
2564 qib_write_kreg(dd, kr_hwdiagctrl,
2565 diagc | SYM_MASK(HwDiagCtrl, CounterWrEnable));
2566
2567 if (ppd->cpspec->ibsymdelta || ppd->cpspec->ibdeltainprog) {
2568 val = read_7322_creg32_port(ppd, crp_ibsymbolerr);
2569 if (ppd->cpspec->ibdeltainprog)
2570 val -= val - ppd->cpspec->ibsymsnap;
2571 val -= ppd->cpspec->ibsymdelta;
2572 write_7322_creg_port(ppd, crp_ibsymbolerr, val);
2573 }
2574 if (ppd->cpspec->iblnkerrdelta || ppd->cpspec->ibdeltainprog) {
2575 val = read_7322_creg32_port(ppd, crp_iblinkerrrecov);
2576 if (ppd->cpspec->ibdeltainprog)
2577 val -= val - ppd->cpspec->iblnkerrsnap;
2578 val -= ppd->cpspec->iblnkerrdelta;
2579 write_7322_creg_port(ppd, crp_iblinkerrrecov, val);
2580 }
2581 if (ppd->cpspec->iblnkdowndelta) {
2582 val = read_7322_creg32_port(ppd, crp_iblinkdown);
2583 val += ppd->cpspec->iblnkdowndelta;
2584 write_7322_creg_port(ppd, crp_iblinkdown, val);
2585 }
2586
2587
2588
2589
2590
2591
2592 qib_write_kreg(dd, kr_hwdiagctrl, diagc);
2593 }
2594}
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618static void qib_setup_7322_setextled(struct qib_pportdata *ppd, u32 on)
2619{
2620 struct qib_devdata *dd = ppd->dd;
2621 u64 extctl, ledblink = 0, val;
2622 unsigned long flags;
2623 int yel, grn;
2624
2625
2626
2627
2628
2629 if (dd->diag_client)
2630 return;
2631
2632
2633 if (ppd->led_override) {
2634 grn = (ppd->led_override & QIB_LED_PHYS);
2635 yel = (ppd->led_override & QIB_LED_LOG);
2636 } else if (on) {
2637 val = qib_read_kreg_port(ppd, krp_ibcstatus_a);
2638 grn = qib_7322_phys_portstate(val) ==
2639 IB_PHYSPORTSTATE_LINKUP;
2640 yel = qib_7322_iblink_state(val) == IB_PORT_ACTIVE;
2641 } else {
2642 grn = 0;
2643 yel = 0;
2644 }
2645
2646 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
2647 extctl = dd->cspec->extctrl & (ppd->port == 1 ?
2648 ~ExtLED_IB1_MASK : ~ExtLED_IB2_MASK);
2649 if (grn) {
2650 extctl |= ppd->port == 1 ? ExtLED_IB1_GRN : ExtLED_IB2_GRN;
2651
2652
2653
2654
2655
2656 ledblink = ((66600 * 1000UL / 4) << IBA7322_LEDBLINK_ON_SHIFT) |
2657 ((187500 * 1000UL / 4) << IBA7322_LEDBLINK_OFF_SHIFT);
2658 }
2659 if (yel)
2660 extctl |= ppd->port == 1 ? ExtLED_IB1_YEL : ExtLED_IB2_YEL;
2661 dd->cspec->extctrl = extctl;
2662 qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
2663 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
2664
2665 if (ledblink)
2666 qib_write_kreg_port(ppd, krp_rcvpktledcnt, ledblink);
2667}
2668
2669#ifdef CONFIG_INFINIBAND_QIB_DCA
2670
2671static int qib_7322_notify_dca(struct qib_devdata *dd, unsigned long event)
2672{
2673 switch (event) {
2674 case DCA_PROVIDER_ADD:
2675 if (dd->flags & QIB_DCA_ENABLED)
2676 break;
2677 if (!dca_add_requester(&dd->pcidev->dev)) {
2678 qib_devinfo(dd->pcidev, "DCA enabled\n");
2679 dd->flags |= QIB_DCA_ENABLED;
2680 qib_setup_dca(dd);
2681 }
2682 break;
2683 case DCA_PROVIDER_REMOVE:
2684 if (dd->flags & QIB_DCA_ENABLED) {
2685 dca_remove_requester(&dd->pcidev->dev);
2686 dd->flags &= ~QIB_DCA_ENABLED;
2687 dd->cspec->dca_ctrl = 0;
2688 qib_write_kreg(dd, KREG_IDX(DCACtrlA),
2689 dd->cspec->dca_ctrl);
2690 }
2691 break;
2692 }
2693 return 0;
2694}
2695
2696static void qib_update_rhdrq_dca(struct qib_ctxtdata *rcd, int cpu)
2697{
2698 struct qib_devdata *dd = rcd->dd;
2699 struct qib_chip_specific *cspec = dd->cspec;
2700
2701 if (!(dd->flags & QIB_DCA_ENABLED))
2702 return;
2703 if (cspec->rhdr_cpu[rcd->ctxt] != cpu) {
2704 const struct dca_reg_map *rmp;
2705
2706 cspec->rhdr_cpu[rcd->ctxt] = cpu;
2707 rmp = &dca_rcvhdr_reg_map[rcd->ctxt];
2708 cspec->dca_rcvhdr_ctrl[rmp->shadow_inx] &= rmp->mask;
2709 cspec->dca_rcvhdr_ctrl[rmp->shadow_inx] |=
2710 (u64) dca3_get_tag(&dd->pcidev->dev, cpu) << rmp->lsb;
2711 qib_devinfo(dd->pcidev,
2712 "Ctxt %d cpu %d dca %llx\n", rcd->ctxt, cpu,
2713 (long long) cspec->dca_rcvhdr_ctrl[rmp->shadow_inx]);
2714 qib_write_kreg(dd, rmp->regno,
2715 cspec->dca_rcvhdr_ctrl[rmp->shadow_inx]);
2716 cspec->dca_ctrl |= SYM_MASK(DCACtrlA, RcvHdrqDCAEnable);
2717 qib_write_kreg(dd, KREG_IDX(DCACtrlA), cspec->dca_ctrl);
2718 }
2719}
2720
2721static void qib_update_sdma_dca(struct qib_pportdata *ppd, int cpu)
2722{
2723 struct qib_devdata *dd = ppd->dd;
2724 struct qib_chip_specific *cspec = dd->cspec;
2725 unsigned pidx = ppd->port - 1;
2726
2727 if (!(dd->flags & QIB_DCA_ENABLED))
2728 return;
2729 if (cspec->sdma_cpu[pidx] != cpu) {
2730 cspec->sdma_cpu[pidx] = cpu;
2731 cspec->dca_rcvhdr_ctrl[4] &= ~(ppd->hw_pidx ?
2732 SYM_MASK(DCACtrlF, SendDma1DCAOPH) :
2733 SYM_MASK(DCACtrlF, SendDma0DCAOPH));
2734 cspec->dca_rcvhdr_ctrl[4] |=
2735 (u64) dca3_get_tag(&dd->pcidev->dev, cpu) <<
2736 (ppd->hw_pidx ?
2737 SYM_LSB(DCACtrlF, SendDma1DCAOPH) :
2738 SYM_LSB(DCACtrlF, SendDma0DCAOPH));
2739 qib_devinfo(dd->pcidev,
2740 "sdma %d cpu %d dca %llx\n", ppd->hw_pidx, cpu,
2741 (long long) cspec->dca_rcvhdr_ctrl[4]);
2742 qib_write_kreg(dd, KREG_IDX(DCACtrlF),
2743 cspec->dca_rcvhdr_ctrl[4]);
2744 cspec->dca_ctrl |= ppd->hw_pidx ?
2745 SYM_MASK(DCACtrlA, SendDMAHead1DCAEnable) :
2746 SYM_MASK(DCACtrlA, SendDMAHead0DCAEnable);
2747 qib_write_kreg(dd, KREG_IDX(DCACtrlA), cspec->dca_ctrl);
2748 }
2749}
2750
2751static void qib_setup_dca(struct qib_devdata *dd)
2752{
2753 struct qib_chip_specific *cspec = dd->cspec;
2754 int i;
2755
2756 for (i = 0; i < ARRAY_SIZE(cspec->rhdr_cpu); i++)
2757 cspec->rhdr_cpu[i] = -1;
2758 for (i = 0; i < ARRAY_SIZE(cspec->sdma_cpu); i++)
2759 cspec->sdma_cpu[i] = -1;
2760 cspec->dca_rcvhdr_ctrl[0] =
2761 (1ULL << SYM_LSB(DCACtrlB, RcvHdrq0DCAXfrCnt)) |
2762 (1ULL << SYM_LSB(DCACtrlB, RcvHdrq1DCAXfrCnt)) |
2763 (1ULL << SYM_LSB(DCACtrlB, RcvHdrq2DCAXfrCnt)) |
2764 (1ULL << SYM_LSB(DCACtrlB, RcvHdrq3DCAXfrCnt));
2765 cspec->dca_rcvhdr_ctrl[1] =
2766 (1ULL << SYM_LSB(DCACtrlC, RcvHdrq4DCAXfrCnt)) |
2767 (1ULL << SYM_LSB(DCACtrlC, RcvHdrq5DCAXfrCnt)) |
2768 (1ULL << SYM_LSB(DCACtrlC, RcvHdrq6DCAXfrCnt)) |
2769 (1ULL << SYM_LSB(DCACtrlC, RcvHdrq7DCAXfrCnt));
2770 cspec->dca_rcvhdr_ctrl[2] =
2771 (1ULL << SYM_LSB(DCACtrlD, RcvHdrq8DCAXfrCnt)) |
2772 (1ULL << SYM_LSB(DCACtrlD, RcvHdrq9DCAXfrCnt)) |
2773 (1ULL << SYM_LSB(DCACtrlD, RcvHdrq10DCAXfrCnt)) |
2774 (1ULL << SYM_LSB(DCACtrlD, RcvHdrq11DCAXfrCnt));
2775 cspec->dca_rcvhdr_ctrl[3] =
2776 (1ULL << SYM_LSB(DCACtrlE, RcvHdrq12DCAXfrCnt)) |
2777 (1ULL << SYM_LSB(DCACtrlE, RcvHdrq13DCAXfrCnt)) |
2778 (1ULL << SYM_LSB(DCACtrlE, RcvHdrq14DCAXfrCnt)) |
2779 (1ULL << SYM_LSB(DCACtrlE, RcvHdrq15DCAXfrCnt));
2780 cspec->dca_rcvhdr_ctrl[4] =
2781 (1ULL << SYM_LSB(DCACtrlF, RcvHdrq16DCAXfrCnt)) |
2782 (1ULL << SYM_LSB(DCACtrlF, RcvHdrq17DCAXfrCnt));
2783 for (i = 0; i < ARRAY_SIZE(cspec->sdma_cpu); i++)
2784 qib_write_kreg(dd, KREG_IDX(DCACtrlB) + i,
2785 cspec->dca_rcvhdr_ctrl[i]);
2786 for (i = 0; i < cspec->num_msix_entries; i++)
2787 setup_dca_notifier(dd, &cspec->msix_entries[i]);
2788}
2789
2790static void qib_irq_notifier_notify(struct irq_affinity_notify *notify,
2791 const cpumask_t *mask)
2792{
2793 struct qib_irq_notify *n =
2794 container_of(notify, struct qib_irq_notify, notify);
2795 int cpu = cpumask_first(mask);
2796
2797 if (n->rcv) {
2798 struct qib_ctxtdata *rcd = (struct qib_ctxtdata *)n->arg;
2799 qib_update_rhdrq_dca(rcd, cpu);
2800 } else {
2801 struct qib_pportdata *ppd = (struct qib_pportdata *)n->arg;
2802 qib_update_sdma_dca(ppd, cpu);
2803 }
2804}
2805
2806static void qib_irq_notifier_release(struct kref *ref)
2807{
2808 struct qib_irq_notify *n =
2809 container_of(ref, struct qib_irq_notify, notify.kref);
2810 struct qib_devdata *dd;
2811
2812 if (n->rcv) {
2813 struct qib_ctxtdata *rcd = (struct qib_ctxtdata *)n->arg;
2814 dd = rcd->dd;
2815 } else {
2816 struct qib_pportdata *ppd = (struct qib_pportdata *)n->arg;
2817 dd = ppd->dd;
2818 }
2819 qib_devinfo(dd->pcidev,
2820 "release on HCA notify 0x%p n 0x%p\n", ref, n);
2821 kfree(n);
2822}
2823#endif
2824
2825
2826
2827
2828
2829
2830static void qib_7322_nomsix(struct qib_devdata *dd)
2831{
2832 u64 intgranted;
2833 int n;
2834
2835 dd->cspec->main_int_mask = ~0ULL;
2836 n = dd->cspec->num_msix_entries;
2837 if (n) {
2838 int i;
2839
2840 dd->cspec->num_msix_entries = 0;
2841 for (i = 0; i < n; i++) {
2842#ifdef CONFIG_INFINIBAND_QIB_DCA
2843 reset_dca_notifier(dd, &dd->cspec->msix_entries[i]);
2844#endif
2845 irq_set_affinity_hint(
2846 dd->cspec->msix_entries[i].msix.vector, NULL);
2847 free_cpumask_var(dd->cspec->msix_entries[i].mask);
2848 free_irq(dd->cspec->msix_entries[i].msix.vector,
2849 dd->cspec->msix_entries[i].arg);
2850 }
2851 qib_nomsix(dd);
2852 }
2853
2854 intgranted = qib_read_kreg64(dd, kr_intgranted);
2855 if (intgranted)
2856 qib_write_kreg(dd, kr_intgranted, intgranted);
2857}
2858
2859static void qib_7322_free_irq(struct qib_devdata *dd)
2860{
2861 if (dd->cspec->irq) {
2862 free_irq(dd->cspec->irq, dd);
2863 dd->cspec->irq = 0;
2864 }
2865 qib_7322_nomsix(dd);
2866}
2867
2868static void qib_setup_7322_cleanup(struct qib_devdata *dd)
2869{
2870 int i;
2871
2872#ifdef CONFIG_INFINIBAND_QIB_DCA
2873 if (dd->flags & QIB_DCA_ENABLED) {
2874 dca_remove_requester(&dd->pcidev->dev);
2875 dd->flags &= ~QIB_DCA_ENABLED;
2876 dd->cspec->dca_ctrl = 0;
2877 qib_write_kreg(dd, KREG_IDX(DCACtrlA), dd->cspec->dca_ctrl);
2878 }
2879#endif
2880
2881 qib_7322_free_irq(dd);
2882 kfree(dd->cspec->cntrs);
2883 kfree(dd->cspec->sendchkenable);
2884 kfree(dd->cspec->sendgrhchk);
2885 kfree(dd->cspec->sendibchk);
2886 kfree(dd->cspec->msix_entries);
2887 for (i = 0; i < dd->num_pports; i++) {
2888 unsigned long flags;
2889 u32 mask = QSFP_GPIO_MOD_PRS_N |
2890 (QSFP_GPIO_MOD_PRS_N << QSFP_GPIO_PORT2_SHIFT);
2891
2892 kfree(dd->pport[i].cpspec->portcntrs);
2893 if (dd->flags & QIB_HAS_QSFP) {
2894 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
2895 dd->cspec->gpio_mask &= ~mask;
2896 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
2897 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
2898 qib_qsfp_deinit(&dd->pport[i].cpspec->qsfp_data);
2899 }
2900 if (dd->pport[i].ibport_data.smi_ah)
2901 ib_destroy_ah(&dd->pport[i].ibport_data.smi_ah->ibah);
2902 }
2903}
2904
2905
2906static void sdma_7322_intr(struct qib_devdata *dd, u64 istat)
2907{
2908 struct qib_pportdata *ppd0 = &dd->pport[0];
2909 struct qib_pportdata *ppd1 = &dd->pport[1];
2910 u64 intr0 = istat & (INT_MASK_P(SDma, 0) |
2911 INT_MASK_P(SDmaIdle, 0) | INT_MASK_P(SDmaProgress, 0));
2912 u64 intr1 = istat & (INT_MASK_P(SDma, 1) |
2913 INT_MASK_P(SDmaIdle, 1) | INT_MASK_P(SDmaProgress, 1));
2914
2915 if (intr0)
2916 qib_sdma_intr(ppd0);
2917 if (intr1)
2918 qib_sdma_intr(ppd1);
2919
2920 if (istat & INT_MASK_PM(SDmaCleanupDone, 0))
2921 qib_sdma_process_event(ppd0, qib_sdma_event_e20_hw_started);
2922 if (istat & INT_MASK_PM(SDmaCleanupDone, 1))
2923 qib_sdma_process_event(ppd1, qib_sdma_event_e20_hw_started);
2924}
2925
2926
2927
2928
2929static void qib_wantpiobuf_7322_intr(struct qib_devdata *dd, u32 needint)
2930{
2931 unsigned long flags;
2932
2933 spin_lock_irqsave(&dd->sendctrl_lock, flags);
2934 if (needint)
2935 dd->sendctrl |= SYM_MASK(SendCtrl, SendIntBufAvail);
2936 else
2937 dd->sendctrl &= ~SYM_MASK(SendCtrl, SendIntBufAvail);
2938 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
2939 qib_write_kreg(dd, kr_scratch, 0ULL);
2940 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
2941}
2942
2943
2944
2945
2946
2947
2948static noinline void unknown_7322_ibits(struct qib_devdata *dd, u64 istat)
2949{
2950 u64 kills;
2951 char msg[128];
2952
2953 kills = istat & ~QIB_I_BITSEXTANT;
2954 qib_dev_err(dd,
2955 "Clearing reserved interrupt(s) 0x%016llx: %s\n",
2956 (unsigned long long) kills, msg);
2957 qib_write_kreg(dd, kr_intmask, (dd->cspec->int_enable_mask & ~kills));
2958}
2959
2960
2961static noinline void unknown_7322_gpio_intr(struct qib_devdata *dd)
2962{
2963 u32 gpiostatus;
2964 int handled = 0;
2965 int pidx;
2966
2967
2968
2969
2970
2971
2972
2973
2974 gpiostatus = qib_read_kreg32(dd, kr_gpio_status);
2975
2976
2977
2978
2979
2980
2981
2982 qib_write_kreg(dd, kr_gpio_clear, gpiostatus);
2983
2984
2985
2986
2987 for (pidx = 0; pidx < dd->num_pports && (dd->flags & QIB_HAS_QSFP);
2988 ++pidx) {
2989 struct qib_pportdata *ppd;
2990 struct qib_qsfp_data *qd;
2991 u32 mask;
2992 if (!dd->pport[pidx].link_speed_supported)
2993 continue;
2994 mask = QSFP_GPIO_MOD_PRS_N;
2995 ppd = dd->pport + pidx;
2996 mask <<= (QSFP_GPIO_PORT2_SHIFT * ppd->hw_pidx);
2997 if (gpiostatus & dd->cspec->gpio_mask & mask) {
2998 u64 pins;
2999 qd = &ppd->cpspec->qsfp_data;
3000 gpiostatus &= ~mask;
3001 pins = qib_read_kreg64(dd, kr_extstatus);
3002 pins >>= SYM_LSB(EXTStatus, GPIOIn);
3003 if (!(pins & mask)) {
3004 ++handled;
3005 qd->t_insert = jiffies;
3006 queue_work(ib_wq, &qd->work);
3007 }
3008 }
3009 }
3010
3011 if (gpiostatus && !handled) {
3012 const u32 mask = qib_read_kreg32(dd, kr_gpio_mask);
3013 u32 gpio_irq = mask & gpiostatus;
3014
3015
3016
3017
3018 dd->cspec->gpio_mask &= ~gpio_irq;
3019 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
3020 }
3021}
3022
3023
3024
3025
3026
3027static noinline void unlikely_7322_intr(struct qib_devdata *dd, u64 istat)
3028{
3029 if (istat & ~QIB_I_BITSEXTANT)
3030 unknown_7322_ibits(dd, istat);
3031 if (istat & QIB_I_GPIO)
3032 unknown_7322_gpio_intr(dd);
3033 if (istat & QIB_I_C_ERROR) {
3034 qib_write_kreg(dd, kr_errmask, 0ULL);
3035 tasklet_schedule(&dd->error_tasklet);
3036 }
3037 if (istat & INT_MASK_P(Err, 0) && dd->rcd[0])
3038 handle_7322_p_errors(dd->rcd[0]->ppd);
3039 if (istat & INT_MASK_P(Err, 1) && dd->rcd[1])
3040 handle_7322_p_errors(dd->rcd[1]->ppd);
3041}
3042
3043
3044
3045
3046
3047static void adjust_rcv_timeout(struct qib_ctxtdata *rcd, int npkts)
3048{
3049 struct qib_devdata *dd = rcd->dd;
3050 u32 timeout = dd->cspec->rcvavail_timeout[rcd->ctxt];
3051
3052
3053
3054
3055
3056 if (npkts < rcv_int_count && timeout > 2)
3057 timeout >>= 1;
3058 else if (npkts >= rcv_int_count && timeout < rcv_int_timeout)
3059 timeout = min(timeout << 1, rcv_int_timeout);
3060 else
3061 return;
3062
3063 dd->cspec->rcvavail_timeout[rcd->ctxt] = timeout;
3064 qib_write_kreg(dd, kr_rcvavailtimeout + rcd->ctxt, timeout);
3065}
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075static irqreturn_t qib_7322intr(int irq, void *data)
3076{
3077 struct qib_devdata *dd = data;
3078 irqreturn_t ret;
3079 u64 istat;
3080 u64 ctxtrbits;
3081 u64 rmask;
3082 unsigned i;
3083 u32 npkts;
3084
3085 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT) {
3086
3087
3088
3089
3090
3091
3092 ret = IRQ_HANDLED;
3093 goto bail;
3094 }
3095
3096 istat = qib_read_kreg64(dd, kr_intstatus);
3097
3098 if (unlikely(istat == ~0ULL)) {
3099 qib_bad_intrstatus(dd);
3100 qib_dev_err(dd, "Interrupt status all f's, skipping\n");
3101
3102 ret = IRQ_NONE;
3103 goto bail;
3104 }
3105
3106 istat &= dd->cspec->main_int_mask;
3107 if (unlikely(!istat)) {
3108
3109 ret = IRQ_NONE;
3110 goto bail;
3111 }
3112
3113 qib_stats.sps_ints++;
3114 if (dd->int_counter != (u32) -1)
3115 dd->int_counter++;
3116
3117
3118 if (unlikely(istat & (~QIB_I_BITSEXTANT | QIB_I_GPIO |
3119 QIB_I_C_ERROR | INT_MASK_P(Err, 0) |
3120 INT_MASK_P(Err, 1))))
3121 unlikely_7322_intr(dd, istat);
3122
3123
3124
3125
3126
3127
3128
3129 qib_write_kreg(dd, kr_intclear, istat);
3130
3131
3132
3133
3134
3135
3136 ctxtrbits = istat & (QIB_I_RCVAVAIL_MASK | QIB_I_RCVURG_MASK);
3137 if (ctxtrbits) {
3138 rmask = (1ULL << QIB_I_RCVAVAIL_LSB) |
3139 (1ULL << QIB_I_RCVURG_LSB);
3140 for (i = 0; i < dd->first_user_ctxt; i++) {
3141 if (ctxtrbits & rmask) {
3142 ctxtrbits &= ~rmask;
3143 if (dd->rcd[i])
3144 qib_kreceive(dd->rcd[i], NULL, &npkts);
3145 }
3146 rmask <<= 1;
3147 }
3148 if (ctxtrbits) {
3149 ctxtrbits = (ctxtrbits >> QIB_I_RCVAVAIL_LSB) |
3150 (ctxtrbits >> QIB_I_RCVURG_LSB);
3151 qib_handle_urcv(dd, ctxtrbits);
3152 }
3153 }
3154
3155 if (istat & (QIB_I_P_SDMAINT(0) | QIB_I_P_SDMAINT(1)))
3156 sdma_7322_intr(dd, istat);
3157
3158 if ((istat & QIB_I_SPIOBUFAVAIL) && (dd->flags & QIB_INITTED))
3159 qib_ib_piobufavail(dd);
3160
3161 ret = IRQ_HANDLED;
3162bail:
3163 return ret;
3164}
3165
3166
3167
3168
3169static irqreturn_t qib_7322pintr(int irq, void *data)
3170{
3171 struct qib_ctxtdata *rcd = data;
3172 struct qib_devdata *dd = rcd->dd;
3173 u32 npkts;
3174
3175 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
3176
3177
3178
3179
3180
3181
3182 return IRQ_HANDLED;
3183
3184 qib_stats.sps_ints++;
3185 if (dd->int_counter != (u32) -1)
3186 dd->int_counter++;
3187
3188
3189 qib_write_kreg(dd, kr_intclear, ((1ULL << QIB_I_RCVAVAIL_LSB) |
3190 (1ULL << QIB_I_RCVURG_LSB)) << rcd->ctxt);
3191
3192 qib_kreceive(rcd, NULL, &npkts);
3193
3194 return IRQ_HANDLED;
3195}
3196
3197
3198
3199
3200static irqreturn_t qib_7322bufavail(int irq, void *data)
3201{
3202 struct qib_devdata *dd = data;
3203
3204 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
3205
3206
3207
3208
3209
3210
3211 return IRQ_HANDLED;
3212
3213 qib_stats.sps_ints++;
3214 if (dd->int_counter != (u32) -1)
3215 dd->int_counter++;
3216
3217
3218 qib_write_kreg(dd, kr_intclear, QIB_I_SPIOBUFAVAIL);
3219
3220
3221 if (dd->flags & QIB_INITTED)
3222 qib_ib_piobufavail(dd);
3223 else
3224 qib_wantpiobuf_7322_intr(dd, 0);
3225
3226 return IRQ_HANDLED;
3227}
3228
3229
3230
3231
3232static irqreturn_t sdma_intr(int irq, void *data)
3233{
3234 struct qib_pportdata *ppd = data;
3235 struct qib_devdata *dd = ppd->dd;
3236
3237 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
3238
3239
3240
3241
3242
3243
3244 return IRQ_HANDLED;
3245
3246 qib_stats.sps_ints++;
3247 if (dd->int_counter != (u32) -1)
3248 dd->int_counter++;
3249
3250
3251 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
3252 INT_MASK_P(SDma, 1) : INT_MASK_P(SDma, 0));
3253 qib_sdma_intr(ppd);
3254
3255 return IRQ_HANDLED;
3256}
3257
3258
3259
3260
3261static irqreturn_t sdma_idle_intr(int irq, void *data)
3262{
3263 struct qib_pportdata *ppd = data;
3264 struct qib_devdata *dd = ppd->dd;
3265
3266 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
3267
3268
3269
3270
3271
3272
3273 return IRQ_HANDLED;
3274
3275 qib_stats.sps_ints++;
3276 if (dd->int_counter != (u32) -1)
3277 dd->int_counter++;
3278
3279
3280 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
3281 INT_MASK_P(SDmaIdle, 1) : INT_MASK_P(SDmaIdle, 0));
3282 qib_sdma_intr(ppd);
3283
3284 return IRQ_HANDLED;
3285}
3286
3287
3288
3289
3290static irqreturn_t sdma_progress_intr(int irq, void *data)
3291{
3292 struct qib_pportdata *ppd = data;
3293 struct qib_devdata *dd = ppd->dd;
3294
3295 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
3296
3297
3298
3299
3300
3301
3302 return IRQ_HANDLED;
3303
3304 qib_stats.sps_ints++;
3305 if (dd->int_counter != (u32) -1)
3306 dd->int_counter++;
3307
3308
3309 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
3310 INT_MASK_P(SDmaProgress, 1) :
3311 INT_MASK_P(SDmaProgress, 0));
3312 qib_sdma_intr(ppd);
3313
3314 return IRQ_HANDLED;
3315}
3316
3317
3318
3319
3320static irqreturn_t sdma_cleanup_intr(int irq, void *data)
3321{
3322 struct qib_pportdata *ppd = data;
3323 struct qib_devdata *dd = ppd->dd;
3324
3325 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
3326
3327
3328
3329
3330
3331
3332 return IRQ_HANDLED;
3333
3334 qib_stats.sps_ints++;
3335 if (dd->int_counter != (u32) -1)
3336 dd->int_counter++;
3337
3338
3339 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
3340 INT_MASK_PM(SDmaCleanupDone, 1) :
3341 INT_MASK_PM(SDmaCleanupDone, 0));
3342 qib_sdma_process_event(ppd, qib_sdma_event_e20_hw_started);
3343
3344 return IRQ_HANDLED;
3345}
3346
3347#ifdef CONFIG_INFINIBAND_QIB_DCA
3348
3349static void reset_dca_notifier(struct qib_devdata *dd, struct qib_msix_entry *m)
3350{
3351 if (!m->dca)
3352 return;
3353 qib_devinfo(dd->pcidev,
3354 "Disabling notifier on HCA %d irq %d\n",
3355 dd->unit,
3356 m->msix.vector);
3357 irq_set_affinity_notifier(
3358 m->msix.vector,
3359 NULL);
3360 m->notifier = NULL;
3361}
3362
3363static void setup_dca_notifier(struct qib_devdata *dd, struct qib_msix_entry *m)
3364{
3365 struct qib_irq_notify *n;
3366
3367 if (!m->dca)
3368 return;
3369 n = kzalloc(sizeof(*n), GFP_KERNEL);
3370 if (n) {
3371 int ret;
3372
3373 m->notifier = n;
3374 n->notify.irq = m->msix.vector;
3375 n->notify.notify = qib_irq_notifier_notify;
3376 n->notify.release = qib_irq_notifier_release;
3377 n->arg = m->arg;
3378 n->rcv = m->rcv;
3379 qib_devinfo(dd->pcidev,
3380 "set notifier irq %d rcv %d notify %p\n",
3381 n->notify.irq, n->rcv, &n->notify);
3382 ret = irq_set_affinity_notifier(
3383 n->notify.irq,
3384 &n->notify);
3385 if (ret) {
3386 m->notifier = NULL;
3387 kfree(n);
3388 }
3389 }
3390}
3391
3392#endif
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402static void qib_setup_7322_interrupt(struct qib_devdata *dd, int clearpend)
3403{
3404 int ret, i, msixnum;
3405 u64 redirect[6];
3406 u64 mask;
3407 const struct cpumask *local_mask;
3408 int firstcpu, secondcpu = 0, currrcvcpu = 0;
3409
3410 if (!dd->num_pports)
3411 return;
3412
3413 if (clearpend) {
3414
3415
3416
3417
3418
3419 qib_7322_set_intr_state(dd, 0);
3420
3421
3422 qib_7322_init_hwerrors(dd);
3423
3424
3425 qib_write_kreg(dd, kr_intclear, ~0ULL);
3426
3427
3428 qib_write_kreg(dd, kr_intgranted, ~0ULL);
3429 qib_write_kreg(dd, kr_vecclr_wo_int, ~0ULL);
3430 }
3431
3432 if (!dd->cspec->num_msix_entries) {
3433
3434try_intx:
3435 if (!dd->pcidev->irq) {
3436 qib_dev_err(dd,
3437 "irq is 0, BIOS error? Interrupts won't work\n");
3438 goto bail;
3439 }
3440 ret = request_irq(dd->pcidev->irq, qib_7322intr,
3441 IRQF_SHARED, QIB_DRV_NAME, dd);
3442 if (ret) {
3443 qib_dev_err(dd,
3444 "Couldn't setup INTx interrupt (irq=%d): %d\n",
3445 dd->pcidev->irq, ret);
3446 goto bail;
3447 }
3448 dd->cspec->irq = dd->pcidev->irq;
3449 dd->cspec->main_int_mask = ~0ULL;
3450 goto bail;
3451 }
3452
3453
3454 memset(redirect, 0, sizeof redirect);
3455 mask = ~0ULL;
3456 msixnum = 0;
3457 local_mask = cpumask_of_pcibus(dd->pcidev->bus);
3458 firstcpu = cpumask_first(local_mask);
3459 if (firstcpu >= nr_cpu_ids ||
3460 cpumask_weight(local_mask) == num_online_cpus()) {
3461 local_mask = topology_core_cpumask(0);
3462 firstcpu = cpumask_first(local_mask);
3463 }
3464 if (firstcpu < nr_cpu_ids) {
3465 secondcpu = cpumask_next(firstcpu, local_mask);
3466 if (secondcpu >= nr_cpu_ids)
3467 secondcpu = firstcpu;
3468 currrcvcpu = secondcpu;
3469 }
3470 for (i = 0; msixnum < dd->cspec->num_msix_entries; i++) {
3471 irq_handler_t handler;
3472 void *arg;
3473 u64 val;
3474 int lsb, reg, sh;
3475#ifdef CONFIG_INFINIBAND_QIB_DCA
3476 int dca = 0;
3477#endif
3478
3479 dd->cspec->msix_entries[msixnum].
3480 name[sizeof(dd->cspec->msix_entries[msixnum].name) - 1]
3481 = '\0';
3482 if (i < ARRAY_SIZE(irq_table)) {
3483 if (irq_table[i].port) {
3484
3485 if (irq_table[i].port > dd->num_pports)
3486 continue;
3487 arg = dd->pport + irq_table[i].port - 1;
3488 } else
3489 arg = dd;
3490#ifdef CONFIG_INFINIBAND_QIB_DCA
3491 dca = irq_table[i].dca;
3492#endif
3493 lsb = irq_table[i].lsb;
3494 handler = irq_table[i].handler;
3495 snprintf(dd->cspec->msix_entries[msixnum].name,
3496 sizeof(dd->cspec->msix_entries[msixnum].name)
3497 - 1,
3498 QIB_DRV_NAME "%d%s", dd->unit,
3499 irq_table[i].name);
3500 } else {
3501 unsigned ctxt;
3502
3503 ctxt = i - ARRAY_SIZE(irq_table);
3504
3505 arg = dd->rcd[ctxt];
3506 if (!arg)
3507 continue;
3508 if (qib_krcvq01_no_msi && ctxt < 2)
3509 continue;
3510#ifdef CONFIG_INFINIBAND_QIB_DCA
3511 dca = 1;
3512#endif
3513 lsb = QIB_I_RCVAVAIL_LSB + ctxt;
3514 handler = qib_7322pintr;
3515 snprintf(dd->cspec->msix_entries[msixnum].name,
3516 sizeof(dd->cspec->msix_entries[msixnum].name)
3517 - 1,
3518 QIB_DRV_NAME "%d (kctx)", dd->unit);
3519 }
3520 ret = request_irq(
3521 dd->cspec->msix_entries[msixnum].msix.vector,
3522 handler, 0, dd->cspec->msix_entries[msixnum].name,
3523 arg);
3524 if (ret) {
3525
3526
3527
3528
3529 qib_dev_err(dd,
3530 "Couldn't setup MSIx interrupt (vec=%d, irq=%d): %d\n",
3531 msixnum,
3532 dd->cspec->msix_entries[msixnum].msix.vector,
3533 ret);
3534 qib_7322_nomsix(dd);
3535 goto try_intx;
3536 }
3537 dd->cspec->msix_entries[msixnum].arg = arg;
3538#ifdef CONFIG_INFINIBAND_QIB_DCA
3539 dd->cspec->msix_entries[msixnum].dca = dca;
3540 dd->cspec->msix_entries[msixnum].rcv =
3541 handler == qib_7322pintr;
3542#endif
3543 if (lsb >= 0) {
3544 reg = lsb / IBA7322_REDIRECT_VEC_PER_REG;
3545 sh = (lsb % IBA7322_REDIRECT_VEC_PER_REG) *
3546 SYM_LSB(IntRedirect0, vec1);
3547 mask &= ~(1ULL << lsb);
3548 redirect[reg] |= ((u64) msixnum) << sh;
3549 }
3550 val = qib_read_kreg64(dd, 2 * msixnum + 1 +
3551 (QIB_7322_MsixTable_OFFS / sizeof(u64)));
3552 if (firstcpu < nr_cpu_ids &&
3553 zalloc_cpumask_var(
3554 &dd->cspec->msix_entries[msixnum].mask,
3555 GFP_KERNEL)) {
3556 if (handler == qib_7322pintr) {
3557 cpumask_set_cpu(currrcvcpu,
3558 dd->cspec->msix_entries[msixnum].mask);
3559 currrcvcpu = cpumask_next(currrcvcpu,
3560 local_mask);
3561 if (currrcvcpu >= nr_cpu_ids)
3562 currrcvcpu = secondcpu;
3563 } else {
3564 cpumask_set_cpu(firstcpu,
3565 dd->cspec->msix_entries[msixnum].mask);
3566 }
3567 irq_set_affinity_hint(
3568 dd->cspec->msix_entries[msixnum].msix.vector,
3569 dd->cspec->msix_entries[msixnum].mask);
3570 }
3571 msixnum++;
3572 }
3573
3574 for (i = 0; i < ARRAY_SIZE(redirect); i++)
3575 qib_write_kreg(dd, kr_intredirect + i, redirect[i]);
3576 dd->cspec->main_int_mask = mask;
3577 tasklet_init(&dd->error_tasklet, qib_error_tasklet,
3578 (unsigned long)dd);
3579bail:;
3580}
3581
3582
3583
3584
3585
3586
3587
3588static unsigned qib_7322_boardname(struct qib_devdata *dd)
3589{
3590
3591 char *n;
3592 u32 boardid, namelen;
3593 unsigned features = DUAL_PORT_CAP;
3594
3595 boardid = SYM_FIELD(dd->revision, Revision, BoardID);
3596
3597 switch (boardid) {
3598 case 0:
3599 n = "InfiniPath_QLE7342_Emulation";
3600 break;
3601 case 1:
3602 n = "InfiniPath_QLE7340";
3603 dd->flags |= QIB_HAS_QSFP;
3604 features = PORT_SPD_CAP;
3605 break;
3606 case 2:
3607 n = "InfiniPath_QLE7342";
3608 dd->flags |= QIB_HAS_QSFP;
3609 break;
3610 case 3:
3611 n = "InfiniPath_QMI7342";
3612 break;
3613 case 4:
3614 n = "InfiniPath_Unsupported7342";
3615 qib_dev_err(dd, "Unsupported version of QMH7342\n");
3616 features = 0;
3617 break;
3618 case BOARD_QMH7342:
3619 n = "InfiniPath_QMH7342";
3620 features = 0x24;
3621 break;
3622 case BOARD_QME7342:
3623 n = "InfiniPath_QME7342";
3624 break;
3625 case 8:
3626 n = "InfiniPath_QME7362";
3627 dd->flags |= QIB_HAS_QSFP;
3628 break;
3629 case 15:
3630 n = "InfiniPath_QLE7342_TEST";
3631 dd->flags |= QIB_HAS_QSFP;
3632 break;
3633 default:
3634 n = "InfiniPath_QLE73xy_UNKNOWN";
3635 qib_dev_err(dd, "Unknown 7322 board type %u\n", boardid);
3636 break;
3637 }
3638 dd->board_atten = 1;
3639
3640 namelen = strlen(n) + 1;
3641 dd->boardname = kmalloc(namelen, GFP_KERNEL);
3642 if (!dd->boardname)
3643 qib_dev_err(dd, "Failed allocation for board name: %s\n", n);
3644 else
3645 snprintf(dd->boardname, namelen, "%s", n);
3646
3647 snprintf(dd->boardversion, sizeof(dd->boardversion),
3648 "ChipABI %u.%u, %s, InfiniPath%u %u.%u, SW Compat %u\n",
3649 QIB_CHIP_VERS_MAJ, QIB_CHIP_VERS_MIN, dd->boardname,
3650 (unsigned)SYM_FIELD(dd->revision, Revision_R, Arch),
3651 dd->majrev, dd->minrev,
3652 (unsigned)SYM_FIELD(dd->revision, Revision_R, SW));
3653
3654 if (qib_singleport && (features >> PORT_SPD_CAP_SHIFT) & PORT_SPD_CAP) {
3655 qib_devinfo(dd->pcidev,
3656 "IB%u: Forced to single port mode by module parameter\n",
3657 dd->unit);
3658 features &= PORT_SPD_CAP;
3659 }
3660
3661 return features;
3662}
3663
3664
3665
3666
3667
3668static int qib_do_7322_reset(struct qib_devdata *dd)
3669{
3670 u64 val;
3671 u64 *msix_vecsave;
3672 int i, msix_entries, ret = 1;
3673 u16 cmdval;
3674 u8 int_line, clinesz;
3675 unsigned long flags;
3676
3677
3678 qib_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->unit);
3679
3680 qib_pcie_getcmd(dd, &cmdval, &int_line, &clinesz);
3681
3682 msix_entries = dd->cspec->num_msix_entries;
3683
3684
3685 qib_7322_set_intr_state(dd, 0);
3686
3687 if (msix_entries) {
3688 qib_7322_nomsix(dd);
3689
3690 msix_vecsave = kmalloc(2 * dd->cspec->num_msix_entries *
3691 sizeof(u64), GFP_KERNEL);
3692 if (!msix_vecsave)
3693 qib_dev_err(dd, "No mem to save MSIx data\n");
3694 } else
3695 msix_vecsave = NULL;
3696
3697
3698
3699
3700
3701
3702
3703
3704 for (i = 0; i < msix_entries; i++) {
3705 u64 vecaddr, vecdata;
3706 vecaddr = qib_read_kreg64(dd, 2 * i +
3707 (QIB_7322_MsixTable_OFFS / sizeof(u64)));
3708 vecdata = qib_read_kreg64(dd, 1 + 2 * i +
3709 (QIB_7322_MsixTable_OFFS / sizeof(u64)));
3710 if (msix_vecsave) {
3711 msix_vecsave[2 * i] = vecaddr;
3712
3713 msix_vecsave[1 + 2 * i] = vecdata & ~0x100000000ULL;
3714 }
3715 }
3716
3717 dd->pport->cpspec->ibdeltainprog = 0;
3718 dd->pport->cpspec->ibsymdelta = 0;
3719 dd->pport->cpspec->iblnkerrdelta = 0;
3720 dd->pport->cpspec->ibmalfdelta = 0;
3721 dd->int_counter = 0;
3722
3723
3724
3725
3726
3727
3728 dd->flags &= ~(QIB_INITTED | QIB_PRESENT | QIB_BADINTR);
3729 dd->flags |= QIB_DOING_RESET;
3730 val = dd->control | QLOGIC_IB_C_RESET;
3731 writeq(val, &dd->kregbase[kr_control]);
3732
3733 for (i = 1; i <= 5; i++) {
3734
3735
3736
3737
3738
3739 msleep(1000 + (1 + i) * 3000);
3740
3741 qib_pcie_reenable(dd, cmdval, int_line, clinesz);
3742
3743
3744
3745
3746
3747 val = readq(&dd->kregbase[kr_revision]);
3748 if (val == dd->revision)
3749 break;
3750 if (i == 5) {
3751 qib_dev_err(dd,
3752 "Failed to initialize after reset, unusable\n");
3753 ret = 0;
3754 goto bail;
3755 }
3756 }
3757
3758 dd->flags |= QIB_PRESENT;
3759
3760 if (msix_entries) {
3761
3762 for (i = 0; i < msix_entries; i++) {
3763 dd->cspec->msix_entries[i].msix.entry = i;
3764 if (!msix_vecsave || !msix_vecsave[2 * i])
3765 continue;
3766 qib_write_kreg(dd, 2 * i +
3767 (QIB_7322_MsixTable_OFFS / sizeof(u64)),
3768 msix_vecsave[2 * i]);
3769 qib_write_kreg(dd, 1 + 2 * i +
3770 (QIB_7322_MsixTable_OFFS / sizeof(u64)),
3771 msix_vecsave[1 + 2 * i]);
3772 }
3773 }
3774
3775
3776 for (i = 0; i < dd->num_pports; ++i)
3777 write_7322_init_portregs(&dd->pport[i]);
3778 write_7322_initregs(dd);
3779
3780 if (qib_pcie_params(dd, dd->lbus_width,
3781 &dd->cspec->num_msix_entries,
3782 dd->cspec->msix_entries))
3783 qib_dev_err(dd,
3784 "Reset failed to setup PCIe or interrupts; continuing anyway\n");
3785
3786 qib_setup_7322_interrupt(dd, 1);
3787
3788 for (i = 0; i < dd->num_pports; ++i) {
3789 struct qib_pportdata *ppd = &dd->pport[i];
3790
3791 spin_lock_irqsave(&ppd->lflags_lock, flags);
3792 ppd->lflags |= QIBL_IB_FORCE_NOTIFY;
3793 ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
3794 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
3795 }
3796
3797bail:
3798 dd->flags &= ~QIB_DOING_RESET;
3799 kfree(msix_vecsave);
3800 return ret;
3801}
3802
3803
3804
3805
3806
3807
3808
3809
3810static void qib_7322_put_tid(struct qib_devdata *dd, u64 __iomem *tidptr,
3811 u32 type, unsigned long pa)
3812{
3813 if (!(dd->flags & QIB_PRESENT))
3814 return;
3815 if (pa != dd->tidinvalid) {
3816 u64 chippa = pa >> IBA7322_TID_PA_SHIFT;
3817
3818
3819 if (pa != (chippa << IBA7322_TID_PA_SHIFT)) {
3820 qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
3821 pa);
3822 return;
3823 }
3824 if (chippa >= (1UL << IBA7322_TID_SZ_SHIFT)) {
3825 qib_dev_err(dd,
3826 "Physical page address 0x%lx larger than supported\n",
3827 pa);
3828 return;
3829 }
3830
3831 if (type == RCVHQ_RCV_TYPE_EAGER)
3832 chippa |= dd->tidtemplate;
3833 else
3834 chippa |= IBA7322_TID_SZ_4K;
3835 pa = chippa;
3836 }
3837 writeq(pa, tidptr);
3838 mmiowb();
3839}
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849static void qib_7322_clear_tids(struct qib_devdata *dd,
3850 struct qib_ctxtdata *rcd)
3851{
3852 u64 __iomem *tidbase;
3853 unsigned long tidinv;
3854 u32 ctxt;
3855 int i;
3856
3857 if (!dd->kregbase || !rcd)
3858 return;
3859
3860 ctxt = rcd->ctxt;
3861
3862 tidinv = dd->tidinvalid;
3863 tidbase = (u64 __iomem *)
3864 ((char __iomem *) dd->kregbase +
3865 dd->rcvtidbase +
3866 ctxt * dd->rcvtidcnt * sizeof(*tidbase));
3867
3868 for (i = 0; i < dd->rcvtidcnt; i++)
3869 qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
3870 tidinv);
3871
3872 tidbase = (u64 __iomem *)
3873 ((char __iomem *) dd->kregbase +
3874 dd->rcvegrbase +
3875 rcd->rcvegr_tid_base * sizeof(*tidbase));
3876
3877 for (i = 0; i < rcd->rcvegrcnt; i++)
3878 qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
3879 tidinv);
3880}
3881
3882
3883
3884
3885
3886
3887
3888static void qib_7322_tidtemplate(struct qib_devdata *dd)
3889{
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899 if (dd->rcvegrbufsize == 2048)
3900 dd->tidtemplate = IBA7322_TID_SZ_2K;
3901 else if (dd->rcvegrbufsize == 4096)
3902 dd->tidtemplate = IBA7322_TID_SZ_4K;
3903 dd->tidinvalid = 0;
3904}
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915static int qib_7322_get_base_info(struct qib_ctxtdata *rcd,
3916 struct qib_base_info *kinfo)
3917{
3918 kinfo->spi_runtime_flags |= QIB_RUNTIME_CTXT_MSB_IN_QP |
3919 QIB_RUNTIME_PCIE | QIB_RUNTIME_NODMA_RTAIL |
3920 QIB_RUNTIME_HDRSUPP | QIB_RUNTIME_SDMA;
3921 if (rcd->dd->cspec->r1)
3922 kinfo->spi_runtime_flags |= QIB_RUNTIME_RCHK;
3923 if (rcd->dd->flags & QIB_USE_SPCL_TRIG)
3924 kinfo->spi_runtime_flags |= QIB_RUNTIME_SPECIAL_TRIGGER;
3925
3926 return 0;
3927}
3928
3929static struct qib_message_header *
3930qib_7322_get_msgheader(struct qib_devdata *dd, __le32 *rhf_addr)
3931{
3932 u32 offset = qib_hdrget_offset(rhf_addr);
3933
3934 return (struct qib_message_header *)
3935 (rhf_addr - dd->rhf_offset + offset);
3936}
3937
3938
3939
3940
3941static void qib_7322_config_ctxts(struct qib_devdata *dd)
3942{
3943 unsigned long flags;
3944 u32 nchipctxts;
3945
3946 nchipctxts = qib_read_kreg32(dd, kr_contextcnt);
3947 dd->cspec->numctxts = nchipctxts;
3948 if (qib_n_krcv_queues > 1 && dd->num_pports) {
3949 dd->first_user_ctxt = NUM_IB_PORTS +
3950 (qib_n_krcv_queues - 1) * dd->num_pports;
3951 if (dd->first_user_ctxt > nchipctxts)
3952 dd->first_user_ctxt = nchipctxts;
3953 dd->n_krcv_queues = dd->first_user_ctxt / dd->num_pports;
3954 } else {
3955 dd->first_user_ctxt = NUM_IB_PORTS;
3956 dd->n_krcv_queues = 1;
3957 }
3958
3959 if (!qib_cfgctxts) {
3960 int nctxts = dd->first_user_ctxt + num_online_cpus();
3961
3962 if (nctxts <= 6)
3963 dd->ctxtcnt = 6;
3964 else if (nctxts <= 10)
3965 dd->ctxtcnt = 10;
3966 else if (nctxts <= nchipctxts)
3967 dd->ctxtcnt = nchipctxts;
3968 } else if (qib_cfgctxts < dd->num_pports)
3969 dd->ctxtcnt = dd->num_pports;
3970 else if (qib_cfgctxts <= nchipctxts)
3971 dd->ctxtcnt = qib_cfgctxts;
3972 if (!dd->ctxtcnt)
3973 dd->ctxtcnt = nchipctxts;
3974
3975
3976
3977
3978
3979
3980 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
3981 if (dd->ctxtcnt > 10)
3982 dd->rcvctrl |= 2ULL << SYM_LSB(RcvCtrl, ContextCfg);
3983 else if (dd->ctxtcnt > 6)
3984 dd->rcvctrl |= 1ULL << SYM_LSB(RcvCtrl, ContextCfg);
3985
3986
3987
3988 dd->rcvctrl |= 5ULL << SYM_LSB(RcvCtrl, XrcTypeCode);
3989
3990
3991
3992
3993
3994 qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
3995 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
3996
3997
3998 dd->cspec->rcvegrcnt = qib_read_kreg32(dd, kr_rcvegrcnt);
3999 if (qib_rcvhdrcnt)
4000 dd->rcvhdrcnt = max(dd->cspec->rcvegrcnt, qib_rcvhdrcnt);
4001 else
4002 dd->rcvhdrcnt = 2 * max(dd->cspec->rcvegrcnt,
4003 dd->num_pports > 1 ? 1024U : 2048U);
4004}
4005
4006static int qib_7322_get_ib_cfg(struct qib_pportdata *ppd, int which)
4007{
4008
4009 int lsb, ret = 0;
4010 u64 maskr;
4011
4012 switch (which) {
4013
4014 case QIB_IB_CFG_LWID_ENB:
4015 ret = ppd->link_width_enabled;
4016 goto done;
4017
4018 case QIB_IB_CFG_LWID:
4019 ret = ppd->link_width_active;
4020 goto done;
4021
4022 case QIB_IB_CFG_SPD_ENB:
4023 ret = ppd->link_speed_enabled;
4024 goto done;
4025
4026 case QIB_IB_CFG_SPD:
4027 ret = ppd->link_speed_active;
4028 goto done;
4029
4030 case QIB_IB_CFG_RXPOL_ENB:
4031 lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
4032 maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
4033 break;
4034
4035 case QIB_IB_CFG_LREV_ENB:
4036 lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
4037 maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
4038 break;
4039
4040 case QIB_IB_CFG_LINKLATENCY:
4041 ret = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
4042 SYM_MASK(IBCStatusB_0, LinkRoundTripLatency);
4043 goto done;
4044
4045 case QIB_IB_CFG_OP_VLS:
4046 ret = ppd->vls_operational;
4047 goto done;
4048
4049 case QIB_IB_CFG_VL_HIGH_CAP:
4050 ret = 16;
4051 goto done;
4052
4053 case QIB_IB_CFG_VL_LOW_CAP:
4054 ret = 16;
4055 goto done;
4056
4057 case QIB_IB_CFG_OVERRUN_THRESH:
4058 ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
4059 OverrunThreshold);
4060 goto done;
4061
4062 case QIB_IB_CFG_PHYERR_THRESH:
4063 ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
4064 PhyerrThreshold);
4065 goto done;
4066
4067 case QIB_IB_CFG_LINKDEFAULT:
4068
4069 ret = (ppd->cpspec->ibcctrl_a &
4070 SYM_MASK(IBCCtrlA_0, LinkDownDefaultState)) ?
4071 IB_LINKINITCMD_SLEEP : IB_LINKINITCMD_POLL;
4072 goto done;
4073
4074 case QIB_IB_CFG_HRTBT:
4075 lsb = IBA7322_IBC_HRTBT_LSB;
4076 maskr = IBA7322_IBC_HRTBT_RMASK;
4077 break;
4078
4079 case QIB_IB_CFG_PMA_TICKS:
4080
4081
4082
4083
4084 if (ppd->link_speed_active == QIB_IB_QDR)
4085 ret = 3;
4086 else if (ppd->link_speed_active == QIB_IB_DDR)
4087 ret = 1;
4088 else
4089 ret = 0;
4090 goto done;
4091
4092 default:
4093 ret = -EINVAL;
4094 goto done;
4095 }
4096 ret = (int)((ppd->cpspec->ibcctrl_b >> lsb) & maskr);
4097done:
4098 return ret;
4099}
4100
4101
4102
4103
4104
4105#define IBA7322_IBC_DLIDLMC_SHIFT QIB_7322_IBCCtrlB_0_IB_DLID_LSB
4106#define IBA7322_IBC_DLIDLMC_MASK (QIB_7322_IBCCtrlB_0_IB_DLID_RMASK \
4107 | (QIB_7322_IBCCtrlB_0_IB_DLID_MASK_RMASK << 16))
4108
4109static int qib_7322_set_ib_cfg(struct qib_pportdata *ppd, int which, u32 val)
4110{
4111 struct qib_devdata *dd = ppd->dd;
4112 u64 maskr;
4113 int lsb, ret = 0;
4114 u16 lcmd, licmd;
4115 unsigned long flags;
4116
4117 switch (which) {
4118 case QIB_IB_CFG_LIDLMC:
4119
4120
4121
4122
4123 lsb = IBA7322_IBC_DLIDLMC_SHIFT;
4124 maskr = IBA7322_IBC_DLIDLMC_MASK;
4125
4126
4127
4128
4129
4130
4131
4132 qib_write_kreg_port(ppd, krp_sendslid,
4133 val & (val >> 16) & SendIBSLIDAssignMask);
4134 qib_write_kreg_port(ppd, krp_sendslidmask,
4135 (val >> 16) & SendIBSLMCMask);
4136 break;
4137
4138 case QIB_IB_CFG_LWID_ENB:
4139 ppd->link_width_enabled = val;
4140
4141 if (val == IB_WIDTH_1X)
4142 val = 0;
4143 else if (val == IB_WIDTH_4X)
4144 val = 1;
4145 else
4146 val = 3;
4147 maskr = SYM_RMASK(IBCCtrlB_0, IB_NUM_CHANNELS);
4148 lsb = SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS);
4149 break;
4150
4151 case QIB_IB_CFG_SPD_ENB:
4152
4153
4154
4155
4156
4157
4158
4159 ppd->link_speed_enabled = val;
4160 val <<= IBA7322_IBC_SPEED_LSB;
4161 maskr = IBA7322_IBC_SPEED_MASK | IBA7322_IBC_IBTA_1_2_MASK |
4162 IBA7322_IBC_MAX_SPEED_MASK;
4163 if (val & (val - 1)) {
4164
4165 val |= IBA7322_IBC_IBTA_1_2_MASK |
4166 IBA7322_IBC_MAX_SPEED_MASK;
4167 spin_lock_irqsave(&ppd->lflags_lock, flags);
4168 ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
4169 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
4170 } else if (val & IBA7322_IBC_SPEED_QDR)
4171 val |= IBA7322_IBC_IBTA_1_2_MASK;
4172
4173 lsb = SYM_LSB(IBCCtrlB_0, IB_ENHANCED_MODE);
4174 break;
4175
4176 case QIB_IB_CFG_RXPOL_ENB:
4177 lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
4178 maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
4179 break;
4180
4181 case QIB_IB_CFG_LREV_ENB:
4182 lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
4183 maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
4184 break;
4185
4186 case QIB_IB_CFG_OVERRUN_THRESH:
4187 maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
4188 OverrunThreshold);
4189 if (maskr != val) {
4190 ppd->cpspec->ibcctrl_a &=
4191 ~SYM_MASK(IBCCtrlA_0, OverrunThreshold);
4192 ppd->cpspec->ibcctrl_a |= (u64) val <<
4193 SYM_LSB(IBCCtrlA_0, OverrunThreshold);
4194 qib_write_kreg_port(ppd, krp_ibcctrl_a,
4195 ppd->cpspec->ibcctrl_a);
4196 qib_write_kreg(dd, kr_scratch, 0ULL);
4197 }
4198 goto bail;
4199
4200 case QIB_IB_CFG_PHYERR_THRESH:
4201 maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
4202 PhyerrThreshold);
4203 if (maskr != val) {
4204 ppd->cpspec->ibcctrl_a &=
4205 ~SYM_MASK(IBCCtrlA_0, PhyerrThreshold);
4206 ppd->cpspec->ibcctrl_a |= (u64) val <<
4207 SYM_LSB(IBCCtrlA_0, PhyerrThreshold);
4208 qib_write_kreg_port(ppd, krp_ibcctrl_a,
4209 ppd->cpspec->ibcctrl_a);
4210 qib_write_kreg(dd, kr_scratch, 0ULL);
4211 }
4212 goto bail;
4213
4214 case QIB_IB_CFG_PKEYS:
4215 maskr = (u64) ppd->pkeys[0] | ((u64) ppd->pkeys[1] << 16) |
4216 ((u64) ppd->pkeys[2] << 32) |
4217 ((u64) ppd->pkeys[3] << 48);
4218 qib_write_kreg_port(ppd, krp_partitionkey, maskr);
4219 goto bail;
4220
4221 case QIB_IB_CFG_LINKDEFAULT:
4222
4223 if (val == IB_LINKINITCMD_POLL)
4224 ppd->cpspec->ibcctrl_a &=
4225 ~SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
4226 else
4227 ppd->cpspec->ibcctrl_a |=
4228 SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
4229 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
4230 qib_write_kreg(dd, kr_scratch, 0ULL);
4231 goto bail;
4232
4233 case QIB_IB_CFG_MTU:
4234
4235
4236
4237
4238
4239
4240
4241 val = (ppd->ibmaxlen >> 2) + 1;
4242 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, MaxPktLen);
4243 ppd->cpspec->ibcctrl_a |= (u64)val <<
4244 SYM_LSB(IBCCtrlA_0, MaxPktLen);
4245 qib_write_kreg_port(ppd, krp_ibcctrl_a,
4246 ppd->cpspec->ibcctrl_a);
4247 qib_write_kreg(dd, kr_scratch, 0ULL);
4248 goto bail;
4249
4250 case QIB_IB_CFG_LSTATE:
4251 switch (val & 0xffff0000) {
4252 case IB_LINKCMD_DOWN:
4253 lcmd = QLOGIC_IB_IBCC_LINKCMD_DOWN;
4254 ppd->cpspec->ibmalfusesnap = 1;
4255 ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
4256 crp_errlink);
4257 if (!ppd->cpspec->ibdeltainprog &&
4258 qib_compat_ddr_negotiate) {
4259 ppd->cpspec->ibdeltainprog = 1;
4260 ppd->cpspec->ibsymsnap =
4261 read_7322_creg32_port(ppd,
4262 crp_ibsymbolerr);
4263 ppd->cpspec->iblnkerrsnap =
4264 read_7322_creg32_port(ppd,
4265 crp_iblinkerrrecov);
4266 }
4267 break;
4268
4269 case IB_LINKCMD_ARMED:
4270 lcmd = QLOGIC_IB_IBCC_LINKCMD_ARMED;
4271 if (ppd->cpspec->ibmalfusesnap) {
4272 ppd->cpspec->ibmalfusesnap = 0;
4273 ppd->cpspec->ibmalfdelta +=
4274 read_7322_creg32_port(ppd,
4275 crp_errlink) -
4276 ppd->cpspec->ibmalfsnap;
4277 }
4278 break;
4279
4280 case IB_LINKCMD_ACTIVE:
4281 lcmd = QLOGIC_IB_IBCC_LINKCMD_ACTIVE;
4282 break;
4283
4284 default:
4285 ret = -EINVAL;
4286 qib_dev_err(dd, "bad linkcmd req 0x%x\n", val >> 16);
4287 goto bail;
4288 }
4289 switch (val & 0xffff) {
4290 case IB_LINKINITCMD_NOP:
4291 licmd = 0;
4292 break;
4293
4294 case IB_LINKINITCMD_POLL:
4295 licmd = QLOGIC_IB_IBCC_LINKINITCMD_POLL;
4296 break;
4297
4298 case IB_LINKINITCMD_SLEEP:
4299 licmd = QLOGIC_IB_IBCC_LINKINITCMD_SLEEP;
4300 break;
4301
4302 case IB_LINKINITCMD_DISABLE:
4303 licmd = QLOGIC_IB_IBCC_LINKINITCMD_DISABLE;
4304 ppd->cpspec->chase_end = 0;
4305
4306
4307
4308
4309 if (ppd->cpspec->chase_timer.expires) {
4310 del_timer_sync(&ppd->cpspec->chase_timer);
4311 ppd->cpspec->chase_timer.expires = 0;
4312 }
4313 break;
4314
4315 default:
4316 ret = -EINVAL;
4317 qib_dev_err(dd, "bad linkinitcmd req 0x%x\n",
4318 val & 0xffff);
4319 goto bail;
4320 }
4321 qib_set_ib_7322_lstate(ppd, lcmd, licmd);
4322 goto bail;
4323
4324 case QIB_IB_CFG_OP_VLS:
4325 if (ppd->vls_operational != val) {
4326 ppd->vls_operational = val;
4327 set_vls(ppd);
4328 }
4329 goto bail;
4330
4331 case QIB_IB_CFG_VL_HIGH_LIMIT:
4332 qib_write_kreg_port(ppd, krp_highprio_limit, val);
4333 goto bail;
4334
4335 case QIB_IB_CFG_HRTBT:
4336 if (val > 3) {
4337 ret = -EINVAL;
4338 goto bail;
4339 }
4340 lsb = IBA7322_IBC_HRTBT_LSB;
4341 maskr = IBA7322_IBC_HRTBT_RMASK;
4342 break;
4343
4344 case QIB_IB_CFG_PORT:
4345
4346 if (ppd->dd->cspec->r1) {
4347 cancel_delayed_work(&ppd->cpspec->ipg_work);
4348 ppd->cpspec->ipg_tries = 0;
4349 }
4350 goto bail;
4351
4352 default:
4353 ret = -EINVAL;
4354 goto bail;
4355 }
4356 ppd->cpspec->ibcctrl_b &= ~(maskr << lsb);
4357 ppd->cpspec->ibcctrl_b |= (((u64) val & maskr) << lsb);
4358 qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
4359 qib_write_kreg(dd, kr_scratch, 0);
4360bail:
4361 return ret;
4362}
4363
4364static int qib_7322_set_loopback(struct qib_pportdata *ppd, const char *what)
4365{
4366 int ret = 0;
4367 u64 val, ctrlb;
4368
4369
4370 if (!strncmp(what, "ibc", 3)) {
4371 ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0,
4372 Loopback);
4373 val = 0;
4374 qib_devinfo(ppd->dd->pcidev, "Enabling IB%u:%u IBC loopback\n",
4375 ppd->dd->unit, ppd->port);
4376 } else if (!strncmp(what, "off", 3)) {
4377 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0,
4378 Loopback);
4379
4380 val = IBA7322_IBC_HRTBT_RMASK << IBA7322_IBC_HRTBT_LSB;
4381 qib_devinfo(ppd->dd->pcidev,
4382 "Disabling IB%u:%u IBC loopback (normal)\n",
4383 ppd->dd->unit, ppd->port);
4384 } else
4385 ret = -EINVAL;
4386 if (!ret) {
4387 qib_write_kreg_port(ppd, krp_ibcctrl_a,
4388 ppd->cpspec->ibcctrl_a);
4389 ctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_HRTBT_MASK
4390 << IBA7322_IBC_HRTBT_LSB);
4391 ppd->cpspec->ibcctrl_b = ctrlb | val;
4392 qib_write_kreg_port(ppd, krp_ibcctrl_b,
4393 ppd->cpspec->ibcctrl_b);
4394 qib_write_kreg(ppd->dd, kr_scratch, 0);
4395 }
4396 return ret;
4397}
4398
4399static void get_vl_weights(struct qib_pportdata *ppd, unsigned regno,
4400 struct ib_vl_weight_elem *vl)
4401{
4402 unsigned i;
4403
4404 for (i = 0; i < 16; i++, regno++, vl++) {
4405 u32 val = qib_read_kreg_port(ppd, regno);
4406
4407 vl->vl = (val >> SYM_LSB(LowPriority0_0, VirtualLane)) &
4408 SYM_RMASK(LowPriority0_0, VirtualLane);
4409 vl->weight = (val >> SYM_LSB(LowPriority0_0, Weight)) &
4410 SYM_RMASK(LowPriority0_0, Weight);
4411 }
4412}
4413
4414static void set_vl_weights(struct qib_pportdata *ppd, unsigned regno,
4415 struct ib_vl_weight_elem *vl)
4416{
4417 unsigned i;
4418
4419 for (i = 0; i < 16; i++, regno++, vl++) {
4420 u64 val;
4421
4422 val = ((vl->vl & SYM_RMASK(LowPriority0_0, VirtualLane)) <<
4423 SYM_LSB(LowPriority0_0, VirtualLane)) |
4424 ((vl->weight & SYM_RMASK(LowPriority0_0, Weight)) <<
4425 SYM_LSB(LowPriority0_0, Weight));
4426 qib_write_kreg_port(ppd, regno, val);
4427 }
4428 if (!(ppd->p_sendctrl & SYM_MASK(SendCtrl_0, IBVLArbiterEn))) {
4429 struct qib_devdata *dd = ppd->dd;
4430 unsigned long flags;
4431
4432 spin_lock_irqsave(&dd->sendctrl_lock, flags);
4433 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, IBVLArbiterEn);
4434 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
4435 qib_write_kreg(dd, kr_scratch, 0);
4436 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
4437 }
4438}
4439
4440static int qib_7322_get_ib_table(struct qib_pportdata *ppd, int which, void *t)
4441{
4442 switch (which) {
4443 case QIB_IB_TBL_VL_HIGH_ARB:
4444 get_vl_weights(ppd, krp_highprio_0, t);
4445 break;
4446
4447 case QIB_IB_TBL_VL_LOW_ARB:
4448 get_vl_weights(ppd, krp_lowprio_0, t);
4449 break;
4450
4451 default:
4452 return -EINVAL;
4453 }
4454 return 0;
4455}
4456
4457static int qib_7322_set_ib_table(struct qib_pportdata *ppd, int which, void *t)
4458{
4459 switch (which) {
4460 case QIB_IB_TBL_VL_HIGH_ARB:
4461 set_vl_weights(ppd, krp_highprio_0, t);
4462 break;
4463
4464 case QIB_IB_TBL_VL_LOW_ARB:
4465 set_vl_weights(ppd, krp_lowprio_0, t);
4466 break;
4467
4468 default:
4469 return -EINVAL;
4470 }
4471 return 0;
4472}
4473
4474static void qib_update_7322_usrhead(struct qib_ctxtdata *rcd, u64 hd,
4475 u32 updegr, u32 egrhd, u32 npkts)
4476{
4477
4478
4479
4480
4481 if (hd >> IBA7322_HDRHEAD_PKTINT_SHIFT)
4482 adjust_rcv_timeout(rcd, npkts);
4483 if (updegr)
4484 qib_write_ureg(rcd->dd, ur_rcvegrindexhead, egrhd, rcd->ctxt);
4485 mmiowb();
4486 qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
4487 qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
4488 mmiowb();
4489}
4490
4491static u32 qib_7322_hdrqempty(struct qib_ctxtdata *rcd)
4492{
4493 u32 head, tail;
4494
4495 head = qib_read_ureg32(rcd->dd, ur_rcvhdrhead, rcd->ctxt);
4496 if (rcd->rcvhdrtail_kvaddr)
4497 tail = qib_get_rcvhdrtail(rcd);
4498 else
4499 tail = qib_read_ureg32(rcd->dd, ur_rcvhdrtail, rcd->ctxt);
4500 return head == tail;
4501}
4502
4503#define RCVCTRL_COMMON_MODS (QIB_RCVCTRL_CTXT_ENB | \
4504 QIB_RCVCTRL_CTXT_DIS | \
4505 QIB_RCVCTRL_TIDFLOW_ENB | \
4506 QIB_RCVCTRL_TIDFLOW_DIS | \
4507 QIB_RCVCTRL_TAILUPD_ENB | \
4508 QIB_RCVCTRL_TAILUPD_DIS | \
4509 QIB_RCVCTRL_INTRAVAIL_ENB | \
4510 QIB_RCVCTRL_INTRAVAIL_DIS | \
4511 QIB_RCVCTRL_BP_ENB | \
4512 QIB_RCVCTRL_BP_DIS)
4513
4514#define RCVCTRL_PORT_MODS (QIB_RCVCTRL_CTXT_ENB | \
4515 QIB_RCVCTRL_CTXT_DIS | \
4516 QIB_RCVCTRL_PKEY_DIS | \
4517 QIB_RCVCTRL_PKEY_ENB)
4518
4519
4520
4521
4522
4523
4524
4525
4526static void rcvctrl_7322_mod(struct qib_pportdata *ppd, unsigned int op,
4527 int ctxt)
4528{
4529 struct qib_devdata *dd = ppd->dd;
4530 struct qib_ctxtdata *rcd;
4531 u64 mask, val;
4532 unsigned long flags;
4533
4534 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
4535
4536 if (op & QIB_RCVCTRL_TIDFLOW_ENB)
4537 dd->rcvctrl |= SYM_MASK(RcvCtrl, TidFlowEnable);
4538 if (op & QIB_RCVCTRL_TIDFLOW_DIS)
4539 dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TidFlowEnable);
4540 if (op & QIB_RCVCTRL_TAILUPD_ENB)
4541 dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
4542 if (op & QIB_RCVCTRL_TAILUPD_DIS)
4543 dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TailUpd);
4544 if (op & QIB_RCVCTRL_PKEY_ENB)
4545 ppd->p_rcvctrl &= ~SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
4546 if (op & QIB_RCVCTRL_PKEY_DIS)
4547 ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
4548 if (ctxt < 0) {
4549 mask = (1ULL << dd->ctxtcnt) - 1;
4550 rcd = NULL;
4551 } else {
4552 mask = (1ULL << ctxt);
4553 rcd = dd->rcd[ctxt];
4554 }
4555 if ((op & QIB_RCVCTRL_CTXT_ENB) && rcd) {
4556 ppd->p_rcvctrl |=
4557 (mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
4558 if (!(dd->flags & QIB_NODMA_RTAIL)) {
4559 op |= QIB_RCVCTRL_TAILUPD_ENB;
4560 dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
4561 }
4562
4563 qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt,
4564 rcd->rcvhdrqtailaddr_phys);
4565 qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt,
4566 rcd->rcvhdrq_phys);
4567 rcd->seq_cnt = 1;
4568 }
4569 if (op & QIB_RCVCTRL_CTXT_DIS)
4570 ppd->p_rcvctrl &=
4571 ~(mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
4572 if (op & QIB_RCVCTRL_BP_ENB)
4573 dd->rcvctrl |= mask << SYM_LSB(RcvCtrl, dontDropRHQFull);
4574 if (op & QIB_RCVCTRL_BP_DIS)
4575 dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, dontDropRHQFull));
4576 if (op & QIB_RCVCTRL_INTRAVAIL_ENB)
4577 dd->rcvctrl |= (mask << SYM_LSB(RcvCtrl, IntrAvail));
4578 if (op & QIB_RCVCTRL_INTRAVAIL_DIS)
4579 dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, IntrAvail));
4580
4581
4582
4583
4584
4585 if (op == 0 || (op & RCVCTRL_COMMON_MODS))
4586 qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
4587 if (op == 0 || (op & RCVCTRL_PORT_MODS))
4588 qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
4589 if ((op & QIB_RCVCTRL_CTXT_ENB) && dd->rcd[ctxt]) {
4590
4591
4592
4593
4594
4595
4596 val = qib_read_ureg32(dd, ur_rcvegrindextail, ctxt);
4597 qib_write_ureg(dd, ur_rcvegrindexhead, val, ctxt);
4598
4599
4600 (void) qib_read_kreg32(dd, kr_scratch);
4601 val = qib_read_ureg32(dd, ur_rcvhdrtail, ctxt);
4602 dd->rcd[ctxt]->head = val;
4603
4604 if (ctxt < dd->first_user_ctxt)
4605 val |= dd->rhdrhead_intr_off;
4606 qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
4607 } else if ((op & QIB_RCVCTRL_INTRAVAIL_ENB) &&
4608 dd->rcd[ctxt] && dd->rhdrhead_intr_off) {
4609
4610 val = dd->rcd[ctxt]->head | dd->rhdrhead_intr_off;
4611 qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
4612 }
4613 if (op & QIB_RCVCTRL_CTXT_DIS) {
4614 unsigned f;
4615
4616
4617 if (ctxt >= 0) {
4618 qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt, 0);
4619 qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt, 0);
4620 for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
4621 qib_write_ureg(dd, ur_rcvflowtable + f,
4622 TIDFLOW_ERRBITS, ctxt);
4623 } else {
4624 unsigned i;
4625
4626 for (i = 0; i < dd->cfgctxts; i++) {
4627 qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr,
4628 i, 0);
4629 qib_write_kreg_ctxt(dd, krc_rcvhdraddr, i, 0);
4630 for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
4631 qib_write_ureg(dd, ur_rcvflowtable + f,
4632 TIDFLOW_ERRBITS, i);
4633 }
4634 }
4635 }
4636 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
4637}
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651#define SENDCTRL_COMMON_MODS (\
4652 QIB_SENDCTRL_CLEAR | \
4653 QIB_SENDCTRL_AVAIL_DIS | \
4654 QIB_SENDCTRL_AVAIL_ENB | \
4655 QIB_SENDCTRL_AVAIL_BLIP | \
4656 QIB_SENDCTRL_DISARM | \
4657 QIB_SENDCTRL_DISARM_ALL | \
4658 QIB_SENDCTRL_SEND_ENB)
4659
4660#define SENDCTRL_PORT_MODS (\
4661 QIB_SENDCTRL_CLEAR | \
4662 QIB_SENDCTRL_SEND_ENB | \
4663 QIB_SENDCTRL_SEND_DIS | \
4664 QIB_SENDCTRL_FLUSH)
4665
4666static void sendctrl_7322_mod(struct qib_pportdata *ppd, u32 op)
4667{
4668 struct qib_devdata *dd = ppd->dd;
4669 u64 tmp_dd_sendctrl;
4670 unsigned long flags;
4671
4672 spin_lock_irqsave(&dd->sendctrl_lock, flags);
4673
4674
4675 if (op & QIB_SENDCTRL_CLEAR)
4676 dd->sendctrl = 0;
4677 if (op & QIB_SENDCTRL_AVAIL_DIS)
4678 dd->sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
4679 else if (op & QIB_SENDCTRL_AVAIL_ENB) {
4680 dd->sendctrl |= SYM_MASK(SendCtrl, SendBufAvailUpd);
4681 if (dd->flags & QIB_USE_SPCL_TRIG)
4682 dd->sendctrl |= SYM_MASK(SendCtrl, SpecialTriggerEn);
4683 }
4684
4685
4686 if (op & QIB_SENDCTRL_SEND_DIS)
4687 ppd->p_sendctrl &= ~SYM_MASK(SendCtrl_0, SendEnable);
4688 else if (op & QIB_SENDCTRL_SEND_ENB)
4689 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, SendEnable);
4690
4691 if (op & QIB_SENDCTRL_DISARM_ALL) {
4692 u32 i, last;
4693
4694 tmp_dd_sendctrl = dd->sendctrl;
4695 last = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
4696
4697
4698
4699
4700 tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
4701 for (i = 0; i < last; i++) {
4702 qib_write_kreg(dd, kr_sendctrl,
4703 tmp_dd_sendctrl |
4704 SYM_MASK(SendCtrl, Disarm) | i);
4705 qib_write_kreg(dd, kr_scratch, 0);
4706 }
4707 }
4708
4709 if (op & QIB_SENDCTRL_FLUSH) {
4710 u64 tmp_ppd_sendctrl = ppd->p_sendctrl;
4711
4712
4713
4714
4715
4716 tmp_ppd_sendctrl |=
4717 SYM_MASK(SendCtrl_0, TxeDrainRmFifo) |
4718 SYM_MASK(SendCtrl_0, TxeDrainLaFifo) |
4719 SYM_MASK(SendCtrl_0, TxeBypassIbc);
4720 qib_write_kreg_port(ppd, krp_sendctrl, tmp_ppd_sendctrl);
4721 qib_write_kreg(dd, kr_scratch, 0);
4722 }
4723
4724 tmp_dd_sendctrl = dd->sendctrl;
4725
4726 if (op & QIB_SENDCTRL_DISARM)
4727 tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Disarm) |
4728 ((op & QIB_7322_SendCtrl_DisarmSendBuf_RMASK) <<
4729 SYM_LSB(SendCtrl, DisarmSendBuf));
4730 if ((op & QIB_SENDCTRL_AVAIL_BLIP) &&
4731 (dd->sendctrl & SYM_MASK(SendCtrl, SendBufAvailUpd)))
4732 tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
4733
4734 if (op == 0 || (op & SENDCTRL_COMMON_MODS)) {
4735 qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl);
4736 qib_write_kreg(dd, kr_scratch, 0);
4737 }
4738
4739 if (op == 0 || (op & SENDCTRL_PORT_MODS)) {
4740 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
4741 qib_write_kreg(dd, kr_scratch, 0);
4742 }
4743
4744 if (op & QIB_SENDCTRL_AVAIL_BLIP) {
4745 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
4746 qib_write_kreg(dd, kr_scratch, 0);
4747 }
4748
4749 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
4750
4751 if (op & QIB_SENDCTRL_FLUSH) {
4752 u32 v;
4753
4754
4755
4756
4757
4758
4759 v = qib_read_kreg32(dd, kr_scratch);
4760 qib_write_kreg(dd, kr_scratch, v);
4761 v = qib_read_kreg32(dd, kr_scratch);
4762 qib_write_kreg(dd, kr_scratch, v);
4763 qib_read_kreg32(dd, kr_scratch);
4764 }
4765}
4766
4767#define _PORT_VIRT_FLAG 0x8000U
4768#define _PORT_64BIT_FLAG 0x10000U
4769#define _PORT_CNTR_IDXMASK 0x7fffU
4770
4771
4772
4773
4774
4775
4776static u64 qib_portcntr_7322(struct qib_pportdata *ppd, u32 reg)
4777{
4778 struct qib_devdata *dd = ppd->dd;
4779 u64 ret = 0ULL;
4780 u16 creg;
4781
4782 static const u32 xlator[] = {
4783 [QIBPORTCNTR_PKTSEND] = crp_pktsend | _PORT_64BIT_FLAG,
4784 [QIBPORTCNTR_WORDSEND] = crp_wordsend | _PORT_64BIT_FLAG,
4785 [QIBPORTCNTR_PSXMITDATA] = crp_psxmitdatacount,
4786 [QIBPORTCNTR_PSXMITPKTS] = crp_psxmitpktscount,
4787 [QIBPORTCNTR_PSXMITWAIT] = crp_psxmitwaitcount,
4788 [QIBPORTCNTR_SENDSTALL] = crp_sendstall,
4789 [QIBPORTCNTR_PKTRCV] = crp_pktrcv | _PORT_64BIT_FLAG,
4790 [QIBPORTCNTR_PSRCVDATA] = crp_psrcvdatacount,
4791 [QIBPORTCNTR_PSRCVPKTS] = crp_psrcvpktscount,
4792 [QIBPORTCNTR_RCVEBP] = crp_rcvebp,
4793 [QIBPORTCNTR_RCVOVFL] = crp_rcvovfl,
4794 [QIBPORTCNTR_WORDRCV] = crp_wordrcv | _PORT_64BIT_FLAG,
4795 [QIBPORTCNTR_RXDROPPKT] = 0xffff,
4796 [QIBPORTCNTR_RXLOCALPHYERR] = crp_rxotherlocalphyerr,
4797 [QIBPORTCNTR_RXVLERR] = crp_rxvlerr,
4798 [QIBPORTCNTR_ERRICRC] = crp_erricrc,
4799 [QIBPORTCNTR_ERRVCRC] = crp_errvcrc,
4800 [QIBPORTCNTR_ERRLPCRC] = crp_errlpcrc,
4801 [QIBPORTCNTR_BADFORMAT] = crp_badformat,
4802 [QIBPORTCNTR_ERR_RLEN] = crp_err_rlen,
4803 [QIBPORTCNTR_IBSYMBOLERR] = crp_ibsymbolerr,
4804 [QIBPORTCNTR_INVALIDRLEN] = crp_invalidrlen,
4805 [QIBPORTCNTR_UNSUPVL] = crp_txunsupvl,
4806 [QIBPORTCNTR_EXCESSBUFOVFL] = crp_excessbufferovfl,
4807 [QIBPORTCNTR_ERRLINK] = crp_errlink,
4808 [QIBPORTCNTR_IBLINKDOWN] = crp_iblinkdown,
4809 [QIBPORTCNTR_IBLINKERRRECOV] = crp_iblinkerrrecov,
4810 [QIBPORTCNTR_LLI] = crp_locallinkintegrityerr,
4811 [QIBPORTCNTR_VL15PKTDROP] = crp_vl15droppedpkt,
4812 [QIBPORTCNTR_ERRPKEY] = crp_errpkey,
4813
4814
4815
4816
4817
4818 [QIBPORTCNTR_PSINTERVAL] = krp_psinterval,
4819 [QIBPORTCNTR_PSSTART] = krp_psstart,
4820 [QIBPORTCNTR_PSSTAT] = krp_psstat,
4821
4822 [QIBPORTCNTR_KHDROVFL] = 0xffff,
4823 };
4824
4825 if (reg >= ARRAY_SIZE(xlator)) {
4826 qib_devinfo(ppd->dd->pcidev,
4827 "Unimplemented portcounter %u\n", reg);
4828 goto done;
4829 }
4830 creg = xlator[reg] & _PORT_CNTR_IDXMASK;
4831
4832
4833 if (reg == QIBPORTCNTR_KHDROVFL) {
4834 int i;
4835
4836
4837 for (i = 0; dd->rcd && i < dd->first_user_ctxt; i++) {
4838 struct qib_ctxtdata *rcd = dd->rcd[i];
4839
4840 if (!rcd || rcd->ppd != ppd)
4841 continue;
4842 ret += read_7322_creg32(dd, cr_base_egrovfl + i);
4843 }
4844 goto done;
4845 } else if (reg == QIBPORTCNTR_RXDROPPKT) {
4846
4847
4848
4849
4850
4851 goto done;
4852 } else if (reg == QIBPORTCNTR_PSINTERVAL ||
4853 reg == QIBPORTCNTR_PSSTART || reg == QIBPORTCNTR_PSSTAT) {
4854
4855 ret = qib_read_kreg_port(ppd, creg);
4856 goto done;
4857 }
4858
4859
4860
4861
4862
4863 if (xlator[reg] & _PORT_64BIT_FLAG)
4864 ret = read_7322_creg_port(ppd, creg);
4865 else
4866 ret = read_7322_creg32_port(ppd, creg);
4867 if (creg == crp_ibsymbolerr) {
4868 if (ppd->cpspec->ibdeltainprog)
4869 ret -= ret - ppd->cpspec->ibsymsnap;
4870 ret -= ppd->cpspec->ibsymdelta;
4871 } else if (creg == crp_iblinkerrrecov) {
4872 if (ppd->cpspec->ibdeltainprog)
4873 ret -= ret - ppd->cpspec->iblnkerrsnap;
4874 ret -= ppd->cpspec->iblnkerrdelta;
4875 } else if (creg == crp_errlink)
4876 ret -= ppd->cpspec->ibmalfdelta;
4877 else if (creg == crp_iblinkdown)
4878 ret += ppd->cpspec->iblnkdowndelta;
4879done:
4880 return ret;
4881}
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896static const char cntr7322names[] =
4897 "Interrupts\n"
4898 "HostBusStall\n"
4899 "E RxTIDFull\n"
4900 "RxTIDInvalid\n"
4901 "RxTIDFloDrop\n"
4902 "Ctxt0EgrOvfl\n"
4903 "Ctxt1EgrOvfl\n"
4904 "Ctxt2EgrOvfl\n"
4905 "Ctxt3EgrOvfl\n"
4906 "Ctxt4EgrOvfl\n"
4907 "Ctxt5EgrOvfl\n"
4908 "Ctxt6EgrOvfl\n"
4909 "Ctxt7EgrOvfl\n"
4910 "Ctxt8EgrOvfl\n"
4911 "Ctxt9EgrOvfl\n"
4912 "Ctx10EgrOvfl\n"
4913 "Ctx11EgrOvfl\n"
4914 "Ctx12EgrOvfl\n"
4915 "Ctx13EgrOvfl\n"
4916 "Ctx14EgrOvfl\n"
4917 "Ctx15EgrOvfl\n"
4918 "Ctx16EgrOvfl\n"
4919 "Ctx17EgrOvfl\n"
4920 ;
4921
4922static const u32 cntr7322indices[] = {
4923 cr_lbint | _PORT_64BIT_FLAG,
4924 cr_lbstall | _PORT_64BIT_FLAG,
4925 cr_tidfull,
4926 cr_tidinvalid,
4927 cr_rxtidflowdrop,
4928 cr_base_egrovfl + 0,
4929 cr_base_egrovfl + 1,
4930 cr_base_egrovfl + 2,
4931 cr_base_egrovfl + 3,
4932 cr_base_egrovfl + 4,
4933 cr_base_egrovfl + 5,
4934 cr_base_egrovfl + 6,
4935 cr_base_egrovfl + 7,
4936 cr_base_egrovfl + 8,
4937 cr_base_egrovfl + 9,
4938 cr_base_egrovfl + 10,
4939 cr_base_egrovfl + 11,
4940 cr_base_egrovfl + 12,
4941 cr_base_egrovfl + 13,
4942 cr_base_egrovfl + 14,
4943 cr_base_egrovfl + 15,
4944 cr_base_egrovfl + 16,
4945 cr_base_egrovfl + 17,
4946};
4947
4948
4949
4950
4951
4952
4953static const char portcntr7322names[] =
4954 "TxPkt\n"
4955 "TxFlowPkt\n"
4956 "TxWords\n"
4957 "RxPkt\n"
4958 "RxFlowPkt\n"
4959 "RxWords\n"
4960 "TxFlowStall\n"
4961 "TxDmaDesc\n"
4962 "E RxDlidFltr\n"
4963 "IBStatusChng\n"
4964 "IBLinkDown\n"
4965 "IBLnkRecov\n"
4966 "IBRxLinkErr\n"
4967 "IBSymbolErr\n"
4968 "RxLLIErr\n"
4969 "RxBadFormat\n"
4970 "RxBadLen\n"
4971 "RxBufOvrfl\n"
4972 "RxEBP\n"
4973 "RxFlowCtlErr\n"
4974 "RxICRCerr\n"
4975 "RxLPCRCerr\n"
4976 "RxVCRCerr\n"
4977 "RxInvalLen\n"
4978 "RxInvalPKey\n"
4979 "RxPktDropped\n"
4980 "TxBadLength\n"
4981 "TxDropped\n"
4982 "TxInvalLen\n"
4983 "TxUnderrun\n"
4984 "TxUnsupVL\n"
4985 "RxLclPhyErr\n"
4986 "RxVL15Drop\n"
4987 "RxVlErr\n"
4988 "XcessBufOvfl\n"
4989 "RxQPBadCtxt\n"
4990 "TXBadHeader\n"
4991 ;
4992
4993static const u32 portcntr7322indices[] = {
4994 QIBPORTCNTR_PKTSEND | _PORT_VIRT_FLAG,
4995 crp_pktsendflow,
4996 QIBPORTCNTR_WORDSEND | _PORT_VIRT_FLAG,
4997 QIBPORTCNTR_PKTRCV | _PORT_VIRT_FLAG,
4998 crp_pktrcvflowctrl,
4999 QIBPORTCNTR_WORDRCV | _PORT_VIRT_FLAG,
5000 QIBPORTCNTR_SENDSTALL | _PORT_VIRT_FLAG,
5001 crp_txsdmadesc | _PORT_64BIT_FLAG,
5002 crp_rxdlidfltr,
5003 crp_ibstatuschange,
5004 QIBPORTCNTR_IBLINKDOWN | _PORT_VIRT_FLAG,
5005 QIBPORTCNTR_IBLINKERRRECOV | _PORT_VIRT_FLAG,
5006 QIBPORTCNTR_ERRLINK | _PORT_VIRT_FLAG,
5007 QIBPORTCNTR_IBSYMBOLERR | _PORT_VIRT_FLAG,
5008 QIBPORTCNTR_LLI | _PORT_VIRT_FLAG,
5009 QIBPORTCNTR_BADFORMAT | _PORT_VIRT_FLAG,
5010 QIBPORTCNTR_ERR_RLEN | _PORT_VIRT_FLAG,
5011 QIBPORTCNTR_RCVOVFL | _PORT_VIRT_FLAG,
5012 QIBPORTCNTR_RCVEBP | _PORT_VIRT_FLAG,
5013 crp_rcvflowctrlviol,
5014 QIBPORTCNTR_ERRICRC | _PORT_VIRT_FLAG,
5015 QIBPORTCNTR_ERRLPCRC | _PORT_VIRT_FLAG,
5016 QIBPORTCNTR_ERRVCRC | _PORT_VIRT_FLAG,
5017 QIBPORTCNTR_INVALIDRLEN | _PORT_VIRT_FLAG,
5018 QIBPORTCNTR_ERRPKEY | _PORT_VIRT_FLAG,
5019 QIBPORTCNTR_RXDROPPKT | _PORT_VIRT_FLAG,
5020 crp_txminmaxlenerr,
5021 crp_txdroppedpkt,
5022 crp_txlenerr,
5023 crp_txunderrun,
5024 crp_txunsupvl,
5025 QIBPORTCNTR_RXLOCALPHYERR | _PORT_VIRT_FLAG,
5026 QIBPORTCNTR_VL15PKTDROP | _PORT_VIRT_FLAG,
5027 QIBPORTCNTR_RXVLERR | _PORT_VIRT_FLAG,
5028 QIBPORTCNTR_EXCESSBUFOVFL | _PORT_VIRT_FLAG,
5029 crp_rxqpinvalidctxt,
5030 crp_txhdrerr,
5031};
5032
5033
5034static void init_7322_cntrnames(struct qib_devdata *dd)
5035{
5036 int i, j = 0;
5037 char *s;
5038
5039 for (i = 0, s = (char *)cntr7322names; s && j <= dd->cfgctxts;
5040 i++) {
5041
5042 if (!j && !strncmp("Ctxt0EgrOvfl", s + 1, 12))
5043 j = 1;
5044 s = strchr(s + 1, '\n');
5045 if (s && j)
5046 j++;
5047 }
5048 dd->cspec->ncntrs = i;
5049 if (!s)
5050
5051 dd->cspec->cntrnamelen = sizeof(cntr7322names) - 1;
5052 else
5053 dd->cspec->cntrnamelen = 1 + s - cntr7322names;
5054 dd->cspec->cntrs = kmalloc(dd->cspec->ncntrs
5055 * sizeof(u64), GFP_KERNEL);
5056 if (!dd->cspec->cntrs)
5057 qib_dev_err(dd, "Failed allocation for counters\n");
5058
5059 for (i = 0, s = (char *)portcntr7322names; s; i++)
5060 s = strchr(s + 1, '\n');
5061 dd->cspec->nportcntrs = i - 1;
5062 dd->cspec->portcntrnamelen = sizeof(portcntr7322names) - 1;
5063 for (i = 0; i < dd->num_pports; ++i) {
5064 dd->pport[i].cpspec->portcntrs = kmalloc(dd->cspec->nportcntrs
5065 * sizeof(u64), GFP_KERNEL);
5066 if (!dd->pport[i].cpspec->portcntrs)
5067 qib_dev_err(dd,
5068 "Failed allocation for portcounters\n");
5069 }
5070}
5071
5072static u32 qib_read_7322cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
5073 u64 **cntrp)
5074{
5075 u32 ret;
5076
5077 if (namep) {
5078 ret = dd->cspec->cntrnamelen;
5079 if (pos >= ret)
5080 ret = 0;
5081 else
5082 *namep = (char *) cntr7322names;
5083 } else {
5084 u64 *cntr = dd->cspec->cntrs;
5085 int i;
5086
5087 ret = dd->cspec->ncntrs * sizeof(u64);
5088 if (!cntr || pos >= ret) {
5089
5090 ret = 0;
5091 goto done;
5092 }
5093 *cntrp = cntr;
5094 for (i = 0; i < dd->cspec->ncntrs; i++)
5095 if (cntr7322indices[i] & _PORT_64BIT_FLAG)
5096 *cntr++ = read_7322_creg(dd,
5097 cntr7322indices[i] &
5098 _PORT_CNTR_IDXMASK);
5099 else
5100 *cntr++ = read_7322_creg32(dd,
5101 cntr7322indices[i]);
5102 }
5103done:
5104 return ret;
5105}
5106
5107static u32 qib_read_7322portcntrs(struct qib_devdata *dd, loff_t pos, u32 port,
5108 char **namep, u64 **cntrp)
5109{
5110 u32 ret;
5111
5112 if (namep) {
5113 ret = dd->cspec->portcntrnamelen;
5114 if (pos >= ret)
5115 ret = 0;
5116 else
5117 *namep = (char *)portcntr7322names;
5118 } else {
5119 struct qib_pportdata *ppd = &dd->pport[port];
5120 u64 *cntr = ppd->cpspec->portcntrs;
5121 int i;
5122
5123 ret = dd->cspec->nportcntrs * sizeof(u64);
5124 if (!cntr || pos >= ret) {
5125
5126 ret = 0;
5127 goto done;
5128 }
5129 *cntrp = cntr;
5130 for (i = 0; i < dd->cspec->nportcntrs; i++) {
5131 if (portcntr7322indices[i] & _PORT_VIRT_FLAG)
5132 *cntr++ = qib_portcntr_7322(ppd,
5133 portcntr7322indices[i] &
5134 _PORT_CNTR_IDXMASK);
5135 else if (portcntr7322indices[i] & _PORT_64BIT_FLAG)
5136 *cntr++ = read_7322_creg_port(ppd,
5137 portcntr7322indices[i] &
5138 _PORT_CNTR_IDXMASK);
5139 else
5140 *cntr++ = read_7322_creg32_port(ppd,
5141 portcntr7322indices[i]);
5142 }
5143 }
5144done:
5145 return ret;
5146}
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159static void qib_get_7322_faststats(unsigned long opaque)
5160{
5161 struct qib_devdata *dd = (struct qib_devdata *) opaque;
5162 struct qib_pportdata *ppd;
5163 unsigned long flags;
5164 u64 traffic_wds;
5165 int pidx;
5166
5167 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
5168 ppd = dd->pport + pidx;
5169
5170
5171
5172
5173
5174
5175 if (!ppd->link_speed_supported || !(dd->flags & QIB_INITTED)
5176 || dd->diag_client)
5177 continue;
5178
5179
5180
5181
5182
5183
5184 traffic_wds = qib_portcntr_7322(ppd, QIBPORTCNTR_WORDRCV) +
5185 qib_portcntr_7322(ppd, QIBPORTCNTR_WORDSEND);
5186 spin_lock_irqsave(&ppd->dd->eep_st_lock, flags);
5187 traffic_wds -= ppd->dd->traffic_wds;
5188 ppd->dd->traffic_wds += traffic_wds;
5189 if (traffic_wds >= QIB_TRAFFIC_ACTIVE_THRESHOLD)
5190 atomic_add(ACTIVITY_TIMER, &ppd->dd->active_time);
5191 spin_unlock_irqrestore(&ppd->dd->eep_st_lock, flags);
5192 if (ppd->cpspec->qdr_dfe_on && (ppd->link_speed_active &
5193 QIB_IB_QDR) &&
5194 (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
5195 QIBL_LINKACTIVE)) &&
5196 ppd->cpspec->qdr_dfe_time &&
5197 time_is_before_jiffies(ppd->cpspec->qdr_dfe_time)) {
5198 ppd->cpspec->qdr_dfe_on = 0;
5199
5200 qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
5201 ppd->dd->cspec->r1 ?
5202 QDR_STATIC_ADAPT_INIT_R1 :
5203 QDR_STATIC_ADAPT_INIT);
5204 force_h1(ppd);
5205 }
5206 }
5207 mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);
5208}
5209
5210
5211
5212
5213static int qib_7322_intr_fallback(struct qib_devdata *dd)
5214{
5215 if (!dd->cspec->num_msix_entries)
5216 return 0;
5217
5218 qib_devinfo(dd->pcidev,
5219 "MSIx interrupt not detected, trying INTx interrupts\n");
5220 qib_7322_nomsix(dd);
5221 qib_enable_intx(dd->pcidev);
5222 qib_setup_7322_interrupt(dd, 0);
5223 return 1;
5224}
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235static void qib_7322_mini_pcs_reset(struct qib_pportdata *ppd)
5236{
5237 u64 val;
5238 struct qib_devdata *dd = ppd->dd;
5239 const u64 reset_bits = SYM_MASK(IBPCSConfig_0, xcv_rreset) |
5240 SYM_MASK(IBPCSConfig_0, xcv_treset) |
5241 SYM_MASK(IBPCSConfig_0, tx_rx_reset);
5242
5243 val = qib_read_kreg_port(ppd, krp_ib_pcsconfig);
5244 qib_write_kreg(dd, kr_hwerrmask,
5245 dd->cspec->hwerrmask & ~HWE_MASK(statusValidNoEop));
5246 qib_write_kreg_port(ppd, krp_ibcctrl_a,
5247 ppd->cpspec->ibcctrl_a &
5248 ~SYM_MASK(IBCCtrlA_0, IBLinkEn));
5249
5250 qib_write_kreg_port(ppd, krp_ib_pcsconfig, val | reset_bits);
5251 qib_read_kreg32(dd, kr_scratch);
5252 qib_write_kreg_port(ppd, krp_ib_pcsconfig, val & ~reset_bits);
5253 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
5254 qib_write_kreg(dd, kr_scratch, 0ULL);
5255 qib_write_kreg(dd, kr_hwerrclear,
5256 SYM_MASK(HwErrClear, statusValidNoEopClear));
5257 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
5258}
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268static void autoneg_7322_sendpkt(struct qib_pportdata *ppd, u32 *hdr,
5269 u32 dcnt, u32 *data)
5270{
5271 int i;
5272 u64 pbc;
5273 u32 __iomem *piobuf;
5274 u32 pnum, control, len;
5275 struct qib_devdata *dd = ppd->dd;
5276
5277 i = 0;
5278 len = 7 + dcnt + 1;
5279 control = qib_7322_setpbc_control(ppd, len, 0, 15);
5280 pbc = ((u64) control << 32) | len;
5281 while (!(piobuf = qib_7322_getsendbuf(ppd, pbc, &pnum))) {
5282 if (i++ > 15)
5283 return;
5284 udelay(2);
5285 }
5286
5287 dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_DIS1, NULL);
5288 writeq(pbc, piobuf);
5289 qib_flush_wc();
5290 qib_pio_copy(piobuf + 2, hdr, 7);
5291 qib_pio_copy(piobuf + 9, data, dcnt);
5292 if (dd->flags & QIB_USE_SPCL_TRIG) {
5293 u32 spcl_off = (pnum >= dd->piobcnt2k) ? 2047 : 1023;
5294
5295 qib_flush_wc();
5296 __raw_writel(0xaebecede, piobuf + spcl_off);
5297 }
5298 qib_flush_wc();
5299 qib_sendbuf_done(dd, pnum);
5300
5301 dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_ENAB1, NULL);
5302}
5303
5304
5305
5306
5307static void qib_autoneg_7322_send(struct qib_pportdata *ppd, int which)
5308{
5309 struct qib_devdata *dd = ppd->dd;
5310 static u32 swapped;
5311 u32 dw, i, hcnt, dcnt, *data;
5312 static u32 hdr[7] = { 0xf002ffff, 0x48ffff, 0x6400abba };
5313 static u32 madpayload_start[0x40] = {
5314 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
5315 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
5316 0x1, 0x1388, 0x15e, 0x1,
5317 };
5318 static u32 madpayload_done[0x40] = {
5319 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
5320 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
5321 0x40000001, 0x1388, 0x15e,
5322 };
5323
5324 dcnt = ARRAY_SIZE(madpayload_start);
5325 hcnt = ARRAY_SIZE(hdr);
5326 if (!swapped) {
5327
5328 for (i = 0; i < hcnt; i++) {
5329 dw = (__force u32) cpu_to_be32(hdr[i]);
5330 hdr[i] = dw;
5331 }
5332 for (i = 0; i < dcnt; i++) {
5333 dw = (__force u32) cpu_to_be32(madpayload_start[i]);
5334 madpayload_start[i] = dw;
5335 dw = (__force u32) cpu_to_be32(madpayload_done[i]);
5336 madpayload_done[i] = dw;
5337 }
5338 swapped = 1;
5339 }
5340
5341 data = which ? madpayload_done : madpayload_start;
5342
5343 autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
5344 qib_read_kreg64(dd, kr_scratch);
5345 udelay(2);
5346 autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
5347 qib_read_kreg64(dd, kr_scratch);
5348 udelay(2);
5349}
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365static void set_7322_ibspeed_fast(struct qib_pportdata *ppd, u32 speed)
5366{
5367 u64 newctrlb;
5368 newctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_SPEED_MASK |
5369 IBA7322_IBC_IBTA_1_2_MASK |
5370 IBA7322_IBC_MAX_SPEED_MASK);
5371
5372 if (speed & (speed - 1))
5373 newctrlb |= (speed << IBA7322_IBC_SPEED_LSB) |
5374 IBA7322_IBC_IBTA_1_2_MASK |
5375 IBA7322_IBC_MAX_SPEED_MASK;
5376 else
5377 newctrlb |= speed == QIB_IB_QDR ?
5378 IBA7322_IBC_SPEED_QDR | IBA7322_IBC_IBTA_1_2_MASK :
5379 ((speed == QIB_IB_DDR ?
5380 IBA7322_IBC_SPEED_DDR : IBA7322_IBC_SPEED_SDR));
5381
5382 if (newctrlb == ppd->cpspec->ibcctrl_b)
5383 return;
5384
5385 ppd->cpspec->ibcctrl_b = newctrlb;
5386 qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
5387 qib_write_kreg(ppd->dd, kr_scratch, 0);
5388}
5389
5390
5391
5392
5393
5394
5395
5396static void try_7322_autoneg(struct qib_pportdata *ppd)
5397{
5398 unsigned long flags;
5399
5400 spin_lock_irqsave(&ppd->lflags_lock, flags);
5401 ppd->lflags |= QIBL_IB_AUTONEG_INPROG;
5402 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5403 qib_autoneg_7322_send(ppd, 0);
5404 set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
5405 qib_7322_mini_pcs_reset(ppd);
5406
5407 queue_delayed_work(ib_wq, &ppd->cpspec->autoneg_work,
5408 msecs_to_jiffies(2));
5409}
5410
5411
5412
5413
5414
5415static void autoneg_7322_work(struct work_struct *work)
5416{
5417 struct qib_pportdata *ppd;
5418 struct qib_devdata *dd;
5419 u64 startms;
5420 u32 i;
5421 unsigned long flags;
5422
5423 ppd = container_of(work, struct qib_chippport_specific,
5424 autoneg_work.work)->ppd;
5425 dd = ppd->dd;
5426
5427 startms = jiffies_to_msecs(jiffies);
5428
5429
5430
5431
5432
5433 for (i = 0; i < 25; i++) {
5434 if (SYM_FIELD(ppd->lastibcstat, IBCStatusA_0, LinkState)
5435 == IB_7322_LT_STATE_POLLQUIET) {
5436 qib_set_linkstate(ppd, QIB_IB_LINKDOWN_DISABLE);
5437 break;
5438 }
5439 udelay(100);
5440 }
5441
5442 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
5443 goto done;
5444
5445
5446 if (wait_event_timeout(ppd->cpspec->autoneg_wait,
5447 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
5448 msecs_to_jiffies(90)))
5449 goto done;
5450 qib_7322_mini_pcs_reset(ppd);
5451
5452
5453 if (wait_event_timeout(ppd->cpspec->autoneg_wait,
5454 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
5455 msecs_to_jiffies(1700)))
5456 goto done;
5457 qib_7322_mini_pcs_reset(ppd);
5458
5459 set_7322_ibspeed_fast(ppd, QIB_IB_SDR);
5460
5461
5462
5463
5464
5465 wait_event_timeout(ppd->cpspec->autoneg_wait,
5466 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
5467 msecs_to_jiffies(250));
5468done:
5469 if (ppd->lflags & QIBL_IB_AUTONEG_INPROG) {
5470 spin_lock_irqsave(&ppd->lflags_lock, flags);
5471 ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
5472 if (ppd->cpspec->autoneg_tries == AUTONEG_TRIES) {
5473 ppd->lflags |= QIBL_IB_AUTONEG_FAILED;
5474 ppd->cpspec->autoneg_tries = 0;
5475 }
5476 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5477 set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
5478 }
5479}
5480
5481
5482
5483
5484
5485static void try_7322_ipg(struct qib_pportdata *ppd)
5486{
5487 struct qib_ibport *ibp = &ppd->ibport_data;
5488 struct ib_mad_send_buf *send_buf;
5489 struct ib_mad_agent *agent;
5490 struct ib_smp *smp;
5491 unsigned delay;
5492 int ret;
5493
5494 agent = ibp->send_agent;
5495 if (!agent)
5496 goto retry;
5497
5498 send_buf = ib_create_send_mad(agent, 0, 0, 0, IB_MGMT_MAD_HDR,
5499 IB_MGMT_MAD_DATA, GFP_ATOMIC);
5500 if (IS_ERR(send_buf))
5501 goto retry;
5502
5503 if (!ibp->smi_ah) {
5504 struct ib_ah *ah;
5505
5506 ah = qib_create_qp0_ah(ibp, be16_to_cpu(IB_LID_PERMISSIVE));
5507 if (IS_ERR(ah))
5508 ret = PTR_ERR(ah);
5509 else {
5510 send_buf->ah = ah;
5511 ibp->smi_ah = to_iah(ah);
5512 ret = 0;
5513 }
5514 } else {
5515 send_buf->ah = &ibp->smi_ah->ibah;
5516 ret = 0;
5517 }
5518
5519 smp = send_buf->mad;
5520 smp->base_version = IB_MGMT_BASE_VERSION;
5521 smp->mgmt_class = IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE;
5522 smp->class_version = 1;
5523 smp->method = IB_MGMT_METHOD_SEND;
5524 smp->hop_cnt = 1;
5525 smp->attr_id = QIB_VENDOR_IPG;
5526 smp->attr_mod = 0;
5527
5528 if (!ret)
5529 ret = ib_post_send_mad(send_buf, NULL);
5530 if (ret)
5531 ib_free_send_mad(send_buf);
5532retry:
5533 delay = 2 << ppd->cpspec->ipg_tries;
5534 queue_delayed_work(ib_wq, &ppd->cpspec->ipg_work,
5535 msecs_to_jiffies(delay));
5536}
5537
5538
5539
5540
5541
5542static void ipg_7322_work(struct work_struct *work)
5543{
5544 struct qib_pportdata *ppd;
5545
5546 ppd = container_of(work, struct qib_chippport_specific,
5547 ipg_work.work)->ppd;
5548 if ((ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED | QIBL_LINKACTIVE))
5549 && ++ppd->cpspec->ipg_tries <= 10)
5550 try_7322_ipg(ppd);
5551}
5552
5553static u32 qib_7322_iblink_state(u64 ibcs)
5554{
5555 u32 state = (u32)SYM_FIELD(ibcs, IBCStatusA_0, LinkState);
5556
5557 switch (state) {
5558 case IB_7322_L_STATE_INIT:
5559 state = IB_PORT_INIT;
5560 break;
5561 case IB_7322_L_STATE_ARM:
5562 state = IB_PORT_ARMED;
5563 break;
5564 case IB_7322_L_STATE_ACTIVE:
5565
5566 case IB_7322_L_STATE_ACT_DEFER:
5567 state = IB_PORT_ACTIVE;
5568 break;
5569 default:
5570 case IB_7322_L_STATE_DOWN:
5571 state = IB_PORT_DOWN;
5572 break;
5573 }
5574 return state;
5575}
5576
5577
5578static u8 qib_7322_phys_portstate(u64 ibcs)
5579{
5580 u8 state = (u8)SYM_FIELD(ibcs, IBCStatusA_0, LinkTrainingState);
5581 return qib_7322_physportstate[state];
5582}
5583
5584static int qib_7322_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
5585{
5586 int ret = 0, symadj = 0;
5587 unsigned long flags;
5588 int mult;
5589
5590 spin_lock_irqsave(&ppd->lflags_lock, flags);
5591 ppd->lflags &= ~QIBL_IB_FORCE_NOTIFY;
5592 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5593
5594
5595 if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedQDR)) {
5596 ppd->link_speed_active = QIB_IB_QDR;
5597 mult = 4;
5598 } else if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedActive)) {
5599 ppd->link_speed_active = QIB_IB_DDR;
5600 mult = 2;
5601 } else {
5602 ppd->link_speed_active = QIB_IB_SDR;
5603 mult = 1;
5604 }
5605 if (ibcs & SYM_MASK(IBCStatusA_0, LinkWidthActive)) {
5606 ppd->link_width_active = IB_WIDTH_4X;
5607 mult *= 4;
5608 } else
5609 ppd->link_width_active = IB_WIDTH_1X;
5610 ppd->delay_mult = ib_rate_to_delay[mult_to_ib_rate(mult)];
5611
5612 if (!ibup) {
5613 u64 clr;
5614
5615
5616
5617 ppd->cpspec->ipg_tries = 0;
5618 clr = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
5619 (SYM_MASK(IBCStatusB_0, heartbeat_timed_out) |
5620 SYM_MASK(IBCStatusB_0, heartbeat_crosstalk));
5621 if (clr)
5622 qib_write_kreg_port(ppd, krp_ibcstatus_b, clr);
5623 if (!(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
5624 QIBL_IB_AUTONEG_INPROG)))
5625 set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
5626 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
5627 struct qib_qsfp_data *qd =
5628 &ppd->cpspec->qsfp_data;
5629
5630 qib_write_kreg_port(ppd, krp_tx_deemph_override,
5631 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
5632 reset_tx_deemphasis_override));
5633 qib_cancel_sends(ppd);
5634
5635 qib_7322_mini_pcs_reset(ppd);
5636
5637
5638 if (ppd->dd->flags & QIB_HAS_QSFP) {
5639 qd->t_insert = jiffies;
5640 queue_work(ib_wq, &qd->work);
5641 }
5642 spin_lock_irqsave(&ppd->sdma_lock, flags);
5643 if (__qib_sdma_running(ppd))
5644 __qib_sdma_process_event(ppd,
5645 qib_sdma_event_e70_go_idle);
5646 spin_unlock_irqrestore(&ppd->sdma_lock, flags);
5647 }
5648 clr = read_7322_creg32_port(ppd, crp_iblinkdown);
5649 if (clr == ppd->cpspec->iblnkdownsnap)
5650 ppd->cpspec->iblnkdowndelta++;
5651 } else {
5652 if (qib_compat_ddr_negotiate &&
5653 !(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
5654 QIBL_IB_AUTONEG_INPROG)) &&
5655 ppd->link_speed_active == QIB_IB_SDR &&
5656 (ppd->link_speed_enabled & QIB_IB_DDR)
5657 && ppd->cpspec->autoneg_tries < AUTONEG_TRIES) {
5658
5659 ++ppd->cpspec->autoneg_tries;
5660 if (!ppd->cpspec->ibdeltainprog) {
5661 ppd->cpspec->ibdeltainprog = 1;
5662 ppd->cpspec->ibsymdelta +=
5663 read_7322_creg32_port(ppd,
5664 crp_ibsymbolerr) -
5665 ppd->cpspec->ibsymsnap;
5666 ppd->cpspec->iblnkerrdelta +=
5667 read_7322_creg32_port(ppd,
5668 crp_iblinkerrrecov) -
5669 ppd->cpspec->iblnkerrsnap;
5670 }
5671 try_7322_autoneg(ppd);
5672 ret = 1;
5673 } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
5674 ppd->link_speed_active == QIB_IB_SDR) {
5675 qib_autoneg_7322_send(ppd, 1);
5676 set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
5677 qib_7322_mini_pcs_reset(ppd);
5678 udelay(2);
5679 ret = 1;
5680 } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
5681 (ppd->link_speed_active & QIB_IB_DDR)) {
5682 spin_lock_irqsave(&ppd->lflags_lock, flags);
5683 ppd->lflags &= ~(QIBL_IB_AUTONEG_INPROG |
5684 QIBL_IB_AUTONEG_FAILED);
5685 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5686 ppd->cpspec->autoneg_tries = 0;
5687
5688 set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
5689 wake_up(&ppd->cpspec->autoneg_wait);
5690 symadj = 1;
5691 } else if (ppd->lflags & QIBL_IB_AUTONEG_FAILED) {
5692
5693
5694
5695
5696
5697
5698 spin_lock_irqsave(&ppd->lflags_lock, flags);
5699 ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
5700 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5701 ppd->cpspec->ibcctrl_b |= IBA7322_IBC_IBTA_1_2_MASK;
5702 symadj = 1;
5703 }
5704 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
5705 symadj = 1;
5706 if (ppd->dd->cspec->r1 && ppd->cpspec->ipg_tries <= 10)
5707 try_7322_ipg(ppd);
5708 if (!ppd->cpspec->recovery_init)
5709 setup_7322_link_recovery(ppd, 0);
5710 ppd->cpspec->qdr_dfe_time = jiffies +
5711 msecs_to_jiffies(QDR_DFE_DISABLE_DELAY);
5712 }
5713 ppd->cpspec->ibmalfusesnap = 0;
5714 ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
5715 crp_errlink);
5716 }
5717 if (symadj) {
5718 ppd->cpspec->iblnkdownsnap =
5719 read_7322_creg32_port(ppd, crp_iblinkdown);
5720 if (ppd->cpspec->ibdeltainprog) {
5721 ppd->cpspec->ibdeltainprog = 0;
5722 ppd->cpspec->ibsymdelta += read_7322_creg32_port(ppd,
5723 crp_ibsymbolerr) - ppd->cpspec->ibsymsnap;
5724 ppd->cpspec->iblnkerrdelta += read_7322_creg32_port(ppd,
5725 crp_iblinkerrrecov) - ppd->cpspec->iblnkerrsnap;
5726 }
5727 } else if (!ibup && qib_compat_ddr_negotiate &&
5728 !ppd->cpspec->ibdeltainprog &&
5729 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
5730 ppd->cpspec->ibdeltainprog = 1;
5731 ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
5732 crp_ibsymbolerr);
5733 ppd->cpspec->iblnkerrsnap = read_7322_creg32_port(ppd,
5734 crp_iblinkerrrecov);
5735 }
5736
5737 if (!ret)
5738 qib_setup_7322_setextled(ppd, ibup);
5739 return ret;
5740}
5741
5742
5743
5744
5745
5746
5747
5748
5749static int gpio_7322_mod(struct qib_devdata *dd, u32 out, u32 dir, u32 mask)
5750{
5751 u64 read_val, new_out;
5752 unsigned long flags;
5753
5754 if (mask) {
5755
5756 dir &= mask;
5757 out &= mask;
5758 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
5759 dd->cspec->extctrl &= ~((u64)mask << SYM_LSB(EXTCtrl, GPIOOe));
5760 dd->cspec->extctrl |= ((u64) dir << SYM_LSB(EXTCtrl, GPIOOe));
5761 new_out = (dd->cspec->gpio_out & ~mask) | out;
5762
5763 qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
5764 qib_write_kreg(dd, kr_gpio_out, new_out);
5765 dd->cspec->gpio_out = new_out;
5766 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
5767 }
5768
5769
5770
5771
5772
5773
5774
5775
5776 read_val = qib_read_kreg64(dd, kr_extstatus);
5777 return SYM_FIELD(read_val, EXTStatus, GPIOIn);
5778}
5779
5780
5781static int qib_7322_eeprom_wen(struct qib_devdata *dd, int wen)
5782{
5783 int prev_wen;
5784 u32 mask;
5785
5786 mask = 1 << QIB_EEPROM_WEN_NUM;
5787 prev_wen = ~gpio_7322_mod(dd, 0, 0, 0) >> QIB_EEPROM_WEN_NUM;
5788 gpio_7322_mod(dd, wen ? 0 : mask, mask, mask);
5789
5790 return prev_wen & 1;
5791}
5792
5793
5794
5795
5796
5797
5798static void get_7322_chip_params(struct qib_devdata *dd)
5799{
5800 u64 val;
5801 u32 piobufs;
5802 int mtu;
5803
5804 dd->palign = qib_read_kreg32(dd, kr_pagealign);
5805
5806 dd->uregbase = qib_read_kreg32(dd, kr_userregbase);
5807
5808 dd->rcvtidcnt = qib_read_kreg32(dd, kr_rcvtidcnt);
5809 dd->rcvtidbase = qib_read_kreg32(dd, kr_rcvtidbase);
5810 dd->rcvegrbase = qib_read_kreg32(dd, kr_rcvegrbase);
5811 dd->piobufbase = qib_read_kreg64(dd, kr_sendpiobufbase);
5812 dd->pio2k_bufbase = dd->piobufbase & 0xffffffff;
5813
5814 val = qib_read_kreg64(dd, kr_sendpiobufcnt);
5815 dd->piobcnt2k = val & ~0U;
5816 dd->piobcnt4k = val >> 32;
5817 val = qib_read_kreg64(dd, kr_sendpiosize);
5818 dd->piosize2k = val & ~0U;
5819 dd->piosize4k = val >> 32;
5820
5821 mtu = ib_mtu_enum_to_int(qib_ibmtu);
5822 if (mtu == -1)
5823 mtu = QIB_DEFAULT_MTU;
5824 dd->pport[0].ibmtu = (u32)mtu;
5825 dd->pport[1].ibmtu = (u32)mtu;
5826
5827
5828 dd->pio2kbase = (u32 __iomem *)
5829 ((char __iomem *) dd->kregbase + dd->pio2k_bufbase);
5830 dd->pio4kbase = (u32 __iomem *)
5831 ((char __iomem *) dd->kregbase +
5832 (dd->piobufbase >> 32));
5833
5834
5835
5836
5837
5838 dd->align4k = ALIGN(dd->piosize4k, dd->palign);
5839
5840 piobufs = dd->piobcnt4k + dd->piobcnt2k + NUM_VL15_BUFS;
5841
5842 dd->pioavregs = ALIGN(piobufs, sizeof(u64) * BITS_PER_BYTE / 2) /
5843 (sizeof(u64) * BITS_PER_BYTE / 2);
5844}
5845
5846
5847
5848
5849
5850
5851static void qib_7322_set_baseaddrs(struct qib_devdata *dd)
5852{
5853 u32 cregbase;
5854 cregbase = qib_read_kreg32(dd, kr_counterregbase);
5855
5856 dd->cspec->cregbase = (u64 __iomem *)(cregbase +
5857 (char __iomem *)dd->kregbase);
5858
5859 dd->egrtidbase = (u64 __iomem *)
5860 ((char __iomem *) dd->kregbase + dd->rcvegrbase);
5861
5862
5863 dd->pport[0].cpspec->kpregbase =
5864 (u64 __iomem *)((char __iomem *)dd->kregbase);
5865 dd->pport[1].cpspec->kpregbase =
5866 (u64 __iomem *)(dd->palign +
5867 (char __iomem *)dd->kregbase);
5868 dd->pport[0].cpspec->cpregbase =
5869 (u64 __iomem *)(qib_read_kreg_port(&dd->pport[0],
5870 kr_counterregbase) + (char __iomem *)dd->kregbase);
5871 dd->pport[1].cpspec->cpregbase =
5872 (u64 __iomem *)(qib_read_kreg_port(&dd->pport[1],
5873 kr_counterregbase) + (char __iomem *)dd->kregbase);
5874}
5875
5876
5877
5878
5879
5880
5881#define SENDCTRL_SHADOWED (SYM_MASK(SendCtrl_0, SendEnable) | \
5882 SYM_MASK(SendCtrl_0, SDmaEnable) | \
5883 SYM_MASK(SendCtrl_0, SDmaIntEnable) | \
5884 SYM_MASK(SendCtrl_0, SDmaSingleDescriptor) | \
5885 SYM_MASK(SendCtrl_0, SDmaHalt) | \
5886 SYM_MASK(SendCtrl_0, IBVLArbiterEn) | \
5887 SYM_MASK(SendCtrl_0, ForceCreditUpToDate))
5888
5889static int sendctrl_hook(struct qib_devdata *dd,
5890 const struct diag_observer *op, u32 offs,
5891 u64 *data, u64 mask, int only_32)
5892{
5893 unsigned long flags;
5894 unsigned idx;
5895 unsigned pidx;
5896 struct qib_pportdata *ppd = NULL;
5897 u64 local_data, all_bits;
5898
5899
5900
5901
5902
5903
5904
5905 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
5906 u64 __iomem *psptr;
5907 u32 psoffs;
5908
5909 ppd = dd->pport + pidx;
5910 if (!ppd->cpspec->kpregbase)
5911 continue;
5912
5913 psptr = ppd->cpspec->kpregbase + krp_sendctrl;
5914 psoffs = (u32) (psptr - dd->kregbase) * sizeof(*psptr);
5915 if (psoffs == offs)
5916 break;
5917 }
5918
5919
5920 if (pidx >= dd->num_pports)
5921 ppd = NULL;
5922
5923
5924 idx = offs / sizeof(u64);
5925
5926 all_bits = ~0ULL;
5927 if (only_32)
5928 all_bits >>= 32;
5929
5930 spin_lock_irqsave(&dd->sendctrl_lock, flags);
5931 if (!ppd || (mask & all_bits) != all_bits) {
5932
5933
5934
5935
5936
5937
5938
5939 if (only_32)
5940 local_data = (u64)qib_read_kreg32(dd, idx);
5941 else
5942 local_data = qib_read_kreg64(dd, idx);
5943 *data = (local_data & ~mask) | (*data & mask);
5944 }
5945 if (mask) {
5946
5947
5948
5949
5950 u64 sval, tval;
5951
5952
5953
5954
5955
5956 if (ppd) {
5957 sval = ppd->p_sendctrl & ~mask;
5958 sval |= *data & SENDCTRL_SHADOWED & mask;
5959 ppd->p_sendctrl = sval;
5960 } else
5961 sval = *data & SENDCTRL_SHADOWED & mask;
5962 tval = sval | (*data & ~SENDCTRL_SHADOWED & mask);
5963 qib_write_kreg(dd, idx, tval);
5964 qib_write_kreg(dd, kr_scratch, 0Ull);
5965 }
5966 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
5967 return only_32 ? 4 : 8;
5968}
5969
5970static const struct diag_observer sendctrl_0_observer = {
5971 sendctrl_hook, KREG_IDX(SendCtrl_0) * sizeof(u64),
5972 KREG_IDX(SendCtrl_0) * sizeof(u64)
5973};
5974
5975static const struct diag_observer sendctrl_1_observer = {
5976 sendctrl_hook, KREG_IDX(SendCtrl_1) * sizeof(u64),
5977 KREG_IDX(SendCtrl_1) * sizeof(u64)
5978};
5979
5980static ushort sdma_fetch_prio = 8;
5981module_param_named(sdma_fetch_prio, sdma_fetch_prio, ushort, S_IRUGO);
5982MODULE_PARM_DESC(sdma_fetch_prio, "SDMA descriptor fetch priority");
5983
5984
5985static void init_txdds_table(struct qib_pportdata *ppd, int override);
5986
5987static void qsfp_7322_event(struct work_struct *work)
5988{
5989 struct qib_qsfp_data *qd;
5990 struct qib_pportdata *ppd;
5991 unsigned long pwrup;
5992 unsigned long flags;
5993 int ret;
5994 u32 le2;
5995
5996 qd = container_of(work, struct qib_qsfp_data, work);
5997 ppd = qd->ppd;
5998 pwrup = qd->t_insert +
5999 msecs_to_jiffies(QSFP_PWR_LAG_MSEC - QSFP_MODPRS_LAG_MSEC);
6000
6001
6002 mdelay(QSFP_MODPRS_LAG_MSEC);
6003
6004 if (!qib_qsfp_mod_present(ppd)) {
6005 ppd->cpspec->qsfp_data.modpresent = 0;
6006
6007 qib_set_ib_7322_lstate(ppd, 0,
6008 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
6009 spin_lock_irqsave(&ppd->lflags_lock, flags);
6010 ppd->lflags &= ~QIBL_LINKV;
6011 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
6012 } else {
6013
6014
6015
6016
6017
6018 while (1) {
6019 if (time_is_before_jiffies(pwrup))
6020 break;
6021 msleep(20);
6022 }
6023
6024 ret = qib_refresh_qsfp_cache(ppd, &qd->cache);
6025
6026
6027
6028
6029
6030
6031
6032 if (!ret && !ppd->dd->cspec->r1) {
6033 if (QSFP_IS_ACTIVE_FAR(qd->cache.tech))
6034 le2 = LE2_QME;
6035 else if (qd->cache.atten[1] >= qib_long_atten &&
6036 QSFP_IS_CU(qd->cache.tech))
6037 le2 = LE2_5m;
6038 else
6039 le2 = LE2_DEFAULT;
6040 } else
6041 le2 = LE2_DEFAULT;
6042 ibsd_wr_allchans(ppd, 13, (le2 << 7), BMASK(9, 7));
6043
6044
6045
6046
6047
6048
6049 init_txdds_table(ppd, 0);
6050
6051
6052
6053
6054 if (!ppd->cpspec->qsfp_data.modpresent &&
6055 (ppd->lflags & (QIBL_LINKV | QIBL_IB_LINK_DISABLED))) {
6056 ppd->cpspec->qsfp_data.modpresent = 1;
6057 qib_set_ib_7322_lstate(ppd, 0,
6058 QLOGIC_IB_IBCC_LINKINITCMD_SLEEP);
6059 spin_lock_irqsave(&ppd->lflags_lock, flags);
6060 ppd->lflags |= QIBL_LINKV;
6061 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
6062 }
6063 }
6064}
6065
6066
6067
6068
6069
6070static void qib_init_7322_qsfp(struct qib_pportdata *ppd)
6071{
6072 unsigned long flags;
6073 struct qib_qsfp_data *qd = &ppd->cpspec->qsfp_data;
6074 struct qib_devdata *dd = ppd->dd;
6075 u64 mod_prs_bit = QSFP_GPIO_MOD_PRS_N;
6076
6077 mod_prs_bit <<= (QSFP_GPIO_PORT2_SHIFT * ppd->hw_pidx);
6078 qd->ppd = ppd;
6079 qib_qsfp_init(qd, qsfp_7322_event);
6080 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
6081 dd->cspec->extctrl |= (mod_prs_bit << SYM_LSB(EXTCtrl, GPIOInvert));
6082 dd->cspec->gpio_mask |= mod_prs_bit;
6083 qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
6084 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
6085 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
6086}
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101static void set_no_qsfp_atten(struct qib_devdata *dd, int change)
6102{
6103 char *nxt, *str;
6104 u32 pidx, unit, port, deflt, h1;
6105 unsigned long val;
6106 int any = 0, seth1;
6107 int txdds_size;
6108
6109 str = txselect_list;
6110
6111
6112 deflt = simple_strtoul(str, &nxt, 0);
6113 for (pidx = 0; pidx < dd->num_pports; ++pidx)
6114 dd->pport[pidx].cpspec->no_eep = deflt;
6115
6116 txdds_size = TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ;
6117 if (IS_QME(dd) || IS_QMH(dd))
6118 txdds_size += TXDDS_MFG_SZ;
6119
6120 while (*nxt && nxt[1]) {
6121 str = ++nxt;
6122 unit = simple_strtoul(str, &nxt, 0);
6123 if (nxt == str || !*nxt || *nxt != ',') {
6124 while (*nxt && *nxt++ != ' ')
6125 ;
6126 continue;
6127 }
6128 str = ++nxt;
6129 port = simple_strtoul(str, &nxt, 0);
6130 if (nxt == str || *nxt != '=') {
6131 while (*nxt && *nxt++ != ' ')
6132 ;
6133 continue;
6134 }
6135 str = ++nxt;
6136 val = simple_strtoul(str, &nxt, 0);
6137 if (nxt == str) {
6138 while (*nxt && *nxt++ != ' ')
6139 ;
6140 continue;
6141 }
6142 if (val >= txdds_size)
6143 continue;
6144 seth1 = 0;
6145 h1 = 0;
6146 if (*nxt == ',' && nxt[1]) {
6147 str = ++nxt;
6148 h1 = (u32)simple_strtoul(str, &nxt, 0);
6149 if (nxt == str)
6150 while (*nxt && *nxt++ != ' ')
6151 ;
6152 else
6153 seth1 = 1;
6154 }
6155 for (pidx = 0; dd->unit == unit && pidx < dd->num_pports;
6156 ++pidx) {
6157 struct qib_pportdata *ppd = &dd->pport[pidx];
6158
6159 if (ppd->port != port || !ppd->link_speed_supported)
6160 continue;
6161 ppd->cpspec->no_eep = val;
6162 if (seth1)
6163 ppd->cpspec->h1_val = h1;
6164
6165 init_txdds_table(ppd, 1);
6166
6167
6168
6169 if (IS_QMH(dd) || IS_QME(dd))
6170 qib_set_ib_7322_lstate(ppd, 0,
6171 QLOGIC_IB_IBCC_LINKINITCMD_SLEEP);
6172 any++;
6173 }
6174 if (*nxt == '\n')
6175 break;
6176 }
6177 if (change && !any) {
6178
6179
6180
6181
6182 for (pidx = 0; pidx < dd->num_pports; ++pidx)
6183 if (dd->pport[pidx].link_speed_supported)
6184 init_txdds_table(&dd->pport[pidx], 0);
6185 }
6186}
6187
6188
6189static int setup_txselect(const char *str, struct kernel_param *kp)
6190{
6191 struct qib_devdata *dd;
6192 unsigned long val;
6193 int ret;
6194
6195 if (strlen(str) >= MAX_ATTEN_LEN) {
6196 pr_info("txselect_values string too long\n");
6197 return -ENOSPC;
6198 }
6199 ret = kstrtoul(str, 0, &val);
6200 if (ret || val >= (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
6201 TXDDS_MFG_SZ)) {
6202 pr_info("txselect_values must start with a number < %d\n",
6203 TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ + TXDDS_MFG_SZ);
6204 return ret ? ret : -EINVAL;
6205 }
6206
6207 strcpy(txselect_list, str);
6208 list_for_each_entry(dd, &qib_dev_list, list)
6209 if (dd->deviceid == PCI_DEVICE_ID_QLOGIC_IB_7322)
6210 set_no_qsfp_atten(dd, 1);
6211 return 0;
6212}
6213
6214
6215
6216
6217
6218
6219static int qib_late_7322_initreg(struct qib_devdata *dd)
6220{
6221 int ret = 0, n;
6222 u64 val;
6223
6224 qib_write_kreg(dd, kr_rcvhdrentsize, dd->rcvhdrentsize);
6225 qib_write_kreg(dd, kr_rcvhdrsize, dd->rcvhdrsize);
6226 qib_write_kreg(dd, kr_rcvhdrcnt, dd->rcvhdrcnt);
6227 qib_write_kreg(dd, kr_sendpioavailaddr, dd->pioavailregs_phys);
6228 val = qib_read_kreg64(dd, kr_sendpioavailaddr);
6229 if (val != dd->pioavailregs_phys) {
6230 qib_dev_err(dd,
6231 "Catastrophic software error, SendPIOAvailAddr written as %lx, read back as %llx\n",
6232 (unsigned long) dd->pioavailregs_phys,
6233 (unsigned long long) val);
6234 ret = -EINVAL;
6235 }
6236
6237 n = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
6238 qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_KERN, NULL);
6239
6240 qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_ENAB1, NULL);
6241
6242 qib_register_observer(dd, &sendctrl_0_observer);
6243 qib_register_observer(dd, &sendctrl_1_observer);
6244
6245 dd->control &= ~QLOGIC_IB_C_SDMAFETCHPRIOEN;
6246 qib_write_kreg(dd, kr_control, dd->control);
6247
6248
6249
6250
6251
6252
6253 set_no_qsfp_atten(dd, 0);
6254 for (n = 0; n < dd->num_pports; ++n) {
6255 struct qib_pportdata *ppd = dd->pport + n;
6256
6257 qib_write_kreg_port(ppd, krp_senddmaprioritythld,
6258 sdma_fetch_prio & 0xf);
6259
6260 if (dd->flags & QIB_HAS_QSFP)
6261 qib_init_7322_qsfp(ppd);
6262 }
6263 dd->control |= QLOGIC_IB_C_SDMAFETCHPRIOEN;
6264 qib_write_kreg(dd, kr_control, dd->control);
6265
6266 return ret;
6267}
6268
6269
6270#define SENDCTRL_PIBP (MASK_ACROSS(0, 1) | MASK_ACROSS(3, 3) | \
6271 MASK_ACROSS(8, 15))
6272#define RCVCTRL_PIBP (MASK_ACROSS(0, 17) | MASK_ACROSS(39, 41))
6273#define ERRS_PIBP (MASK_ACROSS(57, 58) | MASK_ACROSS(54, 54) | \
6274 MASK_ACROSS(36, 49) | MASK_ACROSS(29, 34) | MASK_ACROSS(14, 17) | \
6275 MASK_ACROSS(0, 11))
6276
6277
6278
6279
6280
6281
6282
6283static void write_7322_init_portregs(struct qib_pportdata *ppd)
6284{
6285 u64 val;
6286 int i;
6287
6288 if (!ppd->link_speed_supported) {
6289
6290 for (i = 1; i < 8; i++)
6291 qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, 0);
6292 qib_write_kreg_port(ppd, krp_ibcctrl_b, 0);
6293 qib_write_kreg(ppd->dd, kr_scratch, 0);
6294 return;
6295 }
6296
6297
6298
6299
6300
6301 val = qib_read_kreg_port(ppd, krp_ibsdtestiftx);
6302 val &= ~SYM_MASK(IB_SDTEST_IF_TX_0, VL_CAP);
6303 val |= (u64)(ppd->vls_supported - 1) <<
6304 SYM_LSB(IB_SDTEST_IF_TX_0, VL_CAP);
6305 qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
6306
6307 qib_write_kreg_port(ppd, krp_rcvbthqp, QIB_KD_QP);
6308
6309
6310 qib_write_kreg_port(ppd, krp_sendcheckcontrol, IBA7322_SENDCHK_PKEY |
6311 IBA7322_SENDCHK_BTHQP | IBA7322_SENDCHK_SLID |
6312 IBA7322_SENDCHK_RAW_IPV6 | IBA7322_SENDCHK_MINSZ);
6313
6314 qib_write_kreg_port(ppd, krp_ncmodectrl,
6315 SYM_MASK(IBNCModeCtrl_0, ScrambleCapLocal));
6316
6317
6318
6319
6320
6321 qib_write_kreg_port(ppd, krp_senddmabufmask0, 0);
6322 qib_write_kreg_port(ppd, krp_senddmabufmask1, 0);
6323 qib_write_kreg_port(ppd, krp_senddmabufmask2, 0);
6324 if (ppd->dd->cspec->r1)
6325 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, ForceCreditUpToDate);
6326}
6327
6328
6329
6330
6331
6332
6333
6334
6335static void write_7322_initregs(struct qib_devdata *dd)
6336{
6337 struct qib_pportdata *ppd;
6338 int i, pidx;
6339 u64 val;
6340
6341
6342 qib_write_kreg(dd, KREG_IDX(RcvQPMulticastContext_1), 1);
6343
6344 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
6345 unsigned n, regno;
6346 unsigned long flags;
6347
6348 if (dd->n_krcv_queues < 2 ||
6349 !dd->pport[pidx].link_speed_supported)
6350 continue;
6351
6352 ppd = &dd->pport[pidx];
6353
6354
6355 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
6356 ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvQPMapEnable);
6357 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
6358
6359
6360 regno = krp_rcvqpmaptable;
6361 val = 0;
6362 if (dd->num_pports > 1)
6363 n = dd->first_user_ctxt / dd->num_pports;
6364 else
6365 n = dd->first_user_ctxt - 1;
6366 for (i = 0; i < 32; ) {
6367 unsigned ctxt;
6368
6369 if (dd->num_pports > 1)
6370 ctxt = (i % n) * dd->num_pports + pidx;
6371 else if (i % n)
6372 ctxt = (i % n) + 1;
6373 else
6374 ctxt = ppd->hw_pidx;
6375 val |= ctxt << (5 * (i % 6));
6376 i++;
6377 if (i % 6 == 0) {
6378 qib_write_kreg_port(ppd, regno, val);
6379 val = 0;
6380 regno++;
6381 }
6382 }
6383 qib_write_kreg_port(ppd, regno, val);
6384 }
6385
6386
6387
6388
6389
6390
6391
6392 for (i = 0; i < dd->first_user_ctxt; i++) {
6393 dd->cspec->rcvavail_timeout[i] = rcv_int_timeout;
6394 qib_write_kreg(dd, kr_rcvavailtimeout + i, rcv_int_timeout);
6395 }
6396
6397
6398
6399
6400
6401
6402 val = TIDFLOW_ERRBITS;
6403 for (i = 0; i < dd->cfgctxts; i++) {
6404 int flow;
6405 for (flow = 0; flow < NUM_TIDFLOWS_CTXT; flow++)
6406 qib_write_ureg(dd, ur_rcvflowtable+flow, val, i);
6407 }
6408
6409
6410
6411
6412
6413
6414 if (dd->num_pports)
6415 setup_7322_link_recovery(dd->pport, dd->num_pports > 1);
6416}
6417
6418static int qib_init_7322_variables(struct qib_devdata *dd)
6419{
6420 struct qib_pportdata *ppd;
6421 unsigned features, pidx, sbufcnt;
6422 int ret, mtu;
6423 u32 sbufs, updthresh;
6424
6425
6426 ppd = (struct qib_pportdata *)(dd + 1);
6427 dd->pport = ppd;
6428 ppd[0].dd = dd;
6429 ppd[1].dd = dd;
6430
6431 dd->cspec = (struct qib_chip_specific *)(ppd + 2);
6432
6433 ppd[0].cpspec = (struct qib_chippport_specific *)(dd->cspec + 1);
6434 ppd[1].cpspec = &ppd[0].cpspec[1];
6435 ppd[0].cpspec->ppd = &ppd[0];
6436 ppd[1].cpspec->ppd = &ppd[1];
6437
6438 spin_lock_init(&dd->cspec->rcvmod_lock);
6439 spin_lock_init(&dd->cspec->gpio_lock);
6440
6441
6442 dd->revision = readq(&dd->kregbase[kr_revision]);
6443
6444 if ((dd->revision & 0xffffffffU) == 0xffffffffU) {
6445 qib_dev_err(dd,
6446 "Revision register read failure, giving up initialization\n");
6447 ret = -ENODEV;
6448 goto bail;
6449 }
6450 dd->flags |= QIB_PRESENT;
6451
6452 dd->majrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMajor);
6453 dd->minrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMinor);
6454 dd->cspec->r1 = dd->minrev == 1;
6455
6456 get_7322_chip_params(dd);
6457 features = qib_7322_boardname(dd);
6458
6459
6460 sbufcnt = dd->piobcnt2k + dd->piobcnt4k +
6461 NUM_VL15_BUFS + BITS_PER_LONG - 1;
6462 sbufcnt /= BITS_PER_LONG;
6463 dd->cspec->sendchkenable = kmalloc(sbufcnt *
6464 sizeof(*dd->cspec->sendchkenable), GFP_KERNEL);
6465 dd->cspec->sendgrhchk = kmalloc(sbufcnt *
6466 sizeof(*dd->cspec->sendgrhchk), GFP_KERNEL);
6467 dd->cspec->sendibchk = kmalloc(sbufcnt *
6468 sizeof(*dd->cspec->sendibchk), GFP_KERNEL);
6469 if (!dd->cspec->sendchkenable || !dd->cspec->sendgrhchk ||
6470 !dd->cspec->sendibchk) {
6471 qib_dev_err(dd, "Failed allocation for hdrchk bitmaps\n");
6472 ret = -ENOMEM;
6473 goto bail;
6474 }
6475
6476 ppd = dd->pport;
6477
6478
6479
6480
6481
6482 dd->gpio_sda_num = _QIB_GPIO_SDA_NUM;
6483 dd->gpio_scl_num = _QIB_GPIO_SCL_NUM;
6484 dd->twsi_eeprom_dev = QIB_TWSI_EEPROM_DEV;
6485
6486 dd->flags |= QIB_HAS_INTX | QIB_HAS_LINK_LATENCY |
6487 QIB_NODMA_RTAIL | QIB_HAS_VLSUPP | QIB_HAS_HDRSUPP |
6488 QIB_HAS_THRESH_UPDATE |
6489 (sdma_idle_cnt ? QIB_HAS_SDMA_TIMEOUT : 0);
6490 dd->flags |= qib_special_trigger ?
6491 QIB_USE_SPCL_TRIG : QIB_HAS_SEND_DMA;
6492
6493
6494
6495
6496
6497 qib_7322_set_baseaddrs(dd);
6498
6499 mtu = ib_mtu_enum_to_int(qib_ibmtu);
6500 if (mtu == -1)
6501 mtu = QIB_DEFAULT_MTU;
6502
6503 dd->cspec->int_enable_mask = QIB_I_BITSEXTANT;
6504
6505 dd->cspec->hwerrmask = ~0ULL;
6506
6507
6508 dd->cspec->hwerrmask &=
6509 ~(SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_0) |
6510 SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_1) |
6511 HWE_MASK(LATriggered));
6512
6513 for (pidx = 0; pidx < NUM_IB_PORTS; ++pidx) {
6514 struct qib_chippport_specific *cp = ppd->cpspec;
6515 ppd->link_speed_supported = features & PORT_SPD_CAP;
6516 features >>= PORT_SPD_CAP_SHIFT;
6517 if (!ppd->link_speed_supported) {
6518
6519 dd->skip_kctxt_mask |= 1 << pidx;
6520 if (pidx == 0) {
6521
6522 qib_write_kreg_port(ppd, krp_rcvctrl, 0);
6523 qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
6524 ppd[0] = ppd[1];
6525 dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
6526 IBSerdesPClkNotDetectMask_0)
6527 | SYM_MASK(HwErrMask,
6528 SDmaMemReadErrMask_0));
6529 dd->cspec->int_enable_mask &= ~(
6530 SYM_MASK(IntMask, SDmaCleanupDoneMask_0) |
6531 SYM_MASK(IntMask, SDmaIdleIntMask_0) |
6532 SYM_MASK(IntMask, SDmaProgressIntMask_0) |
6533 SYM_MASK(IntMask, SDmaIntMask_0) |
6534 SYM_MASK(IntMask, ErrIntMask_0) |
6535 SYM_MASK(IntMask, SendDoneIntMask_0));
6536 } else {
6537
6538 qib_write_kreg_port(ppd, krp_rcvctrl, 0);
6539 qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
6540 dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
6541 IBSerdesPClkNotDetectMask_1)
6542 | SYM_MASK(HwErrMask,
6543 SDmaMemReadErrMask_1));
6544 dd->cspec->int_enable_mask &= ~(
6545 SYM_MASK(IntMask, SDmaCleanupDoneMask_1) |
6546 SYM_MASK(IntMask, SDmaIdleIntMask_1) |
6547 SYM_MASK(IntMask, SDmaProgressIntMask_1) |
6548 SYM_MASK(IntMask, SDmaIntMask_1) |
6549 SYM_MASK(IntMask, ErrIntMask_1) |
6550 SYM_MASK(IntMask, SendDoneIntMask_1));
6551 }
6552 continue;
6553 }
6554
6555 dd->num_pports++;
6556 qib_init_pportdata(ppd, dd, pidx, dd->num_pports);
6557
6558 ppd->link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
6559 ppd->link_width_enabled = IB_WIDTH_4X;
6560 ppd->link_speed_enabled = ppd->link_speed_supported;
6561
6562
6563
6564
6565 ppd->link_width_active = IB_WIDTH_4X;
6566 ppd->link_speed_active = QIB_IB_SDR;
6567 ppd->delay_mult = ib_rate_to_delay[IB_RATE_10_GBPS];
6568 switch (qib_num_cfg_vls) {
6569 case 1:
6570 ppd->vls_supported = IB_VL_VL0;
6571 break;
6572 case 2:
6573 ppd->vls_supported = IB_VL_VL0_1;
6574 break;
6575 default:
6576 qib_devinfo(dd->pcidev,
6577 "Invalid num_vls %u, using 4 VLs\n",
6578 qib_num_cfg_vls);
6579 qib_num_cfg_vls = 4;
6580
6581 case 4:
6582 ppd->vls_supported = IB_VL_VL0_3;
6583 break;
6584 case 8:
6585 if (mtu <= 2048)
6586 ppd->vls_supported = IB_VL_VL0_7;
6587 else {
6588 qib_devinfo(dd->pcidev,
6589 "Invalid num_vls %u for MTU %d "
6590 ", using 4 VLs\n",
6591 qib_num_cfg_vls, mtu);
6592 ppd->vls_supported = IB_VL_VL0_3;
6593 qib_num_cfg_vls = 4;
6594 }
6595 break;
6596 }
6597 ppd->vls_operational = ppd->vls_supported;
6598
6599 init_waitqueue_head(&cp->autoneg_wait);
6600 INIT_DELAYED_WORK(&cp->autoneg_work,
6601 autoneg_7322_work);
6602 if (ppd->dd->cspec->r1)
6603 INIT_DELAYED_WORK(&cp->ipg_work, ipg_7322_work);
6604
6605
6606
6607
6608
6609
6610 if (!(dd->flags & QIB_HAS_QSFP)) {
6611 if (!IS_QMH(dd) && !IS_QME(dd))
6612 qib_devinfo(dd->pcidev,
6613 "IB%u:%u: Unknown mezzanine card type\n",
6614 dd->unit, ppd->port);
6615 cp->h1_val = IS_QMH(dd) ? H1_FORCE_QMH : H1_FORCE_QME;
6616
6617
6618
6619
6620 ppd->cpspec->no_eep = IS_QMH(dd) ?
6621 TXDDS_TABLE_SZ + 2 : TXDDS_TABLE_SZ + 4;
6622 } else
6623 cp->h1_val = H1_FORCE_VAL;
6624
6625
6626 if (!qib_mini_init)
6627 write_7322_init_portregs(ppd);
6628
6629 init_timer(&cp->chase_timer);
6630 cp->chase_timer.function = reenable_chase;
6631 cp->chase_timer.data = (unsigned long)ppd;
6632
6633 ppd++;
6634 }
6635
6636 dd->rcvhdrentsize = qib_rcvhdrentsize ?
6637 qib_rcvhdrentsize : QIB_RCVHDR_ENTSIZE;
6638 dd->rcvhdrsize = qib_rcvhdrsize ?
6639 qib_rcvhdrsize : QIB_DFLT_RCVHDRSIZE;
6640 dd->rhf_offset = dd->rcvhdrentsize - sizeof(u64) / sizeof(u32);
6641
6642
6643 dd->rcvegrbufsize = max(mtu, 2048);
6644 BUG_ON(!is_power_of_2(dd->rcvegrbufsize));
6645 dd->rcvegrbufsize_shift = ilog2(dd->rcvegrbufsize);
6646
6647 qib_7322_tidtemplate(dd);
6648
6649
6650
6651
6652
6653 dd->rhdrhead_intr_off =
6654 (u64) rcv_int_count << IBA7322_HDRHEAD_PKTINT_SHIFT;
6655
6656
6657 init_timer(&dd->stats_timer);
6658 dd->stats_timer.function = qib_get_7322_faststats;
6659 dd->stats_timer.data = (unsigned long) dd;
6660
6661 dd->ureg_align = 0x10000;
6662
6663 dd->piosize2kmax_dwords = dd->piosize2k >> 2;
6664
6665 qib_7322_config_ctxts(dd);
6666 qib_set_ctxtcnt(dd);
6667
6668 if (qib_wc_pat) {
6669 resource_size_t vl15off;
6670
6671
6672
6673
6674
6675
6676
6677 ret = init_chip_wc_pat(dd, 0);
6678 if (ret)
6679 goto bail;
6680
6681
6682 vl15off = dd->physaddr + (dd->piobufbase >> 32) +
6683 dd->piobcnt4k * dd->align4k;
6684 dd->piovl15base = ioremap_nocache(vl15off,
6685 NUM_VL15_BUFS * dd->align4k);
6686 if (!dd->piovl15base) {
6687 ret = -ENOMEM;
6688 goto bail;
6689 }
6690 }
6691 qib_7322_set_baseaddrs(dd);
6692
6693 ret = 0;
6694 if (qib_mini_init)
6695 goto bail;
6696 if (!dd->num_pports) {
6697 qib_dev_err(dd, "No ports enabled, giving up initialization\n");
6698 goto bail;
6699 }
6700
6701 write_7322_initregs(dd);
6702 ret = qib_create_ctxts(dd);
6703 init_7322_cntrnames(dd);
6704
6705 updthresh = 8U;
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717 if (dd->flags & QIB_HAS_SEND_DMA) {
6718 dd->cspec->sdmabufcnt = dd->piobcnt4k;
6719 sbufs = updthresh > 3 ? updthresh : 3;
6720 } else {
6721 dd->cspec->sdmabufcnt = 0;
6722 sbufs = dd->piobcnt4k;
6723 }
6724 dd->cspec->lastbuf_for_pio = dd->piobcnt2k + dd->piobcnt4k -
6725 dd->cspec->sdmabufcnt;
6726 dd->lastctxt_piobuf = dd->cspec->lastbuf_for_pio - sbufs;
6727 dd->cspec->lastbuf_for_pio--;
6728 dd->last_pio = dd->cspec->lastbuf_for_pio;
6729 dd->pbufsctxt = (dd->cfgctxts > dd->first_user_ctxt) ?
6730 dd->lastctxt_piobuf / (dd->cfgctxts - dd->first_user_ctxt) : 0;
6731
6732
6733
6734
6735
6736
6737
6738 if (dd->pbufsctxt >= 2 && dd->pbufsctxt - 2 < updthresh)
6739 updthresh = dd->pbufsctxt - 2;
6740 dd->cspec->updthresh_dflt = updthresh;
6741 dd->cspec->updthresh = updthresh;
6742
6743
6744 dd->sendctrl |= ((updthresh & SYM_RMASK(SendCtrl, AvailUpdThld))
6745 << SYM_LSB(SendCtrl, AvailUpdThld)) |
6746 SYM_MASK(SendCtrl, SendBufAvailPad64Byte);
6747
6748 dd->psxmitwait_supported = 1;
6749 dd->psxmitwait_check_rate = QIB_7322_PSXMITWAIT_CHECK_RATE;
6750bail:
6751 if (!dd->ctxtcnt)
6752 dd->ctxtcnt = 1;
6753
6754 return ret;
6755}
6756
6757static u32 __iomem *qib_7322_getsendbuf(struct qib_pportdata *ppd, u64 pbc,
6758 u32 *pbufnum)
6759{
6760 u32 first, last, plen = pbc & QIB_PBC_LENGTH_MASK;
6761 struct qib_devdata *dd = ppd->dd;
6762
6763
6764 if (pbc & PBC_7322_VL15_SEND) {
6765 first = dd->piobcnt2k + dd->piobcnt4k + ppd->hw_pidx;
6766 last = first;
6767 } else {
6768 if ((plen + 1) > dd->piosize2kmax_dwords)
6769 first = dd->piobcnt2k;
6770 else
6771 first = 0;
6772 last = dd->cspec->lastbuf_for_pio;
6773 }
6774 return qib_getsendbuf_range(dd, pbufnum, first, last);
6775}
6776
6777static void qib_set_cntr_7322_sample(struct qib_pportdata *ppd, u32 intv,
6778 u32 start)
6779{
6780 qib_write_kreg_port(ppd, krp_psinterval, intv);
6781 qib_write_kreg_port(ppd, krp_psstart, start);
6782}
6783
6784
6785
6786
6787static void qib_sdma_set_7322_desc_cnt(struct qib_pportdata *ppd, unsigned cnt)
6788{
6789 qib_write_kreg_port(ppd, krp_senddmadesccnt, cnt);
6790}
6791
6792
6793
6794
6795static void dump_sdma_7322_state(struct qib_pportdata *ppd)
6796{
6797 u64 reg, reg1, reg2;
6798
6799 reg = qib_read_kreg_port(ppd, krp_senddmastatus);
6800 qib_dev_porterr(ppd->dd, ppd->port,
6801 "SDMA senddmastatus: 0x%016llx\n", reg);
6802
6803 reg = qib_read_kreg_port(ppd, krp_sendctrl);
6804 qib_dev_porterr(ppd->dd, ppd->port,
6805 "SDMA sendctrl: 0x%016llx\n", reg);
6806
6807 reg = qib_read_kreg_port(ppd, krp_senddmabase);
6808 qib_dev_porterr(ppd->dd, ppd->port,
6809 "SDMA senddmabase: 0x%016llx\n", reg);
6810
6811 reg = qib_read_kreg_port(ppd, krp_senddmabufmask0);
6812 reg1 = qib_read_kreg_port(ppd, krp_senddmabufmask1);
6813 reg2 = qib_read_kreg_port(ppd, krp_senddmabufmask2);
6814 qib_dev_porterr(ppd->dd, ppd->port,
6815 "SDMA senddmabufmask 0:%llx 1:%llx 2:%llx\n",
6816 reg, reg1, reg2);
6817
6818
6819 reg = qib_read_kreg_port(ppd, krp_senddmabuf_use0);
6820 qib_write_kreg_port(ppd, krp_senddmabuf_use0, reg);
6821 reg1 = qib_read_kreg_port(ppd, krp_senddmabuf_use1);
6822 qib_write_kreg_port(ppd, krp_senddmabuf_use0, reg1);
6823 reg2 = qib_read_kreg_port(ppd, krp_senddmabuf_use2);
6824 qib_write_kreg_port(ppd, krp_senddmabuf_use0, reg2);
6825
6826 qib_dev_porterr(ppd->dd, ppd->port,
6827 "SDMA current senddmabuf_use 0:%llx 1:%llx 2:%llx\n",
6828 reg, reg1, reg2);
6829 reg = qib_read_kreg_port(ppd, krp_senddmabuf_use0);
6830 reg1 = qib_read_kreg_port(ppd, krp_senddmabuf_use1);
6831 reg2 = qib_read_kreg_port(ppd, krp_senddmabuf_use2);
6832
6833 qib_dev_porterr(ppd->dd, ppd->port,
6834 "SDMA cleared senddmabuf_use 0:%llx 1:%llx 2:%llx\n",
6835 reg, reg1, reg2);
6836
6837 reg = qib_read_kreg_port(ppd, krp_senddmatail);
6838 qib_dev_porterr(ppd->dd, ppd->port,
6839 "SDMA senddmatail: 0x%016llx\n", reg);
6840
6841 reg = qib_read_kreg_port(ppd, krp_senddmahead);
6842 qib_dev_porterr(ppd->dd, ppd->port,
6843 "SDMA senddmahead: 0x%016llx\n", reg);
6844
6845 reg = qib_read_kreg_port(ppd, krp_senddmaheadaddr);
6846 qib_dev_porterr(ppd->dd, ppd->port,
6847 "SDMA senddmaheadaddr: 0x%016llx\n", reg);
6848
6849 reg = qib_read_kreg_port(ppd, krp_senddmalengen);
6850 qib_dev_porterr(ppd->dd, ppd->port,
6851 "SDMA senddmalengen: 0x%016llx\n", reg);
6852
6853 reg = qib_read_kreg_port(ppd, krp_senddmadesccnt);
6854 qib_dev_porterr(ppd->dd, ppd->port,
6855 "SDMA senddmadesccnt: 0x%016llx\n", reg);
6856
6857 reg = qib_read_kreg_port(ppd, krp_senddmaidlecnt);
6858 qib_dev_porterr(ppd->dd, ppd->port,
6859 "SDMA senddmaidlecnt: 0x%016llx\n", reg);
6860
6861 reg = qib_read_kreg_port(ppd, krp_senddmaprioritythld);
6862 qib_dev_porterr(ppd->dd, ppd->port,
6863 "SDMA senddmapriorityhld: 0x%016llx\n", reg);
6864
6865 reg = qib_read_kreg_port(ppd, krp_senddmareloadcnt);
6866 qib_dev_porterr(ppd->dd, ppd->port,
6867 "SDMA senddmareloadcnt: 0x%016llx\n", reg);
6868
6869 dump_sdma_state(ppd);
6870}
6871
6872static struct sdma_set_state_action sdma_7322_action_table[] = {
6873 [qib_sdma_state_s00_hw_down] = {
6874 .go_s99_running_tofalse = 1,
6875 .op_enable = 0,
6876 .op_intenable = 0,
6877 .op_halt = 0,
6878 .op_drain = 0,
6879 },
6880 [qib_sdma_state_s10_hw_start_up_wait] = {
6881 .op_enable = 0,
6882 .op_intenable = 1,
6883 .op_halt = 1,
6884 .op_drain = 0,
6885 },
6886 [qib_sdma_state_s20_idle] = {
6887 .op_enable = 1,
6888 .op_intenable = 1,
6889 .op_halt = 1,
6890 .op_drain = 0,
6891 },
6892 [qib_sdma_state_s30_sw_clean_up_wait] = {
6893 .op_enable = 0,
6894 .op_intenable = 1,
6895 .op_halt = 1,
6896 .op_drain = 0,
6897 },
6898 [qib_sdma_state_s40_hw_clean_up_wait] = {
6899 .op_enable = 1,
6900 .op_intenable = 1,
6901 .op_halt = 1,
6902 .op_drain = 0,
6903 },
6904 [qib_sdma_state_s50_hw_halt_wait] = {
6905 .op_enable = 1,
6906 .op_intenable = 1,
6907 .op_halt = 1,
6908 .op_drain = 1,
6909 },
6910 [qib_sdma_state_s99_running] = {
6911 .op_enable = 1,
6912 .op_intenable = 1,
6913 .op_halt = 0,
6914 .op_drain = 0,
6915 .go_s99_running_totrue = 1,
6916 },
6917};
6918
6919static void qib_7322_sdma_init_early(struct qib_pportdata *ppd)
6920{
6921 ppd->sdma_state.set_state_action = sdma_7322_action_table;
6922}
6923
6924static int init_sdma_7322_regs(struct qib_pportdata *ppd)
6925{
6926 struct qib_devdata *dd = ppd->dd;
6927 unsigned lastbuf, erstbuf;
6928 u64 senddmabufmask[3] = { 0 };
6929 int n, ret = 0;
6930
6931 qib_write_kreg_port(ppd, krp_senddmabase, ppd->sdma_descq_phys);
6932 qib_sdma_7322_setlengen(ppd);
6933 qib_sdma_update_7322_tail(ppd, 0);
6934 qib_write_kreg_port(ppd, krp_senddmareloadcnt, sdma_idle_cnt);
6935 qib_write_kreg_port(ppd, krp_senddmadesccnt, 0);
6936 qib_write_kreg_port(ppd, krp_senddmaheadaddr, ppd->sdma_head_phys);
6937
6938 if (dd->num_pports)
6939 n = dd->cspec->sdmabufcnt / dd->num_pports;
6940 else
6941 n = dd->cspec->sdmabufcnt;
6942 erstbuf = (dd->piobcnt2k + dd->piobcnt4k) -
6943 ((dd->num_pports == 1 || ppd->port == 2) ? n :
6944 dd->cspec->sdmabufcnt);
6945 lastbuf = erstbuf + n;
6946
6947 ppd->sdma_state.first_sendbuf = erstbuf;
6948 ppd->sdma_state.last_sendbuf = lastbuf;
6949 for (; erstbuf < lastbuf; ++erstbuf) {
6950 unsigned word = erstbuf / BITS_PER_LONG;
6951 unsigned bit = erstbuf & (BITS_PER_LONG - 1);
6952
6953 BUG_ON(word >= 3);
6954 senddmabufmask[word] |= 1ULL << bit;
6955 }
6956 qib_write_kreg_port(ppd, krp_senddmabufmask0, senddmabufmask[0]);
6957 qib_write_kreg_port(ppd, krp_senddmabufmask1, senddmabufmask[1]);
6958 qib_write_kreg_port(ppd, krp_senddmabufmask2, senddmabufmask[2]);
6959 return ret;
6960}
6961
6962
6963static u16 qib_sdma_7322_gethead(struct qib_pportdata *ppd)
6964{
6965 struct qib_devdata *dd = ppd->dd;
6966 int sane;
6967 int use_dmahead;
6968 u16 swhead;
6969 u16 swtail;
6970 u16 cnt;
6971 u16 hwhead;
6972
6973 use_dmahead = __qib_sdma_running(ppd) &&
6974 (dd->flags & QIB_HAS_SDMA_TIMEOUT);
6975retry:
6976 hwhead = use_dmahead ?
6977 (u16) le64_to_cpu(*ppd->sdma_head_dma) :
6978 (u16) qib_read_kreg_port(ppd, krp_senddmahead);
6979
6980 swhead = ppd->sdma_descq_head;
6981 swtail = ppd->sdma_descq_tail;
6982 cnt = ppd->sdma_descq_cnt;
6983
6984 if (swhead < swtail)
6985
6986 sane = (hwhead >= swhead) & (hwhead <= swtail);
6987 else if (swhead > swtail)
6988
6989 sane = ((hwhead >= swhead) && (hwhead < cnt)) ||
6990 (hwhead <= swtail);
6991 else
6992
6993 sane = (hwhead == swhead);
6994
6995 if (unlikely(!sane)) {
6996 if (use_dmahead) {
6997
6998 use_dmahead = 0;
6999 goto retry;
7000 }
7001
7002 hwhead = swhead;
7003 }
7004
7005 return hwhead;
7006}
7007
7008static int qib_sdma_7322_busy(struct qib_pportdata *ppd)
7009{
7010 u64 hwstatus = qib_read_kreg_port(ppd, krp_senddmastatus);
7011
7012 return (hwstatus & SYM_MASK(SendDmaStatus_0, ScoreBoardDrainInProg)) ||
7013 (hwstatus & SYM_MASK(SendDmaStatus_0, HaltInProg)) ||
7014 !(hwstatus & SYM_MASK(SendDmaStatus_0, InternalSDmaHalt)) ||
7015 !(hwstatus & SYM_MASK(SendDmaStatus_0, ScbEmpty));
7016}
7017
7018
7019
7020
7021
7022
7023
7024static u32 qib_7322_setpbc_control(struct qib_pportdata *ppd, u32 plen,
7025 u8 srate, u8 vl)
7026{
7027 u8 snd_mult = ppd->delay_mult;
7028 u8 rcv_mult = ib_rate_to_delay[srate];
7029 u32 ret;
7030
7031 ret = rcv_mult > snd_mult ? ((plen + 1) >> 1) * snd_mult : 0;
7032
7033
7034 if (vl == 15)
7035 ret |= PBC_7322_VL15_SEND_CTRL;
7036 else
7037 ret |= vl << PBC_VL_NUM_LSB;
7038 ret |= ((u32)(ppd->hw_pidx)) << PBC_PORT_SEL_LSB;
7039
7040 return ret;
7041}
7042
7043
7044
7045
7046
7047
7048
7049
7050static void qib_7322_initvl15_bufs(struct qib_devdata *dd)
7051{
7052 unsigned vl15bufs;
7053
7054 vl15bufs = dd->piobcnt2k + dd->piobcnt4k;
7055 qib_chg_pioavailkernel(dd, vl15bufs, NUM_VL15_BUFS,
7056 TXCHK_CHG_TYPE_KERN, NULL);
7057}
7058
7059static void qib_7322_init_ctxt(struct qib_ctxtdata *rcd)
7060{
7061 if (rcd->ctxt < NUM_IB_PORTS) {
7062 if (rcd->dd->num_pports > 1) {
7063 rcd->rcvegrcnt = KCTXT0_EGRCNT / 2;
7064 rcd->rcvegr_tid_base = rcd->ctxt ? rcd->rcvegrcnt : 0;
7065 } else {
7066 rcd->rcvegrcnt = KCTXT0_EGRCNT;
7067 rcd->rcvegr_tid_base = 0;
7068 }
7069 } else {
7070 rcd->rcvegrcnt = rcd->dd->cspec->rcvegrcnt;
7071 rcd->rcvegr_tid_base = KCTXT0_EGRCNT +
7072 (rcd->ctxt - NUM_IB_PORTS) * rcd->rcvegrcnt;
7073 }
7074}
7075
7076#define QTXSLEEPS 5000
7077static void qib_7322_txchk_change(struct qib_devdata *dd, u32 start,
7078 u32 len, u32 which, struct qib_ctxtdata *rcd)
7079{
7080 int i;
7081 const int last = start + len - 1;
7082 const int lastr = last / BITS_PER_LONG;
7083 u32 sleeps = 0;
7084 int wait = rcd != NULL;
7085 unsigned long flags;
7086
7087 while (wait) {
7088 unsigned long shadow;
7089 int cstart, previ = -1;
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099 for (cstart = start; cstart <= last; cstart++) {
7100 i = ((2 * cstart) + QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
7101 / BITS_PER_LONG;
7102 if (i != previ) {
7103 shadow = (unsigned long)
7104 le64_to_cpu(dd->pioavailregs_dma[i]);
7105 previ = i;
7106 }
7107 if (test_bit(((2 * cstart) +
7108 QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
7109 % BITS_PER_LONG, &shadow))
7110 break;
7111 }
7112
7113 if (cstart > last)
7114 break;
7115
7116 if (sleeps == QTXSLEEPS)
7117 break;
7118
7119 sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
7120 sleeps++;
7121 msleep(20);
7122 }
7123
7124 switch (which) {
7125 case TXCHK_CHG_TYPE_DIS1:
7126
7127
7128
7129
7130 for (i = start; i <= last; i++)
7131 clear_bit(i, dd->cspec->sendchkenable);
7132 break;
7133
7134 case TXCHK_CHG_TYPE_ENAB1:
7135
7136
7137
7138
7139
7140
7141 qib_read_kreg32(dd, kr_scratch);
7142 for (i = start; i <= last; i++)
7143 set_bit(i, dd->cspec->sendchkenable);
7144 break;
7145
7146 case TXCHK_CHG_TYPE_KERN:
7147
7148 for (i = start; i <= last; i++) {
7149 set_bit(i, dd->cspec->sendibchk);
7150 clear_bit(i, dd->cspec->sendgrhchk);
7151 }
7152 spin_lock_irqsave(&dd->uctxt_lock, flags);
7153
7154 for (i = dd->first_user_ctxt;
7155 dd->cspec->updthresh != dd->cspec->updthresh_dflt
7156 && i < dd->cfgctxts; i++)
7157 if (dd->rcd[i] && dd->rcd[i]->subctxt_cnt &&
7158 ((dd->rcd[i]->piocnt / dd->rcd[i]->subctxt_cnt) - 1)
7159 < dd->cspec->updthresh_dflt)
7160 break;
7161 spin_unlock_irqrestore(&dd->uctxt_lock, flags);
7162 if (i == dd->cfgctxts) {
7163 spin_lock_irqsave(&dd->sendctrl_lock, flags);
7164 dd->cspec->updthresh = dd->cspec->updthresh_dflt;
7165 dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
7166 dd->sendctrl |= (dd->cspec->updthresh &
7167 SYM_RMASK(SendCtrl, AvailUpdThld)) <<
7168 SYM_LSB(SendCtrl, AvailUpdThld);
7169 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
7170 sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
7171 }
7172 break;
7173
7174 case TXCHK_CHG_TYPE_USER:
7175
7176 for (i = start; i <= last; i++) {
7177 clear_bit(i, dd->cspec->sendibchk);
7178 set_bit(i, dd->cspec->sendgrhchk);
7179 }
7180 spin_lock_irqsave(&dd->sendctrl_lock, flags);
7181 if (rcd && rcd->subctxt_cnt && ((rcd->piocnt
7182 / rcd->subctxt_cnt) - 1) < dd->cspec->updthresh) {
7183 dd->cspec->updthresh = (rcd->piocnt /
7184 rcd->subctxt_cnt) - 1;
7185 dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
7186 dd->sendctrl |= (dd->cspec->updthresh &
7187 SYM_RMASK(SendCtrl, AvailUpdThld))
7188 << SYM_LSB(SendCtrl, AvailUpdThld);
7189 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
7190 sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
7191 } else
7192 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
7193 break;
7194
7195 default:
7196 break;
7197 }
7198
7199 for (i = start / BITS_PER_LONG; which >= 2 && i <= lastr; ++i)
7200 qib_write_kreg(dd, kr_sendcheckmask + i,
7201 dd->cspec->sendchkenable[i]);
7202
7203 for (i = start / BITS_PER_LONG; which < 2 && i <= lastr; ++i) {
7204 qib_write_kreg(dd, kr_sendgrhcheckmask + i,
7205 dd->cspec->sendgrhchk[i]);
7206 qib_write_kreg(dd, kr_sendibpktmask + i,
7207 dd->cspec->sendibchk[i]);
7208 }
7209
7210
7211
7212
7213
7214 qib_read_kreg32(dd, kr_scratch);
7215}
7216
7217
7218
7219static void writescratch(struct qib_devdata *dd, u32 val)
7220{
7221 qib_write_kreg(dd, kr_scratch, val);
7222}
7223
7224
7225static int qib_7322_tempsense_rd(struct qib_devdata *dd, int regnum)
7226{
7227 return -ENXIO;
7228}
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241struct qib_devdata *qib_init_iba7322_funcs(struct pci_dev *pdev,
7242 const struct pci_device_id *ent)
7243{
7244 struct qib_devdata *dd;
7245 int ret, i;
7246 u32 tabsize, actual_cnt = 0;
7247
7248 dd = qib_alloc_devdata(pdev,
7249 NUM_IB_PORTS * sizeof(struct qib_pportdata) +
7250 sizeof(struct qib_chip_specific) +
7251 NUM_IB_PORTS * sizeof(struct qib_chippport_specific));
7252 if (IS_ERR(dd))
7253 goto bail;
7254
7255 dd->f_bringup_serdes = qib_7322_bringup_serdes;
7256 dd->f_cleanup = qib_setup_7322_cleanup;
7257 dd->f_clear_tids = qib_7322_clear_tids;
7258 dd->f_free_irq = qib_7322_free_irq;
7259 dd->f_get_base_info = qib_7322_get_base_info;
7260 dd->f_get_msgheader = qib_7322_get_msgheader;
7261 dd->f_getsendbuf = qib_7322_getsendbuf;
7262 dd->f_gpio_mod = gpio_7322_mod;
7263 dd->f_eeprom_wen = qib_7322_eeprom_wen;
7264 dd->f_hdrqempty = qib_7322_hdrqempty;
7265 dd->f_ib_updown = qib_7322_ib_updown;
7266 dd->f_init_ctxt = qib_7322_init_ctxt;
7267 dd->f_initvl15_bufs = qib_7322_initvl15_bufs;
7268 dd->f_intr_fallback = qib_7322_intr_fallback;
7269 dd->f_late_initreg = qib_late_7322_initreg;
7270 dd->f_setpbc_control = qib_7322_setpbc_control;
7271 dd->f_portcntr = qib_portcntr_7322;
7272 dd->f_put_tid = qib_7322_put_tid;
7273 dd->f_quiet_serdes = qib_7322_mini_quiet_serdes;
7274 dd->f_rcvctrl = rcvctrl_7322_mod;
7275 dd->f_read_cntrs = qib_read_7322cntrs;
7276 dd->f_read_portcntrs = qib_read_7322portcntrs;
7277 dd->f_reset = qib_do_7322_reset;
7278 dd->f_init_sdma_regs = init_sdma_7322_regs;
7279 dd->f_sdma_busy = qib_sdma_7322_busy;
7280 dd->f_sdma_gethead = qib_sdma_7322_gethead;
7281 dd->f_sdma_sendctrl = qib_7322_sdma_sendctrl;
7282 dd->f_sdma_set_desc_cnt = qib_sdma_set_7322_desc_cnt;
7283 dd->f_sdma_update_tail = qib_sdma_update_7322_tail;
7284 dd->f_sendctrl = sendctrl_7322_mod;
7285 dd->f_set_armlaunch = qib_set_7322_armlaunch;
7286 dd->f_set_cntr_sample = qib_set_cntr_7322_sample;
7287 dd->f_iblink_state = qib_7322_iblink_state;
7288 dd->f_ibphys_portstate = qib_7322_phys_portstate;
7289 dd->f_get_ib_cfg = qib_7322_get_ib_cfg;
7290 dd->f_set_ib_cfg = qib_7322_set_ib_cfg;
7291 dd->f_set_ib_loopback = qib_7322_set_loopback;
7292 dd->f_get_ib_table = qib_7322_get_ib_table;
7293 dd->f_set_ib_table = qib_7322_set_ib_table;
7294 dd->f_set_intr_state = qib_7322_set_intr_state;
7295 dd->f_setextled = qib_setup_7322_setextled;
7296 dd->f_txchk_change = qib_7322_txchk_change;
7297 dd->f_update_usrhead = qib_update_7322_usrhead;
7298 dd->f_wantpiobuf_intr = qib_wantpiobuf_7322_intr;
7299 dd->f_xgxs_reset = qib_7322_mini_pcs_reset;
7300 dd->f_sdma_hw_clean_up = qib_7322_sdma_hw_clean_up;
7301 dd->f_sdma_hw_start_up = qib_7322_sdma_hw_start_up;
7302 dd->f_sdma_init_early = qib_7322_sdma_init_early;
7303 dd->f_writescratch = writescratch;
7304 dd->f_tempsense_rd = qib_7322_tempsense_rd;
7305#ifdef CONFIG_INFINIBAND_QIB_DCA
7306 dd->f_notify_dca = qib_7322_notify_dca;
7307#endif
7308
7309
7310
7311
7312
7313
7314 ret = qib_pcie_ddinit(dd, pdev, ent);
7315 if (ret < 0)
7316 goto bail_free;
7317
7318
7319 ret = qib_init_7322_variables(dd);
7320 if (ret)
7321 goto bail_cleanup;
7322
7323 if (qib_mini_init || !dd->num_pports)
7324 goto bail;
7325
7326
7327
7328
7329
7330
7331
7332 tabsize = dd->first_user_ctxt + ARRAY_SIZE(irq_table);
7333 for (i = 0; i < tabsize; i++)
7334 if ((i < ARRAY_SIZE(irq_table) &&
7335 irq_table[i].port <= dd->num_pports) ||
7336 (i >= ARRAY_SIZE(irq_table) &&
7337 dd->rcd[i - ARRAY_SIZE(irq_table)]))
7338 actual_cnt++;
7339
7340 if (qib_krcvq01_no_msi)
7341 actual_cnt -= dd->num_pports;
7342
7343 tabsize = actual_cnt;
7344 dd->cspec->msix_entries = kzalloc(tabsize *
7345 sizeof(struct qib_msix_entry), GFP_KERNEL);
7346 if (!dd->cspec->msix_entries) {
7347 qib_dev_err(dd, "No memory for MSIx table\n");
7348 tabsize = 0;
7349 }
7350 for (i = 0; i < tabsize; i++)
7351 dd->cspec->msix_entries[i].msix.entry = i;
7352
7353 if (qib_pcie_params(dd, 8, &tabsize, dd->cspec->msix_entries))
7354 qib_dev_err(dd,
7355 "Failed to setup PCIe or interrupts; continuing anyway\n");
7356
7357 dd->cspec->num_msix_entries = tabsize;
7358
7359
7360 qib_setup_7322_interrupt(dd, 1);
7361
7362
7363 qib_write_kreg(dd, kr_hwdiagctrl, 0);
7364#ifdef CONFIG_INFINIBAND_QIB_DCA
7365 if (!dca_add_requester(&pdev->dev)) {
7366 qib_devinfo(dd->pcidev, "DCA enabled\n");
7367 dd->flags |= QIB_DCA_ENABLED;
7368 qib_setup_dca(dd);
7369 }
7370#endif
7371 goto bail;
7372
7373bail_cleanup:
7374 qib_pcie_ddcleanup(dd);
7375bail_free:
7376 qib_free_devdata(dd);
7377 dd = ERR_PTR(ret);
7378bail:
7379 return dd;
7380}
7381
7382
7383
7384
7385
7386
7387
7388
7389#define DDS_ENT_AMP_LSB 14
7390#define DDS_ENT_MAIN_LSB 9
7391#define DDS_ENT_POST_LSB 5
7392#define DDS_ENT_PRE_XTRA_LSB 3
7393#define DDS_ENT_PRE_LSB 0
7394
7395
7396
7397
7398
7399
7400static void set_txdds(struct qib_pportdata *ppd, int ridx,
7401 const struct txdds_ent *tp)
7402{
7403 struct qib_devdata *dd = ppd->dd;
7404 u32 pack_ent;
7405 int regidx;
7406
7407
7408 regidx = KREG_IBPORT_IDX(IBSD_DDS_MAP_TABLE) + ridx;
7409
7410
7411
7412
7413
7414 if (ppd->hw_pidx)
7415 regidx += (dd->palign / sizeof(u64));
7416
7417 pack_ent = tp->amp << DDS_ENT_AMP_LSB;
7418 pack_ent |= tp->main << DDS_ENT_MAIN_LSB;
7419 pack_ent |= tp->pre << DDS_ENT_PRE_LSB;
7420 pack_ent |= tp->post << DDS_ENT_POST_LSB;
7421 qib_write_kreg(dd, regidx, pack_ent);
7422
7423 qib_write_kreg(ppd->dd, kr_scratch, 0);
7424}
7425
7426static const struct vendor_txdds_ent vendor_txdds[] = {
7427 {
7428 { 0x41, 0x50, 0x48 }, "584470002 ",
7429 { 10, 0, 0, 5 }, { 10, 0, 0, 9 }, { 7, 1, 0, 13 },
7430 },
7431 {
7432 { 0x41, 0x50, 0x48 }, "584470004 ",
7433 { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 7, 15 },
7434 },
7435 {
7436 { 0x00, 0x90, 0x65 }, "FCBG410QB1C03-QL",
7437 { 0, 0, 0, 3 }, { 0, 0, 0, 4 }, { 0, 0, 0, 13 },
7438 },
7439 {
7440 { 0x00, 0x90, 0x65 }, "FCBG410QB1C30-QL",
7441 { 0, 0, 0, 1 }, { 0, 0, 0, 5 }, { 0, 0, 0, 11 },
7442 },
7443 {
7444 { 0x00, 0x90, 0x65 }, NULL,
7445 { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 0, 0, 12 },
7446 },
7447 {
7448 { 0x00, 0x21, 0x77 }, "QSN3300-1 ",
7449 { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 0, 15 },
7450 },
7451 {
7452 { 0x00, 0x21, 0x77 }, "QSN3300-2 ",
7453 { 0, 0, 0, 8 }, { 0, 0, 0, 10 }, { 0, 1, 7, 15 },
7454 },
7455 {
7456 { 0x00, 0x21, 0x77 }, "QSN3800-1 ",
7457 { 0, 0, 0, 6 }, { 0, 0, 0, 8 }, { 0, 1, 0, 15 },
7458 },
7459 {
7460 { 0x00, 0x21, 0x77 }, "QSN3800-3 ",
7461 { 0, 0, 0, 9 }, { 0, 0, 0, 13 }, { 0, 1, 7, 15 },
7462 },
7463 {
7464 { 0x00, 0x21, 0x77 }, "QSN7000-5 ",
7465 { 0, 0, 0, 7 }, { 0, 0, 0, 9 }, { 0, 1, 3, 15 },
7466 },
7467 {
7468 { 0x00, 0x21, 0x77 }, "QSN7000-7 ",
7469 { 0, 0, 0, 9 }, { 0, 0, 0, 11 }, { 0, 2, 6, 15 },
7470 },
7471 {
7472 { 0x00, 0x21, 0x77 }, "QSN7600-5 ",
7473 { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 9, 13 },
7474 },
7475 {
7476 { 0x00, 0x21, 0x77 }, "QSN7600-7 ",
7477 { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 10, 1, 8, 15 },
7478 },
7479 {
7480 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1224",
7481 { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 3, 0, 9 },
7482 },
7483 {
7484 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1028",
7485 { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 2, 0, 2 },
7486 },
7487 {
7488 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0730",
7489 { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 1, 0, 3 },
7490 },
7491 {
7492 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0532",
7493 { 0, 0, 0, 6 }, { 0, 0, 0, 6 }, { 0, 2, 0, 8 },
7494 },
7495 {
7496 { 0x00, 0x30, 0xB4 }, NULL,
7497 { 0, 0, 0, 6 }, { 0, 0, 0, 5 }, { 0, 2, 0, 5 },
7498 },
7499 {
7500 { 0x00, 0x25, 0x63 }, NULL,
7501 { 0, 0, 0, 5 }, { 0, 0, 0, 8 }, { 0, 2, 0, 12 },
7502 },
7503 {
7504 { 0x00, 0x09, 0x3A }, "74763-0025 ",
7505 { 2, 2, 6, 15 }, { 2, 2, 6, 15 }, { 2, 2, 6, 15 },
7506 },
7507 {
7508 { 0x00, 0x09, 0x3A }, "74757-2201 ",
7509 { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 1, 15 },
7510 },
7511};
7512
7513static const struct txdds_ent txdds_sdr[TXDDS_TABLE_SZ] = {
7514
7515 { 2, 2, 15, 6 },
7516 { 0, 0, 0, 1 },
7517 { 0, 0, 0, 2 },
7518 { 0, 0, 0, 3 },
7519 { 0, 0, 0, 4 },
7520 { 0, 0, 0, 5 },
7521 { 0, 0, 0, 6 },
7522 { 0, 0, 0, 7 },
7523 { 0, 0, 0, 8 },
7524 { 0, 0, 0, 9 },
7525 { 0, 0, 0, 10 },
7526 { 0, 0, 0, 11 },
7527 { 0, 0, 0, 12 },
7528 { 0, 0, 0, 13 },
7529 { 0, 0, 0, 14 },
7530 { 0, 0, 0, 15 },
7531};
7532
7533static const struct txdds_ent txdds_ddr[TXDDS_TABLE_SZ] = {
7534
7535 { 2, 2, 15, 6 },
7536 { 0, 0, 0, 8 },
7537 { 0, 0, 0, 8 },
7538 { 0, 0, 0, 9 },
7539 { 0, 0, 0, 9 },
7540 { 0, 0, 0, 10 },
7541 { 0, 0, 0, 10 },
7542 { 0, 0, 0, 11 },
7543 { 0, 0, 0, 11 },
7544 { 0, 0, 0, 12 },
7545 { 0, 0, 0, 12 },
7546 { 0, 0, 0, 13 },
7547 { 0, 0, 0, 13 },
7548 { 0, 0, 0, 14 },
7549 { 0, 0, 0, 14 },
7550 { 0, 0, 0, 15 },
7551};
7552
7553static const struct txdds_ent txdds_qdr[TXDDS_TABLE_SZ] = {
7554
7555 { 2, 2, 15, 6 },
7556 { 0, 1, 0, 7 },
7557 { 0, 1, 0, 9 },
7558 { 0, 1, 0, 11 },
7559 { 0, 1, 0, 13 },
7560 { 0, 1, 0, 15 },
7561 { 0, 1, 3, 15 },
7562 { 0, 1, 7, 15 },
7563 { 0, 1, 7, 15 },
7564 { 0, 1, 8, 15 },
7565 { 0, 1, 9, 15 },
7566 { 0, 1, 10, 15 },
7567 { 0, 2, 6, 15 },
7568 { 0, 2, 7, 15 },
7569 { 0, 2, 8, 15 },
7570 { 0, 2, 9, 15 },
7571};
7572
7573
7574
7575
7576
7577
7578
7579static const struct txdds_ent txdds_extra_sdr[TXDDS_EXTRA_SZ] = {
7580
7581 { 0, 0, 0, 1 },
7582 { 0, 0, 0, 1 },
7583 { 0, 0, 0, 2 },
7584 { 0, 0, 0, 2 },
7585 { 0, 0, 0, 3 },
7586 { 0, 0, 0, 4 },
7587 { 0, 1, 4, 15 },
7588 { 0, 1, 3, 15 },
7589 { 0, 1, 0, 12 },
7590 { 0, 1, 0, 11 },
7591 { 0, 1, 0, 9 },
7592 { 0, 1, 0, 14 },
7593 { 0, 1, 2, 15 },
7594 { 0, 1, 0, 11 },
7595 { 0, 1, 0, 7 },
7596 { 0, 1, 0, 9 },
7597 { 0, 1, 0, 6 },
7598 { 0, 1, 0, 8 },
7599};
7600
7601static const struct txdds_ent txdds_extra_ddr[TXDDS_EXTRA_SZ] = {
7602
7603 { 0, 0, 0, 7 },
7604 { 0, 0, 0, 7 },
7605 { 0, 0, 0, 8 },
7606 { 0, 0, 0, 8 },
7607 { 0, 0, 0, 9 },
7608 { 0, 0, 0, 10 },
7609 { 0, 1, 4, 15 },
7610 { 0, 1, 3, 15 },
7611 { 0, 1, 0, 12 },
7612 { 0, 1, 0, 11 },
7613 { 0, 1, 0, 9 },
7614 { 0, 1, 0, 14 },
7615 { 0, 1, 2, 15 },
7616 { 0, 1, 0, 11 },
7617 { 0, 1, 0, 7 },
7618 { 0, 1, 0, 9 },
7619 { 0, 1, 0, 6 },
7620 { 0, 1, 0, 8 },
7621};
7622
7623static const struct txdds_ent txdds_extra_qdr[TXDDS_EXTRA_SZ] = {
7624
7625 { 0, 1, 0, 4 },
7626 { 0, 1, 0, 5 },
7627 { 0, 1, 0, 6 },
7628 { 0, 1, 0, 8 },
7629 { 0, 1, 0, 10 },
7630 { 0, 1, 0, 12 },
7631 { 0, 1, 4, 15 },
7632 { 0, 1, 3, 15 },
7633 { 0, 1, 0, 12 },
7634 { 0, 1, 0, 11 },
7635 { 0, 1, 0, 9 },
7636 { 0, 1, 0, 14 },
7637 { 0, 1, 2, 15 },
7638 { 0, 1, 0, 11 },
7639 { 0, 1, 0, 7 },
7640 { 0, 1, 0, 9 },
7641 { 0, 1, 0, 6 },
7642 { 0, 1, 0, 8 },
7643};
7644
7645static const struct txdds_ent txdds_extra_mfg[TXDDS_MFG_SZ] = {
7646
7647 { 0, 0, 0, 0 },
7648 { 0, 0, 0, 6 },
7649};
7650
7651static const struct txdds_ent *get_atten_table(const struct txdds_ent *txdds,
7652 unsigned atten)
7653{
7654
7655
7656
7657
7658 if (atten <= 2)
7659 atten = 1;
7660 else if (atten > TXDDS_TABLE_SZ)
7661 atten = TXDDS_TABLE_SZ - 1;
7662 else
7663 atten--;
7664 return txdds + atten;
7665}
7666
7667
7668
7669
7670
7671static void find_best_ent(struct qib_pportdata *ppd,
7672 const struct txdds_ent **sdr_dds,
7673 const struct txdds_ent **ddr_dds,
7674 const struct txdds_ent **qdr_dds, int override)
7675{
7676 struct qib_qsfp_cache *qd = &ppd->cpspec->qsfp_data.cache;
7677 int idx;
7678
7679
7680 for (idx = 0; !override && idx < ARRAY_SIZE(vendor_txdds); ++idx) {
7681 const struct vendor_txdds_ent *v = vendor_txdds + idx;
7682
7683 if (!memcmp(v->oui, qd->oui, QSFP_VOUI_LEN) &&
7684 (!v->partnum ||
7685 !memcmp(v->partnum, qd->partnum, QSFP_PN_LEN))) {
7686 *sdr_dds = &v->sdr;
7687 *ddr_dds = &v->ddr;
7688 *qdr_dds = &v->qdr;
7689 return;
7690 }
7691 }
7692
7693
7694
7695 if (!override && QSFP_IS_ACTIVE(qd->tech)) {
7696 *sdr_dds = txdds_sdr + ppd->dd->board_atten;
7697 *ddr_dds = txdds_ddr + ppd->dd->board_atten;
7698 *qdr_dds = txdds_qdr + ppd->dd->board_atten;
7699 return;
7700 }
7701
7702 if (!override && QSFP_HAS_ATTEN(qd->tech) && (qd->atten[0] ||
7703 qd->atten[1])) {
7704 *sdr_dds = get_atten_table(txdds_sdr, qd->atten[0]);
7705 *ddr_dds = get_atten_table(txdds_ddr, qd->atten[0]);
7706 *qdr_dds = get_atten_table(txdds_qdr, qd->atten[1]);
7707 return;
7708 } else if (ppd->cpspec->no_eep < TXDDS_TABLE_SZ) {
7709
7710
7711
7712
7713
7714
7715 idx = ppd->cpspec->no_eep;
7716 *sdr_dds = &txdds_sdr[idx];
7717 *ddr_dds = &txdds_ddr[idx];
7718 *qdr_dds = &txdds_qdr[idx];
7719 } else if (ppd->cpspec->no_eep < (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ)) {
7720
7721 idx = ppd->cpspec->no_eep - TXDDS_TABLE_SZ;
7722 *sdr_dds = &txdds_extra_sdr[idx];
7723 *ddr_dds = &txdds_extra_ddr[idx];
7724 *qdr_dds = &txdds_extra_qdr[idx];
7725 } else if ((IS_QME(ppd->dd) || IS_QMH(ppd->dd)) &&
7726 ppd->cpspec->no_eep < (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
7727 TXDDS_MFG_SZ)) {
7728 idx = ppd->cpspec->no_eep - (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ);
7729 pr_info("IB%u:%u use idx %u into txdds_mfg\n",
7730 ppd->dd->unit, ppd->port, idx);
7731 *sdr_dds = &txdds_extra_mfg[idx];
7732 *ddr_dds = &txdds_extra_mfg[idx];
7733 *qdr_dds = &txdds_extra_mfg[idx];
7734 } else {
7735
7736 *sdr_dds = txdds_sdr + qib_long_atten;
7737 *ddr_dds = txdds_ddr + qib_long_atten;
7738 *qdr_dds = txdds_qdr + qib_long_atten;
7739 }
7740}
7741
7742static void init_txdds_table(struct qib_pportdata *ppd, int override)
7743{
7744 const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
7745 struct txdds_ent *dds;
7746 int idx;
7747 int single_ent = 0;
7748
7749 find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, override);
7750
7751
7752 if (!(ppd->dd->flags & QIB_HAS_QSFP) || override)
7753 single_ent = 1;
7754
7755
7756 set_txdds(ppd, 0, sdr_dds);
7757 set_txdds(ppd, TXDDS_TABLE_SZ, ddr_dds);
7758 set_txdds(ppd, 2 * TXDDS_TABLE_SZ, qdr_dds);
7759 if (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
7760 QIBL_LINKACTIVE)) {
7761 dds = (struct txdds_ent *)(ppd->link_speed_active ==
7762 QIB_IB_QDR ? qdr_dds :
7763 (ppd->link_speed_active ==
7764 QIB_IB_DDR ? ddr_dds : sdr_dds));
7765 write_tx_serdes_param(ppd, dds);
7766 }
7767
7768
7769 for (idx = 1; idx < ARRAY_SIZE(txdds_sdr); ++idx) {
7770 set_txdds(ppd, idx, single_ent ? sdr_dds : txdds_sdr + idx);
7771 set_txdds(ppd, idx + TXDDS_TABLE_SZ,
7772 single_ent ? ddr_dds : txdds_ddr + idx);
7773 set_txdds(ppd, idx + 2 * TXDDS_TABLE_SZ,
7774 single_ent ? qdr_dds : txdds_qdr + idx);
7775 }
7776}
7777
7778#define KR_AHB_ACC KREG_IDX(ahb_access_ctrl)
7779#define KR_AHB_TRANS KREG_IDX(ahb_transaction_reg)
7780#define AHB_TRANS_RDY SYM_MASK(ahb_transaction_reg, ahb_rdy)
7781#define AHB_ADDR_LSB SYM_LSB(ahb_transaction_reg, ahb_address)
7782#define AHB_DATA_LSB SYM_LSB(ahb_transaction_reg, ahb_data)
7783#define AHB_WR SYM_MASK(ahb_transaction_reg, write_not_read)
7784#define AHB_TRANS_TRIES 10
7785
7786
7787
7788
7789
7790
7791static u32 ahb_mod(struct qib_devdata *dd, int quad, int chan, int addr,
7792 u32 data, u32 mask)
7793{
7794 u32 rd_data, wr_data, sz_mask;
7795 u64 trans, acc, prev_acc;
7796 u32 ret = 0xBAD0BAD;
7797 int tries;
7798
7799 prev_acc = qib_read_kreg64(dd, KR_AHB_ACC);
7800
7801 acc = (quad << 1) | 1;
7802 qib_write_kreg(dd, KR_AHB_ACC, acc);
7803
7804 for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
7805 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7806 if (trans & AHB_TRANS_RDY)
7807 break;
7808 }
7809 if (tries >= AHB_TRANS_TRIES) {
7810 qib_dev_err(dd, "No ahb_rdy in %d tries\n", AHB_TRANS_TRIES);
7811 goto bail;
7812 }
7813
7814
7815
7816
7817 sz_mask = (1UL << ((quad == 1) ? 32 : 16)) - 1;
7818 wr_data = data & mask & sz_mask;
7819 if ((~mask & sz_mask) != 0) {
7820 trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
7821 qib_write_kreg(dd, KR_AHB_TRANS, trans);
7822
7823 for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
7824 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7825 if (trans & AHB_TRANS_RDY)
7826 break;
7827 }
7828 if (tries >= AHB_TRANS_TRIES) {
7829 qib_dev_err(dd, "No Rd ahb_rdy in %d tries\n",
7830 AHB_TRANS_TRIES);
7831 goto bail;
7832 }
7833
7834 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7835 rd_data = (uint32_t)(trans >> AHB_DATA_LSB);
7836 wr_data |= (rd_data & ~mask & sz_mask);
7837 }
7838
7839
7840 if (mask & sz_mask) {
7841 trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
7842 trans |= ((uint64_t)wr_data << AHB_DATA_LSB);
7843 trans |= AHB_WR;
7844 qib_write_kreg(dd, KR_AHB_TRANS, trans);
7845
7846 for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
7847 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7848 if (trans & AHB_TRANS_RDY)
7849 break;
7850 }
7851 if (tries >= AHB_TRANS_TRIES) {
7852 qib_dev_err(dd, "No Wr ahb_rdy in %d tries\n",
7853 AHB_TRANS_TRIES);
7854 goto bail;
7855 }
7856 }
7857 ret = wr_data;
7858bail:
7859 qib_write_kreg(dd, KR_AHB_ACC, prev_acc);
7860 return ret;
7861}
7862
7863static void ibsd_wr_allchans(struct qib_pportdata *ppd, int addr, unsigned data,
7864 unsigned mask)
7865{
7866 struct qib_devdata *dd = ppd->dd;
7867 int chan;
7868 u32 rbc;
7869
7870 for (chan = 0; chan < SERDES_CHANS; ++chan) {
7871 ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)), addr,
7872 data, mask);
7873 rbc = ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7874 addr, 0, 0);
7875 }
7876}
7877
7878static void serdes_7322_los_enable(struct qib_pportdata *ppd, int enable)
7879{
7880 u64 data = qib_read_kreg_port(ppd, krp_serdesctrl);
7881 u8 state = SYM_FIELD(data, IBSerdesCtrl_0, RXLOSEN);
7882
7883 if (enable && !state) {
7884 pr_info("IB%u:%u Turning LOS on\n",
7885 ppd->dd->unit, ppd->port);
7886 data |= SYM_MASK(IBSerdesCtrl_0, RXLOSEN);
7887 } else if (!enable && state) {
7888 pr_info("IB%u:%u Turning LOS off\n",
7889 ppd->dd->unit, ppd->port);
7890 data &= ~SYM_MASK(IBSerdesCtrl_0, RXLOSEN);
7891 }
7892 qib_write_kreg_port(ppd, krp_serdesctrl, data);
7893}
7894
7895static int serdes_7322_init(struct qib_pportdata *ppd)
7896{
7897 int ret = 0;
7898 if (ppd->dd->cspec->r1)
7899 ret = serdes_7322_init_old(ppd);
7900 else
7901 ret = serdes_7322_init_new(ppd);
7902 return ret;
7903}
7904
7905static int serdes_7322_init_old(struct qib_pportdata *ppd)
7906{
7907 u32 le_val;
7908
7909
7910
7911
7912
7913 init_txdds_table(ppd, 0);
7914
7915
7916 qib_write_kreg_port(ppd, krp_tx_deemph_override,
7917 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7918 reset_tx_deemphasis_override));
7919
7920
7921
7922 ibsd_wr_allchans(ppd, 2, 0, BMASK(11, 9));
7923
7924
7925 ibsd_wr_allchans(ppd, 11, (1 << 11), BMASK(12, 11));
7926
7927 ibsd_wr_allchans(ppd, 13, (1 << 6), (1 << 6));
7928
7929
7930 le_val = IS_QME(ppd->dd) ? LE2_QME : LE2_DEFAULT;
7931 ibsd_wr_allchans(ppd, 13, (le_val << 7), BMASK(9, 7));
7932
7933
7934 le_val = IS_QME(ppd->dd) ? 0 : 1;
7935 ibsd_wr_allchans(ppd, 13, (le_val << 5), (1 << 5));
7936
7937
7938 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
7939
7940
7941 ibsd_wr_allchans(ppd, 5, (0 << 8), BMASK(9, 8));
7942
7943
7944
7945 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 5, 8 << 11, BMASK(14, 11));
7946 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 8 << 4, BMASK(7, 4));
7947 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 8, 8 << 11, BMASK(14, 11));
7948 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 8 << 4, BMASK(7, 4));
7949
7950
7951 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 6, 4 << 0, BMASK(3, 0));
7952 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 4 << 8, BMASK(11, 8));
7953 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 4 << 0, BMASK(3, 0));
7954 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 4 << 8, BMASK(11, 8));
7955
7956
7957 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 1 << 15, 1 << 15);
7958
7959
7960 ibsd_wr_allchans(ppd, 14, (1 << 3), BMASK(5, 3));
7961 ibsd_wr_allchans(ppd, 20, (2 << 10), BMASK(12, 10));
7962 ibsd_wr_allchans(ppd, 20, (4 << 13), BMASK(15, 13));
7963
7964 serdes_7322_los_enable(ppd, 1);
7965
7966
7967 ibsd_wr_allchans(ppd, 9, 0 << 15, 1 << 15);
7968
7969
7970 ibsd_wr_allchans(ppd, 16, 0 << 0, BMASK(1, 0));
7971
7972
7973 le_val = (ppd->dd->cspec->r1 || IS_QME(ppd->dd)) ? 0xb6c0 : 0x6bac;
7974 ibsd_wr_allchans(ppd, 21, le_val, 0xfffe);
7975
7976
7977
7978
7979
7980 qib_write_kreg_port(ppd, krp_static_adapt_dis(0), 0ULL);
7981 qib_write_kreg_port(ppd, krp_static_adapt_dis(1), 0ULL);
7982 qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
7983 ppd->dd->cspec->r1 ?
7984 QDR_STATIC_ADAPT_DOWN_R1 : QDR_STATIC_ADAPT_DOWN);
7985 ppd->cpspec->qdr_dfe_on = 1;
7986
7987
7988 ibsd_wr_allchans(ppd, 38, 0 << 10, 1 << 10);
7989
7990
7991 ibsd_wr_allchans(ppd, 12, 1 << 4, 1 << 4);
7992
7993 if (!ppd->dd->cspec->r1) {
7994 ibsd_wr_allchans(ppd, 12, 1 << 12, 1 << 12);
7995 ibsd_wr_allchans(ppd, 12, 2 << 8, 0x0f << 8);
7996 }
7997
7998
7999 ibsd_wr_allchans(ppd, 2, 15 << 5, BMASK(8, 5));
8000
8001 return 0;
8002}
8003
8004static int serdes_7322_init_new(struct qib_pportdata *ppd)
8005{
8006 unsigned long tend;
8007 u32 le_val, rxcaldone;
8008 int chan, chan_done = (1 << SERDES_CHANS) - 1;
8009
8010
8011 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
8012
8013
8014 qib_write_kreg_port(ppd, krp_tx_deemph_override,
8015 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8016 reset_tx_deemphasis_override));
8017
8018
8019
8020
8021 ibsd_wr_allchans(ppd, 1, 0, BMASK(9, 1));
8022
8023 ibsd_wr_allchans(ppd, 13, 0, BMASK(5, 5));
8024
8025 ibsd_wr_allchans(ppd, 1, 0, BMASK(15, 15));
8026
8027 ibsd_wr_allchans(ppd, 13, 0, BMASK(6, 6));
8028
8029 ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0));
8030
8031 ibsd_wr_allchans(ppd, 12, 0, BMASK(12, 12));
8032
8033 ibsd_wr_allchans(ppd, 2, 0, BMASK(3, 3));
8034
8035 ibsd_wr_allchans(ppd, 2, 0, BMASK(4, 4));
8036
8037 ibsd_wr_allchans(ppd, 13, 0, BMASK(13, 13));
8038
8039 ibsd_wr_allchans(ppd, 4, 0, BMASK(10, 10));
8040
8041 ibsd_wr_allchans(ppd, 12, 0, BMASK(4, 4));
8042
8043 ibsd_wr_allchans(ppd, 2, (1 << 15), BMASK(15, 15));
8044
8045 ibsd_wr_allchans(ppd, 5, 0, BMASK(9, 8));
8046
8047 ibsd_wr_allchans(ppd, 12, (1 << 5), BMASK(5, 5));
8048
8049 ibsd_wr_allchans(ppd, 2, (4 << 12), BMASK(14, 12));
8050
8051 ibsd_wr_allchans(ppd, 16, 0, BMASK(1, 0));
8052
8053 if (!ppd->dd->cspec->r1) {
8054 ibsd_wr_allchans(ppd, 12, 1 << 12, BMASK(12, 12));
8055 ibsd_wr_allchans(ppd, 12, 2 << 8, BMASK(11, 8));
8056 } else {
8057 ibsd_wr_allchans(ppd, 19, (3 << 11), BMASK(13, 11));
8058 }
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068 ibsd_wr_allchans(ppd, 0, 0, BMASK(15, 13));
8069 msleep(20);
8070
8071 ibsd_wr_allchans(ppd, 0, (1 << 14), BMASK(14, 14));
8072 msleep(20);
8073
8074 ibsd_wr_allchans(ppd, 0, (1 << 13), BMASK(13, 13));
8075 msleep(20);
8076
8077
8078
8079 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 5, 8 << 11, BMASK(14, 11));
8080 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 8 << 4, BMASK(7, 4));
8081 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 8, 8 << 11, BMASK(14, 11));
8082 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 8 << 4, BMASK(7, 4));
8083
8084
8085 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 6, 4 << 0, BMASK(3, 0));
8086 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 4 << 8, BMASK(11, 8));
8087 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 4 << 0, BMASK(3, 0));
8088 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 4 << 8, BMASK(11, 8));
8089
8090
8091 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 1 << 15, 1 << 15);
8092
8093
8094 ibsd_wr_allchans(ppd, 14, (1 << 3), BMASK(5, 3));
8095 ibsd_wr_allchans(ppd, 20, (2 << 10), BMASK(12, 10));
8096 ibsd_wr_allchans(ppd, 20, (4 << 13), BMASK(15, 13));
8097
8098
8099 serdes_7322_los_enable(ppd, 1);
8100
8101 ibsd_wr_allchans(ppd, 38, 0 << 10, 1 << 10);
8102
8103
8104
8105 ibsd_wr_allchans(ppd, 15, 1, BMASK(0, 0));
8106
8107 ibsd_wr_allchans(ppd, 12, (1 << 4), BMASK(4, 4));
8108 msleep(20);
8109
8110 ibsd_wr_allchans(ppd, 4, (1 << 10), BMASK(10, 10));
8111 tend = jiffies + msecs_to_jiffies(500);
8112 while (chan_done && !time_is_before_jiffies(tend)) {
8113 msleep(20);
8114 for (chan = 0; chan < SERDES_CHANS; ++chan) {
8115 rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx),
8116 (chan + (chan >> 1)),
8117 25, 0, 0);
8118 if ((~rxcaldone & (u32)BMASK(9, 9)) == 0 &&
8119 (~chan_done & (1 << chan)) == 0)
8120 chan_done &= ~(1 << chan);
8121 }
8122 }
8123 if (chan_done) {
8124 pr_info("Serdes %d calibration not done after .5 sec: 0x%x\n",
8125 IBSD(ppd->hw_pidx), chan_done);
8126 } else {
8127 for (chan = 0; chan < SERDES_CHANS; ++chan) {
8128 rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx),
8129 (chan + (chan >> 1)),
8130 25, 0, 0);
8131 if ((~rxcaldone & (u32)BMASK(10, 10)) == 0)
8132 pr_info("Serdes %d chan %d calibration failed\n",
8133 IBSD(ppd->hw_pidx), chan);
8134 }
8135 }
8136
8137
8138 ibsd_wr_allchans(ppd, 4, 0, BMASK(10, 10));
8139 msleep(20);
8140
8141
8142
8143 le_val = IS_QME(ppd->dd) ? LE2_QME : LE2_DEFAULT;
8144 ibsd_wr_allchans(ppd, 13, (le_val << 7), BMASK(9, 7));
8145
8146 ibsd_wr_allchans(ppd, 3, (7 << 5), BMASK(7, 5));
8147
8148 ibsd_wr_allchans(ppd, 13, (1 << 6), BMASK(6, 6));
8149 msleep(20);
8150
8151 ibsd_wr_allchans(ppd, 1, 1, BMASK(9, 1));
8152
8153 le_val = (ppd->dd->cspec->r1 || IS_QME(ppd->dd)) ? 0xb6c0 : 0x6bac;
8154 ibsd_wr_allchans(ppd, 21, le_val, 0xfffe);
8155
8156 ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0));
8157 msleep(20);
8158
8159 ibsd_wr_allchans(ppd, 2, (15 << 5), BMASK(8, 5));
8160
8161 ibsd_wr_allchans(ppd, 2, (1 << 4), BMASK(4, 4));
8162
8163 ibsd_wr_allchans(ppd, 2, 0, BMASK(11, 9));
8164
8165 ibsd_wr_allchans(ppd, 2, (1 << 3), BMASK(3, 3));
8166 msleep(50);
8167
8168
8169
8170
8171 qib_write_kreg_port(ppd, krp_static_adapt_dis(0), 0ULL);
8172 qib_write_kreg_port(ppd, krp_static_adapt_dis(1), 0ULL);
8173 qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
8174 ppd->dd->cspec->r1 ?
8175 QDR_STATIC_ADAPT_DOWN_R1 : QDR_STATIC_ADAPT_DOWN);
8176 ppd->cpspec->qdr_dfe_on = 1;
8177
8178 ibsd_wr_allchans(ppd, 13, (0 << 5), (1 << 5));
8179
8180 ibsd_wr_allchans(ppd, 1, (0 << 15), BMASK(15, 15));
8181 msleep(20);
8182
8183 ibsd_wr_allchans(ppd, 12, (1 << 12), BMASK(12, 12));
8184
8185 ibsd_wr_allchans(ppd, 12, (1 << 13), BMASK(13, 13));
8186
8187 ibsd_wr_allchans(ppd, 11, (1 << 11), BMASK(12, 11));
8188
8189 ibsd_wr_allchans(ppd, 12, (3 << 2), BMASK(3, 2));
8190
8191
8192
8193
8194
8195 init_txdds_table(ppd, 0);
8196
8197 return 0;
8198}
8199
8200
8201
8202static void set_man_code(struct qib_pportdata *ppd, int chan, int code)
8203{
8204 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
8205 9, code << 9, 0x3f << 9);
8206}
8207
8208static void set_man_mode_h1(struct qib_pportdata *ppd, int chan,
8209 int enable, u32 tapenable)
8210{
8211 if (enable)
8212 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
8213 1, 3 << 10, 0x1f << 10);
8214 else
8215 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
8216 1, 0, 0x1f << 10);
8217}
8218
8219
8220static void clock_man(struct qib_pportdata *ppd, int chan)
8221{
8222 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
8223 4, 0x4000, 0x4000);
8224 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
8225 4, 0, 0x4000);
8226 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
8227 4, 0x4000, 0x4000);
8228 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
8229 4, 0, 0x4000);
8230}
8231
8232
8233
8234
8235
8236
8237static void write_tx_serdes_param(struct qib_pportdata *ppd,
8238 struct txdds_ent *txdds)
8239{
8240 u64 deemph;
8241
8242 deemph = qib_read_kreg_port(ppd, krp_tx_deemph_override);
8243
8244 deemph &= ~(SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txampcntl_d2a) |
8245 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txc0_ena) |
8246 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcp1_ena) |
8247 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcn1_ena));
8248
8249 deemph |= SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8250 tx_override_deemphasis_select);
8251 deemph |= (txdds->amp & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8252 txampcntl_d2a)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8253 txampcntl_d2a);
8254 deemph |= (txdds->main & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8255 txc0_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8256 txc0_ena);
8257 deemph |= (txdds->post & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8258 txcp1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8259 txcp1_ena);
8260 deemph |= (txdds->pre & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8261 txcn1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8262 txcn1_ena);
8263 qib_write_kreg_port(ppd, krp_tx_deemph_override, deemph);
8264}
8265
8266
8267
8268
8269
8270
8271static void adj_tx_serdes(struct qib_pportdata *ppd)
8272{
8273 const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
8274 struct txdds_ent *dds;
8275
8276 find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, 1);
8277 dds = (struct txdds_ent *)(ppd->link_speed_active == QIB_IB_QDR ?
8278 qdr_dds : (ppd->link_speed_active == QIB_IB_DDR ?
8279 ddr_dds : sdr_dds));
8280 write_tx_serdes_param(ppd, dds);
8281}
8282
8283
8284static void force_h1(struct qib_pportdata *ppd)
8285{
8286 int chan;
8287
8288 ppd->cpspec->qdr_reforce = 0;
8289 if (!ppd->dd->cspec->r1)
8290 return;
8291
8292 for (chan = 0; chan < SERDES_CHANS; chan++) {
8293 set_man_mode_h1(ppd, chan, 1, 0);
8294 set_man_code(ppd, chan, ppd->cpspec->h1_val);
8295 clock_man(ppd, chan);
8296 set_man_mode_h1(ppd, chan, 0, 0);
8297 }
8298}
8299
8300#define SJA_EN SYM_MASK(SPC_JTAG_ACCESS_REG, SPC_JTAG_ACCESS_EN)
8301#define BISTEN_LSB SYM_LSB(SPC_JTAG_ACCESS_REG, bist_en)
8302
8303#define R_OPCODE_LSB 3
8304#define R_OP_NOP 0
8305#define R_OP_SHIFT 2
8306#define R_OP_UPDATE 3
8307#define R_TDI_LSB 2
8308#define R_TDO_LSB 1
8309#define R_RDY 1
8310
8311static int qib_r_grab(struct qib_devdata *dd)
8312{
8313 u64 val;
8314 val = SJA_EN;
8315 qib_write_kreg(dd, kr_r_access, val);
8316 qib_read_kreg32(dd, kr_scratch);
8317 return 0;
8318}
8319
8320
8321
8322
8323static int qib_r_wait_for_rdy(struct qib_devdata *dd)
8324{
8325 u64 val;
8326 int timeout;
8327 for (timeout = 0; timeout < 100 ; ++timeout) {
8328 val = qib_read_kreg32(dd, kr_r_access);
8329 if (val & R_RDY)
8330 return (val >> R_TDO_LSB) & 1;
8331 }
8332 return -1;
8333}
8334
8335static int qib_r_shift(struct qib_devdata *dd, int bisten,
8336 int len, u8 *inp, u8 *outp)
8337{
8338 u64 valbase, val;
8339 int ret, pos;
8340
8341 valbase = SJA_EN | (bisten << BISTEN_LSB) |
8342 (R_OP_SHIFT << R_OPCODE_LSB);
8343 ret = qib_r_wait_for_rdy(dd);
8344 if (ret < 0)
8345 goto bail;
8346 for (pos = 0; pos < len; ++pos) {
8347 val = valbase;
8348 if (outp) {
8349 outp[pos >> 3] &= ~(1 << (pos & 7));
8350 outp[pos >> 3] |= (ret << (pos & 7));
8351 }
8352 if (inp) {
8353 int tdi = inp[pos >> 3] >> (pos & 7);
8354 val |= ((tdi & 1) << R_TDI_LSB);
8355 }
8356 qib_write_kreg(dd, kr_r_access, val);
8357 qib_read_kreg32(dd, kr_scratch);
8358 ret = qib_r_wait_for_rdy(dd);
8359 if (ret < 0)
8360 break;
8361 }
8362
8363 val = SJA_EN | (bisten << BISTEN_LSB);
8364 qib_write_kreg(dd, kr_r_access, val);
8365 qib_read_kreg32(dd, kr_scratch);
8366 ret = qib_r_wait_for_rdy(dd);
8367
8368 if (ret >= 0)
8369 ret = pos;
8370bail:
8371 return ret;
8372}
8373
8374static int qib_r_update(struct qib_devdata *dd, int bisten)
8375{
8376 u64 val;
8377 int ret;
8378
8379 val = SJA_EN | (bisten << BISTEN_LSB) | (R_OP_UPDATE << R_OPCODE_LSB);
8380 ret = qib_r_wait_for_rdy(dd);
8381 if (ret >= 0) {
8382 qib_write_kreg(dd, kr_r_access, val);
8383 qib_read_kreg32(dd, kr_scratch);
8384 }
8385 return ret;
8386}
8387
8388#define BISTEN_PORT_SEL 15
8389#define LEN_PORT_SEL 625
8390#define BISTEN_AT 17
8391#define LEN_AT 156
8392#define BISTEN_ETM 16
8393#define LEN_ETM 632
8394
8395#define BIT2BYTE(x) (((x) + BITS_PER_BYTE - 1) / BITS_PER_BYTE)
8396
8397
8398static u8 reset_at[BIT2BYTE(LEN_AT)] = {
8399 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8400 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
8401};
8402static u8 reset_atetm[BIT2BYTE(LEN_ETM)] = {
8403 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8404 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8405 0x00, 0x00, 0x00, 0x80, 0xe3, 0x81, 0x73, 0x3c, 0x70, 0x8e,
8406 0x07, 0xce, 0xf1, 0xc0, 0x39, 0x1e, 0x38, 0xc7, 0x03, 0xe7,
8407 0x78, 0xe0, 0x1c, 0x0f, 0x9c, 0x7f, 0x80, 0x73, 0x0f, 0x70,
8408 0xde, 0x01, 0xce, 0x39, 0xc0, 0xf9, 0x06, 0x38, 0xd7, 0x00,
8409 0xe7, 0x19, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8410 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
8411};
8412static u8 at[BIT2BYTE(LEN_AT)] = {
8413 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
8414 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
8415};
8416
8417
8418static u8 atetm_1port[BIT2BYTE(LEN_ETM)] = {
8419 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8420 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8421 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8422 0x00, 0x10, 0xf2, 0x80, 0x83, 0x1e, 0x38, 0x00, 0x00, 0x00,
8423 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8424 0x00, 0x00, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xc8, 0x03,
8425 0x07, 0x7b, 0xa0, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x18, 0x00,
8426 0x18, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00,
8427};
8428
8429
8430static u8 atetm_2port[BIT2BYTE(LEN_ETM)] = {
8431 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8432 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79,
8433 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8434 0x00, 0x00, 0xf8, 0x80, 0x83, 0x1e, 0x38, 0xe0, 0x03, 0x05,
8435 0x7b, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
8436 0xa2, 0x0f, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xd1, 0x07,
8437 0x02, 0x7c, 0x80, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x3e, 0x00,
8438 0x02, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00,
8439};
8440
8441
8442static u8 portsel_port1[BIT2BYTE(LEN_PORT_SEL)] = {
8443 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
8444 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
8445 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
8446 0x13, 0x78, 0x78, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
8447 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
8448 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
8449 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
8450 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
8451};
8452
8453
8454static u8 portsel_port2[BIT2BYTE(LEN_PORT_SEL)] = {
8455 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x39, 0x39,
8456 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x73, 0x32, 0x32, 0x32,
8457 0x32, 0x32, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
8458 0x39, 0x78, 0x78, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
8459 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x74, 0x32,
8460 0x32, 0x32, 0x32, 0x32, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
8461 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
8462 0x3a, 0x3a, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
8463};
8464
8465
8466static u8 portsel_2port[BIT2BYTE(LEN_PORT_SEL)] = {
8467 0x32, 0xba, 0x54, 0x76, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
8468 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
8469 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
8470 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
8471 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
8472 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x3a,
8473 0x3a, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
8474 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
8475};
8476
8477
8478
8479
8480
8481
8482
8483static void setup_7322_link_recovery(struct qib_pportdata *ppd, u32 both)
8484{
8485 u8 *portsel, *etm;
8486 struct qib_devdata *dd = ppd->dd;
8487
8488 if (!ppd->dd->cspec->r1)
8489 return;
8490 if (!both) {
8491 dd->cspec->recovery_ports_initted++;
8492 ppd->cpspec->recovery_init = 1;
8493 }
8494 if (!both && dd->cspec->recovery_ports_initted == 1) {
8495 portsel = ppd->port == 1 ? portsel_port1 : portsel_port2;
8496 etm = atetm_1port;
8497 } else {
8498 portsel = portsel_2port;
8499 etm = atetm_2port;
8500 }
8501
8502 if (qib_r_grab(dd) < 0 ||
8503 qib_r_shift(dd, BISTEN_ETM, LEN_ETM, reset_atetm, NULL) < 0 ||
8504 qib_r_update(dd, BISTEN_ETM) < 0 ||
8505 qib_r_shift(dd, BISTEN_AT, LEN_AT, reset_at, NULL) < 0 ||
8506 qib_r_update(dd, BISTEN_AT) < 0 ||
8507 qib_r_shift(dd, BISTEN_PORT_SEL, LEN_PORT_SEL,
8508 portsel, NULL) < 0 ||
8509 qib_r_update(dd, BISTEN_PORT_SEL) < 0 ||
8510 qib_r_shift(dd, BISTEN_AT, LEN_AT, at, NULL) < 0 ||
8511 qib_r_update(dd, BISTEN_AT) < 0 ||
8512 qib_r_shift(dd, BISTEN_ETM, LEN_ETM, etm, NULL) < 0 ||
8513 qib_r_update(dd, BISTEN_ETM) < 0)
8514 qib_dev_err(dd, "Failed IB link recovery setup\n");
8515}
8516
8517static void check_7322_rxe_status(struct qib_pportdata *ppd)
8518{
8519 struct qib_devdata *dd = ppd->dd;
8520 u64 fmask;
8521
8522 if (dd->cspec->recovery_ports_initted != 1)
8523 return;
8524 qib_write_kreg(dd, kr_control, dd->control |
8525 SYM_MASK(Control, FreezeMode));
8526 (void)qib_read_kreg64(dd, kr_scratch);
8527 udelay(3);
8528 fmask = qib_read_kreg64(dd, kr_act_fmask);
8529 if (!fmask) {
8530
8531
8532
8533
8534
8535 ppd->dd->cspec->stay_in_freeze = 1;
8536 qib_7322_set_intr_state(ppd->dd, 0);
8537 qib_write_kreg(dd, kr_fmask, 0ULL);
8538 qib_dev_err(dd, "HCA unusable until powercycled\n");
8539 return;
8540 }
8541
8542 qib_write_kreg(ppd->dd, kr_hwerrclear,
8543 SYM_MASK(HwErrClear, IBSerdesPClkNotDetectClear_1));
8544
8545
8546 qib_write_kreg(dd, kr_control, dd->control);
8547 qib_read_kreg32(dd, kr_scratch);
8548
8549 if (ppd->link_speed_supported) {
8550 ppd->cpspec->ibcctrl_a &=
8551 ~SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
8552 qib_write_kreg_port(ppd, krp_ibcctrl_a,
8553 ppd->cpspec->ibcctrl_a);
8554 qib_read_kreg32(dd, kr_scratch);
8555 if (ppd->lflags & QIBL_IB_LINK_DISABLED)
8556 qib_set_ib_7322_lstate(ppd, 0,
8557 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
8558 }
8559}
8560