1*a6013785SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2f7917c00SJeff Kirsher /*****************************************************************************
3f7917c00SJeff Kirsher * *
4f7917c00SJeff Kirsher * File: subr.c *
5f7917c00SJeff Kirsher * $Revision: 1.27 $ *
6f7917c00SJeff Kirsher * $Date: 2005/06/22 01:08:36 $ *
7f7917c00SJeff Kirsher * Description: *
8f7917c00SJeff Kirsher * Various subroutines (intr,pio,etc.) used by Chelsio 10G Ethernet driver. *
9f7917c00SJeff Kirsher * part of the Chelsio 10Gb Ethernet Driver. *
10f7917c00SJeff Kirsher * *
11f7917c00SJeff Kirsher * *
12f7917c00SJeff Kirsher * http://www.chelsio.com *
13f7917c00SJeff Kirsher * *
14f7917c00SJeff Kirsher * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. *
15f7917c00SJeff Kirsher * All rights reserved. *
16f7917c00SJeff Kirsher * *
17f7917c00SJeff Kirsher * Maintainers: maintainers@chelsio.com *
18f7917c00SJeff Kirsher * *
19f7917c00SJeff Kirsher * Authors: Dimitrios Michailidis <dm@chelsio.com> *
20f7917c00SJeff Kirsher * Tina Yang <tainay@chelsio.com> *
21f7917c00SJeff Kirsher * Felix Marti <felix@chelsio.com> *
22f7917c00SJeff Kirsher * Scott Bardone <sbardone@chelsio.com> *
23f7917c00SJeff Kirsher * Kurt Ottaway <kottaway@chelsio.com> *
24f7917c00SJeff Kirsher * Frank DiMambro <frank@chelsio.com> *
25f7917c00SJeff Kirsher * *
26f7917c00SJeff Kirsher * History: *
27f7917c00SJeff Kirsher * *
28f7917c00SJeff Kirsher ****************************************************************************/
29f7917c00SJeff Kirsher
30f7917c00SJeff Kirsher #include "common.h"
31f7917c00SJeff Kirsher #include "elmer0.h"
32f7917c00SJeff Kirsher #include "regs.h"
33f7917c00SJeff Kirsher #include "gmac.h"
34f7917c00SJeff Kirsher #include "cphy.h"
35f7917c00SJeff Kirsher #include "sge.h"
36f7917c00SJeff Kirsher #include "tp.h"
37f7917c00SJeff Kirsher #include "espi.h"
38f7917c00SJeff Kirsher
39f7917c00SJeff Kirsher /**
40f7917c00SJeff Kirsher * t1_wait_op_done - wait until an operation is completed
41f7917c00SJeff Kirsher * @adapter: the adapter performing the operation
42f7917c00SJeff Kirsher * @reg: the register to check for completion
43f7917c00SJeff Kirsher * @mask: a single-bit field within @reg that indicates completion
44f7917c00SJeff Kirsher * @polarity: the value of the field when the operation is completed
45f7917c00SJeff Kirsher * @attempts: number of check iterations
46f7917c00SJeff Kirsher * @delay: delay in usecs between iterations
47f7917c00SJeff Kirsher *
48f7917c00SJeff Kirsher * Wait until an operation is completed by checking a bit in a register
49f7917c00SJeff Kirsher * up to @attempts times. Returns %0 if the operation completes and %1
50f7917c00SJeff Kirsher * otherwise.
51f7917c00SJeff Kirsher */
t1_wait_op_done(adapter_t * adapter,int reg,u32 mask,int polarity,int attempts,int delay)52f7917c00SJeff Kirsher static int t1_wait_op_done(adapter_t *adapter, int reg, u32 mask, int polarity,
53f7917c00SJeff Kirsher int attempts, int delay)
54f7917c00SJeff Kirsher {
55f7917c00SJeff Kirsher while (1) {
56f7917c00SJeff Kirsher u32 val = readl(adapter->regs + reg) & mask;
57f7917c00SJeff Kirsher
58f7917c00SJeff Kirsher if (!!val == polarity)
59f7917c00SJeff Kirsher return 0;
60f7917c00SJeff Kirsher if (--attempts == 0)
61f7917c00SJeff Kirsher return 1;
62f7917c00SJeff Kirsher if (delay)
63f7917c00SJeff Kirsher udelay(delay);
64f7917c00SJeff Kirsher }
65f7917c00SJeff Kirsher }
66f7917c00SJeff Kirsher
67f7917c00SJeff Kirsher #define TPI_ATTEMPTS 50
68f7917c00SJeff Kirsher
69f7917c00SJeff Kirsher /*
70f7917c00SJeff Kirsher * Write a register over the TPI interface (unlocked and locked versions).
71f7917c00SJeff Kirsher */
__t1_tpi_write(adapter_t * adapter,u32 addr,u32 value)72f7917c00SJeff Kirsher int __t1_tpi_write(adapter_t *adapter, u32 addr, u32 value)
73f7917c00SJeff Kirsher {
74f7917c00SJeff Kirsher int tpi_busy;
75f7917c00SJeff Kirsher
76f7917c00SJeff Kirsher writel(addr, adapter->regs + A_TPI_ADDR);
77f7917c00SJeff Kirsher writel(value, adapter->regs + A_TPI_WR_DATA);
78f7917c00SJeff Kirsher writel(F_TPIWR, adapter->regs + A_TPI_CSR);
79f7917c00SJeff Kirsher
80f7917c00SJeff Kirsher tpi_busy = t1_wait_op_done(adapter, A_TPI_CSR, F_TPIRDY, 1,
81f7917c00SJeff Kirsher TPI_ATTEMPTS, 3);
82f7917c00SJeff Kirsher if (tpi_busy)
83f7917c00SJeff Kirsher pr_alert("%s: TPI write to 0x%x failed\n",
84f7917c00SJeff Kirsher adapter->name, addr);
85f7917c00SJeff Kirsher return tpi_busy;
86f7917c00SJeff Kirsher }
87f7917c00SJeff Kirsher
t1_tpi_write(adapter_t * adapter,u32 addr,u32 value)88f7917c00SJeff Kirsher int t1_tpi_write(adapter_t *adapter, u32 addr, u32 value)
89f7917c00SJeff Kirsher {
90f7917c00SJeff Kirsher int ret;
91f7917c00SJeff Kirsher
92f7917c00SJeff Kirsher spin_lock(&adapter->tpi_lock);
93f7917c00SJeff Kirsher ret = __t1_tpi_write(adapter, addr, value);
94f7917c00SJeff Kirsher spin_unlock(&adapter->tpi_lock);
95f7917c00SJeff Kirsher return ret;
96f7917c00SJeff Kirsher }
97f7917c00SJeff Kirsher
98f7917c00SJeff Kirsher /*
99f7917c00SJeff Kirsher * Read a register over the TPI interface (unlocked and locked versions).
100f7917c00SJeff Kirsher */
__t1_tpi_read(adapter_t * adapter,u32 addr,u32 * valp)101f7917c00SJeff Kirsher int __t1_tpi_read(adapter_t *adapter, u32 addr, u32 *valp)
102f7917c00SJeff Kirsher {
103f7917c00SJeff Kirsher int tpi_busy;
104f7917c00SJeff Kirsher
105f7917c00SJeff Kirsher writel(addr, adapter->regs + A_TPI_ADDR);
106f7917c00SJeff Kirsher writel(0, adapter->regs + A_TPI_CSR);
107f7917c00SJeff Kirsher
108f7917c00SJeff Kirsher tpi_busy = t1_wait_op_done(adapter, A_TPI_CSR, F_TPIRDY, 1,
109f7917c00SJeff Kirsher TPI_ATTEMPTS, 3);
110f7917c00SJeff Kirsher if (tpi_busy)
111f7917c00SJeff Kirsher pr_alert("%s: TPI read from 0x%x failed\n",
112f7917c00SJeff Kirsher adapter->name, addr);
113f7917c00SJeff Kirsher else
114f7917c00SJeff Kirsher *valp = readl(adapter->regs + A_TPI_RD_DATA);
115f7917c00SJeff Kirsher return tpi_busy;
116f7917c00SJeff Kirsher }
117f7917c00SJeff Kirsher
t1_tpi_read(adapter_t * adapter,u32 addr,u32 * valp)118f7917c00SJeff Kirsher int t1_tpi_read(adapter_t *adapter, u32 addr, u32 *valp)
119f7917c00SJeff Kirsher {
120f7917c00SJeff Kirsher int ret;
121f7917c00SJeff Kirsher
122f7917c00SJeff Kirsher spin_lock(&adapter->tpi_lock);
123f7917c00SJeff Kirsher ret = __t1_tpi_read(adapter, addr, valp);
124f7917c00SJeff Kirsher spin_unlock(&adapter->tpi_lock);
125f7917c00SJeff Kirsher return ret;
126f7917c00SJeff Kirsher }
127f7917c00SJeff Kirsher
128f7917c00SJeff Kirsher /*
129f7917c00SJeff Kirsher * Set a TPI parameter.
130f7917c00SJeff Kirsher */
t1_tpi_par(adapter_t * adapter,u32 value)131f7917c00SJeff Kirsher static void t1_tpi_par(adapter_t *adapter, u32 value)
132f7917c00SJeff Kirsher {
133f7917c00SJeff Kirsher writel(V_TPIPAR(value), adapter->regs + A_TPI_PAR);
134f7917c00SJeff Kirsher }
135f7917c00SJeff Kirsher
136f7917c00SJeff Kirsher /*
137f7917c00SJeff Kirsher * Called when a port's link settings change to propagate the new values to the
138f7917c00SJeff Kirsher * associated PHY and MAC. After performing the common tasks it invokes an
139f7917c00SJeff Kirsher * OS-specific handler.
140f7917c00SJeff Kirsher */
t1_link_changed(adapter_t * adapter,int port_id)141f7917c00SJeff Kirsher void t1_link_changed(adapter_t *adapter, int port_id)
142f7917c00SJeff Kirsher {
143f7917c00SJeff Kirsher int link_ok, speed, duplex, fc;
144f7917c00SJeff Kirsher struct cphy *phy = adapter->port[port_id].phy;
145f7917c00SJeff Kirsher struct link_config *lc = &adapter->port[port_id].link_config;
146f7917c00SJeff Kirsher
147f7917c00SJeff Kirsher phy->ops->get_link_status(phy, &link_ok, &speed, &duplex, &fc);
148f7917c00SJeff Kirsher
149f7917c00SJeff Kirsher lc->speed = speed < 0 ? SPEED_INVALID : speed;
150f7917c00SJeff Kirsher lc->duplex = duplex < 0 ? DUPLEX_INVALID : duplex;
151f7917c00SJeff Kirsher if (!(lc->requested_fc & PAUSE_AUTONEG))
152f7917c00SJeff Kirsher fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
153f7917c00SJeff Kirsher
154f7917c00SJeff Kirsher if (link_ok && speed >= 0 && lc->autoneg == AUTONEG_ENABLE) {
155f7917c00SJeff Kirsher /* Set MAC speed, duplex, and flow control to match PHY. */
156f7917c00SJeff Kirsher struct cmac *mac = adapter->port[port_id].mac;
157f7917c00SJeff Kirsher
158f7917c00SJeff Kirsher mac->ops->set_speed_duplex_fc(mac, speed, duplex, fc);
159f7917c00SJeff Kirsher lc->fc = (unsigned char)fc;
160f7917c00SJeff Kirsher }
161f7917c00SJeff Kirsher t1_link_negotiated(adapter, port_id, link_ok, speed, duplex, fc);
162f7917c00SJeff Kirsher }
163f7917c00SJeff Kirsher
t1_pci_intr_handler(adapter_t * adapter)16482154580SSebastian Andrzej Siewior static bool t1_pci_intr_handler(adapter_t *adapter)
165f7917c00SJeff Kirsher {
166f7917c00SJeff Kirsher u32 pcix_cause;
167f7917c00SJeff Kirsher
168f7917c00SJeff Kirsher pci_read_config_dword(adapter->pdev, A_PCICFG_INTR_CAUSE, &pcix_cause);
169f7917c00SJeff Kirsher
170f7917c00SJeff Kirsher if (pcix_cause) {
171f7917c00SJeff Kirsher pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_CAUSE,
172f7917c00SJeff Kirsher pcix_cause);
17382154580SSebastian Andrzej Siewior /* PCI errors are fatal */
17482154580SSebastian Andrzej Siewior t1_interrupts_disable(adapter);
17582154580SSebastian Andrzej Siewior adapter->pending_thread_intr |= F_PL_INTR_SGE_ERR;
17682154580SSebastian Andrzej Siewior pr_alert("%s: PCI error encountered.\n", adapter->name);
17782154580SSebastian Andrzej Siewior return true;
178f7917c00SJeff Kirsher }
17982154580SSebastian Andrzej Siewior return false;
180f7917c00SJeff Kirsher }
181f7917c00SJeff Kirsher
182f7917c00SJeff Kirsher #ifdef CONFIG_CHELSIO_T1_1G
183f7917c00SJeff Kirsher #include "fpga_defs.h"
184f7917c00SJeff Kirsher
185f7917c00SJeff Kirsher /*
186f7917c00SJeff Kirsher * PHY interrupt handler for FPGA boards.
187f7917c00SJeff Kirsher */
fpga_phy_intr_handler(adapter_t * adapter)188f7917c00SJeff Kirsher static int fpga_phy_intr_handler(adapter_t *adapter)
189f7917c00SJeff Kirsher {
190f7917c00SJeff Kirsher int p;
191f7917c00SJeff Kirsher u32 cause = readl(adapter->regs + FPGA_GMAC_ADDR_INTERRUPT_CAUSE);
192f7917c00SJeff Kirsher
193f7917c00SJeff Kirsher for_each_port(adapter, p)
194f7917c00SJeff Kirsher if (cause & (1 << p)) {
195f7917c00SJeff Kirsher struct cphy *phy = adapter->port[p].phy;
196f7917c00SJeff Kirsher int phy_cause = phy->ops->interrupt_handler(phy);
197f7917c00SJeff Kirsher
198f7917c00SJeff Kirsher if (phy_cause & cphy_cause_link_change)
199f7917c00SJeff Kirsher t1_link_changed(adapter, p);
200f7917c00SJeff Kirsher }
201f7917c00SJeff Kirsher writel(cause, adapter->regs + FPGA_GMAC_ADDR_INTERRUPT_CAUSE);
202f7917c00SJeff Kirsher return 0;
203f7917c00SJeff Kirsher }
204f7917c00SJeff Kirsher
205f7917c00SJeff Kirsher /*
206f7917c00SJeff Kirsher * Slow path interrupt handler for FPGAs.
207f7917c00SJeff Kirsher */
fpga_slow_intr(adapter_t * adapter)208fec7fa0aSSebastian Andrzej Siewior static irqreturn_t fpga_slow_intr(adapter_t *adapter)
209f7917c00SJeff Kirsher {
210f7917c00SJeff Kirsher u32 cause = readl(adapter->regs + A_PL_CAUSE);
21182154580SSebastian Andrzej Siewior irqreturn_t ret = IRQ_NONE;
212f7917c00SJeff Kirsher
213f7917c00SJeff Kirsher cause &= ~F_PL_INTR_SGE_DATA;
21482154580SSebastian Andrzej Siewior if (cause & F_PL_INTR_SGE_ERR) {
21582154580SSebastian Andrzej Siewior if (t1_sge_intr_error_handler(adapter->sge))
21682154580SSebastian Andrzej Siewior ret = IRQ_WAKE_THREAD;
21782154580SSebastian Andrzej Siewior }
218f7917c00SJeff Kirsher
219f7917c00SJeff Kirsher if (cause & FPGA_PCIX_INTERRUPT_GMAC)
220f7917c00SJeff Kirsher fpga_phy_intr_handler(adapter);
221f7917c00SJeff Kirsher
222f7917c00SJeff Kirsher if (cause & FPGA_PCIX_INTERRUPT_TP) {
223f7917c00SJeff Kirsher /*
224f7917c00SJeff Kirsher * FPGA doesn't support MC4 interrupts and it requires
225f7917c00SJeff Kirsher * this odd layer of indirection for MC5.
226f7917c00SJeff Kirsher */
227f7917c00SJeff Kirsher u32 tp_cause = readl(adapter->regs + FPGA_TP_ADDR_INTERRUPT_CAUSE);
228f7917c00SJeff Kirsher
229f7917c00SJeff Kirsher /* Clear TP interrupt */
230f7917c00SJeff Kirsher writel(tp_cause, adapter->regs + FPGA_TP_ADDR_INTERRUPT_CAUSE);
231f7917c00SJeff Kirsher }
23282154580SSebastian Andrzej Siewior if (cause & FPGA_PCIX_INTERRUPT_PCIX) {
23382154580SSebastian Andrzej Siewior if (t1_pci_intr_handler(adapter))
23482154580SSebastian Andrzej Siewior ret = IRQ_WAKE_THREAD;
23582154580SSebastian Andrzej Siewior }
236f7917c00SJeff Kirsher
237f7917c00SJeff Kirsher /* Clear the interrupts just processed. */
238f7917c00SJeff Kirsher if (cause)
239f7917c00SJeff Kirsher writel(cause, adapter->regs + A_PL_CAUSE);
240f7917c00SJeff Kirsher
24182154580SSebastian Andrzej Siewior if (ret != IRQ_NONE)
24282154580SSebastian Andrzej Siewior return ret;
24382154580SSebastian Andrzej Siewior
244fec7fa0aSSebastian Andrzej Siewior return cause == 0 ? IRQ_NONE : IRQ_HANDLED;
245f7917c00SJeff Kirsher }
246f7917c00SJeff Kirsher #endif
247f7917c00SJeff Kirsher
248f7917c00SJeff Kirsher /*
249f7917c00SJeff Kirsher * Wait until Elmer's MI1 interface is ready for new operations.
250f7917c00SJeff Kirsher */
mi1_wait_until_ready(adapter_t * adapter,int mi1_reg)251f7917c00SJeff Kirsher static int mi1_wait_until_ready(adapter_t *adapter, int mi1_reg)
252f7917c00SJeff Kirsher {
253f7917c00SJeff Kirsher int attempts = 100, busy;
254f7917c00SJeff Kirsher
255f7917c00SJeff Kirsher do {
256f7917c00SJeff Kirsher u32 val;
257f7917c00SJeff Kirsher
258f7917c00SJeff Kirsher __t1_tpi_read(adapter, mi1_reg, &val);
259f7917c00SJeff Kirsher busy = val & F_MI1_OP_BUSY;
260f7917c00SJeff Kirsher if (busy)
261f7917c00SJeff Kirsher udelay(10);
262f7917c00SJeff Kirsher } while (busy && --attempts);
263f7917c00SJeff Kirsher if (busy)
264f7917c00SJeff Kirsher pr_alert("%s: MDIO operation timed out\n", adapter->name);
265f7917c00SJeff Kirsher return busy;
266f7917c00SJeff Kirsher }
267f7917c00SJeff Kirsher
268f7917c00SJeff Kirsher /*
269f7917c00SJeff Kirsher * MI1 MDIO initialization.
270f7917c00SJeff Kirsher */
mi1_mdio_init(adapter_t * adapter,const struct board_info * bi)271f7917c00SJeff Kirsher static void mi1_mdio_init(adapter_t *adapter, const struct board_info *bi)
272f7917c00SJeff Kirsher {
273f7917c00SJeff Kirsher u32 clkdiv = bi->clock_elmer0 / (2 * bi->mdio_mdc) - 1;
274f7917c00SJeff Kirsher u32 val = F_MI1_PREAMBLE_ENABLE | V_MI1_MDI_INVERT(bi->mdio_mdiinv) |
275f7917c00SJeff Kirsher V_MI1_MDI_ENABLE(bi->mdio_mdien) | V_MI1_CLK_DIV(clkdiv);
276f7917c00SJeff Kirsher
277f7917c00SJeff Kirsher if (!(bi->caps & SUPPORTED_10000baseT_Full))
278f7917c00SJeff Kirsher val |= V_MI1_SOF(1);
279f7917c00SJeff Kirsher t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_CFG, val);
280f7917c00SJeff Kirsher }
281f7917c00SJeff Kirsher
282f7917c00SJeff Kirsher #if defined(CONFIG_CHELSIO_T1_1G)
283f7917c00SJeff Kirsher /*
284f7917c00SJeff Kirsher * Elmer MI1 MDIO read/write operations.
285f7917c00SJeff Kirsher */
mi1_mdio_read(struct net_device * dev,int phy_addr,int mmd_addr,u16 reg_addr)286f7917c00SJeff Kirsher static int mi1_mdio_read(struct net_device *dev, int phy_addr, int mmd_addr,
287f7917c00SJeff Kirsher u16 reg_addr)
288f7917c00SJeff Kirsher {
289f7917c00SJeff Kirsher struct adapter *adapter = dev->ml_priv;
290f7917c00SJeff Kirsher u32 addr = V_MI1_REG_ADDR(reg_addr) | V_MI1_PHY_ADDR(phy_addr);
291f7917c00SJeff Kirsher unsigned int val;
292f7917c00SJeff Kirsher
293f7917c00SJeff Kirsher spin_lock(&adapter->tpi_lock);
294f7917c00SJeff Kirsher __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_ADDR, addr);
295f7917c00SJeff Kirsher __t1_tpi_write(adapter,
296f7917c00SJeff Kirsher A_ELMER0_PORT0_MI1_OP, MI1_OP_DIRECT_READ);
297f7917c00SJeff Kirsher mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP);
298f7917c00SJeff Kirsher __t1_tpi_read(adapter, A_ELMER0_PORT0_MI1_DATA, &val);
299f7917c00SJeff Kirsher spin_unlock(&adapter->tpi_lock);
300f7917c00SJeff Kirsher return val;
301f7917c00SJeff Kirsher }
302f7917c00SJeff Kirsher
mi1_mdio_write(struct net_device * dev,int phy_addr,int mmd_addr,u16 reg_addr,u16 val)303f7917c00SJeff Kirsher static int mi1_mdio_write(struct net_device *dev, int phy_addr, int mmd_addr,
304f7917c00SJeff Kirsher u16 reg_addr, u16 val)
305f7917c00SJeff Kirsher {
306f7917c00SJeff Kirsher struct adapter *adapter = dev->ml_priv;
307f7917c00SJeff Kirsher u32 addr = V_MI1_REG_ADDR(reg_addr) | V_MI1_PHY_ADDR(phy_addr);
308f7917c00SJeff Kirsher
309f7917c00SJeff Kirsher spin_lock(&adapter->tpi_lock);
310f7917c00SJeff Kirsher __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_ADDR, addr);
311f7917c00SJeff Kirsher __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_DATA, val);
312f7917c00SJeff Kirsher __t1_tpi_write(adapter,
313f7917c00SJeff Kirsher A_ELMER0_PORT0_MI1_OP, MI1_OP_DIRECT_WRITE);
314f7917c00SJeff Kirsher mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP);
315f7917c00SJeff Kirsher spin_unlock(&adapter->tpi_lock);
316f7917c00SJeff Kirsher return 0;
317f7917c00SJeff Kirsher }
318f7917c00SJeff Kirsher
319f7917c00SJeff Kirsher static const struct mdio_ops mi1_mdio_ops = {
320f7917c00SJeff Kirsher .init = mi1_mdio_init,
321f7917c00SJeff Kirsher .read = mi1_mdio_read,
322f7917c00SJeff Kirsher .write = mi1_mdio_write,
323f7917c00SJeff Kirsher .mode_support = MDIO_SUPPORTS_C22
324f7917c00SJeff Kirsher };
325f7917c00SJeff Kirsher
326f7917c00SJeff Kirsher #endif
327f7917c00SJeff Kirsher
mi1_mdio_ext_read(struct net_device * dev,int phy_addr,int mmd_addr,u16 reg_addr)328f7917c00SJeff Kirsher static int mi1_mdio_ext_read(struct net_device *dev, int phy_addr, int mmd_addr,
329f7917c00SJeff Kirsher u16 reg_addr)
330f7917c00SJeff Kirsher {
331f7917c00SJeff Kirsher struct adapter *adapter = dev->ml_priv;
332f7917c00SJeff Kirsher u32 addr = V_MI1_REG_ADDR(mmd_addr) | V_MI1_PHY_ADDR(phy_addr);
333f7917c00SJeff Kirsher unsigned int val;
334f7917c00SJeff Kirsher
335f7917c00SJeff Kirsher spin_lock(&adapter->tpi_lock);
336f7917c00SJeff Kirsher
337f7917c00SJeff Kirsher /* Write the address we want. */
338f7917c00SJeff Kirsher __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_ADDR, addr);
339f7917c00SJeff Kirsher __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_DATA, reg_addr);
340f7917c00SJeff Kirsher __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_OP,
341f7917c00SJeff Kirsher MI1_OP_INDIRECT_ADDRESS);
342f7917c00SJeff Kirsher mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP);
343f7917c00SJeff Kirsher
344f7917c00SJeff Kirsher /* Write the operation we want. */
345f7917c00SJeff Kirsher __t1_tpi_write(adapter,
346f7917c00SJeff Kirsher A_ELMER0_PORT0_MI1_OP, MI1_OP_INDIRECT_READ);
347f7917c00SJeff Kirsher mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP);
348f7917c00SJeff Kirsher
349f7917c00SJeff Kirsher /* Read the data. */
350f7917c00SJeff Kirsher __t1_tpi_read(adapter, A_ELMER0_PORT0_MI1_DATA, &val);
351f7917c00SJeff Kirsher spin_unlock(&adapter->tpi_lock);
352f7917c00SJeff Kirsher return val;
353f7917c00SJeff Kirsher }
354f7917c00SJeff Kirsher
mi1_mdio_ext_write(struct net_device * dev,int phy_addr,int mmd_addr,u16 reg_addr,u16 val)355f7917c00SJeff Kirsher static int mi1_mdio_ext_write(struct net_device *dev, int phy_addr,
356f7917c00SJeff Kirsher int mmd_addr, u16 reg_addr, u16 val)
357f7917c00SJeff Kirsher {
358f7917c00SJeff Kirsher struct adapter *adapter = dev->ml_priv;
359f7917c00SJeff Kirsher u32 addr = V_MI1_REG_ADDR(mmd_addr) | V_MI1_PHY_ADDR(phy_addr);
360f7917c00SJeff Kirsher
361f7917c00SJeff Kirsher spin_lock(&adapter->tpi_lock);
362f7917c00SJeff Kirsher
363f7917c00SJeff Kirsher /* Write the address we want. */
364f7917c00SJeff Kirsher __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_ADDR, addr);
365f7917c00SJeff Kirsher __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_DATA, reg_addr);
366f7917c00SJeff Kirsher __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_OP,
367f7917c00SJeff Kirsher MI1_OP_INDIRECT_ADDRESS);
368f7917c00SJeff Kirsher mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP);
369f7917c00SJeff Kirsher
370f7917c00SJeff Kirsher /* Write the data. */
371f7917c00SJeff Kirsher __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_DATA, val);
372f7917c00SJeff Kirsher __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_OP, MI1_OP_INDIRECT_WRITE);
373f7917c00SJeff Kirsher mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP);
374f7917c00SJeff Kirsher spin_unlock(&adapter->tpi_lock);
375f7917c00SJeff Kirsher return 0;
376f7917c00SJeff Kirsher }
377f7917c00SJeff Kirsher
378f7917c00SJeff Kirsher static const struct mdio_ops mi1_mdio_ext_ops = {
379f7917c00SJeff Kirsher .init = mi1_mdio_init,
380f7917c00SJeff Kirsher .read = mi1_mdio_ext_read,
381f7917c00SJeff Kirsher .write = mi1_mdio_ext_write,
382f7917c00SJeff Kirsher .mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22
383f7917c00SJeff Kirsher };
384f7917c00SJeff Kirsher
385f7917c00SJeff Kirsher enum {
386f7917c00SJeff Kirsher CH_BRD_T110_1CU,
387f7917c00SJeff Kirsher CH_BRD_N110_1F,
388f7917c00SJeff Kirsher CH_BRD_N210_1F,
389f7917c00SJeff Kirsher CH_BRD_T210_1F,
390f7917c00SJeff Kirsher CH_BRD_T210_1CU,
391f7917c00SJeff Kirsher CH_BRD_N204_4CU,
392f7917c00SJeff Kirsher };
393f7917c00SJeff Kirsher
394f7917c00SJeff Kirsher static const struct board_info t1_board[] = {
395f7917c00SJeff Kirsher {
396f7917c00SJeff Kirsher .board = CHBT_BOARD_CHT110,
397f7917c00SJeff Kirsher .port_number = 1,
398f7917c00SJeff Kirsher .caps = SUPPORTED_10000baseT_Full,
399f7917c00SJeff Kirsher .chip_term = CHBT_TERM_T1,
400f7917c00SJeff Kirsher .chip_mac = CHBT_MAC_PM3393,
401f7917c00SJeff Kirsher .chip_phy = CHBT_PHY_MY3126,
402f7917c00SJeff Kirsher .clock_core = 125000000,
403f7917c00SJeff Kirsher .clock_mc3 = 150000000,
404f7917c00SJeff Kirsher .clock_mc4 = 125000000,
405f7917c00SJeff Kirsher .espi_nports = 1,
406f7917c00SJeff Kirsher .clock_elmer0 = 44,
407f7917c00SJeff Kirsher .mdio_mdien = 1,
408f7917c00SJeff Kirsher .mdio_mdiinv = 1,
409f7917c00SJeff Kirsher .mdio_mdc = 1,
410f7917c00SJeff Kirsher .mdio_phybaseaddr = 1,
411f7917c00SJeff Kirsher .gmac = &t1_pm3393_ops,
412f7917c00SJeff Kirsher .gphy = &t1_my3126_ops,
413f7917c00SJeff Kirsher .mdio_ops = &mi1_mdio_ext_ops,
414f7917c00SJeff Kirsher .desc = "Chelsio T110 1x10GBase-CX4 TOE",
415f7917c00SJeff Kirsher },
416f7917c00SJeff Kirsher
417f7917c00SJeff Kirsher {
418f7917c00SJeff Kirsher .board = CHBT_BOARD_N110,
419f7917c00SJeff Kirsher .port_number = 1,
420f7917c00SJeff Kirsher .caps = SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE,
421f7917c00SJeff Kirsher .chip_term = CHBT_TERM_T1,
422f7917c00SJeff Kirsher .chip_mac = CHBT_MAC_PM3393,
423f7917c00SJeff Kirsher .chip_phy = CHBT_PHY_88X2010,
424f7917c00SJeff Kirsher .clock_core = 125000000,
425f7917c00SJeff Kirsher .espi_nports = 1,
426f7917c00SJeff Kirsher .clock_elmer0 = 44,
427f7917c00SJeff Kirsher .mdio_mdien = 0,
428f7917c00SJeff Kirsher .mdio_mdiinv = 0,
429f7917c00SJeff Kirsher .mdio_mdc = 1,
430f7917c00SJeff Kirsher .mdio_phybaseaddr = 0,
431f7917c00SJeff Kirsher .gmac = &t1_pm3393_ops,
432f7917c00SJeff Kirsher .gphy = &t1_mv88x201x_ops,
433f7917c00SJeff Kirsher .mdio_ops = &mi1_mdio_ext_ops,
434f7917c00SJeff Kirsher .desc = "Chelsio N110 1x10GBaseX NIC",
435f7917c00SJeff Kirsher },
436f7917c00SJeff Kirsher
437f7917c00SJeff Kirsher {
438f7917c00SJeff Kirsher .board = CHBT_BOARD_N210,
439f7917c00SJeff Kirsher .port_number = 1,
440f7917c00SJeff Kirsher .caps = SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE,
441f7917c00SJeff Kirsher .chip_term = CHBT_TERM_T2,
442f7917c00SJeff Kirsher .chip_mac = CHBT_MAC_PM3393,
443f7917c00SJeff Kirsher .chip_phy = CHBT_PHY_88X2010,
444f7917c00SJeff Kirsher .clock_core = 125000000,
445f7917c00SJeff Kirsher .espi_nports = 1,
446f7917c00SJeff Kirsher .clock_elmer0 = 44,
447f7917c00SJeff Kirsher .mdio_mdien = 0,
448f7917c00SJeff Kirsher .mdio_mdiinv = 0,
449f7917c00SJeff Kirsher .mdio_mdc = 1,
450f7917c00SJeff Kirsher .mdio_phybaseaddr = 0,
451f7917c00SJeff Kirsher .gmac = &t1_pm3393_ops,
452f7917c00SJeff Kirsher .gphy = &t1_mv88x201x_ops,
453f7917c00SJeff Kirsher .mdio_ops = &mi1_mdio_ext_ops,
454f7917c00SJeff Kirsher .desc = "Chelsio N210 1x10GBaseX NIC",
455f7917c00SJeff Kirsher },
456f7917c00SJeff Kirsher
457f7917c00SJeff Kirsher {
458f7917c00SJeff Kirsher .board = CHBT_BOARD_CHT210,
459f7917c00SJeff Kirsher .port_number = 1,
460f7917c00SJeff Kirsher .caps = SUPPORTED_10000baseT_Full,
461f7917c00SJeff Kirsher .chip_term = CHBT_TERM_T2,
462f7917c00SJeff Kirsher .chip_mac = CHBT_MAC_PM3393,
463f7917c00SJeff Kirsher .chip_phy = CHBT_PHY_88X2010,
464f7917c00SJeff Kirsher .clock_core = 125000000,
465f7917c00SJeff Kirsher .clock_mc3 = 133000000,
466f7917c00SJeff Kirsher .clock_mc4 = 125000000,
467f7917c00SJeff Kirsher .espi_nports = 1,
468f7917c00SJeff Kirsher .clock_elmer0 = 44,
469f7917c00SJeff Kirsher .mdio_mdien = 0,
470f7917c00SJeff Kirsher .mdio_mdiinv = 0,
471f7917c00SJeff Kirsher .mdio_mdc = 1,
472f7917c00SJeff Kirsher .mdio_phybaseaddr = 0,
473f7917c00SJeff Kirsher .gmac = &t1_pm3393_ops,
474f7917c00SJeff Kirsher .gphy = &t1_mv88x201x_ops,
475f7917c00SJeff Kirsher .mdio_ops = &mi1_mdio_ext_ops,
476f7917c00SJeff Kirsher .desc = "Chelsio T210 1x10GBaseX TOE",
477f7917c00SJeff Kirsher },
478f7917c00SJeff Kirsher
479f7917c00SJeff Kirsher {
480f7917c00SJeff Kirsher .board = CHBT_BOARD_CHT210,
481f7917c00SJeff Kirsher .port_number = 1,
482f7917c00SJeff Kirsher .caps = SUPPORTED_10000baseT_Full,
483f7917c00SJeff Kirsher .chip_term = CHBT_TERM_T2,
484f7917c00SJeff Kirsher .chip_mac = CHBT_MAC_PM3393,
485f7917c00SJeff Kirsher .chip_phy = CHBT_PHY_MY3126,
486f7917c00SJeff Kirsher .clock_core = 125000000,
487f7917c00SJeff Kirsher .clock_mc3 = 133000000,
488f7917c00SJeff Kirsher .clock_mc4 = 125000000,
489f7917c00SJeff Kirsher .espi_nports = 1,
490f7917c00SJeff Kirsher .clock_elmer0 = 44,
491f7917c00SJeff Kirsher .mdio_mdien = 1,
492f7917c00SJeff Kirsher .mdio_mdiinv = 1,
493f7917c00SJeff Kirsher .mdio_mdc = 1,
494f7917c00SJeff Kirsher .mdio_phybaseaddr = 1,
495f7917c00SJeff Kirsher .gmac = &t1_pm3393_ops,
496f7917c00SJeff Kirsher .gphy = &t1_my3126_ops,
497f7917c00SJeff Kirsher .mdio_ops = &mi1_mdio_ext_ops,
498f7917c00SJeff Kirsher .desc = "Chelsio T210 1x10GBase-CX4 TOE",
499f7917c00SJeff Kirsher },
500f7917c00SJeff Kirsher
501f7917c00SJeff Kirsher #ifdef CONFIG_CHELSIO_T1_1G
502f7917c00SJeff Kirsher {
503f7917c00SJeff Kirsher .board = CHBT_BOARD_CHN204,
504f7917c00SJeff Kirsher .port_number = 4,
505f7917c00SJeff Kirsher .caps = SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full
506f7917c00SJeff Kirsher | SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full
507f7917c00SJeff Kirsher | SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg |
508f7917c00SJeff Kirsher SUPPORTED_PAUSE | SUPPORTED_TP,
509f7917c00SJeff Kirsher .chip_term = CHBT_TERM_T2,
510f7917c00SJeff Kirsher .chip_mac = CHBT_MAC_VSC7321,
511f7917c00SJeff Kirsher .chip_phy = CHBT_PHY_88E1111,
512f7917c00SJeff Kirsher .clock_core = 100000000,
513f7917c00SJeff Kirsher .espi_nports = 4,
514f7917c00SJeff Kirsher .clock_elmer0 = 44,
515f7917c00SJeff Kirsher .mdio_mdien = 0,
516f7917c00SJeff Kirsher .mdio_mdiinv = 0,
517f7917c00SJeff Kirsher .mdio_mdc = 0,
518f7917c00SJeff Kirsher .mdio_phybaseaddr = 4,
519f7917c00SJeff Kirsher .gmac = &t1_vsc7326_ops,
520f7917c00SJeff Kirsher .gphy = &t1_mv88e1xxx_ops,
521f7917c00SJeff Kirsher .mdio_ops = &mi1_mdio_ops,
522f7917c00SJeff Kirsher .desc = "Chelsio N204 4x100/1000BaseT NIC",
523f7917c00SJeff Kirsher },
524f7917c00SJeff Kirsher #endif
525f7917c00SJeff Kirsher
526f7917c00SJeff Kirsher };
527f7917c00SJeff Kirsher
5289baa3c34SBenoit Taine const struct pci_device_id t1_pci_tbl[] = {
529f7917c00SJeff Kirsher CH_DEVICE(8, 0, CH_BRD_T110_1CU),
530f7917c00SJeff Kirsher CH_DEVICE(8, 1, CH_BRD_T110_1CU),
531f7917c00SJeff Kirsher CH_DEVICE(7, 0, CH_BRD_N110_1F),
532f7917c00SJeff Kirsher CH_DEVICE(10, 1, CH_BRD_N210_1F),
533f7917c00SJeff Kirsher CH_DEVICE(11, 1, CH_BRD_T210_1F),
534f7917c00SJeff Kirsher CH_DEVICE(14, 1, CH_BRD_T210_1CU),
535f7917c00SJeff Kirsher CH_DEVICE(16, 1, CH_BRD_N204_4CU),
536f7917c00SJeff Kirsher { 0 }
537f7917c00SJeff Kirsher };
538f7917c00SJeff Kirsher
539f7917c00SJeff Kirsher MODULE_DEVICE_TABLE(pci, t1_pci_tbl);
540f7917c00SJeff Kirsher
541f7917c00SJeff Kirsher /*
542f7917c00SJeff Kirsher * Return the board_info structure with a given index. Out-of-range indices
543f7917c00SJeff Kirsher * return NULL.
544f7917c00SJeff Kirsher */
t1_get_board_info(unsigned int board_id)545f7917c00SJeff Kirsher const struct board_info *t1_get_board_info(unsigned int board_id)
546f7917c00SJeff Kirsher {
547f7917c00SJeff Kirsher return board_id < ARRAY_SIZE(t1_board) ? &t1_board[board_id] : NULL;
548f7917c00SJeff Kirsher }
549f7917c00SJeff Kirsher
550f7917c00SJeff Kirsher struct chelsio_vpd_t {
551f7917c00SJeff Kirsher u32 format_version;
552f7917c00SJeff Kirsher u8 serial_number[16];
553f7917c00SJeff Kirsher u8 mac_base_address[6];
554f7917c00SJeff Kirsher u8 pad[2]; /* make multiple-of-4 size requirement explicit */
555f7917c00SJeff Kirsher };
556f7917c00SJeff Kirsher
557f7917c00SJeff Kirsher #define EEPROMSIZE (8 * 1024)
558f7917c00SJeff Kirsher #define EEPROM_MAX_POLL 4
559f7917c00SJeff Kirsher
560f7917c00SJeff Kirsher /*
561f7917c00SJeff Kirsher * Read SEEPROM. A zero is written to the flag register when the address is
562f7917c00SJeff Kirsher * written to the Control register. The hardware device will set the flag to a
563f7917c00SJeff Kirsher * one when 4B have been transferred to the Data register.
564f7917c00SJeff Kirsher */
t1_seeprom_read(adapter_t * adapter,u32 addr,__le32 * data)565f7917c00SJeff Kirsher int t1_seeprom_read(adapter_t *adapter, u32 addr, __le32 *data)
566f7917c00SJeff Kirsher {
567f7917c00SJeff Kirsher int i = EEPROM_MAX_POLL;
568f7917c00SJeff Kirsher u16 val;
569f7917c00SJeff Kirsher u32 v;
570f7917c00SJeff Kirsher
571f7917c00SJeff Kirsher if (addr >= EEPROMSIZE || (addr & 3))
572f7917c00SJeff Kirsher return -EINVAL;
573f7917c00SJeff Kirsher
574f7917c00SJeff Kirsher pci_write_config_word(adapter->pdev, A_PCICFG_VPD_ADDR, (u16)addr);
575f7917c00SJeff Kirsher do {
576f7917c00SJeff Kirsher udelay(50);
577f7917c00SJeff Kirsher pci_read_config_word(adapter->pdev, A_PCICFG_VPD_ADDR, &val);
578f7917c00SJeff Kirsher } while (!(val & F_VPD_OP_FLAG) && --i);
579f7917c00SJeff Kirsher
580f7917c00SJeff Kirsher if (!(val & F_VPD_OP_FLAG)) {
581f7917c00SJeff Kirsher pr_err("%s: reading EEPROM address 0x%x failed\n",
582f7917c00SJeff Kirsher adapter->name, addr);
583f7917c00SJeff Kirsher return -EIO;
584f7917c00SJeff Kirsher }
585f7917c00SJeff Kirsher pci_read_config_dword(adapter->pdev, A_PCICFG_VPD_DATA, &v);
586f7917c00SJeff Kirsher *data = cpu_to_le32(v);
587f7917c00SJeff Kirsher return 0;
588f7917c00SJeff Kirsher }
589f7917c00SJeff Kirsher
t1_eeprom_vpd_get(adapter_t * adapter,struct chelsio_vpd_t * vpd)590f7917c00SJeff Kirsher static int t1_eeprom_vpd_get(adapter_t *adapter, struct chelsio_vpd_t *vpd)
591f7917c00SJeff Kirsher {
592f7917c00SJeff Kirsher int addr, ret = 0;
593f7917c00SJeff Kirsher
594f7917c00SJeff Kirsher for (addr = 0; !ret && addr < sizeof(*vpd); addr += sizeof(u32))
595f7917c00SJeff Kirsher ret = t1_seeprom_read(adapter, addr,
596f7917c00SJeff Kirsher (__le32 *)((u8 *)vpd + addr));
597f7917c00SJeff Kirsher
598f7917c00SJeff Kirsher return ret;
599f7917c00SJeff Kirsher }
600f7917c00SJeff Kirsher
601f7917c00SJeff Kirsher /*
602f7917c00SJeff Kirsher * Read a port's MAC address from the VPD ROM.
603f7917c00SJeff Kirsher */
vpd_macaddress_get(adapter_t * adapter,int index,u8 mac_addr[])604f7917c00SJeff Kirsher static int vpd_macaddress_get(adapter_t *adapter, int index, u8 mac_addr[])
605f7917c00SJeff Kirsher {
606f7917c00SJeff Kirsher struct chelsio_vpd_t vpd;
607f7917c00SJeff Kirsher
608f7917c00SJeff Kirsher if (t1_eeprom_vpd_get(adapter, &vpd))
609f7917c00SJeff Kirsher return 1;
610f7917c00SJeff Kirsher memcpy(mac_addr, vpd.mac_base_address, 5);
611f7917c00SJeff Kirsher mac_addr[5] = vpd.mac_base_address[5] + index;
612f7917c00SJeff Kirsher return 0;
613f7917c00SJeff Kirsher }
614f7917c00SJeff Kirsher
615f7917c00SJeff Kirsher /*
616f7917c00SJeff Kirsher * Set up the MAC/PHY according to the requested link settings.
617f7917c00SJeff Kirsher *
618f7917c00SJeff Kirsher * If the PHY can auto-negotiate first decide what to advertise, then
619f7917c00SJeff Kirsher * enable/disable auto-negotiation as desired and reset.
620f7917c00SJeff Kirsher *
621f7917c00SJeff Kirsher * If the PHY does not auto-negotiate we just reset it.
622f7917c00SJeff Kirsher *
623f7917c00SJeff Kirsher * If auto-negotiation is off set the MAC to the proper speed/duplex/FC,
624f7917c00SJeff Kirsher * otherwise do it later based on the outcome of auto-negotiation.
625f7917c00SJeff Kirsher */
t1_link_start(struct cphy * phy,struct cmac * mac,struct link_config * lc)626f7917c00SJeff Kirsher int t1_link_start(struct cphy *phy, struct cmac *mac, struct link_config *lc)
627f7917c00SJeff Kirsher {
628f7917c00SJeff Kirsher unsigned int fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
629f7917c00SJeff Kirsher
630f7917c00SJeff Kirsher if (lc->supported & SUPPORTED_Autoneg) {
631f7917c00SJeff Kirsher lc->advertising &= ~(ADVERTISED_ASYM_PAUSE | ADVERTISED_PAUSE);
632f7917c00SJeff Kirsher if (fc) {
633f7917c00SJeff Kirsher if (fc == ((PAUSE_RX | PAUSE_TX) &
634f7917c00SJeff Kirsher (mac->adapter->params.nports < 2)))
635f7917c00SJeff Kirsher lc->advertising |= ADVERTISED_PAUSE;
636f7917c00SJeff Kirsher else {
637f7917c00SJeff Kirsher lc->advertising |= ADVERTISED_ASYM_PAUSE;
638f7917c00SJeff Kirsher if (fc == PAUSE_RX)
639f7917c00SJeff Kirsher lc->advertising |= ADVERTISED_PAUSE;
640f7917c00SJeff Kirsher }
641f7917c00SJeff Kirsher }
642f7917c00SJeff Kirsher phy->ops->advertise(phy, lc->advertising);
643f7917c00SJeff Kirsher
644f7917c00SJeff Kirsher if (lc->autoneg == AUTONEG_DISABLE) {
645f7917c00SJeff Kirsher lc->speed = lc->requested_speed;
646f7917c00SJeff Kirsher lc->duplex = lc->requested_duplex;
647f7917c00SJeff Kirsher lc->fc = (unsigned char)fc;
648f7917c00SJeff Kirsher mac->ops->set_speed_duplex_fc(mac, lc->speed,
649f7917c00SJeff Kirsher lc->duplex, fc);
650f7917c00SJeff Kirsher /* Also disables autoneg */
651f7917c00SJeff Kirsher phy->state = PHY_AUTONEG_RDY;
652f7917c00SJeff Kirsher phy->ops->set_speed_duplex(phy, lc->speed, lc->duplex);
653f7917c00SJeff Kirsher phy->ops->reset(phy, 0);
654f7917c00SJeff Kirsher } else {
655f7917c00SJeff Kirsher phy->state = PHY_AUTONEG_EN;
656f7917c00SJeff Kirsher phy->ops->autoneg_enable(phy); /* also resets PHY */
657f7917c00SJeff Kirsher }
658f7917c00SJeff Kirsher } else {
659f7917c00SJeff Kirsher phy->state = PHY_AUTONEG_RDY;
660f7917c00SJeff Kirsher mac->ops->set_speed_duplex_fc(mac, -1, -1, fc);
661f7917c00SJeff Kirsher lc->fc = (unsigned char)fc;
662f7917c00SJeff Kirsher phy->ops->reset(phy, 0);
663f7917c00SJeff Kirsher }
664f7917c00SJeff Kirsher return 0;
665f7917c00SJeff Kirsher }
666f7917c00SJeff Kirsher
667f7917c00SJeff Kirsher /*
668f7917c00SJeff Kirsher * External interrupt handler for boards using elmer0.
669f7917c00SJeff Kirsher */
t1_elmer0_ext_intr_handler(adapter_t * adapter)670f7917c00SJeff Kirsher int t1_elmer0_ext_intr_handler(adapter_t *adapter)
671f7917c00SJeff Kirsher {
672f7917c00SJeff Kirsher struct cphy *phy;
673f7917c00SJeff Kirsher int phy_cause;
674f7917c00SJeff Kirsher u32 cause;
675f7917c00SJeff Kirsher
676f7917c00SJeff Kirsher t1_tpi_read(adapter, A_ELMER0_INT_CAUSE, &cause);
677f7917c00SJeff Kirsher
678f7917c00SJeff Kirsher switch (board_info(adapter)->board) {
679f7917c00SJeff Kirsher #ifdef CONFIG_CHELSIO_T1_1G
680f7917c00SJeff Kirsher case CHBT_BOARD_CHT204:
681f7917c00SJeff Kirsher case CHBT_BOARD_CHT204E:
682f7917c00SJeff Kirsher case CHBT_BOARD_CHN204:
683f7917c00SJeff Kirsher case CHBT_BOARD_CHT204V: {
684f7917c00SJeff Kirsher int i, port_bit;
685f7917c00SJeff Kirsher for_each_port(adapter, i) {
686f7917c00SJeff Kirsher port_bit = i + 1;
687f7917c00SJeff Kirsher if (!(cause & (1 << port_bit)))
688f7917c00SJeff Kirsher continue;
689f7917c00SJeff Kirsher
690f7917c00SJeff Kirsher phy = adapter->port[i].phy;
691f7917c00SJeff Kirsher phy_cause = phy->ops->interrupt_handler(phy);
692f7917c00SJeff Kirsher if (phy_cause & cphy_cause_link_change)
693f7917c00SJeff Kirsher t1_link_changed(adapter, i);
694f7917c00SJeff Kirsher }
695f7917c00SJeff Kirsher break;
696f7917c00SJeff Kirsher }
697f7917c00SJeff Kirsher case CHBT_BOARD_CHT101:
698f7917c00SJeff Kirsher if (cause & ELMER0_GP_BIT1) { /* Marvell 88E1111 interrupt */
699f7917c00SJeff Kirsher phy = adapter->port[0].phy;
700f7917c00SJeff Kirsher phy_cause = phy->ops->interrupt_handler(phy);
701f7917c00SJeff Kirsher if (phy_cause & cphy_cause_link_change)
702f7917c00SJeff Kirsher t1_link_changed(adapter, 0);
703f7917c00SJeff Kirsher }
704f7917c00SJeff Kirsher break;
705f7917c00SJeff Kirsher case CHBT_BOARD_7500: {
706f7917c00SJeff Kirsher int p;
707f7917c00SJeff Kirsher /*
708f7917c00SJeff Kirsher * Elmer0's interrupt cause isn't useful here because there is
709f7917c00SJeff Kirsher * only one bit that can be set for all 4 ports. This means
710f7917c00SJeff Kirsher * we are forced to check every PHY's interrupt status
711f7917c00SJeff Kirsher * register to see who initiated the interrupt.
712f7917c00SJeff Kirsher */
713f7917c00SJeff Kirsher for_each_port(adapter, p) {
714f7917c00SJeff Kirsher phy = adapter->port[p].phy;
715f7917c00SJeff Kirsher phy_cause = phy->ops->interrupt_handler(phy);
716f7917c00SJeff Kirsher if (phy_cause & cphy_cause_link_change)
717f7917c00SJeff Kirsher t1_link_changed(adapter, p);
718f7917c00SJeff Kirsher }
719f7917c00SJeff Kirsher break;
720f7917c00SJeff Kirsher }
721f7917c00SJeff Kirsher #endif
722f7917c00SJeff Kirsher case CHBT_BOARD_CHT210:
723f7917c00SJeff Kirsher case CHBT_BOARD_N210:
724f7917c00SJeff Kirsher case CHBT_BOARD_N110:
725f7917c00SJeff Kirsher if (cause & ELMER0_GP_BIT6) { /* Marvell 88x2010 interrupt */
726f7917c00SJeff Kirsher phy = adapter->port[0].phy;
727f7917c00SJeff Kirsher phy_cause = phy->ops->interrupt_handler(phy);
728f7917c00SJeff Kirsher if (phy_cause & cphy_cause_link_change)
729f7917c00SJeff Kirsher t1_link_changed(adapter, 0);
730f7917c00SJeff Kirsher }
731f7917c00SJeff Kirsher break;
732f7917c00SJeff Kirsher case CHBT_BOARD_8000:
733f7917c00SJeff Kirsher case CHBT_BOARD_CHT110:
734f7917c00SJeff Kirsher if (netif_msg_intr(adapter))
735f7917c00SJeff Kirsher dev_dbg(&adapter->pdev->dev,
736f7917c00SJeff Kirsher "External interrupt cause 0x%x\n", cause);
737f7917c00SJeff Kirsher if (cause & ELMER0_GP_BIT1) { /* PMC3393 INTB */
738f7917c00SJeff Kirsher struct cmac *mac = adapter->port[0].mac;
739f7917c00SJeff Kirsher
740f7917c00SJeff Kirsher mac->ops->interrupt_handler(mac);
741f7917c00SJeff Kirsher }
742f7917c00SJeff Kirsher if (cause & ELMER0_GP_BIT5) { /* XPAK MOD_DETECT */
743f7917c00SJeff Kirsher u32 mod_detect;
744f7917c00SJeff Kirsher
745f7917c00SJeff Kirsher t1_tpi_read(adapter,
746f7917c00SJeff Kirsher A_ELMER0_GPI_STAT, &mod_detect);
747f7917c00SJeff Kirsher if (netif_msg_link(adapter))
748f7917c00SJeff Kirsher dev_info(&adapter->pdev->dev, "XPAK %s\n",
749f7917c00SJeff Kirsher mod_detect ? "removed" : "inserted");
750f7917c00SJeff Kirsher }
751f7917c00SJeff Kirsher break;
752f7917c00SJeff Kirsher }
753f7917c00SJeff Kirsher t1_tpi_write(adapter, A_ELMER0_INT_CAUSE, cause);
754f7917c00SJeff Kirsher return 0;
755f7917c00SJeff Kirsher }
756f7917c00SJeff Kirsher
757f7917c00SJeff Kirsher /* Enables all interrupts. */
t1_interrupts_enable(adapter_t * adapter)758f7917c00SJeff Kirsher void t1_interrupts_enable(adapter_t *adapter)
759f7917c00SJeff Kirsher {
760f7917c00SJeff Kirsher unsigned int i;
761f7917c00SJeff Kirsher
762f7917c00SJeff Kirsher adapter->slow_intr_mask = F_PL_INTR_SGE_ERR | F_PL_INTR_TP;
763f7917c00SJeff Kirsher
764f7917c00SJeff Kirsher t1_sge_intr_enable(adapter->sge);
765f7917c00SJeff Kirsher t1_tp_intr_enable(adapter->tp);
766f7917c00SJeff Kirsher if (adapter->espi) {
767f7917c00SJeff Kirsher adapter->slow_intr_mask |= F_PL_INTR_ESPI;
768f7917c00SJeff Kirsher t1_espi_intr_enable(adapter->espi);
769f7917c00SJeff Kirsher }
770f7917c00SJeff Kirsher
771f7917c00SJeff Kirsher /* Enable MAC/PHY interrupts for each port. */
772f7917c00SJeff Kirsher for_each_port(adapter, i) {
773f7917c00SJeff Kirsher adapter->port[i].mac->ops->interrupt_enable(adapter->port[i].mac);
774f7917c00SJeff Kirsher adapter->port[i].phy->ops->interrupt_enable(adapter->port[i].phy);
775f7917c00SJeff Kirsher }
776f7917c00SJeff Kirsher
777f7917c00SJeff Kirsher /* Enable PCIX & external chip interrupts on ASIC boards. */
778f7917c00SJeff Kirsher if (t1_is_asic(adapter)) {
779f7917c00SJeff Kirsher u32 pl_intr = readl(adapter->regs + A_PL_ENABLE);
780f7917c00SJeff Kirsher
781f7917c00SJeff Kirsher /* PCI-X interrupts */
782f7917c00SJeff Kirsher pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_ENABLE,
783f7917c00SJeff Kirsher 0xffffffff);
784f7917c00SJeff Kirsher
785f7917c00SJeff Kirsher adapter->slow_intr_mask |= F_PL_INTR_EXT | F_PL_INTR_PCIX;
786f7917c00SJeff Kirsher pl_intr |= F_PL_INTR_EXT | F_PL_INTR_PCIX;
787f7917c00SJeff Kirsher writel(pl_intr, adapter->regs + A_PL_ENABLE);
788f7917c00SJeff Kirsher }
789f7917c00SJeff Kirsher }
790f7917c00SJeff Kirsher
791f7917c00SJeff Kirsher /* Disables all interrupts. */
t1_interrupts_disable(adapter_t * adapter)792f7917c00SJeff Kirsher void t1_interrupts_disable(adapter_t* adapter)
793f7917c00SJeff Kirsher {
794f7917c00SJeff Kirsher unsigned int i;
795f7917c00SJeff Kirsher
796f7917c00SJeff Kirsher t1_sge_intr_disable(adapter->sge);
797f7917c00SJeff Kirsher t1_tp_intr_disable(adapter->tp);
798f7917c00SJeff Kirsher if (adapter->espi)
799f7917c00SJeff Kirsher t1_espi_intr_disable(adapter->espi);
800f7917c00SJeff Kirsher
801f7917c00SJeff Kirsher /* Disable MAC/PHY interrupts for each port. */
802f7917c00SJeff Kirsher for_each_port(adapter, i) {
803f7917c00SJeff Kirsher adapter->port[i].mac->ops->interrupt_disable(adapter->port[i].mac);
804f7917c00SJeff Kirsher adapter->port[i].phy->ops->interrupt_disable(adapter->port[i].phy);
805f7917c00SJeff Kirsher }
806f7917c00SJeff Kirsher
807f7917c00SJeff Kirsher /* Disable PCIX & external chip interrupts. */
808f7917c00SJeff Kirsher if (t1_is_asic(adapter))
809f7917c00SJeff Kirsher writel(0, adapter->regs + A_PL_ENABLE);
810f7917c00SJeff Kirsher
811f7917c00SJeff Kirsher /* PCI-X interrupts */
812f7917c00SJeff Kirsher pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_ENABLE, 0);
813f7917c00SJeff Kirsher
814f7917c00SJeff Kirsher adapter->slow_intr_mask = 0;
815f7917c00SJeff Kirsher }
816f7917c00SJeff Kirsher
817f7917c00SJeff Kirsher /* Clears all interrupts */
t1_interrupts_clear(adapter_t * adapter)818f7917c00SJeff Kirsher void t1_interrupts_clear(adapter_t* adapter)
819f7917c00SJeff Kirsher {
820f7917c00SJeff Kirsher unsigned int i;
821f7917c00SJeff Kirsher
822f7917c00SJeff Kirsher t1_sge_intr_clear(adapter->sge);
823f7917c00SJeff Kirsher t1_tp_intr_clear(adapter->tp);
824f7917c00SJeff Kirsher if (adapter->espi)
825f7917c00SJeff Kirsher t1_espi_intr_clear(adapter->espi);
826f7917c00SJeff Kirsher
827f7917c00SJeff Kirsher /* Clear MAC/PHY interrupts for each port. */
828f7917c00SJeff Kirsher for_each_port(adapter, i) {
829f7917c00SJeff Kirsher adapter->port[i].mac->ops->interrupt_clear(adapter->port[i].mac);
830f7917c00SJeff Kirsher adapter->port[i].phy->ops->interrupt_clear(adapter->port[i].phy);
831f7917c00SJeff Kirsher }
832f7917c00SJeff Kirsher
833f7917c00SJeff Kirsher /* Enable interrupts for external devices. */
834f7917c00SJeff Kirsher if (t1_is_asic(adapter)) {
835f7917c00SJeff Kirsher u32 pl_intr = readl(adapter->regs + A_PL_CAUSE);
836f7917c00SJeff Kirsher
837f7917c00SJeff Kirsher writel(pl_intr | F_PL_INTR_EXT | F_PL_INTR_PCIX,
838f7917c00SJeff Kirsher adapter->regs + A_PL_CAUSE);
839f7917c00SJeff Kirsher }
840f7917c00SJeff Kirsher
841f7917c00SJeff Kirsher /* PCI-X interrupts */
842f7917c00SJeff Kirsher pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_CAUSE, 0xffffffff);
843f7917c00SJeff Kirsher }
844f7917c00SJeff Kirsher
845f7917c00SJeff Kirsher /*
846f7917c00SJeff Kirsher * Slow path interrupt handler for ASICs.
847f7917c00SJeff Kirsher */
asic_slow_intr(adapter_t * adapter)848fec7fa0aSSebastian Andrzej Siewior static irqreturn_t asic_slow_intr(adapter_t *adapter)
849f7917c00SJeff Kirsher {
850f7917c00SJeff Kirsher u32 cause = readl(adapter->regs + A_PL_CAUSE);
851fec7fa0aSSebastian Andrzej Siewior irqreturn_t ret = IRQ_HANDLED;
852f7917c00SJeff Kirsher
853f7917c00SJeff Kirsher cause &= adapter->slow_intr_mask;
854f7917c00SJeff Kirsher if (!cause)
855fec7fa0aSSebastian Andrzej Siewior return IRQ_NONE;
85682154580SSebastian Andrzej Siewior if (cause & F_PL_INTR_SGE_ERR) {
85782154580SSebastian Andrzej Siewior if (t1_sge_intr_error_handler(adapter->sge))
85882154580SSebastian Andrzej Siewior ret = IRQ_WAKE_THREAD;
85982154580SSebastian Andrzej Siewior }
860f7917c00SJeff Kirsher if (cause & F_PL_INTR_TP)
861f7917c00SJeff Kirsher t1_tp_intr_handler(adapter->tp);
862f7917c00SJeff Kirsher if (cause & F_PL_INTR_ESPI)
863f7917c00SJeff Kirsher t1_espi_intr_handler(adapter->espi);
86482154580SSebastian Andrzej Siewior if (cause & F_PL_INTR_PCIX) {
86582154580SSebastian Andrzej Siewior if (t1_pci_intr_handler(adapter))
86682154580SSebastian Andrzej Siewior ret = IRQ_WAKE_THREAD;
86782154580SSebastian Andrzej Siewior }
868fec7fa0aSSebastian Andrzej Siewior if (cause & F_PL_INTR_EXT) {
869fec7fa0aSSebastian Andrzej Siewior /* Wake the threaded interrupt to handle external interrupts as
870fec7fa0aSSebastian Andrzej Siewior * we require a process context. We disable EXT interrupts in
871fec7fa0aSSebastian Andrzej Siewior * the interim and let the thread reenable them when it's done.
872fec7fa0aSSebastian Andrzej Siewior */
873fec7fa0aSSebastian Andrzej Siewior adapter->pending_thread_intr |= F_PL_INTR_EXT;
874fec7fa0aSSebastian Andrzej Siewior adapter->slow_intr_mask &= ~F_PL_INTR_EXT;
875fec7fa0aSSebastian Andrzej Siewior writel(adapter->slow_intr_mask | F_PL_INTR_SGE_DATA,
876fec7fa0aSSebastian Andrzej Siewior adapter->regs + A_PL_ENABLE);
877fec7fa0aSSebastian Andrzej Siewior ret = IRQ_WAKE_THREAD;
878fec7fa0aSSebastian Andrzej Siewior }
879f7917c00SJeff Kirsher
880f7917c00SJeff Kirsher /* Clear the interrupts just processed. */
881f7917c00SJeff Kirsher writel(cause, adapter->regs + A_PL_CAUSE);
882f7917c00SJeff Kirsher readl(adapter->regs + A_PL_CAUSE); /* flush writes */
883fec7fa0aSSebastian Andrzej Siewior return ret;
884f7917c00SJeff Kirsher }
885f7917c00SJeff Kirsher
t1_slow_intr_handler(adapter_t * adapter)886fec7fa0aSSebastian Andrzej Siewior irqreturn_t t1_slow_intr_handler(adapter_t *adapter)
887f7917c00SJeff Kirsher {
888f7917c00SJeff Kirsher #ifdef CONFIG_CHELSIO_T1_1G
889f7917c00SJeff Kirsher if (!t1_is_asic(adapter))
890f7917c00SJeff Kirsher return fpga_slow_intr(adapter);
891f7917c00SJeff Kirsher #endif
892f7917c00SJeff Kirsher return asic_slow_intr(adapter);
893f7917c00SJeff Kirsher }
894f7917c00SJeff Kirsher
895f7917c00SJeff Kirsher /* Power sequencing is a work-around for Intel's XPAKs. */
power_sequence_xpak(adapter_t * adapter)896f7917c00SJeff Kirsher static void power_sequence_xpak(adapter_t* adapter)
897f7917c00SJeff Kirsher {
898f7917c00SJeff Kirsher u32 mod_detect;
899f7917c00SJeff Kirsher u32 gpo;
900f7917c00SJeff Kirsher
901f7917c00SJeff Kirsher /* Check for XPAK */
902f7917c00SJeff Kirsher t1_tpi_read(adapter, A_ELMER0_GPI_STAT, &mod_detect);
903f7917c00SJeff Kirsher if (!(ELMER0_GP_BIT5 & mod_detect)) {
904f7917c00SJeff Kirsher /* XPAK is present */
905f7917c00SJeff Kirsher t1_tpi_read(adapter, A_ELMER0_GPO, &gpo);
906f7917c00SJeff Kirsher gpo |= ELMER0_GP_BIT18;
907f7917c00SJeff Kirsher t1_tpi_write(adapter, A_ELMER0_GPO, gpo);
908f7917c00SJeff Kirsher }
909f7917c00SJeff Kirsher }
910f7917c00SJeff Kirsher
t1_get_board_rev(adapter_t * adapter,const struct board_info * bi,struct adapter_params * p)911ff76a3ccSBill Pemberton int t1_get_board_rev(adapter_t *adapter, const struct board_info *bi,
912f7917c00SJeff Kirsher struct adapter_params *p)
913f7917c00SJeff Kirsher {
914f7917c00SJeff Kirsher p->chip_version = bi->chip_term;
915f7917c00SJeff Kirsher p->is_asic = (p->chip_version != CHBT_TERM_FPGA);
916f7917c00SJeff Kirsher if (p->chip_version == CHBT_TERM_T1 ||
917f7917c00SJeff Kirsher p->chip_version == CHBT_TERM_T2 ||
918f7917c00SJeff Kirsher p->chip_version == CHBT_TERM_FPGA) {
919f7917c00SJeff Kirsher u32 val = readl(adapter->regs + A_TP_PC_CONFIG);
920f7917c00SJeff Kirsher
921f7917c00SJeff Kirsher val = G_TP_PC_REV(val);
922f7917c00SJeff Kirsher if (val == 2)
923f7917c00SJeff Kirsher p->chip_revision = TERM_T1B;
924f7917c00SJeff Kirsher else if (val == 3)
925f7917c00SJeff Kirsher p->chip_revision = TERM_T2;
926f7917c00SJeff Kirsher else
927f7917c00SJeff Kirsher return -1;
928f7917c00SJeff Kirsher } else
929f7917c00SJeff Kirsher return -1;
930f7917c00SJeff Kirsher return 0;
931f7917c00SJeff Kirsher }
932f7917c00SJeff Kirsher
933f7917c00SJeff Kirsher /*
934f7917c00SJeff Kirsher * Enable board components other than the Chelsio chip, such as external MAC
935f7917c00SJeff Kirsher * and PHY.
936f7917c00SJeff Kirsher */
board_init(adapter_t * adapter,const struct board_info * bi)937f7917c00SJeff Kirsher static int board_init(adapter_t *adapter, const struct board_info *bi)
938f7917c00SJeff Kirsher {
939f7917c00SJeff Kirsher switch (bi->board) {
940f7917c00SJeff Kirsher case CHBT_BOARD_8000:
941f7917c00SJeff Kirsher case CHBT_BOARD_N110:
942f7917c00SJeff Kirsher case CHBT_BOARD_N210:
943f7917c00SJeff Kirsher case CHBT_BOARD_CHT210:
944f7917c00SJeff Kirsher t1_tpi_par(adapter, 0xf);
945f7917c00SJeff Kirsher t1_tpi_write(adapter, A_ELMER0_GPO, 0x800);
946f7917c00SJeff Kirsher break;
947f7917c00SJeff Kirsher case CHBT_BOARD_CHT110:
948f7917c00SJeff Kirsher t1_tpi_par(adapter, 0xf);
949f7917c00SJeff Kirsher t1_tpi_write(adapter, A_ELMER0_GPO, 0x1800);
950f7917c00SJeff Kirsher
951f7917c00SJeff Kirsher /* TBD XXX Might not need. This fixes a problem
952f7917c00SJeff Kirsher * described in the Intel SR XPAK errata.
953f7917c00SJeff Kirsher */
954f7917c00SJeff Kirsher power_sequence_xpak(adapter);
955f7917c00SJeff Kirsher break;
956f7917c00SJeff Kirsher #ifdef CONFIG_CHELSIO_T1_1G
957f7917c00SJeff Kirsher case CHBT_BOARD_CHT204E:
958f7917c00SJeff Kirsher /* add config space write here */
959f7917c00SJeff Kirsher case CHBT_BOARD_CHT204:
960f7917c00SJeff Kirsher case CHBT_BOARD_CHT204V:
961f7917c00SJeff Kirsher case CHBT_BOARD_CHN204:
962f7917c00SJeff Kirsher t1_tpi_par(adapter, 0xf);
963f7917c00SJeff Kirsher t1_tpi_write(adapter, A_ELMER0_GPO, 0x804);
964f7917c00SJeff Kirsher break;
965f7917c00SJeff Kirsher case CHBT_BOARD_CHT101:
966f7917c00SJeff Kirsher case CHBT_BOARD_7500:
967f7917c00SJeff Kirsher t1_tpi_par(adapter, 0xf);
968f7917c00SJeff Kirsher t1_tpi_write(adapter, A_ELMER0_GPO, 0x1804);
969f7917c00SJeff Kirsher break;
970f7917c00SJeff Kirsher #endif
971f7917c00SJeff Kirsher }
972f7917c00SJeff Kirsher return 0;
973f7917c00SJeff Kirsher }
974f7917c00SJeff Kirsher
975f7917c00SJeff Kirsher /*
976f7917c00SJeff Kirsher * Initialize and configure the Terminator HW modules. Note that external
977f7917c00SJeff Kirsher * MAC and PHYs are initialized separately.
978f7917c00SJeff Kirsher */
t1_init_hw_modules(adapter_t * adapter)979f7917c00SJeff Kirsher int t1_init_hw_modules(adapter_t *adapter)
980f7917c00SJeff Kirsher {
981f7917c00SJeff Kirsher int err = -EIO;
982f7917c00SJeff Kirsher const struct board_info *bi = board_info(adapter);
983f7917c00SJeff Kirsher
984f7917c00SJeff Kirsher if (!bi->clock_mc4) {
985f7917c00SJeff Kirsher u32 val = readl(adapter->regs + A_MC4_CFG);
986f7917c00SJeff Kirsher
987f7917c00SJeff Kirsher writel(val | F_READY | F_MC4_SLOW, adapter->regs + A_MC4_CFG);
988f7917c00SJeff Kirsher writel(F_M_BUS_ENABLE | F_TCAM_RESET,
989f7917c00SJeff Kirsher adapter->regs + A_MC5_CONFIG);
990f7917c00SJeff Kirsher }
991f7917c00SJeff Kirsher
992f7917c00SJeff Kirsher if (adapter->espi && t1_espi_init(adapter->espi, bi->chip_mac,
993f7917c00SJeff Kirsher bi->espi_nports))
994f7917c00SJeff Kirsher goto out_err;
995f7917c00SJeff Kirsher
996f7917c00SJeff Kirsher if (t1_tp_reset(adapter->tp, &adapter->params.tp, bi->clock_core))
997f7917c00SJeff Kirsher goto out_err;
998f7917c00SJeff Kirsher
999f7917c00SJeff Kirsher err = t1_sge_configure(adapter->sge, &adapter->params.sge);
1000f7917c00SJeff Kirsher if (err)
1001f7917c00SJeff Kirsher goto out_err;
1002f7917c00SJeff Kirsher
1003f7917c00SJeff Kirsher err = 0;
1004f7917c00SJeff Kirsher out_err:
1005f7917c00SJeff Kirsher return err;
1006f7917c00SJeff Kirsher }
1007f7917c00SJeff Kirsher
1008f7917c00SJeff Kirsher /*
1009f7917c00SJeff Kirsher * Determine a card's PCI mode.
1010f7917c00SJeff Kirsher */
get_pci_mode(adapter_t * adapter,struct chelsio_pci_params * p)1011ff76a3ccSBill Pemberton static void get_pci_mode(adapter_t *adapter, struct chelsio_pci_params *p)
1012f7917c00SJeff Kirsher {
1013f7917c00SJeff Kirsher static const unsigned short speed_map[] = { 33, 66, 100, 133 };
1014f7917c00SJeff Kirsher u32 pci_mode;
1015f7917c00SJeff Kirsher
1016f7917c00SJeff Kirsher pci_read_config_dword(adapter->pdev, A_PCICFG_MODE, &pci_mode);
1017f7917c00SJeff Kirsher p->speed = speed_map[G_PCI_MODE_CLK(pci_mode)];
1018f7917c00SJeff Kirsher p->width = (pci_mode & F_PCI_MODE_64BIT) ? 64 : 32;
1019f7917c00SJeff Kirsher p->is_pcix = (pci_mode & F_PCI_MODE_PCIX) != 0;
1020f7917c00SJeff Kirsher }
1021f7917c00SJeff Kirsher
1022f7917c00SJeff Kirsher /*
1023f7917c00SJeff Kirsher * Release the structures holding the SW per-Terminator-HW-module state.
1024f7917c00SJeff Kirsher */
t1_free_sw_modules(adapter_t * adapter)1025f7917c00SJeff Kirsher void t1_free_sw_modules(adapter_t *adapter)
1026f7917c00SJeff Kirsher {
1027f7917c00SJeff Kirsher unsigned int i;
1028f7917c00SJeff Kirsher
1029f7917c00SJeff Kirsher for_each_port(adapter, i) {
1030f7917c00SJeff Kirsher struct cmac *mac = adapter->port[i].mac;
1031f7917c00SJeff Kirsher struct cphy *phy = adapter->port[i].phy;
1032f7917c00SJeff Kirsher
1033f7917c00SJeff Kirsher if (mac)
1034f7917c00SJeff Kirsher mac->ops->destroy(mac);
1035f7917c00SJeff Kirsher if (phy)
1036f7917c00SJeff Kirsher phy->ops->destroy(phy);
1037f7917c00SJeff Kirsher }
1038f7917c00SJeff Kirsher
1039f7917c00SJeff Kirsher if (adapter->sge)
1040f7917c00SJeff Kirsher t1_sge_destroy(adapter->sge);
1041f7917c00SJeff Kirsher if (adapter->tp)
1042f7917c00SJeff Kirsher t1_tp_destroy(adapter->tp);
1043f7917c00SJeff Kirsher if (adapter->espi)
1044f7917c00SJeff Kirsher t1_espi_destroy(adapter->espi);
1045f7917c00SJeff Kirsher }
1046f7917c00SJeff Kirsher
init_link_config(struct link_config * lc,const struct board_info * bi)1047ff76a3ccSBill Pemberton static void init_link_config(struct link_config *lc,
1048f7917c00SJeff Kirsher const struct board_info *bi)
1049f7917c00SJeff Kirsher {
1050f7917c00SJeff Kirsher lc->supported = bi->caps;
1051f7917c00SJeff Kirsher lc->requested_speed = lc->speed = SPEED_INVALID;
1052f7917c00SJeff Kirsher lc->requested_duplex = lc->duplex = DUPLEX_INVALID;
1053f7917c00SJeff Kirsher lc->requested_fc = lc->fc = PAUSE_RX | PAUSE_TX;
1054f7917c00SJeff Kirsher if (lc->supported & SUPPORTED_Autoneg) {
1055f7917c00SJeff Kirsher lc->advertising = lc->supported;
1056f7917c00SJeff Kirsher lc->autoneg = AUTONEG_ENABLE;
1057f7917c00SJeff Kirsher lc->requested_fc |= PAUSE_AUTONEG;
1058f7917c00SJeff Kirsher } else {
1059f7917c00SJeff Kirsher lc->advertising = 0;
1060f7917c00SJeff Kirsher lc->autoneg = AUTONEG_DISABLE;
1061f7917c00SJeff Kirsher }
1062f7917c00SJeff Kirsher }
1063f7917c00SJeff Kirsher
1064f7917c00SJeff Kirsher /*
1065f7917c00SJeff Kirsher * Allocate and initialize the data structures that hold the SW state of
1066f7917c00SJeff Kirsher * the Terminator HW modules.
1067f7917c00SJeff Kirsher */
t1_init_sw_modules(adapter_t * adapter,const struct board_info * bi)10681dd06ae8SGreg Kroah-Hartman int t1_init_sw_modules(adapter_t *adapter, const struct board_info *bi)
1069f7917c00SJeff Kirsher {
1070f7917c00SJeff Kirsher unsigned int i;
1071f7917c00SJeff Kirsher
1072f7917c00SJeff Kirsher adapter->params.brd_info = bi;
1073f7917c00SJeff Kirsher adapter->params.nports = bi->port_number;
1074f7917c00SJeff Kirsher adapter->params.stats_update_period = bi->gmac->stats_update_period;
1075f7917c00SJeff Kirsher
1076f7917c00SJeff Kirsher adapter->sge = t1_sge_create(adapter, &adapter->params.sge);
1077f7917c00SJeff Kirsher if (!adapter->sge) {
1078f7917c00SJeff Kirsher pr_err("%s: SGE initialization failed\n",
1079f7917c00SJeff Kirsher adapter->name);
1080f7917c00SJeff Kirsher goto error;
1081f7917c00SJeff Kirsher }
1082f7917c00SJeff Kirsher
1083f7917c00SJeff Kirsher if (bi->espi_nports && !(adapter->espi = t1_espi_create(adapter))) {
1084f7917c00SJeff Kirsher pr_err("%s: ESPI initialization failed\n",
1085f7917c00SJeff Kirsher adapter->name);
1086f7917c00SJeff Kirsher goto error;
1087f7917c00SJeff Kirsher }
1088f7917c00SJeff Kirsher
1089f7917c00SJeff Kirsher adapter->tp = t1_tp_create(adapter, &adapter->params.tp);
1090f7917c00SJeff Kirsher if (!adapter->tp) {
1091f7917c00SJeff Kirsher pr_err("%s: TP initialization failed\n",
1092f7917c00SJeff Kirsher adapter->name);
1093f7917c00SJeff Kirsher goto error;
1094f7917c00SJeff Kirsher }
1095f7917c00SJeff Kirsher
1096f7917c00SJeff Kirsher board_init(adapter, bi);
1097f7917c00SJeff Kirsher bi->mdio_ops->init(adapter, bi);
1098f7917c00SJeff Kirsher if (bi->gphy->reset)
1099f7917c00SJeff Kirsher bi->gphy->reset(adapter);
1100f7917c00SJeff Kirsher if (bi->gmac->reset)
1101f7917c00SJeff Kirsher bi->gmac->reset(adapter);
1102f7917c00SJeff Kirsher
1103f7917c00SJeff Kirsher for_each_port(adapter, i) {
1104f7917c00SJeff Kirsher u8 hw_addr[6];
1105f7917c00SJeff Kirsher struct cmac *mac;
1106f7917c00SJeff Kirsher int phy_addr = bi->mdio_phybaseaddr + i;
1107f7917c00SJeff Kirsher
1108f7917c00SJeff Kirsher adapter->port[i].phy = bi->gphy->create(adapter->port[i].dev,
1109f7917c00SJeff Kirsher phy_addr, bi->mdio_ops);
1110f7917c00SJeff Kirsher if (!adapter->port[i].phy) {
1111f7917c00SJeff Kirsher pr_err("%s: PHY %d initialization failed\n",
1112f7917c00SJeff Kirsher adapter->name, i);
1113f7917c00SJeff Kirsher goto error;
1114f7917c00SJeff Kirsher }
1115f7917c00SJeff Kirsher
1116f7917c00SJeff Kirsher adapter->port[i].mac = mac = bi->gmac->create(adapter, i);
1117f7917c00SJeff Kirsher if (!mac) {
1118f7917c00SJeff Kirsher pr_err("%s: MAC %d initialization failed\n",
1119f7917c00SJeff Kirsher adapter->name, i);
1120f7917c00SJeff Kirsher goto error;
1121f7917c00SJeff Kirsher }
1122f7917c00SJeff Kirsher
1123f7917c00SJeff Kirsher /*
1124f7917c00SJeff Kirsher * Get the port's MAC addresses either from the EEPROM if one
1125f7917c00SJeff Kirsher * exists or the one hardcoded in the MAC.
1126f7917c00SJeff Kirsher */
1127f7917c00SJeff Kirsher if (!t1_is_asic(adapter) || bi->chip_mac == CHBT_MAC_DUMMY)
1128f7917c00SJeff Kirsher mac->ops->macaddress_get(mac, hw_addr);
1129f7917c00SJeff Kirsher else if (vpd_macaddress_get(adapter, i, hw_addr)) {
1130f7917c00SJeff Kirsher pr_err("%s: could not read MAC address from VPD ROM\n",
1131f7917c00SJeff Kirsher adapter->port[i].dev->name);
1132f7917c00SJeff Kirsher goto error;
1133f7917c00SJeff Kirsher }
113447d71f45SJakub Kicinski eth_hw_addr_set(adapter->port[i].dev, hw_addr);
1135f7917c00SJeff Kirsher init_link_config(&adapter->port[i].link_config, bi);
1136f7917c00SJeff Kirsher }
1137f7917c00SJeff Kirsher
1138f7917c00SJeff Kirsher get_pci_mode(adapter, &adapter->params.pci);
1139f7917c00SJeff Kirsher t1_interrupts_clear(adapter);
1140f7917c00SJeff Kirsher return 0;
1141f7917c00SJeff Kirsher
1142f7917c00SJeff Kirsher error:
1143f7917c00SJeff Kirsher t1_free_sw_modules(adapter);
1144f7917c00SJeff Kirsher return -1;
1145f7917c00SJeff Kirsher }
1146