sfc: Rename Falcon-specific board code and types
[linux-2.6/x86.git] / drivers / net / sfc / falcon_boards.c
blob431b74c4a96e19806a0429ee80b7c68461a118cc
1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2007-2008 Solarflare Communications Inc.
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 */
10 #include "net_driver.h"
11 #include "phy.h"
12 #include "boards.h"
13 #include "efx.h"
14 #include "workarounds.h"
16 /* Macros for unpacking the board revision */
17 /* The revision info is in host byte order. */
18 #define FALCON_BOARD_TYPE(_rev) (_rev >> 8)
19 #define FALCON_BOARD_MAJOR(_rev) ((_rev >> 4) & 0xf)
20 #define FALCON_BOARD_MINOR(_rev) (_rev & 0xf)
22 /* Board types */
23 #define FALCON_BOARD_SFE4002 0x02
24 #define FALCON_BOARD_SFN4111T 0x51
25 #define FALCON_BOARD_SFN4112F 0x52
27 /* Blink support. If the PHY has no auto-blink mode so we hang it off a timer */
28 #define BLINK_INTERVAL (HZ/2)
30 static void blink_led_timer(unsigned long context)
32 struct efx_nic *efx = (struct efx_nic *)context;
33 struct efx_blinker *bl = &efx->board_info.blinker;
34 efx->board_info.set_id_led(efx, bl->state);
35 bl->state = !bl->state;
36 if (bl->resubmit)
37 mod_timer(&bl->timer, jiffies + BLINK_INTERVAL);
40 static void board_blink(struct efx_nic *efx, bool blink)
42 struct efx_blinker *blinker = &efx->board_info.blinker;
44 /* The rtnl mutex serialises all ethtool ioctls, so
45 * nothing special needs doing here. */
46 if (blink) {
47 blinker->resubmit = true;
48 blinker->state = false;
49 setup_timer(&blinker->timer, blink_led_timer,
50 (unsigned long)efx);
51 mod_timer(&blinker->timer, jiffies + BLINK_INTERVAL);
52 } else {
53 blinker->resubmit = false;
54 if (blinker->timer.function)
55 del_timer_sync(&blinker->timer);
56 efx->board_info.init_leds(efx);
60 /*****************************************************************************
61 * Support for LM87 sensor chip used on several boards
63 #define LM87_REG_ALARMS1 0x41
64 #define LM87_REG_ALARMS2 0x42
65 #define LM87_IN_LIMITS(nr, _min, _max) \
66 0x2B + (nr) * 2, _max, 0x2C + (nr) * 2, _min
67 #define LM87_AIN_LIMITS(nr, _min, _max) \
68 0x3B + (nr), _max, 0x1A + (nr), _min
69 #define LM87_TEMP_INT_LIMITS(_min, _max) \
70 0x39, _max, 0x3A, _min
71 #define LM87_TEMP_EXT1_LIMITS(_min, _max) \
72 0x37, _max, 0x38, _min
74 #define LM87_ALARM_TEMP_INT 0x10
75 #define LM87_ALARM_TEMP_EXT1 0x20
77 #if defined(CONFIG_SENSORS_LM87) || defined(CONFIG_SENSORS_LM87_MODULE)
79 static int efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
80 const u8 *reg_values)
82 struct i2c_client *client = i2c_new_device(&efx->i2c_adap, info);
83 int rc;
85 if (!client)
86 return -EIO;
88 while (*reg_values) {
89 u8 reg = *reg_values++;
90 u8 value = *reg_values++;
91 rc = i2c_smbus_write_byte_data(client, reg, value);
92 if (rc)
93 goto err;
96 efx->board_info.hwmon_client = client;
97 return 0;
99 err:
100 i2c_unregister_device(client);
101 return rc;
104 static void efx_fini_lm87(struct efx_nic *efx)
106 i2c_unregister_device(efx->board_info.hwmon_client);
109 static int efx_check_lm87(struct efx_nic *efx, unsigned mask)
111 struct i2c_client *client = efx->board_info.hwmon_client;
112 s32 alarms1, alarms2;
114 /* If link is up then do not monitor temperature */
115 if (EFX_WORKAROUND_7884(efx) && efx->link_up)
116 return 0;
118 alarms1 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS1);
119 alarms2 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS2);
120 if (alarms1 < 0)
121 return alarms1;
122 if (alarms2 < 0)
123 return alarms2;
124 alarms1 &= mask;
125 alarms2 &= mask >> 8;
126 if (alarms1 || alarms2) {
127 EFX_ERR(efx,
128 "LM87 detected a hardware failure (status %02x:%02x)"
129 "%s%s\n",
130 alarms1, alarms2,
131 (alarms1 & LM87_ALARM_TEMP_INT) ? " INTERNAL" : "",
132 (alarms1 & LM87_ALARM_TEMP_EXT1) ? " EXTERNAL" : "");
133 return -ERANGE;
136 return 0;
139 #else /* !CONFIG_SENSORS_LM87 */
141 static inline int
142 efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
143 const u8 *reg_values)
145 return 0;
147 static inline void efx_fini_lm87(struct efx_nic *efx)
150 static inline int efx_check_lm87(struct efx_nic *efx, unsigned mask)
152 return 0;
155 #endif /* CONFIG_SENSORS_LM87 */
157 /*****************************************************************************
158 * Support for the SFE4002
161 static u8 sfe4002_lm87_channel = 0x03; /* use AIN not FAN inputs */
163 static const u8 sfe4002_lm87_regs[] = {
164 LM87_IN_LIMITS(0, 0x83, 0x91), /* 2.5V: 1.8V +/- 5% */
165 LM87_IN_LIMITS(1, 0x51, 0x5a), /* Vccp1: 1.2V +/- 5% */
166 LM87_IN_LIMITS(2, 0xb6, 0xca), /* 3.3V: 3.3V +/- 5% */
167 LM87_IN_LIMITS(3, 0xb0, 0xc9), /* 5V: 4.6-5.2V */
168 LM87_IN_LIMITS(4, 0xb0, 0xe0), /* 12V: 11-14V */
169 LM87_IN_LIMITS(5, 0x44, 0x4b), /* Vccp2: 1.0V +/- 5% */
170 LM87_AIN_LIMITS(0, 0xa0, 0xb2), /* AIN1: 1.66V +/- 5% */
171 LM87_AIN_LIMITS(1, 0x91, 0xa1), /* AIN2: 1.5V +/- 5% */
172 LM87_TEMP_INT_LIMITS(10, 60), /* board */
173 LM87_TEMP_EXT1_LIMITS(10, 70), /* Falcon */
177 static struct i2c_board_info sfe4002_hwmon_info = {
178 I2C_BOARD_INFO("lm87", 0x2e),
179 .platform_data = &sfe4002_lm87_channel,
182 /****************************************************************************/
183 /* LED allocations. Note that on rev A0 boards the schematic and the reality
184 * differ: red and green are swapped. Below is the fixed (A1) layout (there
185 * are only 3 A0 boards in existence, so no real reason to make this
186 * conditional).
188 #define SFE4002_FAULT_LED (2) /* Red */
189 #define SFE4002_RX_LED (0) /* Green */
190 #define SFE4002_TX_LED (1) /* Amber */
192 static void sfe4002_init_leds(struct efx_nic *efx)
194 /* Set the TX and RX LEDs to reflect status and activity, and the
195 * fault LED off */
196 xfp_set_led(efx, SFE4002_TX_LED,
197 QUAKE_LED_TXLINK | QUAKE_LED_LINK_ACTSTAT);
198 xfp_set_led(efx, SFE4002_RX_LED,
199 QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACTSTAT);
200 xfp_set_led(efx, SFE4002_FAULT_LED, QUAKE_LED_OFF);
203 static void sfe4002_set_id_led(struct efx_nic *efx, bool state)
205 xfp_set_led(efx, SFE4002_FAULT_LED, state ? QUAKE_LED_ON :
206 QUAKE_LED_OFF);
209 static int sfe4002_check_hw(struct efx_nic *efx)
211 /* A0 board rev. 4002s report a temperature fault the whole time
212 * (bad sensor) so we mask it out. */
213 unsigned alarm_mask =
214 (efx->board_info.major == 0 && efx->board_info.minor == 0) ?
215 ~LM87_ALARM_TEMP_EXT1 : ~0;
217 return efx_check_lm87(efx, alarm_mask);
220 static int sfe4002_init(struct efx_nic *efx)
222 int rc = efx_init_lm87(efx, &sfe4002_hwmon_info, sfe4002_lm87_regs);
223 if (rc)
224 return rc;
225 efx->board_info.monitor = sfe4002_check_hw;
226 efx->board_info.init_leds = sfe4002_init_leds;
227 efx->board_info.set_id_led = sfe4002_set_id_led;
228 efx->board_info.blink = board_blink;
229 efx->board_info.fini = efx_fini_lm87;
230 return 0;
233 /*****************************************************************************
234 * Support for the SFN4112F
237 static u8 sfn4112f_lm87_channel = 0x03; /* use AIN not FAN inputs */
239 static const u8 sfn4112f_lm87_regs[] = {
240 LM87_IN_LIMITS(0, 0x83, 0x91), /* 2.5V: 1.8V +/- 5% */
241 LM87_IN_LIMITS(1, 0x51, 0x5a), /* Vccp1: 1.2V +/- 5% */
242 LM87_IN_LIMITS(2, 0xb6, 0xca), /* 3.3V: 3.3V +/- 5% */
243 LM87_IN_LIMITS(4, 0xb0, 0xe0), /* 12V: 11-14V */
244 LM87_IN_LIMITS(5, 0x44, 0x4b), /* Vccp2: 1.0V +/- 5% */
245 LM87_AIN_LIMITS(1, 0x91, 0xa1), /* AIN2: 1.5V +/- 5% */
246 LM87_TEMP_INT_LIMITS(10, 60), /* board */
247 LM87_TEMP_EXT1_LIMITS(10, 70), /* Falcon */
251 static struct i2c_board_info sfn4112f_hwmon_info = {
252 I2C_BOARD_INFO("lm87", 0x2e),
253 .platform_data = &sfn4112f_lm87_channel,
256 #define SFN4112F_ACT_LED 0
257 #define SFN4112F_LINK_LED 1
259 static void sfn4112f_init_leds(struct efx_nic *efx)
261 xfp_set_led(efx, SFN4112F_ACT_LED,
262 QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACT);
263 xfp_set_led(efx, SFN4112F_LINK_LED,
264 QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT);
267 static void sfn4112f_set_id_led(struct efx_nic *efx, bool state)
269 xfp_set_led(efx, SFN4112F_LINK_LED,
270 state ? QUAKE_LED_ON : QUAKE_LED_OFF);
273 static int sfn4112f_check_hw(struct efx_nic *efx)
275 /* Mask out unused sensors */
276 return efx_check_lm87(efx, ~0x48);
279 static int sfn4112f_init(struct efx_nic *efx)
281 int rc = efx_init_lm87(efx, &sfn4112f_hwmon_info, sfn4112f_lm87_regs);
282 if (rc)
283 return rc;
284 efx->board_info.monitor = sfn4112f_check_hw;
285 efx->board_info.init_leds = sfn4112f_init_leds;
286 efx->board_info.set_id_led = sfn4112f_set_id_led;
287 efx->board_info.blink = board_blink;
288 efx->board_info.fini = efx_fini_lm87;
289 return 0;
292 /* This will get expanded as board-specific details get moved out of the
293 * PHY drivers. */
294 struct falcon_board_data {
295 u8 type;
296 const char *ref_model;
297 const char *gen_type;
298 int (*init) (struct efx_nic *nic);
302 static struct falcon_board_data board_data[] = {
303 { FALCON_BOARD_SFE4001, "SFE4001", "10GBASE-T adapter", sfe4001_init },
304 { FALCON_BOARD_SFE4002, "SFE4002", "XFP adapter", sfe4002_init },
305 { FALCON_BOARD_SFN4111T, "SFN4111T", "100/1000/10GBASE-T adapter",
306 sfn4111t_init },
307 { FALCON_BOARD_SFN4112F, "SFN4112F", "SFP+ adapter",
308 sfn4112f_init },
311 void falcon_probe_board(struct efx_nic *efx, u16 revision_info)
313 struct falcon_board_data *data = NULL;
314 int i;
316 efx->board_info.type = FALCON_BOARD_TYPE(revision_info);
317 efx->board_info.major = FALCON_BOARD_MAJOR(revision_info);
318 efx->board_info.minor = FALCON_BOARD_MINOR(revision_info);
320 for (i = 0; i < ARRAY_SIZE(board_data); i++)
321 if (board_data[i].type == efx->board_info.type)
322 data = &board_data[i];
324 if (data) {
325 EFX_INFO(efx, "board is %s rev %c%d\n",
326 (efx->pci_dev->subsystem_vendor == EFX_VENDID_SFC)
327 ? data->ref_model : data->gen_type,
328 'A' + efx->board_info.major, efx->board_info.minor);
329 efx->board_info.init = data->init;
330 } else {
331 EFX_ERR(efx, "unknown board type %d\n", efx->board_info.type);