e1000_main.c 129 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613
  1. /*******************************************************************************
  2. Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the Free
  5. Software Foundation; either version 2 of the License, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc., 59
  13. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. The full GNU General Public License is included in this distribution in the
  15. file called LICENSE.
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include "e1000.h"
  21. /* Change Log
  22. * 7.0.33 3-Feb-2006
  23. * o Added another fix for the pass false carrier bit
  24. * 7.0.32 24-Jan-2006
  25. * o Need to rebuild with noew version number for the pass false carrier
  26. * fix in e1000_hw.c
  27. * 7.0.30 18-Jan-2006
  28. * o fixup for tso workaround to disable it for pci-x
  29. * o fix mem leak on 82542
  30. * o fixes for 10 Mb/s connections and incorrect stats
  31. * 7.0.28 01/06/2006
  32. * o hardware workaround to only set "speed mode" bit for 1G link.
  33. * 7.0.26 12/23/2005
  34. * o wake on lan support modified for device ID 10B5
  35. * o fix dhcp + vlan issue not making it to the iAMT firmware
  36. * 7.0.24 12/9/2005
  37. * o New hardware support for the Gigabit NIC embedded in the south bridge
  38. * o Fixes to the recycling logic (skb->tail) from IBM LTC
  39. * 6.3.9 12/16/2005
  40. * o incorporate fix for recycled skbs from IBM LTC
  41. * 6.3.7 11/18/2005
  42. * o Honor eeprom setting for enabling/disabling Wake On Lan
  43. * 6.3.5 11/17/2005
  44. * o Fix memory leak in rx ring handling for PCI Express adapters
  45. * 6.3.4 11/8/05
  46. * o Patch from Jesper Juhl to remove redundant NULL checks for kfree
  47. * 6.3.2 9/20/05
  48. * o Render logic that sets/resets DRV_LOAD as inline functions to
  49. * avoid code replication. If f/w is AMT then set DRV_LOAD only when
  50. * network interface is open.
  51. * o Handle DRV_LOAD set/reset in cases where AMT uses VLANs.
  52. * o Adjust PBA partioning for Jumbo frames using MTU size and not
  53. * rx_buffer_len
  54. * 6.3.1 9/19/05
  55. * o Use adapter->tx_timeout_factor in Tx Hung Detect logic
  56. * (e1000_clean_tx_irq)
  57. * o Support for 8086:10B5 device (Quad Port)
  58. */
  59. char e1000_driver_name[] = "e1000";
  60. static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
  61. #ifndef CONFIG_E1000_NAPI
  62. #define DRIVERNAPI
  63. #else
  64. #define DRIVERNAPI "-NAPI"
  65. #endif
  66. #define DRV_VERSION "7.0.33-k2"DRIVERNAPI
  67. char e1000_driver_version[] = DRV_VERSION;
  68. static char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
  69. /* e1000_pci_tbl - PCI Device ID Table
  70. *
  71. * Last entry must be all 0s
  72. *
  73. * Macro expands to...
  74. * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
  75. */
  76. static struct pci_device_id e1000_pci_tbl[] = {
  77. INTEL_E1000_ETHERNET_DEVICE(0x1000),
  78. INTEL_E1000_ETHERNET_DEVICE(0x1001),
  79. INTEL_E1000_ETHERNET_DEVICE(0x1004),
  80. INTEL_E1000_ETHERNET_DEVICE(0x1008),
  81. INTEL_E1000_ETHERNET_DEVICE(0x1009),
  82. INTEL_E1000_ETHERNET_DEVICE(0x100C),
  83. INTEL_E1000_ETHERNET_DEVICE(0x100D),
  84. INTEL_E1000_ETHERNET_DEVICE(0x100E),
  85. INTEL_E1000_ETHERNET_DEVICE(0x100F),
  86. INTEL_E1000_ETHERNET_DEVICE(0x1010),
  87. INTEL_E1000_ETHERNET_DEVICE(0x1011),
  88. INTEL_E1000_ETHERNET_DEVICE(0x1012),
  89. INTEL_E1000_ETHERNET_DEVICE(0x1013),
  90. INTEL_E1000_ETHERNET_DEVICE(0x1014),
  91. INTEL_E1000_ETHERNET_DEVICE(0x1015),
  92. INTEL_E1000_ETHERNET_DEVICE(0x1016),
  93. INTEL_E1000_ETHERNET_DEVICE(0x1017),
  94. INTEL_E1000_ETHERNET_DEVICE(0x1018),
  95. INTEL_E1000_ETHERNET_DEVICE(0x1019),
  96. INTEL_E1000_ETHERNET_DEVICE(0x101A),
  97. INTEL_E1000_ETHERNET_DEVICE(0x101D),
  98. INTEL_E1000_ETHERNET_DEVICE(0x101E),
  99. INTEL_E1000_ETHERNET_DEVICE(0x1026),
  100. INTEL_E1000_ETHERNET_DEVICE(0x1027),
  101. INTEL_E1000_ETHERNET_DEVICE(0x1028),
  102. INTEL_E1000_ETHERNET_DEVICE(0x105E),
  103. INTEL_E1000_ETHERNET_DEVICE(0x105F),
  104. INTEL_E1000_ETHERNET_DEVICE(0x1060),
  105. INTEL_E1000_ETHERNET_DEVICE(0x1075),
  106. INTEL_E1000_ETHERNET_DEVICE(0x1076),
  107. INTEL_E1000_ETHERNET_DEVICE(0x1077),
  108. INTEL_E1000_ETHERNET_DEVICE(0x1078),
  109. INTEL_E1000_ETHERNET_DEVICE(0x1079),
  110. INTEL_E1000_ETHERNET_DEVICE(0x107A),
  111. INTEL_E1000_ETHERNET_DEVICE(0x107B),
  112. INTEL_E1000_ETHERNET_DEVICE(0x107C),
  113. INTEL_E1000_ETHERNET_DEVICE(0x107D),
  114. INTEL_E1000_ETHERNET_DEVICE(0x107E),
  115. INTEL_E1000_ETHERNET_DEVICE(0x107F),
  116. INTEL_E1000_ETHERNET_DEVICE(0x108A),
  117. INTEL_E1000_ETHERNET_DEVICE(0x108B),
  118. INTEL_E1000_ETHERNET_DEVICE(0x108C),
  119. INTEL_E1000_ETHERNET_DEVICE(0x1096),
  120. INTEL_E1000_ETHERNET_DEVICE(0x1098),
  121. INTEL_E1000_ETHERNET_DEVICE(0x1099),
  122. INTEL_E1000_ETHERNET_DEVICE(0x109A),
  123. INTEL_E1000_ETHERNET_DEVICE(0x10B5),
  124. INTEL_E1000_ETHERNET_DEVICE(0x10B9),
  125. /* required last entry */
  126. {0,}
  127. };
  128. MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
  129. static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
  130. struct e1000_tx_ring *txdr);
  131. static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
  132. struct e1000_rx_ring *rxdr);
  133. static void e1000_free_tx_resources(struct e1000_adapter *adapter,
  134. struct e1000_tx_ring *tx_ring);
  135. static void e1000_free_rx_resources(struct e1000_adapter *adapter,
  136. struct e1000_rx_ring *rx_ring);
  137. /* Local Function Prototypes */
  138. static int e1000_init_module(void);
  139. static void e1000_exit_module(void);
  140. static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
  141. static void __devexit e1000_remove(struct pci_dev *pdev);
  142. static int e1000_alloc_queues(struct e1000_adapter *adapter);
  143. static int e1000_sw_init(struct e1000_adapter *adapter);
  144. static int e1000_open(struct net_device *netdev);
  145. static int e1000_close(struct net_device *netdev);
  146. static void e1000_configure_tx(struct e1000_adapter *adapter);
  147. static void e1000_configure_rx(struct e1000_adapter *adapter);
  148. static void e1000_setup_rctl(struct e1000_adapter *adapter);
  149. static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
  150. static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
  151. static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
  152. struct e1000_tx_ring *tx_ring);
  153. static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
  154. struct e1000_rx_ring *rx_ring);
  155. static void e1000_set_multi(struct net_device *netdev);
  156. static void e1000_update_phy_info(unsigned long data);
  157. static void e1000_watchdog(unsigned long data);
  158. static void e1000_watchdog_task(struct e1000_adapter *adapter);
  159. static void e1000_82547_tx_fifo_stall(unsigned long data);
  160. static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
  161. static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
  162. static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
  163. static int e1000_set_mac(struct net_device *netdev, void *p);
  164. static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
  165. static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
  166. struct e1000_tx_ring *tx_ring);
  167. #ifdef CONFIG_E1000_NAPI
  168. static int e1000_clean(struct net_device *poll_dev, int *budget);
  169. static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
  170. struct e1000_rx_ring *rx_ring,
  171. int *work_done, int work_to_do);
  172. static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
  173. struct e1000_rx_ring *rx_ring,
  174. int *work_done, int work_to_do);
  175. #else
  176. static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
  177. struct e1000_rx_ring *rx_ring);
  178. static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
  179. struct e1000_rx_ring *rx_ring);
  180. #endif
  181. static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
  182. struct e1000_rx_ring *rx_ring,
  183. int cleaned_count);
  184. static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
  185. struct e1000_rx_ring *rx_ring,
  186. int cleaned_count);
  187. static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
  188. static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
  189. int cmd);
  190. static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
  191. static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
  192. static void e1000_tx_timeout(struct net_device *dev);
  193. static void e1000_reset_task(struct net_device *dev);
  194. static void e1000_smartspeed(struct e1000_adapter *adapter);
  195. static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
  196. struct sk_buff *skb);
  197. static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
  198. static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
  199. static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
  200. static void e1000_restore_vlan(struct e1000_adapter *adapter);
  201. #ifdef CONFIG_PM
  202. static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
  203. static int e1000_resume(struct pci_dev *pdev);
  204. #endif
  205. #ifdef CONFIG_NET_POLL_CONTROLLER
  206. /* for netdump / net console */
  207. static void e1000_netpoll (struct net_device *netdev);
  208. #endif
  209. static struct pci_driver e1000_driver = {
  210. .name = e1000_driver_name,
  211. .id_table = e1000_pci_tbl,
  212. .probe = e1000_probe,
  213. .remove = __devexit_p(e1000_remove),
  214. /* Power Managment Hooks */
  215. #ifdef CONFIG_PM
  216. .suspend = e1000_suspend,
  217. .resume = e1000_resume
  218. #endif
  219. };
  220. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  221. MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
  222. MODULE_LICENSE("GPL");
  223. MODULE_VERSION(DRV_VERSION);
  224. static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
  225. module_param(debug, int, 0);
  226. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  227. /**
  228. * e1000_init_module - Driver Registration Routine
  229. *
  230. * e1000_init_module is the first routine called when the driver is
  231. * loaded. All it does is register with the PCI subsystem.
  232. **/
  233. static int __init
  234. e1000_init_module(void)
  235. {
  236. int ret;
  237. printk(KERN_INFO "%s - version %s\n",
  238. e1000_driver_string, e1000_driver_version);
  239. printk(KERN_INFO "%s\n", e1000_copyright);
  240. ret = pci_module_init(&e1000_driver);
  241. return ret;
  242. }
  243. module_init(e1000_init_module);
  244. /**
  245. * e1000_exit_module - Driver Exit Cleanup Routine
  246. *
  247. * e1000_exit_module is called just before the driver is removed
  248. * from memory.
  249. **/
  250. static void __exit
  251. e1000_exit_module(void)
  252. {
  253. pci_unregister_driver(&e1000_driver);
  254. }
  255. module_exit(e1000_exit_module);
  256. /**
  257. * e1000_irq_disable - Mask off interrupt generation on the NIC
  258. * @adapter: board private structure
  259. **/
  260. static inline void
  261. e1000_irq_disable(struct e1000_adapter *adapter)
  262. {
  263. atomic_inc(&adapter->irq_sem);
  264. E1000_WRITE_REG(&adapter->hw, IMC, ~0);
  265. E1000_WRITE_FLUSH(&adapter->hw);
  266. synchronize_irq(adapter->pdev->irq);
  267. }
  268. /**
  269. * e1000_irq_enable - Enable default interrupt generation settings
  270. * @adapter: board private structure
  271. **/
  272. static inline void
  273. e1000_irq_enable(struct e1000_adapter *adapter)
  274. {
  275. if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
  276. E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
  277. E1000_WRITE_FLUSH(&adapter->hw);
  278. }
  279. }
  280. static void
  281. e1000_update_mng_vlan(struct e1000_adapter *adapter)
  282. {
  283. struct net_device *netdev = adapter->netdev;
  284. uint16_t vid = adapter->hw.mng_cookie.vlan_id;
  285. uint16_t old_vid = adapter->mng_vlan_id;
  286. if (adapter->vlgrp) {
  287. if (!adapter->vlgrp->vlan_devices[vid]) {
  288. if (adapter->hw.mng_cookie.status &
  289. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
  290. e1000_vlan_rx_add_vid(netdev, vid);
  291. adapter->mng_vlan_id = vid;
  292. } else
  293. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  294. if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
  295. (vid != old_vid) &&
  296. !adapter->vlgrp->vlan_devices[old_vid])
  297. e1000_vlan_rx_kill_vid(netdev, old_vid);
  298. } else
  299. adapter->mng_vlan_id = vid;
  300. }
  301. }
  302. /**
  303. * e1000_release_hw_control - release control of the h/w to f/w
  304. * @adapter: address of board private structure
  305. *
  306. * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
  307. * For ASF and Pass Through versions of f/w this means that the
  308. * driver is no longer loaded. For AMT version (only with 82573) i
  309. * of the f/w this means that the netowrk i/f is closed.
  310. *
  311. **/
  312. static inline void
  313. e1000_release_hw_control(struct e1000_adapter *adapter)
  314. {
  315. uint32_t ctrl_ext;
  316. uint32_t swsm;
  317. /* Let firmware taken over control of h/w */
  318. switch (adapter->hw.mac_type) {
  319. case e1000_82571:
  320. case e1000_82572:
  321. case e1000_80003es2lan:
  322. ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
  323. E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
  324. ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
  325. break;
  326. case e1000_82573:
  327. swsm = E1000_READ_REG(&adapter->hw, SWSM);
  328. E1000_WRITE_REG(&adapter->hw, SWSM,
  329. swsm & ~E1000_SWSM_DRV_LOAD);
  330. default:
  331. break;
  332. }
  333. }
  334. /**
  335. * e1000_get_hw_control - get control of the h/w from f/w
  336. * @adapter: address of board private structure
  337. *
  338. * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
  339. * For ASF and Pass Through versions of f/w this means that
  340. * the driver is loaded. For AMT version (only with 82573)
  341. * of the f/w this means that the netowrk i/f is open.
  342. *
  343. **/
  344. static inline void
  345. e1000_get_hw_control(struct e1000_adapter *adapter)
  346. {
  347. uint32_t ctrl_ext;
  348. uint32_t swsm;
  349. /* Let firmware know the driver has taken over */
  350. switch (adapter->hw.mac_type) {
  351. case e1000_82571:
  352. case e1000_82572:
  353. case e1000_80003es2lan:
  354. ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
  355. E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
  356. ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
  357. break;
  358. case e1000_82573:
  359. swsm = E1000_READ_REG(&adapter->hw, SWSM);
  360. E1000_WRITE_REG(&adapter->hw, SWSM,
  361. swsm | E1000_SWSM_DRV_LOAD);
  362. break;
  363. default:
  364. break;
  365. }
  366. }
  367. int
  368. e1000_up(struct e1000_adapter *adapter)
  369. {
  370. struct net_device *netdev = adapter->netdev;
  371. int i, err;
  372. /* hardware has been reset, we need to reload some things */
  373. /* Reset the PHY if it was previously powered down */
  374. if (adapter->hw.media_type == e1000_media_type_copper) {
  375. uint16_t mii_reg;
  376. e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
  377. if (mii_reg & MII_CR_POWER_DOWN)
  378. e1000_phy_hw_reset(&adapter->hw);
  379. }
  380. e1000_set_multi(netdev);
  381. e1000_restore_vlan(adapter);
  382. e1000_configure_tx(adapter);
  383. e1000_setup_rctl(adapter);
  384. e1000_configure_rx(adapter);
  385. /* call E1000_DESC_UNUSED which always leaves
  386. * at least 1 descriptor unused to make sure
  387. * next_to_use != next_to_clean */
  388. for (i = 0; i < adapter->num_rx_queues; i++) {
  389. struct e1000_rx_ring *ring = &adapter->rx_ring[i];
  390. adapter->alloc_rx_buf(adapter, ring,
  391. E1000_DESC_UNUSED(ring));
  392. }
  393. #ifdef CONFIG_PCI_MSI
  394. if (adapter->hw.mac_type > e1000_82547_rev_2) {
  395. adapter->have_msi = TRUE;
  396. if ((err = pci_enable_msi(adapter->pdev))) {
  397. DPRINTK(PROBE, ERR,
  398. "Unable to allocate MSI interrupt Error: %d\n", err);
  399. adapter->have_msi = FALSE;
  400. }
  401. }
  402. #endif
  403. if ((err = request_irq(adapter->pdev->irq, &e1000_intr,
  404. SA_SHIRQ | SA_SAMPLE_RANDOM,
  405. netdev->name, netdev))) {
  406. DPRINTK(PROBE, ERR,
  407. "Unable to allocate interrupt Error: %d\n", err);
  408. return err;
  409. }
  410. adapter->tx_queue_len = netdev->tx_queue_len;
  411. mod_timer(&adapter->watchdog_timer, jiffies);
  412. #ifdef CONFIG_E1000_NAPI
  413. netif_poll_enable(netdev);
  414. #endif
  415. e1000_irq_enable(adapter);
  416. return 0;
  417. }
  418. void
  419. e1000_down(struct e1000_adapter *adapter)
  420. {
  421. struct net_device *netdev = adapter->netdev;
  422. boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
  423. e1000_check_mng_mode(&adapter->hw);
  424. e1000_irq_disable(adapter);
  425. free_irq(adapter->pdev->irq, netdev);
  426. #ifdef CONFIG_PCI_MSI
  427. if (adapter->hw.mac_type > e1000_82547_rev_2 &&
  428. adapter->have_msi == TRUE)
  429. pci_disable_msi(adapter->pdev);
  430. #endif
  431. del_timer_sync(&adapter->tx_fifo_stall_timer);
  432. del_timer_sync(&adapter->watchdog_timer);
  433. del_timer_sync(&adapter->phy_info_timer);
  434. #ifdef CONFIG_E1000_NAPI
  435. netif_poll_disable(netdev);
  436. #endif
  437. netdev->tx_queue_len = adapter->tx_queue_len;
  438. adapter->link_speed = 0;
  439. adapter->link_duplex = 0;
  440. netif_carrier_off(netdev);
  441. netif_stop_queue(netdev);
  442. e1000_reset(adapter);
  443. e1000_clean_all_tx_rings(adapter);
  444. e1000_clean_all_rx_rings(adapter);
  445. /* Power down the PHY so no link is implied when interface is down *
  446. * The PHY cannot be powered down if any of the following is TRUE *
  447. * (a) WoL is enabled
  448. * (b) AMT is active
  449. * (c) SoL/IDER session is active */
  450. if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
  451. adapter->hw.media_type == e1000_media_type_copper &&
  452. !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
  453. !mng_mode_enabled &&
  454. !e1000_check_phy_reset_block(&adapter->hw)) {
  455. uint16_t mii_reg;
  456. e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
  457. mii_reg |= MII_CR_POWER_DOWN;
  458. e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
  459. mdelay(1);
  460. }
  461. }
  462. void
  463. e1000_reset(struct e1000_adapter *adapter)
  464. {
  465. uint32_t pba, manc;
  466. uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
  467. /* Repartition Pba for greater than 9k mtu
  468. * To take effect CTRL.RST is required.
  469. */
  470. switch (adapter->hw.mac_type) {
  471. case e1000_82547:
  472. case e1000_82547_rev_2:
  473. pba = E1000_PBA_30K;
  474. break;
  475. case e1000_82571:
  476. case e1000_82572:
  477. case e1000_80003es2lan:
  478. pba = E1000_PBA_38K;
  479. break;
  480. case e1000_82573:
  481. pba = E1000_PBA_12K;
  482. break;
  483. default:
  484. pba = E1000_PBA_48K;
  485. break;
  486. }
  487. if ((adapter->hw.mac_type != e1000_82573) &&
  488. (adapter->netdev->mtu > E1000_RXBUFFER_8192))
  489. pba -= 8; /* allocate more FIFO for Tx */
  490. if (adapter->hw.mac_type == e1000_82547) {
  491. adapter->tx_fifo_head = 0;
  492. adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
  493. adapter->tx_fifo_size =
  494. (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
  495. atomic_set(&adapter->tx_fifo_stall, 0);
  496. }
  497. E1000_WRITE_REG(&adapter->hw, PBA, pba);
  498. /* flow control settings */
  499. /* Set the FC high water mark to 90% of the FIFO size.
  500. * Required to clear last 3 LSB */
  501. fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
  502. adapter->hw.fc_high_water = fc_high_water_mark;
  503. adapter->hw.fc_low_water = fc_high_water_mark - 8;
  504. if (adapter->hw.mac_type == e1000_80003es2lan)
  505. adapter->hw.fc_pause_time = 0xFFFF;
  506. else
  507. adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
  508. adapter->hw.fc_send_xon = 1;
  509. adapter->hw.fc = adapter->hw.original_fc;
  510. /* Allow time for pending master requests to run */
  511. e1000_reset_hw(&adapter->hw);
  512. if (adapter->hw.mac_type >= e1000_82544)
  513. E1000_WRITE_REG(&adapter->hw, WUC, 0);
  514. if (e1000_init_hw(&adapter->hw))
  515. DPRINTK(PROBE, ERR, "Hardware Error\n");
  516. e1000_update_mng_vlan(adapter);
  517. /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
  518. E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
  519. e1000_reset_adaptive(&adapter->hw);
  520. e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
  521. if (adapter->en_mng_pt) {
  522. manc = E1000_READ_REG(&adapter->hw, MANC);
  523. manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
  524. E1000_WRITE_REG(&adapter->hw, MANC, manc);
  525. }
  526. }
  527. /**
  528. * e1000_probe - Device Initialization Routine
  529. * @pdev: PCI device information struct
  530. * @ent: entry in e1000_pci_tbl
  531. *
  532. * Returns 0 on success, negative on failure
  533. *
  534. * e1000_probe initializes an adapter identified by a pci_dev structure.
  535. * The OS initialization, configuring of the adapter private structure,
  536. * and a hardware reset occur.
  537. **/
  538. static int __devinit
  539. e1000_probe(struct pci_dev *pdev,
  540. const struct pci_device_id *ent)
  541. {
  542. struct net_device *netdev;
  543. struct e1000_adapter *adapter;
  544. unsigned long mmio_start, mmio_len;
  545. static int cards_found = 0;
  546. static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */
  547. int i, err, pci_using_dac;
  548. uint16_t eeprom_data;
  549. uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
  550. if ((err = pci_enable_device(pdev)))
  551. return err;
  552. if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
  553. pci_using_dac = 1;
  554. } else {
  555. if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
  556. E1000_ERR("No usable DMA configuration, aborting\n");
  557. return err;
  558. }
  559. pci_using_dac = 0;
  560. }
  561. if ((err = pci_request_regions(pdev, e1000_driver_name)))
  562. return err;
  563. pci_set_master(pdev);
  564. netdev = alloc_etherdev(sizeof(struct e1000_adapter));
  565. if (!netdev) {
  566. err = -ENOMEM;
  567. goto err_alloc_etherdev;
  568. }
  569. SET_MODULE_OWNER(netdev);
  570. SET_NETDEV_DEV(netdev, &pdev->dev);
  571. pci_set_drvdata(pdev, netdev);
  572. adapter = netdev_priv(netdev);
  573. adapter->netdev = netdev;
  574. adapter->pdev = pdev;
  575. adapter->hw.back = adapter;
  576. adapter->msg_enable = (1 << debug) - 1;
  577. mmio_start = pci_resource_start(pdev, BAR_0);
  578. mmio_len = pci_resource_len(pdev, BAR_0);
  579. adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
  580. if (!adapter->hw.hw_addr) {
  581. err = -EIO;
  582. goto err_ioremap;
  583. }
  584. for (i = BAR_1; i <= BAR_5; i++) {
  585. if (pci_resource_len(pdev, i) == 0)
  586. continue;
  587. if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
  588. adapter->hw.io_base = pci_resource_start(pdev, i);
  589. break;
  590. }
  591. }
  592. netdev->open = &e1000_open;
  593. netdev->stop = &e1000_close;
  594. netdev->hard_start_xmit = &e1000_xmit_frame;
  595. netdev->get_stats = &e1000_get_stats;
  596. netdev->set_multicast_list = &e1000_set_multi;
  597. netdev->set_mac_address = &e1000_set_mac;
  598. netdev->change_mtu = &e1000_change_mtu;
  599. netdev->do_ioctl = &e1000_ioctl;
  600. e1000_set_ethtool_ops(netdev);
  601. netdev->tx_timeout = &e1000_tx_timeout;
  602. netdev->watchdog_timeo = 5 * HZ;
  603. #ifdef CONFIG_E1000_NAPI
  604. netdev->poll = &e1000_clean;
  605. netdev->weight = 64;
  606. #endif
  607. netdev->vlan_rx_register = e1000_vlan_rx_register;
  608. netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
  609. netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
  610. #ifdef CONFIG_NET_POLL_CONTROLLER
  611. netdev->poll_controller = e1000_netpoll;
  612. #endif
  613. strcpy(netdev->name, pci_name(pdev));
  614. netdev->mem_start = mmio_start;
  615. netdev->mem_end = mmio_start + mmio_len;
  616. netdev->base_addr = adapter->hw.io_base;
  617. adapter->bd_number = cards_found;
  618. /* setup the private structure */
  619. if ((err = e1000_sw_init(adapter)))
  620. goto err_sw_init;
  621. if ((err = e1000_check_phy_reset_block(&adapter->hw)))
  622. DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
  623. /* if ksp3, indicate if it's port a being setup */
  624. if (pdev->device == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 &&
  625. e1000_ksp3_port_a == 0)
  626. adapter->ksp3_port_a = 1;
  627. e1000_ksp3_port_a++;
  628. /* Reset for multiple KP3 adapters */
  629. if (e1000_ksp3_port_a == 4)
  630. e1000_ksp3_port_a = 0;
  631. if (adapter->hw.mac_type >= e1000_82543) {
  632. netdev->features = NETIF_F_SG |
  633. NETIF_F_HW_CSUM |
  634. NETIF_F_HW_VLAN_TX |
  635. NETIF_F_HW_VLAN_RX |
  636. NETIF_F_HW_VLAN_FILTER;
  637. }
  638. #ifdef NETIF_F_TSO
  639. if ((adapter->hw.mac_type >= e1000_82544) &&
  640. (adapter->hw.mac_type != e1000_82547))
  641. netdev->features |= NETIF_F_TSO;
  642. #ifdef NETIF_F_TSO_IPV6
  643. if (adapter->hw.mac_type > e1000_82547_rev_2)
  644. netdev->features |= NETIF_F_TSO_IPV6;
  645. #endif
  646. #endif
  647. if (pci_using_dac)
  648. netdev->features |= NETIF_F_HIGHDMA;
  649. /* hard_start_xmit is safe against parallel locking */
  650. netdev->features |= NETIF_F_LLTX;
  651. adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
  652. /* before reading the EEPROM, reset the controller to
  653. * put the device in a known good starting state */
  654. e1000_reset_hw(&adapter->hw);
  655. /* make sure the EEPROM is good */
  656. if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
  657. DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
  658. err = -EIO;
  659. goto err_eeprom;
  660. }
  661. /* copy the MAC address out of the EEPROM */
  662. if (e1000_read_mac_addr(&adapter->hw))
  663. DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
  664. memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
  665. memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
  666. if (!is_valid_ether_addr(netdev->perm_addr)) {
  667. DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
  668. err = -EIO;
  669. goto err_eeprom;
  670. }
  671. e1000_read_part_num(&adapter->hw, &(adapter->part_num));
  672. e1000_get_bus_info(&adapter->hw);
  673. init_timer(&adapter->tx_fifo_stall_timer);
  674. adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
  675. adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
  676. init_timer(&adapter->watchdog_timer);
  677. adapter->watchdog_timer.function = &e1000_watchdog;
  678. adapter->watchdog_timer.data = (unsigned long) adapter;
  679. INIT_WORK(&adapter->watchdog_task,
  680. (void (*)(void *))e1000_watchdog_task, adapter);
  681. init_timer(&adapter->phy_info_timer);
  682. adapter->phy_info_timer.function = &e1000_update_phy_info;
  683. adapter->phy_info_timer.data = (unsigned long) adapter;
  684. INIT_WORK(&adapter->reset_task,
  685. (void (*)(void *))e1000_reset_task, netdev);
  686. /* we're going to reset, so assume we have no link for now */
  687. netif_carrier_off(netdev);
  688. netif_stop_queue(netdev);
  689. e1000_check_options(adapter);
  690. /* Initial Wake on LAN setting
  691. * If APM wake is enabled in the EEPROM,
  692. * enable the ACPI Magic Packet filter
  693. */
  694. switch (adapter->hw.mac_type) {
  695. case e1000_82542_rev2_0:
  696. case e1000_82542_rev2_1:
  697. case e1000_82543:
  698. break;
  699. case e1000_82544:
  700. e1000_read_eeprom(&adapter->hw,
  701. EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
  702. eeprom_apme_mask = E1000_EEPROM_82544_APM;
  703. break;
  704. case e1000_82546:
  705. case e1000_82546_rev_3:
  706. case e1000_82571:
  707. case e1000_80003es2lan:
  708. if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
  709. e1000_read_eeprom(&adapter->hw,
  710. EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
  711. break;
  712. }
  713. /* Fall Through */
  714. default:
  715. e1000_read_eeprom(&adapter->hw,
  716. EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
  717. break;
  718. }
  719. if (eeprom_data & eeprom_apme_mask)
  720. adapter->wol |= E1000_WUFC_MAG;
  721. /* print bus type/speed/width info */
  722. {
  723. struct e1000_hw *hw = &adapter->hw;
  724. DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
  725. ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
  726. (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
  727. ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
  728. (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
  729. (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
  730. (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
  731. (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
  732. ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
  733. (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
  734. (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
  735. "32-bit"));
  736. }
  737. for (i = 0; i < 6; i++)
  738. printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
  739. /* reset the hardware with the new settings */
  740. e1000_reset(adapter);
  741. /* If the controller is 82573 and f/w is AMT, do not set
  742. * DRV_LOAD until the interface is up. For all other cases,
  743. * let the f/w know that the h/w is now under the control
  744. * of the driver. */
  745. if (adapter->hw.mac_type != e1000_82573 ||
  746. !e1000_check_mng_mode(&adapter->hw))
  747. e1000_get_hw_control(adapter);
  748. strcpy(netdev->name, "eth%d");
  749. if ((err = register_netdev(netdev)))
  750. goto err_register;
  751. DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
  752. cards_found++;
  753. return 0;
  754. err_register:
  755. err_sw_init:
  756. err_eeprom:
  757. iounmap(adapter->hw.hw_addr);
  758. err_ioremap:
  759. free_netdev(netdev);
  760. err_alloc_etherdev:
  761. pci_release_regions(pdev);
  762. return err;
  763. }
  764. /**
  765. * e1000_remove - Device Removal Routine
  766. * @pdev: PCI device information struct
  767. *
  768. * e1000_remove is called by the PCI subsystem to alert the driver
  769. * that it should release a PCI device. The could be caused by a
  770. * Hot-Plug event, or because the driver is going to be removed from
  771. * memory.
  772. **/
  773. static void __devexit
  774. e1000_remove(struct pci_dev *pdev)
  775. {
  776. struct net_device *netdev = pci_get_drvdata(pdev);
  777. struct e1000_adapter *adapter = netdev_priv(netdev);
  778. uint32_t manc;
  779. #ifdef CONFIG_E1000_NAPI
  780. int i;
  781. #endif
  782. flush_scheduled_work();
  783. if (adapter->hw.mac_type >= e1000_82540 &&
  784. adapter->hw.media_type == e1000_media_type_copper) {
  785. manc = E1000_READ_REG(&adapter->hw, MANC);
  786. if (manc & E1000_MANC_SMBUS_EN) {
  787. manc |= E1000_MANC_ARP_EN;
  788. E1000_WRITE_REG(&adapter->hw, MANC, manc);
  789. }
  790. }
  791. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  792. * would have already happened in close and is redundant. */
  793. e1000_release_hw_control(adapter);
  794. unregister_netdev(netdev);
  795. #ifdef CONFIG_E1000_NAPI
  796. for (i = 0; i < adapter->num_rx_queues; i++)
  797. dev_put(&adapter->polling_netdev[i]);
  798. #endif
  799. if (!e1000_check_phy_reset_block(&adapter->hw))
  800. e1000_phy_hw_reset(&adapter->hw);
  801. kfree(adapter->tx_ring);
  802. kfree(adapter->rx_ring);
  803. #ifdef CONFIG_E1000_NAPI
  804. kfree(adapter->polling_netdev);
  805. #endif
  806. iounmap(adapter->hw.hw_addr);
  807. pci_release_regions(pdev);
  808. free_netdev(netdev);
  809. pci_disable_device(pdev);
  810. }
  811. /**
  812. * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
  813. * @adapter: board private structure to initialize
  814. *
  815. * e1000_sw_init initializes the Adapter private data structure.
  816. * Fields are initialized based on PCI device information and
  817. * OS network device settings (MTU size).
  818. **/
  819. static int __devinit
  820. e1000_sw_init(struct e1000_adapter *adapter)
  821. {
  822. struct e1000_hw *hw = &adapter->hw;
  823. struct net_device *netdev = adapter->netdev;
  824. struct pci_dev *pdev = adapter->pdev;
  825. #ifdef CONFIG_E1000_NAPI
  826. int i;
  827. #endif
  828. /* PCI config space info */
  829. hw->vendor_id = pdev->vendor;
  830. hw->device_id = pdev->device;
  831. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  832. hw->subsystem_id = pdev->subsystem_device;
  833. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  834. pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
  835. adapter->rx_buffer_len = E1000_RXBUFFER_2048;
  836. adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
  837. hw->max_frame_size = netdev->mtu +
  838. ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
  839. hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
  840. /* identify the MAC */
  841. if (e1000_set_mac_type(hw)) {
  842. DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
  843. return -EIO;
  844. }
  845. /* initialize eeprom parameters */
  846. if (e1000_init_eeprom_params(hw)) {
  847. E1000_ERR("EEPROM initialization failed\n");
  848. return -EIO;
  849. }
  850. switch (hw->mac_type) {
  851. default:
  852. break;
  853. case e1000_82541:
  854. case e1000_82547:
  855. case e1000_82541_rev_2:
  856. case e1000_82547_rev_2:
  857. hw->phy_init_script = 1;
  858. break;
  859. }
  860. e1000_set_media_type(hw);
  861. hw->wait_autoneg_complete = FALSE;
  862. hw->tbi_compatibility_en = TRUE;
  863. hw->adaptive_ifs = TRUE;
  864. /* Copper options */
  865. if (hw->media_type == e1000_media_type_copper) {
  866. hw->mdix = AUTO_ALL_MODES;
  867. hw->disable_polarity_correction = FALSE;
  868. hw->master_slave = E1000_MASTER_SLAVE;
  869. }
  870. adapter->num_tx_queues = 1;
  871. adapter->num_rx_queues = 1;
  872. if (e1000_alloc_queues(adapter)) {
  873. DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
  874. return -ENOMEM;
  875. }
  876. #ifdef CONFIG_E1000_NAPI
  877. for (i = 0; i < adapter->num_rx_queues; i++) {
  878. adapter->polling_netdev[i].priv = adapter;
  879. adapter->polling_netdev[i].poll = &e1000_clean;
  880. adapter->polling_netdev[i].weight = 64;
  881. dev_hold(&adapter->polling_netdev[i]);
  882. set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
  883. }
  884. spin_lock_init(&adapter->tx_queue_lock);
  885. #endif
  886. atomic_set(&adapter->irq_sem, 1);
  887. spin_lock_init(&adapter->stats_lock);
  888. return 0;
  889. }
  890. /**
  891. * e1000_alloc_queues - Allocate memory for all rings
  892. * @adapter: board private structure to initialize
  893. *
  894. * We allocate one ring per queue at run-time since we don't know the
  895. * number of queues at compile-time. The polling_netdev array is
  896. * intended for Multiqueue, but should work fine with a single queue.
  897. **/
  898. static int __devinit
  899. e1000_alloc_queues(struct e1000_adapter *adapter)
  900. {
  901. int size;
  902. size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
  903. adapter->tx_ring = kmalloc(size, GFP_KERNEL);
  904. if (!adapter->tx_ring)
  905. return -ENOMEM;
  906. memset(adapter->tx_ring, 0, size);
  907. size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
  908. adapter->rx_ring = kmalloc(size, GFP_KERNEL);
  909. if (!adapter->rx_ring) {
  910. kfree(adapter->tx_ring);
  911. return -ENOMEM;
  912. }
  913. memset(adapter->rx_ring, 0, size);
  914. #ifdef CONFIG_E1000_NAPI
  915. size = sizeof(struct net_device) * adapter->num_rx_queues;
  916. adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
  917. if (!adapter->polling_netdev) {
  918. kfree(adapter->tx_ring);
  919. kfree(adapter->rx_ring);
  920. return -ENOMEM;
  921. }
  922. memset(adapter->polling_netdev, 0, size);
  923. #endif
  924. return E1000_SUCCESS;
  925. }
  926. /**
  927. * e1000_open - Called when a network interface is made active
  928. * @netdev: network interface device structure
  929. *
  930. * Returns 0 on success, negative value on failure
  931. *
  932. * The open entry point is called when a network interface is made
  933. * active by the system (IFF_UP). At this point all resources needed
  934. * for transmit and receive operations are allocated, the interrupt
  935. * handler is registered with the OS, the watchdog timer is started,
  936. * and the stack is notified that the interface is ready.
  937. **/
  938. static int
  939. e1000_open(struct net_device *netdev)
  940. {
  941. struct e1000_adapter *adapter = netdev_priv(netdev);
  942. int err;
  943. /* allocate transmit descriptors */
  944. if ((err = e1000_setup_all_tx_resources(adapter)))
  945. goto err_setup_tx;
  946. /* allocate receive descriptors */
  947. if ((err = e1000_setup_all_rx_resources(adapter)))
  948. goto err_setup_rx;
  949. if ((err = e1000_up(adapter)))
  950. goto err_up;
  951. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  952. if ((adapter->hw.mng_cookie.status &
  953. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
  954. e1000_update_mng_vlan(adapter);
  955. }
  956. /* If AMT is enabled, let the firmware know that the network
  957. * interface is now open */
  958. if (adapter->hw.mac_type == e1000_82573 &&
  959. e1000_check_mng_mode(&adapter->hw))
  960. e1000_get_hw_control(adapter);
  961. return E1000_SUCCESS;
  962. err_up:
  963. e1000_free_all_rx_resources(adapter);
  964. err_setup_rx:
  965. e1000_free_all_tx_resources(adapter);
  966. err_setup_tx:
  967. e1000_reset(adapter);
  968. return err;
  969. }
  970. /**
  971. * e1000_close - Disables a network interface
  972. * @netdev: network interface device structure
  973. *
  974. * Returns 0, this is not allowed to fail
  975. *
  976. * The close entry point is called when an interface is de-activated
  977. * by the OS. The hardware is still under the drivers control, but
  978. * needs to be disabled. A global MAC reset is issued to stop the
  979. * hardware, and all transmit and receive resources are freed.
  980. **/
  981. static int
  982. e1000_close(struct net_device *netdev)
  983. {
  984. struct e1000_adapter *adapter = netdev_priv(netdev);
  985. e1000_down(adapter);
  986. e1000_free_all_tx_resources(adapter);
  987. e1000_free_all_rx_resources(adapter);
  988. if ((adapter->hw.mng_cookie.status &
  989. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
  990. e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
  991. }
  992. /* If AMT is enabled, let the firmware know that the network
  993. * interface is now closed */
  994. if (adapter->hw.mac_type == e1000_82573 &&
  995. e1000_check_mng_mode(&adapter->hw))
  996. e1000_release_hw_control(adapter);
  997. return 0;
  998. }
  999. /**
  1000. * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
  1001. * @adapter: address of board private structure
  1002. * @start: address of beginning of memory
  1003. * @len: length of memory
  1004. **/
  1005. static inline boolean_t
  1006. e1000_check_64k_bound(struct e1000_adapter *adapter,
  1007. void *start, unsigned long len)
  1008. {
  1009. unsigned long begin = (unsigned long) start;
  1010. unsigned long end = begin + len;
  1011. /* First rev 82545 and 82546 need to not allow any memory
  1012. * write location to cross 64k boundary due to errata 23 */
  1013. if (adapter->hw.mac_type == e1000_82545 ||
  1014. adapter->hw.mac_type == e1000_82546) {
  1015. return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
  1016. }
  1017. return TRUE;
  1018. }
  1019. /**
  1020. * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
  1021. * @adapter: board private structure
  1022. * @txdr: tx descriptor ring (for a specific queue) to setup
  1023. *
  1024. * Return 0 on success, negative on failure
  1025. **/
  1026. static int
  1027. e1000_setup_tx_resources(struct e1000_adapter *adapter,
  1028. struct e1000_tx_ring *txdr)
  1029. {
  1030. struct pci_dev *pdev = adapter->pdev;
  1031. int size;
  1032. size = sizeof(struct e1000_buffer) * txdr->count;
  1033. txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
  1034. if (!txdr->buffer_info) {
  1035. DPRINTK(PROBE, ERR,
  1036. "Unable to allocate memory for the transmit descriptor ring\n");
  1037. return -ENOMEM;
  1038. }
  1039. memset(txdr->buffer_info, 0, size);
  1040. /* round up to nearest 4K */
  1041. txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
  1042. E1000_ROUNDUP(txdr->size, 4096);
  1043. txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
  1044. if (!txdr->desc) {
  1045. setup_tx_desc_die:
  1046. vfree(txdr->buffer_info);
  1047. DPRINTK(PROBE, ERR,
  1048. "Unable to allocate memory for the transmit descriptor ring\n");
  1049. return -ENOMEM;
  1050. }
  1051. /* Fix for errata 23, can't cross 64kB boundary */
  1052. if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
  1053. void *olddesc = txdr->desc;
  1054. dma_addr_t olddma = txdr->dma;
  1055. DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
  1056. "at %p\n", txdr->size, txdr->desc);
  1057. /* Try again, without freeing the previous */
  1058. txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
  1059. /* Failed allocation, critical failure */
  1060. if (!txdr->desc) {
  1061. pci_free_consistent(pdev, txdr->size, olddesc, olddma);
  1062. goto setup_tx_desc_die;
  1063. }
  1064. if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
  1065. /* give up */
  1066. pci_free_consistent(pdev, txdr->size, txdr->desc,
  1067. txdr->dma);
  1068. pci_free_consistent(pdev, txdr->size, olddesc, olddma);
  1069. DPRINTK(PROBE, ERR,
  1070. "Unable to allocate aligned memory "
  1071. "for the transmit descriptor ring\n");
  1072. vfree(txdr->buffer_info);
  1073. return -ENOMEM;
  1074. } else {
  1075. /* Free old allocation, new allocation was successful */
  1076. pci_free_consistent(pdev, txdr->size, olddesc, olddma);
  1077. }
  1078. }
  1079. memset(txdr->desc, 0, txdr->size);
  1080. txdr->next_to_use = 0;
  1081. txdr->next_to_clean = 0;
  1082. spin_lock_init(&txdr->tx_lock);
  1083. return 0;
  1084. }
  1085. /**
  1086. * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
  1087. * (Descriptors) for all queues
  1088. * @adapter: board private structure
  1089. *
  1090. * If this function returns with an error, then it's possible one or
  1091. * more of the rings is populated (while the rest are not). It is the
  1092. * callers duty to clean those orphaned rings.
  1093. *
  1094. * Return 0 on success, negative on failure
  1095. **/
  1096. int
  1097. e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
  1098. {
  1099. int i, err = 0;
  1100. for (i = 0; i < adapter->num_tx_queues; i++) {
  1101. err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
  1102. if (err) {
  1103. DPRINTK(PROBE, ERR,
  1104. "Allocation for Tx Queue %u failed\n", i);
  1105. break;
  1106. }
  1107. }
  1108. return err;
  1109. }
  1110. /**
  1111. * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
  1112. * @adapter: board private structure
  1113. *
  1114. * Configure the Tx unit of the MAC after a reset.
  1115. **/
  1116. static void
  1117. e1000_configure_tx(struct e1000_adapter *adapter)
  1118. {
  1119. uint64_t tdba;
  1120. struct e1000_hw *hw = &adapter->hw;
  1121. uint32_t tdlen, tctl, tipg, tarc;
  1122. uint32_t ipgr1, ipgr2;
  1123. /* Setup the HW Tx Head and Tail descriptor pointers */
  1124. switch (adapter->num_tx_queues) {
  1125. case 1:
  1126. default:
  1127. tdba = adapter->tx_ring[0].dma;
  1128. tdlen = adapter->tx_ring[0].count *
  1129. sizeof(struct e1000_tx_desc);
  1130. E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
  1131. E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
  1132. E1000_WRITE_REG(hw, TDLEN, tdlen);
  1133. E1000_WRITE_REG(hw, TDH, 0);
  1134. E1000_WRITE_REG(hw, TDT, 0);
  1135. adapter->tx_ring[0].tdh = E1000_TDH;
  1136. adapter->tx_ring[0].tdt = E1000_TDT;
  1137. break;
  1138. }
  1139. /* Set the default values for the Tx Inter Packet Gap timer */
  1140. if (hw->media_type == e1000_media_type_fiber ||
  1141. hw->media_type == e1000_media_type_internal_serdes)
  1142. tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
  1143. else
  1144. tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
  1145. switch (hw->mac_type) {
  1146. case e1000_82542_rev2_0:
  1147. case e1000_82542_rev2_1:
  1148. tipg = DEFAULT_82542_TIPG_IPGT;
  1149. ipgr1 = DEFAULT_82542_TIPG_IPGR1;
  1150. ipgr2 = DEFAULT_82542_TIPG_IPGR2;
  1151. break;
  1152. case e1000_80003es2lan:
  1153. ipgr1 = DEFAULT_82543_TIPG_IPGR1;
  1154. ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
  1155. break;
  1156. default:
  1157. ipgr1 = DEFAULT_82543_TIPG_IPGR1;
  1158. ipgr2 = DEFAULT_82543_TIPG_IPGR2;
  1159. break;
  1160. }
  1161. tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
  1162. tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
  1163. E1000_WRITE_REG(hw, TIPG, tipg);
  1164. /* Set the Tx Interrupt Delay register */
  1165. E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
  1166. if (hw->mac_type >= e1000_82540)
  1167. E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
  1168. /* Program the Transmit Control Register */
  1169. tctl = E1000_READ_REG(hw, TCTL);
  1170. tctl &= ~E1000_TCTL_CT;
  1171. tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
  1172. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
  1173. #ifdef DISABLE_MULR
  1174. /* disable Multiple Reads for debugging */
  1175. tctl &= ~E1000_TCTL_MULR;
  1176. #endif
  1177. if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
  1178. tarc = E1000_READ_REG(hw, TARC0);
  1179. tarc |= ((1 << 25) | (1 << 21));
  1180. E1000_WRITE_REG(hw, TARC0, tarc);
  1181. tarc = E1000_READ_REG(hw, TARC1);
  1182. tarc |= (1 << 25);
  1183. if (tctl & E1000_TCTL_MULR)
  1184. tarc &= ~(1 << 28);
  1185. else
  1186. tarc |= (1 << 28);
  1187. E1000_WRITE_REG(hw, TARC1, tarc);
  1188. } else if (hw->mac_type == e1000_80003es2lan) {
  1189. tarc = E1000_READ_REG(hw, TARC0);
  1190. tarc |= 1;
  1191. if (hw->media_type == e1000_media_type_internal_serdes)
  1192. tarc |= (1 << 20);
  1193. E1000_WRITE_REG(hw, TARC0, tarc);
  1194. tarc = E1000_READ_REG(hw, TARC1);
  1195. tarc |= 1;
  1196. E1000_WRITE_REG(hw, TARC1, tarc);
  1197. }
  1198. e1000_config_collision_dist(hw);
  1199. /* Setup Transmit Descriptor Settings for eop descriptor */
  1200. adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
  1201. E1000_TXD_CMD_IFCS;
  1202. if (hw->mac_type < e1000_82543)
  1203. adapter->txd_cmd |= E1000_TXD_CMD_RPS;
  1204. else
  1205. adapter->txd_cmd |= E1000_TXD_CMD_RS;
  1206. /* Cache if we're 82544 running in PCI-X because we'll
  1207. * need this to apply a workaround later in the send path. */
  1208. if (hw->mac_type == e1000_82544 &&
  1209. hw->bus_type == e1000_bus_type_pcix)
  1210. adapter->pcix_82544 = 1;
  1211. E1000_WRITE_REG(hw, TCTL, tctl);
  1212. }
  1213. /**
  1214. * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
  1215. * @adapter: board private structure
  1216. * @rxdr: rx descriptor ring (for a specific queue) to setup
  1217. *
  1218. * Returns 0 on success, negative on failure
  1219. **/
  1220. static int
  1221. e1000_setup_rx_resources(struct e1000_adapter *adapter,
  1222. struct e1000_rx_ring *rxdr)
  1223. {
  1224. struct pci_dev *pdev = adapter->pdev;
  1225. int size, desc_len;
  1226. size = sizeof(struct e1000_buffer) * rxdr->count;
  1227. rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
  1228. if (!rxdr->buffer_info) {
  1229. DPRINTK(PROBE, ERR,
  1230. "Unable to allocate memory for the receive descriptor ring\n");
  1231. return -ENOMEM;
  1232. }
  1233. memset(rxdr->buffer_info, 0, size);
  1234. size = sizeof(struct e1000_ps_page) * rxdr->count;
  1235. rxdr->ps_page = kmalloc(size, GFP_KERNEL);
  1236. if (!rxdr->ps_page) {
  1237. vfree(rxdr->buffer_info);
  1238. DPRINTK(PROBE, ERR,
  1239. "Unable to allocate memory for the receive descriptor ring\n");
  1240. return -ENOMEM;
  1241. }
  1242. memset(rxdr->ps_page, 0, size);
  1243. size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
  1244. rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
  1245. if (!rxdr->ps_page_dma) {
  1246. vfree(rxdr->buffer_info);
  1247. kfree(rxdr->ps_page);
  1248. DPRINTK(PROBE, ERR,
  1249. "Unable to allocate memory for the receive descriptor ring\n");
  1250. return -ENOMEM;
  1251. }
  1252. memset(rxdr->ps_page_dma, 0, size);
  1253. if (adapter->hw.mac_type <= e1000_82547_rev_2)
  1254. desc_len = sizeof(struct e1000_rx_desc);
  1255. else
  1256. desc_len = sizeof(union e1000_rx_desc_packet_split);
  1257. /* Round up to nearest 4K */
  1258. rxdr->size = rxdr->count * desc_len;
  1259. E1000_ROUNDUP(rxdr->size, 4096);
  1260. rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
  1261. if (!rxdr->desc) {
  1262. DPRINTK(PROBE, ERR,
  1263. "Unable to allocate memory for the receive descriptor ring\n");
  1264. setup_rx_desc_die:
  1265. vfree(rxdr->buffer_info);
  1266. kfree(rxdr->ps_page);
  1267. kfree(rxdr->ps_page_dma);
  1268. return -ENOMEM;
  1269. }
  1270. /* Fix for errata 23, can't cross 64kB boundary */
  1271. if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
  1272. void *olddesc = rxdr->desc;
  1273. dma_addr_t olddma = rxdr->dma;
  1274. DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
  1275. "at %p\n", rxdr->size, rxdr->desc);
  1276. /* Try again, without freeing the previous */
  1277. rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
  1278. /* Failed allocation, critical failure */
  1279. if (!rxdr->desc) {
  1280. pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
  1281. DPRINTK(PROBE, ERR,
  1282. "Unable to allocate memory "
  1283. "for the receive descriptor ring\n");
  1284. goto setup_rx_desc_die;
  1285. }
  1286. if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
  1287. /* give up */
  1288. pci_free_consistent(pdev, rxdr->size, rxdr->desc,
  1289. rxdr->dma);
  1290. pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
  1291. DPRINTK(PROBE, ERR,
  1292. "Unable to allocate aligned memory "
  1293. "for the receive descriptor ring\n");
  1294. goto setup_rx_desc_die;
  1295. } else {
  1296. /* Free old allocation, new allocation was successful */
  1297. pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
  1298. }
  1299. }
  1300. memset(rxdr->desc, 0, rxdr->size);
  1301. rxdr->next_to_clean = 0;
  1302. rxdr->next_to_use = 0;
  1303. return 0;
  1304. }
  1305. /**
  1306. * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
  1307. * (Descriptors) for all queues
  1308. * @adapter: board private structure
  1309. *
  1310. * If this function returns with an error, then it's possible one or
  1311. * more of the rings is populated (while the rest are not). It is the
  1312. * callers duty to clean those orphaned rings.
  1313. *
  1314. * Return 0 on success, negative on failure
  1315. **/
  1316. int
  1317. e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
  1318. {
  1319. int i, err = 0;
  1320. for (i = 0; i < adapter->num_rx_queues; i++) {
  1321. err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
  1322. if (err) {
  1323. DPRINTK(PROBE, ERR,
  1324. "Allocation for Rx Queue %u failed\n", i);
  1325. break;
  1326. }
  1327. }
  1328. return err;
  1329. }
  1330. /**
  1331. * e1000_setup_rctl - configure the receive control registers
  1332. * @adapter: Board private structure
  1333. **/
  1334. #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
  1335. (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
  1336. static void
  1337. e1000_setup_rctl(struct e1000_adapter *adapter)
  1338. {
  1339. uint32_t rctl, rfctl;
  1340. uint32_t psrctl = 0;
  1341. #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
  1342. uint32_t pages = 0;
  1343. #endif
  1344. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  1345. rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
  1346. rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
  1347. E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
  1348. (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
  1349. if (adapter->hw.mac_type > e1000_82543)
  1350. rctl |= E1000_RCTL_SECRC;
  1351. if (adapter->hw.tbi_compatibility_on == 1)
  1352. rctl |= E1000_RCTL_SBP;
  1353. else
  1354. rctl &= ~E1000_RCTL_SBP;
  1355. if (adapter->netdev->mtu <= ETH_DATA_LEN)
  1356. rctl &= ~E1000_RCTL_LPE;
  1357. else
  1358. rctl |= E1000_RCTL_LPE;
  1359. /* Setup buffer sizes */
  1360. if (adapter->hw.mac_type >= e1000_82571) {
  1361. /* We can now specify buffers in 1K increments.
  1362. * BSIZE and BSEX are ignored in this case. */
  1363. rctl |= adapter->rx_buffer_len << 0x11;
  1364. } else {
  1365. rctl &= ~E1000_RCTL_SZ_4096;
  1366. rctl |= E1000_RCTL_BSEX;
  1367. switch (adapter->rx_buffer_len) {
  1368. case E1000_RXBUFFER_2048:
  1369. default:
  1370. rctl |= E1000_RCTL_SZ_2048;
  1371. rctl &= ~E1000_RCTL_BSEX;
  1372. break;
  1373. case E1000_RXBUFFER_4096:
  1374. rctl |= E1000_RCTL_SZ_4096;
  1375. break;
  1376. case E1000_RXBUFFER_8192:
  1377. rctl |= E1000_RCTL_SZ_8192;
  1378. break;
  1379. case E1000_RXBUFFER_16384:
  1380. rctl |= E1000_RCTL_SZ_16384;
  1381. break;
  1382. }
  1383. }
  1384. #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
  1385. /* 82571 and greater support packet-split where the protocol
  1386. * header is placed in skb->data and the packet data is
  1387. * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
  1388. * In the case of a non-split, skb->data is linearly filled,
  1389. * followed by the page buffers. Therefore, skb->data is
  1390. * sized to hold the largest protocol header.
  1391. */
  1392. pages = PAGE_USE_COUNT(adapter->netdev->mtu);
  1393. if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
  1394. PAGE_SIZE <= 16384)
  1395. adapter->rx_ps_pages = pages;
  1396. else
  1397. adapter->rx_ps_pages = 0;
  1398. #endif
  1399. if (adapter->rx_ps_pages) {
  1400. /* Configure extra packet-split registers */
  1401. rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
  1402. rfctl |= E1000_RFCTL_EXTEN;
  1403. /* disable IPv6 packet split support */
  1404. rfctl |= E1000_RFCTL_IPV6_DIS;
  1405. E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
  1406. rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
  1407. psrctl |= adapter->rx_ps_bsize0 >>
  1408. E1000_PSRCTL_BSIZE0_SHIFT;
  1409. switch (adapter->rx_ps_pages) {
  1410. case 3:
  1411. psrctl |= PAGE_SIZE <<
  1412. E1000_PSRCTL_BSIZE3_SHIFT;
  1413. case 2:
  1414. psrctl |= PAGE_SIZE <<
  1415. E1000_PSRCTL_BSIZE2_SHIFT;
  1416. case 1:
  1417. psrctl |= PAGE_SIZE >>
  1418. E1000_PSRCTL_BSIZE1_SHIFT;
  1419. break;
  1420. }
  1421. E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
  1422. }
  1423. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  1424. }
  1425. /**
  1426. * e1000_configure_rx - Configure 8254x Receive Unit after Reset
  1427. * @adapter: board private structure
  1428. *
  1429. * Configure the Rx unit of the MAC after a reset.
  1430. **/
  1431. static void
  1432. e1000_configure_rx(struct e1000_adapter *adapter)
  1433. {
  1434. uint64_t rdba;
  1435. struct e1000_hw *hw = &adapter->hw;
  1436. uint32_t rdlen, rctl, rxcsum, ctrl_ext;
  1437. if (adapter->rx_ps_pages) {
  1438. /* this is a 32 byte descriptor */
  1439. rdlen = adapter->rx_ring[0].count *
  1440. sizeof(union e1000_rx_desc_packet_split);
  1441. adapter->clean_rx = e1000_clean_rx_irq_ps;
  1442. adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
  1443. } else {
  1444. rdlen = adapter->rx_ring[0].count *
  1445. sizeof(struct e1000_rx_desc);
  1446. adapter->clean_rx = e1000_clean_rx_irq;
  1447. adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
  1448. }
  1449. /* disable receives while setting up the descriptors */
  1450. rctl = E1000_READ_REG(hw, RCTL);
  1451. E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
  1452. /* set the Receive Delay Timer Register */
  1453. E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
  1454. if (hw->mac_type >= e1000_82540) {
  1455. E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
  1456. if (adapter->itr > 1)
  1457. E1000_WRITE_REG(hw, ITR,
  1458. 1000000000 / (adapter->itr * 256));
  1459. }
  1460. if (hw->mac_type >= e1000_82571) {
  1461. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1462. /* Reset delay timers after every interrupt */
  1463. ctrl_ext |= E1000_CTRL_EXT_CANC;
  1464. #ifdef CONFIG_E1000_NAPI
  1465. /* Auto-Mask interrupts upon ICR read. */
  1466. ctrl_ext |= E1000_CTRL_EXT_IAME;
  1467. #endif
  1468. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  1469. E1000_WRITE_REG(hw, IAM, ~0);
  1470. E1000_WRITE_FLUSH(hw);
  1471. }
  1472. /* Setup the HW Rx Head and Tail Descriptor Pointers and
  1473. * the Base and Length of the Rx Descriptor Ring */
  1474. switch (adapter->num_rx_queues) {
  1475. case 1:
  1476. default:
  1477. rdba = adapter->rx_ring[0].dma;
  1478. E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
  1479. E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
  1480. E1000_WRITE_REG(hw, RDLEN, rdlen);
  1481. E1000_WRITE_REG(hw, RDH, 0);
  1482. E1000_WRITE_REG(hw, RDT, 0);
  1483. adapter->rx_ring[0].rdh = E1000_RDH;
  1484. adapter->rx_ring[0].rdt = E1000_RDT;
  1485. break;
  1486. }
  1487. /* Enable 82543 Receive Checksum Offload for TCP and UDP */
  1488. if (hw->mac_type >= e1000_82543) {
  1489. rxcsum = E1000_READ_REG(hw, RXCSUM);
  1490. if (adapter->rx_csum == TRUE) {
  1491. rxcsum |= E1000_RXCSUM_TUOFL;
  1492. /* Enable 82571 IPv4 payload checksum for UDP fragments
  1493. * Must be used in conjunction with packet-split. */
  1494. if ((hw->mac_type >= e1000_82571) &&
  1495. (adapter->rx_ps_pages)) {
  1496. rxcsum |= E1000_RXCSUM_IPPCSE;
  1497. }
  1498. } else {
  1499. rxcsum &= ~E1000_RXCSUM_TUOFL;
  1500. /* don't need to clear IPPCSE as it defaults to 0 */
  1501. }
  1502. E1000_WRITE_REG(hw, RXCSUM, rxcsum);
  1503. }
  1504. if (hw->mac_type == e1000_82573)
  1505. E1000_WRITE_REG(hw, ERT, 0x0100);
  1506. /* Enable Receives */
  1507. E1000_WRITE_REG(hw, RCTL, rctl);
  1508. }
  1509. /**
  1510. * e1000_free_tx_resources - Free Tx Resources per Queue
  1511. * @adapter: board private structure
  1512. * @tx_ring: Tx descriptor ring for a specific queue
  1513. *
  1514. * Free all transmit software resources
  1515. **/
  1516. static void
  1517. e1000_free_tx_resources(struct e1000_adapter *adapter,
  1518. struct e1000_tx_ring *tx_ring)
  1519. {
  1520. struct pci_dev *pdev = adapter->pdev;
  1521. e1000_clean_tx_ring(adapter, tx_ring);
  1522. vfree(tx_ring->buffer_info);
  1523. tx_ring->buffer_info = NULL;
  1524. pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
  1525. tx_ring->desc = NULL;
  1526. }
  1527. /**
  1528. * e1000_free_all_tx_resources - Free Tx Resources for All Queues
  1529. * @adapter: board private structure
  1530. *
  1531. * Free all transmit software resources
  1532. **/
  1533. void
  1534. e1000_free_all_tx_resources(struct e1000_adapter *adapter)
  1535. {
  1536. int i;
  1537. for (i = 0; i < adapter->num_tx_queues; i++)
  1538. e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
  1539. }
  1540. static inline void
  1541. e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
  1542. struct e1000_buffer *buffer_info)
  1543. {
  1544. if (buffer_info->dma) {
  1545. pci_unmap_page(adapter->pdev,
  1546. buffer_info->dma,
  1547. buffer_info->length,
  1548. PCI_DMA_TODEVICE);
  1549. }
  1550. if (buffer_info->skb)
  1551. dev_kfree_skb_any(buffer_info->skb);
  1552. memset(buffer_info, 0, sizeof(struct e1000_buffer));
  1553. }
  1554. /**
  1555. * e1000_clean_tx_ring - Free Tx Buffers
  1556. * @adapter: board private structure
  1557. * @tx_ring: ring to be cleaned
  1558. **/
  1559. static void
  1560. e1000_clean_tx_ring(struct e1000_adapter *adapter,
  1561. struct e1000_tx_ring *tx_ring)
  1562. {
  1563. struct e1000_buffer *buffer_info;
  1564. unsigned long size;
  1565. unsigned int i;
  1566. /* Free all the Tx ring sk_buffs */
  1567. for (i = 0; i < tx_ring->count; i++) {
  1568. buffer_info = &tx_ring->buffer_info[i];
  1569. e1000_unmap_and_free_tx_resource(adapter, buffer_info);
  1570. }
  1571. size = sizeof(struct e1000_buffer) * tx_ring->count;
  1572. memset(tx_ring->buffer_info, 0, size);
  1573. /* Zero out the descriptor ring */
  1574. memset(tx_ring->desc, 0, tx_ring->size);
  1575. tx_ring->next_to_use = 0;
  1576. tx_ring->next_to_clean = 0;
  1577. tx_ring->last_tx_tso = 0;
  1578. writel(0, adapter->hw.hw_addr + tx_ring->tdh);
  1579. writel(0, adapter->hw.hw_addr + tx_ring->tdt);
  1580. }
  1581. /**
  1582. * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
  1583. * @adapter: board private structure
  1584. **/
  1585. static void
  1586. e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
  1587. {
  1588. int i;
  1589. for (i = 0; i < adapter->num_tx_queues; i++)
  1590. e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
  1591. }
  1592. /**
  1593. * e1000_free_rx_resources - Free Rx Resources
  1594. * @adapter: board private structure
  1595. * @rx_ring: ring to clean the resources from
  1596. *
  1597. * Free all receive software resources
  1598. **/
  1599. static void
  1600. e1000_free_rx_resources(struct e1000_adapter *adapter,
  1601. struct e1000_rx_ring *rx_ring)
  1602. {
  1603. struct pci_dev *pdev = adapter->pdev;
  1604. e1000_clean_rx_ring(adapter, rx_ring);
  1605. vfree(rx_ring->buffer_info);
  1606. rx_ring->buffer_info = NULL;
  1607. kfree(rx_ring->ps_page);
  1608. rx_ring->ps_page = NULL;
  1609. kfree(rx_ring->ps_page_dma);
  1610. rx_ring->ps_page_dma = NULL;
  1611. pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
  1612. rx_ring->desc = NULL;
  1613. }
  1614. /**
  1615. * e1000_free_all_rx_resources - Free Rx Resources for All Queues
  1616. * @adapter: board private structure
  1617. *
  1618. * Free all receive software resources
  1619. **/
  1620. void
  1621. e1000_free_all_rx_resources(struct e1000_adapter *adapter)
  1622. {
  1623. int i;
  1624. for (i = 0; i < adapter->num_rx_queues; i++)
  1625. e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
  1626. }
  1627. /**
  1628. * e1000_clean_rx_ring - Free Rx Buffers per Queue
  1629. * @adapter: board private structure
  1630. * @rx_ring: ring to free buffers from
  1631. **/
  1632. static void
  1633. e1000_clean_rx_ring(struct e1000_adapter *adapter,
  1634. struct e1000_rx_ring *rx_ring)
  1635. {
  1636. struct e1000_buffer *buffer_info;
  1637. struct e1000_ps_page *ps_page;
  1638. struct e1000_ps_page_dma *ps_page_dma;
  1639. struct pci_dev *pdev = adapter->pdev;
  1640. unsigned long size;
  1641. unsigned int i, j;
  1642. /* Free all the Rx ring sk_buffs */
  1643. for (i = 0; i < rx_ring->count; i++) {
  1644. buffer_info = &rx_ring->buffer_info[i];
  1645. if (buffer_info->skb) {
  1646. pci_unmap_single(pdev,
  1647. buffer_info->dma,
  1648. buffer_info->length,
  1649. PCI_DMA_FROMDEVICE);
  1650. dev_kfree_skb(buffer_info->skb);
  1651. buffer_info->skb = NULL;
  1652. }
  1653. ps_page = &rx_ring->ps_page[i];
  1654. ps_page_dma = &rx_ring->ps_page_dma[i];
  1655. for (j = 0; j < adapter->rx_ps_pages; j++) {
  1656. if (!ps_page->ps_page[j]) break;
  1657. pci_unmap_page(pdev,
  1658. ps_page_dma->ps_page_dma[j],
  1659. PAGE_SIZE, PCI_DMA_FROMDEVICE);
  1660. ps_page_dma->ps_page_dma[j] = 0;
  1661. put_page(ps_page->ps_page[j]);
  1662. ps_page->ps_page[j] = NULL;
  1663. }
  1664. }
  1665. size = sizeof(struct e1000_buffer) * rx_ring->count;
  1666. memset(rx_ring->buffer_info, 0, size);
  1667. size = sizeof(struct e1000_ps_page) * rx_ring->count;
  1668. memset(rx_ring->ps_page, 0, size);
  1669. size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
  1670. memset(rx_ring->ps_page_dma, 0, size);
  1671. /* Zero out the descriptor ring */
  1672. memset(rx_ring->desc, 0, rx_ring->size);
  1673. rx_ring->next_to_clean = 0;
  1674. rx_ring->next_to_use = 0;
  1675. writel(0, adapter->hw.hw_addr + rx_ring->rdh);
  1676. writel(0, adapter->hw.hw_addr + rx_ring->rdt);
  1677. }
  1678. /**
  1679. * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
  1680. * @adapter: board private structure
  1681. **/
  1682. static void
  1683. e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
  1684. {
  1685. int i;
  1686. for (i = 0; i < adapter->num_rx_queues; i++)
  1687. e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
  1688. }
  1689. /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
  1690. * and memory write and invalidate disabled for certain operations
  1691. */
  1692. static void
  1693. e1000_enter_82542_rst(struct e1000_adapter *adapter)
  1694. {
  1695. struct net_device *netdev = adapter->netdev;
  1696. uint32_t rctl;
  1697. e1000_pci_clear_mwi(&adapter->hw);
  1698. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  1699. rctl |= E1000_RCTL_RST;
  1700. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  1701. E1000_WRITE_FLUSH(&adapter->hw);
  1702. mdelay(5);
  1703. if (netif_running(netdev))
  1704. e1000_clean_all_rx_rings(adapter);
  1705. }
  1706. static void
  1707. e1000_leave_82542_rst(struct e1000_adapter *adapter)
  1708. {
  1709. struct net_device *netdev = adapter->netdev;
  1710. uint32_t rctl;
  1711. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  1712. rctl &= ~E1000_RCTL_RST;
  1713. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  1714. E1000_WRITE_FLUSH(&adapter->hw);
  1715. mdelay(5);
  1716. if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
  1717. e1000_pci_set_mwi(&adapter->hw);
  1718. if (netif_running(netdev)) {
  1719. /* No need to loop, because 82542 supports only 1 queue */
  1720. struct e1000_rx_ring *ring = &adapter->rx_ring[0];
  1721. e1000_configure_rx(adapter);
  1722. adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
  1723. }
  1724. }
  1725. /**
  1726. * e1000_set_mac - Change the Ethernet Address of the NIC
  1727. * @netdev: network interface device structure
  1728. * @p: pointer to an address structure
  1729. *
  1730. * Returns 0 on success, negative on failure
  1731. **/
  1732. static int
  1733. e1000_set_mac(struct net_device *netdev, void *p)
  1734. {
  1735. struct e1000_adapter *adapter = netdev_priv(netdev);
  1736. struct sockaddr *addr = p;
  1737. if (!is_valid_ether_addr(addr->sa_data))
  1738. return -EADDRNOTAVAIL;
  1739. /* 82542 2.0 needs to be in reset to write receive address registers */
  1740. if (adapter->hw.mac_type == e1000_82542_rev2_0)
  1741. e1000_enter_82542_rst(adapter);
  1742. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  1743. memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
  1744. e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
  1745. /* With 82571 controllers, LAA may be overwritten (with the default)
  1746. * due to controller reset from the other port. */
  1747. if (adapter->hw.mac_type == e1000_82571) {
  1748. /* activate the work around */
  1749. adapter->hw.laa_is_present = 1;
  1750. /* Hold a copy of the LAA in RAR[14] This is done so that
  1751. * between the time RAR[0] gets clobbered and the time it
  1752. * gets fixed (in e1000_watchdog), the actual LAA is in one
  1753. * of the RARs and no incoming packets directed to this port
  1754. * are dropped. Eventaully the LAA will be in RAR[0] and
  1755. * RAR[14] */
  1756. e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
  1757. E1000_RAR_ENTRIES - 1);
  1758. }
  1759. if (adapter->hw.mac_type == e1000_82542_rev2_0)
  1760. e1000_leave_82542_rst(adapter);
  1761. return 0;
  1762. }
  1763. /**
  1764. * e1000_set_multi - Multicast and Promiscuous mode set
  1765. * @netdev: network interface device structure
  1766. *
  1767. * The set_multi entry point is called whenever the multicast address
  1768. * list or the network interface flags are updated. This routine is
  1769. * responsible for configuring the hardware for proper multicast,
  1770. * promiscuous mode, and all-multi behavior.
  1771. **/
  1772. static void
  1773. e1000_set_multi(struct net_device *netdev)
  1774. {
  1775. struct e1000_adapter *adapter = netdev_priv(netdev);
  1776. struct e1000_hw *hw = &adapter->hw;
  1777. struct dev_mc_list *mc_ptr;
  1778. uint32_t rctl;
  1779. uint32_t hash_value;
  1780. int i, rar_entries = E1000_RAR_ENTRIES;
  1781. /* reserve RAR[14] for LAA over-write work-around */
  1782. if (adapter->hw.mac_type == e1000_82571)
  1783. rar_entries--;
  1784. /* Check for Promiscuous and All Multicast modes */
  1785. rctl = E1000_READ_REG(hw, RCTL);
  1786. if (netdev->flags & IFF_PROMISC) {
  1787. rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
  1788. } else if (netdev->flags & IFF_ALLMULTI) {
  1789. rctl |= E1000_RCTL_MPE;
  1790. rctl &= ~E1000_RCTL_UPE;
  1791. } else {
  1792. rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
  1793. }
  1794. E1000_WRITE_REG(hw, RCTL, rctl);
  1795. /* 82542 2.0 needs to be in reset to write receive address registers */
  1796. if (hw->mac_type == e1000_82542_rev2_0)
  1797. e1000_enter_82542_rst(adapter);
  1798. /* load the first 14 multicast address into the exact filters 1-14
  1799. * RAR 0 is used for the station MAC adddress
  1800. * if there are not 14 addresses, go ahead and clear the filters
  1801. * -- with 82571 controllers only 0-13 entries are filled here
  1802. */
  1803. mc_ptr = netdev->mc_list;
  1804. for (i = 1; i < rar_entries; i++) {
  1805. if (mc_ptr) {
  1806. e1000_rar_set(hw, mc_ptr->dmi_addr, i);
  1807. mc_ptr = mc_ptr->next;
  1808. } else {
  1809. E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
  1810. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
  1811. }
  1812. }
  1813. /* clear the old settings from the multicast hash table */
  1814. for (i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
  1815. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  1816. /* load any remaining addresses into the hash table */
  1817. for (; mc_ptr; mc_ptr = mc_ptr->next) {
  1818. hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
  1819. e1000_mta_set(hw, hash_value);
  1820. }
  1821. if (hw->mac_type == e1000_82542_rev2_0)
  1822. e1000_leave_82542_rst(adapter);
  1823. }
  1824. /* Need to wait a few seconds after link up to get diagnostic information from
  1825. * the phy */
  1826. static void
  1827. e1000_update_phy_info(unsigned long data)
  1828. {
  1829. struct e1000_adapter *adapter = (struct e1000_adapter *) data;
  1830. e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
  1831. }
  1832. /**
  1833. * e1000_82547_tx_fifo_stall - Timer Call-back
  1834. * @data: pointer to adapter cast into an unsigned long
  1835. **/
  1836. static void
  1837. e1000_82547_tx_fifo_stall(unsigned long data)
  1838. {
  1839. struct e1000_adapter *adapter = (struct e1000_adapter *) data;
  1840. struct net_device *netdev = adapter->netdev;
  1841. uint32_t tctl;
  1842. if (atomic_read(&adapter->tx_fifo_stall)) {
  1843. if ((E1000_READ_REG(&adapter->hw, TDT) ==
  1844. E1000_READ_REG(&adapter->hw, TDH)) &&
  1845. (E1000_READ_REG(&adapter->hw, TDFT) ==
  1846. E1000_READ_REG(&adapter->hw, TDFH)) &&
  1847. (E1000_READ_REG(&adapter->hw, TDFTS) ==
  1848. E1000_READ_REG(&adapter->hw, TDFHS))) {
  1849. tctl = E1000_READ_REG(&adapter->hw, TCTL);
  1850. E1000_WRITE_REG(&adapter->hw, TCTL,
  1851. tctl & ~E1000_TCTL_EN);
  1852. E1000_WRITE_REG(&adapter->hw, TDFT,
  1853. adapter->tx_head_addr);
  1854. E1000_WRITE_REG(&adapter->hw, TDFH,
  1855. adapter->tx_head_addr);
  1856. E1000_WRITE_REG(&adapter->hw, TDFTS,
  1857. adapter->tx_head_addr);
  1858. E1000_WRITE_REG(&adapter->hw, TDFHS,
  1859. adapter->tx_head_addr);
  1860. E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
  1861. E1000_WRITE_FLUSH(&adapter->hw);
  1862. adapter->tx_fifo_head = 0;
  1863. atomic_set(&adapter->tx_fifo_stall, 0);
  1864. netif_wake_queue(netdev);
  1865. } else {
  1866. mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
  1867. }
  1868. }
  1869. }
  1870. /**
  1871. * e1000_watchdog - Timer Call-back
  1872. * @data: pointer to adapter cast into an unsigned long
  1873. **/
  1874. static void
  1875. e1000_watchdog(unsigned long data)
  1876. {
  1877. struct e1000_adapter *adapter = (struct e1000_adapter *) data;
  1878. /* Do the rest outside of interrupt context */
  1879. schedule_work(&adapter->watchdog_task);
  1880. }
  1881. static void
  1882. e1000_watchdog_task(struct e1000_adapter *adapter)
  1883. {
  1884. struct net_device *netdev = adapter->netdev;
  1885. struct e1000_tx_ring *txdr = adapter->tx_ring;
  1886. uint32_t link, tctl;
  1887. e1000_check_for_link(&adapter->hw);
  1888. if (adapter->hw.mac_type == e1000_82573) {
  1889. e1000_enable_tx_pkt_filtering(&adapter->hw);
  1890. if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
  1891. e1000_update_mng_vlan(adapter);
  1892. }
  1893. if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
  1894. !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
  1895. link = !adapter->hw.serdes_link_down;
  1896. else
  1897. link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
  1898. if (link) {
  1899. if (!netif_carrier_ok(netdev)) {
  1900. e1000_get_speed_and_duplex(&adapter->hw,
  1901. &adapter->link_speed,
  1902. &adapter->link_duplex);
  1903. DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
  1904. adapter->link_speed,
  1905. adapter->link_duplex == FULL_DUPLEX ?
  1906. "Full Duplex" : "Half Duplex");
  1907. /* tweak tx_queue_len according to speed/duplex
  1908. * and adjust the timeout factor */
  1909. netdev->tx_queue_len = adapter->tx_queue_len;
  1910. adapter->tx_timeout_factor = 1;
  1911. adapter->txb2b = 1;
  1912. switch (adapter->link_speed) {
  1913. case SPEED_10:
  1914. adapter->txb2b = 0;
  1915. netdev->tx_queue_len = 10;
  1916. adapter->tx_timeout_factor = 8;
  1917. break;
  1918. case SPEED_100:
  1919. adapter->txb2b = 0;
  1920. netdev->tx_queue_len = 100;
  1921. /* maybe add some timeout factor ? */
  1922. break;
  1923. }
  1924. if ((adapter->hw.mac_type == e1000_82571 ||
  1925. adapter->hw.mac_type == e1000_82572) &&
  1926. adapter->txb2b == 0) {
  1927. #define SPEED_MODE_BIT (1 << 21)
  1928. uint32_t tarc0;
  1929. tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
  1930. tarc0 &= ~SPEED_MODE_BIT;
  1931. E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
  1932. }
  1933. #ifdef NETIF_F_TSO
  1934. /* disable TSO for pcie and 10/100 speeds, to avoid
  1935. * some hardware issues */
  1936. if (!adapter->tso_force &&
  1937. adapter->hw.bus_type == e1000_bus_type_pci_express){
  1938. switch (adapter->link_speed) {
  1939. case SPEED_10:
  1940. case SPEED_100:
  1941. DPRINTK(PROBE,INFO,
  1942. "10/100 speed: disabling TSO\n");
  1943. netdev->features &= ~NETIF_F_TSO;
  1944. break;
  1945. case SPEED_1000:
  1946. netdev->features |= NETIF_F_TSO;
  1947. break;
  1948. default:
  1949. /* oops */
  1950. break;
  1951. }
  1952. }
  1953. #endif
  1954. /* enable transmits in the hardware, need to do this
  1955. * after setting TARC0 */
  1956. tctl = E1000_READ_REG(&adapter->hw, TCTL);
  1957. tctl |= E1000_TCTL_EN;
  1958. E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
  1959. netif_carrier_on(netdev);
  1960. netif_wake_queue(netdev);
  1961. mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
  1962. adapter->smartspeed = 0;
  1963. }
  1964. } else {
  1965. if (netif_carrier_ok(netdev)) {
  1966. adapter->link_speed = 0;
  1967. adapter->link_duplex = 0;
  1968. DPRINTK(LINK, INFO, "NIC Link is Down\n");
  1969. netif_carrier_off(netdev);
  1970. netif_stop_queue(netdev);
  1971. mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
  1972. /* 80003ES2LAN workaround--
  1973. * For packet buffer work-around on link down event;
  1974. * disable receives in the ISR and
  1975. * reset device here in the watchdog
  1976. */
  1977. if (adapter->hw.mac_type == e1000_80003es2lan) {
  1978. /* reset device */
  1979. schedule_work(&adapter->reset_task);
  1980. }
  1981. }
  1982. e1000_smartspeed(adapter);
  1983. }
  1984. e1000_update_stats(adapter);
  1985. adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
  1986. adapter->tpt_old = adapter->stats.tpt;
  1987. adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
  1988. adapter->colc_old = adapter->stats.colc;
  1989. adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
  1990. adapter->gorcl_old = adapter->stats.gorcl;
  1991. adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
  1992. adapter->gotcl_old = adapter->stats.gotcl;
  1993. e1000_update_adaptive(&adapter->hw);
  1994. if (!netif_carrier_ok(netdev)) {
  1995. if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
  1996. /* We've lost link, so the controller stops DMA,
  1997. * but we've got queued Tx work that's never going
  1998. * to get done, so reset controller to flush Tx.
  1999. * (Do the reset outside of interrupt context). */
  2000. adapter->tx_timeout_count++;
  2001. schedule_work(&adapter->reset_task);
  2002. }
  2003. }
  2004. /* Dynamic mode for Interrupt Throttle Rate (ITR) */
  2005. if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
  2006. /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
  2007. * asymmetrical Tx or Rx gets ITR=8000; everyone
  2008. * else is between 2000-8000. */
  2009. uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
  2010. uint32_t dif = (adapter->gotcl > adapter->gorcl ?
  2011. adapter->gotcl - adapter->gorcl :
  2012. adapter->gorcl - adapter->gotcl) / 10000;
  2013. uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
  2014. E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
  2015. }
  2016. /* Cause software interrupt to ensure rx ring is cleaned */
  2017. E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
  2018. /* Force detection of hung controller every watchdog period */
  2019. adapter->detect_tx_hung = TRUE;
  2020. /* With 82571 controllers, LAA may be overwritten due to controller
  2021. * reset from the other port. Set the appropriate LAA in RAR[0] */
  2022. if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
  2023. e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
  2024. /* Reset the timer */
  2025. mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
  2026. }
  2027. #define E1000_TX_FLAGS_CSUM 0x00000001
  2028. #define E1000_TX_FLAGS_VLAN 0x00000002
  2029. #define E1000_TX_FLAGS_TSO 0x00000004
  2030. #define E1000_TX_FLAGS_IPV4 0x00000008
  2031. #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
  2032. #define E1000_TX_FLAGS_VLAN_SHIFT 16
  2033. static inline int
  2034. e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
  2035. struct sk_buff *skb)
  2036. {
  2037. #ifdef NETIF_F_TSO
  2038. struct e1000_context_desc *context_desc;
  2039. struct e1000_buffer *buffer_info;
  2040. unsigned int i;
  2041. uint32_t cmd_length = 0;
  2042. uint16_t ipcse = 0, tucse, mss;
  2043. uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
  2044. int err;
  2045. if (skb_shinfo(skb)->tso_size) {
  2046. if (skb_header_cloned(skb)) {
  2047. err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  2048. if (err)
  2049. return err;
  2050. }
  2051. hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
  2052. mss = skb_shinfo(skb)->tso_size;
  2053. if (skb->protocol == ntohs(ETH_P_IP)) {
  2054. skb->nh.iph->tot_len = 0;
  2055. skb->nh.iph->check = 0;
  2056. skb->h.th->check =
  2057. ~csum_tcpudp_magic(skb->nh.iph->saddr,
  2058. skb->nh.iph->daddr,
  2059. 0,
  2060. IPPROTO_TCP,
  2061. 0);
  2062. cmd_length = E1000_TXD_CMD_IP;
  2063. ipcse = skb->h.raw - skb->data - 1;
  2064. #ifdef NETIF_F_TSO_IPV6
  2065. } else if (skb->protocol == ntohs(ETH_P_IPV6)) {
  2066. skb->nh.ipv6h->payload_len = 0;
  2067. skb->h.th->check =
  2068. ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
  2069. &skb->nh.ipv6h->daddr,
  2070. 0,
  2071. IPPROTO_TCP,
  2072. 0);
  2073. ipcse = 0;
  2074. #endif
  2075. }
  2076. ipcss = skb->nh.raw - skb->data;
  2077. ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
  2078. tucss = skb->h.raw - skb->data;
  2079. tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
  2080. tucse = 0;
  2081. cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
  2082. E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
  2083. i = tx_ring->next_to_use;
  2084. context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
  2085. buffer_info = &tx_ring->buffer_info[i];
  2086. context_desc->lower_setup.ip_fields.ipcss = ipcss;
  2087. context_desc->lower_setup.ip_fields.ipcso = ipcso;
  2088. context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
  2089. context_desc->upper_setup.tcp_fields.tucss = tucss;
  2090. context_desc->upper_setup.tcp_fields.tucso = tucso;
  2091. context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
  2092. context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
  2093. context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
  2094. context_desc->cmd_and_length = cpu_to_le32(cmd_length);
  2095. buffer_info->time_stamp = jiffies;
  2096. if (++i == tx_ring->count) i = 0;
  2097. tx_ring->next_to_use = i;
  2098. return TRUE;
  2099. }
  2100. #endif
  2101. return FALSE;
  2102. }
  2103. static inline boolean_t
  2104. e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
  2105. struct sk_buff *skb)
  2106. {
  2107. struct e1000_context_desc *context_desc;
  2108. struct e1000_buffer *buffer_info;
  2109. unsigned int i;
  2110. uint8_t css;
  2111. if (likely(skb->ip_summed == CHECKSUM_HW)) {
  2112. css = skb->h.raw - skb->data;
  2113. i = tx_ring->next_to_use;
  2114. buffer_info = &tx_ring->buffer_info[i];
  2115. context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
  2116. context_desc->upper_setup.tcp_fields.tucss = css;
  2117. context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
  2118. context_desc->upper_setup.tcp_fields.tucse = 0;
  2119. context_desc->tcp_seg_setup.data = 0;
  2120. context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
  2121. buffer_info->time_stamp = jiffies;
  2122. if (unlikely(++i == tx_ring->count)) i = 0;
  2123. tx_ring->next_to_use = i;
  2124. return TRUE;
  2125. }
  2126. return FALSE;
  2127. }
  2128. #define E1000_MAX_TXD_PWR 12
  2129. #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
  2130. static inline int
  2131. e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
  2132. struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
  2133. unsigned int nr_frags, unsigned int mss)
  2134. {
  2135. struct e1000_buffer *buffer_info;
  2136. unsigned int len = skb->len;
  2137. unsigned int offset = 0, size, count = 0, i;
  2138. unsigned int f;
  2139. len -= skb->data_len;
  2140. i = tx_ring->next_to_use;
  2141. while (len) {
  2142. buffer_info = &tx_ring->buffer_info[i];
  2143. size = min(len, max_per_txd);
  2144. #ifdef NETIF_F_TSO
  2145. /* Workaround for Controller erratum --
  2146. * descriptor for non-tso packet in a linear SKB that follows a
  2147. * tso gets written back prematurely before the data is fully
  2148. * DMA'd to the controller */
  2149. if (!skb->data_len && tx_ring->last_tx_tso &&
  2150. !skb_shinfo(skb)->tso_size) {
  2151. tx_ring->last_tx_tso = 0;
  2152. size -= 4;
  2153. }
  2154. /* Workaround for premature desc write-backs
  2155. * in TSO mode. Append 4-byte sentinel desc */
  2156. if (unlikely(mss && !nr_frags && size == len && size > 8))
  2157. size -= 4;
  2158. #endif
  2159. /* work-around for errata 10 and it applies
  2160. * to all controllers in PCI-X mode
  2161. * The fix is to make sure that the first descriptor of a
  2162. * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
  2163. */
  2164. if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
  2165. (size > 2015) && count == 0))
  2166. size = 2015;
  2167. /* Workaround for potential 82544 hang in PCI-X. Avoid
  2168. * terminating buffers within evenly-aligned dwords. */
  2169. if (unlikely(adapter->pcix_82544 &&
  2170. !((unsigned long)(skb->data + offset + size - 1) & 4) &&
  2171. size > 4))
  2172. size -= 4;
  2173. buffer_info->length = size;
  2174. buffer_info->dma =
  2175. pci_map_single(adapter->pdev,
  2176. skb->data + offset,
  2177. size,
  2178. PCI_DMA_TODEVICE);
  2179. buffer_info->time_stamp = jiffies;
  2180. len -= size;
  2181. offset += size;
  2182. count++;
  2183. if (unlikely(++i == tx_ring->count)) i = 0;
  2184. }
  2185. for (f = 0; f < nr_frags; f++) {
  2186. struct skb_frag_struct *frag;
  2187. frag = &skb_shinfo(skb)->frags[f];
  2188. len = frag->size;
  2189. offset = frag->page_offset;
  2190. while (len) {
  2191. buffer_info = &tx_ring->buffer_info[i];
  2192. size = min(len, max_per_txd);
  2193. #ifdef NETIF_F_TSO
  2194. /* Workaround for premature desc write-backs
  2195. * in TSO mode. Append 4-byte sentinel desc */
  2196. if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
  2197. size -= 4;
  2198. #endif
  2199. /* Workaround for potential 82544 hang in PCI-X.
  2200. * Avoid terminating buffers within evenly-aligned
  2201. * dwords. */
  2202. if (unlikely(adapter->pcix_82544 &&
  2203. !((unsigned long)(frag->page+offset+size-1) & 4) &&
  2204. size > 4))
  2205. size -= 4;
  2206. buffer_info->length = size;
  2207. buffer_info->dma =
  2208. pci_map_page(adapter->pdev,
  2209. frag->page,
  2210. offset,
  2211. size,
  2212. PCI_DMA_TODEVICE);
  2213. buffer_info->time_stamp = jiffies;
  2214. len -= size;
  2215. offset += size;
  2216. count++;
  2217. if (unlikely(++i == tx_ring->count)) i = 0;
  2218. }
  2219. }
  2220. i = (i == 0) ? tx_ring->count - 1 : i - 1;
  2221. tx_ring->buffer_info[i].skb = skb;
  2222. tx_ring->buffer_info[first].next_to_watch = i;
  2223. return count;
  2224. }
  2225. static inline void
  2226. e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
  2227. int tx_flags, int count)
  2228. {
  2229. struct e1000_tx_desc *tx_desc = NULL;
  2230. struct e1000_buffer *buffer_info;
  2231. uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
  2232. unsigned int i;
  2233. if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
  2234. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
  2235. E1000_TXD_CMD_TSE;
  2236. txd_upper |= E1000_TXD_POPTS_TXSM << 8;
  2237. if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
  2238. txd_upper |= E1000_TXD_POPTS_IXSM << 8;
  2239. }
  2240. if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
  2241. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
  2242. txd_upper |= E1000_TXD_POPTS_TXSM << 8;
  2243. }
  2244. if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
  2245. txd_lower |= E1000_TXD_CMD_VLE;
  2246. txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
  2247. }
  2248. i = tx_ring->next_to_use;
  2249. while (count--) {
  2250. buffer_info = &tx_ring->buffer_info[i];
  2251. tx_desc = E1000_TX_DESC(*tx_ring, i);
  2252. tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
  2253. tx_desc->lower.data =
  2254. cpu_to_le32(txd_lower | buffer_info->length);
  2255. tx_desc->upper.data = cpu_to_le32(txd_upper);
  2256. if (unlikely(++i == tx_ring->count)) i = 0;
  2257. }
  2258. tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
  2259. /* Force memory writes to complete before letting h/w
  2260. * know there are new descriptors to fetch. (Only
  2261. * applicable for weak-ordered memory model archs,
  2262. * such as IA-64). */
  2263. wmb();
  2264. tx_ring->next_to_use = i;
  2265. writel(i, adapter->hw.hw_addr + tx_ring->tdt);
  2266. }
  2267. /**
  2268. * 82547 workaround to avoid controller hang in half-duplex environment.
  2269. * The workaround is to avoid queuing a large packet that would span
  2270. * the internal Tx FIFO ring boundary by notifying the stack to resend
  2271. * the packet at a later time. This gives the Tx FIFO an opportunity to
  2272. * flush all packets. When that occurs, we reset the Tx FIFO pointers
  2273. * to the beginning of the Tx FIFO.
  2274. **/
  2275. #define E1000_FIFO_HDR 0x10
  2276. #define E1000_82547_PAD_LEN 0x3E0
  2277. static inline int
  2278. e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
  2279. {
  2280. uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
  2281. uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
  2282. E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
  2283. if (adapter->link_duplex != HALF_DUPLEX)
  2284. goto no_fifo_stall_required;
  2285. if (atomic_read(&adapter->tx_fifo_stall))
  2286. return 1;
  2287. if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
  2288. atomic_set(&adapter->tx_fifo_stall, 1);
  2289. return 1;
  2290. }
  2291. no_fifo_stall_required:
  2292. adapter->tx_fifo_head += skb_fifo_len;
  2293. if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
  2294. adapter->tx_fifo_head -= adapter->tx_fifo_size;
  2295. return 0;
  2296. }
  2297. #define MINIMUM_DHCP_PACKET_SIZE 282
  2298. static inline int
  2299. e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
  2300. {
  2301. struct e1000_hw *hw = &adapter->hw;
  2302. uint16_t length, offset;
  2303. if (vlan_tx_tag_present(skb)) {
  2304. if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
  2305. ( adapter->hw.mng_cookie.status &
  2306. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
  2307. return 0;
  2308. }
  2309. if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
  2310. struct ethhdr *eth = (struct ethhdr *) skb->data;
  2311. if ((htons(ETH_P_IP) == eth->h_proto)) {
  2312. const struct iphdr *ip =
  2313. (struct iphdr *)((uint8_t *)skb->data+14);
  2314. if (IPPROTO_UDP == ip->protocol) {
  2315. struct udphdr *udp =
  2316. (struct udphdr *)((uint8_t *)ip +
  2317. (ip->ihl << 2));
  2318. if (ntohs(udp->dest) == 67) {
  2319. offset = (uint8_t *)udp + 8 - skb->data;
  2320. length = skb->len - offset;
  2321. return e1000_mng_write_dhcp_info(hw,
  2322. (uint8_t *)udp + 8,
  2323. length);
  2324. }
  2325. }
  2326. }
  2327. }
  2328. return 0;
  2329. }
  2330. #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
  2331. static int
  2332. e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
  2333. {
  2334. struct e1000_adapter *adapter = netdev_priv(netdev);
  2335. struct e1000_tx_ring *tx_ring;
  2336. unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
  2337. unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
  2338. unsigned int tx_flags = 0;
  2339. unsigned int len = skb->len;
  2340. unsigned long flags;
  2341. unsigned int nr_frags = 0;
  2342. unsigned int mss = 0;
  2343. int count = 0;
  2344. int tso;
  2345. unsigned int f;
  2346. len -= skb->data_len;
  2347. tx_ring = adapter->tx_ring;
  2348. if (unlikely(skb->len <= 0)) {
  2349. dev_kfree_skb_any(skb);
  2350. return NETDEV_TX_OK;
  2351. }
  2352. #ifdef NETIF_F_TSO
  2353. mss = skb_shinfo(skb)->tso_size;
  2354. /* The controller does a simple calculation to
  2355. * make sure there is enough room in the FIFO before
  2356. * initiating the DMA for each buffer. The calc is:
  2357. * 4 = ceil(buffer len/mss). To make sure we don't
  2358. * overrun the FIFO, adjust the max buffer len if mss
  2359. * drops. */
  2360. if (mss) {
  2361. uint8_t hdr_len;
  2362. max_per_txd = min(mss << 2, max_per_txd);
  2363. max_txd_pwr = fls(max_per_txd) - 1;
  2364. /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
  2365. * points to just header, pull a few bytes of payload from
  2366. * frags into skb->data */
  2367. hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
  2368. if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
  2369. switch (adapter->hw.mac_type) {
  2370. unsigned int pull_size;
  2371. case e1000_82571:
  2372. case e1000_82572:
  2373. case e1000_82573:
  2374. pull_size = min((unsigned int)4, skb->data_len);
  2375. if (!__pskb_pull_tail(skb, pull_size)) {
  2376. printk(KERN_ERR
  2377. "__pskb_pull_tail failed.\n");
  2378. dev_kfree_skb_any(skb);
  2379. return NETDEV_TX_OK;
  2380. }
  2381. len = skb->len - skb->data_len;
  2382. break;
  2383. default:
  2384. /* do nothing */
  2385. break;
  2386. }
  2387. }
  2388. }
  2389. /* reserve a descriptor for the offload context */
  2390. if ((mss) || (skb->ip_summed == CHECKSUM_HW))
  2391. count++;
  2392. count++;
  2393. #else
  2394. if (skb->ip_summed == CHECKSUM_HW)
  2395. count++;
  2396. #endif
  2397. #ifdef NETIF_F_TSO
  2398. /* Controller Erratum workaround */
  2399. if (!skb->data_len && tx_ring->last_tx_tso &&
  2400. !skb_shinfo(skb)->tso_size)
  2401. count++;
  2402. #endif
  2403. count += TXD_USE_COUNT(len, max_txd_pwr);
  2404. if (adapter->pcix_82544)
  2405. count++;
  2406. /* work-around for errata 10 and it applies to all controllers
  2407. * in PCI-X mode, so add one more descriptor to the count
  2408. */
  2409. if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
  2410. (len > 2015)))
  2411. count++;
  2412. nr_frags = skb_shinfo(skb)->nr_frags;
  2413. for (f = 0; f < nr_frags; f++)
  2414. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
  2415. max_txd_pwr);
  2416. if (adapter->pcix_82544)
  2417. count += nr_frags;
  2418. if (adapter->hw.tx_pkt_filtering &&
  2419. (adapter->hw.mac_type == e1000_82573))
  2420. e1000_transfer_dhcp_info(adapter, skb);
  2421. local_irq_save(flags);
  2422. if (!spin_trylock(&tx_ring->tx_lock)) {
  2423. /* Collision - tell upper layer to requeue */
  2424. local_irq_restore(flags);
  2425. return NETDEV_TX_LOCKED;
  2426. }
  2427. /* need: count + 2 desc gap to keep tail from touching
  2428. * head, otherwise try next time */
  2429. if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
  2430. netif_stop_queue(netdev);
  2431. spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
  2432. return NETDEV_TX_BUSY;
  2433. }
  2434. if (unlikely(adapter->hw.mac_type == e1000_82547)) {
  2435. if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
  2436. netif_stop_queue(netdev);
  2437. mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
  2438. spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
  2439. return NETDEV_TX_BUSY;
  2440. }
  2441. }
  2442. if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
  2443. tx_flags |= E1000_TX_FLAGS_VLAN;
  2444. tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
  2445. }
  2446. first = tx_ring->next_to_use;
  2447. tso = e1000_tso(adapter, tx_ring, skb);
  2448. if (tso < 0) {
  2449. dev_kfree_skb_any(skb);
  2450. spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
  2451. return NETDEV_TX_OK;
  2452. }
  2453. if (likely(tso)) {
  2454. tx_ring->last_tx_tso = 1;
  2455. tx_flags |= E1000_TX_FLAGS_TSO;
  2456. } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
  2457. tx_flags |= E1000_TX_FLAGS_CSUM;
  2458. /* Old method was to assume IPv4 packet by default if TSO was enabled.
  2459. * 82571 hardware supports TSO capabilities for IPv6 as well...
  2460. * no longer assume, we must. */
  2461. if (likely(skb->protocol == ntohs(ETH_P_IP)))
  2462. tx_flags |= E1000_TX_FLAGS_IPV4;
  2463. e1000_tx_queue(adapter, tx_ring, tx_flags,
  2464. e1000_tx_map(adapter, tx_ring, skb, first,
  2465. max_per_txd, nr_frags, mss));
  2466. netdev->trans_start = jiffies;
  2467. /* Make sure there is space in the ring for the next send. */
  2468. if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
  2469. netif_stop_queue(netdev);
  2470. spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
  2471. return NETDEV_TX_OK;
  2472. }
  2473. /**
  2474. * e1000_tx_timeout - Respond to a Tx Hang
  2475. * @netdev: network interface device structure
  2476. **/
  2477. static void
  2478. e1000_tx_timeout(struct net_device *netdev)
  2479. {
  2480. struct e1000_adapter *adapter = netdev_priv(netdev);
  2481. /* Do the reset outside of interrupt context */
  2482. adapter->tx_timeout_count++;
  2483. schedule_work(&adapter->reset_task);
  2484. }
  2485. static void
  2486. e1000_reset_task(struct net_device *netdev)
  2487. {
  2488. struct e1000_adapter *adapter = netdev_priv(netdev);
  2489. e1000_down(adapter);
  2490. e1000_up(adapter);
  2491. }
  2492. /**
  2493. * e1000_get_stats - Get System Network Statistics
  2494. * @netdev: network interface device structure
  2495. *
  2496. * Returns the address of the device statistics structure.
  2497. * The statistics are actually updated from the timer callback.
  2498. **/
  2499. static struct net_device_stats *
  2500. e1000_get_stats(struct net_device *netdev)
  2501. {
  2502. struct e1000_adapter *adapter = netdev_priv(netdev);
  2503. /* only return the current stats */
  2504. return &adapter->net_stats;
  2505. }
  2506. /**
  2507. * e1000_change_mtu - Change the Maximum Transfer Unit
  2508. * @netdev: network interface device structure
  2509. * @new_mtu: new value for maximum frame size
  2510. *
  2511. * Returns 0 on success, negative on failure
  2512. **/
  2513. static int
  2514. e1000_change_mtu(struct net_device *netdev, int new_mtu)
  2515. {
  2516. struct e1000_adapter *adapter = netdev_priv(netdev);
  2517. int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
  2518. uint16_t eeprom_data = 0;
  2519. if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
  2520. (max_frame > MAX_JUMBO_FRAME_SIZE)) {
  2521. DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
  2522. return -EINVAL;
  2523. }
  2524. /* Adapter-specific max frame size limits. */
  2525. switch (adapter->hw.mac_type) {
  2526. case e1000_82542_rev2_0:
  2527. case e1000_82542_rev2_1:
  2528. if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
  2529. DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
  2530. return -EINVAL;
  2531. }
  2532. break;
  2533. case e1000_82573:
  2534. /* only enable jumbo frames if ASPM is disabled completely
  2535. * this means both bits must be zero in 0x1A bits 3:2 */
  2536. e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
  2537. &eeprom_data);
  2538. if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) {
  2539. if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
  2540. DPRINTK(PROBE, ERR,
  2541. "Jumbo Frames not supported.\n");
  2542. return -EINVAL;
  2543. }
  2544. break;
  2545. }
  2546. /* fall through to get support */
  2547. case e1000_82571:
  2548. case e1000_82572:
  2549. case e1000_80003es2lan:
  2550. #define MAX_STD_JUMBO_FRAME_SIZE 9234
  2551. if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
  2552. DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
  2553. return -EINVAL;
  2554. }
  2555. break;
  2556. default:
  2557. /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
  2558. break;
  2559. }
  2560. if (adapter->hw.mac_type > e1000_82547_rev_2) {
  2561. adapter->rx_buffer_len = max_frame;
  2562. E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
  2563. } else {
  2564. if(unlikely((adapter->hw.mac_type < e1000_82543) &&
  2565. (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE))) {
  2566. DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
  2567. "on 82542\n");
  2568. return -EINVAL;
  2569. } else {
  2570. if(max_frame <= E1000_RXBUFFER_2048)
  2571. adapter->rx_buffer_len = E1000_RXBUFFER_2048;
  2572. else if(max_frame <= E1000_RXBUFFER_4096)
  2573. adapter->rx_buffer_len = E1000_RXBUFFER_4096;
  2574. else if(max_frame <= E1000_RXBUFFER_8192)
  2575. adapter->rx_buffer_len = E1000_RXBUFFER_8192;
  2576. else if(max_frame <= E1000_RXBUFFER_16384)
  2577. adapter->rx_buffer_len = E1000_RXBUFFER_16384;
  2578. }
  2579. }
  2580. netdev->mtu = new_mtu;
  2581. if (netif_running(netdev)) {
  2582. e1000_down(adapter);
  2583. e1000_up(adapter);
  2584. }
  2585. adapter->hw.max_frame_size = max_frame;
  2586. return 0;
  2587. }
  2588. /**
  2589. * e1000_update_stats - Update the board statistics counters
  2590. * @adapter: board private structure
  2591. **/
  2592. void
  2593. e1000_update_stats(struct e1000_adapter *adapter)
  2594. {
  2595. struct e1000_hw *hw = &adapter->hw;
  2596. unsigned long flags;
  2597. uint16_t phy_tmp;
  2598. #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
  2599. spin_lock_irqsave(&adapter->stats_lock, flags);
  2600. /* these counters are modified from e1000_adjust_tbi_stats,
  2601. * called from the interrupt context, so they must only
  2602. * be written while holding adapter->stats_lock
  2603. */
  2604. adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
  2605. adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
  2606. adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
  2607. adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
  2608. adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
  2609. adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
  2610. adapter->stats.roc += E1000_READ_REG(hw, ROC);
  2611. adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
  2612. adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
  2613. adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
  2614. adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
  2615. adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
  2616. adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
  2617. adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
  2618. adapter->stats.mpc += E1000_READ_REG(hw, MPC);
  2619. adapter->stats.scc += E1000_READ_REG(hw, SCC);
  2620. adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
  2621. adapter->stats.mcc += E1000_READ_REG(hw, MCC);
  2622. adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
  2623. adapter->stats.dc += E1000_READ_REG(hw, DC);
  2624. adapter->stats.sec += E1000_READ_REG(hw, SEC);
  2625. adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
  2626. adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
  2627. adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
  2628. adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
  2629. adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
  2630. adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
  2631. adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
  2632. adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
  2633. adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
  2634. adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
  2635. adapter->stats.ruc += E1000_READ_REG(hw, RUC);
  2636. adapter->stats.rfc += E1000_READ_REG(hw, RFC);
  2637. adapter->stats.rjc += E1000_READ_REG(hw, RJC);
  2638. adapter->stats.torl += E1000_READ_REG(hw, TORL);
  2639. adapter->stats.torh += E1000_READ_REG(hw, TORH);
  2640. adapter->stats.totl += E1000_READ_REG(hw, TOTL);
  2641. adapter->stats.toth += E1000_READ_REG(hw, TOTH);
  2642. adapter->stats.tpr += E1000_READ_REG(hw, TPR);
  2643. adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
  2644. adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
  2645. adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
  2646. adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
  2647. adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
  2648. adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
  2649. adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
  2650. adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
  2651. /* used for adaptive IFS */
  2652. hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
  2653. adapter->stats.tpt += hw->tx_packet_delta;
  2654. hw->collision_delta = E1000_READ_REG(hw, COLC);
  2655. adapter->stats.colc += hw->collision_delta;
  2656. if (hw->mac_type >= e1000_82543) {
  2657. adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
  2658. adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
  2659. adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
  2660. adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
  2661. adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
  2662. adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
  2663. }
  2664. if (hw->mac_type > e1000_82547_rev_2) {
  2665. adapter->stats.iac += E1000_READ_REG(hw, IAC);
  2666. adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
  2667. adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
  2668. adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
  2669. adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
  2670. adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
  2671. adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
  2672. adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
  2673. adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
  2674. }
  2675. /* Fill out the OS statistics structure */
  2676. adapter->net_stats.rx_packets = adapter->stats.gprc;
  2677. adapter->net_stats.tx_packets = adapter->stats.gptc;
  2678. adapter->net_stats.rx_bytes = adapter->stats.gorcl;
  2679. adapter->net_stats.tx_bytes = adapter->stats.gotcl;
  2680. adapter->net_stats.multicast = adapter->stats.mprc;
  2681. adapter->net_stats.collisions = adapter->stats.colc;
  2682. /* Rx Errors */
  2683. /* RLEC on some newer hardware can be incorrect so build
  2684. * our own version based on RUC and ROC */
  2685. adapter->net_stats.rx_errors = adapter->stats.rxerrc +
  2686. adapter->stats.crcerrs + adapter->stats.algnerrc +
  2687. adapter->stats.ruc + adapter->stats.roc +
  2688. adapter->stats.cexterr;
  2689. adapter->net_stats.rx_dropped = 0;
  2690. adapter->net_stats.rx_length_errors = adapter->stats.ruc +
  2691. adapter->stats.roc;
  2692. adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
  2693. adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
  2694. adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
  2695. /* Tx Errors */
  2696. adapter->net_stats.tx_errors = adapter->stats.ecol +
  2697. adapter->stats.latecol;
  2698. adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
  2699. adapter->net_stats.tx_window_errors = adapter->stats.latecol;
  2700. adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
  2701. /* Tx Dropped needs to be maintained elsewhere */
  2702. /* Phy Stats */
  2703. if (hw->media_type == e1000_media_type_copper) {
  2704. if ((adapter->link_speed == SPEED_1000) &&
  2705. (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
  2706. phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
  2707. adapter->phy_stats.idle_errors += phy_tmp;
  2708. }
  2709. if ((hw->mac_type <= e1000_82546) &&
  2710. (hw->phy_type == e1000_phy_m88) &&
  2711. !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
  2712. adapter->phy_stats.receive_errors += phy_tmp;
  2713. }
  2714. spin_unlock_irqrestore(&adapter->stats_lock, flags);
  2715. }
  2716. /**
  2717. * e1000_intr - Interrupt Handler
  2718. * @irq: interrupt number
  2719. * @data: pointer to a network interface device structure
  2720. * @pt_regs: CPU registers structure
  2721. **/
  2722. static irqreturn_t
  2723. e1000_intr(int irq, void *data, struct pt_regs *regs)
  2724. {
  2725. struct net_device *netdev = data;
  2726. struct e1000_adapter *adapter = netdev_priv(netdev);
  2727. struct e1000_hw *hw = &adapter->hw;
  2728. uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
  2729. #ifndef CONFIG_E1000_NAPI
  2730. int i;
  2731. #else
  2732. /* Interrupt Auto-Mask...upon reading ICR,
  2733. * interrupts are masked. No need for the
  2734. * IMC write, but it does mean we should
  2735. * account for it ASAP. */
  2736. if (likely(hw->mac_type >= e1000_82571))
  2737. atomic_inc(&adapter->irq_sem);
  2738. #endif
  2739. if (unlikely(!icr)) {
  2740. #ifdef CONFIG_E1000_NAPI
  2741. if (hw->mac_type >= e1000_82571)
  2742. e1000_irq_enable(adapter);
  2743. #endif
  2744. return IRQ_NONE; /* Not our interrupt */
  2745. }
  2746. if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
  2747. hw->get_link_status = 1;
  2748. /* 80003ES2LAN workaround--
  2749. * For packet buffer work-around on link down event;
  2750. * disable receives here in the ISR and
  2751. * reset adapter in watchdog
  2752. */
  2753. if (netif_carrier_ok(netdev) &&
  2754. (adapter->hw.mac_type == e1000_80003es2lan)) {
  2755. /* disable receives */
  2756. rctl = E1000_READ_REG(hw, RCTL);
  2757. E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
  2758. }
  2759. mod_timer(&adapter->watchdog_timer, jiffies);
  2760. }
  2761. #ifdef CONFIG_E1000_NAPI
  2762. if (unlikely(hw->mac_type < e1000_82571)) {
  2763. atomic_inc(&adapter->irq_sem);
  2764. E1000_WRITE_REG(hw, IMC, ~0);
  2765. E1000_WRITE_FLUSH(hw);
  2766. }
  2767. if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
  2768. __netif_rx_schedule(&adapter->polling_netdev[0]);
  2769. else
  2770. e1000_irq_enable(adapter);
  2771. #else
  2772. /* Writing IMC and IMS is needed for 82547.
  2773. * Due to Hub Link bus being occupied, an interrupt
  2774. * de-assertion message is not able to be sent.
  2775. * When an interrupt assertion message is generated later,
  2776. * two messages are re-ordered and sent out.
  2777. * That causes APIC to think 82547 is in de-assertion
  2778. * state, while 82547 is in assertion state, resulting
  2779. * in dead lock. Writing IMC forces 82547 into
  2780. * de-assertion state.
  2781. */
  2782. if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
  2783. atomic_inc(&adapter->irq_sem);
  2784. E1000_WRITE_REG(hw, IMC, ~0);
  2785. }
  2786. for (i = 0; i < E1000_MAX_INTR; i++)
  2787. if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
  2788. !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
  2789. break;
  2790. if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
  2791. e1000_irq_enable(adapter);
  2792. #endif
  2793. return IRQ_HANDLED;
  2794. }
  2795. #ifdef CONFIG_E1000_NAPI
  2796. /**
  2797. * e1000_clean - NAPI Rx polling callback
  2798. * @adapter: board private structure
  2799. **/
  2800. static int
  2801. e1000_clean(struct net_device *poll_dev, int *budget)
  2802. {
  2803. struct e1000_adapter *adapter;
  2804. int work_to_do = min(*budget, poll_dev->quota);
  2805. int tx_cleaned = 0, i = 0, work_done = 0;
  2806. /* Must NOT use netdev_priv macro here. */
  2807. adapter = poll_dev->priv;
  2808. /* Keep link state information with original netdev */
  2809. if (!netif_carrier_ok(adapter->netdev))
  2810. goto quit_polling;
  2811. while (poll_dev != &adapter->polling_netdev[i]) {
  2812. i++;
  2813. BUG_ON(i == adapter->num_rx_queues);
  2814. }
  2815. if (likely(adapter->num_tx_queues == 1)) {
  2816. /* e1000_clean is called per-cpu. This lock protects
  2817. * tx_ring[0] from being cleaned by multiple cpus
  2818. * simultaneously. A failure obtaining the lock means
  2819. * tx_ring[0] is currently being cleaned anyway. */
  2820. if (spin_trylock(&adapter->tx_queue_lock)) {
  2821. tx_cleaned = e1000_clean_tx_irq(adapter,
  2822. &adapter->tx_ring[0]);
  2823. spin_unlock(&adapter->tx_queue_lock);
  2824. }
  2825. } else
  2826. tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
  2827. adapter->clean_rx(adapter, &adapter->rx_ring[i],
  2828. &work_done, work_to_do);
  2829. *budget -= work_done;
  2830. poll_dev->quota -= work_done;
  2831. /* If no Tx and not enough Rx work done, exit the polling mode */
  2832. if ((!tx_cleaned && (work_done == 0)) ||
  2833. !netif_running(adapter->netdev)) {
  2834. quit_polling:
  2835. netif_rx_complete(poll_dev);
  2836. e1000_irq_enable(adapter);
  2837. return 0;
  2838. }
  2839. return 1;
  2840. }
  2841. #endif
  2842. /**
  2843. * e1000_clean_tx_irq - Reclaim resources after transmit completes
  2844. * @adapter: board private structure
  2845. **/
  2846. static boolean_t
  2847. e1000_clean_tx_irq(struct e1000_adapter *adapter,
  2848. struct e1000_tx_ring *tx_ring)
  2849. {
  2850. struct net_device *netdev = adapter->netdev;
  2851. struct e1000_tx_desc *tx_desc, *eop_desc;
  2852. struct e1000_buffer *buffer_info;
  2853. unsigned int i, eop;
  2854. #ifdef CONFIG_E1000_NAPI
  2855. unsigned int count = 0;
  2856. #endif
  2857. boolean_t cleaned = FALSE;
  2858. i = tx_ring->next_to_clean;
  2859. eop = tx_ring->buffer_info[i].next_to_watch;
  2860. eop_desc = E1000_TX_DESC(*tx_ring, eop);
  2861. while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
  2862. for (cleaned = FALSE; !cleaned; ) {
  2863. tx_desc = E1000_TX_DESC(*tx_ring, i);
  2864. buffer_info = &tx_ring->buffer_info[i];
  2865. cleaned = (i == eop);
  2866. e1000_unmap_and_free_tx_resource(adapter, buffer_info);
  2867. memset(tx_desc, 0, sizeof(struct e1000_tx_desc));
  2868. if (unlikely(++i == tx_ring->count)) i = 0;
  2869. }
  2870. eop = tx_ring->buffer_info[i].next_to_watch;
  2871. eop_desc = E1000_TX_DESC(*tx_ring, eop);
  2872. #ifdef CONFIG_E1000_NAPI
  2873. #define E1000_TX_WEIGHT 64
  2874. /* weight of a sort for tx, to avoid endless transmit cleanup */
  2875. if (count++ == E1000_TX_WEIGHT) break;
  2876. #endif
  2877. }
  2878. tx_ring->next_to_clean = i;
  2879. spin_lock(&tx_ring->tx_lock);
  2880. if (unlikely(cleaned && netif_queue_stopped(netdev) &&
  2881. netif_carrier_ok(netdev)))
  2882. netif_wake_queue(netdev);
  2883. spin_unlock(&tx_ring->tx_lock);
  2884. if (adapter->detect_tx_hung) {
  2885. /* Detect a transmit hang in hardware, this serializes the
  2886. * check with the clearing of time_stamp and movement of i */
  2887. adapter->detect_tx_hung = FALSE;
  2888. if (tx_ring->buffer_info[eop].dma &&
  2889. time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
  2890. (adapter->tx_timeout_factor * HZ))
  2891. && !(E1000_READ_REG(&adapter->hw, STATUS) &
  2892. E1000_STATUS_TXOFF)) {
  2893. /* detected Tx unit hang */
  2894. DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
  2895. " Tx Queue <%lu>\n"
  2896. " TDH <%x>\n"
  2897. " TDT <%x>\n"
  2898. " next_to_use <%x>\n"
  2899. " next_to_clean <%x>\n"
  2900. "buffer_info[next_to_clean]\n"
  2901. " time_stamp <%lx>\n"
  2902. " next_to_watch <%x>\n"
  2903. " jiffies <%lx>\n"
  2904. " next_to_watch.status <%x>\n",
  2905. (unsigned long)((tx_ring - adapter->tx_ring) /
  2906. sizeof(struct e1000_tx_ring)),
  2907. readl(adapter->hw.hw_addr + tx_ring->tdh),
  2908. readl(adapter->hw.hw_addr + tx_ring->tdt),
  2909. tx_ring->next_to_use,
  2910. tx_ring->next_to_clean,
  2911. tx_ring->buffer_info[eop].time_stamp,
  2912. eop,
  2913. jiffies,
  2914. eop_desc->upper.fields.status);
  2915. netif_stop_queue(netdev);
  2916. }
  2917. }
  2918. return cleaned;
  2919. }
  2920. /**
  2921. * e1000_rx_checksum - Receive Checksum Offload for 82543
  2922. * @adapter: board private structure
  2923. * @status_err: receive descriptor status and error fields
  2924. * @csum: receive descriptor csum field
  2925. * @sk_buff: socket buffer with received data
  2926. **/
  2927. static inline void
  2928. e1000_rx_checksum(struct e1000_adapter *adapter,
  2929. uint32_t status_err, uint32_t csum,
  2930. struct sk_buff *skb)
  2931. {
  2932. uint16_t status = (uint16_t)status_err;
  2933. uint8_t errors = (uint8_t)(status_err >> 24);
  2934. skb->ip_summed = CHECKSUM_NONE;
  2935. /* 82543 or newer only */
  2936. if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
  2937. /* Ignore Checksum bit is set */
  2938. if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
  2939. /* TCP/UDP checksum error bit is set */
  2940. if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
  2941. /* let the stack verify checksum errors */
  2942. adapter->hw_csum_err++;
  2943. return;
  2944. }
  2945. /* TCP/UDP Checksum has not been calculated */
  2946. if (adapter->hw.mac_type <= e1000_82547_rev_2) {
  2947. if (!(status & E1000_RXD_STAT_TCPCS))
  2948. return;
  2949. } else {
  2950. if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
  2951. return;
  2952. }
  2953. /* It must be a TCP or UDP packet with a valid checksum */
  2954. if (likely(status & E1000_RXD_STAT_TCPCS)) {
  2955. /* TCP checksum is good */
  2956. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2957. } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
  2958. /* IP fragment with UDP payload */
  2959. /* Hardware complements the payload checksum, so we undo it
  2960. * and then put the value in host order for further stack use.
  2961. */
  2962. csum = ntohl(csum ^ 0xFFFF);
  2963. skb->csum = csum;
  2964. skb->ip_summed = CHECKSUM_HW;
  2965. }
  2966. adapter->hw_csum_good++;
  2967. }
  2968. /**
  2969. * e1000_clean_rx_irq - Send received data up the network stack; legacy
  2970. * @adapter: board private structure
  2971. **/
  2972. static boolean_t
  2973. #ifdef CONFIG_E1000_NAPI
  2974. e1000_clean_rx_irq(struct e1000_adapter *adapter,
  2975. struct e1000_rx_ring *rx_ring,
  2976. int *work_done, int work_to_do)
  2977. #else
  2978. e1000_clean_rx_irq(struct e1000_adapter *adapter,
  2979. struct e1000_rx_ring *rx_ring)
  2980. #endif
  2981. {
  2982. struct net_device *netdev = adapter->netdev;
  2983. struct pci_dev *pdev = adapter->pdev;
  2984. struct e1000_rx_desc *rx_desc, *next_rxd;
  2985. struct e1000_buffer *buffer_info, *next_buffer;
  2986. unsigned long flags;
  2987. uint32_t length;
  2988. uint8_t last_byte;
  2989. unsigned int i;
  2990. int cleaned_count = 0;
  2991. boolean_t cleaned = FALSE;
  2992. i = rx_ring->next_to_clean;
  2993. rx_desc = E1000_RX_DESC(*rx_ring, i);
  2994. buffer_info = &rx_ring->buffer_info[i];
  2995. while (rx_desc->status & E1000_RXD_STAT_DD) {
  2996. struct sk_buff *skb, *next_skb;
  2997. u8 status;
  2998. #ifdef CONFIG_E1000_NAPI
  2999. if (*work_done >= work_to_do)
  3000. break;
  3001. (*work_done)++;
  3002. #endif
  3003. status = rx_desc->status;
  3004. skb = buffer_info->skb;
  3005. buffer_info->skb = NULL;
  3006. prefetch(skb->data - NET_IP_ALIGN);
  3007. if (++i == rx_ring->count) i = 0;
  3008. next_rxd = E1000_RX_DESC(*rx_ring, i);
  3009. prefetch(next_rxd);
  3010. next_buffer = &rx_ring->buffer_info[i];
  3011. next_skb = next_buffer->skb;
  3012. prefetch(next_skb->data - NET_IP_ALIGN);
  3013. cleaned = TRUE;
  3014. cleaned_count++;
  3015. pci_unmap_single(pdev,
  3016. buffer_info->dma,
  3017. buffer_info->length,
  3018. PCI_DMA_FROMDEVICE);
  3019. length = le16_to_cpu(rx_desc->length);
  3020. if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
  3021. /* All receives must fit into a single buffer */
  3022. E1000_DBG("%s: Receive packet consumed multiple"
  3023. " buffers\n", netdev->name);
  3024. dev_kfree_skb_irq(skb);
  3025. goto next_desc;
  3026. }
  3027. if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
  3028. last_byte = *(skb->data + length - 1);
  3029. if (TBI_ACCEPT(&adapter->hw, status,
  3030. rx_desc->errors, length, last_byte)) {
  3031. spin_lock_irqsave(&adapter->stats_lock, flags);
  3032. e1000_tbi_adjust_stats(&adapter->hw,
  3033. &adapter->stats,
  3034. length, skb->data);
  3035. spin_unlock_irqrestore(&adapter->stats_lock,
  3036. flags);
  3037. length--;
  3038. } else {
  3039. dev_kfree_skb_irq(skb);
  3040. goto next_desc;
  3041. }
  3042. }
  3043. /* code added for copybreak, this should improve
  3044. * performance for small packets with large amounts
  3045. * of reassembly being done in the stack */
  3046. #define E1000_CB_LENGTH 256
  3047. if (length < E1000_CB_LENGTH) {
  3048. struct sk_buff *new_skb =
  3049. dev_alloc_skb(length + NET_IP_ALIGN);
  3050. if (new_skb) {
  3051. skb_reserve(new_skb, NET_IP_ALIGN);
  3052. new_skb->dev = netdev;
  3053. memcpy(new_skb->data - NET_IP_ALIGN,
  3054. skb->data - NET_IP_ALIGN,
  3055. length + NET_IP_ALIGN);
  3056. /* save the skb in buffer_info as good */
  3057. buffer_info->skb = skb;
  3058. skb = new_skb;
  3059. skb_put(skb, length);
  3060. }
  3061. } else
  3062. skb_put(skb, length);
  3063. /* end copybreak code */
  3064. /* Receive Checksum Offload */
  3065. e1000_rx_checksum(adapter,
  3066. (uint32_t)(status) |
  3067. ((uint32_t)(rx_desc->errors) << 24),
  3068. le16_to_cpu(rx_desc->csum), skb);
  3069. skb->protocol = eth_type_trans(skb, netdev);
  3070. #ifdef CONFIG_E1000_NAPI
  3071. if (unlikely(adapter->vlgrp &&
  3072. (status & E1000_RXD_STAT_VP))) {
  3073. vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
  3074. le16_to_cpu(rx_desc->special) &
  3075. E1000_RXD_SPC_VLAN_MASK);
  3076. } else {
  3077. netif_receive_skb(skb);
  3078. }
  3079. #else /* CONFIG_E1000_NAPI */
  3080. if (unlikely(adapter->vlgrp &&
  3081. (status & E1000_RXD_STAT_VP))) {
  3082. vlan_hwaccel_rx(skb, adapter->vlgrp,
  3083. le16_to_cpu(rx_desc->special) &
  3084. E1000_RXD_SPC_VLAN_MASK);
  3085. } else {
  3086. netif_rx(skb);
  3087. }
  3088. #endif /* CONFIG_E1000_NAPI */
  3089. netdev->last_rx = jiffies;
  3090. next_desc:
  3091. rx_desc->status = 0;
  3092. /* return some buffers to hardware, one at a time is too slow */
  3093. if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
  3094. adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
  3095. cleaned_count = 0;
  3096. }
  3097. /* use prefetched values */
  3098. rx_desc = next_rxd;
  3099. buffer_info = next_buffer;
  3100. }
  3101. rx_ring->next_to_clean = i;
  3102. cleaned_count = E1000_DESC_UNUSED(rx_ring);
  3103. if (cleaned_count)
  3104. adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
  3105. return cleaned;
  3106. }
  3107. /**
  3108. * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
  3109. * @adapter: board private structure
  3110. **/
  3111. static boolean_t
  3112. #ifdef CONFIG_E1000_NAPI
  3113. e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
  3114. struct e1000_rx_ring *rx_ring,
  3115. int *work_done, int work_to_do)
  3116. #else
  3117. e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
  3118. struct e1000_rx_ring *rx_ring)
  3119. #endif
  3120. {
  3121. union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
  3122. struct net_device *netdev = adapter->netdev;
  3123. struct pci_dev *pdev = adapter->pdev;
  3124. struct e1000_buffer *buffer_info, *next_buffer;
  3125. struct e1000_ps_page *ps_page;
  3126. struct e1000_ps_page_dma *ps_page_dma;
  3127. struct sk_buff *skb, *next_skb;
  3128. unsigned int i, j;
  3129. uint32_t length, staterr;
  3130. int cleaned_count = 0;
  3131. boolean_t cleaned = FALSE;
  3132. i = rx_ring->next_to_clean;
  3133. rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
  3134. staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
  3135. while (staterr & E1000_RXD_STAT_DD) {
  3136. buffer_info = &rx_ring->buffer_info[i];
  3137. ps_page = &rx_ring->ps_page[i];
  3138. ps_page_dma = &rx_ring->ps_page_dma[i];
  3139. #ifdef CONFIG_E1000_NAPI
  3140. if (unlikely(*work_done >= work_to_do))
  3141. break;
  3142. (*work_done)++;
  3143. #endif
  3144. skb = buffer_info->skb;
  3145. /* in the packet split case this is header only */
  3146. prefetch(skb->data - NET_IP_ALIGN);
  3147. if (++i == rx_ring->count) i = 0;
  3148. next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
  3149. prefetch(next_rxd);
  3150. next_buffer = &rx_ring->buffer_info[i];
  3151. next_skb = next_buffer->skb;
  3152. prefetch(next_skb->data - NET_IP_ALIGN);
  3153. cleaned = TRUE;
  3154. cleaned_count++;
  3155. pci_unmap_single(pdev, buffer_info->dma,
  3156. buffer_info->length,
  3157. PCI_DMA_FROMDEVICE);
  3158. if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
  3159. E1000_DBG("%s: Packet Split buffers didn't pick up"
  3160. " the full packet\n", netdev->name);
  3161. dev_kfree_skb_irq(skb);
  3162. goto next_desc;
  3163. }
  3164. if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
  3165. dev_kfree_skb_irq(skb);
  3166. goto next_desc;
  3167. }
  3168. length = le16_to_cpu(rx_desc->wb.middle.length0);
  3169. if (unlikely(!length)) {
  3170. E1000_DBG("%s: Last part of the packet spanning"
  3171. " multiple descriptors\n", netdev->name);
  3172. dev_kfree_skb_irq(skb);
  3173. goto next_desc;
  3174. }
  3175. /* Good Receive */
  3176. skb_put(skb, length);
  3177. {
  3178. /* this looks ugly, but it seems compiler issues make it
  3179. more efficient than reusing j */
  3180. int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
  3181. /* page alloc/put takes too long and effects small packet
  3182. * throughput, so unsplit small packets and save the alloc/put*/
  3183. if (l1 && ((length + l1) < E1000_CB_LENGTH)) {
  3184. u8 *vaddr;
  3185. /* there is no documentation about how to call
  3186. * kmap_atomic, so we can't hold the mapping
  3187. * very long */
  3188. pci_dma_sync_single_for_cpu(pdev,
  3189. ps_page_dma->ps_page_dma[0],
  3190. PAGE_SIZE,
  3191. PCI_DMA_FROMDEVICE);
  3192. vaddr = kmap_atomic(ps_page->ps_page[0],
  3193. KM_SKB_DATA_SOFTIRQ);
  3194. memcpy(skb->tail, vaddr, l1);
  3195. kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
  3196. pci_dma_sync_single_for_device(pdev,
  3197. ps_page_dma->ps_page_dma[0],
  3198. PAGE_SIZE, PCI_DMA_FROMDEVICE);
  3199. skb_put(skb, l1);
  3200. length += l1;
  3201. goto copydone;
  3202. } /* if */
  3203. }
  3204. for (j = 0; j < adapter->rx_ps_pages; j++) {
  3205. if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
  3206. break;
  3207. pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
  3208. PAGE_SIZE, PCI_DMA_FROMDEVICE);
  3209. ps_page_dma->ps_page_dma[j] = 0;
  3210. skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
  3211. length);
  3212. ps_page->ps_page[j] = NULL;
  3213. skb->len += length;
  3214. skb->data_len += length;
  3215. }
  3216. copydone:
  3217. e1000_rx_checksum(adapter, staterr,
  3218. le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
  3219. skb->protocol = eth_type_trans(skb, netdev);
  3220. if (likely(rx_desc->wb.upper.header_status &
  3221. cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
  3222. adapter->rx_hdr_split++;
  3223. #ifdef CONFIG_E1000_NAPI
  3224. if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
  3225. vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
  3226. le16_to_cpu(rx_desc->wb.middle.vlan) &
  3227. E1000_RXD_SPC_VLAN_MASK);
  3228. } else {
  3229. netif_receive_skb(skb);
  3230. }
  3231. #else /* CONFIG_E1000_NAPI */
  3232. if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
  3233. vlan_hwaccel_rx(skb, adapter->vlgrp,
  3234. le16_to_cpu(rx_desc->wb.middle.vlan) &
  3235. E1000_RXD_SPC_VLAN_MASK);
  3236. } else {
  3237. netif_rx(skb);
  3238. }
  3239. #endif /* CONFIG_E1000_NAPI */
  3240. netdev->last_rx = jiffies;
  3241. next_desc:
  3242. rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
  3243. buffer_info->skb = NULL;
  3244. /* return some buffers to hardware, one at a time is too slow */
  3245. if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
  3246. adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
  3247. cleaned_count = 0;
  3248. }
  3249. /* use prefetched values */
  3250. rx_desc = next_rxd;
  3251. buffer_info = next_buffer;
  3252. staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
  3253. }
  3254. rx_ring->next_to_clean = i;
  3255. cleaned_count = E1000_DESC_UNUSED(rx_ring);
  3256. if (cleaned_count)
  3257. adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
  3258. return cleaned;
  3259. }
  3260. /**
  3261. * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
  3262. * @adapter: address of board private structure
  3263. **/
  3264. static void
  3265. e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
  3266. struct e1000_rx_ring *rx_ring,
  3267. int cleaned_count)
  3268. {
  3269. struct net_device *netdev = adapter->netdev;
  3270. struct pci_dev *pdev = adapter->pdev;
  3271. struct e1000_rx_desc *rx_desc;
  3272. struct e1000_buffer *buffer_info;
  3273. struct sk_buff *skb;
  3274. unsigned int i;
  3275. unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
  3276. i = rx_ring->next_to_use;
  3277. buffer_info = &rx_ring->buffer_info[i];
  3278. while (cleaned_count--) {
  3279. if (!(skb = buffer_info->skb))
  3280. skb = dev_alloc_skb(bufsz);
  3281. else {
  3282. skb_trim(skb, 0);
  3283. goto map_skb;
  3284. }
  3285. if (unlikely(!skb)) {
  3286. /* Better luck next round */
  3287. adapter->alloc_rx_buff_failed++;
  3288. break;
  3289. }
  3290. /* Fix for errata 23, can't cross 64kB boundary */
  3291. if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
  3292. struct sk_buff *oldskb = skb;
  3293. DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
  3294. "at %p\n", bufsz, skb->data);
  3295. /* Try again, without freeing the previous */
  3296. skb = dev_alloc_skb(bufsz);
  3297. /* Failed allocation, critical failure */
  3298. if (!skb) {
  3299. dev_kfree_skb(oldskb);
  3300. break;
  3301. }
  3302. if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
  3303. /* give up */
  3304. dev_kfree_skb(skb);
  3305. dev_kfree_skb(oldskb);
  3306. break; /* while !buffer_info->skb */
  3307. } else {
  3308. /* Use new allocation */
  3309. dev_kfree_skb(oldskb);
  3310. }
  3311. }
  3312. /* Make buffer alignment 2 beyond a 16 byte boundary
  3313. * this will result in a 16 byte aligned IP header after
  3314. * the 14 byte MAC header is removed
  3315. */
  3316. skb_reserve(skb, NET_IP_ALIGN);
  3317. skb->dev = netdev;
  3318. buffer_info->skb = skb;
  3319. buffer_info->length = adapter->rx_buffer_len;
  3320. map_skb:
  3321. buffer_info->dma = pci_map_single(pdev,
  3322. skb->data,
  3323. adapter->rx_buffer_len,
  3324. PCI_DMA_FROMDEVICE);
  3325. /* Fix for errata 23, can't cross 64kB boundary */
  3326. if (!e1000_check_64k_bound(adapter,
  3327. (void *)(unsigned long)buffer_info->dma,
  3328. adapter->rx_buffer_len)) {
  3329. DPRINTK(RX_ERR, ERR,
  3330. "dma align check failed: %u bytes at %p\n",
  3331. adapter->rx_buffer_len,
  3332. (void *)(unsigned long)buffer_info->dma);
  3333. dev_kfree_skb(skb);
  3334. buffer_info->skb = NULL;
  3335. pci_unmap_single(pdev, buffer_info->dma,
  3336. adapter->rx_buffer_len,
  3337. PCI_DMA_FROMDEVICE);
  3338. break; /* while !buffer_info->skb */
  3339. }
  3340. rx_desc = E1000_RX_DESC(*rx_ring, i);
  3341. rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
  3342. if (unlikely(++i == rx_ring->count))
  3343. i = 0;
  3344. buffer_info = &rx_ring->buffer_info[i];
  3345. }
  3346. if (likely(rx_ring->next_to_use != i)) {
  3347. rx_ring->next_to_use = i;
  3348. if (unlikely(i-- == 0))
  3349. i = (rx_ring->count - 1);
  3350. /* Force memory writes to complete before letting h/w
  3351. * know there are new descriptors to fetch. (Only
  3352. * applicable for weak-ordered memory model archs,
  3353. * such as IA-64). */
  3354. wmb();
  3355. writel(i, adapter->hw.hw_addr + rx_ring->rdt);
  3356. }
  3357. }
  3358. /**
  3359. * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
  3360. * @adapter: address of board private structure
  3361. **/
  3362. static void
  3363. e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
  3364. struct e1000_rx_ring *rx_ring,
  3365. int cleaned_count)
  3366. {
  3367. struct net_device *netdev = adapter->netdev;
  3368. struct pci_dev *pdev = adapter->pdev;
  3369. union e1000_rx_desc_packet_split *rx_desc;
  3370. struct e1000_buffer *buffer_info;
  3371. struct e1000_ps_page *ps_page;
  3372. struct e1000_ps_page_dma *ps_page_dma;
  3373. struct sk_buff *skb;
  3374. unsigned int i, j;
  3375. i = rx_ring->next_to_use;
  3376. buffer_info = &rx_ring->buffer_info[i];
  3377. ps_page = &rx_ring->ps_page[i];
  3378. ps_page_dma = &rx_ring->ps_page_dma[i];
  3379. while (cleaned_count--) {
  3380. rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
  3381. for (j = 0; j < PS_PAGE_BUFFERS; j++) {
  3382. if (j < adapter->rx_ps_pages) {
  3383. if (likely(!ps_page->ps_page[j])) {
  3384. ps_page->ps_page[j] =
  3385. alloc_page(GFP_ATOMIC);
  3386. if (unlikely(!ps_page->ps_page[j])) {
  3387. adapter->alloc_rx_buff_failed++;
  3388. goto no_buffers;
  3389. }
  3390. ps_page_dma->ps_page_dma[j] =
  3391. pci_map_page(pdev,
  3392. ps_page->ps_page[j],
  3393. 0, PAGE_SIZE,
  3394. PCI_DMA_FROMDEVICE);
  3395. }
  3396. /* Refresh the desc even if buffer_addrs didn't
  3397. * change because each write-back erases
  3398. * this info.
  3399. */
  3400. rx_desc->read.buffer_addr[j+1] =
  3401. cpu_to_le64(ps_page_dma->ps_page_dma[j]);
  3402. } else
  3403. rx_desc->read.buffer_addr[j+1] = ~0;
  3404. }
  3405. skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
  3406. if (unlikely(!skb)) {
  3407. adapter->alloc_rx_buff_failed++;
  3408. break;
  3409. }
  3410. /* Make buffer alignment 2 beyond a 16 byte boundary
  3411. * this will result in a 16 byte aligned IP header after
  3412. * the 14 byte MAC header is removed
  3413. */
  3414. skb_reserve(skb, NET_IP_ALIGN);
  3415. skb->dev = netdev;
  3416. buffer_info->skb = skb;
  3417. buffer_info->length = adapter->rx_ps_bsize0;
  3418. buffer_info->dma = pci_map_single(pdev, skb->data,
  3419. adapter->rx_ps_bsize0,
  3420. PCI_DMA_FROMDEVICE);
  3421. rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
  3422. if (unlikely(++i == rx_ring->count)) i = 0;
  3423. buffer_info = &rx_ring->buffer_info[i];
  3424. ps_page = &rx_ring->ps_page[i];
  3425. ps_page_dma = &rx_ring->ps_page_dma[i];
  3426. }
  3427. no_buffers:
  3428. if (likely(rx_ring->next_to_use != i)) {
  3429. rx_ring->next_to_use = i;
  3430. if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
  3431. /* Force memory writes to complete before letting h/w
  3432. * know there are new descriptors to fetch. (Only
  3433. * applicable for weak-ordered memory model archs,
  3434. * such as IA-64). */
  3435. wmb();
  3436. /* Hardware increments by 16 bytes, but packet split
  3437. * descriptors are 32 bytes...so we increment tail
  3438. * twice as much.
  3439. */
  3440. writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
  3441. }
  3442. }
  3443. /**
  3444. * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
  3445. * @adapter:
  3446. **/
  3447. static void
  3448. e1000_smartspeed(struct e1000_adapter *adapter)
  3449. {
  3450. uint16_t phy_status;
  3451. uint16_t phy_ctrl;
  3452. if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
  3453. !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
  3454. return;
  3455. if (adapter->smartspeed == 0) {
  3456. /* If Master/Slave config fault is asserted twice,
  3457. * we assume back-to-back */
  3458. e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
  3459. if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
  3460. e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
  3461. if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
  3462. e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
  3463. if (phy_ctrl & CR_1000T_MS_ENABLE) {
  3464. phy_ctrl &= ~CR_1000T_MS_ENABLE;
  3465. e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
  3466. phy_ctrl);
  3467. adapter->smartspeed++;
  3468. if (!e1000_phy_setup_autoneg(&adapter->hw) &&
  3469. !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
  3470. &phy_ctrl)) {
  3471. phy_ctrl |= (MII_CR_AUTO_NEG_EN |
  3472. MII_CR_RESTART_AUTO_NEG);
  3473. e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
  3474. phy_ctrl);
  3475. }
  3476. }
  3477. return;
  3478. } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
  3479. /* If still no link, perhaps using 2/3 pair cable */
  3480. e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
  3481. phy_ctrl |= CR_1000T_MS_ENABLE;
  3482. e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
  3483. if (!e1000_phy_setup_autoneg(&adapter->hw) &&
  3484. !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
  3485. phy_ctrl |= (MII_CR_AUTO_NEG_EN |
  3486. MII_CR_RESTART_AUTO_NEG);
  3487. e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
  3488. }
  3489. }
  3490. /* Restart process after E1000_SMARTSPEED_MAX iterations */
  3491. if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
  3492. adapter->smartspeed = 0;
  3493. }
  3494. /**
  3495. * e1000_ioctl -
  3496. * @netdev:
  3497. * @ifreq:
  3498. * @cmd:
  3499. **/
  3500. static int
  3501. e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  3502. {
  3503. switch (cmd) {
  3504. case SIOCGMIIPHY:
  3505. case SIOCGMIIREG:
  3506. case SIOCSMIIREG:
  3507. return e1000_mii_ioctl(netdev, ifr, cmd);
  3508. default:
  3509. return -EOPNOTSUPP;
  3510. }
  3511. }
  3512. /**
  3513. * e1000_mii_ioctl -
  3514. * @netdev:
  3515. * @ifreq:
  3516. * @cmd:
  3517. **/
  3518. static int
  3519. e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  3520. {
  3521. struct e1000_adapter *adapter = netdev_priv(netdev);
  3522. struct mii_ioctl_data *data = if_mii(ifr);
  3523. int retval;
  3524. uint16_t mii_reg;
  3525. uint16_t spddplx;
  3526. unsigned long flags;
  3527. if (adapter->hw.media_type != e1000_media_type_copper)
  3528. return -EOPNOTSUPP;
  3529. switch (cmd) {
  3530. case SIOCGMIIPHY:
  3531. data->phy_id = adapter->hw.phy_addr;
  3532. break;
  3533. case SIOCGMIIREG:
  3534. if (!capable(CAP_NET_ADMIN))
  3535. return -EPERM;
  3536. spin_lock_irqsave(&adapter->stats_lock, flags);
  3537. if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
  3538. &data->val_out)) {
  3539. spin_unlock_irqrestore(&adapter->stats_lock, flags);
  3540. return -EIO;
  3541. }
  3542. spin_unlock_irqrestore(&adapter->stats_lock, flags);
  3543. break;
  3544. case SIOCSMIIREG:
  3545. if (!capable(CAP_NET_ADMIN))
  3546. return -EPERM;
  3547. if (data->reg_num & ~(0x1F))
  3548. return -EFAULT;
  3549. mii_reg = data->val_in;
  3550. spin_lock_irqsave(&adapter->stats_lock, flags);
  3551. if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
  3552. mii_reg)) {
  3553. spin_unlock_irqrestore(&adapter->stats_lock, flags);
  3554. return -EIO;
  3555. }
  3556. if (adapter->hw.phy_type == e1000_media_type_copper) {
  3557. switch (data->reg_num) {
  3558. case PHY_CTRL:
  3559. if (mii_reg & MII_CR_POWER_DOWN)
  3560. break;
  3561. if (mii_reg & MII_CR_AUTO_NEG_EN) {
  3562. adapter->hw.autoneg = 1;
  3563. adapter->hw.autoneg_advertised = 0x2F;
  3564. } else {
  3565. if (mii_reg & 0x40)
  3566. spddplx = SPEED_1000;
  3567. else if (mii_reg & 0x2000)
  3568. spddplx = SPEED_100;
  3569. else
  3570. spddplx = SPEED_10;
  3571. spddplx += (mii_reg & 0x100)
  3572. ? DUPLEX_FULL :
  3573. DUPLEX_HALF;
  3574. retval = e1000_set_spd_dplx(adapter,
  3575. spddplx);
  3576. if (retval) {
  3577. spin_unlock_irqrestore(
  3578. &adapter->stats_lock,
  3579. flags);
  3580. return retval;
  3581. }
  3582. }
  3583. if (netif_running(adapter->netdev)) {
  3584. e1000_down(adapter);
  3585. e1000_up(adapter);
  3586. } else
  3587. e1000_reset(adapter);
  3588. break;
  3589. case M88E1000_PHY_SPEC_CTRL:
  3590. case M88E1000_EXT_PHY_SPEC_CTRL:
  3591. if (e1000_phy_reset(&adapter->hw)) {
  3592. spin_unlock_irqrestore(
  3593. &adapter->stats_lock, flags);
  3594. return -EIO;
  3595. }
  3596. break;
  3597. }
  3598. } else {
  3599. switch (data->reg_num) {
  3600. case PHY_CTRL:
  3601. if (mii_reg & MII_CR_POWER_DOWN)
  3602. break;
  3603. if (netif_running(adapter->netdev)) {
  3604. e1000_down(adapter);
  3605. e1000_up(adapter);
  3606. } else
  3607. e1000_reset(adapter);
  3608. break;
  3609. }
  3610. }
  3611. spin_unlock_irqrestore(&adapter->stats_lock, flags);
  3612. break;
  3613. default:
  3614. return -EOPNOTSUPP;
  3615. }
  3616. return E1000_SUCCESS;
  3617. }
  3618. void
  3619. e1000_pci_set_mwi(struct e1000_hw *hw)
  3620. {
  3621. struct e1000_adapter *adapter = hw->back;
  3622. int ret_val = pci_set_mwi(adapter->pdev);
  3623. if (ret_val)
  3624. DPRINTK(PROBE, ERR, "Error in setting MWI\n");
  3625. }
  3626. void
  3627. e1000_pci_clear_mwi(struct e1000_hw *hw)
  3628. {
  3629. struct e1000_adapter *adapter = hw->back;
  3630. pci_clear_mwi(adapter->pdev);
  3631. }
  3632. void
  3633. e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
  3634. {
  3635. struct e1000_adapter *adapter = hw->back;
  3636. pci_read_config_word(adapter->pdev, reg, value);
  3637. }
  3638. void
  3639. e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
  3640. {
  3641. struct e1000_adapter *adapter = hw->back;
  3642. pci_write_config_word(adapter->pdev, reg, *value);
  3643. }
  3644. uint32_t
  3645. e1000_io_read(struct e1000_hw *hw, unsigned long port)
  3646. {
  3647. return inl(port);
  3648. }
  3649. void
  3650. e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
  3651. {
  3652. outl(value, port);
  3653. }
  3654. static void
  3655. e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
  3656. {
  3657. struct e1000_adapter *adapter = netdev_priv(netdev);
  3658. uint32_t ctrl, rctl;
  3659. e1000_irq_disable(adapter);
  3660. adapter->vlgrp = grp;
  3661. if (grp) {
  3662. /* enable VLAN tag insert/strip */
  3663. ctrl = E1000_READ_REG(&adapter->hw, CTRL);
  3664. ctrl |= E1000_CTRL_VME;
  3665. E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
  3666. /* enable VLAN receive filtering */
  3667. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  3668. rctl |= E1000_RCTL_VFE;
  3669. rctl &= ~E1000_RCTL_CFIEN;
  3670. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  3671. e1000_update_mng_vlan(adapter);
  3672. } else {
  3673. /* disable VLAN tag insert/strip */
  3674. ctrl = E1000_READ_REG(&adapter->hw, CTRL);
  3675. ctrl &= ~E1000_CTRL_VME;
  3676. E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
  3677. /* disable VLAN filtering */
  3678. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  3679. rctl &= ~E1000_RCTL_VFE;
  3680. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  3681. if (adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
  3682. e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
  3683. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  3684. }
  3685. }
  3686. e1000_irq_enable(adapter);
  3687. }
  3688. static void
  3689. e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
  3690. {
  3691. struct e1000_adapter *adapter = netdev_priv(netdev);
  3692. uint32_t vfta, index;
  3693. if ((adapter->hw.mng_cookie.status &
  3694. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
  3695. (vid == adapter->mng_vlan_id))
  3696. return;
  3697. /* add VID to filter table */
  3698. index = (vid >> 5) & 0x7F;
  3699. vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
  3700. vfta |= (1 << (vid & 0x1F));
  3701. e1000_write_vfta(&adapter->hw, index, vfta);
  3702. }
  3703. static void
  3704. e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
  3705. {
  3706. struct e1000_adapter *adapter = netdev_priv(netdev);
  3707. uint32_t vfta, index;
  3708. e1000_irq_disable(adapter);
  3709. if (adapter->vlgrp)
  3710. adapter->vlgrp->vlan_devices[vid] = NULL;
  3711. e1000_irq_enable(adapter);
  3712. if ((adapter->hw.mng_cookie.status &
  3713. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
  3714. (vid == adapter->mng_vlan_id)) {
  3715. /* release control to f/w */
  3716. e1000_release_hw_control(adapter);
  3717. return;
  3718. }
  3719. /* remove VID from filter table */
  3720. index = (vid >> 5) & 0x7F;
  3721. vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
  3722. vfta &= ~(1 << (vid & 0x1F));
  3723. e1000_write_vfta(&adapter->hw, index, vfta);
  3724. }
  3725. static void
  3726. e1000_restore_vlan(struct e1000_adapter *adapter)
  3727. {
  3728. e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
  3729. if (adapter->vlgrp) {
  3730. uint16_t vid;
  3731. for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
  3732. if (!adapter->vlgrp->vlan_devices[vid])
  3733. continue;
  3734. e1000_vlan_rx_add_vid(adapter->netdev, vid);
  3735. }
  3736. }
  3737. }
  3738. int
  3739. e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
  3740. {
  3741. adapter->hw.autoneg = 0;
  3742. /* Fiber NICs only allow 1000 gbps Full duplex */
  3743. if ((adapter->hw.media_type == e1000_media_type_fiber) &&
  3744. spddplx != (SPEED_1000 + DUPLEX_FULL)) {
  3745. DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
  3746. return -EINVAL;
  3747. }
  3748. switch (spddplx) {
  3749. case SPEED_10 + DUPLEX_HALF:
  3750. adapter->hw.forced_speed_duplex = e1000_10_half;
  3751. break;
  3752. case SPEED_10 + DUPLEX_FULL:
  3753. adapter->hw.forced_speed_duplex = e1000_10_full;
  3754. break;
  3755. case SPEED_100 + DUPLEX_HALF:
  3756. adapter->hw.forced_speed_duplex = e1000_100_half;
  3757. break;
  3758. case SPEED_100 + DUPLEX_FULL:
  3759. adapter->hw.forced_speed_duplex = e1000_100_full;
  3760. break;
  3761. case SPEED_1000 + DUPLEX_FULL:
  3762. adapter->hw.autoneg = 1;
  3763. adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
  3764. break;
  3765. case SPEED_1000 + DUPLEX_HALF: /* not supported */
  3766. default:
  3767. DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
  3768. return -EINVAL;
  3769. }
  3770. return 0;
  3771. }
  3772. #ifdef CONFIG_PM
  3773. /* Save/restore 16 or 64 dwords of PCI config space depending on which
  3774. * bus we're on (PCI(X) vs. PCI-E)
  3775. */
  3776. #define PCIE_CONFIG_SPACE_LEN 256
  3777. #define PCI_CONFIG_SPACE_LEN 64
  3778. static int
  3779. e1000_pci_save_state(struct e1000_adapter *adapter)
  3780. {
  3781. struct pci_dev *dev = adapter->pdev;
  3782. int size;
  3783. int i;
  3784. if (adapter->hw.mac_type >= e1000_82571)
  3785. size = PCIE_CONFIG_SPACE_LEN;
  3786. else
  3787. size = PCI_CONFIG_SPACE_LEN;
  3788. WARN_ON(adapter->config_space != NULL);
  3789. adapter->config_space = kmalloc(size, GFP_KERNEL);
  3790. if (!adapter->config_space) {
  3791. DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
  3792. return -ENOMEM;
  3793. }
  3794. for (i = 0; i < (size / 4); i++)
  3795. pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
  3796. return 0;
  3797. }
  3798. static void
  3799. e1000_pci_restore_state(struct e1000_adapter *adapter)
  3800. {
  3801. struct pci_dev *dev = adapter->pdev;
  3802. int size;
  3803. int i;
  3804. if (adapter->config_space == NULL)
  3805. return;
  3806. if (adapter->hw.mac_type >= e1000_82571)
  3807. size = PCIE_CONFIG_SPACE_LEN;
  3808. else
  3809. size = PCI_CONFIG_SPACE_LEN;
  3810. for (i = 0; i < (size / 4); i++)
  3811. pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
  3812. kfree(adapter->config_space);
  3813. adapter->config_space = NULL;
  3814. return;
  3815. }
  3816. #endif /* CONFIG_PM */
  3817. static int
  3818. e1000_suspend(struct pci_dev *pdev, pm_message_t state)
  3819. {
  3820. struct net_device *netdev = pci_get_drvdata(pdev);
  3821. struct e1000_adapter *adapter = netdev_priv(netdev);
  3822. uint32_t ctrl, ctrl_ext, rctl, manc, status;
  3823. uint32_t wufc = adapter->wol;
  3824. int retval = 0;
  3825. netif_device_detach(netdev);
  3826. if (netif_running(netdev))
  3827. e1000_down(adapter);
  3828. #ifdef CONFIG_PM
  3829. /* Implement our own version of pci_save_state(pdev) because pci-
  3830. * express adapters have 256-byte config spaces. */
  3831. retval = e1000_pci_save_state(adapter);
  3832. if (retval)
  3833. return retval;
  3834. #endif
  3835. status = E1000_READ_REG(&adapter->hw, STATUS);
  3836. if (status & E1000_STATUS_LU)
  3837. wufc &= ~E1000_WUFC_LNKC;
  3838. if (wufc) {
  3839. e1000_setup_rctl(adapter);
  3840. e1000_set_multi(netdev);
  3841. /* turn on all-multi mode if wake on multicast is enabled */
  3842. if (adapter->wol & E1000_WUFC_MC) {
  3843. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  3844. rctl |= E1000_RCTL_MPE;
  3845. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  3846. }
  3847. if (adapter->hw.mac_type >= e1000_82540) {
  3848. ctrl = E1000_READ_REG(&adapter->hw, CTRL);
  3849. /* advertise wake from D3Cold */
  3850. #define E1000_CTRL_ADVD3WUC 0x00100000
  3851. /* phy power management enable */
  3852. #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
  3853. ctrl |= E1000_CTRL_ADVD3WUC |
  3854. E1000_CTRL_EN_PHY_PWR_MGMT;
  3855. E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
  3856. }
  3857. if (adapter->hw.media_type == e1000_media_type_fiber ||
  3858. adapter->hw.media_type == e1000_media_type_internal_serdes) {
  3859. /* keep the laser running in D3 */
  3860. ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
  3861. ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
  3862. E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
  3863. }
  3864. /* Allow time for pending master requests to run */
  3865. e1000_disable_pciex_master(&adapter->hw);
  3866. E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
  3867. E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
  3868. pci_enable_wake(pdev, PCI_D3hot, 1);
  3869. pci_enable_wake(pdev, PCI_D3cold, 1);
  3870. } else {
  3871. E1000_WRITE_REG(&adapter->hw, WUC, 0);
  3872. E1000_WRITE_REG(&adapter->hw, WUFC, 0);
  3873. pci_enable_wake(pdev, PCI_D3hot, 0);
  3874. pci_enable_wake(pdev, PCI_D3cold, 0);
  3875. }
  3876. if (adapter->hw.mac_type >= e1000_82540 &&
  3877. adapter->hw.media_type == e1000_media_type_copper) {
  3878. manc = E1000_READ_REG(&adapter->hw, MANC);
  3879. if (manc & E1000_MANC_SMBUS_EN) {
  3880. manc |= E1000_MANC_ARP_EN;
  3881. E1000_WRITE_REG(&adapter->hw, MANC, manc);
  3882. pci_enable_wake(pdev, PCI_D3hot, 1);
  3883. pci_enable_wake(pdev, PCI_D3cold, 1);
  3884. }
  3885. }
  3886. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  3887. * would have already happened in close and is redundant. */
  3888. e1000_release_hw_control(adapter);
  3889. pci_disable_device(pdev);
  3890. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  3891. return 0;
  3892. }
  3893. #ifdef CONFIG_PM
  3894. static int
  3895. e1000_resume(struct pci_dev *pdev)
  3896. {
  3897. struct net_device *netdev = pci_get_drvdata(pdev);
  3898. struct e1000_adapter *adapter = netdev_priv(netdev);
  3899. uint32_t manc, ret_val;
  3900. pci_set_power_state(pdev, PCI_D0);
  3901. e1000_pci_restore_state(adapter);
  3902. ret_val = pci_enable_device(pdev);
  3903. pci_set_master(pdev);
  3904. pci_enable_wake(pdev, PCI_D3hot, 0);
  3905. pci_enable_wake(pdev, PCI_D3cold, 0);
  3906. e1000_reset(adapter);
  3907. E1000_WRITE_REG(&adapter->hw, WUS, ~0);
  3908. if (netif_running(netdev))
  3909. e1000_up(adapter);
  3910. netif_device_attach(netdev);
  3911. if (adapter->hw.mac_type >= e1000_82540 &&
  3912. adapter->hw.media_type == e1000_media_type_copper) {
  3913. manc = E1000_READ_REG(&adapter->hw, MANC);
  3914. manc &= ~(E1000_MANC_ARP_EN);
  3915. E1000_WRITE_REG(&adapter->hw, MANC, manc);
  3916. }
  3917. /* If the controller is 82573 and f/w is AMT, do not set
  3918. * DRV_LOAD until the interface is up. For all other cases,
  3919. * let the f/w know that the h/w is now under the control
  3920. * of the driver. */
  3921. if (adapter->hw.mac_type != e1000_82573 ||
  3922. !e1000_check_mng_mode(&adapter->hw))
  3923. e1000_get_hw_control(adapter);
  3924. return 0;
  3925. }
  3926. #endif
  3927. #ifdef CONFIG_NET_POLL_CONTROLLER
  3928. /*
  3929. * Polling 'interrupt' - used by things like netconsole to send skbs
  3930. * without having to re-enable interrupts. It's not called while
  3931. * the interrupt routine is executing.
  3932. */
  3933. static void
  3934. e1000_netpoll(struct net_device *netdev)
  3935. {
  3936. struct e1000_adapter *adapter = netdev_priv(netdev);
  3937. disable_irq(adapter->pdev->irq);
  3938. e1000_intr(adapter->pdev->irq, netdev, NULL);
  3939. e1000_clean_tx_irq(adapter, adapter->tx_ring);
  3940. #ifndef CONFIG_E1000_NAPI
  3941. adapter->clean_rx(adapter, adapter->rx_ring);
  3942. #endif
  3943. enable_irq(adapter->pdev->irq);
  3944. }
  3945. #endif
  3946. /* e1000_main.c */