blob: 3d950c2cf205965d6aafced30330acd235d48734 [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 2007-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 Hutchingsc9597d42009-10-23 08:29:33 +000010#include <linux/rtnetlink.h>
11
Ben Hutchings8ceee662008-04-27 12:55:59 +010012#include "net_driver.h"
13#include "phy.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010014#include "efx.h"
Ben Hutchings744093c2009-11-29 15:12:08 +000015#include "nic.h"
Ben Hutchings3e6c4532009-10-23 08:30:36 +000016#include "regs.h"
Ben Hutchings12d00ca2009-10-23 08:30:46 +000017#include "io.h"
Ben Hutchings3e133c42008-11-04 20:34:56 +000018#include "workarounds.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010019
20/* Macros for unpacking the board revision */
21/* The revision info is in host byte order. */
Ben Hutchings3473a5b2009-10-23 08:29:16 +000022#define FALCON_BOARD_TYPE(_rev) (_rev >> 8)
23#define FALCON_BOARD_MAJOR(_rev) ((_rev >> 4) & 0xf)
24#define FALCON_BOARD_MINOR(_rev) (_rev & 0xf)
25
26/* Board types */
Ben Hutchingsc9597d42009-10-23 08:29:33 +000027#define FALCON_BOARD_SFE4001 0x01
Ben Hutchings3473a5b2009-10-23 08:29:16 +000028#define FALCON_BOARD_SFE4002 0x02
29#define FALCON_BOARD_SFN4111T 0x51
30#define FALCON_BOARD_SFN4112F 0x52
Ben Hutchings8ceee662008-04-27 12:55:59 +010031
Ben Hutchings242cc052010-02-19 13:34:03 +000032/* Board temperature is about 15°C above ambient when air flow is
33 * limited. */
34#define FALCON_BOARD_TEMP_BIAS 15
35
36/* SFC4000 datasheet says: 'The maximum permitted junction temperature
37 * is 125°C; the thermal design of the environment for the SFC4000
38 * should aim to keep this well below 100°C.' */
39#define FALCON_JUNC_TEMP_MAX 90
40
Ben Hutchings8ceee662008-04-27 12:55:59 +010041/*****************************************************************************
Ben Hutchings3e133c42008-11-04 20:34:56 +000042 * Support for LM87 sensor chip used on several boards
43 */
44#define LM87_REG_ALARMS1 0x41
45#define LM87_REG_ALARMS2 0x42
46#define LM87_IN_LIMITS(nr, _min, _max) \
47 0x2B + (nr) * 2, _max, 0x2C + (nr) * 2, _min
48#define LM87_AIN_LIMITS(nr, _min, _max) \
49 0x3B + (nr), _max, 0x1A + (nr), _min
50#define LM87_TEMP_INT_LIMITS(_min, _max) \
51 0x39, _max, 0x3A, _min
52#define LM87_TEMP_EXT1_LIMITS(_min, _max) \
53 0x37, _max, 0x38, _min
54
55#define LM87_ALARM_TEMP_INT 0x10
56#define LM87_ALARM_TEMP_EXT1 0x20
57
58#if defined(CONFIG_SENSORS_LM87) || defined(CONFIG_SENSORS_LM87_MODULE)
59
60static int efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
61 const u8 *reg_values)
62{
Ben Hutchingse775fb92009-11-23 16:06:02 +000063 struct falcon_board *board = falcon_board(efx);
64 struct i2c_client *client = i2c_new_device(&board->i2c_adap, info);
Ben Hutchings3e133c42008-11-04 20:34:56 +000065 int rc;
66
67 if (!client)
68 return -EIO;
69
70 while (*reg_values) {
71 u8 reg = *reg_values++;
72 u8 value = *reg_values++;
73 rc = i2c_smbus_write_byte_data(client, reg, value);
74 if (rc)
75 goto err;
76 }
77
Ben Hutchingse775fb92009-11-23 16:06:02 +000078 board->hwmon_client = client;
Ben Hutchings3e133c42008-11-04 20:34:56 +000079 return 0;
80
81err:
82 i2c_unregister_device(client);
83 return rc;
84}
85
86static void efx_fini_lm87(struct efx_nic *efx)
87{
Ben Hutchings278c0622009-11-23 16:05:12 +000088 i2c_unregister_device(falcon_board(efx)->hwmon_client);
Ben Hutchings3e133c42008-11-04 20:34:56 +000089}
90
91static int efx_check_lm87(struct efx_nic *efx, unsigned mask)
92{
Ben Hutchings278c0622009-11-23 16:05:12 +000093 struct i2c_client *client = falcon_board(efx)->hwmon_client;
Ben Hutchings3e133c42008-11-04 20:34:56 +000094 s32 alarms1, alarms2;
95
96 /* If link is up then do not monitor temperature */
Ben Hutchingseb50c0d2009-11-23 16:06:30 +000097 if (EFX_WORKAROUND_7884(efx) && efx->link_state.up)
Ben Hutchings3e133c42008-11-04 20:34:56 +000098 return 0;
99
100 alarms1 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS1);
101 alarms2 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS2);
102 if (alarms1 < 0)
103 return alarms1;
104 if (alarms2 < 0)
105 return alarms2;
106 alarms1 &= mask;
107 alarms2 &= mask >> 8;
108 if (alarms1 || alarms2) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000109 netif_err(efx, hw, efx->net_dev,
110 "LM87 detected a hardware failure (status %02x:%02x)"
Ben Hutchingsbd97a632010-06-25 07:06:29 +0000111 "%s%s%s\n",
Ben Hutchings62776d02010-06-23 11:30:07 +0000112 alarms1, alarms2,
Ben Hutchingsbd97a632010-06-25 07:06:29 +0000113 (alarms1 & LM87_ALARM_TEMP_INT) ?
114 "; board is overheating" : "",
115 (alarms1 & LM87_ALARM_TEMP_EXT1) ?
116 "; controller is overheating" : "",
117 (alarms1 & ~(LM87_ALARM_TEMP_INT | LM87_ALARM_TEMP_EXT1)
118 || alarms2) ?
119 "; electrical fault" : "");
Ben Hutchings3e133c42008-11-04 20:34:56 +0000120 return -ERANGE;
121 }
122
123 return 0;
124}
125
126#else /* !CONFIG_SENSORS_LM87 */
127
128static inline int
129efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
130 const u8 *reg_values)
131{
132 return 0;
133}
134static inline void efx_fini_lm87(struct efx_nic *efx)
135{
136}
137static inline int efx_check_lm87(struct efx_nic *efx, unsigned mask)
138{
139 return 0;
140}
141
142#endif /* CONFIG_SENSORS_LM87 */
143
144/*****************************************************************************
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000145 * Support for the SFE4001 and SFN4111T NICs.
146 *
147 * The SFE4001 does not power-up fully at reset due to its high power
148 * consumption. We control its power via a PCA9539 I/O expander.
149 * Both boards have a MAX6647 temperature monitor which we expose to
150 * the lm90 driver.
151 *
152 * This also provides minimal support for reflashing the PHY, which is
153 * initiated by resetting it with the FLASH_CFG_1 pin pulled down.
154 * On SFE4001 rev A2 and later this is connected to the 3V3X output of
155 * the IO-expander; on the SFN4111T it is connected to Falcon's GPIO3.
156 * We represent reflash mode as PHY_MODE_SPECIAL and make it mutually
157 * exclusive with the network device being open.
158 */
159
160/**************************************************************************
Ben Hutchings89863522009-11-25 16:09:04 +0000161 * Support for I2C IO Expander device on SFE4001
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000162 */
163#define PCA9539 0x74
164
165#define P0_IN 0x00
166#define P0_OUT 0x02
167#define P0_INVERT 0x04
168#define P0_CONFIG 0x06
169
170#define P0_EN_1V0X_LBN 0
171#define P0_EN_1V0X_WIDTH 1
172#define P0_EN_1V2_LBN 1
173#define P0_EN_1V2_WIDTH 1
174#define P0_EN_2V5_LBN 2
175#define P0_EN_2V5_WIDTH 1
176#define P0_EN_3V3X_LBN 3
177#define P0_EN_3V3X_WIDTH 1
178#define P0_EN_5V_LBN 4
179#define P0_EN_5V_WIDTH 1
180#define P0_SHORTEN_JTAG_LBN 5
181#define P0_SHORTEN_JTAG_WIDTH 1
182#define P0_X_TRST_LBN 6
183#define P0_X_TRST_WIDTH 1
184#define P0_DSP_RESET_LBN 7
185#define P0_DSP_RESET_WIDTH 1
186
187#define P1_IN 0x01
188#define P1_OUT 0x03
189#define P1_INVERT 0x05
190#define P1_CONFIG 0x07
191
192#define P1_AFE_PWD_LBN 0
193#define P1_AFE_PWD_WIDTH 1
194#define P1_DSP_PWD25_LBN 1
195#define P1_DSP_PWD25_WIDTH 1
196#define P1_RESERVED_LBN 2
197#define P1_RESERVED_WIDTH 2
198#define P1_SPARE_LBN 4
199#define P1_SPARE_WIDTH 4
200
201/* Temperature Sensor */
202#define MAX664X_REG_RSL 0x02
203#define MAX664X_REG_WLHO 0x0B
204
205static void sfe4001_poweroff(struct efx_nic *efx)
206{
Ben Hutchings278c0622009-11-23 16:05:12 +0000207 struct i2c_client *ioexp_client = falcon_board(efx)->ioexp_client;
208 struct i2c_client *hwmon_client = falcon_board(efx)->hwmon_client;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000209
210 /* Turn off all power rails and disable outputs */
211 i2c_smbus_write_byte_data(ioexp_client, P0_OUT, 0xff);
212 i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG, 0xff);
213 i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0xff);
214
215 /* Clear any over-temperature alert */
216 i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
217}
218
219static int sfe4001_poweron(struct efx_nic *efx)
220{
Ben Hutchings278c0622009-11-23 16:05:12 +0000221 struct i2c_client *ioexp_client = falcon_board(efx)->ioexp_client;
222 struct i2c_client *hwmon_client = falcon_board(efx)->hwmon_client;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000223 unsigned int i, j;
224 int rc;
225 u8 out;
226
227 /* Clear any previous over-temperature alert */
228 rc = i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
229 if (rc < 0)
230 return rc;
231
232 /* Enable port 0 and port 1 outputs on IO expander */
233 rc = i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0x00);
234 if (rc)
235 return rc;
236 rc = i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG,
237 0xff & ~(1 << P1_SPARE_LBN));
238 if (rc)
239 goto fail_on;
240
241 /* If PHY power is on, turn it all off and wait 1 second to
242 * ensure a full reset.
243 */
244 rc = i2c_smbus_read_byte_data(ioexp_client, P0_OUT);
245 if (rc < 0)
246 goto fail_on;
247 out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
248 (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
249 (0 << P0_EN_1V0X_LBN));
250 if (rc != out) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000251 netif_info(efx, hw, efx->net_dev, "power-cycling PHY\n");
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000252 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
253 if (rc)
254 goto fail_on;
255 schedule_timeout_uninterruptible(HZ);
256 }
257
258 for (i = 0; i < 20; ++i) {
259 /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
260 out = 0xff & ~((1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
261 (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
262 (1 << P0_X_TRST_LBN));
263 if (efx->phy_mode & PHY_MODE_SPECIAL)
264 out |= 1 << P0_EN_3V3X_LBN;
265
266 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
267 if (rc)
268 goto fail_on;
269 msleep(10);
270
271 /* Turn on 1V power rail */
272 out &= ~(1 << P0_EN_1V0X_LBN);
273 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
274 if (rc)
275 goto fail_on;
276
Ben Hutchings62776d02010-06-23 11:30:07 +0000277 netif_info(efx, hw, efx->net_dev,
278 "waiting for DSP boot (attempt %d)...\n", i);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000279
280 /* In flash config mode, DSP does not turn on AFE, so
281 * just wait 1 second.
282 */
283 if (efx->phy_mode & PHY_MODE_SPECIAL) {
284 schedule_timeout_uninterruptible(HZ);
285 return 0;
286 }
287
288 for (j = 0; j < 10; ++j) {
289 msleep(100);
290
291 /* Check DSP has asserted AFE power line */
292 rc = i2c_smbus_read_byte_data(ioexp_client, P1_IN);
293 if (rc < 0)
294 goto fail_on;
295 if (rc & (1 << P1_AFE_PWD_LBN))
296 return 0;
297 }
298 }
299
Ben Hutchings62776d02010-06-23 11:30:07 +0000300 netif_info(efx, hw, efx->net_dev, "timed out waiting for DSP boot\n");
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000301 rc = -ETIMEDOUT;
302fail_on:
303 sfe4001_poweroff(efx);
304 return rc;
305}
306
307static int sfn4111t_reset(struct efx_nic *efx)
308{
Ben Hutchingse775fb92009-11-23 16:06:02 +0000309 struct falcon_board *board = falcon_board(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000310 efx_oword_t reg;
311
312 /* GPIO 3 and the GPIO register are shared with I2C, so block that */
Ben Hutchingse775fb92009-11-23 16:06:02 +0000313 i2c_lock_adapter(&board->i2c_adap);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000314
315 /* Pull RST_N (GPIO 2) low then let it up again, setting the
316 * FLASH_CFG_1 strap (GPIO 3) appropriately. Only change the
317 * output enables; the output levels should always be 0 (low)
318 * and we rely on external pull-ups. */
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000319 efx_reado(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000320 EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO2_OEN, true);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000321 efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000322 msleep(1000);
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000323 EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO2_OEN, false);
324 EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO3_OEN,
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000325 !!(efx->phy_mode & PHY_MODE_SPECIAL));
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000326 efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000327 msleep(1);
328
Ben Hutchingse775fb92009-11-23 16:06:02 +0000329 i2c_unlock_adapter(&board->i2c_adap);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000330
331 ssleep(1);
332 return 0;
333}
334
335static ssize_t show_phy_flash_cfg(struct device *dev,
336 struct device_attribute *attr, char *buf)
337{
338 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
339 return sprintf(buf, "%d\n", !!(efx->phy_mode & PHY_MODE_SPECIAL));
340}
341
342static ssize_t set_phy_flash_cfg(struct device *dev,
343 struct device_attribute *attr,
344 const char *buf, size_t count)
345{
346 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
347 enum efx_phy_mode old_mode, new_mode;
348 int err;
349
350 rtnl_lock();
351 old_mode = efx->phy_mode;
352 if (count == 0 || *buf == '0')
353 new_mode = old_mode & ~PHY_MODE_SPECIAL;
354 else
355 new_mode = PHY_MODE_SPECIAL;
356 if (old_mode == new_mode) {
357 err = 0;
358 } else if (efx->state != STATE_RUNNING || netif_running(efx->net_dev)) {
359 err = -EBUSY;
360 } else {
361 /* Reset the PHY, reconfigure the MAC and enable/disable
362 * MAC stats accordingly. */
363 efx->phy_mode = new_mode;
364 if (new_mode & PHY_MODE_SPECIAL)
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000365 falcon_stop_nic_stats(efx);
Ben Hutchings44838a42009-11-25 16:09:41 +0000366 if (falcon_board(efx)->type->id == FALCON_BOARD_SFE4001)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000367 err = sfe4001_poweron(efx);
368 else
369 err = sfn4111t_reset(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000370 if (!err)
371 err = efx_reconfigure_port(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000372 if (!(new_mode & PHY_MODE_SPECIAL))
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000373 falcon_start_nic_stats(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000374 }
375 rtnl_unlock();
376
377 return err ? err : count;
378}
379
380static DEVICE_ATTR(phy_flash_cfg, 0644, show_phy_flash_cfg, set_phy_flash_cfg);
381
382static void sfe4001_fini(struct efx_nic *efx)
383{
Ben Hutchings278c0622009-11-23 16:05:12 +0000384 struct falcon_board *board = falcon_board(efx);
385
Ben Hutchings62776d02010-06-23 11:30:07 +0000386 netif_info(efx, drv, efx->net_dev, "%s\n", __func__);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000387
388 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
389 sfe4001_poweroff(efx);
Ben Hutchings278c0622009-11-23 16:05:12 +0000390 i2c_unregister_device(board->ioexp_client);
391 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000392}
393
394static int sfe4001_check_hw(struct efx_nic *efx)
395{
396 s32 status;
397
398 /* If XAUI link is up then do not monitor */
Ben Hutchings9007b9f2009-11-25 16:12:01 +0000399 if (EFX_WORKAROUND_7884(efx) && !efx->xmac_poll_required)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000400 return 0;
401
402 /* Check the powered status of the PHY. Lack of power implies that
403 * the MAX6647 has shut down power to it, probably due to a temp.
404 * alarm. Reading the power status rather than the MAX6647 status
405 * directly because the later is read-to-clear and would thus
406 * start to power up the PHY again when polled, causing us to blip
407 * the power undesirably.
408 * We know we can read from the IO expander because we did
409 * it during power-on. Assume failure now is bad news. */
Ben Hutchings278c0622009-11-23 16:05:12 +0000410 status = i2c_smbus_read_byte_data(falcon_board(efx)->ioexp_client, P1_IN);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000411 if (status >= 0 &&
412 (status & ((1 << P1_AFE_PWD_LBN) | (1 << P1_DSP_PWD25_LBN))) != 0)
413 return 0;
414
415 /* Use board power control, not PHY power control */
416 sfe4001_poweroff(efx);
417 efx->phy_mode = PHY_MODE_OFF;
418
419 return (status < 0) ? -EIO : -ERANGE;
420}
421
422static struct i2c_board_info sfe4001_hwmon_info = {
423 I2C_BOARD_INFO("max6647", 0x4e),
424};
425
426/* This board uses an I2C expander to provider power to the PHY, which needs to
427 * be turned on before the PHY can be used.
428 * Context: Process context, rtnl lock held
429 */
430static int sfe4001_init(struct efx_nic *efx)
431{
Ben Hutchings278c0622009-11-23 16:05:12 +0000432 struct falcon_board *board = falcon_board(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000433 int rc;
434
435#if defined(CONFIG_SENSORS_LM90) || defined(CONFIG_SENSORS_LM90_MODULE)
Ben Hutchings278c0622009-11-23 16:05:12 +0000436 board->hwmon_client =
Ben Hutchingse775fb92009-11-23 16:06:02 +0000437 i2c_new_device(&board->i2c_adap, &sfe4001_hwmon_info);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000438#else
Ben Hutchings278c0622009-11-23 16:05:12 +0000439 board->hwmon_client =
Ben Hutchingse775fb92009-11-23 16:06:02 +0000440 i2c_new_dummy(&board->i2c_adap, sfe4001_hwmon_info.addr);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000441#endif
Ben Hutchings278c0622009-11-23 16:05:12 +0000442 if (!board->hwmon_client)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000443 return -EIO;
444
445 /* Raise board/PHY high limit from 85 to 90 degrees Celsius */
Ben Hutchings278c0622009-11-23 16:05:12 +0000446 rc = i2c_smbus_write_byte_data(board->hwmon_client,
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000447 MAX664X_REG_WLHO, 90);
448 if (rc)
449 goto fail_hwmon;
450
Ben Hutchingse775fb92009-11-23 16:06:02 +0000451 board->ioexp_client = i2c_new_dummy(&board->i2c_adap, PCA9539);
Ben Hutchings278c0622009-11-23 16:05:12 +0000452 if (!board->ioexp_client) {
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000453 rc = -EIO;
454 goto fail_hwmon;
455 }
456
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000457 if (efx->phy_mode & PHY_MODE_SPECIAL) {
458 /* PHY won't generate a 156.25 MHz clock and MAC stats fetch
459 * will fail. */
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000460 falcon_stop_nic_stats(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000461 }
462 rc = sfe4001_poweron(efx);
463 if (rc)
464 goto fail_ioexp;
465
466 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
467 if (rc)
468 goto fail_on;
469
Ben Hutchings62776d02010-06-23 11:30:07 +0000470 netif_info(efx, hw, efx->net_dev, "PHY is powered on\n");
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000471 return 0;
472
473fail_on:
474 sfe4001_poweroff(efx);
475fail_ioexp:
Ben Hutchings278c0622009-11-23 16:05:12 +0000476 i2c_unregister_device(board->ioexp_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000477fail_hwmon:
Ben Hutchings278c0622009-11-23 16:05:12 +0000478 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000479 return rc;
480}
481
482static int sfn4111t_check_hw(struct efx_nic *efx)
483{
484 s32 status;
485
486 /* If XAUI link is up then do not monitor */
Ben Hutchings9007b9f2009-11-25 16:12:01 +0000487 if (EFX_WORKAROUND_7884(efx) && !efx->xmac_poll_required)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000488 return 0;
489
490 /* Test LHIGH, RHIGH, FAULT, EOT and IOT alarms */
Ben Hutchings278c0622009-11-23 16:05:12 +0000491 status = i2c_smbus_read_byte_data(falcon_board(efx)->hwmon_client,
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000492 MAX664X_REG_RSL);
493 if (status < 0)
494 return -EIO;
495 if (status & 0x57)
496 return -ERANGE;
497 return 0;
498}
499
500static void sfn4111t_fini(struct efx_nic *efx)
501{
Ben Hutchings62776d02010-06-23 11:30:07 +0000502 netif_info(efx, drv, efx->net_dev, "%s\n", __func__);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000503
504 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
Ben Hutchings278c0622009-11-23 16:05:12 +0000505 i2c_unregister_device(falcon_board(efx)->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000506}
507
508static struct i2c_board_info sfn4111t_a0_hwmon_info = {
509 I2C_BOARD_INFO("max6647", 0x4e),
510};
511
512static struct i2c_board_info sfn4111t_r5_hwmon_info = {
513 I2C_BOARD_INFO("max6646", 0x4d),
514};
515
Ben Hutchings981fc1b2009-11-23 16:04:23 +0000516static void sfn4111t_init_phy(struct efx_nic *efx)
517{
518 if (!(efx->phy_mode & PHY_MODE_SPECIAL)) {
519 if (sft9001_wait_boot(efx) != -EINVAL)
520 return;
521
522 efx->phy_mode = PHY_MODE_SPECIAL;
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000523 falcon_stop_nic_stats(efx);
Ben Hutchings981fc1b2009-11-23 16:04:23 +0000524 }
525
526 sfn4111t_reset(efx);
527 sft9001_wait_boot(efx);
528}
529
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000530static int sfn4111t_init(struct efx_nic *efx)
531{
Ben Hutchings278c0622009-11-23 16:05:12 +0000532 struct falcon_board *board = falcon_board(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000533 int rc;
534
Ben Hutchings278c0622009-11-23 16:05:12 +0000535 board->hwmon_client =
Ben Hutchingse775fb92009-11-23 16:06:02 +0000536 i2c_new_device(&board->i2c_adap,
Ben Hutchings278c0622009-11-23 16:05:12 +0000537 (board->minor < 5) ?
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000538 &sfn4111t_a0_hwmon_info :
539 &sfn4111t_r5_hwmon_info);
Ben Hutchings278c0622009-11-23 16:05:12 +0000540 if (!board->hwmon_client)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000541 return -EIO;
542
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000543 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
544 if (rc)
545 goto fail_hwmon;
546
Ben Hutchings981fc1b2009-11-23 16:04:23 +0000547 if (efx->phy_mode & PHY_MODE_SPECIAL)
548 /* PHY may not generate a 156.25 MHz clock and MAC
549 * stats fetch will fail. */
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000550 falcon_stop_nic_stats(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000551
Ben Hutchings981fc1b2009-11-23 16:04:23 +0000552 return 0;
553
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000554fail_hwmon:
Ben Hutchings278c0622009-11-23 16:05:12 +0000555 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000556 return rc;
557}
558
559/*****************************************************************************
Ben Hutchings8ceee662008-04-27 12:55:59 +0100560 * Support for the SFE4002
561 *
562 */
Ben Hutchings3e133c42008-11-04 20:34:56 +0000563static u8 sfe4002_lm87_channel = 0x03; /* use AIN not FAN inputs */
564
565static const u8 sfe4002_lm87_regs[] = {
Ben Hutchings242cc052010-02-19 13:34:03 +0000566 LM87_IN_LIMITS(0, 0x7c, 0x99), /* 2.5V: 1.8V +/- 10% */
567 LM87_IN_LIMITS(1, 0x4c, 0x5e), /* Vccp1: 1.2V +/- 10% */
568 LM87_IN_LIMITS(2, 0xac, 0xd4), /* 3.3V: 3.3V +/- 10% */
569 LM87_IN_LIMITS(3, 0xac, 0xd4), /* 5V: 5.0V +/- 10% */
570 LM87_IN_LIMITS(4, 0xac, 0xe0), /* 12V: 10.8-14V */
571 LM87_IN_LIMITS(5, 0x3f, 0x4f), /* Vccp2: 1.0V +/- 10% */
572 LM87_AIN_LIMITS(0, 0x98, 0xbb), /* AIN1: 1.66V +/- 10% */
573 LM87_AIN_LIMITS(1, 0x8a, 0xa9), /* AIN2: 1.5V +/- 10% */
574 LM87_TEMP_INT_LIMITS(0, 80 + FALCON_BOARD_TEMP_BIAS),
575 LM87_TEMP_EXT1_LIMITS(0, FALCON_JUNC_TEMP_MAX),
Ben Hutchings3e133c42008-11-04 20:34:56 +0000576 0
577};
578
579static struct i2c_board_info sfe4002_hwmon_info = {
580 I2C_BOARD_INFO("lm87", 0x2e),
581 .platform_data = &sfe4002_lm87_channel,
Ben Hutchings3e133c42008-11-04 20:34:56 +0000582};
583
Ben Hutchings8ceee662008-04-27 12:55:59 +0100584/****************************************************************************/
585/* LED allocations. Note that on rev A0 boards the schematic and the reality
586 * differ: red and green are swapped. Below is the fixed (A1) layout (there
587 * are only 3 A0 boards in existence, so no real reason to make this
588 * conditional).
589 */
590#define SFE4002_FAULT_LED (2) /* Red */
591#define SFE4002_RX_LED (0) /* Green */
592#define SFE4002_TX_LED (1) /* Amber */
593
Ben Hutchings981fc1b2009-11-23 16:04:23 +0000594static void sfe4002_init_phy(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100595{
596 /* Set the TX and RX LEDs to reflect status and activity, and the
597 * fault LED off */
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000598 falcon_qt202x_set_led(efx, SFE4002_TX_LED,
599 QUAKE_LED_TXLINK | QUAKE_LED_LINK_ACTSTAT);
600 falcon_qt202x_set_led(efx, SFE4002_RX_LED,
601 QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACTSTAT);
602 falcon_qt202x_set_led(efx, SFE4002_FAULT_LED, QUAKE_LED_OFF);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100603}
604
Ben Hutchings398468e2009-11-23 16:03:45 +0000605static void sfe4002_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100606{
Ben Hutchings398468e2009-11-23 16:03:45 +0000607 falcon_qt202x_set_led(
608 efx, SFE4002_FAULT_LED,
609 (mode == EFX_LED_ON) ? QUAKE_LED_ON : QUAKE_LED_OFF);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100610}
611
Ben Hutchings3e133c42008-11-04 20:34:56 +0000612static int sfe4002_check_hw(struct efx_nic *efx)
613{
Ben Hutchings278c0622009-11-23 16:05:12 +0000614 struct falcon_board *board = falcon_board(efx);
615
Ben Hutchings3e133c42008-11-04 20:34:56 +0000616 /* A0 board rev. 4002s report a temperature fault the whole time
617 * (bad sensor) so we mask it out. */
618 unsigned alarm_mask =
Ben Hutchings278c0622009-11-23 16:05:12 +0000619 (board->major == 0 && board->minor == 0) ?
Ben Hutchings3e133c42008-11-04 20:34:56 +0000620 ~LM87_ALARM_TEMP_EXT1 : ~0;
621
622 return efx_check_lm87(efx, alarm_mask);
623}
624
Ben Hutchings8ceee662008-04-27 12:55:59 +0100625static int sfe4002_init(struct efx_nic *efx)
626{
Ben Hutchings44838a42009-11-25 16:09:41 +0000627 return efx_init_lm87(efx, &sfe4002_hwmon_info, sfe4002_lm87_regs);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100628}
629
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000630/*****************************************************************************
631 * Support for the SFN4112F
632 *
633 */
634static u8 sfn4112f_lm87_channel = 0x03; /* use AIN not FAN inputs */
635
636static const u8 sfn4112f_lm87_regs[] = {
Ben Hutchings242cc052010-02-19 13:34:03 +0000637 LM87_IN_LIMITS(0, 0x7c, 0x99), /* 2.5V: 1.8V +/- 10% */
638 LM87_IN_LIMITS(1, 0x4c, 0x5e), /* Vccp1: 1.2V +/- 10% */
639 LM87_IN_LIMITS(2, 0xac, 0xd4), /* 3.3V: 3.3V +/- 10% */
640 LM87_IN_LIMITS(4, 0xac, 0xe0), /* 12V: 10.8-14V */
641 LM87_IN_LIMITS(5, 0x3f, 0x4f), /* Vccp2: 1.0V +/- 10% */
642 LM87_AIN_LIMITS(1, 0x8a, 0xa9), /* AIN2: 1.5V +/- 10% */
643 LM87_TEMP_INT_LIMITS(0, 60 + FALCON_BOARD_TEMP_BIAS),
644 LM87_TEMP_EXT1_LIMITS(0, FALCON_JUNC_TEMP_MAX),
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000645 0
646};
647
648static struct i2c_board_info sfn4112f_hwmon_info = {
649 I2C_BOARD_INFO("lm87", 0x2e),
650 .platform_data = &sfn4112f_lm87_channel,
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000651};
652
653#define SFN4112F_ACT_LED 0
654#define SFN4112F_LINK_LED 1
655
Ben Hutchings981fc1b2009-11-23 16:04:23 +0000656static void sfn4112f_init_phy(struct efx_nic *efx)
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000657{
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000658 falcon_qt202x_set_led(efx, SFN4112F_ACT_LED,
659 QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACT);
660 falcon_qt202x_set_led(efx, SFN4112F_LINK_LED,
661 QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000662}
663
Ben Hutchings398468e2009-11-23 16:03:45 +0000664static void sfn4112f_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000665{
Ben Hutchings398468e2009-11-23 16:03:45 +0000666 int reg;
667
668 switch (mode) {
669 case EFX_LED_OFF:
670 reg = QUAKE_LED_OFF;
671 break;
672 case EFX_LED_ON:
673 reg = QUAKE_LED_ON;
674 break;
675 default:
676 reg = QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT;
677 break;
678 }
679
680 falcon_qt202x_set_led(efx, SFN4112F_LINK_LED, reg);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000681}
682
683static int sfn4112f_check_hw(struct efx_nic *efx)
684{
685 /* Mask out unused sensors */
686 return efx_check_lm87(efx, ~0x48);
687}
688
689static int sfn4112f_init(struct efx_nic *efx)
690{
Ben Hutchings44838a42009-11-25 16:09:41 +0000691 return efx_init_lm87(efx, &sfn4112f_hwmon_info, sfn4112f_lm87_regs);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000692}
693
Ben Hutchings44838a42009-11-25 16:09:41 +0000694static const struct falcon_board_type board_types[] = {
695 {
696 .id = FALCON_BOARD_SFE4001,
697 .ref_model = "SFE4001",
698 .gen_type = "10GBASE-T adapter",
699 .init = sfe4001_init,
700 .init_phy = efx_port_dummy_op_void,
701 .fini = sfe4001_fini,
702 .set_id_led = tenxpress_set_id_led,
703 .monitor = sfe4001_check_hw,
704 },
705 {
706 .id = FALCON_BOARD_SFE4002,
707 .ref_model = "SFE4002",
708 .gen_type = "XFP adapter",
709 .init = sfe4002_init,
710 .init_phy = sfe4002_init_phy,
711 .fini = efx_fini_lm87,
712 .set_id_led = sfe4002_set_id_led,
713 .monitor = sfe4002_check_hw,
714 },
715 {
716 .id = FALCON_BOARD_SFN4111T,
717 .ref_model = "SFN4111T",
718 .gen_type = "100/1000/10GBASE-T adapter",
719 .init = sfn4111t_init,
720 .init_phy = sfn4111t_init_phy,
721 .fini = sfn4111t_fini,
722 .set_id_led = tenxpress_set_id_led,
723 .monitor = sfn4111t_check_hw,
724 },
725 {
726 .id = FALCON_BOARD_SFN4112F,
727 .ref_model = "SFN4112F",
728 .gen_type = "SFP+ adapter",
729 .init = sfn4112f_init,
730 .init_phy = sfn4112f_init_phy,
731 .fini = efx_fini_lm87,
732 .set_id_led = sfn4112f_set_id_led,
733 .monitor = sfn4112f_check_hw,
734 },
Ben Hutchings8ceee662008-04-27 12:55:59 +0100735};
736
Ben Hutchingse41c11e2010-04-28 09:01:50 +0000737int falcon_probe_board(struct efx_nic *efx, u16 revision_info)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100738{
Ben Hutchings278c0622009-11-23 16:05:12 +0000739 struct falcon_board *board = falcon_board(efx);
Ben Hutchings44838a42009-11-25 16:09:41 +0000740 u8 type_id = FALCON_BOARD_TYPE(revision_info);
Ben Hutchings04300d22008-12-12 21:48:09 -0800741 int i;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100742
Ben Hutchings278c0622009-11-23 16:05:12 +0000743 board->major = FALCON_BOARD_MAJOR(revision_info);
744 board->minor = FALCON_BOARD_MINOR(revision_info);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100745
Ben Hutchings44838a42009-11-25 16:09:41 +0000746 for (i = 0; i < ARRAY_SIZE(board_types); i++)
747 if (board_types[i].id == type_id)
748 board->type = &board_types[i];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100749
Ben Hutchings44838a42009-11-25 16:09:41 +0000750 if (board->type) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000751 netif_info(efx, probe, efx->net_dev, "board is %s rev %c%d\n",
Ben Hutchings8ceee662008-04-27 12:55:59 +0100752 (efx->pci_dev->subsystem_vendor == EFX_VENDID_SFC)
Ben Hutchings44838a42009-11-25 16:09:41 +0000753 ? board->type->ref_model : board->type->gen_type,
Ben Hutchings278c0622009-11-23 16:05:12 +0000754 'A' + board->major, board->minor);
Ben Hutchingse41c11e2010-04-28 09:01:50 +0000755 return 0;
Ben Hutchings04300d22008-12-12 21:48:09 -0800756 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +0000757 netif_err(efx, probe, efx->net_dev, "unknown board type %d\n",
758 type_id);
Ben Hutchingse41c11e2010-04-28 09:01:50 +0000759 return -ENODEV;
Ben Hutchings04300d22008-12-12 21:48:09 -0800760 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100761}