blob: 68813d1d85f30eaac48648b7bb42b6e32ecaa34e [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
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Ben Hutchings8ceee662008-04-27 12:55:59 +010014#include <linux/timer.h>
15#include <linux/delay.h>
16#include "efx.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010017#include "mdio_10g.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010018#include "phy.h"
Ben Hutchings744093c2009-11-29 15:12:08 +000019#include "nic.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010020
Ben Hutchingsb37b62f2009-10-23 08:33:42 +000021#define QT202X_REQUIRED_DEVS (MDIO_DEVS_PCS | \
22 MDIO_DEVS_PMAPMD | \
23 MDIO_DEVS_PHYXS)
Ben Hutchings8ceee662008-04-27 12:55:59 +010024
Ben Hutchingsb37b62f2009-10-23 08:33:42 +000025#define QT202X_LOOPBACKS ((1 << LOOPBACK_PCS) | \
26 (1 << LOOPBACK_PMAPMD) | \
Ben Hutchingse58f69f2009-11-29 15:08:41 +000027 (1 << LOOPBACK_PHYXS_WS))
Ben Hutchings3273c2e2008-05-07 13:36:19 +010028
Ben Hutchings8ceee662008-04-27 12:55:59 +010029/****************************************************************************/
30/* Quake-specific MDIO registers */
31#define MDIO_QUAKE_LED0_REG (0xD006)
32
Ben Hutchingsd2d2c372009-02-27 13:07:33 +000033/* QT2025C only */
34#define PCS_FW_HEARTBEAT_REG 0xd7ee
35#define PCS_FW_HEARTB_LBN 0
36#define PCS_FW_HEARTB_WIDTH 8
Matthew Slattery0d83b2f2009-12-23 13:48:04 +000037#define PCS_FW_PRODUCT_CODE_1 0xd7f0
38#define PCS_FW_VERSION_1 0xd7f3
39#define PCS_FW_BUILD_1 0xd7f6
Ben Hutchingsd2d2c372009-02-27 13:07:33 +000040#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_FTX_CTRL2_REG 0xc309
45#define PMA_PMD_FTX_STATIC_LBN 13
46#define PMA_PMD_VEND1_REG 0xc001
47#define PMA_PMD_VEND1_LBTXD_LBN 15
48#define PCS_VEND1_REG 0xc000
49#define PCS_VEND1_LBTXD_LBN 5
50
Ben Hutchingsb37b62f2009-10-23 08:33:42 +000051void falcon_qt202x_set_led(struct efx_nic *p, int led, int mode)
Ben Hutchings8ceee662008-04-27 12:55:59 +010052{
53 int addr = MDIO_QUAKE_LED0_REG + led;
Ben Hutchings68e7f452009-04-29 08:05:08 +000054 efx_mdio_write(p, MDIO_MMD_PMAPMD, addr, mode);
Ben Hutchings8ceee662008-04-27 12:55:59 +010055}
56
Ben Hutchingsb37b62f2009-10-23 08:33:42 +000057struct qt202x_phy_data {
Ben Hutchingsf8b87c12008-09-01 12:48:17 +010058 enum efx_phy_mode phy_mode;
Matthew Slattery17d6aea2009-12-23 13:47:37 +000059 bool bug17190_in_bad_state;
60 unsigned long bug17190_timer;
Matthew Slattery0d83b2f2009-12-23 13:48:04 +000061 u32 firmware_ver;
Ben Hutchings3273c2e2008-05-07 13:36:19 +010062};
63
Ben Hutchingsb37b62f2009-10-23 08:33:42 +000064#define QT2022C2_MAX_RESET_TIME 500
65#define QT2022C2_RESET_WAIT 10
Ben Hutchings8ceee662008-04-27 12:55:59 +010066
Matthew Slattery1a1284e2009-12-23 13:48:32 +000067#define QT2025C_MAX_HEARTB_TIME (5 * HZ)
68#define QT2025C_HEARTB_WAIT 100
69#define QT2025C_MAX_FWSTART_TIME (25 * HZ / 10)
70#define QT2025C_FWSTART_WAIT 100
71
Matthew Slattery17d6aea2009-12-23 13:47:37 +000072#define BUG17190_INTERVAL (2 * HZ)
73
Matthew Slattery1a1284e2009-12-23 13:48:32 +000074static int qt2025c_wait_heartbeat(struct efx_nic *efx)
Ben Hutchingsd2d2c372009-02-27 13:07:33 +000075{
Matthew Slattery1a1284e2009-12-23 13:48:32 +000076 unsigned long timeout = jiffies + QT2025C_MAX_HEARTB_TIME;
Ben Hutchingsd2d2c372009-02-27 13:07:33 +000077 int reg, old_counter = 0;
78
79 /* Wait for firmware heartbeat to start */
80 for (;;) {
81 int counter;
Ben Hutchings68e7f452009-04-29 08:05:08 +000082 reg = efx_mdio_read(efx, MDIO_MMD_PCS, PCS_FW_HEARTBEAT_REG);
Ben Hutchingsd2d2c372009-02-27 13:07:33 +000083 if (reg < 0)
84 return reg;
85 counter = ((reg >> PCS_FW_HEARTB_LBN) &
86 ((1 << PCS_FW_HEARTB_WIDTH) - 1));
87 if (old_counter == 0)
88 old_counter = counter;
89 else if (counter != old_counter)
90 break;
Ben Hutchings50d6ec52009-12-23 13:48:42 +000091 if (time_after(jiffies, timeout)) {
92 /* Some cables have EEPROMs that conflict with the
93 * PHY's on-board EEPROM so it cannot load firmware */
Ben Hutchings62776d02010-06-23 11:30:07 +000094 netif_err(efx, hw, efx->net_dev,
95 "If an SFP+ direct attach cable is"
96 " connected, please check that it complies"
97 " with the SFP+ specification\n");
Ben Hutchingsd2d2c372009-02-27 13:07:33 +000098 return -ETIMEDOUT;
Ben Hutchings50d6ec52009-12-23 13:48:42 +000099 }
Matthew Slattery1a1284e2009-12-23 13:48:32 +0000100 msleep(QT2025C_HEARTB_WAIT);
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000101 }
102
Matthew Slattery1a1284e2009-12-23 13:48:32 +0000103 return 0;
104}
105
106static int qt2025c_wait_fw_status_good(struct efx_nic *efx)
107{
108 unsigned long timeout = jiffies + QT2025C_MAX_FWSTART_TIME;
109 int reg;
110
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000111 /* Wait for firmware status to look good */
112 for (;;) {
Ben Hutchings68e7f452009-04-29 08:05:08 +0000113 reg = efx_mdio_read(efx, MDIO_MMD_PCS, PCS_UC8051_STATUS_REG);
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000114 if (reg < 0)
115 return reg;
116 if ((reg &
117 ((1 << PCS_UC_STATUS_WIDTH) - 1) << PCS_UC_STATUS_LBN) >=
118 PCS_UC_STATUS_FW_SAVE)
119 break;
120 if (time_after(jiffies, timeout))
121 return -ETIMEDOUT;
Matthew Slattery1a1284e2009-12-23 13:48:32 +0000122 msleep(QT2025C_FWSTART_WAIT);
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000123 }
124
125 return 0;
126}
127
Matthew Slattery1a1284e2009-12-23 13:48:32 +0000128static void qt2025c_restart_firmware(struct efx_nic *efx)
129{
130 /* Restart microcontroller execution of firmware from RAM */
131 efx_mdio_write(efx, 3, 0xe854, 0x00c0);
132 efx_mdio_write(efx, 3, 0xe854, 0x0040);
133 msleep(50);
134}
135
136static int qt2025c_wait_reset(struct efx_nic *efx)
137{
138 int rc;
139
140 rc = qt2025c_wait_heartbeat(efx);
141 if (rc != 0)
142 return rc;
143
144 rc = qt2025c_wait_fw_status_good(efx);
145 if (rc == -ETIMEDOUT) {
146 /* Bug 17689: occasionally heartbeat starts but firmware status
147 * code never progresses beyond 0x00. Try again, once, after
148 * restarting execution of the firmware image. */
Ben Hutchings62776d02010-06-23 11:30:07 +0000149 netif_dbg(efx, hw, efx->net_dev,
150 "bashing QT2025C microcontroller\n");
Matthew Slattery1a1284e2009-12-23 13:48:32 +0000151 qt2025c_restart_firmware(efx);
152 rc = qt2025c_wait_heartbeat(efx);
153 if (rc != 0)
154 return rc;
155 rc = qt2025c_wait_fw_status_good(efx);
156 }
157
158 return rc;
159}
160
Matthew Slattery0d83b2f2009-12-23 13:48:04 +0000161static void qt2025c_firmware_id(struct efx_nic *efx)
162{
163 struct qt202x_phy_data *phy_data = efx->phy_data;
164 u8 firmware_id[9];
165 size_t i;
166
167 for (i = 0; i < sizeof(firmware_id); i++)
168 firmware_id[i] = efx_mdio_read(efx, MDIO_MMD_PCS,
169 PCS_FW_PRODUCT_CODE_1 + i);
Ben Hutchings62776d02010-06-23 11:30:07 +0000170 netif_info(efx, probe, efx->net_dev,
171 "QT2025C firmware %xr%d v%d.%d.%d.%d [20%02d-%02d-%02d]\n",
172 (firmware_id[0] << 8) | firmware_id[1], firmware_id[2],
173 firmware_id[3] >> 4, firmware_id[3] & 0xf,
174 firmware_id[4], firmware_id[5],
175 firmware_id[6], firmware_id[7], firmware_id[8]);
Matthew Slattery0d83b2f2009-12-23 13:48:04 +0000176 phy_data->firmware_ver = ((firmware_id[3] & 0xf0) << 20) |
177 ((firmware_id[3] & 0x0f) << 16) |
178 (firmware_id[4] << 8) | firmware_id[5];
179}
180
Matthew Slattery17d6aea2009-12-23 13:47:37 +0000181static void qt2025c_bug17190_workaround(struct efx_nic *efx)
182{
183 struct qt202x_phy_data *phy_data = efx->phy_data;
184
185 /* The PHY can get stuck in a state where it reports PHY_XS and PMA/PMD
186 * layers up, but PCS down (no block_lock). If we notice this state
187 * persisting for a couple of seconds, we switch PMA/PMD loopback
188 * briefly on and then off again, which is normally sufficient to
189 * recover it.
190 */
191 if (efx->link_state.up ||
192 !efx_mdio_links_ok(efx, MDIO_DEVS_PMAPMD | MDIO_DEVS_PHYXS)) {
193 phy_data->bug17190_in_bad_state = false;
194 return;
195 }
196
197 if (!phy_data->bug17190_in_bad_state) {
198 phy_data->bug17190_in_bad_state = true;
199 phy_data->bug17190_timer = jiffies + BUG17190_INTERVAL;
200 return;
201 }
202
203 if (time_after_eq(jiffies, phy_data->bug17190_timer)) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000204 netif_dbg(efx, hw, efx->net_dev, "bashing QT2025C PMA/PMD\n");
Matthew Slattery17d6aea2009-12-23 13:47:37 +0000205 efx_mdio_set_flag(efx, MDIO_MMD_PMAPMD, MDIO_CTRL1,
206 MDIO_PMA_CTRL1_LOOPBACK, true);
207 msleep(100);
208 efx_mdio_set_flag(efx, MDIO_MMD_PMAPMD, MDIO_CTRL1,
209 MDIO_PMA_CTRL1_LOOPBACK, false);
210 phy_data->bug17190_timer = jiffies + BUG17190_INTERVAL;
211 }
212}
213
Matthew Slattery0d83b2f2009-12-23 13:48:04 +0000214static int qt2025c_select_phy_mode(struct efx_nic *efx)
215{
216 struct qt202x_phy_data *phy_data = efx->phy_data;
217 struct falcon_board *board = falcon_board(efx);
218 int reg, rc, i;
219 uint16_t phy_op_mode;
220
221 /* Only 2.0.1.0+ PHY firmware supports the more optimal SFP+
222 * Self-Configure mode. Don't attempt any switching if we encounter
223 * older firmware. */
224 if (phy_data->firmware_ver < 0x02000100)
225 return 0;
226
227 /* In general we will get optimal behaviour in "SFP+ Self-Configure"
228 * mode; however, that powers down most of the PHY when no module is
229 * present, so we must use a different mode (any fixed mode will do)
230 * to be sure that loopbacks will work. */
231 phy_op_mode = (efx->loopback_mode == LOOPBACK_NONE) ? 0x0038 : 0x0020;
232
233 /* Only change mode if really necessary */
234 reg = efx_mdio_read(efx, 1, 0xc319);
235 if ((reg & 0x0038) == phy_op_mode)
236 return 0;
Ben Hutchings62776d02010-06-23 11:30:07 +0000237 netif_dbg(efx, hw, efx->net_dev, "Switching PHY to mode 0x%04x\n",
238 phy_op_mode);
Matthew Slattery0d83b2f2009-12-23 13:48:04 +0000239
240 /* This sequence replicates the register writes configured in the boot
241 * EEPROM (including the differences between board revisions), except
242 * that the operating mode is changed, and the PHY is prevented from
243 * unnecessarily reloading the main firmware image again. */
244 efx_mdio_write(efx, 1, 0xc300, 0x0000);
245 /* (Note: this portion of the boot EEPROM sequence, which bit-bashes 9
246 * STOPs onto the firmware/module I2C bus to reset it, varies across
247 * board revisions, as the bus is connected to different GPIO/LED
248 * outputs on the PHY.) */
249 if (board->major == 0 && board->minor < 2) {
250 efx_mdio_write(efx, 1, 0xc303, 0x4498);
251 for (i = 0; i < 9; i++) {
252 efx_mdio_write(efx, 1, 0xc303, 0x4488);
253 efx_mdio_write(efx, 1, 0xc303, 0x4480);
254 efx_mdio_write(efx, 1, 0xc303, 0x4490);
255 efx_mdio_write(efx, 1, 0xc303, 0x4498);
256 }
257 } else {
258 efx_mdio_write(efx, 1, 0xc303, 0x0920);
259 efx_mdio_write(efx, 1, 0xd008, 0x0004);
260 for (i = 0; i < 9; i++) {
261 efx_mdio_write(efx, 1, 0xc303, 0x0900);
262 efx_mdio_write(efx, 1, 0xd008, 0x0005);
263 efx_mdio_write(efx, 1, 0xc303, 0x0920);
264 efx_mdio_write(efx, 1, 0xd008, 0x0004);
265 }
266 efx_mdio_write(efx, 1, 0xc303, 0x4900);
267 }
268 efx_mdio_write(efx, 1, 0xc303, 0x4900);
269 efx_mdio_write(efx, 1, 0xc302, 0x0004);
270 efx_mdio_write(efx, 1, 0xc316, 0x0013);
271 efx_mdio_write(efx, 1, 0xc318, 0x0054);
272 efx_mdio_write(efx, 1, 0xc319, phy_op_mode);
273 efx_mdio_write(efx, 1, 0xc31a, 0x0098);
274 efx_mdio_write(efx, 3, 0x0026, 0x0e00);
275 efx_mdio_write(efx, 3, 0x0027, 0x0013);
276 efx_mdio_write(efx, 3, 0x0028, 0xa528);
277 efx_mdio_write(efx, 1, 0xd006, 0x000a);
278 efx_mdio_write(efx, 1, 0xd007, 0x0009);
279 efx_mdio_write(efx, 1, 0xd008, 0x0004);
280 /* This additional write is not present in the boot EEPROM. It
281 * prevents the PHY's internal boot ROM doing another pointless (and
282 * slow) reload of the firmware image (the microcontroller's code
283 * memory is not affected by the microcontroller reset). */
284 efx_mdio_write(efx, 1, 0xc317, 0x00ff);
285 efx_mdio_write(efx, 1, 0xc300, 0x0002);
286 msleep(20);
287
Matthew Slattery1a1284e2009-12-23 13:48:32 +0000288 /* Restart microcontroller execution of firmware from RAM */
289 qt2025c_restart_firmware(efx);
Matthew Slattery0d83b2f2009-12-23 13:48:04 +0000290
291 /* Wait for the microcontroller to be ready again */
292 rc = qt2025c_wait_reset(efx);
293 if (rc < 0) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000294 netif_err(efx, hw, efx->net_dev,
295 "PHY microcontroller reset during mode switch "
296 "timed out\n");
Matthew Slattery0d83b2f2009-12-23 13:48:04 +0000297 return rc;
298 }
299
300 return 0;
301}
302
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000303static int qt202x_reset_phy(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100304{
305 int rc;
306
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000307 if (efx->phy_type == PHY_TYPE_QT2025C) {
Ben Hutchings5afaa752009-08-26 08:17:19 +0000308 /* Wait for the reset triggered by falcon_reset_hw()
309 * to complete */
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000310 rc = qt2025c_wait_reset(efx);
311 if (rc < 0)
312 goto fail;
Ben Hutchings5afaa752009-08-26 08:17:19 +0000313 } else {
314 /* Reset the PHYXS MMD. This is documented as doing
315 * a complete soft reset. */
316 rc = efx_mdio_reset_mmd(efx, MDIO_MMD_PHYXS,
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000317 QT2022C2_MAX_RESET_TIME /
318 QT2022C2_RESET_WAIT,
319 QT2022C2_RESET_WAIT);
Ben Hutchings5afaa752009-08-26 08:17:19 +0000320 if (rc < 0)
321 goto fail;
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000322 }
323
Ben Hutchings8ceee662008-04-27 12:55:59 +0100324 /* Wait 250ms for the PHY to complete bootup */
325 msleep(250);
326
Ben Hutchings44838a42009-11-25 16:09:41 +0000327 falcon_board(efx)->type->init_phy(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100328
Steve Hodgson5e2a9112010-02-12 12:32:27 -0800329 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100330
331 fail:
Ben Hutchings62776d02010-06-23 11:30:07 +0000332 netif_err(efx, hw, efx->net_dev, "PHY reset timed out\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100333 return rc;
334}
335
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000336static int qt202x_phy_probe(struct efx_nic *efx)
337{
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000338 struct qt202x_phy_data *phy_data;
339
340 phy_data = kzalloc(sizeof(struct qt202x_phy_data), GFP_KERNEL);
341 if (!phy_data)
342 return -ENOMEM;
343 efx->phy_data = phy_data;
344 phy_data->phy_mode = efx->phy_mode;
Matthew Slattery17d6aea2009-12-23 13:47:37 +0000345 phy_data->bug17190_in_bad_state = false;
346 phy_data->bug17190_timer = 0;
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000347
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000348 efx->mdio.mmds = QT202X_REQUIRED_DEVS;
349 efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
350 efx->loopback_modes = QT202X_LOOPBACKS | FALCON_XMAC_LOOPBACKS;
351 return 0;
352}
353
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000354static int qt202x_phy_init(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100355{
Steve Hodgson47c3d192009-11-28 05:34:29 +0000356 u32 devid;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100357 int rc;
358
Steve Hodgson47c3d192009-11-28 05:34:29 +0000359 rc = qt202x_reset_phy(efx);
360 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000361 netif_err(efx, probe, efx->net_dev, "PHY init failed\n");
Steve Hodgson47c3d192009-11-28 05:34:29 +0000362 return rc;
363 }
364
Steve Hodgson47c3d192009-11-28 05:34:29 +0000365 devid = efx_mdio_read_id(efx, MDIO_MMD_PHYXS);
Ben Hutchings62776d02010-06-23 11:30:07 +0000366 netif_info(efx, probe, efx->net_dev,
367 "PHY ID reg %x (OUI %06x model %02x revision %x)\n",
368 devid, efx_mdio_id_oui(devid), efx_mdio_id_model(devid),
369 efx_mdio_id_rev(devid));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100370
Matthew Slattery0d83b2f2009-12-23 13:48:04 +0000371 if (efx->phy_type == PHY_TYPE_QT2025C)
372 qt2025c_firmware_id(efx);
373
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100374 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100375}
376
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000377static int qt202x_link_ok(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100378{
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000379 return efx_mdio_links_ok(efx, QT202X_REQUIRED_DEVS);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100380}
381
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000382static bool qt202x_phy_poll(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100383{
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000384 bool was_up = efx->link_state.up;
385
386 efx->link_state.up = qt202x_link_ok(efx);
387 efx->link_state.speed = 10000;
388 efx->link_state.fd = true;
389 efx->link_state.fc = efx->wanted_fc;
390
Matthew Slattery17d6aea2009-12-23 13:47:37 +0000391 if (efx->phy_type == PHY_TYPE_QT2025C)
392 qt2025c_bug17190_workaround(efx);
393
Steve Hodgsonfdaa9ae2009-11-28 05:34:05 +0000394 return efx->link_state.up != was_up;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100395}
396
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000397static int qt202x_phy_reconfigure(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100398{
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000399 struct qt202x_phy_data *phy_data = efx->phy_data;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100400
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000401 if (efx->phy_type == PHY_TYPE_QT2025C) {
Matthew Slattery0d83b2f2009-12-23 13:48:04 +0000402 int rc = qt2025c_select_phy_mode(efx);
403 if (rc)
404 return rc;
405
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000406 /* There are several different register bits which can
407 * disable TX (and save power) on direct-attach cables
408 * or optical transceivers, varying somewhat between
409 * firmware versions. Only 'static mode' appears to
410 * cover everything. */
Ben Hutchings68e7f452009-04-29 08:05:08 +0000411 mdio_set_flag(
412 &efx->mdio, efx->mdio.prtad, MDIO_MMD_PMAPMD,
413 PMA_PMD_FTX_CTRL2_REG, 1 << PMA_PMD_FTX_STATIC_LBN,
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000414 efx->phy_mode & PHY_MODE_TX_DISABLED ||
415 efx->phy_mode & PHY_MODE_LOW_POWER ||
416 efx->loopback_mode == LOOPBACK_PCS ||
417 efx->loopback_mode == LOOPBACK_PMAPMD);
418 } else {
419 /* Reset the PHY when moving from tx off to tx on */
420 if (!(efx->phy_mode & PHY_MODE_TX_DISABLED) &&
421 (phy_data->phy_mode & PHY_MODE_TX_DISABLED))
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000422 qt202x_reset_phy(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100423
Ben Hutchings68e7f452009-04-29 08:05:08 +0000424 efx_mdio_transmit_disable(efx);
Ben Hutchingsd2d2c372009-02-27 13:07:33 +0000425 }
426
Ben Hutchings68e7f452009-04-29 08:05:08 +0000427 efx_mdio_phy_reconfigure(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100428
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100429 phy_data->phy_mode = efx->phy_mode;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000430
431 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100432}
433
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000434static void qt202x_phy_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
Ben Hutchings68e7f452009-04-29 08:05:08 +0000435{
436 mdio45_ethtool_gset(&efx->mdio, ecmd);
437}
Ben Hutchings8ceee662008-04-27 12:55:59 +0100438
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000439static void qt202x_phy_remove(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100440{
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100441 /* Free the context block */
442 kfree(efx->phy_data);
443 efx->phy_data = NULL;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100444}
445
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000446struct efx_phy_operations falcon_qt202x_phy_ops = {
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000447 .probe = qt202x_phy_probe,
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000448 .init = qt202x_phy_init,
449 .reconfigure = qt202x_phy_reconfigure,
450 .poll = qt202x_phy_poll,
Steve Hodgsonff3b00a2009-12-23 13:46:36 +0000451 .fini = efx_port_dummy_op_void,
452 .remove = qt202x_phy_remove,
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000453 .get_settings = qt202x_phy_get_settings,
Ben Hutchings68e7f452009-04-29 08:05:08 +0000454 .set_settings = efx_mdio_set_settings,
Ben Hutchings4f16c072010-02-03 09:30:50 +0000455 .test_alive = efx_mdio_test_alive,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100456};