1 diff -urN linux.old/drivers/net/b44.c linux.dev/drivers/net/b44.c
2 --- linux.old/drivers/net/b44.c 2006-01-12 01:44:42.548326000 +0100
3 +++ linux.dev/drivers/net/b44.c 2006-01-13 17:30:08.283122500 +0100
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)
12 + * Copyright (C) 2006 Felix Fietkau (nbd@openwrt.org)
14 * Distribute under GPL.
17 #define DRV_MODULE_VERSION "0.97"
18 #define DRV_MODULE_RELDATE "Nov 30, 2005"
20 +#ifdef CONFIG_BCM947XX
21 +extern char *nvram_get(char *name);
22 +static inline void e_aton(char *str, char *dest)
32 + dest[i++] = (char) simple_strtoul(str, NULL, 16);
34 + if (!*str++ || i == 6)
39 +static int b44_4713_instance;
42 #define B44_DEF_MSG_ENABLE \
46 static char version[] __devinitdata =
47 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
49 -MODULE_AUTHOR("Florian Schirmer, Pekka Pietikainen, David S. Miller");
50 -MODULE_DESCRIPTION("Broadcom 4400 10/100 PCI ethernet driver");
51 +MODULE_AUTHOR("Felix Fietkau, Florian Schirmer, Pekka Pietikainen, David S. Miller");
52 +MODULE_DESCRIPTION("Broadcom 4400/47xx 10/100 PCI ethernet driver");
53 MODULE_LICENSE("GPL");
54 MODULE_VERSION(DRV_MODULE_VERSION);
57 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
58 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_BCM4401B1,
59 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
60 +#ifdef CONFIG_BCM947XX
61 + { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_BCM4713,
62 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
64 { } /* terminate list with empty entry */
68 dma_desc_sync_size, dir);
71 -static inline unsigned long br32(const struct b44 *bp, unsigned long reg)
73 - return readl(bp->regs + reg);
76 -static inline void bw32(const struct b44 *bp,
77 - unsigned long reg, unsigned long val)
79 - writel(val, bp->regs + reg);
82 static int b44_wait_bit(struct b44 *bp, unsigned long reg,
83 u32 bit, unsigned long timeout, const int clear)
89 +#ifdef CONFIG_BCM947XX
90 + if (bp->pdev->device == PCI_DEVICE_ID_BCM4713)
91 + return b44_4713_instance++;
97 bw32(bp, B44_IMASK, bp->imask);
100 -static int b44_readphy(struct b44 *bp, int reg, u32 *val)
101 +static int __b44_readphy(struct b44 *bp, int phy_addr, int reg, u32 *val)
105 bw32(bp, B44_EMAC_ISTAT, EMAC_INT_MII);
106 bw32(bp, B44_MDIO_DATA, (MDIO_DATA_SB_START |
107 (MDIO_OP_READ << MDIO_DATA_OP_SHIFT) |
108 - (bp->phy_addr << MDIO_DATA_PMD_SHIFT) |
109 + (phy_addr << MDIO_DATA_PMD_SHIFT) |
110 (reg << MDIO_DATA_RA_SHIFT) |
111 (MDIO_TA_VALID << MDIO_DATA_TA_SHIFT)));
112 err = b44_wait_bit(bp, B44_EMAC_ISTAT, EMAC_INT_MII, 100, 0);
113 @@ -329,18 +350,34 @@
117 -static int b44_writephy(struct b44 *bp, int reg, u32 val)
118 +static int __b44_writephy(struct b44 *bp, int phy_addr, int reg, u32 val)
120 bw32(bp, B44_EMAC_ISTAT, EMAC_INT_MII);
121 bw32(bp, B44_MDIO_DATA, (MDIO_DATA_SB_START |
122 (MDIO_OP_WRITE << MDIO_DATA_OP_SHIFT) |
123 - (bp->phy_addr << MDIO_DATA_PMD_SHIFT) |
124 + (phy_addr << MDIO_DATA_PMD_SHIFT) |
125 (reg << MDIO_DATA_RA_SHIFT) |
126 (MDIO_TA_VALID << MDIO_DATA_TA_SHIFT) |
127 (val & MDIO_DATA_DATA)));
128 return b44_wait_bit(bp, B44_EMAC_ISTAT, EMAC_INT_MII, 100, 0);
131 +static inline int b44_readphy(struct b44 *bp, int reg, u32 *val)
133 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
136 + return __b44_readphy(bp, bp->phy_addr, reg, val);
139 +static inline int b44_writephy(struct b44 *bp, int reg, u32 val)
141 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
144 + return __b44_writephy(bp, bp->phy_addr, reg, val);
147 /* miilib interface */
148 /* FIXME FIXME: phy_id is ignored, bp->phy_addr use is unconditional
149 * due to code existing before miilib use was added to this driver.
154 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
156 err = b44_writephy(bp, MII_BMCR, BMCR_RESET);
163 +#ifdef CONFIG_BCM947XX
165 + if ((s = nvram_get("boardnum")) && (s != NULL) && \
166 + !strncmp(s, "2", 1) && \
167 + (__b44_readphy(bp, 0, MII_BMCR, &val) != 0) && \
168 + (val & BMCR_ISOLATE) && \
169 + (__b44_writephy(bp, 0, MII_BMCR, val & ~BMCR_ISOLATE) != 0)) {
170 + printk(KERN_WARNING PFX "PHY: cannot reset MII transceiver isolate bit.\n");
173 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
175 if ((err = b44_readphy(bp, B44_MII_ALEDCTRL, &val)) != 0)
177 if ((err = b44_writephy(bp, B44_MII_ALEDCTRL,
182 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY) {
183 + bp->flags |= B44_FLAG_100_BASE_T;
184 + bp->flags |= B44_FLAG_FULL_DUPLEX;
185 + if (!netif_carrier_ok(bp->dev)) {
186 + u32 val = br32(bp, B44_TX_CTRL);
187 + val |= TX_CTRL_DUPLEX;
188 + bw32(bp, B44_TX_CTRL, val);
189 + netif_carrier_on(bp->dev);
190 + b44_link_report(bp);
195 if (!b44_readphy(bp, MII_BMSR, &bmsr) &&
196 !b44_readphy(bp, B44_MII_AUXCTRL, &aux) &&
198 @@ -1281,9 +1345,10 @@
199 bw32(bp, B44_DMARX_CTRL, 0);
200 bp->rx_prod = bp->rx_cons = 0;
202 - ssb_pci_setup(bp, (bp->core_unit == 0 ?
205 + if (bp->pdev->device != PCI_DEVICE_ID_BCM4713)
206 + ssb_pci_setup(bp, (bp->core_unit == 0 ?
212 @@ -1291,8 +1356,14 @@
215 /* Make PHY accessible. */
216 - bw32(bp, B44_MDIO_CTRL, (MDIO_CTRL_PREAMBLE |
217 + if (bp->pdev->device == PCI_DEVICE_ID_BCM4713)
218 + bw32(bp, B44_MDIO_CTRL, (MDIO_CTRL_PREAMBLE |
219 + (((100000000 + (B44_MDC_RATIO / 2)) / B44_MDC_RATIO)
220 + & MDIO_CTRL_MAXF_MASK)));
222 + bw32(bp, B44_MDIO_CTRL, (MDIO_CTRL_PREAMBLE |
223 (0x0d & MDIO_CTRL_MAXF_MASK)));
225 br32(bp, B44_MDIO_CTRL);
227 if (!(br32(bp, B44_DEVCTRL) & DEVCTRL_IPP)) {
228 @@ -1834,18 +1905,297 @@
229 .get_perm_addr = ethtool_op_get_perm_addr,
232 +static int b44_ethtool_ioctl (struct net_device *dev, void __user *useraddr)
234 + struct b44 *bp = dev->priv;
235 + struct pci_dev *pci_dev = bp->pdev;
238 + if (copy_from_user (ðcmd, useraddr, sizeof (ethcmd)))
242 + case ETHTOOL_GDRVINFO: {
243 + struct ethtool_drvinfo info = { ETHTOOL_GDRVINFO };
244 + strcpy (info.driver, DRV_MODULE_NAME);
245 + strcpy (info.version, DRV_MODULE_VERSION);
246 + memset(&info.fw_version, 0, sizeof(info.fw_version));
247 + strcpy (info.bus_info, pci_name(pci_dev));
248 + info.eedump_len = 0;
249 + info.regdump_len = 0;
250 + if (copy_to_user (useraddr, &info, sizeof (info)))
255 + case ETHTOOL_GSET: {
256 + struct ethtool_cmd cmd = { ETHTOOL_GSET };
258 + if (!(bp->flags & B44_FLAG_INIT_COMPLETE))
260 + cmd.supported = (SUPPORTED_Autoneg);
261 + cmd.supported |= (SUPPORTED_100baseT_Half |
262 + SUPPORTED_100baseT_Full |
263 + SUPPORTED_10baseT_Half |
264 + SUPPORTED_10baseT_Full |
267 + cmd.advertising = 0;
268 + if (bp->flags & B44_FLAG_ADV_10HALF)
269 + cmd.advertising |= ADVERTISE_10HALF;
270 + if (bp->flags & B44_FLAG_ADV_10FULL)
271 + cmd.advertising |= ADVERTISE_10FULL;
272 + if (bp->flags & B44_FLAG_ADV_100HALF)
273 + cmd.advertising |= ADVERTISE_100HALF;
274 + if (bp->flags & B44_FLAG_ADV_100FULL)
275 + cmd.advertising |= ADVERTISE_100FULL;
276 + cmd.advertising |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
277 + cmd.speed = (bp->flags & B44_FLAG_100_BASE_T) ?
278 + SPEED_100 : SPEED_10;
279 + cmd.duplex = (bp->flags & B44_FLAG_FULL_DUPLEX) ?
280 + DUPLEX_FULL : DUPLEX_HALF;
282 + cmd.phy_address = bp->phy_addr;
283 + cmd.transceiver = (bp->flags & B44_FLAG_INTERNAL_PHY) ?
284 + XCVR_INTERNAL : XCVR_EXTERNAL;
285 + cmd.autoneg = (bp->flags & B44_FLAG_FORCE_LINK) ?
286 + AUTONEG_DISABLE : AUTONEG_ENABLE;
289 + if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
293 + case ETHTOOL_SSET: {
294 + struct ethtool_cmd cmd;
296 + if (!(bp->flags & B44_FLAG_INIT_COMPLETE))
299 + if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
302 + /* We do not support gigabit. */
303 + if (cmd.autoneg == AUTONEG_ENABLE) {
304 + if (cmd.advertising &
305 + (ADVERTISED_1000baseT_Half |
306 + ADVERTISED_1000baseT_Full))
308 + } else if ((cmd.speed != SPEED_100 &&
309 + cmd.speed != SPEED_10) ||
310 + (cmd.duplex != DUPLEX_HALF &&
311 + cmd.duplex != DUPLEX_FULL)) {
315 + spin_lock_irq(&bp->lock);
317 + if (cmd.autoneg == AUTONEG_ENABLE) {
318 + bp->flags &= ~B44_FLAG_FORCE_LINK;
319 + bp->flags &= ~(B44_FLAG_ADV_10HALF |
320 + B44_FLAG_ADV_10FULL |
321 + B44_FLAG_ADV_100HALF |
322 + B44_FLAG_ADV_100FULL);
323 + if (cmd.advertising & ADVERTISE_10HALF)
324 + bp->flags |= B44_FLAG_ADV_10HALF;
325 + if (cmd.advertising & ADVERTISE_10FULL)
326 + bp->flags |= B44_FLAG_ADV_10FULL;
327 + if (cmd.advertising & ADVERTISE_100HALF)
328 + bp->flags |= B44_FLAG_ADV_100HALF;
329 + if (cmd.advertising & ADVERTISE_100FULL)
330 + bp->flags |= B44_FLAG_ADV_100FULL;
332 + bp->flags |= B44_FLAG_FORCE_LINK;
333 + if (cmd.speed == SPEED_100)
334 + bp->flags |= B44_FLAG_100_BASE_T;
335 + if (cmd.duplex == DUPLEX_FULL)
336 + bp->flags |= B44_FLAG_FULL_DUPLEX;
341 + spin_unlock_irq(&bp->lock);
346 + case ETHTOOL_GMSGLVL: {
347 + struct ethtool_value edata = { ETHTOOL_GMSGLVL };
348 + edata.data = bp->msg_enable;
349 + if (copy_to_user(useraddr, &edata, sizeof(edata)))
353 + case ETHTOOL_SMSGLVL: {
354 + struct ethtool_value edata;
355 + if (copy_from_user(&edata, useraddr, sizeof(edata)))
357 + bp->msg_enable = edata.data;
360 + case ETHTOOL_NWAY_RST: {
364 + spin_lock_irq(&bp->lock);
365 + b44_readphy(bp, MII_BMCR, &bmcr);
366 + b44_readphy(bp, MII_BMCR, &bmcr);
368 + if (bmcr & BMCR_ANENABLE) {
369 + b44_writephy(bp, MII_BMCR,
370 + bmcr | BMCR_ANRESTART);
373 + spin_unlock_irq(&bp->lock);
377 + case ETHTOOL_GLINK: {
378 + struct ethtool_value edata = { ETHTOOL_GLINK };
379 + edata.data = netif_carrier_ok(bp->dev) ? 1 : 0;
380 + if (copy_to_user(useraddr, &edata, sizeof(edata)))
384 + case ETHTOOL_GRINGPARAM: {
385 + struct ethtool_ringparam ering = { ETHTOOL_GRINGPARAM };
387 + ering.rx_max_pending = B44_RX_RING_SIZE - 1;
388 + ering.rx_pending = bp->rx_pending;
390 + /* XXX ethtool lacks a tx_max_pending, oops... */
392 + if (copy_to_user(useraddr, &ering, sizeof(ering)))
396 + case ETHTOOL_SRINGPARAM: {
397 + struct ethtool_ringparam ering;
399 + if (copy_from_user(&ering, useraddr, sizeof(ering)))
402 + if ((ering.rx_pending > B44_RX_RING_SIZE - 1) ||
403 + (ering.rx_mini_pending != 0) ||
404 + (ering.rx_jumbo_pending != 0) ||
405 + (ering.tx_pending > B44_TX_RING_SIZE - 1))
408 + spin_lock_irq(&bp->lock);
410 + bp->rx_pending = ering.rx_pending;
411 + bp->tx_pending = ering.tx_pending;
414 + b44_init_rings(bp);
416 + netif_wake_queue(bp->dev);
417 + spin_unlock_irq(&bp->lock);
419 + b44_enable_ints(bp);
423 + case ETHTOOL_GPAUSEPARAM: {
424 + struct ethtool_pauseparam epause = { ETHTOOL_GPAUSEPARAM };
427 + (bp->flags & B44_FLAG_PAUSE_AUTO) != 0;
429 + (bp->flags & B44_FLAG_RX_PAUSE) != 0;
431 + (bp->flags & B44_FLAG_TX_PAUSE) != 0;
432 + if (copy_to_user(useraddr, &epause, sizeof(epause)))
436 + case ETHTOOL_SPAUSEPARAM: {
437 + struct ethtool_pauseparam epause;
439 + if (copy_from_user(&epause, useraddr, sizeof(epause)))
442 + spin_lock_irq(&bp->lock);
443 + if (epause.autoneg)
444 + bp->flags |= B44_FLAG_PAUSE_AUTO;
446 + bp->flags &= ~B44_FLAG_PAUSE_AUTO;
447 + if (epause.rx_pause)
448 + bp->flags |= B44_FLAG_RX_PAUSE;
450 + bp->flags &= ~B44_FLAG_RX_PAUSE;
451 + if (epause.tx_pause)
452 + bp->flags |= B44_FLAG_TX_PAUSE;
454 + bp->flags &= ~B44_FLAG_TX_PAUSE;
455 + if (bp->flags & B44_FLAG_PAUSE_AUTO) {
457 + b44_init_rings(bp);
460 + __b44_set_flow_ctrl(bp, bp->flags);
462 + spin_unlock_irq(&bp->lock);
464 + b44_enable_ints(bp);
470 + return -EOPNOTSUPP;
473 static int b44_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
475 struct mii_ioctl_data *data = if_mii(ifr);
476 struct b44 *bp = netdev_priv(dev);
479 - if (!netif_running(dev))
480 + if (bp->pdev->device != PCI_DEVICE_ID_BCM4713) {
481 + if (!netif_running(dev))
484 + spin_lock_irq(&bp->lock);
485 + err = generic_mii_ioctl(&bp->mii_if, data, cmd, NULL);
486 + spin_unlock_irq(&bp->lock);
490 - spin_lock_irq(&bp->lock);
491 - err = generic_mii_ioctl(&bp->mii_if, data, cmd, NULL);
492 - spin_unlock_irq(&bp->lock);
495 + return b44_ethtool_ioctl(dev, (void __user*) ifr->ifr_data);
498 + data->phy_id = bp->phy_addr;
501 + case SIOCGMIIREG: {
503 + spin_lock_irq(&bp->lock);
504 + err = __b44_readphy(bp, data->phy_id & 0x1f, data->reg_num & 0x1f, &mii_regval);
505 + spin_unlock_irq(&bp->lock);
507 + data->val_out = mii_regval;
513 + if (!capable(CAP_NET_ADMIN))
516 + spin_lock_irq(&bp->lock);
517 + err = __b44_writephy(bp, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in);
518 + spin_unlock_irq(&bp->lock);
525 + return -EOPNOTSUPP;
530 @@ -1865,22 +2215,43 @@
531 static int __devinit b44_get_invariants(struct b44 *bp)
538 - err = b44_read_eeprom(bp, &eeprom[0]);
542 - bp->dev->dev_addr[0] = eeprom[79];
543 - bp->dev->dev_addr[1] = eeprom[78];
544 - bp->dev->dev_addr[2] = eeprom[81];
545 - bp->dev->dev_addr[3] = eeprom[80];
546 - bp->dev->dev_addr[4] = eeprom[83];
547 - bp->dev->dev_addr[5] = eeprom[82];
548 - memcpy(bp->dev->perm_addr, bp->dev->dev_addr, bp->dev->addr_len);
550 - bp->phy_addr = eeprom[90] & 0x1f;
551 +#ifdef CONFIG_BCM947XX
552 + if (bp->pdev->device == PCI_DEVICE_ID_BCM4713) {
554 + * BCM47xx boards don't have a EEPROM. The MAC is stored in
555 + * a NVRAM area somewhere in the flash memory.
557 + sprintf(buf, "et%dmacaddr", b44_4713_instance);
558 + e_aton(nvram_get(buf), bp->dev->dev_addr);
561 + * BCM47xx boards don't have a PHY. Usually there is a switch
562 + * chip with multiple PHYs connected to the PHY port.
564 + bp->phy_addr = B44_PHY_ADDR_NO_PHY;
565 + bp->dma_offset = 0;
569 + err = b44_read_eeprom(bp, &eeprom[0]);
573 + bp->dev->dev_addr[0] = eeprom[79];
574 + bp->dev->dev_addr[1] = eeprom[78];
575 + bp->dev->dev_addr[2] = eeprom[81];
576 + bp->dev->dev_addr[3] = eeprom[80];
577 + bp->dev->dev_addr[4] = eeprom[83];
578 + bp->dev->dev_addr[5] = eeprom[82];
579 + memcpy(bp->dev->perm_addr, bp->dev->dev_addr, bp->dev->addr_len);
581 + bp->phy_addr = eeprom[90] & 0x1f;
582 + bp->dma_offset = SB_PCI_DMA;
585 /* With this, plus the rx_header prepended to the data by the
586 * hardware, we'll land the ethernet header on a 2-byte boundary.
588 @@ -1889,11 +2260,7 @@
589 bp->imask = IMASK_DEF;
591 bp->core_unit = ssb_core_unit(bp);
592 - bp->dma_offset = SB_PCI_DMA;
594 - /* XXX - really required?
595 - bp->flags |= B44_FLAG_BUGGY_TXPTR;
600 @@ -2032,11 +2399,17 @@
602 pci_save_state(bp->pdev);
604 - printk(KERN_INFO "%s: Broadcom 4400 10/100BaseT Ethernet ", dev->name);
605 + printk(KERN_INFO "%s: Broadcom %s 10/100BaseT Ethernet ", dev->name,
606 + (pdev->device == PCI_DEVICE_ID_BCM4713) ? "47xx" : "4400");
607 for (i = 0; i < 6; i++)
608 printk("%2.2x%c", dev->dev_addr[i],
609 i == 5 ? '\n' : ':');
611 + /* Initialize phy */
612 + spin_lock_irq(&bp->lock);
613 + b44_chip_reset(bp);
614 + spin_unlock_irq(&bp->lock);
619 diff -urN linux.old/drivers/net/b44.h linux.dev/drivers/net/b44.h
620 --- linux.old/drivers/net/b44.h 2006-01-12 01:44:42.548326000 +0100
621 +++ linux.dev/drivers/net/b44.h 2006-01-12 02:55:06.290783500 +0100
623 #define SSB_PCI_MASK1 0xfc000000
624 #define SSB_PCI_MASK2 0xc0000000
626 +#define br32(bp, REG) readl((void *)bp->regs + (REG))
627 +#define bw32(bp, REG,VAL) writel((VAL), (void *)bp->regs + (REG))
628 +#define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0)
630 /* 4400 PHY registers */
631 #define B44_MII_AUXCTRL 24 /* Auxiliary Control */
632 #define MII_AUXCTRL_DUPLEX 0x0001 /* Full Duplex */
636 #define B44_MCAST_TABLE_SIZE 32
637 +#define B44_PHY_ADDR_NO_PHY 30
638 +#define B44_MDC_RATIO 5000000
640 #define B44_STAT_REG_DECLARE \
641 _B44(tx_good_octets) \
646 +#define B44_FLAG_INIT_COMPLETE 0x00000001
647 #define B44_FLAG_BUGGY_TXPTR 0x00000002
648 #define B44_FLAG_REORDER_BUG 0x00000004
649 #define B44_FLAG_PAUSE_AUTO 0x00008000