You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

depca.c 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. /* #warning "depca.c: FIXME: fix relocation" */
  2. FILE_LICENCE ( GPL_ANY );
  3. #if 0
  4. /* Not fixed for relocation yet. Probably won't work relocated above 16MB */
  5. #ifdef ALLMULTI
  6. #error multicast support is not yet implemented
  7. #endif
  8. /* Etherboot: depca.h merged, comments from Linux driver retained */
  9. /* depca.c: A DIGITAL DEPCA & EtherWORKS ethernet driver for linux.
  10. Written 1994, 1995 by David C. Davies.
  11. Copyright 1994 David C. Davies
  12. and
  13. United States Government
  14. (as represented by the Director, National Security Agency).
  15. Copyright 1995 Digital Equipment Corporation.
  16. This software may be used and distributed according to the terms of
  17. the GNU Public License, incorporated herein by reference.
  18. This driver is written for the Digital Equipment Corporation series
  19. of DEPCA and EtherWORKS ethernet cards:
  20. DEPCA (the original)
  21. DE100
  22. DE101
  23. DE200 Turbo
  24. DE201 Turbo
  25. DE202 Turbo (TP BNC)
  26. DE210
  27. DE422 (EISA)
  28. The driver has been tested on DE100, DE200 and DE202 cards in a
  29. relatively busy network. The DE422 has been tested a little.
  30. This driver will NOT work for the DE203, DE204 and DE205 series of
  31. cards, since they have a new custom ASIC in place of the AMD LANCE
  32. chip. See the 'ewrk3.c' driver in the Linux source tree for running
  33. those cards.
  34. I have benchmarked the driver with a DE100 at 595kB/s to (542kB/s from)
  35. a DECstation 5000/200.
  36. The author may be reached at davies@maniac.ultranet.com
  37. =========================================================================
  38. The driver was originally based on the 'lance.c' driver from Donald
  39. Becker which is included with the standard driver distribution for
  40. linux. V0.4 is a complete re-write with only the kernel interface
  41. remaining from the original code.
  42. 1) Lance.c code in /linux/drivers/net/
  43. 2) "Ethernet/IEEE 802.3 Family. 1992 World Network Data Book/Handbook",
  44. AMD, 1992 [(800) 222-9323].
  45. 3) "Am79C90 CMOS Local Area Network Controller for Ethernet (C-LANCE)",
  46. AMD, Pub. #17881, May 1993.
  47. 4) "Am79C960 PCnet-ISA(tm), Single-Chip Ethernet Controller for ISA",
  48. AMD, Pub. #16907, May 1992
  49. 5) "DEC EtherWORKS LC Ethernet Controller Owners Manual",
  50. Digital Equipment corporation, 1990, Pub. #EK-DE100-OM.003
  51. 6) "DEC EtherWORKS Turbo Ethernet Controller Owners Manual",
  52. Digital Equipment corporation, 1990, Pub. #EK-DE200-OM.003
  53. 7) "DEPCA Hardware Reference Manual", Pub. #EK-DEPCA-PR
  54. Digital Equipment Corporation, 1989
  55. 8) "DEC EtherWORKS Turbo_(TP BNC) Ethernet Controller Owners Manual",
  56. Digital Equipment corporation, 1991, Pub. #EK-DE202-OM.001
  57. Peter Bauer's depca.c (V0.5) was referred to when debugging V0.1 of this
  58. driver.
  59. The original DEPCA card requires that the ethernet ROM address counter
  60. be enabled to count and has an 8 bit NICSR. The ROM counter enabling is
  61. only done when a 0x08 is read as the first address octet (to minimise
  62. the chances of writing over some other hardware's I/O register). The
  63. NICSR accesses have been changed to byte accesses for all the cards
  64. supported by this driver, since there is only one useful bit in the MSB
  65. (remote boot timeout) and it is not used. Also, there is a maximum of
  66. only 48kB network RAM for this card. My thanks to Torbjorn Lindh for
  67. help debugging all this (and holding my feet to the fire until I got it
  68. right).
  69. The DE200 series boards have on-board 64kB RAM for use as a shared
  70. memory network buffer. Only the DE100 cards make use of a 2kB buffer
  71. mode which has not been implemented in this driver (only the 32kB and
  72. 64kB modes are supported [16kB/48kB for the original DEPCA]).
  73. At the most only 2 DEPCA cards can be supported on the ISA bus because
  74. there is only provision for two I/O base addresses on each card (0x300
  75. and 0x200). The I/O address is detected by searching for a byte sequence
  76. in the Ethernet station address PROM at the expected I/O address for the
  77. Ethernet PROM. The shared memory base address is 'autoprobed' by
  78. looking for the self test PROM and detecting the card name. When a
  79. second DEPCA is detected, information is placed in the base_addr
  80. variable of the next device structure (which is created if necessary),
  81. thus enabling ethif_probe initialization for the device. More than 2
  82. EISA cards can be supported, but care will be needed assigning the
  83. shared memory to ensure that each slot has the correct IRQ, I/O address
  84. and shared memory address assigned.
  85. ************************************************************************
  86. NOTE: If you are using two ISA DEPCAs, it is important that you assign
  87. the base memory addresses correctly. The driver autoprobes I/O 0x300
  88. then 0x200. The base memory address for the first device must be less
  89. than that of the second so that the auto probe will correctly assign the
  90. I/O and memory addresses on the same card. I can't think of a way to do
  91. this unambiguously at the moment, since there is nothing on the cards to
  92. tie I/O and memory information together.
  93. I am unable to test 2 cards together for now, so this code is
  94. unchecked. All reports, good or bad, are welcome.
  95. ************************************************************************
  96. The board IRQ setting must be at an unused IRQ which is auto-probed
  97. using Donald Becker's autoprobe routines. DEPCA and DE100 board IRQs are
  98. {2,3,4,5,7}, whereas the DE200 is at {5,9,10,11,15}. Note that IRQ2 is
  99. really IRQ9 in machines with 16 IRQ lines.
  100. No 16MB memory limitation should exist with this driver as DMA is not
  101. used and the common memory area is in low memory on the network card (my
  102. current system has 20MB and I've not had problems yet).
  103. The ability to load this driver as a loadable module has been added. To
  104. utilise this ability, you have to do <8 things:
  105. 0) have a copy of the loadable modules code installed on your system.
  106. 1) copy depca.c from the /linux/drivers/net directory to your favourite
  107. temporary directory.
  108. 2) if you wish, edit the source code near line 1530 to reflect the I/O
  109. address and IRQ you're using (see also 5).
  110. 3) compile depca.c, but include -DMODULE in the command line to ensure
  111. that the correct bits are compiled (see end of source code).
  112. 4) if you are wanting to add a new card, goto 5. Otherwise, recompile a
  113. kernel with the depca configuration turned off and reboot.
  114. 5) insmod depca.o [irq=7] [io=0x200] [mem=0xd0000] [adapter_name=DE100]
  115. [Alan Cox: Changed the code to allow command line irq/io assignments]
  116. [Dave Davies: Changed the code to allow command line mem/name
  117. assignments]
  118. 6) run the net startup bits for your eth?? interface manually
  119. (usually /etc/rc.inet[12] at boot time).
  120. 7) enjoy!
  121. Note that autoprobing is not allowed in loadable modules - the system is
  122. already up and running and you're messing with interrupts.
  123. To unload a module, turn off the associated interface
  124. 'ifconfig eth?? down' then 'rmmod depca'.
  125. To assign a base memory address for the shared memory when running as a
  126. loadable module, see 5 above. To include the adapter name (if you have
  127. no PROM but know the card name) also see 5 above. Note that this last
  128. option will not work with kernel built-in depca's.
  129. The shared memory assignment for a loadable module makes sense to avoid
  130. the 'memory autoprobe' picking the wrong shared memory (for the case of
  131. 2 depca's in a PC).
  132. ************************************************************************
  133. Support for MCA EtherWORKS cards added 11-3-98.
  134. Verified to work with up to 2 DE212 cards in a system (although not
  135. fully stress-tested).
  136. Currently known bugs/limitations:
  137. Note: with the MCA stuff as a module, it trusts the MCA configuration,
  138. not the command line for IRQ and memory address. You can
  139. specify them if you want, but it will throw your values out.
  140. You still have to pass the IO address it was configured as
  141. though.
  142. ************************************************************************
  143. TO DO:
  144. ------
  145. Revision History
  146. ----------------
  147. Version Date Description
  148. 0.1 25-jan-94 Initial writing.
  149. 0.2 27-jan-94 Added LANCE TX hardware buffer chaining.
  150. 0.3 1-feb-94 Added multiple DEPCA support.
  151. 0.31 4-feb-94 Added DE202 recognition.
  152. 0.32 19-feb-94 Tidy up. Improve multi-DEPCA support.
  153. 0.33 25-feb-94 Fix DEPCA ethernet ROM counter enable.
  154. Add jabber packet fix from murf@perftech.com
  155. and becker@super.org
  156. 0.34 7-mar-94 Fix DEPCA max network memory RAM & NICSR access.
  157. 0.35 8-mar-94 Added DE201 recognition. Tidied up.
  158. 0.351 30-apr-94 Added EISA support. Added DE422 recognition.
  159. 0.36 16-may-94 DE422 fix released.
  160. 0.37 22-jul-94 Added MODULE support
  161. 0.38 15-aug-94 Added DBR ROM switch in depca_close().
  162. Multi DEPCA bug fix.
  163. 0.38axp 15-sep-94 Special version for Alpha AXP Linux V1.0.
  164. 0.381 12-dec-94 Added DE101 recognition, fix multicast bug.
  165. 0.382 9-feb-95 Fix recognition bug reported by <bkm@star.rl.ac.uk>.
  166. 0.383 22-feb-95 Fix for conflict with VESA SCSI reported by
  167. <stromain@alf.dec.com>
  168. 0.384 17-mar-95 Fix a ring full bug reported by <bkm@star.rl.ac.uk>
  169. 0.385 3-apr-95 Fix a recognition bug reported by
  170. <ryan.niemi@lastfrontier.com>
  171. 0.386 21-apr-95 Fix the last fix...sorry, must be galloping senility
  172. 0.40 25-May-95 Rewrite for portability & updated.
  173. ALPHA support from <jestabro@amt.tay1.dec.com>
  174. 0.41 26-Jun-95 Added verify_area() calls in depca_ioctl() from
  175. suggestion by <heiko@colossus.escape.de>
  176. 0.42 27-Dec-95 Add 'mem' shared memory assignment for loadable
  177. modules.
  178. Add 'adapter_name' for loadable modules when no PROM.
  179. Both above from a suggestion by
  180. <pchen@woodruffs121.residence.gatech.edu>.
  181. Add new multicasting code.
  182. 0.421 22-Apr-96 Fix alloc_device() bug <jari@markkus2.fimr.fi>
  183. 0.422 29-Apr-96 Fix depca_hw_init() bug <jari@markkus2.fimr.fi>
  184. 0.423 7-Jun-96 Fix module load bug <kmg@barco.be>
  185. 0.43 16-Aug-96 Update alloc_device() to conform to de4x5.c
  186. 0.44 1-Sep-97 Fix *_probe() to test check_region() first - bug
  187. reported by <mmogilvi@elbert.uccs.edu>
  188. 0.45 3-Nov-98 Added support for MCA EtherWORKS (DE210/DE212) cards
  189. by <tymm@computer.org>
  190. 0.451 5-Nov-98 Fixed mca stuff cuz I'm a dummy. <tymm@computer.org>
  191. 0.5 14-Nov-98 Re-spin for 2.1.x kernels.
  192. 0.51 27-Jun-99 Correct received packet length for CRC from
  193. report by <worm@dkik.dk>
  194. =========================================================================
  195. */
  196. #include "etherboot.h"
  197. #include "nic.h"
  198. #include <ipxe/isa.h>
  199. #include "console.h"
  200. #include <ipxe/ethernet.h>
  201. /*
  202. ** I/O addresses. Note that the 2k buffer option is not supported in
  203. ** this driver.
  204. */
  205. #define DEPCA_NICSR 0x00 /* Network interface CSR */
  206. #define DEPCA_RBI 0x02 /* RAM buffer index (2k buffer mode) */
  207. #define DEPCA_DATA 0x04 /* LANCE registers' data port */
  208. #define DEPCA_ADDR 0x06 /* LANCE registers' address port */
  209. #define DEPCA_HBASE 0x08 /* EISA high memory base address reg. */
  210. #define DEPCA_PROM 0x0c /* Ethernet address ROM data port */
  211. #define DEPCA_CNFG 0x0c /* EISA Configuration port */
  212. #define DEPCA_RBSA 0x0e /* RAM buffer starting address (2k buff.) */
  213. /*
  214. ** These are LANCE registers addressable through nic->ioaddr + DEPCA_ADDR
  215. */
  216. #define CSR0 0
  217. #define CSR1 1
  218. #define CSR2 2
  219. #define CSR3 3
  220. /*
  221. ** NETWORK INTERFACE CSR (NI_CSR) bit definitions
  222. */
  223. #define TO 0x0100 /* Time Out for remote boot */
  224. #define SHE 0x0080 /* SHadow memory Enable */
  225. #define BS 0x0040 /* Bank Select */
  226. #define BUF 0x0020 /* BUFfer size (1->32k, 0->64k) */
  227. #define RBE 0x0010 /* Remote Boot Enable (1->net boot) */
  228. #define AAC 0x0008 /* Address ROM Address Counter (1->enable) */
  229. #define _128KB 0x0008 /* 128kB Network RAM (1->enable) */
  230. #define IM 0x0004 /* Interrupt Mask (1->mask) */
  231. #define IEN 0x0002 /* Interrupt tristate ENable (1->enable) */
  232. #define LED 0x0001 /* LED control */
  233. /*
  234. ** Control and Status Register 0 (CSR0) bit definitions
  235. */
  236. #define ERR 0x8000 /* Error summary */
  237. #define BABL 0x4000 /* Babble transmitter timeout error */
  238. #define CERR 0x2000 /* Collision Error */
  239. #define MISS 0x1000 /* Missed packet */
  240. #define MERR 0x0800 /* Memory Error */
  241. #define RINT 0x0400 /* Receiver Interrupt */
  242. #define TINT 0x0200 /* Transmit Interrupt */
  243. #define IDON 0x0100 /* Initialization Done */
  244. #define INTR 0x0080 /* Interrupt Flag */
  245. #define INEA 0x0040 /* Interrupt Enable */
  246. #define RXON 0x0020 /* Receiver on */
  247. #define TXON 0x0010 /* Transmitter on */
  248. #define TDMD 0x0008 /* Transmit Demand */
  249. #define STOP 0x0004 /* Stop */
  250. #define STRT 0x0002 /* Start */
  251. #define INIT 0x0001 /* Initialize */
  252. #define INTM 0xff00 /* Interrupt Mask */
  253. #define INTE 0xfff0 /* Interrupt Enable */
  254. /*
  255. ** CONTROL AND STATUS REGISTER 3 (CSR3)
  256. */
  257. #define BSWP 0x0004 /* Byte SWaP */
  258. #define ACON 0x0002 /* ALE control */
  259. #define BCON 0x0001 /* Byte CONtrol */
  260. /*
  261. ** Initialization Block Mode Register
  262. */
  263. #define PROM 0x8000 /* Promiscuous Mode */
  264. #define EMBA 0x0080 /* Enable Modified Back-off Algorithm */
  265. #define INTL 0x0040 /* Internal Loopback */
  266. #define DRTY 0x0020 /* Disable Retry */
  267. #define COLL 0x0010 /* Force Collision */
  268. #define DTCR 0x0008 /* Disable Transmit CRC */
  269. #define LOOP 0x0004 /* Loopback */
  270. #define DTX 0x0002 /* Disable the Transmitter */
  271. #define DRX 0x0001 /* Disable the Receiver */
  272. /*
  273. ** Receive Message Descriptor 1 (RMD1) bit definitions.
  274. */
  275. #define R_OWN 0x80000000 /* Owner bit 0 = host, 1 = lance */
  276. #define R_ERR 0x4000 /* Error Summary */
  277. #define R_FRAM 0x2000 /* Framing Error */
  278. #define R_OFLO 0x1000 /* Overflow Error */
  279. #define R_CRC 0x0800 /* CRC Error */
  280. #define R_BUFF 0x0400 /* Buffer Error */
  281. #define R_STP 0x0200 /* Start of Packet */
  282. #define R_ENP 0x0100 /* End of Packet */
  283. /*
  284. ** Transmit Message Descriptor 1 (TMD1) bit definitions.
  285. */
  286. #define T_OWN 0x80000000 /* Owner bit 0 = host, 1 = lance */
  287. #define T_ERR 0x4000 /* Error Summary */
  288. #define T_ADD_FCS 0x2000 /* More the 1 retry needed to Xmit */
  289. #define T_MORE 0x1000 /* >1 retry to transmit packet */
  290. #define T_ONE 0x0800 /* 1 try needed to transmit the packet */
  291. #define T_DEF 0x0400 /* Deferred */
  292. #define T_STP 0x02000000 /* Start of Packet */
  293. #define T_ENP 0x01000000 /* End of Packet */
  294. #define T_FLAGS 0xff000000 /* TX Flags Field */
  295. /*
  296. ** Transmit Message Descriptor 3 (TMD3) bit definitions.
  297. */
  298. #define TMD3_BUFF 0x8000 /* BUFFer error */
  299. #define TMD3_UFLO 0x4000 /* UnderFLOw error */
  300. #define TMD3_RES 0x2000 /* REServed */
  301. #define TMD3_LCOL 0x1000 /* Late COLlision */
  302. #define TMD3_LCAR 0x0800 /* Loss of CARrier */
  303. #define TMD3_RTRY 0x0400 /* ReTRY error */
  304. /*
  305. ** Ethernet PROM defines
  306. */
  307. #define PROBE_LENGTH 32
  308. /*
  309. ** Set the number of Tx and Rx buffers. Ensure that the memory requested
  310. ** here is <= to the amount of shared memory set up by the board switches.
  311. ** The number of descriptors MUST BE A POWER OF 2.
  312. **
  313. ** total_memory = NUM_RX_DESC*(8+RX_BUFF_SZ) + NUM_TX_DESC*(8+TX_BUFF_SZ)
  314. */
  315. #define NUM_RX_DESC 2 /* Number of RX descriptors */
  316. #define NUM_TX_DESC 2 /* Number of TX descriptors */
  317. #define RX_BUFF_SZ 1536 /* Buffer size for each Rx buffer */
  318. #define TX_BUFF_SZ 1536 /* Buffer size for each Tx buffer */
  319. /*
  320. ** ISA Bus defines
  321. */
  322. #ifndef DEPCA_MODEL
  323. #define DEPCA_MODEL DEPCA
  324. #endif
  325. static enum {
  326. DEPCA, DE100, DE101, DE200, DE201, DE202, DE210, DE212, DE422, unknown
  327. } adapter = DEPCA_MODEL;
  328. /*
  329. ** Name <-> Adapter mapping
  330. */
  331. static char *adapter_name[] = {
  332. "DEPCA",
  333. "DE100","DE101",
  334. "DE200","DE201","DE202",
  335. "DE210","DE212",
  336. "DE422",
  337. ""
  338. };
  339. #ifndef DEPCA_RAM_BASE
  340. #define DEPCA_RAM_BASE 0xd0000
  341. #endif
  342. /*
  343. ** Memory Alignment. Each descriptor is 4 longwords long. To force a
  344. ** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and
  345. ** DESC_ALIGN. ALIGN aligns the start address of the private memory area
  346. ** and hence the RX descriptor ring's first entry.
  347. */
  348. #define ALIGN4 ((u32)4 - 1) /* 1 longword align */
  349. #define ALIGN8 ((u32)8 - 1) /* 2 longword (quadword) align */
  350. #define ALIGN ALIGN8 /* Keep the LANCE happy... */
  351. /*
  352. ** The DEPCA Rx and Tx ring descriptors.
  353. */
  354. struct depca_rx_desc {
  355. volatile s32 base;
  356. s16 buf_length; /* This length is negative 2's complement! */
  357. s16 msg_length; /* This length is "normal". */
  358. };
  359. struct depca_tx_desc {
  360. volatile s32 base;
  361. s16 length; /* This length is negative 2's complement! */
  362. s16 misc; /* Errors and TDR info */
  363. };
  364. #define LA_MASK 0x0000ffff /* LANCE address mask for mapping network RAM
  365. to LANCE memory address space */
  366. /*
  367. ** The Lance initialization block, described in databook, in common memory.
  368. */
  369. struct depca_init {
  370. u16 mode; /* Mode register */
  371. u8 phys_addr[ETH_ALEN]; /* Physical ethernet address */
  372. u8 mcast_table[8]; /* Multicast Hash Table. */
  373. u32 rx_ring; /* Rx ring base pointer & ring length */
  374. u32 tx_ring; /* Tx ring base pointer & ring length */
  375. };
  376. struct depca_private {
  377. struct depca_rx_desc *rx_ring;
  378. struct depca_tx_desc *tx_ring;
  379. struct depca_init init_block; /* Shadow init block */
  380. char *rx_memcpy[NUM_RX_DESC];
  381. char *tx_memcpy[NUM_TX_DESC];
  382. u32 bus_offset; /* ISA bus address offset */
  383. u32 sh_mem; /* address of shared mem */
  384. u32 dma_buffs; /* Rx & Tx buffer start */
  385. int rx_cur, tx_cur; /* Next free ring entry */
  386. int txRingMask, rxRingMask;
  387. s32 rx_rlen, tx_rlen;
  388. /* log2([rt]xRingMask+1) for the descriptors */
  389. };
  390. static Address mem_start = DEPCA_RAM_BASE;
  391. static Address mem_len, offset;
  392. static struct depca_private lp;
  393. /*
  394. ** Miscellaneous defines...
  395. */
  396. #define STOP_DEPCA(ioaddr) \
  397. outw(CSR0, ioaddr + DEPCA_ADDR);\
  398. outw(STOP, ioaddr + DEPCA_DATA)
  399. /* Initialize the lance Rx and Tx descriptor rings. */
  400. static void depca_init_ring(struct nic *nic)
  401. {
  402. int i;
  403. u32 p;
  404. lp.rx_cur = lp.tx_cur = 0;
  405. /* Initialize the base addresses and length of each buffer in the ring */
  406. for (i = 0; i <= lp.rxRingMask; i++) {
  407. writel((p = lp.dma_buffs + i * RX_BUFF_SZ) | R_OWN, &lp.rx_ring[i].base);
  408. writew(-RX_BUFF_SZ, &lp.rx_ring[i].buf_length);
  409. lp.rx_memcpy[i] = (char *) (p + lp.bus_offset);
  410. }
  411. for (i = 0; i <= lp.txRingMask; i++) {
  412. writel((p = lp.dma_buffs + (i + lp.txRingMask + 1) * TX_BUFF_SZ) & 0x00ffffff, &lp.tx_ring[i].base);
  413. lp.tx_memcpy[i] = (char *) (p + lp.bus_offset);
  414. }
  415. /* Set up the initialization block */
  416. lp.init_block.rx_ring = ((u32) ((u32) lp.rx_ring) & LA_MASK) | lp.rx_rlen;
  417. lp.init_block.tx_ring = ((u32) ((u32) lp.tx_ring) & LA_MASK) | lp.tx_rlen;
  418. for (i = 0; i < ETH_ALEN; i++)
  419. lp.init_block.phys_addr[i] = nic->node_addr[i];
  420. lp.init_block.mode = 0x0000; /* Enable the Tx and Rx */
  421. memset(lp.init_block.mcast_table, 0, sizeof(lp.init_block.mcast_table));
  422. }
  423. static inline void LoadCSRs(struct nic *nic)
  424. {
  425. outw(CSR1, nic->ioaddr + DEPCA_ADDR); /* initialisation block address LSW */
  426. outw((u16) (lp.sh_mem & LA_MASK), nic->ioaddr + DEPCA_DATA);
  427. outw(CSR2, nic->ioaddr + DEPCA_ADDR); /* initialisation block address MSW */
  428. outw((u16) ((lp.sh_mem & LA_MASK) >> 16), nic->ioaddr + DEPCA_DATA);
  429. outw(CSR3, nic->ioaddr + DEPCA_ADDR); /* ALE control */
  430. outw(ACON, nic->ioaddr + DEPCA_DATA);
  431. outw(CSR0, nic->ioaddr + DEPCA_ADDR); /* Point back to CSR0 */
  432. }
  433. static inline int InitRestartDepca(struct nic *nic)
  434. {
  435. int i;
  436. /* Copy the shadow init_block to shared memory */
  437. memcpy_toio((char *)lp.sh_mem, &lp.init_block, sizeof(struct depca_init));
  438. outw(CSR0, nic->ioaddr + DEPCA_ADDR); /* point back to CSR0 */
  439. outw(INIT, nic->ioaddr + DEPCA_DATA); /* initialise DEPCA */
  440. for (i = 0; i < 100 && !(inw(nic->ioaddr + DEPCA_DATA) & IDON); i++)
  441. ;
  442. if (i < 100) {
  443. /* clear IDON by writing a 1, and start LANCE */
  444. outw(IDON | STRT, nic->ioaddr + DEPCA_DATA);
  445. } else {
  446. printf("DEPCA not initialised\n");
  447. return (1);
  448. }
  449. return (0);
  450. }
  451. /**************************************************************************
  452. RESET - Reset adapter
  453. ***************************************************************************/
  454. static void depca_reset(struct nic *nic)
  455. {
  456. s16 nicsr;
  457. int i, j;
  458. STOP_DEPCA(nic->ioaddr);
  459. nicsr = inb(nic->ioaddr + DEPCA_NICSR);
  460. nicsr = ((nicsr & ~SHE & ~RBE & ~IEN) | IM);
  461. outb(nicsr, nic->ioaddr + DEPCA_NICSR);
  462. if (inw(nic->ioaddr + DEPCA_DATA) != STOP)
  463. {
  464. printf("depca: Cannot stop NIC\n");
  465. return;
  466. }
  467. /* Initialisation block */
  468. lp.sh_mem = mem_start;
  469. mem_start += sizeof(struct depca_init);
  470. /* Tx & Rx descriptors (aligned to a quadword boundary) */
  471. mem_start = (mem_start + ALIGN) & ~ALIGN;
  472. lp.rx_ring = (struct depca_rx_desc *) mem_start;
  473. mem_start += (sizeof(struct depca_rx_desc) * NUM_RX_DESC);
  474. lp.tx_ring = (struct depca_tx_desc *) mem_start;
  475. mem_start += (sizeof(struct depca_tx_desc) * NUM_TX_DESC);
  476. lp.bus_offset = mem_start & 0x00ff0000;
  477. /* LANCE re-mapped start address */
  478. lp.dma_buffs = mem_start & LA_MASK;
  479. /* Finish initialising the ring information. */
  480. lp.rxRingMask = NUM_RX_DESC - 1;
  481. lp.txRingMask = NUM_TX_DESC - 1;
  482. /* Calculate Tx/Rx RLEN size for the descriptors. */
  483. for (i = 0, j = lp.rxRingMask; j > 0; i++) {
  484. j >>= 1;
  485. }
  486. lp.rx_rlen = (s32) (i << 29);
  487. for (i = 0, j = lp.txRingMask; j > 0; i++) {
  488. j >>= 1;
  489. }
  490. lp.tx_rlen = (s32) (i << 29);
  491. /* Load the initialisation block */
  492. depca_init_ring(nic);
  493. LoadCSRs(nic);
  494. InitRestartDepca(nic);
  495. }
  496. /**************************************************************************
  497. POLL - Wait for a frame
  498. ***************************************************************************/
  499. static int depca_poll(struct nic *nic, int retrieve)
  500. {
  501. int entry;
  502. u32 status;
  503. entry = lp.rx_cur;
  504. if ((status = readl(&lp.rx_ring[entry].base) & R_OWN))
  505. return (0);
  506. if ( ! retrieve ) return 1;
  507. memcpy(nic->packet, lp.rx_memcpy[entry], nic->packetlen = lp.rx_ring[entry].msg_length);
  508. lp.rx_ring[entry].base |= R_OWN;
  509. lp.rx_cur = (++lp.rx_cur) & lp.rxRingMask;
  510. return (1);
  511. }
  512. /**************************************************************************
  513. TRANSMIT - Transmit a frame
  514. ***************************************************************************/
  515. static void depca_transmit(
  516. struct nic *nic,
  517. const char *d, /* Destination */
  518. unsigned int t, /* Type */
  519. unsigned int s, /* size */
  520. const char *p) /* Packet */
  521. {
  522. int entry, len;
  523. char *mem;
  524. /* send the packet to destination */
  525. /*
  526. ** Caution: the right order is important here... dont
  527. ** setup the ownership rights until all the other
  528. ** information is in place
  529. */
  530. mem = lp.tx_memcpy[entry = lp.tx_cur];
  531. memcpy_toio(mem, d, ETH_ALEN);
  532. memcpy_toio(mem + ETH_ALEN, nic->node_addr, ETH_ALEN);
  533. mem[ETH_ALEN * 2] = t >> 8;
  534. mem[ETH_ALEN * 2 + 1] = t;
  535. memcpy_toio(mem + ETH_HLEN, p, s);
  536. s += ETH_HLEN;
  537. len = (s < ETH_ZLEN ? ETH_ZLEN : s);
  538. /* clean out flags */
  539. writel(readl(&lp.tx_ring[entry].base) & ~T_FLAGS, &lp.tx_ring[entry].base);
  540. /* clears other error flags */
  541. writew(0x0000, &lp.tx_ring[entry].misc);
  542. /* packet length in buffer */
  543. writew(-len, &lp.tx_ring[entry].length);
  544. /* start and end of packet, ownership */
  545. writel(readl(&lp.tx_ring[entry].base) | (T_STP|T_ENP|T_OWN), &lp.tx_ring[entry].base);
  546. /* update current pointers */
  547. lp.tx_cur = (++lp.tx_cur) & lp.txRingMask;
  548. }
  549. /**************************************************************************
  550. DISABLE - Turn off ethernet interface
  551. ***************************************************************************/
  552. static void depca_disable ( struct nic *nic ) {
  553. depca_reset(nic);
  554. STOP_DEPCA(nic->ioaddr);
  555. }
  556. /**************************************************************************
  557. IRQ - Interrupt Control
  558. ***************************************************************************/
  559. static void depca_irq(struct nic *nic __unused, irq_action_t action __unused)
  560. {
  561. switch ( action ) {
  562. case DISABLE :
  563. break;
  564. case ENABLE :
  565. break;
  566. case FORCE :
  567. break;
  568. }
  569. }
  570. /*
  571. ** Look for a special sequence in the Ethernet station address PROM that
  572. ** is common across all DEPCA products. Note that the original DEPCA needs
  573. ** its ROM address counter to be initialized and enabled. Only enable
  574. ** if the first address octet is a 0x08 - this minimises the chances of
  575. ** messing around with some other hardware, but it assumes that this DEPCA
  576. ** card initialized itself correctly.
  577. **
  578. ** Search the Ethernet address ROM for the signature. Since the ROM address
  579. ** counter can start at an arbitrary point, the search must include the entire
  580. ** probe sequence length plus the (length_of_the_signature - 1).
  581. ** Stop the search IMMEDIATELY after the signature is found so that the
  582. ** PROM address counter is correctly positioned at the start of the
  583. ** ethernet address for later read out.
  584. */
  585. /*
  586. * Ugly, ugly, ugly. I can't quite make out where the split should be
  587. * between probe1 and probe()...
  588. *
  589. */
  590. static u8 nicsr;
  591. static int depca_probe1 ( isa_probe_addr_t ioaddr ) {
  592. u8 data;
  593. /* This is only correct for little endian machines, but then
  594. Etherboot doesn't work on anything but a PC */
  595. u8 sig[] = { 0xFF, 0x00, 0x55, 0xAA, 0xFF, 0x00, 0x55, 0xAA };
  596. int i, j;
  597. data = inb(ioaddr + DEPCA_PROM); /* clear counter on DEPCA */
  598. data = inb(ioaddr + DEPCA_PROM); /* read data */
  599. if (data == 0x8) {
  600. nicsr = inb(ioaddr + DEPCA_NICSR);
  601. nicsr |= AAC;
  602. outb(nicsr, ioaddr + DEPCA_NICSR);
  603. }
  604. for (i = 0, j = 0; j < (int)sizeof(sig) && i < PROBE_LENGTH+((int)sizeof(sig))-1; ++i) {
  605. data = inb(ioaddr + DEPCA_PROM);
  606. if (data == sig[j]) /* track signature */
  607. ++j;
  608. else
  609. j = (data == sig[0]) ? 1 : 0;
  610. }
  611. if (j != sizeof(sig))
  612. return (0);
  613. /* put the card in its initial state */
  614. STOP_DEPCA(ioaddr);
  615. nicsr = ((inb(ioaddr + DEPCA_NICSR) & ~SHE & ~RBE & ~IEN) | IM);
  616. outb(nicsr, ioaddr + DEPCA_NICSR);
  617. if (inw(ioaddr + DEPCA_DATA) != STOP)
  618. return (0);
  619. memcpy((char *)mem_start, sig, sizeof(sig));
  620. if (memcmp((char *)mem_start, sig, sizeof(sig)) != 0)
  621. return (0);
  622. return 1;
  623. }
  624. static struct nic_operations depca_operations = {
  625. .connect = dummy_connect,
  626. .poll = depca_poll,
  627. .transmit = depca_transmit,
  628. .irq = depca_irq,
  629. };
  630. /**************************************************************************
  631. PROBE - Look for an adapter, this routine's visible to the outside
  632. ***************************************************************************/
  633. static int depca_probe ( struct nic *nic, struct isa_device *isa ) {
  634. int i, j;
  635. long sum, chksum;
  636. nic->irqno = 0;
  637. nic->ioaddr = isa->ioaddr;
  638. for (i = 0, j = 0, sum = 0; j < 3; j++) {
  639. sum <<= 1;
  640. if (sum > 0xFFFF)
  641. sum -= 0xFFFF;
  642. sum += (u8)(nic->node_addr[i++] = inb(nic->ioaddr + DEPCA_PROM));
  643. sum += (u16)((nic->node_addr[i++] = inb(nic->ioaddr + DEPCA_PROM)) << 8);
  644. if (sum > 0xFFFF)
  645. sum -= 0xFFFF;
  646. }
  647. if (sum == 0xFFFF)
  648. sum = 0;
  649. chksum = (u8)inb(nic->ioaddr + DEPCA_PROM);
  650. chksum |= (u16)(inb(nic->ioaddr + DEPCA_PROM) << 8);
  651. mem_len = (adapter == DEPCA) ? (48 << 10) : (64 << 10);
  652. offset = 0;
  653. if (nicsr & BUF) {
  654. offset = 0x8000;
  655. nicsr &= ~BS;
  656. mem_len -= (32 << 10);
  657. }
  658. if (adapter != DEPCA) /* enable shadow RAM */
  659. outb(nicsr |= SHE, nic->ioaddr + DEPCA_NICSR);
  660. DBG ( "%s base %4.4x, memory [%4.4lx-%4.4lx] addr %s",
  661. adapter_name[adapter], nic->ioaddr, mem_start,
  662. mem_start + mem_len, eth_ntoa ( nic->node_addr ) );
  663. if (sum != chksum)
  664. printf(" (bad checksum)");
  665. putchar('\n');
  666. depca_reset(nic);
  667. /* point to NIC specific routines */
  668. nic->nic_op = &depca_operations;
  669. return 1;
  670. }
  671. static isa_probe_addr_t depca_probe_addrs[] = {
  672. 0x300, 0x200,
  673. };
  674. ISA_DRIVER ( depca_driver, depca_probe_addrs, depca_probe1,
  675. GENERIC_ISAPNP_VENDOR, 0x80f7 );
  676. DRIVER ( "depce", nic_driver, isa_driver, depca_driver,
  677. depca_probe, depca_disable );
  678. ISA_ROM ( "depca", "Digital DE100 and DE200" );
  679. #endif
  680. /*
  681. * Local variables:
  682. * c-basic-offset: 8
  683. * c-indent-level: 8
  684. * tab-width: 8
  685. * End:
  686. */