blob: d21d014bf0c18c2b298d02cf4f2257b516f06316 [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>
Herbert Xuda3bc072009-01-18 21:50:16 -080027#include <linux/rtnetlink.h>
Ben Hutchingsf8b87c12008-09-01 12:48:17 +010028#include "net_driver.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010029#include "efx.h"
30#include "phy.h"
31#include "boards.h"
32#include "falcon.h"
33#include "falcon_hwdefs.h"
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +010034#include "falcon_io.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010035#include "mac.h"
Ben Hutchings3e133c42008-11-04 20:34:56 +000036#include "workarounds.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010037
38/**************************************************************************
39 *
40 * I2C IO Expander device
41 *
42 **************************************************************************/
43#define PCA9539 0x74
44
45#define P0_IN 0x00
46#define P0_OUT 0x02
47#define P0_INVERT 0x04
48#define P0_CONFIG 0x06
49
50#define P0_EN_1V0X_LBN 0
51#define P0_EN_1V0X_WIDTH 1
52#define P0_EN_1V2_LBN 1
53#define P0_EN_1V2_WIDTH 1
54#define P0_EN_2V5_LBN 2
55#define P0_EN_2V5_WIDTH 1
56#define P0_EN_3V3X_LBN 3
57#define P0_EN_3V3X_WIDTH 1
58#define P0_EN_5V_LBN 4
59#define P0_EN_5V_WIDTH 1
60#define P0_SHORTEN_JTAG_LBN 5
61#define P0_SHORTEN_JTAG_WIDTH 1
62#define P0_X_TRST_LBN 6
63#define P0_X_TRST_WIDTH 1
64#define P0_DSP_RESET_LBN 7
65#define P0_DSP_RESET_WIDTH 1
66
67#define P1_IN 0x01
68#define P1_OUT 0x03
69#define P1_INVERT 0x05
70#define P1_CONFIG 0x07
71
72#define P1_AFE_PWD_LBN 0
73#define P1_AFE_PWD_WIDTH 1
74#define P1_DSP_PWD25_LBN 1
75#define P1_DSP_PWD25_WIDTH 1
76#define P1_RESERVED_LBN 2
77#define P1_RESERVED_WIDTH 2
78#define P1_SPARE_LBN 4
79#define P1_SPARE_WIDTH 4
80
Ben Hutchings3e133c42008-11-04 20:34:56 +000081/* Temperature Sensor */
82#define MAX664X_REG_RSL 0x02
83#define MAX664X_REG_WLHO 0x0B
Ben Hutchings8ceee662008-04-27 12:55:59 +010084
Ben Hutchings37b5a602008-05-30 22:27:04 +010085static void sfe4001_poweroff(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +010086{
Ben Hutchings37b5a602008-05-30 22:27:04 +010087 struct i2c_client *ioexp_client = efx->board_info.ioexp_client;
88 struct i2c_client *hwmon_client = efx->board_info.hwmon_client;
Ben Hutchings8ceee662008-04-27 12:55:59 +010089
Ben Hutchings37b5a602008-05-30 22:27:04 +010090 /* Turn off all power rails and disable outputs */
91 i2c_smbus_write_byte_data(ioexp_client, P0_OUT, 0xff);
92 i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG, 0xff);
93 i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0xff);
Ben Hutchings8ceee662008-04-27 12:55:59 +010094
95 /* Clear any over-temperature alert */
Ben Hutchings3e133c42008-11-04 20:34:56 +000096 i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
Ben Hutchings37b5a602008-05-30 22:27:04 +010097}
98
Ben Hutchingsf8b87c12008-09-01 12:48:17 +010099static int sfe4001_poweron(struct efx_nic *efx)
Ben Hutchings37b5a602008-05-30 22:27:04 +0100100{
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100101 struct i2c_client *hwmon_client = efx->board_info.hwmon_client;
102 struct i2c_client *ioexp_client = efx->board_info.ioexp_client;
Ben Hutchings11f34e62008-09-01 12:45:48 +0100103 unsigned int i, j;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100104 int rc;
Ben Hutchings37b5a602008-05-30 22:27:04 +0100105 u8 out;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100106
Ben Hutchings8ceee662008-04-27 12:55:59 +0100107 /* Clear any previous over-temperature alert */
Ben Hutchings3e133c42008-11-04 20:34:56 +0000108 rc = i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
Ben Hutchings37b5a602008-05-30 22:27:04 +0100109 if (rc < 0)
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100110 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100111
112 /* Enable port 0 and port 1 outputs on IO expander */
Ben Hutchings37b5a602008-05-30 22:27:04 +0100113 rc = i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0x00);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100114 if (rc)
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100115 return rc;
Ben Hutchings37b5a602008-05-30 22:27:04 +0100116 rc = i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG,
117 0xff & ~(1 << P1_SPARE_LBN));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100118 if (rc)
Ben Hutchings37b5a602008-05-30 22:27:04 +0100119 goto fail_on;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100120
Ben Hutchings11f34e62008-09-01 12:45:48 +0100121 /* If PHY power is on, turn it all off and wait 1 second to
122 * ensure a full reset.
123 */
124 rc = i2c_smbus_read_byte_data(ioexp_client, P0_OUT);
125 if (rc < 0)
126 goto fail_on;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100127 out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
128 (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
129 (0 << P0_EN_1V0X_LBN));
Ben Hutchings11f34e62008-09-01 12:45:48 +0100130 if (rc != out) {
131 EFX_INFO(efx, "power-cycling PHY\n");
132 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
133 if (rc)
134 goto fail_on;
135 schedule_timeout_uninterruptible(HZ);
136 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100137
Ben Hutchings11f34e62008-09-01 12:45:48 +0100138 for (i = 0; i < 20; ++i) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100139 /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
140 out = 0xff & ~((1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
141 (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
142 (1 << P0_X_TRST_LBN));
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100143 if (efx->phy_mode & PHY_MODE_SPECIAL)
Ben Hutchings75f2d3e2008-05-07 12:55:13 +0100144 out |= 1 << P0_EN_3V3X_LBN;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100145
Ben Hutchings37b5a602008-05-30 22:27:04 +0100146 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100147 if (rc)
Ben Hutchings37b5a602008-05-30 22:27:04 +0100148 goto fail_on;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100149 msleep(10);
150
151 /* Turn on 1V power rail */
152 out &= ~(1 << P0_EN_1V0X_LBN);
Ben Hutchings37b5a602008-05-30 22:27:04 +0100153 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100154 if (rc)
Ben Hutchings37b5a602008-05-30 22:27:04 +0100155 goto fail_on;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100156
Ben Hutchings11f34e62008-09-01 12:45:48 +0100157 EFX_INFO(efx, "waiting for DSP boot (attempt %d)...\n", i);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100158
Ben Hutchings11f34e62008-09-01 12:45:48 +0100159 /* In flash config mode, DSP does not turn on AFE, so
160 * just wait 1 second.
161 */
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100162 if (efx->phy_mode & PHY_MODE_SPECIAL) {
Ben Hutchings11f34e62008-09-01 12:45:48 +0100163 schedule_timeout_uninterruptible(HZ);
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100164 return 0;
Ben Hutchings11f34e62008-09-01 12:45:48 +0100165 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100166
Ben Hutchings11f34e62008-09-01 12:45:48 +0100167 for (j = 0; j < 10; ++j) {
168 msleep(100);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100169
Ben Hutchings11f34e62008-09-01 12:45:48 +0100170 /* Check DSP has asserted AFE power line */
171 rc = i2c_smbus_read_byte_data(ioexp_client, P1_IN);
172 if (rc < 0)
173 goto fail_on;
174 if (rc & (1 << P1_AFE_PWD_LBN))
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100175 return 0;
Ben Hutchings11f34e62008-09-01 12:45:48 +0100176 }
177 }
178
179 EFX_INFO(efx, "timed out waiting for DSP boot\n");
Ben Hutchings8ceee662008-04-27 12:55:59 +0100180 rc = -ETIMEDOUT;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100181fail_on:
182 sfe4001_poweroff(efx);
183 return rc;
184}
Ben Hutchings8ceee662008-04-27 12:55:59 +0100185
Ben Hutchings6f158d52008-12-12 22:00:49 -0800186static int sfn4111t_reset(struct efx_nic *efx)
Ben Hutchings3e133c42008-11-04 20:34:56 +0000187{
Ben Hutchings6f158d52008-12-12 22:00:49 -0800188 efx_oword_t reg;
Ben Hutchings3e133c42008-11-04 20:34:56 +0000189
Ben Hutchings6f158d52008-12-12 22:00:49 -0800190 /* GPIO pins are also used for I2C, so block that temporarily */
191 mutex_lock(&efx->i2c_adap.bus_lock);
Ben Hutchings3e133c42008-11-04 20:34:56 +0000192
Ben Hutchings6f158d52008-12-12 22:00:49 -0800193 falcon_read(efx, &reg, GPIO_CTL_REG_KER);
194 EFX_SET_OWORD_FIELD(reg, GPIO2_OEN, true);
195 EFX_SET_OWORD_FIELD(reg, GPIO2_OUT, false);
196 falcon_write(efx, &reg, GPIO_CTL_REG_KER);
197 msleep(1000);
198 EFX_SET_OWORD_FIELD(reg, GPIO2_OUT, true);
199 EFX_SET_OWORD_FIELD(reg, GPIO3_OEN, true);
200 EFX_SET_OWORD_FIELD(reg, GPIO3_OUT,
201 !(efx->phy_mode & PHY_MODE_SPECIAL));
202 falcon_write(efx, &reg, GPIO_CTL_REG_KER);
Ben Hutchings3e133c42008-11-04 20:34:56 +0000203
Ben Hutchings6f158d52008-12-12 22:00:49 -0800204 mutex_unlock(&efx->i2c_adap.bus_lock);
Ben Hutchings3e133c42008-11-04 20:34:56 +0000205
Ben Hutchings6f158d52008-12-12 22:00:49 -0800206 ssleep(1);
207 return 0;
Ben Hutchings3e133c42008-11-04 20:34:56 +0000208}
209
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100210static ssize_t show_phy_flash_cfg(struct device *dev,
211 struct device_attribute *attr, char *buf)
212{
213 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
214 return sprintf(buf, "%d\n", !!(efx->phy_mode & PHY_MODE_SPECIAL));
215}
216
217static ssize_t set_phy_flash_cfg(struct device *dev,
218 struct device_attribute *attr,
219 const char *buf, size_t count)
220{
221 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
222 enum efx_phy_mode old_mode, new_mode;
223 int err;
224
225 rtnl_lock();
226 old_mode = efx->phy_mode;
227 if (count == 0 || *buf == '0')
228 new_mode = old_mode & ~PHY_MODE_SPECIAL;
229 else
230 new_mode = PHY_MODE_SPECIAL;
231 if (old_mode == new_mode) {
232 err = 0;
233 } else if (efx->state != STATE_RUNNING || netif_running(efx->net_dev)) {
234 err = -EBUSY;
235 } else {
236 efx->phy_mode = new_mode;
Ben Hutchings6f158d52008-12-12 22:00:49 -0800237 if (efx->board_info.type == EFX_BOARD_SFE4001)
238 err = sfe4001_poweron(efx);
239 else
240 err = sfn4111t_reset(efx);
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100241 efx_reconfigure_port(efx);
242 }
243 rtnl_unlock();
244
245 return err ? err : count;
246}
247
248static DEVICE_ATTR(phy_flash_cfg, 0644, show_phy_flash_cfg, set_phy_flash_cfg);
249
250static void sfe4001_fini(struct efx_nic *efx)
251{
252 EFX_INFO(efx, "%s\n", __func__);
253
254 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
255 sfe4001_poweroff(efx);
256 i2c_unregister_device(efx->board_info.ioexp_client);
257 i2c_unregister_device(efx->board_info.hwmon_client);
258}
259
Ben Hutchings6f158d52008-12-12 22:00:49 -0800260static int sfe4001_check_hw(struct efx_nic *efx)
261{
262 s32 status;
263
264 /* If XAUI link is up then do not monitor */
265 if (EFX_WORKAROUND_7884(efx) && efx->mac_up)
266 return 0;
267
268 /* Check the powered status of the PHY. Lack of power implies that
269 * the MAX6647 has shut down power to it, probably due to a temp.
270 * alarm. Reading the power status rather than the MAX6647 status
271 * directly because the later is read-to-clear and would thus
272 * start to power up the PHY again when polled, causing us to blip
273 * the power undesirably.
274 * We know we can read from the IO expander because we did
275 * it during power-on. Assume failure now is bad news. */
276 status = i2c_smbus_read_byte_data(efx->board_info.ioexp_client, P1_IN);
277 if (status >= 0 &&
278 (status & ((1 << P1_AFE_PWD_LBN) | (1 << P1_DSP_PWD25_LBN))) != 0)
279 return 0;
280
281 /* Use board power control, not PHY power control */
282 sfe4001_poweroff(efx);
283 efx->phy_mode = PHY_MODE_OFF;
284
285 return (status < 0) ? -EIO : -ERANGE;
286}
287
Ben Hutchings3e133c42008-11-04 20:34:56 +0000288static struct i2c_board_info sfe4001_hwmon_info = {
289 I2C_BOARD_INFO("max6647", 0x4e),
290 .irq = -1,
291};
292
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100293/* This board uses an I2C expander to provider power to the PHY, which needs to
294 * be turned on before the PHY can be used.
295 * Context: Process context, rtnl lock held
296 */
297int sfe4001_init(struct efx_nic *efx)
298{
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100299 int rc;
300
Ben Hutchings3e133c42008-11-04 20:34:56 +0000301#if defined(CONFIG_SENSORS_LM90) || defined(CONFIG_SENSORS_LM90_MODULE)
302 efx->board_info.hwmon_client =
303 i2c_new_device(&efx->i2c_adap, &sfe4001_hwmon_info);
304#else
305 efx->board_info.hwmon_client =
306 i2c_new_dummy(&efx->i2c_adap, sfe4001_hwmon_info.addr);
307#endif
308 if (!efx->board_info.hwmon_client)
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100309 return -EIO;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100310
Ben Hutchings3e133c42008-11-04 20:34:56 +0000311 /* Raise board/PHY high limit from 85 to 90 degrees Celsius */
312 rc = i2c_smbus_write_byte_data(efx->board_info.hwmon_client,
313 MAX664X_REG_WLHO, 90);
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100314 if (rc)
Ben Hutchings3e133c42008-11-04 20:34:56 +0000315 goto fail_hwmon;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100316
317 efx->board_info.ioexp_client = i2c_new_dummy(&efx->i2c_adap, PCA9539);
318 if (!efx->board_info.ioexp_client) {
319 rc = -EIO;
320 goto fail_hwmon;
321 }
322
323 /* 10Xpress has fixed-function LED pins, so there is no board-specific
324 * blink code. */
325 efx->board_info.blink = tenxpress_phy_blink;
326
Ben Hutchings3e133c42008-11-04 20:34:56 +0000327 efx->board_info.monitor = sfe4001_check_hw;
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100328 efx->board_info.fini = sfe4001_fini;
329
330 rc = sfe4001_poweron(efx);
331 if (rc)
332 goto fail_ioexp;
333
334 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
335 if (rc)
336 goto fail_on;
337
Ben Hutchings8ceee662008-04-27 12:55:59 +0100338 EFX_INFO(efx, "PHY is powered on\n");
339 return 0;
340
Ben Hutchings37b5a602008-05-30 22:27:04 +0100341fail_on:
342 sfe4001_poweroff(efx);
343fail_ioexp:
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100344 i2c_unregister_device(efx->board_info.ioexp_client);
Ben Hutchings37b5a602008-05-30 22:27:04 +0100345fail_hwmon:
Ben Hutchings3e133c42008-11-04 20:34:56 +0000346 i2c_unregister_device(efx->board_info.hwmon_client);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100347 return rc;
348}
Ben Hutchings6f158d52008-12-12 22:00:49 -0800349
350static int sfn4111t_check_hw(struct efx_nic *efx)
351{
352 s32 status;
353
354 /* If XAUI link is up then do not monitor */
355 if (EFX_WORKAROUND_7884(efx) && efx->mac_up)
356 return 0;
357
358 /* Test LHIGH, RHIGH, FAULT, EOT and IOT alarms */
359 status = i2c_smbus_read_byte_data(efx->board_info.hwmon_client,
360 MAX664X_REG_RSL);
361 if (status < 0)
362 return -EIO;
363 if (status & 0x57)
364 return -ERANGE;
365 return 0;
366}
367
368static void sfn4111t_fini(struct efx_nic *efx)
369{
370 EFX_INFO(efx, "%s\n", __func__);
371
372 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
373 i2c_unregister_device(efx->board_info.hwmon_client);
374}
375
376static struct i2c_board_info sfn4111t_hwmon_info = {
377 I2C_BOARD_INFO("max6647", 0x4e),
378 .irq = -1,
379};
380
381int sfn4111t_init(struct efx_nic *efx)
382{
383 int rc;
384
385 efx->board_info.hwmon_client =
386 i2c_new_device(&efx->i2c_adap, &sfn4111t_hwmon_info);
387 if (!efx->board_info.hwmon_client)
388 return -EIO;
389
390 efx->board_info.blink = tenxpress_phy_blink;
391 efx->board_info.monitor = sfn4111t_check_hw;
392 efx->board_info.fini = sfn4111t_fini;
393
394 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
395 if (rc)
396 goto fail_hwmon;
397
398 if (efx->phy_mode & PHY_MODE_SPECIAL)
399 sfn4111t_reset(efx);
400
401 return 0;
402
403fail_hwmon:
404 i2c_unregister_device(efx->board_info.hwmon_client);
405 return rc;
406}