lmc_main.c 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196
  1. /*
  2. * Copyright (c) 1997-2000 LAN Media Corporation (LMC)
  3. * All rights reserved. www.lanmedia.com
  4. *
  5. * This code is written by:
  6. * Andrew Stanley-Jones (asj@cban.com)
  7. * Rob Braun (bbraun@vix.com),
  8. * Michael Graff (explorer@vix.com) and
  9. * Matt Thomas (matt@3am-software.com).
  10. *
  11. * With Help By:
  12. * David Boggs
  13. * Ron Crane
  14. * Alan Cox
  15. *
  16. * This software may be used and distributed according to the terms
  17. * of the GNU General Public License version 2, incorporated herein by reference.
  18. *
  19. * Driver for the LanMedia LMC5200, LMC5245, LMC1000, LMC1200 cards.
  20. *
  21. * To control link specific options lmcctl is required.
  22. * It can be obtained from ftp.lanmedia.com.
  23. *
  24. * Linux driver notes:
  25. * Linux uses the device struct lmc_private to pass private information
  26. * arround.
  27. *
  28. * The initialization portion of this driver (the lmc_reset() and the
  29. * lmc_dec_reset() functions, as well as the led controls and the
  30. * lmc_initcsrs() functions.
  31. *
  32. * The watchdog function runs every second and checks to see if
  33. * we still have link, and that the timing source is what we expected
  34. * it to be. If link is lost, the interface is marked down, and
  35. * we no longer can transmit.
  36. *
  37. */
  38. /* $Id: lmc_main.c,v 1.36 2000/04/11 05:25:25 asj Exp $ */
  39. #include <linux/kernel.h>
  40. #include <linux/module.h>
  41. #include <linux/string.h>
  42. #include <linux/timer.h>
  43. #include <linux/ptrace.h>
  44. #include <linux/errno.h>
  45. #include <linux/ioport.h>
  46. #include <linux/slab.h>
  47. #include <linux/interrupt.h>
  48. #include <linux/pci.h>
  49. #include <linux/delay.h>
  50. #include <linux/init.h>
  51. #include <linux/in.h>
  52. #include <linux/if_arp.h>
  53. #include <linux/netdevice.h>
  54. #include <linux/etherdevice.h>
  55. #include <linux/skbuff.h>
  56. #include <linux/inet.h>
  57. #include <linux/bitops.h>
  58. #include <net/syncppp.h>
  59. #include <asm/processor.h> /* Processor type for cache alignment. */
  60. #include <asm/io.h>
  61. #include <asm/dma.h>
  62. #include <asm/uaccess.h>
  63. //#include <asm/spinlock.h>
  64. #define DRIVER_MAJOR_VERSION 1
  65. #define DRIVER_MINOR_VERSION 34
  66. #define DRIVER_SUB_VERSION 0
  67. #define DRIVER_VERSION ((DRIVER_MAJOR_VERSION << 8) + DRIVER_MINOR_VERSION)
  68. #include "lmc.h"
  69. #include "lmc_var.h"
  70. #include "lmc_ioctl.h"
  71. #include "lmc_debug.h"
  72. #include "lmc_proto.h"
  73. static int lmc_first_load = 0;
  74. static int LMC_PKT_BUF_SZ = 1542;
  75. static struct pci_device_id lmc_pci_tbl[] = {
  76. { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST,
  77. PCI_VENDOR_ID_LMC, PCI_ANY_ID },
  78. { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST,
  79. PCI_ANY_ID, PCI_VENDOR_ID_LMC },
  80. { 0 }
  81. };
  82. MODULE_DEVICE_TABLE(pci, lmc_pci_tbl);
  83. MODULE_LICENSE("GPL");
  84. static int lmc_start_xmit(struct sk_buff *skb, struct net_device *dev);
  85. static int lmc_start_xmit(struct sk_buff *skb, struct net_device *dev);
  86. static int lmc_rx (struct net_device *dev);
  87. static int lmc_open(struct net_device *dev);
  88. static int lmc_close(struct net_device *dev);
  89. static struct net_device_stats *lmc_get_stats(struct net_device *dev);
  90. static irqreturn_t lmc_interrupt(int irq, void *dev_instance);
  91. static void lmc_initcsrs(lmc_softc_t * const sc, lmc_csrptr_t csr_base, size_t csr_size);
  92. static void lmc_softreset(lmc_softc_t * const);
  93. static void lmc_running_reset(struct net_device *dev);
  94. static int lmc_ifdown(struct net_device * const);
  95. static void lmc_watchdog(unsigned long data);
  96. static void lmc_reset(lmc_softc_t * const sc);
  97. static void lmc_dec_reset(lmc_softc_t * const sc);
  98. static void lmc_driver_timeout(struct net_device *dev);
  99. /*
  100. * linux reserves 16 device specific IOCTLs. We call them
  101. * LMCIOC* to control various bits of our world.
  102. */
  103. int lmc_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
  104. {
  105. lmc_softc_t *sc;
  106. lmc_ctl_t ctl;
  107. int ret;
  108. u_int16_t regVal;
  109. unsigned long flags;
  110. struct sppp *sp;
  111. ret = -EOPNOTSUPP;
  112. sc = dev->priv;
  113. lmc_trace(dev, "lmc_ioctl in");
  114. /*
  115. * Most functions mess with the structure
  116. * Disable interrupts while we do the polling
  117. */
  118. spin_lock_irqsave(&sc->lmc_lock, flags);
  119. switch (cmd) {
  120. /*
  121. * Return current driver state. Since we keep this up
  122. * To date internally, just copy this out to the user.
  123. */
  124. case LMCIOCGINFO: /*fold01*/
  125. if (copy_to_user(ifr->ifr_data, &sc->ictl, sizeof (lmc_ctl_t)))
  126. return -EFAULT;
  127. ret = 0;
  128. break;
  129. case LMCIOCSINFO: /*fold01*/
  130. sp = &((struct ppp_device *) dev)->sppp;
  131. if (!capable(CAP_NET_ADMIN)) {
  132. ret = -EPERM;
  133. break;
  134. }
  135. if(dev->flags & IFF_UP){
  136. ret = -EBUSY;
  137. break;
  138. }
  139. if (copy_from_user(&ctl, ifr->ifr_data, sizeof (lmc_ctl_t)))
  140. return -EFAULT;
  141. sc->lmc_media->set_status (sc, &ctl);
  142. if(ctl.crc_length != sc->ictl.crc_length) {
  143. sc->lmc_media->set_crc_length(sc, ctl.crc_length);
  144. if (sc->ictl.crc_length == LMC_CTL_CRC_LENGTH_16)
  145. sc->TxDescriptControlInit |= LMC_TDES_ADD_CRC_DISABLE;
  146. else
  147. sc->TxDescriptControlInit &= ~LMC_TDES_ADD_CRC_DISABLE;
  148. }
  149. if (ctl.keepalive_onoff == LMC_CTL_OFF)
  150. sp->pp_flags &= ~PP_KEEPALIVE; /* Turn off */
  151. else
  152. sp->pp_flags |= PP_KEEPALIVE; /* Turn on */
  153. ret = 0;
  154. break;
  155. case LMCIOCIFTYPE: /*fold01*/
  156. {
  157. u_int16_t old_type = sc->if_type;
  158. u_int16_t new_type;
  159. if (!capable(CAP_NET_ADMIN)) {
  160. ret = -EPERM;
  161. break;
  162. }
  163. if (copy_from_user(&new_type, ifr->ifr_data, sizeof(u_int16_t)))
  164. return -EFAULT;
  165. if (new_type == old_type)
  166. {
  167. ret = 0 ;
  168. break; /* no change */
  169. }
  170. lmc_proto_close(sc);
  171. lmc_proto_detach(sc);
  172. sc->if_type = new_type;
  173. // lmc_proto_init(sc);
  174. lmc_proto_attach(sc);
  175. lmc_proto_open(sc);
  176. ret = 0 ;
  177. break ;
  178. }
  179. case LMCIOCGETXINFO: /*fold01*/
  180. sc->lmc_xinfo.Magic0 = 0xBEEFCAFE;
  181. sc->lmc_xinfo.PciCardType = sc->lmc_cardtype;
  182. sc->lmc_xinfo.PciSlotNumber = 0;
  183. sc->lmc_xinfo.DriverMajorVersion = DRIVER_MAJOR_VERSION;
  184. sc->lmc_xinfo.DriverMinorVersion = DRIVER_MINOR_VERSION;
  185. sc->lmc_xinfo.DriverSubVersion = DRIVER_SUB_VERSION;
  186. sc->lmc_xinfo.XilinxRevisionNumber =
  187. lmc_mii_readreg (sc, 0, 3) & 0xf;
  188. sc->lmc_xinfo.MaxFrameSize = LMC_PKT_BUF_SZ;
  189. sc->lmc_xinfo.link_status = sc->lmc_media->get_link_status (sc);
  190. sc->lmc_xinfo.mii_reg16 = lmc_mii_readreg (sc, 0, 16);
  191. sc->lmc_xinfo.Magic1 = 0xDEADBEEF;
  192. if (copy_to_user(ifr->ifr_data, &sc->lmc_xinfo,
  193. sizeof (struct lmc_xinfo)))
  194. return -EFAULT;
  195. ret = 0;
  196. break;
  197. case LMCIOCGETLMCSTATS: /*fold01*/
  198. if (sc->lmc_cardtype == LMC_CARDTYPE_T1){
  199. lmc_mii_writereg (sc, 0, 17, T1FRAMER_FERR_LSB);
  200. sc->stats.framingBitErrorCount +=
  201. lmc_mii_readreg (sc, 0, 18) & 0xff;
  202. lmc_mii_writereg (sc, 0, 17, T1FRAMER_FERR_MSB);
  203. sc->stats.framingBitErrorCount +=
  204. (lmc_mii_readreg (sc, 0, 18) & 0xff) << 8;
  205. lmc_mii_writereg (sc, 0, 17, T1FRAMER_LCV_LSB);
  206. sc->stats.lineCodeViolationCount +=
  207. lmc_mii_readreg (sc, 0, 18) & 0xff;
  208. lmc_mii_writereg (sc, 0, 17, T1FRAMER_LCV_MSB);
  209. sc->stats.lineCodeViolationCount +=
  210. (lmc_mii_readreg (sc, 0, 18) & 0xff) << 8;
  211. lmc_mii_writereg (sc, 0, 17, T1FRAMER_AERR);
  212. regVal = lmc_mii_readreg (sc, 0, 18) & 0xff;
  213. sc->stats.lossOfFrameCount +=
  214. (regVal & T1FRAMER_LOF_MASK) >> 4;
  215. sc->stats.changeOfFrameAlignmentCount +=
  216. (regVal & T1FRAMER_COFA_MASK) >> 2;
  217. sc->stats.severelyErroredFrameCount +=
  218. regVal & T1FRAMER_SEF_MASK;
  219. }
  220. if (copy_to_user(ifr->ifr_data, &sc->stats,
  221. sizeof (struct lmc_statistics)))
  222. return -EFAULT;
  223. ret = 0;
  224. break;
  225. case LMCIOCCLEARLMCSTATS: /*fold01*/
  226. if (!capable(CAP_NET_ADMIN)){
  227. ret = -EPERM;
  228. break;
  229. }
  230. memset (&sc->stats, 0, sizeof (struct lmc_statistics));
  231. sc->stats.check = STATCHECK;
  232. sc->stats.version_size = (DRIVER_VERSION << 16) +
  233. sizeof (struct lmc_statistics);
  234. sc->stats.lmc_cardtype = sc->lmc_cardtype;
  235. ret = 0;
  236. break;
  237. case LMCIOCSETCIRCUIT: /*fold01*/
  238. if (!capable(CAP_NET_ADMIN)){
  239. ret = -EPERM;
  240. break;
  241. }
  242. if(dev->flags & IFF_UP){
  243. ret = -EBUSY;
  244. break;
  245. }
  246. if (copy_from_user(&ctl, ifr->ifr_data, sizeof (lmc_ctl_t)))
  247. return -EFAULT;
  248. sc->lmc_media->set_circuit_type(sc, ctl.circuit_type);
  249. sc->ictl.circuit_type = ctl.circuit_type;
  250. ret = 0;
  251. break;
  252. case LMCIOCRESET: /*fold01*/
  253. if (!capable(CAP_NET_ADMIN)){
  254. ret = -EPERM;
  255. break;
  256. }
  257. /* Reset driver and bring back to current state */
  258. printk (" REG16 before reset +%04x\n", lmc_mii_readreg (sc, 0, 16));
  259. lmc_running_reset (dev);
  260. printk (" REG16 after reset +%04x\n", lmc_mii_readreg (sc, 0, 16));
  261. LMC_EVENT_LOG(LMC_EVENT_FORCEDRESET, LMC_CSR_READ (sc, csr_status), lmc_mii_readreg (sc, 0, 16));
  262. ret = 0;
  263. break;
  264. #ifdef DEBUG
  265. case LMCIOCDUMPEVENTLOG:
  266. if (copy_to_user(ifr->ifr_data, &lmcEventLogIndex, sizeof (u32)))
  267. return -EFAULT;
  268. if (copy_to_user(ifr->ifr_data + sizeof (u32), lmcEventLogBuf, sizeof (lmcEventLogBuf)))
  269. return -EFAULT;
  270. ret = 0;
  271. break;
  272. #endif /* end ifdef _DBG_EVENTLOG */
  273. case LMCIOCT1CONTROL: /*fold01*/
  274. if (sc->lmc_cardtype != LMC_CARDTYPE_T1){
  275. ret = -EOPNOTSUPP;
  276. break;
  277. }
  278. break;
  279. case LMCIOCXILINX: /*fold01*/
  280. {
  281. struct lmc_xilinx_control xc; /*fold02*/
  282. if (!capable(CAP_NET_ADMIN)){
  283. ret = -EPERM;
  284. break;
  285. }
  286. /*
  287. * Stop the xwitter whlie we restart the hardware
  288. */
  289. netif_stop_queue(dev);
  290. if (copy_from_user(&xc, ifr->ifr_data, sizeof (struct lmc_xilinx_control)))
  291. return -EFAULT;
  292. switch(xc.command){
  293. case lmc_xilinx_reset: /*fold02*/
  294. {
  295. u16 mii;
  296. mii = lmc_mii_readreg (sc, 0, 16);
  297. /*
  298. * Make all of them 0 and make input
  299. */
  300. lmc_gpio_mkinput(sc, 0xff);
  301. /*
  302. * make the reset output
  303. */
  304. lmc_gpio_mkoutput(sc, LMC_GEP_RESET);
  305. /*
  306. * RESET low to force configuration. This also forces
  307. * the transmitter clock to be internal, but we expect to reset
  308. * that later anyway.
  309. */
  310. sc->lmc_gpio &= ~LMC_GEP_RESET;
  311. LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
  312. /*
  313. * hold for more than 10 microseconds
  314. */
  315. udelay(50);
  316. sc->lmc_gpio |= LMC_GEP_RESET;
  317. LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
  318. /*
  319. * stop driving Xilinx-related signals
  320. */
  321. lmc_gpio_mkinput(sc, 0xff);
  322. /* Reset the frammer hardware */
  323. sc->lmc_media->set_link_status (sc, 1);
  324. sc->lmc_media->set_status (sc, NULL);
  325. // lmc_softreset(sc);
  326. {
  327. int i;
  328. for(i = 0; i < 5; i++){
  329. lmc_led_on(sc, LMC_DS3_LED0);
  330. mdelay(100);
  331. lmc_led_off(sc, LMC_DS3_LED0);
  332. lmc_led_on(sc, LMC_DS3_LED1);
  333. mdelay(100);
  334. lmc_led_off(sc, LMC_DS3_LED1);
  335. lmc_led_on(sc, LMC_DS3_LED3);
  336. mdelay(100);
  337. lmc_led_off(sc, LMC_DS3_LED3);
  338. lmc_led_on(sc, LMC_DS3_LED2);
  339. mdelay(100);
  340. lmc_led_off(sc, LMC_DS3_LED2);
  341. }
  342. }
  343. ret = 0x0;
  344. }
  345. break;
  346. case lmc_xilinx_load_prom: /*fold02*/
  347. {
  348. u16 mii;
  349. int timeout = 500000;
  350. mii = lmc_mii_readreg (sc, 0, 16);
  351. /*
  352. * Make all of them 0 and make input
  353. */
  354. lmc_gpio_mkinput(sc, 0xff);
  355. /*
  356. * make the reset output
  357. */
  358. lmc_gpio_mkoutput(sc, LMC_GEP_DP | LMC_GEP_RESET);
  359. /*
  360. * RESET low to force configuration. This also forces
  361. * the transmitter clock to be internal, but we expect to reset
  362. * that later anyway.
  363. */
  364. sc->lmc_gpio &= ~(LMC_GEP_RESET | LMC_GEP_DP);
  365. LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
  366. /*
  367. * hold for more than 10 microseconds
  368. */
  369. udelay(50);
  370. sc->lmc_gpio |= LMC_GEP_DP | LMC_GEP_RESET;
  371. LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
  372. /*
  373. * busy wait for the chip to reset
  374. */
  375. while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
  376. (timeout-- > 0))
  377. ;
  378. /*
  379. * stop driving Xilinx-related signals
  380. */
  381. lmc_gpio_mkinput(sc, 0xff);
  382. ret = 0x0;
  383. break;
  384. }
  385. case lmc_xilinx_load: /*fold02*/
  386. {
  387. char *data;
  388. int pos;
  389. int timeout = 500000;
  390. if(xc.data == 0x0){
  391. ret = -EINVAL;
  392. break;
  393. }
  394. data = kmalloc(xc.len, GFP_KERNEL);
  395. if(data == 0x0){
  396. printk(KERN_WARNING "%s: Failed to allocate memory for copy\n", dev->name);
  397. ret = -ENOMEM;
  398. break;
  399. }
  400. if(copy_from_user(data, xc.data, xc.len))
  401. {
  402. kfree(data);
  403. ret = -ENOMEM;
  404. break;
  405. }
  406. printk("%s: Starting load of data Len: %d at 0x%p == 0x%p\n", dev->name, xc.len, xc.data, data);
  407. lmc_gpio_mkinput(sc, 0xff);
  408. /*
  409. * Clear the Xilinx and start prgramming from the DEC
  410. */
  411. /*
  412. * Set ouput as:
  413. * Reset: 0 (active)
  414. * DP: 0 (active)
  415. * Mode: 1
  416. *
  417. */
  418. sc->lmc_gpio = 0x00;
  419. sc->lmc_gpio &= ~LMC_GEP_DP;
  420. sc->lmc_gpio &= ~LMC_GEP_RESET;
  421. sc->lmc_gpio |= LMC_GEP_MODE;
  422. LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
  423. lmc_gpio_mkoutput(sc, LMC_GEP_MODE | LMC_GEP_DP | LMC_GEP_RESET);
  424. /*
  425. * Wait at least 10 us 20 to be safe
  426. */
  427. udelay(50);
  428. /*
  429. * Clear reset and activate programming lines
  430. * Reset: Input
  431. * DP: Input
  432. * Clock: Output
  433. * Data: Output
  434. * Mode: Output
  435. */
  436. lmc_gpio_mkinput(sc, LMC_GEP_DP | LMC_GEP_RESET);
  437. /*
  438. * Set LOAD, DATA, Clock to 1
  439. */
  440. sc->lmc_gpio = 0x00;
  441. sc->lmc_gpio |= LMC_GEP_MODE;
  442. sc->lmc_gpio |= LMC_GEP_DATA;
  443. sc->lmc_gpio |= LMC_GEP_CLK;
  444. LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
  445. lmc_gpio_mkoutput(sc, LMC_GEP_DATA | LMC_GEP_CLK | LMC_GEP_MODE );
  446. /*
  447. * busy wait for the chip to reset
  448. */
  449. while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
  450. (timeout-- > 0))
  451. ;
  452. printk(KERN_DEBUG "%s: Waited %d for the Xilinx to clear it's memory\n", dev->name, 500000-timeout);
  453. for(pos = 0; pos < xc.len; pos++){
  454. switch(data[pos]){
  455. case 0:
  456. sc->lmc_gpio &= ~LMC_GEP_DATA; /* Data is 0 */
  457. break;
  458. case 1:
  459. sc->lmc_gpio |= LMC_GEP_DATA; /* Data is 1 */
  460. break;
  461. default:
  462. printk(KERN_WARNING "%s Bad data in xilinx programming data at %d, got %d wanted 0 or 1\n", dev->name, pos, data[pos]);
  463. sc->lmc_gpio |= LMC_GEP_DATA; /* Assume it's 1 */
  464. }
  465. sc->lmc_gpio &= ~LMC_GEP_CLK; /* Clock to zero */
  466. sc->lmc_gpio |= LMC_GEP_MODE;
  467. LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
  468. udelay(1);
  469. sc->lmc_gpio |= LMC_GEP_CLK; /* Put the clack back to one */
  470. sc->lmc_gpio |= LMC_GEP_MODE;
  471. LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
  472. udelay(1);
  473. }
  474. if((LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0){
  475. printk(KERN_WARNING "%s: Reprogramming FAILED. Needs to be reprogrammed. (corrupted data)\n", dev->name);
  476. }
  477. else if((LMC_CSR_READ(sc, csr_gp) & LMC_GEP_DP) == 0){
  478. printk(KERN_WARNING "%s: Reprogramming FAILED. Needs to be reprogrammed. (done)\n", dev->name);
  479. }
  480. else {
  481. printk(KERN_DEBUG "%s: Done reprogramming Xilinx, %d bits, good luck!\n", dev->name, pos);
  482. }
  483. lmc_gpio_mkinput(sc, 0xff);
  484. sc->lmc_miireg16 |= LMC_MII16_FIFO_RESET;
  485. lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
  486. sc->lmc_miireg16 &= ~LMC_MII16_FIFO_RESET;
  487. lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
  488. kfree(data);
  489. ret = 0;
  490. break;
  491. }
  492. default: /*fold02*/
  493. ret = -EBADE;
  494. break;
  495. }
  496. netif_wake_queue(dev);
  497. sc->lmc_txfull = 0;
  498. }
  499. break;
  500. default: /*fold01*/
  501. /* If we don't know what to do, give the protocol a shot. */
  502. ret = lmc_proto_ioctl (sc, ifr, cmd);
  503. break;
  504. }
  505. spin_unlock_irqrestore(&sc->lmc_lock, flags); /*fold01*/
  506. lmc_trace(dev, "lmc_ioctl out");
  507. return ret;
  508. }
  509. /* the watchdog process that cruises around */
  510. static void lmc_watchdog (unsigned long data) /*fold00*/
  511. {
  512. struct net_device *dev = (struct net_device *) data;
  513. lmc_softc_t *sc;
  514. int link_status;
  515. u_int32_t ticks;
  516. unsigned long flags;
  517. sc = dev->priv;
  518. lmc_trace(dev, "lmc_watchdog in");
  519. spin_lock_irqsave(&sc->lmc_lock, flags);
  520. if(sc->check != 0xBEAFCAFE){
  521. printk("LMC: Corrupt net_device struct, breaking out\n");
  522. spin_unlock_irqrestore(&sc->lmc_lock, flags);
  523. return;
  524. }
  525. /* Make sure the tx jabber and rx watchdog are off,
  526. * and the transmit and receive processes are running.
  527. */
  528. LMC_CSR_WRITE (sc, csr_15, 0x00000011);
  529. sc->lmc_cmdmode |= TULIP_CMD_TXRUN | TULIP_CMD_RXRUN;
  530. LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
  531. if (sc->lmc_ok == 0)
  532. goto kick_timer;
  533. LMC_EVENT_LOG(LMC_EVENT_WATCHDOG, LMC_CSR_READ (sc, csr_status), lmc_mii_readreg (sc, 0, 16));
  534. /* --- begin time out check -----------------------------------
  535. * check for a transmit interrupt timeout
  536. * Has the packet xmt vs xmt serviced threshold been exceeded */
  537. if (sc->lmc_taint_tx == sc->lastlmc_taint_tx &&
  538. sc->stats.tx_packets > sc->lasttx_packets &&
  539. sc->tx_TimeoutInd == 0)
  540. {
  541. /* wait for the watchdog to come around again */
  542. sc->tx_TimeoutInd = 1;
  543. }
  544. else if (sc->lmc_taint_tx == sc->lastlmc_taint_tx &&
  545. sc->stats.tx_packets > sc->lasttx_packets &&
  546. sc->tx_TimeoutInd)
  547. {
  548. LMC_EVENT_LOG(LMC_EVENT_XMTINTTMO, LMC_CSR_READ (sc, csr_status), 0);
  549. sc->tx_TimeoutDisplay = 1;
  550. sc->stats.tx_TimeoutCnt++;
  551. /* DEC chip is stuck, hit it with a RESET!!!! */
  552. lmc_running_reset (dev);
  553. /* look at receive & transmit process state to make sure they are running */
  554. LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
  555. /* look at: DSR - 02 for Reg 16
  556. * CTS - 08
  557. * DCD - 10
  558. * RI - 20
  559. * for Reg 17
  560. */
  561. LMC_EVENT_LOG(LMC_EVENT_RESET2, lmc_mii_readreg (sc, 0, 16), lmc_mii_readreg (sc, 0, 17));
  562. /* reset the transmit timeout detection flag */
  563. sc->tx_TimeoutInd = 0;
  564. sc->lastlmc_taint_tx = sc->lmc_taint_tx;
  565. sc->lasttx_packets = sc->stats.tx_packets;
  566. }
  567. else
  568. {
  569. sc->tx_TimeoutInd = 0;
  570. sc->lastlmc_taint_tx = sc->lmc_taint_tx;
  571. sc->lasttx_packets = sc->stats.tx_packets;
  572. }
  573. /* --- end time out check ----------------------------------- */
  574. link_status = sc->lmc_media->get_link_status (sc);
  575. /*
  576. * hardware level link lost, but the interface is marked as up.
  577. * Mark it as down.
  578. */
  579. if ((link_status == 0) && (sc->last_link_status != 0)) {
  580. printk(KERN_WARNING "%s: hardware/physical link down\n", dev->name);
  581. sc->last_link_status = 0;
  582. /* lmc_reset (sc); Why reset??? The link can go down ok */
  583. /* Inform the world that link has been lost */
  584. netif_carrier_off(dev);
  585. }
  586. /*
  587. * hardware link is up, but the interface is marked as down.
  588. * Bring it back up again.
  589. */
  590. if (link_status != 0 && sc->last_link_status == 0) {
  591. printk(KERN_WARNING "%s: hardware/physical link up\n", dev->name);
  592. sc->last_link_status = 1;
  593. /* lmc_reset (sc); Again why reset??? */
  594. /* Inform the world that link protocol is back up. */
  595. netif_carrier_on(dev);
  596. /* Now we have to tell the syncppp that we had an outage
  597. * and that it should deal. Calling sppp_reopen here
  598. * should do the trick, but we may have to call sppp_close
  599. * when the link goes down, and call sppp_open here.
  600. * Subject to more testing.
  601. * --bbraun
  602. */
  603. lmc_proto_reopen(sc);
  604. }
  605. /* Call media specific watchdog functions */
  606. sc->lmc_media->watchdog(sc);
  607. /*
  608. * Poke the transmitter to make sure it
  609. * never stops, even if we run out of mem
  610. */
  611. LMC_CSR_WRITE(sc, csr_rxpoll, 0);
  612. /*
  613. * Check for code that failed
  614. * and try and fix it as appropriate
  615. */
  616. if(sc->failed_ring == 1){
  617. /*
  618. * Failed to setup the recv/xmit rin
  619. * Try again
  620. */
  621. sc->failed_ring = 0;
  622. lmc_softreset(sc);
  623. }
  624. if(sc->failed_recv_alloc == 1){
  625. /*
  626. * We failed to alloc mem in the
  627. * interrupt handler, go through the rings
  628. * and rebuild them
  629. */
  630. sc->failed_recv_alloc = 0;
  631. lmc_softreset(sc);
  632. }
  633. /*
  634. * remember the timer value
  635. */
  636. kick_timer:
  637. ticks = LMC_CSR_READ (sc, csr_gp_timer);
  638. LMC_CSR_WRITE (sc, csr_gp_timer, 0xffffffffUL);
  639. sc->ictl.ticks = 0x0000ffff - (ticks & 0x0000ffff);
  640. /*
  641. * restart this timer.
  642. */
  643. sc->timer.expires = jiffies + (HZ);
  644. add_timer (&sc->timer);
  645. spin_unlock_irqrestore(&sc->lmc_lock, flags);
  646. lmc_trace(dev, "lmc_watchdog out");
  647. }
  648. static void lmc_setup(struct net_device * const dev) /*fold00*/
  649. {
  650. lmc_trace(dev, "lmc_setup in");
  651. dev->type = ARPHRD_HDLC;
  652. dev->hard_start_xmit = lmc_start_xmit;
  653. dev->open = lmc_open;
  654. dev->stop = lmc_close;
  655. dev->get_stats = lmc_get_stats;
  656. dev->do_ioctl = lmc_ioctl;
  657. dev->tx_timeout = lmc_driver_timeout;
  658. dev->watchdog_timeo = (HZ); /* 1 second */
  659. lmc_trace(dev, "lmc_setup out");
  660. }
  661. static int __devinit lmc_init_one(struct pci_dev *pdev,
  662. const struct pci_device_id *ent)
  663. {
  664. struct net_device *dev;
  665. lmc_softc_t *sc;
  666. u16 subdevice;
  667. u_int16_t AdapModelNum;
  668. int err = -ENOMEM;
  669. static int cards_found;
  670. #ifndef GCOM
  671. /* We name by type not by vendor */
  672. static const char lmcname[] = "hdlc%d";
  673. #else
  674. /*
  675. * GCOM uses LMC vendor name so that clients can know which card
  676. * to attach to.
  677. */
  678. static const char lmcname[] = "lmc%d";
  679. #endif
  680. /*
  681. * Allocate our own device structure
  682. */
  683. dev = alloc_netdev(sizeof(lmc_softc_t), lmcname, lmc_setup);
  684. if (!dev) {
  685. printk (KERN_ERR "lmc:alloc_netdev for device failed\n");
  686. goto out1;
  687. }
  688. lmc_trace(dev, "lmc_init_one in");
  689. err = pci_enable_device(pdev);
  690. if (err) {
  691. printk(KERN_ERR "lmc: pci enable failed:%d\n", err);
  692. goto out2;
  693. }
  694. if (pci_request_regions(pdev, "lmc")) {
  695. printk(KERN_ERR "lmc: pci_request_region failed\n");
  696. err = -EIO;
  697. goto out3;
  698. }
  699. pci_set_drvdata(pdev, dev);
  700. if(lmc_first_load == 0){
  701. printk(KERN_INFO "Lan Media Corporation WAN Driver Version %d.%d.%d\n",
  702. DRIVER_MAJOR_VERSION, DRIVER_MINOR_VERSION,DRIVER_SUB_VERSION);
  703. lmc_first_load = 1;
  704. }
  705. sc = dev->priv;
  706. sc->lmc_device = dev;
  707. sc->name = dev->name;
  708. /* Initialize the sppp layer */
  709. /* An ioctl can cause a subsequent detach for raw frame interface */
  710. sc->if_type = LMC_PPP;
  711. sc->check = 0xBEAFCAFE;
  712. dev->base_addr = pci_resource_start(pdev, 0);
  713. dev->irq = pdev->irq;
  714. SET_NETDEV_DEV(dev, &pdev->dev);
  715. /*
  716. * This will get the protocol layer ready and do any 1 time init's
  717. * Must have a valid sc and dev structure
  718. */
  719. lmc_proto_init(sc);
  720. lmc_proto_attach(sc);
  721. /*
  722. * Why were we changing this???
  723. dev->tx_queue_len = 100;
  724. */
  725. /* Init the spin lock so can call it latter */
  726. spin_lock_init(&sc->lmc_lock);
  727. pci_set_master(pdev);
  728. printk ("%s: detected at %lx, irq %d\n", dev->name,
  729. dev->base_addr, dev->irq);
  730. if (register_netdev (dev) != 0) {
  731. printk (KERN_ERR "%s: register_netdev failed.\n", dev->name);
  732. goto out4;
  733. }
  734. sc->lmc_cardtype = LMC_CARDTYPE_UNKNOWN;
  735. sc->lmc_timing = LMC_CTL_CLOCK_SOURCE_EXT;
  736. /*
  737. *
  738. * Check either the subvendor or the subdevice, some systems reverse
  739. * the setting in the bois, seems to be version and arch dependent?
  740. * Fix the error, exchange the two values
  741. */
  742. if ((subdevice = pdev->subsystem_device) == PCI_VENDOR_ID_LMC)
  743. subdevice = pdev->subsystem_vendor;
  744. switch (subdevice) {
  745. case PCI_DEVICE_ID_LMC_HSSI:
  746. printk ("%s: LMC HSSI\n", dev->name);
  747. sc->lmc_cardtype = LMC_CARDTYPE_HSSI;
  748. sc->lmc_media = &lmc_hssi_media;
  749. break;
  750. case PCI_DEVICE_ID_LMC_DS3:
  751. printk ("%s: LMC DS3\n", dev->name);
  752. sc->lmc_cardtype = LMC_CARDTYPE_DS3;
  753. sc->lmc_media = &lmc_ds3_media;
  754. break;
  755. case PCI_DEVICE_ID_LMC_SSI:
  756. printk ("%s: LMC SSI\n", dev->name);
  757. sc->lmc_cardtype = LMC_CARDTYPE_SSI;
  758. sc->lmc_media = &lmc_ssi_media;
  759. break;
  760. case PCI_DEVICE_ID_LMC_T1:
  761. printk ("%s: LMC T1\n", dev->name);
  762. sc->lmc_cardtype = LMC_CARDTYPE_T1;
  763. sc->lmc_media = &lmc_t1_media;
  764. break;
  765. default:
  766. printk (KERN_WARNING "%s: LMC UNKOWN CARD!\n", dev->name);
  767. break;
  768. }
  769. lmc_initcsrs (sc, dev->base_addr, 8);
  770. lmc_gpio_mkinput (sc, 0xff);
  771. sc->lmc_gpio = 0; /* drive no signals yet */
  772. sc->lmc_media->defaults (sc);
  773. sc->lmc_media->set_link_status (sc, LMC_LINK_UP);
  774. /* verify that the PCI Sub System ID matches the Adapter Model number
  775. * from the MII register
  776. */
  777. AdapModelNum = (lmc_mii_readreg (sc, 0, 3) & 0x3f0) >> 4;
  778. if ((AdapModelNum == LMC_ADAP_T1
  779. && subdevice == PCI_DEVICE_ID_LMC_T1) || /* detect LMC1200 */
  780. (AdapModelNum == LMC_ADAP_SSI
  781. && subdevice == PCI_DEVICE_ID_LMC_SSI) || /* detect LMC1000 */
  782. (AdapModelNum == LMC_ADAP_DS3
  783. && subdevice == PCI_DEVICE_ID_LMC_DS3) || /* detect LMC5245 */
  784. (AdapModelNum == LMC_ADAP_HSSI
  785. && subdevice == PCI_DEVICE_ID_LMC_HSSI))
  786. { /* detect LMC5200 */
  787. }
  788. else {
  789. printk ("%s: Model number (%d) miscompare for PCI Subsystem ID = 0x%04x\n",
  790. dev->name, AdapModelNum, subdevice);
  791. // return (NULL);
  792. }
  793. /*
  794. * reset clock
  795. */
  796. LMC_CSR_WRITE (sc, csr_gp_timer, 0xFFFFFFFFUL);
  797. sc->board_idx = cards_found++;
  798. sc->stats.check = STATCHECK;
  799. sc->stats.version_size = (DRIVER_VERSION << 16) +
  800. sizeof (struct lmc_statistics);
  801. sc->stats.lmc_cardtype = sc->lmc_cardtype;
  802. sc->lmc_ok = 0;
  803. sc->last_link_status = 0;
  804. lmc_trace(dev, "lmc_init_one out");
  805. return 0;
  806. out4:
  807. lmc_proto_detach(sc);
  808. out3:
  809. if (pdev) {
  810. pci_release_regions(pdev);
  811. pci_set_drvdata(pdev, NULL);
  812. }
  813. out2:
  814. free_netdev(dev);
  815. out1:
  816. return err;
  817. }
  818. /*
  819. * Called from pci when removing module.
  820. */
  821. static void __devexit lmc_remove_one (struct pci_dev *pdev)
  822. {
  823. struct net_device *dev = pci_get_drvdata(pdev);
  824. if (dev) {
  825. lmc_softc_t *sc = dev->priv;
  826. printk("%s: removing...\n", dev->name);
  827. lmc_proto_detach(sc);
  828. unregister_netdev(dev);
  829. free_netdev(dev);
  830. pci_release_regions(pdev);
  831. pci_disable_device(pdev);
  832. pci_set_drvdata(pdev, NULL);
  833. }
  834. }
  835. /* After this is called, packets can be sent.
  836. * Does not initialize the addresses
  837. */
  838. static int lmc_open (struct net_device *dev) /*fold00*/
  839. {
  840. lmc_softc_t *sc = dev->priv;
  841. lmc_trace(dev, "lmc_open in");
  842. lmc_led_on(sc, LMC_DS3_LED0);
  843. lmc_dec_reset (sc);
  844. lmc_reset (sc);
  845. LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
  846. LMC_EVENT_LOG(LMC_EVENT_RESET2,
  847. lmc_mii_readreg (sc, 0, 16),
  848. lmc_mii_readreg (sc, 0, 17));
  849. if (sc->lmc_ok){
  850. lmc_trace(dev, "lmc_open lmc_ok out");
  851. return (0);
  852. }
  853. lmc_softreset (sc);
  854. /* Since we have to use PCI bus, this should work on x86,alpha,ppc */
  855. if (request_irq (dev->irq, &lmc_interrupt, IRQF_SHARED, dev->name, dev)){
  856. printk(KERN_WARNING "%s: could not get irq: %d\n", dev->name, dev->irq);
  857. lmc_trace(dev, "lmc_open irq failed out");
  858. return -EAGAIN;
  859. }
  860. sc->got_irq = 1;
  861. /* Assert Terminal Active */
  862. sc->lmc_miireg16 |= LMC_MII16_LED_ALL;
  863. sc->lmc_media->set_link_status (sc, LMC_LINK_UP);
  864. /*
  865. * reset to last state.
  866. */
  867. sc->lmc_media->set_status (sc, NULL);
  868. /* setup default bits to be used in tulip_desc_t transmit descriptor
  869. * -baz */
  870. sc->TxDescriptControlInit = (
  871. LMC_TDES_INTERRUPT_ON_COMPLETION
  872. | LMC_TDES_FIRST_SEGMENT
  873. | LMC_TDES_LAST_SEGMENT
  874. | LMC_TDES_SECOND_ADDR_CHAINED
  875. | LMC_TDES_DISABLE_PADDING
  876. );
  877. if (sc->ictl.crc_length == LMC_CTL_CRC_LENGTH_16) {
  878. /* disable 32 bit CRC generated by ASIC */
  879. sc->TxDescriptControlInit |= LMC_TDES_ADD_CRC_DISABLE;
  880. }
  881. sc->lmc_media->set_crc_length(sc, sc->ictl.crc_length);
  882. /* Acknoledge the Terminal Active and light LEDs */
  883. /* dev->flags |= IFF_UP; */
  884. lmc_proto_open(sc);
  885. dev->do_ioctl = lmc_ioctl;
  886. netif_start_queue(dev);
  887. sc->stats.tx_tbusy0++ ;
  888. /*
  889. * select what interrupts we want to get
  890. */
  891. sc->lmc_intrmask = 0;
  892. /* Should be using the default interrupt mask defined in the .h file. */
  893. sc->lmc_intrmask |= (TULIP_STS_NORMALINTR
  894. | TULIP_STS_RXINTR
  895. | TULIP_STS_TXINTR
  896. | TULIP_STS_ABNRMLINTR
  897. | TULIP_STS_SYSERROR
  898. | TULIP_STS_TXSTOPPED
  899. | TULIP_STS_TXUNDERFLOW
  900. | TULIP_STS_RXSTOPPED
  901. | TULIP_STS_RXNOBUF
  902. );
  903. LMC_CSR_WRITE (sc, csr_intr, sc->lmc_intrmask);
  904. sc->lmc_cmdmode |= TULIP_CMD_TXRUN;
  905. sc->lmc_cmdmode |= TULIP_CMD_RXRUN;
  906. LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
  907. sc->lmc_ok = 1; /* Run watchdog */
  908. /*
  909. * Set the if up now - pfb
  910. */
  911. sc->last_link_status = 1;
  912. /*
  913. * Setup a timer for the watchdog on probe, and start it running.
  914. * Since lmc_ok == 0, it will be a NOP for now.
  915. */
  916. init_timer (&sc->timer);
  917. sc->timer.expires = jiffies + HZ;
  918. sc->timer.data = (unsigned long) dev;
  919. sc->timer.function = &lmc_watchdog;
  920. add_timer (&sc->timer);
  921. lmc_trace(dev, "lmc_open out");
  922. return (0);
  923. }
  924. /* Total reset to compensate for the AdTran DSU doing bad things
  925. * under heavy load
  926. */
  927. static void lmc_running_reset (struct net_device *dev) /*fold00*/
  928. {
  929. lmc_softc_t *sc = (lmc_softc_t *) dev->priv;
  930. lmc_trace(dev, "lmc_runnig_reset in");
  931. /* stop interrupts */
  932. /* Clear the interrupt mask */
  933. LMC_CSR_WRITE (sc, csr_intr, 0x00000000);
  934. lmc_dec_reset (sc);
  935. lmc_reset (sc);
  936. lmc_softreset (sc);
  937. /* sc->lmc_miireg16 |= LMC_MII16_LED_ALL; */
  938. sc->lmc_media->set_link_status (sc, 1);
  939. sc->lmc_media->set_status (sc, NULL);
  940. netif_wake_queue(dev);
  941. sc->lmc_txfull = 0;
  942. sc->stats.tx_tbusy0++ ;
  943. sc->lmc_intrmask = TULIP_DEFAULT_INTR_MASK;
  944. LMC_CSR_WRITE (sc, csr_intr, sc->lmc_intrmask);
  945. sc->lmc_cmdmode |= (TULIP_CMD_TXRUN | TULIP_CMD_RXRUN);
  946. LMC_CSR_WRITE (sc, csr_command, sc->lmc_cmdmode);
  947. lmc_trace(dev, "lmc_runnin_reset_out");
  948. }
  949. /* This is what is called when you ifconfig down a device.
  950. * This disables the timer for the watchdog and keepalives,
  951. * and disables the irq for dev.
  952. */
  953. static int lmc_close (struct net_device *dev) /*fold00*/
  954. {
  955. /* not calling release_region() as we should */
  956. lmc_softc_t *sc;
  957. lmc_trace(dev, "lmc_close in");
  958. sc = dev->priv;
  959. sc->lmc_ok = 0;
  960. sc->lmc_media->set_link_status (sc, 0);
  961. del_timer (&sc->timer);
  962. lmc_proto_close(sc);
  963. lmc_ifdown (dev);
  964. lmc_trace(dev, "lmc_close out");
  965. return 0;
  966. }
  967. /* Ends the transfer of packets */
  968. /* When the interface goes down, this is called */
  969. static int lmc_ifdown (struct net_device *dev) /*fold00*/
  970. {
  971. lmc_softc_t *sc = dev->priv;
  972. u32 csr6;
  973. int i;
  974. lmc_trace(dev, "lmc_ifdown in");
  975. /* Don't let anything else go on right now */
  976. // dev->start = 0;
  977. netif_stop_queue(dev);
  978. sc->stats.tx_tbusy1++ ;
  979. /* stop interrupts */
  980. /* Clear the interrupt mask */
  981. LMC_CSR_WRITE (sc, csr_intr, 0x00000000);
  982. /* Stop Tx and Rx on the chip */
  983. csr6 = LMC_CSR_READ (sc, csr_command);
  984. csr6 &= ~LMC_DEC_ST; /* Turn off the Transmission bit */
  985. csr6 &= ~LMC_DEC_SR; /* Turn off the Receive bit */
  986. LMC_CSR_WRITE (sc, csr_command, csr6);
  987. sc->stats.rx_missed_errors +=
  988. LMC_CSR_READ (sc, csr_missed_frames) & 0xffff;
  989. /* release the interrupt */
  990. if(sc->got_irq == 1){
  991. free_irq (dev->irq, dev);
  992. sc->got_irq = 0;
  993. }
  994. /* free skbuffs in the Rx queue */
  995. for (i = 0; i < LMC_RXDESCS; i++)
  996. {
  997. struct sk_buff *skb = sc->lmc_rxq[i];
  998. sc->lmc_rxq[i] = NULL;
  999. sc->lmc_rxring[i].status = 0;
  1000. sc->lmc_rxring[i].length = 0;
  1001. sc->lmc_rxring[i].buffer1 = 0xDEADBEEF;
  1002. if (skb != NULL)
  1003. dev_kfree_skb(skb);
  1004. sc->lmc_rxq[i] = NULL;
  1005. }
  1006. for (i = 0; i < LMC_TXDESCS; i++)
  1007. {
  1008. if (sc->lmc_txq[i] != NULL)
  1009. dev_kfree_skb(sc->lmc_txq[i]);
  1010. sc->lmc_txq[i] = NULL;
  1011. }
  1012. lmc_led_off (sc, LMC_MII16_LED_ALL);
  1013. netif_wake_queue(dev);
  1014. sc->stats.tx_tbusy0++ ;
  1015. lmc_trace(dev, "lmc_ifdown out");
  1016. return 0;
  1017. }
  1018. /* Interrupt handling routine. This will take an incoming packet, or clean
  1019. * up after a trasmit.
  1020. */
  1021. static irqreturn_t lmc_interrupt (int irq, void *dev_instance) /*fold00*/
  1022. {
  1023. struct net_device *dev = (struct net_device *) dev_instance;
  1024. lmc_softc_t *sc;
  1025. u32 csr;
  1026. int i;
  1027. s32 stat;
  1028. unsigned int badtx;
  1029. u32 firstcsr;
  1030. int max_work = LMC_RXDESCS;
  1031. int handled = 0;
  1032. lmc_trace(dev, "lmc_interrupt in");
  1033. sc = dev->priv;
  1034. spin_lock(&sc->lmc_lock);
  1035. /*
  1036. * Read the csr to find what interrupts we have (if any)
  1037. */
  1038. csr = LMC_CSR_READ (sc, csr_status);
  1039. /*
  1040. * Make sure this is our interrupt
  1041. */
  1042. if ( ! (csr & sc->lmc_intrmask)) {
  1043. goto lmc_int_fail_out;
  1044. }
  1045. firstcsr = csr;
  1046. /* always go through this loop at least once */
  1047. while (csr & sc->lmc_intrmask) {
  1048. handled = 1;
  1049. /*
  1050. * Clear interrupt bits, we handle all case below
  1051. */
  1052. LMC_CSR_WRITE (sc, csr_status, csr);
  1053. /*
  1054. * One of
  1055. * - Transmit process timed out CSR5<1>
  1056. * - Transmit jabber timeout CSR5<3>
  1057. * - Transmit underflow CSR5<5>
  1058. * - Transmit Receiver buffer unavailable CSR5<7>
  1059. * - Receive process stopped CSR5<8>
  1060. * - Receive watchdog timeout CSR5<9>
  1061. * - Early transmit interrupt CSR5<10>
  1062. *
  1063. * Is this really right? Should we do a running reset for jabber?
  1064. * (being a WAN card and all)
  1065. */
  1066. if (csr & TULIP_STS_ABNRMLINTR){
  1067. lmc_running_reset (dev);
  1068. break;
  1069. }
  1070. if (csr & TULIP_STS_RXINTR){
  1071. lmc_trace(dev, "rx interrupt");
  1072. lmc_rx (dev);
  1073. }
  1074. if (csr & (TULIP_STS_TXINTR | TULIP_STS_TXNOBUF | TULIP_STS_TXSTOPPED)) {
  1075. int n_compl = 0 ;
  1076. /* reset the transmit timeout detection flag -baz */
  1077. sc->stats.tx_NoCompleteCnt = 0;
  1078. badtx = sc->lmc_taint_tx;
  1079. i = badtx % LMC_TXDESCS;
  1080. while ((badtx < sc->lmc_next_tx)) {
  1081. stat = sc->lmc_txring[i].status;
  1082. LMC_EVENT_LOG (LMC_EVENT_XMTINT, stat,
  1083. sc->lmc_txring[i].length);
  1084. /*
  1085. * If bit 31 is 1 the tulip owns it break out of the loop
  1086. */
  1087. if (stat & 0x80000000)
  1088. break;
  1089. n_compl++ ; /* i.e., have an empty slot in ring */
  1090. /*
  1091. * If we have no skbuff or have cleared it
  1092. * Already continue to the next buffer
  1093. */
  1094. if (sc->lmc_txq[i] == NULL)
  1095. continue;
  1096. /*
  1097. * Check the total error summary to look for any errors
  1098. */
  1099. if (stat & 0x8000) {
  1100. sc->stats.tx_errors++;
  1101. if (stat & 0x4104)
  1102. sc->stats.tx_aborted_errors++;
  1103. if (stat & 0x0C00)
  1104. sc->stats.tx_carrier_errors++;
  1105. if (stat & 0x0200)
  1106. sc->stats.tx_window_errors++;
  1107. if (stat & 0x0002)
  1108. sc->stats.tx_fifo_errors++;
  1109. }
  1110. else {
  1111. sc->stats.tx_bytes += sc->lmc_txring[i].length & 0x7ff;
  1112. sc->stats.tx_packets++;
  1113. }
  1114. // dev_kfree_skb(sc->lmc_txq[i]);
  1115. dev_kfree_skb_irq(sc->lmc_txq[i]);
  1116. sc->lmc_txq[i] = NULL;
  1117. badtx++;
  1118. i = badtx % LMC_TXDESCS;
  1119. }
  1120. if (sc->lmc_next_tx - badtx > LMC_TXDESCS)
  1121. {
  1122. printk ("%s: out of sync pointer\n", dev->name);
  1123. badtx += LMC_TXDESCS;
  1124. }
  1125. LMC_EVENT_LOG(LMC_EVENT_TBUSY0, n_compl, 0);
  1126. sc->lmc_txfull = 0;
  1127. netif_wake_queue(dev);
  1128. sc->stats.tx_tbusy0++ ;
  1129. #ifdef DEBUG
  1130. sc->stats.dirtyTx = badtx;
  1131. sc->stats.lmc_next_tx = sc->lmc_next_tx;
  1132. sc->stats.lmc_txfull = sc->lmc_txfull;
  1133. #endif
  1134. sc->lmc_taint_tx = badtx;
  1135. /*
  1136. * Why was there a break here???
  1137. */
  1138. } /* end handle transmit interrupt */
  1139. if (csr & TULIP_STS_SYSERROR) {
  1140. u32 error;
  1141. printk (KERN_WARNING "%s: system bus error csr: %#8.8x\n", dev->name, csr);
  1142. error = csr>>23 & 0x7;
  1143. switch(error){
  1144. case 0x000:
  1145. printk(KERN_WARNING "%s: Parity Fault (bad)\n", dev->name);
  1146. break;
  1147. case 0x001:
  1148. printk(KERN_WARNING "%s: Master Abort (naughty)\n", dev->name);
  1149. break;
  1150. case 0x010:
  1151. printk(KERN_WARNING "%s: Target Abort (not so naughty)\n", dev->name);
  1152. break;
  1153. default:
  1154. printk(KERN_WARNING "%s: This bus error code was supposed to be reserved!\n", dev->name);
  1155. }
  1156. lmc_dec_reset (sc);
  1157. lmc_reset (sc);
  1158. LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
  1159. LMC_EVENT_LOG(LMC_EVENT_RESET2,
  1160. lmc_mii_readreg (sc, 0, 16),
  1161. lmc_mii_readreg (sc, 0, 17));
  1162. }
  1163. if(max_work-- <= 0)
  1164. break;
  1165. /*
  1166. * Get current csr status to make sure
  1167. * we've cleared all interrupts
  1168. */
  1169. csr = LMC_CSR_READ (sc, csr_status);
  1170. } /* end interrupt loop */
  1171. LMC_EVENT_LOG(LMC_EVENT_INT, firstcsr, csr);
  1172. lmc_int_fail_out:
  1173. spin_unlock(&sc->lmc_lock);
  1174. lmc_trace(dev, "lmc_interrupt out");
  1175. return IRQ_RETVAL(handled);
  1176. }
  1177. static int lmc_start_xmit (struct sk_buff *skb, struct net_device *dev) /*fold00*/
  1178. {
  1179. lmc_softc_t *sc;
  1180. u32 flag;
  1181. int entry;
  1182. int ret = 0;
  1183. unsigned long flags;
  1184. lmc_trace(dev, "lmc_start_xmit in");
  1185. sc = dev->priv;
  1186. spin_lock_irqsave(&sc->lmc_lock, flags);
  1187. /* normal path, tbusy known to be zero */
  1188. entry = sc->lmc_next_tx % LMC_TXDESCS;
  1189. sc->lmc_txq[entry] = skb;
  1190. sc->lmc_txring[entry].buffer1 = virt_to_bus (skb->data);
  1191. LMC_CONSOLE_LOG("xmit", skb->data, skb->len);
  1192. #ifndef GCOM
  1193. /* If the queue is less than half full, don't interrupt */
  1194. if (sc->lmc_next_tx - sc->lmc_taint_tx < LMC_TXDESCS / 2)
  1195. {
  1196. /* Do not interrupt on completion of this packet */
  1197. flag = 0x60000000;
  1198. netif_wake_queue(dev);
  1199. }
  1200. else if (sc->lmc_next_tx - sc->lmc_taint_tx == LMC_TXDESCS / 2)
  1201. {
  1202. /* This generates an interrupt on completion of this packet */
  1203. flag = 0xe0000000;
  1204. netif_wake_queue(dev);
  1205. }
  1206. else if (sc->lmc_next_tx - sc->lmc_taint_tx < LMC_TXDESCS - 1)
  1207. {
  1208. /* Do not interrupt on completion of this packet */
  1209. flag = 0x60000000;
  1210. netif_wake_queue(dev);
  1211. }
  1212. else
  1213. {
  1214. /* This generates an interrupt on completion of this packet */
  1215. flag = 0xe0000000;
  1216. sc->lmc_txfull = 1;
  1217. netif_stop_queue(dev);
  1218. }
  1219. #else
  1220. flag = LMC_TDES_INTERRUPT_ON_COMPLETION;
  1221. if (sc->lmc_next_tx - sc->lmc_taint_tx >= LMC_TXDESCS - 1)
  1222. { /* ring full, go busy */
  1223. sc->lmc_txfull = 1;
  1224. netif_stop_queue(dev);
  1225. sc->stats.tx_tbusy1++ ;
  1226. LMC_EVENT_LOG(LMC_EVENT_TBUSY1, entry, 0);
  1227. }
  1228. #endif
  1229. if (entry == LMC_TXDESCS - 1) /* last descriptor in ring */
  1230. flag |= LMC_TDES_END_OF_RING; /* flag as such for Tulip */
  1231. /* don't pad small packets either */
  1232. flag = sc->lmc_txring[entry].length = (skb->len) | flag |
  1233. sc->TxDescriptControlInit;
  1234. /* set the transmit timeout flag to be checked in
  1235. * the watchdog timer handler. -baz
  1236. */
  1237. sc->stats.tx_NoCompleteCnt++;
  1238. sc->lmc_next_tx++;
  1239. /* give ownership to the chip */
  1240. LMC_EVENT_LOG(LMC_EVENT_XMT, flag, entry);
  1241. sc->lmc_txring[entry].status = 0x80000000;
  1242. /* send now! */
  1243. LMC_CSR_WRITE (sc, csr_txpoll, 0);
  1244. dev->trans_start = jiffies;
  1245. spin_unlock_irqrestore(&sc->lmc_lock, flags);
  1246. lmc_trace(dev, "lmc_start_xmit_out");
  1247. return ret;
  1248. }
  1249. static int lmc_rx (struct net_device *dev) /*fold00*/
  1250. {
  1251. lmc_softc_t *sc;
  1252. int i;
  1253. int rx_work_limit = LMC_RXDESCS;
  1254. unsigned int next_rx;
  1255. int rxIntLoopCnt; /* debug -baz */
  1256. int localLengthErrCnt = 0;
  1257. long stat;
  1258. struct sk_buff *skb, *nsb;
  1259. u16 len;
  1260. lmc_trace(dev, "lmc_rx in");
  1261. sc = dev->priv;
  1262. lmc_led_on(sc, LMC_DS3_LED3);
  1263. rxIntLoopCnt = 0; /* debug -baz */
  1264. i = sc->lmc_next_rx % LMC_RXDESCS;
  1265. next_rx = sc->lmc_next_rx;
  1266. while (((stat = sc->lmc_rxring[i].status) & LMC_RDES_OWN_BIT) != DESC_OWNED_BY_DC21X4)
  1267. {
  1268. rxIntLoopCnt++; /* debug -baz */
  1269. len = ((stat & LMC_RDES_FRAME_LENGTH) >> RDES_FRAME_LENGTH_BIT_NUMBER);
  1270. if ((stat & 0x0300) != 0x0300) { /* Check first segment and last segment */
  1271. if ((stat & 0x0000ffff) != 0x7fff) {
  1272. /* Oversized frame */
  1273. sc->stats.rx_length_errors++;
  1274. goto skip_packet;
  1275. }
  1276. }
  1277. if(stat & 0x00000008){ /* Catch a dribbling bit error */
  1278. sc->stats.rx_errors++;
  1279. sc->stats.rx_frame_errors++;
  1280. goto skip_packet;
  1281. }
  1282. if(stat & 0x00000004){ /* Catch a CRC error by the Xilinx */
  1283. sc->stats.rx_errors++;
  1284. sc->stats.rx_crc_errors++;
  1285. goto skip_packet;
  1286. }
  1287. if (len > LMC_PKT_BUF_SZ){
  1288. sc->stats.rx_length_errors++;
  1289. localLengthErrCnt++;
  1290. goto skip_packet;
  1291. }
  1292. if (len < sc->lmc_crcSize + 2) {
  1293. sc->stats.rx_length_errors++;
  1294. sc->stats.rx_SmallPktCnt++;
  1295. localLengthErrCnt++;
  1296. goto skip_packet;
  1297. }
  1298. if(stat & 0x00004000){
  1299. printk(KERN_WARNING "%s: Receiver descriptor error, receiver out of sync?\n", dev->name);
  1300. }
  1301. len -= sc->lmc_crcSize;
  1302. skb = sc->lmc_rxq[i];
  1303. /*
  1304. * We ran out of memory at some point
  1305. * just allocate an skb buff and continue.
  1306. */
  1307. if(skb == 0x0){
  1308. nsb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
  1309. if (nsb) {
  1310. sc->lmc_rxq[i] = nsb;
  1311. nsb->dev = dev;
  1312. sc->lmc_rxring[i].buffer1 = virt_to_bus(skb_tail_pointer(nsb));
  1313. }
  1314. sc->failed_recv_alloc = 1;
  1315. goto skip_packet;
  1316. }
  1317. dev->last_rx = jiffies;
  1318. sc->stats.rx_packets++;
  1319. sc->stats.rx_bytes += len;
  1320. LMC_CONSOLE_LOG("recv", skb->data, len);
  1321. /*
  1322. * I'm not sure of the sanity of this
  1323. * Packets could be arriving at a constant
  1324. * 44.210mbits/sec and we're going to copy
  1325. * them into a new buffer??
  1326. */
  1327. if(len > (LMC_MTU - (LMC_MTU>>2))){ /* len > LMC_MTU * 0.75 */
  1328. /*
  1329. * If it's a large packet don't copy it just hand it up
  1330. */
  1331. give_it_anyways:
  1332. sc->lmc_rxq[i] = NULL;
  1333. sc->lmc_rxring[i].buffer1 = 0x0;
  1334. skb_put (skb, len);
  1335. skb->protocol = lmc_proto_type(sc, skb);
  1336. skb->protocol = htons(ETH_P_WAN_PPP);
  1337. skb_reset_mac_header(skb);
  1338. /* skb_reset_network_header(skb); */
  1339. skb->dev = dev;
  1340. lmc_proto_netif(sc, skb);
  1341. /*
  1342. * This skb will be destroyed by the upper layers, make a new one
  1343. */
  1344. nsb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
  1345. if (nsb) {
  1346. sc->lmc_rxq[i] = nsb;
  1347. nsb->dev = dev;
  1348. sc->lmc_rxring[i].buffer1 = virt_to_bus(skb_tail_pointer(nsb));
  1349. /* Transferred to 21140 below */
  1350. }
  1351. else {
  1352. /*
  1353. * We've run out of memory, stop trying to allocate
  1354. * memory and exit the interrupt handler
  1355. *
  1356. * The chip may run out of receivers and stop
  1357. * in which care we'll try to allocate the buffer
  1358. * again. (once a second)
  1359. */
  1360. sc->stats.rx_BuffAllocErr++;
  1361. LMC_EVENT_LOG(LMC_EVENT_RCVINT, stat, len);
  1362. sc->failed_recv_alloc = 1;
  1363. goto skip_out_of_mem;
  1364. }
  1365. }
  1366. else {
  1367. nsb = dev_alloc_skb(len);
  1368. if(!nsb) {
  1369. goto give_it_anyways;
  1370. }
  1371. skb_copy_from_linear_data(skb, skb_put(nsb, len), len);
  1372. nsb->protocol = lmc_proto_type(sc, skb);
  1373. skb_reset_mac_header(nsb);
  1374. /* skb_reset_network_header(nsb); */
  1375. nsb->dev = dev;
  1376. lmc_proto_netif(sc, nsb);
  1377. }
  1378. skip_packet:
  1379. LMC_EVENT_LOG(LMC_EVENT_RCVINT, stat, len);
  1380. sc->lmc_rxring[i].status = DESC_OWNED_BY_DC21X4;
  1381. sc->lmc_next_rx++;
  1382. i = sc->lmc_next_rx % LMC_RXDESCS;
  1383. rx_work_limit--;
  1384. if (rx_work_limit < 0)
  1385. break;
  1386. }
  1387. /* detect condition for LMC1000 where DSU cable attaches and fills
  1388. * descriptors with bogus packets
  1389. *
  1390. if (localLengthErrCnt > LMC_RXDESCS - 3) {
  1391. sc->stats.rx_BadPktSurgeCnt++;
  1392. LMC_EVENT_LOG(LMC_EVENT_BADPKTSURGE,
  1393. localLengthErrCnt,
  1394. sc->stats.rx_BadPktSurgeCnt);
  1395. } */
  1396. /* save max count of receive descriptors serviced */
  1397. if (rxIntLoopCnt > sc->stats.rxIntLoopCnt) {
  1398. sc->stats.rxIntLoopCnt = rxIntLoopCnt; /* debug -baz */
  1399. }
  1400. #ifdef DEBUG
  1401. if (rxIntLoopCnt == 0)
  1402. {
  1403. for (i = 0; i < LMC_RXDESCS; i++)
  1404. {
  1405. if ((sc->lmc_rxring[i].status & LMC_RDES_OWN_BIT)
  1406. != DESC_OWNED_BY_DC21X4)
  1407. {
  1408. rxIntLoopCnt++;
  1409. }
  1410. }
  1411. LMC_EVENT_LOG(LMC_EVENT_RCVEND, rxIntLoopCnt, 0);
  1412. }
  1413. #endif
  1414. lmc_led_off(sc, LMC_DS3_LED3);
  1415. skip_out_of_mem:
  1416. lmc_trace(dev, "lmc_rx out");
  1417. return 0;
  1418. }
  1419. static struct net_device_stats *lmc_get_stats (struct net_device *dev) /*fold00*/
  1420. {
  1421. lmc_softc_t *sc = dev->priv;
  1422. unsigned long flags;
  1423. lmc_trace(dev, "lmc_get_stats in");
  1424. spin_lock_irqsave(&sc->lmc_lock, flags);
  1425. sc->stats.rx_missed_errors += LMC_CSR_READ (sc, csr_missed_frames) & 0xffff;
  1426. spin_unlock_irqrestore(&sc->lmc_lock, flags);
  1427. lmc_trace(dev, "lmc_get_stats out");
  1428. return (struct net_device_stats *) &sc->stats;
  1429. }
  1430. static struct pci_driver lmc_driver = {
  1431. .name = "lmc",
  1432. .id_table = lmc_pci_tbl,
  1433. .probe = lmc_init_one,
  1434. .remove = __devexit_p(lmc_remove_one),
  1435. };
  1436. static int __init init_lmc(void)
  1437. {
  1438. return pci_register_driver(&lmc_driver);
  1439. }
  1440. static void __exit exit_lmc(void)
  1441. {
  1442. pci_unregister_driver(&lmc_driver);
  1443. }
  1444. module_init(init_lmc);
  1445. module_exit(exit_lmc);
  1446. unsigned lmc_mii_readreg (lmc_softc_t * const sc, unsigned devaddr, unsigned regno) /*fold00*/
  1447. {
  1448. int i;
  1449. int command = (0xf6 << 10) | (devaddr << 5) | regno;
  1450. int retval = 0;
  1451. lmc_trace(sc->lmc_device, "lmc_mii_readreg in");
  1452. LMC_MII_SYNC (sc);
  1453. lmc_trace(sc->lmc_device, "lmc_mii_readreg: done sync");
  1454. for (i = 15; i >= 0; i--)
  1455. {
  1456. int dataval = (command & (1 << i)) ? 0x20000 : 0;
  1457. LMC_CSR_WRITE (sc, csr_9, dataval);
  1458. lmc_delay ();
  1459. /* __SLOW_DOWN_IO; */
  1460. LMC_CSR_WRITE (sc, csr_9, dataval | 0x10000);
  1461. lmc_delay ();
  1462. /* __SLOW_DOWN_IO; */
  1463. }
  1464. lmc_trace(sc->lmc_device, "lmc_mii_readreg: done1");
  1465. for (i = 19; i > 0; i--)
  1466. {
  1467. LMC_CSR_WRITE (sc, csr_9, 0x40000);
  1468. lmc_delay ();
  1469. /* __SLOW_DOWN_IO; */
  1470. retval = (retval << 1) | ((LMC_CSR_READ (sc, csr_9) & 0x80000) ? 1 : 0);
  1471. LMC_CSR_WRITE (sc, csr_9, 0x40000 | 0x10000);
  1472. lmc_delay ();
  1473. /* __SLOW_DOWN_IO; */
  1474. }
  1475. lmc_trace(sc->lmc_device, "lmc_mii_readreg out");
  1476. return (retval >> 1) & 0xffff;
  1477. }
  1478. void lmc_mii_writereg (lmc_softc_t * const sc, unsigned devaddr, unsigned regno, unsigned data) /*fold00*/
  1479. {
  1480. int i = 32;
  1481. int command = (0x5002 << 16) | (devaddr << 23) | (regno << 18) | data;
  1482. lmc_trace(sc->lmc_device, "lmc_mii_writereg in");
  1483. LMC_MII_SYNC (sc);
  1484. i = 31;
  1485. while (i >= 0)
  1486. {
  1487. int datav;
  1488. if (command & (1 << i))
  1489. datav = 0x20000;
  1490. else
  1491. datav = 0x00000;
  1492. LMC_CSR_WRITE (sc, csr_9, datav);
  1493. lmc_delay ();
  1494. /* __SLOW_DOWN_IO; */
  1495. LMC_CSR_WRITE (sc, csr_9, (datav | 0x10000));
  1496. lmc_delay ();
  1497. /* __SLOW_DOWN_IO; */
  1498. i--;
  1499. }
  1500. i = 2;
  1501. while (i > 0)
  1502. {
  1503. LMC_CSR_WRITE (sc, csr_9, 0x40000);
  1504. lmc_delay ();
  1505. /* __SLOW_DOWN_IO; */
  1506. LMC_CSR_WRITE (sc, csr_9, 0x50000);
  1507. lmc_delay ();
  1508. /* __SLOW_DOWN_IO; */
  1509. i--;
  1510. }
  1511. lmc_trace(sc->lmc_device, "lmc_mii_writereg out");
  1512. }
  1513. static void lmc_softreset (lmc_softc_t * const sc) /*fold00*/
  1514. {
  1515. int i;
  1516. lmc_trace(sc->lmc_device, "lmc_softreset in");
  1517. /* Initialize the receive rings and buffers. */
  1518. sc->lmc_txfull = 0;
  1519. sc->lmc_next_rx = 0;
  1520. sc->lmc_next_tx = 0;
  1521. sc->lmc_taint_rx = 0;
  1522. sc->lmc_taint_tx = 0;
  1523. /*
  1524. * Setup each one of the receiver buffers
  1525. * allocate an skbuff for each one, setup the descriptor table
  1526. * and point each buffer at the next one
  1527. */
  1528. for (i = 0; i < LMC_RXDESCS; i++)
  1529. {
  1530. struct sk_buff *skb;
  1531. if (sc->lmc_rxq[i] == NULL)
  1532. {
  1533. skb = dev_alloc_skb (LMC_PKT_BUF_SZ + 2);
  1534. if(skb == NULL){
  1535. printk(KERN_WARNING "%s: Failed to allocate receiver ring, will try again\n", sc->name);
  1536. sc->failed_ring = 1;
  1537. break;
  1538. }
  1539. else{
  1540. sc->lmc_rxq[i] = skb;
  1541. }
  1542. }
  1543. else
  1544. {
  1545. skb = sc->lmc_rxq[i];
  1546. }
  1547. skb->dev = sc->lmc_device;
  1548. /* owned by 21140 */
  1549. sc->lmc_rxring[i].status = 0x80000000;
  1550. /* used to be PKT_BUF_SZ now uses skb since we lose some to head room */
  1551. sc->lmc_rxring[i].length = skb_tailroom(skb);
  1552. /* use to be tail which is dumb since you're thinking why write
  1553. * to the end of the packj,et but since there's nothing there tail == data
  1554. */
  1555. sc->lmc_rxring[i].buffer1 = virt_to_bus (skb->data);
  1556. /* This is fair since the structure is static and we have the next address */
  1557. sc->lmc_rxring[i].buffer2 = virt_to_bus (&sc->lmc_rxring[i + 1]);
  1558. }
  1559. /*
  1560. * Sets end of ring
  1561. */
  1562. sc->lmc_rxring[i - 1].length |= 0x02000000; /* Set end of buffers flag */
  1563. sc->lmc_rxring[i - 1].buffer2 = virt_to_bus (&sc->lmc_rxring[0]); /* Point back to the start */
  1564. LMC_CSR_WRITE (sc, csr_rxlist, virt_to_bus (sc->lmc_rxring)); /* write base address */
  1565. /* Initialize the transmit rings and buffers */
  1566. for (i = 0; i < LMC_TXDESCS; i++)
  1567. {
  1568. if (sc->lmc_txq[i] != NULL){ /* have buffer */
  1569. dev_kfree_skb(sc->lmc_txq[i]); /* free it */
  1570. sc->stats.tx_dropped++; /* We just dropped a packet */
  1571. }
  1572. sc->lmc_txq[i] = NULL;
  1573. sc->lmc_txring[i].status = 0x00000000;
  1574. sc->lmc_txring[i].buffer2 = virt_to_bus (&sc->lmc_txring[i + 1]);
  1575. }
  1576. sc->lmc_txring[i - 1].buffer2 = virt_to_bus (&sc->lmc_txring[0]);
  1577. LMC_CSR_WRITE (sc, csr_txlist, virt_to_bus (sc->lmc_txring));
  1578. lmc_trace(sc->lmc_device, "lmc_softreset out");
  1579. }
  1580. void lmc_gpio_mkinput(lmc_softc_t * const sc, u_int32_t bits) /*fold00*/
  1581. {
  1582. lmc_trace(sc->lmc_device, "lmc_gpio_mkinput in");
  1583. sc->lmc_gpio_io &= ~bits;
  1584. LMC_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET | (sc->lmc_gpio_io));
  1585. lmc_trace(sc->lmc_device, "lmc_gpio_mkinput out");
  1586. }
  1587. void lmc_gpio_mkoutput(lmc_softc_t * const sc, u_int32_t bits) /*fold00*/
  1588. {
  1589. lmc_trace(sc->lmc_device, "lmc_gpio_mkoutput in");
  1590. sc->lmc_gpio_io |= bits;
  1591. LMC_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET | (sc->lmc_gpio_io));
  1592. lmc_trace(sc->lmc_device, "lmc_gpio_mkoutput out");
  1593. }
  1594. void lmc_led_on(lmc_softc_t * const sc, u_int32_t led) /*fold00*/
  1595. {
  1596. lmc_trace(sc->lmc_device, "lmc_led_on in");
  1597. if((~sc->lmc_miireg16) & led){ /* Already on! */
  1598. lmc_trace(sc->lmc_device, "lmc_led_on aon out");
  1599. return;
  1600. }
  1601. sc->lmc_miireg16 &= ~led;
  1602. lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
  1603. lmc_trace(sc->lmc_device, "lmc_led_on out");
  1604. }
  1605. void lmc_led_off(lmc_softc_t * const sc, u_int32_t led) /*fold00*/
  1606. {
  1607. lmc_trace(sc->lmc_device, "lmc_led_off in");
  1608. if(sc->lmc_miireg16 & led){ /* Already set don't do anything */
  1609. lmc_trace(sc->lmc_device, "lmc_led_off aoff out");
  1610. return;
  1611. }
  1612. sc->lmc_miireg16 |= led;
  1613. lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
  1614. lmc_trace(sc->lmc_device, "lmc_led_off out");
  1615. }
  1616. static void lmc_reset(lmc_softc_t * const sc) /*fold00*/
  1617. {
  1618. lmc_trace(sc->lmc_device, "lmc_reset in");
  1619. sc->lmc_miireg16 |= LMC_MII16_FIFO_RESET;
  1620. lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
  1621. sc->lmc_miireg16 &= ~LMC_MII16_FIFO_RESET;
  1622. lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
  1623. /*
  1624. * make some of the GPIO pins be outputs
  1625. */
  1626. lmc_gpio_mkoutput(sc, LMC_GEP_RESET);
  1627. /*
  1628. * RESET low to force state reset. This also forces
  1629. * the transmitter clock to be internal, but we expect to reset
  1630. * that later anyway.
  1631. */
  1632. sc->lmc_gpio &= ~(LMC_GEP_RESET);
  1633. LMC_CSR_WRITE(sc, csr_gp, sc->lmc_gpio);
  1634. /*
  1635. * hold for more than 10 microseconds
  1636. */
  1637. udelay(50);
  1638. /*
  1639. * stop driving Xilinx-related signals
  1640. */
  1641. lmc_gpio_mkinput(sc, LMC_GEP_RESET);
  1642. /*
  1643. * Call media specific init routine
  1644. */
  1645. sc->lmc_media->init(sc);
  1646. sc->stats.resetCount++;
  1647. lmc_trace(sc->lmc_device, "lmc_reset out");
  1648. }
  1649. static void lmc_dec_reset(lmc_softc_t * const sc) /*fold00*/
  1650. {
  1651. u_int32_t val;
  1652. lmc_trace(sc->lmc_device, "lmc_dec_reset in");
  1653. /*
  1654. * disable all interrupts
  1655. */
  1656. sc->lmc_intrmask = 0;
  1657. LMC_CSR_WRITE(sc, csr_intr, sc->lmc_intrmask);
  1658. /*
  1659. * Reset the chip with a software reset command.
  1660. * Wait 10 microseconds (actually 50 PCI cycles but at
  1661. * 33MHz that comes to two microseconds but wait a
  1662. * bit longer anyways)
  1663. */
  1664. LMC_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
  1665. udelay(25);
  1666. #ifdef __sparc__
  1667. sc->lmc_busmode = LMC_CSR_READ(sc, csr_busmode);
  1668. sc->lmc_busmode = 0x00100000;
  1669. sc->lmc_busmode &= ~TULIP_BUSMODE_SWRESET;
  1670. LMC_CSR_WRITE(sc, csr_busmode, sc->lmc_busmode);
  1671. #endif
  1672. sc->lmc_cmdmode = LMC_CSR_READ(sc, csr_command);
  1673. /*
  1674. * We want:
  1675. * no ethernet address in frames we write
  1676. * disable padding (txdesc, padding disable)
  1677. * ignore runt frames (rdes0 bit 15)
  1678. * no receiver watchdog or transmitter jabber timer
  1679. * (csr15 bit 0,14 == 1)
  1680. * if using 16-bit CRC, turn off CRC (trans desc, crc disable)
  1681. */
  1682. sc->lmc_cmdmode |= ( TULIP_CMD_PROMISCUOUS
  1683. | TULIP_CMD_FULLDUPLEX
  1684. | TULIP_CMD_PASSBADPKT
  1685. | TULIP_CMD_NOHEARTBEAT
  1686. | TULIP_CMD_PORTSELECT
  1687. | TULIP_CMD_RECEIVEALL
  1688. | TULIP_CMD_MUSTBEONE
  1689. );
  1690. sc->lmc_cmdmode &= ~( TULIP_CMD_OPERMODE
  1691. | TULIP_CMD_THRESHOLDCTL
  1692. | TULIP_CMD_STOREFWD
  1693. | TULIP_CMD_TXTHRSHLDCTL
  1694. );
  1695. LMC_CSR_WRITE(sc, csr_command, sc->lmc_cmdmode);
  1696. /*
  1697. * disable receiver watchdog and transmit jabber
  1698. */
  1699. val = LMC_CSR_READ(sc, csr_sia_general);
  1700. val |= (TULIP_WATCHDOG_TXDISABLE | TULIP_WATCHDOG_RXDISABLE);
  1701. LMC_CSR_WRITE(sc, csr_sia_general, val);
  1702. lmc_trace(sc->lmc_device, "lmc_dec_reset out");
  1703. }
  1704. static void lmc_initcsrs(lmc_softc_t * const sc, lmc_csrptr_t csr_base, /*fold00*/
  1705. size_t csr_size)
  1706. {
  1707. lmc_trace(sc->lmc_device, "lmc_initcsrs in");
  1708. sc->lmc_csrs.csr_busmode = csr_base + 0 * csr_size;
  1709. sc->lmc_csrs.csr_txpoll = csr_base + 1 * csr_size;
  1710. sc->lmc_csrs.csr_rxpoll = csr_base + 2 * csr_size;
  1711. sc->lmc_csrs.csr_rxlist = csr_base + 3 * csr_size;
  1712. sc->lmc_csrs.csr_txlist = csr_base + 4 * csr_size;
  1713. sc->lmc_csrs.csr_status = csr_base + 5 * csr_size;
  1714. sc->lmc_csrs.csr_command = csr_base + 6 * csr_size;
  1715. sc->lmc_csrs.csr_intr = csr_base + 7 * csr_size;
  1716. sc->lmc_csrs.csr_missed_frames = csr_base + 8 * csr_size;
  1717. sc->lmc_csrs.csr_9 = csr_base + 9 * csr_size;
  1718. sc->lmc_csrs.csr_10 = csr_base + 10 * csr_size;
  1719. sc->lmc_csrs.csr_11 = csr_base + 11 * csr_size;
  1720. sc->lmc_csrs.csr_12 = csr_base + 12 * csr_size;
  1721. sc->lmc_csrs.csr_13 = csr_base + 13 * csr_size;
  1722. sc->lmc_csrs.csr_14 = csr_base + 14 * csr_size;
  1723. sc->lmc_csrs.csr_15 = csr_base + 15 * csr_size;
  1724. lmc_trace(sc->lmc_device, "lmc_initcsrs out");
  1725. }
  1726. static void lmc_driver_timeout(struct net_device *dev) { /*fold00*/
  1727. lmc_softc_t *sc;
  1728. u32 csr6;
  1729. unsigned long flags;
  1730. lmc_trace(dev, "lmc_driver_timeout in");
  1731. sc = dev->priv;
  1732. spin_lock_irqsave(&sc->lmc_lock, flags);
  1733. printk("%s: Xmitter busy|\n", dev->name);
  1734. sc->stats.tx_tbusy_calls++ ;
  1735. if (jiffies - dev->trans_start < TX_TIMEOUT) {
  1736. goto bug_out;
  1737. }
  1738. /*
  1739. * Chip seems to have locked up
  1740. * Reset it
  1741. * This whips out all our decriptor
  1742. * table and starts from scartch
  1743. */
  1744. LMC_EVENT_LOG(LMC_EVENT_XMTPRCTMO,
  1745. LMC_CSR_READ (sc, csr_status),
  1746. sc->stats.tx_ProcTimeout);
  1747. lmc_running_reset (dev);
  1748. LMC_EVENT_LOG(LMC_EVENT_RESET1, LMC_CSR_READ (sc, csr_status), 0);
  1749. LMC_EVENT_LOG(LMC_EVENT_RESET2,
  1750. lmc_mii_readreg (sc, 0, 16),
  1751. lmc_mii_readreg (sc, 0, 17));
  1752. /* restart the tx processes */
  1753. csr6 = LMC_CSR_READ (sc, csr_command);
  1754. LMC_CSR_WRITE (sc, csr_command, csr6 | 0x0002);
  1755. LMC_CSR_WRITE (sc, csr_command, csr6 | 0x2002);
  1756. /* immediate transmit */
  1757. LMC_CSR_WRITE (sc, csr_txpoll, 0);
  1758. sc->stats.tx_errors++;
  1759. sc->stats.tx_ProcTimeout++; /* -baz */
  1760. dev->trans_start = jiffies;
  1761. bug_out:
  1762. spin_unlock_irqrestore(&sc->lmc_lock, flags);
  1763. lmc_trace(dev, "lmc_driver_timout out");
  1764. }