1 /* b44.c: Broadcom 4400 device driver.
3 * Copyright (C) 2002 David S. Miller (davem@redhat.com)
4 * Fixed by Pekka Pietikainen (pp@ee.oulu.fi)
6 * Distribute under GPL.
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/moduleparam.h>
12 #include <linux/types.h>
13 #include <linux/netdevice.h>
14 #include <linux/ethtool.h>
15 #include <linux/mii.h>
16 #include <linux/if_ether.h>
17 #include <linux/etherdevice.h>
18 #include <linux/pci.h>
19 #include <linux/delay.h>
20 #include <linux/init.h>
21 #include <linux/version.h>
23 #include <asm/uaccess.h>
29 #define DRV_MODULE_NAME "b44"
30 #define PFX DRV_MODULE_NAME ": "
31 #define DRV_MODULE_VERSION "0.95"
32 #define DRV_MODULE_RELDATE "Aug 3, 2004"
34 #define B44_DEF_MSG_ENABLE \
44 /* length of time before we decide the hardware is borked,
45 * and dev->tx_timeout() should be called to fix the problem
47 #define B44_TX_TIMEOUT (5 * HZ)
49 /* hardware minimum and maximum for a single frame's data payload */
50 #define B44_MIN_MTU 60
51 #define B44_MAX_MTU 1500
53 #define B44_RX_RING_SIZE 512
54 #define B44_DEF_RX_RING_PENDING 200
55 #define B44_RX_RING_BYTES (sizeof(struct dma_desc) * \
57 #define B44_TX_RING_SIZE 512
58 #define B44_DEF_TX_RING_PENDING (B44_TX_RING_SIZE - 1)
59 #define B44_TX_RING_BYTES (sizeof(struct dma_desc) * \
61 #define B44_DMA_MASK 0x3fffffff
63 #define TX_RING_GAP(BP) \
64 (B44_TX_RING_SIZE - (BP)->tx_pending)
65 #define TX_BUFFS_AVAIL(BP) \
66 (((BP)->tx_cons <= (BP)->tx_prod) ? \
67 (BP)->tx_cons + (BP)->tx_pending - (BP)->tx_prod : \
68 (BP)->tx_cons - (BP)->tx_prod - TX_RING_GAP(BP))
69 #define NEXT_TX(N) (((N) + 1) & (B44_TX_RING_SIZE - 1))
71 #define RX_PKT_BUF_SZ (1536 + bp->rx_offset + 64)
72 #define TX_PKT_BUF_SZ (B44_MAX_MTU + ETH_HLEN + 8)
74 /* minimum number of free TX descriptors required to wake up TX process */
75 #define B44_TX_WAKEUP_THRESH (B44_TX_RING_SIZE / 4)
77 static char version
[] __devinitdata
=
78 DRV_MODULE_NAME
".c:v" DRV_MODULE_VERSION
" (" DRV_MODULE_RELDATE
")\n";
80 MODULE_AUTHOR("Florian Schirmer, Pekka Pietikainen, David S. Miller");
81 MODULE_DESCRIPTION("Broadcom 4400 10/100 PCI ethernet driver");
82 MODULE_LICENSE("GPL");
83 MODULE_VERSION(DRV_MODULE_VERSION
);
85 static int b44_debug
= -1; /* -1 == use B44_DEF_MSG_ENABLE as value */
86 module_param(b44_debug
, int, 0);
87 MODULE_PARM_DESC(b44_debug
, "B44 bitmapped debugging message enable value");
89 static struct pci_device_id b44_pci_tbl
[] = {
90 { PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_BCM4401
,
91 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
92 { PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_BCM4401B0
,
93 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
94 { PCI_VENDOR_ID_BROADCOM
, PCI_DEVICE_ID_BCM4401B1
,
95 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0UL },
96 { } /* terminate list with empty entry */
99 MODULE_DEVICE_TABLE(pci
, b44_pci_tbl
);
101 static void b44_halt(struct b44
*);
102 static void b44_init_rings(struct b44
*);
103 static void b44_init_hw(struct b44
*);
104 static int b44_poll(struct net_device
*dev
, int *budget
);
105 #ifdef CONFIG_NET_POLL_CONTROLLER
106 static void b44_poll_controller(struct net_device
*dev
);
109 static inline unsigned long br32(const struct b44
*bp
, unsigned long reg
)
111 return readl(bp
->regs
+ reg
);
114 static inline void bw32(const struct b44
*bp
,
115 unsigned long reg
, unsigned long val
)
117 writel(val
, bp
->regs
+ reg
);
120 static int b44_wait_bit(struct b44
*bp
, unsigned long reg
,
121 u32 bit
, unsigned long timeout
, const int clear
)
125 for (i
= 0; i
< timeout
; i
++) {
126 u32 val
= br32(bp
, reg
);
128 if (clear
&& !(val
& bit
))
130 if (!clear
&& (val
& bit
))
135 printk(KERN_ERR PFX
"%s: BUG! Timeout waiting for bit %08x of register "
139 (clear
? "clear" : "set"));
145 /* Sonics SiliconBackplane support routines. ROFL, you should see all the
146 * buzz words used on this company's website :-)
148 * All of these routines must be invoked with bp->lock held and
149 * interrupts disabled.
152 #define SB_PCI_DMA 0x40000000 /* Client Mode PCI memory access space (1 GB) */
153 #define BCM4400_PCI_CORE_ADDR 0x18002000 /* Address of PCI core on BCM4400 cards */
155 static u32
ssb_get_core_rev(struct b44
*bp
)
157 return (br32(bp
, B44_SBIDHIGH
) & SBIDHIGH_RC_MASK
);
160 static u32
ssb_pci_setup(struct b44
*bp
, u32 cores
)
162 u32 bar_orig
, pci_rev
, val
;
164 pci_read_config_dword(bp
->pdev
, SSB_BAR0_WIN
, &bar_orig
);
165 pci_write_config_dword(bp
->pdev
, SSB_BAR0_WIN
, BCM4400_PCI_CORE_ADDR
);
166 pci_rev
= ssb_get_core_rev(bp
);
168 val
= br32(bp
, B44_SBINTVEC
);
170 bw32(bp
, B44_SBINTVEC
, val
);
172 val
= br32(bp
, SSB_PCI_TRANS_2
);
173 val
|= SSB_PCI_PREF
| SSB_PCI_BURST
;
174 bw32(bp
, SSB_PCI_TRANS_2
, val
);
176 pci_write_config_dword(bp
->pdev
, SSB_BAR0_WIN
, bar_orig
);
181 static void ssb_core_disable(struct b44
*bp
)
183 if (br32(bp
, B44_SBTMSLOW
) & SBTMSLOW_RESET
)
186 bw32(bp
, B44_SBTMSLOW
, (SBTMSLOW_REJECT
| SBTMSLOW_CLOCK
));
187 b44_wait_bit(bp
, B44_SBTMSLOW
, SBTMSLOW_REJECT
, 100000, 0);
188 b44_wait_bit(bp
, B44_SBTMSHIGH
, SBTMSHIGH_BUSY
, 100000, 1);
189 bw32(bp
, B44_SBTMSLOW
, (SBTMSLOW_FGC
| SBTMSLOW_CLOCK
|
190 SBTMSLOW_REJECT
| SBTMSLOW_RESET
));
191 br32(bp
, B44_SBTMSLOW
);
193 bw32(bp
, B44_SBTMSLOW
, (SBTMSLOW_REJECT
| SBTMSLOW_RESET
));
194 br32(bp
, B44_SBTMSLOW
);
198 static void ssb_core_reset(struct b44
*bp
)
202 ssb_core_disable(bp
);
203 bw32(bp
, B44_SBTMSLOW
, (SBTMSLOW_RESET
| SBTMSLOW_CLOCK
| SBTMSLOW_FGC
));
204 br32(bp
, B44_SBTMSLOW
);
207 /* Clear SERR if set, this is a hw bug workaround. */
208 if (br32(bp
, B44_SBTMSHIGH
) & SBTMSHIGH_SERR
)
209 bw32(bp
, B44_SBTMSHIGH
, 0);
211 val
= br32(bp
, B44_SBIMSTATE
);
212 if (val
& (SBIMSTATE_IBE
| SBIMSTATE_TO
))
213 bw32(bp
, B44_SBIMSTATE
, val
& ~(SBIMSTATE_IBE
| SBIMSTATE_TO
));
215 bw32(bp
, B44_SBTMSLOW
, (SBTMSLOW_CLOCK
| SBTMSLOW_FGC
));
216 br32(bp
, B44_SBTMSLOW
);
219 bw32(bp
, B44_SBTMSLOW
, (SBTMSLOW_CLOCK
));
220 br32(bp
, B44_SBTMSLOW
);
224 static int ssb_core_unit(struct b44
*bp
)
227 u32 val
= br32(bp
, B44_SBADMATCH0
);
230 type
= val
& SBADMATCH0_TYPE_MASK
;
233 base
= val
& SBADMATCH0_BS0_MASK
;
237 base
= val
& SBADMATCH0_BS1_MASK
;
242 base
= val
& SBADMATCH0_BS2_MASK
;
249 static int ssb_is_core_up(struct b44
*bp
)
251 return ((br32(bp
, B44_SBTMSLOW
) & (SBTMSLOW_RESET
| SBTMSLOW_REJECT
| SBTMSLOW_CLOCK
))
255 static void __b44_cam_write(struct b44
*bp
, unsigned char *data
, int index
)
259 val
= ((u32
) data
[2]) << 24;
260 val
|= ((u32
) data
[3]) << 16;
261 val
|= ((u32
) data
[4]) << 8;
262 val
|= ((u32
) data
[5]) << 0;
263 bw32(bp
, B44_CAM_DATA_LO
, val
);
264 val
= (CAM_DATA_HI_VALID
|
265 (((u32
) data
[0]) << 8) |
266 (((u32
) data
[1]) << 0));
267 bw32(bp
, B44_CAM_DATA_HI
, val
);
268 bw32(bp
, B44_CAM_CTRL
, (CAM_CTRL_WRITE
|
269 (index
<< CAM_CTRL_INDEX_SHIFT
)));
270 b44_wait_bit(bp
, B44_CAM_CTRL
, CAM_CTRL_BUSY
, 100, 1);
273 static inline void __b44_disable_ints(struct b44
*bp
)
275 bw32(bp
, B44_IMASK
, 0);
278 static void b44_disable_ints(struct b44
*bp
)
280 __b44_disable_ints(bp
);
282 /* Flush posted writes. */
286 static void b44_enable_ints(struct b44
*bp
)
288 bw32(bp
, B44_IMASK
, bp
->imask
);
291 static int b44_readphy(struct b44
*bp
, int reg
, u32
*val
)
295 bw32(bp
, B44_EMAC_ISTAT
, EMAC_INT_MII
);
296 bw32(bp
, B44_MDIO_DATA
, (MDIO_DATA_SB_START
|
297 (MDIO_OP_READ
<< MDIO_DATA_OP_SHIFT
) |
298 (bp
->phy_addr
<< MDIO_DATA_PMD_SHIFT
) |
299 (reg
<< MDIO_DATA_RA_SHIFT
) |
300 (MDIO_TA_VALID
<< MDIO_DATA_TA_SHIFT
)));
301 err
= b44_wait_bit(bp
, B44_EMAC_ISTAT
, EMAC_INT_MII
, 100, 0);
302 *val
= br32(bp
, B44_MDIO_DATA
) & MDIO_DATA_DATA
;
307 static int b44_writephy(struct b44
*bp
, int reg
, u32 val
)
309 bw32(bp
, B44_EMAC_ISTAT
, EMAC_INT_MII
);
310 bw32(bp
, B44_MDIO_DATA
, (MDIO_DATA_SB_START
|
311 (MDIO_OP_WRITE
<< MDIO_DATA_OP_SHIFT
) |
312 (bp
->phy_addr
<< MDIO_DATA_PMD_SHIFT
) |
313 (reg
<< MDIO_DATA_RA_SHIFT
) |
314 (MDIO_TA_VALID
<< MDIO_DATA_TA_SHIFT
) |
315 (val
& MDIO_DATA_DATA
)));
316 return b44_wait_bit(bp
, B44_EMAC_ISTAT
, EMAC_INT_MII
, 100, 0);
319 /* miilib interface */
320 /* FIXME FIXME: phy_id is ignored, bp->phy_addr use is unconditional
321 * due to code existing before miilib use was added to this driver.
322 * Someone should remove this artificial driver limitation in
323 * b44_{read,write}phy. bp->phy_addr itself is fine (and needed).
325 static int b44_mii_read(struct net_device
*dev
, int phy_id
, int location
)
328 struct b44
*bp
= netdev_priv(dev
);
329 int rc
= b44_readphy(bp
, location
, &val
);
335 static void b44_mii_write(struct net_device
*dev
, int phy_id
, int location
,
338 struct b44
*bp
= netdev_priv(dev
);
339 b44_writephy(bp
, location
, val
);
342 static int b44_phy_reset(struct b44
*bp
)
347 err
= b44_writephy(bp
, MII_BMCR
, BMCR_RESET
);
351 err
= b44_readphy(bp
, MII_BMCR
, &val
);
353 if (val
& BMCR_RESET
) {
354 printk(KERN_ERR PFX
"%s: PHY Reset would not complete.\n",
363 static void __b44_set_flow_ctrl(struct b44
*bp
, u32 pause_flags
)
367 bp
->flags
&= ~(B44_FLAG_TX_PAUSE
| B44_FLAG_RX_PAUSE
);
368 bp
->flags
|= pause_flags
;
370 val
= br32(bp
, B44_RXCONFIG
);
371 if (pause_flags
& B44_FLAG_RX_PAUSE
)
372 val
|= RXCONFIG_FLOW
;
374 val
&= ~RXCONFIG_FLOW
;
375 bw32(bp
, B44_RXCONFIG
, val
);
377 val
= br32(bp
, B44_MAC_FLOW
);
378 if (pause_flags
& B44_FLAG_TX_PAUSE
)
379 val
|= (MAC_FLOW_PAUSE_ENAB
|
380 (0xc0 & MAC_FLOW_RX_HI_WATER
));
382 val
&= ~MAC_FLOW_PAUSE_ENAB
;
383 bw32(bp
, B44_MAC_FLOW
, val
);
386 static void b44_set_flow_ctrl(struct b44
*bp
, u32 local
, u32 remote
)
388 u32 pause_enab
= bp
->flags
& (B44_FLAG_TX_PAUSE
|
391 if (local
& ADVERTISE_PAUSE_CAP
) {
392 if (local
& ADVERTISE_PAUSE_ASYM
) {
393 if (remote
& LPA_PAUSE_CAP
)
394 pause_enab
|= (B44_FLAG_TX_PAUSE
|
396 else if (remote
& LPA_PAUSE_ASYM
)
397 pause_enab
|= B44_FLAG_RX_PAUSE
;
399 if (remote
& LPA_PAUSE_CAP
)
400 pause_enab
|= (B44_FLAG_TX_PAUSE
|
403 } else if (local
& ADVERTISE_PAUSE_ASYM
) {
404 if ((remote
& LPA_PAUSE_CAP
) &&
405 (remote
& LPA_PAUSE_ASYM
))
406 pause_enab
|= B44_FLAG_TX_PAUSE
;
409 __b44_set_flow_ctrl(bp
, pause_enab
);
412 static int b44_setup_phy(struct b44
*bp
)
417 if ((err
= b44_readphy(bp
, B44_MII_ALEDCTRL
, &val
)) != 0)
419 if ((err
= b44_writephy(bp
, B44_MII_ALEDCTRL
,
420 val
& MII_ALEDCTRL_ALLMSK
)) != 0)
422 if ((err
= b44_readphy(bp
, B44_MII_TLEDCTRL
, &val
)) != 0)
424 if ((err
= b44_writephy(bp
, B44_MII_TLEDCTRL
,
425 val
| MII_TLEDCTRL_ENABLE
)) != 0)
428 if (!(bp
->flags
& B44_FLAG_FORCE_LINK
)) {
429 u32 adv
= ADVERTISE_CSMA
;
431 if (bp
->flags
& B44_FLAG_ADV_10HALF
)
432 adv
|= ADVERTISE_10HALF
;
433 if (bp
->flags
& B44_FLAG_ADV_10FULL
)
434 adv
|= ADVERTISE_10FULL
;
435 if (bp
->flags
& B44_FLAG_ADV_100HALF
)
436 adv
|= ADVERTISE_100HALF
;
437 if (bp
->flags
& B44_FLAG_ADV_100FULL
)
438 adv
|= ADVERTISE_100FULL
;
440 if (bp
->flags
& B44_FLAG_PAUSE_AUTO
)
441 adv
|= ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
;
443 if ((err
= b44_writephy(bp
, MII_ADVERTISE
, adv
)) != 0)
445 if ((err
= b44_writephy(bp
, MII_BMCR
, (BMCR_ANENABLE
|
446 BMCR_ANRESTART
))) != 0)
451 if ((err
= b44_readphy(bp
, MII_BMCR
, &bmcr
)) != 0)
453 bmcr
&= ~(BMCR_FULLDPLX
| BMCR_ANENABLE
| BMCR_SPEED100
);
454 if (bp
->flags
& B44_FLAG_100_BASE_T
)
455 bmcr
|= BMCR_SPEED100
;
456 if (bp
->flags
& B44_FLAG_FULL_DUPLEX
)
457 bmcr
|= BMCR_FULLDPLX
;
458 if ((err
= b44_writephy(bp
, MII_BMCR
, bmcr
)) != 0)
461 /* Since we will not be negotiating there is no safe way
462 * to determine if the link partner supports flow control
463 * or not. So just disable it completely in this case.
465 b44_set_flow_ctrl(bp
, 0, 0);
472 static void b44_stats_update(struct b44
*bp
)
477 val
= &bp
->hw_stats
.tx_good_octets
;
478 for (reg
= B44_TX_GOOD_O
; reg
<= B44_TX_PAUSE
; reg
+= 4UL) {
479 *val
++ += br32(bp
, reg
);
481 val
= &bp
->hw_stats
.rx_good_octets
;
482 for (reg
= B44_RX_GOOD_O
; reg
<= B44_RX_NPAUSE
; reg
+= 4UL) {
483 *val
++ += br32(bp
, reg
);
487 static void b44_link_report(struct b44
*bp
)
489 if (!netif_carrier_ok(bp
->dev
)) {
490 printk(KERN_INFO PFX
"%s: Link is down.\n", bp
->dev
->name
);
492 printk(KERN_INFO PFX
"%s: Link is up at %d Mbps, %s duplex.\n",
494 (bp
->flags
& B44_FLAG_100_BASE_T
) ? 100 : 10,
495 (bp
->flags
& B44_FLAG_FULL_DUPLEX
) ? "full" : "half");
497 printk(KERN_INFO PFX
"%s: Flow control is %s for TX and "
500 (bp
->flags
& B44_FLAG_TX_PAUSE
) ? "on" : "off",
501 (bp
->flags
& B44_FLAG_RX_PAUSE
) ? "on" : "off");
505 static void b44_check_phy(struct b44
*bp
)
509 if (!b44_readphy(bp
, MII_BMSR
, &bmsr
) &&
510 !b44_readphy(bp
, B44_MII_AUXCTRL
, &aux
) &&
512 if (aux
& MII_AUXCTRL_SPEED
)
513 bp
->flags
|= B44_FLAG_100_BASE_T
;
515 bp
->flags
&= ~B44_FLAG_100_BASE_T
;
516 if (aux
& MII_AUXCTRL_DUPLEX
)
517 bp
->flags
|= B44_FLAG_FULL_DUPLEX
;
519 bp
->flags
&= ~B44_FLAG_FULL_DUPLEX
;
521 if (!netif_carrier_ok(bp
->dev
) &&
522 (bmsr
& BMSR_LSTATUS
)) {
523 u32 val
= br32(bp
, B44_TX_CTRL
);
524 u32 local_adv
, remote_adv
;
526 if (bp
->flags
& B44_FLAG_FULL_DUPLEX
)
527 val
|= TX_CTRL_DUPLEX
;
529 val
&= ~TX_CTRL_DUPLEX
;
530 bw32(bp
, B44_TX_CTRL
, val
);
532 if (!(bp
->flags
& B44_FLAG_FORCE_LINK
) &&
533 !b44_readphy(bp
, MII_ADVERTISE
, &local_adv
) &&
534 !b44_readphy(bp
, MII_LPA
, &remote_adv
))
535 b44_set_flow_ctrl(bp
, local_adv
, remote_adv
);
538 netif_carrier_on(bp
->dev
);
540 } else if (netif_carrier_ok(bp
->dev
) && !(bmsr
& BMSR_LSTATUS
)) {
542 netif_carrier_off(bp
->dev
);
546 if (bmsr
& BMSR_RFAULT
)
547 printk(KERN_WARNING PFX
"%s: Remote fault detected in PHY\n",
550 printk(KERN_WARNING PFX
"%s: Jabber detected in PHY\n",
555 static void b44_timer(unsigned long __opaque
)
557 struct b44
*bp
= (struct b44
*) __opaque
;
559 spin_lock_irq(&bp
->lock
);
563 b44_stats_update(bp
);
565 spin_unlock_irq(&bp
->lock
);
567 bp
->timer
.expires
= jiffies
+ HZ
;
568 add_timer(&bp
->timer
);
571 static void b44_tx(struct b44
*bp
)
575 cur
= br32(bp
, B44_DMATX_STAT
) & DMATX_STAT_CDMASK
;
576 cur
/= sizeof(struct dma_desc
);
578 /* XXX needs updating when NETIF_F_SG is supported */
579 for (cons
= bp
->tx_cons
; cons
!= cur
; cons
= NEXT_TX(cons
)) {
580 struct ring_info
*rp
= &bp
->tx_buffers
[cons
];
581 struct sk_buff
*skb
= rp
->skb
;
583 if (unlikely(skb
== NULL
))
586 pci_unmap_single(bp
->pdev
,
587 pci_unmap_addr(rp
, mapping
),
591 dev_kfree_skb_irq(skb
);
595 if (netif_queue_stopped(bp
->dev
) &&
596 TX_BUFFS_AVAIL(bp
) > B44_TX_WAKEUP_THRESH
)
597 netif_wake_queue(bp
->dev
);
599 bw32(bp
, B44_GPTIMER
, 0);
602 /* Works like this. This chip writes a 'struct rx_header" 30 bytes
603 * before the DMA address you give it. So we allocate 30 more bytes
604 * for the RX buffer, DMA map all of it, skb_reserve the 30 bytes, then
605 * point the chip at 30 bytes past where the rx_header will go.
607 static int b44_alloc_rx_skb(struct b44
*bp
, int src_idx
, u32 dest_idx_unmasked
)
610 struct ring_info
*src_map
, *map
;
611 struct rx_header
*rh
;
619 src_map
= &bp
->rx_buffers
[src_idx
];
620 dest_idx
= dest_idx_unmasked
& (B44_RX_RING_SIZE
- 1);
621 map
= &bp
->rx_buffers
[dest_idx
];
622 skb
= dev_alloc_skb(RX_PKT_BUF_SZ
);
626 mapping
= pci_map_single(bp
->pdev
, skb
->data
,
630 /* Hardware bug work-around, the chip is unable to do PCI DMA
631 to/from anything above 1GB :-( */
632 if(mapping
+RX_PKT_BUF_SZ
> B44_DMA_MASK
) {
634 pci_unmap_single(bp
->pdev
, mapping
, RX_PKT_BUF_SZ
,PCI_DMA_FROMDEVICE
);
635 dev_kfree_skb_any(skb
);
636 skb
= __dev_alloc_skb(RX_PKT_BUF_SZ
,GFP_DMA
);
639 mapping
= pci_map_single(bp
->pdev
, skb
->data
,
642 if(mapping
+RX_PKT_BUF_SZ
> B44_DMA_MASK
) {
643 pci_unmap_single(bp
->pdev
, mapping
, RX_PKT_BUF_SZ
,PCI_DMA_FROMDEVICE
);
644 dev_kfree_skb_any(skb
);
650 skb_reserve(skb
, bp
->rx_offset
);
652 rh
= (struct rx_header
*)
653 (skb
->data
- bp
->rx_offset
);
658 pci_unmap_addr_set(map
, mapping
, mapping
);
663 ctrl
= (DESC_CTRL_LEN
& (RX_PKT_BUF_SZ
- bp
->rx_offset
));
664 if (dest_idx
== (B44_RX_RING_SIZE
- 1))
665 ctrl
|= DESC_CTRL_EOT
;
667 dp
= &bp
->rx_ring
[dest_idx
];
668 dp
->ctrl
= cpu_to_le32(ctrl
);
669 dp
->addr
= cpu_to_le32((u32
) mapping
+ bp
->rx_offset
+ bp
->dma_offset
);
671 return RX_PKT_BUF_SZ
;
674 static void b44_recycle_rx(struct b44
*bp
, int src_idx
, u32 dest_idx_unmasked
)
676 struct dma_desc
*src_desc
, *dest_desc
;
677 struct ring_info
*src_map
, *dest_map
;
678 struct rx_header
*rh
;
682 dest_idx
= dest_idx_unmasked
& (B44_RX_RING_SIZE
- 1);
683 dest_desc
= &bp
->rx_ring
[dest_idx
];
684 dest_map
= &bp
->rx_buffers
[dest_idx
];
685 src_desc
= &bp
->rx_ring
[src_idx
];
686 src_map
= &bp
->rx_buffers
[src_idx
];
688 dest_map
->skb
= src_map
->skb
;
689 rh
= (struct rx_header
*) src_map
->skb
->data
;
692 pci_unmap_addr_set(dest_map
, mapping
,
693 pci_unmap_addr(src_map
, mapping
));
695 ctrl
= src_desc
->ctrl
;
696 if (dest_idx
== (B44_RX_RING_SIZE
- 1))
697 ctrl
|= cpu_to_le32(DESC_CTRL_EOT
);
699 ctrl
&= cpu_to_le32(~DESC_CTRL_EOT
);
701 dest_desc
->ctrl
= ctrl
;
702 dest_desc
->addr
= src_desc
->addr
;
705 pci_dma_sync_single_for_device(bp
->pdev
, src_desc
->addr
,
710 static int b44_rx(struct b44
*bp
, int budget
)
716 prod
= br32(bp
, B44_DMARX_STAT
) & DMARX_STAT_CDMASK
;
717 prod
/= sizeof(struct dma_desc
);
720 while (cons
!= prod
&& budget
> 0) {
721 struct ring_info
*rp
= &bp
->rx_buffers
[cons
];
722 struct sk_buff
*skb
= rp
->skb
;
723 dma_addr_t map
= pci_unmap_addr(rp
, mapping
);
724 struct rx_header
*rh
;
727 pci_dma_sync_single_for_cpu(bp
->pdev
, map
,
730 rh
= (struct rx_header
*) skb
->data
;
731 len
= cpu_to_le16(rh
->len
);
732 if ((len
> (RX_PKT_BUF_SZ
- bp
->rx_offset
)) ||
733 (rh
->flags
& cpu_to_le16(RX_FLAG_ERRORS
))) {
735 b44_recycle_rx(bp
, cons
, bp
->rx_prod
);
737 bp
->stats
.rx_dropped
++;
747 len
= cpu_to_le16(rh
->len
);
748 } while (len
== 0 && i
++ < 5);
756 if (len
> RX_COPY_THRESHOLD
) {
758 skb_size
= b44_alloc_rx_skb(bp
, cons
, bp
->rx_prod
);
761 pci_unmap_single(bp
->pdev
, map
,
762 skb_size
, PCI_DMA_FROMDEVICE
);
763 /* Leave out rx_header */
764 skb_put(skb
, len
+bp
->rx_offset
);
765 skb_pull(skb
,bp
->rx_offset
);
767 struct sk_buff
*copy_skb
;
769 b44_recycle_rx(bp
, cons
, bp
->rx_prod
);
770 copy_skb
= dev_alloc_skb(len
+ 2);
771 if (copy_skb
== NULL
)
772 goto drop_it_no_recycle
;
774 copy_skb
->dev
= bp
->dev
;
775 skb_reserve(copy_skb
, 2);
776 skb_put(copy_skb
, len
);
777 /* DMA sync done above, copy just the actual packet */
778 memcpy(copy_skb
->data
, skb
->data
+bp
->rx_offset
, len
);
782 skb
->ip_summed
= CHECKSUM_NONE
;
783 skb
->protocol
= eth_type_trans(skb
, bp
->dev
);
784 netif_receive_skb(skb
);
785 bp
->dev
->last_rx
= jiffies
;
789 bp
->rx_prod
= (bp
->rx_prod
+ 1) &
790 (B44_RX_RING_SIZE
- 1);
791 cons
= (cons
+ 1) & (B44_RX_RING_SIZE
- 1);
795 bw32(bp
, B44_DMARX_PTR
, cons
* sizeof(struct dma_desc
));
800 static int b44_poll(struct net_device
*netdev
, int *budget
)
802 struct b44
*bp
= netdev_priv(netdev
);
805 spin_lock_irq(&bp
->lock
);
807 if (bp
->istat
& (ISTAT_TX
| ISTAT_TO
)) {
808 /* spin_lock(&bp->tx_lock); */
810 /* spin_unlock(&bp->tx_lock); */
812 spin_unlock_irq(&bp
->lock
);
815 if (bp
->istat
& ISTAT_RX
) {
816 int orig_budget
= *budget
;
819 if (orig_budget
> netdev
->quota
)
820 orig_budget
= netdev
->quota
;
822 work_done
= b44_rx(bp
, orig_budget
);
824 *budget
-= work_done
;
825 netdev
->quota
-= work_done
;
827 if (work_done
>= orig_budget
)
831 if (bp
->istat
& ISTAT_ERRORS
) {
832 spin_lock_irq(&bp
->lock
);
836 netif_wake_queue(bp
->dev
);
837 spin_unlock_irq(&bp
->lock
);
842 netif_rx_complete(netdev
);
846 return (done
? 0 : 1);
849 static irqreturn_t
b44_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
851 struct net_device
*dev
= dev_id
;
852 struct b44
*bp
= netdev_priv(dev
);
857 spin_lock_irqsave(&bp
->lock
, flags
);
859 istat
= br32(bp
, B44_ISTAT
);
860 imask
= br32(bp
, B44_IMASK
);
862 /* ??? What the fuck is the purpose of the interrupt mask
863 * ??? register if we have to mask it out by hand anyways?
868 if (netif_rx_schedule_prep(dev
)) {
869 /* NOTE: These writes are posted by the readback of
870 * the ISTAT register below.
873 __b44_disable_ints(bp
);
874 __netif_rx_schedule(dev
);
876 printk(KERN_ERR PFX
"%s: Error, poll already scheduled\n",
880 bw32(bp
, B44_ISTAT
, istat
);
883 spin_unlock_irqrestore(&bp
->lock
, flags
);
884 return IRQ_RETVAL(handled
);
887 static void b44_tx_timeout(struct net_device
*dev
)
889 struct b44
*bp
= netdev_priv(dev
);
891 printk(KERN_ERR PFX
"%s: transmit timed out, resetting\n",
894 spin_lock_irq(&bp
->lock
);
900 spin_unlock_irq(&bp
->lock
);
904 netif_wake_queue(dev
);
907 static int b44_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
909 struct b44
*bp
= netdev_priv(dev
);
910 struct sk_buff
*bounce_skb
;
912 u32 len
, entry
, ctrl
;
915 spin_lock_irq(&bp
->lock
);
917 /* This is a hard error, log it. */
918 if (unlikely(TX_BUFFS_AVAIL(bp
) < 1)) {
919 netif_stop_queue(dev
);
920 spin_unlock_irq(&bp
->lock
);
921 printk(KERN_ERR PFX
"%s: BUG! Tx Ring full when queue awake!\n",
926 mapping
= pci_map_single(bp
->pdev
, skb
->data
, len
, PCI_DMA_TODEVICE
);
927 if(mapping
+len
> B44_DMA_MASK
) {
928 /* Chip can't handle DMA to/from >1GB, use bounce buffer */
929 pci_unmap_single(bp
->pdev
, mapping
, len
, PCI_DMA_TODEVICE
);
931 bounce_skb
= __dev_alloc_skb(TX_PKT_BUF_SZ
,
934 return NETDEV_TX_BUSY
;
936 mapping
= pci_map_single(bp
->pdev
, bounce_skb
->data
,
937 len
, PCI_DMA_TODEVICE
);
938 if(mapping
+len
> B44_DMA_MASK
) {
939 pci_unmap_single(bp
->pdev
, mapping
,
940 len
, PCI_DMA_TODEVICE
);
941 dev_kfree_skb_any(bounce_skb
);
942 return NETDEV_TX_BUSY
;
945 memcpy(skb_put(bounce_skb
, len
), skb
->data
, skb
->len
);
946 dev_kfree_skb_any(skb
);
951 bp
->tx_buffers
[entry
].skb
= skb
;
952 pci_unmap_addr_set(&bp
->tx_buffers
[entry
], mapping
, mapping
);
954 ctrl
= (len
& DESC_CTRL_LEN
);
955 ctrl
|= DESC_CTRL_IOC
| DESC_CTRL_SOF
| DESC_CTRL_EOF
;
956 if (entry
== (B44_TX_RING_SIZE
- 1))
957 ctrl
|= DESC_CTRL_EOT
;
959 bp
->tx_ring
[entry
].ctrl
= cpu_to_le32(ctrl
);
960 bp
->tx_ring
[entry
].addr
= cpu_to_le32((u32
) mapping
+bp
->dma_offset
);
962 entry
= NEXT_TX(entry
);
968 bw32(bp
, B44_DMATX_PTR
, entry
* sizeof(struct dma_desc
));
969 if (bp
->flags
& B44_FLAG_BUGGY_TXPTR
)
970 bw32(bp
, B44_DMATX_PTR
, entry
* sizeof(struct dma_desc
));
971 if (bp
->flags
& B44_FLAG_REORDER_BUG
)
972 br32(bp
, B44_DMATX_PTR
);
974 if (TX_BUFFS_AVAIL(bp
) < 1)
975 netif_stop_queue(dev
);
977 spin_unlock_irq(&bp
->lock
);
979 dev
->trans_start
= jiffies
;
984 static int b44_change_mtu(struct net_device
*dev
, int new_mtu
)
986 struct b44
*bp
= netdev_priv(dev
);
988 if (new_mtu
< B44_MIN_MTU
|| new_mtu
> B44_MAX_MTU
)
991 if (!netif_running(dev
)) {
992 /* We'll just catch it later when the
999 spin_lock_irq(&bp
->lock
);
1004 spin_unlock_irq(&bp
->lock
);
1006 b44_enable_ints(bp
);
1011 /* Free up pending packets in all rx/tx rings.
1013 * The chip has been shut down and the driver detached from
1014 * the networking, so no interrupts or new tx packets will
1015 * end up in the driver. bp->lock is not held and we are not
1016 * in an interrupt context and thus may sleep.
1018 static void b44_free_rings(struct b44
*bp
)
1020 struct ring_info
*rp
;
1023 for (i
= 0; i
< B44_RX_RING_SIZE
; i
++) {
1024 rp
= &bp
->rx_buffers
[i
];
1026 if (rp
->skb
== NULL
)
1028 pci_unmap_single(bp
->pdev
,
1029 pci_unmap_addr(rp
, mapping
),
1031 PCI_DMA_FROMDEVICE
);
1032 dev_kfree_skb_any(rp
->skb
);
1036 /* XXX needs changes once NETIF_F_SG is set... */
1037 for (i
= 0; i
< B44_TX_RING_SIZE
; i
++) {
1038 rp
= &bp
->tx_buffers
[i
];
1040 if (rp
->skb
== NULL
)
1042 pci_unmap_single(bp
->pdev
,
1043 pci_unmap_addr(rp
, mapping
),
1046 dev_kfree_skb_any(rp
->skb
);
1051 /* Initialize tx/rx rings for packet processing.
1053 * The chip has been shut down and the driver detached from
1054 * the networking, so no interrupts or new tx packets will
1055 * end up in the driver. bp->lock is not held and we are not
1056 * in an interrupt context and thus may sleep.
1058 static void b44_init_rings(struct b44
*bp
)
1064 memset(bp
->rx_ring
, 0, B44_RX_RING_BYTES
);
1065 memset(bp
->tx_ring
, 0, B44_TX_RING_BYTES
);
1067 for (i
= 0; i
< bp
->rx_pending
; i
++) {
1068 if (b44_alloc_rx_skb(bp
, -1, i
) < 0)
1074 * Must not be invoked with interrupt sources disabled and
1075 * the hardware shutdown down.
1077 static void b44_free_consistent(struct b44
*bp
)
1079 if (bp
->rx_buffers
) {
1080 kfree(bp
->rx_buffers
);
1081 bp
->rx_buffers
= NULL
;
1083 if (bp
->tx_buffers
) {
1084 kfree(bp
->tx_buffers
);
1085 bp
->tx_buffers
= NULL
;
1088 pci_free_consistent(bp
->pdev
, DMA_TABLE_BYTES
,
1089 bp
->rx_ring
, bp
->rx_ring_dma
);
1093 pci_free_consistent(bp
->pdev
, DMA_TABLE_BYTES
,
1094 bp
->tx_ring
, bp
->tx_ring_dma
);
1100 * Must not be invoked with interrupt sources disabled and
1101 * the hardware shutdown down. Can sleep.
1103 static int b44_alloc_consistent(struct b44
*bp
)
1107 size
= B44_RX_RING_SIZE
* sizeof(struct ring_info
);
1108 bp
->rx_buffers
= kmalloc(size
, GFP_KERNEL
);
1109 if (!bp
->rx_buffers
)
1111 memset(bp
->rx_buffers
, 0, size
);
1113 size
= B44_TX_RING_SIZE
* sizeof(struct ring_info
);
1114 bp
->tx_buffers
= kmalloc(size
, GFP_KERNEL
);
1115 if (!bp
->tx_buffers
)
1117 memset(bp
->tx_buffers
, 0, size
);
1119 size
= DMA_TABLE_BYTES
;
1120 bp
->rx_ring
= pci_alloc_consistent(bp
->pdev
, size
, &bp
->rx_ring_dma
);
1124 bp
->tx_ring
= pci_alloc_consistent(bp
->pdev
, size
, &bp
->tx_ring_dma
);
1131 b44_free_consistent(bp
);
1135 /* bp->lock is held. */
1136 static void b44_clear_stats(struct b44
*bp
)
1140 bw32(bp
, B44_MIB_CTRL
, MIB_CTRL_CLR_ON_READ
);
1141 for (reg
= B44_TX_GOOD_O
; reg
<= B44_TX_PAUSE
; reg
+= 4UL)
1143 for (reg
= B44_RX_GOOD_O
; reg
<= B44_RX_NPAUSE
; reg
+= 4UL)
1147 /* bp->lock is held. */
1148 static void b44_chip_reset(struct b44
*bp
)
1150 if (ssb_is_core_up(bp
)) {
1151 bw32(bp
, B44_RCV_LAZY
, 0);
1152 bw32(bp
, B44_ENET_CTRL
, ENET_CTRL_DISABLE
);
1153 b44_wait_bit(bp
, B44_ENET_CTRL
, ENET_CTRL_DISABLE
, 100, 1);
1154 bw32(bp
, B44_DMATX_CTRL
, 0);
1155 bp
->tx_prod
= bp
->tx_cons
= 0;
1156 if (br32(bp
, B44_DMARX_STAT
) & DMARX_STAT_EMASK
) {
1157 b44_wait_bit(bp
, B44_DMARX_STAT
, DMARX_STAT_SIDLE
,
1160 bw32(bp
, B44_DMARX_CTRL
, 0);
1161 bp
->rx_prod
= bp
->rx_cons
= 0;
1163 ssb_pci_setup(bp
, (bp
->core_unit
== 0 ?
1170 b44_clear_stats(bp
);
1172 /* Make PHY accessible. */
1173 bw32(bp
, B44_MDIO_CTRL
, (MDIO_CTRL_PREAMBLE
|
1174 (0x0d & MDIO_CTRL_MAXF_MASK
)));
1175 br32(bp
, B44_MDIO_CTRL
);
1177 if (!(br32(bp
, B44_DEVCTRL
) & DEVCTRL_IPP
)) {
1178 bw32(bp
, B44_ENET_CTRL
, ENET_CTRL_EPSEL
);
1179 br32(bp
, B44_ENET_CTRL
);
1180 bp
->flags
&= ~B44_FLAG_INTERNAL_PHY
;
1182 u32 val
= br32(bp
, B44_DEVCTRL
);
1184 if (val
& DEVCTRL_EPR
) {
1185 bw32(bp
, B44_DEVCTRL
, (val
& ~DEVCTRL_EPR
));
1186 br32(bp
, B44_DEVCTRL
);
1189 bp
->flags
|= B44_FLAG_INTERNAL_PHY
;
1193 /* bp->lock is held. */
1194 static void b44_halt(struct b44
*bp
)
1196 b44_disable_ints(bp
);
1200 /* bp->lock is held. */
1201 static void __b44_set_mac_addr(struct b44
*bp
)
1203 bw32(bp
, B44_CAM_CTRL
, 0);
1204 if (!(bp
->dev
->flags
& IFF_PROMISC
)) {
1207 __b44_cam_write(bp
, bp
->dev
->dev_addr
, 0);
1208 val
= br32(bp
, B44_CAM_CTRL
);
1209 bw32(bp
, B44_CAM_CTRL
, val
| CAM_CTRL_ENABLE
);
1213 static int b44_set_mac_addr(struct net_device
*dev
, void *p
)
1215 struct b44
*bp
= netdev_priv(dev
);
1216 struct sockaddr
*addr
= p
;
1218 if (netif_running(dev
))
1221 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
1223 spin_lock_irq(&bp
->lock
);
1224 __b44_set_mac_addr(bp
);
1225 spin_unlock_irq(&bp
->lock
);
1230 /* Called at device open time to get the chip ready for
1231 * packet processing. Invoked with bp->lock held.
1233 static void __b44_set_rx_mode(struct net_device
*);
1234 static void b44_init_hw(struct b44
*bp
)
1242 /* Enable CRC32, set proper LED modes and power on PHY */
1243 bw32(bp
, B44_MAC_CTRL
, MAC_CTRL_CRC32_ENAB
| MAC_CTRL_PHY_LEDCTRL
);
1244 bw32(bp
, B44_RCV_LAZY
, (1 << RCV_LAZY_FC_SHIFT
));
1246 /* This sets the MAC address too. */
1247 __b44_set_rx_mode(bp
->dev
);
1249 /* MTU + eth header + possible VLAN tag + struct rx_header */
1250 bw32(bp
, B44_RXMAXLEN
, bp
->dev
->mtu
+ ETH_HLEN
+ 8 + RX_HEADER_LEN
);
1251 bw32(bp
, B44_TXMAXLEN
, bp
->dev
->mtu
+ ETH_HLEN
+ 8 + RX_HEADER_LEN
);
1253 bw32(bp
, B44_TX_WMARK
, 56); /* XXX magic */
1254 bw32(bp
, B44_DMATX_CTRL
, DMATX_CTRL_ENABLE
);
1255 bw32(bp
, B44_DMATX_ADDR
, bp
->tx_ring_dma
+ bp
->dma_offset
);
1256 bw32(bp
, B44_DMARX_CTRL
, (DMARX_CTRL_ENABLE
|
1257 (bp
->rx_offset
<< DMARX_CTRL_ROSHIFT
)));
1258 bw32(bp
, B44_DMARX_ADDR
, bp
->rx_ring_dma
+ bp
->dma_offset
);
1260 bw32(bp
, B44_DMARX_PTR
, bp
->rx_pending
);
1261 bp
->rx_prod
= bp
->rx_pending
;
1263 bw32(bp
, B44_MIB_CTRL
, MIB_CTRL_CLR_ON_READ
);
1265 val
= br32(bp
, B44_ENET_CTRL
);
1266 bw32(bp
, B44_ENET_CTRL
, (val
| ENET_CTRL_ENABLE
));
1269 static int b44_open(struct net_device
*dev
)
1271 struct b44
*bp
= netdev_priv(dev
);
1274 err
= b44_alloc_consistent(bp
);
1278 err
= request_irq(dev
->irq
, b44_interrupt
, SA_SHIRQ
, dev
->name
, dev
);
1282 spin_lock_irq(&bp
->lock
);
1286 bp
->flags
|= B44_FLAG_INIT_COMPLETE
;
1288 netif_carrier_off(dev
);
1291 spin_unlock_irq(&bp
->lock
);
1293 init_timer(&bp
->timer
);
1294 bp
->timer
.expires
= jiffies
+ HZ
;
1295 bp
->timer
.data
= (unsigned long) bp
;
1296 bp
->timer
.function
= b44_timer
;
1297 add_timer(&bp
->timer
);
1299 b44_enable_ints(bp
);
1304 b44_free_consistent(bp
);
1309 /*static*/ void b44_dump_state(struct b44
*bp
)
1311 u32 val32
, val32_2
, val32_3
, val32_4
, val32_5
;
1314 pci_read_config_word(bp
->pdev
, PCI_STATUS
, &val16
);
1315 printk("DEBUG: PCI status [%04x] \n", val16
);
1320 #ifdef CONFIG_NET_POLL_CONTROLLER
1322 * Polling receive - used by netconsole and other diagnostic tools
1323 * to allow network i/o with interrupts disabled.
1325 static void b44_poll_controller(struct net_device
*dev
)
1327 disable_irq(dev
->irq
);
1328 b44_interrupt(dev
->irq
, dev
, NULL
);
1329 enable_irq(dev
->irq
);
1333 static int b44_close(struct net_device
*dev
)
1335 struct b44
*bp
= netdev_priv(dev
);
1337 netif_stop_queue(dev
);
1339 del_timer_sync(&bp
->timer
);
1341 spin_lock_irq(&bp
->lock
);
1348 bp
->flags
&= ~B44_FLAG_INIT_COMPLETE
;
1349 netif_carrier_off(bp
->dev
);
1351 spin_unlock_irq(&bp
->lock
);
1353 free_irq(dev
->irq
, dev
);
1355 b44_free_consistent(bp
);
1360 static struct net_device_stats
*b44_get_stats(struct net_device
*dev
)
1362 struct b44
*bp
= netdev_priv(dev
);
1363 struct net_device_stats
*nstat
= &bp
->stats
;
1364 struct b44_hw_stats
*hwstat
= &bp
->hw_stats
;
1366 /* Convert HW stats into netdevice stats. */
1367 nstat
->rx_packets
= hwstat
->rx_pkts
;
1368 nstat
->tx_packets
= hwstat
->tx_pkts
;
1369 nstat
->rx_bytes
= hwstat
->rx_octets
;
1370 nstat
->tx_bytes
= hwstat
->tx_octets
;
1371 nstat
->tx_errors
= (hwstat
->tx_jabber_pkts
+
1372 hwstat
->tx_oversize_pkts
+
1373 hwstat
->tx_underruns
+
1374 hwstat
->tx_excessive_cols
+
1375 hwstat
->tx_late_cols
);
1376 nstat
->multicast
= hwstat
->tx_multicast_pkts
;
1377 nstat
->collisions
= hwstat
->tx_total_cols
;
1379 nstat
->rx_length_errors
= (hwstat
->rx_oversize_pkts
+
1380 hwstat
->rx_undersize
);
1381 nstat
->rx_over_errors
= hwstat
->rx_missed_pkts
;
1382 nstat
->rx_frame_errors
= hwstat
->rx_align_errs
;
1383 nstat
->rx_crc_errors
= hwstat
->rx_crc_errs
;
1384 nstat
->rx_errors
= (hwstat
->rx_jabber_pkts
+
1385 hwstat
->rx_oversize_pkts
+
1386 hwstat
->rx_missed_pkts
+
1387 hwstat
->rx_crc_align_errs
+
1388 hwstat
->rx_undersize
+
1389 hwstat
->rx_crc_errs
+
1390 hwstat
->rx_align_errs
+
1391 hwstat
->rx_symbol_errs
);
1393 nstat
->tx_aborted_errors
= hwstat
->tx_underruns
;
1395 /* Carrier lost counter seems to be broken for some devices */
1396 nstat
->tx_carrier_errors
= hwstat
->tx_carrier_lost
;
1402 static int __b44_load_mcast(struct b44
*bp
, struct net_device
*dev
)
1404 struct dev_mc_list
*mclist
;
1407 num_ents
= min_t(int, dev
->mc_count
, B44_MCAST_TABLE_SIZE
);
1408 mclist
= dev
->mc_list
;
1409 for (i
= 0; mclist
&& i
< num_ents
; i
++, mclist
= mclist
->next
) {
1410 __b44_cam_write(bp
, mclist
->dmi_addr
, i
+ 1);
1415 static void __b44_set_rx_mode(struct net_device
*dev
)
1417 struct b44
*bp
= netdev_priv(dev
);
1420 unsigned char zero
[6] = {0,0,0,0,0,0};
1422 val
= br32(bp
, B44_RXCONFIG
);
1423 val
&= ~(RXCONFIG_PROMISC
| RXCONFIG_ALLMULTI
);
1424 if (dev
->flags
& IFF_PROMISC
) {
1425 val
|= RXCONFIG_PROMISC
;
1426 bw32(bp
, B44_RXCONFIG
, val
);
1428 __b44_set_mac_addr(bp
);
1430 if (dev
->flags
& IFF_ALLMULTI
)
1431 val
|= RXCONFIG_ALLMULTI
;
1433 i
=__b44_load_mcast(bp
, dev
);
1436 __b44_cam_write(bp
, zero
, i
);
1438 bw32(bp
, B44_RXCONFIG
, val
);
1439 val
= br32(bp
, B44_CAM_CTRL
);
1440 bw32(bp
, B44_CAM_CTRL
, val
| CAM_CTRL_ENABLE
);
1444 static void b44_set_rx_mode(struct net_device
*dev
)
1446 struct b44
*bp
= netdev_priv(dev
);
1448 spin_lock_irq(&bp
->lock
);
1449 __b44_set_rx_mode(dev
);
1450 spin_unlock_irq(&bp
->lock
);
1453 static u32
b44_get_msglevel(struct net_device
*dev
)
1455 struct b44
*bp
= netdev_priv(dev
);
1456 return bp
->msg_enable
;
1459 static void b44_set_msglevel(struct net_device
*dev
, u32 value
)
1461 struct b44
*bp
= netdev_priv(dev
);
1462 bp
->msg_enable
= value
;
1465 static void b44_get_drvinfo (struct net_device
*dev
, struct ethtool_drvinfo
*info
)
1467 struct b44
*bp
= netdev_priv(dev
);
1468 struct pci_dev
*pci_dev
= bp
->pdev
;
1470 strcpy (info
->driver
, DRV_MODULE_NAME
);
1471 strcpy (info
->version
, DRV_MODULE_VERSION
);
1472 strcpy (info
->bus_info
, pci_name(pci_dev
));
1475 static int b44_nway_reset(struct net_device
*dev
)
1477 struct b44
*bp
= netdev_priv(dev
);
1481 spin_lock_irq(&bp
->lock
);
1482 b44_readphy(bp
, MII_BMCR
, &bmcr
);
1483 b44_readphy(bp
, MII_BMCR
, &bmcr
);
1485 if (bmcr
& BMCR_ANENABLE
) {
1486 b44_writephy(bp
, MII_BMCR
,
1487 bmcr
| BMCR_ANRESTART
);
1490 spin_unlock_irq(&bp
->lock
);
1495 static int b44_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1497 struct b44
*bp
= netdev_priv(dev
);
1499 if (!(bp
->flags
& B44_FLAG_INIT_COMPLETE
))
1501 cmd
->supported
= (SUPPORTED_Autoneg
);
1502 cmd
->supported
|= (SUPPORTED_100baseT_Half
|
1503 SUPPORTED_100baseT_Full
|
1504 SUPPORTED_10baseT_Half
|
1505 SUPPORTED_10baseT_Full
|
1508 cmd
->advertising
= 0;
1509 if (bp
->flags
& B44_FLAG_ADV_10HALF
)
1510 cmd
->advertising
|= ADVERTISE_10HALF
;
1511 if (bp
->flags
& B44_FLAG_ADV_10FULL
)
1512 cmd
->advertising
|= ADVERTISE_10FULL
;
1513 if (bp
->flags
& B44_FLAG_ADV_100HALF
)
1514 cmd
->advertising
|= ADVERTISE_100HALF
;
1515 if (bp
->flags
& B44_FLAG_ADV_100FULL
)
1516 cmd
->advertising
|= ADVERTISE_100FULL
;
1517 cmd
->advertising
|= ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
;
1518 cmd
->speed
= (bp
->flags
& B44_FLAG_100_BASE_T
) ?
1519 SPEED_100
: SPEED_10
;
1520 cmd
->duplex
= (bp
->flags
& B44_FLAG_FULL_DUPLEX
) ?
1521 DUPLEX_FULL
: DUPLEX_HALF
;
1523 cmd
->phy_address
= bp
->phy_addr
;
1524 cmd
->transceiver
= (bp
->flags
& B44_FLAG_INTERNAL_PHY
) ?
1525 XCVR_INTERNAL
: XCVR_EXTERNAL
;
1526 cmd
->autoneg
= (bp
->flags
& B44_FLAG_FORCE_LINK
) ?
1527 AUTONEG_DISABLE
: AUTONEG_ENABLE
;
1533 static int b44_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1535 struct b44
*bp
= netdev_priv(dev
);
1537 if (!(bp
->flags
& B44_FLAG_INIT_COMPLETE
))
1540 /* We do not support gigabit. */
1541 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
1542 if (cmd
->advertising
&
1543 (ADVERTISED_1000baseT_Half
|
1544 ADVERTISED_1000baseT_Full
))
1546 } else if ((cmd
->speed
!= SPEED_100
&&
1547 cmd
->speed
!= SPEED_10
) ||
1548 (cmd
->duplex
!= DUPLEX_HALF
&&
1549 cmd
->duplex
!= DUPLEX_FULL
)) {
1553 spin_lock_irq(&bp
->lock
);
1555 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
1556 bp
->flags
&= ~B44_FLAG_FORCE_LINK
;
1557 bp
->flags
&= ~(B44_FLAG_ADV_10HALF
|
1558 B44_FLAG_ADV_10FULL
|
1559 B44_FLAG_ADV_100HALF
|
1560 B44_FLAG_ADV_100FULL
);
1561 if (cmd
->advertising
& ADVERTISE_10HALF
)
1562 bp
->flags
|= B44_FLAG_ADV_10HALF
;
1563 if (cmd
->advertising
& ADVERTISE_10FULL
)
1564 bp
->flags
|= B44_FLAG_ADV_10FULL
;
1565 if (cmd
->advertising
& ADVERTISE_100HALF
)
1566 bp
->flags
|= B44_FLAG_ADV_100HALF
;
1567 if (cmd
->advertising
& ADVERTISE_100FULL
)
1568 bp
->flags
|= B44_FLAG_ADV_100FULL
;
1570 bp
->flags
|= B44_FLAG_FORCE_LINK
;
1571 if (cmd
->speed
== SPEED_100
)
1572 bp
->flags
|= B44_FLAG_100_BASE_T
;
1573 if (cmd
->duplex
== DUPLEX_FULL
)
1574 bp
->flags
|= B44_FLAG_FULL_DUPLEX
;
1579 spin_unlock_irq(&bp
->lock
);
1584 static void b44_get_ringparam(struct net_device
*dev
,
1585 struct ethtool_ringparam
*ering
)
1587 struct b44
*bp
= netdev_priv(dev
);
1589 ering
->rx_max_pending
= B44_RX_RING_SIZE
- 1;
1590 ering
->rx_pending
= bp
->rx_pending
;
1592 /* XXX ethtool lacks a tx_max_pending, oops... */
1595 static int b44_set_ringparam(struct net_device
*dev
,
1596 struct ethtool_ringparam
*ering
)
1598 struct b44
*bp
= netdev_priv(dev
);
1600 if ((ering
->rx_pending
> B44_RX_RING_SIZE
- 1) ||
1601 (ering
->rx_mini_pending
!= 0) ||
1602 (ering
->rx_jumbo_pending
!= 0) ||
1603 (ering
->tx_pending
> B44_TX_RING_SIZE
- 1))
1606 spin_lock_irq(&bp
->lock
);
1608 bp
->rx_pending
= ering
->rx_pending
;
1609 bp
->tx_pending
= ering
->tx_pending
;
1614 netif_wake_queue(bp
->dev
);
1615 spin_unlock_irq(&bp
->lock
);
1617 b44_enable_ints(bp
);
1622 static void b44_get_pauseparam(struct net_device
*dev
,
1623 struct ethtool_pauseparam
*epause
)
1625 struct b44
*bp
= netdev_priv(dev
);
1628 (bp
->flags
& B44_FLAG_PAUSE_AUTO
) != 0;
1630 (bp
->flags
& B44_FLAG_RX_PAUSE
) != 0;
1632 (bp
->flags
& B44_FLAG_TX_PAUSE
) != 0;
1635 static int b44_set_pauseparam(struct net_device
*dev
,
1636 struct ethtool_pauseparam
*epause
)
1638 struct b44
*bp
= netdev_priv(dev
);
1640 spin_lock_irq(&bp
->lock
);
1641 if (epause
->autoneg
)
1642 bp
->flags
|= B44_FLAG_PAUSE_AUTO
;
1644 bp
->flags
&= ~B44_FLAG_PAUSE_AUTO
;
1645 if (epause
->rx_pause
)
1646 bp
->flags
|= B44_FLAG_RX_PAUSE
;
1648 bp
->flags
&= ~B44_FLAG_RX_PAUSE
;
1649 if (epause
->tx_pause
)
1650 bp
->flags
|= B44_FLAG_TX_PAUSE
;
1652 bp
->flags
&= ~B44_FLAG_TX_PAUSE
;
1653 if (bp
->flags
& B44_FLAG_PAUSE_AUTO
) {
1658 __b44_set_flow_ctrl(bp
, bp
->flags
);
1660 spin_unlock_irq(&bp
->lock
);
1662 b44_enable_ints(bp
);
1667 static struct ethtool_ops b44_ethtool_ops
= {
1668 .get_drvinfo
= b44_get_drvinfo
,
1669 .get_settings
= b44_get_settings
,
1670 .set_settings
= b44_set_settings
,
1671 .nway_reset
= b44_nway_reset
,
1672 .get_link
= ethtool_op_get_link
,
1673 .get_ringparam
= b44_get_ringparam
,
1674 .set_ringparam
= b44_set_ringparam
,
1675 .get_pauseparam
= b44_get_pauseparam
,
1676 .set_pauseparam
= b44_set_pauseparam
,
1677 .get_msglevel
= b44_get_msglevel
,
1678 .set_msglevel
= b44_set_msglevel
,
1681 static int b44_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1683 struct mii_ioctl_data
*data
= if_mii(ifr
);
1684 struct b44
*bp
= netdev_priv(dev
);
1687 spin_lock_irq(&bp
->lock
);
1688 err
= generic_mii_ioctl(&bp
->mii_if
, data
, cmd
, NULL
);
1689 spin_unlock_irq(&bp
->lock
);
1694 /* Read 128-bytes of EEPROM. */
1695 static int b44_read_eeprom(struct b44
*bp
, u8
*data
)
1698 u16
*ptr
= (u16
*) data
;
1700 for (i
= 0; i
< 128; i
+= 2)
1701 ptr
[i
/ 2] = readw(bp
->regs
+ 4096 + i
);
1706 static int __devinit
b44_get_invariants(struct b44
*bp
)
1711 err
= b44_read_eeprom(bp
, &eeprom
[0]);
1715 bp
->dev
->dev_addr
[0] = eeprom
[79];
1716 bp
->dev
->dev_addr
[1] = eeprom
[78];
1717 bp
->dev
->dev_addr
[2] = eeprom
[81];
1718 bp
->dev
->dev_addr
[3] = eeprom
[80];
1719 bp
->dev
->dev_addr
[4] = eeprom
[83];
1720 bp
->dev
->dev_addr
[5] = eeprom
[82];
1722 bp
->phy_addr
= eeprom
[90] & 0x1f;
1724 /* With this, plus the rx_header prepended to the data by the
1725 * hardware, we'll land the ethernet header on a 2-byte boundary.
1729 bp
->imask
= IMASK_DEF
;
1731 bp
->core_unit
= ssb_core_unit(bp
);
1732 bp
->dma_offset
= SB_PCI_DMA
;
1734 /* XXX - really required?
1735 bp->flags |= B44_FLAG_BUGGY_TXPTR;
1741 static int __devinit
b44_init_one(struct pci_dev
*pdev
,
1742 const struct pci_device_id
*ent
)
1744 static int b44_version_printed
= 0;
1745 unsigned long b44reg_base
, b44reg_len
;
1746 struct net_device
*dev
;
1750 if (b44_version_printed
++ == 0)
1751 printk(KERN_INFO
"%s", version
);
1753 err
= pci_enable_device(pdev
);
1755 printk(KERN_ERR PFX
"Cannot enable PCI device, "
1760 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1761 printk(KERN_ERR PFX
"Cannot find proper PCI device "
1762 "base address, aborting.\n");
1764 goto err_out_disable_pdev
;
1767 err
= pci_request_regions(pdev
, DRV_MODULE_NAME
);
1769 printk(KERN_ERR PFX
"Cannot obtain PCI resources, "
1771 goto err_out_disable_pdev
;
1774 pci_set_master(pdev
);
1776 err
= pci_set_dma_mask(pdev
, (u64
) B44_DMA_MASK
);
1778 printk(KERN_ERR PFX
"No usable DMA configuration, "
1780 goto err_out_free_res
;
1783 err
= pci_set_consistent_dma_mask(pdev
, (u64
) B44_DMA_MASK
);
1785 printk(KERN_ERR PFX
"No usable DMA configuration, "
1787 goto err_out_free_res
;
1790 b44reg_base
= pci_resource_start(pdev
, 0);
1791 b44reg_len
= pci_resource_len(pdev
, 0);
1793 dev
= alloc_etherdev(sizeof(*bp
));
1795 printk(KERN_ERR PFX
"Etherdev alloc failed, aborting.\n");
1797 goto err_out_free_res
;
1800 SET_MODULE_OWNER(dev
);
1801 SET_NETDEV_DEV(dev
,&pdev
->dev
);
1803 /* No interesting netdevice features in this card... */
1806 bp
= netdev_priv(dev
);
1810 bp
->msg_enable
= (1 << b44_debug
) - 1;
1812 bp
->msg_enable
= B44_DEF_MSG_ENABLE
;
1814 spin_lock_init(&bp
->lock
);
1816 bp
->regs
= ioremap(b44reg_base
, b44reg_len
);
1817 if (bp
->regs
== 0UL) {
1818 printk(KERN_ERR PFX
"Cannot map device registers, "
1821 goto err_out_free_dev
;
1824 bp
->rx_pending
= B44_DEF_RX_RING_PENDING
;
1825 bp
->tx_pending
= B44_DEF_TX_RING_PENDING
;
1827 dev
->open
= b44_open
;
1828 dev
->stop
= b44_close
;
1829 dev
->hard_start_xmit
= b44_start_xmit
;
1830 dev
->get_stats
= b44_get_stats
;
1831 dev
->set_multicast_list
= b44_set_rx_mode
;
1832 dev
->set_mac_address
= b44_set_mac_addr
;
1833 dev
->do_ioctl
= b44_ioctl
;
1834 dev
->tx_timeout
= b44_tx_timeout
;
1835 dev
->poll
= b44_poll
;
1837 dev
->watchdog_timeo
= B44_TX_TIMEOUT
;
1838 #ifdef CONFIG_NET_POLL_CONTROLLER
1839 dev
->poll_controller
= b44_poll_controller
;
1841 dev
->change_mtu
= b44_change_mtu
;
1842 dev
->irq
= pdev
->irq
;
1843 SET_ETHTOOL_OPS(dev
, &b44_ethtool_ops
);
1845 err
= b44_get_invariants(bp
);
1847 printk(KERN_ERR PFX
"Problem fetching invariants of chip, "
1849 goto err_out_iounmap
;
1852 bp
->mii_if
.dev
= dev
;
1853 bp
->mii_if
.mdio_read
= b44_mii_read
;
1854 bp
->mii_if
.mdio_write
= b44_mii_write
;
1855 bp
->mii_if
.phy_id
= bp
->phy_addr
;
1856 bp
->mii_if
.phy_id_mask
= 0x1f;
1857 bp
->mii_if
.reg_num_mask
= 0x1f;
1859 /* By default, advertise all speed/duplex settings. */
1860 bp
->flags
|= (B44_FLAG_ADV_10HALF
| B44_FLAG_ADV_10FULL
|
1861 B44_FLAG_ADV_100HALF
| B44_FLAG_ADV_100FULL
);
1863 /* By default, auto-negotiate PAUSE. */
1864 bp
->flags
|= B44_FLAG_PAUSE_AUTO
;
1866 err
= register_netdev(dev
);
1868 printk(KERN_ERR PFX
"Cannot register net device, "
1870 goto err_out_iounmap
;
1873 pci_set_drvdata(pdev
, dev
);
1875 pci_save_state(bp
->pdev
);
1877 printk(KERN_INFO
"%s: Broadcom 4400 10/100BaseT Ethernet ", dev
->name
);
1878 for (i
= 0; i
< 6; i
++)
1879 printk("%2.2x%c", dev
->dev_addr
[i
],
1880 i
== 5 ? '\n' : ':');
1891 pci_release_regions(pdev
);
1893 err_out_disable_pdev
:
1894 pci_disable_device(pdev
);
1895 pci_set_drvdata(pdev
, NULL
);
1899 static void __devexit
b44_remove_one(struct pci_dev
*pdev
)
1901 struct net_device
*dev
= pci_get_drvdata(pdev
);
1904 struct b44
*bp
= netdev_priv(dev
);
1906 unregister_netdev(dev
);
1909 pci_release_regions(pdev
);
1910 pci_disable_device(pdev
);
1911 pci_set_drvdata(pdev
, NULL
);
1915 static int b44_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1917 struct net_device
*dev
= pci_get_drvdata(pdev
);
1918 struct b44
*bp
= netdev_priv(dev
);
1920 if (!netif_running(dev
))
1923 del_timer_sync(&bp
->timer
);
1925 spin_lock_irq(&bp
->lock
);
1928 netif_carrier_off(bp
->dev
);
1929 netif_device_detach(bp
->dev
);
1932 spin_unlock_irq(&bp
->lock
);
1933 pci_disable_device(pdev
);
1937 static int b44_resume(struct pci_dev
*pdev
)
1939 struct net_device
*dev
= pci_get_drvdata(pdev
);
1940 struct b44
*bp
= netdev_priv(dev
);
1942 pci_restore_state(pdev
);
1943 pci_enable_device(pdev
);
1944 pci_set_master(pdev
);
1946 if (!netif_running(dev
))
1949 spin_lock_irq(&bp
->lock
);
1953 netif_device_attach(bp
->dev
);
1954 spin_unlock_irq(&bp
->lock
);
1956 bp
->timer
.expires
= jiffies
+ HZ
;
1957 add_timer(&bp
->timer
);
1959 b44_enable_ints(bp
);
1963 static struct pci_driver b44_driver
= {
1964 .name
= DRV_MODULE_NAME
,
1965 .id_table
= b44_pci_tbl
,
1966 .probe
= b44_init_one
,
1967 .remove
= __devexit_p(b44_remove_one
),
1968 .suspend
= b44_suspend
,
1969 .resume
= b44_resume
,
1972 static int __init
b44_init(void)
1974 return pci_module_init(&b44_driver
);
1977 static void __exit
b44_cleanup(void)
1979 pci_unregister_driver(&b44_driver
);
1982 module_init(b44_init
);
1983 module_exit(b44_cleanup
);