PageRenderTime 77ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 1ms

/linux/src/drivers/net/depca.c

https://bitbucket.org/mischief/oskit
C | 2063 lines | 1302 code | 248 blank | 513 comment | 346 complexity | 8df5b2f9cfd83043b15740b0cb32a86e MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. /* depca.c: A DIGITAL DEPCA & EtherWORKS ethernet driver for linux.
  2. Written 1994, 1995 by David C. Davies.
  3. Copyright 1994 David C. Davies
  4. and
  5. United States Government
  6. (as represented by the Director, National Security Agency).
  7. Copyright 1995 Digital Equipment Corporation.
  8. This software may be used and distributed according to the terms of
  9. the GNU Public License, incorporated herein by reference.
  10. This driver is written for the Digital Equipment Corporation series
  11. of DEPCA and EtherWORKS ethernet cards:
  12. DEPCA (the original)
  13. DE100
  14. DE101
  15. DE200 Turbo
  16. DE201 Turbo
  17. DE202 Turbo (TP BNC)
  18. DE210
  19. DE422 (EISA)
  20. The driver has been tested on DE100, DE200 and DE202 cards in a
  21. relatively busy network. The DE422 has been tested a little.
  22. This driver will NOT work for the DE203, DE204 and DE205 series of
  23. cards, since they have a new custom ASIC in place of the AMD LANCE
  24. chip. See the 'ewrk3.c' driver in the Linux source tree for running
  25. those cards.
  26. I have benchmarked the driver with a DE100 at 595kB/s to (542kB/s from)
  27. a DECstation 5000/200.
  28. The author may be reached at davies@maniac.ultranet.com
  29. =========================================================================
  30. The driver was originally based on the 'lance.c' driver from Donald
  31. Becker which is included with the standard driver distribution for
  32. linux. V0.4 is a complete re-write with only the kernel interface
  33. remaining from the original code.
  34. 1) Lance.c code in /linux/drivers/net/
  35. 2) "Ethernet/IEEE 802.3 Family. 1992 World Network Data Book/Handbook",
  36. AMD, 1992 [(800) 222-9323].
  37. 3) "Am79C90 CMOS Local Area Network Controller for Ethernet (C-LANCE)",
  38. AMD, Pub. #17881, May 1993.
  39. 4) "Am79C960 PCnet-ISA(tm), Single-Chip Ethernet Controller for ISA",
  40. AMD, Pub. #16907, May 1992
  41. 5) "DEC EtherWORKS LC Ethernet Controller Owners Manual",
  42. Digital Equipment corporation, 1990, Pub. #EK-DE100-OM.003
  43. 6) "DEC EtherWORKS Turbo Ethernet Controller Owners Manual",
  44. Digital Equipment corporation, 1990, Pub. #EK-DE200-OM.003
  45. 7) "DEPCA Hardware Reference Manual", Pub. #EK-DEPCA-PR
  46. Digital Equipment Corporation, 1989
  47. 8) "DEC EtherWORKS Turbo_(TP BNC) Ethernet Controller Owners Manual",
  48. Digital Equipment corporation, 1991, Pub. #EK-DE202-OM.001
  49. Peter Bauer's depca.c (V0.5) was referred to when debugging V0.1 of this
  50. driver.
  51. The original DEPCA card requires that the ethernet ROM address counter
  52. be enabled to count and has an 8 bit NICSR. The ROM counter enabling is
  53. only done when a 0x08 is read as the first address octet (to minimise
  54. the chances of writing over some other hardware's I/O register). The
  55. NICSR accesses have been changed to byte accesses for all the cards
  56. supported by this driver, since there is only one useful bit in the MSB
  57. (remote boot timeout) and it is not used. Also, there is a maximum of
  58. only 48kB network RAM for this card. My thanks to Torbjorn Lindh for
  59. help debugging all this (and holding my feet to the fire until I got it
  60. right).
  61. The DE200 series boards have on-board 64kB RAM for use as a shared
  62. memory network buffer. Only the DE100 cards make use of a 2kB buffer
  63. mode which has not been implemented in this driver (only the 32kB and
  64. 64kB modes are supported [16kB/48kB for the original DEPCA]).
  65. At the most only 2 DEPCA cards can be supported on the ISA bus because
  66. there is only provision for two I/O base addresses on each card (0x300
  67. and 0x200). The I/O address is detected by searching for a byte sequence
  68. in the Ethernet station address PROM at the expected I/O address for the
  69. Ethernet PROM. The shared memory base address is 'autoprobed' by
  70. looking for the self test PROM and detecting the card name. When a
  71. second DEPCA is detected, information is placed in the base_addr
  72. variable of the next device structure (which is created if necessary),
  73. thus enabling ethif_probe initialization for the device. More than 2
  74. EISA cards can be supported, but care will be needed assigning the
  75. shared memory to ensure that each slot has the correct IRQ, I/O address
  76. and shared memory address assigned.
  77. ************************************************************************
  78. NOTE: If you are using two ISA DEPCAs, it is important that you assign
  79. the base memory addresses correctly. The driver autoprobes I/O 0x300
  80. then 0x200. The base memory address for the first device must be less
  81. than that of the second so that the auto probe will correctly assign the
  82. I/O and memory addresses on the same card. I can't think of a way to do
  83. this unambiguously at the moment, since there is nothing on the cards to
  84. tie I/O and memory information together.
  85. I am unable to test 2 cards together for now, so this code is
  86. unchecked. All reports, good or bad, are welcome.
  87. ************************************************************************
  88. The board IRQ setting must be at an unused IRQ which is auto-probed
  89. using Donald Becker's autoprobe routines. DEPCA and DE100 board IRQs are
  90. {2,3,4,5,7}, whereas the DE200 is at {5,9,10,11,15}. Note that IRQ2 is
  91. really IRQ9 in machines with 16 IRQ lines.
  92. No 16MB memory limitation should exist with this driver as DMA is not
  93. used and the common memory area is in low memory on the network card (my
  94. current system has 20MB and I've not had problems yet).
  95. The ability to load this driver as a loadable module has been added. To
  96. utilise this ability, you have to do <8 things:
  97. 0) have a copy of the loadable modules code installed on your system.
  98. 1) copy depca.c from the /linux/drivers/net directory to your favourite
  99. temporary directory.
  100. 2) if you wish, edit the source code near line 1530 to reflect the I/O
  101. address and IRQ you're using (see also 5).
  102. 3) compile depca.c, but include -DMODULE in the command line to ensure
  103. that the correct bits are compiled (see end of source code).
  104. 4) if you are wanting to add a new card, goto 5. Otherwise, recompile a
  105. kernel with the depca configuration turned off and reboot.
  106. 5) insmod depca.o [irq=7] [io=0x200] [mem=0xd0000] [adapter_name=DE100]
  107. [Alan Cox: Changed the code to allow command line irq/io assignments]
  108. [Dave Davies: Changed the code to allow command line mem/name
  109. assignments]
  110. 6) run the net startup bits for your eth?? interface manually
  111. (usually /etc/rc.inet[12] at boot time).
  112. 7) enjoy!
  113. Note that autoprobing is not allowed in loadable modules - the system is
  114. already up and running and you're messing with interrupts.
  115. To unload a module, turn off the associated interface
  116. 'ifconfig eth?? down' then 'rmmod depca'.
  117. To assign a base memory address for the shared memory when running as a
  118. loadable module, see 5 above. To include the adapter name (if you have
  119. no PROM but know the card name) also see 5 above. Note that this last
  120. option will not work with kernel built-in depca's.
  121. The shared memory assignment for a loadable module makes sense to avoid
  122. the 'memory autoprobe' picking the wrong shared memory (for the case of
  123. 2 depca's in a PC).
  124. ************************************************************************
  125. Support for MCA EtherWORKS cards added 11-3-98.
  126. Verified to work with up to 2 DE212 cards in a system (although not
  127. fully stress-tested).
  128. Currently known bugs/limitations:
  129. Note: with the MCA stuff as a module, it trusts the MCA configuration,
  130. not the command line for IRQ and memory address. You can
  131. specify them if you want, but it will throw your values out.
  132. You still have to pass the IO address it was configured as
  133. though.
  134. ************************************************************************
  135. TO DO:
  136. ------
  137. Revision History
  138. ----------------
  139. Version Date Description
  140. 0.1 25-jan-94 Initial writing.
  141. 0.2 27-jan-94 Added LANCE TX hardware buffer chaining.
  142. 0.3 1-feb-94 Added multiple DEPCA support.
  143. 0.31 4-feb-94 Added DE202 recognition.
  144. 0.32 19-feb-94 Tidy up. Improve multi-DEPCA support.
  145. 0.33 25-feb-94 Fix DEPCA ethernet ROM counter enable.
  146. Add jabber packet fix from murf@perftech.com
  147. and becker@super.org
  148. 0.34 7-mar-94 Fix DEPCA max network memory RAM & NICSR access.
  149. 0.35 8-mar-94 Added DE201 recognition. Tidied up.
  150. 0.351 30-apr-94 Added EISA support. Added DE422 recognition.
  151. 0.36 16-may-94 DE422 fix released.
  152. 0.37 22-jul-94 Added MODULE support
  153. 0.38 15-aug-94 Added DBR ROM switch in depca_close().
  154. Multi DEPCA bug fix.
  155. 0.38axp 15-sep-94 Special version for Alpha AXP Linux V1.0.
  156. 0.381 12-dec-94 Added DE101 recognition, fix multicast bug.
  157. 0.382 9-feb-95 Fix recognition bug reported by <bkm@star.rl.ac.uk>.
  158. 0.383 22-feb-95 Fix for conflict with VESA SCSI reported by
  159. <stromain@alf.dec.com>
  160. 0.384 17-mar-95 Fix a ring full bug reported by <bkm@star.rl.ac.uk>
  161. 0.385 3-apr-95 Fix a recognition bug reported by
  162. <ryan.niemi@lastfrontier.com>
  163. 0.386 21-apr-95 Fix the last fix...sorry, must be galloping senility
  164. 0.40 25-May-95 Rewrite for portability & updated.
  165. ALPHA support from <jestabro@amt.tay1.dec.com>
  166. 0.41 26-Jun-95 Added verify_area() calls in depca_ioctl() from
  167. suggestion by <heiko@colossus.escape.de>
  168. 0.42 27-Dec-95 Add 'mem' shared memory assignment for loadable
  169. modules.
  170. Add 'adapter_name' for loadable modules when no PROM.
  171. Both above from a suggestion by
  172. <pchen@woodruffs121.residence.gatech.edu>.
  173. Add new multicasting code.
  174. 0.421 22-Apr-96 Fix alloc_device() bug <jari@markkus2.fimr.fi>
  175. 0.422 29-Apr-96 Fix depca_hw_init() bug <jari@markkus2.fimr.fi>
  176. 0.423 7-Jun-96 Fix module load bug <kmg@barco.be>
  177. 0.43 16-Aug-96 Update alloc_device() to conform to de4x5.c
  178. 0.44 1-Sep-97 Fix *_probe() to test check_region() first - bug
  179. reported by <mmogilvi@elbert.uccs.edu>
  180. 0.45 3-Nov-98 Added support for MCA EtherWORKS (DE210/DE212) cards
  181. by <tymm@computer.org>
  182. 0.451 5-Nov-98 Fixed mca stuff cuz I'm a dummy. <tymm@computer.org>
  183. 0.5 14-Nov-98 Re-spin for 2.1.x kernels.
  184. 0.51 27-Jun-99 Correct received packet length for CRC from
  185. report by <worm@dkik.dk>
  186. =========================================================================
  187. */
  188. static const char *version = "depca.c:v0.51 1999/6/27 davies@maniac.ultranet.com\n";
  189. #include <linux/config.h>
  190. #include <linux/module.h>
  191. #include <linux/kernel.h>
  192. #include <linux/sched.h>
  193. #include <linux/string.h>
  194. #include <linux/ptrace.h>
  195. #include <linux/errno.h>
  196. #include <linux/ioport.h>
  197. #include <linux/malloc.h>
  198. #include <linux/interrupt.h>
  199. #include <linux/delay.h>
  200. #include <linux/init.h>
  201. #include <asm/uaccess.h>
  202. #include <asm/bitops.h>
  203. #include <asm/io.h>
  204. #include <asm/dma.h>
  205. #include <linux/netdevice.h>
  206. #include <linux/etherdevice.h>
  207. #include <linux/skbuff.h>
  208. #include <linux/time.h>
  209. #include <linux/types.h>
  210. #include <linux/unistd.h>
  211. #include <linux/ctype.h>
  212. #ifdef CONFIG_MCA
  213. #include <linux/mca.h>
  214. #endif
  215. #include "depca.h"
  216. #ifdef DEPCA_DEBUG
  217. static int depca_debug = DEPCA_DEBUG;
  218. #else
  219. static int depca_debug = 1;
  220. #endif
  221. #define DEPCA_NDA 0xffe0 /* No Device Address */
  222. /*
  223. ** Ethernet PROM defines
  224. */
  225. #define PROBE_LENGTH 32
  226. #define ETH_PROM_SIG 0xAA5500FFUL
  227. /*
  228. ** Set the number of Tx and Rx buffers. Ensure that the memory requested
  229. ** here is <= to the amount of shared memory set up by the board switches.
  230. ** The number of descriptors MUST BE A POWER OF 2.
  231. **
  232. ** total_memory = NUM_RX_DESC*(8+RX_BUFF_SZ) + NUM_TX_DESC*(8+TX_BUFF_SZ)
  233. */
  234. #define NUM_RX_DESC 8 /* Number of RX descriptors */
  235. #define NUM_TX_DESC 8 /* Number of TX descriptors */
  236. #define RX_BUFF_SZ 1536 /* Buffer size for each Rx buffer */
  237. #define TX_BUFF_SZ 1536 /* Buffer size for each Tx buffer */
  238. #define CRC_POLYNOMIAL_BE 0x04c11db7UL /* Ethernet CRC, big endian */
  239. #define CRC_POLYNOMIAL_LE 0xedb88320UL /* Ethernet CRC, little endian */
  240. /*
  241. ** EISA bus defines
  242. */
  243. #define DEPCA_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */
  244. #define MAX_EISA_SLOTS 16
  245. #define EISA_SLOT_INC 0x1000
  246. /*
  247. ** ISA Bus defines
  248. */
  249. #define DEPCA_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0xe0000,0x00000}
  250. #define DEPCA_IO_PORTS {0x300, 0x200, 0}
  251. #define DEPCA_TOTAL_SIZE 0x10
  252. static short mem_chkd = 0;
  253. /*
  254. ** Adapter ID for the MCA EtherWORKS DE210/212 adapter
  255. */
  256. #define DE212_ID 0x6def
  257. /*
  258. ** Name <-> Adapter mapping
  259. */
  260. #define DEPCA_SIGNATURE {"DEPCA",\
  261. "DE100","DE101",\
  262. "DE200","DE201","DE202",\
  263. "DE210","DE212",\
  264. "DE422",\
  265. ""}
  266. static enum {
  267. DEPCA, de100, de101, de200, de201, de202, de210, de212, de422, unknown
  268. } adapter;
  269. /*
  270. ** Miscellaneous info...
  271. */
  272. #define DEPCA_STRLEN 16
  273. #define MAX_NUM_DEPCAS 2
  274. /*
  275. ** Memory Alignment. Each descriptor is 4 longwords long. To force a
  276. ** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and
  277. ** DESC_ALIGN. ALIGN aligns the start address of the private memory area
  278. ** and hence the RX descriptor ring's first entry.
  279. */
  280. #define ALIGN4 ((u_long)4 - 1) /* 1 longword align */
  281. #define ALIGN8 ((u_long)8 - 1) /* 2 longword (quadword) align */
  282. #define ALIGN ALIGN8 /* Keep the LANCE happy... */
  283. /*
  284. ** The DEPCA Rx and Tx ring descriptors.
  285. */
  286. struct depca_rx_desc {
  287. volatile s32 base;
  288. s16 buf_length; /* This length is negative 2's complement! */
  289. s16 msg_length; /* This length is "normal". */
  290. };
  291. struct depca_tx_desc {
  292. volatile s32 base;
  293. s16 length; /* This length is negative 2's complement! */
  294. s16 misc; /* Errors and TDR info */
  295. };
  296. #define LA_MASK 0x0000ffff /* LANCE address mask for mapping network RAM
  297. to LANCE memory address space */
  298. /*
  299. ** The Lance initialization block, described in databook, in common memory.
  300. */
  301. struct depca_init {
  302. u16 mode; /* Mode register */
  303. u8 phys_addr[ETH_ALEN]; /* Physical ethernet address */
  304. u8 mcast_table[8]; /* Multicast Hash Table. */
  305. u32 rx_ring; /* Rx ring base pointer & ring length */
  306. u32 tx_ring; /* Tx ring base pointer & ring length */
  307. };
  308. #define DEPCA_PKT_STAT_SZ 16
  309. #define DEPCA_PKT_BIN_SZ 128 /* Should be >=100 unless you
  310. increase DEPCA_PKT_STAT_SZ */
  311. struct depca_private {
  312. char devname[DEPCA_STRLEN]; /* Device Product String */
  313. char adapter_name[DEPCA_STRLEN];/* /proc/ioports string */
  314. char adapter; /* Adapter type */
  315. char mca_slot; /* MCA slot, if MCA else -1 */ struct depca_rx_desc *rx_ring; /* Pointer to start of RX descriptor ring */
  316. struct depca_tx_desc *tx_ring; /* Pointer to start of TX descriptor ring */
  317. struct depca_init init_block;/* Shadow Initialization block */
  318. char *rx_memcpy[NUM_RX_DESC]; /* CPU virt address of sh'd memory buffs */
  319. char *tx_memcpy[NUM_TX_DESC]; /* CPU virt address of sh'd memory buffs */
  320. u_long bus_offset; /* (E)ISA bus address offset vs LANCE */
  321. u_long sh_mem; /* Physical start addr of shared mem area */
  322. u_long dma_buffs; /* LANCE Rx and Tx buffers start address. */
  323. int rx_new, tx_new; /* The next free ring entry */
  324. int rx_old, tx_old; /* The ring entries to be free()ed. */
  325. struct net_device_stats stats;
  326. struct { /* Private stats counters */
  327. u32 bins[DEPCA_PKT_STAT_SZ];
  328. u32 unicast;
  329. u32 multicast;
  330. u32 broadcast;
  331. u32 excessive_collisions;
  332. u32 tx_underruns;
  333. u32 excessive_underruns;
  334. } pktStats;
  335. int txRingMask; /* TX ring mask */
  336. int rxRingMask; /* RX ring mask */
  337. s32 rx_rlen; /* log2(rxRingMask+1) for the descriptors */
  338. s32 tx_rlen; /* log2(txRingMask+1) for the descriptors */
  339. };
  340. /*
  341. ** The transmit ring full condition is described by the tx_old and tx_new
  342. ** pointers by:
  343. ** tx_old = tx_new Empty ring
  344. ** tx_old = tx_new+1 Full ring
  345. ** tx_old+txRingMask = tx_new Full ring (wrapped condition)
  346. */
  347. #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
  348. lp->tx_old+lp->txRingMask-lp->tx_new:\
  349. lp->tx_old -lp->tx_new-1)
  350. /*
  351. ** Public Functions
  352. */
  353. static int depca_open(struct device *dev);
  354. static int depca_start_xmit(struct sk_buff *skb, struct device *dev);
  355. static void depca_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  356. static int depca_close(struct device *dev);
  357. static int depca_ioctl(struct device *dev, struct ifreq *rq, int cmd);
  358. static struct net_device_stats *depca_get_stats(struct device *dev);
  359. static void set_multicast_list(struct device *dev);
  360. /*
  361. ** Private functions
  362. */
  363. static int depca_hw_init(struct device *dev, u_long ioaddr, int mca_slot);
  364. static void depca_init_ring(struct device *dev);
  365. static int depca_rx(struct device *dev);
  366. static int depca_tx(struct device *dev);
  367. static void LoadCSRs(struct device *dev);
  368. static int InitRestartDepca(struct device *dev);
  369. static void DepcaSignature(char *name, u_long paddr);
  370. static int DevicePresent(u_long ioaddr);
  371. static int get_hw_addr(struct device *dev);
  372. static int EISA_signature(char *name, s32 eisa_id);
  373. static void SetMulticastFilter(struct device *dev);
  374. static void isa_probe(struct device *dev, u_long iobase);
  375. static void eisa_probe(struct device *dev, u_long iobase);
  376. #ifdef CONFIG_MCA
  377. static void mca_probe(struct device *dev, u_long iobase);
  378. #endif
  379. static struct device *alloc_device(struct device *dev, u_long iobase);
  380. static int depca_dev_index(char *s);
  381. static struct device *insert_device(struct device *dev, u_long iobase, int (*init)(struct device *));
  382. static int load_packet(struct device *dev, struct sk_buff *skb);
  383. static void depca_dbg_open(struct device *dev);
  384. #ifdef MODULE
  385. int init_module(void);
  386. void cleanup_module(void);
  387. static int autoprobed = 1, loading_module = 1;
  388. # else
  389. static u_char de1xx_irq[] __initdata = {2,3,4,5,7,9,0};
  390. static u_char de2xx_irq[] __initdata = {5,9,10,11,15,0};
  391. static u_char de422_irq[] __initdata = {5,9,10,11,0};
  392. static u_char *depca_irq;
  393. static int autoprobed = 0, loading_module = 0;
  394. #endif /* MODULE */
  395. static char name[DEPCA_STRLEN];
  396. static int num_depcas = 0, num_eth = 0;
  397. static int mem=0; /* For loadable module assignment
  398. use insmod mem=0x????? .... */
  399. static char *adapter_name = '\0'; /* If no PROM when loadable module
  400. use insmod adapter_name=DE??? ...
  401. */
  402. /*
  403. ** Miscellaneous defines...
  404. */
  405. #define STOP_DEPCA \
  406. outw(CSR0, DEPCA_ADDR);\
  407. outw(STOP, DEPCA_DATA)
  408. __initfunc(int
  409. depca_probe(struct device *dev))
  410. {
  411. int tmp = num_depcas, status = -ENODEV;
  412. u_long iobase = dev->base_addr;
  413. if ((iobase == 0) && loading_module){
  414. printk("Autoprobing is not supported when loading a module based driver.\n");
  415. status = -EIO;
  416. } else {
  417. #ifdef CONFIG_MCA
  418. mca_probe(dev, iobase);
  419. #endif
  420. isa_probe(dev, iobase);
  421. eisa_probe(dev, iobase);
  422. if ((tmp == num_depcas) && (iobase != 0) && loading_module) {
  423. printk("%s: depca_probe() cannot find device at 0x%04lx.\n", dev->name,
  424. iobase);
  425. }
  426. /*
  427. ** Walk the device list to check that at least one device
  428. ** initialised OK
  429. */
  430. for (; (dev->priv == NULL) && (dev->next != NULL); dev = dev->next);
  431. if (dev->priv) status = 0;
  432. if (iobase == 0) autoprobed = 1;
  433. }
  434. return status;
  435. }
  436. __initfunc(static int
  437. depca_hw_init(struct device *dev, u_long ioaddr, int mca_slot))
  438. {
  439. struct depca_private *lp;
  440. int i, j, offset, netRAM, mem_len, status=0;
  441. s16 nicsr;
  442. u_long mem_start=0, mem_base[] = DEPCA_RAM_BASE_ADDRESSES;
  443. STOP_DEPCA;
  444. nicsr = inb(DEPCA_NICSR);
  445. nicsr = ((nicsr & ~SHE & ~RBE & ~IEN) | IM);
  446. outb(nicsr, DEPCA_NICSR);
  447. if (inw(DEPCA_DATA) == STOP) {
  448. do {
  449. strcpy(name, (adapter_name ? adapter_name : ""));
  450. mem_start = (mem ? mem & 0xf0000 : mem_base[mem_chkd++]);
  451. DepcaSignature(name, mem_start);
  452. } while (!mem && mem_base[mem_chkd] && (adapter == unknown));
  453. if ((adapter != unknown) && mem_start) { /* found a DEPCA device */
  454. dev->base_addr = ioaddr;
  455. if (mca_slot != -1) {
  456. printk("%s: %s at 0x%04lx (MCA slot %d)", dev->name, name,
  457. ioaddr, mca_slot);
  458. } else if ((ioaddr & 0x0fff) == DEPCA_EISA_IO_PORTS) { /* EISA slot address */
  459. printk("%s: %s at 0x%04lx (EISA slot %d)",
  460. dev->name, name, ioaddr, (int)((ioaddr>>12)&0x0f));
  461. } else { /* ISA port address */
  462. printk("%s: %s at 0x%04lx", dev->name, name, ioaddr);
  463. }
  464. printk(", h/w address ");
  465. status = get_hw_addr(dev);
  466. for (i=0; i<ETH_ALEN - 1; i++) { /* get the ethernet address */
  467. printk("%2.2x:", dev->dev_addr[i]);
  468. }
  469. printk("%2.2x", dev->dev_addr[i]);
  470. if (status == 0) {
  471. /* Set up the maximum amount of network RAM(kB) */
  472. netRAM = ((adapter != DEPCA) ? 64 : 48);
  473. if ((nicsr & _128KB) && (adapter == de422)) netRAM = 128;
  474. offset = 0x0000;
  475. /* Shared Memory Base Address */
  476. if (nicsr & BUF) {
  477. offset = 0x8000; /* 32kbyte RAM offset*/
  478. nicsr &= ~BS; /* DEPCA RAM in top 32k */
  479. netRAM -= 32;
  480. }
  481. mem_start += offset; /* (E)ISA start address */
  482. if ((mem_len = (NUM_RX_DESC*(sizeof(struct depca_rx_desc)+RX_BUFF_SZ) +
  483. NUM_TX_DESC*(sizeof(struct depca_tx_desc)+TX_BUFF_SZ) +
  484. sizeof(struct depca_init))) <=
  485. (netRAM<<10)) {
  486. printk(",\n has %dkB RAM at 0x%.5lx", netRAM, mem_start);
  487. /* Enable the shadow RAM. */
  488. if (adapter != DEPCA) {
  489. nicsr |= SHE;
  490. outb(nicsr, DEPCA_NICSR);
  491. }
  492. /* Define the device private memory */
  493. dev->priv = (void *) kmalloc(sizeof(struct depca_private), GFP_KERNEL);
  494. if (dev->priv == NULL)
  495. return -ENOMEM;
  496. lp = (struct depca_private *)dev->priv;
  497. memset((char *)dev->priv, 0, sizeof(struct depca_private));
  498. lp->adapter = adapter;
  499. lp->mca_slot = mca_slot;
  500. sprintf(lp->adapter_name,"%s (%s)", name, dev->name);
  501. request_region(ioaddr, DEPCA_TOTAL_SIZE, lp->adapter_name);
  502. /* Initialisation Block */
  503. lp->sh_mem = mem_start;
  504. mem_start += sizeof(struct depca_init);
  505. /* Tx & Rx descriptors (aligned to a quadword boundary) */
  506. mem_start = (mem_start + ALIGN) & ~ALIGN;
  507. lp->rx_ring = (struct depca_rx_desc *)mem_start;
  508. mem_start += (sizeof(struct depca_rx_desc) * NUM_RX_DESC);
  509. lp->tx_ring = (struct depca_tx_desc *)mem_start;
  510. mem_start += (sizeof(struct depca_tx_desc) * NUM_TX_DESC);
  511. lp->bus_offset = mem_start & 0x00ff0000;
  512. mem_start &= LA_MASK; /* LANCE re-mapped start address */
  513. lp->dma_buffs = mem_start;
  514. /* Finish initialising the ring information. */
  515. lp->rxRingMask = NUM_RX_DESC - 1;
  516. lp->txRingMask = NUM_TX_DESC - 1;
  517. /* Calculate Tx/Rx RLEN size for the descriptors. */
  518. for (i=0, j = lp->rxRingMask; j>0; i++) {
  519. j >>= 1;
  520. }
  521. lp->rx_rlen = (s32)(i << 29);
  522. for (i=0, j = lp->txRingMask; j>0; i++) {
  523. j >>= 1;
  524. }
  525. lp->tx_rlen = (s32)(i << 29);
  526. /* Load the initialisation block */
  527. depca_init_ring(dev);
  528. /* Initialise the control and status registers */
  529. LoadCSRs(dev);
  530. /* Enable DEPCA board interrupts for autoprobing */
  531. nicsr = ((nicsr & ~IM)|IEN);
  532. outb(nicsr, DEPCA_NICSR);
  533. /* To auto-IRQ we enable the initialization-done and DMA err,
  534. interrupts. For now we will always get a DMA error. */
  535. if (dev->irq < 2) {
  536. #ifndef MODULE
  537. unsigned char irqnum;
  538. autoirq_setup(0);
  539. /* Assign the correct irq list */
  540. switch (lp->adapter) {
  541. case DEPCA:
  542. case de100:
  543. case de101:
  544. depca_irq = de1xx_irq;
  545. break;
  546. case de200:
  547. case de201:
  548. case de202:
  549. case de210:
  550. case de212:
  551. depca_irq = de2xx_irq;
  552. break;
  553. case de422:
  554. depca_irq = de422_irq;
  555. break;
  556. }
  557. /* Trigger an initialization just for the interrupt. */
  558. outw(INEA | INIT, DEPCA_DATA);
  559. irqnum = autoirq_report(1);
  560. if (!irqnum) {
  561. printk(" and failed to detect IRQ line.\n");
  562. status = -ENXIO;
  563. } else {
  564. for (dev->irq=0,i=0; (depca_irq[i]) && (!dev->irq); i++) {
  565. if (irqnum == depca_irq[i]) {
  566. dev->irq = irqnum;
  567. printk(" and uses IRQ%d.\n", dev->irq);
  568. }
  569. }
  570. if (!dev->irq) {
  571. printk(" but incorrect IRQ line detected.\n");
  572. status = -ENXIO;
  573. }
  574. }
  575. #endif /* MODULE */
  576. } else {
  577. printk(" and assigned IRQ%d.\n", dev->irq);
  578. }
  579. if (status) release_region(ioaddr, DEPCA_TOTAL_SIZE);
  580. } else {
  581. printk(",\n requests %dkB RAM: only %dkB is available!\n",
  582. (mem_len>>10), netRAM);
  583. status = -ENXIO;
  584. }
  585. } else {
  586. printk(" which has an Ethernet PROM CRC error.\n");
  587. status = -ENXIO;
  588. }
  589. } else {
  590. status = -ENXIO;
  591. }
  592. if (!status) {
  593. if (depca_debug > 1) {
  594. printk(version);
  595. }
  596. /* The DEPCA-specific entries in the device structure. */
  597. dev->open = &depca_open;
  598. dev->hard_start_xmit = &depca_start_xmit;
  599. dev->stop = &depca_close;
  600. dev->get_stats = &depca_get_stats;
  601. dev->set_multicast_list = &set_multicast_list;
  602. dev->do_ioctl = &depca_ioctl;
  603. dev->mem_start = 0;
  604. /* Fill in the generic field of the device structure. */
  605. ether_setup(dev);
  606. } else { /* Incorrectly initialised hardware */
  607. if (dev->priv) {
  608. kfree_s(dev->priv, sizeof(struct depca_private));
  609. dev->priv = NULL;
  610. }
  611. }
  612. } else {
  613. status = -ENXIO;
  614. }
  615. return status;
  616. }
  617. static int
  618. depca_open(struct device *dev)
  619. {
  620. struct depca_private *lp = (struct depca_private *)dev->priv;
  621. u_long ioaddr = dev->base_addr;
  622. s16 nicsr;
  623. int status = 0;
  624. STOP_DEPCA;
  625. nicsr = inb(DEPCA_NICSR);
  626. /* Make sure the shadow RAM is enabled */
  627. if (adapter != DEPCA) {
  628. nicsr |= SHE;
  629. outb(nicsr, DEPCA_NICSR);
  630. }
  631. /* Re-initialize the DEPCA... */
  632. depca_init_ring(dev);
  633. LoadCSRs(dev);
  634. depca_dbg_open(dev);
  635. if (request_irq(dev->irq, &depca_interrupt, 0, lp->adapter_name, dev)) {
  636. printk("depca_open(): Requested IRQ%d is busy\n",dev->irq);
  637. status = -EAGAIN;
  638. } else {
  639. /* Enable DEPCA board interrupts and turn off LED */
  640. nicsr = ((nicsr & ~IM & ~LED)|IEN);
  641. outb(nicsr, DEPCA_NICSR);
  642. outw(CSR0,DEPCA_ADDR);
  643. dev->tbusy = 0;
  644. dev->interrupt = 0;
  645. dev->start = 1;
  646. status = InitRestartDepca(dev);
  647. if (depca_debug > 1){
  648. printk("CSR0: 0x%4.4x\n",inw(DEPCA_DATA));
  649. printk("nicsr: 0x%02x\n",inb(DEPCA_NICSR));
  650. }
  651. }
  652. MOD_INC_USE_COUNT;
  653. return status;
  654. }
  655. /* Initialize the lance Rx and Tx descriptor rings. */
  656. static void
  657. depca_init_ring(struct device *dev)
  658. {
  659. struct depca_private *lp = (struct depca_private *)dev->priv;
  660. u_int i;
  661. u_long p;
  662. /* Lock out other processes whilst setting up the hardware */
  663. test_and_set_bit(0, (void *)&dev->tbusy);
  664. lp->rx_new = lp->tx_new = 0;
  665. lp->rx_old = lp->tx_old = 0;
  666. /* Initialize the base addresses and length of each buffer in the ring */
  667. for (i = 0; i <= lp->rxRingMask; i++) {
  668. writel((p=lp->dma_buffs+i*RX_BUFF_SZ) | R_OWN, &lp->rx_ring[i].base);
  669. writew(-RX_BUFF_SZ, &lp->rx_ring[i].buf_length);
  670. lp->rx_memcpy[i]=(char *)(p+lp->bus_offset);
  671. }
  672. for (i = 0; i <= lp->txRingMask; i++) {
  673. writel((p=lp->dma_buffs+(i+lp->txRingMask+1)*TX_BUFF_SZ) & 0x00ffffff,
  674. &lp->tx_ring[i].base);
  675. lp->tx_memcpy[i]=(char *)(p+lp->bus_offset);
  676. }
  677. /* Set up the initialization block */
  678. lp->init_block.rx_ring = ((u32)((u_long)lp->rx_ring)&LA_MASK) | lp->rx_rlen;
  679. lp->init_block.tx_ring = ((u32)((u_long)lp->tx_ring)&LA_MASK) | lp->tx_rlen;
  680. SetMulticastFilter(dev);
  681. for (i = 0; i < ETH_ALEN; i++) {
  682. lp->init_block.phys_addr[i] = dev->dev_addr[i];
  683. }
  684. lp->init_block.mode = 0x0000; /* Enable the Tx and Rx */
  685. return;
  686. }
  687. /*
  688. ** Writes a socket buffer to TX descriptor ring and starts transmission
  689. */
  690. static int
  691. depca_start_xmit(struct sk_buff *skb, struct device *dev)
  692. {
  693. struct depca_private *lp = (struct depca_private *)dev->priv;
  694. u_long ioaddr = dev->base_addr;
  695. int status = 0;
  696. /* Transmitter timeout, serious problems. */
  697. if (dev->tbusy) {
  698. int tickssofar = jiffies - dev->trans_start;
  699. if (tickssofar < 1*HZ) {
  700. status = -1;
  701. } else {
  702. printk("%s: transmit timed out, status %04x, resetting.\n",
  703. dev->name, inw(DEPCA_DATA));
  704. STOP_DEPCA;
  705. depca_init_ring(dev);
  706. LoadCSRs(dev);
  707. dev->interrupt = UNMASK_INTERRUPTS;
  708. dev->start = 1;
  709. dev->tbusy=0;
  710. dev->trans_start = jiffies;
  711. InitRestartDepca(dev);
  712. }
  713. return status;
  714. } else if (skb->len > 0) {
  715. /* Enforce 1 process per h/w access */
  716. if (test_and_set_bit(0, (void*)&dev->tbusy) != 0) {
  717. printk("%s: Transmitter access conflict.\n", dev->name);
  718. status = -1;
  719. } else {
  720. if (TX_BUFFS_AVAIL) { /* Fill in a Tx ring entry */
  721. status = load_packet(dev, skb);
  722. if (!status) {
  723. /* Trigger an immediate send demand. */
  724. outw(CSR0, DEPCA_ADDR);
  725. outw(INEA | TDMD, DEPCA_DATA);
  726. dev->trans_start = jiffies;
  727. dev_kfree_skb(skb);
  728. }
  729. if (TX_BUFFS_AVAIL) {
  730. dev->tbusy=0;
  731. }
  732. } else {
  733. status = -1;
  734. }
  735. }
  736. }
  737. return status;
  738. }
  739. /*
  740. ** The DEPCA interrupt handler.
  741. */
  742. static void
  743. depca_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  744. {
  745. struct device *dev = dev_id;
  746. struct depca_private *lp;
  747. s16 csr0, nicsr;
  748. u_long ioaddr;
  749. if (dev == NULL) {
  750. printk ("depca_interrupt(): irq %d for unknown device.\n", irq);
  751. } else {
  752. lp = (struct depca_private *)dev->priv;
  753. ioaddr = dev->base_addr;
  754. if (dev->interrupt)
  755. printk("%s: Re-entering the interrupt handler.\n", dev->name);
  756. dev->interrupt = MASK_INTERRUPTS;
  757. /* mask the DEPCA board interrupts and turn on the LED */
  758. nicsr = inb(DEPCA_NICSR);
  759. nicsr |= (IM|LED);
  760. outb(nicsr, DEPCA_NICSR);
  761. outw(CSR0, DEPCA_ADDR);
  762. csr0 = inw(DEPCA_DATA);
  763. /* Acknowledge all of the current interrupt sources ASAP. */
  764. outw(csr0 & INTE, DEPCA_DATA);
  765. if (csr0 & RINT) /* Rx interrupt (packet arrived) */
  766. depca_rx(dev);
  767. if (csr0 & TINT) /* Tx interrupt (packet sent) */
  768. depca_tx(dev);
  769. if ((TX_BUFFS_AVAIL >= 0) && dev->tbusy) { /* any resources available? */
  770. dev->tbusy = 0; /* clear TX busy flag */
  771. mark_bh(NET_BH);
  772. }
  773. /* Unmask the DEPCA board interrupts and turn off the LED */
  774. nicsr = (nicsr & ~IM & ~LED);
  775. outb(nicsr, DEPCA_NICSR);
  776. dev->interrupt = UNMASK_INTERRUPTS;
  777. }
  778. return;
  779. }
  780. static int
  781. depca_rx(struct device *dev)
  782. {
  783. struct depca_private *lp = (struct depca_private *)dev->priv;
  784. int i, entry;
  785. s32 status;
  786. for (entry=lp->rx_new;
  787. !(readl(&lp->rx_ring[entry].base) & R_OWN);
  788. entry=lp->rx_new){
  789. status = readl(&lp->rx_ring[entry].base) >> 16 ;
  790. if (status & R_STP) { /* Remember start of frame */
  791. lp->rx_old = entry;
  792. }
  793. if (status & R_ENP) { /* Valid frame status */
  794. if (status & R_ERR) { /* There was an error. */
  795. lp->stats.rx_errors++; /* Update the error stats. */
  796. if (status & R_FRAM) lp->stats.rx_frame_errors++;
  797. if (status & R_OFLO) lp->stats.rx_over_errors++;
  798. if (status & R_CRC) lp->stats.rx_crc_errors++;
  799. if (status & R_BUFF) lp->stats.rx_fifo_errors++;
  800. } else {
  801. short len, pkt_len = readw(&lp->rx_ring[entry].msg_length) - 4;
  802. struct sk_buff *skb;
  803. skb = dev_alloc_skb(pkt_len+2);
  804. if (skb != NULL) {
  805. unsigned char *buf;
  806. skb_reserve(skb,2); /* 16 byte align the IP header */
  807. buf = skb_put(skb,pkt_len);
  808. skb->dev = dev;
  809. if (entry < lp->rx_old) { /* Wrapped buffer */
  810. len = (lp->rxRingMask - lp->rx_old + 1) * RX_BUFF_SZ;
  811. memcpy_fromio(buf, lp->rx_memcpy[lp->rx_old], len);
  812. memcpy_fromio(buf + len, lp->rx_memcpy[0], pkt_len-len);
  813. } else { /* Linear buffer */
  814. memcpy_fromio(buf, lp->rx_memcpy[lp->rx_old], pkt_len);
  815. }
  816. /*
  817. ** Notify the upper protocol layers that there is another
  818. ** packet to handle
  819. */
  820. skb->protocol=eth_type_trans(skb,dev);
  821. netif_rx(skb);
  822. /*
  823. ** Update stats
  824. */
  825. lp->stats.rx_packets++;
  826. for (i=1; i<DEPCA_PKT_STAT_SZ-1; i++) {
  827. if (pkt_len < (i*DEPCA_PKT_BIN_SZ)) {
  828. lp->pktStats.bins[i]++;
  829. i = DEPCA_PKT_STAT_SZ;
  830. }
  831. }
  832. if (buf[0] & 0x01) { /* Multicast/Broadcast */
  833. if ((*(s16 *)&buf[0] == -1) &&
  834. (*(s16 *)&buf[2] == -1) &&
  835. (*(s16 *)&buf[4] == -1)) {
  836. lp->pktStats.broadcast++;
  837. } else {
  838. lp->pktStats.multicast++;
  839. }
  840. } else if ((*(s16 *)&buf[0] == *(s16 *)&dev->dev_addr[0]) &&
  841. (*(s16 *)&buf[2] == *(s16 *)&dev->dev_addr[2]) &&
  842. (*(s16 *)&buf[4] == *(s16 *)&dev->dev_addr[4])) {
  843. lp->pktStats.unicast++;
  844. }
  845. lp->pktStats.bins[0]++; /* Duplicates stats.rx_packets */
  846. if (lp->pktStats.bins[0] == 0) { /* Reset counters */
  847. memset((char *)&lp->pktStats, 0, sizeof(lp->pktStats));
  848. }
  849. } else {
  850. printk("%s: Memory squeeze, deferring packet.\n", dev->name);
  851. lp->stats.rx_dropped++; /* Really, deferred. */
  852. break;
  853. }
  854. }
  855. /* Change buffer ownership for this last frame, back to the adapter */
  856. for (; lp->rx_old!=entry; lp->rx_old=(++lp->rx_old)&lp->rxRingMask) {
  857. writel(readl(&lp->rx_ring[lp->rx_old].base) | R_OWN,
  858. &lp->rx_ring[lp->rx_old].base);
  859. }
  860. writel(readl(&lp->rx_ring[entry].base) | R_OWN, &lp->rx_ring[entry].base);
  861. }
  862. /*
  863. ** Update entry information
  864. */
  865. lp->rx_new = (++lp->rx_new) & lp->rxRingMask;
  866. }
  867. return 0;
  868. }
  869. /*
  870. ** Buffer sent - check for buffer errors.
  871. */
  872. static int
  873. depca_tx(struct device *dev)
  874. {
  875. struct depca_private *lp = (struct depca_private *)dev->priv;
  876. int entry;
  877. s32 status;
  878. u_long ioaddr = dev->base_addr;
  879. for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) {
  880. status = readl(&lp->tx_ring[entry].base) >> 16 ;
  881. if (status < 0) { /* Packet not yet sent! */
  882. break;
  883. } else if (status & T_ERR) { /* An error occurred. */
  884. status = readl(&lp->tx_ring[entry].misc);
  885. lp->stats.tx_errors++;
  886. if (status & TMD3_RTRY) lp->stats.tx_aborted_errors++;
  887. if (status & TMD3_LCAR) lp->stats.tx_carrier_errors++;
  888. if (status & TMD3_LCOL) lp->stats.tx_window_errors++;
  889. if (status & TMD3_UFLO) lp->stats.tx_fifo_errors++;
  890. if (status & (TMD3_BUFF | TMD3_UFLO)) {
  891. /* Trigger an immediate send demand. */
  892. outw(CSR0, DEPCA_ADDR);
  893. outw(INEA | TDMD, DEPCA_DATA);
  894. }
  895. } else if (status & (T_MORE | T_ONE)) {
  896. lp->stats.collisions++;
  897. } else {
  898. lp->stats.tx_packets++;
  899. }
  900. /* Update all the pointers */
  901. lp->tx_old = (++lp->tx_old) & lp->txRingMask;
  902. }
  903. return 0;
  904. }
  905. static int
  906. depca_close(struct device *dev)
  907. {
  908. struct depca_private *lp = (struct depca_private *)dev->priv;
  909. s16 nicsr;
  910. u_long ioaddr = dev->base_addr;
  911. dev->start = 0;
  912. dev->tbusy = 1;
  913. outw(CSR0, DEPCA_ADDR);
  914. if (depca_debug > 1) {
  915. printk("%s: Shutting down ethercard, status was %2.2x.\n",
  916. dev->name, inw(DEPCA_DATA));
  917. }
  918. /*
  919. ** We stop the DEPCA here -- it occasionally polls
  920. ** memory if we don't.
  921. */
  922. outw(STOP, DEPCA_DATA);
  923. /*
  924. ** Give back the ROM in case the user wants to go to DOS
  925. */
  926. if (lp->adapter != DEPCA) {
  927. nicsr = inb(DEPCA_NICSR);
  928. nicsr &= ~SHE;
  929. outb(nicsr, DEPCA_NICSR);
  930. }
  931. /*
  932. ** Free the associated irq
  933. */
  934. free_irq(dev->irq, dev);
  935. MOD_DEC_USE_COUNT;
  936. return 0;
  937. }
  938. static void LoadCSRs(struct device *dev)
  939. {
  940. struct depca_private *lp = (struct depca_private *)dev->priv;
  941. u_long ioaddr = dev->base_addr;
  942. outw(CSR1, DEPCA_ADDR); /* initialisation block address LSW */
  943. outw((u16)(lp->sh_mem & LA_MASK), DEPCA_DATA);
  944. outw(CSR2, DEPCA_ADDR); /* initialisation block address MSW */
  945. outw((u16)((lp->sh_mem & LA_MASK) >> 16), DEPCA_DATA);
  946. outw(CSR3, DEPCA_ADDR); /* ALE control */
  947. outw(ACON, DEPCA_DATA);
  948. outw(CSR0, DEPCA_ADDR); /* Point back to CSR0 */
  949. return;
  950. }
  951. static int InitRestartDepca(struct device *dev)
  952. {
  953. struct depca_private *lp = (struct depca_private *)dev->priv;
  954. u_long ioaddr = dev->base_addr;
  955. int i, status=0;
  956. /* Copy the shadow init_block to shared memory */
  957. memcpy_toio((char *)lp->sh_mem, &lp->init_block, sizeof(struct depca_init));
  958. outw(CSR0, DEPCA_ADDR); /* point back to CSR0 */
  959. outw(INIT, DEPCA_DATA); /* initialize DEPCA */
  960. /* wait for lance to complete initialisation */
  961. for (i=0;(i<100) && !(inw(DEPCA_DATA) & IDON); i++);
  962. if (i!=100) {
  963. /* clear IDON by writing a "1", enable interrupts and start lance */
  964. outw(IDON | INEA | STRT, DEPCA_DATA);
  965. if (depca_debug > 2) {
  966. printk("%s: DEPCA open after %d ticks, init block 0x%08lx csr0 %4.4x.\n",
  967. dev->name, i, lp->sh_mem, inw(DEPCA_DATA));
  968. }
  969. } else {
  970. printk("%s: DEPCA unopen after %d ticks, init block 0x%08lx csr0 %4.4x.\n",
  971. dev->name, i, lp->sh_mem, inw(DEPCA_DATA));
  972. status = -1;
  973. }
  974. return status;
  975. }
  976. static struct net_device_stats *
  977. depca_get_stats(struct device *dev)
  978. {
  979. struct depca_private *lp = (struct depca_private *)dev->priv;
  980. /* Null body since there is no framing error counter */
  981. return &lp->stats;
  982. }
  983. /*
  984. ** Set or clear the multicast filter for this adaptor.
  985. */
  986. static void
  987. set_multicast_list(struct device *dev)
  988. {
  989. struct depca_private *lp = (struct depca_private *)dev->priv;
  990. u_long ioaddr = dev->base_addr;
  991. if (dev) {
  992. while(dev->tbusy) barrier(); /* Stop ring access */
  993. set_bit(0, (void*)&dev->tbusy);
  994. while(lp->tx_old != lp->tx_new); /* Wait for the ring to empty */
  995. STOP_DEPCA; /* Temporarily stop the depca. */
  996. depca_init_ring(dev); /* Initialize the descriptor rings */
  997. if (dev->flags & IFF_PROMISC) { /* Set promiscuous mode */
  998. lp->init_block.mode |= PROM;
  999. } else {
  1000. SetMulticastFilter(dev);
  1001. lp->init_block.mode &= ~PROM; /* Unset promiscuous mode */
  1002. }
  1003. LoadCSRs(dev); /* Reload CSR3 */
  1004. InitRestartDepca(dev); /* Resume normal operation. */
  1005. dev->tbusy = 0; /* Unlock the TX ring */
  1006. }
  1007. }
  1008. /*
  1009. ** Calculate the hash code and update the logical address filter
  1010. ** from a list of ethernet multicast addresses.
  1011. ** Big endian crc one liner is mine, all mine, ha ha ha ha!
  1012. ** LANCE calculates its hash codes big endian.
  1013. */
  1014. static void SetMulticastFilter(struct device *dev)
  1015. {
  1016. struct depca_private *lp = (struct depca_private *)dev->priv;
  1017. struct dev_mc_list *dmi=dev->mc_list;
  1018. char *addrs;
  1019. int i, j, bit, byte;
  1020. u16 hashcode;
  1021. s32 crc, poly = CRC_POLYNOMIAL_BE;
  1022. if (dev->flags & IFF_ALLMULTI) { /* Set all multicast bits */
  1023. for (i=0; i<(HASH_TABLE_LEN>>3); i++) {
  1024. lp->init_block.mcast_table[i] = (char)0xff;
  1025. }
  1026. } else {
  1027. for (i=0; i<(HASH_TABLE_LEN>>3); i++){ /* Clear the multicast table */
  1028. lp->init_block.mcast_table[i]=0;
  1029. }
  1030. /* Add multicast addresses */
  1031. for (i=0;i<dev->mc_count;i++) { /* for each address in the list */
  1032. addrs=dmi->dmi_addr;
  1033. dmi=dmi->next;
  1034. if ((*addrs & 0x01) == 1) { /* multicast address? */
  1035. crc = 0xffffffff; /* init CRC for each address */
  1036. for (byte=0;byte<ETH_ALEN;byte++) {/* for each address byte */
  1037. /* process each address bit */
  1038. for (bit = *addrs++,j=0;j<8;j++, bit>>=1) {
  1039. crc = (crc << 1) ^ ((((crc<0?1:0) ^ bit) & 0x01) ? poly : 0);
  1040. }
  1041. }
  1042. hashcode = (crc & 1); /* hashcode is 6 LSb of CRC ... */
  1043. for (j=0;j<5;j++) { /* ... in reverse order. */
  1044. hashcode = (hashcode << 1) | ((crc>>=1) & 1);
  1045. }
  1046. byte = hashcode >> 3; /* bit[3-5] -> byte in filter */
  1047. bit = 1 << (hashcode & 0x07); /* bit[0-2] -> bit in byte */
  1048. lp->init_block.mcast_table[byte] |= bit;
  1049. }
  1050. }
  1051. }
  1052. return;
  1053. }
  1054. #ifdef CONFIG_MCA
  1055. /*
  1056. ** Microchannel bus I/O device probe
  1057. */
  1058. __initfunc(static void
  1059. mca_probe(struct device *dev, u_long ioaddr))
  1060. {
  1061. unsigned char pos[2];
  1062. unsigned char where;
  1063. unsigned long iobase;
  1064. int irq;
  1065. int slot = 0;
  1066. /*
  1067. ** See if we've been here before.
  1068. */
  1069. if ((!ioaddr && autoprobed) || (ioaddr && !loading_module)) return;
  1070. if (MCA_bus) {
  1071. /*
  1072. ** Search for the adapter. If an address has been given, search
  1073. ** specifically for the card at that address. Otherwise find the
  1074. ** first card in the system.
  1075. */
  1076. while ((dev!=NULL) &&
  1077. ((slot=mca_find_adapter(DE212_ID, slot)) != MCA_NOTFOUND)) {
  1078. pos[0] = mca_read_stored_pos(slot, 2);
  1079. pos[1] = mca_read_stored_pos(slot, 3);
  1080. /*
  1081. ** IO of card is handled by bits 1 and 2 of pos0.
  1082. **
  1083. ** bit2 bit1 IO
  1084. ** 0 0 0x2c00
  1085. ** 0 1 0x2c10
  1086. ** 1 0 0x2c20
  1087. ** 1 1 0x2c30
  1088. */
  1089. where = (pos[0] & 6) >> 1;
  1090. iobase = 0x2c00 + (0x10 * where);
  1091. if ((ioaddr) && (ioaddr != iobase)) {
  1092. /*
  1093. ** Card was found, but not at the right IO location. Continue
  1094. ** scanning from the next MCA slot up for another card.
  1095. */
  1096. slot++;
  1097. continue;
  1098. }
  1099. /*
  1100. ** Found the adapter we were looking for. Now start setting it up.
  1101. **
  1102. ** First work on decoding the IRQ. It's stored in the lower 4 bits
  1103. ** of pos1. Bits are as follows (from the ADF file):
  1104. **
  1105. ** Bits
  1106. ** 3 2 1 0 IRQ
  1107. ** --------------------
  1108. ** 0 0 1 0 5
  1109. ** 0 0 0 1 9
  1110. ** 0 1 0 0 10
  1111. ** 1 0 0 0 11
  1112. **/
  1113. where = pos[1] & 0x0f;
  1114. switch(where) {
  1115. case 1:
  1116. irq = 9;
  1117. break;
  1118. case 2:
  1119. irq = 5;
  1120. break;
  1121. case 4:
  1122. irq = 10;
  1123. break;
  1124. case 8:
  1125. irq = 11;
  1126. break;
  1127. default:
  1128. printk("%s: mca_probe IRQ error. You should never get here (%d).\n", dev->name, where);
  1129. return;
  1130. }
  1131. /*
  1132. ** Shared memory address of adapter is stored in bits 3-5 of pos0.
  1133. ** They are mapped as follows:
  1134. **
  1135. ** Bit
  1136. ** 5 4 3 Memory Addresses
  1137. ** 0 0 0 C0000-CFFFF (64K)
  1138. ** 1 0 0 C8000-CFFFF (32K)
  1139. ** 0 0 1 D0000-DFFFF (64K)
  1140. ** 1 0 1 D8000-DFFFF (32K)
  1141. ** 0 1 0 E0000-EFFFF (64K)
  1142. ** 1 1 0 E8000-EFFFF (32K)
  1143. */
  1144. where = (pos[0] & 0x18) >> 3;
  1145. mem = 0xc0000 + (where * 0x10000);
  1146. if (pos[0] & 0x20) {
  1147. mem += 0x8000;
  1148. }
  1149. /*
  1150. ** Get everything allocated and initialized... (almost just
  1151. ** like the ISA and EISA probes)
  1152. */
  1153. if (DevicePresent(iobase) != 0) {
  1154. /*
  1155. ** If the MCA configuration says the card should be here,
  1156. ** it really should be here.
  1157. */
  1158. printk(KERN_ERR "%s: MCA reports card at 0x%lx but it is not
  1159. responding.\n", dev->name, iobase);
  1160. }
  1161. if (check_region(iobase, DEPCA_TOTAL_SIZE) == 0) {
  1162. if ((dev = alloc_device(dev, iobase)) != NULL) {
  1163. dev->irq = irq;
  1164. if (depca_hw_init(dev, iobase, slot) == 0) {
  1165. /*
  1166. ** Adapter initialized correctly: Name it in
  1167. ** /proc/mca.
  1168. */
  1169. mca_set_adapter_name(slot, "DE210/212 Ethernet Adapter");
  1170. mca_mark_as_used(slot);
  1171. num_depcas++;
  1172. }
  1173. num_eth++;
  1174. }
  1175. } else if (autoprobed) {
  1176. printk(KERN_WARNING "%s: region already allocated at 0x%04lx.\n", dev->name, iobase);
  1177. }
  1178. /*
  1179. ** If this is a probe by a module, return after setting up the
  1180. ** given card.
  1181. */
  1182. if (ioaddr) return;
  1183. /*
  1184. ** Set up to check the next slot and loop.
  1185. */
  1186. slot++;
  1187. }
  1188. }
  1189. return;
  1190. }
  1191. #endif
  1192. /*
  1193. ** ISA bus I/O device probe
  1194. */
  1195. __initfunc(static void
  1196. isa_probe(struct device *dev, u_long ioaddr))
  1197. {
  1198. int i = num_depcas, maxSlots;
  1199. s32 ports[] = DEPCA_IO_PORTS;
  1200. if (!ioaddr && autoprobed) return ; /* Been here before ! */
  1201. if (ioaddr > 0x400) return; /* EISA Address */
  1202. if (i >= MAX_NUM_DEPCAS) return; /* Too many ISA adapters */
  1203. if (ioaddr == 0) { /* Autoprobing */
  1204. maxSlots = MAX_NUM_DEPCAS;
  1205. } else { /* Probe a specific location */
  1206. ports[i] = ioaddr;
  1207. maxSlots = i + 1;
  1208. }
  1209. for (; (i<maxSlots) && (dev!=NULL) && ports[i]; i++) {
  1210. if (check_region(ports[i], DEPCA_TOTAL_SIZE) == 0) {
  1211. if (DevicePresent(ports[i]) == 0) {
  1212. if ((dev = alloc_device(dev, ports[i])) != NULL) {
  1213. if (depca_hw_init(dev, ports[i], -1) == 0) {
  1214. num_depcas++;
  1215. }
  1216. num_eth++;
  1217. }
  1218. }
  1219. } else if (autoprobed) {
  1220. printk("%s: region already allocated at 0x%04x.\n", dev->name, ports[i]);
  1221. }
  1222. }
  1223. return;
  1224. }
  1225. /*
  1226. ** EISA bus I/O device probe. Probe from slot 1 since slot 0 is usually
  1227. ** the motherboard. Upto 15 EISA devices are supported.
  1228. */
  1229. __initfunc(static void
  1230. eisa_probe(struct device *dev, u_long ioaddr))
  1231. {
  1232. int i, maxSlots;
  1233. u_long iobase;
  1234. char name[DEPCA_STRLEN];
  1235. if (!ioaddr && autoprobed) return ; /* Been here before ! */
  1236. if ((ioaddr < 0x400) && (ioaddr > 0)) return; /* ISA Address */
  1237. if (ioaddr == 0) { /* Autoprobing */
  1238. iobase = EISA_SLOT_INC; /* Get the first slot address */
  1239. i = 1;
  1240. maxSlots = MAX_EISA_SLOTS;
  1241. } else { /* Probe a specific location */
  1242. iobase = ioaddr;
  1243. i = (ioaddr >> 12);
  1244. maxSlots = i + 1;
  1245. }
  1246. if ((iobase & 0x0fff) == 0) iobase += DEPCA_EISA_IO_PORTS;
  1247. for (; (i<maxSlots) && (dev!=NULL); i++, iobase+=EISA_SLOT_INC) {
  1248. if (check_region(iobase, DEPCA_TOTAL_SIZE) == 0) {
  1249. if (EISA_signature(name, EISA_ID)) {
  1250. if (DevicePresent(iobase) == 0) {
  1251. if ((dev = alloc_device(dev, iobase)) != NULL) {
  1252. if (depca_hw_init(dev, iobase, -1) == 0) {
  1253. num_depcas++;
  1254. }
  1255. num_eth++;
  1256. }
  1257. }
  1258. }
  1259. } else if (autoprobed) {
  1260. printk("%s: region already allocated at 0x%04lx.\n", dev->name, iobase);
  1261. }
  1262. }
  1263. return;
  1264. }
  1265. /*
  1266. ** Search the entire 'eth' device list for a fixed probe. If a match isn't
  1267. ** found then check for an autoprobe or unused device location. If they
  1268. ** are not available then insert a new device structure at the end of
  1269. ** the current list.
  1270. */
  1271. __initfunc(static struct device *
  1272. alloc_device(struct device *dev, u_long iobase))
  1273. {
  1274. struct device *adev = NULL;
  1275. int fixed = 0, new_dev = 0;
  1276. num_eth = depca_dev_index(dev->name);
  1277. if (loading_module) return dev;
  1278. while (1) {
  1279. if (((dev->base_addr == DEPCA_NDA) || (dev->base_addr==0)) && !adev) {
  1280. adev=dev;
  1281. } else if ((dev->priv == NULL) && (dev->base_addr==iobase)) {
  1282. fixed = 1;
  1283. } else {
  1284. if (dev->next == NULL) {
  1285. new_dev = 1;
  1286. } else if (strncmp(dev->next->name, "eth", 3) != 0) {
  1287. new_dev = 1;
  1288. }
  1289. }
  1290. if ((dev->next == NULL) || new_dev || fixed) break;
  1291. dev = dev->next;
  1292. num_eth++;
  1293. }
  1294. if (adev && !fixed) {
  1295. dev = adev;
  1296. num_eth = depca_dev_index(dev->name);
  1297. new_dev = 0;
  1298. }
  1299. if (((dev->next == NULL) &&
  1300. ((dev->base_addr != DEPCA_NDA) && (dev->base_addr != 0)) && !fixed) ||
  1301. new_dev) {
  1302. num_eth++; /* New device */
  1303. dev = insert_device(dev, iobase, depca_probe);
  1304. }
  1305. return dev;
  1306. }
  1307. /*
  1308. ** If at end of eth device list and can't use current entry, malloc
  1309. ** one up. If memory could not be allocated, print an error message.
  1310. */
  1311. __initfunc(static struct device *
  1312. insert_device(struct device *dev, u_long iobase, int (*init)(struct device *)))
  1313. {
  1314. struct device *new;
  1315. new = (struct device *)kmalloc(sizeof(struct device)+8, GFP_KERNEL);
  1316. if (new == NULL) {
  1317. printk("eth%d: Device not initialised, insufficient memory\n",num_eth);
  1318. return NULL;
  1319. } else {
  1320. new->next = dev->next;
  1321. dev->next = new;
  1322. dev

Large files files are truncated, but you can click here to view the full file