cs89x0.c 61 KB

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