blob: c7c95db2af6da76968a552240dfce214ce63c86f [file] [log] [blame]
Ben Hutchings8ceee662008-04-27 12:55:59 +01001/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
Ben Hutchings6f158d52008-12-12 22:00:49 -08003 * Copyright 2007-2008 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
10/*****************************************************************************
Ben Hutchings6f158d52008-12-12 22:00:49 -080011 * Support for the SFE4001 and SFN4111T NICs.
12 *
13 * The SFE4001 does not power-up fully at reset due to its high power
14 * consumption. We control its power via a PCA9539 I/O expander.
15 * Both boards have a MAX6647 temperature monitor which we expose to
16 * the lm90 driver.
17 *
18 * This also provides minimal support for reflashing the PHY, which is
19 * initiated by resetting it with the FLASH_CFG_1 pin pulled down.
20 * On SFE4001 rev A2 and later this is connected to the 3V3X output of
21 * the IO-expander; on the SFN4111T it is connected to Falcon's GPIO3.
22 * We represent reflash mode as PHY_MODE_SPECIAL and make it mutually
23 * exclusive with the network device being open.
Ben Hutchings8ceee662008-04-27 12:55:59 +010024 */
Ben Hutchings6f158d52008-12-12 22:00:49 -080025
Ben Hutchings8ceee662008-04-27 12:55:59 +010026#include <linux/delay.h>
Ben Hutchingsf8b87c12008-09-01 12:48:17 +010027#include "net_driver.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010028#include "efx.h"
29#include "phy.h"
30#include "boards.h"
31#include "falcon.h"
32#include "falcon_hwdefs.h"
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +010033#include "falcon_io.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010034#include "mac.h"
Ben Hutchings3e133c42008-11-04 20:34:56 +000035#include "workarounds.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010036
37/**************************************************************************
38 *
39 * I2C IO Expander device
40 *
41 **************************************************************************/
42#define PCA9539 0x74
43
44#define P0_IN 0x00
45#define P0_OUT 0x02
46#define P0_INVERT 0x04
47#define P0_CONFIG 0x06
48
49#define P0_EN_1V0X_LBN 0
50#define P0_EN_1V0X_WIDTH 1
51#define P0_EN_1V2_LBN 1
52#define P0_EN_1V2_WIDTH 1
53#define P0_EN_2V5_LBN 2
54#define P0_EN_2V5_WIDTH 1
55#define P0_EN_3V3X_LBN 3
56#define P0_EN_3V3X_WIDTH 1
57#define P0_EN_5V_LBN 4
58#define P0_EN_5V_WIDTH 1
59#define P0_SHORTEN_JTAG_LBN 5
60#define P0_SHORTEN_JTAG_WIDTH 1
61#define P0_X_TRST_LBN 6
62#define P0_X_TRST_WIDTH 1
63#define P0_DSP_RESET_LBN 7
64#define P0_DSP_RESET_WIDTH 1
65
66#define P1_IN 0x01
67#define P1_OUT 0x03
68#define P1_INVERT 0x05
69#define P1_CONFIG 0x07
70
71#define P1_AFE_PWD_LBN 0
72#define P1_AFE_PWD_WIDTH 1
73#define P1_DSP_PWD25_LBN 1
74#define P1_DSP_PWD25_WIDTH 1
75#define P1_RESERVED_LBN 2
76#define P1_RESERVED_WIDTH 2
77#define P1_SPARE_LBN 4
78#define P1_SPARE_WIDTH 4
79
Ben Hutchings3e133c42008-11-04 20:34:56 +000080/* Temperature Sensor */
81#define MAX664X_REG_RSL 0x02
82#define MAX664X_REG_WLHO 0x0B
Ben Hutchings8ceee662008-04-27 12:55:59 +010083
Ben Hutchings37b5a602008-05-30 22:27:04 +010084static void sfe4001_poweroff(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +010085{
Ben Hutchings37b5a602008-05-30 22:27:04 +010086 struct i2c_client *ioexp_client = efx->board_info.ioexp_client;
87 struct i2c_client *hwmon_client = efx->board_info.hwmon_client;
Ben Hutchings8ceee662008-04-27 12:55:59 +010088
Ben Hutchings37b5a602008-05-30 22:27:04 +010089 /* Turn off all power rails and disable outputs */
90 i2c_smbus_write_byte_data(ioexp_client, P0_OUT, 0xff);
91 i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG, 0xff);
92 i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0xff);
Ben Hutchings8ceee662008-04-27 12:55:59 +010093
94 /* Clear any over-temperature alert */
Ben Hutchings3e133c42008-11-04 20:34:56 +000095 i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
Ben Hutchings37b5a602008-05-30 22:27:04 +010096}
97
Ben Hutchingsf8b87c12008-09-01 12:48:17 +010098static int sfe4001_poweron(struct efx_nic *efx)
Ben Hutchings37b5a602008-05-30 22:27:04 +010099{
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100100 struct i2c_client *hwmon_client = efx->board_info.hwmon_client;
101 struct i2c_client *ioexp_client = efx->board_info.ioexp_client;
Ben Hutchings11f34e62008-09-01 12:45:48 +0100102 unsigned int i, j;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100103 int rc;
Ben Hutchings37b5a602008-05-30 22:27:04 +0100104 u8 out;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100105
Ben Hutchings8ceee662008-04-27 12:55:59 +0100106 /* Clear any previous over-temperature alert */
Ben Hutchings3e133c42008-11-04 20:34:56 +0000107 rc = i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
Ben Hutchings37b5a602008-05-30 22:27:04 +0100108 if (rc < 0)
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100109 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100110
111 /* Enable port 0 and port 1 outputs on IO expander */
Ben Hutchings37b5a602008-05-30 22:27:04 +0100112 rc = i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0x00);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100113 if (rc)
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100114 return rc;
Ben Hutchings37b5a602008-05-30 22:27:04 +0100115 rc = i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG,
116 0xff & ~(1 << P1_SPARE_LBN));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100117 if (rc)
Ben Hutchings37b5a602008-05-30 22:27:04 +0100118 goto fail_on;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100119
Ben Hutchings11f34e62008-09-01 12:45:48 +0100120 /* If PHY power is on, turn it all off and wait 1 second to
121 * ensure a full reset.
122 */
123 rc = i2c_smbus_read_byte_data(ioexp_client, P0_OUT);
124 if (rc < 0)
125 goto fail_on;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100126 out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
127 (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
128 (0 << P0_EN_1V0X_LBN));
Ben Hutchings11f34e62008-09-01 12:45:48 +0100129 if (rc != out) {
130 EFX_INFO(efx, "power-cycling PHY\n");
131 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
132 if (rc)
133 goto fail_on;
134 schedule_timeout_uninterruptible(HZ);
135 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100136
Ben Hutchings11f34e62008-09-01 12:45:48 +0100137 for (i = 0; i < 20; ++i) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100138 /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
139 out = 0xff & ~((1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
140 (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
141 (1 << P0_X_TRST_LBN));
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100142 if (efx->phy_mode & PHY_MODE_SPECIAL)
Ben Hutchings75f2d3e2008-05-07 12:55:13 +0100143 out |= 1 << P0_EN_3V3X_LBN;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100144
Ben Hutchings37b5a602008-05-30 22:27:04 +0100145 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100146 if (rc)
Ben Hutchings37b5a602008-05-30 22:27:04 +0100147 goto fail_on;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100148 msleep(10);
149
150 /* Turn on 1V power rail */
151 out &= ~(1 << P0_EN_1V0X_LBN);
Ben Hutchings37b5a602008-05-30 22:27:04 +0100152 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100153 if (rc)
Ben Hutchings37b5a602008-05-30 22:27:04 +0100154 goto fail_on;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100155
Ben Hutchings11f34e62008-09-01 12:45:48 +0100156 EFX_INFO(efx, "waiting for DSP boot (attempt %d)...\n", i);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100157
Ben Hutchings11f34e62008-09-01 12:45:48 +0100158 /* In flash config mode, DSP does not turn on AFE, so
159 * just wait 1 second.
160 */
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100161 if (efx->phy_mode & PHY_MODE_SPECIAL) {
Ben Hutchings11f34e62008-09-01 12:45:48 +0100162 schedule_timeout_uninterruptible(HZ);
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100163 return 0;
Ben Hutchings11f34e62008-09-01 12:45:48 +0100164 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100165
Ben Hutchings11f34e62008-09-01 12:45:48 +0100166 for (j = 0; j < 10; ++j) {
167 msleep(100);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100168
Ben Hutchings11f34e62008-09-01 12:45:48 +0100169 /* Check DSP has asserted AFE power line */
170 rc = i2c_smbus_read_byte_data(ioexp_client, P1_IN);
171 if (rc < 0)
172 goto fail_on;
173 if (rc & (1 << P1_AFE_PWD_LBN))
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100174 return 0;
Ben Hutchings11f34e62008-09-01 12:45:48 +0100175 }
176 }
177
178 EFX_INFO(efx, "timed out waiting for DSP boot\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100179 rc = -ETIMEDOUT;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100180fail_on:
181 sfe4001_poweroff(efx);
182 return rc;
183}
Ben Hutchings8ceee662008-04-27 12:55:59 +0100184
Ben Hutchings6f158d52008-12-12 22:00:49 -0800185static int sfn4111t_reset(struct efx_nic *efx)
Ben Hutchings3e133c42008-11-04 20:34:56 +0000186{
Ben Hutchings6f158d52008-12-12 22:00:49 -0800187 efx_oword_t reg;
Ben Hutchings3e133c42008-11-04 20:34:56 +0000188
Ben Hutchings2f085752009-01-29 17:49:29 +0000189 /* GPIO 3 and the GPIO register are shared with I2C, so block that */
Ben Hutchings6f158d52008-12-12 22:00:49 -0800190 mutex_lock(&efx->i2c_adap.bus_lock);
Ben Hutchings3e133c42008-11-04 20:34:56 +0000191
Ben Hutchings2f085752009-01-29 17:49:29 +0000192 /* Pull RST_N (GPIO 2) low then let it up again, setting the
193 * FLASH_CFG_1 strap (GPIO 3) appropriately. Only change the
194 * output enables; the output levels should always be 0 (low)
195 * and we rely on external pull-ups. */
Ben Hutchings6f158d52008-12-12 22:00:49 -0800196 falcon_read(efx, &reg, GPIO_CTL_REG_KER);
197 EFX_SET_OWORD_FIELD(reg, GPIO2_OEN, true);
Ben Hutchings6f158d52008-12-12 22:00:49 -0800198 falcon_write(efx, &reg, GPIO_CTL_REG_KER);
199 msleep(1000);
Ben Hutchings2f085752009-01-29 17:49:29 +0000200 EFX_SET_OWORD_FIELD(reg, GPIO2_OEN, false);
201 EFX_SET_OWORD_FIELD(reg, GPIO3_OEN,
202 !!(efx->phy_mode & PHY_MODE_SPECIAL));
Ben Hutchings6f158d52008-12-12 22:00:49 -0800203 falcon_write(efx, &reg, GPIO_CTL_REG_KER);
Ben Hutchings2f085752009-01-29 17:49:29 +0000204 msleep(1);
Ben Hutchings3e133c42008-11-04 20:34:56 +0000205
Ben Hutchings6f158d52008-12-12 22:00:49 -0800206 mutex_unlock(&efx->i2c_adap.bus_lock);
Ben Hutchings3e133c42008-11-04 20:34:56 +0000207
Ben Hutchings6f158d52008-12-12 22:00:49 -0800208 ssleep(1);
209 return 0;
Ben Hutchings3e133c42008-11-04 20:34:56 +0000210}
211
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100212static ssize_t show_phy_flash_cfg(struct device *dev,
213 struct device_attribute *attr, char *buf)
214{
215 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
216 return sprintf(buf, "%d\n", !!(efx->phy_mode & PHY_MODE_SPECIAL));
217}
218
219static ssize_t set_phy_flash_cfg(struct device *dev,
220 struct device_attribute *attr,
221 const char *buf, size_t count)
222{
223 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
224 enum efx_phy_mode old_mode, new_mode;
225 int err;
226
227 rtnl_lock();
228 old_mode = efx->phy_mode;
229 if (count == 0 || *buf == '0')
230 new_mode = old_mode & ~PHY_MODE_SPECIAL;
231 else
232 new_mode = PHY_MODE_SPECIAL;
233 if (old_mode == new_mode) {
234 err = 0;
235 } else if (efx->state != STATE_RUNNING || netif_running(efx->net_dev)) {
236 err = -EBUSY;
237 } else {
238 efx->phy_mode = new_mode;
Ben Hutchings6f158d52008-12-12 22:00:49 -0800239 if (efx->board_info.type == EFX_BOARD_SFE4001)
240 err = sfe4001_poweron(efx);
241 else
242 err = sfn4111t_reset(efx);
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100243 efx_reconfigure_port(efx);
244 }
245 rtnl_unlock();
246
247 return err ? err : count;
248}
249
250static DEVICE_ATTR(phy_flash_cfg, 0644, show_phy_flash_cfg, set_phy_flash_cfg);
251
252static void sfe4001_fini(struct efx_nic *efx)
253{
254 EFX_INFO(efx, "%s\n", __func__);
255
256 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
257 sfe4001_poweroff(efx);
258 i2c_unregister_device(efx->board_info.ioexp_client);
259 i2c_unregister_device(efx->board_info.hwmon_client);
260}
261
Ben Hutchings6f158d52008-12-12 22:00:49 -0800262static int sfe4001_check_hw(struct efx_nic *efx)
263{
264 s32 status;
265
266 /* If XAUI link is up then do not monitor */
267 if (EFX_WORKAROUND_7884(efx) && efx->mac_up)
268 return 0;
269
270 /* Check the powered status of the PHY. Lack of power implies that
271 * the MAX6647 has shut down power to it, probably due to a temp.
272 * alarm. Reading the power status rather than the MAX6647 status
273 * directly because the later is read-to-clear and would thus
274 * start to power up the PHY again when polled, causing us to blip
275 * the power undesirably.
276 * We know we can read from the IO expander because we did
277 * it during power-on. Assume failure now is bad news. */
278 status = i2c_smbus_read_byte_data(efx->board_info.ioexp_client, P1_IN);
279 if (status >= 0 &&
280 (status & ((1 << P1_AFE_PWD_LBN) | (1 << P1_DSP_PWD25_LBN))) != 0)
281 return 0;
282
283 /* Use board power control, not PHY power control */
284 sfe4001_poweroff(efx);
285 efx->phy_mode = PHY_MODE_OFF;
286
287 return (status < 0) ? -EIO : -ERANGE;
288}
289
Ben Hutchings3e133c42008-11-04 20:34:56 +0000290static struct i2c_board_info sfe4001_hwmon_info = {
291 I2C_BOARD_INFO("max6647", 0x4e),
292 .irq = -1,
293};
294
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100295/* This board uses an I2C expander to provider power to the PHY, which needs to
296 * be turned on before the PHY can be used.
297 * Context: Process context, rtnl lock held
298 */
299int sfe4001_init(struct efx_nic *efx)
300{
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100301 int rc;
302
Ben Hutchings3e133c42008-11-04 20:34:56 +0000303#if defined(CONFIG_SENSORS_LM90) || defined(CONFIG_SENSORS_LM90_MODULE)
304 efx->board_info.hwmon_client =
305 i2c_new_device(&efx->i2c_adap, &sfe4001_hwmon_info);
306#else
307 efx->board_info.hwmon_client =
308 i2c_new_dummy(&efx->i2c_adap, sfe4001_hwmon_info.addr);
309#endif
310 if (!efx->board_info.hwmon_client)
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100311 return -EIO;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100312
Ben Hutchings3e133c42008-11-04 20:34:56 +0000313 /* Raise board/PHY high limit from 85 to 90 degrees Celsius */
314 rc = i2c_smbus_write_byte_data(efx->board_info.hwmon_client,
315 MAX664X_REG_WLHO, 90);
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100316 if (rc)
Ben Hutchings3e133c42008-11-04 20:34:56 +0000317 goto fail_hwmon;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100318
319 efx->board_info.ioexp_client = i2c_new_dummy(&efx->i2c_adap, PCA9539);
320 if (!efx->board_info.ioexp_client) {
321 rc = -EIO;
322 goto fail_hwmon;
323 }
324
325 /* 10Xpress has fixed-function LED pins, so there is no board-specific
326 * blink code. */
327 efx->board_info.blink = tenxpress_phy_blink;
328
Ben Hutchings3e133c42008-11-04 20:34:56 +0000329 efx->board_info.monitor = sfe4001_check_hw;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100330 efx->board_info.fini = sfe4001_fini;
331
332 rc = sfe4001_poweron(efx);
333 if (rc)
334 goto fail_ioexp;
335
336 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
337 if (rc)
338 goto fail_on;
339
Ben Hutchings8ceee662008-04-27 12:55:59 +0100340 EFX_INFO(efx, "PHY is powered on\n");
341 return 0;
342
Ben Hutchings37b5a602008-05-30 22:27:04 +0100343fail_on:
344 sfe4001_poweroff(efx);
345fail_ioexp:
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100346 i2c_unregister_device(efx->board_info.ioexp_client);
Ben Hutchings37b5a602008-05-30 22:27:04 +0100347fail_hwmon:
Ben Hutchings3e133c42008-11-04 20:34:56 +0000348 i2c_unregister_device(efx->board_info.hwmon_client);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100349 return rc;
350}
Ben Hutchings6f158d52008-12-12 22:00:49 -0800351
352static int sfn4111t_check_hw(struct efx_nic *efx)
353{
354 s32 status;
355
356 /* If XAUI link is up then do not monitor */
357 if (EFX_WORKAROUND_7884(efx) && efx->mac_up)
358 return 0;
359
360 /* Test LHIGH, RHIGH, FAULT, EOT and IOT alarms */
361 status = i2c_smbus_read_byte_data(efx->board_info.hwmon_client,
362 MAX664X_REG_RSL);
363 if (status < 0)
364 return -EIO;
365 if (status & 0x57)
366 return -ERANGE;
367 return 0;
368}
369
370static void sfn4111t_fini(struct efx_nic *efx)
371{
372 EFX_INFO(efx, "%s\n", __func__);
373
374 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
375 i2c_unregister_device(efx->board_info.hwmon_client);
376}
377
378static struct i2c_board_info sfn4111t_hwmon_info = {
379 I2C_BOARD_INFO("max6647", 0x4e),
380 .irq = -1,
381};
382
383int sfn4111t_init(struct efx_nic *efx)
384{
385 int rc;
386
387 efx->board_info.hwmon_client =
388 i2c_new_device(&efx->i2c_adap, &sfn4111t_hwmon_info);
389 if (!efx->board_info.hwmon_client)
390 return -EIO;
391
392 efx->board_info.blink = tenxpress_phy_blink;
393 efx->board_info.monitor = sfn4111t_check_hw;
394 efx->board_info.fini = sfn4111t_fini;
395
396 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
397 if (rc)
398 goto fail_hwmon;
399
400 if (efx->phy_mode & PHY_MODE_SPECIAL)
401 sfn4111t_reset(efx);
402
403 return 0;
404
405fail_hwmon:
406 i2c_unregister_device(efx->board_info.hwmon_client);
407 return rc;
408}