blob: 326ffa49fbd23d292f0a2892f88246e3c1e8f723 [file] [log] [blame]
Ben Hutchings8ceee662008-04-27 12:55:59 +01001/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
Ben Hutchings906bb262009-11-29 15:16:19 +00003 * Copyright 2006-2009 Solarflare Communications Inc.
Ben Hutchings8ceee662008-04-27 12:55:59 +01004 *
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.
8 */
9/*
Ben Hutchingsb37b62f2009-10-23 08:33:42 +000010 * Driver for AMCC QT202x SFP+ and XFP adapters; see www.amcc.com for details
Ben Hutchings8ceee662008-04-27 12:55:59 +010011 */
12
13#include <linux/timer.h>
14#include <linux/delay.h>
15#include "efx.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010016#include "mdio_10g.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010017#include "phy.h"
Ben Hutchings744093c2009-11-29 15:12:08 +000018#include "nic.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010019
Ben Hutchingsb37b62f2009-10-23 08:33:42 +000020#define QT202X_REQUIRED_DEVS (MDIO_DEVS_PCS | \
21 MDIO_DEVS_PMAPMD | \
22 MDIO_DEVS_PHYXS)
Ben Hutchings8ceee662008-04-27 12:55:59 +010023
Ben Hutchingsb37b62f2009-10-23 08:33:42 +000024#define QT202X_LOOPBACKS ((1 << LOOPBACK_PCS) | \
25 (1 << LOOPBACK_PMAPMD) | \
Ben Hutchingse58f69f2009-11-29 15:08:41 +000026 (1 << LOOPBACK_PHYXS_WS))
Ben Hutchings3273c2e2008-05-07 13:36:19 +010027
Ben Hutchings8ceee662008-04-27 12:55:59 +010028/****************************************************************************/
29/* Quake-specific MDIO registers */
30#define MDIO_QUAKE_LED0_REG (0xD006)
31
Ben Hutchingsd2d2c372009-02-27 13:07:33 +000032/* QT2025C only */
33#define PCS_FW_HEARTBEAT_REG 0xd7ee
34#define PCS_FW_HEARTB_LBN 0
35#define PCS_FW_HEARTB_WIDTH 8
Matthew Slattery0d83b2f2009-12-23 13:48:04 +000036#define PCS_FW_PRODUCT_CODE_1 0xd7f0
37#define PCS_FW_VERSION_1 0xd7f3
38#define PCS_FW_BUILD_1 0xd7f6
Ben Hutchingsd2d2c372009-02-27 13:07:33 +000039#define PCS_UC8051_STATUS_REG 0xd7fd
40#define PCS_UC_STATUS_LBN 0
41#define PCS_UC_STATUS_WIDTH 8
42#define PCS_UC_STATUS_FW_SAVE 0x20
43#define PMA_PMD_FTX_CTRL2_REG 0xc309
44#define PMA_PMD_FTX_STATIC_LBN 13
45#define PMA_PMD_VEND1_REG 0xc001
46#define PMA_PMD_VEND1_LBTXD_LBN 15
47#define PCS_VEND1_REG 0xc000
48#define PCS_VEND1_LBTXD_LBN 5
49
Ben Hutchingsb37b62f2009-10-23 08:33:42 +000050void falcon_qt202x_set_led(struct efx_nic *p, int led, int mode)
Ben Hutchings8ceee662008-04-27 12:55:59 +010051{
52 int addr = MDIO_QUAKE_LED0_REG + led;
Ben Hutchings68e7f452009-04-29 08:05:08 +000053 efx_mdio_write(p, MDIO_MMD_PMAPMD, addr, mode);
Ben Hutchings8ceee662008-04-27 12:55:59 +010054}
55
Ben Hutchingsb37b62f2009-10-23 08:33:42 +000056struct qt202x_phy_data {
Ben Hutchingsf8b87c12008-09-01 12:48:17 +010057 enum efx_phy_mode phy_mode;
Matthew Slattery17d6aea2009-12-23 13:47:37 +000058 bool bug17190_in_bad_state;
59 unsigned long bug17190_timer;
Matthew Slattery0d83b2f2009-12-23 13:48:04 +000060 u32 firmware_ver;
Ben Hutchings3273c2e2008-05-07 13:36:19 +010061};
62
Ben Hutchingsb37b62f2009-10-23 08:33:42 +000063#define QT2022C2_MAX_RESET_TIME 500
64#define QT2022C2_RESET_WAIT 10
Ben Hutchings8ceee662008-04-27 12:55:59 +010065
Matthew Slattery1a1284e2009-12-23 13:48:32 +000066#define QT2025C_MAX_HEARTB_TIME (5 * HZ)
67#define QT2025C_HEARTB_WAIT 100
68#define QT2025C_MAX_FWSTART_TIME (25 * HZ / 10)
69#define QT2025C_FWSTART_WAIT 100
70
Matthew Slattery17d6aea2009-12-23 13:47:37 +000071#define BUG17190_INTERVAL (2 * HZ)
72
Matthew Slattery1a1284e2009-12-23 13:48:32 +000073static int qt2025c_wait_heartbeat(struct efx_nic *efx)
Ben Hutchingsd2d2c372009-02-27 13:07:33 +000074{
Matthew Slattery1a1284e2009-12-23 13:48:32 +000075 unsigned long timeout = jiffies + QT2025C_MAX_HEARTB_TIME;
Ben Hutchingsd2d2c372009-02-27 13:07:33 +000076 int reg, old_counter = 0;
77
78 /* Wait for firmware heartbeat to start */
79 for (;;) {
80 int counter;
Ben Hutchings68e7f452009-04-29 08:05:08 +000081 reg = efx_mdio_read(efx, MDIO_MMD_PCS, PCS_FW_HEARTBEAT_REG);
Ben Hutchingsd2d2c372009-02-27 13:07:33 +000082 if (reg < 0)
83 return reg;
84 counter = ((reg >> PCS_FW_HEARTB_LBN) &
85 ((1 << PCS_FW_HEARTB_WIDTH) - 1));
86 if (old_counter == 0)
87 old_counter = counter;
88 else if (counter != old_counter)
89 break;
90 if (time_after(jiffies, timeout))
91 return -ETIMEDOUT;
Matthew Slattery1a1284e2009-12-23 13:48:32 +000092 msleep(QT2025C_HEARTB_WAIT);
Ben Hutchingsd2d2c372009-02-27 13:07:33 +000093 }
94
Matthew Slattery1a1284e2009-12-23 13:48:32 +000095 return 0;
96}
97
98static int qt2025c_wait_fw_status_good(struct efx_nic *efx)
99{
100 unsigned long timeout = jiffies + QT2025C_MAX_FWSTART_TIME;
101 int reg;
102
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000103 /* Wait for firmware status to look good */
104 for (;;) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000105 reg = efx_mdio_read(efx, MDIO_MMD_PCS, PCS_UC8051_STATUS_REG);
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000106 if (reg < 0)
107 return reg;
108 if ((reg &
109 ((1 << PCS_UC_STATUS_WIDTH) - 1) << PCS_UC_STATUS_LBN) >=
110 PCS_UC_STATUS_FW_SAVE)
111 break;
112 if (time_after(jiffies, timeout))
113 return -ETIMEDOUT;
Matthew Slattery1a1284e2009-12-23 13:48:32 +0000114 msleep(QT2025C_FWSTART_WAIT);
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000115 }
116
117 return 0;
118}
119
Matthew Slattery1a1284e2009-12-23 13:48:32 +0000120static void qt2025c_restart_firmware(struct efx_nic *efx)
121{
122 /* Restart microcontroller execution of firmware from RAM */
123 efx_mdio_write(efx, 3, 0xe854, 0x00c0);
124 efx_mdio_write(efx, 3, 0xe854, 0x0040);
125 msleep(50);
126}
127
128static int qt2025c_wait_reset(struct efx_nic *efx)
129{
130 int rc;
131
132 rc = qt2025c_wait_heartbeat(efx);
133 if (rc != 0)
134 return rc;
135
136 rc = qt2025c_wait_fw_status_good(efx);
137 if (rc == -ETIMEDOUT) {
138 /* Bug 17689: occasionally heartbeat starts but firmware status
139 * code never progresses beyond 0x00. Try again, once, after
140 * restarting execution of the firmware image. */
141 EFX_LOG(efx, "bashing QT2025C microcontroller\n");
142 qt2025c_restart_firmware(efx);
143 rc = qt2025c_wait_heartbeat(efx);
144 if (rc != 0)
145 return rc;
146 rc = qt2025c_wait_fw_status_good(efx);
147 }
148
149 return rc;
150}
151
Matthew Slattery0d83b2f2009-12-23 13:48:04 +0000152static void qt2025c_firmware_id(struct efx_nic *efx)
153{
154 struct qt202x_phy_data *phy_data = efx->phy_data;
155 u8 firmware_id[9];
156 size_t i;
157
158 for (i = 0; i < sizeof(firmware_id); i++)
159 firmware_id[i] = efx_mdio_read(efx, MDIO_MMD_PCS,
160 PCS_FW_PRODUCT_CODE_1 + i);
161 EFX_INFO(efx, "QT2025C firmware %xr%d v%d.%d.%d.%d [20%02d-%02d-%02d]\n",
162 (firmware_id[0] << 8) | firmware_id[1], firmware_id[2],
163 firmware_id[3] >> 4, firmware_id[3] & 0xf,
164 firmware_id[4], firmware_id[5],
165 firmware_id[6], firmware_id[7], firmware_id[8]);
166 phy_data->firmware_ver = ((firmware_id[3] & 0xf0) << 20) |
167 ((firmware_id[3] & 0x0f) << 16) |
168 (firmware_id[4] << 8) | firmware_id[5];
169}
170
Matthew Slattery17d6aea2009-12-23 13:47:37 +0000171static void qt2025c_bug17190_workaround(struct efx_nic *efx)
172{
173 struct qt202x_phy_data *phy_data = efx->phy_data;
174
175 /* The PHY can get stuck in a state where it reports PHY_XS and PMA/PMD
176 * layers up, but PCS down (no block_lock). If we notice this state
177 * persisting for a couple of seconds, we switch PMA/PMD loopback
178 * briefly on and then off again, which is normally sufficient to
179 * recover it.
180 */
181 if (efx->link_state.up ||
182 !efx_mdio_links_ok(efx, MDIO_DEVS_PMAPMD | MDIO_DEVS_PHYXS)) {
183 phy_data->bug17190_in_bad_state = false;
184 return;
185 }
186
187 if (!phy_data->bug17190_in_bad_state) {
188 phy_data->bug17190_in_bad_state = true;
189 phy_data->bug17190_timer = jiffies + BUG17190_INTERVAL;
190 return;
191 }
192
193 if (time_after_eq(jiffies, phy_data->bug17190_timer)) {
194 EFX_LOG(efx, "bashing QT2025C PMA/PMD\n");
195 efx_mdio_set_flag(efx, MDIO_MMD_PMAPMD, MDIO_CTRL1,
196 MDIO_PMA_CTRL1_LOOPBACK, true);
197 msleep(100);
198 efx_mdio_set_flag(efx, MDIO_MMD_PMAPMD, MDIO_CTRL1,
199 MDIO_PMA_CTRL1_LOOPBACK, false);
200 phy_data->bug17190_timer = jiffies + BUG17190_INTERVAL;
201 }
202}
203
Matthew Slattery0d83b2f2009-12-23 13:48:04 +0000204static int qt2025c_select_phy_mode(struct efx_nic *efx)
205{
206 struct qt202x_phy_data *phy_data = efx->phy_data;
207 struct falcon_board *board = falcon_board(efx);
208 int reg, rc, i;
209 uint16_t phy_op_mode;
210
211 /* Only 2.0.1.0+ PHY firmware supports the more optimal SFP+
212 * Self-Configure mode. Don't attempt any switching if we encounter
213 * older firmware. */
214 if (phy_data->firmware_ver < 0x02000100)
215 return 0;
216
217 /* In general we will get optimal behaviour in "SFP+ Self-Configure"
218 * mode; however, that powers down most of the PHY when no module is
219 * present, so we must use a different mode (any fixed mode will do)
220 * to be sure that loopbacks will work. */
221 phy_op_mode = (efx->loopback_mode == LOOPBACK_NONE) ? 0x0038 : 0x0020;
222
223 /* Only change mode if really necessary */
224 reg = efx_mdio_read(efx, 1, 0xc319);
225 if ((reg & 0x0038) == phy_op_mode)
226 return 0;
227 EFX_LOG(efx, "Switching PHY to mode 0x%04x\n", phy_op_mode);
228
229 /* This sequence replicates the register writes configured in the boot
230 * EEPROM (including the differences between board revisions), except
231 * that the operating mode is changed, and the PHY is prevented from
232 * unnecessarily reloading the main firmware image again. */
233 efx_mdio_write(efx, 1, 0xc300, 0x0000);
234 /* (Note: this portion of the boot EEPROM sequence, which bit-bashes 9
235 * STOPs onto the firmware/module I2C bus to reset it, varies across
236 * board revisions, as the bus is connected to different GPIO/LED
237 * outputs on the PHY.) */
238 if (board->major == 0 && board->minor < 2) {
239 efx_mdio_write(efx, 1, 0xc303, 0x4498);
240 for (i = 0; i < 9; i++) {
241 efx_mdio_write(efx, 1, 0xc303, 0x4488);
242 efx_mdio_write(efx, 1, 0xc303, 0x4480);
243 efx_mdio_write(efx, 1, 0xc303, 0x4490);
244 efx_mdio_write(efx, 1, 0xc303, 0x4498);
245 }
246 } else {
247 efx_mdio_write(efx, 1, 0xc303, 0x0920);
248 efx_mdio_write(efx, 1, 0xd008, 0x0004);
249 for (i = 0; i < 9; i++) {
250 efx_mdio_write(efx, 1, 0xc303, 0x0900);
251 efx_mdio_write(efx, 1, 0xd008, 0x0005);
252 efx_mdio_write(efx, 1, 0xc303, 0x0920);
253 efx_mdio_write(efx, 1, 0xd008, 0x0004);
254 }
255 efx_mdio_write(efx, 1, 0xc303, 0x4900);
256 }
257 efx_mdio_write(efx, 1, 0xc303, 0x4900);
258 efx_mdio_write(efx, 1, 0xc302, 0x0004);
259 efx_mdio_write(efx, 1, 0xc316, 0x0013);
260 efx_mdio_write(efx, 1, 0xc318, 0x0054);
261 efx_mdio_write(efx, 1, 0xc319, phy_op_mode);
262 efx_mdio_write(efx, 1, 0xc31a, 0x0098);
263 efx_mdio_write(efx, 3, 0x0026, 0x0e00);
264 efx_mdio_write(efx, 3, 0x0027, 0x0013);
265 efx_mdio_write(efx, 3, 0x0028, 0xa528);
266 efx_mdio_write(efx, 1, 0xd006, 0x000a);
267 efx_mdio_write(efx, 1, 0xd007, 0x0009);
268 efx_mdio_write(efx, 1, 0xd008, 0x0004);
269 /* This additional write is not present in the boot EEPROM. It
270 * prevents the PHY's internal boot ROM doing another pointless (and
271 * slow) reload of the firmware image (the microcontroller's code
272 * memory is not affected by the microcontroller reset). */
273 efx_mdio_write(efx, 1, 0xc317, 0x00ff);
274 efx_mdio_write(efx, 1, 0xc300, 0x0002);
275 msleep(20);
276
Matthew Slattery1a1284e2009-12-23 13:48:32 +0000277 /* Restart microcontroller execution of firmware from RAM */
278 qt2025c_restart_firmware(efx);
Matthew Slattery0d83b2f2009-12-23 13:48:04 +0000279
280 /* Wait for the microcontroller to be ready again */
281 rc = qt2025c_wait_reset(efx);
282 if (rc < 0) {
283 EFX_ERR(efx, "PHY microcontroller reset during mode switch "
284 "timed out\n");
285 return rc;
286 }
287
288 return 0;
289}
290
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000291static int qt202x_reset_phy(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100292{
293 int rc;
294
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000295 if (efx->phy_type == PHY_TYPE_QT2025C) {
Ben Hutchings5afaa752009-08-26 08:17:19 +0000296 /* Wait for the reset triggered by falcon_reset_hw()
297 * to complete */
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000298 rc = qt2025c_wait_reset(efx);
299 if (rc < 0)
300 goto fail;
Ben Hutchings5afaa752009-08-26 08:17:19 +0000301 } else {
302 /* Reset the PHYXS MMD. This is documented as doing
303 * a complete soft reset. */
304 rc = efx_mdio_reset_mmd(efx, MDIO_MMD_PHYXS,
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000305 QT2022C2_MAX_RESET_TIME /
306 QT2022C2_RESET_WAIT,
307 QT2022C2_RESET_WAIT);
Ben Hutchings5afaa752009-08-26 08:17:19 +0000308 if (rc < 0)
309 goto fail;
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000310 }
311
Ben Hutchings8ceee662008-04-27 12:55:59 +0100312 /* Wait 250ms for the PHY to complete bootup */
313 msleep(250);
314
315 /* Check that all the MMDs we expect are present and responding. We
316 * expect faults on some if the link is down, but not on the PHY XS */
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000317 rc = efx_mdio_check_mmds(efx, QT202X_REQUIRED_DEVS, MDIO_DEVS_PHYXS);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100318 if (rc < 0)
319 goto fail;
320
Ben Hutchings44838a42009-11-25 16:09:41 +0000321 falcon_board(efx)->type->init_phy(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100322
323 return rc;
324
325 fail:
Ben Hutchingsf794fd42009-02-27 13:06:58 +0000326 EFX_ERR(efx, "PHY reset timed out\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100327 return rc;
328}
329
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000330static int qt202x_phy_probe(struct efx_nic *efx)
331{
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000332 struct qt202x_phy_data *phy_data;
333
334 phy_data = kzalloc(sizeof(struct qt202x_phy_data), GFP_KERNEL);
335 if (!phy_data)
336 return -ENOMEM;
337 efx->phy_data = phy_data;
338 phy_data->phy_mode = efx->phy_mode;
Matthew Slattery17d6aea2009-12-23 13:47:37 +0000339 phy_data->bug17190_in_bad_state = false;
340 phy_data->bug17190_timer = 0;
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000341
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000342 efx->mdio.mmds = QT202X_REQUIRED_DEVS;
343 efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
344 efx->loopback_modes = QT202X_LOOPBACKS | FALCON_XMAC_LOOPBACKS;
345 return 0;
346}
347
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000348static int qt202x_phy_init(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100349{
Steve Hodgson47c3d192009-11-28 05:34:29 +0000350 u32 devid;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100351 int rc;
352
Steve Hodgson47c3d192009-11-28 05:34:29 +0000353 rc = qt202x_reset_phy(efx);
354 if (rc) {
355 EFX_ERR(efx, "PHY init failed\n");
356 return rc;
357 }
358
Steve Hodgson47c3d192009-11-28 05:34:29 +0000359 devid = efx_mdio_read_id(efx, MDIO_MMD_PHYXS);
Ben Hutchings3f39a5e2009-02-27 13:07:15 +0000360 EFX_INFO(efx, "PHY ID reg %x (OUI %06x model %02x revision %x)\n",
Ben Hutchings68e7f452009-04-29 08:05:08 +0000361 devid, efx_mdio_id_oui(devid), efx_mdio_id_model(devid),
362 efx_mdio_id_rev(devid));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100363
Matthew Slattery0d83b2f2009-12-23 13:48:04 +0000364 if (efx->phy_type == PHY_TYPE_QT2025C)
365 qt2025c_firmware_id(efx);
366
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100367 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100368}
369
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000370static int qt202x_link_ok(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100371{
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000372 return efx_mdio_links_ok(efx, QT202X_REQUIRED_DEVS);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100373}
374
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000375static bool qt202x_phy_poll(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100376{
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000377 bool was_up = efx->link_state.up;
378
379 efx->link_state.up = qt202x_link_ok(efx);
380 efx->link_state.speed = 10000;
381 efx->link_state.fd = true;
382 efx->link_state.fc = efx->wanted_fc;
383
Matthew Slattery17d6aea2009-12-23 13:47:37 +0000384 if (efx->phy_type == PHY_TYPE_QT2025C)
385 qt2025c_bug17190_workaround(efx);
386
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000387 return efx->link_state.up != was_up;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100388}
389
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000390static int qt202x_phy_reconfigure(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100391{
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000392 struct qt202x_phy_data *phy_data = efx->phy_data;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100393
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000394 if (efx->phy_type == PHY_TYPE_QT2025C) {
Matthew Slattery0d83b2f2009-12-23 13:48:04 +0000395 int rc = qt2025c_select_phy_mode(efx);
396 if (rc)
397 return rc;
398
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000399 /* There are several different register bits which can
400 * disable TX (and save power) on direct-attach cables
401 * or optical transceivers, varying somewhat between
402 * firmware versions. Only 'static mode' appears to
403 * cover everything. */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000404 mdio_set_flag(
405 &efx->mdio, efx->mdio.prtad, MDIO_MMD_PMAPMD,
406 PMA_PMD_FTX_CTRL2_REG, 1 << PMA_PMD_FTX_STATIC_LBN,
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000407 efx->phy_mode & PHY_MODE_TX_DISABLED ||
408 efx->phy_mode & PHY_MODE_LOW_POWER ||
409 efx->loopback_mode == LOOPBACK_PCS ||
410 efx->loopback_mode == LOOPBACK_PMAPMD);
411 } else {
412 /* Reset the PHY when moving from tx off to tx on */
413 if (!(efx->phy_mode & PHY_MODE_TX_DISABLED) &&
414 (phy_data->phy_mode & PHY_MODE_TX_DISABLED))
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000415 qt202x_reset_phy(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100416
Ben Hutchings68e7f452009-04-29 08:05:08 +0000417 efx_mdio_transmit_disable(efx);
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000418 }
419
Ben Hutchings68e7f452009-04-29 08:05:08 +0000420 efx_mdio_phy_reconfigure(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100421
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100422 phy_data->phy_mode = efx->phy_mode;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000423
424 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100425}
426
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000427static void qt202x_phy_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
Ben Hutchings68e7f452009-04-29 08:05:08 +0000428{
429 mdio45_ethtool_gset(&efx->mdio, ecmd);
430}
Ben Hutchings8ceee662008-04-27 12:55:59 +0100431
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000432static void qt202x_phy_remove(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100433{
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100434 /* Free the context block */
435 kfree(efx->phy_data);
436 efx->phy_data = NULL;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100437}
438
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000439struct efx_phy_operations falcon_qt202x_phy_ops = {
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000440 .probe = qt202x_phy_probe,
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000441 .init = qt202x_phy_init,
442 .reconfigure = qt202x_phy_reconfigure,
443 .poll = qt202x_phy_poll,
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000444 .fini = efx_port_dummy_op_void,
445 .remove = qt202x_phy_remove,
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000446 .get_settings = qt202x_phy_get_settings,
Ben Hutchings68e7f452009-04-29 08:05:08 +0000447 .set_settings = efx_mdio_set_settings,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100448};