1 // SPDX-License-Identifier: GPL-2.0
2 /* sunhme.c: Sparc HME/BigMac 10/100baseT half/full duplex auto switching,
3 * auto carrier detecting ethernet driver. Also known as the
4 * "Happy Meal Ethernet" found on SunSwift SBUS cards.
6 * Copyright (C) 1996, 1998, 1999, 2002, 2003,
7 * 2006, 2008 David S. Miller (davem@davemloft.net)
10 * 2000/11/11 Willy Tarreau <willy AT meta-x.org>
11 * - port to non-sparc architectures. Tested only on x86 and
12 * only currently works with QFE PCI cards.
13 * - ability to specify the MAC address at module load time by passing this
14 * argument : macaddr=0x00,0x10,0x20,0x30,0x40,0x50
17 #include <linux/bitops.h>
18 #include <linux/crc32.h>
19 #include <linux/delay.h>
20 #include <linux/dma-mapping.h>
21 #include <linux/errno.h>
22 #include <linux/etherdevice.h>
23 #include <linux/ethtool.h>
24 #include <linux/fcntl.h>
26 #include <linux/init.h>
27 #include <linux/interrupt.h>
29 #include <linux/ioport.h>
30 #include <linux/kernel.h>
31 #include <linux/mii.h>
33 #include <linux/module.h>
34 #include <linux/netdevice.h>
36 #include <linux/of_device.h>
37 #include <linux/pci.h>
38 #include <linux/platform_device.h>
39 #include <linux/random.h>
40 #include <linux/skbuff.h>
41 #include <linux/slab.h>
42 #include <linux/string.h>
43 #include <linux/types.h>
44 #include <linux/uaccess.h>
46 #include <asm/byteorder.h>
51 #include <asm/auxio.h>
52 #include <asm/idprom.h>
53 #include <asm/openprom.h>
54 #include <asm/oplib.h>
60 #define DRV_NAME "sunhme"
62 MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
63 MODULE_DESCRIPTION("Sun HappyMealEthernet(HME) 10/100baseT ethernet driver");
64 MODULE_LICENSE("GPL");
66 static int macaddr
[6];
68 /* accept MAC address of the form macaddr=0x08,0x00,0x20,0x30,0x40,0x50 */
69 module_param_array(macaddr
, int, NULL
, 0);
70 MODULE_PARM_DESC(macaddr
, "Happy Meal MAC address to set");
73 static struct quattro
*qfe_sbus_list
;
77 static struct quattro
*qfe_pci_list
;
80 #define hme_debug(fmt, ...) pr_debug("%s: " fmt, __func__, ##__VA_ARGS__)
83 /* "Auto Switch Debug" aka phy debug */
91 struct hme_tx_logent
{
95 #define TXLOG_ACTION_IRQ 0x01
96 #define TXLOG_ACTION_TXMIT 0x02
97 #define TXLOG_ACTION_TBUSY 0x04
98 #define TXLOG_ACTION_NBUFS 0x08
101 #define TX_LOG_LEN 128
102 static struct hme_tx_logent tx_log
[TX_LOG_LEN
];
103 static int txlog_cur_entry
;
104 static __inline__
void tx_add_log(struct happy_meal
*hp
, unsigned int a
, unsigned int s
)
106 struct hme_tx_logent
*tlp
;
109 local_irq_save(flags
);
110 tlp
= &tx_log
[txlog_cur_entry
];
111 tlp
->tstamp
= (unsigned int)jiffies
;
112 tlp
->tx_new
= hp
->tx_new
;
113 tlp
->tx_old
= hp
->tx_old
;
116 txlog_cur_entry
= (txlog_cur_entry
+ 1) & (TX_LOG_LEN
- 1);
117 local_irq_restore(flags
);
119 static __inline__
void tx_dump_log(void)
123 this = txlog_cur_entry
;
124 for (i
= 0; i
< TX_LOG_LEN
; i
++) {
125 pr_err("TXLOG[%d]: j[%08x] tx[N(%d)O(%d)] action[%08x] stat[%08x]\n", i
,
127 tx_log
[this].tx_new
, tx_log
[this].tx_old
,
128 tx_log
[this].action
, tx_log
[this].status
);
129 this = (this + 1) & (TX_LOG_LEN
- 1);
133 #define tx_add_log(hp, a, s)
134 #define tx_dump_log()
137 #define DEFAULT_IPG0 16 /* For lance-mode only */
138 #define DEFAULT_IPG1 8 /* For all modes */
139 #define DEFAULT_IPG2 4 /* For all modes */
140 #define DEFAULT_JAMSIZE 4 /* Toe jam */
142 /* NOTE: In the descriptor writes one _must_ write the address
143 * member _first_. The card must not be allowed to see
144 * the updated descriptor flags until the address is
145 * correct. I've added a write memory barrier between
146 * the two stores so that I can sleep well at night... -DaveM
149 #if defined(CONFIG_SBUS) && defined(CONFIG_PCI)
150 static void sbus_hme_write32(void __iomem
*reg
, u32 val
)
152 sbus_writel(val
, reg
);
155 static u32
sbus_hme_read32(void __iomem
*reg
)
157 return sbus_readl(reg
);
160 static void sbus_hme_write_rxd(struct happy_meal_rxd
*rxd
, u32 flags
, u32 addr
)
162 rxd
->rx_addr
= (__force hme32
)addr
;
164 rxd
->rx_flags
= (__force hme32
)flags
;
167 static void sbus_hme_write_txd(struct happy_meal_txd
*txd
, u32 flags
, u32 addr
)
169 txd
->tx_addr
= (__force hme32
)addr
;
171 txd
->tx_flags
= (__force hme32
)flags
;
174 static u32
sbus_hme_read_desc32(hme32
*p
)
176 return (__force u32
)*p
;
179 static void pci_hme_write32(void __iomem
*reg
, u32 val
)
184 static u32
pci_hme_read32(void __iomem
*reg
)
189 static void pci_hme_write_rxd(struct happy_meal_rxd
*rxd
, u32 flags
, u32 addr
)
191 rxd
->rx_addr
= (__force hme32
)cpu_to_le32(addr
);
193 rxd
->rx_flags
= (__force hme32
)cpu_to_le32(flags
);
196 static void pci_hme_write_txd(struct happy_meal_txd
*txd
, u32 flags
, u32 addr
)
198 txd
->tx_addr
= (__force hme32
)cpu_to_le32(addr
);
200 txd
->tx_flags
= (__force hme32
)cpu_to_le32(flags
);
203 static u32
pci_hme_read_desc32(hme32
*p
)
205 return le32_to_cpup((__le32
*)p
);
208 #define hme_write32(__hp, __reg, __val) \
209 ((__hp)->write32((__reg), (__val)))
210 #define hme_read32(__hp, __reg) \
211 ((__hp)->read32(__reg))
212 #define hme_write_rxd(__hp, __rxd, __flags, __addr) \
213 ((__hp)->write_rxd((__rxd), (__flags), (__addr)))
214 #define hme_write_txd(__hp, __txd, __flags, __addr) \
215 ((__hp)->write_txd((__txd), (__flags), (__addr)))
216 #define hme_read_desc32(__hp, __p) \
217 ((__hp)->read_desc32(__p))
220 /* SBUS only compilation */
221 #define hme_write32(__hp, __reg, __val) \
222 sbus_writel((__val), (__reg))
223 #define hme_read32(__hp, __reg) \
225 #define hme_write_rxd(__hp, __rxd, __flags, __addr) \
226 do { (__rxd)->rx_addr = (__force hme32)(u32)(__addr); \
228 (__rxd)->rx_flags = (__force hme32)(u32)(__flags); \
230 #define hme_write_txd(__hp, __txd, __flags, __addr) \
231 do { (__txd)->tx_addr = (__force hme32)(u32)(__addr); \
233 (__txd)->tx_flags = (__force hme32)(u32)(__flags); \
235 #define hme_read_desc32(__hp, __p) ((__force u32)(hme32)*(__p))
237 /* PCI only compilation */
238 #define hme_write32(__hp, __reg, __val) \
239 writel((__val), (__reg))
240 #define hme_read32(__hp, __reg) \
242 #define hme_write_rxd(__hp, __rxd, __flags, __addr) \
243 do { (__rxd)->rx_addr = (__force hme32)cpu_to_le32(__addr); \
245 (__rxd)->rx_flags = (__force hme32)cpu_to_le32(__flags); \
247 #define hme_write_txd(__hp, __txd, __flags, __addr) \
248 do { (__txd)->tx_addr = (__force hme32)cpu_to_le32(__addr); \
250 (__txd)->tx_flags = (__force hme32)cpu_to_le32(__flags); \
252 static inline u32
hme_read_desc32(struct happy_meal
*hp
, hme32
*p
)
254 return le32_to_cpup((__le32
*)p
);
260 /* Oh yes, the MIF BitBang is mighty fun to program. BitBucket is more like it. */
261 static void BB_PUT_BIT(struct happy_meal
*hp
, void __iomem
*tregs
, int bit
)
263 hme_write32(hp
, tregs
+ TCVR_BBDATA
, bit
);
264 hme_write32(hp
, tregs
+ TCVR_BBCLOCK
, 0);
265 hme_write32(hp
, tregs
+ TCVR_BBCLOCK
, 1);
269 static u32
BB_GET_BIT(struct happy_meal
*hp
, void __iomem
*tregs
, int internal
)
273 hme_write32(hp
, tregs
+ TCVR_BBCLOCK
, 0);
274 hme_write32(hp
, tregs
+ TCVR_BBCLOCK
, 1);
275 ret
= hme_read32(hp
, tregs
+ TCVR_CFG
);
277 ret
&= TCV_CFG_MDIO0
;
279 ret
&= TCV_CFG_MDIO1
;
285 static u32
BB_GET_BIT2(struct happy_meal
*hp
, void __iomem
*tregs
, int internal
)
289 hme_write32(hp
, tregs
+ TCVR_BBCLOCK
, 0);
291 retval
= hme_read32(hp
, tregs
+ TCVR_CFG
);
293 retval
&= TCV_CFG_MDIO0
;
295 retval
&= TCV_CFG_MDIO1
;
296 hme_write32(hp
, tregs
+ TCVR_BBCLOCK
, 1);
301 #define TCVR_FAILURE 0x80000000 /* Impossible MIF read value */
303 static int happy_meal_bb_read(struct happy_meal
*hp
,
304 void __iomem
*tregs
, int reg
)
310 /* Enable the MIF BitBang outputs. */
311 hme_write32(hp
, tregs
+ TCVR_BBOENAB
, 1);
313 /* Force BitBang into the idle state. */
314 for (i
= 0; i
< 32; i
++)
315 BB_PUT_BIT(hp
, tregs
, 1);
317 /* Give it the read sequence. */
318 BB_PUT_BIT(hp
, tregs
, 0);
319 BB_PUT_BIT(hp
, tregs
, 1);
320 BB_PUT_BIT(hp
, tregs
, 1);
321 BB_PUT_BIT(hp
, tregs
, 0);
323 /* Give it the PHY address. */
324 tmp
= hp
->paddr
& 0xff;
325 for (i
= 4; i
>= 0; i
--)
326 BB_PUT_BIT(hp
, tregs
, ((tmp
>> i
) & 1));
328 /* Tell it what register we want to read. */
330 for (i
= 4; i
>= 0; i
--)
331 BB_PUT_BIT(hp
, tregs
, ((tmp
>> i
) & 1));
333 /* Close down the MIF BitBang outputs. */
334 hme_write32(hp
, tregs
+ TCVR_BBOENAB
, 0);
336 /* Now read in the value. */
337 (void) BB_GET_BIT2(hp
, tregs
, (hp
->tcvr_type
== internal
));
338 for (i
= 15; i
>= 0; i
--)
339 retval
|= BB_GET_BIT2(hp
, tregs
, (hp
->tcvr_type
== internal
));
340 (void) BB_GET_BIT2(hp
, tregs
, (hp
->tcvr_type
== internal
));
341 (void) BB_GET_BIT2(hp
, tregs
, (hp
->tcvr_type
== internal
));
342 (void) BB_GET_BIT2(hp
, tregs
, (hp
->tcvr_type
== internal
));
343 ASD("reg=%d value=%x\n", reg
, retval
);
347 static void happy_meal_bb_write(struct happy_meal
*hp
,
348 void __iomem
*tregs
, int reg
,
349 unsigned short value
)
354 ASD("reg=%d value=%x\n", reg
, value
);
356 /* Enable the MIF BitBang outputs. */
357 hme_write32(hp
, tregs
+ TCVR_BBOENAB
, 1);
359 /* Force BitBang into the idle state. */
360 for (i
= 0; i
< 32; i
++)
361 BB_PUT_BIT(hp
, tregs
, 1);
363 /* Give it write sequence. */
364 BB_PUT_BIT(hp
, tregs
, 0);
365 BB_PUT_BIT(hp
, tregs
, 1);
366 BB_PUT_BIT(hp
, tregs
, 0);
367 BB_PUT_BIT(hp
, tregs
, 1);
369 /* Give it the PHY address. */
370 tmp
= (hp
->paddr
& 0xff);
371 for (i
= 4; i
>= 0; i
--)
372 BB_PUT_BIT(hp
, tregs
, ((tmp
>> i
) & 1));
374 /* Tell it what register we will be writing. */
376 for (i
= 4; i
>= 0; i
--)
377 BB_PUT_BIT(hp
, tregs
, ((tmp
>> i
) & 1));
379 /* Tell it to become ready for the bits. */
380 BB_PUT_BIT(hp
, tregs
, 1);
381 BB_PUT_BIT(hp
, tregs
, 0);
383 for (i
= 15; i
>= 0; i
--)
384 BB_PUT_BIT(hp
, tregs
, ((value
>> i
) & 1));
386 /* Close down the MIF BitBang outputs. */
387 hme_write32(hp
, tregs
+ TCVR_BBOENAB
, 0);
390 #define TCVR_READ_TRIES 16
392 static int happy_meal_tcvr_read(struct happy_meal
*hp
,
393 void __iomem
*tregs
, int reg
)
395 int tries
= TCVR_READ_TRIES
;
398 if (hp
->tcvr_type
== none
) {
399 ASD("no transceiver, value=TCVR_FAILURE\n");
403 if (!(hp
->happy_flags
& HFLAG_FENABLE
)) {
404 ASD("doing bit bang\n");
405 return happy_meal_bb_read(hp
, tregs
, reg
);
408 hme_write32(hp
, tregs
+ TCVR_FRAME
,
409 (FRAME_READ
| (hp
->paddr
<< 23) | ((reg
& 0xff) << 18)));
410 while (!(hme_read32(hp
, tregs
+ TCVR_FRAME
) & 0x10000) && --tries
)
413 netdev_err(hp
->dev
, "Aieee, transceiver MIF read bolixed\n");
416 retval
= hme_read32(hp
, tregs
+ TCVR_FRAME
) & 0xffff;
417 ASD("reg=0x%02x value=%04x\n", reg
, retval
);
421 #define TCVR_WRITE_TRIES 16
423 static void happy_meal_tcvr_write(struct happy_meal
*hp
,
424 void __iomem
*tregs
, int reg
,
425 unsigned short value
)
427 int tries
= TCVR_WRITE_TRIES
;
429 ASD("reg=0x%02x value=%04x\n", reg
, value
);
431 /* Welcome to Sun Microsystems, can I take your order please? */
432 if (!(hp
->happy_flags
& HFLAG_FENABLE
)) {
433 happy_meal_bb_write(hp
, tregs
, reg
, value
);
437 /* Would you like fries with that? */
438 hme_write32(hp
, tregs
+ TCVR_FRAME
,
439 (FRAME_WRITE
| (hp
->paddr
<< 23) |
440 ((reg
& 0xff) << 18) | (value
& 0xffff)));
441 while (!(hme_read32(hp
, tregs
+ TCVR_FRAME
) & 0x10000) && --tries
)
446 netdev_err(hp
->dev
, "Aieee, transceiver MIF write bolixed\n");
448 /* Fifty-two cents is your change, have a nice day. */
451 /* Auto negotiation. The scheme is very simple. We have a timer routine
452 * that keeps watching the auto negotiation process as it progresses.
453 * The DP83840 is first told to start doing it's thing, we set up the time
454 * and place the timer state machine in it's initial state.
456 * Here the timer peeks at the DP83840 status registers at each click to see
457 * if the auto negotiation has completed, we assume here that the DP83840 PHY
458 * will time out at some point and just tell us what (didn't) happen. For
459 * complete coverage we only allow so many of the ticks at this level to run,
460 * when this has expired we print a warning message and try another strategy.
461 * This "other" strategy is to force the interface into various speed/duplex
462 * configurations and we stop when we see a link-up condition before the
463 * maximum number of "peek" ticks have occurred.
465 * Once a valid link status has been detected we configure the BigMAC and
466 * the rest of the Happy Meal to speak the most efficient protocol we could
467 * get a clean link for. The priority for link configurations, highest first
469 * 100 Base-T Full Duplex
470 * 100 Base-T Half Duplex
471 * 10 Base-T Full Duplex
472 * 10 Base-T Half Duplex
474 * We start a new timer now, after a successful auto negotiation status has
475 * been detected. This timer just waits for the link-up bit to get set in
476 * the BMCR of the DP83840. When this occurs we print a kernel log message
477 * describing the link type in use and the fact that it is up.
479 * If a fatal error of some sort is signalled and detected in the interrupt
480 * service routine, and the chip is reset, or the link is ifconfig'd down
481 * and then back up, this entire process repeats itself all over again.
483 static int try_next_permutation(struct happy_meal
*hp
, void __iomem
*tregs
)
485 hp
->sw_bmcr
= happy_meal_tcvr_read(hp
, tregs
, MII_BMCR
);
487 /* Downgrade from full to half duplex. Only possible
490 if (hp
->sw_bmcr
& BMCR_FULLDPLX
) {
491 hp
->sw_bmcr
&= ~(BMCR_FULLDPLX
);
492 happy_meal_tcvr_write(hp
, tregs
, MII_BMCR
, hp
->sw_bmcr
);
496 /* Downgrade from 100 to 10. */
497 if (hp
->sw_bmcr
& BMCR_SPEED100
) {
498 hp
->sw_bmcr
&= ~(BMCR_SPEED100
);
499 happy_meal_tcvr_write(hp
, tregs
, MII_BMCR
, hp
->sw_bmcr
);
503 /* We've tried everything. */
507 static void display_link_mode(struct happy_meal
*hp
, void __iomem
*tregs
)
509 hp
->sw_lpa
= happy_meal_tcvr_read(hp
, tregs
, MII_LPA
);
512 "Link is up using %s transceiver at %dMb/s, %s Duplex.\n",
513 hp
->tcvr_type
== external
? "external" : "internal",
514 hp
->sw_lpa
& (LPA_100HALF
| LPA_100FULL
) ? 100 : 10,
515 hp
->sw_lpa
& (LPA_100FULL
| LPA_10FULL
) ? "Full" : "Half");
518 static void display_forced_link_mode(struct happy_meal
*hp
, void __iomem
*tregs
)
520 hp
->sw_bmcr
= happy_meal_tcvr_read(hp
, tregs
, MII_BMCR
);
523 "Link has been forced up using %s transceiver at %dMb/s, %s Duplex.\n",
524 hp
->tcvr_type
== external
? "external" : "internal",
525 hp
->sw_bmcr
& BMCR_SPEED100
? 100 : 10,
526 hp
->sw_bmcr
& BMCR_FULLDPLX
? "Full" : "Half");
529 static int set_happy_link_modes(struct happy_meal
*hp
, void __iomem
*tregs
)
533 /* All we care about is making sure the bigmac tx_cfg has a
534 * proper duplex setting.
536 if (hp
->timer_state
== arbwait
) {
537 hp
->sw_lpa
= happy_meal_tcvr_read(hp
, tregs
, MII_LPA
);
538 if (!(hp
->sw_lpa
& (LPA_10HALF
| LPA_10FULL
| LPA_100HALF
| LPA_100FULL
)))
540 if (hp
->sw_lpa
& LPA_100FULL
)
542 else if (hp
->sw_lpa
& LPA_100HALF
)
544 else if (hp
->sw_lpa
& LPA_10FULL
)
549 /* Forcing a link mode. */
550 hp
->sw_bmcr
= happy_meal_tcvr_read(hp
, tregs
, MII_BMCR
);
551 if (hp
->sw_bmcr
& BMCR_FULLDPLX
)
557 /* Before changing other bits in the tx_cfg register, and in
558 * general any of other the TX config registers too, you
561 * 2) Poll with reads until that bit reads back as zero
562 * 3) Make TX configuration changes
563 * 4) Set Enable once more
565 hme_write32(hp
, hp
->bigmacregs
+ BMAC_TXCFG
,
566 hme_read32(hp
, hp
->bigmacregs
+ BMAC_TXCFG
) &
567 ~(BIGMAC_TXCFG_ENABLE
));
568 while (hme_read32(hp
, hp
->bigmacregs
+ BMAC_TXCFG
) & BIGMAC_TXCFG_ENABLE
)
571 hp
->happy_flags
|= HFLAG_FULL
;
572 hme_write32(hp
, hp
->bigmacregs
+ BMAC_TXCFG
,
573 hme_read32(hp
, hp
->bigmacregs
+ BMAC_TXCFG
) |
574 BIGMAC_TXCFG_FULLDPLX
);
576 hp
->happy_flags
&= ~(HFLAG_FULL
);
577 hme_write32(hp
, hp
->bigmacregs
+ BMAC_TXCFG
,
578 hme_read32(hp
, hp
->bigmacregs
+ BMAC_TXCFG
) &
579 ~(BIGMAC_TXCFG_FULLDPLX
));
581 hme_write32(hp
, hp
->bigmacregs
+ BMAC_TXCFG
,
582 hme_read32(hp
, hp
->bigmacregs
+ BMAC_TXCFG
) |
583 BIGMAC_TXCFG_ENABLE
);
589 static int is_lucent_phy(struct happy_meal
*hp
)
591 void __iomem
*tregs
= hp
->tcvregs
;
592 unsigned short mr2
, mr3
;
595 mr2
= happy_meal_tcvr_read(hp
, tregs
, 2);
596 mr3
= happy_meal_tcvr_read(hp
, tregs
, 3);
597 if ((mr2
& 0xffff) == 0x0180 &&
598 ((mr3
& 0xffff) >> 10) == 0x1d)
604 /* hp->happy_lock must be held */
606 happy_meal_begin_auto_negotiation(struct happy_meal
*hp
,
608 const struct ethtool_link_ksettings
*ep
)
612 /* Read all of the registers we are interested in now. */
613 hp
->sw_bmsr
= happy_meal_tcvr_read(hp
, tregs
, MII_BMSR
);
614 hp
->sw_bmcr
= happy_meal_tcvr_read(hp
, tregs
, MII_BMCR
);
615 hp
->sw_physid1
= happy_meal_tcvr_read(hp
, tregs
, MII_PHYSID1
);
616 hp
->sw_physid2
= happy_meal_tcvr_read(hp
, tregs
, MII_PHYSID2
);
618 /* XXX Check BMSR_ANEGCAPABLE, should not be necessary though. */
620 hp
->sw_advertise
= happy_meal_tcvr_read(hp
, tregs
, MII_ADVERTISE
);
621 if (!ep
|| ep
->base
.autoneg
== AUTONEG_ENABLE
) {
622 /* Advertise everything we can support. */
623 if (hp
->sw_bmsr
& BMSR_10HALF
)
624 hp
->sw_advertise
|= (ADVERTISE_10HALF
);
626 hp
->sw_advertise
&= ~(ADVERTISE_10HALF
);
628 if (hp
->sw_bmsr
& BMSR_10FULL
)
629 hp
->sw_advertise
|= (ADVERTISE_10FULL
);
631 hp
->sw_advertise
&= ~(ADVERTISE_10FULL
);
632 if (hp
->sw_bmsr
& BMSR_100HALF
)
633 hp
->sw_advertise
|= (ADVERTISE_100HALF
);
635 hp
->sw_advertise
&= ~(ADVERTISE_100HALF
);
636 if (hp
->sw_bmsr
& BMSR_100FULL
)
637 hp
->sw_advertise
|= (ADVERTISE_100FULL
);
639 hp
->sw_advertise
&= ~(ADVERTISE_100FULL
);
640 happy_meal_tcvr_write(hp
, tregs
, MII_ADVERTISE
, hp
->sw_advertise
);
642 /* XXX Currently no Happy Meal cards I know off support 100BaseT4,
643 * XXX and this is because the DP83840 does not support it, changes
644 * XXX would need to be made to the tx/rx logic in the driver as well
645 * XXX so I completely skip checking for it in the BMSR for now.
648 ASD("Advertising [ %s%s%s%s]\n",
649 hp
->sw_advertise
& ADVERTISE_10HALF
? "10H " : "",
650 hp
->sw_advertise
& ADVERTISE_10FULL
? "10F " : "",
651 hp
->sw_advertise
& ADVERTISE_100HALF
? "100H " : "",
652 hp
->sw_advertise
& ADVERTISE_100FULL
? "100F " : "");
654 /* Enable Auto-Negotiation, this is usually on already... */
655 hp
->sw_bmcr
|= BMCR_ANENABLE
;
656 happy_meal_tcvr_write(hp
, tregs
, MII_BMCR
, hp
->sw_bmcr
);
658 /* Restart it to make sure it is going. */
659 hp
->sw_bmcr
|= BMCR_ANRESTART
;
660 happy_meal_tcvr_write(hp
, tregs
, MII_BMCR
, hp
->sw_bmcr
);
662 /* BMCR_ANRESTART self clears when the process has begun. */
664 timeout
= 64; /* More than enough. */
666 hp
->sw_bmcr
= happy_meal_tcvr_read(hp
, tregs
, MII_BMCR
);
667 if (!(hp
->sw_bmcr
& BMCR_ANRESTART
))
673 "Happy Meal would not start auto negotiation BMCR=0x%04x\n",
675 netdev_notice(hp
->dev
,
676 "Performing force link detection.\n");
679 hp
->timer_state
= arbwait
;
683 /* Force the link up, trying first a particular mode.
684 * Either we are here at the request of ethtool or
685 * because the Happy Meal would not start to autoneg.
688 /* Disable auto-negotiation in BMCR, enable the duplex and
689 * speed setting, init the timer state machine, and fire it off.
691 if (!ep
|| ep
->base
.autoneg
== AUTONEG_ENABLE
) {
692 hp
->sw_bmcr
= BMCR_SPEED100
;
694 if (ep
->base
.speed
== SPEED_100
)
695 hp
->sw_bmcr
= BMCR_SPEED100
;
698 if (ep
->base
.duplex
== DUPLEX_FULL
)
699 hp
->sw_bmcr
|= BMCR_FULLDPLX
;
701 happy_meal_tcvr_write(hp
, tregs
, MII_BMCR
, hp
->sw_bmcr
);
703 if (!is_lucent_phy(hp
)) {
704 /* OK, seems we need do disable the transceiver for the first
705 * tick to make sure we get an accurate link state at the
708 hp
->sw_csconfig
= happy_meal_tcvr_read(hp
, tregs
,
710 hp
->sw_csconfig
&= ~(CSCONFIG_TCVDISAB
);
711 happy_meal_tcvr_write(hp
, tregs
, DP83840_CSCONFIG
,
714 hp
->timer_state
= ltrywait
;
718 hp
->happy_timer
.expires
= jiffies
+ (12 * HZ
)/10; /* 1.2 sec. */
719 add_timer(&hp
->happy_timer
);
722 static void happy_meal_timer(struct timer_list
*t
)
724 struct happy_meal
*hp
= from_timer(hp
, t
, happy_timer
);
725 void __iomem
*tregs
= hp
->tcvregs
;
726 int restart_timer
= 0;
728 spin_lock_irq(&hp
->happy_lock
);
731 switch(hp
->timer_state
) {
733 /* Only allow for 5 ticks, thats 10 seconds and much too
734 * long to wait for arbitration to complete.
736 if (hp
->timer_ticks
>= 10) {
737 /* Enter force mode. */
739 hp
->sw_bmcr
= happy_meal_tcvr_read(hp
, tregs
, MII_BMCR
);
740 netdev_notice(hp
->dev
,
741 "Auto-Negotiation unsuccessful, trying force link mode\n");
742 hp
->sw_bmcr
= BMCR_SPEED100
;
743 happy_meal_tcvr_write(hp
, tregs
, MII_BMCR
, hp
->sw_bmcr
);
745 if (!is_lucent_phy(hp
)) {
746 /* OK, seems we need do disable the transceiver for the first
747 * tick to make sure we get an accurate link state at the
750 hp
->sw_csconfig
= happy_meal_tcvr_read(hp
, tregs
, DP83840_CSCONFIG
);
751 hp
->sw_csconfig
&= ~(CSCONFIG_TCVDISAB
);
752 happy_meal_tcvr_write(hp
, tregs
, DP83840_CSCONFIG
, hp
->sw_csconfig
);
754 hp
->timer_state
= ltrywait
;
758 /* Anything interesting happen? */
759 hp
->sw_bmsr
= happy_meal_tcvr_read(hp
, tregs
, MII_BMSR
);
760 if (hp
->sw_bmsr
& BMSR_ANEGCOMPLETE
) {
763 /* Just what we've been waiting for... */
764 ret
= set_happy_link_modes(hp
, tregs
);
766 /* Ooops, something bad happened, go to force
769 * XXX Broken hubs which don't support 802.3u
770 * XXX auto-negotiation make this happen as well.
775 /* Success, at least so far, advance our state engine. */
776 hp
->timer_state
= lupwait
;
785 /* Auto negotiation was successful and we are awaiting a
786 * link up status. I have decided to let this timer run
787 * forever until some sort of error is signalled, reporting
788 * a message to the user at 10 second intervals.
790 hp
->sw_bmsr
= happy_meal_tcvr_read(hp
, tregs
, MII_BMSR
);
791 if (hp
->sw_bmsr
& BMSR_LSTATUS
) {
792 /* Wheee, it's up, display the link mode in use and put
793 * the timer to sleep.
795 display_link_mode(hp
, tregs
);
796 hp
->timer_state
= asleep
;
799 if (hp
->timer_ticks
>= 10) {
800 netdev_notice(hp
->dev
,
801 "Auto negotiation successful, link still not completely up.\n");
811 /* Making the timeout here too long can make it take
812 * annoyingly long to attempt all of the link mode
813 * permutations, but then again this is essentially
814 * error recovery code for the most part.
816 hp
->sw_bmsr
= happy_meal_tcvr_read(hp
, tregs
, MII_BMSR
);
817 hp
->sw_csconfig
= happy_meal_tcvr_read(hp
, tregs
, DP83840_CSCONFIG
);
818 if (hp
->timer_ticks
== 1) {
819 if (!is_lucent_phy(hp
)) {
820 /* Re-enable transceiver, we'll re-enable the transceiver next
821 * tick, then check link state on the following tick.
823 hp
->sw_csconfig
|= CSCONFIG_TCVDISAB
;
824 happy_meal_tcvr_write(hp
, tregs
,
825 DP83840_CSCONFIG
, hp
->sw_csconfig
);
830 if (hp
->timer_ticks
== 2) {
831 if (!is_lucent_phy(hp
)) {
832 hp
->sw_csconfig
&= ~(CSCONFIG_TCVDISAB
);
833 happy_meal_tcvr_write(hp
, tregs
,
834 DP83840_CSCONFIG
, hp
->sw_csconfig
);
839 if (hp
->sw_bmsr
& BMSR_LSTATUS
) {
840 /* Force mode selection success. */
841 display_forced_link_mode(hp
, tregs
);
842 set_happy_link_modes(hp
, tregs
); /* XXX error? then what? */
843 hp
->timer_state
= asleep
;
846 if (hp
->timer_ticks
>= 4) { /* 6 seconds or so... */
849 ret
= try_next_permutation(hp
, tregs
);
851 /* Aieee, tried them all, reset the
852 * chip and try all over again.
855 /* Let the user know... */
856 netdev_notice(hp
->dev
,
857 "Link down, cable problem?\n");
859 happy_meal_begin_auto_negotiation(hp
, tregs
, NULL
);
862 if (!is_lucent_phy(hp
)) {
863 hp
->sw_csconfig
= happy_meal_tcvr_read(hp
, tregs
,
865 hp
->sw_csconfig
|= CSCONFIG_TCVDISAB
;
866 happy_meal_tcvr_write(hp
, tregs
,
867 DP83840_CSCONFIG
, hp
->sw_csconfig
);
879 /* Can't happens.... */
881 "Aieee, link timer is asleep but we got one anyways!\n");
884 hp
->timer_state
= asleep
; /* foo on you */
889 hp
->happy_timer
.expires
= jiffies
+ ((12 * HZ
)/10); /* 1.2 sec. */
890 add_timer(&hp
->happy_timer
);
894 spin_unlock_irq(&hp
->happy_lock
);
897 #define TX_RESET_TRIES 32
898 #define RX_RESET_TRIES 32
900 /* hp->happy_lock must be held */
901 static void happy_meal_tx_reset(struct happy_meal
*hp
, void __iomem
*bregs
)
903 int tries
= TX_RESET_TRIES
;
907 /* Would you like to try our SMCC Delux? */
908 hme_write32(hp
, bregs
+ BMAC_TXSWRESET
, 0);
909 while ((hme_read32(hp
, bregs
+ BMAC_TXSWRESET
) & 1) && --tries
)
912 /* Lettuce, tomato, buggy hardware (no extra charge)? */
914 netdev_err(hp
->dev
, "Transceiver BigMac ATTACK!");
920 /* hp->happy_lock must be held */
921 static void happy_meal_rx_reset(struct happy_meal
*hp
, void __iomem
*bregs
)
923 int tries
= RX_RESET_TRIES
;
927 /* We have a special on GNU/Viking hardware bugs today. */
928 hme_write32(hp
, bregs
+ BMAC_RXSWRESET
, 0);
929 while ((hme_read32(hp
, bregs
+ BMAC_RXSWRESET
) & 1) && --tries
)
932 /* Will that be all? */
934 netdev_err(hp
->dev
, "Receiver BigMac ATTACK!\n");
936 /* Don't forget your vik_1137125_wa. Have a nice day. */
940 #define STOP_TRIES 16
942 /* hp->happy_lock must be held */
943 static void happy_meal_stop(struct happy_meal
*hp
, void __iomem
*gregs
)
945 int tries
= STOP_TRIES
;
949 /* We're consolidating our STB products, it's your lucky day. */
950 hme_write32(hp
, gregs
+ GREG_SWRESET
, GREG_RESET_ALL
);
951 while (hme_read32(hp
, gregs
+ GREG_SWRESET
) && --tries
)
954 /* Come back next week when we are "Sun Microelectronics". */
956 netdev_err(hp
->dev
, "Fry guys.\n");
958 /* Remember: "Different name, same old buggy as shit hardware." */
962 /* hp->happy_lock must be held */
963 static void happy_meal_get_counters(struct happy_meal
*hp
, void __iomem
*bregs
)
965 struct net_device_stats
*stats
= &hp
->dev
->stats
;
967 stats
->rx_crc_errors
+= hme_read32(hp
, bregs
+ BMAC_RCRCECTR
);
968 hme_write32(hp
, bregs
+ BMAC_RCRCECTR
, 0);
970 stats
->rx_frame_errors
+= hme_read32(hp
, bregs
+ BMAC_UNALECTR
);
971 hme_write32(hp
, bregs
+ BMAC_UNALECTR
, 0);
973 stats
->rx_length_errors
+= hme_read32(hp
, bregs
+ BMAC_GLECTR
);
974 hme_write32(hp
, bregs
+ BMAC_GLECTR
, 0);
976 stats
->tx_aborted_errors
+= hme_read32(hp
, bregs
+ BMAC_EXCTR
);
979 (hme_read32(hp
, bregs
+ BMAC_EXCTR
) +
980 hme_read32(hp
, bregs
+ BMAC_LTCTR
));
981 hme_write32(hp
, bregs
+ BMAC_EXCTR
, 0);
982 hme_write32(hp
, bregs
+ BMAC_LTCTR
, 0);
985 /* Only Sun can take such nice parts and fuck up the programming interface
986 * like this. Good job guys...
988 #define TCVR_RESET_TRIES 16 /* It should reset quickly */
989 #define TCVR_UNISOLATE_TRIES 32 /* Dis-isolation can take longer. */
991 /* hp->happy_lock must be held */
992 static int happy_meal_tcvr_reset(struct happy_meal
*hp
, void __iomem
*tregs
)
995 int result
, tries
= TCVR_RESET_TRIES
;
997 tconfig
= hme_read32(hp
, tregs
+ TCVR_CFG
);
998 ASD("tcfg=%08x\n", tconfig
);
999 if (hp
->tcvr_type
== external
) {
1000 hme_write32(hp
, tregs
+ TCVR_CFG
, tconfig
& ~(TCV_CFG_PSELECT
));
1001 hp
->tcvr_type
= internal
;
1002 hp
->paddr
= TCV_PADDR_ITX
;
1003 happy_meal_tcvr_write(hp
, tregs
, MII_BMCR
,
1004 (BMCR_LOOPBACK
|BMCR_PDOWN
|BMCR_ISOLATE
));
1005 result
= happy_meal_tcvr_read(hp
, tregs
, MII_BMCR
);
1006 if (result
== TCVR_FAILURE
) {
1007 ASD("phyread_fail\n");
1010 ASD("external: ISOLATE, phyread_ok, PSELECT\n");
1011 hme_write32(hp
, tregs
+ TCVR_CFG
, tconfig
| TCV_CFG_PSELECT
);
1012 hp
->tcvr_type
= external
;
1013 hp
->paddr
= TCV_PADDR_ETX
;
1015 if (tconfig
& TCV_CFG_MDIO1
) {
1016 hme_write32(hp
, tregs
+ TCVR_CFG
, (tconfig
| TCV_CFG_PSELECT
));
1017 happy_meal_tcvr_write(hp
, tregs
, MII_BMCR
,
1018 (BMCR_LOOPBACK
|BMCR_PDOWN
|BMCR_ISOLATE
));
1019 result
= happy_meal_tcvr_read(hp
, tregs
, MII_BMCR
);
1020 if (result
== TCVR_FAILURE
) {
1021 ASD("phyread_fail>\n");
1024 ASD("internal: PSELECT, ISOLATE, phyread_ok, ~PSELECT\n");
1025 hme_write32(hp
, tregs
+ TCVR_CFG
, (tconfig
& ~(TCV_CFG_PSELECT
)));
1026 hp
->tcvr_type
= internal
;
1027 hp
->paddr
= TCV_PADDR_ITX
;
1031 ASD("BMCR_RESET...\n");
1032 happy_meal_tcvr_write(hp
, tregs
, MII_BMCR
, BMCR_RESET
);
1035 result
= happy_meal_tcvr_read(hp
, tregs
, MII_BMCR
);
1036 if (result
== TCVR_FAILURE
)
1038 hp
->sw_bmcr
= result
;
1039 if (!(result
& BMCR_RESET
))
1044 ASD("BMCR RESET FAILED!\n");
1049 /* Get fresh copies of the PHY registers. */
1050 hp
->sw_bmsr
= happy_meal_tcvr_read(hp
, tregs
, MII_BMSR
);
1051 hp
->sw_physid1
= happy_meal_tcvr_read(hp
, tregs
, MII_PHYSID1
);
1052 hp
->sw_physid2
= happy_meal_tcvr_read(hp
, tregs
, MII_PHYSID2
);
1053 hp
->sw_advertise
= happy_meal_tcvr_read(hp
, tregs
, MII_ADVERTISE
);
1055 ASD("UNISOLATE...\n");
1056 hp
->sw_bmcr
&= ~(BMCR_ISOLATE
);
1057 happy_meal_tcvr_write(hp
, tregs
, MII_BMCR
, hp
->sw_bmcr
);
1059 tries
= TCVR_UNISOLATE_TRIES
;
1061 result
= happy_meal_tcvr_read(hp
, tregs
, MII_BMCR
);
1062 if (result
== TCVR_FAILURE
)
1064 if (!(result
& BMCR_ISOLATE
))
1069 ASD("UNISOLATE FAILED!\n");
1072 ASD("SUCCESS and CSCONFIG_DFBYPASS\n");
1073 if (!is_lucent_phy(hp
)) {
1074 result
= happy_meal_tcvr_read(hp
, tregs
,
1076 happy_meal_tcvr_write(hp
, tregs
,
1077 DP83840_CSCONFIG
, (result
| CSCONFIG_DFBYPASS
));
1082 /* Figure out whether we have an internal or external transceiver.
1084 * hp->happy_lock must be held
1086 static void happy_meal_transceiver_check(struct happy_meal
*hp
, void __iomem
*tregs
)
1088 unsigned long tconfig
= hme_read32(hp
, tregs
+ TCVR_CFG
);
1089 u32 reread
= hme_read32(hp
, tregs
+ TCVR_CFG
);
1091 ASD("tcfg=%08lx\n", tconfig
);
1092 if (reread
& TCV_CFG_MDIO1
) {
1093 hme_write32(hp
, tregs
+ TCVR_CFG
, tconfig
| TCV_CFG_PSELECT
);
1094 hp
->paddr
= TCV_PADDR_ETX
;
1095 hp
->tcvr_type
= external
;
1096 ASD("not polling, external\n");
1098 if (reread
& TCV_CFG_MDIO0
) {
1099 hme_write32(hp
, tregs
+ TCVR_CFG
,
1100 tconfig
& ~(TCV_CFG_PSELECT
));
1101 hp
->paddr
= TCV_PADDR_ITX
;
1102 hp
->tcvr_type
= internal
;
1103 ASD("not polling, internal\n");
1106 "Transceiver and a coke please.");
1107 hp
->tcvr_type
= none
; /* Grrr... */
1108 ASD("not polling, none\n");
1113 /* The receive ring buffers are a bit tricky to get right. Here goes...
1115 * The buffers we dma into must be 64 byte aligned. So we use a special
1116 * alloc_skb() routine for the happy meal to allocate 64 bytes more than
1119 * We use skb_reserve() to align the data block we get in the skb. We
1120 * also program the etxregs->cfg register to use an offset of 2. This
1121 * imperical constant plus the ethernet header size will always leave
1122 * us with a nicely aligned ip header once we pass things up to the
1125 * The numbers work out to:
1127 * Max ethernet frame size 1518
1128 * Ethernet header size 14
1129 * Happy Meal base offset 2
1131 * Say a skb data area is at 0xf001b010, and its size alloced is
1132 * (ETH_FRAME_LEN + 64 + 2) = (1514 + 64 + 2) = 1580 bytes.
1134 * First our alloc_skb() routine aligns the data base to a 64 byte
1135 * boundary. We now have 0xf001b040 as our skb data address. We
1136 * plug this into the receive descriptor address.
1138 * Next, we skb_reserve() 2 bytes to account for the Happy Meal offset.
1139 * So now the data we will end up looking at starts at 0xf001b042. When
1140 * the packet arrives, we will check out the size received and subtract
1141 * this from the skb->length. Then we just pass the packet up to the
1142 * protocols as is, and allocate a new skb to replace this slot we have
1143 * just received from.
1145 * The ethernet layer will strip the ether header from the front of the
1146 * skb we just sent to it, this leaves us with the ip header sitting
1147 * nicely aligned at 0xf001b050. Also, for tcp and udp packets the
1148 * Happy Meal has even checksummed the tcp/udp data for us. The 16
1149 * bit checksum is obtained from the low bits of the receive descriptor
1152 * skb->csum = rxd->rx_flags & 0xffff;
1153 * skb->ip_summed = CHECKSUM_COMPLETE;
1155 * before sending off the skb to the protocols, and we are good as gold.
1157 static void happy_meal_clean_rings(struct happy_meal
*hp
)
1161 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
1162 if (hp
->rx_skbs
[i
] != NULL
) {
1163 struct sk_buff
*skb
= hp
->rx_skbs
[i
];
1164 struct happy_meal_rxd
*rxd
;
1167 rxd
= &hp
->happy_block
->happy_meal_rxd
[i
];
1168 dma_addr
= hme_read_desc32(hp
, &rxd
->rx_addr
);
1169 dma_unmap_single(hp
->dma_dev
, dma_addr
,
1170 RX_BUF_ALLOC_SIZE
, DMA_FROM_DEVICE
);
1171 dev_kfree_skb_any(skb
);
1172 hp
->rx_skbs
[i
] = NULL
;
1176 for (i
= 0; i
< TX_RING_SIZE
; i
++) {
1177 if (hp
->tx_skbs
[i
] != NULL
) {
1178 struct sk_buff
*skb
= hp
->tx_skbs
[i
];
1179 struct happy_meal_txd
*txd
;
1183 hp
->tx_skbs
[i
] = NULL
;
1185 for (frag
= 0; frag
<= skb_shinfo(skb
)->nr_frags
; frag
++) {
1186 txd
= &hp
->happy_block
->happy_meal_txd
[i
];
1187 dma_addr
= hme_read_desc32(hp
, &txd
->tx_addr
);
1189 dma_unmap_single(hp
->dma_dev
, dma_addr
,
1190 (hme_read_desc32(hp
, &txd
->tx_flags
)
1194 dma_unmap_page(hp
->dma_dev
, dma_addr
,
1195 (hme_read_desc32(hp
, &txd
->tx_flags
)
1199 if (frag
!= skb_shinfo(skb
)->nr_frags
)
1203 dev_kfree_skb_any(skb
);
1208 /* hp->happy_lock must be held */
1209 static void happy_meal_init_rings(struct happy_meal
*hp
)
1211 struct hmeal_init_block
*hb
= hp
->happy_block
;
1214 HMD("counters to zero\n");
1215 hp
->rx_new
= hp
->rx_old
= hp
->tx_new
= hp
->tx_old
= 0;
1217 /* Free any skippy bufs left around in the rings. */
1218 happy_meal_clean_rings(hp
);
1220 /* Now get new skippy bufs for the receive ring. */
1221 HMD("init rxring\n");
1222 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
1223 struct sk_buff
*skb
;
1226 skb
= happy_meal_alloc_skb(RX_BUF_ALLOC_SIZE
, GFP_ATOMIC
);
1228 hme_write_rxd(hp
, &hb
->happy_meal_rxd
[i
], 0, 0);
1231 hp
->rx_skbs
[i
] = skb
;
1233 /* Because we reserve afterwards. */
1234 skb_put(skb
, (ETH_FRAME_LEN
+ RX_OFFSET
+ 4));
1235 mapping
= dma_map_single(hp
->dma_dev
, skb
->data
, RX_BUF_ALLOC_SIZE
,
1237 if (dma_mapping_error(hp
->dma_dev
, mapping
)) {
1238 dev_kfree_skb_any(skb
);
1239 hme_write_rxd(hp
, &hb
->happy_meal_rxd
[i
], 0, 0);
1242 hme_write_rxd(hp
, &hb
->happy_meal_rxd
[i
],
1243 (RXFLAG_OWN
| ((RX_BUF_ALLOC_SIZE
- RX_OFFSET
) << 16)),
1245 skb_reserve(skb
, RX_OFFSET
);
1248 HMD("init txring\n");
1249 for (i
= 0; i
< TX_RING_SIZE
; i
++)
1250 hme_write_txd(hp
, &hb
->happy_meal_txd
[i
], 0, 0);
1255 /* hp->happy_lock must be held */
1256 static int happy_meal_init(struct happy_meal
*hp
)
1258 const unsigned char *e
= &hp
->dev
->dev_addr
[0];
1259 void __iomem
*gregs
= hp
->gregs
;
1260 void __iomem
*etxregs
= hp
->etxregs
;
1261 void __iomem
*erxregs
= hp
->erxregs
;
1262 void __iomem
*bregs
= hp
->bigmacregs
;
1263 void __iomem
*tregs
= hp
->tcvregs
;
1264 const char *bursts
= "64";
1267 /* If auto-negotiation timer is running, kill it. */
1268 del_timer(&hp
->happy_timer
);
1270 HMD("happy_flags[%08x]\n", hp
->happy_flags
);
1271 if (!(hp
->happy_flags
& HFLAG_INIT
)) {
1272 HMD("set HFLAG_INIT\n");
1273 hp
->happy_flags
|= HFLAG_INIT
;
1274 happy_meal_get_counters(hp
, bregs
);
1277 /* Stop transmitter and receiver. */
1278 HMD("to happy_meal_stop\n");
1279 happy_meal_stop(hp
, gregs
);
1281 /* Alloc and reset the tx/rx descriptor chains. */
1282 HMD("to happy_meal_init_rings\n");
1283 happy_meal_init_rings(hp
);
1285 /* See if we can enable the MIF frame on this card to speak to the DP83840. */
1286 if (hp
->happy_flags
& HFLAG_FENABLE
) {
1287 HMD("use frame old[%08x]\n",
1288 hme_read32(hp
, tregs
+ TCVR_CFG
));
1289 hme_write32(hp
, tregs
+ TCVR_CFG
,
1290 hme_read32(hp
, tregs
+ TCVR_CFG
) & ~(TCV_CFG_BENABLE
));
1292 HMD("use bitbang old[%08x]\n",
1293 hme_read32(hp
, tregs
+ TCVR_CFG
));
1294 hme_write32(hp
, tregs
+ TCVR_CFG
,
1295 hme_read32(hp
, tregs
+ TCVR_CFG
) | TCV_CFG_BENABLE
);
1298 /* Check the state of the transceiver. */
1299 HMD("to happy_meal_transceiver_check\n");
1300 happy_meal_transceiver_check(hp
, tregs
);
1302 /* Put the Big Mac into a sane state. */
1303 switch(hp
->tcvr_type
) {
1305 /* Cannot operate if we don't know the transceiver type! */
1306 HMD("AAIEEE no transceiver type, EAGAIN\n");
1310 /* Using the MII buffers. */
1311 HMD("internal, using MII\n");
1312 hme_write32(hp
, bregs
+ BMAC_XIFCFG
, 0);
1316 /* Not using the MII, disable it. */
1317 HMD("external, disable MII\n");
1318 hme_write32(hp
, bregs
+ BMAC_XIFCFG
, BIGMAC_XCFG_MIIDISAB
);
1322 if (happy_meal_tcvr_reset(hp
, tregs
))
1325 /* Reset the Happy Meal Big Mac transceiver and the receiver. */
1326 HMD("tx/rx reset\n");
1327 happy_meal_tx_reset(hp
, bregs
);
1328 happy_meal_rx_reset(hp
, bregs
);
1330 /* Set jam size and inter-packet gaps to reasonable defaults. */
1331 hme_write32(hp
, bregs
+ BMAC_JSIZE
, DEFAULT_JAMSIZE
);
1332 hme_write32(hp
, bregs
+ BMAC_IGAP1
, DEFAULT_IPG1
);
1333 hme_write32(hp
, bregs
+ BMAC_IGAP2
, DEFAULT_IPG2
);
1335 /* Load up the MAC address and random seed. */
1337 /* The docs recommend to use the 10LSB of our MAC here. */
1338 hme_write32(hp
, bregs
+ BMAC_RSEED
, ((e
[5] | e
[4]<<8)&0x3ff));
1340 hme_write32(hp
, bregs
+ BMAC_MACADDR2
, ((e
[4] << 8) | e
[5]));
1341 hme_write32(hp
, bregs
+ BMAC_MACADDR1
, ((e
[2] << 8) | e
[3]));
1342 hme_write32(hp
, bregs
+ BMAC_MACADDR0
, ((e
[0] << 8) | e
[1]));
1344 if ((hp
->dev
->flags
& IFF_ALLMULTI
) ||
1345 (netdev_mc_count(hp
->dev
) > 64)) {
1346 hme_write32(hp
, bregs
+ BMAC_HTABLE0
, 0xffff);
1347 hme_write32(hp
, bregs
+ BMAC_HTABLE1
, 0xffff);
1348 hme_write32(hp
, bregs
+ BMAC_HTABLE2
, 0xffff);
1349 hme_write32(hp
, bregs
+ BMAC_HTABLE3
, 0xffff);
1350 } else if ((hp
->dev
->flags
& IFF_PROMISC
) == 0) {
1352 struct netdev_hw_addr
*ha
;
1355 memset(hash_table
, 0, sizeof(hash_table
));
1356 netdev_for_each_mc_addr(ha
, hp
->dev
) {
1357 crc
= ether_crc_le(6, ha
->addr
);
1359 hash_table
[crc
>> 4] |= 1 << (crc
& 0xf);
1361 hme_write32(hp
, bregs
+ BMAC_HTABLE0
, hash_table
[0]);
1362 hme_write32(hp
, bregs
+ BMAC_HTABLE1
, hash_table
[1]);
1363 hme_write32(hp
, bregs
+ BMAC_HTABLE2
, hash_table
[2]);
1364 hme_write32(hp
, bregs
+ BMAC_HTABLE3
, hash_table
[3]);
1366 hme_write32(hp
, bregs
+ BMAC_HTABLE3
, 0);
1367 hme_write32(hp
, bregs
+ BMAC_HTABLE2
, 0);
1368 hme_write32(hp
, bregs
+ BMAC_HTABLE1
, 0);
1369 hme_write32(hp
, bregs
+ BMAC_HTABLE0
, 0);
1372 /* Set the RX and TX ring ptrs. */
1373 HMD("ring ptrs rxr[%08x] txr[%08x]\n",
1374 ((__u32
)hp
->hblock_dvma
+ hblock_offset(happy_meal_rxd
, 0)),
1375 ((__u32
)hp
->hblock_dvma
+ hblock_offset(happy_meal_txd
, 0)));
1376 hme_write32(hp
, erxregs
+ ERX_RING
,
1377 ((__u32
)hp
->hblock_dvma
+ hblock_offset(happy_meal_rxd
, 0)));
1378 hme_write32(hp
, etxregs
+ ETX_RING
,
1379 ((__u32
)hp
->hblock_dvma
+ hblock_offset(happy_meal_txd
, 0)));
1381 /* Parity issues in the ERX unit of some HME revisions can cause some
1382 * registers to not be written unless their parity is even. Detect such
1383 * lost writes and simply rewrite with a low bit set (which will be ignored
1384 * since the rxring needs to be 2K aligned).
1386 if (hme_read32(hp
, erxregs
+ ERX_RING
) !=
1387 ((__u32
)hp
->hblock_dvma
+ hblock_offset(happy_meal_rxd
, 0)))
1388 hme_write32(hp
, erxregs
+ ERX_RING
,
1389 ((__u32
)hp
->hblock_dvma
+ hblock_offset(happy_meal_rxd
, 0))
1392 /* Set the supported burst sizes. */
1393 #ifndef CONFIG_SPARC
1394 /* It is always PCI and can handle 64byte bursts. */
1395 hme_write32(hp
, gregs
+ GREG_CFG
, GREG_CFG_BURST64
);
1397 if ((hp
->happy_bursts
& DMA_BURST64
) &&
1398 ((hp
->happy_flags
& HFLAG_PCI
) != 0
1400 || sbus_can_burst64()
1403 u32 gcfg
= GREG_CFG_BURST64
;
1405 /* I have no idea if I should set the extended
1406 * transfer mode bit for Cheerio, so for now I
1410 if ((hp
->happy_flags
& HFLAG_PCI
) == 0) {
1411 struct platform_device
*op
= hp
->happy_dev
;
1412 if (sbus_can_dma_64bit()) {
1413 sbus_set_sbus64(&op
->dev
,
1415 gcfg
|= GREG_CFG_64BIT
;
1421 hme_write32(hp
, gregs
+ GREG_CFG
, gcfg
);
1422 } else if (hp
->happy_bursts
& DMA_BURST32
) {
1424 hme_write32(hp
, gregs
+ GREG_CFG
, GREG_CFG_BURST32
);
1425 } else if (hp
->happy_bursts
& DMA_BURST16
) {
1427 hme_write32(hp
, gregs
+ GREG_CFG
, GREG_CFG_BURST16
);
1430 hme_write32(hp
, gregs
+ GREG_CFG
, 0);
1432 #endif /* CONFIG_SPARC */
1434 HMD("old[%08x] bursts<%s>\n",
1435 hme_read32(hp
, gregs
+ GREG_CFG
), bursts
);
1437 /* Turn off interrupts we do not want to hear. */
1438 hme_write32(hp
, gregs
+ GREG_IMASK
,
1439 (GREG_IMASK_GOTFRAME
| GREG_IMASK_RCNTEXP
|
1440 GREG_IMASK_SENTFRAME
| GREG_IMASK_TXPERR
));
1442 /* Set the transmit ring buffer size. */
1443 HMD("tx rsize=%d oreg[%08x]\n", (int)TX_RING_SIZE
,
1444 hme_read32(hp
, etxregs
+ ETX_RSIZE
));
1445 hme_write32(hp
, etxregs
+ ETX_RSIZE
, (TX_RING_SIZE
>> ETX_RSIZE_SHIFT
) - 1);
1447 /* Enable transmitter DVMA. */
1448 HMD("tx dma enable old[%08x]\n", hme_read32(hp
, etxregs
+ ETX_CFG
));
1449 hme_write32(hp
, etxregs
+ ETX_CFG
,
1450 hme_read32(hp
, etxregs
+ ETX_CFG
) | ETX_CFG_DMAENABLE
);
1452 /* This chip really rots, for the receiver sometimes when you
1453 * write to its control registers not all the bits get there
1454 * properly. I cannot think of a sane way to provide complete
1455 * coverage for this hardware bug yet.
1457 HMD("erx regs bug old[%08x]\n",
1458 hme_read32(hp
, erxregs
+ ERX_CFG
));
1459 hme_write32(hp
, erxregs
+ ERX_CFG
, ERX_CFG_DEFAULT(RX_OFFSET
));
1460 regtmp
= hme_read32(hp
, erxregs
+ ERX_CFG
);
1461 hme_write32(hp
, erxregs
+ ERX_CFG
, ERX_CFG_DEFAULT(RX_OFFSET
));
1462 if (hme_read32(hp
, erxregs
+ ERX_CFG
) != ERX_CFG_DEFAULT(RX_OFFSET
)) {
1464 "Eieee, rx config register gets greasy fries.\n");
1466 "Trying to set %08x, reread gives %08x\n",
1467 ERX_CFG_DEFAULT(RX_OFFSET
), regtmp
);
1468 /* XXX Should return failure here... */
1471 /* Enable Big Mac hash table filter. */
1472 HMD("enable hash rx_cfg_old[%08x]\n",
1473 hme_read32(hp
, bregs
+ BMAC_RXCFG
));
1474 rxcfg
= BIGMAC_RXCFG_HENABLE
| BIGMAC_RXCFG_REJME
;
1475 if (hp
->dev
->flags
& IFF_PROMISC
)
1476 rxcfg
|= BIGMAC_RXCFG_PMISC
;
1477 hme_write32(hp
, bregs
+ BMAC_RXCFG
, rxcfg
);
1479 /* Let the bits settle in the chip. */
1482 /* Ok, configure the Big Mac transmitter. */
1483 HMD("BIGMAC init\n");
1485 if (hp
->happy_flags
& HFLAG_FULL
)
1486 regtmp
|= BIGMAC_TXCFG_FULLDPLX
;
1488 /* Don't turn on the "don't give up" bit for now. It could cause hme
1489 * to deadlock with the PHY if a Jabber occurs.
1491 hme_write32(hp
, bregs
+ BMAC_TXCFG
, regtmp
/*| BIGMAC_TXCFG_DGIVEUP*/);
1493 /* Give up after 16 TX attempts. */
1494 hme_write32(hp
, bregs
+ BMAC_ALIMIT
, 16);
1496 /* Enable the output drivers no matter what. */
1497 regtmp
= BIGMAC_XCFG_ODENABLE
;
1499 /* If card can do lance mode, enable it. */
1500 if (hp
->happy_flags
& HFLAG_LANCE
)
1501 regtmp
|= (DEFAULT_IPG0
<< 5) | BIGMAC_XCFG_LANCE
;
1503 /* Disable the MII buffers if using external transceiver. */
1504 if (hp
->tcvr_type
== external
)
1505 regtmp
|= BIGMAC_XCFG_MIIDISAB
;
1507 HMD("XIF config old[%08x]\n", hme_read32(hp
, bregs
+ BMAC_XIFCFG
));
1508 hme_write32(hp
, bregs
+ BMAC_XIFCFG
, regtmp
);
1510 /* Start things up. */
1511 HMD("tx old[%08x] and rx [%08x] ON!\n",
1512 hme_read32(hp
, bregs
+ BMAC_TXCFG
),
1513 hme_read32(hp
, bregs
+ BMAC_RXCFG
));
1515 /* Set larger TX/RX size to allow for 802.1q */
1516 hme_write32(hp
, bregs
+ BMAC_TXMAX
, ETH_FRAME_LEN
+ 8);
1517 hme_write32(hp
, bregs
+ BMAC_RXMAX
, ETH_FRAME_LEN
+ 8);
1519 hme_write32(hp
, bregs
+ BMAC_TXCFG
,
1520 hme_read32(hp
, bregs
+ BMAC_TXCFG
) | BIGMAC_TXCFG_ENABLE
);
1521 hme_write32(hp
, bregs
+ BMAC_RXCFG
,
1522 hme_read32(hp
, bregs
+ BMAC_RXCFG
) | BIGMAC_RXCFG_ENABLE
);
1524 /* Get the autonegotiation started, and the watch timer ticking. */
1525 happy_meal_begin_auto_negotiation(hp
, tregs
, NULL
);
1531 /* hp->happy_lock must be held */
1532 static void happy_meal_set_initial_advertisement(struct happy_meal
*hp
)
1534 void __iomem
*tregs
= hp
->tcvregs
;
1535 void __iomem
*bregs
= hp
->bigmacregs
;
1536 void __iomem
*gregs
= hp
->gregs
;
1538 happy_meal_stop(hp
, gregs
);
1539 if (hp
->happy_flags
& HFLAG_FENABLE
)
1540 hme_write32(hp
, tregs
+ TCVR_CFG
,
1541 hme_read32(hp
, tregs
+ TCVR_CFG
) & ~(TCV_CFG_BENABLE
));
1543 hme_write32(hp
, tregs
+ TCVR_CFG
,
1544 hme_read32(hp
, tregs
+ TCVR_CFG
) | TCV_CFG_BENABLE
);
1545 happy_meal_transceiver_check(hp
, tregs
);
1546 switch(hp
->tcvr_type
) {
1550 hme_write32(hp
, bregs
+ BMAC_XIFCFG
, 0);
1553 hme_write32(hp
, bregs
+ BMAC_XIFCFG
, BIGMAC_XCFG_MIIDISAB
);
1556 if (happy_meal_tcvr_reset(hp
, tregs
))
1559 /* Latch PHY registers as of now. */
1560 hp
->sw_bmsr
= happy_meal_tcvr_read(hp
, tregs
, MII_BMSR
);
1561 hp
->sw_advertise
= happy_meal_tcvr_read(hp
, tregs
, MII_ADVERTISE
);
1563 /* Advertise everything we can support. */
1564 if (hp
->sw_bmsr
& BMSR_10HALF
)
1565 hp
->sw_advertise
|= (ADVERTISE_10HALF
);
1567 hp
->sw_advertise
&= ~(ADVERTISE_10HALF
);
1569 if (hp
->sw_bmsr
& BMSR_10FULL
)
1570 hp
->sw_advertise
|= (ADVERTISE_10FULL
);
1572 hp
->sw_advertise
&= ~(ADVERTISE_10FULL
);
1573 if (hp
->sw_bmsr
& BMSR_100HALF
)
1574 hp
->sw_advertise
|= (ADVERTISE_100HALF
);
1576 hp
->sw_advertise
&= ~(ADVERTISE_100HALF
);
1577 if (hp
->sw_bmsr
& BMSR_100FULL
)
1578 hp
->sw_advertise
|= (ADVERTISE_100FULL
);
1580 hp
->sw_advertise
&= ~(ADVERTISE_100FULL
);
1582 /* Update the PHY advertisement register. */
1583 happy_meal_tcvr_write(hp
, tregs
, MII_ADVERTISE
, hp
->sw_advertise
);
1586 /* Once status is latched (by happy_meal_interrupt) it is cleared by
1587 * the hardware, so we cannot re-read it and get a correct value.
1589 * hp->happy_lock must be held
1591 static int happy_meal_is_not_so_happy(struct happy_meal
*hp
, u32 status
)
1595 /* Only print messages for non-counter related interrupts. */
1596 if (status
& (GREG_STAT_STSTERR
| GREG_STAT_TFIFO_UND
|
1597 GREG_STAT_MAXPKTERR
| GREG_STAT_RXERR
|
1598 GREG_STAT_RXPERR
| GREG_STAT_RXTERR
| GREG_STAT_EOPERR
|
1599 GREG_STAT_MIFIRQ
| GREG_STAT_TXEACK
| GREG_STAT_TXLERR
|
1600 GREG_STAT_TXPERR
| GREG_STAT_TXTERR
| GREG_STAT_SLVERR
|
1603 "Error interrupt for happy meal, status = %08x\n",
1606 if (status
& GREG_STAT_RFIFOVF
) {
1607 /* Receive FIFO overflow is harmless and the hardware will take
1608 care of it, just some packets are lost. Who cares. */
1609 netdev_dbg(hp
->dev
, "Happy Meal receive FIFO overflow.\n");
1612 if (status
& GREG_STAT_STSTERR
) {
1613 /* BigMAC SQE link test failed. */
1614 netdev_err(hp
->dev
, "Happy Meal BigMAC SQE test failed.\n");
1618 if (status
& GREG_STAT_TFIFO_UND
) {
1619 /* Transmit FIFO underrun, again DMA error likely. */
1621 "Happy Meal transmitter FIFO underrun, DMA error.\n");
1625 if (status
& GREG_STAT_MAXPKTERR
) {
1626 /* Driver error, tried to transmit something larger
1627 * than ethernet max mtu.
1629 netdev_err(hp
->dev
, "Happy Meal MAX Packet size error.\n");
1633 if (status
& GREG_STAT_NORXD
) {
1634 /* This is harmless, it just means the system is
1635 * quite loaded and the incoming packet rate was
1636 * faster than the interrupt handler could keep up
1639 netdev_info(hp
->dev
,
1640 "Happy Meal out of receive descriptors, packet dropped.\n");
1643 if (status
& (GREG_STAT_RXERR
|GREG_STAT_RXPERR
|GREG_STAT_RXTERR
)) {
1644 /* All sorts of DMA receive errors. */
1645 netdev_err(hp
->dev
, "Happy Meal rx DMA errors [ %s%s%s]\n",
1646 status
& GREG_STAT_RXERR
? "GenericError " : "",
1647 status
& GREG_STAT_RXPERR
? "ParityError " : "",
1648 status
& GREG_STAT_RXTERR
? "RxTagBotch " : "");
1652 if (status
& GREG_STAT_EOPERR
) {
1653 /* Driver bug, didn't set EOP bit in tx descriptor given
1654 * to the happy meal.
1657 "EOP not set in happy meal transmit descriptor!\n");
1661 if (status
& GREG_STAT_MIFIRQ
) {
1662 /* MIF signalled an interrupt, were we polling it? */
1663 netdev_err(hp
->dev
, "Happy Meal MIF interrupt.\n");
1667 (GREG_STAT_TXEACK
|GREG_STAT_TXLERR
|GREG_STAT_TXPERR
|GREG_STAT_TXTERR
)) {
1668 /* All sorts of transmit DMA errors. */
1669 netdev_err(hp
->dev
, "Happy Meal tx DMA errors [ %s%s%s%s]\n",
1670 status
& GREG_STAT_TXEACK
? "GenericError " : "",
1671 status
& GREG_STAT_TXLERR
? "LateError " : "",
1672 status
& GREG_STAT_TXPERR
? "ParityError " : "",
1673 status
& GREG_STAT_TXTERR
? "TagBotch " : "");
1677 if (status
& (GREG_STAT_SLVERR
|GREG_STAT_SLVPERR
)) {
1678 /* Bus or parity error when cpu accessed happy meal registers
1679 * or it's internal FIFO's. Should never see this.
1682 "Happy Meal register access SBUS slave (%s) error.\n",
1683 (status
& GREG_STAT_SLVPERR
) ? "parity" : "generic");
1688 netdev_notice(hp
->dev
, "Resetting...\n");
1689 happy_meal_init(hp
);
1695 /* hp->happy_lock must be held */
1696 static void happy_meal_tx(struct happy_meal
*hp
)
1698 struct happy_meal_txd
*txbase
= &hp
->happy_block
->happy_meal_txd
[0];
1699 struct happy_meal_txd
*this;
1700 struct net_device
*dev
= hp
->dev
;
1704 while (elem
!= hp
->tx_new
) {
1705 struct sk_buff
*skb
;
1706 u32 flags
, dma_addr
, dma_len
;
1709 netdev_vdbg(hp
->dev
, "TX[%d]\n", elem
);
1710 this = &txbase
[elem
];
1711 flags
= hme_read_desc32(hp
, &this->tx_flags
);
1712 if (flags
& TXFLAG_OWN
)
1714 skb
= hp
->tx_skbs
[elem
];
1715 if (skb_shinfo(skb
)->nr_frags
) {
1718 last
= elem
+ skb_shinfo(skb
)->nr_frags
;
1719 last
&= (TX_RING_SIZE
- 1);
1720 flags
= hme_read_desc32(hp
, &txbase
[last
].tx_flags
);
1721 if (flags
& TXFLAG_OWN
)
1724 hp
->tx_skbs
[elem
] = NULL
;
1725 dev
->stats
.tx_bytes
+= skb
->len
;
1727 for (frag
= 0; frag
<= skb_shinfo(skb
)->nr_frags
; frag
++) {
1728 dma_addr
= hme_read_desc32(hp
, &this->tx_addr
);
1729 dma_len
= hme_read_desc32(hp
, &this->tx_flags
);
1731 dma_len
&= TXFLAG_SIZE
;
1733 dma_unmap_single(hp
->dma_dev
, dma_addr
, dma_len
, DMA_TO_DEVICE
);
1735 dma_unmap_page(hp
->dma_dev
, dma_addr
, dma_len
, DMA_TO_DEVICE
);
1737 elem
= NEXT_TX(elem
);
1738 this = &txbase
[elem
];
1741 dev_consume_skb_irq(skb
);
1742 dev
->stats
.tx_packets
++;
1746 if (netif_queue_stopped(dev
) &&
1747 TX_BUFFS_AVAIL(hp
) > (MAX_SKB_FRAGS
+ 1))
1748 netif_wake_queue(dev
);
1751 /* Originally I used to handle the allocation failure by just giving back just
1752 * that one ring buffer to the happy meal. Problem is that usually when that
1753 * condition is triggered, the happy meal expects you to do something reasonable
1754 * with all of the packets it has DMA'd in. So now I just drop the entire
1755 * ring when we cannot get a new skb and give them all back to the happy meal,
1756 * maybe things will be "happier" now.
1758 * hp->happy_lock must be held
1760 static void happy_meal_rx(struct happy_meal
*hp
, struct net_device
*dev
)
1762 struct happy_meal_rxd
*rxbase
= &hp
->happy_block
->happy_meal_rxd
[0];
1763 struct happy_meal_rxd
*this;
1764 int elem
= hp
->rx_new
, drops
= 0;
1767 this = &rxbase
[elem
];
1768 while (!((flags
= hme_read_desc32(hp
, &this->rx_flags
)) & RXFLAG_OWN
)) {
1769 struct sk_buff
*skb
;
1770 int len
= flags
>> 16;
1771 u16 csum
= flags
& RXFLAG_CSUM
;
1772 u32 dma_addr
= hme_read_desc32(hp
, &this->rx_addr
);
1774 /* Check for errors. */
1775 if ((len
< ETH_ZLEN
) || (flags
& RXFLAG_OVERFLOW
)) {
1776 netdev_vdbg(dev
, "RX[%d ERR(%08x)]", elem
, flags
);
1777 dev
->stats
.rx_errors
++;
1779 dev
->stats
.rx_length_errors
++;
1780 if (len
& (RXFLAG_OVERFLOW
>> 16)) {
1781 dev
->stats
.rx_over_errors
++;
1782 dev
->stats
.rx_fifo_errors
++;
1785 /* Return it to the Happy meal. */
1787 dev
->stats
.rx_dropped
++;
1788 hme_write_rxd(hp
, this,
1789 (RXFLAG_OWN
|((RX_BUF_ALLOC_SIZE
-RX_OFFSET
)<<16)),
1793 skb
= hp
->rx_skbs
[elem
];
1794 if (len
> RX_COPY_THRESHOLD
) {
1795 struct sk_buff
*new_skb
;
1798 /* Now refill the entry, if we can. */
1799 new_skb
= happy_meal_alloc_skb(RX_BUF_ALLOC_SIZE
, GFP_ATOMIC
);
1800 if (new_skb
== NULL
) {
1804 skb_put(new_skb
, (ETH_FRAME_LEN
+ RX_OFFSET
+ 4));
1805 mapping
= dma_map_single(hp
->dma_dev
, new_skb
->data
,
1808 if (unlikely(dma_mapping_error(hp
->dma_dev
, mapping
))) {
1809 dev_kfree_skb_any(new_skb
);
1814 dma_unmap_single(hp
->dma_dev
, dma_addr
, RX_BUF_ALLOC_SIZE
, DMA_FROM_DEVICE
);
1815 hp
->rx_skbs
[elem
] = new_skb
;
1816 hme_write_rxd(hp
, this,
1817 (RXFLAG_OWN
|((RX_BUF_ALLOC_SIZE
-RX_OFFSET
)<<16)),
1819 skb_reserve(new_skb
, RX_OFFSET
);
1821 /* Trim the original skb for the netif. */
1824 struct sk_buff
*copy_skb
= netdev_alloc_skb(dev
, len
+ 2);
1826 if (copy_skb
== NULL
) {
1831 skb_reserve(copy_skb
, 2);
1832 skb_put(copy_skb
, len
);
1833 dma_sync_single_for_cpu(hp
->dma_dev
, dma_addr
, len
+ 2, DMA_FROM_DEVICE
);
1834 skb_copy_from_linear_data(skb
, copy_skb
->data
, len
);
1835 dma_sync_single_for_device(hp
->dma_dev
, dma_addr
, len
+ 2, DMA_FROM_DEVICE
);
1836 /* Reuse original ring buffer. */
1837 hme_write_rxd(hp
, this,
1838 (RXFLAG_OWN
|((RX_BUF_ALLOC_SIZE
-RX_OFFSET
)<<16)),
1844 /* This card is _fucking_ hot... */
1845 skb
->csum
= csum_unfold(~(__force __sum16
)htons(csum
));
1846 skb
->ip_summed
= CHECKSUM_COMPLETE
;
1848 netdev_vdbg(dev
, "RX[%d len=%d csum=%4x]", elem
, len
, csum
);
1849 skb
->protocol
= eth_type_trans(skb
, dev
);
1852 dev
->stats
.rx_packets
++;
1853 dev
->stats
.rx_bytes
+= len
;
1855 elem
= NEXT_RX(elem
);
1856 this = &rxbase
[elem
];
1860 netdev_info(hp
->dev
, "Memory squeeze, deferring packet.\n");
1863 static irqreturn_t
happy_meal_interrupt(int irq
, void *dev_id
)
1865 struct net_device
*dev
= dev_id
;
1866 struct happy_meal
*hp
= netdev_priv(dev
);
1867 u32 happy_status
= hme_read32(hp
, hp
->gregs
+ GREG_STAT
);
1869 HMD("status=%08x\n", happy_status
);
1873 spin_lock(&hp
->happy_lock
);
1875 if (happy_status
& GREG_STAT_ERRORS
) {
1876 if (happy_meal_is_not_so_happy(hp
, /* un- */ happy_status
))
1880 if (happy_status
& GREG_STAT_TXALL
)
1883 if (happy_status
& GREG_STAT_RXTOHOST
)
1884 happy_meal_rx(hp
, dev
);
1888 spin_unlock(&hp
->happy_lock
);
1893 static int happy_meal_open(struct net_device
*dev
)
1895 struct happy_meal
*hp
= netdev_priv(dev
);
1898 res
= request_irq(hp
->irq
, happy_meal_interrupt
, IRQF_SHARED
,
1901 netdev_err(dev
, "Can't order irq %d to go.\n", hp
->irq
);
1905 HMD("to happy_meal_init\n");
1907 spin_lock_irq(&hp
->happy_lock
);
1908 res
= happy_meal_init(hp
);
1909 spin_unlock_irq(&hp
->happy_lock
);
1912 free_irq(hp
->irq
, dev
);
1916 static int happy_meal_close(struct net_device
*dev
)
1918 struct happy_meal
*hp
= netdev_priv(dev
);
1920 spin_lock_irq(&hp
->happy_lock
);
1921 happy_meal_stop(hp
, hp
->gregs
);
1922 happy_meal_clean_rings(hp
);
1924 /* If auto-negotiation timer is running, kill it. */
1925 del_timer(&hp
->happy_timer
);
1927 spin_unlock_irq(&hp
->happy_lock
);
1929 free_irq(hp
->irq
, dev
);
1934 static void happy_meal_tx_timeout(struct net_device
*dev
, unsigned int txqueue
)
1936 struct happy_meal
*hp
= netdev_priv(dev
);
1938 netdev_err(dev
, "transmit timed out, resetting\n");
1940 netdev_err(dev
, "Happy Status %08x TX[%08x:%08x]\n",
1941 hme_read32(hp
, hp
->gregs
+ GREG_STAT
),
1942 hme_read32(hp
, hp
->etxregs
+ ETX_CFG
),
1943 hme_read32(hp
, hp
->bigmacregs
+ BMAC_TXCFG
));
1945 spin_lock_irq(&hp
->happy_lock
);
1946 happy_meal_init(hp
);
1947 spin_unlock_irq(&hp
->happy_lock
);
1949 netif_wake_queue(dev
);
1952 static void unmap_partial_tx_skb(struct happy_meal
*hp
, u32 first_mapping
,
1953 u32 first_len
, u32 first_entry
, u32 entry
)
1955 struct happy_meal_txd
*txbase
= &hp
->happy_block
->happy_meal_txd
[0];
1957 dma_unmap_single(hp
->dma_dev
, first_mapping
, first_len
, DMA_TO_DEVICE
);
1959 first_entry
= NEXT_TX(first_entry
);
1960 while (first_entry
!= entry
) {
1961 struct happy_meal_txd
*this = &txbase
[first_entry
];
1964 addr
= hme_read_desc32(hp
, &this->tx_addr
);
1965 len
= hme_read_desc32(hp
, &this->tx_flags
);
1967 dma_unmap_page(hp
->dma_dev
, addr
, len
, DMA_TO_DEVICE
);
1971 static netdev_tx_t
happy_meal_start_xmit(struct sk_buff
*skb
,
1972 struct net_device
*dev
)
1974 struct happy_meal
*hp
= netdev_priv(dev
);
1978 tx_flags
= TXFLAG_OWN
;
1979 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1980 const u32 csum_start_off
= skb_checksum_start_offset(skb
);
1981 const u32 csum_stuff_off
= csum_start_off
+ skb
->csum_offset
;
1983 tx_flags
= (TXFLAG_OWN
| TXFLAG_CSENABLE
|
1984 ((csum_start_off
<< 14) & TXFLAG_CSBUFBEGIN
) |
1985 ((csum_stuff_off
<< 20) & TXFLAG_CSLOCATION
));
1988 spin_lock_irq(&hp
->happy_lock
);
1990 if (TX_BUFFS_AVAIL(hp
) <= (skb_shinfo(skb
)->nr_frags
+ 1)) {
1991 netif_stop_queue(dev
);
1992 spin_unlock_irq(&hp
->happy_lock
);
1993 netdev_err(dev
, "BUG! Tx Ring full when queue awake!\n");
1994 return NETDEV_TX_BUSY
;
1998 netdev_vdbg(dev
, "SX<l[%d]e[%d]>\n", skb
->len
, entry
);
1999 hp
->tx_skbs
[entry
] = skb
;
2001 if (skb_shinfo(skb
)->nr_frags
== 0) {
2005 mapping
= dma_map_single(hp
->dma_dev
, skb
->data
, len
, DMA_TO_DEVICE
);
2006 if (unlikely(dma_mapping_error(hp
->dma_dev
, mapping
)))
2008 tx_flags
|= (TXFLAG_SOP
| TXFLAG_EOP
);
2009 hme_write_txd(hp
, &hp
->happy_block
->happy_meal_txd
[entry
],
2010 (tx_flags
| (len
& TXFLAG_SIZE
)),
2012 entry
= NEXT_TX(entry
);
2014 u32 first_len
, first_mapping
;
2015 int frag
, first_entry
= entry
;
2017 /* We must give this initial chunk to the device last.
2018 * Otherwise we could race with the device.
2020 first_len
= skb_headlen(skb
);
2021 first_mapping
= dma_map_single(hp
->dma_dev
, skb
->data
, first_len
,
2023 if (unlikely(dma_mapping_error(hp
->dma_dev
, first_mapping
)))
2025 entry
= NEXT_TX(entry
);
2027 for (frag
= 0; frag
< skb_shinfo(skb
)->nr_frags
; frag
++) {
2028 const skb_frag_t
*this_frag
= &skb_shinfo(skb
)->frags
[frag
];
2029 u32 len
, mapping
, this_txflags
;
2031 len
= skb_frag_size(this_frag
);
2032 mapping
= skb_frag_dma_map(hp
->dma_dev
, this_frag
,
2033 0, len
, DMA_TO_DEVICE
);
2034 if (unlikely(dma_mapping_error(hp
->dma_dev
, mapping
))) {
2035 unmap_partial_tx_skb(hp
, first_mapping
, first_len
,
2036 first_entry
, entry
);
2039 this_txflags
= tx_flags
;
2040 if (frag
== skb_shinfo(skb
)->nr_frags
- 1)
2041 this_txflags
|= TXFLAG_EOP
;
2042 hme_write_txd(hp
, &hp
->happy_block
->happy_meal_txd
[entry
],
2043 (this_txflags
| (len
& TXFLAG_SIZE
)),
2045 entry
= NEXT_TX(entry
);
2047 hme_write_txd(hp
, &hp
->happy_block
->happy_meal_txd
[first_entry
],
2048 (tx_flags
| TXFLAG_SOP
| (first_len
& TXFLAG_SIZE
)),
2054 if (TX_BUFFS_AVAIL(hp
) <= (MAX_SKB_FRAGS
+ 1))
2055 netif_stop_queue(dev
);
2058 hme_write32(hp
, hp
->etxregs
+ ETX_PENDING
, ETX_TP_DMAWAKEUP
);
2060 spin_unlock_irq(&hp
->happy_lock
);
2062 tx_add_log(hp
, TXLOG_ACTION_TXMIT
, 0);
2063 return NETDEV_TX_OK
;
2066 hp
->tx_skbs
[hp
->tx_new
] = NULL
;
2067 spin_unlock_irq(&hp
->happy_lock
);
2069 dev_kfree_skb_any(skb
);
2070 dev
->stats
.tx_dropped
++;
2071 return NETDEV_TX_OK
;
2074 static struct net_device_stats
*happy_meal_get_stats(struct net_device
*dev
)
2076 struct happy_meal
*hp
= netdev_priv(dev
);
2078 spin_lock_irq(&hp
->happy_lock
);
2079 happy_meal_get_counters(hp
, hp
->bigmacregs
);
2080 spin_unlock_irq(&hp
->happy_lock
);
2085 static void happy_meal_set_multicast(struct net_device
*dev
)
2087 struct happy_meal
*hp
= netdev_priv(dev
);
2088 void __iomem
*bregs
= hp
->bigmacregs
;
2089 struct netdev_hw_addr
*ha
;
2092 spin_lock_irq(&hp
->happy_lock
);
2094 if ((dev
->flags
& IFF_ALLMULTI
) || (netdev_mc_count(dev
) > 64)) {
2095 hme_write32(hp
, bregs
+ BMAC_HTABLE0
, 0xffff);
2096 hme_write32(hp
, bregs
+ BMAC_HTABLE1
, 0xffff);
2097 hme_write32(hp
, bregs
+ BMAC_HTABLE2
, 0xffff);
2098 hme_write32(hp
, bregs
+ BMAC_HTABLE3
, 0xffff);
2099 } else if (dev
->flags
& IFF_PROMISC
) {
2100 hme_write32(hp
, bregs
+ BMAC_RXCFG
,
2101 hme_read32(hp
, bregs
+ BMAC_RXCFG
) | BIGMAC_RXCFG_PMISC
);
2105 memset(hash_table
, 0, sizeof(hash_table
));
2106 netdev_for_each_mc_addr(ha
, dev
) {
2107 crc
= ether_crc_le(6, ha
->addr
);
2109 hash_table
[crc
>> 4] |= 1 << (crc
& 0xf);
2111 hme_write32(hp
, bregs
+ BMAC_HTABLE0
, hash_table
[0]);
2112 hme_write32(hp
, bregs
+ BMAC_HTABLE1
, hash_table
[1]);
2113 hme_write32(hp
, bregs
+ BMAC_HTABLE2
, hash_table
[2]);
2114 hme_write32(hp
, bregs
+ BMAC_HTABLE3
, hash_table
[3]);
2117 spin_unlock_irq(&hp
->happy_lock
);
2120 /* Ethtool support... */
2121 static int hme_get_link_ksettings(struct net_device
*dev
,
2122 struct ethtool_link_ksettings
*cmd
)
2124 struct happy_meal
*hp
= netdev_priv(dev
);
2129 (SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
|
2130 SUPPORTED_100baseT_Half
| SUPPORTED_100baseT_Full
|
2131 SUPPORTED_Autoneg
| SUPPORTED_TP
| SUPPORTED_MII
);
2133 /* XXX hardcoded stuff for now */
2134 cmd
->base
.port
= PORT_TP
; /* XXX no MII support */
2135 cmd
->base
.phy_address
= 0; /* XXX fixed PHYAD */
2137 /* Record PHY settings. */
2138 spin_lock_irq(&hp
->happy_lock
);
2139 hp
->sw_bmcr
= happy_meal_tcvr_read(hp
, hp
->tcvregs
, MII_BMCR
);
2140 hp
->sw_lpa
= happy_meal_tcvr_read(hp
, hp
->tcvregs
, MII_LPA
);
2141 spin_unlock_irq(&hp
->happy_lock
);
2143 if (hp
->sw_bmcr
& BMCR_ANENABLE
) {
2144 cmd
->base
.autoneg
= AUTONEG_ENABLE
;
2145 speed
= ((hp
->sw_lpa
& (LPA_100HALF
| LPA_100FULL
)) ?
2146 SPEED_100
: SPEED_10
);
2147 if (speed
== SPEED_100
)
2149 (hp
->sw_lpa
& (LPA_100FULL
)) ?
2150 DUPLEX_FULL
: DUPLEX_HALF
;
2153 (hp
->sw_lpa
& (LPA_10FULL
)) ?
2154 DUPLEX_FULL
: DUPLEX_HALF
;
2156 cmd
->base
.autoneg
= AUTONEG_DISABLE
;
2157 speed
= (hp
->sw_bmcr
& BMCR_SPEED100
) ? SPEED_100
: SPEED_10
;
2159 (hp
->sw_bmcr
& BMCR_FULLDPLX
) ?
2160 DUPLEX_FULL
: DUPLEX_HALF
;
2162 cmd
->base
.speed
= speed
;
2163 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
2169 static int hme_set_link_ksettings(struct net_device
*dev
,
2170 const struct ethtool_link_ksettings
*cmd
)
2172 struct happy_meal
*hp
= netdev_priv(dev
);
2174 /* Verify the settings we care about. */
2175 if (cmd
->base
.autoneg
!= AUTONEG_ENABLE
&&
2176 cmd
->base
.autoneg
!= AUTONEG_DISABLE
)
2178 if (cmd
->base
.autoneg
== AUTONEG_DISABLE
&&
2179 ((cmd
->base
.speed
!= SPEED_100
&&
2180 cmd
->base
.speed
!= SPEED_10
) ||
2181 (cmd
->base
.duplex
!= DUPLEX_HALF
&&
2182 cmd
->base
.duplex
!= DUPLEX_FULL
)))
2185 /* Ok, do it to it. */
2186 spin_lock_irq(&hp
->happy_lock
);
2187 del_timer(&hp
->happy_timer
);
2188 happy_meal_begin_auto_negotiation(hp
, hp
->tcvregs
, cmd
);
2189 spin_unlock_irq(&hp
->happy_lock
);
2194 static void hme_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*info
)
2196 struct happy_meal
*hp
= netdev_priv(dev
);
2198 strscpy(info
->driver
, DRV_NAME
, sizeof(info
->driver
));
2199 if (hp
->happy_flags
& HFLAG_PCI
) {
2200 struct pci_dev
*pdev
= hp
->happy_dev
;
2201 strscpy(info
->bus_info
, pci_name(pdev
), sizeof(info
->bus_info
));
2205 const struct linux_prom_registers
*regs
;
2206 struct platform_device
*op
= hp
->happy_dev
;
2207 regs
= of_get_property(op
->dev
.of_node
, "regs", NULL
);
2209 snprintf(info
->bus_info
, sizeof(info
->bus_info
),
2216 static u32
hme_get_link(struct net_device
*dev
)
2218 struct happy_meal
*hp
= netdev_priv(dev
);
2220 spin_lock_irq(&hp
->happy_lock
);
2221 hp
->sw_bmcr
= happy_meal_tcvr_read(hp
, hp
->tcvregs
, MII_BMCR
);
2222 spin_unlock_irq(&hp
->happy_lock
);
2224 return hp
->sw_bmsr
& BMSR_LSTATUS
;
2227 static const struct ethtool_ops hme_ethtool_ops
= {
2228 .get_drvinfo
= hme_get_drvinfo
,
2229 .get_link
= hme_get_link
,
2230 .get_link_ksettings
= hme_get_link_ksettings
,
2231 .set_link_ksettings
= hme_set_link_ksettings
,
2235 /* Given a happy meal sbus device, find it's quattro parent.
2236 * If none exist, allocate and return a new one.
2238 * Return NULL on failure.
2240 static struct quattro
*quattro_sbus_find(struct platform_device
*child
)
2242 struct device
*parent
= child
->dev
.parent
;
2243 struct platform_device
*op
;
2246 op
= to_platform_device(parent
);
2247 qp
= platform_get_drvdata(op
);
2251 qp
= kzalloc(sizeof(*qp
), GFP_KERNEL
);
2255 qp
->quattro_dev
= child
;
2256 qp
->next
= qfe_sbus_list
;
2259 platform_set_drvdata(op
, qp
);
2262 #endif /* CONFIG_SBUS */
2265 static struct quattro
*quattro_pci_find(struct pci_dev
*pdev
)
2268 struct pci_dev
*bdev
= pdev
->bus
->self
;
2272 return ERR_PTR(-ENODEV
);
2274 for (qp
= qfe_pci_list
; qp
!= NULL
; qp
= qp
->next
) {
2275 struct pci_dev
*qpdev
= qp
->quattro_dev
;
2281 qp
= kmalloc(sizeof(struct quattro
), GFP_KERNEL
);
2283 return ERR_PTR(-ENOMEM
);
2285 for (i
= 0; i
< 4; i
++)
2286 qp
->happy_meals
[i
] = NULL
;
2288 qp
->quattro_dev
= bdev
;
2289 qp
->next
= qfe_pci_list
;
2292 /* No range tricks necessary on PCI. */
2296 #endif /* CONFIG_PCI */
2298 static const struct net_device_ops hme_netdev_ops
= {
2299 .ndo_open
= happy_meal_open
,
2300 .ndo_stop
= happy_meal_close
,
2301 .ndo_start_xmit
= happy_meal_start_xmit
,
2302 .ndo_tx_timeout
= happy_meal_tx_timeout
,
2303 .ndo_get_stats
= happy_meal_get_stats
,
2304 .ndo_set_rx_mode
= happy_meal_set_multicast
,
2305 .ndo_set_mac_address
= eth_mac_addr
,
2306 .ndo_validate_addr
= eth_validate_addr
,
2310 static int is_quattro_p(struct pci_dev
*pdev
)
2312 struct pci_dev
*busdev
= pdev
->bus
->self
;
2313 struct pci_dev
*this_pdev
;
2316 if (!busdev
|| busdev
->vendor
!= PCI_VENDOR_ID_DEC
||
2317 busdev
->device
!= PCI_DEVICE_ID_DEC_21153
)
2321 list_for_each_entry(this_pdev
, &pdev
->bus
->devices
, bus_list
) {
2322 if (this_pdev
->vendor
== PCI_VENDOR_ID_SUN
&&
2323 this_pdev
->device
== PCI_DEVICE_ID_SUN_HAPPYMEAL
)
2333 /* Fetch MAC address from vital product data of PCI ROM. */
2334 static int find_eth_addr_in_vpd(void __iomem
*rom_base
, int len
, int index
, unsigned char *dev_addr
)
2338 for (this_offset
= 0x20; this_offset
< len
; this_offset
++) {
2339 void __iomem
*p
= rom_base
+ this_offset
;
2341 if (readb(p
+ 0) != 0x90 ||
2342 readb(p
+ 1) != 0x00 ||
2343 readb(p
+ 2) != 0x09 ||
2344 readb(p
+ 3) != 0x4e ||
2345 readb(p
+ 4) != 0x41 ||
2346 readb(p
+ 5) != 0x06)
2353 for (int i
= 0; i
< 6; i
++)
2354 dev_addr
[i
] = readb(p
+ i
);
2362 static void __maybe_unused
get_hme_mac_nonsparc(struct pci_dev
*pdev
,
2363 unsigned char *dev_addr
)
2368 p
= pci_map_rom(pdev
, &size
);
2373 if (is_quattro_p(pdev
))
2374 index
= PCI_SLOT(pdev
->devfn
);
2376 found
= readb(p
) == 0x55 &&
2377 readb(p
+ 1) == 0xaa &&
2378 find_eth_addr_in_vpd(p
, (64 * 1024), index
, dev_addr
);
2379 pci_unmap_rom(pdev
, p
);
2384 /* Sun MAC prefix then 3 random bytes. */
2388 get_random_bytes(&dev_addr
[3], 3);
2392 static void happy_meal_addr_init(struct happy_meal
*hp
,
2393 struct device_node
*dp
, int qfe_slot
)
2397 for (i
= 0; i
< 6; i
++) {
2398 if (macaddr
[i
] != 0)
2402 if (i
< 6) { /* a mac address was given */
2405 for (i
= 0; i
< 6; i
++)
2406 addr
[i
] = macaddr
[i
];
2407 eth_hw_addr_set(hp
->dev
, addr
);
2411 const unsigned char *addr
;
2414 /* If user did not specify a MAC address specifically, use
2415 * the Quattro local-mac-address property...
2417 if (qfe_slot
!= -1) {
2418 addr
= of_get_property(dp
, "local-mac-address", &len
);
2419 if (addr
&& len
== 6) {
2420 eth_hw_addr_set(hp
->dev
, addr
);
2425 eth_hw_addr_set(hp
->dev
, idprom
->id_ethaddr
);
2429 get_hme_mac_nonsparc(hp
->happy_dev
, addr
);
2430 eth_hw_addr_set(hp
->dev
, addr
);
2435 static int happy_meal_common_probe(struct happy_meal
*hp
,
2436 struct device_node
*dp
)
2438 struct net_device
*dev
= hp
->dev
;
2442 hp
->hm_revision
= of_getintprop_default(dp
, "hm-rev", hp
->hm_revision
);
2445 /* Now enable the feature flags we can. */
2446 if (hp
->hm_revision
== 0x20 || hp
->hm_revision
== 0x21)
2447 hp
->happy_flags
|= HFLAG_20_21
;
2448 else if (hp
->hm_revision
!= 0xa0)
2449 hp
->happy_flags
|= HFLAG_NOT_A0
;
2451 hp
->happy_block
= dmam_alloc_coherent(hp
->dma_dev
, PAGE_SIZE
,
2452 &hp
->hblock_dvma
, GFP_KERNEL
);
2453 if (!hp
->happy_block
)
2456 /* Force check of the link first time we are brought up. */
2459 /* Force timer state to 'asleep' with count of zero. */
2460 hp
->timer_state
= asleep
;
2461 hp
->timer_ticks
= 0;
2463 timer_setup(&hp
->happy_timer
, happy_meal_timer
, 0);
2465 dev
->netdev_ops
= &hme_netdev_ops
;
2466 dev
->watchdog_timeo
= 5 * HZ
;
2467 dev
->ethtool_ops
= &hme_ethtool_ops
;
2469 /* Happy Meal can do it all... */
2470 dev
->hw_features
= NETIF_F_SG
| NETIF_F_HW_CSUM
;
2471 dev
->features
|= dev
->hw_features
| NETIF_F_RXCSUM
;
2474 /* Grrr, Happy Meal comes up by default not advertising
2475 * full duplex 100baseT capabilities, fix this.
2477 spin_lock_irq(&hp
->happy_lock
);
2478 happy_meal_set_initial_advertisement(hp
);
2479 spin_unlock_irq(&hp
->happy_lock
);
2481 err
= devm_register_netdev(hp
->dma_dev
, dev
);
2483 dev_err(hp
->dma_dev
, "Cannot register net device, aborting.\n");
2488 static int happy_meal_sbus_probe_one(struct platform_device
*op
, int is_qfe
)
2490 struct device_node
*dp
= op
->dev
.of_node
, *sbus_dp
;
2491 struct quattro
*qp
= NULL
;
2492 struct happy_meal
*hp
;
2493 struct net_device
*dev
;
2497 sbus_dp
= op
->dev
.parent
->of_node
;
2499 /* We can match PCI devices too, do not accept those here. */
2500 if (!of_node_name_eq(sbus_dp
, "sbus") && !of_node_name_eq(sbus_dp
, "sbi"))
2504 qp
= quattro_sbus_find(op
);
2507 for (qfe_slot
= 0; qfe_slot
< 4; qfe_slot
++)
2508 if (qp
->happy_meals
[qfe_slot
] == NULL
)
2514 dev
= devm_alloc_etherdev(&op
->dev
, sizeof(struct happy_meal
));
2517 SET_NETDEV_DEV(dev
, &op
->dev
);
2519 hp
= netdev_priv(dev
);
2522 hp
->dma_dev
= &op
->dev
;
2523 happy_meal_addr_init(hp
, dp
, qfe_slot
);
2525 spin_lock_init(&hp
->happy_lock
);
2528 hp
->qfe_parent
= qp
;
2529 hp
->qfe_ent
= qfe_slot
;
2530 qp
->happy_meals
[qfe_slot
] = dev
;
2533 hp
->gregs
= devm_platform_ioremap_resource(op
, 0);
2534 if (IS_ERR(hp
->gregs
)) {
2535 dev_err(&op
->dev
, "Cannot map global registers.\n");
2536 err
= PTR_ERR(hp
->gregs
);
2537 goto err_out_clear_quattro
;
2540 hp
->etxregs
= devm_platform_ioremap_resource(op
, 1);
2541 if (IS_ERR(hp
->etxregs
)) {
2542 dev_err(&op
->dev
, "Cannot map MAC TX registers.\n");
2543 err
= PTR_ERR(hp
->etxregs
);
2544 goto err_out_clear_quattro
;
2547 hp
->erxregs
= devm_platform_ioremap_resource(op
, 2);
2548 if (IS_ERR(hp
->erxregs
)) {
2549 dev_err(&op
->dev
, "Cannot map MAC RX registers.\n");
2550 err
= PTR_ERR(hp
->erxregs
);
2551 goto err_out_clear_quattro
;
2554 hp
->bigmacregs
= devm_platform_ioremap_resource(op
, 3);
2555 if (IS_ERR(hp
->bigmacregs
)) {
2556 dev_err(&op
->dev
, "Cannot map BIGMAC registers.\n");
2557 err
= PTR_ERR(hp
->bigmacregs
);
2558 goto err_out_clear_quattro
;
2561 hp
->tcvregs
= devm_platform_ioremap_resource(op
, 4);
2562 if (IS_ERR(hp
->tcvregs
)) {
2563 dev_err(&op
->dev
, "Cannot map TCVR registers.\n");
2564 err
= PTR_ERR(hp
->tcvregs
);
2565 goto err_out_clear_quattro
;
2568 hp
->hm_revision
= 0xa0;
2571 hp
->happy_flags
|= HFLAG_QUATTRO
;
2573 hp
->irq
= op
->archdata
.irqs
[0];
2575 /* Get the supported DVMA burst sizes from our Happy SBUS. */
2576 hp
->happy_bursts
= of_getintprop_default(sbus_dp
,
2577 "burst-sizes", 0x00);
2580 /* Hook up SBUS register/descriptor accessors. */
2581 hp
->read_desc32
= sbus_hme_read_desc32
;
2582 hp
->write_txd
= sbus_hme_write_txd
;
2583 hp
->write_rxd
= sbus_hme_write_rxd
;
2584 hp
->read32
= sbus_hme_read32
;
2585 hp
->write32
= sbus_hme_write32
;
2588 err
= happy_meal_common_probe(hp
, dp
);
2590 goto err_out_clear_quattro
;
2592 platform_set_drvdata(op
, hp
);
2596 "Quattro HME slot %d (SBUS) 10/100baseT Ethernet %pM\n",
2597 qfe_slot
, dev
->dev_addr
);
2599 netdev_info(dev
, "HAPPY MEAL (SBUS) 10/100baseT Ethernet %pM\n",
2604 err_out_clear_quattro
:
2606 qp
->happy_meals
[qfe_slot
] = NULL
;
2612 static int happy_meal_pci_probe(struct pci_dev
*pdev
,
2613 const struct pci_device_id
*ent
)
2615 struct device_node
*dp
= NULL
;
2616 struct quattro
*qp
= NULL
;
2617 struct happy_meal
*hp
;
2618 struct net_device
*dev
;
2619 void __iomem
*hpreg_base
;
2620 struct resource
*hpreg_res
;
2625 /* Now make sure pci_dev cookie is there. */
2627 dp
= pci_device_to_OF_node(pdev
);
2628 snprintf(prom_name
, sizeof(prom_name
), "%pOFn", dp
);
2630 if (is_quattro_p(pdev
))
2631 strcpy(prom_name
, "SUNW,qfe");
2633 strcpy(prom_name
, "SUNW,hme");
2636 err
= pcim_enable_device(pdev
);
2639 pci_set_master(pdev
);
2641 if (!strcmp(prom_name
, "SUNW,qfe") || !strcmp(prom_name
, "qfe")) {
2642 qp
= quattro_pci_find(pdev
);
2646 for (qfe_slot
= 0; qfe_slot
< 4; qfe_slot
++)
2647 if (!qp
->happy_meals
[qfe_slot
])
2654 dev
= devm_alloc_etherdev(&pdev
->dev
, sizeof(struct happy_meal
));
2657 SET_NETDEV_DEV(dev
, &pdev
->dev
);
2659 hp
= netdev_priv(dev
);
2661 hp
->happy_dev
= pdev
;
2662 hp
->dma_dev
= &pdev
->dev
;
2664 spin_lock_init(&hp
->happy_lock
);
2667 hp
->qfe_parent
= qp
;
2668 hp
->qfe_ent
= qfe_slot
;
2669 qp
->happy_meals
[qfe_slot
] = dev
;
2673 if ((pci_resource_flags(pdev
, 0) & IORESOURCE_IO
) != 0) {
2675 "Cannot find proper PCI device base address.\n");
2676 goto err_out_clear_quattro
;
2679 hpreg_res
= devm_request_mem_region(&pdev
->dev
,
2680 pci_resource_start(pdev
, 0),
2681 pci_resource_len(pdev
, 0),
2685 dev_err(&pdev
->dev
, "Cannot obtain PCI resources, aborting.\n");
2686 goto err_out_clear_quattro
;
2689 hpreg_base
= pcim_iomap(pdev
, 0, 0x8000);
2692 dev_err(&pdev
->dev
, "Unable to remap card memory.\n");
2693 goto err_out_clear_quattro
;
2696 happy_meal_addr_init(hp
, dp
, qfe_slot
);
2698 /* Layout registers. */
2699 hp
->gregs
= (hpreg_base
+ 0x0000UL
);
2700 hp
->etxregs
= (hpreg_base
+ 0x2000UL
);
2701 hp
->erxregs
= (hpreg_base
+ 0x4000UL
);
2702 hp
->bigmacregs
= (hpreg_base
+ 0x6000UL
);
2703 hp
->tcvregs
= (hpreg_base
+ 0x7000UL
);
2705 if (IS_ENABLED(CONFIG_SPARC
))
2706 hp
->hm_revision
= 0xc0 | (pdev
->revision
& 0x0f);
2708 hp
->hm_revision
= 0x20;
2711 hp
->happy_flags
|= HFLAG_QUATTRO
;
2713 /* And of course, indicate this is PCI. */
2714 hp
->happy_flags
|= HFLAG_PCI
;
2717 /* Assume PCI happy meals can handle all burst sizes. */
2718 hp
->happy_bursts
= DMA_BURSTBITS
;
2720 hp
->irq
= pdev
->irq
;
2723 /* Hook up PCI register/descriptor accessors. */
2724 hp
->read_desc32
= pci_hme_read_desc32
;
2725 hp
->write_txd
= pci_hme_write_txd
;
2726 hp
->write_rxd
= pci_hme_write_rxd
;
2727 hp
->read32
= pci_hme_read32
;
2728 hp
->write32
= pci_hme_write32
;
2731 err
= happy_meal_common_probe(hp
, dp
);
2733 goto err_out_clear_quattro
;
2735 pci_set_drvdata(pdev
, hp
);
2738 struct pci_dev
*qpdev
= qp
->quattro_dev
;
2741 if (!strncmp(dev
->name
, "eth", 3)) {
2742 int i
= simple_strtoul(dev
->name
+ 3, NULL
, 10);
2743 sprintf(prom_name
, "-%d", i
+ 3);
2746 "%s: Quattro HME (PCI/CheerIO) 10/100baseT Ethernet bridge %04x.%04x\n",
2747 prom_name
, qpdev
->vendor
, qpdev
->device
);
2752 "Quattro HME slot %d (PCI/CheerIO) 10/100baseT Ethernet %pM\n",
2753 qfe_slot
, dev
->dev_addr
);
2756 "HAPPY MEAL (PCI/CheerIO) 10/100BaseT Ethernet %pM\n",
2761 err_out_clear_quattro
:
2763 qp
->happy_meals
[qfe_slot
] = NULL
;
2767 static const struct pci_device_id happymeal_pci_ids
[] = {
2768 { PCI_DEVICE(PCI_VENDOR_ID_SUN
, PCI_DEVICE_ID_SUN_HAPPYMEAL
) },
2769 { } /* Terminating entry */
2772 MODULE_DEVICE_TABLE(pci
, happymeal_pci_ids
);
2774 static struct pci_driver hme_pci_driver
= {
2776 .id_table
= happymeal_pci_ids
,
2777 .probe
= happy_meal_pci_probe
,
2780 static int __init
happy_meal_pci_init(void)
2782 return pci_register_driver(&hme_pci_driver
);
2785 static void happy_meal_pci_exit(void)
2787 pci_unregister_driver(&hme_pci_driver
);
2789 while (qfe_pci_list
) {
2790 struct quattro
*qfe
= qfe_pci_list
;
2791 struct quattro
*next
= qfe
->next
;
2795 qfe_pci_list
= next
;
2802 static const struct of_device_id hme_sbus_match
[];
2803 static int hme_sbus_probe(struct platform_device
*op
)
2805 const struct of_device_id
*match
;
2806 struct device_node
*dp
= op
->dev
.of_node
;
2807 const char *model
= of_get_property(dp
, "model", NULL
);
2810 match
= of_match_device(hme_sbus_match
, &op
->dev
);
2813 is_qfe
= (match
->data
!= NULL
);
2815 if (!is_qfe
&& model
&& !strcmp(model
, "SUNW,sbus-qfe"))
2818 return happy_meal_sbus_probe_one(op
, is_qfe
);
2821 static const struct of_device_id hme_sbus_match
[] = {
2836 MODULE_DEVICE_TABLE(of
, hme_sbus_match
);
2838 static struct platform_driver hme_sbus_driver
= {
2841 .of_match_table
= hme_sbus_match
,
2843 .probe
= hme_sbus_probe
,
2846 static int __init
happy_meal_sbus_init(void)
2848 return platform_driver_register(&hme_sbus_driver
);
2851 static void happy_meal_sbus_exit(void)
2853 platform_driver_unregister(&hme_sbus_driver
);
2855 while (qfe_sbus_list
) {
2856 struct quattro
*qfe
= qfe_sbus_list
;
2857 struct quattro
*next
= qfe
->next
;
2861 qfe_sbus_list
= next
;
2866 static int __init
happy_meal_probe(void)
2871 err
= happy_meal_sbus_init();
2875 err
= happy_meal_pci_init();
2878 happy_meal_sbus_exit();
2887 static void __exit
happy_meal_exit(void)
2890 happy_meal_sbus_exit();
2893 happy_meal_pci_exit();
2897 module_init(happy_meal_probe
);
2898 module_exit(happy_meal_exit
);