blob: f05c9d330a467907d95aa349283a2cd042ec8044 [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{
Ben Hutchingse775fb92009-11-23 16:06:02 +000054 struct falcon_board *board = falcon_board(efx);
55 struct i2c_client *client = i2c_new_device(&board->i2c_adap, info);
Ben Hutchings3e133c42008-11-04 20:34:56 +000056 int rc;
57
58 if (!client)
59 return -EIO;
60
61 while (*reg_values) {
62 u8 reg = *reg_values++;
63 u8 value = *reg_values++;
64 rc = i2c_smbus_write_byte_data(client, reg, value);
65 if (rc)
66 goto err;
67 }
68
Ben Hutchingse775fb92009-11-23 16:06:02 +000069 board->hwmon_client = client;
Ben Hutchings3e133c42008-11-04 20:34:56 +000070 return 0;
71
72err:
73 i2c_unregister_device(client);
74 return rc;
75}
76
77static void efx_fini_lm87(struct efx_nic *efx)
78{
Ben Hutchings278c0622009-11-23 16:05:12 +000079 i2c_unregister_device(falcon_board(efx)->hwmon_client);
Ben Hutchings3e133c42008-11-04 20:34:56 +000080}
81
82static int efx_check_lm87(struct efx_nic *efx, unsigned mask)
83{
Ben Hutchings278c0622009-11-23 16:05:12 +000084 struct i2c_client *client = falcon_board(efx)->hwmon_client;
Ben Hutchings3e133c42008-11-04 20:34:56 +000085 s32 alarms1, alarms2;
86
87 /* If link is up then do not monitor temperature */
Ben Hutchingseb50c0d2009-11-23 16:06:30 +000088 if (EFX_WORKAROUND_7884(efx) && efx->link_state.up)
Ben Hutchings3e133c42008-11-04 20:34:56 +000089 return 0;
90
91 alarms1 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS1);
92 alarms2 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS2);
93 if (alarms1 < 0)
94 return alarms1;
95 if (alarms2 < 0)
96 return alarms2;
97 alarms1 &= mask;
98 alarms2 &= mask >> 8;
99 if (alarms1 || alarms2) {
100 EFX_ERR(efx,
101 "LM87 detected a hardware failure (status %02x:%02x)"
102 "%s%s\n",
103 alarms1, alarms2,
104 (alarms1 & LM87_ALARM_TEMP_INT) ? " INTERNAL" : "",
105 (alarms1 & LM87_ALARM_TEMP_EXT1) ? " EXTERNAL" : "");
106 return -ERANGE;
107 }
108
109 return 0;
110}
111
112#else /* !CONFIG_SENSORS_LM87 */
113
114static inline int
115efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
116 const u8 *reg_values)
117{
118 return 0;
119}
120static inline void efx_fini_lm87(struct efx_nic *efx)
121{
122}
123static inline int efx_check_lm87(struct efx_nic *efx, unsigned mask)
124{
125 return 0;
126}
127
128#endif /* CONFIG_SENSORS_LM87 */
129
130/*****************************************************************************
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000131 * Support for the SFE4001 and SFN4111T NICs.
132 *
133 * The SFE4001 does not power-up fully at reset due to its high power
134 * consumption. We control its power via a PCA9539 I/O expander.
135 * Both boards have a MAX6647 temperature monitor which we expose to
136 * the lm90 driver.
137 *
138 * This also provides minimal support for reflashing the PHY, which is
139 * initiated by resetting it with the FLASH_CFG_1 pin pulled down.
140 * On SFE4001 rev A2 and later this is connected to the 3V3X output of
141 * the IO-expander; on the SFN4111T it is connected to Falcon's GPIO3.
142 * We represent reflash mode as PHY_MODE_SPECIAL and make it mutually
143 * exclusive with the network device being open.
144 */
145
146/**************************************************************************
Ben Hutchings89863522009-11-25 16:09:04 +0000147 * Support for I2C IO Expander device on SFE4001
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000148 */
149#define PCA9539 0x74
150
151#define P0_IN 0x00
152#define P0_OUT 0x02
153#define P0_INVERT 0x04
154#define P0_CONFIG 0x06
155
156#define P0_EN_1V0X_LBN 0
157#define P0_EN_1V0X_WIDTH 1
158#define P0_EN_1V2_LBN 1
159#define P0_EN_1V2_WIDTH 1
160#define P0_EN_2V5_LBN 2
161#define P0_EN_2V5_WIDTH 1
162#define P0_EN_3V3X_LBN 3
163#define P0_EN_3V3X_WIDTH 1
164#define P0_EN_5V_LBN 4
165#define P0_EN_5V_WIDTH 1
166#define P0_SHORTEN_JTAG_LBN 5
167#define P0_SHORTEN_JTAG_WIDTH 1
168#define P0_X_TRST_LBN 6
169#define P0_X_TRST_WIDTH 1
170#define P0_DSP_RESET_LBN 7
171#define P0_DSP_RESET_WIDTH 1
172
173#define P1_IN 0x01
174#define P1_OUT 0x03
175#define P1_INVERT 0x05
176#define P1_CONFIG 0x07
177
178#define P1_AFE_PWD_LBN 0
179#define P1_AFE_PWD_WIDTH 1
180#define P1_DSP_PWD25_LBN 1
181#define P1_DSP_PWD25_WIDTH 1
182#define P1_RESERVED_LBN 2
183#define P1_RESERVED_WIDTH 2
184#define P1_SPARE_LBN 4
185#define P1_SPARE_WIDTH 4
186
187/* Temperature Sensor */
188#define MAX664X_REG_RSL 0x02
189#define MAX664X_REG_WLHO 0x0B
190
191static void sfe4001_poweroff(struct efx_nic *efx)
192{
Ben Hutchings278c0622009-11-23 16:05:12 +0000193 struct i2c_client *ioexp_client = falcon_board(efx)->ioexp_client;
194 struct i2c_client *hwmon_client = falcon_board(efx)->hwmon_client;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000195
196 /* Turn off all power rails and disable outputs */
197 i2c_smbus_write_byte_data(ioexp_client, P0_OUT, 0xff);
198 i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG, 0xff);
199 i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0xff);
200
201 /* Clear any over-temperature alert */
202 i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
203}
204
205static int sfe4001_poweron(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 unsigned int i, j;
210 int rc;
211 u8 out;
212
213 /* Clear any previous over-temperature alert */
214 rc = i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
215 if (rc < 0)
216 return rc;
217
218 /* Enable port 0 and port 1 outputs on IO expander */
219 rc = i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0x00);
220 if (rc)
221 return rc;
222 rc = i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG,
223 0xff & ~(1 << P1_SPARE_LBN));
224 if (rc)
225 goto fail_on;
226
227 /* If PHY power is on, turn it all off and wait 1 second to
228 * ensure a full reset.
229 */
230 rc = i2c_smbus_read_byte_data(ioexp_client, P0_OUT);
231 if (rc < 0)
232 goto fail_on;
233 out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
234 (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
235 (0 << P0_EN_1V0X_LBN));
236 if (rc != out) {
237 EFX_INFO(efx, "power-cycling PHY\n");
238 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
239 if (rc)
240 goto fail_on;
241 schedule_timeout_uninterruptible(HZ);
242 }
243
244 for (i = 0; i < 20; ++i) {
245 /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
246 out = 0xff & ~((1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
247 (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
248 (1 << P0_X_TRST_LBN));
249 if (efx->phy_mode & PHY_MODE_SPECIAL)
250 out |= 1 << P0_EN_3V3X_LBN;
251
252 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
253 if (rc)
254 goto fail_on;
255 msleep(10);
256
257 /* Turn on 1V power rail */
258 out &= ~(1 << P0_EN_1V0X_LBN);
259 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
260 if (rc)
261 goto fail_on;
262
263 EFX_INFO(efx, "waiting for DSP boot (attempt %d)...\n", i);
264
265 /* In flash config mode, DSP does not turn on AFE, so
266 * just wait 1 second.
267 */
268 if (efx->phy_mode & PHY_MODE_SPECIAL) {
269 schedule_timeout_uninterruptible(HZ);
270 return 0;
271 }
272
273 for (j = 0; j < 10; ++j) {
274 msleep(100);
275
276 /* Check DSP has asserted AFE power line */
277 rc = i2c_smbus_read_byte_data(ioexp_client, P1_IN);
278 if (rc < 0)
279 goto fail_on;
280 if (rc & (1 << P1_AFE_PWD_LBN))
281 return 0;
282 }
283 }
284
285 EFX_INFO(efx, "timed out waiting for DSP boot\n");
286 rc = -ETIMEDOUT;
287fail_on:
288 sfe4001_poweroff(efx);
289 return rc;
290}
291
292static int sfn4111t_reset(struct efx_nic *efx)
293{
Ben Hutchingse775fb92009-11-23 16:06:02 +0000294 struct falcon_board *board = falcon_board(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000295 efx_oword_t reg;
296
297 /* GPIO 3 and the GPIO register are shared with I2C, so block that */
Ben Hutchingse775fb92009-11-23 16:06:02 +0000298 i2c_lock_adapter(&board->i2c_adap);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000299
300 /* Pull RST_N (GPIO 2) low then let it up again, setting the
301 * FLASH_CFG_1 strap (GPIO 3) appropriately. Only change the
302 * output enables; the output levels should always be 0 (low)
303 * and we rely on external pull-ups. */
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000304 efx_reado(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000305 EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO2_OEN, true);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000306 efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000307 msleep(1000);
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000308 EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO2_OEN, false);
309 EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO3_OEN,
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000310 !!(efx->phy_mode & PHY_MODE_SPECIAL));
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000311 efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000312 msleep(1);
313
Ben Hutchingse775fb92009-11-23 16:06:02 +0000314 i2c_unlock_adapter(&board->i2c_adap);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000315
316 ssleep(1);
317 return 0;
318}
319
320static ssize_t show_phy_flash_cfg(struct device *dev,
321 struct device_attribute *attr, char *buf)
322{
323 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
324 return sprintf(buf, "%d\n", !!(efx->phy_mode & PHY_MODE_SPECIAL));
325}
326
327static ssize_t set_phy_flash_cfg(struct device *dev,
328 struct device_attribute *attr,
329 const char *buf, size_t count)
330{
331 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
332 enum efx_phy_mode old_mode, new_mode;
333 int err;
334
335 rtnl_lock();
336 old_mode = efx->phy_mode;
337 if (count == 0 || *buf == '0')
338 new_mode = old_mode & ~PHY_MODE_SPECIAL;
339 else
340 new_mode = PHY_MODE_SPECIAL;
341 if (old_mode == new_mode) {
342 err = 0;
343 } else if (efx->state != STATE_RUNNING || netif_running(efx->net_dev)) {
344 err = -EBUSY;
345 } else {
346 /* Reset the PHY, reconfigure the MAC and enable/disable
347 * MAC stats accordingly. */
348 efx->phy_mode = new_mode;
349 if (new_mode & PHY_MODE_SPECIAL)
350 efx_stats_disable(efx);
Ben Hutchings278c0622009-11-23 16:05:12 +0000351 if (falcon_board(efx)->type == FALCON_BOARD_SFE4001)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000352 err = sfe4001_poweron(efx);
353 else
354 err = sfn4111t_reset(efx);
355 efx_reconfigure_port(efx);
356 if (!(new_mode & PHY_MODE_SPECIAL))
357 efx_stats_enable(efx);
358 }
359 rtnl_unlock();
360
361 return err ? err : count;
362}
363
364static DEVICE_ATTR(phy_flash_cfg, 0644, show_phy_flash_cfg, set_phy_flash_cfg);
365
366static void sfe4001_fini(struct efx_nic *efx)
367{
Ben Hutchings278c0622009-11-23 16:05:12 +0000368 struct falcon_board *board = falcon_board(efx);
369
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000370 EFX_INFO(efx, "%s\n", __func__);
371
372 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
373 sfe4001_poweroff(efx);
Ben Hutchings278c0622009-11-23 16:05:12 +0000374 i2c_unregister_device(board->ioexp_client);
375 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000376}
377
378static int sfe4001_check_hw(struct efx_nic *efx)
379{
380 s32 status;
381
382 /* If XAUI link is up then do not monitor */
383 if (EFX_WORKAROUND_7884(efx) && efx->mac_up)
384 return 0;
385
386 /* Check the powered status of the PHY. Lack of power implies that
387 * the MAX6647 has shut down power to it, probably due to a temp.
388 * alarm. Reading the power status rather than the MAX6647 status
389 * directly because the later is read-to-clear and would thus
390 * start to power up the PHY again when polled, causing us to blip
391 * the power undesirably.
392 * We know we can read from the IO expander because we did
393 * it during power-on. Assume failure now is bad news. */
Ben Hutchings278c0622009-11-23 16:05:12 +0000394 status = i2c_smbus_read_byte_data(falcon_board(efx)->ioexp_client, P1_IN);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000395 if (status >= 0 &&
396 (status & ((1 << P1_AFE_PWD_LBN) | (1 << P1_DSP_PWD25_LBN))) != 0)
397 return 0;
398
399 /* Use board power control, not PHY power control */
400 sfe4001_poweroff(efx);
401 efx->phy_mode = PHY_MODE_OFF;
402
403 return (status < 0) ? -EIO : -ERANGE;
404}
405
406static struct i2c_board_info sfe4001_hwmon_info = {
407 I2C_BOARD_INFO("max6647", 0x4e),
408};
409
410/* This board uses an I2C expander to provider power to the PHY, which needs to
411 * be turned on before the PHY can be used.
412 * Context: Process context, rtnl lock held
413 */
414static int sfe4001_init(struct efx_nic *efx)
415{
Ben Hutchings278c0622009-11-23 16:05:12 +0000416 struct falcon_board *board = falcon_board(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000417 int rc;
418
419#if defined(CONFIG_SENSORS_LM90) || defined(CONFIG_SENSORS_LM90_MODULE)
Ben Hutchings278c0622009-11-23 16:05:12 +0000420 board->hwmon_client =
Ben Hutchingse775fb92009-11-23 16:06:02 +0000421 i2c_new_device(&board->i2c_adap, &sfe4001_hwmon_info);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000422#else
Ben Hutchings278c0622009-11-23 16:05:12 +0000423 board->hwmon_client =
Ben Hutchingse775fb92009-11-23 16:06:02 +0000424 i2c_new_dummy(&board->i2c_adap, sfe4001_hwmon_info.addr);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000425#endif
Ben Hutchings278c0622009-11-23 16:05:12 +0000426 if (!board->hwmon_client)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000427 return -EIO;
428
429 /* Raise board/PHY high limit from 85 to 90 degrees Celsius */
Ben Hutchings278c0622009-11-23 16:05:12 +0000430 rc = i2c_smbus_write_byte_data(board->hwmon_client,
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000431 MAX664X_REG_WLHO, 90);
432 if (rc)
433 goto fail_hwmon;
434
Ben Hutchingse775fb92009-11-23 16:06:02 +0000435 board->ioexp_client = i2c_new_dummy(&board->i2c_adap, PCA9539);
Ben Hutchings278c0622009-11-23 16:05:12 +0000436 if (!board->ioexp_client) {
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000437 rc = -EIO;
438 goto fail_hwmon;
439 }
440
441 /* 10Xpress has fixed-function LED pins, so there is no board-specific
442 * blink code. */
Ben Hutchings278c0622009-11-23 16:05:12 +0000443 board->set_id_led = tenxpress_set_id_led;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000444
Ben Hutchings278c0622009-11-23 16:05:12 +0000445 board->monitor = sfe4001_check_hw;
446 board->fini = sfe4001_fini;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000447
448 if (efx->phy_mode & PHY_MODE_SPECIAL) {
449 /* PHY won't generate a 156.25 MHz clock and MAC stats fetch
450 * will fail. */
451 efx_stats_disable(efx);
452 }
453 rc = sfe4001_poweron(efx);
454 if (rc)
455 goto fail_ioexp;
456
457 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
458 if (rc)
459 goto fail_on;
460
461 EFX_INFO(efx, "PHY is powered on\n");
462 return 0;
463
464fail_on:
465 sfe4001_poweroff(efx);
466fail_ioexp:
Ben Hutchings278c0622009-11-23 16:05:12 +0000467 i2c_unregister_device(board->ioexp_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000468fail_hwmon:
Ben Hutchings278c0622009-11-23 16:05:12 +0000469 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000470 return rc;
471}
472
473static int sfn4111t_check_hw(struct efx_nic *efx)
474{
475 s32 status;
476
477 /* If XAUI link is up then do not monitor */
478 if (EFX_WORKAROUND_7884(efx) && efx->mac_up)
479 return 0;
480
481 /* Test LHIGH, RHIGH, FAULT, EOT and IOT alarms */
Ben Hutchings278c0622009-11-23 16:05:12 +0000482 status = i2c_smbus_read_byte_data(falcon_board(efx)->hwmon_client,
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000483 MAX664X_REG_RSL);
484 if (status < 0)
485 return -EIO;
486 if (status & 0x57)
487 return -ERANGE;
488 return 0;
489}
490
491static void sfn4111t_fini(struct efx_nic *efx)
492{
493 EFX_INFO(efx, "%s\n", __func__);
494
495 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
Ben Hutchings278c0622009-11-23 16:05:12 +0000496 i2c_unregister_device(falcon_board(efx)->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000497}
498
499static struct i2c_board_info sfn4111t_a0_hwmon_info = {
500 I2C_BOARD_INFO("max6647", 0x4e),
501};
502
503static struct i2c_board_info sfn4111t_r5_hwmon_info = {
504 I2C_BOARD_INFO("max6646", 0x4d),
505};
506
Ben Hutchings981fc1b42009-11-23 16:04:23 +0000507static void sfn4111t_init_phy(struct efx_nic *efx)
508{
509 if (!(efx->phy_mode & PHY_MODE_SPECIAL)) {
510 if (sft9001_wait_boot(efx) != -EINVAL)
511 return;
512
513 efx->phy_mode = PHY_MODE_SPECIAL;
514 efx_stats_disable(efx);
515 }
516
517 sfn4111t_reset(efx);
518 sft9001_wait_boot(efx);
519}
520
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000521static int sfn4111t_init(struct efx_nic *efx)
522{
Ben Hutchings278c0622009-11-23 16:05:12 +0000523 struct falcon_board *board = falcon_board(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000524 int rc;
525
Ben Hutchings278c0622009-11-23 16:05:12 +0000526 board->hwmon_client =
Ben Hutchingse775fb92009-11-23 16:06:02 +0000527 i2c_new_device(&board->i2c_adap,
Ben Hutchings278c0622009-11-23 16:05:12 +0000528 (board->minor < 5) ?
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000529 &sfn4111t_a0_hwmon_info :
530 &sfn4111t_r5_hwmon_info);
Ben Hutchings278c0622009-11-23 16:05:12 +0000531 if (!board->hwmon_client)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000532 return -EIO;
533
Ben Hutchings278c0622009-11-23 16:05:12 +0000534 board->init_phy = sfn4111t_init_phy;
535 board->set_id_led = tenxpress_set_id_led;
536 board->monitor = sfn4111t_check_hw;
537 board->fini = sfn4111t_fini;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000538
539 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
540 if (rc)
541 goto fail_hwmon;
542
Ben Hutchings981fc1b42009-11-23 16:04:23 +0000543 if (efx->phy_mode & PHY_MODE_SPECIAL)
544 /* PHY may not generate a 156.25 MHz clock and MAC
545 * stats fetch will fail. */
546 efx_stats_disable(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000547
Ben Hutchings981fc1b42009-11-23 16:04:23 +0000548 return 0;
549
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000550fail_hwmon:
Ben Hutchings278c0622009-11-23 16:05:12 +0000551 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000552 return rc;
553}
554
555/*****************************************************************************
Ben Hutchings8ceee662008-04-27 12:55:59 +0100556 * Support for the SFE4002
557 *
558 */
Ben Hutchings3e133c42008-11-04 20:34:56 +0000559static u8 sfe4002_lm87_channel = 0x03; /* use AIN not FAN inputs */
560
561static const u8 sfe4002_lm87_regs[] = {
562 LM87_IN_LIMITS(0, 0x83, 0x91), /* 2.5V: 1.8V +/- 5% */
563 LM87_IN_LIMITS(1, 0x51, 0x5a), /* Vccp1: 1.2V +/- 5% */
564 LM87_IN_LIMITS(2, 0xb6, 0xca), /* 3.3V: 3.3V +/- 5% */
565 LM87_IN_LIMITS(3, 0xb0, 0xc9), /* 5V: 4.6-5.2V */
566 LM87_IN_LIMITS(4, 0xb0, 0xe0), /* 12V: 11-14V */
567 LM87_IN_LIMITS(5, 0x44, 0x4b), /* Vccp2: 1.0V +/- 5% */
568 LM87_AIN_LIMITS(0, 0xa0, 0xb2), /* AIN1: 1.66V +/- 5% */
569 LM87_AIN_LIMITS(1, 0x91, 0xa1), /* AIN2: 1.5V +/- 5% */
570 LM87_TEMP_INT_LIMITS(10, 60), /* board */
571 LM87_TEMP_EXT1_LIMITS(10, 70), /* Falcon */
572 0
573};
574
575static struct i2c_board_info sfe4002_hwmon_info = {
576 I2C_BOARD_INFO("lm87", 0x2e),
577 .platform_data = &sfe4002_lm87_channel,
Ben Hutchings3e133c42008-11-04 20:34:56 +0000578};
579
Ben Hutchings8ceee662008-04-27 12:55:59 +0100580/****************************************************************************/
581/* LED allocations. Note that on rev A0 boards the schematic and the reality
582 * differ: red and green are swapped. Below is the fixed (A1) layout (there
583 * are only 3 A0 boards in existence, so no real reason to make this
584 * conditional).
585 */
586#define SFE4002_FAULT_LED (2) /* Red */
587#define SFE4002_RX_LED (0) /* Green */
588#define SFE4002_TX_LED (1) /* Amber */
589
Ben Hutchings981fc1b42009-11-23 16:04:23 +0000590static void sfe4002_init_phy(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100591{
592 /* Set the TX and RX LEDs to reflect status and activity, and the
593 * fault LED off */
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000594 falcon_qt202x_set_led(efx, SFE4002_TX_LED,
595 QUAKE_LED_TXLINK | QUAKE_LED_LINK_ACTSTAT);
596 falcon_qt202x_set_led(efx, SFE4002_RX_LED,
597 QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACTSTAT);
598 falcon_qt202x_set_led(efx, SFE4002_FAULT_LED, QUAKE_LED_OFF);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100599}
600
Ben Hutchings398468e2009-11-23 16:03:45 +0000601static void sfe4002_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100602{
Ben Hutchings398468e2009-11-23 16:03:45 +0000603 falcon_qt202x_set_led(
604 efx, SFE4002_FAULT_LED,
605 (mode == EFX_LED_ON) ? QUAKE_LED_ON : QUAKE_LED_OFF);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100606}
607
Ben Hutchings3e133c42008-11-04 20:34:56 +0000608static int sfe4002_check_hw(struct efx_nic *efx)
609{
Ben Hutchings278c0622009-11-23 16:05:12 +0000610 struct falcon_board *board = falcon_board(efx);
611
Ben Hutchings3e133c42008-11-04 20:34:56 +0000612 /* A0 board rev. 4002s report a temperature fault the whole time
613 * (bad sensor) so we mask it out. */
614 unsigned alarm_mask =
Ben Hutchings278c0622009-11-23 16:05:12 +0000615 (board->major == 0 && board->minor == 0) ?
Ben Hutchings3e133c42008-11-04 20:34:56 +0000616 ~LM87_ALARM_TEMP_EXT1 : ~0;
617
618 return efx_check_lm87(efx, alarm_mask);
619}
620
Ben Hutchings8ceee662008-04-27 12:55:59 +0100621static int sfe4002_init(struct efx_nic *efx)
622{
Ben Hutchings278c0622009-11-23 16:05:12 +0000623 struct falcon_board *board = falcon_board(efx);
Ben Hutchings3e133c42008-11-04 20:34:56 +0000624 int rc = efx_init_lm87(efx, &sfe4002_hwmon_info, sfe4002_lm87_regs);
625 if (rc)
626 return rc;
Ben Hutchings278c0622009-11-23 16:05:12 +0000627 board->monitor = sfe4002_check_hw;
628 board->init_phy = sfe4002_init_phy;
629 board->set_id_led = sfe4002_set_id_led;
630 board->fini = efx_fini_lm87;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100631 return 0;
632}
633
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000634/*****************************************************************************
635 * Support for the SFN4112F
636 *
637 */
638static u8 sfn4112f_lm87_channel = 0x03; /* use AIN not FAN inputs */
639
640static const u8 sfn4112f_lm87_regs[] = {
641 LM87_IN_LIMITS(0, 0x83, 0x91), /* 2.5V: 1.8V +/- 5% */
642 LM87_IN_LIMITS(1, 0x51, 0x5a), /* Vccp1: 1.2V +/- 5% */
643 LM87_IN_LIMITS(2, 0xb6, 0xca), /* 3.3V: 3.3V +/- 5% */
644 LM87_IN_LIMITS(4, 0xb0, 0xe0), /* 12V: 11-14V */
645 LM87_IN_LIMITS(5, 0x44, 0x4b), /* Vccp2: 1.0V +/- 5% */
646 LM87_AIN_LIMITS(1, 0x91, 0xa1), /* AIN2: 1.5V +/- 5% */
647 LM87_TEMP_INT_LIMITS(10, 60), /* board */
648 LM87_TEMP_EXT1_LIMITS(10, 70), /* Falcon */
649 0
650};
651
652static struct i2c_board_info sfn4112f_hwmon_info = {
653 I2C_BOARD_INFO("lm87", 0x2e),
654 .platform_data = &sfn4112f_lm87_channel,
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000655};
656
657#define SFN4112F_ACT_LED 0
658#define SFN4112F_LINK_LED 1
659
Ben Hutchings981fc1b42009-11-23 16:04:23 +0000660static void sfn4112f_init_phy(struct efx_nic *efx)
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000661{
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000662 falcon_qt202x_set_led(efx, SFN4112F_ACT_LED,
663 QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACT);
664 falcon_qt202x_set_led(efx, SFN4112F_LINK_LED,
665 QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000666}
667
Ben Hutchings398468e2009-11-23 16:03:45 +0000668static void sfn4112f_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000669{
Ben Hutchings398468e2009-11-23 16:03:45 +0000670 int reg;
671
672 switch (mode) {
673 case EFX_LED_OFF:
674 reg = QUAKE_LED_OFF;
675 break;
676 case EFX_LED_ON:
677 reg = QUAKE_LED_ON;
678 break;
679 default:
680 reg = QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT;
681 break;
682 }
683
684 falcon_qt202x_set_led(efx, SFN4112F_LINK_LED, reg);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000685}
686
687static int sfn4112f_check_hw(struct efx_nic *efx)
688{
689 /* Mask out unused sensors */
690 return efx_check_lm87(efx, ~0x48);
691}
692
693static int sfn4112f_init(struct efx_nic *efx)
694{
Ben Hutchings278c0622009-11-23 16:05:12 +0000695 struct falcon_board *board = falcon_board(efx);
696
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000697 int rc = efx_init_lm87(efx, &sfn4112f_hwmon_info, sfn4112f_lm87_regs);
698 if (rc)
699 return rc;
Ben Hutchings278c0622009-11-23 16:05:12 +0000700 board->monitor = sfn4112f_check_hw;
701 board->init_phy = sfn4112f_init_phy;
702 board->set_id_led = sfn4112f_set_id_led;
703 board->fini = efx_fini_lm87;
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000704 return 0;
705}
706
Ben Hutchings8ceee662008-04-27 12:55:59 +0100707/* This will get expanded as board-specific details get moved out of the
708 * PHY drivers. */
Ben Hutchings3473a5b2009-10-23 08:29:16 +0000709struct falcon_board_data {
710 u8 type;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100711 const char *ref_model;
712 const char *gen_type;
713 int (*init) (struct efx_nic *nic);
714};
715
Ben Hutchings8ceee662008-04-27 12:55:59 +0100716
Ben Hutchings3473a5b2009-10-23 08:29:16 +0000717static struct falcon_board_data board_data[] = {
718 { FALCON_BOARD_SFE4001, "SFE4001", "10GBASE-T adapter", sfe4001_init },
719 { FALCON_BOARD_SFE4002, "SFE4002", "XFP adapter", sfe4002_init },
720 { FALCON_BOARD_SFN4111T, "SFN4111T", "100/1000/10GBASE-T adapter",
Ben Hutchings6f158d52008-12-12 22:00:49 -0800721 sfn4111t_init },
Ben Hutchings3473a5b2009-10-23 08:29:16 +0000722 { FALCON_BOARD_SFN4112F, "SFN4112F", "SFP+ adapter",
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000723 sfn4112f_init },
Ben Hutchings8ceee662008-04-27 12:55:59 +0100724};
725
Ben Hutchings37594332009-11-23 16:05:45 +0000726static struct falcon_board falcon_dummy_board = {
727 .init = efx_port_dummy_op_int,
728 .init_phy = efx_port_dummy_op_void,
729 .set_id_led = efx_port_dummy_op_set_id_led,
730 .monitor = efx_port_dummy_op_int,
731 .fini = efx_port_dummy_op_void,
732};
733
Ben Hutchings3473a5b2009-10-23 08:29:16 +0000734void falcon_probe_board(struct efx_nic *efx, u16 revision_info)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100735{
Ben Hutchings278c0622009-11-23 16:05:12 +0000736 struct falcon_board *board = falcon_board(efx);
Ben Hutchings3473a5b2009-10-23 08:29:16 +0000737 struct falcon_board_data *data = NULL;
Ben Hutchings04300d22008-12-12 21:48:09 -0800738 int i;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100739
Ben Hutchings37594332009-11-23 16:05:45 +0000740 *board = falcon_dummy_board;
Ben Hutchings278c0622009-11-23 16:05:12 +0000741 board->type = FALCON_BOARD_TYPE(revision_info);
742 board->major = FALCON_BOARD_MAJOR(revision_info);
743 board->minor = FALCON_BOARD_MINOR(revision_info);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100744
Ben Hutchings04300d22008-12-12 21:48:09 -0800745 for (i = 0; i < ARRAY_SIZE(board_data); i++)
Ben Hutchings278c0622009-11-23 16:05:12 +0000746 if (board_data[i].type == board->type)
Ben Hutchings04300d22008-12-12 21:48:09 -0800747 data = &board_data[i];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100748
Ben Hutchings04300d22008-12-12 21:48:09 -0800749 if (data) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100750 EFX_INFO(efx, "board is %s rev %c%d\n",
751 (efx->pci_dev->subsystem_vendor == EFX_VENDID_SFC)
752 ? data->ref_model : data->gen_type,
Ben Hutchings278c0622009-11-23 16:05:12 +0000753 'A' + board->major, board->minor);
754 board->init = data->init;
Ben Hutchings04300d22008-12-12 21:48:09 -0800755 } else {
Ben Hutchings278c0622009-11-23 16:05:12 +0000756 EFX_ERR(efx, "unknown board type %d\n", board->type);
Ben Hutchings04300d22008-12-12 21:48:09 -0800757 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100758}