1 | /* |
---|
2 | ------------------------------------------------------------------------ |
---|
3 | $Id$ |
---|
4 | ------------------------------------------------------------------------ |
---|
5 | |
---|
6 | My Right Boot, a boot ROM for embedded hardware. |
---|
7 | |
---|
8 | Copyright Cybertec Pty Ltd, 2000 |
---|
9 | All rights reserved Cybertec Pty Ltd, 2000 |
---|
10 | |
---|
11 | COPYRIGHT (c) 1989-1998. |
---|
12 | On-Line Applications Research Corporation (OAR). |
---|
13 | Copyright assigned to U.S. Government, 1994. |
---|
14 | |
---|
15 | The license and distribution terms for this file may be |
---|
16 | found in the file LICENSE in this distribution or at |
---|
17 | http://www.OARcorp.com/rtems/license.html. |
---|
18 | |
---|
19 | ------------------------------------------------------------------------ |
---|
20 | |
---|
21 | CS8900 net boot driver. |
---|
22 | |
---|
23 | */ |
---|
24 | |
---|
25 | #include <bspIo.h> |
---|
26 | #include <rtems.h> |
---|
27 | |
---|
28 | #include <libchip/cs8900.h> |
---|
29 | |
---|
30 | /* |
---|
31 | * Our local data. |
---|
32 | */ |
---|
33 | |
---|
34 | #ifdef CS8900_VERBOSE |
---|
35 | static BOOLEAN cs8900_io_verbose; |
---|
36 | #endif |
---|
37 | |
---|
38 | static rtems_isr_void_entry old_handler[CS8900_DEVICES]; |
---|
39 | static void *old_parameter[CS8900_DEVICES]; |
---|
40 | |
---|
41 | /* |
---|
42 | * Tables of IO addresses and interrupt levels for each device attached. |
---|
43 | */ |
---|
44 | |
---|
45 | static const unsigned long ethernet_io_base[CS8900_DEVICES] = |
---|
46 | { |
---|
47 | ETHERNET_BASE |
---|
48 | }; |
---|
49 | |
---|
50 | static const unsigned long ethernet_mem_base[CS8900_DEVICES] = |
---|
51 | { |
---|
52 | ETHERNET_BASE + CS8900_MEMORY_BASE |
---|
53 | }; |
---|
54 | |
---|
55 | static const unsigned int ethernet_irq_level[CS8900_DEVICES] = |
---|
56 | { |
---|
57 | ETHERNET_IRQ_LEVEL |
---|
58 | }; |
---|
59 | |
---|
60 | static const unsigned int ethernet_irq_priority[CS8900_DEVICES] = |
---|
61 | { |
---|
62 | ETHERNET_IRQ_PRIORITY |
---|
63 | }; |
---|
64 | |
---|
65 | static const unsigned int ethernet_irq_vector[CS8900_DEVICES] = |
---|
66 | { |
---|
67 | ETHERNET_IRQ_VECTOR, |
---|
68 | }; |
---|
69 | |
---|
70 | void cs8900_io_set_reg (int dev, unsigned short reg, unsigned short data) |
---|
71 | { |
---|
72 | #ifdef CS8900_DATA_BUS_SWAPPED |
---|
73 | data = (data >> 8) | (data << 8); |
---|
74 | #endif |
---|
75 | |
---|
76 | #ifdef CS8900_VERBOSE |
---|
77 | if (cs8900_io_verbose) |
---|
78 | printf ("CS8900: io set reg=0x%04x, data=0x%04x\n", reg, data); |
---|
79 | #endif |
---|
80 | |
---|
81 | WRITE_REGISTER_16 (ethernet_io_base[dev] + reg, data); |
---|
82 | } |
---|
83 | |
---|
84 | unsigned short cs8900_io_get_reg (int dev, unsigned short reg) |
---|
85 | { |
---|
86 | unsigned long data; |
---|
87 | |
---|
88 | READ_REGISTER_16 (ethernet_io_base[dev] + reg, data); |
---|
89 | |
---|
90 | #ifdef CS8900_DATA_BUS_SWAPPED |
---|
91 | data = (data >> 8) | (data << 8); |
---|
92 | #endif |
---|
93 | |
---|
94 | #ifdef CS8900_VERBOSE |
---|
95 | if (cs8900_io_verbose) |
---|
96 | printk ("CS8900: io get reg=0x%04x, data=0x%04x\n", reg, data); |
---|
97 | #endif |
---|
98 | |
---|
99 | return data; |
---|
100 | } |
---|
101 | |
---|
102 | void cs8900_mem_set_reg (int dev, unsigned long reg, unsigned short data) |
---|
103 | { |
---|
104 | #ifdef CS8900_DATA_BUS_SWAPPED |
---|
105 | data = (data >> 8) | (data << 8); |
---|
106 | #endif |
---|
107 | |
---|
108 | #ifdef CS8900_VERBOSE |
---|
109 | if (cs8900_io_verbose) |
---|
110 | printk ("CS8900: mem set reg=0x%04x, data=0x%04x\n", reg, data); |
---|
111 | #endif |
---|
112 | |
---|
113 | WRITE_REGISTER_16 (ethernet_io_base[dev] + reg, data); |
---|
114 | } |
---|
115 | |
---|
116 | unsigned short cs8900_mem_get_reg (int dev, unsigned long reg) |
---|
117 | { |
---|
118 | unsigned short data; |
---|
119 | READ_REGISTER_16 (ethernet_io_base[dev] + reg, data); |
---|
120 | |
---|
121 | #ifdef CS8900_DATA_BUS_SWAPPED |
---|
122 | data = (data >> 8) | (data << 8); |
---|
123 | #endif |
---|
124 | |
---|
125 | #ifdef CS8900_VERBOSE |
---|
126 | if (cs8900_io_verbose) |
---|
127 | printk ("CS8900: mem get reg=0x%04x, data=0x%04x\n", reg, data); |
---|
128 | #endif |
---|
129 | |
---|
130 | return data; |
---|
131 | } |
---|
132 | |
---|
133 | void cs8900_put_data_block (int dev, int len, unsigned char *data) |
---|
134 | { |
---|
135 | #ifndef CS8900_DATA_BUS_SWAPPED |
---|
136 | unsigned short swap_word; |
---|
137 | #endif |
---|
138 | unsigned short *src = (unsigned short *) ((unsigned long) data); |
---|
139 | unsigned short *dst = (unsigned short *) (ethernet_mem_base[dev] + CS8900_PP_TxFrameLoc); |
---|
140 | |
---|
141 | while (len > 1) |
---|
142 | { |
---|
143 | #ifndef CS8900_DATA_BUS_SWAPPED |
---|
144 | swap_word = *src++; |
---|
145 | *dst++ = (swap_word >> 8) | (swap_word << 8); |
---|
146 | #else |
---|
147 | *dst++ = *src++; |
---|
148 | #endif |
---|
149 | len -= 2; |
---|
150 | } |
---|
151 | |
---|
152 | if (len) |
---|
153 | { |
---|
154 | #ifndef CS8900_DATA_BUS_SWAPPED |
---|
155 | swap_word = *src++; |
---|
156 | *dst++ = (swap_word >> 8) | (swap_word << 8); |
---|
157 | #else |
---|
158 | *dst++ = *src++; |
---|
159 | #endif |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | unsigned short cs8900_get_data_block (int dev, unsigned char *data) |
---|
164 | { |
---|
165 | unsigned short swap_word; |
---|
166 | volatile unsigned short *src = (unsigned short *) (ethernet_mem_base[dev] + CS8900_PP_RxLength); |
---|
167 | unsigned short *dst; |
---|
168 | unsigned short len; |
---|
169 | unsigned short rx_len; |
---|
170 | unsigned short len_odd; |
---|
171 | |
---|
172 | #ifdef CS8900_DATA_BUS_SWAPPED |
---|
173 | swap_word = *src++; |
---|
174 | len = (swap_word >> 8) | (swap_word << 8); |
---|
175 | #else |
---|
176 | len = *src++; |
---|
177 | #endif |
---|
178 | |
---|
179 | dst = (unsigned short *) ((unsigned long) data); |
---|
180 | |
---|
181 | len_odd = len & 1; |
---|
182 | rx_len = len & ~1; |
---|
183 | |
---|
184 | for (; rx_len; rx_len -= 2) |
---|
185 | { |
---|
186 | #ifndef CS8900_DATA_BUS_SWAPPED |
---|
187 | swap_word = *src++; |
---|
188 | *dst++ = (swap_word >> 8) | (swap_word << 8); |
---|
189 | #else |
---|
190 | *dst++ = *src++; |
---|
191 | #endif |
---|
192 | } |
---|
193 | |
---|
194 | if (len_odd) |
---|
195 | { |
---|
196 | #ifndef CS8900_DATA_BUS_SWAPPED |
---|
197 | swap_word = *src++; |
---|
198 | *dst++ = (swap_word >> 8) | (swap_word << 8); |
---|
199 | #else |
---|
200 | *dst++ = *src++; |
---|
201 | #endif |
---|
202 | } |
---|
203 | |
---|
204 | return len; |
---|
205 | } |
---|
206 | |
---|
207 | void |
---|
208 | cs8900_tx_load (int dev, struct mbuf *m) |
---|
209 | { |
---|
210 | volatile unsigned short *dst = (unsigned short *) (ethernet_mem_base[dev] + CS8900_PP_TxFrameLoc); |
---|
211 | unsigned int len; |
---|
212 | unsigned char *src; |
---|
213 | int remainder = 0; |
---|
214 | unsigned char remainder_data = '\0'; |
---|
215 | |
---|
216 | while (m) |
---|
217 | { |
---|
218 | /* |
---|
219 | * We can get empty mbufs from the stack. |
---|
220 | */ |
---|
221 | |
---|
222 | len = m->m_len; |
---|
223 | src = mtod (m, unsigned char*); |
---|
224 | |
---|
225 | if (len) |
---|
226 | { |
---|
227 | if (remainder) |
---|
228 | { |
---|
229 | #ifndef CS8900_DATA_BUS_SWAPPED |
---|
230 | *dst++ = remainder_data | (*src++ << 8); |
---|
231 | #else |
---|
232 | *dst++ = *src++ | (remainder_data << 8); |
---|
233 | #endif |
---|
234 | len--; |
---|
235 | remainder = 0; |
---|
236 | } |
---|
237 | |
---|
238 | if (len & 1) |
---|
239 | { |
---|
240 | remainder = 1; |
---|
241 | len--; |
---|
242 | } |
---|
243 | |
---|
244 | for (; len; len -= 2) |
---|
245 | #ifndef CS8900_DATA_BUS_SWAPPED |
---|
246 | *dst++ = (*src++) | (*(++src) << 8); |
---|
247 | #else |
---|
248 | *dst++ = (*src++ << 8) | *(++src); |
---|
249 | #endif |
---|
250 | |
---|
251 | if (remainder) |
---|
252 | remainder_data = *src++; |
---|
253 | } |
---|
254 | |
---|
255 | m = m->m_next; |
---|
256 | } |
---|
257 | |
---|
258 | if (remainder) |
---|
259 | { |
---|
260 | #ifndef CS8900_DATA_BUS_SWAPPED |
---|
261 | *dst = (unsigned short) remainder_data; |
---|
262 | #else |
---|
263 | *dst = (unsigned short) (remainder_data << 8); |
---|
264 | #endif |
---|
265 | } |
---|
266 | } |
---|
267 | |
---|
268 | void cs8900_attach_interrupt (int dev, cs8900_device *cs) |
---|
269 | { |
---|
270 | rtems_interrupt_catch_with_void (cs8900_interrupt, |
---|
271 | ethernet_irq_vector[dev], |
---|
272 | &old_handler[dev], |
---|
273 | cs, |
---|
274 | &old_parameter[dev]); |
---|
275 | |
---|
276 | CF_SIM_WRITE_ICR (CF_BASE, |
---|
277 | ethernet_irq_level[dev], |
---|
278 | CF_SIM_ICR_AVEC_AUTO, |
---|
279 | ethernet_irq_level[dev], |
---|
280 | ethernet_irq_priority[dev]); |
---|
281 | CF_SIM_IMR_ENABLE (CF_BASE, 1 << ethernet_irq_level[dev]); |
---|
282 | } |
---|
283 | |
---|
284 | void cs8900_detach_interrupt (int dev) |
---|
285 | { |
---|
286 | CF_SIM_IMR_DISABLE (CF_BASE, 1 << ethernet_irq_level[dev]); |
---|
287 | |
---|
288 | rtems_interrupt_catch_with_void (old_handler, |
---|
289 | ethernet_irq_vector[dev], |
---|
290 | NULL, |
---|
291 | old_parameter[dev], |
---|
292 | NULL); |
---|
293 | } |
---|
294 | |
---|
295 | void cs8900_get_mac_addr (int dev, unsigned char *mac_address) |
---|
296 | { |
---|
297 | memcpy (mac_address, rct_get_mac_address (dev), 6); |
---|
298 | } |
---|