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