ixgbe_main.c 172 KB

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