cs89x0.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866
  1. /* cs89x0.c: A Crystal Semiconductor (Now Cirrus Logic) CS89[02]0
  2. * driver for linux.
  3. */
  4. /*
  5. Written 1996 by Russell Nelson, with reference to skeleton.c
  6. written 1993-1994 by Donald Becker.
  7. This software may be used and distributed according to the terms
  8. of the GNU General Public License, incorporated herein by reference.
  9. The author may be reached at nelson@crynwr.com, Crynwr
  10. Software, 521 Pleasant Valley Rd., Potsdam, NY 13676
  11. Changelog:
  12. Mike Cruse : mcruse@cti-ltd.com
  13. : Changes for Linux 2.0 compatibility.
  14. : Added dev_id parameter in net_interrupt(),
  15. : request_irq() and free_irq(). Just NULL for now.
  16. Mike Cruse : Added MOD_INC_USE_COUNT and MOD_DEC_USE_COUNT macros
  17. : in net_open() and net_close() so kerneld would know
  18. : that the module is in use and wouldn't eject the
  19. : driver prematurely.
  20. Mike Cruse : Rewrote init_module() and cleanup_module using 8390.c
  21. : as an example. Disabled autoprobing in init_module(),
  22. : not a good thing to do to other devices while Linux
  23. : is running from all accounts.
  24. Russ Nelson : Jul 13 1998. Added RxOnly DMA support.
  25. Melody Lee : Aug 10 1999. Changes for Linux 2.2.5 compatibility.
  26. : email: ethernet@crystal.cirrus.com
  27. Alan Cox : Removed 1.2 support, added 2.1 extra counters.
  28. Andrew Morton : andrewm@uow.edu.au
  29. : Kernel 2.3.48
  30. : Handle kmalloc() failures
  31. : Other resource allocation fixes
  32. : Add SMP locks
  33. : Integrate Russ Nelson's ALLOW_DMA functionality back in.
  34. : If ALLOW_DMA is true, make DMA runtime selectable
  35. : Folded in changes from Cirrus (Melody Lee
  36. : <klee@crystal.cirrus.com>)
  37. : Don't call netif_wake_queue() in net_send_packet()
  38. : Fixed an out-of-mem bug in dma_rx()
  39. : Updated Documentation/networking/cs89x0.txt
  40. Andrew Morton : andrewm@uow.edu.au / Kernel 2.3.99-pre1
  41. : Use skb_reserve to longword align IP header (two places)
  42. : Remove a delay loop from dma_rx()
  43. : Replace '100' with HZ
  44. : Clean up a couple of skb API abuses
  45. : Added 'cs89x0_dma=N' kernel boot option
  46. : Correctly initialise lp->lock in non-module compile
  47. Andrew Morton : andrewm@uow.edu.au / Kernel 2.3.99-pre4-1
  48. : MOD_INC/DEC race fix (see
  49. : http://www.uwsg.indiana.edu/hypermail/linux/kernel/0003.3/1532.html)
  50. Andrew Morton : andrewm@uow.edu.au / Kernel 2.4.0-test7-pre2
  51. : Enhanced EEPROM support to cover more devices,
  52. : abstracted IRQ mapping to support CONFIG_ARCH_CLPS7500 arch
  53. : (Jason Gunthorpe <jgg@ualberta.ca>)
  54. Andrew Morton : Kernel 2.4.0-test11-pre4
  55. : Use dev->name in request_*() (Andrey Panin)
  56. : Fix an error-path memleak in init_module()
  57. : Preserve return value from request_irq()
  58. : Fix type of `media' module parm (Keith Owens)
  59. : Use SET_MODULE_OWNER()
  60. : Tidied up strange request_irq() abuse in net_open().
  61. Andrew Morton : Kernel 2.4.3-pre1
  62. : Request correct number of pages for DMA (Hugh Dickens)
  63. : Select PP_ChipID _after_ unregister_netdev in cleanup_module()
  64. : because unregister_netdev() calls get_stats.
  65. : Make `version[]' __initdata
  66. : Uninlined the read/write reg/word functions.
  67. Oskar Schirmer : oskar@scara.com
  68. : HiCO.SH4 (superh) support added (irq#1, cs89x0_media=)
  69. Deepak Saxena : dsaxena@plexity.net
  70. : Intel IXDP2x01 (XScale ixp2x00 NPU) platform support
  71. */
  72. /* Always include 'config.h' first in case the user wants to turn on
  73. or override something. */
  74. #include <linux/config.h>
  75. #include <linux/module.h>
  76. /*
  77. * Set this to zero to disable DMA code
  78. *
  79. * Note that even if DMA is turned off we still support the 'dma' and 'use_dma'
  80. * module options so we don't break any startup scripts.
  81. */
  82. #ifndef CONFIG_ARCH_IXDP2X01
  83. #define ALLOW_DMA 0
  84. #else
  85. #define ALLOW_DMA 1
  86. #endif
  87. /*
  88. * Set this to zero to remove all the debug statements via
  89. * dead code elimination
  90. */
  91. #define DEBUGGING 1
  92. /*
  93. Sources:
  94. Crynwr packet driver epktisa.
  95. Crystal Semiconductor data sheets.
  96. */
  97. #include <linux/errno.h>
  98. #include <linux/netdevice.h>
  99. #include <linux/etherdevice.h>
  100. #include <linux/kernel.h>
  101. #include <linux/types.h>
  102. #include <linux/fcntl.h>
  103. #include <linux/interrupt.h>
  104. #include <linux/ioport.h>
  105. #include <linux/in.h>
  106. #include <linux/skbuff.h>
  107. #include <linux/slab.h>
  108. #include <linux/spinlock.h>
  109. #include <linux/string.h>
  110. #include <linux/init.h>
  111. #include <linux/bitops.h>
  112. #include <linux/delay.h>
  113. #include <asm/system.h>
  114. #include <asm/io.h>
  115. #if ALLOW_DMA
  116. #include <asm/dma.h>
  117. #endif
  118. #include "cs89x0.h"
  119. static char version[] __initdata =
  120. "cs89x0.c: v2.4.3-pre1 Russell Nelson <nelson@crynwr.com>, Andrew Morton <andrewm@uow.edu.au>\n";
  121. #define DRV_NAME "cs89x0"
  122. /* First, a few definitions that the brave might change.
  123. A zero-terminated list of I/O addresses to be probed. Some special flags..
  124. Addr & 1 = Read back the address port, look for signature and reset
  125. the page window before probing
  126. Addr & 3 = Reset the page window and probe
  127. The CLPS eval board has the Cirrus chip at 0x80090300, in ARM IO space,
  128. but it is possible that a Cirrus board could be plugged into the ISA
  129. slots. */
  130. /* The cs8900 has 4 IRQ pins, software selectable. cs8900_irq_map maps
  131. them to system IRQ numbers. This mapping is card specific and is set to
  132. the configuration of the Cirrus Eval board for this chip. */
  133. #ifdef CONFIG_ARCH_CLPS7500
  134. static unsigned int netcard_portlist[] __initdata =
  135. { 0x80090303, 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0};
  136. static unsigned int cs8900_irq_map[] = {12,0,0,0};
  137. #elif defined(CONFIG_SH_HICOSH4)
  138. static unsigned int netcard_portlist[] __initdata =
  139. { 0x0300, 0};
  140. static unsigned int cs8900_irq_map[] = {1,0,0,0};
  141. #elif defined(CONFIG_ARCH_IXDP2X01)
  142. #include <asm/irq.h>
  143. static unsigned int netcard_portlist[] __initdata = {IXDP2X01_CS8900_VIRT_BASE, 0};
  144. static unsigned int cs8900_irq_map[] = {IRQ_IXDP2X01_CS8900, 0, 0, 0};
  145. #else
  146. static unsigned int netcard_portlist[] __initdata =
  147. { 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0};
  148. static unsigned int cs8900_irq_map[] = {10,11,12,5};
  149. #endif
  150. #if DEBUGGING
  151. static unsigned int net_debug = DEBUGGING;
  152. #else
  153. #define net_debug 0 /* gcc will remove all the debug code for us */
  154. #endif
  155. /* The number of low I/O ports used by the ethercard. */
  156. #define NETCARD_IO_EXTENT 16
  157. /* we allow the user to override various values normally set in the EEPROM */
  158. #define FORCE_RJ45 0x0001 /* pick one of these three */
  159. #define FORCE_AUI 0x0002
  160. #define FORCE_BNC 0x0004
  161. #define FORCE_AUTO 0x0010 /* pick one of these three */
  162. #define FORCE_HALF 0x0020
  163. #define FORCE_FULL 0x0030
  164. /* Information that need to be kept for each board. */
  165. struct net_local {
  166. struct net_device_stats stats;
  167. int chip_type; /* one of: CS8900, CS8920, CS8920M */
  168. char chip_revision; /* revision letter of the chip ('A'...) */
  169. int send_cmd; /* the proper send command: TX_NOW, TX_AFTER_381, or TX_AFTER_ALL */
  170. int auto_neg_cnf; /* auto-negotiation word from EEPROM */
  171. int adapter_cnf; /* adapter configuration from EEPROM */
  172. int isa_config; /* ISA configuration from EEPROM */
  173. int irq_map; /* IRQ map from EEPROM */
  174. int rx_mode; /* what mode are we in? 0, RX_MULTCAST_ACCEPT, or RX_ALL_ACCEPT */
  175. int curr_rx_cfg; /* a copy of PP_RxCFG */
  176. int linectl; /* either 0 or LOW_RX_SQUELCH, depending on configuration. */
  177. int send_underrun; /* keep track of how many underruns in a row we get */
  178. int force; /* force various values; see FORCE* above. */
  179. spinlock_t lock;
  180. #if ALLOW_DMA
  181. int use_dma; /* Flag: we're using dma */
  182. int dma; /* DMA channel */
  183. int dmasize; /* 16 or 64 */
  184. unsigned char *dma_buff; /* points to the beginning of the buffer */
  185. unsigned char *end_dma_buff; /* points to the end of the buffer */
  186. unsigned char *rx_dma_ptr; /* points to the next packet */
  187. #endif
  188. };
  189. /* Index to functions, as function prototypes. */
  190. static int cs89x0_probe1(struct net_device *dev, int ioaddr, int modular);
  191. static int net_open(struct net_device *dev);
  192. static int net_send_packet(struct sk_buff *skb, struct net_device *dev);
  193. static irqreturn_t net_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  194. static void set_multicast_list(struct net_device *dev);
  195. static void net_timeout(struct net_device *dev);
  196. static void net_rx(struct net_device *dev);
  197. static int net_close(struct net_device *dev);
  198. static struct net_device_stats *net_get_stats(struct net_device *dev);
  199. static void reset_chip(struct net_device *dev);
  200. static int get_eeprom_data(struct net_device *dev, int off, int len, int *buffer);
  201. static int get_eeprom_cksum(int off, int len, int *buffer);
  202. static int set_mac_address(struct net_device *dev, void *addr);
  203. static void count_rx_errors(int status, struct net_local *lp);
  204. #if ALLOW_DMA
  205. static void get_dma_channel(struct net_device *dev);
  206. static void release_dma_buff(struct net_local *lp);
  207. #endif
  208. /* Example routines you must write ;->. */
  209. #define tx_done(dev) 1
  210. /*
  211. * Permit 'cs89x0_dma=N' in the kernel boot environment
  212. */
  213. #if !defined(MODULE) && (ALLOW_DMA != 0)
  214. static int g_cs89x0_dma;
  215. static int __init dma_fn(char *str)
  216. {
  217. g_cs89x0_dma = simple_strtol(str,NULL,0);
  218. return 1;
  219. }
  220. __setup("cs89x0_dma=", dma_fn);
  221. #endif /* !defined(MODULE) && (ALLOW_DMA != 0) */
  222. #ifndef MODULE
  223. static int g_cs89x0_media__force;
  224. static int __init media_fn(char *str)
  225. {
  226. if (!strcmp(str, "rj45")) g_cs89x0_media__force = FORCE_RJ45;
  227. else if (!strcmp(str, "aui")) g_cs89x0_media__force = FORCE_AUI;
  228. else if (!strcmp(str, "bnc")) g_cs89x0_media__force = FORCE_BNC;
  229. return 1;
  230. }
  231. __setup("cs89x0_media=", media_fn);
  232. /* Check for a network adaptor of this type, and return '0' iff one exists.
  233. If dev->base_addr == 0, probe all likely locations.
  234. If dev->base_addr == 1, always return failure.
  235. If dev->base_addr == 2, allocate space for the device and return success
  236. (detachable devices only).
  237. Return 0 on success.
  238. */
  239. struct net_device * __init cs89x0_probe(int unit)
  240. {
  241. struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
  242. unsigned *port;
  243. int err = 0;
  244. int irq;
  245. int io;
  246. if (!dev)
  247. return ERR_PTR(-ENODEV);
  248. sprintf(dev->name, "eth%d", unit);
  249. netdev_boot_setup_check(dev);
  250. io = dev->base_addr;
  251. irq = dev->irq;
  252. if (net_debug)
  253. printk("cs89x0:cs89x0_probe(0x%x)\n", io);
  254. if (io > 0x1ff) { /* Check a single specified location. */
  255. err = cs89x0_probe1(dev, io, 0);
  256. } else if (io != 0) { /* Don't probe at all. */
  257. err = -ENXIO;
  258. } else {
  259. for (port = netcard_portlist; *port; port++) {
  260. if (cs89x0_probe1(dev, *port, 0) == 0)
  261. break;
  262. dev->irq = irq;
  263. }
  264. if (!*port)
  265. err = -ENODEV;
  266. }
  267. if (err)
  268. goto out;
  269. err = register_netdev(dev);
  270. if (err)
  271. goto out1;
  272. return dev;
  273. out1:
  274. outw(PP_ChipID, dev->base_addr + ADD_PORT);
  275. release_region(dev->base_addr, NETCARD_IO_EXTENT);
  276. out:
  277. free_netdev(dev);
  278. printk(KERN_WARNING "cs89x0: no cs8900 or cs8920 detected. Be sure to disable PnP with SETUP\n");
  279. return ERR_PTR(err);
  280. }
  281. #endif
  282. static int
  283. readreg(struct net_device *dev, int portno)
  284. {
  285. outw(portno, dev->base_addr + ADD_PORT);
  286. return inw(dev->base_addr + DATA_PORT);
  287. }
  288. static void
  289. writereg(struct net_device *dev, int portno, int value)
  290. {
  291. outw(portno, dev->base_addr + ADD_PORT);
  292. outw(value, dev->base_addr + DATA_PORT);
  293. }
  294. static int
  295. readword(struct net_device *dev, int portno)
  296. {
  297. return inw(dev->base_addr + portno);
  298. }
  299. static void
  300. writeword(struct net_device *dev, int portno, int value)
  301. {
  302. outw(value, dev->base_addr + portno);
  303. }
  304. static int __init
  305. wait_eeprom_ready(struct net_device *dev)
  306. {
  307. int timeout = jiffies;
  308. /* check to see if the EEPROM is ready, a timeout is used -
  309. just in case EEPROM is ready when SI_BUSY in the
  310. PP_SelfST is clear */
  311. while(readreg(dev, PP_SelfST) & SI_BUSY)
  312. if (jiffies - timeout >= 40)
  313. return -1;
  314. return 0;
  315. }
  316. static int __init
  317. get_eeprom_data(struct net_device *dev, int off, int len, int *buffer)
  318. {
  319. int i;
  320. if (net_debug > 3) printk("EEPROM data from %x for %x:\n",off,len);
  321. for (i = 0; i < len; i++) {
  322. if (wait_eeprom_ready(dev) < 0) return -1;
  323. /* Now send the EEPROM read command and EEPROM location to read */
  324. writereg(dev, PP_EECMD, (off + i) | EEPROM_READ_CMD);
  325. if (wait_eeprom_ready(dev) < 0) return -1;
  326. buffer[i] = readreg(dev, PP_EEData);
  327. if (net_debug > 3) printk("%04x ", buffer[i]);
  328. }
  329. if (net_debug > 3) printk("\n");
  330. return 0;
  331. }
  332. static int __init
  333. get_eeprom_cksum(int off, int len, int *buffer)
  334. {
  335. int i, cksum;
  336. cksum = 0;
  337. for (i = 0; i < len; i++)
  338. cksum += buffer[i];
  339. cksum &= 0xffff;
  340. if (cksum == 0)
  341. return 0;
  342. return -1;
  343. }
  344. /* This is the real probe routine. Linux has a history of friendly device
  345. probes on the ISA bus. A good device probes avoids doing writes, and
  346. verifies that the correct device exists and functions.
  347. Return 0 on success.
  348. */
  349. static int __init
  350. cs89x0_probe1(struct net_device *dev, int ioaddr, int modular)
  351. {
  352. struct net_local *lp = netdev_priv(dev);
  353. static unsigned version_printed;
  354. int i;
  355. unsigned rev_type = 0;
  356. int eeprom_buff[CHKSUM_LEN];
  357. int retval;
  358. SET_MODULE_OWNER(dev);
  359. /* Initialize the device structure. */
  360. if (!modular) {
  361. memset(lp, 0, sizeof(*lp));
  362. spin_lock_init(&lp->lock);
  363. #ifndef MODULE
  364. #if ALLOW_DMA
  365. if (g_cs89x0_dma) {
  366. lp->use_dma = 1;
  367. lp->dma = g_cs89x0_dma;
  368. lp->dmasize = 16; /* Could make this an option... */
  369. }
  370. #endif
  371. lp->force = g_cs89x0_media__force;
  372. #endif
  373. }
  374. /* Grab the region so we can find another board if autoIRQ fails. */
  375. /* WTF is going on here? */
  376. if (!request_region(ioaddr & ~3, NETCARD_IO_EXTENT, DRV_NAME)) {
  377. printk(KERN_ERR "%s: request_region(0x%x, 0x%x) failed\n",
  378. DRV_NAME, ioaddr, NETCARD_IO_EXTENT);
  379. retval = -EBUSY;
  380. goto out1;
  381. }
  382. #ifdef CONFIG_SH_HICOSH4
  383. /* truely reset the chip */
  384. outw(0x0114, ioaddr + ADD_PORT);
  385. outw(0x0040, ioaddr + DATA_PORT);
  386. #endif
  387. /* if they give us an odd I/O address, then do ONE write to
  388. the address port, to get it back to address zero, where we
  389. expect to find the EISA signature word. An IO with a base of 0x3
  390. will skip the test for the ADD_PORT. */
  391. if (ioaddr & 1) {
  392. if (net_debug > 1)
  393. printk(KERN_INFO "%s: odd ioaddr 0x%x\n", dev->name, ioaddr);
  394. if ((ioaddr & 2) != 2)
  395. if ((inw((ioaddr & ~3)+ ADD_PORT) & ADD_MASK) != ADD_SIG) {
  396. printk(KERN_ERR "%s: bad signature 0x%x\n",
  397. dev->name, inw((ioaddr & ~3)+ ADD_PORT));
  398. retval = -ENODEV;
  399. goto out2;
  400. }
  401. }
  402. printk("PP_addr=0x%x\n", inw(ioaddr + ADD_PORT));
  403. ioaddr &= ~3;
  404. outw(PP_ChipID, ioaddr + ADD_PORT);
  405. if (inw(ioaddr + DATA_PORT) != CHIP_EISA_ID_SIG) {
  406. printk(KERN_ERR "%s: incorrect signature 0x%x\n",
  407. dev->name, inw(ioaddr + DATA_PORT));
  408. retval = -ENODEV;
  409. goto out2;
  410. }
  411. /* Fill in the 'dev' fields. */
  412. dev->base_addr = ioaddr;
  413. /* get the chip type */
  414. rev_type = readreg(dev, PRODUCT_ID_ADD);
  415. lp->chip_type = rev_type &~ REVISON_BITS;
  416. lp->chip_revision = ((rev_type & REVISON_BITS) >> 8) + 'A';
  417. /* Check the chip type and revision in order to set the correct send command
  418. CS8920 revision C and CS8900 revision F can use the faster send. */
  419. lp->send_cmd = TX_AFTER_381;
  420. if (lp->chip_type == CS8900 && lp->chip_revision >= 'F')
  421. lp->send_cmd = TX_NOW;
  422. if (lp->chip_type != CS8900 && lp->chip_revision >= 'C')
  423. lp->send_cmd = TX_NOW;
  424. if (net_debug && version_printed++ == 0)
  425. printk(version);
  426. printk(KERN_INFO "%s: cs89%c0%s rev %c found at %#3lx ",
  427. dev->name,
  428. lp->chip_type==CS8900?'0':'2',
  429. lp->chip_type==CS8920M?"M":"",
  430. lp->chip_revision,
  431. dev->base_addr);
  432. reset_chip(dev);
  433. /* Here we read the current configuration of the chip. If there
  434. is no Extended EEPROM then the idea is to not disturb the chip
  435. configuration, it should have been correctly setup by automatic
  436. EEPROM read on reset. So, if the chip says it read the EEPROM
  437. the driver will always do *something* instead of complain that
  438. adapter_cnf is 0. */
  439. #ifdef CONFIG_SH_HICOSH4
  440. if (1) {
  441. /* For the HiCO.SH4 board, things are different: we don't
  442. have EEPROM, but there is some data in flash, so we go
  443. get it there directly (MAC). */
  444. __u16 *confd;
  445. short cnt;
  446. if (((* (volatile __u32 *) 0xa0013ff0) & 0x00ffffff)
  447. == 0x006c3000) {
  448. confd = (__u16*) 0xa0013fc0;
  449. } else {
  450. confd = (__u16*) 0xa001ffc0;
  451. }
  452. cnt = (*confd++ & 0x00ff) >> 1;
  453. while (--cnt > 0) {
  454. __u16 j = *confd++;
  455. switch (j & 0x0fff) {
  456. case PP_IA:
  457. for (i = 0; i < ETH_ALEN/2; i++) {
  458. dev->dev_addr[i*2] = confd[i] & 0xFF;
  459. dev->dev_addr[i*2+1] = confd[i] >> 8;
  460. }
  461. break;
  462. }
  463. j = (j >> 12) + 1;
  464. confd += j;
  465. cnt -= j;
  466. }
  467. } else
  468. #endif
  469. if ((readreg(dev, PP_SelfST) & (EEPROM_OK | EEPROM_PRESENT)) ==
  470. (EEPROM_OK|EEPROM_PRESENT)) {
  471. /* Load the MAC. */
  472. for (i=0; i < ETH_ALEN/2; i++) {
  473. unsigned int Addr;
  474. Addr = readreg(dev, PP_IA+i*2);
  475. dev->dev_addr[i*2] = Addr & 0xFF;
  476. dev->dev_addr[i*2+1] = Addr >> 8;
  477. }
  478. /* Load the Adapter Configuration.
  479. Note: Barring any more specific information from some
  480. other source (ie EEPROM+Schematics), we would not know
  481. how to operate a 10Base2 interface on the AUI port.
  482. However, since we do read the status of HCB1 and use
  483. settings that always result in calls to control_dc_dc(dev,0)
  484. a BNC interface should work if the enable pin
  485. (dc/dc converter) is on HCB1. It will be called AUI
  486. however. */
  487. lp->adapter_cnf = 0;
  488. i = readreg(dev, PP_LineCTL);
  489. /* Preserve the setting of the HCB1 pin. */
  490. if ((i & (HCB1 | HCB1_ENBL)) == (HCB1 | HCB1_ENBL))
  491. lp->adapter_cnf |= A_CNF_DC_DC_POLARITY;
  492. /* Save the sqelch bit */
  493. if ((i & LOW_RX_SQUELCH) == LOW_RX_SQUELCH)
  494. lp->adapter_cnf |= A_CNF_EXTND_10B_2 | A_CNF_LOW_RX_SQUELCH;
  495. /* Check if the card is in 10Base-t only mode */
  496. if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == 0)
  497. lp->adapter_cnf |= A_CNF_10B_T | A_CNF_MEDIA_10B_T;
  498. /* Check if the card is in AUI only mode */
  499. if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == AUI_ONLY)
  500. lp->adapter_cnf |= A_CNF_AUI | A_CNF_MEDIA_AUI;
  501. /* Check if the card is in Auto mode. */
  502. if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == AUTO_AUI_10BASET)
  503. lp->adapter_cnf |= A_CNF_AUI | A_CNF_10B_T |
  504. A_CNF_MEDIA_AUI | A_CNF_MEDIA_10B_T | A_CNF_MEDIA_AUTO;
  505. if (net_debug > 1)
  506. printk(KERN_INFO "%s: PP_LineCTL=0x%x, adapter_cnf=0x%x\n",
  507. dev->name, i, lp->adapter_cnf);
  508. /* IRQ. Other chips already probe, see below. */
  509. if (lp->chip_type == CS8900)
  510. lp->isa_config = readreg(dev, PP_CS8900_ISAINT) & INT_NO_MASK;
  511. printk( "[Cirrus EEPROM] ");
  512. }
  513. printk("\n");
  514. /* First check to see if an EEPROM is attached. */
  515. #ifdef CONFIG_SH_HICOSH4 /* no EEPROM on HiCO, don't hazzle with it here */
  516. if (1) {
  517. printk(KERN_NOTICE "cs89x0: No EEPROM on HiCO.SH4\n");
  518. } else
  519. #endif
  520. if ((readreg(dev, PP_SelfST) & EEPROM_PRESENT) == 0)
  521. printk(KERN_WARNING "cs89x0: No EEPROM, relying on command line....\n");
  522. else if (get_eeprom_data(dev, START_EEPROM_DATA,CHKSUM_LEN,eeprom_buff) < 0) {
  523. printk(KERN_WARNING "\ncs89x0: EEPROM read failed, relying on command line.\n");
  524. } else if (get_eeprom_cksum(START_EEPROM_DATA,CHKSUM_LEN,eeprom_buff) < 0) {
  525. /* Check if the chip was able to read its own configuration starting
  526. at 0 in the EEPROM*/
  527. if ((readreg(dev, PP_SelfST) & (EEPROM_OK | EEPROM_PRESENT)) !=
  528. (EEPROM_OK|EEPROM_PRESENT))
  529. printk(KERN_WARNING "cs89x0: Extended EEPROM checksum bad and no Cirrus EEPROM, relying on command line\n");
  530. } else {
  531. /* This reads an extended EEPROM that is not documented
  532. in the CS8900 datasheet. */
  533. /* get transmission control word but keep the autonegotiation bits */
  534. if (!lp->auto_neg_cnf) lp->auto_neg_cnf = eeprom_buff[AUTO_NEG_CNF_OFFSET/2];
  535. /* Store adapter configuration */
  536. if (!lp->adapter_cnf) lp->adapter_cnf = eeprom_buff[ADAPTER_CNF_OFFSET/2];
  537. /* Store ISA configuration */
  538. lp->isa_config = eeprom_buff[ISA_CNF_OFFSET/2];
  539. dev->mem_start = eeprom_buff[PACKET_PAGE_OFFSET/2] << 8;
  540. /* eeprom_buff has 32-bit ints, so we can't just memcpy it */
  541. /* store the initial memory base address */
  542. for (i = 0; i < ETH_ALEN/2; i++) {
  543. dev->dev_addr[i*2] = eeprom_buff[i];
  544. dev->dev_addr[i*2+1] = eeprom_buff[i] >> 8;
  545. }
  546. if (net_debug > 1)
  547. printk(KERN_DEBUG "%s: new adapter_cnf: 0x%x\n",
  548. dev->name, lp->adapter_cnf);
  549. }
  550. /* allow them to force multiple transceivers. If they force multiple, autosense */
  551. {
  552. int count = 0;
  553. if (lp->force & FORCE_RJ45) {lp->adapter_cnf |= A_CNF_10B_T; count++; }
  554. if (lp->force & FORCE_AUI) {lp->adapter_cnf |= A_CNF_AUI; count++; }
  555. if (lp->force & FORCE_BNC) {lp->adapter_cnf |= A_CNF_10B_2; count++; }
  556. if (count > 1) {lp->adapter_cnf |= A_CNF_MEDIA_AUTO; }
  557. else if (lp->force & FORCE_RJ45){lp->adapter_cnf |= A_CNF_MEDIA_10B_T; }
  558. else if (lp->force & FORCE_AUI) {lp->adapter_cnf |= A_CNF_MEDIA_AUI; }
  559. else if (lp->force & FORCE_BNC) {lp->adapter_cnf |= A_CNF_MEDIA_10B_2; }
  560. }
  561. if (net_debug > 1)
  562. printk(KERN_DEBUG "%s: after force 0x%x, adapter_cnf=0x%x\n",
  563. dev->name, lp->force, lp->adapter_cnf);
  564. /* FIXME: We don't let you set dc-dc polarity or low RX squelch from the command line: add it here */
  565. /* FIXME: We don't let you set the IMM bit from the command line: add it to lp->auto_neg_cnf here */
  566. /* FIXME: we don't set the Ethernet address on the command line. Use
  567. ifconfig IFACE hw ether AABBCCDDEEFF */
  568. printk(KERN_INFO "cs89x0 media %s%s%s",
  569. (lp->adapter_cnf & A_CNF_10B_T)?"RJ-45,":"",
  570. (lp->adapter_cnf & A_CNF_AUI)?"AUI,":"",
  571. (lp->adapter_cnf & A_CNF_10B_2)?"BNC,":"");
  572. lp->irq_map = 0xffff;
  573. /* If this is a CS8900 then no pnp soft */
  574. if (lp->chip_type != CS8900 &&
  575. /* Check if the ISA IRQ has been set */
  576. (i = readreg(dev, PP_CS8920_ISAINT) & 0xff,
  577. (i != 0 && i < CS8920_NO_INTS))) {
  578. if (!dev->irq)
  579. dev->irq = i;
  580. } else {
  581. i = lp->isa_config & INT_NO_MASK;
  582. if (lp->chip_type == CS8900) {
  583. #ifdef CONFIG_ARCH_IXDP2X01
  584. i = cs8900_irq_map[0];
  585. #else
  586. /* Translate the IRQ using the IRQ mapping table. */
  587. if (i >= sizeof(cs8900_irq_map)/sizeof(cs8900_irq_map[0]))
  588. printk("\ncs89x0: invalid ISA interrupt number %d\n", i);
  589. else
  590. i = cs8900_irq_map[i];
  591. lp->irq_map = CS8900_IRQ_MAP; /* fixed IRQ map for CS8900 */
  592. } else {
  593. int irq_map_buff[IRQ_MAP_LEN/2];
  594. if (get_eeprom_data(dev, IRQ_MAP_EEPROM_DATA,
  595. IRQ_MAP_LEN/2,
  596. irq_map_buff) >= 0) {
  597. if ((irq_map_buff[0] & 0xff) == PNP_IRQ_FRMT)
  598. lp->irq_map = (irq_map_buff[0]>>8) | (irq_map_buff[1] << 8);
  599. }
  600. #endif
  601. }
  602. if (!dev->irq)
  603. dev->irq = i;
  604. }
  605. printk(" IRQ %d", dev->irq);
  606. #if ALLOW_DMA
  607. if (lp->use_dma) {
  608. get_dma_channel(dev);
  609. printk(", DMA %d", dev->dma);
  610. }
  611. else
  612. #endif
  613. {
  614. printk(", programmed I/O");
  615. }
  616. /* print the ethernet address. */
  617. printk(", MAC");
  618. for (i = 0; i < ETH_ALEN; i++)
  619. {
  620. printk("%c%02x", i ? ':' : ' ', dev->dev_addr[i]);
  621. }
  622. dev->open = net_open;
  623. dev->stop = net_close;
  624. dev->tx_timeout = net_timeout;
  625. dev->watchdog_timeo = HZ;
  626. dev->hard_start_xmit = net_send_packet;
  627. dev->get_stats = net_get_stats;
  628. dev->set_multicast_list = set_multicast_list;
  629. dev->set_mac_address = set_mac_address;
  630. printk("\n");
  631. if (net_debug)
  632. printk("cs89x0_probe1() successful\n");
  633. return 0;
  634. out2:
  635. release_region(ioaddr & ~3, NETCARD_IO_EXTENT);
  636. out1:
  637. return retval;
  638. }
  639. /*********************************
  640. * This page contains DMA routines
  641. **********************************/
  642. #if ALLOW_DMA
  643. #define dma_page_eq(ptr1, ptr2) ((long)(ptr1)>>17 == (long)(ptr2)>>17)
  644. static void
  645. get_dma_channel(struct net_device *dev)
  646. {
  647. struct net_local *lp = netdev_priv(dev);
  648. if (lp->dma) {
  649. dev->dma = lp->dma;
  650. lp->isa_config |= ISA_RxDMA;
  651. } else {
  652. if ((lp->isa_config & ANY_ISA_DMA) == 0)
  653. return;
  654. dev->dma = lp->isa_config & DMA_NO_MASK;
  655. if (lp->chip_type == CS8900)
  656. dev->dma += 5;
  657. if (dev->dma < 5 || dev->dma > 7) {
  658. lp->isa_config &= ~ANY_ISA_DMA;
  659. return;
  660. }
  661. }
  662. return;
  663. }
  664. static void
  665. write_dma(struct net_device *dev, int chip_type, int dma)
  666. {
  667. struct net_local *lp = netdev_priv(dev);
  668. if ((lp->isa_config & ANY_ISA_DMA) == 0)
  669. return;
  670. if (chip_type == CS8900) {
  671. writereg(dev, PP_CS8900_ISADMA, dma-5);
  672. } else {
  673. writereg(dev, PP_CS8920_ISADMA, dma);
  674. }
  675. }
  676. static void
  677. set_dma_cfg(struct net_device *dev)
  678. {
  679. struct net_local *lp = netdev_priv(dev);
  680. if (lp->use_dma) {
  681. if ((lp->isa_config & ANY_ISA_DMA) == 0) {
  682. if (net_debug > 3)
  683. printk("set_dma_cfg(): no DMA\n");
  684. return;
  685. }
  686. if (lp->isa_config & ISA_RxDMA) {
  687. lp->curr_rx_cfg |= RX_DMA_ONLY;
  688. if (net_debug > 3)
  689. printk("set_dma_cfg(): RX_DMA_ONLY\n");
  690. } else {
  691. lp->curr_rx_cfg |= AUTO_RX_DMA; /* not that we support it... */
  692. if (net_debug > 3)
  693. printk("set_dma_cfg(): AUTO_RX_DMA\n");
  694. }
  695. }
  696. }
  697. static int
  698. dma_bufcfg(struct net_device *dev)
  699. {
  700. struct net_local *lp = netdev_priv(dev);
  701. if (lp->use_dma)
  702. return (lp->isa_config & ANY_ISA_DMA)? RX_DMA_ENBL : 0;
  703. else
  704. return 0;
  705. }
  706. static int
  707. dma_busctl(struct net_device *dev)
  708. {
  709. int retval = 0;
  710. struct net_local *lp = netdev_priv(dev);
  711. if (lp->use_dma) {
  712. if (lp->isa_config & ANY_ISA_DMA)
  713. retval |= RESET_RX_DMA; /* Reset the DMA pointer */
  714. if (lp->isa_config & DMA_BURST)
  715. retval |= DMA_BURST_MODE; /* Does ISA config specify DMA burst ? */
  716. if (lp->dmasize == 64)
  717. retval |= RX_DMA_SIZE_64K; /* did they ask for 64K? */
  718. retval |= MEMORY_ON; /* we need memory enabled to use DMA. */
  719. }
  720. return retval;
  721. }
  722. static void
  723. dma_rx(struct net_device *dev)
  724. {
  725. struct net_local *lp = netdev_priv(dev);
  726. struct sk_buff *skb;
  727. int status, length;
  728. unsigned char *bp = lp->rx_dma_ptr;
  729. status = bp[0] + (bp[1]<<8);
  730. length = bp[2] + (bp[3]<<8);
  731. bp += 4;
  732. if (net_debug > 5) {
  733. printk( "%s: receiving DMA packet at %lx, status %x, length %x\n",
  734. dev->name, (unsigned long)bp, status, length);
  735. }
  736. if ((status & RX_OK) == 0) {
  737. count_rx_errors(status, lp);
  738. goto skip_this_frame;
  739. }
  740. /* Malloc up new buffer. */
  741. skb = dev_alloc_skb(length + 2);
  742. if (skb == NULL) {
  743. if (net_debug) /* I don't think we want to do this to a stressed system */
  744. printk("%s: Memory squeeze, dropping packet.\n", dev->name);
  745. lp->stats.rx_dropped++;
  746. /* AKPM: advance bp to the next frame */
  747. skip_this_frame:
  748. bp += (length + 3) & ~3;
  749. if (bp >= lp->end_dma_buff) bp -= lp->dmasize*1024;
  750. lp->rx_dma_ptr = bp;
  751. return;
  752. }
  753. skb_reserve(skb, 2); /* longword align L3 header */
  754. skb->dev = dev;
  755. if (bp + length > lp->end_dma_buff) {
  756. int semi_cnt = lp->end_dma_buff - bp;
  757. memcpy(skb_put(skb,semi_cnt), bp, semi_cnt);
  758. memcpy(skb_put(skb,length - semi_cnt), lp->dma_buff,
  759. length - semi_cnt);
  760. } else {
  761. memcpy(skb_put(skb,length), bp, length);
  762. }
  763. bp += (length + 3) & ~3;
  764. if (bp >= lp->end_dma_buff) bp -= lp->dmasize*1024;
  765. lp->rx_dma_ptr = bp;
  766. if (net_debug > 3) {
  767. printk( "%s: received %d byte DMA packet of type %x\n",
  768. dev->name, length,
  769. (skb->data[ETH_ALEN+ETH_ALEN] << 8) | skb->data[ETH_ALEN+ETH_ALEN+1]);
  770. }
  771. skb->protocol=eth_type_trans(skb,dev);
  772. netif_rx(skb);
  773. dev->last_rx = jiffies;
  774. lp->stats.rx_packets++;
  775. lp->stats.rx_bytes += length;
  776. }
  777. #endif /* ALLOW_DMA */
  778. void __init reset_chip(struct net_device *dev)
  779. {
  780. #ifndef CONFIG_ARCH_IXDP2X01
  781. struct net_local *lp = netdev_priv(dev);
  782. int ioaddr = dev->base_addr;
  783. #endif
  784. int reset_start_time;
  785. writereg(dev, PP_SelfCTL, readreg(dev, PP_SelfCTL) | POWER_ON_RESET);
  786. /* wait 30 ms */
  787. msleep(30);
  788. #ifndef CONFIG_ARCH_IXDP2X01
  789. if (lp->chip_type != CS8900) {
  790. /* Hardware problem requires PNP registers to be reconfigured after a reset */
  791. outw(PP_CS8920_ISAINT, ioaddr + ADD_PORT);
  792. outb(dev->irq, ioaddr + DATA_PORT);
  793. outb(0, ioaddr + DATA_PORT + 1);
  794. outw(PP_CS8920_ISAMemB, ioaddr + ADD_PORT);
  795. outb((dev->mem_start >> 16) & 0xff, ioaddr + DATA_PORT);
  796. outb((dev->mem_start >> 8) & 0xff, ioaddr + DATA_PORT + 1);
  797. }
  798. #endif /* IXDP2x01 */
  799. /* Wait until the chip is reset */
  800. reset_start_time = jiffies;
  801. while( (readreg(dev, PP_SelfST) & INIT_DONE) == 0 && jiffies - reset_start_time < 2)
  802. ;
  803. }
  804. static void
  805. control_dc_dc(struct net_device *dev, int on_not_off)
  806. {
  807. struct net_local *lp = netdev_priv(dev);
  808. unsigned int selfcontrol;
  809. int timenow = jiffies;
  810. /* control the DC to DC convertor in the SelfControl register.
  811. Note: This is hooked up to a general purpose pin, might not
  812. always be a DC to DC convertor. */
  813. selfcontrol = HCB1_ENBL; /* Enable the HCB1 bit as an output */
  814. if (((lp->adapter_cnf & A_CNF_DC_DC_POLARITY) != 0) ^ on_not_off)
  815. selfcontrol |= HCB1;
  816. else
  817. selfcontrol &= ~HCB1;
  818. writereg(dev, PP_SelfCTL, selfcontrol);
  819. /* Wait for the DC/DC converter to power up - 500ms */
  820. while (jiffies - timenow < HZ)
  821. ;
  822. }
  823. #define DETECTED_NONE 0
  824. #define DETECTED_RJ45H 1
  825. #define DETECTED_RJ45F 2
  826. #define DETECTED_AUI 3
  827. #define DETECTED_BNC 4
  828. static int
  829. detect_tp(struct net_device *dev)
  830. {
  831. struct net_local *lp = netdev_priv(dev);
  832. int timenow = jiffies;
  833. int fdx;
  834. if (net_debug > 1) printk("%s: Attempting TP\n", dev->name);
  835. /* If connected to another full duplex capable 10-Base-T card the link pulses
  836. seem to be lost when the auto detect bit in the LineCTL is set.
  837. To overcome this the auto detect bit will be cleared whilst testing the
  838. 10-Base-T interface. This would not be necessary for the sparrow chip but
  839. is simpler to do it anyway. */
  840. writereg(dev, PP_LineCTL, lp->linectl &~ AUI_ONLY);
  841. control_dc_dc(dev, 0);
  842. /* Delay for the hardware to work out if the TP cable is present - 150ms */
  843. for (timenow = jiffies; jiffies - timenow < 15; )
  844. ;
  845. if ((readreg(dev, PP_LineST) & LINK_OK) == 0)
  846. return DETECTED_NONE;
  847. if (lp->chip_type == CS8900) {
  848. switch (lp->force & 0xf0) {
  849. #if 0
  850. case FORCE_AUTO:
  851. printk("%s: cs8900 doesn't autonegotiate\n",dev->name);
  852. return DETECTED_NONE;
  853. #endif
  854. /* CS8900 doesn't support AUTO, change to HALF*/
  855. case FORCE_AUTO:
  856. lp->force &= ~FORCE_AUTO;
  857. lp->force |= FORCE_HALF;
  858. break;
  859. case FORCE_HALF:
  860. break;
  861. case FORCE_FULL:
  862. writereg(dev, PP_TestCTL, readreg(dev, PP_TestCTL) | FDX_8900);
  863. break;
  864. }
  865. fdx = readreg(dev, PP_TestCTL) & FDX_8900;
  866. } else {
  867. switch (lp->force & 0xf0) {
  868. case FORCE_AUTO:
  869. lp->auto_neg_cnf = AUTO_NEG_ENABLE;
  870. break;
  871. case FORCE_HALF:
  872. lp->auto_neg_cnf = 0;
  873. break;
  874. case FORCE_FULL:
  875. lp->auto_neg_cnf = RE_NEG_NOW | ALLOW_FDX;
  876. break;
  877. }
  878. writereg(dev, PP_AutoNegCTL, lp->auto_neg_cnf & AUTO_NEG_MASK);
  879. if ((lp->auto_neg_cnf & AUTO_NEG_BITS) == AUTO_NEG_ENABLE) {
  880. printk(KERN_INFO "%s: negotiating duplex...\n",dev->name);
  881. while (readreg(dev, PP_AutoNegST) & AUTO_NEG_BUSY) {
  882. if (jiffies - timenow > 4000) {
  883. printk(KERN_ERR "**** Full / half duplex auto-negotiation timed out ****\n");
  884. break;
  885. }
  886. }
  887. }
  888. fdx = readreg(dev, PP_AutoNegST) & FDX_ACTIVE;
  889. }
  890. if (fdx)
  891. return DETECTED_RJ45F;
  892. else
  893. return DETECTED_RJ45H;
  894. }
  895. /* send a test packet - return true if carrier bits are ok */
  896. static int
  897. send_test_pkt(struct net_device *dev)
  898. {
  899. char test_packet[] = { 0,0,0,0,0,0, 0,0,0,0,0,0,
  900. 0, 46, /* A 46 in network order */
  901. 0, 0, /* DSAP=0 & SSAP=0 fields */
  902. 0xf3, 0 /* Control (Test Req + P bit set) */ };
  903. long timenow = jiffies;
  904. writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_TX_ON);
  905. memcpy(test_packet, dev->dev_addr, ETH_ALEN);
  906. memcpy(test_packet+ETH_ALEN, dev->dev_addr, ETH_ALEN);
  907. writeword(dev, TX_CMD_PORT, TX_AFTER_ALL);
  908. writeword(dev, TX_LEN_PORT, ETH_ZLEN);
  909. /* Test to see if the chip has allocated memory for the packet */
  910. while (jiffies - timenow < 5)
  911. if (readreg(dev, PP_BusST) & READY_FOR_TX_NOW)
  912. break;
  913. if (jiffies - timenow >= 5)
  914. return 0; /* this shouldn't happen */
  915. /* Write the contents of the packet */
  916. outsw(dev->base_addr + TX_FRAME_PORT,test_packet,(ETH_ZLEN+1) >>1);
  917. if (net_debug > 1) printk("Sending test packet ");
  918. /* wait a couple of jiffies for packet to be received */
  919. for (timenow = jiffies; jiffies - timenow < 3; )
  920. ;
  921. if ((readreg(dev, PP_TxEvent) & TX_SEND_OK_BITS) == TX_OK) {
  922. if (net_debug > 1) printk("succeeded\n");
  923. return 1;
  924. }
  925. if (net_debug > 1) printk("failed\n");
  926. return 0;
  927. }
  928. static int
  929. detect_aui(struct net_device *dev)
  930. {
  931. struct net_local *lp = netdev_priv(dev);
  932. if (net_debug > 1) printk("%s: Attempting AUI\n", dev->name);
  933. control_dc_dc(dev, 0);
  934. writereg(dev, PP_LineCTL, (lp->linectl &~ AUTO_AUI_10BASET) | AUI_ONLY);
  935. if (send_test_pkt(dev))
  936. return DETECTED_AUI;
  937. else
  938. return DETECTED_NONE;
  939. }
  940. static int
  941. detect_bnc(struct net_device *dev)
  942. {
  943. struct net_local *lp = netdev_priv(dev);
  944. if (net_debug > 1) printk("%s: Attempting BNC\n", dev->name);
  945. control_dc_dc(dev, 1);
  946. writereg(dev, PP_LineCTL, (lp->linectl &~ AUTO_AUI_10BASET) | AUI_ONLY);
  947. if (send_test_pkt(dev))
  948. return DETECTED_BNC;
  949. else
  950. return DETECTED_NONE;
  951. }
  952. static void
  953. write_irq(struct net_device *dev, int chip_type, int irq)
  954. {
  955. int i;
  956. if (chip_type == CS8900) {
  957. /* Search the mapping table for the corresponding IRQ pin. */
  958. for (i = 0; i != sizeof(cs8900_irq_map)/sizeof(cs8900_irq_map[0]); i++)
  959. if (cs8900_irq_map[i] == irq)
  960. break;
  961. /* Not found */
  962. if (i == sizeof(cs8900_irq_map)/sizeof(cs8900_irq_map[0]))
  963. i = 3;
  964. writereg(dev, PP_CS8900_ISAINT, i);
  965. } else {
  966. writereg(dev, PP_CS8920_ISAINT, irq);
  967. }
  968. }
  969. /* Open/initialize the board. This is called (in the current kernel)
  970. sometime after booting when the 'ifconfig' program is run.
  971. This routine should set everything up anew at each open, even
  972. registers that "should" only need to be set once at boot, so that
  973. there is non-reboot way to recover if something goes wrong.
  974. */
  975. /* AKPM: do we need to do any locking here? */
  976. static int
  977. net_open(struct net_device *dev)
  978. {
  979. struct net_local *lp = netdev_priv(dev);
  980. int result = 0;
  981. int i;
  982. int ret;
  983. #ifndef CONFIG_SH_HICOSH4 /* uses irq#1, so this won't work */
  984. if (dev->irq < 2) {
  985. /* Allow interrupts to be generated by the chip */
  986. /* Cirrus' release had this: */
  987. #if 0
  988. writereg(dev, PP_BusCTL, readreg(dev, PP_BusCTL)|ENABLE_IRQ );
  989. #endif
  990. /* And 2.3.47 had this: */
  991. writereg(dev, PP_BusCTL, ENABLE_IRQ | MEMORY_ON);
  992. for (i = 2; i < CS8920_NO_INTS; i++) {
  993. if ((1 << i) & lp->irq_map) {
  994. if (request_irq(i, net_interrupt, 0, dev->name, dev) == 0) {
  995. dev->irq = i;
  996. write_irq(dev, lp->chip_type, i);
  997. /* writereg(dev, PP_BufCFG, GENERATE_SW_INTERRUPT); */
  998. break;
  999. }
  1000. }
  1001. }
  1002. if (i >= CS8920_NO_INTS) {
  1003. writereg(dev, PP_BusCTL, 0); /* disable interrupts. */
  1004. printk(KERN_ERR "cs89x0: can't get an interrupt\n");
  1005. ret = -EAGAIN;
  1006. goto bad_out;
  1007. }
  1008. }
  1009. else
  1010. #endif
  1011. {
  1012. #ifndef CONFIG_ARCH_IXDP2X01
  1013. if (((1 << dev->irq) & lp->irq_map) == 0) {
  1014. printk(KERN_ERR "%s: IRQ %d is not in our map of allowable IRQs, which is %x\n",
  1015. dev->name, dev->irq, lp->irq_map);
  1016. ret = -EAGAIN;
  1017. goto bad_out;
  1018. }
  1019. #endif
  1020. /* FIXME: Cirrus' release had this: */
  1021. writereg(dev, PP_BusCTL, readreg(dev, PP_BusCTL)|ENABLE_IRQ );
  1022. /* And 2.3.47 had this: */
  1023. #if 0
  1024. writereg(dev, PP_BusCTL, ENABLE_IRQ | MEMORY_ON);
  1025. #endif
  1026. write_irq(dev, lp->chip_type, dev->irq);
  1027. ret = request_irq(dev->irq, &net_interrupt, 0, dev->name, dev);
  1028. if (ret) {
  1029. if (net_debug)
  1030. printk(KERN_DEBUG "cs89x0: request_irq(%d) failed\n", dev->irq);
  1031. goto bad_out;
  1032. }
  1033. }
  1034. #if ALLOW_DMA
  1035. if (lp->use_dma) {
  1036. if (lp->isa_config & ANY_ISA_DMA) {
  1037. unsigned long flags;
  1038. lp->dma_buff = (unsigned char *)__get_dma_pages(GFP_KERNEL,
  1039. get_order(lp->dmasize * 1024));
  1040. if (!lp->dma_buff) {
  1041. printk(KERN_ERR "%s: cannot get %dK memory for DMA\n", dev->name, lp->dmasize);
  1042. goto release_irq;
  1043. }
  1044. if (net_debug > 1) {
  1045. printk( "%s: dma %lx %lx\n",
  1046. dev->name,
  1047. (unsigned long)lp->dma_buff,
  1048. (unsigned long)isa_virt_to_bus(lp->dma_buff));
  1049. }
  1050. if ((unsigned long) lp->dma_buff >= MAX_DMA_ADDRESS ||
  1051. !dma_page_eq(lp->dma_buff, lp->dma_buff+lp->dmasize*1024-1)) {
  1052. printk(KERN_ERR "%s: not usable as DMA buffer\n", dev->name);
  1053. goto release_irq;
  1054. }
  1055. memset(lp->dma_buff, 0, lp->dmasize * 1024); /* Why? */
  1056. if (request_dma(dev->dma, dev->name)) {
  1057. printk(KERN_ERR "%s: cannot get dma channel %d\n", dev->name, dev->dma);
  1058. goto release_irq;
  1059. }
  1060. write_dma(dev, lp->chip_type, dev->dma);
  1061. lp->rx_dma_ptr = lp->dma_buff;
  1062. lp->end_dma_buff = lp->dma_buff + lp->dmasize*1024;
  1063. spin_lock_irqsave(&lp->lock, flags);
  1064. disable_dma(dev->dma);
  1065. clear_dma_ff(dev->dma);
  1066. set_dma_mode(dev->dma, 0x14); /* auto_init as well */
  1067. set_dma_addr(dev->dma, isa_virt_to_bus(lp->dma_buff));
  1068. set_dma_count(dev->dma, lp->dmasize*1024);
  1069. enable_dma(dev->dma);
  1070. spin_unlock_irqrestore(&lp->lock, flags);
  1071. }
  1072. }
  1073. #endif /* ALLOW_DMA */
  1074. /* set the Ethernet address */
  1075. for (i=0; i < ETH_ALEN/2; i++)
  1076. writereg(dev, PP_IA+i*2, dev->dev_addr[i*2] | (dev->dev_addr[i*2+1] << 8));
  1077. /* while we're testing the interface, leave interrupts disabled */
  1078. writereg(dev, PP_BusCTL, MEMORY_ON);
  1079. /* Set the LineCTL quintuplet based on adapter configuration read from EEPROM */
  1080. if ((lp->adapter_cnf & A_CNF_EXTND_10B_2) && (lp->adapter_cnf & A_CNF_LOW_RX_SQUELCH))
  1081. lp->linectl = LOW_RX_SQUELCH;
  1082. else
  1083. lp->linectl = 0;
  1084. /* check to make sure that they have the "right" hardware available */
  1085. switch(lp->adapter_cnf & A_CNF_MEDIA_TYPE) {
  1086. case A_CNF_MEDIA_10B_T: result = lp->adapter_cnf & A_CNF_10B_T; break;
  1087. case A_CNF_MEDIA_AUI: result = lp->adapter_cnf & A_CNF_AUI; break;
  1088. case A_CNF_MEDIA_10B_2: result = lp->adapter_cnf & A_CNF_10B_2; break;
  1089. default: result = lp->adapter_cnf & (A_CNF_10B_T | A_CNF_AUI | A_CNF_10B_2);
  1090. }
  1091. if (!result) {
  1092. printk(KERN_ERR "%s: EEPROM is configured for unavailable media\n", dev->name);
  1093. release_irq:
  1094. #if ALLOW_DMA
  1095. release_dma_buff(lp);
  1096. #endif
  1097. writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) & ~(SERIAL_TX_ON | SERIAL_RX_ON));
  1098. free_irq(dev->irq, dev);
  1099. ret = -EAGAIN;
  1100. goto bad_out;
  1101. }
  1102. /* set the hardware to the configured choice */
  1103. switch(lp->adapter_cnf & A_CNF_MEDIA_TYPE) {
  1104. case A_CNF_MEDIA_10B_T:
  1105. result = detect_tp(dev);
  1106. if (result==DETECTED_NONE) {
  1107. printk(KERN_WARNING "%s: 10Base-T (RJ-45) has no cable\n", dev->name);
  1108. if (lp->auto_neg_cnf & IMM_BIT) /* check "ignore missing media" bit */
  1109. result = DETECTED_RJ45H; /* Yes! I don't care if I see a link pulse */
  1110. }
  1111. break;
  1112. case A_CNF_MEDIA_AUI:
  1113. result = detect_aui(dev);
  1114. if (result==DETECTED_NONE) {
  1115. printk(KERN_WARNING "%s: 10Base-5 (AUI) has no cable\n", dev->name);
  1116. if (lp->auto_neg_cnf & IMM_BIT) /* check "ignore missing media" bit */
  1117. result = DETECTED_AUI; /* Yes! I don't care if I see a carrrier */
  1118. }
  1119. break;
  1120. case A_CNF_MEDIA_10B_2:
  1121. result = detect_bnc(dev);
  1122. if (result==DETECTED_NONE) {
  1123. printk(KERN_WARNING "%s: 10Base-2 (BNC) has no cable\n", dev->name);
  1124. if (lp->auto_neg_cnf & IMM_BIT) /* check "ignore missing media" bit */
  1125. result = DETECTED_BNC; /* Yes! I don't care if I can xmit a packet */
  1126. }
  1127. break;
  1128. case A_CNF_MEDIA_AUTO:
  1129. writereg(dev, PP_LineCTL, lp->linectl | AUTO_AUI_10BASET);
  1130. if (lp->adapter_cnf & A_CNF_10B_T)
  1131. if ((result = detect_tp(dev)) != DETECTED_NONE)
  1132. break;
  1133. if (lp->adapter_cnf & A_CNF_AUI)
  1134. if ((result = detect_aui(dev)) != DETECTED_NONE)
  1135. break;
  1136. if (lp->adapter_cnf & A_CNF_10B_2)
  1137. if ((result = detect_bnc(dev)) != DETECTED_NONE)
  1138. break;
  1139. printk(KERN_ERR "%s: no media detected\n", dev->name);
  1140. goto release_irq;
  1141. }
  1142. switch(result) {
  1143. case DETECTED_NONE:
  1144. printk(KERN_ERR "%s: no network cable attached to configured media\n", dev->name);
  1145. goto release_irq;
  1146. case DETECTED_RJ45H:
  1147. printk(KERN_INFO "%s: using half-duplex 10Base-T (RJ-45)\n", dev->name);
  1148. break;
  1149. case DETECTED_RJ45F:
  1150. printk(KERN_INFO "%s: using full-duplex 10Base-T (RJ-45)\n", dev->name);
  1151. break;
  1152. case DETECTED_AUI:
  1153. printk(KERN_INFO "%s: using 10Base-5 (AUI)\n", dev->name);
  1154. break;
  1155. case DETECTED_BNC:
  1156. printk(KERN_INFO "%s: using 10Base-2 (BNC)\n", dev->name);
  1157. break;
  1158. }
  1159. /* Turn on both receive and transmit operations */
  1160. writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_RX_ON | SERIAL_TX_ON);
  1161. /* Receive only error free packets addressed to this card */
  1162. lp->rx_mode = 0;
  1163. writereg(dev, PP_RxCTL, DEF_RX_ACCEPT);
  1164. lp->curr_rx_cfg = RX_OK_ENBL | RX_CRC_ERROR_ENBL;
  1165. if (lp->isa_config & STREAM_TRANSFER)
  1166. lp->curr_rx_cfg |= RX_STREAM_ENBL;
  1167. #if ALLOW_DMA
  1168. set_dma_cfg(dev);
  1169. #endif
  1170. writereg(dev, PP_RxCFG, lp->curr_rx_cfg);
  1171. writereg(dev, PP_TxCFG, TX_LOST_CRS_ENBL | TX_SQE_ERROR_ENBL | TX_OK_ENBL |
  1172. TX_LATE_COL_ENBL | TX_JBR_ENBL | TX_ANY_COL_ENBL | TX_16_COL_ENBL);
  1173. writereg(dev, PP_BufCFG, READY_FOR_TX_ENBL | RX_MISS_COUNT_OVRFLOW_ENBL |
  1174. #if ALLOW_DMA
  1175. dma_bufcfg(dev) |
  1176. #endif
  1177. TX_COL_COUNT_OVRFLOW_ENBL | TX_UNDERRUN_ENBL);
  1178. /* now that we've got our act together, enable everything */
  1179. writereg(dev, PP_BusCTL, ENABLE_IRQ
  1180. | (dev->mem_start?MEMORY_ON : 0) /* turn memory on */
  1181. #if ALLOW_DMA
  1182. | dma_busctl(dev)
  1183. #endif
  1184. );
  1185. netif_start_queue(dev);
  1186. if (net_debug > 1)
  1187. printk("cs89x0: net_open() succeeded\n");
  1188. return 0;
  1189. bad_out:
  1190. return ret;
  1191. }
  1192. static void net_timeout(struct net_device *dev)
  1193. {
  1194. /* If we get here, some higher level has decided we are broken.
  1195. There should really be a "kick me" function call instead. */
  1196. if (net_debug > 0) printk("%s: transmit timed out, %s?\n", dev->name,
  1197. tx_done(dev) ? "IRQ conflict ?" : "network cable problem");
  1198. /* Try to restart the adaptor. */
  1199. netif_wake_queue(dev);
  1200. }
  1201. static int net_send_packet(struct sk_buff *skb, struct net_device *dev)
  1202. {
  1203. struct net_local *lp = netdev_priv(dev);
  1204. if (net_debug > 3) {
  1205. printk("%s: sent %d byte packet of type %x\n",
  1206. dev->name, skb->len,
  1207. (skb->data[ETH_ALEN+ETH_ALEN] << 8) | skb->data[ETH_ALEN+ETH_ALEN+1]);
  1208. }
  1209. /* keep the upload from being interrupted, since we
  1210. ask the chip to start transmitting before the
  1211. whole packet has been completely uploaded. */
  1212. spin_lock_irq(&lp->lock);
  1213. netif_stop_queue(dev);
  1214. /* initiate a transmit sequence */
  1215. writeword(dev, TX_CMD_PORT, lp->send_cmd);
  1216. writeword(dev, TX_LEN_PORT, skb->len);
  1217. /* Test to see if the chip has allocated memory for the packet */
  1218. if ((readreg(dev, PP_BusST) & READY_FOR_TX_NOW) == 0) {
  1219. /*
  1220. * Gasp! It hasn't. But that shouldn't happen since
  1221. * we're waiting for TxOk, so return 1 and requeue this packet.
  1222. */
  1223. spin_unlock_irq(&lp->lock);
  1224. if (net_debug) printk("cs89x0: Tx buffer not free!\n");
  1225. return 1;
  1226. }
  1227. /* Write the contents of the packet */
  1228. outsw(dev->base_addr + TX_FRAME_PORT,skb->data,(skb->len+1) >>1);
  1229. spin_unlock_irq(&lp->lock);
  1230. dev->trans_start = jiffies;
  1231. dev_kfree_skb (skb);
  1232. /*
  1233. * We DO NOT call netif_wake_queue() here.
  1234. * We also DO NOT call netif_start_queue().
  1235. *
  1236. * Either of these would cause another bottom half run through
  1237. * net_send_packet() before this packet has fully gone out. That causes
  1238. * us to hit the "Gasp!" above and the send is rescheduled. it runs like
  1239. * a dog. We just return and wait for the Tx completion interrupt handler
  1240. * to restart the netdevice layer
  1241. */
  1242. return 0;
  1243. }
  1244. /* The typical workload of the driver:
  1245. Handle the network interface interrupts. */
  1246. static irqreturn_t net_interrupt(int irq, void *dev_id, struct pt_regs * regs)
  1247. {
  1248. struct net_device *dev = dev_id;
  1249. struct net_local *lp;
  1250. int ioaddr, status;
  1251. int handled = 0;
  1252. ioaddr = dev->base_addr;
  1253. lp = netdev_priv(dev);
  1254. /* we MUST read all the events out of the ISQ, otherwise we'll never
  1255. get interrupted again. As a consequence, we can't have any limit
  1256. on the number of times we loop in the interrupt handler. The
  1257. hardware guarantees that eventually we'll run out of events. Of
  1258. course, if you're on a slow machine, and packets are arriving
  1259. faster than you can read them off, you're screwed. Hasta la
  1260. vista, baby! */
  1261. while ((status = readword(dev, ISQ_PORT))) {
  1262. if (net_debug > 4)printk("%s: event=%04x\n", dev->name, status);
  1263. handled = 1;
  1264. switch(status & ISQ_EVENT_MASK) {
  1265. case ISQ_RECEIVER_EVENT:
  1266. /* Got a packet(s). */
  1267. net_rx(dev);
  1268. break;
  1269. case ISQ_TRANSMITTER_EVENT:
  1270. lp->stats.tx_packets++;
  1271. netif_wake_queue(dev); /* Inform upper layers. */
  1272. if ((status & ( TX_OK |
  1273. TX_LOST_CRS |
  1274. TX_SQE_ERROR |
  1275. TX_LATE_COL |
  1276. TX_16_COL)) != TX_OK) {
  1277. if ((status & TX_OK) == 0) lp->stats.tx_errors++;
  1278. if (status & TX_LOST_CRS) lp->stats.tx_carrier_errors++;
  1279. if (status & TX_SQE_ERROR) lp->stats.tx_heartbeat_errors++;
  1280. if (status & TX_LATE_COL) lp->stats.tx_window_errors++;
  1281. if (status & TX_16_COL) lp->stats.tx_aborted_errors++;
  1282. }
  1283. break;
  1284. case ISQ_BUFFER_EVENT:
  1285. if (status & READY_FOR_TX) {
  1286. /* we tried to transmit a packet earlier,
  1287. but inexplicably ran out of buffers.
  1288. That shouldn't happen since we only ever
  1289. load one packet. Shrug. Do the right
  1290. thing anyway. */
  1291. netif_wake_queue(dev); /* Inform upper layers. */
  1292. }
  1293. if (status & TX_UNDERRUN) {
  1294. if (net_debug > 0) printk("%s: transmit underrun\n", dev->name);
  1295. lp->send_underrun++;
  1296. if (lp->send_underrun == 3) lp->send_cmd = TX_AFTER_381;
  1297. else if (lp->send_underrun == 6) lp->send_cmd = TX_AFTER_ALL;
  1298. /* transmit cycle is done, although
  1299. frame wasn't transmitted - this
  1300. avoids having to wait for the upper
  1301. layers to timeout on us, in the
  1302. event of a tx underrun */
  1303. netif_wake_queue(dev); /* Inform upper layers. */
  1304. }
  1305. #if ALLOW_DMA
  1306. if (lp->use_dma && (status & RX_DMA)) {
  1307. int count = readreg(dev, PP_DmaFrameCnt);
  1308. while(count) {
  1309. if (net_debug > 5)
  1310. printk("%s: receiving %d DMA frames\n", dev->name, count);
  1311. if (net_debug > 2 && count >1)
  1312. printk("%s: receiving %d DMA frames\n", dev->name, count);
  1313. dma_rx(dev);
  1314. if (--count == 0)
  1315. count = readreg(dev, PP_DmaFrameCnt);
  1316. if (net_debug > 2 && count > 0)
  1317. printk("%s: continuing with %d DMA frames\n", dev->name, count);
  1318. }
  1319. }
  1320. #endif
  1321. break;
  1322. case ISQ_RX_MISS_EVENT:
  1323. lp->stats.rx_missed_errors += (status >>6);
  1324. break;
  1325. case ISQ_TX_COL_EVENT:
  1326. lp->stats.collisions += (status >>6);
  1327. break;
  1328. }
  1329. }
  1330. return IRQ_RETVAL(handled);
  1331. }
  1332. static void
  1333. count_rx_errors(int status, struct net_local *lp)
  1334. {
  1335. lp->stats.rx_errors++;
  1336. if (status & RX_RUNT) lp->stats.rx_length_errors++;
  1337. if (status & RX_EXTRA_DATA) lp->stats.rx_length_errors++;
  1338. if (status & RX_CRC_ERROR) if (!(status & (RX_EXTRA_DATA|RX_RUNT)))
  1339. /* per str 172 */
  1340. lp->stats.rx_crc_errors++;
  1341. if (status & RX_DRIBBLE) lp->stats.rx_frame_errors++;
  1342. return;
  1343. }
  1344. /* We have a good packet(s), get it/them out of the buffers. */
  1345. static void
  1346. net_rx(struct net_device *dev)
  1347. {
  1348. struct net_local *lp = netdev_priv(dev);
  1349. struct sk_buff *skb;
  1350. int status, length;
  1351. int ioaddr = dev->base_addr;
  1352. status = inw(ioaddr + RX_FRAME_PORT);
  1353. length = inw(ioaddr + RX_FRAME_PORT);
  1354. if ((status & RX_OK) == 0) {
  1355. count_rx_errors(status, lp);
  1356. return;
  1357. }
  1358. /* Malloc up new buffer. */
  1359. skb = dev_alloc_skb(length + 2);
  1360. if (skb == NULL) {
  1361. #if 0 /* Again, this seems a cruel thing to do */
  1362. printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name);
  1363. #endif
  1364. lp->stats.rx_dropped++;
  1365. return;
  1366. }
  1367. skb_reserve(skb, 2); /* longword align L3 header */
  1368. skb->dev = dev;
  1369. insw(ioaddr + RX_FRAME_PORT, skb_put(skb, length), length >> 1);
  1370. if (length & 1)
  1371. skb->data[length-1] = inw(ioaddr + RX_FRAME_PORT);
  1372. if (net_debug > 3) {
  1373. printk( "%s: received %d byte packet of type %x\n",
  1374. dev->name, length,
  1375. (skb->data[ETH_ALEN+ETH_ALEN] << 8) | skb->data[ETH_ALEN+ETH_ALEN+1]);
  1376. }
  1377. skb->protocol=eth_type_trans(skb,dev);
  1378. netif_rx(skb);
  1379. dev->last_rx = jiffies;
  1380. lp->stats.rx_packets++;
  1381. lp->stats.rx_bytes += length;
  1382. }
  1383. #if ALLOW_DMA
  1384. static void release_dma_buff(struct net_local *lp)
  1385. {
  1386. if (lp->dma_buff) {
  1387. free_pages((unsigned long)(lp->dma_buff), get_order(lp->dmasize * 1024));
  1388. lp->dma_buff = NULL;
  1389. }
  1390. }
  1391. #endif
  1392. /* The inverse routine to net_open(). */
  1393. static int
  1394. net_close(struct net_device *dev)
  1395. {
  1396. #if ALLOW_DMA
  1397. struct net_local *lp = netdev_priv(dev);
  1398. #endif
  1399. netif_stop_queue(dev);
  1400. writereg(dev, PP_RxCFG, 0);
  1401. writereg(dev, PP_TxCFG, 0);
  1402. writereg(dev, PP_BufCFG, 0);
  1403. writereg(dev, PP_BusCTL, 0);
  1404. free_irq(dev->irq, dev);
  1405. #if ALLOW_DMA
  1406. if (lp->use_dma && lp->dma) {
  1407. free_dma(dev->dma);
  1408. release_dma_buff(lp);
  1409. }
  1410. #endif
  1411. /* Update the statistics here. */
  1412. return 0;
  1413. }
  1414. /* Get the current statistics. This may be called with the card open or
  1415. closed. */
  1416. static struct net_device_stats *
  1417. net_get_stats(struct net_device *dev)
  1418. {
  1419. struct net_local *lp = netdev_priv(dev);
  1420. unsigned long flags;
  1421. spin_lock_irqsave(&lp->lock, flags);
  1422. /* Update the statistics from the device registers. */
  1423. lp->stats.rx_missed_errors += (readreg(dev, PP_RxMiss) >> 6);
  1424. lp->stats.collisions += (readreg(dev, PP_TxCol) >> 6);
  1425. spin_unlock_irqrestore(&lp->lock, flags);
  1426. return &lp->stats;
  1427. }
  1428. static void set_multicast_list(struct net_device *dev)
  1429. {
  1430. struct net_local *lp = netdev_priv(dev);
  1431. unsigned long flags;
  1432. spin_lock_irqsave(&lp->lock, flags);
  1433. if(dev->flags&IFF_PROMISC)
  1434. {
  1435. lp->rx_mode = RX_ALL_ACCEPT;
  1436. }
  1437. else if((dev->flags&IFF_ALLMULTI)||dev->mc_list)
  1438. {
  1439. /* The multicast-accept list is initialized to accept-all, and we
  1440. rely on higher-level filtering for now. */
  1441. lp->rx_mode = RX_MULTCAST_ACCEPT;
  1442. }
  1443. else
  1444. lp->rx_mode = 0;
  1445. writereg(dev, PP_RxCTL, DEF_RX_ACCEPT | lp->rx_mode);
  1446. /* in promiscuous mode, we accept errored packets, so we have to enable interrupts on them also */
  1447. writereg(dev, PP_RxCFG, lp->curr_rx_cfg |
  1448. (lp->rx_mode == RX_ALL_ACCEPT? (RX_CRC_ERROR_ENBL|RX_RUNT_ENBL|RX_EXTRA_DATA_ENBL) : 0));
  1449. spin_unlock_irqrestore(&lp->lock, flags);
  1450. }
  1451. static int set_mac_address(struct net_device *dev, void *p)
  1452. {
  1453. int i;
  1454. struct sockaddr *addr = p;
  1455. if (netif_running(dev))
  1456. return -EBUSY;
  1457. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  1458. if (net_debug) {
  1459. printk("%s: Setting MAC address to ", dev->name);
  1460. for (i = 0; i < dev->addr_len; i++)
  1461. printk(" %2.2x", dev->dev_addr[i]);
  1462. printk(".\n");
  1463. }
  1464. /* set the Ethernet address */
  1465. for (i=0; i < ETH_ALEN/2; i++)
  1466. writereg(dev, PP_IA+i*2, dev->dev_addr[i*2] | (dev->dev_addr[i*2+1] << 8));
  1467. return 0;
  1468. }
  1469. #ifdef MODULE
  1470. static struct net_device *dev_cs89x0;
  1471. /*
  1472. * Support the 'debug' module parm even if we're compiled for non-debug to
  1473. * avoid breaking someone's startup scripts
  1474. */
  1475. static int io;
  1476. static int irq;
  1477. static int debug;
  1478. static char media[8];
  1479. static int duplex=-1;
  1480. static int use_dma; /* These generate unused var warnings if ALLOW_DMA = 0 */
  1481. static int dma;
  1482. static int dmasize=16; /* or 64 */
  1483. module_param(io, int, 0);
  1484. module_param(irq, int, 0);
  1485. module_param(debug, int, 0);
  1486. module_param_string(media, media, sizeof(media), 0);
  1487. module_param(duplex, int, 0);
  1488. module_param(dma , int, 0);
  1489. module_param(dmasize , int, 0);
  1490. module_param(use_dma , int, 0);
  1491. MODULE_PARM_DESC(io, "cs89x0 I/O base address");
  1492. MODULE_PARM_DESC(irq, "cs89x0 IRQ number");
  1493. #if DEBUGGING
  1494. MODULE_PARM_DESC(debug, "cs89x0 debug level (0-6)");
  1495. #else
  1496. MODULE_PARM_DESC(debug, "(ignored)");
  1497. #endif
  1498. MODULE_PARM_DESC(media, "Set cs89x0 adapter(s) media type(s) (rj45,bnc,aui)");
  1499. /* No other value than -1 for duplex seems to be currently interpreted */
  1500. MODULE_PARM_DESC(duplex, "(ignored)");
  1501. #if ALLOW_DMA
  1502. MODULE_PARM_DESC(dma , "cs89x0 ISA DMA channel; ignored if use_dma=0");
  1503. MODULE_PARM_DESC(dmasize , "cs89x0 DMA size in kB (16,64); ignored if use_dma=0");
  1504. MODULE_PARM_DESC(use_dma , "cs89x0 using DMA (0-1)");
  1505. #else
  1506. MODULE_PARM_DESC(dma , "(ignored)");
  1507. MODULE_PARM_DESC(dmasize , "(ignored)");
  1508. MODULE_PARM_DESC(use_dma , "(ignored)");
  1509. #endif
  1510. MODULE_AUTHOR("Mike Cruse, Russwll Nelson <nelson@crynwr.com>, Andrew Morton <andrewm@uow.edu.au>");
  1511. MODULE_LICENSE("GPL");
  1512. /*
  1513. * media=t - specify media type
  1514. or media=2
  1515. or media=aui
  1516. or medai=auto
  1517. * duplex=0 - specify forced half/full/autonegotiate duplex
  1518. * debug=# - debug level
  1519. * Default Chip Configuration:
  1520. * DMA Burst = enabled
  1521. * IOCHRDY Enabled = enabled
  1522. * UseSA = enabled
  1523. * CS8900 defaults to half-duplex if not specified on command-line
  1524. * CS8920 defaults to autoneg if not specified on command-line
  1525. * Use reset defaults for other config parameters
  1526. * Assumptions:
  1527. * media type specified is supported (circuitry is present)
  1528. * if memory address is > 1MB, then required mem decode hw is present
  1529. * if 10B-2, then agent other than driver will enable DC/DC converter
  1530. (hw or software util)
  1531. */
  1532. int
  1533. init_module(void)
  1534. {
  1535. struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
  1536. struct net_local *lp;
  1537. int ret = 0;
  1538. #if DEBUGGING
  1539. net_debug = debug;
  1540. #else
  1541. debug = 0;
  1542. #endif
  1543. if (!dev)
  1544. return -ENOMEM;
  1545. dev->irq = irq;
  1546. dev->base_addr = io;
  1547. lp = netdev_priv(dev);
  1548. #if ALLOW_DMA
  1549. if (use_dma) {
  1550. lp->use_dma = use_dma;
  1551. lp->dma = dma;
  1552. lp->dmasize = dmasize;
  1553. }
  1554. #endif
  1555. spin_lock_init(&lp->lock);
  1556. /* boy, they'd better get these right */
  1557. if (!strcmp(media, "rj45"))
  1558. lp->adapter_cnf = A_CNF_MEDIA_10B_T | A_CNF_10B_T;
  1559. else if (!strcmp(media, "aui"))
  1560. lp->adapter_cnf = A_CNF_MEDIA_AUI | A_CNF_AUI;
  1561. else if (!strcmp(media, "bnc"))
  1562. lp->adapter_cnf = A_CNF_MEDIA_10B_2 | A_CNF_10B_2;
  1563. else
  1564. lp->adapter_cnf = A_CNF_MEDIA_10B_T | A_CNF_10B_T;
  1565. if (duplex==-1)
  1566. lp->auto_neg_cnf = AUTO_NEG_ENABLE;
  1567. if (io == 0) {
  1568. printk(KERN_ERR "cs89x0.c: Module autoprobing not allowed.\n");
  1569. printk(KERN_ERR "cs89x0.c: Append io=0xNNN\n");
  1570. ret = -EPERM;
  1571. goto out;
  1572. } else if (io <= 0x1ff) {
  1573. ret = -ENXIO;
  1574. goto out;
  1575. }
  1576. #if ALLOW_DMA
  1577. if (use_dma && dmasize != 16 && dmasize != 64) {
  1578. printk(KERN_ERR "cs89x0.c: dma size must be either 16K or 64K, not %dK\n", dmasize);
  1579. ret = -EPERM;
  1580. goto out;
  1581. }
  1582. #endif
  1583. ret = cs89x0_probe1(dev, io, 1);
  1584. if (ret)
  1585. goto out;
  1586. if (register_netdev(dev) != 0) {
  1587. printk(KERN_ERR "cs89x0.c: No card found at 0x%x\n", io);
  1588. ret = -ENXIO;
  1589. outw(PP_ChipID, dev->base_addr + ADD_PORT);
  1590. release_region(dev->base_addr, NETCARD_IO_EXTENT);
  1591. goto out;
  1592. }
  1593. dev_cs89x0 = dev;
  1594. return 0;
  1595. out:
  1596. free_netdev(dev);
  1597. return ret;
  1598. }
  1599. void
  1600. cleanup_module(void)
  1601. {
  1602. unregister_netdev(dev_cs89x0);
  1603. outw(PP_ChipID, dev_cs89x0->base_addr + ADD_PORT);
  1604. release_region(dev_cs89x0->base_addr, NETCARD_IO_EXTENT);
  1605. free_netdev(dev_cs89x0);
  1606. }
  1607. #endif /* MODULE */
  1608. /*
  1609. * Local variables:
  1610. * version-control: t
  1611. * kept-new-versions: 5
  1612. * c-indent-level: 8
  1613. * tab-width: 8
  1614. * End:
  1615. *
  1616. */