2 * Copyright (c) 2008, 2009, 2010 QLogic Corporation. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 * This file contains all of the code that is specific to the
35 * InfiniPath 7322 chip
38 #include <linux/interrupt.h>
39 #include <linux/pci.h>
40 #include <linux/delay.h>
42 #include <linux/jiffies.h>
43 #include <rdma/ib_verbs.h>
44 #include <rdma/ib_smi.h>
47 #include "qib_7322_regs.h"
52 static void qib_setup_7322_setextled(struct qib_pportdata *, u32);
53 static void qib_7322_handle_hwerrors(struct qib_devdata *, char *, size_t);
54 static void sendctrl_7322_mod(struct qib_pportdata *ppd, u32 op);
55 static irqreturn_t qib_7322intr(int irq, void *data);
56 static irqreturn_t qib_7322bufavail(int irq, void *data);
57 static irqreturn_t sdma_intr(int irq, void *data);
58 static irqreturn_t sdma_idle_intr(int irq, void *data);
59 static irqreturn_t sdma_progress_intr(int irq, void *data);
60 static irqreturn_t sdma_cleanup_intr(int irq, void *data);
61 static void qib_7322_txchk_change(struct qib_devdata *, u32, u32, u32,
62 struct qib_ctxtdata *rcd);
63 static u8 qib_7322_phys_portstate(u64);
64 static u32 qib_7322_iblink_state(u64);
65 static void qib_set_ib_7322_lstate(struct qib_pportdata *ppd, u16 linkcmd,
67 static void force_h1(struct qib_pportdata *);
68 static void adj_tx_serdes(struct qib_pportdata *);
69 static u32 qib_7322_setpbc_control(struct qib_pportdata *, u32, u8, u8);
70 static void qib_7322_mini_pcs_reset(struct qib_pportdata *);
72 static u32 ahb_mod(struct qib_devdata *, int, int, int, u32, u32);
73 static void ibsd_wr_allchans(struct qib_pportdata *, int, unsigned, unsigned);
75 #define BMASK(msb, lsb) (((1 << ((msb) + 1 - (lsb))) - 1) << (lsb))
77 /* LE2 serdes values for different cases */
82 /* Below is special-purpose, so only really works for the IB SerDes blocks. */
83 #define IBSD(hw_pidx) (hw_pidx + 2)
85 /* these are variables for documentation and experimentation purposes */
86 static const unsigned rcv_int_timeout = 375;
87 static const unsigned rcv_int_count = 16;
88 static const unsigned sdma_idle_cnt = 64;
90 /* Time to stop altering Rx Equalization parameters, after link up. */
91 #define RXEQ_DISABLE_MSECS 2500
94 * Number of VLs we are configured to use (to allow for more
95 * credits per vl, etc.)
97 ushort qib_num_cfg_vls = 2;
98 module_param_named(num_vls, qib_num_cfg_vls, ushort, S_IRUGO);
99 MODULE_PARM_DESC(num_vls, "Set number of Virtual Lanes to use (1-8)");
101 static ushort qib_chase = 1;
102 module_param_named(chase, qib_chase, ushort, S_IRUGO);
103 MODULE_PARM_DESC(chase, "Enable state chase handling");
105 static ushort qib_long_atten = 10; /* 10 dB ~= 5m length */
106 module_param_named(long_attenuation, qib_long_atten, ushort, S_IRUGO);
107 MODULE_PARM_DESC(long_attenuation, \
108 "attenuation cutoff (dB) for long copper cable setup");
110 static ushort qib_singleport;
111 module_param_named(singleport, qib_singleport, ushort, S_IRUGO);
112 MODULE_PARM_DESC(singleport, "Use only IB port 1; more per-port buffer space");
114 #define MAX_ATTEN_LEN 64 /* plenty for any real system */
115 /* for read back, default index is ~5m copper cable */
116 static char txselect_list[MAX_ATTEN_LEN] = "10";
117 static struct kparam_string kp_txselect = {
118 .string = txselect_list,
119 .maxlen = MAX_ATTEN_LEN
121 static int setup_txselect(const char *, struct kernel_param *);
122 module_param_call(txselect, setup_txselect, param_get_string,
123 &kp_txselect, S_IWUSR | S_IRUGO);
124 MODULE_PARM_DESC(txselect, \
125 "Tx serdes indices (for no QSFP or invalid QSFP data)");
127 #define BOARD_QME7342 5
128 #define BOARD_QMH7342 6
129 #define IS_QMH(dd) (SYM_FIELD((dd)->revision, Revision, BoardID) == \
131 #define IS_QME(dd) (SYM_FIELD((dd)->revision, Revision, BoardID) == \
134 #define KREG_IDX(regname) (QIB_7322_##regname##_OFFS / sizeof(u64))
136 #define KREG_IBPORT_IDX(regname) ((QIB_7322_##regname##_0_OFFS / sizeof(u64)))
138 #define MASK_ACROSS(lsb, msb) \
139 (((1ULL << ((msb) + 1 - (lsb))) - 1) << (lsb))
141 #define SYM_RMASK(regname, fldname) ((u64) \
142 QIB_7322_##regname##_##fldname##_RMASK)
144 #define SYM_MASK(regname, fldname) ((u64) \
145 QIB_7322_##regname##_##fldname##_RMASK << \
146 QIB_7322_##regname##_##fldname##_LSB)
148 #define SYM_FIELD(value, regname, fldname) ((u64) \
149 (((value) >> SYM_LSB(regname, fldname)) & \
150 SYM_RMASK(regname, fldname)))
152 /* useful for things like LaFifoEmpty_0...7, TxCreditOK_0...7, etc. */
153 #define SYM_FIELD_ACROSS(value, regname, fldname, nbits) \
154 (((value) >> SYM_LSB(regname, fldname)) & MASK_ACROSS(0, nbits))
156 #define HWE_MASK(fldname) SYM_MASK(HwErrMask, fldname##Mask)
157 #define ERR_MASK(fldname) SYM_MASK(ErrMask, fldname##Mask)
158 #define ERR_MASK_N(fldname) SYM_MASK(ErrMask_0, fldname##Mask)
159 #define INT_MASK(fldname) SYM_MASK(IntMask, fldname##IntMask)
160 #define INT_MASK_P(fldname, port) SYM_MASK(IntMask, fldname##IntMask##_##port)
161 /* Below because most, but not all, fields of IntMask have that full suffix */
162 #define INT_MASK_PM(fldname, port) SYM_MASK(IntMask, fldname##Mask##_##port)
165 #define SYM_LSB(regname, fldname) (QIB_7322_##regname##_##fldname##_LSB)
168 * the size bits give us 2^N, in KB units. 0 marks as invalid,
169 * and 7 is reserved. We currently use only 2KB and 4KB
171 #define IBA7322_TID_SZ_SHIFT QIB_7322_RcvTIDArray0_RT_BufSize_LSB
172 #define IBA7322_TID_SZ_2K (1UL<<IBA7322_TID_SZ_SHIFT) /* 2KB */
173 #define IBA7322_TID_SZ_4K (2UL<<IBA7322_TID_SZ_SHIFT) /* 4KB */
174 #define IBA7322_TID_PA_SHIFT 11U /* TID addr in chip stored w/o low bits */
176 #define SendIBSLIDAssignMask \
177 QIB_7322_SendIBSLIDAssign_0_SendIBSLIDAssign_15_0_RMASK
178 #define SendIBSLMCMask \
179 QIB_7322_SendIBSLIDMask_0_SendIBSLIDMask_15_0_RMASK
181 #define ExtLED_IB1_YEL SYM_MASK(EXTCtrl, LEDPort0YellowOn)
182 #define ExtLED_IB1_GRN SYM_MASK(EXTCtrl, LEDPort0GreenOn)
183 #define ExtLED_IB2_YEL SYM_MASK(EXTCtrl, LEDPort1YellowOn)
184 #define ExtLED_IB2_GRN SYM_MASK(EXTCtrl, LEDPort1GreenOn)
185 #define ExtLED_IB1_MASK (ExtLED_IB1_YEL | ExtLED_IB1_GRN)
186 #define ExtLED_IB2_MASK (ExtLED_IB2_YEL | ExtLED_IB2_GRN)
188 #define _QIB_GPIO_SDA_NUM 1
189 #define _QIB_GPIO_SCL_NUM 0
190 #define QIB_EEPROM_WEN_NUM 14
191 #define QIB_TWSI_EEPROM_DEV 0xA2 /* All Production 7322 cards. */
193 /* HW counter clock is at 4nsec */
194 #define QIB_7322_PSXMITWAIT_CHECK_RATE 4000
196 /* full speed IB port 1 only */
197 #define PORT_SPD_CAP (QIB_IB_SDR | QIB_IB_DDR | QIB_IB_QDR)
198 #define PORT_SPD_CAP_SHIFT 3
200 /* full speed featuremask, both ports */
201 #define DUAL_PORT_CAP (PORT_SPD_CAP | (PORT_SPD_CAP << PORT_SPD_CAP_SHIFT))
204 * This file contains almost all the chip-specific register information and
205 * access functions for the FAKED QLogic InfiniPath 7322 PCI-Express chip.
208 /* Use defines to tie machine-generated names to lower-case names */
209 #define kr_contextcnt KREG_IDX(ContextCnt)
210 #define kr_control KREG_IDX(Control)
211 #define kr_counterregbase KREG_IDX(CntrRegBase)
212 #define kr_errclear KREG_IDX(ErrClear)
213 #define kr_errmask KREG_IDX(ErrMask)
214 #define kr_errstatus KREG_IDX(ErrStatus)
215 #define kr_extctrl KREG_IDX(EXTCtrl)
216 #define kr_extstatus KREG_IDX(EXTStatus)
217 #define kr_gpio_clear KREG_IDX(GPIOClear)
218 #define kr_gpio_mask KREG_IDX(GPIOMask)
219 #define kr_gpio_out KREG_IDX(GPIOOut)
220 #define kr_gpio_status KREG_IDX(GPIOStatus)
221 #define kr_hwdiagctrl KREG_IDX(HwDiagCtrl)
222 #define kr_debugportval KREG_IDX(DebugPortValueReg)
223 #define kr_fmask KREG_IDX(feature_mask)
224 #define kr_act_fmask KREG_IDX(active_feature_mask)
225 #define kr_hwerrclear KREG_IDX(HwErrClear)
226 #define kr_hwerrmask KREG_IDX(HwErrMask)
227 #define kr_hwerrstatus KREG_IDX(HwErrStatus)
228 #define kr_intclear KREG_IDX(IntClear)
229 #define kr_intmask KREG_IDX(IntMask)
230 #define kr_intredirect KREG_IDX(IntRedirect0)
231 #define kr_intstatus KREG_IDX(IntStatus)
232 #define kr_pagealign KREG_IDX(PageAlign)
233 #define kr_rcvavailtimeout KREG_IDX(RcvAvailTimeOut0)
234 #define kr_rcvctrl KREG_IDX(RcvCtrl) /* Common, but chip also has per-port */
235 #define kr_rcvegrbase KREG_IDX(RcvEgrBase)
236 #define kr_rcvegrcnt KREG_IDX(RcvEgrCnt)
237 #define kr_rcvhdrcnt KREG_IDX(RcvHdrCnt)
238 #define kr_rcvhdrentsize KREG_IDX(RcvHdrEntSize)
239 #define kr_rcvhdrsize KREG_IDX(RcvHdrSize)
240 #define kr_rcvtidbase KREG_IDX(RcvTIDBase)
241 #define kr_rcvtidcnt KREG_IDX(RcvTIDCnt)
242 #define kr_revision KREG_IDX(Revision)
243 #define kr_scratch KREG_IDX(Scratch)
244 #define kr_sendbuffererror KREG_IDX(SendBufErr0) /* and base for 1 and 2 */
245 #define kr_sendcheckmask KREG_IDX(SendCheckMask0) /* and 1, 2 */
246 #define kr_sendctrl KREG_IDX(SendCtrl)
247 #define kr_sendgrhcheckmask KREG_IDX(SendGRHCheckMask0) /* and 1, 2 */
248 #define kr_sendibpktmask KREG_IDX(SendIBPacketMask0) /* and 1, 2 */
249 #define kr_sendpioavailaddr KREG_IDX(SendBufAvailAddr)
250 #define kr_sendpiobufbase KREG_IDX(SendBufBase)
251 #define kr_sendpiobufcnt KREG_IDX(SendBufCnt)
252 #define kr_sendpiosize KREG_IDX(SendBufSize)
253 #define kr_sendregbase KREG_IDX(SendRegBase)
254 #define kr_sendbufavail0 KREG_IDX(SendBufAvail0)
255 #define kr_userregbase KREG_IDX(UserRegBase)
256 #define kr_intgranted KREG_IDX(Int_Granted)
257 #define kr_vecclr_wo_int KREG_IDX(vec_clr_without_int)
258 #define kr_intblocked KREG_IDX(IntBlocked)
259 #define kr_r_access KREG_IDX(SPC_JTAG_ACCESS_REG)
262 * per-port kernel registers. Access only with qib_read_kreg_port()
263 * or qib_write_kreg_port()
265 #define krp_errclear KREG_IBPORT_IDX(ErrClear)
266 #define krp_errmask KREG_IBPORT_IDX(ErrMask)
267 #define krp_errstatus KREG_IBPORT_IDX(ErrStatus)
268 #define krp_highprio_0 KREG_IBPORT_IDX(HighPriority0)
269 #define krp_highprio_limit KREG_IBPORT_IDX(HighPriorityLimit)
270 #define krp_hrtbt_guid KREG_IBPORT_IDX(HRTBT_GUID)
271 #define krp_ib_pcsconfig KREG_IBPORT_IDX(IBPCSConfig)
272 #define krp_ibcctrl_a KREG_IBPORT_IDX(IBCCtrlA)
273 #define krp_ibcctrl_b KREG_IBPORT_IDX(IBCCtrlB)
274 #define krp_ibcctrl_c KREG_IBPORT_IDX(IBCCtrlC)
275 #define krp_ibcstatus_a KREG_IBPORT_IDX(IBCStatusA)
276 #define krp_ibcstatus_b KREG_IBPORT_IDX(IBCStatusB)
277 #define krp_txestatus KREG_IBPORT_IDX(TXEStatus)
278 #define krp_lowprio_0 KREG_IBPORT_IDX(LowPriority0)
279 #define krp_ncmodectrl KREG_IBPORT_IDX(IBNCModeCtrl)
280 #define krp_partitionkey KREG_IBPORT_IDX(RcvPartitionKey)
281 #define krp_psinterval KREG_IBPORT_IDX(PSInterval)
282 #define krp_psstart KREG_IBPORT_IDX(PSStart)
283 #define krp_psstat KREG_IBPORT_IDX(PSStat)
284 #define krp_rcvbthqp KREG_IBPORT_IDX(RcvBTHQP)
285 #define krp_rcvctrl KREG_IBPORT_IDX(RcvCtrl)
286 #define krp_rcvpktledcnt KREG_IBPORT_IDX(RcvPktLEDCnt)
287 #define krp_rcvqpmaptable KREG_IBPORT_IDX(RcvQPMapTableA)
288 #define krp_rxcreditvl0 KREG_IBPORT_IDX(RxCreditVL0)
289 #define krp_rxcreditvl15 (KREG_IBPORT_IDX(RxCreditVL0)+15)
290 #define krp_sendcheckcontrol KREG_IBPORT_IDX(SendCheckControl)
291 #define krp_sendctrl KREG_IBPORT_IDX(SendCtrl)
292 #define krp_senddmabase KREG_IBPORT_IDX(SendDmaBase)
293 #define krp_senddmabufmask0 KREG_IBPORT_IDX(SendDmaBufMask0)
294 #define krp_senddmabufmask1 (KREG_IBPORT_IDX(SendDmaBufMask0) + 1)
295 #define krp_senddmabufmask2 (KREG_IBPORT_IDX(SendDmaBufMask0) + 2)
296 #define krp_senddmabuf_use0 KREG_IBPORT_IDX(SendDmaBufUsed0)
297 #define krp_senddmabuf_use1 (KREG_IBPORT_IDX(SendDmaBufUsed0) + 1)
298 #define krp_senddmabuf_use2 (KREG_IBPORT_IDX(SendDmaBufUsed0) + 2)
299 #define krp_senddmadesccnt KREG_IBPORT_IDX(SendDmaDescCnt)
300 #define krp_senddmahead KREG_IBPORT_IDX(SendDmaHead)
301 #define krp_senddmaheadaddr KREG_IBPORT_IDX(SendDmaHeadAddr)
302 #define krp_senddmaidlecnt KREG_IBPORT_IDX(SendDmaIdleCnt)
303 #define krp_senddmalengen KREG_IBPORT_IDX(SendDmaLenGen)
304 #define krp_senddmaprioritythld KREG_IBPORT_IDX(SendDmaPriorityThld)
305 #define krp_senddmareloadcnt KREG_IBPORT_IDX(SendDmaReloadCnt)
306 #define krp_senddmastatus KREG_IBPORT_IDX(SendDmaStatus)
307 #define krp_senddmatail KREG_IBPORT_IDX(SendDmaTail)
308 #define krp_sendhdrsymptom KREG_IBPORT_IDX(SendHdrErrSymptom)
309 #define krp_sendslid KREG_IBPORT_IDX(SendIBSLIDAssign)
310 #define krp_sendslidmask KREG_IBPORT_IDX(SendIBSLIDMask)
311 #define krp_ibsdtestiftx KREG_IBPORT_IDX(IB_SDTEST_IF_TX)
312 #define krp_adapt_dis_timer KREG_IBPORT_IDX(ADAPT_DISABLE_TIMER_THRESHOLD)
313 #define krp_tx_deemph_override KREG_IBPORT_IDX(IBSD_TX_DEEMPHASIS_OVERRIDE)
314 #define krp_serdesctrl KREG_IBPORT_IDX(IBSerdesCtrl)
317 * Per-context kernel registers. Acess only with qib_read_kreg_ctxt()
318 * or qib_write_kreg_ctxt()
320 #define krc_rcvhdraddr KREG_IDX(RcvHdrAddr0)
321 #define krc_rcvhdrtailaddr KREG_IDX(RcvHdrTailAddr0)
324 * TID Flow table, per context. Reduces
325 * number of hdrq updates to one per flow (or on errors).
326 * context 0 and 1 share same memory, but have distinct
327 * addresses. Since for now, we never use expected sends
328 * on kernel contexts, we don't worry about that (we initialize
329 * those entries for ctxt 0/1 on driver load twice, for example).
331 #define NUM_TIDFLOWS_CTXT 0x20 /* 0x20 per context; have to hardcode */
332 #define ur_rcvflowtable (KREG_IDX(RcvTIDFlowTable0) - KREG_IDX(RcvHdrTail0))
334 /* these are the error bits in the tid flows, and are W1C */
335 #define TIDFLOW_ERRBITS ( \
336 (SYM_MASK(RcvTIDFlowTable0, GenMismatch) << \
337 SYM_LSB(RcvTIDFlowTable0, GenMismatch)) | \
338 (SYM_MASK(RcvTIDFlowTable0, SeqMismatch) << \
339 SYM_LSB(RcvTIDFlowTable0, SeqMismatch)))
341 /* Most (not all) Counters are per-IBport.
342 * Requires LBIntCnt is at offset 0 in the group
344 #define CREG_IDX(regname) \
345 ((QIB_7322_##regname##_0_OFFS - QIB_7322_LBIntCnt_OFFS) / sizeof(u64))
347 #define crp_badformat CREG_IDX(RxVersionErrCnt)
348 #define crp_err_rlen CREG_IDX(RxLenErrCnt)
349 #define crp_erricrc CREG_IDX(RxICRCErrCnt)
350 #define crp_errlink CREG_IDX(RxLinkMalformCnt)
351 #define crp_errlpcrc CREG_IDX(RxLPCRCErrCnt)
352 #define crp_errpkey CREG_IDX(RxPKeyMismatchCnt)
353 #define crp_errvcrc CREG_IDX(RxVCRCErrCnt)
354 #define crp_excessbufferovfl CREG_IDX(ExcessBufferOvflCnt)
355 #define crp_iblinkdown CREG_IDX(IBLinkDownedCnt)
356 #define crp_iblinkerrrecov CREG_IDX(IBLinkErrRecoveryCnt)
357 #define crp_ibstatuschange CREG_IDX(IBStatusChangeCnt)
358 #define crp_ibsymbolerr CREG_IDX(IBSymbolErrCnt)
359 #define crp_invalidrlen CREG_IDX(RxMaxMinLenErrCnt)
360 #define crp_locallinkintegrityerr CREG_IDX(LocalLinkIntegrityErrCnt)
361 #define crp_pktrcv CREG_IDX(RxDataPktCnt)
362 #define crp_pktrcvflowctrl CREG_IDX(RxFlowPktCnt)
363 #define crp_pktsend CREG_IDX(TxDataPktCnt)
364 #define crp_pktsendflow CREG_IDX(TxFlowPktCnt)
365 #define crp_psrcvdatacount CREG_IDX(PSRcvDataCount)
366 #define crp_psrcvpktscount CREG_IDX(PSRcvPktsCount)
367 #define crp_psxmitdatacount CREG_IDX(PSXmitDataCount)
368 #define crp_psxmitpktscount CREG_IDX(PSXmitPktsCount)
369 #define crp_psxmitwaitcount CREG_IDX(PSXmitWaitCount)
370 #define crp_rcvebp CREG_IDX(RxEBPCnt)
371 #define crp_rcvflowctrlviol CREG_IDX(RxFlowCtrlViolCnt)
372 #define crp_rcvovfl CREG_IDX(RxBufOvflCnt)
373 #define crp_rxdlidfltr CREG_IDX(RxDlidFltrCnt)
374 #define crp_rxdroppkt CREG_IDX(RxDroppedPktCnt)
375 #define crp_rxotherlocalphyerr CREG_IDX(RxOtherLocalPhyErrCnt)
376 #define crp_rxqpinvalidctxt CREG_IDX(RxQPInvalidContextCnt)
377 #define crp_rxvlerr CREG_IDX(RxVlErrCnt)
378 #define crp_sendstall CREG_IDX(TxFlowStallCnt)
379 #define crp_txdroppedpkt CREG_IDX(TxDroppedPktCnt)
380 #define crp_txhdrerr CREG_IDX(TxHeadersErrCnt)
381 #define crp_txlenerr CREG_IDX(TxLenErrCnt)
382 #define crp_txlenerr CREG_IDX(TxLenErrCnt)
383 #define crp_txminmaxlenerr CREG_IDX(TxMaxMinLenErrCnt)
384 #define crp_txsdmadesc CREG_IDX(TxSDmaDescCnt)
385 #define crp_txunderrun CREG_IDX(TxUnderrunCnt)
386 #define crp_txunsupvl CREG_IDX(TxUnsupVLErrCnt)
387 #define crp_vl15droppedpkt CREG_IDX(RxVL15DroppedPktCnt)
388 #define crp_wordrcv CREG_IDX(RxDwordCnt)
389 #define crp_wordsend CREG_IDX(TxDwordCnt)
390 #define crp_tx_creditstalls CREG_IDX(TxCreditUpToDateTimeOut)
392 /* these are the (few) counters that are not port-specific */
393 #define CREG_DEVIDX(regname) ((QIB_7322_##regname##_OFFS - \
394 QIB_7322_LBIntCnt_OFFS) / sizeof(u64))
395 #define cr_base_egrovfl CREG_DEVIDX(RxP0HdrEgrOvflCnt)
396 #define cr_lbint CREG_DEVIDX(LBIntCnt)
397 #define cr_lbstall CREG_DEVIDX(LBFlowStallCnt)
398 #define cr_pcieretrydiag CREG_DEVIDX(PcieRetryBufDiagQwordCnt)
399 #define cr_rxtidflowdrop CREG_DEVIDX(RxTidFlowDropCnt)
400 #define cr_tidfull CREG_DEVIDX(RxTIDFullErrCnt)
401 #define cr_tidinvalid CREG_DEVIDX(RxTIDValidErrCnt)
403 /* no chip register for # of IB ports supported, so define */
404 #define NUM_IB_PORTS 2
406 /* 1 VL15 buffer per hardware IB port, no register for this, so define */
407 #define NUM_VL15_BUFS NUM_IB_PORTS
410 * context 0 and 1 are special, and there is no chip register that
411 * defines this value, so we have to define it here.
412 * These are all allocated to either 0 or 1 for single port
413 * hardware configuration, otherwise each gets half
415 #define KCTXT0_EGRCNT 2048
417 /* values for vl and port fields in PBC, 7322-specific */
418 #define PBC_PORT_SEL_LSB 26
419 #define PBC_PORT_SEL_RMASK 1
420 #define PBC_VL_NUM_LSB 27
421 #define PBC_VL_NUM_RMASK 7
422 #define PBC_7322_VL15_SEND (1ULL << 63) /* pbc; VL15, no credit check */
423 #define PBC_7322_VL15_SEND_CTRL (1ULL << 31) /* control version of same */
425 static u8 ib_rate_to_delay[IB_RATE_120_GBPS + 1] = {
426 [IB_RATE_2_5_GBPS] = 16,
427 [IB_RATE_5_GBPS] = 8,
428 [IB_RATE_10_GBPS] = 4,
429 [IB_RATE_20_GBPS] = 2,
430 [IB_RATE_30_GBPS] = 2,
431 [IB_RATE_40_GBPS] = 1
434 #define IBA7322_LINKSPEED_SHIFT SYM_LSB(IBCStatusA_0, LinkSpeedActive)
435 #define IBA7322_LINKWIDTH_SHIFT SYM_LSB(IBCStatusA_0, LinkWidthActive)
437 /* link training states, from IBC */
438 #define IB_7322_LT_STATE_DISABLED 0x00
439 #define IB_7322_LT_STATE_LINKUP 0x01
440 #define IB_7322_LT_STATE_POLLACTIVE 0x02
441 #define IB_7322_LT_STATE_POLLQUIET 0x03
442 #define IB_7322_LT_STATE_SLEEPDELAY 0x04
443 #define IB_7322_LT_STATE_SLEEPQUIET 0x05
444 #define IB_7322_LT_STATE_CFGDEBOUNCE 0x08
445 #define IB_7322_LT_STATE_CFGRCVFCFG 0x09
446 #define IB_7322_LT_STATE_CFGWAITRMT 0x0a
447 #define IB_7322_LT_STATE_CFGIDLE 0x0b
448 #define IB_7322_LT_STATE_RECOVERRETRAIN 0x0c
449 #define IB_7322_LT_STATE_TXREVLANES 0x0d
450 #define IB_7322_LT_STATE_RECOVERWAITRMT 0x0e
451 #define IB_7322_LT_STATE_RECOVERIDLE 0x0f
452 #define IB_7322_LT_STATE_CFGENH 0x10
453 #define IB_7322_LT_STATE_CFGTEST 0x11
455 /* link state machine states from IBC */
456 #define IB_7322_L_STATE_DOWN 0x0
457 #define IB_7322_L_STATE_INIT 0x1
458 #define IB_7322_L_STATE_ARM 0x2
459 #define IB_7322_L_STATE_ACTIVE 0x3
460 #define IB_7322_L_STATE_ACT_DEFER 0x4
462 static const u8 qib_7322_physportstate[0x20] = {
463 [IB_7322_LT_STATE_DISABLED] = IB_PHYSPORTSTATE_DISABLED,
464 [IB_7322_LT_STATE_LINKUP] = IB_PHYSPORTSTATE_LINKUP,
465 [IB_7322_LT_STATE_POLLACTIVE] = IB_PHYSPORTSTATE_POLL,
466 [IB_7322_LT_STATE_POLLQUIET] = IB_PHYSPORTSTATE_POLL,
467 [IB_7322_LT_STATE_SLEEPDELAY] = IB_PHYSPORTSTATE_SLEEP,
468 [IB_7322_LT_STATE_SLEEPQUIET] = IB_PHYSPORTSTATE_SLEEP,
469 [IB_7322_LT_STATE_CFGDEBOUNCE] = IB_PHYSPORTSTATE_CFG_TRAIN,
470 [IB_7322_LT_STATE_CFGRCVFCFG] =
471 IB_PHYSPORTSTATE_CFG_TRAIN,
472 [IB_7322_LT_STATE_CFGWAITRMT] =
473 IB_PHYSPORTSTATE_CFG_TRAIN,
474 [IB_7322_LT_STATE_CFGIDLE] = IB_PHYSPORTSTATE_CFG_IDLE,
475 [IB_7322_LT_STATE_RECOVERRETRAIN] =
476 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
477 [IB_7322_LT_STATE_RECOVERWAITRMT] =
478 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
479 [IB_7322_LT_STATE_RECOVERIDLE] =
480 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
481 [IB_7322_LT_STATE_CFGENH] = IB_PHYSPORTSTATE_CFG_ENH,
482 [IB_7322_LT_STATE_CFGTEST] = IB_PHYSPORTSTATE_CFG_TRAIN,
483 [0x12] = IB_PHYSPORTSTATE_CFG_TRAIN,
484 [0x13] = IB_PHYSPORTSTATE_CFG_WAIT_ENH,
485 [0x14] = IB_PHYSPORTSTATE_CFG_TRAIN,
486 [0x15] = IB_PHYSPORTSTATE_CFG_TRAIN,
487 [0x16] = IB_PHYSPORTSTATE_CFG_TRAIN,
488 [0x17] = IB_PHYSPORTSTATE_CFG_TRAIN
491 struct qib_chip_specific {
492 u64 __iomem *cregbase;
494 spinlock_t rcvmod_lock; /* protect rcvctrl shadow changes */
495 spinlock_t gpio_lock; /* RMW of shadows/regs for ExtCtrl and GPIO */
496 u64 main_int_mask; /* clear bits which have dedicated handlers */
497 u64 int_enable_mask; /* for per port interrupts in single port mode */
500 u64 gpio_out; /* shadow of kr_gpio_out, for rmw ops */
501 u64 gpio_mask; /* shadow the gpio mask register */
502 u64 extctrl; /* shadow the gpio output enable, etc... */
509 u32 updthresh; /* current AvailUpdThld */
510 u32 updthresh_dflt; /* default AvailUpdThld */
513 u32 num_msix_entries;
517 u32 recovery_ports_initted;
518 struct msix_entry *msix_entries;
520 unsigned long *sendchkenable;
521 unsigned long *sendgrhchk;
522 unsigned long *sendibchk;
523 u32 rcvavail_timeout[18];
524 char emsgbuf[128]; /* for device error interrupt msg buffer */
527 /* Table of entries in "human readable" form Tx Emphasis. */
535 struct vendor_txdds_ent {
536 u8 oui[QSFP_VOUI_LEN];
538 struct txdds_ent sdr;
539 struct txdds_ent ddr;
540 struct txdds_ent qdr;
543 static void write_tx_serdes_param(struct qib_pportdata *, struct txdds_ent *);
545 #define TXDDS_TABLE_SZ 16 /* number of entries per speed in onchip table */
546 #define TXDDS_EXTRA_SZ 11 /* number of extra tx settings entries */
547 #define SERDES_CHANS 4 /* yes, it's obvious, but one less magic number */
549 #define H1_FORCE_VAL 8
550 #define H1_FORCE_QME 1 /* may be overridden via setup_txselect() */
551 #define H1_FORCE_QMH 7 /* may be overridden via setup_txselect() */
553 /* The static and dynamic registers are paired, and the pairs indexed by spd */
554 #define krp_static_adapt_dis(spd) (KREG_IBPORT_IDX(ADAPT_DISABLE_STATIC_SDR) \
557 #define QDR_DFE_DISABLE_DELAY 4000 /* msec after LINKUP */
558 #define QDR_STATIC_ADAPT_DOWN 0xf0f0f0f0ULL /* link down, H1-H4 QDR adapts */
559 #define QDR_STATIC_ADAPT_DOWN_R1 0ULL /* r1 link down, H1-H4 QDR adapts */
560 #define QDR_STATIC_ADAPT_INIT 0xffffffffffULL /* up, disable H0,H1-8, LE */
561 #define QDR_STATIC_ADAPT_INIT_R1 0xf0ffffffffULL /* r1 up, disable H0,H1-8 */
563 struct qib_chippport_specific {
564 u64 __iomem *kpregbase;
565 u64 __iomem *cpregbase;
567 struct qib_pportdata *ppd;
568 wait_queue_head_t autoneg_wait;
569 struct delayed_work autoneg_work;
570 struct delayed_work ipg_work;
571 struct timer_list chase_timer;
573 * these 5 fields are used to establish deltas for IB symbol
574 * errors and linkrecovery errors. They can be reported on
575 * some chips during link negotiation prior to INIT, and with
576 * DDR when faking DDR negotiations with non-IBTA switches.
577 * The chip counters are adjusted at driver unload if there is
589 u64 ibcctrl_a; /* krp_ibcctrl_a shadow */
590 u64 ibcctrl_b; /* krp_ibcctrl_b shadow */
598 * Per-bay per-channel rcv QMH H1 values and Tx values for QDR.
599 * entry zero is unused, to simplify indexing
602 u8 no_eep; /* txselect table index to use if no qsfp info */
605 struct qib_qsfp_data qsfp_data;
606 char epmsgbuf[192]; /* for port error interrupt msg buffer */
611 irq_handler_t handler;
613 int port; /* 0 if not port-specific, else port # */
615 { QIB_DRV_NAME, qib_7322intr, -1, 0 },
616 { QIB_DRV_NAME " (buf avail)", qib_7322bufavail,
617 SYM_LSB(IntStatus, SendBufAvail), 0 },
618 { QIB_DRV_NAME " (sdma 0)", sdma_intr,
619 SYM_LSB(IntStatus, SDmaInt_0), 1 },
620 { QIB_DRV_NAME " (sdma 1)", sdma_intr,
621 SYM_LSB(IntStatus, SDmaInt_1), 2 },
622 { QIB_DRV_NAME " (sdmaI 0)", sdma_idle_intr,
623 SYM_LSB(IntStatus, SDmaIdleInt_0), 1 },
624 { QIB_DRV_NAME " (sdmaI 1)", sdma_idle_intr,
625 SYM_LSB(IntStatus, SDmaIdleInt_1), 2 },
626 { QIB_DRV_NAME " (sdmaP 0)", sdma_progress_intr,
627 SYM_LSB(IntStatus, SDmaProgressInt_0), 1 },
628 { QIB_DRV_NAME " (sdmaP 1)", sdma_progress_intr,
629 SYM_LSB(IntStatus, SDmaProgressInt_1), 2 },
630 { QIB_DRV_NAME " (sdmaC 0)", sdma_cleanup_intr,
631 SYM_LSB(IntStatus, SDmaCleanupDone_0), 1 },
632 { QIB_DRV_NAME " (sdmaC 1)", sdma_cleanup_intr,
633 SYM_LSB(IntStatus, SDmaCleanupDone_1), 2 },
637 #define QLOGIC_IB_IBCC_LINKINITCMD_DISABLE 1
638 /* cycle through TS1/TS2 till OK */
639 #define QLOGIC_IB_IBCC_LINKINITCMD_POLL 2
640 /* wait for TS1, then go on */
641 #define QLOGIC_IB_IBCC_LINKINITCMD_SLEEP 3
642 #define QLOGIC_IB_IBCC_LINKINITCMD_SHIFT 16
644 #define QLOGIC_IB_IBCC_LINKCMD_DOWN 1 /* move to 0x11 */
645 #define QLOGIC_IB_IBCC_LINKCMD_ARMED 2 /* move to 0x21 */
646 #define QLOGIC_IB_IBCC_LINKCMD_ACTIVE 3 /* move to 0x31 */
648 #define BLOB_7322_IBCHG 0x101
650 static inline void qib_write_kreg(const struct qib_devdata *dd,
651 const u32 regno, u64 value);
652 static inline u32 qib_read_kreg32(const struct qib_devdata *, const u32);
653 static void write_7322_initregs(struct qib_devdata *);
654 static void write_7322_init_portregs(struct qib_pportdata *);
655 static void setup_7322_link_recovery(struct qib_pportdata *, u32);
656 static void check_7322_rxe_status(struct qib_pportdata *);
657 static u32 __iomem *qib_7322_getsendbuf(struct qib_pportdata *, u64, u32 *);
660 * qib_read_ureg32 - read 32-bit virtualized per-context register
662 * @regno: register number
663 * @ctxt: context number
665 * Return the contents of a register that is virtualized to be per context.
666 * Returns -1 on errors (not distinguishable from valid contents at
667 * runtime; we may add a separate error variable at some point).
669 static inline u32 qib_read_ureg32(const struct qib_devdata *dd,
670 enum qib_ureg regno, int ctxt)
672 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
674 return readl(regno + (u64 __iomem *)(
675 (dd->ureg_align * ctxt) + (dd->userbase ?
676 (char __iomem *)dd->userbase :
677 (char __iomem *)dd->kregbase + dd->uregbase)));
681 * qib_read_ureg - read virtualized per-context register
683 * @regno: register number
684 * @ctxt: context number
686 * Return the contents of a register that is virtualized to be per context.
687 * Returns -1 on errors (not distinguishable from valid contents at
688 * runtime; we may add a separate error variable at some point).
690 static inline u64 qib_read_ureg(const struct qib_devdata *dd,
691 enum qib_ureg regno, int ctxt)
694 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
696 return readq(regno + (u64 __iomem *)(
697 (dd->ureg_align * ctxt) + (dd->userbase ?
698 (char __iomem *)dd->userbase :
699 (char __iomem *)dd->kregbase + dd->uregbase)));
703 * qib_write_ureg - write virtualized per-context register
705 * @regno: register number
709 * Write the contents of a register that is virtualized to be per context.
711 static inline void qib_write_ureg(const struct qib_devdata *dd,
712 enum qib_ureg regno, u64 value, int ctxt)
716 ubase = (u64 __iomem *)
717 ((char __iomem *) dd->userbase +
718 dd->ureg_align * ctxt);
720 ubase = (u64 __iomem *)
722 (char __iomem *) dd->kregbase +
723 dd->ureg_align * ctxt);
725 if (dd->kregbase && (dd->flags & QIB_PRESENT))
726 writeq(value, &ubase[regno]);
729 static inline u32 qib_read_kreg32(const struct qib_devdata *dd,
732 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
734 return readl((u32 __iomem *) &dd->kregbase[regno]);
737 static inline u64 qib_read_kreg64(const struct qib_devdata *dd,
740 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
742 return readq(&dd->kregbase[regno]);
745 static inline void qib_write_kreg(const struct qib_devdata *dd,
746 const u32 regno, u64 value)
748 if (dd->kregbase && (dd->flags & QIB_PRESENT))
749 writeq(value, &dd->kregbase[regno]);
753 * not many sanity checks for the port-specific kernel register routines,
754 * since they are only used when it's known to be safe.
756 static inline u64 qib_read_kreg_port(const struct qib_pportdata *ppd,
759 if (!ppd->cpspec->kpregbase || !(ppd->dd->flags & QIB_PRESENT))
761 return readq(&ppd->cpspec->kpregbase[regno]);
764 static inline void qib_write_kreg_port(const struct qib_pportdata *ppd,
765 const u16 regno, u64 value)
767 if (ppd->cpspec && ppd->dd && ppd->cpspec->kpregbase &&
768 (ppd->dd->flags & QIB_PRESENT))
769 writeq(value, &ppd->cpspec->kpregbase[regno]);
773 * qib_write_kreg_ctxt - write a device's per-ctxt 64-bit kernel register
774 * @dd: the qlogic_ib device
775 * @regno: the register number to write
776 * @ctxt: the context containing the register
777 * @value: the value to write
779 static inline void qib_write_kreg_ctxt(const struct qib_devdata *dd,
780 const u16 regno, unsigned ctxt,
783 qib_write_kreg(dd, regno + ctxt, value);
786 static inline u64 read_7322_creg(const struct qib_devdata *dd, u16 regno)
788 if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
790 return readq(&dd->cspec->cregbase[regno]);
795 static inline u32 read_7322_creg32(const struct qib_devdata *dd, u16 regno)
797 if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
799 return readl(&dd->cspec->cregbase[regno]);
804 static inline void write_7322_creg_port(const struct qib_pportdata *ppd,
805 u16 regno, u64 value)
807 if (ppd->cpspec && ppd->cpspec->cpregbase &&
808 (ppd->dd->flags & QIB_PRESENT))
809 writeq(value, &ppd->cpspec->cpregbase[regno]);
812 static inline u64 read_7322_creg_port(const struct qib_pportdata *ppd,
815 if (!ppd->cpspec || !ppd->cpspec->cpregbase ||
816 !(ppd->dd->flags & QIB_PRESENT))
818 return readq(&ppd->cpspec->cpregbase[regno]);
821 static inline u32 read_7322_creg32_port(const struct qib_pportdata *ppd,
824 if (!ppd->cpspec || !ppd->cpspec->cpregbase ||
825 !(ppd->dd->flags & QIB_PRESENT))
827 return readl(&ppd->cpspec->cpregbase[regno]);
830 /* bits in Control register */
831 #define QLOGIC_IB_C_RESET SYM_MASK(Control, SyncReset)
832 #define QLOGIC_IB_C_SDMAFETCHPRIOEN SYM_MASK(Control, SDmaDescFetchPriorityEn)
834 /* bits in general interrupt regs */
835 #define QIB_I_RCVURG_LSB SYM_LSB(IntMask, RcvUrg0IntMask)
836 #define QIB_I_RCVURG_RMASK MASK_ACROSS(0, 17)
837 #define QIB_I_RCVURG_MASK (QIB_I_RCVURG_RMASK << QIB_I_RCVURG_LSB)
838 #define QIB_I_RCVAVAIL_LSB SYM_LSB(IntMask, RcvAvail0IntMask)
839 #define QIB_I_RCVAVAIL_RMASK MASK_ACROSS(0, 17)
840 #define QIB_I_RCVAVAIL_MASK (QIB_I_RCVAVAIL_RMASK << QIB_I_RCVAVAIL_LSB)
841 #define QIB_I_C_ERROR INT_MASK(Err)
843 #define QIB_I_SPIOSENT (INT_MASK_P(SendDone, 0) | INT_MASK_P(SendDone, 1))
844 #define QIB_I_SPIOBUFAVAIL INT_MASK(SendBufAvail)
845 #define QIB_I_GPIO INT_MASK(AssertGPIO)
846 #define QIB_I_P_SDMAINT(pidx) \
847 (INT_MASK_P(SDma, pidx) | INT_MASK_P(SDmaIdle, pidx) | \
848 INT_MASK_P(SDmaProgress, pidx) | \
849 INT_MASK_PM(SDmaCleanupDone, pidx))
851 /* Interrupt bits that are "per port" */
852 #define QIB_I_P_BITSEXTANT(pidx) \
853 (INT_MASK_P(Err, pidx) | INT_MASK_P(SendDone, pidx) | \
854 INT_MASK_P(SDma, pidx) | INT_MASK_P(SDmaIdle, pidx) | \
855 INT_MASK_P(SDmaProgress, pidx) | \
856 INT_MASK_PM(SDmaCleanupDone, pidx))
858 /* Interrupt bits that are common to a device */
859 /* currently unused: QIB_I_SPIOSENT */
860 #define QIB_I_C_BITSEXTANT \
861 (QIB_I_RCVURG_MASK | QIB_I_RCVAVAIL_MASK | \
863 QIB_I_C_ERROR | QIB_I_SPIOBUFAVAIL | QIB_I_GPIO)
865 #define QIB_I_BITSEXTANT (QIB_I_C_BITSEXTANT | \
866 QIB_I_P_BITSEXTANT(0) | QIB_I_P_BITSEXTANT(1))
869 * Error bits that are "per port".
871 #define QIB_E_P_IBSTATUSCHANGED ERR_MASK_N(IBStatusChanged)
872 #define QIB_E_P_SHDR ERR_MASK_N(SHeadersErr)
873 #define QIB_E_P_VL15_BUF_MISUSE ERR_MASK_N(VL15BufMisuseErr)
874 #define QIB_E_P_SND_BUF_MISUSE ERR_MASK_N(SendBufMisuseErr)
875 #define QIB_E_P_SUNSUPVL ERR_MASK_N(SendUnsupportedVLErr)
876 #define QIB_E_P_SUNEXP_PKTNUM ERR_MASK_N(SendUnexpectedPktNumErr)
877 #define QIB_E_P_SDROP_DATA ERR_MASK_N(SendDroppedDataPktErr)
878 #define QIB_E_P_SDROP_SMP ERR_MASK_N(SendDroppedSmpPktErr)
879 #define QIB_E_P_SPKTLEN ERR_MASK_N(SendPktLenErr)
880 #define QIB_E_P_SUNDERRUN ERR_MASK_N(SendUnderRunErr)
881 #define QIB_E_P_SMAXPKTLEN ERR_MASK_N(SendMaxPktLenErr)
882 #define QIB_E_P_SMINPKTLEN ERR_MASK_N(SendMinPktLenErr)
883 #define QIB_E_P_RIBLOSTLINK ERR_MASK_N(RcvIBLostLinkErr)
884 #define QIB_E_P_RHDR ERR_MASK_N(RcvHdrErr)
885 #define QIB_E_P_RHDRLEN ERR_MASK_N(RcvHdrLenErr)
886 #define QIB_E_P_RBADTID ERR_MASK_N(RcvBadTidErr)
887 #define QIB_E_P_RBADVERSION ERR_MASK_N(RcvBadVersionErr)
888 #define QIB_E_P_RIBFLOW ERR_MASK_N(RcvIBFlowErr)
889 #define QIB_E_P_REBP ERR_MASK_N(RcvEBPErr)
890 #define QIB_E_P_RUNSUPVL ERR_MASK_N(RcvUnsupportedVLErr)
891 #define QIB_E_P_RUNEXPCHAR ERR_MASK_N(RcvUnexpectedCharErr)
892 #define QIB_E_P_RSHORTPKTLEN ERR_MASK_N(RcvShortPktLenErr)
893 #define QIB_E_P_RLONGPKTLEN ERR_MASK_N(RcvLongPktLenErr)
894 #define QIB_E_P_RMAXPKTLEN ERR_MASK_N(RcvMaxPktLenErr)
895 #define QIB_E_P_RMINPKTLEN ERR_MASK_N(RcvMinPktLenErr)
896 #define QIB_E_P_RICRC ERR_MASK_N(RcvICRCErr)
897 #define QIB_E_P_RVCRC ERR_MASK_N(RcvVCRCErr)
898 #define QIB_E_P_RFORMATERR ERR_MASK_N(RcvFormatErr)
900 #define QIB_E_P_SDMA1STDESC ERR_MASK_N(SDma1stDescErr)
901 #define QIB_E_P_SDMABASE ERR_MASK_N(SDmaBaseErr)
902 #define QIB_E_P_SDMADESCADDRMISALIGN ERR_MASK_N(SDmaDescAddrMisalignErr)
903 #define QIB_E_P_SDMADWEN ERR_MASK_N(SDmaDwEnErr)
904 #define QIB_E_P_SDMAGENMISMATCH ERR_MASK_N(SDmaGenMismatchErr)
905 #define QIB_E_P_SDMAHALT ERR_MASK_N(SDmaHaltErr)
906 #define QIB_E_P_SDMAMISSINGDW ERR_MASK_N(SDmaMissingDwErr)
907 #define QIB_E_P_SDMAOUTOFBOUND ERR_MASK_N(SDmaOutOfBoundErr)
908 #define QIB_E_P_SDMARPYTAG ERR_MASK_N(SDmaRpyTagErr)
909 #define QIB_E_P_SDMATAILOUTOFBOUND ERR_MASK_N(SDmaTailOutOfBoundErr)
910 #define QIB_E_P_SDMAUNEXPDATA ERR_MASK_N(SDmaUnexpDataErr)
912 /* Error bits that are common to a device */
913 #define QIB_E_RESET ERR_MASK(ResetNegated)
914 #define QIB_E_HARDWARE ERR_MASK(HardwareErr)
915 #define QIB_E_INVALIDADDR ERR_MASK(InvalidAddrErr)
919 * Per chip (rather than per-port) errors. Most either do
920 * nothing but trigger a print (because they self-recover, or
921 * always occur in tandem with other errors that handle the
922 * issue), or because they indicate errors with no recovery,
923 * but we want to know that they happened.
925 #define QIB_E_SBUF_VL15_MISUSE ERR_MASK(SBufVL15MisUseErr)
926 #define QIB_E_BADEEP ERR_MASK(InvalidEEPCmd)
927 #define QIB_E_VLMISMATCH ERR_MASK(SendVLMismatchErr)
928 #define QIB_E_ARMLAUNCH ERR_MASK(SendArmLaunchErr)
929 #define QIB_E_SPCLTRIG ERR_MASK(SendSpecialTriggerErr)
930 #define QIB_E_RRCVHDRFULL ERR_MASK(RcvHdrFullErr)
931 #define QIB_E_RRCVEGRFULL ERR_MASK(RcvEgrFullErr)
932 #define QIB_E_RCVCTXTSHARE ERR_MASK(RcvContextShareErr)
934 /* SDMA chip errors (not per port)
935 * QIB_E_SDMA_BUF_DUP needs no special handling, because we will also get
936 * the SDMAHALT error immediately, so we just print the dup error via the
937 * E_AUTO mechanism. This is true of most of the per-port fatal errors
938 * as well, but since this is port-independent, by definition, it's
939 * handled a bit differently. SDMA_VL15 and SDMA_WRONG_PORT are per
940 * packet send errors, and so are handled in the same manner as other
943 #define QIB_E_SDMA_VL15 ERR_MASK(SDmaVL15Err)
944 #define QIB_E_SDMA_WRONG_PORT ERR_MASK(SDmaWrongPortErr)
945 #define QIB_E_SDMA_BUF_DUP ERR_MASK(SDmaBufMaskDuplicateErr)
948 * Below functionally equivalent to legacy QLOGIC_IB_E_PKTERRS
949 * it is used to print "common" packet errors.
951 #define QIB_E_P_PKTERRS (QIB_E_P_SPKTLEN |\
952 QIB_E_P_SDROP_DATA | QIB_E_P_RVCRC |\
953 QIB_E_P_RICRC | QIB_E_P_RSHORTPKTLEN |\
954 QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SHDR | \
957 /* Error Bits that Packet-related (Receive, per-port) */
958 #define QIB_E_P_RPKTERRS (\
959 QIB_E_P_RHDRLEN | QIB_E_P_RBADTID | \
960 QIB_E_P_RBADVERSION | QIB_E_P_RHDR | \
961 QIB_E_P_RLONGPKTLEN | QIB_E_P_RSHORTPKTLEN |\
962 QIB_E_P_RMAXPKTLEN | QIB_E_P_RMINPKTLEN | \
963 QIB_E_P_RFORMATERR | QIB_E_P_RUNSUPVL | \
964 QIB_E_P_RUNEXPCHAR | QIB_E_P_RIBFLOW | QIB_E_P_REBP)
967 * Error bits that are Send-related (per port)
968 * (ARMLAUNCH excluded from E_SPKTERRS because it gets special handling).
969 * All of these potentially need to have a buffer disarmed
971 #define QIB_E_P_SPKTERRS (\
972 QIB_E_P_SUNEXP_PKTNUM |\
973 QIB_E_P_SDROP_DATA | QIB_E_P_SDROP_SMP |\
974 QIB_E_P_SMAXPKTLEN |\
975 QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SHDR | \
976 QIB_E_P_SMINPKTLEN | QIB_E_P_SPKTLEN | \
977 QIB_E_P_SND_BUF_MISUSE | QIB_E_P_SUNSUPVL)
979 #define QIB_E_SPKTERRS ( \
980 QIB_E_SBUF_VL15_MISUSE | QIB_E_VLMISMATCH | \
981 ERR_MASK_N(SendUnsupportedVLErr) | \
982 QIB_E_SPCLTRIG | QIB_E_SDMA_VL15 | QIB_E_SDMA_WRONG_PORT)
984 #define QIB_E_P_SDMAERRS ( \
986 QIB_E_P_SDMADESCADDRMISALIGN | \
987 QIB_E_P_SDMAUNEXPDATA | \
988 QIB_E_P_SDMAMISSINGDW | \
990 QIB_E_P_SDMARPYTAG | \
991 QIB_E_P_SDMA1STDESC | \
993 QIB_E_P_SDMATAILOUTOFBOUND | \
994 QIB_E_P_SDMAOUTOFBOUND | \
995 QIB_E_P_SDMAGENMISMATCH)
998 * This sets some bits more than once, but makes it more obvious which
999 * bits are not handled under other categories, and the repeat definition
1002 #define QIB_E_P_BITSEXTANT ( \
1003 QIB_E_P_SPKTERRS | QIB_E_P_PKTERRS | QIB_E_P_RPKTERRS | \
1004 QIB_E_P_RIBLOSTLINK | QIB_E_P_IBSTATUSCHANGED | \
1005 QIB_E_P_SND_BUF_MISUSE | QIB_E_P_SUNDERRUN | \
1006 QIB_E_P_SHDR | QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SDMAERRS \
1010 * These are errors that can occur when the link
1011 * changes state while a packet is being sent or received. This doesn't
1012 * cover things like EBP or VCRC that can be the result of a sending
1013 * having the link change state, so we receive a "known bad" packet.
1014 * All of these are "per port", so renamed:
1016 #define QIB_E_P_LINK_PKTERRS (\
1017 QIB_E_P_SDROP_DATA | QIB_E_P_SDROP_SMP |\
1018 QIB_E_P_SMINPKTLEN | QIB_E_P_SPKTLEN |\
1019 QIB_E_P_RSHORTPKTLEN | QIB_E_P_RMINPKTLEN |\
1023 * This sets some bits more than once, but makes it more obvious which
1024 * bits are not handled under other categories (such as QIB_E_SPKTERRS),
1025 * and the repeat definition is not a problem.
1027 #define QIB_E_C_BITSEXTANT (\
1028 QIB_E_HARDWARE | QIB_E_INVALIDADDR | QIB_E_BADEEP |\
1029 QIB_E_ARMLAUNCH | QIB_E_VLMISMATCH | QIB_E_RRCVHDRFULL |\
1030 QIB_E_RRCVEGRFULL | QIB_E_RESET | QIB_E_SBUF_VL15_MISUSE)
1032 /* Likewise Neuter E_SPKT_ERRS_IGNORE */
1033 #define E_SPKT_ERRS_IGNORE 0
1035 #define QIB_EXTS_MEMBIST_DISABLED \
1036 SYM_MASK(EXTStatus, MemBISTDisabled)
1037 #define QIB_EXTS_MEMBIST_ENDTEST \
1038 SYM_MASK(EXTStatus, MemBISTEndTest)
1040 #define QIB_E_SPIOARMLAUNCH \
1041 ERR_MASK(SendArmLaunchErr)
1043 #define IBA7322_IBCC_LINKINITCMD_MASK SYM_RMASK(IBCCtrlA_0, LinkInitCmd)
1044 #define IBA7322_IBCC_LINKCMD_SHIFT SYM_LSB(IBCCtrlA_0, LinkCmd)
1047 * IBTA_1_2 is set when multiple speeds are enabled (normal),
1048 * and also if forced QDR (only QDR enabled). It's enabled for the
1049 * forced QDR case so that scrambling will be enabled by the TS3
1050 * exchange, when supported by both sides of the link.
1052 #define IBA7322_IBC_IBTA_1_2_MASK SYM_MASK(IBCCtrlB_0, IB_ENHANCED_MODE)
1053 #define IBA7322_IBC_MAX_SPEED_MASK SYM_MASK(IBCCtrlB_0, SD_SPEED)
1054 #define IBA7322_IBC_SPEED_QDR SYM_MASK(IBCCtrlB_0, SD_SPEED_QDR)
1055 #define IBA7322_IBC_SPEED_DDR SYM_MASK(IBCCtrlB_0, SD_SPEED_DDR)
1056 #define IBA7322_IBC_SPEED_SDR SYM_MASK(IBCCtrlB_0, SD_SPEED_SDR)
1057 #define IBA7322_IBC_SPEED_MASK (SYM_MASK(IBCCtrlB_0, SD_SPEED_SDR) | \
1058 SYM_MASK(IBCCtrlB_0, SD_SPEED_DDR) | SYM_MASK(IBCCtrlB_0, SD_SPEED_QDR))
1059 #define IBA7322_IBC_SPEED_LSB SYM_LSB(IBCCtrlB_0, SD_SPEED_SDR)
1061 #define IBA7322_LEDBLINK_OFF_SHIFT SYM_LSB(RcvPktLEDCnt_0, OFFperiod)
1062 #define IBA7322_LEDBLINK_ON_SHIFT SYM_LSB(RcvPktLEDCnt_0, ONperiod)
1064 #define IBA7322_IBC_WIDTH_AUTONEG SYM_MASK(IBCCtrlB_0, IB_NUM_CHANNELS)
1065 #define IBA7322_IBC_WIDTH_4X_ONLY (1<<SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS))
1066 #define IBA7322_IBC_WIDTH_1X_ONLY (0<<SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS))
1068 #define IBA7322_IBC_RXPOL_MASK SYM_MASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP)
1069 #define IBA7322_IBC_RXPOL_LSB SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP)
1070 #define IBA7322_IBC_HRTBT_MASK (SYM_MASK(IBCCtrlB_0, HRTBT_AUTO) | \
1071 SYM_MASK(IBCCtrlB_0, HRTBT_ENB))
1072 #define IBA7322_IBC_HRTBT_RMASK (IBA7322_IBC_HRTBT_MASK >> \
1073 SYM_LSB(IBCCtrlB_0, HRTBT_ENB))
1074 #define IBA7322_IBC_HRTBT_LSB SYM_LSB(IBCCtrlB_0, HRTBT_ENB)
1076 #define IBA7322_REDIRECT_VEC_PER_REG 12
1078 #define IBA7322_SENDCHK_PKEY SYM_MASK(SendCheckControl_0, PKey_En)
1079 #define IBA7322_SENDCHK_BTHQP SYM_MASK(SendCheckControl_0, BTHQP_En)
1080 #define IBA7322_SENDCHK_SLID SYM_MASK(SendCheckControl_0, SLID_En)
1081 #define IBA7322_SENDCHK_RAW_IPV6 SYM_MASK(SendCheckControl_0, RawIPV6_En)
1082 #define IBA7322_SENDCHK_MINSZ SYM_MASK(SendCheckControl_0, PacketTooSmall_En)
1084 #define AUTONEG_TRIES 3 /* sequential retries to negotiate DDR */
1086 #define HWE_AUTO(fldname) { .mask = SYM_MASK(HwErrMask, fldname##Mask), \
1088 #define HWE_AUTO_P(fldname, port) { .mask = SYM_MASK(HwErrMask, \
1089 fldname##Mask##_##port), .msg = #fldname }
1090 static const struct qib_hwerror_msgs qib_7322_hwerror_msgs[] = {
1091 HWE_AUTO_P(IBSerdesPClkNotDetect, 1),
1092 HWE_AUTO_P(IBSerdesPClkNotDetect, 0),
1093 HWE_AUTO(PCIESerdesPClkNotDetect),
1094 HWE_AUTO(PowerOnBISTFailed),
1095 HWE_AUTO(TempsenseTholdReached),
1096 HWE_AUTO(MemoryErr),
1097 HWE_AUTO(PCIeBusParityErr),
1098 HWE_AUTO(PcieCplTimeout),
1099 HWE_AUTO(PciePoisonedTLP),
1100 HWE_AUTO_P(SDmaMemReadErr, 1),
1101 HWE_AUTO_P(SDmaMemReadErr, 0),
1102 HWE_AUTO_P(IBCBusFromSPCParityErr, 1),
1103 HWE_AUTO_P(IBCBusFromSPCParityErr, 0),
1104 HWE_AUTO_P(statusValidNoEop, 1),
1105 HWE_AUTO_P(statusValidNoEop, 0),
1106 HWE_AUTO(LATriggered),
1110 #define E_AUTO(fldname) { .mask = SYM_MASK(ErrMask, fldname##Mask), \
1112 #define E_P_AUTO(fldname) { .mask = SYM_MASK(ErrMask_0, fldname##Mask), \
1114 static const struct qib_hwerror_msgs qib_7322error_msgs[] = {
1115 E_AUTO(ResetNegated),
1116 E_AUTO(HardwareErr),
1117 E_AUTO(InvalidAddrErr),
1118 E_AUTO(SDmaVL15Err),
1119 E_AUTO(SBufVL15MisUseErr),
1120 E_AUTO(InvalidEEPCmd),
1121 E_AUTO(RcvContextShareErr),
1122 E_AUTO(SendVLMismatchErr),
1123 E_AUTO(SendArmLaunchErr),
1124 E_AUTO(SendSpecialTriggerErr),
1125 E_AUTO(SDmaWrongPortErr),
1126 E_AUTO(SDmaBufMaskDuplicateErr),
1127 E_AUTO(RcvHdrFullErr),
1128 E_AUTO(RcvEgrFullErr),
1132 static const struct qib_hwerror_msgs qib_7322p_error_msgs[] = {
1133 E_P_AUTO(IBStatusChanged),
1134 E_P_AUTO(SHeadersErr),
1135 E_P_AUTO(VL15BufMisuseErr),
1137 * SDmaHaltErr is not really an error, make it clearer;
1139 {.mask = SYM_MASK(ErrMask_0, SDmaHaltErrMask), .msg = "SDmaHalted"},
1140 E_P_AUTO(SDmaDescAddrMisalignErr),
1141 E_P_AUTO(SDmaUnexpDataErr),
1142 E_P_AUTO(SDmaMissingDwErr),
1143 E_P_AUTO(SDmaDwEnErr),
1144 E_P_AUTO(SDmaRpyTagErr),
1145 E_P_AUTO(SDma1stDescErr),
1146 E_P_AUTO(SDmaBaseErr),
1147 E_P_AUTO(SDmaTailOutOfBoundErr),
1148 E_P_AUTO(SDmaOutOfBoundErr),
1149 E_P_AUTO(SDmaGenMismatchErr),
1150 E_P_AUTO(SendBufMisuseErr),
1151 E_P_AUTO(SendUnsupportedVLErr),
1152 E_P_AUTO(SendUnexpectedPktNumErr),
1153 E_P_AUTO(SendDroppedDataPktErr),
1154 E_P_AUTO(SendDroppedSmpPktErr),
1155 E_P_AUTO(SendPktLenErr),
1156 E_P_AUTO(SendUnderRunErr),
1157 E_P_AUTO(SendMaxPktLenErr),
1158 E_P_AUTO(SendMinPktLenErr),
1159 E_P_AUTO(RcvIBLostLinkErr),
1160 E_P_AUTO(RcvHdrErr),
1161 E_P_AUTO(RcvHdrLenErr),
1162 E_P_AUTO(RcvBadTidErr),
1163 E_P_AUTO(RcvBadVersionErr),
1164 E_P_AUTO(RcvIBFlowErr),
1165 E_P_AUTO(RcvEBPErr),
1166 E_P_AUTO(RcvUnsupportedVLErr),
1167 E_P_AUTO(RcvUnexpectedCharErr),
1168 E_P_AUTO(RcvShortPktLenErr),
1169 E_P_AUTO(RcvLongPktLenErr),
1170 E_P_AUTO(RcvMaxPktLenErr),
1171 E_P_AUTO(RcvMinPktLenErr),
1172 E_P_AUTO(RcvICRCErr),
1173 E_P_AUTO(RcvVCRCErr),
1174 E_P_AUTO(RcvFormatErr),
1179 * Below generates "auto-message" for interrupts not specific to any port or
1182 #define INTR_AUTO(fldname) { .mask = SYM_MASK(IntMask, fldname##Mask), \
1184 /* Below generates "auto-message" for interrupts specific to a port */
1185 #define INTR_AUTO_P(fldname) { .mask = MASK_ACROSS(\
1186 SYM_LSB(IntMask, fldname##Mask##_0), \
1187 SYM_LSB(IntMask, fldname##Mask##_1)), \
1188 .msg = #fldname "_P" }
1189 /* For some reason, the SerDesTrimDone bits are reversed */
1190 #define INTR_AUTO_PI(fldname) { .mask = MASK_ACROSS(\
1191 SYM_LSB(IntMask, fldname##Mask##_1), \
1192 SYM_LSB(IntMask, fldname##Mask##_0)), \
1193 .msg = #fldname "_P" }
1195 * Below generates "auto-message" for interrupts specific to a context,
1196 * with ctxt-number appended
1198 #define INTR_AUTO_C(fldname) { .mask = MASK_ACROSS(\
1199 SYM_LSB(IntMask, fldname##0IntMask), \
1200 SYM_LSB(IntMask, fldname##17IntMask)), \
1201 .msg = #fldname "_C"}
1203 static const struct qib_hwerror_msgs qib_7322_intr_msgs[] = {
1204 INTR_AUTO_P(SDmaInt),
1205 INTR_AUTO_P(SDmaProgressInt),
1206 INTR_AUTO_P(SDmaIdleInt),
1207 INTR_AUTO_P(SDmaCleanupDone),
1208 INTR_AUTO_C(RcvUrg),
1209 INTR_AUTO_P(ErrInt),
1210 INTR_AUTO(ErrInt), /* non-port-specific errs */
1211 INTR_AUTO(AssertGPIOInt),
1212 INTR_AUTO_P(SendDoneInt),
1213 INTR_AUTO(SendBufAvailInt),
1214 INTR_AUTO_C(RcvAvail),
1218 #define TXSYMPTOM_AUTO_P(fldname) \
1219 { .mask = SYM_MASK(SendHdrErrSymptom_0, fldname), .msg = #fldname }
1220 static const struct qib_hwerror_msgs hdrchk_msgs[] = {
1221 TXSYMPTOM_AUTO_P(NonKeyPacket),
1222 TXSYMPTOM_AUTO_P(GRHFail),
1223 TXSYMPTOM_AUTO_P(PkeyFail),
1224 TXSYMPTOM_AUTO_P(QPFail),
1225 TXSYMPTOM_AUTO_P(SLIDFail),
1226 TXSYMPTOM_AUTO_P(RawIPV6),
1227 TXSYMPTOM_AUTO_P(PacketTooSmall),
1231 #define IBA7322_HDRHEAD_PKTINT_SHIFT 32 /* interrupt cnt in upper 32 bits */
1234 * Called when we might have an error that is specific to a particular
1235 * PIO buffer, and may need to cancel that buffer, so it can be re-used,
1236 * because we don't need to force the update of pioavail
1238 static void qib_disarm_7322_senderrbufs(struct qib_pportdata *ppd)
1240 struct qib_devdata *dd = ppd->dd;
1243 u32 piobcnt = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
1244 u32 regcnt = (piobcnt + BITS_PER_LONG - 1) / BITS_PER_LONG;
1245 unsigned long sbuf[4];
1248 * It's possible that sendbuffererror could have bits set; might
1249 * have already done this as a result of hardware error handling.
1252 for (i = 0; i < regcnt; ++i) {
1253 sbuf[i] = qib_read_kreg64(dd, kr_sendbuffererror + i);
1256 qib_write_kreg(dd, kr_sendbuffererror + i, sbuf[i]);
1261 qib_disarm_piobufs_set(dd, sbuf, piobcnt);
1264 /* No txe_recover yet, if ever */
1266 /* No decode__errors yet */
1267 static void err_decode(char *msg, size_t len, u64 errs,
1268 const struct qib_hwerror_msgs *msp)
1271 int took, multi, n = 0;
1273 while (msp && msp->mask) {
1274 multi = (msp->mask & (msp->mask - 1));
1275 while (errs & msp->mask) {
1276 these = (errs & msp->mask);
1277 lmask = (these & (these - 1)) ^ these;
1280 /* separate the strings */
1284 took = scnprintf(msg, len, "%s", msp->msg);
1290 /* More than one bit this mask */
1293 while (lmask & msp->mask) {
1297 took = scnprintf(msg, len, "_%d", idx);
1304 /* If some bits are left, show in hex. */
1306 snprintf(msg, len, "%sMORE:%llX", n ? "," : "",
1307 (unsigned long long) errs);
1310 /* only called if r1 set */
1311 static void flush_fifo(struct qib_pportdata *ppd)
1313 struct qib_devdata *dd = ppd->dd;
1314 u32 __iomem *piobuf;
1318 const unsigned hdrwords = 7;
1319 static struct qib_ib_header ibhdr = {
1320 .lrh[0] = cpu_to_be16(0xF000 | QIB_LRH_BTH),
1321 .lrh[1] = IB_LID_PERMISSIVE,
1322 .lrh[2] = cpu_to_be16(hdrwords + SIZE_OF_CRC),
1323 .lrh[3] = IB_LID_PERMISSIVE,
1324 .u.oth.bth[0] = cpu_to_be32(
1325 (IB_OPCODE_UD_SEND_ONLY << 24) | QIB_DEFAULT_P_KEY),
1326 .u.oth.bth[1] = cpu_to_be32(0),
1327 .u.oth.bth[2] = cpu_to_be32(0),
1328 .u.oth.u.ud.deth[0] = cpu_to_be32(0),
1329 .u.oth.u.ud.deth[1] = cpu_to_be32(0),
1333 * Send a dummy VL15 packet to flush the launch FIFO.
1334 * This will not actually be sent since the TxeBypassIbc bit is set.
1336 pbc = PBC_7322_VL15_SEND |
1337 (((u64)ppd->hw_pidx) << (PBC_PORT_SEL_LSB + 32)) |
1338 (hdrwords + SIZE_OF_CRC);
1339 piobuf = qib_7322_getsendbuf(ppd, pbc, &bufn);
1342 writeq(pbc, piobuf);
1343 hdr = (u32 *) &ibhdr;
1344 if (dd->flags & QIB_PIO_FLUSH_WC) {
1346 qib_pio_copy(piobuf + 2, hdr, hdrwords - 1);
1348 __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords + 1);
1351 qib_pio_copy(piobuf + 2, hdr, hdrwords);
1352 qib_sendbuf_done(dd, bufn);
1356 * This is called with interrupts disabled and sdma_lock held.
1358 static void qib_7322_sdma_sendctrl(struct qib_pportdata *ppd, unsigned op)
1360 struct qib_devdata *dd = ppd->dd;
1361 u64 set_sendctrl = 0;
1362 u64 clr_sendctrl = 0;
1364 if (op & QIB_SDMA_SENDCTRL_OP_ENABLE)
1365 set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaEnable);
1367 clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaEnable);
1369 if (op & QIB_SDMA_SENDCTRL_OP_INTENABLE)
1370 set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaIntEnable);
1372 clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaIntEnable);
1374 if (op & QIB_SDMA_SENDCTRL_OP_HALT)
1375 set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaHalt);
1377 clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaHalt);
1379 if (op & QIB_SDMA_SENDCTRL_OP_DRAIN)
1380 set_sendctrl |= SYM_MASK(SendCtrl_0, TxeBypassIbc) |
1381 SYM_MASK(SendCtrl_0, TxeAbortIbc) |
1382 SYM_MASK(SendCtrl_0, TxeDrainRmFifo);
1384 clr_sendctrl |= SYM_MASK(SendCtrl_0, TxeBypassIbc) |
1385 SYM_MASK(SendCtrl_0, TxeAbortIbc) |
1386 SYM_MASK(SendCtrl_0, TxeDrainRmFifo);
1388 spin_lock(&dd->sendctrl_lock);
1390 /* If we are draining everything, block sends first */
1391 if (op & QIB_SDMA_SENDCTRL_OP_DRAIN) {
1392 ppd->p_sendctrl &= ~SYM_MASK(SendCtrl_0, SendEnable);
1393 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
1394 qib_write_kreg(dd, kr_scratch, 0);
1397 ppd->p_sendctrl |= set_sendctrl;
1398 ppd->p_sendctrl &= ~clr_sendctrl;
1400 if (op & QIB_SDMA_SENDCTRL_OP_CLEANUP)
1401 qib_write_kreg_port(ppd, krp_sendctrl,
1403 SYM_MASK(SendCtrl_0, SDmaCleanup));
1405 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
1406 qib_write_kreg(dd, kr_scratch, 0);
1408 if (op & QIB_SDMA_SENDCTRL_OP_DRAIN) {
1409 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, SendEnable);
1410 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
1411 qib_write_kreg(dd, kr_scratch, 0);
1414 spin_unlock(&dd->sendctrl_lock);
1416 if ((op & QIB_SDMA_SENDCTRL_OP_DRAIN) && ppd->dd->cspec->r1)
1420 static void qib_7322_sdma_hw_clean_up(struct qib_pportdata *ppd)
1422 __qib_sdma_process_event(ppd, qib_sdma_event_e50_hw_cleaned);
1425 static void qib_sdma_7322_setlengen(struct qib_pportdata *ppd)
1428 * Set SendDmaLenGen and clear and set
1429 * the MSB of the generation count to enable generation checking
1430 * and load the internal generation counter.
1432 qib_write_kreg_port(ppd, krp_senddmalengen, ppd->sdma_descq_cnt);
1433 qib_write_kreg_port(ppd, krp_senddmalengen,
1434 ppd->sdma_descq_cnt |
1435 (1ULL << QIB_7322_SendDmaLenGen_0_Generation_MSB));
1439 * Must be called with sdma_lock held, or before init finished.
1441 static void qib_sdma_update_7322_tail(struct qib_pportdata *ppd, u16 tail)
1443 /* Commit writes to memory and advance the tail on the chip */
1445 ppd->sdma_descq_tail = tail;
1446 qib_write_kreg_port(ppd, krp_senddmatail, tail);
1450 * This is called with interrupts disabled and sdma_lock held.
1452 static void qib_7322_sdma_hw_start_up(struct qib_pportdata *ppd)
1456 * The hardware doesn't require this but we do it so that verbs
1457 * and user applications don't wait for link active to send stale
1460 sendctrl_7322_mod(ppd, QIB_SENDCTRL_FLUSH);
1462 qib_sdma_7322_setlengen(ppd);
1463 qib_sdma_update_7322_tail(ppd, 0); /* Set SendDmaTail */
1464 ppd->sdma_head_dma[0] = 0;
1465 qib_7322_sdma_sendctrl(ppd,
1466 ppd->sdma_state.current_op | QIB_SDMA_SENDCTRL_OP_CLEANUP);
1469 #define DISABLES_SDMA ( \
1470 QIB_E_P_SDMAHALT | \
1471 QIB_E_P_SDMADESCADDRMISALIGN | \
1472 QIB_E_P_SDMAMISSINGDW | \
1473 QIB_E_P_SDMADWEN | \
1474 QIB_E_P_SDMARPYTAG | \
1475 QIB_E_P_SDMA1STDESC | \
1476 QIB_E_P_SDMABASE | \
1477 QIB_E_P_SDMATAILOUTOFBOUND | \
1478 QIB_E_P_SDMAOUTOFBOUND | \
1479 QIB_E_P_SDMAGENMISMATCH)
1481 static void sdma_7322_p_errors(struct qib_pportdata *ppd, u64 errs)
1483 unsigned long flags;
1484 struct qib_devdata *dd = ppd->dd;
1486 errs &= QIB_E_P_SDMAERRS;
1488 if (errs & QIB_E_P_SDMAUNEXPDATA)
1489 qib_dev_err(dd, "IB%u:%u SDmaUnexpData\n", dd->unit,
1492 spin_lock_irqsave(&ppd->sdma_lock, flags);
1494 switch (ppd->sdma_state.current_state) {
1495 case qib_sdma_state_s00_hw_down:
1498 case qib_sdma_state_s10_hw_start_up_wait:
1499 if (errs & QIB_E_P_SDMAHALT)
1500 __qib_sdma_process_event(ppd,
1501 qib_sdma_event_e20_hw_started);
1504 case qib_sdma_state_s20_idle:
1507 case qib_sdma_state_s30_sw_clean_up_wait:
1510 case qib_sdma_state_s40_hw_clean_up_wait:
1511 if (errs & QIB_E_P_SDMAHALT)
1512 __qib_sdma_process_event(ppd,
1513 qib_sdma_event_e50_hw_cleaned);
1516 case qib_sdma_state_s50_hw_halt_wait:
1517 if (errs & QIB_E_P_SDMAHALT)
1518 __qib_sdma_process_event(ppd,
1519 qib_sdma_event_e60_hw_halted);
1522 case qib_sdma_state_s99_running:
1523 __qib_sdma_process_event(ppd, qib_sdma_event_e7322_err_halted);
1524 __qib_sdma_process_event(ppd, qib_sdma_event_e60_hw_halted);
1528 spin_unlock_irqrestore(&ppd->sdma_lock, flags);
1532 * handle per-device errors (not per-port errors)
1534 static noinline void handle_7322_errors(struct qib_devdata *dd)
1542 qib_stats.sps_errints++;
1543 errs = qib_read_kreg64(dd, kr_errstatus);
1545 qib_devinfo(dd->pcidev, "device error interrupt, "
1546 "but no error bits set!\n");
1550 /* don't report errors that are masked */
1551 errs &= dd->cspec->errormask;
1552 msg = dd->cspec->emsgbuf;
1554 /* do these first, they are most important */
1555 if (errs & QIB_E_HARDWARE) {
1557 qib_7322_handle_hwerrors(dd, msg, sizeof dd->cspec->emsgbuf);
1559 for (log_idx = 0; log_idx < QIB_EEP_LOG_CNT; ++log_idx)
1560 if (errs & dd->eep_st_masks[log_idx].errs_to_log)
1561 qib_inc_eeprom_err(dd, log_idx, 1);
1563 if (errs & QIB_E_SPKTERRS) {
1564 qib_disarm_7322_senderrbufs(dd->pport);
1565 qib_stats.sps_txerrs++;
1566 } else if (errs & QIB_E_INVALIDADDR)
1567 qib_stats.sps_txerrs++;
1568 else if (errs & QIB_E_ARMLAUNCH) {
1569 qib_stats.sps_txerrs++;
1570 qib_disarm_7322_senderrbufs(dd->pport);
1572 qib_write_kreg(dd, kr_errclear, errs);
1575 * The ones we mask off are handled specially below
1576 * or above. Also mask SDMADISABLED by default as it
1579 mask = QIB_E_HARDWARE;
1582 err_decode(msg, sizeof dd->cspec->emsgbuf, errs & ~mask,
1583 qib_7322error_msgs);
1586 * Getting reset is a tragedy for all ports. Mark the device
1587 * _and_ the ports as "offline" in way meaningful to each.
1589 if (errs & QIB_E_RESET) {
1592 qib_dev_err(dd, "Got reset, requires re-init "
1593 "(unload and reload driver)\n");
1594 dd->flags &= ~QIB_INITTED; /* needs re-init */
1595 /* mark as having had error */
1596 *dd->devstatusp |= QIB_STATUS_HWERROR;
1597 for (pidx = 0; pidx < dd->num_pports; ++pidx)
1598 if (dd->pport[pidx].link_speed_supported)
1599 *dd->pport[pidx].statusp &= ~QIB_STATUS_IB_CONF;
1603 qib_dev_err(dd, "%s error\n", msg);
1606 * If there were hdrq or egrfull errors, wake up any processes
1607 * waiting in poll. We used to try to check which contexts had
1608 * the overflow, but given the cost of that and the chip reads
1609 * to support it, it's better to just wake everybody up if we
1610 * get an overflow; waiters can poll again if it's not them.
1612 if (errs & (ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr))) {
1613 qib_handle_urcv(dd, ~0U);
1614 if (errs & ERR_MASK(RcvEgrFullErr))
1615 qib_stats.sps_buffull++;
1617 qib_stats.sps_hdrfull++;
1624 static void reenable_chase(unsigned long opaque)
1626 struct qib_pportdata *ppd = (struct qib_pportdata *)opaque;
1628 ppd->cpspec->chase_timer.expires = 0;
1629 qib_set_ib_7322_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
1630 QLOGIC_IB_IBCC_LINKINITCMD_POLL);
1633 static void disable_chase(struct qib_pportdata *ppd, u64 tnow, u8 ibclt)
1635 ppd->cpspec->chase_end = 0;
1640 qib_set_ib_7322_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
1641 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
1642 ppd->cpspec->chase_timer.expires = jiffies + QIB_CHASE_DIS_TIME;
1643 add_timer(&ppd->cpspec->chase_timer);
1646 static void handle_serdes_issues(struct qib_pportdata *ppd, u64 ibcst)
1651 ibclt = (u8)SYM_FIELD(ibcst, IBCStatusA_0, LinkTrainingState);
1654 * Detect and handle the state chase issue, where we can
1655 * get stuck if we are unlucky on timing on both sides of
1656 * the link. If we are, we disable, set a timer, and
1660 case IB_7322_LT_STATE_CFGRCVFCFG:
1661 case IB_7322_LT_STATE_CFGWAITRMT:
1662 case IB_7322_LT_STATE_TXREVLANES:
1663 case IB_7322_LT_STATE_CFGENH:
1664 tnow = get_jiffies_64();
1665 if (ppd->cpspec->chase_end &&
1666 time_after64(tnow, ppd->cpspec->chase_end))
1667 disable_chase(ppd, tnow, ibclt);
1668 else if (!ppd->cpspec->chase_end)
1669 ppd->cpspec->chase_end = tnow + QIB_CHASE_TIME;
1672 ppd->cpspec->chase_end = 0;
1676 if (ibclt == IB_7322_LT_STATE_CFGTEST &&
1677 (ibcst & SYM_MASK(IBCStatusA_0, LinkSpeedQDR))) {
1679 ppd->cpspec->qdr_reforce = 1;
1680 } else if (ppd->cpspec->qdr_reforce &&
1681 (ibcst & SYM_MASK(IBCStatusA_0, LinkSpeedQDR)) &&
1682 (ibclt == IB_7322_LT_STATE_CFGENH ||
1683 ibclt == IB_7322_LT_STATE_CFGIDLE ||
1684 ibclt == IB_7322_LT_STATE_LINKUP))
1687 if ((IS_QMH(ppd->dd) || IS_QME(ppd->dd)) &&
1688 ppd->link_speed_enabled == QIB_IB_QDR &&
1689 (ibclt == IB_7322_LT_STATE_CFGTEST ||
1690 ibclt == IB_7322_LT_STATE_CFGENH ||
1691 (ibclt >= IB_7322_LT_STATE_POLLACTIVE &&
1692 ibclt <= IB_7322_LT_STATE_SLEEPQUIET)))
1695 if (!ppd->cpspec->qdr_dfe_on && ibclt != IB_7322_LT_STATE_LINKUP &&
1696 ibclt <= IB_7322_LT_STATE_SLEEPQUIET) {
1697 ppd->cpspec->qdr_dfe_on = 1;
1698 ppd->cpspec->qdr_dfe_time = 0;
1699 /* On link down, reenable QDR adaptation */
1700 qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
1701 ppd->dd->cspec->r1 ?
1702 QDR_STATIC_ADAPT_DOWN_R1 :
1703 QDR_STATIC_ADAPT_DOWN);
1708 * This is per-pport error handling.
1709 * will likely get it's own MSIx interrupt (one for each port,
1710 * although just a single handler).
1712 static noinline void handle_7322_p_errors(struct qib_pportdata *ppd)
1715 u64 ignore_this_time = 0, iserr = 0, errs, fmask;
1716 struct qib_devdata *dd = ppd->dd;
1718 /* do this as soon as possible */
1719 fmask = qib_read_kreg64(dd, kr_act_fmask);
1721 check_7322_rxe_status(ppd);
1723 errs = qib_read_kreg_port(ppd, krp_errstatus);
1725 qib_devinfo(dd->pcidev,
1726 "Port%d error interrupt, but no error bits set!\n",
1729 errs &= ~QIB_E_P_IBSTATUSCHANGED;
1733 msg = ppd->cpspec->epmsgbuf;
1736 if (errs & ~QIB_E_P_BITSEXTANT) {
1737 err_decode(msg, sizeof ppd->cpspec->epmsgbuf,
1738 errs & ~QIB_E_P_BITSEXTANT, qib_7322p_error_msgs);
1740 snprintf(msg, sizeof ppd->cpspec->epmsgbuf,
1742 qib_dev_porterr(dd, ppd->port, "error interrupt with unknown"
1743 " errors 0x%016Lx set (and %s)\n",
1744 (errs & ~QIB_E_P_BITSEXTANT), msg);
1748 if (errs & QIB_E_P_SHDR) {
1751 /* determine cause, then write to clear */
1752 symptom = qib_read_kreg_port(ppd, krp_sendhdrsymptom);
1753 qib_write_kreg_port(ppd, krp_sendhdrsymptom, 0);
1754 err_decode(msg, sizeof ppd->cpspec->epmsgbuf, symptom,
1757 /* senderrbuf cleared in SPKTERRS below */
1760 if (errs & QIB_E_P_SPKTERRS) {
1761 if ((errs & QIB_E_P_LINK_PKTERRS) &&
1762 !(ppd->lflags & QIBL_LINKACTIVE)) {
1764 * This can happen when trying to bring the link
1765 * up, but the IB link changes state at the "wrong"
1766 * time. The IB logic then complains that the packet
1767 * isn't valid. We don't want to confuse people, so
1768 * we just don't print them, except at debug
1770 err_decode(msg, sizeof ppd->cpspec->epmsgbuf,
1771 (errs & QIB_E_P_LINK_PKTERRS),
1772 qib_7322p_error_msgs);
1774 ignore_this_time = errs & QIB_E_P_LINK_PKTERRS;
1776 qib_disarm_7322_senderrbufs(ppd);
1777 } else if ((errs & QIB_E_P_LINK_PKTERRS) &&
1778 !(ppd->lflags & QIBL_LINKACTIVE)) {
1780 * This can happen when SMA is trying to bring the link
1781 * up, but the IB link changes state at the "wrong" time.
1782 * The IB logic then complains that the packet isn't
1783 * valid. We don't want to confuse people, so we just
1784 * don't print them, except at debug
1786 err_decode(msg, sizeof ppd->cpspec->epmsgbuf, errs,
1787 qib_7322p_error_msgs);
1788 ignore_this_time = errs & QIB_E_P_LINK_PKTERRS;
1792 qib_write_kreg_port(ppd, krp_errclear, errs);
1794 errs &= ~ignore_this_time;
1798 if (errs & QIB_E_P_RPKTERRS)
1799 qib_stats.sps_rcverrs++;
1800 if (errs & QIB_E_P_SPKTERRS)
1801 qib_stats.sps_txerrs++;
1803 iserr = errs & ~(QIB_E_P_RPKTERRS | QIB_E_P_PKTERRS);
1805 if (errs & QIB_E_P_SDMAERRS)
1806 sdma_7322_p_errors(ppd, errs);
1808 if (errs & QIB_E_P_IBSTATUSCHANGED) {
1812 ibcs = qib_read_kreg_port(ppd, krp_ibcstatus_a);
1813 ltstate = qib_7322_phys_portstate(ibcs);
1815 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
1816 handle_serdes_issues(ppd, ibcs);
1817 if (!(ppd->cpspec->ibcctrl_a &
1818 SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn))) {
1820 * We got our interrupt, so init code should be
1821 * happy and not try alternatives. Now squelch
1822 * other "chatter" from link-negotiation (pre Init)
1824 ppd->cpspec->ibcctrl_a |=
1825 SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
1826 qib_write_kreg_port(ppd, krp_ibcctrl_a,
1827 ppd->cpspec->ibcctrl_a);
1830 /* Update our picture of width and speed from chip */
1831 ppd->link_width_active =
1832 (ibcs & SYM_MASK(IBCStatusA_0, LinkWidthActive)) ?
1833 IB_WIDTH_4X : IB_WIDTH_1X;
1834 ppd->link_speed_active = (ibcs & SYM_MASK(IBCStatusA_0,
1835 LinkSpeedQDR)) ? QIB_IB_QDR : (ibcs &
1836 SYM_MASK(IBCStatusA_0, LinkSpeedActive)) ?
1837 QIB_IB_DDR : QIB_IB_SDR;
1839 if ((ppd->lflags & QIBL_IB_LINK_DISABLED) && ltstate !=
1840 IB_PHYSPORTSTATE_DISABLED)
1841 qib_set_ib_7322_lstate(ppd, 0,
1842 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
1845 * Since going into a recovery state causes the link
1846 * state to go down and since recovery is transitory,
1847 * it is better if we "miss" ever seeing the link
1848 * training state go into recovery (i.e., ignore this
1849 * transition for link state special handling purposes)
1850 * without updating lastibcstat.
1852 if (ltstate != IB_PHYSPORTSTATE_LINK_ERR_RECOVER &&
1853 ltstate != IB_PHYSPORTSTATE_RECOVERY_RETRAIN &&
1854 ltstate != IB_PHYSPORTSTATE_RECOVERY_WAITRMT &&
1855 ltstate != IB_PHYSPORTSTATE_RECOVERY_IDLE)
1856 qib_handle_e_ibstatuschanged(ppd, ibcs);
1859 qib_dev_porterr(dd, ppd->port, "%s error\n", msg);
1861 if (ppd->state_wanted & ppd->lflags)
1862 wake_up_interruptible(&ppd->state_wait);
1867 /* enable/disable chip from delivering interrupts */
1868 static void qib_7322_set_intr_state(struct qib_devdata *dd, u32 enable)
1871 if (dd->flags & QIB_BADINTR)
1873 qib_write_kreg(dd, kr_intmask, dd->cspec->int_enable_mask);
1874 /* cause any pending enabled interrupts to be re-delivered */
1875 qib_write_kreg(dd, kr_intclear, 0ULL);
1876 if (dd->cspec->num_msix_entries) {
1877 /* and same for MSIx */
1878 u64 val = qib_read_kreg64(dd, kr_intgranted);
1880 qib_write_kreg(dd, kr_intgranted, val);
1883 qib_write_kreg(dd, kr_intmask, 0ULL);
1887 * Try to cleanup as much as possible for anything that might have gone
1888 * wrong while in freeze mode, such as pio buffers being written by user
1889 * processes (causing armlaunch), send errors due to going into freeze mode,
1890 * etc., and try to avoid causing extra interrupts while doing so.
1891 * Forcibly update the in-memory pioavail register copies after cleanup
1892 * because the chip won't do it while in freeze mode (the register values
1893 * themselves are kept correct).
1894 * Make sure that we don't lose any important interrupts by using the chip
1895 * feature that says that writing 0 to a bit in *clear that is set in
1896 * *status will cause an interrupt to be generated again (if allowed by
1898 * This is in chip-specific code because of all of the register accesses,
1899 * even though the details are similar on most chips.
1901 static void qib_7322_clear_freeze(struct qib_devdata *dd)
1905 /* disable error interrupts, to avoid confusion */
1906 qib_write_kreg(dd, kr_errmask, 0ULL);
1908 for (pidx = 0; pidx < dd->num_pports; ++pidx)
1909 if (dd->pport[pidx].link_speed_supported)
1910 qib_write_kreg_port(dd->pport + pidx, krp_errmask,
1913 /* also disable interrupts; errormask is sometimes overwriten */
1914 qib_7322_set_intr_state(dd, 0);
1916 /* clear the freeze, and be sure chip saw it */
1917 qib_write_kreg(dd, kr_control, dd->control);
1918 qib_read_kreg32(dd, kr_scratch);
1921 * Force new interrupt if any hwerr, error or interrupt bits are
1922 * still set, and clear "safe" send packet errors related to freeze
1923 * and cancelling sends. Re-enable error interrupts before possible
1924 * force of re-interrupt on pending interrupts.
1926 qib_write_kreg(dd, kr_hwerrclear, 0ULL);
1927 qib_write_kreg(dd, kr_errclear, E_SPKT_ERRS_IGNORE);
1928 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
1929 /* We need to purge per-port errs and reset mask, too */
1930 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
1931 if (!dd->pport[pidx].link_speed_supported)
1933 qib_write_kreg_port(dd->pport + pidx, krp_errclear, ~0Ull);
1934 qib_write_kreg_port(dd->pport + pidx, krp_errmask, ~0Ull);
1936 qib_7322_set_intr_state(dd, 1);
1939 /* no error handling to speak of */
1941 * qib_7322_handle_hwerrors - display hardware errors.
1942 * @dd: the qlogic_ib device
1943 * @msg: the output buffer
1944 * @msgl: the size of the output buffer
1946 * Use same msg buffer as regular errors to avoid excessive stack
1947 * use. Most hardware errors are catastrophic, but for right now,
1948 * we'll print them and continue. We reuse the same message buffer as
1949 * qib_handle_errors() to avoid excessive stack usage.
1951 static void qib_7322_handle_hwerrors(struct qib_devdata *dd, char *msg,
1958 hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
1961 if (hwerrs == ~0ULL) {
1962 qib_dev_err(dd, "Read of hardware error status failed "
1963 "(all bits set); ignoring\n");
1966 qib_stats.sps_hwerrs++;
1968 /* Always clear the error status register, except BIST fail */
1969 qib_write_kreg(dd, kr_hwerrclear, hwerrs &
1970 ~HWE_MASK(PowerOnBISTFailed));
1972 hwerrs &= dd->cspec->hwerrmask;
1974 /* no EEPROM logging, yet */
1977 qib_devinfo(dd->pcidev, "Hardware error: hwerr=0x%llx "
1978 "(cleared)\n", (unsigned long long) hwerrs);
1980 ctrl = qib_read_kreg32(dd, kr_control);
1981 if ((ctrl & SYM_MASK(Control, FreezeMode)) && !dd->diag_client) {
1983 * No recovery yet...
1985 if ((hwerrs & ~HWE_MASK(LATriggered)) ||
1986 dd->cspec->stay_in_freeze) {
1988 * If any set that we aren't ignoring only make the
1989 * complaint once, in case it's stuck or recurring,
1990 * and we get here multiple times
1991 * Force link down, so switch knows, and
1992 * LEDs are turned off.
1994 if (dd->flags & QIB_INITTED)
1997 qib_7322_clear_freeze(dd);
2000 if (hwerrs & HWE_MASK(PowerOnBISTFailed)) {
2002 strlcpy(msg, "[Memory BIST test failed, "
2003 "InfiniPath hardware unusable]", msgl);
2004 /* ignore from now on, so disable until driver reloaded */
2005 dd->cspec->hwerrmask &= ~HWE_MASK(PowerOnBISTFailed);
2006 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
2009 err_decode(msg, msgl, hwerrs, qib_7322_hwerror_msgs);
2011 /* Ignore esoteric PLL failures et al. */
2013 qib_dev_err(dd, "%s hardware error\n", msg);
2015 if (isfatal && !dd->diag_client) {
2016 qib_dev_err(dd, "Fatal Hardware Error, no longer"
2017 " usable, SN %.16s\n", dd->serial);
2019 * for /sys status file and user programs to print; if no
2020 * trailing brace is copied, we'll know it was truncated.
2023 snprintf(dd->freezemsg, dd->freezelen,
2025 qib_disable_after_error(dd);
2031 * qib_7322_init_hwerrors - enable hardware errors
2032 * @dd: the qlogic_ib device
2034 * now that we have finished initializing everything that might reasonably
2035 * cause a hardware error, and cleared those errors bits as they occur,
2036 * we can enable hardware errors in the mask (potentially enabling
2037 * freeze mode), and enable hardware errors as errors (along with
2038 * everything else) in errormask
2040 static void qib_7322_init_hwerrors(struct qib_devdata *dd)
2045 extsval = qib_read_kreg64(dd, kr_extstatus);
2046 if (!(extsval & (QIB_EXTS_MEMBIST_DISABLED |
2047 QIB_EXTS_MEMBIST_ENDTEST)))
2048 qib_dev_err(dd, "MemBIST did not complete!\n");
2050 /* never clear BIST failure, so reported on each driver load */
2051 qib_write_kreg(dd, kr_hwerrclear, ~HWE_MASK(PowerOnBISTFailed));
2052 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
2055 qib_write_kreg(dd, kr_errclear, ~0ULL);
2056 /* enable errors that are masked, at least this first time. */
2057 qib_write_kreg(dd, kr_errmask, ~0ULL);
2058 dd->cspec->errormask = qib_read_kreg64(dd, kr_errmask);
2059 for (pidx = 0; pidx < dd->num_pports; ++pidx)
2060 if (dd->pport[pidx].link_speed_supported)
2061 qib_write_kreg_port(dd->pport + pidx, krp_errmask,
2066 * Disable and enable the armlaunch error. Used for PIO bandwidth testing
2067 * on chips that are count-based, rather than trigger-based. There is no
2068 * reference counting, but that's also fine, given the intended use.
2069 * Only chip-specific because it's all register accesses
2071 static void qib_set_7322_armlaunch(struct qib_devdata *dd, u32 enable)
2074 qib_write_kreg(dd, kr_errclear, QIB_E_SPIOARMLAUNCH);
2075 dd->cspec->errormask |= QIB_E_SPIOARMLAUNCH;
2077 dd->cspec->errormask &= ~QIB_E_SPIOARMLAUNCH;
2078 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
2082 * Formerly took parameter <which> in pre-shifted,
2083 * pre-merged form with LinkCmd and LinkInitCmd
2084 * together, and assuming the zero was NOP.
2086 static void qib_set_ib_7322_lstate(struct qib_pportdata *ppd, u16 linkcmd,
2090 struct qib_devdata *dd = ppd->dd;
2091 unsigned long flags;
2093 if (linitcmd == QLOGIC_IB_IBCC_LINKINITCMD_DISABLE) {
2095 * If we are told to disable, note that so link-recovery
2096 * code does not attempt to bring us back up.
2097 * Also reset everything that we can, so we start
2098 * completely clean when re-enabled (before we
2099 * actually issue the disable to the IBC)
2101 qib_7322_mini_pcs_reset(ppd);
2102 spin_lock_irqsave(&ppd->lflags_lock, flags);
2103 ppd->lflags |= QIBL_IB_LINK_DISABLED;
2104 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
2105 } else if (linitcmd || linkcmd == QLOGIC_IB_IBCC_LINKCMD_DOWN) {
2107 * Any other linkinitcmd will lead to LINKDOWN and then
2108 * to INIT (if all is well), so clear flag to let
2109 * link-recovery code attempt to bring us back up.
2111 spin_lock_irqsave(&ppd->lflags_lock, flags);
2112 ppd->lflags &= ~QIBL_IB_LINK_DISABLED;
2113 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
2115 * Clear status change interrupt reduction so the
2116 * new state is seen.
2118 ppd->cpspec->ibcctrl_a &=
2119 ~SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
2122 mod_wd = (linkcmd << IBA7322_IBCC_LINKCMD_SHIFT) |
2123 (linitcmd << QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
2125 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a |
2127 /* write to chip to prevent back-to-back writes of ibc reg */
2128 qib_write_kreg(dd, kr_scratch, 0);
2133 * The total RCV buffer memory is 64KB, used for both ports, and is
2134 * in units of 64 bytes (same as IB flow control credit unit).
2135 * The consumedVL unit in the same registers are in 32 byte units!
2136 * So, a VL15 packet needs 4.50 IB credits, and 9 rx buffer chunks,
2137 * and we can therefore allocate just 9 IB credits for 2 VL15 packets
2138 * in krp_rxcreditvl15, rather than 10.
2140 #define RCV_BUF_UNITSZ 64
2141 #define NUM_RCV_BUF_UNITS(dd) ((64 * 1024) / (RCV_BUF_UNITSZ * dd->num_pports))
2143 static void set_vls(struct qib_pportdata *ppd)
2145 int i, numvls, totcred, cred_vl, vl0extra;
2146 struct qib_devdata *dd = ppd->dd;
2149 numvls = qib_num_vls(ppd->vls_operational);
2152 * Set up per-VL credits. Below is kluge based on these assumptions:
2153 * 1) port is disabled at the time early_init is called.
2154 * 2) give VL15 17 credits, for two max-plausible packets.
2155 * 3) Give VL0-N the rest, with any rounding excess used for VL0
2157 /* 2 VL15 packets @ 288 bytes each (including IB headers) */
2158 totcred = NUM_RCV_BUF_UNITS(dd);
2159 cred_vl = (2 * 288 + RCV_BUF_UNITSZ - 1) / RCV_BUF_UNITSZ;
2161 qib_write_kreg_port(ppd, krp_rxcreditvl15, (u64) cred_vl);
2162 cred_vl = totcred / numvls;
2163 vl0extra = totcred - cred_vl * numvls;
2164 qib_write_kreg_port(ppd, krp_rxcreditvl0, cred_vl + vl0extra);
2165 for (i = 1; i < numvls; i++)
2166 qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, cred_vl);
2167 for (; i < 8; i++) /* no buffer space for other VLs */
2168 qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, 0);
2170 /* Notify IBC that credits need to be recalculated */
2171 val = qib_read_kreg_port(ppd, krp_ibsdtestiftx);
2172 val |= SYM_MASK(IB_SDTEST_IF_TX_0, CREDIT_CHANGE);
2173 qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
2174 qib_write_kreg(dd, kr_scratch, 0ULL);
2175 val &= ~SYM_MASK(IB_SDTEST_IF_TX_0, CREDIT_CHANGE);
2176 qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
2178 for (i = 0; i < numvls; i++)
2179 val = qib_read_kreg_port(ppd, krp_rxcreditvl0 + i);
2180 val = qib_read_kreg_port(ppd, krp_rxcreditvl15);
2182 /* Change the number of operational VLs */
2183 ppd->cpspec->ibcctrl_a = (ppd->cpspec->ibcctrl_a &
2184 ~SYM_MASK(IBCCtrlA_0, NumVLane)) |
2185 ((u64)(numvls - 1) << SYM_LSB(IBCCtrlA_0, NumVLane));
2186 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
2187 qib_write_kreg(dd, kr_scratch, 0ULL);
2191 * The code that deals with actual SerDes is in serdes_7322_init().
2192 * Compared to the code for iba7220, it is minimal.
2194 static int serdes_7322_init(struct qib_pportdata *ppd);
2197 * qib_7322_bringup_serdes - bring up the serdes
2198 * @ppd: physical port on the qlogic_ib device
2200 static int qib_7322_bringup_serdes(struct qib_pportdata *ppd)
2202 struct qib_devdata *dd = ppd->dd;
2204 unsigned long flags;
2208 * SerDes model not in Pd, but still need to
2209 * set up much of IBCCtrl and IBCDDRCtrl; move elsewhere
2212 /* Put IBC in reset, sends disabled (should be in reset already) */
2213 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, IBLinkEn);
2214 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
2215 qib_write_kreg(dd, kr_scratch, 0ULL);
2217 if (qib_compat_ddr_negotiate) {
2218 ppd->cpspec->ibdeltainprog = 1;
2219 ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
2221 ppd->cpspec->iblnkerrsnap = read_7322_creg32_port(ppd,
2222 crp_iblinkerrrecov);
2225 /* flowcontrolwatermark is in units of KBytes */
2226 ibc = 0x5ULL << SYM_LSB(IBCCtrlA_0, FlowCtrlWaterMark);
2228 * Flow control is sent this often, even if no changes in
2229 * buffer space occur. Units are 128ns for this chip.
2232 ibc |= 24ULL << SYM_LSB(IBCCtrlA_0, FlowCtrlPeriod);
2233 /* max error tolerance */
2234 ibc |= 0xfULL << SYM_LSB(IBCCtrlA_0, PhyerrThreshold);
2235 /* IB credit flow control. */
2236 ibc |= 0xfULL << SYM_LSB(IBCCtrlA_0, OverrunThreshold);
2238 * set initial max size pkt IBC will send, including ICRC; it's the
2239 * PIO buffer size in dwords, less 1; also see qib_set_mtu()
2241 ibc |= ((u64)(ppd->ibmaxlen >> 2) + 1) <<
2242 SYM_LSB(IBCCtrlA_0, MaxPktLen);
2243 ppd->cpspec->ibcctrl_a = ibc; /* without linkcmd or linkinitcmd! */
2245 /* initially come up waiting for TS1, without sending anything. */
2246 val = ppd->cpspec->ibcctrl_a | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
2247 QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
2250 * Reset the PCS interface to the serdes (and also ibc, which is still
2251 * in reset from above). Writes new value of ibcctrl_a as last step.
2253 qib_7322_mini_pcs_reset(ppd);
2254 qib_write_kreg(dd, kr_scratch, 0ULL);
2256 if (!ppd->cpspec->ibcctrl_b) {
2257 unsigned lse = ppd->link_speed_enabled;
2260 * Not on re-init after reset, establish shadow
2261 * and force initial config.
2263 ppd->cpspec->ibcctrl_b = qib_read_kreg_port(ppd,
2265 ppd->cpspec->ibcctrl_b &= ~(IBA7322_IBC_SPEED_QDR |
2266 IBA7322_IBC_SPEED_DDR |
2267 IBA7322_IBC_SPEED_SDR |
2268 IBA7322_IBC_WIDTH_AUTONEG |
2269 SYM_MASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED));
2270 if (lse & (lse - 1)) /* Muliple speeds enabled */
2271 ppd->cpspec->ibcctrl_b |=
2272 (lse << IBA7322_IBC_SPEED_LSB) |
2273 IBA7322_IBC_IBTA_1_2_MASK |
2274 IBA7322_IBC_MAX_SPEED_MASK;
2276 ppd->cpspec->ibcctrl_b |= (lse == QIB_IB_QDR) ?
2277 IBA7322_IBC_SPEED_QDR |
2278 IBA7322_IBC_IBTA_1_2_MASK :
2279 (lse == QIB_IB_DDR) ?
2280 IBA7322_IBC_SPEED_DDR :
2281 IBA7322_IBC_SPEED_SDR;
2282 if ((ppd->link_width_enabled & (IB_WIDTH_1X | IB_WIDTH_4X)) ==
2283 (IB_WIDTH_1X | IB_WIDTH_4X))
2284 ppd->cpspec->ibcctrl_b |= IBA7322_IBC_WIDTH_AUTONEG;
2286 ppd->cpspec->ibcctrl_b |=
2287 ppd->link_width_enabled == IB_WIDTH_4X ?
2288 IBA7322_IBC_WIDTH_4X_ONLY :
2289 IBA7322_IBC_WIDTH_1X_ONLY;
2291 /* always enable these on driver reload, not sticky */
2292 ppd->cpspec->ibcctrl_b |= (IBA7322_IBC_RXPOL_MASK |
2293 IBA7322_IBC_HRTBT_MASK);
2295 qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
2297 /* setup so we have more time at CFGTEST to change H1 */
2298 val = qib_read_kreg_port(ppd, krp_ibcctrl_c);
2299 val &= ~SYM_MASK(IBCCtrlC_0, IB_FRONT_PORCH);
2300 val |= 0xfULL << SYM_LSB(IBCCtrlC_0, IB_FRONT_PORCH);
2301 qib_write_kreg_port(ppd, krp_ibcctrl_c, val);
2303 serdes_7322_init(ppd);
2305 guid = be64_to_cpu(ppd->guid);
2308 guid = be64_to_cpu(dd->base_guid) + ppd->port - 1;
2309 ppd->guid = cpu_to_be64(guid);
2312 qib_write_kreg_port(ppd, krp_hrtbt_guid, guid);
2313 /* write to chip to prevent back-to-back writes of ibc reg */
2314 qib_write_kreg(dd, kr_scratch, 0);
2317 ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0, IBLinkEn);
2320 /* be paranoid against later code motion, etc. */
2321 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
2322 ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvIBPortEnable);
2323 qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
2324 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
2326 /* Also enable IBSTATUSCHG interrupt. */
2327 val = qib_read_kreg_port(ppd, krp_errmask);
2328 qib_write_kreg_port(ppd, krp_errmask,
2329 val | ERR_MASK_N(IBStatusChanged));
2331 /* Always zero until we start messing with SerDes for real */
2336 * qib_7322_quiet_serdes - set serdes to txidle
2337 * @dd: the qlogic_ib device
2338 * Called when driver is being unloaded
2340 static void qib_7322_mini_quiet_serdes(struct qib_pportdata *ppd)
2343 unsigned long flags;
2345 qib_set_ib_7322_lstate(ppd, 0, QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
2347 spin_lock_irqsave(&ppd->lflags_lock, flags);
2348 ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
2349 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
2350 wake_up(&ppd->cpspec->autoneg_wait);
2351 cancel_delayed_work(&ppd->cpspec->autoneg_work);
2352 if (ppd->dd->cspec->r1)
2353 cancel_delayed_work(&ppd->cpspec->ipg_work);
2354 flush_scheduled_work();
2356 ppd->cpspec->chase_end = 0;
2357 if (ppd->cpspec->chase_timer.data) /* if initted */
2358 del_timer_sync(&ppd->cpspec->chase_timer);
2361 * Despite the name, actually disables IBC as well. Do it when
2362 * we are as sure as possible that no more packets can be
2363 * received, following the down and the PCS reset.
2364 * The actual disabling happens in qib_7322_mini_pci_reset(),
2365 * along with the PCS being reset.
2367 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, IBLinkEn);
2368 qib_7322_mini_pcs_reset(ppd);
2371 * Update the adjusted counters so the adjustment persists
2372 * across driver reload.
2374 if (ppd->cpspec->ibsymdelta || ppd->cpspec->iblnkerrdelta ||
2375 ppd->cpspec->ibdeltainprog || ppd->cpspec->iblnkdowndelta) {
2376 struct qib_devdata *dd = ppd->dd;
2379 /* enable counter writes */
2380 diagc = qib_read_kreg64(dd, kr_hwdiagctrl);
2381 qib_write_kreg(dd, kr_hwdiagctrl,
2382 diagc | SYM_MASK(HwDiagCtrl, CounterWrEnable));
2384 if (ppd->cpspec->ibsymdelta || ppd->cpspec->ibdeltainprog) {
2385 val = read_7322_creg32_port(ppd, crp_ibsymbolerr);
2386 if (ppd->cpspec->ibdeltainprog)
2387 val -= val - ppd->cpspec->ibsymsnap;
2388 val -= ppd->cpspec->ibsymdelta;
2389 write_7322_creg_port(ppd, crp_ibsymbolerr, val);
2391 if (ppd->cpspec->iblnkerrdelta || ppd->cpspec->ibdeltainprog) {
2392 val = read_7322_creg32_port(ppd, crp_iblinkerrrecov);
2393 if (ppd->cpspec->ibdeltainprog)
2394 val -= val - ppd->cpspec->iblnkerrsnap;
2395 val -= ppd->cpspec->iblnkerrdelta;
2396 write_7322_creg_port(ppd, crp_iblinkerrrecov, val);
2398 if (ppd->cpspec->iblnkdowndelta) {
2399 val = read_7322_creg32_port(ppd, crp_iblinkdown);
2400 val += ppd->cpspec->iblnkdowndelta;
2401 write_7322_creg_port(ppd, crp_iblinkdown, val);
2404 * No need to save ibmalfdelta since IB perfcounters
2405 * are cleared on driver reload.
2408 /* and disable counter writes */
2409 qib_write_kreg(dd, kr_hwdiagctrl, diagc);
2414 * qib_setup_7322_setextled - set the state of the two external LEDs
2415 * @ppd: physical port on the qlogic_ib device
2416 * @on: whether the link is up or not
2418 * The exact combo of LEDs if on is true is determined by looking
2421 * These LEDs indicate the physical and logical state of IB link.
2422 * For this chip (at least with recommended board pinouts), LED1
2423 * is Yellow (logical state) and LED2 is Green (physical state),
2425 * Note: We try to match the Mellanox HCA LED behavior as best
2426 * we can. Green indicates physical link state is OK (something is
2427 * plugged in, and we can train).
2428 * Amber indicates the link is logically up (ACTIVE).
2429 * Mellanox further blinks the amber LED to indicate data packet
2430 * activity, but we have no hardware support for that, so it would
2431 * require waking up every 10-20 msecs and checking the counters
2432 * on the chip, and then turning the LED off if appropriate. That's
2433 * visible overhead, so not something we will do.
2435 static void qib_setup_7322_setextled(struct qib_pportdata *ppd, u32 on)
2437 struct qib_devdata *dd = ppd->dd;
2438 u64 extctl, ledblink = 0, val;
2439 unsigned long flags;
2443 * The diags use the LED to indicate diag info, so we leave
2444 * the external LED alone when the diags are running.
2446 if (dd->diag_client)
2449 /* Allow override of LED display for, e.g. Locating system in rack */
2450 if (ppd->led_override) {
2451 grn = (ppd->led_override & QIB_LED_PHYS);
2452 yel = (ppd->led_override & QIB_LED_LOG);
2454 val = qib_read_kreg_port(ppd, krp_ibcstatus_a);
2455 grn = qib_7322_phys_portstate(val) ==
2456 IB_PHYSPORTSTATE_LINKUP;
2457 yel = qib_7322_iblink_state(val) == IB_PORT_ACTIVE;
2463 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
2464 extctl = dd->cspec->extctrl & (ppd->port == 1 ?
2465 ~ExtLED_IB1_MASK : ~ExtLED_IB2_MASK);
2467 extctl |= ppd->port == 1 ? ExtLED_IB1_GRN : ExtLED_IB2_GRN;
2469 * Counts are in chip clock (4ns) periods.
2470 * This is 1/16 sec (66.6ms) on,
2471 * 3/16 sec (187.5 ms) off, with packets rcvd.
2473 ledblink = ((66600 * 1000UL / 4) << IBA7322_LEDBLINK_ON_SHIFT) |
2474 ((187500 * 1000UL / 4) << IBA7322_LEDBLINK_OFF_SHIFT);
2477 extctl |= ppd->port == 1 ? ExtLED_IB1_YEL : ExtLED_IB2_YEL;
2478 dd->cspec->extctrl = extctl;
2479 qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
2480 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
2482 if (ledblink) /* blink the LED on packet receive */
2483 qib_write_kreg_port(ppd, krp_rcvpktledcnt, ledblink);
2487 * Disable MSIx interrupt if enabled, call generic MSIx code
2488 * to cleanup, and clear pending MSIx interrupts.
2489 * Used for fallback to INTx, after reset, and when MSIx setup fails.
2491 static void qib_7322_nomsix(struct qib_devdata *dd)
2496 dd->cspec->main_int_mask = ~0ULL;
2497 n = dd->cspec->num_msix_entries;
2501 dd->cspec->num_msix_entries = 0;
2502 for (i = 0; i < n; i++)
2503 free_irq(dd->cspec->msix_entries[i].vector,
2504 dd->cspec->msix_arg[i]);
2507 /* make sure no MSIx interrupts are left pending */
2508 intgranted = qib_read_kreg64(dd, kr_intgranted);
2510 qib_write_kreg(dd, kr_intgranted, intgranted);
2513 static void qib_7322_free_irq(struct qib_devdata *dd)
2515 if (dd->cspec->irq) {
2516 free_irq(dd->cspec->irq, dd);
2519 qib_7322_nomsix(dd);
2522 static void qib_setup_7322_cleanup(struct qib_devdata *dd)
2526 qib_7322_free_irq(dd);
2527 kfree(dd->cspec->cntrs);
2528 kfree(dd->cspec->sendchkenable);
2529 kfree(dd->cspec->sendgrhchk);
2530 kfree(dd->cspec->sendibchk);
2531 kfree(dd->cspec->msix_entries);
2532 kfree(dd->cspec->msix_arg);
2533 for (i = 0; i < dd->num_pports; i++) {
2534 unsigned long flags;
2535 u32 mask = QSFP_GPIO_MOD_PRS_N |
2536 (QSFP_GPIO_MOD_PRS_N << QSFP_GPIO_PORT2_SHIFT);
2538 kfree(dd->pport[i].cpspec->portcntrs);
2539 if (dd->flags & QIB_HAS_QSFP) {
2540 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
2541 dd->cspec->gpio_mask &= ~mask;
2542 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
2543 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
2544 qib_qsfp_deinit(&dd->pport[i].cpspec->qsfp_data);
2546 if (dd->pport[i].ibport_data.smi_ah)
2547 ib_destroy_ah(&dd->pport[i].ibport_data.smi_ah->ibah);
2551 /* handle SDMA interrupts */
2552 static void sdma_7322_intr(struct qib_devdata *dd, u64 istat)
2554 struct qib_pportdata *ppd0 = &dd->pport[0];
2555 struct qib_pportdata *ppd1 = &dd->pport[1];
2556 u64 intr0 = istat & (INT_MASK_P(SDma, 0) |
2557 INT_MASK_P(SDmaIdle, 0) | INT_MASK_P(SDmaProgress, 0));
2558 u64 intr1 = istat & (INT_MASK_P(SDma, 1) |
2559 INT_MASK_P(SDmaIdle, 1) | INT_MASK_P(SDmaProgress, 1));
2562 qib_sdma_intr(ppd0);
2564 qib_sdma_intr(ppd1);
2566 if (istat & INT_MASK_PM(SDmaCleanupDone, 0))
2567 qib_sdma_process_event(ppd0, qib_sdma_event_e20_hw_started);
2568 if (istat & INT_MASK_PM(SDmaCleanupDone, 1))
2569 qib_sdma_process_event(ppd1, qib_sdma_event_e20_hw_started);
2573 * Set or clear the Send buffer available interrupt enable bit.
2575 static void qib_wantpiobuf_7322_intr(struct qib_devdata *dd, u32 needint)
2577 unsigned long flags;
2579 spin_lock_irqsave(&dd->sendctrl_lock, flags);
2581 dd->sendctrl |= SYM_MASK(SendCtrl, SendIntBufAvail);
2583 dd->sendctrl &= ~SYM_MASK(SendCtrl, SendIntBufAvail);
2584 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
2585 qib_write_kreg(dd, kr_scratch, 0ULL);
2586 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
2590 * Somehow got an interrupt with reserved bits set in interrupt status.
2591 * Print a message so we know it happened, then clear them.
2592 * keep mainline interrupt handler cache-friendly
2594 static noinline void unknown_7322_ibits(struct qib_devdata *dd, u64 istat)
2599 kills = istat & ~QIB_I_BITSEXTANT;
2600 qib_dev_err(dd, "Clearing reserved interrupt(s) 0x%016llx:"
2601 " %s\n", (unsigned long long) kills, msg);
2602 qib_write_kreg(dd, kr_intmask, (dd->cspec->int_enable_mask & ~kills));
2605 /* keep mainline interrupt handler cache-friendly */
2606 static noinline void unknown_7322_gpio_intr(struct qib_devdata *dd)
2613 * Boards for this chip currently don't use GPIO interrupts,
2614 * so clear by writing GPIOstatus to GPIOclear, and complain
2615 * to developer. To avoid endless repeats, clear
2616 * the bits in the mask, since there is some kind of
2617 * programming error or chip problem.
2619 gpiostatus = qib_read_kreg32(dd, kr_gpio_status);
2621 * In theory, writing GPIOstatus to GPIOclear could
2622 * have a bad side-effect on some diagnostic that wanted
2623 * to poll for a status-change, but the various shadows
2624 * make that problematic at best. Diags will just suppress
2625 * all GPIO interrupts during such tests.
2627 qib_write_kreg(dd, kr_gpio_clear, gpiostatus);
2629 * Check for QSFP MOD_PRS changes
2630 * only works for single port if IB1 != pidx1
2632 for (pidx = 0; pidx < dd->num_pports && (dd->flags & QIB_HAS_QSFP);
2634 struct qib_pportdata *ppd;
2635 struct qib_qsfp_data *qd;
2637 if (!dd->pport[pidx].link_speed_supported)
2639 mask = QSFP_GPIO_MOD_PRS_N;
2640 ppd = dd->pport + pidx;
2641 mask <<= (QSFP_GPIO_PORT2_SHIFT * ppd->hw_pidx);
2642 if (gpiostatus & dd->cspec->gpio_mask & mask) {
2644 qd = &ppd->cpspec->qsfp_data;
2645 gpiostatus &= ~mask;
2646 pins = qib_read_kreg64(dd, kr_extstatus);
2647 pins >>= SYM_LSB(EXTStatus, GPIOIn);
2648 if (!(pins & mask)) {
2650 qd->t_insert = get_jiffies_64();
2651 schedule_work(&qd->work);
2656 if (gpiostatus && !handled) {
2657 const u32 mask = qib_read_kreg32(dd, kr_gpio_mask);
2658 u32 gpio_irq = mask & gpiostatus;
2661 * Clear any troublemakers, and update chip from shadow
2663 dd->cspec->gpio_mask &= ~gpio_irq;
2664 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
2669 * Handle errors and unusual events first, separate function
2670 * to improve cache hits for fast path interrupt handling.
2672 static noinline void unlikely_7322_intr(struct qib_devdata *dd, u64 istat)
2674 if (istat & ~QIB_I_BITSEXTANT)
2675 unknown_7322_ibits(dd, istat);
2676 if (istat & QIB_I_GPIO)
2677 unknown_7322_gpio_intr(dd);
2678 if (istat & QIB_I_C_ERROR)
2679 handle_7322_errors(dd);
2680 if (istat & INT_MASK_P(Err, 0) && dd->rcd[0])
2681 handle_7322_p_errors(dd->rcd[0]->ppd);
2682 if (istat & INT_MASK_P(Err, 1) && dd->rcd[1])
2683 handle_7322_p_errors(dd->rcd[1]->ppd);
2687 * Dynamically adjust the rcv int timeout for a context based on incoming
2690 static void adjust_rcv_timeout(struct qib_ctxtdata *rcd, int npkts)
2692 struct qib_devdata *dd = rcd->dd;
2693 u32 timeout = dd->cspec->rcvavail_timeout[rcd->ctxt];
2696 * Dynamically adjust idle timeout on chip
2697 * based on number of packets processed.
2699 if (npkts < rcv_int_count && timeout > 2)
2701 else if (npkts >= rcv_int_count && timeout < rcv_int_timeout)
2702 timeout = min(timeout << 1, rcv_int_timeout);
2706 dd->cspec->rcvavail_timeout[rcd->ctxt] = timeout;
2707 qib_write_kreg(dd, kr_rcvavailtimeout + rcd->ctxt, timeout);
2711 * This is the main interrupt handler.
2712 * It will normally only be used for low frequency interrupts but may
2713 * have to handle all interrupts if INTx is enabled or fewer than normal
2714 * MSIx interrupts were allocated.
2715 * This routine should ignore the interrupt bits for any of the
2716 * dedicated MSIx handlers.
2718 static irqreturn_t qib_7322intr(int irq, void *data)
2720 struct qib_devdata *dd = data;
2728 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT) {
2730 * This return value is not great, but we do not want the
2731 * interrupt core code to remove our interrupt handler
2732 * because we don't appear to be handling an interrupt
2733 * during a chip reset.
2739 istat = qib_read_kreg64(dd, kr_intstatus);
2741 if (unlikely(istat == ~0ULL)) {
2742 qib_bad_intrstatus(dd);
2743 qib_dev_err(dd, "Interrupt status all f's, skipping\n");
2744 /* don't know if it was our interrupt or not */
2749 istat &= dd->cspec->main_int_mask;
2750 if (unlikely(!istat)) {
2751 /* already handled, or shared and not us */
2756 qib_stats.sps_ints++;
2757 if (dd->int_counter != (u32) -1)
2760 /* handle "errors" of various kinds first, device ahead of port */
2761 if (unlikely(istat & (~QIB_I_BITSEXTANT | QIB_I_GPIO |
2762 QIB_I_C_ERROR | INT_MASK_P(Err, 0) |
2763 INT_MASK_P(Err, 1))))
2764 unlikely_7322_intr(dd, istat);
2767 * Clear the interrupt bits we found set, relatively early, so we
2768 * "know" know the chip will have seen this by the time we process
2769 * the queue, and will re-interrupt if necessary. The processor
2770 * itself won't take the interrupt again until we return.
2772 qib_write_kreg(dd, kr_intclear, istat);
2775 * Handle kernel receive queues before checking for pio buffers
2776 * available since receives can overflow; piobuf waiters can afford
2777 * a few extra cycles, since they were waiting anyway.
2779 ctxtrbits = istat & (QIB_I_RCVAVAIL_MASK | QIB_I_RCVURG_MASK);
2781 rmask = (1ULL << QIB_I_RCVAVAIL_LSB) |
2782 (1ULL << QIB_I_RCVURG_LSB);
2783 for (i = 0; i < dd->first_user_ctxt; i++) {
2784 if (ctxtrbits & rmask) {
2785 ctxtrbits &= ~rmask;
2787 qib_kreceive(dd->rcd[i], NULL, &npkts);
2788 adjust_rcv_timeout(dd->rcd[i], npkts);
2794 ctxtrbits = (ctxtrbits >> QIB_I_RCVAVAIL_LSB) |
2795 (ctxtrbits >> QIB_I_RCVURG_LSB);
2796 qib_handle_urcv(dd, ctxtrbits);
2800 if (istat & (QIB_I_P_SDMAINT(0) | QIB_I_P_SDMAINT(1)))
2801 sdma_7322_intr(dd, istat);
2803 if ((istat & QIB_I_SPIOBUFAVAIL) && (dd->flags & QIB_INITTED))
2804 qib_ib_piobufavail(dd);
2812 * Dedicated receive packet available interrupt handler.
2814 static irqreturn_t qib_7322pintr(int irq, void *data)
2816 struct qib_ctxtdata *rcd = data;
2817 struct qib_devdata *dd = rcd->dd;
2820 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
2822 * This return value is not great, but we do not want the
2823 * interrupt core code to remove our interrupt handler
2824 * because we don't appear to be handling an interrupt
2825 * during a chip reset.
2829 qib_stats.sps_ints++;
2830 if (dd->int_counter != (u32) -1)
2833 /* Clear the interrupt bit we expect to be set. */
2834 qib_write_kreg(dd, kr_intclear, ((1ULL << QIB_I_RCVAVAIL_LSB) |
2835 (1ULL << QIB_I_RCVURG_LSB)) << rcd->ctxt);
2837 qib_kreceive(rcd, NULL, &npkts);
2838 adjust_rcv_timeout(rcd, npkts);
2844 * Dedicated Send buffer available interrupt handler.
2846 static irqreturn_t qib_7322bufavail(int irq, void *data)
2848 struct qib_devdata *dd = data;
2850 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
2852 * This return value is not great, but we do not want the
2853 * interrupt core code to remove our interrupt handler
2854 * because we don't appear to be handling an interrupt
2855 * during a chip reset.
2859 qib_stats.sps_ints++;
2860 if (dd->int_counter != (u32) -1)
2863 /* Clear the interrupt bit we expect to be set. */
2864 qib_write_kreg(dd, kr_intclear, QIB_I_SPIOBUFAVAIL);
2866 /* qib_ib_piobufavail() will clear the want PIO interrupt if needed */
2867 if (dd->flags & QIB_INITTED)
2868 qib_ib_piobufavail(dd);
2870 qib_wantpiobuf_7322_intr(dd, 0);
2876 * Dedicated Send DMA interrupt handler.
2878 static irqreturn_t sdma_intr(int irq, void *data)
2880 struct qib_pportdata *ppd = data;
2881 struct qib_devdata *dd = ppd->dd;
2883 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
2885 * This return value is not great, but we do not want the
2886 * interrupt core code to remove our interrupt handler
2887 * because we don't appear to be handling an interrupt
2888 * during a chip reset.
2892 qib_stats.sps_ints++;
2893 if (dd->int_counter != (u32) -1)
2896 /* Clear the interrupt bit we expect to be set. */
2897 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
2898 INT_MASK_P(SDma, 1) : INT_MASK_P(SDma, 0));
2905 * Dedicated Send DMA idle interrupt handler.
2907 static irqreturn_t sdma_idle_intr(int irq, void *data)
2909 struct qib_pportdata *ppd = data;
2910 struct qib_devdata *dd = ppd->dd;
2912 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
2914 * This return value is not great, but we do not want the
2915 * interrupt core code to remove our interrupt handler
2916 * because we don't appear to be handling an interrupt
2917 * during a chip reset.
2921 qib_stats.sps_ints++;
2922 if (dd->int_counter != (u32) -1)
2925 /* Clear the interrupt bit we expect to be set. */
2926 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
2927 INT_MASK_P(SDmaIdle, 1) : INT_MASK_P(SDmaIdle, 0));
2934 * Dedicated Send DMA progress interrupt handler.
2936 static irqreturn_t sdma_progress_intr(int irq, void *data)
2938 struct qib_pportdata *ppd = data;
2939 struct qib_devdata *dd = ppd->dd;
2941 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
2943 * This return value is not great, but we do not want the
2944 * interrupt core code to remove our interrupt handler
2945 * because we don't appear to be handling an interrupt
2946 * during a chip reset.
2950 qib_stats.sps_ints++;
2951 if (dd->int_counter != (u32) -1)
2954 /* Clear the interrupt bit we expect to be set. */
2955 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
2956 INT_MASK_P(SDmaProgress, 1) :
2957 INT_MASK_P(SDmaProgress, 0));
2964 * Dedicated Send DMA cleanup interrupt handler.
2966 static irqreturn_t sdma_cleanup_intr(int irq, void *data)
2968 struct qib_pportdata *ppd = data;
2969 struct qib_devdata *dd = ppd->dd;
2971 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
2973 * This return value is not great, but we do not want the
2974 * interrupt core code to remove our interrupt handler
2975 * because we don't appear to be handling an interrupt
2976 * during a chip reset.
2980 qib_stats.sps_ints++;
2981 if (dd->int_counter != (u32) -1)
2984 /* Clear the interrupt bit we expect to be set. */
2985 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
2986 INT_MASK_PM(SDmaCleanupDone, 1) :
2987 INT_MASK_PM(SDmaCleanupDone, 0));
2988 qib_sdma_process_event(ppd, qib_sdma_event_e20_hw_started);
2994 * Set up our chip-specific interrupt handler.
2995 * The interrupt type has already been setup, so
2996 * we just need to do the registration and error checking.
2997 * If we are using MSIx interrupts, we may fall back to
2998 * INTx later, if the interrupt handler doesn't get called
2999 * within 1/2 second (see verify_interrupt()).
3001 static void qib_setup_7322_interrupt(struct qib_devdata *dd, int clearpend)
3003 int ret, i, msixnum;
3007 if (!dd->num_pports)
3012 * if not switching interrupt types, be sure interrupts are
3013 * disabled, and then clear anything pending at this point,
3014 * because we are starting clean.
3016 qib_7322_set_intr_state(dd, 0);
3018 /* clear the reset error, init error/hwerror mask */
3019 qib_7322_init_hwerrors(dd);
3021 /* clear any interrupt bits that might be set */
3022 qib_write_kreg(dd, kr_intclear, ~0ULL);
3024 /* make sure no pending MSIx intr, and clear diag reg */
3025 qib_write_kreg(dd, kr_intgranted, ~0ULL);
3026 qib_write_kreg(dd, kr_vecclr_wo_int, ~0ULL);
3029 if (!dd->cspec->num_msix_entries) {
3030 /* Try to get INTx interrupt */
3032 if (!dd->pcidev->irq) {
3033 qib_dev_err(dd, "irq is 0, BIOS error? "
3034 "Interrupts won't work\n");
3037 ret = request_irq(dd->pcidev->irq, qib_7322intr,
3038 IRQF_SHARED, QIB_DRV_NAME, dd);
3040 qib_dev_err(dd, "Couldn't setup INTx "
3041 "interrupt (irq=%d): %d\n",
3042 dd->pcidev->irq, ret);
3045 dd->cspec->irq = dd->pcidev->irq;
3046 dd->cspec->main_int_mask = ~0ULL;
3050 /* Try to get MSIx interrupts */
3051 memset(redirect, 0, sizeof redirect);
3054 for (i = 0; msixnum < dd->cspec->num_msix_entries; i++) {
3055 irq_handler_t handler;
3061 if (i < ARRAY_SIZE(irq_table)) {
3062 if (irq_table[i].port) {
3063 /* skip if for a non-configured port */
3064 if (irq_table[i].port > dd->num_pports)
3066 arg = dd->pport + irq_table[i].port - 1;
3069 lsb = irq_table[i].lsb;
3070 handler = irq_table[i].handler;
3071 name = irq_table[i].name;
3075 ctxt = i - ARRAY_SIZE(irq_table);
3076 /* per krcvq context receive interrupt */
3077 arg = dd->rcd[ctxt];
3080 lsb = QIB_I_RCVAVAIL_LSB + ctxt;
3081 handler = qib_7322pintr;
3082 name = QIB_DRV_NAME " (kctx)";
3084 ret = request_irq(dd->cspec->msix_entries[msixnum].vector,
3085 handler, 0, name, arg);
3088 * Shouldn't happen since the enable said we could
3089 * have as many as we are trying to setup here.
3091 qib_dev_err(dd, "Couldn't setup MSIx "
3092 "interrupt (vec=%d, irq=%d): %d\n", msixnum,
3093 dd->cspec->msix_entries[msixnum].vector,
3095 qib_7322_nomsix(dd);
3098 dd->cspec->msix_arg[msixnum] = arg;
3100 reg = lsb / IBA7322_REDIRECT_VEC_PER_REG;
3101 sh = (lsb % IBA7322_REDIRECT_VEC_PER_REG) *
3102 SYM_LSB(IntRedirect0, vec1);
3103 mask &= ~(1ULL << lsb);
3104 redirect[reg] |= ((u64) msixnum) << sh;
3106 val = qib_read_kreg64(dd, 2 * msixnum + 1 +
3107 (QIB_7322_MsixTable_OFFS / sizeof(u64)));
3110 /* Initialize the vector mapping */
3111 for (i = 0; i < ARRAY_SIZE(redirect); i++)
3112 qib_write_kreg(dd, kr_intredirect + i, redirect[i]);
3113 dd->cspec->main_int_mask = mask;
3118 * qib_7322_boardname - fill in the board name and note features
3119 * @dd: the qlogic_ib device
3121 * info will be based on the board revision register
3123 static unsigned qib_7322_boardname(struct qib_devdata *dd)
3125 /* Will need enumeration of board-types here */
3127 u32 boardid, namelen;
3128 unsigned features = DUAL_PORT_CAP;
3130 boardid = SYM_FIELD(dd->revision, Revision, BoardID);
3134 n = "InfiniPath_QLE7342_Emulation";
3137 n = "InfiniPath_QLE7340";
3138 dd->flags |= QIB_HAS_QSFP;
3139 features = PORT_SPD_CAP;
3142 n = "InfiniPath_QLE7342";
3143 dd->flags |= QIB_HAS_QSFP;
3146 n = "InfiniPath_QMI7342";
3149 n = "InfiniPath_Unsupported7342";
3150 qib_dev_err(dd, "Unsupported version of QMH7342\n");
3154 n = "InfiniPath_QMH7342";
3158 n = "InfiniPath_QME7342";
3161 n = "InfiniPath_QLE7342_TEST";
3162 dd->flags |= QIB_HAS_QSFP;
3165 n = "InfiniPath_QLE73xy_UNKNOWN";
3166 qib_dev_err(dd, "Unknown 7322 board type %u\n", boardid);
3169 dd->board_atten = 1; /* index into txdds_Xdr */
3171 namelen = strlen(n) + 1;
3172 dd->boardname = kmalloc(namelen, GFP_KERNEL);
3174 qib_dev_err(dd, "Failed allocation for board name: %s\n", n);
3176 snprintf(dd->boardname, namelen, "%s", n);
3178 snprintf(dd->boardversion, sizeof(dd->boardversion),
3179 "ChipABI %u.%u, %s, InfiniPath%u %u.%u, SW Compat %u\n",
3180 QIB_CHIP_VERS_MAJ, QIB_CHIP_VERS_MIN, dd->boardname,
3181 (unsigned)SYM_FIELD(dd->revision, Revision_R, Arch),
3182 dd->majrev, dd->minrev,
3183 (unsigned)SYM_FIELD(dd->revision, Revision_R, SW));
3185 if (qib_singleport && (features >> PORT_SPD_CAP_SHIFT) & PORT_SPD_CAP) {
3186 qib_devinfo(dd->pcidev, "IB%u: Forced to single port mode"
3187 " by module parameter\n", dd->unit);
3188 features &= PORT_SPD_CAP;
3195 * This routine sleeps, so it can only be called from user context, not
3196 * from interrupt context.
3198 static int qib_do_7322_reset(struct qib_devdata *dd)
3202 int i, msix_entries, ret = 1;
3204 u8 int_line, clinesz;
3205 unsigned long flags;
3207 /* Use dev_err so it shows up in logs, etc. */
3208 qib_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->unit);
3210 qib_pcie_getcmd(dd, &cmdval, &int_line, &clinesz);
3212 msix_entries = dd->cspec->num_msix_entries;
3214 /* no interrupts till re-initted */
3215 qib_7322_set_intr_state(dd, 0);
3218 qib_7322_nomsix(dd);
3219 /* can be up to 512 bytes, too big for stack */
3220 msix_vecsave = kmalloc(2 * dd->cspec->num_msix_entries *
3221 sizeof(u64), GFP_KERNEL);
3223 qib_dev_err(dd, "No mem to save MSIx data\n");
3225 msix_vecsave = NULL;
3228 * Core PCI (as of 2.6.18) doesn't save or rewrite the full vector
3229 * info that is set up by the BIOS, so we have to save and restore
3230 * it ourselves. There is some risk something could change it,
3231 * after we save it, but since we have disabled the MSIx, it
3232 * shouldn't be touched...
3234 for (i = 0; i < msix_entries; i++) {
3235 u64 vecaddr, vecdata;
3236 vecaddr = qib_read_kreg64(dd, 2 * i +
3237 (QIB_7322_MsixTable_OFFS / sizeof(u64)));
3238 vecdata = qib_read_kreg64(dd, 1 + 2 * i +
3239 (QIB_7322_MsixTable_OFFS / sizeof(u64)));
3241 msix_vecsave[2 * i] = vecaddr;
3242 /* save it without the masked bit set */
3243 msix_vecsave[1 + 2 * i] = vecdata & ~0x100000000ULL;
3247 dd->pport->cpspec->ibdeltainprog = 0;
3248 dd->pport->cpspec->ibsymdelta = 0;
3249 dd->pport->cpspec->iblnkerrdelta = 0;
3250 dd->pport->cpspec->ibmalfdelta = 0;
3251 dd->int_counter = 0; /* so we check interrupts work again */
3254 * Keep chip from being accessed until we are ready. Use
3255 * writeq() directly, to allow the write even though QIB_PRESENT
3258 dd->flags &= ~(QIB_INITTED | QIB_PRESENT | QIB_BADINTR);
3259 dd->flags |= QIB_DOING_RESET;
3260 val = dd->control | QLOGIC_IB_C_RESET;
3261 writeq(val, &dd->kregbase[kr_control]);
3263 for (i = 1; i <= 5; i++) {
3265 * Allow MBIST, etc. to complete; longer on each retry.
3266 * We sometimes get machine checks from bus timeout if no
3267 * response, so for now, make it *really* long.
3269 msleep(1000 + (1 + i) * 3000);
3271 qib_pcie_reenable(dd, cmdval, int_line, clinesz);
3274 * Use readq directly, so we don't need to mark it as PRESENT
3275 * until we get a successful indication that all is well.
3277 val = readq(&dd->kregbase[kr_revision]);
3278 if (val == dd->revision)
3281 qib_dev_err(dd, "Failed to initialize after reset, "
3288 dd->flags |= QIB_PRESENT; /* it's back */
3291 /* restore the MSIx vector address and data if saved above */
3292 for (i = 0; i < msix_entries; i++) {
3293 dd->cspec->msix_entries[i].entry = i;
3294 if (!msix_vecsave || !msix_vecsave[2 * i])
3296 qib_write_kreg(dd, 2 * i +
3297 (QIB_7322_MsixTable_OFFS / sizeof(u64)),
3298 msix_vecsave[2 * i]);
3299 qib_write_kreg(dd, 1 + 2 * i +
3300 (QIB_7322_MsixTable_OFFS / sizeof(u64)),
3301 msix_vecsave[1 + 2 * i]);
3305 /* initialize the remaining registers. */
3306 for (i = 0; i < dd->num_pports; ++i)
3307 write_7322_init_portregs(&dd->pport[i]);
3308 write_7322_initregs(dd);
3310 if (qib_pcie_params(dd, dd->lbus_width,
3311 &dd->cspec->num_msix_entries,
3312 dd->cspec->msix_entries))
3313 qib_dev_err(dd, "Reset failed to setup PCIe or interrupts; "
3314 "continuing anyway\n");
3316 qib_setup_7322_interrupt(dd, 1);
3318 for (i = 0; i < dd->num_pports; ++i) {
3319 struct qib_pportdata *ppd = &dd->pport[i];
3321 spin_lock_irqsave(&ppd->lflags_lock, flags);
3322 ppd->lflags |= QIBL_IB_FORCE_NOTIFY;
3323 ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
3324 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
3328 dd->flags &= ~QIB_DOING_RESET; /* OK or not, no longer resetting */
3329 kfree(msix_vecsave);
3334 * qib_7322_put_tid - write a TID to the chip
3335 * @dd: the qlogic_ib device
3336 * @tidptr: pointer to the expected TID (in chip) to update
3337 * @tidtype: 0 for eager, 1 for expected
3338 * @pa: physical address of in memory buffer; tidinvalid if freeing
3340 static void qib_7322_put_tid(struct qib_devdata *dd, u64 __iomem *tidptr,
3341 u32 type, unsigned long pa)
3343 if (!(dd->flags & QIB_PRESENT))
3345 if (pa != dd->tidinvalid) {
3346 u64 chippa = pa >> IBA7322_TID_PA_SHIFT;
3348 /* paranoia checks */
3349 if (pa != (chippa << IBA7322_TID_PA_SHIFT)) {
3350 qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
3354 if (chippa >= (1UL << IBA7322_TID_SZ_SHIFT)) {
3355 qib_dev_err(dd, "Physical page address 0x%lx "
3356 "larger than supported\n", pa);
3360 if (type == RCVHQ_RCV_TYPE_EAGER)
3361 chippa |= dd->tidtemplate;
3362 else /* for now, always full 4KB page */
3363 chippa |= IBA7322_TID_SZ_4K;
3371 * qib_7322_clear_tids - clear all TID entries for a ctxt, expected and eager
3372 * @dd: the qlogic_ib device
3375 * clear all TID entries for a ctxt, expected and eager.
3376 * Used from qib_close().
3378 static void qib_7322_clear_tids(struct qib_devdata *dd,
3379 struct qib_ctxtdata *rcd)
3381 u64 __iomem *tidbase;
3382 unsigned long tidinv;
3386 if (!dd->kregbase || !rcd)
3391 tidinv = dd->tidinvalid;
3392 tidbase = (u64 __iomem *)
3393 ((char __iomem *) dd->kregbase +
3395 ctxt * dd->rcvtidcnt * sizeof(*tidbase));
3397 for (i = 0; i < dd->rcvtidcnt; i++)
3398 qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
3401 tidbase = (u64 __iomem *)
3402 ((char __iomem *) dd->kregbase +
3404 rcd->rcvegr_tid_base * sizeof(*tidbase));
3406 for (i = 0; i < rcd->rcvegrcnt; i++)
3407 qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
3412 * qib_7322_tidtemplate - setup constants for TID updates
3413 * @dd: the qlogic_ib device
3415 * We setup stuff that we use a lot, to avoid calculating each time
3417 static void qib_7322_tidtemplate(struct qib_devdata *dd)
3420 * For now, we always allocate 4KB buffers (at init) so we can
3421 * receive max size packets. We may want a module parameter to
3422 * specify 2KB or 4KB and/or make it per port instead of per device
3423 * for those who want to reduce memory footprint. Note that the
3424 * rcvhdrentsize size must be large enough to hold the largest
3425 * IB header (currently 96 bytes) that we expect to handle (plus of
3426 * course the 2 dwords of RHF).
3428 if (dd->rcvegrbufsize == 2048)
3429 dd->tidtemplate = IBA7322_TID_SZ_2K;
3430 else if (dd->rcvegrbufsize == 4096)
3431 dd->tidtemplate = IBA7322_TID_SZ_4K;
3436 * qib_init_7322_get_base_info - set chip-specific flags for user code
3437 * @rcd: the qlogic_ib ctxt
3438 * @kbase: qib_base_info pointer
3440 * We set the PCIE flag because the lower bandwidth on PCIe vs
3441 * HyperTransport can affect some user packet algorithims.
3444 static int qib_7322_get_base_info(struct qib_ctxtdata *rcd,
3445 struct qib_base_info *kinfo)
3447 kinfo->spi_runtime_flags |= QIB_RUNTIME_CTXT_MSB_IN_QP |
3448 QIB_RUNTIME_PCIE | QIB_RUNTIME_NODMA_RTAIL |
3449 QIB_RUNTIME_HDRSUPP | QIB_RUNTIME_SDMA;
3450 if (rcd->dd->cspec->r1)
3451 kinfo->spi_runtime_flags |= QIB_RUNTIME_RCHK;
3452 if (rcd->dd->flags & QIB_USE_SPCL_TRIG)
3453 kinfo->spi_runtime_flags |= QIB_RUNTIME_SPECIAL_TRIGGER;
3458 static struct qib_message_header *
3459 qib_7322_get_msgheader(struct qib_devdata *dd, __le32 *rhf_addr)
3461 u32 offset = qib_hdrget_offset(rhf_addr);
3463 return (struct qib_message_header *)
3464 (rhf_addr - dd->rhf_offset + offset);
3468 * Configure number of contexts.
3470 static void qib_7322_config_ctxts(struct qib_devdata *dd)
3472 unsigned long flags;
3475 nchipctxts = qib_read_kreg32(dd, kr_contextcnt);
3476 dd->cspec->numctxts = nchipctxts;
3477 if (qib_n_krcv_queues > 1 && dd->num_pports) {
3479 * Set the mask for which bits from the QPN are used
3480 * to select a context number.
3482 dd->qpn_mask = 0x3f;
3483 dd->first_user_ctxt = NUM_IB_PORTS +
3484 (qib_n_krcv_queues - 1) * dd->num_pports;
3485 if (dd->first_user_ctxt > nchipctxts)
3486 dd->first_user_ctxt = nchipctxts;
3487 dd->n_krcv_queues = dd->first_user_ctxt / dd->num_pports;
3489 dd->first_user_ctxt = NUM_IB_PORTS;
3490 dd->n_krcv_queues = 1;
3493 if (!qib_cfgctxts) {
3494 int nctxts = dd->first_user_ctxt + num_online_cpus();
3498 else if (nctxts <= 10)
3500 else if (nctxts <= nchipctxts)
3501 dd->ctxtcnt = nchipctxts;
3502 } else if (qib_cfgctxts < dd->num_pports)
3503 dd->ctxtcnt = dd->num_pports;
3504 else if (qib_cfgctxts <= nchipctxts)
3505 dd->ctxtcnt = qib_cfgctxts;
3506 if (!dd->ctxtcnt) /* none of the above, set to max */
3507 dd->ctxtcnt = nchipctxts;
3510 * Chip can be configured for 6, 10, or 18 ctxts, and choice
3511 * affects number of eager TIDs per ctxt (1K, 2K, 4K).
3512 * Lock to be paranoid about later motion, etc.
3514 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
3515 if (dd->ctxtcnt > 10)
3516 dd->rcvctrl |= 2ULL << SYM_LSB(RcvCtrl, ContextCfg);
3517 else if (dd->ctxtcnt > 6)
3518 dd->rcvctrl |= 1ULL << SYM_LSB(RcvCtrl, ContextCfg);
3519 /* else configure for default 6 receive ctxts */
3521 /* The XRC opcode is 5. */
3522 dd->rcvctrl |= 5ULL << SYM_LSB(RcvCtrl, XrcTypeCode);
3525 * RcvCtrl *must* be written here so that the
3526 * chip understands how to change rcvegrcnt below.
3528 qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
3529 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
3531 /* kr_rcvegrcnt changes based on the number of contexts enabled */
3532 dd->cspec->rcvegrcnt = qib_read_kreg32(dd, kr_rcvegrcnt);
3533 dd->rcvhdrcnt = max(dd->cspec->rcvegrcnt,
3534 dd->num_pports > 1 ? 1024U : 2048U);
3537 static int qib_7322_get_ib_cfg(struct qib_pportdata *ppd, int which)
3541 u64 maskr; /* right-justified mask */
3545 case QIB_IB_CFG_LWID_ENB: /* Get allowed Link-width */
3546 ret = ppd->link_width_enabled;
3549 case QIB_IB_CFG_LWID: /* Get currently active Link-width */
3550 ret = ppd->link_width_active;
3553 case QIB_IB_CFG_SPD_ENB: /* Get allowed Link speeds */
3554 ret = ppd->link_speed_enabled;
3557 case QIB_IB_CFG_SPD: /* Get current Link spd */
3558 ret = ppd->link_speed_active;
3561 case QIB_IB_CFG_RXPOL_ENB: /* Get Auto-RX-polarity enable */
3562 lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
3563 maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
3566 case QIB_IB_CFG_LREV_ENB: /* Get Auto-Lane-reversal enable */
3567 lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
3568 maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
3571 case QIB_IB_CFG_LINKLATENCY:
3572 ret = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
3573 SYM_MASK(IBCStatusB_0, LinkRoundTripLatency);
3576 case QIB_IB_CFG_OP_VLS:
3577 ret = ppd->vls_operational;
3580 case QIB_IB_CFG_VL_HIGH_CAP:
3584 case QIB_IB_CFG_VL_LOW_CAP:
3588 case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
3589 ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
3593 case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
3594 ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
3598 case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
3599 /* will only take effect when the link state changes */
3600 ret = (ppd->cpspec->ibcctrl_a &
3601 SYM_MASK(IBCCtrlA_0, LinkDownDefaultState)) ?
3602 IB_LINKINITCMD_SLEEP : IB_LINKINITCMD_POLL;
3605 case QIB_IB_CFG_HRTBT: /* Get Heartbeat off/enable/auto */
3606 lsb = IBA7322_IBC_HRTBT_LSB;
3607 maskr = IBA7322_IBC_HRTBT_RMASK; /* OR of AUTO and ENB */
3610 case QIB_IB_CFG_PMA_TICKS:
3612 * 0x00 = 10x link transfer rate or 4 nsec. for 2.5Gbs
3613 * Since the clock is always 250MHz, the value is 3, 1 or 0.
3615 if (ppd->link_speed_active == QIB_IB_QDR)
3617 else if (ppd->link_speed_active == QIB_IB_DDR)
3627 ret = (int)((ppd->cpspec->ibcctrl_b >> lsb) & maskr);
3633 * Below again cribbed liberally from older version. Do not lean
3636 #define IBA7322_IBC_DLIDLMC_SHIFT QIB_7322_IBCCtrlB_0_IB_DLID_LSB
3637 #define IBA7322_IBC_DLIDLMC_MASK (QIB_7322_IBCCtrlB_0_IB_DLID_RMASK \
3638 | (QIB_7322_IBCCtrlB_0_IB_DLID_MASK_RMASK << 16))
3640 static int qib_7322_set_ib_cfg(struct qib_pportdata *ppd, int which, u32 val)
3642 struct qib_devdata *dd = ppd->dd;
3643 u64 maskr; /* right-justified mask */
3646 unsigned long flags;
3649 case QIB_IB_CFG_LIDLMC:
3651 * Set LID and LMC. Combined to avoid possible hazard
3652 * caller puts LMC in 16MSbits, DLID in 16LSbits of val
3654 lsb = IBA7322_IBC_DLIDLMC_SHIFT;
3655 maskr = IBA7322_IBC_DLIDLMC_MASK;
3657 * For header-checking, the SLID in the packet will
3658 * be masked with SendIBSLMCMask, and compared
3659 * with SendIBSLIDAssignMask. Make sure we do not
3660 * set any bits not covered by the mask, or we get
3663 qib_write_kreg_port(ppd, krp_sendslid,
3664 val & (val >> 16) & SendIBSLIDAssignMask);
3665 qib_write_kreg_port(ppd, krp_sendslidmask,
3666 (val >> 16) & SendIBSLMCMask);
3669 case QIB_IB_CFG_LWID_ENB: /* set allowed Link-width */
3670 ppd->link_width_enabled = val;
3671 /* convert IB value to chip register value */
3672 if (val == IB_WIDTH_1X)
3674 else if (val == IB_WIDTH_4X)
3678 maskr = SYM_RMASK(IBCCtrlB_0, IB_NUM_CHANNELS);
3679 lsb = SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS);
3682 case QIB_IB_CFG_SPD_ENB: /* set allowed Link speeds */
3684 * As with width, only write the actual register if the
3685 * link is currently down, otherwise takes effect on next
3686 * link change. Since setting is being explictly requested
3687 * (via MAD or sysfs), clear autoneg failure status if speed
3688 * autoneg is enabled.
3690 ppd->link_speed_enabled = val;
3691 val <<= IBA7322_IBC_SPEED_LSB;
3692 maskr = IBA7322_IBC_SPEED_MASK | IBA7322_IBC_IBTA_1_2_MASK |
3693 IBA7322_IBC_MAX_SPEED_MASK;
3694 if (val & (val - 1)) {
3695 /* Muliple speeds enabled */
3696 val |= IBA7322_IBC_IBTA_1_2_MASK |
3697 IBA7322_IBC_MAX_SPEED_MASK;
3698 spin_lock_irqsave(&ppd->lflags_lock, flags);
3699 ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
3700 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
3701 } else if (val & IBA7322_IBC_SPEED_QDR)
3702 val |= IBA7322_IBC_IBTA_1_2_MASK;
3703 /* IBTA 1.2 mode + min/max + speed bits are contiguous */
3704 lsb = SYM_LSB(IBCCtrlB_0, IB_ENHANCED_MODE);
3707 case QIB_IB_CFG_RXPOL_ENB: /* set Auto-RX-polarity enable */
3708 lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
3709 maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
3712 case QIB_IB_CFG_LREV_ENB: /* set Auto-Lane-reversal enable */
3713 lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
3714 maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
3717 case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
3718 maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
3721 ppd->cpspec->ibcctrl_a &=
3722 ~SYM_MASK(IBCCtrlA_0, OverrunThreshold);
3723 ppd->cpspec->ibcctrl_a |= (u64) val <<
3724 SYM_LSB(IBCCtrlA_0, OverrunThreshold);
3725 qib_write_kreg_port(ppd, krp_ibcctrl_a,
3726 ppd->cpspec->ibcctrl_a);
3727 qib_write_kreg(dd, kr_scratch, 0ULL);
3731 case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
3732 maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
3735 ppd->cpspec->ibcctrl_a &=
3736 ~SYM_MASK(IBCCtrlA_0, PhyerrThreshold);
3737 ppd->cpspec->ibcctrl_a |= (u64) val <<
3738 SYM_LSB(IBCCtrlA_0, PhyerrThreshold);
3739 qib_write_kreg_port(ppd, krp_ibcctrl_a,
3740 ppd->cpspec->ibcctrl_a);
3741 qib_write_kreg(dd, kr_scratch, 0ULL);
3745 case QIB_IB_CFG_PKEYS: /* update pkeys */
3746 maskr = (u64) ppd->pkeys[0] | ((u64) ppd->pkeys[1] << 16) |
3747 ((u64) ppd->pkeys[2] << 32) |
3748 ((u64) ppd->pkeys[3] << 48);
3749 qib_write_kreg_port(ppd, krp_partitionkey, maskr);
3752 case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
3753 /* will only take effect when the link state changes */
3754 if (val == IB_LINKINITCMD_POLL)
3755 ppd->cpspec->ibcctrl_a &=
3756 ~SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
3758 ppd->cpspec->ibcctrl_a |=
3759 SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
3760 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
3761 qib_write_kreg(dd, kr_scratch, 0ULL);
3764 case QIB_IB_CFG_MTU: /* update the MTU in IBC */
3766 * Update our housekeeping variables, and set IBC max
3767 * size, same as init code; max IBC is max we allow in
3768 * buffer, less the qword pbc, plus 1 for ICRC, in dwords
3769 * Set even if it's unchanged, print debug message only
3772 val = (ppd->ibmaxlen >> 2) + 1;
3773 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, MaxPktLen);
3774 ppd->cpspec->ibcctrl_a |= (u64)val <<
3775 SYM_LSB(IBCCtrlA_0, MaxPktLen);
3776 qib_write_kreg_port(ppd, krp_ibcctrl_a,
3777 ppd->cpspec->ibcctrl_a);
3778 qib_write_kreg(dd, kr_scratch, 0ULL);
3781 case QIB_IB_CFG_LSTATE: /* set the IB link state */
3782 switch (val & 0xffff0000) {
3783 case IB_LINKCMD_DOWN:
3784 lcmd = QLOGIC_IB_IBCC_LINKCMD_DOWN;
3785 ppd->cpspec->ibmalfusesnap = 1;
3786 ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
3788 if (!ppd->cpspec->ibdeltainprog &&
3789 qib_compat_ddr_negotiate) {
3790 ppd->cpspec->ibdeltainprog = 1;
3791 ppd->cpspec->ibsymsnap =
3792 read_7322_creg32_port(ppd,
3794 ppd->cpspec->iblnkerrsnap =
3795 read_7322_creg32_port(ppd,
3796 crp_iblinkerrrecov);
3800 case IB_LINKCMD_ARMED:
3801 lcmd = QLOGIC_IB_IBCC_LINKCMD_ARMED;
3802 if (ppd->cpspec->ibmalfusesnap) {
3803 ppd->cpspec->ibmalfusesnap = 0;
3804 ppd->cpspec->ibmalfdelta +=
3805 read_7322_creg32_port(ppd,
3807 ppd->cpspec->ibmalfsnap;
3811 case IB_LINKCMD_ACTIVE:
3812 lcmd = QLOGIC_IB_IBCC_LINKCMD_ACTIVE;
3817 qib_dev_err(dd, "bad linkcmd req 0x%x\n", val >> 16);
3820 switch (val & 0xffff) {
3821 case IB_LINKINITCMD_NOP:
3825 case IB_LINKINITCMD_POLL:
3826 licmd = QLOGIC_IB_IBCC_LINKINITCMD_POLL;
3829 case IB_LINKINITCMD_SLEEP:
3830 licmd = QLOGIC_IB_IBCC_LINKINITCMD_SLEEP;
3833 case IB_LINKINITCMD_DISABLE:
3834 licmd = QLOGIC_IB_IBCC_LINKINITCMD_DISABLE;
3835 ppd->cpspec->chase_end = 0;
3837 * stop state chase counter and timer, if running.
3838 * wait forpending timer, but don't clear .data (ppd)!
3840 if (ppd->cpspec->chase_timer.expires) {
3841 del_timer_sync(&ppd->cpspec->chase_timer);
3842 ppd->cpspec->chase_timer.expires = 0;
3848 qib_dev_err(dd, "bad linkinitcmd req 0x%x\n",
3852 qib_set_ib_7322_lstate(ppd, lcmd, licmd);
3855 case QIB_IB_CFG_OP_VLS:
3856 if (ppd->vls_operational != val) {
3857 ppd->vls_operational = val;
3862 case QIB_IB_CFG_VL_HIGH_LIMIT:
3863 qib_write_kreg_port(ppd, krp_highprio_limit, val);
3866 case QIB_IB_CFG_HRTBT: /* set Heartbeat off/enable/auto */
3871 lsb = IBA7322_IBC_HRTBT_LSB;
3872 maskr = IBA7322_IBC_HRTBT_RMASK; /* OR of AUTO and ENB */
3875 case QIB_IB_CFG_PORT:
3876 /* val is the port number of the switch we are connected to. */
3877 if (ppd->dd->cspec->r1) {
3878 cancel_delayed_work(&ppd->cpspec->ipg_work);
3879 ppd->cpspec->ipg_tries = 0;
3887 ppd->cpspec->ibcctrl_b &= ~(maskr << lsb);
3888 ppd->cpspec->ibcctrl_b |= (((u64) val & maskr) << lsb);
3889 qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
3890 qib_write_kreg(dd, kr_scratch, 0);
3895 static int qib_7322_set_loopback(struct qib_pportdata *ppd, const char *what)
3900 /* only IBC loopback, may add serdes and xgxs loopbacks later */
3901 if (!strncmp(what, "ibc", 3)) {
3902 ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0,
3904 val = 0; /* disable heart beat, so link will come up */
3905 qib_devinfo(ppd->dd->pcidev, "Enabling IB%u:%u IBC loopback\n",
3906 ppd->dd->unit, ppd->port);
3907 } else if (!strncmp(what, "off", 3)) {
3908 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0,
3910 /* enable heart beat again */
3911 val = IBA7322_IBC_HRTBT_RMASK << IBA7322_IBC_HRTBT_LSB;
3912 qib_devinfo(ppd->dd->pcidev, "Disabling IB%u:%u IBC loopback "
3913 "(normal)\n", ppd->dd->unit, ppd->port);
3917 qib_write_kreg_port(ppd, krp_ibcctrl_a,
3918 ppd->cpspec->ibcctrl_a);
3919 ctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_HRTBT_MASK
3920 << IBA7322_IBC_HRTBT_LSB);
3921 ppd->cpspec->ibcctrl_b = ctrlb | val;
3922 qib_write_kreg_port(ppd, krp_ibcctrl_b,
3923 ppd->cpspec->ibcctrl_b);
3924 qib_write_kreg(ppd->dd, kr_scratch, 0);
3929 static void get_vl_weights(struct qib_pportdata *ppd, unsigned regno,
3930 struct ib_vl_weight_elem *vl)
3934 for (i = 0; i < 16; i++, regno++, vl++) {
3935 u32 val = qib_read_kreg_port(ppd, regno);
3937 vl->vl = (val >> SYM_LSB(LowPriority0_0, VirtualLane)) &
3938 SYM_RMASK(LowPriority0_0, VirtualLane);
3939 vl->weight = (val >> SYM_LSB(LowPriority0_0, Weight)) &
3940 SYM_RMASK(LowPriority0_0, Weight);
3944 static void set_vl_weights(struct qib_pportdata *ppd, unsigned regno,
3945 struct ib_vl_weight_elem *vl)
3949 for (i = 0; i < 16; i++, regno++, vl++) {
3952 val = ((vl->vl & SYM_RMASK(LowPriority0_0, VirtualLane)) <<
3953 SYM_LSB(LowPriority0_0, VirtualLane)) |
3954 ((vl->weight & SYM_RMASK(LowPriority0_0, Weight)) <<
3955 SYM_LSB(LowPriority0_0, Weight));
3956 qib_write_kreg_port(ppd, regno, val);
3958 if (!(ppd->p_sendctrl & SYM_MASK(SendCtrl_0, IBVLArbiterEn))) {
3959 struct qib_devdata *dd = ppd->dd;
3960 unsigned long flags;
3962 spin_lock_irqsave(&dd->sendctrl_lock, flags);
3963 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, IBVLArbiterEn);
3964 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
3965 qib_write_kreg(dd, kr_scratch, 0);
3966 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
3970 static int qib_7322_get_ib_table(struct qib_pportdata *ppd, int which, void *t)
3973 case QIB_IB_TBL_VL_HIGH_ARB:
3974 get_vl_weights(ppd, krp_highprio_0, t);
3977 case QIB_IB_TBL_VL_LOW_ARB:
3978 get_vl_weights(ppd, krp_lowprio_0, t);
3987 static int qib_7322_set_ib_table(struct qib_pportdata *ppd, int which, void *t)
3990 case QIB_IB_TBL_VL_HIGH_ARB:
3991 set_vl_weights(ppd, krp_highprio_0, t);
3994 case QIB_IB_TBL_VL_LOW_ARB:
3995 set_vl_weights(ppd, krp_lowprio_0, t);
4004 static void qib_update_7322_usrhead(struct qib_ctxtdata *rcd, u64 hd,
4005 u32 updegr, u32 egrhd)
4007 qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
4008 qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
4010 qib_write_ureg(rcd->dd, ur_rcvegrindexhead, egrhd, rcd->ctxt);
4013 static u32 qib_7322_hdrqempty(struct qib_ctxtdata *rcd)
4017 head = qib_read_ureg32(rcd->dd, ur_rcvhdrhead, rcd->ctxt);
4018 if (rcd->rcvhdrtail_kvaddr)
4019 tail = qib_get_rcvhdrtail(rcd);
4021 tail = qib_read_ureg32(rcd->dd, ur_rcvhdrtail, rcd->ctxt);
4022 return head == tail;
4025 #define RCVCTRL_COMMON_MODS (QIB_RCVCTRL_CTXT_ENB | \
4026 QIB_RCVCTRL_CTXT_DIS | \
4027 QIB_RCVCTRL_TIDFLOW_ENB | \
4028 QIB_RCVCTRL_TIDFLOW_DIS | \
4029 QIB_RCVCTRL_TAILUPD_ENB | \
4030 QIB_RCVCTRL_TAILUPD_DIS | \
4031 QIB_RCVCTRL_INTRAVAIL_ENB | \
4032 QIB_RCVCTRL_INTRAVAIL_DIS | \
4033 QIB_RCVCTRL_BP_ENB | \
4036 #define RCVCTRL_PORT_MODS (QIB_RCVCTRL_CTXT_ENB | \
4037 QIB_RCVCTRL_CTXT_DIS | \
4038 QIB_RCVCTRL_PKEY_DIS | \
4039 QIB_RCVCTRL_PKEY_ENB)
4042 * Modify the RCVCTRL register in chip-specific way. This
4043 * is a function because bit positions and (future) register
4044 * location is chip-specifc, but the needed operations are
4045 * generic. <op> is a bit-mask because we often want to
4046 * do multiple modifications.
4048 static void rcvctrl_7322_mod(struct qib_pportdata *ppd, unsigned int op,
4051 struct qib_devdata *dd = ppd->dd;
4052 struct qib_ctxtdata *rcd;
4054 unsigned long flags;
4056 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
4058 if (op & QIB_RCVCTRL_TIDFLOW_ENB)
4059 dd->rcvctrl |= SYM_MASK(RcvCtrl, TidFlowEnable);
4060 if (op & QIB_RCVCTRL_TIDFLOW_DIS)
4061 dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TidFlowEnable);
4062 if (op & QIB_RCVCTRL_TAILUPD_ENB)
4063 dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
4064 if (op & QIB_RCVCTRL_TAILUPD_DIS)
4065 dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TailUpd);
4066 if (op & QIB_RCVCTRL_PKEY_ENB)
4067 ppd->p_rcvctrl &= ~SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
4068 if (op & QIB_RCVCTRL_PKEY_DIS)
4069 ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
4071 mask = (1ULL << dd->ctxtcnt) - 1;
4074 mask = (1ULL << ctxt);
4075 rcd = dd->rcd[ctxt];
4077 if ((op & QIB_RCVCTRL_CTXT_ENB) && rcd) {
4079 (mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
4080 if (!(dd->flags & QIB_NODMA_RTAIL)) {
4081 op |= QIB_RCVCTRL_TAILUPD_ENB; /* need reg write */
4082 dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
4084 /* Write these registers before the context is enabled. */
4085 qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt,
4086 rcd->rcvhdrqtailaddr_phys);
4087 qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt,
4091 if (op & QIB_RCVCTRL_CTXT_DIS)
4093 ~(mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
4094 if (op & QIB_RCVCTRL_BP_ENB)
4095 dd->rcvctrl |= mask << SYM_LSB(RcvCtrl, dontDropRHQFull);
4096 if (op & QIB_RCVCTRL_BP_DIS)
4097 dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, dontDropRHQFull));
4098 if (op & QIB_RCVCTRL_INTRAVAIL_ENB)
4099 dd->rcvctrl |= (mask << SYM_LSB(RcvCtrl, IntrAvail));
4100 if (op & QIB_RCVCTRL_INTRAVAIL_DIS)
4101 dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, IntrAvail));
4103 * Decide which registers to write depending on the ops enabled.
4104 * Special case is "flush" (no bits set at all)
4105 * which needs to write both.
4107 if (op == 0 || (op & RCVCTRL_COMMON_MODS))
4108 qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
4109 if (op == 0 || (op & RCVCTRL_PORT_MODS))
4110 qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
4111 if ((op & QIB_RCVCTRL_CTXT_ENB) && dd->rcd[ctxt]) {
4113 * Init the context registers also; if we were
4114 * disabled, tail and head should both be zero
4115 * already from the enable, but since we don't
4116 * know, we have to do it explictly.
4118 val = qib_read_ureg32(dd, ur_rcvegrindextail, ctxt);
4119 qib_write_ureg(dd, ur_rcvegrindexhead, val, ctxt);
4121 /* be sure enabling write seen; hd/tl should be 0 */
4122 (void) qib_read_kreg32(dd, kr_scratch);
4123 val = qib_read_ureg32(dd, ur_rcvhdrtail, ctxt);
4124 dd->rcd[ctxt]->head = val;
4125 /* If kctxt, interrupt on next receive. */
4126 if (ctxt < dd->first_user_ctxt)
4127 val |= dd->rhdrhead_intr_off;
4128 qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
4129 } else if ((op & QIB_RCVCTRL_INTRAVAIL_ENB) &&
4130 dd->rcd[ctxt] && dd->rhdrhead_intr_off) {
4131 /* arm rcv interrupt */
4132 val = dd->rcd[ctxt]->head | dd->rhdrhead_intr_off;
4133 qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
4135 if (op & QIB_RCVCTRL_CTXT_DIS) {
4138 /* Now that the context is disabled, clear these registers. */
4140 qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt, 0);
4141 qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt, 0);
4142 for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
4143 qib_write_ureg(dd, ur_rcvflowtable + f,
4144 TIDFLOW_ERRBITS, ctxt);
4148 for (i = 0; i < dd->cfgctxts; i++) {
4149 qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr,
4151 qib_write_kreg_ctxt(dd, krc_rcvhdraddr, i, 0);
4152 for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
4153 qib_write_ureg(dd, ur_rcvflowtable + f,
4154 TIDFLOW_ERRBITS, i);
4158 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
4162 * Modify the SENDCTRL register in chip-specific way. This
4163 * is a function where there are multiple such registers with
4164 * slightly different layouts.
4165 * The chip doesn't allow back-to-back sendctrl writes, so write
4166 * the scratch register after writing sendctrl.
4168 * Which register is written depends on the operation.
4169 * Most operate on the common register, while
4170 * SEND_ENB and SEND_DIS operate on the per-port ones.
4171 * SEND_ENB is included in common because it can change SPCL_TRIG
4173 #define SENDCTRL_COMMON_MODS (\
4174 QIB_SENDCTRL_CLEAR | \
4175 QIB_SENDCTRL_AVAIL_DIS | \
4176 QIB_SENDCTRL_AVAIL_ENB | \
4177 QIB_SENDCTRL_AVAIL_BLIP | \
4178 QIB_SENDCTRL_DISARM | \
4179 QIB_SENDCTRL_DISARM_ALL | \
4180 QIB_SENDCTRL_SEND_ENB)
4182 #define SENDCTRL_PORT_MODS (\
4183 QIB_SENDCTRL_CLEAR | \
4184 QIB_SENDCTRL_SEND_ENB | \
4185 QIB_SENDCTRL_SEND_DIS | \
4188 static void sendctrl_7322_mod(struct qib_pportdata *ppd, u32 op)
4190 struct qib_devdata *dd = ppd->dd;
4191 u64 tmp_dd_sendctrl;
4192 unsigned long flags;
4194 spin_lock_irqsave(&dd->sendctrl_lock, flags);
4196 /* First the dd ones that are "sticky", saved in shadow */
4197 if (op & QIB_SENDCTRL_CLEAR)
4199 if (op & QIB_SENDCTRL_AVAIL_DIS)
4200 dd->sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
4201 else if (op & QIB_SENDCTRL_AVAIL_ENB) {
4202 dd->sendctrl |= SYM_MASK(SendCtrl, SendBufAvailUpd);
4203 if (dd->flags & QIB_USE_SPCL_TRIG)
4204 dd->sendctrl |= SYM_MASK(SendCtrl, SpecialTriggerEn);
4207 /* Then the ppd ones that are "sticky", saved in shadow */
4208 if (op & QIB_SENDCTRL_SEND_DIS)
4209 ppd->p_sendctrl &= ~SYM_MASK(SendCtrl_0, SendEnable);
4210 else if (op & QIB_SENDCTRL_SEND_ENB)
4211 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, SendEnable);
4213 if (op & QIB_SENDCTRL_DISARM_ALL) {
4216 tmp_dd_sendctrl = dd->sendctrl;
4217 last = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
4219 * Disarm any buffers that are not yet launched,
4220 * disabling updates until done.
4222 tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
4223 for (i = 0; i < last; i++) {
4224 qib_write_kreg(dd, kr_sendctrl,
4226 SYM_MASK(SendCtrl, Disarm) | i);
4227 qib_write_kreg(dd, kr_scratch, 0);
4231 if (op & QIB_SENDCTRL_FLUSH) {
4232 u64 tmp_ppd_sendctrl = ppd->p_sendctrl;
4235 * Now drain all the fifos. The Abort bit should never be
4236 * needed, so for now, at least, we don't use it.
4239 SYM_MASK(SendCtrl_0, TxeDrainRmFifo) |
4240 SYM_MASK(SendCtrl_0, TxeDrainLaFifo) |
4241 SYM_MASK(SendCtrl_0, TxeBypassIbc);
4242 qib_write_kreg_port(ppd, krp_sendctrl, tmp_ppd_sendctrl);
4243 qib_write_kreg(dd, kr_scratch, 0);
4246 tmp_dd_sendctrl = dd->sendctrl;
4248 if (op & QIB_SENDCTRL_DISARM)
4249 tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Disarm) |
4250 ((op & QIB_7322_SendCtrl_DisarmSendBuf_RMASK) <<
4251 SYM_LSB(SendCtrl, DisarmSendBuf));
4252 if ((op & QIB_SENDCTRL_AVAIL_BLIP) &&
4253 (dd->sendctrl & SYM_MASK(SendCtrl, SendBufAvailUpd)))
4254 tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
4256 if (op == 0 || (op & SENDCTRL_COMMON_MODS)) {
4257 qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl);
4258 qib_write_kreg(dd, kr_scratch, 0);
4261 if (op == 0 || (op & SENDCTRL_PORT_MODS)) {
4262 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
4263 qib_write_kreg(dd, kr_scratch, 0);
4266 if (op & QIB_SENDCTRL_AVAIL_BLIP) {
4267 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
4268 qib_write_kreg(dd, kr_scratch, 0);
4271 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
4273 if (op & QIB_SENDCTRL_FLUSH) {
4276 * ensure writes have hit chip, then do a few
4277 * more reads, to allow DMA of pioavail registers
4278 * to occur, so in-memory copy is in sync with
4279 * the chip. Not always safe to sleep.
4281 v = qib_read_kreg32(dd, kr_scratch);
4282 qib_write_kreg(dd, kr_scratch, v);
4283 v = qib_read_kreg32(dd, kr_scratch);
4284 qib_write_kreg(dd, kr_scratch, v);
4285 qib_read_kreg32(dd, kr_scratch);
4289 #define _PORT_VIRT_FLAG 0x8000U /* "virtual", need adjustments */
4290 #define _PORT_64BIT_FLAG 0x10000U /* not "virtual", but 64bit */
4291 #define _PORT_CNTR_IDXMASK 0x7fffU /* mask off flags above */
4294 * qib_portcntr_7322 - read a per-port chip counter
4295 * @ppd: the qlogic_ib pport
4296 * @creg: the counter to read (not a chip offset)
4298 static u64 qib_portcntr_7322(struct qib_pportdata *ppd, u32 reg)
4300 struct qib_devdata *dd = ppd->dd;
4303 /* 0xffff for unimplemented or synthesized counters */
4304 static const u32 xlator[] = {
4305 [QIBPORTCNTR_PKTSEND] = crp_pktsend | _PORT_64BIT_FLAG,
4306 [QIBPORTCNTR_WORDSEND] = crp_wordsend | _PORT_64BIT_FLAG,
4307 [QIBPORTCNTR_PSXMITDATA] = crp_psxmitdatacount,
4308 [QIBPORTCNTR_PSXMITPKTS] = crp_psxmitpktscount,
4309 [QIBPORTCNTR_PSXMITWAIT] = crp_psxmitwaitcount,
4310 [QIBPORTCNTR_SENDSTALL] = crp_sendstall,
4311 [QIBPORTCNTR_PKTRCV] = crp_pktrcv | _PORT_64BIT_FLAG,
4312 [QIBPORTCNTR_PSRCVDATA] = crp_psrcvdatacount,
4313 [QIBPORTCNTR_PSRCVPKTS] = crp_psrcvpktscount,
4314 [QIBPORTCNTR_RCVEBP] = crp_rcvebp,
4315 [QIBPORTCNTR_RCVOVFL] = crp_rcvovfl,
4316 [QIBPORTCNTR_WORDRCV] = crp_wordrcv | _PORT_64BIT_FLAG,
4317 [QIBPORTCNTR_RXDROPPKT] = 0xffff, /* not needed for 7322 */
4318 [QIBPORTCNTR_RXLOCALPHYERR] = crp_rxotherlocalphyerr,
4319 [QIBPORTCNTR_RXVLERR] = crp_rxvlerr,
4320 [QIBPORTCNTR_ERRICRC] = crp_erricrc,
4321 [QIBPORTCNTR_ERRVCRC] = crp_errvcrc,
4322 [QIBPORTCNTR_ERRLPCRC] = crp_errlpcrc,
4323 [QIBPORTCNTR_BADFORMAT] = crp_badformat,
4324 [QIBPORTCNTR_ERR_RLEN] = crp_err_rlen,
4325 [QIBPORTCNTR_IBSYMBOLERR] = crp_ibsymbolerr,
4326 [QIBPORTCNTR_INVALIDRLEN] = crp_invalidrlen,
4327 [QIBPORTCNTR_UNSUPVL] = crp_txunsupvl,
4328 [QIBPORTCNTR_EXCESSBUFOVFL] = crp_excessbufferovfl,
4329 [QIBPORTCNTR_ERRLINK] = crp_errlink,
4330 [QIBPORTCNTR_IBLINKDOWN] = crp_iblinkdown,
4331 [QIBPORTCNTR_IBLINKERRRECOV] = crp_iblinkerrrecov,
4332 [QIBPORTCNTR_LLI] = crp_locallinkintegrityerr,
4333 [QIBPORTCNTR_VL15PKTDROP] = crp_vl15droppedpkt,
4334 [QIBPORTCNTR_ERRPKEY] = crp_errpkey,
4336 * the next 3 aren't really counters, but were implemented
4337 * as counters in older chips, so still get accessed as
4338 * though they were counters from this code.
4340 [QIBPORTCNTR_PSINTERVAL] = krp_psinterval,
4341 [QIBPORTCNTR_PSSTART] = krp_psstart,
4342 [QIBPORTCNTR_PSSTAT] = krp_psstat,
4343 /* pseudo-counter, summed for all ports */
4344 [QIBPORTCNTR_KHDROVFL] = 0xffff,
4347 if (reg >= ARRAY_SIZE(xlator)) {
4348 qib_devinfo(ppd->dd->pcidev,
4349 "Unimplemented portcounter %u\n", reg);
4352 creg = xlator[reg] & _PORT_CNTR_IDXMASK;
4354 /* handle non-counters and special cases first */
4355 if (reg == QIBPORTCNTR_KHDROVFL) {
4358 /* sum over all kernel contexts (skip if mini_init) */
4359 for (i = 0; dd->rcd && i < dd->first_user_ctxt; i++) {
4360 struct qib_ctxtdata *rcd = dd->rcd[i];
4362 if (!rcd || rcd->ppd != ppd)
4364 ret += read_7322_creg32(dd, cr_base_egrovfl + i);
4367 } else if (reg == QIBPORTCNTR_RXDROPPKT) {
4369 * Used as part of the synthesis of port_rcv_errors
4370 * in the verbs code for IBTA counters. Not needed for 7322,
4371 * because all the errors are already counted by other cntrs.
4374 } else if (reg == QIBPORTCNTR_PSINTERVAL ||
4375 reg == QIBPORTCNTR_PSSTART || reg == QIBPORTCNTR_PSSTAT) {
4376 /* were counters in older chips, now per-port kernel regs */
4377 ret = qib_read_kreg_port(ppd, creg);
4382 * Only fast increment counters are 64 bits; use 32 bit reads to
4383 * avoid two independent reads when on Opteron.
4385 if (xlator[reg] & _PORT_64BIT_FLAG)
4386 ret = read_7322_creg_port(ppd, creg);
4388 ret = read_7322_creg32_port(ppd, creg);
4389 if (creg == crp_ibsymbolerr) {
4390 if (ppd->cpspec->ibdeltainprog)
4391 ret -= ret - ppd->cpspec->ibsymsnap;
4392 ret -= ppd->cpspec->ibsymdelta;
4393 } else if (creg == crp_iblinkerrrecov) {
4394 if (ppd->cpspec->ibdeltainprog)
4395 ret -= ret - ppd->cpspec->iblnkerrsnap;
4396 ret -= ppd->cpspec->iblnkerrdelta;
4397 } else if (creg == crp_errlink)
4398 ret -= ppd->cpspec->ibmalfdelta;
4399 else if (creg == crp_iblinkdown)
4400 ret += ppd->cpspec->iblnkdowndelta;
4406 * Device counter names (not port-specific), one line per stat,
4407 * single string. Used by utilities like ipathstats to print the stats
4408 * in a way which works for different versions of drivers, without changing
4409 * the utility. Names need to be 12 chars or less (w/o newline), for proper
4410 * display by utility.
4411 * Non-error counters are first.
4412 * Start of "error" conters is indicated by a leading "E " on the first
4413 * "error" counter, and doesn't count in label length.
4414 * The EgrOvfl list needs to be last so we truncate them at the configured
4415 * context count for the device.
4416 * cntr7322indices contains the corresponding register indices.
4418 static const char cntr7322names[] =
4423 "RxTIDFloDrop\n" /* 7322 only */
4444 static const u32 cntr7322indices[] = {
4445 cr_lbint | _PORT_64BIT_FLAG,
4446 cr_lbstall | _PORT_64BIT_FLAG,
4450 cr_base_egrovfl + 0,
4451 cr_base_egrovfl + 1,
4452 cr_base_egrovfl + 2,
4453 cr_base_egrovfl + 3,
4454 cr_base_egrovfl + 4,
4455 cr_base_egrovfl + 5,
4456 cr_base_egrovfl + 6,
4457 cr_base_egrovfl + 7,
4458 cr_base_egrovfl + 8,
4459 cr_base_egrovfl + 9,
4460 cr_base_egrovfl + 10,
4461 cr_base_egrovfl + 11,
4462 cr_base_egrovfl + 12,
4463 cr_base_egrovfl + 13,
4464 cr_base_egrovfl + 14,
4465 cr_base_egrovfl + 15,
4466 cr_base_egrovfl + 16,
4467 cr_base_egrovfl + 17,
4471 * same as cntr7322names and cntr7322indices, but for port-specific counters.
4472 * portcntr7322indices is somewhat complicated by some registers needing
4473 * adjustments of various kinds, and those are ORed with _PORT_VIRT_FLAG
4475 static const char portcntr7322names[] =
4483 "TxDmaDesc\n" /* 7220 and 7322-only */
4484 "E RxDlidFltr\n" /* 7220 and 7322-only */
4507 "RxLclPhyErr\n" /* 7220 and 7322-only from here down */
4511 "RxQPBadCtxt\n" /* 7322-only from here down */
4515 static const u32 portcntr7322indices[] = {
4516 QIBPORTCNTR_PKTSEND | _PORT_VIRT_FLAG,
4518 QIBPORTCNTR_WORDSEND | _PORT_VIRT_FLAG,
4519 QIBPORTCNTR_PKTRCV | _PORT_VIRT_FLAG,
4521 QIBPORTCNTR_WORDRCV | _PORT_VIRT_FLAG,
4522 QIBPORTCNTR_SENDSTALL | _PORT_VIRT_FLAG,
4523 crp_txsdmadesc | _PORT_64BIT_FLAG,
4526 QIBPORTCNTR_IBLINKDOWN | _PORT_VIRT_FLAG,
4527 QIBPORTCNTR_IBLINKERRRECOV | _PORT_VIRT_FLAG,
4528 QIBPORTCNTR_ERRLINK | _PORT_VIRT_FLAG,
4529 QIBPORTCNTR_IBSYMBOLERR | _PORT_VIRT_FLAG,
4530 QIBPORTCNTR_LLI | _PORT_VIRT_FLAG,
4531 QIBPORTCNTR_BADFORMAT | _PORT_VIRT_FLAG,
4532 QIBPORTCNTR_ERR_RLEN | _PORT_VIRT_FLAG,
4533 QIBPORTCNTR_RCVOVFL | _PORT_VIRT_FLAG,
4534 QIBPORTCNTR_RCVEBP | _PORT_VIRT_FLAG,
4535 crp_rcvflowctrlviol,
4536 QIBPORTCNTR_ERRICRC | _PORT_VIRT_FLAG,
4537 QIBPORTCNTR_ERRLPCRC | _PORT_VIRT_FLAG,
4538 QIBPORTCNTR_ERRVCRC | _PORT_VIRT_FLAG,
4539 QIBPORTCNTR_INVALIDRLEN | _PORT_VIRT_FLAG,
4540 QIBPORTCNTR_ERRPKEY | _PORT_VIRT_FLAG,
4541 QIBPORTCNTR_RXDROPPKT | _PORT_VIRT_FLAG,
4547 QIBPORTCNTR_RXLOCALPHYERR | _PORT_VIRT_FLAG,
4548 QIBPORTCNTR_VL15PKTDROP | _PORT_VIRT_FLAG,
4549 QIBPORTCNTR_RXVLERR | _PORT_VIRT_FLAG,
4550 QIBPORTCNTR_EXCESSBUFOVFL | _PORT_VIRT_FLAG,
4551 crp_rxqpinvalidctxt,
4555 /* do all the setup to make the counter reads efficient later */
4556 static void init_7322_cntrnames(struct qib_devdata *dd)
4561 for (i = 0, s = (char *)cntr7322names; s && j <= dd->cfgctxts;
4563 /* we always have at least one counter before the egrovfl */
4564 if (!j && !strncmp("Ctxt0EgrOvfl", s + 1, 12))
4566 s = strchr(s + 1, '\n');
4570 dd->cspec->ncntrs = i;
4572 /* full list; size is without terminating null */
4573 dd->cspec->cntrnamelen = sizeof(cntr7322names) - 1;
4575 dd->cspec->cntrnamelen = 1 + s - cntr7322names;
4576 dd->cspec->cntrs = kmalloc(dd->cspec->ncntrs
4577 * sizeof(u64), GFP_KERNEL);
4578 if (!dd->cspec->cntrs)
4579 qib_dev_err(dd, "Failed allocation for counters\n");
4581 for (i = 0, s = (char *)portcntr7322names; s; i++)
4582 s = strchr(s + 1, '\n');
4583 dd->cspec->nportcntrs = i - 1;
4584 dd->cspec->portcntrnamelen = sizeof(portcntr7322names) - 1;
4585 for (i = 0; i < dd->num_pports; ++i) {
4586 dd->pport[i].cpspec->portcntrs = kmalloc(dd->cspec->nportcntrs
4587 * sizeof(u64), GFP_KERNEL);
4588 if (!dd->pport[i].cpspec->portcntrs)
4589 qib_dev_err(dd, "Failed allocation for"
4594 static u32 qib_read_7322cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
4600 ret = dd->cspec->cntrnamelen;
4602 ret = 0; /* final read after getting everything */
4604 *namep = (char *) cntr7322names;
4606 u64 *cntr = dd->cspec->cntrs;
4609 ret = dd->cspec->ncntrs * sizeof(u64);
4610 if (!cntr || pos >= ret) {
4611 /* everything read, or couldn't get memory */
4616 for (i = 0; i < dd->cspec->ncntrs; i++)
4617 if (cntr7322indices[i] & _PORT_64BIT_FLAG)
4618 *cntr++ = read_7322_creg(dd,
4619 cntr7322indices[i] &
4620 _PORT_CNTR_IDXMASK);
4622 *cntr++ = read_7322_creg32(dd,
4623 cntr7322indices[i]);
4629 static u32 qib_read_7322portcntrs(struct qib_devdata *dd, loff_t pos, u32 port,
4630 char **namep, u64 **cntrp)
4635 ret = dd->cspec->portcntrnamelen;
4637 ret = 0; /* final read after getting everything */
4639 *namep = (char *)portcntr7322names;
4641 struct qib_pportdata *ppd = &dd->pport[port];
4642 u64 *cntr = ppd->cpspec->portcntrs;
4645 ret = dd->cspec->nportcntrs * sizeof(u64);
4646 if (!cntr || pos >= ret) {
4647 /* everything read, or couldn't get memory */
4652 for (i = 0; i < dd->cspec->nportcntrs; i++) {
4653 if (portcntr7322indices[i] & _PORT_VIRT_FLAG)
4654 *cntr++ = qib_portcntr_7322(ppd,
4655 portcntr7322indices[i] &
4656 _PORT_CNTR_IDXMASK);
4657 else if (portcntr7322indices[i] & _PORT_64BIT_FLAG)
4658 *cntr++ = read_7322_creg_port(ppd,
4659 portcntr7322indices[i] &
4660 _PORT_CNTR_IDXMASK);
4662 *cntr++ = read_7322_creg32_port(ppd,
4663 portcntr7322indices[i]);
4671 * qib_get_7322_faststats - get word counters from chip before they overflow
4672 * @opaque - contains a pointer to the qlogic_ib device qib_devdata
4674 * VESTIGIAL IBA7322 has no "small fast counters", so the only
4675 * real purpose of this function is to maintain the notion of
4676 * "active time", which in turn is only logged into the eeprom,
4677 * which we don;t have, yet, for 7322-based boards.
4679 * called from add_timer
4681 static void qib_get_7322_faststats(unsigned long opaque)
4683 struct qib_devdata *dd = (struct qib_devdata *) opaque;
4684 struct qib_pportdata *ppd;
4685 unsigned long flags;
4689 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
4690 ppd = dd->pport + pidx;
4693 * If port isn't enabled or not operational ports, or
4694 * diags is running (can cause memory diags to fail)
4695 * skip this port this time.
4697 if (!ppd->link_speed_supported || !(dd->flags & QIB_INITTED)
4702 * Maintain an activity timer, based on traffic
4703 * exceeding a threshold, so we need to check the word-counts
4704 * even if they are 64-bit.
4706 traffic_wds = qib_portcntr_7322(ppd, QIBPORTCNTR_WORDRCV) +
4707 qib_portcntr_7322(ppd, QIBPORTCNTR_WORDSEND);
4708 spin_lock_irqsave(&ppd->dd->eep_st_lock, flags);
4709 traffic_wds -= ppd->dd->traffic_wds;
4710 ppd->dd->traffic_wds += traffic_wds;
4711 if (traffic_wds >= QIB_TRAFFIC_ACTIVE_THRESHOLD)
4712 atomic_add(ACTIVITY_TIMER, &ppd->dd->active_time);
4713 spin_unlock_irqrestore(&ppd->dd->eep_st_lock, flags);
4714 if (ppd->cpspec->qdr_dfe_on && (ppd->link_speed_active &
4716 (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
4717 QIBL_LINKACTIVE)) &&
4718 ppd->cpspec->qdr_dfe_time &&
4719 time_after64(get_jiffies_64(), ppd->cpspec->qdr_dfe_time)) {
4720 ppd->cpspec->qdr_dfe_on = 0;
4722 qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
4723 ppd->dd->cspec->r1 ?
4724 QDR_STATIC_ADAPT_INIT_R1 :
4725 QDR_STATIC_ADAPT_INIT);
4729 mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);
4733 * If we were using MSIx, try to fallback to INTx.
4735 static int qib_7322_intr_fallback(struct qib_devdata *dd)
4737 if (!dd->cspec->num_msix_entries)
4738 return 0; /* already using INTx */
4740 qib_devinfo(dd->pcidev, "MSIx interrupt not detected,"
4741 " trying INTx interrupts\n");
4742 qib_7322_nomsix(dd);
4743 qib_enable_intx(dd->pcidev);
4744 qib_setup_7322_interrupt(dd, 0);
4749 * Reset the XGXS (between serdes and IBC). Slightly less intrusive
4750 * than resetting the IBC or external link state, and useful in some
4751 * cases to cause some retraining. To do this right, we reset IBC
4752 * as well, then return to previous state (which may be still in reset)
4753 * NOTE: some callers of this "know" this writes the current value
4754 * of cpspec->ibcctrl_a as part of it's operation, so if that changes,
4755 * check all callers.
4757 static void qib_7322_mini_pcs_reset(struct qib_pportdata *ppd)
4760 struct qib_devdata *dd = ppd->dd;
4761 const u64 reset_bits = SYM_MASK(IBPCSConfig_0, xcv_rreset) |
4762 SYM_MASK(IBPCSConfig_0, xcv_treset) |
4763 SYM_MASK(IBPCSConfig_0, tx_rx_reset);
4765 val = qib_read_kreg_port(ppd, krp_ib_pcsconfig);
4766 qib_write_kreg_port(ppd, krp_ibcctrl_a,
4767 ppd->cpspec->ibcctrl_a &
4768 ~SYM_MASK(IBCCtrlA_0, IBLinkEn));
4770 qib_write_kreg_port(ppd, krp_ib_pcsconfig, val | reset_bits);
4771 qib_read_kreg32(dd, kr_scratch);
4772 qib_write_kreg_port(ppd, krp_ib_pcsconfig, val & ~reset_bits);
4773 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
4774 qib_write_kreg(dd, kr_scratch, 0ULL);
4778 * This code for non-IBTA-compliant IB speed negotiation is only known to
4779 * work for the SDR to DDR transition, and only between an HCA and a switch
4780 * with recent firmware. It is based on observed heuristics, rather than
4781 * actual knowledge of the non-compliant speed negotiation.
4782 * It has a number of hard-coded fields, since the hope is to rewrite this
4783 * when a spec is available on how the negoation is intended to work.
4785 static void autoneg_7322_sendpkt(struct qib_pportdata *ppd, u32 *hdr,
4786 u32 dcnt, u32 *data)
4790 u32 __iomem *piobuf;
4791 u32 pnum, control, len;
4792 struct qib_devdata *dd = ppd->dd;
4795 len = 7 + dcnt + 1; /* 7 dword header, dword data, icrc */
4796 control = qib_7322_setpbc_control(ppd, len, 0, 15);
4797 pbc = ((u64) control << 32) | len;
4798 while (!(piobuf = qib_7322_getsendbuf(ppd, pbc, &pnum))) {
4803 /* disable header check on this packet, since it can't be valid */
4804 dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_DIS1, NULL);
4805 writeq(pbc, piobuf);
4807 qib_pio_copy(piobuf + 2, hdr, 7);
4808 qib_pio_copy(piobuf + 9, data, dcnt);
4809 if (dd->flags & QIB_USE_SPCL_TRIG) {
4810 u32 spcl_off = (pnum >= dd->piobcnt2k) ? 2047 : 1023;
4813 __raw_writel(0xaebecede, piobuf + spcl_off);
4816 qib_sendbuf_done(dd, pnum);
4817 /* and re-enable hdr check */
4818 dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_ENAB1, NULL);
4822 * _start packet gets sent twice at start, _done gets sent twice at end
4824 static void qib_autoneg_7322_send(struct qib_pportdata *ppd, int which)
4826 struct qib_devdata *dd = ppd->dd;
4828 u32 dw, i, hcnt, dcnt, *data;
4829 static u32 hdr[7] = { 0xf002ffff, 0x48ffff, 0x6400abba };
4830 static u32 madpayload_start[0x40] = {
4831 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
4832 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
4833 0x1, 0x1388, 0x15e, 0x1, /* rest 0's */
4835 static u32 madpayload_done[0x40] = {
4836 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
4837 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
4838 0x40000001, 0x1388, 0x15e, /* rest 0's */
4841 dcnt = ARRAY_SIZE(madpayload_start);
4842 hcnt = ARRAY_SIZE(hdr);
4844 /* for maintainability, do it at runtime */
4845 for (i = 0; i < hcnt; i++) {
4846 dw = (__force u32) cpu_to_be32(hdr[i]);
4849 for (i = 0; i < dcnt; i++) {
4850 dw = (__force u32) cpu_to_be32(madpayload_start[i]);
4851 madpayload_start[i] = dw;
4852 dw = (__force u32) cpu_to_be32(madpayload_done[i]);
4853 madpayload_done[i] = dw;
4858 data = which ? madpayload_done : madpayload_start;
4860 autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
4861 qib_read_kreg64(dd, kr_scratch);
4863 autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
4864 qib_read_kreg64(dd, kr_scratch);
4869 * Do the absolute minimum to cause an IB speed change, and make it
4870 * ready, but don't actually trigger the change. The caller will
4871 * do that when ready (if link is in Polling training state, it will
4872 * happen immediately, otherwise when link next goes down)
4874 * This routine should only be used as part of the DDR autonegotation
4875 * code for devices that are not compliant with IB 1.2 (or code that
4876 * fixes things up for same).
4878 * When link has gone down, and autoneg enabled, or autoneg has
4879 * failed and we give up until next time we set both speeds, and
4880 * then we want IBTA enabled as well as "use max enabled speed.
4882 static void set_7322_ibspeed_fast(struct qib_pportdata *ppd, u32 speed)
4885 newctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_SPEED_MASK |
4886 IBA7322_IBC_IBTA_1_2_MASK |
4887 IBA7322_IBC_MAX_SPEED_MASK);
4889 if (speed & (speed - 1)) /* multiple speeds */
4890 newctrlb |= (speed << IBA7322_IBC_SPEED_LSB) |
4891 IBA7322_IBC_IBTA_1_2_MASK |
4892 IBA7322_IBC_MAX_SPEED_MASK;
4894 newctrlb |= speed == QIB_IB_QDR ?
4895 IBA7322_IBC_SPEED_QDR | IBA7322_IBC_IBTA_1_2_MASK :
4896 ((speed == QIB_IB_DDR ?
4897 IBA7322_IBC_SPEED_DDR : IBA7322_IBC_SPEED_SDR));
4899 if (newctrlb == ppd->cpspec->ibcctrl_b)
4902 ppd->cpspec->ibcctrl_b = newctrlb;
4903 qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
4904 qib_write_kreg(ppd->dd, kr_scratch, 0);
4908 * This routine is only used when we are not talking to another
4909 * IB 1.2-compliant device that we think can do DDR.
4910 * (This includes all existing switch chips as of Oct 2007.)
4911 * 1.2-compliant devices go directly to DDR prior to reaching INIT
4913 static void try_7322_autoneg(struct qib_pportdata *ppd)
4915 unsigned long flags;
4917 spin_lock_irqsave(&ppd->lflags_lock, flags);
4918 ppd->lflags |= QIBL_IB_AUTONEG_INPROG;
4919 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
4920 qib_autoneg_7322_send(ppd, 0);
4921 set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
4922 qib_7322_mini_pcs_reset(ppd);
4923 /* 2 msec is minimum length of a poll cycle */
4924 schedule_delayed_work(&ppd->cpspec->autoneg_work,
4925 msecs_to_jiffies(2));
4929 * Handle the empirically determined mechanism for auto-negotiation
4930 * of DDR speed with switches.
4932 static void autoneg_7322_work(struct work_struct *work)
4934 struct qib_pportdata *ppd;
4935 struct qib_devdata *dd;
4938 unsigned long flags;
4940 ppd = container_of(work, struct qib_chippport_specific,
4941 autoneg_work.work)->ppd;
4944 startms = jiffies_to_msecs(jiffies);
4947 * Busy wait for this first part, it should be at most a
4948 * few hundred usec, since we scheduled ourselves for 2msec.
4950 for (i = 0; i < 25; i++) {
4951 if (SYM_FIELD(ppd->lastibcstat, IBCStatusA_0, LinkState)
4952 == IB_7322_LT_STATE_POLLQUIET) {
4953 qib_set_linkstate(ppd, QIB_IB_LINKDOWN_DISABLE);
4959 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
4960 goto done; /* we got there early or told to stop */
4962 /* we expect this to timeout */
4963 if (wait_event_timeout(ppd->cpspec->autoneg_wait,
4964 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
4965 msecs_to_jiffies(90)))
4967 qib_7322_mini_pcs_reset(ppd);
4969 /* we expect this to timeout */
4970 if (wait_event_timeout(ppd->cpspec->autoneg_wait,
4971 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
4972 msecs_to_jiffies(1700)))
4974 qib_7322_mini_pcs_reset(ppd);
4976 set_7322_ibspeed_fast(ppd, QIB_IB_SDR);
4979 * Wait up to 250 msec for link to train and get to INIT at DDR;
4980 * this should terminate early.
4982 wait_event_timeout(ppd->cpspec->autoneg_wait,
4983 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
4984 msecs_to_jiffies(250));
4986 if (ppd->lflags & QIBL_IB_AUTONEG_INPROG) {
4987 spin_lock_irqsave(&ppd->lflags_lock, flags);
4988 ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
4989 if (ppd->cpspec->autoneg_tries == AUTONEG_TRIES) {
4990 ppd->lflags |= QIBL_IB_AUTONEG_FAILED;
4991 ppd->cpspec->autoneg_tries = 0;
4993 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
4994 set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
4999 * This routine is used to request IPG set in the QLogic switch.
5000 * Only called if r1.
5002 static void try_7322_ipg(struct qib_pportdata *ppd)
5004 struct qib_ibport *ibp = &ppd->ibport_data;
5005 struct ib_mad_send_buf *send_buf;
5006 struct ib_mad_agent *agent;
5011 agent = ibp->send_agent;
5015 send_buf = ib_create_send_mad(agent, 0, 0, 0, IB_MGMT_MAD_HDR,
5016 IB_MGMT_MAD_DATA, GFP_ATOMIC);
5017 if (IS_ERR(send_buf))
5021 struct ib_ah_attr attr;
5024 memset(&attr, 0, sizeof attr);
5025 attr.dlid = be16_to_cpu(IB_LID_PERMISSIVE);
5026 attr.port_num = ppd->port;
5027 ah = ib_create_ah(ibp->qp0->ibqp.pd, &attr);
5032 ibp->smi_ah = to_iah(ah);
5036 send_buf->ah = &ibp->smi_ah->ibah;
5040 smp = send_buf->mad;
5041 smp->base_version = IB_MGMT_BASE_VERSION;
5042 smp->mgmt_class = IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE;
5043 smp->class_version = 1;
5044 smp->method = IB_MGMT_METHOD_SEND;
5046 smp->attr_id = QIB_VENDOR_IPG;
5050 ret = ib_post_send_mad(send_buf, NULL);
5052 ib_free_send_mad(send_buf);
5054 delay = 2 << ppd->cpspec->ipg_tries;
5055 schedule_delayed_work(&ppd->cpspec->ipg_work, msecs_to_jiffies(delay));
5059 * Timeout handler for setting IPG.
5060 * Only called if r1.
5062 static void ipg_7322_work(struct work_struct *work)
5064 struct qib_pportdata *ppd;
5066 ppd = container_of(work, struct qib_chippport_specific,
5067 ipg_work.work)->ppd;
5068 if ((ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED | QIBL_LINKACTIVE))
5069 && ++ppd->cpspec->ipg_tries <= 10)
5073 static u32 qib_7322_iblink_state(u64 ibcs)
5075 u32 state = (u32)SYM_FIELD(ibcs, IBCStatusA_0, LinkState);
5078 case IB_7322_L_STATE_INIT:
5079 state = IB_PORT_INIT;
5081 case IB_7322_L_STATE_ARM:
5082 state = IB_PORT_ARMED;
5084 case IB_7322_L_STATE_ACTIVE:
5086 case IB_7322_L_STATE_ACT_DEFER:
5087 state = IB_PORT_ACTIVE;
5089 default: /* fall through */
5090 case IB_7322_L_STATE_DOWN:
5091 state = IB_PORT_DOWN;
5097 /* returns the IBTA port state, rather than the IBC link training state */
5098 static u8 qib_7322_phys_portstate(u64 ibcs)
5100 u8 state = (u8)SYM_FIELD(ibcs, IBCStatusA_0, LinkTrainingState);
5101 return qib_7322_physportstate[state];
5104 static int qib_7322_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
5106 int ret = 0, symadj = 0;
5107 unsigned long flags;
5110 spin_lock_irqsave(&ppd->lflags_lock, flags);
5111 ppd->lflags &= ~QIBL_IB_FORCE_NOTIFY;
5112 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5114 /* Update our picture of width and speed from chip */
5115 if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedQDR)) {
5116 ppd->link_speed_active = QIB_IB_QDR;
5118 } else if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedActive)) {
5119 ppd->link_speed_active = QIB_IB_DDR;
5122 ppd->link_speed_active = QIB_IB_SDR;
5125 if (ibcs & SYM_MASK(IBCStatusA_0, LinkWidthActive)) {
5126 ppd->link_width_active = IB_WIDTH_4X;
5129 ppd->link_width_active = IB_WIDTH_1X;
5130 ppd->delay_mult = ib_rate_to_delay[mult_to_ib_rate(mult)];
5135 /* Link went down. */
5136 /* do IPG MAD again after linkdown, even if last time failed */
5137 ppd->cpspec->ipg_tries = 0;
5138 clr = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
5139 (SYM_MASK(IBCStatusB_0, heartbeat_timed_out) |
5140 SYM_MASK(IBCStatusB_0, heartbeat_crosstalk));
5142 qib_write_kreg_port(ppd, krp_ibcstatus_b, clr);
5143 if (!(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
5144 QIBL_IB_AUTONEG_INPROG)))
5145 set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
5146 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
5147 /* unlock the Tx settings, speed may change */
5148 qib_write_kreg_port(ppd, krp_tx_deemph_override,
5149 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
5150 reset_tx_deemphasis_override));
5151 qib_cancel_sends(ppd);
5152 /* on link down, ensure sane pcs state */
5153 qib_7322_mini_pcs_reset(ppd);
5154 spin_lock_irqsave(&ppd->sdma_lock, flags);
5155 if (__qib_sdma_running(ppd))
5156 __qib_sdma_process_event(ppd,
5157 qib_sdma_event_e70_go_idle);
5158 spin_unlock_irqrestore(&ppd->sdma_lock, flags);
5160 clr = read_7322_creg32_port(ppd, crp_iblinkdown);
5161 if (clr == ppd->cpspec->iblnkdownsnap)
5162 ppd->cpspec->iblnkdowndelta++;
5164 if (qib_compat_ddr_negotiate &&
5165 !(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
5166 QIBL_IB_AUTONEG_INPROG)) &&
5167 ppd->link_speed_active == QIB_IB_SDR &&
5168 (ppd->link_speed_enabled & QIB_IB_DDR)
5169 && ppd->cpspec->autoneg_tries < AUTONEG_TRIES) {
5170 /* we are SDR, and auto-negotiation enabled */
5171 ++ppd->cpspec->autoneg_tries;
5172 if (!ppd->cpspec->ibdeltainprog) {
5173 ppd->cpspec->ibdeltainprog = 1;
5174 ppd->cpspec->ibsymdelta +=
5175 read_7322_creg32_port(ppd,
5177 ppd->cpspec->ibsymsnap;
5178 ppd->cpspec->iblnkerrdelta +=
5179 read_7322_creg32_port(ppd,
5180 crp_iblinkerrrecov) -
5181 ppd->cpspec->iblnkerrsnap;
5183 try_7322_autoneg(ppd);
5184 ret = 1; /* no other IB status change processing */
5185 } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
5186 ppd->link_speed_active == QIB_IB_SDR) {
5187 qib_autoneg_7322_send(ppd, 1);
5188 set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
5189 qib_7322_mini_pcs_reset(ppd);
5191 ret = 1; /* no other IB status change processing */
5192 } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
5193 (ppd->link_speed_active & QIB_IB_DDR)) {
5194 spin_lock_irqsave(&ppd->lflags_lock, flags);
5195 ppd->lflags &= ~(QIBL_IB_AUTONEG_INPROG |
5196 QIBL_IB_AUTONEG_FAILED);
5197 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5198 ppd->cpspec->autoneg_tries = 0;
5199 /* re-enable SDR, for next link down */
5200 set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
5201 wake_up(&ppd->cpspec->autoneg_wait);
5203 } else if (ppd->lflags & QIBL_IB_AUTONEG_FAILED) {
5205 * Clear autoneg failure flag, and do setup
5206 * so we'll try next time link goes down and
5207 * back to INIT (possibly connected to a
5208 * different device).
5210 spin_lock_irqsave(&ppd->lflags_lock, flags);
5211 ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
5212 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5213 ppd->cpspec->ibcctrl_b |= IBA7322_IBC_IBTA_1_2_MASK;
5216 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
5218 if (ppd->dd->cspec->r1 && ppd->cpspec->ipg_tries <= 10)
5220 if (!ppd->cpspec->recovery_init)
5221 setup_7322_link_recovery(ppd, 0);
5222 ppd->cpspec->qdr_dfe_time = jiffies +
5223 msecs_to_jiffies(QDR_DFE_DISABLE_DELAY);
5225 ppd->cpspec->ibmalfusesnap = 0;
5226 ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
5230 ppd->cpspec->iblnkdownsnap =
5231 read_7322_creg32_port(ppd, crp_iblinkdown);
5232 if (ppd->cpspec->ibdeltainprog) {
5233 ppd->cpspec->ibdeltainprog = 0;
5234 ppd->cpspec->ibsymdelta += read_7322_creg32_port(ppd,
5235 crp_ibsymbolerr) - ppd->cpspec->ibsymsnap;
5236 ppd->cpspec->iblnkerrdelta += read_7322_creg32_port(ppd,
5237 crp_iblinkerrrecov) - ppd->cpspec->iblnkerrsnap;
5239 } else if (!ibup && qib_compat_ddr_negotiate &&
5240 !ppd->cpspec->ibdeltainprog &&
5241 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
5242 ppd->cpspec->ibdeltainprog = 1;
5243 ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
5245 ppd->cpspec->iblnkerrsnap = read_7322_creg32_port(ppd,
5246 crp_iblinkerrrecov);
5250 qib_setup_7322_setextled(ppd, ibup);
5255 * Does read/modify/write to appropriate registers to
5256 * set output and direction bits selected by mask.
5257 * these are in their canonical postions (e.g. lsb of
5258 * dir will end up in D48 of extctrl on existing chips).
5259 * returns contents of GP Inputs.
5261 static int gpio_7322_mod(struct qib_devdata *dd, u32 out, u32 dir, u32 mask)
5263 u64 read_val, new_out;
5264 unsigned long flags;
5267 /* some bits being written, lock access to GPIO */
5270 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
5271 dd->cspec->extctrl &= ~((u64)mask << SYM_LSB(EXTCtrl, GPIOOe));
5272 dd->cspec->extctrl |= ((u64) dir << SYM_LSB(EXTCtrl, GPIOOe));
5273 new_out = (dd->cspec->gpio_out & ~mask) | out;
5275 qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
5276 qib_write_kreg(dd, kr_gpio_out, new_out);
5277 dd->cspec->gpio_out = new_out;
5278 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
5281 * It is unlikely that a read at this time would get valid
5282 * data on a pin whose direction line was set in the same
5283 * call to this function. We include the read here because
5284 * that allows us to potentially combine a change on one pin with
5285 * a read on another, and because the old code did something like
5288 read_val = qib_read_kreg64(dd, kr_extstatus);
5289 return SYM_FIELD(read_val, EXTStatus, GPIOIn);
5292 /* Enable writes to config EEPROM, if possible. Returns previous state */
5293 static int qib_7322_eeprom_wen(struct qib_devdata *dd, int wen)
5298 mask = 1 << QIB_EEPROM_WEN_NUM;
5299 prev_wen = ~gpio_7322_mod(dd, 0, 0, 0) >> QIB_EEPROM_WEN_NUM;
5300 gpio_7322_mod(dd, wen ? 0 : mask, mask, mask);
5302 return prev_wen & 1;
5306 * Read fundamental info we need to use the chip. These are
5307 * the registers that describe chip capabilities, and are
5308 * saved in shadow registers.
5310 static void get_7322_chip_params(struct qib_devdata *dd)
5316 dd->palign = qib_read_kreg32(dd, kr_pagealign);
5318 dd->uregbase = qib_read_kreg32(dd, kr_userregbase);
5320 dd->rcvtidcnt = qib_read_kreg32(dd, kr_rcvtidcnt);
5321 dd->rcvtidbase = qib_read_kreg32(dd, kr_rcvtidbase);
5322 dd->rcvegrbase = qib_read_kreg32(dd, kr_rcvegrbase);
5323 dd->piobufbase = qib_read_kreg64(dd, kr_sendpiobufbase);
5324 dd->pio2k_bufbase = dd->piobufbase & 0xffffffff;
5326 val = qib_read_kreg64(dd, kr_sendpiobufcnt);
5327 dd->piobcnt2k = val & ~0U;
5328 dd->piobcnt4k = val >> 32;
5329 val = qib_read_kreg64(dd, kr_sendpiosize);
5330 dd->piosize2k = val & ~0U;
5331 dd->piosize4k = val >> 32;
5333 mtu = ib_mtu_enum_to_int(qib_ibmtu);
5335 mtu = QIB_DEFAULT_MTU;
5336 dd->pport[0].ibmtu = (u32)mtu;
5337 dd->pport[1].ibmtu = (u32)mtu;
5339 /* these may be adjusted in init_chip_wc_pat() */
5340 dd->pio2kbase = (u32 __iomem *)
5341 ((char __iomem *) dd->kregbase + dd->pio2k_bufbase);
5342 dd->pio4kbase = (u32 __iomem *)
5343 ((char __iomem *) dd->kregbase +
5344 (dd->piobufbase >> 32));
5346 * 4K buffers take 2 pages; we use roundup just to be
5347 * paranoid; we calculate it once here, rather than on
5350 dd->align4k = ALIGN(dd->piosize4k, dd->palign);
5352 piobufs = dd->piobcnt4k + dd->piobcnt2k + NUM_VL15_BUFS;
5354 dd->pioavregs = ALIGN(piobufs, sizeof(u64) * BITS_PER_BYTE / 2) /
5355 (sizeof(u64) * BITS_PER_BYTE / 2);
5359 * The chip base addresses in cspec and cpspec have to be set
5360 * after possible init_chip_wc_pat(), rather than in
5361 * get_7322_chip_params(), so split out as separate function
5363 static void qib_7322_set_baseaddrs(struct qib_devdata *dd)
5366 cregbase = qib_read_kreg32(dd, kr_counterregbase);
5368 dd->cspec->cregbase = (u64 __iomem *)(cregbase +
5369 (char __iomem *)dd->kregbase);
5371 dd->egrtidbase = (u64 __iomem *)
5372 ((char __iomem *) dd->kregbase + dd->rcvegrbase);
5374 /* port registers are defined as relative to base of chip */
5375 dd->pport[0].cpspec->kpregbase =
5376 (u64 __iomem *)((char __iomem *)dd->kregbase);
5377 dd->pport[1].cpspec->kpregbase =
5378 (u64 __iomem *)(dd->palign +
5379 (char __iomem *)dd->kregbase);
5380 dd->pport[0].cpspec->cpregbase =
5381 (u64 __iomem *)(qib_read_kreg_port(&dd->pport[0],
5382 kr_counterregbase) + (char __iomem *)dd->kregbase);
5383 dd->pport[1].cpspec->cpregbase =
5384 (u64 __iomem *)(qib_read_kreg_port(&dd->pport[1],
5385 kr_counterregbase) + (char __iomem *)dd->kregbase);
5389 * This is a fairly special-purpose observer, so we only support
5390 * the port-specific parts of SendCtrl
5393 #define SENDCTRL_SHADOWED (SYM_MASK(SendCtrl_0, SendEnable) | \
5394 SYM_MASK(SendCtrl_0, SDmaEnable) | \
5395 SYM_MASK(SendCtrl_0, SDmaIntEnable) | \
5396 SYM_MASK(SendCtrl_0, SDmaSingleDescriptor) | \
5397 SYM_MASK(SendCtrl_0, SDmaHalt) | \
5398 SYM_MASK(SendCtrl_0, IBVLArbiterEn) | \
5399 SYM_MASK(SendCtrl_0, ForceCreditUpToDate))
5401 static int sendctrl_hook(struct qib_devdata *dd,
5402 const struct diag_observer *op, u32 offs,
5403 u64 *data, u64 mask, int only_32)
5405 unsigned long flags;
5408 struct qib_pportdata *ppd = NULL;
5409 u64 local_data, all_bits;
5412 * The fixed correspondence between Physical ports and pports is
5413 * severed. We need to hunt for the ppd that corresponds
5414 * to the offset we got. And we have to do that without admitting
5415 * we know the stride, apparently.
5417 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
5421 ppd = dd->pport + pidx;
5422 if (!ppd->cpspec->kpregbase)
5425 psptr = ppd->cpspec->kpregbase + krp_sendctrl;
5426 psoffs = (u32) (psptr - dd->kregbase) * sizeof(*psptr);
5431 /* If pport is not being managed by driver, just avoid shadows. */
5432 if (pidx >= dd->num_pports)
5435 /* In any case, "idx" is flat index in kreg space */
5436 idx = offs / sizeof(u64);
5442 spin_lock_irqsave(&dd->sendctrl_lock, flags);
5443 if (!ppd || (mask & all_bits) != all_bits) {
5445 * At least some mask bits are zero, so we need
5446 * to read. The judgement call is whether from
5447 * reg or shadow. First-cut: read reg, and complain
5448 * if any bits which should be shadowed are different
5449 * from their shadowed value.
5452 local_data = (u64)qib_read_kreg32(dd, idx);
5454 local_data = qib_read_kreg64(dd, idx);
5455 *data = (local_data & ~mask) | (*data & mask);
5459 * At least some mask bits are one, so we need
5460 * to write, but only shadow some bits.
5462 u64 sval, tval; /* Shadowed, transient */
5465 * New shadow val is bits we don't want to touch,
5466 * ORed with bits we do, that are intended for shadow.
5469 sval = ppd->p_sendctrl & ~mask;
5470 sval |= *data & SENDCTRL_SHADOWED & mask;
5471 ppd->p_sendctrl = sval;
5473 sval = *data & SENDCTRL_SHADOWED & mask;
5474 tval = sval | (*data & ~SENDCTRL_SHADOWED & mask);
5475 qib_write_kreg(dd, idx, tval);
5476 qib_write_kreg(dd, kr_scratch, 0Ull);
5478 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
5479 return only_32 ? 4 : 8;
5482 static const struct diag_observer sendctrl_0_observer = {
5483 sendctrl_hook, KREG_IDX(SendCtrl_0) * sizeof(u64),
5484 KREG_IDX(SendCtrl_0) * sizeof(u64)
5487 static const struct diag_observer sendctrl_1_observer = {
5488 sendctrl_hook, KREG_IDX(SendCtrl_1) * sizeof(u64),
5489 KREG_IDX(SendCtrl_1) * sizeof(u64)
5492 static ushort sdma_fetch_prio = 8;
5493 module_param_named(sdma_fetch_prio, sdma_fetch_prio, ushort, S_IRUGO);
5494 MODULE_PARM_DESC(sdma_fetch_prio, "SDMA descriptor fetch priority");
5496 /* Besides logging QSFP events, we set appropriate TxDDS values */
5497 static void init_txdds_table(struct qib_pportdata *ppd, int override);
5499 static void qsfp_7322_event(struct work_struct *work)
5501 struct qib_qsfp_data *qd;
5502 struct qib_pportdata *ppd;
5507 qd = container_of(work, struct qib_qsfp_data, work);
5509 pwrup = qd->t_insert + msecs_to_jiffies(QSFP_PWR_LAG_MSEC);
5512 * Some QSFP's not only do not respond until the full power-up
5513 * time, but may behave badly if we try. So hold off responding
5517 u64 now = get_jiffies_64();
5518 if (time_after64(now, pwrup))
5522 ret = qib_refresh_qsfp_cache(ppd, &qd->cache);
5524 * Need to change LE2 back to defaults if we couldn't
5525 * read the cable type (to handle cable swaps), so do this
5526 * even on failure to read cable information. We don't
5527 * get here for QME, so IS_QME check not needed here.
5529 le2 = (!ret && qd->cache.atten[1] >= qib_long_atten &&
5530 !ppd->dd->cspec->r1 && QSFP_IS_CU(qd->cache.tech)) ?
5531 LE2_5m : LE2_DEFAULT;
5532 ibsd_wr_allchans(ppd, 13, (le2 << 7), BMASK(9, 7));
5533 init_txdds_table(ppd, 0);
5537 * There is little we can do but complain to the user if QSFP
5538 * initialization fails.
5540 static void qib_init_7322_qsfp(struct qib_pportdata *ppd)
5542 unsigned long flags;
5543 struct qib_qsfp_data *qd = &ppd->cpspec->qsfp_data;
5544 struct qib_devdata *dd = ppd->dd;
5545 u64 mod_prs_bit = QSFP_GPIO_MOD_PRS_N;
5547 mod_prs_bit <<= (QSFP_GPIO_PORT2_SHIFT * ppd->hw_pidx);
5549 qib_qsfp_init(qd, qsfp_7322_event);
5550 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
5551 dd->cspec->extctrl |= (mod_prs_bit << SYM_LSB(EXTCtrl, GPIOInvert));
5552 dd->cspec->gpio_mask |= mod_prs_bit;
5553 qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
5554 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
5555 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
5559 * called at device initialization time, and also if the txselect
5560 * module parameter is changed. This is used for cables that don't
5561 * have valid QSFP EEPROMs (not present, or attenuation is zero).
5562 * We initialize to the default, then if there is a specific
5563 * unit,port match, we use that (and set it immediately, for the
5564 * current speed, if the link is at INIT or better).
5565 * String format is "default# unit#,port#=# ... u,p=#", separators must
5566 * be a SPACE character. A newline terminates. The u,p=# tuples may
5567 * optionally have "u,p=#,#", where the final # is the H1 value
5568 * The last specific match is used (actually, all are used, but last
5569 * one is the one that winds up set); if none at all, fall back on default.
5571 static void set_no_qsfp_atten(struct qib_devdata *dd, int change)
5574 u32 pidx, unit, port, deflt, h1;
5578 str = txselect_list;
5580 /* default number is validated in setup_txselect() */
5581 deflt = simple_strtoul(str, &nxt, 0);
5582 for (pidx = 0; pidx < dd->num_pports; ++pidx)
5583 dd->pport[pidx].cpspec->no_eep = deflt;
5585 while (*nxt && nxt[1]) {
5587 unit = simple_strtoul(str, &nxt, 0);
5588 if (nxt == str || !*nxt || *nxt != ',') {
5589 while (*nxt && *nxt++ != ' ') /* skip to next, if any */
5594 port = simple_strtoul(str, &nxt, 0);
5595 if (nxt == str || *nxt != '=') {
5596 while (*nxt && *nxt++ != ' ') /* skip to next, if any */
5601 val = simple_strtoul(str, &nxt, 0);
5603 while (*nxt && *nxt++ != ' ') /* skip to next, if any */
5607 if (val >= TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ)
5610 h1 = 0; /* gcc thinks it might be used uninitted */
5611 if (*nxt == ',' && nxt[1]) {
5613 h1 = (u32)simple_strtoul(str, &nxt, 0);
5615 while (*nxt && *nxt++ != ' ') /* skip */
5620 for (pidx = 0; dd->unit == unit && pidx < dd->num_pports;
5622 struct qib_pportdata *ppd = &dd->pport[pidx];
5624 if (ppd->port != port || !ppd->link_speed_supported)
5626 ppd->cpspec->no_eep = val;
5627 /* now change the IBC and serdes, overriding generic */
5628 init_txdds_table(ppd, 1);
5634 if (change && !any) {
5635 /* no specific setting, use the default.
5636 * Change the IBC and serdes, but since it's
5637 * general, don't override specific settings.
5639 for (pidx = 0; pidx < dd->num_pports; ++pidx)
5640 if (dd->pport[pidx].link_speed_supported)
5641 init_txdds_table(&dd->pport[pidx], 0);
5645 /* handle the txselect parameter changing */
5646 static int setup_txselect(const char *str, struct kernel_param *kp)
5648 struct qib_devdata *dd;
5651 if (strlen(str) >= MAX_ATTEN_LEN) {
5652 printk(KERN_INFO QIB_DRV_NAME " txselect_values string "
5656 val = simple_strtoul(str, &n, 0);
5657 if (n == str || val >= (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ)) {
5658 printk(KERN_INFO QIB_DRV_NAME
5659 "txselect_values must start with a number < %d\n",
5660 TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ);
5663 strcpy(txselect_list, str);
5665 list_for_each_entry(dd, &qib_dev_list, list)
5666 if (dd->deviceid == PCI_DEVICE_ID_QLOGIC_IB_7322)
5667 set_no_qsfp_atten(dd, 1);
5672 * Write the final few registers that depend on some of the
5673 * init setup. Done late in init, just before bringing up
5676 static int qib_late_7322_initreg(struct qib_devdata *dd)
5681 qib_write_kreg(dd, kr_rcvhdrentsize, dd->rcvhdrentsize);
5682 qib_write_kreg(dd, kr_rcvhdrsize, dd->rcvhdrsize);
5683 qib_write_kreg(dd, kr_rcvhdrcnt, dd->rcvhdrcnt);
5684 qib_write_kreg(dd, kr_sendpioavailaddr, dd->pioavailregs_phys);
5685 val = qib_read_kreg64(dd, kr_sendpioavailaddr);
5686 if (val != dd->pioavailregs_phys) {
5687 qib_dev_err(dd, "Catastrophic software error, "
5688 "SendPIOAvailAddr written as %lx, "
5689 "read back as %llx\n",
5690 (unsigned long) dd->pioavailregs_phys,
5691 (unsigned long long) val);
5695 n = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
5696 qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_KERN, NULL);
5697 /* driver sends get pkey, lid, etc. checking also, to catch bugs */
5698 qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_ENAB1, NULL);
5700 qib_register_observer(dd, &sendctrl_0_observer);
5701 qib_register_observer(dd, &sendctrl_1_observer);
5703 dd->control &= ~QLOGIC_IB_C_SDMAFETCHPRIOEN;
5704 qib_write_kreg(dd, kr_control, dd->control);
5706 * Set SendDmaFetchPriority and init Tx params, including
5707 * QSFP handler on boards that have QSFP.
5708 * First set our default attenuation entry for cables that
5709 * don't have valid attenuation.
5711 set_no_qsfp_atten(dd, 0);
5712 for (n = 0; n < dd->num_pports; ++n) {
5713 struct qib_pportdata *ppd = dd->pport + n;
5715 qib_write_kreg_port(ppd, krp_senddmaprioritythld,
5716 sdma_fetch_prio & 0xf);
5717 /* Initialize qsfp if present on board. */
5718 if (dd->flags & QIB_HAS_QSFP)
5719 qib_init_7322_qsfp(ppd);
5721 dd->control |= QLOGIC_IB_C_SDMAFETCHPRIOEN;
5722 qib_write_kreg(dd, kr_control, dd->control);
5727 /* per IB port errors. */
5728 #define SENDCTRL_PIBP (MASK_ACROSS(0, 1) | MASK_ACROSS(3, 3) | \
5730 #define RCVCTRL_PIBP (MASK_ACROSS(0, 17) | MASK_ACROSS(39, 41))
5731 #define ERRS_PIBP (MASK_ACROSS(57, 58) | MASK_ACROSS(54, 54) | \
5732 MASK_ACROSS(36, 49) | MASK_ACROSS(29, 34) | MASK_ACROSS(14, 17) | \
5736 * Write the initialization per-port registers that need to be done at
5737 * driver load and after reset completes (i.e., that aren't done as part
5738 * of other init procedures called from qib_init.c).
5739 * Some of these should be redundant on reset, but play safe.
5741 static void write_7322_init_portregs(struct qib_pportdata *ppd)
5746 if (!ppd->link_speed_supported) {
5747 /* no buffer credits for this port */
5748 for (i = 1; i < 8; i++)
5749 qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, 0);
5750 qib_write_kreg_port(ppd, krp_ibcctrl_b, 0);
5751 qib_write_kreg(ppd->dd, kr_scratch, 0);
5756 * Set the number of supported virtual lanes in IBC,
5757 * for flow control packet handling on unsupported VLs
5759 val = qib_read_kreg_port(ppd, krp_ibsdtestiftx);
5760 val &= ~SYM_MASK(IB_SDTEST_IF_TX_0, VL_CAP);
5761 val |= (u64)(ppd->vls_supported - 1) <<
5762 SYM_LSB(IB_SDTEST_IF_TX_0, VL_CAP);
5763 qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
5765 qib_write_kreg_port(ppd, krp_rcvbthqp, QIB_KD_QP);
5767 /* enable tx header checking */
5768 qib_write_kreg_port(ppd, krp_sendcheckcontrol, IBA7322_SENDCHK_PKEY |
5769 IBA7322_SENDCHK_BTHQP | IBA7322_SENDCHK_SLID |
5770 IBA7322_SENDCHK_RAW_IPV6 | IBA7322_SENDCHK_MINSZ);
5772 qib_write_kreg_port(ppd, krp_ncmodectrl,
5773 SYM_MASK(IBNCModeCtrl_0, ScrambleCapLocal));
5776 * Unconditionally clear the bufmask bits. If SDMA is
5777 * enabled, we'll set them appropriately later.
5779 qib_write_kreg_port(ppd, krp_senddmabufmask0, 0);
5780 qib_write_kreg_port(ppd, krp_senddmabufmask1, 0);
5781 qib_write_kreg_port(ppd, krp_senddmabufmask2, 0);
5782 if (ppd->dd->cspec->r1)
5783 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, ForceCreditUpToDate);
5787 * Write the initialization per-device registers that need to be done at
5788 * driver load and after reset completes (i.e., that aren't done as part
5789 * of other init procedures called from qib_init.c). Also write per-port
5790 * registers that are affected by overall device config, such as QP mapping
5791 * Some of these should be redundant on reset, but play safe.
5793 static void write_7322_initregs(struct qib_devdata *dd)
5795 struct qib_pportdata *ppd;
5799 /* Set Multicast QPs received by port 2 to map to context one. */
5800 qib_write_kreg(dd, KREG_IDX(RcvQPMulticastContext_1), 1);
5802 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
5804 unsigned long flags;
5806 if (!dd->qpn_mask || !dd->pport[pidx].link_speed_supported)
5809 ppd = &dd->pport[pidx];
5811 /* be paranoid against later code motion, etc. */
5812 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
5813 ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvQPMapEnable);
5814 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
5816 /* Initialize QP to context mapping */
5817 regno = krp_rcvqpmaptable;
5819 if (dd->num_pports > 1)
5820 n = dd->first_user_ctxt / dd->num_pports;
5822 n = dd->first_user_ctxt - 1;
5823 for (i = 0; i < 32; ) {
5826 if (dd->num_pports > 1)
5827 ctxt = (i % n) * dd->num_pports + pidx;
5831 ctxt = ppd->hw_pidx;
5832 val |= ctxt << (5 * (i % 6));
5835 qib_write_kreg_port(ppd, regno, val);
5840 qib_write_kreg_port(ppd, regno, val);
5844 * Setup up interrupt mitigation for kernel contexts, but
5845 * not user contexts (user contexts use interrupts when
5846 * stalled waiting for any packet, so want those interrupts
5849 for (i = 0; i < dd->first_user_ctxt; i++) {
5850 dd->cspec->rcvavail_timeout[i] = rcv_int_timeout;
5851 qib_write_kreg(dd, kr_rcvavailtimeout + i, rcv_int_timeout);
5855 * Initialize as (disabled) rcvflow tables. Application code
5856 * will setup each flow as it uses the flow.
5857 * Doesn't clear any of the error bits that might be set.
5859 val = TIDFLOW_ERRBITS; /* these are W1C */
5860 for (i = 0; i < dd->ctxtcnt; i++) {
5862 for (flow = 0; flow < NUM_TIDFLOWS_CTXT; flow++)
5863 qib_write_ureg(dd, ur_rcvflowtable+flow, val, i);
5867 * dual cards init to dual port recovery, single port cards to
5868 * the one port. Dual port cards may later adjust to 1 port,
5869 * and then back to dual port if both ports are connected
5872 setup_7322_link_recovery(dd->pport, dd->num_pports > 1);
5875 static int qib_init_7322_variables(struct qib_devdata *dd)
5877 struct qib_pportdata *ppd;
5878 unsigned features, pidx, sbufcnt;
5880 u32 sbufs, updthresh;
5882 /* pport structs are contiguous, allocated after devdata */
5883 ppd = (struct qib_pportdata *)(dd + 1);
5888 dd->cspec = (struct qib_chip_specific *)(ppd + 2);
5890 ppd[0].cpspec = (struct qib_chippport_specific *)(dd->cspec + 1);
5891 ppd[1].cpspec = &ppd[0].cpspec[1];
5892 ppd[0].cpspec->ppd = &ppd[0]; /* for autoneg_7322_work() */
5893 ppd[1].cpspec->ppd = &ppd[1]; /* for autoneg_7322_work() */
5895 spin_lock_init(&dd->cspec->rcvmod_lock);
5896 spin_lock_init(&dd->cspec->gpio_lock);
5898 /* we haven't yet set QIB_PRESENT, so use read directly */
5899 dd->revision = readq(&dd->kregbase[kr_revision]);
5901 if ((dd->revision & 0xffffffffU) == 0xffffffffU) {
5902 qib_dev_err(dd, "Revision register read failure, "
5903 "giving up initialization\n");
5907 dd->flags |= QIB_PRESENT; /* now register routines work */
5909 dd->majrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMajor);
5910 dd->minrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMinor);
5911 dd->cspec->r1 = dd->minrev == 1;
5913 get_7322_chip_params(dd);
5914 features = qib_7322_boardname(dd);
5916 /* now that piobcnt2k and 4k set, we can allocate these */
5917 sbufcnt = dd->piobcnt2k + dd->piobcnt4k +
5918 NUM_VL15_BUFS + BITS_PER_LONG - 1;
5919 sbufcnt /= BITS_PER_LONG;
5920 dd->cspec->sendchkenable = kmalloc(sbufcnt *
5921 sizeof(*dd->cspec->sendchkenable), GFP_KERNEL);
5922 dd->cspec->sendgrhchk = kmalloc(sbufcnt *
5923 sizeof(*dd->cspec->sendgrhchk), GFP_KERNEL);
5924 dd->cspec->sendibchk = kmalloc(sbufcnt *
5925 sizeof(*dd->cspec->sendibchk), GFP_KERNEL);
5926 if (!dd->cspec->sendchkenable || !dd->cspec->sendgrhchk ||
5927 !dd->cspec->sendibchk) {
5928 qib_dev_err(dd, "Failed allocation for hdrchk bitmaps\n");
5936 * GPIO bits for TWSI data and clock,
5937 * used for serial EEPROM.
5939 dd->gpio_sda_num = _QIB_GPIO_SDA_NUM;
5940 dd->gpio_scl_num = _QIB_GPIO_SCL_NUM;
5941 dd->twsi_eeprom_dev = QIB_TWSI_EEPROM_DEV;
5943 dd->flags |= QIB_HAS_INTX | QIB_HAS_LINK_LATENCY |
5944 QIB_NODMA_RTAIL | QIB_HAS_VLSUPP | QIB_HAS_HDRSUPP |
5945 QIB_HAS_THRESH_UPDATE |
5946 (sdma_idle_cnt ? QIB_HAS_SDMA_TIMEOUT : 0);
5947 dd->flags |= qib_special_trigger ?
5948 QIB_USE_SPCL_TRIG : QIB_HAS_SEND_DMA;
5951 * Setup initial values. These may change when PAT is enabled, but
5952 * we need these to do initial chip register accesses.
5954 qib_7322_set_baseaddrs(dd);
5956 mtu = ib_mtu_enum_to_int(qib_ibmtu);
5958 mtu = QIB_DEFAULT_MTU;
5960 dd->cspec->int_enable_mask = QIB_I_BITSEXTANT;
5961 /* all hwerrors become interrupts, unless special purposed */
5962 dd->cspec->hwerrmask = ~0ULL;
5963 /* link_recovery setup causes these errors, so ignore them,
5964 * other than clearing them when they occur */
5965 dd->cspec->hwerrmask &=
5966 ~(SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_0) |
5967 SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_1) |
5968 HWE_MASK(LATriggered));
5970 for (pidx = 0; pidx < NUM_IB_PORTS; ++pidx) {
5971 struct qib_chippport_specific *cp = ppd->cpspec;
5972 ppd->link_speed_supported = features & PORT_SPD_CAP;
5973 features >>= PORT_SPD_CAP_SHIFT;
5974 if (!ppd->link_speed_supported) {
5975 /* single port mode (7340, or configured) */
5976 dd->skip_kctxt_mask |= 1 << pidx;
5978 /* Make sure port is disabled. */
5979 qib_write_kreg_port(ppd, krp_rcvctrl, 0);
5980 qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
5982 dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
5983 IBSerdesPClkNotDetectMask_0)
5984 | SYM_MASK(HwErrMask,
5985 SDmaMemReadErrMask_0));
5986 dd->cspec->int_enable_mask &= ~(
5987 SYM_MASK(IntMask, SDmaCleanupDoneMask_0) |
5988 SYM_MASK(IntMask, SDmaIdleIntMask_0) |
5989 SYM_MASK(IntMask, SDmaProgressIntMask_0) |
5990 SYM_MASK(IntMask, SDmaIntMask_0) |
5991 SYM_MASK(IntMask, ErrIntMask_0) |
5992 SYM_MASK(IntMask, SendDoneIntMask_0));
5994 /* Make sure port is disabled. */
5995 qib_write_kreg_port(ppd, krp_rcvctrl, 0);
5996 qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
5997 dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
5998 IBSerdesPClkNotDetectMask_1)
5999 | SYM_MASK(HwErrMask,
6000 SDmaMemReadErrMask_1));
6001 dd->cspec->int_enable_mask &= ~(
6002 SYM_MASK(IntMask, SDmaCleanupDoneMask_1) |
6003 SYM_MASK(IntMask, SDmaIdleIntMask_1) |
6004 SYM_MASK(IntMask, SDmaProgressIntMask_1) |
6005 SYM_MASK(IntMask, SDmaIntMask_1) |
6006 SYM_MASK(IntMask, ErrIntMask_1) |
6007 SYM_MASK(IntMask, SendDoneIntMask_1));
6013 qib_init_pportdata(ppd, dd, pidx, dd->num_pports);
6015 ppd->link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
6016 ppd->link_width_enabled = IB_WIDTH_4X;
6017 ppd->link_speed_enabled = ppd->link_speed_supported;
6019 * Set the initial values to reasonable default, will be set
6020 * for real when link is up.
6022 ppd->link_width_active = IB_WIDTH_4X;
6023 ppd->link_speed_active = QIB_IB_SDR;
6024 ppd->delay_mult = ib_rate_to_delay[IB_RATE_10_GBPS];
6025 switch (qib_num_cfg_vls) {
6027 ppd->vls_supported = IB_VL_VL0;
6030 ppd->vls_supported = IB_VL_VL0_1;
6033 qib_devinfo(dd->pcidev,
6034 "Invalid num_vls %u, using 4 VLs\n",
6036 qib_num_cfg_vls = 4;
6039 ppd->vls_supported = IB_VL_VL0_3;
6043 ppd->vls_supported = IB_VL_VL0_7;
6045 qib_devinfo(dd->pcidev,
6046 "Invalid num_vls %u for MTU %d "
6048 qib_num_cfg_vls, mtu);
6049 ppd->vls_supported = IB_VL_VL0_3;
6050 qib_num_cfg_vls = 4;
6054 ppd->vls_operational = ppd->vls_supported;
6056 init_waitqueue_head(&cp->autoneg_wait);
6057 INIT_DELAYED_WORK(&cp->autoneg_work,
6059 if (ppd->dd->cspec->r1)
6060 INIT_DELAYED_WORK(&cp->ipg_work, ipg_7322_work);
6063 * For Mez and similar cards, no qsfp info, so do
6064 * the "cable info" setup here. Can be overridden
6065 * in adapter-specific routines.
6067 if (!(ppd->dd->flags & QIB_HAS_QSFP)) {
6068 if (!IS_QMH(ppd->dd) && !IS_QME(ppd->dd))
6069 qib_devinfo(ppd->dd->pcidev, "IB%u:%u: "
6070 "Unknown mezzanine card type\n",
6071 dd->unit, ppd->port);
6072 cp->h1_val = IS_QMH(dd) ? H1_FORCE_QMH : H1_FORCE_QME;
6074 * Choose center value as default tx serdes setting
6075 * until changed through module parameter.
6077 ppd->cpspec->no_eep = IS_QMH(dd) ?
6078 TXDDS_TABLE_SZ + 2 : TXDDS_TABLE_SZ + 4;
6080 cp->h1_val = H1_FORCE_VAL;
6082 /* Avoid writes to chip for mini_init */
6084 write_7322_init_portregs(ppd);
6086 init_timer(&cp->chase_timer);
6087 cp->chase_timer.function = reenable_chase;
6088 cp->chase_timer.data = (unsigned long)ppd;
6093 dd->rcvhdrentsize = QIB_RCVHDR_ENTSIZE;
6094 dd->rcvhdrsize = QIB_DFLT_RCVHDRSIZE;
6095 dd->rhf_offset = dd->rcvhdrentsize - sizeof(u64) / sizeof(u32);
6097 /* we always allocate at least 2048 bytes for eager buffers */
6098 dd->rcvegrbufsize = max(mtu, 2048);
6100 qib_7322_tidtemplate(dd);
6103 * We can request a receive interrupt for 1 or
6104 * more packets from current offset.
6106 dd->rhdrhead_intr_off =
6107 (u64) rcv_int_count << IBA7322_HDRHEAD_PKTINT_SHIFT;
6109 /* setup the stats timer; the add_timer is done at end of init */
6110 init_timer(&dd->stats_timer);
6111 dd->stats_timer.function = qib_get_7322_faststats;
6112 dd->stats_timer.data = (unsigned long) dd;
6114 dd->ureg_align = 0x10000; /* 64KB alignment */
6116 dd->piosize2kmax_dwords = dd->piosize2k >> 2;
6118 qib_7322_config_ctxts(dd);
6119 qib_set_ctxtcnt(dd);
6122 ret = init_chip_wc_pat(dd, NUM_VL15_BUFS * dd->align4k);
6126 qib_7322_set_baseaddrs(dd); /* set chip access pointers now */
6131 if (!dd->num_pports) {
6132 qib_dev_err(dd, "No ports enabled, giving up initialization\n");
6133 goto bail; /* no error, so can still figure out why err */
6136 write_7322_initregs(dd);
6137 ret = qib_create_ctxts(dd);
6138 init_7322_cntrnames(dd);
6140 updthresh = 8U; /* update threshold */
6142 /* use all of 4KB buffers for the kernel SDMA, zero if !SDMA.
6143 * reserve the update threshold amount for other kernel use, such
6144 * as sending SMI, MAD, and ACKs, or 3, whichever is greater,
6145 * unless we aren't enabling SDMA, in which case we want to use
6146 * all the 4k bufs for the kernel.
6147 * if this was less than the update threshold, we could wait
6148 * a long time for an update. Coded this way because we
6149 * sometimes change the update threshold for various reasons,
6150 * and we want this to remain robust.
6152 if (dd->flags & QIB_HAS_SEND_DMA) {
6153 dd->cspec->sdmabufcnt = dd->piobcnt4k;
6154 sbufs = updthresh > 3 ? updthresh : 3;
6156 dd->cspec->sdmabufcnt = 0;
6157 sbufs = dd->piobcnt4k;
6159 dd->cspec->lastbuf_for_pio = dd->piobcnt2k + dd->piobcnt4k -
6160 dd->cspec->sdmabufcnt;
6161 dd->lastctxt_piobuf = dd->cspec->lastbuf_for_pio - sbufs;
6162 dd->cspec->lastbuf_for_pio--; /* range is <= , not < */
6163 dd->pbufsctxt = (dd->cfgctxts > dd->first_user_ctxt) ?
6164 dd->lastctxt_piobuf / (dd->cfgctxts - dd->first_user_ctxt) : 0;
6167 * If we have 16 user contexts, we will have 7 sbufs
6168 * per context, so reduce the update threshold to match. We
6169 * want to update before we actually run out, at low pbufs/ctxt
6170 * so give ourselves some margin.
6172 if (dd->pbufsctxt >= 2 && dd->pbufsctxt - 2 < updthresh)
6173 updthresh = dd->pbufsctxt - 2;
6174 dd->cspec->updthresh_dflt = updthresh;
6175 dd->cspec->updthresh = updthresh;
6177 /* before full enable, no interrupts, no locking needed */
6178 dd->sendctrl |= ((updthresh & SYM_RMASK(SendCtrl, AvailUpdThld))
6179 << SYM_LSB(SendCtrl, AvailUpdThld)) |
6180 SYM_MASK(SendCtrl, SendBufAvailPad64Byte);
6182 dd->psxmitwait_supported = 1;
6183 dd->psxmitwait_check_rate = QIB_7322_PSXMITWAIT_CHECK_RATE;
6186 dd->ctxtcnt = 1; /* for other initialization code */
6191 static u32 __iomem *qib_7322_getsendbuf(struct qib_pportdata *ppd, u64 pbc,
6194 u32 first, last, plen = pbc & QIB_PBC_LENGTH_MASK;
6195 struct qib_devdata *dd = ppd->dd;
6197 /* last is same for 2k and 4k, because we use 4k if all 2k busy */
6198 if (pbc & PBC_7322_VL15_SEND) {
6199 first = dd->piobcnt2k + dd->piobcnt4k + ppd->hw_pidx;
6202 if ((plen + 1) > dd->piosize2kmax_dwords)
6203 first = dd->piobcnt2k;
6206 last = dd->cspec->lastbuf_for_pio;
6208 return qib_getsendbuf_range(dd, pbufnum, first, last);
6211 static void qib_set_cntr_7322_sample(struct qib_pportdata *ppd, u32 intv,
6214 qib_write_kreg_port(ppd, krp_psinterval, intv);
6215 qib_write_kreg_port(ppd, krp_psstart, start);
6219 * Must be called with sdma_lock held, or before init finished.
6221 static void qib_sdma_set_7322_desc_cnt(struct qib_pportdata *ppd, unsigned cnt)
6223 qib_write_kreg_port(ppd, krp_senddmadesccnt, cnt);
6226 static struct sdma_set_state_action sdma_7322_action_table[] = {
6227 [qib_sdma_state_s00_hw_down] = {
6228 .go_s99_running_tofalse = 1,
6234 [qib_sdma_state_s10_hw_start_up_wait] = {
6240 [qib_sdma_state_s20_idle] = {
6246 [qib_sdma_state_s30_sw_clean_up_wait] = {
6252 [qib_sdma_state_s40_hw_clean_up_wait] = {
6258 [qib_sdma_state_s50_hw_halt_wait] = {
6264 [qib_sdma_state_s99_running] = {
6269 .go_s99_running_totrue = 1,
6273 static void qib_7322_sdma_init_early(struct qib_pportdata *ppd)
6275 ppd->sdma_state.set_state_action = sdma_7322_action_table;
6278 static int init_sdma_7322_regs(struct qib_pportdata *ppd)
6280 struct qib_devdata *dd = ppd->dd;
6281 unsigned lastbuf, erstbuf;
6282 u64 senddmabufmask[3] = { 0 };
6285 qib_write_kreg_port(ppd, krp_senddmabase, ppd->sdma_descq_phys);
6286 qib_sdma_7322_setlengen(ppd);
6287 qib_sdma_update_7322_tail(ppd, 0); /* Set SendDmaTail */
6288 qib_write_kreg_port(ppd, krp_senddmareloadcnt, sdma_idle_cnt);
6289 qib_write_kreg_port(ppd, krp_senddmadesccnt, 0);
6290 qib_write_kreg_port(ppd, krp_senddmaheadaddr, ppd->sdma_head_phys);
6293 n = dd->cspec->sdmabufcnt / dd->num_pports; /* no remainder */
6295 n = dd->cspec->sdmabufcnt; /* failsafe for init */
6296 erstbuf = (dd->piobcnt2k + dd->piobcnt4k) -
6297 ((dd->num_pports == 1 || ppd->port == 2) ? n :
6298 dd->cspec->sdmabufcnt);
6299 lastbuf = erstbuf + n;
6301 ppd->sdma_state.first_sendbuf = erstbuf;
6302 ppd->sdma_state.last_sendbuf = lastbuf;
6303 for (; erstbuf < lastbuf; ++erstbuf) {
6304 unsigned word = erstbuf / BITS_PER_LONG;
6305 unsigned bit = erstbuf & (BITS_PER_LONG - 1);
6308 senddmabufmask[word] |= 1ULL << bit;
6310 qib_write_kreg_port(ppd, krp_senddmabufmask0, senddmabufmask[0]);
6311 qib_write_kreg_port(ppd, krp_senddmabufmask1, senddmabufmask[1]);
6312 qib_write_kreg_port(ppd, krp_senddmabufmask2, senddmabufmask[2]);
6316 /* sdma_lock must be held */
6317 static u16 qib_sdma_7322_gethead(struct qib_pportdata *ppd)
6319 struct qib_devdata *dd = ppd->dd;
6327 use_dmahead = __qib_sdma_running(ppd) &&
6328 (dd->flags & QIB_HAS_SDMA_TIMEOUT);
6330 hwhead = use_dmahead ?
6331 (u16) le64_to_cpu(*ppd->sdma_head_dma) :
6332 (u16) qib_read_kreg_port(ppd, krp_senddmahead);
6334 swhead = ppd->sdma_descq_head;
6335 swtail = ppd->sdma_descq_tail;
6336 cnt = ppd->sdma_descq_cnt;
6338 if (swhead < swtail)
6340 sane = (hwhead >= swhead) & (hwhead <= swtail);
6341 else if (swhead > swtail)
6342 /* wrapped around */
6343 sane = ((hwhead >= swhead) && (hwhead < cnt)) ||
6347 sane = (hwhead == swhead);
6349 if (unlikely(!sane)) {
6351 /* try one more time, directly from the register */
6355 /* proceed as if no progress */
6362 static int qib_sdma_7322_busy(struct qib_pportdata *ppd)
6364 u64 hwstatus = qib_read_kreg_port(ppd, krp_senddmastatus);
6366 return (hwstatus & SYM_MASK(SendDmaStatus_0, ScoreBoardDrainInProg)) ||
6367 (hwstatus & SYM_MASK(SendDmaStatus_0, HaltInProg)) ||
6368 !(hwstatus & SYM_MASK(SendDmaStatus_0, InternalSDmaHalt)) ||
6369 !(hwstatus & SYM_MASK(SendDmaStatus_0, ScbEmpty));
6373 * Compute the amount of delay before sending the next packet if the
6374 * port's send rate differs from the static rate set for the QP.
6375 * The delay affects the next packet and the amount of the delay is
6376 * based on the length of the this packet.
6378 static u32 qib_7322_setpbc_control(struct qib_pportdata *ppd, u32 plen,
6381 u8 snd_mult = ppd->delay_mult;
6382 u8 rcv_mult = ib_rate_to_delay[srate];
6385 ret = rcv_mult > snd_mult ? ((plen + 1) >> 1) * snd_mult : 0;
6387 /* Indicate VL15, else set the VL in the control word */
6389 ret |= PBC_7322_VL15_SEND_CTRL;
6391 ret |= vl << PBC_VL_NUM_LSB;
6392 ret |= ((u32)(ppd->hw_pidx)) << PBC_PORT_SEL_LSB;
6398 * Enable the per-port VL15 send buffers for use.
6399 * They follow the rest of the buffers, without a config parameter.
6400 * This was in initregs, but that is done before the shadow
6401 * is set up, and this has to be done after the shadow is
6404 static void qib_7322_initvl15_bufs(struct qib_devdata *dd)
6408 vl15bufs = dd->piobcnt2k + dd->piobcnt4k;
6409 qib_chg_pioavailkernel(dd, vl15bufs, NUM_VL15_BUFS,
6410 TXCHK_CHG_TYPE_KERN, NULL);
6413 static void qib_7322_init_ctxt(struct qib_ctxtdata *rcd)
6415 if (rcd->ctxt < NUM_IB_PORTS) {
6416 if (rcd->dd->num_pports > 1) {
6417 rcd->rcvegrcnt = KCTXT0_EGRCNT / 2;
6418 rcd->rcvegr_tid_base = rcd->ctxt ? rcd->rcvegrcnt : 0;
6420 rcd->rcvegrcnt = KCTXT0_EGRCNT;
6421 rcd->rcvegr_tid_base = 0;
6424 rcd->rcvegrcnt = rcd->dd->cspec->rcvegrcnt;
6425 rcd->rcvegr_tid_base = KCTXT0_EGRCNT +
6426 (rcd->ctxt - NUM_IB_PORTS) * rcd->rcvegrcnt;
6430 #define QTXSLEEPS 5000
6431 static void qib_7322_txchk_change(struct qib_devdata *dd, u32 start,
6432 u32 len, u32 which, struct qib_ctxtdata *rcd)
6435 const int last = start + len - 1;
6436 const int lastr = last / BITS_PER_LONG;
6438 int wait = rcd != NULL;
6439 unsigned long flags;
6442 unsigned long shadow;
6443 int cstart, previ = -1;
6446 * when flipping from kernel to user, we can't change
6447 * the checking type if the buffer is allocated to the
6448 * driver. It's OK the other direction, because it's
6449 * from close, and we have just disarm'ed all the
6450 * buffers. All the kernel to kernel changes are also
6453 for (cstart = start; cstart <= last; cstart++) {
6454 i = ((2 * cstart) + QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
6457 shadow = (unsigned long)
6458 le64_to_cpu(dd->pioavailregs_dma[i]);
6461 if (test_bit(((2 * cstart) +
6462 QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
6463 % BITS_PER_LONG, &shadow))
6470 if (sleeps == QTXSLEEPS)
6472 /* make sure we see an updated copy next time around */
6473 sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
6479 case TXCHK_CHG_TYPE_DIS1:
6481 * disable checking on a range; used by diags; just
6482 * one buffer, but still written generically
6484 for (i = start; i <= last; i++)
6485 clear_bit(i, dd->cspec->sendchkenable);
6488 case TXCHK_CHG_TYPE_ENAB1:
6490 * (re)enable checking on a range; used by diags; just
6491 * one buffer, but still written generically; read
6492 * scratch to be sure buffer actually triggered, not
6493 * just flushed from processor.
6495 qib_read_kreg32(dd, kr_scratch);
6496 for (i = start; i <= last; i++)
6497 set_bit(i, dd->cspec->sendchkenable);
6500 case TXCHK_CHG_TYPE_KERN:
6501 /* usable by kernel */
6502 for (i = start; i <= last; i++) {
6503 set_bit(i, dd->cspec->sendibchk);
6504 clear_bit(i, dd->cspec->sendgrhchk);
6506 spin_lock_irqsave(&dd->uctxt_lock, flags);
6507 /* see if we need to raise avail update threshold */
6508 for (i = dd->first_user_ctxt;
6509 dd->cspec->updthresh != dd->cspec->updthresh_dflt
6510 && i < dd->cfgctxts; i++)
6511 if (dd->rcd[i] && dd->rcd[i]->subctxt_cnt &&
6512 ((dd->rcd[i]->piocnt / dd->rcd[i]->subctxt_cnt) - 1)
6513 < dd->cspec->updthresh_dflt)
6515 spin_unlock_irqrestore(&dd->uctxt_lock, flags);
6516 if (i == dd->cfgctxts) {
6517 spin_lock_irqsave(&dd->sendctrl_lock, flags);
6518 dd->cspec->updthresh = dd->cspec->updthresh_dflt;
6519 dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
6520 dd->sendctrl |= (dd->cspec->updthresh &
6521 SYM_RMASK(SendCtrl, AvailUpdThld)) <<
6522 SYM_LSB(SendCtrl, AvailUpdThld);
6523 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
6524 sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
6528 case TXCHK_CHG_TYPE_USER:
6529 /* for user process */
6530 for (i = start; i <= last; i++) {
6531 clear_bit(i, dd->cspec->sendibchk);
6532 set_bit(i, dd->cspec->sendgrhchk);
6534 spin_lock_irqsave(&dd->sendctrl_lock, flags);
6535 if (rcd && rcd->subctxt_cnt && ((rcd->piocnt
6536 / rcd->subctxt_cnt) - 1) < dd->cspec->updthresh) {
6537 dd->cspec->updthresh = (rcd->piocnt /
6538 rcd->subctxt_cnt) - 1;
6539 dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
6540 dd->sendctrl |= (dd->cspec->updthresh &
6541 SYM_RMASK(SendCtrl, AvailUpdThld))
6542 << SYM_LSB(SendCtrl, AvailUpdThld);
6543 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
6544 sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
6546 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
6553 for (i = start / BITS_PER_LONG; which >= 2 && i <= lastr; ++i)
6554 qib_write_kreg(dd, kr_sendcheckmask + i,
6555 dd->cspec->sendchkenable[i]);
6557 for (i = start / BITS_PER_LONG; which < 2 && i <= lastr; ++i) {
6558 qib_write_kreg(dd, kr_sendgrhcheckmask + i,
6559 dd->cspec->sendgrhchk[i]);
6560 qib_write_kreg(dd, kr_sendibpktmask + i,
6561 dd->cspec->sendibchk[i]);
6565 * Be sure whatever we did was seen by the chip and acted upon,
6566 * before we return. Mostly important for which >= 2.
6568 qib_read_kreg32(dd, kr_scratch);
6572 /* useful for trigger analyzers, etc. */
6573 static void writescratch(struct qib_devdata *dd, u32 val)
6575 qib_write_kreg(dd, kr_scratch, val);
6578 /* Dummy for now, use chip regs soon */
6579 static int qib_7322_tempsense_rd(struct qib_devdata *dd, int regnum)
6585 * qib_init_iba7322_funcs - set up the chip-specific function pointers
6586 * @dev: the pci_dev for qlogic_ib device
6587 * @ent: pci_device_id struct for this dev
6589 * Also allocates, inits, and returns the devdata struct for this
6592 * This is global, and is called directly at init to set up the
6593 * chip-specific function pointers for later use.
6595 struct qib_devdata *qib_init_iba7322_funcs(struct pci_dev *pdev,
6596 const struct pci_device_id *ent)
6598 struct qib_devdata *dd;
6600 u32 tabsize, actual_cnt = 0;
6602 dd = qib_alloc_devdata(pdev,
6603 NUM_IB_PORTS * sizeof(struct qib_pportdata) +
6604 sizeof(struct qib_chip_specific) +
6605 NUM_IB_PORTS * sizeof(struct qib_chippport_specific));
6609 dd->f_bringup_serdes = qib_7322_bringup_serdes;
6610 dd->f_cleanup = qib_setup_7322_cleanup;
6611 dd->f_clear_tids = qib_7322_clear_tids;
6612 dd->f_free_irq = qib_7322_free_irq;
6613 dd->f_get_base_info = qib_7322_get_base_info;
6614 dd->f_get_msgheader = qib_7322_get_msgheader;
6615 dd->f_getsendbuf = qib_7322_getsendbuf;
6616 dd->f_gpio_mod = gpio_7322_mod;
6617 dd->f_eeprom_wen = qib_7322_eeprom_wen;
6618 dd->f_hdrqempty = qib_7322_hdrqempty;
6619 dd->f_ib_updown = qib_7322_ib_updown;
6620 dd->f_init_ctxt = qib_7322_init_ctxt;
6621 dd->f_initvl15_bufs = qib_7322_initvl15_bufs;
6622 dd->f_intr_fallback = qib_7322_intr_fallback;
6623 dd->f_late_initreg = qib_late_7322_initreg;
6624 dd->f_setpbc_control = qib_7322_setpbc_control;
6625 dd->f_portcntr = qib_portcntr_7322;
6626 dd->f_put_tid = qib_7322_put_tid;
6627 dd->f_quiet_serdes = qib_7322_mini_quiet_serdes;
6628 dd->f_rcvctrl = rcvctrl_7322_mod;
6629 dd->f_read_cntrs = qib_read_7322cntrs;
6630 dd->f_read_portcntrs = qib_read_7322portcntrs;
6631 dd->f_reset = qib_do_7322_reset;
6632 dd->f_init_sdma_regs = init_sdma_7322_regs;
6633 dd->f_sdma_busy = qib_sdma_7322_busy;
6634 dd->f_sdma_gethead = qib_sdma_7322_gethead;
6635 dd->f_sdma_sendctrl = qib_7322_sdma_sendctrl;
6636 dd->f_sdma_set_desc_cnt = qib_sdma_set_7322_desc_cnt;
6637 dd->f_sdma_update_tail = qib_sdma_update_7322_tail;
6638 dd->f_sendctrl = sendctrl_7322_mod;
6639 dd->f_set_armlaunch = qib_set_7322_armlaunch;
6640 dd->f_set_cntr_sample = qib_set_cntr_7322_sample;
6641 dd->f_iblink_state = qib_7322_iblink_state;
6642 dd->f_ibphys_portstate = qib_7322_phys_portstate;
6643 dd->f_get_ib_cfg = qib_7322_get_ib_cfg;
6644 dd->f_set_ib_cfg = qib_7322_set_ib_cfg;
6645 dd->f_set_ib_loopback = qib_7322_set_loopback;
6646 dd->f_get_ib_table = qib_7322_get_ib_table;
6647 dd->f_set_ib_table = qib_7322_set_ib_table;
6648 dd->f_set_intr_state = qib_7322_set_intr_state;
6649 dd->f_setextled = qib_setup_7322_setextled;
6650 dd->f_txchk_change = qib_7322_txchk_change;
6651 dd->f_update_usrhead = qib_update_7322_usrhead;
6652 dd->f_wantpiobuf_intr = qib_wantpiobuf_7322_intr;
6653 dd->f_xgxs_reset = qib_7322_mini_pcs_reset;
6654 dd->f_sdma_hw_clean_up = qib_7322_sdma_hw_clean_up;
6655 dd->f_sdma_hw_start_up = qib_7322_sdma_hw_start_up;
6656 dd->f_sdma_init_early = qib_7322_sdma_init_early;
6657 dd->f_writescratch = writescratch;
6658 dd->f_tempsense_rd = qib_7322_tempsense_rd;
6660 * Do remaining PCIe setup and save PCIe values in dd.
6661 * Any error printing is already done by the init code.
6662 * On return, we have the chip mapped, but chip registers
6663 * are not set up until start of qib_init_7322_variables.
6665 ret = qib_pcie_ddinit(dd, pdev, ent);
6669 /* initialize chip-specific variables */
6670 ret = qib_init_7322_variables(dd);
6674 if (qib_mini_init || !dd->num_pports)
6678 * Determine number of vectors we want; depends on port count
6679 * and number of configured kernel receive queues actually used.
6680 * Should also depend on whether sdma is enabled or not, but
6681 * that's such a rare testing case it's not worth worrying about.
6683 tabsize = dd->first_user_ctxt + ARRAY_SIZE(irq_table);
6684 for (i = 0; i < tabsize; i++)
6685 if ((i < ARRAY_SIZE(irq_table) &&
6686 irq_table[i].port <= dd->num_pports) ||
6687 (i >= ARRAY_SIZE(irq_table) &&
6688 dd->rcd[i - ARRAY_SIZE(irq_table)]))
6690 tabsize = actual_cnt;
6691 dd->cspec->msix_entries = kmalloc(tabsize *
6692 sizeof(struct msix_entry), GFP_KERNEL);
6693 dd->cspec->msix_arg = kmalloc(tabsize *
6694 sizeof(void *), GFP_KERNEL);
6695 if (!dd->cspec->msix_entries || !dd->cspec->msix_arg) {
6696 qib_dev_err(dd, "No memory for MSIx table\n");
6699 for (i = 0; i < tabsize; i++)
6700 dd->cspec->msix_entries[i].entry = i;
6702 if (qib_pcie_params(dd, 8, &tabsize, dd->cspec->msix_entries))
6703 qib_dev_err(dd, "Failed to setup PCIe or interrupts; "
6704 "continuing anyway\n");
6705 /* may be less than we wanted, if not enough available */
6706 dd->cspec->num_msix_entries = tabsize;
6708 /* setup interrupt handler */
6709 qib_setup_7322_interrupt(dd, 1);
6711 /* clear diagctrl register, in case diags were running and crashed */
6712 qib_write_kreg(dd, kr_hwdiagctrl, 0);
6717 qib_pcie_ddcleanup(dd);
6719 qib_free_devdata(dd);
6726 * Set the table entry at the specified index from the table specifed.
6727 * There are 3 * TXDDS_TABLE_SZ entries in all per port, with the first
6728 * TXDDS_TABLE_SZ for SDR, the next for DDR, and the last for QDR.
6729 * 'idx' below addresses the correct entry, while its 4 LSBs select the
6730 * corresponding entry (one of TXDDS_TABLE_SZ) from the selected table.
6732 #define DDS_ENT_AMP_LSB 14
6733 #define DDS_ENT_MAIN_LSB 9
6734 #define DDS_ENT_POST_LSB 5
6735 #define DDS_ENT_PRE_XTRA_LSB 3
6736 #define DDS_ENT_PRE_LSB 0
6739 * Set one entry in the TxDDS table for spec'd port
6740 * ridx picks one of the entries, while tp points
6741 * to the appropriate table entry.
6743 static void set_txdds(struct qib_pportdata *ppd, int ridx,
6744 const struct txdds_ent *tp)
6746 struct qib_devdata *dd = ppd->dd;
6750 /* Get correct offset in chip-space, and in source table */
6751 regidx = KREG_IBPORT_IDX(IBSD_DDS_MAP_TABLE) + ridx;
6753 * We do not use qib_write_kreg_port() because it was intended
6754 * only for registers in the lower "port specific" pages.
6755 * So do index calculation by hand.
6758 regidx += (dd->palign / sizeof(u64));
6760 pack_ent = tp->amp << DDS_ENT_AMP_LSB;
6761 pack_ent |= tp->main << DDS_ENT_MAIN_LSB;
6762 pack_ent |= tp->pre << DDS_ENT_PRE_LSB;
6763 pack_ent |= tp->post << DDS_ENT_POST_LSB;
6764 qib_write_kreg(dd, regidx, pack_ent);
6765 /* Prevent back-to-back writes by hitting scratch */
6766 qib_write_kreg(ppd->dd, kr_scratch, 0);
6769 static const struct vendor_txdds_ent vendor_txdds[] = {
6770 { /* Amphenol 1m 30awg NoEq */
6771 { 0x41, 0x50, 0x48 }, "584470002 ",
6772 { 10, 0, 0, 5 }, { 10, 0, 0, 9 }, { 7, 1, 0, 13 },
6774 { /* Amphenol 3m 28awg NoEq */
6775 { 0x41, 0x50, 0x48 }, "584470004 ",
6776 { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 7, 15 },
6778 { /* Finisar 3m OM2 Optical */
6779 { 0x00, 0x90, 0x65 }, "FCBG410QB1C03-QL",
6780 { 0, 0, 0, 3 }, { 0, 0, 0, 4 }, { 0, 0, 0, 13 },
6782 { /* Finisar 30m OM2 Optical */
6783 { 0x00, 0x90, 0x65 }, "FCBG410QB1C30-QL",
6784 { 0, 0, 0, 1 }, { 0, 0, 0, 5 }, { 0, 0, 0, 11 },
6786 { /* Finisar Default OM2 Optical */
6787 { 0x00, 0x90, 0x65 }, NULL,
6788 { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 0, 0, 12 },
6790 { /* Gore 1m 30awg NoEq */
6791 { 0x00, 0x21, 0x77 }, "QSN3300-1 ",
6792 { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 0, 15 },
6794 { /* Gore 2m 30awg NoEq */
6795 { 0x00, 0x21, 0x77 }, "QSN3300-2 ",
6796 { 0, 0, 0, 8 }, { 0, 0, 0, 10 }, { 0, 1, 7, 15 },
6798 { /* Gore 1m 28awg NoEq */
6799 { 0x00, 0x21, 0x77 }, "QSN3800-1 ",
6800 { 0, 0, 0, 6 }, { 0, 0, 0, 8 }, { 0, 1, 0, 15 },
6802 { /* Gore 3m 28awg NoEq */
6803 { 0x00, 0x21, 0x77 }, "QSN3800-3 ",
6804 { 0, 0, 0, 9 }, { 0, 0, 0, 13 }, { 0, 1, 7, 15 },
6806 { /* Gore 5m 24awg Eq */
6807 { 0x00, 0x21, 0x77 }, "QSN7000-5 ",
6808 { 0, 0, 0, 7 }, { 0, 0, 0, 9 }, { 0, 1, 3, 15 },
6810 { /* Gore 7m 24awg Eq */
6811 { 0x00, 0x21, 0x77 }, "QSN7000-7 ",
6812 { 0, 0, 0, 9 }, { 0, 0, 0, 11 }, { 0, 2, 6, 15 },
6814 { /* Gore 5m 26awg Eq */
6815 { 0x00, 0x21, 0x77 }, "QSN7600-5 ",
6816 { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 9, 13 },
6818 { /* Gore 7m 26awg Eq */
6819 { 0x00, 0x21, 0x77 }, "QSN7600-7 ",
6820 { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 10, 1, 8, 15 },
6822 { /* Intersil 12m 24awg Active */
6823 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1224",
6824 { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 3, 0, 9 },
6826 { /* Intersil 10m 28awg Active */
6827 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1028",
6828 { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 2, 0, 2 },
6830 { /* Intersil 7m 30awg Active */
6831 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0730",
6832 { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 1, 0, 3 },
6834 { /* Intersil 5m 32awg Active */
6835 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0532",
6836 { 0, 0, 0, 6 }, { 0, 0, 0, 6 }, { 0, 2, 0, 8 },
6838 { /* Intersil Default Active */
6839 { 0x00, 0x30, 0xB4 }, NULL,
6840 { 0, 0, 0, 6 }, { 0, 0, 0, 5 }, { 0, 2, 0, 5 },
6842 { /* Luxtera 20m Active Optical */
6843 { 0x00, 0x25, 0x63 }, NULL,
6844 { 0, 0, 0, 5 }, { 0, 0, 0, 8 }, { 0, 2, 0, 12 },
6846 { /* Molex 1M Cu loopback */
6847 { 0x00, 0x09, 0x3A }, "74763-0025 ",
6848 { 2, 2, 6, 15 }, { 2, 2, 6, 15 }, { 2, 2, 6, 15 },
6850 { /* Molex 2m 28awg NoEq */
6851 { 0x00, 0x09, 0x3A }, "74757-2201 ",
6852 { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 1, 15 },
6856 static const struct txdds_ent txdds_sdr[TXDDS_TABLE_SZ] = {
6857 /* amp, pre, main, post */
6858 { 2, 2, 15, 6 }, /* Loopback */
6859 { 0, 0, 0, 1 }, /* 2 dB */
6860 { 0, 0, 0, 2 }, /* 3 dB */
6861 { 0, 0, 0, 3 }, /* 4 dB */
6862 { 0, 0, 0, 4 }, /* 5 dB */
6863 { 0, 0, 0, 5 }, /* 6 dB */
6864 { 0, 0, 0, 6 }, /* 7 dB */
6865 { 0, 0, 0, 7 }, /* 8 dB */
6866 { 0, 0, 0, 8 }, /* 9 dB */
6867 { 0, 0, 0, 9 }, /* 10 dB */
6868 { 0, 0, 0, 10 }, /* 11 dB */
6869 { 0, 0, 0, 11 }, /* 12 dB */
6870 { 0, 0, 0, 12 }, /* 13 dB */
6871 { 0, 0, 0, 13 }, /* 14 dB */
6872 { 0, 0, 0, 14 }, /* 15 dB */
6873 { 0, 0, 0, 15 }, /* 16 dB */
6876 static const struct txdds_ent txdds_ddr[TXDDS_TABLE_SZ] = {
6877 /* amp, pre, main, post */
6878 { 2, 2, 15, 6 }, /* Loopback */
6879 { 0, 0, 0, 8 }, /* 2 dB */
6880 { 0, 0, 0, 8 }, /* 3 dB */
6881 { 0, 0, 0, 9 }, /* 4 dB */
6882 { 0, 0, 0, 9 }, /* 5 dB */
6883 { 0, 0, 0, 10 }, /* 6 dB */
6884 { 0, 0, 0, 10 }, /* 7 dB */
6885 { 0, 0, 0, 11 }, /* 8 dB */
6886 { 0, 0, 0, 11 }, /* 9 dB */
6887 { 0, 0, 0, 12 }, /* 10 dB */
6888 { 0, 0, 0, 12 }, /* 11 dB */
6889 { 0, 0, 0, 13 }, /* 12 dB */
6890 { 0, 0, 0, 13 }, /* 13 dB */
6891 { 0, 0, 0, 14 }, /* 14 dB */
6892 { 0, 0, 0, 14 }, /* 15 dB */
6893 { 0, 0, 0, 15 }, /* 16 dB */
6896 static const struct txdds_ent txdds_qdr[TXDDS_TABLE_SZ] = {
6897 /* amp, pre, main, post */
6898 { 2, 2, 15, 6 }, /* Loopback */
6899 { 0, 1, 0, 7 }, /* 2 dB (also QMH7342) */
6900 { 0, 1, 0, 9 }, /* 3 dB (also QMH7342) */
6901 { 0, 1, 0, 11 }, /* 4 dB */
6902 { 0, 1, 0, 13 }, /* 5 dB */
6903 { 0, 1, 0, 15 }, /* 6 dB */
6904 { 0, 1, 3, 15 }, /* 7 dB */
6905 { 0, 1, 7, 15 }, /* 8 dB */
6906 { 0, 1, 7, 15 }, /* 9 dB */
6907 { 0, 1, 8, 15 }, /* 10 dB */
6908 { 0, 1, 9, 15 }, /* 11 dB */
6909 { 0, 1, 10, 15 }, /* 12 dB */
6910 { 0, 2, 6, 15 }, /* 13 dB */
6911 { 0, 2, 7, 15 }, /* 14 dB */
6912 { 0, 2, 8, 15 }, /* 15 dB */
6913 { 0, 2, 9, 15 }, /* 16 dB */
6917 * extra entries for use with txselect, for indices >= TXDDS_TABLE_SZ.
6918 * These are mostly used for mez cards going through connectors
6919 * and backplane traces, but can be used to add other "unusual"
6920 * table values as well.
6922 static const struct txdds_ent txdds_extra_sdr[TXDDS_EXTRA_SZ] = {
6923 /* amp, pre, main, post */
6924 { 0, 0, 0, 1 }, /* QMH7342 backplane settings */
6925 { 0, 0, 0, 1 }, /* QMH7342 backplane settings */
6926 { 0, 0, 0, 2 }, /* QMH7342 backplane settings */
6927 { 0, 0, 0, 2 }, /* QMH7342 backplane settings */
6928 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
6929 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
6930 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
6931 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
6932 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
6933 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
6934 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
6937 static const struct txdds_ent txdds_extra_ddr[TXDDS_EXTRA_SZ] = {
6938 /* amp, pre, main, post */
6939 { 0, 0, 0, 7 }, /* QMH7342 backplane settings */
6940 { 0, 0, 0, 7 }, /* QMH7342 backplane settings */
6941 { 0, 0, 0, 8 }, /* QMH7342 backplane settings */
6942 { 0, 0, 0, 8 }, /* QMH7342 backplane settings */
6943 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
6944 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
6945 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
6946 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
6947 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
6948 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
6949 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
6952 static const struct txdds_ent txdds_extra_qdr[TXDDS_EXTRA_SZ] = {
6953 /* amp, pre, main, post */
6954 { 0, 1, 0, 4 }, /* QMH7342 backplane settings */
6955 { 0, 1, 0, 5 }, /* QMH7342 backplane settings */
6956 { 0, 1, 0, 6 }, /* QMH7342 backplane settings */
6957 { 0, 1, 0, 8 }, /* QMH7342 backplane settings */
6958 { 0, 1, 12, 10 }, /* QME7342 backplane setting */
6959 { 0, 1, 12, 11 }, /* QME7342 backplane setting */
6960 { 0, 1, 12, 12 }, /* QME7342 backplane setting */
6961 { 0, 1, 12, 14 }, /* QME7342 backplane setting */
6962 { 0, 1, 12, 6 }, /* QME7342 backplane setting */
6963 { 0, 1, 12, 7 }, /* QME7342 backplane setting */
6964 { 0, 1, 12, 8 }, /* QME7342 backplane setting */
6967 static const struct txdds_ent *get_atten_table(const struct txdds_ent *txdds,
6971 * The attenuation table starts at 2dB for entry 1,
6972 * with entry 0 being the loopback entry.
6976 else if (atten > TXDDS_TABLE_SZ)
6977 atten = TXDDS_TABLE_SZ - 1;
6980 return txdds + atten;
6984 * if override is set, the module parameter txselect has a value
6985 * for this specific port, so use it, rather than our normal mechanism.
6987 static void find_best_ent(struct qib_pportdata *ppd,
6988 const struct txdds_ent **sdr_dds,
6989 const struct txdds_ent **ddr_dds,
6990 const struct txdds_ent **qdr_dds, int override)
6992 struct qib_qsfp_cache *qd = &ppd->cpspec->qsfp_data.cache;
6995 /* Search table of known cables */
6996 for (idx = 0; !override && idx < ARRAY_SIZE(vendor_txdds); ++idx) {
6997 const struct vendor_txdds_ent *v = vendor_txdds + idx;
6999 if (!memcmp(v->oui, qd->oui, QSFP_VOUI_LEN) &&
7001 !memcmp(v->partnum, qd->partnum, QSFP_PN_LEN))) {
7009 /* Lookup serdes setting by cable type and attenuation */
7010 if (!override && QSFP_IS_ACTIVE(qd->tech)) {
7011 *sdr_dds = txdds_sdr + ppd->dd->board_atten;
7012 *ddr_dds = txdds_ddr + ppd->dd->board_atten;
7013 *qdr_dds = txdds_qdr + ppd->dd->board_atten;
7017 if (!override && QSFP_HAS_ATTEN(qd->tech) && (qd->atten[0] ||
7019 *sdr_dds = get_atten_table(txdds_sdr, qd->atten[0]);
7020 *ddr_dds = get_atten_table(txdds_ddr, qd->atten[0]);
7021 *qdr_dds = get_atten_table(txdds_qdr, qd->atten[1]);
7023 } else if (ppd->cpspec->no_eep < TXDDS_TABLE_SZ) {
7025 * If we have no (or incomplete) data from the cable
7026 * EEPROM, or no QSFP, or override is set, use the
7027 * module parameter value to index into the attentuation
7030 idx = ppd->cpspec->no_eep;
7031 *sdr_dds = &txdds_sdr[idx];
7032 *ddr_dds = &txdds_ddr[idx];
7033 *qdr_dds = &txdds_qdr[idx];
7034 } else if (ppd->cpspec->no_eep < (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ)) {
7035 /* similar to above, but index into the "extra" table. */
7036 idx = ppd->cpspec->no_eep - TXDDS_TABLE_SZ;
7037 *sdr_dds = &txdds_extra_sdr[idx];
7038 *ddr_dds = &txdds_extra_ddr[idx];
7039 *qdr_dds = &txdds_extra_qdr[idx];
7041 /* this shouldn't happen, it's range checked */
7042 *sdr_dds = txdds_sdr + qib_long_atten;
7043 *ddr_dds = txdds_ddr + qib_long_atten;
7044 *qdr_dds = txdds_qdr + qib_long_atten;
7048 static void init_txdds_table(struct qib_pportdata *ppd, int override)
7050 const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
7051 struct txdds_ent *dds;
7055 find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, override);
7057 /* for mez cards or override, use the selected value for all entries */
7058 if (!(ppd->dd->flags & QIB_HAS_QSFP) || override)
7061 /* Fill in the first entry with the best entry found. */
7062 set_txdds(ppd, 0, sdr_dds);
7063 set_txdds(ppd, TXDDS_TABLE_SZ, ddr_dds);
7064 set_txdds(ppd, 2 * TXDDS_TABLE_SZ, qdr_dds);
7065 if (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
7067 dds = (struct txdds_ent *)(ppd->link_speed_active ==
7068 QIB_IB_QDR ? qdr_dds :
7069 (ppd->link_speed_active ==
7070 QIB_IB_DDR ? ddr_dds : sdr_dds));
7071 write_tx_serdes_param(ppd, dds);
7074 /* Fill in the remaining entries with the default table values. */
7075 for (idx = 1; idx < ARRAY_SIZE(txdds_sdr); ++idx) {
7076 set_txdds(ppd, idx, single_ent ? sdr_dds : txdds_sdr + idx);
7077 set_txdds(ppd, idx + TXDDS_TABLE_SZ,
7078 single_ent ? ddr_dds : txdds_ddr + idx);
7079 set_txdds(ppd, idx + 2 * TXDDS_TABLE_SZ,
7080 single_ent ? qdr_dds : txdds_qdr + idx);
7084 #define KR_AHB_ACC KREG_IDX(ahb_access_ctrl)
7085 #define KR_AHB_TRANS KREG_IDX(ahb_transaction_reg)
7086 #define AHB_TRANS_RDY SYM_MASK(ahb_transaction_reg, ahb_rdy)
7087 #define AHB_ADDR_LSB SYM_LSB(ahb_transaction_reg, ahb_address)
7088 #define AHB_DATA_LSB SYM_LSB(ahb_transaction_reg, ahb_data)
7089 #define AHB_WR SYM_MASK(ahb_transaction_reg, write_not_read)
7090 #define AHB_TRANS_TRIES 10
7093 * The chan argument is 0=chan0, 1=chan1, 2=pll, 3=chan2, 4=chan4,
7094 * 5=subsystem which is why most calls have "chan + chan >> 1"
7095 * for the channel argument.
7097 static u32 ahb_mod(struct qib_devdata *dd, int quad, int chan, int addr,
7100 u32 rd_data, wr_data, sz_mask;
7101 u64 trans, acc, prev_acc;
7102 u32 ret = 0xBAD0BAD;
7105 prev_acc = qib_read_kreg64(dd, KR_AHB_ACC);
7106 /* From this point on, make sure we return access */
7107 acc = (quad << 1) | 1;
7108 qib_write_kreg(dd, KR_AHB_ACC, acc);
7110 for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
7111 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7112 if (trans & AHB_TRANS_RDY)
7115 if (tries >= AHB_TRANS_TRIES) {
7116 qib_dev_err(dd, "No ahb_rdy in %d tries\n", AHB_TRANS_TRIES);
7120 /* If mask is not all 1s, we need to read, but different SerDes
7121 * entities have different sizes
7123 sz_mask = (1UL << ((quad == 1) ? 32 : 16)) - 1;
7124 wr_data = data & mask & sz_mask;
7125 if ((~mask & sz_mask) != 0) {
7126 trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
7127 qib_write_kreg(dd, KR_AHB_TRANS, trans);
7129 for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
7130 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7131 if (trans & AHB_TRANS_RDY)
7134 if (tries >= AHB_TRANS_TRIES) {
7135 qib_dev_err(dd, "No Rd ahb_rdy in %d tries\n",
7139 /* Re-read in case host split reads and read data first */
7140 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7141 rd_data = (uint32_t)(trans >> AHB_DATA_LSB);
7142 wr_data |= (rd_data & ~mask & sz_mask);
7145 /* If mask is not zero, we need to write. */
7146 if (mask & sz_mask) {
7147 trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
7148 trans |= ((uint64_t)wr_data << AHB_DATA_LSB);
7150 qib_write_kreg(dd, KR_AHB_TRANS, trans);
7152 for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
7153 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7154 if (trans & AHB_TRANS_RDY)
7157 if (tries >= AHB_TRANS_TRIES) {
7158 qib_dev_err(dd, "No Wr ahb_rdy in %d tries\n",
7165 qib_write_kreg(dd, KR_AHB_ACC, prev_acc);
7169 static void ibsd_wr_allchans(struct qib_pportdata *ppd, int addr, unsigned data,
7172 struct qib_devdata *dd = ppd->dd;
7176 for (chan = 0; chan < SERDES_CHANS; ++chan) {
7177 ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)), addr,
7179 rbc = ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7184 static int serdes_7322_init(struct qib_pportdata *ppd)
7190 * Initialize the Tx DDS tables. Also done every QSFP event,
7191 * for adapters with QSFP
7193 init_txdds_table(ppd, 0);
7195 /* ensure no tx overrides from earlier driver loads */
7196 qib_write_kreg_port(ppd, krp_tx_deemph_override,
7197 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7198 reset_tx_deemphasis_override));
7200 /* Patch some SerDes defaults to "Better for IB" */
7201 /* Timing Loop Bandwidth: cdr_timing[11:9] = 0 */
7202 ibsd_wr_allchans(ppd, 2, 0, BMASK(11, 9));
7204 /* Termination: rxtermctrl_r2d addr 11 bits [12:11] = 1 */
7205 ibsd_wr_allchans(ppd, 11, (1 << 11), BMASK(12, 11));
7206 /* Enable LE2: rxle2en_r2a addr 13 bit [6] = 1 */
7207 ibsd_wr_allchans(ppd, 13, (1 << 6), (1 << 6));
7209 /* May be overridden in qsfp_7322_event */
7210 le_val = IS_QME(ppd->dd) ? LE2_QME : LE2_DEFAULT;
7211 ibsd_wr_allchans(ppd, 13, (le_val << 7), BMASK(9, 7));
7213 /* enable LE1 adaptation for all but QME, which is disabled */
7214 le_val = IS_QME(ppd->dd) ? 0 : 1;
7215 ibsd_wr_allchans(ppd, 13, (le_val << 5), (1 << 5));
7217 /* Clear cmode-override, may be set from older driver */
7218 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
7220 /* Timing Recovery: rxtapsel addr 5 bits [9:8] = 0 */
7221 ibsd_wr_allchans(ppd, 5, (0 << 8), BMASK(9, 8));
7223 /* setup LoS params; these are subsystem, so chan == 5 */
7224 /* LoS filter threshold_count on, ch 0-3, set to 8 */
7225 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 5, 8 << 11, BMASK(14, 11));
7226 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 8 << 4, BMASK(7, 4));
7227 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 8, 8 << 11, BMASK(14, 11));
7228 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 8 << 4, BMASK(7, 4));
7230 /* LoS filter threshold_count off, ch 0-3, set to 4 */
7231 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 6, 4 << 0, BMASK(3, 0));
7232 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 4 << 8, BMASK(11, 8));
7233 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 4 << 0, BMASK(3, 0));
7234 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 4 << 8, BMASK(11, 8));
7236 /* LoS filter select enabled */
7237 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 1 << 15, 1 << 15);
7239 /* LoS target data: SDR=4, DDR=2, QDR=1 */
7240 ibsd_wr_allchans(ppd, 14, (1 << 3), BMASK(5, 3)); /* QDR */
7241 ibsd_wr_allchans(ppd, 20, (2 << 10), BMASK(12, 10)); /* DDR */
7242 ibsd_wr_allchans(ppd, 20, (4 << 13), BMASK(15, 13)); /* SDR */
7244 data = qib_read_kreg_port(ppd, krp_serdesctrl);
7245 qib_write_kreg_port(ppd, krp_serdesctrl, data |
7246 SYM_MASK(IBSerdesCtrl_0, RXLOSEN));
7248 /* rxbistena; set 0 to avoid effects of it switch later */
7249 ibsd_wr_allchans(ppd, 9, 0 << 15, 1 << 15);
7251 /* Configure 4 DFE taps, and only they adapt */
7252 ibsd_wr_allchans(ppd, 16, 0 << 0, BMASK(1, 0));
7254 /* gain hi stop 32 (22) (6:1) lo stop 7 (10:7) target 22 (13) (15:11) */
7255 le_val = (ppd->dd->cspec->r1 || IS_QME(ppd->dd)) ? 0xb6c0 : 0x6bac;
7256 ibsd_wr_allchans(ppd, 21, le_val, 0xfffe);
7259 * Set receive adaptation mode. SDR and DDR adaptation are
7260 * always on, and QDR is initially enabled; later disabled.
7262 qib_write_kreg_port(ppd, krp_static_adapt_dis(0), 0ULL);
7263 qib_write_kreg_port(ppd, krp_static_adapt_dis(1), 0ULL);
7264 qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
7265 ppd->dd->cspec->r1 ?
7266 QDR_STATIC_ADAPT_DOWN_R1 : QDR_STATIC_ADAPT_DOWN);
7267 ppd->cpspec->qdr_dfe_on = 1;
7269 /* FLoop LOS gate: PPM filter enabled */
7270 ibsd_wr_allchans(ppd, 38, 0 << 10, 1 << 10);
7272 /* rx offset center enabled */
7273 ibsd_wr_allchans(ppd, 12, 1 << 4, 1 << 4);
7275 if (!ppd->dd->cspec->r1) {
7276 ibsd_wr_allchans(ppd, 12, 1 << 12, 1 << 12);
7277 ibsd_wr_allchans(ppd, 12, 2 << 8, 0x0f << 8);
7280 /* Set the frequency loop bandwidth to 15 */
7281 ibsd_wr_allchans(ppd, 2, 15 << 5, BMASK(8, 5));
7286 /* start adjust QMH serdes parameters */
7288 static void set_man_code(struct qib_pportdata *ppd, int chan, int code)
7290 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7291 9, code << 9, 0x3f << 9);
7294 static void set_man_mode_h1(struct qib_pportdata *ppd, int chan,
7295 int enable, u32 tapenable)
7298 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7299 1, 3 << 10, 0x1f << 10);
7301 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7305 /* Set clock to 1, 0, 1, 0 */
7306 static void clock_man(struct qib_pportdata *ppd, int chan)
7308 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7310 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7312 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7314 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7319 * write the current Tx serdes pre,post,main,amp settings into the serdes.
7320 * The caller must pass the settings appropriate for the current speed,
7321 * or not care if they are correct for the current speed.
7323 static void write_tx_serdes_param(struct qib_pportdata *ppd,
7324 struct txdds_ent *txdds)
7328 deemph = qib_read_kreg_port(ppd, krp_tx_deemph_override);
7329 /* field names for amp, main, post, pre, respectively */
7330 deemph &= ~(SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txampcntl_d2a) |
7331 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txc0_ena) |
7332 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcp1_ena) |
7333 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcn1_ena));
7335 deemph |= SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7336 tx_override_deemphasis_select);
7337 deemph |= (txdds->amp & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7338 txampcntl_d2a)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7340 deemph |= (txdds->main & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7341 txc0_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7343 deemph |= (txdds->post & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7344 txcp1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7346 deemph |= (txdds->pre & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7347 txcn1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7349 qib_write_kreg_port(ppd, krp_tx_deemph_override, deemph);
7353 * Set the parameters for mez cards on link bounce, so they are
7354 * always exactly what was requested. Similar logic to init_txdds
7355 * but does just the serdes.
7357 static void adj_tx_serdes(struct qib_pportdata *ppd)
7359 const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
7360 struct txdds_ent *dds;
7362 find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, 1);
7363 dds = (struct txdds_ent *)(ppd->link_speed_active == QIB_IB_QDR ?
7364 qdr_dds : (ppd->link_speed_active == QIB_IB_DDR ?
7365 ddr_dds : sdr_dds));
7366 write_tx_serdes_param(ppd, dds);
7369 /* set QDR forced value for H1, if needed */
7370 static void force_h1(struct qib_pportdata *ppd)
7374 ppd->cpspec->qdr_reforce = 0;
7375 if (!ppd->dd->cspec->r1)
7378 for (chan = 0; chan < SERDES_CHANS; chan++) {
7379 set_man_mode_h1(ppd, chan, 1, 0);
7380 set_man_code(ppd, chan, ppd->cpspec->h1_val);
7381 clock_man(ppd, chan);
7382 set_man_mode_h1(ppd, chan, 0, 0);
7386 #define SJA_EN SYM_MASK(SPC_JTAG_ACCESS_REG, SPC_JTAG_ACCESS_EN)
7387 #define BISTEN_LSB SYM_LSB(SPC_JTAG_ACCESS_REG, bist_en)
7389 #define R_OPCODE_LSB 3
7391 #define R_OP_SHIFT 2
7392 #define R_OP_UPDATE 3
7397 static int qib_r_grab(struct qib_devdata *dd)
7401 qib_write_kreg(dd, kr_r_access, val);
7402 qib_read_kreg32(dd, kr_scratch);
7406 /* qib_r_wait_for_rdy() not only waits for the ready bit, it
7407 * returns the current state of R_TDO
7409 static int qib_r_wait_for_rdy(struct qib_devdata *dd)
7413 for (timeout = 0; timeout < 100 ; ++timeout) {
7414 val = qib_read_kreg32(dd, kr_r_access);
7416 return (val >> R_TDO_LSB) & 1;
7421 static int qib_r_shift(struct qib_devdata *dd, int bisten,
7422 int len, u8 *inp, u8 *outp)
7427 valbase = SJA_EN | (bisten << BISTEN_LSB) |
7428 (R_OP_SHIFT << R_OPCODE_LSB);
7429 ret = qib_r_wait_for_rdy(dd);
7432 for (pos = 0; pos < len; ++pos) {
7435 outp[pos >> 3] &= ~(1 << (pos & 7));
7436 outp[pos >> 3] |= (ret << (pos & 7));
7439 int tdi = inp[pos >> 3] >> (pos & 7);
7440 val |= ((tdi & 1) << R_TDI_LSB);
7442 qib_write_kreg(dd, kr_r_access, val);
7443 qib_read_kreg32(dd, kr_scratch);
7444 ret = qib_r_wait_for_rdy(dd);
7448 /* Restore to NOP between operations. */
7449 val = SJA_EN | (bisten << BISTEN_LSB);
7450 qib_write_kreg(dd, kr_r_access, val);
7451 qib_read_kreg32(dd, kr_scratch);
7452 ret = qib_r_wait_for_rdy(dd);
7460 static int qib_r_update(struct qib_devdata *dd, int bisten)
7465 val = SJA_EN | (bisten << BISTEN_LSB) | (R_OP_UPDATE << R_OPCODE_LSB);
7466 ret = qib_r_wait_for_rdy(dd);
7468 qib_write_kreg(dd, kr_r_access, val);
7469 qib_read_kreg32(dd, kr_scratch);
7474 #define BISTEN_PORT_SEL 15
7475 #define LEN_PORT_SEL 625
7476 #define BISTEN_AT 17
7478 #define BISTEN_ETM 16
7481 #define BIT2BYTE(x) (((x) + BITS_PER_BYTE - 1) / BITS_PER_BYTE)
7483 /* these are common for all IB port use cases. */
7484 static u8 reset_at[BIT2BYTE(LEN_AT)] = {
7485 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7486 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
7488 static u8 reset_atetm[BIT2BYTE(LEN_ETM)] = {
7489 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7490 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7491 0x00, 0x00, 0x00, 0x80, 0xe3, 0x81, 0x73, 0x3c, 0x70, 0x8e,
7492 0x07, 0xce, 0xf1, 0xc0, 0x39, 0x1e, 0x38, 0xc7, 0x03, 0xe7,
7493 0x78, 0xe0, 0x1c, 0x0f, 0x9c, 0x7f, 0x80, 0x73, 0x0f, 0x70,
7494 0xde, 0x01, 0xce, 0x39, 0xc0, 0xf9, 0x06, 0x38, 0xd7, 0x00,
7495 0xe7, 0x19, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7496 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
7498 static u8 at[BIT2BYTE(LEN_AT)] = {
7499 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
7500 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
7503 /* used for IB1 or IB2, only one in use */
7504 static u8 atetm_1port[BIT2BYTE(LEN_ETM)] = {
7505 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7506 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7507 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7508 0x00, 0x10, 0xf2, 0x80, 0x83, 0x1e, 0x38, 0x00, 0x00, 0x00,
7509 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7510 0x00, 0x00, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xc8, 0x03,
7511 0x07, 0x7b, 0xa0, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x18, 0x00,
7512 0x18, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00,
7515 /* used when both IB1 and IB2 are in use */
7516 static u8 atetm_2port[BIT2BYTE(LEN_ETM)] = {
7517 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7518 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79,
7519 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7520 0x00, 0x00, 0xf8, 0x80, 0x83, 0x1e, 0x38, 0xe0, 0x03, 0x05,
7521 0x7b, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
7522 0xa2, 0x0f, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xd1, 0x07,
7523 0x02, 0x7c, 0x80, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x3e, 0x00,
7524 0x02, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00,
7527 /* used when only IB1 is in use */
7528 static u8 portsel_port1[BIT2BYTE(LEN_PORT_SEL)] = {
7529 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
7530 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
7531 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
7532 0x13, 0x78, 0x78, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
7533 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
7534 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
7535 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
7536 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
7539 /* used when only IB2 is in use */
7540 static u8 portsel_port2[BIT2BYTE(LEN_PORT_SEL)] = {
7541 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x39, 0x39,
7542 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x73, 0x32, 0x32, 0x32,
7543 0x32, 0x32, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
7544 0x39, 0x78, 0x78, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
7545 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x74, 0x32,
7546 0x32, 0x32, 0x32, 0x32, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
7547 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
7548 0x3a, 0x3a, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
7551 /* used when both IB1 and IB2 are in use */
7552 static u8 portsel_2port[BIT2BYTE(LEN_PORT_SEL)] = {
7553 0x32, 0xba, 0x54, 0x76, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
7554 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
7555 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
7556 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
7557 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
7558 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x3a,
7559 0x3a, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
7560 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
7564 * Do setup to properly handle IB link recovery; if port is zero, we
7565 * are initializing to cover both ports; otherwise we are initializing
7566 * to cover a single port card, or the port has reached INIT and we may
7567 * need to switch coverage types.
7569 static void setup_7322_link_recovery(struct qib_pportdata *ppd, u32 both)
7572 struct qib_devdata *dd = ppd->dd;
7574 if (!ppd->dd->cspec->r1)
7577 dd->cspec->recovery_ports_initted++;
7578 ppd->cpspec->recovery_init = 1;
7580 if (!both && dd->cspec->recovery_ports_initted == 1) {
7581 portsel = ppd->port == 1 ? portsel_port1 : portsel_port2;
7584 portsel = portsel_2port;
7588 if (qib_r_grab(dd) < 0 ||
7589 qib_r_shift(dd, BISTEN_ETM, LEN_ETM, reset_atetm, NULL) < 0 ||
7590 qib_r_update(dd, BISTEN_ETM) < 0 ||
7591 qib_r_shift(dd, BISTEN_AT, LEN_AT, reset_at, NULL) < 0 ||
7592 qib_r_update(dd, BISTEN_AT) < 0 ||
7593 qib_r_shift(dd, BISTEN_PORT_SEL, LEN_PORT_SEL,
7594 portsel, NULL) < 0 ||
7595 qib_r_update(dd, BISTEN_PORT_SEL) < 0 ||
7596 qib_r_shift(dd, BISTEN_AT, LEN_AT, at, NULL) < 0 ||
7597 qib_r_update(dd, BISTEN_AT) < 0 ||
7598 qib_r_shift(dd, BISTEN_ETM, LEN_ETM, etm, NULL) < 0 ||
7599 qib_r_update(dd, BISTEN_ETM) < 0)
7600 qib_dev_err(dd, "Failed IB link recovery setup\n");
7603 static void check_7322_rxe_status(struct qib_pportdata *ppd)
7605 struct qib_devdata *dd = ppd->dd;
7608 if (dd->cspec->recovery_ports_initted != 1)
7609 return; /* rest doesn't apply to dualport */
7610 qib_write_kreg(dd, kr_control, dd->control |
7611 SYM_MASK(Control, FreezeMode));
7612 (void)qib_read_kreg64(dd, kr_scratch);
7613 udelay(3); /* ibcreset asserted 400ns, be sure that's over */
7614 fmask = qib_read_kreg64(dd, kr_act_fmask);
7617 * require a powercycle before we'll work again, and make
7618 * sure we get no more interrupts, and don't turn off
7621 ppd->dd->cspec->stay_in_freeze = 1;
7622 qib_7322_set_intr_state(ppd->dd, 0);
7623 qib_write_kreg(dd, kr_fmask, 0ULL);
7624 qib_dev_err(dd, "HCA unusable until powercycled\n");
7625 return; /* eventually reset */
7628 qib_write_kreg(ppd->dd, kr_hwerrclear,
7629 SYM_MASK(HwErrClear, IBSerdesPClkNotDetectClear_1));
7631 /* don't do the full clear_freeze(), not needed for this */
7632 qib_write_kreg(dd, kr_control, dd->control);
7633 qib_read_kreg32(dd, kr_scratch);
7634 /* take IBC out of reset */
7635 if (ppd->link_speed_supported) {
7636 ppd->cpspec->ibcctrl_a &=
7637 ~SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
7638 qib_write_kreg_port(ppd, krp_ibcctrl_a,
7639 ppd->cpspec->ibcctrl_a);
7640 qib_read_kreg32(dd, kr_scratch);
7641 if (ppd->lflags & QIBL_IB_LINK_DISABLED)
7642 qib_set_ib_7322_lstate(ppd, 0,
7643 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);