File: | obj-scan-build/../linux/src/drivers/net/depca.c |
Location: | line 1452, column 3 |
Description: | Value stored to 'data' is never read |
1 | /* depca.c: A DIGITAL DEPCA & EtherWORKS ethernet driver for linux. |
2 | |
3 | Written 1994, 1995 by David C. Davies. |
4 | |
5 | |
6 | Copyright 1994 David C. Davies |
7 | and |
8 | United States Government |
9 | (as represented by the Director, National Security Agency). |
10 | |
11 | Copyright 1995 Digital Equipment Corporation. |
12 | |
13 | |
14 | This software may be used and distributed according to the terms of |
15 | the GNU Public License, incorporated herein by reference. |
16 | |
17 | This driver is written for the Digital Equipment Corporation series |
18 | of DEPCA and EtherWORKS ethernet cards: |
19 | |
20 | DEPCA (the original) |
21 | DE100 |
22 | DE101 |
23 | DE200 Turbo |
24 | DE201 Turbo |
25 | DE202 Turbo (TP BNC) |
26 | DE210 |
27 | DE422 (EISA) |
28 | |
29 | The driver has been tested on DE100, DE200 and DE202 cards in a |
30 | relatively busy network. The DE422 has been tested a little. |
31 | |
32 | This driver will NOT work for the DE203, DE204 and DE205 series of |
33 | cards, since they have a new custom ASIC in place of the AMD LANCE |
34 | chip. See the 'ewrk3.c' driver in the Linux source tree for running |
35 | those cards. |
36 | |
37 | I have benchmarked the driver with a DE100 at 595kB/s to (542kB/s from) |
38 | a DECstation 5000/200. |
39 | |
40 | The author may be reached at davies@maniac.ultranet.com |
41 | |
42 | ========================================================================= |
43 | |
44 | The driver was originally based on the 'lance.c' driver from Donald |
45 | Becker which is included with the standard driver distribution for |
46 | linux. V0.4 is a complete re-write with only the kernel interface |
47 | remaining from the original code. |
48 | |
49 | 1) Lance.c code in /linux/drivers/net/ |
50 | 2) "Ethernet/IEEE 802.3 Family. 1992 World Network Data Book/Handbook", |
51 | AMD, 1992 [(800) 222-9323]. |
52 | 3) "Am79C90 CMOS Local Area Network Controller for Ethernet (C-LANCE)", |
53 | AMD, Pub. #17881, May 1993. |
54 | 4) "Am79C960 PCnet-ISA(tm), Single-Chip Ethernet Controller for ISA", |
55 | AMD, Pub. #16907, May 1992 |
56 | 5) "DEC EtherWORKS LC Ethernet Controller Owners Manual", |
57 | Digital Equipment corporation, 1990, Pub. #EK-DE100-OM.003 |
58 | 6) "DEC EtherWORKS Turbo Ethernet Controller Owners Manual", |
59 | Digital Equipment corporation, 1990, Pub. #EK-DE200-OM.003 |
60 | 7) "DEPCA Hardware Reference Manual", Pub. #EK-DEPCA-PR |
61 | Digital Equipment Corporation, 1989 |
62 | 8) "DEC EtherWORKS Turbo_(TP BNC) Ethernet Controller Owners Manual", |
63 | Digital Equipment corporation, 1991, Pub. #EK-DE202-OM.001 |
64 | |
65 | |
66 | Peter Bauer's depca.c (V0.5) was referred to when debugging V0.1 of this |
67 | driver. |
68 | |
69 | The original DEPCA card requires that the ethernet ROM address counter |
70 | be enabled to count and has an 8 bit NICSR. The ROM counter enabling is |
71 | only done when a 0x08 is read as the first address octet (to minimise |
72 | the chances of writing over some other hardware's I/O register). The |
73 | NICSR accesses have been changed to byte accesses for all the cards |
74 | supported by this driver, since there is only one useful bit in the MSB |
75 | (remote boot timeout) and it is not used. Also, there is a maximum of |
76 | only 48kB network RAM for this card. My thanks to Torbjorn Lindh for |
77 | help debugging all this (and holding my feet to the fire until I got it |
78 | right). |
79 | |
80 | The DE200 series boards have on-board 64kB RAM for use as a shared |
81 | memory network buffer. Only the DE100 cards make use of a 2kB buffer |
82 | mode which has not been implemented in this driver (only the 32kB and |
83 | 64kB modes are supported [16kB/48kB for the original DEPCA]). |
84 | |
85 | At the most only 2 DEPCA cards can be supported on the ISA bus because |
86 | there is only provision for two I/O base addresses on each card (0x300 |
87 | and 0x200). The I/O address is detected by searching for a byte sequence |
88 | in the Ethernet station address PROM at the expected I/O address for the |
89 | Ethernet PROM. The shared memory base address is 'autoprobed' by |
90 | looking for the self test PROM and detecting the card name. When a |
91 | second DEPCA is detected, information is placed in the base_addr |
92 | variable of the next device structure (which is created if necessary), |
93 | thus enabling ethif_probe initialization for the device. More than 2 |
94 | EISA cards can be supported, but care will be needed assigning the |
95 | shared memory to ensure that each slot has the correct IRQ, I/O address |
96 | and shared memory address assigned. |
97 | |
98 | ************************************************************************ |
99 | |
100 | NOTE: If you are using two ISA DEPCAs, it is important that you assign |
101 | the base memory addresses correctly. The driver autoprobes I/O 0x300 |
102 | then 0x200. The base memory address for the first device must be less |
103 | than that of the second so that the auto probe will correctly assign the |
104 | I/O and memory addresses on the same card. I can't think of a way to do |
105 | this unambiguously at the moment, since there is nothing on the cards to |
106 | tie I/O and memory information together. |
107 | |
108 | I am unable to test 2 cards together for now, so this code is |
109 | unchecked. All reports, good or bad, are welcome. |
110 | |
111 | ************************************************************************ |
112 | |
113 | The board IRQ setting must be at an unused IRQ which is auto-probed |
114 | using Donald Becker's autoprobe routines. DEPCA and DE100 board IRQs are |
115 | {2,3,4,5,7}, whereas the DE200 is at {5,9,10,11,15}. Note that IRQ2 is |
116 | really IRQ9 in machines with 16 IRQ lines. |
117 | |
118 | No 16MB memory limitation should exist with this driver as DMA is not |
119 | used and the common memory area is in low memory on the network card (my |
120 | current system has 20MB and I've not had problems yet). |
121 | |
122 | The ability to load this driver as a loadable module has been added. To |
123 | utilise this ability, you have to do <8 things: |
124 | |
125 | 0) have a copy of the loadable modules code installed on your system. |
126 | 1) copy depca.c from the /linux/drivers/net directory to your favourite |
127 | temporary directory. |
128 | 2) if you wish, edit the source code near line 1530 to reflect the I/O |
129 | address and IRQ you're using (see also 5). |
130 | 3) compile depca.c, but include -DMODULE in the command line to ensure |
131 | that the correct bits are compiled (see end of source code). |
132 | 4) if you are wanting to add a new card, goto 5. Otherwise, recompile a |
133 | kernel with the depca configuration turned off and reboot. |
134 | 5) insmod depca.o [irq=7] [io=0x200] [mem=0xd0000] [adapter_name=DE100] |
135 | [Alan Cox: Changed the code to allow command line irq/io assignments] |
136 | [Dave Davies: Changed the code to allow command line mem/name |
137 | assignments] |
138 | 6) run the net startup bits for your eth?? interface manually |
139 | (usually /etc/rc.inet[12] at boot time). |
140 | 7) enjoy! |
141 | |
142 | Note that autoprobing is not allowed in loadable modules - the system is |
143 | already up and running and you're messing with interrupts. |
144 | |
145 | To unload a module, turn off the associated interface |
146 | 'ifconfig eth?? down' then 'rmmod depca'. |
147 | |
148 | To assign a base memory address for the shared memory when running as a |
149 | loadable module, see 5 above. To include the adapter name (if you have |
150 | no PROM but know the card name) also see 5 above. Note that this last |
151 | option will not work with kernel built-in depca's. |
152 | |
153 | The shared memory assignment for a loadable module makes sense to avoid |
154 | the 'memory autoprobe' picking the wrong shared memory (for the case of |
155 | 2 depca's in a PC). |
156 | |
157 | |
158 | TO DO: |
159 | ------ |
160 | |
161 | |
162 | Revision History |
163 | ---------------- |
164 | |
165 | Version Date Description |
166 | |
167 | 0.1 25-jan-94 Initial writing. |
168 | 0.2 27-jan-94 Added LANCE TX hardware buffer chaining. |
169 | 0.3 1-feb-94 Added multiple DEPCA support. |
170 | 0.31 4-feb-94 Added DE202 recognition. |
171 | 0.32 19-feb-94 Tidy up. Improve multi-DEPCA support. |
172 | 0.33 25-feb-94 Fix DEPCA ethernet ROM counter enable. |
173 | Add jabber packet fix from murf@perftech.com |
174 | and becker@super.org |
175 | 0.34 7-mar-94 Fix DEPCA max network memory RAM & NICSR access. |
176 | 0.35 8-mar-94 Added DE201 recognition. Tidied up. |
177 | 0.351 30-apr-94 Added EISA support. Added DE422 recognition. |
178 | 0.36 16-may-94 DE422 fix released. |
179 | 0.37 22-jul-94 Added MODULE support |
180 | 0.38 15-aug-94 Added DBR ROM switch in depca_close(). |
181 | Multi DEPCA bug fix. |
182 | 0.38axp 15-sep-94 Special version for Alpha AXP Linux V1.0. |
183 | 0.381 12-dec-94 Added DE101 recognition, fix multicast bug. |
184 | 0.382 9-feb-95 Fix recognition bug reported by <bkm@star.rl.ac.uk>. |
185 | 0.383 22-feb-95 Fix for conflict with VESA SCSI reported by |
186 | <stromain@alf.dec.com> |
187 | 0.384 17-mar-95 Fix a ring full bug reported by <bkm@star.rl.ac.uk> |
188 | 0.385 3-apr-95 Fix a recognition bug reported by |
189 | <ryan.niemi@lastfrontier.com> |
190 | 0.386 21-apr-95 Fix the last fix...sorry, must be galloping senility |
191 | 0.40 25-May-95 Rewrite for portability & updated. |
192 | ALPHA support from <jestabro@amt.tay1.dec.com> |
193 | 0.41 26-Jun-95 Added verify_area() calls in depca_ioctl() from |
194 | suggestion by <heiko@colossus.escape.de> |
195 | 0.42 27-Dec-95 Add 'mem' shared memory assignment for loadable |
196 | modules. |
197 | Add 'adapter_name' for loadable modules when no PROM. |
198 | Both above from a suggestion by |
199 | <pchen@woodruffs121.residence.gatech.edu>. |
200 | Add new multicasting code. |
201 | 0.421 22-Apr-96 Fix alloc_device() bug <jari@markkus2.fimr.fi> |
202 | 0.422 29-Apr-96 Fix depca_hw_init() bug <jari@markkus2.fimr.fi> |
203 | 0.423 7-Jun-96 Fix module load bug <kmg@barco.be> |
204 | 0.43 16-Aug-96 Update alloc_device() to conform to de4x5.c |
205 | |
206 | ========================================================================= |
207 | */ |
208 | |
209 | static const char *version = "depca.c:v0.43 96/8/16 davies@maniac.ultranet.com\n"; |
210 | |
211 | #include <linux/module.h> |
212 | |
213 | #include <linux/kernel.h> |
214 | #include <linux/sched.h> |
215 | #include <linux/string.h> |
216 | #include <linux/ptrace.h> |
217 | #include <linux/errno.h> |
218 | #include <linux/ioport.h> |
219 | #include <linux/malloc.h> |
220 | #include <linux/interrupt.h> |
221 | #include <linux/delay.h> |
222 | #include <asm/segment.h> |
223 | #include <asm/bitops.h> |
224 | #include <asm/io.h> |
225 | #include <asm/dma.h> |
226 | |
227 | #include <linux/netdevice.h> |
228 | #include <linux/etherdevice.h> |
229 | #include <linux/skbuff.h> |
230 | |
231 | #include <linux/time.h> |
232 | #include <linux/types.h> |
233 | #include <linux/unistd.h> |
234 | #include <linux/ctype.h> |
235 | |
236 | #include "depca.h" |
237 | |
238 | #ifdef DEPCA_DEBUG |
239 | static int depca_debug = DEPCA_DEBUG; |
240 | #else |
241 | static int depca_debug = 1; |
242 | #endif |
243 | |
244 | #define DEPCA_NDA0xffe0 0xffe0 /* No Device Address */ |
245 | |
246 | /* |
247 | ** Ethernet PROM defines |
248 | */ |
249 | #define PROBE_LENGTH32 32 |
250 | #define ETH_PROM_SIG0xAA5500FFUL 0xAA5500FFUL |
251 | |
252 | /* |
253 | ** Set the number of Tx and Rx buffers. Ensure that the memory requested |
254 | ** here is <= to the amount of shared memory set up by the board switches. |
255 | ** The number of descriptors MUST BE A POWER OF 2. |
256 | ** |
257 | ** total_memory = NUM_RX_DESC*(8+RX_BUFF_SZ) + NUM_TX_DESC*(8+TX_BUFF_SZ) |
258 | */ |
259 | #define NUM_RX_DESC8 8 /* Number of RX descriptors */ |
260 | #define NUM_TX_DESC8 8 /* Number of TX descriptors */ |
261 | #define RX_BUFF_SZ1536 1536 /* Buffer size for each Rx buffer */ |
262 | #define TX_BUFF_SZ1536 1536 /* Buffer size for each Tx buffer */ |
263 | |
264 | #define CRC_POLYNOMIAL_BE0x04c11db7UL 0x04c11db7UL /* Ethernet CRC, big endian */ |
265 | #define CRC_POLYNOMIAL_LE0xedb88320UL 0xedb88320UL /* Ethernet CRC, little endian */ |
266 | |
267 | /* |
268 | ** EISA bus defines |
269 | */ |
270 | #define DEPCA_EISA_IO_PORTS0x0c00 0x0c00 /* I/O port base address, slot 0 */ |
271 | #define MAX_EISA_SLOTS16 16 |
272 | #define EISA_SLOT_INC0x1000 0x1000 |
273 | |
274 | /* |
275 | ** ISA Bus defines |
276 | */ |
277 | #define DEPCA_RAM_BASE_ADDRESSES{0xc0000,0xd0000,0xe0000,0x00000} {0xc0000,0xd0000,0xe0000,0x00000} |
278 | #define DEPCA_IO_PORTS{0x300, 0x200, 0} {0x300, 0x200, 0} |
279 | #define DEPCA_TOTAL_SIZE0x10 0x10 |
280 | static short mem_chkd = 0; |
281 | |
282 | /* |
283 | ** Name <-> Adapter mapping |
284 | */ |
285 | #define DEPCA_SIGNATURE{"DEPCA", "DE100","DE101", "DE200","DE201","DE202", "DE210", "DE422" , ""} {"DEPCA",\ |
286 | "DE100","DE101",\ |
287 | "DE200","DE201","DE202",\ |
288 | "DE210",\ |
289 | "DE422",\ |
290 | ""} |
291 | static enum {DEPCA, de100, de101, de200, de201, de202, de210, de422, unknown} adapter; |
292 | |
293 | /* |
294 | ** Miscellaneous info... |
295 | */ |
296 | #define DEPCA_STRLEN16 16 |
297 | #define MAX_NUM_DEPCAS2 2 |
298 | |
299 | /* |
300 | ** Memory Alignment. Each descriptor is 4 longwords long. To force a |
301 | ** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and |
302 | ** DESC_ALIGN. ALIGN aligns the start address of the private memory area |
303 | ** and hence the RX descriptor ring's first entry. |
304 | */ |
305 | #define ALIGN4((u_long)4 - 1) ((u_long)4 - 1) /* 1 longword align */ |
306 | #define ALIGN8((u_long)8 - 1) ((u_long)8 - 1) /* 2 longword (quadword) align */ |
307 | #define ALIGN((u_long)8 - 1) ALIGN8((u_long)8 - 1) /* Keep the LANCE happy... */ |
308 | |
309 | /* |
310 | ** The DEPCA Rx and Tx ring descriptors. |
311 | */ |
312 | struct depca_rx_desc { |
313 | volatile s32 base; |
314 | s16 buf_length; /* This length is negative 2's complement! */ |
315 | s16 msg_length; /* This length is "normal". */ |
316 | }; |
317 | |
318 | struct depca_tx_desc { |
319 | volatile s32 base; |
320 | s16 length; /* This length is negative 2's complement! */ |
321 | s16 misc; /* Errors and TDR info */ |
322 | }; |
323 | |
324 | #define LA_MASK0x0000ffff 0x0000ffff /* LANCE address mask for mapping network RAM |
325 | to LANCE memory address space */ |
326 | |
327 | /* |
328 | ** The Lance initialization block, described in databook, in common memory. |
329 | */ |
330 | struct depca_init { |
331 | u16 mode; /* Mode register */ |
332 | u8 phys_addr[ETH_ALEN6]; /* Physical ethernet address */ |
333 | u8 mcast_table[8]; /* Multicast Hash Table. */ |
334 | u32 rx_ring; /* Rx ring base pointer & ring length */ |
335 | u32 tx_ring; /* Tx ring base pointer & ring length */ |
336 | }; |
337 | |
338 | #define DEPCA_PKT_STAT_SZ16 16 |
339 | #define DEPCA_PKT_BIN_SZ128 128 /* Should be >=100 unless you |
340 | increase DEPCA_PKT_STAT_SZ */ |
341 | struct depca_private { |
342 | char devname[DEPCA_STRLEN16]; /* Device Product String */ |
343 | char adapter_name[DEPCA_STRLEN16];/* /proc/ioports string */ |
344 | char adapter; /* Adapter type */ |
345 | struct depca_rx_desc *rx_ring; /* Pointer to start of RX descriptor ring */ |
346 | struct depca_tx_desc *tx_ring; /* Pointer to start of TX descriptor ring */ |
347 | struct depca_init init_block;/* Shadow Initialization block */ |
348 | char *rx_memcpy[NUM_RX_DESC8]; /* CPU virt address of sh'd memory buffs */ |
349 | char *tx_memcpy[NUM_TX_DESC8]; /* CPU virt address of sh'd memory buffs */ |
350 | u_long bus_offset; /* (E)ISA bus address offset vs LANCE */ |
351 | u_long sh_mem; /* Physical start addr of shared mem area */ |
352 | u_long dma_buffs; /* LANCE Rx and Tx buffers start address. */ |
353 | int rx_new, tx_new; /* The next free ring entry */ |
354 | int rx_old, tx_old; /* The ring entries to be free()ed. */ |
355 | struct enet_statistics stats; |
356 | struct { /* Private stats counters */ |
357 | u32 bins[DEPCA_PKT_STAT_SZ16]; |
358 | u32 unicast; |
359 | u32 multicast; |
360 | u32 broadcast; |
361 | u32 excessive_collisions; |
362 | u32 tx_underruns; |
363 | u32 excessive_underruns; |
364 | } pktStats; |
365 | int txRingMask; /* TX ring mask */ |
366 | int rxRingMask; /* RX ring mask */ |
367 | s32 rx_rlen; /* log2(rxRingMask+1) for the descriptors */ |
368 | s32 tx_rlen; /* log2(txRingMask+1) for the descriptors */ |
369 | }; |
370 | |
371 | /* |
372 | ** The transmit ring full condition is described by the tx_old and tx_new |
373 | ** pointers by: |
374 | ** tx_old = tx_new Empty ring |
375 | ** tx_old = tx_new+1 Full ring |
376 | ** tx_old+txRingMask = tx_new Full ring (wrapped condition) |
377 | */ |
378 | #define TX_BUFFS_AVAIL((lp->tx_old<=lp->tx_new)? lp->tx_old+lp->txRingMask -lp->tx_new: lp->tx_old -lp->tx_new-1) ((lp->tx_old<=lp->tx_new)?\ |
379 | lp->tx_old+lp->txRingMask-lp->tx_new:\ |
380 | lp->tx_old -lp->tx_new-1) |
381 | |
382 | /* |
383 | ** Public Functions |
384 | */ |
385 | static int depca_open(struct devicelinux_device *dev); |
386 | static int depca_start_xmit(struct sk_buff *skb, struct devicelinux_device *dev); |
387 | static void depca_interrupt(int irq, void *dev_id, struct pt_regs * regs); |
388 | static int depca_close(struct devicelinux_device *dev); |
389 | static int depca_ioctl(struct devicelinux_device *dev, struct ifreq *rq, int cmd); |
390 | static struct enet_statistics *depca_get_stats(struct devicelinux_device *dev); |
391 | static void set_multicast_list(struct devicelinux_device *dev); |
392 | |
393 | /* |
394 | ** Private functions |
395 | */ |
396 | static int depca_hw_init(struct devicelinux_device *dev, u_long ioaddr); |
397 | static void depca_init_ring(struct devicelinux_device *dev); |
398 | static int depca_rx(struct devicelinux_device *dev); |
399 | static int depca_tx(struct devicelinux_device *dev); |
400 | |
401 | static void LoadCSRs(struct devicelinux_device *dev); |
402 | static int InitRestartDepca(struct devicelinux_device *dev); |
403 | static void DepcaSignature(char *name, u_long paddr); |
404 | static int DevicePresent(u_long ioaddr); |
405 | static int get_hw_addr(struct devicelinux_device *dev); |
406 | static int EISA_signature(char *name, s32 eisa_id); |
407 | static void SetMulticastFilter(struct devicelinux_device *dev); |
408 | static void isa_probe(struct devicelinux_device *dev, u_long iobase); |
409 | static void eisa_probe(struct devicelinux_device *dev, u_long iobase); |
410 | static struct devicelinux_device *alloc_device(struct devicelinux_device *dev, u_long iobase); |
411 | static int depca_dev_index(char *s); |
412 | static struct devicelinux_device *insert_device(struct devicelinux_device *dev, u_long iobase, int (*init)(struct devicelinux_device *)); |
413 | static int load_packet(struct devicelinux_device *dev, struct sk_buff *skb); |
414 | static void depca_dbg_open(struct devicelinux_device *dev); |
415 | |
416 | #ifdef MODULE |
417 | int init_module(void); |
418 | void cleanup_module(void); |
419 | static int autoprobed = 1, loading_module = 1; |
420 | # else |
421 | static u_char de1xx_irq[] = {2,3,4,5,7,9,0}; |
422 | static u_char de2xx_irq[] = {5,9,10,11,15,0}; |
423 | static u_char de422_irq[] = {5,9,10,11,0}; |
424 | static u_char *depca_irq; |
425 | static int autoprobed = 0, loading_module = 0; |
426 | #endif /* MODULE */ |
427 | |
428 | static char name[DEPCA_STRLEN16]; |
429 | static int num_depcas = 0, num_eth = 0; |
430 | static int mem=0; /* For loadable module assignment |
431 | use insmod mem=0x????? .... */ |
432 | static char *adapter_name = '\0'; /* If no PROM when loadable module |
433 | use insmod adapter_name=DE??? ... |
434 | */ |
435 | /* |
436 | ** Miscellaneous defines... |
437 | */ |
438 | #define STOP_DEPCA((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); ((__builtin_constant_p((ioaddr+0x04)) && (ioaddr +0x04) < 256) ? __outwc((0x0004),(ioaddr+0x04)) : __outw(( 0x0004),(ioaddr+0x04))) \ |
439 | outw(CSR0, DEPCA_ADDR)((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06)));\ |
440 | outw(STOP, DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __outwc((0x0004),(ioaddr+0x04)) : __outw((0x0004 ),(ioaddr+0x04))) |
441 | |
442 | |
443 | |
444 | int depca_probe(struct devicelinux_device *dev) |
445 | { |
446 | int tmp = num_depcas, status = -ENODEV19; |
447 | u_long iobase = dev->base_addr; |
448 | |
449 | if ((iobase == 0) && loading_module){ |
450 | printk("Autoprobing is not supported when loading a module based driver.\n"); |
451 | status = -EIO5; |
452 | } else { |
453 | isa_probe(dev, iobase); |
454 | eisa_probe(dev, iobase); |
455 | |
456 | if ((tmp == num_depcas) && (iobase != 0) && loading_module) { |
457 | printk("%s: depca_probe() cannot find device at 0x%04lx.\n", dev->name, |
458 | iobase); |
459 | } |
460 | |
461 | /* |
462 | ** Walk the device list to check that at least one device |
463 | ** initialised OK |
464 | */ |
465 | for (; (dev->priv == NULL((void *) 0)) && (dev->next != NULL((void *) 0)); dev = dev->next); |
466 | |
467 | if (dev->priv) status = 0; |
468 | if (iobase == 0) autoprobed = 1; |
469 | } |
470 | |
471 | return status; |
472 | } |
473 | |
474 | static int |
475 | depca_hw_init(struct devicelinux_device *dev, u_long ioaddr) |
476 | { |
477 | struct depca_private *lp; |
478 | int i, j, offset, netRAM, mem_len, status=0; |
479 | s16 nicsr; |
480 | u_long mem_start=0, mem_base[] = DEPCA_RAM_BASE_ADDRESSES{0xc0000,0xd0000,0xe0000,0x00000}; |
481 | |
482 | STOP_DEPCA((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); ((__builtin_constant_p((ioaddr+0x04)) && (ioaddr +0x04) < 256) ? __outwc((0x0004),(ioaddr+0x04)) : __outw(( 0x0004),(ioaddr+0x04))); |
483 | |
484 | nicsr = inb(DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __inbc(ioaddr+0x00) : __inb(ioaddr+0x00)); |
485 | nicsr = ((nicsr & ~SHE0x0080 & ~RBE0x0010 & ~IEN0x0002) | IM0x0004); |
486 | outb(nicsr, DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __outbc((nicsr),(ioaddr+0x00)) : __outb((nicsr) ,(ioaddr+0x00))); |
487 | |
488 | if (inw(DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __inwc(ioaddr+0x04) : __inw(ioaddr+0x04)) == STOP0x0004) { |
489 | do { |
490 | strcpy(name, (adapter_name ? adapter_name : "")); |
491 | mem_start = (mem ? mem & 0xf0000 : mem_base[mem_chkd++]); |
492 | DepcaSignature(name, mem_start); |
493 | } while (!mem && mem_base[mem_chkd] && (adapter == unknown)); |
494 | |
495 | if ((adapter != unknown) && mem_start) { /* found a DEPCA device */ |
496 | dev->base_addr = ioaddr; |
497 | |
498 | if ((ioaddr&0x0fff)==DEPCA_EISA_IO_PORTS0x0c00) {/* EISA slot address */ |
499 | printk("%s: %s at 0x%04lx (EISA slot %d)", |
500 | dev->name, name, ioaddr, (int)((ioaddr>>12)&0x0f)); |
501 | } else { /* ISA port address */ |
502 | printk("%s: %s at 0x%04lx", dev->name, name, ioaddr); |
503 | } |
504 | |
505 | printk(", h/w address "); |
506 | status = get_hw_addr(dev); |
507 | for (i=0; i<ETH_ALEN6 - 1; i++) { /* get the ethernet address */ |
508 | printk("%2.2x:", dev->dev_addr[i]); |
509 | } |
510 | printk("%2.2x", dev->dev_addr[i]); |
511 | |
512 | if (status == 0) { |
513 | /* Set up the maximum amount of network RAM(kB) */ |
514 | netRAM = ((adapter != DEPCA) ? 64 : 48); |
515 | if ((nicsr & _128KB0x0008) && (adapter == de422)) netRAM = 128; |
516 | offset = 0x0000; |
517 | |
518 | /* Shared Memory Base Address */ |
519 | if (nicsr & BUF0x0020) { |
520 | offset = 0x8000; /* 32kbyte RAM offset*/ |
521 | nicsr &= ~BS0x0040; /* DEPCA RAM in top 32k */ |
522 | netRAM -= 32; |
523 | } |
524 | mem_start += offset; /* (E)ISA start address */ |
525 | if ((mem_len = (NUM_RX_DESC8*(sizeof(struct depca_rx_desc)+RX_BUFF_SZ1536) + |
526 | NUM_TX_DESC8*(sizeof(struct depca_tx_desc)+TX_BUFF_SZ1536) + |
527 | sizeof(struct depca_init))) <= |
528 | (netRAM<<10)) { |
529 | printk(",\n has %dkB RAM at 0x%.5lx", netRAM, mem_start); |
530 | |
531 | /* Enable the shadow RAM. */ |
532 | if (adapter != DEPCA) { |
533 | nicsr |= SHE0x0080; |
534 | outb(nicsr, DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __outbc((nicsr),(ioaddr+0x00)) : __outb((nicsr) ,(ioaddr+0x00))); |
535 | } |
536 | |
537 | /* Define the device private memory */ |
538 | dev->priv = (void *) kmalloclinux_kmalloc(sizeof(struct depca_private), GFP_KERNEL0x03); |
539 | if (dev->priv == NULL((void *) 0)) |
540 | return -ENOMEM12; |
541 | lp = (struct depca_private *)dev->priv; |
542 | memset((char *)dev->priv, 0, sizeof(struct depca_private))(__builtin_constant_p(0) ? (__builtin_constant_p((sizeof(struct depca_private))) ? __constant_c_and_count_memset((((char *)dev ->priv)),((0x01010101UL*(unsigned char)(0))),((sizeof(struct depca_private)))) : __constant_c_memset((((char *)dev->priv )),((0x01010101UL*(unsigned char)(0))),((sizeof(struct depca_private ))))) : (__builtin_constant_p((sizeof(struct depca_private))) ? __memset_generic(((((char *)dev->priv))),(((0))),(((sizeof (struct depca_private))))) : __memset_generic((((char *)dev-> priv)),((0)),((sizeof(struct depca_private)))))); |
543 | lp->adapter = adapter; |
544 | sprintflinux_sprintf(lp->adapter_name,"%s (%s)", name, dev->name); |
545 | request_region(ioaddr, DEPCA_TOTAL_SIZE0x10, lp->adapter_name); |
546 | |
547 | /* Initialisation Block */ |
548 | lp->sh_mem = mem_start; |
549 | mem_start += sizeof(struct depca_init); |
550 | |
551 | /* Tx & Rx descriptors (aligned to a quadword boundary) */ |
552 | mem_start = (mem_start + ALIGN((u_long)8 - 1)) & ~ALIGN((u_long)8 - 1); |
553 | lp->rx_ring = (struct depca_rx_desc *)mem_start; |
554 | |
555 | mem_start += (sizeof(struct depca_rx_desc) * NUM_RX_DESC8); |
556 | lp->tx_ring = (struct depca_tx_desc *)mem_start; |
557 | |
558 | mem_start += (sizeof(struct depca_tx_desc) * NUM_TX_DESC8); |
559 | lp->bus_offset = mem_start & 0x00ff0000; |
560 | mem_start &= LA_MASK0x0000ffff; /* LANCE re-mapped start address */ |
561 | |
562 | lp->dma_buffs = mem_start; |
563 | |
564 | /* Finish initialising the ring information. */ |
565 | lp->rxRingMask = NUM_RX_DESC8 - 1; |
566 | lp->txRingMask = NUM_TX_DESC8 - 1; |
567 | |
568 | /* Calculate Tx/Rx RLEN size for the descriptors. */ |
569 | for (i=0, j = lp->rxRingMask; j>0; i++) { |
570 | j >>= 1; |
571 | } |
572 | lp->rx_rlen = (s32)(i << 29); |
573 | for (i=0, j = lp->txRingMask; j>0; i++) { |
574 | j >>= 1; |
575 | } |
576 | lp->tx_rlen = (s32)(i << 29); |
577 | |
578 | /* Load the initialisation block */ |
579 | depca_init_ring(dev); |
580 | |
581 | /* Initialise the control and status registers */ |
582 | LoadCSRs(dev); |
583 | |
584 | /* Enable DEPCA board interrupts for autoprobing */ |
585 | nicsr = ((nicsr & ~IM0x0004)|IEN0x0002); |
586 | outb(nicsr, DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __outbc((nicsr),(ioaddr+0x00)) : __outb((nicsr) ,(ioaddr+0x00))); |
587 | |
588 | /* To auto-IRQ we enable the initialization-done and DMA err, |
589 | interrupts. For now we will always get a DMA error. */ |
590 | if (dev->irq < 2) { |
591 | #ifndef MODULE |
592 | unsigned char irqnum; |
593 | autoirq_setup(0); |
594 | |
595 | /* Assign the correct irq list */ |
596 | switch (lp->adapter) { |
597 | case DEPCA: |
598 | case de100: |
599 | case de101: |
600 | depca_irq = de1xx_irq; |
601 | break; |
602 | case de200: |
603 | case de201: |
604 | case de202: |
605 | case de210: |
606 | depca_irq = de2xx_irq; |
607 | break; |
608 | case de422: |
609 | depca_irq = de422_irq; |
610 | break; |
611 | } |
612 | |
613 | /* Trigger an initialization just for the interrupt. */ |
614 | outw(INEA | INIT, DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __outwc((0x0040 | 0x0001),(ioaddr+0x04)) : __outw ((0x0040 | 0x0001),(ioaddr+0x04))); |
615 | |
616 | irqnum = autoirq_report(1); |
617 | if (!irqnum) { |
618 | printk(" and failed to detect IRQ line.\n"); |
619 | status = -ENXIO6; |
620 | } else { |
621 | for (dev->irq=0,i=0; (depca_irq[i]) && (!dev->irq); i++) { |
622 | if (irqnum == depca_irq[i]) { |
623 | dev->irq = irqnum; |
624 | printk(" and uses IRQ%d.\n", dev->irq); |
625 | } |
626 | } |
627 | |
628 | if (!dev->irq) { |
629 | printk(" but incorrect IRQ line detected.\n"); |
630 | status = -ENXIO6; |
631 | } |
632 | } |
633 | #endif /* MODULE */ |
634 | } else { |
635 | printk(" and assigned IRQ%d.\n", dev->irq); |
636 | } |
637 | if (status) release_region(ioaddr, DEPCA_TOTAL_SIZE0x10); |
638 | } else { |
639 | printk(",\n requests %dkB RAM: only %dkB is available!\n", |
640 | (mem_len>>10), netRAM); |
641 | status = -ENXIO6; |
642 | } |
643 | } else { |
644 | printk(" which has an Ethernet PROM CRC error.\n"); |
645 | status = -ENXIO6; |
646 | } |
647 | } else { |
648 | status = -ENXIO6; |
649 | } |
650 | if (!status) { |
651 | if (depca_debug > 1) { |
652 | printk(version); |
653 | } |
654 | |
655 | /* The DEPCA-specific entries in the device structure. */ |
656 | dev->open = &depca_open; |
657 | dev->hard_start_xmit = &depca_start_xmit; |
658 | dev->stop = &depca_close; |
659 | dev->get_stats = &depca_get_stats; |
660 | dev->set_multicast_list = &set_multicast_list; |
661 | dev->do_ioctl = &depca_ioctl; |
662 | |
663 | dev->mem_start = 0; |
664 | |
665 | /* Fill in the generic field of the device structure. */ |
666 | ether_setup(dev); |
667 | } else { /* Incorrectly initialised hardware */ |
668 | if (dev->priv) { |
669 | kfree_s(dev->priv, sizeof(struct depca_private))linux_kfree(dev->priv); |
670 | dev->priv = NULL((void *) 0); |
671 | } |
672 | } |
673 | } else { |
674 | status = -ENXIO6; |
675 | } |
676 | |
677 | return status; |
678 | } |
679 | |
680 | |
681 | static int |
682 | depca_open(struct devicelinux_device *dev) |
683 | { |
684 | struct depca_private *lp = (struct depca_private *)dev->priv; |
685 | u_long ioaddr = dev->base_addr; |
686 | s16 nicsr; |
687 | int status = 0; |
688 | |
689 | irq2dev_map[dev->irq] = dev; |
690 | STOP_DEPCA((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); ((__builtin_constant_p((ioaddr+0x04)) && (ioaddr +0x04) < 256) ? __outwc((0x0004),(ioaddr+0x04)) : __outw(( 0x0004),(ioaddr+0x04))); |
691 | nicsr = inb(DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __inbc(ioaddr+0x00) : __inb(ioaddr+0x00)); |
692 | |
693 | /* Make sure the shadow RAM is enabled */ |
694 | if (adapter != DEPCA) { |
695 | nicsr |= SHE0x0080; |
696 | outb(nicsr, DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __outbc((nicsr),(ioaddr+0x00)) : __outb((nicsr) ,(ioaddr+0x00))); |
697 | } |
698 | |
699 | /* Re-initialize the DEPCA... */ |
700 | depca_init_ring(dev); |
701 | LoadCSRs(dev); |
702 | |
703 | depca_dbg_open(dev); |
704 | |
705 | if (request_irq(dev->irq, &depca_interrupt, 0, lp->adapter_name, NULL((void *) 0))) { |
706 | printk("depca_open(): Requested IRQ%d is busy\n",dev->irq); |
707 | status = -EAGAIN11; |
708 | } else { |
709 | |
710 | /* Enable DEPCA board interrupts and turn off LED */ |
711 | nicsr = ((nicsr & ~IM0x0004 & ~LED0x0001)|IEN0x0002); |
712 | outb(nicsr, DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __outbc((nicsr),(ioaddr+0x00)) : __outb((nicsr) ,(ioaddr+0x00))); |
713 | outw(CSR0,DEPCA_ADDR)((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); |
714 | |
715 | dev->tbusy = 0; |
716 | dev->interrupt = 0; |
717 | dev->start = 1; |
718 | |
719 | status = InitRestartDepca(dev); |
720 | |
721 | if (depca_debug > 1){ |
722 | printk("CSR0: 0x%4.4x\n",inw(DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __inwc(ioaddr+0x04) : __inw(ioaddr+0x04))); |
723 | printk("nicsr: 0x%02x\n",inb(DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __inbc(ioaddr+0x00) : __inb(ioaddr+0x00))); |
724 | } |
725 | } |
726 | |
727 | MOD_INC_USE_COUNTdo { } while (0); |
728 | |
729 | return status; |
730 | } |
731 | |
732 | /* Initialize the lance Rx and Tx descriptor rings. */ |
733 | static void |
734 | depca_init_ring(struct devicelinux_device *dev) |
735 | { |
736 | struct depca_private *lp = (struct depca_private *)dev->priv; |
737 | u_int i; |
738 | u_long p; |
739 | |
740 | /* Lock out other processes whilst setting up the hardware */ |
741 | set_bit(0, (void *)&dev->tbusy); |
742 | |
743 | lp->rx_new = lp->tx_new = 0; |
744 | lp->rx_old = lp->tx_old = 0; |
745 | |
746 | /* Initialize the base addresses and length of each buffer in the ring */ |
747 | for (i = 0; i <= lp->rxRingMask; i++) { |
748 | writel((p=lp->dma_buffs+i*RX_BUFF_SZ) | R_OWN, &lp->rx_ring[i].base)((*(volatile unsigned int *) (&lp->rx_ring[i].base)) = ((p=lp->dma_buffs+i*1536) | 0x80000000)); |
749 | writew(-RX_BUFF_SZ, &lp->rx_ring[i].buf_length)((*(volatile unsigned short *) (&lp->rx_ring[i].buf_length )) = (-1536)); |
750 | lp->rx_memcpy[i]=(char *)(p+lp->bus_offset); |
751 | } |
752 | for (i = 0; i <= lp->txRingMask; i++) { |
753 | writel((p=lp->dma_buffs+(i+lp->txRingMask+1)*TX_BUFF_SZ) & 0x00ffffff,((*(volatile unsigned int *) (&lp->tx_ring[i].base)) = ((p=lp->dma_buffs+(i+lp->txRingMask+1)*1536) & 0x00ffffff )) |
754 | &lp->tx_ring[i].base)((*(volatile unsigned int *) (&lp->tx_ring[i].base)) = ((p=lp->dma_buffs+(i+lp->txRingMask+1)*1536) & 0x00ffffff )); |
755 | lp->tx_memcpy[i]=(char *)(p+lp->bus_offset); |
756 | } |
757 | |
758 | /* Set up the initialization block */ |
759 | lp->init_block.rx_ring = ((u32)((u_long)lp->rx_ring)&LA_MASK0x0000ffff) | lp->rx_rlen; |
760 | lp->init_block.tx_ring = ((u32)((u_long)lp->tx_ring)&LA_MASK0x0000ffff) | lp->tx_rlen; |
761 | |
762 | SetMulticastFilter(dev); |
763 | |
764 | for (i = 0; i < ETH_ALEN6; i++) { |
765 | lp->init_block.phys_addr[i] = dev->dev_addr[i]; |
766 | } |
767 | |
768 | lp->init_block.mode = 0x0000; /* Enable the Tx and Rx */ |
769 | |
770 | return; |
771 | } |
772 | |
773 | /* |
774 | ** Writes a socket buffer to TX descriptor ring and starts transmission |
775 | */ |
776 | static int |
777 | depca_start_xmit(struct sk_buff *skb, struct devicelinux_device *dev) |
778 | { |
779 | struct depca_private *lp = (struct depca_private *)dev->priv; |
780 | u_long ioaddr = dev->base_addr; |
781 | int status = 0; |
782 | |
783 | /* Transmitter timeout, serious problems. */ |
784 | if (dev->tbusy) { |
785 | int tickssofar = jiffies - dev->trans_start; |
786 | if (tickssofar < 1*HZ100) { |
787 | status = -1; |
788 | } else { |
789 | printk("%s: transmit timed out, status %04x, resetting.\n", |
790 | dev->name, inw(DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __inwc(ioaddr+0x04) : __inw(ioaddr+0x04))); |
791 | |
792 | STOP_DEPCA((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); ((__builtin_constant_p((ioaddr+0x04)) && (ioaddr +0x04) < 256) ? __outwc((0x0004),(ioaddr+0x04)) : __outw(( 0x0004),(ioaddr+0x04))); |
793 | depca_init_ring(dev); |
794 | LoadCSRs(dev); |
795 | dev->interrupt = UNMASK_INTERRUPTS0; |
796 | dev->start = 1; |
797 | dev->tbusy=0; |
798 | dev->trans_start = jiffies; |
799 | InitRestartDepca(dev); |
800 | dev_kfree_skb(skb, FREE_WRITE0); |
801 | } |
802 | return status; |
803 | } else if (skb == NULL((void *) 0)) { |
804 | dev_tint(dev); |
805 | } else if (skb->len > 0) { |
806 | /* Enforce 1 process per h/w access */ |
807 | if (set_bit(0, (void*)&dev->tbusy) != 0) { |
808 | printk("%s: Transmitter access conflict.\n", dev->name); |
809 | status = -1; |
810 | } else { |
811 | if (TX_BUFFS_AVAIL((lp->tx_old<=lp->tx_new)? lp->tx_old+lp->txRingMask -lp->tx_new: lp->tx_old -lp->tx_new-1)) { /* Fill in a Tx ring entry */ |
812 | status = load_packet(dev, skb); |
813 | |
814 | if (!status) { |
815 | /* Trigger an immediate send demand. */ |
816 | outw(CSR0, DEPCA_ADDR)((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); |
817 | outw(INEA | TDMD, DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __outwc((0x0040 | 0x0008),(ioaddr+0x04)) : __outw ((0x0040 | 0x0008),(ioaddr+0x04))); |
818 | |
819 | dev->trans_start = jiffies; |
820 | dev_kfree_skb(skb, FREE_WRITE0); |
821 | } |
822 | if (TX_BUFFS_AVAIL((lp->tx_old<=lp->tx_new)? lp->tx_old+lp->txRingMask -lp->tx_new: lp->tx_old -lp->tx_new-1)) { |
823 | dev->tbusy=0; |
824 | } |
825 | } else { |
826 | status = -1; |
827 | } |
828 | } |
829 | } |
830 | |
831 | return status; |
832 | } |
833 | |
834 | /* |
835 | ** The DEPCA interrupt handler. |
836 | */ |
837 | static void |
838 | depca_interrupt(int irq, void *dev_id, struct pt_regs * regs) |
839 | { |
840 | struct devicelinux_device *dev = (struct devicelinux_device *)(irq2dev_map[irq]); |
841 | struct depca_private *lp; |
842 | s16 csr0, nicsr; |
843 | u_long ioaddr; |
844 | |
845 | if (dev == NULL((void *) 0)) { |
846 | printk ("depca_interrupt(): irq %d for unknown device.\n", irq); |
847 | } else { |
848 | lp = (struct depca_private *)dev->priv; |
849 | ioaddr = dev->base_addr; |
850 | |
851 | if (dev->interrupt) |
852 | printk("%s: Re-entering the interrupt handler.\n", dev->name); |
853 | |
854 | dev->interrupt = MASK_INTERRUPTS1; |
855 | |
856 | /* mask the DEPCA board interrupts and turn on the LED */ |
857 | nicsr = inb(DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __inbc(ioaddr+0x00) : __inb(ioaddr+0x00)); |
858 | nicsr |= (IM0x0004|LED0x0001); |
859 | outb(nicsr, DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __outbc((nicsr),(ioaddr+0x00)) : __outb((nicsr) ,(ioaddr+0x00))); |
860 | |
861 | outw(CSR0, DEPCA_ADDR)((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); |
862 | csr0 = inw(DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __inwc(ioaddr+0x04) : __inw(ioaddr+0x04)); |
863 | |
864 | /* Acknowledge all of the current interrupt sources ASAP. */ |
865 | outw(csr0 & INTE, DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __outwc((csr0 & 0xfff0),(ioaddr+0x04)) : __outw ((csr0 & 0xfff0),(ioaddr+0x04))); |
866 | |
867 | if (csr0 & RINT0x0400) /* Rx interrupt (packet arrived) */ |
868 | depca_rx(dev); |
869 | |
870 | if (csr0 & TINT0x0200) /* Tx interrupt (packet sent) */ |
871 | depca_tx(dev); |
872 | |
873 | if ((TX_BUFFS_AVAIL((lp->tx_old<=lp->tx_new)? lp->tx_old+lp->txRingMask -lp->tx_new: lp->tx_old -lp->tx_new-1) >= 0) && dev->tbusy) { /* any resources available? */ |
874 | dev->tbusy = 0; /* clear TX busy flag */ |
875 | mark_bh(NET_BH); |
876 | } |
877 | |
878 | /* Unmask the DEPCA board interrupts and turn off the LED */ |
879 | nicsr = (nicsr & ~IM0x0004 & ~LED0x0001); |
880 | outb(nicsr, DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __outbc((nicsr),(ioaddr+0x00)) : __outb((nicsr) ,(ioaddr+0x00))); |
881 | |
882 | dev->interrupt = UNMASK_INTERRUPTS0; |
883 | } |
884 | |
885 | return; |
886 | } |
887 | |
888 | static int |
889 | depca_rx(struct devicelinux_device *dev) |
890 | { |
891 | struct depca_private *lp = (struct depca_private *)dev->priv; |
892 | int i, entry; |
893 | s32 status; |
894 | |
895 | for (entry=lp->rx_new; |
896 | !(readl(&lp->rx_ring[entry].base)(*(volatile unsigned int *) (&lp->rx_ring[entry].base) ) & R_OWN0x80000000); |
897 | entry=lp->rx_new){ |
898 | status = readl(&lp->rx_ring[entry].base)(*(volatile unsigned int *) (&lp->rx_ring[entry].base) ) >> 16 ; |
899 | if (status & R_STP0x0200) { /* Remember start of frame */ |
900 | lp->rx_old = entry; |
901 | } |
902 | if (status & R_ENP0x0100) { /* Valid frame status */ |
903 | if (status & R_ERR0x4000) { /* There was an error. */ |
904 | lp->stats.rx_errors++; /* Update the error stats. */ |
905 | if (status & R_FRAM0x2000) lp->stats.rx_frame_errors++; |
906 | if (status & R_OFLO0x1000) lp->stats.rx_over_errors++; |
907 | if (status & R_CRC0x0800) lp->stats.rx_crc_errors++; |
908 | if (status & R_BUFF0x0400) lp->stats.rx_fifo_errors++; |
909 | } else { |
910 | short len, pkt_len = readw(&lp->rx_ring[entry].msg_length)(*(volatile unsigned short *) (&lp->rx_ring[entry].msg_length )); |
911 | struct sk_buff *skb; |
912 | |
913 | skb = dev_alloc_skb(pkt_len+2); |
914 | if (skb != NULL((void *) 0)) { |
915 | unsigned char *buf; |
916 | skb_reserve(skb,2); /* 16 byte align the IP header */ |
917 | buf = skb_put(skb,pkt_len); |
918 | skb->dev = dev; |
919 | if (entry < lp->rx_old) { /* Wrapped buffer */ |
920 | len = (lp->rxRingMask - lp->rx_old + 1) * RX_BUFF_SZ1536; |
921 | memcpy_fromio(buf, lp->rx_memcpy[lp->rx_old], len)(__builtin_constant_p((len)) ? __constant_memcpy(((buf)),((void *)(lp->rx_memcpy[lp->rx_old])),((len))) : __memcpy(((buf )),((void *)(lp->rx_memcpy[lp->rx_old])),((len)))); |
922 | memcpy_fromio(buf + len, lp->rx_memcpy[0], pkt_len-len)(__builtin_constant_p((pkt_len-len)) ? __constant_memcpy(((buf + len)),((void *)(lp->rx_memcpy[0])),((pkt_len-len))) : __memcpy (((buf + len)),((void *)(lp->rx_memcpy[0])),((pkt_len-len) ))); |
923 | } else { /* Linear buffer */ |
924 | memcpy_fromio(buf, lp->rx_memcpy[lp->rx_old], pkt_len)(__builtin_constant_p((pkt_len)) ? __constant_memcpy(((buf)), ((void *)(lp->rx_memcpy[lp->rx_old])),((pkt_len))) : __memcpy (((buf)),((void *)(lp->rx_memcpy[lp->rx_old])),((pkt_len )))); |
925 | } |
926 | |
927 | /* |
928 | ** Notify the upper protocol layers that there is another |
929 | ** packet to handle |
930 | */ |
931 | skb->protocol=eth_type_trans(skb,dev)((unsigned short)0); |
932 | netif_rx(skb); |
933 | |
934 | /* |
935 | ** Update stats |
936 | */ |
937 | lp->stats.rx_packets++; |
938 | for (i=1; i<DEPCA_PKT_STAT_SZ16-1; i++) { |
939 | if (pkt_len < (i*DEPCA_PKT_BIN_SZ128)) { |
940 | lp->pktStats.bins[i]++; |
941 | i = DEPCA_PKT_STAT_SZ16; |
942 | } |
943 | } |
944 | if (buf[0] & 0x01) { /* Multicast/Broadcast */ |
945 | if ((*(s16 *)&buf[0] == -1) && |
946 | (*(s16 *)&buf[2] == -1) && |
947 | (*(s16 *)&buf[4] == -1)) { |
948 | lp->pktStats.broadcast++; |
949 | } else { |
950 | lp->pktStats.multicast++; |
951 | } |
952 | } else if ((*(s16 *)&buf[0] == *(s16 *)&dev->dev_addr[0]) && |
953 | (*(s16 *)&buf[2] == *(s16 *)&dev->dev_addr[2]) && |
954 | (*(s16 *)&buf[4] == *(s16 *)&dev->dev_addr[4])) { |
955 | lp->pktStats.unicast++; |
956 | } |
957 | |
958 | lp->pktStats.bins[0]++; /* Duplicates stats.rx_packets */ |
959 | if (lp->pktStats.bins[0] == 0) { /* Reset counters */ |
960 | memset((char *)&lp->pktStats, 0, sizeof(lp->pktStats))(__builtin_constant_p(0) ? (__builtin_constant_p((sizeof(lp-> pktStats))) ? __constant_c_and_count_memset((((char *)&lp ->pktStats)),((0x01010101UL*(unsigned char)(0))),((sizeof( lp->pktStats)))) : __constant_c_memset((((char *)&lp-> pktStats)),((0x01010101UL*(unsigned char)(0))),((sizeof(lp-> pktStats))))) : (__builtin_constant_p((sizeof(lp->pktStats ))) ? __memset_generic(((((char *)&lp->pktStats))),((( 0))),(((sizeof(lp->pktStats))))) : __memset_generic((((char *)&lp->pktStats)),((0)),((sizeof(lp->pktStats))))) ); |
961 | } |
962 | } else { |
963 | printk("%s: Memory squeeze, deferring packet.\n", dev->name); |
964 | lp->stats.rx_dropped++; /* Really, deferred. */ |
965 | break; |
966 | } |
967 | } |
968 | /* Change buffer ownership for this last frame, back to the adapter */ |
969 | for (; lp->rx_old!=entry; lp->rx_old=(lp->rx_old+1)&lp->rxRingMask) { |
970 | writel(readl(&lp->rx_ring[lp->rx_old].base) | R_OWN,((*(volatile unsigned int *) (&lp->rx_ring[lp->rx_old ].base)) = ((*(volatile unsigned int *) (&lp->rx_ring[ lp->rx_old].base)) | 0x80000000)) |
971 | &lp->rx_ring[lp->rx_old].base)((*(volatile unsigned int *) (&lp->rx_ring[lp->rx_old ].base)) = ((*(volatile unsigned int *) (&lp->rx_ring[ lp->rx_old].base)) | 0x80000000)); |
972 | } |
973 | writel(readl(&lp->rx_ring[entry].base) | R_OWN, &lp->rx_ring[entry].base)((*(volatile unsigned int *) (&lp->rx_ring[entry].base )) = ((*(volatile unsigned int *) (&lp->rx_ring[entry] .base)) | 0x80000000)); |
974 | } |
975 | |
976 | /* |
977 | ** Update entry information |
978 | */ |
979 | lp->rx_new = (lp->rx_new + 1) & lp->rxRingMask; |
980 | } |
981 | |
982 | return 0; |
983 | } |
984 | |
985 | /* |
986 | ** Buffer sent - check for buffer errors. |
987 | */ |
988 | static int |
989 | depca_tx(struct devicelinux_device *dev) |
990 | { |
991 | struct depca_private *lp = (struct depca_private *)dev->priv; |
992 | int entry; |
993 | s32 status; |
994 | u_long ioaddr = dev->base_addr; |
995 | |
996 | for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) { |
997 | status = readl(&lp->tx_ring[entry].base)(*(volatile unsigned int *) (&lp->tx_ring[entry].base) ) >> 16 ; |
998 | |
999 | if (status < 0) { /* Packet not yet sent! */ |
1000 | break; |
1001 | } else if (status & T_ERR0x4000) { /* An error occurred. */ |
1002 | status = readl(&lp->tx_ring[entry].misc)(*(volatile unsigned int *) (&lp->tx_ring[entry].misc) ); |
1003 | lp->stats.tx_errors++; |
1004 | if (status & TMD3_RTRY0x0400) lp->stats.tx_aborted_errors++; |
1005 | if (status & TMD3_LCAR0x0800) lp->stats.tx_carrier_errors++; |
1006 | if (status & TMD3_LCOL0x1000) lp->stats.tx_window_errors++; |
1007 | if (status & TMD3_UFLO0x4000) lp->stats.tx_fifo_errors++; |
1008 | if (status & (TMD3_BUFF0x8000 | TMD3_UFLO0x4000)) { |
1009 | /* Trigger an immediate send demand. */ |
1010 | outw(CSR0, DEPCA_ADDR)((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); |
1011 | outw(INEA | TDMD, DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __outwc((0x0040 | 0x0008),(ioaddr+0x04)) : __outw ((0x0040 | 0x0008),(ioaddr+0x04))); |
1012 | } |
1013 | } else if (status & (T_MORE0x1000 | T_ONE0x0800)) { |
1014 | lp->stats.collisions++; |
1015 | } else { |
1016 | lp->stats.tx_packets++; |
1017 | } |
1018 | |
1019 | /* Update all the pointers */ |
1020 | lp->tx_old = (lp->tx_old + 1) & lp->txRingMask; |
1021 | } |
1022 | |
1023 | return 0; |
1024 | } |
1025 | |
1026 | static int |
1027 | depca_close(struct devicelinux_device *dev) |
1028 | { |
1029 | struct depca_private *lp = (struct depca_private *)dev->priv; |
1030 | s16 nicsr; |
1031 | u_long ioaddr = dev->base_addr; |
1032 | |
1033 | dev->start = 0; |
1034 | dev->tbusy = 1; |
1035 | |
1036 | outw(CSR0, DEPCA_ADDR)((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); |
1037 | |
1038 | if (depca_debug > 1) { |
1039 | printk("%s: Shutting down ethercard, status was %2.2x.\n", |
1040 | dev->name, inw(DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __inwc(ioaddr+0x04) : __inw(ioaddr+0x04))); |
1041 | } |
1042 | |
1043 | /* |
1044 | ** We stop the DEPCA here -- it occasionally polls |
1045 | ** memory if we don't. |
1046 | */ |
1047 | outw(STOP, DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __outwc((0x0004),(ioaddr+0x04)) : __outw((0x0004 ),(ioaddr+0x04))); |
1048 | |
1049 | /* |
1050 | ** Give back the ROM in case the user wants to go to DOS |
1051 | */ |
1052 | if (lp->adapter != DEPCA) { |
1053 | nicsr = inb(DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __inbc(ioaddr+0x00) : __inb(ioaddr+0x00)); |
1054 | nicsr &= ~SHE0x0080; |
1055 | outb(nicsr, DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __outbc((nicsr),(ioaddr+0x00)) : __outb((nicsr) ,(ioaddr+0x00))); |
1056 | } |
1057 | |
1058 | /* |
1059 | ** Free the associated irq |
1060 | */ |
1061 | free_irq(dev->irq, NULL((void *) 0)); |
1062 | irq2dev_map[dev->irq] = NULL((void *) 0); |
1063 | |
1064 | MOD_DEC_USE_COUNTdo { } while (0); |
1065 | |
1066 | return 0; |
1067 | } |
1068 | |
1069 | static void LoadCSRs(struct devicelinux_device *dev) |
1070 | { |
1071 | struct depca_private *lp = (struct depca_private *)dev->priv; |
1072 | u_long ioaddr = dev->base_addr; |
1073 | |
1074 | outw(CSR1, DEPCA_ADDR)((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((1),(ioaddr+0x06)) : __outw((1),(ioaddr +0x06))); /* initialisation block address LSW */ |
1075 | outw((u16)(lp->sh_mem & LA_MASK), DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __outwc(((u16)(lp->sh_mem & 0x0000ffff)) ,(ioaddr+0x04)) : __outw(((u16)(lp->sh_mem & 0x0000ffff )),(ioaddr+0x04))); |
1076 | outw(CSR2, DEPCA_ADDR)((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((2),(ioaddr+0x06)) : __outw((2),(ioaddr +0x06))); /* initialisation block address MSW */ |
1077 | outw((u16)((lp->sh_mem & LA_MASK) >> 16), DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __outwc(((u16)((lp->sh_mem & 0x0000ffff) >> 16)),(ioaddr+0x04)) : __outw(((u16)((lp->sh_mem & 0x0000ffff) >> 16)),(ioaddr+0x04))); |
1078 | outw(CSR3, DEPCA_ADDR)((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((3),(ioaddr+0x06)) : __outw((3),(ioaddr +0x06))); /* ALE control */ |
1079 | outw(ACON, DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __outwc((0x0002),(ioaddr+0x04)) : __outw((0x0002 ),(ioaddr+0x04))); |
1080 | |
1081 | outw(CSR0, DEPCA_ADDR)((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); /* Point back to CSR0 */ |
1082 | |
1083 | return; |
1084 | } |
1085 | |
1086 | static int InitRestartDepca(struct devicelinux_device *dev) |
1087 | { |
1088 | struct depca_private *lp = (struct depca_private *)dev->priv; |
1089 | u_long ioaddr = dev->base_addr; |
1090 | int i, status=0; |
1091 | |
1092 | /* Copy the shadow init_block to shared memory */ |
1093 | memcpy_toio((char *)lp->sh_mem, &lp->init_block, sizeof(struct depca_init))(__builtin_constant_p((sizeof(struct depca_init))) ? __constant_memcpy (((void *)((char *)lp->sh_mem)),((&lp->init_block)) ,((sizeof(struct depca_init)))) : __memcpy(((void *)((char *) lp->sh_mem)),((&lp->init_block)),((sizeof(struct depca_init ))))); |
1094 | |
1095 | outw(CSR0, DEPCA_ADDR)((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); /* point back to CSR0 */ |
1096 | outw(INIT, DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __outwc((0x0001),(ioaddr+0x04)) : __outw((0x0001 ),(ioaddr+0x04))); /* initialize DEPCA */ |
1097 | |
1098 | /* wait for lance to complete initialisation */ |
1099 | for (i=0;(i<100) && !(inw(DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __inwc(ioaddr+0x04) : __inw(ioaddr+0x04)) & IDON0x0100); i++); |
1100 | |
1101 | if (i!=100) { |
1102 | /* clear IDON by writing a "1", enable interrupts and start lance */ |
1103 | outw(IDON | INEA | STRT, DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __outwc((0x0100 | 0x0040 | 0x0002),(ioaddr+0x04 )) : __outw((0x0100 | 0x0040 | 0x0002),(ioaddr+0x04))); |
1104 | if (depca_debug > 2) { |
1105 | printk("%s: DEPCA open after %d ticks, init block 0x%08lx csr0 %4.4x.\n", |
1106 | dev->name, i, lp->sh_mem, inw(DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __inwc(ioaddr+0x04) : __inw(ioaddr+0x04))); |
1107 | } |
1108 | } else { |
1109 | printk("%s: DEPCA unopen after %d ticks, init block 0x%08lx csr0 %4.4x.\n", |
1110 | dev->name, i, lp->sh_mem, inw(DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __inwc(ioaddr+0x04) : __inw(ioaddr+0x04))); |
1111 | status = -1; |
1112 | } |
1113 | |
1114 | return status; |
1115 | } |
1116 | |
1117 | static struct enet_statistics * |
1118 | depca_get_stats(struct devicelinux_device *dev) |
1119 | { |
1120 | struct depca_private *lp = (struct depca_private *)dev->priv; |
1121 | |
1122 | /* Null body since there is no framing error counter */ |
1123 | |
1124 | return &lp->stats; |
1125 | } |
1126 | |
1127 | /* |
1128 | ** Set or clear the multicast filter for this adaptor. |
1129 | */ |
1130 | static void |
1131 | set_multicast_list(struct devicelinux_device *dev) |
1132 | { |
1133 | struct depca_private *lp = (struct depca_private *)dev->priv; |
1134 | u_long ioaddr = dev->base_addr; |
1135 | |
1136 | if (irq2dev_map[dev->irq] != NULL((void *) 0)) { |
1137 | while(dev->tbusy); /* Stop ring access */ |
1138 | set_bit(0, (void*)&dev->tbusy); |
1139 | while(lp->tx_old != lp->tx_new); /* Wait for the ring to empty */ |
1140 | |
1141 | STOP_DEPCA((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); ((__builtin_constant_p((ioaddr+0x04)) && (ioaddr +0x04) < 256) ? __outwc((0x0004),(ioaddr+0x04)) : __outw(( 0x0004),(ioaddr+0x04))); /* Temporarily stop the depca. */ |
1142 | depca_init_ring(dev); /* Initialize the descriptor rings */ |
1143 | |
1144 | if (dev->flags & IFF_PROMISC0x100) { /* Set promiscuous mode */ |
1145 | lp->init_block.mode |= PROM0x8000; |
1146 | } else { |
1147 | SetMulticastFilter(dev); |
1148 | lp->init_block.mode &= ~PROM0x8000; /* Unset promiscuous mode */ |
1149 | } |
1150 | |
1151 | LoadCSRs(dev); /* Reload CSR3 */ |
1152 | InitRestartDepca(dev); /* Resume normal operation. */ |
1153 | dev->tbusy = 0; /* Unlock the TX ring */ |
1154 | } |
1155 | } |
1156 | |
1157 | /* |
1158 | ** Calculate the hash code and update the logical address filter |
1159 | ** from a list of ethernet multicast addresses. |
1160 | ** Big endian crc one liner is mine, all mine, ha ha ha ha! |
1161 | ** LANCE calculates its hash codes big endian. |
1162 | */ |
1163 | static void SetMulticastFilter(struct devicelinux_device *dev) |
1164 | { |
1165 | struct depca_private *lp = (struct depca_private *)dev->priv; |
1166 | struct dev_mc_list *dmi=dev->mc_list; |
1167 | char *addrs; |
1168 | int i, j, bit, byte; |
1169 | u16 hashcode; |
1170 | s32 crc, poly = CRC_POLYNOMIAL_BE0x04c11db7UL; |
1171 | |
1172 | if (dev->flags & IFF_ALLMULTI0x200) { /* Set all multicast bits */ |
1173 | for (i=0; i<(HASH_TABLE_LEN64>>3); i++) { |
1174 | lp->init_block.mcast_table[i] = (char)0xff; |
1175 | } |
1176 | } else { |
1177 | for (i=0; i<(HASH_TABLE_LEN64>>3); i++){ /* Clear the multicast table */ |
1178 | lp->init_block.mcast_table[i]=0; |
1179 | } |
1180 | /* Add multicast addresses */ |
1181 | for (i=0;i<dev->mc_count;i++) { /* for each address in the list */ |
1182 | addrs=dmi->dmi_addr; |
1183 | dmi=dmi->next; |
1184 | if ((*addrs & 0x01) == 1) { /* multicast address? */ |
1185 | crc = 0xffffffff; /* init CRC for each address */ |
1186 | for (byte=0;byte<ETH_ALEN6;byte++) {/* for each address byte */ |
1187 | /* process each address bit */ |
1188 | for (bit = *addrs++,j=0;j<8;j++, bit>>=1) { |
1189 | crc = (crc << 1) ^ ((((crc<0?1:0) ^ bit) & 0x01) ? poly : 0); |
1190 | } |
1191 | } |
1192 | hashcode = (crc & 1); /* hashcode is 6 LSb of CRC ... */ |
1193 | for (j=0;j<5;j++) { /* ... in reverse order. */ |
1194 | hashcode = (hashcode << 1) | ((crc>>=1) & 1); |
1195 | } |
1196 | |
1197 | |
1198 | byte = hashcode >> 3; /* bit[3-5] -> byte in filter */ |
1199 | bit = 1 << (hashcode & 0x07); /* bit[0-2] -> bit in byte */ |
1200 | lp->init_block.mcast_table[byte] |= bit; |
1201 | } |
1202 | } |
1203 | } |
1204 | |
1205 | return; |
1206 | } |
1207 | |
1208 | /* |
1209 | ** ISA bus I/O device probe |
1210 | */ |
1211 | static void isa_probe(struct devicelinux_device *dev, u_long ioaddr) |
1212 | { |
1213 | int i = num_depcas, maxSlots; |
1214 | s32 ports[] = DEPCA_IO_PORTS{0x300, 0x200, 0}; |
1215 | |
1216 | if (!ioaddr && autoprobed) return ; /* Been here before ! */ |
1217 | if (ioaddr > 0x400) return; /* EISA Address */ |
1218 | if (i >= MAX_NUM_DEPCAS2) return; /* Too many ISA adapters */ |
1219 | |
1220 | if (ioaddr == 0) { /* Autoprobing */ |
1221 | maxSlots = MAX_NUM_DEPCAS2; |
1222 | } else { /* Probe a specific location */ |
1223 | ports[i] = ioaddr; |
1224 | maxSlots = i + 1; |
1225 | } |
1226 | |
1227 | for (; (i<maxSlots) && (dev!=NULL((void *) 0)) && ports[i]; i++) { |
1228 | if (DevicePresent(ports[i]) == 0) { |
1229 | if (check_region(ports[i], DEPCA_TOTAL_SIZE0x10) == 0) { |
1230 | if ((dev = alloc_device(dev, ports[i])) != NULL((void *) 0)) { |
1231 | if (depca_hw_init(dev, ports[i]) == 0) { |
1232 | num_depcas++; |
1233 | } |
1234 | num_eth++; |
1235 | } |
1236 | } else if (autoprobed) { |
1237 | printk("%s: region already allocated at 0x%04x.\n", dev->name,ports[i]); |
1238 | } |
1239 | } |
1240 | } |
1241 | |
1242 | return; |
1243 | } |
1244 | |
1245 | /* |
1246 | ** EISA bus I/O device probe. Probe from slot 1 since slot 0 is usually |
1247 | ** the motherboard. Upto 15 EISA devices are supported. |
1248 | */ |
1249 | static void eisa_probe(struct devicelinux_device *dev, u_long ioaddr) |
1250 | { |
1251 | int i, maxSlots; |
1252 | u_long iobase; |
1253 | char name[DEPCA_STRLEN16]; |
1254 | |
1255 | if (!ioaddr && autoprobed) return ; /* Been here before ! */ |
1256 | if ((ioaddr < 0x400) && (ioaddr > 0)) return; /* ISA Address */ |
1257 | |
1258 | if (ioaddr == 0) { /* Autoprobing */ |
1259 | iobase = EISA_SLOT_INC0x1000; /* Get the first slot address */ |
1260 | i = 1; |
1261 | maxSlots = MAX_EISA_SLOTS16; |
1262 | } else { /* Probe a specific location */ |
1263 | iobase = ioaddr; |
1264 | i = (ioaddr >> 12); |
1265 | maxSlots = i + 1; |
1266 | } |
1267 | if ((iobase & 0x0fff) == 0) iobase += DEPCA_EISA_IO_PORTS0x0c00; |
1268 | |
1269 | for (; (i<maxSlots) && (dev!=NULL((void *) 0)); i++, iobase+=EISA_SLOT_INC0x1000) { |
1270 | if (EISA_signature(name, EISA_IDiobase+0x0080)) { |
1271 | if (DevicePresent(iobase) == 0) { |
1272 | if (check_region(iobase, DEPCA_TOTAL_SIZE0x10) == 0) { |
1273 | if ((dev = alloc_device(dev, iobase)) != NULL((void *) 0)) { |
1274 | if (depca_hw_init(dev, iobase) == 0) { |
1275 | num_depcas++; |
1276 | } |
1277 | num_eth++; |
1278 | } |
1279 | } else if (autoprobed) { |
1280 | printk("%s: region already allocated at 0x%04lx.\n",dev->name,iobase); |
1281 | } |
1282 | } |
1283 | } |
1284 | } |
1285 | |
1286 | return; |
1287 | } |
1288 | |
1289 | /* |
1290 | ** Search the entire 'eth' device list for a fixed probe. If a match isn't |
1291 | ** found then check for an autoprobe or unused device location. If they |
1292 | ** are not available then insert a new device structure at the end of |
1293 | ** the current list. |
1294 | */ |
1295 | static struct devicelinux_device * |
1296 | alloc_device(struct devicelinux_device *dev, u_long iobase) |
1297 | { |
1298 | struct devicelinux_device *adev = NULL((void *) 0); |
1299 | int fixed = 0, new_dev = 0; |
1300 | |
1301 | num_eth = depca_dev_index(dev->name); |
1302 | if (loading_module) return dev; |
1303 | |
1304 | while (1) { |
1305 | if (((dev->base_addr == DEPCA_NDA0xffe0) || (dev->base_addr==0)) && !adev) { |
1306 | adev=dev; |
1307 | } else if ((dev->priv == NULL((void *) 0)) && (dev->base_addr==iobase)) { |
1308 | fixed = 1; |
1309 | } else { |
1310 | if (dev->next == NULL((void *) 0)) { |
1311 | new_dev = 1; |
1312 | } else if (strncmp(dev->next->name, "eth", 3) != 0) { |
1313 | new_dev = 1; |
1314 | } |
1315 | } |
1316 | if ((dev->next == NULL((void *) 0)) || new_dev || fixed) break; |
1317 | dev = dev->next; |
1318 | num_eth++; |
1319 | } |
1320 | if (adev && !fixed) { |
1321 | dev = adev; |
1322 | num_eth = depca_dev_index(dev->name); |
1323 | new_dev = 0; |
1324 | } |
1325 | |
1326 | if (((dev->next == NULL((void *) 0)) && |
1327 | ((dev->base_addr != DEPCA_NDA0xffe0) && (dev->base_addr != 0)) && !fixed) || |
1328 | new_dev) { |
1329 | num_eth++; /* New device */ |
1330 | dev = insert_device(dev, iobase, depca_probe); |
1331 | } |
1332 | |
1333 | return dev; |
1334 | } |
1335 | |
1336 | /* |
1337 | ** If at end of eth device list and can't use current entry, malloc |
1338 | ** one up. If memory could not be allocated, print an error message. |
1339 | */ |
1340 | static struct devicelinux_device * |
1341 | insert_device(struct devicelinux_device *dev, u_long iobase, int (*init)(struct devicelinux_device *)) |
1342 | { |
1343 | struct devicelinux_device *new; |
1344 | |
1345 | new = (struct devicelinux_device *)kmalloclinux_kmalloc(sizeof(struct devicelinux_device)+8, GFP_KERNEL0x03); |
1346 | if (new == NULL((void *) 0)) { |
1347 | printk("eth%d: Device not initialised, insufficient memory\n",num_eth); |
1348 | return NULL((void *) 0); |
1349 | } else { |
1350 | new->next = dev->next; |
1351 | dev->next = new; |
1352 | dev = dev->next; /* point to the new device */ |
1353 | dev->name = (char *)(dev + 1); |
1354 | if (num_eth > 9999) { |
1355 | sprintflinux_sprintf(dev->name,"eth????");/* New device name */ |
1356 | } else { |
1357 | sprintflinux_sprintf(dev->name,"eth%d", num_eth);/* New device name */ |
1358 | } |
1359 | dev->base_addr = iobase; /* assign the io address */ |
1360 | dev->init = init; /* initialisation routine */ |
1361 | } |
1362 | |
1363 | return dev; |
1364 | } |
1365 | |
1366 | static int |
1367 | depca_dev_index(char *s) |
1368 | { |
1369 | int i=0, j=0; |
1370 | |
1371 | for (;*s; s++) { |
1372 | if (isdigit(*s)(((_ctype[(int)(unsigned char)(*s)])&(0x04)) != 0)) { |
1373 | j=1; |
1374 | i = (i * 10) + (*s - '0'); |
1375 | } else if (j) break; |
1376 | } |
1377 | |
1378 | return i; |
1379 | } |
1380 | |
1381 | /* |
1382 | ** Look for a particular board name in the on-board Remote Diagnostics |
1383 | ** and Boot (readb) ROM. This will also give us a clue to the network RAM |
1384 | ** base address. |
1385 | */ |
1386 | static void DepcaSignature(char *name, u_long paddr) |
1387 | { |
1388 | u_int i,j,k; |
1389 | const char *signatures[] = DEPCA_SIGNATURE{"DEPCA", "DE100","DE101", "DE200","DE201","DE202", "DE210", "DE422" , ""}; |
1390 | char tmpstr[16]; |
1391 | |
1392 | /* Copy the first 16 bytes of ROM */ |
1393 | for (i=0;i<16;i++) { |
1394 | tmpstr[i] = readb(paddr+0xc000+i)(*(volatile unsigned char *) (paddr+0xc000 +i)); |
1395 | } |
1396 | |
1397 | /* Check if PROM contains a valid string */ |
1398 | for (i=0;*signatures[i]!='\0';i++) { |
1399 | for (j=0,k=0;j<16 && k<strlen(signatures[i]);j++) { |
1400 | if (signatures[i][k] == tmpstr[j]) { /* track signature */ |
1401 | k++; |
1402 | } else { /* lost signature; begin search again */ |
1403 | k=0; |
1404 | } |
1405 | } |
1406 | if (k == strlen(signatures[i])) break; |
1407 | } |
1408 | |
1409 | /* Check if name string is valid, provided there's no PROM */ |
1410 | if (*name && (i == unknown)) { |
1411 | for (i=0;*signatures[i]!='\0';i++) { |
1412 | if (strcmp(name,signatures[i]) == 0) break; |
1413 | } |
1414 | } |
1415 | |
1416 | /* Update search results */ |
1417 | strcpy(name,signatures[i]); |
1418 | adapter = i; |
1419 | |
1420 | return; |
1421 | } |
1422 | |
1423 | /* |
1424 | ** Look for a special sequence in the Ethernet station address PROM that |
1425 | ** is common across all DEPCA products. Note that the original DEPCA needs |
1426 | ** its ROM address counter to be initialized and enabled. Only enable |
1427 | ** if the first address octet is a 0x08 - this minimises the chances of |
1428 | ** messing around with some other hardware, but it assumes that this DEPCA |
1429 | ** card initialized itself correctly. |
1430 | ** |
1431 | ** Search the Ethernet address ROM for the signature. Since the ROM address |
1432 | ** counter can start at an arbitrary point, the search must include the entire |
1433 | ** probe sequence length plus the (length_of_the_signature - 1). |
1434 | ** Stop the search IMMEDIATELY after the signature is found so that the |
1435 | ** PROM address counter is correctly positioned at the start of the |
1436 | ** ethernet address for later read out. |
1437 | */ |
1438 | static int DevicePresent(u_long ioaddr) |
1439 | { |
1440 | union { |
1441 | struct { |
1442 | u32 a; |
1443 | u32 b; |
1444 | } llsig; |
1445 | char Sig[sizeof(u32) << 1]; |
1446 | } dev; |
1447 | short sigLength=0; |
1448 | s8 data; |
1449 | s16 nicsr; |
1450 | int i, j, status = 0; |
1451 | |
1452 | data = inb(DEPCA_PROM)((__builtin_constant_p((ioaddr+0x0c)) && (ioaddr+0x0c ) < 256) ? __inbc(ioaddr+0x0c) : __inb(ioaddr+0x0c)); /* clear counter on DEPCA */ |
Value stored to 'data' is never read | |
1453 | data = inb(DEPCA_PROM)((__builtin_constant_p((ioaddr+0x0c)) && (ioaddr+0x0c ) < 256) ? __inbc(ioaddr+0x0c) : __inb(ioaddr+0x0c)); /* read data */ |
1454 | |
1455 | if (data == 0x08) { /* Enable counter on DEPCA */ |
1456 | nicsr = inb(DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __inbc(ioaddr+0x00) : __inb(ioaddr+0x00)); |
1457 | nicsr |= AAC0x0008; |
1458 | outb(nicsr, DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __outbc((nicsr),(ioaddr+0x00)) : __outb((nicsr) ,(ioaddr+0x00))); |
1459 | } |
1460 | |
1461 | dev.llsig.a = ETH_PROM_SIG0xAA5500FFUL; |
1462 | dev.llsig.b = ETH_PROM_SIG0xAA5500FFUL; |
1463 | sigLength = sizeof(u32) << 1; |
1464 | |
1465 | for (i=0,j=0;j<sigLength && i<PROBE_LENGTH32+sigLength-1;i++) { |
1466 | data = inb(DEPCA_PROM)((__builtin_constant_p((ioaddr+0x0c)) && (ioaddr+0x0c ) < 256) ? __inbc(ioaddr+0x0c) : __inb(ioaddr+0x0c)); |
1467 | if (dev.Sig[j] == data) { /* track signature */ |
1468 | j++; |
1469 | } else { /* lost signature; begin search again */ |
1470 | if (data == dev.Sig[0]) { /* rare case.... */ |
1471 | j=1; |
1472 | } else { |
1473 | j=0; |
1474 | } |
1475 | } |
1476 | } |
1477 | |
1478 | if (j!=sigLength) { |
1479 | status = -ENODEV19; /* search failed */ |
1480 | } |
1481 | |
1482 | return status; |
1483 | } |
1484 | |
1485 | /* |
1486 | ** The DE100 and DE101 PROM accesses were made non-standard for some bizarre |
1487 | ** reason: access the upper half of the PROM with x=0; access the lower half |
1488 | ** with x=1. |
1489 | */ |
1490 | static int get_hw_addr(struct devicelinux_device *dev) |
1491 | { |
1492 | u_long ioaddr = dev->base_addr; |
1493 | int i, k, tmp, status = 0; |
1494 | u_short j, x, chksum; |
1495 | |
1496 | x = (((adapter == de100) || (adapter == de101)) ? 1 : 0); |
1497 | |
1498 | for (i=0,k=0,j=0;j<3;j++) { |
1499 | k <<= 1 ; |
1500 | if (k > 0xffff) k-=0xffff; |
1501 | |
1502 | k += (u_char) (tmp = inb(DEPCA_PROM + x)((__builtin_constant_p((ioaddr+0x0c + x)) && (ioaddr+ 0x0c + x) < 256) ? __inbc(ioaddr+0x0c + x) : __inb(ioaddr+ 0x0c + x))); |
1503 | dev->dev_addr[i++] = (u_char) tmp; |
1504 | k += (u_short) ((tmp = inb(DEPCA_PROM + x)((__builtin_constant_p((ioaddr+0x0c + x)) && (ioaddr+ 0x0c + x) < 256) ? __inbc(ioaddr+0x0c + x) : __inb(ioaddr+ 0x0c + x))) << 8); |
1505 | dev->dev_addr[i++] = (u_char) tmp; |
1506 | |
1507 | if (k > 0xffff) k-=0xffff; |
1508 | } |
1509 | if (k == 0xffff) k=0; |
1510 | |
1511 | chksum = (u_char) inb(DEPCA_PROM + x)((__builtin_constant_p((ioaddr+0x0c + x)) && (ioaddr+ 0x0c + x) < 256) ? __inbc(ioaddr+0x0c + x) : __inb(ioaddr+ 0x0c + x)); |
1512 | chksum |= (u_short) (inb(DEPCA_PROM + x)((__builtin_constant_p((ioaddr+0x0c + x)) && (ioaddr+ 0x0c + x) < 256) ? __inbc(ioaddr+0x0c + x) : __inb(ioaddr+ 0x0c + x)) << 8); |
1513 | if (k != chksum) status = -1; |
1514 | |
1515 | return status; |
1516 | } |
1517 | |
1518 | /* |
1519 | ** Load a packet into the shared memory |
1520 | */ |
1521 | static int load_packet(struct devicelinux_device *dev, struct sk_buff *skb) |
1522 | { |
1523 | struct depca_private *lp = (struct depca_private *)dev->priv; |
1524 | int i, entry, end, len, status = 0; |
1525 | |
1526 | entry = lp->tx_new; /* Ring around buffer number. */ |
1527 | end = (entry + (skb->len - 1) / TX_BUFF_SZ1536) & lp->txRingMask; |
1528 | if (!(readl(&lp->tx_ring[end].base)(*(volatile unsigned int *) (&lp->tx_ring[end].base)) & T_OWN0x80000000)) {/* Enough room? */ |
1529 | /* |
1530 | ** Caution: the write order is important here... don't set up the |
1531 | ** ownership rights until all the other information is in place. |
1532 | */ |
1533 | if (end < entry) { /* wrapped buffer */ |
1534 | len = (lp->txRingMask - entry + 1) * TX_BUFF_SZ1536; |
1535 | memcpy_toio(lp->tx_memcpy[entry], skb->data, len)(__builtin_constant_p((len)) ? __constant_memcpy(((void *)(lp ->tx_memcpy[entry])),((skb->data)),((len))) : __memcpy( ((void *)(lp->tx_memcpy[entry])),((skb->data)),((len))) ); |
1536 | memcpy_toio(lp->tx_memcpy[0], skb->data + len, skb->len - len)(__builtin_constant_p((skb->len - len)) ? __constant_memcpy (((void *)(lp->tx_memcpy[0])),((skb->data + len)),((skb ->len - len))) : __memcpy(((void *)(lp->tx_memcpy[0])), ((skb->data + len)),((skb->len - len)))); |
1537 | } else { /* linear buffer */ |
1538 | memcpy_toio(lp->tx_memcpy[entry], skb->data, skb->len)(__builtin_constant_p((skb->len)) ? __constant_memcpy(((void *)(lp->tx_memcpy[entry])),((skb->data)),((skb->len) )) : __memcpy(((void *)(lp->tx_memcpy[entry])),((skb->data )),((skb->len)))); |
1539 | } |
1540 | |
1541 | /* set up the buffer descriptors */ |
1542 | len = (skb->len < ETH_ZLEN60) ? ETH_ZLEN60 : skb->len; |
1543 | for (i = entry; i != end; i = (i + 1) & lp->txRingMask) { |
1544 | /* clean out flags */ |
1545 | writel(readl(&lp->tx_ring[i].base) & ~T_FLAGS, &lp->tx_ring[i].base)((*(volatile unsigned int *) (&lp->tx_ring[i].base)) = ((*(volatile unsigned int *) (&lp->tx_ring[i].base)) & ~0xff000000)); |
1546 | writew(0x0000, &lp->tx_ring[i].misc)((*(volatile unsigned short *) (&lp->tx_ring[i].misc)) = (0x0000)); /* clears other error flags */ |
1547 | writew(-TX_BUFF_SZ, &lp->tx_ring[i].length)((*(volatile unsigned short *) (&lp->tx_ring[i].length )) = (-1536));/* packet length in buffer */ |
1548 | len -= TX_BUFF_SZ1536; |
1549 | } |
1550 | /* clean out flags */ |
1551 | writel(readl(&lp->tx_ring[end].base) & ~T_FLAGS, &lp->tx_ring[end].base)((*(volatile unsigned int *) (&lp->tx_ring[end].base)) = ((*(volatile unsigned int *) (&lp->tx_ring[end].base )) & ~0xff000000)); |
1552 | writew(0x0000, &lp->tx_ring[end].misc)((*(volatile unsigned short *) (&lp->tx_ring[end].misc )) = (0x0000)); /* clears other error flags */ |
1553 | writew(-len, &lp->tx_ring[end].length)((*(volatile unsigned short *) (&lp->tx_ring[end].length )) = (-len)); /* packet length in last buff */ |
1554 | |
1555 | /* start of packet */ |
1556 | writel(readl(&lp->tx_ring[entry].base) | T_STP, &lp->tx_ring[entry].base)((*(volatile unsigned int *) (&lp->tx_ring[entry].base )) = ((*(volatile unsigned int *) (&lp->tx_ring[entry] .base)) | 0x02000000)); |
1557 | /* end of packet */ |
1558 | writel(readl(&lp->tx_ring[end].base) | T_ENP, &lp->tx_ring[end].base)((*(volatile unsigned int *) (&lp->tx_ring[end].base)) = ((*(volatile unsigned int *) (&lp->tx_ring[end].base )) | 0x01000000)); |
1559 | |
1560 | for (i=end; i!=entry; --i) { |
1561 | /* ownership of packet */ |
1562 | writel(readl(&lp->tx_ring[i].base) | T_OWN, &lp->tx_ring[i].base)((*(volatile unsigned int *) (&lp->tx_ring[i].base)) = ((*(volatile unsigned int *) (&lp->tx_ring[i].base)) | 0x80000000)); |
1563 | if (i == 0) i=lp->txRingMask+1; |
1564 | } |
1565 | writel(readl(&lp->tx_ring[entry].base) | T_OWN, &lp->tx_ring[entry].base)((*(volatile unsigned int *) (&lp->tx_ring[entry].base )) = ((*(volatile unsigned int *) (&lp->tx_ring[entry] .base)) | 0x80000000)); |
1566 | |
1567 | lp->tx_new = (++end) & lp->txRingMask; /* update current pointers */ |
1568 | } else { |
1569 | status = -1; |
1570 | } |
1571 | |
1572 | return status; |
1573 | } |
1574 | |
1575 | /* |
1576 | ** Look for a particular board name in the EISA configuration space |
1577 | */ |
1578 | static int EISA_signature(char *name, s32 eisa_id) |
1579 | { |
1580 | u_int i; |
1581 | const char *signatures[] = DEPCA_SIGNATURE{"DEPCA", "DE100","DE101", "DE200","DE201","DE202", "DE210", "DE422" , ""}; |
1582 | char ManCode[DEPCA_STRLEN16]; |
1583 | union { |
1584 | s32 ID; |
1585 | char Id[4]; |
1586 | } Eisa; |
1587 | int status = 0; |
1588 | |
1589 | *name = '\0'; |
1590 | Eisa.ID = inl(eisa_id)((__builtin_constant_p((eisa_id)) && (eisa_id) < 256 ) ? __inlc(eisa_id) : __inl(eisa_id)); |
1591 | |
1592 | ManCode[0]=(((Eisa.Id[0]>>2)&0x1f)+0x40); |
1593 | ManCode[1]=(((Eisa.Id[1]&0xe0)>>5)+((Eisa.Id[0]&0x03)<<3)+0x40); |
1594 | ManCode[2]=(((Eisa.Id[2]>>4)&0x0f)+0x30); |
1595 | ManCode[3]=(( Eisa.Id[2]&0x0f)+0x30); |
1596 | ManCode[4]=(((Eisa.Id[3]>>4)&0x0f)+0x30); |
1597 | ManCode[5]='\0'; |
1598 | |
1599 | for (i=0;(*signatures[i] != '\0') && (*name == '\0');i++) { |
1600 | if (strstr(ManCode, signatures[i]) != NULL((void *) 0)) { |
1601 | strcpy(name,ManCode); |
1602 | status = 1; |
1603 | } |
1604 | } |
1605 | |
1606 | return status; |
1607 | } |
1608 | |
1609 | static void depca_dbg_open(struct devicelinux_device *dev) |
1610 | { |
1611 | struct depca_private *lp = (struct depca_private *)dev->priv; |
1612 | u_long ioaddr = dev->base_addr; |
1613 | struct depca_init *p = (struct depca_init *)lp->sh_mem; |
1614 | int i; |
1615 | |
1616 | if (depca_debug > 1){ |
1617 | /* Copy the shadow init_block to shared memory */ |
1618 | memcpy_toio((char *)lp->sh_mem,&lp->init_block,sizeof(struct depca_init))(__builtin_constant_p((sizeof(struct depca_init))) ? __constant_memcpy (((void *)((char *)lp->sh_mem)),((&lp->init_block)) ,((sizeof(struct depca_init)))) : __memcpy(((void *)((char *) lp->sh_mem)),((&lp->init_block)),((sizeof(struct depca_init ))))); |
1619 | |
1620 | printk("%s: depca open with irq %d\n",dev->name,dev->irq); |
1621 | printk("Descriptor head addresses:\n"); |
1622 | printk("\t0x%lx 0x%lx\n",(u_long)lp->rx_ring, (u_long)lp->tx_ring); |
1623 | printk("Descriptor addresses:\nRX: "); |
1624 | for (i=0;i<lp->rxRingMask;i++){ |
1625 | if (i < 3) { |
1626 | printk("0x%8.8lx ", (long) &lp->rx_ring[i].base); |
1627 | } |
1628 | } |
1629 | printk("...0x%8.8lx\n", (long) &lp->rx_ring[i].base); |
1630 | printk("TX: "); |
1631 | for (i=0;i<lp->txRingMask;i++){ |
1632 | if (i < 3) { |
1633 | printk("0x%8.8lx ", (long) &lp->tx_ring[i].base); |
1634 | } |
1635 | } |
1636 | printk("...0x%8.8lx\n", (long) &lp->tx_ring[i].base); |
1637 | printk("\nDescriptor buffers:\nRX: "); |
1638 | for (i=0;i<lp->rxRingMask;i++){ |
1639 | if (i < 3) { |
1640 | printk("0x%8.8x ", readl(&lp->rx_ring[i].base)(*(volatile unsigned int *) (&lp->rx_ring[i].base))); |
1641 | } |
1642 | } |
1643 | printk("...0x%8.8x\n", readl(&lp->rx_ring[i].base)(*(volatile unsigned int *) (&lp->rx_ring[i].base))); |
1644 | printk("TX: "); |
1645 | for (i=0;i<lp->txRingMask;i++){ |
1646 | if (i < 3) { |
1647 | printk("0x%8.8x ", readl(&lp->tx_ring[i].base)(*(volatile unsigned int *) (&lp->tx_ring[i].base))); |
1648 | } |
1649 | } |
1650 | printk("...0x%8.8x\n", readl(&lp->tx_ring[i].base)(*(volatile unsigned int *) (&lp->tx_ring[i].base))); |
1651 | printk("Initialisation block at 0x%8.8lx\n",lp->sh_mem); |
1652 | printk("\tmode: 0x%4.4x\n",readw(&p->mode)(*(volatile unsigned short *) (&p->mode))); |
1653 | printk("\tphysical address: "); |
1654 | for (i=0;i<ETH_ALEN6-1;i++){ |
1655 | printk("%2.2x:",(u_char)readb(&p->phys_addr[i])(*(volatile unsigned char *) (&p->phys_addr[i]))); |
1656 | } |
1657 | printk("%2.2x\n",(u_char)readb(&p->phys_addr[i])(*(volatile unsigned char *) (&p->phys_addr[i]))); |
1658 | printk("\tmulticast hash table: "); |
1659 | for (i=0;i<(HASH_TABLE_LEN64 >> 3)-1;i++){ |
1660 | printk("%2.2x:",(u_char)readb(&p->mcast_table[i])(*(volatile unsigned char *) (&p->mcast_table[i]))); |
1661 | } |
1662 | printk("%2.2x\n",(u_char)readb(&p->mcast_table[i])(*(volatile unsigned char *) (&p->mcast_table[i]))); |
1663 | printk("\trx_ring at: 0x%8.8x\n",readl(&p->rx_ring)(*(volatile unsigned int *) (&p->rx_ring))); |
1664 | printk("\ttx_ring at: 0x%8.8x\n",readl(&p->tx_ring)(*(volatile unsigned int *) (&p->tx_ring))); |
1665 | printk("dma_buffs: 0x%8.8lx\n",lp->dma_buffs); |
1666 | printk("Ring size:\nRX: %d Log2(rxRingMask): 0x%8.8x\n", |
1667 | (int)lp->rxRingMask + 1, |
1668 | lp->rx_rlen); |
1669 | printk("TX: %d Log2(txRingMask): 0x%8.8x\n", |
1670 | (int)lp->txRingMask + 1, |
1671 | lp->tx_rlen); |
1672 | outw(CSR2,DEPCA_ADDR)((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((2),(ioaddr+0x06)) : __outw((2),(ioaddr +0x06))); |
1673 | printk("CSR2&1: 0x%4.4x",inw(DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __inwc(ioaddr+0x04) : __inw(ioaddr+0x04))); |
1674 | outw(CSR1,DEPCA_ADDR)((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((1),(ioaddr+0x06)) : __outw((1),(ioaddr +0x06))); |
1675 | printk("%4.4x\n",inw(DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __inwc(ioaddr+0x04) : __inw(ioaddr+0x04))); |
1676 | outw(CSR3,DEPCA_ADDR)((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((3),(ioaddr+0x06)) : __outw((3),(ioaddr +0x06))); |
1677 | printk("CSR3: 0x%4.4x\n",inw(DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __inwc(ioaddr+0x04) : __inw(ioaddr+0x04))); |
1678 | } |
1679 | |
1680 | return; |
1681 | } |
1682 | |
1683 | /* |
1684 | ** Perform IOCTL call functions here. Some are privileged operations and the |
1685 | ** effective uid is checked in those cases. |
1686 | ** All MCA IOCTLs will not work here and are for testing purposes only. |
1687 | */ |
1688 | static int depca_ioctl(struct devicelinux_device *dev, struct ifreq *rq, int cmd) |
1689 | { |
1690 | struct depca_private *lp = (struct depca_private *)dev->priv; |
1691 | struct depca_ioctl *ioc = (struct depca_ioctl *) &rq->ifr_dataifr_ifru.ifru_data; |
1692 | int i, status = 0; |
1693 | u_long ioaddr = dev->base_addr; |
1694 | union { |
1695 | u8 addr[(HASH_TABLE_LEN64 * ETH_ALEN6)]; |
1696 | u16 sval[(HASH_TABLE_LEN64 * ETH_ALEN6) >> 1]; |
1697 | u32 lval[(HASH_TABLE_LEN64 * ETH_ALEN6) >> 2]; |
1698 | } tmp; |
1699 | |
1700 | switch(ioc->cmd) { |
1701 | case DEPCA_GET_HWADDR0x01: /* Get the hardware address */ |
1702 | for (i=0; i<ETH_ALEN6; i++) { |
1703 | tmp.addr[i] = dev->dev_addr[i]; |
1704 | } |
1705 | ioc->len = ETH_ALEN6; |
1706 | if (!(status = verify_area(VERIFY_WRITE1, (void *)ioc->data, ioc->len))) { |
1707 | memcpy_tofs(ioc->data, tmp.addr, ioc->len); |
1708 | } |
1709 | |
1710 | break; |
1711 | case DEPCA_SET_HWADDR0x02: /* Set the hardware address */ |
1712 | if (suser()) { |
1713 | if (!(status = verify_area(VERIFY_READ0, (void *)ioc->data, ETH_ALEN6))) { |
1714 | memcpy_fromfs(tmp.addr,ioc->data,ETH_ALEN6); |
1715 | for (i=0; i<ETH_ALEN6; i++) { |
1716 | dev->dev_addr[i] = tmp.addr[i]; |
1717 | } |
1718 | while(dev->tbusy); /* Stop ring access */ |
1719 | set_bit(0, (void*)&dev->tbusy); |
1720 | while(lp->tx_old != lp->tx_new);/* Wait for the ring to empty */ |
1721 | |
1722 | STOP_DEPCA((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); ((__builtin_constant_p((ioaddr+0x04)) && (ioaddr +0x04) < 256) ? __outwc((0x0004),(ioaddr+0x04)) : __outw(( 0x0004),(ioaddr+0x04))); /* Temporarily stop the depca. */ |
1723 | depca_init_ring(dev); /* Initialize the descriptor rings */ |
1724 | LoadCSRs(dev); /* Reload CSR3 */ |
1725 | InitRestartDepca(dev); /* Resume normal operation. */ |
1726 | dev->tbusy = 0; /* Unlock the TX ring */ |
1727 | } |
1728 | } else { |
1729 | status = -EPERM1; |
1730 | } |
1731 | |
1732 | break; |
1733 | case DEPCA_SET_PROM0x03: /* Set Promiscuous Mode */ |
1734 | if (suser()) { |
1735 | while(dev->tbusy); /* Stop ring access */ |
1736 | set_bit(0, (void*)&dev->tbusy); |
1737 | while(lp->tx_old != lp->tx_new); /* Wait for the ring to empty */ |
1738 | |
1739 | STOP_DEPCA((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); ((__builtin_constant_p((ioaddr+0x04)) && (ioaddr +0x04) < 256) ? __outwc((0x0004),(ioaddr+0x04)) : __outw(( 0x0004),(ioaddr+0x04))); /* Temporarily stop the depca. */ |
1740 | depca_init_ring(dev); /* Initialize the descriptor rings */ |
1741 | lp->init_block.mode |= PROM0x8000; /* Set promiscuous mode */ |
1742 | |
1743 | LoadCSRs(dev); /* Reload CSR3 */ |
1744 | InitRestartDepca(dev); /* Resume normal operation. */ |
1745 | dev->tbusy = 0; /* Unlock the TX ring */ |
1746 | } else { |
1747 | status = -EPERM1; |
1748 | } |
1749 | |
1750 | break; |
1751 | case DEPCA_CLR_PROM0x04: /* Clear Promiscuous Mode */ |
1752 | if (suser()) { |
1753 | while(dev->tbusy); /* Stop ring access */ |
1754 | set_bit(0, (void*)&dev->tbusy); |
1755 | while(lp->tx_old != lp->tx_new); /* Wait for the ring to empty */ |
1756 | |
1757 | STOP_DEPCA((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); ((__builtin_constant_p((ioaddr+0x04)) && (ioaddr +0x04) < 256) ? __outwc((0x0004),(ioaddr+0x04)) : __outw(( 0x0004),(ioaddr+0x04))); /* Temporarily stop the depca. */ |
1758 | depca_init_ring(dev); /* Initialize the descriptor rings */ |
1759 | lp->init_block.mode &= ~PROM0x8000; /* Clear promiscuous mode */ |
1760 | |
1761 | LoadCSRs(dev); /* Reload CSR3 */ |
1762 | InitRestartDepca(dev); /* Resume normal operation. */ |
1763 | dev->tbusy = 0; /* Unlock the TX ring */ |
1764 | } else { |
1765 | status = -EPERM1; |
1766 | } |
1767 | |
1768 | break; |
1769 | case DEPCA_SAY_BOO0x05: /* Say "Boo!" to the kernel log file */ |
1770 | printk("%s: Boo!\n", dev->name); |
1771 | |
1772 | break; |
1773 | case DEPCA_GET_MCA0x06: /* Get the multicast address table */ |
1774 | ioc->len = (HASH_TABLE_LEN64 >> 3); |
1775 | if (!(status = verify_area(VERIFY_WRITE1, ioc->data, ioc->len))) { |
1776 | memcpy_tofs(ioc->data, lp->init_block.mcast_table, ioc->len); |
1777 | } |
1778 | |
1779 | break; |
1780 | case DEPCA_SET_MCA0x07: /* Set a multicast address */ |
1781 | if (suser()) { |
1782 | if (!(status=verify_area(VERIFY_READ0, ioc->data, ETH_ALEN6*ioc->len))) { |
1783 | memcpy_fromfs(tmp.addr, ioc->data, ETH_ALEN6 * ioc->len); |
1784 | set_multicast_list(dev); |
1785 | } |
1786 | } else { |
1787 | status = -EPERM1; |
1788 | } |
1789 | |
1790 | break; |
1791 | case DEPCA_CLR_MCA0x08: /* Clear all multicast addresses */ |
1792 | if (suser()) { |
1793 | set_multicast_list(dev); |
1794 | } else { |
1795 | status = -EPERM1; |
1796 | } |
1797 | |
1798 | break; |
1799 | case DEPCA_MCA_EN0x09: /* Enable pass all multicast addressing */ |
1800 | if (suser()) { |
1801 | set_multicast_list(dev); |
1802 | } else { |
1803 | status = -EPERM1; |
1804 | } |
1805 | |
1806 | break; |
1807 | case DEPCA_GET_STATS0x0a: /* Get the driver statistics */ |
1808 | cli()__asm__ __volatile__ ("cli": : :"memory"); |
1809 | ioc->len = sizeof(lp->pktStats); |
1810 | if (!(status=verify_area(VERIFY_WRITE1, ioc->data, ioc->len))) { |
1811 | memcpy_tofs(ioc->data, &lp->pktStats, ioc->len); |
1812 | } |
1813 | sti()__asm__ __volatile__ ("sti": : :"memory"); |
1814 | |
1815 | break; |
1816 | case DEPCA_CLR_STATS0x0b: /* Zero out the driver statistics */ |
1817 | if (suser()) { |
1818 | cli()__asm__ __volatile__ ("cli": : :"memory"); |
1819 | memset(&lp->pktStats, 0, sizeof(lp->pktStats))(__builtin_constant_p(0) ? (__builtin_constant_p((sizeof(lp-> pktStats))) ? __constant_c_and_count_memset(((&lp->pktStats )),((0x01010101UL*(unsigned char)(0))),((sizeof(lp->pktStats )))) : __constant_c_memset(((&lp->pktStats)),((0x01010101UL *(unsigned char)(0))),((sizeof(lp->pktStats))))) : (__builtin_constant_p ((sizeof(lp->pktStats))) ? __memset_generic((((&lp-> pktStats))),(((0))),(((sizeof(lp->pktStats))))) : __memset_generic (((&lp->pktStats)),((0)),((sizeof(lp->pktStats))))) ); |
1820 | sti()__asm__ __volatile__ ("sti": : :"memory"); |
1821 | } else { |
1822 | status = -EPERM1; |
1823 | } |
1824 | |
1825 | break; |
1826 | case DEPCA_GET_REG0x0c: /* Get the DEPCA Registers */ |
1827 | i=0; |
1828 | tmp.sval[i++] = inw(DEPCA_NICSR)((__builtin_constant_p((ioaddr+0x00)) && (ioaddr+0x00 ) < 256) ? __inwc(ioaddr+0x00) : __inw(ioaddr+0x00)); |
1829 | outw(CSR0, DEPCA_ADDR)((__builtin_constant_p((ioaddr+0x06)) && (ioaddr+0x06 ) < 256) ? __outwc((0),(ioaddr+0x06)) : __outw((0),(ioaddr +0x06))); /* status register */ |
1830 | tmp.sval[i++] = inw(DEPCA_DATA)((__builtin_constant_p((ioaddr+0x04)) && (ioaddr+0x04 ) < 256) ? __inwc(ioaddr+0x04) : __inw(ioaddr+0x04)); |
1831 | memcpy(&tmp.sval[i], &lp->init_block, sizeof(struct depca_init))(__builtin_constant_p(sizeof(struct depca_init)) ? __constant_memcpy ((&tmp.sval[i]),(&lp->init_block),(sizeof(struct depca_init ))) : __memcpy((&tmp.sval[i]),(&lp->init_block),(sizeof (struct depca_init)))); |
1832 | ioc->len = i+sizeof(struct depca_init); |
1833 | if (!(status=verify_area(VERIFY_WRITE1, ioc->data, ioc->len))) { |
1834 | memcpy_tofs(ioc->data, tmp.addr, ioc->len); |
1835 | } |
1836 | |
1837 | break; |
1838 | default: |
1839 | status = -EOPNOTSUPP95; |
1840 | } |
1841 | |
1842 | return status; |
1843 | } |
1844 | |
1845 | #ifdef MODULE |
1846 | static char devicename[9] = { 0, }; |
1847 | static struct devicelinux_device thisDepca = { |
1848 | devicename, /* device name is inserted by /linux/drivers/net/net_init.c */ |
1849 | 0, 0, 0, 0, |
1850 | 0x200, 7, /* I/O address, IRQ */ |
1851 | 0, 0, 0, NULL((void *) 0), depca_probe }; |
1852 | |
1853 | static int irq=7; /* EDIT THESE LINE FOR YOUR CONFIGURATION */ |
1854 | static int io=0x200; /* Or use the irq= io= options to insmod */ |
1855 | |
1856 | /* See depca_probe() for autoprobe messages when a module */ |
1857 | int |
1858 | init_module(void) |
1859 | { |
1860 | thisDepca.irq=irq; |
1861 | thisDepca.base_addr=io; |
1862 | |
1863 | if (register_netdev(&thisDepca) != 0) |
1864 | return -EIO5; |
1865 | |
1866 | return 0; |
1867 | } |
1868 | |
1869 | void |
1870 | cleanup_module(void) |
1871 | { |
1872 | if (thisDepca.priv) { |
1873 | kfreelinux_kfree(thisDepca.priv); |
1874 | thisDepca.priv = NULL((void *) 0); |
1875 | } |
1876 | thisDepca.irq=0; |
1877 | |
1878 | unregister_netdev(&thisDepca); |
1879 | release_region(thisDepca.base_addr, DEPCA_TOTAL_SIZE0x10); |
1880 | } |
1881 | #endif /* MODULE */ |
1882 | |
1883 | |
1884 | /* |
1885 | * Local variables: |
1886 | * compile-command: "gcc -D__KERNEL__ -I/linux/include -Wall -Wstrict-prototypes -fomit-frame-pointer -fno-strength-reduce -malign-loops=2 -malign-jumps=2 -malign-functions=2 -O2 -m486 -c depca.c" |
1887 | * |
1888 | * compile-command: "gcc -D__KERNEL__ -DMODULE -I/linux/include -Wall -Wstrict-prototypes -fomit-frame-pointer -fno-strength-reduce -malign-loops=2 -malign-jumps=2 -malign-functions=2 -O2 -m486 -c depca.c" |
1889 | * End: |
1890 | */ |