16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/types.h>
19 #include <linux/fcntl.h>
23 #include <linux/slab.h>
24 #include <linux/string.h>
27 #include <linux/ethtool.h>
28 #include <linux/mii.h>
30 #include <linux/random.h>
31 #include <linux/errno.h>
32 #include <linux/netdevice.h>
36 #include <linux/bitops.h>
41 #include <asm/byteorder.h>
46 #include <asm/idprom.h>
47 #include <asm/openprom.h>
48 #include <asm/oplib.h>
52 #include <asm/uaccess.h>
54 #include <asm/pgtable.h>
58 #include <linux/pci.h>
63 #define DRV_NAME "sunhme"
64 #define DRV_VERSION "3.10"
65 #define DRV_RELDATE "August 26, 2008"
83 static struct quattro *qfe_sbus_list;
87 static struct quattro *qfe_pci_list;
97 struct hme_tx_logent {
101 #define TXLOG_ACTION_IRQ 0x01
102 #define TXLOG_ACTION_TXMIT 0x02
103 #define TXLOG_ACTION_TBUSY 0x04
104 #define TXLOG_ACTION_NBUFS 0x08
107 #define TX_LOG_LEN 128
108 static struct hme_tx_logent tx_log[TX_LOG_LEN];
109 static int txlog_cur_entry;
112 struct hme_tx_logent *tlp;
116 tlp = &tx_log[txlog_cur_entry];
117 tlp->tstamp = (
unsigned int)jiffies;
122 txlog_cur_entry = (txlog_cur_entry + 1) & (TX_LOG_LEN - 1);
129 this = txlog_cur_entry;
130 for (i = 0; i < TX_LOG_LEN; i++) {
131 printk(
"TXLOG[%d]: j[%08x] tx[N(%d)O(%d)] action[%08x] stat[%08x]\n", i,
133 tx_log[
this].tx_new, tx_log[
this].tx_old,
135 this = (
this + 1) & (TX_LOG_LEN - 1);
145 printk(
"TXD[%d..%d]: [%08x:%08x] [%08x:%08x] [%08x:%08x] [%08x:%08x]\n",
154 #define tx_add_log(hp, a, s) do { } while(0)
155 #define tx_dump_log() do { } while(0)
156 #define tx_dump_ring(hp) do { } while(0)
160 #define HMD(x) printk x
167 #ifdef AUTO_SWITCH_DEBUG
168 #define ASD(x) printk x
173 #define DEFAULT_IPG0 16
174 #define DEFAULT_IPG1 8
175 #define DEFAULT_IPG2 4
176 #define DEFAULT_JAMSIZE 4
185 #if defined(CONFIG_SBUS) && defined(CONFIG_PCI)
210 static u32 sbus_hme_read_desc32(
hme32 *
p)
239 static u32 pci_hme_read_desc32(
hme32 *p)
244 #define hme_write32(__hp, __reg, __val) \
245 ((__hp)->write32((__reg), (__val)))
246 #define hme_read32(__hp, __reg) \
247 ((__hp)->read32(__reg))
248 #define hme_write_rxd(__hp, __rxd, __flags, __addr) \
249 ((__hp)->write_rxd((__rxd), (__flags), (__addr)))
250 #define hme_write_txd(__hp, __txd, __flags, __addr) \
251 ((__hp)->write_txd((__txd), (__flags), (__addr)))
252 #define hme_read_desc32(__hp, __p) \
253 ((__hp)->read_desc32(__p))
254 #define hme_dma_map(__hp, __ptr, __size, __dir) \
255 ((__hp)->dma_map((__hp)->dma_dev, (__ptr), (__size), (__dir)))
256 #define hme_dma_unmap(__hp, __addr, __size, __dir) \
257 ((__hp)->dma_unmap((__hp)->dma_dev, (__addr), (__size), (__dir)))
258 #define hme_dma_sync_for_cpu(__hp, __addr, __size, __dir) \
259 ((__hp)->dma_sync_for_cpu((__hp)->dma_dev, (__addr), (__size), (__dir)))
260 #define hme_dma_sync_for_device(__hp, __addr, __size, __dir) \
261 ((__hp)->dma_sync_for_device((__hp)->dma_dev, (__addr), (__size), (__dir)))
265 #define hme_write32(__hp, __reg, __val) \
266 sbus_writel((__val), (__reg))
267 #define hme_read32(__hp, __reg) \
269 #define hme_write_rxd(__hp, __rxd, __flags, __addr) \
270 do { (__rxd)->rx_addr = (__force hme32)(u32)(__addr); \
272 (__rxd)->rx_flags = (__force hme32)(u32)(__flags); \
274 #define hme_write_txd(__hp, __txd, __flags, __addr) \
275 do { (__txd)->tx_addr = (__force hme32)(u32)(__addr); \
277 (__txd)->tx_flags = (__force hme32)(u32)(__flags); \
279 #define hme_read_desc32(__hp, __p) ((__force u32)(hme32)*(__p))
280 #define hme_dma_map(__hp, __ptr, __size, __dir) \
281 dma_map_single((__hp)->dma_dev, (__ptr), (__size), (__dir))
282 #define hme_dma_unmap(__hp, __addr, __size, __dir) \
283 dma_unmap_single((__hp)->dma_dev, (__addr), (__size), (__dir))
284 #define hme_dma_sync_for_cpu(__hp, __addr, __size, __dir) \
285 dma_dma_sync_single_for_cpu((__hp)->dma_dev, (__addr), (__size), (__dir))
286 #define hme_dma_sync_for_device(__hp, __addr, __size, __dir) \
287 dma_dma_sync_single_for_device((__hp)->dma_dev, (__addr), (__size), (__dir))
290 #define hme_write32(__hp, __reg, __val) \
291 writel((__val), (__reg))
292 #define hme_read32(__hp, __reg) \
294 #define hme_write_rxd(__hp, __rxd, __flags, __addr) \
295 do { (__rxd)->rx_addr = (__force hme32)cpu_to_le32(__addr); \
297 (__rxd)->rx_flags = (__force hme32)cpu_to_le32(__flags); \
299 #define hme_write_txd(__hp, __txd, __flags, __addr) \
300 do { (__txd)->tx_addr = (__force hme32)cpu_to_le32(__addr); \
302 (__txd)->tx_flags = (__force hme32)cpu_to_le32(__flags); \
308 #define hme_dma_map(__hp, __ptr, __size, __dir) \
309 pci_map_single((__hp)->dma_dev, (__ptr), (__size), (__dir))
310 #define hme_dma_unmap(__hp, __addr, __size, __dir) \
311 pci_unmap_single((__hp)->dma_dev, (__addr), (__size), (__dir))
312 #define hme_dma_sync_for_cpu(__hp, __addr, __size, __dir) \
313 pci_dma_sync_single_for_cpu((__hp)->dma_dev, (__addr), (__size), (__dir))
314 #define hme_dma_sync_for_device(__hp, __addr, __size, __dir) \
315 pci_dma_sync_single_for_device((__hp)->dma_dev, (__addr), (__size), (__dir))
361 #define TCVR_FAILURE 0x80000000
363 static int happy_meal_bb_read(
struct happy_meal *hp,
370 ASD((
"happy_meal_bb_read: reg=%d ", reg));
376 for (i = 0; i < 32; i++)
377 BB_PUT_BIT(hp, tregs, 1);
380 BB_PUT_BIT(hp, tregs, 0);
381 BB_PUT_BIT(hp, tregs, 1);
382 BB_PUT_BIT(hp, tregs, 1);
383 BB_PUT_BIT(hp, tregs, 0);
386 tmp = hp->
paddr & 0xff;
387 for (i = 4; i >= 0; i--)
388 BB_PUT_BIT(hp, tregs, ((tmp >> i) & 1));
392 for (i = 4; i >= 0; i--)
393 BB_PUT_BIT(hp, tregs, ((tmp >> i) & 1));
400 for (i = 15; i >= 0; i--)
401 retval |= BB_GET_BIT2(hp, tregs, (hp->
tcvr_type ==
internal));
405 ASD((
"value=%x\n", retval));
409 static void happy_meal_bb_write(
struct happy_meal *hp,
411 unsigned short value)
416 ASD((
"happy_meal_bb_write: reg=%d value=%x\n", reg, value));
422 for (i = 0; i < 32; i++)
423 BB_PUT_BIT(hp, tregs, 1);
426 BB_PUT_BIT(hp, tregs, 0);
427 BB_PUT_BIT(hp, tregs, 1);
428 BB_PUT_BIT(hp, tregs, 0);
429 BB_PUT_BIT(hp, tregs, 1);
432 tmp = (hp->
paddr & 0xff);
433 for (i = 4; i >= 0; i--)
434 BB_PUT_BIT(hp, tregs, ((tmp >> i) & 1));
438 for (i = 4; i >= 0; i--)
439 BB_PUT_BIT(hp, tregs, ((tmp >> i) & 1));
442 BB_PUT_BIT(hp, tregs, 1);
443 BB_PUT_BIT(hp, tregs, 0);
445 for (i = 15; i >= 0; i--)
446 BB_PUT_BIT(hp, tregs, ((value >> i) & 1));
452 #define TCVR_READ_TRIES 16
454 static int happy_meal_tcvr_read(
struct happy_meal *hp,
460 ASD((
"happy_meal_tcvr_read: reg=0x%02x ", reg));
462 ASD((
"no transceiver, value=TCVR_FAILURE\n"));
467 ASD((
"doing bit bang\n"));
468 return happy_meal_bb_read(hp, tregs, reg);
476 printk(
KERN_ERR "happy meal: Aieee, transceiver MIF read bolixed\n");
480 ASD((
"value=%04x\n", retval));
484 #define TCVR_WRITE_TRIES 16
486 static void happy_meal_tcvr_write(
struct happy_meal *hp,
488 unsigned short value)
492 ASD((
"happy_meal_tcvr_write: reg=0x%02x value=%04x\n", reg, value));
496 happy_meal_bb_write(hp, tregs, reg, value);
503 ((reg & 0xff) << 18) | (value & 0xffff)));
509 printk(
KERN_ERR "happy meal: Aieee, transceiver MIF write bolixed\n");
577 printk(
"transceiver at ");
581 printk(
"100Mb/s, Full Duplex.\n");
583 printk(
"100Mb/s, Half Duplex.\n");
586 printk(
"10Mb/s, Full Duplex.\n");
588 printk(
"10Mb/s, Half Duplex.\n");
599 printk(
"transceiver at ");
665 BIGMAC_TXCFG_ENABLE);
671 static int happy_meal_init(
struct happy_meal *hp);
673 static int is_lucent_phy(
struct happy_meal *hp)
676 unsigned short mr2, mr3;
679 mr2 = happy_meal_tcvr_read(hp, tregs, 2);
680 mr3 = happy_meal_tcvr_read(hp, tregs, 3);
681 if ((mr2 & 0xffff) == 0x0180 &&
682 ((mr3 & 0xffff) >> 10) == 0x1d)
688 static void happy_meal_timer(
unsigned long data)
692 int restart_timer = 0;
706 printk(
KERN_NOTICE "%s: Auto-Negotiation unsuccessful, trying force link mode\n",
711 if (!is_lucent_phy(hp)) {
730 ret = set_happy_link_modes(hp, tregs);
761 display_link_mode(hp, tregs);
767 "not completely up.\n", hp->
dev->name);
785 if (!is_lucent_phy(hp)) {
790 happy_meal_tcvr_write(hp, tregs,
797 if (!is_lucent_phy(hp)) {
799 happy_meal_tcvr_write(hp, tregs,
807 display_forced_link_mode(hp, tregs);
808 set_happy_link_modes(hp, tregs);
815 ret = try_next_permutation(hp, tregs);
825 ret = happy_meal_init(hp);
829 "Happy Meal.\n", hp->
dev->name);
833 if (!is_lucent_phy(hp)) {
837 happy_meal_tcvr_write(hp, tregs,
851 printk(
KERN_ERR "%s: Aieee, link timer is asleep but we got one anyways!\n",
868 #define TX_RESET_TRIES 32
869 #define RX_RESET_TRIES 32
876 HMD((
"happy_meal_tx_reset: reset, "));
896 HMD((
"happy_meal_rx_reset: reset, "));
911 #define STOP_TRIES 16
918 HMD((
"happy_meal_stop: reset, "));
959 ASD((
"happy_meal_poll_stop: "));
964 HMD((
"not polling, return\n"));
969 ASD((
"were polling, mif ints off, "));
973 ASD((
"polling off, "));
988 #define TCVR_RESET_TRIES 16
989 #define TCVR_UNISOLATE_TRIES 32
998 ASD((
"happy_meal_tcvr_reset: tcfg<%08lx> ", tconfig));
1005 happy_meal_tcvr_write(hp, tregs,
MII_BMCR,
1007 result = happy_meal_tcvr_read(hp, tregs,
MII_BMCR);
1009 ASD((
"phyread_fail>\n"));
1012 ASD((
"phyread_ok,PSELECT>"));
1018 ASD((
"internal<PSELECT,"));
1021 happy_meal_tcvr_write(hp, tregs,
MII_BMCR,
1023 result = happy_meal_tcvr_read(hp, tregs,
MII_BMCR);
1025 ASD((
"phyread_fail>\n"));
1028 ASD((
"phyread_ok,~PSELECT>"));
1035 ASD((
"BMCR_RESET "));
1039 result = happy_meal_tcvr_read(hp, tregs,
MII_BMCR);
1048 ASD((
"BMCR RESET FAILED!\n"));
1051 ASD((
"RESET_OK\n"));
1065 result = happy_meal_tcvr_read(hp, tregs,
MII_BMCR);
1073 ASD((
" FAILED!\n"));
1076 ASD((
" SUCCESS and CSCONFIG_DFBYPASS\n"));
1077 if (!is_lucent_phy(hp)) {
1078 result = happy_meal_tcvr_read(hp, tregs,
1080 happy_meal_tcvr_write(hp, tregs,
1090 static void happy_meal_transceiver_check(
struct happy_meal *hp,
void __iomem *tregs)
1094 ASD((
"happy_meal_transceiver_check: tcfg=%08lx ", tconfig));
1097 ASD((
"<polling> "));
1100 ASD((
"<internal> <poll stop> "));
1101 happy_meal_poll_stop(hp, tregs);
1104 ASD((
"<external>\n"));
1111 ASD((
"<external> "));
1113 ASD((
"<poll stop> "));
1114 happy_meal_poll_stop(hp, tregs);
1117 ASD((
"<internal>\n"));
1131 ASD((
"<not polling> "));
1132 if (reread & TCV_CFG_MDIO1) {
1136 ASD((
"<external>\n"));
1143 ASD((
"<internal>\n"));
1197 static void happy_meal_clean_rings(
struct happy_meal *hp)
1208 dma_addr = hme_read_desc32(hp, &rxd->
rx_addr);
1225 for (frag = 0; frag <= skb_shinfo(skb)->nr_frags; frag++) {
1227 dma_addr = hme_read_desc32(hp, &txd->
tx_addr);
1230 (hme_read_desc32(hp, &txd->
tx_flags)
1235 (hme_read_desc32(hp, &txd->
tx_flags)
1239 if (frag != skb_shinfo(skb)->nr_frags)
1249 static void happy_meal_init_rings(
struct happy_meal *hp)
1254 HMD((
"happy_meal_init_rings: counters to zero, "));
1259 happy_meal_clean_rings(hp);
1262 HMD((
"init rxring, "));
1282 HMD((
"init txring, "));
1290 static void happy_meal_begin_auto_negotiation(
struct happy_meal *hp,
1332 #ifdef AUTO_SWITCH_DEBUG
1333 ASD((
"%s: Advertising [ ", hp->
dev->name));
1362 printk(
KERN_ERR "%s: Happy Meal would not start auto negotiation "
1363 "BMCR=0x%04x\n", hp->
dev->name, hp->
sw_bmcr);
1392 if (!is_lucent_phy(hp)) {
1414 static int happy_meal_init(
struct happy_meal *hp)
1422 unsigned char *
e = &hp->
dev->dev_addr[0];
1427 HMD((
"happy_meal_init: happy_flags[%08x] ",
1430 HMD((
"set HFLAG_INIT, "));
1432 happy_meal_get_counters(hp, bregs);
1436 HMD((
"to happy_meal_poll_stop\n"));
1437 happy_meal_poll_stop(hp, tregs);
1440 HMD((
"happy_meal_init: to happy_meal_stop\n"));
1441 happy_meal_stop(hp, gregs);
1444 HMD((
"happy_meal_init: to happy_meal_init_rings\n"));
1445 happy_meal_init_rings(hp);
1448 HMD((
"happy_meal_init: Disable all MIF irqs (old[%08x]), ",
1454 HMD((
"use frame old[%08x], ",
1459 HMD((
"use bitbang old[%08x], ",
1466 HMD((
"to happy_meal_transceiver_check\n"));
1467 happy_meal_transceiver_check(hp, tregs);
1470 HMD((
"happy_meal_init: "));
1474 HMD((
"AAIEEE no transceiver type, EAGAIN"));
1479 HMD((
"internal, using MII, "));
1485 HMD((
"external, disable MII, "));
1490 if (happy_meal_tcvr_reset(hp, tregs))
1494 HMD((
"tx/rx reset, "));
1495 happy_meal_tx_reset(hp, bregs);
1496 happy_meal_rx_reset(hp, bregs);
1499 HMD((
"jsize/ipg1/ipg2, "));
1505 HMD((
"rseed/macaddr, "));
1526 memset(hash_table, 0,
sizeof(hash_table));
1530 hash_table[crc >> 4] |= 1 << (crc & 0xf);
1544 HMD((
"ring ptrs rxr[%08x] txr[%08x]\n",
1564 HMD((
"happy_meal_init: old[%08x] bursts<",
1567 #ifndef CONFIG_SPARC
1574 || sbus_can_burst64()
1586 if (sbus_can_dma_64bit()) {
1609 HMD((
", enable global interrupts, "));
1615 HMD((
"tx rsize=%d oreg[%08x], ", (
int)TX_RING_SIZE,
1620 HMD((
"tx dma enable old[%08x], ",
1630 HMD((
"erx regs bug old[%08x]\n",
1636 printk(
KERN_ERR "happy meal: Eieee, rx config register gets greasy fries.\n");
1637 printk(
KERN_ERR "happy meal: Trying to set %08x, reread gives %08x\n",
1643 HMD((
"happy_meal_init: enable hash rx_cfg_old[%08x], ",
1654 HMD((
"BIGMAC init, "));
1678 HMD((
"XIF config old[%08x], ",
1683 HMD((
"tx old[%08x] and rx [%08x] ON!\n",
1697 happy_meal_begin_auto_negotiation(hp, tregs,
NULL);
1704 static void happy_meal_set_initial_advertisement(
struct happy_meal *hp)
1710 happy_meal_stop(hp, gregs);
1718 happy_meal_transceiver_check(hp, tregs);
1729 if (happy_meal_tcvr_reset(hp, tregs))
1775 printk(
KERN_ERR "%s: Error interrupt for happy meal, status = %08x\n",
1776 hp->
dev->name, status);
1792 printk(
KERN_ERR "%s: Happy Meal transmitter FIFO underrun, DMA error.\n",
1812 "descriptors, packet dropped.\n",
1833 printk(
KERN_ERR "%s: EOP not set in happy meal transmit descriptor!\n",
1863 printk(
KERN_ERR "%s: Happy Meal register access SBUS slave (%s) error.\n",
1871 happy_meal_init(hp);
1878 static void happy_meal_mif_interrupt(
struct happy_meal *hp)
1902 happy_meal_poll_stop(hp, tregs);
1906 #define TXD(x) printk x
1912 static void happy_meal_tx(
struct happy_meal *hp)
1921 while (elem != hp->
tx_new) {
1926 TXD((
"[%d]", elem));
1927 this = &txbase[
elem];
1928 flags = hme_read_desc32(hp, &this->tx_flags);
1932 if (skb_shinfo(skb)->nr_frags) {
1935 last = elem + skb_shinfo(skb)->nr_frags;
1936 last &= (TX_RING_SIZE - 1);
1937 flags = hme_read_desc32(hp, &txbase[last].tx_flags);
1938 if (flags & TXFLAG_OWN)
1944 for (frag = 0; frag <= skb_shinfo(skb)->nr_frags; frag++) {
1945 dma_addr = hme_read_desc32(hp, &this->tx_addr);
1946 dma_len = hme_read_desc32(hp, &this->tx_flags);
1955 this = &txbase[
elem];
1964 if (netif_queue_stopped(dev) &&
1966 netif_wake_queue(dev);
1970 #define RXD(x) printk x
1992 this = &rxbase[
elem];
1995 int len = flags >> 16;
1997 u32 dma_addr = hme_read_desc32(hp, &this->rx_addr);
1999 RXD((
"[%d ", elem));
2003 RXD((
"ERR(%08x)]", flags));
2007 if (len & (RXFLAG_OVERFLOW >> 16)) {
2026 if (new_skb ==
NULL) {
2042 struct sk_buff *copy_skb = netdev_alloc_skb(dev, len + 2);
2044 if (copy_skb ==
NULL) {
2049 skb_reserve(copy_skb, 2);
2052 skb_copy_from_linear_data(skb, copy_skb->
data, len);
2066 RXD((
"len=%d csum=%4x]", len, csum));
2074 this = &rxbase[
elem];
2088 HMD((
"happy_meal_interrupt: status=%08x ", happy_status));
2094 if (happy_meal_is_not_so_happy(hp, happy_status))
2098 if (happy_status & GREG_STAT_MIFIRQ) {
2100 happy_meal_mif_interrupt(hp);
2110 happy_meal_rx(hp, dev);
2126 for (i = 0; i < 4; i++) {
2131 HMD((
"quattro_interrupt: status=%08x ", happy_status));
2133 if (!(happy_status & (GREG_STAT_ERRORS |
2136 GREG_STAT_RXTOHOST)))
2141 if (happy_status & GREG_STAT_ERRORS) {
2143 if (happy_meal_is_not_so_happy(hp, happy_status))
2147 if (happy_status & GREG_STAT_MIFIRQ) {
2149 happy_meal_mif_interrupt(hp);
2152 if (happy_status & GREG_STAT_TXALL) {
2157 if (happy_status & GREG_STAT_RXTOHOST) {
2159 happy_meal_rx(hp, dev);
2171 static int happy_meal_open(
struct net_device *dev)
2176 HMD((
"happy_meal_open: "));
2193 HMD((
"to happy_meal_init\n"));
2196 res = happy_meal_init(hp);
2204 static int happy_meal_close(
struct net_device *dev)
2209 happy_meal_stop(hp, hp->
gregs);
2210 happy_meal_clean_rings(hp);
2228 #define SXD(x) printk x
2233 static void happy_meal_tx_timeout(
struct net_device *dev)
2245 happy_meal_init(hp);
2248 netif_wake_queue(dev);
2260 const u32 csum_start_off = skb_checksum_start_offset(skb);
2271 netif_stop_queue(dev);
2279 SXD((
"SX<l[%d]e[%d]>", len, entry));
2282 if (skb_shinfo(skb)->nr_frags == 0) {
2293 u32 first_len, first_mapping;
2299 first_len = skb_headlen(skb);
2304 for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
2308 len = skb_frag_size(this_frag);
2309 mapping = skb_frag_dma_map(hp->
dma_dev, this_frag,
2311 this_txflags = tx_flags;
2312 if (frag == skb_shinfo(skb)->nr_frags - 1)
2327 netif_stop_queue(dev);
2349 static void happy_meal_set_multicast(
struct net_device *dev)
2369 memset(hash_table, 0,
sizeof(hash_table));
2373 hash_table[crc >> 4] |= 1 << (crc & 0xf);
2425 ethtool_cmd_speed_set(cmd, speed);
2438 ((ethtool_cmd_speed(cmd) !=
SPEED_100 &&
2439 ethtool_cmd_speed(cmd) !=
SPEED_10) ||
2447 happy_meal_begin_auto_negotiation(hp, hp->
tcvregs, cmd);
2487 static const struct ethtool_ops hme_ethtool_ops = {
2488 .get_settings = hme_get_settings,
2489 .set_settings = hme_set_settings,
2490 .get_drvinfo = hme_get_drvinfo,
2491 .get_link = hme_get_link,
2494 static int hme_version_printed;
2517 for (i = 0; i < 4; i++)
2521 qp->
next = qfe_sbus_list;
2533 static int __init quattro_sbus_register_irqs(
void)
2537 for (qp = qfe_sbus_list; qp !=
NULL; qp = qp->
next) {
2541 for (qfe_slot = 0; qfe_slot < 4; qfe_slot++) {
2549 quattro_sbus_interrupt,
2554 "error %d.\n", err);
2562 static void quattro_sbus_free_irqs(
void)
2566 for (qp = qfe_sbus_list; qp !=
NULL; qp = qp->
next) {
2568 int qfe_slot, skip = 0;
2570 for (qfe_slot = 0; qfe_slot < 4; qfe_slot++) {
2588 if (!bdev)
return NULL;
2589 for (qp = qfe_pci_list; qp !=
NULL; qp = qp->
next) {
2599 for (i = 0; i < 4; i++)
2603 qp->
next = qfe_pci_list;
2614 .ndo_open = happy_meal_open,
2615 .ndo_stop = happy_meal_close,
2616 .ndo_start_xmit = happy_meal_start_xmit,
2617 .ndo_tx_timeout = happy_meal_tx_timeout,
2618 .ndo_get_stats = happy_meal_get_stats,
2619 .ndo_set_rx_mode = happy_meal_set_multicast,
2632 int i, qfe_slot = -1;
2635 sbus_dp = op->
dev.parent->of_node;
2638 if (
strcmp(sbus_dp->name,
"sbus") &&
strcmp(sbus_dp->name,
"sbi"))
2642 qp = quattro_sbus_find(op);
2645 for (qfe_slot = 0; qfe_slot < 4; qfe_slot++)
2653 dev = alloc_etherdev(
sizeof(
struct happy_meal));
2658 if (hme_version_printed++ == 0)
2664 for (i = 0; i < 6; i++) {
2669 for (i = 0; i < 6; i++)
2673 const unsigned char *
addr;
2678 if (qfe_slot != -1 && addr && len == 6)
2684 hp = netdev_priv(dev);
2702 goto err_out_free_netdev;
2709 goto err_out_iounmap;
2716 goto err_out_iounmap;
2723 goto err_out_iounmap;
2730 goto err_out_iounmap;
2748 "burst-sizes", 0x00);
2757 goto err_out_iounmap;
2780 #if defined(CONFIG_SBUS) && defined(CONFIG_PCI)
2782 hp->read_desc32 = sbus_hme_read_desc32;
2783 hp->write_txd = sbus_hme_write_txd;
2784 hp->write_rxd = sbus_hme_write_rxd;
2785 hp->read32 = sbus_hme_read32;
2786 hp->write32 = sbus_hme_write32;
2793 happy_meal_set_initial_advertisement(hp);
2800 goto err_out_free_coherent;
2806 printk(
KERN_INFO "%s: Quattro HME slot %d (SBUS) 10/100baseT Ethernet ",
2807 dev->
name, qfe_slot);
2816 err_out_free_coherent:
2837 err_out_free_netdev:
2846 #ifndef CONFIG_SPARC
2847 static int is_quattro_p(
struct pci_dev *pdev)
2853 if (busdev ==
NULL ||
2872 static int find_eth_addr_in_vpd(
void __iomem *rom_base,
int len,
int index,
unsigned char *dev_addr)
2876 for (this_offset = 0x20; this_offset < len; this_offset++) {
2877 void __iomem *p = rom_base + this_offset;
2879 if (
readb(p + 0) != 0x90 ||
2880 readb(p + 1) != 0x00 ||
2881 readb(p + 2) != 0x09 ||
2882 readb(p + 3) != 0x4e ||
2883 readb(p + 4) != 0x41 ||
2884 readb(p + 5) != 0x06)
2893 for (i = 0; i < 6; i++)
2894 dev_addr[i] =
readb(p + i);
2902 static void get_hme_mac_nonsparc(
struct pci_dev *pdev,
unsigned char *dev_addr)
2911 if (is_quattro_p(pdev))
2914 found =
readb(p) == 0x55 &&
2915 readb(p + 1) == 0xaa &&
2916 find_eth_addr_in_vpd(p, (64 * 1024), index, dev_addr);
2940 unsigned long hpreg_res;
2941 int i, qfe_slot = -1;
2947 dp = pci_device_to_OF_node(pdev);
2950 if (is_quattro_p(pdev))
2951 strcpy(prom_name,
"SUNW,qfe");
2953 strcpy(prom_name,
"SUNW,hme");
2962 if (!
strcmp(prom_name,
"SUNW,qfe") || !
strcmp(prom_name,
"qfe")) {
2963 qp = quattro_pci_find(pdev);
2966 for (qfe_slot = 0; qfe_slot < 4; qfe_slot++)
2973 dev = alloc_etherdev(
sizeof(
struct happy_meal));
2979 if (hme_version_printed++ == 0)
2982 hp = netdev_priv(dev);
2998 printk(
KERN_ERR "happymeal(PCI): Cannot find proper PCI device base address.\n");
2999 goto err_out_clear_quattro;
3004 goto err_out_clear_quattro;
3007 if ((hpreg_base =
ioremap(hpreg_res, 0x8000)) ==
NULL) {
3008 printk(
KERN_ERR "happymeal(PCI): Unable to remap card memory.\n");
3009 goto err_out_free_res;
3012 for (i = 0; i < 6; i++) {
3017 for (i = 0; i < 6; i++)
3022 const unsigned char *
addr;
3025 if (qfe_slot != -1 &&
3034 get_hme_mac_nonsparc(pdev, &dev->
dev_addr[0]);
3039 hp->
gregs = (hpreg_base + 0x0000
UL);
3077 goto err_out_iounmap;
3096 #if defined(CONFIG_SBUS) && defined(CONFIG_PCI)
3098 hp->read_desc32 = pci_hme_read_desc32;
3099 hp->write_txd = pci_hme_write_txd;
3100 hp->write_rxd = pci_hme_write_rxd;
3101 hp->read32 = pci_hme_read32;
3102 hp->write32 = pci_hme_write32;
3109 happy_meal_set_initial_advertisement(hp);
3116 goto err_out_iounmap;
3127 sprintf(prom_name,
"-%d", i + 3);
3129 printk(
KERN_INFO "%s%s: Quattro HME (PCI/CheerIO) 10/100baseT Ethernet ", dev->
name, prom_name);
3132 printk(
"DEC 21153 PCI Bridge\n");
3134 printk(
"unknown bridge %04x.%04x\n",
3139 printk(
KERN_INFO "%s: Quattro HME slot %d (PCI/CheerIO) 10/100baseT Ethernet ",
3140 dev->
name, qfe_slot);
3142 printk(
KERN_INFO "%s: HAPPY MEAL (PCI/CheerIO) 10/100BaseT Ethernet ",
3155 err_out_clear_quattro:
3191 .id_table = happymeal_pci_ids,
3192 .probe = happy_meal_pci_probe,
3196 static int __init happy_meal_pci_init(
void)
3198 return pci_register_driver(&hme_pci_driver);
3201 static void happy_meal_pci_exit(
void)
3205 while (qfe_pci_list) {
3206 struct quattro *qfe = qfe_pci_list;
3211 qfe_pci_list =
next;
3231 if (!is_qfe && model && !
strcmp(model,
"SUNW,sbus-qfe"))
3234 return happy_meal_sbus_probe_one(op, is_qfe);
3284 .of_match_table = hme_sbus_match,
3286 .probe = hme_sbus_probe,
3290 static int __init happy_meal_sbus_init(
void)
3296 err = quattro_sbus_register_irqs();
3301 static void happy_meal_sbus_exit(
void)
3304 quattro_sbus_free_irqs();
3306 while (qfe_sbus_list) {
3307 struct quattro *qfe = qfe_sbus_list;
3312 qfe_sbus_list =
next;
3317 static int __init happy_meal_probe(
void)
3322 err = happy_meal_sbus_init();
3326 err = happy_meal_pci_init();
3329 happy_meal_sbus_exit();
3338 static void __exit happy_meal_exit(
void)
3341 happy_meal_sbus_exit();
3344 happy_meal_pci_exit();