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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  1. /* Uses lance chip, not fixed for relocation */
  2. #ifdef ALLMULTI
  3. #error multicast support is not yet implemented
  4. #endif
  5. /**************************************************************************
  6. Etherboot - BOOTP/TFTP Bootstrap Program
  7. Schneider & Koch G16 NIC driver for Etherboot
  8. heavily based on SK G16 driver from Linux 2.0.36
  9. Changes to make it work with Etherboot by Georg Baum <Georg.Baum@gmx.de>
  10. ***************************************************************************/
  11. /*-
  12. * Copyright (C) 1994 by PJD Weichmann & SWS Bern, Switzerland
  13. *
  14. * This software may be used and distributed according to the terms
  15. * of the GNU Public License, incorporated herein by reference.
  16. *
  17. * Module : sk_g16.c
  18. *
  19. * Version : $Revision$
  20. *
  21. * Author : Patrick J.D. Weichmann
  22. *
  23. * Date Created : 94/05/26
  24. * Last Updated : $Date$
  25. *
  26. * Description : Schneider & Koch G16 Ethernet Device Driver for
  27. * Linux Kernel >= 1.1.22
  28. * Update History :
  29. *
  30. -*/
  31. /*
  32. * The Schneider & Koch (SK) G16 Network device driver is based
  33. * on the 'ni6510' driver from Michael Hipp which can be found at
  34. * ftp://sunsite.unc.edu/pub/Linux/system/Network/drivers/nidrivers.tar.gz
  35. *
  36. * Sources: 1) ni6510.c by M. Hipp
  37. * 2) depca.c by D.C. Davies
  38. * 3) skeleton.c by D. Becker
  39. * 4) Am7990 Local Area Network Controller for Ethernet (LANCE),
  40. * AMD, Pub. #05698, June 1989
  41. *
  42. * Many Thanks for helping me to get things working to:
  43. *
  44. * A. Cox (A.Cox@swansea.ac.uk)
  45. * M. Hipp (mhipp@student.uni-tuebingen.de)
  46. * R. Bolz (Schneider & Koch, Germany)
  47. *
  48. * See README.sk_g16 for details about limitations and bugs for the
  49. * current version.
  50. *
  51. * To Do:
  52. * - Support of SK_G8 and other SK Network Cards.
  53. * - Autoset memory mapped RAM. Check for free memory and then
  54. * configure RAM correctly.
  55. * - SK_close should really set card in to initial state.
  56. * - Test if IRQ 3 is not switched off. Use autoirq() functionality.
  57. * (as in /drivers/net/skeleton.c)
  58. * - Implement Multicast addressing. At minimum something like
  59. * in depca.c.
  60. * - Redo the statistics part.
  61. * - Try to find out if the board is in 8 Bit or 16 Bit slot.
  62. * If in 8 Bit mode don't use IRQ 11.
  63. * - (Try to make it slightly faster.)
  64. */
  65. /* to get some global routines like printf */
  66. #include "etherboot.h"
  67. /* to get the interface to the body of the program */
  68. #include "nic.h"
  69. #include "isa.h"
  70. /* From linux/if_ether.h: */
  71. #define ETH_ZLEN 60 /* Min. octets in frame sans FCS */
  72. #include "sk_g16.h"
  73. /*
  74. * Schneider & Koch Card Definitions
  75. * =================================
  76. */
  77. #define SK_NAME "SK_G16"
  78. /*
  79. * SK_G16 Configuration
  80. * --------------------
  81. */
  82. /*
  83. * Abbreviations
  84. * -------------
  85. *
  86. * RAM - used for the 16KB shared memory
  87. * Boot_ROM, ROM - are used for referencing the BootEPROM
  88. *
  89. * SK_ADDR is a symbolic constant used to configure
  90. * the behaviour of the driver and the SK_G16.
  91. *
  92. * SK_ADDR defines the address where the RAM will be mapped into the real
  93. * host memory.
  94. * valid addresses are from 0xa0000 to 0xfc000 in 16Kbyte steps.
  95. */
  96. #define SK_ADDR 0xcc000
  97. /*
  98. * In POS3 are bits A14-A19 of the address bus. These bits can be set
  99. * to choose the RAM address. That's why we only can choose the RAM address
  100. * in 16KB steps.
  101. */
  102. #define POS_ADDR (rom_addr>>14) /* Do not change this line */
  103. /*
  104. * SK_G16 I/O PORT's + IRQ's + Boot_ROM locations
  105. * ----------------------------------------------
  106. */
  107. /*
  108. * As nearly every card has also SK_G16 a specified I/O Port region and
  109. * only a few possible IRQ's.
  110. * In the Installation Guide from Schneider & Koch is listed a possible
  111. * Interrupt IRQ2. IRQ2 is always IRQ9 in boards with two cascaded interrupt
  112. * controllers. So we use in SK_IRQS IRQ9.
  113. */
  114. /* Don't touch any of the following #defines. */
  115. #define SK_IO_PORTS { 0x100, 0x180, 0x208, 0x220, 0x288, 0x320, 0x328, 0x390, 0 }
  116. /*
  117. * SK_G16 POS REGISTERS
  118. * --------------------
  119. */
  120. /*
  121. * SK_G16 has a Programmable Option Select (POS) Register.
  122. * The POS is composed of 8 separate registers (POS0-7) which
  123. * are I/O mapped on an address set by the W1 switch.
  124. *
  125. */
  126. #define SK_POS_SIZE 8 /* 8 I/O Ports are used by SK_G16 */
  127. #define SK_POS0 ioaddr /* Card-ID Low (R) */
  128. #define SK_POS1 ioaddr+1 /* Card-ID High (R) */
  129. #define SK_POS2 ioaddr+2 /* Card-Enable, Boot-ROM Disable (RW) */
  130. #define SK_POS3 ioaddr+3 /* Base address of RAM */
  131. #define SK_POS4 ioaddr+4 /* IRQ */
  132. /* POS5 - POS7 are unused */
  133. /*
  134. * SK_G16 MAC PREFIX
  135. * -----------------
  136. */
  137. /*
  138. * Scheider & Koch manufacturer code (00:00:a5).
  139. * This must be checked, that we are sure it is a SK card.
  140. */
  141. #define SK_MAC0 0x00
  142. #define SK_MAC1 0x00
  143. #define SK_MAC2 0x5a
  144. /*
  145. * SK_G16 ID
  146. * ---------
  147. */
  148. /*
  149. * If POS0,POS1 contain the following ID, then we know
  150. * at which I/O Port Address we are.
  151. */
  152. #define SK_IDLOW 0xfd
  153. #define SK_IDHIGH 0x6a
  154. /*
  155. * LANCE POS Bit definitions
  156. * -------------------------
  157. */
  158. #define SK_ROM_RAM_ON (POS2_CARD)
  159. #define SK_ROM_RAM_OFF (POS2_EPROM)
  160. #define SK_ROM_ON (inb(SK_POS2) & POS2_CARD)
  161. #define SK_ROM_OFF (inb(SK_POS2) | POS2_EPROM)
  162. #define SK_RAM_ON (inb(SK_POS2) | POS2_CARD)
  163. #define SK_RAM_OFF (inb(SK_POS2) & POS2_EPROM)
  164. #define POS2_CARD 0x0001 /* 1 = SK_G16 on 0 = off */
  165. #define POS2_EPROM 0x0002 /* 1 = Boot EPROM off 0 = on */
  166. /*
  167. * SK_G16 Memory mapped Registers
  168. * ------------------------------
  169. *
  170. */
  171. #define SK_IOREG (board->ioreg) /* LANCE data registers. */
  172. #define SK_PORT (board->port) /* Control, Status register */
  173. #define SK_IOCOM (board->iocom) /* I/O Command */
  174. /*
  175. * SK_G16 Status/Control Register bits
  176. * -----------------------------------
  177. *
  178. * (C) Controlreg (S) Statusreg
  179. */
  180. /*
  181. * Register transfer: 0 = no transfer
  182. * 1 = transferring data between LANCE and I/O reg
  183. */
  184. #define SK_IORUN 0x20
  185. /*
  186. * LANCE interrupt: 0 = LANCE interrupt occurred
  187. * 1 = no LANCE interrupt occurred
  188. */
  189. #define SK_IRQ 0x10
  190. #define SK_RESET 0x08 /* Reset SK_CARD: 0 = RESET 1 = normal */
  191. #define SK_RW 0x02 /* 0 = write to 1 = read from */
  192. #define SK_ADR 0x01 /* 0 = REG DataPort 1 = RAP Reg addr port */
  193. #define SK_RREG SK_RW /* Transferdirection to read from lance */
  194. #define SK_WREG 0 /* Transferdirection to write to lance */
  195. #define SK_RAP SK_ADR /* Destination Register RAP */
  196. #define SK_RDATA 0 /* Destination Register REG DataPort */
  197. /*
  198. * SK_G16 I/O Command
  199. * ------------------
  200. */
  201. /*
  202. * Any bitcombination sets the internal I/O bit (transfer will start)
  203. * when written to I/O Command
  204. */
  205. #define SK_DOIO 0x80 /* Do Transfer */
  206. /*
  207. * LANCE RAP (Register Address Port).
  208. * ---------------------------------
  209. */
  210. /*
  211. * The LANCE internal registers are selected through the RAP.
  212. * The Registers are:
  213. *
  214. * CSR0 - Status and Control flags
  215. * CSR1 - Low order bits of initialize block (bits 15:00)
  216. * CSR2 - High order bits of initialize block (bits 07:00, 15:08 are reserved)
  217. * CSR3 - Allows redefinition of the Bus Master Interface.
  218. * This register must be set to 0x0002, which means BSWAP = 0,
  219. * ACON = 1, BCON = 0;
  220. *
  221. */
  222. #define CSR0 0x00
  223. #define CSR1 0x01
  224. #define CSR2 0x02
  225. #define CSR3 0x03
  226. /*
  227. * General Definitions
  228. * ===================
  229. */
  230. /*
  231. * Set the number of Tx and Rx buffers, using Log_2(# buffers).
  232. * We have 16KB RAM which can be accessed by the LANCE. In the
  233. * memory are not only the buffers but also the ring descriptors and
  234. * the initialize block.
  235. * Don't change anything unless you really know what you do.
  236. */
  237. #define LC_LOG_TX_BUFFERS 1 /* (2 == 2^^1) 2 Transmit buffers */
  238. #define LC_LOG_RX_BUFFERS 2 /* (8 == 2^^3) 8 Receive buffers */
  239. /* Descriptor ring sizes */
  240. #define TMDNUM (1 << (LC_LOG_TX_BUFFERS)) /* 2 Transmit descriptor rings */
  241. #define RMDNUM (1 << (LC_LOG_RX_BUFFERS)) /* 8 Receive Buffers */
  242. /* Define Mask for setting RMD, TMD length in the LANCE init_block */
  243. #define TMDNUMMASK (LC_LOG_TX_BUFFERS << 29)
  244. #define RMDNUMMASK (LC_LOG_RX_BUFFERS << 29)
  245. /*
  246. * Data Buffer size is set to maximum packet length.
  247. */
  248. #define PKT_BUF_SZ 1518
  249. /*
  250. * The number of low I/O ports used by the ethercard.
  251. */
  252. #define ETHERCARD_TOTAL_SIZE SK_POS_SIZE
  253. /*
  254. * Portreserve is there to mark the Card I/O Port region as used.
  255. * Check_region is to check if the region at ioaddr with the size "size"
  256. * is free or not.
  257. * Snarf_region allocates the I/O Port region.
  258. */
  259. #ifndef HAVE_PORTRESERVE
  260. #define check_region(ioaddr1, size) 0
  261. #define request_region(ioaddr1, size,name) do ; while (0)
  262. #endif
  263. /*
  264. * SK_DEBUG
  265. *
  266. * Here you can choose what level of debugging wanted.
  267. *
  268. * If SK_DEBUG and SK_DEBUG2 are undefined, then only the
  269. * necessary messages will be printed.
  270. *
  271. * If SK_DEBUG is defined, there will be many debugging prints
  272. * which can help to find some mistakes in configuration or even
  273. * in the driver code.
  274. *
  275. * If SK_DEBUG2 is defined, many many messages will be printed
  276. * which normally you don't need. I used this to check the interrupt
  277. * routine.
  278. *
  279. * (If you define only SK_DEBUG2 then only the messages for
  280. * checking interrupts will be printed!)
  281. *
  282. * Normal way of live is:
  283. *
  284. * For the whole thing get going let both symbolic constants
  285. * undefined. If you face any problems and you know what's going
  286. * on (you know something about the card and you can interpret some
  287. * hex LANCE register output) then define SK_DEBUG
  288. *
  289. */
  290. #undef SK_DEBUG /* debugging */
  291. #undef SK_DEBUG2 /* debugging with more verbose report */
  292. #ifdef SK_DEBUG
  293. #define PRINTF(x) printf x
  294. #else
  295. #define PRINTF(x) /**/
  296. #endif
  297. #ifdef SK_DEBUG2
  298. #define PRINTF2(x) printf x
  299. #else
  300. #define PRINTF2(x) /**/
  301. #endif
  302. /*
  303. * SK_G16 RAM
  304. *
  305. * The components are memory mapped and can be set in a region from
  306. * 0x00000 through 0xfc000 in 16KB steps.
  307. *
  308. * The Network components are: dual ported RAM, Prom, I/O Reg, Status-,
  309. * Controlregister and I/O Command.
  310. *
  311. * dual ported RAM: This is the only memory region which the LANCE chip
  312. * has access to. From the Lance it is addressed from 0x0000 to
  313. * 0x3fbf. The host accesses it normally.
  314. *
  315. * PROM: The PROM obtains the ETHERNET-MAC-Address. It is realised as a
  316. * 8-Bit PROM, this means only the 16 even addresses are used of the
  317. * 32 Byte Address region. Access to a odd address results in invalid
  318. * data.
  319. *
  320. * LANCE I/O Reg: The I/O Reg is build of 4 single Registers, Low-Byte Write,
  321. * Hi-Byte Write, Low-Byte Read, Hi-Byte Read.
  322. * Transfer from or to the LANCE is always in 16Bit so Low and High
  323. * registers are always relevant.
  324. *
  325. * The Data from the Readregister is not the data in the Writeregister!!
  326. *
  327. * Port: Status- and Controlregister.
  328. * Two different registers which share the same address, Status is
  329. * read-only, Control is write-only.
  330. *
  331. * I/O Command:
  332. * Any bitcombination written in here starts the transmission between
  333. * Host and LANCE.
  334. */
  335. typedef struct
  336. {
  337. unsigned char ram[0x3fc0]; /* 16KB dual ported ram */
  338. unsigned char rom[0x0020]; /* 32Byte PROM containing 6Byte MAC */
  339. unsigned char res1[0x0010]; /* reserved */
  340. unsigned volatile short ioreg;/* LANCE I/O Register */
  341. unsigned volatile char port; /* Statusregister and Controlregister */
  342. unsigned char iocom; /* I/O Command Register */
  343. } SK_RAM;
  344. /* struct */
  345. /*
  346. * This is the structure for the dual ported ram. We
  347. * have exactly 16 320 Bytes. In here there must be:
  348. *
  349. * - Initialize Block (starting at a word boundary)
  350. * - Receive and Transmit Descriptor Rings (quadword boundary)
  351. * - Data Buffers (arbitrary boundary)
  352. *
  353. * This is because LANCE has on SK_G16 only access to the dual ported
  354. * RAM and nowhere else.
  355. */
  356. struct SK_ram
  357. {
  358. struct init_block ib;
  359. struct tmd tmde[TMDNUM];
  360. struct rmd rmde[RMDNUM];
  361. char tmdbuf[TMDNUM][PKT_BUF_SZ];
  362. char rmdbuf[RMDNUM][PKT_BUF_SZ];
  363. };
  364. /*
  365. * Structure where all necessary information is for ring buffer
  366. * management and statistics.
  367. */
  368. struct priv
  369. {
  370. struct SK_ram *ram; /* dual ported ram structure */
  371. struct rmd *rmdhead; /* start of receive ring descriptors */
  372. struct tmd *tmdhead; /* start of transmit ring descriptors */
  373. int rmdnum; /* actual used ring descriptor */
  374. int tmdnum; /* actual transmit descriptor for transmitting data */
  375. int tmdlast; /* last sent descriptor used for error handling, etc */
  376. void *rmdbufs[RMDNUM]; /* pointer to the receive buffers */
  377. void *tmdbufs[TMDNUM]; /* pointer to the transmit buffers */
  378. };
  379. /* global variable declaration */
  380. /* static variables */
  381. static SK_RAM *board; /* pointer to our memory mapped board components */
  382. static unsigned short ioaddr; /* base io address */
  383. static struct priv p_data;
  384. /* Macros */
  385. /* Function Prototypes */
  386. /*
  387. * Device Driver functions
  388. * -----------------------
  389. * See for short explanation of each function its definitions header.
  390. */
  391. static int SK_probe1(struct nic *nic, short ioaddr1);
  392. static int SK_poll(struct nic *nic, int retrieve);
  393. static void SK_transmit(
  394. struct nic *nic,
  395. const char *d, /* Destination */
  396. unsigned int t, /* Type */
  397. unsigned int s, /* size */
  398. const char *p); /* Packet */
  399. static void SK_disable(struct nic *nic);
  400. static int SK_probe(struct dev *dev);
  401. /*
  402. * LANCE Functions
  403. * ---------------
  404. */
  405. static int SK_lance_init(struct nic *nic, unsigned short mode);
  406. static void SK_reset_board(void);
  407. static void SK_set_RAP(int reg_number);
  408. static int SK_read_reg(int reg_number);
  409. static int SK_rread_reg(void);
  410. static void SK_write_reg(int reg_number, int value);
  411. /*
  412. * Debugging functions
  413. * -------------------
  414. */
  415. #ifdef SK_DEBUG
  416. static void SK_print_pos(struct nic *nic, char *text);
  417. static void SK_print_ram(struct nic *nic);
  418. #endif
  419. /**************************************************************************
  420. POLL - Wait for a frame
  421. ***************************************************************************/
  422. static int SK_poll(struct nic *nic, int retrieve)
  423. {
  424. /* return true if there's an ethernet packet ready to read */
  425. struct priv *p; /* SK_G16 private structure */
  426. struct rmd *rmdp;
  427. int csr0, rmdstat, packet_there;
  428. PRINTF2(("## %s: At beginning of SK_poll(). CSR0: %#hX\n",
  429. SK_NAME, SK_read_reg(CSR0)));
  430. p = nic->priv_data;
  431. csr0 = SK_read_reg(CSR0); /* store register for checking */
  432. rmdp = p->rmdhead + p->rmdnum;
  433. packet_there = 0;
  434. if ( !(rmdp->u.s.status & RX_OWN) && !retrieve ) return 1;
  435. /*
  436. * Acknowledge all of the current interrupt sources, disable
  437. * Interrupts (INEA = 0)
  438. */
  439. SK_write_reg(CSR0, csr0 & CSR0_CLRALL);
  440. if (csr0 & CSR0_ERR) /* LANCE Error */
  441. {
  442. printf("%s: error: %#hX", SK_NAME, csr0);
  443. if (csr0 & CSR0_MISS) /* No place to store packet ? */
  444. {
  445. printf(", Packet dropped.");
  446. }
  447. putchar('\n');
  448. }
  449. /* As long as we own the next entry, check status and send
  450. * it up to higher layer
  451. */
  452. while (!( (rmdstat = rmdp->u.s.status) & RX_OWN))
  453. {
  454. /*
  455. * Start and end of packet must be set, because we use
  456. * the ethernet maximum packet length (1518) as buffer size.
  457. *
  458. * Because our buffers are at maximum OFLO and BUFF errors are
  459. * not to be concerned (see Data sheet)
  460. */
  461. if ((rmdstat & (RX_STP | RX_ENP)) != (RX_STP | RX_ENP))
  462. {
  463. /* Start of a frame > 1518 Bytes ? */
  464. if (rmdstat & RX_STP)
  465. {
  466. printf("%s: packet too long\n", SK_NAME);
  467. }
  468. /*
  469. * All other packets will be ignored until a new frame with
  470. * start (RX_STP) set follows.
  471. *
  472. * What we do is just give descriptor free for new incoming
  473. * packets.
  474. */
  475. rmdp->u.s.status = RX_OWN; /* Relinquish ownership to LANCE */
  476. }
  477. else if (rmdstat & RX_ERR) /* Receive Error ? */
  478. {
  479. printf("%s: RX error: %#hX\n", SK_NAME, (int) rmdstat);
  480. rmdp->u.s.status = RX_OWN; /* Relinquish ownership to LANCE */
  481. }
  482. else /* We have a packet which can be queued for the upper layers */
  483. {
  484. int len = (rmdp->mlen & 0x0fff); /* extract message length from receive buffer */
  485. /*
  486. * Copy data out of our receive descriptor into nic->packet.
  487. *
  488. * (rmdp->u.buffer & 0x00ffffff) -> get address of buffer and
  489. * ignore status fields)
  490. */
  491. memcpy(nic->packet, (unsigned char *) (rmdp->u.buffer & 0x00ffffff), nic->packetlen = len);
  492. packet_there = 1;
  493. /*
  494. * Packet is queued and marked for processing so we
  495. * free our descriptor
  496. */
  497. rmdp->u.s.status = RX_OWN;
  498. p->rmdnum++;
  499. p->rmdnum %= RMDNUM;
  500. rmdp = p->rmdhead + p->rmdnum;
  501. }
  502. }
  503. SK_write_reg(CSR0, CSR0_INEA); /* Enable Interrupts */
  504. return (packet_there);
  505. }
  506. /**************************************************************************
  507. TRANSMIT - Transmit a frame
  508. ***************************************************************************/
  509. static void SK_transmit(
  510. struct nic *nic,
  511. const char *d, /* Destination */
  512. unsigned int t, /* Type */
  513. unsigned int s, /* size */
  514. const char *pack) /* Packet */
  515. {
  516. /* send the packet to destination */
  517. struct priv *p; /* SK_G16 private structure */
  518. struct tmd *tmdp;
  519. short len;
  520. int csr0, tmdstat;
  521. PRINTF2(("## %s: At beginning of SK_transmit(). CSR0: %#hX\n",
  522. SK_NAME, SK_read_reg(CSR0)));
  523. p = nic->priv_data;
  524. tmdp = p->tmdhead + p->tmdnum; /* Which descriptor for transmitting */
  525. /* Copy data into dual ported ram */
  526. memcpy(&p->ram->tmdbuf[p->tmdnum][0], d, ETH_ALEN); /* dst */
  527. memcpy(&p->ram->tmdbuf[p->tmdnum][ETH_ALEN], nic->node_addr, ETH_ALEN); /* src */
  528. p->ram->tmdbuf[p->tmdnum][ETH_ALEN + ETH_ALEN] = t >> 8; /* type */
  529. p->ram->tmdbuf[p->tmdnum][ETH_ALEN + ETH_ALEN + 1] = t; /* type */
  530. memcpy(&p->ram->tmdbuf[p->tmdnum][ETH_HLEN], pack, s);
  531. s += ETH_HLEN;
  532. while (s < ETH_ZLEN) /* pad to min length */
  533. p->ram->tmdbuf[p->tmdnum][s++] = 0;
  534. p->ram->tmde[p->tmdnum].status2 = 0x0;
  535. /* Evaluate Packet length */
  536. len = ETH_ZLEN < s ? s : ETH_ZLEN;
  537. /* Fill in Transmit Message Descriptor */
  538. tmdp->blen = -len; /* set length to transmit */
  539. /*
  540. * Packet start and end is always set because we use the maximum
  541. * packet length as buffer length.
  542. * Relinquish ownership to LANCE
  543. */
  544. tmdp->u.s.status = TX_OWN | TX_STP | TX_ENP;
  545. /* Start Demand Transmission */
  546. SK_write_reg(CSR0, CSR0_TDMD | CSR0_INEA);
  547. csr0 = SK_read_reg(CSR0); /* store register for checking */
  548. /*
  549. * Acknowledge all of the current interrupt sources, disable
  550. * Interrupts (INEA = 0)
  551. */
  552. SK_write_reg(CSR0, csr0 & CSR0_CLRALL);
  553. if (csr0 & CSR0_ERR) /* LANCE Error */
  554. {
  555. printf("%s: error: %#hX", SK_NAME, csr0);
  556. if (csr0 & CSR0_MISS) /* No place to store packet ? */
  557. {
  558. printf(", Packet dropped.");
  559. }
  560. putchar('\n');
  561. }
  562. /* Set next buffer */
  563. p->tmdlast++;
  564. p->tmdlast &= TMDNUM-1;
  565. tmdstat = tmdp->u.s.status & 0xff00; /* filter out status bits 15:08 */
  566. /*
  567. * We check status of transmitted packet.
  568. * see LANCE data-sheet for error explanation
  569. */
  570. if (tmdstat & TX_ERR) /* Error occurred */
  571. {
  572. printf("%s: TX error: %#hX %#hX\n", SK_NAME, (int) tmdstat,
  573. (int) tmdp->status2);
  574. if (tmdp->status2 & TX_TDR) /* TDR problems? */
  575. {
  576. printf("%s: tdr-problems \n", SK_NAME);
  577. }
  578. if (tmdp->status2 & TX_UFLO) /* Underflow error ? */
  579. {
  580. /*
  581. * If UFLO error occurs it will turn transmitter of.
  582. * So we must reinit LANCE
  583. */
  584. SK_lance_init(nic, MODE_NORMAL);
  585. }
  586. tmdp->status2 = 0; /* Clear error flags */
  587. }
  588. SK_write_reg(CSR0, CSR0_INEA); /* Enable Interrupts */
  589. /* Set pointer to next transmit buffer */
  590. p->tmdnum++;
  591. p->tmdnum &= TMDNUM-1;
  592. }
  593. /**************************************************************************
  594. DISABLE - Turn off ethernet interface
  595. ***************************************************************************/
  596. static void SK_disable ( struct nic *nic ) {
  597. /* put the card in its initial state */
  598. SK_lance_init(nic, MODE_NORMAL); /* reset and disable merge */
  599. PRINTF(("## %s: At beginning of SK_disable(). CSR0: %#hX\n",
  600. SK_NAME, SK_read_reg(CSR0)));
  601. PRINTF(("%s: Shutting %s down CSR0 %#hX\n", SK_NAME, SK_NAME,
  602. (int) SK_read_reg(CSR0)));
  603. SK_write_reg(CSR0, CSR0_STOP); /* STOP the LANCE */
  604. }
  605. /**************************************************************************
  606. IRQ - Enable, Disable, or Force interrupts
  607. ***************************************************************************/
  608. static void SK_irq(struct nic *nic __unused, irq_action_t action __unused)
  609. {
  610. switch ( action ) {
  611. case DISABLE :
  612. break;
  613. case ENABLE :
  614. break;
  615. case FORCE :
  616. break;
  617. }
  618. }
  619. /**************************************************************************
  620. PROBE - Look for an adapter, this routine's visible to the outside
  621. ***************************************************************************/
  622. static int SK_probe(struct dev *dev, unsigned short *probe_addrs)
  623. {
  624. struct nic *nic = (struct nic *)dev;
  625. unsigned short *p;
  626. static unsigned short io_addrs[] = SK_IO_PORTS;
  627. /* if probe_addrs is 0, then routine can use a hardwired default */
  628. nic->priv_data = &p_data;
  629. if (probe_addrs == 0)
  630. probe_addrs = io_addrs;
  631. for (p = probe_addrs; (ioaddr = *p) != 0; ++p)
  632. {
  633. long offset1, offset0 = inb(ioaddr);
  634. if ((offset0 == SK_IDLOW) &&
  635. ((offset1 = inb(ioaddr + 1)) == SK_IDHIGH))
  636. if (SK_probe1(nic, ioaddr) >= 0)
  637. break;
  638. }
  639. /* if board found */
  640. if (ioaddr != 0)
  641. {
  642. nic->ioaddr = ioaddr & ~3;
  643. nic->irqno = 0;
  644. /* point to NIC specific routines */
  645. dev->disable = SK_disable;
  646. nic->poll = SK_poll;
  647. nic->transmit = SK_transmit;
  648. nic->irq = SK_irq;
  649. /* FIXME set dev->devid */
  650. return 1;
  651. }
  652. /* else */
  653. {
  654. return 0;
  655. }
  656. }
  657. int SK_probe1(struct nic *nic, short ioaddr1 __unused)
  658. {
  659. int i,j; /* Counters */
  660. unsigned int rom_addr; /* used to store RAM address used for POS_ADDR */
  661. struct priv *p; /* SK_G16 private structure */
  662. if (SK_ADDR & 0x3fff || SK_ADDR < 0xa0000)
  663. {
  664. /*
  665. * Now here we could use a routine which searches for a free
  666. * place in the ram and set SK_ADDR if found. TODO.
  667. */
  668. printf("%s: SK_ADDR %#hX is not valid. Check configuration.\n",
  669. SK_NAME, SK_ADDR);
  670. return -1;
  671. }
  672. rom_addr = SK_ADDR;
  673. outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */
  674. outb(POS_ADDR, SK_POS3); /* Set RAM address */
  675. outb(SK_ROM_RAM_ON, SK_POS2); /* RAM on, BOOT_ROM on */
  676. #ifdef SK_DEBUG
  677. SK_print_pos(nic, "POS registers after ROM, RAM config");
  678. #endif
  679. board = (SK_RAM *) rom_addr;
  680. PRINTF(("adr[0]: %hX, adr[1]: %hX, adr[2]: %hX\n",
  681. board->rom[0], board->rom[2], board->rom[4]));
  682. /* Read in station address */
  683. for (i = 0, j = 0; i < ETH_ALEN; i++, j+=2)
  684. {
  685. *(nic->node_addr+i) = board->rom[j];
  686. }
  687. /* Check for manufacturer code */
  688. #ifdef SK_DEBUG
  689. if (!(*(nic->node_addr+0) == SK_MAC0 &&
  690. *(nic->node_addr+1) == SK_MAC1 &&
  691. *(nic->node_addr+2) == SK_MAC2) )
  692. {
  693. PRINTF(("## %s: We did not find SK_G16 at RAM location.\n",
  694. SK_NAME));
  695. return -1; /* NO SK_G16 found */
  696. }
  697. #endif
  698. p = nic->priv_data;
  699. /* Initialize private structure */
  700. p->ram = (struct SK_ram *) rom_addr; /* Set dual ported RAM addr */
  701. p->tmdhead = &(p->ram)->tmde[0]; /* Set TMD head */
  702. p->rmdhead = &(p->ram)->rmde[0]; /* Set RMD head */
  703. printf("Schneider & Koch G16 at %#hX, mem at %#hX, HW addr: %!\n",
  704. (unsigned int) ioaddr, (unsigned int) p->ram, nic->node_addr);
  705. /* Initialize buffer pointers */
  706. for (i = 0; i < TMDNUM; i++)
  707. {
  708. p->tmdbufs[i] = p->ram->tmdbuf[i];
  709. }
  710. for (i = 0; i < RMDNUM; i++)
  711. {
  712. p->rmdbufs[i] = p->ram->rmdbuf[i];
  713. }
  714. i = 0;
  715. if (!(i = SK_lance_init(nic, MODE_NORMAL))) /* LANCE init OK? */
  716. {
  717. #ifdef SK_DEBUG
  718. /*
  719. * This debug block tries to stop LANCE,
  720. * reinit LANCE with transmitter and receiver disabled,
  721. * then stop again and reinit with NORMAL_MODE
  722. */
  723. printf("## %s: After lance init. CSR0: %#hX\n",
  724. SK_NAME, SK_read_reg(CSR0));
  725. SK_write_reg(CSR0, CSR0_STOP);
  726. printf("## %s: LANCE stopped. CSR0: %#hX\n",
  727. SK_NAME, SK_read_reg(CSR0));
  728. SK_lance_init(nic, MODE_DTX | MODE_DRX);
  729. printf("## %s: Reinit with DTX + DRX off. CSR0: %#hX\n",
  730. SK_NAME, SK_read_reg(CSR0));
  731. SK_write_reg(CSR0, CSR0_STOP);
  732. printf("## %s: LANCE stopped. CSR0: %#hX\n",
  733. SK_NAME, SK_read_reg(CSR0));
  734. SK_lance_init(nic, MODE_NORMAL);
  735. printf("## %s: LANCE back to normal mode. CSR0: %#hX\n",
  736. SK_NAME, SK_read_reg(CSR0));
  737. SK_print_pos(nic, "POS regs before returning OK");
  738. #endif /* SK_DEBUG */
  739. }
  740. else /* LANCE init failed */
  741. {
  742. PRINTF(("## %s: LANCE init failed: CSR0: %#hX\n",
  743. SK_NAME, SK_read_reg(CSR0)));
  744. return -1;
  745. }
  746. #ifdef SK_DEBUG
  747. SK_print_pos(nic, "End of SK_probe1");
  748. SK_print_ram(nic);
  749. #endif
  750. return 0; /* Initialization done */
  751. } /* End of SK_probe1() */
  752. static int SK_lance_init(struct nic *nic, unsigned short mode)
  753. {
  754. int i;
  755. struct priv *p = (struct priv *) nic->priv_data;
  756. struct tmd *tmdp;
  757. struct rmd *rmdp;
  758. PRINTF(("## %s: At beginning of LANCE init. CSR0: %#hX\n",
  759. SK_NAME, SK_read_reg(CSR0)));
  760. /* Reset LANCE */
  761. SK_reset_board();
  762. /* Initialize TMD's with start values */
  763. p->tmdnum = 0; /* First descriptor for transmitting */
  764. p->tmdlast = 0; /* First descriptor for reading stats */
  765. for (i = 0; i < TMDNUM; i++) /* Init all TMD's */
  766. {
  767. tmdp = p->tmdhead + i;
  768. tmdp->u.buffer = (unsigned long) p->tmdbufs[i]; /* assign buffer */
  769. /* Mark TMD as start and end of packet */
  770. tmdp->u.s.status = TX_STP | TX_ENP;
  771. }
  772. /* Initialize RMD's with start values */
  773. p->rmdnum = 0; /* First RMD which will be used */
  774. for (i = 0; i < RMDNUM; i++) /* Init all RMD's */
  775. {
  776. rmdp = p->rmdhead + i;
  777. rmdp->u.buffer = (unsigned long) p->rmdbufs[i]; /* assign buffer */
  778. /*
  779. * LANCE must be owner at beginning so that he can fill in
  780. * receiving packets, set status and release RMD
  781. */
  782. rmdp->u.s.status = RX_OWN;
  783. rmdp->blen = -PKT_BUF_SZ; /* Buffer Size in a two's complement */
  784. rmdp->mlen = 0; /* init message length */
  785. }
  786. /* Fill LANCE Initialize Block */
  787. (p->ram)->ib.mode = mode; /* Set operation mode */
  788. for (i = 0; i < ETH_ALEN; i++) /* Set physical address */
  789. {
  790. (p->ram)->ib.paddr[i] = *(nic->node_addr+i);
  791. }
  792. for (i = 0; i < 8; i++) /* Set multicast, logical address */
  793. {
  794. (p->ram)->ib.laddr[i] = 0; /* We do not use logical addressing */
  795. }
  796. /* Set ring descriptor pointers and set number of descriptors */
  797. (p->ram)->ib.rdrp = (int) p->rmdhead | RMDNUMMASK;
  798. (p->ram)->ib.tdrp = (int) p->tmdhead | TMDNUMMASK;
  799. /* Prepare LANCE Control and Status Registers */
  800. SK_write_reg(CSR3, CSR3_ACON); /* Ale Control !!!THIS MUST BE SET!!!! */
  801. /*
  802. * LANCE addresses the RAM from 0x0000 to 0x3fbf and has no access to
  803. * PC Memory locations.
  804. *
  805. * In structure SK_ram is defined that the first thing in ram
  806. * is the initialization block. So his address is for LANCE always
  807. * 0x0000
  808. *
  809. * CSR1 contains low order bits 15:0 of initialization block address
  810. * CSR2 is built of:
  811. * 7:0 High order bits 23:16 of initialization block address
  812. * 15:8 reserved, must be 0
  813. */
  814. /* Set initialization block address (must be on word boundary) */
  815. SK_write_reg(CSR1, 0); /* Set low order bits 15:0 */
  816. SK_write_reg(CSR2, 0); /* Set high order bits 23:16 */
  817. PRINTF(("## %s: After setting CSR1-3. CSR0: %#hX\n",
  818. SK_NAME, SK_read_reg(CSR0)));
  819. /* Initialize LANCE */
  820. /*
  821. * INIT = Initialize, when set, causes the LANCE to begin the
  822. * initialization procedure and access the Init Block.
  823. */
  824. SK_write_reg(CSR0, CSR0_INIT);
  825. /* Wait until LANCE finished initialization */
  826. SK_set_RAP(CSR0); /* Register Address Pointer to CSR0 */
  827. for (i = 0; (i < 100) && !(SK_rread_reg() & CSR0_IDON); i++)
  828. ; /* Wait until init done or go ahead if problems (i>=100) */
  829. if (i >= 100) /* Something is wrong ! */
  830. {
  831. printf("%s: can't init am7990, status: %#hX "
  832. "init_block: %#hX\n",
  833. SK_NAME, (int) SK_read_reg(CSR0),
  834. (unsigned int) &(p->ram)->ib);
  835. #ifdef SK_DEBUG
  836. SK_print_pos(nic, "LANCE INIT failed");
  837. #endif
  838. return -1; /* LANCE init failed */
  839. }
  840. PRINTF(("## %s: init done after %d ticks\n", SK_NAME, i));
  841. /* Clear Initialize done, enable Interrupts, start LANCE */
  842. SK_write_reg(CSR0, CSR0_IDON | CSR0_INEA | CSR0_STRT);
  843. PRINTF(("## %s: LANCE started. CSR0: %#hX\n", SK_NAME,
  844. SK_read_reg(CSR0)));
  845. return 0; /* LANCE is up and running */
  846. } /* End of SK_lance_init() */
  847. /* LANCE access functions
  848. *
  849. * ! CSR1-3 can only be accessed when in CSR0 the STOP bit is set !
  850. */
  851. static void SK_reset_board(void)
  852. {
  853. int i;
  854. PRINTF(("## %s: At beginning of SK_reset_board.\n", SK_NAME));
  855. SK_PORT = 0x00; /* Reset active */
  856. for (i = 0; i < 10 ; i++) /* Delay min 5ms */
  857. ;
  858. SK_PORT = SK_RESET; /* Set back to normal operation */
  859. } /* End of SK_reset_board() */
  860. static void SK_set_RAP(int reg_number)
  861. {
  862. SK_IOREG = reg_number;
  863. SK_PORT = SK_RESET | SK_RAP | SK_WREG;
  864. SK_IOCOM = SK_DOIO;
  865. while (SK_PORT & SK_IORUN)
  866. ;
  867. } /* End of SK_set_RAP() */
  868. static int SK_read_reg(int reg_number)
  869. {
  870. SK_set_RAP(reg_number);
  871. SK_PORT = SK_RESET | SK_RDATA | SK_RREG;
  872. SK_IOCOM = SK_DOIO;
  873. while (SK_PORT & SK_IORUN)
  874. ;
  875. return (SK_IOREG);
  876. } /* End of SK_read_reg() */
  877. static int SK_rread_reg(void)
  878. {
  879. SK_PORT = SK_RESET | SK_RDATA | SK_RREG;
  880. SK_IOCOM = SK_DOIO;
  881. while (SK_PORT & SK_IORUN)
  882. ;
  883. return (SK_IOREG);
  884. } /* End of SK_rread_reg() */
  885. static void SK_write_reg(int reg_number, int value)
  886. {
  887. SK_set_RAP(reg_number);
  888. SK_IOREG = value;
  889. SK_PORT = SK_RESET | SK_RDATA | SK_WREG;
  890. SK_IOCOM = SK_DOIO;
  891. while (SK_PORT & SK_IORUN)
  892. ;
  893. } /* End of SK_write_reg */
  894. /*
  895. * Debugging functions
  896. * -------------------
  897. */
  898. #ifdef SK_DEBUG
  899. static void SK_print_pos(struct nic *nic, char *text)
  900. {
  901. unsigned char pos0 = inb(SK_POS0),
  902. pos1 = inb(SK_POS1),
  903. pos2 = inb(SK_POS2),
  904. pos3 = inb(SK_POS3),
  905. pos4 = inb(SK_POS4);
  906. printf("## %s: %s.\n"
  907. "## pos0=%#hX pos1=%#hX pos2=%#hX pos3=%#hX pos4=%#hX\n",
  908. SK_NAME, text, pos0, pos1, pos2, (pos3<<14), pos4);
  909. } /* End of SK_print_pos() */
  910. static void SK_print_ram(struct nic *nic)
  911. {
  912. int i;
  913. struct priv *p = (struct priv *) nic->priv_data;
  914. printf("## %s: RAM Details.\n"
  915. "## RAM at %#hX tmdhead: %#hX rmdhead: %#hX initblock: %#hX\n",
  916. SK_NAME,
  917. (unsigned int) p->ram,
  918. (unsigned int) p->tmdhead,
  919. (unsigned int) p->rmdhead,
  920. (unsigned int) &(p->ram)->ib);
  921. printf("## ");
  922. for(i = 0; i < TMDNUM; i++)
  923. {
  924. if (!(i % 3)) /* Every third line do a newline */
  925. {
  926. printf("\n## ");
  927. }
  928. printf("tmdbufs%d: %#hX ", (i+1), (int) p->tmdbufs[i]);
  929. }
  930. printf("## ");
  931. for(i = 0; i < RMDNUM; i++)
  932. {
  933. if (!(i % 3)) /* Every third line do a newline */
  934. {
  935. printf("\n## ");
  936. }
  937. printf("rmdbufs%d: %#hX ", (i+1), (int) p->rmdbufs[i]);
  938. }
  939. putchar('\n');
  940. } /* End of SK_print_ram() */
  941. #endif
  942. static struct isa_driver SK_driver __isa_driver = {
  943. .type = NIC_DRIVER,
  944. .name = "SK_G16",
  945. .probe = SK_probe,
  946. .ioaddrs = 0,
  947. };
  948. ISA_ROM("sk_g16","Schneider and Koch G16");