446 #include <linux/module.h>
447 #include <linux/kernel.h>
448 #include <linux/string.h>
450 #include <linux/ptrace.h>
451 #include <linux/errno.h>
453 #include <linux/pci.h>
459 #include <linux/netdevice.h>
462 #include <linux/time.h>
463 #include <linux/types.h>
465 #include <linux/ctype.h>
468 #include <linux/bitops.h>
473 #include <asm/byteorder.h>
474 #include <asm/unaligned.h>
475 #include <asm/uaccess.h>
476 #ifdef CONFIG_PPC_PMAC
477 #include <asm/machdep.h>
485 #define c_char const char
520 #define DE4X5_MAX_PHY 8
539 {0,
SEEQ_T4 , 1, {0x12, 0x10, 0x10}},
541 {0, 0x7810 , 1, {0x14, 0x0800, 0x0800}}
549 #define GENERIC_REG 0x05
550 #define GENERIC_MASK MII_ANLPA_100M
551 #define GENERIC_VALUE MII_ANLPA_100M
557 {0x00, 0x00, 0xc0, 0x00, 0x00, 0x00},
558 {0x00, 0x00, 0xe8, 0x00, 0x00, 0x00}
569 static c_char srom_repair_info[][100] = {
570 {0x00,0x1e,0x00,0x00,0x00,0x08,
571 0x1f,0x01,0x8f,0x01,0x00,0x01,0x00,0x02,
572 0x01,0x00,0x00,0x78,0xe0,0x01,0x00,0x50,
578 static int de4x5_debug = DE4X5_DEBUG;
594 static char *args = DE4X5_PARM;
604 #define DE4X5_AUTOSENSE_MS 250
606 #define DE4X5_NDA 0xffe0
611 #define PROBE_LENGTH 32
612 #define ETH_PROM_SIG 0xAA5500FFUL
617 #define PKT_BUF_SZ 1536
618 #define IEEE802_3_SZ 1518
619 #define MAX_PKT_SZ 1514
620 #define MAX_DAT_SZ 1500
622 #define PKT_HDR_LEN 14
623 #define FAKE_FRAME_LEN (MAX_PKT_SZ + 1)
624 #define QUEUE_PKT_TIMEOUT (3*HZ)
630 #define DE4X5_EISA_IO_PORTS 0x0c00
631 #define DE4X5_EISA_TOTAL_SIZE 0x100
633 #define EISA_ALLOWED_IRQ_LIST {5, 9, 10, 11}
635 #define DE4X5_SIGNATURE {"DE425","DE434","DE435","DE450","DE500"}
636 #define DE4X5_NAME_LENGTH 8
643 #define PROBE_LENGTH 32
644 #define ETH_PROM_SIG 0xAA5500FFUL
649 #define PCI_MAX_BUS_NUM 8
650 #define DE4X5_PCI_TOTAL_SIZE 0x80
651 #define DE4X5_CLASS_CODE 0x00020000
659 #define DE4X5_ALIGN4 ((u_long)4 - 1)
660 #define DE4X5_ALIGN8 ((u_long)8 - 1)
661 #define DE4X5_ALIGN16 ((u_long)16 - 1)
662 #define DE4X5_ALIGN32 ((u_long)32 - 1)
663 #define DE4X5_ALIGN64 ((u_long)64 - 1)
664 #define DE4X5_ALIGN128 ((u_long)128 - 1)
666 #define DE4X5_ALIGN DE4X5_ALIGN32
667 #define DE4X5_CACHE_ALIGN CAL_16LONG
668 #define DESC_SKIP_LEN DSL_0
675 static int dec_only = 1;
681 #define ENABLE_IRQs { \
683 outl(imr, DE4X5_IMR); \
686 #define DISABLE_IRQs {\
687 imr = inl(DE4X5_IMR);\
689 outl(imr, DE4X5_IMR); \
692 #define UNMASK_IRQs {\
693 imr |= lp->irq_mask;\
694 outl(imr, DE4X5_IMR); \
698 imr = inl(DE4X5_IMR);\
699 imr &= ~lp->irq_mask;\
700 outl(imr, DE4X5_IMR); \
706 #define START_DE4X5 {\
707 omr = inl(DE4X5_OMR);\
708 omr |= OMR_ST | OMR_SR;\
709 outl(omr, DE4X5_OMR); \
712 #define STOP_DE4X5 {\
713 omr = inl(DE4X5_OMR);\
714 omr &= ~(OMR_ST|OMR_SR);\
715 outl(omr, DE4X5_OMR); \
721 #define RESET_SIA outl(0, DE4X5_SICR);
726 #define DE4X5_AUTOSENSE_MS 250
743 #define SUB_VENDOR_ID 0x500a
753 #define NUM_RX_DESC 8
754 #define NUM_TX_DESC 32
755 #define RX_BUFF_SZ 1536
769 #define DE4X5_PKT_STAT_SZ 16
770 #define DE4X5_PKT_BIN_SZ 128
888 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
889 lp->tx_old+lp->txRingSize-lp->tx_new-1:\
890 lp->tx_old -lp->tx_new-1)
892 #define TX_PKT_PENDING (lp->tx_old != lp->tx_new)
928 static int dc21040_state(
struct net_device *dev,
int csr13,
int csr14,
int csr15,
int timeout,
int next_state,
int suspect_state,
int (*
fn)(
struct net_device *,
int));
931 static int wait_for_link(
struct net_device *dev);
933 static int is_spd_100(
struct net_device *dev);
936 static int is_anc_capable(
struct net_device *dev);
939 static void de4x5_free_rx_buffs(
struct net_device *dev);
940 static void de4x5_free_tx_buffs(
struct net_device *dev);
941 static void de4x5_save_skbs(
struct net_device *dev);
942 static void de4x5_rst_desc_ring(
struct net_device *dev);
947 static void de4x5_setup_intr(
struct net_device *dev);
948 static void de4x5_init_connection(
struct net_device *dev);
949 static int de4x5_reset_phy(
struct net_device *dev);
956 static void enet_addr_rst(
u_long aprom_addr);
966 static int srom_map_media(
struct net_device *dev);
967 static int srom_infoleaf_info(
struct net_device *dev);
968 static void srom_init(
struct net_device *dev);
972 static int mii_rdata(
u_long ioaddr);
975 static int mii_swap(
int data,
int len);
980 static int mii_get_phy(
struct net_device *dev);
981 static void SetMulticastFilter(
struct net_device *dev);
982 static int get_hw_addr(
struct net_device *dev);
987 static void disable_ast(
struct net_device *dev);
988 static long de4x5_switch_mac_port(
struct net_device *dev);
992 static void de4x5_parse_params(
struct net_device *dev);
993 static void de4x5_dbg_open(
struct net_device *dev);
994 static void de4x5_dbg_mii(
struct net_device *dev,
int k);
995 static void de4x5_dbg_media(
struct net_device *dev);
998 static int de4x5_strncmp(
char *
a,
char *
b,
int n);
999 static int dc21041_infoleaf(
struct net_device *dev);
1000 static int dc21140_infoleaf(
struct net_device *dev);
1001 static int dc21142_infoleaf(
struct net_device *dev);
1002 static int dc21143_infoleaf(
struct net_device *dev);
1027 MODULE_PARM_DESC(args,
"de4x5 full duplex and media type settings; see de4x5.c for details");
1037 static struct InfoLeaf infoleaf_array[] = {
1043 #define INFOLEAF_SIZE ARRAY_SIZE(infoleaf_array)
1058 #define COMPACT (ARRAY_SIZE(dc_infoblock) - 1)
1063 #define RESET_DE4X5 {\
1067 outl(i | BMR_SWR, DE4X5_BMR);\
1069 outl(i, DE4X5_BMR);\
1071 for (i=0;i<5;i++) {inl(DE4X5_BMR); mdelay(1);}\
1075 #define PHY_HARD_RESET {\
1076 outl(GEP_HRST, DE4X5_GEP); \
1078 outl(0x00, DE4X5_GEP);\
1083 .ndo_open = de4x5_open,
1084 .ndo_stop = de4x5_close,
1085 .ndo_start_xmit = de4x5_queue_pkt,
1086 .ndo_get_stats = de4x5_get_stats,
1087 .ndo_set_rx_mode = set_multicast_list,
1125 PCI_signature(name, lp);
1127 EISA_signature(name, gendev);
1130 if (*name ==
'\0') {
1135 printk (
"%s: %s at 0x%04lx", dev_name(gendev), name, iobase);
1137 status = get_hw_addr(dev);
1141 printk(
" which has an Ethernet PROM CRC error.\n");
1144 skb_queue_head_init(&lp->
cache.queue);
1155 de4x5_parse_params(dev);
1173 #if defined(__alpha__) || defined(__powerpc__) || defined(CONFIG_SPARC) || defined(DE4X5_DO_MEMCPY)
1188 #if !defined(__alpha__) && !defined(__powerpc__) && !defined(CONFIG_SPARC) && !defined(DE4X5_DO_MEMCPY)
1203 dma_rx_bufs = (dma_rx_bufs +
DE4X5_ALIGN) & ~DE4X5_ALIGN;
1237 create_packet(dev, lp->
frame,
sizeof(lp->
frame));
1240 i = lp->
cfrv & 0x000000fe;
1248 if (srom_infoleaf_info(dev)) {
1265 printk(
" and requires IRQ%d (provided by %s).\n", dev->
irq,
1266 ((lp->
bus ==
PCI) ?
"PCI BIOS" :
"EISA CNFG"));
1302 if (de4x5_alloc_rx_buff(dev, i, 0) ==
NULL) {
1303 de4x5_free_rx_buffs(dev);
1316 status = de4x5_init(dev);
1319 de4x5_dbg_open(dev);
1323 printk(
"de4x5_open(): Requested IRQ%d is busy - attemping FAST/SHARE...", dev->
irq);
1326 printk(
"\n Cannot get IRQ- reconfigure your hardware.\n");
1328 de4x5_free_rx_buffs(dev);
1329 de4x5_free_tx_buffs(dev);
1334 printk(
"\n Succeeded, but you should reconfigure your hardware to avoid this.\n");
1335 printk(
"WARNING: there may be IRQ related problems in heavily loaded systems.\n");
1344 de4x5_setup_intr(dev);
1372 netif_stop_queue(dev);
1374 de4x5_sw_reset(dev);
1377 autoconf_media(dev);
1387 int i,
j, status = 0;
1397 de4x5_switch_mac_port(dev);
1432 SetMulticastFilter(dev);
1439 for (j=0, i=0;(i<500) && (j==0);i++) {
1446 printk(
"%s: Setup frame timed out, status %08x\n", dev->
name,
1467 netif_stop_queue(dev);
1478 spin_unlock_irqrestore(&lp->
lock, flags);
1487 de4x5_putb_cache(dev, skb);
1489 de4x5_put_cache(dev, skb);
1494 }
else if (skb->
len > 0) {
1497 de4x5_put_cache(dev, skb);
1498 skb = de4x5_get_cache(dev);
1501 while (skb && !netif_queue_stopped(dev) &&
1504 netif_stop_queue(dev);
1512 netif_start_queue(dev);
1514 skb = de4x5_get_cache(dev);
1515 spin_unlock_irqrestore(&lp->
lock, flags);
1517 if (skb) de4x5_putb_cache(dev, skb);
1537 de4x5_interrupt(
int irq,
void *
dev_id)
1543 unsigned int handled = 0;
1545 lp = netdev_priv(dev);
1546 spin_lock(&lp->
lock);
1552 printk(
"%s: Re-entering the interrupt handler.\n", dev->
name);
1556 for (limit=0; limit<8; limit++) {
1579 printk(
"%s: Fatal bus error occurred, sts=%#8x, device stopped.\n",
1581 spin_unlock(&lp->
lock);
1588 while (!skb_queue_empty(&lp->
cache.queue) && !netif_queue_stopped(dev) && lp->
tx_enable) {
1589 de4x5_queue_pkt(de4x5_get_cache(dev), dev);
1596 spin_unlock(&lp->
lock);
1620 if (status &
RD_FS) {
1624 if (status &
RD_LS) {
1626 if (status &
RD_ES) {
1627 lp->
stats.rx_errors++;
1629 if (status &
RD_CE) lp->
stats.rx_crc_errors++;
1630 if (status &
RD_OF) lp->
stats.rx_fifo_errors++;
1631 if (status &
RD_TL) lp->
stats.rx_length_errors++;
1635 if (status & RD_OF) lp->
pktStats.rx_overflow++;
1641 if ((skb = de4x5_alloc_rx_buff(dev, entry, pkt_len)) ==
NULL) {
1642 printk(
"%s: Insufficient memory; nuking packet.\n",
1644 lp->
stats.rx_dropped++;
1646 de4x5_dbg_rx(skb, pkt_len);
1650 de4x5_local_stats(dev, skb->
data, pkt_len);
1654 lp->
stats.rx_packets++;
1703 }
else if (status != 0x7fffffff) {
1704 if (status &
TD_ES) {
1705 lp->
stats.tx_errors++;
1706 if (status &
TD_NC) lp->
stats.tx_carrier_errors++;
1707 if (status &
TD_LC) lp->
stats.tx_window_errors++;
1708 if (status &
TD_UF) lp->
stats.tx_fifo_errors++;
1710 if (status &
TD_DE) lp->
stats.tx_aborted_errors++;
1716 lp->
stats.tx_packets++;
1720 lp->
stats.collisions += ((status &
TD_EC) ? 16 :
1721 ((status &
TD_CC) >> 3));
1725 de4x5_free_tx_buff(lp, entry);
1735 netif_wake_queue(dev);
1737 netif_start_queue(dev);
1751 next_tick = srom_autoconf(dev);
1753 next_tick = dc21140m_autoconf(dev);
1755 next_tick = dc21041_autoconf(dev);
1757 next_tick = dc21040_autoconf(dev);
1760 dt = (next_tick *
HZ) / 1000;
1780 if ((omr &
OMR_TR) < OMR_TR) {
1821 netif_stop_queue(dev);
1824 printk(
"%s: Shutting down ethercard, status was %8.8x.\n",
1839 de4x5_free_rx_buffs(dev);
1840 de4x5_free_tx_buffs(dev);
1860 de4x5_local_stats(
struct net_device *dev,
char *
buf,
int pkt_len)
1871 if (is_multicast_ether_addr(buf)) {
1872 if (is_broadcast_ether_addr(buf)) {
1877 }
else if (ether_addr_equal(buf, dev->
dev_addr)) {
1930 SetMulticastFilter(dev);
1956 unsigned char *addrs;
1960 pa = build_setup_frame(dev,
ALL);
1969 byte = hashcode >> 3;
1970 bit = 1 << (hashcode & 0x07);
1982 *(pa + (i&1)) = *addrs++;
1983 if (i & 0x01) pa += 4;
1994 static int __init de4x5_eisa_probe (
struct device *gendev)
2017 if (!(dev = alloc_etherdev (
sizeof (
struct de4x5_private)))) {
2021 lp = netdev_priv(dev);
2025 device = (cfid >> 8) & 0x00ffff00;
2050 irq = de4x5_irq[(regval >> 1) & 0x03];
2067 if (!(status = de4x5_hw_init (dev, iobase, gendev))) {
2080 static int __devexit de4x5_eisa_remove (
struct device *device)
2106 .probe = de4x5_eisa_probe,
2126 u_int irq = 0, device;
2133 vendor = this_dev->
vendor;
2134 device = this_dev->
device << 8;
2138 pb = this_dev->
bus->number;
2155 irq = this_dev->
irq;
2156 if ((irq == 0) || (irq == 0xff) || ((
int)irq == -1))
continue;
2159 pci_read_config_word(this_dev,
PCI_COMMAND, &status);
2167 if (j != 0 && j != 6 * 0xff) {
2198 u_char pb, pbus = 0, dev_num, dnum = 0,
timer;
2207 pb = pdev->
bus->number;
2212 if ((pbus != pb) || (dnum != dev_num))
2217 device = pdev->
device << 8;
2225 if (!(dev = alloc_etherdev (
sizeof (
struct de4x5_private)))) {
2230 lp = netdev_priv(dev);
2237 srom_search(dev, pdev);
2258 if ((irq == 0) || (irq == 0xff) || ((
int)irq == -1)) {
2266 if (!(status & PCI_COMMAND_IO)) {
2272 if (!(status & PCI_COMMAND_IO)) {
2282 if (!(status & PCI_COMMAND_MASTER)) {
2302 if ((error = de4x5_hw_init(dev, iobase, &pdev->
dev))) {
2343 static struct pci_driver de4x5_pci_driver = {
2345 .id_table = de4x5_pci_tbl,
2346 .probe = de4x5_pci_probe,
2397 switch (lp->
media) {
2402 de4x5_save_skbs(dev);
2413 next_tick = dc21040_autoconf(dev);
2417 next_tick = dc21040_state(dev, 0x8f01, 0xffff, 0x0000, 3000,
BNC_AUI,
2422 next_tick = de4x5_suspect_state(dev, 1000,
TP, test_tp, dc21040_autoconf);
2428 next_tick = dc21040_state(dev, 0x8f09, 0x0705, 0x0006, 3000,
EXT_SIA,
2433 next_tick = de4x5_suspect_state(dev, 1000,
BNC_AUI, ping_media, dc21040_autoconf);
2437 next_tick = dc21040_state(dev, 0x3041, 0x0000, 0x0006, 3000,
2442 next_tick = de4x5_suspect_state(dev, 1000,
EXT_SIA, ping_media, dc21040_autoconf);
2447 reset_init_sia(dev, 0x8f01, 0xffff, 0x0000);
2449 de4x5_dbg_media(dev);
2461 dc21040_state(
struct net_device *dev,
int csr13,
int csr14,
int csr15,
int timeout,
2462 int next_state,
int suspect_state,
2471 reset_init_sia(dev, csr13, csr14, csr15);
2478 linkBad =
fn(dev, timeout);
2486 de4x5_init_connection(dev);
2490 lp->
media = suspect_state;
2500 de4x5_suspect_state(
struct net_device *dev,
int timeout,
int prev_state,
2514 next_tick = asfn(dev);
2519 linkBad =
fn(dev, timeout);
2522 }
else if (!linkBad) {
2551 switch (lp->
media) {
2556 de4x5_save_skbs(dev);
2569 next_tick = dc21041_autoconf(dev);
2579 sts = test_media(dev, irqs, irq_mask, 0xef01, 0xffff, 0x0008, 2400);
2588 next_tick = dc21041_autoconf(dev);
2596 sts = test_ans(dev, irqs, irq_mask, 3000);
2602 next_tick = dc21041_autoconf(dev);
2605 de4x5_init_connection(dev);
2615 next_tick = de4x5_suspect_state(dev, 1000,
ANS, test_tp, dc21041_autoconf);
2626 sts = test_media(dev,irqs, irq_mask, 0xef01, 0xff3f, 0x0008, 2400);
2636 next_tick = dc21041_autoconf(dev);
2639 de4x5_init_connection(dev);
2649 next_tick = de4x5_suspect_state(dev, 1000,
TP, test_tp, dc21041_autoconf);
2660 sts = test_media(dev,irqs, irq_mask, 0xef09, 0xf73d, 0x000e, 1000);
2666 next_tick = dc21041_autoconf(dev);
2669 de4x5_init_connection(dev);
2679 next_tick = de4x5_suspect_state(dev, 1000,
AUI, ping_media, dc21041_autoconf);
2691 sts = test_media(dev,irqs, irq_mask, 0xef09, 0xf73d, 0x0006, 1000);
2696 next_tick = dc21041_autoconf(dev);
2702 if ((sts = ping_media(dev, 3000)) < 0) {
2709 de4x5_init_connection(dev);
2721 next_tick = de4x5_suspect_state(dev, 1000,
BNC, ping_media, dc21041_autoconf);
2727 reset_init_sia(dev, 0xef01, 0xffff, 0x0008);
2729 de4x5_dbg_media(dev);
2749 int ana, anlpa,
cap,
cr, slnk,
sr;
2759 de4x5_save_skbs(dev);
2761 if ((next_tick = de4x5_reset_phy(dev)) < 0) {
2765 if (srom_map_media(dev) < 0) {
2769 srom_exec(dev, lp->
phy[lp->
active].gep);
2789 }
else if (is_spd_100(dev) && is_100_up(dev)) {
2796 next_tick = dc21140m_autoconf(dev);
2816 next_tick = dc21140m_autoconf(dev);
2842 next_tick = dc21140m_autoconf(dev);
2854 if ((slnk = test_for_100Mb(dev, 6500)) < 0) {
2857 if (is_spd_100(dev) && is_100_up(dev)) {
2859 }
else if ((!is_spd_100(dev) && (is_10_up(dev) & lp->
tmp))) {
2864 next_tick = dc21140m_autoconf(dev);
2872 de4x5_init_connection(dev);
2875 if (!is_100_up(dev) || (!lp->
useSROM && !is_spd_100(dev))) {
2890 de4x5_init_connection(dev);
2893 if (!is_10_up(dev) || (!lp->
useSROM && is_spd_100(dev))) {
2904 de4x5_dbg_media(dev);
2934 s32 cr, anlpa, ana,
cap, irqs,
irq_mask,
imr, omr, slnk,
sr,
sts;
2937 switch (lp->
media) {
2944 de4x5_save_skbs(dev);
2946 srom_map_media(dev);
2955 if ((next_tick = de4x5_reset_phy(dev)) < 0) {
2971 ((sr=is_anc_capable(dev)) & MII_SR_ANC)) {
2979 next_tick = dc2114x_autoconf(dev);
2999 next_tick = dc2114x_autoconf(dev);
3014 if (!(anlpa & MII_ANLPA_RF) &&
3025 next_tick = dc2114x_autoconf(dev);
3039 sts = test_media(dev,irqs, irq_mask, 0, 0, 0, 1000);
3045 next_tick = dc2114x_autoconf(dev);
3048 de4x5_init_connection(dev);
3058 next_tick = de4x5_suspect_state(dev, 1000,
AUI, ping_media, dc2114x_autoconf);
3070 sts = test_media(dev,irqs, irq_mask, 0, 0, 0, 1000);
3075 next_tick = dc2114x_autoconf(dev);
3081 if ((sts = ping_media(dev, 3000)) < 0) {
3089 de4x5_init_connection(dev);
3101 next_tick = de4x5_suspect_state(dev, 1000,
BNC, ping_media, dc2114x_autoconf);
3105 if (srom_map_media(dev) < 0) {
3111 if ((slnk = test_for_100Mb(dev, 6500)) < 0) {
3116 if (wait_for_link(dev) < 0) {
3122 if (is_spd_100(dev)) {
3127 next_tick = dc2114x_autoconf(dev);
3128 }
else if (((lp->
media ==
_100Mb) && is_100_up(dev)) ||
3132 next_tick = dc2114x_autoconf(dev);
3143 de4x5_init_connection(dev);
3146 if (!is_10_up(dev) || (!lp->
useSROM && is_spd_100(dev))) {
3159 de4x5_init_connection(dev);
3162 if (!is_100_up(dev) || (!lp->
useSROM && !is_spd_100(dev))) {
3205 if (!lp->
params.fdx)
return -1;
3208 if (lp->
params.fdx && !lp->
fdx)
return -1;
3225 if (!lp->
params.fdx)
return -1;
3228 if (lp->
params.fdx && !lp->
fdx)
return -1;
3237 if (!lp->
params.fdx)
return -1;
3240 if (lp->
params.fdx && !lp->
fdx)
return -1;
3250 printk(
"%s: Bad media code [%d] detected in SROM!\n", dev->
name,
3260 de4x5_init_connection(
struct net_device *dev)
3267 de4x5_dbg_media(dev);
3272 de4x5_rst_desc_ring(dev);
3273 de4x5_setup_intr(dev);
3275 spin_unlock_irqrestore(&lp->
lock, flags);
3278 netif_wake_queue(dev);
3297 srom_exec(dev, lp->
phy[lp->
active].rst);
3298 srom_exec(dev, lp->
phy[lp->
active].rst);
3299 }
else if (lp->
rst) {
3300 srom_exec(dev, lp->
rst);
3301 srom_exec(dev, lp->
rst);
3330 reset_init_sia(dev, csr13, csr14, csr15);
3349 if (!(sts & irqs) && --lp->
timeout) {
3385 #define SAMPLE_INTERVAL 500
3386 #define SAMPLE_DELAY 2000
3388 test_for_100Mb(
struct net_device *dev,
int msec)
3405 gep = is_100_up(dev) | is_spd_100(dev);
3452 test = (reg ^ (pol ? ~0 : 0)) &
mask;
3472 spd = ~(spd ^ lp->
phy[lp->
active].spd.value);
3519 return (~gep_rd(dev)) &
GEP_LNP;
3573 if ((!(sisr & SISR_NCR)) &&
3597 #if !defined(__alpha__) && !defined(__powerpc__) && !defined(CONFIG_SPARC) && !defined(DE4X5_DO_MEMCPY)
3601 p = netdev_alloc_skb(dev,
IEEE802_3_SZ + DE4X5_ALIGN + 2);
3602 if (!p)
return NULL;
3621 p = netdev_alloc_skb(dev, len + 2);
3622 if (!p)
return NULL;
3625 if (index < lp->rx_old) {
3645 dev_kfree_skb(lp->
rx_skb[i]);
3660 de4x5_free_tx_buff(lp, i);
3665 __skb_queue_purge(&lp->
cache.queue);
3682 if (!lp->
cache.save_cnt) {
3685 de4x5_free_tx_buffs(dev);
3687 de4x5_sw_reset(dev);
3689 lp->
cache.save_cnt++;
3702 if (lp->
cache.save_cnt) {
3720 lp->
cache.save_cnt--;
3743 gep_wr(lp->
cache.gepc, dev);
3744 gep_wr(lp->
cache.gep, dev);
3746 reset_init_sia(dev, lp->
cache.csr13, lp->
cache.csr14,
3758 __skb_queue_tail(&lp->
cache.queue, skb);
3766 __skb_queue_head(&lp->
cache.queue, skb);
3774 return __skb_dequeue(&lp->
cache.queue);
3837 srom_exec(dev, lp->
phy[lp->
active].rst);
3838 srom_exec(dev, lp->
phy[lp->
active].gep);
3842 csr15 = lp->
cache.csr15;
3843 csr14 = lp->
cache.csr14;
3844 csr13 = lp->
cache.csr13;
3881 EISA_signature(
char *name,
struct device *device)
3883 int i, status = 0, siglen =
ARRAY_SIZE(de4x5_signatures);
3888 i = edev->
id.driver_data;
3890 if (i >= 0 && i < siglen) {
3891 strcpy (name, de4x5_signatures[i]);
3904 int i, status = 0, siglen =
ARRAY_SIZE(de4x5_signatures);
3910 int tmp = *((
char *)&lp->
srom + 19) * 3;
3914 for (i=0; i<siglen; i++) {
3915 if (
strstr(name,de4x5_signatures[i])!=
NULL)
break;
3954 enet_addr_rst(aprom_addr);
3956 outl(0, aprom_addr);
3961 for (i=0; i<(ETH_ALEN>>1); i++) {
3962 tmp = srom_rd(aprom_addr, (
SROM_HWADD>>1) + i);
3966 if (j == 0 || j == 3 * 0xffff) {
3972 for (i=0; i<(sizeof(struct de4x5_srom)>>1); i++) {
3973 tmp = srom_rd(aprom_addr, i);
3976 de4x5_dbg_srom(&lp->
srom);
3986 enet_addr_rst(
u_long aprom_addr)
3993 char Sig[
sizeof(
u32) << 1];
4001 sigLength =
sizeof(
u32) << 1;
4003 for (i=0,j=0;j<sigLength && i<
PROBE_LENGTH+sigLength-1;i++) {
4004 data =
inb(aprom_addr);
4005 if (dev.Sig[j] == data) {
4008 if (data == dev.Sig[0]) {
4027 int broken,
i,
k,
tmp, status = 0;
4031 broken = de4x5_bad_srom(lp);
4033 for (i=0,k=0,j=0;j<3;j++) {
4035 if (k > 0xffff) k-=0xffff;
4045 }
else if (!broken) {
4048 }
else if ((broken ==
SMC) || (broken ==
ACCTON)) {
4059 if (k > 0xffff) k-=0xffff;
4061 if (k == 0xffff) k=0;
4068 chksum |= (
u_short) (tmp << 8);
4069 if ((k != chksum) && (dec_only)) status = -1;
4074 if ((k != chksum) && (dec_only)) status = -1;
4078 srom_repair(dev, broken);
4080 #ifdef CONFIG_PPC_PMAC
4085 if ( machine_is(powermac) &&
4092 x = ((x & 0xf) << 4) + ((x & 0xf0) >> 4);
4093 x = ((x & 0x33) << 2) + ((x & 0xcc) >> 2);
4094 dev->
dev_addr[
i] = ((x & 0x55) << 1) + ((x & 0xaa) >> 1);
4100 status = test_bad_enet(dev, status);
4115 if (!de4x5_strncmp((
char *)&lp->
srom, (
char *)&enet_det[i], 3) &&
4116 !de4x5_strncmp((
char *)&lp->
srom+0x10, (
char *)&enet_det[i], 3)) {
4119 }
else if (i == 1) {
4130 de4x5_strncmp(
char *
a,
char *
b,
int n)
4134 for (;n && !
ret; n--) {
4150 memcpy(lp->
srom.info, (
char *)&srom_repair_info[
SMC-1], 100);
4161 test_bad_enet(
struct net_device *dev,
int status)
4167 if ((tmp == 0) || (tmp == 0x5fa)) {
4168 if ((lp->
chipset == last.chipset) &&
4171 for (i=ETH_ALEN-1; i>2; --
i) {
4176 if (!an_exception(lp)) {
4177 dev->
irq = last.irq;
4182 }
else if (!status) {
4185 last.irq = dev->
irq;
4198 if ((*(
u_short *)lp->
srom.sub_vendor_id == 0x00c0) &&
4224 sendto_srom(command, addr);
4225 sendto_srom(command |
DT_CLK, addr);
4226 sendto_srom(command, addr);
4232 srom_latch(command, addr);
4233 srom_latch(command, addr);
4234 srom_latch((command & 0x0000ff00) |
DT_CS, addr);
4243 for (i=0; i<6; i++, a <<= 1) {
4244 srom_latch(command | ((a & 0x80) ?
DT_IN : 0), addr);
4248 i = (getfrom_srom(addr) >> 3) & 0x01;
4258 for (i=0; i<16; i++) {
4259 sendto_srom(command |
DT_CLK, addr);
4260 tmp = getfrom_srom(addr);
4261 sendto_srom(command, addr);
4266 sendto_srom(command & 0x0000ff00, addr);
4288 outl(command, addr);
4293 getfrom_srom(
u_long addr)
4314 if (i == INFOLEAF_SIZE) {
4316 printk(
"%s: Cannot find correct chipset for SROM decoding!\n",
4324 count = *((u_char *)&lp->
srom + 19);
4325 p = (u_char *)&lp->
srom + 26;
4328 for (i=count;
i; --
i, p+=3) {
4329 if (lp->
device == *p)
break;
4333 printk(
"%s: Cannot find correct PCI device [%d] for SROM decoding!\n",
4361 gep_wr(lp->
cache.gepc, dev);
4371 }
else if (*(p+1) == 5) {
4372 type5_infoblock(dev, 1, p);
4374 }
else if (*(p+1) == 4) {
4376 }
else if (*(p+1) == 3) {
4377 type3_infoblock(dev, 1, p);
4379 }
else if (*(p+1) == 2) {
4381 }
else if (*(p+1) == 1) {
4382 type1_infoblock(dev, 1, p);
4399 u_char count = (p ? *p++ : 0);
4402 if (((lp->
ibn != 1) && (lp->
ibn != 3) && (lp->
ibn != 5)) || !count)
return;
4408 *p++ : get_unaligned_le16(w++)), dev);
4450 next_tick = dc_infoblock[*(p+1)](dev, count, p);
4453 if (lp->
tcount == count) {
4456 de4x5_dbg_media(dev);
4485 next_tick = dc_infoblock[*(p+1)](dev, count, p);
4488 if (lp->
tcount == count) {
4491 de4x5_dbg_media(dev);
4520 next_tick = dc_infoblock[*(p+1)](dev, count, p);
4522 if (lp->
tcount == count) {
4525 de4x5_dbg_media(dev);
4541 compact_infoblock(
struct net_device *dev, u_char count, u_char *p)
4547 if (--count > lp->
tcount) {
4558 gep_wr(lp->
cache.gepc, dev);
4560 lp->
cache.gep = *p++;
4565 lp->
defMedium = (flags & 0x40) ? -1 : 0;
4566 lp->
asBit = 1 << ((csr6 >> 1) & 0x07);
4571 de4x5_switch_mac_port(dev);
4574 return dc21140m_autoconf(dev);
4581 type0_infoblock(
struct net_device *dev, u_char count, u_char *p)
4587 if (--count > lp->
tcount) {
4588 if (*(p+len) < 128) {
4591 return dc_infoblock[*(p+len+1)](dev, count, p+len);
4598 gep_wr(lp->
cache.gepc, dev);
4601 lp->
cache.gep = *p++;
4606 lp->
defMedium = (flags & 0x40) ? -1 : 0;
4607 lp->
asBit = 1 << ((csr6 >> 1) & 0x07);
4612 de4x5_switch_mac_port(dev);
4615 return dc21140m_autoconf(dev);
4621 type1_infoblock(
struct net_device *dev, u_char count, u_char *p)
4627 if (--count > lp->
tcount) {
4628 if (*(p+len) < 128) {
4631 return dc_infoblock[*(p+len+1)](dev, count, p+len);
4641 lp->
phy[lp->
active].mc = get_unaligned_le16(p); p += 2;
4642 lp->
phy[lp->
active].ana = get_unaligned_le16(p); p += 2;
4643 lp->
phy[lp->
active].fdx = get_unaligned_le16(p); p += 2;
4644 lp->
phy[lp->
active].ttm = get_unaligned_le16(p);
4653 de4x5_switch_mac_port(dev);
4656 return dc21140m_autoconf(dev);
4660 type2_infoblock(
struct net_device *dev, u_char count, u_char *p)
4666 if (--count > lp->
tcount) {
4667 if (*(p+len) < 128) {
4670 return dc_infoblock[*(p+len+1)](dev, count, p+len);
4681 lp->
cache.csr13 = get_unaligned_le16(p); p += 2;
4682 lp->
cache.csr14 = get_unaligned_le16(p); p += 2;
4683 lp->
cache.csr15 = get_unaligned_le16(p); p += 2;
4689 lp->
cache.gepc = ((
s32)(get_unaligned_le16(p)) << 16); p += 2;
4690 lp->
cache.gep = ((
s32)(get_unaligned_le16(p)) << 16);
4694 de4x5_switch_mac_port(dev);
4697 return dc2114x_autoconf(dev);
4701 type3_infoblock(
struct net_device *dev, u_char count, u_char *p)
4707 if (--count > lp->
tcount) {
4708 if (*(p+len) < 128) {
4711 return dc_infoblock[*(p+len+1)](dev, count, p+len);
4720 lp->
phy[lp->
active].gep = (*p ? p :
NULL); p += (2 * (*p) + 1);
4721 lp->
phy[lp->
active].rst = (*p ? p :
NULL); p += (2 * (*p) + 1);
4722 lp->
phy[lp->
active].mc = get_unaligned_le16(p); p += 2;
4723 lp->
phy[lp->
active].ana = get_unaligned_le16(p); p += 2;
4724 lp->
phy[lp->
active].fdx = get_unaligned_le16(p); p += 2;
4725 lp->
phy[lp->
active].ttm = get_unaligned_le16(p); p += 2;
4736 de4x5_switch_mac_port(dev);
4739 return dc2114x_autoconf(dev);
4743 type4_infoblock(
struct net_device *dev, u_char count, u_char *p)
4749 if (--count > lp->
tcount) {
4750 if (*(p+len) < 128) {
4753 return dc_infoblock[*(p+len+1)](dev, count, p+len);
4765 lp->
cache.gepc = ((
s32)(get_unaligned_le16(p)) << 16); p += 2;
4766 lp->
cache.gep = ((
s32)(get_unaligned_le16(p)) << 16); p += 2;
4771 lp->
defMedium = (flags & 0x40) ? -1 : 0;
4772 lp->
asBit = 1 << ((csr6 >> 1) & 0x07);
4777 de4x5_switch_mac_port(dev);
4780 return dc2114x_autoconf(dev);
4788 type5_infoblock(
struct net_device *dev, u_char count, u_char *p)
4794 if (--count > lp->
tcount) {
4795 if (*(p+len) < 128) {
4798 return dc_infoblock[*(p+len+1)](dev, count, p+len);
4806 srom_exec(dev, lp->
rst);
4822 mii_address(phyaddr, ioaddr);
4823 mii_address(phyreg, ioaddr);
4826 return mii_rdata(ioaddr);
4830 mii_wr(
int data, u_char phyreg, u_char
phyaddr,
u_long ioaddr)
4835 mii_address(phyaddr, ioaddr);
4836 mii_address(phyreg, ioaddr);
4838 data = mii_swap(data, 16);
4839 mii_wdata(data, 16, ioaddr);
4848 for (i=0; i<16; i++) {
4857 mii_wdata(
int data,
int len,
u_long ioaddr)
4861 for (i=0; i<len; i++) {
4868 mii_address(u_char addr,
u_long ioaddr)
4872 addr = mii_swap(addr, 5);
4873 for (i=0; i<5; i++) {
4891 mii_swap(
int data,
int len)
4895 for (i=0; i<len; i++) {
4905 sendto_mii(
u32 command,
int data,
u_long ioaddr)
4909 j = (data & 1) << 17;
4910 outl(command | j, ioaddr);
4919 outl(command, ioaddr);
4924 return (
inl(ioaddr) >> 19) & 1;
4942 r2 = mii_rd(
MII_ID0, phyaddr, ioaddr);
4943 r3 = mii_rd(
MII_ID1, phyaddr, ioaddr);
4992 while (de4x5_reset_phy(dev)<0)
udelay(100);
4994 if ((
id == 0) || (
id == 65535))
continue;
4995 for (j=0; j<
limit; j++) {
4996 if (
id != phy_info[j].
id)
continue;
5000 (
char *)&phy_info[j],
sizeof(
struct phy_table));
5001 lp->
phy[
k].addr =
i;
5011 lp->
phy[
k].addr =
i;
5018 printk(
"%s: Using generic MII device control. If the board doesn't operate,\nplease mail the following dump to the author:\n", dev->
name);
5021 de4x5_dbg_mii(dev, k);
5028 if (lp->
phy[0].id) {
5033 de4x5_dbg_mii(dev, k);
5056 if (i & 0x01) pa += 2;
5062 if (i & 0x01) pa += 4;
5065 *(pa + (i&1)) = (
char) 0xff;
5066 if (i & 0x01) pa += 4;
5081 de4x5_switch_mac_port(
struct net_device *dev)
5101 gep_wr(lp->
cache.gepc, dev);
5102 gep_wr(lp->
cache.gep, dev);
5104 reset_init_sia(dev, lp->
cache.csr13, lp->
cache.csr14, lp->
cache.csr15);
5197 if (args ==
NULL)
return;
5206 if (
strstr(p,
"autosense") ||
strstr(p,
"AUTOSENSE")) {
5209 }
else if (
strstr(p,
"TP_NW")) {
5211 }
else if (
strstr(p,
"BNC")) {
5213 }
else if (
strstr(p,
"AUI")) {
5215 }
else if (
strstr(p,
"BNC_AUI")) {
5217 }
else if (
strstr(p,
"10Mb")) {
5219 }
else if (
strstr(p,
"100Mb")) {
5221 }
else if (
strstr(p,
"AUTO")) {
5235 if (de4x5_debug & DEBUG_OPEN) {
5236 printk(
"%s: de4x5 opening with irq %d\n",dev->
name,dev->
irq);
5238 printk(
"Descriptor head addresses:\n");
5240 printk(
"Descriptor addresses:\nRX: ");
5254 printk(
"Descriptor buffers:\nRX: ");
5268 printk(
"Ring size:\nRX: %d\nTX: %d\n",
5281 printk(
"\nMII device address: %d\n", lp->
phy[k].addr);
5308 (lp->
media ==
NC ?
"unconnected, link down or incompatible connection" :
5318 ))))))))), (lp->
fdx?
" full duplex.":
"."));
5338 for (i=0; i<64; i++) {
5345 de4x5_dbg_rx(
struct sk_buff *skb,
int len)
5350 printk(
"R: %pM <- %pM len/SAP:%02x%02x [%d]\n",
5352 (u_char)skb->
data[12],
5353 (u_char)skb->
data[13],
5355 for (j=0; len>0;j+=16, len-=16) {
5357 for (i=0; i<16 && i<len; i++) {
5376 int i, j, status = 0;
5397 if (netif_queue_stopped(dev))
5399 netif_stop_queue(dev);
5409 netif_wake_queue(dev);
5427 ioc->len =
sizeof(statbuf);
5430 spin_unlock_irqrestore(&lp->
lock, flags);
5439 spin_unlock_irqrestore(&lp->
lock, flags);
5468 #define DE4X5_DUMP 0x0f
5565 static int __init de4x5_module_init (
void)
5570 err = pci_register_driver(&de4x5_pci_driver);
5579 static void __exit de4x5_module_exit (
void)