ixgbe_main.c 205 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2010 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. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include <linux/types.h>
  21. #include <linux/module.h>
  22. #include <linux/pci.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/vmalloc.h>
  25. #include <linux/string.h>
  26. #include <linux/in.h>
  27. #include <linux/ip.h>
  28. #include <linux/tcp.h>
  29. #include <linux/pkt_sched.h>
  30. #include <linux/ipv6.h>
  31. #include <linux/slab.h>
  32. #include <net/checksum.h>
  33. #include <net/ip6_checksum.h>
  34. #include <linux/ethtool.h>
  35. #include <linux/if_vlan.h>
  36. #include <scsi/fc/fc_fcoe.h>
  37. #include "ixgbe.h"
  38. #include "ixgbe_common.h"
  39. #include "ixgbe_dcb_82599.h"
  40. #include "ixgbe_sriov.h"
  41. char ixgbe_driver_name[] = "ixgbe";
  42. static const char ixgbe_driver_string[] =
  43. "Intel(R) 10 Gigabit PCI Express Network Driver";
  44. #define DRV_VERSION "2.0.84-k2"
  45. const char ixgbe_driver_version[] = DRV_VERSION;
  46. static char ixgbe_copyright[] = "Copyright (c) 1999-2010 Intel Corporation.";
  47. static const struct ixgbe_info *ixgbe_info_tbl[] = {
  48. [board_82598] = &ixgbe_82598_info,
  49. [board_82599] = &ixgbe_82599_info,
  50. };
  51. /* ixgbe_pci_tbl - PCI Device ID Table
  52. *
  53. * Wildcard entries (PCI_ANY_ID) should come last
  54. * Last entry must be all 0s
  55. *
  56. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  57. * Class, Class Mask, private data (not used) }
  58. */
  59. static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
  60. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
  61. board_82598 },
  62. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
  63. board_82598 },
  64. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
  65. board_82598 },
  66. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
  67. board_82598 },
  68. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
  69. board_82598 },
  70. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
  71. board_82598 },
  72. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
  73. board_82598 },
  74. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
  75. board_82598 },
  76. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
  77. board_82598 },
  78. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
  79. board_82598 },
  80. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
  81. board_82598 },
  82. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
  83. board_82598 },
  84. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
  85. board_82599 },
  86. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
  87. board_82599 },
  88. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR),
  89. board_82599 },
  90. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
  91. board_82599 },
  92. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM),
  93. board_82599 },
  94. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
  95. board_82599 },
  96. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4),
  97. board_82599 },
  98. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM),
  99. board_82599 },
  100. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE),
  101. board_82599 },
  102. /* required last entry */
  103. {0, }
  104. };
  105. MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
  106. #ifdef CONFIG_IXGBE_DCA
  107. static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
  108. void *p);
  109. static struct notifier_block dca_notifier = {
  110. .notifier_call = ixgbe_notify_dca,
  111. .next = NULL,
  112. .priority = 0
  113. };
  114. #endif
  115. #ifdef CONFIG_PCI_IOV
  116. static unsigned int max_vfs;
  117. module_param(max_vfs, uint, 0);
  118. MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate "
  119. "per physical function");
  120. #endif /* CONFIG_PCI_IOV */
  121. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  122. MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
  123. MODULE_LICENSE("GPL");
  124. MODULE_VERSION(DRV_VERSION);
  125. #define DEFAULT_DEBUG_LEVEL_SHIFT 3
  126. static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
  127. {
  128. struct ixgbe_hw *hw = &adapter->hw;
  129. u32 gcr;
  130. u32 gpie;
  131. u32 vmdctl;
  132. #ifdef CONFIG_PCI_IOV
  133. /* disable iov and allow time for transactions to clear */
  134. pci_disable_sriov(adapter->pdev);
  135. #endif
  136. /* turn off device IOV mode */
  137. gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
  138. gcr &= ~(IXGBE_GCR_EXT_SRIOV);
  139. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr);
  140. gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
  141. gpie &= ~IXGBE_GPIE_VTMODE_MASK;
  142. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  143. /* set default pool back to 0 */
  144. vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  145. vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
  146. IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
  147. /* take a breather then clean up driver data */
  148. msleep(100);
  149. if (adapter->vfinfo)
  150. kfree(adapter->vfinfo);
  151. adapter->vfinfo = NULL;
  152. adapter->num_vfs = 0;
  153. adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
  154. }
  155. struct ixgbe_reg_info {
  156. u32 ofs;
  157. char *name;
  158. };
  159. static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
  160. /* General Registers */
  161. {IXGBE_CTRL, "CTRL"},
  162. {IXGBE_STATUS, "STATUS"},
  163. {IXGBE_CTRL_EXT, "CTRL_EXT"},
  164. /* Interrupt Registers */
  165. {IXGBE_EICR, "EICR"},
  166. /* RX Registers */
  167. {IXGBE_SRRCTL(0), "SRRCTL"},
  168. {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
  169. {IXGBE_RDLEN(0), "RDLEN"},
  170. {IXGBE_RDH(0), "RDH"},
  171. {IXGBE_RDT(0), "RDT"},
  172. {IXGBE_RXDCTL(0), "RXDCTL"},
  173. {IXGBE_RDBAL(0), "RDBAL"},
  174. {IXGBE_RDBAH(0), "RDBAH"},
  175. /* TX Registers */
  176. {IXGBE_TDBAL(0), "TDBAL"},
  177. {IXGBE_TDBAH(0), "TDBAH"},
  178. {IXGBE_TDLEN(0), "TDLEN"},
  179. {IXGBE_TDH(0), "TDH"},
  180. {IXGBE_TDT(0), "TDT"},
  181. {IXGBE_TXDCTL(0), "TXDCTL"},
  182. /* List Terminator */
  183. {}
  184. };
  185. /*
  186. * ixgbe_regdump - register printout routine
  187. */
  188. static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
  189. {
  190. int i = 0, j = 0;
  191. char rname[16];
  192. u32 regs[64];
  193. switch (reginfo->ofs) {
  194. case IXGBE_SRRCTL(0):
  195. for (i = 0; i < 64; i++)
  196. regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
  197. break;
  198. case IXGBE_DCA_RXCTRL(0):
  199. for (i = 0; i < 64; i++)
  200. regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
  201. break;
  202. case IXGBE_RDLEN(0):
  203. for (i = 0; i < 64; i++)
  204. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
  205. break;
  206. case IXGBE_RDH(0):
  207. for (i = 0; i < 64; i++)
  208. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
  209. break;
  210. case IXGBE_RDT(0):
  211. for (i = 0; i < 64; i++)
  212. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
  213. break;
  214. case IXGBE_RXDCTL(0):
  215. for (i = 0; i < 64; i++)
  216. regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  217. break;
  218. case IXGBE_RDBAL(0):
  219. for (i = 0; i < 64; i++)
  220. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
  221. break;
  222. case IXGBE_RDBAH(0):
  223. for (i = 0; i < 64; i++)
  224. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
  225. break;
  226. case IXGBE_TDBAL(0):
  227. for (i = 0; i < 64; i++)
  228. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
  229. break;
  230. case IXGBE_TDBAH(0):
  231. for (i = 0; i < 64; i++)
  232. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
  233. break;
  234. case IXGBE_TDLEN(0):
  235. for (i = 0; i < 64; i++)
  236. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
  237. break;
  238. case IXGBE_TDH(0):
  239. for (i = 0; i < 64; i++)
  240. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
  241. break;
  242. case IXGBE_TDT(0):
  243. for (i = 0; i < 64; i++)
  244. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
  245. break;
  246. case IXGBE_TXDCTL(0):
  247. for (i = 0; i < 64; i++)
  248. regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
  249. break;
  250. default:
  251. printk(KERN_INFO "%-15s %08x\n", reginfo->name,
  252. IXGBE_READ_REG(hw, reginfo->ofs));
  253. return;
  254. }
  255. for (i = 0; i < 8; i++) {
  256. snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
  257. printk(KERN_ERR "%-15s ", rname);
  258. for (j = 0; j < 8; j++)
  259. printk(KERN_CONT "%08x ", regs[i*8+j]);
  260. printk(KERN_CONT "\n");
  261. }
  262. }
  263. /*
  264. * ixgbe_dump - Print registers, tx-rings and rx-rings
  265. */
  266. static void ixgbe_dump(struct ixgbe_adapter *adapter)
  267. {
  268. struct net_device *netdev = adapter->netdev;
  269. struct ixgbe_hw *hw = &adapter->hw;
  270. struct ixgbe_reg_info *reginfo;
  271. int n = 0;
  272. struct ixgbe_ring *tx_ring;
  273. struct ixgbe_tx_buffer *tx_buffer_info;
  274. union ixgbe_adv_tx_desc *tx_desc;
  275. struct my_u0 { u64 a; u64 b; } *u0;
  276. struct ixgbe_ring *rx_ring;
  277. union ixgbe_adv_rx_desc *rx_desc;
  278. struct ixgbe_rx_buffer *rx_buffer_info;
  279. u32 staterr;
  280. int i = 0;
  281. if (!netif_msg_hw(adapter))
  282. return;
  283. /* Print netdevice Info */
  284. if (netdev) {
  285. dev_info(&adapter->pdev->dev, "Net device Info\n");
  286. printk(KERN_INFO "Device Name state "
  287. "trans_start last_rx\n");
  288. printk(KERN_INFO "%-15s %016lX %016lX %016lX\n",
  289. netdev->name,
  290. netdev->state,
  291. netdev->trans_start,
  292. netdev->last_rx);
  293. }
  294. /* Print Registers */
  295. dev_info(&adapter->pdev->dev, "Register Dump\n");
  296. printk(KERN_INFO " Register Name Value\n");
  297. for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
  298. reginfo->name; reginfo++) {
  299. ixgbe_regdump(hw, reginfo);
  300. }
  301. /* Print TX Ring Summary */
  302. if (!netdev || !netif_running(netdev))
  303. goto exit;
  304. dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
  305. printk(KERN_INFO "Queue [NTU] [NTC] [bi(ntc)->dma ] "
  306. "leng ntw timestamp\n");
  307. for (n = 0; n < adapter->num_tx_queues; n++) {
  308. tx_ring = adapter->tx_ring[n];
  309. tx_buffer_info =
  310. &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
  311. printk(KERN_INFO " %5d %5X %5X %016llX %04X %3X %016llX\n",
  312. n, tx_ring->next_to_use, tx_ring->next_to_clean,
  313. (u64)tx_buffer_info->dma,
  314. tx_buffer_info->length,
  315. tx_buffer_info->next_to_watch,
  316. (u64)tx_buffer_info->time_stamp);
  317. }
  318. /* Print TX Rings */
  319. if (!netif_msg_tx_done(adapter))
  320. goto rx_ring_summary;
  321. dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
  322. /* Transmit Descriptor Formats
  323. *
  324. * Advanced Transmit Descriptor
  325. * +--------------------------------------------------------------+
  326. * 0 | Buffer Address [63:0] |
  327. * +--------------------------------------------------------------+
  328. * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
  329. * +--------------------------------------------------------------+
  330. * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
  331. */
  332. for (n = 0; n < adapter->num_tx_queues; n++) {
  333. tx_ring = adapter->tx_ring[n];
  334. printk(KERN_INFO "------------------------------------\n");
  335. printk(KERN_INFO "TX QUEUE INDEX = %d\n", tx_ring->queue_index);
  336. printk(KERN_INFO "------------------------------------\n");
  337. printk(KERN_INFO "T [desc] [address 63:0 ] "
  338. "[PlPOIdStDDt Ln] [bi->dma ] "
  339. "leng ntw timestamp bi->skb\n");
  340. for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
  341. tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
  342. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  343. u0 = (struct my_u0 *)tx_desc;
  344. printk(KERN_INFO "T [0x%03X] %016llX %016llX %016llX"
  345. " %04X %3X %016llX %p", i,
  346. le64_to_cpu(u0->a),
  347. le64_to_cpu(u0->b),
  348. (u64)tx_buffer_info->dma,
  349. tx_buffer_info->length,
  350. tx_buffer_info->next_to_watch,
  351. (u64)tx_buffer_info->time_stamp,
  352. tx_buffer_info->skb);
  353. if (i == tx_ring->next_to_use &&
  354. i == tx_ring->next_to_clean)
  355. printk(KERN_CONT " NTC/U\n");
  356. else if (i == tx_ring->next_to_use)
  357. printk(KERN_CONT " NTU\n");
  358. else if (i == tx_ring->next_to_clean)
  359. printk(KERN_CONT " NTC\n");
  360. else
  361. printk(KERN_CONT "\n");
  362. if (netif_msg_pktdata(adapter) &&
  363. tx_buffer_info->dma != 0)
  364. print_hex_dump(KERN_INFO, "",
  365. DUMP_PREFIX_ADDRESS, 16, 1,
  366. phys_to_virt(tx_buffer_info->dma),
  367. tx_buffer_info->length, true);
  368. }
  369. }
  370. /* Print RX Rings Summary */
  371. rx_ring_summary:
  372. dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
  373. printk(KERN_INFO "Queue [NTU] [NTC]\n");
  374. for (n = 0; n < adapter->num_rx_queues; n++) {
  375. rx_ring = adapter->rx_ring[n];
  376. printk(KERN_INFO "%5d %5X %5X\n", n,
  377. rx_ring->next_to_use, rx_ring->next_to_clean);
  378. }
  379. /* Print RX Rings */
  380. if (!netif_msg_rx_status(adapter))
  381. goto exit;
  382. dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
  383. /* Advanced Receive Descriptor (Read) Format
  384. * 63 1 0
  385. * +-----------------------------------------------------+
  386. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  387. * +----------------------------------------------+------+
  388. * 8 | Header Buffer Address [63:1] | DD |
  389. * +-----------------------------------------------------+
  390. *
  391. *
  392. * Advanced Receive Descriptor (Write-Back) Format
  393. *
  394. * 63 48 47 32 31 30 21 20 16 15 4 3 0
  395. * +------------------------------------------------------+
  396. * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
  397. * | Checksum Ident | | | | Type | Type |
  398. * +------------------------------------------------------+
  399. * 8 | VLAN Tag | Length | Extended Error | Extended Status |
  400. * +------------------------------------------------------+
  401. * 63 48 47 32 31 20 19 0
  402. */
  403. for (n = 0; n < adapter->num_rx_queues; n++) {
  404. rx_ring = adapter->rx_ring[n];
  405. printk(KERN_INFO "------------------------------------\n");
  406. printk(KERN_INFO "RX QUEUE INDEX = %d\n", rx_ring->queue_index);
  407. printk(KERN_INFO "------------------------------------\n");
  408. printk(KERN_INFO "R [desc] [ PktBuf A0] "
  409. "[ HeadBuf DD] [bi->dma ] [bi->skb] "
  410. "<-- Adv Rx Read format\n");
  411. printk(KERN_INFO "RWB[desc] [PcsmIpSHl PtRs] "
  412. "[vl er S cks ln] ---------------- [bi->skb] "
  413. "<-- Adv Rx Write-Back format\n");
  414. for (i = 0; i < rx_ring->count; i++) {
  415. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  416. rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
  417. u0 = (struct my_u0 *)rx_desc;
  418. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  419. if (staterr & IXGBE_RXD_STAT_DD) {
  420. /* Descriptor Done */
  421. printk(KERN_INFO "RWB[0x%03X] %016llX "
  422. "%016llX ---------------- %p", i,
  423. le64_to_cpu(u0->a),
  424. le64_to_cpu(u0->b),
  425. rx_buffer_info->skb);
  426. } else {
  427. printk(KERN_INFO "R [0x%03X] %016llX "
  428. "%016llX %016llX %p", i,
  429. le64_to_cpu(u0->a),
  430. le64_to_cpu(u0->b),
  431. (u64)rx_buffer_info->dma,
  432. rx_buffer_info->skb);
  433. if (netif_msg_pktdata(adapter)) {
  434. print_hex_dump(KERN_INFO, "",
  435. DUMP_PREFIX_ADDRESS, 16, 1,
  436. phys_to_virt(rx_buffer_info->dma),
  437. rx_ring->rx_buf_len, true);
  438. if (rx_ring->rx_buf_len
  439. < IXGBE_RXBUFFER_2048)
  440. print_hex_dump(KERN_INFO, "",
  441. DUMP_PREFIX_ADDRESS, 16, 1,
  442. phys_to_virt(
  443. rx_buffer_info->page_dma +
  444. rx_buffer_info->page_offset
  445. ),
  446. PAGE_SIZE/2, true);
  447. }
  448. }
  449. if (i == rx_ring->next_to_use)
  450. printk(KERN_CONT " NTU\n");
  451. else if (i == rx_ring->next_to_clean)
  452. printk(KERN_CONT " NTC\n");
  453. else
  454. printk(KERN_CONT "\n");
  455. }
  456. }
  457. exit:
  458. return;
  459. }
  460. static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
  461. {
  462. u32 ctrl_ext;
  463. /* Let firmware take over control of h/w */
  464. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  465. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  466. ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
  467. }
  468. static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
  469. {
  470. u32 ctrl_ext;
  471. /* Let firmware know the driver has taken over */
  472. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  473. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  474. ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
  475. }
  476. /*
  477. * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
  478. * @adapter: pointer to adapter struct
  479. * @direction: 0 for Rx, 1 for Tx, -1 for other causes
  480. * @queue: queue to map the corresponding interrupt to
  481. * @msix_vector: the vector to map to the corresponding queue
  482. *
  483. */
  484. static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
  485. u8 queue, u8 msix_vector)
  486. {
  487. u32 ivar, index;
  488. struct ixgbe_hw *hw = &adapter->hw;
  489. switch (hw->mac.type) {
  490. case ixgbe_mac_82598EB:
  491. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  492. if (direction == -1)
  493. direction = 0;
  494. index = (((direction * 64) + queue) >> 2) & 0x1F;
  495. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
  496. ivar &= ~(0xFF << (8 * (queue & 0x3)));
  497. ivar |= (msix_vector << (8 * (queue & 0x3)));
  498. IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
  499. break;
  500. case ixgbe_mac_82599EB:
  501. if (direction == -1) {
  502. /* other causes */
  503. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  504. index = ((queue & 1) * 8);
  505. ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
  506. ivar &= ~(0xFF << index);
  507. ivar |= (msix_vector << index);
  508. IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
  509. break;
  510. } else {
  511. /* tx or rx causes */
  512. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  513. index = ((16 * (queue & 1)) + (8 * direction));
  514. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
  515. ivar &= ~(0xFF << index);
  516. ivar |= (msix_vector << index);
  517. IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
  518. break;
  519. }
  520. default:
  521. break;
  522. }
  523. }
  524. static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
  525. u64 qmask)
  526. {
  527. u32 mask;
  528. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  529. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  530. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
  531. } else {
  532. mask = (qmask & 0xFFFFFFFF);
  533. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
  534. mask = (qmask >> 32);
  535. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
  536. }
  537. }
  538. static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
  539. struct ixgbe_tx_buffer
  540. *tx_buffer_info)
  541. {
  542. if (tx_buffer_info->dma) {
  543. if (tx_buffer_info->mapped_as_page)
  544. dma_unmap_page(&adapter->pdev->dev,
  545. tx_buffer_info->dma,
  546. tx_buffer_info->length,
  547. DMA_TO_DEVICE);
  548. else
  549. dma_unmap_single(&adapter->pdev->dev,
  550. tx_buffer_info->dma,
  551. tx_buffer_info->length,
  552. DMA_TO_DEVICE);
  553. tx_buffer_info->dma = 0;
  554. }
  555. if (tx_buffer_info->skb) {
  556. dev_kfree_skb_any(tx_buffer_info->skb);
  557. tx_buffer_info->skb = NULL;
  558. }
  559. tx_buffer_info->time_stamp = 0;
  560. /* tx_buffer_info must be completely set up in the transmit path */
  561. }
  562. /**
  563. * ixgbe_tx_xon_state - check the tx ring xon state
  564. * @adapter: the ixgbe adapter
  565. * @tx_ring: the corresponding tx_ring
  566. *
  567. * If not in DCB mode, checks TFCS.TXOFF, otherwise, find out the
  568. * corresponding TC of this tx_ring when checking TFCS.
  569. *
  570. * Returns : true if in xon state (currently not paused)
  571. */
  572. static inline bool ixgbe_tx_xon_state(struct ixgbe_adapter *adapter,
  573. struct ixgbe_ring *tx_ring)
  574. {
  575. u32 txoff = IXGBE_TFCS_TXOFF;
  576. #ifdef CONFIG_IXGBE_DCB
  577. if (adapter->dcb_cfg.pfc_mode_enable) {
  578. int tc;
  579. int reg_idx = tx_ring->reg_idx;
  580. int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
  581. switch (adapter->hw.mac.type) {
  582. case ixgbe_mac_82598EB:
  583. tc = reg_idx >> 2;
  584. txoff = IXGBE_TFCS_TXOFF0;
  585. break;
  586. case ixgbe_mac_82599EB:
  587. tc = 0;
  588. txoff = IXGBE_TFCS_TXOFF;
  589. if (dcb_i == 8) {
  590. /* TC0, TC1 */
  591. tc = reg_idx >> 5;
  592. if (tc == 2) /* TC2, TC3 */
  593. tc += (reg_idx - 64) >> 4;
  594. else if (tc == 3) /* TC4, TC5, TC6, TC7 */
  595. tc += 1 + ((reg_idx - 96) >> 3);
  596. } else if (dcb_i == 4) {
  597. /* TC0, TC1 */
  598. tc = reg_idx >> 6;
  599. if (tc == 1) {
  600. tc += (reg_idx - 64) >> 5;
  601. if (tc == 2) /* TC2, TC3 */
  602. tc += (reg_idx - 96) >> 4;
  603. }
  604. }
  605. break;
  606. default:
  607. tc = 0;
  608. }
  609. txoff <<= tc;
  610. }
  611. #endif
  612. return IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & txoff;
  613. }
  614. static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
  615. struct ixgbe_ring *tx_ring,
  616. unsigned int eop)
  617. {
  618. struct ixgbe_hw *hw = &adapter->hw;
  619. /* Detect a transmit hang in hardware, this serializes the
  620. * check with the clearing of time_stamp and movement of eop */
  621. adapter->detect_tx_hung = false;
  622. if (tx_ring->tx_buffer_info[eop].time_stamp &&
  623. time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
  624. ixgbe_tx_xon_state(adapter, tx_ring)) {
  625. /* detected Tx unit hang */
  626. union ixgbe_adv_tx_desc *tx_desc;
  627. tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
  628. e_err(drv, "Detected Tx Unit Hang\n"
  629. " Tx Queue <%d>\n"
  630. " TDH, TDT <%x>, <%x>\n"
  631. " next_to_use <%x>\n"
  632. " next_to_clean <%x>\n"
  633. "tx_buffer_info[next_to_clean]\n"
  634. " time_stamp <%lx>\n"
  635. " jiffies <%lx>\n",
  636. tx_ring->queue_index,
  637. IXGBE_READ_REG(hw, tx_ring->head),
  638. IXGBE_READ_REG(hw, tx_ring->tail),
  639. tx_ring->next_to_use, eop,
  640. tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
  641. return true;
  642. }
  643. return false;
  644. }
  645. #define IXGBE_MAX_TXD_PWR 14
  646. #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
  647. /* Tx Descriptors needed, worst case */
  648. #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
  649. (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
  650. #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
  651. MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
  652. static void ixgbe_tx_timeout(struct net_device *netdev);
  653. /**
  654. * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
  655. * @q_vector: structure containing interrupt and ring information
  656. * @tx_ring: tx ring to clean
  657. **/
  658. static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
  659. struct ixgbe_ring *tx_ring)
  660. {
  661. struct ixgbe_adapter *adapter = q_vector->adapter;
  662. struct net_device *netdev = adapter->netdev;
  663. union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
  664. struct ixgbe_tx_buffer *tx_buffer_info;
  665. unsigned int i, eop, count = 0;
  666. unsigned int total_bytes = 0, total_packets = 0;
  667. i = tx_ring->next_to_clean;
  668. eop = tx_ring->tx_buffer_info[i].next_to_watch;
  669. eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
  670. while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
  671. (count < tx_ring->work_limit)) {
  672. bool cleaned = false;
  673. rmb(); /* read buffer_info after eop_desc */
  674. for ( ; !cleaned; count++) {
  675. struct sk_buff *skb;
  676. tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
  677. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  678. cleaned = (i == eop);
  679. skb = tx_buffer_info->skb;
  680. if (cleaned && skb) {
  681. unsigned int segs, bytecount;
  682. unsigned int hlen = skb_headlen(skb);
  683. /* gso_segs is currently only valid for tcp */
  684. segs = skb_shinfo(skb)->gso_segs ?: 1;
  685. #ifdef IXGBE_FCOE
  686. /* adjust for FCoE Sequence Offload */
  687. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  688. && (skb->protocol == htons(ETH_P_FCOE)) &&
  689. skb_is_gso(skb)) {
  690. hlen = skb_transport_offset(skb) +
  691. sizeof(struct fc_frame_header) +
  692. sizeof(struct fcoe_crc_eof);
  693. segs = DIV_ROUND_UP(skb->len - hlen,
  694. skb_shinfo(skb)->gso_size);
  695. }
  696. #endif /* IXGBE_FCOE */
  697. /* multiply data chunks by size of headers */
  698. bytecount = ((segs - 1) * hlen) + skb->len;
  699. total_packets += segs;
  700. total_bytes += bytecount;
  701. }
  702. ixgbe_unmap_and_free_tx_resource(adapter,
  703. tx_buffer_info);
  704. tx_desc->wb.status = 0;
  705. i++;
  706. if (i == tx_ring->count)
  707. i = 0;
  708. }
  709. eop = tx_ring->tx_buffer_info[i].next_to_watch;
  710. eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
  711. }
  712. tx_ring->next_to_clean = i;
  713. #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
  714. if (unlikely(count && netif_carrier_ok(netdev) &&
  715. (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
  716. /* Make sure that anybody stopping the queue after this
  717. * sees the new next_to_clean.
  718. */
  719. smp_mb();
  720. if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
  721. !test_bit(__IXGBE_DOWN, &adapter->state)) {
  722. netif_wake_subqueue(netdev, tx_ring->queue_index);
  723. ++tx_ring->restart_queue;
  724. }
  725. }
  726. if (adapter->detect_tx_hung) {
  727. if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
  728. /* schedule immediate reset if we believe we hung */
  729. e_info(probe, "tx hang %d detected, resetting "
  730. "adapter\n", adapter->tx_timeout_count + 1);
  731. ixgbe_tx_timeout(adapter->netdev);
  732. }
  733. }
  734. /* re-arm the interrupt */
  735. if (count >= tx_ring->work_limit)
  736. ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx));
  737. tx_ring->total_bytes += total_bytes;
  738. tx_ring->total_packets += total_packets;
  739. tx_ring->stats.packets += total_packets;
  740. tx_ring->stats.bytes += total_bytes;
  741. return (count < tx_ring->work_limit);
  742. }
  743. #ifdef CONFIG_IXGBE_DCA
  744. static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
  745. struct ixgbe_ring *rx_ring)
  746. {
  747. u32 rxctrl;
  748. int cpu = get_cpu();
  749. int q = rx_ring->reg_idx;
  750. if (rx_ring->cpu != cpu) {
  751. rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
  752. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  753. rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
  754. rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  755. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  756. rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
  757. rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
  758. IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
  759. }
  760. rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
  761. rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
  762. rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
  763. rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
  764. IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
  765. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
  766. rx_ring->cpu = cpu;
  767. }
  768. put_cpu();
  769. }
  770. static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
  771. struct ixgbe_ring *tx_ring)
  772. {
  773. u32 txctrl;
  774. int cpu = get_cpu();
  775. int q = tx_ring->reg_idx;
  776. struct ixgbe_hw *hw = &adapter->hw;
  777. if (tx_ring->cpu != cpu) {
  778. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  779. txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(q));
  780. txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
  781. txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  782. txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
  783. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(q), txctrl);
  784. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  785. txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(q));
  786. txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
  787. txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
  788. IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
  789. txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
  790. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(q), txctrl);
  791. }
  792. tx_ring->cpu = cpu;
  793. }
  794. put_cpu();
  795. }
  796. static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
  797. {
  798. int i;
  799. if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
  800. return;
  801. /* always use CB2 mode, difference is masked in the CB driver */
  802. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
  803. for (i = 0; i < adapter->num_tx_queues; i++) {
  804. adapter->tx_ring[i]->cpu = -1;
  805. ixgbe_update_tx_dca(adapter, adapter->tx_ring[i]);
  806. }
  807. for (i = 0; i < adapter->num_rx_queues; i++) {
  808. adapter->rx_ring[i]->cpu = -1;
  809. ixgbe_update_rx_dca(adapter, adapter->rx_ring[i]);
  810. }
  811. }
  812. static int __ixgbe_notify_dca(struct device *dev, void *data)
  813. {
  814. struct net_device *netdev = dev_get_drvdata(dev);
  815. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  816. unsigned long event = *(unsigned long *)data;
  817. switch (event) {
  818. case DCA_PROVIDER_ADD:
  819. /* if we're already enabled, don't do it again */
  820. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  821. break;
  822. if (dca_add_requester(dev) == 0) {
  823. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  824. ixgbe_setup_dca(adapter);
  825. break;
  826. }
  827. /* Fall Through since DCA is disabled. */
  828. case DCA_PROVIDER_REMOVE:
  829. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  830. dca_remove_requester(dev);
  831. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  832. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
  833. }
  834. break;
  835. }
  836. return 0;
  837. }
  838. #endif /* CONFIG_IXGBE_DCA */
  839. /**
  840. * ixgbe_receive_skb - Send a completed packet up the stack
  841. * @adapter: board private structure
  842. * @skb: packet to send up
  843. * @status: hardware indication of status of receive
  844. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  845. * @rx_desc: rx descriptor
  846. **/
  847. static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
  848. struct sk_buff *skb, u8 status,
  849. struct ixgbe_ring *ring,
  850. union ixgbe_adv_rx_desc *rx_desc)
  851. {
  852. struct ixgbe_adapter *adapter = q_vector->adapter;
  853. struct napi_struct *napi = &q_vector->napi;
  854. bool is_vlan = (status & IXGBE_RXD_STAT_VP);
  855. u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
  856. if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
  857. if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK))
  858. vlan_gro_receive(napi, adapter->vlgrp, tag, skb);
  859. else
  860. napi_gro_receive(napi, skb);
  861. } else {
  862. if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK))
  863. vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
  864. else
  865. netif_rx(skb);
  866. }
  867. }
  868. /**
  869. * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
  870. * @adapter: address of board private structure
  871. * @status_err: hardware indication of status of receive
  872. * @skb: skb currently being received and modified
  873. **/
  874. static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
  875. union ixgbe_adv_rx_desc *rx_desc,
  876. struct sk_buff *skb)
  877. {
  878. u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
  879. skb->ip_summed = CHECKSUM_NONE;
  880. /* Rx csum disabled */
  881. if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
  882. return;
  883. /* if IP and error */
  884. if ((status_err & IXGBE_RXD_STAT_IPCS) &&
  885. (status_err & IXGBE_RXDADV_ERR_IPE)) {
  886. adapter->hw_csum_rx_error++;
  887. return;
  888. }
  889. if (!(status_err & IXGBE_RXD_STAT_L4CS))
  890. return;
  891. if (status_err & IXGBE_RXDADV_ERR_TCPE) {
  892. u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  893. /*
  894. * 82599 errata, UDP frames with a 0 checksum can be marked as
  895. * checksum errors.
  896. */
  897. if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
  898. (adapter->hw.mac.type == ixgbe_mac_82599EB))
  899. return;
  900. adapter->hw_csum_rx_error++;
  901. return;
  902. }
  903. /* It must be a TCP or UDP packet with a valid checksum */
  904. skb->ip_summed = CHECKSUM_UNNECESSARY;
  905. }
  906. static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
  907. struct ixgbe_ring *rx_ring, u32 val)
  908. {
  909. /*
  910. * Force memory writes to complete before letting h/w
  911. * know there are new descriptors to fetch. (Only
  912. * applicable for weak-ordered memory model archs,
  913. * such as IA-64).
  914. */
  915. wmb();
  916. IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
  917. }
  918. /**
  919. * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
  920. * @adapter: address of board private structure
  921. **/
  922. static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
  923. struct ixgbe_ring *rx_ring,
  924. int cleaned_count)
  925. {
  926. struct net_device *netdev = adapter->netdev;
  927. struct pci_dev *pdev = adapter->pdev;
  928. union ixgbe_adv_rx_desc *rx_desc;
  929. struct ixgbe_rx_buffer *bi;
  930. unsigned int i;
  931. unsigned int bufsz = rx_ring->rx_buf_len;
  932. i = rx_ring->next_to_use;
  933. bi = &rx_ring->rx_buffer_info[i];
  934. while (cleaned_count--) {
  935. rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
  936. if (!bi->page_dma &&
  937. (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) {
  938. if (!bi->page) {
  939. bi->page = netdev_alloc_page(netdev);
  940. if (!bi->page) {
  941. adapter->alloc_rx_page_failed++;
  942. goto no_buffers;
  943. }
  944. bi->page_offset = 0;
  945. } else {
  946. /* use a half page if we're re-using */
  947. bi->page_offset ^= (PAGE_SIZE / 2);
  948. }
  949. bi->page_dma = dma_map_page(&pdev->dev, bi->page,
  950. bi->page_offset,
  951. (PAGE_SIZE / 2),
  952. DMA_FROM_DEVICE);
  953. }
  954. if (!bi->skb) {
  955. struct sk_buff *skb = netdev_alloc_skb_ip_align(netdev,
  956. bufsz);
  957. bi->skb = skb;
  958. if (!skb) {
  959. adapter->alloc_rx_buff_failed++;
  960. goto no_buffers;
  961. }
  962. /* initialize queue mapping */
  963. skb_record_rx_queue(skb, rx_ring->queue_index);
  964. }
  965. if (!bi->dma) {
  966. bi->dma = dma_map_single(&pdev->dev,
  967. bi->skb->data,
  968. rx_ring->rx_buf_len,
  969. DMA_FROM_DEVICE);
  970. }
  971. /* Refresh the desc even if buffer_addrs didn't change because
  972. * each write-back erases this info. */
  973. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  974. rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
  975. rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
  976. } else {
  977. rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
  978. }
  979. i++;
  980. if (i == rx_ring->count)
  981. i = 0;
  982. bi = &rx_ring->rx_buffer_info[i];
  983. }
  984. no_buffers:
  985. if (rx_ring->next_to_use != i) {
  986. rx_ring->next_to_use = i;
  987. if (i-- == 0)
  988. i = (rx_ring->count - 1);
  989. ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
  990. }
  991. }
  992. static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
  993. {
  994. return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
  995. }
  996. static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
  997. {
  998. return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  999. }
  1000. static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc)
  1001. {
  1002. return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
  1003. IXGBE_RXDADV_RSCCNT_MASK) >>
  1004. IXGBE_RXDADV_RSCCNT_SHIFT;
  1005. }
  1006. /**
  1007. * ixgbe_transform_rsc_queue - change rsc queue into a full packet
  1008. * @skb: pointer to the last skb in the rsc queue
  1009. * @count: pointer to number of packets coalesced in this context
  1010. *
  1011. * This function changes a queue full of hw rsc buffers into a completed
  1012. * packet. It uses the ->prev pointers to find the first packet and then
  1013. * turns it into the frag list owner.
  1014. **/
  1015. static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb,
  1016. u64 *count)
  1017. {
  1018. unsigned int frag_list_size = 0;
  1019. while (skb->prev) {
  1020. struct sk_buff *prev = skb->prev;
  1021. frag_list_size += skb->len;
  1022. skb->prev = NULL;
  1023. skb = prev;
  1024. *count += 1;
  1025. }
  1026. skb_shinfo(skb)->frag_list = skb->next;
  1027. skb->next = NULL;
  1028. skb->len += frag_list_size;
  1029. skb->data_len += frag_list_size;
  1030. skb->truesize += frag_list_size;
  1031. return skb;
  1032. }
  1033. struct ixgbe_rsc_cb {
  1034. dma_addr_t dma;
  1035. bool delay_unmap;
  1036. };
  1037. #define IXGBE_RSC_CB(skb) ((struct ixgbe_rsc_cb *)(skb)->cb)
  1038. static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
  1039. struct ixgbe_ring *rx_ring,
  1040. int *work_done, int work_to_do)
  1041. {
  1042. struct ixgbe_adapter *adapter = q_vector->adapter;
  1043. struct net_device *netdev = adapter->netdev;
  1044. struct pci_dev *pdev = adapter->pdev;
  1045. union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
  1046. struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
  1047. struct sk_buff *skb;
  1048. unsigned int i, rsc_count = 0;
  1049. u32 len, staterr;
  1050. u16 hdr_info;
  1051. bool cleaned = false;
  1052. int cleaned_count = 0;
  1053. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  1054. #ifdef IXGBE_FCOE
  1055. int ddp_bytes = 0;
  1056. #endif /* IXGBE_FCOE */
  1057. i = rx_ring->next_to_clean;
  1058. rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
  1059. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  1060. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  1061. while (staterr & IXGBE_RXD_STAT_DD) {
  1062. u32 upper_len = 0;
  1063. if (*work_done >= work_to_do)
  1064. break;
  1065. (*work_done)++;
  1066. rmb(); /* read descriptor and rx_buffer_info after status DD */
  1067. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  1068. hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
  1069. len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
  1070. IXGBE_RXDADV_HDRBUFLEN_SHIFT;
  1071. upper_len = le16_to_cpu(rx_desc->wb.upper.length);
  1072. if ((len > IXGBE_RX_HDR_SIZE) ||
  1073. (upper_len && !(hdr_info & IXGBE_RXDADV_SPH)))
  1074. len = IXGBE_RX_HDR_SIZE;
  1075. } else {
  1076. len = le16_to_cpu(rx_desc->wb.upper.length);
  1077. }
  1078. cleaned = true;
  1079. skb = rx_buffer_info->skb;
  1080. prefetch(skb->data);
  1081. rx_buffer_info->skb = NULL;
  1082. if (rx_buffer_info->dma) {
  1083. if ((adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
  1084. (!(staterr & IXGBE_RXD_STAT_EOP)) &&
  1085. (!(skb->prev))) {
  1086. /*
  1087. * When HWRSC is enabled, delay unmapping
  1088. * of the first packet. It carries the
  1089. * header information, HW may still
  1090. * access the header after the writeback.
  1091. * Only unmap it when EOP is reached
  1092. */
  1093. IXGBE_RSC_CB(skb)->delay_unmap = true;
  1094. IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
  1095. } else {
  1096. dma_unmap_single(&pdev->dev,
  1097. rx_buffer_info->dma,
  1098. rx_ring->rx_buf_len,
  1099. DMA_FROM_DEVICE);
  1100. }
  1101. rx_buffer_info->dma = 0;
  1102. skb_put(skb, len);
  1103. }
  1104. if (upper_len) {
  1105. dma_unmap_page(&pdev->dev, rx_buffer_info->page_dma,
  1106. PAGE_SIZE / 2, DMA_FROM_DEVICE);
  1107. rx_buffer_info->page_dma = 0;
  1108. skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
  1109. rx_buffer_info->page,
  1110. rx_buffer_info->page_offset,
  1111. upper_len);
  1112. if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
  1113. (page_count(rx_buffer_info->page) != 1))
  1114. rx_buffer_info->page = NULL;
  1115. else
  1116. get_page(rx_buffer_info->page);
  1117. skb->len += upper_len;
  1118. skb->data_len += upper_len;
  1119. skb->truesize += upper_len;
  1120. }
  1121. i++;
  1122. if (i == rx_ring->count)
  1123. i = 0;
  1124. next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
  1125. prefetch(next_rxd);
  1126. cleaned_count++;
  1127. if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
  1128. rsc_count = ixgbe_get_rsc_count(rx_desc);
  1129. if (rsc_count) {
  1130. u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
  1131. IXGBE_RXDADV_NEXTP_SHIFT;
  1132. next_buffer = &rx_ring->rx_buffer_info[nextp];
  1133. } else {
  1134. next_buffer = &rx_ring->rx_buffer_info[i];
  1135. }
  1136. if (staterr & IXGBE_RXD_STAT_EOP) {
  1137. if (skb->prev)
  1138. skb = ixgbe_transform_rsc_queue(skb, &(rx_ring->rsc_count));
  1139. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  1140. if (IXGBE_RSC_CB(skb)->delay_unmap) {
  1141. dma_unmap_single(&pdev->dev,
  1142. IXGBE_RSC_CB(skb)->dma,
  1143. rx_ring->rx_buf_len,
  1144. DMA_FROM_DEVICE);
  1145. IXGBE_RSC_CB(skb)->dma = 0;
  1146. IXGBE_RSC_CB(skb)->delay_unmap = false;
  1147. }
  1148. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)
  1149. rx_ring->rsc_count += skb_shinfo(skb)->nr_frags;
  1150. else
  1151. rx_ring->rsc_count++;
  1152. rx_ring->rsc_flush++;
  1153. }
  1154. rx_ring->stats.packets++;
  1155. rx_ring->stats.bytes += skb->len;
  1156. } else {
  1157. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  1158. rx_buffer_info->skb = next_buffer->skb;
  1159. rx_buffer_info->dma = next_buffer->dma;
  1160. next_buffer->skb = skb;
  1161. next_buffer->dma = 0;
  1162. } else {
  1163. skb->next = next_buffer->skb;
  1164. skb->next->prev = skb;
  1165. }
  1166. rx_ring->non_eop_descs++;
  1167. goto next_desc;
  1168. }
  1169. if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
  1170. dev_kfree_skb_irq(skb);
  1171. goto next_desc;
  1172. }
  1173. ixgbe_rx_checksum(adapter, rx_desc, skb);
  1174. /* probably a little skewed due to removing CRC */
  1175. total_rx_bytes += skb->len;
  1176. total_rx_packets++;
  1177. skb->protocol = eth_type_trans(skb, adapter->netdev);
  1178. #ifdef IXGBE_FCOE
  1179. /* if ddp, not passing to ULD unless for FCP_RSP or error */
  1180. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  1181. ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
  1182. if (!ddp_bytes)
  1183. goto next_desc;
  1184. }
  1185. #endif /* IXGBE_FCOE */
  1186. ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
  1187. next_desc:
  1188. rx_desc->wb.upper.status_error = 0;
  1189. /* return some buffers to hardware, one at a time is too slow */
  1190. if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
  1191. ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
  1192. cleaned_count = 0;
  1193. }
  1194. /* use prefetched values */
  1195. rx_desc = next_rxd;
  1196. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  1197. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  1198. }
  1199. rx_ring->next_to_clean = i;
  1200. cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
  1201. if (cleaned_count)
  1202. ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
  1203. #ifdef IXGBE_FCOE
  1204. /* include DDPed FCoE data */
  1205. if (ddp_bytes > 0) {
  1206. unsigned int mss;
  1207. mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) -
  1208. sizeof(struct fc_frame_header) -
  1209. sizeof(struct fcoe_crc_eof);
  1210. if (mss > 512)
  1211. mss &= ~511;
  1212. total_rx_bytes += ddp_bytes;
  1213. total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
  1214. }
  1215. #endif /* IXGBE_FCOE */
  1216. rx_ring->total_packets += total_rx_packets;
  1217. rx_ring->total_bytes += total_rx_bytes;
  1218. netdev->stats.rx_bytes += total_rx_bytes;
  1219. netdev->stats.rx_packets += total_rx_packets;
  1220. return cleaned;
  1221. }
  1222. static int ixgbe_clean_rxonly(struct napi_struct *, int);
  1223. /**
  1224. * ixgbe_configure_msix - Configure MSI-X hardware
  1225. * @adapter: board private structure
  1226. *
  1227. * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
  1228. * interrupts.
  1229. **/
  1230. static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
  1231. {
  1232. struct ixgbe_q_vector *q_vector;
  1233. int i, j, q_vectors, v_idx, r_idx;
  1234. u32 mask;
  1235. q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1236. /*
  1237. * Populate the IVAR table and set the ITR values to the
  1238. * corresponding register.
  1239. */
  1240. for (v_idx = 0; v_idx < q_vectors; v_idx++) {
  1241. q_vector = adapter->q_vector[v_idx];
  1242. /* XXX for_each_set_bit(...) */
  1243. r_idx = find_first_bit(q_vector->rxr_idx,
  1244. adapter->num_rx_queues);
  1245. for (i = 0; i < q_vector->rxr_count; i++) {
  1246. j = adapter->rx_ring[r_idx]->reg_idx;
  1247. ixgbe_set_ivar(adapter, 0, j, v_idx);
  1248. r_idx = find_next_bit(q_vector->rxr_idx,
  1249. adapter->num_rx_queues,
  1250. r_idx + 1);
  1251. }
  1252. r_idx = find_first_bit(q_vector->txr_idx,
  1253. adapter->num_tx_queues);
  1254. for (i = 0; i < q_vector->txr_count; i++) {
  1255. j = adapter->tx_ring[r_idx]->reg_idx;
  1256. ixgbe_set_ivar(adapter, 1, j, v_idx);
  1257. r_idx = find_next_bit(q_vector->txr_idx,
  1258. adapter->num_tx_queues,
  1259. r_idx + 1);
  1260. }
  1261. if (q_vector->txr_count && !q_vector->rxr_count)
  1262. /* tx only */
  1263. q_vector->eitr = adapter->tx_eitr_param;
  1264. else if (q_vector->rxr_count)
  1265. /* rx or mixed */
  1266. q_vector->eitr = adapter->rx_eitr_param;
  1267. ixgbe_write_eitr(q_vector);
  1268. }
  1269. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  1270. ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
  1271. v_idx);
  1272. else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
  1273. ixgbe_set_ivar(adapter, -1, 1, v_idx);
  1274. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
  1275. /* set up to autoclear timer, and the vectors */
  1276. mask = IXGBE_EIMS_ENABLE_MASK;
  1277. if (adapter->num_vfs)
  1278. mask &= ~(IXGBE_EIMS_OTHER |
  1279. IXGBE_EIMS_MAILBOX |
  1280. IXGBE_EIMS_LSC);
  1281. else
  1282. mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
  1283. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
  1284. }
  1285. enum latency_range {
  1286. lowest_latency = 0,
  1287. low_latency = 1,
  1288. bulk_latency = 2,
  1289. latency_invalid = 255
  1290. };
  1291. /**
  1292. * ixgbe_update_itr - update the dynamic ITR value based on statistics
  1293. * @adapter: pointer to adapter
  1294. * @eitr: eitr setting (ints per sec) to give last timeslice
  1295. * @itr_setting: current throttle rate in ints/second
  1296. * @packets: the number of packets during this measurement interval
  1297. * @bytes: the number of bytes during this measurement interval
  1298. *
  1299. * Stores a new ITR value based on packets and byte
  1300. * counts during the last interrupt. The advantage of per interrupt
  1301. * computation is faster updates and more accurate ITR for the current
  1302. * traffic pattern. Constants in this function were computed
  1303. * based on theoretical maximum wire speed and thresholds were set based
  1304. * on testing data as well as attempting to minimize response time
  1305. * while increasing bulk throughput.
  1306. * this functionality is controlled by the InterruptThrottleRate module
  1307. * parameter (see ixgbe_param.c)
  1308. **/
  1309. static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
  1310. u32 eitr, u8 itr_setting,
  1311. int packets, int bytes)
  1312. {
  1313. unsigned int retval = itr_setting;
  1314. u32 timepassed_us;
  1315. u64 bytes_perint;
  1316. if (packets == 0)
  1317. goto update_itr_done;
  1318. /* simple throttlerate management
  1319. * 0-20MB/s lowest (100000 ints/s)
  1320. * 20-100MB/s low (20000 ints/s)
  1321. * 100-1249MB/s bulk (8000 ints/s)
  1322. */
  1323. /* what was last interrupt timeslice? */
  1324. timepassed_us = 1000000/eitr;
  1325. bytes_perint = bytes / timepassed_us; /* bytes/usec */
  1326. switch (itr_setting) {
  1327. case lowest_latency:
  1328. if (bytes_perint > adapter->eitr_low)
  1329. retval = low_latency;
  1330. break;
  1331. case low_latency:
  1332. if (bytes_perint > adapter->eitr_high)
  1333. retval = bulk_latency;
  1334. else if (bytes_perint <= adapter->eitr_low)
  1335. retval = lowest_latency;
  1336. break;
  1337. case bulk_latency:
  1338. if (bytes_perint <= adapter->eitr_high)
  1339. retval = low_latency;
  1340. break;
  1341. }
  1342. update_itr_done:
  1343. return retval;
  1344. }
  1345. /**
  1346. * ixgbe_write_eitr - write EITR register in hardware specific way
  1347. * @q_vector: structure containing interrupt and ring information
  1348. *
  1349. * This function is made to be called by ethtool and by the driver
  1350. * when it needs to update EITR registers at runtime. Hardware
  1351. * specific quirks/differences are taken care of here.
  1352. */
  1353. void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
  1354. {
  1355. struct ixgbe_adapter *adapter = q_vector->adapter;
  1356. struct ixgbe_hw *hw = &adapter->hw;
  1357. int v_idx = q_vector->v_idx;
  1358. u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
  1359. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  1360. /* must write high and low 16 bits to reset counter */
  1361. itr_reg |= (itr_reg << 16);
  1362. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  1363. /*
  1364. * 82599 can support a value of zero, so allow it for
  1365. * max interrupt rate, but there is an errata where it can
  1366. * not be zero with RSC
  1367. */
  1368. if (itr_reg == 8 &&
  1369. !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
  1370. itr_reg = 0;
  1371. /*
  1372. * set the WDIS bit to not clear the timer bits and cause an
  1373. * immediate assertion of the interrupt
  1374. */
  1375. itr_reg |= IXGBE_EITR_CNT_WDIS;
  1376. }
  1377. IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
  1378. }
  1379. static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
  1380. {
  1381. struct ixgbe_adapter *adapter = q_vector->adapter;
  1382. u32 new_itr;
  1383. u8 current_itr, ret_itr;
  1384. int i, r_idx;
  1385. struct ixgbe_ring *rx_ring, *tx_ring;
  1386. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1387. for (i = 0; i < q_vector->txr_count; i++) {
  1388. tx_ring = adapter->tx_ring[r_idx];
  1389. ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
  1390. q_vector->tx_itr,
  1391. tx_ring->total_packets,
  1392. tx_ring->total_bytes);
  1393. /* if the result for this queue would decrease interrupt
  1394. * rate for this vector then use that result */
  1395. q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
  1396. q_vector->tx_itr - 1 : ret_itr);
  1397. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1398. r_idx + 1);
  1399. }
  1400. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1401. for (i = 0; i < q_vector->rxr_count; i++) {
  1402. rx_ring = adapter->rx_ring[r_idx];
  1403. ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
  1404. q_vector->rx_itr,
  1405. rx_ring->total_packets,
  1406. rx_ring->total_bytes);
  1407. /* if the result for this queue would decrease interrupt
  1408. * rate for this vector then use that result */
  1409. q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
  1410. q_vector->rx_itr - 1 : ret_itr);
  1411. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1412. r_idx + 1);
  1413. }
  1414. current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
  1415. switch (current_itr) {
  1416. /* counts and packets in update_itr are dependent on these numbers */
  1417. case lowest_latency:
  1418. new_itr = 100000;
  1419. break;
  1420. case low_latency:
  1421. new_itr = 20000; /* aka hwitr = ~200 */
  1422. break;
  1423. case bulk_latency:
  1424. default:
  1425. new_itr = 8000;
  1426. break;
  1427. }
  1428. if (new_itr != q_vector->eitr) {
  1429. /* do an exponential smoothing */
  1430. new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
  1431. /* save the algorithm value here, not the smoothed one */
  1432. q_vector->eitr = new_itr;
  1433. ixgbe_write_eitr(q_vector);
  1434. }
  1435. }
  1436. /**
  1437. * ixgbe_check_overtemp_task - worker thread to check over tempurature
  1438. * @work: pointer to work_struct containing our data
  1439. **/
  1440. static void ixgbe_check_overtemp_task(struct work_struct *work)
  1441. {
  1442. struct ixgbe_adapter *adapter = container_of(work,
  1443. struct ixgbe_adapter,
  1444. check_overtemp_task);
  1445. struct ixgbe_hw *hw = &adapter->hw;
  1446. u32 eicr = adapter->interrupt_event;
  1447. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
  1448. switch (hw->device_id) {
  1449. case IXGBE_DEV_ID_82599_T3_LOM: {
  1450. u32 autoneg;
  1451. bool link_up = false;
  1452. if (hw->mac.ops.check_link)
  1453. hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
  1454. if (((eicr & IXGBE_EICR_GPI_SDP0) && (!link_up)) ||
  1455. (eicr & IXGBE_EICR_LSC))
  1456. /* Check if this is due to overtemp */
  1457. if (hw->phy.ops.check_overtemp(hw) == IXGBE_ERR_OVERTEMP)
  1458. break;
  1459. }
  1460. return;
  1461. default:
  1462. if (!(eicr & IXGBE_EICR_GPI_SDP0))
  1463. return;
  1464. break;
  1465. }
  1466. e_crit(drv, "Network adapter has been stopped because it has "
  1467. "over heated. Restart the computer. If the problem "
  1468. "persists, power off the system and replace the "
  1469. "adapter\n");
  1470. /* write to clear the interrupt */
  1471. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP0);
  1472. }
  1473. }
  1474. static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
  1475. {
  1476. struct ixgbe_hw *hw = &adapter->hw;
  1477. if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
  1478. (eicr & IXGBE_EICR_GPI_SDP1)) {
  1479. e_crit(probe, "Fan has stopped, replace the adapter\n");
  1480. /* write to clear the interrupt */
  1481. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
  1482. }
  1483. }
  1484. static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
  1485. {
  1486. struct ixgbe_hw *hw = &adapter->hw;
  1487. if (eicr & IXGBE_EICR_GPI_SDP1) {
  1488. /* Clear the interrupt */
  1489. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
  1490. schedule_work(&adapter->multispeed_fiber_task);
  1491. } else if (eicr & IXGBE_EICR_GPI_SDP2) {
  1492. /* Clear the interrupt */
  1493. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
  1494. schedule_work(&adapter->sfp_config_module_task);
  1495. } else {
  1496. /* Interrupt isn't for us... */
  1497. return;
  1498. }
  1499. }
  1500. static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
  1501. {
  1502. struct ixgbe_hw *hw = &adapter->hw;
  1503. adapter->lsc_int++;
  1504. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  1505. adapter->link_check_timeout = jiffies;
  1506. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  1507. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
  1508. IXGBE_WRITE_FLUSH(hw);
  1509. schedule_work(&adapter->watchdog_task);
  1510. }
  1511. }
  1512. static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
  1513. {
  1514. struct net_device *netdev = data;
  1515. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1516. struct ixgbe_hw *hw = &adapter->hw;
  1517. u32 eicr;
  1518. /*
  1519. * Workaround for Silicon errata. Use clear-by-write instead
  1520. * of clear-by-read. Reading with EICS will return the
  1521. * interrupt causes without clearing, which later be done
  1522. * with the write to EICR.
  1523. */
  1524. eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
  1525. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
  1526. if (eicr & IXGBE_EICR_LSC)
  1527. ixgbe_check_lsc(adapter);
  1528. if (eicr & IXGBE_EICR_MAILBOX)
  1529. ixgbe_msg_task(adapter);
  1530. if (hw->mac.type == ixgbe_mac_82598EB)
  1531. ixgbe_check_fan_failure(adapter, eicr);
  1532. if (hw->mac.type == ixgbe_mac_82599EB) {
  1533. ixgbe_check_sfp_event(adapter, eicr);
  1534. adapter->interrupt_event = eicr;
  1535. if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
  1536. ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)))
  1537. schedule_work(&adapter->check_overtemp_task);
  1538. /* Handle Flow Director Full threshold interrupt */
  1539. if (eicr & IXGBE_EICR_FLOW_DIR) {
  1540. int i;
  1541. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR);
  1542. /* Disable transmits before FDIR Re-initialization */
  1543. netif_tx_stop_all_queues(netdev);
  1544. for (i = 0; i < adapter->num_tx_queues; i++) {
  1545. struct ixgbe_ring *tx_ring =
  1546. adapter->tx_ring[i];
  1547. if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE,
  1548. &tx_ring->reinit_state))
  1549. schedule_work(&adapter->fdir_reinit_task);
  1550. }
  1551. }
  1552. }
  1553. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1554. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
  1555. return IRQ_HANDLED;
  1556. }
  1557. static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
  1558. u64 qmask)
  1559. {
  1560. u32 mask;
  1561. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  1562. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  1563. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  1564. } else {
  1565. mask = (qmask & 0xFFFFFFFF);
  1566. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask);
  1567. mask = (qmask >> 32);
  1568. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask);
  1569. }
  1570. /* skip the flush */
  1571. }
  1572. static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
  1573. u64 qmask)
  1574. {
  1575. u32 mask;
  1576. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  1577. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  1578. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask);
  1579. } else {
  1580. mask = (qmask & 0xFFFFFFFF);
  1581. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask);
  1582. mask = (qmask >> 32);
  1583. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask);
  1584. }
  1585. /* skip the flush */
  1586. }
  1587. static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
  1588. {
  1589. struct ixgbe_q_vector *q_vector = data;
  1590. struct ixgbe_adapter *adapter = q_vector->adapter;
  1591. struct ixgbe_ring *tx_ring;
  1592. int i, r_idx;
  1593. if (!q_vector->txr_count)
  1594. return IRQ_HANDLED;
  1595. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1596. for (i = 0; i < q_vector->txr_count; i++) {
  1597. tx_ring = adapter->tx_ring[r_idx];
  1598. tx_ring->total_bytes = 0;
  1599. tx_ring->total_packets = 0;
  1600. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1601. r_idx + 1);
  1602. }
  1603. /* EIAM disabled interrupts (on this vector) for us */
  1604. napi_schedule(&q_vector->napi);
  1605. return IRQ_HANDLED;
  1606. }
  1607. /**
  1608. * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
  1609. * @irq: unused
  1610. * @data: pointer to our q_vector struct for this interrupt vector
  1611. **/
  1612. static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
  1613. {
  1614. struct ixgbe_q_vector *q_vector = data;
  1615. struct ixgbe_adapter *adapter = q_vector->adapter;
  1616. struct ixgbe_ring *rx_ring;
  1617. int r_idx;
  1618. int i;
  1619. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1620. for (i = 0; i < q_vector->rxr_count; i++) {
  1621. rx_ring = adapter->rx_ring[r_idx];
  1622. rx_ring->total_bytes = 0;
  1623. rx_ring->total_packets = 0;
  1624. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1625. r_idx + 1);
  1626. }
  1627. if (!q_vector->rxr_count)
  1628. return IRQ_HANDLED;
  1629. /* disable interrupts on this vector only */
  1630. /* EIAM disabled interrupts (on this vector) for us */
  1631. napi_schedule(&q_vector->napi);
  1632. return IRQ_HANDLED;
  1633. }
  1634. static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
  1635. {
  1636. struct ixgbe_q_vector *q_vector = data;
  1637. struct ixgbe_adapter *adapter = q_vector->adapter;
  1638. struct ixgbe_ring *ring;
  1639. int r_idx;
  1640. int i;
  1641. if (!q_vector->txr_count && !q_vector->rxr_count)
  1642. return IRQ_HANDLED;
  1643. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1644. for (i = 0; i < q_vector->txr_count; i++) {
  1645. ring = adapter->tx_ring[r_idx];
  1646. ring->total_bytes = 0;
  1647. ring->total_packets = 0;
  1648. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1649. r_idx + 1);
  1650. }
  1651. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1652. for (i = 0; i < q_vector->rxr_count; i++) {
  1653. ring = adapter->rx_ring[r_idx];
  1654. ring->total_bytes = 0;
  1655. ring->total_packets = 0;
  1656. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1657. r_idx + 1);
  1658. }
  1659. /* EIAM disabled interrupts (on this vector) for us */
  1660. napi_schedule(&q_vector->napi);
  1661. return IRQ_HANDLED;
  1662. }
  1663. /**
  1664. * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
  1665. * @napi: napi struct with our devices info in it
  1666. * @budget: amount of work driver is allowed to do this pass, in packets
  1667. *
  1668. * This function is optimized for cleaning one queue only on a single
  1669. * q_vector!!!
  1670. **/
  1671. static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
  1672. {
  1673. struct ixgbe_q_vector *q_vector =
  1674. container_of(napi, struct ixgbe_q_vector, napi);
  1675. struct ixgbe_adapter *adapter = q_vector->adapter;
  1676. struct ixgbe_ring *rx_ring = NULL;
  1677. int work_done = 0;
  1678. long r_idx;
  1679. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1680. rx_ring = adapter->rx_ring[r_idx];
  1681. #ifdef CONFIG_IXGBE_DCA
  1682. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1683. ixgbe_update_rx_dca(adapter, rx_ring);
  1684. #endif
  1685. ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
  1686. /* If all Rx work done, exit the polling mode */
  1687. if (work_done < budget) {
  1688. napi_complete(napi);
  1689. if (adapter->rx_itr_setting & 1)
  1690. ixgbe_set_itr_msix(q_vector);
  1691. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1692. ixgbe_irq_enable_queues(adapter,
  1693. ((u64)1 << q_vector->v_idx));
  1694. }
  1695. return work_done;
  1696. }
  1697. /**
  1698. * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
  1699. * @napi: napi struct with our devices info in it
  1700. * @budget: amount of work driver is allowed to do this pass, in packets
  1701. *
  1702. * This function will clean more than one rx queue associated with a
  1703. * q_vector.
  1704. **/
  1705. static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
  1706. {
  1707. struct ixgbe_q_vector *q_vector =
  1708. container_of(napi, struct ixgbe_q_vector, napi);
  1709. struct ixgbe_adapter *adapter = q_vector->adapter;
  1710. struct ixgbe_ring *ring = NULL;
  1711. int work_done = 0, i;
  1712. long r_idx;
  1713. bool tx_clean_complete = true;
  1714. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1715. for (i = 0; i < q_vector->txr_count; i++) {
  1716. ring = adapter->tx_ring[r_idx];
  1717. #ifdef CONFIG_IXGBE_DCA
  1718. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1719. ixgbe_update_tx_dca(adapter, ring);
  1720. #endif
  1721. tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
  1722. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1723. r_idx + 1);
  1724. }
  1725. /* attempt to distribute budget to each queue fairly, but don't allow
  1726. * the budget to go below 1 because we'll exit polling */
  1727. budget /= (q_vector->rxr_count ?: 1);
  1728. budget = max(budget, 1);
  1729. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1730. for (i = 0; i < q_vector->rxr_count; i++) {
  1731. ring = adapter->rx_ring[r_idx];
  1732. #ifdef CONFIG_IXGBE_DCA
  1733. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1734. ixgbe_update_rx_dca(adapter, ring);
  1735. #endif
  1736. ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
  1737. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1738. r_idx + 1);
  1739. }
  1740. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1741. ring = adapter->rx_ring[r_idx];
  1742. /* If all Rx work done, exit the polling mode */
  1743. if (work_done < budget) {
  1744. napi_complete(napi);
  1745. if (adapter->rx_itr_setting & 1)
  1746. ixgbe_set_itr_msix(q_vector);
  1747. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1748. ixgbe_irq_enable_queues(adapter,
  1749. ((u64)1 << q_vector->v_idx));
  1750. return 0;
  1751. }
  1752. return work_done;
  1753. }
  1754. /**
  1755. * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
  1756. * @napi: napi struct with our devices info in it
  1757. * @budget: amount of work driver is allowed to do this pass, in packets
  1758. *
  1759. * This function is optimized for cleaning one queue only on a single
  1760. * q_vector!!!
  1761. **/
  1762. static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
  1763. {
  1764. struct ixgbe_q_vector *q_vector =
  1765. container_of(napi, struct ixgbe_q_vector, napi);
  1766. struct ixgbe_adapter *adapter = q_vector->adapter;
  1767. struct ixgbe_ring *tx_ring = NULL;
  1768. int work_done = 0;
  1769. long r_idx;
  1770. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1771. tx_ring = adapter->tx_ring[r_idx];
  1772. #ifdef CONFIG_IXGBE_DCA
  1773. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1774. ixgbe_update_tx_dca(adapter, tx_ring);
  1775. #endif
  1776. if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
  1777. work_done = budget;
  1778. /* If all Tx work done, exit the polling mode */
  1779. if (work_done < budget) {
  1780. napi_complete(napi);
  1781. if (adapter->tx_itr_setting & 1)
  1782. ixgbe_set_itr_msix(q_vector);
  1783. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1784. ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
  1785. }
  1786. return work_done;
  1787. }
  1788. static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
  1789. int r_idx)
  1790. {
  1791. struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
  1792. set_bit(r_idx, q_vector->rxr_idx);
  1793. q_vector->rxr_count++;
  1794. }
  1795. static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
  1796. int t_idx)
  1797. {
  1798. struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
  1799. set_bit(t_idx, q_vector->txr_idx);
  1800. q_vector->txr_count++;
  1801. }
  1802. /**
  1803. * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
  1804. * @adapter: board private structure to initialize
  1805. * @vectors: allotted vector count for descriptor rings
  1806. *
  1807. * This function maps descriptor rings to the queue-specific vectors
  1808. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  1809. * one vector per ring/queue, but on a constrained vector budget, we
  1810. * group the rings as "efficiently" as possible. You would add new
  1811. * mapping configurations in here.
  1812. **/
  1813. static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
  1814. int vectors)
  1815. {
  1816. int v_start = 0;
  1817. int rxr_idx = 0, txr_idx = 0;
  1818. int rxr_remaining = adapter->num_rx_queues;
  1819. int txr_remaining = adapter->num_tx_queues;
  1820. int i, j;
  1821. int rqpv, tqpv;
  1822. int err = 0;
  1823. /* No mapping required if MSI-X is disabled. */
  1824. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  1825. goto out;
  1826. /*
  1827. * The ideal configuration...
  1828. * We have enough vectors to map one per queue.
  1829. */
  1830. if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
  1831. for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
  1832. map_vector_to_rxq(adapter, v_start, rxr_idx);
  1833. for (; txr_idx < txr_remaining; v_start++, txr_idx++)
  1834. map_vector_to_txq(adapter, v_start, txr_idx);
  1835. goto out;
  1836. }
  1837. /*
  1838. * If we don't have enough vectors for a 1-to-1
  1839. * mapping, we'll have to group them so there are
  1840. * multiple queues per vector.
  1841. */
  1842. /* Re-adjusting *qpv takes care of the remainder. */
  1843. for (i = v_start; i < vectors; i++) {
  1844. rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
  1845. for (j = 0; j < rqpv; j++) {
  1846. map_vector_to_rxq(adapter, i, rxr_idx);
  1847. rxr_idx++;
  1848. rxr_remaining--;
  1849. }
  1850. }
  1851. for (i = v_start; i < vectors; i++) {
  1852. tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
  1853. for (j = 0; j < tqpv; j++) {
  1854. map_vector_to_txq(adapter, i, txr_idx);
  1855. txr_idx++;
  1856. txr_remaining--;
  1857. }
  1858. }
  1859. out:
  1860. return err;
  1861. }
  1862. /**
  1863. * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
  1864. * @adapter: board private structure
  1865. *
  1866. * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
  1867. * interrupts from the kernel.
  1868. **/
  1869. static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
  1870. {
  1871. struct net_device *netdev = adapter->netdev;
  1872. irqreturn_t (*handler)(int, void *);
  1873. int i, vector, q_vectors, err;
  1874. int ri=0, ti=0;
  1875. /* Decrement for Other and TCP Timer vectors */
  1876. q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1877. /* Map the Tx/Rx rings to the vectors we were allotted. */
  1878. err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
  1879. if (err)
  1880. goto out;
  1881. #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
  1882. (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
  1883. &ixgbe_msix_clean_many)
  1884. for (vector = 0; vector < q_vectors; vector++) {
  1885. handler = SET_HANDLER(adapter->q_vector[vector]);
  1886. if(handler == &ixgbe_msix_clean_rx) {
  1887. sprintf(adapter->name[vector], "%s-%s-%d",
  1888. netdev->name, "rx", ri++);
  1889. }
  1890. else if(handler == &ixgbe_msix_clean_tx) {
  1891. sprintf(adapter->name[vector], "%s-%s-%d",
  1892. netdev->name, "tx", ti++);
  1893. }
  1894. else
  1895. sprintf(adapter->name[vector], "%s-%s-%d",
  1896. netdev->name, "TxRx", vector);
  1897. err = request_irq(adapter->msix_entries[vector].vector,
  1898. handler, 0, adapter->name[vector],
  1899. adapter->q_vector[vector]);
  1900. if (err) {
  1901. e_err(probe, "request_irq failed for MSIX interrupt "
  1902. "Error: %d\n", err);
  1903. goto free_queue_irqs;
  1904. }
  1905. }
  1906. sprintf(adapter->name[vector], "%s:lsc", netdev->name);
  1907. err = request_irq(adapter->msix_entries[vector].vector,
  1908. ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
  1909. if (err) {
  1910. e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
  1911. goto free_queue_irqs;
  1912. }
  1913. return 0;
  1914. free_queue_irqs:
  1915. for (i = vector - 1; i >= 0; i--)
  1916. free_irq(adapter->msix_entries[--vector].vector,
  1917. adapter->q_vector[i]);
  1918. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  1919. pci_disable_msix(adapter->pdev);
  1920. kfree(adapter->msix_entries);
  1921. adapter->msix_entries = NULL;
  1922. out:
  1923. return err;
  1924. }
  1925. static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
  1926. {
  1927. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  1928. u8 current_itr;
  1929. u32 new_itr = q_vector->eitr;
  1930. struct ixgbe_ring *rx_ring = adapter->rx_ring[0];
  1931. struct ixgbe_ring *tx_ring = adapter->tx_ring[0];
  1932. q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
  1933. q_vector->tx_itr,
  1934. tx_ring->total_packets,
  1935. tx_ring->total_bytes);
  1936. q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
  1937. q_vector->rx_itr,
  1938. rx_ring->total_packets,
  1939. rx_ring->total_bytes);
  1940. current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
  1941. switch (current_itr) {
  1942. /* counts and packets in update_itr are dependent on these numbers */
  1943. case lowest_latency:
  1944. new_itr = 100000;
  1945. break;
  1946. case low_latency:
  1947. new_itr = 20000; /* aka hwitr = ~200 */
  1948. break;
  1949. case bulk_latency:
  1950. new_itr = 8000;
  1951. break;
  1952. default:
  1953. break;
  1954. }
  1955. if (new_itr != q_vector->eitr) {
  1956. /* do an exponential smoothing */
  1957. new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
  1958. /* save the algorithm value here, not the smoothed one */
  1959. q_vector->eitr = new_itr;
  1960. ixgbe_write_eitr(q_vector);
  1961. }
  1962. }
  1963. /**
  1964. * ixgbe_irq_enable - Enable default interrupt generation settings
  1965. * @adapter: board private structure
  1966. **/
  1967. static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
  1968. {
  1969. u32 mask;
  1970. mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
  1971. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
  1972. mask |= IXGBE_EIMS_GPI_SDP0;
  1973. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  1974. mask |= IXGBE_EIMS_GPI_SDP1;
  1975. if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  1976. mask |= IXGBE_EIMS_ECC;
  1977. mask |= IXGBE_EIMS_GPI_SDP1;
  1978. mask |= IXGBE_EIMS_GPI_SDP2;
  1979. if (adapter->num_vfs)
  1980. mask |= IXGBE_EIMS_MAILBOX;
  1981. }
  1982. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  1983. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  1984. mask |= IXGBE_EIMS_FLOW_DIR;
  1985. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  1986. ixgbe_irq_enable_queues(adapter, ~0);
  1987. IXGBE_WRITE_FLUSH(&adapter->hw);
  1988. if (adapter->num_vfs > 32) {
  1989. u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
  1990. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
  1991. }
  1992. }
  1993. /**
  1994. * ixgbe_intr - legacy mode Interrupt Handler
  1995. * @irq: interrupt number
  1996. * @data: pointer to a network interface device structure
  1997. **/
  1998. static irqreturn_t ixgbe_intr(int irq, void *data)
  1999. {
  2000. struct net_device *netdev = data;
  2001. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2002. struct ixgbe_hw *hw = &adapter->hw;
  2003. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  2004. u32 eicr;
  2005. /*
  2006. * Workaround for silicon errata. Mask the interrupts
  2007. * before the read of EICR.
  2008. */
  2009. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  2010. /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
  2011. * therefore no explict interrupt disable is necessary */
  2012. eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
  2013. if (!eicr) {
  2014. /* shared interrupt alert!
  2015. * make sure interrupts are enabled because the read will
  2016. * have disabled interrupts due to EIAM */
  2017. ixgbe_irq_enable(adapter);
  2018. return IRQ_NONE; /* Not our interrupt */
  2019. }
  2020. if (eicr & IXGBE_EICR_LSC)
  2021. ixgbe_check_lsc(adapter);
  2022. if (hw->mac.type == ixgbe_mac_82599EB)
  2023. ixgbe_check_sfp_event(adapter, eicr);
  2024. ixgbe_check_fan_failure(adapter, eicr);
  2025. if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
  2026. ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)))
  2027. schedule_work(&adapter->check_overtemp_task);
  2028. if (napi_schedule_prep(&(q_vector->napi))) {
  2029. adapter->tx_ring[0]->total_packets = 0;
  2030. adapter->tx_ring[0]->total_bytes = 0;
  2031. adapter->rx_ring[0]->total_packets = 0;
  2032. adapter->rx_ring[0]->total_bytes = 0;
  2033. /* would disable interrupts here but EIAM disabled it */
  2034. __napi_schedule(&(q_vector->napi));
  2035. }
  2036. return IRQ_HANDLED;
  2037. }
  2038. static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
  2039. {
  2040. int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  2041. for (i = 0; i < q_vectors; i++) {
  2042. struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
  2043. bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
  2044. bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
  2045. q_vector->rxr_count = 0;
  2046. q_vector->txr_count = 0;
  2047. }
  2048. }
  2049. /**
  2050. * ixgbe_request_irq - initialize interrupts
  2051. * @adapter: board private structure
  2052. *
  2053. * Attempts to configure interrupts using the best available
  2054. * capabilities of the hardware and kernel.
  2055. **/
  2056. static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
  2057. {
  2058. struct net_device *netdev = adapter->netdev;
  2059. int err;
  2060. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2061. err = ixgbe_request_msix_irqs(adapter);
  2062. } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
  2063. err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
  2064. netdev->name, netdev);
  2065. } else {
  2066. err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
  2067. netdev->name, netdev);
  2068. }
  2069. if (err)
  2070. e_err(probe, "request_irq failed, Error %d\n", err);
  2071. return err;
  2072. }
  2073. static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
  2074. {
  2075. struct net_device *netdev = adapter->netdev;
  2076. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2077. int i, q_vectors;
  2078. q_vectors = adapter->num_msix_vectors;
  2079. i = q_vectors - 1;
  2080. free_irq(adapter->msix_entries[i].vector, netdev);
  2081. i--;
  2082. for (; i >= 0; i--) {
  2083. free_irq(adapter->msix_entries[i].vector,
  2084. adapter->q_vector[i]);
  2085. }
  2086. ixgbe_reset_q_vectors(adapter);
  2087. } else {
  2088. free_irq(adapter->pdev->irq, netdev);
  2089. }
  2090. }
  2091. /**
  2092. * ixgbe_irq_disable - Mask off interrupt generation on the NIC
  2093. * @adapter: board private structure
  2094. **/
  2095. static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
  2096. {
  2097. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  2098. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
  2099. } else {
  2100. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
  2101. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
  2102. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
  2103. if (adapter->num_vfs > 32)
  2104. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
  2105. }
  2106. IXGBE_WRITE_FLUSH(&adapter->hw);
  2107. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2108. int i;
  2109. for (i = 0; i < adapter->num_msix_vectors; i++)
  2110. synchronize_irq(adapter->msix_entries[i].vector);
  2111. } else {
  2112. synchronize_irq(adapter->pdev->irq);
  2113. }
  2114. }
  2115. /**
  2116. * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
  2117. *
  2118. **/
  2119. static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
  2120. {
  2121. struct ixgbe_hw *hw = &adapter->hw;
  2122. IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
  2123. EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
  2124. ixgbe_set_ivar(adapter, 0, 0, 0);
  2125. ixgbe_set_ivar(adapter, 1, 0, 0);
  2126. map_vector_to_rxq(adapter, 0, 0);
  2127. map_vector_to_txq(adapter, 0, 0);
  2128. e_info(hw, "Legacy interrupt IVAR setup done\n");
  2129. }
  2130. /**
  2131. * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
  2132. * @adapter: board private structure
  2133. * @ring: structure containing ring specific data
  2134. *
  2135. * Configure the Tx descriptor ring after a reset.
  2136. **/
  2137. static void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
  2138. struct ixgbe_ring *ring)
  2139. {
  2140. struct ixgbe_hw *hw = &adapter->hw;
  2141. u64 tdba = ring->dma;
  2142. u16 reg_idx = ring->reg_idx;
  2143. IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
  2144. (tdba & DMA_BIT_MASK(32)));
  2145. IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
  2146. IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
  2147. ring->count * sizeof(union ixgbe_adv_tx_desc));
  2148. IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
  2149. IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
  2150. ring->head = IXGBE_TDH(reg_idx);
  2151. ring->tail = IXGBE_TDT(reg_idx);
  2152. }
  2153. static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
  2154. {
  2155. struct ixgbe_hw *hw = &adapter->hw;
  2156. u32 rttdcs;
  2157. u32 mask;
  2158. if (hw->mac.type == ixgbe_mac_82598EB)
  2159. return;
  2160. /* disable the arbiter while setting MTQC */
  2161. rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
  2162. rttdcs |= IXGBE_RTTDCS_ARBDIS;
  2163. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  2164. /* set transmit pool layout */
  2165. mask = (IXGBE_FLAG_SRIOV_ENABLED | IXGBE_FLAG_DCB_ENABLED);
  2166. switch (adapter->flags & mask) {
  2167. case (IXGBE_FLAG_SRIOV_ENABLED):
  2168. IXGBE_WRITE_REG(hw, IXGBE_MTQC,
  2169. (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
  2170. break;
  2171. case (IXGBE_FLAG_DCB_ENABLED):
  2172. /* We enable 8 traffic classes, DCB only */
  2173. IXGBE_WRITE_REG(hw, IXGBE_MTQC,
  2174. (IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ));
  2175. break;
  2176. default:
  2177. IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
  2178. break;
  2179. }
  2180. /* re-enable the arbiter */
  2181. rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
  2182. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  2183. }
  2184. /**
  2185. * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
  2186. * @adapter: board private structure
  2187. *
  2188. * Configure the Tx unit of the MAC after a reset.
  2189. **/
  2190. static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
  2191. {
  2192. u32 i;
  2193. /* Setup the HW Tx Head and Tail descriptor pointers */
  2194. for (i = 0; i < adapter->num_tx_queues; i++)
  2195. ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
  2196. ixgbe_setup_mtqc(adapter);
  2197. }
  2198. #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
  2199. static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
  2200. struct ixgbe_ring *rx_ring)
  2201. {
  2202. u32 srrctl;
  2203. int index;
  2204. struct ixgbe_ring_feature *feature = adapter->ring_feature;
  2205. index = rx_ring->reg_idx;
  2206. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  2207. unsigned long mask;
  2208. mask = (unsigned long) feature[RING_F_RSS].mask;
  2209. index = index & mask;
  2210. }
  2211. srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
  2212. srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
  2213. srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
  2214. srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
  2215. IXGBE_SRRCTL_BSIZEHDR_MASK;
  2216. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  2217. #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
  2218. srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  2219. #else
  2220. srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  2221. #endif
  2222. srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
  2223. } else {
  2224. srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
  2225. IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  2226. srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
  2227. }
  2228. IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
  2229. }
  2230. static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
  2231. {
  2232. struct ixgbe_hw *hw = &adapter->hw;
  2233. static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
  2234. 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
  2235. 0x6A3E67EA, 0x14364D17, 0x3BED200D};
  2236. u32 mrqc = 0, reta = 0;
  2237. u32 rxcsum;
  2238. int i, j;
  2239. int mask;
  2240. /* Fill out hash function seeds */
  2241. for (i = 0; i < 10; i++)
  2242. IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
  2243. /* Fill out redirection table */
  2244. for (i = 0, j = 0; i < 128; i++, j++) {
  2245. if (j == adapter->ring_feature[RING_F_RSS].indices)
  2246. j = 0;
  2247. /* reta = 4-byte sliding window of
  2248. * 0x00..(indices-1)(indices-1)00..etc. */
  2249. reta = (reta << 8) | (j * 0x11);
  2250. if ((i & 3) == 3)
  2251. IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
  2252. }
  2253. /* Disable indicating checksum in descriptor, enables RSS hash */
  2254. rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
  2255. rxcsum |= IXGBE_RXCSUM_PCSD;
  2256. IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
  2257. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  2258. mask = adapter->flags & IXGBE_FLAG_RSS_ENABLED;
  2259. else
  2260. mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
  2261. #ifdef CONFIG_IXGBE_DCB
  2262. | IXGBE_FLAG_DCB_ENABLED
  2263. #endif
  2264. | IXGBE_FLAG_SRIOV_ENABLED
  2265. );
  2266. switch (mask) {
  2267. case (IXGBE_FLAG_RSS_ENABLED):
  2268. mrqc = IXGBE_MRQC_RSSEN;
  2269. break;
  2270. case (IXGBE_FLAG_SRIOV_ENABLED):
  2271. mrqc = IXGBE_MRQC_VMDQEN;
  2272. break;
  2273. #ifdef CONFIG_IXGBE_DCB
  2274. case (IXGBE_FLAG_DCB_ENABLED):
  2275. mrqc = IXGBE_MRQC_RT8TCEN;
  2276. break;
  2277. #endif /* CONFIG_IXGBE_DCB */
  2278. default:
  2279. break;
  2280. }
  2281. /* Perform hash on these packet types */
  2282. mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
  2283. | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
  2284. | IXGBE_MRQC_RSS_FIELD_IPV6
  2285. | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
  2286. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  2287. }
  2288. /**
  2289. * ixgbe_configure_rscctl - enable RSC for the indicated ring
  2290. * @adapter: address of board private structure
  2291. * @index: index of ring to set
  2292. **/
  2293. static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
  2294. struct ixgbe_ring *ring)
  2295. {
  2296. struct ixgbe_hw *hw = &adapter->hw;
  2297. u32 rscctrl;
  2298. int rx_buf_len;
  2299. u16 reg_idx = ring->reg_idx;
  2300. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
  2301. return;
  2302. rx_buf_len = ring->rx_buf_len;
  2303. rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
  2304. rscctrl |= IXGBE_RSCCTL_RSCEN;
  2305. /*
  2306. * we must limit the number of descriptors so that the
  2307. * total size of max desc * buf_len is not greater
  2308. * than 65535
  2309. */
  2310. if (ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  2311. #if (MAX_SKB_FRAGS > 16)
  2312. rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
  2313. #elif (MAX_SKB_FRAGS > 8)
  2314. rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
  2315. #elif (MAX_SKB_FRAGS > 4)
  2316. rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
  2317. #else
  2318. rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
  2319. #endif
  2320. } else {
  2321. if (rx_buf_len < IXGBE_RXBUFFER_4096)
  2322. rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
  2323. else if (rx_buf_len < IXGBE_RXBUFFER_8192)
  2324. rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
  2325. else
  2326. rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
  2327. }
  2328. IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
  2329. }
  2330. static void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
  2331. struct ixgbe_ring *ring)
  2332. {
  2333. struct ixgbe_hw *hw = &adapter->hw;
  2334. u64 rdba = ring->dma;
  2335. u16 reg_idx = ring->reg_idx;
  2336. IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
  2337. IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
  2338. IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
  2339. ring->count * sizeof(union ixgbe_adv_rx_desc));
  2340. IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
  2341. IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
  2342. ring->head = IXGBE_RDH(reg_idx);
  2343. ring->tail = IXGBE_RDT(reg_idx);
  2344. }
  2345. static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
  2346. {
  2347. struct ixgbe_hw *hw = &adapter->hw;
  2348. int p;
  2349. /* PSRTYPE must be initialized in non 82598 adapters */
  2350. u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
  2351. IXGBE_PSRTYPE_UDPHDR |
  2352. IXGBE_PSRTYPE_IPV4HDR |
  2353. IXGBE_PSRTYPE_L2HDR |
  2354. IXGBE_PSRTYPE_IPV6HDR;
  2355. if (hw->mac.type == ixgbe_mac_82598EB)
  2356. return;
  2357. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
  2358. psrtype |= (adapter->num_rx_queues_per_pool << 29);
  2359. for (p = 0; p < adapter->num_rx_pools; p++)
  2360. IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
  2361. psrtype);
  2362. }
  2363. static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
  2364. {
  2365. struct ixgbe_hw *hw = &adapter->hw;
  2366. u32 gcr_ext;
  2367. u32 vt_reg_bits;
  2368. u32 reg_offset, vf_shift;
  2369. u32 vmdctl;
  2370. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  2371. return;
  2372. vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  2373. vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
  2374. vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
  2375. IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
  2376. vf_shift = adapter->num_vfs % 32;
  2377. reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
  2378. /* Enable only the PF's pool for Tx/Rx */
  2379. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
  2380. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
  2381. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
  2382. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
  2383. IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
  2384. /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
  2385. hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
  2386. /*
  2387. * Set up VF register offsets for selected VT Mode,
  2388. * i.e. 32 or 64 VFs for SR-IOV
  2389. */
  2390. gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
  2391. gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
  2392. gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
  2393. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
  2394. /* enable Tx loopback for VF/PF communication */
  2395. IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
  2396. }
  2397. static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
  2398. {
  2399. struct ixgbe_hw *hw = &adapter->hw;
  2400. struct net_device *netdev = adapter->netdev;
  2401. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  2402. int rx_buf_len;
  2403. struct ixgbe_ring *rx_ring;
  2404. int i;
  2405. u32 mhadd, hlreg0;
  2406. /* Decide whether to use packet split mode or not */
  2407. /* Do not use packet split if we're in SR-IOV Mode */
  2408. if (!adapter->num_vfs)
  2409. adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
  2410. /* Set the RX buffer length according to the mode */
  2411. if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
  2412. rx_buf_len = IXGBE_RX_HDR_SIZE;
  2413. } else {
  2414. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
  2415. (netdev->mtu <= ETH_DATA_LEN))
  2416. rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
  2417. else
  2418. rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
  2419. }
  2420. #ifdef IXGBE_FCOE
  2421. /* adjust max frame to be able to do baby jumbo for FCoE */
  2422. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
  2423. (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
  2424. max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  2425. #endif /* IXGBE_FCOE */
  2426. mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
  2427. if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
  2428. mhadd &= ~IXGBE_MHADD_MFS_MASK;
  2429. mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
  2430. IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
  2431. }
  2432. hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  2433. /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
  2434. hlreg0 |= IXGBE_HLREG0_JUMBOEN;
  2435. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
  2436. /*
  2437. * Setup the HW Rx Head and Tail Descriptor Pointers and
  2438. * the Base and Length of the Rx Descriptor Ring
  2439. */
  2440. for (i = 0; i < adapter->num_rx_queues; i++) {
  2441. rx_ring = adapter->rx_ring[i];
  2442. rx_ring->rx_buf_len = rx_buf_len;
  2443. if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
  2444. rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED;
  2445. else
  2446. rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
  2447. #ifdef IXGBE_FCOE
  2448. if (netdev->features & NETIF_F_FCOE_MTU)
  2449. {
  2450. struct ixgbe_ring_feature *f;
  2451. f = &adapter->ring_feature[RING_F_FCOE];
  2452. if ((i >= f->mask) && (i < f->mask + f->indices)) {
  2453. rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
  2454. if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
  2455. rx_ring->rx_buf_len =
  2456. IXGBE_FCOE_JUMBO_FRAME_SIZE;
  2457. }
  2458. }
  2459. #endif /* IXGBE_FCOE */
  2460. }
  2461. }
  2462. static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
  2463. {
  2464. struct ixgbe_hw *hw = &adapter->hw;
  2465. u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  2466. switch (hw->mac.type) {
  2467. case ixgbe_mac_82598EB:
  2468. /*
  2469. * For VMDq support of different descriptor types or
  2470. * buffer sizes through the use of multiple SRRCTL
  2471. * registers, RDRXCTL.MVMEN must be set to 1
  2472. *
  2473. * also, the manual doesn't mention it clearly but DCA hints
  2474. * will only use queue 0's tags unless this bit is set. Side
  2475. * effects of setting this bit are only that SRRCTL must be
  2476. * fully programmed [0..15]
  2477. */
  2478. rdrxctl |= IXGBE_RDRXCTL_MVMEN;
  2479. break;
  2480. case ixgbe_mac_82599EB:
  2481. /* Disable RSC for ACK packets */
  2482. IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
  2483. (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
  2484. rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
  2485. /* hardware requires some bits to be set by default */
  2486. rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
  2487. rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
  2488. break;
  2489. default:
  2490. /* We should do nothing since we don't know this hardware */
  2491. return;
  2492. }
  2493. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
  2494. }
  2495. /**
  2496. * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
  2497. * @adapter: board private structure
  2498. *
  2499. * Configure the Rx unit of the MAC after a reset.
  2500. **/
  2501. static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
  2502. {
  2503. struct ixgbe_hw *hw = &adapter->hw;
  2504. struct ixgbe_ring *rx_ring;
  2505. int i;
  2506. u32 rxctrl;
  2507. /* disable receives while setting up the descriptors */
  2508. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  2509. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
  2510. ixgbe_setup_psrtype(adapter);
  2511. ixgbe_setup_rdrxctl(adapter);
  2512. /* Program MRQC for the distribution of queues */
  2513. ixgbe_setup_mrqc(adapter);
  2514. ixgbe_configure_virtualization(adapter);
  2515. /* set_rx_buffer_len must be called before ring initialization */
  2516. ixgbe_set_rx_buffer_len(adapter);
  2517. /*
  2518. * Setup the HW Rx Head and Tail Descriptor Pointers and
  2519. * the Base and Length of the Rx Descriptor Ring
  2520. */
  2521. for (i = 0; i < adapter->num_rx_queues; i++) {
  2522. rx_ring = adapter->rx_ring[i];
  2523. ixgbe_configure_rx_ring(adapter, rx_ring);
  2524. ixgbe_configure_srrctl(adapter, rx_ring);
  2525. ixgbe_configure_rscctl(adapter, rx_ring);
  2526. }
  2527. }
  2528. static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  2529. {
  2530. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2531. struct ixgbe_hw *hw = &adapter->hw;
  2532. int pool_ndx = adapter->num_vfs;
  2533. /* add VID to filter table */
  2534. hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
  2535. }
  2536. static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  2537. {
  2538. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2539. struct ixgbe_hw *hw = &adapter->hw;
  2540. int pool_ndx = adapter->num_vfs;
  2541. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2542. ixgbe_irq_disable(adapter);
  2543. vlan_group_set_device(adapter->vlgrp, vid, NULL);
  2544. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2545. ixgbe_irq_enable(adapter);
  2546. /* remove VID from filter table */
  2547. hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
  2548. }
  2549. /**
  2550. * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
  2551. * @adapter: driver data
  2552. */
  2553. static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
  2554. {
  2555. struct ixgbe_hw *hw = &adapter->hw;
  2556. u32 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  2557. int i, j;
  2558. switch (hw->mac.type) {
  2559. case ixgbe_mac_82598EB:
  2560. vlnctrl &= ~IXGBE_VLNCTRL_VFE;
  2561. #ifdef CONFIG_IXGBE_DCB
  2562. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
  2563. vlnctrl &= ~IXGBE_VLNCTRL_VME;
  2564. #endif
  2565. vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
  2566. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  2567. break;
  2568. case ixgbe_mac_82599EB:
  2569. vlnctrl &= ~IXGBE_VLNCTRL_VFE;
  2570. vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
  2571. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  2572. #ifdef CONFIG_IXGBE_DCB
  2573. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
  2574. break;
  2575. #endif
  2576. for (i = 0; i < adapter->num_rx_queues; i++) {
  2577. j = adapter->rx_ring[i]->reg_idx;
  2578. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  2579. vlnctrl &= ~IXGBE_RXDCTL_VME;
  2580. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  2581. }
  2582. break;
  2583. default:
  2584. break;
  2585. }
  2586. }
  2587. /**
  2588. * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
  2589. * @adapter: driver data
  2590. */
  2591. static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
  2592. {
  2593. struct ixgbe_hw *hw = &adapter->hw;
  2594. u32 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  2595. int i, j;
  2596. switch (hw->mac.type) {
  2597. case ixgbe_mac_82598EB:
  2598. vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
  2599. vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
  2600. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  2601. break;
  2602. case ixgbe_mac_82599EB:
  2603. vlnctrl |= IXGBE_VLNCTRL_VFE;
  2604. vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
  2605. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  2606. for (i = 0; i < adapter->num_rx_queues; i++) {
  2607. j = adapter->rx_ring[i]->reg_idx;
  2608. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  2609. vlnctrl |= IXGBE_RXDCTL_VME;
  2610. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  2611. }
  2612. break;
  2613. default:
  2614. break;
  2615. }
  2616. }
  2617. static void ixgbe_vlan_rx_register(struct net_device *netdev,
  2618. struct vlan_group *grp)
  2619. {
  2620. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2621. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2622. ixgbe_irq_disable(adapter);
  2623. adapter->vlgrp = grp;
  2624. /*
  2625. * For a DCB driver, always enable VLAN tag stripping so we can
  2626. * still receive traffic from a DCB-enabled host even if we're
  2627. * not in DCB mode.
  2628. */
  2629. ixgbe_vlan_filter_enable(adapter);
  2630. ixgbe_vlan_rx_add_vid(netdev, 0);
  2631. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2632. ixgbe_irq_enable(adapter);
  2633. }
  2634. static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
  2635. {
  2636. ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
  2637. if (adapter->vlgrp) {
  2638. u16 vid;
  2639. for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
  2640. if (!vlan_group_get_device(adapter->vlgrp, vid))
  2641. continue;
  2642. ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
  2643. }
  2644. }
  2645. }
  2646. /**
  2647. * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
  2648. * @netdev: network interface device structure
  2649. *
  2650. * Writes unicast address list to the RAR table.
  2651. * Returns: -ENOMEM on failure/insufficient address space
  2652. * 0 on no addresses written
  2653. * X on writing X addresses to the RAR table
  2654. **/
  2655. static int ixgbe_write_uc_addr_list(struct net_device *netdev)
  2656. {
  2657. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2658. struct ixgbe_hw *hw = &adapter->hw;
  2659. unsigned int vfn = adapter->num_vfs;
  2660. unsigned int rar_entries = hw->mac.num_rar_entries - (vfn + 1);
  2661. int count = 0;
  2662. /* return ENOMEM indicating insufficient memory for addresses */
  2663. if (netdev_uc_count(netdev) > rar_entries)
  2664. return -ENOMEM;
  2665. if (!netdev_uc_empty(netdev) && rar_entries) {
  2666. struct netdev_hw_addr *ha;
  2667. /* return error if we do not support writing to RAR table */
  2668. if (!hw->mac.ops.set_rar)
  2669. return -ENOMEM;
  2670. netdev_for_each_uc_addr(ha, netdev) {
  2671. if (!rar_entries)
  2672. break;
  2673. hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
  2674. vfn, IXGBE_RAH_AV);
  2675. count++;
  2676. }
  2677. }
  2678. /* write the addresses in reverse order to avoid write combining */
  2679. for (; rar_entries > 0 ; rar_entries--)
  2680. hw->mac.ops.clear_rar(hw, rar_entries);
  2681. return count;
  2682. }
  2683. /**
  2684. * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
  2685. * @netdev: network interface device structure
  2686. *
  2687. * The set_rx_method entry point is called whenever the unicast/multicast
  2688. * address list or the network interface flags are updated. This routine is
  2689. * responsible for configuring the hardware for proper unicast, multicast and
  2690. * promiscuous mode.
  2691. **/
  2692. void ixgbe_set_rx_mode(struct net_device *netdev)
  2693. {
  2694. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2695. struct ixgbe_hw *hw = &adapter->hw;
  2696. u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
  2697. int count;
  2698. /* Check for Promiscuous and All Multicast modes */
  2699. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  2700. /* set all bits that we expect to always be set */
  2701. fctrl |= IXGBE_FCTRL_BAM;
  2702. fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
  2703. fctrl |= IXGBE_FCTRL_PMCF;
  2704. /* clear the bits we are changing the status of */
  2705. fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  2706. if (netdev->flags & IFF_PROMISC) {
  2707. hw->addr_ctrl.user_set_promisc = true;
  2708. fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  2709. vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
  2710. /* don't hardware filter vlans in promisc mode */
  2711. ixgbe_vlan_filter_disable(adapter);
  2712. } else {
  2713. if (netdev->flags & IFF_ALLMULTI) {
  2714. fctrl |= IXGBE_FCTRL_MPE;
  2715. vmolr |= IXGBE_VMOLR_MPE;
  2716. } else {
  2717. /*
  2718. * Write addresses to the MTA, if the attempt fails
  2719. * then we should just turn on promiscous mode so
  2720. * that we can at least receive multicast traffic
  2721. */
  2722. hw->mac.ops.update_mc_addr_list(hw, netdev);
  2723. vmolr |= IXGBE_VMOLR_ROMPE;
  2724. }
  2725. ixgbe_vlan_filter_enable(adapter);
  2726. hw->addr_ctrl.user_set_promisc = false;
  2727. /*
  2728. * Write addresses to available RAR registers, if there is not
  2729. * sufficient space to store all the addresses then enable
  2730. * unicast promiscous mode
  2731. */
  2732. count = ixgbe_write_uc_addr_list(netdev);
  2733. if (count < 0) {
  2734. fctrl |= IXGBE_FCTRL_UPE;
  2735. vmolr |= IXGBE_VMOLR_ROPE;
  2736. }
  2737. }
  2738. if (adapter->num_vfs) {
  2739. ixgbe_restore_vf_multicasts(adapter);
  2740. vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
  2741. ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
  2742. IXGBE_VMOLR_ROPE);
  2743. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
  2744. }
  2745. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  2746. }
  2747. static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
  2748. {
  2749. int q_idx;
  2750. struct ixgbe_q_vector *q_vector;
  2751. int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  2752. /* legacy and MSI only use one vector */
  2753. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  2754. q_vectors = 1;
  2755. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  2756. struct napi_struct *napi;
  2757. q_vector = adapter->q_vector[q_idx];
  2758. napi = &q_vector->napi;
  2759. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2760. if (!q_vector->rxr_count || !q_vector->txr_count) {
  2761. if (q_vector->txr_count == 1)
  2762. napi->poll = &ixgbe_clean_txonly;
  2763. else if (q_vector->rxr_count == 1)
  2764. napi->poll = &ixgbe_clean_rxonly;
  2765. }
  2766. }
  2767. napi_enable(napi);
  2768. }
  2769. }
  2770. static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
  2771. {
  2772. int q_idx;
  2773. struct ixgbe_q_vector *q_vector;
  2774. int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  2775. /* legacy and MSI only use one vector */
  2776. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  2777. q_vectors = 1;
  2778. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  2779. q_vector = adapter->q_vector[q_idx];
  2780. napi_disable(&q_vector->napi);
  2781. }
  2782. }
  2783. #ifdef CONFIG_IXGBE_DCB
  2784. /*
  2785. * ixgbe_configure_dcb - Configure DCB hardware
  2786. * @adapter: ixgbe adapter struct
  2787. *
  2788. * This is called by the driver on open to configure the DCB hardware.
  2789. * This is also called by the gennetlink interface when reconfiguring
  2790. * the DCB state.
  2791. */
  2792. static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
  2793. {
  2794. struct ixgbe_hw *hw = &adapter->hw;
  2795. u32 txdctl;
  2796. int i, j;
  2797. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
  2798. if (hw->mac.type == ixgbe_mac_82598EB)
  2799. netif_set_gso_max_size(adapter->netdev, 65536);
  2800. return;
  2801. }
  2802. if (hw->mac.type == ixgbe_mac_82598EB)
  2803. netif_set_gso_max_size(adapter->netdev, 32768);
  2804. ixgbe_dcb_check_config(&adapter->dcb_cfg);
  2805. ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
  2806. ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
  2807. /* reconfigure the hardware */
  2808. ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
  2809. for (i = 0; i < adapter->num_tx_queues; i++) {
  2810. j = adapter->tx_ring[i]->reg_idx;
  2811. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
  2812. /* PThresh workaround for Tx hang with DFP enabled. */
  2813. txdctl |= 32;
  2814. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
  2815. }
  2816. /* Enable VLAN tag insert/strip */
  2817. ixgbe_vlan_filter_enable(adapter);
  2818. hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
  2819. }
  2820. #endif
  2821. static void ixgbe_configure(struct ixgbe_adapter *adapter)
  2822. {
  2823. struct net_device *netdev = adapter->netdev;
  2824. struct ixgbe_hw *hw = &adapter->hw;
  2825. int i;
  2826. ixgbe_set_rx_mode(netdev);
  2827. ixgbe_restore_vlan(adapter);
  2828. #ifdef CONFIG_IXGBE_DCB
  2829. ixgbe_configure_dcb(adapter);
  2830. #endif
  2831. #ifdef IXGBE_FCOE
  2832. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  2833. ixgbe_configure_fcoe(adapter);
  2834. #endif /* IXGBE_FCOE */
  2835. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  2836. for (i = 0; i < adapter->num_tx_queues; i++)
  2837. adapter->tx_ring[i]->atr_sample_rate =
  2838. adapter->atr_sample_rate;
  2839. ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
  2840. } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
  2841. ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
  2842. }
  2843. ixgbe_configure_tx(adapter);
  2844. ixgbe_configure_rx(adapter);
  2845. for (i = 0; i < adapter->num_rx_queues; i++)
  2846. ixgbe_alloc_rx_buffers(adapter, adapter->rx_ring[i],
  2847. (adapter->rx_ring[i]->count - 1));
  2848. }
  2849. static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
  2850. {
  2851. switch (hw->phy.type) {
  2852. case ixgbe_phy_sfp_avago:
  2853. case ixgbe_phy_sfp_ftl:
  2854. case ixgbe_phy_sfp_intel:
  2855. case ixgbe_phy_sfp_unknown:
  2856. case ixgbe_phy_sfp_passive_tyco:
  2857. case ixgbe_phy_sfp_passive_unknown:
  2858. case ixgbe_phy_sfp_active_unknown:
  2859. case ixgbe_phy_sfp_ftl_active:
  2860. return true;
  2861. default:
  2862. return false;
  2863. }
  2864. }
  2865. /**
  2866. * ixgbe_sfp_link_config - set up SFP+ link
  2867. * @adapter: pointer to private adapter struct
  2868. **/
  2869. static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
  2870. {
  2871. struct ixgbe_hw *hw = &adapter->hw;
  2872. if (hw->phy.multispeed_fiber) {
  2873. /*
  2874. * In multispeed fiber setups, the device may not have
  2875. * had a physical connection when the driver loaded.
  2876. * If that's the case, the initial link configuration
  2877. * couldn't get the MAC into 10G or 1G mode, so we'll
  2878. * never have a link status change interrupt fire.
  2879. * We need to try and force an autonegotiation
  2880. * session, then bring up link.
  2881. */
  2882. hw->mac.ops.setup_sfp(hw);
  2883. if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
  2884. schedule_work(&adapter->multispeed_fiber_task);
  2885. } else {
  2886. /*
  2887. * Direct Attach Cu and non-multispeed fiber modules
  2888. * still need to be configured properly prior to
  2889. * attempting link.
  2890. */
  2891. if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
  2892. schedule_work(&adapter->sfp_config_module_task);
  2893. }
  2894. }
  2895. /**
  2896. * ixgbe_non_sfp_link_config - set up non-SFP+ link
  2897. * @hw: pointer to private hardware struct
  2898. *
  2899. * Returns 0 on success, negative on failure
  2900. **/
  2901. static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
  2902. {
  2903. u32 autoneg;
  2904. bool negotiation, link_up = false;
  2905. u32 ret = IXGBE_ERR_LINK_SETUP;
  2906. if (hw->mac.ops.check_link)
  2907. ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
  2908. if (ret)
  2909. goto link_cfg_out;
  2910. if (hw->mac.ops.get_link_capabilities)
  2911. ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
  2912. if (ret)
  2913. goto link_cfg_out;
  2914. if (hw->mac.ops.setup_link)
  2915. ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
  2916. link_cfg_out:
  2917. return ret;
  2918. }
  2919. #define IXGBE_MAX_RX_DESC_POLL 10
  2920. static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
  2921. int rxr)
  2922. {
  2923. int j = adapter->rx_ring[rxr]->reg_idx;
  2924. int k;
  2925. for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
  2926. if (IXGBE_READ_REG(&adapter->hw,
  2927. IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
  2928. break;
  2929. else
  2930. msleep(1);
  2931. }
  2932. if (k >= IXGBE_MAX_RX_DESC_POLL) {
  2933. e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
  2934. "the polling period\n", rxr);
  2935. }
  2936. ixgbe_release_rx_desc(&adapter->hw, adapter->rx_ring[rxr],
  2937. (adapter->rx_ring[rxr]->count - 1));
  2938. }
  2939. static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
  2940. {
  2941. struct ixgbe_hw *hw = &adapter->hw;
  2942. int i, j = 0;
  2943. int num_rx_rings = adapter->num_rx_queues;
  2944. int err;
  2945. u32 txdctl, rxdctl;
  2946. u32 dmatxctl;
  2947. u32 gpie;
  2948. u32 ctrl_ext;
  2949. ixgbe_get_hw_control(adapter);
  2950. if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
  2951. (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
  2952. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2953. gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
  2954. IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
  2955. } else {
  2956. /* MSI only */
  2957. gpie = 0;
  2958. }
  2959. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  2960. gpie &= ~IXGBE_GPIE_VTMODE_MASK;
  2961. gpie |= IXGBE_GPIE_VTMODE_64;
  2962. }
  2963. /* XXX: to interrupt immediately for EICS writes, enable this */
  2964. /* gpie |= IXGBE_GPIE_EIMEN; */
  2965. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  2966. }
  2967. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2968. /*
  2969. * use EIAM to auto-mask when MSI-X interrupt is asserted
  2970. * this saves a register write for every interrupt
  2971. */
  2972. switch (hw->mac.type) {
  2973. case ixgbe_mac_82598EB:
  2974. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  2975. break;
  2976. default:
  2977. case ixgbe_mac_82599EB:
  2978. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
  2979. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
  2980. break;
  2981. }
  2982. } else {
  2983. /* legacy interrupts, use EIAM to auto-mask when reading EICR,
  2984. * specifically only auto mask tx and rx interrupts */
  2985. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  2986. }
  2987. /* Enable Thermal over heat sensor interrupt */
  2988. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
  2989. gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
  2990. gpie |= IXGBE_SDP0_GPIEN;
  2991. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  2992. }
  2993. /* Enable fan failure interrupt if media type is copper */
  2994. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  2995. gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
  2996. gpie |= IXGBE_SDP1_GPIEN;
  2997. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  2998. }
  2999. if (hw->mac.type == ixgbe_mac_82599EB) {
  3000. gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
  3001. gpie |= IXGBE_SDP1_GPIEN;
  3002. gpie |= IXGBE_SDP2_GPIEN;
  3003. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  3004. }
  3005. if (hw->mac.type == ixgbe_mac_82599EB) {
  3006. /* DMATXCTL.EN must be set after all Tx queue config is done */
  3007. dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
  3008. dmatxctl |= IXGBE_DMATXCTL_TE;
  3009. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
  3010. }
  3011. for (i = 0; i < adapter->num_tx_queues; i++) {
  3012. j = adapter->tx_ring[i]->reg_idx;
  3013. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
  3014. if (adapter->rx_itr_setting == 0) {
  3015. /* cannot set wthresh when itr==0 */
  3016. txdctl &= ~0x007F0000;
  3017. } else {
  3018. /* enable WTHRESH=8 descriptors, to encourage burst writeback */
  3019. txdctl |= (8 << 16);
  3020. }
  3021. txdctl |= IXGBE_TXDCTL_ENABLE;
  3022. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
  3023. if (hw->mac.type == ixgbe_mac_82599EB) {
  3024. int wait_loop = 10;
  3025. /* poll for Tx Enable ready */
  3026. do {
  3027. msleep(1);
  3028. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
  3029. } while (--wait_loop &&
  3030. !(txdctl & IXGBE_TXDCTL_ENABLE));
  3031. if (!wait_loop)
  3032. e_err(drv, "Could not enable Tx Queue %d\n", j);
  3033. }
  3034. }
  3035. for (i = 0; i < num_rx_rings; i++) {
  3036. j = adapter->rx_ring[i]->reg_idx;
  3037. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  3038. /* enable PTHRESH=32 descriptors (half the internal cache)
  3039. * and HTHRESH=0 descriptors (to minimize latency on fetch),
  3040. * this also removes a pesky rx_no_buffer_count increment */
  3041. rxdctl |= 0x0020;
  3042. rxdctl |= IXGBE_RXDCTL_ENABLE;
  3043. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
  3044. if (hw->mac.type == ixgbe_mac_82599EB)
  3045. ixgbe_rx_desc_queue_enable(adapter, i);
  3046. }
  3047. /* enable all receives */
  3048. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  3049. if (hw->mac.type == ixgbe_mac_82598EB)
  3050. rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
  3051. else
  3052. rxdctl |= IXGBE_RXCTRL_RXEN;
  3053. hw->mac.ops.enable_rx_dma(hw, rxdctl);
  3054. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  3055. ixgbe_configure_msix(adapter);
  3056. else
  3057. ixgbe_configure_msi_and_legacy(adapter);
  3058. /* enable the optics */
  3059. if (hw->phy.multispeed_fiber)
  3060. hw->mac.ops.enable_tx_laser(hw);
  3061. clear_bit(__IXGBE_DOWN, &adapter->state);
  3062. ixgbe_napi_enable_all(adapter);
  3063. /* clear any pending interrupts, may auto mask */
  3064. IXGBE_READ_REG(hw, IXGBE_EICR);
  3065. ixgbe_irq_enable(adapter);
  3066. /*
  3067. * If this adapter has a fan, check to see if we had a failure
  3068. * before we enabled the interrupt.
  3069. */
  3070. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  3071. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  3072. if (esdp & IXGBE_ESDP_SDP1)
  3073. e_crit(drv, "Fan has stopped, replace the adapter\n");
  3074. }
  3075. /*
  3076. * For hot-pluggable SFP+ devices, a new SFP+ module may have
  3077. * arrived before interrupts were enabled but after probe. Such
  3078. * devices wouldn't have their type identified yet. We need to
  3079. * kick off the SFP+ module setup first, then try to bring up link.
  3080. * If we're not hot-pluggable SFP+, we just need to configure link
  3081. * and bring it up.
  3082. */
  3083. if (hw->phy.type == ixgbe_phy_unknown) {
  3084. err = hw->phy.ops.identify(hw);
  3085. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  3086. /*
  3087. * Take the device down and schedule the sfp tasklet
  3088. * which will unregister_netdev and log it.
  3089. */
  3090. ixgbe_down(adapter);
  3091. schedule_work(&adapter->sfp_config_module_task);
  3092. return err;
  3093. }
  3094. }
  3095. if (ixgbe_is_sfp(hw)) {
  3096. ixgbe_sfp_link_config(adapter);
  3097. } else {
  3098. err = ixgbe_non_sfp_link_config(hw);
  3099. if (err)
  3100. e_err(probe, "link_config FAILED %d\n", err);
  3101. }
  3102. for (i = 0; i < adapter->num_tx_queues; i++)
  3103. set_bit(__IXGBE_FDIR_INIT_DONE,
  3104. &(adapter->tx_ring[i]->reinit_state));
  3105. /* enable transmits */
  3106. netif_tx_start_all_queues(adapter->netdev);
  3107. /* bring the link up in the watchdog, this could race with our first
  3108. * link up interrupt but shouldn't be a problem */
  3109. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  3110. adapter->link_check_timeout = jiffies;
  3111. mod_timer(&adapter->watchdog_timer, jiffies);
  3112. /* Set PF Reset Done bit so PF/VF Mail Ops can work */
  3113. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  3114. ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
  3115. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  3116. return 0;
  3117. }
  3118. void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
  3119. {
  3120. WARN_ON(in_interrupt());
  3121. while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
  3122. msleep(1);
  3123. ixgbe_down(adapter);
  3124. /*
  3125. * If SR-IOV enabled then wait a bit before bringing the adapter
  3126. * back up to give the VFs time to respond to the reset. The
  3127. * two second wait is based upon the watchdog timer cycle in
  3128. * the VF driver.
  3129. */
  3130. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  3131. msleep(2000);
  3132. ixgbe_up(adapter);
  3133. clear_bit(__IXGBE_RESETTING, &adapter->state);
  3134. }
  3135. int ixgbe_up(struct ixgbe_adapter *adapter)
  3136. {
  3137. /* hardware has been reset, we need to reload some things */
  3138. ixgbe_configure(adapter);
  3139. return ixgbe_up_complete(adapter);
  3140. }
  3141. void ixgbe_reset(struct ixgbe_adapter *adapter)
  3142. {
  3143. struct ixgbe_hw *hw = &adapter->hw;
  3144. int err;
  3145. err = hw->mac.ops.init_hw(hw);
  3146. switch (err) {
  3147. case 0:
  3148. case IXGBE_ERR_SFP_NOT_PRESENT:
  3149. break;
  3150. case IXGBE_ERR_MASTER_REQUESTS_PENDING:
  3151. e_dev_err("master disable timed out\n");
  3152. break;
  3153. case IXGBE_ERR_EEPROM_VERSION:
  3154. /* We are running on a pre-production device, log a warning */
  3155. e_dev_warn("This device is a pre-production adapter/LOM. "
  3156. "Please be aware there may be issuesassociated with "
  3157. "your hardware. If you are experiencing problems "
  3158. "please contact your Intel or hardware "
  3159. "representative who provided you with this "
  3160. "hardware.\n");
  3161. break;
  3162. default:
  3163. e_dev_err("Hardware Error: %d\n", err);
  3164. }
  3165. /* reprogram the RAR[0] in case user changed it. */
  3166. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
  3167. IXGBE_RAH_AV);
  3168. }
  3169. /**
  3170. * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
  3171. * @adapter: board private structure
  3172. * @rx_ring: ring to free buffers from
  3173. **/
  3174. static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
  3175. struct ixgbe_ring *rx_ring)
  3176. {
  3177. struct pci_dev *pdev = adapter->pdev;
  3178. unsigned long size;
  3179. unsigned int i;
  3180. /* Free all the Rx ring sk_buffs */
  3181. for (i = 0; i < rx_ring->count; i++) {
  3182. struct ixgbe_rx_buffer *rx_buffer_info;
  3183. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  3184. if (rx_buffer_info->dma) {
  3185. dma_unmap_single(&pdev->dev, rx_buffer_info->dma,
  3186. rx_ring->rx_buf_len,
  3187. DMA_FROM_DEVICE);
  3188. rx_buffer_info->dma = 0;
  3189. }
  3190. if (rx_buffer_info->skb) {
  3191. struct sk_buff *skb = rx_buffer_info->skb;
  3192. rx_buffer_info->skb = NULL;
  3193. do {
  3194. struct sk_buff *this = skb;
  3195. if (IXGBE_RSC_CB(this)->delay_unmap) {
  3196. dma_unmap_single(&pdev->dev,
  3197. IXGBE_RSC_CB(this)->dma,
  3198. rx_ring->rx_buf_len,
  3199. DMA_FROM_DEVICE);
  3200. IXGBE_RSC_CB(this)->dma = 0;
  3201. IXGBE_RSC_CB(skb)->delay_unmap = false;
  3202. }
  3203. skb = skb->prev;
  3204. dev_kfree_skb(this);
  3205. } while (skb);
  3206. }
  3207. if (!rx_buffer_info->page)
  3208. continue;
  3209. if (rx_buffer_info->page_dma) {
  3210. dma_unmap_page(&pdev->dev, rx_buffer_info->page_dma,
  3211. PAGE_SIZE / 2, DMA_FROM_DEVICE);
  3212. rx_buffer_info->page_dma = 0;
  3213. }
  3214. put_page(rx_buffer_info->page);
  3215. rx_buffer_info->page = NULL;
  3216. rx_buffer_info->page_offset = 0;
  3217. }
  3218. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  3219. memset(rx_ring->rx_buffer_info, 0, size);
  3220. /* Zero out the descriptor ring */
  3221. memset(rx_ring->desc, 0, rx_ring->size);
  3222. rx_ring->next_to_clean = 0;
  3223. rx_ring->next_to_use = 0;
  3224. if (rx_ring->head)
  3225. writel(0, adapter->hw.hw_addr + rx_ring->head);
  3226. if (rx_ring->tail)
  3227. writel(0, adapter->hw.hw_addr + rx_ring->tail);
  3228. }
  3229. /**
  3230. * ixgbe_clean_tx_ring - Free Tx Buffers
  3231. * @adapter: board private structure
  3232. * @tx_ring: ring to be cleaned
  3233. **/
  3234. static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
  3235. struct ixgbe_ring *tx_ring)
  3236. {
  3237. struct ixgbe_tx_buffer *tx_buffer_info;
  3238. unsigned long size;
  3239. unsigned int i;
  3240. /* Free all the Tx ring sk_buffs */
  3241. for (i = 0; i < tx_ring->count; i++) {
  3242. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  3243. ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
  3244. }
  3245. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  3246. memset(tx_ring->tx_buffer_info, 0, size);
  3247. /* Zero out the descriptor ring */
  3248. memset(tx_ring->desc, 0, tx_ring->size);
  3249. tx_ring->next_to_use = 0;
  3250. tx_ring->next_to_clean = 0;
  3251. if (tx_ring->head)
  3252. writel(0, adapter->hw.hw_addr + tx_ring->head);
  3253. if (tx_ring->tail)
  3254. writel(0, adapter->hw.hw_addr + tx_ring->tail);
  3255. }
  3256. /**
  3257. * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
  3258. * @adapter: board private structure
  3259. **/
  3260. static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
  3261. {
  3262. int i;
  3263. for (i = 0; i < adapter->num_rx_queues; i++)
  3264. ixgbe_clean_rx_ring(adapter, adapter->rx_ring[i]);
  3265. }
  3266. /**
  3267. * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
  3268. * @adapter: board private structure
  3269. **/
  3270. static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
  3271. {
  3272. int i;
  3273. for (i = 0; i < adapter->num_tx_queues; i++)
  3274. ixgbe_clean_tx_ring(adapter, adapter->tx_ring[i]);
  3275. }
  3276. void ixgbe_down(struct ixgbe_adapter *adapter)
  3277. {
  3278. struct net_device *netdev = adapter->netdev;
  3279. struct ixgbe_hw *hw = &adapter->hw;
  3280. u32 rxctrl;
  3281. u32 txdctl;
  3282. int i, j;
  3283. /* signal that we are down to the interrupt handler */
  3284. set_bit(__IXGBE_DOWN, &adapter->state);
  3285. /* disable receive for all VFs and wait one second */
  3286. if (adapter->num_vfs) {
  3287. /* ping all the active vfs to let them know we are going down */
  3288. ixgbe_ping_all_vfs(adapter);
  3289. /* Disable all VFTE/VFRE TX/RX */
  3290. ixgbe_disable_tx_rx(adapter);
  3291. /* Mark all the VFs as inactive */
  3292. for (i = 0 ; i < adapter->num_vfs; i++)
  3293. adapter->vfinfo[i].clear_to_send = 0;
  3294. }
  3295. /* disable receives */
  3296. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  3297. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
  3298. IXGBE_WRITE_FLUSH(hw);
  3299. msleep(10);
  3300. netif_tx_stop_all_queues(netdev);
  3301. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  3302. del_timer_sync(&adapter->sfp_timer);
  3303. del_timer_sync(&adapter->watchdog_timer);
  3304. cancel_work_sync(&adapter->watchdog_task);
  3305. netif_carrier_off(netdev);
  3306. netif_tx_disable(netdev);
  3307. ixgbe_irq_disable(adapter);
  3308. ixgbe_napi_disable_all(adapter);
  3309. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  3310. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  3311. cancel_work_sync(&adapter->fdir_reinit_task);
  3312. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
  3313. cancel_work_sync(&adapter->check_overtemp_task);
  3314. /* disable transmits in the hardware now that interrupts are off */
  3315. for (i = 0; i < adapter->num_tx_queues; i++) {
  3316. j = adapter->tx_ring[i]->reg_idx;
  3317. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
  3318. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
  3319. (txdctl & ~IXGBE_TXDCTL_ENABLE));
  3320. }
  3321. /* Disable the Tx DMA engine on 82599 */
  3322. if (hw->mac.type == ixgbe_mac_82599EB)
  3323. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
  3324. (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
  3325. ~IXGBE_DMATXCTL_TE));
  3326. /* power down the optics */
  3327. if (hw->phy.multispeed_fiber)
  3328. hw->mac.ops.disable_tx_laser(hw);
  3329. /* clear n-tuple filters that are cached */
  3330. ethtool_ntuple_flush(netdev);
  3331. if (!pci_channel_offline(adapter->pdev))
  3332. ixgbe_reset(adapter);
  3333. ixgbe_clean_all_tx_rings(adapter);
  3334. ixgbe_clean_all_rx_rings(adapter);
  3335. #ifdef CONFIG_IXGBE_DCA
  3336. /* since we reset the hardware DCA settings were cleared */
  3337. ixgbe_setup_dca(adapter);
  3338. #endif
  3339. }
  3340. /**
  3341. * ixgbe_poll - NAPI Rx polling callback
  3342. * @napi: structure for representing this polling device
  3343. * @budget: how many packets driver is allowed to clean
  3344. *
  3345. * This function is used for legacy and MSI, NAPI mode
  3346. **/
  3347. static int ixgbe_poll(struct napi_struct *napi, int budget)
  3348. {
  3349. struct ixgbe_q_vector *q_vector =
  3350. container_of(napi, struct ixgbe_q_vector, napi);
  3351. struct ixgbe_adapter *adapter = q_vector->adapter;
  3352. int tx_clean_complete, work_done = 0;
  3353. #ifdef CONFIG_IXGBE_DCA
  3354. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  3355. ixgbe_update_tx_dca(adapter, adapter->tx_ring[0]);
  3356. ixgbe_update_rx_dca(adapter, adapter->rx_ring[0]);
  3357. }
  3358. #endif
  3359. tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
  3360. ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
  3361. if (!tx_clean_complete)
  3362. work_done = budget;
  3363. /* If budget not fully consumed, exit the polling mode */
  3364. if (work_done < budget) {
  3365. napi_complete(napi);
  3366. if (adapter->rx_itr_setting & 1)
  3367. ixgbe_set_itr(adapter);
  3368. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  3369. ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
  3370. }
  3371. return work_done;
  3372. }
  3373. /**
  3374. * ixgbe_tx_timeout - Respond to a Tx Hang
  3375. * @netdev: network interface device structure
  3376. **/
  3377. static void ixgbe_tx_timeout(struct net_device *netdev)
  3378. {
  3379. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3380. /* Do the reset outside of interrupt context */
  3381. schedule_work(&adapter->reset_task);
  3382. }
  3383. static void ixgbe_reset_task(struct work_struct *work)
  3384. {
  3385. struct ixgbe_adapter *adapter;
  3386. adapter = container_of(work, struct ixgbe_adapter, reset_task);
  3387. /* If we're already down or resetting, just bail */
  3388. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  3389. test_bit(__IXGBE_RESETTING, &adapter->state))
  3390. return;
  3391. adapter->tx_timeout_count++;
  3392. ixgbe_dump(adapter);
  3393. netdev_err(adapter->netdev, "Reset adapter\n");
  3394. ixgbe_reinit_locked(adapter);
  3395. }
  3396. #ifdef CONFIG_IXGBE_DCB
  3397. static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
  3398. {
  3399. bool ret = false;
  3400. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
  3401. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
  3402. return ret;
  3403. f->mask = 0x7 << 3;
  3404. adapter->num_rx_queues = f->indices;
  3405. adapter->num_tx_queues = f->indices;
  3406. ret = true;
  3407. return ret;
  3408. }
  3409. #endif
  3410. /**
  3411. * ixgbe_set_rss_queues: Allocate queues for RSS
  3412. * @adapter: board private structure to initialize
  3413. *
  3414. * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
  3415. * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
  3416. *
  3417. **/
  3418. static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
  3419. {
  3420. bool ret = false;
  3421. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
  3422. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  3423. f->mask = 0xF;
  3424. adapter->num_rx_queues = f->indices;
  3425. adapter->num_tx_queues = f->indices;
  3426. ret = true;
  3427. } else {
  3428. ret = false;
  3429. }
  3430. return ret;
  3431. }
  3432. /**
  3433. * ixgbe_set_fdir_queues: Allocate queues for Flow Director
  3434. * @adapter: board private structure to initialize
  3435. *
  3436. * Flow Director is an advanced Rx filter, attempting to get Rx flows back
  3437. * to the original CPU that initiated the Tx session. This runs in addition
  3438. * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
  3439. * Rx load across CPUs using RSS.
  3440. *
  3441. **/
  3442. static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
  3443. {
  3444. bool ret = false;
  3445. struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
  3446. f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
  3447. f_fdir->mask = 0;
  3448. /* Flow Director must have RSS enabled */
  3449. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
  3450. ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  3451. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
  3452. adapter->num_tx_queues = f_fdir->indices;
  3453. adapter->num_rx_queues = f_fdir->indices;
  3454. ret = true;
  3455. } else {
  3456. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  3457. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  3458. }
  3459. return ret;
  3460. }
  3461. #ifdef IXGBE_FCOE
  3462. /**
  3463. * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
  3464. * @adapter: board private structure to initialize
  3465. *
  3466. * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
  3467. * The ring feature mask is not used as a mask for FCoE, as it can take any 8
  3468. * rx queues out of the max number of rx queues, instead, it is used as the
  3469. * index of the first rx queue used by FCoE.
  3470. *
  3471. **/
  3472. static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
  3473. {
  3474. bool ret = false;
  3475. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
  3476. f->indices = min((int)num_online_cpus(), f->indices);
  3477. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  3478. adapter->num_rx_queues = 1;
  3479. adapter->num_tx_queues = 1;
  3480. #ifdef CONFIG_IXGBE_DCB
  3481. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  3482. e_info(probe, "FCoE enabled with DCB\n");
  3483. ixgbe_set_dcb_queues(adapter);
  3484. }
  3485. #endif
  3486. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  3487. e_info(probe, "FCoE enabled with RSS\n");
  3488. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
  3489. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  3490. ixgbe_set_fdir_queues(adapter);
  3491. else
  3492. ixgbe_set_rss_queues(adapter);
  3493. }
  3494. /* adding FCoE rx rings to the end */
  3495. f->mask = adapter->num_rx_queues;
  3496. adapter->num_rx_queues += f->indices;
  3497. adapter->num_tx_queues += f->indices;
  3498. ret = true;
  3499. }
  3500. return ret;
  3501. }
  3502. #endif /* IXGBE_FCOE */
  3503. /**
  3504. * ixgbe_set_sriov_queues: Allocate queues for IOV use
  3505. * @adapter: board private structure to initialize
  3506. *
  3507. * IOV doesn't actually use anything, so just NAK the
  3508. * request for now and let the other queue routines
  3509. * figure out what to do.
  3510. */
  3511. static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
  3512. {
  3513. return false;
  3514. }
  3515. /*
  3516. * ixgbe_set_num_queues: Allocate queues for device, feature dependant
  3517. * @adapter: board private structure to initialize
  3518. *
  3519. * This is the top level queue allocation routine. The order here is very
  3520. * important, starting with the "most" number of features turned on at once,
  3521. * and ending with the smallest set of features. This way large combinations
  3522. * can be allocated if they're turned on, and smaller combinations are the
  3523. * fallthrough conditions.
  3524. *
  3525. **/
  3526. static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
  3527. {
  3528. /* Start with base case */
  3529. adapter->num_rx_queues = 1;
  3530. adapter->num_tx_queues = 1;
  3531. adapter->num_rx_pools = adapter->num_rx_queues;
  3532. adapter->num_rx_queues_per_pool = 1;
  3533. if (ixgbe_set_sriov_queues(adapter))
  3534. return;
  3535. #ifdef IXGBE_FCOE
  3536. if (ixgbe_set_fcoe_queues(adapter))
  3537. goto done;
  3538. #endif /* IXGBE_FCOE */
  3539. #ifdef CONFIG_IXGBE_DCB
  3540. if (ixgbe_set_dcb_queues(adapter))
  3541. goto done;
  3542. #endif
  3543. if (ixgbe_set_fdir_queues(adapter))
  3544. goto done;
  3545. if (ixgbe_set_rss_queues(adapter))
  3546. goto done;
  3547. /* fallback to base case */
  3548. adapter->num_rx_queues = 1;
  3549. adapter->num_tx_queues = 1;
  3550. done:
  3551. /* Notify the stack of the (possibly) reduced Tx Queue count. */
  3552. netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
  3553. }
  3554. static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
  3555. int vectors)
  3556. {
  3557. int err, vector_threshold;
  3558. /* We'll want at least 3 (vector_threshold):
  3559. * 1) TxQ[0] Cleanup
  3560. * 2) RxQ[0] Cleanup
  3561. * 3) Other (Link Status Change, etc.)
  3562. * 4) TCP Timer (optional)
  3563. */
  3564. vector_threshold = MIN_MSIX_COUNT;
  3565. /* The more we get, the more we will assign to Tx/Rx Cleanup
  3566. * for the separate queues...where Rx Cleanup >= Tx Cleanup.
  3567. * Right now, we simply care about how many we'll get; we'll
  3568. * set them up later while requesting irq's.
  3569. */
  3570. while (vectors >= vector_threshold) {
  3571. err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
  3572. vectors);
  3573. if (!err) /* Success in acquiring all requested vectors. */
  3574. break;
  3575. else if (err < 0)
  3576. vectors = 0; /* Nasty failure, quit now */
  3577. else /* err == number of vectors we should try again with */
  3578. vectors = err;
  3579. }
  3580. if (vectors < vector_threshold) {
  3581. /* Can't allocate enough MSI-X interrupts? Oh well.
  3582. * This just means we'll go with either a single MSI
  3583. * vector or fall back to legacy interrupts.
  3584. */
  3585. netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
  3586. "Unable to allocate MSI-X interrupts\n");
  3587. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  3588. kfree(adapter->msix_entries);
  3589. adapter->msix_entries = NULL;
  3590. } else {
  3591. adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
  3592. /*
  3593. * Adjust for only the vectors we'll use, which is minimum
  3594. * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
  3595. * vectors we were allocated.
  3596. */
  3597. adapter->num_msix_vectors = min(vectors,
  3598. adapter->max_msix_q_vectors + NON_Q_VECTORS);
  3599. }
  3600. }
  3601. /**
  3602. * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
  3603. * @adapter: board private structure to initialize
  3604. *
  3605. * Cache the descriptor ring offsets for RSS to the assigned rings.
  3606. *
  3607. **/
  3608. static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
  3609. {
  3610. int i;
  3611. bool ret = false;
  3612. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  3613. for (i = 0; i < adapter->num_rx_queues; i++)
  3614. adapter->rx_ring[i]->reg_idx = i;
  3615. for (i = 0; i < adapter->num_tx_queues; i++)
  3616. adapter->tx_ring[i]->reg_idx = i;
  3617. ret = true;
  3618. } else {
  3619. ret = false;
  3620. }
  3621. return ret;
  3622. }
  3623. #ifdef CONFIG_IXGBE_DCB
  3624. /**
  3625. * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
  3626. * @adapter: board private structure to initialize
  3627. *
  3628. * Cache the descriptor ring offsets for DCB to the assigned rings.
  3629. *
  3630. **/
  3631. static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
  3632. {
  3633. int i;
  3634. bool ret = false;
  3635. int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
  3636. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  3637. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  3638. /* the number of queues is assumed to be symmetric */
  3639. for (i = 0; i < dcb_i; i++) {
  3640. adapter->rx_ring[i]->reg_idx = i << 3;
  3641. adapter->tx_ring[i]->reg_idx = i << 2;
  3642. }
  3643. ret = true;
  3644. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  3645. if (dcb_i == 8) {
  3646. /*
  3647. * Tx TC0 starts at: descriptor queue 0
  3648. * Tx TC1 starts at: descriptor queue 32
  3649. * Tx TC2 starts at: descriptor queue 64
  3650. * Tx TC3 starts at: descriptor queue 80
  3651. * Tx TC4 starts at: descriptor queue 96
  3652. * Tx TC5 starts at: descriptor queue 104
  3653. * Tx TC6 starts at: descriptor queue 112
  3654. * Tx TC7 starts at: descriptor queue 120
  3655. *
  3656. * Rx TC0-TC7 are offset by 16 queues each
  3657. */
  3658. for (i = 0; i < 3; i++) {
  3659. adapter->tx_ring[i]->reg_idx = i << 5;
  3660. adapter->rx_ring[i]->reg_idx = i << 4;
  3661. }
  3662. for ( ; i < 5; i++) {
  3663. adapter->tx_ring[i]->reg_idx =
  3664. ((i + 2) << 4);
  3665. adapter->rx_ring[i]->reg_idx = i << 4;
  3666. }
  3667. for ( ; i < dcb_i; i++) {
  3668. adapter->tx_ring[i]->reg_idx =
  3669. ((i + 8) << 3);
  3670. adapter->rx_ring[i]->reg_idx = i << 4;
  3671. }
  3672. ret = true;
  3673. } else if (dcb_i == 4) {
  3674. /*
  3675. * Tx TC0 starts at: descriptor queue 0
  3676. * Tx TC1 starts at: descriptor queue 64
  3677. * Tx TC2 starts at: descriptor queue 96
  3678. * Tx TC3 starts at: descriptor queue 112
  3679. *
  3680. * Rx TC0-TC3 are offset by 32 queues each
  3681. */
  3682. adapter->tx_ring[0]->reg_idx = 0;
  3683. adapter->tx_ring[1]->reg_idx = 64;
  3684. adapter->tx_ring[2]->reg_idx = 96;
  3685. adapter->tx_ring[3]->reg_idx = 112;
  3686. for (i = 0 ; i < dcb_i; i++)
  3687. adapter->rx_ring[i]->reg_idx = i << 5;
  3688. ret = true;
  3689. } else {
  3690. ret = false;
  3691. }
  3692. } else {
  3693. ret = false;
  3694. }
  3695. } else {
  3696. ret = false;
  3697. }
  3698. return ret;
  3699. }
  3700. #endif
  3701. /**
  3702. * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
  3703. * @adapter: board private structure to initialize
  3704. *
  3705. * Cache the descriptor ring offsets for Flow Director to the assigned rings.
  3706. *
  3707. **/
  3708. static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
  3709. {
  3710. int i;
  3711. bool ret = false;
  3712. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
  3713. ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
  3714. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
  3715. for (i = 0; i < adapter->num_rx_queues; i++)
  3716. adapter->rx_ring[i]->reg_idx = i;
  3717. for (i = 0; i < adapter->num_tx_queues; i++)
  3718. adapter->tx_ring[i]->reg_idx = i;
  3719. ret = true;
  3720. }
  3721. return ret;
  3722. }
  3723. #ifdef IXGBE_FCOE
  3724. /**
  3725. * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
  3726. * @adapter: board private structure to initialize
  3727. *
  3728. * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
  3729. *
  3730. */
  3731. static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
  3732. {
  3733. int i, fcoe_rx_i = 0, fcoe_tx_i = 0;
  3734. bool ret = false;
  3735. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
  3736. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  3737. #ifdef CONFIG_IXGBE_DCB
  3738. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  3739. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  3740. ixgbe_cache_ring_dcb(adapter);
  3741. /* find out queues in TC for FCoE */
  3742. fcoe_rx_i = adapter->rx_ring[fcoe->tc]->reg_idx + 1;
  3743. fcoe_tx_i = adapter->tx_ring[fcoe->tc]->reg_idx + 1;
  3744. /*
  3745. * In 82599, the number of Tx queues for each traffic
  3746. * class for both 8-TC and 4-TC modes are:
  3747. * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7
  3748. * 8 TCs: 32 32 16 16 8 8 8 8
  3749. * 4 TCs: 64 64 32 32
  3750. * We have max 8 queues for FCoE, where 8 the is
  3751. * FCoE redirection table size. If TC for FCoE is
  3752. * less than or equal to TC3, we have enough queues
  3753. * to add max of 8 queues for FCoE, so we start FCoE
  3754. * tx descriptor from the next one, i.e., reg_idx + 1.
  3755. * If TC for FCoE is above TC3, implying 8 TC mode,
  3756. * and we need 8 for FCoE, we have to take all queues
  3757. * in that traffic class for FCoE.
  3758. */
  3759. if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3))
  3760. fcoe_tx_i--;
  3761. }
  3762. #endif /* CONFIG_IXGBE_DCB */
  3763. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  3764. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
  3765. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  3766. ixgbe_cache_ring_fdir(adapter);
  3767. else
  3768. ixgbe_cache_ring_rss(adapter);
  3769. fcoe_rx_i = f->mask;
  3770. fcoe_tx_i = f->mask;
  3771. }
  3772. for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
  3773. adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
  3774. adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
  3775. }
  3776. ret = true;
  3777. }
  3778. return ret;
  3779. }
  3780. #endif /* IXGBE_FCOE */
  3781. /**
  3782. * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
  3783. * @adapter: board private structure to initialize
  3784. *
  3785. * SR-IOV doesn't use any descriptor rings but changes the default if
  3786. * no other mapping is used.
  3787. *
  3788. */
  3789. static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
  3790. {
  3791. adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
  3792. adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
  3793. if (adapter->num_vfs)
  3794. return true;
  3795. else
  3796. return false;
  3797. }
  3798. /**
  3799. * ixgbe_cache_ring_register - Descriptor ring to register mapping
  3800. * @adapter: board private structure to initialize
  3801. *
  3802. * Once we know the feature-set enabled for the device, we'll cache
  3803. * the register offset the descriptor ring is assigned to.
  3804. *
  3805. * Note, the order the various feature calls is important. It must start with
  3806. * the "most" features enabled at the same time, then trickle down to the
  3807. * least amount of features turned on at once.
  3808. **/
  3809. static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
  3810. {
  3811. /* start with default case */
  3812. adapter->rx_ring[0]->reg_idx = 0;
  3813. adapter->tx_ring[0]->reg_idx = 0;
  3814. if (ixgbe_cache_ring_sriov(adapter))
  3815. return;
  3816. #ifdef IXGBE_FCOE
  3817. if (ixgbe_cache_ring_fcoe(adapter))
  3818. return;
  3819. #endif /* IXGBE_FCOE */
  3820. #ifdef CONFIG_IXGBE_DCB
  3821. if (ixgbe_cache_ring_dcb(adapter))
  3822. return;
  3823. #endif
  3824. if (ixgbe_cache_ring_fdir(adapter))
  3825. return;
  3826. if (ixgbe_cache_ring_rss(adapter))
  3827. return;
  3828. }
  3829. /**
  3830. * ixgbe_alloc_queues - Allocate memory for all rings
  3831. * @adapter: board private structure to initialize
  3832. *
  3833. * We allocate one ring per queue at run-time since we don't know the
  3834. * number of queues at compile-time. The polling_netdev array is
  3835. * intended for Multiqueue, but should work fine with a single queue.
  3836. **/
  3837. static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
  3838. {
  3839. int i;
  3840. int orig_node = adapter->node;
  3841. for (i = 0; i < adapter->num_tx_queues; i++) {
  3842. struct ixgbe_ring *ring = adapter->tx_ring[i];
  3843. if (orig_node == -1) {
  3844. int cur_node = next_online_node(adapter->node);
  3845. if (cur_node == MAX_NUMNODES)
  3846. cur_node = first_online_node;
  3847. adapter->node = cur_node;
  3848. }
  3849. ring = kzalloc_node(sizeof(struct ixgbe_ring), GFP_KERNEL,
  3850. adapter->node);
  3851. if (!ring)
  3852. ring = kzalloc(sizeof(struct ixgbe_ring), GFP_KERNEL);
  3853. if (!ring)
  3854. goto err_tx_ring_allocation;
  3855. ring->count = adapter->tx_ring_count;
  3856. ring->queue_index = i;
  3857. ring->numa_node = adapter->node;
  3858. adapter->tx_ring[i] = ring;
  3859. }
  3860. /* Restore the adapter's original node */
  3861. adapter->node = orig_node;
  3862. for (i = 0; i < adapter->num_rx_queues; i++) {
  3863. struct ixgbe_ring *ring = adapter->rx_ring[i];
  3864. if (orig_node == -1) {
  3865. int cur_node = next_online_node(adapter->node);
  3866. if (cur_node == MAX_NUMNODES)
  3867. cur_node = first_online_node;
  3868. adapter->node = cur_node;
  3869. }
  3870. ring = kzalloc_node(sizeof(struct ixgbe_ring), GFP_KERNEL,
  3871. adapter->node);
  3872. if (!ring)
  3873. ring = kzalloc(sizeof(struct ixgbe_ring), GFP_KERNEL);
  3874. if (!ring)
  3875. goto err_rx_ring_allocation;
  3876. ring->count = adapter->rx_ring_count;
  3877. ring->queue_index = i;
  3878. ring->numa_node = adapter->node;
  3879. adapter->rx_ring[i] = ring;
  3880. }
  3881. /* Restore the adapter's original node */
  3882. adapter->node = orig_node;
  3883. ixgbe_cache_ring_register(adapter);
  3884. return 0;
  3885. err_rx_ring_allocation:
  3886. for (i = 0; i < adapter->num_tx_queues; i++)
  3887. kfree(adapter->tx_ring[i]);
  3888. err_tx_ring_allocation:
  3889. return -ENOMEM;
  3890. }
  3891. /**
  3892. * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
  3893. * @adapter: board private structure to initialize
  3894. *
  3895. * Attempt to configure the interrupts using the best available
  3896. * capabilities of the hardware and the kernel.
  3897. **/
  3898. static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
  3899. {
  3900. struct ixgbe_hw *hw = &adapter->hw;
  3901. int err = 0;
  3902. int vector, v_budget;
  3903. /*
  3904. * It's easy to be greedy for MSI-X vectors, but it really
  3905. * doesn't do us much good if we have a lot more vectors
  3906. * than CPU's. So let's be conservative and only ask for
  3907. * (roughly) the same number of vectors as there are CPU's.
  3908. */
  3909. v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
  3910. (int)num_online_cpus()) + NON_Q_VECTORS;
  3911. /*
  3912. * At the same time, hardware can only support a maximum of
  3913. * hw.mac->max_msix_vectors vectors. With features
  3914. * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
  3915. * descriptor queues supported by our device. Thus, we cap it off in
  3916. * those rare cases where the cpu count also exceeds our vector limit.
  3917. */
  3918. v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
  3919. /* A failure in MSI-X entry allocation isn't fatal, but it does
  3920. * mean we disable MSI-X capabilities of the adapter. */
  3921. adapter->msix_entries = kcalloc(v_budget,
  3922. sizeof(struct msix_entry), GFP_KERNEL);
  3923. if (adapter->msix_entries) {
  3924. for (vector = 0; vector < v_budget; vector++)
  3925. adapter->msix_entries[vector].entry = vector;
  3926. ixgbe_acquire_msix_vectors(adapter, v_budget);
  3927. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  3928. goto out;
  3929. }
  3930. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  3931. adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
  3932. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  3933. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  3934. adapter->atr_sample_rate = 0;
  3935. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  3936. ixgbe_disable_sriov(adapter);
  3937. ixgbe_set_num_queues(adapter);
  3938. err = pci_enable_msi(adapter->pdev);
  3939. if (!err) {
  3940. adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
  3941. } else {
  3942. netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
  3943. "Unable to allocate MSI interrupt, "
  3944. "falling back to legacy. Error: %d\n", err);
  3945. /* reset err */
  3946. err = 0;
  3947. }
  3948. out:
  3949. return err;
  3950. }
  3951. /**
  3952. * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
  3953. * @adapter: board private structure to initialize
  3954. *
  3955. * We allocate one q_vector per queue interrupt. If allocation fails we
  3956. * return -ENOMEM.
  3957. **/
  3958. static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
  3959. {
  3960. int q_idx, num_q_vectors;
  3961. struct ixgbe_q_vector *q_vector;
  3962. int napi_vectors;
  3963. int (*poll)(struct napi_struct *, int);
  3964. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  3965. num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  3966. napi_vectors = adapter->num_rx_queues;
  3967. poll = &ixgbe_clean_rxtx_many;
  3968. } else {
  3969. num_q_vectors = 1;
  3970. napi_vectors = 1;
  3971. poll = &ixgbe_poll;
  3972. }
  3973. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  3974. q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
  3975. GFP_KERNEL, adapter->node);
  3976. if (!q_vector)
  3977. q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
  3978. GFP_KERNEL);
  3979. if (!q_vector)
  3980. goto err_out;
  3981. q_vector->adapter = adapter;
  3982. if (q_vector->txr_count && !q_vector->rxr_count)
  3983. q_vector->eitr = adapter->tx_eitr_param;
  3984. else
  3985. q_vector->eitr = adapter->rx_eitr_param;
  3986. q_vector->v_idx = q_idx;
  3987. netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
  3988. adapter->q_vector[q_idx] = q_vector;
  3989. }
  3990. return 0;
  3991. err_out:
  3992. while (q_idx) {
  3993. q_idx--;
  3994. q_vector = adapter->q_vector[q_idx];
  3995. netif_napi_del(&q_vector->napi);
  3996. kfree(q_vector);
  3997. adapter->q_vector[q_idx] = NULL;
  3998. }
  3999. return -ENOMEM;
  4000. }
  4001. /**
  4002. * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
  4003. * @adapter: board private structure to initialize
  4004. *
  4005. * This function frees the memory allocated to the q_vectors. In addition if
  4006. * NAPI is enabled it will delete any references to the NAPI struct prior
  4007. * to freeing the q_vector.
  4008. **/
  4009. static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
  4010. {
  4011. int q_idx, num_q_vectors;
  4012. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  4013. num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  4014. else
  4015. num_q_vectors = 1;
  4016. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  4017. struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
  4018. adapter->q_vector[q_idx] = NULL;
  4019. netif_napi_del(&q_vector->napi);
  4020. kfree(q_vector);
  4021. }
  4022. }
  4023. static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
  4024. {
  4025. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  4026. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  4027. pci_disable_msix(adapter->pdev);
  4028. kfree(adapter->msix_entries);
  4029. adapter->msix_entries = NULL;
  4030. } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
  4031. adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
  4032. pci_disable_msi(adapter->pdev);
  4033. }
  4034. }
  4035. /**
  4036. * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
  4037. * @adapter: board private structure to initialize
  4038. *
  4039. * We determine which interrupt scheme to use based on...
  4040. * - Kernel support (MSI, MSI-X)
  4041. * - which can be user-defined (via MODULE_PARAM)
  4042. * - Hardware queue count (num_*_queues)
  4043. * - defined by miscellaneous hardware support/features (RSS, etc.)
  4044. **/
  4045. int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
  4046. {
  4047. int err;
  4048. /* Number of supported queues */
  4049. ixgbe_set_num_queues(adapter);
  4050. err = ixgbe_set_interrupt_capability(adapter);
  4051. if (err) {
  4052. e_dev_err("Unable to setup interrupt capabilities\n");
  4053. goto err_set_interrupt;
  4054. }
  4055. err = ixgbe_alloc_q_vectors(adapter);
  4056. if (err) {
  4057. e_dev_err("Unable to allocate memory for queue vectors\n");
  4058. goto err_alloc_q_vectors;
  4059. }
  4060. err = ixgbe_alloc_queues(adapter);
  4061. if (err) {
  4062. e_dev_err("Unable to allocate memory for queues\n");
  4063. goto err_alloc_queues;
  4064. }
  4065. e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
  4066. (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
  4067. adapter->num_rx_queues, adapter->num_tx_queues);
  4068. set_bit(__IXGBE_DOWN, &adapter->state);
  4069. return 0;
  4070. err_alloc_queues:
  4071. ixgbe_free_q_vectors(adapter);
  4072. err_alloc_q_vectors:
  4073. ixgbe_reset_interrupt_capability(adapter);
  4074. err_set_interrupt:
  4075. return err;
  4076. }
  4077. /**
  4078. * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
  4079. * @adapter: board private structure to clear interrupt scheme on
  4080. *
  4081. * We go through and clear interrupt specific resources and reset the structure
  4082. * to pre-load conditions
  4083. **/
  4084. void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
  4085. {
  4086. int i;
  4087. for (i = 0; i < adapter->num_tx_queues; i++) {
  4088. kfree(adapter->tx_ring[i]);
  4089. adapter->tx_ring[i] = NULL;
  4090. }
  4091. for (i = 0; i < adapter->num_rx_queues; i++) {
  4092. kfree(adapter->rx_ring[i]);
  4093. adapter->rx_ring[i] = NULL;
  4094. }
  4095. ixgbe_free_q_vectors(adapter);
  4096. ixgbe_reset_interrupt_capability(adapter);
  4097. }
  4098. /**
  4099. * ixgbe_sfp_timer - worker thread to find a missing module
  4100. * @data: pointer to our adapter struct
  4101. **/
  4102. static void ixgbe_sfp_timer(unsigned long data)
  4103. {
  4104. struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
  4105. /*
  4106. * Do the sfp_timer outside of interrupt context due to the
  4107. * delays that sfp+ detection requires
  4108. */
  4109. schedule_work(&adapter->sfp_task);
  4110. }
  4111. /**
  4112. * ixgbe_sfp_task - worker thread to find a missing module
  4113. * @work: pointer to work_struct containing our data
  4114. **/
  4115. static void ixgbe_sfp_task(struct work_struct *work)
  4116. {
  4117. struct ixgbe_adapter *adapter = container_of(work,
  4118. struct ixgbe_adapter,
  4119. sfp_task);
  4120. struct ixgbe_hw *hw = &adapter->hw;
  4121. if ((hw->phy.type == ixgbe_phy_nl) &&
  4122. (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
  4123. s32 ret = hw->phy.ops.identify_sfp(hw);
  4124. if (ret == IXGBE_ERR_SFP_NOT_PRESENT)
  4125. goto reschedule;
  4126. ret = hw->phy.ops.reset(hw);
  4127. if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  4128. e_dev_err("failed to initialize because an unsupported "
  4129. "SFP+ module type was detected.\n");
  4130. e_dev_err("Reload the driver after installing a "
  4131. "supported module.\n");
  4132. unregister_netdev(adapter->netdev);
  4133. } else {
  4134. e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
  4135. }
  4136. /* don't need this routine any more */
  4137. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  4138. }
  4139. return;
  4140. reschedule:
  4141. if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
  4142. mod_timer(&adapter->sfp_timer,
  4143. round_jiffies(jiffies + (2 * HZ)));
  4144. }
  4145. /**
  4146. * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
  4147. * @adapter: board private structure to initialize
  4148. *
  4149. * ixgbe_sw_init initializes the Adapter private data structure.
  4150. * Fields are initialized based on PCI device information and
  4151. * OS network device settings (MTU size).
  4152. **/
  4153. static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
  4154. {
  4155. struct ixgbe_hw *hw = &adapter->hw;
  4156. struct pci_dev *pdev = adapter->pdev;
  4157. struct net_device *dev = adapter->netdev;
  4158. unsigned int rss;
  4159. #ifdef CONFIG_IXGBE_DCB
  4160. int j;
  4161. struct tc_configuration *tc;
  4162. #endif
  4163. /* PCI config space info */
  4164. hw->vendor_id = pdev->vendor;
  4165. hw->device_id = pdev->device;
  4166. hw->revision_id = pdev->revision;
  4167. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  4168. hw->subsystem_device_id = pdev->subsystem_device;
  4169. /* Set capability flags */
  4170. rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
  4171. adapter->ring_feature[RING_F_RSS].indices = rss;
  4172. adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
  4173. adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
  4174. if (hw->mac.type == ixgbe_mac_82598EB) {
  4175. if (hw->device_id == IXGBE_DEV_ID_82598AT)
  4176. adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
  4177. adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
  4178. } else if (hw->mac.type == ixgbe_mac_82599EB) {
  4179. adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
  4180. adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
  4181. adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
  4182. if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
  4183. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  4184. if (dev->features & NETIF_F_NTUPLE) {
  4185. /* Flow Director perfect filter enabled */
  4186. adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  4187. adapter->atr_sample_rate = 0;
  4188. spin_lock_init(&adapter->fdir_perfect_lock);
  4189. } else {
  4190. /* Flow Director hash filters enabled */
  4191. adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
  4192. adapter->atr_sample_rate = 20;
  4193. }
  4194. adapter->ring_feature[RING_F_FDIR].indices =
  4195. IXGBE_MAX_FDIR_INDICES;
  4196. adapter->fdir_pballoc = 0;
  4197. #ifdef IXGBE_FCOE
  4198. adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
  4199. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  4200. adapter->ring_feature[RING_F_FCOE].indices = 0;
  4201. #ifdef CONFIG_IXGBE_DCB
  4202. /* Default traffic class to use for FCoE */
  4203. adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
  4204. adapter->fcoe.up = IXGBE_FCOE_DEFTC;
  4205. #endif
  4206. #endif /* IXGBE_FCOE */
  4207. }
  4208. #ifdef CONFIG_IXGBE_DCB
  4209. /* Configure DCB traffic classes */
  4210. for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
  4211. tc = &adapter->dcb_cfg.tc_config[j];
  4212. tc->path[DCB_TX_CONFIG].bwg_id = 0;
  4213. tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
  4214. tc->path[DCB_RX_CONFIG].bwg_id = 0;
  4215. tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
  4216. tc->dcb_pfc = pfc_disabled;
  4217. }
  4218. adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
  4219. adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
  4220. adapter->dcb_cfg.rx_pba_cfg = pba_equal;
  4221. adapter->dcb_cfg.pfc_mode_enable = false;
  4222. adapter->dcb_cfg.round_robin_enable = false;
  4223. adapter->dcb_set_bitmap = 0x00;
  4224. ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
  4225. adapter->ring_feature[RING_F_DCB].indices);
  4226. #endif
  4227. /* default flow control settings */
  4228. hw->fc.requested_mode = ixgbe_fc_full;
  4229. hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
  4230. #ifdef CONFIG_DCB
  4231. adapter->last_lfc_mode = hw->fc.current_mode;
  4232. #endif
  4233. hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
  4234. hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
  4235. hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
  4236. hw->fc.send_xon = true;
  4237. hw->fc.disable_fc_autoneg = false;
  4238. /* enable itr by default in dynamic mode */
  4239. adapter->rx_itr_setting = 1;
  4240. adapter->rx_eitr_param = 20000;
  4241. adapter->tx_itr_setting = 1;
  4242. adapter->tx_eitr_param = 10000;
  4243. /* set defaults for eitr in MegaBytes */
  4244. adapter->eitr_low = 10;
  4245. adapter->eitr_high = 20;
  4246. /* set default ring sizes */
  4247. adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
  4248. adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
  4249. /* initialize eeprom parameters */
  4250. if (ixgbe_init_eeprom_params_generic(hw)) {
  4251. e_dev_err("EEPROM initialization failed\n");
  4252. return -EIO;
  4253. }
  4254. /* enable rx csum by default */
  4255. adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
  4256. /* get assigned NUMA node */
  4257. adapter->node = dev_to_node(&pdev->dev);
  4258. set_bit(__IXGBE_DOWN, &adapter->state);
  4259. return 0;
  4260. }
  4261. /**
  4262. * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
  4263. * @adapter: board private structure
  4264. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  4265. *
  4266. * Return 0 on success, negative on failure
  4267. **/
  4268. int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
  4269. struct ixgbe_ring *tx_ring)
  4270. {
  4271. struct pci_dev *pdev = adapter->pdev;
  4272. int size;
  4273. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  4274. tx_ring->tx_buffer_info = vmalloc_node(size, tx_ring->numa_node);
  4275. if (!tx_ring->tx_buffer_info)
  4276. tx_ring->tx_buffer_info = vmalloc(size);
  4277. if (!tx_ring->tx_buffer_info)
  4278. goto err;
  4279. memset(tx_ring->tx_buffer_info, 0, size);
  4280. /* round up to nearest 4K */
  4281. tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
  4282. tx_ring->size = ALIGN(tx_ring->size, 4096);
  4283. tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
  4284. &tx_ring->dma, GFP_KERNEL);
  4285. if (!tx_ring->desc)
  4286. goto err;
  4287. tx_ring->next_to_use = 0;
  4288. tx_ring->next_to_clean = 0;
  4289. tx_ring->work_limit = tx_ring->count;
  4290. return 0;
  4291. err:
  4292. vfree(tx_ring->tx_buffer_info);
  4293. tx_ring->tx_buffer_info = NULL;
  4294. e_err(probe, "Unable to allocate memory for the Tx descriptor ring\n");
  4295. return -ENOMEM;
  4296. }
  4297. /**
  4298. * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
  4299. * @adapter: board private structure
  4300. *
  4301. * If this function returns with an error, then it's possible one or
  4302. * more of the rings is populated (while the rest are not). It is the
  4303. * callers duty to clean those orphaned rings.
  4304. *
  4305. * Return 0 on success, negative on failure
  4306. **/
  4307. static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
  4308. {
  4309. int i, err = 0;
  4310. for (i = 0; i < adapter->num_tx_queues; i++) {
  4311. err = ixgbe_setup_tx_resources(adapter, adapter->tx_ring[i]);
  4312. if (!err)
  4313. continue;
  4314. e_err(probe, "Allocation for Tx Queue %u failed\n", i);
  4315. break;
  4316. }
  4317. return err;
  4318. }
  4319. /**
  4320. * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
  4321. * @adapter: board private structure
  4322. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  4323. *
  4324. * Returns 0 on success, negative on failure
  4325. **/
  4326. int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
  4327. struct ixgbe_ring *rx_ring)
  4328. {
  4329. struct pci_dev *pdev = adapter->pdev;
  4330. int size;
  4331. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  4332. rx_ring->rx_buffer_info = vmalloc_node(size, adapter->node);
  4333. if (!rx_ring->rx_buffer_info)
  4334. rx_ring->rx_buffer_info = vmalloc(size);
  4335. if (!rx_ring->rx_buffer_info) {
  4336. e_err(probe, "vmalloc allocation failed for the Rx "
  4337. "descriptor ring\n");
  4338. goto alloc_failed;
  4339. }
  4340. memset(rx_ring->rx_buffer_info, 0, size);
  4341. /* Round up to nearest 4K */
  4342. rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
  4343. rx_ring->size = ALIGN(rx_ring->size, 4096);
  4344. rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
  4345. &rx_ring->dma, GFP_KERNEL);
  4346. if (!rx_ring->desc) {
  4347. e_err(probe, "Memory allocation failed for the Rx "
  4348. "descriptor ring\n");
  4349. vfree(rx_ring->rx_buffer_info);
  4350. goto alloc_failed;
  4351. }
  4352. rx_ring->next_to_clean = 0;
  4353. rx_ring->next_to_use = 0;
  4354. return 0;
  4355. alloc_failed:
  4356. return -ENOMEM;
  4357. }
  4358. /**
  4359. * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
  4360. * @adapter: board private structure
  4361. *
  4362. * If this function returns with an error, then it's possible one or
  4363. * more of the rings is populated (while the rest are not). It is the
  4364. * callers duty to clean those orphaned rings.
  4365. *
  4366. * Return 0 on success, negative on failure
  4367. **/
  4368. static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
  4369. {
  4370. int i, err = 0;
  4371. for (i = 0; i < adapter->num_rx_queues; i++) {
  4372. err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]);
  4373. if (!err)
  4374. continue;
  4375. e_err(probe, "Allocation for Rx Queue %u failed\n", i);
  4376. break;
  4377. }
  4378. return err;
  4379. }
  4380. /**
  4381. * ixgbe_free_tx_resources - Free Tx Resources per Queue
  4382. * @adapter: board private structure
  4383. * @tx_ring: Tx descriptor ring for a specific queue
  4384. *
  4385. * Free all transmit software resources
  4386. **/
  4387. void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
  4388. struct ixgbe_ring *tx_ring)
  4389. {
  4390. struct pci_dev *pdev = adapter->pdev;
  4391. ixgbe_clean_tx_ring(adapter, tx_ring);
  4392. vfree(tx_ring->tx_buffer_info);
  4393. tx_ring->tx_buffer_info = NULL;
  4394. dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
  4395. tx_ring->dma);
  4396. tx_ring->desc = NULL;
  4397. }
  4398. /**
  4399. * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
  4400. * @adapter: board private structure
  4401. *
  4402. * Free all transmit software resources
  4403. **/
  4404. static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
  4405. {
  4406. int i;
  4407. for (i = 0; i < adapter->num_tx_queues; i++)
  4408. if (adapter->tx_ring[i]->desc)
  4409. ixgbe_free_tx_resources(adapter, adapter->tx_ring[i]);
  4410. }
  4411. /**
  4412. * ixgbe_free_rx_resources - Free Rx Resources
  4413. * @adapter: board private structure
  4414. * @rx_ring: ring to clean the resources from
  4415. *
  4416. * Free all receive software resources
  4417. **/
  4418. void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
  4419. struct ixgbe_ring *rx_ring)
  4420. {
  4421. struct pci_dev *pdev = adapter->pdev;
  4422. ixgbe_clean_rx_ring(adapter, rx_ring);
  4423. vfree(rx_ring->rx_buffer_info);
  4424. rx_ring->rx_buffer_info = NULL;
  4425. dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
  4426. rx_ring->dma);
  4427. rx_ring->desc = NULL;
  4428. }
  4429. /**
  4430. * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
  4431. * @adapter: board private structure
  4432. *
  4433. * Free all receive software resources
  4434. **/
  4435. static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
  4436. {
  4437. int i;
  4438. for (i = 0; i < adapter->num_rx_queues; i++)
  4439. if (adapter->rx_ring[i]->desc)
  4440. ixgbe_free_rx_resources(adapter, adapter->rx_ring[i]);
  4441. }
  4442. /**
  4443. * ixgbe_change_mtu - Change the Maximum Transfer Unit
  4444. * @netdev: network interface device structure
  4445. * @new_mtu: new value for maximum frame size
  4446. *
  4447. * Returns 0 on success, negative on failure
  4448. **/
  4449. static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
  4450. {
  4451. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4452. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  4453. /* MTU < 68 is an error and causes problems on some kernels */
  4454. if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
  4455. return -EINVAL;
  4456. e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
  4457. /* must set new MTU before calling down or up */
  4458. netdev->mtu = new_mtu;
  4459. if (netif_running(netdev))
  4460. ixgbe_reinit_locked(adapter);
  4461. return 0;
  4462. }
  4463. /**
  4464. * ixgbe_open - Called when a network interface is made active
  4465. * @netdev: network interface device structure
  4466. *
  4467. * Returns 0 on success, negative value on failure
  4468. *
  4469. * The open entry point is called when a network interface is made
  4470. * active by the system (IFF_UP). At this point all resources needed
  4471. * for transmit and receive operations are allocated, the interrupt
  4472. * handler is registered with the OS, the watchdog timer is started,
  4473. * and the stack is notified that the interface is ready.
  4474. **/
  4475. static int ixgbe_open(struct net_device *netdev)
  4476. {
  4477. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4478. int err;
  4479. /* disallow open during test */
  4480. if (test_bit(__IXGBE_TESTING, &adapter->state))
  4481. return -EBUSY;
  4482. netif_carrier_off(netdev);
  4483. /* allocate transmit descriptors */
  4484. err = ixgbe_setup_all_tx_resources(adapter);
  4485. if (err)
  4486. goto err_setup_tx;
  4487. /* allocate receive descriptors */
  4488. err = ixgbe_setup_all_rx_resources(adapter);
  4489. if (err)
  4490. goto err_setup_rx;
  4491. ixgbe_configure(adapter);
  4492. err = ixgbe_request_irq(adapter);
  4493. if (err)
  4494. goto err_req_irq;
  4495. err = ixgbe_up_complete(adapter);
  4496. if (err)
  4497. goto err_up;
  4498. netif_tx_start_all_queues(netdev);
  4499. return 0;
  4500. err_up:
  4501. ixgbe_release_hw_control(adapter);
  4502. ixgbe_free_irq(adapter);
  4503. err_req_irq:
  4504. err_setup_rx:
  4505. ixgbe_free_all_rx_resources(adapter);
  4506. err_setup_tx:
  4507. ixgbe_free_all_tx_resources(adapter);
  4508. ixgbe_reset(adapter);
  4509. return err;
  4510. }
  4511. /**
  4512. * ixgbe_close - Disables a network interface
  4513. * @netdev: network interface device structure
  4514. *
  4515. * Returns 0, this is not allowed to fail
  4516. *
  4517. * The close entry point is called when an interface is de-activated
  4518. * by the OS. The hardware is still under the drivers control, but
  4519. * needs to be disabled. A global MAC reset is issued to stop the
  4520. * hardware, and all transmit and receive resources are freed.
  4521. **/
  4522. static int ixgbe_close(struct net_device *netdev)
  4523. {
  4524. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4525. ixgbe_down(adapter);
  4526. ixgbe_free_irq(adapter);
  4527. ixgbe_free_all_tx_resources(adapter);
  4528. ixgbe_free_all_rx_resources(adapter);
  4529. ixgbe_release_hw_control(adapter);
  4530. return 0;
  4531. }
  4532. #ifdef CONFIG_PM
  4533. static int ixgbe_resume(struct pci_dev *pdev)
  4534. {
  4535. struct net_device *netdev = pci_get_drvdata(pdev);
  4536. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4537. u32 err;
  4538. pci_set_power_state(pdev, PCI_D0);
  4539. pci_restore_state(pdev);
  4540. /*
  4541. * pci_restore_state clears dev->state_saved so call
  4542. * pci_save_state to restore it.
  4543. */
  4544. pci_save_state(pdev);
  4545. err = pci_enable_device_mem(pdev);
  4546. if (err) {
  4547. e_dev_err("Cannot enable PCI device from suspend\n");
  4548. return err;
  4549. }
  4550. pci_set_master(pdev);
  4551. pci_wake_from_d3(pdev, false);
  4552. err = ixgbe_init_interrupt_scheme(adapter);
  4553. if (err) {
  4554. e_dev_err("Cannot initialize interrupts for device\n");
  4555. return err;
  4556. }
  4557. ixgbe_reset(adapter);
  4558. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  4559. if (netif_running(netdev)) {
  4560. err = ixgbe_open(adapter->netdev);
  4561. if (err)
  4562. return err;
  4563. }
  4564. netif_device_attach(netdev);
  4565. return 0;
  4566. }
  4567. #endif /* CONFIG_PM */
  4568. static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
  4569. {
  4570. struct net_device *netdev = pci_get_drvdata(pdev);
  4571. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4572. struct ixgbe_hw *hw = &adapter->hw;
  4573. u32 ctrl, fctrl;
  4574. u32 wufc = adapter->wol;
  4575. #ifdef CONFIG_PM
  4576. int retval = 0;
  4577. #endif
  4578. netif_device_detach(netdev);
  4579. if (netif_running(netdev)) {
  4580. ixgbe_down(adapter);
  4581. ixgbe_free_irq(adapter);
  4582. ixgbe_free_all_tx_resources(adapter);
  4583. ixgbe_free_all_rx_resources(adapter);
  4584. }
  4585. #ifdef CONFIG_PM
  4586. retval = pci_save_state(pdev);
  4587. if (retval)
  4588. return retval;
  4589. #endif
  4590. if (wufc) {
  4591. ixgbe_set_rx_mode(netdev);
  4592. /* turn on all-multi mode if wake on multicast is enabled */
  4593. if (wufc & IXGBE_WUFC_MC) {
  4594. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  4595. fctrl |= IXGBE_FCTRL_MPE;
  4596. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  4597. }
  4598. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  4599. ctrl |= IXGBE_CTRL_GIO_DIS;
  4600. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  4601. IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
  4602. } else {
  4603. IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
  4604. IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
  4605. }
  4606. if (wufc && hw->mac.type == ixgbe_mac_82599EB)
  4607. pci_wake_from_d3(pdev, true);
  4608. else
  4609. pci_wake_from_d3(pdev, false);
  4610. *enable_wake = !!wufc;
  4611. ixgbe_clear_interrupt_scheme(adapter);
  4612. ixgbe_release_hw_control(adapter);
  4613. pci_disable_device(pdev);
  4614. return 0;
  4615. }
  4616. #ifdef CONFIG_PM
  4617. static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
  4618. {
  4619. int retval;
  4620. bool wake;
  4621. retval = __ixgbe_shutdown(pdev, &wake);
  4622. if (retval)
  4623. return retval;
  4624. if (wake) {
  4625. pci_prepare_to_sleep(pdev);
  4626. } else {
  4627. pci_wake_from_d3(pdev, false);
  4628. pci_set_power_state(pdev, PCI_D3hot);
  4629. }
  4630. return 0;
  4631. }
  4632. #endif /* CONFIG_PM */
  4633. static void ixgbe_shutdown(struct pci_dev *pdev)
  4634. {
  4635. bool wake;
  4636. __ixgbe_shutdown(pdev, &wake);
  4637. if (system_state == SYSTEM_POWER_OFF) {
  4638. pci_wake_from_d3(pdev, wake);
  4639. pci_set_power_state(pdev, PCI_D3hot);
  4640. }
  4641. }
  4642. /**
  4643. * ixgbe_update_stats - Update the board statistics counters.
  4644. * @adapter: board private structure
  4645. **/
  4646. void ixgbe_update_stats(struct ixgbe_adapter *adapter)
  4647. {
  4648. struct net_device *netdev = adapter->netdev;
  4649. struct ixgbe_hw *hw = &adapter->hw;
  4650. u64 total_mpc = 0;
  4651. u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
  4652. u64 non_eop_descs = 0, restart_queue = 0;
  4653. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  4654. test_bit(__IXGBE_RESETTING, &adapter->state))
  4655. return;
  4656. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  4657. u64 rsc_count = 0;
  4658. u64 rsc_flush = 0;
  4659. for (i = 0; i < 16; i++)
  4660. adapter->hw_rx_no_dma_resources +=
  4661. IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  4662. for (i = 0; i < adapter->num_rx_queues; i++) {
  4663. rsc_count += adapter->rx_ring[i]->rsc_count;
  4664. rsc_flush += adapter->rx_ring[i]->rsc_flush;
  4665. }
  4666. adapter->rsc_total_count = rsc_count;
  4667. adapter->rsc_total_flush = rsc_flush;
  4668. }
  4669. /* gather some stats to the adapter struct that are per queue */
  4670. for (i = 0; i < adapter->num_tx_queues; i++)
  4671. restart_queue += adapter->tx_ring[i]->restart_queue;
  4672. adapter->restart_queue = restart_queue;
  4673. for (i = 0; i < adapter->num_rx_queues; i++)
  4674. non_eop_descs += adapter->rx_ring[i]->non_eop_descs;
  4675. adapter->non_eop_descs = non_eop_descs;
  4676. adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  4677. for (i = 0; i < 8; i++) {
  4678. /* for packet buffers not used, the register should read 0 */
  4679. mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
  4680. missed_rx += mpc;
  4681. adapter->stats.mpc[i] += mpc;
  4682. total_mpc += adapter->stats.mpc[i];
  4683. if (hw->mac.type == ixgbe_mac_82598EB)
  4684. adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  4685. adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  4686. adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  4687. adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  4688. adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  4689. if (hw->mac.type == ixgbe_mac_82599EB) {
  4690. adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
  4691. IXGBE_PXONRXCNT(i));
  4692. adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
  4693. IXGBE_PXOFFRXCNT(i));
  4694. adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  4695. } else {
  4696. adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
  4697. IXGBE_PXONRXC(i));
  4698. adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
  4699. IXGBE_PXOFFRXC(i));
  4700. }
  4701. adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
  4702. IXGBE_PXONTXC(i));
  4703. adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
  4704. IXGBE_PXOFFTXC(i));
  4705. }
  4706. adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
  4707. /* work around hardware counting issue */
  4708. adapter->stats.gprc -= missed_rx;
  4709. /* 82598 hardware only has a 32 bit counter in the high register */
  4710. if (hw->mac.type == ixgbe_mac_82599EB) {
  4711. u64 tmp;
  4712. adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
  4713. tmp = IXGBE_READ_REG(hw, IXGBE_GORCH) & 0xF; /* 4 high bits of GORC */
  4714. adapter->stats.gorc += (tmp << 32);
  4715. adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
  4716. tmp = IXGBE_READ_REG(hw, IXGBE_GOTCH) & 0xF; /* 4 high bits of GOTC */
  4717. adapter->stats.gotc += (tmp << 32);
  4718. adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
  4719. IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
  4720. adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
  4721. adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
  4722. adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  4723. adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  4724. #ifdef IXGBE_FCOE
  4725. adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
  4726. adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
  4727. adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
  4728. adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
  4729. adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
  4730. adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
  4731. #endif /* IXGBE_FCOE */
  4732. } else {
  4733. adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  4734. adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  4735. adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
  4736. adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
  4737. adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
  4738. }
  4739. bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
  4740. adapter->stats.bprc += bprc;
  4741. adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
  4742. if (hw->mac.type == ixgbe_mac_82598EB)
  4743. adapter->stats.mprc -= bprc;
  4744. adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
  4745. adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
  4746. adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
  4747. adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
  4748. adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
  4749. adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
  4750. adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
  4751. adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
  4752. lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  4753. adapter->stats.lxontxc += lxon;
  4754. lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  4755. adapter->stats.lxofftxc += lxoff;
  4756. adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
  4757. adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
  4758. adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
  4759. /*
  4760. * 82598 errata - tx of flow control packets is included in tx counters
  4761. */
  4762. xon_off_tot = lxon + lxoff;
  4763. adapter->stats.gptc -= xon_off_tot;
  4764. adapter->stats.mptc -= xon_off_tot;
  4765. adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
  4766. adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
  4767. adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
  4768. adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
  4769. adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
  4770. adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
  4771. adapter->stats.ptc64 -= xon_off_tot;
  4772. adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
  4773. adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
  4774. adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
  4775. adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
  4776. adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
  4777. adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
  4778. /* Fill out the OS statistics structure */
  4779. netdev->stats.multicast = adapter->stats.mprc;
  4780. /* Rx Errors */
  4781. netdev->stats.rx_errors = adapter->stats.crcerrs +
  4782. adapter->stats.rlec;
  4783. netdev->stats.rx_dropped = 0;
  4784. netdev->stats.rx_length_errors = adapter->stats.rlec;
  4785. netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
  4786. netdev->stats.rx_missed_errors = total_mpc;
  4787. }
  4788. /**
  4789. * ixgbe_watchdog - Timer Call-back
  4790. * @data: pointer to adapter cast into an unsigned long
  4791. **/
  4792. static void ixgbe_watchdog(unsigned long data)
  4793. {
  4794. struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
  4795. struct ixgbe_hw *hw = &adapter->hw;
  4796. u64 eics = 0;
  4797. int i;
  4798. /*
  4799. * Do the watchdog outside of interrupt context due to the lovely
  4800. * delays that some of the newer hardware requires
  4801. */
  4802. if (test_bit(__IXGBE_DOWN, &adapter->state))
  4803. goto watchdog_short_circuit;
  4804. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  4805. /*
  4806. * for legacy and MSI interrupts don't set any bits
  4807. * that are enabled for EIAM, because this operation
  4808. * would set *both* EIMS and EICS for any bit in EIAM
  4809. */
  4810. IXGBE_WRITE_REG(hw, IXGBE_EICS,
  4811. (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
  4812. goto watchdog_reschedule;
  4813. }
  4814. /* get one bit for every active tx/rx interrupt vector */
  4815. for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
  4816. struct ixgbe_q_vector *qv = adapter->q_vector[i];
  4817. if (qv->rxr_count || qv->txr_count)
  4818. eics |= ((u64)1 << i);
  4819. }
  4820. /* Cause software interrupt to ensure rx rings are cleaned */
  4821. ixgbe_irq_rearm_queues(adapter, eics);
  4822. watchdog_reschedule:
  4823. /* Reset the timer */
  4824. mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
  4825. watchdog_short_circuit:
  4826. schedule_work(&adapter->watchdog_task);
  4827. }
  4828. /**
  4829. * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
  4830. * @work: pointer to work_struct containing our data
  4831. **/
  4832. static void ixgbe_multispeed_fiber_task(struct work_struct *work)
  4833. {
  4834. struct ixgbe_adapter *adapter = container_of(work,
  4835. struct ixgbe_adapter,
  4836. multispeed_fiber_task);
  4837. struct ixgbe_hw *hw = &adapter->hw;
  4838. u32 autoneg;
  4839. bool negotiation;
  4840. adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
  4841. autoneg = hw->phy.autoneg_advertised;
  4842. if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
  4843. hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
  4844. hw->mac.autotry_restart = false;
  4845. if (hw->mac.ops.setup_link)
  4846. hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
  4847. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  4848. adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
  4849. }
  4850. /**
  4851. * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
  4852. * @work: pointer to work_struct containing our data
  4853. **/
  4854. static void ixgbe_sfp_config_module_task(struct work_struct *work)
  4855. {
  4856. struct ixgbe_adapter *adapter = container_of(work,
  4857. struct ixgbe_adapter,
  4858. sfp_config_module_task);
  4859. struct ixgbe_hw *hw = &adapter->hw;
  4860. u32 err;
  4861. adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
  4862. /* Time for electrical oscillations to settle down */
  4863. msleep(100);
  4864. err = hw->phy.ops.identify_sfp(hw);
  4865. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  4866. e_dev_err("failed to initialize because an unsupported SFP+ "
  4867. "module type was detected.\n");
  4868. e_dev_err("Reload the driver after installing a supported "
  4869. "module.\n");
  4870. unregister_netdev(adapter->netdev);
  4871. return;
  4872. }
  4873. hw->mac.ops.setup_sfp(hw);
  4874. if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
  4875. /* This will also work for DA Twinax connections */
  4876. schedule_work(&adapter->multispeed_fiber_task);
  4877. adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
  4878. }
  4879. /**
  4880. * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
  4881. * @work: pointer to work_struct containing our data
  4882. **/
  4883. static void ixgbe_fdir_reinit_task(struct work_struct *work)
  4884. {
  4885. struct ixgbe_adapter *adapter = container_of(work,
  4886. struct ixgbe_adapter,
  4887. fdir_reinit_task);
  4888. struct ixgbe_hw *hw = &adapter->hw;
  4889. int i;
  4890. if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
  4891. for (i = 0; i < adapter->num_tx_queues; i++)
  4892. set_bit(__IXGBE_FDIR_INIT_DONE,
  4893. &(adapter->tx_ring[i]->reinit_state));
  4894. } else {
  4895. e_err(probe, "failed to finish FDIR re-initialization, "
  4896. "ignored adding FDIR ATR filters\n");
  4897. }
  4898. /* Done FDIR Re-initialization, enable transmits */
  4899. netif_tx_start_all_queues(adapter->netdev);
  4900. }
  4901. static DEFINE_MUTEX(ixgbe_watchdog_lock);
  4902. /**
  4903. * ixgbe_watchdog_task - worker thread to bring link up
  4904. * @work: pointer to work_struct containing our data
  4905. **/
  4906. static void ixgbe_watchdog_task(struct work_struct *work)
  4907. {
  4908. struct ixgbe_adapter *adapter = container_of(work,
  4909. struct ixgbe_adapter,
  4910. watchdog_task);
  4911. struct net_device *netdev = adapter->netdev;
  4912. struct ixgbe_hw *hw = &adapter->hw;
  4913. u32 link_speed;
  4914. bool link_up;
  4915. int i;
  4916. struct ixgbe_ring *tx_ring;
  4917. int some_tx_pending = 0;
  4918. mutex_lock(&ixgbe_watchdog_lock);
  4919. link_up = adapter->link_up;
  4920. link_speed = adapter->link_speed;
  4921. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
  4922. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  4923. if (link_up) {
  4924. #ifdef CONFIG_DCB
  4925. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  4926. for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
  4927. hw->mac.ops.fc_enable(hw, i);
  4928. } else {
  4929. hw->mac.ops.fc_enable(hw, 0);
  4930. }
  4931. #else
  4932. hw->mac.ops.fc_enable(hw, 0);
  4933. #endif
  4934. }
  4935. if (link_up ||
  4936. time_after(jiffies, (adapter->link_check_timeout +
  4937. IXGBE_TRY_LINK_TIMEOUT))) {
  4938. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  4939. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
  4940. }
  4941. adapter->link_up = link_up;
  4942. adapter->link_speed = link_speed;
  4943. }
  4944. if (link_up) {
  4945. if (!netif_carrier_ok(netdev)) {
  4946. bool flow_rx, flow_tx;
  4947. if (hw->mac.type == ixgbe_mac_82599EB) {
  4948. u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  4949. u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  4950. flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
  4951. flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
  4952. } else {
  4953. u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  4954. u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
  4955. flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
  4956. flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
  4957. }
  4958. e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
  4959. (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
  4960. "10 Gbps" :
  4961. (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
  4962. "1 Gbps" : "unknown speed")),
  4963. ((flow_rx && flow_tx) ? "RX/TX" :
  4964. (flow_rx ? "RX" :
  4965. (flow_tx ? "TX" : "None"))));
  4966. netif_carrier_on(netdev);
  4967. } else {
  4968. /* Force detection of hung controller */
  4969. adapter->detect_tx_hung = true;
  4970. }
  4971. } else {
  4972. adapter->link_up = false;
  4973. adapter->link_speed = 0;
  4974. if (netif_carrier_ok(netdev)) {
  4975. e_info(drv, "NIC Link is Down\n");
  4976. netif_carrier_off(netdev);
  4977. }
  4978. }
  4979. if (!netif_carrier_ok(netdev)) {
  4980. for (i = 0; i < adapter->num_tx_queues; i++) {
  4981. tx_ring = adapter->tx_ring[i];
  4982. if (tx_ring->next_to_use != tx_ring->next_to_clean) {
  4983. some_tx_pending = 1;
  4984. break;
  4985. }
  4986. }
  4987. if (some_tx_pending) {
  4988. /* We've lost link, so the controller stops DMA,
  4989. * but we've got queued Tx work that's never going
  4990. * to get done, so reset controller to flush Tx.
  4991. * (Do the reset outside of interrupt context).
  4992. */
  4993. schedule_work(&adapter->reset_task);
  4994. }
  4995. }
  4996. ixgbe_update_stats(adapter);
  4997. mutex_unlock(&ixgbe_watchdog_lock);
  4998. }
  4999. static int ixgbe_tso(struct ixgbe_adapter *adapter,
  5000. struct ixgbe_ring *tx_ring, struct sk_buff *skb,
  5001. u32 tx_flags, u8 *hdr_len)
  5002. {
  5003. struct ixgbe_adv_tx_context_desc *context_desc;
  5004. unsigned int i;
  5005. int err;
  5006. struct ixgbe_tx_buffer *tx_buffer_info;
  5007. u32 vlan_macip_lens = 0, type_tucmd_mlhl;
  5008. u32 mss_l4len_idx, l4len;
  5009. if (skb_is_gso(skb)) {
  5010. if (skb_header_cloned(skb)) {
  5011. err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  5012. if (err)
  5013. return err;
  5014. }
  5015. l4len = tcp_hdrlen(skb);
  5016. *hdr_len += l4len;
  5017. if (skb->protocol == htons(ETH_P_IP)) {
  5018. struct iphdr *iph = ip_hdr(skb);
  5019. iph->tot_len = 0;
  5020. iph->check = 0;
  5021. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  5022. iph->daddr, 0,
  5023. IPPROTO_TCP,
  5024. 0);
  5025. } else if (skb_is_gso_v6(skb)) {
  5026. ipv6_hdr(skb)->payload_len = 0;
  5027. tcp_hdr(skb)->check =
  5028. ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  5029. &ipv6_hdr(skb)->daddr,
  5030. 0, IPPROTO_TCP, 0);
  5031. }
  5032. i = tx_ring->next_to_use;
  5033. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  5034. context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
  5035. /* VLAN MACLEN IPLEN */
  5036. if (tx_flags & IXGBE_TX_FLAGS_VLAN)
  5037. vlan_macip_lens |=
  5038. (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
  5039. vlan_macip_lens |= ((skb_network_offset(skb)) <<
  5040. IXGBE_ADVTXD_MACLEN_SHIFT);
  5041. *hdr_len += skb_network_offset(skb);
  5042. vlan_macip_lens |=
  5043. (skb_transport_header(skb) - skb_network_header(skb));
  5044. *hdr_len +=
  5045. (skb_transport_header(skb) - skb_network_header(skb));
  5046. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  5047. context_desc->seqnum_seed = 0;
  5048. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  5049. type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
  5050. IXGBE_ADVTXD_DTYP_CTXT);
  5051. if (skb->protocol == htons(ETH_P_IP))
  5052. type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
  5053. type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
  5054. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
  5055. /* MSS L4LEN IDX */
  5056. mss_l4len_idx =
  5057. (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
  5058. mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
  5059. /* use index 1 for TSO */
  5060. mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
  5061. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  5062. tx_buffer_info->time_stamp = jiffies;
  5063. tx_buffer_info->next_to_watch = i;
  5064. i++;
  5065. if (i == tx_ring->count)
  5066. i = 0;
  5067. tx_ring->next_to_use = i;
  5068. return true;
  5069. }
  5070. return false;
  5071. }
  5072. static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
  5073. struct ixgbe_ring *tx_ring,
  5074. struct sk_buff *skb, u32 tx_flags)
  5075. {
  5076. struct ixgbe_adv_tx_context_desc *context_desc;
  5077. unsigned int i;
  5078. struct ixgbe_tx_buffer *tx_buffer_info;
  5079. u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
  5080. if (skb->ip_summed == CHECKSUM_PARTIAL ||
  5081. (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
  5082. i = tx_ring->next_to_use;
  5083. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  5084. context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
  5085. if (tx_flags & IXGBE_TX_FLAGS_VLAN)
  5086. vlan_macip_lens |=
  5087. (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
  5088. vlan_macip_lens |= (skb_network_offset(skb) <<
  5089. IXGBE_ADVTXD_MACLEN_SHIFT);
  5090. if (skb->ip_summed == CHECKSUM_PARTIAL)
  5091. vlan_macip_lens |= (skb_transport_header(skb) -
  5092. skb_network_header(skb));
  5093. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  5094. context_desc->seqnum_seed = 0;
  5095. type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
  5096. IXGBE_ADVTXD_DTYP_CTXT);
  5097. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  5098. __be16 protocol;
  5099. if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) {
  5100. const struct vlan_ethhdr *vhdr =
  5101. (const struct vlan_ethhdr *)skb->data;
  5102. protocol = vhdr->h_vlan_encapsulated_proto;
  5103. } else {
  5104. protocol = skb->protocol;
  5105. }
  5106. switch (protocol) {
  5107. case cpu_to_be16(ETH_P_IP):
  5108. type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
  5109. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  5110. type_tucmd_mlhl |=
  5111. IXGBE_ADVTXD_TUCMD_L4T_TCP;
  5112. else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
  5113. type_tucmd_mlhl |=
  5114. IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  5115. break;
  5116. case cpu_to_be16(ETH_P_IPV6):
  5117. /* XXX what about other V6 headers?? */
  5118. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  5119. type_tucmd_mlhl |=
  5120. IXGBE_ADVTXD_TUCMD_L4T_TCP;
  5121. else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
  5122. type_tucmd_mlhl |=
  5123. IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  5124. break;
  5125. default:
  5126. if (unlikely(net_ratelimit())) {
  5127. e_warn(probe, "partial checksum "
  5128. "but proto=%x!\n",
  5129. skb->protocol);
  5130. }
  5131. break;
  5132. }
  5133. }
  5134. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
  5135. /* use index zero for tx checksum offload */
  5136. context_desc->mss_l4len_idx = 0;
  5137. tx_buffer_info->time_stamp = jiffies;
  5138. tx_buffer_info->next_to_watch = i;
  5139. i++;
  5140. if (i == tx_ring->count)
  5141. i = 0;
  5142. tx_ring->next_to_use = i;
  5143. return true;
  5144. }
  5145. return false;
  5146. }
  5147. static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
  5148. struct ixgbe_ring *tx_ring,
  5149. struct sk_buff *skb, u32 tx_flags,
  5150. unsigned int first)
  5151. {
  5152. struct pci_dev *pdev = adapter->pdev;
  5153. struct ixgbe_tx_buffer *tx_buffer_info;
  5154. unsigned int len;
  5155. unsigned int total = skb->len;
  5156. unsigned int offset = 0, size, count = 0, i;
  5157. unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
  5158. unsigned int f;
  5159. i = tx_ring->next_to_use;
  5160. if (tx_flags & IXGBE_TX_FLAGS_FCOE)
  5161. /* excluding fcoe_crc_eof for FCoE */
  5162. total -= sizeof(struct fcoe_crc_eof);
  5163. len = min(skb_headlen(skb), total);
  5164. while (len) {
  5165. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  5166. size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
  5167. tx_buffer_info->length = size;
  5168. tx_buffer_info->mapped_as_page = false;
  5169. tx_buffer_info->dma = dma_map_single(&pdev->dev,
  5170. skb->data + offset,
  5171. size, DMA_TO_DEVICE);
  5172. if (dma_mapping_error(&pdev->dev, tx_buffer_info->dma))
  5173. goto dma_error;
  5174. tx_buffer_info->time_stamp = jiffies;
  5175. tx_buffer_info->next_to_watch = i;
  5176. len -= size;
  5177. total -= size;
  5178. offset += size;
  5179. count++;
  5180. if (len) {
  5181. i++;
  5182. if (i == tx_ring->count)
  5183. i = 0;
  5184. }
  5185. }
  5186. for (f = 0; f < nr_frags; f++) {
  5187. struct skb_frag_struct *frag;
  5188. frag = &skb_shinfo(skb)->frags[f];
  5189. len = min((unsigned int)frag->size, total);
  5190. offset = frag->page_offset;
  5191. while (len) {
  5192. i++;
  5193. if (i == tx_ring->count)
  5194. i = 0;
  5195. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  5196. size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
  5197. tx_buffer_info->length = size;
  5198. tx_buffer_info->dma = dma_map_page(&adapter->pdev->dev,
  5199. frag->page,
  5200. offset, size,
  5201. DMA_TO_DEVICE);
  5202. tx_buffer_info->mapped_as_page = true;
  5203. if (dma_mapping_error(&pdev->dev, tx_buffer_info->dma))
  5204. goto dma_error;
  5205. tx_buffer_info->time_stamp = jiffies;
  5206. tx_buffer_info->next_to_watch = i;
  5207. len -= size;
  5208. total -= size;
  5209. offset += size;
  5210. count++;
  5211. }
  5212. if (total == 0)
  5213. break;
  5214. }
  5215. tx_ring->tx_buffer_info[i].skb = skb;
  5216. tx_ring->tx_buffer_info[first].next_to_watch = i;
  5217. return count;
  5218. dma_error:
  5219. e_dev_err("TX DMA map failed\n");
  5220. /* clear timestamp and dma mappings for failed tx_buffer_info map */
  5221. tx_buffer_info->dma = 0;
  5222. tx_buffer_info->time_stamp = 0;
  5223. tx_buffer_info->next_to_watch = 0;
  5224. if (count)
  5225. count--;
  5226. /* clear timestamp and dma mappings for remaining portion of packet */
  5227. while (count--) {
  5228. if (i==0)
  5229. i += tx_ring->count;
  5230. i--;
  5231. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  5232. ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
  5233. }
  5234. return 0;
  5235. }
  5236. static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
  5237. struct ixgbe_ring *tx_ring,
  5238. int tx_flags, int count, u32 paylen, u8 hdr_len)
  5239. {
  5240. union ixgbe_adv_tx_desc *tx_desc = NULL;
  5241. struct ixgbe_tx_buffer *tx_buffer_info;
  5242. u32 olinfo_status = 0, cmd_type_len = 0;
  5243. unsigned int i;
  5244. u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
  5245. cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
  5246. cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
  5247. if (tx_flags & IXGBE_TX_FLAGS_VLAN)
  5248. cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
  5249. if (tx_flags & IXGBE_TX_FLAGS_TSO) {
  5250. cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
  5251. olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
  5252. IXGBE_ADVTXD_POPTS_SHIFT;
  5253. /* use index 1 context for tso */
  5254. olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
  5255. if (tx_flags & IXGBE_TX_FLAGS_IPV4)
  5256. olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
  5257. IXGBE_ADVTXD_POPTS_SHIFT;
  5258. } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
  5259. olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
  5260. IXGBE_ADVTXD_POPTS_SHIFT;
  5261. if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
  5262. olinfo_status |= IXGBE_ADVTXD_CC;
  5263. olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
  5264. if (tx_flags & IXGBE_TX_FLAGS_FSO)
  5265. cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
  5266. }
  5267. olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
  5268. i = tx_ring->next_to_use;
  5269. while (count--) {
  5270. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  5271. tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
  5272. tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
  5273. tx_desc->read.cmd_type_len =
  5274. cpu_to_le32(cmd_type_len | tx_buffer_info->length);
  5275. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  5276. i++;
  5277. if (i == tx_ring->count)
  5278. i = 0;
  5279. }
  5280. tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
  5281. /*
  5282. * Force memory writes to complete before letting h/w
  5283. * know there are new descriptors to fetch. (Only
  5284. * applicable for weak-ordered memory model archs,
  5285. * such as IA-64).
  5286. */
  5287. wmb();
  5288. tx_ring->next_to_use = i;
  5289. writel(i, adapter->hw.hw_addr + tx_ring->tail);
  5290. }
  5291. static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb,
  5292. int queue, u32 tx_flags)
  5293. {
  5294. struct ixgbe_atr_input atr_input;
  5295. struct tcphdr *th;
  5296. struct iphdr *iph = ip_hdr(skb);
  5297. struct ethhdr *eth = (struct ethhdr *)skb->data;
  5298. u16 vlan_id, src_port, dst_port, flex_bytes;
  5299. u32 src_ipv4_addr, dst_ipv4_addr;
  5300. u8 l4type = 0;
  5301. /* Right now, we support IPv4 only */
  5302. if (skb->protocol != htons(ETH_P_IP))
  5303. return;
  5304. /* check if we're UDP or TCP */
  5305. if (iph->protocol == IPPROTO_TCP) {
  5306. th = tcp_hdr(skb);
  5307. src_port = th->source;
  5308. dst_port = th->dest;
  5309. l4type |= IXGBE_ATR_L4TYPE_TCP;
  5310. /* l4type IPv4 type is 0, no need to assign */
  5311. } else {
  5312. /* Unsupported L4 header, just bail here */
  5313. return;
  5314. }
  5315. memset(&atr_input, 0, sizeof(struct ixgbe_atr_input));
  5316. vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >>
  5317. IXGBE_TX_FLAGS_VLAN_SHIFT;
  5318. src_ipv4_addr = iph->saddr;
  5319. dst_ipv4_addr = iph->daddr;
  5320. flex_bytes = eth->h_proto;
  5321. ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id);
  5322. ixgbe_atr_set_src_port_82599(&atr_input, dst_port);
  5323. ixgbe_atr_set_dst_port_82599(&atr_input, src_port);
  5324. ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes);
  5325. ixgbe_atr_set_l4type_82599(&atr_input, l4type);
  5326. /* src and dst are inverted, think how the receiver sees them */
  5327. ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr);
  5328. ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr);
  5329. /* This assumes the Rx queue and Tx queue are bound to the same CPU */
  5330. ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue);
  5331. }
  5332. static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
  5333. struct ixgbe_ring *tx_ring, int size)
  5334. {
  5335. netif_stop_subqueue(netdev, tx_ring->queue_index);
  5336. /* Herbert's original patch had:
  5337. * smp_mb__after_netif_stop_queue();
  5338. * but since that doesn't exist yet, just open code it. */
  5339. smp_mb();
  5340. /* We need to check again in a case another CPU has just
  5341. * made room available. */
  5342. if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
  5343. return -EBUSY;
  5344. /* A reprieve! - use start_queue because it doesn't call schedule */
  5345. netif_start_subqueue(netdev, tx_ring->queue_index);
  5346. ++tx_ring->restart_queue;
  5347. return 0;
  5348. }
  5349. static int ixgbe_maybe_stop_tx(struct net_device *netdev,
  5350. struct ixgbe_ring *tx_ring, int size)
  5351. {
  5352. if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
  5353. return 0;
  5354. return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
  5355. }
  5356. static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
  5357. {
  5358. struct ixgbe_adapter *adapter = netdev_priv(dev);
  5359. int txq = smp_processor_id();
  5360. #ifdef IXGBE_FCOE
  5361. if ((skb->protocol == htons(ETH_P_FCOE)) ||
  5362. (skb->protocol == htons(ETH_P_FIP))) {
  5363. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  5364. txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
  5365. txq += adapter->ring_feature[RING_F_FCOE].mask;
  5366. return txq;
  5367. #ifdef CONFIG_IXGBE_DCB
  5368. } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  5369. txq = adapter->fcoe.up;
  5370. return txq;
  5371. #endif
  5372. }
  5373. }
  5374. #endif
  5375. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  5376. while (unlikely(txq >= dev->real_num_tx_queues))
  5377. txq -= dev->real_num_tx_queues;
  5378. return txq;
  5379. }
  5380. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  5381. if (skb->priority == TC_PRIO_CONTROL)
  5382. txq = adapter->ring_feature[RING_F_DCB].indices-1;
  5383. else
  5384. txq = (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK)
  5385. >> 13;
  5386. return txq;
  5387. }
  5388. return skb_tx_hash(dev, skb);
  5389. }
  5390. static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
  5391. struct net_device *netdev)
  5392. {
  5393. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5394. struct ixgbe_ring *tx_ring;
  5395. struct netdev_queue *txq;
  5396. unsigned int first;
  5397. unsigned int tx_flags = 0;
  5398. u8 hdr_len = 0;
  5399. int tso;
  5400. int count = 0;
  5401. unsigned int f;
  5402. if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
  5403. tx_flags |= vlan_tx_tag_get(skb);
  5404. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  5405. tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
  5406. tx_flags |= ((skb->queue_mapping & 0x7) << 13);
  5407. }
  5408. tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
  5409. tx_flags |= IXGBE_TX_FLAGS_VLAN;
  5410. } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
  5411. skb->priority != TC_PRIO_CONTROL) {
  5412. tx_flags |= ((skb->queue_mapping & 0x7) << 13);
  5413. tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
  5414. tx_flags |= IXGBE_TX_FLAGS_VLAN;
  5415. }
  5416. tx_ring = adapter->tx_ring[skb->queue_mapping];
  5417. #ifdef IXGBE_FCOE
  5418. /* for FCoE with DCB, we force the priority to what
  5419. * was specified by the switch */
  5420. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
  5421. (skb->protocol == htons(ETH_P_FCOE) ||
  5422. skb->protocol == htons(ETH_P_FIP))) {
  5423. #ifdef CONFIG_IXGBE_DCB
  5424. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  5425. tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK
  5426. << IXGBE_TX_FLAGS_VLAN_SHIFT);
  5427. tx_flags |= ((adapter->fcoe.up << 13)
  5428. << IXGBE_TX_FLAGS_VLAN_SHIFT);
  5429. }
  5430. #endif
  5431. /* flag for FCoE offloads */
  5432. if (skb->protocol == htons(ETH_P_FCOE))
  5433. tx_flags |= IXGBE_TX_FLAGS_FCOE;
  5434. }
  5435. #endif
  5436. /* four things can cause us to need a context descriptor */
  5437. if (skb_is_gso(skb) ||
  5438. (skb->ip_summed == CHECKSUM_PARTIAL) ||
  5439. (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
  5440. (tx_flags & IXGBE_TX_FLAGS_FCOE))
  5441. count++;
  5442. count += TXD_USE_COUNT(skb_headlen(skb));
  5443. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
  5444. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
  5445. if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
  5446. adapter->tx_busy++;
  5447. return NETDEV_TX_BUSY;
  5448. }
  5449. first = tx_ring->next_to_use;
  5450. if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
  5451. #ifdef IXGBE_FCOE
  5452. /* setup tx offload for FCoE */
  5453. tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
  5454. if (tso < 0) {
  5455. dev_kfree_skb_any(skb);
  5456. return NETDEV_TX_OK;
  5457. }
  5458. if (tso)
  5459. tx_flags |= IXGBE_TX_FLAGS_FSO;
  5460. #endif /* IXGBE_FCOE */
  5461. } else {
  5462. if (skb->protocol == htons(ETH_P_IP))
  5463. tx_flags |= IXGBE_TX_FLAGS_IPV4;
  5464. tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
  5465. if (tso < 0) {
  5466. dev_kfree_skb_any(skb);
  5467. return NETDEV_TX_OK;
  5468. }
  5469. if (tso)
  5470. tx_flags |= IXGBE_TX_FLAGS_TSO;
  5471. else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
  5472. (skb->ip_summed == CHECKSUM_PARTIAL))
  5473. tx_flags |= IXGBE_TX_FLAGS_CSUM;
  5474. }
  5475. count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first);
  5476. if (count) {
  5477. /* add the ATR filter if ATR is on */
  5478. if (tx_ring->atr_sample_rate) {
  5479. ++tx_ring->atr_count;
  5480. if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) &&
  5481. test_bit(__IXGBE_FDIR_INIT_DONE,
  5482. &tx_ring->reinit_state)) {
  5483. ixgbe_atr(adapter, skb, tx_ring->queue_index,
  5484. tx_flags);
  5485. tx_ring->atr_count = 0;
  5486. }
  5487. }
  5488. txq = netdev_get_tx_queue(netdev, tx_ring->queue_index);
  5489. txq->tx_bytes += skb->len;
  5490. txq->tx_packets++;
  5491. ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len,
  5492. hdr_len);
  5493. ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
  5494. } else {
  5495. dev_kfree_skb_any(skb);
  5496. tx_ring->tx_buffer_info[first].time_stamp = 0;
  5497. tx_ring->next_to_use = first;
  5498. }
  5499. return NETDEV_TX_OK;
  5500. }
  5501. /**
  5502. * ixgbe_set_mac - Change the Ethernet Address of the NIC
  5503. * @netdev: network interface device structure
  5504. * @p: pointer to an address structure
  5505. *
  5506. * Returns 0 on success, negative on failure
  5507. **/
  5508. static int ixgbe_set_mac(struct net_device *netdev, void *p)
  5509. {
  5510. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5511. struct ixgbe_hw *hw = &adapter->hw;
  5512. struct sockaddr *addr = p;
  5513. if (!is_valid_ether_addr(addr->sa_data))
  5514. return -EADDRNOTAVAIL;
  5515. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  5516. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  5517. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
  5518. IXGBE_RAH_AV);
  5519. return 0;
  5520. }
  5521. static int
  5522. ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
  5523. {
  5524. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5525. struct ixgbe_hw *hw = &adapter->hw;
  5526. u16 value;
  5527. int rc;
  5528. if (prtad != hw->phy.mdio.prtad)
  5529. return -EINVAL;
  5530. rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
  5531. if (!rc)
  5532. rc = value;
  5533. return rc;
  5534. }
  5535. static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
  5536. u16 addr, u16 value)
  5537. {
  5538. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5539. struct ixgbe_hw *hw = &adapter->hw;
  5540. if (prtad != hw->phy.mdio.prtad)
  5541. return -EINVAL;
  5542. return hw->phy.ops.write_reg(hw, addr, devad, value);
  5543. }
  5544. static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
  5545. {
  5546. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5547. return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
  5548. }
  5549. /**
  5550. * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
  5551. * netdev->dev_addrs
  5552. * @netdev: network interface device structure
  5553. *
  5554. * Returns non-zero on failure
  5555. **/
  5556. static int ixgbe_add_sanmac_netdev(struct net_device *dev)
  5557. {
  5558. int err = 0;
  5559. struct ixgbe_adapter *adapter = netdev_priv(dev);
  5560. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  5561. if (is_valid_ether_addr(mac->san_addr)) {
  5562. rtnl_lock();
  5563. err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
  5564. rtnl_unlock();
  5565. }
  5566. return err;
  5567. }
  5568. /**
  5569. * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
  5570. * netdev->dev_addrs
  5571. * @netdev: network interface device structure
  5572. *
  5573. * Returns non-zero on failure
  5574. **/
  5575. static int ixgbe_del_sanmac_netdev(struct net_device *dev)
  5576. {
  5577. int err = 0;
  5578. struct ixgbe_adapter *adapter = netdev_priv(dev);
  5579. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  5580. if (is_valid_ether_addr(mac->san_addr)) {
  5581. rtnl_lock();
  5582. err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
  5583. rtnl_unlock();
  5584. }
  5585. return err;
  5586. }
  5587. #ifdef CONFIG_NET_POLL_CONTROLLER
  5588. /*
  5589. * Polling 'interrupt' - used by things like netconsole to send skbs
  5590. * without having to re-enable interrupts. It's not called while
  5591. * the interrupt routine is executing.
  5592. */
  5593. static void ixgbe_netpoll(struct net_device *netdev)
  5594. {
  5595. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5596. int i;
  5597. /* if interface is down do nothing */
  5598. if (test_bit(__IXGBE_DOWN, &adapter->state))
  5599. return;
  5600. adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
  5601. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  5602. int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  5603. for (i = 0; i < num_q_vectors; i++) {
  5604. struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
  5605. ixgbe_msix_clean_many(0, q_vector);
  5606. }
  5607. } else {
  5608. ixgbe_intr(adapter->pdev->irq, netdev);
  5609. }
  5610. adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
  5611. }
  5612. #endif
  5613. static const struct net_device_ops ixgbe_netdev_ops = {
  5614. .ndo_open = ixgbe_open,
  5615. .ndo_stop = ixgbe_close,
  5616. .ndo_start_xmit = ixgbe_xmit_frame,
  5617. .ndo_select_queue = ixgbe_select_queue,
  5618. .ndo_set_rx_mode = ixgbe_set_rx_mode,
  5619. .ndo_set_multicast_list = ixgbe_set_rx_mode,
  5620. .ndo_validate_addr = eth_validate_addr,
  5621. .ndo_set_mac_address = ixgbe_set_mac,
  5622. .ndo_change_mtu = ixgbe_change_mtu,
  5623. .ndo_tx_timeout = ixgbe_tx_timeout,
  5624. .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
  5625. .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
  5626. .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
  5627. .ndo_do_ioctl = ixgbe_ioctl,
  5628. .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
  5629. .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
  5630. .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
  5631. .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
  5632. #ifdef CONFIG_NET_POLL_CONTROLLER
  5633. .ndo_poll_controller = ixgbe_netpoll,
  5634. #endif
  5635. #ifdef IXGBE_FCOE
  5636. .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
  5637. .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
  5638. .ndo_fcoe_enable = ixgbe_fcoe_enable,
  5639. .ndo_fcoe_disable = ixgbe_fcoe_disable,
  5640. .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
  5641. #endif /* IXGBE_FCOE */
  5642. };
  5643. static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
  5644. const struct ixgbe_info *ii)
  5645. {
  5646. #ifdef CONFIG_PCI_IOV
  5647. struct ixgbe_hw *hw = &adapter->hw;
  5648. int err;
  5649. if (hw->mac.type != ixgbe_mac_82599EB || !max_vfs)
  5650. return;
  5651. /* The 82599 supports up to 64 VFs per physical function
  5652. * but this implementation limits allocation to 63 so that
  5653. * basic networking resources are still available to the
  5654. * physical function
  5655. */
  5656. adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
  5657. adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
  5658. err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
  5659. if (err) {
  5660. e_err(probe, "Failed to enable PCI sriov: %d\n", err);
  5661. goto err_novfs;
  5662. }
  5663. /* If call to enable VFs succeeded then allocate memory
  5664. * for per VF control structures.
  5665. */
  5666. adapter->vfinfo =
  5667. kcalloc(adapter->num_vfs,
  5668. sizeof(struct vf_data_storage), GFP_KERNEL);
  5669. if (adapter->vfinfo) {
  5670. /* Now that we're sure SR-IOV is enabled
  5671. * and memory allocated set up the mailbox parameters
  5672. */
  5673. ixgbe_init_mbx_params_pf(hw);
  5674. memcpy(&hw->mbx.ops, ii->mbx_ops,
  5675. sizeof(hw->mbx.ops));
  5676. /* Disable RSC when in SR-IOV mode */
  5677. adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
  5678. IXGBE_FLAG2_RSC_ENABLED);
  5679. return;
  5680. }
  5681. /* Oh oh */
  5682. e_err(probe, "Unable to allocate memory for VF Data Storage - "
  5683. "SRIOV disabled\n");
  5684. pci_disable_sriov(adapter->pdev);
  5685. err_novfs:
  5686. adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
  5687. adapter->num_vfs = 0;
  5688. #endif /* CONFIG_PCI_IOV */
  5689. }
  5690. /**
  5691. * ixgbe_probe - Device Initialization Routine
  5692. * @pdev: PCI device information struct
  5693. * @ent: entry in ixgbe_pci_tbl
  5694. *
  5695. * Returns 0 on success, negative on failure
  5696. *
  5697. * ixgbe_probe initializes an adapter identified by a pci_dev structure.
  5698. * The OS initialization, configuring of the adapter private structure,
  5699. * and a hardware reset occur.
  5700. **/
  5701. static int __devinit ixgbe_probe(struct pci_dev *pdev,
  5702. const struct pci_device_id *ent)
  5703. {
  5704. struct net_device *netdev;
  5705. struct ixgbe_adapter *adapter = NULL;
  5706. struct ixgbe_hw *hw;
  5707. const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
  5708. static int cards_found;
  5709. int i, err, pci_using_dac;
  5710. unsigned int indices = num_possible_cpus();
  5711. #ifdef IXGBE_FCOE
  5712. u16 device_caps;
  5713. #endif
  5714. u32 part_num, eec;
  5715. /* Catch broken hardware that put the wrong VF device ID in
  5716. * the PCIe SR-IOV capability.
  5717. */
  5718. if (pdev->is_virtfn) {
  5719. WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
  5720. pci_name(pdev), pdev->vendor, pdev->device);
  5721. return -EINVAL;
  5722. }
  5723. err = pci_enable_device_mem(pdev);
  5724. if (err)
  5725. return err;
  5726. if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
  5727. !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
  5728. pci_using_dac = 1;
  5729. } else {
  5730. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  5731. if (err) {
  5732. err = dma_set_coherent_mask(&pdev->dev,
  5733. DMA_BIT_MASK(32));
  5734. if (err) {
  5735. dev_err(&pdev->dev,
  5736. "No usable DMA configuration, aborting\n");
  5737. goto err_dma;
  5738. }
  5739. }
  5740. pci_using_dac = 0;
  5741. }
  5742. err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
  5743. IORESOURCE_MEM), ixgbe_driver_name);
  5744. if (err) {
  5745. dev_err(&pdev->dev,
  5746. "pci_request_selected_regions failed 0x%x\n", err);
  5747. goto err_pci_reg;
  5748. }
  5749. pci_enable_pcie_error_reporting(pdev);
  5750. pci_set_master(pdev);
  5751. pci_save_state(pdev);
  5752. if (ii->mac == ixgbe_mac_82598EB)
  5753. indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
  5754. else
  5755. indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
  5756. indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
  5757. #ifdef IXGBE_FCOE
  5758. indices += min_t(unsigned int, num_possible_cpus(),
  5759. IXGBE_MAX_FCOE_INDICES);
  5760. #endif
  5761. netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
  5762. if (!netdev) {
  5763. err = -ENOMEM;
  5764. goto err_alloc_etherdev;
  5765. }
  5766. SET_NETDEV_DEV(netdev, &pdev->dev);
  5767. pci_set_drvdata(pdev, netdev);
  5768. adapter = netdev_priv(netdev);
  5769. adapter->netdev = netdev;
  5770. adapter->pdev = pdev;
  5771. hw = &adapter->hw;
  5772. hw->back = adapter;
  5773. adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
  5774. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  5775. pci_resource_len(pdev, 0));
  5776. if (!hw->hw_addr) {
  5777. err = -EIO;
  5778. goto err_ioremap;
  5779. }
  5780. for (i = 1; i <= 5; i++) {
  5781. if (pci_resource_len(pdev, i) == 0)
  5782. continue;
  5783. }
  5784. netdev->netdev_ops = &ixgbe_netdev_ops;
  5785. ixgbe_set_ethtool_ops(netdev);
  5786. netdev->watchdog_timeo = 5 * HZ;
  5787. strcpy(netdev->name, pci_name(pdev));
  5788. adapter->bd_number = cards_found;
  5789. /* Setup hw api */
  5790. memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
  5791. hw->mac.type = ii->mac;
  5792. /* EEPROM */
  5793. memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
  5794. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  5795. /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
  5796. if (!(eec & (1 << 8)))
  5797. hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
  5798. /* PHY */
  5799. memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
  5800. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  5801. /* ixgbe_identify_phy_generic will set prtad and mmds properly */
  5802. hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
  5803. hw->phy.mdio.mmds = 0;
  5804. hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  5805. hw->phy.mdio.dev = netdev;
  5806. hw->phy.mdio.mdio_read = ixgbe_mdio_read;
  5807. hw->phy.mdio.mdio_write = ixgbe_mdio_write;
  5808. /* set up this timer and work struct before calling get_invariants
  5809. * which might start the timer
  5810. */
  5811. init_timer(&adapter->sfp_timer);
  5812. adapter->sfp_timer.function = &ixgbe_sfp_timer;
  5813. adapter->sfp_timer.data = (unsigned long) adapter;
  5814. INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
  5815. /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
  5816. INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
  5817. /* a new SFP+ module arrival, called from GPI SDP2 context */
  5818. INIT_WORK(&adapter->sfp_config_module_task,
  5819. ixgbe_sfp_config_module_task);
  5820. ii->get_invariants(hw);
  5821. /* setup the private structure */
  5822. err = ixgbe_sw_init(adapter);
  5823. if (err)
  5824. goto err_sw_init;
  5825. /* Make it possible the adapter to be woken up via WOL */
  5826. if (adapter->hw.mac.type == ixgbe_mac_82599EB)
  5827. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  5828. /*
  5829. * If there is a fan on this device and it has failed log the
  5830. * failure.
  5831. */
  5832. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  5833. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  5834. if (esdp & IXGBE_ESDP_SDP1)
  5835. e_crit(probe, "Fan has stopped, replace the adapter\n");
  5836. }
  5837. /* reset_hw fills in the perm_addr as well */
  5838. hw->phy.reset_if_overtemp = true;
  5839. err = hw->mac.ops.reset_hw(hw);
  5840. hw->phy.reset_if_overtemp = false;
  5841. if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
  5842. hw->mac.type == ixgbe_mac_82598EB) {
  5843. /*
  5844. * Start a kernel thread to watch for a module to arrive.
  5845. * Only do this for 82598, since 82599 will generate
  5846. * interrupts on module arrival.
  5847. */
  5848. set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  5849. mod_timer(&adapter->sfp_timer,
  5850. round_jiffies(jiffies + (2 * HZ)));
  5851. err = 0;
  5852. } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  5853. e_dev_err("failed to initialize because an unsupported SFP+ "
  5854. "module type was detected.\n");
  5855. e_dev_err("Reload the driver after installing a supported "
  5856. "module.\n");
  5857. goto err_sw_init;
  5858. } else if (err) {
  5859. e_dev_err("HW Init failed: %d\n", err);
  5860. goto err_sw_init;
  5861. }
  5862. ixgbe_probe_vf(adapter, ii);
  5863. netdev->features = NETIF_F_SG |
  5864. NETIF_F_IP_CSUM |
  5865. NETIF_F_HW_VLAN_TX |
  5866. NETIF_F_HW_VLAN_RX |
  5867. NETIF_F_HW_VLAN_FILTER;
  5868. netdev->features |= NETIF_F_IPV6_CSUM;
  5869. netdev->features |= NETIF_F_TSO;
  5870. netdev->features |= NETIF_F_TSO6;
  5871. netdev->features |= NETIF_F_GRO;
  5872. if (adapter->hw.mac.type == ixgbe_mac_82599EB)
  5873. netdev->features |= NETIF_F_SCTP_CSUM;
  5874. netdev->vlan_features |= NETIF_F_TSO;
  5875. netdev->vlan_features |= NETIF_F_TSO6;
  5876. netdev->vlan_features |= NETIF_F_IP_CSUM;
  5877. netdev->vlan_features |= NETIF_F_IPV6_CSUM;
  5878. netdev->vlan_features |= NETIF_F_SG;
  5879. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  5880. adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
  5881. IXGBE_FLAG_DCB_ENABLED);
  5882. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
  5883. adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
  5884. #ifdef CONFIG_IXGBE_DCB
  5885. netdev->dcbnl_ops = &dcbnl_ops;
  5886. #endif
  5887. #ifdef IXGBE_FCOE
  5888. if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
  5889. if (hw->mac.ops.get_device_caps) {
  5890. hw->mac.ops.get_device_caps(hw, &device_caps);
  5891. if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
  5892. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  5893. }
  5894. }
  5895. if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
  5896. netdev->vlan_features |= NETIF_F_FCOE_CRC;
  5897. netdev->vlan_features |= NETIF_F_FSO;
  5898. netdev->vlan_features |= NETIF_F_FCOE_MTU;
  5899. }
  5900. #endif /* IXGBE_FCOE */
  5901. if (pci_using_dac)
  5902. netdev->features |= NETIF_F_HIGHDMA;
  5903. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  5904. netdev->features |= NETIF_F_LRO;
  5905. /* make sure the EEPROM is good */
  5906. if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
  5907. e_dev_err("The EEPROM Checksum Is Not Valid\n");
  5908. err = -EIO;
  5909. goto err_eeprom;
  5910. }
  5911. memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
  5912. memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
  5913. if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
  5914. e_dev_err("invalid MAC address\n");
  5915. err = -EIO;
  5916. goto err_eeprom;
  5917. }
  5918. /* power down the optics */
  5919. if (hw->phy.multispeed_fiber)
  5920. hw->mac.ops.disable_tx_laser(hw);
  5921. init_timer(&adapter->watchdog_timer);
  5922. adapter->watchdog_timer.function = &ixgbe_watchdog;
  5923. adapter->watchdog_timer.data = (unsigned long)adapter;
  5924. INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
  5925. INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
  5926. err = ixgbe_init_interrupt_scheme(adapter);
  5927. if (err)
  5928. goto err_sw_init;
  5929. switch (pdev->device) {
  5930. case IXGBE_DEV_ID_82599_KX4:
  5931. adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
  5932. IXGBE_WUFC_MC | IXGBE_WUFC_BC);
  5933. break;
  5934. default:
  5935. adapter->wol = 0;
  5936. break;
  5937. }
  5938. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  5939. /* pick up the PCI bus settings for reporting later */
  5940. hw->mac.ops.get_bus_info(hw);
  5941. /* print bus type/speed/width info */
  5942. e_dev_info("(PCI Express:%s:%s) %pM\n",
  5943. ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
  5944. (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
  5945. ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
  5946. (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
  5947. (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
  5948. "Unknown"),
  5949. netdev->dev_addr);
  5950. ixgbe_read_pba_num_generic(hw, &part_num);
  5951. if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
  5952. e_dev_info("MAC: %d, PHY: %d, SFP+: %d, "
  5953. "PBA No: %06x-%03x\n",
  5954. hw->mac.type, hw->phy.type, hw->phy.sfp_type,
  5955. (part_num >> 8), (part_num & 0xff));
  5956. else
  5957. e_dev_info("MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
  5958. hw->mac.type, hw->phy.type,
  5959. (part_num >> 8), (part_num & 0xff));
  5960. if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
  5961. e_dev_warn("PCI-Express bandwidth available for this card is "
  5962. "not sufficient for optimal performance.\n");
  5963. e_dev_warn("For optimal performance a x8 PCI-Express slot "
  5964. "is required.\n");
  5965. }
  5966. /* save off EEPROM version number */
  5967. hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
  5968. /* reset the hardware with the new settings */
  5969. err = hw->mac.ops.start_hw(hw);
  5970. if (err == IXGBE_ERR_EEPROM_VERSION) {
  5971. /* We are running on a pre-production device, log a warning */
  5972. e_dev_warn("This device is a pre-production adapter/LOM. "
  5973. "Please be aware there may be issues associated "
  5974. "with your hardware. If you are experiencing "
  5975. "problems please contact your Intel or hardware "
  5976. "representative who provided you with this "
  5977. "hardware.\n");
  5978. }
  5979. strcpy(netdev->name, "eth%d");
  5980. err = register_netdev(netdev);
  5981. if (err)
  5982. goto err_register;
  5983. /* carrier off reporting is important to ethtool even BEFORE open */
  5984. netif_carrier_off(netdev);
  5985. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  5986. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  5987. INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task);
  5988. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
  5989. INIT_WORK(&adapter->check_overtemp_task, ixgbe_check_overtemp_task);
  5990. #ifdef CONFIG_IXGBE_DCA
  5991. if (dca_add_requester(&pdev->dev) == 0) {
  5992. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  5993. ixgbe_setup_dca(adapter);
  5994. }
  5995. #endif
  5996. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  5997. e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
  5998. for (i = 0; i < adapter->num_vfs; i++)
  5999. ixgbe_vf_configuration(pdev, (i | 0x10000000));
  6000. }
  6001. /* add san mac addr to netdev */
  6002. ixgbe_add_sanmac_netdev(netdev);
  6003. e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
  6004. cards_found++;
  6005. return 0;
  6006. err_register:
  6007. ixgbe_release_hw_control(adapter);
  6008. ixgbe_clear_interrupt_scheme(adapter);
  6009. err_sw_init:
  6010. err_eeprom:
  6011. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  6012. ixgbe_disable_sriov(adapter);
  6013. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  6014. del_timer_sync(&adapter->sfp_timer);
  6015. cancel_work_sync(&adapter->sfp_task);
  6016. cancel_work_sync(&adapter->multispeed_fiber_task);
  6017. cancel_work_sync(&adapter->sfp_config_module_task);
  6018. iounmap(hw->hw_addr);
  6019. err_ioremap:
  6020. free_netdev(netdev);
  6021. err_alloc_etherdev:
  6022. pci_release_selected_regions(pdev, pci_select_bars(pdev,
  6023. IORESOURCE_MEM));
  6024. err_pci_reg:
  6025. err_dma:
  6026. pci_disable_device(pdev);
  6027. return err;
  6028. }
  6029. /**
  6030. * ixgbe_remove - Device Removal Routine
  6031. * @pdev: PCI device information struct
  6032. *
  6033. * ixgbe_remove is called by the PCI subsystem to alert the driver
  6034. * that it should release a PCI device. The could be caused by a
  6035. * Hot-Plug event, or because the driver is going to be removed from
  6036. * memory.
  6037. **/
  6038. static void __devexit ixgbe_remove(struct pci_dev *pdev)
  6039. {
  6040. struct net_device *netdev = pci_get_drvdata(pdev);
  6041. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6042. set_bit(__IXGBE_DOWN, &adapter->state);
  6043. /* clear the module not found bit to make sure the worker won't
  6044. * reschedule
  6045. */
  6046. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  6047. del_timer_sync(&adapter->watchdog_timer);
  6048. del_timer_sync(&adapter->sfp_timer);
  6049. cancel_work_sync(&adapter->watchdog_task);
  6050. cancel_work_sync(&adapter->sfp_task);
  6051. cancel_work_sync(&adapter->multispeed_fiber_task);
  6052. cancel_work_sync(&adapter->sfp_config_module_task);
  6053. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  6054. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  6055. cancel_work_sync(&adapter->fdir_reinit_task);
  6056. flush_scheduled_work();
  6057. #ifdef CONFIG_IXGBE_DCA
  6058. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  6059. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  6060. dca_remove_requester(&pdev->dev);
  6061. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
  6062. }
  6063. #endif
  6064. #ifdef IXGBE_FCOE
  6065. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  6066. ixgbe_cleanup_fcoe(adapter);
  6067. #endif /* IXGBE_FCOE */
  6068. /* remove the added san mac */
  6069. ixgbe_del_sanmac_netdev(netdev);
  6070. if (netdev->reg_state == NETREG_REGISTERED)
  6071. unregister_netdev(netdev);
  6072. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  6073. ixgbe_disable_sriov(adapter);
  6074. ixgbe_clear_interrupt_scheme(adapter);
  6075. ixgbe_release_hw_control(adapter);
  6076. iounmap(adapter->hw.hw_addr);
  6077. pci_release_selected_regions(pdev, pci_select_bars(pdev,
  6078. IORESOURCE_MEM));
  6079. e_dev_info("complete\n");
  6080. free_netdev(netdev);
  6081. pci_disable_pcie_error_reporting(pdev);
  6082. pci_disable_device(pdev);
  6083. }
  6084. /**
  6085. * ixgbe_io_error_detected - called when PCI error is detected
  6086. * @pdev: Pointer to PCI device
  6087. * @state: The current pci connection state
  6088. *
  6089. * This function is called after a PCI bus error affecting
  6090. * this device has been detected.
  6091. */
  6092. static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
  6093. pci_channel_state_t state)
  6094. {
  6095. struct net_device *netdev = pci_get_drvdata(pdev);
  6096. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6097. netif_device_detach(netdev);
  6098. if (state == pci_channel_io_perm_failure)
  6099. return PCI_ERS_RESULT_DISCONNECT;
  6100. if (netif_running(netdev))
  6101. ixgbe_down(adapter);
  6102. pci_disable_device(pdev);
  6103. /* Request a slot reset. */
  6104. return PCI_ERS_RESULT_NEED_RESET;
  6105. }
  6106. /**
  6107. * ixgbe_io_slot_reset - called after the pci bus has been reset.
  6108. * @pdev: Pointer to PCI device
  6109. *
  6110. * Restart the card from scratch, as if from a cold-boot.
  6111. */
  6112. static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
  6113. {
  6114. struct net_device *netdev = pci_get_drvdata(pdev);
  6115. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6116. pci_ers_result_t result;
  6117. int err;
  6118. if (pci_enable_device_mem(pdev)) {
  6119. e_err(probe, "Cannot re-enable PCI device after reset.\n");
  6120. result = PCI_ERS_RESULT_DISCONNECT;
  6121. } else {
  6122. pci_set_master(pdev);
  6123. pci_restore_state(pdev);
  6124. pci_save_state(pdev);
  6125. pci_wake_from_d3(pdev, false);
  6126. ixgbe_reset(adapter);
  6127. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  6128. result = PCI_ERS_RESULT_RECOVERED;
  6129. }
  6130. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  6131. if (err) {
  6132. e_dev_err("pci_cleanup_aer_uncorrect_error_status "
  6133. "failed 0x%0x\n", err);
  6134. /* non-fatal, continue */
  6135. }
  6136. return result;
  6137. }
  6138. /**
  6139. * ixgbe_io_resume - called when traffic can start flowing again.
  6140. * @pdev: Pointer to PCI device
  6141. *
  6142. * This callback is called when the error recovery driver tells us that
  6143. * its OK to resume normal operation.
  6144. */
  6145. static void ixgbe_io_resume(struct pci_dev *pdev)
  6146. {
  6147. struct net_device *netdev = pci_get_drvdata(pdev);
  6148. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6149. if (netif_running(netdev)) {
  6150. if (ixgbe_up(adapter)) {
  6151. e_info(probe, "ixgbe_up failed after reset\n");
  6152. return;
  6153. }
  6154. }
  6155. netif_device_attach(netdev);
  6156. }
  6157. static struct pci_error_handlers ixgbe_err_handler = {
  6158. .error_detected = ixgbe_io_error_detected,
  6159. .slot_reset = ixgbe_io_slot_reset,
  6160. .resume = ixgbe_io_resume,
  6161. };
  6162. static struct pci_driver ixgbe_driver = {
  6163. .name = ixgbe_driver_name,
  6164. .id_table = ixgbe_pci_tbl,
  6165. .probe = ixgbe_probe,
  6166. .remove = __devexit_p(ixgbe_remove),
  6167. #ifdef CONFIG_PM
  6168. .suspend = ixgbe_suspend,
  6169. .resume = ixgbe_resume,
  6170. #endif
  6171. .shutdown = ixgbe_shutdown,
  6172. .err_handler = &ixgbe_err_handler
  6173. };
  6174. /**
  6175. * ixgbe_init_module - Driver Registration Routine
  6176. *
  6177. * ixgbe_init_module is the first routine called when the driver is
  6178. * loaded. All it does is register with the PCI subsystem.
  6179. **/
  6180. static int __init ixgbe_init_module(void)
  6181. {
  6182. int ret;
  6183. pr_info("%s - version %s\n", ixgbe_driver_string,
  6184. ixgbe_driver_version);
  6185. pr_info("%s\n", ixgbe_copyright);
  6186. #ifdef CONFIG_IXGBE_DCA
  6187. dca_register_notify(&dca_notifier);
  6188. #endif
  6189. ret = pci_register_driver(&ixgbe_driver);
  6190. return ret;
  6191. }
  6192. module_init(ixgbe_init_module);
  6193. /**
  6194. * ixgbe_exit_module - Driver Exit Cleanup Routine
  6195. *
  6196. * ixgbe_exit_module is called just before the driver is removed
  6197. * from memory.
  6198. **/
  6199. static void __exit ixgbe_exit_module(void)
  6200. {
  6201. #ifdef CONFIG_IXGBE_DCA
  6202. dca_unregister_notify(&dca_notifier);
  6203. #endif
  6204. pci_unregister_driver(&ixgbe_driver);
  6205. }
  6206. #ifdef CONFIG_IXGBE_DCA
  6207. static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
  6208. void *p)
  6209. {
  6210. int ret_val;
  6211. ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
  6212. __ixgbe_notify_dca);
  6213. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  6214. }
  6215. #endif /* CONFIG_IXGBE_DCA */
  6216. /**
  6217. * ixgbe_get_hw_dev return device
  6218. * used by hardware layer to print debugging information
  6219. **/
  6220. struct net_device *ixgbe_get_hw_dev(struct ixgbe_hw *hw)
  6221. {
  6222. struct ixgbe_adapter *adapter = hw->back;
  6223. return adapter->netdev;
  6224. }
  6225. module_exit(ixgbe_exit_module);
  6226. /* ixgbe_main.c */