cs89x0.c 56 KB

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