1 /**************************************************
3 * Definition of D-Link Ethernet Pocket adapter *
5 **************************************************/
7 * D-Link Ethernet pocket adapter ports
10 * OK, so I'm cheating, but there are an awful lot of
11 * reads and writes in order to get anything in and out
12 * of the DE-600 with 4 bits at a time in the parallel port,
13 * so every saved instruction really helps :-)
17 #define DE600_IO 0x378
20 #define DATA_PORT (DE600_IO)
21 #define STATUS_PORT (DE600_IO + 1)
22 #define COMMAND_PORT (DE600_IO + 2)
28 * It really should look like this, and autoprobing as well...
30 #define DATA_PORT (dev->base_addr + 0)
31 #define STATUS_PORT (dev->base_addr + 1)
32 #define COMMAND_PORT (dev->base_addr + 2)
33 #define DE600_IRQ dev->irq
37 * D-Link COMMAND_PORT commands
39 #define SELECT_NIC 0x04 /* select Network Interface Card */
40 #define SELECT_PRN 0x1c /* select Printer */
41 #define NML_PRN 0xec /* normal Printer situation */
42 #define IRQEN 0x10 /* enable IRQ line */
49 #define TX_FAILED16 0x10
53 * D-Link DATA_PORT commands
54 * command in low 4 bits
56 * select current data nibble with HI_NIBBLE bit
58 #define WRITE_DATA 0x00 /* write memory */
59 #define READ_DATA 0x01 /* read memory */
60 #define STATUS 0x02 /* read status register */
61 #define COMMAND 0x03 /* write command register (see COMMAND below) */
62 #define NULL_COMMAND 0x04 /* null command */
63 #define RX_LEN 0x05 /* read received packet length */
64 #define TX_ADDR 0x06 /* set adapter transmit memory address */
65 #define RW_ADDR 0x07 /* set adapter read/write memory address */
66 #define HI_NIBBLE 0x08 /* read/write the high nibble of data,
67 or-ed with rest of command */
70 * command register, accessed through DATA_PORT with low bits = COMMAND
72 #define RX_ALL 0x01 /* PROMISCUOUS */
73 #define RX_BP 0x02 /* default: BROADCAST & PHYSICAL ADDRESS */
74 #define RX_MBP 0x03 /* MULTICAST, BROADCAST & PHYSICAL ADDRESS */
76 #define TX_ENABLE 0x04 /* bit 2 */
77 #define RX_ENABLE 0x08 /* bit 3 */
79 #define RESET 0x80 /* set bit 7 high */
80 #define STOP_RESET 0x00 /* set bit 7 low */
83 * data to command register
84 * (high 4 bits in write to DATA_PORT)
86 #define RX_PAGE2_SELECT 0x10 /* bit 4, only 2 pages to select */
87 #define RX_BASE_PAGE 0x20 /* bit 5, always set when specifying RX_ADDR */
88 #define FLIP_IRQ 0x40 /* bit 6 */
91 * D-Link adapter internal memory:
93 * 0-2K 1:st transmit page (send from pointer up to 2K)
94 * 2-4K 2:nd transmit page (send from pointer up to 4K)
96 * 4-6K 1:st receive page (data from 4K upwards)
97 * 6-8K 2:nd receive page (data from 6K upwards)
99 * 8K+ Adapter ROM (contains magic code and last 3 bytes of Ethernet address)
101 #define MEM_2K 0x0800 /* 2048 */
102 #define MEM_4K 0x1000 /* 4096 */
103 #define MEM_6K 0x1800 /* 6144 */
104 #define NODE_ADDRESS 0x2000 /* 8192 */
106 #define RUNT 60 /* Too small Ethernet packet */
108 /**************************************************
110 * End of definition *
112 **************************************************/
115 * Index to functions, as function prototypes.
117 /* Routines used internally. (See "convenience macros") */
118 static u8 de600_read_status(struct net_device *dev);
119 static u8 de600_read_byte(unsigned char type, struct net_device *dev);
121 /* Put in the device structure. */
122 static int de600_open(struct net_device *dev);
123 static int de600_close(struct net_device *dev);
124 static struct net_device_stats *get_stats(struct net_device *dev);
125 static int de600_start_xmit(struct sk_buff *skb, struct net_device *dev);
127 /* Dispatch from interrupts. */
128 static irqreturn_t de600_interrupt(int irq, void *dev_id, struct pt_regs *regs);
129 static int de600_tx_intr(struct net_device *dev, int irq_status);
130 static void de600_rx_intr(struct net_device *dev);
133 static void trigger_interrupt(struct net_device *dev);
134 static int adapter_init(struct net_device *dev);
137 * Convenience macros/functions for D-Link adapter
140 #define select_prn() outb_p(SELECT_PRN, COMMAND_PORT); DE600_SLOW_DOWN
141 #define select_nic() outb_p(SELECT_NIC, COMMAND_PORT); DE600_SLOW_DOWN
143 /* Thanks for hints from Mark Burton <markb@ordern.demon.co.uk> */
144 #define de600_put_byte(data) ( \
145 outb_p(((data) << 4) | WRITE_DATA , DATA_PORT), \
146 outb_p(((data) & 0xf0) | WRITE_DATA | HI_NIBBLE, DATA_PORT))
149 * The first two outb_p()'s below could perhaps be deleted if there
150 * would be more delay in the last two. Not certain about it yet...
152 #define de600_put_command(cmd) ( \
153 outb_p(( rx_page << 4) | COMMAND , DATA_PORT), \
154 outb_p(( rx_page & 0xf0) | COMMAND | HI_NIBBLE, DATA_PORT), \
155 outb_p(((rx_page | cmd) << 4) | COMMAND , DATA_PORT), \
156 outb_p(((rx_page | cmd) & 0xf0) | COMMAND | HI_NIBBLE, DATA_PORT))
158 #define de600_setup_address(addr,type) ( \
159 outb_p((((addr) << 4) & 0xf0) | type , DATA_PORT), \
160 outb_p(( (addr) & 0xf0) | type | HI_NIBBLE, DATA_PORT), \
161 outb_p((((addr) >> 4) & 0xf0) | type , DATA_PORT), \
162 outb_p((((addr) >> 8) & 0xf0) | type | HI_NIBBLE, DATA_PORT))
164 #define rx_page_adr() ((rx_page & RX_PAGE2_SELECT)?(MEM_6K):(MEM_4K))
166 /* Flip bit, only 2 pages */
167 #define next_rx_page() (rx_page ^= RX_PAGE2_SELECT)
169 #define tx_page_adr(a) (((a) + 1) * MEM_2K)