1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2006-2008 Solarflare Communications Inc.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
10 * Driver for XFP optical PHYs (plus some support specific to the Quake 2022/32)
11 * See www.amcc.com for details (search for qt2032)
14 #include <linux/timer.h>
15 #include <linux/delay.h>
22 #define XFP_REQUIRED_DEVS (MDIO_MMDREG_DEVS_PCS | \
23 MDIO_MMDREG_DEVS_PMAPMD | \
24 MDIO_MMDREG_DEVS_PHYXS)
26 #define XFP_LOOPBACKS ((1 << LOOPBACK_PCS) | \
27 (1 << LOOPBACK_PMAPMD) | \
28 (1 << LOOPBACK_NETWORK))
30 /****************************************************************************/
31 /* Quake-specific MDIO registers */
32 #define MDIO_QUAKE_LED0_REG (0xD006)
34 void xfp_set_led(struct efx_nic
*p
, int led
, int mode
)
36 int addr
= MDIO_QUAKE_LED0_REG
+ led
;
37 mdio_clause45_write(p
, p
->mii
.phy_id
, MDIO_MMD_PMAPMD
, addr
,
42 enum efx_phy_mode phy_mode
;
45 #define XFP_MAX_RESET_TIME 500
46 #define XFP_RESET_WAIT 10
48 /* Reset the PHYXS MMD. This is documented (for the Quake PHY) as doing
49 * a complete soft reset.
51 static int xfp_reset_phy(struct efx_nic
*efx
)
55 rc
= mdio_clause45_reset_mmd(efx
, MDIO_MMD_PHYXS
,
56 XFP_MAX_RESET_TIME
/ XFP_RESET_WAIT
,
61 /* Wait 250ms for the PHY to complete bootup */
64 /* Check that all the MMDs we expect are present and responding. We
65 * expect faults on some if the link is down, but not on the PHY XS */
66 rc
= mdio_clause45_check_mmds(efx
, XFP_REQUIRED_DEVS
,
67 MDIO_MMDREG_DEVS_PHYXS
);
71 efx
->board_info
.init_leds(efx
);
76 EFX_ERR(efx
, "PHY reset timed out\n");
80 static int xfp_phy_init(struct efx_nic
*efx
)
82 struct xfp_phy_data
*phy_data
;
83 u32 devid
= mdio_clause45_read_id(efx
, MDIO_MMD_PHYXS
);
86 phy_data
= kzalloc(sizeof(struct xfp_phy_data
), GFP_KERNEL
);
89 efx
->phy_data
= phy_data
;
91 EFX_INFO(efx
, "PHY ID reg %x (OUI %06x model %02x revision %x)\n",
92 devid
, mdio_id_oui(devid
), mdio_id_model(devid
),
95 phy_data
->phy_mode
= efx
->phy_mode
;
97 rc
= xfp_reset_phy(efx
);
99 EFX_INFO(efx
, "PHY init %s.\n",
100 rc
? "failed" : "successful");
107 kfree(efx
->phy_data
);
108 efx
->phy_data
= NULL
;
112 static void xfp_phy_clear_interrupt(struct efx_nic
*efx
)
114 xenpack_clear_lasi_irqs(efx
);
117 static int xfp_link_ok(struct efx_nic
*efx
)
119 return mdio_clause45_links_ok(efx
, XFP_REQUIRED_DEVS
);
122 static void xfp_phy_poll(struct efx_nic
*efx
)
124 int link_up
= xfp_link_ok(efx
);
125 /* Simulate a PHY event if link state has changed */
126 if (link_up
!= efx
->link_up
)
127 falcon_sim_phy_event(efx
);
130 static void xfp_phy_reconfigure(struct efx_nic
*efx
)
132 struct xfp_phy_data
*phy_data
= efx
->phy_data
;
134 /* Reset the PHY when moving from tx off to tx on */
135 if (!(efx
->phy_mode
& PHY_MODE_TX_DISABLED
) &&
136 (phy_data
->phy_mode
& PHY_MODE_TX_DISABLED
))
139 mdio_clause45_transmit_disable(efx
);
140 mdio_clause45_phy_reconfigure(efx
);
142 phy_data
->phy_mode
= efx
->phy_mode
;
143 efx
->link_up
= xfp_link_ok(efx
);
144 efx
->link_speed
= 10000;
146 efx
->link_fc
= efx
->wanted_fc
;
150 static void xfp_phy_fini(struct efx_nic
*efx
)
152 /* Clobber the LED if it was blinking */
153 efx
->board_info
.blink(efx
, false);
155 /* Free the context block */
156 kfree(efx
->phy_data
);
157 efx
->phy_data
= NULL
;
160 struct efx_phy_operations falcon_xfp_phy_ops
= {
162 .init
= xfp_phy_init
,
163 .reconfigure
= xfp_phy_reconfigure
,
164 .poll
= xfp_phy_poll
,
165 .fini
= xfp_phy_fini
,
166 .clear_interrupt
= xfp_phy_clear_interrupt
,
167 .get_settings
= mdio_clause45_get_settings
,
168 .set_settings
= mdio_clause45_set_settings
,
169 .mmds
= XFP_REQUIRED_DEVS
,
170 .loopbacks
= XFP_LOOPBACKS
,