2 * Copyright (c) 2012 Intel Corporation. All rights reserved.
3 * Copyright (c) 2008 - 2012 QLogic Corporation. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 * This file contains all of the code that is specific to the
36 * InfiniPath 7322 chip
39 #include <linux/interrupt.h>
40 #include <linux/pci.h>
41 #include <linux/delay.h>
43 #include <linux/jiffies.h>
44 #include <linux/module.h>
45 #include <rdma/ib_verbs.h>
46 #include <rdma/ib_smi.h>
47 #ifdef CONFIG_INFINIBAND_QIB_DCA
48 #include <linux/dca.h>
52 #include "qib_7322_regs.h"
56 #include "qib_verbs.h"
59 #define pr_fmt(fmt) QIB_DRV_NAME " " fmt
61 static void qib_setup_7322_setextled(struct qib_pportdata *, u32);
62 static void qib_7322_handle_hwerrors(struct qib_devdata *, char *, size_t);
63 static void sendctrl_7322_mod(struct qib_pportdata *ppd, u32 op);
64 static irqreturn_t qib_7322intr(int irq, void *data);
65 static irqreturn_t qib_7322bufavail(int irq, void *data);
66 static irqreturn_t sdma_intr(int irq, void *data);
67 static irqreturn_t sdma_idle_intr(int irq, void *data);
68 static irqreturn_t sdma_progress_intr(int irq, void *data);
69 static irqreturn_t sdma_cleanup_intr(int irq, void *data);
70 static void qib_7322_txchk_change(struct qib_devdata *, u32, u32, u32,
71 struct qib_ctxtdata *rcd);
72 static u8 qib_7322_phys_portstate(u64);
73 static u32 qib_7322_iblink_state(u64);
74 static void qib_set_ib_7322_lstate(struct qib_pportdata *ppd, u16 linkcmd,
76 static void force_h1(struct qib_pportdata *);
77 static void adj_tx_serdes(struct qib_pportdata *);
78 static u32 qib_7322_setpbc_control(struct qib_pportdata *, u32, u8, u8);
79 static void qib_7322_mini_pcs_reset(struct qib_pportdata *);
81 static u32 ahb_mod(struct qib_devdata *, int, int, int, u32, u32);
82 static void ibsd_wr_allchans(struct qib_pportdata *, int, unsigned, unsigned);
83 static void serdes_7322_los_enable(struct qib_pportdata *, int);
84 static int serdes_7322_init_old(struct qib_pportdata *);
85 static int serdes_7322_init_new(struct qib_pportdata *);
87 #define BMASK(msb, lsb) (((1 << ((msb) + 1 - (lsb))) - 1) << (lsb))
89 /* LE2 serdes values for different cases */
94 /* Below is special-purpose, so only really works for the IB SerDes blocks. */
95 #define IBSD(hw_pidx) (hw_pidx + 2)
97 /* these are variables for documentation and experimentation purposes */
98 static const unsigned rcv_int_timeout = 375;
99 static const unsigned rcv_int_count = 16;
100 static const unsigned sdma_idle_cnt = 64;
102 /* Time to stop altering Rx Equalization parameters, after link up. */
103 #define RXEQ_DISABLE_MSECS 2500
106 * Number of VLs we are configured to use (to allow for more
107 * credits per vl, etc.)
109 ushort qib_num_cfg_vls = 2;
110 module_param_named(num_vls, qib_num_cfg_vls, ushort, S_IRUGO);
111 MODULE_PARM_DESC(num_vls, "Set number of Virtual Lanes to use (1-8)");
113 static ushort qib_chase = 1;
114 module_param_named(chase, qib_chase, ushort, S_IRUGO);
115 MODULE_PARM_DESC(chase, "Enable state chase handling");
117 static ushort qib_long_atten = 10; /* 10 dB ~= 5m length */
118 module_param_named(long_attenuation, qib_long_atten, ushort, S_IRUGO);
119 MODULE_PARM_DESC(long_attenuation, \
120 "attenuation cutoff (dB) for long copper cable setup");
122 static ushort qib_singleport;
123 module_param_named(singleport, qib_singleport, ushort, S_IRUGO);
124 MODULE_PARM_DESC(singleport, "Use only IB port 1; more per-port buffer space");
126 static ushort qib_krcvq01_no_msi;
127 module_param_named(krcvq01_no_msi, qib_krcvq01_no_msi, ushort, S_IRUGO);
128 MODULE_PARM_DESC(krcvq01_no_msi, "No MSI for kctx < 2");
131 * Receive header queue sizes
133 static unsigned qib_rcvhdrcnt;
134 module_param_named(rcvhdrcnt, qib_rcvhdrcnt, uint, S_IRUGO);
135 MODULE_PARM_DESC(rcvhdrcnt, "receive header count");
137 static unsigned qib_rcvhdrsize;
138 module_param_named(rcvhdrsize, qib_rcvhdrsize, uint, S_IRUGO);
139 MODULE_PARM_DESC(rcvhdrsize, "receive header size in 32-bit words");
141 static unsigned qib_rcvhdrentsize;
142 module_param_named(rcvhdrentsize, qib_rcvhdrentsize, uint, S_IRUGO);
143 MODULE_PARM_DESC(rcvhdrentsize, "receive header entry size in 32-bit words");
145 #define MAX_ATTEN_LEN 64 /* plenty for any real system */
146 /* for read back, default index is ~5m copper cable */
147 static char txselect_list[MAX_ATTEN_LEN] = "10";
148 static struct kparam_string kp_txselect = {
149 .string = txselect_list,
150 .maxlen = MAX_ATTEN_LEN
152 static int setup_txselect(const char *, struct kernel_param *);
153 module_param_call(txselect, setup_txselect, param_get_string,
154 &kp_txselect, S_IWUSR | S_IRUGO);
155 MODULE_PARM_DESC(txselect, \
156 "Tx serdes indices (for no QSFP or invalid QSFP data)");
158 #define BOARD_QME7342 5
159 #define BOARD_QMH7342 6
160 #define IS_QMH(dd) (SYM_FIELD((dd)->revision, Revision, BoardID) == \
162 #define IS_QME(dd) (SYM_FIELD((dd)->revision, Revision, BoardID) == \
165 #define KREG_IDX(regname) (QIB_7322_##regname##_OFFS / sizeof(u64))
167 #define KREG_IBPORT_IDX(regname) ((QIB_7322_##regname##_0_OFFS / sizeof(u64)))
169 #define MASK_ACROSS(lsb, msb) \
170 (((1ULL << ((msb) + 1 - (lsb))) - 1) << (lsb))
172 #define SYM_RMASK(regname, fldname) ((u64) \
173 QIB_7322_##regname##_##fldname##_RMASK)
175 #define SYM_MASK(regname, fldname) ((u64) \
176 QIB_7322_##regname##_##fldname##_RMASK << \
177 QIB_7322_##regname##_##fldname##_LSB)
179 #define SYM_FIELD(value, regname, fldname) ((u64) \
180 (((value) >> SYM_LSB(regname, fldname)) & \
181 SYM_RMASK(regname, fldname)))
183 /* useful for things like LaFifoEmpty_0...7, TxCreditOK_0...7, etc. */
184 #define SYM_FIELD_ACROSS(value, regname, fldname, nbits) \
185 (((value) >> SYM_LSB(regname, fldname)) & MASK_ACROSS(0, nbits))
187 #define HWE_MASK(fldname) SYM_MASK(HwErrMask, fldname##Mask)
188 #define ERR_MASK(fldname) SYM_MASK(ErrMask, fldname##Mask)
189 #define ERR_MASK_N(fldname) SYM_MASK(ErrMask_0, fldname##Mask)
190 #define INT_MASK(fldname) SYM_MASK(IntMask, fldname##IntMask)
191 #define INT_MASK_P(fldname, port) SYM_MASK(IntMask, fldname##IntMask##_##port)
192 /* Below because most, but not all, fields of IntMask have that full suffix */
193 #define INT_MASK_PM(fldname, port) SYM_MASK(IntMask, fldname##Mask##_##port)
196 #define SYM_LSB(regname, fldname) (QIB_7322_##regname##_##fldname##_LSB)
199 * the size bits give us 2^N, in KB units. 0 marks as invalid,
200 * and 7 is reserved. We currently use only 2KB and 4KB
202 #define IBA7322_TID_SZ_SHIFT QIB_7322_RcvTIDArray0_RT_BufSize_LSB
203 #define IBA7322_TID_SZ_2K (1UL<<IBA7322_TID_SZ_SHIFT) /* 2KB */
204 #define IBA7322_TID_SZ_4K (2UL<<IBA7322_TID_SZ_SHIFT) /* 4KB */
205 #define IBA7322_TID_PA_SHIFT 11U /* TID addr in chip stored w/o low bits */
207 #define SendIBSLIDAssignMask \
208 QIB_7322_SendIBSLIDAssign_0_SendIBSLIDAssign_15_0_RMASK
209 #define SendIBSLMCMask \
210 QIB_7322_SendIBSLIDMask_0_SendIBSLIDMask_15_0_RMASK
212 #define ExtLED_IB1_YEL SYM_MASK(EXTCtrl, LEDPort0YellowOn)
213 #define ExtLED_IB1_GRN SYM_MASK(EXTCtrl, LEDPort0GreenOn)
214 #define ExtLED_IB2_YEL SYM_MASK(EXTCtrl, LEDPort1YellowOn)
215 #define ExtLED_IB2_GRN SYM_MASK(EXTCtrl, LEDPort1GreenOn)
216 #define ExtLED_IB1_MASK (ExtLED_IB1_YEL | ExtLED_IB1_GRN)
217 #define ExtLED_IB2_MASK (ExtLED_IB2_YEL | ExtLED_IB2_GRN)
219 #define _QIB_GPIO_SDA_NUM 1
220 #define _QIB_GPIO_SCL_NUM 0
221 #define QIB_EEPROM_WEN_NUM 14
222 #define QIB_TWSI_EEPROM_DEV 0xA2 /* All Production 7322 cards. */
224 /* HW counter clock is at 4nsec */
225 #define QIB_7322_PSXMITWAIT_CHECK_RATE 4000
227 /* full speed IB port 1 only */
228 #define PORT_SPD_CAP (QIB_IB_SDR | QIB_IB_DDR | QIB_IB_QDR)
229 #define PORT_SPD_CAP_SHIFT 3
231 /* full speed featuremask, both ports */
232 #define DUAL_PORT_CAP (PORT_SPD_CAP | (PORT_SPD_CAP << PORT_SPD_CAP_SHIFT))
235 * This file contains almost all the chip-specific register information and
236 * access functions for the FAKED QLogic InfiniPath 7322 PCI-Express chip.
239 /* Use defines to tie machine-generated names to lower-case names */
240 #define kr_contextcnt KREG_IDX(ContextCnt)
241 #define kr_control KREG_IDX(Control)
242 #define kr_counterregbase KREG_IDX(CntrRegBase)
243 #define kr_errclear KREG_IDX(ErrClear)
244 #define kr_errmask KREG_IDX(ErrMask)
245 #define kr_errstatus KREG_IDX(ErrStatus)
246 #define kr_extctrl KREG_IDX(EXTCtrl)
247 #define kr_extstatus KREG_IDX(EXTStatus)
248 #define kr_gpio_clear KREG_IDX(GPIOClear)
249 #define kr_gpio_mask KREG_IDX(GPIOMask)
250 #define kr_gpio_out KREG_IDX(GPIOOut)
251 #define kr_gpio_status KREG_IDX(GPIOStatus)
252 #define kr_hwdiagctrl KREG_IDX(HwDiagCtrl)
253 #define kr_debugportval KREG_IDX(DebugPortValueReg)
254 #define kr_fmask KREG_IDX(feature_mask)
255 #define kr_act_fmask KREG_IDX(active_feature_mask)
256 #define kr_hwerrclear KREG_IDX(HwErrClear)
257 #define kr_hwerrmask KREG_IDX(HwErrMask)
258 #define kr_hwerrstatus KREG_IDX(HwErrStatus)
259 #define kr_intclear KREG_IDX(IntClear)
260 #define kr_intmask KREG_IDX(IntMask)
261 #define kr_intredirect KREG_IDX(IntRedirect0)
262 #define kr_intstatus KREG_IDX(IntStatus)
263 #define kr_pagealign KREG_IDX(PageAlign)
264 #define kr_rcvavailtimeout KREG_IDX(RcvAvailTimeOut0)
265 #define kr_rcvctrl KREG_IDX(RcvCtrl) /* Common, but chip also has per-port */
266 #define kr_rcvegrbase KREG_IDX(RcvEgrBase)
267 #define kr_rcvegrcnt KREG_IDX(RcvEgrCnt)
268 #define kr_rcvhdrcnt KREG_IDX(RcvHdrCnt)
269 #define kr_rcvhdrentsize KREG_IDX(RcvHdrEntSize)
270 #define kr_rcvhdrsize KREG_IDX(RcvHdrSize)
271 #define kr_rcvtidbase KREG_IDX(RcvTIDBase)
272 #define kr_rcvtidcnt KREG_IDX(RcvTIDCnt)
273 #define kr_revision KREG_IDX(Revision)
274 #define kr_scratch KREG_IDX(Scratch)
275 #define kr_sendbuffererror KREG_IDX(SendBufErr0) /* and base for 1 and 2 */
276 #define kr_sendcheckmask KREG_IDX(SendCheckMask0) /* and 1, 2 */
277 #define kr_sendctrl KREG_IDX(SendCtrl)
278 #define kr_sendgrhcheckmask KREG_IDX(SendGRHCheckMask0) /* and 1, 2 */
279 #define kr_sendibpktmask KREG_IDX(SendIBPacketMask0) /* and 1, 2 */
280 #define kr_sendpioavailaddr KREG_IDX(SendBufAvailAddr)
281 #define kr_sendpiobufbase KREG_IDX(SendBufBase)
282 #define kr_sendpiobufcnt KREG_IDX(SendBufCnt)
283 #define kr_sendpiosize KREG_IDX(SendBufSize)
284 #define kr_sendregbase KREG_IDX(SendRegBase)
285 #define kr_sendbufavail0 KREG_IDX(SendBufAvail0)
286 #define kr_userregbase KREG_IDX(UserRegBase)
287 #define kr_intgranted KREG_IDX(Int_Granted)
288 #define kr_vecclr_wo_int KREG_IDX(vec_clr_without_int)
289 #define kr_intblocked KREG_IDX(IntBlocked)
290 #define kr_r_access KREG_IDX(SPC_JTAG_ACCESS_REG)
293 * per-port kernel registers. Access only with qib_read_kreg_port()
294 * or qib_write_kreg_port()
296 #define krp_errclear KREG_IBPORT_IDX(ErrClear)
297 #define krp_errmask KREG_IBPORT_IDX(ErrMask)
298 #define krp_errstatus KREG_IBPORT_IDX(ErrStatus)
299 #define krp_highprio_0 KREG_IBPORT_IDX(HighPriority0)
300 #define krp_highprio_limit KREG_IBPORT_IDX(HighPriorityLimit)
301 #define krp_hrtbt_guid KREG_IBPORT_IDX(HRTBT_GUID)
302 #define krp_ib_pcsconfig KREG_IBPORT_IDX(IBPCSConfig)
303 #define krp_ibcctrl_a KREG_IBPORT_IDX(IBCCtrlA)
304 #define krp_ibcctrl_b KREG_IBPORT_IDX(IBCCtrlB)
305 #define krp_ibcctrl_c KREG_IBPORT_IDX(IBCCtrlC)
306 #define krp_ibcstatus_a KREG_IBPORT_IDX(IBCStatusA)
307 #define krp_ibcstatus_b KREG_IBPORT_IDX(IBCStatusB)
308 #define krp_txestatus KREG_IBPORT_IDX(TXEStatus)
309 #define krp_lowprio_0 KREG_IBPORT_IDX(LowPriority0)
310 #define krp_ncmodectrl KREG_IBPORT_IDX(IBNCModeCtrl)
311 #define krp_partitionkey KREG_IBPORT_IDX(RcvPartitionKey)
312 #define krp_psinterval KREG_IBPORT_IDX(PSInterval)
313 #define krp_psstart KREG_IBPORT_IDX(PSStart)
314 #define krp_psstat KREG_IBPORT_IDX(PSStat)
315 #define krp_rcvbthqp KREG_IBPORT_IDX(RcvBTHQP)
316 #define krp_rcvctrl KREG_IBPORT_IDX(RcvCtrl)
317 #define krp_rcvpktledcnt KREG_IBPORT_IDX(RcvPktLEDCnt)
318 #define krp_rcvqpmaptable KREG_IBPORT_IDX(RcvQPMapTableA)
319 #define krp_rxcreditvl0 KREG_IBPORT_IDX(RxCreditVL0)
320 #define krp_rxcreditvl15 (KREG_IBPORT_IDX(RxCreditVL0)+15)
321 #define krp_sendcheckcontrol KREG_IBPORT_IDX(SendCheckControl)
322 #define krp_sendctrl KREG_IBPORT_IDX(SendCtrl)
323 #define krp_senddmabase KREG_IBPORT_IDX(SendDmaBase)
324 #define krp_senddmabufmask0 KREG_IBPORT_IDX(SendDmaBufMask0)
325 #define krp_senddmabufmask1 (KREG_IBPORT_IDX(SendDmaBufMask0) + 1)
326 #define krp_senddmabufmask2 (KREG_IBPORT_IDX(SendDmaBufMask0) + 2)
327 #define krp_senddmabuf_use0 KREG_IBPORT_IDX(SendDmaBufUsed0)
328 #define krp_senddmabuf_use1 (KREG_IBPORT_IDX(SendDmaBufUsed0) + 1)
329 #define krp_senddmabuf_use2 (KREG_IBPORT_IDX(SendDmaBufUsed0) + 2)
330 #define krp_senddmadesccnt KREG_IBPORT_IDX(SendDmaDescCnt)
331 #define krp_senddmahead KREG_IBPORT_IDX(SendDmaHead)
332 #define krp_senddmaheadaddr KREG_IBPORT_IDX(SendDmaHeadAddr)
333 #define krp_senddmaidlecnt KREG_IBPORT_IDX(SendDmaIdleCnt)
334 #define krp_senddmalengen KREG_IBPORT_IDX(SendDmaLenGen)
335 #define krp_senddmaprioritythld KREG_IBPORT_IDX(SendDmaPriorityThld)
336 #define krp_senddmareloadcnt KREG_IBPORT_IDX(SendDmaReloadCnt)
337 #define krp_senddmastatus KREG_IBPORT_IDX(SendDmaStatus)
338 #define krp_senddmatail KREG_IBPORT_IDX(SendDmaTail)
339 #define krp_sendhdrsymptom KREG_IBPORT_IDX(SendHdrErrSymptom)
340 #define krp_sendslid KREG_IBPORT_IDX(SendIBSLIDAssign)
341 #define krp_sendslidmask KREG_IBPORT_IDX(SendIBSLIDMask)
342 #define krp_ibsdtestiftx KREG_IBPORT_IDX(IB_SDTEST_IF_TX)
343 #define krp_adapt_dis_timer KREG_IBPORT_IDX(ADAPT_DISABLE_TIMER_THRESHOLD)
344 #define krp_tx_deemph_override KREG_IBPORT_IDX(IBSD_TX_DEEMPHASIS_OVERRIDE)
345 #define krp_serdesctrl KREG_IBPORT_IDX(IBSerdesCtrl)
348 * Per-context kernel registers. Access only with qib_read_kreg_ctxt()
349 * or qib_write_kreg_ctxt()
351 #define krc_rcvhdraddr KREG_IDX(RcvHdrAddr0)
352 #define krc_rcvhdrtailaddr KREG_IDX(RcvHdrTailAddr0)
355 * TID Flow table, per context. Reduces
356 * number of hdrq updates to one per flow (or on errors).
357 * context 0 and 1 share same memory, but have distinct
358 * addresses. Since for now, we never use expected sends
359 * on kernel contexts, we don't worry about that (we initialize
360 * those entries for ctxt 0/1 on driver load twice, for example).
362 #define NUM_TIDFLOWS_CTXT 0x20 /* 0x20 per context; have to hardcode */
363 #define ur_rcvflowtable (KREG_IDX(RcvTIDFlowTable0) - KREG_IDX(RcvHdrTail0))
365 /* these are the error bits in the tid flows, and are W1C */
366 #define TIDFLOW_ERRBITS ( \
367 (SYM_MASK(RcvTIDFlowTable0, GenMismatch) << \
368 SYM_LSB(RcvTIDFlowTable0, GenMismatch)) | \
369 (SYM_MASK(RcvTIDFlowTable0, SeqMismatch) << \
370 SYM_LSB(RcvTIDFlowTable0, SeqMismatch)))
372 /* Most (not all) Counters are per-IBport.
373 * Requires LBIntCnt is at offset 0 in the group
375 #define CREG_IDX(regname) \
376 ((QIB_7322_##regname##_0_OFFS - QIB_7322_LBIntCnt_OFFS) / sizeof(u64))
378 #define crp_badformat CREG_IDX(RxVersionErrCnt)
379 #define crp_err_rlen CREG_IDX(RxLenErrCnt)
380 #define crp_erricrc CREG_IDX(RxICRCErrCnt)
381 #define crp_errlink CREG_IDX(RxLinkMalformCnt)
382 #define crp_errlpcrc CREG_IDX(RxLPCRCErrCnt)
383 #define crp_errpkey CREG_IDX(RxPKeyMismatchCnt)
384 #define crp_errvcrc CREG_IDX(RxVCRCErrCnt)
385 #define crp_excessbufferovfl CREG_IDX(ExcessBufferOvflCnt)
386 #define crp_iblinkdown CREG_IDX(IBLinkDownedCnt)
387 #define crp_iblinkerrrecov CREG_IDX(IBLinkErrRecoveryCnt)
388 #define crp_ibstatuschange CREG_IDX(IBStatusChangeCnt)
389 #define crp_ibsymbolerr CREG_IDX(IBSymbolErrCnt)
390 #define crp_invalidrlen CREG_IDX(RxMaxMinLenErrCnt)
391 #define crp_locallinkintegrityerr CREG_IDX(LocalLinkIntegrityErrCnt)
392 #define crp_pktrcv CREG_IDX(RxDataPktCnt)
393 #define crp_pktrcvflowctrl CREG_IDX(RxFlowPktCnt)
394 #define crp_pktsend CREG_IDX(TxDataPktCnt)
395 #define crp_pktsendflow CREG_IDX(TxFlowPktCnt)
396 #define crp_psrcvdatacount CREG_IDX(PSRcvDataCount)
397 #define crp_psrcvpktscount CREG_IDX(PSRcvPktsCount)
398 #define crp_psxmitdatacount CREG_IDX(PSXmitDataCount)
399 #define crp_psxmitpktscount CREG_IDX(PSXmitPktsCount)
400 #define crp_psxmitwaitcount CREG_IDX(PSXmitWaitCount)
401 #define crp_rcvebp CREG_IDX(RxEBPCnt)
402 #define crp_rcvflowctrlviol CREG_IDX(RxFlowCtrlViolCnt)
403 #define crp_rcvovfl CREG_IDX(RxBufOvflCnt)
404 #define crp_rxdlidfltr CREG_IDX(RxDlidFltrCnt)
405 #define crp_rxdroppkt CREG_IDX(RxDroppedPktCnt)
406 #define crp_rxotherlocalphyerr CREG_IDX(RxOtherLocalPhyErrCnt)
407 #define crp_rxqpinvalidctxt CREG_IDX(RxQPInvalidContextCnt)
408 #define crp_rxvlerr CREG_IDX(RxVlErrCnt)
409 #define crp_sendstall CREG_IDX(TxFlowStallCnt)
410 #define crp_txdroppedpkt CREG_IDX(TxDroppedPktCnt)
411 #define crp_txhdrerr CREG_IDX(TxHeadersErrCnt)
412 #define crp_txlenerr CREG_IDX(TxLenErrCnt)
413 #define crp_txminmaxlenerr CREG_IDX(TxMaxMinLenErrCnt)
414 #define crp_txsdmadesc CREG_IDX(TxSDmaDescCnt)
415 #define crp_txunderrun CREG_IDX(TxUnderrunCnt)
416 #define crp_txunsupvl CREG_IDX(TxUnsupVLErrCnt)
417 #define crp_vl15droppedpkt CREG_IDX(RxVL15DroppedPktCnt)
418 #define crp_wordrcv CREG_IDX(RxDwordCnt)
419 #define crp_wordsend CREG_IDX(TxDwordCnt)
420 #define crp_tx_creditstalls CREG_IDX(TxCreditUpToDateTimeOut)
422 /* these are the (few) counters that are not port-specific */
423 #define CREG_DEVIDX(regname) ((QIB_7322_##regname##_OFFS - \
424 QIB_7322_LBIntCnt_OFFS) / sizeof(u64))
425 #define cr_base_egrovfl CREG_DEVIDX(RxP0HdrEgrOvflCnt)
426 #define cr_lbint CREG_DEVIDX(LBIntCnt)
427 #define cr_lbstall CREG_DEVIDX(LBFlowStallCnt)
428 #define cr_pcieretrydiag CREG_DEVIDX(PcieRetryBufDiagQwordCnt)
429 #define cr_rxtidflowdrop CREG_DEVIDX(RxTidFlowDropCnt)
430 #define cr_tidfull CREG_DEVIDX(RxTIDFullErrCnt)
431 #define cr_tidinvalid CREG_DEVIDX(RxTIDValidErrCnt)
433 /* no chip register for # of IB ports supported, so define */
434 #define NUM_IB_PORTS 2
436 /* 1 VL15 buffer per hardware IB port, no register for this, so define */
437 #define NUM_VL15_BUFS NUM_IB_PORTS
440 * context 0 and 1 are special, and there is no chip register that
441 * defines this value, so we have to define it here.
442 * These are all allocated to either 0 or 1 for single port
443 * hardware configuration, otherwise each gets half
445 #define KCTXT0_EGRCNT 2048
447 /* values for vl and port fields in PBC, 7322-specific */
448 #define PBC_PORT_SEL_LSB 26
449 #define PBC_PORT_SEL_RMASK 1
450 #define PBC_VL_NUM_LSB 27
451 #define PBC_VL_NUM_RMASK 7
452 #define PBC_7322_VL15_SEND (1ULL << 63) /* pbc; VL15, no credit check */
453 #define PBC_7322_VL15_SEND_CTRL (1ULL << 31) /* control version of same */
455 static u8 ib_rate_to_delay[IB_RATE_120_GBPS + 1] = {
456 [IB_RATE_2_5_GBPS] = 16,
457 [IB_RATE_5_GBPS] = 8,
458 [IB_RATE_10_GBPS] = 4,
459 [IB_RATE_20_GBPS] = 2,
460 [IB_RATE_30_GBPS] = 2,
461 [IB_RATE_40_GBPS] = 1
464 #define IBA7322_LINKSPEED_SHIFT SYM_LSB(IBCStatusA_0, LinkSpeedActive)
465 #define IBA7322_LINKWIDTH_SHIFT SYM_LSB(IBCStatusA_0, LinkWidthActive)
467 /* link training states, from IBC */
468 #define IB_7322_LT_STATE_DISABLED 0x00
469 #define IB_7322_LT_STATE_LINKUP 0x01
470 #define IB_7322_LT_STATE_POLLACTIVE 0x02
471 #define IB_7322_LT_STATE_POLLQUIET 0x03
472 #define IB_7322_LT_STATE_SLEEPDELAY 0x04
473 #define IB_7322_LT_STATE_SLEEPQUIET 0x05
474 #define IB_7322_LT_STATE_CFGDEBOUNCE 0x08
475 #define IB_7322_LT_STATE_CFGRCVFCFG 0x09
476 #define IB_7322_LT_STATE_CFGWAITRMT 0x0a
477 #define IB_7322_LT_STATE_CFGIDLE 0x0b
478 #define IB_7322_LT_STATE_RECOVERRETRAIN 0x0c
479 #define IB_7322_LT_STATE_TXREVLANES 0x0d
480 #define IB_7322_LT_STATE_RECOVERWAITRMT 0x0e
481 #define IB_7322_LT_STATE_RECOVERIDLE 0x0f
482 #define IB_7322_LT_STATE_CFGENH 0x10
483 #define IB_7322_LT_STATE_CFGTEST 0x11
484 #define IB_7322_LT_STATE_CFGWAITRMTTEST 0x12
485 #define IB_7322_LT_STATE_CFGWAITENH 0x13
487 /* link state machine states from IBC */
488 #define IB_7322_L_STATE_DOWN 0x0
489 #define IB_7322_L_STATE_INIT 0x1
490 #define IB_7322_L_STATE_ARM 0x2
491 #define IB_7322_L_STATE_ACTIVE 0x3
492 #define IB_7322_L_STATE_ACT_DEFER 0x4
494 static const u8 qib_7322_physportstate[0x20] = {
495 [IB_7322_LT_STATE_DISABLED] = IB_PHYSPORTSTATE_DISABLED,
496 [IB_7322_LT_STATE_LINKUP] = IB_PHYSPORTSTATE_LINKUP,
497 [IB_7322_LT_STATE_POLLACTIVE] = IB_PHYSPORTSTATE_POLL,
498 [IB_7322_LT_STATE_POLLQUIET] = IB_PHYSPORTSTATE_POLL,
499 [IB_7322_LT_STATE_SLEEPDELAY] = IB_PHYSPORTSTATE_SLEEP,
500 [IB_7322_LT_STATE_SLEEPQUIET] = IB_PHYSPORTSTATE_SLEEP,
501 [IB_7322_LT_STATE_CFGDEBOUNCE] = IB_PHYSPORTSTATE_CFG_TRAIN,
502 [IB_7322_LT_STATE_CFGRCVFCFG] =
503 IB_PHYSPORTSTATE_CFG_TRAIN,
504 [IB_7322_LT_STATE_CFGWAITRMT] =
505 IB_PHYSPORTSTATE_CFG_TRAIN,
506 [IB_7322_LT_STATE_CFGIDLE] = IB_PHYSPORTSTATE_CFG_IDLE,
507 [IB_7322_LT_STATE_RECOVERRETRAIN] =
508 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
509 [IB_7322_LT_STATE_RECOVERWAITRMT] =
510 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
511 [IB_7322_LT_STATE_RECOVERIDLE] =
512 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
513 [IB_7322_LT_STATE_CFGENH] = IB_PHYSPORTSTATE_CFG_ENH,
514 [IB_7322_LT_STATE_CFGTEST] = IB_PHYSPORTSTATE_CFG_TRAIN,
515 [IB_7322_LT_STATE_CFGWAITRMTTEST] =
516 IB_PHYSPORTSTATE_CFG_TRAIN,
517 [IB_7322_LT_STATE_CFGWAITENH] =
518 IB_PHYSPORTSTATE_CFG_WAIT_ENH,
519 [0x14] = IB_PHYSPORTSTATE_CFG_TRAIN,
520 [0x15] = IB_PHYSPORTSTATE_CFG_TRAIN,
521 [0x16] = IB_PHYSPORTSTATE_CFG_TRAIN,
522 [0x17] = IB_PHYSPORTSTATE_CFG_TRAIN
525 #ifdef CONFIG_INFINIBAND_QIB_DCA
526 struct qib_irq_notify {
529 struct irq_affinity_notify notify;
533 struct qib_chip_specific {
534 u64 __iomem *cregbase;
536 spinlock_t rcvmod_lock; /* protect rcvctrl shadow changes */
537 spinlock_t gpio_lock; /* RMW of shadows/regs for ExtCtrl and GPIO */
538 u64 main_int_mask; /* clear bits which have dedicated handlers */
539 u64 int_enable_mask; /* for per port interrupts in single port mode */
542 u64 gpio_out; /* shadow of kr_gpio_out, for rmw ops */
543 u64 gpio_mask; /* shadow the gpio mask register */
544 u64 extctrl; /* shadow the gpio output enable, etc... */
551 u32 updthresh; /* current AvailUpdThld */
552 u32 updthresh_dflt; /* default AvailUpdThld */
555 u32 num_msix_entries;
559 u32 recovery_ports_initted;
560 #ifdef CONFIG_INFINIBAND_QIB_DCA
564 u64 dca_rcvhdr_ctrl[5]; /* B, C, D, E, F */
566 struct qib_msix_entry *msix_entries;
567 unsigned long *sendchkenable;
568 unsigned long *sendgrhchk;
569 unsigned long *sendibchk;
570 u32 rcvavail_timeout[18];
571 char emsgbuf[128]; /* for device error interrupt msg buffer */
574 /* Table of entries in "human readable" form Tx Emphasis. */
582 struct vendor_txdds_ent {
583 u8 oui[QSFP_VOUI_LEN];
585 struct txdds_ent sdr;
586 struct txdds_ent ddr;
587 struct txdds_ent qdr;
590 static void write_tx_serdes_param(struct qib_pportdata *, struct txdds_ent *);
592 #define TXDDS_TABLE_SZ 16 /* number of entries per speed in onchip table */
593 #define TXDDS_EXTRA_SZ 13 /* number of extra tx settings entries */
594 #define TXDDS_MFG_SZ 2 /* number of mfg tx settings entries */
595 #define SERDES_CHANS 4 /* yes, it's obvious, but one less magic number */
597 #define H1_FORCE_VAL 8
598 #define H1_FORCE_QME 1 /* may be overridden via setup_txselect() */
599 #define H1_FORCE_QMH 7 /* may be overridden via setup_txselect() */
601 /* The static and dynamic registers are paired, and the pairs indexed by spd */
602 #define krp_static_adapt_dis(spd) (KREG_IBPORT_IDX(ADAPT_DISABLE_STATIC_SDR) \
605 #define QDR_DFE_DISABLE_DELAY 4000 /* msec after LINKUP */
606 #define QDR_STATIC_ADAPT_DOWN 0xf0f0f0f0ULL /* link down, H1-H4 QDR adapts */
607 #define QDR_STATIC_ADAPT_DOWN_R1 0ULL /* r1 link down, H1-H4 QDR adapts */
608 #define QDR_STATIC_ADAPT_INIT 0xffffffffffULL /* up, disable H0,H1-8, LE */
609 #define QDR_STATIC_ADAPT_INIT_R1 0xf0ffffffffULL /* r1 up, disable H0,H1-8 */
611 struct qib_chippport_specific {
612 u64 __iomem *kpregbase;
613 u64 __iomem *cpregbase;
615 struct qib_pportdata *ppd;
616 wait_queue_head_t autoneg_wait;
617 struct delayed_work autoneg_work;
618 struct delayed_work ipg_work;
619 struct timer_list chase_timer;
621 * these 5 fields are used to establish deltas for IB symbol
622 * errors and linkrecovery errors. They can be reported on
623 * some chips during link negotiation prior to INIT, and with
624 * DDR when faking DDR negotiations with non-IBTA switches.
625 * The chip counters are adjusted at driver unload if there is
637 u64 ibcctrl_a; /* krp_ibcctrl_a shadow */
638 u64 ibcctrl_b; /* krp_ibcctrl_b shadow */
639 unsigned long qdr_dfe_time;
640 unsigned long chase_end;
646 * Per-bay per-channel rcv QMH H1 values and Tx values for QDR.
647 * entry zero is unused, to simplify indexing
650 u8 no_eep; /* txselect table index to use if no qsfp info */
653 struct qib_qsfp_data qsfp_data;
654 char epmsgbuf[192]; /* for port error interrupt msg buffer */
659 irq_handler_t handler;
661 int port; /* 0 if not port-specific, else port # */
664 { "", qib_7322intr, -1, 0, 0 },
665 { " (buf avail)", qib_7322bufavail,
666 SYM_LSB(IntStatus, SendBufAvail), 0, 0},
667 { " (sdma 0)", sdma_intr,
668 SYM_LSB(IntStatus, SDmaInt_0), 1, 1 },
669 { " (sdma 1)", sdma_intr,
670 SYM_LSB(IntStatus, SDmaInt_1), 2, 1 },
671 { " (sdmaI 0)", sdma_idle_intr,
672 SYM_LSB(IntStatus, SDmaIdleInt_0), 1, 1},
673 { " (sdmaI 1)", sdma_idle_intr,
674 SYM_LSB(IntStatus, SDmaIdleInt_1), 2, 1},
675 { " (sdmaP 0)", sdma_progress_intr,
676 SYM_LSB(IntStatus, SDmaProgressInt_0), 1, 1 },
677 { " (sdmaP 1)", sdma_progress_intr,
678 SYM_LSB(IntStatus, SDmaProgressInt_1), 2, 1 },
679 { " (sdmaC 0)", sdma_cleanup_intr,
680 SYM_LSB(IntStatus, SDmaCleanupDone_0), 1, 0 },
681 { " (sdmaC 1)", sdma_cleanup_intr,
682 SYM_LSB(IntStatus, SDmaCleanupDone_1), 2 , 0},
685 #ifdef CONFIG_INFINIBAND_QIB_DCA
687 static const struct dca_reg_map {
692 } dca_rcvhdr_reg_map[] = {
693 { 0, SYM_LSB(DCACtrlB, RcvHdrq0DCAOPH),
694 ~SYM_MASK(DCACtrlB, RcvHdrq0DCAOPH) , KREG_IDX(DCACtrlB) },
695 { 0, SYM_LSB(DCACtrlB, RcvHdrq1DCAOPH),
696 ~SYM_MASK(DCACtrlB, RcvHdrq1DCAOPH) , KREG_IDX(DCACtrlB) },
697 { 0, SYM_LSB(DCACtrlB, RcvHdrq2DCAOPH),
698 ~SYM_MASK(DCACtrlB, RcvHdrq2DCAOPH) , KREG_IDX(DCACtrlB) },
699 { 0, SYM_LSB(DCACtrlB, RcvHdrq3DCAOPH),
700 ~SYM_MASK(DCACtrlB, RcvHdrq3DCAOPH) , KREG_IDX(DCACtrlB) },
701 { 1, SYM_LSB(DCACtrlC, RcvHdrq4DCAOPH),
702 ~SYM_MASK(DCACtrlC, RcvHdrq4DCAOPH) , KREG_IDX(DCACtrlC) },
703 { 1, SYM_LSB(DCACtrlC, RcvHdrq5DCAOPH),
704 ~SYM_MASK(DCACtrlC, RcvHdrq5DCAOPH) , KREG_IDX(DCACtrlC) },
705 { 1, SYM_LSB(DCACtrlC, RcvHdrq6DCAOPH),
706 ~SYM_MASK(DCACtrlC, RcvHdrq6DCAOPH) , KREG_IDX(DCACtrlC) },
707 { 1, SYM_LSB(DCACtrlC, RcvHdrq7DCAOPH),
708 ~SYM_MASK(DCACtrlC, RcvHdrq7DCAOPH) , KREG_IDX(DCACtrlC) },
709 { 2, SYM_LSB(DCACtrlD, RcvHdrq8DCAOPH),
710 ~SYM_MASK(DCACtrlD, RcvHdrq8DCAOPH) , KREG_IDX(DCACtrlD) },
711 { 2, SYM_LSB(DCACtrlD, RcvHdrq9DCAOPH),
712 ~SYM_MASK(DCACtrlD, RcvHdrq9DCAOPH) , KREG_IDX(DCACtrlD) },
713 { 2, SYM_LSB(DCACtrlD, RcvHdrq10DCAOPH),
714 ~SYM_MASK(DCACtrlD, RcvHdrq10DCAOPH) , KREG_IDX(DCACtrlD) },
715 { 2, SYM_LSB(DCACtrlD, RcvHdrq11DCAOPH),
716 ~SYM_MASK(DCACtrlD, RcvHdrq11DCAOPH) , KREG_IDX(DCACtrlD) },
717 { 3, SYM_LSB(DCACtrlE, RcvHdrq12DCAOPH),
718 ~SYM_MASK(DCACtrlE, RcvHdrq12DCAOPH) , KREG_IDX(DCACtrlE) },
719 { 3, SYM_LSB(DCACtrlE, RcvHdrq13DCAOPH),
720 ~SYM_MASK(DCACtrlE, RcvHdrq13DCAOPH) , KREG_IDX(DCACtrlE) },
721 { 3, SYM_LSB(DCACtrlE, RcvHdrq14DCAOPH),
722 ~SYM_MASK(DCACtrlE, RcvHdrq14DCAOPH) , KREG_IDX(DCACtrlE) },
723 { 3, SYM_LSB(DCACtrlE, RcvHdrq15DCAOPH),
724 ~SYM_MASK(DCACtrlE, RcvHdrq15DCAOPH) , KREG_IDX(DCACtrlE) },
725 { 4, SYM_LSB(DCACtrlF, RcvHdrq16DCAOPH),
726 ~SYM_MASK(DCACtrlF, RcvHdrq16DCAOPH) , KREG_IDX(DCACtrlF) },
727 { 4, SYM_LSB(DCACtrlF, RcvHdrq17DCAOPH),
728 ~SYM_MASK(DCACtrlF, RcvHdrq17DCAOPH) , KREG_IDX(DCACtrlF) },
733 #define QLOGIC_IB_IBCC_LINKINITCMD_DISABLE 1
734 /* cycle through TS1/TS2 till OK */
735 #define QLOGIC_IB_IBCC_LINKINITCMD_POLL 2
736 /* wait for TS1, then go on */
737 #define QLOGIC_IB_IBCC_LINKINITCMD_SLEEP 3
738 #define QLOGIC_IB_IBCC_LINKINITCMD_SHIFT 16
740 #define QLOGIC_IB_IBCC_LINKCMD_DOWN 1 /* move to 0x11 */
741 #define QLOGIC_IB_IBCC_LINKCMD_ARMED 2 /* move to 0x21 */
742 #define QLOGIC_IB_IBCC_LINKCMD_ACTIVE 3 /* move to 0x31 */
744 #define BLOB_7322_IBCHG 0x101
746 static inline void qib_write_kreg(const struct qib_devdata *dd,
747 const u32 regno, u64 value);
748 static inline u32 qib_read_kreg32(const struct qib_devdata *, const u32);
749 static void write_7322_initregs(struct qib_devdata *);
750 static void write_7322_init_portregs(struct qib_pportdata *);
751 static void setup_7322_link_recovery(struct qib_pportdata *, u32);
752 static void check_7322_rxe_status(struct qib_pportdata *);
753 static u32 __iomem *qib_7322_getsendbuf(struct qib_pportdata *, u64, u32 *);
754 #ifdef CONFIG_INFINIBAND_QIB_DCA
755 static void qib_setup_dca(struct qib_devdata *dd);
756 static void setup_dca_notifier(struct qib_devdata *dd,
757 struct qib_msix_entry *m);
758 static void reset_dca_notifier(struct qib_devdata *dd,
759 struct qib_msix_entry *m);
763 * qib_read_ureg32 - read 32-bit virtualized per-context register
765 * @regno: register number
766 * @ctxt: context number
768 * Return the contents of a register that is virtualized to be per context.
769 * Returns -1 on errors (not distinguishable from valid contents at
770 * runtime; we may add a separate error variable at some point).
772 static inline u32 qib_read_ureg32(const struct qib_devdata *dd,
773 enum qib_ureg regno, int ctxt)
775 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
777 return readl(regno + (u64 __iomem *)(
778 (dd->ureg_align * ctxt) + (dd->userbase ?
779 (char __iomem *)dd->userbase :
780 (char __iomem *)dd->kregbase + dd->uregbase)));
784 * qib_read_ureg - read virtualized per-context register
786 * @regno: register number
787 * @ctxt: context number
789 * Return the contents of a register that is virtualized to be per context.
790 * Returns -1 on errors (not distinguishable from valid contents at
791 * runtime; we may add a separate error variable at some point).
793 static inline u64 qib_read_ureg(const struct qib_devdata *dd,
794 enum qib_ureg regno, int ctxt)
797 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
799 return readq(regno + (u64 __iomem *)(
800 (dd->ureg_align * ctxt) + (dd->userbase ?
801 (char __iomem *)dd->userbase :
802 (char __iomem *)dd->kregbase + dd->uregbase)));
806 * qib_write_ureg - write virtualized per-context register
808 * @regno: register number
812 * Write the contents of a register that is virtualized to be per context.
814 static inline void qib_write_ureg(const struct qib_devdata *dd,
815 enum qib_ureg regno, u64 value, int ctxt)
819 ubase = (u64 __iomem *)
820 ((char __iomem *) dd->userbase +
821 dd->ureg_align * ctxt);
823 ubase = (u64 __iomem *)
825 (char __iomem *) dd->kregbase +
826 dd->ureg_align * ctxt);
828 if (dd->kregbase && (dd->flags & QIB_PRESENT))
829 writeq(value, &ubase[regno]);
832 static inline u32 qib_read_kreg32(const struct qib_devdata *dd,
835 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
837 return readl((u32 __iomem *) &dd->kregbase[regno]);
840 static inline u64 qib_read_kreg64(const struct qib_devdata *dd,
843 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
845 return readq(&dd->kregbase[regno]);
848 static inline void qib_write_kreg(const struct qib_devdata *dd,
849 const u32 regno, u64 value)
851 if (dd->kregbase && (dd->flags & QIB_PRESENT))
852 writeq(value, &dd->kregbase[regno]);
856 * not many sanity checks for the port-specific kernel register routines,
857 * since they are only used when it's known to be safe.
859 static inline u64 qib_read_kreg_port(const struct qib_pportdata *ppd,
862 if (!ppd->cpspec->kpregbase || !(ppd->dd->flags & QIB_PRESENT))
864 return readq(&ppd->cpspec->kpregbase[regno]);
867 static inline void qib_write_kreg_port(const struct qib_pportdata *ppd,
868 const u16 regno, u64 value)
870 if (ppd->cpspec && ppd->dd && ppd->cpspec->kpregbase &&
871 (ppd->dd->flags & QIB_PRESENT))
872 writeq(value, &ppd->cpspec->kpregbase[regno]);
876 * qib_write_kreg_ctxt - write a device's per-ctxt 64-bit kernel register
877 * @dd: the qlogic_ib device
878 * @regno: the register number to write
879 * @ctxt: the context containing the register
880 * @value: the value to write
882 static inline void qib_write_kreg_ctxt(const struct qib_devdata *dd,
883 const u16 regno, unsigned ctxt,
886 qib_write_kreg(dd, regno + ctxt, value);
889 static inline u64 read_7322_creg(const struct qib_devdata *dd, u16 regno)
891 if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
893 return readq(&dd->cspec->cregbase[regno]);
898 static inline u32 read_7322_creg32(const struct qib_devdata *dd, u16 regno)
900 if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
902 return readl(&dd->cspec->cregbase[regno]);
907 static inline void write_7322_creg_port(const struct qib_pportdata *ppd,
908 u16 regno, u64 value)
910 if (ppd->cpspec && ppd->cpspec->cpregbase &&
911 (ppd->dd->flags & QIB_PRESENT))
912 writeq(value, &ppd->cpspec->cpregbase[regno]);
915 static inline u64 read_7322_creg_port(const struct qib_pportdata *ppd,
918 if (!ppd->cpspec || !ppd->cpspec->cpregbase ||
919 !(ppd->dd->flags & QIB_PRESENT))
921 return readq(&ppd->cpspec->cpregbase[regno]);
924 static inline u32 read_7322_creg32_port(const struct qib_pportdata *ppd,
927 if (!ppd->cpspec || !ppd->cpspec->cpregbase ||
928 !(ppd->dd->flags & QIB_PRESENT))
930 return readl(&ppd->cpspec->cpregbase[regno]);
933 /* bits in Control register */
934 #define QLOGIC_IB_C_RESET SYM_MASK(Control, SyncReset)
935 #define QLOGIC_IB_C_SDMAFETCHPRIOEN SYM_MASK(Control, SDmaDescFetchPriorityEn)
937 /* bits in general interrupt regs */
938 #define QIB_I_RCVURG_LSB SYM_LSB(IntMask, RcvUrg0IntMask)
939 #define QIB_I_RCVURG_RMASK MASK_ACROSS(0, 17)
940 #define QIB_I_RCVURG_MASK (QIB_I_RCVURG_RMASK << QIB_I_RCVURG_LSB)
941 #define QIB_I_RCVAVAIL_LSB SYM_LSB(IntMask, RcvAvail0IntMask)
942 #define QIB_I_RCVAVAIL_RMASK MASK_ACROSS(0, 17)
943 #define QIB_I_RCVAVAIL_MASK (QIB_I_RCVAVAIL_RMASK << QIB_I_RCVAVAIL_LSB)
944 #define QIB_I_C_ERROR INT_MASK(Err)
946 #define QIB_I_SPIOSENT (INT_MASK_P(SendDone, 0) | INT_MASK_P(SendDone, 1))
947 #define QIB_I_SPIOBUFAVAIL INT_MASK(SendBufAvail)
948 #define QIB_I_GPIO INT_MASK(AssertGPIO)
949 #define QIB_I_P_SDMAINT(pidx) \
950 (INT_MASK_P(SDma, pidx) | INT_MASK_P(SDmaIdle, pidx) | \
951 INT_MASK_P(SDmaProgress, pidx) | \
952 INT_MASK_PM(SDmaCleanupDone, pidx))
954 /* Interrupt bits that are "per port" */
955 #define QIB_I_P_BITSEXTANT(pidx) \
956 (INT_MASK_P(Err, pidx) | INT_MASK_P(SendDone, pidx) | \
957 INT_MASK_P(SDma, pidx) | INT_MASK_P(SDmaIdle, pidx) | \
958 INT_MASK_P(SDmaProgress, pidx) | \
959 INT_MASK_PM(SDmaCleanupDone, pidx))
961 /* Interrupt bits that are common to a device */
962 /* currently unused: QIB_I_SPIOSENT */
963 #define QIB_I_C_BITSEXTANT \
964 (QIB_I_RCVURG_MASK | QIB_I_RCVAVAIL_MASK | \
966 QIB_I_C_ERROR | QIB_I_SPIOBUFAVAIL | QIB_I_GPIO)
968 #define QIB_I_BITSEXTANT (QIB_I_C_BITSEXTANT | \
969 QIB_I_P_BITSEXTANT(0) | QIB_I_P_BITSEXTANT(1))
972 * Error bits that are "per port".
974 #define QIB_E_P_IBSTATUSCHANGED ERR_MASK_N(IBStatusChanged)
975 #define QIB_E_P_SHDR ERR_MASK_N(SHeadersErr)
976 #define QIB_E_P_VL15_BUF_MISUSE ERR_MASK_N(VL15BufMisuseErr)
977 #define QIB_E_P_SND_BUF_MISUSE ERR_MASK_N(SendBufMisuseErr)
978 #define QIB_E_P_SUNSUPVL ERR_MASK_N(SendUnsupportedVLErr)
979 #define QIB_E_P_SUNEXP_PKTNUM ERR_MASK_N(SendUnexpectedPktNumErr)
980 #define QIB_E_P_SDROP_DATA ERR_MASK_N(SendDroppedDataPktErr)
981 #define QIB_E_P_SDROP_SMP ERR_MASK_N(SendDroppedSmpPktErr)
982 #define QIB_E_P_SPKTLEN ERR_MASK_N(SendPktLenErr)
983 #define QIB_E_P_SUNDERRUN ERR_MASK_N(SendUnderRunErr)
984 #define QIB_E_P_SMAXPKTLEN ERR_MASK_N(SendMaxPktLenErr)
985 #define QIB_E_P_SMINPKTLEN ERR_MASK_N(SendMinPktLenErr)
986 #define QIB_E_P_RIBLOSTLINK ERR_MASK_N(RcvIBLostLinkErr)
987 #define QIB_E_P_RHDR ERR_MASK_N(RcvHdrErr)
988 #define QIB_E_P_RHDRLEN ERR_MASK_N(RcvHdrLenErr)
989 #define QIB_E_P_RBADTID ERR_MASK_N(RcvBadTidErr)
990 #define QIB_E_P_RBADVERSION ERR_MASK_N(RcvBadVersionErr)
991 #define QIB_E_P_RIBFLOW ERR_MASK_N(RcvIBFlowErr)
992 #define QIB_E_P_REBP ERR_MASK_N(RcvEBPErr)
993 #define QIB_E_P_RUNSUPVL ERR_MASK_N(RcvUnsupportedVLErr)
994 #define QIB_E_P_RUNEXPCHAR ERR_MASK_N(RcvUnexpectedCharErr)
995 #define QIB_E_P_RSHORTPKTLEN ERR_MASK_N(RcvShortPktLenErr)
996 #define QIB_E_P_RLONGPKTLEN ERR_MASK_N(RcvLongPktLenErr)
997 #define QIB_E_P_RMAXPKTLEN ERR_MASK_N(RcvMaxPktLenErr)
998 #define QIB_E_P_RMINPKTLEN ERR_MASK_N(RcvMinPktLenErr)
999 #define QIB_E_P_RICRC ERR_MASK_N(RcvICRCErr)
1000 #define QIB_E_P_RVCRC ERR_MASK_N(RcvVCRCErr)
1001 #define QIB_E_P_RFORMATERR ERR_MASK_N(RcvFormatErr)
1003 #define QIB_E_P_SDMA1STDESC ERR_MASK_N(SDma1stDescErr)
1004 #define QIB_E_P_SDMABASE ERR_MASK_N(SDmaBaseErr)
1005 #define QIB_E_P_SDMADESCADDRMISALIGN ERR_MASK_N(SDmaDescAddrMisalignErr)
1006 #define QIB_E_P_SDMADWEN ERR_MASK_N(SDmaDwEnErr)
1007 #define QIB_E_P_SDMAGENMISMATCH ERR_MASK_N(SDmaGenMismatchErr)
1008 #define QIB_E_P_SDMAHALT ERR_MASK_N(SDmaHaltErr)
1009 #define QIB_E_P_SDMAMISSINGDW ERR_MASK_N(SDmaMissingDwErr)
1010 #define QIB_E_P_SDMAOUTOFBOUND ERR_MASK_N(SDmaOutOfBoundErr)
1011 #define QIB_E_P_SDMARPYTAG ERR_MASK_N(SDmaRpyTagErr)
1012 #define QIB_E_P_SDMATAILOUTOFBOUND ERR_MASK_N(SDmaTailOutOfBoundErr)
1013 #define QIB_E_P_SDMAUNEXPDATA ERR_MASK_N(SDmaUnexpDataErr)
1015 /* Error bits that are common to a device */
1016 #define QIB_E_RESET ERR_MASK(ResetNegated)
1017 #define QIB_E_HARDWARE ERR_MASK(HardwareErr)
1018 #define QIB_E_INVALIDADDR ERR_MASK(InvalidAddrErr)
1022 * Per chip (rather than per-port) errors. Most either do
1023 * nothing but trigger a print (because they self-recover, or
1024 * always occur in tandem with other errors that handle the
1025 * issue), or because they indicate errors with no recovery,
1026 * but we want to know that they happened.
1028 #define QIB_E_SBUF_VL15_MISUSE ERR_MASK(SBufVL15MisUseErr)
1029 #define QIB_E_BADEEP ERR_MASK(InvalidEEPCmd)
1030 #define QIB_E_VLMISMATCH ERR_MASK(SendVLMismatchErr)
1031 #define QIB_E_ARMLAUNCH ERR_MASK(SendArmLaunchErr)
1032 #define QIB_E_SPCLTRIG ERR_MASK(SendSpecialTriggerErr)
1033 #define QIB_E_RRCVHDRFULL ERR_MASK(RcvHdrFullErr)
1034 #define QIB_E_RRCVEGRFULL ERR_MASK(RcvEgrFullErr)
1035 #define QIB_E_RCVCTXTSHARE ERR_MASK(RcvContextShareErr)
1037 /* SDMA chip errors (not per port)
1038 * QIB_E_SDMA_BUF_DUP needs no special handling, because we will also get
1039 * the SDMAHALT error immediately, so we just print the dup error via the
1040 * E_AUTO mechanism. This is true of most of the per-port fatal errors
1041 * as well, but since this is port-independent, by definition, it's
1042 * handled a bit differently. SDMA_VL15 and SDMA_WRONG_PORT are per
1043 * packet send errors, and so are handled in the same manner as other
1044 * per-packet errors.
1046 #define QIB_E_SDMA_VL15 ERR_MASK(SDmaVL15Err)
1047 #define QIB_E_SDMA_WRONG_PORT ERR_MASK(SDmaWrongPortErr)
1048 #define QIB_E_SDMA_BUF_DUP ERR_MASK(SDmaBufMaskDuplicateErr)
1051 * Below functionally equivalent to legacy QLOGIC_IB_E_PKTERRS
1052 * it is used to print "common" packet errors.
1054 #define QIB_E_P_PKTERRS (QIB_E_P_SPKTLEN |\
1055 QIB_E_P_SDROP_DATA | QIB_E_P_RVCRC |\
1056 QIB_E_P_RICRC | QIB_E_P_RSHORTPKTLEN |\
1057 QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SHDR | \
1060 /* Error Bits that Packet-related (Receive, per-port) */
1061 #define QIB_E_P_RPKTERRS (\
1062 QIB_E_P_RHDRLEN | QIB_E_P_RBADTID | \
1063 QIB_E_P_RBADVERSION | QIB_E_P_RHDR | \
1064 QIB_E_P_RLONGPKTLEN | QIB_E_P_RSHORTPKTLEN |\
1065 QIB_E_P_RMAXPKTLEN | QIB_E_P_RMINPKTLEN | \
1066 QIB_E_P_RFORMATERR | QIB_E_P_RUNSUPVL | \
1067 QIB_E_P_RUNEXPCHAR | QIB_E_P_RIBFLOW | QIB_E_P_REBP)
1070 * Error bits that are Send-related (per port)
1071 * (ARMLAUNCH excluded from E_SPKTERRS because it gets special handling).
1072 * All of these potentially need to have a buffer disarmed
1074 #define QIB_E_P_SPKTERRS (\
1075 QIB_E_P_SUNEXP_PKTNUM |\
1076 QIB_E_P_SDROP_DATA | QIB_E_P_SDROP_SMP |\
1077 QIB_E_P_SMAXPKTLEN |\
1078 QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SHDR | \
1079 QIB_E_P_SMINPKTLEN | QIB_E_P_SPKTLEN | \
1080 QIB_E_P_SND_BUF_MISUSE | QIB_E_P_SUNSUPVL)
1082 #define QIB_E_SPKTERRS ( \
1083 QIB_E_SBUF_VL15_MISUSE | QIB_E_VLMISMATCH | \
1084 ERR_MASK_N(SendUnsupportedVLErr) | \
1085 QIB_E_SPCLTRIG | QIB_E_SDMA_VL15 | QIB_E_SDMA_WRONG_PORT)
1087 #define QIB_E_P_SDMAERRS ( \
1088 QIB_E_P_SDMAHALT | \
1089 QIB_E_P_SDMADESCADDRMISALIGN | \
1090 QIB_E_P_SDMAUNEXPDATA | \
1091 QIB_E_P_SDMAMISSINGDW | \
1092 QIB_E_P_SDMADWEN | \
1093 QIB_E_P_SDMARPYTAG | \
1094 QIB_E_P_SDMA1STDESC | \
1095 QIB_E_P_SDMABASE | \
1096 QIB_E_P_SDMATAILOUTOFBOUND | \
1097 QIB_E_P_SDMAOUTOFBOUND | \
1098 QIB_E_P_SDMAGENMISMATCH)
1101 * This sets some bits more than once, but makes it more obvious which
1102 * bits are not handled under other categories, and the repeat definition
1105 #define QIB_E_P_BITSEXTANT ( \
1106 QIB_E_P_SPKTERRS | QIB_E_P_PKTERRS | QIB_E_P_RPKTERRS | \
1107 QIB_E_P_RIBLOSTLINK | QIB_E_P_IBSTATUSCHANGED | \
1108 QIB_E_P_SND_BUF_MISUSE | QIB_E_P_SUNDERRUN | \
1109 QIB_E_P_SHDR | QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SDMAERRS \
1113 * These are errors that can occur when the link
1114 * changes state while a packet is being sent or received. This doesn't
1115 * cover things like EBP or VCRC that can be the result of a sending
1116 * having the link change state, so we receive a "known bad" packet.
1117 * All of these are "per port", so renamed:
1119 #define QIB_E_P_LINK_PKTERRS (\
1120 QIB_E_P_SDROP_DATA | QIB_E_P_SDROP_SMP |\
1121 QIB_E_P_SMINPKTLEN | QIB_E_P_SPKTLEN |\
1122 QIB_E_P_RSHORTPKTLEN | QIB_E_P_RMINPKTLEN |\
1126 * This sets some bits more than once, but makes it more obvious which
1127 * bits are not handled under other categories (such as QIB_E_SPKTERRS),
1128 * and the repeat definition is not a problem.
1130 #define QIB_E_C_BITSEXTANT (\
1131 QIB_E_HARDWARE | QIB_E_INVALIDADDR | QIB_E_BADEEP |\
1132 QIB_E_ARMLAUNCH | QIB_E_VLMISMATCH | QIB_E_RRCVHDRFULL |\
1133 QIB_E_RRCVEGRFULL | QIB_E_RESET | QIB_E_SBUF_VL15_MISUSE)
1135 /* Likewise Neuter E_SPKT_ERRS_IGNORE */
1136 #define E_SPKT_ERRS_IGNORE 0
1138 #define QIB_EXTS_MEMBIST_DISABLED \
1139 SYM_MASK(EXTStatus, MemBISTDisabled)
1140 #define QIB_EXTS_MEMBIST_ENDTEST \
1141 SYM_MASK(EXTStatus, MemBISTEndTest)
1143 #define QIB_E_SPIOARMLAUNCH \
1144 ERR_MASK(SendArmLaunchErr)
1146 #define IBA7322_IBCC_LINKINITCMD_MASK SYM_RMASK(IBCCtrlA_0, LinkInitCmd)
1147 #define IBA7322_IBCC_LINKCMD_SHIFT SYM_LSB(IBCCtrlA_0, LinkCmd)
1150 * IBTA_1_2 is set when multiple speeds are enabled (normal),
1151 * and also if forced QDR (only QDR enabled). It's enabled for the
1152 * forced QDR case so that scrambling will be enabled by the TS3
1153 * exchange, when supported by both sides of the link.
1155 #define IBA7322_IBC_IBTA_1_2_MASK SYM_MASK(IBCCtrlB_0, IB_ENHANCED_MODE)
1156 #define IBA7322_IBC_MAX_SPEED_MASK SYM_MASK(IBCCtrlB_0, SD_SPEED)
1157 #define IBA7322_IBC_SPEED_QDR SYM_MASK(IBCCtrlB_0, SD_SPEED_QDR)
1158 #define IBA7322_IBC_SPEED_DDR SYM_MASK(IBCCtrlB_0, SD_SPEED_DDR)
1159 #define IBA7322_IBC_SPEED_SDR SYM_MASK(IBCCtrlB_0, SD_SPEED_SDR)
1160 #define IBA7322_IBC_SPEED_MASK (SYM_MASK(IBCCtrlB_0, SD_SPEED_SDR) | \
1161 SYM_MASK(IBCCtrlB_0, SD_SPEED_DDR) | SYM_MASK(IBCCtrlB_0, SD_SPEED_QDR))
1162 #define IBA7322_IBC_SPEED_LSB SYM_LSB(IBCCtrlB_0, SD_SPEED_SDR)
1164 #define IBA7322_LEDBLINK_OFF_SHIFT SYM_LSB(RcvPktLEDCnt_0, OFFperiod)
1165 #define IBA7322_LEDBLINK_ON_SHIFT SYM_LSB(RcvPktLEDCnt_0, ONperiod)
1167 #define IBA7322_IBC_WIDTH_AUTONEG SYM_MASK(IBCCtrlB_0, IB_NUM_CHANNELS)
1168 #define IBA7322_IBC_WIDTH_4X_ONLY (1<<SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS))
1169 #define IBA7322_IBC_WIDTH_1X_ONLY (0<<SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS))
1171 #define IBA7322_IBC_RXPOL_MASK SYM_MASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP)
1172 #define IBA7322_IBC_RXPOL_LSB SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP)
1173 #define IBA7322_IBC_HRTBT_MASK (SYM_MASK(IBCCtrlB_0, HRTBT_AUTO) | \
1174 SYM_MASK(IBCCtrlB_0, HRTBT_ENB))
1175 #define IBA7322_IBC_HRTBT_RMASK (IBA7322_IBC_HRTBT_MASK >> \
1176 SYM_LSB(IBCCtrlB_0, HRTBT_ENB))
1177 #define IBA7322_IBC_HRTBT_LSB SYM_LSB(IBCCtrlB_0, HRTBT_ENB)
1179 #define IBA7322_REDIRECT_VEC_PER_REG 12
1181 #define IBA7322_SENDCHK_PKEY SYM_MASK(SendCheckControl_0, PKey_En)
1182 #define IBA7322_SENDCHK_BTHQP SYM_MASK(SendCheckControl_0, BTHQP_En)
1183 #define IBA7322_SENDCHK_SLID SYM_MASK(SendCheckControl_0, SLID_En)
1184 #define IBA7322_SENDCHK_RAW_IPV6 SYM_MASK(SendCheckControl_0, RawIPV6_En)
1185 #define IBA7322_SENDCHK_MINSZ SYM_MASK(SendCheckControl_0, PacketTooSmall_En)
1187 #define AUTONEG_TRIES 3 /* sequential retries to negotiate DDR */
1189 #define HWE_AUTO(fldname) { .mask = SYM_MASK(HwErrMask, fldname##Mask), \
1190 .msg = #fldname , .sz = sizeof(#fldname) }
1191 #define HWE_AUTO_P(fldname, port) { .mask = SYM_MASK(HwErrMask, \
1192 fldname##Mask##_##port), .msg = #fldname , .sz = sizeof(#fldname) }
1193 static const struct qib_hwerror_msgs qib_7322_hwerror_msgs[] = {
1194 HWE_AUTO_P(IBSerdesPClkNotDetect, 1),
1195 HWE_AUTO_P(IBSerdesPClkNotDetect, 0),
1196 HWE_AUTO(PCIESerdesPClkNotDetect),
1197 HWE_AUTO(PowerOnBISTFailed),
1198 HWE_AUTO(TempsenseTholdReached),
1199 HWE_AUTO(MemoryErr),
1200 HWE_AUTO(PCIeBusParityErr),
1201 HWE_AUTO(PcieCplTimeout),
1202 HWE_AUTO(PciePoisonedTLP),
1203 HWE_AUTO_P(SDmaMemReadErr, 1),
1204 HWE_AUTO_P(SDmaMemReadErr, 0),
1205 HWE_AUTO_P(IBCBusFromSPCParityErr, 1),
1206 HWE_AUTO_P(IBCBusToSPCParityErr, 1),
1207 HWE_AUTO_P(IBCBusFromSPCParityErr, 0),
1208 HWE_AUTO(statusValidNoEop),
1209 HWE_AUTO(LATriggered),
1210 { .mask = 0, .sz = 0 }
1213 #define E_AUTO(fldname) { .mask = SYM_MASK(ErrMask, fldname##Mask), \
1214 .msg = #fldname, .sz = sizeof(#fldname) }
1215 #define E_P_AUTO(fldname) { .mask = SYM_MASK(ErrMask_0, fldname##Mask), \
1216 .msg = #fldname, .sz = sizeof(#fldname) }
1217 static const struct qib_hwerror_msgs qib_7322error_msgs[] = {
1218 E_AUTO(RcvEgrFullErr),
1219 E_AUTO(RcvHdrFullErr),
1220 E_AUTO(ResetNegated),
1221 E_AUTO(HardwareErr),
1222 E_AUTO(InvalidAddrErr),
1223 E_AUTO(SDmaVL15Err),
1224 E_AUTO(SBufVL15MisUseErr),
1225 E_AUTO(InvalidEEPCmd),
1226 E_AUTO(RcvContextShareErr),
1227 E_AUTO(SendVLMismatchErr),
1228 E_AUTO(SendArmLaunchErr),
1229 E_AUTO(SendSpecialTriggerErr),
1230 E_AUTO(SDmaWrongPortErr),
1231 E_AUTO(SDmaBufMaskDuplicateErr),
1232 { .mask = 0, .sz = 0 }
1235 static const struct qib_hwerror_msgs qib_7322p_error_msgs[] = {
1236 E_P_AUTO(IBStatusChanged),
1237 E_P_AUTO(SHeadersErr),
1238 E_P_AUTO(VL15BufMisuseErr),
1240 * SDmaHaltErr is not really an error, make it clearer;
1242 {.mask = SYM_MASK(ErrMask_0, SDmaHaltErrMask), .msg = "SDmaHalted",
1244 E_P_AUTO(SDmaDescAddrMisalignErr),
1245 E_P_AUTO(SDmaUnexpDataErr),
1246 E_P_AUTO(SDmaMissingDwErr),
1247 E_P_AUTO(SDmaDwEnErr),
1248 E_P_AUTO(SDmaRpyTagErr),
1249 E_P_AUTO(SDma1stDescErr),
1250 E_P_AUTO(SDmaBaseErr),
1251 E_P_AUTO(SDmaTailOutOfBoundErr),
1252 E_P_AUTO(SDmaOutOfBoundErr),
1253 E_P_AUTO(SDmaGenMismatchErr),
1254 E_P_AUTO(SendBufMisuseErr),
1255 E_P_AUTO(SendUnsupportedVLErr),
1256 E_P_AUTO(SendUnexpectedPktNumErr),
1257 E_P_AUTO(SendDroppedDataPktErr),
1258 E_P_AUTO(SendDroppedSmpPktErr),
1259 E_P_AUTO(SendPktLenErr),
1260 E_P_AUTO(SendUnderRunErr),
1261 E_P_AUTO(SendMaxPktLenErr),
1262 E_P_AUTO(SendMinPktLenErr),
1263 E_P_AUTO(RcvIBLostLinkErr),
1264 E_P_AUTO(RcvHdrErr),
1265 E_P_AUTO(RcvHdrLenErr),
1266 E_P_AUTO(RcvBadTidErr),
1267 E_P_AUTO(RcvBadVersionErr),
1268 E_P_AUTO(RcvIBFlowErr),
1269 E_P_AUTO(RcvEBPErr),
1270 E_P_AUTO(RcvUnsupportedVLErr),
1271 E_P_AUTO(RcvUnexpectedCharErr),
1272 E_P_AUTO(RcvShortPktLenErr),
1273 E_P_AUTO(RcvLongPktLenErr),
1274 E_P_AUTO(RcvMaxPktLenErr),
1275 E_P_AUTO(RcvMinPktLenErr),
1276 E_P_AUTO(RcvICRCErr),
1277 E_P_AUTO(RcvVCRCErr),
1278 E_P_AUTO(RcvFormatErr),
1279 { .mask = 0, .sz = 0 }
1283 * Below generates "auto-message" for interrupts not specific to any port or
1286 #define INTR_AUTO(fldname) { .mask = SYM_MASK(IntMask, fldname##Mask), \
1287 .msg = #fldname, .sz = sizeof(#fldname) }
1288 /* Below generates "auto-message" for interrupts specific to a port */
1289 #define INTR_AUTO_P(fldname) { .mask = MASK_ACROSS(\
1290 SYM_LSB(IntMask, fldname##Mask##_0), \
1291 SYM_LSB(IntMask, fldname##Mask##_1)), \
1292 .msg = #fldname "_P", .sz = sizeof(#fldname "_P") }
1293 /* For some reason, the SerDesTrimDone bits are reversed */
1294 #define INTR_AUTO_PI(fldname) { .mask = MASK_ACROSS(\
1295 SYM_LSB(IntMask, fldname##Mask##_1), \
1296 SYM_LSB(IntMask, fldname##Mask##_0)), \
1297 .msg = #fldname "_P", .sz = sizeof(#fldname "_P") }
1299 * Below generates "auto-message" for interrupts specific to a context,
1300 * with ctxt-number appended
1302 #define INTR_AUTO_C(fldname) { .mask = MASK_ACROSS(\
1303 SYM_LSB(IntMask, fldname##0IntMask), \
1304 SYM_LSB(IntMask, fldname##17IntMask)), \
1305 .msg = #fldname "_C", .sz = sizeof(#fldname "_C") }
1307 static const struct qib_hwerror_msgs qib_7322_intr_msgs[] = {
1308 INTR_AUTO_P(SDmaInt),
1309 INTR_AUTO_P(SDmaProgressInt),
1310 INTR_AUTO_P(SDmaIdleInt),
1311 INTR_AUTO_P(SDmaCleanupDone),
1312 INTR_AUTO_C(RcvUrg),
1313 INTR_AUTO_P(ErrInt),
1314 INTR_AUTO(ErrInt), /* non-port-specific errs */
1315 INTR_AUTO(AssertGPIOInt),
1316 INTR_AUTO_P(SendDoneInt),
1317 INTR_AUTO(SendBufAvailInt),
1318 INTR_AUTO_C(RcvAvail),
1319 { .mask = 0, .sz = 0 }
1322 #define TXSYMPTOM_AUTO_P(fldname) \
1323 { .mask = SYM_MASK(SendHdrErrSymptom_0, fldname), \
1324 .msg = #fldname, .sz = sizeof(#fldname) }
1325 static const struct qib_hwerror_msgs hdrchk_msgs[] = {
1326 TXSYMPTOM_AUTO_P(NonKeyPacket),
1327 TXSYMPTOM_AUTO_P(GRHFail),
1328 TXSYMPTOM_AUTO_P(PkeyFail),
1329 TXSYMPTOM_AUTO_P(QPFail),
1330 TXSYMPTOM_AUTO_P(SLIDFail),
1331 TXSYMPTOM_AUTO_P(RawIPV6),
1332 TXSYMPTOM_AUTO_P(PacketTooSmall),
1333 { .mask = 0, .sz = 0 }
1336 #define IBA7322_HDRHEAD_PKTINT_SHIFT 32 /* interrupt cnt in upper 32 bits */
1339 * Called when we might have an error that is specific to a particular
1340 * PIO buffer, and may need to cancel that buffer, so it can be re-used,
1341 * because we don't need to force the update of pioavail
1343 static void qib_disarm_7322_senderrbufs(struct qib_pportdata *ppd)
1345 struct qib_devdata *dd = ppd->dd;
1348 u32 piobcnt = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
1349 u32 regcnt = (piobcnt + BITS_PER_LONG - 1) / BITS_PER_LONG;
1350 unsigned long sbuf[4];
1353 * It's possible that sendbuffererror could have bits set; might
1354 * have already done this as a result of hardware error handling.
1357 for (i = 0; i < regcnt; ++i) {
1358 sbuf[i] = qib_read_kreg64(dd, kr_sendbuffererror + i);
1361 qib_write_kreg(dd, kr_sendbuffererror + i, sbuf[i]);
1366 qib_disarm_piobufs_set(dd, sbuf, piobcnt);
1369 /* No txe_recover yet, if ever */
1371 /* No decode__errors yet */
1372 static void err_decode(char *msg, size_t len, u64 errs,
1373 const struct qib_hwerror_msgs *msp)
1376 int took, multi, n = 0;
1378 while (errs && msp && msp->mask) {
1379 multi = (msp->mask & (msp->mask - 1));
1380 while (errs & msp->mask) {
1381 these = (errs & msp->mask);
1382 lmask = (these & (these - 1)) ^ these;
1385 /* separate the strings */
1390 /* msp->sz counts the nul */
1391 took = min_t(size_t, msp->sz - (size_t)1, len);
1392 memcpy(msg, msp->msg, took);
1400 /* More than one bit this mask */
1403 while (lmask & msp->mask) {
1407 took = scnprintf(msg, len, "_%d", idx);
1414 /* If some bits are left, show in hex. */
1416 snprintf(msg, len, "%sMORE:%llX", n ? "," : "",
1417 (unsigned long long) errs);
1420 /* only called if r1 set */
1421 static void flush_fifo(struct qib_pportdata *ppd)
1423 struct qib_devdata *dd = ppd->dd;
1424 u32 __iomem *piobuf;
1428 const unsigned hdrwords = 7;
1429 static struct qib_ib_header ibhdr = {
1430 .lrh[0] = cpu_to_be16(0xF000 | QIB_LRH_BTH),
1431 .lrh[1] = IB_LID_PERMISSIVE,
1432 .lrh[2] = cpu_to_be16(hdrwords + SIZE_OF_CRC),
1433 .lrh[3] = IB_LID_PERMISSIVE,
1434 .u.oth.bth[0] = cpu_to_be32(
1435 (IB_OPCODE_UD_SEND_ONLY << 24) | QIB_DEFAULT_P_KEY),
1436 .u.oth.bth[1] = cpu_to_be32(0),
1437 .u.oth.bth[2] = cpu_to_be32(0),
1438 .u.oth.u.ud.deth[0] = cpu_to_be32(0),
1439 .u.oth.u.ud.deth[1] = cpu_to_be32(0),
1443 * Send a dummy VL15 packet to flush the launch FIFO.
1444 * This will not actually be sent since the TxeBypassIbc bit is set.
1446 pbc = PBC_7322_VL15_SEND |
1447 (((u64)ppd->hw_pidx) << (PBC_PORT_SEL_LSB + 32)) |
1448 (hdrwords + SIZE_OF_CRC);
1449 piobuf = qib_7322_getsendbuf(ppd, pbc, &bufn);
1452 writeq(pbc, piobuf);
1453 hdr = (u32 *) &ibhdr;
1454 if (dd->flags & QIB_PIO_FLUSH_WC) {
1456 qib_pio_copy(piobuf + 2, hdr, hdrwords - 1);
1458 __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords + 1);
1461 qib_pio_copy(piobuf + 2, hdr, hdrwords);
1462 qib_sendbuf_done(dd, bufn);
1466 * This is called with interrupts disabled and sdma_lock held.
1468 static void qib_7322_sdma_sendctrl(struct qib_pportdata *ppd, unsigned op)
1470 struct qib_devdata *dd = ppd->dd;
1471 u64 set_sendctrl = 0;
1472 u64 clr_sendctrl = 0;
1474 if (op & QIB_SDMA_SENDCTRL_OP_ENABLE)
1475 set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaEnable);
1477 clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaEnable);
1479 if (op & QIB_SDMA_SENDCTRL_OP_INTENABLE)
1480 set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaIntEnable);
1482 clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaIntEnable);
1484 if (op & QIB_SDMA_SENDCTRL_OP_HALT)
1485 set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaHalt);
1487 clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaHalt);
1489 if (op & QIB_SDMA_SENDCTRL_OP_DRAIN)
1490 set_sendctrl |= SYM_MASK(SendCtrl_0, TxeBypassIbc) |
1491 SYM_MASK(SendCtrl_0, TxeAbortIbc) |
1492 SYM_MASK(SendCtrl_0, TxeDrainRmFifo);
1494 clr_sendctrl |= SYM_MASK(SendCtrl_0, TxeBypassIbc) |
1495 SYM_MASK(SendCtrl_0, TxeAbortIbc) |
1496 SYM_MASK(SendCtrl_0, TxeDrainRmFifo);
1498 spin_lock(&dd->sendctrl_lock);
1500 /* If we are draining everything, block sends first */
1501 if (op & QIB_SDMA_SENDCTRL_OP_DRAIN) {
1502 ppd->p_sendctrl &= ~SYM_MASK(SendCtrl_0, SendEnable);
1503 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
1504 qib_write_kreg(dd, kr_scratch, 0);
1507 ppd->p_sendctrl |= set_sendctrl;
1508 ppd->p_sendctrl &= ~clr_sendctrl;
1510 if (op & QIB_SDMA_SENDCTRL_OP_CLEANUP)
1511 qib_write_kreg_port(ppd, krp_sendctrl,
1513 SYM_MASK(SendCtrl_0, SDmaCleanup));
1515 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
1516 qib_write_kreg(dd, kr_scratch, 0);
1518 if (op & QIB_SDMA_SENDCTRL_OP_DRAIN) {
1519 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, SendEnable);
1520 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
1521 qib_write_kreg(dd, kr_scratch, 0);
1524 spin_unlock(&dd->sendctrl_lock);
1526 if ((op & QIB_SDMA_SENDCTRL_OP_DRAIN) && ppd->dd->cspec->r1)
1530 static void qib_7322_sdma_hw_clean_up(struct qib_pportdata *ppd)
1532 __qib_sdma_process_event(ppd, qib_sdma_event_e50_hw_cleaned);
1535 static void qib_sdma_7322_setlengen(struct qib_pportdata *ppd)
1538 * Set SendDmaLenGen and clear and set
1539 * the MSB of the generation count to enable generation checking
1540 * and load the internal generation counter.
1542 qib_write_kreg_port(ppd, krp_senddmalengen, ppd->sdma_descq_cnt);
1543 qib_write_kreg_port(ppd, krp_senddmalengen,
1544 ppd->sdma_descq_cnt |
1545 (1ULL << QIB_7322_SendDmaLenGen_0_Generation_MSB));
1549 * Must be called with sdma_lock held, or before init finished.
1551 static void qib_sdma_update_7322_tail(struct qib_pportdata *ppd, u16 tail)
1553 /* Commit writes to memory and advance the tail on the chip */
1555 ppd->sdma_descq_tail = tail;
1556 qib_write_kreg_port(ppd, krp_senddmatail, tail);
1560 * This is called with interrupts disabled and sdma_lock held.
1562 static void qib_7322_sdma_hw_start_up(struct qib_pportdata *ppd)
1566 * The hardware doesn't require this but we do it so that verbs
1567 * and user applications don't wait for link active to send stale
1570 sendctrl_7322_mod(ppd, QIB_SENDCTRL_FLUSH);
1572 qib_sdma_7322_setlengen(ppd);
1573 qib_sdma_update_7322_tail(ppd, 0); /* Set SendDmaTail */
1574 ppd->sdma_head_dma[0] = 0;
1575 qib_7322_sdma_sendctrl(ppd,
1576 ppd->sdma_state.current_op | QIB_SDMA_SENDCTRL_OP_CLEANUP);
1579 #define DISABLES_SDMA ( \
1580 QIB_E_P_SDMAHALT | \
1581 QIB_E_P_SDMADESCADDRMISALIGN | \
1582 QIB_E_P_SDMAMISSINGDW | \
1583 QIB_E_P_SDMADWEN | \
1584 QIB_E_P_SDMARPYTAG | \
1585 QIB_E_P_SDMA1STDESC | \
1586 QIB_E_P_SDMABASE | \
1587 QIB_E_P_SDMATAILOUTOFBOUND | \
1588 QIB_E_P_SDMAOUTOFBOUND | \
1589 QIB_E_P_SDMAGENMISMATCH)
1591 static void sdma_7322_p_errors(struct qib_pportdata *ppd, u64 errs)
1593 unsigned long flags;
1594 struct qib_devdata *dd = ppd->dd;
1596 errs &= QIB_E_P_SDMAERRS;
1598 if (errs & QIB_E_P_SDMAUNEXPDATA)
1599 qib_dev_err(dd, "IB%u:%u SDmaUnexpData\n", dd->unit,
1602 spin_lock_irqsave(&ppd->sdma_lock, flags);
1604 switch (ppd->sdma_state.current_state) {
1605 case qib_sdma_state_s00_hw_down:
1608 case qib_sdma_state_s10_hw_start_up_wait:
1609 if (errs & QIB_E_P_SDMAHALT)
1610 __qib_sdma_process_event(ppd,
1611 qib_sdma_event_e20_hw_started);
1614 case qib_sdma_state_s20_idle:
1617 case qib_sdma_state_s30_sw_clean_up_wait:
1620 case qib_sdma_state_s40_hw_clean_up_wait:
1621 if (errs & QIB_E_P_SDMAHALT)
1622 __qib_sdma_process_event(ppd,
1623 qib_sdma_event_e50_hw_cleaned);
1626 case qib_sdma_state_s50_hw_halt_wait:
1627 if (errs & QIB_E_P_SDMAHALT)
1628 __qib_sdma_process_event(ppd,
1629 qib_sdma_event_e60_hw_halted);
1632 case qib_sdma_state_s99_running:
1633 __qib_sdma_process_event(ppd, qib_sdma_event_e7322_err_halted);
1634 __qib_sdma_process_event(ppd, qib_sdma_event_e60_hw_halted);
1638 spin_unlock_irqrestore(&ppd->sdma_lock, flags);
1642 * handle per-device errors (not per-port errors)
1644 static noinline void handle_7322_errors(struct qib_devdata *dd)
1652 qib_stats.sps_errints++;
1653 errs = qib_read_kreg64(dd, kr_errstatus);
1655 qib_devinfo(dd->pcidev,
1656 "device error interrupt, but no error bits set!\n");
1660 /* don't report errors that are masked */
1661 errs &= dd->cspec->errormask;
1662 msg = dd->cspec->emsgbuf;
1664 /* do these first, they are most important */
1665 if (errs & QIB_E_HARDWARE) {
1667 qib_7322_handle_hwerrors(dd, msg, sizeof dd->cspec->emsgbuf);
1669 for (log_idx = 0; log_idx < QIB_EEP_LOG_CNT; ++log_idx)
1670 if (errs & dd->eep_st_masks[log_idx].errs_to_log)
1671 qib_inc_eeprom_err(dd, log_idx, 1);
1673 if (errs & QIB_E_SPKTERRS) {
1674 qib_disarm_7322_senderrbufs(dd->pport);
1675 qib_stats.sps_txerrs++;
1676 } else if (errs & QIB_E_INVALIDADDR)
1677 qib_stats.sps_txerrs++;
1678 else if (errs & QIB_E_ARMLAUNCH) {
1679 qib_stats.sps_txerrs++;
1680 qib_disarm_7322_senderrbufs(dd->pport);
1682 qib_write_kreg(dd, kr_errclear, errs);
1685 * The ones we mask off are handled specially below
1686 * or above. Also mask SDMADISABLED by default as it
1689 mask = QIB_E_HARDWARE;
1692 err_decode(msg, sizeof dd->cspec->emsgbuf, errs & ~mask,
1693 qib_7322error_msgs);
1696 * Getting reset is a tragedy for all ports. Mark the device
1697 * _and_ the ports as "offline" in way meaningful to each.
1699 if (errs & QIB_E_RESET) {
1703 "Got reset, requires re-init (unload and reload driver)\n");
1704 dd->flags &= ~QIB_INITTED; /* needs re-init */
1705 /* mark as having had error */
1706 *dd->devstatusp |= QIB_STATUS_HWERROR;
1707 for (pidx = 0; pidx < dd->num_pports; ++pidx)
1708 if (dd->pport[pidx].link_speed_supported)
1709 *dd->pport[pidx].statusp &= ~QIB_STATUS_IB_CONF;
1713 qib_dev_err(dd, "%s error\n", msg);
1716 * If there were hdrq or egrfull errors, wake up any processes
1717 * waiting in poll. We used to try to check which contexts had
1718 * the overflow, but given the cost of that and the chip reads
1719 * to support it, it's better to just wake everybody up if we
1720 * get an overflow; waiters can poll again if it's not them.
1722 if (errs & (ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr))) {
1723 qib_handle_urcv(dd, ~0U);
1724 if (errs & ERR_MASK(RcvEgrFullErr))
1725 qib_stats.sps_buffull++;
1727 qib_stats.sps_hdrfull++;
1734 static void qib_error_tasklet(unsigned long data)
1736 struct qib_devdata *dd = (struct qib_devdata *)data;
1738 handle_7322_errors(dd);
1739 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
1742 static void reenable_chase(unsigned long opaque)
1744 struct qib_pportdata *ppd = (struct qib_pportdata *)opaque;
1746 ppd->cpspec->chase_timer.expires = 0;
1747 qib_set_ib_7322_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
1748 QLOGIC_IB_IBCC_LINKINITCMD_POLL);
1751 static void disable_chase(struct qib_pportdata *ppd, unsigned long tnow,
1754 ppd->cpspec->chase_end = 0;
1759 qib_set_ib_7322_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
1760 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
1761 ppd->cpspec->chase_timer.expires = jiffies + QIB_CHASE_DIS_TIME;
1762 add_timer(&ppd->cpspec->chase_timer);
1765 static void handle_serdes_issues(struct qib_pportdata *ppd, u64 ibcst)
1770 ibclt = (u8)SYM_FIELD(ibcst, IBCStatusA_0, LinkTrainingState);
1773 * Detect and handle the state chase issue, where we can
1774 * get stuck if we are unlucky on timing on both sides of
1775 * the link. If we are, we disable, set a timer, and
1779 case IB_7322_LT_STATE_CFGRCVFCFG:
1780 case IB_7322_LT_STATE_CFGWAITRMT:
1781 case IB_7322_LT_STATE_TXREVLANES:
1782 case IB_7322_LT_STATE_CFGENH:
1784 if (ppd->cpspec->chase_end &&
1785 time_after(tnow, ppd->cpspec->chase_end))
1786 disable_chase(ppd, tnow, ibclt);
1787 else if (!ppd->cpspec->chase_end)
1788 ppd->cpspec->chase_end = tnow + QIB_CHASE_TIME;
1791 ppd->cpspec->chase_end = 0;
1795 if (((ibclt >= IB_7322_LT_STATE_CFGTEST &&
1796 ibclt <= IB_7322_LT_STATE_CFGWAITENH) ||
1797 ibclt == IB_7322_LT_STATE_LINKUP) &&
1798 (ibcst & SYM_MASK(IBCStatusA_0, LinkSpeedQDR))) {
1800 ppd->cpspec->qdr_reforce = 1;
1801 if (!ppd->dd->cspec->r1)
1802 serdes_7322_los_enable(ppd, 0);
1803 } else if (ppd->cpspec->qdr_reforce &&
1804 (ibcst & SYM_MASK(IBCStatusA_0, LinkSpeedQDR)) &&
1805 (ibclt == IB_7322_LT_STATE_CFGENH ||
1806 ibclt == IB_7322_LT_STATE_CFGIDLE ||
1807 ibclt == IB_7322_LT_STATE_LINKUP))
1810 if ((IS_QMH(ppd->dd) || IS_QME(ppd->dd)) &&
1811 ppd->link_speed_enabled == QIB_IB_QDR &&
1812 (ibclt == IB_7322_LT_STATE_CFGTEST ||
1813 ibclt == IB_7322_LT_STATE_CFGENH ||
1814 (ibclt >= IB_7322_LT_STATE_POLLACTIVE &&
1815 ibclt <= IB_7322_LT_STATE_SLEEPQUIET)))
1818 if (ibclt != IB_7322_LT_STATE_LINKUP) {
1819 u8 ltstate = qib_7322_phys_portstate(ibcst);
1820 u8 pibclt = (u8)SYM_FIELD(ppd->lastibcstat, IBCStatusA_0,
1822 if (!ppd->dd->cspec->r1 &&
1823 pibclt == IB_7322_LT_STATE_LINKUP &&
1824 ltstate != IB_PHYSPORTSTATE_LINK_ERR_RECOVER &&
1825 ltstate != IB_PHYSPORTSTATE_RECOVERY_RETRAIN &&
1826 ltstate != IB_PHYSPORTSTATE_RECOVERY_WAITRMT &&
1827 ltstate != IB_PHYSPORTSTATE_RECOVERY_IDLE)
1828 /* If the link went down (but no into recovery,
1829 * turn LOS back on */
1830 serdes_7322_los_enable(ppd, 1);
1831 if (!ppd->cpspec->qdr_dfe_on &&
1832 ibclt <= IB_7322_LT_STATE_SLEEPQUIET) {
1833 ppd->cpspec->qdr_dfe_on = 1;
1834 ppd->cpspec->qdr_dfe_time = 0;
1835 /* On link down, reenable QDR adaptation */
1836 qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
1837 ppd->dd->cspec->r1 ?
1838 QDR_STATIC_ADAPT_DOWN_R1 :
1839 QDR_STATIC_ADAPT_DOWN);
1841 "IB%u:%u re-enabled QDR adaptation ibclt %x\n",
1842 ppd->dd->unit, ppd->port, ibclt);
1847 static int qib_7322_set_ib_cfg(struct qib_pportdata *, int, u32);
1850 * This is per-pport error handling.
1851 * will likely get it's own MSIx interrupt (one for each port,
1852 * although just a single handler).
1854 static noinline void handle_7322_p_errors(struct qib_pportdata *ppd)
1857 u64 ignore_this_time = 0, iserr = 0, errs, fmask;
1858 struct qib_devdata *dd = ppd->dd;
1860 /* do this as soon as possible */
1861 fmask = qib_read_kreg64(dd, kr_act_fmask);
1863 check_7322_rxe_status(ppd);
1865 errs = qib_read_kreg_port(ppd, krp_errstatus);
1867 qib_devinfo(dd->pcidev,
1868 "Port%d error interrupt, but no error bits set!\n",
1871 errs &= ~QIB_E_P_IBSTATUSCHANGED;
1875 msg = ppd->cpspec->epmsgbuf;
1878 if (errs & ~QIB_E_P_BITSEXTANT) {
1879 err_decode(msg, sizeof ppd->cpspec->epmsgbuf,
1880 errs & ~QIB_E_P_BITSEXTANT, qib_7322p_error_msgs);
1882 snprintf(msg, sizeof ppd->cpspec->epmsgbuf,
1884 qib_dev_porterr(dd, ppd->port,
1885 "error interrupt with unknown errors 0x%016Lx set (and %s)\n",
1886 (errs & ~QIB_E_P_BITSEXTANT), msg);
1890 if (errs & QIB_E_P_SHDR) {
1893 /* determine cause, then write to clear */
1894 symptom = qib_read_kreg_port(ppd, krp_sendhdrsymptom);
1895 qib_write_kreg_port(ppd, krp_sendhdrsymptom, 0);
1896 err_decode(msg, sizeof ppd->cpspec->epmsgbuf, symptom,
1899 /* senderrbuf cleared in SPKTERRS below */
1902 if (errs & QIB_E_P_SPKTERRS) {
1903 if ((errs & QIB_E_P_LINK_PKTERRS) &&
1904 !(ppd->lflags & QIBL_LINKACTIVE)) {
1906 * This can happen when trying to bring the link
1907 * up, but the IB link changes state at the "wrong"
1908 * time. The IB logic then complains that the packet
1909 * isn't valid. We don't want to confuse people, so
1910 * we just don't print them, except at debug
1912 err_decode(msg, sizeof ppd->cpspec->epmsgbuf,
1913 (errs & QIB_E_P_LINK_PKTERRS),
1914 qib_7322p_error_msgs);
1916 ignore_this_time = errs & QIB_E_P_LINK_PKTERRS;
1918 qib_disarm_7322_senderrbufs(ppd);
1919 } else if ((errs & QIB_E_P_LINK_PKTERRS) &&
1920 !(ppd->lflags & QIBL_LINKACTIVE)) {
1922 * This can happen when SMA is trying to bring the link
1923 * up, but the IB link changes state at the "wrong" time.
1924 * The IB logic then complains that the packet isn't
1925 * valid. We don't want to confuse people, so we just
1926 * don't print them, except at debug
1928 err_decode(msg, sizeof ppd->cpspec->epmsgbuf, errs,
1929 qib_7322p_error_msgs);
1930 ignore_this_time = errs & QIB_E_P_LINK_PKTERRS;
1934 qib_write_kreg_port(ppd, krp_errclear, errs);
1936 errs &= ~ignore_this_time;
1940 if (errs & QIB_E_P_RPKTERRS)
1941 qib_stats.sps_rcverrs++;
1942 if (errs & QIB_E_P_SPKTERRS)
1943 qib_stats.sps_txerrs++;
1945 iserr = errs & ~(QIB_E_P_RPKTERRS | QIB_E_P_PKTERRS);
1947 if (errs & QIB_E_P_SDMAERRS)
1948 sdma_7322_p_errors(ppd, errs);
1950 if (errs & QIB_E_P_IBSTATUSCHANGED) {
1954 ibcs = qib_read_kreg_port(ppd, krp_ibcstatus_a);
1955 ltstate = qib_7322_phys_portstate(ibcs);
1957 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
1958 handle_serdes_issues(ppd, ibcs);
1959 if (!(ppd->cpspec->ibcctrl_a &
1960 SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn))) {
1962 * We got our interrupt, so init code should be
1963 * happy and not try alternatives. Now squelch
1964 * other "chatter" from link-negotiation (pre Init)
1966 ppd->cpspec->ibcctrl_a |=
1967 SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
1968 qib_write_kreg_port(ppd, krp_ibcctrl_a,
1969 ppd->cpspec->ibcctrl_a);
1972 /* Update our picture of width and speed from chip */
1973 ppd->link_width_active =
1974 (ibcs & SYM_MASK(IBCStatusA_0, LinkWidthActive)) ?
1975 IB_WIDTH_4X : IB_WIDTH_1X;
1976 ppd->link_speed_active = (ibcs & SYM_MASK(IBCStatusA_0,
1977 LinkSpeedQDR)) ? QIB_IB_QDR : (ibcs &
1978 SYM_MASK(IBCStatusA_0, LinkSpeedActive)) ?
1979 QIB_IB_DDR : QIB_IB_SDR;
1981 if ((ppd->lflags & QIBL_IB_LINK_DISABLED) && ltstate !=
1982 IB_PHYSPORTSTATE_DISABLED)
1983 qib_set_ib_7322_lstate(ppd, 0,
1984 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
1987 * Since going into a recovery state causes the link
1988 * state to go down and since recovery is transitory,
1989 * it is better if we "miss" ever seeing the link
1990 * training state go into recovery (i.e., ignore this
1991 * transition for link state special handling purposes)
1992 * without updating lastibcstat.
1994 if (ltstate != IB_PHYSPORTSTATE_LINK_ERR_RECOVER &&
1995 ltstate != IB_PHYSPORTSTATE_RECOVERY_RETRAIN &&
1996 ltstate != IB_PHYSPORTSTATE_RECOVERY_WAITRMT &&
1997 ltstate != IB_PHYSPORTSTATE_RECOVERY_IDLE)
1998 qib_handle_e_ibstatuschanged(ppd, ibcs);
2001 qib_dev_porterr(dd, ppd->port, "%s error\n", msg);
2003 if (ppd->state_wanted & ppd->lflags)
2004 wake_up_interruptible(&ppd->state_wait);
2009 /* enable/disable chip from delivering interrupts */
2010 static void qib_7322_set_intr_state(struct qib_devdata *dd, u32 enable)
2013 if (dd->flags & QIB_BADINTR)
2015 qib_write_kreg(dd, kr_intmask, dd->cspec->int_enable_mask);
2016 /* cause any pending enabled interrupts to be re-delivered */
2017 qib_write_kreg(dd, kr_intclear, 0ULL);
2018 if (dd->cspec->num_msix_entries) {
2019 /* and same for MSIx */
2020 u64 val = qib_read_kreg64(dd, kr_intgranted);
2022 qib_write_kreg(dd, kr_intgranted, val);
2025 qib_write_kreg(dd, kr_intmask, 0ULL);
2029 * Try to cleanup as much as possible for anything that might have gone
2030 * wrong while in freeze mode, such as pio buffers being written by user
2031 * processes (causing armlaunch), send errors due to going into freeze mode,
2032 * etc., and try to avoid causing extra interrupts while doing so.
2033 * Forcibly update the in-memory pioavail register copies after cleanup
2034 * because the chip won't do it while in freeze mode (the register values
2035 * themselves are kept correct).
2036 * Make sure that we don't lose any important interrupts by using the chip
2037 * feature that says that writing 0 to a bit in *clear that is set in
2038 * *status will cause an interrupt to be generated again (if allowed by
2040 * This is in chip-specific code because of all of the register accesses,
2041 * even though the details are similar on most chips.
2043 static void qib_7322_clear_freeze(struct qib_devdata *dd)
2047 /* disable error interrupts, to avoid confusion */
2048 qib_write_kreg(dd, kr_errmask, 0ULL);
2050 for (pidx = 0; pidx < dd->num_pports; ++pidx)
2051 if (dd->pport[pidx].link_speed_supported)
2052 qib_write_kreg_port(dd->pport + pidx, krp_errmask,
2055 /* also disable interrupts; errormask is sometimes overwriten */
2056 qib_7322_set_intr_state(dd, 0);
2058 /* clear the freeze, and be sure chip saw it */
2059 qib_write_kreg(dd, kr_control, dd->control);
2060 qib_read_kreg32(dd, kr_scratch);
2063 * Force new interrupt if any hwerr, error or interrupt bits are
2064 * still set, and clear "safe" send packet errors related to freeze
2065 * and cancelling sends. Re-enable error interrupts before possible
2066 * force of re-interrupt on pending interrupts.
2068 qib_write_kreg(dd, kr_hwerrclear, 0ULL);
2069 qib_write_kreg(dd, kr_errclear, E_SPKT_ERRS_IGNORE);
2070 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
2071 /* We need to purge per-port errs and reset mask, too */
2072 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
2073 if (!dd->pport[pidx].link_speed_supported)
2075 qib_write_kreg_port(dd->pport + pidx, krp_errclear, ~0Ull);
2076 qib_write_kreg_port(dd->pport + pidx, krp_errmask, ~0Ull);
2078 qib_7322_set_intr_state(dd, 1);
2081 /* no error handling to speak of */
2083 * qib_7322_handle_hwerrors - display hardware errors.
2084 * @dd: the qlogic_ib device
2085 * @msg: the output buffer
2086 * @msgl: the size of the output buffer
2088 * Use same msg buffer as regular errors to avoid excessive stack
2089 * use. Most hardware errors are catastrophic, but for right now,
2090 * we'll print them and continue. We reuse the same message buffer as
2091 * qib_handle_errors() to avoid excessive stack usage.
2093 static void qib_7322_handle_hwerrors(struct qib_devdata *dd, char *msg,
2100 hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
2103 if (hwerrs == ~0ULL) {
2105 "Read of hardware error status failed (all bits set); ignoring\n");
2108 qib_stats.sps_hwerrs++;
2110 /* Always clear the error status register, except BIST fail */
2111 qib_write_kreg(dd, kr_hwerrclear, hwerrs &
2112 ~HWE_MASK(PowerOnBISTFailed));
2114 hwerrs &= dd->cspec->hwerrmask;
2116 /* no EEPROM logging, yet */
2119 qib_devinfo(dd->pcidev,
2120 "Hardware error: hwerr=0x%llx (cleared)\n",
2121 (unsigned long long) hwerrs);
2123 ctrl = qib_read_kreg32(dd, kr_control);
2124 if ((ctrl & SYM_MASK(Control, FreezeMode)) && !dd->diag_client) {
2126 * No recovery yet...
2128 if ((hwerrs & ~HWE_MASK(LATriggered)) ||
2129 dd->cspec->stay_in_freeze) {
2131 * If any set that we aren't ignoring only make the
2132 * complaint once, in case it's stuck or recurring,
2133 * and we get here multiple times
2134 * Force link down, so switch knows, and
2135 * LEDs are turned off.
2137 if (dd->flags & QIB_INITTED)
2140 qib_7322_clear_freeze(dd);
2143 if (hwerrs & HWE_MASK(PowerOnBISTFailed)) {
2146 "[Memory BIST test failed, InfiniPath hardware unusable]",
2148 /* ignore from now on, so disable until driver reloaded */
2149 dd->cspec->hwerrmask &= ~HWE_MASK(PowerOnBISTFailed);
2150 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
2153 err_decode(msg, msgl, hwerrs, qib_7322_hwerror_msgs);
2155 /* Ignore esoteric PLL failures et al. */
2157 qib_dev_err(dd, "%s hardware error\n", msg);
2159 if (isfatal && !dd->diag_client) {
2161 "Fatal Hardware Error, no longer usable, SN %.16s\n",
2164 * for /sys status file and user programs to print; if no
2165 * trailing brace is copied, we'll know it was truncated.
2168 snprintf(dd->freezemsg, dd->freezelen,
2170 qib_disable_after_error(dd);
2176 * qib_7322_init_hwerrors - enable hardware errors
2177 * @dd: the qlogic_ib device
2179 * now that we have finished initializing everything that might reasonably
2180 * cause a hardware error, and cleared those errors bits as they occur,
2181 * we can enable hardware errors in the mask (potentially enabling
2182 * freeze mode), and enable hardware errors as errors (along with
2183 * everything else) in errormask
2185 static void qib_7322_init_hwerrors(struct qib_devdata *dd)
2190 extsval = qib_read_kreg64(dd, kr_extstatus);
2191 if (!(extsval & (QIB_EXTS_MEMBIST_DISABLED |
2192 QIB_EXTS_MEMBIST_ENDTEST)))
2193 qib_dev_err(dd, "MemBIST did not complete!\n");
2195 /* never clear BIST failure, so reported on each driver load */
2196 qib_write_kreg(dd, kr_hwerrclear, ~HWE_MASK(PowerOnBISTFailed));
2197 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
2200 qib_write_kreg(dd, kr_errclear, ~0ULL);
2201 /* enable errors that are masked, at least this first time. */
2202 qib_write_kreg(dd, kr_errmask, ~0ULL);
2203 dd->cspec->errormask = qib_read_kreg64(dd, kr_errmask);
2204 for (pidx = 0; pidx < dd->num_pports; ++pidx)
2205 if (dd->pport[pidx].link_speed_supported)
2206 qib_write_kreg_port(dd->pport + pidx, krp_errmask,
2211 * Disable and enable the armlaunch error. Used for PIO bandwidth testing
2212 * on chips that are count-based, rather than trigger-based. There is no
2213 * reference counting, but that's also fine, given the intended use.
2214 * Only chip-specific because it's all register accesses
2216 static void qib_set_7322_armlaunch(struct qib_devdata *dd, u32 enable)
2219 qib_write_kreg(dd, kr_errclear, QIB_E_SPIOARMLAUNCH);
2220 dd->cspec->errormask |= QIB_E_SPIOARMLAUNCH;
2222 dd->cspec->errormask &= ~QIB_E_SPIOARMLAUNCH;
2223 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
2227 * Formerly took parameter <which> in pre-shifted,
2228 * pre-merged form with LinkCmd and LinkInitCmd
2229 * together, and assuming the zero was NOP.
2231 static void qib_set_ib_7322_lstate(struct qib_pportdata *ppd, u16 linkcmd,
2235 struct qib_devdata *dd = ppd->dd;
2236 unsigned long flags;
2238 if (linitcmd == QLOGIC_IB_IBCC_LINKINITCMD_DISABLE) {
2240 * If we are told to disable, note that so link-recovery
2241 * code does not attempt to bring us back up.
2242 * Also reset everything that we can, so we start
2243 * completely clean when re-enabled (before we
2244 * actually issue the disable to the IBC)
2246 qib_7322_mini_pcs_reset(ppd);
2247 spin_lock_irqsave(&ppd->lflags_lock, flags);
2248 ppd->lflags |= QIBL_IB_LINK_DISABLED;
2249 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
2250 } else if (linitcmd || linkcmd == QLOGIC_IB_IBCC_LINKCMD_DOWN) {
2252 * Any other linkinitcmd will lead to LINKDOWN and then
2253 * to INIT (if all is well), so clear flag to let
2254 * link-recovery code attempt to bring us back up.
2256 spin_lock_irqsave(&ppd->lflags_lock, flags);
2257 ppd->lflags &= ~QIBL_IB_LINK_DISABLED;
2258 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
2260 * Clear status change interrupt reduction so the
2261 * new state is seen.
2263 ppd->cpspec->ibcctrl_a &=
2264 ~SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
2267 mod_wd = (linkcmd << IBA7322_IBCC_LINKCMD_SHIFT) |
2268 (linitcmd << QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
2270 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a |
2272 /* write to chip to prevent back-to-back writes of ibc reg */
2273 qib_write_kreg(dd, kr_scratch, 0);
2278 * The total RCV buffer memory is 64KB, used for both ports, and is
2279 * in units of 64 bytes (same as IB flow control credit unit).
2280 * The consumedVL unit in the same registers are in 32 byte units!
2281 * So, a VL15 packet needs 4.50 IB credits, and 9 rx buffer chunks,
2282 * and we can therefore allocate just 9 IB credits for 2 VL15 packets
2283 * in krp_rxcreditvl15, rather than 10.
2285 #define RCV_BUF_UNITSZ 64
2286 #define NUM_RCV_BUF_UNITS(dd) ((64 * 1024) / (RCV_BUF_UNITSZ * dd->num_pports))
2288 static void set_vls(struct qib_pportdata *ppd)
2290 int i, numvls, totcred, cred_vl, vl0extra;
2291 struct qib_devdata *dd = ppd->dd;
2294 numvls = qib_num_vls(ppd->vls_operational);
2297 * Set up per-VL credits. Below is kluge based on these assumptions:
2298 * 1) port is disabled at the time early_init is called.
2299 * 2) give VL15 17 credits, for two max-plausible packets.
2300 * 3) Give VL0-N the rest, with any rounding excess used for VL0
2302 /* 2 VL15 packets @ 288 bytes each (including IB headers) */
2303 totcred = NUM_RCV_BUF_UNITS(dd);
2304 cred_vl = (2 * 288 + RCV_BUF_UNITSZ - 1) / RCV_BUF_UNITSZ;
2306 qib_write_kreg_port(ppd, krp_rxcreditvl15, (u64) cred_vl);
2307 cred_vl = totcred / numvls;
2308 vl0extra = totcred - cred_vl * numvls;
2309 qib_write_kreg_port(ppd, krp_rxcreditvl0, cred_vl + vl0extra);
2310 for (i = 1; i < numvls; i++)
2311 qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, cred_vl);
2312 for (; i < 8; i++) /* no buffer space for other VLs */
2313 qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, 0);
2315 /* Notify IBC that credits need to be recalculated */
2316 val = qib_read_kreg_port(ppd, krp_ibsdtestiftx);
2317 val |= SYM_MASK(IB_SDTEST_IF_TX_0, CREDIT_CHANGE);
2318 qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
2319 qib_write_kreg(dd, kr_scratch, 0ULL);
2320 val &= ~SYM_MASK(IB_SDTEST_IF_TX_0, CREDIT_CHANGE);
2321 qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
2323 for (i = 0; i < numvls; i++)
2324 val = qib_read_kreg_port(ppd, krp_rxcreditvl0 + i);
2325 val = qib_read_kreg_port(ppd, krp_rxcreditvl15);
2327 /* Change the number of operational VLs */
2328 ppd->cpspec->ibcctrl_a = (ppd->cpspec->ibcctrl_a &
2329 ~SYM_MASK(IBCCtrlA_0, NumVLane)) |
2330 ((u64)(numvls - 1) << SYM_LSB(IBCCtrlA_0, NumVLane));
2331 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
2332 qib_write_kreg(dd, kr_scratch, 0ULL);
2336 * The code that deals with actual SerDes is in serdes_7322_init().
2337 * Compared to the code for iba7220, it is minimal.
2339 static int serdes_7322_init(struct qib_pportdata *ppd);
2342 * qib_7322_bringup_serdes - bring up the serdes
2343 * @ppd: physical port on the qlogic_ib device
2345 static int qib_7322_bringup_serdes(struct qib_pportdata *ppd)
2347 struct qib_devdata *dd = ppd->dd;
2349 unsigned long flags;
2353 * SerDes model not in Pd, but still need to
2354 * set up much of IBCCtrl and IBCDDRCtrl; move elsewhere
2357 /* Put IBC in reset, sends disabled (should be in reset already) */
2358 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, IBLinkEn);
2359 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
2360 qib_write_kreg(dd, kr_scratch, 0ULL);
2362 if (qib_compat_ddr_negotiate) {
2363 ppd->cpspec->ibdeltainprog = 1;
2364 ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
2366 ppd->cpspec->iblnkerrsnap = read_7322_creg32_port(ppd,
2367 crp_iblinkerrrecov);
2370 /* flowcontrolwatermark is in units of KBytes */
2371 ibc = 0x5ULL << SYM_LSB(IBCCtrlA_0, FlowCtrlWaterMark);
2373 * Flow control is sent this often, even if no changes in
2374 * buffer space occur. Units are 128ns for this chip.
2377 ibc |= 24ULL << SYM_LSB(IBCCtrlA_0, FlowCtrlPeriod);
2378 /* max error tolerance */
2379 ibc |= 0xfULL << SYM_LSB(IBCCtrlA_0, PhyerrThreshold);
2380 /* IB credit flow control. */
2381 ibc |= 0xfULL << SYM_LSB(IBCCtrlA_0, OverrunThreshold);
2383 * set initial max size pkt IBC will send, including ICRC; it's the
2384 * PIO buffer size in dwords, less 1; also see qib_set_mtu()
2386 ibc |= ((u64)(ppd->ibmaxlen >> 2) + 1) <<
2387 SYM_LSB(IBCCtrlA_0, MaxPktLen);
2388 ppd->cpspec->ibcctrl_a = ibc; /* without linkcmd or linkinitcmd! */
2391 * Reset the PCS interface to the serdes (and also ibc, which is still
2392 * in reset from above). Writes new value of ibcctrl_a as last step.
2394 qib_7322_mini_pcs_reset(ppd);
2396 if (!ppd->cpspec->ibcctrl_b) {
2397 unsigned lse = ppd->link_speed_enabled;
2400 * Not on re-init after reset, establish shadow
2401 * and force initial config.
2403 ppd->cpspec->ibcctrl_b = qib_read_kreg_port(ppd,
2405 ppd->cpspec->ibcctrl_b &= ~(IBA7322_IBC_SPEED_QDR |
2406 IBA7322_IBC_SPEED_DDR |
2407 IBA7322_IBC_SPEED_SDR |
2408 IBA7322_IBC_WIDTH_AUTONEG |
2409 SYM_MASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED));
2410 if (lse & (lse - 1)) /* Muliple speeds enabled */
2411 ppd->cpspec->ibcctrl_b |=
2412 (lse << IBA7322_IBC_SPEED_LSB) |
2413 IBA7322_IBC_IBTA_1_2_MASK |
2414 IBA7322_IBC_MAX_SPEED_MASK;
2416 ppd->cpspec->ibcctrl_b |= (lse == QIB_IB_QDR) ?
2417 IBA7322_IBC_SPEED_QDR |
2418 IBA7322_IBC_IBTA_1_2_MASK :
2419 (lse == QIB_IB_DDR) ?
2420 IBA7322_IBC_SPEED_DDR :
2421 IBA7322_IBC_SPEED_SDR;
2422 if ((ppd->link_width_enabled & (IB_WIDTH_1X | IB_WIDTH_4X)) ==
2423 (IB_WIDTH_1X | IB_WIDTH_4X))
2424 ppd->cpspec->ibcctrl_b |= IBA7322_IBC_WIDTH_AUTONEG;
2426 ppd->cpspec->ibcctrl_b |=
2427 ppd->link_width_enabled == IB_WIDTH_4X ?
2428 IBA7322_IBC_WIDTH_4X_ONLY :
2429 IBA7322_IBC_WIDTH_1X_ONLY;
2431 /* always enable these on driver reload, not sticky */
2432 ppd->cpspec->ibcctrl_b |= (IBA7322_IBC_RXPOL_MASK |
2433 IBA7322_IBC_HRTBT_MASK);
2435 qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
2437 /* setup so we have more time at CFGTEST to change H1 */
2438 val = qib_read_kreg_port(ppd, krp_ibcctrl_c);
2439 val &= ~SYM_MASK(IBCCtrlC_0, IB_FRONT_PORCH);
2440 val |= 0xfULL << SYM_LSB(IBCCtrlC_0, IB_FRONT_PORCH);
2441 qib_write_kreg_port(ppd, krp_ibcctrl_c, val);
2443 serdes_7322_init(ppd);
2445 guid = be64_to_cpu(ppd->guid);
2448 guid = be64_to_cpu(dd->base_guid) + ppd->port - 1;
2449 ppd->guid = cpu_to_be64(guid);
2452 qib_write_kreg_port(ppd, krp_hrtbt_guid, guid);
2453 /* write to chip to prevent back-to-back writes of ibc reg */
2454 qib_write_kreg(dd, kr_scratch, 0);
2457 ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0, IBLinkEn);
2460 /* initially come up DISABLED, without sending anything. */
2461 val = ppd->cpspec->ibcctrl_a | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
2462 QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
2463 qib_write_kreg_port(ppd, krp_ibcctrl_a, val);
2464 qib_write_kreg(dd, kr_scratch, 0ULL);
2465 /* clear the linkinit cmds */
2466 ppd->cpspec->ibcctrl_a = val & ~SYM_MASK(IBCCtrlA_0, LinkInitCmd);
2468 /* be paranoid against later code motion, etc. */
2469 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
2470 ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvIBPortEnable);
2471 qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
2472 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
2474 /* Also enable IBSTATUSCHG interrupt. */
2475 val = qib_read_kreg_port(ppd, krp_errmask);
2476 qib_write_kreg_port(ppd, krp_errmask,
2477 val | ERR_MASK_N(IBStatusChanged));
2479 /* Always zero until we start messing with SerDes for real */
2484 * qib_7322_quiet_serdes - set serdes to txidle
2485 * @dd: the qlogic_ib device
2486 * Called when driver is being unloaded
2488 static void qib_7322_mini_quiet_serdes(struct qib_pportdata *ppd)
2491 unsigned long flags;
2493 qib_set_ib_7322_lstate(ppd, 0, QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
2495 spin_lock_irqsave(&ppd->lflags_lock, flags);
2496 ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
2497 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
2498 wake_up(&ppd->cpspec->autoneg_wait);
2499 cancel_delayed_work_sync(&ppd->cpspec->autoneg_work);
2500 if (ppd->dd->cspec->r1)
2501 cancel_delayed_work_sync(&ppd->cpspec->ipg_work);
2503 ppd->cpspec->chase_end = 0;
2504 if (ppd->cpspec->chase_timer.data) /* if initted */
2505 del_timer_sync(&ppd->cpspec->chase_timer);
2508 * Despite the name, actually disables IBC as well. Do it when
2509 * we are as sure as possible that no more packets can be
2510 * received, following the down and the PCS reset.
2511 * The actual disabling happens in qib_7322_mini_pci_reset(),
2512 * along with the PCS being reset.
2514 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, IBLinkEn);
2515 qib_7322_mini_pcs_reset(ppd);
2518 * Update the adjusted counters so the adjustment persists
2519 * across driver reload.
2521 if (ppd->cpspec->ibsymdelta || ppd->cpspec->iblnkerrdelta ||
2522 ppd->cpspec->ibdeltainprog || ppd->cpspec->iblnkdowndelta) {
2523 struct qib_devdata *dd = ppd->dd;
2526 /* enable counter writes */
2527 diagc = qib_read_kreg64(dd, kr_hwdiagctrl);
2528 qib_write_kreg(dd, kr_hwdiagctrl,
2529 diagc | SYM_MASK(HwDiagCtrl, CounterWrEnable));
2531 if (ppd->cpspec->ibsymdelta || ppd->cpspec->ibdeltainprog) {
2532 val = read_7322_creg32_port(ppd, crp_ibsymbolerr);
2533 if (ppd->cpspec->ibdeltainprog)
2534 val -= val - ppd->cpspec->ibsymsnap;
2535 val -= ppd->cpspec->ibsymdelta;
2536 write_7322_creg_port(ppd, crp_ibsymbolerr, val);
2538 if (ppd->cpspec->iblnkerrdelta || ppd->cpspec->ibdeltainprog) {
2539 val = read_7322_creg32_port(ppd, crp_iblinkerrrecov);
2540 if (ppd->cpspec->ibdeltainprog)
2541 val -= val - ppd->cpspec->iblnkerrsnap;
2542 val -= ppd->cpspec->iblnkerrdelta;
2543 write_7322_creg_port(ppd, crp_iblinkerrrecov, val);
2545 if (ppd->cpspec->iblnkdowndelta) {
2546 val = read_7322_creg32_port(ppd, crp_iblinkdown);
2547 val += ppd->cpspec->iblnkdowndelta;
2548 write_7322_creg_port(ppd, crp_iblinkdown, val);
2551 * No need to save ibmalfdelta since IB perfcounters
2552 * are cleared on driver reload.
2555 /* and disable counter writes */
2556 qib_write_kreg(dd, kr_hwdiagctrl, diagc);
2561 * qib_setup_7322_setextled - set the state of the two external LEDs
2562 * @ppd: physical port on the qlogic_ib device
2563 * @on: whether the link is up or not
2565 * The exact combo of LEDs if on is true is determined by looking
2568 * These LEDs indicate the physical and logical state of IB link.
2569 * For this chip (at least with recommended board pinouts), LED1
2570 * is Yellow (logical state) and LED2 is Green (physical state),
2572 * Note: We try to match the Mellanox HCA LED behavior as best
2573 * we can. Green indicates physical link state is OK (something is
2574 * plugged in, and we can train).
2575 * Amber indicates the link is logically up (ACTIVE).
2576 * Mellanox further blinks the amber LED to indicate data packet
2577 * activity, but we have no hardware support for that, so it would
2578 * require waking up every 10-20 msecs and checking the counters
2579 * on the chip, and then turning the LED off if appropriate. That's
2580 * visible overhead, so not something we will do.
2582 static void qib_setup_7322_setextled(struct qib_pportdata *ppd, u32 on)
2584 struct qib_devdata *dd = ppd->dd;
2585 u64 extctl, ledblink = 0, val;
2586 unsigned long flags;
2590 * The diags use the LED to indicate diag info, so we leave
2591 * the external LED alone when the diags are running.
2593 if (dd->diag_client)
2596 /* Allow override of LED display for, e.g. Locating system in rack */
2597 if (ppd->led_override) {
2598 grn = (ppd->led_override & QIB_LED_PHYS);
2599 yel = (ppd->led_override & QIB_LED_LOG);
2601 val = qib_read_kreg_port(ppd, krp_ibcstatus_a);
2602 grn = qib_7322_phys_portstate(val) ==
2603 IB_PHYSPORTSTATE_LINKUP;
2604 yel = qib_7322_iblink_state(val) == IB_PORT_ACTIVE;
2610 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
2611 extctl = dd->cspec->extctrl & (ppd->port == 1 ?
2612 ~ExtLED_IB1_MASK : ~ExtLED_IB2_MASK);
2614 extctl |= ppd->port == 1 ? ExtLED_IB1_GRN : ExtLED_IB2_GRN;
2616 * Counts are in chip clock (4ns) periods.
2617 * This is 1/16 sec (66.6ms) on,
2618 * 3/16 sec (187.5 ms) off, with packets rcvd.
2620 ledblink = ((66600 * 1000UL / 4) << IBA7322_LEDBLINK_ON_SHIFT) |
2621 ((187500 * 1000UL / 4) << IBA7322_LEDBLINK_OFF_SHIFT);
2624 extctl |= ppd->port == 1 ? ExtLED_IB1_YEL : ExtLED_IB2_YEL;
2625 dd->cspec->extctrl = extctl;
2626 qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
2627 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
2629 if (ledblink) /* blink the LED on packet receive */
2630 qib_write_kreg_port(ppd, krp_rcvpktledcnt, ledblink);
2633 #ifdef CONFIG_INFINIBAND_QIB_DCA
2635 static int qib_7322_notify_dca(struct qib_devdata *dd, unsigned long event)
2638 case DCA_PROVIDER_ADD:
2639 if (dd->flags & QIB_DCA_ENABLED)
2641 if (!dca_add_requester(&dd->pcidev->dev)) {
2642 qib_devinfo(dd->pcidev, "DCA enabled\n");
2643 dd->flags |= QIB_DCA_ENABLED;
2647 case DCA_PROVIDER_REMOVE:
2648 if (dd->flags & QIB_DCA_ENABLED) {
2649 dca_remove_requester(&dd->pcidev->dev);
2650 dd->flags &= ~QIB_DCA_ENABLED;
2651 dd->cspec->dca_ctrl = 0;
2652 qib_write_kreg(dd, KREG_IDX(DCACtrlA),
2653 dd->cspec->dca_ctrl);
2660 static void qib_update_rhdrq_dca(struct qib_ctxtdata *rcd, int cpu)
2662 struct qib_devdata *dd = rcd->dd;
2663 struct qib_chip_specific *cspec = dd->cspec;
2665 if (!(dd->flags & QIB_DCA_ENABLED))
2667 if (cspec->rhdr_cpu[rcd->ctxt] != cpu) {
2668 const struct dca_reg_map *rmp;
2670 cspec->rhdr_cpu[rcd->ctxt] = cpu;
2671 rmp = &dca_rcvhdr_reg_map[rcd->ctxt];
2672 cspec->dca_rcvhdr_ctrl[rmp->shadow_inx] &= rmp->mask;
2673 cspec->dca_rcvhdr_ctrl[rmp->shadow_inx] |=
2674 (u64) dca3_get_tag(&dd->pcidev->dev, cpu) << rmp->lsb;
2675 qib_devinfo(dd->pcidev,
2676 "Ctxt %d cpu %d dca %llx\n", rcd->ctxt, cpu,
2677 (long long) cspec->dca_rcvhdr_ctrl[rmp->shadow_inx]);
2678 qib_write_kreg(dd, rmp->regno,
2679 cspec->dca_rcvhdr_ctrl[rmp->shadow_inx]);
2680 cspec->dca_ctrl |= SYM_MASK(DCACtrlA, RcvHdrqDCAEnable);
2681 qib_write_kreg(dd, KREG_IDX(DCACtrlA), cspec->dca_ctrl);
2685 static void qib_update_sdma_dca(struct qib_pportdata *ppd, int cpu)
2687 struct qib_devdata *dd = ppd->dd;
2688 struct qib_chip_specific *cspec = dd->cspec;
2689 unsigned pidx = ppd->port - 1;
2691 if (!(dd->flags & QIB_DCA_ENABLED))
2693 if (cspec->sdma_cpu[pidx] != cpu) {
2694 cspec->sdma_cpu[pidx] = cpu;
2695 cspec->dca_rcvhdr_ctrl[4] &= ~(ppd->hw_pidx ?
2696 SYM_MASK(DCACtrlF, SendDma1DCAOPH) :
2697 SYM_MASK(DCACtrlF, SendDma0DCAOPH));
2698 cspec->dca_rcvhdr_ctrl[4] |=
2699 (u64) dca3_get_tag(&dd->pcidev->dev, cpu) <<
2701 SYM_LSB(DCACtrlF, SendDma1DCAOPH) :
2702 SYM_LSB(DCACtrlF, SendDma0DCAOPH));
2703 qib_devinfo(dd->pcidev,
2704 "sdma %d cpu %d dca %llx\n", ppd->hw_pidx, cpu,
2705 (long long) cspec->dca_rcvhdr_ctrl[4]);
2706 qib_write_kreg(dd, KREG_IDX(DCACtrlF),
2707 cspec->dca_rcvhdr_ctrl[4]);
2708 cspec->dca_ctrl |= ppd->hw_pidx ?
2709 SYM_MASK(DCACtrlA, SendDMAHead1DCAEnable) :
2710 SYM_MASK(DCACtrlA, SendDMAHead0DCAEnable);
2711 qib_write_kreg(dd, KREG_IDX(DCACtrlA), cspec->dca_ctrl);
2715 static void qib_setup_dca(struct qib_devdata *dd)
2717 struct qib_chip_specific *cspec = dd->cspec;
2720 for (i = 0; i < ARRAY_SIZE(cspec->rhdr_cpu); i++)
2721 cspec->rhdr_cpu[i] = -1;
2722 for (i = 0; i < ARRAY_SIZE(cspec->sdma_cpu); i++)
2723 cspec->sdma_cpu[i] = -1;
2724 cspec->dca_rcvhdr_ctrl[0] =
2725 (1ULL << SYM_LSB(DCACtrlB, RcvHdrq0DCAXfrCnt)) |
2726 (1ULL << SYM_LSB(DCACtrlB, RcvHdrq1DCAXfrCnt)) |
2727 (1ULL << SYM_LSB(DCACtrlB, RcvHdrq2DCAXfrCnt)) |
2728 (1ULL << SYM_LSB(DCACtrlB, RcvHdrq3DCAXfrCnt));
2729 cspec->dca_rcvhdr_ctrl[1] =
2730 (1ULL << SYM_LSB(DCACtrlC, RcvHdrq4DCAXfrCnt)) |
2731 (1ULL << SYM_LSB(DCACtrlC, RcvHdrq5DCAXfrCnt)) |
2732 (1ULL << SYM_LSB(DCACtrlC, RcvHdrq6DCAXfrCnt)) |
2733 (1ULL << SYM_LSB(DCACtrlC, RcvHdrq7DCAXfrCnt));
2734 cspec->dca_rcvhdr_ctrl[2] =
2735 (1ULL << SYM_LSB(DCACtrlD, RcvHdrq8DCAXfrCnt)) |
2736 (1ULL << SYM_LSB(DCACtrlD, RcvHdrq9DCAXfrCnt)) |
2737 (1ULL << SYM_LSB(DCACtrlD, RcvHdrq10DCAXfrCnt)) |
2738 (1ULL << SYM_LSB(DCACtrlD, RcvHdrq11DCAXfrCnt));
2739 cspec->dca_rcvhdr_ctrl[3] =
2740 (1ULL << SYM_LSB(DCACtrlE, RcvHdrq12DCAXfrCnt)) |
2741 (1ULL << SYM_LSB(DCACtrlE, RcvHdrq13DCAXfrCnt)) |
2742 (1ULL << SYM_LSB(DCACtrlE, RcvHdrq14DCAXfrCnt)) |
2743 (1ULL << SYM_LSB(DCACtrlE, RcvHdrq15DCAXfrCnt));
2744 cspec->dca_rcvhdr_ctrl[4] =
2745 (1ULL << SYM_LSB(DCACtrlF, RcvHdrq16DCAXfrCnt)) |
2746 (1ULL << SYM_LSB(DCACtrlF, RcvHdrq17DCAXfrCnt));
2747 for (i = 0; i < ARRAY_SIZE(cspec->sdma_cpu); i++)
2748 qib_write_kreg(dd, KREG_IDX(DCACtrlB) + i,
2749 cspec->dca_rcvhdr_ctrl[i]);
2750 for (i = 0; i < cspec->num_msix_entries; i++)
2751 setup_dca_notifier(dd, &cspec->msix_entries[i]);
2754 static void qib_irq_notifier_notify(struct irq_affinity_notify *notify,
2755 const cpumask_t *mask)
2757 struct qib_irq_notify *n =
2758 container_of(notify, struct qib_irq_notify, notify);
2759 int cpu = cpumask_first(mask);
2762 struct qib_ctxtdata *rcd = (struct qib_ctxtdata *)n->arg;
2763 qib_update_rhdrq_dca(rcd, cpu);
2765 struct qib_pportdata *ppd = (struct qib_pportdata *)n->arg;
2766 qib_update_sdma_dca(ppd, cpu);
2770 static void qib_irq_notifier_release(struct kref *ref)
2772 struct qib_irq_notify *n =
2773 container_of(ref, struct qib_irq_notify, notify.kref);
2774 struct qib_devdata *dd;
2777 struct qib_ctxtdata *rcd = (struct qib_ctxtdata *)n->arg;
2780 struct qib_pportdata *ppd = (struct qib_pportdata *)n->arg;
2783 qib_devinfo(dd->pcidev,
2784 "release on HCA notify 0x%p n 0x%p\n", ref, n);
2790 * Disable MSIx interrupt if enabled, call generic MSIx code
2791 * to cleanup, and clear pending MSIx interrupts.
2792 * Used for fallback to INTx, after reset, and when MSIx setup fails.
2794 static void qib_7322_nomsix(struct qib_devdata *dd)
2799 dd->cspec->main_int_mask = ~0ULL;
2800 n = dd->cspec->num_msix_entries;
2804 dd->cspec->num_msix_entries = 0;
2805 for (i = 0; i < n; i++) {
2806 #ifdef CONFIG_INFINIBAND_QIB_DCA
2807 reset_dca_notifier(dd, &dd->cspec->msix_entries[i]);
2809 irq_set_affinity_hint(
2810 dd->cspec->msix_entries[i].msix.vector, NULL);
2811 free_cpumask_var(dd->cspec->msix_entries[i].mask);
2812 free_irq(dd->cspec->msix_entries[i].msix.vector,
2813 dd->cspec->msix_entries[i].arg);
2817 /* make sure no MSIx interrupts are left pending */
2818 intgranted = qib_read_kreg64(dd, kr_intgranted);
2820 qib_write_kreg(dd, kr_intgranted, intgranted);
2823 static void qib_7322_free_irq(struct qib_devdata *dd)
2825 if (dd->cspec->irq) {
2826 free_irq(dd->cspec->irq, dd);
2829 qib_7322_nomsix(dd);
2832 static void qib_setup_7322_cleanup(struct qib_devdata *dd)
2836 #ifdef CONFIG_INFINIBAND_QIB_DCA
2837 if (dd->flags & QIB_DCA_ENABLED) {
2838 dca_remove_requester(&dd->pcidev->dev);
2839 dd->flags &= ~QIB_DCA_ENABLED;
2840 dd->cspec->dca_ctrl = 0;
2841 qib_write_kreg(dd, KREG_IDX(DCACtrlA), dd->cspec->dca_ctrl);
2845 qib_7322_free_irq(dd);
2846 kfree(dd->cspec->cntrs);
2847 kfree(dd->cspec->sendchkenable);
2848 kfree(dd->cspec->sendgrhchk);
2849 kfree(dd->cspec->sendibchk);
2850 kfree(dd->cspec->msix_entries);
2851 for (i = 0; i < dd->num_pports; i++) {
2852 unsigned long flags;
2853 u32 mask = QSFP_GPIO_MOD_PRS_N |
2854 (QSFP_GPIO_MOD_PRS_N << QSFP_GPIO_PORT2_SHIFT);
2856 kfree(dd->pport[i].cpspec->portcntrs);
2857 if (dd->flags & QIB_HAS_QSFP) {
2858 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
2859 dd->cspec->gpio_mask &= ~mask;
2860 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
2861 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
2862 qib_qsfp_deinit(&dd->pport[i].cpspec->qsfp_data);
2864 if (dd->pport[i].ibport_data.smi_ah)
2865 ib_destroy_ah(&dd->pport[i].ibport_data.smi_ah->ibah);
2869 /* handle SDMA interrupts */
2870 static void sdma_7322_intr(struct qib_devdata *dd, u64 istat)
2872 struct qib_pportdata *ppd0 = &dd->pport[0];
2873 struct qib_pportdata *ppd1 = &dd->pport[1];
2874 u64 intr0 = istat & (INT_MASK_P(SDma, 0) |
2875 INT_MASK_P(SDmaIdle, 0) | INT_MASK_P(SDmaProgress, 0));
2876 u64 intr1 = istat & (INT_MASK_P(SDma, 1) |
2877 INT_MASK_P(SDmaIdle, 1) | INT_MASK_P(SDmaProgress, 1));
2880 qib_sdma_intr(ppd0);
2882 qib_sdma_intr(ppd1);
2884 if (istat & INT_MASK_PM(SDmaCleanupDone, 0))
2885 qib_sdma_process_event(ppd0, qib_sdma_event_e20_hw_started);
2886 if (istat & INT_MASK_PM(SDmaCleanupDone, 1))
2887 qib_sdma_process_event(ppd1, qib_sdma_event_e20_hw_started);
2891 * Set or clear the Send buffer available interrupt enable bit.
2893 static void qib_wantpiobuf_7322_intr(struct qib_devdata *dd, u32 needint)
2895 unsigned long flags;
2897 spin_lock_irqsave(&dd->sendctrl_lock, flags);
2899 dd->sendctrl |= SYM_MASK(SendCtrl, SendIntBufAvail);
2901 dd->sendctrl &= ~SYM_MASK(SendCtrl, SendIntBufAvail);
2902 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
2903 qib_write_kreg(dd, kr_scratch, 0ULL);
2904 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
2908 * Somehow got an interrupt with reserved bits set in interrupt status.
2909 * Print a message so we know it happened, then clear them.
2910 * keep mainline interrupt handler cache-friendly
2912 static noinline void unknown_7322_ibits(struct qib_devdata *dd, u64 istat)
2917 kills = istat & ~QIB_I_BITSEXTANT;
2919 "Clearing reserved interrupt(s) 0x%016llx: %s\n",
2920 (unsigned long long) kills, msg);
2921 qib_write_kreg(dd, kr_intmask, (dd->cspec->int_enable_mask & ~kills));
2924 /* keep mainline interrupt handler cache-friendly */
2925 static noinline void unknown_7322_gpio_intr(struct qib_devdata *dd)
2932 * Boards for this chip currently don't use GPIO interrupts,
2933 * so clear by writing GPIOstatus to GPIOclear, and complain
2934 * to developer. To avoid endless repeats, clear
2935 * the bits in the mask, since there is some kind of
2936 * programming error or chip problem.
2938 gpiostatus = qib_read_kreg32(dd, kr_gpio_status);
2940 * In theory, writing GPIOstatus to GPIOclear could
2941 * have a bad side-effect on some diagnostic that wanted
2942 * to poll for a status-change, but the various shadows
2943 * make that problematic at best. Diags will just suppress
2944 * all GPIO interrupts during such tests.
2946 qib_write_kreg(dd, kr_gpio_clear, gpiostatus);
2948 * Check for QSFP MOD_PRS changes
2949 * only works for single port if IB1 != pidx1
2951 for (pidx = 0; pidx < dd->num_pports && (dd->flags & QIB_HAS_QSFP);
2953 struct qib_pportdata *ppd;
2954 struct qib_qsfp_data *qd;
2956 if (!dd->pport[pidx].link_speed_supported)
2958 mask = QSFP_GPIO_MOD_PRS_N;
2959 ppd = dd->pport + pidx;
2960 mask <<= (QSFP_GPIO_PORT2_SHIFT * ppd->hw_pidx);
2961 if (gpiostatus & dd->cspec->gpio_mask & mask) {
2963 qd = &ppd->cpspec->qsfp_data;
2964 gpiostatus &= ~mask;
2965 pins = qib_read_kreg64(dd, kr_extstatus);
2966 pins >>= SYM_LSB(EXTStatus, GPIOIn);
2967 if (!(pins & mask)) {
2969 qd->t_insert = jiffies;
2970 queue_work(ib_wq, &qd->work);
2975 if (gpiostatus && !handled) {
2976 const u32 mask = qib_read_kreg32(dd, kr_gpio_mask);
2977 u32 gpio_irq = mask & gpiostatus;
2980 * Clear any troublemakers, and update chip from shadow
2982 dd->cspec->gpio_mask &= ~gpio_irq;
2983 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
2988 * Handle errors and unusual events first, separate function
2989 * to improve cache hits for fast path interrupt handling.
2991 static noinline void unlikely_7322_intr(struct qib_devdata *dd, u64 istat)
2993 if (istat & ~QIB_I_BITSEXTANT)
2994 unknown_7322_ibits(dd, istat);
2995 if (istat & QIB_I_GPIO)
2996 unknown_7322_gpio_intr(dd);
2997 if (istat & QIB_I_C_ERROR) {
2998 qib_write_kreg(dd, kr_errmask, 0ULL);
2999 tasklet_schedule(&dd->error_tasklet);
3001 if (istat & INT_MASK_P(Err, 0) && dd->rcd[0])
3002 handle_7322_p_errors(dd->rcd[0]->ppd);
3003 if (istat & INT_MASK_P(Err, 1) && dd->rcd[1])
3004 handle_7322_p_errors(dd->rcd[1]->ppd);
3008 * Dynamically adjust the rcv int timeout for a context based on incoming
3011 static void adjust_rcv_timeout(struct qib_ctxtdata *rcd, int npkts)
3013 struct qib_devdata *dd = rcd->dd;
3014 u32 timeout = dd->cspec->rcvavail_timeout[rcd->ctxt];
3017 * Dynamically adjust idle timeout on chip
3018 * based on number of packets processed.
3020 if (npkts < rcv_int_count && timeout > 2)
3022 else if (npkts >= rcv_int_count && timeout < rcv_int_timeout)
3023 timeout = min(timeout << 1, rcv_int_timeout);
3027 dd->cspec->rcvavail_timeout[rcd->ctxt] = timeout;
3028 qib_write_kreg(dd, kr_rcvavailtimeout + rcd->ctxt, timeout);
3032 * This is the main interrupt handler.
3033 * It will normally only be used for low frequency interrupts but may
3034 * have to handle all interrupts if INTx is enabled or fewer than normal
3035 * MSIx interrupts were allocated.
3036 * This routine should ignore the interrupt bits for any of the
3037 * dedicated MSIx handlers.
3039 static irqreturn_t qib_7322intr(int irq, void *data)
3041 struct qib_devdata *dd = data;
3049 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT) {
3051 * This return value is not great, but we do not want the
3052 * interrupt core code to remove our interrupt handler
3053 * because we don't appear to be handling an interrupt
3054 * during a chip reset.
3060 istat = qib_read_kreg64(dd, kr_intstatus);
3062 if (unlikely(istat == ~0ULL)) {
3063 qib_bad_intrstatus(dd);
3064 qib_dev_err(dd, "Interrupt status all f's, skipping\n");
3065 /* don't know if it was our interrupt or not */
3070 istat &= dd->cspec->main_int_mask;
3071 if (unlikely(!istat)) {
3072 /* already handled, or shared and not us */
3077 qib_stats.sps_ints++;
3078 if (dd->int_counter != (u32) -1)
3081 /* handle "errors" of various kinds first, device ahead of port */
3082 if (unlikely(istat & (~QIB_I_BITSEXTANT | QIB_I_GPIO |
3083 QIB_I_C_ERROR | INT_MASK_P(Err, 0) |
3084 INT_MASK_P(Err, 1))))
3085 unlikely_7322_intr(dd, istat);
3088 * Clear the interrupt bits we found set, relatively early, so we
3089 * "know" know the chip will have seen this by the time we process
3090 * the queue, and will re-interrupt if necessary. The processor
3091 * itself won't take the interrupt again until we return.
3093 qib_write_kreg(dd, kr_intclear, istat);
3096 * Handle kernel receive queues before checking for pio buffers
3097 * available since receives can overflow; piobuf waiters can afford
3098 * a few extra cycles, since they were waiting anyway.
3100 ctxtrbits = istat & (QIB_I_RCVAVAIL_MASK | QIB_I_RCVURG_MASK);
3102 rmask = (1ULL << QIB_I_RCVAVAIL_LSB) |
3103 (1ULL << QIB_I_RCVURG_LSB);
3104 for (i = 0; i < dd->first_user_ctxt; i++) {
3105 if (ctxtrbits & rmask) {
3106 ctxtrbits &= ~rmask;
3108 qib_kreceive(dd->rcd[i], NULL, &npkts);
3113 ctxtrbits = (ctxtrbits >> QIB_I_RCVAVAIL_LSB) |
3114 (ctxtrbits >> QIB_I_RCVURG_LSB);
3115 qib_handle_urcv(dd, ctxtrbits);
3119 if (istat & (QIB_I_P_SDMAINT(0) | QIB_I_P_SDMAINT(1)))
3120 sdma_7322_intr(dd, istat);
3122 if ((istat & QIB_I_SPIOBUFAVAIL) && (dd->flags & QIB_INITTED))
3123 qib_ib_piobufavail(dd);
3131 * Dedicated receive packet available interrupt handler.
3133 static irqreturn_t qib_7322pintr(int irq, void *data)
3135 struct qib_ctxtdata *rcd = data;
3136 struct qib_devdata *dd = rcd->dd;
3139 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
3141 * This return value is not great, but we do not want the
3142 * interrupt core code to remove our interrupt handler
3143 * because we don't appear to be handling an interrupt
3144 * during a chip reset.
3148 qib_stats.sps_ints++;
3149 if (dd->int_counter != (u32) -1)
3152 /* Clear the interrupt bit we expect to be set. */
3153 qib_write_kreg(dd, kr_intclear, ((1ULL << QIB_I_RCVAVAIL_LSB) |
3154 (1ULL << QIB_I_RCVURG_LSB)) << rcd->ctxt);
3156 qib_kreceive(rcd, NULL, &npkts);
3162 * Dedicated Send buffer available interrupt handler.
3164 static irqreturn_t qib_7322bufavail(int irq, void *data)
3166 struct qib_devdata *dd = data;
3168 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
3170 * This return value is not great, but we do not want the
3171 * interrupt core code to remove our interrupt handler
3172 * because we don't appear to be handling an interrupt
3173 * during a chip reset.
3177 qib_stats.sps_ints++;
3178 if (dd->int_counter != (u32) -1)
3181 /* Clear the interrupt bit we expect to be set. */
3182 qib_write_kreg(dd, kr_intclear, QIB_I_SPIOBUFAVAIL);
3184 /* qib_ib_piobufavail() will clear the want PIO interrupt if needed */
3185 if (dd->flags & QIB_INITTED)
3186 qib_ib_piobufavail(dd);
3188 qib_wantpiobuf_7322_intr(dd, 0);
3194 * Dedicated Send DMA interrupt handler.
3196 static irqreturn_t sdma_intr(int irq, void *data)
3198 struct qib_pportdata *ppd = data;
3199 struct qib_devdata *dd = ppd->dd;
3201 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
3203 * This return value is not great, but we do not want the
3204 * interrupt core code to remove our interrupt handler
3205 * because we don't appear to be handling an interrupt
3206 * during a chip reset.
3210 qib_stats.sps_ints++;
3211 if (dd->int_counter != (u32) -1)
3214 /* Clear the interrupt bit we expect to be set. */
3215 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
3216 INT_MASK_P(SDma, 1) : INT_MASK_P(SDma, 0));
3223 * Dedicated Send DMA idle interrupt handler.
3225 static irqreturn_t sdma_idle_intr(int irq, void *data)
3227 struct qib_pportdata *ppd = data;
3228 struct qib_devdata *dd = ppd->dd;
3230 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
3232 * This return value is not great, but we do not want the
3233 * interrupt core code to remove our interrupt handler
3234 * because we don't appear to be handling an interrupt
3235 * during a chip reset.
3239 qib_stats.sps_ints++;
3240 if (dd->int_counter != (u32) -1)
3243 /* Clear the interrupt bit we expect to be set. */
3244 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
3245 INT_MASK_P(SDmaIdle, 1) : INT_MASK_P(SDmaIdle, 0));
3252 * Dedicated Send DMA progress interrupt handler.
3254 static irqreturn_t sdma_progress_intr(int irq, void *data)
3256 struct qib_pportdata *ppd = data;
3257 struct qib_devdata *dd = ppd->dd;
3259 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
3261 * This return value is not great, but we do not want the
3262 * interrupt core code to remove our interrupt handler
3263 * because we don't appear to be handling an interrupt
3264 * during a chip reset.
3268 qib_stats.sps_ints++;
3269 if (dd->int_counter != (u32) -1)
3272 /* Clear the interrupt bit we expect to be set. */
3273 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
3274 INT_MASK_P(SDmaProgress, 1) :
3275 INT_MASK_P(SDmaProgress, 0));
3282 * Dedicated Send DMA cleanup interrupt handler.
3284 static irqreturn_t sdma_cleanup_intr(int irq, void *data)
3286 struct qib_pportdata *ppd = data;
3287 struct qib_devdata *dd = ppd->dd;
3289 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
3291 * This return value is not great, but we do not want the
3292 * interrupt core code to remove our interrupt handler
3293 * because we don't appear to be handling an interrupt
3294 * during a chip reset.
3298 qib_stats.sps_ints++;
3299 if (dd->int_counter != (u32) -1)
3302 /* Clear the interrupt bit we expect to be set. */
3303 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
3304 INT_MASK_PM(SDmaCleanupDone, 1) :
3305 INT_MASK_PM(SDmaCleanupDone, 0));
3306 qib_sdma_process_event(ppd, qib_sdma_event_e20_hw_started);
3311 #ifdef CONFIG_INFINIBAND_QIB_DCA
3313 static void reset_dca_notifier(struct qib_devdata *dd, struct qib_msix_entry *m)
3317 qib_devinfo(dd->pcidev,
3318 "Disabling notifier on HCA %d irq %d\n",
3321 irq_set_affinity_notifier(
3327 static void setup_dca_notifier(struct qib_devdata *dd, struct qib_msix_entry *m)
3329 struct qib_irq_notify *n;
3333 n = kzalloc(sizeof(*n), GFP_KERNEL);
3338 n->notify.irq = m->msix.vector;
3339 n->notify.notify = qib_irq_notifier_notify;
3340 n->notify.release = qib_irq_notifier_release;
3343 qib_devinfo(dd->pcidev,
3344 "set notifier irq %d rcv %d notify %p\n",
3345 n->notify.irq, n->rcv, &n->notify);
3346 ret = irq_set_affinity_notifier(
3359 * Set up our chip-specific interrupt handler.
3360 * The interrupt type has already been setup, so
3361 * we just need to do the registration and error checking.
3362 * If we are using MSIx interrupts, we may fall back to
3363 * INTx later, if the interrupt handler doesn't get called
3364 * within 1/2 second (see verify_interrupt()).
3366 static void qib_setup_7322_interrupt(struct qib_devdata *dd, int clearpend)
3368 int ret, i, msixnum;
3371 const struct cpumask *local_mask;
3372 int firstcpu, secondcpu = 0, currrcvcpu = 0;
3374 if (!dd->num_pports)
3379 * if not switching interrupt types, be sure interrupts are
3380 * disabled, and then clear anything pending at this point,
3381 * because we are starting clean.
3383 qib_7322_set_intr_state(dd, 0);
3385 /* clear the reset error, init error/hwerror mask */
3386 qib_7322_init_hwerrors(dd);
3388 /* clear any interrupt bits that might be set */
3389 qib_write_kreg(dd, kr_intclear, ~0ULL);
3391 /* make sure no pending MSIx intr, and clear diag reg */
3392 qib_write_kreg(dd, kr_intgranted, ~0ULL);
3393 qib_write_kreg(dd, kr_vecclr_wo_int, ~0ULL);
3396 if (!dd->cspec->num_msix_entries) {
3397 /* Try to get INTx interrupt */
3399 if (!dd->pcidev->irq) {
3401 "irq is 0, BIOS error? Interrupts won't work\n");
3404 ret = request_irq(dd->pcidev->irq, qib_7322intr,
3405 IRQF_SHARED, QIB_DRV_NAME, dd);
3408 "Couldn't setup INTx interrupt (irq=%d): %d\n",
3409 dd->pcidev->irq, ret);
3412 dd->cspec->irq = dd->pcidev->irq;
3413 dd->cspec->main_int_mask = ~0ULL;
3417 /* Try to get MSIx interrupts */
3418 memset(redirect, 0, sizeof redirect);
3421 local_mask = cpumask_of_pcibus(dd->pcidev->bus);
3422 firstcpu = cpumask_first(local_mask);
3423 if (firstcpu >= nr_cpu_ids ||
3424 cpumask_weight(local_mask) == num_online_cpus()) {
3425 local_mask = topology_core_cpumask(0);
3426 firstcpu = cpumask_first(local_mask);
3428 if (firstcpu < nr_cpu_ids) {
3429 secondcpu = cpumask_next(firstcpu, local_mask);
3430 if (secondcpu >= nr_cpu_ids)
3431 secondcpu = firstcpu;
3432 currrcvcpu = secondcpu;
3434 for (i = 0; msixnum < dd->cspec->num_msix_entries; i++) {
3435 irq_handler_t handler;
3439 #ifdef CONFIG_INFINIBAND_QIB_DCA
3443 dd->cspec->msix_entries[msixnum].
3444 name[sizeof(dd->cspec->msix_entries[msixnum].name) - 1]
3446 if (i < ARRAY_SIZE(irq_table)) {
3447 if (irq_table[i].port) {
3448 /* skip if for a non-configured port */
3449 if (irq_table[i].port > dd->num_pports)
3451 arg = dd->pport + irq_table[i].port - 1;
3454 #ifdef CONFIG_INFINIBAND_QIB_DCA
3455 dca = irq_table[i].dca;
3457 lsb = irq_table[i].lsb;
3458 handler = irq_table[i].handler;
3459 snprintf(dd->cspec->msix_entries[msixnum].name,
3460 sizeof(dd->cspec->msix_entries[msixnum].name)
3462 QIB_DRV_NAME "%d%s", dd->unit,
3467 ctxt = i - ARRAY_SIZE(irq_table);
3468 /* per krcvq context receive interrupt */
3469 arg = dd->rcd[ctxt];
3472 if (qib_krcvq01_no_msi && ctxt < 2)
3474 #ifdef CONFIG_INFINIBAND_QIB_DCA
3477 lsb = QIB_I_RCVAVAIL_LSB + ctxt;
3478 handler = qib_7322pintr;
3479 snprintf(dd->cspec->msix_entries[msixnum].name,
3480 sizeof(dd->cspec->msix_entries[msixnum].name)
3482 QIB_DRV_NAME "%d (kctx)", dd->unit);
3485 dd->cspec->msix_entries[msixnum].msix.vector,
3486 handler, 0, dd->cspec->msix_entries[msixnum].name,
3490 * Shouldn't happen since the enable said we could
3491 * have as many as we are trying to setup here.
3494 "Couldn't setup MSIx interrupt (vec=%d, irq=%d): %d\n",
3496 dd->cspec->msix_entries[msixnum].msix.vector,
3498 qib_7322_nomsix(dd);
3501 dd->cspec->msix_entries[msixnum].arg = arg;
3502 #ifdef CONFIG_INFINIBAND_QIB_DCA
3503 dd->cspec->msix_entries[msixnum].dca = dca;
3504 dd->cspec->msix_entries[msixnum].rcv =
3505 handler == qib_7322pintr;
3508 reg = lsb / IBA7322_REDIRECT_VEC_PER_REG;
3509 sh = (lsb % IBA7322_REDIRECT_VEC_PER_REG) *
3510 SYM_LSB(IntRedirect0, vec1);
3511 mask &= ~(1ULL << lsb);
3512 redirect[reg] |= ((u64) msixnum) << sh;
3514 val = qib_read_kreg64(dd, 2 * msixnum + 1 +
3515 (QIB_7322_MsixTable_OFFS / sizeof(u64)));
3516 if (firstcpu < nr_cpu_ids &&
3518 &dd->cspec->msix_entries[msixnum].mask,
3520 if (handler == qib_7322pintr) {
3521 cpumask_set_cpu(currrcvcpu,
3522 dd->cspec->msix_entries[msixnum].mask);
3523 currrcvcpu = cpumask_next(currrcvcpu,
3525 if (currrcvcpu >= nr_cpu_ids)
3526 currrcvcpu = secondcpu;
3528 cpumask_set_cpu(firstcpu,
3529 dd->cspec->msix_entries[msixnum].mask);
3531 irq_set_affinity_hint(
3532 dd->cspec->msix_entries[msixnum].msix.vector,
3533 dd->cspec->msix_entries[msixnum].mask);
3537 /* Initialize the vector mapping */
3538 for (i = 0; i < ARRAY_SIZE(redirect); i++)
3539 qib_write_kreg(dd, kr_intredirect + i, redirect[i]);
3540 dd->cspec->main_int_mask = mask;
3541 tasklet_init(&dd->error_tasklet, qib_error_tasklet,
3547 * qib_7322_boardname - fill in the board name and note features
3548 * @dd: the qlogic_ib device
3550 * info will be based on the board revision register
3552 static unsigned qib_7322_boardname(struct qib_devdata *dd)
3554 /* Will need enumeration of board-types here */
3556 u32 boardid, namelen;
3557 unsigned features = DUAL_PORT_CAP;
3559 boardid = SYM_FIELD(dd->revision, Revision, BoardID);
3563 n = "InfiniPath_QLE7342_Emulation";
3566 n = "InfiniPath_QLE7340";
3567 dd->flags |= QIB_HAS_QSFP;
3568 features = PORT_SPD_CAP;
3571 n = "InfiniPath_QLE7342";
3572 dd->flags |= QIB_HAS_QSFP;
3575 n = "InfiniPath_QMI7342";
3578 n = "InfiniPath_Unsupported7342";
3579 qib_dev_err(dd, "Unsupported version of QMH7342\n");
3583 n = "InfiniPath_QMH7342";
3587 n = "InfiniPath_QME7342";
3590 n = "InfiniPath_QME7362";
3591 dd->flags |= QIB_HAS_QSFP;
3594 n = "InfiniPath_QLE7342_TEST";
3595 dd->flags |= QIB_HAS_QSFP;
3598 n = "InfiniPath_QLE73xy_UNKNOWN";
3599 qib_dev_err(dd, "Unknown 7322 board type %u\n", boardid);
3602 dd->board_atten = 1; /* index into txdds_Xdr */
3604 namelen = strlen(n) + 1;
3605 dd->boardname = kmalloc(namelen, GFP_KERNEL);
3607 qib_dev_err(dd, "Failed allocation for board name: %s\n", n);
3609 snprintf(dd->boardname, namelen, "%s", n);
3611 snprintf(dd->boardversion, sizeof(dd->boardversion),
3612 "ChipABI %u.%u, %s, InfiniPath%u %u.%u, SW Compat %u\n",
3613 QIB_CHIP_VERS_MAJ, QIB_CHIP_VERS_MIN, dd->boardname,
3614 (unsigned)SYM_FIELD(dd->revision, Revision_R, Arch),
3615 dd->majrev, dd->minrev,
3616 (unsigned)SYM_FIELD(dd->revision, Revision_R, SW));
3618 if (qib_singleport && (features >> PORT_SPD_CAP_SHIFT) & PORT_SPD_CAP) {
3619 qib_devinfo(dd->pcidev,
3620 "IB%u: Forced to single port mode by module parameter\n",
3622 features &= PORT_SPD_CAP;
3629 * This routine sleeps, so it can only be called from user context, not
3630 * from interrupt context.
3632 static int qib_do_7322_reset(struct qib_devdata *dd)
3636 int i, msix_entries, ret = 1;
3638 u8 int_line, clinesz;
3639 unsigned long flags;
3641 /* Use dev_err so it shows up in logs, etc. */
3642 qib_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->unit);
3644 qib_pcie_getcmd(dd, &cmdval, &int_line, &clinesz);
3646 msix_entries = dd->cspec->num_msix_entries;
3648 /* no interrupts till re-initted */
3649 qib_7322_set_intr_state(dd, 0);
3652 qib_7322_nomsix(dd);
3653 /* can be up to 512 bytes, too big for stack */
3654 msix_vecsave = kmalloc(2 * dd->cspec->num_msix_entries *
3655 sizeof(u64), GFP_KERNEL);
3657 qib_dev_err(dd, "No mem to save MSIx data\n");
3659 msix_vecsave = NULL;
3662 * Core PCI (as of 2.6.18) doesn't save or rewrite the full vector
3663 * info that is set up by the BIOS, so we have to save and restore
3664 * it ourselves. There is some risk something could change it,
3665 * after we save it, but since we have disabled the MSIx, it
3666 * shouldn't be touched...
3668 for (i = 0; i < msix_entries; i++) {
3669 u64 vecaddr, vecdata;
3670 vecaddr = qib_read_kreg64(dd, 2 * i +
3671 (QIB_7322_MsixTable_OFFS / sizeof(u64)));
3672 vecdata = qib_read_kreg64(dd, 1 + 2 * i +
3673 (QIB_7322_MsixTable_OFFS / sizeof(u64)));
3675 msix_vecsave[2 * i] = vecaddr;
3676 /* save it without the masked bit set */
3677 msix_vecsave[1 + 2 * i] = vecdata & ~0x100000000ULL;
3681 dd->pport->cpspec->ibdeltainprog = 0;
3682 dd->pport->cpspec->ibsymdelta = 0;
3683 dd->pport->cpspec->iblnkerrdelta = 0;
3684 dd->pport->cpspec->ibmalfdelta = 0;
3685 dd->int_counter = 0; /* so we check interrupts work again */
3688 * Keep chip from being accessed until we are ready. Use
3689 * writeq() directly, to allow the write even though QIB_PRESENT
3692 dd->flags &= ~(QIB_INITTED | QIB_PRESENT | QIB_BADINTR);
3693 dd->flags |= QIB_DOING_RESET;
3694 val = dd->control | QLOGIC_IB_C_RESET;
3695 writeq(val, &dd->kregbase[kr_control]);
3697 for (i = 1; i <= 5; i++) {
3699 * Allow MBIST, etc. to complete; longer on each retry.
3700 * We sometimes get machine checks from bus timeout if no
3701 * response, so for now, make it *really* long.
3703 msleep(1000 + (1 + i) * 3000);
3705 qib_pcie_reenable(dd, cmdval, int_line, clinesz);
3708 * Use readq directly, so we don't need to mark it as PRESENT
3709 * until we get a successful indication that all is well.
3711 val = readq(&dd->kregbase[kr_revision]);
3712 if (val == dd->revision)
3716 "Failed to initialize after reset, unusable\n");
3722 dd->flags |= QIB_PRESENT; /* it's back */
3725 /* restore the MSIx vector address and data if saved above */
3726 for (i = 0; i < msix_entries; i++) {
3727 dd->cspec->msix_entries[i].msix.entry = i;
3728 if (!msix_vecsave || !msix_vecsave[2 * i])
3730 qib_write_kreg(dd, 2 * i +
3731 (QIB_7322_MsixTable_OFFS / sizeof(u64)),
3732 msix_vecsave[2 * i]);
3733 qib_write_kreg(dd, 1 + 2 * i +
3734 (QIB_7322_MsixTable_OFFS / sizeof(u64)),
3735 msix_vecsave[1 + 2 * i]);
3739 /* initialize the remaining registers. */
3740 for (i = 0; i < dd->num_pports; ++i)
3741 write_7322_init_portregs(&dd->pport[i]);
3742 write_7322_initregs(dd);
3744 if (qib_pcie_params(dd, dd->lbus_width,
3745 &dd->cspec->num_msix_entries,
3746 dd->cspec->msix_entries))
3748 "Reset failed to setup PCIe or interrupts; continuing anyway\n");
3750 qib_setup_7322_interrupt(dd, 1);
3752 for (i = 0; i < dd->num_pports; ++i) {
3753 struct qib_pportdata *ppd = &dd->pport[i];
3755 spin_lock_irqsave(&ppd->lflags_lock, flags);
3756 ppd->lflags |= QIBL_IB_FORCE_NOTIFY;
3757 ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
3758 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
3762 dd->flags &= ~QIB_DOING_RESET; /* OK or not, no longer resetting */
3763 kfree(msix_vecsave);
3768 * qib_7322_put_tid - write a TID to the chip
3769 * @dd: the qlogic_ib device
3770 * @tidptr: pointer to the expected TID (in chip) to update
3771 * @tidtype: 0 for eager, 1 for expected
3772 * @pa: physical address of in memory buffer; tidinvalid if freeing
3774 static void qib_7322_put_tid(struct qib_devdata *dd, u64 __iomem *tidptr,
3775 u32 type, unsigned long pa)
3777 if (!(dd->flags & QIB_PRESENT))
3779 if (pa != dd->tidinvalid) {
3780 u64 chippa = pa >> IBA7322_TID_PA_SHIFT;
3782 /* paranoia checks */
3783 if (pa != (chippa << IBA7322_TID_PA_SHIFT)) {
3784 qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
3788 if (chippa >= (1UL << IBA7322_TID_SZ_SHIFT)) {
3790 "Physical page address 0x%lx larger than supported\n",
3795 if (type == RCVHQ_RCV_TYPE_EAGER)
3796 chippa |= dd->tidtemplate;
3797 else /* for now, always full 4KB page */
3798 chippa |= IBA7322_TID_SZ_4K;
3806 * qib_7322_clear_tids - clear all TID entries for a ctxt, expected and eager
3807 * @dd: the qlogic_ib device
3810 * clear all TID entries for a ctxt, expected and eager.
3811 * Used from qib_close().
3813 static void qib_7322_clear_tids(struct qib_devdata *dd,
3814 struct qib_ctxtdata *rcd)
3816 u64 __iomem *tidbase;
3817 unsigned long tidinv;
3821 if (!dd->kregbase || !rcd)
3826 tidinv = dd->tidinvalid;
3827 tidbase = (u64 __iomem *)
3828 ((char __iomem *) dd->kregbase +
3830 ctxt * dd->rcvtidcnt * sizeof(*tidbase));
3832 for (i = 0; i < dd->rcvtidcnt; i++)
3833 qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
3836 tidbase = (u64 __iomem *)
3837 ((char __iomem *) dd->kregbase +
3839 rcd->rcvegr_tid_base * sizeof(*tidbase));
3841 for (i = 0; i < rcd->rcvegrcnt; i++)
3842 qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
3847 * qib_7322_tidtemplate - setup constants for TID updates
3848 * @dd: the qlogic_ib device
3850 * We setup stuff that we use a lot, to avoid calculating each time
3852 static void qib_7322_tidtemplate(struct qib_devdata *dd)
3855 * For now, we always allocate 4KB buffers (at init) so we can
3856 * receive max size packets. We may want a module parameter to
3857 * specify 2KB or 4KB and/or make it per port instead of per device
3858 * for those who want to reduce memory footprint. Note that the
3859 * rcvhdrentsize size must be large enough to hold the largest
3860 * IB header (currently 96 bytes) that we expect to handle (plus of
3861 * course the 2 dwords of RHF).
3863 if (dd->rcvegrbufsize == 2048)
3864 dd->tidtemplate = IBA7322_TID_SZ_2K;
3865 else if (dd->rcvegrbufsize == 4096)
3866 dd->tidtemplate = IBA7322_TID_SZ_4K;
3871 * qib_init_7322_get_base_info - set chip-specific flags for user code
3872 * @rcd: the qlogic_ib ctxt
3873 * @kbase: qib_base_info pointer
3875 * We set the PCIE flag because the lower bandwidth on PCIe vs
3876 * HyperTransport can affect some user packet algorithims.
3879 static int qib_7322_get_base_info(struct qib_ctxtdata *rcd,
3880 struct qib_base_info *kinfo)
3882 kinfo->spi_runtime_flags |= QIB_RUNTIME_CTXT_MSB_IN_QP |
3883 QIB_RUNTIME_PCIE | QIB_RUNTIME_NODMA_RTAIL |
3884 QIB_RUNTIME_HDRSUPP | QIB_RUNTIME_SDMA;
3885 if (rcd->dd->cspec->r1)
3886 kinfo->spi_runtime_flags |= QIB_RUNTIME_RCHK;
3887 if (rcd->dd->flags & QIB_USE_SPCL_TRIG)
3888 kinfo->spi_runtime_flags |= QIB_RUNTIME_SPECIAL_TRIGGER;
3893 static struct qib_message_header *
3894 qib_7322_get_msgheader(struct qib_devdata *dd, __le32 *rhf_addr)
3896 u32 offset = qib_hdrget_offset(rhf_addr);
3898 return (struct qib_message_header *)
3899 (rhf_addr - dd->rhf_offset + offset);
3903 * Configure number of contexts.
3905 static void qib_7322_config_ctxts(struct qib_devdata *dd)
3907 unsigned long flags;
3910 nchipctxts = qib_read_kreg32(dd, kr_contextcnt);
3911 dd->cspec->numctxts = nchipctxts;
3912 if (qib_n_krcv_queues > 1 && dd->num_pports) {
3913 dd->first_user_ctxt = NUM_IB_PORTS +
3914 (qib_n_krcv_queues - 1) * dd->num_pports;
3915 if (dd->first_user_ctxt > nchipctxts)
3916 dd->first_user_ctxt = nchipctxts;
3917 dd->n_krcv_queues = dd->first_user_ctxt / dd->num_pports;
3919 dd->first_user_ctxt = NUM_IB_PORTS;
3920 dd->n_krcv_queues = 1;
3923 if (!qib_cfgctxts) {
3924 int nctxts = dd->first_user_ctxt + num_online_cpus();
3928 else if (nctxts <= 10)
3930 else if (nctxts <= nchipctxts)
3931 dd->ctxtcnt = nchipctxts;
3932 } else if (qib_cfgctxts < dd->num_pports)
3933 dd->ctxtcnt = dd->num_pports;
3934 else if (qib_cfgctxts <= nchipctxts)
3935 dd->ctxtcnt = qib_cfgctxts;
3936 if (!dd->ctxtcnt) /* none of the above, set to max */
3937 dd->ctxtcnt = nchipctxts;
3940 * Chip can be configured for 6, 10, or 18 ctxts, and choice
3941 * affects number of eager TIDs per ctxt (1K, 2K, 4K).
3942 * Lock to be paranoid about later motion, etc.
3944 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
3945 if (dd->ctxtcnt > 10)
3946 dd->rcvctrl |= 2ULL << SYM_LSB(RcvCtrl, ContextCfg);
3947 else if (dd->ctxtcnt > 6)
3948 dd->rcvctrl |= 1ULL << SYM_LSB(RcvCtrl, ContextCfg);
3949 /* else configure for default 6 receive ctxts */
3951 /* The XRC opcode is 5. */
3952 dd->rcvctrl |= 5ULL << SYM_LSB(RcvCtrl, XrcTypeCode);
3955 * RcvCtrl *must* be written here so that the
3956 * chip understands how to change rcvegrcnt below.
3958 qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
3959 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
3961 /* kr_rcvegrcnt changes based on the number of contexts enabled */
3962 dd->cspec->rcvegrcnt = qib_read_kreg32(dd, kr_rcvegrcnt);
3964 dd->rcvhdrcnt = max(dd->cspec->rcvegrcnt, qib_rcvhdrcnt);
3966 dd->rcvhdrcnt = 2 * max(dd->cspec->rcvegrcnt,
3967 dd->num_pports > 1 ? 1024U : 2048U);
3970 static int qib_7322_get_ib_cfg(struct qib_pportdata *ppd, int which)
3974 u64 maskr; /* right-justified mask */
3978 case QIB_IB_CFG_LWID_ENB: /* Get allowed Link-width */
3979 ret = ppd->link_width_enabled;
3982 case QIB_IB_CFG_LWID: /* Get currently active Link-width */
3983 ret = ppd->link_width_active;
3986 case QIB_IB_CFG_SPD_ENB: /* Get allowed Link speeds */
3987 ret = ppd->link_speed_enabled;
3990 case QIB_IB_CFG_SPD: /* Get current Link spd */
3991 ret = ppd->link_speed_active;
3994 case QIB_IB_CFG_RXPOL_ENB: /* Get Auto-RX-polarity enable */
3995 lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
3996 maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
3999 case QIB_IB_CFG_LREV_ENB: /* Get Auto-Lane-reversal enable */
4000 lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
4001 maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
4004 case QIB_IB_CFG_LINKLATENCY:
4005 ret = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
4006 SYM_MASK(IBCStatusB_0, LinkRoundTripLatency);
4009 case QIB_IB_CFG_OP_VLS:
4010 ret = ppd->vls_operational;
4013 case QIB_IB_CFG_VL_HIGH_CAP:
4017 case QIB_IB_CFG_VL_LOW_CAP:
4021 case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
4022 ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
4026 case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
4027 ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
4031 case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
4032 /* will only take effect when the link state changes */
4033 ret = (ppd->cpspec->ibcctrl_a &
4034 SYM_MASK(IBCCtrlA_0, LinkDownDefaultState)) ?
4035 IB_LINKINITCMD_SLEEP : IB_LINKINITCMD_POLL;
4038 case QIB_IB_CFG_HRTBT: /* Get Heartbeat off/enable/auto */
4039 lsb = IBA7322_IBC_HRTBT_LSB;
4040 maskr = IBA7322_IBC_HRTBT_RMASK; /* OR of AUTO and ENB */
4043 case QIB_IB_CFG_PMA_TICKS:
4045 * 0x00 = 10x link transfer rate or 4 nsec. for 2.5Gbs
4046 * Since the clock is always 250MHz, the value is 3, 1 or 0.
4048 if (ppd->link_speed_active == QIB_IB_QDR)
4050 else if (ppd->link_speed_active == QIB_IB_DDR)
4060 ret = (int)((ppd->cpspec->ibcctrl_b >> lsb) & maskr);
4066 * Below again cribbed liberally from older version. Do not lean
4069 #define IBA7322_IBC_DLIDLMC_SHIFT QIB_7322_IBCCtrlB_0_IB_DLID_LSB
4070 #define IBA7322_IBC_DLIDLMC_MASK (QIB_7322_IBCCtrlB_0_IB_DLID_RMASK \
4071 | (QIB_7322_IBCCtrlB_0_IB_DLID_MASK_RMASK << 16))
4073 static int qib_7322_set_ib_cfg(struct qib_pportdata *ppd, int which, u32 val)
4075 struct qib_devdata *dd = ppd->dd;
4076 u64 maskr; /* right-justified mask */
4079 unsigned long flags;
4082 case QIB_IB_CFG_LIDLMC:
4084 * Set LID and LMC. Combined to avoid possible hazard
4085 * caller puts LMC in 16MSbits, DLID in 16LSbits of val
4087 lsb = IBA7322_IBC_DLIDLMC_SHIFT;
4088 maskr = IBA7322_IBC_DLIDLMC_MASK;
4090 * For header-checking, the SLID in the packet will
4091 * be masked with SendIBSLMCMask, and compared
4092 * with SendIBSLIDAssignMask. Make sure we do not
4093 * set any bits not covered by the mask, or we get
4096 qib_write_kreg_port(ppd, krp_sendslid,
4097 val & (val >> 16) & SendIBSLIDAssignMask);
4098 qib_write_kreg_port(ppd, krp_sendslidmask,
4099 (val >> 16) & SendIBSLMCMask);
4102 case QIB_IB_CFG_LWID_ENB: /* set allowed Link-width */
4103 ppd->link_width_enabled = val;
4104 /* convert IB value to chip register value */
4105 if (val == IB_WIDTH_1X)
4107 else if (val == IB_WIDTH_4X)
4111 maskr = SYM_RMASK(IBCCtrlB_0, IB_NUM_CHANNELS);
4112 lsb = SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS);
4115 case QIB_IB_CFG_SPD_ENB: /* set allowed Link speeds */
4117 * As with width, only write the actual register if the
4118 * link is currently down, otherwise takes effect on next
4119 * link change. Since setting is being explicitly requested
4120 * (via MAD or sysfs), clear autoneg failure status if speed
4121 * autoneg is enabled.
4123 ppd->link_speed_enabled = val;
4124 val <<= IBA7322_IBC_SPEED_LSB;
4125 maskr = IBA7322_IBC_SPEED_MASK | IBA7322_IBC_IBTA_1_2_MASK |
4126 IBA7322_IBC_MAX_SPEED_MASK;
4127 if (val & (val - 1)) {
4128 /* Muliple speeds enabled */
4129 val |= IBA7322_IBC_IBTA_1_2_MASK |
4130 IBA7322_IBC_MAX_SPEED_MASK;
4131 spin_lock_irqsave(&ppd->lflags_lock, flags);
4132 ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
4133 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
4134 } else if (val & IBA7322_IBC_SPEED_QDR)
4135 val |= IBA7322_IBC_IBTA_1_2_MASK;
4136 /* IBTA 1.2 mode + min/max + speed bits are contiguous */
4137 lsb = SYM_LSB(IBCCtrlB_0, IB_ENHANCED_MODE);
4140 case QIB_IB_CFG_RXPOL_ENB: /* set Auto-RX-polarity enable */
4141 lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
4142 maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
4145 case QIB_IB_CFG_LREV_ENB: /* set Auto-Lane-reversal enable */
4146 lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
4147 maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
4150 case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
4151 maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
4154 ppd->cpspec->ibcctrl_a &=
4155 ~SYM_MASK(IBCCtrlA_0, OverrunThreshold);
4156 ppd->cpspec->ibcctrl_a |= (u64) val <<
4157 SYM_LSB(IBCCtrlA_0, OverrunThreshold);
4158 qib_write_kreg_port(ppd, krp_ibcctrl_a,
4159 ppd->cpspec->ibcctrl_a);
4160 qib_write_kreg(dd, kr_scratch, 0ULL);
4164 case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
4165 maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
4168 ppd->cpspec->ibcctrl_a &=
4169 ~SYM_MASK(IBCCtrlA_0, PhyerrThreshold);
4170 ppd->cpspec->ibcctrl_a |= (u64) val <<
4171 SYM_LSB(IBCCtrlA_0, PhyerrThreshold);
4172 qib_write_kreg_port(ppd, krp_ibcctrl_a,
4173 ppd->cpspec->ibcctrl_a);
4174 qib_write_kreg(dd, kr_scratch, 0ULL);
4178 case QIB_IB_CFG_PKEYS: /* update pkeys */
4179 maskr = (u64) ppd->pkeys[0] | ((u64) ppd->pkeys[1] << 16) |
4180 ((u64) ppd->pkeys[2] << 32) |
4181 ((u64) ppd->pkeys[3] << 48);
4182 qib_write_kreg_port(ppd, krp_partitionkey, maskr);
4185 case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
4186 /* will only take effect when the link state changes */
4187 if (val == IB_LINKINITCMD_POLL)
4188 ppd->cpspec->ibcctrl_a &=
4189 ~SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
4191 ppd->cpspec->ibcctrl_a |=
4192 SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
4193 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
4194 qib_write_kreg(dd, kr_scratch, 0ULL);
4197 case QIB_IB_CFG_MTU: /* update the MTU in IBC */
4199 * Update our housekeeping variables, and set IBC max
4200 * size, same as init code; max IBC is max we allow in
4201 * buffer, less the qword pbc, plus 1 for ICRC, in dwords
4202 * Set even if it's unchanged, print debug message only
4205 val = (ppd->ibmaxlen >> 2) + 1;
4206 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, MaxPktLen);
4207 ppd->cpspec->ibcctrl_a |= (u64)val <<
4208 SYM_LSB(IBCCtrlA_0, MaxPktLen);
4209 qib_write_kreg_port(ppd, krp_ibcctrl_a,
4210 ppd->cpspec->ibcctrl_a);
4211 qib_write_kreg(dd, kr_scratch, 0ULL);
4214 case QIB_IB_CFG_LSTATE: /* set the IB link state */
4215 switch (val & 0xffff0000) {
4216 case IB_LINKCMD_DOWN:
4217 lcmd = QLOGIC_IB_IBCC_LINKCMD_DOWN;
4218 ppd->cpspec->ibmalfusesnap = 1;
4219 ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
4221 if (!ppd->cpspec->ibdeltainprog &&
4222 qib_compat_ddr_negotiate) {
4223 ppd->cpspec->ibdeltainprog = 1;
4224 ppd->cpspec->ibsymsnap =
4225 read_7322_creg32_port(ppd,
4227 ppd->cpspec->iblnkerrsnap =
4228 read_7322_creg32_port(ppd,
4229 crp_iblinkerrrecov);
4233 case IB_LINKCMD_ARMED:
4234 lcmd = QLOGIC_IB_IBCC_LINKCMD_ARMED;
4235 if (ppd->cpspec->ibmalfusesnap) {
4236 ppd->cpspec->ibmalfusesnap = 0;
4237 ppd->cpspec->ibmalfdelta +=
4238 read_7322_creg32_port(ppd,
4240 ppd->cpspec->ibmalfsnap;
4244 case IB_LINKCMD_ACTIVE:
4245 lcmd = QLOGIC_IB_IBCC_LINKCMD_ACTIVE;
4250 qib_dev_err(dd, "bad linkcmd req 0x%x\n", val >> 16);
4253 switch (val & 0xffff) {
4254 case IB_LINKINITCMD_NOP:
4258 case IB_LINKINITCMD_POLL:
4259 licmd = QLOGIC_IB_IBCC_LINKINITCMD_POLL;
4262 case IB_LINKINITCMD_SLEEP:
4263 licmd = QLOGIC_IB_IBCC_LINKINITCMD_SLEEP;
4266 case IB_LINKINITCMD_DISABLE:
4267 licmd = QLOGIC_IB_IBCC_LINKINITCMD_DISABLE;
4268 ppd->cpspec->chase_end = 0;
4270 * stop state chase counter and timer, if running.
4271 * wait forpending timer, but don't clear .data (ppd)!
4273 if (ppd->cpspec->chase_timer.expires) {
4274 del_timer_sync(&ppd->cpspec->chase_timer);
4275 ppd->cpspec->chase_timer.expires = 0;
4281 qib_dev_err(dd, "bad linkinitcmd req 0x%x\n",
4285 qib_set_ib_7322_lstate(ppd, lcmd, licmd);
4288 case QIB_IB_CFG_OP_VLS:
4289 if (ppd->vls_operational != val) {
4290 ppd->vls_operational = val;
4295 case QIB_IB_CFG_VL_HIGH_LIMIT:
4296 qib_write_kreg_port(ppd, krp_highprio_limit, val);
4299 case QIB_IB_CFG_HRTBT: /* set Heartbeat off/enable/auto */
4304 lsb = IBA7322_IBC_HRTBT_LSB;
4305 maskr = IBA7322_IBC_HRTBT_RMASK; /* OR of AUTO and ENB */
4308 case QIB_IB_CFG_PORT:
4309 /* val is the port number of the switch we are connected to. */
4310 if (ppd->dd->cspec->r1) {
4311 cancel_delayed_work(&ppd->cpspec->ipg_work);
4312 ppd->cpspec->ipg_tries = 0;
4320 ppd->cpspec->ibcctrl_b &= ~(maskr << lsb);
4321 ppd->cpspec->ibcctrl_b |= (((u64) val & maskr) << lsb);
4322 qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
4323 qib_write_kreg(dd, kr_scratch, 0);
4328 static int qib_7322_set_loopback(struct qib_pportdata *ppd, const char *what)
4333 /* only IBC loopback, may add serdes and xgxs loopbacks later */
4334 if (!strncmp(what, "ibc", 3)) {
4335 ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0,
4337 val = 0; /* disable heart beat, so link will come up */
4338 qib_devinfo(ppd->dd->pcidev, "Enabling IB%u:%u IBC loopback\n",
4339 ppd->dd->unit, ppd->port);
4340 } else if (!strncmp(what, "off", 3)) {
4341 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0,
4343 /* enable heart beat again */
4344 val = IBA7322_IBC_HRTBT_RMASK << IBA7322_IBC_HRTBT_LSB;
4345 qib_devinfo(ppd->dd->pcidev,
4346 "Disabling IB%u:%u IBC loopback (normal)\n",
4347 ppd->dd->unit, ppd->port);
4351 qib_write_kreg_port(ppd, krp_ibcctrl_a,
4352 ppd->cpspec->ibcctrl_a);
4353 ctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_HRTBT_MASK
4354 << IBA7322_IBC_HRTBT_LSB);
4355 ppd->cpspec->ibcctrl_b = ctrlb | val;
4356 qib_write_kreg_port(ppd, krp_ibcctrl_b,
4357 ppd->cpspec->ibcctrl_b);
4358 qib_write_kreg(ppd->dd, kr_scratch, 0);
4363 static void get_vl_weights(struct qib_pportdata *ppd, unsigned regno,
4364 struct ib_vl_weight_elem *vl)
4368 for (i = 0; i < 16; i++, regno++, vl++) {
4369 u32 val = qib_read_kreg_port(ppd, regno);
4371 vl->vl = (val >> SYM_LSB(LowPriority0_0, VirtualLane)) &
4372 SYM_RMASK(LowPriority0_0, VirtualLane);
4373 vl->weight = (val >> SYM_LSB(LowPriority0_0, Weight)) &
4374 SYM_RMASK(LowPriority0_0, Weight);
4378 static void set_vl_weights(struct qib_pportdata *ppd, unsigned regno,
4379 struct ib_vl_weight_elem *vl)
4383 for (i = 0; i < 16; i++, regno++, vl++) {
4386 val = ((vl->vl & SYM_RMASK(LowPriority0_0, VirtualLane)) <<
4387 SYM_LSB(LowPriority0_0, VirtualLane)) |
4388 ((vl->weight & SYM_RMASK(LowPriority0_0, Weight)) <<
4389 SYM_LSB(LowPriority0_0, Weight));
4390 qib_write_kreg_port(ppd, regno, val);
4392 if (!(ppd->p_sendctrl & SYM_MASK(SendCtrl_0, IBVLArbiterEn))) {
4393 struct qib_devdata *dd = ppd->dd;
4394 unsigned long flags;
4396 spin_lock_irqsave(&dd->sendctrl_lock, flags);
4397 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, IBVLArbiterEn);
4398 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
4399 qib_write_kreg(dd, kr_scratch, 0);
4400 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
4404 static int qib_7322_get_ib_table(struct qib_pportdata *ppd, int which, void *t)
4407 case QIB_IB_TBL_VL_HIGH_ARB:
4408 get_vl_weights(ppd, krp_highprio_0, t);
4411 case QIB_IB_TBL_VL_LOW_ARB:
4412 get_vl_weights(ppd, krp_lowprio_0, t);
4421 static int qib_7322_set_ib_table(struct qib_pportdata *ppd, int which, void *t)
4424 case QIB_IB_TBL_VL_HIGH_ARB:
4425 set_vl_weights(ppd, krp_highprio_0, t);
4428 case QIB_IB_TBL_VL_LOW_ARB:
4429 set_vl_weights(ppd, krp_lowprio_0, t);
4438 static void qib_update_7322_usrhead(struct qib_ctxtdata *rcd, u64 hd,
4439 u32 updegr, u32 egrhd, u32 npkts)
4442 * Need to write timeout register before updating rcvhdrhead to ensure
4443 * that the timer is enabled on reception of a packet.
4445 if (hd >> IBA7322_HDRHEAD_PKTINT_SHIFT)
4446 adjust_rcv_timeout(rcd, npkts);
4448 qib_write_ureg(rcd->dd, ur_rcvegrindexhead, egrhd, rcd->ctxt);
4450 qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
4451 qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
4455 static u32 qib_7322_hdrqempty(struct qib_ctxtdata *rcd)
4459 head = qib_read_ureg32(rcd->dd, ur_rcvhdrhead, rcd->ctxt);
4460 if (rcd->rcvhdrtail_kvaddr)
4461 tail = qib_get_rcvhdrtail(rcd);
4463 tail = qib_read_ureg32(rcd->dd, ur_rcvhdrtail, rcd->ctxt);
4464 return head == tail;
4467 #define RCVCTRL_COMMON_MODS (QIB_RCVCTRL_CTXT_ENB | \
4468 QIB_RCVCTRL_CTXT_DIS | \
4469 QIB_RCVCTRL_TIDFLOW_ENB | \
4470 QIB_RCVCTRL_TIDFLOW_DIS | \
4471 QIB_RCVCTRL_TAILUPD_ENB | \
4472 QIB_RCVCTRL_TAILUPD_DIS | \
4473 QIB_RCVCTRL_INTRAVAIL_ENB | \
4474 QIB_RCVCTRL_INTRAVAIL_DIS | \
4475 QIB_RCVCTRL_BP_ENB | \
4478 #define RCVCTRL_PORT_MODS (QIB_RCVCTRL_CTXT_ENB | \
4479 QIB_RCVCTRL_CTXT_DIS | \
4480 QIB_RCVCTRL_PKEY_DIS | \
4481 QIB_RCVCTRL_PKEY_ENB)
4484 * Modify the RCVCTRL register in chip-specific way. This
4485 * is a function because bit positions and (future) register
4486 * location is chip-specifc, but the needed operations are
4487 * generic. <op> is a bit-mask because we often want to
4488 * do multiple modifications.
4490 static void rcvctrl_7322_mod(struct qib_pportdata *ppd, unsigned int op,
4493 struct qib_devdata *dd = ppd->dd;
4494 struct qib_ctxtdata *rcd;
4496 unsigned long flags;
4498 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
4500 if (op & QIB_RCVCTRL_TIDFLOW_ENB)
4501 dd->rcvctrl |= SYM_MASK(RcvCtrl, TidFlowEnable);
4502 if (op & QIB_RCVCTRL_TIDFLOW_DIS)
4503 dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TidFlowEnable);
4504 if (op & QIB_RCVCTRL_TAILUPD_ENB)
4505 dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
4506 if (op & QIB_RCVCTRL_TAILUPD_DIS)
4507 dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TailUpd);
4508 if (op & QIB_RCVCTRL_PKEY_ENB)
4509 ppd->p_rcvctrl &= ~SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
4510 if (op & QIB_RCVCTRL_PKEY_DIS)
4511 ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
4513 mask = (1ULL << dd->ctxtcnt) - 1;
4516 mask = (1ULL << ctxt);
4517 rcd = dd->rcd[ctxt];
4519 if ((op & QIB_RCVCTRL_CTXT_ENB) && rcd) {
4521 (mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
4522 if (!(dd->flags & QIB_NODMA_RTAIL)) {
4523 op |= QIB_RCVCTRL_TAILUPD_ENB; /* need reg write */
4524 dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
4526 /* Write these registers before the context is enabled. */
4527 qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt,
4528 rcd->rcvhdrqtailaddr_phys);
4529 qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt,
4533 if (op & QIB_RCVCTRL_CTXT_DIS)
4535 ~(mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
4536 if (op & QIB_RCVCTRL_BP_ENB)
4537 dd->rcvctrl |= mask << SYM_LSB(RcvCtrl, dontDropRHQFull);
4538 if (op & QIB_RCVCTRL_BP_DIS)
4539 dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, dontDropRHQFull));
4540 if (op & QIB_RCVCTRL_INTRAVAIL_ENB)
4541 dd->rcvctrl |= (mask << SYM_LSB(RcvCtrl, IntrAvail));
4542 if (op & QIB_RCVCTRL_INTRAVAIL_DIS)
4543 dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, IntrAvail));
4545 * Decide which registers to write depending on the ops enabled.
4546 * Special case is "flush" (no bits set at all)
4547 * which needs to write both.
4549 if (op == 0 || (op & RCVCTRL_COMMON_MODS))
4550 qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
4551 if (op == 0 || (op & RCVCTRL_PORT_MODS))
4552 qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
4553 if ((op & QIB_RCVCTRL_CTXT_ENB) && dd->rcd[ctxt]) {
4555 * Init the context registers also; if we were
4556 * disabled, tail and head should both be zero
4557 * already from the enable, but since we don't
4558 * know, we have to do it explicitly.
4560 val = qib_read_ureg32(dd, ur_rcvegrindextail, ctxt);
4561 qib_write_ureg(dd, ur_rcvegrindexhead, val, ctxt);
4563 /* be sure enabling write seen; hd/tl should be 0 */
4564 (void) qib_read_kreg32(dd, kr_scratch);
4565 val = qib_read_ureg32(dd, ur_rcvhdrtail, ctxt);
4566 dd->rcd[ctxt]->head = val;
4567 /* If kctxt, interrupt on next receive. */
4568 if (ctxt < dd->first_user_ctxt)
4569 val |= dd->rhdrhead_intr_off;
4570 qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
4571 } else if ((op & QIB_RCVCTRL_INTRAVAIL_ENB) &&
4572 dd->rcd[ctxt] && dd->rhdrhead_intr_off) {
4573 /* arm rcv interrupt */
4574 val = dd->rcd[ctxt]->head | dd->rhdrhead_intr_off;
4575 qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
4577 if (op & QIB_RCVCTRL_CTXT_DIS) {
4580 /* Now that the context is disabled, clear these registers. */
4582 qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt, 0);
4583 qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt, 0);
4584 for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
4585 qib_write_ureg(dd, ur_rcvflowtable + f,
4586 TIDFLOW_ERRBITS, ctxt);
4590 for (i = 0; i < dd->cfgctxts; i++) {
4591 qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr,
4593 qib_write_kreg_ctxt(dd, krc_rcvhdraddr, i, 0);
4594 for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
4595 qib_write_ureg(dd, ur_rcvflowtable + f,
4596 TIDFLOW_ERRBITS, i);
4600 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
4604 * Modify the SENDCTRL register in chip-specific way. This
4605 * is a function where there are multiple such registers with
4606 * slightly different layouts.
4607 * The chip doesn't allow back-to-back sendctrl writes, so write
4608 * the scratch register after writing sendctrl.
4610 * Which register is written depends on the operation.
4611 * Most operate on the common register, while
4612 * SEND_ENB and SEND_DIS operate on the per-port ones.
4613 * SEND_ENB is included in common because it can change SPCL_TRIG
4615 #define SENDCTRL_COMMON_MODS (\
4616 QIB_SENDCTRL_CLEAR | \
4617 QIB_SENDCTRL_AVAIL_DIS | \
4618 QIB_SENDCTRL_AVAIL_ENB | \
4619 QIB_SENDCTRL_AVAIL_BLIP | \
4620 QIB_SENDCTRL_DISARM | \
4621 QIB_SENDCTRL_DISARM_ALL | \
4622 QIB_SENDCTRL_SEND_ENB)
4624 #define SENDCTRL_PORT_MODS (\
4625 QIB_SENDCTRL_CLEAR | \
4626 QIB_SENDCTRL_SEND_ENB | \
4627 QIB_SENDCTRL_SEND_DIS | \
4630 static void sendctrl_7322_mod(struct qib_pportdata *ppd, u32 op)
4632 struct qib_devdata *dd = ppd->dd;
4633 u64 tmp_dd_sendctrl;
4634 unsigned long flags;
4636 spin_lock_irqsave(&dd->sendctrl_lock, flags);
4638 /* First the dd ones that are "sticky", saved in shadow */
4639 if (op & QIB_SENDCTRL_CLEAR)
4641 if (op & QIB_SENDCTRL_AVAIL_DIS)
4642 dd->sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
4643 else if (op & QIB_SENDCTRL_AVAIL_ENB) {
4644 dd->sendctrl |= SYM_MASK(SendCtrl, SendBufAvailUpd);
4645 if (dd->flags & QIB_USE_SPCL_TRIG)
4646 dd->sendctrl |= SYM_MASK(SendCtrl, SpecialTriggerEn);
4649 /* Then the ppd ones that are "sticky", saved in shadow */
4650 if (op & QIB_SENDCTRL_SEND_DIS)
4651 ppd->p_sendctrl &= ~SYM_MASK(SendCtrl_0, SendEnable);
4652 else if (op & QIB_SENDCTRL_SEND_ENB)
4653 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, SendEnable);
4655 if (op & QIB_SENDCTRL_DISARM_ALL) {
4658 tmp_dd_sendctrl = dd->sendctrl;
4659 last = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
4661 * Disarm any buffers that are not yet launched,
4662 * disabling updates until done.
4664 tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
4665 for (i = 0; i < last; i++) {
4666 qib_write_kreg(dd, kr_sendctrl,
4668 SYM_MASK(SendCtrl, Disarm) | i);
4669 qib_write_kreg(dd, kr_scratch, 0);
4673 if (op & QIB_SENDCTRL_FLUSH) {
4674 u64 tmp_ppd_sendctrl = ppd->p_sendctrl;
4677 * Now drain all the fifos. The Abort bit should never be
4678 * needed, so for now, at least, we don't use it.
4681 SYM_MASK(SendCtrl_0, TxeDrainRmFifo) |
4682 SYM_MASK(SendCtrl_0, TxeDrainLaFifo) |
4683 SYM_MASK(SendCtrl_0, TxeBypassIbc);
4684 qib_write_kreg_port(ppd, krp_sendctrl, tmp_ppd_sendctrl);
4685 qib_write_kreg(dd, kr_scratch, 0);
4688 tmp_dd_sendctrl = dd->sendctrl;
4690 if (op & QIB_SENDCTRL_DISARM)
4691 tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Disarm) |
4692 ((op & QIB_7322_SendCtrl_DisarmSendBuf_RMASK) <<
4693 SYM_LSB(SendCtrl, DisarmSendBuf));
4694 if ((op & QIB_SENDCTRL_AVAIL_BLIP) &&
4695 (dd->sendctrl & SYM_MASK(SendCtrl, SendBufAvailUpd)))
4696 tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
4698 if (op == 0 || (op & SENDCTRL_COMMON_MODS)) {
4699 qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl);
4700 qib_write_kreg(dd, kr_scratch, 0);
4703 if (op == 0 || (op & SENDCTRL_PORT_MODS)) {
4704 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
4705 qib_write_kreg(dd, kr_scratch, 0);
4708 if (op & QIB_SENDCTRL_AVAIL_BLIP) {
4709 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
4710 qib_write_kreg(dd, kr_scratch, 0);
4713 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
4715 if (op & QIB_SENDCTRL_FLUSH) {
4718 * ensure writes have hit chip, then do a few
4719 * more reads, to allow DMA of pioavail registers
4720 * to occur, so in-memory copy is in sync with
4721 * the chip. Not always safe to sleep.
4723 v = qib_read_kreg32(dd, kr_scratch);
4724 qib_write_kreg(dd, kr_scratch, v);
4725 v = qib_read_kreg32(dd, kr_scratch);
4726 qib_write_kreg(dd, kr_scratch, v);
4727 qib_read_kreg32(dd, kr_scratch);
4731 #define _PORT_VIRT_FLAG 0x8000U /* "virtual", need adjustments */
4732 #define _PORT_64BIT_FLAG 0x10000U /* not "virtual", but 64bit */
4733 #define _PORT_CNTR_IDXMASK 0x7fffU /* mask off flags above */
4736 * qib_portcntr_7322 - read a per-port chip counter
4737 * @ppd: the qlogic_ib pport
4738 * @creg: the counter to read (not a chip offset)
4740 static u64 qib_portcntr_7322(struct qib_pportdata *ppd, u32 reg)
4742 struct qib_devdata *dd = ppd->dd;
4745 /* 0xffff for unimplemented or synthesized counters */
4746 static const u32 xlator[] = {
4747 [QIBPORTCNTR_PKTSEND] = crp_pktsend | _PORT_64BIT_FLAG,
4748 [QIBPORTCNTR_WORDSEND] = crp_wordsend | _PORT_64BIT_FLAG,
4749 [QIBPORTCNTR_PSXMITDATA] = crp_psxmitdatacount,
4750 [QIBPORTCNTR_PSXMITPKTS] = crp_psxmitpktscount,
4751 [QIBPORTCNTR_PSXMITWAIT] = crp_psxmitwaitcount,
4752 [QIBPORTCNTR_SENDSTALL] = crp_sendstall,
4753 [QIBPORTCNTR_PKTRCV] = crp_pktrcv | _PORT_64BIT_FLAG,
4754 [QIBPORTCNTR_PSRCVDATA] = crp_psrcvdatacount,
4755 [QIBPORTCNTR_PSRCVPKTS] = crp_psrcvpktscount,
4756 [QIBPORTCNTR_RCVEBP] = crp_rcvebp,
4757 [QIBPORTCNTR_RCVOVFL] = crp_rcvovfl,
4758 [QIBPORTCNTR_WORDRCV] = crp_wordrcv | _PORT_64BIT_FLAG,
4759 [QIBPORTCNTR_RXDROPPKT] = 0xffff, /* not needed for 7322 */
4760 [QIBPORTCNTR_RXLOCALPHYERR] = crp_rxotherlocalphyerr,
4761 [QIBPORTCNTR_RXVLERR] = crp_rxvlerr,
4762 [QIBPORTCNTR_ERRICRC] = crp_erricrc,
4763 [QIBPORTCNTR_ERRVCRC] = crp_errvcrc,
4764 [QIBPORTCNTR_ERRLPCRC] = crp_errlpcrc,
4765 [QIBPORTCNTR_BADFORMAT] = crp_badformat,
4766 [QIBPORTCNTR_ERR_RLEN] = crp_err_rlen,
4767 [QIBPORTCNTR_IBSYMBOLERR] = crp_ibsymbolerr,
4768 [QIBPORTCNTR_INVALIDRLEN] = crp_invalidrlen,
4769 [QIBPORTCNTR_UNSUPVL] = crp_txunsupvl,
4770 [QIBPORTCNTR_EXCESSBUFOVFL] = crp_excessbufferovfl,
4771 [QIBPORTCNTR_ERRLINK] = crp_errlink,
4772 [QIBPORTCNTR_IBLINKDOWN] = crp_iblinkdown,
4773 [QIBPORTCNTR_IBLINKERRRECOV] = crp_iblinkerrrecov,
4774 [QIBPORTCNTR_LLI] = crp_locallinkintegrityerr,
4775 [QIBPORTCNTR_VL15PKTDROP] = crp_vl15droppedpkt,
4776 [QIBPORTCNTR_ERRPKEY] = crp_errpkey,
4778 * the next 3 aren't really counters, but were implemented
4779 * as counters in older chips, so still get accessed as
4780 * though they were counters from this code.
4782 [QIBPORTCNTR_PSINTERVAL] = krp_psinterval,
4783 [QIBPORTCNTR_PSSTART] = krp_psstart,
4784 [QIBPORTCNTR_PSSTAT] = krp_psstat,
4785 /* pseudo-counter, summed for all ports */
4786 [QIBPORTCNTR_KHDROVFL] = 0xffff,
4789 if (reg >= ARRAY_SIZE(xlator)) {
4790 qib_devinfo(ppd->dd->pcidev,
4791 "Unimplemented portcounter %u\n", reg);
4794 creg = xlator[reg] & _PORT_CNTR_IDXMASK;
4796 /* handle non-counters and special cases first */
4797 if (reg == QIBPORTCNTR_KHDROVFL) {
4800 /* sum over all kernel contexts (skip if mini_init) */
4801 for (i = 0; dd->rcd && i < dd->first_user_ctxt; i++) {
4802 struct qib_ctxtdata *rcd = dd->rcd[i];
4804 if (!rcd || rcd->ppd != ppd)
4806 ret += read_7322_creg32(dd, cr_base_egrovfl + i);
4809 } else if (reg == QIBPORTCNTR_RXDROPPKT) {
4811 * Used as part of the synthesis of port_rcv_errors
4812 * in the verbs code for IBTA counters. Not needed for 7322,
4813 * because all the errors are already counted by other cntrs.
4816 } else if (reg == QIBPORTCNTR_PSINTERVAL ||
4817 reg == QIBPORTCNTR_PSSTART || reg == QIBPORTCNTR_PSSTAT) {
4818 /* were counters in older chips, now per-port kernel regs */
4819 ret = qib_read_kreg_port(ppd, creg);
4824 * Only fast increment counters are 64 bits; use 32 bit reads to
4825 * avoid two independent reads when on Opteron.
4827 if (xlator[reg] & _PORT_64BIT_FLAG)
4828 ret = read_7322_creg_port(ppd, creg);
4830 ret = read_7322_creg32_port(ppd, creg);
4831 if (creg == crp_ibsymbolerr) {
4832 if (ppd->cpspec->ibdeltainprog)
4833 ret -= ret - ppd->cpspec->ibsymsnap;
4834 ret -= ppd->cpspec->ibsymdelta;
4835 } else if (creg == crp_iblinkerrrecov) {
4836 if (ppd->cpspec->ibdeltainprog)
4837 ret -= ret - ppd->cpspec->iblnkerrsnap;
4838 ret -= ppd->cpspec->iblnkerrdelta;
4839 } else if (creg == crp_errlink)
4840 ret -= ppd->cpspec->ibmalfdelta;
4841 else if (creg == crp_iblinkdown)
4842 ret += ppd->cpspec->iblnkdowndelta;
4848 * Device counter names (not port-specific), one line per stat,
4849 * single string. Used by utilities like ipathstats to print the stats
4850 * in a way which works for different versions of drivers, without changing
4851 * the utility. Names need to be 12 chars or less (w/o newline), for proper
4852 * display by utility.
4853 * Non-error counters are first.
4854 * Start of "error" conters is indicated by a leading "E " on the first
4855 * "error" counter, and doesn't count in label length.
4856 * The EgrOvfl list needs to be last so we truncate them at the configured
4857 * context count for the device.
4858 * cntr7322indices contains the corresponding register indices.
4860 static const char cntr7322names[] =
4865 "RxTIDFloDrop\n" /* 7322 only */
4886 static const u32 cntr7322indices[] = {
4887 cr_lbint | _PORT_64BIT_FLAG,
4888 cr_lbstall | _PORT_64BIT_FLAG,
4892 cr_base_egrovfl + 0,
4893 cr_base_egrovfl + 1,
4894 cr_base_egrovfl + 2,
4895 cr_base_egrovfl + 3,
4896 cr_base_egrovfl + 4,
4897 cr_base_egrovfl + 5,
4898 cr_base_egrovfl + 6,
4899 cr_base_egrovfl + 7,
4900 cr_base_egrovfl + 8,
4901 cr_base_egrovfl + 9,
4902 cr_base_egrovfl + 10,
4903 cr_base_egrovfl + 11,
4904 cr_base_egrovfl + 12,
4905 cr_base_egrovfl + 13,
4906 cr_base_egrovfl + 14,
4907 cr_base_egrovfl + 15,
4908 cr_base_egrovfl + 16,
4909 cr_base_egrovfl + 17,
4913 * same as cntr7322names and cntr7322indices, but for port-specific counters.
4914 * portcntr7322indices is somewhat complicated by some registers needing
4915 * adjustments of various kinds, and those are ORed with _PORT_VIRT_FLAG
4917 static const char portcntr7322names[] =
4925 "TxDmaDesc\n" /* 7220 and 7322-only */
4926 "E RxDlidFltr\n" /* 7220 and 7322-only */
4949 "RxLclPhyErr\n" /* 7220 and 7322-only from here down */
4953 "RxQPBadCtxt\n" /* 7322-only from here down */
4957 static const u32 portcntr7322indices[] = {
4958 QIBPORTCNTR_PKTSEND | _PORT_VIRT_FLAG,
4960 QIBPORTCNTR_WORDSEND | _PORT_VIRT_FLAG,
4961 QIBPORTCNTR_PKTRCV | _PORT_VIRT_FLAG,
4963 QIBPORTCNTR_WORDRCV | _PORT_VIRT_FLAG,
4964 QIBPORTCNTR_SENDSTALL | _PORT_VIRT_FLAG,
4965 crp_txsdmadesc | _PORT_64BIT_FLAG,
4968 QIBPORTCNTR_IBLINKDOWN | _PORT_VIRT_FLAG,
4969 QIBPORTCNTR_IBLINKERRRECOV | _PORT_VIRT_FLAG,
4970 QIBPORTCNTR_ERRLINK | _PORT_VIRT_FLAG,
4971 QIBPORTCNTR_IBSYMBOLERR | _PORT_VIRT_FLAG,
4972 QIBPORTCNTR_LLI | _PORT_VIRT_FLAG,
4973 QIBPORTCNTR_BADFORMAT | _PORT_VIRT_FLAG,
4974 QIBPORTCNTR_ERR_RLEN | _PORT_VIRT_FLAG,
4975 QIBPORTCNTR_RCVOVFL | _PORT_VIRT_FLAG,
4976 QIBPORTCNTR_RCVEBP | _PORT_VIRT_FLAG,
4977 crp_rcvflowctrlviol,
4978 QIBPORTCNTR_ERRICRC | _PORT_VIRT_FLAG,
4979 QIBPORTCNTR_ERRLPCRC | _PORT_VIRT_FLAG,
4980 QIBPORTCNTR_ERRVCRC | _PORT_VIRT_FLAG,
4981 QIBPORTCNTR_INVALIDRLEN | _PORT_VIRT_FLAG,
4982 QIBPORTCNTR_ERRPKEY | _PORT_VIRT_FLAG,
4983 QIBPORTCNTR_RXDROPPKT | _PORT_VIRT_FLAG,
4989 QIBPORTCNTR_RXLOCALPHYERR | _PORT_VIRT_FLAG,
4990 QIBPORTCNTR_VL15PKTDROP | _PORT_VIRT_FLAG,
4991 QIBPORTCNTR_RXVLERR | _PORT_VIRT_FLAG,
4992 QIBPORTCNTR_EXCESSBUFOVFL | _PORT_VIRT_FLAG,
4993 crp_rxqpinvalidctxt,
4997 /* do all the setup to make the counter reads efficient later */
4998 static void init_7322_cntrnames(struct qib_devdata *dd)
5003 for (i = 0, s = (char *)cntr7322names; s && j <= dd->cfgctxts;
5005 /* we always have at least one counter before the egrovfl */
5006 if (!j && !strncmp("Ctxt0EgrOvfl", s + 1, 12))
5008 s = strchr(s + 1, '\n');
5012 dd->cspec->ncntrs = i;
5014 /* full list; size is without terminating null */
5015 dd->cspec->cntrnamelen = sizeof(cntr7322names) - 1;
5017 dd->cspec->cntrnamelen = 1 + s - cntr7322names;
5018 dd->cspec->cntrs = kmalloc(dd->cspec->ncntrs
5019 * sizeof(u64), GFP_KERNEL);
5020 if (!dd->cspec->cntrs)
5021 qib_dev_err(dd, "Failed allocation for counters\n");
5023 for (i = 0, s = (char *)portcntr7322names; s; i++)
5024 s = strchr(s + 1, '\n');
5025 dd->cspec->nportcntrs = i - 1;
5026 dd->cspec->portcntrnamelen = sizeof(portcntr7322names) - 1;
5027 for (i = 0; i < dd->num_pports; ++i) {
5028 dd->pport[i].cpspec->portcntrs = kmalloc(dd->cspec->nportcntrs
5029 * sizeof(u64), GFP_KERNEL);
5030 if (!dd->pport[i].cpspec->portcntrs)
5032 "Failed allocation for portcounters\n");
5036 static u32 qib_read_7322cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
5042 ret = dd->cspec->cntrnamelen;
5044 ret = 0; /* final read after getting everything */
5046 *namep = (char *) cntr7322names;
5048 u64 *cntr = dd->cspec->cntrs;
5051 ret = dd->cspec->ncntrs * sizeof(u64);
5052 if (!cntr || pos >= ret) {
5053 /* everything read, or couldn't get memory */
5058 for (i = 0; i < dd->cspec->ncntrs; i++)
5059 if (cntr7322indices[i] & _PORT_64BIT_FLAG)
5060 *cntr++ = read_7322_creg(dd,
5061 cntr7322indices[i] &
5062 _PORT_CNTR_IDXMASK);
5064 *cntr++ = read_7322_creg32(dd,
5065 cntr7322indices[i]);
5071 static u32 qib_read_7322portcntrs(struct qib_devdata *dd, loff_t pos, u32 port,
5072 char **namep, u64 **cntrp)
5077 ret = dd->cspec->portcntrnamelen;
5079 ret = 0; /* final read after getting everything */
5081 *namep = (char *)portcntr7322names;
5083 struct qib_pportdata *ppd = &dd->pport[port];
5084 u64 *cntr = ppd->cpspec->portcntrs;
5087 ret = dd->cspec->nportcntrs * sizeof(u64);
5088 if (!cntr || pos >= ret) {
5089 /* everything read, or couldn't get memory */
5094 for (i = 0; i < dd->cspec->nportcntrs; i++) {
5095 if (portcntr7322indices[i] & _PORT_VIRT_FLAG)
5096 *cntr++ = qib_portcntr_7322(ppd,
5097 portcntr7322indices[i] &
5098 _PORT_CNTR_IDXMASK);
5099 else if (portcntr7322indices[i] & _PORT_64BIT_FLAG)
5100 *cntr++ = read_7322_creg_port(ppd,
5101 portcntr7322indices[i] &
5102 _PORT_CNTR_IDXMASK);
5104 *cntr++ = read_7322_creg32_port(ppd,
5105 portcntr7322indices[i]);
5113 * qib_get_7322_faststats - get word counters from chip before they overflow
5114 * @opaque - contains a pointer to the qlogic_ib device qib_devdata
5116 * VESTIGIAL IBA7322 has no "small fast counters", so the only
5117 * real purpose of this function is to maintain the notion of
5118 * "active time", which in turn is only logged into the eeprom,
5119 * which we don;t have, yet, for 7322-based boards.
5121 * called from add_timer
5123 static void qib_get_7322_faststats(unsigned long opaque)
5125 struct qib_devdata *dd = (struct qib_devdata *) opaque;
5126 struct qib_pportdata *ppd;
5127 unsigned long flags;
5131 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
5132 ppd = dd->pport + pidx;
5135 * If port isn't enabled or not operational ports, or
5136 * diags is running (can cause memory diags to fail)
5137 * skip this port this time.
5139 if (!ppd->link_speed_supported || !(dd->flags & QIB_INITTED)
5144 * Maintain an activity timer, based on traffic
5145 * exceeding a threshold, so we need to check the word-counts
5146 * even if they are 64-bit.
5148 traffic_wds = qib_portcntr_7322(ppd, QIBPORTCNTR_WORDRCV) +
5149 qib_portcntr_7322(ppd, QIBPORTCNTR_WORDSEND);
5150 spin_lock_irqsave(&ppd->dd->eep_st_lock, flags);
5151 traffic_wds -= ppd->dd->traffic_wds;
5152 ppd->dd->traffic_wds += traffic_wds;
5153 if (traffic_wds >= QIB_TRAFFIC_ACTIVE_THRESHOLD)
5154 atomic_add(ACTIVITY_TIMER, &ppd->dd->active_time);
5155 spin_unlock_irqrestore(&ppd->dd->eep_st_lock, flags);
5156 if (ppd->cpspec->qdr_dfe_on && (ppd->link_speed_active &
5158 (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
5159 QIBL_LINKACTIVE)) &&
5160 ppd->cpspec->qdr_dfe_time &&
5161 time_is_before_jiffies(ppd->cpspec->qdr_dfe_time)) {
5162 ppd->cpspec->qdr_dfe_on = 0;
5164 qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
5165 ppd->dd->cspec->r1 ?
5166 QDR_STATIC_ADAPT_INIT_R1 :
5167 QDR_STATIC_ADAPT_INIT);
5171 mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);
5175 * If we were using MSIx, try to fallback to INTx.
5177 static int qib_7322_intr_fallback(struct qib_devdata *dd)
5179 if (!dd->cspec->num_msix_entries)
5180 return 0; /* already using INTx */
5182 qib_devinfo(dd->pcidev,
5183 "MSIx interrupt not detected, trying INTx interrupts\n");
5184 qib_7322_nomsix(dd);
5185 qib_enable_intx(dd->pcidev);
5186 qib_setup_7322_interrupt(dd, 0);
5191 * Reset the XGXS (between serdes and IBC). Slightly less intrusive
5192 * than resetting the IBC or external link state, and useful in some
5193 * cases to cause some retraining. To do this right, we reset IBC
5194 * as well, then return to previous state (which may be still in reset)
5195 * NOTE: some callers of this "know" this writes the current value
5196 * of cpspec->ibcctrl_a as part of it's operation, so if that changes,
5197 * check all callers.
5199 static void qib_7322_mini_pcs_reset(struct qib_pportdata *ppd)
5202 struct qib_devdata *dd = ppd->dd;
5203 const u64 reset_bits = SYM_MASK(IBPCSConfig_0, xcv_rreset) |
5204 SYM_MASK(IBPCSConfig_0, xcv_treset) |
5205 SYM_MASK(IBPCSConfig_0, tx_rx_reset);
5207 val = qib_read_kreg_port(ppd, krp_ib_pcsconfig);
5208 qib_write_kreg(dd, kr_hwerrmask,
5209 dd->cspec->hwerrmask & ~HWE_MASK(statusValidNoEop));
5210 qib_write_kreg_port(ppd, krp_ibcctrl_a,
5211 ppd->cpspec->ibcctrl_a &
5212 ~SYM_MASK(IBCCtrlA_0, IBLinkEn));
5214 qib_write_kreg_port(ppd, krp_ib_pcsconfig, val | reset_bits);
5215 qib_read_kreg32(dd, kr_scratch);
5216 qib_write_kreg_port(ppd, krp_ib_pcsconfig, val & ~reset_bits);
5217 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
5218 qib_write_kreg(dd, kr_scratch, 0ULL);
5219 qib_write_kreg(dd, kr_hwerrclear,
5220 SYM_MASK(HwErrClear, statusValidNoEopClear));
5221 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
5225 * This code for non-IBTA-compliant IB speed negotiation is only known to
5226 * work for the SDR to DDR transition, and only between an HCA and a switch
5227 * with recent firmware. It is based on observed heuristics, rather than
5228 * actual knowledge of the non-compliant speed negotiation.
5229 * It has a number of hard-coded fields, since the hope is to rewrite this
5230 * when a spec is available on how the negoation is intended to work.
5232 static void autoneg_7322_sendpkt(struct qib_pportdata *ppd, u32 *hdr,
5233 u32 dcnt, u32 *data)
5237 u32 __iomem *piobuf;
5238 u32 pnum, control, len;
5239 struct qib_devdata *dd = ppd->dd;
5242 len = 7 + dcnt + 1; /* 7 dword header, dword data, icrc */
5243 control = qib_7322_setpbc_control(ppd, len, 0, 15);
5244 pbc = ((u64) control << 32) | len;
5245 while (!(piobuf = qib_7322_getsendbuf(ppd, pbc, &pnum))) {
5250 /* disable header check on this packet, since it can't be valid */
5251 dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_DIS1, NULL);
5252 writeq(pbc, piobuf);
5254 qib_pio_copy(piobuf + 2, hdr, 7);
5255 qib_pio_copy(piobuf + 9, data, dcnt);
5256 if (dd->flags & QIB_USE_SPCL_TRIG) {
5257 u32 spcl_off = (pnum >= dd->piobcnt2k) ? 2047 : 1023;
5260 __raw_writel(0xaebecede, piobuf + spcl_off);
5263 qib_sendbuf_done(dd, pnum);
5264 /* and re-enable hdr check */
5265 dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_ENAB1, NULL);
5269 * _start packet gets sent twice at start, _done gets sent twice at end
5271 static void qib_autoneg_7322_send(struct qib_pportdata *ppd, int which)
5273 struct qib_devdata *dd = ppd->dd;
5275 u32 dw, i, hcnt, dcnt, *data;
5276 static u32 hdr[7] = { 0xf002ffff, 0x48ffff, 0x6400abba };
5277 static u32 madpayload_start[0x40] = {
5278 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
5279 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
5280 0x1, 0x1388, 0x15e, 0x1, /* rest 0's */
5282 static u32 madpayload_done[0x40] = {
5283 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
5284 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
5285 0x40000001, 0x1388, 0x15e, /* rest 0's */
5288 dcnt = ARRAY_SIZE(madpayload_start);
5289 hcnt = ARRAY_SIZE(hdr);
5291 /* for maintainability, do it at runtime */
5292 for (i = 0; i < hcnt; i++) {
5293 dw = (__force u32) cpu_to_be32(hdr[i]);
5296 for (i = 0; i < dcnt; i++) {
5297 dw = (__force u32) cpu_to_be32(madpayload_start[i]);
5298 madpayload_start[i] = dw;
5299 dw = (__force u32) cpu_to_be32(madpayload_done[i]);
5300 madpayload_done[i] = dw;
5305 data = which ? madpayload_done : madpayload_start;
5307 autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
5308 qib_read_kreg64(dd, kr_scratch);
5310 autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
5311 qib_read_kreg64(dd, kr_scratch);
5316 * Do the absolute minimum to cause an IB speed change, and make it
5317 * ready, but don't actually trigger the change. The caller will
5318 * do that when ready (if link is in Polling training state, it will
5319 * happen immediately, otherwise when link next goes down)
5321 * This routine should only be used as part of the DDR autonegotation
5322 * code for devices that are not compliant with IB 1.2 (or code that
5323 * fixes things up for same).
5325 * When link has gone down, and autoneg enabled, or autoneg has
5326 * failed and we give up until next time we set both speeds, and
5327 * then we want IBTA enabled as well as "use max enabled speed.
5329 static void set_7322_ibspeed_fast(struct qib_pportdata *ppd, u32 speed)
5332 newctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_SPEED_MASK |
5333 IBA7322_IBC_IBTA_1_2_MASK |
5334 IBA7322_IBC_MAX_SPEED_MASK);
5336 if (speed & (speed - 1)) /* multiple speeds */
5337 newctrlb |= (speed << IBA7322_IBC_SPEED_LSB) |
5338 IBA7322_IBC_IBTA_1_2_MASK |
5339 IBA7322_IBC_MAX_SPEED_MASK;
5341 newctrlb |= speed == QIB_IB_QDR ?
5342 IBA7322_IBC_SPEED_QDR | IBA7322_IBC_IBTA_1_2_MASK :
5343 ((speed == QIB_IB_DDR ?
5344 IBA7322_IBC_SPEED_DDR : IBA7322_IBC_SPEED_SDR));
5346 if (newctrlb == ppd->cpspec->ibcctrl_b)
5349 ppd->cpspec->ibcctrl_b = newctrlb;
5350 qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
5351 qib_write_kreg(ppd->dd, kr_scratch, 0);
5355 * This routine is only used when we are not talking to another
5356 * IB 1.2-compliant device that we think can do DDR.
5357 * (This includes all existing switch chips as of Oct 2007.)
5358 * 1.2-compliant devices go directly to DDR prior to reaching INIT
5360 static void try_7322_autoneg(struct qib_pportdata *ppd)
5362 unsigned long flags;
5364 spin_lock_irqsave(&ppd->lflags_lock, flags);
5365 ppd->lflags |= QIBL_IB_AUTONEG_INPROG;
5366 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5367 qib_autoneg_7322_send(ppd, 0);
5368 set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
5369 qib_7322_mini_pcs_reset(ppd);
5370 /* 2 msec is minimum length of a poll cycle */
5371 queue_delayed_work(ib_wq, &ppd->cpspec->autoneg_work,
5372 msecs_to_jiffies(2));
5376 * Handle the empirically determined mechanism for auto-negotiation
5377 * of DDR speed with switches.
5379 static void autoneg_7322_work(struct work_struct *work)
5381 struct qib_pportdata *ppd;
5382 struct qib_devdata *dd;
5385 unsigned long flags;
5387 ppd = container_of(work, struct qib_chippport_specific,
5388 autoneg_work.work)->ppd;
5391 startms = jiffies_to_msecs(jiffies);
5394 * Busy wait for this first part, it should be at most a
5395 * few hundred usec, since we scheduled ourselves for 2msec.
5397 for (i = 0; i < 25; i++) {
5398 if (SYM_FIELD(ppd->lastibcstat, IBCStatusA_0, LinkState)
5399 == IB_7322_LT_STATE_POLLQUIET) {
5400 qib_set_linkstate(ppd, QIB_IB_LINKDOWN_DISABLE);
5406 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
5407 goto done; /* we got there early or told to stop */
5409 /* we expect this to timeout */
5410 if (wait_event_timeout(ppd->cpspec->autoneg_wait,
5411 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
5412 msecs_to_jiffies(90)))
5414 qib_7322_mini_pcs_reset(ppd);
5416 /* we expect this to timeout */
5417 if (wait_event_timeout(ppd->cpspec->autoneg_wait,
5418 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
5419 msecs_to_jiffies(1700)))
5421 qib_7322_mini_pcs_reset(ppd);
5423 set_7322_ibspeed_fast(ppd, QIB_IB_SDR);
5426 * Wait up to 250 msec for link to train and get to INIT at DDR;
5427 * this should terminate early.
5429 wait_event_timeout(ppd->cpspec->autoneg_wait,
5430 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
5431 msecs_to_jiffies(250));
5433 if (ppd->lflags & QIBL_IB_AUTONEG_INPROG) {
5434 spin_lock_irqsave(&ppd->lflags_lock, flags);
5435 ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
5436 if (ppd->cpspec->autoneg_tries == AUTONEG_TRIES) {
5437 ppd->lflags |= QIBL_IB_AUTONEG_FAILED;
5438 ppd->cpspec->autoneg_tries = 0;
5440 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5441 set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
5446 * This routine is used to request IPG set in the QLogic switch.
5447 * Only called if r1.
5449 static void try_7322_ipg(struct qib_pportdata *ppd)
5451 struct qib_ibport *ibp = &ppd->ibport_data;
5452 struct ib_mad_send_buf *send_buf;
5453 struct ib_mad_agent *agent;
5458 agent = ibp->send_agent;
5462 send_buf = ib_create_send_mad(agent, 0, 0, 0, IB_MGMT_MAD_HDR,
5463 IB_MGMT_MAD_DATA, GFP_ATOMIC);
5464 if (IS_ERR(send_buf))
5470 ah = qib_create_qp0_ah(ibp, be16_to_cpu(IB_LID_PERMISSIVE));
5475 ibp->smi_ah = to_iah(ah);
5479 send_buf->ah = &ibp->smi_ah->ibah;
5483 smp = send_buf->mad;
5484 smp->base_version = IB_MGMT_BASE_VERSION;
5485 smp->mgmt_class = IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE;
5486 smp->class_version = 1;
5487 smp->method = IB_MGMT_METHOD_SEND;
5489 smp->attr_id = QIB_VENDOR_IPG;
5493 ret = ib_post_send_mad(send_buf, NULL);
5495 ib_free_send_mad(send_buf);
5497 delay = 2 << ppd->cpspec->ipg_tries;
5498 queue_delayed_work(ib_wq, &ppd->cpspec->ipg_work,
5499 msecs_to_jiffies(delay));
5503 * Timeout handler for setting IPG.
5504 * Only called if r1.
5506 static void ipg_7322_work(struct work_struct *work)
5508 struct qib_pportdata *ppd;
5510 ppd = container_of(work, struct qib_chippport_specific,
5511 ipg_work.work)->ppd;
5512 if ((ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED | QIBL_LINKACTIVE))
5513 && ++ppd->cpspec->ipg_tries <= 10)
5517 static u32 qib_7322_iblink_state(u64 ibcs)
5519 u32 state = (u32)SYM_FIELD(ibcs, IBCStatusA_0, LinkState);
5522 case IB_7322_L_STATE_INIT:
5523 state = IB_PORT_INIT;
5525 case IB_7322_L_STATE_ARM:
5526 state = IB_PORT_ARMED;
5528 case IB_7322_L_STATE_ACTIVE:
5530 case IB_7322_L_STATE_ACT_DEFER:
5531 state = IB_PORT_ACTIVE;
5533 default: /* fall through */
5534 case IB_7322_L_STATE_DOWN:
5535 state = IB_PORT_DOWN;
5541 /* returns the IBTA port state, rather than the IBC link training state */
5542 static u8 qib_7322_phys_portstate(u64 ibcs)
5544 u8 state = (u8)SYM_FIELD(ibcs, IBCStatusA_0, LinkTrainingState);
5545 return qib_7322_physportstate[state];
5548 static int qib_7322_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
5550 int ret = 0, symadj = 0;
5551 unsigned long flags;
5554 spin_lock_irqsave(&ppd->lflags_lock, flags);
5555 ppd->lflags &= ~QIBL_IB_FORCE_NOTIFY;
5556 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5558 /* Update our picture of width and speed from chip */
5559 if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedQDR)) {
5560 ppd->link_speed_active = QIB_IB_QDR;
5562 } else if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedActive)) {
5563 ppd->link_speed_active = QIB_IB_DDR;
5566 ppd->link_speed_active = QIB_IB_SDR;
5569 if (ibcs & SYM_MASK(IBCStatusA_0, LinkWidthActive)) {
5570 ppd->link_width_active = IB_WIDTH_4X;
5573 ppd->link_width_active = IB_WIDTH_1X;
5574 ppd->delay_mult = ib_rate_to_delay[mult_to_ib_rate(mult)];
5579 /* Link went down. */
5580 /* do IPG MAD again after linkdown, even if last time failed */
5581 ppd->cpspec->ipg_tries = 0;
5582 clr = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
5583 (SYM_MASK(IBCStatusB_0, heartbeat_timed_out) |
5584 SYM_MASK(IBCStatusB_0, heartbeat_crosstalk));
5586 qib_write_kreg_port(ppd, krp_ibcstatus_b, clr);
5587 if (!(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
5588 QIBL_IB_AUTONEG_INPROG)))
5589 set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
5590 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
5591 struct qib_qsfp_data *qd =
5592 &ppd->cpspec->qsfp_data;
5593 /* unlock the Tx settings, speed may change */
5594 qib_write_kreg_port(ppd, krp_tx_deemph_override,
5595 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
5596 reset_tx_deemphasis_override));
5597 qib_cancel_sends(ppd);
5598 /* on link down, ensure sane pcs state */
5599 qib_7322_mini_pcs_reset(ppd);
5600 /* schedule the qsfp refresh which should turn the link
5602 if (ppd->dd->flags & QIB_HAS_QSFP) {
5603 qd->t_insert = jiffies;
5604 queue_work(ib_wq, &qd->work);
5606 spin_lock_irqsave(&ppd->sdma_lock, flags);
5607 if (__qib_sdma_running(ppd))
5608 __qib_sdma_process_event(ppd,
5609 qib_sdma_event_e70_go_idle);
5610 spin_unlock_irqrestore(&ppd->sdma_lock, flags);
5612 clr = read_7322_creg32_port(ppd, crp_iblinkdown);
5613 if (clr == ppd->cpspec->iblnkdownsnap)
5614 ppd->cpspec->iblnkdowndelta++;
5616 if (qib_compat_ddr_negotiate &&
5617 !(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
5618 QIBL_IB_AUTONEG_INPROG)) &&
5619 ppd->link_speed_active == QIB_IB_SDR &&
5620 (ppd->link_speed_enabled & QIB_IB_DDR)
5621 && ppd->cpspec->autoneg_tries < AUTONEG_TRIES) {
5622 /* we are SDR, and auto-negotiation enabled */
5623 ++ppd->cpspec->autoneg_tries;
5624 if (!ppd->cpspec->ibdeltainprog) {
5625 ppd->cpspec->ibdeltainprog = 1;
5626 ppd->cpspec->ibsymdelta +=
5627 read_7322_creg32_port(ppd,
5629 ppd->cpspec->ibsymsnap;
5630 ppd->cpspec->iblnkerrdelta +=
5631 read_7322_creg32_port(ppd,
5632 crp_iblinkerrrecov) -
5633 ppd->cpspec->iblnkerrsnap;
5635 try_7322_autoneg(ppd);
5636 ret = 1; /* no other IB status change processing */
5637 } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
5638 ppd->link_speed_active == QIB_IB_SDR) {
5639 qib_autoneg_7322_send(ppd, 1);
5640 set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
5641 qib_7322_mini_pcs_reset(ppd);
5643 ret = 1; /* no other IB status change processing */
5644 } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
5645 (ppd->link_speed_active & QIB_IB_DDR)) {
5646 spin_lock_irqsave(&ppd->lflags_lock, flags);
5647 ppd->lflags &= ~(QIBL_IB_AUTONEG_INPROG |
5648 QIBL_IB_AUTONEG_FAILED);
5649 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5650 ppd->cpspec->autoneg_tries = 0;
5651 /* re-enable SDR, for next link down */
5652 set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
5653 wake_up(&ppd->cpspec->autoneg_wait);
5655 } else if (ppd->lflags & QIBL_IB_AUTONEG_FAILED) {
5657 * Clear autoneg failure flag, and do setup
5658 * so we'll try next time link goes down and
5659 * back to INIT (possibly connected to a
5660 * different device).
5662 spin_lock_irqsave(&ppd->lflags_lock, flags);
5663 ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
5664 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5665 ppd->cpspec->ibcctrl_b |= IBA7322_IBC_IBTA_1_2_MASK;
5668 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
5670 if (ppd->dd->cspec->r1 && ppd->cpspec->ipg_tries <= 10)
5672 if (!ppd->cpspec->recovery_init)
5673 setup_7322_link_recovery(ppd, 0);
5674 ppd->cpspec->qdr_dfe_time = jiffies +
5675 msecs_to_jiffies(QDR_DFE_DISABLE_DELAY);
5677 ppd->cpspec->ibmalfusesnap = 0;
5678 ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
5682 ppd->cpspec->iblnkdownsnap =
5683 read_7322_creg32_port(ppd, crp_iblinkdown);
5684 if (ppd->cpspec->ibdeltainprog) {
5685 ppd->cpspec->ibdeltainprog = 0;
5686 ppd->cpspec->ibsymdelta += read_7322_creg32_port(ppd,
5687 crp_ibsymbolerr) - ppd->cpspec->ibsymsnap;
5688 ppd->cpspec->iblnkerrdelta += read_7322_creg32_port(ppd,
5689 crp_iblinkerrrecov) - ppd->cpspec->iblnkerrsnap;
5691 } else if (!ibup && qib_compat_ddr_negotiate &&
5692 !ppd->cpspec->ibdeltainprog &&
5693 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
5694 ppd->cpspec->ibdeltainprog = 1;
5695 ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
5697 ppd->cpspec->iblnkerrsnap = read_7322_creg32_port(ppd,
5698 crp_iblinkerrrecov);
5702 qib_setup_7322_setextled(ppd, ibup);
5707 * Does read/modify/write to appropriate registers to
5708 * set output and direction bits selected by mask.
5709 * these are in their canonical postions (e.g. lsb of
5710 * dir will end up in D48 of extctrl on existing chips).
5711 * returns contents of GP Inputs.
5713 static int gpio_7322_mod(struct qib_devdata *dd, u32 out, u32 dir, u32 mask)
5715 u64 read_val, new_out;
5716 unsigned long flags;
5719 /* some bits being written, lock access to GPIO */
5722 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
5723 dd->cspec->extctrl &= ~((u64)mask << SYM_LSB(EXTCtrl, GPIOOe));
5724 dd->cspec->extctrl |= ((u64) dir << SYM_LSB(EXTCtrl, GPIOOe));
5725 new_out = (dd->cspec->gpio_out & ~mask) | out;
5727 qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
5728 qib_write_kreg(dd, kr_gpio_out, new_out);
5729 dd->cspec->gpio_out = new_out;
5730 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
5733 * It is unlikely that a read at this time would get valid
5734 * data on a pin whose direction line was set in the same
5735 * call to this function. We include the read here because
5736 * that allows us to potentially combine a change on one pin with
5737 * a read on another, and because the old code did something like
5740 read_val = qib_read_kreg64(dd, kr_extstatus);
5741 return SYM_FIELD(read_val, EXTStatus, GPIOIn);
5744 /* Enable writes to config EEPROM, if possible. Returns previous state */
5745 static int qib_7322_eeprom_wen(struct qib_devdata *dd, int wen)
5750 mask = 1 << QIB_EEPROM_WEN_NUM;
5751 prev_wen = ~gpio_7322_mod(dd, 0, 0, 0) >> QIB_EEPROM_WEN_NUM;
5752 gpio_7322_mod(dd, wen ? 0 : mask, mask, mask);
5754 return prev_wen & 1;
5758 * Read fundamental info we need to use the chip. These are
5759 * the registers that describe chip capabilities, and are
5760 * saved in shadow registers.
5762 static void get_7322_chip_params(struct qib_devdata *dd)
5768 dd->palign = qib_read_kreg32(dd, kr_pagealign);
5770 dd->uregbase = qib_read_kreg32(dd, kr_userregbase);
5772 dd->rcvtidcnt = qib_read_kreg32(dd, kr_rcvtidcnt);
5773 dd->rcvtidbase = qib_read_kreg32(dd, kr_rcvtidbase);
5774 dd->rcvegrbase = qib_read_kreg32(dd, kr_rcvegrbase);
5775 dd->piobufbase = qib_read_kreg64(dd, kr_sendpiobufbase);
5776 dd->pio2k_bufbase = dd->piobufbase & 0xffffffff;
5778 val = qib_read_kreg64(dd, kr_sendpiobufcnt);
5779 dd->piobcnt2k = val & ~0U;
5780 dd->piobcnt4k = val >> 32;
5781 val = qib_read_kreg64(dd, kr_sendpiosize);
5782 dd->piosize2k = val & ~0U;
5783 dd->piosize4k = val >> 32;
5785 mtu = ib_mtu_enum_to_int(qib_ibmtu);
5787 mtu = QIB_DEFAULT_MTU;
5788 dd->pport[0].ibmtu = (u32)mtu;
5789 dd->pport[1].ibmtu = (u32)mtu;
5791 /* these may be adjusted in init_chip_wc_pat() */
5792 dd->pio2kbase = (u32 __iomem *)
5793 ((char __iomem *) dd->kregbase + dd->pio2k_bufbase);
5794 dd->pio4kbase = (u32 __iomem *)
5795 ((char __iomem *) dd->kregbase +
5796 (dd->piobufbase >> 32));
5798 * 4K buffers take 2 pages; we use roundup just to be
5799 * paranoid; we calculate it once here, rather than on
5802 dd->align4k = ALIGN(dd->piosize4k, dd->palign);
5804 piobufs = dd->piobcnt4k + dd->piobcnt2k + NUM_VL15_BUFS;
5806 dd->pioavregs = ALIGN(piobufs, sizeof(u64) * BITS_PER_BYTE / 2) /
5807 (sizeof(u64) * BITS_PER_BYTE / 2);
5811 * The chip base addresses in cspec and cpspec have to be set
5812 * after possible init_chip_wc_pat(), rather than in
5813 * get_7322_chip_params(), so split out as separate function
5815 static void qib_7322_set_baseaddrs(struct qib_devdata *dd)
5818 cregbase = qib_read_kreg32(dd, kr_counterregbase);
5820 dd->cspec->cregbase = (u64 __iomem *)(cregbase +
5821 (char __iomem *)dd->kregbase);
5823 dd->egrtidbase = (u64 __iomem *)
5824 ((char __iomem *) dd->kregbase + dd->rcvegrbase);
5826 /* port registers are defined as relative to base of chip */
5827 dd->pport[0].cpspec->kpregbase =
5828 (u64 __iomem *)((char __iomem *)dd->kregbase);
5829 dd->pport[1].cpspec->kpregbase =
5830 (u64 __iomem *)(dd->palign +
5831 (char __iomem *)dd->kregbase);
5832 dd->pport[0].cpspec->cpregbase =
5833 (u64 __iomem *)(qib_read_kreg_port(&dd->pport[0],
5834 kr_counterregbase) + (char __iomem *)dd->kregbase);
5835 dd->pport[1].cpspec->cpregbase =
5836 (u64 __iomem *)(qib_read_kreg_port(&dd->pport[1],
5837 kr_counterregbase) + (char __iomem *)dd->kregbase);
5841 * This is a fairly special-purpose observer, so we only support
5842 * the port-specific parts of SendCtrl
5845 #define SENDCTRL_SHADOWED (SYM_MASK(SendCtrl_0, SendEnable) | \
5846 SYM_MASK(SendCtrl_0, SDmaEnable) | \
5847 SYM_MASK(SendCtrl_0, SDmaIntEnable) | \
5848 SYM_MASK(SendCtrl_0, SDmaSingleDescriptor) | \
5849 SYM_MASK(SendCtrl_0, SDmaHalt) | \
5850 SYM_MASK(SendCtrl_0, IBVLArbiterEn) | \
5851 SYM_MASK(SendCtrl_0, ForceCreditUpToDate))
5853 static int sendctrl_hook(struct qib_devdata *dd,
5854 const struct diag_observer *op, u32 offs,
5855 u64 *data, u64 mask, int only_32)
5857 unsigned long flags;
5860 struct qib_pportdata *ppd = NULL;
5861 u64 local_data, all_bits;
5864 * The fixed correspondence between Physical ports and pports is
5865 * severed. We need to hunt for the ppd that corresponds
5866 * to the offset we got. And we have to do that without admitting
5867 * we know the stride, apparently.
5869 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
5873 ppd = dd->pport + pidx;
5874 if (!ppd->cpspec->kpregbase)
5877 psptr = ppd->cpspec->kpregbase + krp_sendctrl;
5878 psoffs = (u32) (psptr - dd->kregbase) * sizeof(*psptr);
5883 /* If pport is not being managed by driver, just avoid shadows. */
5884 if (pidx >= dd->num_pports)
5887 /* In any case, "idx" is flat index in kreg space */
5888 idx = offs / sizeof(u64);
5894 spin_lock_irqsave(&dd->sendctrl_lock, flags);
5895 if (!ppd || (mask & all_bits) != all_bits) {
5897 * At least some mask bits are zero, so we need
5898 * to read. The judgement call is whether from
5899 * reg or shadow. First-cut: read reg, and complain
5900 * if any bits which should be shadowed are different
5901 * from their shadowed value.
5904 local_data = (u64)qib_read_kreg32(dd, idx);
5906 local_data = qib_read_kreg64(dd, idx);
5907 *data = (local_data & ~mask) | (*data & mask);
5911 * At least some mask bits are one, so we need
5912 * to write, but only shadow some bits.
5914 u64 sval, tval; /* Shadowed, transient */
5917 * New shadow val is bits we don't want to touch,
5918 * ORed with bits we do, that are intended for shadow.
5921 sval = ppd->p_sendctrl & ~mask;
5922 sval |= *data & SENDCTRL_SHADOWED & mask;
5923 ppd->p_sendctrl = sval;
5925 sval = *data & SENDCTRL_SHADOWED & mask;
5926 tval = sval | (*data & ~SENDCTRL_SHADOWED & mask);
5927 qib_write_kreg(dd, idx, tval);
5928 qib_write_kreg(dd, kr_scratch, 0Ull);
5930 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
5931 return only_32 ? 4 : 8;
5934 static const struct diag_observer sendctrl_0_observer = {
5935 sendctrl_hook, KREG_IDX(SendCtrl_0) * sizeof(u64),
5936 KREG_IDX(SendCtrl_0) * sizeof(u64)
5939 static const struct diag_observer sendctrl_1_observer = {
5940 sendctrl_hook, KREG_IDX(SendCtrl_1) * sizeof(u64),
5941 KREG_IDX(SendCtrl_1) * sizeof(u64)
5944 static ushort sdma_fetch_prio = 8;
5945 module_param_named(sdma_fetch_prio, sdma_fetch_prio, ushort, S_IRUGO);
5946 MODULE_PARM_DESC(sdma_fetch_prio, "SDMA descriptor fetch priority");
5948 /* Besides logging QSFP events, we set appropriate TxDDS values */
5949 static void init_txdds_table(struct qib_pportdata *ppd, int override);
5951 static void qsfp_7322_event(struct work_struct *work)
5953 struct qib_qsfp_data *qd;
5954 struct qib_pportdata *ppd;
5955 unsigned long pwrup;
5956 unsigned long flags;
5960 qd = container_of(work, struct qib_qsfp_data, work);
5962 pwrup = qd->t_insert +
5963 msecs_to_jiffies(QSFP_PWR_LAG_MSEC - QSFP_MODPRS_LAG_MSEC);
5965 /* Delay for 20 msecs to allow ModPrs resistor to setup */
5966 mdelay(QSFP_MODPRS_LAG_MSEC);
5968 if (!qib_qsfp_mod_present(ppd)) {
5969 ppd->cpspec->qsfp_data.modpresent = 0;
5970 /* Set the physical link to disabled */
5971 qib_set_ib_7322_lstate(ppd, 0,
5972 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
5973 spin_lock_irqsave(&ppd->lflags_lock, flags);
5974 ppd->lflags &= ~QIBL_LINKV;
5975 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5978 * Some QSFP's not only do not respond until the full power-up
5979 * time, but may behave badly if we try. So hold off responding
5983 if (time_is_before_jiffies(pwrup))
5988 ret = qib_refresh_qsfp_cache(ppd, &qd->cache);
5991 * Need to change LE2 back to defaults if we couldn't
5992 * read the cable type (to handle cable swaps), so do this
5993 * even on failure to read cable information. We don't
5994 * get here for QME, so IS_QME check not needed here.
5996 if (!ret && !ppd->dd->cspec->r1) {
5997 if (QSFP_IS_ACTIVE_FAR(qd->cache.tech))
5999 else if (qd->cache.atten[1] >= qib_long_atten &&
6000 QSFP_IS_CU(qd->cache.tech))
6006 ibsd_wr_allchans(ppd, 13, (le2 << 7), BMASK(9, 7));
6008 * We always change parameteters, since we can choose
6009 * values for cables without eeproms, and the cable may have
6010 * changed from a cable with full or partial eeprom content
6011 * to one with partial or no content.
6013 init_txdds_table(ppd, 0);
6014 /* The physical link is being re-enabled only when the
6015 * previous state was DISABLED and the VALID bit is not
6016 * set. This should only happen when the cable has been
6017 * physically pulled. */
6018 if (!ppd->cpspec->qsfp_data.modpresent &&
6019 (ppd->lflags & (QIBL_LINKV | QIBL_IB_LINK_DISABLED))) {
6020 ppd->cpspec->qsfp_data.modpresent = 1;
6021 qib_set_ib_7322_lstate(ppd, 0,
6022 QLOGIC_IB_IBCC_LINKINITCMD_SLEEP);
6023 spin_lock_irqsave(&ppd->lflags_lock, flags);
6024 ppd->lflags |= QIBL_LINKV;
6025 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
6031 * There is little we can do but complain to the user if QSFP
6032 * initialization fails.
6034 static void qib_init_7322_qsfp(struct qib_pportdata *ppd)
6036 unsigned long flags;
6037 struct qib_qsfp_data *qd = &ppd->cpspec->qsfp_data;
6038 struct qib_devdata *dd = ppd->dd;
6039 u64 mod_prs_bit = QSFP_GPIO_MOD_PRS_N;
6041 mod_prs_bit <<= (QSFP_GPIO_PORT2_SHIFT * ppd->hw_pidx);
6043 qib_qsfp_init(qd, qsfp_7322_event);
6044 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
6045 dd->cspec->extctrl |= (mod_prs_bit << SYM_LSB(EXTCtrl, GPIOInvert));
6046 dd->cspec->gpio_mask |= mod_prs_bit;
6047 qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
6048 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
6049 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
6053 * called at device initialization time, and also if the txselect
6054 * module parameter is changed. This is used for cables that don't
6055 * have valid QSFP EEPROMs (not present, or attenuation is zero).
6056 * We initialize to the default, then if there is a specific
6057 * unit,port match, we use that (and set it immediately, for the
6058 * current speed, if the link is at INIT or better).
6059 * String format is "default# unit#,port#=# ... u,p=#", separators must
6060 * be a SPACE character. A newline terminates. The u,p=# tuples may
6061 * optionally have "u,p=#,#", where the final # is the H1 value
6062 * The last specific match is used (actually, all are used, but last
6063 * one is the one that winds up set); if none at all, fall back on default.
6065 static void set_no_qsfp_atten(struct qib_devdata *dd, int change)
6068 u32 pidx, unit, port, deflt, h1;
6073 str = txselect_list;
6075 /* default number is validated in setup_txselect() */
6076 deflt = simple_strtoul(str, &nxt, 0);
6077 for (pidx = 0; pidx < dd->num_pports; ++pidx)
6078 dd->pport[pidx].cpspec->no_eep = deflt;
6080 txdds_size = TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ;
6081 if (IS_QME(dd) || IS_QMH(dd))
6082 txdds_size += TXDDS_MFG_SZ;
6084 while (*nxt && nxt[1]) {
6086 unit = simple_strtoul(str, &nxt, 0);
6087 if (nxt == str || !*nxt || *nxt != ',') {
6088 while (*nxt && *nxt++ != ' ') /* skip to next, if any */
6093 port = simple_strtoul(str, &nxt, 0);
6094 if (nxt == str || *nxt != '=') {
6095 while (*nxt && *nxt++ != ' ') /* skip to next, if any */
6100 val = simple_strtoul(str, &nxt, 0);
6102 while (*nxt && *nxt++ != ' ') /* skip to next, if any */
6106 if (val >= txdds_size)
6109 h1 = 0; /* gcc thinks it might be used uninitted */
6110 if (*nxt == ',' && nxt[1]) {
6112 h1 = (u32)simple_strtoul(str, &nxt, 0);
6114 while (*nxt && *nxt++ != ' ') /* skip */
6119 for (pidx = 0; dd->unit == unit && pidx < dd->num_pports;
6121 struct qib_pportdata *ppd = &dd->pport[pidx];
6123 if (ppd->port != port || !ppd->link_speed_supported)
6125 ppd->cpspec->no_eep = val;
6127 ppd->cpspec->h1_val = h1;
6128 /* now change the IBC and serdes, overriding generic */
6129 init_txdds_table(ppd, 1);
6130 /* Re-enable the physical state machine on mezz boards
6131 * now that the correct settings have been set.
6132 * QSFP boards are handles by the QSFP event handler */
6133 if (IS_QMH(dd) || IS_QME(dd))
6134 qib_set_ib_7322_lstate(ppd, 0,
6135 QLOGIC_IB_IBCC_LINKINITCMD_SLEEP);
6141 if (change && !any) {
6142 /* no specific setting, use the default.
6143 * Change the IBC and serdes, but since it's
6144 * general, don't override specific settings.
6146 for (pidx = 0; pidx < dd->num_pports; ++pidx)
6147 if (dd->pport[pidx].link_speed_supported)
6148 init_txdds_table(&dd->pport[pidx], 0);
6152 /* handle the txselect parameter changing */
6153 static int setup_txselect(const char *str, struct kernel_param *kp)
6155 struct qib_devdata *dd;
6159 if (strlen(str) >= MAX_ATTEN_LEN) {
6160 pr_info("txselect_values string too long\n");
6163 ret = kstrtoul(str, 0, &val);
6164 if (ret || val >= (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
6166 pr_info("txselect_values must start with a number < %d\n",
6167 TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ + TXDDS_MFG_SZ);
6168 return ret ? ret : -EINVAL;
6171 strcpy(txselect_list, str);
6172 list_for_each_entry(dd, &qib_dev_list, list)
6173 if (dd->deviceid == PCI_DEVICE_ID_QLOGIC_IB_7322)
6174 set_no_qsfp_atten(dd, 1);
6179 * Write the final few registers that depend on some of the
6180 * init setup. Done late in init, just before bringing up
6183 static int qib_late_7322_initreg(struct qib_devdata *dd)
6188 qib_write_kreg(dd, kr_rcvhdrentsize, dd->rcvhdrentsize);
6189 qib_write_kreg(dd, kr_rcvhdrsize, dd->rcvhdrsize);
6190 qib_write_kreg(dd, kr_rcvhdrcnt, dd->rcvhdrcnt);
6191 qib_write_kreg(dd, kr_sendpioavailaddr, dd->pioavailregs_phys);
6192 val = qib_read_kreg64(dd, kr_sendpioavailaddr);
6193 if (val != dd->pioavailregs_phys) {
6195 "Catastrophic software error, SendPIOAvailAddr written as %lx, read back as %llx\n",
6196 (unsigned long) dd->pioavailregs_phys,
6197 (unsigned long long) val);
6201 n = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
6202 qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_KERN, NULL);
6203 /* driver sends get pkey, lid, etc. checking also, to catch bugs */
6204 qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_ENAB1, NULL);
6206 qib_register_observer(dd, &sendctrl_0_observer);
6207 qib_register_observer(dd, &sendctrl_1_observer);
6209 dd->control &= ~QLOGIC_IB_C_SDMAFETCHPRIOEN;
6210 qib_write_kreg(dd, kr_control, dd->control);
6212 * Set SendDmaFetchPriority and init Tx params, including
6213 * QSFP handler on boards that have QSFP.
6214 * First set our default attenuation entry for cables that
6215 * don't have valid attenuation.
6217 set_no_qsfp_atten(dd, 0);
6218 for (n = 0; n < dd->num_pports; ++n) {
6219 struct qib_pportdata *ppd = dd->pport + n;
6221 qib_write_kreg_port(ppd, krp_senddmaprioritythld,
6222 sdma_fetch_prio & 0xf);
6223 /* Initialize qsfp if present on board. */
6224 if (dd->flags & QIB_HAS_QSFP)
6225 qib_init_7322_qsfp(ppd);
6227 dd->control |= QLOGIC_IB_C_SDMAFETCHPRIOEN;
6228 qib_write_kreg(dd, kr_control, dd->control);
6233 /* per IB port errors. */
6234 #define SENDCTRL_PIBP (MASK_ACROSS(0, 1) | MASK_ACROSS(3, 3) | \
6236 #define RCVCTRL_PIBP (MASK_ACROSS(0, 17) | MASK_ACROSS(39, 41))
6237 #define ERRS_PIBP (MASK_ACROSS(57, 58) | MASK_ACROSS(54, 54) | \
6238 MASK_ACROSS(36, 49) | MASK_ACROSS(29, 34) | MASK_ACROSS(14, 17) | \
6242 * Write the initialization per-port registers that need to be done at
6243 * driver load and after reset completes (i.e., that aren't done as part
6244 * of other init procedures called from qib_init.c).
6245 * Some of these should be redundant on reset, but play safe.
6247 static void write_7322_init_portregs(struct qib_pportdata *ppd)
6252 if (!ppd->link_speed_supported) {
6253 /* no buffer credits for this port */
6254 for (i = 1; i < 8; i++)
6255 qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, 0);
6256 qib_write_kreg_port(ppd, krp_ibcctrl_b, 0);
6257 qib_write_kreg(ppd->dd, kr_scratch, 0);
6262 * Set the number of supported virtual lanes in IBC,
6263 * for flow control packet handling on unsupported VLs
6265 val = qib_read_kreg_port(ppd, krp_ibsdtestiftx);
6266 val &= ~SYM_MASK(IB_SDTEST_IF_TX_0, VL_CAP);
6267 val |= (u64)(ppd->vls_supported - 1) <<
6268 SYM_LSB(IB_SDTEST_IF_TX_0, VL_CAP);
6269 qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
6271 qib_write_kreg_port(ppd, krp_rcvbthqp, QIB_KD_QP);
6273 /* enable tx header checking */
6274 qib_write_kreg_port(ppd, krp_sendcheckcontrol, IBA7322_SENDCHK_PKEY |
6275 IBA7322_SENDCHK_BTHQP | IBA7322_SENDCHK_SLID |
6276 IBA7322_SENDCHK_RAW_IPV6 | IBA7322_SENDCHK_MINSZ);
6278 qib_write_kreg_port(ppd, krp_ncmodectrl,
6279 SYM_MASK(IBNCModeCtrl_0, ScrambleCapLocal));
6282 * Unconditionally clear the bufmask bits. If SDMA is
6283 * enabled, we'll set them appropriately later.
6285 qib_write_kreg_port(ppd, krp_senddmabufmask0, 0);
6286 qib_write_kreg_port(ppd, krp_senddmabufmask1, 0);
6287 qib_write_kreg_port(ppd, krp_senddmabufmask2, 0);
6288 if (ppd->dd->cspec->r1)
6289 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, ForceCreditUpToDate);
6293 * Write the initialization per-device registers that need to be done at
6294 * driver load and after reset completes (i.e., that aren't done as part
6295 * of other init procedures called from qib_init.c). Also write per-port
6296 * registers that are affected by overall device config, such as QP mapping
6297 * Some of these should be redundant on reset, but play safe.
6299 static void write_7322_initregs(struct qib_devdata *dd)
6301 struct qib_pportdata *ppd;
6305 /* Set Multicast QPs received by port 2 to map to context one. */
6306 qib_write_kreg(dd, KREG_IDX(RcvQPMulticastContext_1), 1);
6308 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
6310 unsigned long flags;
6312 if (dd->n_krcv_queues < 2 ||
6313 !dd->pport[pidx].link_speed_supported)
6316 ppd = &dd->pport[pidx];
6318 /* be paranoid against later code motion, etc. */
6319 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
6320 ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvQPMapEnable);
6321 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
6323 /* Initialize QP to context mapping */
6324 regno = krp_rcvqpmaptable;
6326 if (dd->num_pports > 1)
6327 n = dd->first_user_ctxt / dd->num_pports;
6329 n = dd->first_user_ctxt - 1;
6330 for (i = 0; i < 32; ) {
6333 if (dd->num_pports > 1)
6334 ctxt = (i % n) * dd->num_pports + pidx;
6338 ctxt = ppd->hw_pidx;
6339 val |= ctxt << (5 * (i % 6));
6342 qib_write_kreg_port(ppd, regno, val);
6347 qib_write_kreg_port(ppd, regno, val);
6351 * Setup up interrupt mitigation for kernel contexts, but
6352 * not user contexts (user contexts use interrupts when
6353 * stalled waiting for any packet, so want those interrupts
6356 for (i = 0; i < dd->first_user_ctxt; i++) {
6357 dd->cspec->rcvavail_timeout[i] = rcv_int_timeout;
6358 qib_write_kreg(dd, kr_rcvavailtimeout + i, rcv_int_timeout);
6362 * Initialize as (disabled) rcvflow tables. Application code
6363 * will setup each flow as it uses the flow.
6364 * Doesn't clear any of the error bits that might be set.
6366 val = TIDFLOW_ERRBITS; /* these are W1C */
6367 for (i = 0; i < dd->cfgctxts; i++) {
6369 for (flow = 0; flow < NUM_TIDFLOWS_CTXT; flow++)
6370 qib_write_ureg(dd, ur_rcvflowtable+flow, val, i);
6374 * dual cards init to dual port recovery, single port cards to
6375 * the one port. Dual port cards may later adjust to 1 port,
6376 * and then back to dual port if both ports are connected
6379 setup_7322_link_recovery(dd->pport, dd->num_pports > 1);
6382 static int qib_init_7322_variables(struct qib_devdata *dd)
6384 struct qib_pportdata *ppd;
6385 unsigned features, pidx, sbufcnt;
6387 u32 sbufs, updthresh;
6389 /* pport structs are contiguous, allocated after devdata */
6390 ppd = (struct qib_pportdata *)(dd + 1);
6395 dd->cspec = (struct qib_chip_specific *)(ppd + 2);
6397 ppd[0].cpspec = (struct qib_chippport_specific *)(dd->cspec + 1);
6398 ppd[1].cpspec = &ppd[0].cpspec[1];
6399 ppd[0].cpspec->ppd = &ppd[0]; /* for autoneg_7322_work() */
6400 ppd[1].cpspec->ppd = &ppd[1]; /* for autoneg_7322_work() */
6402 spin_lock_init(&dd->cspec->rcvmod_lock);
6403 spin_lock_init(&dd->cspec->gpio_lock);
6405 /* we haven't yet set QIB_PRESENT, so use read directly */
6406 dd->revision = readq(&dd->kregbase[kr_revision]);
6408 if ((dd->revision & 0xffffffffU) == 0xffffffffU) {
6410 "Revision register read failure, giving up initialization\n");
6414 dd->flags |= QIB_PRESENT; /* now register routines work */
6416 dd->majrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMajor);
6417 dd->minrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMinor);
6418 dd->cspec->r1 = dd->minrev == 1;
6420 get_7322_chip_params(dd);
6421 features = qib_7322_boardname(dd);
6423 /* now that piobcnt2k and 4k set, we can allocate these */
6424 sbufcnt = dd->piobcnt2k + dd->piobcnt4k +
6425 NUM_VL15_BUFS + BITS_PER_LONG - 1;
6426 sbufcnt /= BITS_PER_LONG;
6427 dd->cspec->sendchkenable = kmalloc(sbufcnt *
6428 sizeof(*dd->cspec->sendchkenable), GFP_KERNEL);
6429 dd->cspec->sendgrhchk = kmalloc(sbufcnt *
6430 sizeof(*dd->cspec->sendgrhchk), GFP_KERNEL);
6431 dd->cspec->sendibchk = kmalloc(sbufcnt *
6432 sizeof(*dd->cspec->sendibchk), GFP_KERNEL);
6433 if (!dd->cspec->sendchkenable || !dd->cspec->sendgrhchk ||
6434 !dd->cspec->sendibchk) {
6435 qib_dev_err(dd, "Failed allocation for hdrchk bitmaps\n");
6443 * GPIO bits for TWSI data and clock,
6444 * used for serial EEPROM.
6446 dd->gpio_sda_num = _QIB_GPIO_SDA_NUM;
6447 dd->gpio_scl_num = _QIB_GPIO_SCL_NUM;
6448 dd->twsi_eeprom_dev = QIB_TWSI_EEPROM_DEV;
6450 dd->flags |= QIB_HAS_INTX | QIB_HAS_LINK_LATENCY |
6451 QIB_NODMA_RTAIL | QIB_HAS_VLSUPP | QIB_HAS_HDRSUPP |
6452 QIB_HAS_THRESH_UPDATE |
6453 (sdma_idle_cnt ? QIB_HAS_SDMA_TIMEOUT : 0);
6454 dd->flags |= qib_special_trigger ?
6455 QIB_USE_SPCL_TRIG : QIB_HAS_SEND_DMA;
6458 * Setup initial values. These may change when PAT is enabled, but
6459 * we need these to do initial chip register accesses.
6461 qib_7322_set_baseaddrs(dd);
6463 mtu = ib_mtu_enum_to_int(qib_ibmtu);
6465 mtu = QIB_DEFAULT_MTU;
6467 dd->cspec->int_enable_mask = QIB_I_BITSEXTANT;
6468 /* all hwerrors become interrupts, unless special purposed */
6469 dd->cspec->hwerrmask = ~0ULL;
6470 /* link_recovery setup causes these errors, so ignore them,
6471 * other than clearing them when they occur */
6472 dd->cspec->hwerrmask &=
6473 ~(SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_0) |
6474 SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_1) |
6475 HWE_MASK(LATriggered));
6477 for (pidx = 0; pidx < NUM_IB_PORTS; ++pidx) {
6478 struct qib_chippport_specific *cp = ppd->cpspec;
6479 ppd->link_speed_supported = features & PORT_SPD_CAP;
6480 features >>= PORT_SPD_CAP_SHIFT;
6481 if (!ppd->link_speed_supported) {
6482 /* single port mode (7340, or configured) */
6483 dd->skip_kctxt_mask |= 1 << pidx;
6485 /* Make sure port is disabled. */
6486 qib_write_kreg_port(ppd, krp_rcvctrl, 0);
6487 qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
6489 dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
6490 IBSerdesPClkNotDetectMask_0)
6491 | SYM_MASK(HwErrMask,
6492 SDmaMemReadErrMask_0));
6493 dd->cspec->int_enable_mask &= ~(
6494 SYM_MASK(IntMask, SDmaCleanupDoneMask_0) |
6495 SYM_MASK(IntMask, SDmaIdleIntMask_0) |
6496 SYM_MASK(IntMask, SDmaProgressIntMask_0) |
6497 SYM_MASK(IntMask, SDmaIntMask_0) |
6498 SYM_MASK(IntMask, ErrIntMask_0) |
6499 SYM_MASK(IntMask, SendDoneIntMask_0));
6501 /* Make sure port is disabled. */
6502 qib_write_kreg_port(ppd, krp_rcvctrl, 0);
6503 qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
6504 dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
6505 IBSerdesPClkNotDetectMask_1)
6506 | SYM_MASK(HwErrMask,
6507 SDmaMemReadErrMask_1));
6508 dd->cspec->int_enable_mask &= ~(
6509 SYM_MASK(IntMask, SDmaCleanupDoneMask_1) |
6510 SYM_MASK(IntMask, SDmaIdleIntMask_1) |
6511 SYM_MASK(IntMask, SDmaProgressIntMask_1) |
6512 SYM_MASK(IntMask, SDmaIntMask_1) |
6513 SYM_MASK(IntMask, ErrIntMask_1) |
6514 SYM_MASK(IntMask, SendDoneIntMask_1));
6520 qib_init_pportdata(ppd, dd, pidx, dd->num_pports);
6522 ppd->link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
6523 ppd->link_width_enabled = IB_WIDTH_4X;
6524 ppd->link_speed_enabled = ppd->link_speed_supported;
6526 * Set the initial values to reasonable default, will be set
6527 * for real when link is up.
6529 ppd->link_width_active = IB_WIDTH_4X;
6530 ppd->link_speed_active = QIB_IB_SDR;
6531 ppd->delay_mult = ib_rate_to_delay[IB_RATE_10_GBPS];
6532 switch (qib_num_cfg_vls) {
6534 ppd->vls_supported = IB_VL_VL0;
6537 ppd->vls_supported = IB_VL_VL0_1;
6540 qib_devinfo(dd->pcidev,
6541 "Invalid num_vls %u, using 4 VLs\n",
6543 qib_num_cfg_vls = 4;
6546 ppd->vls_supported = IB_VL_VL0_3;
6550 ppd->vls_supported = IB_VL_VL0_7;
6552 qib_devinfo(dd->pcidev,
6553 "Invalid num_vls %u for MTU %d "
6555 qib_num_cfg_vls, mtu);
6556 ppd->vls_supported = IB_VL_VL0_3;
6557 qib_num_cfg_vls = 4;
6561 ppd->vls_operational = ppd->vls_supported;
6563 init_waitqueue_head(&cp->autoneg_wait);
6564 INIT_DELAYED_WORK(&cp->autoneg_work,
6566 if (ppd->dd->cspec->r1)
6567 INIT_DELAYED_WORK(&cp->ipg_work, ipg_7322_work);
6570 * For Mez and similar cards, no qsfp info, so do
6571 * the "cable info" setup here. Can be overridden
6572 * in adapter-specific routines.
6574 if (!(dd->flags & QIB_HAS_QSFP)) {
6575 if (!IS_QMH(dd) && !IS_QME(dd))
6576 qib_devinfo(dd->pcidev,
6577 "IB%u:%u: Unknown mezzanine card type\n",
6578 dd->unit, ppd->port);
6579 cp->h1_val = IS_QMH(dd) ? H1_FORCE_QMH : H1_FORCE_QME;
6581 * Choose center value as default tx serdes setting
6582 * until changed through module parameter.
6584 ppd->cpspec->no_eep = IS_QMH(dd) ?
6585 TXDDS_TABLE_SZ + 2 : TXDDS_TABLE_SZ + 4;
6587 cp->h1_val = H1_FORCE_VAL;
6589 /* Avoid writes to chip for mini_init */
6591 write_7322_init_portregs(ppd);
6593 init_timer(&cp->chase_timer);
6594 cp->chase_timer.function = reenable_chase;
6595 cp->chase_timer.data = (unsigned long)ppd;
6600 dd->rcvhdrentsize = qib_rcvhdrentsize ?
6601 qib_rcvhdrentsize : QIB_RCVHDR_ENTSIZE;
6602 dd->rcvhdrsize = qib_rcvhdrsize ?
6603 qib_rcvhdrsize : QIB_DFLT_RCVHDRSIZE;
6604 dd->rhf_offset = dd->rcvhdrentsize - sizeof(u64) / sizeof(u32);
6606 /* we always allocate at least 2048 bytes for eager buffers */
6607 dd->rcvegrbufsize = max(mtu, 2048);
6608 BUG_ON(!is_power_of_2(dd->rcvegrbufsize));
6609 dd->rcvegrbufsize_shift = ilog2(dd->rcvegrbufsize);
6611 qib_7322_tidtemplate(dd);
6614 * We can request a receive interrupt for 1 or
6615 * more packets from current offset.
6617 dd->rhdrhead_intr_off =
6618 (u64) rcv_int_count << IBA7322_HDRHEAD_PKTINT_SHIFT;
6620 /* setup the stats timer; the add_timer is done at end of init */
6621 init_timer(&dd->stats_timer);
6622 dd->stats_timer.function = qib_get_7322_faststats;
6623 dd->stats_timer.data = (unsigned long) dd;
6625 dd->ureg_align = 0x10000; /* 64KB alignment */
6627 dd->piosize2kmax_dwords = dd->piosize2k >> 2;
6629 qib_7322_config_ctxts(dd);
6630 qib_set_ctxtcnt(dd);
6633 resource_size_t vl15off;
6635 * We do not set WC on the VL15 buffers to avoid
6636 * a rare problem with unaligned writes from
6637 * interrupt-flushed store buffers, so we need
6638 * to map those separately here. We can't solve
6639 * this for the rarely used mtrr case.
6641 ret = init_chip_wc_pat(dd, 0);
6645 /* vl15 buffers start just after the 4k buffers */
6646 vl15off = dd->physaddr + (dd->piobufbase >> 32) +
6647 dd->piobcnt4k * dd->align4k;
6648 dd->piovl15base = ioremap_nocache(vl15off,
6649 NUM_VL15_BUFS * dd->align4k);
6650 if (!dd->piovl15base) {
6655 qib_7322_set_baseaddrs(dd); /* set chip access pointers now */
6660 if (!dd->num_pports) {
6661 qib_dev_err(dd, "No ports enabled, giving up initialization\n");
6662 goto bail; /* no error, so can still figure out why err */
6665 write_7322_initregs(dd);
6666 ret = qib_create_ctxts(dd);
6667 init_7322_cntrnames(dd);
6669 updthresh = 8U; /* update threshold */
6671 /* use all of 4KB buffers for the kernel SDMA, zero if !SDMA.
6672 * reserve the update threshold amount for other kernel use, such
6673 * as sending SMI, MAD, and ACKs, or 3, whichever is greater,
6674 * unless we aren't enabling SDMA, in which case we want to use
6675 * all the 4k bufs for the kernel.
6676 * if this was less than the update threshold, we could wait
6677 * a long time for an update. Coded this way because we
6678 * sometimes change the update threshold for various reasons,
6679 * and we want this to remain robust.
6681 if (dd->flags & QIB_HAS_SEND_DMA) {
6682 dd->cspec->sdmabufcnt = dd->piobcnt4k;
6683 sbufs = updthresh > 3 ? updthresh : 3;
6685 dd->cspec->sdmabufcnt = 0;
6686 sbufs = dd->piobcnt4k;
6688 dd->cspec->lastbuf_for_pio = dd->piobcnt2k + dd->piobcnt4k -
6689 dd->cspec->sdmabufcnt;
6690 dd->lastctxt_piobuf = dd->cspec->lastbuf_for_pio - sbufs;
6691 dd->cspec->lastbuf_for_pio--; /* range is <= , not < */
6692 dd->last_pio = dd->cspec->lastbuf_for_pio;
6693 dd->pbufsctxt = (dd->cfgctxts > dd->first_user_ctxt) ?
6694 dd->lastctxt_piobuf / (dd->cfgctxts - dd->first_user_ctxt) : 0;
6697 * If we have 16 user contexts, we will have 7 sbufs
6698 * per context, so reduce the update threshold to match. We
6699 * want to update before we actually run out, at low pbufs/ctxt
6700 * so give ourselves some margin.
6702 if (dd->pbufsctxt >= 2 && dd->pbufsctxt - 2 < updthresh)
6703 updthresh = dd->pbufsctxt - 2;
6704 dd->cspec->updthresh_dflt = updthresh;
6705 dd->cspec->updthresh = updthresh;
6707 /* before full enable, no interrupts, no locking needed */
6708 dd->sendctrl |= ((updthresh & SYM_RMASK(SendCtrl, AvailUpdThld))
6709 << SYM_LSB(SendCtrl, AvailUpdThld)) |
6710 SYM_MASK(SendCtrl, SendBufAvailPad64Byte);
6712 dd->psxmitwait_supported = 1;
6713 dd->psxmitwait_check_rate = QIB_7322_PSXMITWAIT_CHECK_RATE;
6716 dd->ctxtcnt = 1; /* for other initialization code */
6721 static u32 __iomem *qib_7322_getsendbuf(struct qib_pportdata *ppd, u64 pbc,
6724 u32 first, last, plen = pbc & QIB_PBC_LENGTH_MASK;
6725 struct qib_devdata *dd = ppd->dd;
6727 /* last is same for 2k and 4k, because we use 4k if all 2k busy */
6728 if (pbc & PBC_7322_VL15_SEND) {
6729 first = dd->piobcnt2k + dd->piobcnt4k + ppd->hw_pidx;
6732 if ((plen + 1) > dd->piosize2kmax_dwords)
6733 first = dd->piobcnt2k;
6736 last = dd->cspec->lastbuf_for_pio;
6738 return qib_getsendbuf_range(dd, pbufnum, first, last);
6741 static void qib_set_cntr_7322_sample(struct qib_pportdata *ppd, u32 intv,
6744 qib_write_kreg_port(ppd, krp_psinterval, intv);
6745 qib_write_kreg_port(ppd, krp_psstart, start);
6749 * Must be called with sdma_lock held, or before init finished.
6751 static void qib_sdma_set_7322_desc_cnt(struct qib_pportdata *ppd, unsigned cnt)
6753 qib_write_kreg_port(ppd, krp_senddmadesccnt, cnt);
6756 static struct sdma_set_state_action sdma_7322_action_table[] = {
6757 [qib_sdma_state_s00_hw_down] = {
6758 .go_s99_running_tofalse = 1,
6764 [qib_sdma_state_s10_hw_start_up_wait] = {
6770 [qib_sdma_state_s20_idle] = {
6776 [qib_sdma_state_s30_sw_clean_up_wait] = {
6782 [qib_sdma_state_s40_hw_clean_up_wait] = {
6788 [qib_sdma_state_s50_hw_halt_wait] = {
6794 [qib_sdma_state_s99_running] = {
6799 .go_s99_running_totrue = 1,
6803 static void qib_7322_sdma_init_early(struct qib_pportdata *ppd)
6805 ppd->sdma_state.set_state_action = sdma_7322_action_table;
6808 static int init_sdma_7322_regs(struct qib_pportdata *ppd)
6810 struct qib_devdata *dd = ppd->dd;
6811 unsigned lastbuf, erstbuf;
6812 u64 senddmabufmask[3] = { 0 };
6815 qib_write_kreg_port(ppd, krp_senddmabase, ppd->sdma_descq_phys);
6816 qib_sdma_7322_setlengen(ppd);
6817 qib_sdma_update_7322_tail(ppd, 0); /* Set SendDmaTail */
6818 qib_write_kreg_port(ppd, krp_senddmareloadcnt, sdma_idle_cnt);
6819 qib_write_kreg_port(ppd, krp_senddmadesccnt, 0);
6820 qib_write_kreg_port(ppd, krp_senddmaheadaddr, ppd->sdma_head_phys);
6823 n = dd->cspec->sdmabufcnt / dd->num_pports; /* no remainder */
6825 n = dd->cspec->sdmabufcnt; /* failsafe for init */
6826 erstbuf = (dd->piobcnt2k + dd->piobcnt4k) -
6827 ((dd->num_pports == 1 || ppd->port == 2) ? n :
6828 dd->cspec->sdmabufcnt);
6829 lastbuf = erstbuf + n;
6831 ppd->sdma_state.first_sendbuf = erstbuf;
6832 ppd->sdma_state.last_sendbuf = lastbuf;
6833 for (; erstbuf < lastbuf; ++erstbuf) {
6834 unsigned word = erstbuf / BITS_PER_LONG;
6835 unsigned bit = erstbuf & (BITS_PER_LONG - 1);
6838 senddmabufmask[word] |= 1ULL << bit;
6840 qib_write_kreg_port(ppd, krp_senddmabufmask0, senddmabufmask[0]);
6841 qib_write_kreg_port(ppd, krp_senddmabufmask1, senddmabufmask[1]);
6842 qib_write_kreg_port(ppd, krp_senddmabufmask2, senddmabufmask[2]);
6846 /* sdma_lock must be held */
6847 static u16 qib_sdma_7322_gethead(struct qib_pportdata *ppd)
6849 struct qib_devdata *dd = ppd->dd;
6857 use_dmahead = __qib_sdma_running(ppd) &&
6858 (dd->flags & QIB_HAS_SDMA_TIMEOUT);
6860 hwhead = use_dmahead ?
6861 (u16) le64_to_cpu(*ppd->sdma_head_dma) :
6862 (u16) qib_read_kreg_port(ppd, krp_senddmahead);
6864 swhead = ppd->sdma_descq_head;
6865 swtail = ppd->sdma_descq_tail;
6866 cnt = ppd->sdma_descq_cnt;
6868 if (swhead < swtail)
6870 sane = (hwhead >= swhead) & (hwhead <= swtail);
6871 else if (swhead > swtail)
6872 /* wrapped around */
6873 sane = ((hwhead >= swhead) && (hwhead < cnt)) ||
6877 sane = (hwhead == swhead);
6879 if (unlikely(!sane)) {
6881 /* try one more time, directly from the register */
6885 /* proceed as if no progress */
6892 static int qib_sdma_7322_busy(struct qib_pportdata *ppd)
6894 u64 hwstatus = qib_read_kreg_port(ppd, krp_senddmastatus);
6896 return (hwstatus & SYM_MASK(SendDmaStatus_0, ScoreBoardDrainInProg)) ||
6897 (hwstatus & SYM_MASK(SendDmaStatus_0, HaltInProg)) ||
6898 !(hwstatus & SYM_MASK(SendDmaStatus_0, InternalSDmaHalt)) ||
6899 !(hwstatus & SYM_MASK(SendDmaStatus_0, ScbEmpty));
6903 * Compute the amount of delay before sending the next packet if the
6904 * port's send rate differs from the static rate set for the QP.
6905 * The delay affects the next packet and the amount of the delay is
6906 * based on the length of the this packet.
6908 static u32 qib_7322_setpbc_control(struct qib_pportdata *ppd, u32 plen,
6911 u8 snd_mult = ppd->delay_mult;
6912 u8 rcv_mult = ib_rate_to_delay[srate];
6915 ret = rcv_mult > snd_mult ? ((plen + 1) >> 1) * snd_mult : 0;
6917 /* Indicate VL15, else set the VL in the control word */
6919 ret |= PBC_7322_VL15_SEND_CTRL;
6921 ret |= vl << PBC_VL_NUM_LSB;
6922 ret |= ((u32)(ppd->hw_pidx)) << PBC_PORT_SEL_LSB;
6928 * Enable the per-port VL15 send buffers for use.
6929 * They follow the rest of the buffers, without a config parameter.
6930 * This was in initregs, but that is done before the shadow
6931 * is set up, and this has to be done after the shadow is
6934 static void qib_7322_initvl15_bufs(struct qib_devdata *dd)
6938 vl15bufs = dd->piobcnt2k + dd->piobcnt4k;
6939 qib_chg_pioavailkernel(dd, vl15bufs, NUM_VL15_BUFS,
6940 TXCHK_CHG_TYPE_KERN, NULL);
6943 static void qib_7322_init_ctxt(struct qib_ctxtdata *rcd)
6945 if (rcd->ctxt < NUM_IB_PORTS) {
6946 if (rcd->dd->num_pports > 1) {
6947 rcd->rcvegrcnt = KCTXT0_EGRCNT / 2;
6948 rcd->rcvegr_tid_base = rcd->ctxt ? rcd->rcvegrcnt : 0;
6950 rcd->rcvegrcnt = KCTXT0_EGRCNT;
6951 rcd->rcvegr_tid_base = 0;
6954 rcd->rcvegrcnt = rcd->dd->cspec->rcvegrcnt;
6955 rcd->rcvegr_tid_base = KCTXT0_EGRCNT +
6956 (rcd->ctxt - NUM_IB_PORTS) * rcd->rcvegrcnt;
6960 #define QTXSLEEPS 5000
6961 static void qib_7322_txchk_change(struct qib_devdata *dd, u32 start,
6962 u32 len, u32 which, struct qib_ctxtdata *rcd)
6965 const int last = start + len - 1;
6966 const int lastr = last / BITS_PER_LONG;
6968 int wait = rcd != NULL;
6969 unsigned long flags;
6972 unsigned long shadow;
6973 int cstart, previ = -1;
6976 * when flipping from kernel to user, we can't change
6977 * the checking type if the buffer is allocated to the
6978 * driver. It's OK the other direction, because it's
6979 * from close, and we have just disarm'ed all the
6980 * buffers. All the kernel to kernel changes are also
6983 for (cstart = start; cstart <= last; cstart++) {
6984 i = ((2 * cstart) + QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
6987 shadow = (unsigned long)
6988 le64_to_cpu(dd->pioavailregs_dma[i]);
6991 if (test_bit(((2 * cstart) +
6992 QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
6993 % BITS_PER_LONG, &shadow))
7000 if (sleeps == QTXSLEEPS)
7002 /* make sure we see an updated copy next time around */
7003 sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
7009 case TXCHK_CHG_TYPE_DIS1:
7011 * disable checking on a range; used by diags; just
7012 * one buffer, but still written generically
7014 for (i = start; i <= last; i++)
7015 clear_bit(i, dd->cspec->sendchkenable);
7018 case TXCHK_CHG_TYPE_ENAB1:
7020 * (re)enable checking on a range; used by diags; just
7021 * one buffer, but still written generically; read
7022 * scratch to be sure buffer actually triggered, not
7023 * just flushed from processor.
7025 qib_read_kreg32(dd, kr_scratch);
7026 for (i = start; i <= last; i++)
7027 set_bit(i, dd->cspec->sendchkenable);
7030 case TXCHK_CHG_TYPE_KERN:
7031 /* usable by kernel */
7032 for (i = start; i <= last; i++) {
7033 set_bit(i, dd->cspec->sendibchk);
7034 clear_bit(i, dd->cspec->sendgrhchk);
7036 spin_lock_irqsave(&dd->uctxt_lock, flags);
7037 /* see if we need to raise avail update threshold */
7038 for (i = dd->first_user_ctxt;
7039 dd->cspec->updthresh != dd->cspec->updthresh_dflt
7040 && i < dd->cfgctxts; i++)
7041 if (dd->rcd[i] && dd->rcd[i]->subctxt_cnt &&
7042 ((dd->rcd[i]->piocnt / dd->rcd[i]->subctxt_cnt) - 1)
7043 < dd->cspec->updthresh_dflt)
7045 spin_unlock_irqrestore(&dd->uctxt_lock, flags);
7046 if (i == dd->cfgctxts) {
7047 spin_lock_irqsave(&dd->sendctrl_lock, flags);
7048 dd->cspec->updthresh = dd->cspec->updthresh_dflt;
7049 dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
7050 dd->sendctrl |= (dd->cspec->updthresh &
7051 SYM_RMASK(SendCtrl, AvailUpdThld)) <<
7052 SYM_LSB(SendCtrl, AvailUpdThld);
7053 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
7054 sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
7058 case TXCHK_CHG_TYPE_USER:
7059 /* for user process */
7060 for (i = start; i <= last; i++) {
7061 clear_bit(i, dd->cspec->sendibchk);
7062 set_bit(i, dd->cspec->sendgrhchk);
7064 spin_lock_irqsave(&dd->sendctrl_lock, flags);
7065 if (rcd && rcd->subctxt_cnt && ((rcd->piocnt
7066 / rcd->subctxt_cnt) - 1) < dd->cspec->updthresh) {
7067 dd->cspec->updthresh = (rcd->piocnt /
7068 rcd->subctxt_cnt) - 1;
7069 dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
7070 dd->sendctrl |= (dd->cspec->updthresh &
7071 SYM_RMASK(SendCtrl, AvailUpdThld))
7072 << SYM_LSB(SendCtrl, AvailUpdThld);
7073 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
7074 sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
7076 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
7083 for (i = start / BITS_PER_LONG; which >= 2 && i <= lastr; ++i)
7084 qib_write_kreg(dd, kr_sendcheckmask + i,
7085 dd->cspec->sendchkenable[i]);
7087 for (i = start / BITS_PER_LONG; which < 2 && i <= lastr; ++i) {
7088 qib_write_kreg(dd, kr_sendgrhcheckmask + i,
7089 dd->cspec->sendgrhchk[i]);
7090 qib_write_kreg(dd, kr_sendibpktmask + i,
7091 dd->cspec->sendibchk[i]);
7095 * Be sure whatever we did was seen by the chip and acted upon,
7096 * before we return. Mostly important for which >= 2.
7098 qib_read_kreg32(dd, kr_scratch);
7102 /* useful for trigger analyzers, etc. */
7103 static void writescratch(struct qib_devdata *dd, u32 val)
7105 qib_write_kreg(dd, kr_scratch, val);
7108 /* Dummy for now, use chip regs soon */
7109 static int qib_7322_tempsense_rd(struct qib_devdata *dd, int regnum)
7115 * qib_init_iba7322_funcs - set up the chip-specific function pointers
7116 * @dev: the pci_dev for qlogic_ib device
7117 * @ent: pci_device_id struct for this dev
7119 * Also allocates, inits, and returns the devdata struct for this
7122 * This is global, and is called directly at init to set up the
7123 * chip-specific function pointers for later use.
7125 struct qib_devdata *qib_init_iba7322_funcs(struct pci_dev *pdev,
7126 const struct pci_device_id *ent)
7128 struct qib_devdata *dd;
7130 u32 tabsize, actual_cnt = 0;
7132 dd = qib_alloc_devdata(pdev,
7133 NUM_IB_PORTS * sizeof(struct qib_pportdata) +
7134 sizeof(struct qib_chip_specific) +
7135 NUM_IB_PORTS * sizeof(struct qib_chippport_specific));
7139 dd->f_bringup_serdes = qib_7322_bringup_serdes;
7140 dd->f_cleanup = qib_setup_7322_cleanup;
7141 dd->f_clear_tids = qib_7322_clear_tids;
7142 dd->f_free_irq = qib_7322_free_irq;
7143 dd->f_get_base_info = qib_7322_get_base_info;
7144 dd->f_get_msgheader = qib_7322_get_msgheader;
7145 dd->f_getsendbuf = qib_7322_getsendbuf;
7146 dd->f_gpio_mod = gpio_7322_mod;
7147 dd->f_eeprom_wen = qib_7322_eeprom_wen;
7148 dd->f_hdrqempty = qib_7322_hdrqempty;
7149 dd->f_ib_updown = qib_7322_ib_updown;
7150 dd->f_init_ctxt = qib_7322_init_ctxt;
7151 dd->f_initvl15_bufs = qib_7322_initvl15_bufs;
7152 dd->f_intr_fallback = qib_7322_intr_fallback;
7153 dd->f_late_initreg = qib_late_7322_initreg;
7154 dd->f_setpbc_control = qib_7322_setpbc_control;
7155 dd->f_portcntr = qib_portcntr_7322;
7156 dd->f_put_tid = qib_7322_put_tid;
7157 dd->f_quiet_serdes = qib_7322_mini_quiet_serdes;
7158 dd->f_rcvctrl = rcvctrl_7322_mod;
7159 dd->f_read_cntrs = qib_read_7322cntrs;
7160 dd->f_read_portcntrs = qib_read_7322portcntrs;
7161 dd->f_reset = qib_do_7322_reset;
7162 dd->f_init_sdma_regs = init_sdma_7322_regs;
7163 dd->f_sdma_busy = qib_sdma_7322_busy;
7164 dd->f_sdma_gethead = qib_sdma_7322_gethead;
7165 dd->f_sdma_sendctrl = qib_7322_sdma_sendctrl;
7166 dd->f_sdma_set_desc_cnt = qib_sdma_set_7322_desc_cnt;
7167 dd->f_sdma_update_tail = qib_sdma_update_7322_tail;
7168 dd->f_sendctrl = sendctrl_7322_mod;
7169 dd->f_set_armlaunch = qib_set_7322_armlaunch;
7170 dd->f_set_cntr_sample = qib_set_cntr_7322_sample;
7171 dd->f_iblink_state = qib_7322_iblink_state;
7172 dd->f_ibphys_portstate = qib_7322_phys_portstate;
7173 dd->f_get_ib_cfg = qib_7322_get_ib_cfg;
7174 dd->f_set_ib_cfg = qib_7322_set_ib_cfg;
7175 dd->f_set_ib_loopback = qib_7322_set_loopback;
7176 dd->f_get_ib_table = qib_7322_get_ib_table;
7177 dd->f_set_ib_table = qib_7322_set_ib_table;
7178 dd->f_set_intr_state = qib_7322_set_intr_state;
7179 dd->f_setextled = qib_setup_7322_setextled;
7180 dd->f_txchk_change = qib_7322_txchk_change;
7181 dd->f_update_usrhead = qib_update_7322_usrhead;
7182 dd->f_wantpiobuf_intr = qib_wantpiobuf_7322_intr;
7183 dd->f_xgxs_reset = qib_7322_mini_pcs_reset;
7184 dd->f_sdma_hw_clean_up = qib_7322_sdma_hw_clean_up;
7185 dd->f_sdma_hw_start_up = qib_7322_sdma_hw_start_up;
7186 dd->f_sdma_init_early = qib_7322_sdma_init_early;
7187 dd->f_writescratch = writescratch;
7188 dd->f_tempsense_rd = qib_7322_tempsense_rd;
7189 #ifdef CONFIG_INFINIBAND_QIB_DCA
7190 dd->f_notify_dca = qib_7322_notify_dca;
7193 * Do remaining PCIe setup and save PCIe values in dd.
7194 * Any error printing is already done by the init code.
7195 * On return, we have the chip mapped, but chip registers
7196 * are not set up until start of qib_init_7322_variables.
7198 ret = qib_pcie_ddinit(dd, pdev, ent);
7202 /* initialize chip-specific variables */
7203 ret = qib_init_7322_variables(dd);
7207 if (qib_mini_init || !dd->num_pports)
7211 * Determine number of vectors we want; depends on port count
7212 * and number of configured kernel receive queues actually used.
7213 * Should also depend on whether sdma is enabled or not, but
7214 * that's such a rare testing case it's not worth worrying about.
7216 tabsize = dd->first_user_ctxt + ARRAY_SIZE(irq_table);
7217 for (i = 0; i < tabsize; i++)
7218 if ((i < ARRAY_SIZE(irq_table) &&
7219 irq_table[i].port <= dd->num_pports) ||
7220 (i >= ARRAY_SIZE(irq_table) &&
7221 dd->rcd[i - ARRAY_SIZE(irq_table)]))
7223 /* reduce by ctxt's < 2 */
7224 if (qib_krcvq01_no_msi)
7225 actual_cnt -= dd->num_pports;
7227 tabsize = actual_cnt;
7228 dd->cspec->msix_entries = kzalloc(tabsize *
7229 sizeof(struct qib_msix_entry), GFP_KERNEL);
7230 if (!dd->cspec->msix_entries) {
7231 qib_dev_err(dd, "No memory for MSIx table\n");
7234 for (i = 0; i < tabsize; i++)
7235 dd->cspec->msix_entries[i].msix.entry = i;
7237 if (qib_pcie_params(dd, 8, &tabsize, dd->cspec->msix_entries))
7239 "Failed to setup PCIe or interrupts; continuing anyway\n");
7240 /* may be less than we wanted, if not enough available */
7241 dd->cspec->num_msix_entries = tabsize;
7243 /* setup interrupt handler */
7244 qib_setup_7322_interrupt(dd, 1);
7246 /* clear diagctrl register, in case diags were running and crashed */
7247 qib_write_kreg(dd, kr_hwdiagctrl, 0);
7248 #ifdef CONFIG_INFINIBAND_QIB_DCA
7249 if (!dca_add_requester(&pdev->dev)) {
7250 qib_devinfo(dd->pcidev, "DCA enabled\n");
7251 dd->flags |= QIB_DCA_ENABLED;
7258 qib_pcie_ddcleanup(dd);
7260 qib_free_devdata(dd);
7267 * Set the table entry at the specified index from the table specifed.
7268 * There are 3 * TXDDS_TABLE_SZ entries in all per port, with the first
7269 * TXDDS_TABLE_SZ for SDR, the next for DDR, and the last for QDR.
7270 * 'idx' below addresses the correct entry, while its 4 LSBs select the
7271 * corresponding entry (one of TXDDS_TABLE_SZ) from the selected table.
7273 #define DDS_ENT_AMP_LSB 14
7274 #define DDS_ENT_MAIN_LSB 9
7275 #define DDS_ENT_POST_LSB 5
7276 #define DDS_ENT_PRE_XTRA_LSB 3
7277 #define DDS_ENT_PRE_LSB 0
7280 * Set one entry in the TxDDS table for spec'd port
7281 * ridx picks one of the entries, while tp points
7282 * to the appropriate table entry.
7284 static void set_txdds(struct qib_pportdata *ppd, int ridx,
7285 const struct txdds_ent *tp)
7287 struct qib_devdata *dd = ppd->dd;
7291 /* Get correct offset in chip-space, and in source table */
7292 regidx = KREG_IBPORT_IDX(IBSD_DDS_MAP_TABLE) + ridx;
7294 * We do not use qib_write_kreg_port() because it was intended
7295 * only for registers in the lower "port specific" pages.
7296 * So do index calculation by hand.
7299 regidx += (dd->palign / sizeof(u64));
7301 pack_ent = tp->amp << DDS_ENT_AMP_LSB;
7302 pack_ent |= tp->main << DDS_ENT_MAIN_LSB;
7303 pack_ent |= tp->pre << DDS_ENT_PRE_LSB;
7304 pack_ent |= tp->post << DDS_ENT_POST_LSB;
7305 qib_write_kreg(dd, regidx, pack_ent);
7306 /* Prevent back-to-back writes by hitting scratch */
7307 qib_write_kreg(ppd->dd, kr_scratch, 0);
7310 static const struct vendor_txdds_ent vendor_txdds[] = {
7311 { /* Amphenol 1m 30awg NoEq */
7312 { 0x41, 0x50, 0x48 }, "584470002 ",
7313 { 10, 0, 0, 5 }, { 10, 0, 0, 9 }, { 7, 1, 0, 13 },
7315 { /* Amphenol 3m 28awg NoEq */
7316 { 0x41, 0x50, 0x48 }, "584470004 ",
7317 { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 7, 15 },
7319 { /* Finisar 3m OM2 Optical */
7320 { 0x00, 0x90, 0x65 }, "FCBG410QB1C03-QL",
7321 { 0, 0, 0, 3 }, { 0, 0, 0, 4 }, { 0, 0, 0, 13 },
7323 { /* Finisar 30m OM2 Optical */
7324 { 0x00, 0x90, 0x65 }, "FCBG410QB1C30-QL",
7325 { 0, 0, 0, 1 }, { 0, 0, 0, 5 }, { 0, 0, 0, 11 },
7327 { /* Finisar Default OM2 Optical */
7328 { 0x00, 0x90, 0x65 }, NULL,
7329 { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 0, 0, 12 },
7331 { /* Gore 1m 30awg NoEq */
7332 { 0x00, 0x21, 0x77 }, "QSN3300-1 ",
7333 { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 0, 15 },
7335 { /* Gore 2m 30awg NoEq */
7336 { 0x00, 0x21, 0x77 }, "QSN3300-2 ",
7337 { 0, 0, 0, 8 }, { 0, 0, 0, 10 }, { 0, 1, 7, 15 },
7339 { /* Gore 1m 28awg NoEq */
7340 { 0x00, 0x21, 0x77 }, "QSN3800-1 ",
7341 { 0, 0, 0, 6 }, { 0, 0, 0, 8 }, { 0, 1, 0, 15 },
7343 { /* Gore 3m 28awg NoEq */
7344 { 0x00, 0x21, 0x77 }, "QSN3800-3 ",
7345 { 0, 0, 0, 9 }, { 0, 0, 0, 13 }, { 0, 1, 7, 15 },
7347 { /* Gore 5m 24awg Eq */
7348 { 0x00, 0x21, 0x77 }, "QSN7000-5 ",
7349 { 0, 0, 0, 7 }, { 0, 0, 0, 9 }, { 0, 1, 3, 15 },
7351 { /* Gore 7m 24awg Eq */
7352 { 0x00, 0x21, 0x77 }, "QSN7000-7 ",
7353 { 0, 0, 0, 9 }, { 0, 0, 0, 11 }, { 0, 2, 6, 15 },
7355 { /* Gore 5m 26awg Eq */
7356 { 0x00, 0x21, 0x77 }, "QSN7600-5 ",
7357 { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 9, 13 },
7359 { /* Gore 7m 26awg Eq */
7360 { 0x00, 0x21, 0x77 }, "QSN7600-7 ",
7361 { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 10, 1, 8, 15 },
7363 { /* Intersil 12m 24awg Active */
7364 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1224",
7365 { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 3, 0, 9 },
7367 { /* Intersil 10m 28awg Active */
7368 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1028",
7369 { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 2, 0, 2 },
7371 { /* Intersil 7m 30awg Active */
7372 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0730",
7373 { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 1, 0, 3 },
7375 { /* Intersil 5m 32awg Active */
7376 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0532",
7377 { 0, 0, 0, 6 }, { 0, 0, 0, 6 }, { 0, 2, 0, 8 },
7379 { /* Intersil Default Active */
7380 { 0x00, 0x30, 0xB4 }, NULL,
7381 { 0, 0, 0, 6 }, { 0, 0, 0, 5 }, { 0, 2, 0, 5 },
7383 { /* Luxtera 20m Active Optical */
7384 { 0x00, 0x25, 0x63 }, NULL,
7385 { 0, 0, 0, 5 }, { 0, 0, 0, 8 }, { 0, 2, 0, 12 },
7387 { /* Molex 1M Cu loopback */
7388 { 0x00, 0x09, 0x3A }, "74763-0025 ",
7389 { 2, 2, 6, 15 }, { 2, 2, 6, 15 }, { 2, 2, 6, 15 },
7391 { /* Molex 2m 28awg NoEq */
7392 { 0x00, 0x09, 0x3A }, "74757-2201 ",
7393 { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 1, 15 },
7397 static const struct txdds_ent txdds_sdr[TXDDS_TABLE_SZ] = {
7398 /* amp, pre, main, post */
7399 { 2, 2, 15, 6 }, /* Loopback */
7400 { 0, 0, 0, 1 }, /* 2 dB */
7401 { 0, 0, 0, 2 }, /* 3 dB */
7402 { 0, 0, 0, 3 }, /* 4 dB */
7403 { 0, 0, 0, 4 }, /* 5 dB */
7404 { 0, 0, 0, 5 }, /* 6 dB */
7405 { 0, 0, 0, 6 }, /* 7 dB */
7406 { 0, 0, 0, 7 }, /* 8 dB */
7407 { 0, 0, 0, 8 }, /* 9 dB */
7408 { 0, 0, 0, 9 }, /* 10 dB */
7409 { 0, 0, 0, 10 }, /* 11 dB */
7410 { 0, 0, 0, 11 }, /* 12 dB */
7411 { 0, 0, 0, 12 }, /* 13 dB */
7412 { 0, 0, 0, 13 }, /* 14 dB */
7413 { 0, 0, 0, 14 }, /* 15 dB */
7414 { 0, 0, 0, 15 }, /* 16 dB */
7417 static const struct txdds_ent txdds_ddr[TXDDS_TABLE_SZ] = {
7418 /* amp, pre, main, post */
7419 { 2, 2, 15, 6 }, /* Loopback */
7420 { 0, 0, 0, 8 }, /* 2 dB */
7421 { 0, 0, 0, 8 }, /* 3 dB */
7422 { 0, 0, 0, 9 }, /* 4 dB */
7423 { 0, 0, 0, 9 }, /* 5 dB */
7424 { 0, 0, 0, 10 }, /* 6 dB */
7425 { 0, 0, 0, 10 }, /* 7 dB */
7426 { 0, 0, 0, 11 }, /* 8 dB */
7427 { 0, 0, 0, 11 }, /* 9 dB */
7428 { 0, 0, 0, 12 }, /* 10 dB */
7429 { 0, 0, 0, 12 }, /* 11 dB */
7430 { 0, 0, 0, 13 }, /* 12 dB */
7431 { 0, 0, 0, 13 }, /* 13 dB */
7432 { 0, 0, 0, 14 }, /* 14 dB */
7433 { 0, 0, 0, 14 }, /* 15 dB */
7434 { 0, 0, 0, 15 }, /* 16 dB */
7437 static const struct txdds_ent txdds_qdr[TXDDS_TABLE_SZ] = {
7438 /* amp, pre, main, post */
7439 { 2, 2, 15, 6 }, /* Loopback */
7440 { 0, 1, 0, 7 }, /* 2 dB (also QMH7342) */
7441 { 0, 1, 0, 9 }, /* 3 dB (also QMH7342) */
7442 { 0, 1, 0, 11 }, /* 4 dB */
7443 { 0, 1, 0, 13 }, /* 5 dB */
7444 { 0, 1, 0, 15 }, /* 6 dB */
7445 { 0, 1, 3, 15 }, /* 7 dB */
7446 { 0, 1, 7, 15 }, /* 8 dB */
7447 { 0, 1, 7, 15 }, /* 9 dB */
7448 { 0, 1, 8, 15 }, /* 10 dB */
7449 { 0, 1, 9, 15 }, /* 11 dB */
7450 { 0, 1, 10, 15 }, /* 12 dB */
7451 { 0, 2, 6, 15 }, /* 13 dB */
7452 { 0, 2, 7, 15 }, /* 14 dB */
7453 { 0, 2, 8, 15 }, /* 15 dB */
7454 { 0, 2, 9, 15 }, /* 16 dB */
7458 * extra entries for use with txselect, for indices >= TXDDS_TABLE_SZ.
7459 * These are mostly used for mez cards going through connectors
7460 * and backplane traces, but can be used to add other "unusual"
7461 * table values as well.
7463 static const struct txdds_ent txdds_extra_sdr[TXDDS_EXTRA_SZ] = {
7464 /* amp, pre, main, post */
7465 { 0, 0, 0, 1 }, /* QMH7342 backplane settings */
7466 { 0, 0, 0, 1 }, /* QMH7342 backplane settings */
7467 { 0, 0, 0, 2 }, /* QMH7342 backplane settings */
7468 { 0, 0, 0, 2 }, /* QMH7342 backplane settings */
7469 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
7470 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
7471 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
7472 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
7473 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
7474 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
7475 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
7476 { 0, 0, 0, 3 }, /* QMH7342 backplane settings */
7477 { 0, 0, 0, 4 }, /* QMH7342 backplane settings */
7480 static const struct txdds_ent txdds_extra_ddr[TXDDS_EXTRA_SZ] = {
7481 /* amp, pre, main, post */
7482 { 0, 0, 0, 7 }, /* QMH7342 backplane settings */
7483 { 0, 0, 0, 7 }, /* QMH7342 backplane settings */
7484 { 0, 0, 0, 8 }, /* QMH7342 backplane settings */
7485 { 0, 0, 0, 8 }, /* QMH7342 backplane settings */
7486 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
7487 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
7488 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
7489 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
7490 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
7491 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
7492 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
7493 { 0, 0, 0, 9 }, /* QMH7342 backplane settings */
7494 { 0, 0, 0, 10 }, /* QMH7342 backplane settings */
7497 static const struct txdds_ent txdds_extra_qdr[TXDDS_EXTRA_SZ] = {
7498 /* amp, pre, main, post */
7499 { 0, 1, 0, 4 }, /* QMH7342 backplane settings */
7500 { 0, 1, 0, 5 }, /* QMH7342 backplane settings */
7501 { 0, 1, 0, 6 }, /* QMH7342 backplane settings */
7502 { 0, 1, 0, 8 }, /* QMH7342 backplane settings */
7503 { 0, 1, 12, 10 }, /* QME7342 backplane setting */
7504 { 0, 1, 12, 11 }, /* QME7342 backplane setting */
7505 { 0, 1, 12, 12 }, /* QME7342 backplane setting */
7506 { 0, 1, 12, 14 }, /* QME7342 backplane setting */
7507 { 0, 1, 12, 6 }, /* QME7342 backplane setting */
7508 { 0, 1, 12, 7 }, /* QME7342 backplane setting */
7509 { 0, 1, 12, 8 }, /* QME7342 backplane setting */
7510 { 0, 1, 0, 10 }, /* QMH7342 backplane settings */
7511 { 0, 1, 0, 12 }, /* QMH7342 backplane settings */
7514 static const struct txdds_ent txdds_extra_mfg[TXDDS_MFG_SZ] = {
7515 /* amp, pre, main, post */
7516 { 0, 0, 0, 0 }, /* QME7342 mfg settings */
7517 { 0, 0, 0, 6 }, /* QME7342 P2 mfg settings */
7520 static const struct txdds_ent *get_atten_table(const struct txdds_ent *txdds,
7524 * The attenuation table starts at 2dB for entry 1,
7525 * with entry 0 being the loopback entry.
7529 else if (atten > TXDDS_TABLE_SZ)
7530 atten = TXDDS_TABLE_SZ - 1;
7533 return txdds + atten;
7537 * if override is set, the module parameter txselect has a value
7538 * for this specific port, so use it, rather than our normal mechanism.
7540 static void find_best_ent(struct qib_pportdata *ppd,
7541 const struct txdds_ent **sdr_dds,
7542 const struct txdds_ent **ddr_dds,
7543 const struct txdds_ent **qdr_dds, int override)
7545 struct qib_qsfp_cache *qd = &ppd->cpspec->qsfp_data.cache;
7548 /* Search table of known cables */
7549 for (idx = 0; !override && idx < ARRAY_SIZE(vendor_txdds); ++idx) {
7550 const struct vendor_txdds_ent *v = vendor_txdds + idx;
7552 if (!memcmp(v->oui, qd->oui, QSFP_VOUI_LEN) &&
7554 !memcmp(v->partnum, qd->partnum, QSFP_PN_LEN))) {
7562 /* Active cables don't have attenuation so we only set SERDES
7563 * settings to account for the attenuation of the board traces. */
7564 if (!override && QSFP_IS_ACTIVE(qd->tech)) {
7565 *sdr_dds = txdds_sdr + ppd->dd->board_atten;
7566 *ddr_dds = txdds_ddr + ppd->dd->board_atten;
7567 *qdr_dds = txdds_qdr + ppd->dd->board_atten;
7571 if (!override && QSFP_HAS_ATTEN(qd->tech) && (qd->atten[0] ||
7573 *sdr_dds = get_atten_table(txdds_sdr, qd->atten[0]);
7574 *ddr_dds = get_atten_table(txdds_ddr, qd->atten[0]);
7575 *qdr_dds = get_atten_table(txdds_qdr, qd->atten[1]);
7577 } else if (ppd->cpspec->no_eep < TXDDS_TABLE_SZ) {
7579 * If we have no (or incomplete) data from the cable
7580 * EEPROM, or no QSFP, or override is set, use the
7581 * module parameter value to index into the attentuation
7584 idx = ppd->cpspec->no_eep;
7585 *sdr_dds = &txdds_sdr[idx];
7586 *ddr_dds = &txdds_ddr[idx];
7587 *qdr_dds = &txdds_qdr[idx];
7588 } else if (ppd->cpspec->no_eep < (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ)) {
7589 /* similar to above, but index into the "extra" table. */
7590 idx = ppd->cpspec->no_eep - TXDDS_TABLE_SZ;
7591 *sdr_dds = &txdds_extra_sdr[idx];
7592 *ddr_dds = &txdds_extra_ddr[idx];
7593 *qdr_dds = &txdds_extra_qdr[idx];
7594 } else if ((IS_QME(ppd->dd) || IS_QMH(ppd->dd)) &&
7595 ppd->cpspec->no_eep < (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
7597 idx = ppd->cpspec->no_eep - (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ);
7598 pr_info("IB%u:%u use idx %u into txdds_mfg\n",
7599 ppd->dd->unit, ppd->port, idx);
7600 *sdr_dds = &txdds_extra_mfg[idx];
7601 *ddr_dds = &txdds_extra_mfg[idx];
7602 *qdr_dds = &txdds_extra_mfg[idx];
7604 /* this shouldn't happen, it's range checked */
7605 *sdr_dds = txdds_sdr + qib_long_atten;
7606 *ddr_dds = txdds_ddr + qib_long_atten;
7607 *qdr_dds = txdds_qdr + qib_long_atten;
7611 static void init_txdds_table(struct qib_pportdata *ppd, int override)
7613 const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
7614 struct txdds_ent *dds;
7618 find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, override);
7620 /* for mez cards or override, use the selected value for all entries */
7621 if (!(ppd->dd->flags & QIB_HAS_QSFP) || override)
7624 /* Fill in the first entry with the best entry found. */
7625 set_txdds(ppd, 0, sdr_dds);
7626 set_txdds(ppd, TXDDS_TABLE_SZ, ddr_dds);
7627 set_txdds(ppd, 2 * TXDDS_TABLE_SZ, qdr_dds);
7628 if (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
7630 dds = (struct txdds_ent *)(ppd->link_speed_active ==
7631 QIB_IB_QDR ? qdr_dds :
7632 (ppd->link_speed_active ==
7633 QIB_IB_DDR ? ddr_dds : sdr_dds));
7634 write_tx_serdes_param(ppd, dds);
7637 /* Fill in the remaining entries with the default table values. */
7638 for (idx = 1; idx < ARRAY_SIZE(txdds_sdr); ++idx) {
7639 set_txdds(ppd, idx, single_ent ? sdr_dds : txdds_sdr + idx);
7640 set_txdds(ppd, idx + TXDDS_TABLE_SZ,
7641 single_ent ? ddr_dds : txdds_ddr + idx);
7642 set_txdds(ppd, idx + 2 * TXDDS_TABLE_SZ,
7643 single_ent ? qdr_dds : txdds_qdr + idx);
7647 #define KR_AHB_ACC KREG_IDX(ahb_access_ctrl)
7648 #define KR_AHB_TRANS KREG_IDX(ahb_transaction_reg)
7649 #define AHB_TRANS_RDY SYM_MASK(ahb_transaction_reg, ahb_rdy)
7650 #define AHB_ADDR_LSB SYM_LSB(ahb_transaction_reg, ahb_address)
7651 #define AHB_DATA_LSB SYM_LSB(ahb_transaction_reg, ahb_data)
7652 #define AHB_WR SYM_MASK(ahb_transaction_reg, write_not_read)
7653 #define AHB_TRANS_TRIES 10
7656 * The chan argument is 0=chan0, 1=chan1, 2=pll, 3=chan2, 4=chan4,
7657 * 5=subsystem which is why most calls have "chan + chan >> 1"
7658 * for the channel argument.
7660 static u32 ahb_mod(struct qib_devdata *dd, int quad, int chan, int addr,
7663 u32 rd_data, wr_data, sz_mask;
7664 u64 trans, acc, prev_acc;
7665 u32 ret = 0xBAD0BAD;
7668 prev_acc = qib_read_kreg64(dd, KR_AHB_ACC);
7669 /* From this point on, make sure we return access */
7670 acc = (quad << 1) | 1;
7671 qib_write_kreg(dd, KR_AHB_ACC, acc);
7673 for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
7674 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7675 if (trans & AHB_TRANS_RDY)
7678 if (tries >= AHB_TRANS_TRIES) {
7679 qib_dev_err(dd, "No ahb_rdy in %d tries\n", AHB_TRANS_TRIES);
7683 /* If mask is not all 1s, we need to read, but different SerDes
7684 * entities have different sizes
7686 sz_mask = (1UL << ((quad == 1) ? 32 : 16)) - 1;
7687 wr_data = data & mask & sz_mask;
7688 if ((~mask & sz_mask) != 0) {
7689 trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
7690 qib_write_kreg(dd, KR_AHB_TRANS, trans);
7692 for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
7693 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7694 if (trans & AHB_TRANS_RDY)
7697 if (tries >= AHB_TRANS_TRIES) {
7698 qib_dev_err(dd, "No Rd ahb_rdy in %d tries\n",
7702 /* Re-read in case host split reads and read data first */
7703 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7704 rd_data = (uint32_t)(trans >> AHB_DATA_LSB);
7705 wr_data |= (rd_data & ~mask & sz_mask);
7708 /* If mask is not zero, we need to write. */
7709 if (mask & sz_mask) {
7710 trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
7711 trans |= ((uint64_t)wr_data << AHB_DATA_LSB);
7713 qib_write_kreg(dd, KR_AHB_TRANS, trans);
7715 for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
7716 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7717 if (trans & AHB_TRANS_RDY)
7720 if (tries >= AHB_TRANS_TRIES) {
7721 qib_dev_err(dd, "No Wr ahb_rdy in %d tries\n",
7728 qib_write_kreg(dd, KR_AHB_ACC, prev_acc);
7732 static void ibsd_wr_allchans(struct qib_pportdata *ppd, int addr, unsigned data,
7735 struct qib_devdata *dd = ppd->dd;
7739 for (chan = 0; chan < SERDES_CHANS; ++chan) {
7740 ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)), addr,
7742 rbc = ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7747 static void serdes_7322_los_enable(struct qib_pportdata *ppd, int enable)
7749 u64 data = qib_read_kreg_port(ppd, krp_serdesctrl);
7750 u8 state = SYM_FIELD(data, IBSerdesCtrl_0, RXLOSEN);
7752 if (enable && !state) {
7753 pr_info("IB%u:%u Turning LOS on\n",
7754 ppd->dd->unit, ppd->port);
7755 data |= SYM_MASK(IBSerdesCtrl_0, RXLOSEN);
7756 } else if (!enable && state) {
7757 pr_info("IB%u:%u Turning LOS off\n",
7758 ppd->dd->unit, ppd->port);
7759 data &= ~SYM_MASK(IBSerdesCtrl_0, RXLOSEN);
7761 qib_write_kreg_port(ppd, krp_serdesctrl, data);
7764 static int serdes_7322_init(struct qib_pportdata *ppd)
7767 if (ppd->dd->cspec->r1)
7768 ret = serdes_7322_init_old(ppd);
7770 ret = serdes_7322_init_new(ppd);
7774 static int serdes_7322_init_old(struct qib_pportdata *ppd)
7779 * Initialize the Tx DDS tables. Also done every QSFP event,
7780 * for adapters with QSFP
7782 init_txdds_table(ppd, 0);
7784 /* ensure no tx overrides from earlier driver loads */
7785 qib_write_kreg_port(ppd, krp_tx_deemph_override,
7786 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7787 reset_tx_deemphasis_override));
7789 /* Patch some SerDes defaults to "Better for IB" */
7790 /* Timing Loop Bandwidth: cdr_timing[11:9] = 0 */
7791 ibsd_wr_allchans(ppd, 2, 0, BMASK(11, 9));
7793 /* Termination: rxtermctrl_r2d addr 11 bits [12:11] = 1 */
7794 ibsd_wr_allchans(ppd, 11, (1 << 11), BMASK(12, 11));
7795 /* Enable LE2: rxle2en_r2a addr 13 bit [6] = 1 */
7796 ibsd_wr_allchans(ppd, 13, (1 << 6), (1 << 6));
7798 /* May be overridden in qsfp_7322_event */
7799 le_val = IS_QME(ppd->dd) ? LE2_QME : LE2_DEFAULT;
7800 ibsd_wr_allchans(ppd, 13, (le_val << 7), BMASK(9, 7));
7802 /* enable LE1 adaptation for all but QME, which is disabled */
7803 le_val = IS_QME(ppd->dd) ? 0 : 1;
7804 ibsd_wr_allchans(ppd, 13, (le_val << 5), (1 << 5));
7806 /* Clear cmode-override, may be set from older driver */
7807 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
7809 /* Timing Recovery: rxtapsel addr 5 bits [9:8] = 0 */
7810 ibsd_wr_allchans(ppd, 5, (0 << 8), BMASK(9, 8));
7812 /* setup LoS params; these are subsystem, so chan == 5 */
7813 /* LoS filter threshold_count on, ch 0-3, set to 8 */
7814 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 5, 8 << 11, BMASK(14, 11));
7815 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 8 << 4, BMASK(7, 4));
7816 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 8, 8 << 11, BMASK(14, 11));
7817 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 8 << 4, BMASK(7, 4));
7819 /* LoS filter threshold_count off, ch 0-3, set to 4 */
7820 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 6, 4 << 0, BMASK(3, 0));
7821 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 4 << 8, BMASK(11, 8));
7822 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 4 << 0, BMASK(3, 0));
7823 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 4 << 8, BMASK(11, 8));
7825 /* LoS filter select enabled */
7826 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 1 << 15, 1 << 15);
7828 /* LoS target data: SDR=4, DDR=2, QDR=1 */
7829 ibsd_wr_allchans(ppd, 14, (1 << 3), BMASK(5, 3)); /* QDR */
7830 ibsd_wr_allchans(ppd, 20, (2 << 10), BMASK(12, 10)); /* DDR */
7831 ibsd_wr_allchans(ppd, 20, (4 << 13), BMASK(15, 13)); /* SDR */
7833 serdes_7322_los_enable(ppd, 1);
7835 /* rxbistena; set 0 to avoid effects of it switch later */
7836 ibsd_wr_allchans(ppd, 9, 0 << 15, 1 << 15);
7838 /* Configure 4 DFE taps, and only they adapt */
7839 ibsd_wr_allchans(ppd, 16, 0 << 0, BMASK(1, 0));
7841 /* gain hi stop 32 (22) (6:1) lo stop 7 (10:7) target 22 (13) (15:11) */
7842 le_val = (ppd->dd->cspec->r1 || IS_QME(ppd->dd)) ? 0xb6c0 : 0x6bac;
7843 ibsd_wr_allchans(ppd, 21, le_val, 0xfffe);
7846 * Set receive adaptation mode. SDR and DDR adaptation are
7847 * always on, and QDR is initially enabled; later disabled.
7849 qib_write_kreg_port(ppd, krp_static_adapt_dis(0), 0ULL);
7850 qib_write_kreg_port(ppd, krp_static_adapt_dis(1), 0ULL);
7851 qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
7852 ppd->dd->cspec->r1 ?
7853 QDR_STATIC_ADAPT_DOWN_R1 : QDR_STATIC_ADAPT_DOWN);
7854 ppd->cpspec->qdr_dfe_on = 1;
7856 /* FLoop LOS gate: PPM filter enabled */
7857 ibsd_wr_allchans(ppd, 38, 0 << 10, 1 << 10);
7859 /* rx offset center enabled */
7860 ibsd_wr_allchans(ppd, 12, 1 << 4, 1 << 4);
7862 if (!ppd->dd->cspec->r1) {
7863 ibsd_wr_allchans(ppd, 12, 1 << 12, 1 << 12);
7864 ibsd_wr_allchans(ppd, 12, 2 << 8, 0x0f << 8);
7867 /* Set the frequency loop bandwidth to 15 */
7868 ibsd_wr_allchans(ppd, 2, 15 << 5, BMASK(8, 5));
7873 static int serdes_7322_init_new(struct qib_pportdata *ppd)
7876 u32 le_val, rxcaldone;
7877 int chan, chan_done = (1 << SERDES_CHANS) - 1;
7879 /* Clear cmode-override, may be set from older driver */
7880 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
7882 /* ensure no tx overrides from earlier driver loads */
7883 qib_write_kreg_port(ppd, krp_tx_deemph_override,
7884 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7885 reset_tx_deemphasis_override));
7887 /* START OF LSI SUGGESTED SERDES BRINGUP */
7888 /* Reset - Calibration Setup */
7889 /* Stop DFE adaptaion */
7890 ibsd_wr_allchans(ppd, 1, 0, BMASK(9, 1));
7892 ibsd_wr_allchans(ppd, 13, 0, BMASK(5, 5));
7893 /* Disable autoadapt for LE1 */
7894 ibsd_wr_allchans(ppd, 1, 0, BMASK(15, 15));
7896 ibsd_wr_allchans(ppd, 13, 0, BMASK(6, 6));
7898 ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0));
7899 /* Disable AFE Offset Cancel */
7900 ibsd_wr_allchans(ppd, 12, 0, BMASK(12, 12));
7901 /* Disable Timing Loop */
7902 ibsd_wr_allchans(ppd, 2, 0, BMASK(3, 3));
7903 /* Disable Frequency Loop */
7904 ibsd_wr_allchans(ppd, 2, 0, BMASK(4, 4));
7905 /* Disable Baseline Wander Correction */
7906 ibsd_wr_allchans(ppd, 13, 0, BMASK(13, 13));
7907 /* Disable RX Calibration */
7908 ibsd_wr_allchans(ppd, 4, 0, BMASK(10, 10));
7909 /* Disable RX Offset Calibration */
7910 ibsd_wr_allchans(ppd, 12, 0, BMASK(4, 4));
7912 ibsd_wr_allchans(ppd, 2, (1 << 15), BMASK(15, 15));
7914 ibsd_wr_allchans(ppd, 5, 0, BMASK(9, 8));
7915 /* Enable phase Calibration */
7916 ibsd_wr_allchans(ppd, 12, (1 << 5), BMASK(5, 5));
7917 /* DFE Bandwidth [2:14-12] */
7918 ibsd_wr_allchans(ppd, 2, (4 << 12), BMASK(14, 12));
7919 /* DFE Config (4 taps only) */
7920 ibsd_wr_allchans(ppd, 16, 0, BMASK(1, 0));
7921 /* Gain Loop Bandwidth */
7922 if (!ppd->dd->cspec->r1) {
7923 ibsd_wr_allchans(ppd, 12, 1 << 12, BMASK(12, 12));
7924 ibsd_wr_allchans(ppd, 12, 2 << 8, BMASK(11, 8));
7926 ibsd_wr_allchans(ppd, 19, (3 << 11), BMASK(13, 11));
7928 /* Baseline Wander Correction Gain [13:4-0] (leave as default) */
7929 /* Baseline Wander Correction Gain [3:7-5] (leave as default) */
7930 /* Data Rate Select [5:7-6] (leave as default) */
7931 /* RX Parallel Word Width [3:10-8] (leave as default) */
7934 /* Single- or Multi-channel reset */
7935 /* RX Analog reset */
7936 /* RX Digital reset */
7937 ibsd_wr_allchans(ppd, 0, 0, BMASK(15, 13));
7939 /* RX Analog reset */
7940 ibsd_wr_allchans(ppd, 0, (1 << 14), BMASK(14, 14));
7942 /* RX Digital reset */
7943 ibsd_wr_allchans(ppd, 0, (1 << 13), BMASK(13, 13));
7946 /* setup LoS params; these are subsystem, so chan == 5 */
7947 /* LoS filter threshold_count on, ch 0-3, set to 8 */
7948 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 5, 8 << 11, BMASK(14, 11));
7949 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 8 << 4, BMASK(7, 4));
7950 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 8, 8 << 11, BMASK(14, 11));
7951 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 8 << 4, BMASK(7, 4));
7953 /* LoS filter threshold_count off, ch 0-3, set to 4 */
7954 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 6, 4 << 0, BMASK(3, 0));
7955 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 4 << 8, BMASK(11, 8));
7956 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 4 << 0, BMASK(3, 0));
7957 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 4 << 8, BMASK(11, 8));
7959 /* LoS filter select enabled */
7960 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 1 << 15, 1 << 15);
7962 /* LoS target data: SDR=4, DDR=2, QDR=1 */
7963 ibsd_wr_allchans(ppd, 14, (1 << 3), BMASK(5, 3)); /* QDR */
7964 ibsd_wr_allchans(ppd, 20, (2 << 10), BMASK(12, 10)); /* DDR */
7965 ibsd_wr_allchans(ppd, 20, (4 << 13), BMASK(15, 13)); /* SDR */
7967 /* Turn on LOS on initial SERDES init */
7968 serdes_7322_los_enable(ppd, 1);
7969 /* FLoop LOS gate: PPM filter enabled */
7970 ibsd_wr_allchans(ppd, 38, 0 << 10, 1 << 10);
7972 /* RX LATCH CALIBRATION */
7973 /* Enable Eyefinder Phase Calibration latch */
7974 ibsd_wr_allchans(ppd, 15, 1, BMASK(0, 0));
7975 /* Enable RX Offset Calibration latch */
7976 ibsd_wr_allchans(ppd, 12, (1 << 4), BMASK(4, 4));
7978 /* Start Calibration */
7979 ibsd_wr_allchans(ppd, 4, (1 << 10), BMASK(10, 10));
7980 tend = jiffies + msecs_to_jiffies(500);
7981 while (chan_done && !time_is_before_jiffies(tend)) {
7983 for (chan = 0; chan < SERDES_CHANS; ++chan) {
7984 rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx),
7985 (chan + (chan >> 1)),
7987 if ((~rxcaldone & (u32)BMASK(9, 9)) == 0 &&
7988 (~chan_done & (1 << chan)) == 0)
7989 chan_done &= ~(1 << chan);
7993 pr_info("Serdes %d calibration not done after .5 sec: 0x%x\n",
7994 IBSD(ppd->hw_pidx), chan_done);
7996 for (chan = 0; chan < SERDES_CHANS; ++chan) {
7997 rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx),
7998 (chan + (chan >> 1)),
8000 if ((~rxcaldone & (u32)BMASK(10, 10)) == 0)
8001 pr_info("Serdes %d chan %d calibration failed\n",
8002 IBSD(ppd->hw_pidx), chan);
8006 /* Turn off Calibration */
8007 ibsd_wr_allchans(ppd, 4, 0, BMASK(10, 10));
8011 /* Set LE2 value (May be overridden in qsfp_7322_event) */
8012 le_val = IS_QME(ppd->dd) ? LE2_QME : LE2_DEFAULT;
8013 ibsd_wr_allchans(ppd, 13, (le_val << 7), BMASK(9, 7));
8014 /* Set LE2 Loop bandwidth */
8015 ibsd_wr_allchans(ppd, 3, (7 << 5), BMASK(7, 5));
8017 ibsd_wr_allchans(ppd, 13, (1 << 6), BMASK(6, 6));
8019 /* Enable H0 only */
8020 ibsd_wr_allchans(ppd, 1, 1, BMASK(9, 1));
8021 /* gain hi stop 32 (22) (6:1) lo stop 7 (10:7) target 22 (13) (15:11) */
8022 le_val = (ppd->dd->cspec->r1 || IS_QME(ppd->dd)) ? 0xb6c0 : 0x6bac;
8023 ibsd_wr_allchans(ppd, 21, le_val, 0xfffe);
8025 ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0));
8027 /* Set Frequency Loop Bandwidth */
8028 ibsd_wr_allchans(ppd, 2, (15 << 5), BMASK(8, 5));
8029 /* Enable Frequency Loop */
8030 ibsd_wr_allchans(ppd, 2, (1 << 4), BMASK(4, 4));
8031 /* Set Timing Loop Bandwidth */
8032 ibsd_wr_allchans(ppd, 2, 0, BMASK(11, 9));
8033 /* Enable Timing Loop */
8034 ibsd_wr_allchans(ppd, 2, (1 << 3), BMASK(3, 3));
8037 * Set receive adaptation mode. SDR and DDR adaptation are
8038 * always on, and QDR is initially enabled; later disabled.
8040 qib_write_kreg_port(ppd, krp_static_adapt_dis(0), 0ULL);
8041 qib_write_kreg_port(ppd, krp_static_adapt_dis(1), 0ULL);
8042 qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
8043 ppd->dd->cspec->r1 ?
8044 QDR_STATIC_ADAPT_DOWN_R1 : QDR_STATIC_ADAPT_DOWN);
8045 ppd->cpspec->qdr_dfe_on = 1;
8047 ibsd_wr_allchans(ppd, 13, (0 << 5), (1 << 5));
8048 /* Disable auto adapt for LE1 */
8049 ibsd_wr_allchans(ppd, 1, (0 << 15), BMASK(15, 15));
8051 /* Enable AFE Offset Cancel */
8052 ibsd_wr_allchans(ppd, 12, (1 << 12), BMASK(12, 12));
8053 /* Enable Baseline Wander Correction */
8054 ibsd_wr_allchans(ppd, 12, (1 << 13), BMASK(13, 13));
8055 /* Termination: rxtermctrl_r2d addr 11 bits [12:11] = 1 */
8056 ibsd_wr_allchans(ppd, 11, (1 << 11), BMASK(12, 11));
8057 /* VGA output common mode */
8058 ibsd_wr_allchans(ppd, 12, (3 << 2), BMASK(3, 2));
8061 * Initialize the Tx DDS tables. Also done every QSFP event,
8062 * for adapters with QSFP
8064 init_txdds_table(ppd, 0);
8069 /* start adjust QMH serdes parameters */
8071 static void set_man_code(struct qib_pportdata *ppd, int chan, int code)
8073 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
8074 9, code << 9, 0x3f << 9);
8077 static void set_man_mode_h1(struct qib_pportdata *ppd, int chan,
8078 int enable, u32 tapenable)
8081 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
8082 1, 3 << 10, 0x1f << 10);
8084 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
8088 /* Set clock to 1, 0, 1, 0 */
8089 static void clock_man(struct qib_pportdata *ppd, int chan)
8091 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
8093 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
8095 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
8097 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
8102 * write the current Tx serdes pre,post,main,amp settings into the serdes.
8103 * The caller must pass the settings appropriate for the current speed,
8104 * or not care if they are correct for the current speed.
8106 static void write_tx_serdes_param(struct qib_pportdata *ppd,
8107 struct txdds_ent *txdds)
8111 deemph = qib_read_kreg_port(ppd, krp_tx_deemph_override);
8112 /* field names for amp, main, post, pre, respectively */
8113 deemph &= ~(SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txampcntl_d2a) |
8114 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txc0_ena) |
8115 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcp1_ena) |
8116 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcn1_ena));
8118 deemph |= SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8119 tx_override_deemphasis_select);
8120 deemph |= (txdds->amp & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8121 txampcntl_d2a)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8123 deemph |= (txdds->main & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8124 txc0_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8126 deemph |= (txdds->post & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8127 txcp1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8129 deemph |= (txdds->pre & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8130 txcn1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
8132 qib_write_kreg_port(ppd, krp_tx_deemph_override, deemph);
8136 * Set the parameters for mez cards on link bounce, so they are
8137 * always exactly what was requested. Similar logic to init_txdds
8138 * but does just the serdes.
8140 static void adj_tx_serdes(struct qib_pportdata *ppd)
8142 const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
8143 struct txdds_ent *dds;
8145 find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, 1);
8146 dds = (struct txdds_ent *)(ppd->link_speed_active == QIB_IB_QDR ?
8147 qdr_dds : (ppd->link_speed_active == QIB_IB_DDR ?
8148 ddr_dds : sdr_dds));
8149 write_tx_serdes_param(ppd, dds);
8152 /* set QDR forced value for H1, if needed */
8153 static void force_h1(struct qib_pportdata *ppd)
8157 ppd->cpspec->qdr_reforce = 0;
8158 if (!ppd->dd->cspec->r1)
8161 for (chan = 0; chan < SERDES_CHANS; chan++) {
8162 set_man_mode_h1(ppd, chan, 1, 0);
8163 set_man_code(ppd, chan, ppd->cpspec->h1_val);
8164 clock_man(ppd, chan);
8165 set_man_mode_h1(ppd, chan, 0, 0);
8169 #define SJA_EN SYM_MASK(SPC_JTAG_ACCESS_REG, SPC_JTAG_ACCESS_EN)
8170 #define BISTEN_LSB SYM_LSB(SPC_JTAG_ACCESS_REG, bist_en)
8172 #define R_OPCODE_LSB 3
8174 #define R_OP_SHIFT 2
8175 #define R_OP_UPDATE 3
8180 static int qib_r_grab(struct qib_devdata *dd)
8184 qib_write_kreg(dd, kr_r_access, val);
8185 qib_read_kreg32(dd, kr_scratch);
8189 /* qib_r_wait_for_rdy() not only waits for the ready bit, it
8190 * returns the current state of R_TDO
8192 static int qib_r_wait_for_rdy(struct qib_devdata *dd)
8196 for (timeout = 0; timeout < 100 ; ++timeout) {
8197 val = qib_read_kreg32(dd, kr_r_access);
8199 return (val >> R_TDO_LSB) & 1;
8204 static int qib_r_shift(struct qib_devdata *dd, int bisten,
8205 int len, u8 *inp, u8 *outp)
8210 valbase = SJA_EN | (bisten << BISTEN_LSB) |
8211 (R_OP_SHIFT << R_OPCODE_LSB);
8212 ret = qib_r_wait_for_rdy(dd);
8215 for (pos = 0; pos < len; ++pos) {
8218 outp[pos >> 3] &= ~(1 << (pos & 7));
8219 outp[pos >> 3] |= (ret << (pos & 7));
8222 int tdi = inp[pos >> 3] >> (pos & 7);
8223 val |= ((tdi & 1) << R_TDI_LSB);
8225 qib_write_kreg(dd, kr_r_access, val);
8226 qib_read_kreg32(dd, kr_scratch);
8227 ret = qib_r_wait_for_rdy(dd);
8231 /* Restore to NOP between operations. */
8232 val = SJA_EN | (bisten << BISTEN_LSB);
8233 qib_write_kreg(dd, kr_r_access, val);
8234 qib_read_kreg32(dd, kr_scratch);
8235 ret = qib_r_wait_for_rdy(dd);
8243 static int qib_r_update(struct qib_devdata *dd, int bisten)
8248 val = SJA_EN | (bisten << BISTEN_LSB) | (R_OP_UPDATE << R_OPCODE_LSB);
8249 ret = qib_r_wait_for_rdy(dd);
8251 qib_write_kreg(dd, kr_r_access, val);
8252 qib_read_kreg32(dd, kr_scratch);
8257 #define BISTEN_PORT_SEL 15
8258 #define LEN_PORT_SEL 625
8259 #define BISTEN_AT 17
8261 #define BISTEN_ETM 16
8264 #define BIT2BYTE(x) (((x) + BITS_PER_BYTE - 1) / BITS_PER_BYTE)
8266 /* these are common for all IB port use cases. */
8267 static u8 reset_at[BIT2BYTE(LEN_AT)] = {
8268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
8271 static u8 reset_atetm[BIT2BYTE(LEN_ETM)] = {
8272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8273 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8274 0x00, 0x00, 0x00, 0x80, 0xe3, 0x81, 0x73, 0x3c, 0x70, 0x8e,
8275 0x07, 0xce, 0xf1, 0xc0, 0x39, 0x1e, 0x38, 0xc7, 0x03, 0xe7,
8276 0x78, 0xe0, 0x1c, 0x0f, 0x9c, 0x7f, 0x80, 0x73, 0x0f, 0x70,
8277 0xde, 0x01, 0xce, 0x39, 0xc0, 0xf9, 0x06, 0x38, 0xd7, 0x00,
8278 0xe7, 0x19, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8279 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
8281 static u8 at[BIT2BYTE(LEN_AT)] = {
8282 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
8283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
8286 /* used for IB1 or IB2, only one in use */
8287 static u8 atetm_1port[BIT2BYTE(LEN_ETM)] = {
8288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8291 0x00, 0x10, 0xf2, 0x80, 0x83, 0x1e, 0x38, 0x00, 0x00, 0x00,
8292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8293 0x00, 0x00, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xc8, 0x03,
8294 0x07, 0x7b, 0xa0, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x18, 0x00,
8295 0x18, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00,
8298 /* used when both IB1 and IB2 are in use */
8299 static u8 atetm_2port[BIT2BYTE(LEN_ETM)] = {
8300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79,
8302 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8303 0x00, 0x00, 0xf8, 0x80, 0x83, 0x1e, 0x38, 0xe0, 0x03, 0x05,
8304 0x7b, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
8305 0xa2, 0x0f, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xd1, 0x07,
8306 0x02, 0x7c, 0x80, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x3e, 0x00,
8307 0x02, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00,
8310 /* used when only IB1 is in use */
8311 static u8 portsel_port1[BIT2BYTE(LEN_PORT_SEL)] = {
8312 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
8313 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
8314 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
8315 0x13, 0x78, 0x78, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
8316 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
8317 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
8318 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
8319 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
8322 /* used when only IB2 is in use */
8323 static u8 portsel_port2[BIT2BYTE(LEN_PORT_SEL)] = {
8324 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x39, 0x39,
8325 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x73, 0x32, 0x32, 0x32,
8326 0x32, 0x32, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
8327 0x39, 0x78, 0x78, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
8328 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x74, 0x32,
8329 0x32, 0x32, 0x32, 0x32, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
8330 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
8331 0x3a, 0x3a, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
8334 /* used when both IB1 and IB2 are in use */
8335 static u8 portsel_2port[BIT2BYTE(LEN_PORT_SEL)] = {
8336 0x32, 0xba, 0x54, 0x76, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
8337 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
8338 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
8339 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
8340 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
8341 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x3a,
8342 0x3a, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
8343 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
8347 * Do setup to properly handle IB link recovery; if port is zero, we
8348 * are initializing to cover both ports; otherwise we are initializing
8349 * to cover a single port card, or the port has reached INIT and we may
8350 * need to switch coverage types.
8352 static void setup_7322_link_recovery(struct qib_pportdata *ppd, u32 both)
8355 struct qib_devdata *dd = ppd->dd;
8357 if (!ppd->dd->cspec->r1)
8360 dd->cspec->recovery_ports_initted++;
8361 ppd->cpspec->recovery_init = 1;
8363 if (!both && dd->cspec->recovery_ports_initted == 1) {
8364 portsel = ppd->port == 1 ? portsel_port1 : portsel_port2;
8367 portsel = portsel_2port;
8371 if (qib_r_grab(dd) < 0 ||
8372 qib_r_shift(dd, BISTEN_ETM, LEN_ETM, reset_atetm, NULL) < 0 ||
8373 qib_r_update(dd, BISTEN_ETM) < 0 ||
8374 qib_r_shift(dd, BISTEN_AT, LEN_AT, reset_at, NULL) < 0 ||
8375 qib_r_update(dd, BISTEN_AT) < 0 ||
8376 qib_r_shift(dd, BISTEN_PORT_SEL, LEN_PORT_SEL,
8377 portsel, NULL) < 0 ||
8378 qib_r_update(dd, BISTEN_PORT_SEL) < 0 ||
8379 qib_r_shift(dd, BISTEN_AT, LEN_AT, at, NULL) < 0 ||
8380 qib_r_update(dd, BISTEN_AT) < 0 ||
8381 qib_r_shift(dd, BISTEN_ETM, LEN_ETM, etm, NULL) < 0 ||
8382 qib_r_update(dd, BISTEN_ETM) < 0)
8383 qib_dev_err(dd, "Failed IB link recovery setup\n");
8386 static void check_7322_rxe_status(struct qib_pportdata *ppd)
8388 struct qib_devdata *dd = ppd->dd;
8391 if (dd->cspec->recovery_ports_initted != 1)
8392 return; /* rest doesn't apply to dualport */
8393 qib_write_kreg(dd, kr_control, dd->control |
8394 SYM_MASK(Control, FreezeMode));
8395 (void)qib_read_kreg64(dd, kr_scratch);
8396 udelay(3); /* ibcreset asserted 400ns, be sure that's over */
8397 fmask = qib_read_kreg64(dd, kr_act_fmask);
8400 * require a powercycle before we'll work again, and make
8401 * sure we get no more interrupts, and don't turn off
8404 ppd->dd->cspec->stay_in_freeze = 1;
8405 qib_7322_set_intr_state(ppd->dd, 0);
8406 qib_write_kreg(dd, kr_fmask, 0ULL);
8407 qib_dev_err(dd, "HCA unusable until powercycled\n");
8408 return; /* eventually reset */
8411 qib_write_kreg(ppd->dd, kr_hwerrclear,
8412 SYM_MASK(HwErrClear, IBSerdesPClkNotDetectClear_1));
8414 /* don't do the full clear_freeze(), not needed for this */
8415 qib_write_kreg(dd, kr_control, dd->control);
8416 qib_read_kreg32(dd, kr_scratch);
8417 /* take IBC out of reset */
8418 if (ppd->link_speed_supported) {
8419 ppd->cpspec->ibcctrl_a &=
8420 ~SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
8421 qib_write_kreg_port(ppd, krp_ibcctrl_a,
8422 ppd->cpspec->ibcctrl_a);
8423 qib_read_kreg32(dd, kr_scratch);
8424 if (ppd->lflags & QIBL_IB_LINK_DISABLED)
8425 qib_set_ib_7322_lstate(ppd, 0,
8426 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);