1 /*****************************************************************************
5 * $Date: 2005/06/22 01:08:36 $ *
7 * Various subroutines (intr,pio,etc.) used by Chelsio 10G Ethernet driver. *
8 * part of the Chelsio 10Gb Ethernet Driver. *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License, version 2, as *
12 * published by the Free Software Foundation. *
14 * You should have received a copy of the GNU General Public License along *
15 * with this program; if not, write to the Free Software Foundation, Inc., *
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED *
19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF *
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *
22 * http://www.chelsio.com *
24 * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. *
25 * All rights reserved. *
27 * Maintainers: maintainers@chelsio.com *
29 * Authors: Dimitrios Michailidis <dm@chelsio.com> *
30 * Tina Yang <tainay@chelsio.com> *
31 * Felix Marti <felix@chelsio.com> *
32 * Scott Bardone <sbardone@chelsio.com> *
33 * Kurt Ottaway <kottaway@chelsio.com> *
34 * Frank DiMambro <frank@chelsio.com> *
38 ****************************************************************************/
50 * t1_wait_op_done - wait until an operation is completed
51 * @adapter: the adapter performing the operation
52 * @reg: the register to check for completion
53 * @mask: a single-bit field within @reg that indicates completion
54 * @polarity: the value of the field when the operation is completed
55 * @attempts: number of check iterations
56 * @delay: delay in usecs between iterations
58 * Wait until an operation is completed by checking a bit in a register
59 * up to @attempts times. Returns %0 if the operation completes and %1
62 static int t1_wait_op_done(adapter_t
*adapter
, int reg
, u32 mask
, int polarity
,
63 int attempts
, int delay
)
66 u32 val
= readl(adapter
->regs
+ reg
) & mask
;
68 if (!!val
== polarity
)
77 #define TPI_ATTEMPTS 50
80 * Write a register over the TPI interface (unlocked and locked versions).
82 int __t1_tpi_write(adapter_t
*adapter
, u32 addr
, u32 value
)
86 writel(addr
, adapter
->regs
+ A_TPI_ADDR
);
87 writel(value
, adapter
->regs
+ A_TPI_WR_DATA
);
88 writel(F_TPIWR
, adapter
->regs
+ A_TPI_CSR
);
90 tpi_busy
= t1_wait_op_done(adapter
, A_TPI_CSR
, F_TPIRDY
, 1,
93 CH_ALERT("%s: TPI write to 0x%x failed\n",
98 int t1_tpi_write(adapter_t
*adapter
, u32 addr
, u32 value
)
102 spin_lock(&adapter
->tpi_lock
);
103 ret
= __t1_tpi_write(adapter
, addr
, value
);
104 spin_unlock(&adapter
->tpi_lock
);
109 * Read a register over the TPI interface (unlocked and locked versions).
111 int __t1_tpi_read(adapter_t
*adapter
, u32 addr
, u32
*valp
)
115 writel(addr
, adapter
->regs
+ A_TPI_ADDR
);
116 writel(0, adapter
->regs
+ A_TPI_CSR
);
118 tpi_busy
= t1_wait_op_done(adapter
, A_TPI_CSR
, F_TPIRDY
, 1,
121 CH_ALERT("%s: TPI read from 0x%x failed\n",
122 adapter
->name
, addr
);
124 *valp
= readl(adapter
->regs
+ A_TPI_RD_DATA
);
128 int t1_tpi_read(adapter_t
*adapter
, u32 addr
, u32
*valp
)
132 spin_lock(&adapter
->tpi_lock
);
133 ret
= __t1_tpi_read(adapter
, addr
, valp
);
134 spin_unlock(&adapter
->tpi_lock
);
139 * Set a TPI parameter.
141 static void t1_tpi_par(adapter_t
*adapter
, u32 value
)
143 writel(V_TPIPAR(value
), adapter
->regs
+ A_TPI_PAR
);
147 * Called when a port's link settings change to propagate the new values to the
148 * associated PHY and MAC. After performing the common tasks it invokes an
149 * OS-specific handler.
151 void t1_link_changed(adapter_t
*adapter
, int port_id
)
153 int link_ok
, speed
, duplex
, fc
;
154 struct cphy
*phy
= adapter
->port
[port_id
].phy
;
155 struct link_config
*lc
= &adapter
->port
[port_id
].link_config
;
157 phy
->ops
->get_link_status(phy
, &link_ok
, &speed
, &duplex
, &fc
);
159 lc
->speed
= speed
< 0 ? SPEED_INVALID
: speed
;
160 lc
->duplex
= duplex
< 0 ? DUPLEX_INVALID
: duplex
;
161 if (!(lc
->requested_fc
& PAUSE_AUTONEG
))
162 fc
= lc
->requested_fc
& (PAUSE_RX
| PAUSE_TX
);
164 if (link_ok
&& speed
>= 0 && lc
->autoneg
== AUTONEG_ENABLE
) {
165 /* Set MAC speed, duplex, and flow control to match PHY. */
166 struct cmac
*mac
= adapter
->port
[port_id
].mac
;
168 mac
->ops
->set_speed_duplex_fc(mac
, speed
, duplex
, fc
);
169 lc
->fc
= (unsigned char)fc
;
171 t1_link_negotiated(adapter
, port_id
, link_ok
, speed
, duplex
, fc
);
174 static int t1_pci_intr_handler(adapter_t
*adapter
)
178 pci_read_config_dword(adapter
->pdev
, A_PCICFG_INTR_CAUSE
, &pcix_cause
);
181 pci_write_config_dword(adapter
->pdev
, A_PCICFG_INTR_CAUSE
,
183 t1_fatal_err(adapter
); /* PCI errors are fatal */
188 #ifdef CONFIG_CHELSIO_T1_COUGAR
191 #ifdef CONFIG_CHELSIO_T1_1G
192 #include "fpga_defs.h"
195 * PHY interrupt handler for FPGA boards.
197 static int fpga_phy_intr_handler(adapter_t
*adapter
)
200 u32 cause
= readl(adapter
->regs
+ FPGA_GMAC_ADDR_INTERRUPT_CAUSE
);
202 for_each_port(adapter
, p
)
203 if (cause
& (1 << p
)) {
204 struct cphy
*phy
= adapter
->port
[p
].phy
;
205 int phy_cause
= phy
->ops
->interrupt_handler(phy
);
207 if (phy_cause
& cphy_cause_link_change
)
208 t1_link_changed(adapter
, p
);
210 writel(cause
, adapter
->regs
+ FPGA_GMAC_ADDR_INTERRUPT_CAUSE
);
215 * Slow path interrupt handler for FPGAs.
217 static int fpga_slow_intr(adapter_t
*adapter
)
219 u32 cause
= readl(adapter
->regs
+ A_PL_CAUSE
);
221 cause
&= ~F_PL_INTR_SGE_DATA
;
222 if (cause
& F_PL_INTR_SGE_ERR
)
223 t1_sge_intr_error_handler(adapter
->sge
);
225 if (cause
& FPGA_PCIX_INTERRUPT_GMAC
)
226 fpga_phy_intr_handler(adapter
);
228 if (cause
& FPGA_PCIX_INTERRUPT_TP
) {
230 * FPGA doesn't support MC4 interrupts and it requires
231 * this odd layer of indirection for MC5.
233 u32 tp_cause
= readl(adapter
->regs
+ FPGA_TP_ADDR_INTERRUPT_CAUSE
);
235 /* Clear TP interrupt */
236 writel(tp_cause
, adapter
->regs
+ FPGA_TP_ADDR_INTERRUPT_CAUSE
);
238 if (cause
& FPGA_PCIX_INTERRUPT_PCIX
)
239 t1_pci_intr_handler(adapter
);
241 /* Clear the interrupts just processed. */
243 writel(cause
, adapter
->regs
+ A_PL_CAUSE
);
250 * Wait until Elmer's MI1 interface is ready for new operations.
252 static int mi1_wait_until_ready(adapter_t
*adapter
, int mi1_reg
)
254 int attempts
= 100, busy
;
259 __t1_tpi_read(adapter
, mi1_reg
, &val
);
260 busy
= val
& F_MI1_OP_BUSY
;
263 } while (busy
&& --attempts
);
265 CH_ALERT("%s: MDIO operation timed out\n", adapter
->name
);
270 * MI1 MDIO initialization.
272 static void mi1_mdio_init(adapter_t
*adapter
, const struct board_info
*bi
)
274 u32 clkdiv
= bi
->clock_elmer0
/ (2 * bi
->mdio_mdc
) - 1;
275 u32 val
= F_MI1_PREAMBLE_ENABLE
| V_MI1_MDI_INVERT(bi
->mdio_mdiinv
) |
276 V_MI1_MDI_ENABLE(bi
->mdio_mdien
) | V_MI1_CLK_DIV(clkdiv
);
278 if (!(bi
->caps
& SUPPORTED_10000baseT_Full
))
280 t1_tpi_write(adapter
, A_ELMER0_PORT0_MI1_CFG
, val
);
283 #if defined(CONFIG_CHELSIO_T1_1G) || defined(CONFIG_CHELSIO_T1_COUGAR)
285 * Elmer MI1 MDIO read/write operations.
287 static int mi1_mdio_read(adapter_t
*adapter
, int phy_addr
, int mmd_addr
,
288 int reg_addr
, unsigned int *valp
)
290 u32 addr
= V_MI1_REG_ADDR(reg_addr
) | V_MI1_PHY_ADDR(phy_addr
);
295 spin_lock(&adapter
->tpi_lock
);
296 __t1_tpi_write(adapter
, A_ELMER0_PORT0_MI1_ADDR
, addr
);
297 __t1_tpi_write(adapter
,
298 A_ELMER0_PORT0_MI1_OP
, MI1_OP_DIRECT_READ
);
299 mi1_wait_until_ready(adapter
, A_ELMER0_PORT0_MI1_OP
);
300 __t1_tpi_read(adapter
, A_ELMER0_PORT0_MI1_DATA
, valp
);
301 spin_unlock(&adapter
->tpi_lock
);
305 static int mi1_mdio_write(adapter_t
*adapter
, int phy_addr
, int mmd_addr
,
306 int reg_addr
, unsigned int val
)
308 u32 addr
= V_MI1_REG_ADDR(reg_addr
) | V_MI1_PHY_ADDR(phy_addr
);
313 spin_lock(&adapter
->tpi_lock
);
314 __t1_tpi_write(adapter
, A_ELMER0_PORT0_MI1_ADDR
, addr
);
315 __t1_tpi_write(adapter
, A_ELMER0_PORT0_MI1_DATA
, val
);
316 __t1_tpi_write(adapter
,
317 A_ELMER0_PORT0_MI1_OP
, MI1_OP_DIRECT_WRITE
);
318 mi1_wait_until_ready(adapter
, A_ELMER0_PORT0_MI1_OP
);
319 spin_unlock(&adapter
->tpi_lock
);
323 #if defined(CONFIG_CHELSIO_T1_1G) || defined(CONFIG_CHELSIO_T1_COUGAR)
324 static const struct mdio_ops mi1_mdio_ops
= {
325 .init
= mi1_mdio_init
,
326 .read
= mi1_mdio_read
,
327 .write
= mi1_mdio_write
333 static int mi1_mdio_ext_read(adapter_t
*adapter
, int phy_addr
, int mmd_addr
,
334 int reg_addr
, unsigned int *valp
)
336 u32 addr
= V_MI1_REG_ADDR(mmd_addr
) | V_MI1_PHY_ADDR(phy_addr
);
338 spin_lock(&adapter
->tpi_lock
);
340 /* Write the address we want. */
341 __t1_tpi_write(adapter
, A_ELMER0_PORT0_MI1_ADDR
, addr
);
342 __t1_tpi_write(adapter
, A_ELMER0_PORT0_MI1_DATA
, reg_addr
);
343 __t1_tpi_write(adapter
, A_ELMER0_PORT0_MI1_OP
,
344 MI1_OP_INDIRECT_ADDRESS
);
345 mi1_wait_until_ready(adapter
, A_ELMER0_PORT0_MI1_OP
);
347 /* Write the operation we want. */
348 __t1_tpi_write(adapter
,
349 A_ELMER0_PORT0_MI1_OP
, MI1_OP_INDIRECT_READ
);
350 mi1_wait_until_ready(adapter
, A_ELMER0_PORT0_MI1_OP
);
353 __t1_tpi_read(adapter
, A_ELMER0_PORT0_MI1_DATA
, valp
);
354 spin_unlock(&adapter
->tpi_lock
);
358 static int mi1_mdio_ext_write(adapter_t
*adapter
, int phy_addr
, int mmd_addr
,
359 int reg_addr
, unsigned int val
)
361 u32 addr
= V_MI1_REG_ADDR(mmd_addr
) | V_MI1_PHY_ADDR(phy_addr
);
363 spin_lock(&adapter
->tpi_lock
);
365 /* Write the address we want. */
366 __t1_tpi_write(adapter
, A_ELMER0_PORT0_MI1_ADDR
, addr
);
367 __t1_tpi_write(adapter
, A_ELMER0_PORT0_MI1_DATA
, reg_addr
);
368 __t1_tpi_write(adapter
, A_ELMER0_PORT0_MI1_OP
,
369 MI1_OP_INDIRECT_ADDRESS
);
370 mi1_wait_until_ready(adapter
, A_ELMER0_PORT0_MI1_OP
);
372 /* Write the data. */
373 __t1_tpi_write(adapter
, A_ELMER0_PORT0_MI1_DATA
, val
);
374 __t1_tpi_write(adapter
, A_ELMER0_PORT0_MI1_OP
, MI1_OP_INDIRECT_WRITE
);
375 mi1_wait_until_ready(adapter
, A_ELMER0_PORT0_MI1_OP
);
376 spin_unlock(&adapter
->tpi_lock
);
380 static const struct mdio_ops mi1_mdio_ext_ops
= {
381 .init
= mi1_mdio_init
,
382 .read
= mi1_mdio_ext_read
,
383 .write
= mi1_mdio_ext_write
395 static const struct board_info t1_board
[] = {
397 .board
= CHBT_BOARD_CHT110
,
399 .caps
= SUPPORTED_10000baseT_Full
,
400 .chip_term
= CHBT_TERM_T1
,
401 .chip_mac
= CHBT_MAC_PM3393
,
402 .chip_phy
= CHBT_PHY_MY3126
,
403 .clock_core
= 125000000,
404 .clock_mc3
= 150000000,
405 .clock_mc4
= 125000000,
411 .mdio_phybaseaddr
= 1,
412 .gmac
= &t1_pm3393_ops
,
413 .gphy
= &t1_my3126_ops
,
414 .mdio_ops
= &mi1_mdio_ext_ops
,
415 .desc
= "Chelsio T110 1x10GBase-CX4 TOE",
419 .board
= CHBT_BOARD_N110
,
421 .caps
= SUPPORTED_10000baseT_Full
| SUPPORTED_FIBRE
,
422 .chip_term
= CHBT_TERM_T1
,
423 .chip_mac
= CHBT_MAC_PM3393
,
424 .chip_phy
= CHBT_PHY_88X2010
,
425 .clock_core
= 125000000,
431 .mdio_phybaseaddr
= 0,
432 .gmac
= &t1_pm3393_ops
,
433 .gphy
= &t1_mv88x201x_ops
,
434 .mdio_ops
= &mi1_mdio_ext_ops
,
435 .desc
= "Chelsio N110 1x10GBaseX NIC",
439 .board
= CHBT_BOARD_N210
,
441 .caps
= SUPPORTED_10000baseT_Full
| SUPPORTED_FIBRE
,
442 .chip_term
= CHBT_TERM_T2
,
443 .chip_mac
= CHBT_MAC_PM3393
,
444 .chip_phy
= CHBT_PHY_88X2010
,
445 .clock_core
= 125000000,
451 .mdio_phybaseaddr
= 0,
452 .gmac
= &t1_pm3393_ops
,
453 .gphy
= &t1_mv88x201x_ops
,
454 .mdio_ops
= &mi1_mdio_ext_ops
,
455 .desc
= "Chelsio N210 1x10GBaseX NIC",
459 .board
= CHBT_BOARD_CHT210
,
461 .caps
= SUPPORTED_10000baseT_Full
,
462 .chip_term
= CHBT_TERM_T2
,
463 .chip_mac
= CHBT_MAC_PM3393
,
464 .chip_phy
= CHBT_PHY_88X2010
,
465 .clock_core
= 125000000,
466 .clock_mc3
= 133000000,
467 .clock_mc4
= 125000000,
473 .mdio_phybaseaddr
= 0,
474 .gmac
= &t1_pm3393_ops
,
475 .gphy
= &t1_mv88x201x_ops
,
476 .mdio_ops
= &mi1_mdio_ext_ops
,
477 .desc
= "Chelsio T210 1x10GBaseX TOE",
481 .board
= CHBT_BOARD_CHT210
,
483 .caps
= SUPPORTED_10000baseT_Full
,
484 .chip_term
= CHBT_TERM_T2
,
485 .chip_mac
= CHBT_MAC_PM3393
,
486 .chip_phy
= CHBT_PHY_MY3126
,
487 .clock_core
= 125000000,
488 .clock_mc3
= 133000000,
489 .clock_mc4
= 125000000,
495 .mdio_phybaseaddr
= 1,
496 .gmac
= &t1_pm3393_ops
,
497 .gphy
= &t1_my3126_ops
,
498 .mdio_ops
= &mi1_mdio_ext_ops
,
499 .desc
= "Chelsio T210 1x10GBase-CX4 TOE",
502 #ifdef CONFIG_CHELSIO_T1_1G
504 .board
= CHBT_BOARD_CHN204
,
506 .caps
= SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
507 | SUPPORTED_100baseT_Half
| SUPPORTED_100baseT_Full
508 | SUPPORTED_1000baseT_Full
| SUPPORTED_Autoneg
|
509 SUPPORTED_PAUSE
| SUPPORTED_TP
,
510 .chip_term
= CHBT_TERM_T2
,
511 .chip_mac
= CHBT_MAC_VSC7321
,
512 .chip_phy
= CHBT_PHY_88E1111
,
513 .clock_core
= 100000000,
519 .mdio_phybaseaddr
= 4,
520 .gmac
= &t1_vsc7326_ops
,
521 .gphy
= &t1_mv88e1xxx_ops
,
522 .mdio_ops
= &mi1_mdio_ops
,
523 .desc
= "Chelsio N204 4x100/1000BaseT NIC",
529 struct pci_device_id t1_pci_tbl
[] = {
530 CH_DEVICE(8, 0, CH_BRD_T110_1CU
),
531 CH_DEVICE(8, 1, CH_BRD_T110_1CU
),
532 CH_DEVICE(7, 0, CH_BRD_N110_1F
),
533 CH_DEVICE(10, 1, CH_BRD_N210_1F
),
534 CH_DEVICE(11, 1, CH_BRD_T210_1F
),
535 CH_DEVICE(14, 1, CH_BRD_T210_1CU
),
536 CH_DEVICE(16, 1, CH_BRD_N204_4CU
),
540 MODULE_DEVICE_TABLE(pci
, t1_pci_tbl
);
543 * Return the board_info structure with a given index. Out-of-range indices
546 const struct board_info
*t1_get_board_info(unsigned int board_id
)
548 return board_id
< ARRAY_SIZE(t1_board
) ? &t1_board
[board_id
] : NULL
;
551 struct chelsio_vpd_t
{
553 u8 serial_number
[16];
554 u8 mac_base_address
[6];
555 u8 pad
[2]; /* make multiple-of-4 size requirement explicit */
558 #define EEPROMSIZE (8 * 1024)
559 #define EEPROM_MAX_POLL 4
562 * Read SEEPROM. A zero is written to the flag register when the addres is
563 * written to the Control register. The hardware device will set the flag to a
564 * one when 4B have been transferred to the Data register.
566 int t1_seeprom_read(adapter_t
*adapter
, u32 addr
, u32
*data
)
568 int i
= EEPROM_MAX_POLL
;
571 if (addr
>= EEPROMSIZE
|| (addr
& 3))
574 pci_write_config_word(adapter
->pdev
, A_PCICFG_VPD_ADDR
, (u16
)addr
);
577 pci_read_config_word(adapter
->pdev
, A_PCICFG_VPD_ADDR
, &val
);
578 } while (!(val
& F_VPD_OP_FLAG
) && --i
);
580 if (!(val
& F_VPD_OP_FLAG
)) {
581 CH_ERR("%s: reading EEPROM address 0x%x failed\n",
582 adapter
->name
, addr
);
585 pci_read_config_dword(adapter
->pdev
, A_PCICFG_VPD_DATA
, data
);
586 *data
= le32_to_cpu(*data
);
590 static int t1_eeprom_vpd_get(adapter_t
*adapter
, struct chelsio_vpd_t
*vpd
)
594 for (addr
= 0; !ret
&& addr
< sizeof(*vpd
); addr
+= sizeof(u32
))
595 ret
= t1_seeprom_read(adapter
, addr
,
596 (u32
*)((u8
*)vpd
+ addr
));
602 * Read a port's MAC address from the VPD ROM.
604 static int vpd_macaddress_get(adapter_t
*adapter
, int index
, u8 mac_addr
[])
606 struct chelsio_vpd_t vpd
;
608 if (t1_eeprom_vpd_get(adapter
, &vpd
))
610 memcpy(mac_addr
, vpd
.mac_base_address
, 5);
611 mac_addr
[5] = vpd
.mac_base_address
[5] + index
;
616 * Set up the MAC/PHY according to the requested link settings.
618 * If the PHY can auto-negotiate first decide what to advertise, then
619 * enable/disable auto-negotiation as desired and reset.
621 * If the PHY does not auto-negotiate we just reset it.
623 * If auto-negotiation is off set the MAC to the proper speed/duplex/FC,
624 * otherwise do it later based on the outcome of auto-negotiation.
626 int t1_link_start(struct cphy
*phy
, struct cmac
*mac
, struct link_config
*lc
)
628 unsigned int fc
= lc
->requested_fc
& (PAUSE_RX
| PAUSE_TX
);
630 if (lc
->supported
& SUPPORTED_Autoneg
) {
631 lc
->advertising
&= ~(ADVERTISED_ASYM_PAUSE
| ADVERTISED_PAUSE
);
633 if (fc
== ((PAUSE_RX
| PAUSE_TX
) &
634 (mac
->adapter
->params
.nports
< 2)))
635 lc
->advertising
|= ADVERTISED_PAUSE
;
637 lc
->advertising
|= ADVERTISED_ASYM_PAUSE
;
639 lc
->advertising
|= ADVERTISED_PAUSE
;
642 phy
->ops
->advertise(phy
, lc
->advertising
);
644 if (lc
->autoneg
== AUTONEG_DISABLE
) {
645 lc
->speed
= lc
->requested_speed
;
646 lc
->duplex
= lc
->requested_duplex
;
647 lc
->fc
= (unsigned char)fc
;
648 mac
->ops
->set_speed_duplex_fc(mac
, lc
->speed
,
650 /* Also disables autoneg */
651 phy
->state
= PHY_AUTONEG_RDY
;
652 phy
->ops
->set_speed_duplex(phy
, lc
->speed
, lc
->duplex
);
653 phy
->ops
->reset(phy
, 0);
655 phy
->state
= PHY_AUTONEG_EN
;
656 phy
->ops
->autoneg_enable(phy
); /* also resets PHY */
659 phy
->state
= PHY_AUTONEG_RDY
;
660 mac
->ops
->set_speed_duplex_fc(mac
, -1, -1, fc
);
661 lc
->fc
= (unsigned char)fc
;
662 phy
->ops
->reset(phy
, 0);
668 * External interrupt handler for boards using elmer0.
670 int t1_elmer0_ext_intr_handler(adapter_t
*adapter
)
676 t1_tpi_read(adapter
, A_ELMER0_INT_CAUSE
, &cause
);
678 switch (board_info(adapter
)->board
) {
679 #ifdef CONFIG_CHELSIO_T1_1G
680 case CHBT_BOARD_CHT204
:
681 case CHBT_BOARD_CHT204E
:
682 case CHBT_BOARD_CHN204
:
683 case CHBT_BOARD_CHT204V
: {
685 for_each_port(adapter
, i
) {
687 if (!(cause
& (1 << port_bit
)))
690 phy
= adapter
->port
[i
].phy
;
691 phy_cause
= phy
->ops
->interrupt_handler(phy
);
692 if (phy_cause
& cphy_cause_link_change
)
693 t1_link_changed(adapter
, i
);
697 case CHBT_BOARD_CHT101
:
698 if (cause
& ELMER0_GP_BIT1
) { /* Marvell 88E1111 interrupt */
699 phy
= adapter
->port
[0].phy
;
700 phy_cause
= phy
->ops
->interrupt_handler(phy
);
701 if (phy_cause
& cphy_cause_link_change
)
702 t1_link_changed(adapter
, 0);
705 case CHBT_BOARD_7500
: {
708 * Elmer0's interrupt cause isn't useful here because there is
709 * only one bit that can be set for all 4 ports. This means
710 * we are forced to check every PHY's interrupt status
711 * register to see who initiated the interrupt.
713 for_each_port(adapter
, p
) {
714 phy
= adapter
->port
[p
].phy
;
715 phy_cause
= phy
->ops
->interrupt_handler(phy
);
716 if (phy_cause
& cphy_cause_link_change
)
717 t1_link_changed(adapter
, p
);
722 case CHBT_BOARD_CHT210
:
723 case CHBT_BOARD_N210
:
724 case CHBT_BOARD_N110
:
725 if (cause
& ELMER0_GP_BIT6
) { /* Marvell 88x2010 interrupt */
726 phy
= adapter
->port
[0].phy
;
727 phy_cause
= phy
->ops
->interrupt_handler(phy
);
728 if (phy_cause
& cphy_cause_link_change
)
729 t1_link_changed(adapter
, 0);
732 case CHBT_BOARD_8000
:
733 case CHBT_BOARD_CHT110
:
734 CH_DBG(adapter
, INTR
, "External interrupt cause 0x%x\n",
736 if (cause
& ELMER0_GP_BIT1
) { /* PMC3393 INTB */
737 struct cmac
*mac
= adapter
->port
[0].mac
;
739 mac
->ops
->interrupt_handler(mac
);
741 if (cause
& ELMER0_GP_BIT5
) { /* XPAK MOD_DETECT */
745 A_ELMER0_GPI_STAT
, &mod_detect
);
746 CH_MSG(adapter
, INFO
, LINK
, "XPAK %s\n",
747 mod_detect
? "removed" : "inserted");
750 #ifdef CONFIG_CHELSIO_T1_COUGAR
751 case CHBT_BOARD_COUGAR
:
752 if (adapter
->params
.nports
== 1) {
753 if (cause
& ELMER0_GP_BIT1
) { /* Vitesse MAC */
754 struct cmac
*mac
= adapter
->port
[0].mac
;
755 mac
->ops
->interrupt_handler(mac
);
757 if (cause
& ELMER0_GP_BIT5
) { /* XPAK MOD_DETECT */
762 for_each_port(adapter
, i
) {
763 port_bit
= i
? i
+ 1 : 0;
764 if (!(cause
& (1 << port_bit
)))
767 phy
= adapter
->port
[i
].phy
;
768 phy_cause
= phy
->ops
->interrupt_handler(phy
);
769 if (phy_cause
& cphy_cause_link_change
)
770 t1_link_changed(adapter
, i
);
776 t1_tpi_write(adapter
, A_ELMER0_INT_CAUSE
, cause
);
780 /* Enables all interrupts. */
781 void t1_interrupts_enable(adapter_t
*adapter
)
785 adapter
->slow_intr_mask
= F_PL_INTR_SGE_ERR
| F_PL_INTR_TP
;
787 t1_sge_intr_enable(adapter
->sge
);
788 t1_tp_intr_enable(adapter
->tp
);
790 adapter
->slow_intr_mask
|= F_PL_INTR_ESPI
;
791 t1_espi_intr_enable(adapter
->espi
);
794 /* Enable MAC/PHY interrupts for each port. */
795 for_each_port(adapter
, i
) {
796 adapter
->port
[i
].mac
->ops
->interrupt_enable(adapter
->port
[i
].mac
);
797 adapter
->port
[i
].phy
->ops
->interrupt_enable(adapter
->port
[i
].phy
);
800 /* Enable PCIX & external chip interrupts on ASIC boards. */
801 if (t1_is_asic(adapter
)) {
802 u32 pl_intr
= readl(adapter
->regs
+ A_PL_ENABLE
);
804 /* PCI-X interrupts */
805 pci_write_config_dword(adapter
->pdev
, A_PCICFG_INTR_ENABLE
,
808 adapter
->slow_intr_mask
|= F_PL_INTR_EXT
| F_PL_INTR_PCIX
;
809 pl_intr
|= F_PL_INTR_EXT
| F_PL_INTR_PCIX
;
810 writel(pl_intr
, adapter
->regs
+ A_PL_ENABLE
);
814 /* Disables all interrupts. */
815 void t1_interrupts_disable(adapter_t
* adapter
)
819 t1_sge_intr_disable(adapter
->sge
);
820 t1_tp_intr_disable(adapter
->tp
);
822 t1_espi_intr_disable(adapter
->espi
);
824 /* Disable MAC/PHY interrupts for each port. */
825 for_each_port(adapter
, i
) {
826 adapter
->port
[i
].mac
->ops
->interrupt_disable(adapter
->port
[i
].mac
);
827 adapter
->port
[i
].phy
->ops
->interrupt_disable(adapter
->port
[i
].phy
);
830 /* Disable PCIX & external chip interrupts. */
831 if (t1_is_asic(adapter
))
832 writel(0, adapter
->regs
+ A_PL_ENABLE
);
834 /* PCI-X interrupts */
835 pci_write_config_dword(adapter
->pdev
, A_PCICFG_INTR_ENABLE
, 0);
837 adapter
->slow_intr_mask
= 0;
840 /* Clears all interrupts */
841 void t1_interrupts_clear(adapter_t
* adapter
)
845 t1_sge_intr_clear(adapter
->sge
);
846 t1_tp_intr_clear(adapter
->tp
);
848 t1_espi_intr_clear(adapter
->espi
);
850 /* Clear MAC/PHY interrupts for each port. */
851 for_each_port(adapter
, i
) {
852 adapter
->port
[i
].mac
->ops
->interrupt_clear(adapter
->port
[i
].mac
);
853 adapter
->port
[i
].phy
->ops
->interrupt_clear(adapter
->port
[i
].phy
);
856 /* Enable interrupts for external devices. */
857 if (t1_is_asic(adapter
)) {
858 u32 pl_intr
= readl(adapter
->regs
+ A_PL_CAUSE
);
860 writel(pl_intr
| F_PL_INTR_EXT
| F_PL_INTR_PCIX
,
861 adapter
->regs
+ A_PL_CAUSE
);
864 /* PCI-X interrupts */
865 pci_write_config_dword(adapter
->pdev
, A_PCICFG_INTR_CAUSE
, 0xffffffff);
869 * Slow path interrupt handler for ASICs.
871 static int asic_slow_intr(adapter_t
*adapter
)
873 u32 cause
= readl(adapter
->regs
+ A_PL_CAUSE
);
875 cause
&= adapter
->slow_intr_mask
;
878 if (cause
& F_PL_INTR_SGE_ERR
)
879 t1_sge_intr_error_handler(adapter
->sge
);
880 if (cause
& F_PL_INTR_TP
)
881 t1_tp_intr_handler(adapter
->tp
);
882 if (cause
& F_PL_INTR_ESPI
)
883 t1_espi_intr_handler(adapter
->espi
);
884 if (cause
& F_PL_INTR_PCIX
)
885 t1_pci_intr_handler(adapter
);
886 if (cause
& F_PL_INTR_EXT
)
887 t1_elmer0_ext_intr(adapter
);
889 /* Clear the interrupts just processed. */
890 writel(cause
, adapter
->regs
+ A_PL_CAUSE
);
891 readl(adapter
->regs
+ A_PL_CAUSE
); /* flush writes */
895 int t1_slow_intr_handler(adapter_t
*adapter
)
897 #ifdef CONFIG_CHELSIO_T1_1G
898 if (!t1_is_asic(adapter
))
899 return fpga_slow_intr(adapter
);
901 return asic_slow_intr(adapter
);
904 /* Power sequencing is a work-around for Intel's XPAKs. */
905 static void power_sequence_xpak(adapter_t
* adapter
)
911 t1_tpi_read(adapter
, A_ELMER0_GPI_STAT
, &mod_detect
);
912 if (!(ELMER0_GP_BIT5
& mod_detect
)) {
913 /* XPAK is present */
914 t1_tpi_read(adapter
, A_ELMER0_GPO
, &gpo
);
915 gpo
|= ELMER0_GP_BIT18
;
916 t1_tpi_write(adapter
, A_ELMER0_GPO
, gpo
);
920 int __devinit
t1_get_board_rev(adapter_t
*adapter
, const struct board_info
*bi
,
921 struct adapter_params
*p
)
923 p
->chip_version
= bi
->chip_term
;
924 p
->is_asic
= (p
->chip_version
!= CHBT_TERM_FPGA
);
925 if (p
->chip_version
== CHBT_TERM_T1
||
926 p
->chip_version
== CHBT_TERM_T2
||
927 p
->chip_version
== CHBT_TERM_FPGA
) {
928 u32 val
= readl(adapter
->regs
+ A_TP_PC_CONFIG
);
930 val
= G_TP_PC_REV(val
);
932 p
->chip_revision
= TERM_T1B
;
934 p
->chip_revision
= TERM_T2
;
943 * Enable board components other than the Chelsio chip, such as external MAC
946 static int board_init(adapter_t
*adapter
, const struct board_info
*bi
)
949 case CHBT_BOARD_8000
:
950 case CHBT_BOARD_N110
:
951 case CHBT_BOARD_N210
:
952 case CHBT_BOARD_CHT210
:
953 case CHBT_BOARD_COUGAR
:
954 t1_tpi_par(adapter
, 0xf);
955 t1_tpi_write(adapter
, A_ELMER0_GPO
, 0x800);
957 case CHBT_BOARD_CHT110
:
958 t1_tpi_par(adapter
, 0xf);
959 t1_tpi_write(adapter
, A_ELMER0_GPO
, 0x1800);
961 /* TBD XXX Might not need. This fixes a problem
962 * described in the Intel SR XPAK errata.
964 power_sequence_xpak(adapter
);
966 #ifdef CONFIG_CHELSIO_T1_1G
967 case CHBT_BOARD_CHT204E
:
968 /* add config space write here */
969 case CHBT_BOARD_CHT204
:
970 case CHBT_BOARD_CHT204V
:
971 case CHBT_BOARD_CHN204
:
972 t1_tpi_par(adapter
, 0xf);
973 t1_tpi_write(adapter
, A_ELMER0_GPO
, 0x804);
975 case CHBT_BOARD_CHT101
:
976 case CHBT_BOARD_7500
:
977 t1_tpi_par(adapter
, 0xf);
978 t1_tpi_write(adapter
, A_ELMER0_GPO
, 0x1804);
986 * Initialize and configure the Terminator HW modules. Note that external
987 * MAC and PHYs are initialized separately.
989 int t1_init_hw_modules(adapter_t
*adapter
)
992 const struct board_info
*bi
= board_info(adapter
);
994 if (!bi
->clock_mc4
) {
995 u32 val
= readl(adapter
->regs
+ A_MC4_CFG
);
997 writel(val
| F_READY
| F_MC4_SLOW
, adapter
->regs
+ A_MC4_CFG
);
998 writel(F_M_BUS_ENABLE
| F_TCAM_RESET
,
999 adapter
->regs
+ A_MC5_CONFIG
);
1002 #ifdef CONFIG_CHELSIO_T1_COUGAR
1003 if (adapter
->cspi
&& t1_cspi_init(adapter
->cspi
))
1006 if (adapter
->espi
&& t1_espi_init(adapter
->espi
, bi
->chip_mac
,
1010 if (t1_tp_reset(adapter
->tp
, &adapter
->params
.tp
, bi
->clock_core
))
1013 err
= t1_sge_configure(adapter
->sge
, &adapter
->params
.sge
);
1023 * Determine a card's PCI mode.
1025 static void __devinit
get_pci_mode(adapter_t
*adapter
, struct chelsio_pci_params
*p
)
1027 static const unsigned short speed_map
[] = { 33, 66, 100, 133 };
1030 pci_read_config_dword(adapter
->pdev
, A_PCICFG_MODE
, &pci_mode
);
1031 p
->speed
= speed_map
[G_PCI_MODE_CLK(pci_mode
)];
1032 p
->width
= (pci_mode
& F_PCI_MODE_64BIT
) ? 64 : 32;
1033 p
->is_pcix
= (pci_mode
& F_PCI_MODE_PCIX
) != 0;
1037 * Release the structures holding the SW per-Terminator-HW-module state.
1039 void t1_free_sw_modules(adapter_t
*adapter
)
1043 for_each_port(adapter
, i
) {
1044 struct cmac
*mac
= adapter
->port
[i
].mac
;
1045 struct cphy
*phy
= adapter
->port
[i
].phy
;
1048 mac
->ops
->destroy(mac
);
1050 phy
->ops
->destroy(phy
);
1054 t1_sge_destroy(adapter
->sge
);
1056 t1_tp_destroy(adapter
->tp
);
1058 t1_espi_destroy(adapter
->espi
);
1059 #ifdef CONFIG_CHELSIO_T1_COUGAR
1061 t1_cspi_destroy(adapter
->cspi
);
1065 static void __devinit
init_link_config(struct link_config
*lc
,
1066 const struct board_info
*bi
)
1068 lc
->supported
= bi
->caps
;
1069 lc
->requested_speed
= lc
->speed
= SPEED_INVALID
;
1070 lc
->requested_duplex
= lc
->duplex
= DUPLEX_INVALID
;
1071 lc
->requested_fc
= lc
->fc
= PAUSE_RX
| PAUSE_TX
;
1072 if (lc
->supported
& SUPPORTED_Autoneg
) {
1073 lc
->advertising
= lc
->supported
;
1074 lc
->autoneg
= AUTONEG_ENABLE
;
1075 lc
->requested_fc
|= PAUSE_AUTONEG
;
1077 lc
->advertising
= 0;
1078 lc
->autoneg
= AUTONEG_DISABLE
;
1082 #ifdef CONFIG_CHELSIO_T1_COUGAR
1083 if (bi
->clock_cspi
&& !(adapter
->cspi
= t1_cspi_create(adapter
))) {
1084 CH_ERR("%s: CSPI initialization failed\n",
1091 * Allocate and initialize the data structures that hold the SW state of
1092 * the Terminator HW modules.
1094 int __devinit
t1_init_sw_modules(adapter_t
*adapter
,
1095 const struct board_info
*bi
)
1099 adapter
->params
.brd_info
= bi
;
1100 adapter
->params
.nports
= bi
->port_number
;
1101 adapter
->params
.stats_update_period
= bi
->gmac
->stats_update_period
;
1103 adapter
->sge
= t1_sge_create(adapter
, &adapter
->params
.sge
);
1104 if (!adapter
->sge
) {
1105 CH_ERR("%s: SGE initialization failed\n",
1110 if (bi
->espi_nports
&& !(adapter
->espi
= t1_espi_create(adapter
))) {
1111 CH_ERR("%s: ESPI initialization failed\n",
1116 adapter
->tp
= t1_tp_create(adapter
, &adapter
->params
.tp
);
1118 CH_ERR("%s: TP initialization failed\n",
1123 board_init(adapter
, bi
);
1124 bi
->mdio_ops
->init(adapter
, bi
);
1125 if (bi
->gphy
->reset
)
1126 bi
->gphy
->reset(adapter
);
1127 if (bi
->gmac
->reset
)
1128 bi
->gmac
->reset(adapter
);
1130 for_each_port(adapter
, i
) {
1133 int phy_addr
= bi
->mdio_phybaseaddr
+ i
;
1135 adapter
->port
[i
].phy
= bi
->gphy
->create(adapter
, phy_addr
,
1137 if (!adapter
->port
[i
].phy
) {
1138 CH_ERR("%s: PHY %d initialization failed\n",
1143 adapter
->port
[i
].mac
= mac
= bi
->gmac
->create(adapter
, i
);
1145 CH_ERR("%s: MAC %d initialization failed\n",
1151 * Get the port's MAC addresses either from the EEPROM if one
1152 * exists or the one hardcoded in the MAC.
1154 if (!t1_is_asic(adapter
) || bi
->chip_mac
== CHBT_MAC_DUMMY
)
1155 mac
->ops
->macaddress_get(mac
, hw_addr
);
1156 else if (vpd_macaddress_get(adapter
, i
, hw_addr
)) {
1157 CH_ERR("%s: could not read MAC address from VPD ROM\n",
1158 adapter
->port
[i
].dev
->name
);
1161 memcpy(adapter
->port
[i
].dev
->dev_addr
, hw_addr
, ETH_ALEN
);
1162 init_link_config(&adapter
->port
[i
].link_config
, bi
);
1165 get_pci_mode(adapter
, &adapter
->params
.pci
);
1166 t1_interrupts_clear(adapter
);
1170 t1_free_sw_modules(adapter
);