acenic.c 87 KB

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