2 * Copyright (c) 2006, 2007, 2008 QLogic Corporation. All rights reserved.
3 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 * This file contains all of the code that is specific to the SerDes
35 * on the InfiniPath 7220 chip.
38 #include <linux/pci.h>
39 #include <linux/delay.h>
41 #include "ipath_kernel.h"
42 #include "ipath_registers.h"
43 #include "ipath_7220.h"
46 * The IBSerDesMappTable is a memory that holds values to be stored in
47 * various SerDes registers by IBC. It is not part of the normal kregs
48 * map and is used in exactly one place, hence the #define below.
50 #define KR_IBSerDesMappTable (0x94000 / (sizeof(uint64_t)))
53 * Below used for sdnum parameter, selecting one of the two sections
54 * used for PCIe, or the single SerDes used for IB.
56 #define PCIE_SERDES0 0
57 #define PCIE_SERDES1 1
60 * The EPB requires addressing in a particular form. EPB_LOC() is intended
61 * to make #definitions a little more readable.
63 #define EPB_ADDR_SHF 8
64 #define EPB_LOC(chn, elt, reg) \
65 (((elt & 0xf) | ((chn & 7) << 4) | ((reg & 0x3f) << 9)) << \
67 #define EPB_IB_QUAD0_CS_SHF (25)
68 #define EPB_IB_QUAD0_CS (1U << EPB_IB_QUAD0_CS_SHF)
69 #define EPB_IB_UC_CS_SHF (26)
70 #define EPB_PCIE_UC_CS_SHF (27)
71 #define EPB_GLOBAL_WR (1U << (EPB_ADDR_SHF + 8))
73 /* Forward declarations. */
74 static int ipath_sd7220_reg_mod(struct ipath_devdata
*dd
, int sdnum
, u32 loc
,
76 static int ibsd_mod_allchnls(struct ipath_devdata
*dd
, int loc
, int val
,
78 static int ipath_sd_trimdone_poll(struct ipath_devdata
*dd
);
79 static void ipath_sd_trimdone_monitor(struct ipath_devdata
*dd
,
81 static int ipath_sd_setvals(struct ipath_devdata
*dd
);
82 static int ipath_sd_early(struct ipath_devdata
*dd
);
83 static int ipath_sd_dactrim(struct ipath_devdata
*dd
);
84 /* Set the registers that IBC may muck with to their default "preset" values */
85 int ipath_sd7220_presets(struct ipath_devdata
*dd
);
86 static int ipath_internal_presets(struct ipath_devdata
*dd
);
87 /* Tweak the register (CMUCTRL5) that contains the TRIMSELF controls */
88 static int ipath_sd_trimself(struct ipath_devdata
*dd
, int val
);
89 static int epb_access(struct ipath_devdata
*dd
, int sdnum
, int claim
);
91 void ipath_set_relock_poll(struct ipath_devdata
*dd
, int ibup
);
94 * Below keeps track of whether the "once per power-on" initialization has
95 * been done, because uC code Version 1.32.17 or higher allows the uC to
96 * be reset at will, and Automatic Equalization may require it. So the
97 * state of the reset "pin", as reflected in was_reset parameter to
98 * ipath_sd7220_init() is no longer valid. Instead, we check for the
99 * actual uC code having been loaded.
101 static int ipath_ibsd_ucode_loaded(struct ipath_devdata
*dd
)
103 if (!dd
->serdes_first_init_done
&& (ipath_sd7220_ib_vfy(dd
) > 0))
104 dd
->serdes_first_init_done
= 1;
105 return dd
->serdes_first_init_done
;
108 /* repeat #define for local use. "Real" #define is in ipath_iba7220.c */
109 #define INFINIPATH_HWE_IB_UC_MEMORYPARITYERR 0x0000004000000000ULL
110 #define IB_MPREG5 (EPB_LOC(6, 0, 0xE) | (1L << EPB_IB_UC_CS_SHF))
111 #define IB_MPREG6 (EPB_LOC(6, 0, 0xF) | (1U << EPB_IB_UC_CS_SHF))
112 #define UC_PAR_CLR_D 8
113 #define UC_PAR_CLR_M 0xC
114 #define IB_CTRL2(chn) (EPB_LOC(chn, 7, 3) | EPB_IB_QUAD0_CS)
115 #define START_EQ1(chan) EPB_LOC(chan, 7, 0x27)
117 void ipath_sd7220_clr_ibpar(struct ipath_devdata
*dd
)
121 /* clear, then re-enable parity errs */
122 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
, IB_MPREG6
,
123 UC_PAR_CLR_D
, UC_PAR_CLR_M
);
125 ipath_dev_err(dd
, "Failed clearing IBSerDes Parity err\n");
128 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
, IB_MPREG6
, 0,
131 ipath_read_kreg32(dd
, dd
->ipath_kregs
->kr_scratch
);
133 ipath_write_kreg(dd
, dd
->ipath_kregs
->kr_hwerrclear
,
134 INFINIPATH_HWE_IB_UC_MEMORYPARITYERR
);
135 ipath_read_kreg32(dd
, dd
->ipath_kregs
->kr_scratch
);
141 * After a reset or other unusual event, the epb interface may need
142 * to be re-synchronized, between the host and the uC.
143 * returns <0 for failure to resync within IBSD_RESYNC_TRIES (not expected)
145 #define IBSD_RESYNC_TRIES 3
146 #define IB_PGUDP(chn) (EPB_LOC((chn), 2, 1) | EPB_IB_QUAD0_CS)
147 #define IB_CMUDONE(chn) (EPB_LOC((chn), 7, 0xF) | EPB_IB_QUAD0_CS)
149 static int ipath_resync_ibepb(struct ipath_devdata
*dd
)
151 int ret
, pat
, tries
, chn
;
156 for (tries
= 0; tries
< (4 * IBSD_RESYNC_TRIES
); ++tries
) {
158 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
, loc
, 0, 0);
160 ipath_dev_err(dd
, "Failed read in resync\n");
163 if (ret
!= 0xF0 && ret
!= 0x55 && tries
== 0)
164 ipath_dev_err(dd
, "unexpected pattern in resync\n");
165 pat
= ret
^ 0xA5; /* alternate F0 and 55 */
166 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
, loc
, pat
, 0xFF);
168 ipath_dev_err(dd
, "Failed write in resync\n");
171 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
, loc
, 0, 0);
173 ipath_dev_err(dd
, "Failed re-read in resync\n");
177 ipath_dev_err(dd
, "Failed compare1 in resync\n");
180 loc
= IB_CMUDONE(chn
);
181 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
, loc
, 0, 0);
183 ipath_dev_err(dd
, "Failed CMUDONE rd in resync\n");
186 if ((ret
& 0x70) != ((chn
<< 4) | 0x40)) {
187 ipath_dev_err(dd
, "Bad CMUDONE value %02X, chn %d\n",
194 ipath_cdbg(VERBOSE
, "Resync in %d tries\n", tries
);
195 return (ret
> 0) ? 0 : ret
;
199 * Localize the stuff that should be done to change IB uC reset
200 * returns <0 for errors.
202 static int ipath_ibsd_reset(struct ipath_devdata
*dd
, int assert_rst
)
208 rst_val
= ipath_read_kreg64(dd
, dd
->ipath_kregs
->kr_ibserdesctrl
);
211 * Vendor recommends "interrupting" uC before reset, to
212 * minimize possible glitches.
214 spin_lock_irqsave(&dd
->ipath_sdepb_lock
, flags
);
215 epb_access(dd
, IB_7220_SERDES
, 1);
217 /* Squelch possible parity error from _asserting_ reset */
218 ipath_write_kreg(dd
, dd
->ipath_kregs
->kr_hwerrmask
,
219 dd
->ipath_hwerrmask
&
220 ~INFINIPATH_HWE_IB_UC_MEMORYPARITYERR
);
221 ipath_write_kreg(dd
, dd
->ipath_kregs
->kr_ibserdesctrl
, rst_val
);
222 /* flush write, delay to ensure it took effect */
223 ipath_read_kreg32(dd
, dd
->ipath_kregs
->kr_scratch
);
225 /* once it's reset, can remove interrupt */
226 epb_access(dd
, IB_7220_SERDES
, -1);
227 spin_unlock_irqrestore(&dd
->ipath_sdepb_lock
, flags
);
230 * Before we de-assert reset, we need to deal with
231 * possible glitch on the Parity-error line.
232 * Suppress it around the reset, both in chip-level
233 * hwerrmask and in IB uC control reg. uC will allow
234 * it again during startup.
238 ipath_write_kreg(dd
, dd
->ipath_kregs
->kr_hwerrmask
,
239 dd
->ipath_hwerrmask
&
240 ~INFINIPATH_HWE_IB_UC_MEMORYPARITYERR
);
242 ret
= ipath_resync_ibepb(dd
);
244 ipath_dev_err(dd
, "unable to re-sync IB EPB\n");
246 /* set uC control regs to suppress parity errs */
247 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
, IB_MPREG5
, 1, 1);
250 /* IB uC code past Version 1.32.17 allow suppression of wdog */
251 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
, IB_MPREG6
, 0x80,
254 ipath_dev_err(dd
, "Failed to set WDOG disable\n");
257 ipath_write_kreg(dd
, dd
->ipath_kregs
->kr_ibserdesctrl
, rst_val
);
258 /* flush write, delay for startup */
259 ipath_read_kreg32(dd
, dd
->ipath_kregs
->kr_scratch
);
261 /* clear, then re-enable parity errs */
262 ipath_sd7220_clr_ibpar(dd
);
263 val
= ipath_read_kreg64(dd
, dd
->ipath_kregs
->kr_hwerrstatus
);
264 if (val
& INFINIPATH_HWE_IB_UC_MEMORYPARITYERR
) {
265 ipath_dev_err(dd
, "IBUC Parity still set after RST\n");
266 dd
->ipath_hwerrmask
&=
267 ~INFINIPATH_HWE_IB_UC_MEMORYPARITYERR
;
269 ipath_write_kreg(dd
, dd
->ipath_kregs
->kr_hwerrmask
,
270 dd
->ipath_hwerrmask
);
277 static void ipath_sd_trimdone_monitor(struct ipath_devdata
*dd
,
280 int ret
, chn
, baduns
;
286 /* give time for reset to settle out in EPB */
289 ret
= ipath_resync_ibepb(dd
);
291 ipath_dev_err(dd
, "not able to re-sync IB EPB (%s)\n", where
);
293 /* Do "sacrificial read" to get EPB in sane state after reset */
294 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
, IB_CTRL2(0), 0, 0);
296 ipath_dev_err(dd
, "Failed TRIMDONE 1st read, (%s)\n", where
);
298 /* Check/show "summary" Trim-done bit in IBCStatus */
299 val
= ipath_read_kreg64(dd
, dd
->ipath_kregs
->kr_ibcstatus
);
300 if (val
& (1ULL << 11))
301 ipath_cdbg(VERBOSE
, "IBCS TRIMDONE set (%s)\n", where
);
303 ipath_dev_err(dd
, "IBCS TRIMDONE clear (%s)\n", where
);
307 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
, IB_MPREG6
, 0x80, 0x80);
309 ipath_dev_err(dd
, "Failed Dummy RMW, (%s)\n", where
);
314 for (chn
= 3; chn
>= 0; --chn
) {
315 /* Read CTRL reg for each channel to check TRIMDONE */
316 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
,
317 IB_CTRL2(chn
), 0, 0);
319 ipath_dev_err(dd
, "Failed checking TRIMDONE, chn %d"
320 " (%s)\n", chn
, where
);
324 baduns
|= (1 << chn
);
325 ipath_dev_err(dd
, "TRIMDONE cleared on chn %d (%02X)."
326 " (%s)\n", chn
, ret
, where
);
327 probe
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
,
329 ipath_dev_err(dd
, "probe is %d (%02X)\n",
331 probe
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
,
332 IB_CTRL2(chn
), 0, 0);
333 ipath_dev_err(dd
, "re-read: %d (%02X)\n",
335 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
,
336 IB_CTRL2(chn
), 0x10, 0x10);
339 "Err on TRIMDONE rewrite1\n");
342 for (chn
= 3; chn
>= 0; --chn
) {
343 /* Read CTRL reg for each channel to check TRIMDONE */
344 if (baduns
& (1 << chn
)) {
346 "Reseting TRIMDONE on chn %d (%s)\n",
348 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
,
349 IB_CTRL2(chn
), 0x10, 0x10);
351 ipath_dev_err(dd
, "Failed re-setting "
352 "TRIMDONE, chn %d (%s)\n",
359 * Below is portion of IBA7220-specific bringup_serdes() that actually
360 * deals with registers and memory within the SerDes itself.
361 * Post IB uC code version 1.32.17, was_reset being 1 is not really
362 * informative, so we double-check.
364 int ipath_sd7220_init(struct ipath_devdata
*dd
, int was_reset
)
366 int ret
= 1; /* default to failure */
371 /* entered with reset not asserted, we need to do it */
372 ipath_ibsd_reset(dd
, 1);
373 ipath_sd_trimdone_monitor(dd
, "Driver-reload");
376 /* Substitute our deduced value for was_reset */
377 ret
= ipath_ibsd_ucode_loaded(dd
);
382 first_reset
= !ret
; /* First reset if IBSD uCode not yet loaded */
385 * Alter some regs per vendor latest doc, reset-defaults
386 * are not right for IB.
388 ret
= ipath_sd_early(dd
);
390 ipath_dev_err(dd
, "Failed to set IB SERDES early defaults\n");
396 * Set DAC manual trim IB.
397 * We only do this once after chip has been reset (usually
398 * same as once per system boot).
401 ret
= ipath_sd_dactrim(dd
);
403 ipath_dev_err(dd
, "Failed IB SERDES DAC trim\n");
410 * Set various registers (DDS and RXEQ) that will be
411 * controlled by IBC (in 1.2 mode) to reasonable preset values
412 * Calling the "internal" version avoids the "check for needed"
413 * and "trimdone monitor" that might be counter-productive.
415 ret
= ipath_internal_presets(dd
);
417 ipath_dev_err(dd
, "Failed to set IB SERDES presets\n");
421 ret
= ipath_sd_trimself(dd
, 0x80);
423 ipath_dev_err(dd
, "Failed to set IB SERDES TRIMSELF\n");
428 /* Load image, then try to verify */
429 ret
= 0; /* Assume success */
433 ipath_dbg("SerDes uC was reset, reloading PRAM\n");
434 ret
= ipath_sd7220_ib_load(dd
);
436 ipath_dev_err(dd
, "Failed to load IB SERDES image\n");
441 /* Loaded image, try to verify */
442 vfy
= ipath_sd7220_ib_vfy(dd
);
444 ipath_dev_err(dd
, "SERDES PRAM VFY failed\n");
449 * Loaded and verified. Almost good...
450 * hold "success" in ret
455 * Prev steps all worked, continue bringup
456 * De-assert RESET to uC, only in first reset, to allow
459 * Since our default setup sets START_EQ1 to
460 * PRESET, we need to clear that for this very first run.
462 ret
= ibsd_mod_allchnls(dd
, START_EQ1(0), 0, 0x38);
464 ipath_dev_err(dd
, "Failed clearing START_EQ1\n");
469 ipath_ibsd_reset(dd
, 0);
471 * If this is not the first reset, trimdone should be set
474 trim_done
= ipath_sd_trimdone_poll(dd
);
476 * Whether or not trimdone succeeded, we need to put the
477 * uC back into reset to avoid a possible fight with the
480 ipath_ibsd_reset(dd
, 1);
483 ipath_dev_err(dd
, "No TRIMDONE seen\n");
488 ipath_sd_trimdone_monitor(dd
, "First-reset");
489 /* Remember so we do not re-do the load, dactrim, etc. */
490 dd
->serdes_first_init_done
= 1;
493 * Setup for channel training and load values for
494 * RxEq and DDS in tables used by IBC in IB1.2 mode
497 val_stat
= ipath_sd_setvals(dd
);
501 /* start relock timer regardless, but start at 1 second */
502 ipath_set_relock_poll(dd
, -1);
506 #define EPB_ACC_REQ 1
507 #define EPB_ACC_GNT 0x100
508 #define EPB_DATA_MASK 0xFF
509 #define EPB_RD (1ULL << 24)
510 #define EPB_TRANS_RDY (1ULL << 31)
511 #define EPB_TRANS_ERR (1ULL << 30)
512 #define EPB_TRANS_TRIES 5
515 * query, claim, release ownership of the EPB (External Parallel Bus)
516 * for a specified SERDES.
517 * the "claim" parameter is >0 to claim, <0 to release, 0 to query.
518 * Returns <0 for errors, >0 if we had ownership, else 0.
520 static int epb_access(struct ipath_devdata
*dd
, int sdnum
, int claim
)
528 case IB_7220_SERDES
:
530 * The IB SERDES "ownership" is fairly simple. A single each
533 acc
= dd
->ipath_kregs
->kr_ib_epbacc
;
537 /* PCIe SERDES has two "octants", need to select which */
538 acc
= dd
->ipath_kregs
->kr_pcie_epbacc
;
539 oct_sel
= (2 << (sdnum
- PCIE_SERDES0
));
545 /* Make sure any outstanding transaction was seen */
546 ipath_read_kreg32(dd
, dd
->ipath_kregs
->kr_scratch
);
549 accval
= ipath_read_kreg32(dd
, acc
);
551 owned
= !!(accval
& EPB_ACC_GNT
);
553 /* Need to release */
556 * The only writeable bits are the request and CS.
557 * Both should be clear
560 ipath_write_kreg(dd
, acc
, newval
);
561 /* First read after write is not trustworthy */
562 pollval
= ipath_read_kreg32(dd
, acc
);
564 pollval
= ipath_read_kreg32(dd
, acc
);
565 if (pollval
& EPB_ACC_GNT
)
567 } else if (claim
> 0) {
570 u64 newval
= EPB_ACC_REQ
| oct_sel
;
571 ipath_write_kreg(dd
, acc
, newval
);
572 /* First read after write is not trustworthy */
573 pollval
= ipath_read_kreg32(dd
, acc
);
575 pollval
= ipath_read_kreg32(dd
, acc
);
576 if (!(pollval
& EPB_ACC_GNT
))
583 * Lemma to deal with race condition of write..read to epb regs
585 static int epb_trans(struct ipath_devdata
*dd
, u16 reg
, u64 i_val
, u64
*o_vp
)
591 ipath_write_kreg(dd
, reg
, i_val
);
592 /* Throw away first read, as RDY bit may be stale */
593 transval
= ipath_read_kreg64(dd
, reg
);
595 for (tries
= EPB_TRANS_TRIES
; tries
; --tries
) {
596 transval
= ipath_read_kreg32(dd
, reg
);
597 if (transval
& EPB_TRANS_RDY
)
601 if (transval
& EPB_TRANS_ERR
)
603 if (tries
> 0 && o_vp
)
610 * ipath_sd7220_reg_mod - modify SERDES register
611 * @dd: the infinipath device
612 * @sdnum: which SERDES to access
613 * @loc: location - channel, element, register, as packed by EPB_LOC() macro.
614 * @wd: Write Data - value to set in register
615 * @mask: ones where data should be spliced into reg.
617 * Basic register read/modify/write, with un-needed acesses elided. That is,
618 * a mask of zero will prevent write, while a mask of 0xFF will prevent read.
619 * returns current (presumed, if a write was done) contents of selected
620 * register, or <0 if errors.
622 static int ipath_sd7220_reg_mod(struct ipath_devdata
*dd
, int sdnum
, u32 loc
,
632 case IB_7220_SERDES
:
633 trans
= dd
->ipath_kregs
->kr_ib_epbtrans
;
637 trans
= dd
->ipath_kregs
->kr_pcie_epbtrans
;
644 * All access is locked in software (vs other host threads) and
645 * hardware (vs uC access).
647 spin_lock_irqsave(&dd
->ipath_sdepb_lock
, flags
);
649 owned
= epb_access(dd
, sdnum
, 1);
651 spin_unlock_irqrestore(&dd
->ipath_sdepb_lock
, flags
);
655 for (tries
= EPB_TRANS_TRIES
; tries
; --tries
) {
656 transval
= ipath_read_kreg32(dd
, trans
);
657 if (transval
& EPB_TRANS_RDY
)
663 tries
= 1; /* to make read-skip work */
666 * Not a pure write, so need to read.
667 * loc encodes chip-select as well as address
669 transval
= loc
| EPB_RD
;
670 tries
= epb_trans(dd
, trans
, transval
, &transval
);
672 if (tries
> 0 && mask
!= 0) {
674 * Not a pure read, so need to write.
676 wd
= (wd
& mask
) | (transval
& ~mask
);
677 transval
= loc
| (wd
& EPB_DATA_MASK
);
678 tries
= epb_trans(dd
, trans
, transval
, &transval
);
681 /* else, failed to see ready, what error-handling? */
684 * Release bus. Failure is an error.
686 if (epb_access(dd
, sdnum
, -1) < 0)
689 ret
= transval
& EPB_DATA_MASK
;
691 spin_unlock_irqrestore(&dd
->ipath_sdepb_lock
, flags
);
697 #define EPB_ROM_R (2)
698 #define EPB_ROM_W (1)
700 * Below, all uC-related, use appropriate UC_CS, depending
701 * on which SerDes is used.
703 #define EPB_UC_CTL EPB_LOC(6, 0, 0)
704 #define EPB_MADDRL EPB_LOC(6, 0, 2)
705 #define EPB_MADDRH EPB_LOC(6, 0, 3)
706 #define EPB_ROMDATA EPB_LOC(6, 0, 4)
707 #define EPB_RAMDATA EPB_LOC(6, 0, 5)
709 /* Transfer date to/from uC Program RAM of IB or PCIe SerDes */
710 static int ipath_sd7220_ram_xfer(struct ipath_devdata
*dd
, int sdnum
, u32 loc
,
711 u8
*buf
, int cnt
, int rd_notwr
)
724 /* Pick appropriate transaction reg and "Chip select" for this serdes */
726 case IB_7220_SERDES
:
727 csbit
= 1ULL << EPB_IB_UC_CS_SHF
;
728 trans
= dd
->ipath_kregs
->kr_ib_epbtrans
;
732 /* PCIe SERDES has uC "chip select" in different bit, too */
733 csbit
= 1ULL << EPB_PCIE_UC_CS_SHF
;
734 trans
= dd
->ipath_kregs
->kr_pcie_epbtrans
;
740 op
= rd_notwr
? "Rd" : "Wr";
741 spin_lock_irqsave(&dd
->ipath_sdepb_lock
, flags
);
743 owned
= epb_access(dd
, sdnum
, 1);
745 spin_unlock_irqrestore(&dd
->ipath_sdepb_lock
, flags
);
746 ipath_dbg("Could not get %s access to %s EPB: %X, loc %X\n",
747 op
, (sdnum
== IB_7220_SERDES
) ? "IB" : "PCIe",
753 * In future code, we may need to distinguish several address ranges,
754 * and select various memories based on this. For now, just trim
755 * "loc" (location including address and memory select) to
756 * "addr" (address within memory). we will only support PRAM
760 for (tries
= EPB_TRANS_TRIES
; tries
; --tries
) {
761 transval
= ipath_read_kreg32(dd
, trans
);
762 if (transval
& EPB_TRANS_RDY
)
769 ipath_dbg("No initial RDY on EPB access request\n");
772 * Every "memory" access is doubly-indirect.
773 * We set two bytes of address, then read/write
774 * one or mores bytes of data.
777 /* First, we set control to "Read" or "Write" */
778 transval
= csbit
| EPB_UC_CTL
|
779 (rd_notwr
? EPB_ROM_R
: EPB_ROM_W
);
780 tries
= epb_trans(dd
, trans
, transval
, &transval
);
782 ipath_dbg("No EPB response to uC %s cmd\n", op
);
783 while (tries
> 0 && sofar
< cnt
) {
785 /* Only set address at start of chunk */
786 int addrbyte
= (addr
+ sofar
) >> 8;
787 transval
= csbit
| EPB_MADDRH
| addrbyte
;
788 tries
= epb_trans(dd
, trans
, transval
,
791 ipath_dbg("No EPB response ADDRH\n");
794 addrbyte
= (addr
+ sofar
) & 0xFF;
795 transval
= csbit
| EPB_MADDRL
| addrbyte
;
796 tries
= epb_trans(dd
, trans
, transval
,
799 ipath_dbg("No EPB response ADDRL\n");
805 transval
= csbit
| EPB_ROMDATA
| EPB_RD
;
807 transval
= csbit
| EPB_ROMDATA
| buf
[sofar
];
808 tries
= epb_trans(dd
, trans
, transval
, &transval
);
810 ipath_dbg("No EPB response DATA\n");
814 buf
[sofar
] = transval
& EPB_DATA_MASK
;
817 /* Finally, clear control-bit for Read or Write */
818 transval
= csbit
| EPB_UC_CTL
;
819 tries
= epb_trans(dd
, trans
, transval
, &transval
);
821 ipath_dbg("No EPB response to drop of uC %s cmd\n", op
);
825 /* Release bus. Failure is an error */
826 if (epb_access(dd
, sdnum
, -1) < 0)
829 spin_unlock_irqrestore(&dd
->ipath_sdepb_lock
, flags
);
831 ipath_dbg("SERDES PRAM %s failed after %d bytes\n", op
, sofar
);
837 #define PROG_CHUNK 64
839 int ipath_sd7220_prog_ld(struct ipath_devdata
*dd
, int sdnum
,
840 u8
*img
, int len
, int offset
)
845 while (sofar
< len
) {
847 if (req
> PROG_CHUNK
)
849 cnt
= ipath_sd7220_ram_xfer(dd
, sdnum
, offset
+ sofar
,
850 img
+ sofar
, req
, 0);
861 #define SD_PRAM_ERROR_LIMIT 42
863 int ipath_sd7220_prog_vfy(struct ipath_devdata
*dd
, int sdnum
,
864 const u8
*img
, int len
, int offset
)
866 int cnt
, sofar
, req
, idx
, errors
;
867 unsigned char readback
[VFY_CHUNK
];
871 while (sofar
< len
) {
875 cnt
= ipath_sd7220_ram_xfer(dd
, sdnum
, sofar
+ offset
,
878 /* failed in read itself */
882 for (idx
= 0; idx
< cnt
; ++idx
) {
883 if (readback
[idx
] != img
[idx
+sofar
])
888 return errors
? -errors
: sofar
;
891 /* IRQ not set up at this point in init, so we poll. */
892 #define IB_SERDES_TRIM_DONE (1ULL << 11)
893 #define TRIM_TMO (30)
895 static int ipath_sd_trimdone_poll(struct ipath_devdata
*dd
)
901 * Default to failure, so IBC will not start
902 * without IB_SERDES_TRIM_DONE.
905 for (trim_tmo
= 0; trim_tmo
< TRIM_TMO
; ++trim_tmo
) {
906 val
= ipath_read_kreg64(dd
, dd
->ipath_kregs
->kr_ibcstatus
);
907 if (val
& IB_SERDES_TRIM_DONE
) {
908 ipath_cdbg(VERBOSE
, "TRIMDONE after %d\n", trim_tmo
);
914 if (trim_tmo
>= TRIM_TMO
) {
915 ipath_dev_err(dd
, "No TRIMDONE in %d tries\n", trim_tmo
);
921 #define TX_FAST_ELT (9)
924 * Set the "negotiation" values for SERDES. These are used by the IB1.2
925 * link negotiation. Macros below are attempt to keep the values a
926 * little more human-editable.
927 * First, values related to Drive De-emphasis Settings.
930 #define NUM_DDS_REGS 6
931 #define DDS_REG_MAP 0x76A910 /* LSB-first list of regs (in elt 9) to mod */
933 #define DDS_VAL(amp_d, main_d, ipst_d, ipre_d, amp_s, main_s, ipst_s, ipre_s) \
934 { { ((amp_d & 0x1F) << 1) | 1, ((amp_s & 0x1F) << 1) | 1, \
935 (main_d << 3) | 4 | (ipre_d >> 2), \
936 (main_s << 3) | 4 | (ipre_s >> 2), \
937 ((ipst_d & 0xF) << 1) | ((ipre_d & 3) << 6) | 0x21, \
938 ((ipst_s & 0xF) << 1) | ((ipre_s & 3) << 6) | 0x21 } }
940 static struct dds_init
{
941 uint8_t reg_vals
[NUM_DDS_REGS
];
942 } dds_init_vals
[] = {
943 /* DDR(FDR) SDR(HDR) */
944 /* Vendor recommends below for 3m cable */
946 DDS_VAL(31, 19, 12, 0, 29, 22, 9, 0),
947 DDS_VAL(31, 12, 15, 4, 31, 15, 15, 1),
948 DDS_VAL(31, 13, 15, 3, 31, 16, 15, 0),
949 DDS_VAL(31, 14, 15, 2, 31, 17, 14, 0),
950 DDS_VAL(31, 15, 15, 1, 31, 18, 13, 0),
951 DDS_VAL(31, 16, 15, 0, 31, 19, 12, 0),
952 DDS_VAL(31, 17, 14, 0, 31, 20, 11, 0),
953 DDS_VAL(31, 18, 13, 0, 30, 21, 10, 0),
954 DDS_VAL(31, 20, 11, 0, 28, 23, 8, 0),
955 DDS_VAL(31, 21, 10, 0, 27, 24, 7, 0),
956 DDS_VAL(31, 22, 9, 0, 26, 25, 6, 0),
957 DDS_VAL(30, 23, 8, 0, 25, 26, 5, 0),
958 DDS_VAL(29, 24, 7, 0, 23, 27, 4, 0),
959 /* Vendor recommends below for 1m cable */
961 DDS_VAL(28, 25, 6, 0, 21, 28, 3, 0),
962 DDS_VAL(27, 26, 5, 0, 19, 29, 2, 0),
963 DDS_VAL(25, 27, 4, 0, 17, 30, 1, 0)
967 * Next, values related to Receive Equalization.
968 * In comments, FDR (Full) is IB DDR, HDR (Half) is IB SDR
970 /* Hardware packs an element number and register address thus: */
971 #define RXEQ_INIT_RDESC(elt, addr) (((elt) & 0xF) | ((addr) << 4))
972 #define RXEQ_VAL(elt, adr, val0, val1, val2, val3) \
973 {RXEQ_INIT_RDESC((elt), (adr)), {(val0), (val1), (val2), (val3)} }
975 #define RXEQ_VAL_ALL(elt, adr, val) \
976 {RXEQ_INIT_RDESC((elt), (adr)), {(val), (val), (val), (val)} }
978 #define RXEQ_SDR_DFELTH 0
979 #define RXEQ_SDR_TLTH 0
980 #define RXEQ_SDR_G1CNT_Z1CNT 0x11
981 #define RXEQ_SDR_ZCNT 23
983 static struct rxeq_init
{
984 u16 rdesc
; /* in form used in SerDesDDSRXEQ */
986 } rxeq_init_vals
[] = {
987 /* Set Rcv Eq. to Preset node */
988 RXEQ_VAL_ALL(7, 0x27, 0x10),
989 /* Set DFELTHFDR/HDR thresholds */
990 RXEQ_VAL(7, 8, 0, 0, 0, 0), /* FDR */
991 RXEQ_VAL(7, 0x21, 0, 0, 0, 0), /* HDR */
992 /* Set TLTHFDR/HDR theshold */
993 RXEQ_VAL(7, 9, 2, 2, 2, 2), /* FDR */
994 RXEQ_VAL(7, 0x23, 2, 2, 2, 2), /* HDR */
995 /* Set Preamp setting 2 (ZFR/ZCNT) */
996 RXEQ_VAL(7, 0x1B, 12, 12, 12, 12), /* FDR */
997 RXEQ_VAL(7, 0x1C, 12, 12, 12, 12), /* HDR */
998 /* Set Preamp DC gain and Setting 1 (GFR/GHR) */
999 RXEQ_VAL(7, 0x1E, 0x10, 0x10, 0x10, 0x10), /* FDR */
1000 RXEQ_VAL(7, 0x1F, 0x10, 0x10, 0x10, 0x10), /* HDR */
1001 /* Toggle RELOCK (in VCDL_CTRL0) to lock to data */
1002 RXEQ_VAL_ALL(6, 6, 0x20), /* Set D5 High */
1003 RXEQ_VAL_ALL(6, 6, 0), /* Set D5 Low */
1006 /* There are 17 values from vendor, but IBC only accesses the first 16 */
1007 #define DDS_ROWS (16)
1008 #define RXEQ_ROWS ARRAY_SIZE(rxeq_init_vals)
1010 static int ipath_sd_setvals(struct ipath_devdata
*dd
)
1013 int min_idx
; /* Minimum index for this portion of table */
1014 uint32_t dds_reg_map
;
1015 u64 __iomem
*taddr
, *iaddr
;
1019 taddr
= dd
->ipath_kregbase
+ KR_IBSerDesMappTable
;
1020 iaddr
= dd
->ipath_kregbase
+ dd
->ipath_kregs
->kr_ib_ddsrxeq
;
1023 * Init the DDS section of the table.
1024 * Each "row" of the table provokes NUM_DDS_REG writes, to the
1025 * registers indicated in DDS_REG_MAP.
1027 sdctl
= ipath_read_kreg64(dd
, dd
->ipath_kregs
->kr_ibserdesctrl
);
1028 sdctl
= (sdctl
& ~(0x1f << 8)) | (NUM_DDS_REGS
<< 8);
1029 sdctl
= (sdctl
& ~(0x1f << 13)) | (RXEQ_ROWS
<< 13);
1030 ipath_write_kreg(dd
, dd
->ipath_kregs
->kr_ibserdesctrl
, sdctl
);
1033 * Iterate down table within loop for each register to store.
1035 dds_reg_map
= DDS_REG_MAP
;
1036 for (idx
= 0; idx
< NUM_DDS_REGS
; ++idx
) {
1037 data
= ((dds_reg_map
& 0xF) << 4) | TX_FAST_ELT
;
1038 writeq(data
, iaddr
+ idx
);
1040 ipath_read_kreg32(dd
, dd
->ipath_kregs
->kr_scratch
);
1042 for (midx
= 0; midx
< DDS_ROWS
; ++midx
) {
1043 u64 __iomem
*daddr
= taddr
+ ((midx
<< 4) + idx
);
1044 data
= dds_init_vals
[midx
].reg_vals
[idx
];
1045 writeq(data
, daddr
);
1047 ipath_read_kreg32(dd
, dd
->ipath_kregs
->kr_scratch
);
1048 } /* End inner for (vals for this reg, each row) */
1049 } /* end outer for (regs to be stored) */
1052 * Init the RXEQ section of the table. As explained above the table
1053 * rxeq_init_vals[], this runs in a different order, as the pattern
1054 * of register references is more complex, but there are only
1055 * four "data" values per register.
1057 min_idx
= idx
; /* RXEQ indices pick up where DDS left off */
1058 taddr
+= 0x100; /* RXEQ data is in second half of table */
1059 /* Iterate through RXEQ register addresses */
1060 for (idx
= 0; idx
< RXEQ_ROWS
; ++idx
) {
1061 int didx
; /* "destination" */
1064 /* didx is offset by min_idx to address RXEQ range of regs */
1065 didx
= idx
+ min_idx
;
1066 /* Store the next RXEQ register address */
1067 writeq(rxeq_init_vals
[idx
].rdesc
, iaddr
+ didx
);
1069 ipath_read_kreg32(dd
, dd
->ipath_kregs
->kr_scratch
);
1070 /* Iterate through RXEQ values */
1071 for (vidx
= 0; vidx
< 4; vidx
++) {
1072 data
= rxeq_init_vals
[idx
].rdata
[vidx
];
1073 writeq(data
, taddr
+ (vidx
<< 6) + idx
);
1075 ipath_read_kreg32(dd
, dd
->ipath_kregs
->kr_scratch
);
1077 } /* end outer for (Reg-writes for RXEQ) */
1081 #define CMUCTRL5 EPB_LOC(7, 0, 0x15)
1082 #define RXHSCTRL0(chan) EPB_LOC(chan, 6, 0)
1083 #define VCDL_DAC2(chan) EPB_LOC(chan, 6, 5)
1084 #define VCDL_CTRL0(chan) EPB_LOC(chan, 6, 6)
1085 #define VCDL_CTRL2(chan) EPB_LOC(chan, 6, 8)
1086 #define START_EQ2(chan) EPB_LOC(chan, 7, 0x28)
1088 static int ibsd_sto_noisy(struct ipath_devdata
*dd
, int loc
, int val
, int mask
)
1091 int sloc
; /* shifted loc, for messages */
1093 loc
|= (1U << EPB_IB_QUAD0_CS_SHF
);
1094 sloc
= loc
>> EPB_ADDR_SHF
;
1096 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
, loc
, val
, mask
);
1098 ipath_dev_err(dd
, "Write failed: elt %d,"
1099 " addr 0x%X, chnl %d, val 0x%02X, mask 0x%02X\n",
1100 (sloc
& 0xF), (sloc
>> 9) & 0x3f, (sloc
>> 4) & 7,
1101 val
& 0xFF, mask
& 0xFF);
1106 * Repeat a "store" across all channels of the IB SerDes.
1107 * Although nominally it inherits the "read value" of the last
1108 * channel it modified, the only really useful return is <0 for
1109 * failure, >= 0 for success. The parameter 'loc' is assumed to
1110 * be the location for the channel-0 copy of the register to
1113 static int ibsd_mod_allchnls(struct ipath_devdata
*dd
, int loc
, int val
,
1119 if (loc
& EPB_GLOBAL_WR
) {
1121 * Our caller has assured us that we can set all four
1122 * channels at once. Trust that. If mask is not 0xFF,
1123 * we will read the _specified_ channel for our starting
1126 loc
|= (1U << EPB_IB_QUAD0_CS_SHF
);
1127 chnl
= (loc
>> (4 + EPB_ADDR_SHF
)) & 7;
1129 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
,
1130 loc
& ~EPB_GLOBAL_WR
, 0, 0);
1132 int sloc
= loc
>> EPB_ADDR_SHF
;
1133 ipath_dev_err(dd
, "pre-read failed: elt %d,"
1134 " addr 0x%X, chnl %d\n", (sloc
& 0xF),
1135 (sloc
>> 9) & 0x3f, chnl
);
1138 val
= (ret
& ~mask
) | (val
& mask
);
1140 loc
&= ~(7 << (4+EPB_ADDR_SHF
));
1141 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
, loc
, val
, 0xFF);
1143 int sloc
= loc
>> EPB_ADDR_SHF
;
1144 ipath_dev_err(dd
, "Global WR failed: elt %d,"
1145 " addr 0x%X, val %02X\n",
1146 (sloc
& 0xF), (sloc
>> 9) & 0x3f, val
);
1150 /* Clear "channel" and set CS so we can simply iterate */
1151 loc
&= ~(7 << (4+EPB_ADDR_SHF
));
1152 loc
|= (1U << EPB_IB_QUAD0_CS_SHF
);
1153 for (chnl
= 0; chnl
< 4; ++chnl
) {
1155 cloc
= loc
| (chnl
<< (4+EPB_ADDR_SHF
));
1156 ret
= ipath_sd7220_reg_mod(dd
, IB_7220_SERDES
, cloc
, val
, mask
);
1158 int sloc
= loc
>> EPB_ADDR_SHF
;
1159 ipath_dev_err(dd
, "Write failed: elt %d,"
1160 " addr 0x%X, chnl %d, val 0x%02X,"
1162 (sloc
& 0xF), (sloc
>> 9) & 0x3f, chnl
,
1163 val
& 0xFF, mask
& 0xFF);
1171 * Set the Tx values normally modified by IBC in IB1.2 mode to default
1172 * values, as gotten from first row of init table.
1174 static int set_dds_vals(struct ipath_devdata
*dd
, struct dds_init
*ddi
)
1180 regmap
= DDS_REG_MAP
;
1181 for (idx
= 0; idx
< NUM_DDS_REGS
; ++idx
) {
1182 reg
= (regmap
& 0xF);
1184 data
= ddi
->reg_vals
[idx
];
1185 /* Vendor says RMW not needed for these regs, use 0xFF mask */
1186 ret
= ibsd_mod_allchnls(dd
, EPB_LOC(0, 9, reg
), data
, 0xFF);
1194 * Set the Rx values normally modified by IBC in IB1.2 mode to default
1195 * values, as gotten from selected column of init table.
1197 static int set_rxeq_vals(struct ipath_devdata
*dd
, int vsel
)
1201 int cnt
= ARRAY_SIZE(rxeq_init_vals
);
1203 for (ridx
= 0; ridx
< cnt
; ++ridx
) {
1204 int elt
, reg
, val
, loc
;
1205 elt
= rxeq_init_vals
[ridx
].rdesc
& 0xF;
1206 reg
= rxeq_init_vals
[ridx
].rdesc
>> 4;
1207 loc
= EPB_LOC(0, elt
, reg
);
1208 val
= rxeq_init_vals
[ridx
].rdata
[vsel
];
1209 /* mask of 0xFF, because hardware does full-byte store. */
1210 ret
= ibsd_mod_allchnls(dd
, loc
, val
, 0xFF);
1218 * Set the default values (row 0) for DDR Driver Demphasis.
1219 * we do this initially and whenever we turn off IB-1.2
1220 * The "default" values for Rx equalization are also stored to
1221 * SerDes registers. Formerly (and still default), we used set 2.
1222 * For experimenting with cables and link-partners, we allow changing
1223 * that via a module parameter.
1225 static unsigned ipath_rxeq_set
= 2;
1226 module_param_named(rxeq_default_set
, ipath_rxeq_set
, uint
,
1228 MODULE_PARM_DESC(rxeq_default_set
,
1229 "Which set [0..3] of Rx Equalization values is default");
1231 static int ipath_internal_presets(struct ipath_devdata
*dd
)
1235 ret
= set_dds_vals(dd
, dds_init_vals
+ DDS_3M
);
1238 ipath_dev_err(dd
, "Failed to set default DDS values\n");
1239 ret
= set_rxeq_vals(dd
, ipath_rxeq_set
& 3);
1241 ipath_dev_err(dd
, "Failed to set default RXEQ values\n");
1245 int ipath_sd7220_presets(struct ipath_devdata
*dd
)
1249 if (!dd
->ipath_presets_needed
)
1251 dd
->ipath_presets_needed
= 0;
1252 /* Assert uC reset, so we don't clash with it. */
1253 ipath_ibsd_reset(dd
, 1);
1255 ipath_sd_trimdone_monitor(dd
, "link-down");
1257 ret
= ipath_internal_presets(dd
);
1261 static int ipath_sd_trimself(struct ipath_devdata
*dd
, int val
)
1263 return ibsd_sto_noisy(dd
, CMUCTRL5
, val
, 0xFF);
1266 static int ipath_sd_early(struct ipath_devdata
*dd
)
1268 int ret
= -1; /* Default failed */
1271 for (chnl
= 0; chnl
< 4; ++chnl
) {
1272 ret
= ibsd_sto_noisy(dd
, RXHSCTRL0(chnl
), 0xD4, 0xFF);
1276 for (chnl
= 0; chnl
< 4; ++chnl
) {
1277 ret
= ibsd_sto_noisy(dd
, VCDL_DAC2(chnl
), 0x2D, 0xFF);
1281 /* more fine-tuning of what will be default */
1282 for (chnl
= 0; chnl
< 4; ++chnl
) {
1283 ret
= ibsd_sto_noisy(dd
, VCDL_CTRL2(chnl
), 3, 0xF);
1287 for (chnl
= 0; chnl
< 4; ++chnl
) {
1288 ret
= ibsd_sto_noisy(dd
, START_EQ1(chnl
), 0x10, 0xFF);
1292 for (chnl
= 0; chnl
< 4; ++chnl
) {
1293 ret
= ibsd_sto_noisy(dd
, START_EQ2(chnl
), 0x30, 0xFF);
1301 #define BACTRL(chnl) EPB_LOC(chnl, 6, 0x0E)
1302 #define LDOUTCTRL1(chnl) EPB_LOC(chnl, 7, 6)
1303 #define RXHSSTATUS(chnl) EPB_LOC(chnl, 6, 0xF)
1305 static int ipath_sd_dactrim(struct ipath_devdata
*dd
)
1307 int ret
= -1; /* Default failed */
1310 for (chnl
= 0; chnl
< 4; ++chnl
) {
1311 ret
= ibsd_sto_noisy(dd
, BACTRL(chnl
), 0x40, 0xFF);
1315 for (chnl
= 0; chnl
< 4; ++chnl
) {
1316 ret
= ibsd_sto_noisy(dd
, LDOUTCTRL1(chnl
), 0x04, 0xFF);
1320 for (chnl
= 0; chnl
< 4; ++chnl
) {
1321 ret
= ibsd_sto_noisy(dd
, RXHSSTATUS(chnl
), 0x04, 0xFF);
1326 * delay for max possible number of steps, with slop.
1327 * Each step is about 4usec.
1330 for (chnl
= 0; chnl
< 4; ++chnl
) {
1331 ret
= ibsd_sto_noisy(dd
, LDOUTCTRL1(chnl
), 0x00, 0xFF);
1339 #define RELOCK_FIRST_MS 3
1340 #define RXLSPPM(chan) EPB_LOC(chan, 0, 2)
1341 void ipath_toggle_rclkrls(struct ipath_devdata
*dd
)
1343 int loc
= RXLSPPM(0) | EPB_GLOBAL_WR
;
1346 ret
= ibsd_mod_allchnls(dd
, loc
, 0, 0x80);
1348 ipath_dev_err(dd
, "RCLKRLS failed to clear D7\n");
1351 ibsd_mod_allchnls(dd
, loc
, 0x80, 0x80);
1353 /* And again for good measure */
1355 ret
= ibsd_mod_allchnls(dd
, loc
, 0, 0x80);
1357 ipath_dev_err(dd
, "RCLKRLS failed to clear D7\n");
1360 ibsd_mod_allchnls(dd
, loc
, 0x80, 0x80);
1362 /* Now reset xgxs and IBC to complete the recovery */
1363 dd
->ipath_f_xgxs_reset(dd
);
1367 * Shut down the timer that polls for relock occasions, if needed
1368 * this is "hooked" from ipath_7220_quiet_serdes(), which is called
1369 * just before ipath_shutdown_device() in ipath_driver.c shuts down all
1372 void ipath_shutdown_relock_poll(struct ipath_devdata
*dd
)
1374 struct ipath_relock
*irp
= &dd
->ipath_relock_singleton
;
1375 if (atomic_read(&irp
->ipath_relock_timer_active
)) {
1376 del_timer_sync(&irp
->ipath_relock_timer
);
1377 atomic_set(&irp
->ipath_relock_timer_active
, 0);
1381 static unsigned ipath_relock_by_timer
= 1;
1382 module_param_named(relock_by_timer
, ipath_relock_by_timer
, uint
,
1384 MODULE_PARM_DESC(relock_by_timer
, "Allow relock attempt if link not up");
1386 static void ipath_run_relock(unsigned long opaque
)
1388 struct ipath_devdata
*dd
= (struct ipath_devdata
*)opaque
;
1389 struct ipath_relock
*irp
= &dd
->ipath_relock_singleton
;
1392 if (!(dd
->ipath_flags
& IPATH_INITTED
)) {
1393 /* Not yet up, just reenable the timer for later */
1394 irp
->ipath_relock_interval
= HZ
;
1395 mod_timer(&irp
->ipath_relock_timer
, jiffies
+ HZ
);
1400 * Check link-training state for "stuck" state.
1401 * if found, try relock and schedule another try at
1402 * exponentially growing delay, maxed at one second.
1403 * if not stuck, our work is done.
1405 val
= ipath_read_kreg64(dd
, dd
->ipath_kregs
->kr_ibcstatus
);
1406 ltstate
= ipath_ib_linktrstate(dd
, val
);
1408 if (ltstate
<= INFINIPATH_IBCS_LT_STATE_CFGWAITRMT
1409 && ltstate
!= INFINIPATH_IBCS_LT_STATE_LINKUP
) {
1411 /* Not up yet. Try again, if allowed by module-param */
1412 if (ipath_relock_by_timer
) {
1413 if (dd
->ipath_flags
& IPATH_IB_AUTONEG_INPROG
)
1414 ipath_cdbg(VERBOSE
, "Skip RELOCK in AUTONEG\n");
1415 else if (!(dd
->ipath_flags
& IPATH_IB_LINK_DISABLED
)) {
1416 ipath_cdbg(VERBOSE
, "RELOCK\n");
1417 ipath_toggle_rclkrls(dd
);
1420 /* re-set timer for next check */
1421 timeoff
= irp
->ipath_relock_interval
<< 1;
1424 irp
->ipath_relock_interval
= timeoff
;
1426 mod_timer(&irp
->ipath_relock_timer
, jiffies
+ timeoff
);
1428 /* Up, so no more need to check so often */
1429 mod_timer(&irp
->ipath_relock_timer
, jiffies
+ HZ
);
1433 void ipath_set_relock_poll(struct ipath_devdata
*dd
, int ibup
)
1435 struct ipath_relock
*irp
= &dd
->ipath_relock_singleton
;
1438 /* we are now up, so relax timer to 1 second interval */
1439 if (atomic_read(&irp
->ipath_relock_timer_active
))
1440 mod_timer(&irp
->ipath_relock_timer
, jiffies
+ HZ
);
1442 /* Transition to down, (re-)set timer to short interval. */
1444 timeout
= (HZ
* ((ibup
== -1) ? 1000 : RELOCK_FIRST_MS
))/1000;
1447 /* If timer has not yet been started, do so. */
1448 if (atomic_inc_return(&irp
->ipath_relock_timer_active
) == 1) {
1449 init_timer(&irp
->ipath_relock_timer
);
1450 irp
->ipath_relock_timer
.function
= ipath_run_relock
;
1451 irp
->ipath_relock_timer
.data
= (unsigned long) dd
;
1452 irp
->ipath_relock_interval
= timeout
;
1453 irp
->ipath_relock_timer
.expires
= jiffies
+ timeout
;
1454 add_timer(&irp
->ipath_relock_timer
);
1456 irp
->ipath_relock_interval
= timeout
;
1457 mod_timer(&irp
->ipath_relock_timer
, jiffies
+ timeout
);
1458 atomic_dec(&irp
->ipath_relock_timer_active
);