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.

sk_g16.c 32KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  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. static struct nic_operations SK_operations;
  646. static struct nic_operations SK_operations = {
  647. .connect = dummy_connect,
  648. .poll = SK_poll,
  649. .transmit = SK_transmit,
  650. .irq = SK_irq,
  651. .disable = SK_disable,
  652. }; nic->nic_op = &SK_operations;
  653. /* FIXME set dev->devid */
  654. return 1;
  655. }
  656. /* else */
  657. {
  658. return 0;
  659. }
  660. }
  661. int SK_probe1(struct nic *nic, short ioaddr1 __unused)
  662. {
  663. int i,j; /* Counters */
  664. unsigned int rom_addr; /* used to store RAM address used for POS_ADDR */
  665. struct priv *p; /* SK_G16 private structure */
  666. if (SK_ADDR & 0x3fff || SK_ADDR < 0xa0000)
  667. {
  668. /*
  669. * Now here we could use a routine which searches for a free
  670. * place in the ram and set SK_ADDR if found. TODO.
  671. */
  672. printf("%s: SK_ADDR %#hX is not valid. Check configuration.\n",
  673. SK_NAME, SK_ADDR);
  674. return -1;
  675. }
  676. rom_addr = SK_ADDR;
  677. outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */
  678. outb(POS_ADDR, SK_POS3); /* Set RAM address */
  679. outb(SK_ROM_RAM_ON, SK_POS2); /* RAM on, BOOT_ROM on */
  680. #ifdef SK_DEBUG
  681. SK_print_pos(nic, "POS registers after ROM, RAM config");
  682. #endif
  683. board = (SK_RAM *) rom_addr;
  684. PRINTF(("adr[0]: %hX, adr[1]: %hX, adr[2]: %hX\n",
  685. board->rom[0], board->rom[2], board->rom[4]));
  686. /* Read in station address */
  687. for (i = 0, j = 0; i < ETH_ALEN; i++, j+=2)
  688. {
  689. *(nic->node_addr+i) = board->rom[j];
  690. }
  691. /* Check for manufacturer code */
  692. #ifdef SK_DEBUG
  693. if (!(*(nic->node_addr+0) == SK_MAC0 &&
  694. *(nic->node_addr+1) == SK_MAC1 &&
  695. *(nic->node_addr+2) == SK_MAC2) )
  696. {
  697. PRINTF(("## %s: We did not find SK_G16 at RAM location.\n",
  698. SK_NAME));
  699. return -1; /* NO SK_G16 found */
  700. }
  701. #endif
  702. p = nic->priv_data;
  703. /* Initialize private structure */
  704. p->ram = (struct SK_ram *) rom_addr; /* Set dual ported RAM addr */
  705. p->tmdhead = &(p->ram)->tmde[0]; /* Set TMD head */
  706. p->rmdhead = &(p->ram)->rmde[0]; /* Set RMD head */
  707. printf("Schneider & Koch G16 at %#hX, mem at %#hX, HW addr: %!\n",
  708. (unsigned int) ioaddr, (unsigned int) p->ram, nic->node_addr);
  709. /* Initialize buffer pointers */
  710. for (i = 0; i < TMDNUM; i++)
  711. {
  712. p->tmdbufs[i] = p->ram->tmdbuf[i];
  713. }
  714. for (i = 0; i < RMDNUM; i++)
  715. {
  716. p->rmdbufs[i] = p->ram->rmdbuf[i];
  717. }
  718. i = 0;
  719. if (!(i = SK_lance_init(nic, MODE_NORMAL))) /* LANCE init OK? */
  720. {
  721. #ifdef SK_DEBUG
  722. /*
  723. * This debug block tries to stop LANCE,
  724. * reinit LANCE with transmitter and receiver disabled,
  725. * then stop again and reinit with NORMAL_MODE
  726. */
  727. printf("## %s: After lance init. CSR0: %#hX\n",
  728. SK_NAME, SK_read_reg(CSR0));
  729. SK_write_reg(CSR0, CSR0_STOP);
  730. printf("## %s: LANCE stopped. CSR0: %#hX\n",
  731. SK_NAME, SK_read_reg(CSR0));
  732. SK_lance_init(nic, MODE_DTX | MODE_DRX);
  733. printf("## %s: Reinit with DTX + DRX off. CSR0: %#hX\n",
  734. SK_NAME, SK_read_reg(CSR0));
  735. SK_write_reg(CSR0, CSR0_STOP);
  736. printf("## %s: LANCE stopped. CSR0: %#hX\n",
  737. SK_NAME, SK_read_reg(CSR0));
  738. SK_lance_init(nic, MODE_NORMAL);
  739. printf("## %s: LANCE back to normal mode. CSR0: %#hX\n",
  740. SK_NAME, SK_read_reg(CSR0));
  741. SK_print_pos(nic, "POS regs before returning OK");
  742. #endif /* SK_DEBUG */
  743. }
  744. else /* LANCE init failed */
  745. {
  746. PRINTF(("## %s: LANCE init failed: CSR0: %#hX\n",
  747. SK_NAME, SK_read_reg(CSR0)));
  748. return -1;
  749. }
  750. #ifdef SK_DEBUG
  751. SK_print_pos(nic, "End of SK_probe1");
  752. SK_print_ram(nic);
  753. #endif
  754. return 0; /* Initialization done */
  755. } /* End of SK_probe1() */
  756. static int SK_lance_init(struct nic *nic, unsigned short mode)
  757. {
  758. int i;
  759. struct priv *p = (struct priv *) nic->priv_data;
  760. struct tmd *tmdp;
  761. struct rmd *rmdp;
  762. PRINTF(("## %s: At beginning of LANCE init. CSR0: %#hX\n",
  763. SK_NAME, SK_read_reg(CSR0)));
  764. /* Reset LANCE */
  765. SK_reset_board();
  766. /* Initialize TMD's with start values */
  767. p->tmdnum = 0; /* First descriptor for transmitting */
  768. p->tmdlast = 0; /* First descriptor for reading stats */
  769. for (i = 0; i < TMDNUM; i++) /* Init all TMD's */
  770. {
  771. tmdp = p->tmdhead + i;
  772. tmdp->u.buffer = (unsigned long) p->tmdbufs[i]; /* assign buffer */
  773. /* Mark TMD as start and end of packet */
  774. tmdp->u.s.status = TX_STP | TX_ENP;
  775. }
  776. /* Initialize RMD's with start values */
  777. p->rmdnum = 0; /* First RMD which will be used */
  778. for (i = 0; i < RMDNUM; i++) /* Init all RMD's */
  779. {
  780. rmdp = p->rmdhead + i;
  781. rmdp->u.buffer = (unsigned long) p->rmdbufs[i]; /* assign buffer */
  782. /*
  783. * LANCE must be owner at beginning so that he can fill in
  784. * receiving packets, set status and release RMD
  785. */
  786. rmdp->u.s.status = RX_OWN;
  787. rmdp->blen = -PKT_BUF_SZ; /* Buffer Size in a two's complement */
  788. rmdp->mlen = 0; /* init message length */
  789. }
  790. /* Fill LANCE Initialize Block */
  791. (p->ram)->ib.mode = mode; /* Set operation mode */
  792. for (i = 0; i < ETH_ALEN; i++) /* Set physical address */
  793. {
  794. (p->ram)->ib.paddr[i] = *(nic->node_addr+i);
  795. }
  796. for (i = 0; i < 8; i++) /* Set multicast, logical address */
  797. {
  798. (p->ram)->ib.laddr[i] = 0; /* We do not use logical addressing */
  799. }
  800. /* Set ring descriptor pointers and set number of descriptors */
  801. (p->ram)->ib.rdrp = (int) p->rmdhead | RMDNUMMASK;
  802. (p->ram)->ib.tdrp = (int) p->tmdhead | TMDNUMMASK;
  803. /* Prepare LANCE Control and Status Registers */
  804. SK_write_reg(CSR3, CSR3_ACON); /* Ale Control !!!THIS MUST BE SET!!!! */
  805. /*
  806. * LANCE addresses the RAM from 0x0000 to 0x3fbf and has no access to
  807. * PC Memory locations.
  808. *
  809. * In structure SK_ram is defined that the first thing in ram
  810. * is the initialization block. So his address is for LANCE always
  811. * 0x0000
  812. *
  813. * CSR1 contains low order bits 15:0 of initialization block address
  814. * CSR2 is built of:
  815. * 7:0 High order bits 23:16 of initialization block address
  816. * 15:8 reserved, must be 0
  817. */
  818. /* Set initialization block address (must be on word boundary) */
  819. SK_write_reg(CSR1, 0); /* Set low order bits 15:0 */
  820. SK_write_reg(CSR2, 0); /* Set high order bits 23:16 */
  821. PRINTF(("## %s: After setting CSR1-3. CSR0: %#hX\n",
  822. SK_NAME, SK_read_reg(CSR0)));
  823. /* Initialize LANCE */
  824. /*
  825. * INIT = Initialize, when set, causes the LANCE to begin the
  826. * initialization procedure and access the Init Block.
  827. */
  828. SK_write_reg(CSR0, CSR0_INIT);
  829. /* Wait until LANCE finished initialization */
  830. SK_set_RAP(CSR0); /* Register Address Pointer to CSR0 */
  831. for (i = 0; (i < 100) && !(SK_rread_reg() & CSR0_IDON); i++)
  832. ; /* Wait until init done or go ahead if problems (i>=100) */
  833. if (i >= 100) /* Something is wrong ! */
  834. {
  835. printf("%s: can't init am7990, status: %#hX "
  836. "init_block: %#hX\n",
  837. SK_NAME, (int) SK_read_reg(CSR0),
  838. (unsigned int) &(p->ram)->ib);
  839. #ifdef SK_DEBUG
  840. SK_print_pos(nic, "LANCE INIT failed");
  841. #endif
  842. return -1; /* LANCE init failed */
  843. }
  844. PRINTF(("## %s: init done after %d ticks\n", SK_NAME, i));
  845. /* Clear Initialize done, enable Interrupts, start LANCE */
  846. SK_write_reg(CSR0, CSR0_IDON | CSR0_INEA | CSR0_STRT);
  847. PRINTF(("## %s: LANCE started. CSR0: %#hX\n", SK_NAME,
  848. SK_read_reg(CSR0)));
  849. return 0; /* LANCE is up and running */
  850. } /* End of SK_lance_init() */
  851. /* LANCE access functions
  852. *
  853. * ! CSR1-3 can only be accessed when in CSR0 the STOP bit is set !
  854. */
  855. static void SK_reset_board(void)
  856. {
  857. int i;
  858. PRINTF(("## %s: At beginning of SK_reset_board.\n", SK_NAME));
  859. SK_PORT = 0x00; /* Reset active */
  860. for (i = 0; i < 10 ; i++) /* Delay min 5ms */
  861. ;
  862. SK_PORT = SK_RESET; /* Set back to normal operation */
  863. } /* End of SK_reset_board() */
  864. static void SK_set_RAP(int reg_number)
  865. {
  866. SK_IOREG = reg_number;
  867. SK_PORT = SK_RESET | SK_RAP | SK_WREG;
  868. SK_IOCOM = SK_DOIO;
  869. while (SK_PORT & SK_IORUN)
  870. ;
  871. } /* End of SK_set_RAP() */
  872. static int SK_read_reg(int reg_number)
  873. {
  874. SK_set_RAP(reg_number);
  875. SK_PORT = SK_RESET | SK_RDATA | SK_RREG;
  876. SK_IOCOM = SK_DOIO;
  877. while (SK_PORT & SK_IORUN)
  878. ;
  879. return (SK_IOREG);
  880. } /* End of SK_read_reg() */
  881. static int SK_rread_reg(void)
  882. {
  883. SK_PORT = SK_RESET | SK_RDATA | SK_RREG;
  884. SK_IOCOM = SK_DOIO;
  885. while (SK_PORT & SK_IORUN)
  886. ;
  887. return (SK_IOREG);
  888. } /* End of SK_rread_reg() */
  889. static void SK_write_reg(int reg_number, int value)
  890. {
  891. SK_set_RAP(reg_number);
  892. SK_IOREG = value;
  893. SK_PORT = SK_RESET | SK_RDATA | SK_WREG;
  894. SK_IOCOM = SK_DOIO;
  895. while (SK_PORT & SK_IORUN)
  896. ;
  897. } /* End of SK_write_reg */
  898. /*
  899. * Debugging functions
  900. * -------------------
  901. */
  902. #ifdef SK_DEBUG
  903. static void SK_print_pos(struct nic *nic, char *text)
  904. {
  905. unsigned char pos0 = inb(SK_POS0),
  906. pos1 = inb(SK_POS1),
  907. pos2 = inb(SK_POS2),
  908. pos3 = inb(SK_POS3),
  909. pos4 = inb(SK_POS4);
  910. printf("## %s: %s.\n"
  911. "## pos0=%#hX pos1=%#hX pos2=%#hX pos3=%#hX pos4=%#hX\n",
  912. SK_NAME, text, pos0, pos1, pos2, (pos3<<14), pos4);
  913. } /* End of SK_print_pos() */
  914. static void SK_print_ram(struct nic *nic)
  915. {
  916. int i;
  917. struct priv *p = (struct priv *) nic->priv_data;
  918. printf("## %s: RAM Details.\n"
  919. "## RAM at %#hX tmdhead: %#hX rmdhead: %#hX initblock: %#hX\n",
  920. SK_NAME,
  921. (unsigned int) p->ram,
  922. (unsigned int) p->tmdhead,
  923. (unsigned int) p->rmdhead,
  924. (unsigned int) &(p->ram)->ib);
  925. printf("## ");
  926. for(i = 0; i < TMDNUM; i++)
  927. {
  928. if (!(i % 3)) /* Every third line do a newline */
  929. {
  930. printf("\n## ");
  931. }
  932. printf("tmdbufs%d: %#hX ", (i+1), (int) p->tmdbufs[i]);
  933. }
  934. printf("## ");
  935. for(i = 0; i < RMDNUM; i++)
  936. {
  937. if (!(i % 3)) /* Every third line do a newline */
  938. {
  939. printf("\n## ");
  940. }
  941. printf("rmdbufs%d: %#hX ", (i+1), (int) p->rmdbufs[i]);
  942. }
  943. putchar('\n');
  944. } /* End of SK_print_ram() */
  945. #endif
  946. static struct isa_driver SK_driver __isa_driver = {
  947. .type = NIC_DRIVER,
  948. .name = "SK_G16",
  949. .probe = SK_probe,
  950. .ioaddrs = 0,
  951. };
  952. ISA_ROM("sk_g16","Schneider and Koch G16");