cs89x0.c 58 KB

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