1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2007 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.
10 #include "net_driver.h"
15 /* Macros for unpacking the board revision */
16 /* The revision info is in host byte order. */
17 #define BOARD_TYPE(_rev) (_rev >> 8)
18 #define BOARD_MAJOR(_rev) ((_rev >> 4) & 0xf)
19 #define BOARD_MINOR(_rev) (_rev & 0xf)
21 /* Blink support. If the PHY has no auto-blink mode so we hang it off a timer */
22 #define BLINK_INTERVAL (HZ/2)
24 static void blink_led_timer(unsigned long context
)
26 struct efx_nic
*efx
= (struct efx_nic
*)context
;
27 struct efx_blinker
*bl
= &efx
->board_info
.blinker
;
28 efx
->board_info
.set_fault_led(efx
, bl
->state
);
29 bl
->state
= !bl
->state
;
31 mod_timer(&bl
->timer
, jiffies
+ BLINK_INTERVAL
);
34 static void board_blink(struct efx_nic
*efx
, int blink
)
36 struct efx_blinker
*blinker
= &efx
->board_info
.blinker
;
38 /* The rtnl mutex serialises all ethtool ioctls, so
39 * nothing special needs doing here. */
41 blinker
->resubmit
= 1;
43 setup_timer(&blinker
->timer
, blink_led_timer
,
45 mod_timer(&blinker
->timer
, jiffies
+ BLINK_INTERVAL
);
47 blinker
->resubmit
= 0;
48 if (blinker
->timer
.function
)
49 del_timer_sync(&blinker
->timer
);
50 efx
->board_info
.set_fault_led(efx
, 0);
54 /*****************************************************************************
55 * Support for the SFE4002
58 /****************************************************************************/
59 /* LED allocations. Note that on rev A0 boards the schematic and the reality
60 * differ: red and green are swapped. Below is the fixed (A1) layout (there
61 * are only 3 A0 boards in existence, so no real reason to make this
64 #define SFE4002_FAULT_LED (2) /* Red */
65 #define SFE4002_RX_LED (0) /* Green */
66 #define SFE4002_TX_LED (1) /* Amber */
68 static int sfe4002_init_leds(struct efx_nic
*efx
)
70 /* Set the TX and RX LEDs to reflect status and activity, and the
72 xfp_set_led(efx
, SFE4002_TX_LED
,
73 QUAKE_LED_TXLINK
| QUAKE_LED_LINK_ACTSTAT
);
74 xfp_set_led(efx
, SFE4002_RX_LED
,
75 QUAKE_LED_RXLINK
| QUAKE_LED_LINK_ACTSTAT
);
76 xfp_set_led(efx
, SFE4002_FAULT_LED
, QUAKE_LED_OFF
);
77 efx
->board_info
.blinker
.led_num
= SFE4002_FAULT_LED
;
81 static void sfe4002_fault_led(struct efx_nic
*efx
, int state
)
83 xfp_set_led(efx
, SFE4002_FAULT_LED
, state
? QUAKE_LED_ON
:
87 static int sfe4002_init(struct efx_nic
*efx
)
89 efx
->board_info
.init_leds
= sfe4002_init_leds
;
90 efx
->board_info
.set_fault_led
= sfe4002_fault_led
;
91 efx
->board_info
.blink
= board_blink
;
95 /* This will get expanded as board-specific details get moved out of the
97 struct efx_board_data
{
98 const char *ref_model
;
100 int (*init
) (struct efx_nic
*nic
);
103 static int dummy_init(struct efx_nic
*nic
)
108 static struct efx_board_data board_data
[] = {
109 [EFX_BOARD_INVALID
] =
110 {NULL
, NULL
, dummy_init
},
111 [EFX_BOARD_SFE4001
] =
112 {"SFE4001", "10GBASE-T adapter", sfe4001_poweron
},
113 [EFX_BOARD_SFE4002
] =
114 {"SFE4002", "XFP adapter", sfe4002_init
},
117 int efx_set_board_info(struct efx_nic
*efx
, u16 revision_info
)
120 struct efx_board_data
*data
;
122 if (BOARD_TYPE(revision_info
) >= EFX_BOARD_MAX
) {
123 EFX_ERR(efx
, "squashing unknown board type %d\n",
124 BOARD_TYPE(revision_info
));
128 if (BOARD_TYPE(revision_info
) == 0) {
129 efx
->board_info
.major
= 0;
130 efx
->board_info
.minor
= 0;
131 /* For early boards that don't have revision info. there is
132 * only 1 board for each PHY type, so we can work it out, with
133 * the exception of the PHY-less boards. */
134 switch (efx
->phy_type
) {
135 case PHY_TYPE_10XPRESS
:
136 efx
->board_info
.type
= EFX_BOARD_SFE4001
;
139 efx
->board_info
.type
= EFX_BOARD_SFE4002
;
142 efx
->board_info
.type
= 0;
146 efx
->board_info
.type
= BOARD_TYPE(revision_info
);
147 efx
->board_info
.major
= BOARD_MAJOR(revision_info
);
148 efx
->board_info
.minor
= BOARD_MINOR(revision_info
);
151 data
= &board_data
[efx
->board_info
.type
];
153 /* Report the board model number or generic type for recognisable
155 if (efx
->board_info
.type
!= 0)
156 EFX_INFO(efx
, "board is %s rev %c%d\n",
157 (efx
->pci_dev
->subsystem_vendor
== EFX_VENDID_SFC
)
158 ? data
->ref_model
: data
->gen_type
,
159 'A' + efx
->board_info
.major
, efx
->board_info
.minor
);
161 efx
->board_info
.init
= data
->init
;