e1000_main.c 152 KB

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