32 #ifndef CONFIG_ISA_DMA_API
49 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
51 #include <linux/module.h>
53 #include <linux/errno.h>
54 #include <linux/netdevice.h>
57 #include <linux/kernel.h>
58 #include <linux/types.h>
59 #include <linux/fcntl.h>
65 #include <linux/string.h>
67 #include <linux/bitops.h>
80 #define cs89_dbg(val, level, fmt, ...) \
82 if (val <= net_debug) \
83 pr_##level(fmt, ##__VA_ARGS__); \
89 #define DRV_NAME "cs89x0"
104 #if defined(CONFIG_MACH_IXDP2351)
105 #define CS89x0_NONISA_IRQ
107 IXDP2351_VIRT_CS8900_BASE, 0
109 static unsigned int cs8900_irq_map[] = {
110 IRQ_IXDP2351_CS8900, 0, 0, 0
112 #elif defined(CONFIG_ARCH_IXDP2X01)
113 #define CS89x0_NONISA_IRQ
115 IXDP2X01_CS8900_VIRT_BASE, 0
117 static unsigned int cs8900_irq_map[] = {
118 IRQ_IXDP2X01_CS8900, 0, 0, 0
121 #ifndef CONFIG_CS89x0_PLATFORM
123 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240,
124 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0
126 static unsigned int cs8900_irq_map[] = {
139 #define NETCARD_IO_EXTENT 16
142 #define FORCE_RJ45 0x0001
143 #define FORCE_AUI 0x0002
144 #define FORCE_BNC 0x0004
146 #define FORCE_AUTO 0x0010
147 #define FORCE_HALF 0x0020
148 #define FORCE_FULL 0x0030
171 unsigned char *dma_buff;
172 unsigned char *end_dma_buff;
173 unsigned char *rx_dma_ptr;
178 #define tx_done(dev) 1
185 static int g_cs89x0_dma;
193 __setup(
"cs89x0_dma=", dma_fn);
196 static int g_cs89x0_media__force;
202 else if (!
strcmp(str,
"aui"))
204 else if (!
strcmp(str,
"bnc"))
210 __setup(
"cs89x0_media=", media_fn);
213 #if defined(CONFIG_MACH_IXDP2351)
215 readword(
unsigned long base_addr,
int portno)
221 writeword(
unsigned long base_addr,
int portno,
u16 value)
225 #elif defined(CONFIG_ARCH_IXDP2X01)
227 readword(
unsigned long base_addr,
int portno)
233 writeword(
unsigned long base_addr,
int portno,
u16 value)
241 u8 *buf8 = (
u8 *)buf;
248 *buf8++ = (
u8)(tmp16 >> 8);
252 static void writewords(
struct net_local *lp,
int portno,
void *buf,
int length)
254 u8 *buf8 = (
u8 *)buf;
260 tmp16 |= (*buf8++) << 8;
292 if (jiffies - timeout >= 40)
302 cs89_dbg(3,
info,
"EEPROM data from %x for %x:", off, len);
303 for (i = 0; i < len; i++) {
304 if (wait_eeprom_ready(dev) < 0)
308 if (wait_eeprom_ready(dev) < 0)
318 get_eeprom_cksum(
int off,
int len,
int *buffer)
323 for (i = 0; i < len; i++)
336 if (chip_type ==
CS8900) {
337 #ifndef CONFIG_CS89x0_PLATFORM
339 for (i = 0; i !=
ARRAY_SIZE(cs8900_irq_map); i++)
340 if (cs8900_irq_map[i] == irq)
358 dev->
stats.rx_errors++;
360 dev->
stats.rx_length_errors++;
362 dev->
stats.rx_length_errors++;
363 if ((status &
RX_CRC_ERROR) && !(status & (RX_EXTRA_DATA | RX_RUNT)))
365 dev->
stats.rx_crc_errors++;
367 dev->
stats.rx_frame_errors++;
376 #define dma_page_eq(ptr1, ptr2) ((long)(ptr1) >> 17 == (long)(ptr2) >> 17)
392 if (dev->
dma < 5 || dev->
dma > 7) {
451 if (lp->dmasize == 64)
464 unsigned char *bp = lp->rx_dma_ptr;
466 status = bp[0] + (bp[1] << 8);
467 length = bp[2] + (bp[3] << 8);
470 cs89_dbg(5,
debug,
"%s: receiving DMA packet at %lx, status %x, length %x\n",
471 dev->
name, (
unsigned long)bp, status, length);
473 if ((status &
RX_OK) == 0) {
474 count_rx_errors(status, dev);
475 goto skip_this_frame;
479 skb = netdev_alloc_skb(dev, length + 2);
482 cs89_dbg(0,
err,
"%s: Memory squeeze, dropping packet\n",
484 dev->
stats.rx_dropped++;
488 bp += (length + 3) & ~3;
489 if (bp >= lp->end_dma_buff)
490 bp -= lp->dmasize * 1024;
496 if (bp + length > lp->end_dma_buff) {
497 int semi_cnt = lp->end_dma_buff - bp;
504 bp += (length + 3) & ~3;
505 if (bp >= lp->end_dma_buff)
506 bp -= lp->dmasize*1024;
509 cs89_dbg(3,
info,
"%s: received %d byte DMA packet of type %x\n",
516 dev->
stats.rx_packets++;
520 static void release_dma_buff(
struct net_local *lp)
532 control_dc_dc(
struct net_device *dev,
int on_not_off)
535 unsigned int selfcontrol;
546 selfcontrol &= ~
HCB1;
550 while (jiffies - timenow <
HZ)
559 char test_packet[] = {
560 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
576 while (jiffies - timenow < 5)
579 if (jiffies - timenow >= 5)
587 for (timenow = jiffies;
jiffies - timenow < 3;)
597 #define DETECTED_NONE 0
598 #define DETECTED_RJ45H 1
599 #define DETECTED_RJ45F 2
600 #define DETECTED_AUI 3
601 #define DETECTED_BNC 4
620 control_dc_dc(dev, 0);
631 switch (lp->
force & 0xf0) {
634 pr_info(
"%s: cs8900 doesn't autonegotiate\n",
652 switch (lp->
force & 0xf0) {
669 if (
jiffies - timenow > 4000) {
670 pr_err(
"**** Full / half duplex auto-negotiation timed out ****\n");
689 control_dc_dc(dev, 1);
693 if (send_test_pkt(dev))
705 control_dc_dc(dev, 0);
709 if (send_test_pkt(dev))
726 if ((status & RX_OK) == 0) {
727 count_rx_errors(status, dev);
732 skb = netdev_alloc_skb(dev, length + 2);
735 pr_warn(
"%s: Memory squeeze, dropping packet\n", dev->
name);
737 dev->
stats.rx_dropped++;
746 cs89_dbg(3,
debug,
"%s: received %d byte packet of type %x\n",
753 dev->
stats.rx_packets++;
768 lp = netdev_priv(dev);
787 dev->
stats.tx_packets++;
788 netif_wake_queue(dev);
789 if ((status & (
TX_OK |
794 if ((status &
TX_OK) == 0)
795 dev->
stats.tx_errors++;
797 dev->
stats.tx_carrier_errors++;
799 dev->
stats.tx_heartbeat_errors++;
801 dev->
stats.tx_window_errors++;
803 dev->
stats.tx_aborted_errors++;
814 netif_wake_queue(dev);
830 netif_wake_queue(dev);
833 if (lp->use_dma && (status &
RX_DMA)) {
837 "%s: receiving %d DMA frames\n",
841 "%s: receiving %d DMA frames\n",
848 "%s: continuing with %d DMA frames\n",
855 dev->
stats.rx_missed_errors += (status >> 6);
858 dev->
stats.collisions += (status >> 6);
904 if (i >= CS8920_NO_INTS) {
906 pr_err(
"can't get an interrupt\n");
911 #if !defined(CS89x0_NONISA_IRQ) && !defined(CONFIG_CS89x0_PLATFORM)
913 pr_err(
"%s: IRQ %d is not in our map of allowable IRQs, which is %x\n",
928 pr_err(
"request_irq(%d) failed\n", dev->
irq);
939 pr_err(
"%s: cannot get %dK memory for DMA\n",
940 dev->
name, lp->dmasize);
945 (
unsigned long)lp->dma_buff,
946 (
unsigned long)isa_virt_to_bus(lp->dma_buff));
949 lp->dma_buff + lp->dmasize * 1024 - 1)) {
950 pr_err(
"%s: not usable as DMA buffer\n", dev->
name);
953 memset(lp->dma_buff, 0, lp->dmasize * 1024);
955 pr_err(
"%s: cannot get dma channel %d\n",
960 lp->rx_dma_ptr = lp->dma_buff;
961 lp->end_dma_buff = lp->dma_buff + lp->dmasize * 1024;
964 clear_dma_ff(dev->
dma);
966 set_dma_addr(dev->
dma, isa_virt_to_bus(lp->dma_buff));
969 spin_unlock_irqrestore(&lp->
lock, flags);
1006 pr_err(
"%s: EEPROM is configured for unavailable media\n",
1012 release_dma_buff(lp);
1024 result = detect_tp(dev);
1026 pr_warn(
"%s: 10Base-T (RJ-45) has no cable\n",
1033 result = detect_aui(dev);
1035 pr_warn(
"%s: 10Base-5 (AUI) has no cable\n", dev->
name);
1041 result = detect_bnc(dev);
1043 pr_warn(
"%s: 10Base-2 (BNC) has no cable\n", dev->
name);
1051 result = detect_tp(dev);
1056 result = detect_aui(dev);
1061 result = detect_bnc(dev);
1065 pr_err(
"%s: no media detected\n", dev->
name);
1070 pr_err(
"%s: no network cable attached to configured media\n",
1074 pr_info(
"%s: using half-duplex 10Base-T (RJ-45)\n", dev->
name);
1077 pr_info(
"%s: using full-duplex 10Base-T (RJ-45)\n", dev->
name);
1127 netif_start_queue(dev);
1139 struct net_local *lp = netdev_priv(dev);
1142 netif_stop_queue(dev);
1152 if (lp->use_dma && lp->dma) {
1154 release_dma_buff(lp);
1168 struct net_local *lp = netdev_priv(dev);
1169 unsigned long flags;
1175 spin_unlock_irqrestore(&lp->
lock, flags);
1180 static void net_timeout(
struct net_device *dev)
1186 tx_done(dev) ?
"IRQ conflict" :
"network cable problem");
1188 netif_wake_queue(dev);
1193 struct net_local *lp = netdev_priv(dev);
1194 unsigned long flags;
1207 netif_stop_queue(dev);
1219 spin_unlock_irqrestore(&lp->
lock, flags);
1225 spin_unlock_irqrestore(&lp->
lock, flags);
1242 static void set_multicast_list(
struct net_device *dev)
1244 struct net_local *lp = netdev_priv(dev);
1245 unsigned long flags;
1268 spin_unlock_irqrestore(&lp->
lock, flags);
1271 static int set_mac_address(
struct net_device *dev,
void *
p)
1276 if (netif_running(dev))
1293 #ifdef CONFIG_NET_POLL_CONTROLLER
1298 static void net_poll_controller(
struct net_device *dev)
1301 net_interrupt(dev->
irq, dev);
1307 .ndo_open = net_open,
1308 .ndo_stop = net_close,
1309 .ndo_tx_timeout = net_timeout,
1310 .ndo_start_xmit = net_send_packet,
1311 .ndo_get_stats = net_get_stats,
1312 .ndo_set_rx_mode = set_multicast_list,
1313 .ndo_set_mac_address = set_mac_address,
1314 #ifdef CONFIG_NET_POLL_CONTROLLER
1315 .ndo_poll_controller = net_poll_controller,
1323 #if !defined(CONFIG_MACH_MX31ADS)
1324 #if !defined(CS89x0_NONISA_IRQ)
1325 struct net_local *lp = netdev_priv(dev);
1327 int reset_start_time;
1334 #if !defined(CS89x0_NONISA_IRQ)
1352 jiffies - reset_start_time < 2)
1366 struct net_local *lp = netdev_priv(dev);
1369 unsigned rev_type = 0;
1375 memset(lp, 0,
sizeof(*lp));
1381 lp->dma = g_cs89x0_dma;
1385 lp->
force = g_cs89x0_media__force;
1389 pr_debug(
"PP_addr at %p[%x]: 0x%x\n",
1395 pr_debug(
"%s: incorrect signature at %p[%x]: 0x%x!="
1421 pr_info(
"%s: cs89%c0%s rev %c found at %p ",
1441 for (i = 0; i <
ETH_ALEN / 2; i++) {
1444 dev->
dev_addr[i * 2] = Addr & 0xFF;
1445 dev->
dev_addr[i * 2 + 1] = Addr >> 8;
1478 cs89_dbg(1,
info,
"%s: PP_LineCTL=0x%x, adapter_cnf=0x%x\n",
1493 pr_warn(
"No EEPROM, relying on command line....\n");
1495 pr_warn(
"EEPROM read failed, relying on command line\n");
1501 pr_warn(
"Extended EEPROM checksum bad and no Cirrus EEPROM, relying on command line\n");
1520 for (i = 0; i <
ETH_ALEN / 2; i++) {
1522 dev->
dev_addr[i * 2 + 1] = eeprom_buff[
i] >> 8;
1553 cs89_dbg(1,
debug,
"%s: after force 0x%x, adapter_cnf=0x%x\n",
1575 (i != 0 && i < CS8920_NO_INTS))) {
1580 #ifndef CONFIG_CS89x0_PLATFORM
1582 #ifdef CS89x0_NONISA_IRQ
1583 i = cs8900_irq_map[0];
1587 pr_err(
"invalid ISA interrupt number %d\n", i);
1589 i = cs8900_irq_map[
i];
1597 irq_map_buff) >= 0) {
1599 lp->
irq_map = ((irq_map_buff[0] >> 8) |
1600 (irq_map_buff[1] << 8));
1637 #ifndef CONFIG_CS89x0_PLATFORM
1644 cs89x0_ioport_probe(
struct net_device *dev,
unsigned long ioport,
int modular)
1646 struct net_local *lp = netdev_priv(dev);
1673 if ((ioport & 2) != 2) {
1676 pr_err(
"%s: bad signature 0x%x\n",
1684 ret = cs89x0_probe1(dev, io_mem, modular);
1723 err = cs89x0_ioport_probe(dev, io, 0);
1724 }
else if (io != 0) {
1727 for (port = netcard_portlist; *
port; port++) {
1728 if (cs89x0_ioport_probe(dev, *port, 0) == 0)
1740 pr_warn(
"no cs8900 or cs8920 detected. Be sure to disable PnP with SETUP\n");
1741 return ERR_PTR(err);
1746 #if defined(MODULE) && !defined(CONFIG_CS89x0_PLATFORM)
1757 static char media[8];
1762 static int dmasize = 16;
1779 MODULE_PARM_DESC(media,
"Set cs89x0 adapter(s) media type(s) (rj45,bnc,aui)");
1784 MODULE_PARM_DESC(dmasize ,
"cs89x0 DMA size in kB (16,64); ignored if use_dma=0");
1834 lp = netdev_priv(dev);
1840 lp->dmasize = dmasize;
1847 if (!
strcmp(media,
"rj45"))
1849 else if (!
strcmp(media,
"aui"))
1851 else if (!
strcmp(media,
"bnc"))
1860 pr_err(
"Module autoprobing not allowed\n");
1861 pr_err(
"Append io=0xNNN\n");
1864 }
else if (io <= 0x1ff) {
1870 if (use_dma && dmasize != 16 && dmasize != 64) {
1871 pr_err(
"dma size must be either 16K or 64K, not %dK\n",
1877 ret = cs89x0_ioport_probe(dev, io, 1);
1891 struct net_local *lp = netdev_priv(dev_cs89x0);
1901 #ifdef CONFIG_CS89x0_PLATFORM
1913 lp = netdev_priv(dev);
1917 if (mem_res ==
NULL || dev->
irq <= 0) {
1918 dev_warn(&dev->
dev,
"memory/interrupt resource missing\n");
1923 lp->
size = resource_size(mem_res);
1925 dev_warn(&dev->
dev,
"request_mem_region() failed\n");
1937 err = cs89x0_probe1(dev, virt_addr, 0);
1939 dev_warn(&dev->
dev,
"no cs8900 or cs8920 detected\n");
1943 platform_set_drvdata(pdev, dev);
1957 struct net_device *dev = platform_get_drvdata(pdev);
1958 struct net_local *lp = netdev_priv(dev);
1978 .remove = cs89x0_platform_remove,
1981 static int __init cs89x0_init(
void)
1988 static void __exit cs89x0_cleanup(
void)