ixgbe_main.c 200 KB

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