blob: 92b35e3d1100d9e92c284486891bb418541daab4 [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)"
111 "%s%s\n",
112 alarms1, alarms2,
113 (alarms1 & LM87_ALARM_TEMP_INT) ? " INTERNAL" : "",
114 (alarms1 & LM87_ALARM_TEMP_EXT1) ? " EXTERNAL" : "");
Ben Hutchings3e133c42008-11-04 20:34:56 +0000115 return -ERANGE;
116 }
117
118 return 0;
119}
120
121#else /* !CONFIG_SENSORS_LM87 */
122
123static inline int
124efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
125 const u8 *reg_values)
126{
127 return 0;
128}
129static inline void efx_fini_lm87(struct efx_nic *efx)
130{
131}
132static inline int efx_check_lm87(struct efx_nic *efx, unsigned mask)
133{
134 return 0;
135}
136
137#endif /* CONFIG_SENSORS_LM87 */
138
139/*****************************************************************************
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000140 * Support for the SFE4001 and SFN4111T NICs.
141 *
142 * The SFE4001 does not power-up fully at reset due to its high power
143 * consumption. We control its power via a PCA9539 I/O expander.
144 * Both boards have a MAX6647 temperature monitor which we expose to
145 * the lm90 driver.
146 *
147 * This also provides minimal support for reflashing the PHY, which is
148 * initiated by resetting it with the FLASH_CFG_1 pin pulled down.
149 * On SFE4001 rev A2 and later this is connected to the 3V3X output of
150 * the IO-expander; on the SFN4111T it is connected to Falcon's GPIO3.
151 * We represent reflash mode as PHY_MODE_SPECIAL and make it mutually
152 * exclusive with the network device being open.
153 */
154
155/**************************************************************************
Ben Hutchings89863522009-11-25 16:09:04 +0000156 * Support for I2C IO Expander device on SFE4001
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000157 */
158#define PCA9539 0x74
159
160#define P0_IN 0x00
161#define P0_OUT 0x02
162#define P0_INVERT 0x04
163#define P0_CONFIG 0x06
164
165#define P0_EN_1V0X_LBN 0
166#define P0_EN_1V0X_WIDTH 1
167#define P0_EN_1V2_LBN 1
168#define P0_EN_1V2_WIDTH 1
169#define P0_EN_2V5_LBN 2
170#define P0_EN_2V5_WIDTH 1
171#define P0_EN_3V3X_LBN 3
172#define P0_EN_3V3X_WIDTH 1
173#define P0_EN_5V_LBN 4
174#define P0_EN_5V_WIDTH 1
175#define P0_SHORTEN_JTAG_LBN 5
176#define P0_SHORTEN_JTAG_WIDTH 1
177#define P0_X_TRST_LBN 6
178#define P0_X_TRST_WIDTH 1
179#define P0_DSP_RESET_LBN 7
180#define P0_DSP_RESET_WIDTH 1
181
182#define P1_IN 0x01
183#define P1_OUT 0x03
184#define P1_INVERT 0x05
185#define P1_CONFIG 0x07
186
187#define P1_AFE_PWD_LBN 0
188#define P1_AFE_PWD_WIDTH 1
189#define P1_DSP_PWD25_LBN 1
190#define P1_DSP_PWD25_WIDTH 1
191#define P1_RESERVED_LBN 2
192#define P1_RESERVED_WIDTH 2
193#define P1_SPARE_LBN 4
194#define P1_SPARE_WIDTH 4
195
196/* Temperature Sensor */
197#define MAX664X_REG_RSL 0x02
198#define MAX664X_REG_WLHO 0x0B
199
200static void sfe4001_poweroff(struct efx_nic *efx)
201{
Ben Hutchings278c0622009-11-23 16:05:12 +0000202 struct i2c_client *ioexp_client = falcon_board(efx)->ioexp_client;
203 struct i2c_client *hwmon_client = falcon_board(efx)->hwmon_client;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000204
205 /* Turn off all power rails and disable outputs */
206 i2c_smbus_write_byte_data(ioexp_client, P0_OUT, 0xff);
207 i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG, 0xff);
208 i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0xff);
209
210 /* Clear any over-temperature alert */
211 i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
212}
213
214static int sfe4001_poweron(struct efx_nic *efx)
215{
Ben Hutchings278c0622009-11-23 16:05:12 +0000216 struct i2c_client *ioexp_client = falcon_board(efx)->ioexp_client;
217 struct i2c_client *hwmon_client = falcon_board(efx)->hwmon_client;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000218 unsigned int i, j;
219 int rc;
220 u8 out;
221
222 /* Clear any previous over-temperature alert */
223 rc = i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
224 if (rc < 0)
225 return rc;
226
227 /* Enable port 0 and port 1 outputs on IO expander */
228 rc = i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0x00);
229 if (rc)
230 return rc;
231 rc = i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG,
232 0xff & ~(1 << P1_SPARE_LBN));
233 if (rc)
234 goto fail_on;
235
236 /* If PHY power is on, turn it all off and wait 1 second to
237 * ensure a full reset.
238 */
239 rc = i2c_smbus_read_byte_data(ioexp_client, P0_OUT);
240 if (rc < 0)
241 goto fail_on;
242 out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
243 (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
244 (0 << P0_EN_1V0X_LBN));
245 if (rc != out) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000246 netif_info(efx, hw, efx->net_dev, "power-cycling PHY\n");
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000247 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
248 if (rc)
249 goto fail_on;
250 schedule_timeout_uninterruptible(HZ);
251 }
252
253 for (i = 0; i < 20; ++i) {
254 /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
255 out = 0xff & ~((1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
256 (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
257 (1 << P0_X_TRST_LBN));
258 if (efx->phy_mode & PHY_MODE_SPECIAL)
259 out |= 1 << P0_EN_3V3X_LBN;
260
261 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
262 if (rc)
263 goto fail_on;
264 msleep(10);
265
266 /* Turn on 1V power rail */
267 out &= ~(1 << P0_EN_1V0X_LBN);
268 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
269 if (rc)
270 goto fail_on;
271
Ben Hutchings62776d02010-06-23 11:30:07 +0000272 netif_info(efx, hw, efx->net_dev,
273 "waiting for DSP boot (attempt %d)...\n", i);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000274
275 /* In flash config mode, DSP does not turn on AFE, so
276 * just wait 1 second.
277 */
278 if (efx->phy_mode & PHY_MODE_SPECIAL) {
279 schedule_timeout_uninterruptible(HZ);
280 return 0;
281 }
282
283 for (j = 0; j < 10; ++j) {
284 msleep(100);
285
286 /* Check DSP has asserted AFE power line */
287 rc = i2c_smbus_read_byte_data(ioexp_client, P1_IN);
288 if (rc < 0)
289 goto fail_on;
290 if (rc & (1 << P1_AFE_PWD_LBN))
291 return 0;
292 }
293 }
294
Ben Hutchings62776d02010-06-23 11:30:07 +0000295 netif_info(efx, hw, efx->net_dev, "timed out waiting for DSP boot\n");
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000296 rc = -ETIMEDOUT;
297fail_on:
298 sfe4001_poweroff(efx);
299 return rc;
300}
301
302static int sfn4111t_reset(struct efx_nic *efx)
303{
Ben Hutchingse775fb92009-11-23 16:06:02 +0000304 struct falcon_board *board = falcon_board(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000305 efx_oword_t reg;
306
307 /* GPIO 3 and the GPIO register are shared with I2C, so block that */
Ben Hutchingse775fb92009-11-23 16:06:02 +0000308 i2c_lock_adapter(&board->i2c_adap);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000309
310 /* Pull RST_N (GPIO 2) low then let it up again, setting the
311 * FLASH_CFG_1 strap (GPIO 3) appropriately. Only change the
312 * output enables; the output levels should always be 0 (low)
313 * and we rely on external pull-ups. */
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000314 efx_reado(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000315 EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO2_OEN, true);
Ben Hutchings12d00ca2009-10-23 08:30:46 +0000316 efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000317 msleep(1000);
Ben Hutchings3e6c4532009-10-23 08:30:36 +0000318 EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO2_OEN, false);
319 EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO3_OEN,
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000320 !!(efx->phy_mode & PHY_MODE_SPECIAL));
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(1);
323
Ben Hutchingse775fb92009-11-23 16:06:02 +0000324 i2c_unlock_adapter(&board->i2c_adap);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000325
326 ssleep(1);
327 return 0;
328}
329
330static ssize_t show_phy_flash_cfg(struct device *dev,
331 struct device_attribute *attr, char *buf)
332{
333 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
334 return sprintf(buf, "%d\n", !!(efx->phy_mode & PHY_MODE_SPECIAL));
335}
336
337static ssize_t set_phy_flash_cfg(struct device *dev,
338 struct device_attribute *attr,
339 const char *buf, size_t count)
340{
341 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
342 enum efx_phy_mode old_mode, new_mode;
343 int err;
344
345 rtnl_lock();
346 old_mode = efx->phy_mode;
347 if (count == 0 || *buf == '0')
348 new_mode = old_mode & ~PHY_MODE_SPECIAL;
349 else
350 new_mode = PHY_MODE_SPECIAL;
351 if (old_mode == new_mode) {
352 err = 0;
353 } else if (efx->state != STATE_RUNNING || netif_running(efx->net_dev)) {
354 err = -EBUSY;
355 } else {
356 /* Reset the PHY, reconfigure the MAC and enable/disable
357 * MAC stats accordingly. */
358 efx->phy_mode = new_mode;
359 if (new_mode & PHY_MODE_SPECIAL)
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000360 falcon_stop_nic_stats(efx);
Ben Hutchings44838a42009-11-25 16:09:41 +0000361 if (falcon_board(efx)->type->id == FALCON_BOARD_SFE4001)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000362 err = sfe4001_poweron(efx);
363 else
364 err = sfn4111t_reset(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000365 if (!err)
366 err = efx_reconfigure_port(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000367 if (!(new_mode & PHY_MODE_SPECIAL))
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000368 falcon_start_nic_stats(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000369 }
370 rtnl_unlock();
371
372 return err ? err : count;
373}
374
375static DEVICE_ATTR(phy_flash_cfg, 0644, show_phy_flash_cfg, set_phy_flash_cfg);
376
377static void sfe4001_fini(struct efx_nic *efx)
378{
Ben Hutchings278c0622009-11-23 16:05:12 +0000379 struct falcon_board *board = falcon_board(efx);
380
Ben Hutchings62776d02010-06-23 11:30:07 +0000381 netif_info(efx, drv, efx->net_dev, "%s\n", __func__);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000382
383 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
384 sfe4001_poweroff(efx);
Ben Hutchings278c0622009-11-23 16:05:12 +0000385 i2c_unregister_device(board->ioexp_client);
386 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000387}
388
389static int sfe4001_check_hw(struct efx_nic *efx)
390{
391 s32 status;
392
393 /* If XAUI link is up then do not monitor */
Ben Hutchings9007b9f2009-11-25 16:12:01 +0000394 if (EFX_WORKAROUND_7884(efx) && !efx->xmac_poll_required)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000395 return 0;
396
397 /* Check the powered status of the PHY. Lack of power implies that
398 * the MAX6647 has shut down power to it, probably due to a temp.
399 * alarm. Reading the power status rather than the MAX6647 status
400 * directly because the later is read-to-clear and would thus
401 * start to power up the PHY again when polled, causing us to blip
402 * the power undesirably.
403 * We know we can read from the IO expander because we did
404 * it during power-on. Assume failure now is bad news. */
Ben Hutchings278c0622009-11-23 16:05:12 +0000405 status = i2c_smbus_read_byte_data(falcon_board(efx)->ioexp_client, P1_IN);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000406 if (status >= 0 &&
407 (status & ((1 << P1_AFE_PWD_LBN) | (1 << P1_DSP_PWD25_LBN))) != 0)
408 return 0;
409
410 /* Use board power control, not PHY power control */
411 sfe4001_poweroff(efx);
412 efx->phy_mode = PHY_MODE_OFF;
413
414 return (status < 0) ? -EIO : -ERANGE;
415}
416
417static struct i2c_board_info sfe4001_hwmon_info = {
418 I2C_BOARD_INFO("max6647", 0x4e),
419};
420
421/* This board uses an I2C expander to provider power to the PHY, which needs to
422 * be turned on before the PHY can be used.
423 * Context: Process context, rtnl lock held
424 */
425static int sfe4001_init(struct efx_nic *efx)
426{
Ben Hutchings278c0622009-11-23 16:05:12 +0000427 struct falcon_board *board = falcon_board(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000428 int rc;
429
430#if defined(CONFIG_SENSORS_LM90) || defined(CONFIG_SENSORS_LM90_MODULE)
Ben Hutchings278c0622009-11-23 16:05:12 +0000431 board->hwmon_client =
Ben Hutchingse775fb92009-11-23 16:06:02 +0000432 i2c_new_device(&board->i2c_adap, &sfe4001_hwmon_info);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000433#else
Ben Hutchings278c0622009-11-23 16:05:12 +0000434 board->hwmon_client =
Ben Hutchingse775fb92009-11-23 16:06:02 +0000435 i2c_new_dummy(&board->i2c_adap, sfe4001_hwmon_info.addr);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000436#endif
Ben Hutchings278c0622009-11-23 16:05:12 +0000437 if (!board->hwmon_client)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000438 return -EIO;
439
440 /* Raise board/PHY high limit from 85 to 90 degrees Celsius */
Ben Hutchings278c0622009-11-23 16:05:12 +0000441 rc = i2c_smbus_write_byte_data(board->hwmon_client,
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000442 MAX664X_REG_WLHO, 90);
443 if (rc)
444 goto fail_hwmon;
445
Ben Hutchingse775fb92009-11-23 16:06:02 +0000446 board->ioexp_client = i2c_new_dummy(&board->i2c_adap, PCA9539);
Ben Hutchings278c0622009-11-23 16:05:12 +0000447 if (!board->ioexp_client) {
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000448 rc = -EIO;
449 goto fail_hwmon;
450 }
451
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000452 if (efx->phy_mode & PHY_MODE_SPECIAL) {
453 /* PHY won't generate a 156.25 MHz clock and MAC stats fetch
454 * will fail. */
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000455 falcon_stop_nic_stats(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000456 }
457 rc = sfe4001_poweron(efx);
458 if (rc)
459 goto fail_ioexp;
460
461 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
462 if (rc)
463 goto fail_on;
464
Ben Hutchings62776d02010-06-23 11:30:07 +0000465 netif_info(efx, hw, efx->net_dev, "PHY is powered on\n");
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000466 return 0;
467
468fail_on:
469 sfe4001_poweroff(efx);
470fail_ioexp:
Ben Hutchings278c0622009-11-23 16:05:12 +0000471 i2c_unregister_device(board->ioexp_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000472fail_hwmon:
Ben Hutchings278c0622009-11-23 16:05:12 +0000473 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000474 return rc;
475}
476
477static int sfn4111t_check_hw(struct efx_nic *efx)
478{
479 s32 status;
480
481 /* If XAUI link is up then do not monitor */
Ben Hutchings9007b9f2009-11-25 16:12:01 +0000482 if (EFX_WORKAROUND_7884(efx) && !efx->xmac_poll_required)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000483 return 0;
484
485 /* Test LHIGH, RHIGH, FAULT, EOT and IOT alarms */
Ben Hutchings278c0622009-11-23 16:05:12 +0000486 status = i2c_smbus_read_byte_data(falcon_board(efx)->hwmon_client,
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000487 MAX664X_REG_RSL);
488 if (status < 0)
489 return -EIO;
490 if (status & 0x57)
491 return -ERANGE;
492 return 0;
493}
494
495static void sfn4111t_fini(struct efx_nic *efx)
496{
Ben Hutchings62776d02010-06-23 11:30:07 +0000497 netif_info(efx, drv, efx->net_dev, "%s\n", __func__);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000498
499 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
Ben Hutchings278c0622009-11-23 16:05:12 +0000500 i2c_unregister_device(falcon_board(efx)->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000501}
502
503static struct i2c_board_info sfn4111t_a0_hwmon_info = {
504 I2C_BOARD_INFO("max6647", 0x4e),
505};
506
507static struct i2c_board_info sfn4111t_r5_hwmon_info = {
508 I2C_BOARD_INFO("max6646", 0x4d),
509};
510
Ben Hutchings981fc1b2009-11-23 16:04:23 +0000511static void sfn4111t_init_phy(struct efx_nic *efx)
512{
513 if (!(efx->phy_mode & PHY_MODE_SPECIAL)) {
514 if (sft9001_wait_boot(efx) != -EINVAL)
515 return;
516
517 efx->phy_mode = PHY_MODE_SPECIAL;
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000518 falcon_stop_nic_stats(efx);
Ben Hutchings981fc1b2009-11-23 16:04:23 +0000519 }
520
521 sfn4111t_reset(efx);
522 sft9001_wait_boot(efx);
523}
524
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000525static int sfn4111t_init(struct efx_nic *efx)
526{
Ben Hutchings278c0622009-11-23 16:05:12 +0000527 struct falcon_board *board = falcon_board(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000528 int rc;
529
Ben Hutchings278c0622009-11-23 16:05:12 +0000530 board->hwmon_client =
Ben Hutchingse775fb92009-11-23 16:06:02 +0000531 i2c_new_device(&board->i2c_adap,
Ben Hutchings278c0622009-11-23 16:05:12 +0000532 (board->minor < 5) ?
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000533 &sfn4111t_a0_hwmon_info :
534 &sfn4111t_r5_hwmon_info);
Ben Hutchings278c0622009-11-23 16:05:12 +0000535 if (!board->hwmon_client)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000536 return -EIO;
537
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000538 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
539 if (rc)
540 goto fail_hwmon;
541
Ben Hutchings981fc1b2009-11-23 16:04:23 +0000542 if (efx->phy_mode & PHY_MODE_SPECIAL)
543 /* PHY may not generate a 156.25 MHz clock and MAC
544 * stats fetch will fail. */
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000545 falcon_stop_nic_stats(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000546
Ben Hutchings981fc1b2009-11-23 16:04:23 +0000547 return 0;
548
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000549fail_hwmon:
Ben Hutchings278c0622009-11-23 16:05:12 +0000550 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000551 return rc;
552}
553
554/*****************************************************************************
Ben Hutchings8ceee662008-04-27 12:55:59 +0100555 * Support for the SFE4002
556 *
557 */
Ben Hutchings3e133c42008-11-04 20:34:56 +0000558static u8 sfe4002_lm87_channel = 0x03; /* use AIN not FAN inputs */
559
560static const u8 sfe4002_lm87_regs[] = {
Ben Hutchings242cc052010-02-19 13:34:03 +0000561 LM87_IN_LIMITS(0, 0x7c, 0x99), /* 2.5V: 1.8V +/- 10% */
562 LM87_IN_LIMITS(1, 0x4c, 0x5e), /* Vccp1: 1.2V +/- 10% */
563 LM87_IN_LIMITS(2, 0xac, 0xd4), /* 3.3V: 3.3V +/- 10% */
564 LM87_IN_LIMITS(3, 0xac, 0xd4), /* 5V: 5.0V +/- 10% */
565 LM87_IN_LIMITS(4, 0xac, 0xe0), /* 12V: 10.8-14V */
566 LM87_IN_LIMITS(5, 0x3f, 0x4f), /* Vccp2: 1.0V +/- 10% */
567 LM87_AIN_LIMITS(0, 0x98, 0xbb), /* AIN1: 1.66V +/- 10% */
568 LM87_AIN_LIMITS(1, 0x8a, 0xa9), /* AIN2: 1.5V +/- 10% */
569 LM87_TEMP_INT_LIMITS(0, 80 + FALCON_BOARD_TEMP_BIAS),
570 LM87_TEMP_EXT1_LIMITS(0, FALCON_JUNC_TEMP_MAX),
Ben Hutchings3e133c42008-11-04 20:34:56 +0000571 0
572};
573
574static struct i2c_board_info sfe4002_hwmon_info = {
575 I2C_BOARD_INFO("lm87", 0x2e),
576 .platform_data = &sfe4002_lm87_channel,
Ben Hutchings3e133c42008-11-04 20:34:56 +0000577};
578
Ben Hutchings8ceee662008-04-27 12:55:59 +0100579/****************************************************************************/
580/* LED allocations. Note that on rev A0 boards the schematic and the reality
581 * differ: red and green are swapped. Below is the fixed (A1) layout (there
582 * are only 3 A0 boards in existence, so no real reason to make this
583 * conditional).
584 */
585#define SFE4002_FAULT_LED (2) /* Red */
586#define SFE4002_RX_LED (0) /* Green */
587#define SFE4002_TX_LED (1) /* Amber */
588
Ben Hutchings981fc1b2009-11-23 16:04:23 +0000589static void sfe4002_init_phy(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100590{
591 /* Set the TX and RX LEDs to reflect status and activity, and the
592 * fault LED off */
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000593 falcon_qt202x_set_led(efx, SFE4002_TX_LED,
594 QUAKE_LED_TXLINK | QUAKE_LED_LINK_ACTSTAT);
595 falcon_qt202x_set_led(efx, SFE4002_RX_LED,
596 QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACTSTAT);
597 falcon_qt202x_set_led(efx, SFE4002_FAULT_LED, QUAKE_LED_OFF);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100598}
599
Ben Hutchings398468e2009-11-23 16:03:45 +0000600static void sfe4002_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100601{
Ben Hutchings398468e2009-11-23 16:03:45 +0000602 falcon_qt202x_set_led(
603 efx, SFE4002_FAULT_LED,
604 (mode == EFX_LED_ON) ? QUAKE_LED_ON : QUAKE_LED_OFF);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100605}
606
Ben Hutchings3e133c42008-11-04 20:34:56 +0000607static int sfe4002_check_hw(struct efx_nic *efx)
608{
Ben Hutchings278c0622009-11-23 16:05:12 +0000609 struct falcon_board *board = falcon_board(efx);
610
Ben Hutchings3e133c42008-11-04 20:34:56 +0000611 /* A0 board rev. 4002s report a temperature fault the whole time
612 * (bad sensor) so we mask it out. */
613 unsigned alarm_mask =
Ben Hutchings278c0622009-11-23 16:05:12 +0000614 (board->major == 0 && board->minor == 0) ?
Ben Hutchings3e133c42008-11-04 20:34:56 +0000615 ~LM87_ALARM_TEMP_EXT1 : ~0;
616
617 return efx_check_lm87(efx, alarm_mask);
618}
619
Ben Hutchings8ceee662008-04-27 12:55:59 +0100620static int sfe4002_init(struct efx_nic *efx)
621{
Ben Hutchings44838a42009-11-25 16:09:41 +0000622 return efx_init_lm87(efx, &sfe4002_hwmon_info, sfe4002_lm87_regs);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100623}
624
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000625/*****************************************************************************
626 * Support for the SFN4112F
627 *
628 */
629static u8 sfn4112f_lm87_channel = 0x03; /* use AIN not FAN inputs */
630
631static const u8 sfn4112f_lm87_regs[] = {
Ben Hutchings242cc052010-02-19 13:34:03 +0000632 LM87_IN_LIMITS(0, 0x7c, 0x99), /* 2.5V: 1.8V +/- 10% */
633 LM87_IN_LIMITS(1, 0x4c, 0x5e), /* Vccp1: 1.2V +/- 10% */
634 LM87_IN_LIMITS(2, 0xac, 0xd4), /* 3.3V: 3.3V +/- 10% */
635 LM87_IN_LIMITS(4, 0xac, 0xe0), /* 12V: 10.8-14V */
636 LM87_IN_LIMITS(5, 0x3f, 0x4f), /* Vccp2: 1.0V +/- 10% */
637 LM87_AIN_LIMITS(1, 0x8a, 0xa9), /* AIN2: 1.5V +/- 10% */
638 LM87_TEMP_INT_LIMITS(0, 60 + FALCON_BOARD_TEMP_BIAS),
639 LM87_TEMP_EXT1_LIMITS(0, FALCON_JUNC_TEMP_MAX),
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000640 0
641};
642
643static struct i2c_board_info sfn4112f_hwmon_info = {
644 I2C_BOARD_INFO("lm87", 0x2e),
645 .platform_data = &sfn4112f_lm87_channel,
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000646};
647
648#define SFN4112F_ACT_LED 0
649#define SFN4112F_LINK_LED 1
650
Ben Hutchings981fc1b2009-11-23 16:04:23 +0000651static void sfn4112f_init_phy(struct efx_nic *efx)
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000652{
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000653 falcon_qt202x_set_led(efx, SFN4112F_ACT_LED,
654 QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACT);
655 falcon_qt202x_set_led(efx, SFN4112F_LINK_LED,
656 QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000657}
658
Ben Hutchings398468e2009-11-23 16:03:45 +0000659static void sfn4112f_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000660{
Ben Hutchings398468e2009-11-23 16:03:45 +0000661 int reg;
662
663 switch (mode) {
664 case EFX_LED_OFF:
665 reg = QUAKE_LED_OFF;
666 break;
667 case EFX_LED_ON:
668 reg = QUAKE_LED_ON;
669 break;
670 default:
671 reg = QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT;
672 break;
673 }
674
675 falcon_qt202x_set_led(efx, SFN4112F_LINK_LED, reg);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000676}
677
678static int sfn4112f_check_hw(struct efx_nic *efx)
679{
680 /* Mask out unused sensors */
681 return efx_check_lm87(efx, ~0x48);
682}
683
684static int sfn4112f_init(struct efx_nic *efx)
685{
Ben Hutchings44838a42009-11-25 16:09:41 +0000686 return efx_init_lm87(efx, &sfn4112f_hwmon_info, sfn4112f_lm87_regs);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000687}
688
Ben Hutchings44838a42009-11-25 16:09:41 +0000689static const struct falcon_board_type board_types[] = {
690 {
691 .id = FALCON_BOARD_SFE4001,
692 .ref_model = "SFE4001",
693 .gen_type = "10GBASE-T adapter",
694 .init = sfe4001_init,
695 .init_phy = efx_port_dummy_op_void,
696 .fini = sfe4001_fini,
697 .set_id_led = tenxpress_set_id_led,
698 .monitor = sfe4001_check_hw,
699 },
700 {
701 .id = FALCON_BOARD_SFE4002,
702 .ref_model = "SFE4002",
703 .gen_type = "XFP adapter",
704 .init = sfe4002_init,
705 .init_phy = sfe4002_init_phy,
706 .fini = efx_fini_lm87,
707 .set_id_led = sfe4002_set_id_led,
708 .monitor = sfe4002_check_hw,
709 },
710 {
711 .id = FALCON_BOARD_SFN4111T,
712 .ref_model = "SFN4111T",
713 .gen_type = "100/1000/10GBASE-T adapter",
714 .init = sfn4111t_init,
715 .init_phy = sfn4111t_init_phy,
716 .fini = sfn4111t_fini,
717 .set_id_led = tenxpress_set_id_led,
718 .monitor = sfn4111t_check_hw,
719 },
720 {
721 .id = FALCON_BOARD_SFN4112F,
722 .ref_model = "SFN4112F",
723 .gen_type = "SFP+ adapter",
724 .init = sfn4112f_init,
725 .init_phy = sfn4112f_init_phy,
726 .fini = efx_fini_lm87,
727 .set_id_led = sfn4112f_set_id_led,
728 .monitor = sfn4112f_check_hw,
729 },
Ben Hutchings8ceee662008-04-27 12:55:59 +0100730};
731
Ben Hutchingse41c11e2010-04-28 09:01:50 +0000732int falcon_probe_board(struct efx_nic *efx, u16 revision_info)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100733{
Ben Hutchings278c0622009-11-23 16:05:12 +0000734 struct falcon_board *board = falcon_board(efx);
Ben Hutchings44838a42009-11-25 16:09:41 +0000735 u8 type_id = FALCON_BOARD_TYPE(revision_info);
Ben Hutchings04300d22008-12-12 21:48:09 -0800736 int i;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100737
Ben Hutchings278c0622009-11-23 16:05:12 +0000738 board->major = FALCON_BOARD_MAJOR(revision_info);
739 board->minor = FALCON_BOARD_MINOR(revision_info);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100740
Ben Hutchings44838a42009-11-25 16:09:41 +0000741 for (i = 0; i < ARRAY_SIZE(board_types); i++)
742 if (board_types[i].id == type_id)
743 board->type = &board_types[i];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100744
Ben Hutchings44838a42009-11-25 16:09:41 +0000745 if (board->type) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000746 netif_info(efx, probe, efx->net_dev, "board is %s rev %c%d\n",
Ben Hutchings8ceee662008-04-27 12:55:59 +0100747 (efx->pci_dev->subsystem_vendor == EFX_VENDID_SFC)
Ben Hutchings44838a42009-11-25 16:09:41 +0000748 ? board->type->ref_model : board->type->gen_type,
Ben Hutchings278c0622009-11-23 16:05:12 +0000749 'A' + board->major, board->minor);
Ben Hutchingse41c11e2010-04-28 09:01:50 +0000750 return 0;
Ben Hutchings04300d22008-12-12 21:48:09 -0800751 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +0000752 netif_err(efx, probe, efx->net_dev, "unknown board type %d\n",
753 type_id);
Ben Hutchingse41c11e2010-04-28 09:01:50 +0000754 return -ENODEV;
Ben Hutchings04300d22008-12-12 21:48:09 -0800755 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100756}