This client driver allows you to use a GPIO pin as a source for PPS
[linux-2.6/next.git] / drivers / infiniband / hw / qib / qib_iba7322.c
bloba9dc6935e07f735a3a10c0cae5ee5c2acb80280c
1 /*
2 * Copyright (c) 2008, 2009, 2010 QLogic Corporation. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
34 * This file contains all of the code that is specific to the
35 * InfiniPath 7322 chip
38 #include <linux/interrupt.h>
39 #include <linux/pci.h>
40 #include <linux/delay.h>
41 #include <linux/io.h>
42 #include <linux/jiffies.h>
43 #include <linux/module.h>
44 #include <rdma/ib_verbs.h>
45 #include <rdma/ib_smi.h>
47 #include "qib.h"
48 #include "qib_7322_regs.h"
49 #include "qib_qsfp.h"
51 #include "qib_mad.h"
53 static void qib_setup_7322_setextled(struct qib_pportdata *, u32);
54 static void qib_7322_handle_hwerrors(struct qib_devdata *, char *, size_t);
55 static void sendctrl_7322_mod(struct qib_pportdata *ppd, u32 op);
56 static irqreturn_t qib_7322intr(int irq, void *data);
57 static irqreturn_t qib_7322bufavail(int irq, void *data);
58 static irqreturn_t sdma_intr(int irq, void *data);
59 static irqreturn_t sdma_idle_intr(int irq, void *data);
60 static irqreturn_t sdma_progress_intr(int irq, void *data);
61 static irqreturn_t sdma_cleanup_intr(int irq, void *data);
62 static void qib_7322_txchk_change(struct qib_devdata *, u32, u32, u32,
63 struct qib_ctxtdata *rcd);
64 static u8 qib_7322_phys_portstate(u64);
65 static u32 qib_7322_iblink_state(u64);
66 static void qib_set_ib_7322_lstate(struct qib_pportdata *ppd, u16 linkcmd,
67 u16 linitcmd);
68 static void force_h1(struct qib_pportdata *);
69 static void adj_tx_serdes(struct qib_pportdata *);
70 static u32 qib_7322_setpbc_control(struct qib_pportdata *, u32, u8, u8);
71 static void qib_7322_mini_pcs_reset(struct qib_pportdata *);
73 static u32 ahb_mod(struct qib_devdata *, int, int, int, u32, u32);
74 static void ibsd_wr_allchans(struct qib_pportdata *, int, unsigned, unsigned);
75 static void serdes_7322_los_enable(struct qib_pportdata *, int);
76 static int serdes_7322_init_old(struct qib_pportdata *);
77 static int serdes_7322_init_new(struct qib_pportdata *);
79 #define BMASK(msb, lsb) (((1 << ((msb) + 1 - (lsb))) - 1) << (lsb))
81 /* LE2 serdes values for different cases */
82 #define LE2_DEFAULT 5
83 #define LE2_5m 4
84 #define LE2_QME 0
86 /* Below is special-purpose, so only really works for the IB SerDes blocks. */
87 #define IBSD(hw_pidx) (hw_pidx + 2)
89 /* these are variables for documentation and experimentation purposes */
90 static const unsigned rcv_int_timeout = 375;
91 static const unsigned rcv_int_count = 16;
92 static const unsigned sdma_idle_cnt = 64;
94 /* Time to stop altering Rx Equalization parameters, after link up. */
95 #define RXEQ_DISABLE_MSECS 2500
98 * Number of VLs we are configured to use (to allow for more
99 * credits per vl, etc.)
101 ushort qib_num_cfg_vls = 2;
102 module_param_named(num_vls, qib_num_cfg_vls, ushort, S_IRUGO);
103 MODULE_PARM_DESC(num_vls, "Set number of Virtual Lanes to use (1-8)");
105 static ushort qib_chase = 1;
106 module_param_named(chase, qib_chase, ushort, S_IRUGO);
107 MODULE_PARM_DESC(chase, "Enable state chase handling");
109 static ushort qib_long_atten = 10; /* 10 dB ~= 5m length */
110 module_param_named(long_attenuation, qib_long_atten, ushort, S_IRUGO);
111 MODULE_PARM_DESC(long_attenuation, \
112 "attenuation cutoff (dB) for long copper cable setup");
114 static ushort qib_singleport;
115 module_param_named(singleport, qib_singleport, ushort, S_IRUGO);
116 MODULE_PARM_DESC(singleport, "Use only IB port 1; more per-port buffer space");
118 static ushort qib_krcvq01_no_msi;
119 module_param_named(krcvq01_no_msi, qib_krcvq01_no_msi, ushort, S_IRUGO);
120 MODULE_PARM_DESC(krcvq01_no_msi, "No MSI for kctx < 2");
123 * Receive header queue sizes
125 static unsigned qib_rcvhdrcnt;
126 module_param_named(rcvhdrcnt, qib_rcvhdrcnt, uint, S_IRUGO);
127 MODULE_PARM_DESC(rcvhdrcnt, "receive header count");
129 static unsigned qib_rcvhdrsize;
130 module_param_named(rcvhdrsize, qib_rcvhdrsize, uint, S_IRUGO);
131 MODULE_PARM_DESC(rcvhdrsize, "receive header size in 32-bit words");
133 static unsigned qib_rcvhdrentsize;
134 module_param_named(rcvhdrentsize, qib_rcvhdrentsize, uint, S_IRUGO);
135 MODULE_PARM_DESC(rcvhdrentsize, "receive header entry size in 32-bit words");
137 #define MAX_ATTEN_LEN 64 /* plenty for any real system */
138 /* for read back, default index is ~5m copper cable */
139 static char txselect_list[MAX_ATTEN_LEN] = "10";
140 static struct kparam_string kp_txselect = {
141 .string = txselect_list,
142 .maxlen = MAX_ATTEN_LEN
144 static int setup_txselect(const char *, struct kernel_param *);
145 module_param_call(txselect, setup_txselect, param_get_string,
146 &kp_txselect, S_IWUSR | S_IRUGO);
147 MODULE_PARM_DESC(txselect, \
148 "Tx serdes indices (for no QSFP or invalid QSFP data)");
150 #define BOARD_QME7342 5
151 #define BOARD_QMH7342 6
152 #define IS_QMH(dd) (SYM_FIELD((dd)->revision, Revision, BoardID) == \
153 BOARD_QMH7342)
154 #define IS_QME(dd) (SYM_FIELD((dd)->revision, Revision, BoardID) == \
155 BOARD_QME7342)
157 #define KREG_IDX(regname) (QIB_7322_##regname##_OFFS / sizeof(u64))
159 #define KREG_IBPORT_IDX(regname) ((QIB_7322_##regname##_0_OFFS / sizeof(u64)))
161 #define MASK_ACROSS(lsb, msb) \
162 (((1ULL << ((msb) + 1 - (lsb))) - 1) << (lsb))
164 #define SYM_RMASK(regname, fldname) ((u64) \
165 QIB_7322_##regname##_##fldname##_RMASK)
167 #define SYM_MASK(regname, fldname) ((u64) \
168 QIB_7322_##regname##_##fldname##_RMASK << \
169 QIB_7322_##regname##_##fldname##_LSB)
171 #define SYM_FIELD(value, regname, fldname) ((u64) \
172 (((value) >> SYM_LSB(regname, fldname)) & \
173 SYM_RMASK(regname, fldname)))
175 /* useful for things like LaFifoEmpty_0...7, TxCreditOK_0...7, etc. */
176 #define SYM_FIELD_ACROSS(value, regname, fldname, nbits) \
177 (((value) >> SYM_LSB(regname, fldname)) & MASK_ACROSS(0, nbits))
179 #define HWE_MASK(fldname) SYM_MASK(HwErrMask, fldname##Mask)
180 #define ERR_MASK(fldname) SYM_MASK(ErrMask, fldname##Mask)
181 #define ERR_MASK_N(fldname) SYM_MASK(ErrMask_0, fldname##Mask)
182 #define INT_MASK(fldname) SYM_MASK(IntMask, fldname##IntMask)
183 #define INT_MASK_P(fldname, port) SYM_MASK(IntMask, fldname##IntMask##_##port)
184 /* Below because most, but not all, fields of IntMask have that full suffix */
185 #define INT_MASK_PM(fldname, port) SYM_MASK(IntMask, fldname##Mask##_##port)
188 #define SYM_LSB(regname, fldname) (QIB_7322_##regname##_##fldname##_LSB)
191 * the size bits give us 2^N, in KB units. 0 marks as invalid,
192 * and 7 is reserved. We currently use only 2KB and 4KB
194 #define IBA7322_TID_SZ_SHIFT QIB_7322_RcvTIDArray0_RT_BufSize_LSB
195 #define IBA7322_TID_SZ_2K (1UL<<IBA7322_TID_SZ_SHIFT) /* 2KB */
196 #define IBA7322_TID_SZ_4K (2UL<<IBA7322_TID_SZ_SHIFT) /* 4KB */
197 #define IBA7322_TID_PA_SHIFT 11U /* TID addr in chip stored w/o low bits */
199 #define SendIBSLIDAssignMask \
200 QIB_7322_SendIBSLIDAssign_0_SendIBSLIDAssign_15_0_RMASK
201 #define SendIBSLMCMask \
202 QIB_7322_SendIBSLIDMask_0_SendIBSLIDMask_15_0_RMASK
204 #define ExtLED_IB1_YEL SYM_MASK(EXTCtrl, LEDPort0YellowOn)
205 #define ExtLED_IB1_GRN SYM_MASK(EXTCtrl, LEDPort0GreenOn)
206 #define ExtLED_IB2_YEL SYM_MASK(EXTCtrl, LEDPort1YellowOn)
207 #define ExtLED_IB2_GRN SYM_MASK(EXTCtrl, LEDPort1GreenOn)
208 #define ExtLED_IB1_MASK (ExtLED_IB1_YEL | ExtLED_IB1_GRN)
209 #define ExtLED_IB2_MASK (ExtLED_IB2_YEL | ExtLED_IB2_GRN)
211 #define _QIB_GPIO_SDA_NUM 1
212 #define _QIB_GPIO_SCL_NUM 0
213 #define QIB_EEPROM_WEN_NUM 14
214 #define QIB_TWSI_EEPROM_DEV 0xA2 /* All Production 7322 cards. */
216 /* HW counter clock is at 4nsec */
217 #define QIB_7322_PSXMITWAIT_CHECK_RATE 4000
219 /* full speed IB port 1 only */
220 #define PORT_SPD_CAP (QIB_IB_SDR | QIB_IB_DDR | QIB_IB_QDR)
221 #define PORT_SPD_CAP_SHIFT 3
223 /* full speed featuremask, both ports */
224 #define DUAL_PORT_CAP (PORT_SPD_CAP | (PORT_SPD_CAP << PORT_SPD_CAP_SHIFT))
227 * This file contains almost all the chip-specific register information and
228 * access functions for the FAKED QLogic InfiniPath 7322 PCI-Express chip.
231 /* Use defines to tie machine-generated names to lower-case names */
232 #define kr_contextcnt KREG_IDX(ContextCnt)
233 #define kr_control KREG_IDX(Control)
234 #define kr_counterregbase KREG_IDX(CntrRegBase)
235 #define kr_errclear KREG_IDX(ErrClear)
236 #define kr_errmask KREG_IDX(ErrMask)
237 #define kr_errstatus KREG_IDX(ErrStatus)
238 #define kr_extctrl KREG_IDX(EXTCtrl)
239 #define kr_extstatus KREG_IDX(EXTStatus)
240 #define kr_gpio_clear KREG_IDX(GPIOClear)
241 #define kr_gpio_mask KREG_IDX(GPIOMask)
242 #define kr_gpio_out KREG_IDX(GPIOOut)
243 #define kr_gpio_status KREG_IDX(GPIOStatus)
244 #define kr_hwdiagctrl KREG_IDX(HwDiagCtrl)
245 #define kr_debugportval KREG_IDX(DebugPortValueReg)
246 #define kr_fmask KREG_IDX(feature_mask)
247 #define kr_act_fmask KREG_IDX(active_feature_mask)
248 #define kr_hwerrclear KREG_IDX(HwErrClear)
249 #define kr_hwerrmask KREG_IDX(HwErrMask)
250 #define kr_hwerrstatus KREG_IDX(HwErrStatus)
251 #define kr_intclear KREG_IDX(IntClear)
252 #define kr_intmask KREG_IDX(IntMask)
253 #define kr_intredirect KREG_IDX(IntRedirect0)
254 #define kr_intstatus KREG_IDX(IntStatus)
255 #define kr_pagealign KREG_IDX(PageAlign)
256 #define kr_rcvavailtimeout KREG_IDX(RcvAvailTimeOut0)
257 #define kr_rcvctrl KREG_IDX(RcvCtrl) /* Common, but chip also has per-port */
258 #define kr_rcvegrbase KREG_IDX(RcvEgrBase)
259 #define kr_rcvegrcnt KREG_IDX(RcvEgrCnt)
260 #define kr_rcvhdrcnt KREG_IDX(RcvHdrCnt)
261 #define kr_rcvhdrentsize KREG_IDX(RcvHdrEntSize)
262 #define kr_rcvhdrsize KREG_IDX(RcvHdrSize)
263 #define kr_rcvtidbase KREG_IDX(RcvTIDBase)
264 #define kr_rcvtidcnt KREG_IDX(RcvTIDCnt)
265 #define kr_revision KREG_IDX(Revision)
266 #define kr_scratch KREG_IDX(Scratch)
267 #define kr_sendbuffererror KREG_IDX(SendBufErr0) /* and base for 1 and 2 */
268 #define kr_sendcheckmask KREG_IDX(SendCheckMask0) /* and 1, 2 */
269 #define kr_sendctrl KREG_IDX(SendCtrl)
270 #define kr_sendgrhcheckmask KREG_IDX(SendGRHCheckMask0) /* and 1, 2 */
271 #define kr_sendibpktmask KREG_IDX(SendIBPacketMask0) /* and 1, 2 */
272 #define kr_sendpioavailaddr KREG_IDX(SendBufAvailAddr)
273 #define kr_sendpiobufbase KREG_IDX(SendBufBase)
274 #define kr_sendpiobufcnt KREG_IDX(SendBufCnt)
275 #define kr_sendpiosize KREG_IDX(SendBufSize)
276 #define kr_sendregbase KREG_IDX(SendRegBase)
277 #define kr_sendbufavail0 KREG_IDX(SendBufAvail0)
278 #define kr_userregbase KREG_IDX(UserRegBase)
279 #define kr_intgranted KREG_IDX(Int_Granted)
280 #define kr_vecclr_wo_int KREG_IDX(vec_clr_without_int)
281 #define kr_intblocked KREG_IDX(IntBlocked)
282 #define kr_r_access KREG_IDX(SPC_JTAG_ACCESS_REG)
285 * per-port kernel registers. Access only with qib_read_kreg_port()
286 * or qib_write_kreg_port()
288 #define krp_errclear KREG_IBPORT_IDX(ErrClear)
289 #define krp_errmask KREG_IBPORT_IDX(ErrMask)
290 #define krp_errstatus KREG_IBPORT_IDX(ErrStatus)
291 #define krp_highprio_0 KREG_IBPORT_IDX(HighPriority0)
292 #define krp_highprio_limit KREG_IBPORT_IDX(HighPriorityLimit)
293 #define krp_hrtbt_guid KREG_IBPORT_IDX(HRTBT_GUID)
294 #define krp_ib_pcsconfig KREG_IBPORT_IDX(IBPCSConfig)
295 #define krp_ibcctrl_a KREG_IBPORT_IDX(IBCCtrlA)
296 #define krp_ibcctrl_b KREG_IBPORT_IDX(IBCCtrlB)
297 #define krp_ibcctrl_c KREG_IBPORT_IDX(IBCCtrlC)
298 #define krp_ibcstatus_a KREG_IBPORT_IDX(IBCStatusA)
299 #define krp_ibcstatus_b KREG_IBPORT_IDX(IBCStatusB)
300 #define krp_txestatus KREG_IBPORT_IDX(TXEStatus)
301 #define krp_lowprio_0 KREG_IBPORT_IDX(LowPriority0)
302 #define krp_ncmodectrl KREG_IBPORT_IDX(IBNCModeCtrl)
303 #define krp_partitionkey KREG_IBPORT_IDX(RcvPartitionKey)
304 #define krp_psinterval KREG_IBPORT_IDX(PSInterval)
305 #define krp_psstart KREG_IBPORT_IDX(PSStart)
306 #define krp_psstat KREG_IBPORT_IDX(PSStat)
307 #define krp_rcvbthqp KREG_IBPORT_IDX(RcvBTHQP)
308 #define krp_rcvctrl KREG_IBPORT_IDX(RcvCtrl)
309 #define krp_rcvpktledcnt KREG_IBPORT_IDX(RcvPktLEDCnt)
310 #define krp_rcvqpmaptable KREG_IBPORT_IDX(RcvQPMapTableA)
311 #define krp_rxcreditvl0 KREG_IBPORT_IDX(RxCreditVL0)
312 #define krp_rxcreditvl15 (KREG_IBPORT_IDX(RxCreditVL0)+15)
313 #define krp_sendcheckcontrol KREG_IBPORT_IDX(SendCheckControl)
314 #define krp_sendctrl KREG_IBPORT_IDX(SendCtrl)
315 #define krp_senddmabase KREG_IBPORT_IDX(SendDmaBase)
316 #define krp_senddmabufmask0 KREG_IBPORT_IDX(SendDmaBufMask0)
317 #define krp_senddmabufmask1 (KREG_IBPORT_IDX(SendDmaBufMask0) + 1)
318 #define krp_senddmabufmask2 (KREG_IBPORT_IDX(SendDmaBufMask0) + 2)
319 #define krp_senddmabuf_use0 KREG_IBPORT_IDX(SendDmaBufUsed0)
320 #define krp_senddmabuf_use1 (KREG_IBPORT_IDX(SendDmaBufUsed0) + 1)
321 #define krp_senddmabuf_use2 (KREG_IBPORT_IDX(SendDmaBufUsed0) + 2)
322 #define krp_senddmadesccnt KREG_IBPORT_IDX(SendDmaDescCnt)
323 #define krp_senddmahead KREG_IBPORT_IDX(SendDmaHead)
324 #define krp_senddmaheadaddr KREG_IBPORT_IDX(SendDmaHeadAddr)
325 #define krp_senddmaidlecnt KREG_IBPORT_IDX(SendDmaIdleCnt)
326 #define krp_senddmalengen KREG_IBPORT_IDX(SendDmaLenGen)
327 #define krp_senddmaprioritythld KREG_IBPORT_IDX(SendDmaPriorityThld)
328 #define krp_senddmareloadcnt KREG_IBPORT_IDX(SendDmaReloadCnt)
329 #define krp_senddmastatus KREG_IBPORT_IDX(SendDmaStatus)
330 #define krp_senddmatail KREG_IBPORT_IDX(SendDmaTail)
331 #define krp_sendhdrsymptom KREG_IBPORT_IDX(SendHdrErrSymptom)
332 #define krp_sendslid KREG_IBPORT_IDX(SendIBSLIDAssign)
333 #define krp_sendslidmask KREG_IBPORT_IDX(SendIBSLIDMask)
334 #define krp_ibsdtestiftx KREG_IBPORT_IDX(IB_SDTEST_IF_TX)
335 #define krp_adapt_dis_timer KREG_IBPORT_IDX(ADAPT_DISABLE_TIMER_THRESHOLD)
336 #define krp_tx_deemph_override KREG_IBPORT_IDX(IBSD_TX_DEEMPHASIS_OVERRIDE)
337 #define krp_serdesctrl KREG_IBPORT_IDX(IBSerdesCtrl)
340 * Per-context kernel registers. Access only with qib_read_kreg_ctxt()
341 * or qib_write_kreg_ctxt()
343 #define krc_rcvhdraddr KREG_IDX(RcvHdrAddr0)
344 #define krc_rcvhdrtailaddr KREG_IDX(RcvHdrTailAddr0)
347 * TID Flow table, per context. Reduces
348 * number of hdrq updates to one per flow (or on errors).
349 * context 0 and 1 share same memory, but have distinct
350 * addresses. Since for now, we never use expected sends
351 * on kernel contexts, we don't worry about that (we initialize
352 * those entries for ctxt 0/1 on driver load twice, for example).
354 #define NUM_TIDFLOWS_CTXT 0x20 /* 0x20 per context; have to hardcode */
355 #define ur_rcvflowtable (KREG_IDX(RcvTIDFlowTable0) - KREG_IDX(RcvHdrTail0))
357 /* these are the error bits in the tid flows, and are W1C */
358 #define TIDFLOW_ERRBITS ( \
359 (SYM_MASK(RcvTIDFlowTable0, GenMismatch) << \
360 SYM_LSB(RcvTIDFlowTable0, GenMismatch)) | \
361 (SYM_MASK(RcvTIDFlowTable0, SeqMismatch) << \
362 SYM_LSB(RcvTIDFlowTable0, SeqMismatch)))
364 /* Most (not all) Counters are per-IBport.
365 * Requires LBIntCnt is at offset 0 in the group
367 #define CREG_IDX(regname) \
368 ((QIB_7322_##regname##_0_OFFS - QIB_7322_LBIntCnt_OFFS) / sizeof(u64))
370 #define crp_badformat CREG_IDX(RxVersionErrCnt)
371 #define crp_err_rlen CREG_IDX(RxLenErrCnt)
372 #define crp_erricrc CREG_IDX(RxICRCErrCnt)
373 #define crp_errlink CREG_IDX(RxLinkMalformCnt)
374 #define crp_errlpcrc CREG_IDX(RxLPCRCErrCnt)
375 #define crp_errpkey CREG_IDX(RxPKeyMismatchCnt)
376 #define crp_errvcrc CREG_IDX(RxVCRCErrCnt)
377 #define crp_excessbufferovfl CREG_IDX(ExcessBufferOvflCnt)
378 #define crp_iblinkdown CREG_IDX(IBLinkDownedCnt)
379 #define crp_iblinkerrrecov CREG_IDX(IBLinkErrRecoveryCnt)
380 #define crp_ibstatuschange CREG_IDX(IBStatusChangeCnt)
381 #define crp_ibsymbolerr CREG_IDX(IBSymbolErrCnt)
382 #define crp_invalidrlen CREG_IDX(RxMaxMinLenErrCnt)
383 #define crp_locallinkintegrityerr CREG_IDX(LocalLinkIntegrityErrCnt)
384 #define crp_pktrcv CREG_IDX(RxDataPktCnt)
385 #define crp_pktrcvflowctrl CREG_IDX(RxFlowPktCnt)
386 #define crp_pktsend CREG_IDX(TxDataPktCnt)
387 #define crp_pktsendflow CREG_IDX(TxFlowPktCnt)
388 #define crp_psrcvdatacount CREG_IDX(PSRcvDataCount)
389 #define crp_psrcvpktscount CREG_IDX(PSRcvPktsCount)
390 #define crp_psxmitdatacount CREG_IDX(PSXmitDataCount)
391 #define crp_psxmitpktscount CREG_IDX(PSXmitPktsCount)
392 #define crp_psxmitwaitcount CREG_IDX(PSXmitWaitCount)
393 #define crp_rcvebp CREG_IDX(RxEBPCnt)
394 #define crp_rcvflowctrlviol CREG_IDX(RxFlowCtrlViolCnt)
395 #define crp_rcvovfl CREG_IDX(RxBufOvflCnt)
396 #define crp_rxdlidfltr CREG_IDX(RxDlidFltrCnt)
397 #define crp_rxdroppkt CREG_IDX(RxDroppedPktCnt)
398 #define crp_rxotherlocalphyerr CREG_IDX(RxOtherLocalPhyErrCnt)
399 #define crp_rxqpinvalidctxt CREG_IDX(RxQPInvalidContextCnt)
400 #define crp_rxvlerr CREG_IDX(RxVlErrCnt)
401 #define crp_sendstall CREG_IDX(TxFlowStallCnt)
402 #define crp_txdroppedpkt CREG_IDX(TxDroppedPktCnt)
403 #define crp_txhdrerr CREG_IDX(TxHeadersErrCnt)
404 #define crp_txlenerr CREG_IDX(TxLenErrCnt)
405 #define crp_txminmaxlenerr CREG_IDX(TxMaxMinLenErrCnt)
406 #define crp_txsdmadesc CREG_IDX(TxSDmaDescCnt)
407 #define crp_txunderrun CREG_IDX(TxUnderrunCnt)
408 #define crp_txunsupvl CREG_IDX(TxUnsupVLErrCnt)
409 #define crp_vl15droppedpkt CREG_IDX(RxVL15DroppedPktCnt)
410 #define crp_wordrcv CREG_IDX(RxDwordCnt)
411 #define crp_wordsend CREG_IDX(TxDwordCnt)
412 #define crp_tx_creditstalls CREG_IDX(TxCreditUpToDateTimeOut)
414 /* these are the (few) counters that are not port-specific */
415 #define CREG_DEVIDX(regname) ((QIB_7322_##regname##_OFFS - \
416 QIB_7322_LBIntCnt_OFFS) / sizeof(u64))
417 #define cr_base_egrovfl CREG_DEVIDX(RxP0HdrEgrOvflCnt)
418 #define cr_lbint CREG_DEVIDX(LBIntCnt)
419 #define cr_lbstall CREG_DEVIDX(LBFlowStallCnt)
420 #define cr_pcieretrydiag CREG_DEVIDX(PcieRetryBufDiagQwordCnt)
421 #define cr_rxtidflowdrop CREG_DEVIDX(RxTidFlowDropCnt)
422 #define cr_tidfull CREG_DEVIDX(RxTIDFullErrCnt)
423 #define cr_tidinvalid CREG_DEVIDX(RxTIDValidErrCnt)
425 /* no chip register for # of IB ports supported, so define */
426 #define NUM_IB_PORTS 2
428 /* 1 VL15 buffer per hardware IB port, no register for this, so define */
429 #define NUM_VL15_BUFS NUM_IB_PORTS
432 * context 0 and 1 are special, and there is no chip register that
433 * defines this value, so we have to define it here.
434 * These are all allocated to either 0 or 1 for single port
435 * hardware configuration, otherwise each gets half
437 #define KCTXT0_EGRCNT 2048
439 /* values for vl and port fields in PBC, 7322-specific */
440 #define PBC_PORT_SEL_LSB 26
441 #define PBC_PORT_SEL_RMASK 1
442 #define PBC_VL_NUM_LSB 27
443 #define PBC_VL_NUM_RMASK 7
444 #define PBC_7322_VL15_SEND (1ULL << 63) /* pbc; VL15, no credit check */
445 #define PBC_7322_VL15_SEND_CTRL (1ULL << 31) /* control version of same */
447 static u8 ib_rate_to_delay[IB_RATE_120_GBPS + 1] = {
448 [IB_RATE_2_5_GBPS] = 16,
449 [IB_RATE_5_GBPS] = 8,
450 [IB_RATE_10_GBPS] = 4,
451 [IB_RATE_20_GBPS] = 2,
452 [IB_RATE_30_GBPS] = 2,
453 [IB_RATE_40_GBPS] = 1
456 #define IBA7322_LINKSPEED_SHIFT SYM_LSB(IBCStatusA_0, LinkSpeedActive)
457 #define IBA7322_LINKWIDTH_SHIFT SYM_LSB(IBCStatusA_0, LinkWidthActive)
459 /* link training states, from IBC */
460 #define IB_7322_LT_STATE_DISABLED 0x00
461 #define IB_7322_LT_STATE_LINKUP 0x01
462 #define IB_7322_LT_STATE_POLLACTIVE 0x02
463 #define IB_7322_LT_STATE_POLLQUIET 0x03
464 #define IB_7322_LT_STATE_SLEEPDELAY 0x04
465 #define IB_7322_LT_STATE_SLEEPQUIET 0x05
466 #define IB_7322_LT_STATE_CFGDEBOUNCE 0x08
467 #define IB_7322_LT_STATE_CFGRCVFCFG 0x09
468 #define IB_7322_LT_STATE_CFGWAITRMT 0x0a
469 #define IB_7322_LT_STATE_CFGIDLE 0x0b
470 #define IB_7322_LT_STATE_RECOVERRETRAIN 0x0c
471 #define IB_7322_LT_STATE_TXREVLANES 0x0d
472 #define IB_7322_LT_STATE_RECOVERWAITRMT 0x0e
473 #define IB_7322_LT_STATE_RECOVERIDLE 0x0f
474 #define IB_7322_LT_STATE_CFGENH 0x10
475 #define IB_7322_LT_STATE_CFGTEST 0x11
476 #define IB_7322_LT_STATE_CFGWAITRMTTEST 0x12
477 #define IB_7322_LT_STATE_CFGWAITENH 0x13
479 /* link state machine states from IBC */
480 #define IB_7322_L_STATE_DOWN 0x0
481 #define IB_7322_L_STATE_INIT 0x1
482 #define IB_7322_L_STATE_ARM 0x2
483 #define IB_7322_L_STATE_ACTIVE 0x3
484 #define IB_7322_L_STATE_ACT_DEFER 0x4
486 static const u8 qib_7322_physportstate[0x20] = {
487 [IB_7322_LT_STATE_DISABLED] = IB_PHYSPORTSTATE_DISABLED,
488 [IB_7322_LT_STATE_LINKUP] = IB_PHYSPORTSTATE_LINKUP,
489 [IB_7322_LT_STATE_POLLACTIVE] = IB_PHYSPORTSTATE_POLL,
490 [IB_7322_LT_STATE_POLLQUIET] = IB_PHYSPORTSTATE_POLL,
491 [IB_7322_LT_STATE_SLEEPDELAY] = IB_PHYSPORTSTATE_SLEEP,
492 [IB_7322_LT_STATE_SLEEPQUIET] = IB_PHYSPORTSTATE_SLEEP,
493 [IB_7322_LT_STATE_CFGDEBOUNCE] = IB_PHYSPORTSTATE_CFG_TRAIN,
494 [IB_7322_LT_STATE_CFGRCVFCFG] =
495 IB_PHYSPORTSTATE_CFG_TRAIN,
496 [IB_7322_LT_STATE_CFGWAITRMT] =
497 IB_PHYSPORTSTATE_CFG_TRAIN,
498 [IB_7322_LT_STATE_CFGIDLE] = IB_PHYSPORTSTATE_CFG_IDLE,
499 [IB_7322_LT_STATE_RECOVERRETRAIN] =
500 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
501 [IB_7322_LT_STATE_RECOVERWAITRMT] =
502 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
503 [IB_7322_LT_STATE_RECOVERIDLE] =
504 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
505 [IB_7322_LT_STATE_CFGENH] = IB_PHYSPORTSTATE_CFG_ENH,
506 [IB_7322_LT_STATE_CFGTEST] = IB_PHYSPORTSTATE_CFG_TRAIN,
507 [IB_7322_LT_STATE_CFGWAITRMTTEST] =
508 IB_PHYSPORTSTATE_CFG_TRAIN,
509 [IB_7322_LT_STATE_CFGWAITENH] =
510 IB_PHYSPORTSTATE_CFG_WAIT_ENH,
511 [0x14] = IB_PHYSPORTSTATE_CFG_TRAIN,
512 [0x15] = IB_PHYSPORTSTATE_CFG_TRAIN,
513 [0x16] = IB_PHYSPORTSTATE_CFG_TRAIN,
514 [0x17] = IB_PHYSPORTSTATE_CFG_TRAIN
517 struct qib_chip_specific {
518 u64 __iomem *cregbase;
519 u64 *cntrs;
520 spinlock_t rcvmod_lock; /* protect rcvctrl shadow changes */
521 spinlock_t gpio_lock; /* RMW of shadows/regs for ExtCtrl and GPIO */
522 u64 main_int_mask; /* clear bits which have dedicated handlers */
523 u64 int_enable_mask; /* for per port interrupts in single port mode */
524 u64 errormask;
525 u64 hwerrmask;
526 u64 gpio_out; /* shadow of kr_gpio_out, for rmw ops */
527 u64 gpio_mask; /* shadow the gpio mask register */
528 u64 extctrl; /* shadow the gpio output enable, etc... */
529 u32 ncntrs;
530 u32 nportcntrs;
531 u32 cntrnamelen;
532 u32 portcntrnamelen;
533 u32 numctxts;
534 u32 rcvegrcnt;
535 u32 updthresh; /* current AvailUpdThld */
536 u32 updthresh_dflt; /* default AvailUpdThld */
537 u32 r1;
538 int irq;
539 u32 num_msix_entries;
540 u32 sdmabufcnt;
541 u32 lastbuf_for_pio;
542 u32 stay_in_freeze;
543 u32 recovery_ports_initted;
544 struct msix_entry *msix_entries;
545 void **msix_arg;
546 unsigned long *sendchkenable;
547 unsigned long *sendgrhchk;
548 unsigned long *sendibchk;
549 u32 rcvavail_timeout[18];
550 char emsgbuf[128]; /* for device error interrupt msg buffer */
553 /* Table of entries in "human readable" form Tx Emphasis. */
554 struct txdds_ent {
555 u8 amp;
556 u8 pre;
557 u8 main;
558 u8 post;
561 struct vendor_txdds_ent {
562 u8 oui[QSFP_VOUI_LEN];
563 u8 *partnum;
564 struct txdds_ent sdr;
565 struct txdds_ent ddr;
566 struct txdds_ent qdr;
569 static void write_tx_serdes_param(struct qib_pportdata *, struct txdds_ent *);
571 #define TXDDS_TABLE_SZ 16 /* number of entries per speed in onchip table */
572 #define TXDDS_EXTRA_SZ 13 /* number of extra tx settings entries */
573 #define TXDDS_MFG_SZ 2 /* number of mfg tx settings entries */
574 #define SERDES_CHANS 4 /* yes, it's obvious, but one less magic number */
576 #define H1_FORCE_VAL 8
577 #define H1_FORCE_QME 1 /* may be overridden via setup_txselect() */
578 #define H1_FORCE_QMH 7 /* may be overridden via setup_txselect() */
580 /* The static and dynamic registers are paired, and the pairs indexed by spd */
581 #define krp_static_adapt_dis(spd) (KREG_IBPORT_IDX(ADAPT_DISABLE_STATIC_SDR) \
582 + ((spd) * 2))
584 #define QDR_DFE_DISABLE_DELAY 4000 /* msec after LINKUP */
585 #define QDR_STATIC_ADAPT_DOWN 0xf0f0f0f0ULL /* link down, H1-H4 QDR adapts */
586 #define QDR_STATIC_ADAPT_DOWN_R1 0ULL /* r1 link down, H1-H4 QDR adapts */
587 #define QDR_STATIC_ADAPT_INIT 0xffffffffffULL /* up, disable H0,H1-8, LE */
588 #define QDR_STATIC_ADAPT_INIT_R1 0xf0ffffffffULL /* r1 up, disable H0,H1-8 */
590 struct qib_chippport_specific {
591 u64 __iomem *kpregbase;
592 u64 __iomem *cpregbase;
593 u64 *portcntrs;
594 struct qib_pportdata *ppd;
595 wait_queue_head_t autoneg_wait;
596 struct delayed_work autoneg_work;
597 struct delayed_work ipg_work;
598 struct timer_list chase_timer;
600 * these 5 fields are used to establish deltas for IB symbol
601 * errors and linkrecovery errors. They can be reported on
602 * some chips during link negotiation prior to INIT, and with
603 * DDR when faking DDR negotiations with non-IBTA switches.
604 * The chip counters are adjusted at driver unload if there is
605 * a non-zero delta.
607 u64 ibdeltainprog;
608 u64 ibsymdelta;
609 u64 ibsymsnap;
610 u64 iblnkerrdelta;
611 u64 iblnkerrsnap;
612 u64 iblnkdownsnap;
613 u64 iblnkdowndelta;
614 u64 ibmalfdelta;
615 u64 ibmalfsnap;
616 u64 ibcctrl_a; /* krp_ibcctrl_a shadow */
617 u64 ibcctrl_b; /* krp_ibcctrl_b shadow */
618 u64 qdr_dfe_time;
619 u64 chase_end;
620 u32 autoneg_tries;
621 u32 recovery_init;
622 u32 qdr_dfe_on;
623 u32 qdr_reforce;
625 * Per-bay per-channel rcv QMH H1 values and Tx values for QDR.
626 * entry zero is unused, to simplify indexing
628 u8 h1_val;
629 u8 no_eep; /* txselect table index to use if no qsfp info */
630 u8 ipg_tries;
631 u8 ibmalfusesnap;
632 struct qib_qsfp_data qsfp_data;
633 char epmsgbuf[192]; /* for port error interrupt msg buffer */
636 static struct {
637 const char *name;
638 irq_handler_t handler;
639 int lsb;
640 int port; /* 0 if not port-specific, else port # */
641 } irq_table[] = {
642 { QIB_DRV_NAME, qib_7322intr, -1, 0 },
643 { QIB_DRV_NAME " (buf avail)", qib_7322bufavail,
644 SYM_LSB(IntStatus, SendBufAvail), 0 },
645 { QIB_DRV_NAME " (sdma 0)", sdma_intr,
646 SYM_LSB(IntStatus, SDmaInt_0), 1 },
647 { QIB_DRV_NAME " (sdma 1)", sdma_intr,
648 SYM_LSB(IntStatus, SDmaInt_1), 2 },
649 { QIB_DRV_NAME " (sdmaI 0)", sdma_idle_intr,
650 SYM_LSB(IntStatus, SDmaIdleInt_0), 1 },
651 { QIB_DRV_NAME " (sdmaI 1)", sdma_idle_intr,
652 SYM_LSB(IntStatus, SDmaIdleInt_1), 2 },
653 { QIB_DRV_NAME " (sdmaP 0)", sdma_progress_intr,
654 SYM_LSB(IntStatus, SDmaProgressInt_0), 1 },
655 { QIB_DRV_NAME " (sdmaP 1)", sdma_progress_intr,
656 SYM_LSB(IntStatus, SDmaProgressInt_1), 2 },
657 { QIB_DRV_NAME " (sdmaC 0)", sdma_cleanup_intr,
658 SYM_LSB(IntStatus, SDmaCleanupDone_0), 1 },
659 { QIB_DRV_NAME " (sdmaC 1)", sdma_cleanup_intr,
660 SYM_LSB(IntStatus, SDmaCleanupDone_1), 2 },
663 /* ibcctrl bits */
664 #define QLOGIC_IB_IBCC_LINKINITCMD_DISABLE 1
665 /* cycle through TS1/TS2 till OK */
666 #define QLOGIC_IB_IBCC_LINKINITCMD_POLL 2
667 /* wait for TS1, then go on */
668 #define QLOGIC_IB_IBCC_LINKINITCMD_SLEEP 3
669 #define QLOGIC_IB_IBCC_LINKINITCMD_SHIFT 16
671 #define QLOGIC_IB_IBCC_LINKCMD_DOWN 1 /* move to 0x11 */
672 #define QLOGIC_IB_IBCC_LINKCMD_ARMED 2 /* move to 0x21 */
673 #define QLOGIC_IB_IBCC_LINKCMD_ACTIVE 3 /* move to 0x31 */
675 #define BLOB_7322_IBCHG 0x101
677 static inline void qib_write_kreg(const struct qib_devdata *dd,
678 const u32 regno, u64 value);
679 static inline u32 qib_read_kreg32(const struct qib_devdata *, const u32);
680 static void write_7322_initregs(struct qib_devdata *);
681 static void write_7322_init_portregs(struct qib_pportdata *);
682 static void setup_7322_link_recovery(struct qib_pportdata *, u32);
683 static void check_7322_rxe_status(struct qib_pportdata *);
684 static u32 __iomem *qib_7322_getsendbuf(struct qib_pportdata *, u64, u32 *);
687 * qib_read_ureg32 - read 32-bit virtualized per-context register
688 * @dd: device
689 * @regno: register number
690 * @ctxt: context number
692 * Return the contents of a register that is virtualized to be per context.
693 * Returns -1 on errors (not distinguishable from valid contents at
694 * runtime; we may add a separate error variable at some point).
696 static inline u32 qib_read_ureg32(const struct qib_devdata *dd,
697 enum qib_ureg regno, int ctxt)
699 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
700 return 0;
701 return readl(regno + (u64 __iomem *)(
702 (dd->ureg_align * ctxt) + (dd->userbase ?
703 (char __iomem *)dd->userbase :
704 (char __iomem *)dd->kregbase + dd->uregbase)));
708 * qib_read_ureg - read virtualized per-context register
709 * @dd: device
710 * @regno: register number
711 * @ctxt: context number
713 * Return the contents of a register that is virtualized to be per context.
714 * Returns -1 on errors (not distinguishable from valid contents at
715 * runtime; we may add a separate error variable at some point).
717 static inline u64 qib_read_ureg(const struct qib_devdata *dd,
718 enum qib_ureg regno, int ctxt)
721 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
722 return 0;
723 return readq(regno + (u64 __iomem *)(
724 (dd->ureg_align * ctxt) + (dd->userbase ?
725 (char __iomem *)dd->userbase :
726 (char __iomem *)dd->kregbase + dd->uregbase)));
730 * qib_write_ureg - write virtualized per-context register
731 * @dd: device
732 * @regno: register number
733 * @value: value
734 * @ctxt: context
736 * Write the contents of a register that is virtualized to be per context.
738 static inline void qib_write_ureg(const struct qib_devdata *dd,
739 enum qib_ureg regno, u64 value, int ctxt)
741 u64 __iomem *ubase;
742 if (dd->userbase)
743 ubase = (u64 __iomem *)
744 ((char __iomem *) dd->userbase +
745 dd->ureg_align * ctxt);
746 else
747 ubase = (u64 __iomem *)
748 (dd->uregbase +
749 (char __iomem *) dd->kregbase +
750 dd->ureg_align * ctxt);
752 if (dd->kregbase && (dd->flags & QIB_PRESENT))
753 writeq(value, &ubase[regno]);
756 static inline u32 qib_read_kreg32(const struct qib_devdata *dd,
757 const u32 regno)
759 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
760 return -1;
761 return readl((u32 __iomem *) &dd->kregbase[regno]);
764 static inline u64 qib_read_kreg64(const struct qib_devdata *dd,
765 const u32 regno)
767 if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
768 return -1;
769 return readq(&dd->kregbase[regno]);
772 static inline void qib_write_kreg(const struct qib_devdata *dd,
773 const u32 regno, u64 value)
775 if (dd->kregbase && (dd->flags & QIB_PRESENT))
776 writeq(value, &dd->kregbase[regno]);
780 * not many sanity checks for the port-specific kernel register routines,
781 * since they are only used when it's known to be safe.
783 static inline u64 qib_read_kreg_port(const struct qib_pportdata *ppd,
784 const u16 regno)
786 if (!ppd->cpspec->kpregbase || !(ppd->dd->flags & QIB_PRESENT))
787 return 0ULL;
788 return readq(&ppd->cpspec->kpregbase[regno]);
791 static inline void qib_write_kreg_port(const struct qib_pportdata *ppd,
792 const u16 regno, u64 value)
794 if (ppd->cpspec && ppd->dd && ppd->cpspec->kpregbase &&
795 (ppd->dd->flags & QIB_PRESENT))
796 writeq(value, &ppd->cpspec->kpregbase[regno]);
800 * qib_write_kreg_ctxt - write a device's per-ctxt 64-bit kernel register
801 * @dd: the qlogic_ib device
802 * @regno: the register number to write
803 * @ctxt: the context containing the register
804 * @value: the value to write
806 static inline void qib_write_kreg_ctxt(const struct qib_devdata *dd,
807 const u16 regno, unsigned ctxt,
808 u64 value)
810 qib_write_kreg(dd, regno + ctxt, value);
813 static inline u64 read_7322_creg(const struct qib_devdata *dd, u16 regno)
815 if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
816 return 0;
817 return readq(&dd->cspec->cregbase[regno]);
822 static inline u32 read_7322_creg32(const struct qib_devdata *dd, u16 regno)
824 if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
825 return 0;
826 return readl(&dd->cspec->cregbase[regno]);
831 static inline void write_7322_creg_port(const struct qib_pportdata *ppd,
832 u16 regno, u64 value)
834 if (ppd->cpspec && ppd->cpspec->cpregbase &&
835 (ppd->dd->flags & QIB_PRESENT))
836 writeq(value, &ppd->cpspec->cpregbase[regno]);
839 static inline u64 read_7322_creg_port(const struct qib_pportdata *ppd,
840 u16 regno)
842 if (!ppd->cpspec || !ppd->cpspec->cpregbase ||
843 !(ppd->dd->flags & QIB_PRESENT))
844 return 0;
845 return readq(&ppd->cpspec->cpregbase[regno]);
848 static inline u32 read_7322_creg32_port(const struct qib_pportdata *ppd,
849 u16 regno)
851 if (!ppd->cpspec || !ppd->cpspec->cpregbase ||
852 !(ppd->dd->flags & QIB_PRESENT))
853 return 0;
854 return readl(&ppd->cpspec->cpregbase[regno]);
857 /* bits in Control register */
858 #define QLOGIC_IB_C_RESET SYM_MASK(Control, SyncReset)
859 #define QLOGIC_IB_C_SDMAFETCHPRIOEN SYM_MASK(Control, SDmaDescFetchPriorityEn)
861 /* bits in general interrupt regs */
862 #define QIB_I_RCVURG_LSB SYM_LSB(IntMask, RcvUrg0IntMask)
863 #define QIB_I_RCVURG_RMASK MASK_ACROSS(0, 17)
864 #define QIB_I_RCVURG_MASK (QIB_I_RCVURG_RMASK << QIB_I_RCVURG_LSB)
865 #define QIB_I_RCVAVAIL_LSB SYM_LSB(IntMask, RcvAvail0IntMask)
866 #define QIB_I_RCVAVAIL_RMASK MASK_ACROSS(0, 17)
867 #define QIB_I_RCVAVAIL_MASK (QIB_I_RCVAVAIL_RMASK << QIB_I_RCVAVAIL_LSB)
868 #define QIB_I_C_ERROR INT_MASK(Err)
870 #define QIB_I_SPIOSENT (INT_MASK_P(SendDone, 0) | INT_MASK_P(SendDone, 1))
871 #define QIB_I_SPIOBUFAVAIL INT_MASK(SendBufAvail)
872 #define QIB_I_GPIO INT_MASK(AssertGPIO)
873 #define QIB_I_P_SDMAINT(pidx) \
874 (INT_MASK_P(SDma, pidx) | INT_MASK_P(SDmaIdle, pidx) | \
875 INT_MASK_P(SDmaProgress, pidx) | \
876 INT_MASK_PM(SDmaCleanupDone, pidx))
878 /* Interrupt bits that are "per port" */
879 #define QIB_I_P_BITSEXTANT(pidx) \
880 (INT_MASK_P(Err, pidx) | INT_MASK_P(SendDone, pidx) | \
881 INT_MASK_P(SDma, pidx) | INT_MASK_P(SDmaIdle, pidx) | \
882 INT_MASK_P(SDmaProgress, pidx) | \
883 INT_MASK_PM(SDmaCleanupDone, pidx))
885 /* Interrupt bits that are common to a device */
886 /* currently unused: QIB_I_SPIOSENT */
887 #define QIB_I_C_BITSEXTANT \
888 (QIB_I_RCVURG_MASK | QIB_I_RCVAVAIL_MASK | \
889 QIB_I_SPIOSENT | \
890 QIB_I_C_ERROR | QIB_I_SPIOBUFAVAIL | QIB_I_GPIO)
892 #define QIB_I_BITSEXTANT (QIB_I_C_BITSEXTANT | \
893 QIB_I_P_BITSEXTANT(0) | QIB_I_P_BITSEXTANT(1))
896 * Error bits that are "per port".
898 #define QIB_E_P_IBSTATUSCHANGED ERR_MASK_N(IBStatusChanged)
899 #define QIB_E_P_SHDR ERR_MASK_N(SHeadersErr)
900 #define QIB_E_P_VL15_BUF_MISUSE ERR_MASK_N(VL15BufMisuseErr)
901 #define QIB_E_P_SND_BUF_MISUSE ERR_MASK_N(SendBufMisuseErr)
902 #define QIB_E_P_SUNSUPVL ERR_MASK_N(SendUnsupportedVLErr)
903 #define QIB_E_P_SUNEXP_PKTNUM ERR_MASK_N(SendUnexpectedPktNumErr)
904 #define QIB_E_P_SDROP_DATA ERR_MASK_N(SendDroppedDataPktErr)
905 #define QIB_E_P_SDROP_SMP ERR_MASK_N(SendDroppedSmpPktErr)
906 #define QIB_E_P_SPKTLEN ERR_MASK_N(SendPktLenErr)
907 #define QIB_E_P_SUNDERRUN ERR_MASK_N(SendUnderRunErr)
908 #define QIB_E_P_SMAXPKTLEN ERR_MASK_N(SendMaxPktLenErr)
909 #define QIB_E_P_SMINPKTLEN ERR_MASK_N(SendMinPktLenErr)
910 #define QIB_E_P_RIBLOSTLINK ERR_MASK_N(RcvIBLostLinkErr)
911 #define QIB_E_P_RHDR ERR_MASK_N(RcvHdrErr)
912 #define QIB_E_P_RHDRLEN ERR_MASK_N(RcvHdrLenErr)
913 #define QIB_E_P_RBADTID ERR_MASK_N(RcvBadTidErr)
914 #define QIB_E_P_RBADVERSION ERR_MASK_N(RcvBadVersionErr)
915 #define QIB_E_P_RIBFLOW ERR_MASK_N(RcvIBFlowErr)
916 #define QIB_E_P_REBP ERR_MASK_N(RcvEBPErr)
917 #define QIB_E_P_RUNSUPVL ERR_MASK_N(RcvUnsupportedVLErr)
918 #define QIB_E_P_RUNEXPCHAR ERR_MASK_N(RcvUnexpectedCharErr)
919 #define QIB_E_P_RSHORTPKTLEN ERR_MASK_N(RcvShortPktLenErr)
920 #define QIB_E_P_RLONGPKTLEN ERR_MASK_N(RcvLongPktLenErr)
921 #define QIB_E_P_RMAXPKTLEN ERR_MASK_N(RcvMaxPktLenErr)
922 #define QIB_E_P_RMINPKTLEN ERR_MASK_N(RcvMinPktLenErr)
923 #define QIB_E_P_RICRC ERR_MASK_N(RcvICRCErr)
924 #define QIB_E_P_RVCRC ERR_MASK_N(RcvVCRCErr)
925 #define QIB_E_P_RFORMATERR ERR_MASK_N(RcvFormatErr)
927 #define QIB_E_P_SDMA1STDESC ERR_MASK_N(SDma1stDescErr)
928 #define QIB_E_P_SDMABASE ERR_MASK_N(SDmaBaseErr)
929 #define QIB_E_P_SDMADESCADDRMISALIGN ERR_MASK_N(SDmaDescAddrMisalignErr)
930 #define QIB_E_P_SDMADWEN ERR_MASK_N(SDmaDwEnErr)
931 #define QIB_E_P_SDMAGENMISMATCH ERR_MASK_N(SDmaGenMismatchErr)
932 #define QIB_E_P_SDMAHALT ERR_MASK_N(SDmaHaltErr)
933 #define QIB_E_P_SDMAMISSINGDW ERR_MASK_N(SDmaMissingDwErr)
934 #define QIB_E_P_SDMAOUTOFBOUND ERR_MASK_N(SDmaOutOfBoundErr)
935 #define QIB_E_P_SDMARPYTAG ERR_MASK_N(SDmaRpyTagErr)
936 #define QIB_E_P_SDMATAILOUTOFBOUND ERR_MASK_N(SDmaTailOutOfBoundErr)
937 #define QIB_E_P_SDMAUNEXPDATA ERR_MASK_N(SDmaUnexpDataErr)
939 /* Error bits that are common to a device */
940 #define QIB_E_RESET ERR_MASK(ResetNegated)
941 #define QIB_E_HARDWARE ERR_MASK(HardwareErr)
942 #define QIB_E_INVALIDADDR ERR_MASK(InvalidAddrErr)
946 * Per chip (rather than per-port) errors. Most either do
947 * nothing but trigger a print (because they self-recover, or
948 * always occur in tandem with other errors that handle the
949 * issue), or because they indicate errors with no recovery,
950 * but we want to know that they happened.
952 #define QIB_E_SBUF_VL15_MISUSE ERR_MASK(SBufVL15MisUseErr)
953 #define QIB_E_BADEEP ERR_MASK(InvalidEEPCmd)
954 #define QIB_E_VLMISMATCH ERR_MASK(SendVLMismatchErr)
955 #define QIB_E_ARMLAUNCH ERR_MASK(SendArmLaunchErr)
956 #define QIB_E_SPCLTRIG ERR_MASK(SendSpecialTriggerErr)
957 #define QIB_E_RRCVHDRFULL ERR_MASK(RcvHdrFullErr)
958 #define QIB_E_RRCVEGRFULL ERR_MASK(RcvEgrFullErr)
959 #define QIB_E_RCVCTXTSHARE ERR_MASK(RcvContextShareErr)
961 /* SDMA chip errors (not per port)
962 * QIB_E_SDMA_BUF_DUP needs no special handling, because we will also get
963 * the SDMAHALT error immediately, so we just print the dup error via the
964 * E_AUTO mechanism. This is true of most of the per-port fatal errors
965 * as well, but since this is port-independent, by definition, it's
966 * handled a bit differently. SDMA_VL15 and SDMA_WRONG_PORT are per
967 * packet send errors, and so are handled in the same manner as other
968 * per-packet errors.
970 #define QIB_E_SDMA_VL15 ERR_MASK(SDmaVL15Err)
971 #define QIB_E_SDMA_WRONG_PORT ERR_MASK(SDmaWrongPortErr)
972 #define QIB_E_SDMA_BUF_DUP ERR_MASK(SDmaBufMaskDuplicateErr)
975 * Below functionally equivalent to legacy QLOGIC_IB_E_PKTERRS
976 * it is used to print "common" packet errors.
978 #define QIB_E_P_PKTERRS (QIB_E_P_SPKTLEN |\
979 QIB_E_P_SDROP_DATA | QIB_E_P_RVCRC |\
980 QIB_E_P_RICRC | QIB_E_P_RSHORTPKTLEN |\
981 QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SHDR | \
982 QIB_E_P_REBP)
984 /* Error Bits that Packet-related (Receive, per-port) */
985 #define QIB_E_P_RPKTERRS (\
986 QIB_E_P_RHDRLEN | QIB_E_P_RBADTID | \
987 QIB_E_P_RBADVERSION | QIB_E_P_RHDR | \
988 QIB_E_P_RLONGPKTLEN | QIB_E_P_RSHORTPKTLEN |\
989 QIB_E_P_RMAXPKTLEN | QIB_E_P_RMINPKTLEN | \
990 QIB_E_P_RFORMATERR | QIB_E_P_RUNSUPVL | \
991 QIB_E_P_RUNEXPCHAR | QIB_E_P_RIBFLOW | QIB_E_P_REBP)
994 * Error bits that are Send-related (per port)
995 * (ARMLAUNCH excluded from E_SPKTERRS because it gets special handling).
996 * All of these potentially need to have a buffer disarmed
998 #define QIB_E_P_SPKTERRS (\
999 QIB_E_P_SUNEXP_PKTNUM |\
1000 QIB_E_P_SDROP_DATA | QIB_E_P_SDROP_SMP |\
1001 QIB_E_P_SMAXPKTLEN |\
1002 QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SHDR | \
1003 QIB_E_P_SMINPKTLEN | QIB_E_P_SPKTLEN | \
1004 QIB_E_P_SND_BUF_MISUSE | QIB_E_P_SUNSUPVL)
1006 #define QIB_E_SPKTERRS ( \
1007 QIB_E_SBUF_VL15_MISUSE | QIB_E_VLMISMATCH | \
1008 ERR_MASK_N(SendUnsupportedVLErr) | \
1009 QIB_E_SPCLTRIG | QIB_E_SDMA_VL15 | QIB_E_SDMA_WRONG_PORT)
1011 #define QIB_E_P_SDMAERRS ( \
1012 QIB_E_P_SDMAHALT | \
1013 QIB_E_P_SDMADESCADDRMISALIGN | \
1014 QIB_E_P_SDMAUNEXPDATA | \
1015 QIB_E_P_SDMAMISSINGDW | \
1016 QIB_E_P_SDMADWEN | \
1017 QIB_E_P_SDMARPYTAG | \
1018 QIB_E_P_SDMA1STDESC | \
1019 QIB_E_P_SDMABASE | \
1020 QIB_E_P_SDMATAILOUTOFBOUND | \
1021 QIB_E_P_SDMAOUTOFBOUND | \
1022 QIB_E_P_SDMAGENMISMATCH)
1025 * This sets some bits more than once, but makes it more obvious which
1026 * bits are not handled under other categories, and the repeat definition
1027 * is not a problem.
1029 #define QIB_E_P_BITSEXTANT ( \
1030 QIB_E_P_SPKTERRS | QIB_E_P_PKTERRS | QIB_E_P_RPKTERRS | \
1031 QIB_E_P_RIBLOSTLINK | QIB_E_P_IBSTATUSCHANGED | \
1032 QIB_E_P_SND_BUF_MISUSE | QIB_E_P_SUNDERRUN | \
1033 QIB_E_P_SHDR | QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SDMAERRS \
1037 * These are errors that can occur when the link
1038 * changes state while a packet is being sent or received. This doesn't
1039 * cover things like EBP or VCRC that can be the result of a sending
1040 * having the link change state, so we receive a "known bad" packet.
1041 * All of these are "per port", so renamed:
1043 #define QIB_E_P_LINK_PKTERRS (\
1044 QIB_E_P_SDROP_DATA | QIB_E_P_SDROP_SMP |\
1045 QIB_E_P_SMINPKTLEN | QIB_E_P_SPKTLEN |\
1046 QIB_E_P_RSHORTPKTLEN | QIB_E_P_RMINPKTLEN |\
1047 QIB_E_P_RUNEXPCHAR)
1050 * This sets some bits more than once, but makes it more obvious which
1051 * bits are not handled under other categories (such as QIB_E_SPKTERRS),
1052 * and the repeat definition is not a problem.
1054 #define QIB_E_C_BITSEXTANT (\
1055 QIB_E_HARDWARE | QIB_E_INVALIDADDR | QIB_E_BADEEP |\
1056 QIB_E_ARMLAUNCH | QIB_E_VLMISMATCH | QIB_E_RRCVHDRFULL |\
1057 QIB_E_RRCVEGRFULL | QIB_E_RESET | QIB_E_SBUF_VL15_MISUSE)
1059 /* Likewise Neuter E_SPKT_ERRS_IGNORE */
1060 #define E_SPKT_ERRS_IGNORE 0
1062 #define QIB_EXTS_MEMBIST_DISABLED \
1063 SYM_MASK(EXTStatus, MemBISTDisabled)
1064 #define QIB_EXTS_MEMBIST_ENDTEST \
1065 SYM_MASK(EXTStatus, MemBISTEndTest)
1067 #define QIB_E_SPIOARMLAUNCH \
1068 ERR_MASK(SendArmLaunchErr)
1070 #define IBA7322_IBCC_LINKINITCMD_MASK SYM_RMASK(IBCCtrlA_0, LinkInitCmd)
1071 #define IBA7322_IBCC_LINKCMD_SHIFT SYM_LSB(IBCCtrlA_0, LinkCmd)
1074 * IBTA_1_2 is set when multiple speeds are enabled (normal),
1075 * and also if forced QDR (only QDR enabled). It's enabled for the
1076 * forced QDR case so that scrambling will be enabled by the TS3
1077 * exchange, when supported by both sides of the link.
1079 #define IBA7322_IBC_IBTA_1_2_MASK SYM_MASK(IBCCtrlB_0, IB_ENHANCED_MODE)
1080 #define IBA7322_IBC_MAX_SPEED_MASK SYM_MASK(IBCCtrlB_0, SD_SPEED)
1081 #define IBA7322_IBC_SPEED_QDR SYM_MASK(IBCCtrlB_0, SD_SPEED_QDR)
1082 #define IBA7322_IBC_SPEED_DDR SYM_MASK(IBCCtrlB_0, SD_SPEED_DDR)
1083 #define IBA7322_IBC_SPEED_SDR SYM_MASK(IBCCtrlB_0, SD_SPEED_SDR)
1084 #define IBA7322_IBC_SPEED_MASK (SYM_MASK(IBCCtrlB_0, SD_SPEED_SDR) | \
1085 SYM_MASK(IBCCtrlB_0, SD_SPEED_DDR) | SYM_MASK(IBCCtrlB_0, SD_SPEED_QDR))
1086 #define IBA7322_IBC_SPEED_LSB SYM_LSB(IBCCtrlB_0, SD_SPEED_SDR)
1088 #define IBA7322_LEDBLINK_OFF_SHIFT SYM_LSB(RcvPktLEDCnt_0, OFFperiod)
1089 #define IBA7322_LEDBLINK_ON_SHIFT SYM_LSB(RcvPktLEDCnt_0, ONperiod)
1091 #define IBA7322_IBC_WIDTH_AUTONEG SYM_MASK(IBCCtrlB_0, IB_NUM_CHANNELS)
1092 #define IBA7322_IBC_WIDTH_4X_ONLY (1<<SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS))
1093 #define IBA7322_IBC_WIDTH_1X_ONLY (0<<SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS))
1095 #define IBA7322_IBC_RXPOL_MASK SYM_MASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP)
1096 #define IBA7322_IBC_RXPOL_LSB SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP)
1097 #define IBA7322_IBC_HRTBT_MASK (SYM_MASK(IBCCtrlB_0, HRTBT_AUTO) | \
1098 SYM_MASK(IBCCtrlB_0, HRTBT_ENB))
1099 #define IBA7322_IBC_HRTBT_RMASK (IBA7322_IBC_HRTBT_MASK >> \
1100 SYM_LSB(IBCCtrlB_0, HRTBT_ENB))
1101 #define IBA7322_IBC_HRTBT_LSB SYM_LSB(IBCCtrlB_0, HRTBT_ENB)
1103 #define IBA7322_REDIRECT_VEC_PER_REG 12
1105 #define IBA7322_SENDCHK_PKEY SYM_MASK(SendCheckControl_0, PKey_En)
1106 #define IBA7322_SENDCHK_BTHQP SYM_MASK(SendCheckControl_0, BTHQP_En)
1107 #define IBA7322_SENDCHK_SLID SYM_MASK(SendCheckControl_0, SLID_En)
1108 #define IBA7322_SENDCHK_RAW_IPV6 SYM_MASK(SendCheckControl_0, RawIPV6_En)
1109 #define IBA7322_SENDCHK_MINSZ SYM_MASK(SendCheckControl_0, PacketTooSmall_En)
1111 #define AUTONEG_TRIES 3 /* sequential retries to negotiate DDR */
1113 #define HWE_AUTO(fldname) { .mask = SYM_MASK(HwErrMask, fldname##Mask), \
1114 .msg = #fldname , .sz = sizeof(#fldname) }
1115 #define HWE_AUTO_P(fldname, port) { .mask = SYM_MASK(HwErrMask, \
1116 fldname##Mask##_##port), .msg = #fldname , .sz = sizeof(#fldname) }
1117 static const struct qib_hwerror_msgs qib_7322_hwerror_msgs[] = {
1118 HWE_AUTO_P(IBSerdesPClkNotDetect, 1),
1119 HWE_AUTO_P(IBSerdesPClkNotDetect, 0),
1120 HWE_AUTO(PCIESerdesPClkNotDetect),
1121 HWE_AUTO(PowerOnBISTFailed),
1122 HWE_AUTO(TempsenseTholdReached),
1123 HWE_AUTO(MemoryErr),
1124 HWE_AUTO(PCIeBusParityErr),
1125 HWE_AUTO(PcieCplTimeout),
1126 HWE_AUTO(PciePoisonedTLP),
1127 HWE_AUTO_P(SDmaMemReadErr, 1),
1128 HWE_AUTO_P(SDmaMemReadErr, 0),
1129 HWE_AUTO_P(IBCBusFromSPCParityErr, 1),
1130 HWE_AUTO_P(IBCBusToSPCParityErr, 1),
1131 HWE_AUTO_P(IBCBusFromSPCParityErr, 0),
1132 HWE_AUTO(statusValidNoEop),
1133 HWE_AUTO(LATriggered),
1134 { .mask = 0, .sz = 0 }
1137 #define E_AUTO(fldname) { .mask = SYM_MASK(ErrMask, fldname##Mask), \
1138 .msg = #fldname, .sz = sizeof(#fldname) }
1139 #define E_P_AUTO(fldname) { .mask = SYM_MASK(ErrMask_0, fldname##Mask), \
1140 .msg = #fldname, .sz = sizeof(#fldname) }
1141 static const struct qib_hwerror_msgs qib_7322error_msgs[] = {
1142 E_AUTO(RcvEgrFullErr),
1143 E_AUTO(RcvHdrFullErr),
1144 E_AUTO(ResetNegated),
1145 E_AUTO(HardwareErr),
1146 E_AUTO(InvalidAddrErr),
1147 E_AUTO(SDmaVL15Err),
1148 E_AUTO(SBufVL15MisUseErr),
1149 E_AUTO(InvalidEEPCmd),
1150 E_AUTO(RcvContextShareErr),
1151 E_AUTO(SendVLMismatchErr),
1152 E_AUTO(SendArmLaunchErr),
1153 E_AUTO(SendSpecialTriggerErr),
1154 E_AUTO(SDmaWrongPortErr),
1155 E_AUTO(SDmaBufMaskDuplicateErr),
1156 { .mask = 0, .sz = 0 }
1159 static const struct qib_hwerror_msgs qib_7322p_error_msgs[] = {
1160 E_P_AUTO(IBStatusChanged),
1161 E_P_AUTO(SHeadersErr),
1162 E_P_AUTO(VL15BufMisuseErr),
1164 * SDmaHaltErr is not really an error, make it clearer;
1166 {.mask = SYM_MASK(ErrMask_0, SDmaHaltErrMask), .msg = "SDmaHalted",
1167 .sz = 11},
1168 E_P_AUTO(SDmaDescAddrMisalignErr),
1169 E_P_AUTO(SDmaUnexpDataErr),
1170 E_P_AUTO(SDmaMissingDwErr),
1171 E_P_AUTO(SDmaDwEnErr),
1172 E_P_AUTO(SDmaRpyTagErr),
1173 E_P_AUTO(SDma1stDescErr),
1174 E_P_AUTO(SDmaBaseErr),
1175 E_P_AUTO(SDmaTailOutOfBoundErr),
1176 E_P_AUTO(SDmaOutOfBoundErr),
1177 E_P_AUTO(SDmaGenMismatchErr),
1178 E_P_AUTO(SendBufMisuseErr),
1179 E_P_AUTO(SendUnsupportedVLErr),
1180 E_P_AUTO(SendUnexpectedPktNumErr),
1181 E_P_AUTO(SendDroppedDataPktErr),
1182 E_P_AUTO(SendDroppedSmpPktErr),
1183 E_P_AUTO(SendPktLenErr),
1184 E_P_AUTO(SendUnderRunErr),
1185 E_P_AUTO(SendMaxPktLenErr),
1186 E_P_AUTO(SendMinPktLenErr),
1187 E_P_AUTO(RcvIBLostLinkErr),
1188 E_P_AUTO(RcvHdrErr),
1189 E_P_AUTO(RcvHdrLenErr),
1190 E_P_AUTO(RcvBadTidErr),
1191 E_P_AUTO(RcvBadVersionErr),
1192 E_P_AUTO(RcvIBFlowErr),
1193 E_P_AUTO(RcvEBPErr),
1194 E_P_AUTO(RcvUnsupportedVLErr),
1195 E_P_AUTO(RcvUnexpectedCharErr),
1196 E_P_AUTO(RcvShortPktLenErr),
1197 E_P_AUTO(RcvLongPktLenErr),
1198 E_P_AUTO(RcvMaxPktLenErr),
1199 E_P_AUTO(RcvMinPktLenErr),
1200 E_P_AUTO(RcvICRCErr),
1201 E_P_AUTO(RcvVCRCErr),
1202 E_P_AUTO(RcvFormatErr),
1203 { .mask = 0, .sz = 0 }
1207 * Below generates "auto-message" for interrupts not specific to any port or
1208 * context
1210 #define INTR_AUTO(fldname) { .mask = SYM_MASK(IntMask, fldname##Mask), \
1211 .msg = #fldname, .sz = sizeof(#fldname) }
1212 /* Below generates "auto-message" for interrupts specific to a port */
1213 #define INTR_AUTO_P(fldname) { .mask = MASK_ACROSS(\
1214 SYM_LSB(IntMask, fldname##Mask##_0), \
1215 SYM_LSB(IntMask, fldname##Mask##_1)), \
1216 .msg = #fldname "_P", .sz = sizeof(#fldname "_P") }
1217 /* For some reason, the SerDesTrimDone bits are reversed */
1218 #define INTR_AUTO_PI(fldname) { .mask = MASK_ACROSS(\
1219 SYM_LSB(IntMask, fldname##Mask##_1), \
1220 SYM_LSB(IntMask, fldname##Mask##_0)), \
1221 .msg = #fldname "_P", .sz = sizeof(#fldname "_P") }
1223 * Below generates "auto-message" for interrupts specific to a context,
1224 * with ctxt-number appended
1226 #define INTR_AUTO_C(fldname) { .mask = MASK_ACROSS(\
1227 SYM_LSB(IntMask, fldname##0IntMask), \
1228 SYM_LSB(IntMask, fldname##17IntMask)), \
1229 .msg = #fldname "_C", .sz = sizeof(#fldname "_C") }
1231 static const struct qib_hwerror_msgs qib_7322_intr_msgs[] = {
1232 INTR_AUTO_P(SDmaInt),
1233 INTR_AUTO_P(SDmaProgressInt),
1234 INTR_AUTO_P(SDmaIdleInt),
1235 INTR_AUTO_P(SDmaCleanupDone),
1236 INTR_AUTO_C(RcvUrg),
1237 INTR_AUTO_P(ErrInt),
1238 INTR_AUTO(ErrInt), /* non-port-specific errs */
1239 INTR_AUTO(AssertGPIOInt),
1240 INTR_AUTO_P(SendDoneInt),
1241 INTR_AUTO(SendBufAvailInt),
1242 INTR_AUTO_C(RcvAvail),
1243 { .mask = 0, .sz = 0 }
1246 #define TXSYMPTOM_AUTO_P(fldname) \
1247 { .mask = SYM_MASK(SendHdrErrSymptom_0, fldname), \
1248 .msg = #fldname, .sz = sizeof(#fldname) }
1249 static const struct qib_hwerror_msgs hdrchk_msgs[] = {
1250 TXSYMPTOM_AUTO_P(NonKeyPacket),
1251 TXSYMPTOM_AUTO_P(GRHFail),
1252 TXSYMPTOM_AUTO_P(PkeyFail),
1253 TXSYMPTOM_AUTO_P(QPFail),
1254 TXSYMPTOM_AUTO_P(SLIDFail),
1255 TXSYMPTOM_AUTO_P(RawIPV6),
1256 TXSYMPTOM_AUTO_P(PacketTooSmall),
1257 { .mask = 0, .sz = 0 }
1260 #define IBA7322_HDRHEAD_PKTINT_SHIFT 32 /* interrupt cnt in upper 32 bits */
1263 * Called when we might have an error that is specific to a particular
1264 * PIO buffer, and may need to cancel that buffer, so it can be re-used,
1265 * because we don't need to force the update of pioavail
1267 static void qib_disarm_7322_senderrbufs(struct qib_pportdata *ppd)
1269 struct qib_devdata *dd = ppd->dd;
1270 u32 i;
1271 int any;
1272 u32 piobcnt = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
1273 u32 regcnt = (piobcnt + BITS_PER_LONG - 1) / BITS_PER_LONG;
1274 unsigned long sbuf[4];
1277 * It's possible that sendbuffererror could have bits set; might
1278 * have already done this as a result of hardware error handling.
1280 any = 0;
1281 for (i = 0; i < regcnt; ++i) {
1282 sbuf[i] = qib_read_kreg64(dd, kr_sendbuffererror + i);
1283 if (sbuf[i]) {
1284 any = 1;
1285 qib_write_kreg(dd, kr_sendbuffererror + i, sbuf[i]);
1289 if (any)
1290 qib_disarm_piobufs_set(dd, sbuf, piobcnt);
1293 /* No txe_recover yet, if ever */
1295 /* No decode__errors yet */
1296 static void err_decode(char *msg, size_t len, u64 errs,
1297 const struct qib_hwerror_msgs *msp)
1299 u64 these, lmask;
1300 int took, multi, n = 0;
1302 while (errs && msp && msp->mask) {
1303 multi = (msp->mask & (msp->mask - 1));
1304 while (errs & msp->mask) {
1305 these = (errs & msp->mask);
1306 lmask = (these & (these - 1)) ^ these;
1307 if (len) {
1308 if (n++) {
1309 /* separate the strings */
1310 *msg++ = ',';
1311 len--;
1313 BUG_ON(!msp->sz);
1314 /* msp->sz counts the nul */
1315 took = min_t(size_t, msp->sz - (size_t)1, len);
1316 memcpy(msg, msp->msg, took);
1317 len -= took;
1318 msg += took;
1319 if (len)
1320 *msg = '\0';
1322 errs &= ~lmask;
1323 if (len && multi) {
1324 /* More than one bit this mask */
1325 int idx = -1;
1327 while (lmask & msp->mask) {
1328 ++idx;
1329 lmask >>= 1;
1331 took = scnprintf(msg, len, "_%d", idx);
1332 len -= took;
1333 msg += took;
1336 ++msp;
1338 /* If some bits are left, show in hex. */
1339 if (len && errs)
1340 snprintf(msg, len, "%sMORE:%llX", n ? "," : "",
1341 (unsigned long long) errs);
1344 /* only called if r1 set */
1345 static void flush_fifo(struct qib_pportdata *ppd)
1347 struct qib_devdata *dd = ppd->dd;
1348 u32 __iomem *piobuf;
1349 u32 bufn;
1350 u32 *hdr;
1351 u64 pbc;
1352 const unsigned hdrwords = 7;
1353 static struct qib_ib_header ibhdr = {
1354 .lrh[0] = cpu_to_be16(0xF000 | QIB_LRH_BTH),
1355 .lrh[1] = IB_LID_PERMISSIVE,
1356 .lrh[2] = cpu_to_be16(hdrwords + SIZE_OF_CRC),
1357 .lrh[3] = IB_LID_PERMISSIVE,
1358 .u.oth.bth[0] = cpu_to_be32(
1359 (IB_OPCODE_UD_SEND_ONLY << 24) | QIB_DEFAULT_P_KEY),
1360 .u.oth.bth[1] = cpu_to_be32(0),
1361 .u.oth.bth[2] = cpu_to_be32(0),
1362 .u.oth.u.ud.deth[0] = cpu_to_be32(0),
1363 .u.oth.u.ud.deth[1] = cpu_to_be32(0),
1367 * Send a dummy VL15 packet to flush the launch FIFO.
1368 * This will not actually be sent since the TxeBypassIbc bit is set.
1370 pbc = PBC_7322_VL15_SEND |
1371 (((u64)ppd->hw_pidx) << (PBC_PORT_SEL_LSB + 32)) |
1372 (hdrwords + SIZE_OF_CRC);
1373 piobuf = qib_7322_getsendbuf(ppd, pbc, &bufn);
1374 if (!piobuf)
1375 return;
1376 writeq(pbc, piobuf);
1377 hdr = (u32 *) &ibhdr;
1378 if (dd->flags & QIB_PIO_FLUSH_WC) {
1379 qib_flush_wc();
1380 qib_pio_copy(piobuf + 2, hdr, hdrwords - 1);
1381 qib_flush_wc();
1382 __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords + 1);
1383 qib_flush_wc();
1384 } else
1385 qib_pio_copy(piobuf + 2, hdr, hdrwords);
1386 qib_sendbuf_done(dd, bufn);
1390 * This is called with interrupts disabled and sdma_lock held.
1392 static void qib_7322_sdma_sendctrl(struct qib_pportdata *ppd, unsigned op)
1394 struct qib_devdata *dd = ppd->dd;
1395 u64 set_sendctrl = 0;
1396 u64 clr_sendctrl = 0;
1398 if (op & QIB_SDMA_SENDCTRL_OP_ENABLE)
1399 set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaEnable);
1400 else
1401 clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaEnable);
1403 if (op & QIB_SDMA_SENDCTRL_OP_INTENABLE)
1404 set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaIntEnable);
1405 else
1406 clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaIntEnable);
1408 if (op & QIB_SDMA_SENDCTRL_OP_HALT)
1409 set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaHalt);
1410 else
1411 clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaHalt);
1413 if (op & QIB_SDMA_SENDCTRL_OP_DRAIN)
1414 set_sendctrl |= SYM_MASK(SendCtrl_0, TxeBypassIbc) |
1415 SYM_MASK(SendCtrl_0, TxeAbortIbc) |
1416 SYM_MASK(SendCtrl_0, TxeDrainRmFifo);
1417 else
1418 clr_sendctrl |= SYM_MASK(SendCtrl_0, TxeBypassIbc) |
1419 SYM_MASK(SendCtrl_0, TxeAbortIbc) |
1420 SYM_MASK(SendCtrl_0, TxeDrainRmFifo);
1422 spin_lock(&dd->sendctrl_lock);
1424 /* If we are draining everything, block sends first */
1425 if (op & QIB_SDMA_SENDCTRL_OP_DRAIN) {
1426 ppd->p_sendctrl &= ~SYM_MASK(SendCtrl_0, SendEnable);
1427 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
1428 qib_write_kreg(dd, kr_scratch, 0);
1431 ppd->p_sendctrl |= set_sendctrl;
1432 ppd->p_sendctrl &= ~clr_sendctrl;
1434 if (op & QIB_SDMA_SENDCTRL_OP_CLEANUP)
1435 qib_write_kreg_port(ppd, krp_sendctrl,
1436 ppd->p_sendctrl |
1437 SYM_MASK(SendCtrl_0, SDmaCleanup));
1438 else
1439 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
1440 qib_write_kreg(dd, kr_scratch, 0);
1442 if (op & QIB_SDMA_SENDCTRL_OP_DRAIN) {
1443 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, SendEnable);
1444 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
1445 qib_write_kreg(dd, kr_scratch, 0);
1448 spin_unlock(&dd->sendctrl_lock);
1450 if ((op & QIB_SDMA_SENDCTRL_OP_DRAIN) && ppd->dd->cspec->r1)
1451 flush_fifo(ppd);
1454 static void qib_7322_sdma_hw_clean_up(struct qib_pportdata *ppd)
1456 __qib_sdma_process_event(ppd, qib_sdma_event_e50_hw_cleaned);
1459 static void qib_sdma_7322_setlengen(struct qib_pportdata *ppd)
1462 * Set SendDmaLenGen and clear and set
1463 * the MSB of the generation count to enable generation checking
1464 * and load the internal generation counter.
1466 qib_write_kreg_port(ppd, krp_senddmalengen, ppd->sdma_descq_cnt);
1467 qib_write_kreg_port(ppd, krp_senddmalengen,
1468 ppd->sdma_descq_cnt |
1469 (1ULL << QIB_7322_SendDmaLenGen_0_Generation_MSB));
1473 * Must be called with sdma_lock held, or before init finished.
1475 static void qib_sdma_update_7322_tail(struct qib_pportdata *ppd, u16 tail)
1477 /* Commit writes to memory and advance the tail on the chip */
1478 wmb();
1479 ppd->sdma_descq_tail = tail;
1480 qib_write_kreg_port(ppd, krp_senddmatail, tail);
1484 * This is called with interrupts disabled and sdma_lock held.
1486 static void qib_7322_sdma_hw_start_up(struct qib_pportdata *ppd)
1489 * Drain all FIFOs.
1490 * The hardware doesn't require this but we do it so that verbs
1491 * and user applications don't wait for link active to send stale
1492 * data.
1494 sendctrl_7322_mod(ppd, QIB_SENDCTRL_FLUSH);
1496 qib_sdma_7322_setlengen(ppd);
1497 qib_sdma_update_7322_tail(ppd, 0); /* Set SendDmaTail */
1498 ppd->sdma_head_dma[0] = 0;
1499 qib_7322_sdma_sendctrl(ppd,
1500 ppd->sdma_state.current_op | QIB_SDMA_SENDCTRL_OP_CLEANUP);
1503 #define DISABLES_SDMA ( \
1504 QIB_E_P_SDMAHALT | \
1505 QIB_E_P_SDMADESCADDRMISALIGN | \
1506 QIB_E_P_SDMAMISSINGDW | \
1507 QIB_E_P_SDMADWEN | \
1508 QIB_E_P_SDMARPYTAG | \
1509 QIB_E_P_SDMA1STDESC | \
1510 QIB_E_P_SDMABASE | \
1511 QIB_E_P_SDMATAILOUTOFBOUND | \
1512 QIB_E_P_SDMAOUTOFBOUND | \
1513 QIB_E_P_SDMAGENMISMATCH)
1515 static void sdma_7322_p_errors(struct qib_pportdata *ppd, u64 errs)
1517 unsigned long flags;
1518 struct qib_devdata *dd = ppd->dd;
1520 errs &= QIB_E_P_SDMAERRS;
1522 if (errs & QIB_E_P_SDMAUNEXPDATA)
1523 qib_dev_err(dd, "IB%u:%u SDmaUnexpData\n", dd->unit,
1524 ppd->port);
1526 spin_lock_irqsave(&ppd->sdma_lock, flags);
1528 switch (ppd->sdma_state.current_state) {
1529 case qib_sdma_state_s00_hw_down:
1530 break;
1532 case qib_sdma_state_s10_hw_start_up_wait:
1533 if (errs & QIB_E_P_SDMAHALT)
1534 __qib_sdma_process_event(ppd,
1535 qib_sdma_event_e20_hw_started);
1536 break;
1538 case qib_sdma_state_s20_idle:
1539 break;
1541 case qib_sdma_state_s30_sw_clean_up_wait:
1542 break;
1544 case qib_sdma_state_s40_hw_clean_up_wait:
1545 if (errs & QIB_E_P_SDMAHALT)
1546 __qib_sdma_process_event(ppd,
1547 qib_sdma_event_e50_hw_cleaned);
1548 break;
1550 case qib_sdma_state_s50_hw_halt_wait:
1551 if (errs & QIB_E_P_SDMAHALT)
1552 __qib_sdma_process_event(ppd,
1553 qib_sdma_event_e60_hw_halted);
1554 break;
1556 case qib_sdma_state_s99_running:
1557 __qib_sdma_process_event(ppd, qib_sdma_event_e7322_err_halted);
1558 __qib_sdma_process_event(ppd, qib_sdma_event_e60_hw_halted);
1559 break;
1562 spin_unlock_irqrestore(&ppd->sdma_lock, flags);
1566 * handle per-device errors (not per-port errors)
1568 static noinline void handle_7322_errors(struct qib_devdata *dd)
1570 char *msg;
1571 u64 iserr = 0;
1572 u64 errs;
1573 u64 mask;
1574 int log_idx;
1576 qib_stats.sps_errints++;
1577 errs = qib_read_kreg64(dd, kr_errstatus);
1578 if (!errs) {
1579 qib_devinfo(dd->pcidev, "device error interrupt, "
1580 "but no error bits set!\n");
1581 goto done;
1584 /* don't report errors that are masked */
1585 errs &= dd->cspec->errormask;
1586 msg = dd->cspec->emsgbuf;
1588 /* do these first, they are most important */
1589 if (errs & QIB_E_HARDWARE) {
1590 *msg = '\0';
1591 qib_7322_handle_hwerrors(dd, msg, sizeof dd->cspec->emsgbuf);
1592 } else
1593 for (log_idx = 0; log_idx < QIB_EEP_LOG_CNT; ++log_idx)
1594 if (errs & dd->eep_st_masks[log_idx].errs_to_log)
1595 qib_inc_eeprom_err(dd, log_idx, 1);
1597 if (errs & QIB_E_SPKTERRS) {
1598 qib_disarm_7322_senderrbufs(dd->pport);
1599 qib_stats.sps_txerrs++;
1600 } else if (errs & QIB_E_INVALIDADDR)
1601 qib_stats.sps_txerrs++;
1602 else if (errs & QIB_E_ARMLAUNCH) {
1603 qib_stats.sps_txerrs++;
1604 qib_disarm_7322_senderrbufs(dd->pport);
1606 qib_write_kreg(dd, kr_errclear, errs);
1609 * The ones we mask off are handled specially below
1610 * or above. Also mask SDMADISABLED by default as it
1611 * is too chatty.
1613 mask = QIB_E_HARDWARE;
1614 *msg = '\0';
1616 err_decode(msg, sizeof dd->cspec->emsgbuf, errs & ~mask,
1617 qib_7322error_msgs);
1620 * Getting reset is a tragedy for all ports. Mark the device
1621 * _and_ the ports as "offline" in way meaningful to each.
1623 if (errs & QIB_E_RESET) {
1624 int pidx;
1626 qib_dev_err(dd, "Got reset, requires re-init "
1627 "(unload and reload driver)\n");
1628 dd->flags &= ~QIB_INITTED; /* needs re-init */
1629 /* mark as having had error */
1630 *dd->devstatusp |= QIB_STATUS_HWERROR;
1631 for (pidx = 0; pidx < dd->num_pports; ++pidx)
1632 if (dd->pport[pidx].link_speed_supported)
1633 *dd->pport[pidx].statusp &= ~QIB_STATUS_IB_CONF;
1636 if (*msg && iserr)
1637 qib_dev_err(dd, "%s error\n", msg);
1640 * If there were hdrq or egrfull errors, wake up any processes
1641 * waiting in poll. We used to try to check which contexts had
1642 * the overflow, but given the cost of that and the chip reads
1643 * to support it, it's better to just wake everybody up if we
1644 * get an overflow; waiters can poll again if it's not them.
1646 if (errs & (ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr))) {
1647 qib_handle_urcv(dd, ~0U);
1648 if (errs & ERR_MASK(RcvEgrFullErr))
1649 qib_stats.sps_buffull++;
1650 else
1651 qib_stats.sps_hdrfull++;
1654 done:
1655 return;
1658 static void qib_error_tasklet(unsigned long data)
1660 struct qib_devdata *dd = (struct qib_devdata *)data;
1662 handle_7322_errors(dd);
1663 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
1666 static void reenable_chase(unsigned long opaque)
1668 struct qib_pportdata *ppd = (struct qib_pportdata *)opaque;
1670 ppd->cpspec->chase_timer.expires = 0;
1671 qib_set_ib_7322_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
1672 QLOGIC_IB_IBCC_LINKINITCMD_POLL);
1675 static void disable_chase(struct qib_pportdata *ppd, u64 tnow, u8 ibclt)
1677 ppd->cpspec->chase_end = 0;
1679 if (!qib_chase)
1680 return;
1682 qib_set_ib_7322_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
1683 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
1684 ppd->cpspec->chase_timer.expires = jiffies + QIB_CHASE_DIS_TIME;
1685 add_timer(&ppd->cpspec->chase_timer);
1688 static void handle_serdes_issues(struct qib_pportdata *ppd, u64 ibcst)
1690 u8 ibclt;
1691 u64 tnow;
1693 ibclt = (u8)SYM_FIELD(ibcst, IBCStatusA_0, LinkTrainingState);
1696 * Detect and handle the state chase issue, where we can
1697 * get stuck if we are unlucky on timing on both sides of
1698 * the link. If we are, we disable, set a timer, and
1699 * then re-enable.
1701 switch (ibclt) {
1702 case IB_7322_LT_STATE_CFGRCVFCFG:
1703 case IB_7322_LT_STATE_CFGWAITRMT:
1704 case IB_7322_LT_STATE_TXREVLANES:
1705 case IB_7322_LT_STATE_CFGENH:
1706 tnow = get_jiffies_64();
1707 if (ppd->cpspec->chase_end &&
1708 time_after64(tnow, ppd->cpspec->chase_end))
1709 disable_chase(ppd, tnow, ibclt);
1710 else if (!ppd->cpspec->chase_end)
1711 ppd->cpspec->chase_end = tnow + QIB_CHASE_TIME;
1712 break;
1713 default:
1714 ppd->cpspec->chase_end = 0;
1715 break;
1718 if (((ibclt >= IB_7322_LT_STATE_CFGTEST &&
1719 ibclt <= IB_7322_LT_STATE_CFGWAITENH) ||
1720 ibclt == IB_7322_LT_STATE_LINKUP) &&
1721 (ibcst & SYM_MASK(IBCStatusA_0, LinkSpeedQDR))) {
1722 force_h1(ppd);
1723 ppd->cpspec->qdr_reforce = 1;
1724 if (!ppd->dd->cspec->r1)
1725 serdes_7322_los_enable(ppd, 0);
1726 } else if (ppd->cpspec->qdr_reforce &&
1727 (ibcst & SYM_MASK(IBCStatusA_0, LinkSpeedQDR)) &&
1728 (ibclt == IB_7322_LT_STATE_CFGENH ||
1729 ibclt == IB_7322_LT_STATE_CFGIDLE ||
1730 ibclt == IB_7322_LT_STATE_LINKUP))
1731 force_h1(ppd);
1733 if ((IS_QMH(ppd->dd) || IS_QME(ppd->dd)) &&
1734 ppd->link_speed_enabled == QIB_IB_QDR &&
1735 (ibclt == IB_7322_LT_STATE_CFGTEST ||
1736 ibclt == IB_7322_LT_STATE_CFGENH ||
1737 (ibclt >= IB_7322_LT_STATE_POLLACTIVE &&
1738 ibclt <= IB_7322_LT_STATE_SLEEPQUIET)))
1739 adj_tx_serdes(ppd);
1741 if (ibclt != IB_7322_LT_STATE_LINKUP) {
1742 u8 ltstate = qib_7322_phys_portstate(ibcst);
1743 u8 pibclt = (u8)SYM_FIELD(ppd->lastibcstat, IBCStatusA_0,
1744 LinkTrainingState);
1745 if (!ppd->dd->cspec->r1 &&
1746 pibclt == IB_7322_LT_STATE_LINKUP &&
1747 ltstate != IB_PHYSPORTSTATE_LINK_ERR_RECOVER &&
1748 ltstate != IB_PHYSPORTSTATE_RECOVERY_RETRAIN &&
1749 ltstate != IB_PHYSPORTSTATE_RECOVERY_WAITRMT &&
1750 ltstate != IB_PHYSPORTSTATE_RECOVERY_IDLE)
1751 /* If the link went down (but no into recovery,
1752 * turn LOS back on */
1753 serdes_7322_los_enable(ppd, 1);
1754 if (!ppd->cpspec->qdr_dfe_on &&
1755 ibclt <= IB_7322_LT_STATE_SLEEPQUIET) {
1756 ppd->cpspec->qdr_dfe_on = 1;
1757 ppd->cpspec->qdr_dfe_time = 0;
1758 /* On link down, reenable QDR adaptation */
1759 qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
1760 ppd->dd->cspec->r1 ?
1761 QDR_STATIC_ADAPT_DOWN_R1 :
1762 QDR_STATIC_ADAPT_DOWN);
1763 printk(KERN_INFO QIB_DRV_NAME
1764 " IB%u:%u re-enabled QDR adaptation "
1765 "ibclt %x\n", ppd->dd->unit, ppd->port, ibclt);
1770 static int qib_7322_set_ib_cfg(struct qib_pportdata *, int, u32);
1773 * This is per-pport error handling.
1774 * will likely get it's own MSIx interrupt (one for each port,
1775 * although just a single handler).
1777 static noinline void handle_7322_p_errors(struct qib_pportdata *ppd)
1779 char *msg;
1780 u64 ignore_this_time = 0, iserr = 0, errs, fmask;
1781 struct qib_devdata *dd = ppd->dd;
1783 /* do this as soon as possible */
1784 fmask = qib_read_kreg64(dd, kr_act_fmask);
1785 if (!fmask)
1786 check_7322_rxe_status(ppd);
1788 errs = qib_read_kreg_port(ppd, krp_errstatus);
1789 if (!errs)
1790 qib_devinfo(dd->pcidev,
1791 "Port%d error interrupt, but no error bits set!\n",
1792 ppd->port);
1793 if (!fmask)
1794 errs &= ~QIB_E_P_IBSTATUSCHANGED;
1795 if (!errs)
1796 goto done;
1798 msg = ppd->cpspec->epmsgbuf;
1799 *msg = '\0';
1801 if (errs & ~QIB_E_P_BITSEXTANT) {
1802 err_decode(msg, sizeof ppd->cpspec->epmsgbuf,
1803 errs & ~QIB_E_P_BITSEXTANT, qib_7322p_error_msgs);
1804 if (!*msg)
1805 snprintf(msg, sizeof ppd->cpspec->epmsgbuf,
1806 "no others");
1807 qib_dev_porterr(dd, ppd->port, "error interrupt with unknown"
1808 " errors 0x%016Lx set (and %s)\n",
1809 (errs & ~QIB_E_P_BITSEXTANT), msg);
1810 *msg = '\0';
1813 if (errs & QIB_E_P_SHDR) {
1814 u64 symptom;
1816 /* determine cause, then write to clear */
1817 symptom = qib_read_kreg_port(ppd, krp_sendhdrsymptom);
1818 qib_write_kreg_port(ppd, krp_sendhdrsymptom, 0);
1819 err_decode(msg, sizeof ppd->cpspec->epmsgbuf, symptom,
1820 hdrchk_msgs);
1821 *msg = '\0';
1822 /* senderrbuf cleared in SPKTERRS below */
1825 if (errs & QIB_E_P_SPKTERRS) {
1826 if ((errs & QIB_E_P_LINK_PKTERRS) &&
1827 !(ppd->lflags & QIBL_LINKACTIVE)) {
1829 * This can happen when trying to bring the link
1830 * up, but the IB link changes state at the "wrong"
1831 * time. The IB logic then complains that the packet
1832 * isn't valid. We don't want to confuse people, so
1833 * we just don't print them, except at debug
1835 err_decode(msg, sizeof ppd->cpspec->epmsgbuf,
1836 (errs & QIB_E_P_LINK_PKTERRS),
1837 qib_7322p_error_msgs);
1838 *msg = '\0';
1839 ignore_this_time = errs & QIB_E_P_LINK_PKTERRS;
1841 qib_disarm_7322_senderrbufs(ppd);
1842 } else if ((errs & QIB_E_P_LINK_PKTERRS) &&
1843 !(ppd->lflags & QIBL_LINKACTIVE)) {
1845 * This can happen when SMA is trying to bring the link
1846 * up, but the IB link changes state at the "wrong" time.
1847 * The IB logic then complains that the packet isn't
1848 * valid. We don't want to confuse people, so we just
1849 * don't print them, except at debug
1851 err_decode(msg, sizeof ppd->cpspec->epmsgbuf, errs,
1852 qib_7322p_error_msgs);
1853 ignore_this_time = errs & QIB_E_P_LINK_PKTERRS;
1854 *msg = '\0';
1857 qib_write_kreg_port(ppd, krp_errclear, errs);
1859 errs &= ~ignore_this_time;
1860 if (!errs)
1861 goto done;
1863 if (errs & QIB_E_P_RPKTERRS)
1864 qib_stats.sps_rcverrs++;
1865 if (errs & QIB_E_P_SPKTERRS)
1866 qib_stats.sps_txerrs++;
1868 iserr = errs & ~(QIB_E_P_RPKTERRS | QIB_E_P_PKTERRS);
1870 if (errs & QIB_E_P_SDMAERRS)
1871 sdma_7322_p_errors(ppd, errs);
1873 if (errs & QIB_E_P_IBSTATUSCHANGED) {
1874 u64 ibcs;
1875 u8 ltstate;
1877 ibcs = qib_read_kreg_port(ppd, krp_ibcstatus_a);
1878 ltstate = qib_7322_phys_portstate(ibcs);
1880 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
1881 handle_serdes_issues(ppd, ibcs);
1882 if (!(ppd->cpspec->ibcctrl_a &
1883 SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn))) {
1885 * We got our interrupt, so init code should be
1886 * happy and not try alternatives. Now squelch
1887 * other "chatter" from link-negotiation (pre Init)
1889 ppd->cpspec->ibcctrl_a |=
1890 SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
1891 qib_write_kreg_port(ppd, krp_ibcctrl_a,
1892 ppd->cpspec->ibcctrl_a);
1895 /* Update our picture of width and speed from chip */
1896 ppd->link_width_active =
1897 (ibcs & SYM_MASK(IBCStatusA_0, LinkWidthActive)) ?
1898 IB_WIDTH_4X : IB_WIDTH_1X;
1899 ppd->link_speed_active = (ibcs & SYM_MASK(IBCStatusA_0,
1900 LinkSpeedQDR)) ? QIB_IB_QDR : (ibcs &
1901 SYM_MASK(IBCStatusA_0, LinkSpeedActive)) ?
1902 QIB_IB_DDR : QIB_IB_SDR;
1904 if ((ppd->lflags & QIBL_IB_LINK_DISABLED) && ltstate !=
1905 IB_PHYSPORTSTATE_DISABLED)
1906 qib_set_ib_7322_lstate(ppd, 0,
1907 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
1908 else
1910 * Since going into a recovery state causes the link
1911 * state to go down and since recovery is transitory,
1912 * it is better if we "miss" ever seeing the link
1913 * training state go into recovery (i.e., ignore this
1914 * transition for link state special handling purposes)
1915 * without updating lastibcstat.
1917 if (ltstate != IB_PHYSPORTSTATE_LINK_ERR_RECOVER &&
1918 ltstate != IB_PHYSPORTSTATE_RECOVERY_RETRAIN &&
1919 ltstate != IB_PHYSPORTSTATE_RECOVERY_WAITRMT &&
1920 ltstate != IB_PHYSPORTSTATE_RECOVERY_IDLE)
1921 qib_handle_e_ibstatuschanged(ppd, ibcs);
1923 if (*msg && iserr)
1924 qib_dev_porterr(dd, ppd->port, "%s error\n", msg);
1926 if (ppd->state_wanted & ppd->lflags)
1927 wake_up_interruptible(&ppd->state_wait);
1928 done:
1929 return;
1932 /* enable/disable chip from delivering interrupts */
1933 static void qib_7322_set_intr_state(struct qib_devdata *dd, u32 enable)
1935 if (enable) {
1936 if (dd->flags & QIB_BADINTR)
1937 return;
1938 qib_write_kreg(dd, kr_intmask, dd->cspec->int_enable_mask);
1939 /* cause any pending enabled interrupts to be re-delivered */
1940 qib_write_kreg(dd, kr_intclear, 0ULL);
1941 if (dd->cspec->num_msix_entries) {
1942 /* and same for MSIx */
1943 u64 val = qib_read_kreg64(dd, kr_intgranted);
1944 if (val)
1945 qib_write_kreg(dd, kr_intgranted, val);
1947 } else
1948 qib_write_kreg(dd, kr_intmask, 0ULL);
1952 * Try to cleanup as much as possible for anything that might have gone
1953 * wrong while in freeze mode, such as pio buffers being written by user
1954 * processes (causing armlaunch), send errors due to going into freeze mode,
1955 * etc., and try to avoid causing extra interrupts while doing so.
1956 * Forcibly update the in-memory pioavail register copies after cleanup
1957 * because the chip won't do it while in freeze mode (the register values
1958 * themselves are kept correct).
1959 * Make sure that we don't lose any important interrupts by using the chip
1960 * feature that says that writing 0 to a bit in *clear that is set in
1961 * *status will cause an interrupt to be generated again (if allowed by
1962 * the *mask value).
1963 * This is in chip-specific code because of all of the register accesses,
1964 * even though the details are similar on most chips.
1966 static void qib_7322_clear_freeze(struct qib_devdata *dd)
1968 int pidx;
1970 /* disable error interrupts, to avoid confusion */
1971 qib_write_kreg(dd, kr_errmask, 0ULL);
1973 for (pidx = 0; pidx < dd->num_pports; ++pidx)
1974 if (dd->pport[pidx].link_speed_supported)
1975 qib_write_kreg_port(dd->pport + pidx, krp_errmask,
1976 0ULL);
1978 /* also disable interrupts; errormask is sometimes overwriten */
1979 qib_7322_set_intr_state(dd, 0);
1981 /* clear the freeze, and be sure chip saw it */
1982 qib_write_kreg(dd, kr_control, dd->control);
1983 qib_read_kreg32(dd, kr_scratch);
1986 * Force new interrupt if any hwerr, error or interrupt bits are
1987 * still set, and clear "safe" send packet errors related to freeze
1988 * and cancelling sends. Re-enable error interrupts before possible
1989 * force of re-interrupt on pending interrupts.
1991 qib_write_kreg(dd, kr_hwerrclear, 0ULL);
1992 qib_write_kreg(dd, kr_errclear, E_SPKT_ERRS_IGNORE);
1993 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
1994 /* We need to purge per-port errs and reset mask, too */
1995 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
1996 if (!dd->pport[pidx].link_speed_supported)
1997 continue;
1998 qib_write_kreg_port(dd->pport + pidx, krp_errclear, ~0Ull);
1999 qib_write_kreg_port(dd->pport + pidx, krp_errmask, ~0Ull);
2001 qib_7322_set_intr_state(dd, 1);
2004 /* no error handling to speak of */
2006 * qib_7322_handle_hwerrors - display hardware errors.
2007 * @dd: the qlogic_ib device
2008 * @msg: the output buffer
2009 * @msgl: the size of the output buffer
2011 * Use same msg buffer as regular errors to avoid excessive stack
2012 * use. Most hardware errors are catastrophic, but for right now,
2013 * we'll print them and continue. We reuse the same message buffer as
2014 * qib_handle_errors() to avoid excessive stack usage.
2016 static void qib_7322_handle_hwerrors(struct qib_devdata *dd, char *msg,
2017 size_t msgl)
2019 u64 hwerrs;
2020 u32 ctrl;
2021 int isfatal = 0;
2023 hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
2024 if (!hwerrs)
2025 goto bail;
2026 if (hwerrs == ~0ULL) {
2027 qib_dev_err(dd, "Read of hardware error status failed "
2028 "(all bits set); ignoring\n");
2029 goto bail;
2031 qib_stats.sps_hwerrs++;
2033 /* Always clear the error status register, except BIST fail */
2034 qib_write_kreg(dd, kr_hwerrclear, hwerrs &
2035 ~HWE_MASK(PowerOnBISTFailed));
2037 hwerrs &= dd->cspec->hwerrmask;
2039 /* no EEPROM logging, yet */
2041 if (hwerrs)
2042 qib_devinfo(dd->pcidev, "Hardware error: hwerr=0x%llx "
2043 "(cleared)\n", (unsigned long long) hwerrs);
2045 ctrl = qib_read_kreg32(dd, kr_control);
2046 if ((ctrl & SYM_MASK(Control, FreezeMode)) && !dd->diag_client) {
2048 * No recovery yet...
2050 if ((hwerrs & ~HWE_MASK(LATriggered)) ||
2051 dd->cspec->stay_in_freeze) {
2053 * If any set that we aren't ignoring only make the
2054 * complaint once, in case it's stuck or recurring,
2055 * and we get here multiple times
2056 * Force link down, so switch knows, and
2057 * LEDs are turned off.
2059 if (dd->flags & QIB_INITTED)
2060 isfatal = 1;
2061 } else
2062 qib_7322_clear_freeze(dd);
2065 if (hwerrs & HWE_MASK(PowerOnBISTFailed)) {
2066 isfatal = 1;
2067 strlcpy(msg, "[Memory BIST test failed, "
2068 "InfiniPath hardware unusable]", msgl);
2069 /* ignore from now on, so disable until driver reloaded */
2070 dd->cspec->hwerrmask &= ~HWE_MASK(PowerOnBISTFailed);
2071 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
2074 err_decode(msg, msgl, hwerrs, qib_7322_hwerror_msgs);
2076 /* Ignore esoteric PLL failures et al. */
2078 qib_dev_err(dd, "%s hardware error\n", msg);
2080 if (isfatal && !dd->diag_client) {
2081 qib_dev_err(dd, "Fatal Hardware Error, no longer"
2082 " usable, SN %.16s\n", dd->serial);
2084 * for /sys status file and user programs to print; if no
2085 * trailing brace is copied, we'll know it was truncated.
2087 if (dd->freezemsg)
2088 snprintf(dd->freezemsg, dd->freezelen,
2089 "{%s}", msg);
2090 qib_disable_after_error(dd);
2092 bail:;
2096 * qib_7322_init_hwerrors - enable hardware errors
2097 * @dd: the qlogic_ib device
2099 * now that we have finished initializing everything that might reasonably
2100 * cause a hardware error, and cleared those errors bits as they occur,
2101 * we can enable hardware errors in the mask (potentially enabling
2102 * freeze mode), and enable hardware errors as errors (along with
2103 * everything else) in errormask
2105 static void qib_7322_init_hwerrors(struct qib_devdata *dd)
2107 int pidx;
2108 u64 extsval;
2110 extsval = qib_read_kreg64(dd, kr_extstatus);
2111 if (!(extsval & (QIB_EXTS_MEMBIST_DISABLED |
2112 QIB_EXTS_MEMBIST_ENDTEST)))
2113 qib_dev_err(dd, "MemBIST did not complete!\n");
2115 /* never clear BIST failure, so reported on each driver load */
2116 qib_write_kreg(dd, kr_hwerrclear, ~HWE_MASK(PowerOnBISTFailed));
2117 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
2119 /* clear all */
2120 qib_write_kreg(dd, kr_errclear, ~0ULL);
2121 /* enable errors that are masked, at least this first time. */
2122 qib_write_kreg(dd, kr_errmask, ~0ULL);
2123 dd->cspec->errormask = qib_read_kreg64(dd, kr_errmask);
2124 for (pidx = 0; pidx < dd->num_pports; ++pidx)
2125 if (dd->pport[pidx].link_speed_supported)
2126 qib_write_kreg_port(dd->pport + pidx, krp_errmask,
2127 ~0ULL);
2131 * Disable and enable the armlaunch error. Used for PIO bandwidth testing
2132 * on chips that are count-based, rather than trigger-based. There is no
2133 * reference counting, but that's also fine, given the intended use.
2134 * Only chip-specific because it's all register accesses
2136 static void qib_set_7322_armlaunch(struct qib_devdata *dd, u32 enable)
2138 if (enable) {
2139 qib_write_kreg(dd, kr_errclear, QIB_E_SPIOARMLAUNCH);
2140 dd->cspec->errormask |= QIB_E_SPIOARMLAUNCH;
2141 } else
2142 dd->cspec->errormask &= ~QIB_E_SPIOARMLAUNCH;
2143 qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
2147 * Formerly took parameter <which> in pre-shifted,
2148 * pre-merged form with LinkCmd and LinkInitCmd
2149 * together, and assuming the zero was NOP.
2151 static void qib_set_ib_7322_lstate(struct qib_pportdata *ppd, u16 linkcmd,
2152 u16 linitcmd)
2154 u64 mod_wd;
2155 struct qib_devdata *dd = ppd->dd;
2156 unsigned long flags;
2158 if (linitcmd == QLOGIC_IB_IBCC_LINKINITCMD_DISABLE) {
2160 * If we are told to disable, note that so link-recovery
2161 * code does not attempt to bring us back up.
2162 * Also reset everything that we can, so we start
2163 * completely clean when re-enabled (before we
2164 * actually issue the disable to the IBC)
2166 qib_7322_mini_pcs_reset(ppd);
2167 spin_lock_irqsave(&ppd->lflags_lock, flags);
2168 ppd->lflags |= QIBL_IB_LINK_DISABLED;
2169 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
2170 } else if (linitcmd || linkcmd == QLOGIC_IB_IBCC_LINKCMD_DOWN) {
2172 * Any other linkinitcmd will lead to LINKDOWN and then
2173 * to INIT (if all is well), so clear flag to let
2174 * link-recovery code attempt to bring us back up.
2176 spin_lock_irqsave(&ppd->lflags_lock, flags);
2177 ppd->lflags &= ~QIBL_IB_LINK_DISABLED;
2178 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
2180 * Clear status change interrupt reduction so the
2181 * new state is seen.
2183 ppd->cpspec->ibcctrl_a &=
2184 ~SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
2187 mod_wd = (linkcmd << IBA7322_IBCC_LINKCMD_SHIFT) |
2188 (linitcmd << QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
2190 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a |
2191 mod_wd);
2192 /* write to chip to prevent back-to-back writes of ibc reg */
2193 qib_write_kreg(dd, kr_scratch, 0);
2198 * The total RCV buffer memory is 64KB, used for both ports, and is
2199 * in units of 64 bytes (same as IB flow control credit unit).
2200 * The consumedVL unit in the same registers are in 32 byte units!
2201 * So, a VL15 packet needs 4.50 IB credits, and 9 rx buffer chunks,
2202 * and we can therefore allocate just 9 IB credits for 2 VL15 packets
2203 * in krp_rxcreditvl15, rather than 10.
2205 #define RCV_BUF_UNITSZ 64
2206 #define NUM_RCV_BUF_UNITS(dd) ((64 * 1024) / (RCV_BUF_UNITSZ * dd->num_pports))
2208 static void set_vls(struct qib_pportdata *ppd)
2210 int i, numvls, totcred, cred_vl, vl0extra;
2211 struct qib_devdata *dd = ppd->dd;
2212 u64 val;
2214 numvls = qib_num_vls(ppd->vls_operational);
2217 * Set up per-VL credits. Below is kluge based on these assumptions:
2218 * 1) port is disabled at the time early_init is called.
2219 * 2) give VL15 17 credits, for two max-plausible packets.
2220 * 3) Give VL0-N the rest, with any rounding excess used for VL0
2222 /* 2 VL15 packets @ 288 bytes each (including IB headers) */
2223 totcred = NUM_RCV_BUF_UNITS(dd);
2224 cred_vl = (2 * 288 + RCV_BUF_UNITSZ - 1) / RCV_BUF_UNITSZ;
2225 totcred -= cred_vl;
2226 qib_write_kreg_port(ppd, krp_rxcreditvl15, (u64) cred_vl);
2227 cred_vl = totcred / numvls;
2228 vl0extra = totcred - cred_vl * numvls;
2229 qib_write_kreg_port(ppd, krp_rxcreditvl0, cred_vl + vl0extra);
2230 for (i = 1; i < numvls; i++)
2231 qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, cred_vl);
2232 for (; i < 8; i++) /* no buffer space for other VLs */
2233 qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, 0);
2235 /* Notify IBC that credits need to be recalculated */
2236 val = qib_read_kreg_port(ppd, krp_ibsdtestiftx);
2237 val |= SYM_MASK(IB_SDTEST_IF_TX_0, CREDIT_CHANGE);
2238 qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
2239 qib_write_kreg(dd, kr_scratch, 0ULL);
2240 val &= ~SYM_MASK(IB_SDTEST_IF_TX_0, CREDIT_CHANGE);
2241 qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
2243 for (i = 0; i < numvls; i++)
2244 val = qib_read_kreg_port(ppd, krp_rxcreditvl0 + i);
2245 val = qib_read_kreg_port(ppd, krp_rxcreditvl15);
2247 /* Change the number of operational VLs */
2248 ppd->cpspec->ibcctrl_a = (ppd->cpspec->ibcctrl_a &
2249 ~SYM_MASK(IBCCtrlA_0, NumVLane)) |
2250 ((u64)(numvls - 1) << SYM_LSB(IBCCtrlA_0, NumVLane));
2251 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
2252 qib_write_kreg(dd, kr_scratch, 0ULL);
2256 * The code that deals with actual SerDes is in serdes_7322_init().
2257 * Compared to the code for iba7220, it is minimal.
2259 static int serdes_7322_init(struct qib_pportdata *ppd);
2262 * qib_7322_bringup_serdes - bring up the serdes
2263 * @ppd: physical port on the qlogic_ib device
2265 static int qib_7322_bringup_serdes(struct qib_pportdata *ppd)
2267 struct qib_devdata *dd = ppd->dd;
2268 u64 val, guid, ibc;
2269 unsigned long flags;
2270 int ret = 0;
2273 * SerDes model not in Pd, but still need to
2274 * set up much of IBCCtrl and IBCDDRCtrl; move elsewhere
2275 * eventually.
2277 /* Put IBC in reset, sends disabled (should be in reset already) */
2278 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, IBLinkEn);
2279 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
2280 qib_write_kreg(dd, kr_scratch, 0ULL);
2282 if (qib_compat_ddr_negotiate) {
2283 ppd->cpspec->ibdeltainprog = 1;
2284 ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
2285 crp_ibsymbolerr);
2286 ppd->cpspec->iblnkerrsnap = read_7322_creg32_port(ppd,
2287 crp_iblinkerrrecov);
2290 /* flowcontrolwatermark is in units of KBytes */
2291 ibc = 0x5ULL << SYM_LSB(IBCCtrlA_0, FlowCtrlWaterMark);
2293 * Flow control is sent this often, even if no changes in
2294 * buffer space occur. Units are 128ns for this chip.
2295 * Set to 3usec.
2297 ibc |= 24ULL << SYM_LSB(IBCCtrlA_0, FlowCtrlPeriod);
2298 /* max error tolerance */
2299 ibc |= 0xfULL << SYM_LSB(IBCCtrlA_0, PhyerrThreshold);
2300 /* IB credit flow control. */
2301 ibc |= 0xfULL << SYM_LSB(IBCCtrlA_0, OverrunThreshold);
2303 * set initial max size pkt IBC will send, including ICRC; it's the
2304 * PIO buffer size in dwords, less 1; also see qib_set_mtu()
2306 ibc |= ((u64)(ppd->ibmaxlen >> 2) + 1) <<
2307 SYM_LSB(IBCCtrlA_0, MaxPktLen);
2308 ppd->cpspec->ibcctrl_a = ibc; /* without linkcmd or linkinitcmd! */
2310 /* initially come up waiting for TS1, without sending anything. */
2311 val = ppd->cpspec->ibcctrl_a | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
2312 QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
2315 * Reset the PCS interface to the serdes (and also ibc, which is still
2316 * in reset from above). Writes new value of ibcctrl_a as last step.
2318 qib_7322_mini_pcs_reset(ppd);
2319 qib_write_kreg(dd, kr_scratch, 0ULL);
2321 if (!ppd->cpspec->ibcctrl_b) {
2322 unsigned lse = ppd->link_speed_enabled;
2325 * Not on re-init after reset, establish shadow
2326 * and force initial config.
2328 ppd->cpspec->ibcctrl_b = qib_read_kreg_port(ppd,
2329 krp_ibcctrl_b);
2330 ppd->cpspec->ibcctrl_b &= ~(IBA7322_IBC_SPEED_QDR |
2331 IBA7322_IBC_SPEED_DDR |
2332 IBA7322_IBC_SPEED_SDR |
2333 IBA7322_IBC_WIDTH_AUTONEG |
2334 SYM_MASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED));
2335 if (lse & (lse - 1)) /* Muliple speeds enabled */
2336 ppd->cpspec->ibcctrl_b |=
2337 (lse << IBA7322_IBC_SPEED_LSB) |
2338 IBA7322_IBC_IBTA_1_2_MASK |
2339 IBA7322_IBC_MAX_SPEED_MASK;
2340 else
2341 ppd->cpspec->ibcctrl_b |= (lse == QIB_IB_QDR) ?
2342 IBA7322_IBC_SPEED_QDR |
2343 IBA7322_IBC_IBTA_1_2_MASK :
2344 (lse == QIB_IB_DDR) ?
2345 IBA7322_IBC_SPEED_DDR :
2346 IBA7322_IBC_SPEED_SDR;
2347 if ((ppd->link_width_enabled & (IB_WIDTH_1X | IB_WIDTH_4X)) ==
2348 (IB_WIDTH_1X | IB_WIDTH_4X))
2349 ppd->cpspec->ibcctrl_b |= IBA7322_IBC_WIDTH_AUTONEG;
2350 else
2351 ppd->cpspec->ibcctrl_b |=
2352 ppd->link_width_enabled == IB_WIDTH_4X ?
2353 IBA7322_IBC_WIDTH_4X_ONLY :
2354 IBA7322_IBC_WIDTH_1X_ONLY;
2356 /* always enable these on driver reload, not sticky */
2357 ppd->cpspec->ibcctrl_b |= (IBA7322_IBC_RXPOL_MASK |
2358 IBA7322_IBC_HRTBT_MASK);
2360 qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
2362 /* setup so we have more time at CFGTEST to change H1 */
2363 val = qib_read_kreg_port(ppd, krp_ibcctrl_c);
2364 val &= ~SYM_MASK(IBCCtrlC_0, IB_FRONT_PORCH);
2365 val |= 0xfULL << SYM_LSB(IBCCtrlC_0, IB_FRONT_PORCH);
2366 qib_write_kreg_port(ppd, krp_ibcctrl_c, val);
2368 serdes_7322_init(ppd);
2370 guid = be64_to_cpu(ppd->guid);
2371 if (!guid) {
2372 if (dd->base_guid)
2373 guid = be64_to_cpu(dd->base_guid) + ppd->port - 1;
2374 ppd->guid = cpu_to_be64(guid);
2377 qib_write_kreg_port(ppd, krp_hrtbt_guid, guid);
2378 /* write to chip to prevent back-to-back writes of ibc reg */
2379 qib_write_kreg(dd, kr_scratch, 0);
2381 /* Enable port */
2382 ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0, IBLinkEn);
2383 set_vls(ppd);
2385 /* be paranoid against later code motion, etc. */
2386 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
2387 ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvIBPortEnable);
2388 qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
2389 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
2391 /* Hold the link state machine for mezz boards */
2392 if (IS_QMH(dd) || IS_QME(dd))
2393 qib_set_ib_7322_lstate(ppd, 0,
2394 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
2396 /* Also enable IBSTATUSCHG interrupt. */
2397 val = qib_read_kreg_port(ppd, krp_errmask);
2398 qib_write_kreg_port(ppd, krp_errmask,
2399 val | ERR_MASK_N(IBStatusChanged));
2401 /* Always zero until we start messing with SerDes for real */
2402 return ret;
2406 * qib_7322_quiet_serdes - set serdes to txidle
2407 * @dd: the qlogic_ib device
2408 * Called when driver is being unloaded
2410 static void qib_7322_mini_quiet_serdes(struct qib_pportdata *ppd)
2412 u64 val;
2413 unsigned long flags;
2415 qib_set_ib_7322_lstate(ppd, 0, QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
2417 spin_lock_irqsave(&ppd->lflags_lock, flags);
2418 ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
2419 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
2420 wake_up(&ppd->cpspec->autoneg_wait);
2421 cancel_delayed_work_sync(&ppd->cpspec->autoneg_work);
2422 if (ppd->dd->cspec->r1)
2423 cancel_delayed_work_sync(&ppd->cpspec->ipg_work);
2425 ppd->cpspec->chase_end = 0;
2426 if (ppd->cpspec->chase_timer.data) /* if initted */
2427 del_timer_sync(&ppd->cpspec->chase_timer);
2430 * Despite the name, actually disables IBC as well. Do it when
2431 * we are as sure as possible that no more packets can be
2432 * received, following the down and the PCS reset.
2433 * The actual disabling happens in qib_7322_mini_pci_reset(),
2434 * along with the PCS being reset.
2436 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, IBLinkEn);
2437 qib_7322_mini_pcs_reset(ppd);
2440 * Update the adjusted counters so the adjustment persists
2441 * across driver reload.
2443 if (ppd->cpspec->ibsymdelta || ppd->cpspec->iblnkerrdelta ||
2444 ppd->cpspec->ibdeltainprog || ppd->cpspec->iblnkdowndelta) {
2445 struct qib_devdata *dd = ppd->dd;
2446 u64 diagc;
2448 /* enable counter writes */
2449 diagc = qib_read_kreg64(dd, kr_hwdiagctrl);
2450 qib_write_kreg(dd, kr_hwdiagctrl,
2451 diagc | SYM_MASK(HwDiagCtrl, CounterWrEnable));
2453 if (ppd->cpspec->ibsymdelta || ppd->cpspec->ibdeltainprog) {
2454 val = read_7322_creg32_port(ppd, crp_ibsymbolerr);
2455 if (ppd->cpspec->ibdeltainprog)
2456 val -= val - ppd->cpspec->ibsymsnap;
2457 val -= ppd->cpspec->ibsymdelta;
2458 write_7322_creg_port(ppd, crp_ibsymbolerr, val);
2460 if (ppd->cpspec->iblnkerrdelta || ppd->cpspec->ibdeltainprog) {
2461 val = read_7322_creg32_port(ppd, crp_iblinkerrrecov);
2462 if (ppd->cpspec->ibdeltainprog)
2463 val -= val - ppd->cpspec->iblnkerrsnap;
2464 val -= ppd->cpspec->iblnkerrdelta;
2465 write_7322_creg_port(ppd, crp_iblinkerrrecov, val);
2467 if (ppd->cpspec->iblnkdowndelta) {
2468 val = read_7322_creg32_port(ppd, crp_iblinkdown);
2469 val += ppd->cpspec->iblnkdowndelta;
2470 write_7322_creg_port(ppd, crp_iblinkdown, val);
2473 * No need to save ibmalfdelta since IB perfcounters
2474 * are cleared on driver reload.
2477 /* and disable counter writes */
2478 qib_write_kreg(dd, kr_hwdiagctrl, diagc);
2483 * qib_setup_7322_setextled - set the state of the two external LEDs
2484 * @ppd: physical port on the qlogic_ib device
2485 * @on: whether the link is up or not
2487 * The exact combo of LEDs if on is true is determined by looking
2488 * at the ibcstatus.
2490 * These LEDs indicate the physical and logical state of IB link.
2491 * For this chip (at least with recommended board pinouts), LED1
2492 * is Yellow (logical state) and LED2 is Green (physical state),
2494 * Note: We try to match the Mellanox HCA LED behavior as best
2495 * we can. Green indicates physical link state is OK (something is
2496 * plugged in, and we can train).
2497 * Amber indicates the link is logically up (ACTIVE).
2498 * Mellanox further blinks the amber LED to indicate data packet
2499 * activity, but we have no hardware support for that, so it would
2500 * require waking up every 10-20 msecs and checking the counters
2501 * on the chip, and then turning the LED off if appropriate. That's
2502 * visible overhead, so not something we will do.
2504 static void qib_setup_7322_setextled(struct qib_pportdata *ppd, u32 on)
2506 struct qib_devdata *dd = ppd->dd;
2507 u64 extctl, ledblink = 0, val;
2508 unsigned long flags;
2509 int yel, grn;
2512 * The diags use the LED to indicate diag info, so we leave
2513 * the external LED alone when the diags are running.
2515 if (dd->diag_client)
2516 return;
2518 /* Allow override of LED display for, e.g. Locating system in rack */
2519 if (ppd->led_override) {
2520 grn = (ppd->led_override & QIB_LED_PHYS);
2521 yel = (ppd->led_override & QIB_LED_LOG);
2522 } else if (on) {
2523 val = qib_read_kreg_port(ppd, krp_ibcstatus_a);
2524 grn = qib_7322_phys_portstate(val) ==
2525 IB_PHYSPORTSTATE_LINKUP;
2526 yel = qib_7322_iblink_state(val) == IB_PORT_ACTIVE;
2527 } else {
2528 grn = 0;
2529 yel = 0;
2532 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
2533 extctl = dd->cspec->extctrl & (ppd->port == 1 ?
2534 ~ExtLED_IB1_MASK : ~ExtLED_IB2_MASK);
2535 if (grn) {
2536 extctl |= ppd->port == 1 ? ExtLED_IB1_GRN : ExtLED_IB2_GRN;
2538 * Counts are in chip clock (4ns) periods.
2539 * This is 1/16 sec (66.6ms) on,
2540 * 3/16 sec (187.5 ms) off, with packets rcvd.
2542 ledblink = ((66600 * 1000UL / 4) << IBA7322_LEDBLINK_ON_SHIFT) |
2543 ((187500 * 1000UL / 4) << IBA7322_LEDBLINK_OFF_SHIFT);
2545 if (yel)
2546 extctl |= ppd->port == 1 ? ExtLED_IB1_YEL : ExtLED_IB2_YEL;
2547 dd->cspec->extctrl = extctl;
2548 qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
2549 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
2551 if (ledblink) /* blink the LED on packet receive */
2552 qib_write_kreg_port(ppd, krp_rcvpktledcnt, ledblink);
2556 * Disable MSIx interrupt if enabled, call generic MSIx code
2557 * to cleanup, and clear pending MSIx interrupts.
2558 * Used for fallback to INTx, after reset, and when MSIx setup fails.
2560 static void qib_7322_nomsix(struct qib_devdata *dd)
2562 u64 intgranted;
2563 int n;
2565 dd->cspec->main_int_mask = ~0ULL;
2566 n = dd->cspec->num_msix_entries;
2567 if (n) {
2568 int i;
2570 dd->cspec->num_msix_entries = 0;
2571 for (i = 0; i < n; i++)
2572 free_irq(dd->cspec->msix_entries[i].vector,
2573 dd->cspec->msix_arg[i]);
2574 qib_nomsix(dd);
2576 /* make sure no MSIx interrupts are left pending */
2577 intgranted = qib_read_kreg64(dd, kr_intgranted);
2578 if (intgranted)
2579 qib_write_kreg(dd, kr_intgranted, intgranted);
2582 static void qib_7322_free_irq(struct qib_devdata *dd)
2584 if (dd->cspec->irq) {
2585 free_irq(dd->cspec->irq, dd);
2586 dd->cspec->irq = 0;
2588 qib_7322_nomsix(dd);
2591 static void qib_setup_7322_cleanup(struct qib_devdata *dd)
2593 int i;
2595 qib_7322_free_irq(dd);
2596 kfree(dd->cspec->cntrs);
2597 kfree(dd->cspec->sendchkenable);
2598 kfree(dd->cspec->sendgrhchk);
2599 kfree(dd->cspec->sendibchk);
2600 kfree(dd->cspec->msix_entries);
2601 kfree(dd->cspec->msix_arg);
2602 for (i = 0; i < dd->num_pports; i++) {
2603 unsigned long flags;
2604 u32 mask = QSFP_GPIO_MOD_PRS_N |
2605 (QSFP_GPIO_MOD_PRS_N << QSFP_GPIO_PORT2_SHIFT);
2607 kfree(dd->pport[i].cpspec->portcntrs);
2608 if (dd->flags & QIB_HAS_QSFP) {
2609 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
2610 dd->cspec->gpio_mask &= ~mask;
2611 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
2612 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
2613 qib_qsfp_deinit(&dd->pport[i].cpspec->qsfp_data);
2615 if (dd->pport[i].ibport_data.smi_ah)
2616 ib_destroy_ah(&dd->pport[i].ibport_data.smi_ah->ibah);
2620 /* handle SDMA interrupts */
2621 static void sdma_7322_intr(struct qib_devdata *dd, u64 istat)
2623 struct qib_pportdata *ppd0 = &dd->pport[0];
2624 struct qib_pportdata *ppd1 = &dd->pport[1];
2625 u64 intr0 = istat & (INT_MASK_P(SDma, 0) |
2626 INT_MASK_P(SDmaIdle, 0) | INT_MASK_P(SDmaProgress, 0));
2627 u64 intr1 = istat & (INT_MASK_P(SDma, 1) |
2628 INT_MASK_P(SDmaIdle, 1) | INT_MASK_P(SDmaProgress, 1));
2630 if (intr0)
2631 qib_sdma_intr(ppd0);
2632 if (intr1)
2633 qib_sdma_intr(ppd1);
2635 if (istat & INT_MASK_PM(SDmaCleanupDone, 0))
2636 qib_sdma_process_event(ppd0, qib_sdma_event_e20_hw_started);
2637 if (istat & INT_MASK_PM(SDmaCleanupDone, 1))
2638 qib_sdma_process_event(ppd1, qib_sdma_event_e20_hw_started);
2642 * Set or clear the Send buffer available interrupt enable bit.
2644 static void qib_wantpiobuf_7322_intr(struct qib_devdata *dd, u32 needint)
2646 unsigned long flags;
2648 spin_lock_irqsave(&dd->sendctrl_lock, flags);
2649 if (needint)
2650 dd->sendctrl |= SYM_MASK(SendCtrl, SendIntBufAvail);
2651 else
2652 dd->sendctrl &= ~SYM_MASK(SendCtrl, SendIntBufAvail);
2653 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
2654 qib_write_kreg(dd, kr_scratch, 0ULL);
2655 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
2659 * Somehow got an interrupt with reserved bits set in interrupt status.
2660 * Print a message so we know it happened, then clear them.
2661 * keep mainline interrupt handler cache-friendly
2663 static noinline void unknown_7322_ibits(struct qib_devdata *dd, u64 istat)
2665 u64 kills;
2666 char msg[128];
2668 kills = istat & ~QIB_I_BITSEXTANT;
2669 qib_dev_err(dd, "Clearing reserved interrupt(s) 0x%016llx:"
2670 " %s\n", (unsigned long long) kills, msg);
2671 qib_write_kreg(dd, kr_intmask, (dd->cspec->int_enable_mask & ~kills));
2674 /* keep mainline interrupt handler cache-friendly */
2675 static noinline void unknown_7322_gpio_intr(struct qib_devdata *dd)
2677 u32 gpiostatus;
2678 int handled = 0;
2679 int pidx;
2682 * Boards for this chip currently don't use GPIO interrupts,
2683 * so clear by writing GPIOstatus to GPIOclear, and complain
2684 * to developer. To avoid endless repeats, clear
2685 * the bits in the mask, since there is some kind of
2686 * programming error or chip problem.
2688 gpiostatus = qib_read_kreg32(dd, kr_gpio_status);
2690 * In theory, writing GPIOstatus to GPIOclear could
2691 * have a bad side-effect on some diagnostic that wanted
2692 * to poll for a status-change, but the various shadows
2693 * make that problematic at best. Diags will just suppress
2694 * all GPIO interrupts during such tests.
2696 qib_write_kreg(dd, kr_gpio_clear, gpiostatus);
2698 * Check for QSFP MOD_PRS changes
2699 * only works for single port if IB1 != pidx1
2701 for (pidx = 0; pidx < dd->num_pports && (dd->flags & QIB_HAS_QSFP);
2702 ++pidx) {
2703 struct qib_pportdata *ppd;
2704 struct qib_qsfp_data *qd;
2705 u32 mask;
2706 if (!dd->pport[pidx].link_speed_supported)
2707 continue;
2708 mask = QSFP_GPIO_MOD_PRS_N;
2709 ppd = dd->pport + pidx;
2710 mask <<= (QSFP_GPIO_PORT2_SHIFT * ppd->hw_pidx);
2711 if (gpiostatus & dd->cspec->gpio_mask & mask) {
2712 u64 pins;
2713 qd = &ppd->cpspec->qsfp_data;
2714 gpiostatus &= ~mask;
2715 pins = qib_read_kreg64(dd, kr_extstatus);
2716 pins >>= SYM_LSB(EXTStatus, GPIOIn);
2717 if (!(pins & mask)) {
2718 ++handled;
2719 qd->t_insert = get_jiffies_64();
2720 queue_work(ib_wq, &qd->work);
2725 if (gpiostatus && !handled) {
2726 const u32 mask = qib_read_kreg32(dd, kr_gpio_mask);
2727 u32 gpio_irq = mask & gpiostatus;
2730 * Clear any troublemakers, and update chip from shadow
2732 dd->cspec->gpio_mask &= ~gpio_irq;
2733 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
2738 * Handle errors and unusual events first, separate function
2739 * to improve cache hits for fast path interrupt handling.
2741 static noinline void unlikely_7322_intr(struct qib_devdata *dd, u64 istat)
2743 if (istat & ~QIB_I_BITSEXTANT)
2744 unknown_7322_ibits(dd, istat);
2745 if (istat & QIB_I_GPIO)
2746 unknown_7322_gpio_intr(dd);
2747 if (istat & QIB_I_C_ERROR) {
2748 qib_write_kreg(dd, kr_errmask, 0ULL);
2749 tasklet_schedule(&dd->error_tasklet);
2751 if (istat & INT_MASK_P(Err, 0) && dd->rcd[0])
2752 handle_7322_p_errors(dd->rcd[0]->ppd);
2753 if (istat & INT_MASK_P(Err, 1) && dd->rcd[1])
2754 handle_7322_p_errors(dd->rcd[1]->ppd);
2758 * Dynamically adjust the rcv int timeout for a context based on incoming
2759 * packet rate.
2761 static void adjust_rcv_timeout(struct qib_ctxtdata *rcd, int npkts)
2763 struct qib_devdata *dd = rcd->dd;
2764 u32 timeout = dd->cspec->rcvavail_timeout[rcd->ctxt];
2767 * Dynamically adjust idle timeout on chip
2768 * based on number of packets processed.
2770 if (npkts < rcv_int_count && timeout > 2)
2771 timeout >>= 1;
2772 else if (npkts >= rcv_int_count && timeout < rcv_int_timeout)
2773 timeout = min(timeout << 1, rcv_int_timeout);
2774 else
2775 return;
2777 dd->cspec->rcvavail_timeout[rcd->ctxt] = timeout;
2778 qib_write_kreg(dd, kr_rcvavailtimeout + rcd->ctxt, timeout);
2782 * This is the main interrupt handler.
2783 * It will normally only be used for low frequency interrupts but may
2784 * have to handle all interrupts if INTx is enabled or fewer than normal
2785 * MSIx interrupts were allocated.
2786 * This routine should ignore the interrupt bits for any of the
2787 * dedicated MSIx handlers.
2789 static irqreturn_t qib_7322intr(int irq, void *data)
2791 struct qib_devdata *dd = data;
2792 irqreturn_t ret;
2793 u64 istat;
2794 u64 ctxtrbits;
2795 u64 rmask;
2796 unsigned i;
2797 u32 npkts;
2799 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT) {
2801 * This return value is not great, but we do not want the
2802 * interrupt core code to remove our interrupt handler
2803 * because we don't appear to be handling an interrupt
2804 * during a chip reset.
2806 ret = IRQ_HANDLED;
2807 goto bail;
2810 istat = qib_read_kreg64(dd, kr_intstatus);
2812 if (unlikely(istat == ~0ULL)) {
2813 qib_bad_intrstatus(dd);
2814 qib_dev_err(dd, "Interrupt status all f's, skipping\n");
2815 /* don't know if it was our interrupt or not */
2816 ret = IRQ_NONE;
2817 goto bail;
2820 istat &= dd->cspec->main_int_mask;
2821 if (unlikely(!istat)) {
2822 /* already handled, or shared and not us */
2823 ret = IRQ_NONE;
2824 goto bail;
2827 qib_stats.sps_ints++;
2828 if (dd->int_counter != (u32) -1)
2829 dd->int_counter++;
2831 /* handle "errors" of various kinds first, device ahead of port */
2832 if (unlikely(istat & (~QIB_I_BITSEXTANT | QIB_I_GPIO |
2833 QIB_I_C_ERROR | INT_MASK_P(Err, 0) |
2834 INT_MASK_P(Err, 1))))
2835 unlikely_7322_intr(dd, istat);
2838 * Clear the interrupt bits we found set, relatively early, so we
2839 * "know" know the chip will have seen this by the time we process
2840 * the queue, and will re-interrupt if necessary. The processor
2841 * itself won't take the interrupt again until we return.
2843 qib_write_kreg(dd, kr_intclear, istat);
2846 * Handle kernel receive queues before checking for pio buffers
2847 * available since receives can overflow; piobuf waiters can afford
2848 * a few extra cycles, since they were waiting anyway.
2850 ctxtrbits = istat & (QIB_I_RCVAVAIL_MASK | QIB_I_RCVURG_MASK);
2851 if (ctxtrbits) {
2852 rmask = (1ULL << QIB_I_RCVAVAIL_LSB) |
2853 (1ULL << QIB_I_RCVURG_LSB);
2854 for (i = 0; i < dd->first_user_ctxt; i++) {
2855 if (ctxtrbits & rmask) {
2856 ctxtrbits &= ~rmask;
2857 if (dd->rcd[i]) {
2858 qib_kreceive(dd->rcd[i], NULL, &npkts);
2861 rmask <<= 1;
2863 if (ctxtrbits) {
2864 ctxtrbits = (ctxtrbits >> QIB_I_RCVAVAIL_LSB) |
2865 (ctxtrbits >> QIB_I_RCVURG_LSB);
2866 qib_handle_urcv(dd, ctxtrbits);
2870 if (istat & (QIB_I_P_SDMAINT(0) | QIB_I_P_SDMAINT(1)))
2871 sdma_7322_intr(dd, istat);
2873 if ((istat & QIB_I_SPIOBUFAVAIL) && (dd->flags & QIB_INITTED))
2874 qib_ib_piobufavail(dd);
2876 ret = IRQ_HANDLED;
2877 bail:
2878 return ret;
2882 * Dedicated receive packet available interrupt handler.
2884 static irqreturn_t qib_7322pintr(int irq, void *data)
2886 struct qib_ctxtdata *rcd = data;
2887 struct qib_devdata *dd = rcd->dd;
2888 u32 npkts;
2890 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
2892 * This return value is not great, but we do not want the
2893 * interrupt core code to remove our interrupt handler
2894 * because we don't appear to be handling an interrupt
2895 * during a chip reset.
2897 return IRQ_HANDLED;
2899 qib_stats.sps_ints++;
2900 if (dd->int_counter != (u32) -1)
2901 dd->int_counter++;
2903 /* Clear the interrupt bit we expect to be set. */
2904 qib_write_kreg(dd, kr_intclear, ((1ULL << QIB_I_RCVAVAIL_LSB) |
2905 (1ULL << QIB_I_RCVURG_LSB)) << rcd->ctxt);
2907 qib_kreceive(rcd, NULL, &npkts);
2909 return IRQ_HANDLED;
2913 * Dedicated Send buffer available interrupt handler.
2915 static irqreturn_t qib_7322bufavail(int irq, void *data)
2917 struct qib_devdata *dd = data;
2919 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
2921 * This return value is not great, but we do not want the
2922 * interrupt core code to remove our interrupt handler
2923 * because we don't appear to be handling an interrupt
2924 * during a chip reset.
2926 return IRQ_HANDLED;
2928 qib_stats.sps_ints++;
2929 if (dd->int_counter != (u32) -1)
2930 dd->int_counter++;
2932 /* Clear the interrupt bit we expect to be set. */
2933 qib_write_kreg(dd, kr_intclear, QIB_I_SPIOBUFAVAIL);
2935 /* qib_ib_piobufavail() will clear the want PIO interrupt if needed */
2936 if (dd->flags & QIB_INITTED)
2937 qib_ib_piobufavail(dd);
2938 else
2939 qib_wantpiobuf_7322_intr(dd, 0);
2941 return IRQ_HANDLED;
2945 * Dedicated Send DMA interrupt handler.
2947 static irqreturn_t sdma_intr(int irq, void *data)
2949 struct qib_pportdata *ppd = data;
2950 struct qib_devdata *dd = ppd->dd;
2952 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
2954 * This return value is not great, but we do not want the
2955 * interrupt core code to remove our interrupt handler
2956 * because we don't appear to be handling an interrupt
2957 * during a chip reset.
2959 return IRQ_HANDLED;
2961 qib_stats.sps_ints++;
2962 if (dd->int_counter != (u32) -1)
2963 dd->int_counter++;
2965 /* Clear the interrupt bit we expect to be set. */
2966 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
2967 INT_MASK_P(SDma, 1) : INT_MASK_P(SDma, 0));
2968 qib_sdma_intr(ppd);
2970 return IRQ_HANDLED;
2974 * Dedicated Send DMA idle interrupt handler.
2976 static irqreturn_t sdma_idle_intr(int irq, void *data)
2978 struct qib_pportdata *ppd = data;
2979 struct qib_devdata *dd = ppd->dd;
2981 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
2983 * This return value is not great, but we do not want the
2984 * interrupt core code to remove our interrupt handler
2985 * because we don't appear to be handling an interrupt
2986 * during a chip reset.
2988 return IRQ_HANDLED;
2990 qib_stats.sps_ints++;
2991 if (dd->int_counter != (u32) -1)
2992 dd->int_counter++;
2994 /* Clear the interrupt bit we expect to be set. */
2995 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
2996 INT_MASK_P(SDmaIdle, 1) : INT_MASK_P(SDmaIdle, 0));
2997 qib_sdma_intr(ppd);
2999 return IRQ_HANDLED;
3003 * Dedicated Send DMA progress interrupt handler.
3005 static irqreturn_t sdma_progress_intr(int irq, void *data)
3007 struct qib_pportdata *ppd = data;
3008 struct qib_devdata *dd = ppd->dd;
3010 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
3012 * This return value is not great, but we do not want the
3013 * interrupt core code to remove our interrupt handler
3014 * because we don't appear to be handling an interrupt
3015 * during a chip reset.
3017 return IRQ_HANDLED;
3019 qib_stats.sps_ints++;
3020 if (dd->int_counter != (u32) -1)
3021 dd->int_counter++;
3023 /* Clear the interrupt bit we expect to be set. */
3024 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
3025 INT_MASK_P(SDmaProgress, 1) :
3026 INT_MASK_P(SDmaProgress, 0));
3027 qib_sdma_intr(ppd);
3029 return IRQ_HANDLED;
3033 * Dedicated Send DMA cleanup interrupt handler.
3035 static irqreturn_t sdma_cleanup_intr(int irq, void *data)
3037 struct qib_pportdata *ppd = data;
3038 struct qib_devdata *dd = ppd->dd;
3040 if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
3042 * This return value is not great, but we do not want the
3043 * interrupt core code to remove our interrupt handler
3044 * because we don't appear to be handling an interrupt
3045 * during a chip reset.
3047 return IRQ_HANDLED;
3049 qib_stats.sps_ints++;
3050 if (dd->int_counter != (u32) -1)
3051 dd->int_counter++;
3053 /* Clear the interrupt bit we expect to be set. */
3054 qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
3055 INT_MASK_PM(SDmaCleanupDone, 1) :
3056 INT_MASK_PM(SDmaCleanupDone, 0));
3057 qib_sdma_process_event(ppd, qib_sdma_event_e20_hw_started);
3059 return IRQ_HANDLED;
3063 * Set up our chip-specific interrupt handler.
3064 * The interrupt type has already been setup, so
3065 * we just need to do the registration and error checking.
3066 * If we are using MSIx interrupts, we may fall back to
3067 * INTx later, if the interrupt handler doesn't get called
3068 * within 1/2 second (see verify_interrupt()).
3070 static void qib_setup_7322_interrupt(struct qib_devdata *dd, int clearpend)
3072 int ret, i, msixnum;
3073 u64 redirect[6];
3074 u64 mask;
3076 if (!dd->num_pports)
3077 return;
3079 if (clearpend) {
3081 * if not switching interrupt types, be sure interrupts are
3082 * disabled, and then clear anything pending at this point,
3083 * because we are starting clean.
3085 qib_7322_set_intr_state(dd, 0);
3087 /* clear the reset error, init error/hwerror mask */
3088 qib_7322_init_hwerrors(dd);
3090 /* clear any interrupt bits that might be set */
3091 qib_write_kreg(dd, kr_intclear, ~0ULL);
3093 /* make sure no pending MSIx intr, and clear diag reg */
3094 qib_write_kreg(dd, kr_intgranted, ~0ULL);
3095 qib_write_kreg(dd, kr_vecclr_wo_int, ~0ULL);
3098 if (!dd->cspec->num_msix_entries) {
3099 /* Try to get INTx interrupt */
3100 try_intx:
3101 if (!dd->pcidev->irq) {
3102 qib_dev_err(dd, "irq is 0, BIOS error? "
3103 "Interrupts won't work\n");
3104 goto bail;
3106 ret = request_irq(dd->pcidev->irq, qib_7322intr,
3107 IRQF_SHARED, QIB_DRV_NAME, dd);
3108 if (ret) {
3109 qib_dev_err(dd, "Couldn't setup INTx "
3110 "interrupt (irq=%d): %d\n",
3111 dd->pcidev->irq, ret);
3112 goto bail;
3114 dd->cspec->irq = dd->pcidev->irq;
3115 dd->cspec->main_int_mask = ~0ULL;
3116 goto bail;
3119 /* Try to get MSIx interrupts */
3120 memset(redirect, 0, sizeof redirect);
3121 mask = ~0ULL;
3122 msixnum = 0;
3123 for (i = 0; msixnum < dd->cspec->num_msix_entries; i++) {
3124 irq_handler_t handler;
3125 const char *name;
3126 void *arg;
3127 u64 val;
3128 int lsb, reg, sh;
3130 if (i < ARRAY_SIZE(irq_table)) {
3131 if (irq_table[i].port) {
3132 /* skip if for a non-configured port */
3133 if (irq_table[i].port > dd->num_pports)
3134 continue;
3135 arg = dd->pport + irq_table[i].port - 1;
3136 } else
3137 arg = dd;
3138 lsb = irq_table[i].lsb;
3139 handler = irq_table[i].handler;
3140 name = irq_table[i].name;
3141 } else {
3142 unsigned ctxt;
3144 ctxt = i - ARRAY_SIZE(irq_table);
3145 /* per krcvq context receive interrupt */
3146 arg = dd->rcd[ctxt];
3147 if (!arg)
3148 continue;
3149 if (qib_krcvq01_no_msi && ctxt < 2)
3150 continue;
3151 lsb = QIB_I_RCVAVAIL_LSB + ctxt;
3152 handler = qib_7322pintr;
3153 name = QIB_DRV_NAME " (kctx)";
3155 ret = request_irq(dd->cspec->msix_entries[msixnum].vector,
3156 handler, 0, name, arg);
3157 if (ret) {
3159 * Shouldn't happen since the enable said we could
3160 * have as many as we are trying to setup here.
3162 qib_dev_err(dd, "Couldn't setup MSIx "
3163 "interrupt (vec=%d, irq=%d): %d\n", msixnum,
3164 dd->cspec->msix_entries[msixnum].vector,
3165 ret);
3166 qib_7322_nomsix(dd);
3167 goto try_intx;
3169 dd->cspec->msix_arg[msixnum] = arg;
3170 if (lsb >= 0) {
3171 reg = lsb / IBA7322_REDIRECT_VEC_PER_REG;
3172 sh = (lsb % IBA7322_REDIRECT_VEC_PER_REG) *
3173 SYM_LSB(IntRedirect0, vec1);
3174 mask &= ~(1ULL << lsb);
3175 redirect[reg] |= ((u64) msixnum) << sh;
3177 val = qib_read_kreg64(dd, 2 * msixnum + 1 +
3178 (QIB_7322_MsixTable_OFFS / sizeof(u64)));
3179 msixnum++;
3181 /* Initialize the vector mapping */
3182 for (i = 0; i < ARRAY_SIZE(redirect); i++)
3183 qib_write_kreg(dd, kr_intredirect + i, redirect[i]);
3184 dd->cspec->main_int_mask = mask;
3185 tasklet_init(&dd->error_tasklet, qib_error_tasklet,
3186 (unsigned long)dd);
3187 bail:;
3191 * qib_7322_boardname - fill in the board name and note features
3192 * @dd: the qlogic_ib device
3194 * info will be based on the board revision register
3196 static unsigned qib_7322_boardname(struct qib_devdata *dd)
3198 /* Will need enumeration of board-types here */
3199 char *n;
3200 u32 boardid, namelen;
3201 unsigned features = DUAL_PORT_CAP;
3203 boardid = SYM_FIELD(dd->revision, Revision, BoardID);
3205 switch (boardid) {
3206 case 0:
3207 n = "InfiniPath_QLE7342_Emulation";
3208 break;
3209 case 1:
3210 n = "InfiniPath_QLE7340";
3211 dd->flags |= QIB_HAS_QSFP;
3212 features = PORT_SPD_CAP;
3213 break;
3214 case 2:
3215 n = "InfiniPath_QLE7342";
3216 dd->flags |= QIB_HAS_QSFP;
3217 break;
3218 case 3:
3219 n = "InfiniPath_QMI7342";
3220 break;
3221 case 4:
3222 n = "InfiniPath_Unsupported7342";
3223 qib_dev_err(dd, "Unsupported version of QMH7342\n");
3224 features = 0;
3225 break;
3226 case BOARD_QMH7342:
3227 n = "InfiniPath_QMH7342";
3228 features = 0x24;
3229 break;
3230 case BOARD_QME7342:
3231 n = "InfiniPath_QME7342";
3232 break;
3233 case 8:
3234 n = "InfiniPath_QME7362";
3235 dd->flags |= QIB_HAS_QSFP;
3236 break;
3237 case 15:
3238 n = "InfiniPath_QLE7342_TEST";
3239 dd->flags |= QIB_HAS_QSFP;
3240 break;
3241 default:
3242 n = "InfiniPath_QLE73xy_UNKNOWN";
3243 qib_dev_err(dd, "Unknown 7322 board type %u\n", boardid);
3244 break;
3246 dd->board_atten = 1; /* index into txdds_Xdr */
3248 namelen = strlen(n) + 1;
3249 dd->boardname = kmalloc(namelen, GFP_KERNEL);
3250 if (!dd->boardname)
3251 qib_dev_err(dd, "Failed allocation for board name: %s\n", n);
3252 else
3253 snprintf(dd->boardname, namelen, "%s", n);
3255 snprintf(dd->boardversion, sizeof(dd->boardversion),
3256 "ChipABI %u.%u, %s, InfiniPath%u %u.%u, SW Compat %u\n",
3257 QIB_CHIP_VERS_MAJ, QIB_CHIP_VERS_MIN, dd->boardname,
3258 (unsigned)SYM_FIELD(dd->revision, Revision_R, Arch),
3259 dd->majrev, dd->minrev,
3260 (unsigned)SYM_FIELD(dd->revision, Revision_R, SW));
3262 if (qib_singleport && (features >> PORT_SPD_CAP_SHIFT) & PORT_SPD_CAP) {
3263 qib_devinfo(dd->pcidev, "IB%u: Forced to single port mode"
3264 " by module parameter\n", dd->unit);
3265 features &= PORT_SPD_CAP;
3268 return features;
3272 * This routine sleeps, so it can only be called from user context, not
3273 * from interrupt context.
3275 static int qib_do_7322_reset(struct qib_devdata *dd)
3277 u64 val;
3278 u64 *msix_vecsave;
3279 int i, msix_entries, ret = 1;
3280 u16 cmdval;
3281 u8 int_line, clinesz;
3282 unsigned long flags;
3284 /* Use dev_err so it shows up in logs, etc. */
3285 qib_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->unit);
3287 qib_pcie_getcmd(dd, &cmdval, &int_line, &clinesz);
3289 msix_entries = dd->cspec->num_msix_entries;
3291 /* no interrupts till re-initted */
3292 qib_7322_set_intr_state(dd, 0);
3294 if (msix_entries) {
3295 qib_7322_nomsix(dd);
3296 /* can be up to 512 bytes, too big for stack */
3297 msix_vecsave = kmalloc(2 * dd->cspec->num_msix_entries *
3298 sizeof(u64), GFP_KERNEL);
3299 if (!msix_vecsave)
3300 qib_dev_err(dd, "No mem to save MSIx data\n");
3301 } else
3302 msix_vecsave = NULL;
3305 * Core PCI (as of 2.6.18) doesn't save or rewrite the full vector
3306 * info that is set up by the BIOS, so we have to save and restore
3307 * it ourselves. There is some risk something could change it,
3308 * after we save it, but since we have disabled the MSIx, it
3309 * shouldn't be touched...
3311 for (i = 0; i < msix_entries; i++) {
3312 u64 vecaddr, vecdata;
3313 vecaddr = qib_read_kreg64(dd, 2 * i +
3314 (QIB_7322_MsixTable_OFFS / sizeof(u64)));
3315 vecdata = qib_read_kreg64(dd, 1 + 2 * i +
3316 (QIB_7322_MsixTable_OFFS / sizeof(u64)));
3317 if (msix_vecsave) {
3318 msix_vecsave[2 * i] = vecaddr;
3319 /* save it without the masked bit set */
3320 msix_vecsave[1 + 2 * i] = vecdata & ~0x100000000ULL;
3324 dd->pport->cpspec->ibdeltainprog = 0;
3325 dd->pport->cpspec->ibsymdelta = 0;
3326 dd->pport->cpspec->iblnkerrdelta = 0;
3327 dd->pport->cpspec->ibmalfdelta = 0;
3328 dd->int_counter = 0; /* so we check interrupts work again */
3331 * Keep chip from being accessed until we are ready. Use
3332 * writeq() directly, to allow the write even though QIB_PRESENT
3333 * isn't set.
3335 dd->flags &= ~(QIB_INITTED | QIB_PRESENT | QIB_BADINTR);
3336 dd->flags |= QIB_DOING_RESET;
3337 val = dd->control | QLOGIC_IB_C_RESET;
3338 writeq(val, &dd->kregbase[kr_control]);
3340 for (i = 1; i <= 5; i++) {
3342 * Allow MBIST, etc. to complete; longer on each retry.
3343 * We sometimes get machine checks from bus timeout if no
3344 * response, so for now, make it *really* long.
3346 msleep(1000 + (1 + i) * 3000);
3348 qib_pcie_reenable(dd, cmdval, int_line, clinesz);
3351 * Use readq directly, so we don't need to mark it as PRESENT
3352 * until we get a successful indication that all is well.
3354 val = readq(&dd->kregbase[kr_revision]);
3355 if (val == dd->revision)
3356 break;
3357 if (i == 5) {
3358 qib_dev_err(dd, "Failed to initialize after reset, "
3359 "unusable\n");
3360 ret = 0;
3361 goto bail;
3365 dd->flags |= QIB_PRESENT; /* it's back */
3367 if (msix_entries) {
3368 /* restore the MSIx vector address and data if saved above */
3369 for (i = 0; i < msix_entries; i++) {
3370 dd->cspec->msix_entries[i].entry = i;
3371 if (!msix_vecsave || !msix_vecsave[2 * i])
3372 continue;
3373 qib_write_kreg(dd, 2 * i +
3374 (QIB_7322_MsixTable_OFFS / sizeof(u64)),
3375 msix_vecsave[2 * i]);
3376 qib_write_kreg(dd, 1 + 2 * i +
3377 (QIB_7322_MsixTable_OFFS / sizeof(u64)),
3378 msix_vecsave[1 + 2 * i]);
3382 /* initialize the remaining registers. */
3383 for (i = 0; i < dd->num_pports; ++i)
3384 write_7322_init_portregs(&dd->pport[i]);
3385 write_7322_initregs(dd);
3387 if (qib_pcie_params(dd, dd->lbus_width,
3388 &dd->cspec->num_msix_entries,
3389 dd->cspec->msix_entries))
3390 qib_dev_err(dd, "Reset failed to setup PCIe or interrupts; "
3391 "continuing anyway\n");
3393 qib_setup_7322_interrupt(dd, 1);
3395 for (i = 0; i < dd->num_pports; ++i) {
3396 struct qib_pportdata *ppd = &dd->pport[i];
3398 spin_lock_irqsave(&ppd->lflags_lock, flags);
3399 ppd->lflags |= QIBL_IB_FORCE_NOTIFY;
3400 ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
3401 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
3404 bail:
3405 dd->flags &= ~QIB_DOING_RESET; /* OK or not, no longer resetting */
3406 kfree(msix_vecsave);
3407 return ret;
3411 * qib_7322_put_tid - write a TID to the chip
3412 * @dd: the qlogic_ib device
3413 * @tidptr: pointer to the expected TID (in chip) to update
3414 * @tidtype: 0 for eager, 1 for expected
3415 * @pa: physical address of in memory buffer; tidinvalid if freeing
3417 static void qib_7322_put_tid(struct qib_devdata *dd, u64 __iomem *tidptr,
3418 u32 type, unsigned long pa)
3420 if (!(dd->flags & QIB_PRESENT))
3421 return;
3422 if (pa != dd->tidinvalid) {
3423 u64 chippa = pa >> IBA7322_TID_PA_SHIFT;
3425 /* paranoia checks */
3426 if (pa != (chippa << IBA7322_TID_PA_SHIFT)) {
3427 qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
3428 pa);
3429 return;
3431 if (chippa >= (1UL << IBA7322_TID_SZ_SHIFT)) {
3432 qib_dev_err(dd, "Physical page address 0x%lx "
3433 "larger than supported\n", pa);
3434 return;
3437 if (type == RCVHQ_RCV_TYPE_EAGER)
3438 chippa |= dd->tidtemplate;
3439 else /* for now, always full 4KB page */
3440 chippa |= IBA7322_TID_SZ_4K;
3441 pa = chippa;
3443 writeq(pa, tidptr);
3444 mmiowb();
3448 * qib_7322_clear_tids - clear all TID entries for a ctxt, expected and eager
3449 * @dd: the qlogic_ib device
3450 * @ctxt: the ctxt
3452 * clear all TID entries for a ctxt, expected and eager.
3453 * Used from qib_close().
3455 static void qib_7322_clear_tids(struct qib_devdata *dd,
3456 struct qib_ctxtdata *rcd)
3458 u64 __iomem *tidbase;
3459 unsigned long tidinv;
3460 u32 ctxt;
3461 int i;
3463 if (!dd->kregbase || !rcd)
3464 return;
3466 ctxt = rcd->ctxt;
3468 tidinv = dd->tidinvalid;
3469 tidbase = (u64 __iomem *)
3470 ((char __iomem *) dd->kregbase +
3471 dd->rcvtidbase +
3472 ctxt * dd->rcvtidcnt * sizeof(*tidbase));
3474 for (i = 0; i < dd->rcvtidcnt; i++)
3475 qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
3476 tidinv);
3478 tidbase = (u64 __iomem *)
3479 ((char __iomem *) dd->kregbase +
3480 dd->rcvegrbase +
3481 rcd->rcvegr_tid_base * sizeof(*tidbase));
3483 for (i = 0; i < rcd->rcvegrcnt; i++)
3484 qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
3485 tidinv);
3489 * qib_7322_tidtemplate - setup constants for TID updates
3490 * @dd: the qlogic_ib device
3492 * We setup stuff that we use a lot, to avoid calculating each time
3494 static void qib_7322_tidtemplate(struct qib_devdata *dd)
3497 * For now, we always allocate 4KB buffers (at init) so we can
3498 * receive max size packets. We may want a module parameter to
3499 * specify 2KB or 4KB and/or make it per port instead of per device
3500 * for those who want to reduce memory footprint. Note that the
3501 * rcvhdrentsize size must be large enough to hold the largest
3502 * IB header (currently 96 bytes) that we expect to handle (plus of
3503 * course the 2 dwords of RHF).
3505 if (dd->rcvegrbufsize == 2048)
3506 dd->tidtemplate = IBA7322_TID_SZ_2K;
3507 else if (dd->rcvegrbufsize == 4096)
3508 dd->tidtemplate = IBA7322_TID_SZ_4K;
3509 dd->tidinvalid = 0;
3513 * qib_init_7322_get_base_info - set chip-specific flags for user code
3514 * @rcd: the qlogic_ib ctxt
3515 * @kbase: qib_base_info pointer
3517 * We set the PCIE flag because the lower bandwidth on PCIe vs
3518 * HyperTransport can affect some user packet algorithims.
3521 static int qib_7322_get_base_info(struct qib_ctxtdata *rcd,
3522 struct qib_base_info *kinfo)
3524 kinfo->spi_runtime_flags |= QIB_RUNTIME_CTXT_MSB_IN_QP |
3525 QIB_RUNTIME_PCIE | QIB_RUNTIME_NODMA_RTAIL |
3526 QIB_RUNTIME_HDRSUPP | QIB_RUNTIME_SDMA;
3527 if (rcd->dd->cspec->r1)
3528 kinfo->spi_runtime_flags |= QIB_RUNTIME_RCHK;
3529 if (rcd->dd->flags & QIB_USE_SPCL_TRIG)
3530 kinfo->spi_runtime_flags |= QIB_RUNTIME_SPECIAL_TRIGGER;
3532 return 0;
3535 static struct qib_message_header *
3536 qib_7322_get_msgheader(struct qib_devdata *dd, __le32 *rhf_addr)
3538 u32 offset = qib_hdrget_offset(rhf_addr);
3540 return (struct qib_message_header *)
3541 (rhf_addr - dd->rhf_offset + offset);
3545 * Configure number of contexts.
3547 static void qib_7322_config_ctxts(struct qib_devdata *dd)
3549 unsigned long flags;
3550 u32 nchipctxts;
3552 nchipctxts = qib_read_kreg32(dd, kr_contextcnt);
3553 dd->cspec->numctxts = nchipctxts;
3554 if (qib_n_krcv_queues > 1 && dd->num_pports) {
3555 dd->first_user_ctxt = NUM_IB_PORTS +
3556 (qib_n_krcv_queues - 1) * dd->num_pports;
3557 if (dd->first_user_ctxt > nchipctxts)
3558 dd->first_user_ctxt = nchipctxts;
3559 dd->n_krcv_queues = dd->first_user_ctxt / dd->num_pports;
3560 } else {
3561 dd->first_user_ctxt = NUM_IB_PORTS;
3562 dd->n_krcv_queues = 1;
3565 if (!qib_cfgctxts) {
3566 int nctxts = dd->first_user_ctxt + num_online_cpus();
3568 if (nctxts <= 6)
3569 dd->ctxtcnt = 6;
3570 else if (nctxts <= 10)
3571 dd->ctxtcnt = 10;
3572 else if (nctxts <= nchipctxts)
3573 dd->ctxtcnt = nchipctxts;
3574 } else if (qib_cfgctxts < dd->num_pports)
3575 dd->ctxtcnt = dd->num_pports;
3576 else if (qib_cfgctxts <= nchipctxts)
3577 dd->ctxtcnt = qib_cfgctxts;
3578 if (!dd->ctxtcnt) /* none of the above, set to max */
3579 dd->ctxtcnt = nchipctxts;
3582 * Chip can be configured for 6, 10, or 18 ctxts, and choice
3583 * affects number of eager TIDs per ctxt (1K, 2K, 4K).
3584 * Lock to be paranoid about later motion, etc.
3586 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
3587 if (dd->ctxtcnt > 10)
3588 dd->rcvctrl |= 2ULL << SYM_LSB(RcvCtrl, ContextCfg);
3589 else if (dd->ctxtcnt > 6)
3590 dd->rcvctrl |= 1ULL << SYM_LSB(RcvCtrl, ContextCfg);
3591 /* else configure for default 6 receive ctxts */
3593 /* The XRC opcode is 5. */
3594 dd->rcvctrl |= 5ULL << SYM_LSB(RcvCtrl, XrcTypeCode);
3597 * RcvCtrl *must* be written here so that the
3598 * chip understands how to change rcvegrcnt below.
3600 qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
3601 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
3603 /* kr_rcvegrcnt changes based on the number of contexts enabled */
3604 dd->cspec->rcvegrcnt = qib_read_kreg32(dd, kr_rcvegrcnt);
3605 if (qib_rcvhdrcnt)
3606 dd->rcvhdrcnt = max(dd->cspec->rcvegrcnt, qib_rcvhdrcnt);
3607 else
3608 dd->rcvhdrcnt = max(dd->cspec->rcvegrcnt,
3609 dd->num_pports > 1 ? 1024U : 2048U);
3612 static int qib_7322_get_ib_cfg(struct qib_pportdata *ppd, int which)
3615 int lsb, ret = 0;
3616 u64 maskr; /* right-justified mask */
3618 switch (which) {
3620 case QIB_IB_CFG_LWID_ENB: /* Get allowed Link-width */
3621 ret = ppd->link_width_enabled;
3622 goto done;
3624 case QIB_IB_CFG_LWID: /* Get currently active Link-width */
3625 ret = ppd->link_width_active;
3626 goto done;
3628 case QIB_IB_CFG_SPD_ENB: /* Get allowed Link speeds */
3629 ret = ppd->link_speed_enabled;
3630 goto done;
3632 case QIB_IB_CFG_SPD: /* Get current Link spd */
3633 ret = ppd->link_speed_active;
3634 goto done;
3636 case QIB_IB_CFG_RXPOL_ENB: /* Get Auto-RX-polarity enable */
3637 lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
3638 maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
3639 break;
3641 case QIB_IB_CFG_LREV_ENB: /* Get Auto-Lane-reversal enable */
3642 lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
3643 maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
3644 break;
3646 case QIB_IB_CFG_LINKLATENCY:
3647 ret = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
3648 SYM_MASK(IBCStatusB_0, LinkRoundTripLatency);
3649 goto done;
3651 case QIB_IB_CFG_OP_VLS:
3652 ret = ppd->vls_operational;
3653 goto done;
3655 case QIB_IB_CFG_VL_HIGH_CAP:
3656 ret = 16;
3657 goto done;
3659 case QIB_IB_CFG_VL_LOW_CAP:
3660 ret = 16;
3661 goto done;
3663 case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
3664 ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
3665 OverrunThreshold);
3666 goto done;
3668 case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
3669 ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
3670 PhyerrThreshold);
3671 goto done;
3673 case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
3674 /* will only take effect when the link state changes */
3675 ret = (ppd->cpspec->ibcctrl_a &
3676 SYM_MASK(IBCCtrlA_0, LinkDownDefaultState)) ?
3677 IB_LINKINITCMD_SLEEP : IB_LINKINITCMD_POLL;
3678 goto done;
3680 case QIB_IB_CFG_HRTBT: /* Get Heartbeat off/enable/auto */
3681 lsb = IBA7322_IBC_HRTBT_LSB;
3682 maskr = IBA7322_IBC_HRTBT_RMASK; /* OR of AUTO and ENB */
3683 break;
3685 case QIB_IB_CFG_PMA_TICKS:
3687 * 0x00 = 10x link transfer rate or 4 nsec. for 2.5Gbs
3688 * Since the clock is always 250MHz, the value is 3, 1 or 0.
3690 if (ppd->link_speed_active == QIB_IB_QDR)
3691 ret = 3;
3692 else if (ppd->link_speed_active == QIB_IB_DDR)
3693 ret = 1;
3694 else
3695 ret = 0;
3696 goto done;
3698 default:
3699 ret = -EINVAL;
3700 goto done;
3702 ret = (int)((ppd->cpspec->ibcctrl_b >> lsb) & maskr);
3703 done:
3704 return ret;
3708 * Below again cribbed liberally from older version. Do not lean
3709 * heavily on it.
3711 #define IBA7322_IBC_DLIDLMC_SHIFT QIB_7322_IBCCtrlB_0_IB_DLID_LSB
3712 #define IBA7322_IBC_DLIDLMC_MASK (QIB_7322_IBCCtrlB_0_IB_DLID_RMASK \
3713 | (QIB_7322_IBCCtrlB_0_IB_DLID_MASK_RMASK << 16))
3715 static int qib_7322_set_ib_cfg(struct qib_pportdata *ppd, int which, u32 val)
3717 struct qib_devdata *dd = ppd->dd;
3718 u64 maskr; /* right-justified mask */
3719 int lsb, ret = 0;
3720 u16 lcmd, licmd;
3721 unsigned long flags;
3723 switch (which) {
3724 case QIB_IB_CFG_LIDLMC:
3726 * Set LID and LMC. Combined to avoid possible hazard
3727 * caller puts LMC in 16MSbits, DLID in 16LSbits of val
3729 lsb = IBA7322_IBC_DLIDLMC_SHIFT;
3730 maskr = IBA7322_IBC_DLIDLMC_MASK;
3732 * For header-checking, the SLID in the packet will
3733 * be masked with SendIBSLMCMask, and compared
3734 * with SendIBSLIDAssignMask. Make sure we do not
3735 * set any bits not covered by the mask, or we get
3736 * false-positives.
3738 qib_write_kreg_port(ppd, krp_sendslid,
3739 val & (val >> 16) & SendIBSLIDAssignMask);
3740 qib_write_kreg_port(ppd, krp_sendslidmask,
3741 (val >> 16) & SendIBSLMCMask);
3742 break;
3744 case QIB_IB_CFG_LWID_ENB: /* set allowed Link-width */
3745 ppd->link_width_enabled = val;
3746 /* convert IB value to chip register value */
3747 if (val == IB_WIDTH_1X)
3748 val = 0;
3749 else if (val == IB_WIDTH_4X)
3750 val = 1;
3751 else
3752 val = 3;
3753 maskr = SYM_RMASK(IBCCtrlB_0, IB_NUM_CHANNELS);
3754 lsb = SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS);
3755 break;
3757 case QIB_IB_CFG_SPD_ENB: /* set allowed Link speeds */
3759 * As with width, only write the actual register if the
3760 * link is currently down, otherwise takes effect on next
3761 * link change. Since setting is being explicitly requested
3762 * (via MAD or sysfs), clear autoneg failure status if speed
3763 * autoneg is enabled.
3765 ppd->link_speed_enabled = val;
3766 val <<= IBA7322_IBC_SPEED_LSB;
3767 maskr = IBA7322_IBC_SPEED_MASK | IBA7322_IBC_IBTA_1_2_MASK |
3768 IBA7322_IBC_MAX_SPEED_MASK;
3769 if (val & (val - 1)) {
3770 /* Muliple speeds enabled */
3771 val |= IBA7322_IBC_IBTA_1_2_MASK |
3772 IBA7322_IBC_MAX_SPEED_MASK;
3773 spin_lock_irqsave(&ppd->lflags_lock, flags);
3774 ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
3775 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
3776 } else if (val & IBA7322_IBC_SPEED_QDR)
3777 val |= IBA7322_IBC_IBTA_1_2_MASK;
3778 /* IBTA 1.2 mode + min/max + speed bits are contiguous */
3779 lsb = SYM_LSB(IBCCtrlB_0, IB_ENHANCED_MODE);
3780 break;
3782 case QIB_IB_CFG_RXPOL_ENB: /* set Auto-RX-polarity enable */
3783 lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
3784 maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
3785 break;
3787 case QIB_IB_CFG_LREV_ENB: /* set Auto-Lane-reversal enable */
3788 lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
3789 maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
3790 break;
3792 case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
3793 maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
3794 OverrunThreshold);
3795 if (maskr != val) {
3796 ppd->cpspec->ibcctrl_a &=
3797 ~SYM_MASK(IBCCtrlA_0, OverrunThreshold);
3798 ppd->cpspec->ibcctrl_a |= (u64) val <<
3799 SYM_LSB(IBCCtrlA_0, OverrunThreshold);
3800 qib_write_kreg_port(ppd, krp_ibcctrl_a,
3801 ppd->cpspec->ibcctrl_a);
3802 qib_write_kreg(dd, kr_scratch, 0ULL);
3804 goto bail;
3806 case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
3807 maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
3808 PhyerrThreshold);
3809 if (maskr != val) {
3810 ppd->cpspec->ibcctrl_a &=
3811 ~SYM_MASK(IBCCtrlA_0, PhyerrThreshold);
3812 ppd->cpspec->ibcctrl_a |= (u64) val <<
3813 SYM_LSB(IBCCtrlA_0, PhyerrThreshold);
3814 qib_write_kreg_port(ppd, krp_ibcctrl_a,
3815 ppd->cpspec->ibcctrl_a);
3816 qib_write_kreg(dd, kr_scratch, 0ULL);
3818 goto bail;
3820 case QIB_IB_CFG_PKEYS: /* update pkeys */
3821 maskr = (u64) ppd->pkeys[0] | ((u64) ppd->pkeys[1] << 16) |
3822 ((u64) ppd->pkeys[2] << 32) |
3823 ((u64) ppd->pkeys[3] << 48);
3824 qib_write_kreg_port(ppd, krp_partitionkey, maskr);
3825 goto bail;
3827 case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
3828 /* will only take effect when the link state changes */
3829 if (val == IB_LINKINITCMD_POLL)
3830 ppd->cpspec->ibcctrl_a &=
3831 ~SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
3832 else /* SLEEP */
3833 ppd->cpspec->ibcctrl_a |=
3834 SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
3835 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
3836 qib_write_kreg(dd, kr_scratch, 0ULL);
3837 goto bail;
3839 case QIB_IB_CFG_MTU: /* update the MTU in IBC */
3841 * Update our housekeeping variables, and set IBC max
3842 * size, same as init code; max IBC is max we allow in
3843 * buffer, less the qword pbc, plus 1 for ICRC, in dwords
3844 * Set even if it's unchanged, print debug message only
3845 * on changes.
3847 val = (ppd->ibmaxlen >> 2) + 1;
3848 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, MaxPktLen);
3849 ppd->cpspec->ibcctrl_a |= (u64)val <<
3850 SYM_LSB(IBCCtrlA_0, MaxPktLen);
3851 qib_write_kreg_port(ppd, krp_ibcctrl_a,
3852 ppd->cpspec->ibcctrl_a);
3853 qib_write_kreg(dd, kr_scratch, 0ULL);
3854 goto bail;
3856 case QIB_IB_CFG_LSTATE: /* set the IB link state */
3857 switch (val & 0xffff0000) {
3858 case IB_LINKCMD_DOWN:
3859 lcmd = QLOGIC_IB_IBCC_LINKCMD_DOWN;
3860 ppd->cpspec->ibmalfusesnap = 1;
3861 ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
3862 crp_errlink);
3863 if (!ppd->cpspec->ibdeltainprog &&
3864 qib_compat_ddr_negotiate) {
3865 ppd->cpspec->ibdeltainprog = 1;
3866 ppd->cpspec->ibsymsnap =
3867 read_7322_creg32_port(ppd,
3868 crp_ibsymbolerr);
3869 ppd->cpspec->iblnkerrsnap =
3870 read_7322_creg32_port(ppd,
3871 crp_iblinkerrrecov);
3873 break;
3875 case IB_LINKCMD_ARMED:
3876 lcmd = QLOGIC_IB_IBCC_LINKCMD_ARMED;
3877 if (ppd->cpspec->ibmalfusesnap) {
3878 ppd->cpspec->ibmalfusesnap = 0;
3879 ppd->cpspec->ibmalfdelta +=
3880 read_7322_creg32_port(ppd,
3881 crp_errlink) -
3882 ppd->cpspec->ibmalfsnap;
3884 break;
3886 case IB_LINKCMD_ACTIVE:
3887 lcmd = QLOGIC_IB_IBCC_LINKCMD_ACTIVE;
3888 break;
3890 default:
3891 ret = -EINVAL;
3892 qib_dev_err(dd, "bad linkcmd req 0x%x\n", val >> 16);
3893 goto bail;
3895 switch (val & 0xffff) {
3896 case IB_LINKINITCMD_NOP:
3897 licmd = 0;
3898 break;
3900 case IB_LINKINITCMD_POLL:
3901 licmd = QLOGIC_IB_IBCC_LINKINITCMD_POLL;
3902 break;
3904 case IB_LINKINITCMD_SLEEP:
3905 licmd = QLOGIC_IB_IBCC_LINKINITCMD_SLEEP;
3906 break;
3908 case IB_LINKINITCMD_DISABLE:
3909 licmd = QLOGIC_IB_IBCC_LINKINITCMD_DISABLE;
3910 ppd->cpspec->chase_end = 0;
3912 * stop state chase counter and timer, if running.
3913 * wait forpending timer, but don't clear .data (ppd)!
3915 if (ppd->cpspec->chase_timer.expires) {
3916 del_timer_sync(&ppd->cpspec->chase_timer);
3917 ppd->cpspec->chase_timer.expires = 0;
3919 break;
3921 default:
3922 ret = -EINVAL;
3923 qib_dev_err(dd, "bad linkinitcmd req 0x%x\n",
3924 val & 0xffff);
3925 goto bail;
3927 qib_set_ib_7322_lstate(ppd, lcmd, licmd);
3928 goto bail;
3930 case QIB_IB_CFG_OP_VLS:
3931 if (ppd->vls_operational != val) {
3932 ppd->vls_operational = val;
3933 set_vls(ppd);
3935 goto bail;
3937 case QIB_IB_CFG_VL_HIGH_LIMIT:
3938 qib_write_kreg_port(ppd, krp_highprio_limit, val);
3939 goto bail;
3941 case QIB_IB_CFG_HRTBT: /* set Heartbeat off/enable/auto */
3942 if (val > 3) {
3943 ret = -EINVAL;
3944 goto bail;
3946 lsb = IBA7322_IBC_HRTBT_LSB;
3947 maskr = IBA7322_IBC_HRTBT_RMASK; /* OR of AUTO and ENB */
3948 break;
3950 case QIB_IB_CFG_PORT:
3951 /* val is the port number of the switch we are connected to. */
3952 if (ppd->dd->cspec->r1) {
3953 cancel_delayed_work(&ppd->cpspec->ipg_work);
3954 ppd->cpspec->ipg_tries = 0;
3956 goto bail;
3958 default:
3959 ret = -EINVAL;
3960 goto bail;
3962 ppd->cpspec->ibcctrl_b &= ~(maskr << lsb);
3963 ppd->cpspec->ibcctrl_b |= (((u64) val & maskr) << lsb);
3964 qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
3965 qib_write_kreg(dd, kr_scratch, 0);
3966 bail:
3967 return ret;
3970 static int qib_7322_set_loopback(struct qib_pportdata *ppd, const char *what)
3972 int ret = 0;
3973 u64 val, ctrlb;
3975 /* only IBC loopback, may add serdes and xgxs loopbacks later */
3976 if (!strncmp(what, "ibc", 3)) {
3977 ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0,
3978 Loopback);
3979 val = 0; /* disable heart beat, so link will come up */
3980 qib_devinfo(ppd->dd->pcidev, "Enabling IB%u:%u IBC loopback\n",
3981 ppd->dd->unit, ppd->port);
3982 } else if (!strncmp(what, "off", 3)) {
3983 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0,
3984 Loopback);
3985 /* enable heart beat again */
3986 val = IBA7322_IBC_HRTBT_RMASK << IBA7322_IBC_HRTBT_LSB;
3987 qib_devinfo(ppd->dd->pcidev, "Disabling IB%u:%u IBC loopback "
3988 "(normal)\n", ppd->dd->unit, ppd->port);
3989 } else
3990 ret = -EINVAL;
3991 if (!ret) {
3992 qib_write_kreg_port(ppd, krp_ibcctrl_a,
3993 ppd->cpspec->ibcctrl_a);
3994 ctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_HRTBT_MASK
3995 << IBA7322_IBC_HRTBT_LSB);
3996 ppd->cpspec->ibcctrl_b = ctrlb | val;
3997 qib_write_kreg_port(ppd, krp_ibcctrl_b,
3998 ppd->cpspec->ibcctrl_b);
3999 qib_write_kreg(ppd->dd, kr_scratch, 0);
4001 return ret;
4004 static void get_vl_weights(struct qib_pportdata *ppd, unsigned regno,
4005 struct ib_vl_weight_elem *vl)
4007 unsigned i;
4009 for (i = 0; i < 16; i++, regno++, vl++) {
4010 u32 val = qib_read_kreg_port(ppd, regno);
4012 vl->vl = (val >> SYM_LSB(LowPriority0_0, VirtualLane)) &
4013 SYM_RMASK(LowPriority0_0, VirtualLane);
4014 vl->weight = (val >> SYM_LSB(LowPriority0_0, Weight)) &
4015 SYM_RMASK(LowPriority0_0, Weight);
4019 static void set_vl_weights(struct qib_pportdata *ppd, unsigned regno,
4020 struct ib_vl_weight_elem *vl)
4022 unsigned i;
4024 for (i = 0; i < 16; i++, regno++, vl++) {
4025 u64 val;
4027 val = ((vl->vl & SYM_RMASK(LowPriority0_0, VirtualLane)) <<
4028 SYM_LSB(LowPriority0_0, VirtualLane)) |
4029 ((vl->weight & SYM_RMASK(LowPriority0_0, Weight)) <<
4030 SYM_LSB(LowPriority0_0, Weight));
4031 qib_write_kreg_port(ppd, regno, val);
4033 if (!(ppd->p_sendctrl & SYM_MASK(SendCtrl_0, IBVLArbiterEn))) {
4034 struct qib_devdata *dd = ppd->dd;
4035 unsigned long flags;
4037 spin_lock_irqsave(&dd->sendctrl_lock, flags);
4038 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, IBVLArbiterEn);
4039 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
4040 qib_write_kreg(dd, kr_scratch, 0);
4041 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
4045 static int qib_7322_get_ib_table(struct qib_pportdata *ppd, int which, void *t)
4047 switch (which) {
4048 case QIB_IB_TBL_VL_HIGH_ARB:
4049 get_vl_weights(ppd, krp_highprio_0, t);
4050 break;
4052 case QIB_IB_TBL_VL_LOW_ARB:
4053 get_vl_weights(ppd, krp_lowprio_0, t);
4054 break;
4056 default:
4057 return -EINVAL;
4059 return 0;
4062 static int qib_7322_set_ib_table(struct qib_pportdata *ppd, int which, void *t)
4064 switch (which) {
4065 case QIB_IB_TBL_VL_HIGH_ARB:
4066 set_vl_weights(ppd, krp_highprio_0, t);
4067 break;
4069 case QIB_IB_TBL_VL_LOW_ARB:
4070 set_vl_weights(ppd, krp_lowprio_0, t);
4071 break;
4073 default:
4074 return -EINVAL;
4076 return 0;
4079 static void qib_update_7322_usrhead(struct qib_ctxtdata *rcd, u64 hd,
4080 u32 updegr, u32 egrhd, u32 npkts)
4083 * Need to write timeout register before updating rcvhdrhead to ensure
4084 * that the timer is enabled on reception of a packet.
4086 if (hd >> IBA7322_HDRHEAD_PKTINT_SHIFT)
4087 adjust_rcv_timeout(rcd, npkts);
4088 qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
4089 qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
4090 if (updegr)
4091 qib_write_ureg(rcd->dd, ur_rcvegrindexhead, egrhd, rcd->ctxt);
4094 static u32 qib_7322_hdrqempty(struct qib_ctxtdata *rcd)
4096 u32 head, tail;
4098 head = qib_read_ureg32(rcd->dd, ur_rcvhdrhead, rcd->ctxt);
4099 if (rcd->rcvhdrtail_kvaddr)
4100 tail = qib_get_rcvhdrtail(rcd);
4101 else
4102 tail = qib_read_ureg32(rcd->dd, ur_rcvhdrtail, rcd->ctxt);
4103 return head == tail;
4106 #define RCVCTRL_COMMON_MODS (QIB_RCVCTRL_CTXT_ENB | \
4107 QIB_RCVCTRL_CTXT_DIS | \
4108 QIB_RCVCTRL_TIDFLOW_ENB | \
4109 QIB_RCVCTRL_TIDFLOW_DIS | \
4110 QIB_RCVCTRL_TAILUPD_ENB | \
4111 QIB_RCVCTRL_TAILUPD_DIS | \
4112 QIB_RCVCTRL_INTRAVAIL_ENB | \
4113 QIB_RCVCTRL_INTRAVAIL_DIS | \
4114 QIB_RCVCTRL_BP_ENB | \
4115 QIB_RCVCTRL_BP_DIS)
4117 #define RCVCTRL_PORT_MODS (QIB_RCVCTRL_CTXT_ENB | \
4118 QIB_RCVCTRL_CTXT_DIS | \
4119 QIB_RCVCTRL_PKEY_DIS | \
4120 QIB_RCVCTRL_PKEY_ENB)
4123 * Modify the RCVCTRL register in chip-specific way. This
4124 * is a function because bit positions and (future) register
4125 * location is chip-specifc, but the needed operations are
4126 * generic. <op> is a bit-mask because we often want to
4127 * do multiple modifications.
4129 static void rcvctrl_7322_mod(struct qib_pportdata *ppd, unsigned int op,
4130 int ctxt)
4132 struct qib_devdata *dd = ppd->dd;
4133 struct qib_ctxtdata *rcd;
4134 u64 mask, val;
4135 unsigned long flags;
4137 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
4139 if (op & QIB_RCVCTRL_TIDFLOW_ENB)
4140 dd->rcvctrl |= SYM_MASK(RcvCtrl, TidFlowEnable);
4141 if (op & QIB_RCVCTRL_TIDFLOW_DIS)
4142 dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TidFlowEnable);
4143 if (op & QIB_RCVCTRL_TAILUPD_ENB)
4144 dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
4145 if (op & QIB_RCVCTRL_TAILUPD_DIS)
4146 dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TailUpd);
4147 if (op & QIB_RCVCTRL_PKEY_ENB)
4148 ppd->p_rcvctrl &= ~SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
4149 if (op & QIB_RCVCTRL_PKEY_DIS)
4150 ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
4151 if (ctxt < 0) {
4152 mask = (1ULL << dd->ctxtcnt) - 1;
4153 rcd = NULL;
4154 } else {
4155 mask = (1ULL << ctxt);
4156 rcd = dd->rcd[ctxt];
4158 if ((op & QIB_RCVCTRL_CTXT_ENB) && rcd) {
4159 ppd->p_rcvctrl |=
4160 (mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
4161 if (!(dd->flags & QIB_NODMA_RTAIL)) {
4162 op |= QIB_RCVCTRL_TAILUPD_ENB; /* need reg write */
4163 dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
4165 /* Write these registers before the context is enabled. */
4166 qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt,
4167 rcd->rcvhdrqtailaddr_phys);
4168 qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt,
4169 rcd->rcvhdrq_phys);
4170 rcd->seq_cnt = 1;
4172 if (op & QIB_RCVCTRL_CTXT_DIS)
4173 ppd->p_rcvctrl &=
4174 ~(mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
4175 if (op & QIB_RCVCTRL_BP_ENB)
4176 dd->rcvctrl |= mask << SYM_LSB(RcvCtrl, dontDropRHQFull);
4177 if (op & QIB_RCVCTRL_BP_DIS)
4178 dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, dontDropRHQFull));
4179 if (op & QIB_RCVCTRL_INTRAVAIL_ENB)
4180 dd->rcvctrl |= (mask << SYM_LSB(RcvCtrl, IntrAvail));
4181 if (op & QIB_RCVCTRL_INTRAVAIL_DIS)
4182 dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, IntrAvail));
4184 * Decide which registers to write depending on the ops enabled.
4185 * Special case is "flush" (no bits set at all)
4186 * which needs to write both.
4188 if (op == 0 || (op & RCVCTRL_COMMON_MODS))
4189 qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
4190 if (op == 0 || (op & RCVCTRL_PORT_MODS))
4191 qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
4192 if ((op & QIB_RCVCTRL_CTXT_ENB) && dd->rcd[ctxt]) {
4194 * Init the context registers also; if we were
4195 * disabled, tail and head should both be zero
4196 * already from the enable, but since we don't
4197 * know, we have to do it explicitly.
4199 val = qib_read_ureg32(dd, ur_rcvegrindextail, ctxt);
4200 qib_write_ureg(dd, ur_rcvegrindexhead, val, ctxt);
4202 /* be sure enabling write seen; hd/tl should be 0 */
4203 (void) qib_read_kreg32(dd, kr_scratch);
4204 val = qib_read_ureg32(dd, ur_rcvhdrtail, ctxt);
4205 dd->rcd[ctxt]->head = val;
4206 /* If kctxt, interrupt on next receive. */
4207 if (ctxt < dd->first_user_ctxt)
4208 val |= dd->rhdrhead_intr_off;
4209 qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
4210 } else if ((op & QIB_RCVCTRL_INTRAVAIL_ENB) &&
4211 dd->rcd[ctxt] && dd->rhdrhead_intr_off) {
4212 /* arm rcv interrupt */
4213 val = dd->rcd[ctxt]->head | dd->rhdrhead_intr_off;
4214 qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
4216 if (op & QIB_RCVCTRL_CTXT_DIS) {
4217 unsigned f;
4219 /* Now that the context is disabled, clear these registers. */
4220 if (ctxt >= 0) {
4221 qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt, 0);
4222 qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt, 0);
4223 for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
4224 qib_write_ureg(dd, ur_rcvflowtable + f,
4225 TIDFLOW_ERRBITS, ctxt);
4226 } else {
4227 unsigned i;
4229 for (i = 0; i < dd->cfgctxts; i++) {
4230 qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr,
4231 i, 0);
4232 qib_write_kreg_ctxt(dd, krc_rcvhdraddr, i, 0);
4233 for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
4234 qib_write_ureg(dd, ur_rcvflowtable + f,
4235 TIDFLOW_ERRBITS, i);
4239 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
4243 * Modify the SENDCTRL register in chip-specific way. This
4244 * is a function where there are multiple such registers with
4245 * slightly different layouts.
4246 * The chip doesn't allow back-to-back sendctrl writes, so write
4247 * the scratch register after writing sendctrl.
4249 * Which register is written depends on the operation.
4250 * Most operate on the common register, while
4251 * SEND_ENB and SEND_DIS operate on the per-port ones.
4252 * SEND_ENB is included in common because it can change SPCL_TRIG
4254 #define SENDCTRL_COMMON_MODS (\
4255 QIB_SENDCTRL_CLEAR | \
4256 QIB_SENDCTRL_AVAIL_DIS | \
4257 QIB_SENDCTRL_AVAIL_ENB | \
4258 QIB_SENDCTRL_AVAIL_BLIP | \
4259 QIB_SENDCTRL_DISARM | \
4260 QIB_SENDCTRL_DISARM_ALL | \
4261 QIB_SENDCTRL_SEND_ENB)
4263 #define SENDCTRL_PORT_MODS (\
4264 QIB_SENDCTRL_CLEAR | \
4265 QIB_SENDCTRL_SEND_ENB | \
4266 QIB_SENDCTRL_SEND_DIS | \
4267 QIB_SENDCTRL_FLUSH)
4269 static void sendctrl_7322_mod(struct qib_pportdata *ppd, u32 op)
4271 struct qib_devdata *dd = ppd->dd;
4272 u64 tmp_dd_sendctrl;
4273 unsigned long flags;
4275 spin_lock_irqsave(&dd->sendctrl_lock, flags);
4277 /* First the dd ones that are "sticky", saved in shadow */
4278 if (op & QIB_SENDCTRL_CLEAR)
4279 dd->sendctrl = 0;
4280 if (op & QIB_SENDCTRL_AVAIL_DIS)
4281 dd->sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
4282 else if (op & QIB_SENDCTRL_AVAIL_ENB) {
4283 dd->sendctrl |= SYM_MASK(SendCtrl, SendBufAvailUpd);
4284 if (dd->flags & QIB_USE_SPCL_TRIG)
4285 dd->sendctrl |= SYM_MASK(SendCtrl, SpecialTriggerEn);
4288 /* Then the ppd ones that are "sticky", saved in shadow */
4289 if (op & QIB_SENDCTRL_SEND_DIS)
4290 ppd->p_sendctrl &= ~SYM_MASK(SendCtrl_0, SendEnable);
4291 else if (op & QIB_SENDCTRL_SEND_ENB)
4292 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, SendEnable);
4294 if (op & QIB_SENDCTRL_DISARM_ALL) {
4295 u32 i, last;
4297 tmp_dd_sendctrl = dd->sendctrl;
4298 last = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
4300 * Disarm any buffers that are not yet launched,
4301 * disabling updates until done.
4303 tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
4304 for (i = 0; i < last; i++) {
4305 qib_write_kreg(dd, kr_sendctrl,
4306 tmp_dd_sendctrl |
4307 SYM_MASK(SendCtrl, Disarm) | i);
4308 qib_write_kreg(dd, kr_scratch, 0);
4312 if (op & QIB_SENDCTRL_FLUSH) {
4313 u64 tmp_ppd_sendctrl = ppd->p_sendctrl;
4316 * Now drain all the fifos. The Abort bit should never be
4317 * needed, so for now, at least, we don't use it.
4319 tmp_ppd_sendctrl |=
4320 SYM_MASK(SendCtrl_0, TxeDrainRmFifo) |
4321 SYM_MASK(SendCtrl_0, TxeDrainLaFifo) |
4322 SYM_MASK(SendCtrl_0, TxeBypassIbc);
4323 qib_write_kreg_port(ppd, krp_sendctrl, tmp_ppd_sendctrl);
4324 qib_write_kreg(dd, kr_scratch, 0);
4327 tmp_dd_sendctrl = dd->sendctrl;
4329 if (op & QIB_SENDCTRL_DISARM)
4330 tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Disarm) |
4331 ((op & QIB_7322_SendCtrl_DisarmSendBuf_RMASK) <<
4332 SYM_LSB(SendCtrl, DisarmSendBuf));
4333 if ((op & QIB_SENDCTRL_AVAIL_BLIP) &&
4334 (dd->sendctrl & SYM_MASK(SendCtrl, SendBufAvailUpd)))
4335 tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
4337 if (op == 0 || (op & SENDCTRL_COMMON_MODS)) {
4338 qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl);
4339 qib_write_kreg(dd, kr_scratch, 0);
4342 if (op == 0 || (op & SENDCTRL_PORT_MODS)) {
4343 qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
4344 qib_write_kreg(dd, kr_scratch, 0);
4347 if (op & QIB_SENDCTRL_AVAIL_BLIP) {
4348 qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
4349 qib_write_kreg(dd, kr_scratch, 0);
4352 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
4354 if (op & QIB_SENDCTRL_FLUSH) {
4355 u32 v;
4357 * ensure writes have hit chip, then do a few
4358 * more reads, to allow DMA of pioavail registers
4359 * to occur, so in-memory copy is in sync with
4360 * the chip. Not always safe to sleep.
4362 v = qib_read_kreg32(dd, kr_scratch);
4363 qib_write_kreg(dd, kr_scratch, v);
4364 v = qib_read_kreg32(dd, kr_scratch);
4365 qib_write_kreg(dd, kr_scratch, v);
4366 qib_read_kreg32(dd, kr_scratch);
4370 #define _PORT_VIRT_FLAG 0x8000U /* "virtual", need adjustments */
4371 #define _PORT_64BIT_FLAG 0x10000U /* not "virtual", but 64bit */
4372 #define _PORT_CNTR_IDXMASK 0x7fffU /* mask off flags above */
4375 * qib_portcntr_7322 - read a per-port chip counter
4376 * @ppd: the qlogic_ib pport
4377 * @creg: the counter to read (not a chip offset)
4379 static u64 qib_portcntr_7322(struct qib_pportdata *ppd, u32 reg)
4381 struct qib_devdata *dd = ppd->dd;
4382 u64 ret = 0ULL;
4383 u16 creg;
4384 /* 0xffff for unimplemented or synthesized counters */
4385 static const u32 xlator[] = {
4386 [QIBPORTCNTR_PKTSEND] = crp_pktsend | _PORT_64BIT_FLAG,
4387 [QIBPORTCNTR_WORDSEND] = crp_wordsend | _PORT_64BIT_FLAG,
4388 [QIBPORTCNTR_PSXMITDATA] = crp_psxmitdatacount,
4389 [QIBPORTCNTR_PSXMITPKTS] = crp_psxmitpktscount,
4390 [QIBPORTCNTR_PSXMITWAIT] = crp_psxmitwaitcount,
4391 [QIBPORTCNTR_SENDSTALL] = crp_sendstall,
4392 [QIBPORTCNTR_PKTRCV] = crp_pktrcv | _PORT_64BIT_FLAG,
4393 [QIBPORTCNTR_PSRCVDATA] = crp_psrcvdatacount,
4394 [QIBPORTCNTR_PSRCVPKTS] = crp_psrcvpktscount,
4395 [QIBPORTCNTR_RCVEBP] = crp_rcvebp,
4396 [QIBPORTCNTR_RCVOVFL] = crp_rcvovfl,
4397 [QIBPORTCNTR_WORDRCV] = crp_wordrcv | _PORT_64BIT_FLAG,
4398 [QIBPORTCNTR_RXDROPPKT] = 0xffff, /* not needed for 7322 */
4399 [QIBPORTCNTR_RXLOCALPHYERR] = crp_rxotherlocalphyerr,
4400 [QIBPORTCNTR_RXVLERR] = crp_rxvlerr,
4401 [QIBPORTCNTR_ERRICRC] = crp_erricrc,
4402 [QIBPORTCNTR_ERRVCRC] = crp_errvcrc,
4403 [QIBPORTCNTR_ERRLPCRC] = crp_errlpcrc,
4404 [QIBPORTCNTR_BADFORMAT] = crp_badformat,
4405 [QIBPORTCNTR_ERR_RLEN] = crp_err_rlen,
4406 [QIBPORTCNTR_IBSYMBOLERR] = crp_ibsymbolerr,
4407 [QIBPORTCNTR_INVALIDRLEN] = crp_invalidrlen,
4408 [QIBPORTCNTR_UNSUPVL] = crp_txunsupvl,
4409 [QIBPORTCNTR_EXCESSBUFOVFL] = crp_excessbufferovfl,
4410 [QIBPORTCNTR_ERRLINK] = crp_errlink,
4411 [QIBPORTCNTR_IBLINKDOWN] = crp_iblinkdown,
4412 [QIBPORTCNTR_IBLINKERRRECOV] = crp_iblinkerrrecov,
4413 [QIBPORTCNTR_LLI] = crp_locallinkintegrityerr,
4414 [QIBPORTCNTR_VL15PKTDROP] = crp_vl15droppedpkt,
4415 [QIBPORTCNTR_ERRPKEY] = crp_errpkey,
4417 * the next 3 aren't really counters, but were implemented
4418 * as counters in older chips, so still get accessed as
4419 * though they were counters from this code.
4421 [QIBPORTCNTR_PSINTERVAL] = krp_psinterval,
4422 [QIBPORTCNTR_PSSTART] = krp_psstart,
4423 [QIBPORTCNTR_PSSTAT] = krp_psstat,
4424 /* pseudo-counter, summed for all ports */
4425 [QIBPORTCNTR_KHDROVFL] = 0xffff,
4428 if (reg >= ARRAY_SIZE(xlator)) {
4429 qib_devinfo(ppd->dd->pcidev,
4430 "Unimplemented portcounter %u\n", reg);
4431 goto done;
4433 creg = xlator[reg] & _PORT_CNTR_IDXMASK;
4435 /* handle non-counters and special cases first */
4436 if (reg == QIBPORTCNTR_KHDROVFL) {
4437 int i;
4439 /* sum over all kernel contexts (skip if mini_init) */
4440 for (i = 0; dd->rcd && i < dd->first_user_ctxt; i++) {
4441 struct qib_ctxtdata *rcd = dd->rcd[i];
4443 if (!rcd || rcd->ppd != ppd)
4444 continue;
4445 ret += read_7322_creg32(dd, cr_base_egrovfl + i);
4447 goto done;
4448 } else if (reg == QIBPORTCNTR_RXDROPPKT) {
4450 * Used as part of the synthesis of port_rcv_errors
4451 * in the verbs code for IBTA counters. Not needed for 7322,
4452 * because all the errors are already counted by other cntrs.
4454 goto done;
4455 } else if (reg == QIBPORTCNTR_PSINTERVAL ||
4456 reg == QIBPORTCNTR_PSSTART || reg == QIBPORTCNTR_PSSTAT) {
4457 /* were counters in older chips, now per-port kernel regs */
4458 ret = qib_read_kreg_port(ppd, creg);
4459 goto done;
4463 * Only fast increment counters are 64 bits; use 32 bit reads to
4464 * avoid two independent reads when on Opteron.
4466 if (xlator[reg] & _PORT_64BIT_FLAG)
4467 ret = read_7322_creg_port(ppd, creg);
4468 else
4469 ret = read_7322_creg32_port(ppd, creg);
4470 if (creg == crp_ibsymbolerr) {
4471 if (ppd->cpspec->ibdeltainprog)
4472 ret -= ret - ppd->cpspec->ibsymsnap;
4473 ret -= ppd->cpspec->ibsymdelta;
4474 } else if (creg == crp_iblinkerrrecov) {
4475 if (ppd->cpspec->ibdeltainprog)
4476 ret -= ret - ppd->cpspec->iblnkerrsnap;
4477 ret -= ppd->cpspec->iblnkerrdelta;
4478 } else if (creg == crp_errlink)
4479 ret -= ppd->cpspec->ibmalfdelta;
4480 else if (creg == crp_iblinkdown)
4481 ret += ppd->cpspec->iblnkdowndelta;
4482 done:
4483 return ret;
4487 * Device counter names (not port-specific), one line per stat,
4488 * single string. Used by utilities like ipathstats to print the stats
4489 * in a way which works for different versions of drivers, without changing
4490 * the utility. Names need to be 12 chars or less (w/o newline), for proper
4491 * display by utility.
4492 * Non-error counters are first.
4493 * Start of "error" conters is indicated by a leading "E " on the first
4494 * "error" counter, and doesn't count in label length.
4495 * The EgrOvfl list needs to be last so we truncate them at the configured
4496 * context count for the device.
4497 * cntr7322indices contains the corresponding register indices.
4499 static const char cntr7322names[] =
4500 "Interrupts\n"
4501 "HostBusStall\n"
4502 "E RxTIDFull\n"
4503 "RxTIDInvalid\n"
4504 "RxTIDFloDrop\n" /* 7322 only */
4505 "Ctxt0EgrOvfl\n"
4506 "Ctxt1EgrOvfl\n"
4507 "Ctxt2EgrOvfl\n"
4508 "Ctxt3EgrOvfl\n"
4509 "Ctxt4EgrOvfl\n"
4510 "Ctxt5EgrOvfl\n"
4511 "Ctxt6EgrOvfl\n"
4512 "Ctxt7EgrOvfl\n"
4513 "Ctxt8EgrOvfl\n"
4514 "Ctxt9EgrOvfl\n"
4515 "Ctx10EgrOvfl\n"
4516 "Ctx11EgrOvfl\n"
4517 "Ctx12EgrOvfl\n"
4518 "Ctx13EgrOvfl\n"
4519 "Ctx14EgrOvfl\n"
4520 "Ctx15EgrOvfl\n"
4521 "Ctx16EgrOvfl\n"
4522 "Ctx17EgrOvfl\n"
4525 static const u32 cntr7322indices[] = {
4526 cr_lbint | _PORT_64BIT_FLAG,
4527 cr_lbstall | _PORT_64BIT_FLAG,
4528 cr_tidfull,
4529 cr_tidinvalid,
4530 cr_rxtidflowdrop,
4531 cr_base_egrovfl + 0,
4532 cr_base_egrovfl + 1,
4533 cr_base_egrovfl + 2,
4534 cr_base_egrovfl + 3,
4535 cr_base_egrovfl + 4,
4536 cr_base_egrovfl + 5,
4537 cr_base_egrovfl + 6,
4538 cr_base_egrovfl + 7,
4539 cr_base_egrovfl + 8,
4540 cr_base_egrovfl + 9,
4541 cr_base_egrovfl + 10,
4542 cr_base_egrovfl + 11,
4543 cr_base_egrovfl + 12,
4544 cr_base_egrovfl + 13,
4545 cr_base_egrovfl + 14,
4546 cr_base_egrovfl + 15,
4547 cr_base_egrovfl + 16,
4548 cr_base_egrovfl + 17,
4552 * same as cntr7322names and cntr7322indices, but for port-specific counters.
4553 * portcntr7322indices is somewhat complicated by some registers needing
4554 * adjustments of various kinds, and those are ORed with _PORT_VIRT_FLAG
4556 static const char portcntr7322names[] =
4557 "TxPkt\n"
4558 "TxFlowPkt\n"
4559 "TxWords\n"
4560 "RxPkt\n"
4561 "RxFlowPkt\n"
4562 "RxWords\n"
4563 "TxFlowStall\n"
4564 "TxDmaDesc\n" /* 7220 and 7322-only */
4565 "E RxDlidFltr\n" /* 7220 and 7322-only */
4566 "IBStatusChng\n"
4567 "IBLinkDown\n"
4568 "IBLnkRecov\n"
4569 "IBRxLinkErr\n"
4570 "IBSymbolErr\n"
4571 "RxLLIErr\n"
4572 "RxBadFormat\n"
4573 "RxBadLen\n"
4574 "RxBufOvrfl\n"
4575 "RxEBP\n"
4576 "RxFlowCtlErr\n"
4577 "RxICRCerr\n"
4578 "RxLPCRCerr\n"
4579 "RxVCRCerr\n"
4580 "RxInvalLen\n"
4581 "RxInvalPKey\n"
4582 "RxPktDropped\n"
4583 "TxBadLength\n"
4584 "TxDropped\n"
4585 "TxInvalLen\n"
4586 "TxUnderrun\n"
4587 "TxUnsupVL\n"
4588 "RxLclPhyErr\n" /* 7220 and 7322-only from here down */
4589 "RxVL15Drop\n"
4590 "RxVlErr\n"
4591 "XcessBufOvfl\n"
4592 "RxQPBadCtxt\n" /* 7322-only from here down */
4593 "TXBadHeader\n"
4596 static const u32 portcntr7322indices[] = {
4597 QIBPORTCNTR_PKTSEND | _PORT_VIRT_FLAG,
4598 crp_pktsendflow,
4599 QIBPORTCNTR_WORDSEND | _PORT_VIRT_FLAG,
4600 QIBPORTCNTR_PKTRCV | _PORT_VIRT_FLAG,
4601 crp_pktrcvflowctrl,
4602 QIBPORTCNTR_WORDRCV | _PORT_VIRT_FLAG,
4603 QIBPORTCNTR_SENDSTALL | _PORT_VIRT_FLAG,
4604 crp_txsdmadesc | _PORT_64BIT_FLAG,
4605 crp_rxdlidfltr,
4606 crp_ibstatuschange,
4607 QIBPORTCNTR_IBLINKDOWN | _PORT_VIRT_FLAG,
4608 QIBPORTCNTR_IBLINKERRRECOV | _PORT_VIRT_FLAG,
4609 QIBPORTCNTR_ERRLINK | _PORT_VIRT_FLAG,
4610 QIBPORTCNTR_IBSYMBOLERR | _PORT_VIRT_FLAG,
4611 QIBPORTCNTR_LLI | _PORT_VIRT_FLAG,
4612 QIBPORTCNTR_BADFORMAT | _PORT_VIRT_FLAG,
4613 QIBPORTCNTR_ERR_RLEN | _PORT_VIRT_FLAG,
4614 QIBPORTCNTR_RCVOVFL | _PORT_VIRT_FLAG,
4615 QIBPORTCNTR_RCVEBP | _PORT_VIRT_FLAG,
4616 crp_rcvflowctrlviol,
4617 QIBPORTCNTR_ERRICRC | _PORT_VIRT_FLAG,
4618 QIBPORTCNTR_ERRLPCRC | _PORT_VIRT_FLAG,
4619 QIBPORTCNTR_ERRVCRC | _PORT_VIRT_FLAG,
4620 QIBPORTCNTR_INVALIDRLEN | _PORT_VIRT_FLAG,
4621 QIBPORTCNTR_ERRPKEY | _PORT_VIRT_FLAG,
4622 QIBPORTCNTR_RXDROPPKT | _PORT_VIRT_FLAG,
4623 crp_txminmaxlenerr,
4624 crp_txdroppedpkt,
4625 crp_txlenerr,
4626 crp_txunderrun,
4627 crp_txunsupvl,
4628 QIBPORTCNTR_RXLOCALPHYERR | _PORT_VIRT_FLAG,
4629 QIBPORTCNTR_VL15PKTDROP | _PORT_VIRT_FLAG,
4630 QIBPORTCNTR_RXVLERR | _PORT_VIRT_FLAG,
4631 QIBPORTCNTR_EXCESSBUFOVFL | _PORT_VIRT_FLAG,
4632 crp_rxqpinvalidctxt,
4633 crp_txhdrerr,
4636 /* do all the setup to make the counter reads efficient later */
4637 static void init_7322_cntrnames(struct qib_devdata *dd)
4639 int i, j = 0;
4640 char *s;
4642 for (i = 0, s = (char *)cntr7322names; s && j <= dd->cfgctxts;
4643 i++) {
4644 /* we always have at least one counter before the egrovfl */
4645 if (!j && !strncmp("Ctxt0EgrOvfl", s + 1, 12))
4646 j = 1;
4647 s = strchr(s + 1, '\n');
4648 if (s && j)
4649 j++;
4651 dd->cspec->ncntrs = i;
4652 if (!s)
4653 /* full list; size is without terminating null */
4654 dd->cspec->cntrnamelen = sizeof(cntr7322names) - 1;
4655 else
4656 dd->cspec->cntrnamelen = 1 + s - cntr7322names;
4657 dd->cspec->cntrs = kmalloc(dd->cspec->ncntrs
4658 * sizeof(u64), GFP_KERNEL);
4659 if (!dd->cspec->cntrs)
4660 qib_dev_err(dd, "Failed allocation for counters\n");
4662 for (i = 0, s = (char *)portcntr7322names; s; i++)
4663 s = strchr(s + 1, '\n');
4664 dd->cspec->nportcntrs = i - 1;
4665 dd->cspec->portcntrnamelen = sizeof(portcntr7322names) - 1;
4666 for (i = 0; i < dd->num_pports; ++i) {
4667 dd->pport[i].cpspec->portcntrs = kmalloc(dd->cspec->nportcntrs
4668 * sizeof(u64), GFP_KERNEL);
4669 if (!dd->pport[i].cpspec->portcntrs)
4670 qib_dev_err(dd, "Failed allocation for"
4671 " portcounters\n");
4675 static u32 qib_read_7322cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
4676 u64 **cntrp)
4678 u32 ret;
4680 if (namep) {
4681 ret = dd->cspec->cntrnamelen;
4682 if (pos >= ret)
4683 ret = 0; /* final read after getting everything */
4684 else
4685 *namep = (char *) cntr7322names;
4686 } else {
4687 u64 *cntr = dd->cspec->cntrs;
4688 int i;
4690 ret = dd->cspec->ncntrs * sizeof(u64);
4691 if (!cntr || pos >= ret) {
4692 /* everything read, or couldn't get memory */
4693 ret = 0;
4694 goto done;
4696 *cntrp = cntr;
4697 for (i = 0; i < dd->cspec->ncntrs; i++)
4698 if (cntr7322indices[i] & _PORT_64BIT_FLAG)
4699 *cntr++ = read_7322_creg(dd,
4700 cntr7322indices[i] &
4701 _PORT_CNTR_IDXMASK);
4702 else
4703 *cntr++ = read_7322_creg32(dd,
4704 cntr7322indices[i]);
4706 done:
4707 return ret;
4710 static u32 qib_read_7322portcntrs(struct qib_devdata *dd, loff_t pos, u32 port,
4711 char **namep, u64 **cntrp)
4713 u32 ret;
4715 if (namep) {
4716 ret = dd->cspec->portcntrnamelen;
4717 if (pos >= ret)
4718 ret = 0; /* final read after getting everything */
4719 else
4720 *namep = (char *)portcntr7322names;
4721 } else {
4722 struct qib_pportdata *ppd = &dd->pport[port];
4723 u64 *cntr = ppd->cpspec->portcntrs;
4724 int i;
4726 ret = dd->cspec->nportcntrs * sizeof(u64);
4727 if (!cntr || pos >= ret) {
4728 /* everything read, or couldn't get memory */
4729 ret = 0;
4730 goto done;
4732 *cntrp = cntr;
4733 for (i = 0; i < dd->cspec->nportcntrs; i++) {
4734 if (portcntr7322indices[i] & _PORT_VIRT_FLAG)
4735 *cntr++ = qib_portcntr_7322(ppd,
4736 portcntr7322indices[i] &
4737 _PORT_CNTR_IDXMASK);
4738 else if (portcntr7322indices[i] & _PORT_64BIT_FLAG)
4739 *cntr++ = read_7322_creg_port(ppd,
4740 portcntr7322indices[i] &
4741 _PORT_CNTR_IDXMASK);
4742 else
4743 *cntr++ = read_7322_creg32_port(ppd,
4744 portcntr7322indices[i]);
4747 done:
4748 return ret;
4752 * qib_get_7322_faststats - get word counters from chip before they overflow
4753 * @opaque - contains a pointer to the qlogic_ib device qib_devdata
4755 * VESTIGIAL IBA7322 has no "small fast counters", so the only
4756 * real purpose of this function is to maintain the notion of
4757 * "active time", which in turn is only logged into the eeprom,
4758 * which we don;t have, yet, for 7322-based boards.
4760 * called from add_timer
4762 static void qib_get_7322_faststats(unsigned long opaque)
4764 struct qib_devdata *dd = (struct qib_devdata *) opaque;
4765 struct qib_pportdata *ppd;
4766 unsigned long flags;
4767 u64 traffic_wds;
4768 int pidx;
4770 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
4771 ppd = dd->pport + pidx;
4774 * If port isn't enabled or not operational ports, or
4775 * diags is running (can cause memory diags to fail)
4776 * skip this port this time.
4778 if (!ppd->link_speed_supported || !(dd->flags & QIB_INITTED)
4779 || dd->diag_client)
4780 continue;
4783 * Maintain an activity timer, based on traffic
4784 * exceeding a threshold, so we need to check the word-counts
4785 * even if they are 64-bit.
4787 traffic_wds = qib_portcntr_7322(ppd, QIBPORTCNTR_WORDRCV) +
4788 qib_portcntr_7322(ppd, QIBPORTCNTR_WORDSEND);
4789 spin_lock_irqsave(&ppd->dd->eep_st_lock, flags);
4790 traffic_wds -= ppd->dd->traffic_wds;
4791 ppd->dd->traffic_wds += traffic_wds;
4792 if (traffic_wds >= QIB_TRAFFIC_ACTIVE_THRESHOLD)
4793 atomic_add(ACTIVITY_TIMER, &ppd->dd->active_time);
4794 spin_unlock_irqrestore(&ppd->dd->eep_st_lock, flags);
4795 if (ppd->cpspec->qdr_dfe_on && (ppd->link_speed_active &
4796 QIB_IB_QDR) &&
4797 (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
4798 QIBL_LINKACTIVE)) &&
4799 ppd->cpspec->qdr_dfe_time &&
4800 time_after64(get_jiffies_64(), ppd->cpspec->qdr_dfe_time)) {
4801 ppd->cpspec->qdr_dfe_on = 0;
4803 qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
4804 ppd->dd->cspec->r1 ?
4805 QDR_STATIC_ADAPT_INIT_R1 :
4806 QDR_STATIC_ADAPT_INIT);
4807 force_h1(ppd);
4810 mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);
4814 * If we were using MSIx, try to fallback to INTx.
4816 static int qib_7322_intr_fallback(struct qib_devdata *dd)
4818 if (!dd->cspec->num_msix_entries)
4819 return 0; /* already using INTx */
4821 qib_devinfo(dd->pcidev, "MSIx interrupt not detected,"
4822 " trying INTx interrupts\n");
4823 qib_7322_nomsix(dd);
4824 qib_enable_intx(dd->pcidev);
4825 qib_setup_7322_interrupt(dd, 0);
4826 return 1;
4830 * Reset the XGXS (between serdes and IBC). Slightly less intrusive
4831 * than resetting the IBC or external link state, and useful in some
4832 * cases to cause some retraining. To do this right, we reset IBC
4833 * as well, then return to previous state (which may be still in reset)
4834 * NOTE: some callers of this "know" this writes the current value
4835 * of cpspec->ibcctrl_a as part of it's operation, so if that changes,
4836 * check all callers.
4838 static void qib_7322_mini_pcs_reset(struct qib_pportdata *ppd)
4840 u64 val;
4841 struct qib_devdata *dd = ppd->dd;
4842 const u64 reset_bits = SYM_MASK(IBPCSConfig_0, xcv_rreset) |
4843 SYM_MASK(IBPCSConfig_0, xcv_treset) |
4844 SYM_MASK(IBPCSConfig_0, tx_rx_reset);
4846 val = qib_read_kreg_port(ppd, krp_ib_pcsconfig);
4847 qib_write_kreg(dd, kr_hwerrmask,
4848 dd->cspec->hwerrmask & ~HWE_MASK(statusValidNoEop));
4849 qib_write_kreg_port(ppd, krp_ibcctrl_a,
4850 ppd->cpspec->ibcctrl_a &
4851 ~SYM_MASK(IBCCtrlA_0, IBLinkEn));
4853 qib_write_kreg_port(ppd, krp_ib_pcsconfig, val | reset_bits);
4854 qib_read_kreg32(dd, kr_scratch);
4855 qib_write_kreg_port(ppd, krp_ib_pcsconfig, val & ~reset_bits);
4856 qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
4857 qib_write_kreg(dd, kr_scratch, 0ULL);
4858 qib_write_kreg(dd, kr_hwerrclear,
4859 SYM_MASK(HwErrClear, statusValidNoEopClear));
4860 qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
4864 * This code for non-IBTA-compliant IB speed negotiation is only known to
4865 * work for the SDR to DDR transition, and only between an HCA and a switch
4866 * with recent firmware. It is based on observed heuristics, rather than
4867 * actual knowledge of the non-compliant speed negotiation.
4868 * It has a number of hard-coded fields, since the hope is to rewrite this
4869 * when a spec is available on how the negoation is intended to work.
4871 static void autoneg_7322_sendpkt(struct qib_pportdata *ppd, u32 *hdr,
4872 u32 dcnt, u32 *data)
4874 int i;
4875 u64 pbc;
4876 u32 __iomem *piobuf;
4877 u32 pnum, control, len;
4878 struct qib_devdata *dd = ppd->dd;
4880 i = 0;
4881 len = 7 + dcnt + 1; /* 7 dword header, dword data, icrc */
4882 control = qib_7322_setpbc_control(ppd, len, 0, 15);
4883 pbc = ((u64) control << 32) | len;
4884 while (!(piobuf = qib_7322_getsendbuf(ppd, pbc, &pnum))) {
4885 if (i++ > 15)
4886 return;
4887 udelay(2);
4889 /* disable header check on this packet, since it can't be valid */
4890 dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_DIS1, NULL);
4891 writeq(pbc, piobuf);
4892 qib_flush_wc();
4893 qib_pio_copy(piobuf + 2, hdr, 7);
4894 qib_pio_copy(piobuf + 9, data, dcnt);
4895 if (dd->flags & QIB_USE_SPCL_TRIG) {
4896 u32 spcl_off = (pnum >= dd->piobcnt2k) ? 2047 : 1023;
4898 qib_flush_wc();
4899 __raw_writel(0xaebecede, piobuf + spcl_off);
4901 qib_flush_wc();
4902 qib_sendbuf_done(dd, pnum);
4903 /* and re-enable hdr check */
4904 dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_ENAB1, NULL);
4908 * _start packet gets sent twice at start, _done gets sent twice at end
4910 static void qib_autoneg_7322_send(struct qib_pportdata *ppd, int which)
4912 struct qib_devdata *dd = ppd->dd;
4913 static u32 swapped;
4914 u32 dw, i, hcnt, dcnt, *data;
4915 static u32 hdr[7] = { 0xf002ffff, 0x48ffff, 0x6400abba };
4916 static u32 madpayload_start[0x40] = {
4917 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
4918 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
4919 0x1, 0x1388, 0x15e, 0x1, /* rest 0's */
4921 static u32 madpayload_done[0x40] = {
4922 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
4923 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
4924 0x40000001, 0x1388, 0x15e, /* rest 0's */
4927 dcnt = ARRAY_SIZE(madpayload_start);
4928 hcnt = ARRAY_SIZE(hdr);
4929 if (!swapped) {
4930 /* for maintainability, do it at runtime */
4931 for (i = 0; i < hcnt; i++) {
4932 dw = (__force u32) cpu_to_be32(hdr[i]);
4933 hdr[i] = dw;
4935 for (i = 0; i < dcnt; i++) {
4936 dw = (__force u32) cpu_to_be32(madpayload_start[i]);
4937 madpayload_start[i] = dw;
4938 dw = (__force u32) cpu_to_be32(madpayload_done[i]);
4939 madpayload_done[i] = dw;
4941 swapped = 1;
4944 data = which ? madpayload_done : madpayload_start;
4946 autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
4947 qib_read_kreg64(dd, kr_scratch);
4948 udelay(2);
4949 autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
4950 qib_read_kreg64(dd, kr_scratch);
4951 udelay(2);
4955 * Do the absolute minimum to cause an IB speed change, and make it
4956 * ready, but don't actually trigger the change. The caller will
4957 * do that when ready (if link is in Polling training state, it will
4958 * happen immediately, otherwise when link next goes down)
4960 * This routine should only be used as part of the DDR autonegotation
4961 * code for devices that are not compliant with IB 1.2 (or code that
4962 * fixes things up for same).
4964 * When link has gone down, and autoneg enabled, or autoneg has
4965 * failed and we give up until next time we set both speeds, and
4966 * then we want IBTA enabled as well as "use max enabled speed.
4968 static void set_7322_ibspeed_fast(struct qib_pportdata *ppd, u32 speed)
4970 u64 newctrlb;
4971 newctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_SPEED_MASK |
4972 IBA7322_IBC_IBTA_1_2_MASK |
4973 IBA7322_IBC_MAX_SPEED_MASK);
4975 if (speed & (speed - 1)) /* multiple speeds */
4976 newctrlb |= (speed << IBA7322_IBC_SPEED_LSB) |
4977 IBA7322_IBC_IBTA_1_2_MASK |
4978 IBA7322_IBC_MAX_SPEED_MASK;
4979 else
4980 newctrlb |= speed == QIB_IB_QDR ?
4981 IBA7322_IBC_SPEED_QDR | IBA7322_IBC_IBTA_1_2_MASK :
4982 ((speed == QIB_IB_DDR ?
4983 IBA7322_IBC_SPEED_DDR : IBA7322_IBC_SPEED_SDR));
4985 if (newctrlb == ppd->cpspec->ibcctrl_b)
4986 return;
4988 ppd->cpspec->ibcctrl_b = newctrlb;
4989 qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
4990 qib_write_kreg(ppd->dd, kr_scratch, 0);
4994 * This routine is only used when we are not talking to another
4995 * IB 1.2-compliant device that we think can do DDR.
4996 * (This includes all existing switch chips as of Oct 2007.)
4997 * 1.2-compliant devices go directly to DDR prior to reaching INIT
4999 static void try_7322_autoneg(struct qib_pportdata *ppd)
5001 unsigned long flags;
5003 spin_lock_irqsave(&ppd->lflags_lock, flags);
5004 ppd->lflags |= QIBL_IB_AUTONEG_INPROG;
5005 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5006 qib_autoneg_7322_send(ppd, 0);
5007 set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
5008 qib_7322_mini_pcs_reset(ppd);
5009 /* 2 msec is minimum length of a poll cycle */
5010 queue_delayed_work(ib_wq, &ppd->cpspec->autoneg_work,
5011 msecs_to_jiffies(2));
5015 * Handle the empirically determined mechanism for auto-negotiation
5016 * of DDR speed with switches.
5018 static void autoneg_7322_work(struct work_struct *work)
5020 struct qib_pportdata *ppd;
5021 struct qib_devdata *dd;
5022 u64 startms;
5023 u32 i;
5024 unsigned long flags;
5026 ppd = container_of(work, struct qib_chippport_specific,
5027 autoneg_work.work)->ppd;
5028 dd = ppd->dd;
5030 startms = jiffies_to_msecs(jiffies);
5033 * Busy wait for this first part, it should be at most a
5034 * few hundred usec, since we scheduled ourselves for 2msec.
5036 for (i = 0; i < 25; i++) {
5037 if (SYM_FIELD(ppd->lastibcstat, IBCStatusA_0, LinkState)
5038 == IB_7322_LT_STATE_POLLQUIET) {
5039 qib_set_linkstate(ppd, QIB_IB_LINKDOWN_DISABLE);
5040 break;
5042 udelay(100);
5045 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
5046 goto done; /* we got there early or told to stop */
5048 /* we expect this to timeout */
5049 if (wait_event_timeout(ppd->cpspec->autoneg_wait,
5050 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
5051 msecs_to_jiffies(90)))
5052 goto done;
5053 qib_7322_mini_pcs_reset(ppd);
5055 /* we expect this to timeout */
5056 if (wait_event_timeout(ppd->cpspec->autoneg_wait,
5057 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
5058 msecs_to_jiffies(1700)))
5059 goto done;
5060 qib_7322_mini_pcs_reset(ppd);
5062 set_7322_ibspeed_fast(ppd, QIB_IB_SDR);
5065 * Wait up to 250 msec for link to train and get to INIT at DDR;
5066 * this should terminate early.
5068 wait_event_timeout(ppd->cpspec->autoneg_wait,
5069 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
5070 msecs_to_jiffies(250));
5071 done:
5072 if (ppd->lflags & QIBL_IB_AUTONEG_INPROG) {
5073 spin_lock_irqsave(&ppd->lflags_lock, flags);
5074 ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
5075 if (ppd->cpspec->autoneg_tries == AUTONEG_TRIES) {
5076 ppd->lflags |= QIBL_IB_AUTONEG_FAILED;
5077 ppd->cpspec->autoneg_tries = 0;
5079 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5080 set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
5085 * This routine is used to request IPG set in the QLogic switch.
5086 * Only called if r1.
5088 static void try_7322_ipg(struct qib_pportdata *ppd)
5090 struct qib_ibport *ibp = &ppd->ibport_data;
5091 struct ib_mad_send_buf *send_buf;
5092 struct ib_mad_agent *agent;
5093 struct ib_smp *smp;
5094 unsigned delay;
5095 int ret;
5097 agent = ibp->send_agent;
5098 if (!agent)
5099 goto retry;
5101 send_buf = ib_create_send_mad(agent, 0, 0, 0, IB_MGMT_MAD_HDR,
5102 IB_MGMT_MAD_DATA, GFP_ATOMIC);
5103 if (IS_ERR(send_buf))
5104 goto retry;
5106 if (!ibp->smi_ah) {
5107 struct ib_ah_attr attr;
5108 struct ib_ah *ah;
5110 memset(&attr, 0, sizeof attr);
5111 attr.dlid = be16_to_cpu(IB_LID_PERMISSIVE);
5112 attr.port_num = ppd->port;
5113 ah = ib_create_ah(ibp->qp0->ibqp.pd, &attr);
5114 if (IS_ERR(ah))
5115 ret = -EINVAL;
5116 else {
5117 send_buf->ah = ah;
5118 ibp->smi_ah = to_iah(ah);
5119 ret = 0;
5121 } else {
5122 send_buf->ah = &ibp->smi_ah->ibah;
5123 ret = 0;
5126 smp = send_buf->mad;
5127 smp->base_version = IB_MGMT_BASE_VERSION;
5128 smp->mgmt_class = IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE;
5129 smp->class_version = 1;
5130 smp->method = IB_MGMT_METHOD_SEND;
5131 smp->hop_cnt = 1;
5132 smp->attr_id = QIB_VENDOR_IPG;
5133 smp->attr_mod = 0;
5135 if (!ret)
5136 ret = ib_post_send_mad(send_buf, NULL);
5137 if (ret)
5138 ib_free_send_mad(send_buf);
5139 retry:
5140 delay = 2 << ppd->cpspec->ipg_tries;
5141 queue_delayed_work(ib_wq, &ppd->cpspec->ipg_work,
5142 msecs_to_jiffies(delay));
5146 * Timeout handler for setting IPG.
5147 * Only called if r1.
5149 static void ipg_7322_work(struct work_struct *work)
5151 struct qib_pportdata *ppd;
5153 ppd = container_of(work, struct qib_chippport_specific,
5154 ipg_work.work)->ppd;
5155 if ((ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED | QIBL_LINKACTIVE))
5156 && ++ppd->cpspec->ipg_tries <= 10)
5157 try_7322_ipg(ppd);
5160 static u32 qib_7322_iblink_state(u64 ibcs)
5162 u32 state = (u32)SYM_FIELD(ibcs, IBCStatusA_0, LinkState);
5164 switch (state) {
5165 case IB_7322_L_STATE_INIT:
5166 state = IB_PORT_INIT;
5167 break;
5168 case IB_7322_L_STATE_ARM:
5169 state = IB_PORT_ARMED;
5170 break;
5171 case IB_7322_L_STATE_ACTIVE:
5172 /* fall through */
5173 case IB_7322_L_STATE_ACT_DEFER:
5174 state = IB_PORT_ACTIVE;
5175 break;
5176 default: /* fall through */
5177 case IB_7322_L_STATE_DOWN:
5178 state = IB_PORT_DOWN;
5179 break;
5181 return state;
5184 /* returns the IBTA port state, rather than the IBC link training state */
5185 static u8 qib_7322_phys_portstate(u64 ibcs)
5187 u8 state = (u8)SYM_FIELD(ibcs, IBCStatusA_0, LinkTrainingState);
5188 return qib_7322_physportstate[state];
5191 static int qib_7322_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
5193 int ret = 0, symadj = 0;
5194 unsigned long flags;
5195 int mult;
5197 spin_lock_irqsave(&ppd->lflags_lock, flags);
5198 ppd->lflags &= ~QIBL_IB_FORCE_NOTIFY;
5199 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5201 /* Update our picture of width and speed from chip */
5202 if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedQDR)) {
5203 ppd->link_speed_active = QIB_IB_QDR;
5204 mult = 4;
5205 } else if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedActive)) {
5206 ppd->link_speed_active = QIB_IB_DDR;
5207 mult = 2;
5208 } else {
5209 ppd->link_speed_active = QIB_IB_SDR;
5210 mult = 1;
5212 if (ibcs & SYM_MASK(IBCStatusA_0, LinkWidthActive)) {
5213 ppd->link_width_active = IB_WIDTH_4X;
5214 mult *= 4;
5215 } else
5216 ppd->link_width_active = IB_WIDTH_1X;
5217 ppd->delay_mult = ib_rate_to_delay[mult_to_ib_rate(mult)];
5219 if (!ibup) {
5220 u64 clr;
5222 /* Link went down. */
5223 /* do IPG MAD again after linkdown, even if last time failed */
5224 ppd->cpspec->ipg_tries = 0;
5225 clr = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
5226 (SYM_MASK(IBCStatusB_0, heartbeat_timed_out) |
5227 SYM_MASK(IBCStatusB_0, heartbeat_crosstalk));
5228 if (clr)
5229 qib_write_kreg_port(ppd, krp_ibcstatus_b, clr);
5230 if (!(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
5231 QIBL_IB_AUTONEG_INPROG)))
5232 set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
5233 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
5234 /* unlock the Tx settings, speed may change */
5235 qib_write_kreg_port(ppd, krp_tx_deemph_override,
5236 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
5237 reset_tx_deemphasis_override));
5238 qib_cancel_sends(ppd);
5239 /* on link down, ensure sane pcs state */
5240 qib_7322_mini_pcs_reset(ppd);
5241 spin_lock_irqsave(&ppd->sdma_lock, flags);
5242 if (__qib_sdma_running(ppd))
5243 __qib_sdma_process_event(ppd,
5244 qib_sdma_event_e70_go_idle);
5245 spin_unlock_irqrestore(&ppd->sdma_lock, flags);
5247 clr = read_7322_creg32_port(ppd, crp_iblinkdown);
5248 if (clr == ppd->cpspec->iblnkdownsnap)
5249 ppd->cpspec->iblnkdowndelta++;
5250 } else {
5251 if (qib_compat_ddr_negotiate &&
5252 !(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
5253 QIBL_IB_AUTONEG_INPROG)) &&
5254 ppd->link_speed_active == QIB_IB_SDR &&
5255 (ppd->link_speed_enabled & QIB_IB_DDR)
5256 && ppd->cpspec->autoneg_tries < AUTONEG_TRIES) {
5257 /* we are SDR, and auto-negotiation enabled */
5258 ++ppd->cpspec->autoneg_tries;
5259 if (!ppd->cpspec->ibdeltainprog) {
5260 ppd->cpspec->ibdeltainprog = 1;
5261 ppd->cpspec->ibsymdelta +=
5262 read_7322_creg32_port(ppd,
5263 crp_ibsymbolerr) -
5264 ppd->cpspec->ibsymsnap;
5265 ppd->cpspec->iblnkerrdelta +=
5266 read_7322_creg32_port(ppd,
5267 crp_iblinkerrrecov) -
5268 ppd->cpspec->iblnkerrsnap;
5270 try_7322_autoneg(ppd);
5271 ret = 1; /* no other IB status change processing */
5272 } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
5273 ppd->link_speed_active == QIB_IB_SDR) {
5274 qib_autoneg_7322_send(ppd, 1);
5275 set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
5276 qib_7322_mini_pcs_reset(ppd);
5277 udelay(2);
5278 ret = 1; /* no other IB status change processing */
5279 } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
5280 (ppd->link_speed_active & QIB_IB_DDR)) {
5281 spin_lock_irqsave(&ppd->lflags_lock, flags);
5282 ppd->lflags &= ~(QIBL_IB_AUTONEG_INPROG |
5283 QIBL_IB_AUTONEG_FAILED);
5284 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5285 ppd->cpspec->autoneg_tries = 0;
5286 /* re-enable SDR, for next link down */
5287 set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
5288 wake_up(&ppd->cpspec->autoneg_wait);
5289 symadj = 1;
5290 } else if (ppd->lflags & QIBL_IB_AUTONEG_FAILED) {
5292 * Clear autoneg failure flag, and do setup
5293 * so we'll try next time link goes down and
5294 * back to INIT (possibly connected to a
5295 * different device).
5297 spin_lock_irqsave(&ppd->lflags_lock, flags);
5298 ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
5299 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
5300 ppd->cpspec->ibcctrl_b |= IBA7322_IBC_IBTA_1_2_MASK;
5301 symadj = 1;
5303 if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
5304 symadj = 1;
5305 if (ppd->dd->cspec->r1 && ppd->cpspec->ipg_tries <= 10)
5306 try_7322_ipg(ppd);
5307 if (!ppd->cpspec->recovery_init)
5308 setup_7322_link_recovery(ppd, 0);
5309 ppd->cpspec->qdr_dfe_time = jiffies +
5310 msecs_to_jiffies(QDR_DFE_DISABLE_DELAY);
5312 ppd->cpspec->ibmalfusesnap = 0;
5313 ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
5314 crp_errlink);
5316 if (symadj) {
5317 ppd->cpspec->iblnkdownsnap =
5318 read_7322_creg32_port(ppd, crp_iblinkdown);
5319 if (ppd->cpspec->ibdeltainprog) {
5320 ppd->cpspec->ibdeltainprog = 0;
5321 ppd->cpspec->ibsymdelta += read_7322_creg32_port(ppd,
5322 crp_ibsymbolerr) - ppd->cpspec->ibsymsnap;
5323 ppd->cpspec->iblnkerrdelta += read_7322_creg32_port(ppd,
5324 crp_iblinkerrrecov) - ppd->cpspec->iblnkerrsnap;
5326 } else if (!ibup && qib_compat_ddr_negotiate &&
5327 !ppd->cpspec->ibdeltainprog &&
5328 !(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
5329 ppd->cpspec->ibdeltainprog = 1;
5330 ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
5331 crp_ibsymbolerr);
5332 ppd->cpspec->iblnkerrsnap = read_7322_creg32_port(ppd,
5333 crp_iblinkerrrecov);
5336 if (!ret)
5337 qib_setup_7322_setextled(ppd, ibup);
5338 return ret;
5342 * Does read/modify/write to appropriate registers to
5343 * set output and direction bits selected by mask.
5344 * these are in their canonical postions (e.g. lsb of
5345 * dir will end up in D48 of extctrl on existing chips).
5346 * returns contents of GP Inputs.
5348 static int gpio_7322_mod(struct qib_devdata *dd, u32 out, u32 dir, u32 mask)
5350 u64 read_val, new_out;
5351 unsigned long flags;
5353 if (mask) {
5354 /* some bits being written, lock access to GPIO */
5355 dir &= mask;
5356 out &= mask;
5357 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
5358 dd->cspec->extctrl &= ~((u64)mask << SYM_LSB(EXTCtrl, GPIOOe));
5359 dd->cspec->extctrl |= ((u64) dir << SYM_LSB(EXTCtrl, GPIOOe));
5360 new_out = (dd->cspec->gpio_out & ~mask) | out;
5362 qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
5363 qib_write_kreg(dd, kr_gpio_out, new_out);
5364 dd->cspec->gpio_out = new_out;
5365 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
5368 * It is unlikely that a read at this time would get valid
5369 * data on a pin whose direction line was set in the same
5370 * call to this function. We include the read here because
5371 * that allows us to potentially combine a change on one pin with
5372 * a read on another, and because the old code did something like
5373 * this.
5375 read_val = qib_read_kreg64(dd, kr_extstatus);
5376 return SYM_FIELD(read_val, EXTStatus, GPIOIn);
5379 /* Enable writes to config EEPROM, if possible. Returns previous state */
5380 static int qib_7322_eeprom_wen(struct qib_devdata *dd, int wen)
5382 int prev_wen;
5383 u32 mask;
5385 mask = 1 << QIB_EEPROM_WEN_NUM;
5386 prev_wen = ~gpio_7322_mod(dd, 0, 0, 0) >> QIB_EEPROM_WEN_NUM;
5387 gpio_7322_mod(dd, wen ? 0 : mask, mask, mask);
5389 return prev_wen & 1;
5393 * Read fundamental info we need to use the chip. These are
5394 * the registers that describe chip capabilities, and are
5395 * saved in shadow registers.
5397 static void get_7322_chip_params(struct qib_devdata *dd)
5399 u64 val;
5400 u32 piobufs;
5401 int mtu;
5403 dd->palign = qib_read_kreg32(dd, kr_pagealign);
5405 dd->uregbase = qib_read_kreg32(dd, kr_userregbase);
5407 dd->rcvtidcnt = qib_read_kreg32(dd, kr_rcvtidcnt);
5408 dd->rcvtidbase = qib_read_kreg32(dd, kr_rcvtidbase);
5409 dd->rcvegrbase = qib_read_kreg32(dd, kr_rcvegrbase);
5410 dd->piobufbase = qib_read_kreg64(dd, kr_sendpiobufbase);
5411 dd->pio2k_bufbase = dd->piobufbase & 0xffffffff;
5413 val = qib_read_kreg64(dd, kr_sendpiobufcnt);
5414 dd->piobcnt2k = val & ~0U;
5415 dd->piobcnt4k = val >> 32;
5416 val = qib_read_kreg64(dd, kr_sendpiosize);
5417 dd->piosize2k = val & ~0U;
5418 dd->piosize4k = val >> 32;
5420 mtu = ib_mtu_enum_to_int(qib_ibmtu);
5421 if (mtu == -1)
5422 mtu = QIB_DEFAULT_MTU;
5423 dd->pport[0].ibmtu = (u32)mtu;
5424 dd->pport[1].ibmtu = (u32)mtu;
5426 /* these may be adjusted in init_chip_wc_pat() */
5427 dd->pio2kbase = (u32 __iomem *)
5428 ((char __iomem *) dd->kregbase + dd->pio2k_bufbase);
5429 dd->pio4kbase = (u32 __iomem *)
5430 ((char __iomem *) dd->kregbase +
5431 (dd->piobufbase >> 32));
5433 * 4K buffers take 2 pages; we use roundup just to be
5434 * paranoid; we calculate it once here, rather than on
5435 * ever buf allocate
5437 dd->align4k = ALIGN(dd->piosize4k, dd->palign);
5439 piobufs = dd->piobcnt4k + dd->piobcnt2k + NUM_VL15_BUFS;
5441 dd->pioavregs = ALIGN(piobufs, sizeof(u64) * BITS_PER_BYTE / 2) /
5442 (sizeof(u64) * BITS_PER_BYTE / 2);
5446 * The chip base addresses in cspec and cpspec have to be set
5447 * after possible init_chip_wc_pat(), rather than in
5448 * get_7322_chip_params(), so split out as separate function
5450 static void qib_7322_set_baseaddrs(struct qib_devdata *dd)
5452 u32 cregbase;
5453 cregbase = qib_read_kreg32(dd, kr_counterregbase);
5455 dd->cspec->cregbase = (u64 __iomem *)(cregbase +
5456 (char __iomem *)dd->kregbase);
5458 dd->egrtidbase = (u64 __iomem *)
5459 ((char __iomem *) dd->kregbase + dd->rcvegrbase);
5461 /* port registers are defined as relative to base of chip */
5462 dd->pport[0].cpspec->kpregbase =
5463 (u64 __iomem *)((char __iomem *)dd->kregbase);
5464 dd->pport[1].cpspec->kpregbase =
5465 (u64 __iomem *)(dd->palign +
5466 (char __iomem *)dd->kregbase);
5467 dd->pport[0].cpspec->cpregbase =
5468 (u64 __iomem *)(qib_read_kreg_port(&dd->pport[0],
5469 kr_counterregbase) + (char __iomem *)dd->kregbase);
5470 dd->pport[1].cpspec->cpregbase =
5471 (u64 __iomem *)(qib_read_kreg_port(&dd->pport[1],
5472 kr_counterregbase) + (char __iomem *)dd->kregbase);
5476 * This is a fairly special-purpose observer, so we only support
5477 * the port-specific parts of SendCtrl
5480 #define SENDCTRL_SHADOWED (SYM_MASK(SendCtrl_0, SendEnable) | \
5481 SYM_MASK(SendCtrl_0, SDmaEnable) | \
5482 SYM_MASK(SendCtrl_0, SDmaIntEnable) | \
5483 SYM_MASK(SendCtrl_0, SDmaSingleDescriptor) | \
5484 SYM_MASK(SendCtrl_0, SDmaHalt) | \
5485 SYM_MASK(SendCtrl_0, IBVLArbiterEn) | \
5486 SYM_MASK(SendCtrl_0, ForceCreditUpToDate))
5488 static int sendctrl_hook(struct qib_devdata *dd,
5489 const struct diag_observer *op, u32 offs,
5490 u64 *data, u64 mask, int only_32)
5492 unsigned long flags;
5493 unsigned idx;
5494 unsigned pidx;
5495 struct qib_pportdata *ppd = NULL;
5496 u64 local_data, all_bits;
5499 * The fixed correspondence between Physical ports and pports is
5500 * severed. We need to hunt for the ppd that corresponds
5501 * to the offset we got. And we have to do that without admitting
5502 * we know the stride, apparently.
5504 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
5505 u64 __iomem *psptr;
5506 u32 psoffs;
5508 ppd = dd->pport + pidx;
5509 if (!ppd->cpspec->kpregbase)
5510 continue;
5512 psptr = ppd->cpspec->kpregbase + krp_sendctrl;
5513 psoffs = (u32) (psptr - dd->kregbase) * sizeof(*psptr);
5514 if (psoffs == offs)
5515 break;
5518 /* If pport is not being managed by driver, just avoid shadows. */
5519 if (pidx >= dd->num_pports)
5520 ppd = NULL;
5522 /* In any case, "idx" is flat index in kreg space */
5523 idx = offs / sizeof(u64);
5525 all_bits = ~0ULL;
5526 if (only_32)
5527 all_bits >>= 32;
5529 spin_lock_irqsave(&dd->sendctrl_lock, flags);
5530 if (!ppd || (mask & all_bits) != all_bits) {
5532 * At least some mask bits are zero, so we need
5533 * to read. The judgement call is whether from
5534 * reg or shadow. First-cut: read reg, and complain
5535 * if any bits which should be shadowed are different
5536 * from their shadowed value.
5538 if (only_32)
5539 local_data = (u64)qib_read_kreg32(dd, idx);
5540 else
5541 local_data = qib_read_kreg64(dd, idx);
5542 *data = (local_data & ~mask) | (*data & mask);
5544 if (mask) {
5546 * At least some mask bits are one, so we need
5547 * to write, but only shadow some bits.
5549 u64 sval, tval; /* Shadowed, transient */
5552 * New shadow val is bits we don't want to touch,
5553 * ORed with bits we do, that are intended for shadow.
5555 if (ppd) {
5556 sval = ppd->p_sendctrl & ~mask;
5557 sval |= *data & SENDCTRL_SHADOWED & mask;
5558 ppd->p_sendctrl = sval;
5559 } else
5560 sval = *data & SENDCTRL_SHADOWED & mask;
5561 tval = sval | (*data & ~SENDCTRL_SHADOWED & mask);
5562 qib_write_kreg(dd, idx, tval);
5563 qib_write_kreg(dd, kr_scratch, 0Ull);
5565 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
5566 return only_32 ? 4 : 8;
5569 static const struct diag_observer sendctrl_0_observer = {
5570 sendctrl_hook, KREG_IDX(SendCtrl_0) * sizeof(u64),
5571 KREG_IDX(SendCtrl_0) * sizeof(u64)
5574 static const struct diag_observer sendctrl_1_observer = {
5575 sendctrl_hook, KREG_IDX(SendCtrl_1) * sizeof(u64),
5576 KREG_IDX(SendCtrl_1) * sizeof(u64)
5579 static ushort sdma_fetch_prio = 8;
5580 module_param_named(sdma_fetch_prio, sdma_fetch_prio, ushort, S_IRUGO);
5581 MODULE_PARM_DESC(sdma_fetch_prio, "SDMA descriptor fetch priority");
5583 /* Besides logging QSFP events, we set appropriate TxDDS values */
5584 static void init_txdds_table(struct qib_pportdata *ppd, int override);
5586 static void qsfp_7322_event(struct work_struct *work)
5588 struct qib_qsfp_data *qd;
5589 struct qib_pportdata *ppd;
5590 u64 pwrup;
5591 int ret;
5592 u32 le2;
5594 qd = container_of(work, struct qib_qsfp_data, work);
5595 ppd = qd->ppd;
5596 pwrup = qd->t_insert + msecs_to_jiffies(QSFP_PWR_LAG_MSEC);
5599 * Some QSFP's not only do not respond until the full power-up
5600 * time, but may behave badly if we try. So hold off responding
5601 * to insertion.
5603 while (1) {
5604 u64 now = get_jiffies_64();
5605 if (time_after64(now, pwrup))
5606 break;
5607 msleep(20);
5609 ret = qib_refresh_qsfp_cache(ppd, &qd->cache);
5611 * Need to change LE2 back to defaults if we couldn't
5612 * read the cable type (to handle cable swaps), so do this
5613 * even on failure to read cable information. We don't
5614 * get here for QME, so IS_QME check not needed here.
5616 if (!ret && !ppd->dd->cspec->r1) {
5617 if (QSFP_IS_ACTIVE_FAR(qd->cache.tech))
5618 le2 = LE2_QME;
5619 else if (qd->cache.atten[1] >= qib_long_atten &&
5620 QSFP_IS_CU(qd->cache.tech))
5621 le2 = LE2_5m;
5622 else
5623 le2 = LE2_DEFAULT;
5624 } else
5625 le2 = LE2_DEFAULT;
5626 ibsd_wr_allchans(ppd, 13, (le2 << 7), BMASK(9, 7));
5627 init_txdds_table(ppd, 0);
5631 * There is little we can do but complain to the user if QSFP
5632 * initialization fails.
5634 static void qib_init_7322_qsfp(struct qib_pportdata *ppd)
5636 unsigned long flags;
5637 struct qib_qsfp_data *qd = &ppd->cpspec->qsfp_data;
5638 struct qib_devdata *dd = ppd->dd;
5639 u64 mod_prs_bit = QSFP_GPIO_MOD_PRS_N;
5641 mod_prs_bit <<= (QSFP_GPIO_PORT2_SHIFT * ppd->hw_pidx);
5642 qd->ppd = ppd;
5643 qib_qsfp_init(qd, qsfp_7322_event);
5644 spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
5645 dd->cspec->extctrl |= (mod_prs_bit << SYM_LSB(EXTCtrl, GPIOInvert));
5646 dd->cspec->gpio_mask |= mod_prs_bit;
5647 qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
5648 qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
5649 spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
5653 * called at device initialization time, and also if the txselect
5654 * module parameter is changed. This is used for cables that don't
5655 * have valid QSFP EEPROMs (not present, or attenuation is zero).
5656 * We initialize to the default, then if there is a specific
5657 * unit,port match, we use that (and set it immediately, for the
5658 * current speed, if the link is at INIT or better).
5659 * String format is "default# unit#,port#=# ... u,p=#", separators must
5660 * be a SPACE character. A newline terminates. The u,p=# tuples may
5661 * optionally have "u,p=#,#", where the final # is the H1 value
5662 * The last specific match is used (actually, all are used, but last
5663 * one is the one that winds up set); if none at all, fall back on default.
5665 static void set_no_qsfp_atten(struct qib_devdata *dd, int change)
5667 char *nxt, *str;
5668 u32 pidx, unit, port, deflt, h1;
5669 unsigned long val;
5670 int any = 0, seth1;
5671 int txdds_size;
5673 str = txselect_list;
5675 /* default number is validated in setup_txselect() */
5676 deflt = simple_strtoul(str, &nxt, 0);
5677 for (pidx = 0; pidx < dd->num_pports; ++pidx)
5678 dd->pport[pidx].cpspec->no_eep = deflt;
5680 txdds_size = TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ;
5681 if (IS_QME(dd) || IS_QMH(dd))
5682 txdds_size += TXDDS_MFG_SZ;
5684 while (*nxt && nxt[1]) {
5685 str = ++nxt;
5686 unit = simple_strtoul(str, &nxt, 0);
5687 if (nxt == str || !*nxt || *nxt != ',') {
5688 while (*nxt && *nxt++ != ' ') /* skip to next, if any */
5690 continue;
5692 str = ++nxt;
5693 port = simple_strtoul(str, &nxt, 0);
5694 if (nxt == str || *nxt != '=') {
5695 while (*nxt && *nxt++ != ' ') /* skip to next, if any */
5697 continue;
5699 str = ++nxt;
5700 val = simple_strtoul(str, &nxt, 0);
5701 if (nxt == str) {
5702 while (*nxt && *nxt++ != ' ') /* skip to next, if any */
5704 continue;
5706 if (val >= txdds_size)
5707 continue;
5708 seth1 = 0;
5709 h1 = 0; /* gcc thinks it might be used uninitted */
5710 if (*nxt == ',' && nxt[1]) {
5711 str = ++nxt;
5712 h1 = (u32)simple_strtoul(str, &nxt, 0);
5713 if (nxt == str)
5714 while (*nxt && *nxt++ != ' ') /* skip */
5716 else
5717 seth1 = 1;
5719 for (pidx = 0; dd->unit == unit && pidx < dd->num_pports;
5720 ++pidx) {
5721 struct qib_pportdata *ppd = &dd->pport[pidx];
5723 if (ppd->port != port || !ppd->link_speed_supported)
5724 continue;
5725 ppd->cpspec->no_eep = val;
5726 if (seth1)
5727 ppd->cpspec->h1_val = h1;
5728 /* now change the IBC and serdes, overriding generic */
5729 init_txdds_table(ppd, 1);
5730 /* Re-enable the physical state machine on mezz boards
5731 * now that the correct settings have been set. */
5732 if (IS_QMH(dd) || IS_QME(dd))
5733 qib_set_ib_7322_lstate(ppd, 0,
5734 QLOGIC_IB_IBCC_LINKINITCMD_SLEEP);
5735 any++;
5737 if (*nxt == '\n')
5738 break; /* done */
5740 if (change && !any) {
5741 /* no specific setting, use the default.
5742 * Change the IBC and serdes, but since it's
5743 * general, don't override specific settings.
5745 for (pidx = 0; pidx < dd->num_pports; ++pidx)
5746 if (dd->pport[pidx].link_speed_supported)
5747 init_txdds_table(&dd->pport[pidx], 0);
5751 /* handle the txselect parameter changing */
5752 static int setup_txselect(const char *str, struct kernel_param *kp)
5754 struct qib_devdata *dd;
5755 unsigned long val;
5756 char *n;
5757 if (strlen(str) >= MAX_ATTEN_LEN) {
5758 printk(KERN_INFO QIB_DRV_NAME " txselect_values string "
5759 "too long\n");
5760 return -ENOSPC;
5762 val = simple_strtoul(str, &n, 0);
5763 if (n == str || val >= (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
5764 TXDDS_MFG_SZ)) {
5765 printk(KERN_INFO QIB_DRV_NAME
5766 "txselect_values must start with a number < %d\n",
5767 TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ + TXDDS_MFG_SZ);
5768 return -EINVAL;
5770 strcpy(txselect_list, str);
5772 list_for_each_entry(dd, &qib_dev_list, list)
5773 if (dd->deviceid == PCI_DEVICE_ID_QLOGIC_IB_7322)
5774 set_no_qsfp_atten(dd, 1);
5775 return 0;
5779 * Write the final few registers that depend on some of the
5780 * init setup. Done late in init, just before bringing up
5781 * the serdes.
5783 static int qib_late_7322_initreg(struct qib_devdata *dd)
5785 int ret = 0, n;
5786 u64 val;
5788 qib_write_kreg(dd, kr_rcvhdrentsize, dd->rcvhdrentsize);
5789 qib_write_kreg(dd, kr_rcvhdrsize, dd->rcvhdrsize);
5790 qib_write_kreg(dd, kr_rcvhdrcnt, dd->rcvhdrcnt);
5791 qib_write_kreg(dd, kr_sendpioavailaddr, dd->pioavailregs_phys);
5792 val = qib_read_kreg64(dd, kr_sendpioavailaddr);
5793 if (val != dd->pioavailregs_phys) {
5794 qib_dev_err(dd, "Catastrophic software error, "
5795 "SendPIOAvailAddr written as %lx, "
5796 "read back as %llx\n",
5797 (unsigned long) dd->pioavailregs_phys,
5798 (unsigned long long) val);
5799 ret = -EINVAL;
5802 n = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
5803 qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_KERN, NULL);
5804 /* driver sends get pkey, lid, etc. checking also, to catch bugs */
5805 qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_ENAB1, NULL);
5807 qib_register_observer(dd, &sendctrl_0_observer);
5808 qib_register_observer(dd, &sendctrl_1_observer);
5810 dd->control &= ~QLOGIC_IB_C_SDMAFETCHPRIOEN;
5811 qib_write_kreg(dd, kr_control, dd->control);
5813 * Set SendDmaFetchPriority and init Tx params, including
5814 * QSFP handler on boards that have QSFP.
5815 * First set our default attenuation entry for cables that
5816 * don't have valid attenuation.
5818 set_no_qsfp_atten(dd, 0);
5819 for (n = 0; n < dd->num_pports; ++n) {
5820 struct qib_pportdata *ppd = dd->pport + n;
5822 qib_write_kreg_port(ppd, krp_senddmaprioritythld,
5823 sdma_fetch_prio & 0xf);
5824 /* Initialize qsfp if present on board. */
5825 if (dd->flags & QIB_HAS_QSFP)
5826 qib_init_7322_qsfp(ppd);
5828 dd->control |= QLOGIC_IB_C_SDMAFETCHPRIOEN;
5829 qib_write_kreg(dd, kr_control, dd->control);
5831 return ret;
5834 /* per IB port errors. */
5835 #define SENDCTRL_PIBP (MASK_ACROSS(0, 1) | MASK_ACROSS(3, 3) | \
5836 MASK_ACROSS(8, 15))
5837 #define RCVCTRL_PIBP (MASK_ACROSS(0, 17) | MASK_ACROSS(39, 41))
5838 #define ERRS_PIBP (MASK_ACROSS(57, 58) | MASK_ACROSS(54, 54) | \
5839 MASK_ACROSS(36, 49) | MASK_ACROSS(29, 34) | MASK_ACROSS(14, 17) | \
5840 MASK_ACROSS(0, 11))
5843 * Write the initialization per-port registers that need to be done at
5844 * driver load and after reset completes (i.e., that aren't done as part
5845 * of other init procedures called from qib_init.c).
5846 * Some of these should be redundant on reset, but play safe.
5848 static void write_7322_init_portregs(struct qib_pportdata *ppd)
5850 u64 val;
5851 int i;
5853 if (!ppd->link_speed_supported) {
5854 /* no buffer credits for this port */
5855 for (i = 1; i < 8; i++)
5856 qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, 0);
5857 qib_write_kreg_port(ppd, krp_ibcctrl_b, 0);
5858 qib_write_kreg(ppd->dd, kr_scratch, 0);
5859 return;
5863 * Set the number of supported virtual lanes in IBC,
5864 * for flow control packet handling on unsupported VLs
5866 val = qib_read_kreg_port(ppd, krp_ibsdtestiftx);
5867 val &= ~SYM_MASK(IB_SDTEST_IF_TX_0, VL_CAP);
5868 val |= (u64)(ppd->vls_supported - 1) <<
5869 SYM_LSB(IB_SDTEST_IF_TX_0, VL_CAP);
5870 qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
5872 qib_write_kreg_port(ppd, krp_rcvbthqp, QIB_KD_QP);
5874 /* enable tx header checking */
5875 qib_write_kreg_port(ppd, krp_sendcheckcontrol, IBA7322_SENDCHK_PKEY |
5876 IBA7322_SENDCHK_BTHQP | IBA7322_SENDCHK_SLID |
5877 IBA7322_SENDCHK_RAW_IPV6 | IBA7322_SENDCHK_MINSZ);
5879 qib_write_kreg_port(ppd, krp_ncmodectrl,
5880 SYM_MASK(IBNCModeCtrl_0, ScrambleCapLocal));
5883 * Unconditionally clear the bufmask bits. If SDMA is
5884 * enabled, we'll set them appropriately later.
5886 qib_write_kreg_port(ppd, krp_senddmabufmask0, 0);
5887 qib_write_kreg_port(ppd, krp_senddmabufmask1, 0);
5888 qib_write_kreg_port(ppd, krp_senddmabufmask2, 0);
5889 if (ppd->dd->cspec->r1)
5890 ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, ForceCreditUpToDate);
5894 * Write the initialization per-device registers that need to be done at
5895 * driver load and after reset completes (i.e., that aren't done as part
5896 * of other init procedures called from qib_init.c). Also write per-port
5897 * registers that are affected by overall device config, such as QP mapping
5898 * Some of these should be redundant on reset, but play safe.
5900 static void write_7322_initregs(struct qib_devdata *dd)
5902 struct qib_pportdata *ppd;
5903 int i, pidx;
5904 u64 val;
5906 /* Set Multicast QPs received by port 2 to map to context one. */
5907 qib_write_kreg(dd, KREG_IDX(RcvQPMulticastContext_1), 1);
5909 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
5910 unsigned n, regno;
5911 unsigned long flags;
5913 if (dd->n_krcv_queues < 2 ||
5914 !dd->pport[pidx].link_speed_supported)
5915 continue;
5917 ppd = &dd->pport[pidx];
5919 /* be paranoid against later code motion, etc. */
5920 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
5921 ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvQPMapEnable);
5922 spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
5924 /* Initialize QP to context mapping */
5925 regno = krp_rcvqpmaptable;
5926 val = 0;
5927 if (dd->num_pports > 1)
5928 n = dd->first_user_ctxt / dd->num_pports;
5929 else
5930 n = dd->first_user_ctxt - 1;
5931 for (i = 0; i < 32; ) {
5932 unsigned ctxt;
5934 if (dd->num_pports > 1)
5935 ctxt = (i % n) * dd->num_pports + pidx;
5936 else if (i % n)
5937 ctxt = (i % n) + 1;
5938 else
5939 ctxt = ppd->hw_pidx;
5940 val |= ctxt << (5 * (i % 6));
5941 i++;
5942 if (i % 6 == 0) {
5943 qib_write_kreg_port(ppd, regno, val);
5944 val = 0;
5945 regno++;
5948 qib_write_kreg_port(ppd, regno, val);
5952 * Setup up interrupt mitigation for kernel contexts, but
5953 * not user contexts (user contexts use interrupts when
5954 * stalled waiting for any packet, so want those interrupts
5955 * right away).
5957 for (i = 0; i < dd->first_user_ctxt; i++) {
5958 dd->cspec->rcvavail_timeout[i] = rcv_int_timeout;
5959 qib_write_kreg(dd, kr_rcvavailtimeout + i, rcv_int_timeout);
5963 * Initialize as (disabled) rcvflow tables. Application code
5964 * will setup each flow as it uses the flow.
5965 * Doesn't clear any of the error bits that might be set.
5967 val = TIDFLOW_ERRBITS; /* these are W1C */
5968 for (i = 0; i < dd->cfgctxts; i++) {
5969 int flow;
5970 for (flow = 0; flow < NUM_TIDFLOWS_CTXT; flow++)
5971 qib_write_ureg(dd, ur_rcvflowtable+flow, val, i);
5975 * dual cards init to dual port recovery, single port cards to
5976 * the one port. Dual port cards may later adjust to 1 port,
5977 * and then back to dual port if both ports are connected
5978 * */
5979 if (dd->num_pports)
5980 setup_7322_link_recovery(dd->pport, dd->num_pports > 1);
5983 static int qib_init_7322_variables(struct qib_devdata *dd)
5985 struct qib_pportdata *ppd;
5986 unsigned features, pidx, sbufcnt;
5987 int ret, mtu;
5988 u32 sbufs, updthresh;
5990 /* pport structs are contiguous, allocated after devdata */
5991 ppd = (struct qib_pportdata *)(dd + 1);
5992 dd->pport = ppd;
5993 ppd[0].dd = dd;
5994 ppd[1].dd = dd;
5996 dd->cspec = (struct qib_chip_specific *)(ppd + 2);
5998 ppd[0].cpspec = (struct qib_chippport_specific *)(dd->cspec + 1);
5999 ppd[1].cpspec = &ppd[0].cpspec[1];
6000 ppd[0].cpspec->ppd = &ppd[0]; /* for autoneg_7322_work() */
6001 ppd[1].cpspec->ppd = &ppd[1]; /* for autoneg_7322_work() */
6003 spin_lock_init(&dd->cspec->rcvmod_lock);
6004 spin_lock_init(&dd->cspec->gpio_lock);
6006 /* we haven't yet set QIB_PRESENT, so use read directly */
6007 dd->revision = readq(&dd->kregbase[kr_revision]);
6009 if ((dd->revision & 0xffffffffU) == 0xffffffffU) {
6010 qib_dev_err(dd, "Revision register read failure, "
6011 "giving up initialization\n");
6012 ret = -ENODEV;
6013 goto bail;
6015 dd->flags |= QIB_PRESENT; /* now register routines work */
6017 dd->majrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMajor);
6018 dd->minrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMinor);
6019 dd->cspec->r1 = dd->minrev == 1;
6021 get_7322_chip_params(dd);
6022 features = qib_7322_boardname(dd);
6024 /* now that piobcnt2k and 4k set, we can allocate these */
6025 sbufcnt = dd->piobcnt2k + dd->piobcnt4k +
6026 NUM_VL15_BUFS + BITS_PER_LONG - 1;
6027 sbufcnt /= BITS_PER_LONG;
6028 dd->cspec->sendchkenable = kmalloc(sbufcnt *
6029 sizeof(*dd->cspec->sendchkenable), GFP_KERNEL);
6030 dd->cspec->sendgrhchk = kmalloc(sbufcnt *
6031 sizeof(*dd->cspec->sendgrhchk), GFP_KERNEL);
6032 dd->cspec->sendibchk = kmalloc(sbufcnt *
6033 sizeof(*dd->cspec->sendibchk), GFP_KERNEL);
6034 if (!dd->cspec->sendchkenable || !dd->cspec->sendgrhchk ||
6035 !dd->cspec->sendibchk) {
6036 qib_dev_err(dd, "Failed allocation for hdrchk bitmaps\n");
6037 ret = -ENOMEM;
6038 goto bail;
6041 ppd = dd->pport;
6044 * GPIO bits for TWSI data and clock,
6045 * used for serial EEPROM.
6047 dd->gpio_sda_num = _QIB_GPIO_SDA_NUM;
6048 dd->gpio_scl_num = _QIB_GPIO_SCL_NUM;
6049 dd->twsi_eeprom_dev = QIB_TWSI_EEPROM_DEV;
6051 dd->flags |= QIB_HAS_INTX | QIB_HAS_LINK_LATENCY |
6052 QIB_NODMA_RTAIL | QIB_HAS_VLSUPP | QIB_HAS_HDRSUPP |
6053 QIB_HAS_THRESH_UPDATE |
6054 (sdma_idle_cnt ? QIB_HAS_SDMA_TIMEOUT : 0);
6055 dd->flags |= qib_special_trigger ?
6056 QIB_USE_SPCL_TRIG : QIB_HAS_SEND_DMA;
6059 * Setup initial values. These may change when PAT is enabled, but
6060 * we need these to do initial chip register accesses.
6062 qib_7322_set_baseaddrs(dd);
6064 mtu = ib_mtu_enum_to_int(qib_ibmtu);
6065 if (mtu == -1)
6066 mtu = QIB_DEFAULT_MTU;
6068 dd->cspec->int_enable_mask = QIB_I_BITSEXTANT;
6069 /* all hwerrors become interrupts, unless special purposed */
6070 dd->cspec->hwerrmask = ~0ULL;
6071 /* link_recovery setup causes these errors, so ignore them,
6072 * other than clearing them when they occur */
6073 dd->cspec->hwerrmask &=
6074 ~(SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_0) |
6075 SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_1) |
6076 HWE_MASK(LATriggered));
6078 for (pidx = 0; pidx < NUM_IB_PORTS; ++pidx) {
6079 struct qib_chippport_specific *cp = ppd->cpspec;
6080 ppd->link_speed_supported = features & PORT_SPD_CAP;
6081 features >>= PORT_SPD_CAP_SHIFT;
6082 if (!ppd->link_speed_supported) {
6083 /* single port mode (7340, or configured) */
6084 dd->skip_kctxt_mask |= 1 << pidx;
6085 if (pidx == 0) {
6086 /* Make sure port is disabled. */
6087 qib_write_kreg_port(ppd, krp_rcvctrl, 0);
6088 qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
6089 ppd[0] = ppd[1];
6090 dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
6091 IBSerdesPClkNotDetectMask_0)
6092 | SYM_MASK(HwErrMask,
6093 SDmaMemReadErrMask_0));
6094 dd->cspec->int_enable_mask &= ~(
6095 SYM_MASK(IntMask, SDmaCleanupDoneMask_0) |
6096 SYM_MASK(IntMask, SDmaIdleIntMask_0) |
6097 SYM_MASK(IntMask, SDmaProgressIntMask_0) |
6098 SYM_MASK(IntMask, SDmaIntMask_0) |
6099 SYM_MASK(IntMask, ErrIntMask_0) |
6100 SYM_MASK(IntMask, SendDoneIntMask_0));
6101 } else {
6102 /* Make sure port is disabled. */
6103 qib_write_kreg_port(ppd, krp_rcvctrl, 0);
6104 qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
6105 dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
6106 IBSerdesPClkNotDetectMask_1)
6107 | SYM_MASK(HwErrMask,
6108 SDmaMemReadErrMask_1));
6109 dd->cspec->int_enable_mask &= ~(
6110 SYM_MASK(IntMask, SDmaCleanupDoneMask_1) |
6111 SYM_MASK(IntMask, SDmaIdleIntMask_1) |
6112 SYM_MASK(IntMask, SDmaProgressIntMask_1) |
6113 SYM_MASK(IntMask, SDmaIntMask_1) |
6114 SYM_MASK(IntMask, ErrIntMask_1) |
6115 SYM_MASK(IntMask, SendDoneIntMask_1));
6117 continue;
6120 dd->num_pports++;
6121 qib_init_pportdata(ppd, dd, pidx, dd->num_pports);
6123 ppd->link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
6124 ppd->link_width_enabled = IB_WIDTH_4X;
6125 ppd->link_speed_enabled = ppd->link_speed_supported;
6127 * Set the initial values to reasonable default, will be set
6128 * for real when link is up.
6130 ppd->link_width_active = IB_WIDTH_4X;
6131 ppd->link_speed_active = QIB_IB_SDR;
6132 ppd->delay_mult = ib_rate_to_delay[IB_RATE_10_GBPS];
6133 switch (qib_num_cfg_vls) {
6134 case 1:
6135 ppd->vls_supported = IB_VL_VL0;
6136 break;
6137 case 2:
6138 ppd->vls_supported = IB_VL_VL0_1;
6139 break;
6140 default:
6141 qib_devinfo(dd->pcidev,
6142 "Invalid num_vls %u, using 4 VLs\n",
6143 qib_num_cfg_vls);
6144 qib_num_cfg_vls = 4;
6145 /* fall through */
6146 case 4:
6147 ppd->vls_supported = IB_VL_VL0_3;
6148 break;
6149 case 8:
6150 if (mtu <= 2048)
6151 ppd->vls_supported = IB_VL_VL0_7;
6152 else {
6153 qib_devinfo(dd->pcidev,
6154 "Invalid num_vls %u for MTU %d "
6155 ", using 4 VLs\n",
6156 qib_num_cfg_vls, mtu);
6157 ppd->vls_supported = IB_VL_VL0_3;
6158 qib_num_cfg_vls = 4;
6160 break;
6162 ppd->vls_operational = ppd->vls_supported;
6164 init_waitqueue_head(&cp->autoneg_wait);
6165 INIT_DELAYED_WORK(&cp->autoneg_work,
6166 autoneg_7322_work);
6167 if (ppd->dd->cspec->r1)
6168 INIT_DELAYED_WORK(&cp->ipg_work, ipg_7322_work);
6171 * For Mez and similar cards, no qsfp info, so do
6172 * the "cable info" setup here. Can be overridden
6173 * in adapter-specific routines.
6175 if (!(dd->flags & QIB_HAS_QSFP)) {
6176 if (!IS_QMH(dd) && !IS_QME(dd))
6177 qib_devinfo(dd->pcidev, "IB%u:%u: "
6178 "Unknown mezzanine card type\n",
6179 dd->unit, ppd->port);
6180 cp->h1_val = IS_QMH(dd) ? H1_FORCE_QMH : H1_FORCE_QME;
6182 * Choose center value as default tx serdes setting
6183 * until changed through module parameter.
6185 ppd->cpspec->no_eep = IS_QMH(dd) ?
6186 TXDDS_TABLE_SZ + 2 : TXDDS_TABLE_SZ + 4;
6187 } else
6188 cp->h1_val = H1_FORCE_VAL;
6190 /* Avoid writes to chip for mini_init */
6191 if (!qib_mini_init)
6192 write_7322_init_portregs(ppd);
6194 init_timer(&cp->chase_timer);
6195 cp->chase_timer.function = reenable_chase;
6196 cp->chase_timer.data = (unsigned long)ppd;
6198 ppd++;
6201 dd->rcvhdrentsize = qib_rcvhdrentsize ?
6202 qib_rcvhdrentsize : QIB_RCVHDR_ENTSIZE;
6203 dd->rcvhdrsize = qib_rcvhdrsize ?
6204 qib_rcvhdrsize : QIB_DFLT_RCVHDRSIZE;
6205 dd->rhf_offset = dd->rcvhdrentsize - sizeof(u64) / sizeof(u32);
6207 /* we always allocate at least 2048 bytes for eager buffers */
6208 dd->rcvegrbufsize = max(mtu, 2048);
6210 qib_7322_tidtemplate(dd);
6213 * We can request a receive interrupt for 1 or
6214 * more packets from current offset.
6216 dd->rhdrhead_intr_off =
6217 (u64) rcv_int_count << IBA7322_HDRHEAD_PKTINT_SHIFT;
6219 /* setup the stats timer; the add_timer is done at end of init */
6220 init_timer(&dd->stats_timer);
6221 dd->stats_timer.function = qib_get_7322_faststats;
6222 dd->stats_timer.data = (unsigned long) dd;
6224 dd->ureg_align = 0x10000; /* 64KB alignment */
6226 dd->piosize2kmax_dwords = dd->piosize2k >> 2;
6228 qib_7322_config_ctxts(dd);
6229 qib_set_ctxtcnt(dd);
6231 if (qib_wc_pat) {
6232 resource_size_t vl15off;
6234 * We do not set WC on the VL15 buffers to avoid
6235 * a rare problem with unaligned writes from
6236 * interrupt-flushed store buffers, so we need
6237 * to map those separately here. We can't solve
6238 * this for the rarely used mtrr case.
6240 ret = init_chip_wc_pat(dd, 0);
6241 if (ret)
6242 goto bail;
6244 /* vl15 buffers start just after the 4k buffers */
6245 vl15off = dd->physaddr + (dd->piobufbase >> 32) +
6246 dd->piobcnt4k * dd->align4k;
6247 dd->piovl15base = ioremap_nocache(vl15off,
6248 NUM_VL15_BUFS * dd->align4k);
6249 if (!dd->piovl15base)
6250 goto bail;
6252 qib_7322_set_baseaddrs(dd); /* set chip access pointers now */
6254 ret = 0;
6255 if (qib_mini_init)
6256 goto bail;
6257 if (!dd->num_pports) {
6258 qib_dev_err(dd, "No ports enabled, giving up initialization\n");
6259 goto bail; /* no error, so can still figure out why err */
6262 write_7322_initregs(dd);
6263 ret = qib_create_ctxts(dd);
6264 init_7322_cntrnames(dd);
6266 updthresh = 8U; /* update threshold */
6268 /* use all of 4KB buffers for the kernel SDMA, zero if !SDMA.
6269 * reserve the update threshold amount for other kernel use, such
6270 * as sending SMI, MAD, and ACKs, or 3, whichever is greater,
6271 * unless we aren't enabling SDMA, in which case we want to use
6272 * all the 4k bufs for the kernel.
6273 * if this was less than the update threshold, we could wait
6274 * a long time for an update. Coded this way because we
6275 * sometimes change the update threshold for various reasons,
6276 * and we want this to remain robust.
6278 if (dd->flags & QIB_HAS_SEND_DMA) {
6279 dd->cspec->sdmabufcnt = dd->piobcnt4k;
6280 sbufs = updthresh > 3 ? updthresh : 3;
6281 } else {
6282 dd->cspec->sdmabufcnt = 0;
6283 sbufs = dd->piobcnt4k;
6285 dd->cspec->lastbuf_for_pio = dd->piobcnt2k + dd->piobcnt4k -
6286 dd->cspec->sdmabufcnt;
6287 dd->lastctxt_piobuf = dd->cspec->lastbuf_for_pio - sbufs;
6288 dd->cspec->lastbuf_for_pio--; /* range is <= , not < */
6289 dd->pbufsctxt = (dd->cfgctxts > dd->first_user_ctxt) ?
6290 dd->lastctxt_piobuf / (dd->cfgctxts - dd->first_user_ctxt) : 0;
6293 * If we have 16 user contexts, we will have 7 sbufs
6294 * per context, so reduce the update threshold to match. We
6295 * want to update before we actually run out, at low pbufs/ctxt
6296 * so give ourselves some margin.
6298 if (dd->pbufsctxt >= 2 && dd->pbufsctxt - 2 < updthresh)
6299 updthresh = dd->pbufsctxt - 2;
6300 dd->cspec->updthresh_dflt = updthresh;
6301 dd->cspec->updthresh = updthresh;
6303 /* before full enable, no interrupts, no locking needed */
6304 dd->sendctrl |= ((updthresh & SYM_RMASK(SendCtrl, AvailUpdThld))
6305 << SYM_LSB(SendCtrl, AvailUpdThld)) |
6306 SYM_MASK(SendCtrl, SendBufAvailPad64Byte);
6308 dd->psxmitwait_supported = 1;
6309 dd->psxmitwait_check_rate = QIB_7322_PSXMITWAIT_CHECK_RATE;
6310 bail:
6311 if (!dd->ctxtcnt)
6312 dd->ctxtcnt = 1; /* for other initialization code */
6314 return ret;
6317 static u32 __iomem *qib_7322_getsendbuf(struct qib_pportdata *ppd, u64 pbc,
6318 u32 *pbufnum)
6320 u32 first, last, plen = pbc & QIB_PBC_LENGTH_MASK;
6321 struct qib_devdata *dd = ppd->dd;
6323 /* last is same for 2k and 4k, because we use 4k if all 2k busy */
6324 if (pbc & PBC_7322_VL15_SEND) {
6325 first = dd->piobcnt2k + dd->piobcnt4k + ppd->hw_pidx;
6326 last = first;
6327 } else {
6328 if ((plen + 1) > dd->piosize2kmax_dwords)
6329 first = dd->piobcnt2k;
6330 else
6331 first = 0;
6332 last = dd->cspec->lastbuf_for_pio;
6334 return qib_getsendbuf_range(dd, pbufnum, first, last);
6337 static void qib_set_cntr_7322_sample(struct qib_pportdata *ppd, u32 intv,
6338 u32 start)
6340 qib_write_kreg_port(ppd, krp_psinterval, intv);
6341 qib_write_kreg_port(ppd, krp_psstart, start);
6345 * Must be called with sdma_lock held, or before init finished.
6347 static void qib_sdma_set_7322_desc_cnt(struct qib_pportdata *ppd, unsigned cnt)
6349 qib_write_kreg_port(ppd, krp_senddmadesccnt, cnt);
6352 static struct sdma_set_state_action sdma_7322_action_table[] = {
6353 [qib_sdma_state_s00_hw_down] = {
6354 .go_s99_running_tofalse = 1,
6355 .op_enable = 0,
6356 .op_intenable = 0,
6357 .op_halt = 0,
6358 .op_drain = 0,
6360 [qib_sdma_state_s10_hw_start_up_wait] = {
6361 .op_enable = 0,
6362 .op_intenable = 1,
6363 .op_halt = 1,
6364 .op_drain = 0,
6366 [qib_sdma_state_s20_idle] = {
6367 .op_enable = 1,
6368 .op_intenable = 1,
6369 .op_halt = 1,
6370 .op_drain = 0,
6372 [qib_sdma_state_s30_sw_clean_up_wait] = {
6373 .op_enable = 0,
6374 .op_intenable = 1,
6375 .op_halt = 1,
6376 .op_drain = 0,
6378 [qib_sdma_state_s40_hw_clean_up_wait] = {
6379 .op_enable = 1,
6380 .op_intenable = 1,
6381 .op_halt = 1,
6382 .op_drain = 0,
6384 [qib_sdma_state_s50_hw_halt_wait] = {
6385 .op_enable = 1,
6386 .op_intenable = 1,
6387 .op_halt = 1,
6388 .op_drain = 1,
6390 [qib_sdma_state_s99_running] = {
6391 .op_enable = 1,
6392 .op_intenable = 1,
6393 .op_halt = 0,
6394 .op_drain = 0,
6395 .go_s99_running_totrue = 1,
6399 static void qib_7322_sdma_init_early(struct qib_pportdata *ppd)
6401 ppd->sdma_state.set_state_action = sdma_7322_action_table;
6404 static int init_sdma_7322_regs(struct qib_pportdata *ppd)
6406 struct qib_devdata *dd = ppd->dd;
6407 unsigned lastbuf, erstbuf;
6408 u64 senddmabufmask[3] = { 0 };
6409 int n, ret = 0;
6411 qib_write_kreg_port(ppd, krp_senddmabase, ppd->sdma_descq_phys);
6412 qib_sdma_7322_setlengen(ppd);
6413 qib_sdma_update_7322_tail(ppd, 0); /* Set SendDmaTail */
6414 qib_write_kreg_port(ppd, krp_senddmareloadcnt, sdma_idle_cnt);
6415 qib_write_kreg_port(ppd, krp_senddmadesccnt, 0);
6416 qib_write_kreg_port(ppd, krp_senddmaheadaddr, ppd->sdma_head_phys);
6418 if (dd->num_pports)
6419 n = dd->cspec->sdmabufcnt / dd->num_pports; /* no remainder */
6420 else
6421 n = dd->cspec->sdmabufcnt; /* failsafe for init */
6422 erstbuf = (dd->piobcnt2k + dd->piobcnt4k) -
6423 ((dd->num_pports == 1 || ppd->port == 2) ? n :
6424 dd->cspec->sdmabufcnt);
6425 lastbuf = erstbuf + n;
6427 ppd->sdma_state.first_sendbuf = erstbuf;
6428 ppd->sdma_state.last_sendbuf = lastbuf;
6429 for (; erstbuf < lastbuf; ++erstbuf) {
6430 unsigned word = erstbuf / BITS_PER_LONG;
6431 unsigned bit = erstbuf & (BITS_PER_LONG - 1);
6433 BUG_ON(word >= 3);
6434 senddmabufmask[word] |= 1ULL << bit;
6436 qib_write_kreg_port(ppd, krp_senddmabufmask0, senddmabufmask[0]);
6437 qib_write_kreg_port(ppd, krp_senddmabufmask1, senddmabufmask[1]);
6438 qib_write_kreg_port(ppd, krp_senddmabufmask2, senddmabufmask[2]);
6439 return ret;
6442 /* sdma_lock must be held */
6443 static u16 qib_sdma_7322_gethead(struct qib_pportdata *ppd)
6445 struct qib_devdata *dd = ppd->dd;
6446 int sane;
6447 int use_dmahead;
6448 u16 swhead;
6449 u16 swtail;
6450 u16 cnt;
6451 u16 hwhead;
6453 use_dmahead = __qib_sdma_running(ppd) &&
6454 (dd->flags & QIB_HAS_SDMA_TIMEOUT);
6455 retry:
6456 hwhead = use_dmahead ?
6457 (u16) le64_to_cpu(*ppd->sdma_head_dma) :
6458 (u16) qib_read_kreg_port(ppd, krp_senddmahead);
6460 swhead = ppd->sdma_descq_head;
6461 swtail = ppd->sdma_descq_tail;
6462 cnt = ppd->sdma_descq_cnt;
6464 if (swhead < swtail)
6465 /* not wrapped */
6466 sane = (hwhead >= swhead) & (hwhead <= swtail);
6467 else if (swhead > swtail)
6468 /* wrapped around */
6469 sane = ((hwhead >= swhead) && (hwhead < cnt)) ||
6470 (hwhead <= swtail);
6471 else
6472 /* empty */
6473 sane = (hwhead == swhead);
6475 if (unlikely(!sane)) {
6476 if (use_dmahead) {
6477 /* try one more time, directly from the register */
6478 use_dmahead = 0;
6479 goto retry;
6481 /* proceed as if no progress */
6482 hwhead = swhead;
6485 return hwhead;
6488 static int qib_sdma_7322_busy(struct qib_pportdata *ppd)
6490 u64 hwstatus = qib_read_kreg_port(ppd, krp_senddmastatus);
6492 return (hwstatus & SYM_MASK(SendDmaStatus_0, ScoreBoardDrainInProg)) ||
6493 (hwstatus & SYM_MASK(SendDmaStatus_0, HaltInProg)) ||
6494 !(hwstatus & SYM_MASK(SendDmaStatus_0, InternalSDmaHalt)) ||
6495 !(hwstatus & SYM_MASK(SendDmaStatus_0, ScbEmpty));
6499 * Compute the amount of delay before sending the next packet if the
6500 * port's send rate differs from the static rate set for the QP.
6501 * The delay affects the next packet and the amount of the delay is
6502 * based on the length of the this packet.
6504 static u32 qib_7322_setpbc_control(struct qib_pportdata *ppd, u32 plen,
6505 u8 srate, u8 vl)
6507 u8 snd_mult = ppd->delay_mult;
6508 u8 rcv_mult = ib_rate_to_delay[srate];
6509 u32 ret;
6511 ret = rcv_mult > snd_mult ? ((plen + 1) >> 1) * snd_mult : 0;
6513 /* Indicate VL15, else set the VL in the control word */
6514 if (vl == 15)
6515 ret |= PBC_7322_VL15_SEND_CTRL;
6516 else
6517 ret |= vl << PBC_VL_NUM_LSB;
6518 ret |= ((u32)(ppd->hw_pidx)) << PBC_PORT_SEL_LSB;
6520 return ret;
6524 * Enable the per-port VL15 send buffers for use.
6525 * They follow the rest of the buffers, without a config parameter.
6526 * This was in initregs, but that is done before the shadow
6527 * is set up, and this has to be done after the shadow is
6528 * set up.
6530 static void qib_7322_initvl15_bufs(struct qib_devdata *dd)
6532 unsigned vl15bufs;
6534 vl15bufs = dd->piobcnt2k + dd->piobcnt4k;
6535 qib_chg_pioavailkernel(dd, vl15bufs, NUM_VL15_BUFS,
6536 TXCHK_CHG_TYPE_KERN, NULL);
6539 static void qib_7322_init_ctxt(struct qib_ctxtdata *rcd)
6541 if (rcd->ctxt < NUM_IB_PORTS) {
6542 if (rcd->dd->num_pports > 1) {
6543 rcd->rcvegrcnt = KCTXT0_EGRCNT / 2;
6544 rcd->rcvegr_tid_base = rcd->ctxt ? rcd->rcvegrcnt : 0;
6545 } else {
6546 rcd->rcvegrcnt = KCTXT0_EGRCNT;
6547 rcd->rcvegr_tid_base = 0;
6549 } else {
6550 rcd->rcvegrcnt = rcd->dd->cspec->rcvegrcnt;
6551 rcd->rcvegr_tid_base = KCTXT0_EGRCNT +
6552 (rcd->ctxt - NUM_IB_PORTS) * rcd->rcvegrcnt;
6556 #define QTXSLEEPS 5000
6557 static void qib_7322_txchk_change(struct qib_devdata *dd, u32 start,
6558 u32 len, u32 which, struct qib_ctxtdata *rcd)
6560 int i;
6561 const int last = start + len - 1;
6562 const int lastr = last / BITS_PER_LONG;
6563 u32 sleeps = 0;
6564 int wait = rcd != NULL;
6565 unsigned long flags;
6567 while (wait) {
6568 unsigned long shadow;
6569 int cstart, previ = -1;
6572 * when flipping from kernel to user, we can't change
6573 * the checking type if the buffer is allocated to the
6574 * driver. It's OK the other direction, because it's
6575 * from close, and we have just disarm'ed all the
6576 * buffers. All the kernel to kernel changes are also
6577 * OK.
6579 for (cstart = start; cstart <= last; cstart++) {
6580 i = ((2 * cstart) + QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
6581 / BITS_PER_LONG;
6582 if (i != previ) {
6583 shadow = (unsigned long)
6584 le64_to_cpu(dd->pioavailregs_dma[i]);
6585 previ = i;
6587 if (test_bit(((2 * cstart) +
6588 QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
6589 % BITS_PER_LONG, &shadow))
6590 break;
6593 if (cstart > last)
6594 break;
6596 if (sleeps == QTXSLEEPS)
6597 break;
6598 /* make sure we see an updated copy next time around */
6599 sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
6600 sleeps++;
6601 msleep(20);
6604 switch (which) {
6605 case TXCHK_CHG_TYPE_DIS1:
6607 * disable checking on a range; used by diags; just
6608 * one buffer, but still written generically
6610 for (i = start; i <= last; i++)
6611 clear_bit(i, dd->cspec->sendchkenable);
6612 break;
6614 case TXCHK_CHG_TYPE_ENAB1:
6616 * (re)enable checking on a range; used by diags; just
6617 * one buffer, but still written generically; read
6618 * scratch to be sure buffer actually triggered, not
6619 * just flushed from processor.
6621 qib_read_kreg32(dd, kr_scratch);
6622 for (i = start; i <= last; i++)
6623 set_bit(i, dd->cspec->sendchkenable);
6624 break;
6626 case TXCHK_CHG_TYPE_KERN:
6627 /* usable by kernel */
6628 for (i = start; i <= last; i++) {
6629 set_bit(i, dd->cspec->sendibchk);
6630 clear_bit(i, dd->cspec->sendgrhchk);
6632 spin_lock_irqsave(&dd->uctxt_lock, flags);
6633 /* see if we need to raise avail update threshold */
6634 for (i = dd->first_user_ctxt;
6635 dd->cspec->updthresh != dd->cspec->updthresh_dflt
6636 && i < dd->cfgctxts; i++)
6637 if (dd->rcd[i] && dd->rcd[i]->subctxt_cnt &&
6638 ((dd->rcd[i]->piocnt / dd->rcd[i]->subctxt_cnt) - 1)
6639 < dd->cspec->updthresh_dflt)
6640 break;
6641 spin_unlock_irqrestore(&dd->uctxt_lock, flags);
6642 if (i == dd->cfgctxts) {
6643 spin_lock_irqsave(&dd->sendctrl_lock, flags);
6644 dd->cspec->updthresh = dd->cspec->updthresh_dflt;
6645 dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
6646 dd->sendctrl |= (dd->cspec->updthresh &
6647 SYM_RMASK(SendCtrl, AvailUpdThld)) <<
6648 SYM_LSB(SendCtrl, AvailUpdThld);
6649 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
6650 sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
6652 break;
6654 case TXCHK_CHG_TYPE_USER:
6655 /* for user process */
6656 for (i = start; i <= last; i++) {
6657 clear_bit(i, dd->cspec->sendibchk);
6658 set_bit(i, dd->cspec->sendgrhchk);
6660 spin_lock_irqsave(&dd->sendctrl_lock, flags);
6661 if (rcd && rcd->subctxt_cnt && ((rcd->piocnt
6662 / rcd->subctxt_cnt) - 1) < dd->cspec->updthresh) {
6663 dd->cspec->updthresh = (rcd->piocnt /
6664 rcd->subctxt_cnt) - 1;
6665 dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
6666 dd->sendctrl |= (dd->cspec->updthresh &
6667 SYM_RMASK(SendCtrl, AvailUpdThld))
6668 << SYM_LSB(SendCtrl, AvailUpdThld);
6669 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
6670 sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
6671 } else
6672 spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
6673 break;
6675 default:
6676 break;
6679 for (i = start / BITS_PER_LONG; which >= 2 && i <= lastr; ++i)
6680 qib_write_kreg(dd, kr_sendcheckmask + i,
6681 dd->cspec->sendchkenable[i]);
6683 for (i = start / BITS_PER_LONG; which < 2 && i <= lastr; ++i) {
6684 qib_write_kreg(dd, kr_sendgrhcheckmask + i,
6685 dd->cspec->sendgrhchk[i]);
6686 qib_write_kreg(dd, kr_sendibpktmask + i,
6687 dd->cspec->sendibchk[i]);
6691 * Be sure whatever we did was seen by the chip and acted upon,
6692 * before we return. Mostly important for which >= 2.
6694 qib_read_kreg32(dd, kr_scratch);
6698 /* useful for trigger analyzers, etc. */
6699 static void writescratch(struct qib_devdata *dd, u32 val)
6701 qib_write_kreg(dd, kr_scratch, val);
6704 /* Dummy for now, use chip regs soon */
6705 static int qib_7322_tempsense_rd(struct qib_devdata *dd, int regnum)
6707 return -ENXIO;
6711 * qib_init_iba7322_funcs - set up the chip-specific function pointers
6712 * @dev: the pci_dev for qlogic_ib device
6713 * @ent: pci_device_id struct for this dev
6715 * Also allocates, inits, and returns the devdata struct for this
6716 * device instance
6718 * This is global, and is called directly at init to set up the
6719 * chip-specific function pointers for later use.
6721 struct qib_devdata *qib_init_iba7322_funcs(struct pci_dev *pdev,
6722 const struct pci_device_id *ent)
6724 struct qib_devdata *dd;
6725 int ret, i;
6726 u32 tabsize, actual_cnt = 0;
6728 dd = qib_alloc_devdata(pdev,
6729 NUM_IB_PORTS * sizeof(struct qib_pportdata) +
6730 sizeof(struct qib_chip_specific) +
6731 NUM_IB_PORTS * sizeof(struct qib_chippport_specific));
6732 if (IS_ERR(dd))
6733 goto bail;
6735 dd->f_bringup_serdes = qib_7322_bringup_serdes;
6736 dd->f_cleanup = qib_setup_7322_cleanup;
6737 dd->f_clear_tids = qib_7322_clear_tids;
6738 dd->f_free_irq = qib_7322_free_irq;
6739 dd->f_get_base_info = qib_7322_get_base_info;
6740 dd->f_get_msgheader = qib_7322_get_msgheader;
6741 dd->f_getsendbuf = qib_7322_getsendbuf;
6742 dd->f_gpio_mod = gpio_7322_mod;
6743 dd->f_eeprom_wen = qib_7322_eeprom_wen;
6744 dd->f_hdrqempty = qib_7322_hdrqempty;
6745 dd->f_ib_updown = qib_7322_ib_updown;
6746 dd->f_init_ctxt = qib_7322_init_ctxt;
6747 dd->f_initvl15_bufs = qib_7322_initvl15_bufs;
6748 dd->f_intr_fallback = qib_7322_intr_fallback;
6749 dd->f_late_initreg = qib_late_7322_initreg;
6750 dd->f_setpbc_control = qib_7322_setpbc_control;
6751 dd->f_portcntr = qib_portcntr_7322;
6752 dd->f_put_tid = qib_7322_put_tid;
6753 dd->f_quiet_serdes = qib_7322_mini_quiet_serdes;
6754 dd->f_rcvctrl = rcvctrl_7322_mod;
6755 dd->f_read_cntrs = qib_read_7322cntrs;
6756 dd->f_read_portcntrs = qib_read_7322portcntrs;
6757 dd->f_reset = qib_do_7322_reset;
6758 dd->f_init_sdma_regs = init_sdma_7322_regs;
6759 dd->f_sdma_busy = qib_sdma_7322_busy;
6760 dd->f_sdma_gethead = qib_sdma_7322_gethead;
6761 dd->f_sdma_sendctrl = qib_7322_sdma_sendctrl;
6762 dd->f_sdma_set_desc_cnt = qib_sdma_set_7322_desc_cnt;
6763 dd->f_sdma_update_tail = qib_sdma_update_7322_tail;
6764 dd->f_sendctrl = sendctrl_7322_mod;
6765 dd->f_set_armlaunch = qib_set_7322_armlaunch;
6766 dd->f_set_cntr_sample = qib_set_cntr_7322_sample;
6767 dd->f_iblink_state = qib_7322_iblink_state;
6768 dd->f_ibphys_portstate = qib_7322_phys_portstate;
6769 dd->f_get_ib_cfg = qib_7322_get_ib_cfg;
6770 dd->f_set_ib_cfg = qib_7322_set_ib_cfg;
6771 dd->f_set_ib_loopback = qib_7322_set_loopback;
6772 dd->f_get_ib_table = qib_7322_get_ib_table;
6773 dd->f_set_ib_table = qib_7322_set_ib_table;
6774 dd->f_set_intr_state = qib_7322_set_intr_state;
6775 dd->f_setextled = qib_setup_7322_setextled;
6776 dd->f_txchk_change = qib_7322_txchk_change;
6777 dd->f_update_usrhead = qib_update_7322_usrhead;
6778 dd->f_wantpiobuf_intr = qib_wantpiobuf_7322_intr;
6779 dd->f_xgxs_reset = qib_7322_mini_pcs_reset;
6780 dd->f_sdma_hw_clean_up = qib_7322_sdma_hw_clean_up;
6781 dd->f_sdma_hw_start_up = qib_7322_sdma_hw_start_up;
6782 dd->f_sdma_init_early = qib_7322_sdma_init_early;
6783 dd->f_writescratch = writescratch;
6784 dd->f_tempsense_rd = qib_7322_tempsense_rd;
6786 * Do remaining PCIe setup and save PCIe values in dd.
6787 * Any error printing is already done by the init code.
6788 * On return, we have the chip mapped, but chip registers
6789 * are not set up until start of qib_init_7322_variables.
6791 ret = qib_pcie_ddinit(dd, pdev, ent);
6792 if (ret < 0)
6793 goto bail_free;
6795 /* initialize chip-specific variables */
6796 ret = qib_init_7322_variables(dd);
6797 if (ret)
6798 goto bail_cleanup;
6800 if (qib_mini_init || !dd->num_pports)
6801 goto bail;
6804 * Determine number of vectors we want; depends on port count
6805 * and number of configured kernel receive queues actually used.
6806 * Should also depend on whether sdma is enabled or not, but
6807 * that's such a rare testing case it's not worth worrying about.
6809 tabsize = dd->first_user_ctxt + ARRAY_SIZE(irq_table);
6810 for (i = 0; i < tabsize; i++)
6811 if ((i < ARRAY_SIZE(irq_table) &&
6812 irq_table[i].port <= dd->num_pports) ||
6813 (i >= ARRAY_SIZE(irq_table) &&
6814 dd->rcd[i - ARRAY_SIZE(irq_table)]))
6815 actual_cnt++;
6816 /* reduce by ctxt's < 2 */
6817 if (qib_krcvq01_no_msi)
6818 actual_cnt -= dd->num_pports;
6820 tabsize = actual_cnt;
6821 dd->cspec->msix_entries = kmalloc(tabsize *
6822 sizeof(struct msix_entry), GFP_KERNEL);
6823 dd->cspec->msix_arg = kmalloc(tabsize *
6824 sizeof(void *), GFP_KERNEL);
6825 if (!dd->cspec->msix_entries || !dd->cspec->msix_arg) {
6826 qib_dev_err(dd, "No memory for MSIx table\n");
6827 tabsize = 0;
6829 for (i = 0; i < tabsize; i++)
6830 dd->cspec->msix_entries[i].entry = i;
6832 if (qib_pcie_params(dd, 8, &tabsize, dd->cspec->msix_entries))
6833 qib_dev_err(dd, "Failed to setup PCIe or interrupts; "
6834 "continuing anyway\n");
6835 /* may be less than we wanted, if not enough available */
6836 dd->cspec->num_msix_entries = tabsize;
6838 /* setup interrupt handler */
6839 qib_setup_7322_interrupt(dd, 1);
6841 /* clear diagctrl register, in case diags were running and crashed */
6842 qib_write_kreg(dd, kr_hwdiagctrl, 0);
6844 goto bail;
6846 bail_cleanup:
6847 qib_pcie_ddcleanup(dd);
6848 bail_free:
6849 qib_free_devdata(dd);
6850 dd = ERR_PTR(ret);
6851 bail:
6852 return dd;
6856 * Set the table entry at the specified index from the table specifed.
6857 * There are 3 * TXDDS_TABLE_SZ entries in all per port, with the first
6858 * TXDDS_TABLE_SZ for SDR, the next for DDR, and the last for QDR.
6859 * 'idx' below addresses the correct entry, while its 4 LSBs select the
6860 * corresponding entry (one of TXDDS_TABLE_SZ) from the selected table.
6862 #define DDS_ENT_AMP_LSB 14
6863 #define DDS_ENT_MAIN_LSB 9
6864 #define DDS_ENT_POST_LSB 5
6865 #define DDS_ENT_PRE_XTRA_LSB 3
6866 #define DDS_ENT_PRE_LSB 0
6869 * Set one entry in the TxDDS table for spec'd port
6870 * ridx picks one of the entries, while tp points
6871 * to the appropriate table entry.
6873 static void set_txdds(struct qib_pportdata *ppd, int ridx,
6874 const struct txdds_ent *tp)
6876 struct qib_devdata *dd = ppd->dd;
6877 u32 pack_ent;
6878 int regidx;
6880 /* Get correct offset in chip-space, and in source table */
6881 regidx = KREG_IBPORT_IDX(IBSD_DDS_MAP_TABLE) + ridx;
6883 * We do not use qib_write_kreg_port() because it was intended
6884 * only for registers in the lower "port specific" pages.
6885 * So do index calculation by hand.
6887 if (ppd->hw_pidx)
6888 regidx += (dd->palign / sizeof(u64));
6890 pack_ent = tp->amp << DDS_ENT_AMP_LSB;
6891 pack_ent |= tp->main << DDS_ENT_MAIN_LSB;
6892 pack_ent |= tp->pre << DDS_ENT_PRE_LSB;
6893 pack_ent |= tp->post << DDS_ENT_POST_LSB;
6894 qib_write_kreg(dd, regidx, pack_ent);
6895 /* Prevent back-to-back writes by hitting scratch */
6896 qib_write_kreg(ppd->dd, kr_scratch, 0);
6899 static const struct vendor_txdds_ent vendor_txdds[] = {
6900 { /* Amphenol 1m 30awg NoEq */
6901 { 0x41, 0x50, 0x48 }, "584470002 ",
6902 { 10, 0, 0, 5 }, { 10, 0, 0, 9 }, { 7, 1, 0, 13 },
6904 { /* Amphenol 3m 28awg NoEq */
6905 { 0x41, 0x50, 0x48 }, "584470004 ",
6906 { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 7, 15 },
6908 { /* Finisar 3m OM2 Optical */
6909 { 0x00, 0x90, 0x65 }, "FCBG410QB1C03-QL",
6910 { 0, 0, 0, 3 }, { 0, 0, 0, 4 }, { 0, 0, 0, 13 },
6912 { /* Finisar 30m OM2 Optical */
6913 { 0x00, 0x90, 0x65 }, "FCBG410QB1C30-QL",
6914 { 0, 0, 0, 1 }, { 0, 0, 0, 5 }, { 0, 0, 0, 11 },
6916 { /* Finisar Default OM2 Optical */
6917 { 0x00, 0x90, 0x65 }, NULL,
6918 { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 0, 0, 12 },
6920 { /* Gore 1m 30awg NoEq */
6921 { 0x00, 0x21, 0x77 }, "QSN3300-1 ",
6922 { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 0, 15 },
6924 { /* Gore 2m 30awg NoEq */
6925 { 0x00, 0x21, 0x77 }, "QSN3300-2 ",
6926 { 0, 0, 0, 8 }, { 0, 0, 0, 10 }, { 0, 1, 7, 15 },
6928 { /* Gore 1m 28awg NoEq */
6929 { 0x00, 0x21, 0x77 }, "QSN3800-1 ",
6930 { 0, 0, 0, 6 }, { 0, 0, 0, 8 }, { 0, 1, 0, 15 },
6932 { /* Gore 3m 28awg NoEq */
6933 { 0x00, 0x21, 0x77 }, "QSN3800-3 ",
6934 { 0, 0, 0, 9 }, { 0, 0, 0, 13 }, { 0, 1, 7, 15 },
6936 { /* Gore 5m 24awg Eq */
6937 { 0x00, 0x21, 0x77 }, "QSN7000-5 ",
6938 { 0, 0, 0, 7 }, { 0, 0, 0, 9 }, { 0, 1, 3, 15 },
6940 { /* Gore 7m 24awg Eq */
6941 { 0x00, 0x21, 0x77 }, "QSN7000-7 ",
6942 { 0, 0, 0, 9 }, { 0, 0, 0, 11 }, { 0, 2, 6, 15 },
6944 { /* Gore 5m 26awg Eq */
6945 { 0x00, 0x21, 0x77 }, "QSN7600-5 ",
6946 { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 9, 13 },
6948 { /* Gore 7m 26awg Eq */
6949 { 0x00, 0x21, 0x77 }, "QSN7600-7 ",
6950 { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 10, 1, 8, 15 },
6952 { /* Intersil 12m 24awg Active */
6953 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1224",
6954 { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 3, 0, 9 },
6956 { /* Intersil 10m 28awg Active */
6957 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1028",
6958 { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 2, 0, 2 },
6960 { /* Intersil 7m 30awg Active */
6961 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0730",
6962 { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 1, 0, 3 },
6964 { /* Intersil 5m 32awg Active */
6965 { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0532",
6966 { 0, 0, 0, 6 }, { 0, 0, 0, 6 }, { 0, 2, 0, 8 },
6968 { /* Intersil Default Active */
6969 { 0x00, 0x30, 0xB4 }, NULL,
6970 { 0, 0, 0, 6 }, { 0, 0, 0, 5 }, { 0, 2, 0, 5 },
6972 { /* Luxtera 20m Active Optical */
6973 { 0x00, 0x25, 0x63 }, NULL,
6974 { 0, 0, 0, 5 }, { 0, 0, 0, 8 }, { 0, 2, 0, 12 },
6976 { /* Molex 1M Cu loopback */
6977 { 0x00, 0x09, 0x3A }, "74763-0025 ",
6978 { 2, 2, 6, 15 }, { 2, 2, 6, 15 }, { 2, 2, 6, 15 },
6980 { /* Molex 2m 28awg NoEq */
6981 { 0x00, 0x09, 0x3A }, "74757-2201 ",
6982 { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 1, 15 },
6986 static const struct txdds_ent txdds_sdr[TXDDS_TABLE_SZ] = {
6987 /* amp, pre, main, post */
6988 { 2, 2, 15, 6 }, /* Loopback */
6989 { 0, 0, 0, 1 }, /* 2 dB */
6990 { 0, 0, 0, 2 }, /* 3 dB */
6991 { 0, 0, 0, 3 }, /* 4 dB */
6992 { 0, 0, 0, 4 }, /* 5 dB */
6993 { 0, 0, 0, 5 }, /* 6 dB */
6994 { 0, 0, 0, 6 }, /* 7 dB */
6995 { 0, 0, 0, 7 }, /* 8 dB */
6996 { 0, 0, 0, 8 }, /* 9 dB */
6997 { 0, 0, 0, 9 }, /* 10 dB */
6998 { 0, 0, 0, 10 }, /* 11 dB */
6999 { 0, 0, 0, 11 }, /* 12 dB */
7000 { 0, 0, 0, 12 }, /* 13 dB */
7001 { 0, 0, 0, 13 }, /* 14 dB */
7002 { 0, 0, 0, 14 }, /* 15 dB */
7003 { 0, 0, 0, 15 }, /* 16 dB */
7006 static const struct txdds_ent txdds_ddr[TXDDS_TABLE_SZ] = {
7007 /* amp, pre, main, post */
7008 { 2, 2, 15, 6 }, /* Loopback */
7009 { 0, 0, 0, 8 }, /* 2 dB */
7010 { 0, 0, 0, 8 }, /* 3 dB */
7011 { 0, 0, 0, 9 }, /* 4 dB */
7012 { 0, 0, 0, 9 }, /* 5 dB */
7013 { 0, 0, 0, 10 }, /* 6 dB */
7014 { 0, 0, 0, 10 }, /* 7 dB */
7015 { 0, 0, 0, 11 }, /* 8 dB */
7016 { 0, 0, 0, 11 }, /* 9 dB */
7017 { 0, 0, 0, 12 }, /* 10 dB */
7018 { 0, 0, 0, 12 }, /* 11 dB */
7019 { 0, 0, 0, 13 }, /* 12 dB */
7020 { 0, 0, 0, 13 }, /* 13 dB */
7021 { 0, 0, 0, 14 }, /* 14 dB */
7022 { 0, 0, 0, 14 }, /* 15 dB */
7023 { 0, 0, 0, 15 }, /* 16 dB */
7026 static const struct txdds_ent txdds_qdr[TXDDS_TABLE_SZ] = {
7027 /* amp, pre, main, post */
7028 { 2, 2, 15, 6 }, /* Loopback */
7029 { 0, 1, 0, 7 }, /* 2 dB (also QMH7342) */
7030 { 0, 1, 0, 9 }, /* 3 dB (also QMH7342) */
7031 { 0, 1, 0, 11 }, /* 4 dB */
7032 { 0, 1, 0, 13 }, /* 5 dB */
7033 { 0, 1, 0, 15 }, /* 6 dB */
7034 { 0, 1, 3, 15 }, /* 7 dB */
7035 { 0, 1, 7, 15 }, /* 8 dB */
7036 { 0, 1, 7, 15 }, /* 9 dB */
7037 { 0, 1, 8, 15 }, /* 10 dB */
7038 { 0, 1, 9, 15 }, /* 11 dB */
7039 { 0, 1, 10, 15 }, /* 12 dB */
7040 { 0, 2, 6, 15 }, /* 13 dB */
7041 { 0, 2, 7, 15 }, /* 14 dB */
7042 { 0, 2, 8, 15 }, /* 15 dB */
7043 { 0, 2, 9, 15 }, /* 16 dB */
7047 * extra entries for use with txselect, for indices >= TXDDS_TABLE_SZ.
7048 * These are mostly used for mez cards going through connectors
7049 * and backplane traces, but can be used to add other "unusual"
7050 * table values as well.
7052 static const struct txdds_ent txdds_extra_sdr[TXDDS_EXTRA_SZ] = {
7053 /* amp, pre, main, post */
7054 { 0, 0, 0, 1 }, /* QMH7342 backplane settings */
7055 { 0, 0, 0, 1 }, /* QMH7342 backplane settings */
7056 { 0, 0, 0, 2 }, /* QMH7342 backplane settings */
7057 { 0, 0, 0, 2 }, /* QMH7342 backplane settings */
7058 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
7059 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
7060 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
7061 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
7062 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
7063 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
7064 { 0, 0, 0, 11 }, /* QME7342 backplane settings */
7065 { 0, 0, 0, 3 }, /* QMH7342 backplane settings */
7066 { 0, 0, 0, 4 }, /* QMH7342 backplane settings */
7069 static const struct txdds_ent txdds_extra_ddr[TXDDS_EXTRA_SZ] = {
7070 /* amp, pre, main, post */
7071 { 0, 0, 0, 7 }, /* QMH7342 backplane settings */
7072 { 0, 0, 0, 7 }, /* QMH7342 backplane settings */
7073 { 0, 0, 0, 8 }, /* QMH7342 backplane settings */
7074 { 0, 0, 0, 8 }, /* QMH7342 backplane settings */
7075 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
7076 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
7077 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
7078 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
7079 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
7080 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
7081 { 0, 0, 0, 13 }, /* QME7342 backplane settings */
7082 { 0, 0, 0, 9 }, /* QMH7342 backplane settings */
7083 { 0, 0, 0, 10 }, /* QMH7342 backplane settings */
7086 static const struct txdds_ent txdds_extra_qdr[TXDDS_EXTRA_SZ] = {
7087 /* amp, pre, main, post */
7088 { 0, 1, 0, 4 }, /* QMH7342 backplane settings */
7089 { 0, 1, 0, 5 }, /* QMH7342 backplane settings */
7090 { 0, 1, 0, 6 }, /* QMH7342 backplane settings */
7091 { 0, 1, 0, 8 }, /* QMH7342 backplane settings */
7092 { 0, 1, 12, 10 }, /* QME7342 backplane setting */
7093 { 0, 1, 12, 11 }, /* QME7342 backplane setting */
7094 { 0, 1, 12, 12 }, /* QME7342 backplane setting */
7095 { 0, 1, 12, 14 }, /* QME7342 backplane setting */
7096 { 0, 1, 12, 6 }, /* QME7342 backplane setting */
7097 { 0, 1, 12, 7 }, /* QME7342 backplane setting */
7098 { 0, 1, 12, 8 }, /* QME7342 backplane setting */
7099 { 0, 1, 0, 10 }, /* QMH7342 backplane settings */
7100 { 0, 1, 0, 12 }, /* QMH7342 backplane settings */
7103 static const struct txdds_ent txdds_extra_mfg[TXDDS_MFG_SZ] = {
7104 /* amp, pre, main, post */
7105 { 0, 0, 0, 0 }, /* QME7342 mfg settings */
7106 { 0, 0, 0, 6 }, /* QME7342 P2 mfg settings */
7109 static const struct txdds_ent *get_atten_table(const struct txdds_ent *txdds,
7110 unsigned atten)
7113 * The attenuation table starts at 2dB for entry 1,
7114 * with entry 0 being the loopback entry.
7116 if (atten <= 2)
7117 atten = 1;
7118 else if (atten > TXDDS_TABLE_SZ)
7119 atten = TXDDS_TABLE_SZ - 1;
7120 else
7121 atten--;
7122 return txdds + atten;
7126 * if override is set, the module parameter txselect has a value
7127 * for this specific port, so use it, rather than our normal mechanism.
7129 static void find_best_ent(struct qib_pportdata *ppd,
7130 const struct txdds_ent **sdr_dds,
7131 const struct txdds_ent **ddr_dds,
7132 const struct txdds_ent **qdr_dds, int override)
7134 struct qib_qsfp_cache *qd = &ppd->cpspec->qsfp_data.cache;
7135 int idx;
7137 /* Search table of known cables */
7138 for (idx = 0; !override && idx < ARRAY_SIZE(vendor_txdds); ++idx) {
7139 const struct vendor_txdds_ent *v = vendor_txdds + idx;
7141 if (!memcmp(v->oui, qd->oui, QSFP_VOUI_LEN) &&
7142 (!v->partnum ||
7143 !memcmp(v->partnum, qd->partnum, QSFP_PN_LEN))) {
7144 *sdr_dds = &v->sdr;
7145 *ddr_dds = &v->ddr;
7146 *qdr_dds = &v->qdr;
7147 return;
7151 /* Lookup serdes setting by cable type and attenuation */
7152 if (!override && QSFP_IS_ACTIVE(qd->tech)) {
7153 *sdr_dds = txdds_sdr + ppd->dd->board_atten;
7154 *ddr_dds = txdds_ddr + ppd->dd->board_atten;
7155 *qdr_dds = txdds_qdr + ppd->dd->board_atten;
7156 return;
7159 if (!override && QSFP_HAS_ATTEN(qd->tech) && (qd->atten[0] ||
7160 qd->atten[1])) {
7161 *sdr_dds = get_atten_table(txdds_sdr, qd->atten[0]);
7162 *ddr_dds = get_atten_table(txdds_ddr, qd->atten[0]);
7163 *qdr_dds = get_atten_table(txdds_qdr, qd->atten[1]);
7164 return;
7165 } else if (ppd->cpspec->no_eep < TXDDS_TABLE_SZ) {
7167 * If we have no (or incomplete) data from the cable
7168 * EEPROM, or no QSFP, or override is set, use the
7169 * module parameter value to index into the attentuation
7170 * table.
7172 idx = ppd->cpspec->no_eep;
7173 *sdr_dds = &txdds_sdr[idx];
7174 *ddr_dds = &txdds_ddr[idx];
7175 *qdr_dds = &txdds_qdr[idx];
7176 } else if (ppd->cpspec->no_eep < (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ)) {
7177 /* similar to above, but index into the "extra" table. */
7178 idx = ppd->cpspec->no_eep - TXDDS_TABLE_SZ;
7179 *sdr_dds = &txdds_extra_sdr[idx];
7180 *ddr_dds = &txdds_extra_ddr[idx];
7181 *qdr_dds = &txdds_extra_qdr[idx];
7182 } else if ((IS_QME(ppd->dd) || IS_QMH(ppd->dd)) &&
7183 ppd->cpspec->no_eep < (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
7184 TXDDS_MFG_SZ)) {
7185 idx = ppd->cpspec->no_eep - (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ);
7186 printk(KERN_INFO QIB_DRV_NAME
7187 " IB%u:%u use idx %u into txdds_mfg\n",
7188 ppd->dd->unit, ppd->port, idx);
7189 *sdr_dds = &txdds_extra_mfg[idx];
7190 *ddr_dds = &txdds_extra_mfg[idx];
7191 *qdr_dds = &txdds_extra_mfg[idx];
7192 } else {
7193 /* this shouldn't happen, it's range checked */
7194 *sdr_dds = txdds_sdr + qib_long_atten;
7195 *ddr_dds = txdds_ddr + qib_long_atten;
7196 *qdr_dds = txdds_qdr + qib_long_atten;
7200 static void init_txdds_table(struct qib_pportdata *ppd, int override)
7202 const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
7203 struct txdds_ent *dds;
7204 int idx;
7205 int single_ent = 0;
7207 find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, override);
7209 /* for mez cards or override, use the selected value for all entries */
7210 if (!(ppd->dd->flags & QIB_HAS_QSFP) || override)
7211 single_ent = 1;
7213 /* Fill in the first entry with the best entry found. */
7214 set_txdds(ppd, 0, sdr_dds);
7215 set_txdds(ppd, TXDDS_TABLE_SZ, ddr_dds);
7216 set_txdds(ppd, 2 * TXDDS_TABLE_SZ, qdr_dds);
7217 if (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
7218 QIBL_LINKACTIVE)) {
7219 dds = (struct txdds_ent *)(ppd->link_speed_active ==
7220 QIB_IB_QDR ? qdr_dds :
7221 (ppd->link_speed_active ==
7222 QIB_IB_DDR ? ddr_dds : sdr_dds));
7223 write_tx_serdes_param(ppd, dds);
7226 /* Fill in the remaining entries with the default table values. */
7227 for (idx = 1; idx < ARRAY_SIZE(txdds_sdr); ++idx) {
7228 set_txdds(ppd, idx, single_ent ? sdr_dds : txdds_sdr + idx);
7229 set_txdds(ppd, idx + TXDDS_TABLE_SZ,
7230 single_ent ? ddr_dds : txdds_ddr + idx);
7231 set_txdds(ppd, idx + 2 * TXDDS_TABLE_SZ,
7232 single_ent ? qdr_dds : txdds_qdr + idx);
7236 #define KR_AHB_ACC KREG_IDX(ahb_access_ctrl)
7237 #define KR_AHB_TRANS KREG_IDX(ahb_transaction_reg)
7238 #define AHB_TRANS_RDY SYM_MASK(ahb_transaction_reg, ahb_rdy)
7239 #define AHB_ADDR_LSB SYM_LSB(ahb_transaction_reg, ahb_address)
7240 #define AHB_DATA_LSB SYM_LSB(ahb_transaction_reg, ahb_data)
7241 #define AHB_WR SYM_MASK(ahb_transaction_reg, write_not_read)
7242 #define AHB_TRANS_TRIES 10
7245 * The chan argument is 0=chan0, 1=chan1, 2=pll, 3=chan2, 4=chan4,
7246 * 5=subsystem which is why most calls have "chan + chan >> 1"
7247 * for the channel argument.
7249 static u32 ahb_mod(struct qib_devdata *dd, int quad, int chan, int addr,
7250 u32 data, u32 mask)
7252 u32 rd_data, wr_data, sz_mask;
7253 u64 trans, acc, prev_acc;
7254 u32 ret = 0xBAD0BAD;
7255 int tries;
7257 prev_acc = qib_read_kreg64(dd, KR_AHB_ACC);
7258 /* From this point on, make sure we return access */
7259 acc = (quad << 1) | 1;
7260 qib_write_kreg(dd, KR_AHB_ACC, acc);
7262 for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
7263 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7264 if (trans & AHB_TRANS_RDY)
7265 break;
7267 if (tries >= AHB_TRANS_TRIES) {
7268 qib_dev_err(dd, "No ahb_rdy in %d tries\n", AHB_TRANS_TRIES);
7269 goto bail;
7272 /* If mask is not all 1s, we need to read, but different SerDes
7273 * entities have different sizes
7275 sz_mask = (1UL << ((quad == 1) ? 32 : 16)) - 1;
7276 wr_data = data & mask & sz_mask;
7277 if ((~mask & sz_mask) != 0) {
7278 trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
7279 qib_write_kreg(dd, KR_AHB_TRANS, trans);
7281 for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
7282 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7283 if (trans & AHB_TRANS_RDY)
7284 break;
7286 if (tries >= AHB_TRANS_TRIES) {
7287 qib_dev_err(dd, "No Rd ahb_rdy in %d tries\n",
7288 AHB_TRANS_TRIES);
7289 goto bail;
7291 /* Re-read in case host split reads and read data first */
7292 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7293 rd_data = (uint32_t)(trans >> AHB_DATA_LSB);
7294 wr_data |= (rd_data & ~mask & sz_mask);
7297 /* If mask is not zero, we need to write. */
7298 if (mask & sz_mask) {
7299 trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
7300 trans |= ((uint64_t)wr_data << AHB_DATA_LSB);
7301 trans |= AHB_WR;
7302 qib_write_kreg(dd, KR_AHB_TRANS, trans);
7304 for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
7305 trans = qib_read_kreg64(dd, KR_AHB_TRANS);
7306 if (trans & AHB_TRANS_RDY)
7307 break;
7309 if (tries >= AHB_TRANS_TRIES) {
7310 qib_dev_err(dd, "No Wr ahb_rdy in %d tries\n",
7311 AHB_TRANS_TRIES);
7312 goto bail;
7315 ret = wr_data;
7316 bail:
7317 qib_write_kreg(dd, KR_AHB_ACC, prev_acc);
7318 return ret;
7321 static void ibsd_wr_allchans(struct qib_pportdata *ppd, int addr, unsigned data,
7322 unsigned mask)
7324 struct qib_devdata *dd = ppd->dd;
7325 int chan;
7326 u32 rbc;
7328 for (chan = 0; chan < SERDES_CHANS; ++chan) {
7329 ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)), addr,
7330 data, mask);
7331 rbc = ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7332 addr, 0, 0);
7336 static void serdes_7322_los_enable(struct qib_pportdata *ppd, int enable)
7338 u64 data = qib_read_kreg_port(ppd, krp_serdesctrl);
7339 u8 state = SYM_FIELD(data, IBSerdesCtrl_0, RXLOSEN);
7341 if (enable && !state) {
7342 printk(KERN_INFO QIB_DRV_NAME " IB%u:%u Turning LOS on\n",
7343 ppd->dd->unit, ppd->port);
7344 data |= SYM_MASK(IBSerdesCtrl_0, RXLOSEN);
7345 } else if (!enable && state) {
7346 printk(KERN_INFO QIB_DRV_NAME " IB%u:%u Turning LOS off\n",
7347 ppd->dd->unit, ppd->port);
7348 data &= ~SYM_MASK(IBSerdesCtrl_0, RXLOSEN);
7350 qib_write_kreg_port(ppd, krp_serdesctrl, data);
7353 static int serdes_7322_init(struct qib_pportdata *ppd)
7355 int ret = 0;
7356 if (ppd->dd->cspec->r1)
7357 ret = serdes_7322_init_old(ppd);
7358 else
7359 ret = serdes_7322_init_new(ppd);
7360 return ret;
7363 static int serdes_7322_init_old(struct qib_pportdata *ppd)
7365 u32 le_val;
7368 * Initialize the Tx DDS tables. Also done every QSFP event,
7369 * for adapters with QSFP
7371 init_txdds_table(ppd, 0);
7373 /* ensure no tx overrides from earlier driver loads */
7374 qib_write_kreg_port(ppd, krp_tx_deemph_override,
7375 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7376 reset_tx_deemphasis_override));
7378 /* Patch some SerDes defaults to "Better for IB" */
7379 /* Timing Loop Bandwidth: cdr_timing[11:9] = 0 */
7380 ibsd_wr_allchans(ppd, 2, 0, BMASK(11, 9));
7382 /* Termination: rxtermctrl_r2d addr 11 bits [12:11] = 1 */
7383 ibsd_wr_allchans(ppd, 11, (1 << 11), BMASK(12, 11));
7384 /* Enable LE2: rxle2en_r2a addr 13 bit [6] = 1 */
7385 ibsd_wr_allchans(ppd, 13, (1 << 6), (1 << 6));
7387 /* May be overridden in qsfp_7322_event */
7388 le_val = IS_QME(ppd->dd) ? LE2_QME : LE2_DEFAULT;
7389 ibsd_wr_allchans(ppd, 13, (le_val << 7), BMASK(9, 7));
7391 /* enable LE1 adaptation for all but QME, which is disabled */
7392 le_val = IS_QME(ppd->dd) ? 0 : 1;
7393 ibsd_wr_allchans(ppd, 13, (le_val << 5), (1 << 5));
7395 /* Clear cmode-override, may be set from older driver */
7396 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
7398 /* Timing Recovery: rxtapsel addr 5 bits [9:8] = 0 */
7399 ibsd_wr_allchans(ppd, 5, (0 << 8), BMASK(9, 8));
7401 /* setup LoS params; these are subsystem, so chan == 5 */
7402 /* LoS filter threshold_count on, ch 0-3, set to 8 */
7403 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 5, 8 << 11, BMASK(14, 11));
7404 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 8 << 4, BMASK(7, 4));
7405 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 8, 8 << 11, BMASK(14, 11));
7406 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 8 << 4, BMASK(7, 4));
7408 /* LoS filter threshold_count off, ch 0-3, set to 4 */
7409 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 6, 4 << 0, BMASK(3, 0));
7410 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 4 << 8, BMASK(11, 8));
7411 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 4 << 0, BMASK(3, 0));
7412 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 4 << 8, BMASK(11, 8));
7414 /* LoS filter select enabled */
7415 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 1 << 15, 1 << 15);
7417 /* LoS target data: SDR=4, DDR=2, QDR=1 */
7418 ibsd_wr_allchans(ppd, 14, (1 << 3), BMASK(5, 3)); /* QDR */
7419 ibsd_wr_allchans(ppd, 20, (2 << 10), BMASK(12, 10)); /* DDR */
7420 ibsd_wr_allchans(ppd, 20, (4 << 13), BMASK(15, 13)); /* SDR */
7422 serdes_7322_los_enable(ppd, 1);
7424 /* rxbistena; set 0 to avoid effects of it switch later */
7425 ibsd_wr_allchans(ppd, 9, 0 << 15, 1 << 15);
7427 /* Configure 4 DFE taps, and only they adapt */
7428 ibsd_wr_allchans(ppd, 16, 0 << 0, BMASK(1, 0));
7430 /* gain hi stop 32 (22) (6:1) lo stop 7 (10:7) target 22 (13) (15:11) */
7431 le_val = (ppd->dd->cspec->r1 || IS_QME(ppd->dd)) ? 0xb6c0 : 0x6bac;
7432 ibsd_wr_allchans(ppd, 21, le_val, 0xfffe);
7435 * Set receive adaptation mode. SDR and DDR adaptation are
7436 * always on, and QDR is initially enabled; later disabled.
7438 qib_write_kreg_port(ppd, krp_static_adapt_dis(0), 0ULL);
7439 qib_write_kreg_port(ppd, krp_static_adapt_dis(1), 0ULL);
7440 qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
7441 ppd->dd->cspec->r1 ?
7442 QDR_STATIC_ADAPT_DOWN_R1 : QDR_STATIC_ADAPT_DOWN);
7443 ppd->cpspec->qdr_dfe_on = 1;
7445 /* FLoop LOS gate: PPM filter enabled */
7446 ibsd_wr_allchans(ppd, 38, 0 << 10, 1 << 10);
7448 /* rx offset center enabled */
7449 ibsd_wr_allchans(ppd, 12, 1 << 4, 1 << 4);
7451 if (!ppd->dd->cspec->r1) {
7452 ibsd_wr_allchans(ppd, 12, 1 << 12, 1 << 12);
7453 ibsd_wr_allchans(ppd, 12, 2 << 8, 0x0f << 8);
7456 /* Set the frequency loop bandwidth to 15 */
7457 ibsd_wr_allchans(ppd, 2, 15 << 5, BMASK(8, 5));
7459 return 0;
7462 static int serdes_7322_init_new(struct qib_pportdata *ppd)
7464 u64 tstart;
7465 u32 le_val, rxcaldone;
7466 int chan, chan_done = (1 << SERDES_CHANS) - 1;
7469 * Initialize the Tx DDS tables. Also done every QSFP event,
7470 * for adapters with QSFP
7472 init_txdds_table(ppd, 0);
7474 /* Clear cmode-override, may be set from older driver */
7475 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
7477 /* ensure no tx overrides from earlier driver loads */
7478 qib_write_kreg_port(ppd, krp_tx_deemph_override,
7479 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7480 reset_tx_deemphasis_override));
7482 /* START OF LSI SUGGESTED SERDES BRINGUP */
7483 /* Reset - Calibration Setup */
7484 /* Stop DFE adaptaion */
7485 ibsd_wr_allchans(ppd, 1, 0, BMASK(9, 1));
7486 /* Disable LE1 */
7487 ibsd_wr_allchans(ppd, 13, 0, BMASK(5, 5));
7488 /* Disable autoadapt for LE1 */
7489 ibsd_wr_allchans(ppd, 1, 0, BMASK(15, 15));
7490 /* Disable LE2 */
7491 ibsd_wr_allchans(ppd, 13, 0, BMASK(6, 6));
7492 /* Disable VGA */
7493 ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0));
7494 /* Disable AFE Offset Cancel */
7495 ibsd_wr_allchans(ppd, 12, 0, BMASK(12, 12));
7496 /* Disable Timing Loop */
7497 ibsd_wr_allchans(ppd, 2, 0, BMASK(3, 3));
7498 /* Disable Frequency Loop */
7499 ibsd_wr_allchans(ppd, 2, 0, BMASK(4, 4));
7500 /* Disable Baseline Wander Correction */
7501 ibsd_wr_allchans(ppd, 13, 0, BMASK(13, 13));
7502 /* Disable RX Calibration */
7503 ibsd_wr_allchans(ppd, 4, 0, BMASK(10, 10));
7504 /* Disable RX Offset Calibration */
7505 ibsd_wr_allchans(ppd, 12, 0, BMASK(4, 4));
7506 /* Select BB CDR */
7507 ibsd_wr_allchans(ppd, 2, (1 << 15), BMASK(15, 15));
7508 /* CDR Step Size */
7509 ibsd_wr_allchans(ppd, 5, 0, BMASK(9, 8));
7510 /* Enable phase Calibration */
7511 ibsd_wr_allchans(ppd, 12, (1 << 5), BMASK(5, 5));
7512 /* DFE Bandwidth [2:14-12] */
7513 ibsd_wr_allchans(ppd, 2, (4 << 12), BMASK(14, 12));
7514 /* DFE Config (4 taps only) */
7515 ibsd_wr_allchans(ppd, 16, 0, BMASK(1, 0));
7516 /* Gain Loop Bandwidth */
7517 if (!ppd->dd->cspec->r1) {
7518 ibsd_wr_allchans(ppd, 12, 1 << 12, BMASK(12, 12));
7519 ibsd_wr_allchans(ppd, 12, 2 << 8, BMASK(11, 8));
7520 } else {
7521 ibsd_wr_allchans(ppd, 19, (3 << 11), BMASK(13, 11));
7523 /* Baseline Wander Correction Gain [13:4-0] (leave as default) */
7524 /* Baseline Wander Correction Gain [3:7-5] (leave as default) */
7525 /* Data Rate Select [5:7-6] (leave as default) */
7526 /* RX Parallel Word Width [3:10-8] (leave as default) */
7528 /* RX REST */
7529 /* Single- or Multi-channel reset */
7530 /* RX Analog reset */
7531 /* RX Digital reset */
7532 ibsd_wr_allchans(ppd, 0, 0, BMASK(15, 13));
7533 msleep(20);
7534 /* RX Analog reset */
7535 ibsd_wr_allchans(ppd, 0, (1 << 14), BMASK(14, 14));
7536 msleep(20);
7537 /* RX Digital reset */
7538 ibsd_wr_allchans(ppd, 0, (1 << 13), BMASK(13, 13));
7539 msleep(20);
7541 /* setup LoS params; these are subsystem, so chan == 5 */
7542 /* LoS filter threshold_count on, ch 0-3, set to 8 */
7543 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 5, 8 << 11, BMASK(14, 11));
7544 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 8 << 4, BMASK(7, 4));
7545 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 8, 8 << 11, BMASK(14, 11));
7546 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 8 << 4, BMASK(7, 4));
7548 /* LoS filter threshold_count off, ch 0-3, set to 4 */
7549 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 6, 4 << 0, BMASK(3, 0));
7550 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 4 << 8, BMASK(11, 8));
7551 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 4 << 0, BMASK(3, 0));
7552 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 4 << 8, BMASK(11, 8));
7554 /* LoS filter select enabled */
7555 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 1 << 15, 1 << 15);
7557 /* LoS target data: SDR=4, DDR=2, QDR=1 */
7558 ibsd_wr_allchans(ppd, 14, (1 << 3), BMASK(5, 3)); /* QDR */
7559 ibsd_wr_allchans(ppd, 20, (2 << 10), BMASK(12, 10)); /* DDR */
7560 ibsd_wr_allchans(ppd, 20, (4 << 13), BMASK(15, 13)); /* SDR */
7562 /* Turn on LOS on initial SERDES init */
7563 serdes_7322_los_enable(ppd, 1);
7564 /* FLoop LOS gate: PPM filter enabled */
7565 ibsd_wr_allchans(ppd, 38, 0 << 10, 1 << 10);
7567 /* RX LATCH CALIBRATION */
7568 /* Enable Eyefinder Phase Calibration latch */
7569 ibsd_wr_allchans(ppd, 15, 1, BMASK(0, 0));
7570 /* Enable RX Offset Calibration latch */
7571 ibsd_wr_allchans(ppd, 12, (1 << 4), BMASK(4, 4));
7572 msleep(20);
7573 /* Start Calibration */
7574 ibsd_wr_allchans(ppd, 4, (1 << 10), BMASK(10, 10));
7575 tstart = get_jiffies_64();
7576 while (chan_done &&
7577 !time_after64(get_jiffies_64(),
7578 tstart + msecs_to_jiffies(500))) {
7579 msleep(20);
7580 for (chan = 0; chan < SERDES_CHANS; ++chan) {
7581 rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx),
7582 (chan + (chan >> 1)),
7583 25, 0, 0);
7584 if ((~rxcaldone & (u32)BMASK(9, 9)) == 0 &&
7585 (~chan_done & (1 << chan)) == 0)
7586 chan_done &= ~(1 << chan);
7589 if (chan_done) {
7590 printk(KERN_INFO QIB_DRV_NAME
7591 " Serdes %d calibration not done after .5 sec: 0x%x\n",
7592 IBSD(ppd->hw_pidx), chan_done);
7593 } else {
7594 for (chan = 0; chan < SERDES_CHANS; ++chan) {
7595 rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx),
7596 (chan + (chan >> 1)),
7597 25, 0, 0);
7598 if ((~rxcaldone & (u32)BMASK(10, 10)) == 0)
7599 printk(KERN_INFO QIB_DRV_NAME
7600 " Serdes %d chan %d calibration "
7601 "failed\n", IBSD(ppd->hw_pidx), chan);
7605 /* Turn off Calibration */
7606 ibsd_wr_allchans(ppd, 4, 0, BMASK(10, 10));
7607 msleep(20);
7609 /* BRING RX UP */
7610 /* Set LE2 value (May be overridden in qsfp_7322_event) */
7611 le_val = IS_QME(ppd->dd) ? LE2_QME : LE2_DEFAULT;
7612 ibsd_wr_allchans(ppd, 13, (le_val << 7), BMASK(9, 7));
7613 /* Set LE2 Loop bandwidth */
7614 ibsd_wr_allchans(ppd, 3, (7 << 5), BMASK(7, 5));
7615 /* Enable LE2 */
7616 ibsd_wr_allchans(ppd, 13, (1 << 6), BMASK(6, 6));
7617 msleep(20);
7618 /* Enable H0 only */
7619 ibsd_wr_allchans(ppd, 1, 1, BMASK(9, 1));
7620 /* gain hi stop 32 (22) (6:1) lo stop 7 (10:7) target 22 (13) (15:11) */
7621 le_val = (ppd->dd->cspec->r1 || IS_QME(ppd->dd)) ? 0xb6c0 : 0x6bac;
7622 ibsd_wr_allchans(ppd, 21, le_val, 0xfffe);
7623 /* Enable VGA */
7624 ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0));
7625 msleep(20);
7626 /* Set Frequency Loop Bandwidth */
7627 ibsd_wr_allchans(ppd, 2, (7 << 5), BMASK(8, 5));
7628 /* Enable Frequency Loop */
7629 ibsd_wr_allchans(ppd, 2, (1 << 4), BMASK(4, 4));
7630 /* Set Timing Loop Bandwidth */
7631 ibsd_wr_allchans(ppd, 2, 0, BMASK(11, 9));
7632 /* Enable Timing Loop */
7633 ibsd_wr_allchans(ppd, 2, (1 << 3), BMASK(3, 3));
7634 msleep(50);
7635 /* Enable DFE
7636 * Set receive adaptation mode. SDR and DDR adaptation are
7637 * always on, and QDR is initially enabled; later disabled.
7639 qib_write_kreg_port(ppd, krp_static_adapt_dis(0), 0ULL);
7640 qib_write_kreg_port(ppd, krp_static_adapt_dis(1), 0ULL);
7641 qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
7642 ppd->dd->cspec->r1 ?
7643 QDR_STATIC_ADAPT_DOWN_R1 : QDR_STATIC_ADAPT_DOWN);
7644 ppd->cpspec->qdr_dfe_on = 1;
7645 /* Disable LE1 */
7646 ibsd_wr_allchans(ppd, 13, (0 << 5), (1 << 5));
7647 /* Disable auto adapt for LE1 */
7648 ibsd_wr_allchans(ppd, 1, (0 << 15), BMASK(15, 15));
7649 msleep(20);
7650 /* Enable AFE Offset Cancel */
7651 ibsd_wr_allchans(ppd, 12, (1 << 12), BMASK(12, 12));
7652 /* Enable Baseline Wander Correction */
7653 ibsd_wr_allchans(ppd, 12, (1 << 13), BMASK(13, 13));
7654 /* Termination: rxtermctrl_r2d addr 11 bits [12:11] = 1 */
7655 ibsd_wr_allchans(ppd, 11, (1 << 11), BMASK(12, 11));
7656 /* VGA output common mode */
7657 ibsd_wr_allchans(ppd, 12, (3 << 2), BMASK(3, 2));
7659 return 0;
7662 /* start adjust QMH serdes parameters */
7664 static void set_man_code(struct qib_pportdata *ppd, int chan, int code)
7666 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7667 9, code << 9, 0x3f << 9);
7670 static void set_man_mode_h1(struct qib_pportdata *ppd, int chan,
7671 int enable, u32 tapenable)
7673 if (enable)
7674 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7675 1, 3 << 10, 0x1f << 10);
7676 else
7677 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7678 1, 0, 0x1f << 10);
7681 /* Set clock to 1, 0, 1, 0 */
7682 static void clock_man(struct qib_pportdata *ppd, int chan)
7684 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7685 4, 0x4000, 0x4000);
7686 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7687 4, 0, 0x4000);
7688 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7689 4, 0x4000, 0x4000);
7690 ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
7691 4, 0, 0x4000);
7695 * write the current Tx serdes pre,post,main,amp settings into the serdes.
7696 * The caller must pass the settings appropriate for the current speed,
7697 * or not care if they are correct for the current speed.
7699 static void write_tx_serdes_param(struct qib_pportdata *ppd,
7700 struct txdds_ent *txdds)
7702 u64 deemph;
7704 deemph = qib_read_kreg_port(ppd, krp_tx_deemph_override);
7705 /* field names for amp, main, post, pre, respectively */
7706 deemph &= ~(SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txampcntl_d2a) |
7707 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txc0_ena) |
7708 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcp1_ena) |
7709 SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcn1_ena));
7711 deemph |= SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7712 tx_override_deemphasis_select);
7713 deemph |= (txdds->amp & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7714 txampcntl_d2a)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7715 txampcntl_d2a);
7716 deemph |= (txdds->main & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7717 txc0_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7718 txc0_ena);
7719 deemph |= (txdds->post & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7720 txcp1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7721 txcp1_ena);
7722 deemph |= (txdds->pre & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7723 txcn1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
7724 txcn1_ena);
7725 qib_write_kreg_port(ppd, krp_tx_deemph_override, deemph);
7729 * Set the parameters for mez cards on link bounce, so they are
7730 * always exactly what was requested. Similar logic to init_txdds
7731 * but does just the serdes.
7733 static void adj_tx_serdes(struct qib_pportdata *ppd)
7735 const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
7736 struct txdds_ent *dds;
7738 find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, 1);
7739 dds = (struct txdds_ent *)(ppd->link_speed_active == QIB_IB_QDR ?
7740 qdr_dds : (ppd->link_speed_active == QIB_IB_DDR ?
7741 ddr_dds : sdr_dds));
7742 write_tx_serdes_param(ppd, dds);
7745 /* set QDR forced value for H1, if needed */
7746 static void force_h1(struct qib_pportdata *ppd)
7748 int chan;
7750 ppd->cpspec->qdr_reforce = 0;
7751 if (!ppd->dd->cspec->r1)
7752 return;
7754 for (chan = 0; chan < SERDES_CHANS; chan++) {
7755 set_man_mode_h1(ppd, chan, 1, 0);
7756 set_man_code(ppd, chan, ppd->cpspec->h1_val);
7757 clock_man(ppd, chan);
7758 set_man_mode_h1(ppd, chan, 0, 0);
7762 #define SJA_EN SYM_MASK(SPC_JTAG_ACCESS_REG, SPC_JTAG_ACCESS_EN)
7763 #define BISTEN_LSB SYM_LSB(SPC_JTAG_ACCESS_REG, bist_en)
7765 #define R_OPCODE_LSB 3
7766 #define R_OP_NOP 0
7767 #define R_OP_SHIFT 2
7768 #define R_OP_UPDATE 3
7769 #define R_TDI_LSB 2
7770 #define R_TDO_LSB 1
7771 #define R_RDY 1
7773 static int qib_r_grab(struct qib_devdata *dd)
7775 u64 val;
7776 val = SJA_EN;
7777 qib_write_kreg(dd, kr_r_access, val);
7778 qib_read_kreg32(dd, kr_scratch);
7779 return 0;
7782 /* qib_r_wait_for_rdy() not only waits for the ready bit, it
7783 * returns the current state of R_TDO
7785 static int qib_r_wait_for_rdy(struct qib_devdata *dd)
7787 u64 val;
7788 int timeout;
7789 for (timeout = 0; timeout < 100 ; ++timeout) {
7790 val = qib_read_kreg32(dd, kr_r_access);
7791 if (val & R_RDY)
7792 return (val >> R_TDO_LSB) & 1;
7794 return -1;
7797 static int qib_r_shift(struct qib_devdata *dd, int bisten,
7798 int len, u8 *inp, u8 *outp)
7800 u64 valbase, val;
7801 int ret, pos;
7803 valbase = SJA_EN | (bisten << BISTEN_LSB) |
7804 (R_OP_SHIFT << R_OPCODE_LSB);
7805 ret = qib_r_wait_for_rdy(dd);
7806 if (ret < 0)
7807 goto bail;
7808 for (pos = 0; pos < len; ++pos) {
7809 val = valbase;
7810 if (outp) {
7811 outp[pos >> 3] &= ~(1 << (pos & 7));
7812 outp[pos >> 3] |= (ret << (pos & 7));
7814 if (inp) {
7815 int tdi = inp[pos >> 3] >> (pos & 7);
7816 val |= ((tdi & 1) << R_TDI_LSB);
7818 qib_write_kreg(dd, kr_r_access, val);
7819 qib_read_kreg32(dd, kr_scratch);
7820 ret = qib_r_wait_for_rdy(dd);
7821 if (ret < 0)
7822 break;
7824 /* Restore to NOP between operations. */
7825 val = SJA_EN | (bisten << BISTEN_LSB);
7826 qib_write_kreg(dd, kr_r_access, val);
7827 qib_read_kreg32(dd, kr_scratch);
7828 ret = qib_r_wait_for_rdy(dd);
7830 if (ret >= 0)
7831 ret = pos;
7832 bail:
7833 return ret;
7836 static int qib_r_update(struct qib_devdata *dd, int bisten)
7838 u64 val;
7839 int ret;
7841 val = SJA_EN | (bisten << BISTEN_LSB) | (R_OP_UPDATE << R_OPCODE_LSB);
7842 ret = qib_r_wait_for_rdy(dd);
7843 if (ret >= 0) {
7844 qib_write_kreg(dd, kr_r_access, val);
7845 qib_read_kreg32(dd, kr_scratch);
7847 return ret;
7850 #define BISTEN_PORT_SEL 15
7851 #define LEN_PORT_SEL 625
7852 #define BISTEN_AT 17
7853 #define LEN_AT 156
7854 #define BISTEN_ETM 16
7855 #define LEN_ETM 632
7857 #define BIT2BYTE(x) (((x) + BITS_PER_BYTE - 1) / BITS_PER_BYTE)
7859 /* these are common for all IB port use cases. */
7860 static u8 reset_at[BIT2BYTE(LEN_AT)] = {
7861 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7862 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
7864 static u8 reset_atetm[BIT2BYTE(LEN_ETM)] = {
7865 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7866 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7867 0x00, 0x00, 0x00, 0x80, 0xe3, 0x81, 0x73, 0x3c, 0x70, 0x8e,
7868 0x07, 0xce, 0xf1, 0xc0, 0x39, 0x1e, 0x38, 0xc7, 0x03, 0xe7,
7869 0x78, 0xe0, 0x1c, 0x0f, 0x9c, 0x7f, 0x80, 0x73, 0x0f, 0x70,
7870 0xde, 0x01, 0xce, 0x39, 0xc0, 0xf9, 0x06, 0x38, 0xd7, 0x00,
7871 0xe7, 0x19, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7872 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
7874 static u8 at[BIT2BYTE(LEN_AT)] = {
7875 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
7876 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
7879 /* used for IB1 or IB2, only one in use */
7880 static u8 atetm_1port[BIT2BYTE(LEN_ETM)] = {
7881 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7882 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7883 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7884 0x00, 0x10, 0xf2, 0x80, 0x83, 0x1e, 0x38, 0x00, 0x00, 0x00,
7885 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7886 0x00, 0x00, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xc8, 0x03,
7887 0x07, 0x7b, 0xa0, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x18, 0x00,
7888 0x18, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00,
7891 /* used when both IB1 and IB2 are in use */
7892 static u8 atetm_2port[BIT2BYTE(LEN_ETM)] = {
7893 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7894 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79,
7895 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7896 0x00, 0x00, 0xf8, 0x80, 0x83, 0x1e, 0x38, 0xe0, 0x03, 0x05,
7897 0x7b, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
7898 0xa2, 0x0f, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xd1, 0x07,
7899 0x02, 0x7c, 0x80, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x3e, 0x00,
7900 0x02, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00,
7903 /* used when only IB1 is in use */
7904 static u8 portsel_port1[BIT2BYTE(LEN_PORT_SEL)] = {
7905 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
7906 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
7907 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
7908 0x13, 0x78, 0x78, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
7909 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
7910 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
7911 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
7912 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
7915 /* used when only IB2 is in use */
7916 static u8 portsel_port2[BIT2BYTE(LEN_PORT_SEL)] = {
7917 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x39, 0x39,
7918 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x73, 0x32, 0x32, 0x32,
7919 0x32, 0x32, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
7920 0x39, 0x78, 0x78, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
7921 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x74, 0x32,
7922 0x32, 0x32, 0x32, 0x32, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
7923 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
7924 0x3a, 0x3a, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
7927 /* used when both IB1 and IB2 are in use */
7928 static u8 portsel_2port[BIT2BYTE(LEN_PORT_SEL)] = {
7929 0x32, 0xba, 0x54, 0x76, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
7930 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
7931 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
7932 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
7933 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
7934 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x3a,
7935 0x3a, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
7936 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
7940 * Do setup to properly handle IB link recovery; if port is zero, we
7941 * are initializing to cover both ports; otherwise we are initializing
7942 * to cover a single port card, or the port has reached INIT and we may
7943 * need to switch coverage types.
7945 static void setup_7322_link_recovery(struct qib_pportdata *ppd, u32 both)
7947 u8 *portsel, *etm;
7948 struct qib_devdata *dd = ppd->dd;
7950 if (!ppd->dd->cspec->r1)
7951 return;
7952 if (!both) {
7953 dd->cspec->recovery_ports_initted++;
7954 ppd->cpspec->recovery_init = 1;
7956 if (!both && dd->cspec->recovery_ports_initted == 1) {
7957 portsel = ppd->port == 1 ? portsel_port1 : portsel_port2;
7958 etm = atetm_1port;
7959 } else {
7960 portsel = portsel_2port;
7961 etm = atetm_2port;
7964 if (qib_r_grab(dd) < 0 ||
7965 qib_r_shift(dd, BISTEN_ETM, LEN_ETM, reset_atetm, NULL) < 0 ||
7966 qib_r_update(dd, BISTEN_ETM) < 0 ||
7967 qib_r_shift(dd, BISTEN_AT, LEN_AT, reset_at, NULL) < 0 ||
7968 qib_r_update(dd, BISTEN_AT) < 0 ||
7969 qib_r_shift(dd, BISTEN_PORT_SEL, LEN_PORT_SEL,
7970 portsel, NULL) < 0 ||
7971 qib_r_update(dd, BISTEN_PORT_SEL) < 0 ||
7972 qib_r_shift(dd, BISTEN_AT, LEN_AT, at, NULL) < 0 ||
7973 qib_r_update(dd, BISTEN_AT) < 0 ||
7974 qib_r_shift(dd, BISTEN_ETM, LEN_ETM, etm, NULL) < 0 ||
7975 qib_r_update(dd, BISTEN_ETM) < 0)
7976 qib_dev_err(dd, "Failed IB link recovery setup\n");
7979 static void check_7322_rxe_status(struct qib_pportdata *ppd)
7981 struct qib_devdata *dd = ppd->dd;
7982 u64 fmask;
7984 if (dd->cspec->recovery_ports_initted != 1)
7985 return; /* rest doesn't apply to dualport */
7986 qib_write_kreg(dd, kr_control, dd->control |
7987 SYM_MASK(Control, FreezeMode));
7988 (void)qib_read_kreg64(dd, kr_scratch);
7989 udelay(3); /* ibcreset asserted 400ns, be sure that's over */
7990 fmask = qib_read_kreg64(dd, kr_act_fmask);
7991 if (!fmask) {
7993 * require a powercycle before we'll work again, and make
7994 * sure we get no more interrupts, and don't turn off
7995 * freeze.
7997 ppd->dd->cspec->stay_in_freeze = 1;
7998 qib_7322_set_intr_state(ppd->dd, 0);
7999 qib_write_kreg(dd, kr_fmask, 0ULL);
8000 qib_dev_err(dd, "HCA unusable until powercycled\n");
8001 return; /* eventually reset */
8004 qib_write_kreg(ppd->dd, kr_hwerrclear,
8005 SYM_MASK(HwErrClear, IBSerdesPClkNotDetectClear_1));
8007 /* don't do the full clear_freeze(), not needed for this */
8008 qib_write_kreg(dd, kr_control, dd->control);
8009 qib_read_kreg32(dd, kr_scratch);
8010 /* take IBC out of reset */
8011 if (ppd->link_speed_supported) {
8012 ppd->cpspec->ibcctrl_a &=
8013 ~SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
8014 qib_write_kreg_port(ppd, krp_ibcctrl_a,
8015 ppd->cpspec->ibcctrl_a);
8016 qib_read_kreg32(dd, kr_scratch);
8017 if (ppd->lflags & QIBL_IB_LINK_DISABLED)
8018 qib_set_ib_7322_lstate(ppd, 0,
8019 QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);