Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

sk_g16.c 32KB

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