blob: 86180ee02ec07e50e037367fcf7cb6e33a5bd995 [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
Ben Hutchings7e51b432010-09-22 10:00:47 +000029#define FALCON_BOARD_SFE4003 0x03
Ben Hutchings3473a5b2009-10-23 08:29:16 +000030#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
Ben Hutchings71839f72010-12-02 13:46:24 +000033 * limited. The maximum acceptable ambient temperature varies
34 * depending on the PHY specifications but the critical temperature
35 * above which we should shut down to avoid damage is 80°C. */
Ben Hutchings242cc052010-02-19 13:34:03 +000036#define FALCON_BOARD_TEMP_BIAS 15
Ben Hutchings71839f72010-12-02 13:46:24 +000037#define FALCON_BOARD_TEMP_CRIT (80 + FALCON_BOARD_TEMP_BIAS)
Ben Hutchings242cc052010-02-19 13:34:03 +000038
39/* SFC4000 datasheet says: 'The maximum permitted junction temperature
40 * is 125°C; the thermal design of the environment for the SFC4000
41 * should aim to keep this well below 100°C.' */
Ben Hutchings71839f72010-12-02 13:46:24 +000042#define FALCON_JUNC_TEMP_MIN 0
Ben Hutchings242cc052010-02-19 13:34:03 +000043#define FALCON_JUNC_TEMP_MAX 90
Ben Hutchings71839f72010-12-02 13:46:24 +000044#define FALCON_JUNC_TEMP_CRIT 125
Ben Hutchings242cc052010-02-19 13:34:03 +000045
Ben Hutchings8ceee662008-04-27 12:55:59 +010046/*****************************************************************************
Ben Hutchings3e133c42008-11-04 20:34:56 +000047 * Support for LM87 sensor chip used on several boards
48 */
Ben Hutchings71839f72010-12-02 13:46:24 +000049#define LM87_REG_TEMP_HW_INT_LOCK 0x13
50#define LM87_REG_TEMP_HW_EXT_LOCK 0x14
51#define LM87_REG_TEMP_HW_INT 0x17
52#define LM87_REG_TEMP_HW_EXT 0x18
53#define LM87_REG_TEMP_EXT1 0x26
54#define LM87_REG_TEMP_INT 0x27
Ben Hutchings3e133c42008-11-04 20:34:56 +000055#define LM87_REG_ALARMS1 0x41
56#define LM87_REG_ALARMS2 0x42
57#define LM87_IN_LIMITS(nr, _min, _max) \
58 0x2B + (nr) * 2, _max, 0x2C + (nr) * 2, _min
59#define LM87_AIN_LIMITS(nr, _min, _max) \
60 0x3B + (nr), _max, 0x1A + (nr), _min
61#define LM87_TEMP_INT_LIMITS(_min, _max) \
62 0x39, _max, 0x3A, _min
63#define LM87_TEMP_EXT1_LIMITS(_min, _max) \
64 0x37, _max, 0x38, _min
65
66#define LM87_ALARM_TEMP_INT 0x10
67#define LM87_ALARM_TEMP_EXT1 0x20
68
69#if defined(CONFIG_SENSORS_LM87) || defined(CONFIG_SENSORS_LM87_MODULE)
70
Ben Hutchings71839f72010-12-02 13:46:24 +000071static int efx_poke_lm87(struct i2c_client *client, const u8 *reg_values)
72{
73 while (*reg_values) {
74 u8 reg = *reg_values++;
75 u8 value = *reg_values++;
76 int rc = i2c_smbus_write_byte_data(client, reg, value);
77 if (rc)
78 return rc;
79 }
80 return 0;
81}
82
83static const u8 falcon_lm87_common_regs[] = {
84 LM87_REG_TEMP_HW_INT_LOCK, FALCON_BOARD_TEMP_CRIT,
85 LM87_REG_TEMP_HW_INT, FALCON_BOARD_TEMP_CRIT,
86 LM87_TEMP_EXT1_LIMITS(FALCON_JUNC_TEMP_MIN, FALCON_JUNC_TEMP_MAX),
87 LM87_REG_TEMP_HW_EXT_LOCK, FALCON_JUNC_TEMP_CRIT,
88 LM87_REG_TEMP_HW_EXT, FALCON_JUNC_TEMP_CRIT,
89 0
90};
91
Ben Hutchings3e133c42008-11-04 20:34:56 +000092static int efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
93 const u8 *reg_values)
94{
Ben Hutchingse775fb92009-11-23 16:06:02 +000095 struct falcon_board *board = falcon_board(efx);
96 struct i2c_client *client = i2c_new_device(&board->i2c_adap, info);
Ben Hutchings3e133c42008-11-04 20:34:56 +000097 int rc;
98
99 if (!client)
100 return -EIO;
101
Ben Hutchings71839f72010-12-02 13:46:24 +0000102 rc = efx_poke_lm87(client, reg_values);
103 if (rc)
104 goto err;
105 rc = efx_poke_lm87(client, falcon_lm87_common_regs);
106 if (rc)
107 goto err;
Ben Hutchings3e133c42008-11-04 20:34:56 +0000108
Ben Hutchingse775fb92009-11-23 16:06:02 +0000109 board->hwmon_client = client;
Ben Hutchings3e133c42008-11-04 20:34:56 +0000110 return 0;
111
112err:
113 i2c_unregister_device(client);
114 return rc;
115}
116
117static void efx_fini_lm87(struct efx_nic *efx)
118{
Ben Hutchings278c0622009-11-23 16:05:12 +0000119 i2c_unregister_device(falcon_board(efx)->hwmon_client);
Ben Hutchings3e133c42008-11-04 20:34:56 +0000120}
121
122static int efx_check_lm87(struct efx_nic *efx, unsigned mask)
123{
Ben Hutchings278c0622009-11-23 16:05:12 +0000124 struct i2c_client *client = falcon_board(efx)->hwmon_client;
Ben Hutchings71839f72010-12-02 13:46:24 +0000125 bool temp_crit, elec_fault, is_failure;
126 u16 alarms;
127 s32 reg;
Ben Hutchings3e133c42008-11-04 20:34:56 +0000128
129 /* If link is up then do not monitor temperature */
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000130 if (EFX_WORKAROUND_7884(efx) && efx->link_state.up)
Ben Hutchings3e133c42008-11-04 20:34:56 +0000131 return 0;
132
Ben Hutchings71839f72010-12-02 13:46:24 +0000133 reg = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS1);
134 if (reg < 0)
135 return reg;
136 alarms = reg;
137 reg = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS2);
138 if (reg < 0)
139 return reg;
140 alarms |= reg << 8;
141 alarms &= mask;
Ben Hutchings3e133c42008-11-04 20:34:56 +0000142
Ben Hutchings71839f72010-12-02 13:46:24 +0000143 temp_crit = false;
144 if (alarms & LM87_ALARM_TEMP_INT) {
145 reg = i2c_smbus_read_byte_data(client, LM87_REG_TEMP_INT);
146 if (reg < 0)
147 return reg;
148 if (reg > FALCON_BOARD_TEMP_CRIT)
149 temp_crit = true;
150 }
151 if (alarms & LM87_ALARM_TEMP_EXT1) {
152 reg = i2c_smbus_read_byte_data(client, LM87_REG_TEMP_EXT1);
153 if (reg < 0)
154 return reg;
155 if (reg > FALCON_JUNC_TEMP_CRIT)
156 temp_crit = true;
157 }
158 elec_fault = alarms & ~(LM87_ALARM_TEMP_INT | LM87_ALARM_TEMP_EXT1);
159 is_failure = temp_crit || elec_fault;
160
161 if (alarms)
162 netif_err(efx, hw, efx->net_dev,
163 "LM87 detected a hardware %s (status %02x:%02x)"
164 "%s%s%s%s\n",
165 is_failure ? "failure" : "problem",
166 alarms & 0xff, alarms >> 8,
167 (alarms & LM87_ALARM_TEMP_INT) ?
168 "; board is overheating" : "",
169 (alarms & LM87_ALARM_TEMP_EXT1) ?
170 "; controller is overheating" : "",
171 temp_crit ? "; reached critical temperature" : "",
172 elec_fault ? "; electrical fault" : "");
173
174 return is_failure ? -ERANGE : 0;
Ben Hutchings3e133c42008-11-04 20:34:56 +0000175}
176
177#else /* !CONFIG_SENSORS_LM87 */
178
179static inline int
180efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
181 const u8 *reg_values)
182{
183 return 0;
184}
185static inline void efx_fini_lm87(struct efx_nic *efx)
186{
187}
188static inline int efx_check_lm87(struct efx_nic *efx, unsigned mask)
189{
190 return 0;
191}
192
193#endif /* CONFIG_SENSORS_LM87 */
194
195/*****************************************************************************
Ben Hutchings8fbca792010-09-22 10:00:11 +0000196 * Support for the SFE4001 NIC.
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000197 *
198 * The SFE4001 does not power-up fully at reset due to its high power
199 * consumption. We control its power via a PCA9539 I/O expander.
Ben Hutchings8fbca792010-09-22 10:00:11 +0000200 * It also has a MAX6647 temperature monitor which we expose to
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000201 * the lm90 driver.
202 *
203 * This also provides minimal support for reflashing the PHY, which is
204 * initiated by resetting it with the FLASH_CFG_1 pin pulled down.
205 * On SFE4001 rev A2 and later this is connected to the 3V3X output of
Ben Hutchings8fbca792010-09-22 10:00:11 +0000206 * the IO-expander.
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000207 * We represent reflash mode as PHY_MODE_SPECIAL and make it mutually
208 * exclusive with the network device being open.
209 */
210
211/**************************************************************************
Ben Hutchings89863522009-11-25 16:09:04 +0000212 * Support for I2C IO Expander device on SFE4001
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000213 */
214#define PCA9539 0x74
215
216#define P0_IN 0x00
217#define P0_OUT 0x02
218#define P0_INVERT 0x04
219#define P0_CONFIG 0x06
220
221#define P0_EN_1V0X_LBN 0
222#define P0_EN_1V0X_WIDTH 1
223#define P0_EN_1V2_LBN 1
224#define P0_EN_1V2_WIDTH 1
225#define P0_EN_2V5_LBN 2
226#define P0_EN_2V5_WIDTH 1
227#define P0_EN_3V3X_LBN 3
228#define P0_EN_3V3X_WIDTH 1
229#define P0_EN_5V_LBN 4
230#define P0_EN_5V_WIDTH 1
231#define P0_SHORTEN_JTAG_LBN 5
232#define P0_SHORTEN_JTAG_WIDTH 1
233#define P0_X_TRST_LBN 6
234#define P0_X_TRST_WIDTH 1
235#define P0_DSP_RESET_LBN 7
236#define P0_DSP_RESET_WIDTH 1
237
238#define P1_IN 0x01
239#define P1_OUT 0x03
240#define P1_INVERT 0x05
241#define P1_CONFIG 0x07
242
243#define P1_AFE_PWD_LBN 0
244#define P1_AFE_PWD_WIDTH 1
245#define P1_DSP_PWD25_LBN 1
246#define P1_DSP_PWD25_WIDTH 1
247#define P1_RESERVED_LBN 2
248#define P1_RESERVED_WIDTH 2
249#define P1_SPARE_LBN 4
250#define P1_SPARE_WIDTH 4
251
252/* Temperature Sensor */
253#define MAX664X_REG_RSL 0x02
254#define MAX664X_REG_WLHO 0x0B
255
256static void sfe4001_poweroff(struct efx_nic *efx)
257{
Ben Hutchings278c0622009-11-23 16:05:12 +0000258 struct i2c_client *ioexp_client = falcon_board(efx)->ioexp_client;
259 struct i2c_client *hwmon_client = falcon_board(efx)->hwmon_client;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000260
261 /* Turn off all power rails and disable outputs */
262 i2c_smbus_write_byte_data(ioexp_client, P0_OUT, 0xff);
263 i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG, 0xff);
264 i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0xff);
265
266 /* Clear any over-temperature alert */
267 i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
268}
269
270static int sfe4001_poweron(struct efx_nic *efx)
271{
Ben Hutchings278c0622009-11-23 16:05:12 +0000272 struct i2c_client *ioexp_client = falcon_board(efx)->ioexp_client;
273 struct i2c_client *hwmon_client = falcon_board(efx)->hwmon_client;
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000274 unsigned int i, j;
275 int rc;
276 u8 out;
277
278 /* Clear any previous over-temperature alert */
279 rc = i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
280 if (rc < 0)
281 return rc;
282
283 /* Enable port 0 and port 1 outputs on IO expander */
284 rc = i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0x00);
285 if (rc)
286 return rc;
287 rc = i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG,
288 0xff & ~(1 << P1_SPARE_LBN));
289 if (rc)
290 goto fail_on;
291
292 /* If PHY power is on, turn it all off and wait 1 second to
293 * ensure a full reset.
294 */
295 rc = i2c_smbus_read_byte_data(ioexp_client, P0_OUT);
296 if (rc < 0)
297 goto fail_on;
298 out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
299 (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
300 (0 << P0_EN_1V0X_LBN));
301 if (rc != out) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000302 netif_info(efx, hw, efx->net_dev, "power-cycling PHY\n");
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000303 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
304 if (rc)
305 goto fail_on;
306 schedule_timeout_uninterruptible(HZ);
307 }
308
309 for (i = 0; i < 20; ++i) {
310 /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
311 out = 0xff & ~((1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
312 (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
313 (1 << P0_X_TRST_LBN));
314 if (efx->phy_mode & PHY_MODE_SPECIAL)
315 out |= 1 << P0_EN_3V3X_LBN;
316
317 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
318 if (rc)
319 goto fail_on;
320 msleep(10);
321
322 /* Turn on 1V power rail */
323 out &= ~(1 << P0_EN_1V0X_LBN);
324 rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
325 if (rc)
326 goto fail_on;
327
Ben Hutchings62776d02010-06-23 11:30:07 +0000328 netif_info(efx, hw, efx->net_dev,
329 "waiting for DSP boot (attempt %d)...\n", i);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000330
331 /* In flash config mode, DSP does not turn on AFE, so
332 * just wait 1 second.
333 */
334 if (efx->phy_mode & PHY_MODE_SPECIAL) {
335 schedule_timeout_uninterruptible(HZ);
336 return 0;
337 }
338
339 for (j = 0; j < 10; ++j) {
340 msleep(100);
341
342 /* Check DSP has asserted AFE power line */
343 rc = i2c_smbus_read_byte_data(ioexp_client, P1_IN);
344 if (rc < 0)
345 goto fail_on;
346 if (rc & (1 << P1_AFE_PWD_LBN))
347 return 0;
348 }
349 }
350
Ben Hutchings62776d02010-06-23 11:30:07 +0000351 netif_info(efx, hw, efx->net_dev, "timed out waiting for DSP boot\n");
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000352 rc = -ETIMEDOUT;
353fail_on:
354 sfe4001_poweroff(efx);
355 return rc;
356}
357
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000358static ssize_t show_phy_flash_cfg(struct device *dev,
359 struct device_attribute *attr, char *buf)
360{
361 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
362 return sprintf(buf, "%d\n", !!(efx->phy_mode & PHY_MODE_SPECIAL));
363}
364
365static ssize_t set_phy_flash_cfg(struct device *dev,
366 struct device_attribute *attr,
367 const char *buf, size_t count)
368{
369 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
370 enum efx_phy_mode old_mode, new_mode;
371 int err;
372
373 rtnl_lock();
374 old_mode = efx->phy_mode;
375 if (count == 0 || *buf == '0')
376 new_mode = old_mode & ~PHY_MODE_SPECIAL;
377 else
378 new_mode = PHY_MODE_SPECIAL;
Ben Hutchings4484cd72010-12-02 13:46:14 +0000379 if (!((old_mode ^ new_mode) & PHY_MODE_SPECIAL)) {
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000380 err = 0;
381 } else if (efx->state != STATE_RUNNING || netif_running(efx->net_dev)) {
382 err = -EBUSY;
383 } else {
384 /* Reset the PHY, reconfigure the MAC and enable/disable
385 * MAC stats accordingly. */
386 efx->phy_mode = new_mode;
387 if (new_mode & PHY_MODE_SPECIAL)
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000388 falcon_stop_nic_stats(efx);
Ben Hutchings8fbca792010-09-22 10:00:11 +0000389 err = sfe4001_poweron(efx);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000390 if (!err)
391 err = efx_reconfigure_port(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000392 if (!(new_mode & PHY_MODE_SPECIAL))
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000393 falcon_start_nic_stats(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000394 }
395 rtnl_unlock();
396
397 return err ? err : count;
398}
399
400static DEVICE_ATTR(phy_flash_cfg, 0644, show_phy_flash_cfg, set_phy_flash_cfg);
401
402static void sfe4001_fini(struct efx_nic *efx)
403{
Ben Hutchings278c0622009-11-23 16:05:12 +0000404 struct falcon_board *board = falcon_board(efx);
405
Ben Hutchings62776d02010-06-23 11:30:07 +0000406 netif_info(efx, drv, efx->net_dev, "%s\n", __func__);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000407
408 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
409 sfe4001_poweroff(efx);
Ben Hutchings278c0622009-11-23 16:05:12 +0000410 i2c_unregister_device(board->ioexp_client);
411 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000412}
413
414static int sfe4001_check_hw(struct efx_nic *efx)
415{
416 s32 status;
417
418 /* If XAUI link is up then do not monitor */
Ben Hutchings9007b9f2009-11-25 16:12:01 +0000419 if (EFX_WORKAROUND_7884(efx) && !efx->xmac_poll_required)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000420 return 0;
421
422 /* Check the powered status of the PHY. Lack of power implies that
423 * the MAX6647 has shut down power to it, probably due to a temp.
424 * alarm. Reading the power status rather than the MAX6647 status
425 * directly because the later is read-to-clear and would thus
426 * start to power up the PHY again when polled, causing us to blip
427 * the power undesirably.
428 * We know we can read from the IO expander because we did
429 * it during power-on. Assume failure now is bad news. */
Ben Hutchings278c0622009-11-23 16:05:12 +0000430 status = i2c_smbus_read_byte_data(falcon_board(efx)->ioexp_client, P1_IN);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000431 if (status >= 0 &&
432 (status & ((1 << P1_AFE_PWD_LBN) | (1 << P1_DSP_PWD25_LBN))) != 0)
433 return 0;
434
435 /* Use board power control, not PHY power control */
436 sfe4001_poweroff(efx);
437 efx->phy_mode = PHY_MODE_OFF;
438
439 return (status < 0) ? -EIO : -ERANGE;
440}
441
442static struct i2c_board_info sfe4001_hwmon_info = {
443 I2C_BOARD_INFO("max6647", 0x4e),
444};
445
446/* This board uses an I2C expander to provider power to the PHY, which needs to
447 * be turned on before the PHY can be used.
448 * Context: Process context, rtnl lock held
449 */
450static int sfe4001_init(struct efx_nic *efx)
451{
Ben Hutchings278c0622009-11-23 16:05:12 +0000452 struct falcon_board *board = falcon_board(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000453 int rc;
454
455#if defined(CONFIG_SENSORS_LM90) || defined(CONFIG_SENSORS_LM90_MODULE)
Ben Hutchings278c0622009-11-23 16:05:12 +0000456 board->hwmon_client =
Ben Hutchingse775fb92009-11-23 16:06:02 +0000457 i2c_new_device(&board->i2c_adap, &sfe4001_hwmon_info);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000458#else
Ben Hutchings278c0622009-11-23 16:05:12 +0000459 board->hwmon_client =
Ben Hutchingse775fb92009-11-23 16:06:02 +0000460 i2c_new_dummy(&board->i2c_adap, sfe4001_hwmon_info.addr);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000461#endif
Ben Hutchings278c0622009-11-23 16:05:12 +0000462 if (!board->hwmon_client)
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000463 return -EIO;
464
465 /* Raise board/PHY high limit from 85 to 90 degrees Celsius */
Ben Hutchings278c0622009-11-23 16:05:12 +0000466 rc = i2c_smbus_write_byte_data(board->hwmon_client,
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000467 MAX664X_REG_WLHO, 90);
468 if (rc)
469 goto fail_hwmon;
470
Ben Hutchingse775fb92009-11-23 16:06:02 +0000471 board->ioexp_client = i2c_new_dummy(&board->i2c_adap, PCA9539);
Ben Hutchings278c0622009-11-23 16:05:12 +0000472 if (!board->ioexp_client) {
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000473 rc = -EIO;
474 goto fail_hwmon;
475 }
476
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000477 if (efx->phy_mode & PHY_MODE_SPECIAL) {
478 /* PHY won't generate a 156.25 MHz clock and MAC stats fetch
479 * will fail. */
Ben Hutchings55edc6e2009-11-25 16:11:35 +0000480 falcon_stop_nic_stats(efx);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000481 }
482 rc = sfe4001_poweron(efx);
483 if (rc)
484 goto fail_ioexp;
485
486 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
487 if (rc)
488 goto fail_on;
489
Ben Hutchings62776d02010-06-23 11:30:07 +0000490 netif_info(efx, hw, efx->net_dev, "PHY is powered on\n");
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000491 return 0;
492
493fail_on:
494 sfe4001_poweroff(efx);
495fail_ioexp:
Ben Hutchings278c0622009-11-23 16:05:12 +0000496 i2c_unregister_device(board->ioexp_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000497fail_hwmon:
Ben Hutchings278c0622009-11-23 16:05:12 +0000498 i2c_unregister_device(board->hwmon_client);
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000499 return rc;
500}
501
Ben Hutchingsc9597d42009-10-23 08:29:33 +0000502/*****************************************************************************
Ben Hutchings8ceee662008-04-27 12:55:59 +0100503 * Support for the SFE4002
504 *
505 */
Ben Hutchings3e133c42008-11-04 20:34:56 +0000506static u8 sfe4002_lm87_channel = 0x03; /* use AIN not FAN inputs */
507
508static const u8 sfe4002_lm87_regs[] = {
Ben Hutchings242cc052010-02-19 13:34:03 +0000509 LM87_IN_LIMITS(0, 0x7c, 0x99), /* 2.5V: 1.8V +/- 10% */
510 LM87_IN_LIMITS(1, 0x4c, 0x5e), /* Vccp1: 1.2V +/- 10% */
511 LM87_IN_LIMITS(2, 0xac, 0xd4), /* 3.3V: 3.3V +/- 10% */
512 LM87_IN_LIMITS(3, 0xac, 0xd4), /* 5V: 5.0V +/- 10% */
513 LM87_IN_LIMITS(4, 0xac, 0xe0), /* 12V: 10.8-14V */
514 LM87_IN_LIMITS(5, 0x3f, 0x4f), /* Vccp2: 1.0V +/- 10% */
515 LM87_AIN_LIMITS(0, 0x98, 0xbb), /* AIN1: 1.66V +/- 10% */
516 LM87_AIN_LIMITS(1, 0x8a, 0xa9), /* AIN2: 1.5V +/- 10% */
517 LM87_TEMP_INT_LIMITS(0, 80 + FALCON_BOARD_TEMP_BIAS),
518 LM87_TEMP_EXT1_LIMITS(0, FALCON_JUNC_TEMP_MAX),
Ben Hutchings3e133c42008-11-04 20:34:56 +0000519 0
520};
521
522static struct i2c_board_info sfe4002_hwmon_info = {
523 I2C_BOARD_INFO("lm87", 0x2e),
524 .platform_data = &sfe4002_lm87_channel,
Ben Hutchings3e133c42008-11-04 20:34:56 +0000525};
526
Ben Hutchings8ceee662008-04-27 12:55:59 +0100527/****************************************************************************/
528/* LED allocations. Note that on rev A0 boards the schematic and the reality
529 * differ: red and green are swapped. Below is the fixed (A1) layout (there
530 * are only 3 A0 boards in existence, so no real reason to make this
531 * conditional).
532 */
533#define SFE4002_FAULT_LED (2) /* Red */
534#define SFE4002_RX_LED (0) /* Green */
535#define SFE4002_TX_LED (1) /* Amber */
536
Ben Hutchings981fc1b2009-11-23 16:04:23 +0000537static void sfe4002_init_phy(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100538{
539 /* Set the TX and RX LEDs to reflect status and activity, and the
540 * fault LED off */
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000541 falcon_qt202x_set_led(efx, SFE4002_TX_LED,
542 QUAKE_LED_TXLINK | QUAKE_LED_LINK_ACTSTAT);
543 falcon_qt202x_set_led(efx, SFE4002_RX_LED,
544 QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACTSTAT);
545 falcon_qt202x_set_led(efx, SFE4002_FAULT_LED, QUAKE_LED_OFF);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100546}
547
Ben Hutchings398468e2009-11-23 16:03:45 +0000548static void sfe4002_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100549{
Ben Hutchings398468e2009-11-23 16:03:45 +0000550 falcon_qt202x_set_led(
551 efx, SFE4002_FAULT_LED,
552 (mode == EFX_LED_ON) ? QUAKE_LED_ON : QUAKE_LED_OFF);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100553}
554
Ben Hutchings3e133c42008-11-04 20:34:56 +0000555static int sfe4002_check_hw(struct efx_nic *efx)
556{
Ben Hutchings278c0622009-11-23 16:05:12 +0000557 struct falcon_board *board = falcon_board(efx);
558
Ben Hutchings3e133c42008-11-04 20:34:56 +0000559 /* A0 board rev. 4002s report a temperature fault the whole time
560 * (bad sensor) so we mask it out. */
561 unsigned alarm_mask =
Ben Hutchings278c0622009-11-23 16:05:12 +0000562 (board->major == 0 && board->minor == 0) ?
Ben Hutchings3e133c42008-11-04 20:34:56 +0000563 ~LM87_ALARM_TEMP_EXT1 : ~0;
564
565 return efx_check_lm87(efx, alarm_mask);
566}
567
Ben Hutchings8ceee662008-04-27 12:55:59 +0100568static int sfe4002_init(struct efx_nic *efx)
569{
Ben Hutchings44838a42009-11-25 16:09:41 +0000570 return efx_init_lm87(efx, &sfe4002_hwmon_info, sfe4002_lm87_regs);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100571}
572
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000573/*****************************************************************************
574 * Support for the SFN4112F
575 *
576 */
577static u8 sfn4112f_lm87_channel = 0x03; /* use AIN not FAN inputs */
578
579static const u8 sfn4112f_lm87_regs[] = {
Ben Hutchings242cc052010-02-19 13:34:03 +0000580 LM87_IN_LIMITS(0, 0x7c, 0x99), /* 2.5V: 1.8V +/- 10% */
581 LM87_IN_LIMITS(1, 0x4c, 0x5e), /* Vccp1: 1.2V +/- 10% */
582 LM87_IN_LIMITS(2, 0xac, 0xd4), /* 3.3V: 3.3V +/- 10% */
583 LM87_IN_LIMITS(4, 0xac, 0xe0), /* 12V: 10.8-14V */
584 LM87_IN_LIMITS(5, 0x3f, 0x4f), /* Vccp2: 1.0V +/- 10% */
585 LM87_AIN_LIMITS(1, 0x8a, 0xa9), /* AIN2: 1.5V +/- 10% */
586 LM87_TEMP_INT_LIMITS(0, 60 + FALCON_BOARD_TEMP_BIAS),
587 LM87_TEMP_EXT1_LIMITS(0, FALCON_JUNC_TEMP_MAX),
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000588 0
589};
590
591static struct i2c_board_info sfn4112f_hwmon_info = {
592 I2C_BOARD_INFO("lm87", 0x2e),
593 .platform_data = &sfn4112f_lm87_channel,
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000594};
595
596#define SFN4112F_ACT_LED 0
597#define SFN4112F_LINK_LED 1
598
Ben Hutchings981fc1b2009-11-23 16:04:23 +0000599static void sfn4112f_init_phy(struct efx_nic *efx)
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000600{
Ben Hutchingsb37b62f2009-10-23 08:33:42 +0000601 falcon_qt202x_set_led(efx, SFN4112F_ACT_LED,
602 QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACT);
603 falcon_qt202x_set_led(efx, SFN4112F_LINK_LED,
604 QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000605}
606
Ben Hutchings398468e2009-11-23 16:03:45 +0000607static void sfn4112f_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000608{
Ben Hutchings398468e2009-11-23 16:03:45 +0000609 int reg;
610
611 switch (mode) {
612 case EFX_LED_OFF:
613 reg = QUAKE_LED_OFF;
614 break;
615 case EFX_LED_ON:
616 reg = QUAKE_LED_ON;
617 break;
618 default:
619 reg = QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT;
620 break;
621 }
622
623 falcon_qt202x_set_led(efx, SFN4112F_LINK_LED, reg);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000624}
625
626static int sfn4112f_check_hw(struct efx_nic *efx)
627{
628 /* Mask out unused sensors */
629 return efx_check_lm87(efx, ~0x48);
630}
631
632static int sfn4112f_init(struct efx_nic *efx)
633{
Ben Hutchings44838a42009-11-25 16:09:41 +0000634 return efx_init_lm87(efx, &sfn4112f_hwmon_info, sfn4112f_lm87_regs);
Ben Hutchings94f52cd2009-02-27 13:08:18 +0000635}
636
Ben Hutchings7e51b432010-09-22 10:00:47 +0000637/*****************************************************************************
638 * Support for the SFE4003
639 *
640 */
641static u8 sfe4003_lm87_channel = 0x03; /* use AIN not FAN inputs */
642
643static const u8 sfe4003_lm87_regs[] = {
644 LM87_IN_LIMITS(0, 0x67, 0x7f), /* 2.5V: 1.5V +/- 10% */
645 LM87_IN_LIMITS(1, 0x4c, 0x5e), /* Vccp1: 1.2V +/- 10% */
646 LM87_IN_LIMITS(2, 0xac, 0xd4), /* 3.3V: 3.3V +/- 10% */
647 LM87_IN_LIMITS(4, 0xac, 0xe0), /* 12V: 10.8-14V */
648 LM87_IN_LIMITS(5, 0x3f, 0x4f), /* Vccp2: 1.0V +/- 10% */
649 LM87_TEMP_INT_LIMITS(0, 70 + FALCON_BOARD_TEMP_BIAS),
650 0
651};
652
653static struct i2c_board_info sfe4003_hwmon_info = {
654 I2C_BOARD_INFO("lm87", 0x2e),
655 .platform_data = &sfe4003_lm87_channel,
656};
657
658/* Board-specific LED info. */
659#define SFE4003_RED_LED_GPIO 11
660#define SFE4003_LED_ON 1
661#define SFE4003_LED_OFF 0
662
663static void sfe4003_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
664{
665 struct falcon_board *board = falcon_board(efx);
666
667 /* The LEDs were not wired to GPIOs before A3 */
668 if (board->minor < 3 && board->major == 0)
669 return;
670
671 falcon_txc_set_gpio_val(
672 efx, SFE4003_RED_LED_GPIO,
673 (mode == EFX_LED_ON) ? SFE4003_LED_ON : SFE4003_LED_OFF);
674}
675
676static void sfe4003_init_phy(struct efx_nic *efx)
677{
678 struct falcon_board *board = falcon_board(efx);
679
680 /* The LEDs were not wired to GPIOs before A3 */
681 if (board->minor < 3 && board->major == 0)
682 return;
683
684 falcon_txc_set_gpio_dir(efx, SFE4003_RED_LED_GPIO, TXC_GPIO_DIR_OUTPUT);
685 falcon_txc_set_gpio_val(efx, SFE4003_RED_LED_GPIO, SFE4003_LED_OFF);
686}
687
688static int sfe4003_check_hw(struct efx_nic *efx)
689{
690 struct falcon_board *board = falcon_board(efx);
691
692 /* A0/A1/A2 board rev. 4003s report a temperature fault the whole time
693 * (bad sensor) so we mask it out. */
694 unsigned alarm_mask =
695 (board->major == 0 && board->minor <= 2) ?
696 ~LM87_ALARM_TEMP_EXT1 : ~0;
697
698 return efx_check_lm87(efx, alarm_mask);
699}
700
701static int sfe4003_init(struct efx_nic *efx)
702{
703 return efx_init_lm87(efx, &sfe4003_hwmon_info, sfe4003_lm87_regs);
704}
705
Ben Hutchings44838a42009-11-25 16:09:41 +0000706static const struct falcon_board_type board_types[] = {
707 {
708 .id = FALCON_BOARD_SFE4001,
709 .ref_model = "SFE4001",
710 .gen_type = "10GBASE-T adapter",
711 .init = sfe4001_init,
712 .init_phy = efx_port_dummy_op_void,
713 .fini = sfe4001_fini,
714 .set_id_led = tenxpress_set_id_led,
715 .monitor = sfe4001_check_hw,
716 },
717 {
718 .id = FALCON_BOARD_SFE4002,
719 .ref_model = "SFE4002",
720 .gen_type = "XFP adapter",
721 .init = sfe4002_init,
722 .init_phy = sfe4002_init_phy,
723 .fini = efx_fini_lm87,
724 .set_id_led = sfe4002_set_id_led,
725 .monitor = sfe4002_check_hw,
726 },
727 {
Ben Hutchings7e51b432010-09-22 10:00:47 +0000728 .id = FALCON_BOARD_SFE4003,
729 .ref_model = "SFE4003",
730 .gen_type = "10GBASE-CX4 adapter",
731 .init = sfe4003_init,
732 .init_phy = sfe4003_init_phy,
733 .fini = efx_fini_lm87,
734 .set_id_led = sfe4003_set_id_led,
735 .monitor = sfe4003_check_hw,
736 },
737 {
Ben Hutchings44838a42009-11-25 16:09:41 +0000738 .id = FALCON_BOARD_SFN4112F,
739 .ref_model = "SFN4112F",
740 .gen_type = "SFP+ adapter",
741 .init = sfn4112f_init,
742 .init_phy = sfn4112f_init_phy,
743 .fini = efx_fini_lm87,
744 .set_id_led = sfn4112f_set_id_led,
745 .monitor = sfn4112f_check_hw,
746 },
Ben Hutchings8ceee662008-04-27 12:55:59 +0100747};
748
Ben Hutchingse41c11e2010-04-28 09:01:50 +0000749int falcon_probe_board(struct efx_nic *efx, u16 revision_info)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100750{
Ben Hutchings278c0622009-11-23 16:05:12 +0000751 struct falcon_board *board = falcon_board(efx);
Ben Hutchings44838a42009-11-25 16:09:41 +0000752 u8 type_id = FALCON_BOARD_TYPE(revision_info);
Ben Hutchings04300d22008-12-12 21:48:09 -0800753 int i;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100754
Ben Hutchings278c0622009-11-23 16:05:12 +0000755 board->major = FALCON_BOARD_MAJOR(revision_info);
756 board->minor = FALCON_BOARD_MINOR(revision_info);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100757
Ben Hutchings44838a42009-11-25 16:09:41 +0000758 for (i = 0; i < ARRAY_SIZE(board_types); i++)
759 if (board_types[i].id == type_id)
760 board->type = &board_types[i];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100761
Ben Hutchings44838a42009-11-25 16:09:41 +0000762 if (board->type) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000763 netif_info(efx, probe, efx->net_dev, "board is %s rev %c%d\n",
Ben Hutchings8ceee662008-04-27 12:55:59 +0100764 (efx->pci_dev->subsystem_vendor == EFX_VENDID_SFC)
Ben Hutchings44838a42009-11-25 16:09:41 +0000765 ? board->type->ref_model : board->type->gen_type,
Ben Hutchings278c0622009-11-23 16:05:12 +0000766 'A' + board->major, board->minor);
Ben Hutchingse41c11e2010-04-28 09:01:50 +0000767 return 0;
Ben Hutchings04300d22008-12-12 21:48:09 -0800768 } else {
Ben Hutchings62776d02010-06-23 11:30:07 +0000769 netif_err(efx, probe, efx->net_dev, "unknown board type %d\n",
770 type_id);
Ben Hutchingse41c11e2010-04-28 09:01:50 +0000771 return -ENODEV;
Ben Hutchings04300d22008-12-12 21:48:09 -0800772 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100773}