de6*/dl2k/sundance: Move the D-Link drivers
Move the D-Link drivers into drivers/net/ethernet/dlink/ and make the necessary Kconfig and Makefile changes. CC: Bjorn Ekwall <bj0rn@blox.se> CC: Donald Becker <becker@scyld.com> CC: Edward Peng <edward_peng@dlink.com.tw> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
This commit is contained in:
@@ -18,6 +18,7 @@ source "drivers/net/ethernet/broadcom/Kconfig"
|
||||
source "drivers/net/ethernet/brocade/Kconfig"
|
||||
source "drivers/net/ethernet/chelsio/Kconfig"
|
||||
source "drivers/net/ethernet/cisco/Kconfig"
|
||||
source "drivers/net/ethernet/dlink/Kconfig"
|
||||
source "drivers/net/ethernet/emulex/Kconfig"
|
||||
source "drivers/net/ethernet/neterion/Kconfig"
|
||||
source "drivers/net/ethernet/faraday/Kconfig"
|
||||
|
@@ -10,6 +10,7 @@ obj-$(CONFIG_NET_VENDOR_BROADCOM) += broadcom/
|
||||
obj-$(CONFIG_NET_VENDOR_BROCADE) += brocade/
|
||||
obj-$(CONFIG_NET_VENDOR_CHELSIO) += chelsio/
|
||||
obj-$(CONFIG_NET_VENDOR_CISCO) += cisco/
|
||||
obj-$(CONFIG_NET_VENDOR_DLINK) += dlink/
|
||||
obj-$(CONFIG_NET_VENDOR_EMULEX) += emulex/
|
||||
obj-$(CONFIG_NET_VENDOR_EXAR) += neterion/
|
||||
obj-$(CONFIG_NET_VENDOR_FARADAY) += faraday/
|
||||
|
84
drivers/net/ethernet/dlink/Kconfig
Normal file
84
drivers/net/ethernet/dlink/Kconfig
Normal file
@@ -0,0 +1,84 @@
|
||||
#
|
||||
# D-Link device configuration
|
||||
#
|
||||
|
||||
config NET_VENDOR_DLINK
|
||||
bool "D-Link devices"
|
||||
depends on PCI || PARPORT
|
||||
---help---
|
||||
If you have a network (Ethernet) card belonging to this class, say Y
|
||||
and read the Ethernet-HOWTO, available from
|
||||
<http://www.tldp.org/docs.html#howto>.
|
||||
|
||||
Note that the answer to this question doesn't directly affect the
|
||||
kernel: saying N will just cause the configurator to skip all
|
||||
the questions about D-Link devices. If you say Y, you will be asked for
|
||||
your specific card in the following questions.
|
||||
|
||||
if NET_VENDOR_DLINK
|
||||
|
||||
config DE600
|
||||
tristate "D-Link DE600 pocket adapter support"
|
||||
depends on PARPORT
|
||||
---help---
|
||||
This is a network (Ethernet) device which attaches to your parallel
|
||||
port. Read <file:Documentation/networking/DLINK.txt> as well as the
|
||||
Ethernet-HOWTO, available from
|
||||
<http://www.tldp.org/docs.html#howto>, if you want to use
|
||||
this. It is possible to have several devices share a single parallel
|
||||
port and it is safe to compile the corresponding drivers into the
|
||||
kernel.
|
||||
|
||||
To compile this driver as a module, choose M here: the module
|
||||
will be called de600.
|
||||
|
||||
config DE620
|
||||
tristate "D-Link DE620 pocket adapter support"
|
||||
depends on PARPORT
|
||||
---help---
|
||||
This is a network (Ethernet) device which attaches to your parallel
|
||||
port. Read <file:Documentation/networking/DLINK.txt> as well as the
|
||||
Ethernet-HOWTO, available from
|
||||
<http://www.tldp.org/docs.html#howto>, if you want to use
|
||||
this. It is possible to have several devices share a single parallel
|
||||
port and it is safe to compile the corresponding drivers into the
|
||||
kernel.
|
||||
|
||||
To compile this driver as a module, choose M here: the module
|
||||
will be called de620.
|
||||
|
||||
config DL2K
|
||||
tristate "DL2000/TC902x-based Gigabit Ethernet support"
|
||||
depends on PCI
|
||||
select CRC32
|
||||
---help---
|
||||
This driver supports DL2000/TC902x-based Gigabit ethernet cards,
|
||||
which includes
|
||||
D-Link DGE-550T Gigabit Ethernet Adapter.
|
||||
D-Link DL2000-based Gigabit Ethernet Adapter.
|
||||
Sundance/Tamarack TC902x Gigabit Ethernet Adapter.
|
||||
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called dl2k.
|
||||
|
||||
config SUNDANCE
|
||||
tristate "Sundance Alta support"
|
||||
depends on PCI
|
||||
select CRC32
|
||||
select MII
|
||||
---help---
|
||||
This driver is for the Sundance "Alta" chip.
|
||||
More specific information and updates are available from
|
||||
<http://www.scyld.com/network/sundance.html>.
|
||||
|
||||
config SUNDANCE_MMIO
|
||||
bool "Use MMIO instead of PIO"
|
||||
depends on SUNDANCE
|
||||
---help---
|
||||
Enable memory-mapped I/O for interaction with Sundance NIC registers.
|
||||
Do NOT enable this by default, PIO (enabled when MMIO is disabled)
|
||||
is known to solve bugs on certain chips.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
endif # NET_VENDOR_DLINK
|
8
drivers/net/ethernet/dlink/Makefile
Normal file
8
drivers/net/ethernet/dlink/Makefile
Normal file
@@ -0,0 +1,8 @@
|
||||
#
|
||||
# Makefile for the D-Link network device drivers.
|
||||
#
|
||||
|
||||
obj-$(CONFIG_DE600) += de600.o
|
||||
obj-$(CONFIG_DE620) += de620.o
|
||||
obj-$(CONFIG_DL2K) += dl2k.o
|
||||
obj-$(CONFIG_SUNDANCE) += sundance.o
|
530
drivers/net/ethernet/dlink/de600.c
Normal file
530
drivers/net/ethernet/dlink/de600.c
Normal file
@@ -0,0 +1,530 @@
|
||||
static const char version[] = "de600.c: $Revision: 1.41-2.5 $, Bjorn Ekwall (bj0rn@blox.se)\n";
|
||||
/*
|
||||
* de600.c
|
||||
*
|
||||
* Linux driver for the D-Link DE-600 Ethernet pocket adapter.
|
||||
*
|
||||
* Portions (C) Copyright 1993, 1994 by Bjorn Ekwall
|
||||
* The Author may be reached as bj0rn@blox.se
|
||||
*
|
||||
* Based on adapter information gathered from DE600.ASM by D-Link Inc.,
|
||||
* as included on disk C in the v.2.11 of PC/TCP from FTP Software.
|
||||
* For DE600.asm:
|
||||
* Portions (C) Copyright 1990 D-Link, Inc.
|
||||
* Copyright, 1988-1992, Russell Nelson, Crynwr Software
|
||||
*
|
||||
* Adapted to the sample network driver core for linux,
|
||||
* written by: Donald Becker <becker@super.org>
|
||||
* (Now at <becker@scyld.com>)
|
||||
*
|
||||
**************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
**************************************************************/
|
||||
|
||||
/* Add more time here if your adapter won't work OK: */
|
||||
#define DE600_SLOW_DOWN udelay(delay_time)
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/fcntl.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/in.h>
|
||||
#include <asm/system.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/inet.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/skbuff.h>
|
||||
|
||||
#include <asm/io.h>
|
||||
|
||||
#include "de600.h"
|
||||
|
||||
static unsigned int check_lost = 1;
|
||||
module_param(check_lost, bool, 0);
|
||||
MODULE_PARM_DESC(check_lost, "If set then check for unplugged de600");
|
||||
|
||||
static unsigned int delay_time = 10;
|
||||
module_param(delay_time, int, 0);
|
||||
MODULE_PARM_DESC(delay_time, "DE-600 deley on I/O in microseconds");
|
||||
|
||||
|
||||
/*
|
||||
* D-Link driver variables:
|
||||
*/
|
||||
|
||||
static volatile int rx_page;
|
||||
|
||||
#define TX_PAGES 2
|
||||
static volatile int tx_fifo[TX_PAGES];
|
||||
static volatile int tx_fifo_in;
|
||||
static volatile int tx_fifo_out;
|
||||
static volatile int free_tx_pages = TX_PAGES;
|
||||
static int was_down;
|
||||
static DEFINE_SPINLOCK(de600_lock);
|
||||
|
||||
static inline u8 de600_read_status(struct net_device *dev)
|
||||
{
|
||||
u8 status;
|
||||
|
||||
outb_p(STATUS, DATA_PORT);
|
||||
status = inb(STATUS_PORT);
|
||||
outb_p(NULL_COMMAND | HI_NIBBLE, DATA_PORT);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static inline u8 de600_read_byte(unsigned char type, struct net_device *dev)
|
||||
{
|
||||
/* dev used by macros */
|
||||
u8 lo;
|
||||
outb_p((type), DATA_PORT);
|
||||
lo = ((unsigned char)inb(STATUS_PORT)) >> 4;
|
||||
outb_p((type) | HI_NIBBLE, DATA_PORT);
|
||||
return ((unsigned char)inb(STATUS_PORT) & (unsigned char)0xf0) | lo;
|
||||
}
|
||||
|
||||
/*
|
||||
* Open/initialize the board. This is called (in the current kernel)
|
||||
* after booting when 'ifconfig <dev->name> $IP_ADDR' is run (in rc.inet1).
|
||||
*
|
||||
* This routine should set everything up anew at each open, even
|
||||
* registers that "should" only need to be set once at boot, so that
|
||||
* there is a non-reboot way to recover if something goes wrong.
|
||||
*/
|
||||
|
||||
static int de600_open(struct net_device *dev)
|
||||
{
|
||||
unsigned long flags;
|
||||
int ret = request_irq(DE600_IRQ, de600_interrupt, 0, dev->name, dev);
|
||||
if (ret) {
|
||||
printk(KERN_ERR "%s: unable to get IRQ %d\n", dev->name, DE600_IRQ);
|
||||
return ret;
|
||||
}
|
||||
spin_lock_irqsave(&de600_lock, flags);
|
||||
ret = adapter_init(dev);
|
||||
spin_unlock_irqrestore(&de600_lock, flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* The inverse routine to de600_open().
|
||||
*/
|
||||
|
||||
static int de600_close(struct net_device *dev)
|
||||
{
|
||||
select_nic();
|
||||
rx_page = 0;
|
||||
de600_put_command(RESET);
|
||||
de600_put_command(STOP_RESET);
|
||||
de600_put_command(0);
|
||||
select_prn();
|
||||
free_irq(DE600_IRQ, dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void trigger_interrupt(struct net_device *dev)
|
||||
{
|
||||
de600_put_command(FLIP_IRQ);
|
||||
select_prn();
|
||||
DE600_SLOW_DOWN;
|
||||
select_nic();
|
||||
de600_put_command(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy a buffer to the adapter transmit page memory.
|
||||
* Start sending.
|
||||
*/
|
||||
|
||||
static int de600_start_xmit(struct sk_buff *skb, struct net_device *dev)
|
||||
{
|
||||
unsigned long flags;
|
||||
int transmit_from;
|
||||
int len;
|
||||
int tickssofar;
|
||||
u8 *buffer = skb->data;
|
||||
int i;
|
||||
|
||||
if (free_tx_pages <= 0) { /* Do timeouts, to avoid hangs. */
|
||||
tickssofar = jiffies - dev_trans_start(dev);
|
||||
if (tickssofar < HZ/20)
|
||||
return NETDEV_TX_BUSY;
|
||||
/* else */
|
||||
printk(KERN_WARNING "%s: transmit timed out (%d), %s?\n", dev->name, tickssofar, "network cable problem");
|
||||
/* Restart the adapter. */
|
||||
spin_lock_irqsave(&de600_lock, flags);
|
||||
if (adapter_init(dev)) {
|
||||
spin_unlock_irqrestore(&de600_lock, flags);
|
||||
return NETDEV_TX_BUSY;
|
||||
}
|
||||
spin_unlock_irqrestore(&de600_lock, flags);
|
||||
}
|
||||
|
||||
/* Start real output */
|
||||
pr_debug("de600_start_xmit:len=%d, page %d/%d\n", skb->len, tx_fifo_in, free_tx_pages);
|
||||
|
||||
if ((len = skb->len) < RUNT)
|
||||
len = RUNT;
|
||||
|
||||
spin_lock_irqsave(&de600_lock, flags);
|
||||
select_nic();
|
||||
tx_fifo[tx_fifo_in] = transmit_from = tx_page_adr(tx_fifo_in) - len;
|
||||
tx_fifo_in = (tx_fifo_in + 1) % TX_PAGES; /* Next free tx page */
|
||||
|
||||
if(check_lost)
|
||||
{
|
||||
/* This costs about 40 instructions per packet... */
|
||||
de600_setup_address(NODE_ADDRESS, RW_ADDR);
|
||||
de600_read_byte(READ_DATA, dev);
|
||||
if (was_down || (de600_read_byte(READ_DATA, dev) != 0xde)) {
|
||||
if (adapter_init(dev)) {
|
||||
spin_unlock_irqrestore(&de600_lock, flags);
|
||||
return NETDEV_TX_BUSY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
de600_setup_address(transmit_from, RW_ADDR);
|
||||
for (i = 0; i < skb->len ; ++i, ++buffer)
|
||||
de600_put_byte(*buffer);
|
||||
for (; i < len; ++i)
|
||||
de600_put_byte(0);
|
||||
|
||||
if (free_tx_pages-- == TX_PAGES) { /* No transmission going on */
|
||||
dev->trans_start = jiffies;
|
||||
netif_start_queue(dev); /* allow more packets into adapter */
|
||||
/* Send page and generate a faked interrupt */
|
||||
de600_setup_address(transmit_from, TX_ADDR);
|
||||
de600_put_command(TX_ENABLE);
|
||||
}
|
||||
else {
|
||||
if (free_tx_pages)
|
||||
netif_start_queue(dev);
|
||||
else
|
||||
netif_stop_queue(dev);
|
||||
select_prn();
|
||||
}
|
||||
spin_unlock_irqrestore(&de600_lock, flags);
|
||||
dev_kfree_skb(skb);
|
||||
return NETDEV_TX_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* The typical workload of the driver:
|
||||
* Handle the network interface interrupts.
|
||||
*/
|
||||
|
||||
static irqreturn_t de600_interrupt(int irq, void *dev_id)
|
||||
{
|
||||
struct net_device *dev = dev_id;
|
||||
u8 irq_status;
|
||||
int retrig = 0;
|
||||
int boguscount = 0;
|
||||
|
||||
spin_lock(&de600_lock);
|
||||
|
||||
select_nic();
|
||||
irq_status = de600_read_status(dev);
|
||||
|
||||
do {
|
||||
pr_debug("de600_interrupt (%02X)\n", irq_status);
|
||||
|
||||
if (irq_status & RX_GOOD)
|
||||
de600_rx_intr(dev);
|
||||
else if (!(irq_status & RX_BUSY))
|
||||
de600_put_command(RX_ENABLE);
|
||||
|
||||
/* Any transmission in progress? */
|
||||
if (free_tx_pages < TX_PAGES)
|
||||
retrig = de600_tx_intr(dev, irq_status);
|
||||
else
|
||||
retrig = 0;
|
||||
|
||||
irq_status = de600_read_status(dev);
|
||||
} while ( (irq_status & RX_GOOD) || ((++boguscount < 100) && retrig) );
|
||||
/*
|
||||
* Yeah, it _looks_ like busy waiting, smells like busy waiting
|
||||
* and I know it's not PC, but please, it will only occur once
|
||||
* in a while and then only for a loop or so (< 1ms for sure!)
|
||||
*/
|
||||
|
||||
/* Enable adapter interrupts */
|
||||
select_prn();
|
||||
if (retrig)
|
||||
trigger_interrupt(dev);
|
||||
spin_unlock(&de600_lock);
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static int de600_tx_intr(struct net_device *dev, int irq_status)
|
||||
{
|
||||
/*
|
||||
* Returns 1 if tx still not done
|
||||
*/
|
||||
|
||||
/* Check if current transmission is done yet */
|
||||
if (irq_status & TX_BUSY)
|
||||
return 1; /* tx not done, try again */
|
||||
|
||||
/* else */
|
||||
/* If last transmission OK then bump fifo index */
|
||||
if (!(irq_status & TX_FAILED16)) {
|
||||
tx_fifo_out = (tx_fifo_out + 1) % TX_PAGES;
|
||||
++free_tx_pages;
|
||||
dev->stats.tx_packets++;
|
||||
netif_wake_queue(dev);
|
||||
}
|
||||
|
||||
/* More to send, or resend last packet? */
|
||||
if ((free_tx_pages < TX_PAGES) || (irq_status & TX_FAILED16)) {
|
||||
dev->trans_start = jiffies;
|
||||
de600_setup_address(tx_fifo[tx_fifo_out], TX_ADDR);
|
||||
de600_put_command(TX_ENABLE);
|
||||
return 1;
|
||||
}
|
||||
/* else */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* We have a good packet, get it out of the adapter.
|
||||
*/
|
||||
static void de600_rx_intr(struct net_device *dev)
|
||||
{
|
||||
struct sk_buff *skb;
|
||||
int i;
|
||||
int read_from;
|
||||
int size;
|
||||
unsigned char *buffer;
|
||||
|
||||
/* Get size of received packet */
|
||||
size = de600_read_byte(RX_LEN, dev); /* low byte */
|
||||
size += (de600_read_byte(RX_LEN, dev) << 8); /* high byte */
|
||||
size -= 4; /* Ignore trailing 4 CRC-bytes */
|
||||
|
||||
/* Tell adapter where to store next incoming packet, enable receiver */
|
||||
read_from = rx_page_adr();
|
||||
next_rx_page();
|
||||
de600_put_command(RX_ENABLE);
|
||||
|
||||
if ((size < 32) || (size > 1535)) {
|
||||
printk(KERN_WARNING "%s: Bogus packet size %d.\n", dev->name, size);
|
||||
if (size > 10000)
|
||||
adapter_init(dev);
|
||||
return;
|
||||
}
|
||||
|
||||
skb = dev_alloc_skb(size+2);
|
||||
if (skb == NULL) {
|
||||
printk("%s: Couldn't allocate a sk_buff of size %d.\n", dev->name, size);
|
||||
return;
|
||||
}
|
||||
/* else */
|
||||
|
||||
skb_reserve(skb,2); /* Align */
|
||||
|
||||
/* 'skb->data' points to the start of sk_buff data area. */
|
||||
buffer = skb_put(skb,size);
|
||||
|
||||
/* copy the packet into the buffer */
|
||||
de600_setup_address(read_from, RW_ADDR);
|
||||
for (i = size; i > 0; --i, ++buffer)
|
||||
*buffer = de600_read_byte(READ_DATA, dev);
|
||||
|
||||
skb->protocol=eth_type_trans(skb,dev);
|
||||
|
||||
netif_rx(skb);
|
||||
|
||||
/* update stats */
|
||||
dev->stats.rx_packets++; /* count all receives */
|
||||
dev->stats.rx_bytes += size; /* count all received bytes */
|
||||
|
||||
/*
|
||||
* If any worth-while packets have been received, netif_rx()
|
||||
* will work on them when we get to the tasklets.
|
||||
*/
|
||||
}
|
||||
|
||||
static const struct net_device_ops de600_netdev_ops = {
|
||||
.ndo_open = de600_open,
|
||||
.ndo_stop = de600_close,
|
||||
.ndo_start_xmit = de600_start_xmit,
|
||||
.ndo_change_mtu = eth_change_mtu,
|
||||
.ndo_set_mac_address = eth_mac_addr,
|
||||
.ndo_validate_addr = eth_validate_addr,
|
||||
};
|
||||
|
||||
|
||||
static struct net_device * __init de600_probe(void)
|
||||
{
|
||||
int i;
|
||||
struct net_device *dev;
|
||||
int err;
|
||||
|
||||
dev = alloc_etherdev(0);
|
||||
if (!dev)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
|
||||
if (!request_region(DE600_IO, 3, "de600")) {
|
||||
printk(KERN_WARNING "DE600: port 0x%x busy\n", DE600_IO);
|
||||
err = -EBUSY;
|
||||
goto out;
|
||||
}
|
||||
|
||||
printk(KERN_INFO "%s: D-Link DE-600 pocket adapter", dev->name);
|
||||
/* Alpha testers must have the version number to report bugs. */
|
||||
pr_debug("%s", version);
|
||||
|
||||
/* probe for adapter */
|
||||
err = -ENODEV;
|
||||
rx_page = 0;
|
||||
select_nic();
|
||||
(void)de600_read_status(dev);
|
||||
de600_put_command(RESET);
|
||||
de600_put_command(STOP_RESET);
|
||||
if (de600_read_status(dev) & 0xf0) {
|
||||
printk(": not at I/O %#3x.\n", DATA_PORT);
|
||||
goto out1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Maybe we found one,
|
||||
* have to check if it is a D-Link DE-600 adapter...
|
||||
*/
|
||||
|
||||
/* Get the adapter ethernet address from the ROM */
|
||||
de600_setup_address(NODE_ADDRESS, RW_ADDR);
|
||||
for (i = 0; i < ETH_ALEN; i++) {
|
||||
dev->dev_addr[i] = de600_read_byte(READ_DATA, dev);
|
||||
dev->broadcast[i] = 0xff;
|
||||
}
|
||||
|
||||
/* Check magic code */
|
||||
if ((dev->dev_addr[1] == 0xde) && (dev->dev_addr[2] == 0x15)) {
|
||||
/* OK, install real address */
|
||||
dev->dev_addr[0] = 0x00;
|
||||
dev->dev_addr[1] = 0x80;
|
||||
dev->dev_addr[2] = 0xc8;
|
||||
dev->dev_addr[3] &= 0x0f;
|
||||
dev->dev_addr[3] |= 0x70;
|
||||
} else {
|
||||
printk(" not identified in the printer port\n");
|
||||
goto out1;
|
||||
}
|
||||
|
||||
printk(", Ethernet Address: %pM\n", dev->dev_addr);
|
||||
|
||||
dev->netdev_ops = &de600_netdev_ops;
|
||||
|
||||
dev->flags&=~IFF_MULTICAST;
|
||||
|
||||
select_prn();
|
||||
|
||||
err = register_netdev(dev);
|
||||
if (err)
|
||||
goto out1;
|
||||
|
||||
return dev;
|
||||
|
||||
out1:
|
||||
release_region(DE600_IO, 3);
|
||||
out:
|
||||
free_netdev(dev);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
|
||||
static int adapter_init(struct net_device *dev)
|
||||
{
|
||||
int i;
|
||||
|
||||
select_nic();
|
||||
rx_page = 0; /* used by RESET */
|
||||
de600_put_command(RESET);
|
||||
de600_put_command(STOP_RESET);
|
||||
|
||||
/* Check if it is still there... */
|
||||
/* Get the some bytes of the adapter ethernet address from the ROM */
|
||||
de600_setup_address(NODE_ADDRESS, RW_ADDR);
|
||||
de600_read_byte(READ_DATA, dev);
|
||||
if ((de600_read_byte(READ_DATA, dev) != 0xde) ||
|
||||
(de600_read_byte(READ_DATA, dev) != 0x15)) {
|
||||
/* was: if (de600_read_status(dev) & 0xf0) { */
|
||||
printk("Something has happened to the DE-600! Please check it and do a new ifconfig!\n");
|
||||
/* Goodbye, cruel world... */
|
||||
dev->flags &= ~IFF_UP;
|
||||
de600_close(dev);
|
||||
was_down = 1;
|
||||
netif_stop_queue(dev); /* Transmit busy... */
|
||||
return 1; /* failed */
|
||||
}
|
||||
|
||||
if (was_down) {
|
||||
printk(KERN_INFO "%s: Thanks, I feel much better now!\n", dev->name);
|
||||
was_down = 0;
|
||||
}
|
||||
|
||||
tx_fifo_in = 0;
|
||||
tx_fifo_out = 0;
|
||||
free_tx_pages = TX_PAGES;
|
||||
|
||||
|
||||
/* set the ether address. */
|
||||
de600_setup_address(NODE_ADDRESS, RW_ADDR);
|
||||
for (i = 0; i < ETH_ALEN; i++)
|
||||
de600_put_byte(dev->dev_addr[i]);
|
||||
|
||||
/* where to start saving incoming packets */
|
||||
rx_page = RX_BP | RX_BASE_PAGE;
|
||||
de600_setup_address(MEM_4K, RW_ADDR);
|
||||
/* Enable receiver */
|
||||
de600_put_command(RX_ENABLE);
|
||||
select_prn();
|
||||
|
||||
netif_start_queue(dev);
|
||||
|
||||
return 0; /* OK */
|
||||
}
|
||||
|
||||
static struct net_device *de600_dev;
|
||||
|
||||
static int __init de600_init(void)
|
||||
{
|
||||
de600_dev = de600_probe();
|
||||
if (IS_ERR(de600_dev))
|
||||
return PTR_ERR(de600_dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit de600_exit(void)
|
||||
{
|
||||
unregister_netdev(de600_dev);
|
||||
release_region(DE600_IO, 3);
|
||||
free_netdev(de600_dev);
|
||||
}
|
||||
|
||||
module_init(de600_init);
|
||||
module_exit(de600_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
168
drivers/net/ethernet/dlink/de600.h
Normal file
168
drivers/net/ethernet/dlink/de600.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/**************************************************
|
||||
* *
|
||||
* Definition of D-Link Ethernet Pocket adapter *
|
||||
* *
|
||||
**************************************************/
|
||||
/*
|
||||
* D-Link Ethernet pocket adapter ports
|
||||
*/
|
||||
/*
|
||||
* OK, so I'm cheating, but there are an awful lot of
|
||||
* reads and writes in order to get anything in and out
|
||||
* of the DE-600 with 4 bits at a time in the parallel port,
|
||||
* so every saved instruction really helps :-)
|
||||
*/
|
||||
|
||||
#ifndef DE600_IO
|
||||
#define DE600_IO 0x378
|
||||
#endif
|
||||
|
||||
#define DATA_PORT (DE600_IO)
|
||||
#define STATUS_PORT (DE600_IO + 1)
|
||||
#define COMMAND_PORT (DE600_IO + 2)
|
||||
|
||||
#ifndef DE600_IRQ
|
||||
#define DE600_IRQ 7
|
||||
#endif
|
||||
/*
|
||||
* It really should look like this, and autoprobing as well...
|
||||
*
|
||||
#define DATA_PORT (dev->base_addr + 0)
|
||||
#define STATUS_PORT (dev->base_addr + 1)
|
||||
#define COMMAND_PORT (dev->base_addr + 2)
|
||||
#define DE600_IRQ dev->irq
|
||||
*/
|
||||
|
||||
/*
|
||||
* D-Link COMMAND_PORT commands
|
||||
*/
|
||||
#define SELECT_NIC 0x04 /* select Network Interface Card */
|
||||
#define SELECT_PRN 0x1c /* select Printer */
|
||||
#define NML_PRN 0xec /* normal Printer situation */
|
||||
#define IRQEN 0x10 /* enable IRQ line */
|
||||
|
||||
/*
|
||||
* D-Link STATUS_PORT
|
||||
*/
|
||||
#define RX_BUSY 0x80
|
||||
#define RX_GOOD 0x40
|
||||
#define TX_FAILED16 0x10
|
||||
#define TX_BUSY 0x08
|
||||
|
||||
/*
|
||||
* D-Link DATA_PORT commands
|
||||
* command in low 4 bits
|
||||
* data in high 4 bits
|
||||
* select current data nibble with HI_NIBBLE bit
|
||||
*/
|
||||
#define WRITE_DATA 0x00 /* write memory */
|
||||
#define READ_DATA 0x01 /* read memory */
|
||||
#define STATUS 0x02 /* read status register */
|
||||
#define COMMAND 0x03 /* write command register (see COMMAND below) */
|
||||
#define NULL_COMMAND 0x04 /* null command */
|
||||
#define RX_LEN 0x05 /* read received packet length */
|
||||
#define TX_ADDR 0x06 /* set adapter transmit memory address */
|
||||
#define RW_ADDR 0x07 /* set adapter read/write memory address */
|
||||
#define HI_NIBBLE 0x08 /* read/write the high nibble of data,
|
||||
or-ed with rest of command */
|
||||
|
||||
/*
|
||||
* command register, accessed through DATA_PORT with low bits = COMMAND
|
||||
*/
|
||||
#define RX_ALL 0x01 /* PROMISCUOUS */
|
||||
#define RX_BP 0x02 /* default: BROADCAST & PHYSICAL ADDRESS */
|
||||
#define RX_MBP 0x03 /* MULTICAST, BROADCAST & PHYSICAL ADDRESS */
|
||||
|
||||
#define TX_ENABLE 0x04 /* bit 2 */
|
||||
#define RX_ENABLE 0x08 /* bit 3 */
|
||||
|
||||
#define RESET 0x80 /* set bit 7 high */
|
||||
#define STOP_RESET 0x00 /* set bit 7 low */
|
||||
|
||||
/*
|
||||
* data to command register
|
||||
* (high 4 bits in write to DATA_PORT)
|
||||
*/
|
||||
#define RX_PAGE2_SELECT 0x10 /* bit 4, only 2 pages to select */
|
||||
#define RX_BASE_PAGE 0x20 /* bit 5, always set when specifying RX_ADDR */
|
||||
#define FLIP_IRQ 0x40 /* bit 6 */
|
||||
|
||||
/*
|
||||
* D-Link adapter internal memory:
|
||||
*
|
||||
* 0-2K 1:st transmit page (send from pointer up to 2K)
|
||||
* 2-4K 2:nd transmit page (send from pointer up to 4K)
|
||||
*
|
||||
* 4-6K 1:st receive page (data from 4K upwards)
|
||||
* 6-8K 2:nd receive page (data from 6K upwards)
|
||||
*
|
||||
* 8K+ Adapter ROM (contains magic code and last 3 bytes of Ethernet address)
|
||||
*/
|
||||
#define MEM_2K 0x0800 /* 2048 */
|
||||
#define MEM_4K 0x1000 /* 4096 */
|
||||
#define MEM_6K 0x1800 /* 6144 */
|
||||
#define NODE_ADDRESS 0x2000 /* 8192 */
|
||||
|
||||
#define RUNT 60 /* Too small Ethernet packet */
|
||||
|
||||
/**************************************************
|
||||
* *
|
||||
* End of definition *
|
||||
* *
|
||||
**************************************************/
|
||||
|
||||
/*
|
||||
* Index to functions, as function prototypes.
|
||||
*/
|
||||
/* Routines used internally. (See "convenience macros") */
|
||||
static u8 de600_read_status(struct net_device *dev);
|
||||
static u8 de600_read_byte(unsigned char type, struct net_device *dev);
|
||||
|
||||
/* Put in the device structure. */
|
||||
static int de600_open(struct net_device *dev);
|
||||
static int de600_close(struct net_device *dev);
|
||||
static int de600_start_xmit(struct sk_buff *skb, struct net_device *dev);
|
||||
|
||||
/* Dispatch from interrupts. */
|
||||
static irqreturn_t de600_interrupt(int irq, void *dev_id);
|
||||
static int de600_tx_intr(struct net_device *dev, int irq_status);
|
||||
static void de600_rx_intr(struct net_device *dev);
|
||||
|
||||
/* Initialization */
|
||||
static void trigger_interrupt(struct net_device *dev);
|
||||
static int adapter_init(struct net_device *dev);
|
||||
|
||||
/*
|
||||
* Convenience macros/functions for D-Link adapter
|
||||
*/
|
||||
|
||||
#define select_prn() outb_p(SELECT_PRN, COMMAND_PORT); DE600_SLOW_DOWN
|
||||
#define select_nic() outb_p(SELECT_NIC, COMMAND_PORT); DE600_SLOW_DOWN
|
||||
|
||||
/* Thanks for hints from Mark Burton <markb@ordern.demon.co.uk> */
|
||||
#define de600_put_byte(data) ( \
|
||||
outb_p(((data) << 4) | WRITE_DATA , DATA_PORT), \
|
||||
outb_p(((data) & 0xf0) | WRITE_DATA | HI_NIBBLE, DATA_PORT))
|
||||
|
||||
/*
|
||||
* The first two outb_p()'s below could perhaps be deleted if there
|
||||
* would be more delay in the last two. Not certain about it yet...
|
||||
*/
|
||||
#define de600_put_command(cmd) ( \
|
||||
outb_p(( rx_page << 4) | COMMAND , DATA_PORT), \
|
||||
outb_p(( rx_page & 0xf0) | COMMAND | HI_NIBBLE, DATA_PORT), \
|
||||
outb_p(((rx_page | cmd) << 4) | COMMAND , DATA_PORT), \
|
||||
outb_p(((rx_page | cmd) & 0xf0) | COMMAND | HI_NIBBLE, DATA_PORT))
|
||||
|
||||
#define de600_setup_address(addr,type) ( \
|
||||
outb_p((((addr) << 4) & 0xf0) | type , DATA_PORT), \
|
||||
outb_p(( (addr) & 0xf0) | type | HI_NIBBLE, DATA_PORT), \
|
||||
outb_p((((addr) >> 4) & 0xf0) | type , DATA_PORT), \
|
||||
outb_p((((addr) >> 8) & 0xf0) | type | HI_NIBBLE, DATA_PORT))
|
||||
|
||||
#define rx_page_adr() ((rx_page & RX_PAGE2_SELECT)?(MEM_6K):(MEM_4K))
|
||||
|
||||
/* Flip bit, only 2 pages */
|
||||
#define next_rx_page() (rx_page ^= RX_PAGE2_SELECT)
|
||||
|
||||
#define tx_page_adr(a) (((a) + 1) * MEM_2K)
|
988
drivers/net/ethernet/dlink/de620.c
Normal file
988
drivers/net/ethernet/dlink/de620.c
Normal file
@@ -0,0 +1,988 @@
|
||||
/*
|
||||
* de620.c $Revision: 1.40 $ BETA
|
||||
*
|
||||
*
|
||||
* Linux driver for the D-Link DE-620 Ethernet pocket adapter.
|
||||
*
|
||||
* Portions (C) Copyright 1993, 1994 by Bjorn Ekwall <bj0rn@blox.se>
|
||||
*
|
||||
* Based on adapter information gathered from DOS packetdriver
|
||||
* sources from D-Link Inc: (Special thanks to Henry Ngai of D-Link.)
|
||||
* Portions (C) Copyright D-Link SYSTEM Inc. 1991, 1992
|
||||
* Copyright, 1988, Russell Nelson, Crynwr Software
|
||||
*
|
||||
* Adapted to the sample network driver core for linux,
|
||||
* written by: Donald Becker <becker@super.org>
|
||||
* (Now at <becker@scyld.com>)
|
||||
*
|
||||
* Valuable assistance from:
|
||||
* J. Joshua Kopper <kopper@rtsg.mot.com>
|
||||
* Olav Kvittem <Olav.Kvittem@uninett.no>
|
||||
* Germano Caronni <caronni@nessie.cs.id.ethz.ch>
|
||||
* Jeremy Fitzhardinge <jeremy@suite.sw.oz.au>
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*****************************************************************************/
|
||||
static const char version[] =
|
||||
"de620.c: $Revision: 1.40 $, Bjorn Ekwall <bj0rn@blox.se>\n";
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* "Tuning" section.
|
||||
*
|
||||
* Compile-time options: (see below for descriptions)
|
||||
* -DDE620_IO=0x378 (lpt1)
|
||||
* -DDE620_IRQ=7 (lpt1)
|
||||
* -DSHUTDOWN_WHEN_LOST
|
||||
* -DCOUNT_LOOPS
|
||||
* -DLOWSPEED
|
||||
* -DREAD_DELAY
|
||||
* -DWRITE_DELAY
|
||||
*/
|
||||
|
||||
/*
|
||||
* This driver assumes that the printer port is a "normal",
|
||||
* dumb, uni-directional port!
|
||||
* If your port is "fancy" in any way, please try to set it to "normal"
|
||||
* with your BIOS setup. I have no access to machines with bi-directional
|
||||
* ports, so I can't test such a driver :-(
|
||||
* (Yes, I _know_ it is possible to use DE620 with bidirectional ports...)
|
||||
*
|
||||
* There are some clones of DE620 out there, with different names.
|
||||
* If the current driver does not recognize a clone, try to change
|
||||
* the following #define to:
|
||||
*
|
||||
* #define DE620_CLONE 1
|
||||
*/
|
||||
#define DE620_CLONE 0
|
||||
|
||||
/*
|
||||
* If the adapter has problems with high speeds, enable this #define
|
||||
* otherwise full printerport speed will be attempted.
|
||||
*
|
||||
* You can tune the READ_DELAY/WRITE_DELAY below if you enable LOWSPEED
|
||||
*
|
||||
#define LOWSPEED
|
||||
*/
|
||||
|
||||
#ifndef READ_DELAY
|
||||
#define READ_DELAY 100 /* adapter internal read delay in 100ns units */
|
||||
#endif
|
||||
|
||||
#ifndef WRITE_DELAY
|
||||
#define WRITE_DELAY 100 /* adapter internal write delay in 100ns units */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enable this #define if you want the adapter to do a "ifconfig down" on
|
||||
* itself when we have detected that something is possibly wrong with it.
|
||||
* The default behaviour is to retry with "adapter_init()" until success.
|
||||
* This should be used for debugging purposes only.
|
||||
*
|
||||
#define SHUTDOWN_WHEN_LOST
|
||||
*/
|
||||
|
||||
#ifdef LOWSPEED
|
||||
/*
|
||||
* Enable this #define if you want to see debugging output that show how long
|
||||
* we have to wait before the DE-620 is ready for the next read/write/command.
|
||||
*
|
||||
#define COUNT_LOOPS
|
||||
*/
|
||||
#endif
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/fcntl.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/in.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/inet.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/skbuff.h>
|
||||
|
||||
#include <asm/io.h>
|
||||
#include <asm/system.h>
|
||||
|
||||
/* Constant definitions for the DE-620 registers, commands and bits */
|
||||
#include "de620.h"
|
||||
|
||||
typedef unsigned char byte;
|
||||
|
||||
/*******************************************************
|
||||
* *
|
||||
* Definition of D-Link DE-620 Ethernet Pocket adapter *
|
||||
* See also "de620.h" *
|
||||
* *
|
||||
*******************************************************/
|
||||
#ifndef DE620_IO /* Compile-time configurable */
|
||||
#define DE620_IO 0x378
|
||||
#endif
|
||||
|
||||
#ifndef DE620_IRQ /* Compile-time configurable */
|
||||
#define DE620_IRQ 7
|
||||
#endif
|
||||
|
||||
#define DATA_PORT (dev->base_addr)
|
||||
#define STATUS_PORT (dev->base_addr + 1)
|
||||
#define COMMAND_PORT (dev->base_addr + 2)
|
||||
|
||||
#define RUNT 60 /* Too small Ethernet packet */
|
||||
#define GIANT 1514 /* largest legal size packet, no fcs */
|
||||
|
||||
/*
|
||||
* Force media with insmod:
|
||||
* insmod de620.o bnc=1
|
||||
* or
|
||||
* insmod de620.o utp=1
|
||||
*
|
||||
* Force io and/or irq with insmod:
|
||||
* insmod de620.o io=0x378 irq=7
|
||||
*
|
||||
* Make a clone skip the Ethernet-address range check:
|
||||
* insmod de620.o clone=1
|
||||
*/
|
||||
static int bnc;
|
||||
static int utp;
|
||||
static int io = DE620_IO;
|
||||
static int irq = DE620_IRQ;
|
||||
static int clone = DE620_CLONE;
|
||||
|
||||
static spinlock_t de620_lock;
|
||||
|
||||
module_param(bnc, int, 0);
|
||||
module_param(utp, int, 0);
|
||||
module_param(io, int, 0);
|
||||
module_param(irq, int, 0);
|
||||
module_param(clone, int, 0);
|
||||
MODULE_PARM_DESC(bnc, "DE-620 set BNC medium (0-1)");
|
||||
MODULE_PARM_DESC(utp, "DE-620 set UTP medium (0-1)");
|
||||
MODULE_PARM_DESC(io, "DE-620 I/O base address,required");
|
||||
MODULE_PARM_DESC(irq, "DE-620 IRQ number,required");
|
||||
MODULE_PARM_DESC(clone, "Check also for non-D-Link DE-620 clones (0-1)");
|
||||
|
||||
/***********************************************
|
||||
* *
|
||||
* Index to functions, as function prototypes. *
|
||||
* *
|
||||
***********************************************/
|
||||
|
||||
/*
|
||||
* Routines used internally. (See also "convenience macros.. below")
|
||||
*/
|
||||
|
||||
/* Put in the device structure. */
|
||||
static int de620_open(struct net_device *);
|
||||
static int de620_close(struct net_device *);
|
||||
static void de620_set_multicast_list(struct net_device *);
|
||||
static int de620_start_xmit(struct sk_buff *, struct net_device *);
|
||||
|
||||
/* Dispatch from interrupts. */
|
||||
static irqreturn_t de620_interrupt(int, void *);
|
||||
static int de620_rx_intr(struct net_device *);
|
||||
|
||||
/* Initialization */
|
||||
static int adapter_init(struct net_device *);
|
||||
static int read_eeprom(struct net_device *);
|
||||
|
||||
|
||||
/*
|
||||
* D-Link driver variables:
|
||||
*/
|
||||
#define SCR_DEF NIBBLEMODE |INTON | SLEEP | AUTOTX
|
||||
#define TCR_DEF RXPB /* not used: | TXSUCINT | T16INT */
|
||||
#define DE620_RX_START_PAGE 12 /* 12 pages (=3k) reserved for tx */
|
||||
#define DEF_NIC_CMD IRQEN | ICEN | DS1
|
||||
|
||||
static volatile byte NIC_Cmd;
|
||||
static volatile byte next_rx_page;
|
||||
static byte first_rx_page;
|
||||
static byte last_rx_page;
|
||||
static byte EIPRegister;
|
||||
|
||||
static struct nic {
|
||||
byte NodeID[6];
|
||||
byte RAM_Size;
|
||||
byte Model;
|
||||
byte Media;
|
||||
byte SCR;
|
||||
} nic_data;
|
||||
|
||||
/**********************************************************
|
||||
* *
|
||||
* Convenience macros/functions for D-Link DE-620 adapter *
|
||||
* *
|
||||
**********************************************************/
|
||||
#define de620_tx_buffs(dd) (inb(STATUS_PORT) & (TXBF0 | TXBF1))
|
||||
#define de620_flip_ds(dd) NIC_Cmd ^= DS0 | DS1; outb(NIC_Cmd, COMMAND_PORT);
|
||||
|
||||
/* Check for ready-status, and return a nibble (high 4 bits) for data input */
|
||||
#ifdef COUNT_LOOPS
|
||||
static int tot_cnt;
|
||||
#endif
|
||||
static inline byte
|
||||
de620_ready(struct net_device *dev)
|
||||
{
|
||||
byte value;
|
||||
register short int cnt = 0;
|
||||
|
||||
while ((((value = inb(STATUS_PORT)) & READY) == 0) && (cnt <= 1000))
|
||||
++cnt;
|
||||
|
||||
#ifdef COUNT_LOOPS
|
||||
tot_cnt += cnt;
|
||||
#endif
|
||||
return value & 0xf0; /* nibble */
|
||||
}
|
||||
|
||||
static inline void
|
||||
de620_send_command(struct net_device *dev, byte cmd)
|
||||
{
|
||||
de620_ready(dev);
|
||||
if (cmd == W_DUMMY)
|
||||
outb(NIC_Cmd, COMMAND_PORT);
|
||||
|
||||
outb(cmd, DATA_PORT);
|
||||
|
||||
outb(NIC_Cmd ^ CS0, COMMAND_PORT);
|
||||
de620_ready(dev);
|
||||
outb(NIC_Cmd, COMMAND_PORT);
|
||||
}
|
||||
|
||||
static inline void
|
||||
de620_put_byte(struct net_device *dev, byte value)
|
||||
{
|
||||
/* The de620_ready() makes 7 loops, on the average, on a DX2/66 */
|
||||
de620_ready(dev);
|
||||
outb(value, DATA_PORT);
|
||||
de620_flip_ds(dev);
|
||||
}
|
||||
|
||||
static inline byte
|
||||
de620_read_byte(struct net_device *dev)
|
||||
{
|
||||
byte value;
|
||||
|
||||
/* The de620_ready() makes 7 loops, on the average, on a DX2/66 */
|
||||
value = de620_ready(dev); /* High nibble */
|
||||
de620_flip_ds(dev);
|
||||
value |= de620_ready(dev) >> 4; /* Low nibble */
|
||||
return value;
|
||||
}
|
||||
|
||||
static inline void
|
||||
de620_write_block(struct net_device *dev, byte *buffer, int count, int pad)
|
||||
{
|
||||
#ifndef LOWSPEED
|
||||
byte uflip = NIC_Cmd ^ (DS0 | DS1);
|
||||
byte dflip = NIC_Cmd;
|
||||
#else /* LOWSPEED */
|
||||
#ifdef COUNT_LOOPS
|
||||
int bytes = count;
|
||||
#endif /* COUNT_LOOPS */
|
||||
#endif /* LOWSPEED */
|
||||
|
||||
#ifdef LOWSPEED
|
||||
#ifdef COUNT_LOOPS
|
||||
tot_cnt = 0;
|
||||
#endif /* COUNT_LOOPS */
|
||||
/* No further optimization useful, the limit is in the adapter. */
|
||||
for ( ; count > 0; --count, ++buffer) {
|
||||
de620_put_byte(dev,*buffer);
|
||||
}
|
||||
for ( count = pad ; count > 0; --count, ++buffer) {
|
||||
de620_put_byte(dev, 0);
|
||||
}
|
||||
de620_send_command(dev,W_DUMMY);
|
||||
#ifdef COUNT_LOOPS
|
||||
/* trial debug output: loops per byte in de620_ready() */
|
||||
printk("WRITE(%d)\n", tot_cnt/((bytes?bytes:1)));
|
||||
#endif /* COUNT_LOOPS */
|
||||
#else /* not LOWSPEED */
|
||||
for ( ; count > 0; count -=2) {
|
||||
outb(*buffer++, DATA_PORT);
|
||||
outb(uflip, COMMAND_PORT);
|
||||
outb(*buffer++, DATA_PORT);
|
||||
outb(dflip, COMMAND_PORT);
|
||||
}
|
||||
de620_send_command(dev,W_DUMMY);
|
||||
#endif /* LOWSPEED */
|
||||
}
|
||||
|
||||
static inline void
|
||||
de620_read_block(struct net_device *dev, byte *data, int count)
|
||||
{
|
||||
#ifndef LOWSPEED
|
||||
byte value;
|
||||
byte uflip = NIC_Cmd ^ (DS0 | DS1);
|
||||
byte dflip = NIC_Cmd;
|
||||
#else /* LOWSPEED */
|
||||
#ifdef COUNT_LOOPS
|
||||
int bytes = count;
|
||||
|
||||
tot_cnt = 0;
|
||||
#endif /* COUNT_LOOPS */
|
||||
#endif /* LOWSPEED */
|
||||
|
||||
#ifdef LOWSPEED
|
||||
/* No further optimization useful, the limit is in the adapter. */
|
||||
while (count-- > 0) {
|
||||
*data++ = de620_read_byte(dev);
|
||||
de620_flip_ds(dev);
|
||||
}
|
||||
#ifdef COUNT_LOOPS
|
||||
/* trial debug output: loops per byte in de620_ready() */
|
||||
printk("READ(%d)\n", tot_cnt/(2*(bytes?bytes:1)));
|
||||
#endif /* COUNT_LOOPS */
|
||||
#else /* not LOWSPEED */
|
||||
while (count-- > 0) {
|
||||
value = inb(STATUS_PORT) & 0xf0; /* High nibble */
|
||||
outb(uflip, COMMAND_PORT);
|
||||
*data++ = value | inb(STATUS_PORT) >> 4; /* Low nibble */
|
||||
outb(dflip , COMMAND_PORT);
|
||||
}
|
||||
#endif /* LOWSPEED */
|
||||
}
|
||||
|
||||
static inline void
|
||||
de620_set_delay(struct net_device *dev)
|
||||
{
|
||||
de620_ready(dev);
|
||||
outb(W_DFR, DATA_PORT);
|
||||
outb(NIC_Cmd ^ CS0, COMMAND_PORT);
|
||||
|
||||
de620_ready(dev);
|
||||
#ifdef LOWSPEED
|
||||
outb(WRITE_DELAY, DATA_PORT);
|
||||
#else
|
||||
outb(0, DATA_PORT);
|
||||
#endif
|
||||
de620_flip_ds(dev);
|
||||
|
||||
de620_ready(dev);
|
||||
#ifdef LOWSPEED
|
||||
outb(READ_DELAY, DATA_PORT);
|
||||
#else
|
||||
outb(0, DATA_PORT);
|
||||
#endif
|
||||
de620_flip_ds(dev);
|
||||
}
|
||||
|
||||
static inline void
|
||||
de620_set_register(struct net_device *dev, byte reg, byte value)
|
||||
{
|
||||
de620_ready(dev);
|
||||
outb(reg, DATA_PORT);
|
||||
outb(NIC_Cmd ^ CS0, COMMAND_PORT);
|
||||
|
||||
de620_put_byte(dev, value);
|
||||
}
|
||||
|
||||
static inline byte
|
||||
de620_get_register(struct net_device *dev, byte reg)
|
||||
{
|
||||
byte value;
|
||||
|
||||
de620_send_command(dev,reg);
|
||||
value = de620_read_byte(dev);
|
||||
de620_send_command(dev,W_DUMMY);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Open/initialize the board.
|
||||
*
|
||||
* This routine should set everything up anew at each open, even
|
||||
* registers that "should" only need to be set once at boot, so that
|
||||
* there is a non-reboot way to recover if something goes wrong.
|
||||
*
|
||||
*/
|
||||
static int de620_open(struct net_device *dev)
|
||||
{
|
||||
int ret = request_irq(dev->irq, de620_interrupt, 0, dev->name, dev);
|
||||
if (ret) {
|
||||
printk (KERN_ERR "%s: unable to get IRQ %d\n", dev->name, dev->irq);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (adapter_init(dev)) {
|
||||
ret = -EIO;
|
||||
goto out_free_irq;
|
||||
}
|
||||
|
||||
netif_start_queue(dev);
|
||||
return 0;
|
||||
|
||||
out_free_irq:
|
||||
free_irq(dev->irq, dev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/************************************************
|
||||
*
|
||||
* The inverse routine to de620_open().
|
||||
*
|
||||
*/
|
||||
|
||||
static int de620_close(struct net_device *dev)
|
||||
{
|
||||
netif_stop_queue(dev);
|
||||
/* disable recv */
|
||||
de620_set_register(dev, W_TCR, RXOFF);
|
||||
free_irq(dev->irq, dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************
|
||||
*
|
||||
* Set or clear the multicast filter for this adaptor.
|
||||
* (no real multicast implemented for the DE-620, but she can be promiscuous...)
|
||||
*
|
||||
*/
|
||||
|
||||
static void de620_set_multicast_list(struct net_device *dev)
|
||||
{
|
||||
if (!netdev_mc_empty(dev) || dev->flags&(IFF_ALLMULTI|IFF_PROMISC))
|
||||
{ /* Enable promiscuous mode */
|
||||
de620_set_register(dev, W_TCR, (TCR_DEF & ~RXPBM) | RXALL);
|
||||
}
|
||||
else
|
||||
{ /* Disable promiscuous mode, use normal mode */
|
||||
de620_set_register(dev, W_TCR, TCR_DEF);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************
|
||||
*
|
||||
* Handle timeouts on transmit
|
||||
*/
|
||||
|
||||
static void de620_timeout(struct net_device *dev)
|
||||
{
|
||||
printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name, "network cable problem");
|
||||
/* Restart the adapter. */
|
||||
if (!adapter_init(dev)) /* maybe close it */
|
||||
netif_wake_queue(dev);
|
||||
}
|
||||
|
||||
/*******************************************************
|
||||
*
|
||||
* Copy a buffer to the adapter transmit page memory.
|
||||
* Start sending.
|
||||
*/
|
||||
static int de620_start_xmit(struct sk_buff *skb, struct net_device *dev)
|
||||
{
|
||||
unsigned long flags;
|
||||
int len;
|
||||
byte *buffer = skb->data;
|
||||
byte using_txbuf;
|
||||
|
||||
using_txbuf = de620_tx_buffs(dev); /* Peek at the adapter */
|
||||
|
||||
netif_stop_queue(dev);
|
||||
|
||||
|
||||
if ((len = skb->len) < RUNT)
|
||||
len = RUNT;
|
||||
if (len & 1) /* send an even number of bytes */
|
||||
++len;
|
||||
|
||||
/* Start real output */
|
||||
|
||||
spin_lock_irqsave(&de620_lock, flags);
|
||||
pr_debug("de620_start_xmit: len=%d, bufs 0x%02x\n",
|
||||
(int)skb->len, using_txbuf);
|
||||
|
||||
/* select a free tx buffer. if there is one... */
|
||||
switch (using_txbuf) {
|
||||
default: /* both are free: use TXBF0 */
|
||||
case TXBF1: /* use TXBF0 */
|
||||
de620_send_command(dev,W_CR | RW0);
|
||||
using_txbuf |= TXBF0;
|
||||
break;
|
||||
|
||||
case TXBF0: /* use TXBF1 */
|
||||
de620_send_command(dev,W_CR | RW1);
|
||||
using_txbuf |= TXBF1;
|
||||
break;
|
||||
|
||||
case (TXBF0 | TXBF1): /* NONE!!! */
|
||||
printk(KERN_WARNING "%s: No tx-buffer available!\n", dev->name);
|
||||
spin_unlock_irqrestore(&de620_lock, flags);
|
||||
return NETDEV_TX_BUSY;
|
||||
}
|
||||
de620_write_block(dev, buffer, skb->len, len-skb->len);
|
||||
|
||||
if(!(using_txbuf == (TXBF0 | TXBF1)))
|
||||
netif_wake_queue(dev);
|
||||
|
||||
dev->stats.tx_packets++;
|
||||
spin_unlock_irqrestore(&de620_lock, flags);
|
||||
dev_kfree_skb (skb);
|
||||
return NETDEV_TX_OK;
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
*
|
||||
* Handle the network interface interrupts.
|
||||
*
|
||||
*/
|
||||
static irqreturn_t
|
||||
de620_interrupt(int irq_in, void *dev_id)
|
||||
{
|
||||
struct net_device *dev = dev_id;
|
||||
byte irq_status;
|
||||
int bogus_count = 0;
|
||||
int again = 0;
|
||||
|
||||
spin_lock(&de620_lock);
|
||||
|
||||
/* Read the status register (_not_ the status port) */
|
||||
irq_status = de620_get_register(dev, R_STS);
|
||||
|
||||
pr_debug("de620_interrupt (%2.2X)\n", irq_status);
|
||||
|
||||
if (irq_status & RXGOOD) {
|
||||
do {
|
||||
again = de620_rx_intr(dev);
|
||||
pr_debug("again=%d\n", again);
|
||||
}
|
||||
while (again && (++bogus_count < 100));
|
||||
}
|
||||
|
||||
if(de620_tx_buffs(dev) != (TXBF0 | TXBF1))
|
||||
netif_wake_queue(dev);
|
||||
|
||||
spin_unlock(&de620_lock);
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
/**************************************
|
||||
*
|
||||
* Get a packet from the adapter
|
||||
*
|
||||
* Send it "upstairs"
|
||||
*
|
||||
*/
|
||||
static int de620_rx_intr(struct net_device *dev)
|
||||
{
|
||||
struct header_buf {
|
||||
byte status;
|
||||
byte Rx_NextPage;
|
||||
unsigned short Rx_ByteCount;
|
||||
} header_buf;
|
||||
struct sk_buff *skb;
|
||||
int size;
|
||||
byte *buffer;
|
||||
byte pagelink;
|
||||
byte curr_page;
|
||||
|
||||
pr_debug("de620_rx_intr: next_rx_page = %d\n", next_rx_page);
|
||||
|
||||
/* Tell the adapter that we are going to read data, and from where */
|
||||
de620_send_command(dev, W_CR | RRN);
|
||||
de620_set_register(dev, W_RSA1, next_rx_page);
|
||||
de620_set_register(dev, W_RSA0, 0);
|
||||
|
||||
/* Deep breath, and away we goooooo */
|
||||
de620_read_block(dev, (byte *)&header_buf, sizeof(struct header_buf));
|
||||
pr_debug("page status=0x%02x, nextpage=%d, packetsize=%d\n",
|
||||
header_buf.status, header_buf.Rx_NextPage,
|
||||
header_buf.Rx_ByteCount);
|
||||
|
||||
/* Plausible page header? */
|
||||
pagelink = header_buf.Rx_NextPage;
|
||||
if ((pagelink < first_rx_page) || (last_rx_page < pagelink)) {
|
||||
/* Ouch... Forget it! Skip all and start afresh... */
|
||||
printk(KERN_WARNING "%s: Ring overrun? Restoring...\n", dev->name);
|
||||
/* You win some, you lose some. And sometimes plenty... */
|
||||
adapter_init(dev);
|
||||
netif_wake_queue(dev);
|
||||
dev->stats.rx_over_errors++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* OK, this look good, so far. Let's see if it's consistent... */
|
||||
/* Let's compute the start of the next packet, based on where we are */
|
||||
pagelink = next_rx_page +
|
||||
((header_buf.Rx_ByteCount + (4 - 1 + 0x100)) >> 8);
|
||||
|
||||
/* Are we going to wrap around the page counter? */
|
||||
if (pagelink > last_rx_page)
|
||||
pagelink -= (last_rx_page - first_rx_page + 1);
|
||||
|
||||
/* Is the _computed_ next page number equal to what the adapter says? */
|
||||
if (pagelink != header_buf.Rx_NextPage) {
|
||||
/* Naah, we'll skip this packet. Probably bogus data as well */
|
||||
printk(KERN_WARNING "%s: Page link out of sync! Restoring...\n", dev->name);
|
||||
next_rx_page = header_buf.Rx_NextPage; /* at least a try... */
|
||||
de620_send_command(dev, W_DUMMY);
|
||||
de620_set_register(dev, W_NPRF, next_rx_page);
|
||||
dev->stats.rx_over_errors++;
|
||||
return 0;
|
||||
}
|
||||
next_rx_page = pagelink;
|
||||
|
||||
size = header_buf.Rx_ByteCount - 4;
|
||||
if ((size < RUNT) || (GIANT < size)) {
|
||||
printk(KERN_WARNING "%s: Illegal packet size: %d!\n", dev->name, size);
|
||||
}
|
||||
else { /* Good packet? */
|
||||
skb = dev_alloc_skb(size+2);
|
||||
if (skb == NULL) { /* Yeah, but no place to put it... */
|
||||
printk(KERN_WARNING "%s: Couldn't allocate a sk_buff of size %d.\n", dev->name, size);
|
||||
dev->stats.rx_dropped++;
|
||||
}
|
||||
else { /* Yep! Go get it! */
|
||||
skb_reserve(skb,2); /* Align */
|
||||
/* skb->data points to the start of sk_buff data area */
|
||||
buffer = skb_put(skb,size);
|
||||
/* copy the packet into the buffer */
|
||||
de620_read_block(dev, buffer, size);
|
||||
pr_debug("Read %d bytes\n", size);
|
||||
skb->protocol=eth_type_trans(skb,dev);
|
||||
netif_rx(skb); /* deliver it "upstairs" */
|
||||
/* count all receives */
|
||||
dev->stats.rx_packets++;
|
||||
dev->stats.rx_bytes += size;
|
||||
}
|
||||
}
|
||||
|
||||
/* Let's peek ahead to see if we have read the last current packet */
|
||||
/* NOTE! We're _not_ checking the 'EMPTY'-flag! This seems better... */
|
||||
curr_page = de620_get_register(dev, R_CPR);
|
||||
de620_set_register(dev, W_NPRF, next_rx_page);
|
||||
pr_debug("next_rx_page=%d CPR=%d\n", next_rx_page, curr_page);
|
||||
|
||||
return next_rx_page != curr_page; /* That was slightly tricky... */
|
||||
}
|
||||
|
||||
/*********************************************
|
||||
*
|
||||
* Reset the adapter to a known state
|
||||
*
|
||||
*/
|
||||
static int adapter_init(struct net_device *dev)
|
||||
{
|
||||
int i;
|
||||
static int was_down;
|
||||
|
||||
if ((nic_data.Model == 3) || (nic_data.Model == 0)) { /* CT */
|
||||
EIPRegister = NCTL0;
|
||||
if (nic_data.Media != 1)
|
||||
EIPRegister |= NIS0; /* not BNC */
|
||||
}
|
||||
else if (nic_data.Model == 2) { /* UTP */
|
||||
EIPRegister = NCTL0 | NIS0;
|
||||
}
|
||||
|
||||
if (utp)
|
||||
EIPRegister = NCTL0 | NIS0;
|
||||
if (bnc)
|
||||
EIPRegister = NCTL0;
|
||||
|
||||
de620_send_command(dev, W_CR | RNOP | CLEAR);
|
||||
de620_send_command(dev, W_CR | RNOP);
|
||||
|
||||
de620_set_register(dev, W_SCR, SCR_DEF);
|
||||
/* disable recv to wait init */
|
||||
de620_set_register(dev, W_TCR, RXOFF);
|
||||
|
||||
/* Set the node ID in the adapter */
|
||||
for (i = 0; i < 6; ++i) { /* W_PARn = 0xaa + n */
|
||||
de620_set_register(dev, W_PAR0 + i, dev->dev_addr[i]);
|
||||
}
|
||||
|
||||
de620_set_register(dev, W_EIP, EIPRegister);
|
||||
|
||||
next_rx_page = first_rx_page = DE620_RX_START_PAGE;
|
||||
if (nic_data.RAM_Size)
|
||||
last_rx_page = nic_data.RAM_Size - 1;
|
||||
else /* 64k RAM */
|
||||
last_rx_page = 255;
|
||||
|
||||
de620_set_register(dev, W_SPR, first_rx_page); /* Start Page Register*/
|
||||
de620_set_register(dev, W_EPR, last_rx_page); /* End Page Register */
|
||||
de620_set_register(dev, W_CPR, first_rx_page);/*Current Page Register*/
|
||||
de620_send_command(dev, W_NPR | first_rx_page); /* Next Page Register*/
|
||||
de620_send_command(dev, W_DUMMY);
|
||||
de620_set_delay(dev);
|
||||
|
||||
/* Final sanity check: Anybody out there? */
|
||||
/* Let's hope some bits from the statusregister make a good check */
|
||||
#define CHECK_MASK ( 0 | TXSUC | T16 | 0 | RXCRC | RXSHORT | 0 | 0 )
|
||||
#define CHECK_OK ( 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 )
|
||||
/* success: X 0 0 X 0 0 X X */
|
||||
/* ignore: EEDI RXGOOD COLS LNKS*/
|
||||
|
||||
if (((i = de620_get_register(dev, R_STS)) & CHECK_MASK) != CHECK_OK) {
|
||||
printk(KERN_ERR "%s: Something has happened to the DE-620! Please check it"
|
||||
#ifdef SHUTDOWN_WHEN_LOST
|
||||
" and do a new ifconfig"
|
||||
#endif
|
||||
"! (%02x)\n", dev->name, i);
|
||||
#ifdef SHUTDOWN_WHEN_LOST
|
||||
/* Goodbye, cruel world... */
|
||||
dev->flags &= ~IFF_UP;
|
||||
de620_close(dev);
|
||||
#endif
|
||||
was_down = 1;
|
||||
return 1; /* failed */
|
||||
}
|
||||
if (was_down) {
|
||||
printk(KERN_WARNING "%s: Thanks, I feel much better now!\n", dev->name);
|
||||
was_down = 0;
|
||||
}
|
||||
|
||||
/* All OK, go ahead... */
|
||||
de620_set_register(dev, W_TCR, TCR_DEF);
|
||||
|
||||
return 0; /* all ok */
|
||||
}
|
||||
|
||||
static const struct net_device_ops de620_netdev_ops = {
|
||||
.ndo_open = de620_open,
|
||||
.ndo_stop = de620_close,
|
||||
.ndo_start_xmit = de620_start_xmit,
|
||||
.ndo_tx_timeout = de620_timeout,
|
||||
.ndo_set_multicast_list = de620_set_multicast_list,
|
||||
.ndo_change_mtu = eth_change_mtu,
|
||||
.ndo_set_mac_address = eth_mac_addr,
|
||||
.ndo_validate_addr = eth_validate_addr,
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Only start-up code below
|
||||
*
|
||||
*/
|
||||
/****************************************
|
||||
*
|
||||
* Check if there is a DE-620 connected
|
||||
*/
|
||||
struct net_device * __init de620_probe(int unit)
|
||||
{
|
||||
byte checkbyte = 0xa5;
|
||||
struct net_device *dev;
|
||||
int err = -ENOMEM;
|
||||
int i;
|
||||
|
||||
dev = alloc_etherdev(0);
|
||||
if (!dev)
|
||||
goto out;
|
||||
|
||||
spin_lock_init(&de620_lock);
|
||||
|
||||
/*
|
||||
* This is where the base_addr and irq gets set.
|
||||
* Tunable at compile-time and insmod-time
|
||||
*/
|
||||
dev->base_addr = io;
|
||||
dev->irq = irq;
|
||||
|
||||
/* allow overriding parameters on command line */
|
||||
if (unit >= 0) {
|
||||
sprintf(dev->name, "eth%d", unit);
|
||||
netdev_boot_setup_check(dev);
|
||||
}
|
||||
|
||||
pr_debug("%s", version);
|
||||
|
||||
printk(KERN_INFO "D-Link DE-620 pocket adapter");
|
||||
|
||||
if (!request_region(dev->base_addr, 3, "de620")) {
|
||||
printk(" io 0x%3lX, which is busy.\n", dev->base_addr);
|
||||
err = -EBUSY;
|
||||
goto out1;
|
||||
}
|
||||
|
||||
/* Initially, configure basic nibble mode, so we can read the EEPROM */
|
||||
NIC_Cmd = DEF_NIC_CMD;
|
||||
de620_set_register(dev, W_EIP, EIPRegister);
|
||||
|
||||
/* Anybody out there? */
|
||||
de620_set_register(dev, W_CPR, checkbyte);
|
||||
checkbyte = de620_get_register(dev, R_CPR);
|
||||
|
||||
if ((checkbyte != 0xa5) || (read_eeprom(dev) != 0)) {
|
||||
printk(" not identified in the printer port\n");
|
||||
err = -ENODEV;
|
||||
goto out2;
|
||||
}
|
||||
|
||||
/* else, got it! */
|
||||
dev->dev_addr[0] = nic_data.NodeID[0];
|
||||
for (i = 1; i < ETH_ALEN; i++) {
|
||||
dev->dev_addr[i] = nic_data.NodeID[i];
|
||||
dev->broadcast[i] = 0xff;
|
||||
}
|
||||
|
||||
printk(", Ethernet Address: %pM", dev->dev_addr);
|
||||
|
||||
printk(" (%dk RAM,",
|
||||
(nic_data.RAM_Size) ? (nic_data.RAM_Size >> 2) : 64);
|
||||
|
||||
if (nic_data.Media == 1)
|
||||
printk(" BNC)\n");
|
||||
else
|
||||
printk(" UTP)\n");
|
||||
|
||||
dev->netdev_ops = &de620_netdev_ops;
|
||||
dev->watchdog_timeo = HZ*2;
|
||||
|
||||
/* base_addr and irq are already set, see above! */
|
||||
|
||||
/* dump eeprom */
|
||||
pr_debug("\nEEPROM contents:\n"
|
||||
"RAM_Size = 0x%02X\n"
|
||||
"NodeID = %pM\n"
|
||||
"Model = %d\n"
|
||||
"Media = %d\n"
|
||||
"SCR = 0x%02x\n", nic_data.RAM_Size, nic_data.NodeID,
|
||||
nic_data.Model, nic_data.Media, nic_data.SCR);
|
||||
|
||||
err = register_netdev(dev);
|
||||
if (err)
|
||||
goto out2;
|
||||
return dev;
|
||||
|
||||
out2:
|
||||
release_region(dev->base_addr, 3);
|
||||
out1:
|
||||
free_netdev(dev);
|
||||
out:
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
|
||||
/**********************************
|
||||
*
|
||||
* Read info from on-board EEPROM
|
||||
*
|
||||
* Note: Bitwise serial I/O to/from the EEPROM vi the status _register_!
|
||||
*/
|
||||
#define sendit(dev,data) de620_set_register(dev, W_EIP, data | EIPRegister);
|
||||
|
||||
static unsigned short __init ReadAWord(struct net_device *dev, int from)
|
||||
{
|
||||
unsigned short data;
|
||||
int nbits;
|
||||
|
||||
/* cs [__~~] SET SEND STATE */
|
||||
/* di [____] */
|
||||
/* sck [_~~_] */
|
||||
sendit(dev, 0); sendit(dev, 1); sendit(dev, 5); sendit(dev, 4);
|
||||
|
||||
/* Send the 9-bit address from where we want to read the 16-bit word */
|
||||
for (nbits = 9; nbits > 0; --nbits, from <<= 1) {
|
||||
if (from & 0x0100) { /* bit set? */
|
||||
/* cs [~~~~] SEND 1 */
|
||||
/* di [~~~~] */
|
||||
/* sck [_~~_] */
|
||||
sendit(dev, 6); sendit(dev, 7); sendit(dev, 7); sendit(dev, 6);
|
||||
}
|
||||
else {
|
||||
/* cs [~~~~] SEND 0 */
|
||||
/* di [____] */
|
||||
/* sck [_~~_] */
|
||||
sendit(dev, 4); sendit(dev, 5); sendit(dev, 5); sendit(dev, 4);
|
||||
}
|
||||
}
|
||||
|
||||
/* Shift in the 16-bit word. The bits appear serially in EEDI (=0x80) */
|
||||
for (data = 0, nbits = 16; nbits > 0; --nbits) {
|
||||
/* cs [~~~~] SEND 0 */
|
||||
/* di [____] */
|
||||
/* sck [_~~_] */
|
||||
sendit(dev, 4); sendit(dev, 5); sendit(dev, 5); sendit(dev, 4);
|
||||
data = (data << 1) | ((de620_get_register(dev, R_STS) & EEDI) >> 7);
|
||||
}
|
||||
/* cs [____] RESET SEND STATE */
|
||||
/* di [____] */
|
||||
/* sck [_~~_] */
|
||||
sendit(dev, 0); sendit(dev, 1); sendit(dev, 1); sendit(dev, 0);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static int __init read_eeprom(struct net_device *dev)
|
||||
{
|
||||
unsigned short wrd;
|
||||
|
||||
/* D-Link Ethernet addresses are in the series 00:80:c8:7X:XX:XX:XX */
|
||||
wrd = ReadAWord(dev, 0x1aa); /* bytes 0 + 1 of NodeID */
|
||||
if (!clone && (wrd != htons(0x0080))) /* Valid D-Link ether sequence? */
|
||||
return -1; /* Nope, not a DE-620 */
|
||||
nic_data.NodeID[0] = wrd & 0xff;
|
||||
nic_data.NodeID[1] = wrd >> 8;
|
||||
|
||||
wrd = ReadAWord(dev, 0x1ab); /* bytes 2 + 3 of NodeID */
|
||||
if (!clone && ((wrd & 0xff) != 0xc8)) /* Valid D-Link ether sequence? */
|
||||
return -1; /* Nope, not a DE-620 */
|
||||
nic_data.NodeID[2] = wrd & 0xff;
|
||||
nic_data.NodeID[3] = wrd >> 8;
|
||||
|
||||
wrd = ReadAWord(dev, 0x1ac); /* bytes 4 + 5 of NodeID */
|
||||
nic_data.NodeID[4] = wrd & 0xff;
|
||||
nic_data.NodeID[5] = wrd >> 8;
|
||||
|
||||
wrd = ReadAWord(dev, 0x1ad); /* RAM size in pages (256 bytes). 0 = 64k */
|
||||
nic_data.RAM_Size = (wrd >> 8);
|
||||
|
||||
wrd = ReadAWord(dev, 0x1ae); /* hardware model (CT = 3) */
|
||||
nic_data.Model = (wrd & 0xff);
|
||||
|
||||
wrd = ReadAWord(dev, 0x1af); /* media (indicates BNC/UTP) */
|
||||
nic_data.Media = (wrd & 0xff);
|
||||
|
||||
wrd = ReadAWord(dev, 0x1a8); /* System Configuration Register */
|
||||
nic_data.SCR = (wrd >> 8);
|
||||
|
||||
return 0; /* no errors */
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Loadable module skeleton
|
||||
*
|
||||
*/
|
||||
#ifdef MODULE
|
||||
static struct net_device *de620_dev;
|
||||
|
||||
int __init init_module(void)
|
||||
{
|
||||
de620_dev = de620_probe(-1);
|
||||
if (IS_ERR(de620_dev))
|
||||
return PTR_ERR(de620_dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cleanup_module(void)
|
||||
{
|
||||
unregister_netdev(de620_dev);
|
||||
release_region(de620_dev->base_addr, 3);
|
||||
free_netdev(de620_dev);
|
||||
}
|
||||
#endif /* MODULE */
|
||||
MODULE_LICENSE("GPL");
|
117
drivers/net/ethernet/dlink/de620.h
Normal file
117
drivers/net/ethernet/dlink/de620.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/*********************************************************
|
||||
* *
|
||||
* Definition of D-Link DE-620 Ethernet Pocket adapter *
|
||||
* *
|
||||
*********************************************************/
|
||||
|
||||
/* DE-620's CMD port Command */
|
||||
#define CS0 0x08 /* 1->0 command strobe */
|
||||
#define ICEN 0x04 /* 0=enable DL3520 host interface */
|
||||
#define DS0 0x02 /* 1->0 data strobe 0 */
|
||||
#define DS1 0x01 /* 1->0 data strobe 1 */
|
||||
|
||||
#define WDIR 0x20 /* general 0=read 1=write */
|
||||
#define RDIR 0x00 /* (not 100% confirm ) */
|
||||
#define PS2WDIR 0x00 /* ps/2 mode 1=read, 0=write */
|
||||
#define PS2RDIR 0x20
|
||||
|
||||
#define IRQEN 0x10 /* 1 = enable printer IRQ line */
|
||||
#define SELECTIN 0x08 /* 1 = select printer */
|
||||
#define INITP 0x04 /* 0 = initial printer */
|
||||
#define AUTOFEED 0x02 /* 1 = printer auto form feed */
|
||||
#define STROBE 0x01 /* 0->1 data strobe */
|
||||
|
||||
#define RESET 0x08
|
||||
#define NIS0 0x20 /* 0 = BNC, 1 = UTP */
|
||||
#define NCTL0 0x10
|
||||
|
||||
/* DE-620 DIC Command */
|
||||
#define W_DUMMY 0x00 /* DIC reserved command */
|
||||
#define W_CR 0x20 /* DIC write command register */
|
||||
#define W_NPR 0x40 /* DIC write Next Page Register */
|
||||
#define W_TBR 0x60 /* DIC write Tx Byte Count 1 reg */
|
||||
#define W_RSA 0x80 /* DIC write Remote Start Addr 1 */
|
||||
|
||||
/* DE-620's STAT port bits 7-4 */
|
||||
#define EMPTY 0x80 /* 1 = receive buffer empty */
|
||||
#define INTLEVEL 0x40 /* 1 = interrupt level is high */
|
||||
#define TXBF1 0x20 /* 1 = transmit buffer 1 is in use */
|
||||
#define TXBF0 0x10 /* 1 = transmit buffer 0 is in use */
|
||||
#define READY 0x08 /* 1 = h/w ready to accept cmd/data */
|
||||
|
||||
/* IDC 1 Command */
|
||||
#define W_RSA1 0xa0 /* write remote start address 1 */
|
||||
#define W_RSA0 0xa1 /* write remote start address 0 */
|
||||
#define W_NPRF 0xa2 /* write next page register NPR15-NPR8 */
|
||||
#define W_DFR 0xa3 /* write delay factor register */
|
||||
#define W_CPR 0xa4 /* write current page register */
|
||||
#define W_SPR 0xa5 /* write start page register */
|
||||
#define W_EPR 0xa6 /* write end page register */
|
||||
#define W_SCR 0xa7 /* write system configuration register */
|
||||
#define W_TCR 0xa8 /* write Transceiver Configuration reg */
|
||||
#define W_EIP 0xa9 /* write EEPM Interface port */
|
||||
#define W_PAR0 0xaa /* write physical address register 0 */
|
||||
#define W_PAR1 0xab /* write physical address register 1 */
|
||||
#define W_PAR2 0xac /* write physical address register 2 */
|
||||
#define W_PAR3 0xad /* write physical address register 3 */
|
||||
#define W_PAR4 0xae /* write physical address register 4 */
|
||||
#define W_PAR5 0xaf /* write physical address register 5 */
|
||||
|
||||
/* IDC 2 Command */
|
||||
#define R_STS 0xc0 /* read status register */
|
||||
#define R_CPR 0xc1 /* read current page register */
|
||||
#define R_BPR 0xc2 /* read boundary page register */
|
||||
#define R_TDR 0xc3 /* read time domain reflectometry reg */
|
||||
|
||||
/* STATUS Register */
|
||||
#define EEDI 0x80 /* EEPM DO pin */
|
||||
#define TXSUC 0x40 /* tx success */
|
||||
#define T16 0x20 /* tx fail 16 times */
|
||||
#define TS1 0x40 /* 0=Tx success, 1=T16 */
|
||||
#define TS0 0x20 /* 0=Tx success, 1=T16 */
|
||||
#define RXGOOD 0x10 /* rx a good packet */
|
||||
#define RXCRC 0x08 /* rx a CRC error packet */
|
||||
#define RXSHORT 0x04 /* rx a short packet */
|
||||
#define COLS 0x02 /* coaxial collision status */
|
||||
#define LNKS 0x01 /* UTP link status */
|
||||
|
||||
/* Command Register */
|
||||
#define CLEAR 0x10 /* reset part of hardware */
|
||||
#define NOPER 0x08 /* No Operation */
|
||||
#define RNOP 0x08
|
||||
#define RRA 0x06 /* After RR then auto-advance NPR & BPR(=NPR-1) */
|
||||
#define RRN 0x04 /* Normal Remote Read mode */
|
||||
#define RW1 0x02 /* Remote Write tx buffer 1 ( page 6 - 11 ) */
|
||||
#define RW0 0x00 /* Remote Write tx buffer 0 ( page 0 - 5 ) */
|
||||
#define TXEN 0x01 /* 0->1 tx enable */
|
||||
|
||||
/* System Configuration Register */
|
||||
#define TESTON 0x80 /* test host data transfer reliability */
|
||||
#define SLEEP 0x40 /* sleep mode */
|
||||
#if 0
|
||||
#define FASTMODE 0x04 /* fast mode for intel 82360SL fast mode */
|
||||
#define BYTEMODE 0x02 /* byte mode */
|
||||
#else
|
||||
#define FASTMODE 0x20 /* fast mode for intel 82360SL fast mode */
|
||||
#define BYTEMODE 0x10 /* byte mode */
|
||||
#endif
|
||||
#define NIBBLEMODE 0x00 /* nibble mode */
|
||||
#define IRQINV 0x08 /* turn off IRQ line inverter */
|
||||
#define IRQNML 0x00 /* turn on IRQ line inverter */
|
||||
#define INTON 0x04
|
||||
#define AUTOFFSET 0x02 /* auto shift address to TPR+12 */
|
||||
#define AUTOTX 0x01 /* auto tx when leave RW mode */
|
||||
|
||||
/* Transceiver Configuration Register */
|
||||
#define JABBER 0x80 /* generate jabber condition */
|
||||
#define TXSUCINT 0x40 /* enable tx success interrupt */
|
||||
#define T16INT 0x20 /* enable T16 interrupt */
|
||||
#define RXERRPKT 0x10 /* accept CRC error or short packet */
|
||||
#define EXTERNALB2 0x0C /* external loopback 2 */
|
||||
#define EXTERNALB1 0x08 /* external loopback 1 */
|
||||
#define INTERNALB 0x04 /* internal loopback */
|
||||
#define NMLOPERATE 0x00 /* normal operation */
|
||||
#define RXPBM 0x03 /* rx physical, broadcast, multicast */
|
||||
#define RXPB 0x02 /* rx physical, broadcast */
|
||||
#define RXALL 0x01 /* rx all packet */
|
||||
#define RXOFF 0x00 /* rx disable */
|
1824
drivers/net/ethernet/dlink/dl2k.c
Normal file
1824
drivers/net/ethernet/dlink/dl2k.c
Normal file
File diff suppressed because it is too large
Load Diff
554
drivers/net/ethernet/dlink/dl2k.h
Normal file
554
drivers/net/ethernet/dlink/dl2k.h
Normal file
@@ -0,0 +1,554 @@
|
||||
/* D-Link DL2000-based Gigabit Ethernet Adapter Linux driver */
|
||||
/*
|
||||
Copyright (c) 2001, 2002 by D-Link Corporation
|
||||
Written by Edward Peng.<edward_peng@dlink.com.tw>
|
||||
Created 03-May-2001, base on Linux' sundance.c.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
*/
|
||||
|
||||
#ifndef __DL2K_H__
|
||||
#define __DL2K_H__
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/timer.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/crc32.h>
|
||||
#include <linux/ethtool.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <asm/processor.h> /* Processor type for cache alignment. */
|
||||
#include <asm/io.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/time.h>
|
||||
#define TX_RING_SIZE 256
|
||||
#define TX_QUEUE_LEN (TX_RING_SIZE - 1) /* Limit ring entries actually used.*/
|
||||
#define RX_RING_SIZE 256
|
||||
#define TX_TOTAL_SIZE TX_RING_SIZE*sizeof(struct netdev_desc)
|
||||
#define RX_TOTAL_SIZE RX_RING_SIZE*sizeof(struct netdev_desc)
|
||||
|
||||
/* This driver was written to use PCI memory space, however x86-oriented
|
||||
hardware often uses I/O space accesses. */
|
||||
#ifndef MEM_MAPPING
|
||||
#undef readb
|
||||
#undef readw
|
||||
#undef readl
|
||||
#undef writeb
|
||||
#undef writew
|
||||
#undef writel
|
||||
#define readb inb
|
||||
#define readw inw
|
||||
#define readl inl
|
||||
#define writeb outb
|
||||
#define writew outw
|
||||
#define writel outl
|
||||
#endif
|
||||
|
||||
/* Offsets to the device registers.
|
||||
Unlike software-only systems, device drivers interact with complex hardware.
|
||||
It's not useful to define symbolic names for every register bit in the
|
||||
device. The name can only partially document the semantics and make
|
||||
the driver longer and more difficult to read.
|
||||
In general, only the important configuration values or bits changed
|
||||
multiple times should be defined symbolically.
|
||||
*/
|
||||
enum dl2x_offsets {
|
||||
/* I/O register offsets */
|
||||
DMACtrl = 0x00,
|
||||
RxDMAStatus = 0x08,
|
||||
TFDListPtr0 = 0x10,
|
||||
TFDListPtr1 = 0x14,
|
||||
TxDMABurstThresh = 0x18,
|
||||
TxDMAUrgentThresh = 0x19,
|
||||
TxDMAPollPeriod = 0x1a,
|
||||
RFDListPtr0 = 0x1c,
|
||||
RFDListPtr1 = 0x20,
|
||||
RxDMABurstThresh = 0x24,
|
||||
RxDMAUrgentThresh = 0x25,
|
||||
RxDMAPollPeriod = 0x26,
|
||||
RxDMAIntCtrl = 0x28,
|
||||
DebugCtrl = 0x2c,
|
||||
ASICCtrl = 0x30,
|
||||
FifoCtrl = 0x38,
|
||||
RxEarlyThresh = 0x3a,
|
||||
FlowOffThresh = 0x3c,
|
||||
FlowOnThresh = 0x3e,
|
||||
TxStartThresh = 0x44,
|
||||
EepromData = 0x48,
|
||||
EepromCtrl = 0x4a,
|
||||
ExpromAddr = 0x4c,
|
||||
Exprodata = 0x50,
|
||||
WakeEvent = 0x51,
|
||||
CountDown = 0x54,
|
||||
IntStatusAck = 0x5a,
|
||||
IntEnable = 0x5c,
|
||||
IntStatus = 0x5e,
|
||||
TxStatus = 0x60,
|
||||
MACCtrl = 0x6c,
|
||||
VLANTag = 0x70,
|
||||
PhyCtrl = 0x76,
|
||||
StationAddr0 = 0x78,
|
||||
StationAddr1 = 0x7a,
|
||||
StationAddr2 = 0x7c,
|
||||
VLANId = 0x80,
|
||||
MaxFrameSize = 0x86,
|
||||
ReceiveMode = 0x88,
|
||||
HashTable0 = 0x8c,
|
||||
HashTable1 = 0x90,
|
||||
RmonStatMask = 0x98,
|
||||
StatMask = 0x9c,
|
||||
RxJumboFrames = 0xbc,
|
||||
TCPCheckSumErrors = 0xc0,
|
||||
IPCheckSumErrors = 0xc2,
|
||||
UDPCheckSumErrors = 0xc4,
|
||||
TxJumboFrames = 0xf4,
|
||||
/* Ethernet MIB statistic register offsets */
|
||||
OctetRcvOk = 0xa8,
|
||||
McstOctetRcvOk = 0xac,
|
||||
BcstOctetRcvOk = 0xb0,
|
||||
FramesRcvOk = 0xb4,
|
||||
McstFramesRcvdOk = 0xb8,
|
||||
BcstFramesRcvdOk = 0xbe,
|
||||
MacControlFramesRcvd = 0xc6,
|
||||
FrameTooLongErrors = 0xc8,
|
||||
InRangeLengthErrors = 0xca,
|
||||
FramesCheckSeqErrors = 0xcc,
|
||||
FramesLostRxErrors = 0xce,
|
||||
OctetXmtOk = 0xd0,
|
||||
McstOctetXmtOk = 0xd4,
|
||||
BcstOctetXmtOk = 0xd8,
|
||||
FramesXmtOk = 0xdc,
|
||||
McstFramesXmtdOk = 0xe0,
|
||||
FramesWDeferredXmt = 0xe4,
|
||||
LateCollisions = 0xe8,
|
||||
MultiColFrames = 0xec,
|
||||
SingleColFrames = 0xf0,
|
||||
BcstFramesXmtdOk = 0xf6,
|
||||
CarrierSenseErrors = 0xf8,
|
||||
MacControlFramesXmtd = 0xfa,
|
||||
FramesAbortXSColls = 0xfc,
|
||||
FramesWEXDeferal = 0xfe,
|
||||
/* RMON statistic register offsets */
|
||||
EtherStatsCollisions = 0x100,
|
||||
EtherStatsOctetsTransmit = 0x104,
|
||||
EtherStatsPktsTransmit = 0x108,
|
||||
EtherStatsPkts64OctetTransmit = 0x10c,
|
||||
EtherStats65to127OctetsTransmit = 0x110,
|
||||
EtherStatsPkts128to255OctetsTransmit = 0x114,
|
||||
EtherStatsPkts256to511OctetsTransmit = 0x118,
|
||||
EtherStatsPkts512to1023OctetsTransmit = 0x11c,
|
||||
EtherStatsPkts1024to1518OctetsTransmit = 0x120,
|
||||
EtherStatsCRCAlignErrors = 0x124,
|
||||
EtherStatsUndersizePkts = 0x128,
|
||||
EtherStatsFragments = 0x12c,
|
||||
EtherStatsJabbers = 0x130,
|
||||
EtherStatsOctets = 0x134,
|
||||
EtherStatsPkts = 0x138,
|
||||
EtherStats64Octets = 0x13c,
|
||||
EtherStatsPkts65to127Octets = 0x140,
|
||||
EtherStatsPkts128to255Octets = 0x144,
|
||||
EtherStatsPkts256to511Octets = 0x148,
|
||||
EtherStatsPkts512to1023Octets = 0x14c,
|
||||
EtherStatsPkts1024to1518Octets = 0x150,
|
||||
};
|
||||
|
||||
/* Bits in the interrupt status/mask registers. */
|
||||
enum IntStatus_bits {
|
||||
InterruptStatus = 0x0001,
|
||||
HostError = 0x0002,
|
||||
MACCtrlFrame = 0x0008,
|
||||
TxComplete = 0x0004,
|
||||
RxComplete = 0x0010,
|
||||
RxEarly = 0x0020,
|
||||
IntRequested = 0x0040,
|
||||
UpdateStats = 0x0080,
|
||||
LinkEvent = 0x0100,
|
||||
TxDMAComplete = 0x0200,
|
||||
RxDMAComplete = 0x0400,
|
||||
RFDListEnd = 0x0800,
|
||||
RxDMAPriority = 0x1000,
|
||||
};
|
||||
|
||||
/* Bits in the ReceiveMode register. */
|
||||
enum ReceiveMode_bits {
|
||||
ReceiveUnicast = 0x0001,
|
||||
ReceiveMulticast = 0x0002,
|
||||
ReceiveBroadcast = 0x0004,
|
||||
ReceiveAllFrames = 0x0008,
|
||||
ReceiveMulticastHash = 0x0010,
|
||||
ReceiveIPMulticast = 0x0020,
|
||||
ReceiveVLANMatch = 0x0100,
|
||||
ReceiveVLANHash = 0x0200,
|
||||
};
|
||||
/* Bits in MACCtrl. */
|
||||
enum MACCtrl_bits {
|
||||
DuplexSelect = 0x20,
|
||||
TxFlowControlEnable = 0x80,
|
||||
RxFlowControlEnable = 0x0100,
|
||||
RcvFCS = 0x200,
|
||||
AutoVLANtagging = 0x1000,
|
||||
AutoVLANuntagging = 0x2000,
|
||||
StatsEnable = 0x00200000,
|
||||
StatsDisable = 0x00400000,
|
||||
StatsEnabled = 0x00800000,
|
||||
TxEnable = 0x01000000,
|
||||
TxDisable = 0x02000000,
|
||||
TxEnabled = 0x04000000,
|
||||
RxEnable = 0x08000000,
|
||||
RxDisable = 0x10000000,
|
||||
RxEnabled = 0x20000000,
|
||||
};
|
||||
|
||||
enum ASICCtrl_LoWord_bits {
|
||||
PhyMedia = 0x0080,
|
||||
};
|
||||
|
||||
enum ASICCtrl_HiWord_bits {
|
||||
GlobalReset = 0x0001,
|
||||
RxReset = 0x0002,
|
||||
TxReset = 0x0004,
|
||||
DMAReset = 0x0008,
|
||||
FIFOReset = 0x0010,
|
||||
NetworkReset = 0x0020,
|
||||
HostReset = 0x0040,
|
||||
ResetBusy = 0x0400,
|
||||
};
|
||||
|
||||
/* Transmit Frame Control bits */
|
||||
enum TFC_bits {
|
||||
DwordAlign = 0x00000000,
|
||||
WordAlignDisable = 0x00030000,
|
||||
WordAlign = 0x00020000,
|
||||
TCPChecksumEnable = 0x00040000,
|
||||
UDPChecksumEnable = 0x00080000,
|
||||
IPChecksumEnable = 0x00100000,
|
||||
FCSAppendDisable = 0x00200000,
|
||||
TxIndicate = 0x00400000,
|
||||
TxDMAIndicate = 0x00800000,
|
||||
FragCountShift = 24,
|
||||
VLANTagInsert = 0x0000000010000000,
|
||||
TFDDone = 0x80000000,
|
||||
VIDShift = 32,
|
||||
UsePriorityShift = 48,
|
||||
};
|
||||
|
||||
/* Receive Frames Status bits */
|
||||
enum RFS_bits {
|
||||
RxFIFOOverrun = 0x00010000,
|
||||
RxRuntFrame = 0x00020000,
|
||||
RxAlignmentError = 0x00040000,
|
||||
RxFCSError = 0x00080000,
|
||||
RxOverSizedFrame = 0x00100000,
|
||||
RxLengthError = 0x00200000,
|
||||
VLANDetected = 0x00400000,
|
||||
TCPDetected = 0x00800000,
|
||||
TCPError = 0x01000000,
|
||||
UDPDetected = 0x02000000,
|
||||
UDPError = 0x04000000,
|
||||
IPDetected = 0x08000000,
|
||||
IPError = 0x10000000,
|
||||
FrameStart = 0x20000000,
|
||||
FrameEnd = 0x40000000,
|
||||
RFDDone = 0x80000000,
|
||||
TCIShift = 32,
|
||||
RFS_Errors = 0x003f0000,
|
||||
};
|
||||
|
||||
#define MII_RESET_TIME_OUT 10000
|
||||
/* MII register */
|
||||
enum _mii_reg {
|
||||
MII_BMCR = 0,
|
||||
MII_BMSR = 1,
|
||||
MII_PHY_ID1 = 2,
|
||||
MII_PHY_ID2 = 3,
|
||||
MII_ANAR = 4,
|
||||
MII_ANLPAR = 5,
|
||||
MII_ANER = 6,
|
||||
MII_ANNPT = 7,
|
||||
MII_ANLPRNP = 8,
|
||||
MII_MSCR = 9,
|
||||
MII_MSSR = 10,
|
||||
MII_ESR = 15,
|
||||
MII_PHY_SCR = 16,
|
||||
};
|
||||
/* PCS register */
|
||||
enum _pcs_reg {
|
||||
PCS_BMCR = 0,
|
||||
PCS_BMSR = 1,
|
||||
PCS_ANAR = 4,
|
||||
PCS_ANLPAR = 5,
|
||||
PCS_ANER = 6,
|
||||
PCS_ANNPT = 7,
|
||||
PCS_ANLPRNP = 8,
|
||||
PCS_ESR = 15,
|
||||
};
|
||||
|
||||
/* Basic Mode Control Register */
|
||||
enum _mii_bmcr {
|
||||
MII_BMCR_RESET = 0x8000,
|
||||
MII_BMCR_LOOP_BACK = 0x4000,
|
||||
MII_BMCR_SPEED_LSB = 0x2000,
|
||||
MII_BMCR_AN_ENABLE = 0x1000,
|
||||
MII_BMCR_POWER_DOWN = 0x0800,
|
||||
MII_BMCR_ISOLATE = 0x0400,
|
||||
MII_BMCR_RESTART_AN = 0x0200,
|
||||
MII_BMCR_DUPLEX_MODE = 0x0100,
|
||||
MII_BMCR_COL_TEST = 0x0080,
|
||||
MII_BMCR_SPEED_MSB = 0x0040,
|
||||
MII_BMCR_SPEED_RESERVED = 0x003f,
|
||||
MII_BMCR_SPEED_10 = 0,
|
||||
MII_BMCR_SPEED_100 = MII_BMCR_SPEED_LSB,
|
||||
MII_BMCR_SPEED_1000 = MII_BMCR_SPEED_MSB,
|
||||
};
|
||||
|
||||
/* Basic Mode Status Register */
|
||||
enum _mii_bmsr {
|
||||
MII_BMSR_100BT4 = 0x8000,
|
||||
MII_BMSR_100BX_FD = 0x4000,
|
||||
MII_BMSR_100BX_HD = 0x2000,
|
||||
MII_BMSR_10BT_FD = 0x1000,
|
||||
MII_BMSR_10BT_HD = 0x0800,
|
||||
MII_BMSR_100BT2_FD = 0x0400,
|
||||
MII_BMSR_100BT2_HD = 0x0200,
|
||||
MII_BMSR_EXT_STATUS = 0x0100,
|
||||
MII_BMSR_PREAMBLE_SUPP = 0x0040,
|
||||
MII_BMSR_AN_COMPLETE = 0x0020,
|
||||
MII_BMSR_REMOTE_FAULT = 0x0010,
|
||||
MII_BMSR_AN_ABILITY = 0x0008,
|
||||
MII_BMSR_LINK_STATUS = 0x0004,
|
||||
MII_BMSR_JABBER_DETECT = 0x0002,
|
||||
MII_BMSR_EXT_CAP = 0x0001,
|
||||
};
|
||||
|
||||
/* ANAR */
|
||||
enum _mii_anar {
|
||||
MII_ANAR_NEXT_PAGE = 0x8000,
|
||||
MII_ANAR_REMOTE_FAULT = 0x4000,
|
||||
MII_ANAR_ASYMMETRIC = 0x0800,
|
||||
MII_ANAR_PAUSE = 0x0400,
|
||||
MII_ANAR_100BT4 = 0x0200,
|
||||
MII_ANAR_100BX_FD = 0x0100,
|
||||
MII_ANAR_100BX_HD = 0x0080,
|
||||
MII_ANAR_10BT_FD = 0x0020,
|
||||
MII_ANAR_10BT_HD = 0x0010,
|
||||
MII_ANAR_SELECTOR = 0x001f,
|
||||
MII_IEEE8023_CSMACD = 0x0001,
|
||||
};
|
||||
|
||||
/* ANLPAR */
|
||||
enum _mii_anlpar {
|
||||
MII_ANLPAR_NEXT_PAGE = MII_ANAR_NEXT_PAGE,
|
||||
MII_ANLPAR_REMOTE_FAULT = MII_ANAR_REMOTE_FAULT,
|
||||
MII_ANLPAR_ASYMMETRIC = MII_ANAR_ASYMMETRIC,
|
||||
MII_ANLPAR_PAUSE = MII_ANAR_PAUSE,
|
||||
MII_ANLPAR_100BT4 = MII_ANAR_100BT4,
|
||||
MII_ANLPAR_100BX_FD = MII_ANAR_100BX_FD,
|
||||
MII_ANLPAR_100BX_HD = MII_ANAR_100BX_HD,
|
||||
MII_ANLPAR_10BT_FD = MII_ANAR_10BT_FD,
|
||||
MII_ANLPAR_10BT_HD = MII_ANAR_10BT_HD,
|
||||
MII_ANLPAR_SELECTOR = MII_ANAR_SELECTOR,
|
||||
};
|
||||
|
||||
/* Auto-Negotiation Expansion Register */
|
||||
enum _mii_aner {
|
||||
MII_ANER_PAR_DETECT_FAULT = 0x0010,
|
||||
MII_ANER_LP_NEXTPAGABLE = 0x0008,
|
||||
MII_ANER_NETXTPAGABLE = 0x0004,
|
||||
MII_ANER_PAGE_RECEIVED = 0x0002,
|
||||
MII_ANER_LP_NEGOTIABLE = 0x0001,
|
||||
};
|
||||
|
||||
/* MASTER-SLAVE Control Register */
|
||||
enum _mii_mscr {
|
||||
MII_MSCR_TEST_MODE = 0xe000,
|
||||
MII_MSCR_CFG_ENABLE = 0x1000,
|
||||
MII_MSCR_CFG_VALUE = 0x0800,
|
||||
MII_MSCR_PORT_VALUE = 0x0400,
|
||||
MII_MSCR_1000BT_FD = 0x0200,
|
||||
MII_MSCR_1000BT_HD = 0X0100,
|
||||
};
|
||||
|
||||
/* MASTER-SLAVE Status Register */
|
||||
enum _mii_mssr {
|
||||
MII_MSSR_CFG_FAULT = 0x8000,
|
||||
MII_MSSR_CFG_RES = 0x4000,
|
||||
MII_MSSR_LOCAL_RCV_STATUS = 0x2000,
|
||||
MII_MSSR_REMOTE_RCVR = 0x1000,
|
||||
MII_MSSR_LP_1000BT_FD = 0x0800,
|
||||
MII_MSSR_LP_1000BT_HD = 0x0400,
|
||||
MII_MSSR_IDLE_ERR_COUNT = 0x00ff,
|
||||
};
|
||||
|
||||
/* IEEE Extened Status Register */
|
||||
enum _mii_esr {
|
||||
MII_ESR_1000BX_FD = 0x8000,
|
||||
MII_ESR_1000BX_HD = 0x4000,
|
||||
MII_ESR_1000BT_FD = 0x2000,
|
||||
MII_ESR_1000BT_HD = 0x1000,
|
||||
};
|
||||
/* PHY Specific Control Register */
|
||||
#if 0
|
||||
typedef union t_MII_PHY_SCR {
|
||||
u16 image;
|
||||
struct {
|
||||
u16 disable_jabber:1; // bit 0
|
||||
u16 polarity_reversal:1; // bit 1
|
||||
u16 SEQ_test:1; // bit 2
|
||||
u16 _bit_3:1; // bit 3
|
||||
u16 disable_CLK125:1; // bit 4
|
||||
u16 mdi_crossover_mode:2; // bit 6:5
|
||||
u16 enable_ext_dist:1; // bit 7
|
||||
u16 _bit_8_9:2; // bit 9:8
|
||||
u16 force_link:1; // bit 10
|
||||
u16 assert_CRS:1; // bit 11
|
||||
u16 rcv_fifo_depth:2; // bit 13:12
|
||||
u16 xmit_fifo_depth:2; // bit 15:14
|
||||
} bits;
|
||||
} PHY_SCR_t, *PPHY_SCR_t;
|
||||
#endif
|
||||
|
||||
typedef enum t_MII_ADMIN_STATUS {
|
||||
adm_reset,
|
||||
adm_operational,
|
||||
adm_loopback,
|
||||
adm_power_down,
|
||||
adm_isolate
|
||||
} MII_ADMIN_t, *PMII_ADMIN_t;
|
||||
|
||||
/* Physical Coding Sublayer Management (PCS) */
|
||||
/* PCS control and status registers bitmap as the same as MII */
|
||||
/* PCS Extended Status register bitmap as the same as MII */
|
||||
/* PCS ANAR */
|
||||
enum _pcs_anar {
|
||||
PCS_ANAR_NEXT_PAGE = 0x8000,
|
||||
PCS_ANAR_REMOTE_FAULT = 0x3000,
|
||||
PCS_ANAR_ASYMMETRIC = 0x0100,
|
||||
PCS_ANAR_PAUSE = 0x0080,
|
||||
PCS_ANAR_HALF_DUPLEX = 0x0040,
|
||||
PCS_ANAR_FULL_DUPLEX = 0x0020,
|
||||
};
|
||||
/* PCS ANLPAR */
|
||||
enum _pcs_anlpar {
|
||||
PCS_ANLPAR_NEXT_PAGE = PCS_ANAR_NEXT_PAGE,
|
||||
PCS_ANLPAR_REMOTE_FAULT = PCS_ANAR_REMOTE_FAULT,
|
||||
PCS_ANLPAR_ASYMMETRIC = PCS_ANAR_ASYMMETRIC,
|
||||
PCS_ANLPAR_PAUSE = PCS_ANAR_PAUSE,
|
||||
PCS_ANLPAR_HALF_DUPLEX = PCS_ANAR_HALF_DUPLEX,
|
||||
PCS_ANLPAR_FULL_DUPLEX = PCS_ANAR_FULL_DUPLEX,
|
||||
};
|
||||
|
||||
typedef struct t_SROM {
|
||||
u16 config_param; /* 0x00 */
|
||||
u16 asic_ctrl; /* 0x02 */
|
||||
u16 sub_vendor_id; /* 0x04 */
|
||||
u16 sub_system_id; /* 0x06 */
|
||||
u16 reserved1[12]; /* 0x08-0x1f */
|
||||
u8 mac_addr[6]; /* 0x20-0x25 */
|
||||
u8 reserved2[10]; /* 0x26-0x2f */
|
||||
u8 sib[204]; /* 0x30-0xfb */
|
||||
u32 crc; /* 0xfc-0xff */
|
||||
} SROM_t, *PSROM_t;
|
||||
|
||||
/* Ioctl custom data */
|
||||
struct ioctl_data {
|
||||
char signature[10];
|
||||
int cmd;
|
||||
int len;
|
||||
char *data;
|
||||
};
|
||||
|
||||
struct mii_data {
|
||||
__u16 reserved;
|
||||
__u16 reg_num;
|
||||
__u16 in_value;
|
||||
__u16 out_value;
|
||||
};
|
||||
|
||||
/* The Rx and Tx buffer descriptors. */
|
||||
struct netdev_desc {
|
||||
__le64 next_desc;
|
||||
__le64 status;
|
||||
__le64 fraginfo;
|
||||
};
|
||||
|
||||
#define PRIV_ALIGN 15 /* Required alignment mask */
|
||||
/* Use __attribute__((aligned (L1_CACHE_BYTES))) to maintain alignment
|
||||
within the structure. */
|
||||
struct netdev_private {
|
||||
/* Descriptor rings first for alignment. */
|
||||
struct netdev_desc *rx_ring;
|
||||
struct netdev_desc *tx_ring;
|
||||
struct sk_buff *rx_skbuff[RX_RING_SIZE];
|
||||
struct sk_buff *tx_skbuff[TX_RING_SIZE];
|
||||
dma_addr_t tx_ring_dma;
|
||||
dma_addr_t rx_ring_dma;
|
||||
struct pci_dev *pdev;
|
||||
spinlock_t tx_lock;
|
||||
spinlock_t rx_lock;
|
||||
struct net_device_stats stats;
|
||||
unsigned int rx_buf_sz; /* Based on MTU+slack. */
|
||||
unsigned int speed; /* Operating speed */
|
||||
unsigned int vlan; /* VLAN Id */
|
||||
unsigned int chip_id; /* PCI table chip id */
|
||||
unsigned int rx_coalesce; /* Maximum frames each RxDMAComplete intr */
|
||||
unsigned int rx_timeout; /* Wait time between RxDMAComplete intr */
|
||||
unsigned int tx_coalesce; /* Maximum frames each tx interrupt */
|
||||
unsigned int full_duplex:1; /* Full-duplex operation requested. */
|
||||
unsigned int an_enable:2; /* Auto-Negotiated Enable */
|
||||
unsigned int jumbo:1; /* Jumbo frame enable */
|
||||
unsigned int coalesce:1; /* Rx coalescing enable */
|
||||
unsigned int tx_flow:1; /* Tx flow control enable */
|
||||
unsigned int rx_flow:1; /* Rx flow control enable */
|
||||
unsigned int phy_media:1; /* 1: fiber, 0: copper */
|
||||
unsigned int link_status:1; /* Current link status */
|
||||
struct netdev_desc *last_tx; /* Last Tx descriptor used. */
|
||||
unsigned long cur_rx, old_rx; /* Producer/consumer ring indices */
|
||||
unsigned long cur_tx, old_tx;
|
||||
struct timer_list timer;
|
||||
int wake_polarity;
|
||||
char name[256]; /* net device description */
|
||||
u8 duplex_polarity;
|
||||
u16 mcast_filter[4];
|
||||
u16 advertising; /* NWay media advertisement */
|
||||
u16 negotiate; /* Negotiated media */
|
||||
int phy_addr; /* PHY addresses. */
|
||||
};
|
||||
|
||||
/* The station address location in the EEPROM. */
|
||||
/* The struct pci_device_id consist of:
|
||||
vendor, device Vendor and device ID to match (or PCI_ANY_ID)
|
||||
subvendor, subdevice Subsystem vendor and device ID to match (or PCI_ANY_ID)
|
||||
class Device class to match. The class_mask tells which bits
|
||||
class_mask of the class are honored during the comparison.
|
||||
driver_data Data private to the driver.
|
||||
*/
|
||||
|
||||
static DEFINE_PCI_DEVICE_TABLE(rio_pci_tbl) = {
|
||||
{0x1186, 0x4000, PCI_ANY_ID, PCI_ANY_ID, },
|
||||
{0x13f0, 0x1021, PCI_ANY_ID, PCI_ANY_ID, },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE (pci, rio_pci_tbl);
|
||||
#define TX_TIMEOUT (4*HZ)
|
||||
#define PACKET_SIZE 1536
|
||||
#define MAX_JUMBO 8000
|
||||
#define RIO_IO_SIZE 340
|
||||
#define DEFAULT_RXC 5
|
||||
#define DEFAULT_RXT 750
|
||||
#define DEFAULT_TXC 1
|
||||
#define MAX_TXC 8
|
||||
#endif /* __DL2K_H__ */
|
1940
drivers/net/ethernet/dlink/sundance.c
Normal file
1940
drivers/net/ethernet/dlink/sundance.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user