e1000_main.c 141 KB

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