41 #define DRV_NAME "3c505"
42 #define DRV_VERSION "1.10a"
99 #include <linux/module.h>
100 #include <linux/kernel.h>
101 #include <linux/string.h>
103 #include <linux/errno.h>
104 #include <linux/in.h>
107 #include <linux/ethtool.h>
109 #include <linux/bitops.h>
112 #include <asm/uaccess.h>
116 #include <linux/netdevice.h>
129 #define timeout_msg "*** timeout at %s:%s (line %d) ***\n"
130 #define TIMEOUT_MSG(lineno) \
131 pr_notice(timeout_msg, __FILE__, __func__, (lineno))
133 #define invalid_pcb_msg "*** invalid pcb length %d at %s:%s (line %d) ***\n"
134 #define INVALID_PCB_MSG(len) \
135 pr_notice(invalid_pcb_msg, (len), __FILE__, __func__, __LINE__)
137 #define search_msg "%s: Looking for 3c505 adapter at address %#x..."
139 #define stilllooking_msg "still looking..."
141 #define found_msg "found.\n"
143 #define notfound_msg "not found (reason = %d)\n"
145 #define couldnot_msg "%s: 3c505 not found\n"
154 static int elp_debug = ELP_DEBUG;
156 static int elp_debug;
158 #define debug elp_debug
173 static int addr_list[]
__initdata = {0x300, 0x280, 0x310, 0};
177 static unsigned long dma_mem_alloc(
int size)
190 static inline unsigned char inb_status(
unsigned int base_addr)
195 static inline int inb_command(
unsigned int base_addr)
206 #define HCR_VAL(x) (((elp_device *)(netdev_priv(x)))->hcr_val)
208 static inline void outb_command(
unsigned char val,
unsigned int base_addr)
213 static inline unsigned int backlog_next(
unsigned int n)
230 #define GET_ASF(addr) \
231 (get_status(addr)&ASF_PCB_MASK)
233 static inline int get_status(
unsigned int base_addr)
238 stat1 = inb_status(base_addr);
245 static inline void set_hsf(
struct net_device *dev,
int hsf)
252 spin_unlock_irqrestore(&adapter->
lock, flags);
257 static inline void adapter_reset(
struct net_device *dev)
261 unsigned char orig_hcr = adapter->
hcr_val;
263 outb_control(0, dev);
282 outb_control(orig_hcr, dev);
283 if (!start_receive(dev, &adapter->
tx_pcb))
284 pr_err(
"%s: start receive command failed\n", dev->
name);
291 static inline void check_3c505_dma(
struct net_device *dev)
296 pr_err(
"%s: DMA %s timed out, %d bytes left\n", dev->
name,
297 adapter->
current_dma.direction ?
"download" :
"upload",
310 spin_unlock_irqrestore(&adapter->
lock, flags);
315 static inline bool send_pcb_slow(
unsigned int base_addr,
unsigned char byte)
317 unsigned long timeout;
318 outb_command(byte, base_addr);
319 for (timeout = jiffies + 5*
HZ/100;
time_before(jiffies, timeout);) {
320 if (inb_status(base_addr) &
HCRE)
323 pr_warning(
"3c505: send_pcb_slow timed out\n");
327 static inline bool send_pcb_fast(
unsigned int base_addr,
unsigned char byte)
329 unsigned int timeout;
330 outb_command(byte, base_addr);
331 for (timeout = 0; timeout < 40000; timeout++) {
332 if (inb_status(base_addr) &
HCRE)
335 pr_warning(
"3c505: send_pcb_fast timed out\n");
340 static inline void prime_rx(
struct net_device *dev)
344 if (!start_receive(dev, &adapter->
itx_pcb))
376 unsigned long timeout;
380 check_3c505_dma(dev);
387 if (elp_debug >= 3) {
388 pr_debug(
"%s: send_pcb entered while threaded\n", dev->
name);
407 for (i = 0; i < pcb->
length; i++) {
412 outb_control(adapter->
hcr_val | 3, dev);
416 spin_unlock_irqrestore(&adapter->
lock, flags);
418 for (timeout = jiffies + 5*
HZ/100;
time_before(jiffies, timeout);) {
433 pr_debug(
"%s: timeout waiting for PCB acknowledge (status %02x)\n",
438 spin_unlock_irqrestore(&adapter->
lock, flags);
463 unsigned long timeout;
497 for (j = 0; j < 20000; j++) {
506 spin_unlock_irqrestore(&adapter->
lock, flags);
507 if (i >= MAX_PCB_DATA) {
519 if (total_length != (pcb->
length + 2)) {
530 pr_warning(
"%s: PCB rejected, transfer in progress and backlog full\n", dev->
name);
562 status = send_pcb(dev, tx_pcb);
577 static void receive_packet(
struct net_device *dev,
int len)
585 rlen = (len + 1) & ~1;
586 skb = netdev_alloc_skb(dev, rlen + 2);
607 pr_err(
"%s: rx blocked, DMA in progress, dir %d\n",
619 clear_dma_ff(dev->
dma);
621 set_dma_addr(dev->
dma, isa_virt_to_bus(target));
626 if (elp_debug >= 3) {
634 pr_warning(
"%s: receive_packet called, busy not set.\n", dev->
name);
650 unsigned long timeout;
652 spin_lock(&adapter->
lock);
663 pr_debug(
"%s: %s DMA complete, status %02x\n", dev->
name,
687 pr_debug(
"%s: receiving backlogged packet (%d)\n", dev->
name, t);
688 receive_packet(dev, t);
694 check_3c505_dma(dev);
702 if (receive_pcb(dev, &adapter->
irx_pcb)) {
713 if (!netif_running(dev))
718 pr_err(
"%s: interrupt - packet not received correctly\n", dev->
name);
720 if (elp_debug >= 3) {
721 pr_debug(
"%s: interrupt - packet received of length %i (%i)\n",
722 dev->
name, len, dlen);
726 pr_debug(
"%s: adding packet to backlog (len = %d)\n",
731 receive_packet(dev, dlen);
744 pr_debug(
"%s: interrupt - configure response received\n", dev->
name);
753 pr_debug(
"%s: Adapter memory configuration %s.\n", dev->
name,
763 pr_debug(
"%s: Multicast address list loading %s.\n", dev->
name,
773 pr_debug(
"%s: Ethernet address setting %s.\n", dev->
name,
790 pr_debug(
"%s: interrupt - statistics response received\n", dev->
name);
799 if (!netif_running(dev))
803 dev->
stats.tx_aborted_errors++;
804 pr_info(
"%s: transmit timed out, network cable problem?\n", dev->
name);
807 dev->
stats.tx_fifo_errors++;
808 pr_info(
"%s: transmit timed out, FIFO underrun\n", dev->
name);
811 netif_wake_queue(dev);
818 pr_debug(
"%s: unknown PCB received - %2.2x\n",
835 spin_unlock(&adapter->
lock);
857 if (adapter ==
NULL) {
858 pr_err(
"%s: Opening a non-existent physical device\n", dev->
name);
864 outb_control(0, dev);
888 pr_err(
"%s: could not allocate IRQ%d\n", dev->
name, dev->
irq);
893 pr_err(
"%s: could not allocate DMA%d channel\n", dev->
name, dev->
dma);
898 pr_err(
"%s: could not allocate DMA buffer\n", dev->
name);
908 outb_control(
CMDE, dev);
914 pr_debug(
"%s: sending 3c505 memory configuration command\n", dev->
name);
924 if (!send_pcb(dev, &adapter->
tx_pcb))
925 pr_err(
"%s: couldn't send memory configuration command\n", dev->
name);
938 pr_debug(
"%s: sending 82586 configure command\n", dev->
name);
943 if (!send_pcb(dev, &adapter->
tx_pcb))
944 pr_err(
"%s: couldn't send 82586 configure command\n", dev->
name);
966 netif_start_queue(dev);
986 unsigned int nlen = (((skb->
len < 60) ? 60 : skb->
len) + 1) & (~1);
994 dev->
stats.tx_bytes += nlen;
1006 if (!send_pcb(dev, &adapter->
tx_pcb)) {
1018 skb_copy_from_linear_data(skb, adapter->
dma_buffer, nlen);
1020 target = isa_virt_to_bus(adapter->
dma_buffer);
1023 target = isa_virt_to_bus(skb->
data);
1029 clear_dma_ff(dev->
dma);
1031 set_dma_addr(dev->
dma, target);
1047 static void elp_timeout(
struct net_device *dev)
1053 (stat &
ACRF) ?
"interrupt" :
"command");
1057 dev->
stats.tx_dropped++;
1058 netif_wake_queue(dev);
1070 unsigned long flags;
1074 check_3c505_dma(dev);
1077 pr_debug(
"%s: request to send packet of length %d\n", dev->
name, (
int) skb->
len);
1079 netif_stop_queue(dev);
1085 if (elp_debug >= 2) {
1086 pr_debug(
"%s: failed to transmit packet\n", dev->
name);
1088 spin_unlock_irqrestore(&adapter->
lock, flags);
1092 pr_debug(
"%s: packet of length %d sent\n", dev->
name, (
int) skb->
len);
1095 spin_unlock_irqrestore(&adapter->
lock, flags);
1096 netif_start_queue(dev);
1115 if (!netif_running(dev))
1122 if (!send_pcb(dev, &adapter->
tx_pcb))
1123 pr_err(
"%s: couldn't send get statistics command\n", dev->
name);
1138 static void netdev_get_drvinfo(
struct net_device *dev,
1156 static const struct ethtool_ops netdev_ethtool_ops = {
1157 .get_drvinfo = netdev_get_drvinfo,
1158 .get_msglevel = netdev_get_msglevel,
1159 .set_msglevel = netdev_set_msglevel,
1175 netif_stop_queue(dev);
1181 (
void) elp_get_stats(dev);
1186 outb_control(0, dev);
1209 static void elp_set_mc_list(
struct net_device *dev)
1214 unsigned long flags;
1217 pr_debug(
"%s: request to set multicast list\n", dev->
name);
1231 if (!send_pcb(dev, &adapter->tx_pcb))
1235 while (adapter->
got[CMD_LOAD_MULTICAST_LIST] == 0 &&
time_before(jiffies, timeout));
1251 pr_debug(
"%s: sending 82586 configure command\n", dev->name);
1255 if (!send_pcb(dev, &adapter->
tx_pcb))
1257 spin_unlock_irqrestore(&adapter->
lock, flags);
1258 pr_err(
"%s: couldn't send 82586 configure command\n", dev->name);
1262 spin_unlock_irqrestore(&adapter->
lock, flags);
1278 const char *name = dev->
name;
1284 orig_HSR = inb_status(addr);
1289 if (orig_HSR == 0xff) {
1299 if (orig_HSR &
DIR) {
1303 if (inb_status(addr) & DIR) {
1312 if (!(inb_status(addr) & DIR)) {
1343 if (elp_sense(dev) == 0)
1346 while ((dev->
base_addr = addr_list[idx++])) {
1347 if (elp_sense(dev) == 0)
1359 .ndo_open = elp_open,
1360 .ndo_stop = elp_close,
1361 .ndo_get_stats = elp_get_stats,
1362 .ndo_start_xmit = elp_start_xmit,
1363 .ndo_tx_timeout = elp_timeout,
1364 .ndo_set_rx_mode = elp_set_mc_list,
1394 int i, tries, tries1, okay;
1395 unsigned long timeout;
1396 unsigned long cookie = 0;
1409 for (tries1 = 0; tries1 < 3; tries1++) {
1410 outb_control((adapter->
hcr_val |
CMDE) & ~DIR, dev);
1428 pr_err(
"%s: command register wouldn't drain, ", dev->
name);
1429 if ((inb_status(dev->
base_addr) & 7) == 3) {
1433 pr_cont(
"assuming 3c505 still starting\n");
1437 pr_err(
"%s: 3c505 failed to start\n", dev->
name);
1445 pr_cont(
"3c505 is sulking\n");
1448 for (tries = 0; tries < 5 && okay; tries++) {
1457 if (!send_pcb(dev, &adapter->
tx_pcb)) {
1458 pr_err(
"%s: could not send first PCB\n", dev->
name);
1462 if (!receive_pcb(dev, &adapter->
rx_pcb)) {
1463 pr_err(
"%s: could not read first PCB\n", dev->
name);
1469 pr_err(
"%s: first PCB wrong (%d, %d)\n", dev->
name,
1483 pr_err(
"%s: failed to initialise 3c505\n", dev->
name);
1489 if (dev->
irq != rpt) {
1490 pr_warning(
"%s: warning, irq %d configured but %d detected\n", dev->
name, dev->
irq, rpt);
1497 pr_err(
"%s: IRQ probe failed: check 3c505 jumpers.\n",
1504 pr_err(
"%s: Impossible IRQ %d reported by probe_irq_off().\n",
1517 for (i = 0; i < 6; i++)
1526 pr_warning(
"%s: warning, DMA channel not specified, using default\n", dev->
name);
1534 pr_info(
"%s: 3c505 at %#lx, irq %d, dma %d, addr %pM, ",
1542 if (!send_pcb(dev, &adapter->
tx_pcb) ||
1543 !receive_pcb(dev, &adapter->
rx_pcb) ||
1546 pr_cont(
"not responding to second PCB\n");
1562 if (!send_pcb(dev, &adapter->
tx_pcb) ||
1563 !receive_pcb(dev, &adapter->
rx_pcb) ||
1566 pr_err(
"%s: could not configure adapter memory\n", dev->
name);
1569 pr_err(
"%s: adapter configuration failed\n", dev->
name);
1599 err = elplus_setup(dev);
1602 return ERR_PTR(err);
1621 int this_dev, found = 0;
1628 dev->
irq = irq[this_dev];
1630 if (dma[this_dev]) {
1631 dev->
dma = dma[this_dev];
1634 pr_warning(
"3c505.c: warning, using default DMA channel,\n");
1636 if (io[this_dev] == 0) {
1641 pr_notice(
"3c505.c: module autoprobe not recommended, give io=xx.\n");
1643 if (elplus_setup(dev) != 0) {
1644 pr_warning(
"3c505.c: Failed to register card at 0x%x.\n", io[this_dev]);
1648 dev_3c505[this_dev] =
dev;
1661 struct net_device *dev = dev_3c505[this_dev];