Merge branch 'drm-intel-next' of git://git.kernel.org/pub/scm/linux/kernel/git/anholt...
[pandora-kernel.git] / drivers / net / de600.h
1 /**************************************************
2  *                                                *
3  * Definition of D-Link Ethernet Pocket adapter   *
4  *                                                *
5  **************************************************/
6 /*
7  * D-Link Ethernet pocket adapter ports
8  */
9 /*
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 :-)
14  */
15
16 #ifndef DE600_IO
17 #define DE600_IO        0x378
18 #endif
19
20 #define DATA_PORT       (DE600_IO)
21 #define STATUS_PORT     (DE600_IO + 1)
22 #define COMMAND_PORT    (DE600_IO + 2)
23
24 #ifndef DE600_IRQ
25 #define DE600_IRQ       7
26 #endif
27 /*
28  * It really should look like this, and autoprobing as well...
29  *
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
34  */
35
36 /*
37  * D-Link COMMAND_PORT commands
38  */
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 */
43
44 /*
45  * D-Link STATUS_PORT
46  */
47 #define RX_BUSY         0x80
48 #define RX_GOOD         0x40
49 #define TX_FAILED16     0x10
50 #define TX_BUSY         0x08
51
52 /*
53  * D-Link DATA_PORT commands
54  * command in low 4 bits
55  * data in high 4 bits
56  * select current data nibble with HI_NIBBLE bit
57  */
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 */
68
69 /*
70  * command register, accessed through DATA_PORT with low bits = COMMAND
71  */
72 #define RX_ALL          0x01 /* PROMISCUOUS */
73 #define RX_BP           0x02 /* default: BROADCAST & PHYSICAL ADDRESS */
74 #define RX_MBP          0x03 /* MULTICAST, BROADCAST & PHYSICAL ADDRESS */
75
76 #define TX_ENABLE       0x04 /* bit 2 */
77 #define RX_ENABLE       0x08 /* bit 3 */
78
79 #define RESET           0x80 /* set bit 7 high */
80 #define STOP_RESET      0x00 /* set bit 7 low */
81
82 /*
83  * data to command register
84  * (high 4 bits in write to DATA_PORT)
85  */
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 */
89
90 /*
91  * D-Link adapter internal memory:
92  *
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)
95  *
96  * 4-6K 1:st receive page (data from 4K upwards)
97  * 6-8K 2:nd receive page (data from 6K upwards)
98  *
99  * 8K+  Adapter ROM (contains magic code and last 3 bytes of Ethernet address)
100  */
101 #define MEM_2K          0x0800 /* 2048 */
102 #define MEM_4K          0x1000 /* 4096 */
103 #define MEM_6K          0x1800 /* 6144 */
104 #define NODE_ADDRESS    0x2000 /* 8192 */
105
106 #define RUNT 60         /* Too small Ethernet packet */
107
108 /**************************************************
109  *                                                *
110  *             End of definition                  *
111  *                                                *
112  **************************************************/
113
114 /*
115  * Index to functions, as function prototypes.
116  */
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);
120
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 int      de600_start_xmit(struct sk_buff *skb, struct net_device *dev);
125
126 /* Dispatch from interrupts. */
127 static irqreturn_t de600_interrupt(int irq, void *dev_id);
128 static int      de600_tx_intr(struct net_device *dev, int irq_status);
129 static void     de600_rx_intr(struct net_device *dev);
130
131 /* Initialization */
132 static void     trigger_interrupt(struct net_device *dev);
133 static int      adapter_init(struct net_device *dev);
134
135 /*
136  * Convenience macros/functions for D-Link adapter
137  */
138
139 #define select_prn() outb_p(SELECT_PRN, COMMAND_PORT); DE600_SLOW_DOWN
140 #define select_nic() outb_p(SELECT_NIC, COMMAND_PORT); DE600_SLOW_DOWN
141
142 /* Thanks for hints from Mark Burton <markb@ordern.demon.co.uk> */
143 #define de600_put_byte(data) ( \
144         outb_p(((data) << 4)   | WRITE_DATA            , DATA_PORT), \
145         outb_p(((data) & 0xf0) | WRITE_DATA | HI_NIBBLE, DATA_PORT))
146
147 /*
148  * The first two outb_p()'s below could perhaps be deleted if there
149  * would be more delay in the last two. Not certain about it yet...
150  */
151 #define de600_put_command(cmd) ( \
152         outb_p(( rx_page        << 4)   | COMMAND            , DATA_PORT), \
153         outb_p(( rx_page        & 0xf0) | COMMAND | HI_NIBBLE, DATA_PORT), \
154         outb_p(((rx_page | cmd) << 4)   | COMMAND            , DATA_PORT), \
155         outb_p(((rx_page | cmd) & 0xf0) | COMMAND | HI_NIBBLE, DATA_PORT))
156
157 #define de600_setup_address(addr,type) ( \
158         outb_p((((addr) << 4) & 0xf0) | type            , DATA_PORT), \
159         outb_p(( (addr)       & 0xf0) | type | HI_NIBBLE, DATA_PORT), \
160         outb_p((((addr) >> 4) & 0xf0) | type            , DATA_PORT), \
161         outb_p((((addr) >> 8) & 0xf0) | type | HI_NIBBLE, DATA_PORT))
162
163 #define rx_page_adr() ((rx_page & RX_PAGE2_SELECT)?(MEM_6K):(MEM_4K))
164
165 /* Flip bit, only 2 pages */
166 #define next_rx_page() (rx_page ^= RX_PAGE2_SELECT)
167
168 #define tx_page_adr(a) (((a) + 1) * MEM_2K)