3c359.c 58 KB

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