162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * 7990.h -- LANCE ethernet IC generic routines. 462306a36Sopenharmony_ci * This is an attempt to separate out the bits of various ethernet 562306a36Sopenharmony_ci * drivers that are common because they all use the AMD 7990 LANCE 662306a36Sopenharmony_ci * (Local Area Network Controller for Ethernet) chip. 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk> 962306a36Sopenharmony_ci * 1062306a36Sopenharmony_ci * Most of this stuff was obtained by looking at other LANCE drivers, 1162306a36Sopenharmony_ci * in particular a2065.[ch]. The AMD C-LANCE datasheet was also helpful. 1262306a36Sopenharmony_ci */ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#ifndef _7990_H 1562306a36Sopenharmony_ci#define _7990_H 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci/* The lance only has two register locations. We communicate mostly via memory. */ 1862306a36Sopenharmony_ci#define LANCE_RDP 0 /* Register Data Port */ 1962306a36Sopenharmony_ci#define LANCE_RAP 2 /* Register Address Port */ 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci/* Transmit/receive ring definitions. 2262306a36Sopenharmony_ci * We allow the specific drivers to override these defaults if they want to. 2362306a36Sopenharmony_ci * NB: according to lance.c, increasing the number of buffers is a waste 2462306a36Sopenharmony_ci * of space and reduces the chance that an upper layer will be able to 2562306a36Sopenharmony_ci * reorder queued Tx packets based on priority. [Clearly there is a minimum 2662306a36Sopenharmony_ci * limit too: too small and we drop rx packets and can't tx at full speed.] 2762306a36Sopenharmony_ci * 4+4 seems to be the usual setting; the atarilance driver uses 3 and 5. 2862306a36Sopenharmony_ci */ 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci/* Blast! This won't work. The problem is that we can't specify a default 3162306a36Sopenharmony_ci * setting because that would cause the lance_init_block struct to be 3262306a36Sopenharmony_ci * too long (and overflow the RAM on shared-memory cards like the HP LANCE. 3362306a36Sopenharmony_ci */ 3462306a36Sopenharmony_ci#ifndef LANCE_LOG_TX_BUFFERS 3562306a36Sopenharmony_ci#define LANCE_LOG_TX_BUFFERS 1 3662306a36Sopenharmony_ci#define LANCE_LOG_RX_BUFFERS 3 3762306a36Sopenharmony_ci#endif 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci#define TX_RING_SIZE (1 << LANCE_LOG_TX_BUFFERS) 4062306a36Sopenharmony_ci#define RX_RING_SIZE (1 << LANCE_LOG_RX_BUFFERS) 4162306a36Sopenharmony_ci#define TX_RING_MOD_MASK (TX_RING_SIZE - 1) 4262306a36Sopenharmony_ci#define RX_RING_MOD_MASK (RX_RING_SIZE - 1) 4362306a36Sopenharmony_ci#define TX_RING_LEN_BITS ((LANCE_LOG_TX_BUFFERS) << 29) 4462306a36Sopenharmony_ci#define RX_RING_LEN_BITS ((LANCE_LOG_RX_BUFFERS) << 29) 4562306a36Sopenharmony_ci#define PKT_BUFF_SIZE (1544) 4662306a36Sopenharmony_ci#define RX_BUFF_SIZE PKT_BUFF_SIZE 4762306a36Sopenharmony_ci#define TX_BUFF_SIZE PKT_BUFF_SIZE 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci/* Each receive buffer is described by a receive message descriptor (RMD) */ 5062306a36Sopenharmony_cistruct lance_rx_desc { 5162306a36Sopenharmony_ci volatile unsigned short rmd0; /* low address of packet */ 5262306a36Sopenharmony_ci volatile unsigned char rmd1_bits; /* descriptor bits */ 5362306a36Sopenharmony_ci volatile unsigned char rmd1_hadr; /* high address of packet */ 5462306a36Sopenharmony_ci volatile short length; /* This length is 2s complement (negative)! 5562306a36Sopenharmony_ci * Buffer length */ 5662306a36Sopenharmony_ci volatile unsigned short mblength; /* Actual number of bytes received */ 5762306a36Sopenharmony_ci}; 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci/* Ditto for TMD: */ 6062306a36Sopenharmony_cistruct lance_tx_desc { 6162306a36Sopenharmony_ci volatile unsigned short tmd0; /* low address of packet */ 6262306a36Sopenharmony_ci volatile unsigned char tmd1_bits; /* descriptor bits */ 6362306a36Sopenharmony_ci volatile unsigned char tmd1_hadr; /* high address of packet */ 6462306a36Sopenharmony_ci volatile short length; /* Length is 2s complement (negative)! */ 6562306a36Sopenharmony_ci volatile unsigned short misc; 6662306a36Sopenharmony_ci}; 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci/* There are three memory structures accessed by the LANCE: 6962306a36Sopenharmony_ci * the initialization block, the receive and transmit descriptor rings, 7062306a36Sopenharmony_ci * and the data buffers themselves. In fact we might as well put the 7162306a36Sopenharmony_ci * init block,the Tx and Rx rings and the buffers together in memory: 7262306a36Sopenharmony_ci */ 7362306a36Sopenharmony_cistruct lance_init_block { 7462306a36Sopenharmony_ci volatile unsigned short mode; /* Pre-set mode (reg. 15) */ 7562306a36Sopenharmony_ci volatile unsigned char phys_addr[6]; /* Physical ethernet address */ 7662306a36Sopenharmony_ci volatile unsigned filter[2]; /* Multicast filter (64 bits) */ 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci /* Receive and transmit ring base, along with extra bits. */ 7962306a36Sopenharmony_ci volatile unsigned short rx_ptr; /* receive descriptor addr */ 8062306a36Sopenharmony_ci volatile unsigned short rx_len; /* receive len and high addr */ 8162306a36Sopenharmony_ci volatile unsigned short tx_ptr; /* transmit descriptor addr */ 8262306a36Sopenharmony_ci volatile unsigned short tx_len; /* transmit len and high addr */ 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci /* The Tx and Rx ring entries must be aligned on 8-byte boundaries. 8562306a36Sopenharmony_ci * This will be true if this whole struct is 8-byte aligned. 8662306a36Sopenharmony_ci */ 8762306a36Sopenharmony_ci volatile struct lance_tx_desc btx_ring[TX_RING_SIZE]; 8862306a36Sopenharmony_ci volatile struct lance_rx_desc brx_ring[RX_RING_SIZE]; 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci volatile char tx_buf[TX_RING_SIZE][TX_BUFF_SIZE]; 9162306a36Sopenharmony_ci volatile char rx_buf[RX_RING_SIZE][RX_BUFF_SIZE]; 9262306a36Sopenharmony_ci /* we use this just to make the struct big enough that we can move its startaddr 9362306a36Sopenharmony_ci * in order to force alignment to an eight byte boundary. 9462306a36Sopenharmony_ci */ 9562306a36Sopenharmony_ci}; 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci/* This is where we keep all the stuff the driver needs to know about. 9862306a36Sopenharmony_ci * I'm definitely unhappy about the mechanism for allowing specific 9962306a36Sopenharmony_ci * drivers to add things... 10062306a36Sopenharmony_ci */ 10162306a36Sopenharmony_cistruct lance_private { 10262306a36Sopenharmony_ci const char *name; 10362306a36Sopenharmony_ci unsigned long base; 10462306a36Sopenharmony_ci volatile struct lance_init_block *init_block; /* CPU address of RAM */ 10562306a36Sopenharmony_ci volatile struct lance_init_block *lance_init_block; /* LANCE address of RAM */ 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci int rx_new, tx_new; 10862306a36Sopenharmony_ci int rx_old, tx_old; 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci int lance_log_rx_bufs, lance_log_tx_bufs; 11162306a36Sopenharmony_ci int rx_ring_mod_mask, tx_ring_mod_mask; 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci int tpe; /* TPE is selected */ 11462306a36Sopenharmony_ci int auto_select; /* cable-selection is by carrier */ 11562306a36Sopenharmony_ci unsigned short busmaster_regval; 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci unsigned int irq; /* IRQ to register */ 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci /* This is because the HP LANCE is disgusting and you have to check 12062306a36Sopenharmony_ci * a DIO-specific register every time you read/write the LANCE regs :-< 12162306a36Sopenharmony_ci * [could we get away with making these some sort of macro?] 12262306a36Sopenharmony_ci */ 12362306a36Sopenharmony_ci void (*writerap)(void *, unsigned short); 12462306a36Sopenharmony_ci void (*writerdp)(void *, unsigned short); 12562306a36Sopenharmony_ci unsigned short (*readrdp)(void *); 12662306a36Sopenharmony_ci spinlock_t devlock; 12762306a36Sopenharmony_ci char tx_full; 12862306a36Sopenharmony_ci}; 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci/* 13162306a36Sopenharmony_ci * Am7990 Control and Status Registers 13262306a36Sopenharmony_ci */ 13362306a36Sopenharmony_ci#define LE_CSR0 0x0000 /* LANCE Controller Status */ 13462306a36Sopenharmony_ci#define LE_CSR1 0x0001 /* IADR[15:0] (bit0==0 ie word aligned) */ 13562306a36Sopenharmony_ci#define LE_CSR2 0x0002 /* IADR[23:16] (high bits reserved) */ 13662306a36Sopenharmony_ci#define LE_CSR3 0x0003 /* Misc */ 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci/* 13962306a36Sopenharmony_ci * Bit definitions for CSR0 (LANCE Controller Status) 14062306a36Sopenharmony_ci */ 14162306a36Sopenharmony_ci#define LE_C0_ERR 0x8000 /* Error = BABL | CERR | MISS | MERR */ 14262306a36Sopenharmony_ci#define LE_C0_BABL 0x4000 /* Babble: Transmitted too many bits */ 14362306a36Sopenharmony_ci#define LE_C0_CERR 0x2000 /* No Heartbeat (10BASE-T) */ 14462306a36Sopenharmony_ci#define LE_C0_MISS 0x1000 /* Missed Frame (no rx buffer to put it in) */ 14562306a36Sopenharmony_ci#define LE_C0_MERR 0x0800 /* Memory Error */ 14662306a36Sopenharmony_ci#define LE_C0_RINT 0x0400 /* Receive Interrupt */ 14762306a36Sopenharmony_ci#define LE_C0_TINT 0x0200 /* Transmit Interrupt */ 14862306a36Sopenharmony_ci#define LE_C0_IDON 0x0100 /* Initialization Done */ 14962306a36Sopenharmony_ci#define LE_C0_INTR 0x0080 /* Interrupt Flag 15062306a36Sopenharmony_ci = BABL | MISS | MERR | RINT | TINT | IDON */ 15162306a36Sopenharmony_ci#define LE_C0_INEA 0x0040 /* Interrupt Enable */ 15262306a36Sopenharmony_ci#define LE_C0_RXON 0x0020 /* Receive On */ 15362306a36Sopenharmony_ci#define LE_C0_TXON 0x0010 /* Transmit On */ 15462306a36Sopenharmony_ci#define LE_C0_TDMD 0x0008 /* Transmit Demand */ 15562306a36Sopenharmony_ci#define LE_C0_STOP 0x0004 /* Stop */ 15662306a36Sopenharmony_ci#define LE_C0_STRT 0x0002 /* Start */ 15762306a36Sopenharmony_ci#define LE_C0_INIT 0x0001 /* Initialize */ 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci/* 16162306a36Sopenharmony_ci * Bit definitions for CSR3 16262306a36Sopenharmony_ci */ 16362306a36Sopenharmony_ci#define LE_C3_BSWP 0x0004 /* Byte Swap (on for big endian byte order) */ 16462306a36Sopenharmony_ci#define LE_C3_ACON 0x0002 /* ALE Control (on for active low ALE) */ 16562306a36Sopenharmony_ci#define LE_C3_BCON 0x0001 /* Byte Control */ 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_ci/* 16962306a36Sopenharmony_ci * Mode Flags 17062306a36Sopenharmony_ci */ 17162306a36Sopenharmony_ci#define LE_MO_PROM 0x8000 /* Promiscuous Mode */ 17262306a36Sopenharmony_ci/* these next ones 0x4000 -- 0x0080 are not available on the LANCE 7990, 17362306a36Sopenharmony_ci * but they are in NetBSD's am7990.h, presumably for backwards-compatible chips 17462306a36Sopenharmony_ci */ 17562306a36Sopenharmony_ci#define LE_MO_DRCVBC 0x4000 /* disable receive broadcast */ 17662306a36Sopenharmony_ci#define LE_MO_DRCVPA 0x2000 /* disable physical address detection */ 17762306a36Sopenharmony_ci#define LE_MO_DLNKTST 0x1000 /* disable link status */ 17862306a36Sopenharmony_ci#define LE_MO_DAPC 0x0800 /* disable automatic polarity correction */ 17962306a36Sopenharmony_ci#define LE_MO_MENDECL 0x0400 /* MENDEC loopback mode */ 18062306a36Sopenharmony_ci#define LE_MO_LRTTSEL 0x0200 /* lower RX threshold / TX mode selection */ 18162306a36Sopenharmony_ci#define LE_MO_PSEL1 0x0100 /* port selection bit1 */ 18262306a36Sopenharmony_ci#define LE_MO_PSEL0 0x0080 /* port selection bit0 */ 18362306a36Sopenharmony_ci/* and this one is from the C-LANCE data sheet... */ 18462306a36Sopenharmony_ci#define LE_MO_EMBA 0x0080 /* Enable Modified Backoff Algorithm 18562306a36Sopenharmony_ci (C-LANCE, not original LANCE) */ 18662306a36Sopenharmony_ci#define LE_MO_INTL 0x0040 /* Internal Loopback */ 18762306a36Sopenharmony_ci#define LE_MO_DRTY 0x0020 /* Disable Retry */ 18862306a36Sopenharmony_ci#define LE_MO_FCOLL 0x0010 /* Force Collision */ 18962306a36Sopenharmony_ci#define LE_MO_DXMTFCS 0x0008 /* Disable Transmit CRC */ 19062306a36Sopenharmony_ci#define LE_MO_LOOP 0x0004 /* Loopback Enable */ 19162306a36Sopenharmony_ci#define LE_MO_DTX 0x0002 /* Disable Transmitter */ 19262306a36Sopenharmony_ci#define LE_MO_DRX 0x0001 /* Disable Receiver */ 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci 19562306a36Sopenharmony_ci/* 19662306a36Sopenharmony_ci * Receive Flags 19762306a36Sopenharmony_ci */ 19862306a36Sopenharmony_ci#define LE_R1_OWN 0x80 /* LANCE owns the descriptor */ 19962306a36Sopenharmony_ci#define LE_R1_ERR 0x40 /* Error */ 20062306a36Sopenharmony_ci#define LE_R1_FRA 0x20 /* Framing Error */ 20162306a36Sopenharmony_ci#define LE_R1_OFL 0x10 /* Overflow Error */ 20262306a36Sopenharmony_ci#define LE_R1_CRC 0x08 /* CRC Error */ 20362306a36Sopenharmony_ci#define LE_R1_BUF 0x04 /* Buffer Error */ 20462306a36Sopenharmony_ci#define LE_R1_SOP 0x02 /* Start of Packet */ 20562306a36Sopenharmony_ci#define LE_R1_EOP 0x01 /* End of Packet */ 20662306a36Sopenharmony_ci#define LE_R1_POK 0x03 /* Packet is complete: SOP + EOP */ 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci/* 21062306a36Sopenharmony_ci * Transmit Flags 21162306a36Sopenharmony_ci */ 21262306a36Sopenharmony_ci#define LE_T1_OWN 0x80 /* LANCE owns the descriptor */ 21362306a36Sopenharmony_ci#define LE_T1_ERR 0x40 /* Error */ 21462306a36Sopenharmony_ci#define LE_T1_RES 0x20 /* Reserved, LANCE writes this with a zero */ 21562306a36Sopenharmony_ci#define LE_T1_EMORE 0x10 /* More than one retry needed */ 21662306a36Sopenharmony_ci#define LE_T1_EONE 0x08 /* One retry needed */ 21762306a36Sopenharmony_ci#define LE_T1_EDEF 0x04 /* Deferred */ 21862306a36Sopenharmony_ci#define LE_T1_SOP 0x02 /* Start of Packet */ 21962306a36Sopenharmony_ci#define LE_T1_EOP 0x01 /* End of Packet */ 22062306a36Sopenharmony_ci#define LE_T1_POK 0x03 /* Packet is complete: SOP + EOP */ 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_ci/* 22362306a36Sopenharmony_ci * Error Flags 22462306a36Sopenharmony_ci */ 22562306a36Sopenharmony_ci#define LE_T3_BUF 0x8000 /* Buffer Error */ 22662306a36Sopenharmony_ci#define LE_T3_UFL 0x4000 /* Underflow Error */ 22762306a36Sopenharmony_ci#define LE_T3_LCOL 0x1000 /* Late Collision */ 22862306a36Sopenharmony_ci#define LE_T3_CLOS 0x0800 /* Loss of Carrier */ 22962306a36Sopenharmony_ci#define LE_T3_RTY 0x0400 /* Retry Error */ 23062306a36Sopenharmony_ci#define LE_T3_TDR 0x03ff /* Time Domain Reflectometry */ 23162306a36Sopenharmony_ci 23262306a36Sopenharmony_ci/* Miscellaneous useful macros */ 23362306a36Sopenharmony_ci 23462306a36Sopenharmony_ci#define TX_BUFFS_AVAIL ((lp->tx_old <= lp->tx_new) ? \ 23562306a36Sopenharmony_ci lp->tx_old + lp->tx_ring_mod_mask - lp->tx_new : \ 23662306a36Sopenharmony_ci lp->tx_old - lp->tx_new - 1) 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ci/* The LANCE only uses 24 bit addresses. This does the obvious thing. */ 23962306a36Sopenharmony_ci#define LANCE_ADDR(x) ((int)(x) & ~0xff000000) 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_ci/* Now the prototypes we export */ 24262306a36Sopenharmony_ciint lance_open(struct net_device *dev); 24362306a36Sopenharmony_ciint lance_close(struct net_device *dev); 24462306a36Sopenharmony_cinetdev_tx_t lance_start_xmit(struct sk_buff *skb, struct net_device *dev); 24562306a36Sopenharmony_civoid lance_set_multicast(struct net_device *dev); 24662306a36Sopenharmony_civoid lance_tx_timeout(struct net_device *dev, unsigned int txqueue); 24762306a36Sopenharmony_ci#ifdef CONFIG_NET_POLL_CONTROLLER 24862306a36Sopenharmony_civoid lance_poll(struct net_device *dev); 24962306a36Sopenharmony_ci#endif 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_ci#endif /* ndef _7990_H */ 252