PageRenderTime 69ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/kernel/2.6.32_froyo_photon_nightly/drivers/net/depca.c

http://photon-android.googlecode.com/
C | 2107 lines | 1309 code | 293 blank | 505 comment | 240 complexity | ea07121d0c8b32ccdf06d9574826264b MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, 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 General 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. 0.52 16-Oct-00 Fixes for 2.3 io memory accesses
  187. Fix show-stopper (ints left masked) in depca_interrupt
  188. by <peterd@pnd-pc.demon.co.uk>
  189. 0.53 12-Jan-01 Release resources on failure, bss tidbits
  190. by acme@conectiva.com.br
  191. 0.54 08-Nov-01 use library crc32 functions
  192. by Matt_Domsch@dell.com
  193. 0.55 01-Mar-03 Use EISA/sysfs framework <maz@wild-wind.fr.eu.org>
  194. =========================================================================
  195. */
  196. #include <linux/module.h>
  197. #include <linux/kernel.h>
  198. #include <linux/sched.h>
  199. #include <linux/string.h>
  200. #include <linux/errno.h>
  201. #include <linux/ioport.h>
  202. #include <linux/slab.h>
  203. #include <linux/interrupt.h>
  204. #include <linux/delay.h>
  205. #include <linux/init.h>
  206. #include <linux/crc32.h>
  207. #include <linux/netdevice.h>
  208. #include <linux/etherdevice.h>
  209. #include <linux/skbuff.h>
  210. #include <linux/time.h>
  211. #include <linux/types.h>
  212. #include <linux/unistd.h>
  213. #include <linux/ctype.h>
  214. #include <linux/moduleparam.h>
  215. #include <linux/platform_device.h>
  216. #include <linux/bitops.h>
  217. #include <asm/uaccess.h>
  218. #include <asm/io.h>
  219. #include <asm/dma.h>
  220. #ifdef CONFIG_MCA
  221. #include <linux/mca.h>
  222. #endif
  223. #ifdef CONFIG_EISA
  224. #include <linux/eisa.h>
  225. #endif
  226. #include "depca.h"
  227. static char version[] __initdata = "depca.c:v0.53 2001/1/12 davies@maniac.ultranet.com\n";
  228. #ifdef DEPCA_DEBUG
  229. static int depca_debug = DEPCA_DEBUG;
  230. #else
  231. static int depca_debug = 1;
  232. #endif
  233. #define DEPCA_NDA 0xffe0 /* No Device Address */
  234. #define TX_TIMEOUT (1*HZ)
  235. /*
  236. ** Ethernet PROM defines
  237. */
  238. #define PROBE_LENGTH 32
  239. #define ETH_PROM_SIG 0xAA5500FFUL
  240. /*
  241. ** Set the number of Tx and Rx buffers. Ensure that the memory requested
  242. ** here is <= to the amount of shared memory set up by the board switches.
  243. ** The number of descriptors MUST BE A POWER OF 2.
  244. **
  245. ** total_memory = NUM_RX_DESC*(8+RX_BUFF_SZ) + NUM_TX_DESC*(8+TX_BUFF_SZ)
  246. */
  247. #define NUM_RX_DESC 8 /* Number of RX descriptors */
  248. #define NUM_TX_DESC 8 /* Number of TX descriptors */
  249. #define RX_BUFF_SZ 1536 /* Buffer size for each Rx buffer */
  250. #define TX_BUFF_SZ 1536 /* Buffer size for each Tx buffer */
  251. /*
  252. ** EISA bus defines
  253. */
  254. #define DEPCA_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */
  255. /*
  256. ** ISA Bus defines
  257. */
  258. #define DEPCA_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0xe0000,0x00000}
  259. #define DEPCA_TOTAL_SIZE 0x10
  260. static struct {
  261. u_long iobase;
  262. struct platform_device *device;
  263. } depca_io_ports[] = {
  264. { 0x300, NULL },
  265. { 0x200, NULL },
  266. { 0 , NULL },
  267. };
  268. /*
  269. ** Name <-> Adapter mapping
  270. */
  271. #define DEPCA_SIGNATURE {"DEPCA",\
  272. "DE100","DE101",\
  273. "DE200","DE201","DE202",\
  274. "DE210","DE212",\
  275. "DE422",\
  276. ""}
  277. static char* __initdata depca_signature[] = DEPCA_SIGNATURE;
  278. enum depca_type {
  279. DEPCA, de100, de101, de200, de201, de202, de210, de212, de422, unknown
  280. };
  281. static char depca_string[] = "depca";
  282. static int depca_device_remove (struct device *device);
  283. #ifdef CONFIG_EISA
  284. static struct eisa_device_id depca_eisa_ids[] = {
  285. { "DEC4220", de422 },
  286. { "" }
  287. };
  288. MODULE_DEVICE_TABLE(eisa, depca_eisa_ids);
  289. static int depca_eisa_probe (struct device *device);
  290. static struct eisa_driver depca_eisa_driver = {
  291. .id_table = depca_eisa_ids,
  292. .driver = {
  293. .name = depca_string,
  294. .probe = depca_eisa_probe,
  295. .remove = __devexit_p (depca_device_remove)
  296. }
  297. };
  298. #endif
  299. #ifdef CONFIG_MCA
  300. /*
  301. ** Adapter ID for the MCA EtherWORKS DE210/212 adapter
  302. */
  303. #define DE210_ID 0x628d
  304. #define DE212_ID 0x6def
  305. static short depca_mca_adapter_ids[] = {
  306. DE210_ID,
  307. DE212_ID,
  308. 0x0000
  309. };
  310. static char *depca_mca_adapter_name[] = {
  311. "DEC EtherWORKS MC Adapter (DE210)",
  312. "DEC EtherWORKS MC Adapter (DE212)",
  313. NULL
  314. };
  315. static enum depca_type depca_mca_adapter_type[] = {
  316. de210,
  317. de212,
  318. 0
  319. };
  320. static int depca_mca_probe (struct device *);
  321. static struct mca_driver depca_mca_driver = {
  322. .id_table = depca_mca_adapter_ids,
  323. .driver = {
  324. .name = depca_string,
  325. .bus = &mca_bus_type,
  326. .probe = depca_mca_probe,
  327. .remove = __devexit_p(depca_device_remove),
  328. },
  329. };
  330. #endif
  331. static int depca_isa_probe (struct platform_device *);
  332. static int __devexit depca_isa_remove(struct platform_device *pdev)
  333. {
  334. return depca_device_remove(&pdev->dev);
  335. }
  336. static struct platform_driver depca_isa_driver = {
  337. .probe = depca_isa_probe,
  338. .remove = __devexit_p(depca_isa_remove),
  339. .driver = {
  340. .name = depca_string,
  341. },
  342. };
  343. /*
  344. ** Miscellaneous info...
  345. */
  346. #define DEPCA_STRLEN 16
  347. /*
  348. ** Memory Alignment. Each descriptor is 4 longwords long. To force a
  349. ** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and
  350. ** DESC_ALIGN. DEPCA_ALIGN aligns the start address of the private memory area
  351. ** and hence the RX descriptor ring's first entry.
  352. */
  353. #define DEPCA_ALIGN4 ((u_long)4 - 1) /* 1 longword align */
  354. #define DEPCA_ALIGN8 ((u_long)8 - 1) /* 2 longword (quadword) align */
  355. #define DEPCA_ALIGN DEPCA_ALIGN8 /* Keep the LANCE happy... */
  356. /*
  357. ** The DEPCA Rx and Tx ring descriptors.
  358. */
  359. struct depca_rx_desc {
  360. volatile s32 base;
  361. s16 buf_length; /* This length is negative 2's complement! */
  362. s16 msg_length; /* This length is "normal". */
  363. };
  364. struct depca_tx_desc {
  365. volatile s32 base;
  366. s16 length; /* This length is negative 2's complement! */
  367. s16 misc; /* Errors and TDR info */
  368. };
  369. #define LA_MASK 0x0000ffff /* LANCE address mask for mapping network RAM
  370. to LANCE memory address space */
  371. /*
  372. ** The Lance initialization block, described in databook, in common memory.
  373. */
  374. struct depca_init {
  375. u16 mode; /* Mode register */
  376. u8 phys_addr[ETH_ALEN]; /* Physical ethernet address */
  377. u8 mcast_table[8]; /* Multicast Hash Table. */
  378. u32 rx_ring; /* Rx ring base pointer & ring length */
  379. u32 tx_ring; /* Tx ring base pointer & ring length */
  380. };
  381. #define DEPCA_PKT_STAT_SZ 16
  382. #define DEPCA_PKT_BIN_SZ 128 /* Should be >=100 unless you
  383. increase DEPCA_PKT_STAT_SZ */
  384. struct depca_private {
  385. char adapter_name[DEPCA_STRLEN]; /* /proc/ioports string */
  386. enum depca_type adapter; /* Adapter type */
  387. enum {
  388. DEPCA_BUS_MCA = 1,
  389. DEPCA_BUS_ISA,
  390. DEPCA_BUS_EISA,
  391. } depca_bus; /* type of bus */
  392. struct depca_init init_block; /* Shadow Initialization block */
  393. /* CPU address space fields */
  394. struct depca_rx_desc __iomem *rx_ring; /* Pointer to start of RX descriptor ring */
  395. struct depca_tx_desc __iomem *tx_ring; /* Pointer to start of TX descriptor ring */
  396. void __iomem *rx_buff[NUM_RX_DESC]; /* CPU virt address of sh'd memory buffs */
  397. void __iomem *tx_buff[NUM_TX_DESC]; /* CPU virt address of sh'd memory buffs */
  398. void __iomem *sh_mem; /* CPU mapped virt address of device RAM */
  399. u_long mem_start; /* Bus address of device RAM (before remap) */
  400. u_long mem_len; /* device memory size */
  401. /* Device address space fields */
  402. u_long device_ram_start; /* Start of RAM in device addr space */
  403. /* Offsets used in both address spaces */
  404. u_long rx_ring_offset; /* Offset from start of RAM to rx_ring */
  405. u_long tx_ring_offset; /* Offset from start of RAM to tx_ring */
  406. u_long buffs_offset; /* LANCE Rx and Tx buffers start address. */
  407. /* Kernel-only (not device) fields */
  408. int rx_new, tx_new; /* The next free ring entry */
  409. int rx_old, tx_old; /* The ring entries to be free()ed. */
  410. spinlock_t lock;
  411. struct { /* Private stats counters */
  412. u32 bins[DEPCA_PKT_STAT_SZ];
  413. u32 unicast;
  414. u32 multicast;
  415. u32 broadcast;
  416. u32 excessive_collisions;
  417. u32 tx_underruns;
  418. u32 excessive_underruns;
  419. } pktStats;
  420. int txRingMask; /* TX ring mask */
  421. int rxRingMask; /* RX ring mask */
  422. s32 rx_rlen; /* log2(rxRingMask+1) for the descriptors */
  423. s32 tx_rlen; /* log2(txRingMask+1) for the descriptors */
  424. };
  425. /*
  426. ** The transmit ring full condition is described by the tx_old and tx_new
  427. ** pointers by:
  428. ** tx_old = tx_new Empty ring
  429. ** tx_old = tx_new+1 Full ring
  430. ** tx_old+txRingMask = tx_new Full ring (wrapped condition)
  431. */
  432. #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
  433. lp->tx_old+lp->txRingMask-lp->tx_new:\
  434. lp->tx_old -lp->tx_new-1)
  435. /*
  436. ** Public Functions
  437. */
  438. static int depca_open(struct net_device *dev);
  439. static netdev_tx_t depca_start_xmit(struct sk_buff *skb,
  440. struct net_device *dev);
  441. static irqreturn_t depca_interrupt(int irq, void *dev_id);
  442. static int depca_close(struct net_device *dev);
  443. static int depca_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  444. static void depca_tx_timeout(struct net_device *dev);
  445. static void set_multicast_list(struct net_device *dev);
  446. /*
  447. ** Private functions
  448. */
  449. static void depca_init_ring(struct net_device *dev);
  450. static int depca_rx(struct net_device *dev);
  451. static int depca_tx(struct net_device *dev);
  452. static void LoadCSRs(struct net_device *dev);
  453. static int InitRestartDepca(struct net_device *dev);
  454. static int DepcaSignature(char *name, u_long paddr);
  455. static int DevicePresent(u_long ioaddr);
  456. static int get_hw_addr(struct net_device *dev);
  457. static void SetMulticastFilter(struct net_device *dev);
  458. static int load_packet(struct net_device *dev, struct sk_buff *skb);
  459. static void depca_dbg_open(struct net_device *dev);
  460. static u_char de1xx_irq[] __initdata = { 2, 3, 4, 5, 7, 9, 0 };
  461. static u_char de2xx_irq[] __initdata = { 5, 9, 10, 11, 15, 0 };
  462. static u_char de422_irq[] __initdata = { 5, 9, 10, 11, 0 };
  463. static u_char *depca_irq;
  464. static int irq;
  465. static int io;
  466. static char *adapter_name;
  467. static int mem; /* For loadable module assignment
  468. use insmod mem=0x????? .... */
  469. module_param (irq, int, 0);
  470. module_param (io, int, 0);
  471. module_param (adapter_name, charp, 0);
  472. module_param (mem, int, 0);
  473. MODULE_PARM_DESC(irq, "DEPCA IRQ number");
  474. MODULE_PARM_DESC(io, "DEPCA I/O base address");
  475. MODULE_PARM_DESC(adapter_name, "DEPCA adapter name");
  476. MODULE_PARM_DESC(mem, "DEPCA shared memory address");
  477. MODULE_LICENSE("GPL");
  478. /*
  479. ** Miscellaneous defines...
  480. */
  481. #define STOP_DEPCA \
  482. outw(CSR0, DEPCA_ADDR);\
  483. outw(STOP, DEPCA_DATA)
  484. static const struct net_device_ops depca_netdev_ops = {
  485. .ndo_open = depca_open,
  486. .ndo_start_xmit = depca_start_xmit,
  487. .ndo_stop = depca_close,
  488. .ndo_set_multicast_list = set_multicast_list,
  489. .ndo_do_ioctl = depca_ioctl,
  490. .ndo_tx_timeout = depca_tx_timeout,
  491. .ndo_change_mtu = eth_change_mtu,
  492. .ndo_set_mac_address = eth_mac_addr,
  493. .ndo_validate_addr = eth_validate_addr,
  494. };
  495. static int __init depca_hw_init (struct net_device *dev, struct device *device)
  496. {
  497. struct depca_private *lp;
  498. int i, j, offset, netRAM, mem_len, status = 0;
  499. s16 nicsr;
  500. u_long ioaddr;
  501. u_long mem_start;
  502. /*
  503. * We are now supposed to enter this function with the
  504. * following fields filled with proper values :
  505. *
  506. * dev->base_addr
  507. * lp->mem_start
  508. * lp->depca_bus
  509. * lp->adapter
  510. *
  511. * dev->irq can be set if known from device configuration (on
  512. * MCA or EISA) or module option. Otherwise, it will be auto
  513. * detected.
  514. */
  515. ioaddr = dev->base_addr;
  516. STOP_DEPCA;
  517. nicsr = inb(DEPCA_NICSR);
  518. nicsr = ((nicsr & ~SHE & ~RBE & ~IEN) | IM);
  519. outb(nicsr, DEPCA_NICSR);
  520. if (inw(DEPCA_DATA) != STOP) {
  521. return -ENXIO;
  522. }
  523. lp = netdev_priv(dev);
  524. mem_start = lp->mem_start;
  525. if (!mem_start || lp->adapter < DEPCA || lp->adapter >=unknown)
  526. return -ENXIO;
  527. printk("%s: %s at 0x%04lx",
  528. dev_name(device), depca_signature[lp->adapter], ioaddr);
  529. switch (lp->depca_bus) {
  530. #ifdef CONFIG_MCA
  531. case DEPCA_BUS_MCA:
  532. printk(" (MCA slot %d)", to_mca_device(device)->slot + 1);
  533. break;
  534. #endif
  535. #ifdef CONFIG_EISA
  536. case DEPCA_BUS_EISA:
  537. printk(" (EISA slot %d)", to_eisa_device(device)->slot);
  538. break;
  539. #endif
  540. case DEPCA_BUS_ISA:
  541. break;
  542. default:
  543. printk("Unknown DEPCA bus %d\n", lp->depca_bus);
  544. return -ENXIO;
  545. }
  546. printk(", h/w address ");
  547. status = get_hw_addr(dev);
  548. printk("%pM", dev->dev_addr);
  549. if (status != 0) {
  550. printk(" which has an Ethernet PROM CRC error.\n");
  551. return -ENXIO;
  552. }
  553. /* Set up the maximum amount of network RAM(kB) */
  554. netRAM = ((lp->adapter != DEPCA) ? 64 : 48);
  555. if ((nicsr & _128KB) && (lp->adapter == de422))
  556. netRAM = 128;
  557. /* Shared Memory Base Address */
  558. if (nicsr & BUF) {
  559. nicsr &= ~BS; /* DEPCA RAM in top 32k */
  560. netRAM -= 32;
  561. /* Only EISA/ISA needs start address to be re-computed */
  562. if (lp->depca_bus != DEPCA_BUS_MCA)
  563. mem_start += 0x8000;
  564. }
  565. if ((mem_len = (NUM_RX_DESC * (sizeof(struct depca_rx_desc) + RX_BUFF_SZ) + NUM_TX_DESC * (sizeof(struct depca_tx_desc) + TX_BUFF_SZ) + sizeof(struct depca_init)))
  566. > (netRAM << 10)) {
  567. printk(",\n requests %dkB RAM: only %dkB is available!\n", (mem_len >> 10), netRAM);
  568. return -ENXIO;
  569. }
  570. printk(",\n has %dkB RAM at 0x%.5lx", netRAM, mem_start);
  571. /* Enable the shadow RAM. */
  572. if (lp->adapter != DEPCA) {
  573. nicsr |= SHE;
  574. outb(nicsr, DEPCA_NICSR);
  575. }
  576. spin_lock_init(&lp->lock);
  577. sprintf(lp->adapter_name, "%s (%s)",
  578. depca_signature[lp->adapter], dev_name(device));
  579. status = -EBUSY;
  580. /* Initialisation Block */
  581. if (!request_mem_region (mem_start, mem_len, lp->adapter_name)) {
  582. printk(KERN_ERR "depca: cannot request ISA memory, aborting\n");
  583. goto out_priv;
  584. }
  585. status = -EIO;
  586. lp->sh_mem = ioremap(mem_start, mem_len);
  587. if (lp->sh_mem == NULL) {
  588. printk(KERN_ERR "depca: cannot remap ISA memory, aborting\n");
  589. goto out1;
  590. }
  591. lp->mem_start = mem_start;
  592. lp->mem_len = mem_len;
  593. lp->device_ram_start = mem_start & LA_MASK;
  594. offset = 0;
  595. offset += sizeof(struct depca_init);
  596. /* Tx & Rx descriptors (aligned to a quadword boundary) */
  597. offset = (offset + DEPCA_ALIGN) & ~DEPCA_ALIGN;
  598. lp->rx_ring = (struct depca_rx_desc __iomem *) (lp->sh_mem + offset);
  599. lp->rx_ring_offset = offset;
  600. offset += (sizeof(struct depca_rx_desc) * NUM_RX_DESC);
  601. lp->tx_ring = (struct depca_tx_desc __iomem *) (lp->sh_mem + offset);
  602. lp->tx_ring_offset = offset;
  603. offset += (sizeof(struct depca_tx_desc) * NUM_TX_DESC);
  604. lp->buffs_offset = offset;
  605. /* Finish initialising the ring information. */
  606. lp->rxRingMask = NUM_RX_DESC - 1;
  607. lp->txRingMask = NUM_TX_DESC - 1;
  608. /* Calculate Tx/Rx RLEN size for the descriptors. */
  609. for (i = 0, j = lp->rxRingMask; j > 0; i++) {
  610. j >>= 1;
  611. }
  612. lp->rx_rlen = (s32) (i << 29);
  613. for (i = 0, j = lp->txRingMask; j > 0; i++) {
  614. j >>= 1;
  615. }
  616. lp->tx_rlen = (s32) (i << 29);
  617. /* Load the initialisation block */
  618. depca_init_ring(dev);
  619. /* Initialise the control and status registers */
  620. LoadCSRs(dev);
  621. /* Enable DEPCA board interrupts for autoprobing */
  622. nicsr = ((nicsr & ~IM) | IEN);
  623. outb(nicsr, DEPCA_NICSR);
  624. /* To auto-IRQ we enable the initialization-done and DMA err,
  625. interrupts. For now we will always get a DMA error. */
  626. if (dev->irq < 2) {
  627. unsigned char irqnum;
  628. unsigned long irq_mask, delay;
  629. irq_mask = probe_irq_on();
  630. /* Assign the correct irq list */
  631. switch (lp->adapter) {
  632. case DEPCA:
  633. case de100:
  634. case de101:
  635. depca_irq = de1xx_irq;
  636. break;
  637. case de200:
  638. case de201:
  639. case de202:
  640. case de210:
  641. case de212:
  642. depca_irq = de2xx_irq;
  643. break;
  644. case de422:
  645. depca_irq = de422_irq;
  646. break;
  647. default:
  648. break; /* Not reached */
  649. }
  650. /* Trigger an initialization just for the interrupt. */
  651. outw(INEA | INIT, DEPCA_DATA);
  652. delay = jiffies + HZ/50;
  653. while (time_before(jiffies, delay))
  654. yield();
  655. irqnum = probe_irq_off(irq_mask);
  656. status = -ENXIO;
  657. if (!irqnum) {
  658. printk(" and failed to detect IRQ line.\n");
  659. goto out2;
  660. } else {
  661. for (dev->irq = 0, i = 0; (depca_irq[i]) && (!dev->irq); i++)
  662. if (irqnum == depca_irq[i]) {
  663. dev->irq = irqnum;
  664. printk(" and uses IRQ%d.\n", dev->irq);
  665. }
  666. if (!dev->irq) {
  667. printk(" but incorrect IRQ line detected.\n");
  668. goto out2;
  669. }
  670. }
  671. } else {
  672. printk(" and assigned IRQ%d.\n", dev->irq);
  673. }
  674. if (depca_debug > 1) {
  675. printk(version);
  676. }
  677. /* The DEPCA-specific entries in the device structure. */
  678. dev->netdev_ops = &depca_netdev_ops;
  679. dev->watchdog_timeo = TX_TIMEOUT;
  680. dev->mem_start = 0;
  681. dev_set_drvdata(device, dev);
  682. SET_NETDEV_DEV (dev, device);
  683. status = register_netdev(dev);
  684. if (status == 0)
  685. return 0;
  686. out2:
  687. iounmap(lp->sh_mem);
  688. out1:
  689. release_mem_region (mem_start, mem_len);
  690. out_priv:
  691. return status;
  692. }
  693. static int depca_open(struct net_device *dev)
  694. {
  695. struct depca_private *lp = netdev_priv(dev);
  696. u_long ioaddr = dev->base_addr;
  697. s16 nicsr;
  698. int status = 0;
  699. STOP_DEPCA;
  700. nicsr = inb(DEPCA_NICSR);
  701. /* Make sure the shadow RAM is enabled */
  702. if (lp->adapter != DEPCA) {
  703. nicsr |= SHE;
  704. outb(nicsr, DEPCA_NICSR);
  705. }
  706. /* Re-initialize the DEPCA... */
  707. depca_init_ring(dev);
  708. LoadCSRs(dev);
  709. depca_dbg_open(dev);
  710. if (request_irq(dev->irq, &depca_interrupt, 0, lp->adapter_name, dev)) {
  711. printk("depca_open(): Requested IRQ%d is busy\n", dev->irq);
  712. status = -EAGAIN;
  713. } else {
  714. /* Enable DEPCA board interrupts and turn off LED */
  715. nicsr = ((nicsr & ~IM & ~LED) | IEN);
  716. outb(nicsr, DEPCA_NICSR);
  717. outw(CSR0, DEPCA_ADDR);
  718. netif_start_queue(dev);
  719. status = InitRestartDepca(dev);
  720. if (depca_debug > 1) {
  721. printk("CSR0: 0x%4.4x\n", inw(DEPCA_DATA));
  722. printk("nicsr: 0x%02x\n", inb(DEPCA_NICSR));
  723. }
  724. }
  725. return status;
  726. }
  727. /* Initialize the lance Rx and Tx descriptor rings. */
  728. static void depca_init_ring(struct net_device *dev)
  729. {
  730. struct depca_private *lp = netdev_priv(dev);
  731. u_int i;
  732. u_long offset;
  733. /* Lock out other processes whilst setting up the hardware */
  734. netif_stop_queue(dev);
  735. lp->rx_new = lp->tx_new = 0;
  736. lp->rx_old = lp->tx_old = 0;
  737. /* Initialize the base address and length of each buffer in the ring */
  738. for (i = 0; i <= lp->rxRingMask; i++) {
  739. offset = lp->buffs_offset + i * RX_BUFF_SZ;
  740. writel((lp->device_ram_start + offset) | R_OWN, &lp->rx_ring[i].base);
  741. writew(-RX_BUFF_SZ, &lp->rx_ring[i].buf_length);
  742. lp->rx_buff[i] = lp->sh_mem + offset;
  743. }
  744. for (i = 0; i <= lp->txRingMask; i++) {
  745. offset = lp->buffs_offset + (i + lp->rxRingMask + 1) * TX_BUFF_SZ;
  746. writel((lp->device_ram_start + offset) & 0x00ffffff, &lp->tx_ring[i].base);
  747. lp->tx_buff[i] = lp->sh_mem + offset;
  748. }
  749. /* Set up the initialization block */
  750. lp->init_block.rx_ring = (lp->device_ram_start + lp->rx_ring_offset) | lp->rx_rlen;
  751. lp->init_block.tx_ring = (lp->device_ram_start + lp->tx_ring_offset) | lp->tx_rlen;
  752. SetMulticastFilter(dev);
  753. for (i = 0; i < ETH_ALEN; i++) {
  754. lp->init_block.phys_addr[i] = dev->dev_addr[i];
  755. }
  756. lp->init_block.mode = 0x0000; /* Enable the Tx and Rx */
  757. }
  758. static void depca_tx_timeout(struct net_device *dev)
  759. {
  760. u_long ioaddr = dev->base_addr;
  761. printk("%s: transmit timed out, status %04x, resetting.\n", dev->name, inw(DEPCA_DATA));
  762. STOP_DEPCA;
  763. depca_init_ring(dev);
  764. LoadCSRs(dev);
  765. dev->trans_start = jiffies;
  766. netif_wake_queue(dev);
  767. InitRestartDepca(dev);
  768. }
  769. /*
  770. ** Writes a socket buffer to TX descriptor ring and starts transmission
  771. */
  772. static netdev_tx_t depca_start_xmit(struct sk_buff *skb,
  773. struct net_device *dev)
  774. {
  775. struct depca_private *lp = netdev_priv(dev);
  776. u_long ioaddr = dev->base_addr;
  777. int status = 0;
  778. /* Transmitter timeout, serious problems. */
  779. if (skb->len < 1)
  780. goto out;
  781. if (skb_padto(skb, ETH_ZLEN))
  782. goto out;
  783. netif_stop_queue(dev);
  784. if (TX_BUFFS_AVAIL) { /* Fill in a Tx ring entry */
  785. status = load_packet(dev, skb);
  786. if (!status) {
  787. /* Trigger an immediate send demand. */
  788. outw(CSR0, DEPCA_ADDR);
  789. outw(INEA | TDMD, DEPCA_DATA);
  790. dev->trans_start = jiffies;
  791. dev_kfree_skb(skb);
  792. }
  793. if (TX_BUFFS_AVAIL)
  794. netif_start_queue(dev);
  795. } else
  796. status = NETDEV_TX_LOCKED;
  797. out:
  798. return status;
  799. }
  800. /*
  801. ** The DEPCA interrupt handler.
  802. */
  803. static irqreturn_t depca_interrupt(int irq, void *dev_id)
  804. {
  805. struct net_device *dev = dev_id;
  806. struct depca_private *lp;
  807. s16 csr0, nicsr;
  808. u_long ioaddr;
  809. if (dev == NULL) {
  810. printk("depca_interrupt(): irq %d for unknown device.\n", irq);
  811. return IRQ_NONE;
  812. }
  813. lp = netdev_priv(dev);
  814. ioaddr = dev->base_addr;
  815. spin_lock(&lp->lock);
  816. /* mask the DEPCA board interrupts and turn on the LED */
  817. nicsr = inb(DEPCA_NICSR);
  818. nicsr |= (IM | LED);
  819. outb(nicsr, DEPCA_NICSR);
  820. outw(CSR0, DEPCA_ADDR);
  821. csr0 = inw(DEPCA_DATA);
  822. /* Acknowledge all of the current interrupt sources ASAP. */
  823. outw(csr0 & INTE, DEPCA_DATA);
  824. if (csr0 & RINT) /* Rx interrupt (packet arrived) */
  825. depca_rx(dev);
  826. if (csr0 & TINT) /* Tx interrupt (packet sent) */
  827. depca_tx(dev);
  828. /* Any resources available? */
  829. if ((TX_BUFFS_AVAIL >= 0) && netif_queue_stopped(dev)) {
  830. netif_wake_queue(dev);
  831. }
  832. /* Unmask the DEPCA board interrupts and turn off the LED */
  833. nicsr = (nicsr & ~IM & ~LED);
  834. outb(nicsr, DEPCA_NICSR);
  835. spin_unlock(&lp->lock);
  836. return IRQ_HANDLED;
  837. }
  838. /* Called with lp->lock held */
  839. static int depca_rx(struct net_device *dev)
  840. {
  841. struct depca_private *lp = netdev_priv(dev);
  842. int i, entry;
  843. s32 status;
  844. for (entry = lp->rx_new; !(readl(&lp->rx_ring[entry].base) & R_OWN); entry = lp->rx_new) {
  845. status = readl(&lp->rx_ring[entry].base) >> 16;
  846. if (status & R_STP) { /* Remember start of frame */
  847. lp->rx_old = entry;
  848. }
  849. if (status & R_ENP) { /* Valid frame status */
  850. if (status & R_ERR) { /* There was an error. */
  851. dev->stats.rx_errors++; /* Update the error stats. */
  852. if (status & R_FRAM)
  853. dev->stats.rx_frame_errors++;
  854. if (status & R_OFLO)
  855. dev->stats.rx_over_errors++;
  856. if (status & R_CRC)
  857. dev->stats.rx_crc_errors++;
  858. if (status & R_BUFF)
  859. dev->stats.rx_fifo_errors++;
  860. } else {
  861. short len, pkt_len = readw(&lp->rx_ring[entry].msg_length) - 4;
  862. struct sk_buff *skb;
  863. skb = dev_alloc_skb(pkt_len + 2);
  864. if (skb != NULL) {
  865. unsigned char *buf;
  866. skb_reserve(skb, 2); /* 16 byte align the IP header */
  867. buf = skb_put(skb, pkt_len);
  868. if (entry < lp->rx_old) { /* Wrapped buffer */
  869. len = (lp->rxRingMask - lp->rx_old + 1) * RX_BUFF_SZ;
  870. memcpy_fromio(buf, lp->rx_buff[lp->rx_old], len);
  871. memcpy_fromio(buf + len, lp->rx_buff[0], pkt_len - len);
  872. } else { /* Linear buffer */
  873. memcpy_fromio(buf, lp->rx_buff[lp->rx_old], pkt_len);
  874. }
  875. /*
  876. ** Notify the upper protocol layers that there is another
  877. ** packet to handle
  878. */
  879. skb->protocol = eth_type_trans(skb, dev);
  880. netif_rx(skb);
  881. /*
  882. ** Update stats
  883. */
  884. dev->stats.rx_packets++;
  885. dev->stats.rx_bytes += pkt_len;
  886. for (i = 1; i < DEPCA_PKT_STAT_SZ - 1; i++) {
  887. if (pkt_len < (i * DEPCA_PKT_BIN_SZ)) {
  888. lp->pktStats.bins[i]++;
  889. i = DEPCA_PKT_STAT_SZ;
  890. }
  891. }
  892. if (buf[0] & 0x01) { /* Multicast/Broadcast */
  893. if ((*(s16 *) & buf[0] == -1) && (*(s16 *) & buf[2] == -1) && (*(s16 *) & buf[4] == -1)) {
  894. lp->pktStats.broadcast++;
  895. } else {
  896. lp->pktStats.multicast++;
  897. }
  898. } else if ((*(s16 *) & buf[0] == *(s16 *) & dev->dev_addr[0]) && (*(s16 *) & buf[2] == *(s16 *) & dev->dev_addr[2]) && (*(s16 *) & buf[4] == *(s16 *) & dev->dev_addr[4])) {
  899. lp->pktStats.unicast++;
  900. }
  901. lp->pktStats.bins[0]++; /* Duplicates stats.rx_packets */
  902. if (lp->pktStats.bins[0] == 0) { /* Reset counters */
  903. memset((char *) &lp->pktStats, 0, sizeof(lp->pktStats));
  904. }
  905. } else {
  906. printk("%s: Memory squeeze, deferring packet.\n", dev->name);
  907. dev->stats.rx_dropped++; /* Really, deferred. */
  908. break;
  909. }
  910. }
  911. /* Change buffer ownership for this last frame, back to the adapter */
  912. for (; lp->rx_old != entry; lp->rx_old = (++lp->rx_old) & lp->rxRingMask) {
  913. writel(readl(&lp->rx_ring[lp->rx_old].base) | R_OWN, &lp->rx_ring[lp->rx_old].base);
  914. }
  915. writel(readl(&lp->rx_ring[entry].base) | R_OWN, &lp->rx_ring[entry].base);
  916. }
  917. /*
  918. ** Update entry information
  919. */
  920. lp->rx_new = (++lp->rx_new) & lp->rxRingMask;
  921. }
  922. return 0;
  923. }
  924. /*
  925. ** Buffer sent - check for buffer errors.
  926. ** Called with lp->lock held
  927. */
  928. static int depca_tx(struct net_device *dev)
  929. {
  930. struct depca_private *lp = netdev_priv(dev);
  931. int entry;
  932. s32 status;
  933. u_long ioaddr = dev->base_addr;
  934. for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) {
  935. status = readl(&lp->tx_ring[entry].base) >> 16;
  936. if (status < 0) { /* Packet not yet sent! */
  937. break;
  938. } else if (status & T_ERR) { /* An error occurred. */
  939. status = readl(&lp->tx_ring[entry].misc);
  940. dev->stats.tx_errors++;
  941. if (status & TMD3_RTRY)
  942. dev->stats.tx_aborted_errors++;
  943. if (status & TMD3_LCAR)
  944. dev->stats.tx_carrier_errors++;
  945. if (status & TMD3_LCOL)
  946. dev->stats.tx_window_errors++;
  947. if (status & TMD3_UFLO)
  948. dev->stats.tx_fifo_errors++;
  949. if (status & (TMD3_BUFF | TMD3_UFLO)) {
  950. /* Trigger an immediate send demand. */
  951. outw(CSR0, DEPCA_ADDR);
  952. outw(INEA | TDMD, DEPCA_DATA);
  953. }
  954. } else if (status & (T_MORE | T_ONE)) {
  955. dev->stats.collisions++;
  956. } else {
  957. dev->stats.tx_packets++;
  958. }
  959. /* Update all the pointers */
  960. lp->tx_old = (++lp->tx_old) & lp->txRingMask;
  961. }
  962. return 0;
  963. }
  964. static int depca_close(struct net_device *dev)
  965. {
  966. struct depca_private *lp = netdev_priv(dev);
  967. s16 nicsr;
  968. u_long ioaddr = dev->base_addr;
  969. netif_stop_queue(dev);
  970. outw(CSR0, DEPCA_ADDR);
  971. if (depca_debug > 1) {
  972. printk("%s: Shutting down ethercard, status was %2.2x.\n", dev->name, inw(DEPCA_DATA));
  973. }
  974. /*
  975. ** We stop the DEPCA here -- it occasionally polls
  976. ** memory if we don't.
  977. */
  978. outw(STOP, DEPCA_DATA);
  979. /*
  980. ** Give back the ROM in case the user wants to go to DOS
  981. */
  982. if (lp->adapter != DEPCA) {
  983. nicsr = inb(DEPCA_NICSR);
  984. nicsr &= ~SHE;
  985. outb(nicsr, DEPCA_NICSR);
  986. }
  987. /*
  988. ** Free the associated irq
  989. */
  990. free_irq(dev->irq, dev);
  991. return 0;
  992. }
  993. static void LoadCSRs(struct net_device *dev)
  994. {
  995. struct depca_private *lp = netdev_priv(dev);
  996. u_long ioaddr = dev->base_addr;
  997. outw(CSR1, DEPCA_ADDR); /* initialisation block address LSW */
  998. outw((u16) lp->device_ram_start, DEPCA_DATA);
  999. outw(CSR2, DEPCA_ADDR); /* initialisation block address MSW */
  1000. outw((u16) (lp->device_ram_start >> 16), DEPCA_DATA);
  1001. outw(CSR3, DEPCA_ADDR); /* ALE control */
  1002. outw(ACON, DEPCA_DATA);
  1003. outw(CSR0, DEPCA_ADDR); /* Point back to CSR0 */
  1004. return;
  1005. }
  1006. static int InitRestartDepca(struct net_device *dev)
  1007. {
  1008. struct depca_private *lp = netdev_priv(dev);
  1009. u_long ioaddr = dev->base_addr;
  1010. int i, status = 0;
  1011. /* Copy the shadow init_block to shared memory */
  1012. memcpy_toio(lp->sh_mem, &lp->init_block, sizeof(struct depca_init));
  1013. outw(CSR0, DEPCA_ADDR); /* point back to CSR0 */
  1014. outw(INIT, DEPCA_DATA); /* initialize DEPCA */
  1015. /* wait for lance to complete initialisation */
  1016. for (i = 0; (i < 100) && !(inw(DEPCA_DATA) & IDON); i++);
  1017. if (i != 100) {
  1018. /* clear IDON by writing a "1", enable interrupts and start lance */
  1019. outw(IDON | INEA | STRT, DEPCA_DATA);
  1020. if (depca_debug > 2) {
  1021. printk("%s: DEPCA open after %d ticks, init block 0x%08lx csr0 %4.4x.\n", dev->name, i, lp->mem_start, inw(DEPCA_DATA));
  1022. }
  1023. } else {
  1024. printk("%s: DEPCA unopen after %d ticks, init block 0x%08lx csr0 %4.4x.\n", dev->name, i, lp->mem_start, inw(DEPCA_DATA));
  1025. status = -1;
  1026. }
  1027. return status;
  1028. }
  1029. /*
  1030. ** Set or clear the multicast filter for this adaptor.
  1031. */
  1032. static void set_multicast_list(struct net_device *dev)
  1033. {
  1034. struct depca_private *lp = netdev_priv(dev);
  1035. u_long ioaddr = dev->base_addr;
  1036. netif_stop_queue(dev);
  1037. while (lp->tx_old != lp->tx_new); /* Wait for the ring to empty */
  1038. STOP_DEPCA; /* Temporarily stop the depca. */
  1039. depca_init_ring(dev); /* Initialize the descriptor rings */
  1040. if (dev->flags & IFF_PROMISC) { /* Set promiscuous mode */
  1041. lp->init_block.mode |= PROM;
  1042. } else {
  1043. SetMulticastFilter(dev);
  1044. lp->init_block.mode &= ~PROM; /* Unset promiscuous mode */
  1045. }
  1046. LoadCSRs(dev); /* Reload CSR3 */
  1047. InitRestartDepca(dev); /* Resume normal operation. */
  1048. netif_start_queue(dev); /* Unlock the TX ring */
  1049. }
  1050. /*
  1051. ** Calculate the hash code and update the logical address filter
  1052. ** from a list of ethernet multicast addresses.
  1053. ** Big endian crc one liner is mine, all mine, ha ha ha ha!
  1054. ** LANCE calculates its hash codes big endian.
  1055. */
  1056. static void SetMulticastFilter(struct net_device *dev)
  1057. {
  1058. struct depca_private *lp = netdev_priv(dev);
  1059. struct dev_mc_list *dmi = dev->mc_list;
  1060. char *addrs;
  1061. int i, j, bit, byte;
  1062. u16 hashcode;
  1063. u32 crc;
  1064. if (dev->flags & IFF_ALLMULTI) { /* Set all multicast bits */
  1065. for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) {
  1066. lp->init_block.mcast_table[i] = (char) 0xff;
  1067. }
  1068. } else {
  1069. for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) { /* Clear the multicast table */
  1070. lp->init_block.mcast_table[i] = 0;
  1071. }
  1072. /* Add multicast addresses */
  1073. for (i = 0; i < dev->mc_count; i++) { /* for each address in the list */
  1074. addrs = dmi->dmi_addr;
  1075. dmi = dmi->next;
  1076. if ((*addrs & 0x01) == 1) { /* multicast address? */
  1077. crc = ether_crc(ETH_ALEN, addrs);
  1078. hashcode = (crc & 1); /* hashcode is 6 LSb of CRC ... */
  1079. for (j = 0; j < 5; j++) { /* ... in reverse order. */
  1080. hashcode = (hashcode << 1) | ((crc >>= 1) & 1);
  1081. }
  1082. byte = hashcode >> 3; /* bit[3-5] -> byte in filter */
  1083. bit = 1 << (hashcode & 0x07); /* bit[0-2] -> bit in byte */
  1084. lp->init_block.mcast_table[byte] |= bit;
  1085. }
  1086. }
  1087. }
  1088. return;
  1089. }
  1090. static int __init depca_common_init (u_long ioaddr, struct net_device **devp)
  1091. {
  1092. int status = 0;
  1093. if (!request_region (ioaddr, DEPCA_TOTAL_SIZE, depca_string)) {
  1094. status = -EBUSY;
  1095. goto out;
  1096. }
  1097. if (DevicePresent(ioaddr)) {
  1098. status = -ENODEV;
  1099. goto out_release;
  1100. }
  1101. if (!(*devp = alloc_etherdev (sizeof (struct depca_private)))) {
  1102. status = -ENOMEM;
  1103. goto out_release;
  1104. }
  1105. return 0;
  1106. out_release:
  1107. release_region (ioaddr, DEPCA_TOTAL_SIZE);
  1108. out:
  1109. return status;
  1110. }
  1111. #ifdef CONFIG_MCA
  1112. /*
  1113. ** Microchannel bus I/O device probe
  1114. */
  1115. static int __init depca_mca_probe(struct device *device)
  1116. {
  1117. unsigned char pos[2];
  1118. unsigned char where;
  1119. unsigned long iobase, mem_start;
  1120. int irq, err;
  1121. struct mca_device *mdev = to_mca_device (device);
  1122. struct net_device *dev;
  1123. struct depca_private *lp;
  1124. /*
  1125. ** Search for the adapter. If an address has been given, search
  1126. ** specifically for the card at that address. Otherwise find the
  1127. ** first card in the system.
  1128. */
  1129. pos[0] = mca_device_read_stored_pos(mdev, 2);
  1130. pos[1] = mca_device_read_stored_pos(mdev, 3);
  1131. /*
  1132. ** IO of card is handled by bits 1 and 2 of pos0.
  1133. **
  1134. ** bit2 bit1 IO
  1135. ** 0 0 0x2c00
  1136. ** 0 1 0x2c10
  1137. ** 1 0 0x2c20
  1138. ** 1 1 0x2c30
  1139. */
  1140. where = (pos[0] & 6) >> 1;
  1141. iobase = 0x2c00 + (0x10 * where);
  1142. /*
  1143. ** Found the adapter we were looking for. Now start setting it up.
  1144. **
  1145. ** First work on decoding the IRQ. It's stored in the lower 4 bits
  1146. ** of pos1. Bits are as follows (from the ADF file):
  1147. **
  1148. ** Bits
  1149. ** 3 2 1 0 IRQ
  1150. ** --------------------
  1151. ** 0 0 1 0 5
  1152. ** 0 0 0 1 9
  1153. ** 0 1 0 0 10
  1154. ** 1 0 0 0 11
  1155. */
  1156. where = pos[1] & 0x0f;
  1157. switch (where) {
  1158. case 1:
  1159. irq = 9;
  1160. break;
  1161. case 2:
  1162. irq = 5;
  1163. break;
  1164. case 4:
  1165. irq = 10;
  1166. break;
  1167. case 8:
  1168. irq = 11;
  1169. break;
  1170. default:
  1171. printk("%s: mca_probe IRQ error. You should never get here (%d).\n", mdev->name, where);
  1172. return -EINVAL;
  1173. }
  1174. /*
  1175. ** Shared memory address of adapter is stored in bits 3-5 of pos0.
  1176. ** They are mapped as follows:
  1177. **
  1178. ** Bit
  1179. ** 5 4 3 Memory Addresses
  1180. ** 0 0 0 C0000-CFFFF (64K)
  1181. ** 1 0 0 C8000-CFFFF (32K)
  1182. ** 0 0 1 D0000-DFFFF (64K)
  1183. ** 1 0 1 D8000-DFFFF (32K)
  1184. ** 0 1 0 E0000-EFFFF (64K)
  1185. ** 1 1 0 E8000-EFFFF (32K)
  1186. */
  1187. where = (pos[0] & 0x18) >> 3;
  1188. mem_start = 0xc0000 + (where * 0x10000);
  1189. if (pos[0] & 0x20) {
  1190. mem_start += 0x8000;
  1191. }
  1192. /* claim the slot */
  1193. strncpy(mdev->name, depca_mca_adapter_name[mdev->index],
  1194. sizeof(mdev->name));
  1195. mca_device_set_claim(mdev, 1);
  1196. /*
  1197. ** Get everything allocated and initialized... (almost just
  1198. ** like the ISA and EISA probes)
  1199. */
  1200. irq = mca_device_transform_irq(mdev, irq);
  1201. iobase = mca_device_transform_ioport(mdev, iobase);
  1202. if ((err = depca_common_init (iobase, &dev)))
  1203. goto out_unclaim;
  1204. dev->irq = irq;
  1205. dev->base_addr = iobase;
  1206. lp = netdev_priv(dev);
  1207. lp->depca_bus = DEPCA_BUS_MCA;
  1208. lp->adapter = depca_mca_adapter_type[mdev->index];
  1209. lp->mem_start = mem_start;
  1210. if ((err = depca_hw_init(dev, device)))
  1211. goto out_free;
  1212. return 0;
  1213. out_free:
  1214. free_netdev (dev);
  1215. release_region (iobase, DEPCA_TOTAL_SIZE);
  1216. out_unclaim:
  1217. mca_device_set_claim(mdev, 0);
  1218. return err;
  1219. }
  1220. #endif
  1221. /*
  1222. ** ISA bus I/O device probe
  1223. */
  1224. static void __init depca_platform_probe (void)
  1225. {
  1226. int i;
  1227. struct platform_device *pldev;
  1228. for (i = 0; depca_io_ports[i].iobase; i++) {
  1229. depca_io_ports[i].device = NULL;
  1230. /* if an address has been specified on the command
  1231. * line, use it (if valid) */
  1232. if (io && io != depca_io_ports[i].iobase)
  1233. continue;
  1234. pldev = platform_device_alloc(depca_string, i);
  1235. if (!pldev)
  1236. continue;
  1237. pldev->dev.platform_data = (void *) depca_io_ports[i].iobase;
  1238. depca_io_ports[i].device = pldev;
  1239. if (platform_device_add(pldev)) {
  1240. depca_io_ports[i].device = NULL;
  1241. pldev->dev.platform_data = NULL;
  1242. platform_device_put(pldev);
  1243. continue;
  1244. }
  1245. if (!pldev->dev.driver) {
  1246. /* The driver was not bound to this device, there was
  1247. * no hardware at this address. Unregister it, as the
  1248. * release fuction will take care of freeing the
  1249. * allocated structure */
  1250. depca_io_ports[i].device = NULL;
  1251. pldev->dev.platform_data = NULL;
  1252. platform_device_unregister (pldev);
  1253. }
  1254. }
  1255. }
  1256. static enum depca_type __init depca_shmem_probe (ulong *mem_start)
  1257. {
  1258. u_long mem_base[] = DEPCA_RAM_BASE_ADDRESSES;
  1259. enum depca_type adapter = unknown;
  1260. int i;
  1261. for (i = 0; mem_base[i]; i++) {
  1262. *mem_start = mem ? mem : mem_base[i];
  1263. adapter = DepcaSignature (adapter_name, *mem_start);
  1264. if (adapter != unknown)
  1265. break;
  1266. }
  1267. return adapter;
  1268. }
  1269. static int __init depca_isa_probe (struct platform_device *device)
  1270. {
  1271. struct net_device *dev;
  1272. struct depca_private *lp;
  1273. u_long ioaddr, mem_start = 0;
  1274. enum depca_type adapter = unknown;
  1275. int status = 0;
  1276. ioaddr = (u_long) device->dev.platform_data;
  1277. if ((status = depca_common_init (ioaddr, &dev)))
  1278. goto out;
  1279. adapter = depca_shmem_probe (&mem_start);
  1280. if (adapter == unknown) {
  1281. status = -ENODEV;
  1282. goto out_free;
  1283. }
  1284. dev->base_addr = ioaddr;
  1285. dev->irq = irq; /* Use whatever value the user gave
  1286. * us, and 0 if he didn't. */
  1287. lp = netdev_priv(dev);
  1288. lp->depca_bus = DEPCA_BUS_ISA;
  1289. lp->adapter = adapter;
  1290. lp->mem_start = mem_start;
  1291. if ((status = depca_hw_init(dev, &device->dev)))
  1292. goto out_free;
  1293. return 0;
  1294. out_free:
  1295. free_netdev (dev);
  1296. release_region (ioaddr, DEPCA_TOTAL_SIZE);
  1297. out:
  1298. return status;
  1299. }
  1300. /*
  1301. ** EISA callbacks from sysfs.
  1302. */
  1303. #ifdef CONFIG_EISA
  1304. static int __init depca_eisa_probe (struct device *device)
  1305. {
  1306. enum depca_type adapter = unknown;
  1307. struct eisa_device *edev;
  1308. struct net_device *dev;
  1309. struct depca_private *lp;
  1310. u_long ioaddr, mem_start;
  1311. int status = 0;
  1312. edev = to_eisa_device (device);
  1313. ioaddr = edev->base_addr + DEPCA_EISA_IO_PORTS;
  1314. if ((status = depca_common_init (ioaddr, &dev)))
  1315. goto out;
  1316. /* It would have been nice to get card configuration from the
  1317. * card. Unfortunately, this register is write-only (shares
  1318. * it's address with the ethernet prom)... As we don't parse
  1319. * the EISA configuration structures (yet... :-), just rely on
  1320. * the ISA probing to sort it out... */
  1321. adapter = depca_shmem_probe (&mem_start);
  1322. if (adapter == unknown) {
  1323. status = -ENODEV;
  1324. goto out_free;
  1325. }
  1326. dev->base_addr = ioaddr;
  1327. dev->irq = irq;
  1328. lp = netdev_priv(dev);
  1329. lp->depca_bus = DEPCA_BUS_EISA;
  1330. lp->adapter = edev->id.driver_data;
  1331. lp->mem_start = mem_start;
  1332. if ((status = depca_hw_init(dev, device)))
  1333. goto out_free;
  1334. return 0;
  1335. out_free:
  1336. free_netdev (dev);
  1337. release_region (ioaddr, DEPCA_TOTAL_SIZE);
  1338. out:
  1339. return status;
  1340. }
  1341. #endif
  1342. static int __devexit depca_device_remove (struct device *device)
  1343. {
  1344. struct net_device *dev;
  1345. struct depca_private *lp;
  1346. int bus;
  1347. dev = dev_get_drvdata(device);
  1348. lp = netdev_priv(dev);
  1349. unregister_netdev (dev);
  1350. iounmap (lp->sh_mem);
  1351. release_mem_region (lp->mem_start, lp->mem_len);
  1352. release_region (dev->base_addr, DEPCA_TOTAL_SIZE);
  1353. bus = lp->depca_bus;
  1354. free_netdev (dev);
  1355. return 0;
  1356. }
  1357. /*
  1358. ** Look for a particular board name in the on-board Remote Diagnostics
  1359. ** and Boot (readb) ROM. This will also give us a clue to the network RAM
  1360. ** base address.
  1361. */
  1362. static int __init DepcaSignature(char *name, u_long base_addr)
  1363. {
  1364. u_int i, j, k;
  1365. void __iomem *ptr;
  1366. char tmpstr[16];
  1367. u_long prom_addr = base_addr + 0xc000;
  1368. u_long mem_addr = base_addr + 0x8000; /* 32KB */
  1369. /* Can't reserve the prom region, it is already marked as
  1370. * used, at least on x86. Instead, reserve a memory region a
  1371. * board would certainly use. If it works, go ahead. If not,
  1372. * run like hell... */
  1373. if (!request_mem_region (mem_addr, 16, depca_string))
  1374. return unknown;
  1375. /* Copy the first 16 bytes of ROM */
  1376. ptr = ioremap(prom_addr, 16);
  1377. if (ptr == NULL) {
  1378. printk(KERN_ERR "depca: I/O remap failed at %lx\n", prom_addr);
  1379. return unknown;
  1380. }
  1381. for (i = 0; i < 16; i++) {
  1382. tmpstr[i] = readb(ptr + i);
  1383. }
  1384. iounmap(ptr);
  1385. release_mem_region (mem_addr, 16);
  1386. /* Check if PROM contains a valid string */
  1387. for (i = 0; *depca_signature[i] != '\0'; i++) {
  1388. for (j = 0, k = 0; j < 16 && k < strlen(depca_signature[i]); j++) {
  1389. if (depca_signature[i][k] == tmpstr[j]) { /* track signature */
  1390. k++;
  1391. } else { /* lost signature; begin search again */
  1392. k = 0;
  1393. }
  1394. }
  1395. if (k == strlen(depca_signature[i]))
  1396. break;
  1397. }
  1398. /* Check if name string is valid, provided there's no PROM */
  1399. if (name && *name && (i == unknown)) {
  1400. for (i = 0; *depca_signature[i] != '\0'; i++) {
  1401. if (strcmp(name, depca_signature[i]) == 0)
  1402. break;
  1403. }
  1404. }
  1405. return i;
  1406. }
  1407. /*
  1408. ** Look for a special sequence in the Ethernet station address PROM that
  1409. ** is common across all DEPCA products. Note that the original DEPCA needs
  1410. ** its ROM address counter to be initialized and enabled. Only enable
  1411. ** if the first address octet is a 0x08 - this minimises the chances of
  1412. ** messing around with some other hardware, but it assumes that this DEPCA
  1413. ** card initialized itself correctly.
  1414. **
  1415. ** Search the Ethernet address ROM for the signature. Since the ROM address
  1416. ** counter can start at an arbitrary point, the search must include the entire
  1417. ** probe sequence length plus the (length_of_the_signature - 1).
  1418. ** Stop the search IMMEDIATELY after the signature is found so that the
  1419. ** PROM address counter is correctly positioned at the start of the
  1420. ** ethernet address for later read out.
  1421. */
  1422. static int __init DevicePresent(u_long ioaddr)
  1423. {
  1424. union {
  1425. struct {
  1426. u32 a;
  1427. u32 b;
  1428. } llsig;
  1429. char Sig[sizeof(u32) << 1];
  1430. }
  1431. d

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