3c359.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830
  1. /*
  2. * 3c359.c (c) 2000 Mike Phillips (mikep@linuxtr.net) All Rights Reserved
  3. *
  4. * Linux driver for 3Com 3c359 Tokenlink Velocity XL PCI NIC
  5. *
  6. * Base Driver Olympic:
  7. * Written 1999 Peter De Schrijver & Mike Phillips
  8. *
  9. * This software may be used and distributed according to the terms
  10. * of the GNU General Public License, incorporated herein by reference.
  11. *
  12. * 7/17/00 - Clean up, version number 0.9.0. Ready to release to the world.
  13. *
  14. * 2/16/01 - Port up to kernel 2.4.2 ready for submission into the kernel.
  15. * 3/05/01 - Last clean up stuff before submission.
  16. * 2/15/01 - Finally, update to new pci api.
  17. *
  18. * To Do:
  19. */
  20. /*
  21. * Technical Card Details
  22. *
  23. * All access to data is done with 16/8 bit transfers. The transfer
  24. * method really sucks. You can only read or write one location at a time.
  25. *
  26. * Also, the microcode for the card must be uploaded if the card does not have
  27. * the flashrom on board. This is a 28K bloat in the driver when compiled
  28. * as a module.
  29. *
  30. * Rx is very simple, status into a ring of descriptors, dma data transfer,
  31. * interrupts to tell us when a packet is received.
  32. *
  33. * Tx is a little more interesting. Similar scenario, descriptor and dma data
  34. * transfers, but we don't have to interrupt the card to tell it another packet
  35. * is ready for transmission, we are just doing simple memory writes, not io or mmio
  36. * writes. The card can be set up to simply poll on the next
  37. * descriptor pointer and when this value is non-zero will automatically download
  38. * the next packet. The card then interrupts us when the packet is done.
  39. *
  40. */
  41. #define XL_DEBUG 0
  42. #include <linux/module.h>
  43. #include <linux/kernel.h>
  44. #include <linux/errno.h>
  45. #include <linux/timer.h>
  46. #include <linux/in.h>
  47. #include <linux/ioport.h>
  48. #include <linux/string.h>
  49. #include <linux/proc_fs.h>
  50. #include <linux/ptrace.h>
  51. #include <linux/skbuff.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/delay.h>
  54. #include <linux/netdevice.h>
  55. #include <linux/trdevice.h>
  56. #include <linux/stddef.h>
  57. #include <linux/init.h>
  58. #include <linux/pci.h>
  59. #include <linux/spinlock.h>
  60. #include <linux/bitops.h>
  61. #include <net/checksum.h>
  62. #include <asm/io.h>
  63. #include <asm/system.h>
  64. #include "3c359.h"
  65. static char version[] __devinitdata =
  66. "3c359.c v1.2.0 2/17/01 - Mike Phillips (mikep@linuxtr.net)" ;
  67. MODULE_AUTHOR("Mike Phillips <mikep@linuxtr.net>") ;
  68. MODULE_DESCRIPTION("3Com 3C359 Velocity XL Token Ring Adapter Driver \n") ;
  69. /* Module paramters */
  70. /* Ring Speed 0,4,16
  71. * 0 = Autosense
  72. * 4,16 = Selected speed only, no autosense
  73. * This allows the card to be the first on the ring
  74. * and become the active monitor.
  75. *
  76. * WARNING: Some hubs will allow you to insert
  77. * at the wrong speed.
  78. *
  79. * The adapter will _not_ fail to open if there are no
  80. * active monitors on the ring, it will simply open up in
  81. * its last known ringspeed if no ringspeed is specified.
  82. */
  83. static int ringspeed[XL_MAX_ADAPTERS] = {0,} ;
  84. module_param_array(ringspeed, int, NULL, 0);
  85. MODULE_PARM_DESC(ringspeed,"3c359: Ringspeed selection - 4,16 or 0") ;
  86. /* Packet buffer size */
  87. static int pkt_buf_sz[XL_MAX_ADAPTERS] = {0,} ;
  88. module_param_array(pkt_buf_sz, int, NULL, 0) ;
  89. MODULE_PARM_DESC(pkt_buf_sz,"3c359: Initial buffer size") ;
  90. /* Message Level */
  91. static int message_level[XL_MAX_ADAPTERS] = {0,} ;
  92. module_param_array(message_level, int, NULL, 0) ;
  93. MODULE_PARM_DESC(message_level, "3c359: Level of reported messages \n") ;
  94. /*
  95. * This is a real nasty way of doing this, but otherwise you
  96. * will be stuck with 1555 lines of hex #'s in the code.
  97. */
  98. #include "3c359_microcode.h"
  99. static struct pci_device_id xl_pci_tbl[] =
  100. {
  101. {PCI_VENDOR_ID_3COM,PCI_DEVICE_ID_3COM_3C359, PCI_ANY_ID, PCI_ANY_ID, },
  102. { } /* terminate list */
  103. };
  104. MODULE_DEVICE_TABLE(pci,xl_pci_tbl) ;
  105. static int xl_init(struct net_device *dev);
  106. static int xl_open(struct net_device *dev);
  107. static int xl_open_hw(struct net_device *dev) ;
  108. static int xl_hw_reset(struct net_device *dev);
  109. static int xl_xmit(struct sk_buff *skb, struct net_device *dev);
  110. static void xl_dn_comp(struct net_device *dev);
  111. static int xl_close(struct net_device *dev);
  112. static void xl_set_rx_mode(struct net_device *dev);
  113. static irqreturn_t xl_interrupt(int irq, void *dev_id);
  114. static struct net_device_stats * xl_get_stats(struct net_device *dev);
  115. static int xl_set_mac_address(struct net_device *dev, void *addr) ;
  116. static void xl_arb_cmd(struct net_device *dev);
  117. static void xl_asb_cmd(struct net_device *dev) ;
  118. static void xl_srb_cmd(struct net_device *dev, int srb_cmd) ;
  119. static void xl_wait_misr_flags(struct net_device *dev) ;
  120. static int xl_change_mtu(struct net_device *dev, int mtu);
  121. static void xl_srb_bh(struct net_device *dev) ;
  122. static void xl_asb_bh(struct net_device *dev) ;
  123. static void xl_reset(struct net_device *dev) ;
  124. static void xl_freemem(struct net_device *dev) ;
  125. /* EEProm Access Functions */
  126. static u16 xl_ee_read(struct net_device *dev, int ee_addr) ;
  127. static void xl_ee_write(struct net_device *dev, int ee_addr, u16 ee_value) ;
  128. /* Debugging functions */
  129. #if XL_DEBUG
  130. static void print_tx_state(struct net_device *dev) ;
  131. static void print_rx_state(struct net_device *dev) ;
  132. static void print_tx_state(struct net_device *dev)
  133. {
  134. struct xl_private *xl_priv = (struct xl_private *)dev->priv ;
  135. struct xl_tx_desc *txd ;
  136. u8 __iomem *xl_mmio = xl_priv->xl_mmio ;
  137. int i ;
  138. printk("tx_ring_head: %d, tx_ring_tail: %d, free_ent: %d \n",xl_priv->tx_ring_head,
  139. xl_priv->tx_ring_tail, xl_priv->free_ring_entries) ;
  140. printk("Ring , Address , FSH , DnNextPtr, Buffer, Buffer_Len \n");
  141. for (i = 0; i < 16; i++) {
  142. txd = &(xl_priv->xl_tx_ring[i]) ;
  143. printk("%d, %08lx, %08x, %08x, %08x, %08x \n", i, virt_to_bus(txd),
  144. txd->framestartheader, txd->dnnextptr, txd->buffer, txd->buffer_length ) ;
  145. }
  146. printk("DNLISTPTR = %04x \n", readl(xl_mmio + MMIO_DNLISTPTR) );
  147. printk("DmaCtl = %04x \n", readl(xl_mmio + MMIO_DMA_CTRL) );
  148. printk("Queue status = %0x \n",netif_running(dev) ) ;
  149. }
  150. static void print_rx_state(struct net_device *dev)
  151. {
  152. struct xl_private *xl_priv = (struct xl_private *)dev->priv ;
  153. struct xl_rx_desc *rxd ;
  154. u8 __iomem *xl_mmio = xl_priv->xl_mmio ;
  155. int i ;
  156. printk("rx_ring_tail: %d \n", xl_priv->rx_ring_tail) ;
  157. printk("Ring , Address , FrameState , UPNextPtr, FragAddr, Frag_Len \n");
  158. for (i = 0; i < 16; i++) {
  159. /* rxd = (struct xl_rx_desc *)xl_priv->rx_ring_dma_addr + (i * sizeof(struct xl_rx_desc)) ; */
  160. rxd = &(xl_priv->xl_rx_ring[i]) ;
  161. printk("%d, %08lx, %08x, %08x, %08x, %08x \n", i, virt_to_bus(rxd),
  162. rxd->framestatus, rxd->upnextptr, rxd->upfragaddr, rxd->upfraglen ) ;
  163. }
  164. printk("UPLISTPTR = %04x \n", readl(xl_mmio + MMIO_UPLISTPTR) );
  165. printk("DmaCtl = %04x \n", readl(xl_mmio + MMIO_DMA_CTRL) );
  166. printk("Queue status = %0x \n",netif_running(dev) ) ;
  167. }
  168. #endif
  169. /*
  170. * Read values from the on-board EEProm. This looks very strange
  171. * but you have to wait for the EEProm to get/set the value before
  172. * passing/getting the next value from the nic. As with all requests
  173. * on this nic it has to be done in two stages, a) tell the nic which
  174. * memory address you want to access and b) pass/get the value from the nic.
  175. * With the EEProm, you have to wait before and inbetween access a) and b).
  176. * As this is only read at initialization time and the wait period is very
  177. * small we shouldn't have to worry about scheduling issues.
  178. */
  179. static u16 xl_ee_read(struct net_device *dev, int ee_addr)
  180. {
  181. struct xl_private *xl_priv = (struct xl_private *)dev->priv ;
  182. u8 __iomem *xl_mmio = xl_priv->xl_mmio ;
  183. /* Wait for EEProm to not be busy */
  184. writel(IO_WORD_READ | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  185. while ( readw(xl_mmio + MMIO_MACDATA) & EEBUSY ) ;
  186. /* Tell EEProm what we want to do and where */
  187. writel(IO_WORD_WRITE | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  188. writew(EEREAD + ee_addr, xl_mmio + MMIO_MACDATA) ;
  189. /* Wait for EEProm to not be busy */
  190. writel(IO_WORD_READ | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  191. while ( readw(xl_mmio + MMIO_MACDATA) & EEBUSY ) ;
  192. /* Tell EEProm what we want to do and where */
  193. writel(IO_WORD_WRITE | EECONTROL , xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  194. writew(EEREAD + ee_addr, xl_mmio + MMIO_MACDATA) ;
  195. /* Finally read the value from the EEProm */
  196. writel(IO_WORD_READ | EEDATA , xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  197. return readw(xl_mmio + MMIO_MACDATA) ;
  198. }
  199. /*
  200. * Write values to the onboard eeprom. As with eeprom read you need to
  201. * set which location to write, wait, value to write, wait, with the
  202. * added twist of having to enable eeprom writes as well.
  203. */
  204. static void xl_ee_write(struct net_device *dev, int ee_addr, u16 ee_value)
  205. {
  206. struct xl_private *xl_priv = (struct xl_private *)dev->priv ;
  207. u8 __iomem *xl_mmio = xl_priv->xl_mmio ;
  208. /* Wait for EEProm to not be busy */
  209. writel(IO_WORD_READ | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  210. while ( readw(xl_mmio + MMIO_MACDATA) & EEBUSY ) ;
  211. /* Enable write/erase */
  212. writel(IO_WORD_WRITE | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  213. writew(EE_ENABLE_WRITE, xl_mmio + MMIO_MACDATA) ;
  214. /* Wait for EEProm to not be busy */
  215. writel(IO_WORD_READ | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  216. while ( readw(xl_mmio + MMIO_MACDATA) & EEBUSY ) ;
  217. /* Put the value we want to write into EEDATA */
  218. writel(IO_WORD_WRITE | EEDATA, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  219. writew(ee_value, xl_mmio + MMIO_MACDATA) ;
  220. /* Tell EEProm to write eevalue into ee_addr */
  221. writel(IO_WORD_WRITE | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  222. writew(EEWRITE + ee_addr, xl_mmio + MMIO_MACDATA) ;
  223. /* Wait for EEProm to not be busy, to ensure write gets done */
  224. writel(IO_WORD_READ | EECONTROL, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  225. while ( readw(xl_mmio + MMIO_MACDATA) & EEBUSY ) ;
  226. return ;
  227. }
  228. static int __devinit xl_probe(struct pci_dev *pdev,
  229. const struct pci_device_id *ent)
  230. {
  231. struct net_device *dev ;
  232. struct xl_private *xl_priv ;
  233. static int card_no = -1 ;
  234. int i ;
  235. card_no++ ;
  236. if (pci_enable_device(pdev)) {
  237. return -ENODEV ;
  238. }
  239. pci_set_master(pdev);
  240. if ((i = pci_request_regions(pdev,"3c359"))) {
  241. return i ;
  242. } ;
  243. /*
  244. * Allowing init_trdev to allocate the dev->priv structure will align xl_private
  245. * on a 32 bytes boundary which we need for the rx/tx descriptors
  246. */
  247. dev = alloc_trdev(sizeof(struct xl_private)) ;
  248. if (!dev) {
  249. pci_release_regions(pdev) ;
  250. return -ENOMEM ;
  251. }
  252. xl_priv = dev->priv ;
  253. #if XL_DEBUG
  254. printk("pci_device: %p, dev:%p, dev->priv: %p, ba[0]: %10x, ba[1]:%10x\n",
  255. pdev, dev, dev->priv, (unsigned int)pdev->resource[0].start, (unsigned int)pdev->resource[1].start) ;
  256. #endif
  257. dev->irq=pdev->irq;
  258. dev->base_addr=pci_resource_start(pdev,0) ;
  259. xl_priv->xl_card_name = pci_name(pdev);
  260. xl_priv->xl_mmio=ioremap(pci_resource_start(pdev,1), XL_IO_SPACE);
  261. xl_priv->pdev = pdev ;
  262. if ((pkt_buf_sz[card_no] < 100) || (pkt_buf_sz[card_no] > 18000) )
  263. xl_priv->pkt_buf_sz = PKT_BUF_SZ ;
  264. else
  265. xl_priv->pkt_buf_sz = pkt_buf_sz[card_no] ;
  266. dev->mtu = xl_priv->pkt_buf_sz - TR_HLEN ;
  267. xl_priv->xl_ring_speed = ringspeed[card_no] ;
  268. xl_priv->xl_message_level = message_level[card_no] ;
  269. xl_priv->xl_functional_addr[0] = xl_priv->xl_functional_addr[1] = xl_priv->xl_functional_addr[2] = xl_priv->xl_functional_addr[3] = 0 ;
  270. xl_priv->xl_copy_all_options = 0 ;
  271. if((i = xl_init(dev))) {
  272. iounmap(xl_priv->xl_mmio) ;
  273. free_netdev(dev) ;
  274. pci_release_regions(pdev) ;
  275. return i ;
  276. }
  277. dev->open=&xl_open;
  278. dev->hard_start_xmit=&xl_xmit;
  279. dev->change_mtu=&xl_change_mtu;
  280. dev->stop=&xl_close;
  281. dev->do_ioctl=NULL;
  282. dev->set_multicast_list=&xl_set_rx_mode;
  283. dev->get_stats=&xl_get_stats ;
  284. dev->set_mac_address=&xl_set_mac_address ;
  285. SET_MODULE_OWNER(dev);
  286. SET_NETDEV_DEV(dev, &pdev->dev);
  287. pci_set_drvdata(pdev,dev) ;
  288. if ((i = register_netdev(dev))) {
  289. printk(KERN_ERR "3C359, register netdev failed\n") ;
  290. pci_set_drvdata(pdev,NULL) ;
  291. iounmap(xl_priv->xl_mmio) ;
  292. free_netdev(dev) ;
  293. pci_release_regions(pdev) ;
  294. return i ;
  295. }
  296. printk(KERN_INFO "3C359: %s registered as: %s\n",xl_priv->xl_card_name,dev->name) ;
  297. return 0;
  298. }
  299. static int __init xl_init(struct net_device *dev)
  300. {
  301. struct xl_private *xl_priv = (struct xl_private *)dev->priv ;
  302. printk(KERN_INFO "%s \n", version);
  303. printk(KERN_INFO "%s: I/O at %hx, MMIO at %p, using irq %d\n",
  304. xl_priv->xl_card_name, (unsigned int)dev->base_addr ,xl_priv->xl_mmio, dev->irq);
  305. spin_lock_init(&xl_priv->xl_lock) ;
  306. return xl_hw_reset(dev) ;
  307. }
  308. /*
  309. * Hardware reset. This needs to be a separate entity as we need to reset the card
  310. * when we change the EEProm settings.
  311. */
  312. static int xl_hw_reset(struct net_device *dev)
  313. {
  314. struct xl_private *xl_priv = (struct xl_private *)dev->priv ;
  315. u8 __iomem *xl_mmio = xl_priv->xl_mmio ;
  316. unsigned long t ;
  317. u16 i ;
  318. u16 result_16 ;
  319. u8 result_8 ;
  320. u16 start ;
  321. int j ;
  322. /*
  323. * Reset the card. If the card has got the microcode on board, we have
  324. * missed the initialization interrupt, so we must always do this.
  325. */
  326. writew( GLOBAL_RESET, xl_mmio + MMIO_COMMAND ) ;
  327. /*
  328. * Must wait for cmdInProgress bit (12) to clear before continuing with
  329. * card configuration.
  330. */
  331. t=jiffies;
  332. while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) {
  333. schedule();
  334. if(jiffies-t > 40*HZ) {
  335. printk(KERN_ERR "%s: 3COM 3C359 Velocity XL card not responding to global reset.\n", dev->name);
  336. return -ENODEV;
  337. }
  338. }
  339. /*
  340. * Enable pmbar by setting bit in CPAttention
  341. */
  342. writel( (IO_BYTE_READ | CPATTENTION), xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  343. result_8 = readb(xl_mmio + MMIO_MACDATA) ;
  344. result_8 = result_8 | CPA_PMBARVIS ;
  345. writel( (IO_BYTE_WRITE | CPATTENTION), xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  346. writeb(result_8, xl_mmio + MMIO_MACDATA) ;
  347. /*
  348. * Read cpHold bit in pmbar, if cleared we have got Flashrom on board.
  349. * If not, we need to upload the microcode to the card
  350. */
  351. writel( (IO_WORD_READ | PMBAR),xl_mmio + MMIO_MAC_ACCESS_CMD);
  352. #if XL_DEBUG
  353. printk(KERN_INFO "Read from PMBAR = %04x \n", readw(xl_mmio + MMIO_MACDATA)) ;
  354. #endif
  355. if ( readw( (xl_mmio + MMIO_MACDATA)) & PMB_CPHOLD ) {
  356. /* Set PmBar, privateMemoryBase bits (8:2) to 0 */
  357. writel( (IO_WORD_READ | PMBAR),xl_mmio + MMIO_MAC_ACCESS_CMD);
  358. result_16 = readw(xl_mmio + MMIO_MACDATA) ;
  359. result_16 = result_16 & ~((0x7F) << 2) ;
  360. writel( (IO_WORD_WRITE | PMBAR), xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  361. writew(result_16,xl_mmio + MMIO_MACDATA) ;
  362. /* Set CPAttention, memWrEn bit */
  363. writel( (IO_BYTE_READ | CPATTENTION), xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  364. result_8 = readb(xl_mmio + MMIO_MACDATA) ;
  365. result_8 = result_8 | CPA_MEMWREN ;
  366. writel( (IO_BYTE_WRITE | CPATTENTION), xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  367. writeb(result_8, xl_mmio + MMIO_MACDATA) ;
  368. /*
  369. * Now to write the microcode into the shared ram
  370. * The microcode must finish at position 0xFFFF, so we must subtract
  371. * to get the start position for the code
  372. */
  373. start = (0xFFFF - (mc_size) + 1 ) ; /* Looks strange but ensures compiler only uses 16 bit unsigned int for this */
  374. printk(KERN_INFO "3C359: Uploading Microcode: ");
  375. for (i = start, j = 0; j < mc_size; i++, j++) {
  376. writel(MEM_BYTE_WRITE | 0XD0000 | i, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  377. writeb(microcode[j],xl_mmio + MMIO_MACDATA) ;
  378. if (j % 1024 == 0)
  379. printk(".");
  380. }
  381. printk("\n") ;
  382. for (i=0;i < 16; i++) {
  383. writel( (MEM_BYTE_WRITE | 0xDFFF0) + i, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  384. writeb(microcode[mc_size - 16 + i], xl_mmio + MMIO_MACDATA) ;
  385. }
  386. /*
  387. * Have to write the start address of the upload to FFF4, but
  388. * the address must be >> 4. You do not want to know how long
  389. * it took me to discover this.
  390. */
  391. writel(MEM_WORD_WRITE | 0xDFFF4, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  392. writew(start >> 4, xl_mmio + MMIO_MACDATA);
  393. /* Clear the CPAttention, memWrEn Bit */
  394. writel( (IO_BYTE_READ | CPATTENTION), xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  395. result_8 = readb(xl_mmio + MMIO_MACDATA) ;
  396. result_8 = result_8 & ~CPA_MEMWREN ;
  397. writel( (IO_BYTE_WRITE | CPATTENTION), xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  398. writeb(result_8, xl_mmio + MMIO_MACDATA) ;
  399. /* Clear the cpHold bit in pmbar */
  400. writel( (IO_WORD_READ | PMBAR),xl_mmio + MMIO_MAC_ACCESS_CMD);
  401. result_16 = readw(xl_mmio + MMIO_MACDATA) ;
  402. result_16 = result_16 & ~PMB_CPHOLD ;
  403. writel( (IO_WORD_WRITE | PMBAR), xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  404. writew(result_16,xl_mmio + MMIO_MACDATA) ;
  405. } /* If microcode upload required */
  406. /*
  407. * The card should now go though a self test procedure and get itself ready
  408. * to be opened, we must wait for an srb response with the initialization
  409. * information.
  410. */
  411. #if XL_DEBUG
  412. printk(KERN_INFO "%s: Microcode uploaded, must wait for the self test to complete\n", dev->name);
  413. #endif
  414. writew(SETINDENABLE | 0xFFF, xl_mmio + MMIO_COMMAND) ;
  415. t=jiffies;
  416. while ( !(readw(xl_mmio + MMIO_INTSTATUS_AUTO) & INTSTAT_SRB) ) {
  417. schedule();
  418. if(jiffies-t > 15*HZ) {
  419. printk(KERN_ERR "3COM 3C359 Velocity XL card not responding.\n");
  420. return -ENODEV;
  421. }
  422. }
  423. /*
  424. * Write the RxBufArea with D000, RxEarlyThresh, TxStartThresh,
  425. * DnPriReqThresh, read the tech docs if you want to know what
  426. * values they need to be.
  427. */
  428. writel(MMIO_WORD_WRITE | RXBUFAREA, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  429. writew(0xD000, xl_mmio + MMIO_MACDATA) ;
  430. writel(MMIO_WORD_WRITE | RXEARLYTHRESH, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  431. writew(0X0020, xl_mmio + MMIO_MACDATA) ;
  432. writew( SETTXSTARTTHRESH | 0x40 , xl_mmio + MMIO_COMMAND) ;
  433. writeb(0x04, xl_mmio + MMIO_DNBURSTTHRESH) ;
  434. writeb(0x04, xl_mmio + DNPRIREQTHRESH) ;
  435. /*
  436. * Read WRBR to provide the location of the srb block, have to use byte reads not word reads.
  437. * Tech docs have this wrong !!!!
  438. */
  439. writel(MMIO_BYTE_READ | WRBR, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  440. xl_priv->srb = readb(xl_mmio + MMIO_MACDATA) << 8 ;
  441. writel( (MMIO_BYTE_READ | WRBR) + 1, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  442. xl_priv->srb = xl_priv->srb | readb(xl_mmio + MMIO_MACDATA) ;
  443. #if XL_DEBUG
  444. writel(IO_WORD_READ | SWITCHSETTINGS, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  445. if ( readw(xl_mmio + MMIO_MACDATA) & 2) {
  446. printk(KERN_INFO "Default ring speed 4 mbps \n") ;
  447. } else {
  448. printk(KERN_INFO "Default ring speed 16 mbps \n") ;
  449. }
  450. printk(KERN_INFO "%s: xl_priv->srb = %04x\n",xl_priv->xl_card_name, xl_priv->srb);
  451. #endif
  452. return 0;
  453. }
  454. static int xl_open(struct net_device *dev)
  455. {
  456. struct xl_private *xl_priv=(struct xl_private *)dev->priv;
  457. u8 __iomem *xl_mmio = xl_priv->xl_mmio ;
  458. u8 i ;
  459. u16 hwaddr[3] ; /* Should be u8[6] but we get word return values */
  460. int open_err ;
  461. u16 switchsettings, switchsettings_eeprom ;
  462. if(request_irq(dev->irq, &xl_interrupt, IRQF_SHARED , "3c359", dev)) {
  463. return -EAGAIN;
  464. }
  465. /*
  466. * Read the information from the EEPROM that we need. I know we
  467. * should use ntohs, but the word gets stored reversed in the 16
  468. * bit field anyway and it all works its self out when we memcpy
  469. * it into dev->dev_addr.
  470. */
  471. hwaddr[0] = xl_ee_read(dev,0x10) ;
  472. hwaddr[1] = xl_ee_read(dev,0x11) ;
  473. hwaddr[2] = xl_ee_read(dev,0x12) ;
  474. /* Ring speed */
  475. switchsettings_eeprom = xl_ee_read(dev,0x08) ;
  476. switchsettings = switchsettings_eeprom ;
  477. if (xl_priv->xl_ring_speed != 0) {
  478. if (xl_priv->xl_ring_speed == 4)
  479. switchsettings = switchsettings | 0x02 ;
  480. else
  481. switchsettings = switchsettings & ~0x02 ;
  482. }
  483. /* Only write EEProm if there has been a change */
  484. if (switchsettings != switchsettings_eeprom) {
  485. xl_ee_write(dev,0x08,switchsettings) ;
  486. /* Hardware reset after changing EEProm */
  487. xl_hw_reset(dev) ;
  488. }
  489. memcpy(dev->dev_addr,hwaddr,dev->addr_len) ;
  490. open_err = xl_open_hw(dev) ;
  491. /*
  492. * This really needs to be cleaned up with better error reporting.
  493. */
  494. if (open_err != 0) { /* Something went wrong with the open command */
  495. if (open_err & 0x07) { /* Wrong speed, retry at different speed */
  496. printk(KERN_WARNING "%s: Open Error, retrying at different ringspeed \n", dev->name) ;
  497. switchsettings = switchsettings ^ 2 ;
  498. xl_ee_write(dev,0x08,switchsettings) ;
  499. xl_hw_reset(dev) ;
  500. open_err = xl_open_hw(dev) ;
  501. if (open_err != 0) {
  502. printk(KERN_WARNING "%s: Open error returned a second time, we're bombing out now\n", dev->name);
  503. free_irq(dev->irq,dev) ;
  504. return -ENODEV ;
  505. }
  506. } else {
  507. printk(KERN_WARNING "%s: Open Error = %04x\n", dev->name, open_err) ;
  508. free_irq(dev->irq,dev) ;
  509. return -ENODEV ;
  510. }
  511. }
  512. /*
  513. * Now to set up the Rx and Tx buffer structures
  514. */
  515. /* These MUST be on 8 byte boundaries */
  516. xl_priv->xl_tx_ring = kmalloc((sizeof(struct xl_tx_desc) * XL_TX_RING_SIZE) + 7, GFP_DMA | GFP_KERNEL) ;
  517. if (xl_priv->xl_tx_ring == NULL) {
  518. printk(KERN_WARNING "%s: Not enough memory to allocate rx buffers.\n",
  519. dev->name);
  520. free_irq(dev->irq,dev);
  521. return -ENOMEM;
  522. }
  523. xl_priv->xl_rx_ring = kmalloc((sizeof(struct xl_rx_desc) * XL_RX_RING_SIZE) +7, GFP_DMA | GFP_KERNEL) ;
  524. if (xl_priv->xl_tx_ring == NULL) {
  525. printk(KERN_WARNING "%s: Not enough memory to allocate rx buffers.\n",
  526. dev->name);
  527. free_irq(dev->irq,dev);
  528. kfree(xl_priv->xl_tx_ring);
  529. return -ENOMEM;
  530. }
  531. memset(xl_priv->xl_tx_ring,0,sizeof(struct xl_tx_desc) * XL_TX_RING_SIZE) ;
  532. memset(xl_priv->xl_rx_ring,0,sizeof(struct xl_rx_desc) * XL_RX_RING_SIZE) ;
  533. /* Setup Rx Ring */
  534. for (i=0 ; i < XL_RX_RING_SIZE ; i++) {
  535. struct sk_buff *skb ;
  536. skb = dev_alloc_skb(xl_priv->pkt_buf_sz) ;
  537. if (skb==NULL)
  538. break ;
  539. skb->dev = dev ;
  540. xl_priv->xl_rx_ring[i].upfragaddr = pci_map_single(xl_priv->pdev, skb->data,xl_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE) ;
  541. xl_priv->xl_rx_ring[i].upfraglen = xl_priv->pkt_buf_sz | RXUPLASTFRAG;
  542. xl_priv->rx_ring_skb[i] = skb ;
  543. }
  544. if (i==0) {
  545. printk(KERN_WARNING "%s: Not enough memory to allocate rx buffers. Adapter disabled \n",dev->name) ;
  546. free_irq(dev->irq,dev) ;
  547. return -EIO ;
  548. }
  549. xl_priv->rx_ring_no = i ;
  550. xl_priv->rx_ring_tail = 0 ;
  551. xl_priv->rx_ring_dma_addr = pci_map_single(xl_priv->pdev,xl_priv->xl_rx_ring, sizeof(struct xl_rx_desc) * XL_RX_RING_SIZE, PCI_DMA_TODEVICE) ;
  552. for (i=0;i<(xl_priv->rx_ring_no-1);i++) {
  553. xl_priv->xl_rx_ring[i].upnextptr = xl_priv->rx_ring_dma_addr + (sizeof (struct xl_rx_desc) * (i+1)) ;
  554. }
  555. xl_priv->xl_rx_ring[i].upnextptr = 0 ;
  556. writel(xl_priv->rx_ring_dma_addr, xl_mmio + MMIO_UPLISTPTR) ;
  557. /* Setup Tx Ring */
  558. xl_priv->tx_ring_dma_addr = pci_map_single(xl_priv->pdev,xl_priv->xl_tx_ring, sizeof(struct xl_tx_desc) * XL_TX_RING_SIZE,PCI_DMA_TODEVICE) ;
  559. xl_priv->tx_ring_head = 1 ;
  560. xl_priv->tx_ring_tail = 255 ; /* Special marker for first packet */
  561. xl_priv->free_ring_entries = XL_TX_RING_SIZE ;
  562. /*
  563. * Setup the first dummy DPD entry for polling to start working.
  564. */
  565. xl_priv->xl_tx_ring[0].framestartheader = TXDPDEMPTY ;
  566. xl_priv->xl_tx_ring[0].buffer = 0 ;
  567. xl_priv->xl_tx_ring[0].buffer_length = 0 ;
  568. xl_priv->xl_tx_ring[0].dnnextptr = 0 ;
  569. writel(xl_priv->tx_ring_dma_addr, xl_mmio + MMIO_DNLISTPTR) ;
  570. writel(DNUNSTALL, xl_mmio + MMIO_COMMAND) ;
  571. writel(UPUNSTALL, xl_mmio + MMIO_COMMAND) ;
  572. writel(DNENABLE, xl_mmio + MMIO_COMMAND) ;
  573. writeb(0x40, xl_mmio + MMIO_DNPOLL) ;
  574. /*
  575. * Enable interrupts on the card
  576. */
  577. writel(SETINTENABLE | INT_MASK, xl_mmio + MMIO_COMMAND) ;
  578. writel(SETINDENABLE | INT_MASK, xl_mmio + MMIO_COMMAND) ;
  579. netif_start_queue(dev) ;
  580. return 0;
  581. }
  582. static int xl_open_hw(struct net_device *dev)
  583. {
  584. struct xl_private *xl_priv=(struct xl_private *)dev->priv;
  585. u8 __iomem *xl_mmio = xl_priv->xl_mmio ;
  586. u16 vsoff ;
  587. char ver_str[33];
  588. int open_err ;
  589. int i ;
  590. unsigned long t ;
  591. /*
  592. * Okay, let's build up the Open.NIC srb command
  593. *
  594. */
  595. writel( (MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb), xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  596. writeb(OPEN_NIC, xl_mmio + MMIO_MACDATA) ;
  597. /*
  598. * Use this as a test byte, if it comes back with the same value, the command didn't work
  599. */
  600. writel( (MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb)+ 2, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  601. writeb(0xff,xl_mmio + MMIO_MACDATA) ;
  602. /* Open options */
  603. writel( (MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb) + 8, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  604. writeb(0x00, xl_mmio + MMIO_MACDATA) ;
  605. writel( (MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb) + 9, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  606. writeb(0x00, xl_mmio + MMIO_MACDATA) ;
  607. /*
  608. * Node address, be careful here, the docs say you can just put zeros here and it will use
  609. * the hardware address, it doesn't, you must include the node address in the open command.
  610. */
  611. if (xl_priv->xl_laa[0]) { /* If using a LAA address */
  612. for (i=10;i<16;i++) {
  613. writel( (MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb) + i, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  614. writeb(xl_priv->xl_laa[i],xl_mmio + MMIO_MACDATA) ;
  615. }
  616. memcpy(dev->dev_addr,xl_priv->xl_laa,dev->addr_len) ;
  617. } else { /* Regular hardware address */
  618. for (i=10;i<16;i++) {
  619. writel( (MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb) + i, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  620. writeb(dev->dev_addr[i-10], xl_mmio + MMIO_MACDATA) ;
  621. }
  622. }
  623. /* Default everything else to 0 */
  624. for (i = 16; i < 34; i++) {
  625. writel( (MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb) + i, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  626. writeb(0x00,xl_mmio + MMIO_MACDATA) ;
  627. }
  628. /*
  629. * Set the csrb bit in the MISR register
  630. */
  631. xl_wait_misr_flags(dev) ;
  632. writel(MEM_BYTE_WRITE | MF_CSRB, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  633. writeb(0xFF, xl_mmio + MMIO_MACDATA) ;
  634. writel(MMIO_BYTE_WRITE | MISR_SET, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  635. writeb(MISR_CSRB , xl_mmio + MMIO_MACDATA) ;
  636. /*
  637. * Now wait for the command to run
  638. */
  639. t=jiffies;
  640. while (! (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_SRB)) {
  641. schedule();
  642. if(jiffies-t > 40*HZ) {
  643. printk(KERN_ERR "3COM 3C359 Velocity XL card not responding.\n");
  644. break ;
  645. }
  646. }
  647. /*
  648. * Let's interpret the open response
  649. */
  650. writel( (MEM_BYTE_READ | 0xD0000 | xl_priv->srb)+2, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  651. if (readb(xl_mmio + MMIO_MACDATA)!=0) {
  652. open_err = readb(xl_mmio + MMIO_MACDATA) << 8 ;
  653. writel( (MEM_BYTE_READ | 0xD0000 | xl_priv->srb) + 7, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  654. open_err |= readb(xl_mmio + MMIO_MACDATA) ;
  655. return open_err ;
  656. } else {
  657. writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 8, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  658. xl_priv->asb = ntohs(readw(xl_mmio + MMIO_MACDATA)) ;
  659. printk(KERN_INFO "%s: Adapter Opened Details: ",dev->name) ;
  660. printk("ASB: %04x",xl_priv->asb ) ;
  661. writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 10, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  662. printk(", SRB: %04x",ntohs(readw(xl_mmio + MMIO_MACDATA)) ) ;
  663. writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 12, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  664. xl_priv->arb = ntohs(readw(xl_mmio + MMIO_MACDATA)) ;
  665. printk(", ARB: %04x \n",xl_priv->arb ) ;
  666. writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 14, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  667. vsoff = ntohs(readw(xl_mmio + MMIO_MACDATA)) ;
  668. /*
  669. * Interesting, sending the individual characters directly to printk was causing klogd to use
  670. * use 100% of processor time, so we build up the string and print that instead.
  671. */
  672. for (i=0;i<0x20;i++) {
  673. writel( (MEM_BYTE_READ | 0xD0000 | vsoff) + i, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  674. ver_str[i] = readb(xl_mmio + MMIO_MACDATA) ;
  675. }
  676. ver_str[i] = '\0' ;
  677. printk(KERN_INFO "%s: Microcode version String: %s \n",dev->name,ver_str);
  678. }
  679. /*
  680. * Issue the AckInterrupt
  681. */
  682. writew(ACK_INTERRUPT | SRBRACK | LATCH_ACK, xl_mmio + MMIO_COMMAND) ;
  683. return 0 ;
  684. }
  685. /*
  686. * There are two ways of implementing rx on the 359 NIC, either
  687. * interrupt driven or polling. We are going to uses interrupts,
  688. * it is the easier way of doing things.
  689. *
  690. * The Rx works with a ring of Rx descriptors. At initialise time the ring
  691. * entries point to the next entry except for the last entry in the ring
  692. * which points to 0. The card is programmed with the location of the first
  693. * available descriptor and keeps reading the next_ptr until next_ptr is set
  694. * to 0. Hopefully with a ring size of 16 the card will never get to read a next_ptr
  695. * of 0. As the Rx interrupt is received we copy the frame up to the protocol layers
  696. * and then point the end of the ring to our current position and point our current
  697. * position to 0, therefore making the current position the last position on the ring.
  698. * The last position on the ring therefore loops continually loops around the rx ring.
  699. *
  700. * rx_ring_tail is the position on the ring to process next. (Think of a snake, the head
  701. * expands as the card adds new packets and we go around eating the tail processing the
  702. * packets.)
  703. *
  704. * Undoubtably it could be streamlined and improved upon, but at the moment it works
  705. * and the fast path through the routine is fine.
  706. *
  707. * adv_rx_ring could be inlined to increase performance, but its called a *lot* of times
  708. * in xl_rx so would increase the size of the function significantly.
  709. */
  710. static void adv_rx_ring(struct net_device *dev) /* Advance rx_ring, cut down on bloat in xl_rx */
  711. {
  712. struct xl_private *xl_priv=(struct xl_private *)dev->priv;
  713. int prev_ring_loc ;
  714. prev_ring_loc = (xl_priv->rx_ring_tail + XL_RX_RING_SIZE - 1) & (XL_RX_RING_SIZE - 1);
  715. xl_priv->xl_rx_ring[prev_ring_loc].upnextptr = xl_priv->rx_ring_dma_addr + (sizeof (struct xl_rx_desc) * xl_priv->rx_ring_tail) ;
  716. xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].framestatus = 0 ;
  717. xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upnextptr = 0 ;
  718. xl_priv->rx_ring_tail++ ;
  719. xl_priv->rx_ring_tail &= (XL_RX_RING_SIZE-1) ;
  720. return ;
  721. }
  722. static void xl_rx(struct net_device *dev)
  723. {
  724. struct xl_private *xl_priv=(struct xl_private *)dev->priv;
  725. u8 __iomem * xl_mmio = xl_priv->xl_mmio ;
  726. struct sk_buff *skb, *skb2 ;
  727. int frame_length = 0, copy_len = 0 ;
  728. int temp_ring_loc ;
  729. /*
  730. * Receive the next frame, loop around the ring until all frames
  731. * have been received.
  732. */
  733. while (xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].framestatus & (RXUPDCOMPLETE | RXUPDFULL) ) { /* Descriptor to process */
  734. if (xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].framestatus & RXUPDFULL ) { /* UpdFull, Multiple Descriptors used for the frame */
  735. /*
  736. * This is a pain, you need to go through all the descriptors until the last one
  737. * for this frame to find the framelength
  738. */
  739. temp_ring_loc = xl_priv->rx_ring_tail ;
  740. while (xl_priv->xl_rx_ring[temp_ring_loc].framestatus & RXUPDFULL ) {
  741. temp_ring_loc++ ;
  742. temp_ring_loc &= (XL_RX_RING_SIZE-1) ;
  743. }
  744. frame_length = xl_priv->xl_rx_ring[temp_ring_loc].framestatus & 0x7FFF ;
  745. skb = dev_alloc_skb(frame_length) ;
  746. if (skb==NULL) { /* No memory for frame, still need to roll forward the rx ring */
  747. printk(KERN_WARNING "%s: dev_alloc_skb failed - multi buffer !\n", dev->name) ;
  748. while (xl_priv->rx_ring_tail != temp_ring_loc)
  749. adv_rx_ring(dev) ;
  750. adv_rx_ring(dev) ; /* One more time just for luck :) */
  751. xl_priv->xl_stats.rx_dropped++ ;
  752. writel(ACK_INTERRUPT | UPCOMPACK | LATCH_ACK , xl_mmio + MMIO_COMMAND) ;
  753. return ;
  754. }
  755. skb->dev = dev ;
  756. while (xl_priv->rx_ring_tail != temp_ring_loc) {
  757. copy_len = xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfraglen & 0x7FFF ;
  758. frame_length -= copy_len ;
  759. pci_dma_sync_single_for_cpu(xl_priv->pdev,xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr,xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ;
  760. memcpy(skb_put(skb,copy_len), xl_priv->rx_ring_skb[xl_priv->rx_ring_tail]->data, copy_len) ;
  761. pci_dma_sync_single_for_device(xl_priv->pdev,xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr,xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ;
  762. adv_rx_ring(dev) ;
  763. }
  764. /* Now we have found the last fragment */
  765. pci_dma_sync_single_for_cpu(xl_priv->pdev,xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr,xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ;
  766. memcpy(skb_put(skb,copy_len), xl_priv->rx_ring_skb[xl_priv->rx_ring_tail]->data, frame_length) ;
  767. /* memcpy(skb_put(skb,frame_length), bus_to_virt(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr), frame_length) ; */
  768. pci_dma_sync_single_for_device(xl_priv->pdev,xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr,xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ;
  769. adv_rx_ring(dev) ;
  770. skb->protocol = tr_type_trans(skb,dev) ;
  771. netif_rx(skb) ;
  772. } else { /* Single Descriptor Used, simply swap buffers over, fast path */
  773. frame_length = xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].framestatus & 0x7FFF ;
  774. skb = dev_alloc_skb(xl_priv->pkt_buf_sz) ;
  775. if (skb==NULL) { /* Still need to fix the rx ring */
  776. printk(KERN_WARNING "%s: dev_alloc_skb failed in rx, single buffer \n",dev->name) ;
  777. adv_rx_ring(dev) ;
  778. xl_priv->xl_stats.rx_dropped++ ;
  779. writel(ACK_INTERRUPT | UPCOMPACK | LATCH_ACK , xl_mmio + MMIO_COMMAND) ;
  780. return ;
  781. }
  782. skb->dev = dev ;
  783. skb2 = xl_priv->rx_ring_skb[xl_priv->rx_ring_tail] ;
  784. pci_unmap_single(xl_priv->pdev, xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr, xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ;
  785. skb_put(skb2, frame_length) ;
  786. skb2->protocol = tr_type_trans(skb2,dev) ;
  787. xl_priv->rx_ring_skb[xl_priv->rx_ring_tail] = skb ;
  788. xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr = pci_map_single(xl_priv->pdev,skb->data,xl_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE) ;
  789. xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfraglen = xl_priv->pkt_buf_sz | RXUPLASTFRAG ;
  790. adv_rx_ring(dev) ;
  791. xl_priv->xl_stats.rx_packets++ ;
  792. xl_priv->xl_stats.rx_bytes += frame_length ;
  793. netif_rx(skb2) ;
  794. } /* if multiple buffers */
  795. dev->last_rx = jiffies ;
  796. } /* while packet to do */
  797. /* Clear the updComplete interrupt */
  798. writel(ACK_INTERRUPT | UPCOMPACK | LATCH_ACK , xl_mmio + MMIO_COMMAND) ;
  799. return ;
  800. }
  801. /*
  802. * This is ruthless, it doesn't care what state the card is in it will
  803. * completely reset the adapter.
  804. */
  805. static void xl_reset(struct net_device *dev)
  806. {
  807. struct xl_private *xl_priv=(struct xl_private *)dev->priv;
  808. u8 __iomem * xl_mmio = xl_priv->xl_mmio ;
  809. unsigned long t;
  810. writew( GLOBAL_RESET, xl_mmio + MMIO_COMMAND ) ;
  811. /*
  812. * Must wait for cmdInProgress bit (12) to clear before continuing with
  813. * card configuration.
  814. */
  815. t=jiffies;
  816. while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) {
  817. if(jiffies-t > 40*HZ) {
  818. printk(KERN_ERR "3COM 3C359 Velocity XL card not responding.\n");
  819. break ;
  820. }
  821. }
  822. }
  823. static void xl_freemem(struct net_device *dev)
  824. {
  825. struct xl_private *xl_priv=(struct xl_private *)dev->priv ;
  826. int i ;
  827. for (i=0;i<XL_RX_RING_SIZE;i++) {
  828. dev_kfree_skb_irq(xl_priv->rx_ring_skb[xl_priv->rx_ring_tail]) ;
  829. pci_unmap_single(xl_priv->pdev,xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr,xl_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE) ;
  830. xl_priv->rx_ring_tail++ ;
  831. xl_priv->rx_ring_tail &= XL_RX_RING_SIZE-1;
  832. }
  833. /* unmap ring */
  834. pci_unmap_single(xl_priv->pdev,xl_priv->rx_ring_dma_addr, sizeof(struct xl_rx_desc) * XL_RX_RING_SIZE, PCI_DMA_FROMDEVICE) ;
  835. pci_unmap_single(xl_priv->pdev,xl_priv->tx_ring_dma_addr, sizeof(struct xl_tx_desc) * XL_TX_RING_SIZE, PCI_DMA_TODEVICE) ;
  836. kfree(xl_priv->xl_rx_ring) ;
  837. kfree(xl_priv->xl_tx_ring) ;
  838. return ;
  839. }
  840. static irqreturn_t xl_interrupt(int irq, void *dev_id)
  841. {
  842. struct net_device *dev = (struct net_device *)dev_id;
  843. struct xl_private *xl_priv =(struct xl_private *)dev->priv;
  844. u8 __iomem * xl_mmio = xl_priv->xl_mmio ;
  845. u16 intstatus, macstatus ;
  846. if (!dev) {
  847. printk(KERN_WARNING "Device structure dead, aaahhhh !\n") ;
  848. return IRQ_NONE;
  849. }
  850. intstatus = readw(xl_mmio + MMIO_INTSTATUS) ;
  851. if (!(intstatus & 1)) /* We didn't generate the interrupt */
  852. return IRQ_NONE;
  853. spin_lock(&xl_priv->xl_lock) ;
  854. /*
  855. * Process the interrupt
  856. */
  857. /*
  858. * Something fishy going on here, we shouldn't get 0001 ints, not fatal though.
  859. */
  860. if (intstatus == 0x0001) {
  861. writel(ACK_INTERRUPT | LATCH_ACK, xl_mmio + MMIO_COMMAND) ;
  862. printk(KERN_INFO "%s: 00001 int received \n",dev->name) ;
  863. } else {
  864. if (intstatus & (HOSTERRINT | SRBRINT | ARBCINT | UPCOMPINT | DNCOMPINT | HARDERRINT | (1<<8) | TXUNDERRUN | ASBFINT)) {
  865. /*
  866. * Host Error.
  867. * It may be possible to recover from this, but usually it means something
  868. * is seriously fubar, so we just close the adapter.
  869. */
  870. if (intstatus & HOSTERRINT) {
  871. printk(KERN_WARNING "%s: Host Error, performing global reset, intstatus = %04x \n",dev->name,intstatus) ;
  872. writew( GLOBAL_RESET, xl_mmio + MMIO_COMMAND ) ;
  873. printk(KERN_WARNING "%s: Resetting hardware: \n", dev->name);
  874. netif_stop_queue(dev) ;
  875. xl_freemem(dev) ;
  876. free_irq(dev->irq,dev);
  877. xl_reset(dev) ;
  878. writel(ACK_INTERRUPT | LATCH_ACK, xl_mmio + MMIO_COMMAND) ;
  879. spin_unlock(&xl_priv->xl_lock) ;
  880. return IRQ_HANDLED;
  881. } /* Host Error */
  882. if (intstatus & SRBRINT ) { /* Srbc interrupt */
  883. writel(ACK_INTERRUPT | SRBRACK | LATCH_ACK, xl_mmio + MMIO_COMMAND) ;
  884. if (xl_priv->srb_queued)
  885. xl_srb_bh(dev) ;
  886. } /* SRBR Interrupt */
  887. if (intstatus & TXUNDERRUN) { /* Issue DnReset command */
  888. writel(DNRESET, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  889. while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) { /* Wait for command to run */
  890. /* !!! FIX-ME !!!!
  891. Must put a timeout check here ! */
  892. /* Empty Loop */
  893. }
  894. printk(KERN_WARNING "%s: TX Underrun received \n",dev->name) ;
  895. writel(ACK_INTERRUPT | LATCH_ACK, xl_mmio + MMIO_COMMAND) ;
  896. } /* TxUnderRun */
  897. if (intstatus & ARBCINT ) { /* Arbc interrupt */
  898. xl_arb_cmd(dev) ;
  899. } /* Arbc */
  900. if (intstatus & ASBFINT) {
  901. if (xl_priv->asb_queued == 1) {
  902. xl_asb_cmd(dev) ;
  903. } else if (xl_priv->asb_queued == 2) {
  904. xl_asb_bh(dev) ;
  905. } else {
  906. writel(ACK_INTERRUPT | LATCH_ACK | ASBFACK, xl_mmio + MMIO_COMMAND) ;
  907. }
  908. } /* Asbf */
  909. if (intstatus & UPCOMPINT ) /* UpComplete */
  910. xl_rx(dev) ;
  911. if (intstatus & DNCOMPINT ) /* DnComplete */
  912. xl_dn_comp(dev) ;
  913. if (intstatus & HARDERRINT ) { /* Hardware error */
  914. writel(MMIO_WORD_READ | MACSTATUS, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  915. macstatus = readw(xl_mmio + MMIO_MACDATA) ;
  916. printk(KERN_WARNING "%s: MacStatusError, details: ", dev->name);
  917. if (macstatus & (1<<14))
  918. printk(KERN_WARNING "tchk error: Unrecoverable error \n") ;
  919. if (macstatus & (1<<3))
  920. printk(KERN_WARNING "eint error: Internal watchdog timer expired \n") ;
  921. if (macstatus & (1<<2))
  922. printk(KERN_WARNING "aint error: Host tried to perform invalid operation \n") ;
  923. printk(KERN_WARNING "Instatus = %02x, macstatus = %02x\n",intstatus,macstatus) ;
  924. printk(KERN_WARNING "%s: Resetting hardware: \n", dev->name);
  925. netif_stop_queue(dev) ;
  926. xl_freemem(dev) ;
  927. free_irq(dev->irq,dev);
  928. unregister_netdev(dev) ;
  929. free_netdev(dev) ;
  930. xl_reset(dev) ;
  931. writel(ACK_INTERRUPT | LATCH_ACK, xl_mmio + MMIO_COMMAND) ;
  932. spin_unlock(&xl_priv->xl_lock) ;
  933. return IRQ_HANDLED;
  934. }
  935. } else {
  936. printk(KERN_WARNING "%s: Received Unknown interrupt : %04x \n", dev->name, intstatus) ;
  937. writel(ACK_INTERRUPT | LATCH_ACK, xl_mmio + MMIO_COMMAND) ;
  938. }
  939. }
  940. /* Turn interrupts back on */
  941. writel( SETINDENABLE | INT_MASK, xl_mmio + MMIO_COMMAND) ;
  942. writel( SETINTENABLE | INT_MASK, xl_mmio + MMIO_COMMAND) ;
  943. spin_unlock(&xl_priv->xl_lock) ;
  944. return IRQ_HANDLED;
  945. }
  946. /*
  947. * Tx - Polling configuration
  948. */
  949. static int xl_xmit(struct sk_buff *skb, struct net_device *dev)
  950. {
  951. struct xl_private *xl_priv=(struct xl_private *)dev->priv;
  952. struct xl_tx_desc *txd ;
  953. int tx_head, tx_tail, tx_prev ;
  954. unsigned long flags ;
  955. spin_lock_irqsave(&xl_priv->xl_lock,flags) ;
  956. netif_stop_queue(dev) ;
  957. if (xl_priv->free_ring_entries > 1 ) {
  958. /*
  959. * Set up the descriptor for the packet
  960. */
  961. tx_head = xl_priv->tx_ring_head ;
  962. tx_tail = xl_priv->tx_ring_tail ;
  963. txd = &(xl_priv->xl_tx_ring[tx_head]) ;
  964. txd->dnnextptr = 0 ;
  965. txd->framestartheader = skb->len | TXDNINDICATE ;
  966. txd->buffer = pci_map_single(xl_priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE) ;
  967. txd->buffer_length = skb->len | TXDNFRAGLAST ;
  968. xl_priv->tx_ring_skb[tx_head] = skb ;
  969. xl_priv->xl_stats.tx_packets++ ;
  970. xl_priv->xl_stats.tx_bytes += skb->len ;
  971. /*
  972. * Set the nextptr of the previous descriptor equal to this descriptor, add XL_TX_RING_SIZE -1
  973. * to ensure no negative numbers in unsigned locations.
  974. */
  975. tx_prev = (xl_priv->tx_ring_head + XL_TX_RING_SIZE - 1) & (XL_TX_RING_SIZE - 1) ;
  976. xl_priv->tx_ring_head++ ;
  977. xl_priv->tx_ring_head &= (XL_TX_RING_SIZE - 1) ;
  978. xl_priv->free_ring_entries-- ;
  979. xl_priv->xl_tx_ring[tx_prev].dnnextptr = xl_priv->tx_ring_dma_addr + (sizeof (struct xl_tx_desc) * tx_head) ;
  980. /* Sneaky, by doing a read on DnListPtr we can force the card to poll on the DnNextPtr */
  981. /* readl(xl_mmio + MMIO_DNLISTPTR) ; */
  982. netif_wake_queue(dev) ;
  983. spin_unlock_irqrestore(&xl_priv->xl_lock,flags) ;
  984. return 0;
  985. } else {
  986. spin_unlock_irqrestore(&xl_priv->xl_lock,flags) ;
  987. return 1;
  988. }
  989. }
  990. /*
  991. * The NIC has told us that a packet has been downloaded onto the card, we must
  992. * find out which packet it has done, clear the skb and information for the packet
  993. * then advance around the ring for all tranmitted packets
  994. */
  995. static void xl_dn_comp(struct net_device *dev)
  996. {
  997. struct xl_private *xl_priv=(struct xl_private *)dev->priv;
  998. u8 __iomem * xl_mmio = xl_priv->xl_mmio ;
  999. struct xl_tx_desc *txd ;
  1000. if (xl_priv->tx_ring_tail == 255) {/* First time */
  1001. xl_priv->xl_tx_ring[0].framestartheader = 0 ;
  1002. xl_priv->xl_tx_ring[0].dnnextptr = 0 ;
  1003. xl_priv->tx_ring_tail = 1 ;
  1004. }
  1005. while (xl_priv->xl_tx_ring[xl_priv->tx_ring_tail].framestartheader & TXDNCOMPLETE ) {
  1006. txd = &(xl_priv->xl_tx_ring[xl_priv->tx_ring_tail]) ;
  1007. pci_unmap_single(xl_priv->pdev,txd->buffer, xl_priv->tx_ring_skb[xl_priv->tx_ring_tail]->len, PCI_DMA_TODEVICE) ;
  1008. txd->framestartheader = 0 ;
  1009. txd->buffer = 0xdeadbeef ;
  1010. txd->buffer_length = 0 ;
  1011. dev_kfree_skb_irq(xl_priv->tx_ring_skb[xl_priv->tx_ring_tail]) ;
  1012. xl_priv->tx_ring_tail++ ;
  1013. xl_priv->tx_ring_tail &= (XL_TX_RING_SIZE - 1) ;
  1014. xl_priv->free_ring_entries++ ;
  1015. }
  1016. netif_wake_queue(dev) ;
  1017. writel(ACK_INTERRUPT | DNCOMPACK | LATCH_ACK , xl_mmio + MMIO_COMMAND) ;
  1018. }
  1019. /*
  1020. * Close the adapter properly.
  1021. * This srb reply cannot be handled from interrupt context as we have
  1022. * to free the interrupt from the driver.
  1023. */
  1024. static int xl_close(struct net_device *dev)
  1025. {
  1026. struct xl_private *xl_priv = (struct xl_private *) dev->priv ;
  1027. u8 __iomem * xl_mmio = xl_priv->xl_mmio ;
  1028. unsigned long t ;
  1029. netif_stop_queue(dev) ;
  1030. /*
  1031. * Close the adapter, need to stall the rx and tx queues.
  1032. */
  1033. writew(DNSTALL, xl_mmio + MMIO_COMMAND) ;
  1034. t=jiffies;
  1035. while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) {
  1036. schedule();
  1037. if(jiffies-t > 10*HZ) {
  1038. printk(KERN_ERR "%s: 3COM 3C359 Velocity XL-DNSTALL not responding.\n", dev->name);
  1039. break ;
  1040. }
  1041. }
  1042. writew(DNDISABLE, xl_mmio + MMIO_COMMAND) ;
  1043. t=jiffies;
  1044. while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) {
  1045. schedule();
  1046. if(jiffies-t > 10*HZ) {
  1047. printk(KERN_ERR "%s: 3COM 3C359 Velocity XL-DNDISABLE not responding.\n", dev->name);
  1048. break ;
  1049. }
  1050. }
  1051. writew(UPSTALL, xl_mmio + MMIO_COMMAND) ;
  1052. t=jiffies;
  1053. while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) {
  1054. schedule();
  1055. if(jiffies-t > 10*HZ) {
  1056. printk(KERN_ERR "%s: 3COM 3C359 Velocity XL-UPSTALL not responding.\n", dev->name);
  1057. break ;
  1058. }
  1059. }
  1060. /* Turn off interrupts, we will still get the indication though
  1061. * so we can trap it
  1062. */
  1063. writel(SETINTENABLE, xl_mmio + MMIO_COMMAND) ;
  1064. xl_srb_cmd(dev,CLOSE_NIC) ;
  1065. t=jiffies;
  1066. while (!(readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_SRB)) {
  1067. schedule();
  1068. if(jiffies-t > 10*HZ) {
  1069. printk(KERN_ERR "%s: 3COM 3C359 Velocity XL-CLOSENIC not responding.\n", dev->name);
  1070. break ;
  1071. }
  1072. }
  1073. /* Read the srb response from the adapter */
  1074. writel(MEM_BYTE_READ | 0xd0000 | xl_priv->srb, xl_mmio + MMIO_MAC_ACCESS_CMD);
  1075. if (readb(xl_mmio + MMIO_MACDATA) != CLOSE_NIC) {
  1076. printk(KERN_INFO "%s: CLOSE_NIC did not get a CLOSE_NIC response \n",dev->name) ;
  1077. } else {
  1078. writel((MEM_BYTE_READ | 0xd0000 | xl_priv->srb) +2, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1079. if (readb(xl_mmio + MMIO_MACDATA)==0) {
  1080. printk(KERN_INFO "%s: Adapter has been closed \n",dev->name) ;
  1081. writew(ACK_INTERRUPT | SRBRACK | LATCH_ACK, xl_mmio + MMIO_COMMAND) ;
  1082. xl_freemem(dev) ;
  1083. free_irq(dev->irq,dev) ;
  1084. } else {
  1085. printk(KERN_INFO "%s: Close nic command returned error code %02x\n",dev->name, readb(xl_mmio + MMIO_MACDATA)) ;
  1086. }
  1087. }
  1088. /* Reset the upload and download logic */
  1089. writew(UPRESET, xl_mmio + MMIO_COMMAND) ;
  1090. t=jiffies;
  1091. while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) {
  1092. schedule();
  1093. if(jiffies-t > 10*HZ) {
  1094. printk(KERN_ERR "%s: 3COM 3C359 Velocity XL-UPRESET not responding.\n", dev->name);
  1095. break ;
  1096. }
  1097. }
  1098. writew(DNRESET, xl_mmio + MMIO_COMMAND) ;
  1099. t=jiffies;
  1100. while (readw(xl_mmio + MMIO_INTSTATUS) & INTSTAT_CMD_IN_PROGRESS) {
  1101. schedule();
  1102. if(jiffies-t > 10*HZ) {
  1103. printk(KERN_ERR "%s: 3COM 3C359 Velocity XL-DNRESET not responding.\n", dev->name);
  1104. break ;
  1105. }
  1106. }
  1107. xl_hw_reset(dev) ;
  1108. return 0 ;
  1109. }
  1110. static void xl_set_rx_mode(struct net_device *dev)
  1111. {
  1112. struct xl_private *xl_priv = (struct xl_private *) dev->priv ;
  1113. struct dev_mc_list *dmi ;
  1114. unsigned char dev_mc_address[4] ;
  1115. u16 options ;
  1116. int i ;
  1117. if (dev->flags & IFF_PROMISC)
  1118. options = 0x0004 ;
  1119. else
  1120. options = 0x0000 ;
  1121. if (options ^ xl_priv->xl_copy_all_options) { /* Changed, must send command */
  1122. xl_priv->xl_copy_all_options = options ;
  1123. xl_srb_cmd(dev, SET_RECEIVE_MODE) ;
  1124. return ;
  1125. }
  1126. dev_mc_address[0] = dev_mc_address[1] = dev_mc_address[2] = dev_mc_address[3] = 0 ;
  1127. for (i=0,dmi=dev->mc_list;i < dev->mc_count; i++,dmi = dmi->next) {
  1128. dev_mc_address[0] |= dmi->dmi_addr[2] ;
  1129. dev_mc_address[1] |= dmi->dmi_addr[3] ;
  1130. dev_mc_address[2] |= dmi->dmi_addr[4] ;
  1131. dev_mc_address[3] |= dmi->dmi_addr[5] ;
  1132. }
  1133. if (memcmp(xl_priv->xl_functional_addr,dev_mc_address,4) != 0) { /* Options have changed, run the command */
  1134. memcpy(xl_priv->xl_functional_addr, dev_mc_address,4) ;
  1135. xl_srb_cmd(dev, SET_FUNC_ADDRESS) ;
  1136. }
  1137. return ;
  1138. }
  1139. /*
  1140. * We issued an srb command and now we must read
  1141. * the response from the completed command.
  1142. */
  1143. static void xl_srb_bh(struct net_device *dev)
  1144. {
  1145. struct xl_private *xl_priv = (struct xl_private *) dev->priv ;
  1146. u8 __iomem * xl_mmio = xl_priv->xl_mmio ;
  1147. u8 srb_cmd, ret_code ;
  1148. int i ;
  1149. writel(MEM_BYTE_READ | 0xd0000 | xl_priv->srb, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1150. srb_cmd = readb(xl_mmio + MMIO_MACDATA) ;
  1151. writel((MEM_BYTE_READ | 0xd0000 | xl_priv->srb) +2, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1152. ret_code = readb(xl_mmio + MMIO_MACDATA) ;
  1153. /* Ret_code is standard across all commands */
  1154. switch (ret_code) {
  1155. case 1:
  1156. printk(KERN_INFO "%s: Command: %d - Invalid Command code\n",dev->name,srb_cmd) ;
  1157. break ;
  1158. case 4:
  1159. printk(KERN_INFO "%s: Command: %d - Adapter is closed, must be open for this command \n",dev->name,srb_cmd) ;
  1160. break ;
  1161. case 6:
  1162. printk(KERN_INFO "%s: Command: %d - Options Invalid for command \n",dev->name,srb_cmd) ;
  1163. break ;
  1164. case 0: /* Successful command execution */
  1165. switch (srb_cmd) {
  1166. case READ_LOG: /* Returns 14 bytes of data from the NIC */
  1167. if(xl_priv->xl_message_level)
  1168. printk(KERN_INFO "%s: READ.LOG 14 bytes of data ",dev->name) ;
  1169. /*
  1170. * We still have to read the log even if message_level = 0 and we don't want
  1171. * to see it
  1172. */
  1173. for (i=0;i<14;i++) {
  1174. writel(MEM_BYTE_READ | 0xd0000 | xl_priv->srb | i, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1175. if(xl_priv->xl_message_level)
  1176. printk("%02x:",readb(xl_mmio + MMIO_MACDATA)) ;
  1177. }
  1178. printk("\n") ;
  1179. break ;
  1180. case SET_FUNC_ADDRESS:
  1181. if(xl_priv->xl_message_level)
  1182. printk(KERN_INFO "%s: Functional Address Set \n",dev->name) ;
  1183. break ;
  1184. case CLOSE_NIC:
  1185. if(xl_priv->xl_message_level)
  1186. printk(KERN_INFO "%s: Received CLOSE_NIC interrupt in interrupt handler \n",dev->name) ;
  1187. break ;
  1188. case SET_MULTICAST_MODE:
  1189. if(xl_priv->xl_message_level)
  1190. printk(KERN_INFO "%s: Multicast options successfully changed\n",dev->name) ;
  1191. break ;
  1192. case SET_RECEIVE_MODE:
  1193. if(xl_priv->xl_message_level) {
  1194. if (xl_priv->xl_copy_all_options == 0x0004)
  1195. printk(KERN_INFO "%s: Entering promiscuous mode \n", dev->name) ;
  1196. else
  1197. printk(KERN_INFO "%s: Entering normal receive mode \n",dev->name) ;
  1198. }
  1199. break ;
  1200. } /* switch */
  1201. break ;
  1202. } /* switch */
  1203. return ;
  1204. }
  1205. static struct net_device_stats * xl_get_stats(struct net_device *dev)
  1206. {
  1207. struct xl_private *xl_priv = (struct xl_private *) dev->priv ;
  1208. return (struct net_device_stats *) &xl_priv->xl_stats;
  1209. }
  1210. static int xl_set_mac_address (struct net_device *dev, void *addr)
  1211. {
  1212. struct sockaddr *saddr = addr ;
  1213. struct xl_private *xl_priv = (struct xl_private *)dev->priv ;
  1214. if (netif_running(dev)) {
  1215. printk(KERN_WARNING "%s: Cannot set mac/laa address while card is open\n", dev->name) ;
  1216. return -EIO ;
  1217. }
  1218. memcpy(xl_priv->xl_laa, saddr->sa_data,dev->addr_len) ;
  1219. if (xl_priv->xl_message_level) {
  1220. printk(KERN_INFO "%s: MAC/LAA Set to = %x.%x.%x.%x.%x.%x\n",dev->name, xl_priv->xl_laa[0],
  1221. xl_priv->xl_laa[1], xl_priv->xl_laa[2],
  1222. xl_priv->xl_laa[3], xl_priv->xl_laa[4],
  1223. xl_priv->xl_laa[5]);
  1224. }
  1225. return 0 ;
  1226. }
  1227. static void xl_arb_cmd(struct net_device *dev)
  1228. {
  1229. struct xl_private *xl_priv = (struct xl_private *) dev->priv;
  1230. u8 __iomem * xl_mmio = xl_priv->xl_mmio ;
  1231. u8 arb_cmd ;
  1232. u16 lan_status, lan_status_diff ;
  1233. writel( ( MEM_BYTE_READ | 0xD0000 | xl_priv->arb), xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1234. arb_cmd = readb(xl_mmio + MMIO_MACDATA) ;
  1235. if (arb_cmd == RING_STATUS_CHANGE) { /* Ring.Status.Change */
  1236. writel( ( (MEM_WORD_READ | 0xD0000 | xl_priv->arb) + 6), xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1237. printk(KERN_INFO "%s: Ring Status Change: New Status = %04x\n", dev->name, ntohs(readw(xl_mmio + MMIO_MACDATA) )) ;
  1238. lan_status = ntohs(readw(xl_mmio + MMIO_MACDATA));
  1239. /* Acknowledge interrupt, this tells nic we are done with the arb */
  1240. writel(ACK_INTERRUPT | ARBCACK | LATCH_ACK, xl_mmio + MMIO_COMMAND) ;
  1241. lan_status_diff = xl_priv->xl_lan_status ^ lan_status ;
  1242. if (lan_status_diff & (LSC_LWF | LSC_ARW | LSC_FPE | LSC_RR) ) {
  1243. if (lan_status_diff & LSC_LWF)
  1244. printk(KERN_WARNING "%s: Short circuit detected on the lobe\n",dev->name);
  1245. if (lan_status_diff & LSC_ARW)
  1246. printk(KERN_WARNING "%s: Auto removal error\n",dev->name);
  1247. if (lan_status_diff & LSC_FPE)
  1248. printk(KERN_WARNING "%s: FDX Protocol Error\n",dev->name);
  1249. if (lan_status_diff & LSC_RR)
  1250. printk(KERN_WARNING "%s: Force remove MAC frame received\n",dev->name);
  1251. /* Adapter has been closed by the hardware */
  1252. netif_stop_queue(dev);
  1253. xl_freemem(dev) ;
  1254. free_irq(dev->irq,dev);
  1255. printk(KERN_WARNING "%s: Adapter has been closed \n", dev->name) ;
  1256. } /* If serious error */
  1257. if (xl_priv->xl_message_level) {
  1258. if (lan_status_diff & LSC_SIG_LOSS)
  1259. printk(KERN_WARNING "%s: No receive signal detected \n", dev->name) ;
  1260. if (lan_status_diff & LSC_HARD_ERR)
  1261. printk(KERN_INFO "%s: Beaconing \n",dev->name);
  1262. if (lan_status_diff & LSC_SOFT_ERR)
  1263. printk(KERN_WARNING "%s: Adapter transmitted Soft Error Report Mac Frame \n",dev->name);
  1264. if (lan_status_diff & LSC_TRAN_BCN)
  1265. printk(KERN_INFO "%s: We are tranmitting the beacon, aaah\n",dev->name);
  1266. if (lan_status_diff & LSC_SS)
  1267. printk(KERN_INFO "%s: Single Station on the ring \n", dev->name);
  1268. if (lan_status_diff & LSC_RING_REC)
  1269. printk(KERN_INFO "%s: Ring recovery ongoing\n",dev->name);
  1270. if (lan_status_diff & LSC_FDX_MODE)
  1271. printk(KERN_INFO "%s: Operating in FDX mode\n",dev->name);
  1272. }
  1273. if (lan_status_diff & LSC_CO) {
  1274. if (xl_priv->xl_message_level)
  1275. printk(KERN_INFO "%s: Counter Overflow \n", dev->name);
  1276. /* Issue READ.LOG command */
  1277. xl_srb_cmd(dev, READ_LOG) ;
  1278. }
  1279. /* There is no command in the tech docs to issue the read_sr_counters */
  1280. if (lan_status_diff & LSC_SR_CO) {
  1281. if (xl_priv->xl_message_level)
  1282. printk(KERN_INFO "%s: Source routing counters overflow\n", dev->name);
  1283. }
  1284. xl_priv->xl_lan_status = lan_status ;
  1285. } /* Lan.change.status */
  1286. else if ( arb_cmd == RECEIVE_DATA) { /* Received.Data */
  1287. #if XL_DEBUG
  1288. printk(KERN_INFO "Received.Data \n") ;
  1289. #endif
  1290. writel( ((MEM_WORD_READ | 0xD0000 | xl_priv->arb) + 6), xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1291. xl_priv->mac_buffer = ntohs(readw(xl_mmio + MMIO_MACDATA)) ;
  1292. /* Now we are going to be really basic here and not do anything
  1293. * with the data at all. The tech docs do not give me enough
  1294. * information to calculate the buffers properly so we're
  1295. * just going to tell the nic that we've dealt with the frame
  1296. * anyway.
  1297. */
  1298. dev->last_rx = jiffies ;
  1299. /* Acknowledge interrupt, this tells nic we are done with the arb */
  1300. writel(ACK_INTERRUPT | ARBCACK | LATCH_ACK, xl_mmio + MMIO_COMMAND) ;
  1301. /* Is the ASB free ? */
  1302. xl_priv->asb_queued = 0 ;
  1303. writel( ((MEM_BYTE_READ | 0xD0000 | xl_priv->asb) + 2), xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1304. if (readb(xl_mmio + MMIO_MACDATA) != 0xff) {
  1305. xl_priv->asb_queued = 1 ;
  1306. xl_wait_misr_flags(dev) ;
  1307. writel(MEM_BYTE_WRITE | MF_ASBFR, xl_mmio + MMIO_MAC_ACCESS_CMD);
  1308. writeb(0xff, xl_mmio + MMIO_MACDATA) ;
  1309. writel(MMIO_BYTE_WRITE | MISR_SET, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1310. writeb(MISR_ASBFR, xl_mmio + MMIO_MACDATA) ;
  1311. return ;
  1312. /* Drop out and wait for the bottom half to be run */
  1313. }
  1314. xl_asb_cmd(dev) ;
  1315. } else {
  1316. printk(KERN_WARNING "%s: Received unknown arb (xl_priv) command: %02x \n",dev->name,arb_cmd) ;
  1317. }
  1318. /* Acknowledge the arb interrupt */
  1319. writel(ACK_INTERRUPT | ARBCACK | LATCH_ACK , xl_mmio + MMIO_COMMAND) ;
  1320. return ;
  1321. }
  1322. /*
  1323. * There is only one asb command, but we can get called from different
  1324. * places.
  1325. */
  1326. static void xl_asb_cmd(struct net_device *dev)
  1327. {
  1328. struct xl_private *xl_priv = (struct xl_private *) dev->priv ;
  1329. u8 __iomem * xl_mmio = xl_priv->xl_mmio ;
  1330. if (xl_priv->asb_queued == 1)
  1331. writel(ACK_INTERRUPT | LATCH_ACK | ASBFACK, xl_mmio + MMIO_COMMAND) ;
  1332. writel(MEM_BYTE_WRITE | 0xd0000 | xl_priv->asb, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1333. writeb(0x81, xl_mmio + MMIO_MACDATA) ;
  1334. writel(MEM_WORD_WRITE | 0xd0000 | xl_priv->asb | 6, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1335. writew(ntohs(xl_priv->mac_buffer), xl_mmio + MMIO_MACDATA) ;
  1336. xl_wait_misr_flags(dev) ;
  1337. writel(MEM_BYTE_WRITE | MF_RASB, xl_mmio + MMIO_MAC_ACCESS_CMD);
  1338. writeb(0xff, xl_mmio + MMIO_MACDATA) ;
  1339. writel(MMIO_BYTE_WRITE | MISR_SET, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1340. writeb(MISR_RASB, xl_mmio + MMIO_MACDATA) ;
  1341. xl_priv->asb_queued = 2 ;
  1342. return ;
  1343. }
  1344. /*
  1345. * This will only get called if there was an error
  1346. * from the asb cmd.
  1347. */
  1348. static void xl_asb_bh(struct net_device *dev)
  1349. {
  1350. struct xl_private *xl_priv = (struct xl_private *) dev->priv ;
  1351. u8 __iomem * xl_mmio = xl_priv->xl_mmio ;
  1352. u8 ret_code ;
  1353. writel(MMIO_BYTE_READ | 0xd0000 | xl_priv->asb | 2, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1354. ret_code = readb(xl_mmio + MMIO_MACDATA) ;
  1355. switch (ret_code) {
  1356. case 0x01:
  1357. printk(KERN_INFO "%s: ASB Command, unrecognized command code \n",dev->name) ;
  1358. break ;
  1359. case 0x26:
  1360. printk(KERN_INFO "%s: ASB Command, unexpected receive buffer \n", dev->name) ;
  1361. break ;
  1362. case 0x40:
  1363. printk(KERN_INFO "%s: ASB Command, Invalid Station ID \n", dev->name) ;
  1364. break ;
  1365. }
  1366. xl_priv->asb_queued = 0 ;
  1367. writel(ACK_INTERRUPT | LATCH_ACK | ASBFACK, xl_mmio + MMIO_COMMAND) ;
  1368. return ;
  1369. }
  1370. /*
  1371. * Issue srb commands to the nic
  1372. */
  1373. static void xl_srb_cmd(struct net_device *dev, int srb_cmd)
  1374. {
  1375. struct xl_private *xl_priv = (struct xl_private *) dev->priv ;
  1376. u8 __iomem * xl_mmio = xl_priv->xl_mmio ;
  1377. switch (srb_cmd) {
  1378. case READ_LOG:
  1379. writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1380. writeb(READ_LOG, xl_mmio + MMIO_MACDATA) ;
  1381. break;
  1382. case CLOSE_NIC:
  1383. writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1384. writeb(CLOSE_NIC, xl_mmio + MMIO_MACDATA) ;
  1385. break ;
  1386. case SET_RECEIVE_MODE:
  1387. writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1388. writeb(SET_RECEIVE_MODE, xl_mmio + MMIO_MACDATA) ;
  1389. writel(MEM_WORD_WRITE | 0xD0000 | xl_priv->srb | 4, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1390. writew(xl_priv->xl_copy_all_options, xl_mmio + MMIO_MACDATA) ;
  1391. break ;
  1392. case SET_FUNC_ADDRESS:
  1393. writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1394. writeb(SET_FUNC_ADDRESS, xl_mmio + MMIO_MACDATA) ;
  1395. writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb | 6 , xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1396. writeb(xl_priv->xl_functional_addr[0], xl_mmio + MMIO_MACDATA) ;
  1397. writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb | 7 , xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1398. writeb(xl_priv->xl_functional_addr[1], xl_mmio + MMIO_MACDATA) ;
  1399. writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb | 8 , xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1400. writeb(xl_priv->xl_functional_addr[2], xl_mmio + MMIO_MACDATA) ;
  1401. writel(MEM_BYTE_WRITE | 0xD0000 | xl_priv->srb | 9 , xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1402. writeb(xl_priv->xl_functional_addr[3], xl_mmio + MMIO_MACDATA) ;
  1403. break ;
  1404. } /* switch */
  1405. xl_wait_misr_flags(dev) ;
  1406. /* Write 0xff to the CSRB flag */
  1407. writel(MEM_BYTE_WRITE | MF_CSRB , xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1408. writeb(0xFF, xl_mmio + MMIO_MACDATA) ;
  1409. /* Set csrb bit in MISR register to process command */
  1410. writel(MMIO_BYTE_WRITE | MISR_SET, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1411. writeb(MISR_CSRB, xl_mmio + MMIO_MACDATA) ;
  1412. xl_priv->srb_queued = 1 ;
  1413. return ;
  1414. }
  1415. /*
  1416. * This is nasty, to use the MISR command you have to wait for 6 memory locations
  1417. * to be zero. This is the way the driver does on other OS'es so we should be ok with
  1418. * the empty loop.
  1419. */
  1420. static void xl_wait_misr_flags(struct net_device *dev)
  1421. {
  1422. struct xl_private *xl_priv = (struct xl_private *) dev->priv ;
  1423. u8 __iomem * xl_mmio = xl_priv->xl_mmio ;
  1424. int i ;
  1425. writel(MMIO_BYTE_READ | MISR_RW, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1426. if (readb(xl_mmio + MMIO_MACDATA) != 0) { /* Misr not clear */
  1427. for (i=0; i<6; i++) {
  1428. writel(MEM_BYTE_READ | 0xDFFE0 | i, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1429. while (readb(xl_mmio + MMIO_MACDATA) != 0 ) {} ; /* Empty Loop */
  1430. }
  1431. }
  1432. writel(MMIO_BYTE_WRITE | MISR_AND, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
  1433. writeb(0x80, xl_mmio + MMIO_MACDATA) ;
  1434. return ;
  1435. }
  1436. /*
  1437. * Change mtu size, this should work the same as olympic
  1438. */
  1439. static int xl_change_mtu(struct net_device *dev, int mtu)
  1440. {
  1441. struct xl_private *xl_priv = (struct xl_private *) dev->priv;
  1442. u16 max_mtu ;
  1443. if (xl_priv->xl_ring_speed == 4)
  1444. max_mtu = 4500 ;
  1445. else
  1446. max_mtu = 18000 ;
  1447. if (mtu > max_mtu)
  1448. return -EINVAL ;
  1449. if (mtu < 100)
  1450. return -EINVAL ;
  1451. dev->mtu = mtu ;
  1452. xl_priv->pkt_buf_sz = mtu + TR_HLEN ;
  1453. return 0 ;
  1454. }
  1455. static void __devexit xl_remove_one (struct pci_dev *pdev)
  1456. {
  1457. struct net_device *dev = pci_get_drvdata(pdev);
  1458. struct xl_private *xl_priv=(struct xl_private *)dev->priv;
  1459. unregister_netdev(dev);
  1460. iounmap(xl_priv->xl_mmio) ;
  1461. pci_release_regions(pdev) ;
  1462. pci_set_drvdata(pdev,NULL) ;
  1463. free_netdev(dev);
  1464. return ;
  1465. }
  1466. static struct pci_driver xl_3c359_driver = {
  1467. .name = "3c359",
  1468. .id_table = xl_pci_tbl,
  1469. .probe = xl_probe,
  1470. .remove = __devexit_p(xl_remove_one),
  1471. };
  1472. static int __init xl_pci_init (void)
  1473. {
  1474. return pci_register_driver(&xl_3c359_driver);
  1475. }
  1476. static void __exit xl_pci_cleanup (void)
  1477. {
  1478. pci_unregister_driver (&xl_3c359_driver);
  1479. }
  1480. module_init(xl_pci_init);
  1481. module_exit(xl_pci_cleanup);
  1482. MODULE_LICENSE("GPL") ;