e1000_main.c 154 KB

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