ixgbe_main.c 144 KB

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