sk_g16.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066
  1. /*-
  2. * Copyright (C) 1994 by PJD Weichmann & SWS Bern, Switzerland
  3. *
  4. * This software may be used and distributed according to the terms
  5. * of the GNU General Public License, incorporated herein by reference.
  6. *
  7. * Module : sk_g16.c
  8. *
  9. * Version : $Revision: 1.1 $
  10. *
  11. * Author : Patrick J.D. Weichmann
  12. *
  13. * Date Created : 94/05/26
  14. * Last Updated : $Date: 1994/06/30 16:25:15 $
  15. *
  16. * Description : Schneider & Koch G16 Ethernet Device Driver for
  17. * Linux Kernel >= 1.1.22
  18. * Update History :
  19. * Paul Gortmaker, 03/97: Fix for v2.1.x to use read{b,w}
  20. * write{b,w} and memcpy -> memcpy_{to,from}io
  21. *
  22. * Jeff Garzik, 06/2000, Modularize
  23. *
  24. -*/
  25. static const char rcsid[] = "$Id: sk_g16.c,v 1.1 1994/06/30 16:25:15 root Exp $";
  26. /*
  27. * The Schneider & Koch (SK) G16 Network device driver is based
  28. * on the 'ni6510' driver from Michael Hipp which can be found at
  29. * ftp://sunsite.unc.edu/pub/Linux/system/Network/drivers/nidrivers.tar.gz
  30. *
  31. * Sources: 1) ni6510.c by M. Hipp
  32. * 2) depca.c by D.C. Davies
  33. * 3) skeleton.c by D. Becker
  34. * 4) Am7990 Local Area Network Controller for Ethernet (LANCE),
  35. * AMD, Pub. #05698, June 1989
  36. *
  37. * Many Thanks for helping me to get things working to:
  38. *
  39. * A. Cox (A.Cox@swansea.ac.uk)
  40. * M. Hipp (mhipp@student.uni-tuebingen.de)
  41. * R. Bolz (Schneider & Koch, Germany)
  42. *
  43. * To Do:
  44. * - Support of SK_G8 and other SK Network Cards.
  45. * - Autoset memory mapped RAM. Check for free memory and then
  46. * configure RAM correctly.
  47. * - SK_close should really set card in to initial state.
  48. * - Test if IRQ 3 is not switched off. Use autoirq() functionality.
  49. * (as in /drivers/net/skeleton.c)
  50. * - Implement Multicast addressing. At minimum something like
  51. * in depca.c.
  52. * - Redo the statistics part.
  53. * - Try to find out if the board is in 8 Bit or 16 Bit slot.
  54. * If in 8 Bit mode don't use IRQ 11.
  55. * - (Try to make it slightly faster.)
  56. * - Power management support
  57. */
  58. #include <linux/module.h>
  59. #include <linux/kernel.h>
  60. #include <linux/fcntl.h>
  61. #include <linux/ioport.h>
  62. #include <linux/interrupt.h>
  63. #include <linux/slab.h>
  64. #include <linux/string.h>
  65. #include <linux/delay.h>
  66. #include <linux/errno.h>
  67. #include <linux/init.h>
  68. #include <linux/spinlock.h>
  69. #include <linux/netdevice.h>
  70. #include <linux/etherdevice.h>
  71. #include <linux/skbuff.h>
  72. #include <linux/bitops.h>
  73. #include <asm/system.h>
  74. #include <asm/io.h>
  75. #include "sk_g16.h"
  76. /*
  77. * Schneider & Koch Card Definitions
  78. * =================================
  79. */
  80. #define SK_NAME "SK_G16"
  81. /*
  82. * SK_G16 Configuration
  83. * --------------------
  84. */
  85. /*
  86. * Abbreviations
  87. * -------------
  88. *
  89. * RAM - used for the 16KB shared memory
  90. * Boot_ROM, ROM - are used for referencing the BootEPROM
  91. *
  92. * SK_BOOT_ROM and SK_ADDR are symbolic constants used to configure
  93. * the behaviour of the driver and the SK_G16.
  94. *
  95. * ! See sk_g16.install on how to install and configure the driver !
  96. *
  97. * SK_BOOT_ROM defines if the Boot_ROM should be switched off or not.
  98. *
  99. * SK_ADDR defines the address where the RAM will be mapped into the real
  100. * host memory.
  101. * valid addresses are from 0xa0000 to 0xfc000 in 16Kbyte steps.
  102. */
  103. #define SK_BOOT_ROM 1 /* 1=BootROM on 0=off */
  104. #define SK_ADDR 0xcc000
  105. /*
  106. * In POS3 are bits A14-A19 of the address bus. These bits can be set
  107. * to choose the RAM address. That's why we only can choose the RAM address
  108. * in 16KB steps.
  109. */
  110. #define POS_ADDR (rom_addr>>14) /* Do not change this line */
  111. /*
  112. * SK_G16 I/O PORT's + IRQ's + Boot_ROM locations
  113. * ----------------------------------------------
  114. */
  115. /*
  116. * As nearly every card has also SK_G16 a specified I/O Port region and
  117. * only a few possible IRQ's.
  118. * In the Installation Guide from Schneider & Koch is listed a possible
  119. * Interrupt IRQ2. IRQ2 is always IRQ9 in boards with two cascaded interrupt
  120. * controllers. So we use in SK_IRQS IRQ9.
  121. */
  122. /* Don't touch any of the following #defines. */
  123. #define SK_IO_PORTS { 0x100, 0x180, 0x208, 0x220, 0x288, 0x320, 0x328, 0x390, 0 }
  124. #define SK_IRQS { 3, 5, 9, 11, 0 }
  125. #define SK_BOOT_ROM_LOCATIONS { 0xc0000, 0xc4000, 0xc8000, 0xcc000, 0xd0000, 0xd4000, 0xd8000, 0xdc000, 0 }
  126. #define SK_BOOT_ROM_ID { 0x55, 0xaa, 0x10, 0x50, 0x06, 0x33 }
  127. /*
  128. * SK_G16 POS REGISTERS
  129. * --------------------
  130. */
  131. /*
  132. * SK_G16 has a Programmable Option Select (POS) Register.
  133. * The POS is composed of 8 separate registers (POS0-7) which
  134. * are I/O mapped on an address set by the W1 switch.
  135. *
  136. */
  137. #define SK_POS_SIZE 8 /* 8 I/O Ports are used by SK_G16 */
  138. #define SK_POS0 ioaddr /* Card-ID Low (R) */
  139. #define SK_POS1 ioaddr+1 /* Card-ID High (R) */
  140. #define SK_POS2 ioaddr+2 /* Card-Enable, Boot-ROM Disable (RW) */
  141. #define SK_POS3 ioaddr+3 /* Base address of RAM */
  142. #define SK_POS4 ioaddr+4 /* IRQ */
  143. /* POS5 - POS7 are unused */
  144. /*
  145. * SK_G16 MAC PREFIX
  146. * -----------------
  147. */
  148. /*
  149. * Scheider & Koch manufacturer code (00:00:a5).
  150. * This must be checked, that we are sure it is a SK card.
  151. */
  152. #define SK_MAC0 0x00
  153. #define SK_MAC1 0x00
  154. #define SK_MAC2 0x5a
  155. /*
  156. * SK_G16 ID
  157. * ---------
  158. */
  159. /*
  160. * If POS0,POS1 contain the following ID, then we know
  161. * at which I/O Port Address we are.
  162. */
  163. #define SK_IDLOW 0xfd
  164. #define SK_IDHIGH 0x6a
  165. /*
  166. * LANCE POS Bit definitions
  167. * -------------------------
  168. */
  169. #define SK_ROM_RAM_ON (POS2_CARD)
  170. #define SK_ROM_RAM_OFF (POS2_EPROM)
  171. #define SK_ROM_ON (inb(SK_POS2) & POS2_CARD)
  172. #define SK_ROM_OFF (inb(SK_POS2) | POS2_EPROM)
  173. #define SK_RAM_ON (inb(SK_POS2) | POS2_CARD)
  174. #define SK_RAM_OFF (inb(SK_POS2) & POS2_EPROM)
  175. #define POS2_CARD 0x0001 /* 1 = SK_G16 on 0 = off */
  176. #define POS2_EPROM 0x0002 /* 1 = Boot EPROM off 0 = on */
  177. /*
  178. * SK_G16 Memory mapped Registers
  179. * ------------------------------
  180. *
  181. */
  182. #define SK_IOREG (&board->ioreg) /* LANCE data registers. */
  183. #define SK_PORT (&board->port) /* Control, Status register */
  184. #define SK_IOCOM (&board->iocom) /* I/O Command */
  185. /*
  186. * SK_G16 Status/Control Register bits
  187. * -----------------------------------
  188. *
  189. * (C) Controlreg (S) Statusreg
  190. */
  191. /*
  192. * Register transfer: 0 = no transfer
  193. * 1 = transferring data between LANCE and I/O reg
  194. */
  195. #define SK_IORUN 0x20
  196. /*
  197. * LANCE interrupt: 0 = LANCE interrupt occurred
  198. * 1 = no LANCE interrupt occurred
  199. */
  200. #define SK_IRQ 0x10
  201. #define SK_RESET 0x08 /* Reset SK_CARD: 0 = RESET 1 = normal */
  202. #define SK_RW 0x02 /* 0 = write to 1 = read from */
  203. #define SK_ADR 0x01 /* 0 = REG DataPort 1 = RAP Reg addr port */
  204. #define SK_RREG SK_RW /* Transferdirection to read from lance */
  205. #define SK_WREG 0 /* Transferdirection to write to lance */
  206. #define SK_RAP SK_ADR /* Destination Register RAP */
  207. #define SK_RDATA 0 /* Destination Register REG DataPort */
  208. /*
  209. * SK_G16 I/O Command
  210. * ------------------
  211. */
  212. /*
  213. * Any bitcombination sets the internal I/O bit (transfer will start)
  214. * when written to I/O Command
  215. */
  216. #define SK_DOIO 0x80 /* Do Transfer */
  217. /*
  218. * LANCE RAP (Register Address Port).
  219. * ---------------------------------
  220. */
  221. /*
  222. * The LANCE internal registers are selected through the RAP.
  223. * The Registers are:
  224. *
  225. * CSR0 - Status and Control flags
  226. * CSR1 - Low order bits of initialize block (bits 15:00)
  227. * CSR2 - High order bits of initialize block (bits 07:00, 15:08 are reserved)
  228. * CSR3 - Allows redefinition of the Bus Master Interface.
  229. * This register must be set to 0x0002, which means BSWAP = 0,
  230. * ACON = 1, BCON = 0;
  231. *
  232. */
  233. #define CSR0 0x00
  234. #define CSR1 0x01
  235. #define CSR2 0x02
  236. #define CSR3 0x03
  237. /*
  238. * General Definitions
  239. * ===================
  240. */
  241. /*
  242. * Set the number of Tx and Rx buffers, using Log_2(# buffers).
  243. * We have 16KB RAM which can be accessed by the LANCE. In the
  244. * memory are not only the buffers but also the ring descriptors and
  245. * the initialize block.
  246. * Don't change anything unless you really know what you do.
  247. */
  248. #define LC_LOG_TX_BUFFERS 1 /* (2 == 2^^1) 2 Transmit buffers */
  249. #define LC_LOG_RX_BUFFERS 3 /* (8 == 2^^3) 8 Receive buffers */
  250. /* Descriptor ring sizes */
  251. #define TMDNUM (1 << (LC_LOG_TX_BUFFERS)) /* 2 Transmit descriptor rings */
  252. #define RMDNUM (1 << (LC_LOG_RX_BUFFERS)) /* 8 Receive Buffers */
  253. /* Define Mask for setting RMD, TMD length in the LANCE init_block */
  254. #define TMDNUMMASK (LC_LOG_TX_BUFFERS << 29)
  255. #define RMDNUMMASK (LC_LOG_RX_BUFFERS << 29)
  256. /*
  257. * Data Buffer size is set to maximum packet length.
  258. */
  259. #define PKT_BUF_SZ 1518
  260. /*
  261. * The number of low I/O ports used by the ethercard.
  262. */
  263. #define ETHERCARD_TOTAL_SIZE SK_POS_SIZE
  264. /*
  265. * SK_DEBUG
  266. *
  267. * Here you can choose what level of debugging wanted.
  268. *
  269. * If SK_DEBUG and SK_DEBUG2 are undefined, then only the
  270. * necessary messages will be printed.
  271. *
  272. * If SK_DEBUG is defined, there will be many debugging prints
  273. * which can help to find some mistakes in configuration or even
  274. * in the driver code.
  275. *
  276. * If SK_DEBUG2 is defined, many many messages will be printed
  277. * which normally you don't need. I used this to check the interrupt
  278. * routine.
  279. *
  280. * (If you define only SK_DEBUG2 then only the messages for
  281. * checking interrupts will be printed!)
  282. *
  283. * Normal way of live is:
  284. *
  285. * For the whole thing get going let both symbolic constants
  286. * undefined. If you face any problems and you know what's going
  287. * on (you know something about the card and you can interpret some
  288. * hex LANCE register output) then define SK_DEBUG
  289. *
  290. */
  291. #undef SK_DEBUG /* debugging */
  292. #undef SK_DEBUG2 /* debugging with more verbose report */
  293. #ifdef SK_DEBUG
  294. #define PRINTK(x) printk x
  295. #else
  296. #define PRINTK(x) /**/
  297. #endif
  298. #ifdef SK_DEBUG2
  299. #define PRINTK2(x) printk x
  300. #else
  301. #define PRINTK2(x) /**/
  302. #endif
  303. /*
  304. * SK_G16 RAM
  305. *
  306. * The components are memory mapped and can be set in a region from
  307. * 0x00000 through 0xfc000 in 16KB steps.
  308. *
  309. * The Network components are: dual ported RAM, Prom, I/O Reg, Status-,
  310. * Controlregister and I/O Command.
  311. *
  312. * dual ported RAM: This is the only memory region which the LANCE chip
  313. * has access to. From the Lance it is addressed from 0x0000 to
  314. * 0x3fbf. The host accesses it normally.
  315. *
  316. * PROM: The PROM obtains the ETHERNET-MAC-Address. It is realised as a
  317. * 8-Bit PROM, this means only the 16 even addresses are used of the
  318. * 32 Byte Address region. Access to an odd address results in invalid
  319. * data.
  320. *
  321. * LANCE I/O Reg: The I/O Reg is build of 4 single Registers, Low-Byte Write,
  322. * Hi-Byte Write, Low-Byte Read, Hi-Byte Read.
  323. * Transfer from or to the LANCE is always in 16Bit so Low and High
  324. * registers are always relevant.
  325. *
  326. * The Data from the Readregister is not the data in the Writeregister!!
  327. *
  328. * Port: Status- and Controlregister.
  329. * Two different registers which share the same address, Status is
  330. * read-only, Control is write-only.
  331. *
  332. * I/O Command:
  333. * Any bitcombination written in here starts the transmission between
  334. * Host and LANCE.
  335. */
  336. typedef struct
  337. {
  338. unsigned char ram[0x3fc0]; /* 16KB dual ported ram */
  339. unsigned char rom[0x0020]; /* 32Byte PROM containing 6Byte MAC */
  340. unsigned char res1[0x0010]; /* reserved */
  341. unsigned volatile short ioreg;/* LANCE I/O Register */
  342. unsigned volatile char port; /* Statusregister and Controlregister */
  343. unsigned char iocom; /* I/O Command Register */
  344. } SK_RAM;
  345. /* struct */
  346. /*
  347. * This is the structure for the dual ported ram. We
  348. * have exactly 16 320 Bytes. In here there must be:
  349. *
  350. * - Initialize Block (starting at a word boundary)
  351. * - Receive and Transmit Descriptor Rings (quadword boundary)
  352. * - Data Buffers (arbitrary boundary)
  353. *
  354. * This is because LANCE has on SK_G16 only access to the dual ported
  355. * RAM and nowhere else.
  356. */
  357. struct SK_ram
  358. {
  359. struct init_block ib;
  360. struct tmd tmde[TMDNUM];
  361. struct rmd rmde[RMDNUM];
  362. char tmdbuf[TMDNUM][PKT_BUF_SZ];
  363. char rmdbuf[RMDNUM][PKT_BUF_SZ];
  364. };
  365. /*
  366. * Structure where all necessary information is for ring buffer
  367. * management and statistics.
  368. */
  369. struct priv
  370. {
  371. struct SK_ram *ram; /* dual ported ram structure */
  372. struct rmd *rmdhead; /* start of receive ring descriptors */
  373. struct tmd *tmdhead; /* start of transmit ring descriptors */
  374. int rmdnum; /* actual used ring descriptor */
  375. int tmdnum; /* actual transmit descriptor for transmitting data */
  376. int tmdlast; /* last sent descriptor used for error handling, etc */
  377. void *rmdbufs[RMDNUM]; /* pointer to the receive buffers */
  378. void *tmdbufs[TMDNUM]; /* pointer to the transmit buffers */
  379. struct net_device_stats stats; /* Device driver statistics */
  380. };
  381. /* global variable declaration */
  382. /* IRQ map used to reserve a IRQ (see SK_open()) */
  383. /* static variables */
  384. static SK_RAM *board; /* pointer to our memory mapped board components */
  385. static DEFINE_SPINLOCK(SK_lock);
  386. /* Macros */
  387. /* Function Prototypes */
  388. /*
  389. * Device Driver functions
  390. * -----------------------
  391. * See for short explanation of each function its definitions header.
  392. */
  393. static int SK_probe(struct net_device *dev, short ioaddr);
  394. static void SK_timeout(struct net_device *dev);
  395. static int SK_open(struct net_device *dev);
  396. static int SK_send_packet(struct sk_buff *skb, struct net_device *dev);
  397. static irqreturn_t SK_interrupt(int irq, void *dev_id, struct pt_regs * regs);
  398. static void SK_rxintr(struct net_device *dev);
  399. static void SK_txintr(struct net_device *dev);
  400. static int SK_close(struct net_device *dev);
  401. static struct net_device_stats *SK_get_stats(struct net_device *dev);
  402. unsigned int SK_rom_addr(void);
  403. static void set_multicast_list(struct net_device *dev);
  404. /*
  405. * LANCE Functions
  406. * ---------------
  407. */
  408. static int SK_lance_init(struct net_device *dev, unsigned short mode);
  409. void SK_reset_board(void);
  410. void SK_set_RAP(int reg_number);
  411. int SK_read_reg(int reg_number);
  412. int SK_rread_reg(void);
  413. void SK_write_reg(int reg_number, int value);
  414. /*
  415. * Debugging functions
  416. * -------------------
  417. */
  418. void SK_print_pos(struct net_device *dev, char *text);
  419. void SK_print_dev(struct net_device *dev, char *text);
  420. void SK_print_ram(struct net_device *dev);
  421. /*-
  422. * Function : SK_init
  423. * Author : Patrick J.D. Weichmann
  424. * Date Created : 94/05/26
  425. *
  426. * Description : Check for a SK_G16 network adaptor and initialize it.
  427. * This function gets called by dev_init which initializes
  428. * all Network devices.
  429. *
  430. * Parameters : I : struct net_device *dev - structure preconfigured
  431. * from Space.c
  432. * Return Value : 0 = Driver Found and initialized
  433. * Errors : ENODEV - no device found
  434. * ENXIO - not probed
  435. * Globals : None
  436. * Update History :
  437. * YY/MM/DD uid Description
  438. -*/
  439. static int io; /* 0 == probe */
  440. /*
  441. * Check for a network adaptor of this type, and return '0' if one exists.
  442. * If dev->base_addr == 0, probe all likely locations.
  443. * If dev->base_addr == 1, always return failure.
  444. */
  445. struct net_device * __init SK_init(int unit)
  446. {
  447. int *port, ports[] = SK_IO_PORTS; /* SK_G16 supported ports */
  448. static unsigned version_printed;
  449. struct net_device *dev = alloc_etherdev(sizeof(struct priv));
  450. int err = -ENODEV;
  451. if (!dev)
  452. return ERR_PTR(-ENOMEM);
  453. if (unit >= 0) {
  454. sprintf(dev->name, "eth%d", unit);
  455. netdev_boot_setup_check(dev);
  456. io = dev->base_addr;
  457. }
  458. if (version_printed++ == 0)
  459. PRINTK(("%s: %s", SK_NAME, rcsid));
  460. if (io > 0xff) { /* Check a single specified address */
  461. err = -EBUSY;
  462. /* Check if on specified address is a SK_G16 */
  463. if (request_region(io, ETHERCARD_TOTAL_SIZE, "sk_g16")) {
  464. err = SK_probe(dev, io);
  465. if (!err)
  466. goto got_it;
  467. release_region(io, ETHERCARD_TOTAL_SIZE);
  468. }
  469. } else if (io > 0) { /* Don't probe at all */
  470. err = -ENXIO;
  471. } else {
  472. /* Autoprobe base_addr */
  473. for (port = &ports[0]; *port; port++) {
  474. io = *port;
  475. /* Check if I/O Port region is used by another board */
  476. if (!request_region(io, ETHERCARD_TOTAL_SIZE, "sk_g16"))
  477. continue; /* Try next Port address */
  478. /* Check if at ioaddr is a SK_G16 */
  479. if (SK_probe(dev, io) == 0)
  480. goto got_it;
  481. release_region(io, ETHERCARD_TOTAL_SIZE);
  482. }
  483. }
  484. err_out:
  485. free_netdev(dev);
  486. return ERR_PTR(err);
  487. got_it:
  488. err = register_netdev(dev);
  489. if (err) {
  490. release_region(dev->base_addr, ETHERCARD_TOTAL_SIZE);
  491. goto err_out;
  492. }
  493. return dev;
  494. } /* End of SK_init */
  495. MODULE_AUTHOR("Patrick J.D. Weichmann");
  496. MODULE_DESCRIPTION("Schneider & Koch G16 Ethernet Device Driver");
  497. MODULE_LICENSE("GPL");
  498. MODULE_PARM(io, "i");
  499. MODULE_PARM_DESC(io, "0 to probe common ports (unsafe), or the I/O base of the board");
  500. #ifdef MODULE
  501. static struct net_device *SK_dev;
  502. static int __init SK_init_module (void)
  503. {
  504. SK_dev = SK_init(-1);
  505. return IS_ERR(SK_dev) ? PTR_ERR(SK_dev) : 0;
  506. }
  507. static void __exit SK_cleanup_module (void)
  508. {
  509. unregister_netdev(SK_dev);
  510. release_region(SK_dev->base_addr, ETHERCARD_TOTAL_SIZE);
  511. free_netdev(SK_dev);
  512. }
  513. module_init(SK_init_module);
  514. module_exit(SK_cleanup_module);
  515. #endif
  516. /*-
  517. * Function : SK_probe
  518. * Author : Patrick J.D. Weichmann
  519. * Date Created : 94/05/26
  520. *
  521. * Description : This function is called by SK_init and
  522. * does the main part of initialization.
  523. *
  524. * Parameters : I : struct net_device *dev - SK_G16 device structure
  525. * I : short ioaddr - I/O Port address where POS is.
  526. * Return Value : 0 = Initialization done
  527. * Errors : ENODEV - No SK_G16 found
  528. * -1 - Configuration problem
  529. * Globals : board - pointer to SK_RAM
  530. * Update History :
  531. * YY/MM/DD uid Description
  532. * 94/06/30 pwe SK_ADDR now checked and at the correct place
  533. -*/
  534. int __init SK_probe(struct net_device *dev, short ioaddr)
  535. {
  536. int i,j; /* Counters */
  537. int sk_addr_flag = 0; /* SK ADDR correct? 1 - no, 0 - yes */
  538. unsigned int rom_addr; /* used to store RAM address used for POS_ADDR */
  539. struct priv *p = netdev_priv(dev); /* SK_G16 private structure */
  540. if (inb(SK_POS0) != SK_IDLOW || inb(SK_POS1) != SK_IDHIGH)
  541. return -ENODEV;
  542. dev->base_addr = ioaddr;
  543. if (SK_ADDR & 0x3fff || SK_ADDR < 0xa0000)
  544. {
  545. sk_addr_flag = 1;
  546. /*
  547. * Now here we could use a routine which searches for a free
  548. * place in the ram and set SK_ADDR if found. TODO.
  549. */
  550. }
  551. if (SK_BOOT_ROM) /* Shall we keep Boot_ROM on ? */
  552. {
  553. PRINTK(("## %s: SK_BOOT_ROM is set.\n", SK_NAME));
  554. rom_addr = SK_rom_addr();
  555. if (rom_addr == 0) /* No Boot_ROM found */
  556. {
  557. if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
  558. {
  559. printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
  560. dev->name, SK_ADDR);
  561. return -1;
  562. }
  563. rom_addr = SK_ADDR; /* assign predefined address */
  564. PRINTK(("## %s: NO Bootrom found \n", SK_NAME));
  565. outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */
  566. outb(POS_ADDR, SK_POS3); /* Set RAM address */
  567. outb(SK_RAM_ON, SK_POS2); /* enable RAM */
  568. }
  569. else if (rom_addr == SK_ADDR)
  570. {
  571. printk("%s: RAM + ROM are set to the same address %#08x\n"
  572. " Check configuration. Now switching off Boot_ROM\n",
  573. SK_NAME, rom_addr);
  574. outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off*/
  575. outb(POS_ADDR, SK_POS3); /* Set RAM address */
  576. outb(SK_RAM_ON, SK_POS2); /* enable RAM */
  577. }
  578. else
  579. {
  580. PRINTK(("## %s: Found ROM at %#08x\n", SK_NAME, rom_addr));
  581. PRINTK(("## %s: Keeping Boot_ROM on\n", SK_NAME));
  582. if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
  583. {
  584. printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
  585. dev->name, SK_ADDR);
  586. return -1;
  587. }
  588. rom_addr = SK_ADDR;
  589. outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */
  590. outb(POS_ADDR, SK_POS3); /* Set RAM address */
  591. outb(SK_ROM_RAM_ON, SK_POS2); /* RAM on, BOOT_ROM on */
  592. }
  593. }
  594. else /* Don't keep Boot_ROM */
  595. {
  596. PRINTK(("## %s: SK_BOOT_ROM is not set.\n", SK_NAME));
  597. if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
  598. {
  599. printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
  600. dev->name, SK_ADDR);
  601. return -1;
  602. }
  603. rom_addr = SK_rom_addr(); /* Try to find a Boot_ROM */
  604. /* IF we find a Boot_ROM disable it */
  605. outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */
  606. /* We found a Boot_ROM and it's gone. Set RAM address on
  607. * Boot_ROM address.
  608. */
  609. if (rom_addr)
  610. {
  611. printk("%s: We found Boot_ROM at %#08x. Now setting RAM on"
  612. "that address\n", SK_NAME, rom_addr);
  613. outb(POS_ADDR, SK_POS3); /* Set RAM on Boot_ROM address */
  614. }
  615. else /* We did not find a Boot_ROM, use predefined SK_ADDR for ram */
  616. {
  617. if (sk_addr_flag) /* No or Invalid SK_ADDR is defined */
  618. {
  619. printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
  620. dev->name, SK_ADDR);
  621. return -1;
  622. }
  623. rom_addr = SK_ADDR;
  624. outb(POS_ADDR, SK_POS3); /* Set RAM address */
  625. }
  626. outb(SK_RAM_ON, SK_POS2); /* enable RAM */
  627. }
  628. #ifdef SK_DEBUG
  629. SK_print_pos(dev, "POS registers after ROM, RAM config");
  630. #endif
  631. board = (SK_RAM *) isa_bus_to_virt(rom_addr);
  632. /* Read in station address */
  633. for (i = 0, j = 0; i < ETH_ALEN; i++, j+=2)
  634. {
  635. dev->dev_addr[i] = readb(board->rom+j);
  636. }
  637. /* Check for manufacturer code */
  638. if (!(dev->dev_addr[0] == SK_MAC0 &&
  639. dev->dev_addr[1] == SK_MAC1 &&
  640. dev->dev_addr[2] == SK_MAC2) )
  641. {
  642. PRINTK(("## %s: We did not find SK_G16 at RAM location.\n",
  643. SK_NAME));
  644. return -ENODEV; /* NO SK_G16 found */
  645. }
  646. printk("%s: %s found at %#3x, HW addr: %#04x:%02x:%02x:%02x:%02x:%02x\n",
  647. dev->name,
  648. "Schneider & Koch Netcard",
  649. (unsigned int) dev->base_addr,
  650. dev->dev_addr[0],
  651. dev->dev_addr[1],
  652. dev->dev_addr[2],
  653. dev->dev_addr[3],
  654. dev->dev_addr[4],
  655. dev->dev_addr[5]);
  656. memset((char *) dev->priv, 0, sizeof(struct priv)); /* clear memory */
  657. /* Assign our Device Driver functions */
  658. dev->open = SK_open;
  659. dev->stop = SK_close;
  660. dev->hard_start_xmit = SK_send_packet;
  661. dev->get_stats = SK_get_stats;
  662. dev->set_multicast_list = set_multicast_list;
  663. dev->tx_timeout = SK_timeout;
  664. dev->watchdog_timeo = HZ/7;
  665. dev->flags &= ~IFF_MULTICAST;
  666. /* Initialize private structure */
  667. p->ram = (struct SK_ram *) rom_addr; /* Set dual ported RAM addr */
  668. p->tmdhead = &(p->ram)->tmde[0]; /* Set TMD head */
  669. p->rmdhead = &(p->ram)->rmde[0]; /* Set RMD head */
  670. /* Initialize buffer pointers */
  671. for (i = 0; i < TMDNUM; i++)
  672. {
  673. p->tmdbufs[i] = &(p->ram)->tmdbuf[i];
  674. }
  675. for (i = 0; i < RMDNUM; i++)
  676. {
  677. p->rmdbufs[i] = &(p->ram)->rmdbuf[i];
  678. }
  679. #ifdef SK_DEBUG
  680. SK_print_pos(dev, "End of SK_probe");
  681. SK_print_ram(dev);
  682. #endif
  683. return 0; /* Initialization done */
  684. } /* End of SK_probe() */
  685. /*-
  686. * Function : SK_open
  687. * Author : Patrick J.D. Weichmann
  688. * Date Created : 94/05/26
  689. *
  690. * Description : This function is called sometimes after booting
  691. * when ifconfig program is run.
  692. *
  693. * This function requests an IRQ, sets the correct
  694. * IRQ in the card. Then calls SK_lance_init() to
  695. * init and start the LANCE chip. Then if everything is
  696. * ok returns with 0 (OK), which means SK_G16 is now
  697. * opened and operational.
  698. *
  699. * (Called by dev_open() /net/inet/dev.c)
  700. *
  701. * Parameters : I : struct net_device *dev - SK_G16 device structure
  702. * Return Value : 0 - Device opened
  703. * Errors : -EAGAIN - Open failed
  704. * Side Effects : None
  705. * Update History :
  706. * YY/MM/DD uid Description
  707. -*/
  708. static int SK_open(struct net_device *dev)
  709. {
  710. int i = 0;
  711. int irqval = 0;
  712. int ioaddr = dev->base_addr;
  713. int irqtab[] = SK_IRQS;
  714. struct priv *p = netdev_priv(dev);
  715. PRINTK(("## %s: At beginning of SK_open(). CSR0: %#06x\n",
  716. SK_NAME, SK_read_reg(CSR0)));
  717. if (dev->irq == 0) /* Autoirq */
  718. {
  719. i = 0;
  720. /*
  721. * Check if one IRQ out of SK_IRQS is free and install
  722. * interrupt handler.
  723. * Most done by request_irq().
  724. * irqval: 0 - interrupt handler installed for IRQ irqtab[i]
  725. * -EBUSY - interrupt busy
  726. * -EINVAL - irq > 15 or handler = NULL
  727. */
  728. do
  729. {
  730. irqval = request_irq(irqtab[i], &SK_interrupt, 0, "sk_g16", dev);
  731. i++;
  732. } while (irqval && irqtab[i]);
  733. if (irqval) /* We tried every possible IRQ but no success */
  734. {
  735. printk("%s: unable to get an IRQ\n", dev->name);
  736. return -EAGAIN;
  737. }
  738. dev->irq = irqtab[--i];
  739. outb(i<<2, SK_POS4); /* Set Card on probed IRQ */
  740. }
  741. else if (dev->irq == 2) /* IRQ2 is always IRQ9 */
  742. {
  743. if (request_irq(9, &SK_interrupt, 0, "sk_g16", dev))
  744. {
  745. printk("%s: unable to get IRQ 9\n", dev->name);
  746. return -EAGAIN;
  747. }
  748. dev->irq = 9;
  749. /*
  750. * Now we set card on IRQ2.
  751. * This can be confusing, but remember that IRQ2 on the network
  752. * card is in reality IRQ9
  753. */
  754. outb(0x08, SK_POS4); /* set card to IRQ2 */
  755. }
  756. else /* Check IRQ as defined in Space.c */
  757. {
  758. int i = 0;
  759. /* check if IRQ free and valid. Then install Interrupt handler */
  760. if (request_irq(dev->irq, &SK_interrupt, 0, "sk_g16", dev))
  761. {
  762. printk("%s: unable to get selected IRQ\n", dev->name);
  763. return -EAGAIN;
  764. }
  765. switch(dev->irq)
  766. {
  767. case 3: i = 0;
  768. break;
  769. case 5: i = 1;
  770. break;
  771. case 2: i = 2;
  772. break;
  773. case 11:i = 3;
  774. break;
  775. default:
  776. printk("%s: Preselected IRQ %d is invalid for %s boards",
  777. dev->name,
  778. dev->irq,
  779. SK_NAME);
  780. return -EAGAIN;
  781. }
  782. outb(i<<2, SK_POS4); /* Set IRQ on card */
  783. }
  784. printk("%s: Schneider & Koch G16 at %#3x, IRQ %d, shared mem at %#08x\n",
  785. dev->name, (unsigned int)dev->base_addr,
  786. (int) dev->irq, (unsigned int) p->ram);
  787. if (!(i = SK_lance_init(dev, 0))) /* LANCE init OK? */
  788. {
  789. netif_start_queue(dev);
  790. #ifdef SK_DEBUG
  791. /*
  792. * This debug block tries to stop LANCE,
  793. * reinit LANCE with transmitter and receiver disabled,
  794. * then stop again and reinit with NORMAL_MODE
  795. */
  796. printk("## %s: After lance init. CSR0: %#06x\n",
  797. SK_NAME, SK_read_reg(CSR0));
  798. SK_write_reg(CSR0, CSR0_STOP);
  799. printk("## %s: LANCE stopped. CSR0: %#06x\n",
  800. SK_NAME, SK_read_reg(CSR0));
  801. SK_lance_init(dev, MODE_DTX | MODE_DRX);
  802. printk("## %s: Reinit with DTX + DRX off. CSR0: %#06x\n",
  803. SK_NAME, SK_read_reg(CSR0));
  804. SK_write_reg(CSR0, CSR0_STOP);
  805. printk("## %s: LANCE stopped. CSR0: %#06x\n",
  806. SK_NAME, SK_read_reg(CSR0));
  807. SK_lance_init(dev, MODE_NORMAL);
  808. printk("## %s: LANCE back to normal mode. CSR0: %#06x\n",
  809. SK_NAME, SK_read_reg(CSR0));
  810. SK_print_pos(dev, "POS regs before returning OK");
  811. #endif /* SK_DEBUG */
  812. return 0; /* SK_open() is successful */
  813. }
  814. else /* LANCE init failed */
  815. {
  816. PRINTK(("## %s: LANCE init failed: CSR0: %#06x\n",
  817. SK_NAME, SK_read_reg(CSR0)));
  818. return -EAGAIN;
  819. }
  820. } /* End of SK_open() */
  821. /*-
  822. * Function : SK_lance_init
  823. * Author : Patrick J.D. Weichmann
  824. * Date Created : 94/05/26
  825. *
  826. * Description : Reset LANCE chip, fill RMD, TMD structures with
  827. * start values and Start LANCE.
  828. *
  829. * Parameters : I : struct net_device *dev - SK_G16 device structure
  830. * I : int mode - put LANCE into "mode" see data-sheet for
  831. * more info.
  832. * Return Value : 0 - Init done
  833. * Errors : -1 - Init failed
  834. * Update History :
  835. * YY/MM/DD uid Description
  836. -*/
  837. static int SK_lance_init(struct net_device *dev, unsigned short mode)
  838. {
  839. int i;
  840. unsigned long flags;
  841. struct priv *p = netdev_priv(dev);
  842. struct tmd *tmdp;
  843. struct rmd *rmdp;
  844. PRINTK(("## %s: At beginning of LANCE init. CSR0: %#06x\n",
  845. SK_NAME, SK_read_reg(CSR0)));
  846. /* Reset LANCE */
  847. SK_reset_board();
  848. /* Initialize TMD's with start values */
  849. p->tmdnum = 0; /* First descriptor for transmitting */
  850. p->tmdlast = 0; /* First descriptor for reading stats */
  851. for (i = 0; i < TMDNUM; i++) /* Init all TMD's */
  852. {
  853. tmdp = p->tmdhead + i;
  854. writel((unsigned long) p->tmdbufs[i], tmdp->u.buffer); /* assign buffer */
  855. /* Mark TMD as start and end of packet */
  856. writeb(TX_STP | TX_ENP, &tmdp->u.s.status);
  857. }
  858. /* Initialize RMD's with start values */
  859. p->rmdnum = 0; /* First RMD which will be used */
  860. for (i = 0; i < RMDNUM; i++) /* Init all RMD's */
  861. {
  862. rmdp = p->rmdhead + i;
  863. writel((unsigned long) p->rmdbufs[i], rmdp->u.buffer); /* assign buffer */
  864. /*
  865. * LANCE must be owner at beginning so that he can fill in
  866. * receiving packets, set status and release RMD
  867. */
  868. writeb(RX_OWN, &rmdp->u.s.status);
  869. writew(-PKT_BUF_SZ, &rmdp->blen); /* Buffer Size (two's complement) */
  870. writeb(0, &rmdp->mlen); /* init message length */
  871. }
  872. /* Fill LANCE Initialize Block */
  873. writew(mode, (&((p->ram)->ib.mode))); /* Set operation mode */
  874. for (i = 0; i < ETH_ALEN; i++) /* Set physical address */
  875. {
  876. writeb(dev->dev_addr[i], (&((p->ram)->ib.paddr[i])));
  877. }
  878. for (i = 0; i < 8; i++) /* Set multicast, logical address */
  879. {
  880. writeb(0, (&((p->ram)->ib.laddr[i]))); /* We do not use logical addressing */
  881. }
  882. /* Set ring descriptor pointers and set number of descriptors */
  883. writel((int)p->rmdhead | RMDNUMMASK, (&((p->ram)->ib.rdrp)));
  884. writel((int)p->tmdhead | TMDNUMMASK, (&((p->ram)->ib.tdrp)));
  885. /* Prepare LANCE Control and Status Registers */
  886. spin_lock_irqsave(&SK_lock, flags);
  887. SK_write_reg(CSR3, CSR3_ACON); /* Ale Control !!!THIS MUST BE SET!!!! */
  888. /*
  889. * LANCE addresses the RAM from 0x0000 to 0x3fbf and has no access to
  890. * PC Memory locations.
  891. *
  892. * In structure SK_ram is defined that the first thing in ram
  893. * is the initialization block. So his address is for LANCE always
  894. * 0x0000
  895. *
  896. * CSR1 contains low order bits 15:0 of initialization block address
  897. * CSR2 is built of:
  898. * 7:0 High order bits 23:16 of initialization block address
  899. * 15:8 reserved, must be 0
  900. */
  901. /* Set initialization block address (must be on word boundary) */
  902. SK_write_reg(CSR1, 0); /* Set low order bits 15:0 */
  903. SK_write_reg(CSR2, 0); /* Set high order bits 23:16 */
  904. PRINTK(("## %s: After setting CSR1-3. CSR0: %#06x\n",
  905. SK_NAME, SK_read_reg(CSR0)));
  906. /* Initialize LANCE */
  907. /*
  908. * INIT = Initialize, when set, causes the LANCE to begin the
  909. * initialization procedure and access the Init Block.
  910. */
  911. SK_write_reg(CSR0, CSR0_INIT);
  912. spin_unlock_irqrestore(&SK_lock, flags);
  913. /* Wait until LANCE finished initialization */
  914. SK_set_RAP(CSR0); /* Register Address Pointer to CSR0 */
  915. for (i = 0; (i < 100) && !(SK_rread_reg() & CSR0_IDON); i++)
  916. ; /* Wait until init done or go ahead if problems (i>=100) */
  917. if (i >= 100) /* Something is wrong ! */
  918. {
  919. printk("%s: can't init am7990, status: %04x "
  920. "init_block: %#08x\n",
  921. dev->name, (int) SK_read_reg(CSR0),
  922. (unsigned int) &(p->ram)->ib);
  923. #ifdef SK_DEBUG
  924. SK_print_pos(dev, "LANCE INIT failed");
  925. SK_print_dev(dev,"Device Structure:");
  926. #endif
  927. return -1; /* LANCE init failed */
  928. }
  929. PRINTK(("## %s: init done after %d ticks\n", SK_NAME, i));
  930. /* Clear Initialize done, enable Interrupts, start LANCE */
  931. SK_write_reg(CSR0, CSR0_IDON | CSR0_INEA | CSR0_STRT);
  932. PRINTK(("## %s: LANCE started. CSR0: %#06x\n", SK_NAME,
  933. SK_read_reg(CSR0)));
  934. return 0; /* LANCE is up and running */
  935. } /* End of SK_lance_init() */
  936. /*-
  937. * Function : SK_send_packet
  938. * Author : Patrick J.D. Weichmann
  939. * Date Created : 94/05/27
  940. *
  941. * Description : Writes an socket buffer into a transmit descriptor
  942. * and starts transmission.
  943. *
  944. * Parameters : I : struct sk_buff *skb - packet to transfer
  945. * I : struct net_device *dev - SK_G16 device structure
  946. * Return Value : 0 - OK
  947. * 1 - Could not transmit (dev_queue_xmit will queue it)
  948. * and try to sent it later
  949. * Globals : None
  950. * Side Effects : None
  951. * Update History :
  952. * YY/MM/DD uid Description
  953. -*/
  954. static void SK_timeout(struct net_device *dev)
  955. {
  956. printk(KERN_WARNING "%s: xmitter timed out, try to restart!\n", dev->name);
  957. SK_lance_init(dev, MODE_NORMAL); /* Reinit LANCE */
  958. netif_wake_queue(dev); /* Clear Transmitter flag */
  959. dev->trans_start = jiffies; /* Mark Start of transmission */
  960. }
  961. static int SK_send_packet(struct sk_buff *skb, struct net_device *dev)
  962. {
  963. struct priv *p = netdev_priv(dev);
  964. struct tmd *tmdp;
  965. static char pad[64];
  966. PRINTK2(("## %s: SK_send_packet() called, CSR0 %#04x.\n",
  967. SK_NAME, SK_read_reg(CSR0)));
  968. /*
  969. * Block a timer-based transmit from overlapping.
  970. * This means check if we are already in.
  971. */
  972. netif_stop_queue (dev);
  973. {
  974. /* Evaluate Packet length */
  975. short len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
  976. tmdp = p->tmdhead + p->tmdnum; /* Which descriptor for transmitting */
  977. /* Fill in Transmit Message Descriptor */
  978. /* Copy data into dual ported ram */
  979. memcpy_toio((tmdp->u.buffer & 0x00ffffff), skb->data, skb->len);
  980. if (len != skb->len)
  981. memcpy_toio((tmdp->u.buffer & 0x00ffffff) + skb->len, pad, len-skb->len);
  982. writew(-len, &tmdp->blen); /* set length to transmit */
  983. /*
  984. * Packet start and end is always set because we use the maximum
  985. * packet length as buffer length.
  986. * Relinquish ownership to LANCE
  987. */
  988. writeb(TX_OWN | TX_STP | TX_ENP, &tmdp->u.s.status);
  989. /* Start Demand Transmission */
  990. SK_write_reg(CSR0, CSR0_TDMD | CSR0_INEA);
  991. dev->trans_start = jiffies; /* Mark start of transmission */
  992. /* Set pointer to next transmit buffer */
  993. p->tmdnum++;
  994. p->tmdnum &= TMDNUM-1;
  995. /* Do we own the next transmit buffer ? */
  996. if (! (readb(&((p->tmdhead + p->tmdnum)->u.s.status)) & TX_OWN) )
  997. {
  998. /*
  999. * We own next buffer and are ready to transmit, so
  1000. * clear busy flag
  1001. */
  1002. netif_start_queue(dev);
  1003. }
  1004. p->stats.tx_bytes += skb->len;
  1005. }
  1006. dev_kfree_skb(skb);
  1007. return 0;
  1008. } /* End of SK_send_packet */
  1009. /*-
  1010. * Function : SK_interrupt
  1011. * Author : Patrick J.D. Weichmann
  1012. * Date Created : 94/05/27
  1013. *
  1014. * Description : SK_G16 interrupt handler which checks for LANCE
  1015. * Errors, handles transmit and receive interrupts
  1016. *
  1017. * Parameters : I : int irq, void *dev_id, struct pt_regs * regs -
  1018. * Return Value : None
  1019. * Errors : None
  1020. * Globals : None
  1021. * Side Effects : None
  1022. * Update History :
  1023. * YY/MM/DD uid Description
  1024. -*/
  1025. static irqreturn_t SK_interrupt(int irq, void *dev_id, struct pt_regs * regs)
  1026. {
  1027. int csr0;
  1028. struct net_device *dev = dev_id;
  1029. struct priv *p = netdev_priv(dev);
  1030. PRINTK2(("## %s: SK_interrupt(). status: %#06x\n",
  1031. SK_NAME, SK_read_reg(CSR0)));
  1032. if (dev == NULL)
  1033. {
  1034. printk("SK_interrupt(): IRQ %d for unknown device.\n", irq);
  1035. }
  1036. spin_lock (&SK_lock);
  1037. csr0 = SK_read_reg(CSR0); /* store register for checking */
  1038. /*
  1039. * Acknowledge all of the current interrupt sources, disable
  1040. * Interrupts (INEA = 0)
  1041. */
  1042. SK_write_reg(CSR0, csr0 & CSR0_CLRALL);
  1043. if (csr0 & CSR0_ERR) /* LANCE Error */
  1044. {
  1045. printk("%s: error: %04x\n", dev->name, csr0);
  1046. if (csr0 & CSR0_MISS) /* No place to store packet ? */
  1047. {
  1048. p->stats.rx_dropped++;
  1049. }
  1050. }
  1051. if (csr0 & CSR0_RINT) /* Receive Interrupt (packet arrived) */
  1052. {
  1053. SK_rxintr(dev);
  1054. }
  1055. if (csr0 & CSR0_TINT) /* Transmit interrupt (packet sent) */
  1056. {
  1057. SK_txintr(dev);
  1058. }
  1059. SK_write_reg(CSR0, CSR0_INEA); /* Enable Interrupts */
  1060. spin_unlock (&SK_lock);
  1061. return IRQ_HANDLED;
  1062. } /* End of SK_interrupt() */
  1063. /*-
  1064. * Function : SK_txintr
  1065. * Author : Patrick J.D. Weichmann
  1066. * Date Created : 94/05/27
  1067. *
  1068. * Description : After sending a packet we check status, update
  1069. * statistics and relinquish ownership of transmit
  1070. * descriptor ring.
  1071. *
  1072. * Parameters : I : struct net_device *dev - SK_G16 device structure
  1073. * Return Value : None
  1074. * Errors : None
  1075. * Globals : None
  1076. * Update History :
  1077. * YY/MM/DD uid Description
  1078. -*/
  1079. static void SK_txintr(struct net_device *dev)
  1080. {
  1081. int tmdstat;
  1082. struct tmd *tmdp;
  1083. struct priv *p = netdev_priv(dev);
  1084. PRINTK2(("## %s: SK_txintr() status: %#06x\n",
  1085. SK_NAME, SK_read_reg(CSR0)));
  1086. tmdp = p->tmdhead + p->tmdlast; /* Which buffer we sent at last ? */
  1087. /* Set next buffer */
  1088. p->tmdlast++;
  1089. p->tmdlast &= TMDNUM-1;
  1090. tmdstat = readb(&tmdp->u.s.status);
  1091. /*
  1092. * We check status of transmitted packet.
  1093. * see LANCE data-sheet for error explanation
  1094. */
  1095. if (tmdstat & TX_ERR) /* Error occurred */
  1096. {
  1097. int stat2 = readw(&tmdp->status2);
  1098. printk("%s: TX error: %04x %04x\n", dev->name, tmdstat, stat2);
  1099. if (stat2 & TX_TDR) /* TDR problems? */
  1100. {
  1101. printk("%s: tdr-problems \n", dev->name);
  1102. }
  1103. if (stat2 & TX_RTRY) /* Failed in 16 attempts to transmit ? */
  1104. p->stats.tx_aborted_errors++;
  1105. if (stat2 & TX_LCOL) /* Late collision ? */
  1106. p->stats.tx_window_errors++;
  1107. if (stat2 & TX_LCAR) /* Loss of Carrier ? */
  1108. p->stats.tx_carrier_errors++;
  1109. if (stat2 & TX_UFLO) /* Underflow error ? */
  1110. {
  1111. p->stats.tx_fifo_errors++;
  1112. /*
  1113. * If UFLO error occurs it will turn transmitter of.
  1114. * So we must reinit LANCE
  1115. */
  1116. SK_lance_init(dev, MODE_NORMAL);
  1117. }
  1118. p->stats.tx_errors++;
  1119. writew(0, &tmdp->status2); /* Clear error flags */
  1120. }
  1121. else if (tmdstat & TX_MORE) /* Collisions occurred ? */
  1122. {
  1123. /*
  1124. * Here I have a problem.
  1125. * I only know that there must be one or up to 15 collisions.
  1126. * That's why TX_MORE is set, because after 16 attempts TX_RTRY
  1127. * will be set which means couldn't send packet aborted transfer.
  1128. *
  1129. * First I did not have this in but then I thought at minimum
  1130. * we see that something was not ok.
  1131. * If anyone knows something better than this to handle this
  1132. * please report it.
  1133. */
  1134. p->stats.collisions++;
  1135. }
  1136. else /* Packet sent without any problems */
  1137. {
  1138. p->stats.tx_packets++;
  1139. }
  1140. /*
  1141. * We mark transmitter not busy anymore, because now we have a free
  1142. * transmit descriptor which can be filled by SK_send_packet and
  1143. * afterwards sent by the LANCE
  1144. *
  1145. * The function which do handle slow IRQ parts is do_bottom_half()
  1146. * which runs at normal kernel priority, that means all interrupt are
  1147. * enabled. (see kernel/irq.c)
  1148. *
  1149. * net_bh does something like this:
  1150. * - check if already in net_bh
  1151. * - try to transmit something from the send queue
  1152. * - if something is in the receive queue send it up to higher
  1153. * levels if it is a known protocol
  1154. * - try to transmit something from the send queue
  1155. */
  1156. netif_wake_queue(dev);
  1157. } /* End of SK_txintr() */
  1158. /*-
  1159. * Function : SK_rxintr
  1160. * Author : Patrick J.D. Weichmann
  1161. * Date Created : 94/05/27
  1162. *
  1163. * Description : Buffer sent, check for errors, relinquish ownership
  1164. * of the receive message descriptor.
  1165. *
  1166. * Parameters : I : SK_G16 device structure
  1167. * Return Value : None
  1168. * Globals : None
  1169. * Update History :
  1170. * YY/MM/DD uid Description
  1171. -*/
  1172. static void SK_rxintr(struct net_device *dev)
  1173. {
  1174. struct rmd *rmdp;
  1175. int rmdstat;
  1176. struct priv *p = netdev_priv(dev);
  1177. PRINTK2(("## %s: SK_rxintr(). CSR0: %#06x\n",
  1178. SK_NAME, SK_read_reg(CSR0)));
  1179. rmdp = p->rmdhead + p->rmdnum;
  1180. /* As long as we own the next entry, check status and send
  1181. * it up to higher layer
  1182. */
  1183. while (!( (rmdstat = readb(&rmdp->u.s.status)) & RX_OWN))
  1184. {
  1185. /*
  1186. * Start and end of packet must be set, because we use
  1187. * the ethernet maximum packet length (1518) as buffer size.
  1188. *
  1189. * Because our buffers are at maximum OFLO and BUFF errors are
  1190. * not to be concerned (see Data sheet)
  1191. */
  1192. if ((rmdstat & (RX_STP | RX_ENP)) != (RX_STP | RX_ENP))
  1193. {
  1194. /* Start of a frame > 1518 Bytes ? */
  1195. if (rmdstat & RX_STP)
  1196. {
  1197. p->stats.rx_errors++; /* bad packet received */
  1198. p->stats.rx_length_errors++; /* packet too long */
  1199. printk("%s: packet too long\n", dev->name);
  1200. }
  1201. /*
  1202. * All other packets will be ignored until a new frame with
  1203. * start (RX_STP) set follows.
  1204. *
  1205. * What we do is just give descriptor free for new incoming
  1206. * packets.
  1207. */
  1208. writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */
  1209. }
  1210. else if (rmdstat & RX_ERR) /* Receive Error ? */
  1211. {
  1212. printk("%s: RX error: %04x\n", dev->name, (int) rmdstat);
  1213. p->stats.rx_errors++;
  1214. if (rmdstat & RX_FRAM) p->stats.rx_frame_errors++;
  1215. if (rmdstat & RX_CRC) p->stats.rx_crc_errors++;
  1216. writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */
  1217. }
  1218. else /* We have a packet which can be queued for the upper layers */
  1219. {
  1220. int len = readw(&rmdp->mlen) & 0x0fff; /* extract message length from receive buffer */
  1221. struct sk_buff *skb;
  1222. skb = dev_alloc_skb(len+2); /* allocate socket buffer */
  1223. if (skb == NULL) /* Could not get mem ? */
  1224. {
  1225. /*
  1226. * Couldn't allocate sk_buffer so we give descriptor back
  1227. * to Lance, update statistics and go ahead.
  1228. */
  1229. writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */
  1230. printk("%s: Couldn't allocate sk_buff, deferring packet.\n",
  1231. dev->name);
  1232. p->stats.rx_dropped++;
  1233. break; /* Jump out */
  1234. }
  1235. /* Prepare sk_buff to queue for upper layers */
  1236. skb->dev = dev;
  1237. skb_reserve(skb,2); /* Align IP header on 16 byte boundary */
  1238. /*
  1239. * Copy data out of our receive descriptor into sk_buff.
  1240. *
  1241. * (rmdp->u.buffer & 0x00ffffff) -> get address of buffer and
  1242. * ignore status fields)
  1243. */
  1244. memcpy_fromio(skb_put(skb,len), (rmdp->u.buffer & 0x00ffffff), len);
  1245. /*
  1246. * Notify the upper protocol layers that there is another packet
  1247. * to handle
  1248. *
  1249. * netif_rx() always succeeds. see /net/inet/dev.c for more.
  1250. */
  1251. skb->protocol=eth_type_trans(skb,dev);
  1252. netif_rx(skb); /* queue packet and mark it for processing */
  1253. /*
  1254. * Packet is queued and marked for processing so we
  1255. * free our descriptor and update statistics
  1256. */
  1257. writeb(RX_OWN, &rmdp->u.s.status);
  1258. dev->last_rx = jiffies;
  1259. p->stats.rx_packets++;
  1260. p->stats.rx_bytes += len;
  1261. p->rmdnum++;
  1262. p->rmdnum %= RMDNUM;
  1263. rmdp = p->rmdhead + p->rmdnum;
  1264. }
  1265. }
  1266. } /* End of SK_rxintr() */
  1267. /*-
  1268. * Function : SK_close
  1269. * Author : Patrick J.D. Weichmann
  1270. * Date Created : 94/05/26
  1271. *
  1272. * Description : close gets called from dev_close() and should
  1273. * deinstall the card (free_irq, mem etc).
  1274. *
  1275. * Parameters : I : struct net_device *dev - our device structure
  1276. * Return Value : 0 - closed device driver
  1277. * Errors : None
  1278. * Globals : None
  1279. * Update History :
  1280. * YY/MM/DD uid Description
  1281. -*/
  1282. /* I have tried to set BOOT_ROM on and RAM off but then, after a 'ifconfig
  1283. * down' the system stops. So I don't shut set card to init state.
  1284. */
  1285. static int SK_close(struct net_device *dev)
  1286. {
  1287. PRINTK(("## %s: SK_close(). CSR0: %#06x\n",
  1288. SK_NAME, SK_read_reg(CSR0)));
  1289. netif_stop_queue(dev); /* Transmitter busy */
  1290. printk("%s: Shutting %s down CSR0 %#06x\n", dev->name, SK_NAME,
  1291. (int) SK_read_reg(CSR0));
  1292. SK_write_reg(CSR0, CSR0_STOP); /* STOP the LANCE */
  1293. free_irq(dev->irq, dev); /* Free IRQ */
  1294. return 0; /* always succeed */
  1295. } /* End of SK_close() */
  1296. /*-
  1297. * Function : SK_get_stats
  1298. * Author : Patrick J.D. Weichmann
  1299. * Date Created : 94/05/26
  1300. *
  1301. * Description : Return current status structure to upper layers.
  1302. * It is called by sprintf_stats (dev.c).
  1303. *
  1304. * Parameters : I : struct net_device *dev - our device structure
  1305. * Return Value : struct net_device_stats * - our current statistics
  1306. * Errors : None
  1307. * Side Effects : None
  1308. * Update History :
  1309. * YY/MM/DD uid Description
  1310. -*/
  1311. static struct net_device_stats *SK_get_stats(struct net_device *dev)
  1312. {
  1313. struct priv *p = netdev_priv(dev);
  1314. PRINTK(("## %s: SK_get_stats(). CSR0: %#06x\n",
  1315. SK_NAME, SK_read_reg(CSR0)));
  1316. return &p->stats; /* Return Device status */
  1317. } /* End of SK_get_stats() */
  1318. /*-
  1319. * Function : set_multicast_list
  1320. * Author : Patrick J.D. Weichmann
  1321. * Date Created : 94/05/26
  1322. *
  1323. * Description : This function gets called when a program performs
  1324. * a SIOCSIFFLAGS call. Ifconfig does this if you call
  1325. * 'ifconfig [-]allmulti' which enables or disables the
  1326. * Promiscuous mode.
  1327. * Promiscuous mode is when the Network card accepts all
  1328. * packets, not only the packets which match our MAC
  1329. * Address. It is useful for writing a network monitor,
  1330. * but it is also a security problem. You have to remember
  1331. * that all information on the net is not encrypted.
  1332. *
  1333. * Parameters : I : struct net_device *dev - SK_G16 device Structure
  1334. * Return Value : None
  1335. * Errors : None
  1336. * Globals : None
  1337. * Update History :
  1338. * YY/MM/DD uid Description
  1339. * 95/10/18 ACox New multicast calling scheme
  1340. -*/
  1341. /* Set or clear the multicast filter for SK_G16.
  1342. */
  1343. static void set_multicast_list(struct net_device *dev)
  1344. {
  1345. if (dev->flags&IFF_PROMISC)
  1346. {
  1347. /* Reinitialize LANCE with MODE_PROM set */
  1348. SK_lance_init(dev, MODE_PROM);
  1349. }
  1350. else if (dev->mc_count==0 && !(dev->flags&IFF_ALLMULTI))
  1351. {
  1352. /* Reinitialize LANCE without MODE_PROM */
  1353. SK_lance_init(dev, MODE_NORMAL);
  1354. }
  1355. else
  1356. {
  1357. /* Multicast with logical address filter on */
  1358. /* Reinitialize LANCE without MODE_PROM */
  1359. SK_lance_init(dev, MODE_NORMAL);
  1360. /* Not implemented yet. */
  1361. }
  1362. } /* End of set_multicast_list() */
  1363. /*-
  1364. * Function : SK_rom_addr
  1365. * Author : Patrick J.D. Weichmann
  1366. * Date Created : 94/06/01
  1367. *
  1368. * Description : Try to find a Boot_ROM at all possible locations
  1369. *
  1370. * Parameters : None
  1371. * Return Value : Address where Boot_ROM is
  1372. * Errors : 0 - Did not find Boot_ROM
  1373. * Globals : None
  1374. * Update History :
  1375. * YY/MM/DD uid Description
  1376. -*/
  1377. unsigned int __init SK_rom_addr(void)
  1378. {
  1379. int i,j;
  1380. int rom_found = 0;
  1381. unsigned int rom_location[] = SK_BOOT_ROM_LOCATIONS;
  1382. unsigned char rom_id[] = SK_BOOT_ROM_ID;
  1383. unsigned char test_byte;
  1384. /* Autodetect Boot_ROM */
  1385. PRINTK(("## %s: Autodetection of Boot_ROM\n", SK_NAME));
  1386. for (i = 0; (rom_location[i] != 0) && (rom_found == 0); i++)
  1387. {
  1388. PRINTK(("## Trying ROM location %#08x", rom_location[i]));
  1389. rom_found = 1;
  1390. for (j = 0; j < 6; j++)
  1391. {
  1392. test_byte = readb(rom_location[i]+j);
  1393. PRINTK((" %02x ", *test_byte));
  1394. if(test_byte != rom_id[j])
  1395. {
  1396. rom_found = 0;
  1397. }
  1398. }
  1399. PRINTK(("\n"));
  1400. }
  1401. if (rom_found == 1)
  1402. {
  1403. PRINTK(("## %s: Boot_ROM found at %#08x\n",
  1404. SK_NAME, rom_location[(i-1)]));
  1405. return (rom_location[--i]);
  1406. }
  1407. else
  1408. {
  1409. PRINTK(("%s: No Boot_ROM found\n", SK_NAME));
  1410. return 0;
  1411. }
  1412. } /* End of SK_rom_addr() */
  1413. /* LANCE access functions
  1414. *
  1415. * ! CSR1-3 can only be accessed when in CSR0 the STOP bit is set !
  1416. */
  1417. /*-
  1418. * Function : SK_reset_board
  1419. *
  1420. * Author : Patrick J.D. Weichmann
  1421. *
  1422. * Date Created : 94/05/25
  1423. *
  1424. * Description : This function resets SK_G16 and all components, but
  1425. * POS registers are not changed
  1426. *
  1427. * Parameters : None
  1428. * Return Value : None
  1429. * Errors : None
  1430. * Globals : SK_RAM *board - SK_RAM structure pointer
  1431. *
  1432. * Update History :
  1433. * YY/MM/DD uid Description
  1434. -*/
  1435. void SK_reset_board(void)
  1436. {
  1437. writeb(0x00, SK_PORT); /* Reset active */
  1438. mdelay(5); /* Delay min 5ms */
  1439. writeb(SK_RESET, SK_PORT); /* Set back to normal operation */
  1440. } /* End of SK_reset_board() */
  1441. /*-
  1442. * Function : SK_set_RAP
  1443. * Author : Patrick J.D. Weichmann
  1444. * Date Created : 94/05/25
  1445. *
  1446. * Description : Set LANCE Register Address Port to register
  1447. * for later data transfer.
  1448. *
  1449. * Parameters : I : reg_number - which CSR to read/write from/to
  1450. * Return Value : None
  1451. * Errors : None
  1452. * Globals : SK_RAM *board - SK_RAM structure pointer
  1453. * Update History :
  1454. * YY/MM/DD uid Description
  1455. -*/
  1456. void SK_set_RAP(int reg_number)
  1457. {
  1458. writew(reg_number, SK_IOREG);
  1459. writeb(SK_RESET | SK_RAP | SK_WREG, SK_PORT);
  1460. writeb(SK_DOIO, SK_IOCOM);
  1461. while (readb(SK_PORT) & SK_IORUN)
  1462. barrier();
  1463. } /* End of SK_set_RAP() */
  1464. /*-
  1465. * Function : SK_read_reg
  1466. * Author : Patrick J.D. Weichmann
  1467. * Date Created : 94/05/25
  1468. *
  1469. * Description : Set RAP and read data from a LANCE CSR register
  1470. *
  1471. * Parameters : I : reg_number - which CSR to read from
  1472. * Return Value : Register contents
  1473. * Errors : None
  1474. * Globals : SK_RAM *board - SK_RAM structure pointer
  1475. * Update History :
  1476. * YY/MM/DD uid Description
  1477. -*/
  1478. int SK_read_reg(int reg_number)
  1479. {
  1480. SK_set_RAP(reg_number);
  1481. writeb(SK_RESET | SK_RDATA | SK_RREG, SK_PORT);
  1482. writeb(SK_DOIO, SK_IOCOM);
  1483. while (readb(SK_PORT) & SK_IORUN)
  1484. barrier();
  1485. return (readw(SK_IOREG));
  1486. } /* End of SK_read_reg() */
  1487. /*-
  1488. * Function : SK_rread_reg
  1489. * Author : Patrick J.D. Weichmann
  1490. * Date Created : 94/05/28
  1491. *
  1492. * Description : Read data from preseted register.
  1493. * This function requires that you know which
  1494. * Register is actually set. Be aware that CSR1-3
  1495. * can only be accessed when in CSR0 STOP is set.
  1496. *
  1497. * Return Value : Register contents
  1498. * Errors : None
  1499. * Globals : SK_RAM *board - SK_RAM structure pointer
  1500. * Update History :
  1501. * YY/MM/DD uid Description
  1502. -*/
  1503. int SK_rread_reg(void)
  1504. {
  1505. writeb(SK_RESET | SK_RDATA | SK_RREG, SK_PORT);
  1506. writeb(SK_DOIO, SK_IOCOM);
  1507. while (readb(SK_PORT) & SK_IORUN)
  1508. barrier();
  1509. return (readw(SK_IOREG));
  1510. } /* End of SK_rread_reg() */
  1511. /*-
  1512. * Function : SK_write_reg
  1513. * Author : Patrick J.D. Weichmann
  1514. * Date Created : 94/05/25
  1515. *
  1516. * Description : This function sets the RAP then fills in the
  1517. * LANCE I/O Reg and starts Transfer to LANCE.
  1518. * It waits until transfer has ended which is max. 7 ms
  1519. * and then it returns.
  1520. *
  1521. * Parameters : I : reg_number - which CSR to write to
  1522. * I : value - what value to fill into register
  1523. * Return Value : None
  1524. * Errors : None
  1525. * Globals : SK_RAM *board - SK_RAM structure pointer
  1526. * Update History :
  1527. * YY/MM/DD uid Description
  1528. -*/
  1529. void SK_write_reg(int reg_number, int value)
  1530. {
  1531. SK_set_RAP(reg_number);
  1532. writew(value, SK_IOREG);
  1533. writeb(SK_RESET | SK_RDATA | SK_WREG, SK_PORT);
  1534. writeb(SK_DOIO, SK_IOCOM);
  1535. while (readb(SK_PORT) & SK_IORUN)
  1536. barrier();
  1537. } /* End of SK_write_reg */
  1538. /*
  1539. * Debugging functions
  1540. * -------------------
  1541. */
  1542. /*-
  1543. * Function : SK_print_pos
  1544. * Author : Patrick J.D. Weichmann
  1545. * Date Created : 94/05/25
  1546. *
  1547. * Description : This function prints out the 4 POS (Programmable
  1548. * Option Select) Registers. Used mainly to debug operation.
  1549. *
  1550. * Parameters : I : struct net_device *dev - SK_G16 device structure
  1551. * I : char * - Text which will be printed as title
  1552. * Return Value : None
  1553. * Errors : None
  1554. * Update History :
  1555. * YY/MM/DD uid Description
  1556. -*/
  1557. void SK_print_pos(struct net_device *dev, char *text)
  1558. {
  1559. int ioaddr = dev->base_addr;
  1560. unsigned char pos0 = inb(SK_POS0),
  1561. pos1 = inb(SK_POS1),
  1562. pos2 = inb(SK_POS2),
  1563. pos3 = inb(SK_POS3),
  1564. pos4 = inb(SK_POS4);
  1565. printk("## %s: %s.\n"
  1566. "## pos0=%#4x pos1=%#4x pos2=%#04x pos3=%#08x pos4=%#04x\n",
  1567. SK_NAME, text, pos0, pos1, pos2, (pos3<<14), pos4);
  1568. } /* End of SK_print_pos() */
  1569. /*-
  1570. * Function : SK_print_dev
  1571. * Author : Patrick J.D. Weichmann
  1572. * Date Created : 94/05/25
  1573. *
  1574. * Description : This function simply prints out the important fields
  1575. * of the device structure.
  1576. *
  1577. * Parameters : I : struct net_device *dev - SK_G16 device structure
  1578. * I : char *text - Title for printing
  1579. * Return Value : None
  1580. * Errors : None
  1581. * Update History :
  1582. * YY/MM/DD uid Description
  1583. -*/
  1584. void SK_print_dev(struct net_device *dev, char *text)
  1585. {
  1586. if (dev == NULL)
  1587. {
  1588. printk("## %s: Device Structure. %s\n", SK_NAME, text);
  1589. printk("## DEVICE == NULL\n");
  1590. }
  1591. else
  1592. {
  1593. printk("## %s: Device Structure. %s\n", SK_NAME, text);
  1594. printk("## Device Name: %s Base Address: %#06lx IRQ: %d\n",
  1595. dev->name, dev->base_addr, dev->irq);
  1596. printk("## next device: %#08x init function: %#08x\n",
  1597. (int) dev->next, (int) dev->init);
  1598. }
  1599. } /* End of SK_print_dev() */
  1600. /*-
  1601. * Function : SK_print_ram
  1602. * Author : Patrick J.D. Weichmann
  1603. * Date Created : 94/06/02
  1604. *
  1605. * Description : This function is used to check how are things set up
  1606. * in the 16KB RAM. Also the pointers to the receive and
  1607. * transmit descriptor rings and rx and tx buffers locations.
  1608. * It contains a minor bug in printing, but has no effect to the values
  1609. * only newlines are not correct.
  1610. *
  1611. * Parameters : I : struct net_device *dev - SK_G16 device structure
  1612. * Return Value : None
  1613. * Errors : None
  1614. * Globals : None
  1615. * Update History :
  1616. * YY/MM/DD uid Description
  1617. -*/
  1618. void __init SK_print_ram(struct net_device *dev)
  1619. {
  1620. int i;
  1621. struct priv *p = netdev_priv(dev);
  1622. printk("## %s: RAM Details.\n"
  1623. "## RAM at %#08x tmdhead: %#08x rmdhead: %#08x initblock: %#08x\n",
  1624. SK_NAME,
  1625. (unsigned int) p->ram,
  1626. (unsigned int) p->tmdhead,
  1627. (unsigned int) p->rmdhead,
  1628. (unsigned int) &(p->ram)->ib);
  1629. printk("## ");
  1630. for(i = 0; i < TMDNUM; i++)
  1631. {
  1632. if (!(i % 3)) /* Every third line do a newline */
  1633. {
  1634. printk("\n## ");
  1635. }
  1636. printk("tmdbufs%d: %#08x ", (i+1), (int) p->tmdbufs[i]);
  1637. }
  1638. printk("## ");
  1639. for(i = 0; i < RMDNUM; i++)
  1640. {
  1641. if (!(i % 3)) /* Every third line do a newline */
  1642. {
  1643. printk("\n## ");
  1644. }
  1645. printk("rmdbufs%d: %#08x ", (i+1), (int) p->rmdbufs[i]);
  1646. }
  1647. printk("\n");
  1648. } /* End of SK_print_ram() */