Merge git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/v4l-dvb
[pandora-kernel.git] / drivers / net / sfc / boards.c
1 /****************************************************************************
2  * Driver for Solarflare Solarstorm network controllers and boards
3  * Copyright 2007 Solarflare Communications Inc.
4  *
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
10 #include "net_driver.h"
11 #include "phy.h"
12 #include "boards.h"
13 #include "efx.h"
14
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)
20
21 /* Blink support. If the PHY has no auto-blink mode so we hang it off a timer */
22 #define BLINK_INTERVAL (HZ/2)
23
24 static void blink_led_timer(unsigned long context)
25 {
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;
30         if (bl->resubmit)
31                 mod_timer(&bl->timer, jiffies + BLINK_INTERVAL);
32 }
33
34 static void board_blink(struct efx_nic *efx, int blink)
35 {
36         struct efx_blinker *blinker = &efx->board_info.blinker;
37
38         /* The rtnl mutex serialises all ethtool ioctls, so
39          * nothing special needs doing here. */
40         if (blink) {
41                 blinker->resubmit = 1;
42                 blinker->state = 0;
43                 setup_timer(&blinker->timer, blink_led_timer,
44                             (unsigned long)efx);
45                 mod_timer(&blinker->timer, jiffies + BLINK_INTERVAL);
46         } else {
47                 blinker->resubmit = 0;
48                 if (blinker->timer.function)
49                         del_timer_sync(&blinker->timer);
50                 efx->board_info.set_fault_led(efx, 0);
51         }
52 }
53
54 /*****************************************************************************
55  * Support for the SFE4002
56  *
57  */
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
62  * conditional).
63  */
64 #define SFE4002_FAULT_LED (2)   /* Red */
65 #define SFE4002_RX_LED    (0)   /* Green */
66 #define SFE4002_TX_LED    (1)   /* Amber */
67
68 static int sfe4002_init_leds(struct efx_nic *efx)
69 {
70         /* Set the TX and RX LEDs to reflect status and activity, and the
71          * fault LED off */
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;
78         return 0;
79 }
80
81 static void sfe4002_fault_led(struct efx_nic *efx, int state)
82 {
83         xfp_set_led(efx, SFE4002_FAULT_LED, state ? QUAKE_LED_ON :
84                         QUAKE_LED_OFF);
85 }
86
87 static int sfe4002_init(struct efx_nic *efx)
88 {
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;
92         return 0;
93 }
94
95 /* This will get expanded as board-specific details get moved out of the
96  * PHY drivers. */
97 struct efx_board_data {
98         const char *ref_model;
99         const char *gen_type;
100         int (*init) (struct efx_nic *nic);
101 };
102
103 static int dummy_init(struct efx_nic *nic)
104 {
105         return 0;
106 }
107
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_init},
113         [EFX_BOARD_SFE4002] =
114         {"SFE4002", "XFP adapter",         sfe4002_init},
115 };
116
117 int efx_set_board_info(struct efx_nic *efx, u16 revision_info)
118 {
119         int rc = 0;
120         struct efx_board_data *data;
121
122         if (BOARD_TYPE(revision_info) >= EFX_BOARD_MAX) {
123                 EFX_ERR(efx, "squashing unknown board type %d\n",
124                         BOARD_TYPE(revision_info));
125                 revision_info = 0;
126         }
127
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;
137                         break;
138                 case PHY_TYPE_XFP:
139                         efx->board_info.type = EFX_BOARD_SFE4002;
140                         break;
141                 default:
142                         efx->board_info.type = 0;
143                         break;
144                 }
145         } else {
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);
149         }
150
151         data = &board_data[efx->board_info.type];
152
153         /* Report the board model number or generic type for recognisable
154          * boards. */
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);
160
161         efx->board_info.init = data->init;
162
163         return rc;
164 }