acenic.c 86 KB

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