1 diff -Nur linux-2.6.12.5/drivers/net/b44.c linux-2.6.12.5-b44/drivers/net/b44.c
2 --- linux-2.6.12.5/drivers/net/b44.c 2005-08-15 02:20:18.000000000 +0200
3 +++ linux-2.6.12.5-b44/drivers/net/b44.c 2005-09-16 12:54:43.997122712 +0200
5 -/* b44.c: Broadcom 4400 device driver.
6 +/* b44.c: Broadcom 4400/47xx device driver.
8 * Copyright (C) 2002 David S. Miller (davem@redhat.com)
9 - * Fixed by Pekka Pietikainen (pp@ee.oulu.fi)
10 + * Copyright (C) 2004 Pekka Pietikainen (pp@ee.oulu.fi)
11 + * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
13 * Distribute under GPL.
16 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
18 MODULE_AUTHOR("Florian Schirmer, Pekka Pietikainen, David S. Miller");
19 -MODULE_DESCRIPTION("Broadcom 4400 10/100 PCI ethernet driver");
20 +MODULE_DESCRIPTION("Broadcom 4400/47xx 10/100 PCI ethernet driver");
21 MODULE_LICENSE("GPL");
22 MODULE_VERSION(DRV_MODULE_VERSION);
25 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
26 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_BCM4401B1,
27 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
28 + { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_BCM4713,
29 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
30 { } /* terminate list with empty entry */
34 static void b44_poll_controller(struct net_device *dev);
37 -static inline unsigned long br32(const struct b44 *bp, unsigned long reg)
39 - return readl(bp->regs + reg);
42 -static inline void bw32(const struct b44 *bp,
43 - unsigned long reg, unsigned long val)
45 - writel(val, bp->regs + reg);
48 static int b44_wait_bit(struct b44 *bp, unsigned long reg,
49 u32 bit, unsigned long timeout, const int clear)
53 for (i = 0; i < timeout; i++) {
54 - u32 val = br32(bp, reg);
55 + u32 val = br32(reg);
57 if (clear && !(val & bit))
61 static u32 ssb_get_core_rev(struct b44 *bp)
63 - return (br32(bp, B44_SBIDHIGH) & SBIDHIGH_RC_MASK);
64 + return (br32(B44_SBIDHIGH) & SBIDHIGH_RC_MASK);
67 static u32 ssb_pci_setup(struct b44 *bp, u32 cores)
69 pci_write_config_dword(bp->pdev, SSB_BAR0_WIN, BCM4400_PCI_CORE_ADDR);
70 pci_rev = ssb_get_core_rev(bp);
72 - val = br32(bp, B44_SBINTVEC);
73 + val = br32(B44_SBINTVEC);
75 - bw32(bp, B44_SBINTVEC, val);
76 + bw32(B44_SBINTVEC, val);
78 - val = br32(bp, SSB_PCI_TRANS_2);
79 + val = br32(SSB_PCI_TRANS_2);
80 val |= SSB_PCI_PREF | SSB_PCI_BURST;
81 - bw32(bp, SSB_PCI_TRANS_2, val);
82 + bw32(SSB_PCI_TRANS_2, val);
84 pci_write_config_dword(bp->pdev, SSB_BAR0_WIN, bar_orig);
88 static void ssb_core_disable(struct b44 *bp)
90 - if (br32(bp, B44_SBTMSLOW) & SBTMSLOW_RESET)
91 + if (br32(B44_SBTMSLOW) & SBTMSLOW_RESET)
94 - bw32(bp, B44_SBTMSLOW, (SBTMSLOW_REJECT | SBTMSLOW_CLOCK));
95 + bw32(B44_SBTMSLOW, (SBTMSLOW_REJECT | SBTMSLOW_CLOCK));
96 b44_wait_bit(bp, B44_SBTMSLOW, SBTMSLOW_REJECT, 100000, 0);
97 b44_wait_bit(bp, B44_SBTMSHIGH, SBTMSHIGH_BUSY, 100000, 1);
98 - bw32(bp, B44_SBTMSLOW, (SBTMSLOW_FGC | SBTMSLOW_CLOCK |
99 + bw32(B44_SBTMSLOW, (SBTMSLOW_FGC | SBTMSLOW_CLOCK |
100 SBTMSLOW_REJECT | SBTMSLOW_RESET));
101 - br32(bp, B44_SBTMSLOW);
102 + br32(B44_SBTMSLOW);
104 - bw32(bp, B44_SBTMSLOW, (SBTMSLOW_REJECT | SBTMSLOW_RESET));
105 - br32(bp, B44_SBTMSLOW);
106 + bw32(B44_SBTMSLOW, (SBTMSLOW_REJECT | SBTMSLOW_RESET));
107 + br32(B44_SBTMSLOW);
111 @@ -200,58 +192,65 @@
114 ssb_core_disable(bp);
115 - bw32(bp, B44_SBTMSLOW, (SBTMSLOW_RESET | SBTMSLOW_CLOCK | SBTMSLOW_FGC));
116 - br32(bp, B44_SBTMSLOW);
117 + bw32(B44_SBTMSLOW, (SBTMSLOW_RESET | SBTMSLOW_CLOCK | SBTMSLOW_FGC));
118 + br32(B44_SBTMSLOW);
121 /* Clear SERR if set, this is a hw bug workaround. */
122 - if (br32(bp, B44_SBTMSHIGH) & SBTMSHIGH_SERR)
123 - bw32(bp, B44_SBTMSHIGH, 0);
124 + if (br32(B44_SBTMSHIGH) & SBTMSHIGH_SERR)
125 + bw32(B44_SBTMSHIGH, 0);
127 - val = br32(bp, B44_SBIMSTATE);
128 + val = br32(B44_SBIMSTATE);
129 if (val & (SBIMSTATE_IBE | SBIMSTATE_TO))
130 - bw32(bp, B44_SBIMSTATE, val & ~(SBIMSTATE_IBE | SBIMSTATE_TO));
131 + bw32(B44_SBIMSTATE, val & ~(SBIMSTATE_IBE | SBIMSTATE_TO));
133 - bw32(bp, B44_SBTMSLOW, (SBTMSLOW_CLOCK | SBTMSLOW_FGC));
134 - br32(bp, B44_SBTMSLOW);
135 + bw32(B44_SBTMSLOW, (SBTMSLOW_CLOCK | SBTMSLOW_FGC));
136 + br32(B44_SBTMSLOW);
139 - bw32(bp, B44_SBTMSLOW, (SBTMSLOW_CLOCK));
140 - br32(bp, B44_SBTMSLOW);
141 + bw32(B44_SBTMSLOW, (SBTMSLOW_CLOCK));
142 + br32(B44_SBTMSLOW);
146 +static int b44_4713_instance;
148 static int ssb_core_unit(struct b44 *bp)
151 - u32 val = br32(bp, B44_SBADMATCH0);
154 - type = val & SBADMATCH0_TYPE_MASK;
157 - base = val & SBADMATCH0_BS0_MASK;
161 - base = val & SBADMATCH0_BS1_MASK;
166 - base = val & SBADMATCH0_BS2_MASK;
171 + if (bp->pdev->device == PCI_DEVICE_ID_BCM4713)
172 + return b44_4713_instance++;
177 static int ssb_is_core_up(struct b44 *bp)
179 - return ((br32(bp, B44_SBTMSLOW) & (SBTMSLOW_RESET | SBTMSLOW_REJECT | SBTMSLOW_CLOCK))
180 + return ((br32(B44_SBTMSLOW) & (SBTMSLOW_RESET | SBTMSLOW_REJECT | SBTMSLOW_CLOCK))
184 +static void __b44_cam_read(struct b44 *bp, unsigned char *data, int index)
188 + bw32(B44_CAM_CTRL, (CAM_CTRL_READ |
189 + (index << CAM_CTRL_INDEX_SHIFT)));
191 + b44_wait_bit(bp, B44_CAM_CTRL, CAM_CTRL_BUSY, 100, 1);
193 + val = br32(B44_CAM_DATA_LO);
195 + data[2] = (val >> 24) & 0xFF;
196 + data[3] = (val >> 16) & 0xFF;
197 + data[4] = (val >> 8) & 0xFF;
198 + data[5] = (val >> 0) & 0xFF;
200 + val = br32(B44_CAM_DATA_HI);
202 + data[0] = (val >> 8) & 0xFF;
203 + data[1] = (val >> 0) & 0xFF;
206 static void __b44_cam_write(struct b44 *bp, unsigned char *data, int index)
209 @@ -260,19 +259,19 @@
210 val |= ((u32) data[3]) << 16;
211 val |= ((u32) data[4]) << 8;
212 val |= ((u32) data[5]) << 0;
213 - bw32(bp, B44_CAM_DATA_LO, val);
214 + bw32(B44_CAM_DATA_LO, val);
215 val = (CAM_DATA_HI_VALID |
216 (((u32) data[0]) << 8) |
217 (((u32) data[1]) << 0));
218 - bw32(bp, B44_CAM_DATA_HI, val);
219 - bw32(bp, B44_CAM_CTRL, (CAM_CTRL_WRITE |
220 + bw32(B44_CAM_DATA_HI, val);
221 + bw32(B44_CAM_CTRL, (CAM_CTRL_WRITE |
222 (index << CAM_CTRL_INDEX_SHIFT)));
223 b44_wait_bit(bp, B44_CAM_CTRL, CAM_CTRL_BUSY, 100, 1);
226 static inline void __b44_disable_ints(struct b44 *bp)
228 - bw32(bp, B44_IMASK, 0);
229 + bw32(B44_IMASK, 0);
232 static void b44_disable_ints(struct b44 *bp)
233 @@ -280,42 +279,59 @@
234 __b44_disable_ints(bp);
236 /* Flush posted writes. */
237 - br32(bp, B44_IMASK);
241 static void b44_enable_ints(struct b44 *bp)
243 - bw32(bp, B44_IMASK, bp->imask);
244 + bw32(B44_IMASK, bp->imask);
247 -static int b44_readphy(struct b44 *bp, int reg, u32 *val)
248 +static int __b44_readphy(struct b44 *bp, int phy_addr, int reg, u32 *val)
252 - bw32(bp, B44_EMAC_ISTAT, EMAC_INT_MII);
253 - bw32(bp, B44_MDIO_DATA, (MDIO_DATA_SB_START |
254 + bw32(B44_EMAC_ISTAT, EMAC_INT_MII);
255 + bw32(B44_MDIO_DATA, (MDIO_DATA_SB_START |
256 (MDIO_OP_READ << MDIO_DATA_OP_SHIFT) |
257 - (bp->phy_addr << MDIO_DATA_PMD_SHIFT) |
258 + (phy_addr << MDIO_DATA_PMD_SHIFT) |
259 (reg << MDIO_DATA_RA_SHIFT) |
260 (MDIO_TA_VALID << MDIO_DATA_TA_SHIFT)));
261 err = b44_wait_bit(bp, B44_EMAC_ISTAT, EMAC_INT_MII, 100, 0);
262 - *val = br32(bp, B44_MDIO_DATA) & MDIO_DATA_DATA;
263 + *val = br32(B44_MDIO_DATA) & MDIO_DATA_DATA;
268 -static int b44_writephy(struct b44 *bp, int reg, u32 val)
269 +static int b44_readphy(struct b44 *bp, int reg, u32 *val)
271 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
274 + return __b44_readphy(bp, bp->phy_addr, reg, val);
277 +static int __b44_writephy(struct b44 *bp, int phy_addr, int reg, u32 val)
279 - bw32(bp, B44_EMAC_ISTAT, EMAC_INT_MII);
280 - bw32(bp, B44_MDIO_DATA, (MDIO_DATA_SB_START |
281 + bw32(B44_EMAC_ISTAT, EMAC_INT_MII);
282 + bw32(B44_MDIO_DATA, (MDIO_DATA_SB_START |
283 (MDIO_OP_WRITE << MDIO_DATA_OP_SHIFT) |
284 - (bp->phy_addr << MDIO_DATA_PMD_SHIFT) |
285 + (phy_addr << MDIO_DATA_PMD_SHIFT) |
286 (reg << MDIO_DATA_RA_SHIFT) |
287 (MDIO_TA_VALID << MDIO_DATA_TA_SHIFT) |
288 (val & MDIO_DATA_DATA)));
289 return b44_wait_bit(bp, B44_EMAC_ISTAT, EMAC_INT_MII, 100, 0);
292 +static int b44_writephy(struct b44 *bp, int reg, u32 val)
294 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
297 + return __b44_writephy(bp, bp->phy_addr, reg, val);
301 /* miilib interface */
302 /* FIXME FIXME: phy_id is ignored, bp->phy_addr use is unconditional
303 * due to code existing before miilib use was added to this driver.
308 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
311 err = b44_writephy(bp, MII_BMCR, BMCR_RESET);
314 @@ -367,20 +386,20 @@
315 bp->flags &= ~(B44_FLAG_TX_PAUSE | B44_FLAG_RX_PAUSE);
316 bp->flags |= pause_flags;
318 - val = br32(bp, B44_RXCONFIG);
319 + val = br32(B44_RXCONFIG);
320 if (pause_flags & B44_FLAG_RX_PAUSE)
321 val |= RXCONFIG_FLOW;
323 val &= ~RXCONFIG_FLOW;
324 - bw32(bp, B44_RXCONFIG, val);
325 + bw32(B44_RXCONFIG, val);
327 - val = br32(bp, B44_MAC_FLOW);
328 + val = br32(B44_MAC_FLOW);
329 if (pause_flags & B44_FLAG_TX_PAUSE)
330 val |= (MAC_FLOW_PAUSE_ENAB |
331 (0xc0 & MAC_FLOW_RX_HI_WATER));
333 val &= ~MAC_FLOW_PAUSE_ENAB;
334 - bw32(bp, B44_MAC_FLOW, val);
335 + bw32(B44_MAC_FLOW, val);
338 static void b44_set_flow_ctrl(struct b44 *bp, u32 local, u32 remote)
343 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
346 if ((err = b44_readphy(bp, B44_MII_ALEDCTRL, &val)) != 0)
348 if ((err = b44_writephy(bp, B44_MII_ALEDCTRL,
349 @@ -476,11 +498,11 @@
351 val = &bp->hw_stats.tx_good_octets;
352 for (reg = B44_TX_GOOD_O; reg <= B44_TX_PAUSE; reg += 4UL) {
353 - *val++ += br32(bp, reg);
354 + *val++ += br32(reg);
356 val = &bp->hw_stats.rx_good_octets;
357 for (reg = B44_RX_GOOD_O; reg <= B44_RX_NPAUSE; reg += 4UL) {
358 - *val++ += br32(bp, reg);
359 + *val++ += br32(reg);
367 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY) {
368 + bp->flags |= B44_FLAG_100_BASE_T;
369 + bp->flags |= B44_FLAG_FULL_DUPLEX;
370 + if (!netif_carrier_ok(bp->dev)) {
371 + u32 val = br32(B44_TX_CTRL);
372 + val |= TX_CTRL_DUPLEX;
373 + bw32(B44_TX_CTRL, val);
374 + netif_carrier_on(bp->dev);
375 + b44_link_report(bp);
380 if (!b44_readphy(bp, MII_BMSR, &bmsr) &&
381 !b44_readphy(bp, B44_MII_AUXCTRL, &aux) &&
383 @@ -520,14 +555,14 @@
385 if (!netif_carrier_ok(bp->dev) &&
386 (bmsr & BMSR_LSTATUS)) {
387 - u32 val = br32(bp, B44_TX_CTRL);
388 + u32 val = br32(B44_TX_CTRL);
389 u32 local_adv, remote_adv;
391 if (bp->flags & B44_FLAG_FULL_DUPLEX)
392 val |= TX_CTRL_DUPLEX;
394 val &= ~TX_CTRL_DUPLEX;
395 - bw32(bp, B44_TX_CTRL, val);
396 + bw32(B44_TX_CTRL, val);
398 if (!(bp->flags & B44_FLAG_FORCE_LINK) &&
399 !b44_readphy(bp, MII_ADVERTISE, &local_adv) &&
404 - cur = br32(bp, B44_DMATX_STAT) & DMATX_STAT_CDMASK;
405 + cur = br32(B44_DMATX_STAT) & DMATX_STAT_CDMASK;
406 cur /= sizeof(struct dma_desc);
408 /* XXX needs updating when NETIF_F_SG is supported */
410 TX_BUFFS_AVAIL(bp) > B44_TX_WAKEUP_THRESH)
411 netif_wake_queue(bp->dev);
413 - bw32(bp, B44_GPTIMER, 0);
414 + bw32(B44_GPTIMER, 0);
417 /* Works like this. This chip writes a 'struct rx_header" 30 bytes
422 - prod = br32(bp, B44_DMARX_STAT) & DMARX_STAT_CDMASK;
423 + prod = br32(B44_DMARX_STAT) & DMARX_STAT_CDMASK;
424 prod /= sizeof(struct dma_desc);
431 - bw32(bp, B44_DMARX_PTR, cons * sizeof(struct dma_desc));
432 + bw32(B44_DMARX_PTR, cons * sizeof(struct dma_desc));
438 spin_lock_irqsave(&bp->lock, flags);
440 - istat = br32(bp, B44_ISTAT);
441 - imask = br32(bp, B44_IMASK);
442 + istat = br32(B44_ISTAT);
443 + imask = br32(B44_IMASK);
445 /* ??? What the fuck is the purpose of the interrupt mask
446 * ??? register if we have to mask it out by hand anyways?
451 - bw32(bp, B44_ISTAT, istat);
452 - br32(bp, B44_ISTAT);
453 + bw32(B44_ISTAT, istat);
456 spin_unlock_irqrestore(&bp->lock, flags);
457 return IRQ_RETVAL(handled);
458 @@ -965,11 +1000,11 @@
462 - bw32(bp, B44_DMATX_PTR, entry * sizeof(struct dma_desc));
463 + bw32(B44_DMATX_PTR, entry * sizeof(struct dma_desc));
464 if (bp->flags & B44_FLAG_BUGGY_TXPTR)
465 - bw32(bp, B44_DMATX_PTR, entry * sizeof(struct dma_desc));
466 + bw32(B44_DMATX_PTR, entry * sizeof(struct dma_desc));
467 if (bp->flags & B44_FLAG_REORDER_BUG)
468 - br32(bp, B44_DMATX_PTR);
469 + br32(B44_DMATX_PTR);
471 if (TX_BUFFS_AVAIL(bp) < 1)
472 netif_stop_queue(dev);
473 @@ -1137,32 +1172,35 @@
477 - bw32(bp, B44_MIB_CTRL, MIB_CTRL_CLR_ON_READ);
478 + bw32(B44_MIB_CTRL, MIB_CTRL_CLR_ON_READ);
479 for (reg = B44_TX_GOOD_O; reg <= B44_TX_PAUSE; reg += 4UL)
482 for (reg = B44_RX_GOOD_O; reg <= B44_RX_NPAUSE; reg += 4UL)
487 /* bp->lock is held. */
488 static void b44_chip_reset(struct b44 *bp)
490 + unsigned int sb_clock;
492 if (ssb_is_core_up(bp)) {
493 - bw32(bp, B44_RCV_LAZY, 0);
494 - bw32(bp, B44_ENET_CTRL, ENET_CTRL_DISABLE);
495 + bw32(B44_RCV_LAZY, 0);
496 + bw32(B44_ENET_CTRL, ENET_CTRL_DISABLE);
497 b44_wait_bit(bp, B44_ENET_CTRL, ENET_CTRL_DISABLE, 100, 1);
498 - bw32(bp, B44_DMATX_CTRL, 0);
499 + bw32(B44_DMATX_CTRL, 0);
500 bp->tx_prod = bp->tx_cons = 0;
501 - if (br32(bp, B44_DMARX_STAT) & DMARX_STAT_EMASK) {
502 + if (br32(B44_DMARX_STAT) & DMARX_STAT_EMASK) {
503 b44_wait_bit(bp, B44_DMARX_STAT, DMARX_STAT_SIDLE,
506 - bw32(bp, B44_DMARX_CTRL, 0);
507 + bw32(B44_DMARX_CTRL, 0);
508 bp->rx_prod = bp->rx_cons = 0;
510 - ssb_pci_setup(bp, (bp->core_unit == 0 ?
513 + if (bp->pdev->device != PCI_DEVICE_ID_BCM4713)
514 + ssb_pci_setup(bp, (bp->core_unit == 0 ?
520 @@ -1170,20 +1208,26 @@
523 /* Make PHY accessible. */
524 - bw32(bp, B44_MDIO_CTRL, (MDIO_CTRL_PREAMBLE |
525 - (0x0d & MDIO_CTRL_MAXF_MASK)));
526 - br32(bp, B44_MDIO_CTRL);
528 - if (!(br32(bp, B44_DEVCTRL) & DEVCTRL_IPP)) {
529 - bw32(bp, B44_ENET_CTRL, ENET_CTRL_EPSEL);
530 - br32(bp, B44_ENET_CTRL);
531 + if (bp->pdev->device == PCI_DEVICE_ID_BCM4713)
532 + sb_clock = 100000000; /* 100 MHz */
534 + sb_clock = 62500000; /* 62.5 MHz */
536 + bw32(B44_MDIO_CTRL, (MDIO_CTRL_PREAMBLE |
537 + (((sb_clock + (B44_MDC_RATIO / 2)) / B44_MDC_RATIO)
538 + & MDIO_CTRL_MAXF_MASK)));
539 + br32(B44_MDIO_CTRL);
541 + if (!(br32(B44_DEVCTRL) & DEVCTRL_IPP)) {
542 + bw32(B44_ENET_CTRL, ENET_CTRL_EPSEL);
543 + br32(B44_ENET_CTRL);
544 bp->flags &= ~B44_FLAG_INTERNAL_PHY;
546 - u32 val = br32(bp, B44_DEVCTRL);
547 + u32 val = br32(B44_DEVCTRL);
549 if (val & DEVCTRL_EPR) {
550 - bw32(bp, B44_DEVCTRL, (val & ~DEVCTRL_EPR));
551 - br32(bp, B44_DEVCTRL);
552 + bw32(B44_DEVCTRL, (val & ~DEVCTRL_EPR));
556 bp->flags |= B44_FLAG_INTERNAL_PHY;
557 @@ -1200,13 +1244,13 @@
558 /* bp->lock is held. */
559 static void __b44_set_mac_addr(struct b44 *bp)
561 - bw32(bp, B44_CAM_CTRL, 0);
562 + bw32(B44_CAM_CTRL, 0);
563 if (!(bp->dev->flags & IFF_PROMISC)) {
566 __b44_cam_write(bp, bp->dev->dev_addr, 0);
567 - val = br32(bp, B44_CAM_CTRL);
568 - bw32(bp, B44_CAM_CTRL, val | CAM_CTRL_ENABLE);
569 + val = br32(B44_CAM_CTRL);
570 + bw32(B44_CAM_CTRL, val | CAM_CTRL_ENABLE);
574 @@ -1240,30 +1284,30 @@
577 /* Enable CRC32, set proper LED modes and power on PHY */
578 - bw32(bp, B44_MAC_CTRL, MAC_CTRL_CRC32_ENAB | MAC_CTRL_PHY_LEDCTRL);
579 - bw32(bp, B44_RCV_LAZY, (1 << RCV_LAZY_FC_SHIFT));
580 + bw32(B44_MAC_CTRL, MAC_CTRL_CRC32_ENAB | MAC_CTRL_PHY_LEDCTRL);
581 + bw32(B44_RCV_LAZY, (1 << RCV_LAZY_FC_SHIFT));
583 /* This sets the MAC address too. */
584 __b44_set_rx_mode(bp->dev);
586 /* MTU + eth header + possible VLAN tag + struct rx_header */
587 - bw32(bp, B44_RXMAXLEN, bp->dev->mtu + ETH_HLEN + 8 + RX_HEADER_LEN);
588 - bw32(bp, B44_TXMAXLEN, bp->dev->mtu + ETH_HLEN + 8 + RX_HEADER_LEN);
589 + bw32(B44_RXMAXLEN, bp->dev->mtu + ETH_HLEN + 8 + RX_HEADER_LEN);
590 + bw32(B44_TXMAXLEN, bp->dev->mtu + ETH_HLEN + 8 + RX_HEADER_LEN);
592 - bw32(bp, B44_TX_WMARK, 56); /* XXX magic */
593 - bw32(bp, B44_DMATX_CTRL, DMATX_CTRL_ENABLE);
594 - bw32(bp, B44_DMATX_ADDR, bp->tx_ring_dma + bp->dma_offset);
595 - bw32(bp, B44_DMARX_CTRL, (DMARX_CTRL_ENABLE |
596 + bw32(B44_TX_WMARK, 56); /* XXX magic */
597 + bw32(B44_DMATX_CTRL, DMATX_CTRL_ENABLE);
598 + bw32(B44_DMATX_ADDR, bp->tx_ring_dma + bp->dma_offset);
599 + bw32(B44_DMARX_CTRL, (DMARX_CTRL_ENABLE |
600 (bp->rx_offset << DMARX_CTRL_ROSHIFT)));
601 - bw32(bp, B44_DMARX_ADDR, bp->rx_ring_dma + bp->dma_offset);
602 + bw32(B44_DMARX_ADDR, bp->rx_ring_dma + bp->dma_offset);
604 - bw32(bp, B44_DMARX_PTR, bp->rx_pending);
605 + bw32(B44_DMARX_PTR, bp->rx_pending);
606 bp->rx_prod = bp->rx_pending;
608 - bw32(bp, B44_MIB_CTRL, MIB_CTRL_CLR_ON_READ);
609 + bw32(B44_MIB_CTRL, MIB_CTRL_CLR_ON_READ);
611 - val = br32(bp, B44_ENET_CTRL);
612 - bw32(bp, B44_ENET_CTRL, (val | ENET_CTRL_ENABLE));
613 + val = br32(B44_ENET_CTRL);
614 + bw32(B44_ENET_CTRL, (val | ENET_CTRL_ENABLE));
617 static int b44_open(struct net_device *dev)
618 @@ -1416,11 +1460,11 @@
620 unsigned char zero[6] = {0,0,0,0,0,0};
622 - val = br32(bp, B44_RXCONFIG);
623 + val = br32(B44_RXCONFIG);
624 val &= ~(RXCONFIG_PROMISC | RXCONFIG_ALLMULTI);
625 if (dev->flags & IFF_PROMISC) {
626 val |= RXCONFIG_PROMISC;
627 - bw32(bp, B44_RXCONFIG, val);
628 + bw32(B44_RXCONFIG, val);
630 __b44_set_mac_addr(bp);
632 @@ -1432,9 +1476,9 @@
634 __b44_cam_write(bp, zero, i);
636 - bw32(bp, B44_RXCONFIG, val);
637 - val = br32(bp, B44_CAM_CTRL);
638 - bw32(bp, B44_CAM_CTRL, val | CAM_CTRL_ENABLE);
639 + bw32(B44_RXCONFIG, val);
640 + val = br32(B44_CAM_CTRL);
641 + bw32(B44_CAM_CTRL, val | CAM_CTRL_ENABLE);
645 @@ -1675,17 +1719,288 @@
646 .set_msglevel = b44_set_msglevel,
649 +static int b44_ethtool_ioctl (struct net_device *dev, void __user *useraddr)
651 + struct b44 *bp = dev->priv;
652 + struct pci_dev *pci_dev = bp->pdev;
655 + if (copy_from_user (ðcmd, useraddr, sizeof (ethcmd)))
659 + case ETHTOOL_GDRVINFO: {
660 + struct ethtool_drvinfo info = { ETHTOOL_GDRVINFO };
661 + strcpy (info.driver, DRV_MODULE_NAME);
662 + strcpy (info.version, DRV_MODULE_VERSION);
663 + memset(&info.fw_version, 0, sizeof(info.fw_version));
664 + strcpy (info.bus_info, pci_name(pci_dev));
665 + info.eedump_len = 0;
666 + info.regdump_len = 0;
667 + if (copy_to_user (useraddr, &info, sizeof (info)))
672 + case ETHTOOL_GSET: {
673 + struct ethtool_cmd cmd = { ETHTOOL_GSET };
675 + if (!(bp->flags & B44_FLAG_INIT_COMPLETE))
677 + cmd.supported = (SUPPORTED_Autoneg);
678 + cmd.supported |= (SUPPORTED_100baseT_Half |
679 + SUPPORTED_100baseT_Full |
680 + SUPPORTED_10baseT_Half |
681 + SUPPORTED_10baseT_Full |
684 + cmd.advertising = 0;
685 + if (bp->flags & B44_FLAG_ADV_10HALF)
686 + cmd.advertising |= ADVERTISE_10HALF;
687 + if (bp->flags & B44_FLAG_ADV_10FULL)
688 + cmd.advertising |= ADVERTISE_10FULL;
689 + if (bp->flags & B44_FLAG_ADV_100HALF)
690 + cmd.advertising |= ADVERTISE_100HALF;
691 + if (bp->flags & B44_FLAG_ADV_100FULL)
692 + cmd.advertising |= ADVERTISE_100FULL;
693 + cmd.advertising |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
694 + cmd.speed = (bp->flags & B44_FLAG_100_BASE_T) ?
695 + SPEED_100 : SPEED_10;
696 + cmd.duplex = (bp->flags & B44_FLAG_FULL_DUPLEX) ?
697 + DUPLEX_FULL : DUPLEX_HALF;
699 + cmd.phy_address = bp->phy_addr;
700 + cmd.transceiver = (bp->flags & B44_FLAG_INTERNAL_PHY) ?
701 + XCVR_INTERNAL : XCVR_EXTERNAL;
702 + cmd.autoneg = (bp->flags & B44_FLAG_FORCE_LINK) ?
703 + AUTONEG_DISABLE : AUTONEG_ENABLE;
706 + if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
710 + case ETHTOOL_SSET: {
711 + struct ethtool_cmd cmd;
713 + if (!(bp->flags & B44_FLAG_INIT_COMPLETE))
716 + if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
719 + /* We do not support gigabit. */
720 + if (cmd.autoneg == AUTONEG_ENABLE) {
721 + if (cmd.advertising &
722 + (ADVERTISED_1000baseT_Half |
723 + ADVERTISED_1000baseT_Full))
725 + } else if ((cmd.speed != SPEED_100 &&
726 + cmd.speed != SPEED_10) ||
727 + (cmd.duplex != DUPLEX_HALF &&
728 + cmd.duplex != DUPLEX_FULL)) {
732 + spin_lock_irq(&bp->lock);
734 + if (cmd.autoneg == AUTONEG_ENABLE) {
735 + bp->flags &= ~B44_FLAG_FORCE_LINK;
736 + bp->flags &= ~(B44_FLAG_ADV_10HALF |
737 + B44_FLAG_ADV_10FULL |
738 + B44_FLAG_ADV_100HALF |
739 + B44_FLAG_ADV_100FULL);
740 + if (cmd.advertising & ADVERTISE_10HALF)
741 + bp->flags |= B44_FLAG_ADV_10HALF;
742 + if (cmd.advertising & ADVERTISE_10FULL)
743 + bp->flags |= B44_FLAG_ADV_10FULL;
744 + if (cmd.advertising & ADVERTISE_100HALF)
745 + bp->flags |= B44_FLAG_ADV_100HALF;
746 + if (cmd.advertising & ADVERTISE_100FULL)
747 + bp->flags |= B44_FLAG_ADV_100FULL;
749 + bp->flags |= B44_FLAG_FORCE_LINK;
750 + if (cmd.speed == SPEED_100)
751 + bp->flags |= B44_FLAG_100_BASE_T;
752 + if (cmd.duplex == DUPLEX_FULL)
753 + bp->flags |= B44_FLAG_FULL_DUPLEX;
758 + spin_unlock_irq(&bp->lock);
763 + case ETHTOOL_GMSGLVL: {
764 + struct ethtool_value edata = { ETHTOOL_GMSGLVL };
765 + edata.data = bp->msg_enable;
766 + if (copy_to_user(useraddr, &edata, sizeof(edata)))
770 + case ETHTOOL_SMSGLVL: {
771 + struct ethtool_value edata;
772 + if (copy_from_user(&edata, useraddr, sizeof(edata)))
774 + bp->msg_enable = edata.data;
777 + case ETHTOOL_NWAY_RST: {
781 + spin_lock_irq(&bp->lock);
782 + b44_readphy(bp, MII_BMCR, &bmcr);
783 + b44_readphy(bp, MII_BMCR, &bmcr);
785 + if (bmcr & BMCR_ANENABLE) {
786 + b44_writephy(bp, MII_BMCR,
787 + bmcr | BMCR_ANRESTART);
790 + spin_unlock_irq(&bp->lock);
794 + case ETHTOOL_GLINK: {
795 + struct ethtool_value edata = { ETHTOOL_GLINK };
796 + edata.data = netif_carrier_ok(bp->dev) ? 1 : 0;
797 + if (copy_to_user(useraddr, &edata, sizeof(edata)))
801 + case ETHTOOL_GRINGPARAM: {
802 + struct ethtool_ringparam ering = { ETHTOOL_GRINGPARAM };
804 + ering.rx_max_pending = B44_RX_RING_SIZE - 1;
805 + ering.rx_pending = bp->rx_pending;
807 + /* XXX ethtool lacks a tx_max_pending, oops... */
809 + if (copy_to_user(useraddr, &ering, sizeof(ering)))
813 + case ETHTOOL_SRINGPARAM: {
814 + struct ethtool_ringparam ering;
816 + if (copy_from_user(&ering, useraddr, sizeof(ering)))
819 + if ((ering.rx_pending > B44_RX_RING_SIZE - 1) ||
820 + (ering.rx_mini_pending != 0) ||
821 + (ering.rx_jumbo_pending != 0) ||
822 + (ering.tx_pending > B44_TX_RING_SIZE - 1))
825 + spin_lock_irq(&bp->lock);
827 + bp->rx_pending = ering.rx_pending;
828 + bp->tx_pending = ering.tx_pending;
831 + b44_init_rings(bp);
833 + netif_wake_queue(bp->dev);
834 + spin_unlock_irq(&bp->lock);
836 + b44_enable_ints(bp);
840 + case ETHTOOL_GPAUSEPARAM: {
841 + struct ethtool_pauseparam epause = { ETHTOOL_GPAUSEPARAM };
844 + (bp->flags & B44_FLAG_PAUSE_AUTO) != 0;
846 + (bp->flags & B44_FLAG_RX_PAUSE) != 0;
848 + (bp->flags & B44_FLAG_TX_PAUSE) != 0;
849 + if (copy_to_user(useraddr, &epause, sizeof(epause)))
853 + case ETHTOOL_SPAUSEPARAM: {
854 + struct ethtool_pauseparam epause;
856 + if (copy_from_user(&epause, useraddr, sizeof(epause)))
859 + spin_lock_irq(&bp->lock);
860 + if (epause.autoneg)
861 + bp->flags |= B44_FLAG_PAUSE_AUTO;
863 + bp->flags &= ~B44_FLAG_PAUSE_AUTO;
864 + if (epause.rx_pause)
865 + bp->flags |= B44_FLAG_RX_PAUSE;
867 + bp->flags &= ~B44_FLAG_RX_PAUSE;
868 + if (epause.tx_pause)
869 + bp->flags |= B44_FLAG_TX_PAUSE;
871 + bp->flags &= ~B44_FLAG_TX_PAUSE;
872 + if (bp->flags & B44_FLAG_PAUSE_AUTO) {
874 + b44_init_rings(bp);
877 + __b44_set_flow_ctrl(bp, bp->flags);
879 + spin_unlock_irq(&bp->lock);
881 + b44_enable_ints(bp);
887 + return -EOPNOTSUPP;
890 static int b44_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
892 struct mii_ioctl_data *data = if_mii(ifr);
893 struct b44 *bp = netdev_priv(dev);
896 - spin_lock_irq(&bp->lock);
897 - err = generic_mii_ioctl(&bp->mii_if, data, cmd, NULL);
898 - spin_unlock_irq(&bp->lock);
901 + return b44_ethtool_ioctl(dev, (void __user*) ifr->ifr_data);
904 + data->phy_id = bp->phy_addr;
907 + case SIOCGMIIREG: {
911 + spin_lock_irq(&bp->lock);
912 + err = __b44_readphy(bp, data->phy_id & 0x1f, data->reg_num & 0x1f, &mii_regval);
913 + spin_unlock_irq(&bp->lock);
915 + data->val_out = mii_regval;
921 + if (!capable(CAP_NET_ADMIN))
924 + spin_lock_irq(&bp->lock);
925 + err = __b44_writephy(bp, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in);
926 + spin_unlock_irq(&bp->lock);
934 + return -EOPNOTSUPP;
937 /* Read 128-bytes of EEPROM. */
938 @@ -1704,19 +2019,41 @@
942 + unsigned long flags;
944 - err = b44_read_eeprom(bp, &eeprom[0]);
948 - bp->dev->dev_addr[0] = eeprom[79];
949 - bp->dev->dev_addr[1] = eeprom[78];
950 - bp->dev->dev_addr[2] = eeprom[81];
951 - bp->dev->dev_addr[3] = eeprom[80];
952 - bp->dev->dev_addr[4] = eeprom[83];
953 - bp->dev->dev_addr[5] = eeprom[82];
955 - bp->phy_addr = eeprom[90] & 0x1f;
956 + if (bp->pdev->device == PCI_DEVICE_ID_BCM4713) {
958 + * BCM47xx boards don't have a EEPROM. The MAC is stored in
959 + * a NVRAM area somewhere in the flash memory. As we don't
960 + * know the location and/or the format of the NVRAM area
961 + * here, we simply rely on the bootloader to write the
962 + * MAC into the CAM.
964 + spin_lock_irqsave(&bp->lock, flags);
965 + __b44_cam_read(bp, bp->dev->dev_addr, 0);
966 + spin_unlock_irqrestore(&bp->lock, flags);
969 + * BCM47xx boards don't have a PHY. Usually there is a switch
970 + * chip with multiple PHYs connected to the PHY port.
972 + bp->phy_addr = B44_PHY_ADDR_NO_PHY;
973 + bp->dma_offset = 0;
975 + err = b44_read_eeprom(bp, &eeprom[0]);
979 + bp->dev->dev_addr[0] = eeprom[79];
980 + bp->dev->dev_addr[1] = eeprom[78];
981 + bp->dev->dev_addr[2] = eeprom[81];
982 + bp->dev->dev_addr[3] = eeprom[80];
983 + bp->dev->dev_addr[4] = eeprom[83];
984 + bp->dev->dev_addr[5] = eeprom[82];
986 + bp->phy_addr = eeprom[90] & 0x1f;
987 + bp->dma_offset = SB_PCI_DMA;
990 /* With this, plus the rx_header prepended to the data by the
991 * hardware, we'll land the ethernet header on a 2-byte boundary.
992 @@ -1726,13 +2063,12 @@
993 bp->imask = IMASK_DEF;
995 bp->core_unit = ssb_core_unit(bp);
996 - bp->dma_offset = SB_PCI_DMA;
998 /* XXX - really required?
999 bp->flags |= B44_FLAG_BUGGY_TXPTR;
1007 static int __devinit b44_init_one(struct pci_dev *pdev,
1008 @@ -1810,7 +2146,7 @@
1010 spin_lock_init(&bp->lock);
1012 - bp->regs = ioremap(b44reg_base, b44reg_len);
1013 + bp->regs = (unsigned long) ioremap(b44reg_base, b44reg_len);
1014 if (bp->regs == 0UL) {
1015 printk(KERN_ERR PFX "Cannot map device registers, "
1017 @@ -1871,15 +2207,21 @@
1019 pci_save_state(bp->pdev);
1021 - printk(KERN_INFO "%s: Broadcom 4400 10/100BaseT Ethernet ", dev->name);
1022 + printk(KERN_INFO "%s: Broadcom %s 10/100BaseT Ethernet ", dev->name,
1023 + (pdev->device == PCI_DEVICE_ID_BCM4713) ? "47xx" : "4400");
1024 for (i = 0; i < 6; i++)
1025 printk("%2.2x%c", dev->dev_addr[i],
1026 i == 5 ? '\n' : ':');
1028 + /* Initialize phy */
1029 + spin_lock_irq(&bp->lock);
1030 + b44_chip_reset(bp);
1031 + spin_unlock_irq(&bp->lock);
1036 - iounmap(bp->regs);
1037 + iounmap((void *) bp->regs);
1041 @@ -1901,7 +2243,7 @@
1042 struct b44 *bp = netdev_priv(dev);
1044 unregister_netdev(dev);
1045 - iounmap(bp->regs);
1046 + iounmap((void *) bp->regs);
1048 pci_release_regions(pdev);
1049 pci_disable_device(pdev);
1050 diff -Nur linux-2.6.12.5/drivers/net/b44.h linux-2.6.12.5-b44/drivers/net/b44.h
1051 --- linux-2.6.12.5/drivers/net/b44.h 2005-08-15 02:20:18.000000000 +0200
1052 +++ linux-2.6.12.5-b44/drivers/net/b44.h 2005-09-16 11:06:16.393533960 +0200
1054 #define SSB_PCI_MASK1 0xfc000000
1055 #define SSB_PCI_MASK2 0xc0000000
1057 +#define br32(REG) readl((void *)bp->regs + (REG))
1058 +#define bw32(REG,VAL) writel((VAL), (void *)bp->regs + (REG))
1060 /* 4400 PHY registers */
1061 #define B44_MII_AUXCTRL 24 /* Auxiliary Control */
1062 #define MII_AUXCTRL_DUPLEX 0x0001 /* Full Duplex */
1066 #define B44_MCAST_TABLE_SIZE 32
1067 +#define B44_PHY_ADDR_NO_PHY 30
1068 +#define B44_MDC_RATIO 5000000
1070 /* SW copy of device statistics, kept up to date by periodic timer
1071 * which probes HW values. Must have same relative layout as HW
1073 struct net_device_stats stats;
1074 struct b44_hw_stats hw_stats;
1076 - void __iomem *regs;
1077 + unsigned long regs;
1078 struct pci_dev *pdev;
1079 struct net_device *dev;