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 17:27:45.920623500 +0100
3 +++ linux.dev/drivers/net/b44.c 2006-01-13 13:29:18.782391750 +0100
5 /* b44.c: Broadcom 4400 device driver.
7 * Copyright (C) 2002 David S. Miller (davem@redhat.com)
8 - * Fixed by Pekka Pietikainen (pp@ee.oulu.fi)
9 + * Copyright (C) 2004 Pekka Pietikainen (pp@ee.oulu.fi)
10 + * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
11 + * Copyright (C) 2006 Felix Fietkau (nbd@openwrt.org)
13 * Distribute under GPL.
19 +#include <typedefs.h>
21 +#include <bcmutils.h>
23 +#include <bcmutils.h>
24 +#include <bcmnvram.h>
25 +#include <sbconfig.h>
29 +#ifdef CONFIG_BCM947XX
30 +#define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0)
32 +static inline void e_aton(char *str, char *dest)
35 + u16 *d = (u16 *) dest;
43 + dest[i++] = (char) simple_strtoul(str, NULL, 16);
45 + if (!*str++ || i == 6)
50 +static int instance = 0;
54 #define DRV_MODULE_NAME "b44"
55 #define PFX DRV_MODULE_NAME ": "
56 #define DRV_MODULE_VERSION "0.93"
58 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
60 MODULE_AUTHOR("David S. Miller (davem@redhat.com)");
61 -MODULE_DESCRIPTION("Broadcom 4400 10/100 PCI ethernet driver");
62 +MODULE_DESCRIPTION("Broadcom 4400/47xx 10/100 PCI ethernet driver");
63 MODULE_LICENSE("GPL");
64 MODULE_PARM(b44_debug, "i");
65 MODULE_PARM_DESC(b44_debug, "B44 bitmapped debugging message enable value");
67 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
68 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_BCM4401B1,
69 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
70 + { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_BCM4713,
71 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
72 { } /* terminate list with empty entry */
79 +static int b44_4713_instance;
81 static int ssb_core_unit(struct b44 *bp)
88 + if (bp->pdev->device == PCI_DEVICE_ID_BCM4713)
89 + return b44_4713_instance++;
98 +static inline void __b44_cam_read(struct b44 *bp, unsigned char *data, int index)
102 + bw32(B44_CAM_CTRL, (CAM_CTRL_READ |
103 + (index << CAM_CTRL_INDEX_SHIFT)));
105 + b44_wait_bit(bp, B44_CAM_CTRL, CAM_CTRL_BUSY, 100, 1);
107 + val = br32(B44_CAM_DATA_LO);
109 + data[2] = (val >> 24) & 0xFF;
110 + data[3] = (val >> 16) & 0xFF;
111 + data[4] = (val >> 8) & 0xFF;
112 + data[5] = (val >> 0) & 0xFF;
114 + val = br32(B44_CAM_DATA_HI);
116 + data[0] = (val >> 8) & 0xFF;
117 + data[1] = (val >> 0) & 0xFF;
120 static void __b44_cam_write(struct b44 *bp, unsigned char *data, int index)
123 @@ -303,14 +369,14 @@
124 bw32(B44_IMASK, bp->imask);
127 -static int b44_readphy(struct b44 *bp, int reg, u32 *val)
128 +static int __b44_readphy(struct b44 *bp, int phy_addr, int reg, u32 *val)
132 bw32(B44_EMAC_ISTAT, EMAC_INT_MII);
133 bw32(B44_MDIO_DATA, (MDIO_DATA_SB_START |
134 (MDIO_OP_READ << MDIO_DATA_OP_SHIFT) |
135 - (bp->phy_addr << MDIO_DATA_PMD_SHIFT) |
136 + (phy_addr << MDIO_DATA_PMD_SHIFT) |
137 (reg << MDIO_DATA_RA_SHIFT) |
138 (MDIO_TA_VALID << MDIO_DATA_TA_SHIFT)));
139 err = b44_wait_bit(bp, B44_EMAC_ISTAT, EMAC_INT_MII, 100, 0);
140 @@ -319,23 +385,42 @@
144 -static int b44_writephy(struct b44 *bp, int reg, u32 val)
145 +static int b44_readphy(struct b44 *bp, int reg, u32 *val)
147 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
150 + return __b44_readphy(bp, bp->phy_addr, reg, val);
153 +static int __b44_writephy(struct b44 *bp, int phy_addr, int reg, u32 val)
155 bw32(B44_EMAC_ISTAT, EMAC_INT_MII);
156 bw32(B44_MDIO_DATA, (MDIO_DATA_SB_START |
157 (MDIO_OP_WRITE << MDIO_DATA_OP_SHIFT) |
158 - (bp->phy_addr << MDIO_DATA_PMD_SHIFT) |
159 + (phy_addr << MDIO_DATA_PMD_SHIFT) |
160 (reg << MDIO_DATA_RA_SHIFT) |
161 (MDIO_TA_VALID << MDIO_DATA_TA_SHIFT) |
162 (val & MDIO_DATA_DATA)));
163 return b44_wait_bit(bp, B44_EMAC_ISTAT, EMAC_INT_MII, 100, 0);
166 +static int b44_writephy(struct b44 *bp, int reg, u32 val)
168 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
171 + return __b44_writephy(bp, bp->phy_addr, reg, val);
174 static int b44_phy_reset(struct b44 *bp)
179 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
182 err = b44_writephy(bp, MII_BMCR, BMCR_RESET);
191 + if ((s = nvram_get("boardnum")) && (s != NULL) && \
192 + !strncmp(s, "2", 1) && \
193 + (__b44_readphy(bp, 0, MII_BMCR, &val) != 0) && \
194 + (val & BMCR_ISOLATE) && \
195 + (__b44_writephy(bp, 0, MII_BMCR, val & ~BMCR_ISOLATE) != 0)) {
196 + printk(KERN_WARNING PFX "PHY: cannot reset MII transceiver isolate bit.\n");
199 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
202 if ((err = b44_readphy(bp, B44_MII_ALEDCTRL, &val)) != 0)
208 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY) {
209 + bp->flags |= B44_FLAG_100_BASE_T;
210 + bp->flags |= B44_FLAG_FULL_DUPLEX;
211 + if (!netif_carrier_ok(bp->dev)) {
212 + u32 val = br32(B44_TX_CTRL);
213 + val |= TX_CTRL_DUPLEX;
214 + bw32(B44_TX_CTRL, val);
215 + netif_carrier_on(bp->dev);
216 + b44_link_report(bp);
221 if (!b44_readphy(bp, MII_BMSR, &bmsr) &&
222 !b44_readphy(bp, B44_MII_AUXCTRL, &aux) &&
224 @@ -1092,6 +1202,8 @@
225 /* bp->lock is held. */
226 static void b44_chip_reset(struct b44 *bp)
228 + unsigned int sb_clock;
230 if (ssb_is_core_up(bp)) {
231 bw32(B44_RCV_LAZY, 0);
232 bw32(B44_ENET_CTRL, ENET_CTRL_DISABLE);
233 @@ -1105,9 +1217,10 @@
234 bw32(B44_DMARX_CTRL, 0);
235 bp->rx_prod = bp->rx_cons = 0;
237 - ssb_pci_setup(bp, (bp->core_unit == 0 ?
240 + /*if (bp->pdev->device != PCI_DEVICE_ID_BCM4713)*/
241 + ssb_pci_setup(bp, (bp->core_unit == 0 ?
247 @@ -1115,6 +1228,11 @@
250 /* Make PHY accessible. */
251 + if (bp->pdev->device == PCI_DEVICE_ID_BCM4713)
252 + sb_clock = 100000000; /* 100 MHz */
254 + sb_clock = 62500000; /* 62.5 MHz */
256 bw32(B44_MDIO_CTRL, (MDIO_CTRL_PREAMBLE |
257 (0x0d & MDIO_CTRL_MAXF_MASK)));
259 @@ -1628,7 +1746,7 @@
262 spin_lock_irq(&bp->lock);
263 - err = b44_readphy(bp, data->reg_num & 0x1f, &mii_regval);
264 + err = __b44_readphy(bp, data->phy_id & 0x1f, data->reg_num & 0x1f, &mii_regval);
265 spin_unlock_irq(&bp->lock);
267 data->val_out = mii_regval;
268 @@ -1641,7 +1759,7 @@
271 spin_lock_irq(&bp->lock);
272 - err = b44_writephy(bp, data->reg_num & 0x1f, data->val_in);
273 + err = __b44_writephy(bp, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in);
274 spin_unlock_irq(&bp->lock);
277 @@ -1668,21 +1786,52 @@
278 static int __devinit b44_get_invariants(struct b44 *bp)
283 + unsigned long flags;
285 - err = b44_read_eeprom(bp, &eeprom[0]);
289 - bp->dev->dev_addr[0] = eeprom[79];
290 - bp->dev->dev_addr[1] = eeprom[78];
291 - bp->dev->dev_addr[2] = eeprom[81];
292 - bp->dev->dev_addr[3] = eeprom[80];
293 - bp->dev->dev_addr[4] = eeprom[83];
294 - bp->dev->dev_addr[5] = eeprom[82];
296 - bp->phy_addr = eeprom[90] & 0x1f;
297 - bp->mdc_port = (eeprom[90] >> 14) & 0x1;
298 + if (bp->pdev->device == PCI_DEVICE_ID_BCM4713) {
299 +#ifdef CONFIG_BCM947XX
300 + sprintf(buf, "et%dmacaddr", instance - 1);
301 + e_aton(nvram_get(buf), bp->dev->dev_addr);
303 + sprintf(buf, "et%dphyaddr", instance - 1);
304 + bp->phy_addr = B44_PHY_ADDR_NO_PHY;
307 + * BCM47xx boards don't have a EEPROM. The MAC is stored in
308 + * a NVRAM area somewhere in the flash memory. As we don't
309 + * know the location and/or the format of the NVRAM area
310 + * here, we simply rely on the bootloader to write the
311 + * MAC into the CAM.
313 + spin_lock_irqsave(&bp->lock, flags);
314 + __b44_cam_read(bp, bp->dev->dev_addr, 0);
315 + spin_unlock_irqrestore(&bp->lock, flags);
318 + * BCM47xx boards don't have a PHY. Usually there is a switch
319 + * chip with multiple PHYs connected to the PHY port.
321 + bp->phy_addr = B44_PHY_ADDR_NO_PHY;
323 + bp->dma_offset = 0;
325 + err = b44_read_eeprom(bp, &eeprom[0]);
329 + bp->dev->dev_addr[0] = eeprom[79];
330 + bp->dev->dev_addr[1] = eeprom[78];
331 + bp->dev->dev_addr[2] = eeprom[81];
332 + bp->dev->dev_addr[3] = eeprom[80];
333 + bp->dev->dev_addr[4] = eeprom[83];
334 + bp->dev->dev_addr[5] = eeprom[82];
336 + bp->phy_addr = eeprom[90] & 0x1f;
337 + bp->dma_offset = SB_PCI_DMA;
338 + bp->mdc_port = (eeprom[90] >> 14) & 0x1;
341 /* With this, plus the rx_header prepended to the data by the
342 * hardware, we'll land the ethernet header on a 2-byte boundary.
343 @@ -1692,13 +1841,12 @@
344 bp->imask = IMASK_DEF;
346 bp->core_unit = ssb_core_unit(bp);
347 - bp->dma_offset = ssb_get_addr(bp, SBID_PCI_DMA, 0);
349 /* XXX - really required?
350 bp->flags |= B44_FLAG_BUGGY_TXPTR;
358 static int __devinit b44_init_one(struct pci_dev *pdev,
359 @@ -1710,6 +1858,10 @@
363 +#ifdef CONFIG_BCM947XX
367 if (b44_version_printed++ == 0)
368 printk(KERN_INFO "%s", version);
370 @@ -1819,11 +1971,17 @@
372 pci_save_state(bp->pdev, bp->pci_cfg_state);
374 - printk(KERN_INFO "%s: Broadcom 4400 10/100BaseT Ethernet ", dev->name);
375 + printk(KERN_INFO "%s: Broadcom %s 10/100BaseT Ethernet ", dev->name,
376 + (pdev->device == PCI_DEVICE_ID_BCM4713) ? "47xx" : "4400");
377 for (i = 0; i < 6; i++)
378 printk("%2.2x%c", dev->dev_addr[i],
379 i == 5 ? '\n' : ':');
381 + /* Initialize phy */
382 + spin_lock_irq(&bp->lock);
383 + b44_chip_reset(bp);
384 + spin_unlock_irq(&bp->lock);
389 diff -urN linux.old/drivers/net/b44.h linux.dev/drivers/net/b44.h
390 --- linux.old/drivers/net/b44.h 2006-01-12 17:26:13.234831000 +0100
391 +++ linux.dev/drivers/net/b44.h 2006-01-12 17:22:01.043070000 +0100
393 #define SBIPSFLAG_IMASK4 0x3f000000 /* Which sbflags --> mips interrupt 4 */
394 #define SBIPSFLAG_ISHIFT4 24
395 #define B44_SBTPSFLAG 0x0F18UL /* SB Target Port OCP Slave Flag */
396 -#define SBTPS_NUM0_MASK 0x0000003f
397 -#define SBTPS_F0EN0 0x00000040
398 #define B44_SBADMATCH3 0x0F60UL /* SB Address Match 3 */
399 #define B44_SBADMATCH2 0x0F68UL /* SB Address Match 2 */
400 #define B44_SBADMATCH1 0x0F70UL /* SB Address Match 1 */
404 #define B44_MCAST_TABLE_SIZE 32
405 +#define B44_PHY_ADDR_NO_PHY 30
406 +#define B44_MDC_RATIO 5000000
408 /* SW copy of device statistics, kept up to date by periodic timer
409 * which probes HW values. Must have same relative layout as HW
410 diff -urN linux.old/include/linux/pci_ids.h linux.dev/include/linux/pci_ids.h
411 --- linux.old/include/linux/pci_ids.h 2006-01-12 17:26:13.250832000 +0100
412 +++ linux.dev/include/linux/pci_ids.h 2006-01-12 17:22:01.071071750 +0100
413 @@ -1735,6 +1735,7 @@
414 #define PCI_DEVICE_ID_TIGON3_5901_2 0x170e
415 #define PCI_DEVICE_ID_BCM4401 0x4401
416 #define PCI_DEVICE_ID_BCM4401B0 0x4402
417 +#define PCI_DEVICE_ID_BCM4713 0x4713
419 #define PCI_VENDOR_ID_ENE 0x1524
420 #define PCI_DEVICE_ID_ENE_1211 0x1211