ixgbe_main.c 162 KB

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