2 * Copyright (C) 2001,2002,2003 Broadcom Corporation
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * This driver is designed for the Broadcom SiByte SOC built-in
20 * Ethernet controllers. Written by Mitch Lichtenberg at Broadcom Corp.
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/string.h>
25 #include <linux/timer.h>
26 #include <linux/errno.h>
27 #include <linux/ioport.h>
28 #include <linux/slab.h>
29 #include <linux/interrupt.h>
30 #include <linux/netdevice.h>
31 #include <linux/etherdevice.h>
32 #include <linux/skbuff.h>
33 #include <linux/init.h>
34 #include <linux/config.h>
35 #include <linux/bitops.h>
36 #include <asm/processor.h> /* Processor type for cache alignment. */
38 #include <asm/cache.h>
40 /* This is only here until the firmware is ready. In that case,
41 the firmware leaves the ethernet address in the register for us. */
42 #ifdef CONFIG_SIBYTE_STANDALONE
43 #define SBMAC_ETH0_HWADDR "40:00:00:00:01:00"
44 #define SBMAC_ETH1_HWADDR "40:00:00:00:01:01"
45 #define SBMAC_ETH2_HWADDR "40:00:00:00:01:02"
49 /* These identify the driver base version and may not be removed. */
51 static char version1[] __devinitdata =
52 "sb1250-mac.c:1.00 1/11/2001 Written by Mitch Lichtenberg\n";
56 /* Operational parameters that usually are not changed. */
58 #define CONFIG_SBMAC_COALESCE
60 #define MAX_UNITS 3 /* More are supported, limit only on options */
62 /* Time in jiffies before concluding the transmitter is hung. */
63 #define TX_TIMEOUT (2*HZ)
66 MODULE_AUTHOR("Mitch Lichtenberg (Broadcom Corp.)");
67 MODULE_DESCRIPTION("Broadcom SiByte SOC GB Ethernet driver");
69 /* A few user-configurable values which may be modified when a driver
72 /* 1 normal messages, 0 quiet .. 7 verbose. */
74 module_param(debug, int, S_IRUGO);
75 MODULE_PARM_DESC(debug, "Debug messages");
78 static int noisy_mii = 1;
79 module_param(noisy_mii, int, S_IRUGO);
80 MODULE_PARM_DESC(noisy_mii, "MII status messages");
82 /* Used to pass the media type, etc.
83 Both 'options[]' and 'full_duplex[]' should exist for driver
85 The media type is usually passed in 'options[]'.
88 static int options[MAX_UNITS] = {-1, -1, -1};
89 module_param_array(options, int, NULL, S_IRUGO);
90 MODULE_PARM_DESC(options, "1-" __MODULE_STRING(MAX_UNITS));
92 static int full_duplex[MAX_UNITS] = {-1, -1, -1};
93 module_param_array(full_duplex, int, NULL, S_IRUGO);
94 MODULE_PARM_DESC(full_duplex, "1-" __MODULE_STRING(MAX_UNITS));
97 #ifdef CONFIG_SBMAC_COALESCE
98 static int int_pktcnt = 0;
99 module_param(int_pktcnt, int, S_IRUGO);
100 MODULE_PARM_DESC(int_pktcnt, "Packet count");
102 static int int_timeout = 0;
103 module_param(int_timeout, int, S_IRUGO);
104 MODULE_PARM_DESC(int_timeout, "Timeout value");
107 #include <asm/sibyte/sb1250.h>
108 #include <asm/sibyte/sb1250_defs.h>
109 #include <asm/sibyte/sb1250_regs.h>
110 #include <asm/sibyte/sb1250_mac.h>
111 #include <asm/sibyte/sb1250_dma.h>
112 #include <asm/sibyte/sb1250_int.h>
113 #include <asm/sibyte/sb1250_scd.h>
116 /**********************************************************************
118 ********************************************************************* */
121 typedef unsigned long sbmac_port_t;
123 typedef enum { sbmac_speed_auto, sbmac_speed_10,
124 sbmac_speed_100, sbmac_speed_1000 } sbmac_speed_t;
126 typedef enum { sbmac_duplex_auto, sbmac_duplex_half,
127 sbmac_duplex_full } sbmac_duplex_t;
129 typedef enum { sbmac_fc_auto, sbmac_fc_disabled, sbmac_fc_frame,
130 sbmac_fc_collision, sbmac_fc_carrier } sbmac_fc_t;
132 typedef enum { sbmac_state_uninit, sbmac_state_off, sbmac_state_on,
133 sbmac_state_broken } sbmac_state_t;
136 /**********************************************************************
138 ********************************************************************* */
141 #define SBDMA_NEXTBUF(d,f) ((((d)->f+1) == (d)->sbdma_dscrtable_end) ? \
142 (d)->sbdma_dscrtable : (d)->f+1)
145 #define NUMCACHEBLKS(x) (((x)+SMP_CACHE_BYTES-1)/SMP_CACHE_BYTES)
147 #define SBMAC_READCSR(t) __raw_readq((unsigned long)t)
148 #define SBMAC_WRITECSR(t,v) __raw_writeq(v, (unsigned long)t)
151 #define SBMAC_MAX_TXDESCR 32
152 #define SBMAC_MAX_RXDESCR 32
154 #define ETHER_ALIGN 2
155 #define ETHER_ADDR_LEN 6
156 #define ENET_PACKET_SIZE 1518
157 /*#define ENET_PACKET_SIZE 9216 */
159 /**********************************************************************
160 * DMA Descriptor structure
161 ********************************************************************* */
163 typedef struct sbdmadscr_s {
168 typedef unsigned long paddr_t;
170 /**********************************************************************
171 * DMA Controller structure
172 ********************************************************************* */
174 typedef struct sbmacdma_s {
177 * This stuff is used to identify the channel and the registers
178 * associated with it.
181 struct sbmac_softc *sbdma_eth; /* back pointer to associated MAC */
182 int sbdma_channel; /* channel number */
183 int sbdma_txdir; /* direction (1=transmit) */
184 int sbdma_maxdescr; /* total # of descriptors in ring */
185 #ifdef CONFIG_SBMAC_COALESCE
186 int sbdma_int_pktcnt; /* # descriptors rx/tx before interrupt*/
187 int sbdma_int_timeout; /* # usec rx/tx interrupt */
190 sbmac_port_t sbdma_config0; /* DMA config register 0 */
191 sbmac_port_t sbdma_config1; /* DMA config register 1 */
192 sbmac_port_t sbdma_dscrbase; /* Descriptor base address */
193 sbmac_port_t sbdma_dscrcnt; /* Descriptor count register */
194 sbmac_port_t sbdma_curdscr; /* current descriptor address */
197 * This stuff is for maintenance of the ring
200 sbdmadscr_t *sbdma_dscrtable; /* base of descriptor table */
201 sbdmadscr_t *sbdma_dscrtable_end; /* end of descriptor table */
203 struct sk_buff **sbdma_ctxtable; /* context table, one per descr */
205 paddr_t sbdma_dscrtable_phys; /* and also the phys addr */
206 sbdmadscr_t *sbdma_addptr; /* next dscr for sw to add */
207 sbdmadscr_t *sbdma_remptr; /* next dscr for sw to remove */
211 /**********************************************************************
212 * Ethernet softc structure
213 ********************************************************************* */
218 * Linux-specific things
221 struct net_device *sbm_dev; /* pointer to linux device */
222 spinlock_t sbm_lock; /* spin lock */
223 struct timer_list sbm_timer; /* for monitoring MII */
224 struct net_device_stats sbm_stats;
225 int sbm_devflags; /* current device flags */
228 int sbm_phy_oldanlpar;
229 int sbm_phy_oldk1stsr;
230 int sbm_phy_oldlinkstat;
233 unsigned char sbm_phys[2];
236 * Controller-specific things
239 unsigned long sbm_base; /* MAC's base address */
240 sbmac_state_t sbm_state; /* current state */
242 sbmac_port_t sbm_macenable; /* MAC Enable Register */
243 sbmac_port_t sbm_maccfg; /* MAC Configuration Register */
244 sbmac_port_t sbm_fifocfg; /* FIFO configuration register */
245 sbmac_port_t sbm_framecfg; /* Frame configuration register */
246 sbmac_port_t sbm_rxfilter; /* receive filter register */
247 sbmac_port_t sbm_isr; /* Interrupt status register */
248 sbmac_port_t sbm_imr; /* Interrupt mask register */
249 sbmac_port_t sbm_mdio; /* MDIO register */
251 sbmac_speed_t sbm_speed; /* current speed */
252 sbmac_duplex_t sbm_duplex; /* current duplex */
253 sbmac_fc_t sbm_fc; /* current flow control setting */
255 unsigned char sbm_hwaddr[ETHER_ADDR_LEN];
257 sbmacdma_t sbm_txdma; /* for now, only use channel 0 */
258 sbmacdma_t sbm_rxdma;
264 /**********************************************************************
266 ********************************************************************* */
268 /**********************************************************************
270 ********************************************************************* */
272 static void sbdma_initctx(sbmacdma_t *d,
273 struct sbmac_softc *s,
277 static void sbdma_channel_start(sbmacdma_t *d, int rxtx);
278 static int sbdma_add_rcvbuffer(sbmacdma_t *d,struct sk_buff *m);
279 static int sbdma_add_txbuffer(sbmacdma_t *d,struct sk_buff *m);
280 static void sbdma_emptyring(sbmacdma_t *d);
281 static void sbdma_fillring(sbmacdma_t *d);
282 static void sbdma_rx_process(struct sbmac_softc *sc,sbmacdma_t *d);
283 static void sbdma_tx_process(struct sbmac_softc *sc,sbmacdma_t *d);
284 static int sbmac_initctx(struct sbmac_softc *s);
285 static void sbmac_channel_start(struct sbmac_softc *s);
286 static void sbmac_channel_stop(struct sbmac_softc *s);
287 static sbmac_state_t sbmac_set_channel_state(struct sbmac_softc *,sbmac_state_t);
288 static void sbmac_promiscuous_mode(struct sbmac_softc *sc,int onoff);
289 static uint64_t sbmac_addr2reg(unsigned char *ptr);
290 static irqreturn_t sbmac_intr(int irq,void *dev_instance,struct pt_regs *rgs);
291 static int sbmac_start_tx(struct sk_buff *skb, struct net_device *dev);
292 static void sbmac_setmulti(struct sbmac_softc *sc);
293 static int sbmac_init(struct net_device *dev, int idx);
294 static int sbmac_set_speed(struct sbmac_softc *s,sbmac_speed_t speed);
295 static int sbmac_set_duplex(struct sbmac_softc *s,sbmac_duplex_t duplex,sbmac_fc_t fc);
297 static int sbmac_open(struct net_device *dev);
298 static void sbmac_timer(unsigned long data);
299 static void sbmac_tx_timeout (struct net_device *dev);
300 static struct net_device_stats *sbmac_get_stats(struct net_device *dev);
301 static void sbmac_set_rx_mode(struct net_device *dev);
302 static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
303 static int sbmac_close(struct net_device *dev);
304 static int sbmac_mii_poll(struct sbmac_softc *s,int noisy);
306 static void sbmac_mii_sync(struct sbmac_softc *s);
307 static void sbmac_mii_senddata(struct sbmac_softc *s,unsigned int data, int bitcnt);
308 static unsigned int sbmac_mii_read(struct sbmac_softc *s,int phyaddr,int regidx);
309 static void sbmac_mii_write(struct sbmac_softc *s,int phyaddr,int regidx,
310 unsigned int regval);
313 /**********************************************************************
315 ********************************************************************* */
317 static uint64_t sbmac_orig_hwaddr[MAX_UNITS];
320 /**********************************************************************
322 ********************************************************************* */
324 #define MII_COMMAND_START 0x01
325 #define MII_COMMAND_READ 0x02
326 #define MII_COMMAND_WRITE 0x01
327 #define MII_COMMAND_ACK 0x02
329 #define BMCR_RESET 0x8000
330 #define BMCR_LOOPBACK 0x4000
331 #define BMCR_SPEED0 0x2000
332 #define BMCR_ANENABLE 0x1000
333 #define BMCR_POWERDOWN 0x0800
334 #define BMCR_ISOLATE 0x0400
335 #define BMCR_RESTARTAN 0x0200
336 #define BMCR_DUPLEX 0x0100
337 #define BMCR_COLTEST 0x0080
338 #define BMCR_SPEED1 0x0040
339 #define BMCR_SPEED1000 BMCR_SPEED1
340 #define BMCR_SPEED100 BMCR_SPEED0
341 #define BMCR_SPEED10 0
343 #define BMSR_100BT4 0x8000
344 #define BMSR_100BT_FDX 0x4000
345 #define BMSR_100BT_HDX 0x2000
346 #define BMSR_10BT_FDX 0x1000
347 #define BMSR_10BT_HDX 0x0800
348 #define BMSR_100BT2_FDX 0x0400
349 #define BMSR_100BT2_HDX 0x0200
350 #define BMSR_1000BT_XSR 0x0100
351 #define BMSR_PRESUP 0x0040
352 #define BMSR_ANCOMPLT 0x0020
353 #define BMSR_REMFAULT 0x0010
354 #define BMSR_AUTONEG 0x0008
355 #define BMSR_LINKSTAT 0x0004
356 #define BMSR_JABDETECT 0x0002
357 #define BMSR_EXTCAPAB 0x0001
359 #define PHYIDR1 0x2000
360 #define PHYIDR2 0x5C60
362 #define ANAR_NP 0x8000
363 #define ANAR_RF 0x2000
364 #define ANAR_ASYPAUSE 0x0800
365 #define ANAR_PAUSE 0x0400
366 #define ANAR_T4 0x0200
367 #define ANAR_TXFD 0x0100
368 #define ANAR_TXHD 0x0080
369 #define ANAR_10FD 0x0040
370 #define ANAR_10HD 0x0020
371 #define ANAR_PSB 0x0001
373 #define ANLPAR_NP 0x8000
374 #define ANLPAR_ACK 0x4000
375 #define ANLPAR_RF 0x2000
376 #define ANLPAR_ASYPAUSE 0x0800
377 #define ANLPAR_PAUSE 0x0400
378 #define ANLPAR_T4 0x0200
379 #define ANLPAR_TXFD 0x0100
380 #define ANLPAR_TXHD 0x0080
381 #define ANLPAR_10FD 0x0040
382 #define ANLPAR_10HD 0x0020
383 #define ANLPAR_PSB 0x0001 /* 802.3 */
385 #define ANER_PDF 0x0010
386 #define ANER_LPNPABLE 0x0008
387 #define ANER_NPABLE 0x0004
388 #define ANER_PAGERX 0x0002
389 #define ANER_LPANABLE 0x0001
391 #define ANNPTR_NP 0x8000
392 #define ANNPTR_MP 0x2000
393 #define ANNPTR_ACK2 0x1000
394 #define ANNPTR_TOGTX 0x0800
395 #define ANNPTR_CODE 0x0008
397 #define ANNPRR_NP 0x8000
398 #define ANNPRR_MP 0x2000
399 #define ANNPRR_ACK3 0x1000
400 #define ANNPRR_TOGTX 0x0800
401 #define ANNPRR_CODE 0x0008
403 #define K1TCR_TESTMODE 0x0000
404 #define K1TCR_MSMCE 0x1000
405 #define K1TCR_MSCV 0x0800
406 #define K1TCR_RPTR 0x0400
407 #define K1TCR_1000BT_FDX 0x200
408 #define K1TCR_1000BT_HDX 0x100
410 #define K1STSR_MSMCFLT 0x8000
411 #define K1STSR_MSCFGRES 0x4000
412 #define K1STSR_LRSTAT 0x2000
413 #define K1STSR_RRSTAT 0x1000
414 #define K1STSR_LP1KFD 0x0800
415 #define K1STSR_LP1KHD 0x0400
416 #define K1STSR_LPASMDIR 0x0200
418 #define K1SCR_1KX_FDX 0x8000
419 #define K1SCR_1KX_HDX 0x4000
420 #define K1SCR_1KT_FDX 0x2000
421 #define K1SCR_1KT_HDX 0x1000
423 #define STRAP_PHY1 0x0800
424 #define STRAP_NCMODE 0x0400
425 #define STRAP_MANMSCFG 0x0200
426 #define STRAP_ANENABLE 0x0100
427 #define STRAP_MSVAL 0x0080
428 #define STRAP_1KHDXADV 0x0010
429 #define STRAP_1KFDXADV 0x0008
430 #define STRAP_100ADV 0x0004
431 #define STRAP_SPEEDSEL 0x0000
432 #define STRAP_SPEED100 0x0001
434 #define PHYSUP_SPEED1000 0x10
435 #define PHYSUP_SPEED100 0x08
436 #define PHYSUP_SPEED10 0x00
437 #define PHYSUP_LINKUP 0x04
438 #define PHYSUP_FDX 0x02
440 #define MII_BMCR 0x00 /* Basic mode control register (rw) */
441 #define MII_BMSR 0x01 /* Basic mode status register (ro) */
442 #define MII_K1STSR 0x0A /* 1K Status Register (ro) */
443 #define MII_ANLPAR 0x05 /* Autonegotiation lnk partner abilities (rw) */
446 #define M_MAC_MDIO_DIR_OUTPUT 0 /* for clarity */
451 /**********************************************************************
454 * Synchronize with the MII - send a pattern of bits to the MII
455 * that will guarantee that it is ready to accept a command.
458 * s - sbmac structure
462 ********************************************************************* */
464 static void sbmac_mii_sync(struct sbmac_softc *s)
470 mac_mdio_genc = SBMAC_READCSR(s->sbm_mdio) & M_MAC_GENC;
472 bits = M_MAC_MDIO_DIR_OUTPUT | M_MAC_MDIO_OUT;
474 SBMAC_WRITECSR(s->sbm_mdio,bits | mac_mdio_genc);
476 for (cnt = 0; cnt < 32; cnt++) {
477 SBMAC_WRITECSR(s->sbm_mdio,bits | M_MAC_MDC | mac_mdio_genc);
478 SBMAC_WRITECSR(s->sbm_mdio,bits | mac_mdio_genc);
482 /**********************************************************************
483 * SBMAC_MII_SENDDATA(s,data,bitcnt)
485 * Send some bits to the MII. The bits to be sent are right-
486 * justified in the 'data' parameter.
489 * s - sbmac structure
490 * data - data to send
491 * bitcnt - number of bits to send
492 ********************************************************************* */
494 static void sbmac_mii_senddata(struct sbmac_softc *s,unsigned int data, int bitcnt)
498 unsigned int curmask;
501 mac_mdio_genc = SBMAC_READCSR(s->sbm_mdio) & M_MAC_GENC;
503 bits = M_MAC_MDIO_DIR_OUTPUT;
504 SBMAC_WRITECSR(s->sbm_mdio,bits | mac_mdio_genc);
506 curmask = 1 << (bitcnt - 1);
508 for (i = 0; i < bitcnt; i++) {
510 bits |= M_MAC_MDIO_OUT;
511 else bits &= ~M_MAC_MDIO_OUT;
512 SBMAC_WRITECSR(s->sbm_mdio,bits | mac_mdio_genc);
513 SBMAC_WRITECSR(s->sbm_mdio,bits | M_MAC_MDC | mac_mdio_genc);
514 SBMAC_WRITECSR(s->sbm_mdio,bits | mac_mdio_genc);
521 /**********************************************************************
522 * SBMAC_MII_READ(s,phyaddr,regidx)
524 * Read a PHY register.
527 * s - sbmac structure
528 * phyaddr - PHY's address
529 * regidx = index of register to read
532 * value read, or 0 if an error occurred.
533 ********************************************************************* */
535 static unsigned int sbmac_mii_read(struct sbmac_softc *s,int phyaddr,int regidx)
543 * Synchronize ourselves so that the PHY knows the next
544 * thing coming down is a command
550 * Send the data to the PHY. The sequence is
551 * a "start" command (2 bits)
552 * a "read" command (2 bits)
553 * the PHY addr (5 bits)
554 * the register index (5 bits)
557 sbmac_mii_senddata(s,MII_COMMAND_START, 2);
558 sbmac_mii_senddata(s,MII_COMMAND_READ, 2);
559 sbmac_mii_senddata(s,phyaddr, 5);
560 sbmac_mii_senddata(s,regidx, 5);
562 mac_mdio_genc = SBMAC_READCSR(s->sbm_mdio) & M_MAC_GENC;
565 * Switch the port around without a clock transition.
567 SBMAC_WRITECSR(s->sbm_mdio,M_MAC_MDIO_DIR_INPUT | mac_mdio_genc);
570 * Send out a clock pulse to signal we want the status
573 SBMAC_WRITECSR(s->sbm_mdio,
574 M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc);
575 SBMAC_WRITECSR(s->sbm_mdio,M_MAC_MDIO_DIR_INPUT | mac_mdio_genc);
578 * If an error occurred, the PHY will signal '1' back
580 error = SBMAC_READCSR(s->sbm_mdio) & M_MAC_MDIO_IN;
583 * Issue an 'idle' clock pulse, but keep the direction
586 SBMAC_WRITECSR(s->sbm_mdio,
587 M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc);
588 SBMAC_WRITECSR(s->sbm_mdio,M_MAC_MDIO_DIR_INPUT | mac_mdio_genc);
592 for (idx = 0; idx < 16; idx++) {
596 if (SBMAC_READCSR(s->sbm_mdio) & M_MAC_MDIO_IN)
600 SBMAC_WRITECSR(s->sbm_mdio,
601 M_MAC_MDIO_DIR_INPUT|M_MAC_MDC | mac_mdio_genc);
602 SBMAC_WRITECSR(s->sbm_mdio,
603 M_MAC_MDIO_DIR_INPUT | mac_mdio_genc);
606 /* Switch back to output */
607 SBMAC_WRITECSR(s->sbm_mdio,M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc);
615 /**********************************************************************
616 * SBMAC_MII_WRITE(s,phyaddr,regidx,regval)
618 * Write a value to a PHY register.
621 * s - sbmac structure
622 * phyaddr - PHY to use
623 * regidx - register within the PHY
624 * regval - data to write to register
628 ********************************************************************* */
630 static void sbmac_mii_write(struct sbmac_softc *s,int phyaddr,int regidx,
637 sbmac_mii_senddata(s,MII_COMMAND_START,2);
638 sbmac_mii_senddata(s,MII_COMMAND_WRITE,2);
639 sbmac_mii_senddata(s,phyaddr, 5);
640 sbmac_mii_senddata(s,regidx, 5);
641 sbmac_mii_senddata(s,MII_COMMAND_ACK,2);
642 sbmac_mii_senddata(s,regval,16);
644 mac_mdio_genc = SBMAC_READCSR(s->sbm_mdio) & M_MAC_GENC;
646 SBMAC_WRITECSR(s->sbm_mdio,M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc);
651 /**********************************************************************
652 * SBDMA_INITCTX(d,s,chan,txrx,maxdescr)
654 * Initialize a DMA channel context. Since there are potentially
655 * eight DMA channels per MAC, it's nice to do this in a standard
659 * d - sbmacdma_t structure (DMA channel context)
660 * s - sbmac_softc structure (pointer to a MAC)
661 * chan - channel number (0..1 right now)
662 * txrx - Identifies DMA_TX or DMA_RX for channel direction
663 * maxdescr - number of descriptors
667 ********************************************************************* */
669 static void sbdma_initctx(sbmacdma_t *d,
670 struct sbmac_softc *s,
676 * Save away interesting stuff in the structure
680 d->sbdma_channel = chan;
681 d->sbdma_txdir = txrx;
685 s->sbe_idx =(s->sbm_base - A_MAC_BASE_0)/MAC_SPACING;
688 SBMAC_WRITECSR(IOADDR(
689 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_BYTES)), 0);
690 SBMAC_WRITECSR(IOADDR(
691 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_COLLISIONS)), 0);
692 SBMAC_WRITECSR(IOADDR(
693 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_LATE_COL)), 0);
694 SBMAC_WRITECSR(IOADDR(
695 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_EX_COL)), 0);
696 SBMAC_WRITECSR(IOADDR(
697 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_FCS_ERROR)), 0);
698 SBMAC_WRITECSR(IOADDR(
699 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_ABORT)), 0);
700 SBMAC_WRITECSR(IOADDR(
701 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_BAD)), 0);
702 SBMAC_WRITECSR(IOADDR(
703 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_GOOD)), 0);
704 SBMAC_WRITECSR(IOADDR(
705 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_RUNT)), 0);
706 SBMAC_WRITECSR(IOADDR(
707 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_OVERSIZE)), 0);
708 SBMAC_WRITECSR(IOADDR(
709 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_BYTES)), 0);
710 SBMAC_WRITECSR(IOADDR(
711 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_MCAST)), 0);
712 SBMAC_WRITECSR(IOADDR(
713 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_BCAST)), 0);
714 SBMAC_WRITECSR(IOADDR(
715 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_BAD)), 0);
716 SBMAC_WRITECSR(IOADDR(
717 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_GOOD)), 0);
718 SBMAC_WRITECSR(IOADDR(
719 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_RUNT)), 0);
720 SBMAC_WRITECSR(IOADDR(
721 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_OVERSIZE)), 0);
722 SBMAC_WRITECSR(IOADDR(
723 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_FCS_ERROR)), 0);
724 SBMAC_WRITECSR(IOADDR(
725 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_LENGTH_ERROR)), 0);
726 SBMAC_WRITECSR(IOADDR(
727 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_CODE_ERROR)), 0);
728 SBMAC_WRITECSR(IOADDR(
729 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_ALIGN_ERROR)), 0);
732 * initialize register pointers
736 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG0);
738 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG1);
740 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_BASE);
742 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_CNT);
744 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CUR_DSCRADDR);
747 * Allocate memory for the ring
750 d->sbdma_maxdescr = maxdescr;
752 d->sbdma_dscrtable = (sbdmadscr_t *)
753 kmalloc(d->sbdma_maxdescr*sizeof(sbdmadscr_t), GFP_KERNEL);
755 memset(d->sbdma_dscrtable,0,d->sbdma_maxdescr*sizeof(sbdmadscr_t));
757 d->sbdma_dscrtable_end = d->sbdma_dscrtable + d->sbdma_maxdescr;
759 d->sbdma_dscrtable_phys = virt_to_phys(d->sbdma_dscrtable);
765 d->sbdma_ctxtable = (struct sk_buff **)
766 kmalloc(d->sbdma_maxdescr*sizeof(struct sk_buff *), GFP_KERNEL);
768 memset(d->sbdma_ctxtable,0,d->sbdma_maxdescr*sizeof(struct sk_buff *));
770 #ifdef CONFIG_SBMAC_COALESCE
772 * Setup Rx/Tx DMA coalescing defaults
776 d->sbdma_int_pktcnt = int_pktcnt;
778 d->sbdma_int_pktcnt = 1;
782 d->sbdma_int_timeout = int_timeout;
784 d->sbdma_int_timeout = 0;
790 /**********************************************************************
791 * SBDMA_CHANNEL_START(d)
793 * Initialize the hardware registers for a DMA channel.
796 * d - DMA channel to init (context must be previously init'd
797 * rxtx - DMA_RX or DMA_TX depending on what type of channel
801 ********************************************************************* */
803 static void sbdma_channel_start(sbmacdma_t *d, int rxtx )
806 * Turn on the DMA channel
809 #ifdef CONFIG_SBMAC_COALESCE
810 SBMAC_WRITECSR(d->sbdma_config1,
811 V_DMA_INT_TIMEOUT(d->sbdma_int_timeout) |
813 SBMAC_WRITECSR(d->sbdma_config0,
815 V_DMA_RINGSZ(d->sbdma_maxdescr) |
816 V_DMA_INT_PKTCNT(d->sbdma_int_pktcnt) |
819 SBMAC_WRITECSR(d->sbdma_config1,0);
820 SBMAC_WRITECSR(d->sbdma_config0,
821 V_DMA_RINGSZ(d->sbdma_maxdescr) |
825 SBMAC_WRITECSR(d->sbdma_dscrbase,d->sbdma_dscrtable_phys);
828 * Initialize ring pointers
831 d->sbdma_addptr = d->sbdma_dscrtable;
832 d->sbdma_remptr = d->sbdma_dscrtable;
835 /**********************************************************************
836 * SBDMA_CHANNEL_STOP(d)
838 * Initialize the hardware registers for a DMA channel.
841 * d - DMA channel to init (context must be previously init'd
845 ********************************************************************* */
847 static void sbdma_channel_stop(sbmacdma_t *d)
850 * Turn off the DMA channel
853 SBMAC_WRITECSR(d->sbdma_config1,0);
855 SBMAC_WRITECSR(d->sbdma_dscrbase,0);
857 SBMAC_WRITECSR(d->sbdma_config0,0);
867 static void sbdma_align_skb(struct sk_buff *skb,int power2,int offset)
870 unsigned long newaddr;
872 addr = (unsigned long) skb->data;
874 newaddr = (addr + power2 - 1) & ~(power2 - 1);
876 skb_reserve(skb,newaddr-addr+offset);
880 /**********************************************************************
881 * SBDMA_ADD_RCVBUFFER(d,sb)
883 * Add a buffer to the specified DMA channel. For receive channels,
884 * this queues a buffer for inbound packets.
887 * d - DMA channel descriptor
888 * sb - sk_buff to add, or NULL if we should allocate one
891 * 0 if buffer could not be added (ring is full)
892 * 1 if buffer added successfully
893 ********************************************************************* */
896 static int sbdma_add_rcvbuffer(sbmacdma_t *d,struct sk_buff *sb)
899 sbdmadscr_t *nextdsc;
900 struct sk_buff *sb_new = NULL;
901 int pktsize = ENET_PACKET_SIZE;
903 /* get pointer to our current place in the ring */
905 dsc = d->sbdma_addptr;
906 nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr);
909 * figure out if the ring is full - if the next descriptor
910 * is the same as the one that we're going to remove from
911 * the ring, the ring is full
914 if (nextdsc == d->sbdma_remptr) {
919 * Allocate a sk_buff if we don't already have one.
920 * If we do have an sk_buff, reset it so that it's empty.
922 * Note: sk_buffs don't seem to be guaranteed to have any sort
923 * of alignment when they are allocated. Therefore, allocate enough
924 * extra space to make sure that:
926 * 1. the data does not start in the middle of a cache line.
927 * 2. The data does not end in the middle of a cache line
928 * 3. The buffer can be aligned such that the IP addresses are
931 * Remember, the SOCs MAC writes whole cache lines at a time,
932 * without reading the old contents first. So, if the sk_buff's
933 * data portion starts in the middle of a cache line, the SOC
934 * DMA will trash the beginning (and ending) portions.
938 sb_new = dev_alloc_skb(ENET_PACKET_SIZE + SMP_CACHE_BYTES * 2 + ETHER_ALIGN);
939 if (sb_new == NULL) {
940 printk(KERN_INFO "%s: sk_buff allocation failed\n",
941 d->sbdma_eth->sbm_dev->name);
945 sbdma_align_skb(sb_new, SMP_CACHE_BYTES, ETHER_ALIGN);
947 /* mark skbuff owned by our device */
948 sb_new->dev = d->sbdma_eth->sbm_dev;
953 * nothing special to reinit buffer, it's already aligned
954 * and sb->data already points to a good place.
959 * fill in the descriptor
962 #ifdef CONFIG_SBMAC_COALESCE
964 * Do not interrupt per DMA transfer.
966 dsc->dscr_a = virt_to_phys(sb_new->tail) |
967 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) |
970 dsc->dscr_a = virt_to_phys(sb_new->tail) |
971 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) |
972 M_DMA_DSCRA_INTERRUPT;
975 /* receiving: no options */
979 * fill in the context
982 d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb_new;
985 * point at next packet
988 d->sbdma_addptr = nextdsc;
991 * Give the buffer to the DMA engine.
994 SBMAC_WRITECSR(d->sbdma_dscrcnt,1);
996 return 0; /* we did it */
999 /**********************************************************************
1000 * SBDMA_ADD_TXBUFFER(d,sb)
1002 * Add a transmit buffer to the specified DMA channel, causing a
1003 * transmit to start.
1006 * d - DMA channel descriptor
1007 * sb - sk_buff to add
1010 * 0 transmit queued successfully
1011 * otherwise error code
1012 ********************************************************************* */
1015 static int sbdma_add_txbuffer(sbmacdma_t *d,struct sk_buff *sb)
1018 sbdmadscr_t *nextdsc;
1023 /* get pointer to our current place in the ring */
1025 dsc = d->sbdma_addptr;
1026 nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr);
1029 * figure out if the ring is full - if the next descriptor
1030 * is the same as the one that we're going to remove from
1031 * the ring, the ring is full
1034 if (nextdsc == d->sbdma_remptr) {
1039 * Under Linux, it's not necessary to copy/coalesce buffers
1040 * like it is on NetBSD. We think they're all contiguous,
1041 * but that may not be true for GBE.
1047 * fill in the descriptor. Note that the number of cache
1048 * blocks in the descriptor is the number of blocks
1049 * *spanned*, so we need to add in the offset (if any)
1050 * while doing the calculation.
1053 phys = virt_to_phys(sb->data);
1054 ncb = NUMCACHEBLKS(length+(phys & (SMP_CACHE_BYTES - 1)));
1056 dsc->dscr_a = phys |
1057 V_DMA_DSCRA_A_SIZE(ncb) |
1058 #ifndef CONFIG_SBMAC_COALESCE
1059 M_DMA_DSCRA_INTERRUPT |
1063 /* transmitting: set outbound options and length */
1065 dsc->dscr_b = V_DMA_DSCRB_OPTIONS(K_DMA_ETHTX_APPENDCRC_APPENDPAD) |
1066 V_DMA_DSCRB_PKT_SIZE(length);
1069 * fill in the context
1072 d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb;
1075 * point at next packet
1078 d->sbdma_addptr = nextdsc;
1081 * Give the buffer to the DMA engine.
1084 SBMAC_WRITECSR(d->sbdma_dscrcnt,1);
1086 return 0; /* we did it */
1092 /**********************************************************************
1093 * SBDMA_EMPTYRING(d)
1095 * Free all allocated sk_buffs on the specified DMA channel;
1102 ********************************************************************* */
1104 static void sbdma_emptyring(sbmacdma_t *d)
1109 for (idx = 0; idx < d->sbdma_maxdescr; idx++) {
1110 sb = d->sbdma_ctxtable[idx];
1113 d->sbdma_ctxtable[idx] = NULL;
1119 /**********************************************************************
1122 * Fill the specified DMA channel (must be receive channel)
1130 ********************************************************************* */
1132 static void sbdma_fillring(sbmacdma_t *d)
1136 for (idx = 0; idx < SBMAC_MAX_RXDESCR-1; idx++) {
1137 if (sbdma_add_rcvbuffer(d,NULL) != 0)
1143 /**********************************************************************
1144 * SBDMA_RX_PROCESS(sc,d)
1146 * Process "completed" receive buffers on the specified DMA channel.
1147 * Note that this isn't really ideal for priority channels, since
1148 * it processes all of the packets on a given channel before
1152 * sc - softc structure
1153 * d - DMA channel context
1157 ********************************************************************* */
1159 static void sbdma_rx_process(struct sbmac_softc *sc,sbmacdma_t *d)
1169 * figure out where we are (as an index) and where
1170 * the hardware is (also as an index)
1172 * This could be done faster if (for example) the
1173 * descriptor table was page-aligned and contiguous in
1174 * both virtual and physical memory -- you could then
1175 * just compare the low-order bits of the virtual address
1176 * (sbdma_remptr) and the physical address (sbdma_curdscr CSR)
1179 curidx = d->sbdma_remptr - d->sbdma_dscrtable;
1180 hwidx = (int) (((SBMAC_READCSR(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) -
1181 d->sbdma_dscrtable_phys) / sizeof(sbdmadscr_t));
1184 * If they're the same, that means we've processed all
1185 * of the descriptors up to (but not including) the one that
1186 * the hardware is working on right now.
1189 if (curidx == hwidx)
1193 * Otherwise, get the packet's sk_buff ptr back
1196 dsc = &(d->sbdma_dscrtable[curidx]);
1197 sb = d->sbdma_ctxtable[curidx];
1198 d->sbdma_ctxtable[curidx] = NULL;
1200 len = (int)G_DMA_DSCRB_PKT_SIZE(dsc->dscr_b) - 4;
1203 * Check packet status. If good, process it.
1204 * If not, silently drop it and put it back on the
1208 if (!(dsc->dscr_a & M_DMA_ETHRX_BAD)) {
1211 * Add a new buffer to replace the old one. If we fail
1212 * to allocate a buffer, we're going to drop this
1213 * packet and put it right back on the receive ring.
1216 if (sbdma_add_rcvbuffer(d,NULL) == -ENOBUFS) {
1217 sc->sbm_stats.rx_dropped++;
1218 sbdma_add_rcvbuffer(d,sb); /* re-add old buffer */
1221 * Set length into the packet
1226 * Buffer has been replaced on the
1227 * receive ring. Pass the buffer to
1230 sc->sbm_stats.rx_bytes += len;
1231 sc->sbm_stats.rx_packets++;
1232 sb->protocol = eth_type_trans(sb,d->sbdma_eth->sbm_dev);
1233 /* Check hw IPv4/TCP checksum if supported */
1234 if (sc->rx_hw_checksum == ENABLE) {
1235 if (!((dsc->dscr_a) & M_DMA_ETHRX_BADIP4CS) &&
1236 !((dsc->dscr_a) & M_DMA_ETHRX_BADTCPCS)) {
1237 sb->ip_summed = CHECKSUM_UNNECESSARY;
1238 /* don't need to set sb->csum */
1240 sb->ip_summed = CHECKSUM_NONE;
1248 * Packet was mangled somehow. Just drop it and
1249 * put it back on the receive ring.
1251 sc->sbm_stats.rx_errors++;
1252 sbdma_add_rcvbuffer(d,sb);
1257 * .. and advance to the next buffer.
1260 d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);
1267 /**********************************************************************
1268 * SBDMA_TX_PROCESS(sc,d)
1270 * Process "completed" transmit buffers on the specified DMA channel.
1271 * This is normally called within the interrupt service routine.
1272 * Note that this isn't really ideal for priority channels, since
1273 * it processes all of the packets on a given channel before
1277 * sc - softc structure
1278 * d - DMA channel context
1282 ********************************************************************* */
1284 static void sbdma_tx_process(struct sbmac_softc *sc,sbmacdma_t *d)
1290 unsigned long flags;
1292 spin_lock_irqsave(&(sc->sbm_lock), flags);
1296 * figure out where we are (as an index) and where
1297 * the hardware is (also as an index)
1299 * This could be done faster if (for example) the
1300 * descriptor table was page-aligned and contiguous in
1301 * both virtual and physical memory -- you could then
1302 * just compare the low-order bits of the virtual address
1303 * (sbdma_remptr) and the physical address (sbdma_curdscr CSR)
1306 curidx = d->sbdma_remptr - d->sbdma_dscrtable;
1307 hwidx = (int) (((SBMAC_READCSR(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) -
1308 d->sbdma_dscrtable_phys) / sizeof(sbdmadscr_t));
1311 * If they're the same, that means we've processed all
1312 * of the descriptors up to (but not including) the one that
1313 * the hardware is working on right now.
1316 if (curidx == hwidx)
1320 * Otherwise, get the packet's sk_buff ptr back
1323 dsc = &(d->sbdma_dscrtable[curidx]);
1324 sb = d->sbdma_ctxtable[curidx];
1325 d->sbdma_ctxtable[curidx] = NULL;
1331 sc->sbm_stats.tx_bytes += sb->len;
1332 sc->sbm_stats.tx_packets++;
1335 * for transmits, we just free buffers.
1338 dev_kfree_skb_irq(sb);
1341 * .. and advance to the next buffer.
1344 d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);
1349 * Decide if we should wake up the protocol or not.
1350 * Other drivers seem to do this when we reach a low
1351 * watermark on the transmit queue.
1354 netif_wake_queue(d->sbdma_eth->sbm_dev);
1356 spin_unlock_irqrestore(&(sc->sbm_lock), flags);
1362 /**********************************************************************
1365 * Initialize an Ethernet context structure - this is called
1366 * once per MAC on the 1250. Memory is allocated here, so don't
1367 * call it again from inside the ioctl routines that bring the
1371 * s - sbmac context structure
1375 ********************************************************************* */
1377 static int sbmac_initctx(struct sbmac_softc *s)
1381 * figure out the addresses of some ports
1384 s->sbm_macenable = s->sbm_base + R_MAC_ENABLE;
1385 s->sbm_maccfg = s->sbm_base + R_MAC_CFG;
1386 s->sbm_fifocfg = s->sbm_base + R_MAC_THRSH_CFG;
1387 s->sbm_framecfg = s->sbm_base + R_MAC_FRAMECFG;
1388 s->sbm_rxfilter = s->sbm_base + R_MAC_ADFILTER_CFG;
1389 s->sbm_isr = s->sbm_base + R_MAC_STATUS;
1390 s->sbm_imr = s->sbm_base + R_MAC_INT_MASK;
1391 s->sbm_mdio = s->sbm_base + R_MAC_MDIO;
1396 s->sbm_phy_oldbmsr = 0;
1397 s->sbm_phy_oldanlpar = 0;
1398 s->sbm_phy_oldk1stsr = 0;
1399 s->sbm_phy_oldlinkstat = 0;
1402 * Initialize the DMA channels. Right now, only one per MAC is used
1403 * Note: Only do this _once_, as it allocates memory from the kernel!
1406 sbdma_initctx(&(s->sbm_txdma),s,0,DMA_TX,SBMAC_MAX_TXDESCR);
1407 sbdma_initctx(&(s->sbm_rxdma),s,0,DMA_RX,SBMAC_MAX_RXDESCR);
1410 * initial state is OFF
1413 s->sbm_state = sbmac_state_off;
1416 * Initial speed is (XXX TEMP) 10MBit/s HDX no FC
1419 s->sbm_speed = sbmac_speed_10;
1420 s->sbm_duplex = sbmac_duplex_half;
1421 s->sbm_fc = sbmac_fc_disabled;
1427 static void sbdma_uninitctx(struct sbmacdma_s *d)
1429 if (d->sbdma_dscrtable) {
1430 kfree(d->sbdma_dscrtable);
1431 d->sbdma_dscrtable = NULL;
1434 if (d->sbdma_ctxtable) {
1435 kfree(d->sbdma_ctxtable);
1436 d->sbdma_ctxtable = NULL;
1441 static void sbmac_uninitctx(struct sbmac_softc *sc)
1443 sbdma_uninitctx(&(sc->sbm_txdma));
1444 sbdma_uninitctx(&(sc->sbm_rxdma));
1448 /**********************************************************************
1449 * SBMAC_CHANNEL_START(s)
1451 * Start packet processing on this MAC.
1454 * s - sbmac structure
1458 ********************************************************************* */
1460 static void sbmac_channel_start(struct sbmac_softc *s)
1464 uint64_t cfg,fifo,framecfg;
1468 * Don't do this if running
1471 if (s->sbm_state == sbmac_state_on)
1475 * Bring the controller out of reset, but leave it off.
1478 SBMAC_WRITECSR(s->sbm_macenable,0);
1481 * Ignore all received packets
1484 SBMAC_WRITECSR(s->sbm_rxfilter,0);
1487 * Calculate values for various control registers.
1490 cfg = M_MAC_RETRY_EN |
1491 M_MAC_TX_HOLD_SOP_EN |
1492 V_MAC_TX_PAUSE_CNT_16K |
1499 * Be sure that RD_THRSH+WR_THRSH <= 32 for pass1 pars
1500 * and make sure that RD_THRSH + WR_THRSH <=128 for pass2 and above
1501 * Use a larger RD_THRSH for gigabit
1503 if (periph_rev >= 2)
1508 fifo = V_MAC_TX_WR_THRSH(4) | /* Must be '4' or '8' */
1509 ((s->sbm_speed == sbmac_speed_1000)
1510 ? V_MAC_TX_RD_THRSH(th_value) : V_MAC_TX_RD_THRSH(4)) |
1511 V_MAC_TX_RL_THRSH(4) |
1512 V_MAC_RX_PL_THRSH(4) |
1513 V_MAC_RX_RD_THRSH(4) | /* Must be '4' */
1514 V_MAC_RX_PL_THRSH(4) |
1515 V_MAC_RX_RL_THRSH(8) |
1518 framecfg = V_MAC_MIN_FRAMESZ_DEFAULT |
1519 V_MAC_MAX_FRAMESZ_DEFAULT |
1520 V_MAC_BACKOFF_SEL(1);
1523 * Clear out the hash address map
1526 port = s->sbm_base + R_MAC_HASH_BASE;
1527 for (idx = 0; idx < MAC_HASH_COUNT; idx++) {
1528 SBMAC_WRITECSR(port,0);
1529 port += sizeof(uint64_t);
1533 * Clear out the exact-match table
1536 port = s->sbm_base + R_MAC_ADDR_BASE;
1537 for (idx = 0; idx < MAC_ADDR_COUNT; idx++) {
1538 SBMAC_WRITECSR(port,0);
1539 port += sizeof(uint64_t);
1543 * Clear out the DMA Channel mapping table registers
1546 port = s->sbm_base + R_MAC_CHUP0_BASE;
1547 for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) {
1548 SBMAC_WRITECSR(port,0);
1549 port += sizeof(uint64_t);
1553 port = s->sbm_base + R_MAC_CHLO0_BASE;
1554 for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) {
1555 SBMAC_WRITECSR(port,0);
1556 port += sizeof(uint64_t);
1560 * Program the hardware address. It goes into the hardware-address
1561 * register as well as the first filter register.
1564 reg = sbmac_addr2reg(s->sbm_hwaddr);
1566 port = s->sbm_base + R_MAC_ADDR_BASE;
1567 SBMAC_WRITECSR(port,reg);
1568 port = s->sbm_base + R_MAC_ETHERNET_ADDR;
1570 #ifdef CONFIG_SB1_PASS_1_WORKAROUNDS
1572 * Pass1 SOCs do not receive packets addressed to the
1573 * destination address in the R_MAC_ETHERNET_ADDR register.
1574 * Set the value to zero.
1576 SBMAC_WRITECSR(port,0);
1578 SBMAC_WRITECSR(port,reg);
1582 * Set the receive filter for no packets, and write values
1583 * to the various config registers
1586 SBMAC_WRITECSR(s->sbm_rxfilter,0);
1587 SBMAC_WRITECSR(s->sbm_imr,0);
1588 SBMAC_WRITECSR(s->sbm_framecfg,framecfg);
1589 SBMAC_WRITECSR(s->sbm_fifocfg,fifo);
1590 SBMAC_WRITECSR(s->sbm_maccfg,cfg);
1593 * Initialize DMA channels (rings should be ok now)
1596 sbdma_channel_start(&(s->sbm_rxdma), DMA_RX);
1597 sbdma_channel_start(&(s->sbm_txdma), DMA_TX);
1600 * Configure the speed, duplex, and flow control
1603 sbmac_set_speed(s,s->sbm_speed);
1604 sbmac_set_duplex(s,s->sbm_duplex,s->sbm_fc);
1607 * Fill the receive ring
1610 sbdma_fillring(&(s->sbm_rxdma));
1613 * Turn on the rest of the bits in the enable register
1616 SBMAC_WRITECSR(s->sbm_macenable,
1625 #ifdef CONFIG_SBMAC_COALESCE
1627 * Accept any TX interrupt and EOP count/timer RX interrupts on ch 0
1629 SBMAC_WRITECSR(s->sbm_imr,
1630 ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) |
1631 ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0));
1634 * Accept any kind of interrupt on TX and RX DMA channel 0
1636 SBMAC_WRITECSR(s->sbm_imr,
1637 (M_MAC_INT_CHANNEL << S_MAC_TX_CH0) |
1638 (M_MAC_INT_CHANNEL << S_MAC_RX_CH0));
1642 * Enable receiving unicasts and broadcasts
1645 SBMAC_WRITECSR(s->sbm_rxfilter,M_MAC_UCAST_EN | M_MAC_BCAST_EN);
1648 * we're running now.
1651 s->sbm_state = sbmac_state_on;
1654 * Program multicast addresses
1660 * If channel was in promiscuous mode before, turn that on
1663 if (s->sbm_devflags & IFF_PROMISC) {
1664 sbmac_promiscuous_mode(s,1);
1670 /**********************************************************************
1671 * SBMAC_CHANNEL_STOP(s)
1673 * Stop packet processing on this MAC.
1676 * s - sbmac structure
1680 ********************************************************************* */
1682 static void sbmac_channel_stop(struct sbmac_softc *s)
1684 /* don't do this if already stopped */
1686 if (s->sbm_state == sbmac_state_off)
1689 /* don't accept any packets, disable all interrupts */
1691 SBMAC_WRITECSR(s->sbm_rxfilter,0);
1692 SBMAC_WRITECSR(s->sbm_imr,0);
1694 /* Turn off ticker */
1698 /* turn off receiver and transmitter */
1700 SBMAC_WRITECSR(s->sbm_macenable,0);
1702 /* We're stopped now. */
1704 s->sbm_state = sbmac_state_off;
1707 * Stop DMA channels (rings should be ok now)
1710 sbdma_channel_stop(&(s->sbm_rxdma));
1711 sbdma_channel_stop(&(s->sbm_txdma));
1713 /* Empty the receive and transmit rings */
1715 sbdma_emptyring(&(s->sbm_rxdma));
1716 sbdma_emptyring(&(s->sbm_txdma));
1720 /**********************************************************************
1721 * SBMAC_SET_CHANNEL_STATE(state)
1723 * Set the channel's state ON or OFF
1730 ********************************************************************* */
1731 static sbmac_state_t sbmac_set_channel_state(struct sbmac_softc *sc,
1732 sbmac_state_t state)
1734 sbmac_state_t oldstate = sc->sbm_state;
1737 * If same as previous state, return
1740 if (state == oldstate) {
1745 * If new state is ON, turn channel on
1748 if (state == sbmac_state_on) {
1749 sbmac_channel_start(sc);
1752 sbmac_channel_stop(sc);
1756 * Return previous state
1763 /**********************************************************************
1764 * SBMAC_PROMISCUOUS_MODE(sc,onoff)
1766 * Turn on or off promiscuous mode
1770 * onoff - 1 to turn on, 0 to turn off
1774 ********************************************************************* */
1776 static void sbmac_promiscuous_mode(struct sbmac_softc *sc,int onoff)
1780 if (sc->sbm_state != sbmac_state_on)
1784 reg = SBMAC_READCSR(sc->sbm_rxfilter);
1785 reg |= M_MAC_ALLPKT_EN;
1786 SBMAC_WRITECSR(sc->sbm_rxfilter,reg);
1789 reg = SBMAC_READCSR(sc->sbm_rxfilter);
1790 reg &= ~M_MAC_ALLPKT_EN;
1791 SBMAC_WRITECSR(sc->sbm_rxfilter,reg);
1795 /**********************************************************************
1796 * SBMAC_SETIPHDR_OFFSET(sc,onoff)
1798 * Set the iphdr offset as 15 assuming ethernet encapsulation
1805 ********************************************************************* */
1807 static void sbmac_set_iphdr_offset(struct sbmac_softc *sc)
1811 /* Hard code the off set to 15 for now */
1812 reg = SBMAC_READCSR(sc->sbm_rxfilter);
1813 reg &= ~M_MAC_IPHDR_OFFSET | V_MAC_IPHDR_OFFSET(15);
1814 SBMAC_WRITECSR(sc->sbm_rxfilter,reg);
1816 /* read system identification to determine revision */
1817 if (periph_rev >= 2) {
1818 sc->rx_hw_checksum = ENABLE;
1820 sc->rx_hw_checksum = DISABLE;
1825 /**********************************************************************
1826 * SBMAC_ADDR2REG(ptr)
1828 * Convert six bytes into the 64-bit register value that
1829 * we typically write into the SBMAC's address/mcast registers
1832 * ptr - pointer to 6 bytes
1836 ********************************************************************* */
1838 static uint64_t sbmac_addr2reg(unsigned char *ptr)
1844 reg |= (uint64_t) *(--ptr);
1846 reg |= (uint64_t) *(--ptr);
1848 reg |= (uint64_t) *(--ptr);
1850 reg |= (uint64_t) *(--ptr);
1852 reg |= (uint64_t) *(--ptr);
1854 reg |= (uint64_t) *(--ptr);
1860 /**********************************************************************
1861 * SBMAC_SET_SPEED(s,speed)
1863 * Configure LAN speed for the specified MAC.
1864 * Warning: must be called when MAC is off!
1867 * s - sbmac structure
1868 * speed - speed to set MAC to (see sbmac_speed_t enum)
1872 * 0 indicates invalid parameters
1873 ********************************************************************* */
1875 static int sbmac_set_speed(struct sbmac_softc *s,sbmac_speed_t speed)
1881 * Save new current values
1884 s->sbm_speed = speed;
1886 if (s->sbm_state == sbmac_state_on)
1887 return 0; /* save for next restart */
1890 * Read current register values
1893 cfg = SBMAC_READCSR(s->sbm_maccfg);
1894 framecfg = SBMAC_READCSR(s->sbm_framecfg);
1897 * Mask out the stuff we want to change
1900 cfg &= ~(M_MAC_BURST_EN | M_MAC_SPEED_SEL);
1901 framecfg &= ~(M_MAC_IFG_RX | M_MAC_IFG_TX | M_MAC_IFG_THRSH |
1905 * Now add in the new bits
1909 case sbmac_speed_10:
1910 framecfg |= V_MAC_IFG_RX_10 |
1912 K_MAC_IFG_THRSH_10 |
1914 cfg |= V_MAC_SPEED_SEL_10MBPS;
1917 case sbmac_speed_100:
1918 framecfg |= V_MAC_IFG_RX_100 |
1920 V_MAC_IFG_THRSH_100 |
1921 V_MAC_SLOT_SIZE_100;
1922 cfg |= V_MAC_SPEED_SEL_100MBPS ;
1925 case sbmac_speed_1000:
1926 framecfg |= V_MAC_IFG_RX_1000 |
1928 V_MAC_IFG_THRSH_1000 |
1929 V_MAC_SLOT_SIZE_1000;
1930 cfg |= V_MAC_SPEED_SEL_1000MBPS | M_MAC_BURST_EN;
1933 case sbmac_speed_auto: /* XXX not implemented */
1940 * Send the bits back to the hardware
1943 SBMAC_WRITECSR(s->sbm_framecfg,framecfg);
1944 SBMAC_WRITECSR(s->sbm_maccfg,cfg);
1949 /**********************************************************************
1950 * SBMAC_SET_DUPLEX(s,duplex,fc)
1952 * Set Ethernet duplex and flow control options for this MAC
1953 * Warning: must be called when MAC is off!
1956 * s - sbmac structure
1957 * duplex - duplex setting (see sbmac_duplex_t)
1958 * fc - flow control setting (see sbmac_fc_t)
1962 * 0 if an invalid parameter combination was specified
1963 ********************************************************************* */
1965 static int sbmac_set_duplex(struct sbmac_softc *s,sbmac_duplex_t duplex,sbmac_fc_t fc)
1970 * Save new current values
1973 s->sbm_duplex = duplex;
1976 if (s->sbm_state == sbmac_state_on)
1977 return 0; /* save for next restart */
1980 * Read current register values
1983 cfg = SBMAC_READCSR(s->sbm_maccfg);
1986 * Mask off the stuff we're about to change
1989 cfg &= ~(M_MAC_FC_SEL | M_MAC_FC_CMD | M_MAC_HDX_EN);
1993 case sbmac_duplex_half:
1995 case sbmac_fc_disabled:
1996 cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_DISABLED;
1999 case sbmac_fc_collision:
2000 cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENABLED;
2003 case sbmac_fc_carrier:
2004 cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENAB_FALSECARR;
2007 case sbmac_fc_auto: /* XXX not implemented */
2009 case sbmac_fc_frame: /* not valid in half duplex */
2010 default: /* invalid selection */
2015 case sbmac_duplex_full:
2017 case sbmac_fc_disabled:
2018 cfg |= V_MAC_FC_CMD_DISABLED;
2021 case sbmac_fc_frame:
2022 cfg |= V_MAC_FC_CMD_ENABLED;
2025 case sbmac_fc_collision: /* not valid in full duplex */
2026 case sbmac_fc_carrier: /* not valid in full duplex */
2027 case sbmac_fc_auto: /* XXX not implemented */
2033 case sbmac_duplex_auto:
2034 /* XXX not implemented */
2039 * Send the bits back to the hardware
2042 SBMAC_WRITECSR(s->sbm_maccfg,cfg);
2050 /**********************************************************************
2053 * Interrupt handler for MAC interrupts
2060 ********************************************************************* */
2061 static irqreturn_t sbmac_intr(int irq,void *dev_instance,struct pt_regs *rgs)
2063 struct net_device *dev = (struct net_device *) dev_instance;
2064 struct sbmac_softc *sc = netdev_priv(dev);
2071 * Read the ISR (this clears the bits in the real
2072 * register, except for counter addr)
2075 isr = SBMAC_READCSR(sc->sbm_isr) & ~M_MAC_COUNTER_ADDR;
2083 * Transmits on channel 0
2086 if (isr & (M_MAC_INT_CHANNEL << S_MAC_TX_CH0)) {
2087 sbdma_tx_process(sc,&(sc->sbm_txdma));
2091 * Receives on channel 0
2095 * It's important to test all the bits (or at least the
2096 * EOP_SEEN bit) when deciding to do the RX process
2097 * particularly when coalescing, to make sure we
2098 * take care of the following:
2100 * If you have some packets waiting (have been received
2101 * but no interrupt) and get a TX interrupt before
2102 * the RX timer or counter expires, reading the ISR
2103 * above will clear the timer and counter, and you
2104 * won't get another interrupt until a packet shows
2105 * up to start the timer again. Testing
2106 * EOP_SEEN here takes care of this case.
2107 * (EOP_SEEN is part of M_MAC_INT_CHANNEL << S_MAC_RX_CH0)
2111 if (isr & (M_MAC_INT_CHANNEL << S_MAC_RX_CH0)) {
2112 sbdma_rx_process(sc,&(sc->sbm_rxdma));
2115 return IRQ_RETVAL(handled);
2119 /**********************************************************************
2120 * SBMAC_START_TX(skb,dev)
2122 * Start output on the specified interface. Basically, we
2123 * queue as many buffers as we can until the ring fills up, or
2124 * we run off the end of the queue, whichever comes first.
2131 ********************************************************************* */
2132 static int sbmac_start_tx(struct sk_buff *skb, struct net_device *dev)
2134 struct sbmac_softc *sc = netdev_priv(dev);
2137 spin_lock_irq (&sc->sbm_lock);
2140 * Put the buffer on the transmit ring. If we
2141 * don't have room, stop the queue.
2144 if (sbdma_add_txbuffer(&(sc->sbm_txdma),skb)) {
2145 /* XXX save skb that we could not send */
2146 netif_stop_queue(dev);
2147 spin_unlock_irq(&sc->sbm_lock);
2152 dev->trans_start = jiffies;
2154 spin_unlock_irq (&sc->sbm_lock);
2159 /**********************************************************************
2160 * SBMAC_SETMULTI(sc)
2162 * Reprogram the multicast table into the hardware, given
2163 * the list of multicasts associated with the interface
2171 ********************************************************************* */
2173 static void sbmac_setmulti(struct sbmac_softc *sc)
2178 struct dev_mc_list *mclist;
2179 struct net_device *dev = sc->sbm_dev;
2182 * Clear out entire multicast table. We do this by nuking
2183 * the entire hash table and all the direct matches except
2184 * the first one, which is used for our station address
2187 for (idx = 1; idx < MAC_ADDR_COUNT; idx++) {
2188 port = sc->sbm_base + R_MAC_ADDR_BASE+(idx*sizeof(uint64_t));
2189 SBMAC_WRITECSR(port,0);
2192 for (idx = 0; idx < MAC_HASH_COUNT; idx++) {
2193 port = sc->sbm_base + R_MAC_HASH_BASE+(idx*sizeof(uint64_t));
2194 SBMAC_WRITECSR(port,0);
2198 * Clear the filter to say we don't want any multicasts.
2201 reg = SBMAC_READCSR(sc->sbm_rxfilter);
2202 reg &= ~(M_MAC_MCAST_INV | M_MAC_MCAST_EN);
2203 SBMAC_WRITECSR(sc->sbm_rxfilter,reg);
2205 if (dev->flags & IFF_ALLMULTI) {
2207 * Enable ALL multicasts. Do this by inverting the
2208 * multicast enable bit.
2210 reg = SBMAC_READCSR(sc->sbm_rxfilter);
2211 reg |= (M_MAC_MCAST_INV | M_MAC_MCAST_EN);
2212 SBMAC_WRITECSR(sc->sbm_rxfilter,reg);
2218 * Progam new multicast entries. For now, only use the
2219 * perfect filter. In the future we'll need to use the
2220 * hash filter if the perfect filter overflows
2223 /* XXX only using perfect filter for now, need to use hash
2224 * XXX if the table overflows */
2226 idx = 1; /* skip station address */
2227 mclist = dev->mc_list;
2228 while (mclist && (idx < MAC_ADDR_COUNT)) {
2229 reg = sbmac_addr2reg(mclist->dmi_addr);
2230 port = sc->sbm_base + R_MAC_ADDR_BASE+(idx * sizeof(uint64_t));
2231 SBMAC_WRITECSR(port,reg);
2233 mclist = mclist->next;
2237 * Enable the "accept multicast bits" if we programmed at least one
2242 reg = SBMAC_READCSR(sc->sbm_rxfilter);
2243 reg |= M_MAC_MCAST_EN;
2244 SBMAC_WRITECSR(sc->sbm_rxfilter,reg);
2250 #if defined(SBMAC_ETH0_HWADDR) || defined(SBMAC_ETH1_HWADDR) || defined(SBMAC_ETH2_HWADDR)
2251 /**********************************************************************
2252 * SBMAC_PARSE_XDIGIT(str)
2254 * Parse a hex digit, returning its value
2260 * hex value, or -1 if invalid
2261 ********************************************************************* */
2263 static int sbmac_parse_xdigit(char str)
2267 if ((str >= '0') && (str <= '9'))
2269 else if ((str >= 'a') && (str <= 'f'))
2270 digit = str - 'a' + 10;
2271 else if ((str >= 'A') && (str <= 'F'))
2272 digit = str - 'A' + 10;
2279 /**********************************************************************
2280 * SBMAC_PARSE_HWADDR(str,hwaddr)
2282 * Convert a string in the form xx:xx:xx:xx:xx:xx into a 6-byte
2287 * hwaddr - pointer to hardware address
2291 ********************************************************************* */
2293 static int sbmac_parse_hwaddr(char *str, unsigned char *hwaddr)
2298 while (*str && (idx > 0)) {
2299 digit1 = sbmac_parse_xdigit(*str);
2306 if ((*str == ':') || (*str == '-')) {
2311 digit2 = sbmac_parse_xdigit(*str);
2317 *hwaddr++ = (digit1 << 4) | digit2;
2329 static int sb1250_change_mtu(struct net_device *_dev, int new_mtu)
2331 if (new_mtu > ENET_PACKET_SIZE)
2333 _dev->mtu = new_mtu;
2334 printk(KERN_INFO "changing the mtu to %d\n", new_mtu);
2338 /**********************************************************************
2341 * Attach routine - init hardware and hook ourselves into linux
2344 * dev - net_device structure
2348 ********************************************************************* */
2350 static int sbmac_init(struct net_device *dev, int idx)
2352 struct sbmac_softc *sc;
2353 unsigned char *eaddr;
2358 sc = netdev_priv(dev);
2360 /* Determine controller base address */
2362 sc->sbm_base = IOADDR(dev->base_addr);
2366 eaddr = sc->sbm_hwaddr;
2369 * Read the ethernet address. The firwmare left this programmed
2370 * for us in the ethernet address register for each mac.
2373 ea_reg = SBMAC_READCSR(sc->sbm_base + R_MAC_ETHERNET_ADDR);
2374 SBMAC_WRITECSR(sc->sbm_base + R_MAC_ETHERNET_ADDR, 0);
2375 for (i = 0; i < 6; i++) {
2376 eaddr[i] = (uint8_t) (ea_reg & 0xFF);
2380 for (i = 0; i < 6; i++) {
2381 dev->dev_addr[i] = eaddr[i];
2389 sc->sbm_buffersize = ENET_PACKET_SIZE + SMP_CACHE_BYTES * 2 + ETHER_ALIGN;
2392 * Initialize context (get pointers to registers and stuff), then
2393 * allocate the memory for the descriptor tables.
2399 * Set up Linux device callins
2402 spin_lock_init(&(sc->sbm_lock));
2404 dev->open = sbmac_open;
2405 dev->hard_start_xmit = sbmac_start_tx;
2406 dev->stop = sbmac_close;
2407 dev->get_stats = sbmac_get_stats;
2408 dev->set_multicast_list = sbmac_set_rx_mode;
2409 dev->do_ioctl = sbmac_mii_ioctl;
2410 dev->tx_timeout = sbmac_tx_timeout;
2411 dev->watchdog_timeo = TX_TIMEOUT;
2413 dev->change_mtu = sb1250_change_mtu;
2415 /* This is needed for PASS2 for Rx H/W checksum feature */
2416 sbmac_set_iphdr_offset(sc);
2418 err = register_netdev(dev);
2422 if (periph_rev >= 2) {
2423 printk(KERN_INFO "%s: enabling TCP rcv checksum\n",
2428 * Display Ethernet address (this is called during the config
2429 * process so we need to finish off the config message that
2430 * was being displayed)
2433 "%s: SiByte Ethernet at 0x%08lX, address: %02X:%02X:%02X:%02X:%02X:%02X\n",
2434 dev->name, dev->base_addr,
2435 eaddr[0],eaddr[1],eaddr[2],eaddr[3],eaddr[4],eaddr[5]);
2441 sbmac_uninitctx(sc);
2447 static int sbmac_open(struct net_device *dev)
2449 struct sbmac_softc *sc = netdev_priv(dev);
2452 printk(KERN_DEBUG "%s: sbmac_open() irq %d.\n", dev->name, dev->irq);
2456 * map/route interrupt (clear status first, in case something
2457 * weird is pending; we haven't initialized the mac registers
2461 SBMAC_READCSR(sc->sbm_isr);
2462 if (request_irq(dev->irq, &sbmac_intr, SA_SHIRQ, dev->name, dev))
2466 * Configure default speed
2469 sbmac_mii_poll(sc,noisy_mii);
2472 * Turn on the channel
2475 sbmac_set_channel_state(sc,sbmac_state_on);
2478 * XXX Station address is in dev->dev_addr
2481 if (dev->if_port == 0)
2484 netif_start_queue(dev);
2486 sbmac_set_rx_mode(dev);
2488 /* Set the timer to check for link beat. */
2489 init_timer(&sc->sbm_timer);
2490 sc->sbm_timer.expires = jiffies + 2 * HZ/100;
2491 sc->sbm_timer.data = (unsigned long)dev;
2492 sc->sbm_timer.function = &sbmac_timer;
2493 add_timer(&sc->sbm_timer);
2500 static int sbmac_mii_poll(struct sbmac_softc *s,int noisy)
2502 int bmsr,bmcr,k1stsr,anlpar;
2507 /* Read the mode status and mode control registers. */
2508 bmsr = sbmac_mii_read(s,s->sbm_phys[0],MII_BMSR);
2509 bmcr = sbmac_mii_read(s,s->sbm_phys[0],MII_BMCR);
2511 /* get the link partner status */
2512 anlpar = sbmac_mii_read(s,s->sbm_phys[0],MII_ANLPAR);
2514 /* if supported, read the 1000baseT register */
2515 if (bmsr & BMSR_1000BT_XSR) {
2516 k1stsr = sbmac_mii_read(s,s->sbm_phys[0],MII_K1STSR);
2524 if ((bmsr & BMSR_LINKSTAT) == 0) {
2526 * If link status is down, clear out old info so that when
2527 * it comes back up it will force us to reconfigure speed
2529 s->sbm_phy_oldbmsr = 0;
2530 s->sbm_phy_oldanlpar = 0;
2531 s->sbm_phy_oldk1stsr = 0;
2535 if ((s->sbm_phy_oldbmsr != bmsr) ||
2536 (s->sbm_phy_oldanlpar != anlpar) ||
2537 (s->sbm_phy_oldk1stsr != k1stsr)) {
2539 printk(KERN_DEBUG "%s: bmsr:%x/%x anlpar:%x/%x k1stsr:%x/%x\n",
2541 s->sbm_phy_oldbmsr,bmsr,
2542 s->sbm_phy_oldanlpar,anlpar,
2543 s->sbm_phy_oldk1stsr,k1stsr);
2545 s->sbm_phy_oldbmsr = bmsr;
2546 s->sbm_phy_oldanlpar = anlpar;
2547 s->sbm_phy_oldk1stsr = k1stsr;
2554 p += sprintf(p,"Link speed: ");
2556 if (k1stsr & K1STSR_LP1KFD) {
2557 s->sbm_speed = sbmac_speed_1000;
2558 s->sbm_duplex = sbmac_duplex_full;
2559 s->sbm_fc = sbmac_fc_frame;
2560 p += sprintf(p,"1000BaseT FDX");
2562 else if (k1stsr & K1STSR_LP1KHD) {
2563 s->sbm_speed = sbmac_speed_1000;
2564 s->sbm_duplex = sbmac_duplex_half;
2565 s->sbm_fc = sbmac_fc_disabled;
2566 p += sprintf(p,"1000BaseT HDX");
2568 else if (anlpar & ANLPAR_TXFD) {
2569 s->sbm_speed = sbmac_speed_100;
2570 s->sbm_duplex = sbmac_duplex_full;
2571 s->sbm_fc = (anlpar & ANLPAR_PAUSE) ? sbmac_fc_frame : sbmac_fc_disabled;
2572 p += sprintf(p,"100BaseT FDX");
2574 else if (anlpar & ANLPAR_TXHD) {
2575 s->sbm_speed = sbmac_speed_100;
2576 s->sbm_duplex = sbmac_duplex_half;
2577 s->sbm_fc = sbmac_fc_disabled;
2578 p += sprintf(p,"100BaseT HDX");
2580 else if (anlpar & ANLPAR_10FD) {
2581 s->sbm_speed = sbmac_speed_10;
2582 s->sbm_duplex = sbmac_duplex_full;
2583 s->sbm_fc = sbmac_fc_frame;
2584 p += sprintf(p,"10BaseT FDX");
2586 else if (anlpar & ANLPAR_10HD) {
2587 s->sbm_speed = sbmac_speed_10;
2588 s->sbm_duplex = sbmac_duplex_half;
2589 s->sbm_fc = sbmac_fc_collision;
2590 p += sprintf(p,"10BaseT HDX");
2593 p += sprintf(p,"Unknown");
2597 printk(KERN_INFO "%s: %s\n",s->sbm_dev->name,buffer);
2604 static void sbmac_timer(unsigned long data)
2606 struct net_device *dev = (struct net_device *)data;
2607 struct sbmac_softc *sc = netdev_priv(dev);
2611 spin_lock_irq (&sc->sbm_lock);
2613 /* make IFF_RUNNING follow the MII status bit "Link established" */
2614 mii_status = sbmac_mii_read(sc, sc->sbm_phys[0], MII_BMSR);
2616 if ( (mii_status & BMSR_LINKSTAT) != (sc->sbm_phy_oldlinkstat) ) {
2617 sc->sbm_phy_oldlinkstat = mii_status & BMSR_LINKSTAT;
2618 if (mii_status & BMSR_LINKSTAT) {
2619 netif_carrier_on(dev);
2622 netif_carrier_off(dev);
2627 * Poll the PHY to see what speed we should be running at
2630 if (sbmac_mii_poll(sc,noisy_mii)) {
2631 if (sc->sbm_state != sbmac_state_off) {
2633 * something changed, restart the channel
2636 printk("%s: restarting channel because speed changed\n",
2639 sbmac_channel_stop(sc);
2640 sbmac_channel_start(sc);
2644 spin_unlock_irq (&sc->sbm_lock);
2646 sc->sbm_timer.expires = jiffies + next_tick;
2647 add_timer(&sc->sbm_timer);
2651 static void sbmac_tx_timeout (struct net_device *dev)
2653 struct sbmac_softc *sc = netdev_priv(dev);
2655 spin_lock_irq (&sc->sbm_lock);
2658 dev->trans_start = jiffies;
2659 sc->sbm_stats.tx_errors++;
2661 spin_unlock_irq (&sc->sbm_lock);
2663 printk (KERN_WARNING "%s: Transmit timed out\n",dev->name);
2669 static struct net_device_stats *sbmac_get_stats(struct net_device *dev)
2671 struct sbmac_softc *sc = netdev_priv(dev);
2672 unsigned long flags;
2674 spin_lock_irqsave(&sc->sbm_lock, flags);
2676 /* XXX update other stats here */
2678 spin_unlock_irqrestore(&sc->sbm_lock, flags);
2680 return &sc->sbm_stats;
2685 static void sbmac_set_rx_mode(struct net_device *dev)
2687 unsigned long flags;
2689 struct sbmac_softc *sc = netdev_priv(dev);
2691 spin_lock_irqsave(&sc->sbm_lock, flags);
2692 if ((dev->flags ^ sc->sbm_devflags) & IFF_PROMISC) {
2694 * Promiscuous changed.
2697 if (dev->flags & IFF_PROMISC) {
2698 /* Unconditionally log net taps. */
2700 sbmac_promiscuous_mode(sc,1);
2704 sbmac_promiscuous_mode(sc,0);
2707 spin_unlock_irqrestore(&sc->sbm_lock, flags);
2710 printk(KERN_NOTICE "%s: Promiscuous mode %sabled.\n",
2711 dev->name,(msg_flag==1)?"en":"dis");
2715 * Program the multicasts. Do this every time.
2722 static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2724 struct sbmac_softc *sc = netdev_priv(dev);
2725 u16 *data = (u16 *)&rq->ifr_ifru;
2726 unsigned long flags;
2729 spin_lock_irqsave(&sc->sbm_lock, flags);
2733 case SIOCDEVPRIVATE: /* Get the address of the PHY in use. */
2734 data[0] = sc->sbm_phys[0] & 0x1f;
2736 case SIOCDEVPRIVATE+1: /* Read the specified MII register. */
2737 data[3] = sbmac_mii_read(sc, data[0] & 0x1f, data[1] & 0x1f);
2739 case SIOCDEVPRIVATE+2: /* Write the specified MII register */
2740 if (!capable(CAP_NET_ADMIN)) {
2745 printk(KERN_DEBUG "%s: sbmac_mii_ioctl: write %02X %02X %02X\n",dev->name,
2746 data[0],data[1],data[2]);
2748 sbmac_mii_write(sc, data[0] & 0x1f, data[1] & 0x1f, data[2]);
2751 retval = -EOPNOTSUPP;
2754 spin_unlock_irqrestore(&sc->sbm_lock, flags);
2758 static int sbmac_close(struct net_device *dev)
2760 struct sbmac_softc *sc = netdev_priv(dev);
2761 unsigned long flags;
2764 sbmac_set_channel_state(sc,sbmac_state_off);
2766 del_timer_sync(&sc->sbm_timer);
2768 spin_lock_irqsave(&sc->sbm_lock, flags);
2770 netif_stop_queue(dev);
2773 printk(KERN_DEBUG "%s: Shutting down ethercard\n",dev->name);
2776 spin_unlock_irqrestore(&sc->sbm_lock, flags);
2779 synchronize_irq(irq);
2782 sbdma_emptyring(&(sc->sbm_txdma));
2783 sbdma_emptyring(&(sc->sbm_rxdma));
2790 #if defined(SBMAC_ETH0_HWADDR) || defined(SBMAC_ETH1_HWADDR) || defined(SBMAC_ETH2_HWADDR)
2792 sbmac_setup_hwaddr(int chan,char *addr)
2798 port = A_MAC_CHANNEL_BASE(chan);
2799 sbmac_parse_hwaddr(addr,eaddr);
2800 val = sbmac_addr2reg(eaddr);
2801 SBMAC_WRITECSR(IOADDR(port+R_MAC_ETHERNET_ADDR),val);
2802 val = SBMAC_READCSR(IOADDR(port+R_MAC_ETHERNET_ADDR));
2806 static struct net_device *dev_sbmac[MAX_UNITS];
2809 sbmac_init_module(void)
2812 struct net_device *dev;
2817 * For bringup when not using the firmware, we can pre-fill
2818 * the MAC addresses using the environment variables
2819 * specified in this file (or maybe from the config file?)
2821 #ifdef SBMAC_ETH0_HWADDR
2822 sbmac_setup_hwaddr(0,SBMAC_ETH0_HWADDR);
2824 #ifdef SBMAC_ETH1_HWADDR
2825 sbmac_setup_hwaddr(1,SBMAC_ETH1_HWADDR);
2827 #ifdef SBMAC_ETH2_HWADDR
2828 sbmac_setup_hwaddr(2,SBMAC_ETH2_HWADDR);
2832 * Walk through the Ethernet controllers and find
2833 * those who have their MAC addresses set.
2836 case K_SYS_SOC_TYPE_BCM1250:
2837 case K_SYS_SOC_TYPE_BCM1250_ALT:
2840 case K_SYS_SOC_TYPE_BCM1120:
2841 case K_SYS_SOC_TYPE_BCM1125:
2842 case K_SYS_SOC_TYPE_BCM1125H:
2843 case K_SYS_SOC_TYPE_BCM1250_ALT2: /* Hybrid */
2850 if (chip_max_units > MAX_UNITS)
2851 chip_max_units = MAX_UNITS;
2853 for (idx = 0; idx < chip_max_units; idx++) {
2856 * This is the base address of the MAC.
2859 port = A_MAC_CHANNEL_BASE(idx);
2862 * The R_MAC_ETHERNET_ADDR register will be set to some nonzero
2863 * value for us by the firmware if we're going to use this MAC.
2864 * If we find a zero, skip this MAC.
2867 sbmac_orig_hwaddr[idx] = SBMAC_READCSR(IOADDR(port+R_MAC_ETHERNET_ADDR));
2868 if (sbmac_orig_hwaddr[idx] == 0) {
2869 printk(KERN_DEBUG "sbmac: not configuring MAC at "
2875 * Okay, cool. Initialize this MAC.
2878 dev = alloc_etherdev(sizeof(struct sbmac_softc));
2880 return -ENOMEM; /* return ENOMEM */
2882 printk(KERN_DEBUG "sbmac: configuring MAC at %lx\n", port);
2884 dev->irq = K_INT_MAC_0 + idx;
2885 dev->base_addr = port;
2887 if (sbmac_init(dev, idx)) {
2888 port = A_MAC_CHANNEL_BASE(idx);
2889 SBMAC_WRITECSR(IOADDR(port+R_MAC_ETHERNET_ADDR),
2890 sbmac_orig_hwaddr[idx]);
2894 dev_sbmac[idx] = dev;
2901 sbmac_cleanup_module(void)
2903 struct net_device *dev;
2906 for (idx = 0; idx < MAX_UNITS; idx++) {
2907 struct sbmac_softc *sc;
2908 dev = dev_sbmac[idx];
2912 sc = netdev_priv(dev);
2913 unregister_netdev(dev);
2914 sbmac_uninitctx(sc);
2919 module_init(sbmac_init_module);
2920 module_exit(sbmac_cleanup_module);