13 #include <linux/slab.h>
21 #define QT202X_REQUIRED_DEVS (MDIO_DEVS_PCS | \
25 #define QT202X_LOOPBACKS ((1 << LOOPBACK_PCS) | \
26 (1 << LOOPBACK_PMAPMD) | \
27 (1 << LOOPBACK_PHYXS_WS))
31 #define MDIO_QUAKE_LED0_REG (0xD006)
34 #define PCS_FW_HEARTBEAT_REG 0xd7ee
35 #define PCS_FW_HEARTB_LBN 0
36 #define PCS_FW_HEARTB_WIDTH 8
37 #define PCS_FW_PRODUCT_CODE_1 0xd7f0
38 #define PCS_FW_VERSION_1 0xd7f3
39 #define PCS_FW_BUILD_1 0xd7f6
40 #define PCS_UC8051_STATUS_REG 0xd7fd
41 #define PCS_UC_STATUS_LBN 0
42 #define PCS_UC_STATUS_WIDTH 8
43 #define PCS_UC_STATUS_FW_SAVE 0x20
44 #define PMA_PMD_MODE_REG 0xc301
45 #define PMA_PMD_RXIN_SEL_LBN 6
46 #define PMA_PMD_FTX_CTRL2_REG 0xc309
47 #define PMA_PMD_FTX_STATIC_LBN 13
48 #define PMA_PMD_VEND1_REG 0xc001
49 #define PMA_PMD_VEND1_LBTXD_LBN 15
50 #define PCS_VEND1_REG 0xc000
51 #define PCS_VEND1_LBTXD_LBN 5
66 #define QT2022C2_MAX_RESET_TIME 500
67 #define QT2022C2_RESET_WAIT 10
69 #define QT2025C_MAX_HEARTB_TIME (5 * HZ)
70 #define QT2025C_HEARTB_WAIT 100
71 #define QT2025C_MAX_FWSTART_TIME (25 * HZ / 10)
72 #define QT2025C_FWSTART_WAIT 100
74 #define BUG17190_INTERVAL (2 * HZ)
76 static int qt2025c_wait_heartbeat(
struct efx_nic *efx)
79 int reg, old_counter = 0;
91 else if (counter != old_counter)
97 "If an SFP+ direct attach cable is"
98 " connected, please check that it complies"
99 " with the SFP+ specification\n");
108 static int qt2025c_wait_fw_status_good(
struct efx_nic *efx)
130 static void qt2025c_restart_firmware(
struct efx_nic *efx)
133 efx_mdio_write(efx, 3, 0xe854, 0x00c0);
134 efx_mdio_write(efx, 3, 0xe854, 0x0040);
138 static int qt2025c_wait_reset(
struct efx_nic *efx)
142 rc = qt2025c_wait_heartbeat(efx);
146 rc = qt2025c_wait_fw_status_good(efx);
152 "bashing QT2025C microcontroller\n");
153 qt2025c_restart_firmware(efx);
154 rc = qt2025c_wait_heartbeat(efx);
157 rc = qt2025c_wait_fw_status_good(efx);
163 static void qt2025c_firmware_id(
struct efx_nic *efx)
169 for (i = 0; i <
sizeof(firmware_id); i++)
173 "QT2025C firmware %xr%d v%d.%d.%d.%d [20%02d-%02d-%02d]\n",
174 (firmware_id[0] << 8) | firmware_id[1], firmware_id[2],
175 firmware_id[3] >> 4, firmware_id[3] & 0xf,
176 firmware_id[4], firmware_id[5],
177 firmware_id[6], firmware_id[7], firmware_id[8]);
178 phy_data->
firmware_ver = ((firmware_id[3] & 0xf0) << 20) |
179 ((firmware_id[3] & 0x0f) << 16) |
180 (firmware_id[4] << 8) | firmware_id[5];
183 static void qt2025c_bug17190_workaround(
struct efx_nic *efx)
216 static int qt2025c_select_phy_mode(
struct efx_nic *efx)
236 reg = efx_mdio_read(efx, 1, 0xc319);
237 if ((reg & 0x0038) == phy_op_mode)
246 efx_mdio_write(efx, 1, 0xc300, 0x0000);
252 efx_mdio_write(efx, 1, 0xc303, 0x4498);
253 for (i = 0; i < 9; i++) {
254 efx_mdio_write(efx, 1, 0xc303, 0x4488);
255 efx_mdio_write(efx, 1, 0xc303, 0x4480);
256 efx_mdio_write(efx, 1, 0xc303, 0x4490);
257 efx_mdio_write(efx, 1, 0xc303, 0x4498);
260 efx_mdio_write(efx, 1, 0xc303, 0x0920);
261 efx_mdio_write(efx, 1, 0xd008, 0x0004);
262 for (i = 0; i < 9; i++) {
263 efx_mdio_write(efx, 1, 0xc303, 0x0900);
264 efx_mdio_write(efx, 1, 0xd008, 0x0005);
265 efx_mdio_write(efx, 1, 0xc303, 0x0920);
266 efx_mdio_write(efx, 1, 0xd008, 0x0004);
268 efx_mdio_write(efx, 1, 0xc303, 0x4900);
270 efx_mdio_write(efx, 1, 0xc303, 0x4900);
271 efx_mdio_write(efx, 1, 0xc302, 0x0004);
272 efx_mdio_write(efx, 1, 0xc316, 0x0013);
273 efx_mdio_write(efx, 1, 0xc318, 0x0054);
274 efx_mdio_write(efx, 1, 0xc319, phy_op_mode);
275 efx_mdio_write(efx, 1, 0xc31a, 0x0098);
276 efx_mdio_write(efx, 3, 0x0026, 0x0e00);
277 efx_mdio_write(efx, 3, 0x0027, 0x0013);
278 efx_mdio_write(efx, 3, 0x0028, 0xa528);
279 efx_mdio_write(efx, 1, 0xd006, 0x000a);
280 efx_mdio_write(efx, 1, 0xd007, 0x0009);
281 efx_mdio_write(efx, 1, 0xd008, 0x0004);
286 efx_mdio_write(efx, 1, 0xc317, 0x00ff);
291 efx_mdio_write(efx, 1, 0xc300, 0x0002);
295 qt2025c_restart_firmware(efx);
298 rc = qt2025c_wait_reset(efx);
301 "PHY microcontroller reset during mode switch "
309 static int qt202x_reset_phy(
struct efx_nic *efx)
316 rc = qt2025c_wait_reset(efx);
342 static int qt202x_phy_probe(
struct efx_nic *efx)
360 static int qt202x_phy_init(
struct efx_nic *efx)
365 rc = qt202x_reset_phy(efx);
373 "PHY ID reg %x (OUI %06x model %02x revision %x)\n",
375 efx_mdio_id_rev(devid));
378 qt2025c_firmware_id(efx);
383 static int qt202x_link_ok(
struct efx_nic *efx)
388 static bool qt202x_phy_poll(
struct efx_nic *efx)
398 qt2025c_bug17190_workaround(efx);
403 static int qt202x_phy_reconfigure(
struct efx_nic *efx)
408 int rc = qt2025c_select_phy_mode(efx);
428 qt202x_reset_phy(efx);
442 mdio45_ethtool_gset(&efx->
mdio, ecmd);
445 static void qt202x_phy_remove(
struct efx_nic *efx)
452 static int qt202x_phy_get_module_info(
struct efx_nic *efx,
460 static int qt202x_phy_get_module_eeprom(
struct efx_nic *efx,
463 int mmd, reg_base,
rc,
i;
473 for (i = 0; i < ee->
len; i++) {
474 rc = efx_mdio_read(efx, mmd, reg_base + ee->
offset + i);
484 .probe = qt202x_phy_probe,
485 .init = qt202x_phy_init,
486 .reconfigure = qt202x_phy_reconfigure,
487 .poll = qt202x_phy_poll,
489 .remove = qt202x_phy_remove,
490 .get_settings = qt202x_phy_get_settings,
493 .get_module_eeprom = qt202x_phy_get_module_eeprom,
494 .get_module_info = qt202x_phy_get_module_info,