blob: af7cd2a0b449ebe5182e985ca4cc168b43caee18 [file] [log] [blame]
Ben Hutchings8ceee662008-04-27 12:55:59 +01001/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
Ben Hutchings04300d22008-12-12 21:48:09 -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
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 Hutchingsc9597d42009-10-23 08:29:33 +000015#include "falcon.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 Hutchings8ceee662008-04-27 12:55:59 +010032/*****************************************************************************
Ben Hutchings3e133c42008-11-04 20:34:56 +000033 * Support for LM87 sensor chip used on several boards
34 */
35#define LM87_REG_ALARMS1 0x41
36#define LM87_REG_ALARMS2 0x42
37#define LM87_IN_LIMITS(nr, _min, _max) \
38 0x2B + (nr) * 2, _max, 0x2C + (nr) * 2, _min
39#define LM87_AIN_LIMITS(nr, _min, _max) \
40 0x3B + (nr), _max, 0x1A + (nr), _min
41#define LM87_TEMP_INT_LIMITS(_min, _max) \
42 0x39, _max, 0x3A, _min
43#define LM87_TEMP_EXT1_LIMITS(_min, _max) \
44 0x37, _max, 0x38, _min
45
46#define LM87_ALARM_TEMP_INT 0x10
47#define LM87_ALARM_TEMP_EXT1 0x20
48
49#if defined(CONFIG_SENSORS_LM87) || defined(CONFIG_SENSORS_LM87_MODULE)
50
51static int efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
52 const u8 *reg_values)
53{
54 struct i2c_client *client = i2c_new_device(&efx->i2c_adap, info);
55 int rc;
56
57 if (!client)
58 return -EIO;
59
60 while (*reg_values) {
61 u8 reg = *reg_values++;
62 u8 value = *reg_values++;
63 rc = i2c_smbus_write_byte_data(client, reg, value);
64 if (rc)
65 goto err;
66 }
67
Ben Hutchings278c0622009-11-23 16:05:12 +000068 falcon_board(efx)->hwmon_client = client;
Ben Hutchings3e133c42008-11-04 20:34:56 +000069 return 0;
70
71err:
72 i2c_unregister_device(client);
73 return rc;
74}
75
76static void efx_fini_lm87(struct efx_nic *efx)
77{
Ben Hutchings278c0622009-11-23 16:05:12 +000078 i2c_unregister_device(falcon_board(efx)->hwmon_client);
Ben Hutchings3e133c42008-11-04 20:34:56 +000079}
80
81static int efx_check_lm87(struct efx_nic *efx, unsigned mask)
82{
Ben Hutchings278c0622009-11-23 16:05:12 +000083 struct i2c_client *client = falcon_board(efx)->hwmon_client;
Ben Hutchings3e133c42008-11-04 20:34:56 +000084 s32 alarms1, alarms2;
85
86 /* If link is up then do not monitor temperature */
87 if (EFX_WORKAROUND_7884(efx) && efx->link_up)
88 return 0;
89
90 alarms1 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS1);
91 alarms2 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS2);
92 if (alarms1 < 0)
93 return alarms1;
94 if (alarms2 < 0)
95 return alarms2;
96 alarms1 &= mask;
97 alarms2 &= mask >> 8;
98 if (alarms1 || alarms2) {
99 EFX_ERR(efx,
100 "LM87 detected a hardware failure (status %02x:%02x)"
101 "%s%s\n",
102 alarms1, alarms2,
103 (alarms1 & LM87_ALARM_TEMP_INT) ? " INTERNAL" : "",
104 (alarms1 & LM87_ALARM_TEMP_EXT1) ? " EXTERNAL" : "");
105 return -ERANGE;
106 }
107
108 return 0;
109}
110
111#else /* !CONFIG_SENSORS_LM87 */
112
113static inline int
114efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
115 const u8 *reg_values)
116{
117 return 0;
118}
119static inline void efx_fini_lm87(struct efx_nic *efx)
120{
121}
122static inline int efx_check_lm87(struct efx_nic *efx, unsigned mask)
123{
124 return 0;
125}
126
127#endif /* CONFIG_SENSORS_LM87 */
128
129/*****************************************************************************
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000130 * Support for the SFE4001 and SFN4111T NICs.
131 *
132 * The SFE4001 does not power-up fully at reset due to its high power
133 * consumption. We control its power via a PCA9539 I/O expander.
134 * Both boards have a MAX6647 temperature monitor which we expose to
135 * the lm90 driver.
136 *
137 * This also provides minimal support for reflashing the PHY, which is
138 * initiated by resetting it with the FLASH_CFG_1 pin pulled down.
139 * On SFE4001 rev A2 and later this is connected to the 3V3X output of
140 * the IO-expander; on the SFN4111T it is connected to Falcon's GPIO3.
141 * We represent reflash mode as PHY_MODE_SPECIAL and make it mutually
142 * exclusive with the network device being open.
143 */
144
145/**************************************************************************
146 * Support for I2C IO Expander device on SFE40001
147 */
148#define PCA9539 0x74
149
150#define P0_IN 0x00
151#define P0_OUT 0x02
152#define P0_INVERT 0x04
153#define P0_CONFIG 0x06
154
155#define P0_EN_1V0X_LBN 0
156#define P0_EN_1V0X_WIDTH 1
157#define P0_EN_1V2_LBN 1
158#define P0_EN_1V2_WIDTH 1
159#define P0_EN_2V5_LBN 2
160#define P0_EN_2V5_WIDTH 1
161#define P0_EN_3V3X_LBN 3
162#define P0_EN_3V3X_WIDTH 1
163#define P0_EN_5V_LBN 4
164#define P0_EN_5V_WIDTH 1
165#define P0_SHORTEN_JTAG_LBN 5
166#define P0_SHORTEN_JTAG_WIDTH 1
167#define P0_X_TRST_LBN 6
168#define P0_X_TRST_WIDTH 1
169#define P0_DSP_RESET_LBN 7
170#define P0_DSP_RESET_WIDTH 1
171
172#define P1_IN 0x01
173#define P1_OUT 0x03
174#define P1_INVERT 0x05
175#define P1_CONFIG 0x07
176
177#define P1_AFE_PWD_LBN 0
178#define P1_AFE_PWD_WIDTH 1
179#define P1_DSP_PWD25_LBN 1
180#define P1_DSP_PWD25_WIDTH 1
181#define P1_RESERVED_LBN 2
182#define P1_RESERVED_WIDTH 2
183#define P1_SPARE_LBN 4
184#define P1_SPARE_WIDTH 4
185
186/* Temperature Sensor */
187#define MAX664X_REG_RSL 0x02
188#define MAX664X_REG_WLHO 0x0B
189
190static void sfe4001_poweroff(struct efx_nic *efx)
191{
Ben Hutchings278c0622009-11-23 16:05:12 +0000192 struct i2c_client *ioexp_client = falcon_board(efx)->ioexp_client;
193 struct i2c_client *hwmon_client = falcon_board(efx)->hwmon_client;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000194
195 /* Turn off all power rails and disable outputs */
196 i2c_smbus_write_byte_data(ioexp_client, P0_OUT, 0xff);
197 i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG, 0xff);
198 i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0xff);
199
200 /* Clear any over-temperature alert */
201 i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
202}
203
204static int sfe4001_poweron(struct efx_nic *efx)
205{
Ben Hutchings278c0622009-11-23 16:05:12 +0000206 struct i2c_client *ioexp_client = falcon_board(efx)->ioexp_client;
207 struct i2c_client *hwmon_client = falcon_board(efx)->hwmon_client;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000208 unsigned int i, j;
209 int rc;
210 u8 out;
211
212 /* Clear any previous over-temperature alert */
213 rc = i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
214 if (rc < 0)
215 return rc;
216
217 /* Enable port 0 and port 1 outputs on IO expander */
218 rc = i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0x00);
219 if (rc)
220 return rc;
221 rc = i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG,
222 0xff & ~(1 << P1_SPARE_LBN));
223 if (rc)
224 goto fail_on;
225
226 /* If PHY power is on, turn it all off and wait 1 second to
227 * ensure a full reset.
228 */
229 rc = i2c_smbus_read_byte_data(ioexp_client, P0_OUT);
230 if (rc < 0)
231 goto fail_on;
232 out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
233 (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
234 (0 << P0_EN_1V0X_LBN));
235 if (rc != out) {
236 EFX_INFO(efx, "power-cycling PHY\n");
237 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
238 if (rc)
239 goto fail_on;
240 schedule_timeout_uninterruptible(HZ);
241 }
242
243 for (i = 0; i < 20; ++i) {
244 /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
245 out = 0xff & ~((1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
246 (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
247 (1 << P0_X_TRST_LBN));
248 if (efx->phy_mode & PHY_MODE_SPECIAL)
249 out |= 1 << P0_EN_3V3X_LBN;
250
251 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
252 if (rc)
253 goto fail_on;
254 msleep(10);
255
256 /* Turn on 1V power rail */
257 out &= ~(1 << P0_EN_1V0X_LBN);
258 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
259 if (rc)
260 goto fail_on;
261
262 EFX_INFO(efx, "waiting for DSP boot (attempt %d)...\n", i);
263
264 /* In flash config mode, DSP does not turn on AFE, so
265 * just wait 1 second.
266 */
267 if (efx->phy_mode & PHY_MODE_SPECIAL) {
268 schedule_timeout_uninterruptible(HZ);
269 return 0;
270 }
271
272 for (j = 0; j < 10; ++j) {
273 msleep(100);
274
275 /* Check DSP has asserted AFE power line */
276 rc = i2c_smbus_read_byte_data(ioexp_client, P1_IN);
277 if (rc < 0)
278 goto fail_on;
279 if (rc & (1 << P1_AFE_PWD_LBN))
280 return 0;
281 }
282 }
283
284 EFX_INFO(efx, "timed out waiting for DSP boot\n");
285 rc = -ETIMEDOUT;
286fail_on:
287 sfe4001_poweroff(efx);
288 return rc;
289}
290
291static int sfn4111t_reset(struct efx_nic *efx)
292{
293 efx_oword_t reg;
294
295 /* GPIO 3 and the GPIO register are shared with I2C, so block that */
David S. Miller3505d1a2009-11-18 22:19:03 -0800296 i2c_lock_adapter(&efx->i2c_adap);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000297
298 /* Pull RST_N (GPIO 2) low then let it up again, setting the
299 * FLASH_CFG_1 strap (GPIO 3) appropriately. Only change the
300 * output enables; the output levels should always be 0 (low)
301 * and we rely on external pull-ups. */
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000302 efx_reado(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000303 EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO2_OEN, true);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000304 efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000305 msleep(1000);
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000306 EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO2_OEN, false);
307 EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO3_OEN,
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000308 !!(efx->phy_mode & PHY_MODE_SPECIAL));
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000309 efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000310 msleep(1);
311
David S. Miller3505d1a2009-11-18 22:19:03 -0800312 i2c_unlock_adapter(&efx->i2c_adap);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000313
314 ssleep(1);
315 return 0;
316}
317
318static ssize_t show_phy_flash_cfg(struct device *dev,
319 struct device_attribute *attr, char *buf)
320{
321 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
322 return sprintf(buf, "%d\n", !!(efx->phy_mode & PHY_MODE_SPECIAL));
323}
324
325static ssize_t set_phy_flash_cfg(struct device *dev,
326 struct device_attribute *attr,
327 const char *buf, size_t count)
328{
329 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
330 enum efx_phy_mode old_mode, new_mode;
331 int err;
332
333 rtnl_lock();
334 old_mode = efx->phy_mode;
335 if (count == 0 || *buf == '0')
336 new_mode = old_mode & ~PHY_MODE_SPECIAL;
337 else
338 new_mode = PHY_MODE_SPECIAL;
339 if (old_mode == new_mode) {
340 err = 0;
341 } else if (efx->state != STATE_RUNNING || netif_running(efx->net_dev)) {
342 err = -EBUSY;
343 } else {
344 /* Reset the PHY, reconfigure the MAC and enable/disable
345 * MAC stats accordingly. */
346 efx->phy_mode = new_mode;
347 if (new_mode & PHY_MODE_SPECIAL)
348 efx_stats_disable(efx);
Ben Hutchings278c0622009-11-23 16:05:12 +0000349 if (falcon_board(efx)->type == FALCON_BOARD_SFE4001)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000350 err = sfe4001_poweron(efx);
351 else
352 err = sfn4111t_reset(efx);
353 efx_reconfigure_port(efx);
354 if (!(new_mode & PHY_MODE_SPECIAL))
355 efx_stats_enable(efx);
356 }
357 rtnl_unlock();
358
359 return err ? err : count;
360}
361
362static DEVICE_ATTR(phy_flash_cfg, 0644, show_phy_flash_cfg, set_phy_flash_cfg);
363
364static void sfe4001_fini(struct efx_nic *efx)
365{
Ben Hutchings278c0622009-11-23 16:05:12 +0000366 struct falcon_board *board = falcon_board(efx);
367
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000368 EFX_INFO(efx, "%s\n", __func__);
369
370 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
371 sfe4001_poweroff(efx);
Ben Hutchings278c0622009-11-23 16:05:12 +0000372 i2c_unregister_device(board->ioexp_client);
373 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000374}
375
376static int sfe4001_check_hw(struct efx_nic *efx)
377{
378 s32 status;
379
380 /* If XAUI link is up then do not monitor */
381 if (EFX_WORKAROUND_7884(efx) && efx->mac_up)
382 return 0;
383
384 /* Check the powered status of the PHY. Lack of power implies that
385 * the MAX6647 has shut down power to it, probably due to a temp.
386 * alarm. Reading the power status rather than the MAX6647 status
387 * directly because the later is read-to-clear and would thus
388 * start to power up the PHY again when polled, causing us to blip
389 * the power undesirably.
390 * We know we can read from the IO expander because we did
391 * it during power-on. Assume failure now is bad news. */
Ben Hutchings278c0622009-11-23 16:05:12 +0000392 status = i2c_smbus_read_byte_data(falcon_board(efx)->ioexp_client, P1_IN);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000393 if (status >= 0 &&
394 (status & ((1 << P1_AFE_PWD_LBN) | (1 << P1_DSP_PWD25_LBN))) != 0)
395 return 0;
396
397 /* Use board power control, not PHY power control */
398 sfe4001_poweroff(efx);
399 efx->phy_mode = PHY_MODE_OFF;
400
401 return (status < 0) ? -EIO : -ERANGE;
402}
403
404static struct i2c_board_info sfe4001_hwmon_info = {
405 I2C_BOARD_INFO("max6647", 0x4e),
406};
407
408/* This board uses an I2C expander to provider power to the PHY, which needs to
409 * be turned on before the PHY can be used.
410 * Context: Process context, rtnl lock held
411 */
412static int sfe4001_init(struct efx_nic *efx)
413{
Ben Hutchings278c0622009-11-23 16:05:12 +0000414 struct falcon_board *board = falcon_board(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000415 int rc;
416
417#if defined(CONFIG_SENSORS_LM90) || defined(CONFIG_SENSORS_LM90_MODULE)
Ben Hutchings278c0622009-11-23 16:05:12 +0000418 board->hwmon_client =
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000419 i2c_new_device(&efx->i2c_adap, &sfe4001_hwmon_info);
420#else
Ben Hutchings278c0622009-11-23 16:05:12 +0000421 board->hwmon_client =
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000422 i2c_new_dummy(&efx->i2c_adap, sfe4001_hwmon_info.addr);
423#endif
Ben Hutchings278c0622009-11-23 16:05:12 +0000424 if (!board->hwmon_client)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000425 return -EIO;
426
427 /* Raise board/PHY high limit from 85 to 90 degrees Celsius */
Ben Hutchings278c0622009-11-23 16:05:12 +0000428 rc = i2c_smbus_write_byte_data(board->hwmon_client,
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000429 MAX664X_REG_WLHO, 90);
430 if (rc)
431 goto fail_hwmon;
432
Ben Hutchings278c0622009-11-23 16:05:12 +0000433 board->ioexp_client = i2c_new_dummy(&efx->i2c_adap, PCA9539);
434 if (!board->ioexp_client) {
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000435 rc = -EIO;
436 goto fail_hwmon;
437 }
438
439 /* 10Xpress has fixed-function LED pins, so there is no board-specific
440 * blink code. */
Ben Hutchings278c0622009-11-23 16:05:12 +0000441 board->set_id_led = tenxpress_set_id_led;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000442
Ben Hutchings278c0622009-11-23 16:05:12 +0000443 board->monitor = sfe4001_check_hw;
444 board->fini = sfe4001_fini;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000445
446 if (efx->phy_mode & PHY_MODE_SPECIAL) {
447 /* PHY won't generate a 156.25 MHz clock and MAC stats fetch
448 * will fail. */
449 efx_stats_disable(efx);
450 }
451 rc = sfe4001_poweron(efx);
452 if (rc)
453 goto fail_ioexp;
454
455 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
456 if (rc)
457 goto fail_on;
458
459 EFX_INFO(efx, "PHY is powered on\n");
460 return 0;
461
462fail_on:
463 sfe4001_poweroff(efx);
464fail_ioexp:
Ben Hutchings278c0622009-11-23 16:05:12 +0000465 i2c_unregister_device(board->ioexp_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000466fail_hwmon:
Ben Hutchings278c0622009-11-23 16:05:12 +0000467 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000468 return rc;
469}
470
471static int sfn4111t_check_hw(struct efx_nic *efx)
472{
473 s32 status;
474
475 /* If XAUI link is up then do not monitor */
476 if (EFX_WORKAROUND_7884(efx) && efx->mac_up)
477 return 0;
478
479 /* Test LHIGH, RHIGH, FAULT, EOT and IOT alarms */
Ben Hutchings278c0622009-11-23 16:05:12 +0000480 status = i2c_smbus_read_byte_data(falcon_board(efx)->hwmon_client,
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000481 MAX664X_REG_RSL);
482 if (status < 0)
483 return -EIO;
484 if (status & 0x57)
485 return -ERANGE;
486 return 0;
487}
488
489static void sfn4111t_fini(struct efx_nic *efx)
490{
491 EFX_INFO(efx, "%s\n", __func__);
492
493 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
Ben Hutchings278c0622009-11-23 16:05:12 +0000494 i2c_unregister_device(falcon_board(efx)->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000495}
496
497static struct i2c_board_info sfn4111t_a0_hwmon_info = {
498 I2C_BOARD_INFO("max6647", 0x4e),
499};
500
501static struct i2c_board_info sfn4111t_r5_hwmon_info = {
502 I2C_BOARD_INFO("max6646", 0x4d),
503};
504
Ben Hutchings981fc1b42009-11-23 16:04:23 +0000505static void sfn4111t_init_phy(struct efx_nic *efx)
506{
507 if (!(efx->phy_mode & PHY_MODE_SPECIAL)) {
508 if (sft9001_wait_boot(efx) != -EINVAL)
509 return;
510
511 efx->phy_mode = PHY_MODE_SPECIAL;
512 efx_stats_disable(efx);
513 }
514
515 sfn4111t_reset(efx);
516 sft9001_wait_boot(efx);
517}
518
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000519static int sfn4111t_init(struct efx_nic *efx)
520{
Ben Hutchings278c0622009-11-23 16:05:12 +0000521 struct falcon_board *board = falcon_board(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000522 int rc;
523
Ben Hutchings278c0622009-11-23 16:05:12 +0000524 board->hwmon_client =
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000525 i2c_new_device(&efx->i2c_adap,
Ben Hutchings278c0622009-11-23 16:05:12 +0000526 (board->minor < 5) ?
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000527 &sfn4111t_a0_hwmon_info :
528 &sfn4111t_r5_hwmon_info);
Ben Hutchings278c0622009-11-23 16:05:12 +0000529 if (!board->hwmon_client)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000530 return -EIO;
531
Ben Hutchings278c0622009-11-23 16:05:12 +0000532 board->init_phy = sfn4111t_init_phy;
533 board->set_id_led = tenxpress_set_id_led;
534 board->monitor = sfn4111t_check_hw;
535 board->fini = sfn4111t_fini;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000536
537 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
538 if (rc)
539 goto fail_hwmon;
540
Ben Hutchings981fc1b42009-11-23 16:04:23 +0000541 if (efx->phy_mode & PHY_MODE_SPECIAL)
542 /* PHY may not generate a 156.25 MHz clock and MAC
543 * stats fetch will fail. */
544 efx_stats_disable(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000545
Ben Hutchings981fc1b42009-11-23 16:04:23 +0000546 return 0;
547
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000548fail_hwmon:
Ben Hutchings278c0622009-11-23 16:05:12 +0000549 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000550 return rc;
551}
552
553/*****************************************************************************
Ben Hutchings8ceee662008-04-27 12:55:59 +0100554 * Support for the SFE4002
555 *
556 */
Ben Hutchings3e133c42008-11-04 20:34:56 +0000557static u8 sfe4002_lm87_channel = 0x03; /* use AIN not FAN inputs */
558
559static const u8 sfe4002_lm87_regs[] = {
560 LM87_IN_LIMITS(0, 0x83, 0x91), /* 2.5V: 1.8V +/- 5% */
561 LM87_IN_LIMITS(1, 0x51, 0x5a), /* Vccp1: 1.2V +/- 5% */
562 LM87_IN_LIMITS(2, 0xb6, 0xca), /* 3.3V: 3.3V +/- 5% */
563 LM87_IN_LIMITS(3, 0xb0, 0xc9), /* 5V: 4.6-5.2V */
564 LM87_IN_LIMITS(4, 0xb0, 0xe0), /* 12V: 11-14V */
565 LM87_IN_LIMITS(5, 0x44, 0x4b), /* Vccp2: 1.0V +/- 5% */
566 LM87_AIN_LIMITS(0, 0xa0, 0xb2), /* AIN1: 1.66V +/- 5% */
567 LM87_AIN_LIMITS(1, 0x91, 0xa1), /* AIN2: 1.5V +/- 5% */
568 LM87_TEMP_INT_LIMITS(10, 60), /* board */
569 LM87_TEMP_EXT1_LIMITS(10, 70), /* Falcon */
570 0
571};
572
573static struct i2c_board_info sfe4002_hwmon_info = {
574 I2C_BOARD_INFO("lm87", 0x2e),
575 .platform_data = &sfe4002_lm87_channel,
Ben Hutchings3e133c42008-11-04 20:34:56 +0000576};
577
Ben Hutchings8ceee662008-04-27 12:55:59 +0100578/****************************************************************************/
579/* LED allocations. Note that on rev A0 boards the schematic and the reality
580 * differ: red and green are swapped. Below is the fixed (A1) layout (there
581 * are only 3 A0 boards in existence, so no real reason to make this
582 * conditional).
583 */
584#define SFE4002_FAULT_LED (2) /* Red */
585#define SFE4002_RX_LED (0) /* Green */
586#define SFE4002_TX_LED (1) /* Amber */
587
Ben Hutchings981fc1b42009-11-23 16:04:23 +0000588static void sfe4002_init_phy(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100589{
590 /* Set the TX and RX LEDs to reflect status and activity, and the
591 * fault LED off */
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000592 falcon_qt202x_set_led(efx, SFE4002_TX_LED,
593 QUAKE_LED_TXLINK | QUAKE_LED_LINK_ACTSTAT);
594 falcon_qt202x_set_led(efx, SFE4002_RX_LED,
595 QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACTSTAT);
596 falcon_qt202x_set_led(efx, SFE4002_FAULT_LED, QUAKE_LED_OFF);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100597}
598
Ben Hutchings398468e2009-11-23 16:03:45 +0000599static void sfe4002_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100600{
Ben Hutchings398468e2009-11-23 16:03:45 +0000601 falcon_qt202x_set_led(
602 efx, SFE4002_FAULT_LED,
603 (mode == EFX_LED_ON) ? QUAKE_LED_ON : QUAKE_LED_OFF);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100604}
605
Ben Hutchings3e133c42008-11-04 20:34:56 +0000606static int sfe4002_check_hw(struct efx_nic *efx)
607{
Ben Hutchings278c0622009-11-23 16:05:12 +0000608 struct falcon_board *board = falcon_board(efx);
609
Ben Hutchings3e133c42008-11-04 20:34:56 +0000610 /* A0 board rev. 4002s report a temperature fault the whole time
611 * (bad sensor) so we mask it out. */
612 unsigned alarm_mask =
Ben Hutchings278c0622009-11-23 16:05:12 +0000613 (board->major == 0 && board->minor == 0) ?
Ben Hutchings3e133c42008-11-04 20:34:56 +0000614 ~LM87_ALARM_TEMP_EXT1 : ~0;
615
616 return efx_check_lm87(efx, alarm_mask);
617}
618
Ben Hutchings8ceee662008-04-27 12:55:59 +0100619static int sfe4002_init(struct efx_nic *efx)
620{
Ben Hutchings278c0622009-11-23 16:05:12 +0000621 struct falcon_board *board = falcon_board(efx);
Ben Hutchings3e133c42008-11-04 20:34:56 +0000622 int rc = efx_init_lm87(efx, &sfe4002_hwmon_info, sfe4002_lm87_regs);
623 if (rc)
624 return rc;
Ben Hutchings278c0622009-11-23 16:05:12 +0000625 board->monitor = sfe4002_check_hw;
626 board->init_phy = sfe4002_init_phy;
627 board->set_id_led = sfe4002_set_id_led;
628 board->fini = efx_fini_lm87;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100629 return 0;
630}
631
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000632/*****************************************************************************
633 * Support for the SFN4112F
634 *
635 */
636static u8 sfn4112f_lm87_channel = 0x03; /* use AIN not FAN inputs */
637
638static const u8 sfn4112f_lm87_regs[] = {
639 LM87_IN_LIMITS(0, 0x83, 0x91), /* 2.5V: 1.8V +/- 5% */
640 LM87_IN_LIMITS(1, 0x51, 0x5a), /* Vccp1: 1.2V +/- 5% */
641 LM87_IN_LIMITS(2, 0xb6, 0xca), /* 3.3V: 3.3V +/- 5% */
642 LM87_IN_LIMITS(4, 0xb0, 0xe0), /* 12V: 11-14V */
643 LM87_IN_LIMITS(5, 0x44, 0x4b), /* Vccp2: 1.0V +/- 5% */
644 LM87_AIN_LIMITS(1, 0x91, 0xa1), /* AIN2: 1.5V +/- 5% */
645 LM87_TEMP_INT_LIMITS(10, 60), /* board */
646 LM87_TEMP_EXT1_LIMITS(10, 70), /* Falcon */
647 0
648};
649
650static struct i2c_board_info sfn4112f_hwmon_info = {
651 I2C_BOARD_INFO("lm87", 0x2e),
652 .platform_data = &sfn4112f_lm87_channel,
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000653};
654
655#define SFN4112F_ACT_LED 0
656#define SFN4112F_LINK_LED 1
657
Ben Hutchings981fc1b42009-11-23 16:04:23 +0000658static void sfn4112f_init_phy(struct efx_nic *efx)
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000659{
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000660 falcon_qt202x_set_led(efx, SFN4112F_ACT_LED,
661 QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACT);
662 falcon_qt202x_set_led(efx, SFN4112F_LINK_LED,
663 QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000664}
665
Ben Hutchings398468e2009-11-23 16:03:45 +0000666static void sfn4112f_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000667{
Ben Hutchings398468e2009-11-23 16:03:45 +0000668 int reg;
669
670 switch (mode) {
671 case EFX_LED_OFF:
672 reg = QUAKE_LED_OFF;
673 break;
674 case EFX_LED_ON:
675 reg = QUAKE_LED_ON;
676 break;
677 default:
678 reg = QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT;
679 break;
680 }
681
682 falcon_qt202x_set_led(efx, SFN4112F_LINK_LED, reg);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000683}
684
685static int sfn4112f_check_hw(struct efx_nic *efx)
686{
687 /* Mask out unused sensors */
688 return efx_check_lm87(efx, ~0x48);
689}
690
691static int sfn4112f_init(struct efx_nic *efx)
692{
Ben Hutchings278c0622009-11-23 16:05:12 +0000693 struct falcon_board *board = falcon_board(efx);
694
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000695 int rc = efx_init_lm87(efx, &sfn4112f_hwmon_info, sfn4112f_lm87_regs);
696 if (rc)
697 return rc;
Ben Hutchings278c0622009-11-23 16:05:12 +0000698 board->monitor = sfn4112f_check_hw;
699 board->init_phy = sfn4112f_init_phy;
700 board->set_id_led = sfn4112f_set_id_led;
701 board->fini = efx_fini_lm87;
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000702 return 0;
703}
704
Ben Hutchings8ceee662008-04-27 12:55:59 +0100705/* This will get expanded as board-specific details get moved out of the
706 * PHY drivers. */
Ben Hutchings3473a5b2009-10-23 08:29:16 +0000707struct falcon_board_data {
708 u8 type;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100709 const char *ref_model;
710 const char *gen_type;
711 int (*init) (struct efx_nic *nic);
712};
713
Ben Hutchings8ceee662008-04-27 12:55:59 +0100714
Ben Hutchings3473a5b2009-10-23 08:29:16 +0000715static struct falcon_board_data board_data[] = {
716 { FALCON_BOARD_SFE4001, "SFE4001", "10GBASE-T adapter", sfe4001_init },
717 { FALCON_BOARD_SFE4002, "SFE4002", "XFP adapter", sfe4002_init },
718 { FALCON_BOARD_SFN4111T, "SFN4111T", "100/1000/10GBASE-T adapter",
Ben Hutchings6f158d52008-12-12 22:00:49 -0800719 sfn4111t_init },
Ben Hutchings3473a5b2009-10-23 08:29:16 +0000720 { FALCON_BOARD_SFN4112F, "SFN4112F", "SFP+ adapter",
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000721 sfn4112f_init },
Ben Hutchings8ceee662008-04-27 12:55:59 +0100722};
723
Ben Hutchings3473a5b2009-10-23 08:29:16 +0000724void falcon_probe_board(struct efx_nic *efx, u16 revision_info)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100725{
Ben Hutchings278c0622009-11-23 16:05:12 +0000726 struct falcon_board *board = falcon_board(efx);
Ben Hutchings3473a5b2009-10-23 08:29:16 +0000727 struct falcon_board_data *data = NULL;
Ben Hutchings04300d22008-12-12 21:48:09 -0800728 int i;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100729
Ben Hutchings278c0622009-11-23 16:05:12 +0000730 board->type = FALCON_BOARD_TYPE(revision_info);
731 board->major = FALCON_BOARD_MAJOR(revision_info);
732 board->minor = FALCON_BOARD_MINOR(revision_info);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100733
Ben Hutchings04300d22008-12-12 21:48:09 -0800734 for (i = 0; i < ARRAY_SIZE(board_data); i++)
Ben Hutchings278c0622009-11-23 16:05:12 +0000735 if (board_data[i].type == board->type)
Ben Hutchings04300d22008-12-12 21:48:09 -0800736 data = &board_data[i];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100737
Ben Hutchings04300d22008-12-12 21:48:09 -0800738 if (data) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100739 EFX_INFO(efx, "board is %s rev %c%d\n",
740 (efx->pci_dev->subsystem_vendor == EFX_VENDID_SFC)
741 ? data->ref_model : data->gen_type,
Ben Hutchings278c0622009-11-23 16:05:12 +0000742 'A' + board->major, board->minor);
743 board->init = data->init;
Ben Hutchings04300d22008-12-12 21:48:09 -0800744 } else {
Ben Hutchings278c0622009-11-23 16:05:12 +0000745 EFX_ERR(efx, "unknown board type %d\n", board->type);
Ben Hutchings04300d22008-12-12 21:48:09 -0800746 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100747}