提交 efcce839 编写于 作者: F Finn Thain 提交者: Jeff Garzik

[PATCH] macsonic/jazzsonic network drivers update

The purpose of this patch:

- Adopt the DMA API (jazzsonic, macsonic & core driver).

- Adopt the driver model (macsonic).

This part was cribbed from jazzsonic. As a consequence, macsonic once
again works as a module. Driver model is also used by the DMA calls.

- Support 16 bit cards (macsonic & core driver, also affects jazzsonic)

This code was adapted from the mac68k linux 2.2 kernel, where it has
languished for a long time.

- Support more 32-bit mac cards (macsonic)

Also from mac68k repo.

- Zero-copy buffer handling (core driver)

Provides a nice performance improvement. The new algorithm incidentally
helped to replace the old Jazz DMA code.

The patch was tested on a variety of macs (several 32-bit quadra built-in
NICs, a 16-bit LC PDS NIC and a 16-bit comm-slot NIC), and also on MIPS
Jazz.
Signed-off-by: NFinn Thain <fthain@telegraphics.com.au>
Acked-by: NThomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: NJeff Garzik <jgarzik@pobox.com>
上级 26006360
......@@ -87,7 +87,6 @@ extern struct net_device *mvme147lance_probe(int unit);
extern struct net_device *tc515_probe(int unit);
extern struct net_device *lance_probe(int unit);
extern struct net_device *mace_probe(int unit);
extern struct net_device *macsonic_probe(int unit);
extern struct net_device *mac8390_probe(int unit);
extern struct net_device *mac89x0_probe(int unit);
extern struct net_device *mc32_probe(int unit);
......@@ -284,9 +283,6 @@ static struct devprobe2 m68k_probes[] __initdata = {
#ifdef CONFIG_MACMACE /* Mac 68k Quadra AV builtin Ethernet */
{mace_probe, 0},
#endif
#ifdef CONFIG_MACSONIC /* Mac SONIC-based Ethernet of all sorts */
{macsonic_probe, 0},
#endif
#ifdef CONFIG_MAC8390 /* NuBus NS8390-based cards */
{mac8390_probe, 0},
#endif
......
/*
* sonic.c
* jazzsonic.c
*
* (C) 2005 Finn Thain
*
* Converted to DMA API, and (from the mac68k project) introduced
* dhd's support for 16-bit cards.
*
* (C) 1996,1998 by Thomas Bogendoerfer (tsbogend@alpha.franken.de)
*
......@@ -28,8 +33,8 @@
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/bitops.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <asm/bootinfo.h>
#include <asm/system.h>
......@@ -44,22 +49,20 @@ static struct platform_device *jazz_sonic_device;
#define SONIC_MEM_SIZE 0x100
#define SREGS_PAD(n) u16 n;
#include "sonic.h"
/*
* Macros to access SONIC registers
*/
#define SONIC_READ(reg) (*((volatile unsigned int *)base_addr+reg))
#define SONIC_READ(reg) (*((volatile unsigned int *)dev->base_addr+reg))
#define SONIC_WRITE(reg,val) \
do { \
*((volatile unsigned int *)base_addr+(reg)) = (val); \
*((volatile unsigned int *)dev->base_addr+(reg)) = (val); \
} while (0)
/* use 0 for production, 1 for verification, >2 for debug */
/* use 0 for production, 1 for verification, >1 for debug */
#ifdef SONIC_DEBUG
static unsigned int sonic_debug = SONIC_DEBUG;
#else
......@@ -85,18 +88,18 @@ static unsigned short known_revisions[] =
0xffff /* end of list */
};
static int __init sonic_probe1(struct net_device *dev, unsigned long base_addr,
unsigned int irq)
static int __init sonic_probe1(struct net_device *dev)
{
static unsigned version_printed;
unsigned int silicon_revision;
unsigned int val;
struct sonic_local *lp;
struct sonic_local *lp = netdev_priv(dev);
int err = -ENODEV;
int i;
if (!request_mem_region(base_addr, SONIC_MEM_SIZE, jazz_sonic_string))
if (!request_mem_region(dev->base_addr, SONIC_MEM_SIZE, jazz_sonic_string))
return -EBUSY;
/*
* get the Silicon Revision ID. If this is one of the known
* one assume that we found a SONIC ethernet controller at
......@@ -120,11 +123,7 @@ static int __init sonic_probe1(struct net_device *dev, unsigned long base_addr,
if (sonic_debug && version_printed++ == 0)
printk(version);
printk("%s: Sonic ethernet found at 0x%08lx, ", dev->name, base_addr);
/* Fill in the 'dev' fields. */
dev->base_addr = base_addr;
dev->irq = irq;
printk(KERN_INFO "%s: Sonic ethernet found at 0x%08lx, ", lp->device->bus_id, dev->base_addr);
/*
* Put the sonic into software reset, then
......@@ -138,84 +137,44 @@ static int __init sonic_probe1(struct net_device *dev, unsigned long base_addr,
dev->dev_addr[i*2+1] = val >> 8;
}
printk("HW Address ");
for (i = 0; i < 6; i++) {
printk("%2.2x", dev->dev_addr[i]);
if (i<5)
printk(":");
}
printk(" IRQ %d\n", irq);
err = -ENOMEM;
/* Initialize the device structure. */
if (dev->priv == NULL) {
/*
* the memory be located in the same 64kb segment
*/
lp = NULL;
i = 0;
do {
lp = kmalloc(sizeof(*lp), GFP_KERNEL);
if ((unsigned long) lp >> 16
!= ((unsigned long)lp + sizeof(*lp) ) >> 16) {
/* FIXME, free the memory later */
kfree(lp);
lp = NULL;
}
} while (lp == NULL && i++ < 20);
if (lp == NULL) {
printk("%s: couldn't allocate memory for descriptors\n",
dev->name);
goto out;
}
memset(lp, 0, sizeof(struct sonic_local));
/* get the virtual dma address */
lp->cda_laddr = vdma_alloc(CPHYSADDR(lp),sizeof(*lp));
if (lp->cda_laddr == ~0UL) {
printk("%s: couldn't get DMA page entry for "
"descriptors\n", dev->name);
goto out1;
}
lp->tda_laddr = lp->cda_laddr + sizeof (lp->cda);
lp->rra_laddr = lp->tda_laddr + sizeof (lp->tda);
lp->rda_laddr = lp->rra_laddr + sizeof (lp->rra);
/* allocate receive buffer area */
/* FIXME, maybe we should use skbs */
lp->rba = kmalloc(SONIC_NUM_RRS * SONIC_RBSIZE, GFP_KERNEL);
if (!lp->rba) {
printk("%s: couldn't allocate receive buffers\n",
dev->name);
goto out2;
}
lp->dma_bitmode = SONIC_BITMODE32;
/* get virtual dma address */
lp->rba_laddr = vdma_alloc(CPHYSADDR(lp->rba),
SONIC_NUM_RRS * SONIC_RBSIZE);
if (lp->rba_laddr == ~0UL) {
printk("%s: couldn't get DMA page entry for receive "
"buffers\n",dev->name);
goto out3;
}
/* now convert pointer to KSEG1 pointer */
lp->rba = (char *)KSEG1ADDR(lp->rba);
flush_cache_all();
dev->priv = (struct sonic_local *)KSEG1ADDR(lp);
/* Allocate the entire chunk of memory for the descriptors.
Note that this cannot cross a 64K boundary. */
if ((lp->descriptors = dma_alloc_coherent(lp->device,
SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
&lp->descriptors_laddr, GFP_KERNEL)) == NULL) {
printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n", lp->device->bus_id);
goto out;
}
lp = (struct sonic_local *)dev->priv;
/* Now set up the pointers to point to the appropriate places */
lp->cda = lp->descriptors;
lp->tda = lp->cda + (SIZEOF_SONIC_CDA
* SONIC_BUS_SCALE(lp->dma_bitmode));
lp->rda = lp->tda + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
* SONIC_BUS_SCALE(lp->dma_bitmode));
lp->rra = lp->rda + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
* SONIC_BUS_SCALE(lp->dma_bitmode));
lp->cda_laddr = lp->descriptors_laddr;
lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA
* SONIC_BUS_SCALE(lp->dma_bitmode));
lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
* SONIC_BUS_SCALE(lp->dma_bitmode));
lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
* SONIC_BUS_SCALE(lp->dma_bitmode));
dev->open = sonic_open;
dev->stop = sonic_close;
dev->hard_start_xmit = sonic_send_packet;
dev->get_stats = sonic_get_stats;
dev->get_stats = sonic_get_stats;
dev->set_multicast_list = &sonic_multicast_list;
dev->tx_timeout = sonic_tx_timeout;
dev->watchdog_timeo = TX_TIMEOUT;
/*
......@@ -226,14 +185,8 @@ static int __init sonic_probe1(struct net_device *dev, unsigned long base_addr,
SONIC_WRITE(SONIC_MPT,0xffff);
return 0;
out3:
kfree(lp->rba);
out2:
vdma_free(lp->cda_laddr);
out1:
kfree(lp);
out:
release_region(base_addr, SONIC_MEM_SIZE);
release_region(dev->base_addr, SONIC_MEM_SIZE);
return err;
}
......@@ -245,7 +198,6 @@ static int __init jazz_sonic_probe(struct device *device)
{
struct net_device *dev;
struct sonic_local *lp;
unsigned long base_addr;
int err = 0;
int i;
......@@ -255,21 +207,26 @@ static int __init jazz_sonic_probe(struct device *device)
if (mips_machgroup != MACH_GROUP_JAZZ)
return -ENODEV;
dev = alloc_etherdev(0);
dev = alloc_etherdev(sizeof(struct sonic_local));
if (!dev)
return -ENOMEM;
lp = netdev_priv(dev);
lp->device = device;
SET_NETDEV_DEV(dev, device);
SET_MODULE_OWNER(dev);
netdev_boot_setup_check(dev);
base_addr = dev->base_addr;
if (base_addr >= KSEG0) { /* Check a single specified location. */
err = sonic_probe1(dev, base_addr, dev->irq);
} else if (base_addr != 0) { /* Don't probe at all. */
if (dev->base_addr >= KSEG0) { /* Check a single specified location. */
err = sonic_probe1(dev);
} else if (dev->base_addr != 0) { /* Don't probe at all. */
err = -ENXIO;
} else {
for (i = 0; sonic_portlist[i].port; i++) {
int io = sonic_portlist[i].port;
if (sonic_probe1(dev, io, sonic_portlist[i].irq) == 0)
dev->base_addr = sonic_portlist[i].port;
dev->irq = sonic_portlist[i].irq;
if (sonic_probe1(dev) == 0)
break;
}
if (!sonic_portlist[i].port)
......@@ -281,14 +238,17 @@ static int __init jazz_sonic_probe(struct device *device)
if (err)
goto out1;
printk("%s: MAC ", dev->name);
for (i = 0; i < 6; i++) {
printk("%2.2x", dev->dev_addr[i]);
if (i < 5)
printk(":");
}
printk(" IRQ %d\n", dev->irq);
return 0;
out1:
lp = dev->priv;
vdma_free(lp->rba_laddr);
kfree(lp->rba);
vdma_free(lp->cda_laddr);
kfree(lp);
release_region(dev->base_addr, SONIC_MEM_SIZE);
out:
free_netdev(dev);
......@@ -296,21 +256,22 @@ static int __init jazz_sonic_probe(struct device *device)
return err;
}
/*
* SONIC uses a normal IRQ
*/
#define sonic_request_irq request_irq
#define sonic_free_irq free_irq
MODULE_DESCRIPTION("Jazz SONIC ethernet driver");
module_param(sonic_debug, int, 0);
MODULE_PARM_DESC(sonic_debug, "jazzsonic debug level (1-4)");
#define sonic_chiptomem(x) KSEG1ADDR(vdma_log2phys(x))
#define SONIC_IRQ_FLAG SA_INTERRUPT
#include "sonic.c"
static int __devexit jazz_sonic_device_remove (struct device *device)
{
struct net_device *dev = device->driver_data;
struct sonic_local* lp = netdev_priv(dev);
unregister_netdev (dev);
dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
lp->descriptors, lp->descriptors_laddr);
release_region (dev->base_addr, SONIC_MEM_SIZE);
free_netdev (dev);
......@@ -323,7 +284,7 @@ static struct device_driver jazz_sonic_driver = {
.probe = jazz_sonic_probe,
.remove = __devexit_p(jazz_sonic_device_remove),
};
static void jazz_sonic_platform_release (struct device *device)
{
struct platform_device *pldev;
......@@ -336,10 +297,11 @@ static void jazz_sonic_platform_release (struct device *device)
static int __init jazz_sonic_init_module(void)
{
struct platform_device *pldev;
int err;
if (driver_register(&jazz_sonic_driver)) {
if ((err = driver_register(&jazz_sonic_driver))) {
printk(KERN_ERR "Driver registration failed\n");
return -ENOMEM;
return err;
}
jazz_sonic_device = NULL;
......
此差异已折叠。
此差异已折叠。
/*
* Helpfile for sonic.c
* Header file for sonic.c
*
* (C) Waldorf Electronics, Germany
* Written by Andreas Busse
......@@ -9,10 +9,16 @@
* and pad structure members must be exchanged. Also, the structures
* need to be changed accordingly to the bus size.
*
* 981229 MSch: did just that for the 68k Mac port (32 bit, big endian),
* see CONFIG_MACSONIC branch below.
* 981229 MSch: did just that for the 68k Mac port (32 bit, big endian)
*
* 990611 David Huggins-Daines <dhd@debian.org>: This machine abstraction
* does not cope with 16-bit bus sizes very well. Therefore I have
* rewritten it with ugly macros and evil inlines.
*
* 050625 Finn Thain: introduced more 32-bit cards and dhd's support
* for 16-bit cards (from the mac68k project).
*/
#ifndef SONIC_H
#define SONIC_H
......@@ -83,6 +89,7 @@
/*
* Error counters
*/
#define SONIC_CRCT 0x2c
#define SONIC_FAET 0x2d
#define SONIC_MPT 0x2e
......@@ -182,14 +189,14 @@
#define SONIC_INT_BR 0x4000
#define SONIC_INT_HBL 0x2000
#define SONIC_INT_LCD 0x1000
#define SONIC_INT_PINT 0x0800
#define SONIC_INT_PKTRX 0x0400
#define SONIC_INT_TXDN 0x0200
#define SONIC_INT_TXER 0x0100
#define SONIC_INT_TC 0x0080
#define SONIC_INT_RDE 0x0040
#define SONIC_INT_RBE 0x0020
#define SONIC_INT_LCD 0x1000
#define SONIC_INT_PINT 0x0800
#define SONIC_INT_PKTRX 0x0400
#define SONIC_INT_TXDN 0x0200
#define SONIC_INT_TXER 0x0100
#define SONIC_INT_TC 0x0080
#define SONIC_INT_RDE 0x0040
#define SONIC_INT_RBE 0x0020
#define SONIC_INT_RBAE 0x0010
#define SONIC_INT_CRC 0x0008
#define SONIC_INT_FAE 0x0004
......@@ -201,224 +208,61 @@
* The interrupts we allow.
*/
#define SONIC_IMR_DEFAULT (SONIC_INT_BR | \
SONIC_INT_LCD | \
SONIC_INT_PINT | \
#define SONIC_IMR_DEFAULT ( SONIC_INT_BR | \
SONIC_INT_LCD | \
SONIC_INT_RFO | \
SONIC_INT_PKTRX | \
SONIC_INT_TXDN | \
SONIC_INT_TXER | \
SONIC_INT_RDE | \
SONIC_INT_RBE | \
SONIC_INT_RBAE | \
SONIC_INT_CRC | \
SONIC_INT_FAE | \
SONIC_INT_MP)
#define SONIC_END_OF_LINKS 0x0001
#ifdef CONFIG_MACSONIC
/*
* Big endian like structures on 680x0 Macs
*/
typedef struct {
u32 rx_bufadr_l; /* receive buffer ptr */
u32 rx_bufadr_h;
u32 rx_bufsize_l; /* no. of words in the receive buffer */
u32 rx_bufsize_h;
} sonic_rr_t;
/*
* Sonic receive descriptor. Receive descriptors are
* kept in a linked list of these structures.
*/
typedef struct {
SREGS_PAD(pad0);
u16 rx_status; /* status after reception of a packet */
SREGS_PAD(pad1);
u16 rx_pktlen; /* length of the packet incl. CRC */
/*
* Pointers to the location in the receive buffer area (RBA)
* where the packet resides. A packet is always received into
* a contiguous piece of memory.
*/
SREGS_PAD(pad2);
u16 rx_pktptr_l;
SREGS_PAD(pad3);
u16 rx_pktptr_h;
SREGS_PAD(pad4);
u16 rx_seqno; /* sequence no. */
SREGS_PAD(pad5);
u16 link; /* link to next RDD (end if EOL bit set) */
/*
* Owner of this descriptor, 0= driver, 1=sonic
*/
SREGS_PAD(pad6);
u16 in_use;
caddr_t rda_next; /* pointer to next RD */
} sonic_rd_t;
/*
* Describes a Transmit Descriptor
*/
typedef struct {
SREGS_PAD(pad0);
u16 tx_status; /* status after transmission of a packet */
SREGS_PAD(pad1);
u16 tx_config; /* transmit configuration for this packet */
SREGS_PAD(pad2);
u16 tx_pktsize; /* size of the packet to be transmitted */
SREGS_PAD(pad3);
u16 tx_frag_count; /* no. of fragments */
SREGS_PAD(pad4);
u16 tx_frag_ptr_l;
SREGS_PAD(pad5);
u16 tx_frag_ptr_h;
SREGS_PAD(pad6);
u16 tx_frag_size;
SREGS_PAD(pad7);
u16 link; /* ptr to next descriptor */
} sonic_td_t;
/*
* Describes an entry in the CAM Descriptor Area.
*/
typedef struct {
SREGS_PAD(pad0);
u16 cam_entry_pointer;
SREGS_PAD(pad1);
u16 cam_cap0;
SREGS_PAD(pad2);
u16 cam_cap1;
SREGS_PAD(pad3);
u16 cam_cap2;
} sonic_cd_t;
#define SONIC_EOL 0x0001
#define CAM_DESCRIPTORS 16
typedef struct {
sonic_cd_t cam_desc[CAM_DESCRIPTORS];
SREGS_PAD(pad);
u16 cam_enable;
} sonic_cda_t;
#else /* original declarations, little endian 32 bit */
/*
* structure definitions
*/
typedef struct {
u32 rx_bufadr_l; /* receive buffer ptr */
u32 rx_bufadr_h;
u32 rx_bufsize_l; /* no. of words in the receive buffer */
u32 rx_bufsize_h;
} sonic_rr_t;
/*
* Sonic receive descriptor. Receive descriptors are
* kept in a linked list of these structures.
*/
typedef struct {
u16 rx_status; /* status after reception of a packet */
SREGS_PAD(pad0);
u16 rx_pktlen; /* length of the packet incl. CRC */
SREGS_PAD(pad1);
/*
* Pointers to the location in the receive buffer area (RBA)
* where the packet resides. A packet is always received into
* a contiguous piece of memory.
*/
u16 rx_pktptr_l;
SREGS_PAD(pad2);
u16 rx_pktptr_h;
SREGS_PAD(pad3);
u16 rx_seqno; /* sequence no. */
SREGS_PAD(pad4);
u16 link; /* link to next RDD (end if EOL bit set) */
SREGS_PAD(pad5);
/*
* Owner of this descriptor, 0= driver, 1=sonic
*/
u16 in_use;
SREGS_PAD(pad6);
caddr_t rda_next; /* pointer to next RD */
} sonic_rd_t;
/*
* Describes a Transmit Descriptor
*/
typedef struct {
u16 tx_status; /* status after transmission of a packet */
SREGS_PAD(pad0);
u16 tx_config; /* transmit configuration for this packet */
SREGS_PAD(pad1);
u16 tx_pktsize; /* size of the packet to be transmitted */
SREGS_PAD(pad2);
u16 tx_frag_count; /* no. of fragments */
SREGS_PAD(pad3);
u16 tx_frag_ptr_l;
SREGS_PAD(pad4);
u16 tx_frag_ptr_h;
SREGS_PAD(pad5);
u16 tx_frag_size;
SREGS_PAD(pad6);
u16 link; /* ptr to next descriptor */
SREGS_PAD(pad7);
} sonic_td_t;
/*
* Describes an entry in the CAM Descriptor Area.
*/
typedef struct {
u16 cam_entry_pointer;
SREGS_PAD(pad0);
u16 cam_cap0;
SREGS_PAD(pad1);
u16 cam_cap1;
SREGS_PAD(pad2);
u16 cam_cap2;
SREGS_PAD(pad3);
} sonic_cd_t;
#define CAM_DESCRIPTORS 16
typedef struct {
sonic_cd_t cam_desc[CAM_DESCRIPTORS];
u16 cam_enable;
SREGS_PAD(pad);
} sonic_cda_t;
#endif /* endianness */
/* Offsets in the various DMA buffers accessed by the SONIC */
#define SONIC_BITMODE16 0
#define SONIC_BITMODE32 1
#define SONIC_BUS_SCALE(bitmode) ((bitmode) ? 4 : 2)
/* Note! These are all measured in bus-size units, so use SONIC_BUS_SCALE */
#define SIZEOF_SONIC_RR 4
#define SONIC_RR_BUFADR_L 0
#define SONIC_RR_BUFADR_H 1
#define SONIC_RR_BUFSIZE_L 2
#define SONIC_RR_BUFSIZE_H 3
#define SIZEOF_SONIC_RD 7
#define SONIC_RD_STATUS 0
#define SONIC_RD_PKTLEN 1
#define SONIC_RD_PKTPTR_L 2
#define SONIC_RD_PKTPTR_H 3
#define SONIC_RD_SEQNO 4
#define SONIC_RD_LINK 5
#define SONIC_RD_IN_USE 6
#define SIZEOF_SONIC_TD 8
#define SONIC_TD_STATUS 0
#define SONIC_TD_CONFIG 1
#define SONIC_TD_PKTSIZE 2
#define SONIC_TD_FRAG_COUNT 3
#define SONIC_TD_FRAG_PTR_L 4
#define SONIC_TD_FRAG_PTR_H 5
#define SONIC_TD_FRAG_SIZE 6
#define SONIC_TD_LINK 7
#define SIZEOF_SONIC_CD 4
#define SONIC_CD_ENTRY_POINTER 0
#define SONIC_CD_CAP0 1
#define SONIC_CD_CAP1 2
#define SONIC_CD_CAP2 3
#define SIZEOF_SONIC_CDA ((CAM_DESCRIPTORS * SIZEOF_SONIC_CD) + 1)
#define SONIC_CDA_CAM_ENABLE (CAM_DESCRIPTORS * SIZEOF_SONIC_CD)
/*
* Some tunables for the buffer areas. Power of 2 is required
......@@ -426,44 +270,60 @@ typedef struct {
*
* MSch: use more buffer space for the slow m68k Macs!
*/
#ifdef CONFIG_MACSONIC
#define SONIC_NUM_RRS 32 /* number of receive resources */
#define SONIC_NUM_RDS SONIC_NUM_RRS /* number of receive descriptors */
#define SONIC_NUM_TDS 32 /* number of transmit descriptors */
#else
#define SONIC_NUM_RRS 16 /* number of receive resources */
#define SONIC_NUM_RDS SONIC_NUM_RRS /* number of receive descriptors */
#define SONIC_NUM_TDS 16 /* number of transmit descriptors */
#endif
#define SONIC_RBSIZE 1520 /* size of one resource buffer */
#define SONIC_NUM_RRS 16 /* number of receive resources */
#define SONIC_NUM_RDS SONIC_NUM_RRS /* number of receive descriptors */
#define SONIC_NUM_TDS 16 /* number of transmit descriptors */
#define SONIC_RDS_MASK (SONIC_NUM_RDS-1)
#define SONIC_TDS_MASK (SONIC_NUM_TDS-1)
#define SONIC_RDS_MASK (SONIC_NUM_RDS-1)
#define SONIC_TDS_MASK (SONIC_NUM_TDS-1)
#define SONIC_RBSIZE 1520 /* size of one resource buffer */
/* Again, measured in bus size units! */
#define SIZEOF_SONIC_DESC (SIZEOF_SONIC_CDA \
+ (SIZEOF_SONIC_TD * SONIC_NUM_TDS) \
+ (SIZEOF_SONIC_RD * SONIC_NUM_RDS) \
+ (SIZEOF_SONIC_RR * SONIC_NUM_RRS))
/* Information that need to be kept for each board. */
struct sonic_local {
sonic_cda_t cda; /* virtual CPU address of CDA */
sonic_td_t tda[SONIC_NUM_TDS]; /* transmit descriptor area */
sonic_rr_t rra[SONIC_NUM_RRS]; /* receive resource area */
sonic_rd_t rda[SONIC_NUM_RDS]; /* receive descriptor area */
struct sk_buff *tx_skb[SONIC_NUM_TDS]; /* skbuffs for packets to transmit */
unsigned int tx_laddr[SONIC_NUM_TDS]; /* logical DMA address fro skbuffs */
unsigned char *rba; /* start of receive buffer areas */
unsigned int cda_laddr; /* logical DMA address of CDA */
unsigned int tda_laddr; /* logical DMA address of TDA */
unsigned int rra_laddr; /* logical DMA address of RRA */
unsigned int rda_laddr; /* logical DMA address of RDA */
unsigned int rba_laddr; /* logical DMA address of RBA */
unsigned int cur_rra; /* current indexes to resource areas */
/* Bus size. 0 == 16 bits, 1 == 32 bits. */
int dma_bitmode;
/* Register offset within the longword (independent of endianness,
and varies from one type of Macintosh SONIC to another
(Aarrgh)) */
int reg_offset;
void *descriptors;
/* Crud. These areas have to be within the same 64K. Therefore
we allocate a desriptors page, and point these to places within it. */
void *cda; /* CAM descriptor area */
void *tda; /* Transmit descriptor area */
void *rra; /* Receive resource area */
void *rda; /* Receive descriptor area */
struct sk_buff* volatile rx_skb[SONIC_NUM_RRS]; /* packets to be received */
struct sk_buff* volatile tx_skb[SONIC_NUM_TDS]; /* packets to be transmitted */
unsigned int tx_len[SONIC_NUM_TDS]; /* lengths of tx DMA mappings */
/* Logical DMA addresses on MIPS, bus addresses on m68k
* (so "laddr" is a bit misleading) */
dma_addr_t descriptors_laddr;
u32 cda_laddr; /* logical DMA address of CDA */
u32 tda_laddr; /* logical DMA address of TDA */
u32 rra_laddr; /* logical DMA address of RRA */
u32 rda_laddr; /* logical DMA address of RDA */
dma_addr_t rx_laddr[SONIC_NUM_RRS]; /* logical DMA addresses of rx skbuffs */
dma_addr_t tx_laddr[SONIC_NUM_TDS]; /* logical DMA addresses of tx skbuffs */
unsigned int rra_end;
unsigned int cur_rwp;
unsigned int cur_rx;
unsigned int cur_tx;
unsigned int dirty_tx; /* last unacked transmit packet */
char tx_full;
unsigned int cur_tx; /* first unacked transmit packet */
unsigned int eol_rx;
unsigned int eol_tx; /* last unacked transmit packet */
unsigned int next_tx; /* next free TD */
struct device *device; /* generic device */
struct net_device_stats stats;
};
#define TX_TIMEOUT 6
#define TX_TIMEOUT (3 * HZ)
/* Index to functions, as function prototypes. */
......@@ -477,6 +337,114 @@ static void sonic_multicast_list(struct net_device *dev);
static int sonic_init(struct net_device *dev);
static void sonic_tx_timeout(struct net_device *dev);
/* Internal inlines for reading/writing DMA buffers. Note that bus
size and endianness matter here, whereas they don't for registers,
as far as we can tell. */
/* OpenBSD calls this "SWO". I'd like to think that sonic_buf_put()
is a much better name. */
static inline void sonic_buf_put(void* base, int bitmode,
int offset, __u16 val)
{
if (bitmode)
#ifdef __BIG_ENDIAN
((__u16 *) base + (offset*2))[1] = val;
#else
((__u16 *) base + (offset*2))[0] = val;
#endif
else
((__u16 *) base)[offset] = val;
}
static inline __u16 sonic_buf_get(void* base, int bitmode,
int offset)
{
if (bitmode)
#ifdef __BIG_ENDIAN
return ((volatile __u16 *) base + (offset*2))[1];
#else
return ((volatile __u16 *) base + (offset*2))[0];
#endif
else
return ((volatile __u16 *) base)[offset];
}
/* Inlines that you should actually use for reading/writing DMA buffers */
static inline void sonic_cda_put(struct net_device* dev, int entry,
int offset, __u16 val)
{
struct sonic_local* lp = (struct sonic_local *) dev->priv;
sonic_buf_put(lp->cda, lp->dma_bitmode,
(entry * SIZEOF_SONIC_CD) + offset, val);
}
static inline __u16 sonic_cda_get(struct net_device* dev, int entry,
int offset)
{
struct sonic_local* lp = (struct sonic_local *) dev->priv;
return sonic_buf_get(lp->cda, lp->dma_bitmode,
(entry * SIZEOF_SONIC_CD) + offset);
}
static inline void sonic_set_cam_enable(struct net_device* dev, __u16 val)
{
struct sonic_local* lp = (struct sonic_local *) dev->priv;
sonic_buf_put(lp->cda, lp->dma_bitmode, SONIC_CDA_CAM_ENABLE, val);
}
static inline __u16 sonic_get_cam_enable(struct net_device* dev)
{
struct sonic_local* lp = (struct sonic_local *) dev->priv;
return sonic_buf_get(lp->cda, lp->dma_bitmode, SONIC_CDA_CAM_ENABLE);
}
static inline void sonic_tda_put(struct net_device* dev, int entry,
int offset, __u16 val)
{
struct sonic_local* lp = (struct sonic_local *) dev->priv;
sonic_buf_put(lp->tda, lp->dma_bitmode,
(entry * SIZEOF_SONIC_TD) + offset, val);
}
static inline __u16 sonic_tda_get(struct net_device* dev, int entry,
int offset)
{
struct sonic_local* lp = (struct sonic_local *) dev->priv;
return sonic_buf_get(lp->tda, lp->dma_bitmode,
(entry * SIZEOF_SONIC_TD) + offset);
}
static inline void sonic_rda_put(struct net_device* dev, int entry,
int offset, __u16 val)
{
struct sonic_local* lp = (struct sonic_local *) dev->priv;
sonic_buf_put(lp->rda, lp->dma_bitmode,
(entry * SIZEOF_SONIC_RD) + offset, val);
}
static inline __u16 sonic_rda_get(struct net_device* dev, int entry,
int offset)
{
struct sonic_local* lp = (struct sonic_local *) dev->priv;
return sonic_buf_get(lp->rda, lp->dma_bitmode,
(entry * SIZEOF_SONIC_RD) + offset);
}
static inline void sonic_rra_put(struct net_device* dev, int entry,
int offset, __u16 val)
{
struct sonic_local* lp = (struct sonic_local *) dev->priv;
sonic_buf_put(lp->rra, lp->dma_bitmode,
(entry * SIZEOF_SONIC_RR) + offset, val);
}
static inline __u16 sonic_rra_get(struct net_device* dev, int entry,
int offset)
{
struct sonic_local* lp = (struct sonic_local *) dev->priv;
return sonic_buf_get(lp->rra, lp->dma_bitmode,
(entry * SIZEOF_SONIC_RR) + offset);
}
static const char *version =
"sonic.c:v0.92 20.9.98 tsbogend@alpha.franken.de\n";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册