Pull acpica into release branch
[pandora-kernel.git] / drivers / net / ixp2000 / enp2611.c
1 /*
2  * IXP2400 MSF network device driver for the Radisys ENP2611
3  * Copyright (C) 2004, 2005 Lennert Buytenhek <buytenh@wantstofly.org>
4  * Dedicated to Marija Kulikova.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  */
11
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/netdevice.h>
16 #include <linux/etherdevice.h>
17 #include <linux/init.h>
18 #include <linux/moduleparam.h>
19 #include <asm/hardware/uengine.h>
20 #include <asm/mach-types.h>
21 #include <asm/io.h>
22 #include "ixpdev.h"
23 #include "caleb.h"
24 #include "ixp2400-msf.h"
25 #include "pm3386.h"
26
27 /***********************************************************************
28  * The Radisys ENP2611 is a PCI form factor board with three SFP GBIC
29  * slots, connected via two PMC/Sierra 3386s and an SPI-3 bridge FPGA
30  * to the IXP2400.
31  *
32  *                +-------------+
33  * SFP GBIC #0 ---+             |       +---------+
34  *                |  PM3386 #0  +-------+         |
35  * SFP GBIC #1 ---+             |       | "Caleb" |         +---------+
36  *                +-------------+       |         |         |         |
37  *                                      | SPI-3   +---------+ IXP2400 |
38  *                +-------------+       | bridge  |         |         |
39  * SFP GBIC #2 ---+             |       | FPGA    |         +---------+
40  *                |  PM3386 #1  +-------+         |
41  *                |             |       +---------+
42  *                +-------------+
43  *              ^                   ^                  ^
44  *              | 1.25Gbaud         | 104MHz           | 104MHz
45  *              | SERDES ea.        | SPI-3 ea.        | SPI-3
46  *
47  ***********************************************************************/
48 static struct ixp2400_msf_parameters enp2611_msf_parameters =
49 {
50         .rx_mode =              IXP2400_RX_MODE_UTOPIA_POS |
51                                 IXP2400_RX_MODE_1x32 |
52                                 IXP2400_RX_MODE_MPHY |
53                                 IXP2400_RX_MODE_MPHY_32 |
54                                 IXP2400_RX_MODE_MPHY_POLLED_STATUS |
55                                 IXP2400_RX_MODE_MPHY_LEVEL3 |
56                                 IXP2400_RX_MODE_RBUF_SIZE_64,
57
58         .rxclk01_multiplier =   IXP2400_PLL_MULTIPLIER_16,
59
60         .rx_poll_ports =        3,
61
62         .rx_channel_mode = {
63                 IXP2400_PORT_RX_MODE_MASTER |
64                 IXP2400_PORT_RX_MODE_POS_PHY |
65                 IXP2400_PORT_RX_MODE_POS_PHY_L3 |
66                 IXP2400_PORT_RX_MODE_ODD_PARITY |
67                 IXP2400_PORT_RX_MODE_2_CYCLE_DECODE,
68
69                 IXP2400_PORT_RX_MODE_MASTER |
70                 IXP2400_PORT_RX_MODE_POS_PHY |
71                 IXP2400_PORT_RX_MODE_POS_PHY_L3 |
72                 IXP2400_PORT_RX_MODE_ODD_PARITY |
73                 IXP2400_PORT_RX_MODE_2_CYCLE_DECODE,
74
75                 IXP2400_PORT_RX_MODE_MASTER |
76                 IXP2400_PORT_RX_MODE_POS_PHY |
77                 IXP2400_PORT_RX_MODE_POS_PHY_L3 |
78                 IXP2400_PORT_RX_MODE_ODD_PARITY |
79                 IXP2400_PORT_RX_MODE_2_CYCLE_DECODE,
80
81                 IXP2400_PORT_RX_MODE_MASTER |
82                 IXP2400_PORT_RX_MODE_POS_PHY |
83                 IXP2400_PORT_RX_MODE_POS_PHY_L3 |
84                 IXP2400_PORT_RX_MODE_ODD_PARITY |
85                 IXP2400_PORT_RX_MODE_2_CYCLE_DECODE
86         },
87
88         .tx_mode =              IXP2400_TX_MODE_UTOPIA_POS |
89                                 IXP2400_TX_MODE_1x32 |
90                                 IXP2400_TX_MODE_MPHY |
91                                 IXP2400_TX_MODE_MPHY_32 |
92                                 IXP2400_TX_MODE_MPHY_POLLED_STATUS |
93                                 IXP2400_TX_MODE_MPHY_LEVEL3 |
94                                 IXP2400_TX_MODE_TBUF_SIZE_64,
95
96         .txclk01_multiplier =   IXP2400_PLL_MULTIPLIER_16,
97
98         .tx_poll_ports =        3,
99
100         .tx_channel_mode = {
101                 IXP2400_PORT_TX_MODE_MASTER |
102                 IXP2400_PORT_TX_MODE_POS_PHY |
103                 IXP2400_PORT_TX_MODE_ODD_PARITY |
104                 IXP2400_PORT_TX_MODE_2_CYCLE_DECODE,
105
106                 IXP2400_PORT_TX_MODE_MASTER |
107                 IXP2400_PORT_TX_MODE_POS_PHY |
108                 IXP2400_PORT_TX_MODE_ODD_PARITY |
109                 IXP2400_PORT_TX_MODE_2_CYCLE_DECODE,
110
111                 IXP2400_PORT_TX_MODE_MASTER |
112                 IXP2400_PORT_TX_MODE_POS_PHY |
113                 IXP2400_PORT_TX_MODE_ODD_PARITY |
114                 IXP2400_PORT_TX_MODE_2_CYCLE_DECODE,
115
116                 IXP2400_PORT_TX_MODE_MASTER |
117                 IXP2400_PORT_TX_MODE_POS_PHY |
118                 IXP2400_PORT_TX_MODE_ODD_PARITY |
119                 IXP2400_PORT_TX_MODE_2_CYCLE_DECODE
120         }
121 };
122
123 struct enp2611_ixpdev_priv
124 {
125         struct ixpdev_priv              ixpdev_priv;
126         struct net_device_stats         stats;
127 };
128
129 static struct net_device *nds[3];
130 static struct timer_list link_check_timer;
131
132 static struct net_device_stats *enp2611_get_stats(struct net_device *dev)
133 {
134         struct enp2611_ixpdev_priv *ip = netdev_priv(dev);
135
136         pm3386_get_stats(ip->ixpdev_priv.channel, &(ip->stats));
137
138         return &(ip->stats);
139 }
140
141 /* @@@ Poll the SFP moddef0 line too.  */
142 /* @@@ Try to use the pm3386 DOOL interrupt as well.  */
143 static void enp2611_check_link_status(unsigned long __dummy)
144 {
145         int i;
146
147         for (i = 0; i < 3; i++) {
148                 struct net_device *dev;
149                 int status;
150
151                 dev = nds[i];
152                 if (dev == NULL)
153                         continue;
154
155                 status = pm3386_is_link_up(i);
156                 if (status && !netif_carrier_ok(dev)) {
157                         /* @@@ Should report autonegotiation status.  */
158                         printk(KERN_INFO "%s: NIC Link is Up\n", dev->name);
159
160                         pm3386_enable_tx(i);
161                         caleb_enable_tx(i);
162                         netif_carrier_on(dev);
163                 } else if (!status && netif_carrier_ok(dev)) {
164                         printk(KERN_INFO "%s: NIC Link is Down\n", dev->name);
165
166                         netif_carrier_off(dev);
167                         caleb_disable_tx(i);
168                         pm3386_disable_tx(i);
169                 }
170         }
171
172         link_check_timer.expires = jiffies + HZ / 10;
173         add_timer(&link_check_timer);
174 }
175
176 static void enp2611_set_port_admin_status(int port, int up)
177 {
178         if (up) {
179                 caleb_enable_rx(port);
180
181                 pm3386_set_carrier(port, 1);
182                 pm3386_enable_rx(port);
183         } else {
184                 caleb_disable_tx(port);
185                 pm3386_disable_tx(port);
186                 /* @@@ Flush out pending packets.  */
187                 pm3386_set_carrier(port, 0);
188
189                 pm3386_disable_rx(port);
190                 caleb_disable_rx(port);
191         }
192 }
193
194 static int __init enp2611_init_module(void)
195
196         int ports;
197         int i;
198
199         if (!machine_is_enp2611())
200                 return -ENODEV;
201
202         caleb_reset();
203         pm3386_reset();
204
205         ports = pm3386_port_count();
206         for (i = 0; i < ports; i++) {
207                 nds[i] = ixpdev_alloc(i, sizeof(struct enp2611_ixpdev_priv));
208                 if (nds[i] == NULL) {
209                         while (--i >= 0)
210                                 free_netdev(nds[i]);
211                         return -ENOMEM;
212                 }
213
214                 SET_MODULE_OWNER(nds[i]);
215                 nds[i]->get_stats = enp2611_get_stats;
216                 pm3386_init_port(i);
217                 pm3386_get_mac(i, nds[i]->dev_addr);
218         }
219
220         ixp2400_msf_init(&enp2611_msf_parameters);
221
222         if (ixpdev_init(ports, nds, enp2611_set_port_admin_status)) {
223                 for (i = 0; i < ports; i++)
224                         if (nds[i])
225                                 free_netdev(nds[i]);
226                 return -EINVAL;
227         }
228
229         init_timer(&link_check_timer);
230         link_check_timer.function = enp2611_check_link_status;
231         link_check_timer.expires = jiffies;
232         add_timer(&link_check_timer);
233
234         return 0;
235 }
236
237 static void __exit enp2611_cleanup_module(void)
238 {
239         int i;
240
241         del_timer_sync(&link_check_timer);
242
243         ixpdev_deinit();
244         for (i = 0; i < 3; i++)
245                 free_netdev(nds[i]);
246 }
247
248 module_init(enp2611_init_module);
249 module_exit(enp2611_cleanup_module);
250 MODULE_LICENSE("GPL");