]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
f90fdc3c | 2 | * Copyright (C) 2001,2002,2003,2004 Broadcom Corporation |
f5279ffd | 3 | * Copyright (c) 2006, 2007 Maciej W. Rozycki |
1da177e4 LT |
4 | * |
5 | * This program is free software; you can redistribute it and/or | |
6 | * modify it under the terms of the GNU General Public License | |
7 | * as published by the Free Software Foundation; either version 2 | |
8 | * of the License, or (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
74b0247f | 14 | * |
1da177e4 LT |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 | * | |
19 | * | |
20 | * This driver is designed for the Broadcom SiByte SOC built-in | |
21 | * Ethernet controllers. Written by Mitch Lichtenberg at Broadcom Corp. | |
f5279ffd MR |
22 | * |
23 | * Updated to the driver model and the PHY abstraction layer | |
24 | * by Maciej W. Rozycki. | |
1da177e4 | 25 | */ |
f5279ffd MR |
26 | |
27 | #include <linux/bug.h> | |
1da177e4 LT |
28 | #include <linux/module.h> |
29 | #include <linux/kernel.h> | |
30 | #include <linux/string.h> | |
31 | #include <linux/timer.h> | |
32 | #include <linux/errno.h> | |
33 | #include <linux/ioport.h> | |
34 | #include <linux/slab.h> | |
35 | #include <linux/interrupt.h> | |
36 | #include <linux/netdevice.h> | |
37 | #include <linux/etherdevice.h> | |
38 | #include <linux/skbuff.h> | |
39 | #include <linux/init.h> | |
1da177e4 | 40 | #include <linux/bitops.h> |
f5279ffd MR |
41 | #include <linux/err.h> |
42 | #include <linux/ethtool.h> | |
43 | #include <linux/mii.h> | |
44 | #include <linux/phy.h> | |
45 | #include <linux/platform_device.h> | |
46 | ||
1da177e4 | 47 | #include <asm/cache.h> |
f5279ffd MR |
48 | #include <asm/io.h> |
49 | #include <asm/processor.h> /* Processor type for cache alignment. */ | |
1da177e4 LT |
50 | |
51 | /* This is only here until the firmware is ready. In that case, | |
52 | the firmware leaves the ethernet address in the register for us. */ | |
53 | #ifdef CONFIG_SIBYTE_STANDALONE | |
54 | #define SBMAC_ETH0_HWADDR "40:00:00:00:01:00" | |
55 | #define SBMAC_ETH1_HWADDR "40:00:00:00:01:01" | |
56 | #define SBMAC_ETH2_HWADDR "40:00:00:00:01:02" | |
f90fdc3c | 57 | #define SBMAC_ETH3_HWADDR "40:00:00:00:01:03" |
1da177e4 LT |
58 | #endif |
59 | ||
60 | ||
61 | /* These identify the driver base version and may not be removed. */ | |
62 | #if 0 | |
f5279ffd | 63 | static char version1[] __initdata = |
1da177e4 LT |
64 | "sb1250-mac.c:1.00 1/11/2001 Written by Mitch Lichtenberg\n"; |
65 | #endif | |
66 | ||
67 | ||
68 | /* Operational parameters that usually are not changed. */ | |
69 | ||
70 | #define CONFIG_SBMAC_COALESCE | |
71 | ||
1da177e4 LT |
72 | /* Time in jiffies before concluding the transmitter is hung. */ |
73 | #define TX_TIMEOUT (2*HZ) | |
74 | ||
75 | ||
76 | MODULE_AUTHOR("Mitch Lichtenberg (Broadcom Corp.)"); | |
77 | MODULE_DESCRIPTION("Broadcom SiByte SOC GB Ethernet driver"); | |
78 | ||
79 | /* A few user-configurable values which may be modified when a driver | |
80 | module is loaded. */ | |
81 | ||
82 | /* 1 normal messages, 0 quiet .. 7 verbose. */ | |
83 | static int debug = 1; | |
84 | module_param(debug, int, S_IRUGO); | |
85 | MODULE_PARM_DESC(debug, "Debug messages"); | |
86 | ||
1da177e4 | 87 | #ifdef CONFIG_SBMAC_COALESCE |
693aa947 MM |
88 | static int int_pktcnt_tx = 255; |
89 | module_param(int_pktcnt_tx, int, S_IRUGO); | |
90 | MODULE_PARM_DESC(int_pktcnt_tx, "TX packet count"); | |
1da177e4 | 91 | |
693aa947 MM |
92 | static int int_timeout_tx = 255; |
93 | module_param(int_timeout_tx, int, S_IRUGO); | |
94 | MODULE_PARM_DESC(int_timeout_tx, "TX timeout value"); | |
95 | ||
96 | static int int_pktcnt_rx = 64; | |
97 | module_param(int_pktcnt_rx, int, S_IRUGO); | |
98 | MODULE_PARM_DESC(int_pktcnt_rx, "RX packet count"); | |
99 | ||
100 | static int int_timeout_rx = 64; | |
101 | module_param(int_timeout_rx, int, S_IRUGO); | |
102 | MODULE_PARM_DESC(int_timeout_rx, "RX timeout value"); | |
1da177e4 LT |
103 | #endif |
104 | ||
f5279ffd | 105 | #include <asm/sibyte/board.h> |
1da177e4 | 106 | #include <asm/sibyte/sb1250.h> |
f90fdc3c RB |
107 | #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80) |
108 | #include <asm/sibyte/bcm1480_regs.h> | |
109 | #include <asm/sibyte/bcm1480_int.h> | |
693aa947 | 110 | #define R_MAC_DMA_OODPKTLOST_RX R_MAC_DMA_OODPKTLOST |
f90fdc3c | 111 | #elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X) |
1da177e4 | 112 | #include <asm/sibyte/sb1250_regs.h> |
1da177e4 | 113 | #include <asm/sibyte/sb1250_int.h> |
f90fdc3c RB |
114 | #else |
115 | #error invalid SiByte MAC configuation | |
116 | #endif | |
1da177e4 | 117 | #include <asm/sibyte/sb1250_scd.h> |
f90fdc3c RB |
118 | #include <asm/sibyte/sb1250_mac.h> |
119 | #include <asm/sibyte/sb1250_dma.h> | |
1da177e4 | 120 | |
f90fdc3c RB |
121 | #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80) |
122 | #define UNIT_INT(n) (K_BCM1480_INT_MAC_0 + ((n) * 2)) | |
123 | #elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X) | |
124 | #define UNIT_INT(n) (K_INT_MAC_0 + (n)) | |
125 | #else | |
126 | #error invalid SiByte MAC configuation | |
127 | #endif | |
1da177e4 | 128 | |
f5279ffd MR |
129 | #ifdef K_INT_PHY |
130 | #define SBMAC_PHY_INT K_INT_PHY | |
131 | #else | |
132 | #define SBMAC_PHY_INT PHY_POLL | |
133 | #endif | |
134 | ||
1da177e4 LT |
135 | /********************************************************************** |
136 | * Simple types | |
137 | ********************************************************************* */ | |
138 | ||
f5279ffd MR |
139 | enum sbmac_speed { |
140 | sbmac_speed_none = 0, | |
141 | sbmac_speed_10 = SPEED_10, | |
142 | sbmac_speed_100 = SPEED_100, | |
143 | sbmac_speed_1000 = SPEED_1000, | |
144 | }; | |
1da177e4 | 145 | |
f5279ffd MR |
146 | enum sbmac_duplex { |
147 | sbmac_duplex_none = -1, | |
148 | sbmac_duplex_half = DUPLEX_HALF, | |
149 | sbmac_duplex_full = DUPLEX_FULL, | |
150 | }; | |
1da177e4 | 151 | |
f5279ffd MR |
152 | enum sbmac_fc { |
153 | sbmac_fc_none, | |
154 | sbmac_fc_disabled, | |
155 | sbmac_fc_frame, | |
156 | sbmac_fc_collision, | |
157 | sbmac_fc_carrier, | |
158 | }; | |
1da177e4 | 159 | |
f5279ffd MR |
160 | enum sbmac_state { |
161 | sbmac_state_uninit, | |
162 | sbmac_state_off, | |
163 | sbmac_state_on, | |
164 | sbmac_state_broken, | |
165 | }; | |
1da177e4 LT |
166 | |
167 | ||
168 | /********************************************************************** | |
169 | * Macros | |
170 | ********************************************************************* */ | |
171 | ||
172 | ||
173 | #define SBDMA_NEXTBUF(d,f) ((((d)->f+1) == (d)->sbdma_dscrtable_end) ? \ | |
174 | (d)->sbdma_dscrtable : (d)->f+1) | |
175 | ||
176 | ||
177 | #define NUMCACHEBLKS(x) (((x)+SMP_CACHE_BYTES-1)/SMP_CACHE_BYTES) | |
178 | ||
693aa947 MM |
179 | #define SBMAC_MAX_TXDESCR 256 |
180 | #define SBMAC_MAX_RXDESCR 256 | |
1da177e4 LT |
181 | |
182 | #define ETHER_ALIGN 2 | |
183 | #define ETHER_ADDR_LEN 6 | |
74b0247f RB |
184 | #define ENET_PACKET_SIZE 1518 |
185 | /*#define ENET_PACKET_SIZE 9216 */ | |
1da177e4 LT |
186 | |
187 | /********************************************************************** | |
188 | * DMA Descriptor structure | |
189 | ********************************************************************* */ | |
190 | ||
73d73969 | 191 | struct sbdmadscr { |
1da177e4 LT |
192 | uint64_t dscr_a; |
193 | uint64_t dscr_b; | |
73d73969 | 194 | }; |
1da177e4 LT |
195 | |
196 | /********************************************************************** | |
197 | * DMA Controller structure | |
198 | ********************************************************************* */ | |
199 | ||
73d73969 | 200 | struct sbmacdma { |
74b0247f RB |
201 | |
202 | /* | |
1da177e4 LT |
203 | * This stuff is used to identify the channel and the registers |
204 | * associated with it. | |
205 | */ | |
73d73969 MR |
206 | struct sbmac_softc *sbdma_eth; /* back pointer to associated |
207 | MAC */ | |
208 | int sbdma_channel; /* channel number */ | |
209 | int sbdma_txdir; /* direction (1=transmit) */ | |
210 | int sbdma_maxdescr; /* total # of descriptors | |
211 | in ring */ | |
1da177e4 | 212 | #ifdef CONFIG_SBMAC_COALESCE |
73d73969 MR |
213 | int sbdma_int_pktcnt; |
214 | /* # descriptors rx/tx | |
215 | before interrupt */ | |
216 | int sbdma_int_timeout; | |
217 | /* # usec rx/tx interrupt */ | |
1da177e4 | 218 | #endif |
73d73969 MR |
219 | void __iomem *sbdma_config0; /* DMA config register 0 */ |
220 | void __iomem *sbdma_config1; /* DMA config register 1 */ | |
221 | void __iomem *sbdma_dscrbase; | |
222 | /* descriptor base address */ | |
223 | void __iomem *sbdma_dscrcnt; /* descriptor count register */ | |
224 | void __iomem *sbdma_curdscr; /* current descriptor | |
225 | address */ | |
226 | void __iomem *sbdma_oodpktlost; | |
227 | /* pkt drop (rx only) */ | |
74b0247f | 228 | |
1da177e4 LT |
229 | /* |
230 | * This stuff is for maintenance of the ring | |
231 | */ | |
73d73969 MR |
232 | void *sbdma_dscrtable_unaligned; |
233 | struct sbdmadscr *sbdma_dscrtable; | |
234 | /* base of descriptor table */ | |
235 | struct sbdmadscr *sbdma_dscrtable_end; | |
236 | /* end of descriptor table */ | |
237 | struct sk_buff **sbdma_ctxtable; | |
238 | /* context table, one | |
239 | per descr */ | |
240 | dma_addr_t sbdma_dscrtable_phys; | |
241 | /* and also the phys addr */ | |
242 | struct sbdmadscr *sbdma_addptr; /* next dscr for sw to add */ | |
243 | struct sbdmadscr *sbdma_remptr; /* next dscr for sw | |
244 | to remove */ | |
245 | }; | |
1da177e4 LT |
246 | |
247 | ||
248 | /********************************************************************** | |
249 | * Ethernet softc structure | |
250 | ********************************************************************* */ | |
251 | ||
252 | struct sbmac_softc { | |
74b0247f | 253 | |
1da177e4 LT |
254 | /* |
255 | * Linux-specific things | |
256 | */ | |
73d73969 MR |
257 | struct net_device *sbm_dev; /* pointer to linux device */ |
258 | struct napi_struct napi; | |
f5279ffd MR |
259 | struct phy_device *phy_dev; /* the associated PHY device */ |
260 | struct mii_bus mii_bus; /* the MII bus */ | |
261 | int phy_irq[PHY_MAX_ADDR]; | |
73d73969 | 262 | spinlock_t sbm_lock; /* spin lock */ |
73d73969 | 263 | int sbm_devflags; /* current device flags */ |
74b0247f | 264 | |
73d73969 | 265 | int sbm_buffersize; |
74b0247f | 266 | |
1da177e4 LT |
267 | /* |
268 | * Controller-specific things | |
269 | */ | |
73d73969 MR |
270 | void __iomem *sbm_base; /* MAC's base address */ |
271 | enum sbmac_state sbm_state; /* current state */ | |
74b0247f | 272 | |
73d73969 MR |
273 | void __iomem *sbm_macenable; /* MAC Enable Register */ |
274 | void __iomem *sbm_maccfg; /* MAC Config Register */ | |
275 | void __iomem *sbm_fifocfg; /* FIFO Config Register */ | |
276 | void __iomem *sbm_framecfg; /* Frame Config Register */ | |
277 | void __iomem *sbm_rxfilter; /* Receive Filter Register */ | |
278 | void __iomem *sbm_isr; /* Interrupt Status Register */ | |
279 | void __iomem *sbm_imr; /* Interrupt Mask Register */ | |
280 | void __iomem *sbm_mdio; /* MDIO Register */ | |
74b0247f | 281 | |
73d73969 MR |
282 | enum sbmac_speed sbm_speed; /* current speed */ |
283 | enum sbmac_duplex sbm_duplex; /* current duplex */ | |
284 | enum sbmac_fc sbm_fc; /* cur. flow control setting */ | |
f5279ffd MR |
285 | int sbm_pause; /* current pause setting */ |
286 | int sbm_link; /* current link state */ | |
74b0247f | 287 | |
73d73969 | 288 | unsigned char sbm_hwaddr[ETHER_ADDR_LEN]; |
74b0247f | 289 | |
73d73969 MR |
290 | struct sbmacdma sbm_txdma; /* only channel 0 for now */ |
291 | struct sbmacdma sbm_rxdma; | |
292 | int rx_hw_checksum; | |
293 | int sbe_idx; | |
1da177e4 LT |
294 | }; |
295 | ||
296 | ||
297 | /********************************************************************** | |
298 | * Externs | |
299 | ********************************************************************* */ | |
300 | ||
301 | /********************************************************************** | |
302 | * Prototypes | |
303 | ********************************************************************* */ | |
304 | ||
73d73969 MR |
305 | static void sbdma_initctx(struct sbmacdma *d, struct sbmac_softc *s, int chan, |
306 | int txrx, int maxdescr); | |
307 | static void sbdma_channel_start(struct sbmacdma *d, int rxtx); | |
308 | static int sbdma_add_rcvbuffer(struct sbmacdma *d, struct sk_buff *m); | |
309 | static int sbdma_add_txbuffer(struct sbmacdma *d, struct sk_buff *m); | |
310 | static void sbdma_emptyring(struct sbmacdma *d); | |
311 | static void sbdma_fillring(struct sbmacdma *d); | |
312 | static int sbdma_rx_process(struct sbmac_softc *sc, struct sbmacdma *d, | |
313 | int work_to_do, int poll); | |
314 | static void sbdma_tx_process(struct sbmac_softc *sc, struct sbmacdma *d, | |
315 | int poll); | |
1da177e4 LT |
316 | static int sbmac_initctx(struct sbmac_softc *s); |
317 | static void sbmac_channel_start(struct sbmac_softc *s); | |
318 | static void sbmac_channel_stop(struct sbmac_softc *s); | |
73d73969 MR |
319 | static enum sbmac_state sbmac_set_channel_state(struct sbmac_softc *, |
320 | enum sbmac_state); | |
321 | static void sbmac_promiscuous_mode(struct sbmac_softc *sc, int onoff); | |
1da177e4 | 322 | static uint64_t sbmac_addr2reg(unsigned char *ptr); |
73d73969 | 323 | static irqreturn_t sbmac_intr(int irq, void *dev_instance); |
1da177e4 LT |
324 | static int sbmac_start_tx(struct sk_buff *skb, struct net_device *dev); |
325 | static void sbmac_setmulti(struct sbmac_softc *sc); | |
f5279ffd | 326 | static int sbmac_init(struct platform_device *pldev, long long base); |
73d73969 MR |
327 | static int sbmac_set_speed(struct sbmac_softc *s, enum sbmac_speed speed); |
328 | static int sbmac_set_duplex(struct sbmac_softc *s, enum sbmac_duplex duplex, | |
329 | enum sbmac_fc fc); | |
1da177e4 LT |
330 | |
331 | static int sbmac_open(struct net_device *dev); | |
1da177e4 | 332 | static void sbmac_tx_timeout (struct net_device *dev); |
1da177e4 LT |
333 | static void sbmac_set_rx_mode(struct net_device *dev); |
334 | static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); | |
335 | static int sbmac_close(struct net_device *dev); | |
bea3348e | 336 | static int sbmac_poll(struct napi_struct *napi, int budget); |
693aa947 | 337 | |
f5279ffd | 338 | static void sbmac_mii_poll(struct net_device *dev); |
59b81827 | 339 | static int sbmac_mii_probe(struct net_device *dev); |
1da177e4 | 340 | |
f5279ffd MR |
341 | static void sbmac_mii_sync(void __iomem *sbm_mdio); |
342 | static void sbmac_mii_senddata(void __iomem *sbm_mdio, unsigned int data, | |
73d73969 | 343 | int bitcnt); |
f5279ffd MR |
344 | static int sbmac_mii_read(struct mii_bus *bus, int phyaddr, int regidx); |
345 | static int sbmac_mii_write(struct mii_bus *bus, int phyaddr, int regidx, | |
346 | u16 val); | |
1da177e4 LT |
347 | |
348 | ||
349 | /********************************************************************** | |
350 | * Globals | |
351 | ********************************************************************* */ | |
352 | ||
f5279ffd MR |
353 | static char sbmac_string[] = "sb1250-mac"; |
354 | static char sbmac_pretty[] = "SB1250 MAC"; | |
355 | ||
356 | static char sbmac_mdio_string[] = "sb1250-mac-mdio"; | |
1da177e4 LT |
357 | |
358 | ||
359 | /********************************************************************** | |
360 | * MDIO constants | |
361 | ********************************************************************* */ | |
362 | ||
363 | #define MII_COMMAND_START 0x01 | |
364 | #define MII_COMMAND_READ 0x02 | |
365 | #define MII_COMMAND_WRITE 0x01 | |
366 | #define MII_COMMAND_ACK 0x02 | |
367 | ||
1da177e4 LT |
368 | #define M_MAC_MDIO_DIR_OUTPUT 0 /* for clarity */ |
369 | ||
370 | #define ENABLE 1 | |
371 | #define DISABLE 0 | |
372 | ||
373 | /********************************************************************** | |
f5279ffd | 374 | * SBMAC_MII_SYNC(sbm_mdio) |
74b0247f | 375 | * |
1da177e4 LT |
376 | * Synchronize with the MII - send a pattern of bits to the MII |
377 | * that will guarantee that it is ready to accept a command. | |
74b0247f RB |
378 | * |
379 | * Input parameters: | |
f5279ffd | 380 | * sbm_mdio - address of the MAC's MDIO register |
74b0247f | 381 | * |
1da177e4 LT |
382 | * Return value: |
383 | * nothing | |
384 | ********************************************************************* */ | |
385 | ||
f5279ffd | 386 | static void sbmac_mii_sync(void __iomem *sbm_mdio) |
1da177e4 LT |
387 | { |
388 | int cnt; | |
389 | uint64_t bits; | |
390 | int mac_mdio_genc; | |
391 | ||
f5279ffd | 392 | mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC; |
74b0247f | 393 | |
1da177e4 | 394 | bits = M_MAC_MDIO_DIR_OUTPUT | M_MAC_MDIO_OUT; |
74b0247f | 395 | |
f5279ffd | 396 | __raw_writeq(bits | mac_mdio_genc, sbm_mdio); |
74b0247f | 397 | |
1da177e4 | 398 | for (cnt = 0; cnt < 32; cnt++) { |
f5279ffd MR |
399 | __raw_writeq(bits | M_MAC_MDC | mac_mdio_genc, sbm_mdio); |
400 | __raw_writeq(bits | mac_mdio_genc, sbm_mdio); | |
1da177e4 LT |
401 | } |
402 | } | |
403 | ||
404 | /********************************************************************** | |
f5279ffd | 405 | * SBMAC_MII_SENDDATA(sbm_mdio, data, bitcnt) |
74b0247f | 406 | * |
1da177e4 LT |
407 | * Send some bits to the MII. The bits to be sent are right- |
408 | * justified in the 'data' parameter. | |
74b0247f RB |
409 | * |
410 | * Input parameters: | |
f5279ffd MR |
411 | * sbm_mdio - address of the MAC's MDIO register |
412 | * data - data to send | |
413 | * bitcnt - number of bits to send | |
1da177e4 LT |
414 | ********************************************************************* */ |
415 | ||
f5279ffd MR |
416 | static void sbmac_mii_senddata(void __iomem *sbm_mdio, unsigned int data, |
417 | int bitcnt) | |
1da177e4 LT |
418 | { |
419 | int i; | |
420 | uint64_t bits; | |
421 | unsigned int curmask; | |
422 | int mac_mdio_genc; | |
423 | ||
f5279ffd | 424 | mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC; |
74b0247f | 425 | |
1da177e4 | 426 | bits = M_MAC_MDIO_DIR_OUTPUT; |
f5279ffd | 427 | __raw_writeq(bits | mac_mdio_genc, sbm_mdio); |
74b0247f | 428 | |
1da177e4 | 429 | curmask = 1 << (bitcnt - 1); |
74b0247f | 430 | |
1da177e4 LT |
431 | for (i = 0; i < bitcnt; i++) { |
432 | if (data & curmask) | |
433 | bits |= M_MAC_MDIO_OUT; | |
434 | else bits &= ~M_MAC_MDIO_OUT; | |
f5279ffd MR |
435 | __raw_writeq(bits | mac_mdio_genc, sbm_mdio); |
436 | __raw_writeq(bits | M_MAC_MDC | mac_mdio_genc, sbm_mdio); | |
437 | __raw_writeq(bits | mac_mdio_genc, sbm_mdio); | |
1da177e4 LT |
438 | curmask >>= 1; |
439 | } | |
440 | } | |
441 | ||
442 | ||
443 | ||
444 | /********************************************************************** | |
f5279ffd | 445 | * SBMAC_MII_READ(bus, phyaddr, regidx) |
1da177e4 | 446 | * Read a PHY register. |
74b0247f RB |
447 | * |
448 | * Input parameters: | |
f5279ffd | 449 | * bus - MDIO bus handle |
1da177e4 | 450 | * phyaddr - PHY's address |
f5279ffd | 451 | * regnum - index of register to read |
74b0247f | 452 | * |
1da177e4 | 453 | * Return value: |
f5279ffd | 454 | * value read, or 0xffff if an error occurred. |
1da177e4 LT |
455 | ********************************************************************* */ |
456 | ||
f5279ffd | 457 | static int sbmac_mii_read(struct mii_bus *bus, int phyaddr, int regidx) |
1da177e4 | 458 | { |
f5279ffd MR |
459 | struct sbmac_softc *sc = (struct sbmac_softc *)bus->priv; |
460 | void __iomem *sbm_mdio = sc->sbm_mdio; | |
1da177e4 LT |
461 | int idx; |
462 | int error; | |
463 | int regval; | |
464 | int mac_mdio_genc; | |
465 | ||
466 | /* | |
467 | * Synchronize ourselves so that the PHY knows the next | |
468 | * thing coming down is a command | |
469 | */ | |
f5279ffd | 470 | sbmac_mii_sync(sbm_mdio); |
74b0247f | 471 | |
1da177e4 LT |
472 | /* |
473 | * Send the data to the PHY. The sequence is | |
474 | * a "start" command (2 bits) | |
475 | * a "read" command (2 bits) | |
476 | * the PHY addr (5 bits) | |
477 | * the register index (5 bits) | |
478 | */ | |
f5279ffd MR |
479 | sbmac_mii_senddata(sbm_mdio, MII_COMMAND_START, 2); |
480 | sbmac_mii_senddata(sbm_mdio, MII_COMMAND_READ, 2); | |
481 | sbmac_mii_senddata(sbm_mdio, phyaddr, 5); | |
482 | sbmac_mii_senddata(sbm_mdio, regidx, 5); | |
74b0247f | 483 | |
f5279ffd | 484 | mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC; |
74b0247f RB |
485 | |
486 | /* | |
1da177e4 LT |
487 | * Switch the port around without a clock transition. |
488 | */ | |
f5279ffd | 489 | __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio); |
74b0247f | 490 | |
1da177e4 LT |
491 | /* |
492 | * Send out a clock pulse to signal we want the status | |
493 | */ | |
f5279ffd MR |
494 | __raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc, |
495 | sbm_mdio); | |
496 | __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio); | |
74b0247f RB |
497 | |
498 | /* | |
1da177e4 LT |
499 | * If an error occurred, the PHY will signal '1' back |
500 | */ | |
f5279ffd | 501 | error = __raw_readq(sbm_mdio) & M_MAC_MDIO_IN; |
74b0247f RB |
502 | |
503 | /* | |
1da177e4 LT |
504 | * Issue an 'idle' clock pulse, but keep the direction |
505 | * the same. | |
506 | */ | |
f5279ffd MR |
507 | __raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc, |
508 | sbm_mdio); | |
509 | __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio); | |
74b0247f | 510 | |
1da177e4 | 511 | regval = 0; |
74b0247f | 512 | |
1da177e4 LT |
513 | for (idx = 0; idx < 16; idx++) { |
514 | regval <<= 1; | |
74b0247f | 515 | |
1da177e4 | 516 | if (error == 0) { |
f5279ffd | 517 | if (__raw_readq(sbm_mdio) & M_MAC_MDIO_IN) |
1da177e4 LT |
518 | regval |= 1; |
519 | } | |
74b0247f | 520 | |
f5279ffd MR |
521 | __raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc, |
522 | sbm_mdio); | |
523 | __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio); | |
1da177e4 | 524 | } |
74b0247f | 525 | |
1da177e4 | 526 | /* Switch back to output */ |
f5279ffd | 527 | __raw_writeq(M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc, sbm_mdio); |
74b0247f | 528 | |
1da177e4 LT |
529 | if (error == 0) |
530 | return regval; | |
f5279ffd | 531 | return 0xffff; |
1da177e4 LT |
532 | } |
533 | ||
534 | ||
535 | /********************************************************************** | |
f5279ffd | 536 | * SBMAC_MII_WRITE(bus, phyaddr, regidx, regval) |
74b0247f | 537 | * |
1da177e4 | 538 | * Write a value to a PHY register. |
74b0247f RB |
539 | * |
540 | * Input parameters: | |
f5279ffd | 541 | * bus - MDIO bus handle |
1da177e4 | 542 | * phyaddr - PHY to use |
f5279ffd MR |
543 | * regidx - register within the PHY |
544 | * regval - data to write to register | |
74b0247f | 545 | * |
1da177e4 | 546 | * Return value: |
f5279ffd | 547 | * 0 for success |
1da177e4 LT |
548 | ********************************************************************* */ |
549 | ||
f5279ffd MR |
550 | static int sbmac_mii_write(struct mii_bus *bus, int phyaddr, int regidx, |
551 | u16 regval) | |
1da177e4 | 552 | { |
f5279ffd MR |
553 | struct sbmac_softc *sc = (struct sbmac_softc *)bus->priv; |
554 | void __iomem *sbm_mdio = sc->sbm_mdio; | |
1da177e4 LT |
555 | int mac_mdio_genc; |
556 | ||
f5279ffd | 557 | sbmac_mii_sync(sbm_mdio); |
74b0247f | 558 | |
f5279ffd MR |
559 | sbmac_mii_senddata(sbm_mdio, MII_COMMAND_START, 2); |
560 | sbmac_mii_senddata(sbm_mdio, MII_COMMAND_WRITE, 2); | |
561 | sbmac_mii_senddata(sbm_mdio, phyaddr, 5); | |
562 | sbmac_mii_senddata(sbm_mdio, regidx, 5); | |
563 | sbmac_mii_senddata(sbm_mdio, MII_COMMAND_ACK, 2); | |
564 | sbmac_mii_senddata(sbm_mdio, regval, 16); | |
1da177e4 | 565 | |
f5279ffd | 566 | mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC; |
1da177e4 | 567 | |
f5279ffd MR |
568 | __raw_writeq(M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc, sbm_mdio); |
569 | ||
570 | return 0; | |
1da177e4 LT |
571 | } |
572 | ||
573 | ||
574 | ||
575 | /********************************************************************** | |
576 | * SBDMA_INITCTX(d,s,chan,txrx,maxdescr) | |
74b0247f | 577 | * |
1da177e4 LT |
578 | * Initialize a DMA channel context. Since there are potentially |
579 | * eight DMA channels per MAC, it's nice to do this in a standard | |
74b0247f RB |
580 | * way. |
581 | * | |
582 | * Input parameters: | |
73d73969 MR |
583 | * d - struct sbmacdma (DMA channel context) |
584 | * s - struct sbmac_softc (pointer to a MAC) | |
1da177e4 LT |
585 | * chan - channel number (0..1 right now) |
586 | * txrx - Identifies DMA_TX or DMA_RX for channel direction | |
587 | * maxdescr - number of descriptors | |
74b0247f | 588 | * |
1da177e4 LT |
589 | * Return value: |
590 | * nothing | |
591 | ********************************************************************* */ | |
592 | ||
73d73969 MR |
593 | static void sbdma_initctx(struct sbmacdma *d, struct sbmac_softc *s, int chan, |
594 | int txrx, int maxdescr) | |
1da177e4 | 595 | { |
693aa947 MM |
596 | #ifdef CONFIG_SBMAC_COALESCE |
597 | int int_pktcnt, int_timeout; | |
598 | #endif | |
599 | ||
74b0247f RB |
600 | /* |
601 | * Save away interesting stuff in the structure | |
1da177e4 | 602 | */ |
74b0247f | 603 | |
1da177e4 LT |
604 | d->sbdma_eth = s; |
605 | d->sbdma_channel = chan; | |
606 | d->sbdma_txdir = txrx; | |
74b0247f | 607 | |
1da177e4 LT |
608 | #if 0 |
609 | /* RMON clearing */ | |
610 | s->sbe_idx =(s->sbm_base - A_MAC_BASE_0)/MAC_SPACING; | |
611 | #endif | |
612 | ||
f5279ffd MR |
613 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_BYTES); |
614 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_COLLISIONS); | |
615 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_LATE_COL); | |
616 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_EX_COL); | |
617 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_FCS_ERROR); | |
618 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_ABORT); | |
619 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_BAD); | |
620 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_GOOD); | |
621 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_RUNT); | |
622 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_OVERSIZE); | |
623 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_BYTES); | |
624 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_MCAST); | |
625 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_BCAST); | |
626 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_BAD); | |
627 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_GOOD); | |
628 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_RUNT); | |
629 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_OVERSIZE); | |
630 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_FCS_ERROR); | |
631 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_LENGTH_ERROR); | |
632 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_CODE_ERROR); | |
633 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_ALIGN_ERROR); | |
1da177e4 | 634 | |
74b0247f RB |
635 | /* |
636 | * initialize register pointers | |
1da177e4 | 637 | */ |
74b0247f RB |
638 | |
639 | d->sbdma_config0 = | |
1da177e4 | 640 | s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG0); |
74b0247f | 641 | d->sbdma_config1 = |
1da177e4 | 642 | s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG1); |
74b0247f | 643 | d->sbdma_dscrbase = |
1da177e4 | 644 | s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_BASE); |
74b0247f | 645 | d->sbdma_dscrcnt = |
1da177e4 | 646 | s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_CNT); |
74b0247f | 647 | d->sbdma_curdscr = |
1da177e4 | 648 | s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CUR_DSCRADDR); |
693aa947 MM |
649 | if (d->sbdma_txdir) |
650 | d->sbdma_oodpktlost = NULL; | |
651 | else | |
652 | d->sbdma_oodpktlost = | |
653 | s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_OODPKTLOST_RX); | |
74b0247f | 654 | |
1da177e4 LT |
655 | /* |
656 | * Allocate memory for the ring | |
657 | */ | |
74b0247f | 658 | |
1da177e4 | 659 | d->sbdma_maxdescr = maxdescr; |
74b0247f | 660 | |
73d73969 MR |
661 | d->sbdma_dscrtable_unaligned = kcalloc(d->sbdma_maxdescr + 1, |
662 | sizeof(*d->sbdma_dscrtable), | |
663 | GFP_KERNEL); | |
04115def RB |
664 | |
665 | /* | |
666 | * The descriptor table must be aligned to at least 16 bytes or the | |
667 | * MAC will corrupt it. | |
668 | */ | |
73d73969 MR |
669 | d->sbdma_dscrtable = (struct sbdmadscr *) |
670 | ALIGN((unsigned long)d->sbdma_dscrtable_unaligned, | |
671 | sizeof(*d->sbdma_dscrtable)); | |
74b0247f | 672 | |
1da177e4 | 673 | d->sbdma_dscrtable_end = d->sbdma_dscrtable + d->sbdma_maxdescr; |
74b0247f | 674 | |
1da177e4 | 675 | d->sbdma_dscrtable_phys = virt_to_phys(d->sbdma_dscrtable); |
74b0247f | 676 | |
1da177e4 LT |
677 | /* |
678 | * And context table | |
679 | */ | |
74b0247f | 680 | |
c477f334 | 681 | d->sbdma_ctxtable = kcalloc(d->sbdma_maxdescr, |
73d73969 | 682 | sizeof(*d->sbdma_ctxtable), GFP_KERNEL); |
74b0247f | 683 | |
1da177e4 LT |
684 | #ifdef CONFIG_SBMAC_COALESCE |
685 | /* | |
686 | * Setup Rx/Tx DMA coalescing defaults | |
687 | */ | |
688 | ||
693aa947 | 689 | int_pktcnt = (txrx == DMA_TX) ? int_pktcnt_tx : int_pktcnt_rx; |
1da177e4 LT |
690 | if ( int_pktcnt ) { |
691 | d->sbdma_int_pktcnt = int_pktcnt; | |
692 | } else { | |
693 | d->sbdma_int_pktcnt = 1; | |
694 | } | |
74b0247f | 695 | |
693aa947 | 696 | int_timeout = (txrx == DMA_TX) ? int_timeout_tx : int_timeout_rx; |
1da177e4 LT |
697 | if ( int_timeout ) { |
698 | d->sbdma_int_timeout = int_timeout; | |
699 | } else { | |
700 | d->sbdma_int_timeout = 0; | |
701 | } | |
702 | #endif | |
703 | ||
704 | } | |
705 | ||
706 | /********************************************************************** | |
707 | * SBDMA_CHANNEL_START(d) | |
74b0247f | 708 | * |
1da177e4 | 709 | * Initialize the hardware registers for a DMA channel. |
74b0247f RB |
710 | * |
711 | * Input parameters: | |
1da177e4 LT |
712 | * d - DMA channel to init (context must be previously init'd |
713 | * rxtx - DMA_RX or DMA_TX depending on what type of channel | |
74b0247f | 714 | * |
1da177e4 LT |
715 | * Return value: |
716 | * nothing | |
717 | ********************************************************************* */ | |
718 | ||
73d73969 | 719 | static void sbdma_channel_start(struct sbmacdma *d, int rxtx) |
1da177e4 LT |
720 | { |
721 | /* | |
722 | * Turn on the DMA channel | |
723 | */ | |
74b0247f | 724 | |
1da177e4 | 725 | #ifdef CONFIG_SBMAC_COALESCE |
2039973a RB |
726 | __raw_writeq(V_DMA_INT_TIMEOUT(d->sbdma_int_timeout) | |
727 | 0, d->sbdma_config1); | |
728 | __raw_writeq(M_DMA_EOP_INT_EN | | |
1da177e4 LT |
729 | V_DMA_RINGSZ(d->sbdma_maxdescr) | |
730 | V_DMA_INT_PKTCNT(d->sbdma_int_pktcnt) | | |
2039973a | 731 | 0, d->sbdma_config0); |
1da177e4 | 732 | #else |
2039973a RB |
733 | __raw_writeq(0, d->sbdma_config1); |
734 | __raw_writeq(V_DMA_RINGSZ(d->sbdma_maxdescr) | | |
735 | 0, d->sbdma_config0); | |
1da177e4 LT |
736 | #endif |
737 | ||
2039973a | 738 | __raw_writeq(d->sbdma_dscrtable_phys, d->sbdma_dscrbase); |
1da177e4 LT |
739 | |
740 | /* | |
741 | * Initialize ring pointers | |
742 | */ | |
743 | ||
744 | d->sbdma_addptr = d->sbdma_dscrtable; | |
745 | d->sbdma_remptr = d->sbdma_dscrtable; | |
746 | } | |
747 | ||
748 | /********************************************************************** | |
749 | * SBDMA_CHANNEL_STOP(d) | |
74b0247f | 750 | * |
1da177e4 | 751 | * Initialize the hardware registers for a DMA channel. |
74b0247f RB |
752 | * |
753 | * Input parameters: | |
1da177e4 | 754 | * d - DMA channel to init (context must be previously init'd |
74b0247f | 755 | * |
1da177e4 LT |
756 | * Return value: |
757 | * nothing | |
758 | ********************************************************************* */ | |
759 | ||
73d73969 | 760 | static void sbdma_channel_stop(struct sbmacdma *d) |
1da177e4 LT |
761 | { |
762 | /* | |
763 | * Turn off the DMA channel | |
764 | */ | |
74b0247f | 765 | |
2039973a | 766 | __raw_writeq(0, d->sbdma_config1); |
74b0247f | 767 | |
2039973a | 768 | __raw_writeq(0, d->sbdma_dscrbase); |
74b0247f | 769 | |
2039973a | 770 | __raw_writeq(0, d->sbdma_config0); |
74b0247f | 771 | |
1da177e4 LT |
772 | /* |
773 | * Zero ring pointers | |
774 | */ | |
74b0247f | 775 | |
2039973a RB |
776 | d->sbdma_addptr = NULL; |
777 | d->sbdma_remptr = NULL; | |
1da177e4 LT |
778 | } |
779 | ||
780 | static void sbdma_align_skb(struct sk_buff *skb,int power2,int offset) | |
781 | { | |
782 | unsigned long addr; | |
783 | unsigned long newaddr; | |
74b0247f | 784 | |
1da177e4 | 785 | addr = (unsigned long) skb->data; |
74b0247f | 786 | |
1da177e4 | 787 | newaddr = (addr + power2 - 1) & ~(power2 - 1); |
74b0247f | 788 | |
1da177e4 LT |
789 | skb_reserve(skb,newaddr-addr+offset); |
790 | } | |
791 | ||
792 | ||
793 | /********************************************************************** | |
794 | * SBDMA_ADD_RCVBUFFER(d,sb) | |
74b0247f | 795 | * |
1da177e4 LT |
796 | * Add a buffer to the specified DMA channel. For receive channels, |
797 | * this queues a buffer for inbound packets. | |
74b0247f RB |
798 | * |
799 | * Input parameters: | |
1da177e4 LT |
800 | * d - DMA channel descriptor |
801 | * sb - sk_buff to add, or NULL if we should allocate one | |
74b0247f | 802 | * |
1da177e4 LT |
803 | * Return value: |
804 | * 0 if buffer could not be added (ring is full) | |
805 | * 1 if buffer added successfully | |
806 | ********************************************************************* */ | |
807 | ||
808 | ||
73d73969 | 809 | static int sbdma_add_rcvbuffer(struct sbmacdma *d, struct sk_buff *sb) |
1da177e4 | 810 | { |
73d73969 MR |
811 | struct sbdmadscr *dsc; |
812 | struct sbdmadscr *nextdsc; | |
1da177e4 LT |
813 | struct sk_buff *sb_new = NULL; |
814 | int pktsize = ENET_PACKET_SIZE; | |
74b0247f | 815 | |
1da177e4 | 816 | /* get pointer to our current place in the ring */ |
74b0247f | 817 | |
1da177e4 LT |
818 | dsc = d->sbdma_addptr; |
819 | nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr); | |
74b0247f | 820 | |
1da177e4 LT |
821 | /* |
822 | * figure out if the ring is full - if the next descriptor | |
823 | * is the same as the one that we're going to remove from | |
824 | * the ring, the ring is full | |
825 | */ | |
74b0247f | 826 | |
1da177e4 LT |
827 | if (nextdsc == d->sbdma_remptr) { |
828 | return -ENOSPC; | |
829 | } | |
830 | ||
74b0247f RB |
831 | /* |
832 | * Allocate a sk_buff if we don't already have one. | |
1da177e4 LT |
833 | * If we do have an sk_buff, reset it so that it's empty. |
834 | * | |
835 | * Note: sk_buffs don't seem to be guaranteed to have any sort | |
836 | * of alignment when they are allocated. Therefore, allocate enough | |
837 | * extra space to make sure that: | |
838 | * | |
839 | * 1. the data does not start in the middle of a cache line. | |
840 | * 2. The data does not end in the middle of a cache line | |
74b0247f | 841 | * 3. The buffer can be aligned such that the IP addresses are |
1da177e4 LT |
842 | * naturally aligned. |
843 | * | |
844 | * Remember, the SOCs MAC writes whole cache lines at a time, | |
845 | * without reading the old contents first. So, if the sk_buff's | |
846 | * data portion starts in the middle of a cache line, the SOC | |
847 | * DMA will trash the beginning (and ending) portions. | |
848 | */ | |
74b0247f | 849 | |
1da177e4 LT |
850 | if (sb == NULL) { |
851 | sb_new = dev_alloc_skb(ENET_PACKET_SIZE + SMP_CACHE_BYTES * 2 + ETHER_ALIGN); | |
852 | if (sb_new == NULL) { | |
f5279ffd | 853 | pr_info("%s: sk_buff allocation failed\n", |
1da177e4 LT |
854 | d->sbdma_eth->sbm_dev->name); |
855 | return -ENOBUFS; | |
856 | } | |
857 | ||
858 | sbdma_align_skb(sb_new, SMP_CACHE_BYTES, ETHER_ALIGN); | |
1da177e4 LT |
859 | } |
860 | else { | |
861 | sb_new = sb; | |
74b0247f | 862 | /* |
1da177e4 LT |
863 | * nothing special to reinit buffer, it's already aligned |
864 | * and sb->data already points to a good place. | |
865 | */ | |
866 | } | |
74b0247f | 867 | |
1da177e4 | 868 | /* |
74b0247f | 869 | * fill in the descriptor |
1da177e4 | 870 | */ |
74b0247f | 871 | |
1da177e4 LT |
872 | #ifdef CONFIG_SBMAC_COALESCE |
873 | /* | |
874 | * Do not interrupt per DMA transfer. | |
875 | */ | |
689be439 | 876 | dsc->dscr_a = virt_to_phys(sb_new->data) | |
2039973a | 877 | V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) | 0; |
1da177e4 | 878 | #else |
689be439 | 879 | dsc->dscr_a = virt_to_phys(sb_new->data) | |
1da177e4 LT |
880 | V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) | |
881 | M_DMA_DSCRA_INTERRUPT; | |
882 | #endif | |
883 | ||
884 | /* receiving: no options */ | |
885 | dsc->dscr_b = 0; | |
74b0247f | 886 | |
1da177e4 | 887 | /* |
74b0247f | 888 | * fill in the context |
1da177e4 | 889 | */ |
74b0247f | 890 | |
1da177e4 | 891 | d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb_new; |
74b0247f RB |
892 | |
893 | /* | |
894 | * point at next packet | |
1da177e4 | 895 | */ |
74b0247f | 896 | |
1da177e4 | 897 | d->sbdma_addptr = nextdsc; |
74b0247f RB |
898 | |
899 | /* | |
1da177e4 LT |
900 | * Give the buffer to the DMA engine. |
901 | */ | |
74b0247f | 902 | |
2039973a | 903 | __raw_writeq(1, d->sbdma_dscrcnt); |
74b0247f | 904 | |
1da177e4 LT |
905 | return 0; /* we did it */ |
906 | } | |
907 | ||
908 | /********************************************************************** | |
909 | * SBDMA_ADD_TXBUFFER(d,sb) | |
74b0247f | 910 | * |
1da177e4 LT |
911 | * Add a transmit buffer to the specified DMA channel, causing a |
912 | * transmit to start. | |
74b0247f RB |
913 | * |
914 | * Input parameters: | |
1da177e4 LT |
915 | * d - DMA channel descriptor |
916 | * sb - sk_buff to add | |
74b0247f | 917 | * |
1da177e4 LT |
918 | * Return value: |
919 | * 0 transmit queued successfully | |
920 | * otherwise error code | |
921 | ********************************************************************* */ | |
922 | ||
923 | ||
73d73969 | 924 | static int sbdma_add_txbuffer(struct sbmacdma *d, struct sk_buff *sb) |
1da177e4 | 925 | { |
73d73969 MR |
926 | struct sbdmadscr *dsc; |
927 | struct sbdmadscr *nextdsc; | |
1da177e4 LT |
928 | uint64_t phys; |
929 | uint64_t ncb; | |
930 | int length; | |
74b0247f | 931 | |
1da177e4 | 932 | /* get pointer to our current place in the ring */ |
74b0247f | 933 | |
1da177e4 LT |
934 | dsc = d->sbdma_addptr; |
935 | nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr); | |
74b0247f | 936 | |
1da177e4 LT |
937 | /* |
938 | * figure out if the ring is full - if the next descriptor | |
939 | * is the same as the one that we're going to remove from | |
940 | * the ring, the ring is full | |
941 | */ | |
74b0247f | 942 | |
1da177e4 LT |
943 | if (nextdsc == d->sbdma_remptr) { |
944 | return -ENOSPC; | |
945 | } | |
74b0247f | 946 | |
1da177e4 LT |
947 | /* |
948 | * Under Linux, it's not necessary to copy/coalesce buffers | |
949 | * like it is on NetBSD. We think they're all contiguous, | |
950 | * but that may not be true for GBE. | |
951 | */ | |
74b0247f | 952 | |
1da177e4 | 953 | length = sb->len; |
74b0247f | 954 | |
1da177e4 LT |
955 | /* |
956 | * fill in the descriptor. Note that the number of cache | |
957 | * blocks in the descriptor is the number of blocks | |
958 | * *spanned*, so we need to add in the offset (if any) | |
959 | * while doing the calculation. | |
960 | */ | |
74b0247f | 961 | |
1da177e4 LT |
962 | phys = virt_to_phys(sb->data); |
963 | ncb = NUMCACHEBLKS(length+(phys & (SMP_CACHE_BYTES - 1))); | |
964 | ||
74b0247f | 965 | dsc->dscr_a = phys | |
1da177e4 LT |
966 | V_DMA_DSCRA_A_SIZE(ncb) | |
967 | #ifndef CONFIG_SBMAC_COALESCE | |
968 | M_DMA_DSCRA_INTERRUPT | | |
969 | #endif | |
970 | M_DMA_ETHTX_SOP; | |
74b0247f | 971 | |
1da177e4 LT |
972 | /* transmitting: set outbound options and length */ |
973 | ||
974 | dsc->dscr_b = V_DMA_DSCRB_OPTIONS(K_DMA_ETHTX_APPENDCRC_APPENDPAD) | | |
975 | V_DMA_DSCRB_PKT_SIZE(length); | |
74b0247f | 976 | |
1da177e4 | 977 | /* |
74b0247f | 978 | * fill in the context |
1da177e4 | 979 | */ |
74b0247f | 980 | |
1da177e4 | 981 | d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb; |
74b0247f RB |
982 | |
983 | /* | |
984 | * point at next packet | |
1da177e4 | 985 | */ |
74b0247f | 986 | |
1da177e4 | 987 | d->sbdma_addptr = nextdsc; |
74b0247f RB |
988 | |
989 | /* | |
1da177e4 LT |
990 | * Give the buffer to the DMA engine. |
991 | */ | |
74b0247f | 992 | |
2039973a | 993 | __raw_writeq(1, d->sbdma_dscrcnt); |
74b0247f | 994 | |
1da177e4 LT |
995 | return 0; /* we did it */ |
996 | } | |
997 | ||
998 | ||
999 | ||
1000 | ||
1001 | /********************************************************************** | |
1002 | * SBDMA_EMPTYRING(d) | |
74b0247f | 1003 | * |
1da177e4 | 1004 | * Free all allocated sk_buffs on the specified DMA channel; |
74b0247f RB |
1005 | * |
1006 | * Input parameters: | |
1da177e4 | 1007 | * d - DMA channel |
74b0247f | 1008 | * |
1da177e4 LT |
1009 | * Return value: |
1010 | * nothing | |
1011 | ********************************************************************* */ | |
1012 | ||
73d73969 | 1013 | static void sbdma_emptyring(struct sbmacdma *d) |
1da177e4 LT |
1014 | { |
1015 | int idx; | |
1016 | struct sk_buff *sb; | |
74b0247f | 1017 | |
1da177e4 LT |
1018 | for (idx = 0; idx < d->sbdma_maxdescr; idx++) { |
1019 | sb = d->sbdma_ctxtable[idx]; | |
1020 | if (sb) { | |
1021 | dev_kfree_skb(sb); | |
1022 | d->sbdma_ctxtable[idx] = NULL; | |
1023 | } | |
1024 | } | |
1025 | } | |
1026 | ||
1027 | ||
1028 | /********************************************************************** | |
1029 | * SBDMA_FILLRING(d) | |
74b0247f | 1030 | * |
1da177e4 LT |
1031 | * Fill the specified DMA channel (must be receive channel) |
1032 | * with sk_buffs | |
74b0247f RB |
1033 | * |
1034 | * Input parameters: | |
1da177e4 | 1035 | * d - DMA channel |
74b0247f | 1036 | * |
1da177e4 LT |
1037 | * Return value: |
1038 | * nothing | |
1039 | ********************************************************************* */ | |
1040 | ||
73d73969 | 1041 | static void sbdma_fillring(struct sbmacdma *d) |
1da177e4 LT |
1042 | { |
1043 | int idx; | |
74b0247f | 1044 | |
1da177e4 LT |
1045 | for (idx = 0; idx < SBMAC_MAX_RXDESCR-1; idx++) { |
1046 | if (sbdma_add_rcvbuffer(d,NULL) != 0) | |
1047 | break; | |
1048 | } | |
1049 | } | |
1050 | ||
d6830018 DS |
1051 | #ifdef CONFIG_NET_POLL_CONTROLLER |
1052 | static void sbmac_netpoll(struct net_device *netdev) | |
1053 | { | |
1054 | struct sbmac_softc *sc = netdev_priv(netdev); | |
1055 | int irq = sc->sbm_dev->irq; | |
1056 | ||
1057 | __raw_writeq(0, sc->sbm_imr); | |
1058 | ||
0da2f0f1 | 1059 | sbmac_intr(irq, netdev); |
d6830018 DS |
1060 | |
1061 | #ifdef CONFIG_SBMAC_COALESCE | |
1062 | __raw_writeq(((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) | | |
1063 | ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0), | |
1064 | sc->sbm_imr); | |
1065 | #else | |
1066 | __raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) | | |
1067 | (M_MAC_INT_CHANNEL << S_MAC_RX_CH0), sc->sbm_imr); | |
1068 | #endif | |
1069 | } | |
1070 | #endif | |
1da177e4 LT |
1071 | |
1072 | /********************************************************************** | |
693aa947 | 1073 | * SBDMA_RX_PROCESS(sc,d,work_to_do,poll) |
74b0247f RB |
1074 | * |
1075 | * Process "completed" receive buffers on the specified DMA channel. | |
1da177e4 | 1076 | * |
74b0247f | 1077 | * Input parameters: |
693aa947 MM |
1078 | * sc - softc structure |
1079 | * d - DMA channel context | |
1080 | * work_to_do - no. of packets to process before enabling interrupt | |
1081 | * again (for NAPI) | |
1082 | * poll - 1: using polling (for NAPI) | |
74b0247f | 1083 | * |
1da177e4 LT |
1084 | * Return value: |
1085 | * nothing | |
1086 | ********************************************************************* */ | |
1087 | ||
73d73969 MR |
1088 | static int sbdma_rx_process(struct sbmac_softc *sc, struct sbmacdma *d, |
1089 | int work_to_do, int poll) | |
1da177e4 | 1090 | { |
09f75cd7 | 1091 | struct net_device *dev = sc->sbm_dev; |
1da177e4 LT |
1092 | int curidx; |
1093 | int hwidx; | |
73d73969 | 1094 | struct sbdmadscr *dsc; |
1da177e4 LT |
1095 | struct sk_buff *sb; |
1096 | int len; | |
693aa947 MM |
1097 | int work_done = 0; |
1098 | int dropped = 0; | |
74b0247f | 1099 | |
693aa947 MM |
1100 | prefetch(d); |
1101 | ||
1102 | again: | |
1103 | /* Check if the HW dropped any frames */ | |
09f75cd7 | 1104 | dev->stats.rx_fifo_errors |
693aa947 MM |
1105 | += __raw_readq(sc->sbm_rxdma.sbdma_oodpktlost) & 0xffff; |
1106 | __raw_writeq(0, sc->sbm_rxdma.sbdma_oodpktlost); | |
1107 | ||
1108 | while (work_to_do-- > 0) { | |
74b0247f | 1109 | /* |
1da177e4 LT |
1110 | * figure out where we are (as an index) and where |
1111 | * the hardware is (also as an index) | |
1112 | * | |
74b0247f | 1113 | * This could be done faster if (for example) the |
1da177e4 LT |
1114 | * descriptor table was page-aligned and contiguous in |
1115 | * both virtual and physical memory -- you could then | |
1116 | * just compare the low-order bits of the virtual address | |
1117 | * (sbdma_remptr) and the physical address (sbdma_curdscr CSR) | |
1118 | */ | |
74b0247f | 1119 | |
693aa947 MM |
1120 | dsc = d->sbdma_remptr; |
1121 | curidx = dsc - d->sbdma_dscrtable; | |
1122 | ||
1123 | prefetch(dsc); | |
1124 | prefetch(&d->sbdma_ctxtable[curidx]); | |
1125 | ||
73d73969 MR |
1126 | hwidx = ((__raw_readq(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) - |
1127 | d->sbdma_dscrtable_phys) / | |
1128 | sizeof(*d->sbdma_dscrtable); | |
74b0247f | 1129 | |
1da177e4 LT |
1130 | /* |
1131 | * If they're the same, that means we've processed all | |
1132 | * of the descriptors up to (but not including) the one that | |
1133 | * the hardware is working on right now. | |
1134 | */ | |
74b0247f | 1135 | |
1da177e4 | 1136 | if (curidx == hwidx) |
693aa947 | 1137 | goto done; |
74b0247f | 1138 | |
1da177e4 LT |
1139 | /* |
1140 | * Otherwise, get the packet's sk_buff ptr back | |
1141 | */ | |
74b0247f | 1142 | |
1da177e4 LT |
1143 | sb = d->sbdma_ctxtable[curidx]; |
1144 | d->sbdma_ctxtable[curidx] = NULL; | |
74b0247f | 1145 | |
1da177e4 | 1146 | len = (int)G_DMA_DSCRB_PKT_SIZE(dsc->dscr_b) - 4; |
74b0247f | 1147 | |
1da177e4 LT |
1148 | /* |
1149 | * Check packet status. If good, process it. | |
1150 | * If not, silently drop it and put it back on the | |
1151 | * receive ring. | |
1152 | */ | |
74b0247f | 1153 | |
693aa947 | 1154 | if (likely (!(dsc->dscr_a & M_DMA_ETHRX_BAD))) { |
74b0247f | 1155 | |
1da177e4 LT |
1156 | /* |
1157 | * Add a new buffer to replace the old one. If we fail | |
1158 | * to allocate a buffer, we're going to drop this | |
1159 | * packet and put it right back on the receive ring. | |
1160 | */ | |
74b0247f | 1161 | |
693aa947 MM |
1162 | if (unlikely (sbdma_add_rcvbuffer(d,NULL) == |
1163 | -ENOBUFS)) { | |
09f75cd7 | 1164 | dev->stats.rx_dropped++; |
1da177e4 | 1165 | sbdma_add_rcvbuffer(d,sb); /* re-add old buffer */ |
693aa947 MM |
1166 | /* No point in continuing at the moment */ |
1167 | printk(KERN_ERR "dropped packet (1)\n"); | |
1168 | d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr); | |
1169 | goto done; | |
1da177e4 LT |
1170 | } else { |
1171 | /* | |
1172 | * Set length into the packet | |
1173 | */ | |
1174 | skb_put(sb,len); | |
74b0247f | 1175 | |
1da177e4 LT |
1176 | /* |
1177 | * Buffer has been replaced on the | |
1178 | * receive ring. Pass the buffer to | |
1179 | * the kernel | |
1180 | */ | |
1da177e4 LT |
1181 | sb->protocol = eth_type_trans(sb,d->sbdma_eth->sbm_dev); |
1182 | /* Check hw IPv4/TCP checksum if supported */ | |
1183 | if (sc->rx_hw_checksum == ENABLE) { | |
1184 | if (!((dsc->dscr_a) & M_DMA_ETHRX_BADIP4CS) && | |
1185 | !((dsc->dscr_a) & M_DMA_ETHRX_BADTCPCS)) { | |
1186 | sb->ip_summed = CHECKSUM_UNNECESSARY; | |
1187 | /* don't need to set sb->csum */ | |
1188 | } else { | |
1189 | sb->ip_summed = CHECKSUM_NONE; | |
1190 | } | |
1191 | } | |
693aa947 MM |
1192 | prefetch(sb->data); |
1193 | prefetch((const void *)(((char *)sb->data)+32)); | |
1194 | if (poll) | |
1195 | dropped = netif_receive_skb(sb); | |
1196 | else | |
1197 | dropped = netif_rx(sb); | |
1198 | ||
1199 | if (dropped == NET_RX_DROP) { | |
09f75cd7 | 1200 | dev->stats.rx_dropped++; |
693aa947 MM |
1201 | d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr); |
1202 | goto done; | |
1203 | } | |
1204 | else { | |
09f75cd7 JG |
1205 | dev->stats.rx_bytes += len; |
1206 | dev->stats.rx_packets++; | |
693aa947 | 1207 | } |
1da177e4 LT |
1208 | } |
1209 | } else { | |
1210 | /* | |
1211 | * Packet was mangled somehow. Just drop it and | |
1212 | * put it back on the receive ring. | |
1213 | */ | |
09f75cd7 | 1214 | dev->stats.rx_errors++; |
1da177e4 LT |
1215 | sbdma_add_rcvbuffer(d,sb); |
1216 | } | |
74b0247f RB |
1217 | |
1218 | ||
1219 | /* | |
1da177e4 LT |
1220 | * .. and advance to the next buffer. |
1221 | */ | |
74b0247f | 1222 | |
1da177e4 | 1223 | d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr); |
693aa947 MM |
1224 | work_done++; |
1225 | } | |
1226 | if (!poll) { | |
1227 | work_to_do = 32; | |
1228 | goto again; /* collect fifo drop statistics again */ | |
1da177e4 | 1229 | } |
693aa947 MM |
1230 | done: |
1231 | return work_done; | |
1da177e4 LT |
1232 | } |
1233 | ||
1da177e4 LT |
1234 | /********************************************************************** |
1235 | * SBDMA_TX_PROCESS(sc,d) | |
74b0247f RB |
1236 | * |
1237 | * Process "completed" transmit buffers on the specified DMA channel. | |
1da177e4 LT |
1238 | * This is normally called within the interrupt service routine. |
1239 | * Note that this isn't really ideal for priority channels, since | |
74b0247f RB |
1240 | * it processes all of the packets on a given channel before |
1241 | * returning. | |
1da177e4 | 1242 | * |
74b0247f | 1243 | * Input parameters: |
1da177e4 | 1244 | * sc - softc structure |
693aa947 MM |
1245 | * d - DMA channel context |
1246 | * poll - 1: using polling (for NAPI) | |
74b0247f | 1247 | * |
1da177e4 LT |
1248 | * Return value: |
1249 | * nothing | |
1250 | ********************************************************************* */ | |
1251 | ||
73d73969 MR |
1252 | static void sbdma_tx_process(struct sbmac_softc *sc, struct sbmacdma *d, |
1253 | int poll) | |
1da177e4 | 1254 | { |
09f75cd7 | 1255 | struct net_device *dev = sc->sbm_dev; |
1da177e4 LT |
1256 | int curidx; |
1257 | int hwidx; | |
73d73969 | 1258 | struct sbdmadscr *dsc; |
1da177e4 LT |
1259 | struct sk_buff *sb; |
1260 | unsigned long flags; | |
693aa947 | 1261 | int packets_handled = 0; |
1da177e4 LT |
1262 | |
1263 | spin_lock_irqsave(&(sc->sbm_lock), flags); | |
74b0247f | 1264 | |
693aa947 MM |
1265 | if (d->sbdma_remptr == d->sbdma_addptr) |
1266 | goto end_unlock; | |
1267 | ||
73d73969 MR |
1268 | hwidx = ((__raw_readq(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) - |
1269 | d->sbdma_dscrtable_phys) / sizeof(*d->sbdma_dscrtable); | |
693aa947 | 1270 | |
1da177e4 | 1271 | for (;;) { |
74b0247f | 1272 | /* |
1da177e4 LT |
1273 | * figure out where we are (as an index) and where |
1274 | * the hardware is (also as an index) | |
1275 | * | |
74b0247f | 1276 | * This could be done faster if (for example) the |
1da177e4 LT |
1277 | * descriptor table was page-aligned and contiguous in |
1278 | * both virtual and physical memory -- you could then | |
1279 | * just compare the low-order bits of the virtual address | |
1280 | * (sbdma_remptr) and the physical address (sbdma_curdscr CSR) | |
1281 | */ | |
74b0247f | 1282 | |
1da177e4 | 1283 | curidx = d->sbdma_remptr - d->sbdma_dscrtable; |
1da177e4 LT |
1284 | |
1285 | /* | |
1286 | * If they're the same, that means we've processed all | |
1287 | * of the descriptors up to (but not including) the one that | |
1288 | * the hardware is working on right now. | |
1289 | */ | |
74b0247f | 1290 | |
1da177e4 LT |
1291 | if (curidx == hwidx) |
1292 | break; | |
74b0247f | 1293 | |
1da177e4 LT |
1294 | /* |
1295 | * Otherwise, get the packet's sk_buff ptr back | |
1296 | */ | |
74b0247f | 1297 | |
1da177e4 LT |
1298 | dsc = &(d->sbdma_dscrtable[curidx]); |
1299 | sb = d->sbdma_ctxtable[curidx]; | |
1300 | d->sbdma_ctxtable[curidx] = NULL; | |
74b0247f | 1301 | |
1da177e4 LT |
1302 | /* |
1303 | * Stats | |
1304 | */ | |
74b0247f | 1305 | |
09f75cd7 JG |
1306 | dev->stats.tx_bytes += sb->len; |
1307 | dev->stats.tx_packets++; | |
74b0247f | 1308 | |
1da177e4 LT |
1309 | /* |
1310 | * for transmits, we just free buffers. | |
1311 | */ | |
74b0247f | 1312 | |
1da177e4 | 1313 | dev_kfree_skb_irq(sb); |
74b0247f RB |
1314 | |
1315 | /* | |
1da177e4 LT |
1316 | * .. and advance to the next buffer. |
1317 | */ | |
1318 | ||
1319 | d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr); | |
74b0247f | 1320 | |
693aa947 MM |
1321 | packets_handled++; |
1322 | ||
1da177e4 | 1323 | } |
74b0247f | 1324 | |
1da177e4 LT |
1325 | /* |
1326 | * Decide if we should wake up the protocol or not. | |
1327 | * Other drivers seem to do this when we reach a low | |
1328 | * watermark on the transmit queue. | |
1329 | */ | |
74b0247f | 1330 | |
693aa947 MM |
1331 | if (packets_handled) |
1332 | netif_wake_queue(d->sbdma_eth->sbm_dev); | |
74b0247f | 1333 | |
693aa947 | 1334 | end_unlock: |
1da177e4 | 1335 | spin_unlock_irqrestore(&(sc->sbm_lock), flags); |
74b0247f | 1336 | |
1da177e4 LT |
1337 | } |
1338 | ||
1339 | ||
1340 | ||
1341 | /********************************************************************** | |
1342 | * SBMAC_INITCTX(s) | |
74b0247f | 1343 | * |
1da177e4 LT |
1344 | * Initialize an Ethernet context structure - this is called |
1345 | * once per MAC on the 1250. Memory is allocated here, so don't | |
1346 | * call it again from inside the ioctl routines that bring the | |
1347 | * interface up/down | |
74b0247f RB |
1348 | * |
1349 | * Input parameters: | |
1da177e4 | 1350 | * s - sbmac context structure |
74b0247f | 1351 | * |
1da177e4 LT |
1352 | * Return value: |
1353 | * 0 | |
1354 | ********************************************************************* */ | |
1355 | ||
1356 | static int sbmac_initctx(struct sbmac_softc *s) | |
1357 | { | |
74b0247f RB |
1358 | |
1359 | /* | |
1360 | * figure out the addresses of some ports | |
1da177e4 | 1361 | */ |
74b0247f | 1362 | |
1da177e4 LT |
1363 | s->sbm_macenable = s->sbm_base + R_MAC_ENABLE; |
1364 | s->sbm_maccfg = s->sbm_base + R_MAC_CFG; | |
1365 | s->sbm_fifocfg = s->sbm_base + R_MAC_THRSH_CFG; | |
1366 | s->sbm_framecfg = s->sbm_base + R_MAC_FRAMECFG; | |
1367 | s->sbm_rxfilter = s->sbm_base + R_MAC_ADFILTER_CFG; | |
1368 | s->sbm_isr = s->sbm_base + R_MAC_STATUS; | |
1369 | s->sbm_imr = s->sbm_base + R_MAC_INT_MASK; | |
1370 | s->sbm_mdio = s->sbm_base + R_MAC_MDIO; | |
1371 | ||
1da177e4 LT |
1372 | /* |
1373 | * Initialize the DMA channels. Right now, only one per MAC is used | |
1374 | * Note: Only do this _once_, as it allocates memory from the kernel! | |
1375 | */ | |
74b0247f | 1376 | |
1da177e4 LT |
1377 | sbdma_initctx(&(s->sbm_txdma),s,0,DMA_TX,SBMAC_MAX_TXDESCR); |
1378 | sbdma_initctx(&(s->sbm_rxdma),s,0,DMA_RX,SBMAC_MAX_RXDESCR); | |
74b0247f | 1379 | |
1da177e4 LT |
1380 | /* |
1381 | * initial state is OFF | |
1382 | */ | |
74b0247f | 1383 | |
1da177e4 | 1384 | s->sbm_state = sbmac_state_off; |
74b0247f | 1385 | |
1da177e4 LT |
1386 | return 0; |
1387 | } | |
1388 | ||
1389 | ||
73d73969 | 1390 | static void sbdma_uninitctx(struct sbmacdma *d) |
1da177e4 | 1391 | { |
693aa947 MM |
1392 | if (d->sbdma_dscrtable_unaligned) { |
1393 | kfree(d->sbdma_dscrtable_unaligned); | |
1394 | d->sbdma_dscrtable_unaligned = d->sbdma_dscrtable = NULL; | |
1da177e4 | 1395 | } |
74b0247f | 1396 | |
1da177e4 LT |
1397 | if (d->sbdma_ctxtable) { |
1398 | kfree(d->sbdma_ctxtable); | |
1399 | d->sbdma_ctxtable = NULL; | |
1400 | } | |
1401 | } | |
1402 | ||
1403 | ||
1404 | static void sbmac_uninitctx(struct sbmac_softc *sc) | |
1405 | { | |
1406 | sbdma_uninitctx(&(sc->sbm_txdma)); | |
1407 | sbdma_uninitctx(&(sc->sbm_rxdma)); | |
1408 | } | |
1409 | ||
1410 | ||
1411 | /********************************************************************** | |
1412 | * SBMAC_CHANNEL_START(s) | |
74b0247f | 1413 | * |
1da177e4 | 1414 | * Start packet processing on this MAC. |
74b0247f RB |
1415 | * |
1416 | * Input parameters: | |
1da177e4 | 1417 | * s - sbmac structure |
74b0247f | 1418 | * |
1da177e4 LT |
1419 | * Return value: |
1420 | * nothing | |
1421 | ********************************************************************* */ | |
1422 | ||
1423 | static void sbmac_channel_start(struct sbmac_softc *s) | |
1424 | { | |
1425 | uint64_t reg; | |
73d73969 | 1426 | void __iomem *port; |
1da177e4 LT |
1427 | uint64_t cfg,fifo,framecfg; |
1428 | int idx, th_value; | |
74b0247f | 1429 | |
1da177e4 LT |
1430 | /* |
1431 | * Don't do this if running | |
1432 | */ | |
1433 | ||
1434 | if (s->sbm_state == sbmac_state_on) | |
1435 | return; | |
74b0247f | 1436 | |
1da177e4 LT |
1437 | /* |
1438 | * Bring the controller out of reset, but leave it off. | |
1439 | */ | |
74b0247f | 1440 | |
2039973a | 1441 | __raw_writeq(0, s->sbm_macenable); |
74b0247f | 1442 | |
1da177e4 LT |
1443 | /* |
1444 | * Ignore all received packets | |
1445 | */ | |
74b0247f | 1446 | |
2039973a | 1447 | __raw_writeq(0, s->sbm_rxfilter); |
74b0247f RB |
1448 | |
1449 | /* | |
1da177e4 LT |
1450 | * Calculate values for various control registers. |
1451 | */ | |
74b0247f | 1452 | |
1da177e4 | 1453 | cfg = M_MAC_RETRY_EN | |
74b0247f | 1454 | M_MAC_TX_HOLD_SOP_EN | |
1da177e4 LT |
1455 | V_MAC_TX_PAUSE_CNT_16K | |
1456 | M_MAC_AP_STAT_EN | | |
1457 | M_MAC_FAST_SYNC | | |
1458 | M_MAC_SS_EN | | |
1459 | 0; | |
74b0247f RB |
1460 | |
1461 | /* | |
1da177e4 LT |
1462 | * Be sure that RD_THRSH+WR_THRSH <= 32 for pass1 pars |
1463 | * and make sure that RD_THRSH + WR_THRSH <=128 for pass2 and above | |
1464 | * Use a larger RD_THRSH for gigabit | |
1465 | */ | |
f90fdc3c | 1466 | if (soc_type == K_SYS_SOC_TYPE_BCM1250 && periph_rev < 2) |
1da177e4 | 1467 | th_value = 28; |
f90fdc3c RB |
1468 | else |
1469 | th_value = 64; | |
1da177e4 LT |
1470 | |
1471 | fifo = V_MAC_TX_WR_THRSH(4) | /* Must be '4' or '8' */ | |
1472 | ((s->sbm_speed == sbmac_speed_1000) | |
1473 | ? V_MAC_TX_RD_THRSH(th_value) : V_MAC_TX_RD_THRSH(4)) | | |
1474 | V_MAC_TX_RL_THRSH(4) | | |
1475 | V_MAC_RX_PL_THRSH(4) | | |
1476 | V_MAC_RX_RD_THRSH(4) | /* Must be '4' */ | |
1477 | V_MAC_RX_PL_THRSH(4) | | |
1478 | V_MAC_RX_RL_THRSH(8) | | |
1479 | 0; | |
1480 | ||
1481 | framecfg = V_MAC_MIN_FRAMESZ_DEFAULT | | |
1482 | V_MAC_MAX_FRAMESZ_DEFAULT | | |
1483 | V_MAC_BACKOFF_SEL(1); | |
1484 | ||
1485 | /* | |
74b0247f | 1486 | * Clear out the hash address map |
1da177e4 | 1487 | */ |
74b0247f | 1488 | |
1da177e4 LT |
1489 | port = s->sbm_base + R_MAC_HASH_BASE; |
1490 | for (idx = 0; idx < MAC_HASH_COUNT; idx++) { | |
2039973a | 1491 | __raw_writeq(0, port); |
1da177e4 LT |
1492 | port += sizeof(uint64_t); |
1493 | } | |
74b0247f | 1494 | |
1da177e4 LT |
1495 | /* |
1496 | * Clear out the exact-match table | |
1497 | */ | |
74b0247f | 1498 | |
1da177e4 LT |
1499 | port = s->sbm_base + R_MAC_ADDR_BASE; |
1500 | for (idx = 0; idx < MAC_ADDR_COUNT; idx++) { | |
2039973a | 1501 | __raw_writeq(0, port); |
1da177e4 LT |
1502 | port += sizeof(uint64_t); |
1503 | } | |
74b0247f | 1504 | |
1da177e4 LT |
1505 | /* |
1506 | * Clear out the DMA Channel mapping table registers | |
1507 | */ | |
74b0247f | 1508 | |
1da177e4 LT |
1509 | port = s->sbm_base + R_MAC_CHUP0_BASE; |
1510 | for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) { | |
2039973a | 1511 | __raw_writeq(0, port); |
1da177e4 LT |
1512 | port += sizeof(uint64_t); |
1513 | } | |
1514 | ||
1515 | ||
1516 | port = s->sbm_base + R_MAC_CHLO0_BASE; | |
1517 | for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) { | |
2039973a | 1518 | __raw_writeq(0, port); |
1da177e4 LT |
1519 | port += sizeof(uint64_t); |
1520 | } | |
74b0247f | 1521 | |
1da177e4 LT |
1522 | /* |
1523 | * Program the hardware address. It goes into the hardware-address | |
1524 | * register as well as the first filter register. | |
1525 | */ | |
74b0247f | 1526 | |
1da177e4 | 1527 | reg = sbmac_addr2reg(s->sbm_hwaddr); |
74b0247f | 1528 | |
1da177e4 | 1529 | port = s->sbm_base + R_MAC_ADDR_BASE; |
2039973a | 1530 | __raw_writeq(reg, port); |
1da177e4 LT |
1531 | port = s->sbm_base + R_MAC_ETHERNET_ADDR; |
1532 | ||
1533 | #ifdef CONFIG_SB1_PASS_1_WORKAROUNDS | |
1534 | /* | |
1535 | * Pass1 SOCs do not receive packets addressed to the | |
1536 | * destination address in the R_MAC_ETHERNET_ADDR register. | |
1537 | * Set the value to zero. | |
1538 | */ | |
2039973a | 1539 | __raw_writeq(0, port); |
1da177e4 | 1540 | #else |
2039973a | 1541 | __raw_writeq(reg, port); |
1da177e4 | 1542 | #endif |
74b0247f | 1543 | |
1da177e4 LT |
1544 | /* |
1545 | * Set the receive filter for no packets, and write values | |
1546 | * to the various config registers | |
1547 | */ | |
74b0247f | 1548 | |
2039973a RB |
1549 | __raw_writeq(0, s->sbm_rxfilter); |
1550 | __raw_writeq(0, s->sbm_imr); | |
1551 | __raw_writeq(framecfg, s->sbm_framecfg); | |
1552 | __raw_writeq(fifo, s->sbm_fifocfg); | |
1553 | __raw_writeq(cfg, s->sbm_maccfg); | |
74b0247f | 1554 | |
1da177e4 LT |
1555 | /* |
1556 | * Initialize DMA channels (rings should be ok now) | |
1557 | */ | |
74b0247f | 1558 | |
1da177e4 LT |
1559 | sbdma_channel_start(&(s->sbm_rxdma), DMA_RX); |
1560 | sbdma_channel_start(&(s->sbm_txdma), DMA_TX); | |
74b0247f | 1561 | |
1da177e4 LT |
1562 | /* |
1563 | * Configure the speed, duplex, and flow control | |
1564 | */ | |
1565 | ||
1566 | sbmac_set_speed(s,s->sbm_speed); | |
1567 | sbmac_set_duplex(s,s->sbm_duplex,s->sbm_fc); | |
74b0247f | 1568 | |
1da177e4 LT |
1569 | /* |
1570 | * Fill the receive ring | |
1571 | */ | |
74b0247f | 1572 | |
1da177e4 | 1573 | sbdma_fillring(&(s->sbm_rxdma)); |
74b0247f RB |
1574 | |
1575 | /* | |
1da177e4 | 1576 | * Turn on the rest of the bits in the enable register |
74b0247f RB |
1577 | */ |
1578 | ||
f90fdc3c RB |
1579 | #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80) |
1580 | __raw_writeq(M_MAC_RXDMA_EN0 | | |
1581 | M_MAC_TXDMA_EN0, s->sbm_macenable); | |
1582 | #elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X) | |
2039973a | 1583 | __raw_writeq(M_MAC_RXDMA_EN0 | |
1da177e4 LT |
1584 | M_MAC_TXDMA_EN0 | |
1585 | M_MAC_RX_ENABLE | | |
2039973a | 1586 | M_MAC_TX_ENABLE, s->sbm_macenable); |
f90fdc3c RB |
1587 | #else |
1588 | #error invalid SiByte MAC configuation | |
1589 | #endif | |
1da177e4 LT |
1590 | |
1591 | #ifdef CONFIG_SBMAC_COALESCE | |
2039973a RB |
1592 | __raw_writeq(((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) | |
1593 | ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0), s->sbm_imr); | |
1da177e4 | 1594 | #else |
2039973a RB |
1595 | __raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) | |
1596 | (M_MAC_INT_CHANNEL << S_MAC_RX_CH0), s->sbm_imr); | |
1da177e4 | 1597 | #endif |
74b0247f RB |
1598 | |
1599 | /* | |
1600 | * Enable receiving unicasts and broadcasts | |
1da177e4 | 1601 | */ |
74b0247f | 1602 | |
2039973a | 1603 | __raw_writeq(M_MAC_UCAST_EN | M_MAC_BCAST_EN, s->sbm_rxfilter); |
74b0247f | 1604 | |
1da177e4 | 1605 | /* |
74b0247f | 1606 | * we're running now. |
1da177e4 | 1607 | */ |
74b0247f | 1608 | |
1da177e4 | 1609 | s->sbm_state = sbmac_state_on; |
74b0247f RB |
1610 | |
1611 | /* | |
1612 | * Program multicast addresses | |
1da177e4 | 1613 | */ |
74b0247f | 1614 | |
1da177e4 | 1615 | sbmac_setmulti(s); |
74b0247f RB |
1616 | |
1617 | /* | |
1618 | * If channel was in promiscuous mode before, turn that on | |
1da177e4 | 1619 | */ |
74b0247f | 1620 | |
1da177e4 LT |
1621 | if (s->sbm_devflags & IFF_PROMISC) { |
1622 | sbmac_promiscuous_mode(s,1); | |
1623 | } | |
74b0247f | 1624 | |
1da177e4 LT |
1625 | } |
1626 | ||
1627 | ||
1628 | /********************************************************************** | |
1629 | * SBMAC_CHANNEL_STOP(s) | |
74b0247f | 1630 | * |
1da177e4 | 1631 | * Stop packet processing on this MAC. |
74b0247f RB |
1632 | * |
1633 | * Input parameters: | |
1da177e4 | 1634 | * s - sbmac structure |
74b0247f | 1635 | * |
1da177e4 LT |
1636 | * Return value: |
1637 | * nothing | |
1638 | ********************************************************************* */ | |
1639 | ||
1640 | static void sbmac_channel_stop(struct sbmac_softc *s) | |
1641 | { | |
1642 | /* don't do this if already stopped */ | |
74b0247f | 1643 | |
1da177e4 LT |
1644 | if (s->sbm_state == sbmac_state_off) |
1645 | return; | |
74b0247f | 1646 | |
1da177e4 | 1647 | /* don't accept any packets, disable all interrupts */ |
74b0247f | 1648 | |
2039973a RB |
1649 | __raw_writeq(0, s->sbm_rxfilter); |
1650 | __raw_writeq(0, s->sbm_imr); | |
74b0247f | 1651 | |
1da177e4 | 1652 | /* Turn off ticker */ |
74b0247f | 1653 | |
1da177e4 | 1654 | /* XXX */ |
74b0247f | 1655 | |
1da177e4 | 1656 | /* turn off receiver and transmitter */ |
74b0247f | 1657 | |
2039973a | 1658 | __raw_writeq(0, s->sbm_macenable); |
74b0247f | 1659 | |
1da177e4 | 1660 | /* We're stopped now. */ |
74b0247f | 1661 | |
1da177e4 | 1662 | s->sbm_state = sbmac_state_off; |
74b0247f | 1663 | |
1da177e4 LT |
1664 | /* |
1665 | * Stop DMA channels (rings should be ok now) | |
1666 | */ | |
74b0247f | 1667 | |
1da177e4 LT |
1668 | sbdma_channel_stop(&(s->sbm_rxdma)); |
1669 | sbdma_channel_stop(&(s->sbm_txdma)); | |
74b0247f | 1670 | |
1da177e4 | 1671 | /* Empty the receive and transmit rings */ |
74b0247f | 1672 | |
1da177e4 LT |
1673 | sbdma_emptyring(&(s->sbm_rxdma)); |
1674 | sbdma_emptyring(&(s->sbm_txdma)); | |
74b0247f | 1675 | |
1da177e4 LT |
1676 | } |
1677 | ||
1678 | /********************************************************************** | |
1679 | * SBMAC_SET_CHANNEL_STATE(state) | |
74b0247f | 1680 | * |
1da177e4 | 1681 | * Set the channel's state ON or OFF |
74b0247f RB |
1682 | * |
1683 | * Input parameters: | |
1da177e4 | 1684 | * state - new state |
74b0247f | 1685 | * |
1da177e4 LT |
1686 | * Return value: |
1687 | * old state | |
1688 | ********************************************************************* */ | |
73d73969 MR |
1689 | static enum sbmac_state sbmac_set_channel_state(struct sbmac_softc *sc, |
1690 | enum sbmac_state state) | |
1da177e4 | 1691 | { |
73d73969 | 1692 | enum sbmac_state oldstate = sc->sbm_state; |
74b0247f | 1693 | |
1da177e4 LT |
1694 | /* |
1695 | * If same as previous state, return | |
1696 | */ | |
74b0247f | 1697 | |
1da177e4 LT |
1698 | if (state == oldstate) { |
1699 | return oldstate; | |
1700 | } | |
74b0247f | 1701 | |
1da177e4 | 1702 | /* |
74b0247f | 1703 | * If new state is ON, turn channel on |
1da177e4 | 1704 | */ |
74b0247f | 1705 | |
1da177e4 LT |
1706 | if (state == sbmac_state_on) { |
1707 | sbmac_channel_start(sc); | |
1708 | } | |
1709 | else { | |
1710 | sbmac_channel_stop(sc); | |
1711 | } | |
74b0247f | 1712 | |
1da177e4 LT |
1713 | /* |
1714 | * Return previous state | |
1715 | */ | |
74b0247f | 1716 | |
1da177e4 LT |
1717 | return oldstate; |
1718 | } | |
1719 | ||
1720 | ||
1721 | /********************************************************************** | |
1722 | * SBMAC_PROMISCUOUS_MODE(sc,onoff) | |
74b0247f | 1723 | * |
1da177e4 | 1724 | * Turn on or off promiscuous mode |
74b0247f RB |
1725 | * |
1726 | * Input parameters: | |
1da177e4 LT |
1727 | * sc - softc |
1728 | * onoff - 1 to turn on, 0 to turn off | |
74b0247f | 1729 | * |
1da177e4 LT |
1730 | * Return value: |
1731 | * nothing | |
1732 | ********************************************************************* */ | |
1733 | ||
1734 | static void sbmac_promiscuous_mode(struct sbmac_softc *sc,int onoff) | |
1735 | { | |
1736 | uint64_t reg; | |
74b0247f | 1737 | |
1da177e4 LT |
1738 | if (sc->sbm_state != sbmac_state_on) |
1739 | return; | |
74b0247f | 1740 | |
1da177e4 | 1741 | if (onoff) { |
2039973a | 1742 | reg = __raw_readq(sc->sbm_rxfilter); |
1da177e4 | 1743 | reg |= M_MAC_ALLPKT_EN; |
2039973a | 1744 | __raw_writeq(reg, sc->sbm_rxfilter); |
74b0247f | 1745 | } |
1da177e4 | 1746 | else { |
2039973a | 1747 | reg = __raw_readq(sc->sbm_rxfilter); |
1da177e4 | 1748 | reg &= ~M_MAC_ALLPKT_EN; |
2039973a | 1749 | __raw_writeq(reg, sc->sbm_rxfilter); |
1da177e4 LT |
1750 | } |
1751 | } | |
1752 | ||
1753 | /********************************************************************** | |
1754 | * SBMAC_SETIPHDR_OFFSET(sc,onoff) | |
74b0247f | 1755 | * |
1da177e4 | 1756 | * Set the iphdr offset as 15 assuming ethernet encapsulation |
74b0247f RB |
1757 | * |
1758 | * Input parameters: | |
1da177e4 | 1759 | * sc - softc |
74b0247f | 1760 | * |
1da177e4 LT |
1761 | * Return value: |
1762 | * nothing | |
1763 | ********************************************************************* */ | |
1764 | ||
1765 | static void sbmac_set_iphdr_offset(struct sbmac_softc *sc) | |
1766 | { | |
1767 | uint64_t reg; | |
74b0247f | 1768 | |
1da177e4 | 1769 | /* Hard code the off set to 15 for now */ |
2039973a | 1770 | reg = __raw_readq(sc->sbm_rxfilter); |
1da177e4 | 1771 | reg &= ~M_MAC_IPHDR_OFFSET | V_MAC_IPHDR_OFFSET(15); |
2039973a | 1772 | __raw_writeq(reg, sc->sbm_rxfilter); |
74b0247f | 1773 | |
f90fdc3c RB |
1774 | /* BCM1250 pass1 didn't have hardware checksum. Everything |
1775 | later does. */ | |
1776 | if (soc_type == K_SYS_SOC_TYPE_BCM1250 && periph_rev < 2) { | |
1da177e4 | 1777 | sc->rx_hw_checksum = DISABLE; |
f90fdc3c RB |
1778 | } else { |
1779 | sc->rx_hw_checksum = ENABLE; | |
1da177e4 LT |
1780 | } |
1781 | } | |
1782 | ||
1783 | ||
1784 | /********************************************************************** | |
1785 | * SBMAC_ADDR2REG(ptr) | |
74b0247f | 1786 | * |
1da177e4 LT |
1787 | * Convert six bytes into the 64-bit register value that |
1788 | * we typically write into the SBMAC's address/mcast registers | |
74b0247f RB |
1789 | * |
1790 | * Input parameters: | |
1da177e4 | 1791 | * ptr - pointer to 6 bytes |
74b0247f | 1792 | * |
1da177e4 LT |
1793 | * Return value: |
1794 | * register value | |
1795 | ********************************************************************* */ | |
1796 | ||
1797 | static uint64_t sbmac_addr2reg(unsigned char *ptr) | |
1798 | { | |
1799 | uint64_t reg = 0; | |
74b0247f | 1800 | |
1da177e4 | 1801 | ptr += 6; |
74b0247f RB |
1802 | |
1803 | reg |= (uint64_t) *(--ptr); | |
1da177e4 | 1804 | reg <<= 8; |
74b0247f | 1805 | reg |= (uint64_t) *(--ptr); |
1da177e4 | 1806 | reg <<= 8; |
74b0247f | 1807 | reg |= (uint64_t) *(--ptr); |
1da177e4 | 1808 | reg <<= 8; |
74b0247f | 1809 | reg |= (uint64_t) *(--ptr); |
1da177e4 | 1810 | reg <<= 8; |
74b0247f | 1811 | reg |= (uint64_t) *(--ptr); |
1da177e4 | 1812 | reg <<= 8; |
74b0247f RB |
1813 | reg |= (uint64_t) *(--ptr); |
1814 | ||
1da177e4 LT |
1815 | return reg; |
1816 | } | |
1817 | ||
1818 | ||
1819 | /********************************************************************** | |
1820 | * SBMAC_SET_SPEED(s,speed) | |
74b0247f | 1821 | * |
1da177e4 LT |
1822 | * Configure LAN speed for the specified MAC. |
1823 | * Warning: must be called when MAC is off! | |
74b0247f RB |
1824 | * |
1825 | * Input parameters: | |
1da177e4 | 1826 | * s - sbmac structure |
73d73969 | 1827 | * speed - speed to set MAC to (see enum sbmac_speed) |
74b0247f | 1828 | * |
1da177e4 LT |
1829 | * Return value: |
1830 | * 1 if successful | |
1831 | * 0 indicates invalid parameters | |
1832 | ********************************************************************* */ | |
1833 | ||
73d73969 | 1834 | static int sbmac_set_speed(struct sbmac_softc *s, enum sbmac_speed speed) |
1da177e4 LT |
1835 | { |
1836 | uint64_t cfg; | |
1837 | uint64_t framecfg; | |
1838 | ||
1839 | /* | |
1840 | * Save new current values | |
1841 | */ | |
74b0247f | 1842 | |
1da177e4 | 1843 | s->sbm_speed = speed; |
74b0247f | 1844 | |
1da177e4 LT |
1845 | if (s->sbm_state == sbmac_state_on) |
1846 | return 0; /* save for next restart */ | |
1847 | ||
1848 | /* | |
74b0247f | 1849 | * Read current register values |
1da177e4 | 1850 | */ |
74b0247f | 1851 | |
2039973a RB |
1852 | cfg = __raw_readq(s->sbm_maccfg); |
1853 | framecfg = __raw_readq(s->sbm_framecfg); | |
74b0247f | 1854 | |
1da177e4 LT |
1855 | /* |
1856 | * Mask out the stuff we want to change | |
1857 | */ | |
74b0247f | 1858 | |
1da177e4 LT |
1859 | cfg &= ~(M_MAC_BURST_EN | M_MAC_SPEED_SEL); |
1860 | framecfg &= ~(M_MAC_IFG_RX | M_MAC_IFG_TX | M_MAC_IFG_THRSH | | |
1861 | M_MAC_SLOT_SIZE); | |
74b0247f | 1862 | |
1da177e4 LT |
1863 | /* |
1864 | * Now add in the new bits | |
1865 | */ | |
74b0247f | 1866 | |
1da177e4 LT |
1867 | switch (speed) { |
1868 | case sbmac_speed_10: | |
1869 | framecfg |= V_MAC_IFG_RX_10 | | |
1870 | V_MAC_IFG_TX_10 | | |
1871 | K_MAC_IFG_THRSH_10 | | |
1872 | V_MAC_SLOT_SIZE_10; | |
1873 | cfg |= V_MAC_SPEED_SEL_10MBPS; | |
1874 | break; | |
74b0247f | 1875 | |
1da177e4 LT |
1876 | case sbmac_speed_100: |
1877 | framecfg |= V_MAC_IFG_RX_100 | | |
1878 | V_MAC_IFG_TX_100 | | |
1879 | V_MAC_IFG_THRSH_100 | | |
1880 | V_MAC_SLOT_SIZE_100; | |
1881 | cfg |= V_MAC_SPEED_SEL_100MBPS ; | |
1882 | break; | |
74b0247f | 1883 | |
1da177e4 LT |
1884 | case sbmac_speed_1000: |
1885 | framecfg |= V_MAC_IFG_RX_1000 | | |
1886 | V_MAC_IFG_TX_1000 | | |
1887 | V_MAC_IFG_THRSH_1000 | | |
1888 | V_MAC_SLOT_SIZE_1000; | |
1889 | cfg |= V_MAC_SPEED_SEL_1000MBPS | M_MAC_BURST_EN; | |
1890 | break; | |
74b0247f | 1891 | |
1da177e4 LT |
1892 | default: |
1893 | return 0; | |
1894 | } | |
74b0247f | 1895 | |
1da177e4 | 1896 | /* |
74b0247f | 1897 | * Send the bits back to the hardware |
1da177e4 | 1898 | */ |
74b0247f | 1899 | |
2039973a RB |
1900 | __raw_writeq(framecfg, s->sbm_framecfg); |
1901 | __raw_writeq(cfg, s->sbm_maccfg); | |
74b0247f | 1902 | |
1da177e4 LT |
1903 | return 1; |
1904 | } | |
1905 | ||
1906 | /********************************************************************** | |
1907 | * SBMAC_SET_DUPLEX(s,duplex,fc) | |
74b0247f | 1908 | * |
1da177e4 LT |
1909 | * Set Ethernet duplex and flow control options for this MAC |
1910 | * Warning: must be called when MAC is off! | |
74b0247f RB |
1911 | * |
1912 | * Input parameters: | |
1da177e4 | 1913 | * s - sbmac structure |
73d73969 MR |
1914 | * duplex - duplex setting (see enum sbmac_duplex) |
1915 | * fc - flow control setting (see enum sbmac_fc) | |
74b0247f | 1916 | * |
1da177e4 LT |
1917 | * Return value: |
1918 | * 1 if ok | |
1919 | * 0 if an invalid parameter combination was specified | |
1920 | ********************************************************************* */ | |
1921 | ||
73d73969 MR |
1922 | static int sbmac_set_duplex(struct sbmac_softc *s, enum sbmac_duplex duplex, |
1923 | enum sbmac_fc fc) | |
1da177e4 LT |
1924 | { |
1925 | uint64_t cfg; | |
74b0247f | 1926 | |
1da177e4 LT |
1927 | /* |
1928 | * Save new current values | |
1929 | */ | |
74b0247f | 1930 | |
1da177e4 LT |
1931 | s->sbm_duplex = duplex; |
1932 | s->sbm_fc = fc; | |
74b0247f | 1933 | |
1da177e4 LT |
1934 | if (s->sbm_state == sbmac_state_on) |
1935 | return 0; /* save for next restart */ | |
74b0247f | 1936 | |
1da177e4 | 1937 | /* |
74b0247f | 1938 | * Read current register values |
1da177e4 | 1939 | */ |
74b0247f | 1940 | |
2039973a | 1941 | cfg = __raw_readq(s->sbm_maccfg); |
74b0247f | 1942 | |
1da177e4 LT |
1943 | /* |
1944 | * Mask off the stuff we're about to change | |
1945 | */ | |
74b0247f | 1946 | |
1da177e4 | 1947 | cfg &= ~(M_MAC_FC_SEL | M_MAC_FC_CMD | M_MAC_HDX_EN); |
74b0247f RB |
1948 | |
1949 | ||
1da177e4 LT |
1950 | switch (duplex) { |
1951 | case sbmac_duplex_half: | |
1952 | switch (fc) { | |
1953 | case sbmac_fc_disabled: | |
1954 | cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_DISABLED; | |
1955 | break; | |
74b0247f | 1956 | |
1da177e4 LT |
1957 | case sbmac_fc_collision: |
1958 | cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENABLED; | |
1959 | break; | |
74b0247f | 1960 | |
1da177e4 LT |
1961 | case sbmac_fc_carrier: |
1962 | cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENAB_FALSECARR; | |
1963 | break; | |
74b0247f | 1964 | |
1da177e4 LT |
1965 | case sbmac_fc_frame: /* not valid in half duplex */ |
1966 | default: /* invalid selection */ | |
1967 | return 0; | |
1968 | } | |
1969 | break; | |
74b0247f | 1970 | |
1da177e4 LT |
1971 | case sbmac_duplex_full: |
1972 | switch (fc) { | |
1973 | case sbmac_fc_disabled: | |
1974 | cfg |= V_MAC_FC_CMD_DISABLED; | |
1975 | break; | |
74b0247f | 1976 | |
1da177e4 LT |
1977 | case sbmac_fc_frame: |
1978 | cfg |= V_MAC_FC_CMD_ENABLED; | |
1979 | break; | |
74b0247f | 1980 | |
1da177e4 LT |
1981 | case sbmac_fc_collision: /* not valid in full duplex */ |
1982 | case sbmac_fc_carrier: /* not valid in full duplex */ | |
1da177e4 LT |
1983 | default: |
1984 | return 0; | |
1985 | } | |
1986 | break; | |
f5279ffd MR |
1987 | default: |
1988 | return 0; | |
1da177e4 | 1989 | } |
74b0247f | 1990 | |
1da177e4 | 1991 | /* |
74b0247f | 1992 | * Send the bits back to the hardware |
1da177e4 | 1993 | */ |
74b0247f | 1994 | |
2039973a | 1995 | __raw_writeq(cfg, s->sbm_maccfg); |
74b0247f | 1996 | |
1da177e4 LT |
1997 | return 1; |
1998 | } | |
1999 | ||
2000 | ||
2001 | ||
2002 | ||
2003 | /********************************************************************** | |
2004 | * SBMAC_INTR() | |
74b0247f | 2005 | * |
1da177e4 | 2006 | * Interrupt handler for MAC interrupts |
74b0247f RB |
2007 | * |
2008 | * Input parameters: | |
1da177e4 | 2009 | * MAC structure |
74b0247f | 2010 | * |
1da177e4 LT |
2011 | * Return value: |
2012 | * nothing | |
2013 | ********************************************************************* */ | |
7d12e780 | 2014 | static irqreturn_t sbmac_intr(int irq,void *dev_instance) |
1da177e4 LT |
2015 | { |
2016 | struct net_device *dev = (struct net_device *) dev_instance; | |
2017 | struct sbmac_softc *sc = netdev_priv(dev); | |
2018 | uint64_t isr; | |
2019 | int handled = 0; | |
2020 | ||
693aa947 MM |
2021 | /* |
2022 | * Read the ISR (this clears the bits in the real | |
2023 | * register, except for counter addr) | |
2024 | */ | |
74b0247f | 2025 | |
693aa947 | 2026 | isr = __raw_readq(sc->sbm_isr) & ~M_MAC_COUNTER_ADDR; |
1da177e4 | 2027 | |
693aa947 MM |
2028 | if (isr == 0) |
2029 | return IRQ_RETVAL(0); | |
2030 | handled = 1; | |
74b0247f | 2031 | |
693aa947 MM |
2032 | /* |
2033 | * Transmits on channel 0 | |
2034 | */ | |
74b0247f | 2035 | |
bea3348e | 2036 | if (isr & (M_MAC_INT_CHANNEL << S_MAC_TX_CH0)) |
693aa947 | 2037 | sbdma_tx_process(sc,&(sc->sbm_txdma), 0); |
74b0247f | 2038 | |
693aa947 | 2039 | if (isr & (M_MAC_INT_CHANNEL << S_MAC_RX_CH0)) { |
bea3348e | 2040 | if (netif_rx_schedule_prep(dev, &sc->napi)) { |
693aa947 | 2041 | __raw_writeq(0, sc->sbm_imr); |
bea3348e | 2042 | __netif_rx_schedule(dev, &sc->napi); |
693aa947 MM |
2043 | /* Depend on the exit from poll to reenable intr */ |
2044 | } | |
2045 | else { | |
2046 | /* may leave some packets behind */ | |
2047 | sbdma_rx_process(sc,&(sc->sbm_rxdma), | |
2048 | SBMAC_MAX_RXDESCR * 2, 0); | |
1da177e4 LT |
2049 | } |
2050 | } | |
2051 | return IRQ_RETVAL(handled); | |
2052 | } | |
2053 | ||
1da177e4 LT |
2054 | /********************************************************************** |
2055 | * SBMAC_START_TX(skb,dev) | |
74b0247f RB |
2056 | * |
2057 | * Start output on the specified interface. Basically, we | |
1da177e4 LT |
2058 | * queue as many buffers as we can until the ring fills up, or |
2059 | * we run off the end of the queue, whichever comes first. | |
74b0247f RB |
2060 | * |
2061 | * Input parameters: | |
2062 | * | |
2063 | * | |
1da177e4 LT |
2064 | * Return value: |
2065 | * nothing | |
2066 | ********************************************************************* */ | |
2067 | static int sbmac_start_tx(struct sk_buff *skb, struct net_device *dev) | |
2068 | { | |
2069 | struct sbmac_softc *sc = netdev_priv(dev); | |
74b0247f | 2070 | |
1da177e4 LT |
2071 | /* lock eth irq */ |
2072 | spin_lock_irq (&sc->sbm_lock); | |
74b0247f | 2073 | |
1da177e4 | 2074 | /* |
74b0247f | 2075 | * Put the buffer on the transmit ring. If we |
1da177e4 LT |
2076 | * don't have room, stop the queue. |
2077 | */ | |
74b0247f | 2078 | |
1da177e4 LT |
2079 | if (sbdma_add_txbuffer(&(sc->sbm_txdma),skb)) { |
2080 | /* XXX save skb that we could not send */ | |
2081 | netif_stop_queue(dev); | |
2082 | spin_unlock_irq(&sc->sbm_lock); | |
2083 | ||
2084 | return 1; | |
2085 | } | |
74b0247f | 2086 | |
1da177e4 | 2087 | dev->trans_start = jiffies; |
74b0247f | 2088 | |
1da177e4 | 2089 | spin_unlock_irq (&sc->sbm_lock); |
74b0247f | 2090 | |
1da177e4 LT |
2091 | return 0; |
2092 | } | |
2093 | ||
2094 | /********************************************************************** | |
2095 | * SBMAC_SETMULTI(sc) | |
74b0247f | 2096 | * |
1da177e4 LT |
2097 | * Reprogram the multicast table into the hardware, given |
2098 | * the list of multicasts associated with the interface | |
2099 | * structure. | |
74b0247f RB |
2100 | * |
2101 | * Input parameters: | |
1da177e4 | 2102 | * sc - softc |
74b0247f | 2103 | * |
1da177e4 LT |
2104 | * Return value: |
2105 | * nothing | |
2106 | ********************************************************************* */ | |
2107 | ||
2108 | static void sbmac_setmulti(struct sbmac_softc *sc) | |
2109 | { | |
2110 | uint64_t reg; | |
73d73969 | 2111 | void __iomem *port; |
1da177e4 LT |
2112 | int idx; |
2113 | struct dev_mc_list *mclist; | |
2114 | struct net_device *dev = sc->sbm_dev; | |
74b0247f RB |
2115 | |
2116 | /* | |
1da177e4 LT |
2117 | * Clear out entire multicast table. We do this by nuking |
2118 | * the entire hash table and all the direct matches except | |
74b0247f | 2119 | * the first one, which is used for our station address |
1da177e4 | 2120 | */ |
74b0247f | 2121 | |
1da177e4 LT |
2122 | for (idx = 1; idx < MAC_ADDR_COUNT; idx++) { |
2123 | port = sc->sbm_base + R_MAC_ADDR_BASE+(idx*sizeof(uint64_t)); | |
2039973a | 2124 | __raw_writeq(0, port); |
1da177e4 | 2125 | } |
74b0247f | 2126 | |
1da177e4 LT |
2127 | for (idx = 0; idx < MAC_HASH_COUNT; idx++) { |
2128 | port = sc->sbm_base + R_MAC_HASH_BASE+(idx*sizeof(uint64_t)); | |
2039973a | 2129 | __raw_writeq(0, port); |
1da177e4 | 2130 | } |
74b0247f | 2131 | |
1da177e4 LT |
2132 | /* |
2133 | * Clear the filter to say we don't want any multicasts. | |
2134 | */ | |
74b0247f | 2135 | |
2039973a | 2136 | reg = __raw_readq(sc->sbm_rxfilter); |
1da177e4 | 2137 | reg &= ~(M_MAC_MCAST_INV | M_MAC_MCAST_EN); |
2039973a | 2138 | __raw_writeq(reg, sc->sbm_rxfilter); |
74b0247f | 2139 | |
1da177e4 | 2140 | if (dev->flags & IFF_ALLMULTI) { |
74b0247f RB |
2141 | /* |
2142 | * Enable ALL multicasts. Do this by inverting the | |
2143 | * multicast enable bit. | |
1da177e4 | 2144 | */ |
2039973a | 2145 | reg = __raw_readq(sc->sbm_rxfilter); |
1da177e4 | 2146 | reg |= (M_MAC_MCAST_INV | M_MAC_MCAST_EN); |
2039973a | 2147 | __raw_writeq(reg, sc->sbm_rxfilter); |
1da177e4 LT |
2148 | return; |
2149 | } | |
1da177e4 | 2150 | |
74b0247f RB |
2151 | |
2152 | /* | |
1da177e4 LT |
2153 | * Progam new multicast entries. For now, only use the |
2154 | * perfect filter. In the future we'll need to use the | |
2155 | * hash filter if the perfect filter overflows | |
2156 | */ | |
74b0247f | 2157 | |
1da177e4 LT |
2158 | /* XXX only using perfect filter for now, need to use hash |
2159 | * XXX if the table overflows */ | |
74b0247f | 2160 | |
1da177e4 LT |
2161 | idx = 1; /* skip station address */ |
2162 | mclist = dev->mc_list; | |
2163 | while (mclist && (idx < MAC_ADDR_COUNT)) { | |
2164 | reg = sbmac_addr2reg(mclist->dmi_addr); | |
2165 | port = sc->sbm_base + R_MAC_ADDR_BASE+(idx * sizeof(uint64_t)); | |
2039973a | 2166 | __raw_writeq(reg, port); |
1da177e4 LT |
2167 | idx++; |
2168 | mclist = mclist->next; | |
2169 | } | |
74b0247f RB |
2170 | |
2171 | /* | |
1da177e4 | 2172 | * Enable the "accept multicast bits" if we programmed at least one |
74b0247f | 2173 | * multicast. |
1da177e4 | 2174 | */ |
74b0247f | 2175 | |
1da177e4 | 2176 | if (idx > 1) { |
2039973a | 2177 | reg = __raw_readq(sc->sbm_rxfilter); |
1da177e4 | 2178 | reg |= M_MAC_MCAST_EN; |
2039973a | 2179 | __raw_writeq(reg, sc->sbm_rxfilter); |
1da177e4 LT |
2180 | } |
2181 | } | |
2182 | ||
f90fdc3c | 2183 | #if defined(SBMAC_ETH0_HWADDR) || defined(SBMAC_ETH1_HWADDR) || defined(SBMAC_ETH2_HWADDR) || defined(SBMAC_ETH3_HWADDR) |
1da177e4 LT |
2184 | /********************************************************************** |
2185 | * SBMAC_PARSE_XDIGIT(str) | |
74b0247f | 2186 | * |
1da177e4 | 2187 | * Parse a hex digit, returning its value |
74b0247f RB |
2188 | * |
2189 | * Input parameters: | |
1da177e4 | 2190 | * str - character |
74b0247f | 2191 | * |
1da177e4 LT |
2192 | * Return value: |
2193 | * hex value, or -1 if invalid | |
2194 | ********************************************************************* */ | |
2195 | ||
2196 | static int sbmac_parse_xdigit(char str) | |
2197 | { | |
2198 | int digit; | |
74b0247f | 2199 | |
1da177e4 LT |
2200 | if ((str >= '0') && (str <= '9')) |
2201 | digit = str - '0'; | |
2202 | else if ((str >= 'a') && (str <= 'f')) | |
2203 | digit = str - 'a' + 10; | |
2204 | else if ((str >= 'A') && (str <= 'F')) | |
2205 | digit = str - 'A' + 10; | |
2206 | else | |
2207 | return -1; | |
74b0247f | 2208 | |
1da177e4 LT |
2209 | return digit; |
2210 | } | |
2211 | ||
2212 | /********************************************************************** | |
2213 | * SBMAC_PARSE_HWADDR(str,hwaddr) | |
74b0247f | 2214 | * |
1da177e4 LT |
2215 | * Convert a string in the form xx:xx:xx:xx:xx:xx into a 6-byte |
2216 | * Ethernet address. | |
74b0247f RB |
2217 | * |
2218 | * Input parameters: | |
1da177e4 LT |
2219 | * str - string |
2220 | * hwaddr - pointer to hardware address | |
74b0247f | 2221 | * |
1da177e4 LT |
2222 | * Return value: |
2223 | * 0 if ok, else -1 | |
2224 | ********************************************************************* */ | |
2225 | ||
2226 | static int sbmac_parse_hwaddr(char *str, unsigned char *hwaddr) | |
2227 | { | |
2228 | int digit1,digit2; | |
2229 | int idx = 6; | |
74b0247f | 2230 | |
1da177e4 LT |
2231 | while (*str && (idx > 0)) { |
2232 | digit1 = sbmac_parse_xdigit(*str); | |
2233 | if (digit1 < 0) | |
2234 | return -1; | |
2235 | str++; | |
2236 | if (!*str) | |
2237 | return -1; | |
74b0247f | 2238 | |
1da177e4 LT |
2239 | if ((*str == ':') || (*str == '-')) { |
2240 | digit2 = digit1; | |
2241 | digit1 = 0; | |
2242 | } | |
2243 | else { | |
2244 | digit2 = sbmac_parse_xdigit(*str); | |
2245 | if (digit2 < 0) | |
2246 | return -1; | |
2247 | str++; | |
2248 | } | |
74b0247f | 2249 | |
1da177e4 LT |
2250 | *hwaddr++ = (digit1 << 4) | digit2; |
2251 | idx--; | |
74b0247f | 2252 | |
1da177e4 LT |
2253 | if (*str == '-') |
2254 | str++; | |
2255 | if (*str == ':') | |
2256 | str++; | |
2257 | } | |
2258 | return 0; | |
2259 | } | |
2260 | #endif | |
2261 | ||
2262 | static int sb1250_change_mtu(struct net_device *_dev, int new_mtu) | |
2263 | { | |
2264 | if (new_mtu > ENET_PACKET_SIZE) | |
2265 | return -EINVAL; | |
2266 | _dev->mtu = new_mtu; | |
f5279ffd | 2267 | pr_info("changing the mtu to %d\n", new_mtu); |
1da177e4 LT |
2268 | return 0; |
2269 | } | |
2270 | ||
2271 | /********************************************************************** | |
2272 | * SBMAC_INIT(dev) | |
74b0247f | 2273 | * |
1da177e4 | 2274 | * Attach routine - init hardware and hook ourselves into linux |
74b0247f RB |
2275 | * |
2276 | * Input parameters: | |
1da177e4 | 2277 | * dev - net_device structure |
74b0247f | 2278 | * |
1da177e4 LT |
2279 | * Return value: |
2280 | * status | |
2281 | ********************************************************************* */ | |
2282 | ||
f5279ffd | 2283 | static int sbmac_init(struct platform_device *pldev, long long base) |
1da177e4 | 2284 | { |
f5279ffd MR |
2285 | struct net_device *dev = pldev->dev.driver_data; |
2286 | int idx = pldev->id; | |
2287 | struct sbmac_softc *sc = netdev_priv(dev); | |
1da177e4 LT |
2288 | unsigned char *eaddr; |
2289 | uint64_t ea_reg; | |
2290 | int i; | |
2291 | int err; | |
0795af57 | 2292 | DECLARE_MAC_BUF(mac); |
74b0247f | 2293 | |
1da177e4 LT |
2294 | sc->sbm_dev = dev; |
2295 | sc->sbe_idx = idx; | |
74b0247f | 2296 | |
1da177e4 | 2297 | eaddr = sc->sbm_hwaddr; |
74b0247f RB |
2298 | |
2299 | /* | |
1da177e4 LT |
2300 | * Read the ethernet address. The firwmare left this programmed |
2301 | * for us in the ethernet address register for each mac. | |
2302 | */ | |
74b0247f | 2303 | |
2039973a RB |
2304 | ea_reg = __raw_readq(sc->sbm_base + R_MAC_ETHERNET_ADDR); |
2305 | __raw_writeq(0, sc->sbm_base + R_MAC_ETHERNET_ADDR); | |
1da177e4 LT |
2306 | for (i = 0; i < 6; i++) { |
2307 | eaddr[i] = (uint8_t) (ea_reg & 0xFF); | |
2308 | ea_reg >>= 8; | |
2309 | } | |
74b0247f | 2310 | |
1da177e4 LT |
2311 | for (i = 0; i < 6; i++) { |
2312 | dev->dev_addr[i] = eaddr[i]; | |
2313 | } | |
74b0247f RB |
2314 | |
2315 | ||
1da177e4 | 2316 | /* |
74b0247f | 2317 | * Init packet size |
1da177e4 | 2318 | */ |
74b0247f | 2319 | |
1da177e4 LT |
2320 | sc->sbm_buffersize = ENET_PACKET_SIZE + SMP_CACHE_BYTES * 2 + ETHER_ALIGN; |
2321 | ||
74b0247f | 2322 | /* |
1da177e4 LT |
2323 | * Initialize context (get pointers to registers and stuff), then |
2324 | * allocate the memory for the descriptor tables. | |
2325 | */ | |
74b0247f | 2326 | |
1da177e4 | 2327 | sbmac_initctx(sc); |
74b0247f | 2328 | |
1da177e4 LT |
2329 | /* |
2330 | * Set up Linux device callins | |
2331 | */ | |
74b0247f | 2332 | |
1da177e4 | 2333 | spin_lock_init(&(sc->sbm_lock)); |
74b0247f | 2334 | |
1da177e4 LT |
2335 | dev->open = sbmac_open; |
2336 | dev->hard_start_xmit = sbmac_start_tx; | |
2337 | dev->stop = sbmac_close; | |
1da177e4 LT |
2338 | dev->set_multicast_list = sbmac_set_rx_mode; |
2339 | dev->do_ioctl = sbmac_mii_ioctl; | |
2340 | dev->tx_timeout = sbmac_tx_timeout; | |
2341 | dev->watchdog_timeo = TX_TIMEOUT; | |
bea3348e SH |
2342 | |
2343 | netif_napi_add(dev, &sc->napi, sbmac_poll, 16); | |
1da177e4 LT |
2344 | |
2345 | dev->change_mtu = sb1250_change_mtu; | |
d6830018 DS |
2346 | #ifdef CONFIG_NET_POLL_CONTROLLER |
2347 | dev->poll_controller = sbmac_netpoll; | |
2348 | #endif | |
1da177e4 | 2349 | |
f5279ffd MR |
2350 | dev->irq = UNIT_INT(idx); |
2351 | ||
1da177e4 LT |
2352 | /* This is needed for PASS2 for Rx H/W checksum feature */ |
2353 | sbmac_set_iphdr_offset(sc); | |
2354 | ||
2355 | err = register_netdev(dev); | |
f5279ffd MR |
2356 | if (err) { |
2357 | printk(KERN_ERR "%s.%d: unable to register netdev\n", | |
2358 | sbmac_string, idx); | |
2359 | sbmac_uninitctx(sc); | |
2360 | return err; | |
1da177e4 LT |
2361 | } |
2362 | ||
f5279ffd MR |
2363 | pr_info("%s.%d: registered as %s\n", sbmac_string, idx, dev->name); |
2364 | ||
2365 | if (sc->rx_hw_checksum == ENABLE) | |
2366 | pr_info("%s: enabling TCP rcv checksum\n", dev->name); | |
2367 | ||
1da177e4 LT |
2368 | /* |
2369 | * Display Ethernet address (this is called during the config | |
2370 | * process so we need to finish off the config message that | |
2371 | * was being displayed) | |
2372 | */ | |
f5279ffd MR |
2373 | pr_info("%s: SiByte Ethernet at 0x%08Lx, address: %s\n", |
2374 | dev->name, base, print_mac(mac, eaddr)); | |
1da177e4 | 2375 | |
f5279ffd MR |
2376 | sc->mii_bus.name = sbmac_mdio_string; |
2377 | sc->mii_bus.id = idx; | |
2378 | sc->mii_bus.priv = sc; | |
2379 | sc->mii_bus.read = sbmac_mii_read; | |
2380 | sc->mii_bus.write = sbmac_mii_write; | |
2381 | sc->mii_bus.irq = sc->phy_irq; | |
2382 | for (i = 0; i < PHY_MAX_ADDR; ++i) | |
2383 | sc->mii_bus.irq[i] = SBMAC_PHY_INT; | |
1da177e4 | 2384 | |
f5279ffd MR |
2385 | sc->mii_bus.dev = &pldev->dev; |
2386 | dev_set_drvdata(&pldev->dev, &sc->mii_bus); | |
1da177e4 | 2387 | |
f5279ffd | 2388 | return 0; |
1da177e4 LT |
2389 | } |
2390 | ||
2391 | ||
2392 | static int sbmac_open(struct net_device *dev) | |
2393 | { | |
2394 | struct sbmac_softc *sc = netdev_priv(dev); | |
f5279ffd | 2395 | int err; |
74b0247f | 2396 | |
f5279ffd MR |
2397 | if (debug > 1) |
2398 | pr_debug("%s: sbmac_open() irq %d.\n", dev->name, dev->irq); | |
74b0247f RB |
2399 | |
2400 | /* | |
1da177e4 LT |
2401 | * map/route interrupt (clear status first, in case something |
2402 | * weird is pending; we haven't initialized the mac registers | |
2403 | * yet) | |
2404 | */ | |
2405 | ||
2039973a | 2406 | __raw_readq(sc->sbm_isr); |
f5279ffd MR |
2407 | err = request_irq(dev->irq, &sbmac_intr, IRQF_SHARED, dev->name, dev); |
2408 | if (err) { | |
2409 | printk(KERN_ERR "%s: unable to get IRQ %d\n", dev->name, | |
2410 | dev->irq); | |
2411 | goto out_err; | |
2412 | } | |
1da177e4 | 2413 | |
59b81827 | 2414 | /* |
f5279ffd | 2415 | * Probe PHY address |
59b81827 | 2416 | */ |
f5279ffd MR |
2417 | err = mdiobus_register(&sc->mii_bus); |
2418 | if (err) { | |
2419 | printk(KERN_ERR "%s: unable to register MDIO bus\n", | |
2420 | dev->name); | |
2421 | goto out_unirq; | |
59b81827 RB |
2422 | } |
2423 | ||
f5279ffd MR |
2424 | sc->sbm_speed = sbmac_speed_none; |
2425 | sc->sbm_duplex = sbmac_duplex_none; | |
2426 | sc->sbm_fc = sbmac_fc_none; | |
2427 | sc->sbm_pause = -1; | |
2428 | sc->sbm_link = 0; | |
bea3348e | 2429 | |
1da177e4 | 2430 | /* |
f5279ffd | 2431 | * Attach to the PHY |
1da177e4 | 2432 | */ |
f5279ffd MR |
2433 | err = sbmac_mii_probe(dev); |
2434 | if (err) | |
2435 | goto out_unregister; | |
74b0247f | 2436 | |
1da177e4 LT |
2437 | /* |
2438 | * Turn on the channel | |
2439 | */ | |
2440 | ||
2441 | sbmac_set_channel_state(sc,sbmac_state_on); | |
74b0247f | 2442 | |
1da177e4 | 2443 | netif_start_queue(dev); |
74b0247f | 2444 | |
1da177e4 | 2445 | sbmac_set_rx_mode(dev); |
74b0247f | 2446 | |
f5279ffd MR |
2447 | phy_start(sc->phy_dev); |
2448 | ||
2449 | napi_enable(&sc->napi); | |
74b0247f | 2450 | |
1da177e4 | 2451 | return 0; |
f5279ffd MR |
2452 | |
2453 | out_unregister: | |
2454 | mdiobus_unregister(&sc->mii_bus); | |
2455 | ||
2456 | out_unirq: | |
2457 | free_irq(dev->irq, dev); | |
2458 | ||
2459 | out_err: | |
2460 | return err; | |
1da177e4 LT |
2461 | } |
2462 | ||
59b81827 RB |
2463 | static int sbmac_mii_probe(struct net_device *dev) |
2464 | { | |
f5279ffd MR |
2465 | struct sbmac_softc *sc = netdev_priv(dev); |
2466 | struct phy_device *phy_dev; | |
59b81827 | 2467 | int i; |
1da177e4 | 2468 | |
f5279ffd MR |
2469 | for (i = 0; i < PHY_MAX_ADDR; i++) { |
2470 | phy_dev = sc->mii_bus.phy_map[i]; | |
2471 | if (phy_dev) | |
2472 | break; | |
1da177e4 | 2473 | } |
f5279ffd MR |
2474 | if (!phy_dev) { |
2475 | printk(KERN_ERR "%s: no PHY found\n", dev->name); | |
2476 | return -ENXIO; | |
1da177e4 LT |
2477 | } |
2478 | ||
f5279ffd MR |
2479 | phy_dev = phy_connect(dev, phy_dev->dev.bus_id, &sbmac_mii_poll, 0, |
2480 | PHY_INTERFACE_MODE_GMII); | |
2481 | if (IS_ERR(phy_dev)) { | |
2482 | printk(KERN_ERR "%s: could not attach to PHY\n", dev->name); | |
2483 | return PTR_ERR(phy_dev); | |
1da177e4 LT |
2484 | } |
2485 | ||
f5279ffd MR |
2486 | /* Remove any features not supported by the controller */ |
2487 | phy_dev->supported &= SUPPORTED_10baseT_Half | | |
2488 | SUPPORTED_10baseT_Full | | |
2489 | SUPPORTED_100baseT_Half | | |
2490 | SUPPORTED_100baseT_Full | | |
2491 | SUPPORTED_1000baseT_Half | | |
2492 | SUPPORTED_1000baseT_Full | | |
2493 | SUPPORTED_Autoneg | | |
2494 | SUPPORTED_MII | | |
2495 | SUPPORTED_Pause | | |
2496 | SUPPORTED_Asym_Pause; | |
2497 | phy_dev->advertising = phy_dev->supported; | |
2498 | ||
2499 | pr_info("%s: attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n", | |
2500 | dev->name, phy_dev->drv->name, | |
2501 | phy_dev->dev.bus_id, phy_dev->irq); | |
2502 | ||
2503 | sc->phy_dev = phy_dev; | |
1da177e4 | 2504 | |
f5279ffd | 2505 | return 0; |
1da177e4 LT |
2506 | } |
2507 | ||
2508 | ||
f5279ffd | 2509 | static void sbmac_mii_poll(struct net_device *dev) |
1da177e4 | 2510 | { |
1da177e4 | 2511 | struct sbmac_softc *sc = netdev_priv(dev); |
f5279ffd MR |
2512 | struct phy_device *phy_dev = sc->phy_dev; |
2513 | unsigned long flags; | |
2514 | enum sbmac_fc fc; | |
2515 | int link_chg, speed_chg, duplex_chg, pause_chg, fc_chg; | |
2516 | ||
2517 | link_chg = (sc->sbm_link != phy_dev->link); | |
2518 | speed_chg = (sc->sbm_speed != phy_dev->speed); | |
2519 | duplex_chg = (sc->sbm_duplex != phy_dev->duplex); | |
2520 | pause_chg = (sc->sbm_pause != phy_dev->pause); | |
2521 | ||
2522 | if (!link_chg && !speed_chg && !duplex_chg && !pause_chg) | |
2523 | return; /* Hmmm... */ | |
2524 | ||
2525 | if (!phy_dev->link) { | |
2526 | if (link_chg) { | |
2527 | sc->sbm_link = phy_dev->link; | |
2528 | sc->sbm_speed = sbmac_speed_none; | |
2529 | sc->sbm_duplex = sbmac_duplex_none; | |
2530 | sc->sbm_fc = sbmac_fc_disabled; | |
2531 | sc->sbm_pause = -1; | |
2532 | pr_info("%s: link unavailable\n", dev->name); | |
2533 | } | |
2534 | return; | |
2535 | } | |
1da177e4 | 2536 | |
f5279ffd MR |
2537 | if (phy_dev->duplex == DUPLEX_FULL) { |
2538 | if (phy_dev->pause) | |
2539 | fc = sbmac_fc_frame; | |
2540 | else | |
2541 | fc = sbmac_fc_disabled; | |
2542 | } else | |
2543 | fc = sbmac_fc_collision; | |
2544 | fc_chg = (sc->sbm_fc != fc); | |
74b0247f | 2545 | |
f5279ffd MR |
2546 | pr_info("%s: link available: %dbase-%cD\n", dev->name, phy_dev->speed, |
2547 | phy_dev->duplex == DUPLEX_FULL ? 'F' : 'H'); | |
74b0247f | 2548 | |
f5279ffd | 2549 | spin_lock_irqsave(&sc->sbm_lock, flags); |
74b0247f | 2550 | |
f5279ffd MR |
2551 | sc->sbm_speed = phy_dev->speed; |
2552 | sc->sbm_duplex = phy_dev->duplex; | |
2553 | sc->sbm_fc = fc; | |
2554 | sc->sbm_pause = phy_dev->pause; | |
2555 | sc->sbm_link = phy_dev->link; | |
1da177e4 | 2556 | |
f5279ffd MR |
2557 | if ((speed_chg || duplex_chg || fc_chg) && |
2558 | sc->sbm_state != sbmac_state_off) { | |
2559 | /* | |
2560 | * something changed, restart the channel | |
2561 | */ | |
2562 | if (debug > 1) | |
2563 | pr_debug("%s: restarting channel " | |
2564 | "because PHY state changed\n", dev->name); | |
2565 | sbmac_channel_stop(sc); | |
2566 | sbmac_channel_start(sc); | |
1da177e4 | 2567 | } |
74b0247f | 2568 | |
f5279ffd | 2569 | spin_unlock_irqrestore(&sc->sbm_lock, flags); |
1da177e4 LT |
2570 | } |
2571 | ||
2572 | ||
2573 | static void sbmac_tx_timeout (struct net_device *dev) | |
2574 | { | |
2575 | struct sbmac_softc *sc = netdev_priv(dev); | |
74b0247f | 2576 | |
1da177e4 | 2577 | spin_lock_irq (&sc->sbm_lock); |
74b0247f RB |
2578 | |
2579 | ||
1da177e4 | 2580 | dev->trans_start = jiffies; |
09f75cd7 | 2581 | dev->stats.tx_errors++; |
74b0247f | 2582 | |
1da177e4 LT |
2583 | spin_unlock_irq (&sc->sbm_lock); |
2584 | ||
2585 | printk (KERN_WARNING "%s: Transmit timed out\n",dev->name); | |
2586 | } | |
2587 | ||
2588 | ||
2589 | ||
2590 | ||
1da177e4 LT |
2591 | static void sbmac_set_rx_mode(struct net_device *dev) |
2592 | { | |
2593 | unsigned long flags; | |
1da177e4 LT |
2594 | struct sbmac_softc *sc = netdev_priv(dev); |
2595 | ||
2596 | spin_lock_irqsave(&sc->sbm_lock, flags); | |
2597 | if ((dev->flags ^ sc->sbm_devflags) & IFF_PROMISC) { | |
2598 | /* | |
2599 | * Promiscuous changed. | |
2600 | */ | |
74b0247f RB |
2601 | |
2602 | if (dev->flags & IFF_PROMISC) { | |
1da177e4 LT |
2603 | sbmac_promiscuous_mode(sc,1); |
2604 | } | |
2605 | else { | |
1da177e4 LT |
2606 | sbmac_promiscuous_mode(sc,0); |
2607 | } | |
2608 | } | |
2609 | spin_unlock_irqrestore(&sc->sbm_lock, flags); | |
74b0247f | 2610 | |
1da177e4 LT |
2611 | /* |
2612 | * Program the multicasts. Do this every time. | |
2613 | */ | |
74b0247f | 2614 | |
1da177e4 | 2615 | sbmac_setmulti(sc); |
74b0247f | 2616 | |
1da177e4 LT |
2617 | } |
2618 | ||
2619 | static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) | |
2620 | { | |
2621 | struct sbmac_softc *sc = netdev_priv(dev); | |
74b0247f | 2622 | |
f5279ffd MR |
2623 | if (!netif_running(dev) || !sc->phy_dev) |
2624 | return -EINVAL; | |
74b0247f | 2625 | |
f5279ffd | 2626 | return phy_mii_ioctl(sc->phy_dev, if_mii(rq), cmd); |
1da177e4 LT |
2627 | } |
2628 | ||
2629 | static int sbmac_close(struct net_device *dev) | |
2630 | { | |
2631 | struct sbmac_softc *sc = netdev_priv(dev); | |
1da177e4 | 2632 | |
bea3348e SH |
2633 | napi_disable(&sc->napi); |
2634 | ||
f5279ffd | 2635 | phy_stop(sc->phy_dev); |
1da177e4 | 2636 | |
f5279ffd | 2637 | sbmac_set_channel_state(sc, sbmac_state_off); |
1da177e4 LT |
2638 | |
2639 | netif_stop_queue(dev); | |
2640 | ||
f5279ffd MR |
2641 | if (debug > 1) |
2642 | pr_debug("%s: Shutting down ethercard\n", dev->name); | |
1da177e4 | 2643 | |
f5279ffd MR |
2644 | phy_disconnect(sc->phy_dev); |
2645 | sc->phy_dev = NULL; | |
2646 | ||
2647 | mdiobus_unregister(&sc->mii_bus); | |
1da177e4 | 2648 | |
f5279ffd | 2649 | free_irq(dev->irq, dev); |
1da177e4 LT |
2650 | |
2651 | sbdma_emptyring(&(sc->sbm_txdma)); | |
2652 | sbdma_emptyring(&(sc->sbm_rxdma)); | |
74b0247f | 2653 | |
1da177e4 LT |
2654 | return 0; |
2655 | } | |
2656 | ||
bea3348e | 2657 | static int sbmac_poll(struct napi_struct *napi, int budget) |
693aa947 | 2658 | { |
bea3348e SH |
2659 | struct sbmac_softc *sc = container_of(napi, struct sbmac_softc, napi); |
2660 | struct net_device *dev = sc->sbm_dev; | |
693aa947 | 2661 | int work_done; |
1da177e4 | 2662 | |
bea3348e | 2663 | work_done = sbdma_rx_process(sc, &(sc->sbm_rxdma), budget, 1); |
693aa947 MM |
2664 | sbdma_tx_process(sc, &(sc->sbm_txdma), 1); |
2665 | ||
bea3348e SH |
2666 | if (work_done < budget) { |
2667 | netif_rx_complete(dev, napi); | |
693aa947 MM |
2668 | |
2669 | #ifdef CONFIG_SBMAC_COALESCE | |
2670 | __raw_writeq(((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) | | |
2671 | ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0), | |
2672 | sc->sbm_imr); | |
2673 | #else | |
2674 | __raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) | | |
2675 | (M_MAC_INT_CHANNEL << S_MAC_RX_CH0), sc->sbm_imr); | |
2676 | #endif | |
2677 | } | |
2678 | ||
bea3348e | 2679 | return work_done; |
693aa947 | 2680 | } |
1da177e4 | 2681 | |
f5279ffd MR |
2682 | |
2683 | static int __init sbmac_probe(struct platform_device *pldev) | |
2684 | { | |
2685 | struct net_device *dev; | |
2686 | struct sbmac_softc *sc; | |
2687 | void __iomem *sbm_base; | |
2688 | struct resource *res; | |
2689 | u64 sbmac_orig_hwaddr; | |
2690 | int err; | |
2691 | ||
2692 | res = platform_get_resource(pldev, IORESOURCE_MEM, 0); | |
2693 | BUG_ON(!res); | |
2694 | sbm_base = ioremap_nocache(res->start, res->end - res->start + 1); | |
2695 | if (!sbm_base) { | |
2696 | printk(KERN_ERR "%s: unable to map device registers\n", | |
2697 | pldev->dev.bus_id); | |
2698 | err = -ENOMEM; | |
2699 | goto out_out; | |
2700 | } | |
2701 | ||
2702 | /* | |
2703 | * The R_MAC_ETHERNET_ADDR register will be set to some nonzero | |
2704 | * value for us by the firmware if we're going to use this MAC. | |
2705 | * If we find a zero, skip this MAC. | |
2706 | */ | |
2707 | sbmac_orig_hwaddr = __raw_readq(sbm_base + R_MAC_ETHERNET_ADDR); | |
2708 | pr_debug("%s: %sconfiguring MAC at 0x%08Lx\n", pldev->dev.bus_id, | |
2709 | sbmac_orig_hwaddr ? "" : "not ", (long long)res->start); | |
2710 | if (sbmac_orig_hwaddr == 0) { | |
2711 | err = 0; | |
2712 | goto out_unmap; | |
2713 | } | |
2714 | ||
2715 | /* | |
2716 | * Okay, cool. Initialize this MAC. | |
2717 | */ | |
2718 | dev = alloc_etherdev(sizeof(struct sbmac_softc)); | |
2719 | if (!dev) { | |
2720 | printk(KERN_ERR "%s: unable to allocate etherdev\n", | |
2721 | pldev->dev.bus_id); | |
2722 | err = -ENOMEM; | |
2723 | goto out_unmap; | |
2724 | } | |
2725 | ||
2726 | pldev->dev.driver_data = dev; | |
2727 | SET_NETDEV_DEV(dev, &pldev->dev); | |
2728 | ||
2729 | sc = netdev_priv(dev); | |
2730 | sc->sbm_base = sbm_base; | |
2731 | ||
2732 | err = sbmac_init(pldev, res->start); | |
2733 | if (err) | |
2734 | goto out_kfree; | |
2735 | ||
2736 | return 0; | |
2737 | ||
2738 | out_kfree: | |
2739 | free_netdev(dev); | |
2740 | __raw_writeq(sbmac_orig_hwaddr, sbm_base + R_MAC_ETHERNET_ADDR); | |
2741 | ||
2742 | out_unmap: | |
2743 | iounmap(sbm_base); | |
2744 | ||
2745 | out_out: | |
2746 | return err; | |
2747 | } | |
2748 | ||
2749 | static int __exit sbmac_remove(struct platform_device *pldev) | |
2750 | { | |
2751 | struct net_device *dev = pldev->dev.driver_data; | |
2752 | struct sbmac_softc *sc = netdev_priv(dev); | |
2753 | ||
2754 | unregister_netdev(dev); | |
2755 | sbmac_uninitctx(sc); | |
2756 | iounmap(sc->sbm_base); | |
2757 | free_netdev(dev); | |
2758 | ||
2759 | return 0; | |
2760 | } | |
2761 | ||
2762 | ||
2763 | static struct platform_device **sbmac_pldev; | |
2764 | static int sbmac_max_units; | |
2765 | ||
f90fdc3c | 2766 | #if defined(SBMAC_ETH0_HWADDR) || defined(SBMAC_ETH1_HWADDR) || defined(SBMAC_ETH2_HWADDR) || defined(SBMAC_ETH3_HWADDR) |
f5279ffd | 2767 | static void __init sbmac_setup_hwaddr(int idx, char *addr) |
1da177e4 | 2768 | { |
f5279ffd MR |
2769 | void __iomem *sbm_base; |
2770 | unsigned long start, end; | |
1da177e4 LT |
2771 | uint8_t eaddr[6]; |
2772 | uint64_t val; | |
1da177e4 | 2773 | |
f5279ffd MR |
2774 | if (idx >= sbmac_max_units) |
2775 | return; | |
2776 | ||
2777 | start = A_MAC_CHANNEL_BASE(idx); | |
2778 | end = A_MAC_CHANNEL_BASE(idx + 1) - 1; | |
2779 | ||
2780 | sbm_base = ioremap_nocache(start, end - start + 1); | |
2781 | if (!sbm_base) { | |
2782 | printk(KERN_ERR "%s: unable to map device registers\n", | |
2783 | sbmac_string); | |
2784 | return; | |
2785 | } | |
2786 | ||
2787 | sbmac_parse_hwaddr(addr, eaddr); | |
1da177e4 | 2788 | val = sbmac_addr2reg(eaddr); |
f5279ffd MR |
2789 | __raw_writeq(val, sbm_base + R_MAC_ETHERNET_ADDR); |
2790 | val = __raw_readq(sbm_base + R_MAC_ETHERNET_ADDR); | |
2791 | ||
2792 | iounmap(sbm_base); | |
1da177e4 LT |
2793 | } |
2794 | #endif | |
2795 | ||
f5279ffd MR |
2796 | static int __init sbmac_platform_probe_one(int idx) |
2797 | { | |
2798 | struct platform_device *pldev; | |
2799 | struct { | |
2800 | struct resource r; | |
2801 | char name[strlen(sbmac_pretty) + 4]; | |
2802 | } *res; | |
2803 | int err; | |
2804 | ||
2805 | res = kzalloc(sizeof(*res), GFP_KERNEL); | |
2806 | if (!res) { | |
2807 | printk(KERN_ERR "%s.%d: unable to allocate memory\n", | |
2808 | sbmac_string, idx); | |
2809 | err = -ENOMEM; | |
2810 | goto out_err; | |
2811 | } | |
2812 | ||
2813 | /* | |
2814 | * This is the base address of the MAC. | |
2815 | */ | |
2816 | snprintf(res->name, sizeof(res->name), "%s %d", sbmac_pretty, idx); | |
2817 | res->r.name = res->name; | |
2818 | res->r.flags = IORESOURCE_MEM; | |
2819 | res->r.start = A_MAC_CHANNEL_BASE(idx); | |
2820 | res->r.end = A_MAC_CHANNEL_BASE(idx + 1) - 1; | |
2821 | ||
2822 | pldev = platform_device_register_simple(sbmac_string, idx, &res->r, 1); | |
2823 | if (IS_ERR(pldev)) { | |
2824 | printk(KERN_ERR "%s.%d: unable to register platform device\n", | |
2825 | sbmac_string, idx); | |
2826 | err = PTR_ERR(pldev); | |
2827 | goto out_kfree; | |
2828 | } | |
2829 | ||
2830 | if (!pldev->dev.driver) { | |
2831 | err = 0; /* No hardware at this address. */ | |
2832 | goto out_unregister; | |
2833 | } | |
2834 | ||
2835 | sbmac_pldev[idx] = pldev; | |
2836 | return 0; | |
2837 | ||
2838 | out_unregister: | |
2839 | platform_device_unregister(pldev); | |
1da177e4 | 2840 | |
f5279ffd MR |
2841 | out_kfree: |
2842 | kfree(res); | |
2843 | ||
2844 | out_err: | |
2845 | return err; | |
2846 | } | |
2847 | ||
2848 | static void __init sbmac_platform_probe(void) | |
1da177e4 | 2849 | { |
f5279ffd | 2850 | int i; |
74b0247f | 2851 | |
f90fdc3c | 2852 | /* Set the number of available units based on the SOC type. */ |
1da177e4 LT |
2853 | switch (soc_type) { |
2854 | case K_SYS_SOC_TYPE_BCM1250: | |
2855 | case K_SYS_SOC_TYPE_BCM1250_ALT: | |
f5279ffd | 2856 | sbmac_max_units = 3; |
1da177e4 LT |
2857 | break; |
2858 | case K_SYS_SOC_TYPE_BCM1120: | |
2859 | case K_SYS_SOC_TYPE_BCM1125: | |
2860 | case K_SYS_SOC_TYPE_BCM1125H: | |
f5279ffd MR |
2861 | case K_SYS_SOC_TYPE_BCM1250_ALT2: /* Hybrid */ |
2862 | sbmac_max_units = 2; | |
1da177e4 | 2863 | break; |
f90fdc3c RB |
2864 | case K_SYS_SOC_TYPE_BCM1x55: |
2865 | case K_SYS_SOC_TYPE_BCM1x80: | |
f5279ffd | 2866 | sbmac_max_units = 4; |
f90fdc3c | 2867 | break; |
1da177e4 | 2868 | default: |
f5279ffd | 2869 | return; /* none */ |
1da177e4 | 2870 | } |
1da177e4 | 2871 | |
f90fdc3c RB |
2872 | /* |
2873 | * For bringup when not using the firmware, we can pre-fill | |
2874 | * the MAC addresses using the environment variables | |
2875 | * specified in this file (or maybe from the config file?) | |
2876 | */ | |
2877 | #ifdef SBMAC_ETH0_HWADDR | |
f5279ffd | 2878 | sbmac_setup_hwaddr(0, SBMAC_ETH0_HWADDR); |
f90fdc3c RB |
2879 | #endif |
2880 | #ifdef SBMAC_ETH1_HWADDR | |
f5279ffd | 2881 | sbmac_setup_hwaddr(1, SBMAC_ETH1_HWADDR); |
f90fdc3c RB |
2882 | #endif |
2883 | #ifdef SBMAC_ETH2_HWADDR | |
f5279ffd | 2884 | sbmac_setup_hwaddr(2, SBMAC_ETH2_HWADDR); |
f90fdc3c RB |
2885 | #endif |
2886 | #ifdef SBMAC_ETH3_HWADDR | |
f5279ffd | 2887 | sbmac_setup_hwaddr(3, SBMAC_ETH3_HWADDR); |
f90fdc3c RB |
2888 | #endif |
2889 | ||
f5279ffd MR |
2890 | sbmac_pldev = kcalloc(sbmac_max_units, sizeof(*sbmac_pldev), |
2891 | GFP_KERNEL); | |
2892 | if (!sbmac_pldev) { | |
2893 | printk(KERN_ERR "%s: unable to allocate memory\n", | |
2894 | sbmac_string); | |
2895 | return; | |
2896 | } | |
2897 | ||
f90fdc3c RB |
2898 | /* |
2899 | * Walk through the Ethernet controllers and find | |
2900 | * those who have their MAC addresses set. | |
2901 | */ | |
f5279ffd MR |
2902 | for (i = 0; i < sbmac_max_units; i++) |
2903 | if (sbmac_platform_probe_one(i)) | |
2904 | break; | |
2905 | } | |
1da177e4 | 2906 | |
1da177e4 | 2907 | |
f5279ffd MR |
2908 | static void __exit sbmac_platform_cleanup(void) |
2909 | { | |
2910 | int i; | |
1da177e4 | 2911 | |
f5279ffd MR |
2912 | for (i = 0; i < sbmac_max_units; i++) |
2913 | platform_device_unregister(sbmac_pldev[i]); | |
2914 | kfree(sbmac_pldev); | |
2915 | } | |
1da177e4 | 2916 | |
1da177e4 | 2917 | |
f5279ffd MR |
2918 | static struct platform_driver sbmac_driver = { |
2919 | .probe = sbmac_probe, | |
2920 | .remove = __exit_p(sbmac_remove), | |
2921 | .driver = { | |
2922 | .name = sbmac_string, | |
2923 | }, | |
2924 | }; | |
1da177e4 | 2925 | |
f5279ffd MR |
2926 | static int __init sbmac_init_module(void) |
2927 | { | |
2928 | int err; | |
1da177e4 | 2929 | |
f5279ffd MR |
2930 | err = platform_driver_register(&sbmac_driver); |
2931 | if (err) | |
2932 | return err; | |
1da177e4 | 2933 | |
f5279ffd | 2934 | sbmac_platform_probe(); |
1da177e4 | 2935 | |
f5279ffd MR |
2936 | return err; |
2937 | } | |
1da177e4 | 2938 | |
f5279ffd | 2939 | static void __exit sbmac_cleanup_module(void) |
1da177e4 | 2940 | { |
f5279ffd MR |
2941 | sbmac_platform_cleanup(); |
2942 | platform_driver_unregister(&sbmac_driver); | |
1da177e4 LT |
2943 | } |
2944 | ||
2945 | module_init(sbmac_init_module); | |
2946 | module_exit(sbmac_cleanup_module); |