acenic.c 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229
  1. /*
  2. * acenic.c: Linux driver for the Alteon AceNIC Gigabit Ethernet card
  3. * and other Tigon based cards.
  4. *
  5. * Copyright 1998-2002 by Jes Sorensen, <jes@trained-monkey.org>.
  6. *
  7. * Thanks to Alteon and 3Com for providing hardware and documentation
  8. * enabling me to write this driver.
  9. *
  10. * A mailing list for discussing the use of this driver has been
  11. * setup, please subscribe to the lists if you have any questions
  12. * about the driver. Send mail to linux-acenic-help@sunsite.auc.dk to
  13. * see how to subscribe.
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * Additional credits:
  21. * Pete Wyckoff <wyckoff@ca.sandia.gov>: Initial Linux/Alpha and trace
  22. * dump support. The trace dump support has not been
  23. * integrated yet however.
  24. * Troy Benjegerdes: Big Endian (PPC) patches.
  25. * Nate Stahl: Better out of memory handling and stats support.
  26. * Aman Singla: Nasty race between interrupt handler and tx code dealing
  27. * with 'testing the tx_ret_csm and setting tx_full'
  28. * David S. Miller <davem@redhat.com>: conversion to new PCI dma mapping
  29. * infrastructure and Sparc support
  30. * Pierrick Pinasseau (CERN): For lending me an Ultra 5 to test the
  31. * driver under Linux/Sparc64
  32. * Matt Domsch <Matt_Domsch@dell.com>: Detect Alteon 1000baseT cards
  33. * ETHTOOL_GDRVINFO support
  34. * Chip Salzenberg <chip@valinux.com>: Fix race condition between tx
  35. * handler and close() cleanup.
  36. * Ken Aaker <kdaaker@rchland.vnet.ibm.com>: Correct check for whether
  37. * memory mapped IO is enabled to
  38. * make the driver work on RS/6000.
  39. * Takayoshi Kouchi <kouchi@hpc.bs1.fc.nec.co.jp>: Identifying problem
  40. * where the driver would disable
  41. * bus master mode if it had to disable
  42. * write and invalidate.
  43. * Stephen Hack <stephen_hack@hp.com>: Fixed ace_set_mac_addr for little
  44. * endian systems.
  45. * Val Henson <vhenson@esscom.com>: Reset Jumbo skb producer and
  46. * rx producer index when
  47. * flushing the Jumbo ring.
  48. * Hans Grobler <grobh@sun.ac.za>: Memory leak fixes in the
  49. * driver init path.
  50. * Grant Grundler <grundler@cup.hp.com>: PCI write posting fixes.
  51. */
  52. #include <linux/module.h>
  53. #include <linux/moduleparam.h>
  54. #include <linux/types.h>
  55. #include <linux/errno.h>
  56. #include <linux/ioport.h>
  57. #include <linux/pci.h>
  58. #include <linux/dma-mapping.h>
  59. #include <linux/kernel.h>
  60. #include <linux/netdevice.h>
  61. #include <linux/etherdevice.h>
  62. #include <linux/skbuff.h>
  63. #include <linux/init.h>
  64. #include <linux/delay.h>
  65. #include <linux/mm.h>
  66. #include <linux/highmem.h>
  67. #include <linux/sockios.h>
  68. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  69. #include <linux/if_vlan.h>
  70. #endif
  71. #ifdef SIOCETHTOOL
  72. #include <linux/ethtool.h>
  73. #endif
  74. #include <net/sock.h>
  75. #include <net/ip.h>
  76. #include <asm/system.h>
  77. #include <asm/io.h>
  78. #include <asm/irq.h>
  79. #include <asm/byteorder.h>
  80. #include <asm/uaccess.h>
  81. #define DRV_NAME "acenic"
  82. #undef INDEX_DEBUG
  83. #ifdef CONFIG_ACENIC_OMIT_TIGON_I
  84. #define ACE_IS_TIGON_I(ap) 0
  85. #define ACE_TX_RING_ENTRIES(ap) MAX_TX_RING_ENTRIES
  86. #else
  87. #define ACE_IS_TIGON_I(ap) (ap->version == 1)
  88. #define ACE_TX_RING_ENTRIES(ap) ap->tx_ring_entries
  89. #endif
  90. #ifndef PCI_VENDOR_ID_ALTEON
  91. #define PCI_VENDOR_ID_ALTEON 0x12ae
  92. #endif
  93. #ifndef PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE
  94. #define PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE 0x0001
  95. #define PCI_DEVICE_ID_ALTEON_ACENIC_COPPER 0x0002
  96. #endif
  97. #ifndef PCI_DEVICE_ID_3COM_3C985
  98. #define PCI_DEVICE_ID_3COM_3C985 0x0001
  99. #endif
  100. #ifndef PCI_VENDOR_ID_NETGEAR
  101. #define PCI_VENDOR_ID_NETGEAR 0x1385
  102. #define PCI_DEVICE_ID_NETGEAR_GA620 0x620a
  103. #endif
  104. #ifndef PCI_DEVICE_ID_NETGEAR_GA620T
  105. #define PCI_DEVICE_ID_NETGEAR_GA620T 0x630a
  106. #endif
  107. /*
  108. * Farallon used the DEC vendor ID by mistake and they seem not
  109. * to care - stinky!
  110. */
  111. #ifndef PCI_DEVICE_ID_FARALLON_PN9000SX
  112. #define PCI_DEVICE_ID_FARALLON_PN9000SX 0x1a
  113. #endif
  114. #ifndef PCI_DEVICE_ID_FARALLON_PN9100T
  115. #define PCI_DEVICE_ID_FARALLON_PN9100T 0xfa
  116. #endif
  117. #ifndef PCI_VENDOR_ID_SGI
  118. #define PCI_VENDOR_ID_SGI 0x10a9
  119. #endif
  120. #ifndef PCI_DEVICE_ID_SGI_ACENIC
  121. #define PCI_DEVICE_ID_SGI_ACENIC 0x0009
  122. #endif
  123. static struct pci_device_id acenic_pci_tbl[] = {
  124. { PCI_VENDOR_ID_ALTEON, PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE,
  125. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  126. { PCI_VENDOR_ID_ALTEON, PCI_DEVICE_ID_ALTEON_ACENIC_COPPER,
  127. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  128. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C985,
  129. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  130. { PCI_VENDOR_ID_NETGEAR, PCI_DEVICE_ID_NETGEAR_GA620,
  131. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  132. { PCI_VENDOR_ID_NETGEAR, PCI_DEVICE_ID_NETGEAR_GA620T,
  133. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  134. /*
  135. * Farallon used the DEC vendor ID on their cards incorrectly,
  136. * then later Alteon's ID.
  137. */
  138. { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_FARALLON_PN9000SX,
  139. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  140. { PCI_VENDOR_ID_ALTEON, PCI_DEVICE_ID_FARALLON_PN9100T,
  141. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  142. { PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_ACENIC,
  143. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  144. { }
  145. };
  146. MODULE_DEVICE_TABLE(pci, acenic_pci_tbl);
  147. #define ace_sync_irq(irq) synchronize_irq(irq)
  148. #ifndef offset_in_page
  149. #define offset_in_page(ptr) ((unsigned long)(ptr) & ~PAGE_MASK)
  150. #endif
  151. #define ACE_MAX_MOD_PARMS 8
  152. #define BOARD_IDX_STATIC 0
  153. #define BOARD_IDX_OVERFLOW -1
  154. #if (defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)) && \
  155. defined(NETIF_F_HW_VLAN_RX)
  156. #define ACENIC_DO_VLAN 1
  157. #define ACE_RCB_VLAN_FLAG RCB_FLG_VLAN_ASSIST
  158. #else
  159. #define ACENIC_DO_VLAN 0
  160. #define ACE_RCB_VLAN_FLAG 0
  161. #endif
  162. #include "acenic.h"
  163. /*
  164. * These must be defined before the firmware is included.
  165. */
  166. #define MAX_TEXT_LEN 96*1024
  167. #define MAX_RODATA_LEN 8*1024
  168. #define MAX_DATA_LEN 2*1024
  169. #include "acenic_firmware.h"
  170. #ifndef tigon2FwReleaseLocal
  171. #define tigon2FwReleaseLocal 0
  172. #endif
  173. /*
  174. * This driver currently supports Tigon I and Tigon II based cards
  175. * including the Alteon AceNIC, the 3Com 3C985[B] and NetGear
  176. * GA620. The driver should also work on the SGI, DEC and Farallon
  177. * versions of the card, however I have not been able to test that
  178. * myself.
  179. *
  180. * This card is really neat, it supports receive hardware checksumming
  181. * and jumbo frames (up to 9000 bytes) and does a lot of work in the
  182. * firmware. Also the programming interface is quite neat, except for
  183. * the parts dealing with the i2c eeprom on the card ;-)
  184. *
  185. * Using jumbo frames:
  186. *
  187. * To enable jumbo frames, simply specify an mtu between 1500 and 9000
  188. * bytes to ifconfig. Jumbo frames can be enabled or disabled at any time
  189. * by running `ifconfig eth<X> mtu <MTU>' with <X> being the Ethernet
  190. * interface number and <MTU> being the MTU value.
  191. *
  192. * Module parameters:
  193. *
  194. * When compiled as a loadable module, the driver allows for a number
  195. * of module parameters to be specified. The driver supports the
  196. * following module parameters:
  197. *
  198. * trace=<val> - Firmware trace level. This requires special traced
  199. * firmware to replace the firmware supplied with
  200. * the driver - for debugging purposes only.
  201. *
  202. * link=<val> - Link state. Normally you want to use the default link
  203. * parameters set by the driver. This can be used to
  204. * override these in case your switch doesn't negotiate
  205. * the link properly. Valid values are:
  206. * 0x0001 - Force half duplex link.
  207. * 0x0002 - Do not negotiate line speed with the other end.
  208. * 0x0010 - 10Mbit/sec link.
  209. * 0x0020 - 100Mbit/sec link.
  210. * 0x0040 - 1000Mbit/sec link.
  211. * 0x0100 - Do not negotiate flow control.
  212. * 0x0200 - Enable RX flow control Y
  213. * 0x0400 - Enable TX flow control Y (Tigon II NICs only).
  214. * Default value is 0x0270, ie. enable link+flow
  215. * control negotiation. Negotiating the highest
  216. * possible link speed with RX flow control enabled.
  217. *
  218. * When disabling link speed negotiation, only one link
  219. * speed is allowed to be specified!
  220. *
  221. * tx_coal_tick=<val> - number of coalescing clock ticks (us) allowed
  222. * to wait for more packets to arive before
  223. * interrupting the host, from the time the first
  224. * packet arrives.
  225. *
  226. * rx_coal_tick=<val> - number of coalescing clock ticks (us) allowed
  227. * to wait for more packets to arive in the transmit ring,
  228. * before interrupting the host, after transmitting the
  229. * first packet in the ring.
  230. *
  231. * max_tx_desc=<val> - maximum number of transmit descriptors
  232. * (packets) transmitted before interrupting the host.
  233. *
  234. * max_rx_desc=<val> - maximum number of receive descriptors
  235. * (packets) received before interrupting the host.
  236. *
  237. * tx_ratio=<val> - 7 bit value (0 - 63) specifying the split in 64th
  238. * increments of the NIC's on board memory to be used for
  239. * transmit and receive buffers. For the 1MB NIC app. 800KB
  240. * is available, on the 1/2MB NIC app. 300KB is available.
  241. * 68KB will always be available as a minimum for both
  242. * directions. The default value is a 50/50 split.
  243. * dis_pci_mem_inval=<val> - disable PCI memory write and invalidate
  244. * operations, default (1) is to always disable this as
  245. * that is what Alteon does on NT. I have not been able
  246. * to measure any real performance differences with
  247. * this on my systems. Set <val>=0 if you want to
  248. * enable these operations.
  249. *
  250. * If you use more than one NIC, specify the parameters for the
  251. * individual NICs with a comma, ie. trace=0,0x00001fff,0 you want to
  252. * run tracing on NIC #2 but not on NIC #1 and #3.
  253. *
  254. * TODO:
  255. *
  256. * - Proper multicast support.
  257. * - NIC dump support.
  258. * - More tuning parameters.
  259. *
  260. * The mini ring is not used under Linux and I am not sure it makes sense
  261. * to actually use it.
  262. *
  263. * New interrupt handler strategy:
  264. *
  265. * The old interrupt handler worked using the traditional method of
  266. * replacing an skbuff with a new one when a packet arrives. However
  267. * the rx rings do not need to contain a static number of buffer
  268. * descriptors, thus it makes sense to move the memory allocation out
  269. * of the main interrupt handler and do it in a bottom half handler
  270. * and only allocate new buffers when the number of buffers in the
  271. * ring is below a certain threshold. In order to avoid starving the
  272. * NIC under heavy load it is however necessary to force allocation
  273. * when hitting a minimum threshold. The strategy for alloction is as
  274. * follows:
  275. *
  276. * RX_LOW_BUF_THRES - allocate buffers in the bottom half
  277. * RX_PANIC_LOW_THRES - we are very low on buffers, allocate
  278. * the buffers in the interrupt handler
  279. * RX_RING_THRES - maximum number of buffers in the rx ring
  280. * RX_MINI_THRES - maximum number of buffers in the mini ring
  281. * RX_JUMBO_THRES - maximum number of buffers in the jumbo ring
  282. *
  283. * One advantagous side effect of this allocation approach is that the
  284. * entire rx processing can be done without holding any spin lock
  285. * since the rx rings and registers are totally independent of the tx
  286. * ring and its registers. This of course includes the kmalloc's of
  287. * new skb's. Thus start_xmit can run in parallel with rx processing
  288. * and the memory allocation on SMP systems.
  289. *
  290. * Note that running the skb reallocation in a bottom half opens up
  291. * another can of races which needs to be handled properly. In
  292. * particular it can happen that the interrupt handler tries to run
  293. * the reallocation while the bottom half is either running on another
  294. * CPU or was interrupted on the same CPU. To get around this the
  295. * driver uses bitops to prevent the reallocation routines from being
  296. * reentered.
  297. *
  298. * TX handling can also be done without holding any spin lock, wheee
  299. * this is fun! since tx_ret_csm is only written to by the interrupt
  300. * handler. The case to be aware of is when shutting down the device
  301. * and cleaning up where it is necessary to make sure that
  302. * start_xmit() is not running while this is happening. Well DaveM
  303. * informs me that this case is already protected against ... bye bye
  304. * Mr. Spin Lock, it was nice to know you.
  305. *
  306. * TX interrupts are now partly disabled so the NIC will only generate
  307. * TX interrupts for the number of coal ticks, not for the number of
  308. * TX packets in the queue. This should reduce the number of TX only,
  309. * ie. when no RX processing is done, interrupts seen.
  310. */
  311. /*
  312. * Threshold values for RX buffer allocation - the low water marks for
  313. * when to start refilling the rings are set to 75% of the ring
  314. * sizes. It seems to make sense to refill the rings entirely from the
  315. * intrrupt handler once it gets below the panic threshold, that way
  316. * we don't risk that the refilling is moved to another CPU when the
  317. * one running the interrupt handler just got the slab code hot in its
  318. * cache.
  319. */
  320. #define RX_RING_SIZE 72
  321. #define RX_MINI_SIZE 64
  322. #define RX_JUMBO_SIZE 48
  323. #define RX_PANIC_STD_THRES 16
  324. #define RX_PANIC_STD_REFILL (3*RX_PANIC_STD_THRES)/2
  325. #define RX_LOW_STD_THRES (3*RX_RING_SIZE)/4
  326. #define RX_PANIC_MINI_THRES 12
  327. #define RX_PANIC_MINI_REFILL (3*RX_PANIC_MINI_THRES)/2
  328. #define RX_LOW_MINI_THRES (3*RX_MINI_SIZE)/4
  329. #define RX_PANIC_JUMBO_THRES 6
  330. #define RX_PANIC_JUMBO_REFILL (3*RX_PANIC_JUMBO_THRES)/2
  331. #define RX_LOW_JUMBO_THRES (3*RX_JUMBO_SIZE)/4
  332. /*
  333. * Size of the mini ring entries, basically these just should be big
  334. * enough to take TCP ACKs
  335. */
  336. #define ACE_MINI_SIZE 100
  337. #define ACE_MINI_BUFSIZE ACE_MINI_SIZE
  338. #define ACE_STD_BUFSIZE (ACE_STD_MTU + ETH_HLEN + 4)
  339. #define ACE_JUMBO_BUFSIZE (ACE_JUMBO_MTU + ETH_HLEN + 4)
  340. /*
  341. * There seems to be a magic difference in the effect between 995 and 996
  342. * but little difference between 900 and 995 ... no idea why.
  343. *
  344. * There is now a default set of tuning parameters which is set, depending
  345. * on whether or not the user enables Jumbo frames. It's assumed that if
  346. * Jumbo frames are enabled, the user wants optimal tuning for that case.
  347. */
  348. #define DEF_TX_COAL 400 /* 996 */
  349. #define DEF_TX_MAX_DESC 60 /* was 40 */
  350. #define DEF_RX_COAL 120 /* 1000 */
  351. #define DEF_RX_MAX_DESC 25
  352. #define DEF_TX_RATIO 21 /* 24 */
  353. #define DEF_JUMBO_TX_COAL 20
  354. #define DEF_JUMBO_TX_MAX_DESC 60
  355. #define DEF_JUMBO_RX_COAL 30
  356. #define DEF_JUMBO_RX_MAX_DESC 6
  357. #define DEF_JUMBO_TX_RATIO 21
  358. #if tigon2FwReleaseLocal < 20001118
  359. /*
  360. * Standard firmware and early modifications duplicate
  361. * IRQ load without this flag (coal timer is never reset).
  362. * Note that with this flag tx_coal should be less than
  363. * time to xmit full tx ring.
  364. * 400usec is not so bad for tx ring size of 128.
  365. */
  366. #define TX_COAL_INTS_ONLY 1 /* worth it */
  367. #else
  368. /*
  369. * With modified firmware, this is not necessary, but still useful.
  370. */
  371. #define TX_COAL_INTS_ONLY 1
  372. #endif
  373. #define DEF_TRACE 0
  374. #define DEF_STAT (2 * TICKS_PER_SEC)
  375. static int link_state[ACE_MAX_MOD_PARMS];
  376. static int trace[ACE_MAX_MOD_PARMS];
  377. static int tx_coal_tick[ACE_MAX_MOD_PARMS];
  378. static int rx_coal_tick[ACE_MAX_MOD_PARMS];
  379. static int max_tx_desc[ACE_MAX_MOD_PARMS];
  380. static int max_rx_desc[ACE_MAX_MOD_PARMS];
  381. static int tx_ratio[ACE_MAX_MOD_PARMS];
  382. static int dis_pci_mem_inval[ACE_MAX_MOD_PARMS] = {1, 1, 1, 1, 1, 1, 1, 1};
  383. MODULE_AUTHOR("Jes Sorensen <jes@trained-monkey.org>");
  384. MODULE_LICENSE("GPL");
  385. MODULE_DESCRIPTION("AceNIC/3C985/GA620 Gigabit Ethernet driver");
  386. module_param_array_named(link, link_state, int, NULL, 0);
  387. module_param_array(trace, int, NULL, 0);
  388. module_param_array(tx_coal_tick, int, NULL, 0);
  389. module_param_array(max_tx_desc, int, NULL, 0);
  390. module_param_array(rx_coal_tick, int, NULL, 0);
  391. module_param_array(max_rx_desc, int, NULL, 0);
  392. module_param_array(tx_ratio, int, NULL, 0);
  393. MODULE_PARM_DESC(link, "AceNIC/3C985/NetGear link state");
  394. MODULE_PARM_DESC(trace, "AceNIC/3C985/NetGear firmware trace level");
  395. MODULE_PARM_DESC(tx_coal_tick, "AceNIC/3C985/GA620 max clock ticks to wait from first tx descriptor arrives");
  396. MODULE_PARM_DESC(max_tx_desc, "AceNIC/3C985/GA620 max number of transmit descriptors to wait");
  397. MODULE_PARM_DESC(rx_coal_tick, "AceNIC/3C985/GA620 max clock ticks to wait from first rx descriptor arrives");
  398. MODULE_PARM_DESC(max_rx_desc, "AceNIC/3C985/GA620 max number of receive descriptors to wait");
  399. MODULE_PARM_DESC(tx_ratio, "AceNIC/3C985/GA620 ratio of NIC memory used for TX/RX descriptors (range 0-63)");
  400. static char version[] __devinitdata =
  401. "acenic.c: v0.92 08/05/2002 Jes Sorensen, linux-acenic@SunSITE.dk\n"
  402. " http://home.cern.ch/~jes/gige/acenic.html\n";
  403. static int ace_get_settings(struct net_device *, struct ethtool_cmd *);
  404. static int ace_set_settings(struct net_device *, struct ethtool_cmd *);
  405. static void ace_get_drvinfo(struct net_device *, struct ethtool_drvinfo *);
  406. static const struct ethtool_ops ace_ethtool_ops = {
  407. .get_settings = ace_get_settings,
  408. .set_settings = ace_set_settings,
  409. .get_drvinfo = ace_get_drvinfo,
  410. };
  411. static void ace_watchdog(struct net_device *dev);
  412. static int __devinit acenic_probe_one(struct pci_dev *pdev,
  413. const struct pci_device_id *id)
  414. {
  415. struct net_device *dev;
  416. struct ace_private *ap;
  417. static int boards_found;
  418. dev = alloc_etherdev(sizeof(struct ace_private));
  419. if (dev == NULL) {
  420. printk(KERN_ERR "acenic: Unable to allocate "
  421. "net_device structure!\n");
  422. return -ENOMEM;
  423. }
  424. SET_NETDEV_DEV(dev, &pdev->dev);
  425. ap = dev->priv;
  426. ap->pdev = pdev;
  427. ap->name = pci_name(pdev);
  428. dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
  429. #if ACENIC_DO_VLAN
  430. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  431. dev->vlan_rx_register = ace_vlan_rx_register;
  432. #endif
  433. dev->tx_timeout = &ace_watchdog;
  434. dev->watchdog_timeo = 5*HZ;
  435. dev->open = &ace_open;
  436. dev->stop = &ace_close;
  437. dev->hard_start_xmit = &ace_start_xmit;
  438. dev->get_stats = &ace_get_stats;
  439. dev->set_multicast_list = &ace_set_multicast_list;
  440. SET_ETHTOOL_OPS(dev, &ace_ethtool_ops);
  441. dev->set_mac_address = &ace_set_mac_addr;
  442. dev->change_mtu = &ace_change_mtu;
  443. /* we only display this string ONCE */
  444. if (!boards_found)
  445. printk(version);
  446. if (pci_enable_device(pdev))
  447. goto fail_free_netdev;
  448. /*
  449. * Enable master mode before we start playing with the
  450. * pci_command word since pci_set_master() will modify
  451. * it.
  452. */
  453. pci_set_master(pdev);
  454. pci_read_config_word(pdev, PCI_COMMAND, &ap->pci_command);
  455. /* OpenFirmware on Mac's does not set this - DOH.. */
  456. if (!(ap->pci_command & PCI_COMMAND_MEMORY)) {
  457. printk(KERN_INFO "%s: Enabling PCI Memory Mapped "
  458. "access - was not enabled by BIOS/Firmware\n",
  459. ap->name);
  460. ap->pci_command = ap->pci_command | PCI_COMMAND_MEMORY;
  461. pci_write_config_word(ap->pdev, PCI_COMMAND,
  462. ap->pci_command);
  463. wmb();
  464. }
  465. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &ap->pci_latency);
  466. if (ap->pci_latency <= 0x40) {
  467. ap->pci_latency = 0x40;
  468. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, ap->pci_latency);
  469. }
  470. /*
  471. * Remap the regs into kernel space - this is abuse of
  472. * dev->base_addr since it was means for I/O port
  473. * addresses but who gives a damn.
  474. */
  475. dev->base_addr = pci_resource_start(pdev, 0);
  476. ap->regs = ioremap(dev->base_addr, 0x4000);
  477. if (!ap->regs) {
  478. printk(KERN_ERR "%s: Unable to map I/O register, "
  479. "AceNIC %i will be disabled.\n",
  480. ap->name, boards_found);
  481. goto fail_free_netdev;
  482. }
  483. switch(pdev->vendor) {
  484. case PCI_VENDOR_ID_ALTEON:
  485. if (pdev->device == PCI_DEVICE_ID_FARALLON_PN9100T) {
  486. printk(KERN_INFO "%s: Farallon PN9100-T ",
  487. ap->name);
  488. } else {
  489. printk(KERN_INFO "%s: Alteon AceNIC ",
  490. ap->name);
  491. }
  492. break;
  493. case PCI_VENDOR_ID_3COM:
  494. printk(KERN_INFO "%s: 3Com 3C985 ", ap->name);
  495. break;
  496. case PCI_VENDOR_ID_NETGEAR:
  497. printk(KERN_INFO "%s: NetGear GA620 ", ap->name);
  498. break;
  499. case PCI_VENDOR_ID_DEC:
  500. if (pdev->device == PCI_DEVICE_ID_FARALLON_PN9000SX) {
  501. printk(KERN_INFO "%s: Farallon PN9000-SX ",
  502. ap->name);
  503. break;
  504. }
  505. case PCI_VENDOR_ID_SGI:
  506. printk(KERN_INFO "%s: SGI AceNIC ", ap->name);
  507. break;
  508. default:
  509. printk(KERN_INFO "%s: Unknown AceNIC ", ap->name);
  510. break;
  511. }
  512. printk("Gigabit Ethernet at 0x%08lx, ", dev->base_addr);
  513. printk("irq %d\n", pdev->irq);
  514. #ifdef CONFIG_ACENIC_OMIT_TIGON_I
  515. if ((readl(&ap->regs->HostCtrl) >> 28) == 4) {
  516. printk(KERN_ERR "%s: Driver compiled without Tigon I"
  517. " support - NIC disabled\n", dev->name);
  518. goto fail_uninit;
  519. }
  520. #endif
  521. if (ace_allocate_descriptors(dev))
  522. goto fail_free_netdev;
  523. #ifdef MODULE
  524. if (boards_found >= ACE_MAX_MOD_PARMS)
  525. ap->board_idx = BOARD_IDX_OVERFLOW;
  526. else
  527. ap->board_idx = boards_found;
  528. #else
  529. ap->board_idx = BOARD_IDX_STATIC;
  530. #endif
  531. if (ace_init(dev))
  532. goto fail_free_netdev;
  533. if (register_netdev(dev)) {
  534. printk(KERN_ERR "acenic: device registration failed\n");
  535. goto fail_uninit;
  536. }
  537. ap->name = dev->name;
  538. if (ap->pci_using_dac)
  539. dev->features |= NETIF_F_HIGHDMA;
  540. pci_set_drvdata(pdev, dev);
  541. boards_found++;
  542. return 0;
  543. fail_uninit:
  544. ace_init_cleanup(dev);
  545. fail_free_netdev:
  546. free_netdev(dev);
  547. return -ENODEV;
  548. }
  549. static void __devexit acenic_remove_one(struct pci_dev *pdev)
  550. {
  551. struct net_device *dev = pci_get_drvdata(pdev);
  552. struct ace_private *ap = netdev_priv(dev);
  553. struct ace_regs __iomem *regs = ap->regs;
  554. short i;
  555. unregister_netdev(dev);
  556. writel(readl(&regs->CpuCtrl) | CPU_HALT, &regs->CpuCtrl);
  557. if (ap->version >= 2)
  558. writel(readl(&regs->CpuBCtrl) | CPU_HALT, &regs->CpuBCtrl);
  559. /*
  560. * This clears any pending interrupts
  561. */
  562. writel(1, &regs->Mb0Lo);
  563. readl(&regs->CpuCtrl); /* flush */
  564. /*
  565. * Make sure no other CPUs are processing interrupts
  566. * on the card before the buffers are being released.
  567. * Otherwise one might experience some `interesting'
  568. * effects.
  569. *
  570. * Then release the RX buffers - jumbo buffers were
  571. * already released in ace_close().
  572. */
  573. ace_sync_irq(dev->irq);
  574. for (i = 0; i < RX_STD_RING_ENTRIES; i++) {
  575. struct sk_buff *skb = ap->skb->rx_std_skbuff[i].skb;
  576. if (skb) {
  577. struct ring_info *ringp;
  578. dma_addr_t mapping;
  579. ringp = &ap->skb->rx_std_skbuff[i];
  580. mapping = pci_unmap_addr(ringp, mapping);
  581. pci_unmap_page(ap->pdev, mapping,
  582. ACE_STD_BUFSIZE,
  583. PCI_DMA_FROMDEVICE);
  584. ap->rx_std_ring[i].size = 0;
  585. ap->skb->rx_std_skbuff[i].skb = NULL;
  586. dev_kfree_skb(skb);
  587. }
  588. }
  589. if (ap->version >= 2) {
  590. for (i = 0; i < RX_MINI_RING_ENTRIES; i++) {
  591. struct sk_buff *skb = ap->skb->rx_mini_skbuff[i].skb;
  592. if (skb) {
  593. struct ring_info *ringp;
  594. dma_addr_t mapping;
  595. ringp = &ap->skb->rx_mini_skbuff[i];
  596. mapping = pci_unmap_addr(ringp,mapping);
  597. pci_unmap_page(ap->pdev, mapping,
  598. ACE_MINI_BUFSIZE,
  599. PCI_DMA_FROMDEVICE);
  600. ap->rx_mini_ring[i].size = 0;
  601. ap->skb->rx_mini_skbuff[i].skb = NULL;
  602. dev_kfree_skb(skb);
  603. }
  604. }
  605. }
  606. for (i = 0; i < RX_JUMBO_RING_ENTRIES; i++) {
  607. struct sk_buff *skb = ap->skb->rx_jumbo_skbuff[i].skb;
  608. if (skb) {
  609. struct ring_info *ringp;
  610. dma_addr_t mapping;
  611. ringp = &ap->skb->rx_jumbo_skbuff[i];
  612. mapping = pci_unmap_addr(ringp, mapping);
  613. pci_unmap_page(ap->pdev, mapping,
  614. ACE_JUMBO_BUFSIZE,
  615. PCI_DMA_FROMDEVICE);
  616. ap->rx_jumbo_ring[i].size = 0;
  617. ap->skb->rx_jumbo_skbuff[i].skb = NULL;
  618. dev_kfree_skb(skb);
  619. }
  620. }
  621. ace_init_cleanup(dev);
  622. free_netdev(dev);
  623. }
  624. static struct pci_driver acenic_pci_driver = {
  625. .name = "acenic",
  626. .id_table = acenic_pci_tbl,
  627. .probe = acenic_probe_one,
  628. .remove = __devexit_p(acenic_remove_one),
  629. };
  630. static int __init acenic_init(void)
  631. {
  632. return pci_register_driver(&acenic_pci_driver);
  633. }
  634. static void __exit acenic_exit(void)
  635. {
  636. pci_unregister_driver(&acenic_pci_driver);
  637. }
  638. module_init(acenic_init);
  639. module_exit(acenic_exit);
  640. static void ace_free_descriptors(struct net_device *dev)
  641. {
  642. struct ace_private *ap = netdev_priv(dev);
  643. int size;
  644. if (ap->rx_std_ring != NULL) {
  645. size = (sizeof(struct rx_desc) *
  646. (RX_STD_RING_ENTRIES +
  647. RX_JUMBO_RING_ENTRIES +
  648. RX_MINI_RING_ENTRIES +
  649. RX_RETURN_RING_ENTRIES));
  650. pci_free_consistent(ap->pdev, size, ap->rx_std_ring,
  651. ap->rx_ring_base_dma);
  652. ap->rx_std_ring = NULL;
  653. ap->rx_jumbo_ring = NULL;
  654. ap->rx_mini_ring = NULL;
  655. ap->rx_return_ring = NULL;
  656. }
  657. if (ap->evt_ring != NULL) {
  658. size = (sizeof(struct event) * EVT_RING_ENTRIES);
  659. pci_free_consistent(ap->pdev, size, ap->evt_ring,
  660. ap->evt_ring_dma);
  661. ap->evt_ring = NULL;
  662. }
  663. if (ap->tx_ring != NULL && !ACE_IS_TIGON_I(ap)) {
  664. size = (sizeof(struct tx_desc) * MAX_TX_RING_ENTRIES);
  665. pci_free_consistent(ap->pdev, size, ap->tx_ring,
  666. ap->tx_ring_dma);
  667. }
  668. ap->tx_ring = NULL;
  669. if (ap->evt_prd != NULL) {
  670. pci_free_consistent(ap->pdev, sizeof(u32),
  671. (void *)ap->evt_prd, ap->evt_prd_dma);
  672. ap->evt_prd = NULL;
  673. }
  674. if (ap->rx_ret_prd != NULL) {
  675. pci_free_consistent(ap->pdev, sizeof(u32),
  676. (void *)ap->rx_ret_prd,
  677. ap->rx_ret_prd_dma);
  678. ap->rx_ret_prd = NULL;
  679. }
  680. if (ap->tx_csm != NULL) {
  681. pci_free_consistent(ap->pdev, sizeof(u32),
  682. (void *)ap->tx_csm, ap->tx_csm_dma);
  683. ap->tx_csm = NULL;
  684. }
  685. }
  686. static int ace_allocate_descriptors(struct net_device *dev)
  687. {
  688. struct ace_private *ap = netdev_priv(dev);
  689. int size;
  690. size = (sizeof(struct rx_desc) *
  691. (RX_STD_RING_ENTRIES +
  692. RX_JUMBO_RING_ENTRIES +
  693. RX_MINI_RING_ENTRIES +
  694. RX_RETURN_RING_ENTRIES));
  695. ap->rx_std_ring = pci_alloc_consistent(ap->pdev, size,
  696. &ap->rx_ring_base_dma);
  697. if (ap->rx_std_ring == NULL)
  698. goto fail;
  699. ap->rx_jumbo_ring = ap->rx_std_ring + RX_STD_RING_ENTRIES;
  700. ap->rx_mini_ring = ap->rx_jumbo_ring + RX_JUMBO_RING_ENTRIES;
  701. ap->rx_return_ring = ap->rx_mini_ring + RX_MINI_RING_ENTRIES;
  702. size = (sizeof(struct event) * EVT_RING_ENTRIES);
  703. ap->evt_ring = pci_alloc_consistent(ap->pdev, size, &ap->evt_ring_dma);
  704. if (ap->evt_ring == NULL)
  705. goto fail;
  706. /*
  707. * Only allocate a host TX ring for the Tigon II, the Tigon I
  708. * has to use PCI registers for this ;-(
  709. */
  710. if (!ACE_IS_TIGON_I(ap)) {
  711. size = (sizeof(struct tx_desc) * MAX_TX_RING_ENTRIES);
  712. ap->tx_ring = pci_alloc_consistent(ap->pdev, size,
  713. &ap->tx_ring_dma);
  714. if (ap->tx_ring == NULL)
  715. goto fail;
  716. }
  717. ap->evt_prd = pci_alloc_consistent(ap->pdev, sizeof(u32),
  718. &ap->evt_prd_dma);
  719. if (ap->evt_prd == NULL)
  720. goto fail;
  721. ap->rx_ret_prd = pci_alloc_consistent(ap->pdev, sizeof(u32),
  722. &ap->rx_ret_prd_dma);
  723. if (ap->rx_ret_prd == NULL)
  724. goto fail;
  725. ap->tx_csm = pci_alloc_consistent(ap->pdev, sizeof(u32),
  726. &ap->tx_csm_dma);
  727. if (ap->tx_csm == NULL)
  728. goto fail;
  729. return 0;
  730. fail:
  731. /* Clean up. */
  732. ace_init_cleanup(dev);
  733. return 1;
  734. }
  735. /*
  736. * Generic cleanup handling data allocated during init. Used when the
  737. * module is unloaded or if an error occurs during initialization
  738. */
  739. static void ace_init_cleanup(struct net_device *dev)
  740. {
  741. struct ace_private *ap;
  742. ap = netdev_priv(dev);
  743. ace_free_descriptors(dev);
  744. if (ap->info)
  745. pci_free_consistent(ap->pdev, sizeof(struct ace_info),
  746. ap->info, ap->info_dma);
  747. kfree(ap->skb);
  748. kfree(ap->trace_buf);
  749. if (dev->irq)
  750. free_irq(dev->irq, dev);
  751. iounmap(ap->regs);
  752. }
  753. /*
  754. * Commands are considered to be slow.
  755. */
  756. static inline void ace_issue_cmd(struct ace_regs __iomem *regs, struct cmd *cmd)
  757. {
  758. u32 idx;
  759. idx = readl(&regs->CmdPrd);
  760. writel(*(u32 *)(cmd), &regs->CmdRng[idx]);
  761. idx = (idx + 1) % CMD_RING_ENTRIES;
  762. writel(idx, &regs->CmdPrd);
  763. }
  764. static int __devinit ace_init(struct net_device *dev)
  765. {
  766. struct ace_private *ap;
  767. struct ace_regs __iomem *regs;
  768. struct ace_info *info = NULL;
  769. struct pci_dev *pdev;
  770. unsigned long myjif;
  771. u64 tmp_ptr;
  772. u32 tig_ver, mac1, mac2, tmp, pci_state;
  773. int board_idx, ecode = 0;
  774. short i;
  775. unsigned char cache_size;
  776. DECLARE_MAC_BUF(mac);
  777. ap = netdev_priv(dev);
  778. regs = ap->regs;
  779. board_idx = ap->board_idx;
  780. /*
  781. * aman@sgi.com - its useful to do a NIC reset here to
  782. * address the `Firmware not running' problem subsequent
  783. * to any crashes involving the NIC
  784. */
  785. writel(HW_RESET | (HW_RESET << 24), &regs->HostCtrl);
  786. readl(&regs->HostCtrl); /* PCI write posting */
  787. udelay(5);
  788. /*
  789. * Don't access any other registers before this point!
  790. */
  791. #ifdef __BIG_ENDIAN
  792. /*
  793. * This will most likely need BYTE_SWAP once we switch
  794. * to using __raw_writel()
  795. */
  796. writel((WORD_SWAP | CLR_INT | ((WORD_SWAP | CLR_INT) << 24)),
  797. &regs->HostCtrl);
  798. #else
  799. writel((CLR_INT | WORD_SWAP | ((CLR_INT | WORD_SWAP) << 24)),
  800. &regs->HostCtrl);
  801. #endif
  802. readl(&regs->HostCtrl); /* PCI write posting */
  803. /*
  804. * Stop the NIC CPU and clear pending interrupts
  805. */
  806. writel(readl(&regs->CpuCtrl) | CPU_HALT, &regs->CpuCtrl);
  807. readl(&regs->CpuCtrl); /* PCI write posting */
  808. writel(0, &regs->Mb0Lo);
  809. tig_ver = readl(&regs->HostCtrl) >> 28;
  810. switch(tig_ver){
  811. #ifndef CONFIG_ACENIC_OMIT_TIGON_I
  812. case 4:
  813. case 5:
  814. printk(KERN_INFO " Tigon I (Rev. %i), Firmware: %i.%i.%i, ",
  815. tig_ver, tigonFwReleaseMajor, tigonFwReleaseMinor,
  816. tigonFwReleaseFix);
  817. writel(0, &regs->LocalCtrl);
  818. ap->version = 1;
  819. ap->tx_ring_entries = TIGON_I_TX_RING_ENTRIES;
  820. break;
  821. #endif
  822. case 6:
  823. printk(KERN_INFO " Tigon II (Rev. %i), Firmware: %i.%i.%i, ",
  824. tig_ver, tigon2FwReleaseMajor, tigon2FwReleaseMinor,
  825. tigon2FwReleaseFix);
  826. writel(readl(&regs->CpuBCtrl) | CPU_HALT, &regs->CpuBCtrl);
  827. readl(&regs->CpuBCtrl); /* PCI write posting */
  828. /*
  829. * The SRAM bank size does _not_ indicate the amount
  830. * of memory on the card, it controls the _bank_ size!
  831. * Ie. a 1MB AceNIC will have two banks of 512KB.
  832. */
  833. writel(SRAM_BANK_512K, &regs->LocalCtrl);
  834. writel(SYNC_SRAM_TIMING, &regs->MiscCfg);
  835. ap->version = 2;
  836. ap->tx_ring_entries = MAX_TX_RING_ENTRIES;
  837. break;
  838. default:
  839. printk(KERN_WARNING " Unsupported Tigon version detected "
  840. "(%i)\n", tig_ver);
  841. ecode = -ENODEV;
  842. goto init_error;
  843. }
  844. /*
  845. * ModeStat _must_ be set after the SRAM settings as this change
  846. * seems to corrupt the ModeStat and possible other registers.
  847. * The SRAM settings survive resets and setting it to the same
  848. * value a second time works as well. This is what caused the
  849. * `Firmware not running' problem on the Tigon II.
  850. */
  851. #ifdef __BIG_ENDIAN
  852. writel(ACE_BYTE_SWAP_DMA | ACE_WARN | ACE_FATAL | ACE_BYTE_SWAP_BD |
  853. ACE_WORD_SWAP_BD | ACE_NO_JUMBO_FRAG, &regs->ModeStat);
  854. #else
  855. writel(ACE_BYTE_SWAP_DMA | ACE_WARN | ACE_FATAL |
  856. ACE_WORD_SWAP_BD | ACE_NO_JUMBO_FRAG, &regs->ModeStat);
  857. #endif
  858. readl(&regs->ModeStat); /* PCI write posting */
  859. mac1 = 0;
  860. for(i = 0; i < 4; i++) {
  861. int t;
  862. mac1 = mac1 << 8;
  863. t = read_eeprom_byte(dev, 0x8c+i);
  864. if (t < 0) {
  865. ecode = -EIO;
  866. goto init_error;
  867. } else
  868. mac1 |= (t & 0xff);
  869. }
  870. mac2 = 0;
  871. for(i = 4; i < 8; i++) {
  872. int t;
  873. mac2 = mac2 << 8;
  874. t = read_eeprom_byte(dev, 0x8c+i);
  875. if (t < 0) {
  876. ecode = -EIO;
  877. goto init_error;
  878. } else
  879. mac2 |= (t & 0xff);
  880. }
  881. writel(mac1, &regs->MacAddrHi);
  882. writel(mac2, &regs->MacAddrLo);
  883. dev->dev_addr[0] = (mac1 >> 8) & 0xff;
  884. dev->dev_addr[1] = mac1 & 0xff;
  885. dev->dev_addr[2] = (mac2 >> 24) & 0xff;
  886. dev->dev_addr[3] = (mac2 >> 16) & 0xff;
  887. dev->dev_addr[4] = (mac2 >> 8) & 0xff;
  888. dev->dev_addr[5] = mac2 & 0xff;
  889. printk("MAC: %s\n", print_mac(mac, dev->dev_addr));
  890. /*
  891. * Looks like this is necessary to deal with on all architectures,
  892. * even this %$#%$# N440BX Intel based thing doesn't get it right.
  893. * Ie. having two NICs in the machine, one will have the cache
  894. * line set at boot time, the other will not.
  895. */
  896. pdev = ap->pdev;
  897. pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &cache_size);
  898. cache_size <<= 2;
  899. if (cache_size != SMP_CACHE_BYTES) {
  900. printk(KERN_INFO " PCI cache line size set incorrectly "
  901. "(%i bytes) by BIOS/FW, ", cache_size);
  902. if (cache_size > SMP_CACHE_BYTES)
  903. printk("expecting %i\n", SMP_CACHE_BYTES);
  904. else {
  905. printk("correcting to %i\n", SMP_CACHE_BYTES);
  906. pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
  907. SMP_CACHE_BYTES >> 2);
  908. }
  909. }
  910. pci_state = readl(&regs->PciState);
  911. printk(KERN_INFO " PCI bus width: %i bits, speed: %iMHz, "
  912. "latency: %i clks\n",
  913. (pci_state & PCI_32BIT) ? 32 : 64,
  914. (pci_state & PCI_66MHZ) ? 66 : 33,
  915. ap->pci_latency);
  916. /*
  917. * Set the max DMA transfer size. Seems that for most systems
  918. * the performance is better when no MAX parameter is
  919. * set. However for systems enabling PCI write and invalidate,
  920. * DMA writes must be set to the L1 cache line size to get
  921. * optimal performance.
  922. *
  923. * The default is now to turn the PCI write and invalidate off
  924. * - that is what Alteon does for NT.
  925. */
  926. tmp = READ_CMD_MEM | WRITE_CMD_MEM;
  927. if (ap->version >= 2) {
  928. tmp |= (MEM_READ_MULTIPLE | (pci_state & PCI_66MHZ));
  929. /*
  930. * Tuning parameters only supported for 8 cards
  931. */
  932. if (board_idx == BOARD_IDX_OVERFLOW ||
  933. dis_pci_mem_inval[board_idx]) {
  934. if (ap->pci_command & PCI_COMMAND_INVALIDATE) {
  935. ap->pci_command &= ~PCI_COMMAND_INVALIDATE;
  936. pci_write_config_word(pdev, PCI_COMMAND,
  937. ap->pci_command);
  938. printk(KERN_INFO " Disabling PCI memory "
  939. "write and invalidate\n");
  940. }
  941. } else if (ap->pci_command & PCI_COMMAND_INVALIDATE) {
  942. printk(KERN_INFO " PCI memory write & invalidate "
  943. "enabled by BIOS, enabling counter measures\n");
  944. switch(SMP_CACHE_BYTES) {
  945. case 16:
  946. tmp |= DMA_WRITE_MAX_16;
  947. break;
  948. case 32:
  949. tmp |= DMA_WRITE_MAX_32;
  950. break;
  951. case 64:
  952. tmp |= DMA_WRITE_MAX_64;
  953. break;
  954. case 128:
  955. tmp |= DMA_WRITE_MAX_128;
  956. break;
  957. default:
  958. printk(KERN_INFO " Cache line size %i not "
  959. "supported, PCI write and invalidate "
  960. "disabled\n", SMP_CACHE_BYTES);
  961. ap->pci_command &= ~PCI_COMMAND_INVALIDATE;
  962. pci_write_config_word(pdev, PCI_COMMAND,
  963. ap->pci_command);
  964. }
  965. }
  966. }
  967. #ifdef __sparc__
  968. /*
  969. * On this platform, we know what the best dma settings
  970. * are. We use 64-byte maximum bursts, because if we
  971. * burst larger than the cache line size (or even cross
  972. * a 64byte boundary in a single burst) the UltraSparc
  973. * PCI controller will disconnect at 64-byte multiples.
  974. *
  975. * Read-multiple will be properly enabled above, and when
  976. * set will give the PCI controller proper hints about
  977. * prefetching.
  978. */
  979. tmp &= ~DMA_READ_WRITE_MASK;
  980. tmp |= DMA_READ_MAX_64;
  981. tmp |= DMA_WRITE_MAX_64;
  982. #endif
  983. #ifdef __alpha__
  984. tmp &= ~DMA_READ_WRITE_MASK;
  985. tmp |= DMA_READ_MAX_128;
  986. /*
  987. * All the docs say MUST NOT. Well, I did.
  988. * Nothing terrible happens, if we load wrong size.
  989. * Bit w&i still works better!
  990. */
  991. tmp |= DMA_WRITE_MAX_128;
  992. #endif
  993. writel(tmp, &regs->PciState);
  994. #if 0
  995. /*
  996. * The Host PCI bus controller driver has to set FBB.
  997. * If all devices on that PCI bus support FBB, then the controller
  998. * can enable FBB support in the Host PCI Bus controller (or on
  999. * the PCI-PCI bridge if that applies).
  1000. * -ggg
  1001. */
  1002. /*
  1003. * I have received reports from people having problems when this
  1004. * bit is enabled.
  1005. */
  1006. if (!(ap->pci_command & PCI_COMMAND_FAST_BACK)) {
  1007. printk(KERN_INFO " Enabling PCI Fast Back to Back\n");
  1008. ap->pci_command |= PCI_COMMAND_FAST_BACK;
  1009. pci_write_config_word(pdev, PCI_COMMAND, ap->pci_command);
  1010. }
  1011. #endif
  1012. /*
  1013. * Configure DMA attributes.
  1014. */
  1015. if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
  1016. ap->pci_using_dac = 1;
  1017. } else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
  1018. ap->pci_using_dac = 0;
  1019. } else {
  1020. ecode = -ENODEV;
  1021. goto init_error;
  1022. }
  1023. /*
  1024. * Initialize the generic info block and the command+event rings
  1025. * and the control blocks for the transmit and receive rings
  1026. * as they need to be setup once and for all.
  1027. */
  1028. if (!(info = pci_alloc_consistent(ap->pdev, sizeof(struct ace_info),
  1029. &ap->info_dma))) {
  1030. ecode = -EAGAIN;
  1031. goto init_error;
  1032. }
  1033. ap->info = info;
  1034. /*
  1035. * Get the memory for the skb rings.
  1036. */
  1037. if (!(ap->skb = kmalloc(sizeof(struct ace_skb), GFP_KERNEL))) {
  1038. ecode = -EAGAIN;
  1039. goto init_error;
  1040. }
  1041. ecode = request_irq(pdev->irq, ace_interrupt, IRQF_SHARED,
  1042. DRV_NAME, dev);
  1043. if (ecode) {
  1044. printk(KERN_WARNING "%s: Requested IRQ %d is busy\n",
  1045. DRV_NAME, pdev->irq);
  1046. goto init_error;
  1047. } else
  1048. dev->irq = pdev->irq;
  1049. #ifdef INDEX_DEBUG
  1050. spin_lock_init(&ap->debug_lock);
  1051. ap->last_tx = ACE_TX_RING_ENTRIES(ap) - 1;
  1052. ap->last_std_rx = 0;
  1053. ap->last_mini_rx = 0;
  1054. #endif
  1055. memset(ap->info, 0, sizeof(struct ace_info));
  1056. memset(ap->skb, 0, sizeof(struct ace_skb));
  1057. ace_load_firmware(dev);
  1058. ap->fw_running = 0;
  1059. tmp_ptr = ap->info_dma;
  1060. writel(tmp_ptr >> 32, &regs->InfoPtrHi);
  1061. writel(tmp_ptr & 0xffffffff, &regs->InfoPtrLo);
  1062. memset(ap->evt_ring, 0, EVT_RING_ENTRIES * sizeof(struct event));
  1063. set_aceaddr(&info->evt_ctrl.rngptr, ap->evt_ring_dma);
  1064. info->evt_ctrl.flags = 0;
  1065. *(ap->evt_prd) = 0;
  1066. wmb();
  1067. set_aceaddr(&info->evt_prd_ptr, ap->evt_prd_dma);
  1068. writel(0, &regs->EvtCsm);
  1069. set_aceaddr(&info->cmd_ctrl.rngptr, 0x100);
  1070. info->cmd_ctrl.flags = 0;
  1071. info->cmd_ctrl.max_len = 0;
  1072. for (i = 0; i < CMD_RING_ENTRIES; i++)
  1073. writel(0, &regs->CmdRng[i]);
  1074. writel(0, &regs->CmdPrd);
  1075. writel(0, &regs->CmdCsm);
  1076. tmp_ptr = ap->info_dma;
  1077. tmp_ptr += (unsigned long) &(((struct ace_info *)0)->s.stats);
  1078. set_aceaddr(&info->stats2_ptr, (dma_addr_t) tmp_ptr);
  1079. set_aceaddr(&info->rx_std_ctrl.rngptr, ap->rx_ring_base_dma);
  1080. info->rx_std_ctrl.max_len = ACE_STD_BUFSIZE;
  1081. info->rx_std_ctrl.flags =
  1082. RCB_FLG_TCP_UDP_SUM | RCB_FLG_NO_PSEUDO_HDR | ACE_RCB_VLAN_FLAG;
  1083. memset(ap->rx_std_ring, 0,
  1084. RX_STD_RING_ENTRIES * sizeof(struct rx_desc));
  1085. for (i = 0; i < RX_STD_RING_ENTRIES; i++)
  1086. ap->rx_std_ring[i].flags = BD_FLG_TCP_UDP_SUM;
  1087. ap->rx_std_skbprd = 0;
  1088. atomic_set(&ap->cur_rx_bufs, 0);
  1089. set_aceaddr(&info->rx_jumbo_ctrl.rngptr,
  1090. (ap->rx_ring_base_dma +
  1091. (sizeof(struct rx_desc) * RX_STD_RING_ENTRIES)));
  1092. info->rx_jumbo_ctrl.max_len = 0;
  1093. info->rx_jumbo_ctrl.flags =
  1094. RCB_FLG_TCP_UDP_SUM | RCB_FLG_NO_PSEUDO_HDR | ACE_RCB_VLAN_FLAG;
  1095. memset(ap->rx_jumbo_ring, 0,
  1096. RX_JUMBO_RING_ENTRIES * sizeof(struct rx_desc));
  1097. for (i = 0; i < RX_JUMBO_RING_ENTRIES; i++)
  1098. ap->rx_jumbo_ring[i].flags = BD_FLG_TCP_UDP_SUM | BD_FLG_JUMBO;
  1099. ap->rx_jumbo_skbprd = 0;
  1100. atomic_set(&ap->cur_jumbo_bufs, 0);
  1101. memset(ap->rx_mini_ring, 0,
  1102. RX_MINI_RING_ENTRIES * sizeof(struct rx_desc));
  1103. if (ap->version >= 2) {
  1104. set_aceaddr(&info->rx_mini_ctrl.rngptr,
  1105. (ap->rx_ring_base_dma +
  1106. (sizeof(struct rx_desc) *
  1107. (RX_STD_RING_ENTRIES +
  1108. RX_JUMBO_RING_ENTRIES))));
  1109. info->rx_mini_ctrl.max_len = ACE_MINI_SIZE;
  1110. info->rx_mini_ctrl.flags =
  1111. RCB_FLG_TCP_UDP_SUM|RCB_FLG_NO_PSEUDO_HDR|ACE_RCB_VLAN_FLAG;
  1112. for (i = 0; i < RX_MINI_RING_ENTRIES; i++)
  1113. ap->rx_mini_ring[i].flags =
  1114. BD_FLG_TCP_UDP_SUM | BD_FLG_MINI;
  1115. } else {
  1116. set_aceaddr(&info->rx_mini_ctrl.rngptr, 0);
  1117. info->rx_mini_ctrl.flags = RCB_FLG_RNG_DISABLE;
  1118. info->rx_mini_ctrl.max_len = 0;
  1119. }
  1120. ap->rx_mini_skbprd = 0;
  1121. atomic_set(&ap->cur_mini_bufs, 0);
  1122. set_aceaddr(&info->rx_return_ctrl.rngptr,
  1123. (ap->rx_ring_base_dma +
  1124. (sizeof(struct rx_desc) *
  1125. (RX_STD_RING_ENTRIES +
  1126. RX_JUMBO_RING_ENTRIES +
  1127. RX_MINI_RING_ENTRIES))));
  1128. info->rx_return_ctrl.flags = 0;
  1129. info->rx_return_ctrl.max_len = RX_RETURN_RING_ENTRIES;
  1130. memset(ap->rx_return_ring, 0,
  1131. RX_RETURN_RING_ENTRIES * sizeof(struct rx_desc));
  1132. set_aceaddr(&info->rx_ret_prd_ptr, ap->rx_ret_prd_dma);
  1133. *(ap->rx_ret_prd) = 0;
  1134. writel(TX_RING_BASE, &regs->WinBase);
  1135. if (ACE_IS_TIGON_I(ap)) {
  1136. ap->tx_ring = (__force struct tx_desc *) regs->Window;
  1137. for (i = 0; i < (TIGON_I_TX_RING_ENTRIES
  1138. * sizeof(struct tx_desc)) / sizeof(u32); i++)
  1139. writel(0, (__force void __iomem *)ap->tx_ring + i * 4);
  1140. set_aceaddr(&info->tx_ctrl.rngptr, TX_RING_BASE);
  1141. } else {
  1142. memset(ap->tx_ring, 0,
  1143. MAX_TX_RING_ENTRIES * sizeof(struct tx_desc));
  1144. set_aceaddr(&info->tx_ctrl.rngptr, ap->tx_ring_dma);
  1145. }
  1146. info->tx_ctrl.max_len = ACE_TX_RING_ENTRIES(ap);
  1147. tmp = RCB_FLG_TCP_UDP_SUM | RCB_FLG_NO_PSEUDO_HDR | ACE_RCB_VLAN_FLAG;
  1148. /*
  1149. * The Tigon I does not like having the TX ring in host memory ;-(
  1150. */
  1151. if (!ACE_IS_TIGON_I(ap))
  1152. tmp |= RCB_FLG_TX_HOST_RING;
  1153. #if TX_COAL_INTS_ONLY
  1154. tmp |= RCB_FLG_COAL_INT_ONLY;
  1155. #endif
  1156. info->tx_ctrl.flags = tmp;
  1157. set_aceaddr(&info->tx_csm_ptr, ap->tx_csm_dma);
  1158. /*
  1159. * Potential item for tuning parameter
  1160. */
  1161. #if 0 /* NO */
  1162. writel(DMA_THRESH_16W, &regs->DmaReadCfg);
  1163. writel(DMA_THRESH_16W, &regs->DmaWriteCfg);
  1164. #else
  1165. writel(DMA_THRESH_8W, &regs->DmaReadCfg);
  1166. writel(DMA_THRESH_8W, &regs->DmaWriteCfg);
  1167. #endif
  1168. writel(0, &regs->MaskInt);
  1169. writel(1, &regs->IfIdx);
  1170. #if 0
  1171. /*
  1172. * McKinley boxes do not like us fiddling with AssistState
  1173. * this early
  1174. */
  1175. writel(1, &regs->AssistState);
  1176. #endif
  1177. writel(DEF_STAT, &regs->TuneStatTicks);
  1178. writel(DEF_TRACE, &regs->TuneTrace);
  1179. ace_set_rxtx_parms(dev, 0);
  1180. if (board_idx == BOARD_IDX_OVERFLOW) {
  1181. printk(KERN_WARNING "%s: more than %i NICs detected, "
  1182. "ignoring module parameters!\n",
  1183. ap->name, ACE_MAX_MOD_PARMS);
  1184. } else if (board_idx >= 0) {
  1185. if (tx_coal_tick[board_idx])
  1186. writel(tx_coal_tick[board_idx],
  1187. &regs->TuneTxCoalTicks);
  1188. if (max_tx_desc[board_idx])
  1189. writel(max_tx_desc[board_idx], &regs->TuneMaxTxDesc);
  1190. if (rx_coal_tick[board_idx])
  1191. writel(rx_coal_tick[board_idx],
  1192. &regs->TuneRxCoalTicks);
  1193. if (max_rx_desc[board_idx])
  1194. writel(max_rx_desc[board_idx], &regs->TuneMaxRxDesc);
  1195. if (trace[board_idx])
  1196. writel(trace[board_idx], &regs->TuneTrace);
  1197. if ((tx_ratio[board_idx] > 0) && (tx_ratio[board_idx] < 64))
  1198. writel(tx_ratio[board_idx], &regs->TxBufRat);
  1199. }
  1200. /*
  1201. * Default link parameters
  1202. */
  1203. tmp = LNK_ENABLE | LNK_FULL_DUPLEX | LNK_1000MB | LNK_100MB |
  1204. LNK_10MB | LNK_RX_FLOW_CTL_Y | LNK_NEG_FCTL | LNK_NEGOTIATE;
  1205. if(ap->version >= 2)
  1206. tmp |= LNK_TX_FLOW_CTL_Y;
  1207. /*
  1208. * Override link default parameters
  1209. */
  1210. if ((board_idx >= 0) && link_state[board_idx]) {
  1211. int option = link_state[board_idx];
  1212. tmp = LNK_ENABLE;
  1213. if (option & 0x01) {
  1214. printk(KERN_INFO "%s: Setting half duplex link\n",
  1215. ap->name);
  1216. tmp &= ~LNK_FULL_DUPLEX;
  1217. }
  1218. if (option & 0x02)
  1219. tmp &= ~LNK_NEGOTIATE;
  1220. if (option & 0x10)
  1221. tmp |= LNK_10MB;
  1222. if (option & 0x20)
  1223. tmp |= LNK_100MB;
  1224. if (option & 0x40)
  1225. tmp |= LNK_1000MB;
  1226. if ((option & 0x70) == 0) {
  1227. printk(KERN_WARNING "%s: No media speed specified, "
  1228. "forcing auto negotiation\n", ap->name);
  1229. tmp |= LNK_NEGOTIATE | LNK_1000MB |
  1230. LNK_100MB | LNK_10MB;
  1231. }
  1232. if ((option & 0x100) == 0)
  1233. tmp |= LNK_NEG_FCTL;
  1234. else
  1235. printk(KERN_INFO "%s: Disabling flow control "
  1236. "negotiation\n", ap->name);
  1237. if (option & 0x200)
  1238. tmp |= LNK_RX_FLOW_CTL_Y;
  1239. if ((option & 0x400) && (ap->version >= 2)) {
  1240. printk(KERN_INFO "%s: Enabling TX flow control\n",
  1241. ap->name);
  1242. tmp |= LNK_TX_FLOW_CTL_Y;
  1243. }
  1244. }
  1245. ap->link = tmp;
  1246. writel(tmp, &regs->TuneLink);
  1247. if (ap->version >= 2)
  1248. writel(tmp, &regs->TuneFastLink);
  1249. if (ACE_IS_TIGON_I(ap))
  1250. writel(tigonFwStartAddr, &regs->Pc);
  1251. if (ap->version == 2)
  1252. writel(tigon2FwStartAddr, &regs->Pc);
  1253. writel(0, &regs->Mb0Lo);
  1254. /*
  1255. * Set tx_csm before we start receiving interrupts, otherwise
  1256. * the interrupt handler might think it is supposed to process
  1257. * tx ints before we are up and running, which may cause a null
  1258. * pointer access in the int handler.
  1259. */
  1260. ap->cur_rx = 0;
  1261. ap->tx_prd = *(ap->tx_csm) = ap->tx_ret_csm = 0;
  1262. wmb();
  1263. ace_set_txprd(regs, ap, 0);
  1264. writel(0, &regs->RxRetCsm);
  1265. /*
  1266. * Enable DMA engine now.
  1267. * If we do this sooner, Mckinley box pukes.
  1268. * I assume it's because Tigon II DMA engine wants to check
  1269. * *something* even before the CPU is started.
  1270. */
  1271. writel(1, &regs->AssistState); /* enable DMA */
  1272. /*
  1273. * Start the NIC CPU
  1274. */
  1275. writel(readl(&regs->CpuCtrl) & ~(CPU_HALT|CPU_TRACE), &regs->CpuCtrl);
  1276. readl(&regs->CpuCtrl);
  1277. /*
  1278. * Wait for the firmware to spin up - max 3 seconds.
  1279. */
  1280. myjif = jiffies + 3 * HZ;
  1281. while (time_before(jiffies, myjif) && !ap->fw_running)
  1282. cpu_relax();
  1283. if (!ap->fw_running) {
  1284. printk(KERN_ERR "%s: Firmware NOT running!\n", ap->name);
  1285. ace_dump_trace(ap);
  1286. writel(readl(&regs->CpuCtrl) | CPU_HALT, &regs->CpuCtrl);
  1287. readl(&regs->CpuCtrl);
  1288. /* aman@sgi.com - account for badly behaving firmware/NIC:
  1289. * - have observed that the NIC may continue to generate
  1290. * interrupts for some reason; attempt to stop it - halt
  1291. * second CPU for Tigon II cards, and also clear Mb0
  1292. * - if we're a module, we'll fail to load if this was
  1293. * the only GbE card in the system => if the kernel does
  1294. * see an interrupt from the NIC, code to handle it is
  1295. * gone and OOps! - so free_irq also
  1296. */
  1297. if (ap->version >= 2)
  1298. writel(readl(&regs->CpuBCtrl) | CPU_HALT,
  1299. &regs->CpuBCtrl);
  1300. writel(0, &regs->Mb0Lo);
  1301. readl(&regs->Mb0Lo);
  1302. ecode = -EBUSY;
  1303. goto init_error;
  1304. }
  1305. /*
  1306. * We load the ring here as there seem to be no way to tell the
  1307. * firmware to wipe the ring without re-initializing it.
  1308. */
  1309. if (!test_and_set_bit(0, &ap->std_refill_busy))
  1310. ace_load_std_rx_ring(ap, RX_RING_SIZE);
  1311. else
  1312. printk(KERN_ERR "%s: Someone is busy refilling the RX ring\n",
  1313. ap->name);
  1314. if (ap->version >= 2) {
  1315. if (!test_and_set_bit(0, &ap->mini_refill_busy))
  1316. ace_load_mini_rx_ring(ap, RX_MINI_SIZE);
  1317. else
  1318. printk(KERN_ERR "%s: Someone is busy refilling "
  1319. "the RX mini ring\n", ap->name);
  1320. }
  1321. return 0;
  1322. init_error:
  1323. ace_init_cleanup(dev);
  1324. return ecode;
  1325. }
  1326. static void ace_set_rxtx_parms(struct net_device *dev, int jumbo)
  1327. {
  1328. struct ace_private *ap = netdev_priv(dev);
  1329. struct ace_regs __iomem *regs = ap->regs;
  1330. int board_idx = ap->board_idx;
  1331. if (board_idx >= 0) {
  1332. if (!jumbo) {
  1333. if (!tx_coal_tick[board_idx])
  1334. writel(DEF_TX_COAL, &regs->TuneTxCoalTicks);
  1335. if (!max_tx_desc[board_idx])
  1336. writel(DEF_TX_MAX_DESC, &regs->TuneMaxTxDesc);
  1337. if (!rx_coal_tick[board_idx])
  1338. writel(DEF_RX_COAL, &regs->TuneRxCoalTicks);
  1339. if (!max_rx_desc[board_idx])
  1340. writel(DEF_RX_MAX_DESC, &regs->TuneMaxRxDesc);
  1341. if (!tx_ratio[board_idx])
  1342. writel(DEF_TX_RATIO, &regs->TxBufRat);
  1343. } else {
  1344. if (!tx_coal_tick[board_idx])
  1345. writel(DEF_JUMBO_TX_COAL,
  1346. &regs->TuneTxCoalTicks);
  1347. if (!max_tx_desc[board_idx])
  1348. writel(DEF_JUMBO_TX_MAX_DESC,
  1349. &regs->TuneMaxTxDesc);
  1350. if (!rx_coal_tick[board_idx])
  1351. writel(DEF_JUMBO_RX_COAL,
  1352. &regs->TuneRxCoalTicks);
  1353. if (!max_rx_desc[board_idx])
  1354. writel(DEF_JUMBO_RX_MAX_DESC,
  1355. &regs->TuneMaxRxDesc);
  1356. if (!tx_ratio[board_idx])
  1357. writel(DEF_JUMBO_TX_RATIO, &regs->TxBufRat);
  1358. }
  1359. }
  1360. }
  1361. static void ace_watchdog(struct net_device *data)
  1362. {
  1363. struct net_device *dev = data;
  1364. struct ace_private *ap = netdev_priv(dev);
  1365. struct ace_regs __iomem *regs = ap->regs;
  1366. /*
  1367. * We haven't received a stats update event for more than 2.5
  1368. * seconds and there is data in the transmit queue, thus we
  1369. * asume the card is stuck.
  1370. */
  1371. if (*ap->tx_csm != ap->tx_ret_csm) {
  1372. printk(KERN_WARNING "%s: Transmitter is stuck, %08x\n",
  1373. dev->name, (unsigned int)readl(&regs->HostCtrl));
  1374. /* This can happen due to ieee flow control. */
  1375. } else {
  1376. printk(KERN_DEBUG "%s: BUG... transmitter died. Kicking it.\n",
  1377. dev->name);
  1378. #if 0
  1379. netif_wake_queue(dev);
  1380. #endif
  1381. }
  1382. }
  1383. static void ace_tasklet(unsigned long dev)
  1384. {
  1385. struct ace_private *ap = netdev_priv((struct net_device *)dev);
  1386. int cur_size;
  1387. cur_size = atomic_read(&ap->cur_rx_bufs);
  1388. if ((cur_size < RX_LOW_STD_THRES) &&
  1389. !test_and_set_bit(0, &ap->std_refill_busy)) {
  1390. #ifdef DEBUG
  1391. printk("refilling buffers (current %i)\n", cur_size);
  1392. #endif
  1393. ace_load_std_rx_ring(ap, RX_RING_SIZE - cur_size);
  1394. }
  1395. if (ap->version >= 2) {
  1396. cur_size = atomic_read(&ap->cur_mini_bufs);
  1397. if ((cur_size < RX_LOW_MINI_THRES) &&
  1398. !test_and_set_bit(0, &ap->mini_refill_busy)) {
  1399. #ifdef DEBUG
  1400. printk("refilling mini buffers (current %i)\n",
  1401. cur_size);
  1402. #endif
  1403. ace_load_mini_rx_ring(ap, RX_MINI_SIZE - cur_size);
  1404. }
  1405. }
  1406. cur_size = atomic_read(&ap->cur_jumbo_bufs);
  1407. if (ap->jumbo && (cur_size < RX_LOW_JUMBO_THRES) &&
  1408. !test_and_set_bit(0, &ap->jumbo_refill_busy)) {
  1409. #ifdef DEBUG
  1410. printk("refilling jumbo buffers (current %i)\n", cur_size);
  1411. #endif
  1412. ace_load_jumbo_rx_ring(ap, RX_JUMBO_SIZE - cur_size);
  1413. }
  1414. ap->tasklet_pending = 0;
  1415. }
  1416. /*
  1417. * Copy the contents of the NIC's trace buffer to kernel memory.
  1418. */
  1419. static void ace_dump_trace(struct ace_private *ap)
  1420. {
  1421. #if 0
  1422. if (!ap->trace_buf)
  1423. if (!(ap->trace_buf = kmalloc(ACE_TRACE_SIZE, GFP_KERNEL)))
  1424. return;
  1425. #endif
  1426. }
  1427. /*
  1428. * Load the standard rx ring.
  1429. *
  1430. * Loading rings is safe without holding the spin lock since this is
  1431. * done only before the device is enabled, thus no interrupts are
  1432. * generated and by the interrupt handler/tasklet handler.
  1433. */
  1434. static void ace_load_std_rx_ring(struct ace_private *ap, int nr_bufs)
  1435. {
  1436. struct ace_regs __iomem *regs = ap->regs;
  1437. short i, idx;
  1438. prefetchw(&ap->cur_rx_bufs);
  1439. idx = ap->rx_std_skbprd;
  1440. for (i = 0; i < nr_bufs; i++) {
  1441. struct sk_buff *skb;
  1442. struct rx_desc *rd;
  1443. dma_addr_t mapping;
  1444. skb = alloc_skb(ACE_STD_BUFSIZE + NET_IP_ALIGN, GFP_ATOMIC);
  1445. if (!skb)
  1446. break;
  1447. skb_reserve(skb, NET_IP_ALIGN);
  1448. mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
  1449. offset_in_page(skb->data),
  1450. ACE_STD_BUFSIZE,
  1451. PCI_DMA_FROMDEVICE);
  1452. ap->skb->rx_std_skbuff[idx].skb = skb;
  1453. pci_unmap_addr_set(&ap->skb->rx_std_skbuff[idx],
  1454. mapping, mapping);
  1455. rd = &ap->rx_std_ring[idx];
  1456. set_aceaddr(&rd->addr, mapping);
  1457. rd->size = ACE_STD_BUFSIZE;
  1458. rd->idx = idx;
  1459. idx = (idx + 1) % RX_STD_RING_ENTRIES;
  1460. }
  1461. if (!i)
  1462. goto error_out;
  1463. atomic_add(i, &ap->cur_rx_bufs);
  1464. ap->rx_std_skbprd = idx;
  1465. if (ACE_IS_TIGON_I(ap)) {
  1466. struct cmd cmd;
  1467. cmd.evt = C_SET_RX_PRD_IDX;
  1468. cmd.code = 0;
  1469. cmd.idx = ap->rx_std_skbprd;
  1470. ace_issue_cmd(regs, &cmd);
  1471. } else {
  1472. writel(idx, &regs->RxStdPrd);
  1473. wmb();
  1474. }
  1475. out:
  1476. clear_bit(0, &ap->std_refill_busy);
  1477. return;
  1478. error_out:
  1479. printk(KERN_INFO "Out of memory when allocating "
  1480. "standard receive buffers\n");
  1481. goto out;
  1482. }
  1483. static void ace_load_mini_rx_ring(struct ace_private *ap, int nr_bufs)
  1484. {
  1485. struct ace_regs __iomem *regs = ap->regs;
  1486. short i, idx;
  1487. prefetchw(&ap->cur_mini_bufs);
  1488. idx = ap->rx_mini_skbprd;
  1489. for (i = 0; i < nr_bufs; i++) {
  1490. struct sk_buff *skb;
  1491. struct rx_desc *rd;
  1492. dma_addr_t mapping;
  1493. skb = alloc_skb(ACE_MINI_BUFSIZE + NET_IP_ALIGN, GFP_ATOMIC);
  1494. if (!skb)
  1495. break;
  1496. skb_reserve(skb, NET_IP_ALIGN);
  1497. mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
  1498. offset_in_page(skb->data),
  1499. ACE_MINI_BUFSIZE,
  1500. PCI_DMA_FROMDEVICE);
  1501. ap->skb->rx_mini_skbuff[idx].skb = skb;
  1502. pci_unmap_addr_set(&ap->skb->rx_mini_skbuff[idx],
  1503. mapping, mapping);
  1504. rd = &ap->rx_mini_ring[idx];
  1505. set_aceaddr(&rd->addr, mapping);
  1506. rd->size = ACE_MINI_BUFSIZE;
  1507. rd->idx = idx;
  1508. idx = (idx + 1) % RX_MINI_RING_ENTRIES;
  1509. }
  1510. if (!i)
  1511. goto error_out;
  1512. atomic_add(i, &ap->cur_mini_bufs);
  1513. ap->rx_mini_skbprd = idx;
  1514. writel(idx, &regs->RxMiniPrd);
  1515. wmb();
  1516. out:
  1517. clear_bit(0, &ap->mini_refill_busy);
  1518. return;
  1519. error_out:
  1520. printk(KERN_INFO "Out of memory when allocating "
  1521. "mini receive buffers\n");
  1522. goto out;
  1523. }
  1524. /*
  1525. * Load the jumbo rx ring, this may happen at any time if the MTU
  1526. * is changed to a value > 1500.
  1527. */
  1528. static void ace_load_jumbo_rx_ring(struct ace_private *ap, int nr_bufs)
  1529. {
  1530. struct ace_regs __iomem *regs = ap->regs;
  1531. short i, idx;
  1532. idx = ap->rx_jumbo_skbprd;
  1533. for (i = 0; i < nr_bufs; i++) {
  1534. struct sk_buff *skb;
  1535. struct rx_desc *rd;
  1536. dma_addr_t mapping;
  1537. skb = alloc_skb(ACE_JUMBO_BUFSIZE + NET_IP_ALIGN, GFP_ATOMIC);
  1538. if (!skb)
  1539. break;
  1540. skb_reserve(skb, NET_IP_ALIGN);
  1541. mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
  1542. offset_in_page(skb->data),
  1543. ACE_JUMBO_BUFSIZE,
  1544. PCI_DMA_FROMDEVICE);
  1545. ap->skb->rx_jumbo_skbuff[idx].skb = skb;
  1546. pci_unmap_addr_set(&ap->skb->rx_jumbo_skbuff[idx],
  1547. mapping, mapping);
  1548. rd = &ap->rx_jumbo_ring[idx];
  1549. set_aceaddr(&rd->addr, mapping);
  1550. rd->size = ACE_JUMBO_BUFSIZE;
  1551. rd->idx = idx;
  1552. idx = (idx + 1) % RX_JUMBO_RING_ENTRIES;
  1553. }
  1554. if (!i)
  1555. goto error_out;
  1556. atomic_add(i, &ap->cur_jumbo_bufs);
  1557. ap->rx_jumbo_skbprd = idx;
  1558. if (ACE_IS_TIGON_I(ap)) {
  1559. struct cmd cmd;
  1560. cmd.evt = C_SET_RX_JUMBO_PRD_IDX;
  1561. cmd.code = 0;
  1562. cmd.idx = ap->rx_jumbo_skbprd;
  1563. ace_issue_cmd(regs, &cmd);
  1564. } else {
  1565. writel(idx, &regs->RxJumboPrd);
  1566. wmb();
  1567. }
  1568. out:
  1569. clear_bit(0, &ap->jumbo_refill_busy);
  1570. return;
  1571. error_out:
  1572. if (net_ratelimit())
  1573. printk(KERN_INFO "Out of memory when allocating "
  1574. "jumbo receive buffers\n");
  1575. goto out;
  1576. }
  1577. /*
  1578. * All events are considered to be slow (RX/TX ints do not generate
  1579. * events) and are handled here, outside the main interrupt handler,
  1580. * to reduce the size of the handler.
  1581. */
  1582. static u32 ace_handle_event(struct net_device *dev, u32 evtcsm, u32 evtprd)
  1583. {
  1584. struct ace_private *ap;
  1585. ap = netdev_priv(dev);
  1586. while (evtcsm != evtprd) {
  1587. switch (ap->evt_ring[evtcsm].evt) {
  1588. case E_FW_RUNNING:
  1589. printk(KERN_INFO "%s: Firmware up and running\n",
  1590. ap->name);
  1591. ap->fw_running = 1;
  1592. wmb();
  1593. break;
  1594. case E_STATS_UPDATED:
  1595. break;
  1596. case E_LNK_STATE:
  1597. {
  1598. u16 code = ap->evt_ring[evtcsm].code;
  1599. switch (code) {
  1600. case E_C_LINK_UP:
  1601. {
  1602. u32 state = readl(&ap->regs->GigLnkState);
  1603. printk(KERN_WARNING "%s: Optical link UP "
  1604. "(%s Duplex, Flow Control: %s%s)\n",
  1605. ap->name,
  1606. state & LNK_FULL_DUPLEX ? "Full":"Half",
  1607. state & LNK_TX_FLOW_CTL_Y ? "TX " : "",
  1608. state & LNK_RX_FLOW_CTL_Y ? "RX" : "");
  1609. break;
  1610. }
  1611. case E_C_LINK_DOWN:
  1612. printk(KERN_WARNING "%s: Optical link DOWN\n",
  1613. ap->name);
  1614. break;
  1615. case E_C_LINK_10_100:
  1616. printk(KERN_WARNING "%s: 10/100BaseT link "
  1617. "UP\n", ap->name);
  1618. break;
  1619. default:
  1620. printk(KERN_ERR "%s: Unknown optical link "
  1621. "state %02x\n", ap->name, code);
  1622. }
  1623. break;
  1624. }
  1625. case E_ERROR:
  1626. switch(ap->evt_ring[evtcsm].code) {
  1627. case E_C_ERR_INVAL_CMD:
  1628. printk(KERN_ERR "%s: invalid command error\n",
  1629. ap->name);
  1630. break;
  1631. case E_C_ERR_UNIMP_CMD:
  1632. printk(KERN_ERR "%s: unimplemented command "
  1633. "error\n", ap->name);
  1634. break;
  1635. case E_C_ERR_BAD_CFG:
  1636. printk(KERN_ERR "%s: bad config error\n",
  1637. ap->name);
  1638. break;
  1639. default:
  1640. printk(KERN_ERR "%s: unknown error %02x\n",
  1641. ap->name, ap->evt_ring[evtcsm].code);
  1642. }
  1643. break;
  1644. case E_RESET_JUMBO_RNG:
  1645. {
  1646. int i;
  1647. for (i = 0; i < RX_JUMBO_RING_ENTRIES; i++) {
  1648. if (ap->skb->rx_jumbo_skbuff[i].skb) {
  1649. ap->rx_jumbo_ring[i].size = 0;
  1650. set_aceaddr(&ap->rx_jumbo_ring[i].addr, 0);
  1651. dev_kfree_skb(ap->skb->rx_jumbo_skbuff[i].skb);
  1652. ap->skb->rx_jumbo_skbuff[i].skb = NULL;
  1653. }
  1654. }
  1655. if (ACE_IS_TIGON_I(ap)) {
  1656. struct cmd cmd;
  1657. cmd.evt = C_SET_RX_JUMBO_PRD_IDX;
  1658. cmd.code = 0;
  1659. cmd.idx = 0;
  1660. ace_issue_cmd(ap->regs, &cmd);
  1661. } else {
  1662. writel(0, &((ap->regs)->RxJumboPrd));
  1663. wmb();
  1664. }
  1665. ap->jumbo = 0;
  1666. ap->rx_jumbo_skbprd = 0;
  1667. printk(KERN_INFO "%s: Jumbo ring flushed\n",
  1668. ap->name);
  1669. clear_bit(0, &ap->jumbo_refill_busy);
  1670. break;
  1671. }
  1672. default:
  1673. printk(KERN_ERR "%s: Unhandled event 0x%02x\n",
  1674. ap->name, ap->evt_ring[evtcsm].evt);
  1675. }
  1676. evtcsm = (evtcsm + 1) % EVT_RING_ENTRIES;
  1677. }
  1678. return evtcsm;
  1679. }
  1680. static void ace_rx_int(struct net_device *dev, u32 rxretprd, u32 rxretcsm)
  1681. {
  1682. struct ace_private *ap = netdev_priv(dev);
  1683. u32 idx;
  1684. int mini_count = 0, std_count = 0;
  1685. idx = rxretcsm;
  1686. prefetchw(&ap->cur_rx_bufs);
  1687. prefetchw(&ap->cur_mini_bufs);
  1688. while (idx != rxretprd) {
  1689. struct ring_info *rip;
  1690. struct sk_buff *skb;
  1691. struct rx_desc *rxdesc, *retdesc;
  1692. u32 skbidx;
  1693. int bd_flags, desc_type, mapsize;
  1694. u16 csum;
  1695. /* make sure the rx descriptor isn't read before rxretprd */
  1696. if (idx == rxretcsm)
  1697. rmb();
  1698. retdesc = &ap->rx_return_ring[idx];
  1699. skbidx = retdesc->idx;
  1700. bd_flags = retdesc->flags;
  1701. desc_type = bd_flags & (BD_FLG_JUMBO | BD_FLG_MINI);
  1702. switch(desc_type) {
  1703. /*
  1704. * Normal frames do not have any flags set
  1705. *
  1706. * Mini and normal frames arrive frequently,
  1707. * so use a local counter to avoid doing
  1708. * atomic operations for each packet arriving.
  1709. */
  1710. case 0:
  1711. rip = &ap->skb->rx_std_skbuff[skbidx];
  1712. mapsize = ACE_STD_BUFSIZE;
  1713. rxdesc = &ap->rx_std_ring[skbidx];
  1714. std_count++;
  1715. break;
  1716. case BD_FLG_JUMBO:
  1717. rip = &ap->skb->rx_jumbo_skbuff[skbidx];
  1718. mapsize = ACE_JUMBO_BUFSIZE;
  1719. rxdesc = &ap->rx_jumbo_ring[skbidx];
  1720. atomic_dec(&ap->cur_jumbo_bufs);
  1721. break;
  1722. case BD_FLG_MINI:
  1723. rip = &ap->skb->rx_mini_skbuff[skbidx];
  1724. mapsize = ACE_MINI_BUFSIZE;
  1725. rxdesc = &ap->rx_mini_ring[skbidx];
  1726. mini_count++;
  1727. break;
  1728. default:
  1729. printk(KERN_INFO "%s: unknown frame type (0x%02x) "
  1730. "returned by NIC\n", dev->name,
  1731. retdesc->flags);
  1732. goto error;
  1733. }
  1734. skb = rip->skb;
  1735. rip->skb = NULL;
  1736. pci_unmap_page(ap->pdev,
  1737. pci_unmap_addr(rip, mapping),
  1738. mapsize,
  1739. PCI_DMA_FROMDEVICE);
  1740. skb_put(skb, retdesc->size);
  1741. /*
  1742. * Fly baby, fly!
  1743. */
  1744. csum = retdesc->tcp_udp_csum;
  1745. skb->protocol = eth_type_trans(skb, dev);
  1746. /*
  1747. * Instead of forcing the poor tigon mips cpu to calculate
  1748. * pseudo hdr checksum, we do this ourselves.
  1749. */
  1750. if (bd_flags & BD_FLG_TCP_UDP_SUM) {
  1751. skb->csum = htons(csum);
  1752. skb->ip_summed = CHECKSUM_COMPLETE;
  1753. } else {
  1754. skb->ip_summed = CHECKSUM_NONE;
  1755. }
  1756. /* send it up */
  1757. #if ACENIC_DO_VLAN
  1758. if (ap->vlgrp && (bd_flags & BD_FLG_VLAN_TAG)) {
  1759. vlan_hwaccel_rx(skb, ap->vlgrp, retdesc->vlan);
  1760. } else
  1761. #endif
  1762. netif_rx(skb);
  1763. dev->last_rx = jiffies;
  1764. dev->stats.rx_packets++;
  1765. dev->stats.rx_bytes += retdesc->size;
  1766. idx = (idx + 1) % RX_RETURN_RING_ENTRIES;
  1767. }
  1768. atomic_sub(std_count, &ap->cur_rx_bufs);
  1769. if (!ACE_IS_TIGON_I(ap))
  1770. atomic_sub(mini_count, &ap->cur_mini_bufs);
  1771. out:
  1772. /*
  1773. * According to the documentation RxRetCsm is obsolete with
  1774. * the 12.3.x Firmware - my Tigon I NICs seem to disagree!
  1775. */
  1776. if (ACE_IS_TIGON_I(ap)) {
  1777. writel(idx, &ap->regs->RxRetCsm);
  1778. }
  1779. ap->cur_rx = idx;
  1780. return;
  1781. error:
  1782. idx = rxretprd;
  1783. goto out;
  1784. }
  1785. static inline void ace_tx_int(struct net_device *dev,
  1786. u32 txcsm, u32 idx)
  1787. {
  1788. struct ace_private *ap = netdev_priv(dev);
  1789. do {
  1790. struct sk_buff *skb;
  1791. dma_addr_t mapping;
  1792. struct tx_ring_info *info;
  1793. info = ap->skb->tx_skbuff + idx;
  1794. skb = info->skb;
  1795. mapping = pci_unmap_addr(info, mapping);
  1796. if (mapping) {
  1797. pci_unmap_page(ap->pdev, mapping,
  1798. pci_unmap_len(info, maplen),
  1799. PCI_DMA_TODEVICE);
  1800. pci_unmap_addr_set(info, mapping, 0);
  1801. }
  1802. if (skb) {
  1803. dev->stats.tx_packets++;
  1804. dev->stats.tx_bytes += skb->len;
  1805. dev_kfree_skb_irq(skb);
  1806. info->skb = NULL;
  1807. }
  1808. idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
  1809. } while (idx != txcsm);
  1810. if (netif_queue_stopped(dev))
  1811. netif_wake_queue(dev);
  1812. wmb();
  1813. ap->tx_ret_csm = txcsm;
  1814. /* So... tx_ret_csm is advanced _after_ check for device wakeup.
  1815. *
  1816. * We could try to make it before. In this case we would get
  1817. * the following race condition: hard_start_xmit on other cpu
  1818. * enters after we advanced tx_ret_csm and fills space,
  1819. * which we have just freed, so that we make illegal device wakeup.
  1820. * There is no good way to workaround this (at entry
  1821. * to ace_start_xmit detects this condition and prevents
  1822. * ring corruption, but it is not a good workaround.)
  1823. *
  1824. * When tx_ret_csm is advanced after, we wake up device _only_
  1825. * if we really have some space in ring (though the core doing
  1826. * hard_start_xmit can see full ring for some period and has to
  1827. * synchronize.) Superb.
  1828. * BUT! We get another subtle race condition. hard_start_xmit
  1829. * may think that ring is full between wakeup and advancing
  1830. * tx_ret_csm and will stop device instantly! It is not so bad.
  1831. * We are guaranteed that there is something in ring, so that
  1832. * the next irq will resume transmission. To speedup this we could
  1833. * mark descriptor, which closes ring with BD_FLG_COAL_NOW
  1834. * (see ace_start_xmit).
  1835. *
  1836. * Well, this dilemma exists in all lock-free devices.
  1837. * We, following scheme used in drivers by Donald Becker,
  1838. * select the least dangerous.
  1839. * --ANK
  1840. */
  1841. }
  1842. static irqreturn_t ace_interrupt(int irq, void *dev_id)
  1843. {
  1844. struct net_device *dev = (struct net_device *)dev_id;
  1845. struct ace_private *ap = netdev_priv(dev);
  1846. struct ace_regs __iomem *regs = ap->regs;
  1847. u32 idx;
  1848. u32 txcsm, rxretcsm, rxretprd;
  1849. u32 evtcsm, evtprd;
  1850. /*
  1851. * In case of PCI shared interrupts or spurious interrupts,
  1852. * we want to make sure it is actually our interrupt before
  1853. * spending any time in here.
  1854. */
  1855. if (!(readl(&regs->HostCtrl) & IN_INT))
  1856. return IRQ_NONE;
  1857. /*
  1858. * ACK intr now. Otherwise we will lose updates to rx_ret_prd,
  1859. * which happened _after_ rxretprd = *ap->rx_ret_prd; but before
  1860. * writel(0, &regs->Mb0Lo).
  1861. *
  1862. * "IRQ avoidance" recommended in docs applies to IRQs served
  1863. * threads and it is wrong even for that case.
  1864. */
  1865. writel(0, &regs->Mb0Lo);
  1866. readl(&regs->Mb0Lo);
  1867. /*
  1868. * There is no conflict between transmit handling in
  1869. * start_xmit and receive processing, thus there is no reason
  1870. * to take a spin lock for RX handling. Wait until we start
  1871. * working on the other stuff - hey we don't need a spin lock
  1872. * anymore.
  1873. */
  1874. rxretprd = *ap->rx_ret_prd;
  1875. rxretcsm = ap->cur_rx;
  1876. if (rxretprd != rxretcsm)
  1877. ace_rx_int(dev, rxretprd, rxretcsm);
  1878. txcsm = *ap->tx_csm;
  1879. idx = ap->tx_ret_csm;
  1880. if (txcsm != idx) {
  1881. /*
  1882. * If each skb takes only one descriptor this check degenerates
  1883. * to identity, because new space has just been opened.
  1884. * But if skbs are fragmented we must check that this index
  1885. * update releases enough of space, otherwise we just
  1886. * wait for device to make more work.
  1887. */
  1888. if (!tx_ring_full(ap, txcsm, ap->tx_prd))
  1889. ace_tx_int(dev, txcsm, idx);
  1890. }
  1891. evtcsm = readl(&regs->EvtCsm);
  1892. evtprd = *ap->evt_prd;
  1893. if (evtcsm != evtprd) {
  1894. evtcsm = ace_handle_event(dev, evtcsm, evtprd);
  1895. writel(evtcsm, &regs->EvtCsm);
  1896. }
  1897. /*
  1898. * This has to go last in the interrupt handler and run with
  1899. * the spin lock released ... what lock?
  1900. */
  1901. if (netif_running(dev)) {
  1902. int cur_size;
  1903. int run_tasklet = 0;
  1904. cur_size = atomic_read(&ap->cur_rx_bufs);
  1905. if (cur_size < RX_LOW_STD_THRES) {
  1906. if ((cur_size < RX_PANIC_STD_THRES) &&
  1907. !test_and_set_bit(0, &ap->std_refill_busy)) {
  1908. #ifdef DEBUG
  1909. printk("low on std buffers %i\n", cur_size);
  1910. #endif
  1911. ace_load_std_rx_ring(ap,
  1912. RX_RING_SIZE - cur_size);
  1913. } else
  1914. run_tasklet = 1;
  1915. }
  1916. if (!ACE_IS_TIGON_I(ap)) {
  1917. cur_size = atomic_read(&ap->cur_mini_bufs);
  1918. if (cur_size < RX_LOW_MINI_THRES) {
  1919. if ((cur_size < RX_PANIC_MINI_THRES) &&
  1920. !test_and_set_bit(0,
  1921. &ap->mini_refill_busy)) {
  1922. #ifdef DEBUG
  1923. printk("low on mini buffers %i\n",
  1924. cur_size);
  1925. #endif
  1926. ace_load_mini_rx_ring(ap, RX_MINI_SIZE - cur_size);
  1927. } else
  1928. run_tasklet = 1;
  1929. }
  1930. }
  1931. if (ap->jumbo) {
  1932. cur_size = atomic_read(&ap->cur_jumbo_bufs);
  1933. if (cur_size < RX_LOW_JUMBO_THRES) {
  1934. if ((cur_size < RX_PANIC_JUMBO_THRES) &&
  1935. !test_and_set_bit(0,
  1936. &ap->jumbo_refill_busy)){
  1937. #ifdef DEBUG
  1938. printk("low on jumbo buffers %i\n",
  1939. cur_size);
  1940. #endif
  1941. ace_load_jumbo_rx_ring(ap, RX_JUMBO_SIZE - cur_size);
  1942. } else
  1943. run_tasklet = 1;
  1944. }
  1945. }
  1946. if (run_tasklet && !ap->tasklet_pending) {
  1947. ap->tasklet_pending = 1;
  1948. tasklet_schedule(&ap->ace_tasklet);
  1949. }
  1950. }
  1951. return IRQ_HANDLED;
  1952. }
  1953. #if ACENIC_DO_VLAN
  1954. static void ace_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
  1955. {
  1956. struct ace_private *ap = netdev_priv(dev);
  1957. unsigned long flags;
  1958. local_irq_save(flags);
  1959. ace_mask_irq(dev);
  1960. ap->vlgrp = grp;
  1961. ace_unmask_irq(dev);
  1962. local_irq_restore(flags);
  1963. }
  1964. #endif /* ACENIC_DO_VLAN */
  1965. static int ace_open(struct net_device *dev)
  1966. {
  1967. struct ace_private *ap = netdev_priv(dev);
  1968. struct ace_regs __iomem *regs = ap->regs;
  1969. struct cmd cmd;
  1970. if (!(ap->fw_running)) {
  1971. printk(KERN_WARNING "%s: Firmware not running!\n", dev->name);
  1972. return -EBUSY;
  1973. }
  1974. writel(dev->mtu + ETH_HLEN + 4, &regs->IfMtu);
  1975. cmd.evt = C_CLEAR_STATS;
  1976. cmd.code = 0;
  1977. cmd.idx = 0;
  1978. ace_issue_cmd(regs, &cmd);
  1979. cmd.evt = C_HOST_STATE;
  1980. cmd.code = C_C_STACK_UP;
  1981. cmd.idx = 0;
  1982. ace_issue_cmd(regs, &cmd);
  1983. if (ap->jumbo &&
  1984. !test_and_set_bit(0, &ap->jumbo_refill_busy))
  1985. ace_load_jumbo_rx_ring(ap, RX_JUMBO_SIZE);
  1986. if (dev->flags & IFF_PROMISC) {
  1987. cmd.evt = C_SET_PROMISC_MODE;
  1988. cmd.code = C_C_PROMISC_ENABLE;
  1989. cmd.idx = 0;
  1990. ace_issue_cmd(regs, &cmd);
  1991. ap->promisc = 1;
  1992. }else
  1993. ap->promisc = 0;
  1994. ap->mcast_all = 0;
  1995. #if 0
  1996. cmd.evt = C_LNK_NEGOTIATION;
  1997. cmd.code = 0;
  1998. cmd.idx = 0;
  1999. ace_issue_cmd(regs, &cmd);
  2000. #endif
  2001. netif_start_queue(dev);
  2002. /*
  2003. * Setup the bottom half rx ring refill handler
  2004. */
  2005. tasklet_init(&ap->ace_tasklet, ace_tasklet, (unsigned long)dev);
  2006. return 0;
  2007. }
  2008. static int ace_close(struct net_device *dev)
  2009. {
  2010. struct ace_private *ap = netdev_priv(dev);
  2011. struct ace_regs __iomem *regs = ap->regs;
  2012. struct cmd cmd;
  2013. unsigned long flags;
  2014. short i;
  2015. /*
  2016. * Without (or before) releasing irq and stopping hardware, this
  2017. * is an absolute non-sense, by the way. It will be reset instantly
  2018. * by the first irq.
  2019. */
  2020. netif_stop_queue(dev);
  2021. if (ap->promisc) {
  2022. cmd.evt = C_SET_PROMISC_MODE;
  2023. cmd.code = C_C_PROMISC_DISABLE;
  2024. cmd.idx = 0;
  2025. ace_issue_cmd(regs, &cmd);
  2026. ap->promisc = 0;
  2027. }
  2028. cmd.evt = C_HOST_STATE;
  2029. cmd.code = C_C_STACK_DOWN;
  2030. cmd.idx = 0;
  2031. ace_issue_cmd(regs, &cmd);
  2032. tasklet_kill(&ap->ace_tasklet);
  2033. /*
  2034. * Make sure one CPU is not processing packets while
  2035. * buffers are being released by another.
  2036. */
  2037. local_irq_save(flags);
  2038. ace_mask_irq(dev);
  2039. for (i = 0; i < ACE_TX_RING_ENTRIES(ap); i++) {
  2040. struct sk_buff *skb;
  2041. dma_addr_t mapping;
  2042. struct tx_ring_info *info;
  2043. info = ap->skb->tx_skbuff + i;
  2044. skb = info->skb;
  2045. mapping = pci_unmap_addr(info, mapping);
  2046. if (mapping) {
  2047. if (ACE_IS_TIGON_I(ap)) {
  2048. /* NB: TIGON_1 is special, tx_ring is in io space */
  2049. struct tx_desc __iomem *tx;
  2050. tx = (__force struct tx_desc __iomem *) &ap->tx_ring[i];
  2051. writel(0, &tx->addr.addrhi);
  2052. writel(0, &tx->addr.addrlo);
  2053. writel(0, &tx->flagsize);
  2054. } else
  2055. memset(ap->tx_ring + i, 0,
  2056. sizeof(struct tx_desc));
  2057. pci_unmap_page(ap->pdev, mapping,
  2058. pci_unmap_len(info, maplen),
  2059. PCI_DMA_TODEVICE);
  2060. pci_unmap_addr_set(info, mapping, 0);
  2061. }
  2062. if (skb) {
  2063. dev_kfree_skb(skb);
  2064. info->skb = NULL;
  2065. }
  2066. }
  2067. if (ap->jumbo) {
  2068. cmd.evt = C_RESET_JUMBO_RNG;
  2069. cmd.code = 0;
  2070. cmd.idx = 0;
  2071. ace_issue_cmd(regs, &cmd);
  2072. }
  2073. ace_unmask_irq(dev);
  2074. local_irq_restore(flags);
  2075. return 0;
  2076. }
  2077. static inline dma_addr_t
  2078. ace_map_tx_skb(struct ace_private *ap, struct sk_buff *skb,
  2079. struct sk_buff *tail, u32 idx)
  2080. {
  2081. dma_addr_t mapping;
  2082. struct tx_ring_info *info;
  2083. mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
  2084. offset_in_page(skb->data),
  2085. skb->len, PCI_DMA_TODEVICE);
  2086. info = ap->skb->tx_skbuff + idx;
  2087. info->skb = tail;
  2088. pci_unmap_addr_set(info, mapping, mapping);
  2089. pci_unmap_len_set(info, maplen, skb->len);
  2090. return mapping;
  2091. }
  2092. static inline void
  2093. ace_load_tx_bd(struct ace_private *ap, struct tx_desc *desc, u64 addr,
  2094. u32 flagsize, u32 vlan_tag)
  2095. {
  2096. #if !USE_TX_COAL_NOW
  2097. flagsize &= ~BD_FLG_COAL_NOW;
  2098. #endif
  2099. if (ACE_IS_TIGON_I(ap)) {
  2100. struct tx_desc __iomem *io = (__force struct tx_desc __iomem *) desc;
  2101. writel(addr >> 32, &io->addr.addrhi);
  2102. writel(addr & 0xffffffff, &io->addr.addrlo);
  2103. writel(flagsize, &io->flagsize);
  2104. #if ACENIC_DO_VLAN
  2105. writel(vlan_tag, &io->vlanres);
  2106. #endif
  2107. } else {
  2108. desc->addr.addrhi = addr >> 32;
  2109. desc->addr.addrlo = addr;
  2110. desc->flagsize = flagsize;
  2111. #if ACENIC_DO_VLAN
  2112. desc->vlanres = vlan_tag;
  2113. #endif
  2114. }
  2115. }
  2116. static int ace_start_xmit(struct sk_buff *skb, struct net_device *dev)
  2117. {
  2118. struct ace_private *ap = netdev_priv(dev);
  2119. struct ace_regs __iomem *regs = ap->regs;
  2120. struct tx_desc *desc;
  2121. u32 idx, flagsize;
  2122. unsigned long maxjiff = jiffies + 3*HZ;
  2123. restart:
  2124. idx = ap->tx_prd;
  2125. if (tx_ring_full(ap, ap->tx_ret_csm, idx))
  2126. goto overflow;
  2127. if (!skb_shinfo(skb)->nr_frags) {
  2128. dma_addr_t mapping;
  2129. u32 vlan_tag = 0;
  2130. mapping = ace_map_tx_skb(ap, skb, skb, idx);
  2131. flagsize = (skb->len << 16) | (BD_FLG_END);
  2132. if (skb->ip_summed == CHECKSUM_PARTIAL)
  2133. flagsize |= BD_FLG_TCP_UDP_SUM;
  2134. #if ACENIC_DO_VLAN
  2135. if (vlan_tx_tag_present(skb)) {
  2136. flagsize |= BD_FLG_VLAN_TAG;
  2137. vlan_tag = vlan_tx_tag_get(skb);
  2138. }
  2139. #endif
  2140. desc = ap->tx_ring + idx;
  2141. idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
  2142. /* Look at ace_tx_int for explanations. */
  2143. if (tx_ring_full(ap, ap->tx_ret_csm, idx))
  2144. flagsize |= BD_FLG_COAL_NOW;
  2145. ace_load_tx_bd(ap, desc, mapping, flagsize, vlan_tag);
  2146. } else {
  2147. dma_addr_t mapping;
  2148. u32 vlan_tag = 0;
  2149. int i, len = 0;
  2150. mapping = ace_map_tx_skb(ap, skb, NULL, idx);
  2151. flagsize = (skb_headlen(skb) << 16);
  2152. if (skb->ip_summed == CHECKSUM_PARTIAL)
  2153. flagsize |= BD_FLG_TCP_UDP_SUM;
  2154. #if ACENIC_DO_VLAN
  2155. if (vlan_tx_tag_present(skb)) {
  2156. flagsize |= BD_FLG_VLAN_TAG;
  2157. vlan_tag = vlan_tx_tag_get(skb);
  2158. }
  2159. #endif
  2160. ace_load_tx_bd(ap, ap->tx_ring + idx, mapping, flagsize, vlan_tag);
  2161. idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
  2162. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2163. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  2164. struct tx_ring_info *info;
  2165. len += frag->size;
  2166. info = ap->skb->tx_skbuff + idx;
  2167. desc = ap->tx_ring + idx;
  2168. mapping = pci_map_page(ap->pdev, frag->page,
  2169. frag->page_offset, frag->size,
  2170. PCI_DMA_TODEVICE);
  2171. flagsize = (frag->size << 16);
  2172. if (skb->ip_summed == CHECKSUM_PARTIAL)
  2173. flagsize |= BD_FLG_TCP_UDP_SUM;
  2174. idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
  2175. if (i == skb_shinfo(skb)->nr_frags - 1) {
  2176. flagsize |= BD_FLG_END;
  2177. if (tx_ring_full(ap, ap->tx_ret_csm, idx))
  2178. flagsize |= BD_FLG_COAL_NOW;
  2179. /*
  2180. * Only the last fragment frees
  2181. * the skb!
  2182. */
  2183. info->skb = skb;
  2184. } else {
  2185. info->skb = NULL;
  2186. }
  2187. pci_unmap_addr_set(info, mapping, mapping);
  2188. pci_unmap_len_set(info, maplen, frag->size);
  2189. ace_load_tx_bd(ap, desc, mapping, flagsize, vlan_tag);
  2190. }
  2191. }
  2192. wmb();
  2193. ap->tx_prd = idx;
  2194. ace_set_txprd(regs, ap, idx);
  2195. if (flagsize & BD_FLG_COAL_NOW) {
  2196. netif_stop_queue(dev);
  2197. /*
  2198. * A TX-descriptor producer (an IRQ) might have gotten
  2199. * inbetween, making the ring free again. Since xmit is
  2200. * serialized, this is the only situation we have to
  2201. * re-test.
  2202. */
  2203. if (!tx_ring_full(ap, ap->tx_ret_csm, idx))
  2204. netif_wake_queue(dev);
  2205. }
  2206. dev->trans_start = jiffies;
  2207. return NETDEV_TX_OK;
  2208. overflow:
  2209. /*
  2210. * This race condition is unavoidable with lock-free drivers.
  2211. * We wake up the queue _before_ tx_prd is advanced, so that we can
  2212. * enter hard_start_xmit too early, while tx ring still looks closed.
  2213. * This happens ~1-4 times per 100000 packets, so that we can allow
  2214. * to loop syncing to other CPU. Probably, we need an additional
  2215. * wmb() in ace_tx_intr as well.
  2216. *
  2217. * Note that this race is relieved by reserving one more entry
  2218. * in tx ring than it is necessary (see original non-SG driver).
  2219. * However, with SG we need to reserve 2*MAX_SKB_FRAGS+1, which
  2220. * is already overkill.
  2221. *
  2222. * Alternative is to return with 1 not throttling queue. In this
  2223. * case loop becomes longer, no more useful effects.
  2224. */
  2225. if (time_before(jiffies, maxjiff)) {
  2226. barrier();
  2227. cpu_relax();
  2228. goto restart;
  2229. }
  2230. /* The ring is stuck full. */
  2231. printk(KERN_WARNING "%s: Transmit ring stuck full\n", dev->name);
  2232. return NETDEV_TX_BUSY;
  2233. }
  2234. static int ace_change_mtu(struct net_device *dev, int new_mtu)
  2235. {
  2236. struct ace_private *ap = netdev_priv(dev);
  2237. struct ace_regs __iomem *regs = ap->regs;
  2238. if (new_mtu > ACE_JUMBO_MTU)
  2239. return -EINVAL;
  2240. writel(new_mtu + ETH_HLEN + 4, &regs->IfMtu);
  2241. dev->mtu = new_mtu;
  2242. if (new_mtu > ACE_STD_MTU) {
  2243. if (!(ap->jumbo)) {
  2244. printk(KERN_INFO "%s: Enabling Jumbo frame "
  2245. "support\n", dev->name);
  2246. ap->jumbo = 1;
  2247. if (!test_and_set_bit(0, &ap->jumbo_refill_busy))
  2248. ace_load_jumbo_rx_ring(ap, RX_JUMBO_SIZE);
  2249. ace_set_rxtx_parms(dev, 1);
  2250. }
  2251. } else {
  2252. while (test_and_set_bit(0, &ap->jumbo_refill_busy));
  2253. ace_sync_irq(dev->irq);
  2254. ace_set_rxtx_parms(dev, 0);
  2255. if (ap->jumbo) {
  2256. struct cmd cmd;
  2257. cmd.evt = C_RESET_JUMBO_RNG;
  2258. cmd.code = 0;
  2259. cmd.idx = 0;
  2260. ace_issue_cmd(regs, &cmd);
  2261. }
  2262. }
  2263. return 0;
  2264. }
  2265. static int ace_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  2266. {
  2267. struct ace_private *ap = netdev_priv(dev);
  2268. struct ace_regs __iomem *regs = ap->regs;
  2269. u32 link;
  2270. memset(ecmd, 0, sizeof(struct ethtool_cmd));
  2271. ecmd->supported =
  2272. (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
  2273. SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
  2274. SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full |
  2275. SUPPORTED_Autoneg | SUPPORTED_FIBRE);
  2276. ecmd->port = PORT_FIBRE;
  2277. ecmd->transceiver = XCVR_INTERNAL;
  2278. link = readl(&regs->GigLnkState);
  2279. if (link & LNK_1000MB)
  2280. ecmd->speed = SPEED_1000;
  2281. else {
  2282. link = readl(&regs->FastLnkState);
  2283. if (link & LNK_100MB)
  2284. ecmd->speed = SPEED_100;
  2285. else if (link & LNK_10MB)
  2286. ecmd->speed = SPEED_10;
  2287. else
  2288. ecmd->speed = 0;
  2289. }
  2290. if (link & LNK_FULL_DUPLEX)
  2291. ecmd->duplex = DUPLEX_FULL;
  2292. else
  2293. ecmd->duplex = DUPLEX_HALF;
  2294. if (link & LNK_NEGOTIATE)
  2295. ecmd->autoneg = AUTONEG_ENABLE;
  2296. else
  2297. ecmd->autoneg = AUTONEG_DISABLE;
  2298. #if 0
  2299. /*
  2300. * Current struct ethtool_cmd is insufficient
  2301. */
  2302. ecmd->trace = readl(&regs->TuneTrace);
  2303. ecmd->txcoal = readl(&regs->TuneTxCoalTicks);
  2304. ecmd->rxcoal = readl(&regs->TuneRxCoalTicks);
  2305. #endif
  2306. ecmd->maxtxpkt = readl(&regs->TuneMaxTxDesc);
  2307. ecmd->maxrxpkt = readl(&regs->TuneMaxRxDesc);
  2308. return 0;
  2309. }
  2310. static int ace_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  2311. {
  2312. struct ace_private *ap = netdev_priv(dev);
  2313. struct ace_regs __iomem *regs = ap->regs;
  2314. u32 link, speed;
  2315. link = readl(&regs->GigLnkState);
  2316. if (link & LNK_1000MB)
  2317. speed = SPEED_1000;
  2318. else {
  2319. link = readl(&regs->FastLnkState);
  2320. if (link & LNK_100MB)
  2321. speed = SPEED_100;
  2322. else if (link & LNK_10MB)
  2323. speed = SPEED_10;
  2324. else
  2325. speed = SPEED_100;
  2326. }
  2327. link = LNK_ENABLE | LNK_1000MB | LNK_100MB | LNK_10MB |
  2328. LNK_RX_FLOW_CTL_Y | LNK_NEG_FCTL;
  2329. if (!ACE_IS_TIGON_I(ap))
  2330. link |= LNK_TX_FLOW_CTL_Y;
  2331. if (ecmd->autoneg == AUTONEG_ENABLE)
  2332. link |= LNK_NEGOTIATE;
  2333. if (ecmd->speed != speed) {
  2334. link &= ~(LNK_1000MB | LNK_100MB | LNK_10MB);
  2335. switch (speed) {
  2336. case SPEED_1000:
  2337. link |= LNK_1000MB;
  2338. break;
  2339. case SPEED_100:
  2340. link |= LNK_100MB;
  2341. break;
  2342. case SPEED_10:
  2343. link |= LNK_10MB;
  2344. break;
  2345. }
  2346. }
  2347. if (ecmd->duplex == DUPLEX_FULL)
  2348. link |= LNK_FULL_DUPLEX;
  2349. if (link != ap->link) {
  2350. struct cmd cmd;
  2351. printk(KERN_INFO "%s: Renegotiating link state\n",
  2352. dev->name);
  2353. ap->link = link;
  2354. writel(link, &regs->TuneLink);
  2355. if (!ACE_IS_TIGON_I(ap))
  2356. writel(link, &regs->TuneFastLink);
  2357. wmb();
  2358. cmd.evt = C_LNK_NEGOTIATION;
  2359. cmd.code = 0;
  2360. cmd.idx = 0;
  2361. ace_issue_cmd(regs, &cmd);
  2362. }
  2363. return 0;
  2364. }
  2365. static void ace_get_drvinfo(struct net_device *dev,
  2366. struct ethtool_drvinfo *info)
  2367. {
  2368. struct ace_private *ap = netdev_priv(dev);
  2369. strlcpy(info->driver, "acenic", sizeof(info->driver));
  2370. snprintf(info->version, sizeof(info->version), "%i.%i.%i",
  2371. tigonFwReleaseMajor, tigonFwReleaseMinor,
  2372. tigonFwReleaseFix);
  2373. if (ap->pdev)
  2374. strlcpy(info->bus_info, pci_name(ap->pdev),
  2375. sizeof(info->bus_info));
  2376. }
  2377. /*
  2378. * Set the hardware MAC address.
  2379. */
  2380. static int ace_set_mac_addr(struct net_device *dev, void *p)
  2381. {
  2382. struct ace_private *ap = netdev_priv(dev);
  2383. struct ace_regs __iomem *regs = ap->regs;
  2384. struct sockaddr *addr=p;
  2385. u8 *da;
  2386. struct cmd cmd;
  2387. if(netif_running(dev))
  2388. return -EBUSY;
  2389. memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
  2390. da = (u8 *)dev->dev_addr;
  2391. writel(da[0] << 8 | da[1], &regs->MacAddrHi);
  2392. writel((da[2] << 24) | (da[3] << 16) | (da[4] << 8) | da[5],
  2393. &regs->MacAddrLo);
  2394. cmd.evt = C_SET_MAC_ADDR;
  2395. cmd.code = 0;
  2396. cmd.idx = 0;
  2397. ace_issue_cmd(regs, &cmd);
  2398. return 0;
  2399. }
  2400. static void ace_set_multicast_list(struct net_device *dev)
  2401. {
  2402. struct ace_private *ap = netdev_priv(dev);
  2403. struct ace_regs __iomem *regs = ap->regs;
  2404. struct cmd cmd;
  2405. if ((dev->flags & IFF_ALLMULTI) && !(ap->mcast_all)) {
  2406. cmd.evt = C_SET_MULTICAST_MODE;
  2407. cmd.code = C_C_MCAST_ENABLE;
  2408. cmd.idx = 0;
  2409. ace_issue_cmd(regs, &cmd);
  2410. ap->mcast_all = 1;
  2411. } else if (ap->mcast_all) {
  2412. cmd.evt = C_SET_MULTICAST_MODE;
  2413. cmd.code = C_C_MCAST_DISABLE;
  2414. cmd.idx = 0;
  2415. ace_issue_cmd(regs, &cmd);
  2416. ap->mcast_all = 0;
  2417. }
  2418. if ((dev->flags & IFF_PROMISC) && !(ap->promisc)) {
  2419. cmd.evt = C_SET_PROMISC_MODE;
  2420. cmd.code = C_C_PROMISC_ENABLE;
  2421. cmd.idx = 0;
  2422. ace_issue_cmd(regs, &cmd);
  2423. ap->promisc = 1;
  2424. }else if (!(dev->flags & IFF_PROMISC) && (ap->promisc)) {
  2425. cmd.evt = C_SET_PROMISC_MODE;
  2426. cmd.code = C_C_PROMISC_DISABLE;
  2427. cmd.idx = 0;
  2428. ace_issue_cmd(regs, &cmd);
  2429. ap->promisc = 0;
  2430. }
  2431. /*
  2432. * For the time being multicast relies on the upper layers
  2433. * filtering it properly. The Firmware does not allow one to
  2434. * set the entire multicast list at a time and keeping track of
  2435. * it here is going to be messy.
  2436. */
  2437. if ((dev->mc_count) && !(ap->mcast_all)) {
  2438. cmd.evt = C_SET_MULTICAST_MODE;
  2439. cmd.code = C_C_MCAST_ENABLE;
  2440. cmd.idx = 0;
  2441. ace_issue_cmd(regs, &cmd);
  2442. }else if (!ap->mcast_all) {
  2443. cmd.evt = C_SET_MULTICAST_MODE;
  2444. cmd.code = C_C_MCAST_DISABLE;
  2445. cmd.idx = 0;
  2446. ace_issue_cmd(regs, &cmd);
  2447. }
  2448. }
  2449. static struct net_device_stats *ace_get_stats(struct net_device *dev)
  2450. {
  2451. struct ace_private *ap = netdev_priv(dev);
  2452. struct ace_mac_stats __iomem *mac_stats =
  2453. (struct ace_mac_stats __iomem *)ap->regs->Stats;
  2454. dev->stats.rx_missed_errors = readl(&mac_stats->drop_space);
  2455. dev->stats.multicast = readl(&mac_stats->kept_mc);
  2456. dev->stats.collisions = readl(&mac_stats->coll);
  2457. return &dev->stats;
  2458. }
  2459. static void __devinit ace_copy(struct ace_regs __iomem *regs, void *src,
  2460. u32 dest, int size)
  2461. {
  2462. void __iomem *tdest;
  2463. u32 *wsrc;
  2464. short tsize, i;
  2465. if (size <= 0)
  2466. return;
  2467. while (size > 0) {
  2468. tsize = min_t(u32, ((~dest & (ACE_WINDOW_SIZE - 1)) + 1),
  2469. min_t(u32, size, ACE_WINDOW_SIZE));
  2470. tdest = (void __iomem *) &regs->Window +
  2471. (dest & (ACE_WINDOW_SIZE - 1));
  2472. writel(dest & ~(ACE_WINDOW_SIZE - 1), &regs->WinBase);
  2473. /*
  2474. * This requires byte swapping on big endian, however
  2475. * writel does that for us
  2476. */
  2477. wsrc = src;
  2478. for (i = 0; i < (tsize / 4); i++) {
  2479. writel(wsrc[i], tdest + i*4);
  2480. }
  2481. dest += tsize;
  2482. src += tsize;
  2483. size -= tsize;
  2484. }
  2485. return;
  2486. }
  2487. static void __devinit ace_clear(struct ace_regs __iomem *regs, u32 dest, int size)
  2488. {
  2489. void __iomem *tdest;
  2490. short tsize = 0, i;
  2491. if (size <= 0)
  2492. return;
  2493. while (size > 0) {
  2494. tsize = min_t(u32, ((~dest & (ACE_WINDOW_SIZE - 1)) + 1),
  2495. min_t(u32, size, ACE_WINDOW_SIZE));
  2496. tdest = (void __iomem *) &regs->Window +
  2497. (dest & (ACE_WINDOW_SIZE - 1));
  2498. writel(dest & ~(ACE_WINDOW_SIZE - 1), &regs->WinBase);
  2499. for (i = 0; i < (tsize / 4); i++) {
  2500. writel(0, tdest + i*4);
  2501. }
  2502. dest += tsize;
  2503. size -= tsize;
  2504. }
  2505. return;
  2506. }
  2507. /*
  2508. * Download the firmware into the SRAM on the NIC
  2509. *
  2510. * This operation requires the NIC to be halted and is performed with
  2511. * interrupts disabled and with the spinlock hold.
  2512. */
  2513. static int __devinit ace_load_firmware(struct net_device *dev)
  2514. {
  2515. struct ace_private *ap = netdev_priv(dev);
  2516. struct ace_regs __iomem *regs = ap->regs;
  2517. if (!(readl(&regs->CpuCtrl) & CPU_HALTED)) {
  2518. printk(KERN_ERR "%s: trying to download firmware while the "
  2519. "CPU is running!\n", ap->name);
  2520. return -EFAULT;
  2521. }
  2522. /*
  2523. * Do not try to clear more than 512KB or we end up seeing
  2524. * funny things on NICs with only 512KB SRAM
  2525. */
  2526. ace_clear(regs, 0x2000, 0x80000-0x2000);
  2527. if (ACE_IS_TIGON_I(ap)) {
  2528. ace_copy(regs, tigonFwText, tigonFwTextAddr, tigonFwTextLen);
  2529. ace_copy(regs, tigonFwData, tigonFwDataAddr, tigonFwDataLen);
  2530. ace_copy(regs, tigonFwRodata, tigonFwRodataAddr,
  2531. tigonFwRodataLen);
  2532. ace_clear(regs, tigonFwBssAddr, tigonFwBssLen);
  2533. ace_clear(regs, tigonFwSbssAddr, tigonFwSbssLen);
  2534. }else if (ap->version == 2) {
  2535. ace_clear(regs, tigon2FwBssAddr, tigon2FwBssLen);
  2536. ace_clear(regs, tigon2FwSbssAddr, tigon2FwSbssLen);
  2537. ace_copy(regs, tigon2FwText, tigon2FwTextAddr,tigon2FwTextLen);
  2538. ace_copy(regs, tigon2FwRodata, tigon2FwRodataAddr,
  2539. tigon2FwRodataLen);
  2540. ace_copy(regs, tigon2FwData, tigon2FwDataAddr,tigon2FwDataLen);
  2541. }
  2542. return 0;
  2543. }
  2544. /*
  2545. * The eeprom on the AceNIC is an Atmel i2c EEPROM.
  2546. *
  2547. * Accessing the EEPROM is `interesting' to say the least - don't read
  2548. * this code right after dinner.
  2549. *
  2550. * This is all about black magic and bit-banging the device .... I
  2551. * wonder in what hospital they have put the guy who designed the i2c
  2552. * specs.
  2553. *
  2554. * Oh yes, this is only the beginning!
  2555. *
  2556. * Thanks to Stevarino Webinski for helping tracking down the bugs in the
  2557. * code i2c readout code by beta testing all my hacks.
  2558. */
  2559. static void __devinit eeprom_start(struct ace_regs __iomem *regs)
  2560. {
  2561. u32 local;
  2562. readl(&regs->LocalCtrl);
  2563. udelay(ACE_SHORT_DELAY);
  2564. local = readl(&regs->LocalCtrl);
  2565. local |= EEPROM_DATA_OUT | EEPROM_WRITE_ENABLE;
  2566. writel(local, &regs->LocalCtrl);
  2567. readl(&regs->LocalCtrl);
  2568. mb();
  2569. udelay(ACE_SHORT_DELAY);
  2570. local |= EEPROM_CLK_OUT;
  2571. writel(local, &regs->LocalCtrl);
  2572. readl(&regs->LocalCtrl);
  2573. mb();
  2574. udelay(ACE_SHORT_DELAY);
  2575. local &= ~EEPROM_DATA_OUT;
  2576. writel(local, &regs->LocalCtrl);
  2577. readl(&regs->LocalCtrl);
  2578. mb();
  2579. udelay(ACE_SHORT_DELAY);
  2580. local &= ~EEPROM_CLK_OUT;
  2581. writel(local, &regs->LocalCtrl);
  2582. readl(&regs->LocalCtrl);
  2583. mb();
  2584. }
  2585. static void __devinit eeprom_prep(struct ace_regs __iomem *regs, u8 magic)
  2586. {
  2587. short i;
  2588. u32 local;
  2589. udelay(ACE_SHORT_DELAY);
  2590. local = readl(&regs->LocalCtrl);
  2591. local &= ~EEPROM_DATA_OUT;
  2592. local |= EEPROM_WRITE_ENABLE;
  2593. writel(local, &regs->LocalCtrl);
  2594. readl(&regs->LocalCtrl);
  2595. mb();
  2596. for (i = 0; i < 8; i++, magic <<= 1) {
  2597. udelay(ACE_SHORT_DELAY);
  2598. if (magic & 0x80)
  2599. local |= EEPROM_DATA_OUT;
  2600. else
  2601. local &= ~EEPROM_DATA_OUT;
  2602. writel(local, &regs->LocalCtrl);
  2603. readl(&regs->LocalCtrl);
  2604. mb();
  2605. udelay(ACE_SHORT_DELAY);
  2606. local |= EEPROM_CLK_OUT;
  2607. writel(local, &regs->LocalCtrl);
  2608. readl(&regs->LocalCtrl);
  2609. mb();
  2610. udelay(ACE_SHORT_DELAY);
  2611. local &= ~(EEPROM_CLK_OUT | EEPROM_DATA_OUT);
  2612. writel(local, &regs->LocalCtrl);
  2613. readl(&regs->LocalCtrl);
  2614. mb();
  2615. }
  2616. }
  2617. static int __devinit eeprom_check_ack(struct ace_regs __iomem *regs)
  2618. {
  2619. int state;
  2620. u32 local;
  2621. local = readl(&regs->LocalCtrl);
  2622. local &= ~EEPROM_WRITE_ENABLE;
  2623. writel(local, &regs->LocalCtrl);
  2624. readl(&regs->LocalCtrl);
  2625. mb();
  2626. udelay(ACE_LONG_DELAY);
  2627. local |= EEPROM_CLK_OUT;
  2628. writel(local, &regs->LocalCtrl);
  2629. readl(&regs->LocalCtrl);
  2630. mb();
  2631. udelay(ACE_SHORT_DELAY);
  2632. /* sample data in middle of high clk */
  2633. state = (readl(&regs->LocalCtrl) & EEPROM_DATA_IN) != 0;
  2634. udelay(ACE_SHORT_DELAY);
  2635. mb();
  2636. writel(readl(&regs->LocalCtrl) & ~EEPROM_CLK_OUT, &regs->LocalCtrl);
  2637. readl(&regs->LocalCtrl);
  2638. mb();
  2639. return state;
  2640. }
  2641. static void __devinit eeprom_stop(struct ace_regs __iomem *regs)
  2642. {
  2643. u32 local;
  2644. udelay(ACE_SHORT_DELAY);
  2645. local = readl(&regs->LocalCtrl);
  2646. local |= EEPROM_WRITE_ENABLE;
  2647. writel(local, &regs->LocalCtrl);
  2648. readl(&regs->LocalCtrl);
  2649. mb();
  2650. udelay(ACE_SHORT_DELAY);
  2651. local &= ~EEPROM_DATA_OUT;
  2652. writel(local, &regs->LocalCtrl);
  2653. readl(&regs->LocalCtrl);
  2654. mb();
  2655. udelay(ACE_SHORT_DELAY);
  2656. local |= EEPROM_CLK_OUT;
  2657. writel(local, &regs->LocalCtrl);
  2658. readl(&regs->LocalCtrl);
  2659. mb();
  2660. udelay(ACE_SHORT_DELAY);
  2661. local |= EEPROM_DATA_OUT;
  2662. writel(local, &regs->LocalCtrl);
  2663. readl(&regs->LocalCtrl);
  2664. mb();
  2665. udelay(ACE_LONG_DELAY);
  2666. local &= ~EEPROM_CLK_OUT;
  2667. writel(local, &regs->LocalCtrl);
  2668. mb();
  2669. }
  2670. /*
  2671. * Read a whole byte from the EEPROM.
  2672. */
  2673. static int __devinit read_eeprom_byte(struct net_device *dev,
  2674. unsigned long offset)
  2675. {
  2676. struct ace_private *ap = netdev_priv(dev);
  2677. struct ace_regs __iomem *regs = ap->regs;
  2678. unsigned long flags;
  2679. u32 local;
  2680. int result = 0;
  2681. short i;
  2682. /*
  2683. * Don't take interrupts on this CPU will bit banging
  2684. * the %#%#@$ I2C device
  2685. */
  2686. local_irq_save(flags);
  2687. eeprom_start(regs);
  2688. eeprom_prep(regs, EEPROM_WRITE_SELECT);
  2689. if (eeprom_check_ack(regs)) {
  2690. local_irq_restore(flags);
  2691. printk(KERN_ERR "%s: Unable to sync eeprom\n", ap->name);
  2692. result = -EIO;
  2693. goto eeprom_read_error;
  2694. }
  2695. eeprom_prep(regs, (offset >> 8) & 0xff);
  2696. if (eeprom_check_ack(regs)) {
  2697. local_irq_restore(flags);
  2698. printk(KERN_ERR "%s: Unable to set address byte 0\n",
  2699. ap->name);
  2700. result = -EIO;
  2701. goto eeprom_read_error;
  2702. }
  2703. eeprom_prep(regs, offset & 0xff);
  2704. if (eeprom_check_ack(regs)) {
  2705. local_irq_restore(flags);
  2706. printk(KERN_ERR "%s: Unable to set address byte 1\n",
  2707. ap->name);
  2708. result = -EIO;
  2709. goto eeprom_read_error;
  2710. }
  2711. eeprom_start(regs);
  2712. eeprom_prep(regs, EEPROM_READ_SELECT);
  2713. if (eeprom_check_ack(regs)) {
  2714. local_irq_restore(flags);
  2715. printk(KERN_ERR "%s: Unable to set READ_SELECT\n",
  2716. ap->name);
  2717. result = -EIO;
  2718. goto eeprom_read_error;
  2719. }
  2720. for (i = 0; i < 8; i++) {
  2721. local = readl(&regs->LocalCtrl);
  2722. local &= ~EEPROM_WRITE_ENABLE;
  2723. writel(local, &regs->LocalCtrl);
  2724. readl(&regs->LocalCtrl);
  2725. udelay(ACE_LONG_DELAY);
  2726. mb();
  2727. local |= EEPROM_CLK_OUT;
  2728. writel(local, &regs->LocalCtrl);
  2729. readl(&regs->LocalCtrl);
  2730. mb();
  2731. udelay(ACE_SHORT_DELAY);
  2732. /* sample data mid high clk */
  2733. result = (result << 1) |
  2734. ((readl(&regs->LocalCtrl) & EEPROM_DATA_IN) != 0);
  2735. udelay(ACE_SHORT_DELAY);
  2736. mb();
  2737. local = readl(&regs->LocalCtrl);
  2738. local &= ~EEPROM_CLK_OUT;
  2739. writel(local, &regs->LocalCtrl);
  2740. readl(&regs->LocalCtrl);
  2741. udelay(ACE_SHORT_DELAY);
  2742. mb();
  2743. if (i == 7) {
  2744. local |= EEPROM_WRITE_ENABLE;
  2745. writel(local, &regs->LocalCtrl);
  2746. readl(&regs->LocalCtrl);
  2747. mb();
  2748. udelay(ACE_SHORT_DELAY);
  2749. }
  2750. }
  2751. local |= EEPROM_DATA_OUT;
  2752. writel(local, &regs->LocalCtrl);
  2753. readl(&regs->LocalCtrl);
  2754. mb();
  2755. udelay(ACE_SHORT_DELAY);
  2756. writel(readl(&regs->LocalCtrl) | EEPROM_CLK_OUT, &regs->LocalCtrl);
  2757. readl(&regs->LocalCtrl);
  2758. udelay(ACE_LONG_DELAY);
  2759. writel(readl(&regs->LocalCtrl) & ~EEPROM_CLK_OUT, &regs->LocalCtrl);
  2760. readl(&regs->LocalCtrl);
  2761. mb();
  2762. udelay(ACE_SHORT_DELAY);
  2763. eeprom_stop(regs);
  2764. local_irq_restore(flags);
  2765. out:
  2766. return result;
  2767. eeprom_read_error:
  2768. printk(KERN_ERR "%s: Unable to read eeprom byte 0x%02lx\n",
  2769. ap->name, offset);
  2770. goto out;
  2771. }
  2772. /*
  2773. * Local variables:
  2774. * compile-command: "gcc -D__SMP__ -D__KERNEL__ -DMODULE -I../../include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -fno-strength-reduce -DMODVERSIONS -include ../../include/linux/modversions.h -c -o acenic.o acenic.c"
  2775. * End:
  2776. */