igb_main.c 120 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472
  1. /*******************************************************************************
  2. Intel(R) Gigabit Ethernet Linux driver
  3. Copyright(c) 2007 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/module.h>
  21. #include <linux/types.h>
  22. #include <linux/init.h>
  23. #include <linux/vmalloc.h>
  24. #include <linux/pagemap.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/ipv6.h>
  27. #include <net/checksum.h>
  28. #include <net/ip6_checksum.h>
  29. #include <linux/mii.h>
  30. #include <linux/ethtool.h>
  31. #include <linux/if_vlan.h>
  32. #include <linux/pci.h>
  33. #include <linux/delay.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/if_ether.h>
  36. #ifdef CONFIG_DCA
  37. #include <linux/dca.h>
  38. #endif
  39. #include "igb.h"
  40. #define DRV_VERSION "1.2.45-k2"
  41. char igb_driver_name[] = "igb";
  42. char igb_driver_version[] = DRV_VERSION;
  43. static const char igb_driver_string[] =
  44. "Intel(R) Gigabit Ethernet Network Driver";
  45. static const char igb_copyright[] = "Copyright (c) 2008 Intel Corporation.";
  46. static const struct e1000_info *igb_info_tbl[] = {
  47. [board_82575] = &e1000_82575_info,
  48. };
  49. static struct pci_device_id igb_pci_tbl[] = {
  50. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576), board_82575 },
  51. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER), board_82575 },
  52. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES), board_82575 },
  53. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER), board_82575 },
  54. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 },
  55. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 },
  56. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 },
  57. /* required last entry */
  58. {0, }
  59. };
  60. MODULE_DEVICE_TABLE(pci, igb_pci_tbl);
  61. void igb_reset(struct igb_adapter *);
  62. static int igb_setup_all_tx_resources(struct igb_adapter *);
  63. static int igb_setup_all_rx_resources(struct igb_adapter *);
  64. static void igb_free_all_tx_resources(struct igb_adapter *);
  65. static void igb_free_all_rx_resources(struct igb_adapter *);
  66. static void igb_free_tx_resources(struct igb_ring *);
  67. static void igb_free_rx_resources(struct igb_ring *);
  68. void igb_update_stats(struct igb_adapter *);
  69. static int igb_probe(struct pci_dev *, const struct pci_device_id *);
  70. static void __devexit igb_remove(struct pci_dev *pdev);
  71. static int igb_sw_init(struct igb_adapter *);
  72. static int igb_open(struct net_device *);
  73. static int igb_close(struct net_device *);
  74. static void igb_configure_tx(struct igb_adapter *);
  75. static void igb_configure_rx(struct igb_adapter *);
  76. static void igb_setup_rctl(struct igb_adapter *);
  77. static void igb_clean_all_tx_rings(struct igb_adapter *);
  78. static void igb_clean_all_rx_rings(struct igb_adapter *);
  79. static void igb_clean_tx_ring(struct igb_ring *);
  80. static void igb_clean_rx_ring(struct igb_ring *);
  81. static void igb_set_multi(struct net_device *);
  82. static void igb_update_phy_info(unsigned long);
  83. static void igb_watchdog(unsigned long);
  84. static void igb_watchdog_task(struct work_struct *);
  85. static int igb_xmit_frame_ring_adv(struct sk_buff *, struct net_device *,
  86. struct igb_ring *);
  87. static int igb_xmit_frame_adv(struct sk_buff *skb, struct net_device *);
  88. static struct net_device_stats *igb_get_stats(struct net_device *);
  89. static int igb_change_mtu(struct net_device *, int);
  90. static int igb_set_mac(struct net_device *, void *);
  91. static irqreturn_t igb_intr(int irq, void *);
  92. static irqreturn_t igb_intr_msi(int irq, void *);
  93. static irqreturn_t igb_msix_other(int irq, void *);
  94. static irqreturn_t igb_msix_rx(int irq, void *);
  95. static irqreturn_t igb_msix_tx(int irq, void *);
  96. static int igb_clean_rx_ring_msix(struct napi_struct *, int);
  97. #ifdef CONFIG_DCA
  98. static void igb_update_rx_dca(struct igb_ring *);
  99. static void igb_update_tx_dca(struct igb_ring *);
  100. static void igb_setup_dca(struct igb_adapter *);
  101. #endif /* CONFIG_DCA */
  102. static bool igb_clean_tx_irq(struct igb_ring *);
  103. static int igb_poll(struct napi_struct *, int);
  104. static bool igb_clean_rx_irq_adv(struct igb_ring *, int *, int);
  105. static void igb_alloc_rx_buffers_adv(struct igb_ring *, int);
  106. static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
  107. static void igb_tx_timeout(struct net_device *);
  108. static void igb_reset_task(struct work_struct *);
  109. static void igb_vlan_rx_register(struct net_device *, struct vlan_group *);
  110. static void igb_vlan_rx_add_vid(struct net_device *, u16);
  111. static void igb_vlan_rx_kill_vid(struct net_device *, u16);
  112. static void igb_restore_vlan(struct igb_adapter *);
  113. static int igb_suspend(struct pci_dev *, pm_message_t);
  114. #ifdef CONFIG_PM
  115. static int igb_resume(struct pci_dev *);
  116. #endif
  117. static void igb_shutdown(struct pci_dev *);
  118. #ifdef CONFIG_DCA
  119. static int igb_notify_dca(struct notifier_block *, unsigned long, void *);
  120. static struct notifier_block dca_notifier = {
  121. .notifier_call = igb_notify_dca,
  122. .next = NULL,
  123. .priority = 0
  124. };
  125. #endif
  126. #ifdef CONFIG_NET_POLL_CONTROLLER
  127. /* for netdump / net console */
  128. static void igb_netpoll(struct net_device *);
  129. #endif
  130. static pci_ers_result_t igb_io_error_detected(struct pci_dev *,
  131. pci_channel_state_t);
  132. static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);
  133. static void igb_io_resume(struct pci_dev *);
  134. static struct pci_error_handlers igb_err_handler = {
  135. .error_detected = igb_io_error_detected,
  136. .slot_reset = igb_io_slot_reset,
  137. .resume = igb_io_resume,
  138. };
  139. static struct pci_driver igb_driver = {
  140. .name = igb_driver_name,
  141. .id_table = igb_pci_tbl,
  142. .probe = igb_probe,
  143. .remove = __devexit_p(igb_remove),
  144. #ifdef CONFIG_PM
  145. /* Power Managment Hooks */
  146. .suspend = igb_suspend,
  147. .resume = igb_resume,
  148. #endif
  149. .shutdown = igb_shutdown,
  150. .err_handler = &igb_err_handler
  151. };
  152. static int global_quad_port_a; /* global quad port a indication */
  153. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  154. MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
  155. MODULE_LICENSE("GPL");
  156. MODULE_VERSION(DRV_VERSION);
  157. #ifdef DEBUG
  158. /**
  159. * igb_get_hw_dev_name - return device name string
  160. * used by hardware layer to print debugging information
  161. **/
  162. char *igb_get_hw_dev_name(struct e1000_hw *hw)
  163. {
  164. struct igb_adapter *adapter = hw->back;
  165. return adapter->netdev->name;
  166. }
  167. #endif
  168. /**
  169. * igb_init_module - Driver Registration Routine
  170. *
  171. * igb_init_module is the first routine called when the driver is
  172. * loaded. All it does is register with the PCI subsystem.
  173. **/
  174. static int __init igb_init_module(void)
  175. {
  176. int ret;
  177. printk(KERN_INFO "%s - version %s\n",
  178. igb_driver_string, igb_driver_version);
  179. printk(KERN_INFO "%s\n", igb_copyright);
  180. global_quad_port_a = 0;
  181. ret = pci_register_driver(&igb_driver);
  182. #ifdef CONFIG_DCA
  183. dca_register_notify(&dca_notifier);
  184. #endif
  185. return ret;
  186. }
  187. module_init(igb_init_module);
  188. /**
  189. * igb_exit_module - Driver Exit Cleanup Routine
  190. *
  191. * igb_exit_module is called just before the driver is removed
  192. * from memory.
  193. **/
  194. static void __exit igb_exit_module(void)
  195. {
  196. #ifdef CONFIG_DCA
  197. dca_unregister_notify(&dca_notifier);
  198. #endif
  199. pci_unregister_driver(&igb_driver);
  200. }
  201. module_exit(igb_exit_module);
  202. /**
  203. * igb_alloc_queues - Allocate memory for all rings
  204. * @adapter: board private structure to initialize
  205. *
  206. * We allocate one ring per queue at run-time since we don't know the
  207. * number of queues at compile-time.
  208. **/
  209. static int igb_alloc_queues(struct igb_adapter *adapter)
  210. {
  211. int i;
  212. adapter->tx_ring = kcalloc(adapter->num_tx_queues,
  213. sizeof(struct igb_ring), GFP_KERNEL);
  214. if (!adapter->tx_ring)
  215. return -ENOMEM;
  216. adapter->rx_ring = kcalloc(adapter->num_rx_queues,
  217. sizeof(struct igb_ring), GFP_KERNEL);
  218. if (!adapter->rx_ring) {
  219. kfree(adapter->tx_ring);
  220. return -ENOMEM;
  221. }
  222. for (i = 0; i < adapter->num_tx_queues; i++) {
  223. struct igb_ring *ring = &(adapter->tx_ring[i]);
  224. ring->adapter = adapter;
  225. ring->queue_index = i;
  226. }
  227. for (i = 0; i < adapter->num_rx_queues; i++) {
  228. struct igb_ring *ring = &(adapter->rx_ring[i]);
  229. ring->adapter = adapter;
  230. ring->queue_index = i;
  231. ring->itr_register = E1000_ITR;
  232. /* set a default napi handler for each rx_ring */
  233. netif_napi_add(adapter->netdev, &ring->napi, igb_poll, 64);
  234. }
  235. return 0;
  236. }
  237. #define IGB_N0_QUEUE -1
  238. static void igb_assign_vector(struct igb_adapter *adapter, int rx_queue,
  239. int tx_queue, int msix_vector)
  240. {
  241. u32 msixbm = 0;
  242. struct e1000_hw *hw = &adapter->hw;
  243. u32 ivar, index;
  244. switch (hw->mac.type) {
  245. case e1000_82575:
  246. /* The 82575 assigns vectors using a bitmask, which matches the
  247. bitmask for the EICR/EIMS/EIMC registers. To assign one
  248. or more queues to a vector, we write the appropriate bits
  249. into the MSIXBM register for that vector. */
  250. if (rx_queue > IGB_N0_QUEUE) {
  251. msixbm = E1000_EICR_RX_QUEUE0 << rx_queue;
  252. adapter->rx_ring[rx_queue].eims_value = msixbm;
  253. }
  254. if (tx_queue > IGB_N0_QUEUE) {
  255. msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue;
  256. adapter->tx_ring[tx_queue].eims_value =
  257. E1000_EICR_TX_QUEUE0 << tx_queue;
  258. }
  259. array_wr32(E1000_MSIXBM(0), msix_vector, msixbm);
  260. break;
  261. case e1000_82576:
  262. /* Kawela uses a table-based method for assigning vectors.
  263. Each queue has a single entry in the table to which we write
  264. a vector number along with a "valid" bit. Sadly, the layout
  265. of the table is somewhat counterintuitive. */
  266. if (rx_queue > IGB_N0_QUEUE) {
  267. index = (rx_queue & 0x7);
  268. ivar = array_rd32(E1000_IVAR0, index);
  269. if (rx_queue < 8) {
  270. /* vector goes into low byte of register */
  271. ivar = ivar & 0xFFFFFF00;
  272. ivar |= msix_vector | E1000_IVAR_VALID;
  273. } else {
  274. /* vector goes into third byte of register */
  275. ivar = ivar & 0xFF00FFFF;
  276. ivar |= (msix_vector | E1000_IVAR_VALID) << 16;
  277. }
  278. adapter->rx_ring[rx_queue].eims_value= 1 << msix_vector;
  279. array_wr32(E1000_IVAR0, index, ivar);
  280. }
  281. if (tx_queue > IGB_N0_QUEUE) {
  282. index = (tx_queue & 0x7);
  283. ivar = array_rd32(E1000_IVAR0, index);
  284. if (tx_queue < 8) {
  285. /* vector goes into second byte of register */
  286. ivar = ivar & 0xFFFF00FF;
  287. ivar |= (msix_vector | E1000_IVAR_VALID) << 8;
  288. } else {
  289. /* vector goes into high byte of register */
  290. ivar = ivar & 0x00FFFFFF;
  291. ivar |= (msix_vector | E1000_IVAR_VALID) << 24;
  292. }
  293. adapter->tx_ring[tx_queue].eims_value= 1 << msix_vector;
  294. array_wr32(E1000_IVAR0, index, ivar);
  295. }
  296. break;
  297. default:
  298. BUG();
  299. break;
  300. }
  301. }
  302. /**
  303. * igb_configure_msix - Configure MSI-X hardware
  304. *
  305. * igb_configure_msix sets up the hardware to properly
  306. * generate MSI-X interrupts.
  307. **/
  308. static void igb_configure_msix(struct igb_adapter *adapter)
  309. {
  310. u32 tmp;
  311. int i, vector = 0;
  312. struct e1000_hw *hw = &adapter->hw;
  313. adapter->eims_enable_mask = 0;
  314. if (hw->mac.type == e1000_82576)
  315. /* Turn on MSI-X capability first, or our settings
  316. * won't stick. And it will take days to debug. */
  317. wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE |
  318. E1000_GPIE_PBA | E1000_GPIE_EIAME |
  319. E1000_GPIE_NSICR);
  320. for (i = 0; i < adapter->num_tx_queues; i++) {
  321. struct igb_ring *tx_ring = &adapter->tx_ring[i];
  322. igb_assign_vector(adapter, IGB_N0_QUEUE, i, vector++);
  323. adapter->eims_enable_mask |= tx_ring->eims_value;
  324. if (tx_ring->itr_val)
  325. writel(1000000000 / (tx_ring->itr_val * 256),
  326. hw->hw_addr + tx_ring->itr_register);
  327. else
  328. writel(1, hw->hw_addr + tx_ring->itr_register);
  329. }
  330. for (i = 0; i < adapter->num_rx_queues; i++) {
  331. struct igb_ring *rx_ring = &adapter->rx_ring[i];
  332. igb_assign_vector(adapter, i, IGB_N0_QUEUE, vector++);
  333. adapter->eims_enable_mask |= rx_ring->eims_value;
  334. if (rx_ring->itr_val)
  335. writel(1000000000 / (rx_ring->itr_val * 256),
  336. hw->hw_addr + rx_ring->itr_register);
  337. else
  338. writel(1, hw->hw_addr + rx_ring->itr_register);
  339. }
  340. /* set vector for other causes, i.e. link changes */
  341. switch (hw->mac.type) {
  342. case e1000_82575:
  343. array_wr32(E1000_MSIXBM(0), vector++,
  344. E1000_EIMS_OTHER);
  345. tmp = rd32(E1000_CTRL_EXT);
  346. /* enable MSI-X PBA support*/
  347. tmp |= E1000_CTRL_EXT_PBA_CLR;
  348. /* Auto-Mask interrupts upon ICR read. */
  349. tmp |= E1000_CTRL_EXT_EIAME;
  350. tmp |= E1000_CTRL_EXT_IRCA;
  351. wr32(E1000_CTRL_EXT, tmp);
  352. adapter->eims_enable_mask |= E1000_EIMS_OTHER;
  353. adapter->eims_other = E1000_EIMS_OTHER;
  354. break;
  355. case e1000_82576:
  356. tmp = (vector++ | E1000_IVAR_VALID) << 8;
  357. wr32(E1000_IVAR_MISC, tmp);
  358. adapter->eims_enable_mask = (1 << (vector)) - 1;
  359. adapter->eims_other = 1 << (vector - 1);
  360. break;
  361. default:
  362. /* do nothing, since nothing else supports MSI-X */
  363. break;
  364. } /* switch (hw->mac.type) */
  365. wrfl();
  366. }
  367. /**
  368. * igb_request_msix - Initialize MSI-X interrupts
  369. *
  370. * igb_request_msix allocates MSI-X vectors and requests interrupts from the
  371. * kernel.
  372. **/
  373. static int igb_request_msix(struct igb_adapter *adapter)
  374. {
  375. struct net_device *netdev = adapter->netdev;
  376. int i, err = 0, vector = 0;
  377. vector = 0;
  378. for (i = 0; i < adapter->num_tx_queues; i++) {
  379. struct igb_ring *ring = &(adapter->tx_ring[i]);
  380. sprintf(ring->name, "%s-tx%d", netdev->name, i);
  381. err = request_irq(adapter->msix_entries[vector].vector,
  382. &igb_msix_tx, 0, ring->name,
  383. &(adapter->tx_ring[i]));
  384. if (err)
  385. goto out;
  386. ring->itr_register = E1000_EITR(0) + (vector << 2);
  387. ring->itr_val = adapter->itr;
  388. vector++;
  389. }
  390. for (i = 0; i < adapter->num_rx_queues; i++) {
  391. struct igb_ring *ring = &(adapter->rx_ring[i]);
  392. if (strlen(netdev->name) < (IFNAMSIZ - 5))
  393. sprintf(ring->name, "%s-rx%d", netdev->name, i);
  394. else
  395. memcpy(ring->name, netdev->name, IFNAMSIZ);
  396. err = request_irq(adapter->msix_entries[vector].vector,
  397. &igb_msix_rx, 0, ring->name,
  398. &(adapter->rx_ring[i]));
  399. if (err)
  400. goto out;
  401. ring->itr_register = E1000_EITR(0) + (vector << 2);
  402. ring->itr_val = adapter->itr;
  403. /* overwrite the poll routine for MSIX, we've already done
  404. * netif_napi_add */
  405. ring->napi.poll = &igb_clean_rx_ring_msix;
  406. vector++;
  407. }
  408. err = request_irq(adapter->msix_entries[vector].vector,
  409. &igb_msix_other, 0, netdev->name, netdev);
  410. if (err)
  411. goto out;
  412. igb_configure_msix(adapter);
  413. return 0;
  414. out:
  415. return err;
  416. }
  417. static void igb_reset_interrupt_capability(struct igb_adapter *adapter)
  418. {
  419. if (adapter->msix_entries) {
  420. pci_disable_msix(adapter->pdev);
  421. kfree(adapter->msix_entries);
  422. adapter->msix_entries = NULL;
  423. } else if (adapter->flags & IGB_FLAG_HAS_MSI)
  424. pci_disable_msi(adapter->pdev);
  425. return;
  426. }
  427. /**
  428. * igb_set_interrupt_capability - set MSI or MSI-X if supported
  429. *
  430. * Attempt to configure interrupts using the best available
  431. * capabilities of the hardware and kernel.
  432. **/
  433. static void igb_set_interrupt_capability(struct igb_adapter *adapter)
  434. {
  435. int err;
  436. int numvecs, i;
  437. numvecs = adapter->num_tx_queues + adapter->num_rx_queues + 1;
  438. adapter->msix_entries = kcalloc(numvecs, sizeof(struct msix_entry),
  439. GFP_KERNEL);
  440. if (!adapter->msix_entries)
  441. goto msi_only;
  442. for (i = 0; i < numvecs; i++)
  443. adapter->msix_entries[i].entry = i;
  444. err = pci_enable_msix(adapter->pdev,
  445. adapter->msix_entries,
  446. numvecs);
  447. if (err == 0)
  448. return;
  449. igb_reset_interrupt_capability(adapter);
  450. /* If we can't do MSI-X, try MSI */
  451. msi_only:
  452. adapter->num_rx_queues = 1;
  453. adapter->num_tx_queues = 1;
  454. if (!pci_enable_msi(adapter->pdev))
  455. adapter->flags |= IGB_FLAG_HAS_MSI;
  456. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  457. /* Notify the stack of the (possibly) reduced Tx Queue count. */
  458. adapter->netdev->egress_subqueue_count = adapter->num_tx_queues;
  459. #endif
  460. return;
  461. }
  462. /**
  463. * igb_request_irq - initialize interrupts
  464. *
  465. * Attempts to configure interrupts using the best available
  466. * capabilities of the hardware and kernel.
  467. **/
  468. static int igb_request_irq(struct igb_adapter *adapter)
  469. {
  470. struct net_device *netdev = adapter->netdev;
  471. struct e1000_hw *hw = &adapter->hw;
  472. int err = 0;
  473. if (adapter->msix_entries) {
  474. err = igb_request_msix(adapter);
  475. if (!err)
  476. goto request_done;
  477. /* fall back to MSI */
  478. igb_reset_interrupt_capability(adapter);
  479. if (!pci_enable_msi(adapter->pdev))
  480. adapter->flags |= IGB_FLAG_HAS_MSI;
  481. igb_free_all_tx_resources(adapter);
  482. igb_free_all_rx_resources(adapter);
  483. adapter->num_rx_queues = 1;
  484. igb_alloc_queues(adapter);
  485. } else {
  486. switch (hw->mac.type) {
  487. case e1000_82575:
  488. wr32(E1000_MSIXBM(0),
  489. (E1000_EICR_RX_QUEUE0 | E1000_EIMS_OTHER));
  490. break;
  491. case e1000_82576:
  492. wr32(E1000_IVAR0, E1000_IVAR_VALID);
  493. break;
  494. default:
  495. break;
  496. }
  497. }
  498. if (adapter->flags & IGB_FLAG_HAS_MSI) {
  499. err = request_irq(adapter->pdev->irq, &igb_intr_msi, 0,
  500. netdev->name, netdev);
  501. if (!err)
  502. goto request_done;
  503. /* fall back to legacy interrupts */
  504. igb_reset_interrupt_capability(adapter);
  505. adapter->flags &= ~IGB_FLAG_HAS_MSI;
  506. }
  507. err = request_irq(adapter->pdev->irq, &igb_intr, IRQF_SHARED,
  508. netdev->name, netdev);
  509. if (err)
  510. dev_err(&adapter->pdev->dev, "Error %d getting interrupt\n",
  511. err);
  512. request_done:
  513. return err;
  514. }
  515. static void igb_free_irq(struct igb_adapter *adapter)
  516. {
  517. struct net_device *netdev = adapter->netdev;
  518. if (adapter->msix_entries) {
  519. int vector = 0, i;
  520. for (i = 0; i < adapter->num_tx_queues; i++)
  521. free_irq(adapter->msix_entries[vector++].vector,
  522. &(adapter->tx_ring[i]));
  523. for (i = 0; i < adapter->num_rx_queues; i++)
  524. free_irq(adapter->msix_entries[vector++].vector,
  525. &(adapter->rx_ring[i]));
  526. free_irq(adapter->msix_entries[vector++].vector, netdev);
  527. return;
  528. }
  529. free_irq(adapter->pdev->irq, netdev);
  530. }
  531. /**
  532. * igb_irq_disable - Mask off interrupt generation on the NIC
  533. * @adapter: board private structure
  534. **/
  535. static void igb_irq_disable(struct igb_adapter *adapter)
  536. {
  537. struct e1000_hw *hw = &adapter->hw;
  538. if (adapter->msix_entries) {
  539. wr32(E1000_EIAM, 0);
  540. wr32(E1000_EIMC, ~0);
  541. wr32(E1000_EIAC, 0);
  542. }
  543. wr32(E1000_IAM, 0);
  544. wr32(E1000_IMC, ~0);
  545. wrfl();
  546. synchronize_irq(adapter->pdev->irq);
  547. }
  548. /**
  549. * igb_irq_enable - Enable default interrupt generation settings
  550. * @adapter: board private structure
  551. **/
  552. static void igb_irq_enable(struct igb_adapter *adapter)
  553. {
  554. struct e1000_hw *hw = &adapter->hw;
  555. if (adapter->msix_entries) {
  556. wr32(E1000_EIAC, adapter->eims_enable_mask);
  557. wr32(E1000_EIAM, adapter->eims_enable_mask);
  558. wr32(E1000_EIMS, adapter->eims_enable_mask);
  559. wr32(E1000_IMS, E1000_IMS_LSC);
  560. } else {
  561. wr32(E1000_IMS, IMS_ENABLE_MASK);
  562. wr32(E1000_IAM, IMS_ENABLE_MASK);
  563. }
  564. }
  565. static void igb_update_mng_vlan(struct igb_adapter *adapter)
  566. {
  567. struct net_device *netdev = adapter->netdev;
  568. u16 vid = adapter->hw.mng_cookie.vlan_id;
  569. u16 old_vid = adapter->mng_vlan_id;
  570. if (adapter->vlgrp) {
  571. if (!vlan_group_get_device(adapter->vlgrp, vid)) {
  572. if (adapter->hw.mng_cookie.status &
  573. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
  574. igb_vlan_rx_add_vid(netdev, vid);
  575. adapter->mng_vlan_id = vid;
  576. } else
  577. adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
  578. if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
  579. (vid != old_vid) &&
  580. !vlan_group_get_device(adapter->vlgrp, old_vid))
  581. igb_vlan_rx_kill_vid(netdev, old_vid);
  582. } else
  583. adapter->mng_vlan_id = vid;
  584. }
  585. }
  586. /**
  587. * igb_release_hw_control - release control of the h/w to f/w
  588. * @adapter: address of board private structure
  589. *
  590. * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
  591. * For ASF and Pass Through versions of f/w this means that the
  592. * driver is no longer loaded.
  593. *
  594. **/
  595. static void igb_release_hw_control(struct igb_adapter *adapter)
  596. {
  597. struct e1000_hw *hw = &adapter->hw;
  598. u32 ctrl_ext;
  599. /* Let firmware take over control of h/w */
  600. ctrl_ext = rd32(E1000_CTRL_EXT);
  601. wr32(E1000_CTRL_EXT,
  602. ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
  603. }
  604. /**
  605. * igb_get_hw_control - get control of the h/w from f/w
  606. * @adapter: address of board private structure
  607. *
  608. * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
  609. * For ASF and Pass Through versions of f/w this means that
  610. * the driver is loaded.
  611. *
  612. **/
  613. static void igb_get_hw_control(struct igb_adapter *adapter)
  614. {
  615. struct e1000_hw *hw = &adapter->hw;
  616. u32 ctrl_ext;
  617. /* Let firmware know the driver has taken over */
  618. ctrl_ext = rd32(E1000_CTRL_EXT);
  619. wr32(E1000_CTRL_EXT,
  620. ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
  621. }
  622. static void igb_init_manageability(struct igb_adapter *adapter)
  623. {
  624. struct e1000_hw *hw = &adapter->hw;
  625. if (adapter->en_mng_pt) {
  626. u32 manc2h = rd32(E1000_MANC2H);
  627. u32 manc = rd32(E1000_MANC);
  628. /* enable receiving management packets to the host */
  629. /* this will probably generate destination unreachable messages
  630. * from the host OS, but the packets will be handled on SMBUS */
  631. manc |= E1000_MANC_EN_MNG2HOST;
  632. #define E1000_MNG2HOST_PORT_623 (1 << 5)
  633. #define E1000_MNG2HOST_PORT_664 (1 << 6)
  634. manc2h |= E1000_MNG2HOST_PORT_623;
  635. manc2h |= E1000_MNG2HOST_PORT_664;
  636. wr32(E1000_MANC2H, manc2h);
  637. wr32(E1000_MANC, manc);
  638. }
  639. }
  640. /**
  641. * igb_configure - configure the hardware for RX and TX
  642. * @adapter: private board structure
  643. **/
  644. static void igb_configure(struct igb_adapter *adapter)
  645. {
  646. struct net_device *netdev = adapter->netdev;
  647. int i;
  648. igb_get_hw_control(adapter);
  649. igb_set_multi(netdev);
  650. igb_restore_vlan(adapter);
  651. igb_init_manageability(adapter);
  652. igb_configure_tx(adapter);
  653. igb_setup_rctl(adapter);
  654. igb_configure_rx(adapter);
  655. igb_rx_fifo_flush_82575(&adapter->hw);
  656. /* call IGB_DESC_UNUSED which always leaves
  657. * at least 1 descriptor unused to make sure
  658. * next_to_use != next_to_clean */
  659. for (i = 0; i < adapter->num_rx_queues; i++) {
  660. struct igb_ring *ring = &adapter->rx_ring[i];
  661. igb_alloc_rx_buffers_adv(ring, IGB_DESC_UNUSED(ring));
  662. }
  663. adapter->tx_queue_len = netdev->tx_queue_len;
  664. }
  665. /**
  666. * igb_up - Open the interface and prepare it to handle traffic
  667. * @adapter: board private structure
  668. **/
  669. int igb_up(struct igb_adapter *adapter)
  670. {
  671. struct e1000_hw *hw = &adapter->hw;
  672. int i;
  673. /* hardware has been reset, we need to reload some things */
  674. igb_configure(adapter);
  675. clear_bit(__IGB_DOWN, &adapter->state);
  676. for (i = 0; i < adapter->num_rx_queues; i++)
  677. napi_enable(&adapter->rx_ring[i].napi);
  678. if (adapter->msix_entries)
  679. igb_configure_msix(adapter);
  680. /* Clear any pending interrupts. */
  681. rd32(E1000_ICR);
  682. igb_irq_enable(adapter);
  683. /* Fire a link change interrupt to start the watchdog. */
  684. wr32(E1000_ICS, E1000_ICS_LSC);
  685. return 0;
  686. }
  687. void igb_down(struct igb_adapter *adapter)
  688. {
  689. struct e1000_hw *hw = &adapter->hw;
  690. struct net_device *netdev = adapter->netdev;
  691. u32 tctl, rctl;
  692. int i;
  693. /* signal that we're down so the interrupt handler does not
  694. * reschedule our watchdog timer */
  695. set_bit(__IGB_DOWN, &adapter->state);
  696. /* disable receives in the hardware */
  697. rctl = rd32(E1000_RCTL);
  698. wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
  699. /* flush and sleep below */
  700. netif_stop_queue(netdev);
  701. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  702. for (i = 0; i < adapter->num_tx_queues; i++)
  703. netif_stop_subqueue(netdev, i);
  704. #endif
  705. /* disable transmits in the hardware */
  706. tctl = rd32(E1000_TCTL);
  707. tctl &= ~E1000_TCTL_EN;
  708. wr32(E1000_TCTL, tctl);
  709. /* flush both disables and wait for them to finish */
  710. wrfl();
  711. msleep(10);
  712. for (i = 0; i < adapter->num_rx_queues; i++)
  713. napi_disable(&adapter->rx_ring[i].napi);
  714. igb_irq_disable(adapter);
  715. del_timer_sync(&adapter->watchdog_timer);
  716. del_timer_sync(&adapter->phy_info_timer);
  717. netdev->tx_queue_len = adapter->tx_queue_len;
  718. netif_carrier_off(netdev);
  719. adapter->link_speed = 0;
  720. adapter->link_duplex = 0;
  721. if (!pci_channel_offline(adapter->pdev))
  722. igb_reset(adapter);
  723. igb_clean_all_tx_rings(adapter);
  724. igb_clean_all_rx_rings(adapter);
  725. }
  726. void igb_reinit_locked(struct igb_adapter *adapter)
  727. {
  728. WARN_ON(in_interrupt());
  729. while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
  730. msleep(1);
  731. igb_down(adapter);
  732. igb_up(adapter);
  733. clear_bit(__IGB_RESETTING, &adapter->state);
  734. }
  735. void igb_reset(struct igb_adapter *adapter)
  736. {
  737. struct e1000_hw *hw = &adapter->hw;
  738. struct e1000_mac_info *mac = &hw->mac;
  739. struct e1000_fc_info *fc = &hw->fc;
  740. u32 pba = 0, tx_space, min_tx_space, min_rx_space;
  741. u16 hwm;
  742. /* Repartition Pba for greater than 9k mtu
  743. * To take effect CTRL.RST is required.
  744. */
  745. if (mac->type != e1000_82576) {
  746. pba = E1000_PBA_34K;
  747. }
  748. else {
  749. pba = E1000_PBA_64K;
  750. }
  751. if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) &&
  752. (mac->type < e1000_82576)) {
  753. /* adjust PBA for jumbo frames */
  754. wr32(E1000_PBA, pba);
  755. /* To maintain wire speed transmits, the Tx FIFO should be
  756. * large enough to accommodate two full transmit packets,
  757. * rounded up to the next 1KB and expressed in KB. Likewise,
  758. * the Rx FIFO should be large enough to accommodate at least
  759. * one full receive packet and is similarly rounded up and
  760. * expressed in KB. */
  761. pba = rd32(E1000_PBA);
  762. /* upper 16 bits has Tx packet buffer allocation size in KB */
  763. tx_space = pba >> 16;
  764. /* lower 16 bits has Rx packet buffer allocation size in KB */
  765. pba &= 0xffff;
  766. /* the tx fifo also stores 16 bytes of information about the tx
  767. * but don't include ethernet FCS because hardware appends it */
  768. min_tx_space = (adapter->max_frame_size +
  769. sizeof(struct e1000_tx_desc) -
  770. ETH_FCS_LEN) * 2;
  771. min_tx_space = ALIGN(min_tx_space, 1024);
  772. min_tx_space >>= 10;
  773. /* software strips receive CRC, so leave room for it */
  774. min_rx_space = adapter->max_frame_size;
  775. min_rx_space = ALIGN(min_rx_space, 1024);
  776. min_rx_space >>= 10;
  777. /* If current Tx allocation is less than the min Tx FIFO size,
  778. * and the min Tx FIFO size is less than the current Rx FIFO
  779. * allocation, take space away from current Rx allocation */
  780. if (tx_space < min_tx_space &&
  781. ((min_tx_space - tx_space) < pba)) {
  782. pba = pba - (min_tx_space - tx_space);
  783. /* if short on rx space, rx wins and must trump tx
  784. * adjustment */
  785. if (pba < min_rx_space)
  786. pba = min_rx_space;
  787. }
  788. wr32(E1000_PBA, pba);
  789. }
  790. /* flow control settings */
  791. /* The high water mark must be low enough to fit one full frame
  792. * (or the size used for early receive) above it in the Rx FIFO.
  793. * Set it to the lower of:
  794. * - 90% of the Rx FIFO size, or
  795. * - the full Rx FIFO size minus one full frame */
  796. hwm = min(((pba << 10) * 9 / 10),
  797. ((pba << 10) - 2 * adapter->max_frame_size));
  798. if (mac->type < e1000_82576) {
  799. fc->high_water = hwm & 0xFFF8; /* 8-byte granularity */
  800. fc->low_water = fc->high_water - 8;
  801. } else {
  802. fc->high_water = hwm & 0xFFF0; /* 16-byte granularity */
  803. fc->low_water = fc->high_water - 16;
  804. }
  805. fc->pause_time = 0xFFFF;
  806. fc->send_xon = 1;
  807. fc->type = fc->original_type;
  808. /* Allow time for pending master requests to run */
  809. adapter->hw.mac.ops.reset_hw(&adapter->hw);
  810. wr32(E1000_WUC, 0);
  811. if (adapter->hw.mac.ops.init_hw(&adapter->hw))
  812. dev_err(&adapter->pdev->dev, "Hardware Error\n");
  813. igb_update_mng_vlan(adapter);
  814. /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
  815. wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
  816. igb_reset_adaptive(&adapter->hw);
  817. if (adapter->hw.phy.ops.get_phy_info)
  818. adapter->hw.phy.ops.get_phy_info(&adapter->hw);
  819. }
  820. /**
  821. * igb_is_need_ioport - determine if an adapter needs ioport resources or not
  822. * @pdev: PCI device information struct
  823. *
  824. * Returns true if an adapter needs ioport resources
  825. **/
  826. static int igb_is_need_ioport(struct pci_dev *pdev)
  827. {
  828. switch (pdev->device) {
  829. /* Currently there are no adapters that need ioport resources */
  830. default:
  831. return false;
  832. }
  833. }
  834. /**
  835. * igb_probe - Device Initialization Routine
  836. * @pdev: PCI device information struct
  837. * @ent: entry in igb_pci_tbl
  838. *
  839. * Returns 0 on success, negative on failure
  840. *
  841. * igb_probe initializes an adapter identified by a pci_dev structure.
  842. * The OS initialization, configuring of the adapter private structure,
  843. * and a hardware reset occur.
  844. **/
  845. static int __devinit igb_probe(struct pci_dev *pdev,
  846. const struct pci_device_id *ent)
  847. {
  848. struct net_device *netdev;
  849. struct igb_adapter *adapter;
  850. struct e1000_hw *hw;
  851. const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
  852. unsigned long mmio_start, mmio_len;
  853. int i, err, pci_using_dac;
  854. u16 eeprom_data = 0;
  855. u16 eeprom_apme_mask = IGB_EEPROM_APME;
  856. u32 part_num;
  857. int bars, need_ioport;
  858. /* do not allocate ioport bars when not needed */
  859. need_ioport = igb_is_need_ioport(pdev);
  860. if (need_ioport) {
  861. bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
  862. err = pci_enable_device(pdev);
  863. } else {
  864. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  865. err = pci_enable_device_mem(pdev);
  866. }
  867. if (err)
  868. return err;
  869. pci_using_dac = 0;
  870. err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
  871. if (!err) {
  872. err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
  873. if (!err)
  874. pci_using_dac = 1;
  875. } else {
  876. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  877. if (err) {
  878. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  879. if (err) {
  880. dev_err(&pdev->dev, "No usable DMA "
  881. "configuration, aborting\n");
  882. goto err_dma;
  883. }
  884. }
  885. }
  886. err = pci_request_selected_regions(pdev, bars, igb_driver_name);
  887. if (err)
  888. goto err_pci_reg;
  889. pci_set_master(pdev);
  890. pci_save_state(pdev);
  891. err = -ENOMEM;
  892. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  893. netdev = alloc_etherdev_mq(sizeof(struct igb_adapter), IGB_MAX_TX_QUEUES);
  894. #else
  895. netdev = alloc_etherdev(sizeof(struct igb_adapter));
  896. #endif /* CONFIG_NETDEVICES_MULTIQUEUE */
  897. if (!netdev)
  898. goto err_alloc_etherdev;
  899. SET_NETDEV_DEV(netdev, &pdev->dev);
  900. pci_set_drvdata(pdev, netdev);
  901. adapter = netdev_priv(netdev);
  902. adapter->netdev = netdev;
  903. adapter->pdev = pdev;
  904. hw = &adapter->hw;
  905. hw->back = adapter;
  906. adapter->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE;
  907. adapter->bars = bars;
  908. adapter->need_ioport = need_ioport;
  909. mmio_start = pci_resource_start(pdev, 0);
  910. mmio_len = pci_resource_len(pdev, 0);
  911. err = -EIO;
  912. adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
  913. if (!adapter->hw.hw_addr)
  914. goto err_ioremap;
  915. netdev->open = &igb_open;
  916. netdev->stop = &igb_close;
  917. netdev->get_stats = &igb_get_stats;
  918. netdev->set_multicast_list = &igb_set_multi;
  919. netdev->set_mac_address = &igb_set_mac;
  920. netdev->change_mtu = &igb_change_mtu;
  921. netdev->do_ioctl = &igb_ioctl;
  922. igb_set_ethtool_ops(netdev);
  923. netdev->tx_timeout = &igb_tx_timeout;
  924. netdev->watchdog_timeo = 5 * HZ;
  925. netdev->vlan_rx_register = igb_vlan_rx_register;
  926. netdev->vlan_rx_add_vid = igb_vlan_rx_add_vid;
  927. netdev->vlan_rx_kill_vid = igb_vlan_rx_kill_vid;
  928. #ifdef CONFIG_NET_POLL_CONTROLLER
  929. netdev->poll_controller = igb_netpoll;
  930. #endif
  931. netdev->hard_start_xmit = &igb_xmit_frame_adv;
  932. strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
  933. netdev->mem_start = mmio_start;
  934. netdev->mem_end = mmio_start + mmio_len;
  935. /* PCI config space info */
  936. hw->vendor_id = pdev->vendor;
  937. hw->device_id = pdev->device;
  938. hw->revision_id = pdev->revision;
  939. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  940. hw->subsystem_device_id = pdev->subsystem_device;
  941. /* setup the private structure */
  942. hw->back = adapter;
  943. /* Copy the default MAC, PHY and NVM function pointers */
  944. memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
  945. memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
  946. memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
  947. /* Initialize skew-specific constants */
  948. err = ei->get_invariants(hw);
  949. if (err)
  950. goto err_hw_init;
  951. err = igb_sw_init(adapter);
  952. if (err)
  953. goto err_sw_init;
  954. igb_get_bus_info_pcie(hw);
  955. /* set flags */
  956. switch (hw->mac.type) {
  957. case e1000_82576:
  958. case e1000_82575:
  959. adapter->flags |= IGB_FLAG_HAS_DCA;
  960. adapter->flags |= IGB_FLAG_NEED_CTX_IDX;
  961. break;
  962. default:
  963. break;
  964. }
  965. hw->phy.autoneg_wait_to_complete = false;
  966. hw->mac.adaptive_ifs = true;
  967. /* Copper options */
  968. if (hw->phy.media_type == e1000_media_type_copper) {
  969. hw->phy.mdix = AUTO_ALL_MODES;
  970. hw->phy.disable_polarity_correction = false;
  971. hw->phy.ms_type = e1000_ms_hw_default;
  972. }
  973. if (igb_check_reset_block(hw))
  974. dev_info(&pdev->dev,
  975. "PHY reset is blocked due to SOL/IDER session.\n");
  976. netdev->features = NETIF_F_SG |
  977. NETIF_F_HW_CSUM |
  978. NETIF_F_HW_VLAN_TX |
  979. NETIF_F_HW_VLAN_RX |
  980. NETIF_F_HW_VLAN_FILTER;
  981. netdev->features |= NETIF_F_TSO;
  982. netdev->features |= NETIF_F_TSO6;
  983. netdev->vlan_features |= NETIF_F_TSO;
  984. netdev->vlan_features |= NETIF_F_TSO6;
  985. netdev->vlan_features |= NETIF_F_HW_CSUM;
  986. netdev->vlan_features |= NETIF_F_SG;
  987. if (pci_using_dac)
  988. netdev->features |= NETIF_F_HIGHDMA;
  989. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  990. netdev->features |= NETIF_F_MULTI_QUEUE;
  991. #endif
  992. netdev->features |= NETIF_F_LLTX;
  993. adapter->en_mng_pt = igb_enable_mng_pass_thru(&adapter->hw);
  994. /* before reading the NVM, reset the controller to put the device in a
  995. * known good starting state */
  996. hw->mac.ops.reset_hw(hw);
  997. /* make sure the NVM is good */
  998. if (igb_validate_nvm_checksum(hw) < 0) {
  999. dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
  1000. err = -EIO;
  1001. goto err_eeprom;
  1002. }
  1003. /* copy the MAC address out of the NVM */
  1004. if (hw->mac.ops.read_mac_addr(hw))
  1005. dev_err(&pdev->dev, "NVM Read Error\n");
  1006. memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
  1007. memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
  1008. if (!is_valid_ether_addr(netdev->perm_addr)) {
  1009. dev_err(&pdev->dev, "Invalid MAC Address\n");
  1010. err = -EIO;
  1011. goto err_eeprom;
  1012. }
  1013. init_timer(&adapter->watchdog_timer);
  1014. adapter->watchdog_timer.function = &igb_watchdog;
  1015. adapter->watchdog_timer.data = (unsigned long) adapter;
  1016. init_timer(&adapter->phy_info_timer);
  1017. adapter->phy_info_timer.function = &igb_update_phy_info;
  1018. adapter->phy_info_timer.data = (unsigned long) adapter;
  1019. INIT_WORK(&adapter->reset_task, igb_reset_task);
  1020. INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
  1021. /* Initialize link & ring properties that are user-changeable */
  1022. adapter->tx_ring->count = 256;
  1023. for (i = 0; i < adapter->num_tx_queues; i++)
  1024. adapter->tx_ring[i].count = adapter->tx_ring->count;
  1025. adapter->rx_ring->count = 256;
  1026. for (i = 0; i < adapter->num_rx_queues; i++)
  1027. adapter->rx_ring[i].count = adapter->rx_ring->count;
  1028. adapter->fc_autoneg = true;
  1029. hw->mac.autoneg = true;
  1030. hw->phy.autoneg_advertised = 0x2f;
  1031. hw->fc.original_type = e1000_fc_default;
  1032. hw->fc.type = e1000_fc_default;
  1033. adapter->itr_setting = 3;
  1034. adapter->itr = IGB_START_ITR;
  1035. igb_validate_mdi_setting(hw);
  1036. adapter->rx_csum = 1;
  1037. /* Initial Wake on LAN setting If APM wake is enabled in the EEPROM,
  1038. * enable the ACPI Magic Packet filter
  1039. */
  1040. if (hw->bus.func == 0 ||
  1041. hw->device_id == E1000_DEV_ID_82575EB_COPPER)
  1042. hw->nvm.ops.read_nvm(hw, NVM_INIT_CONTROL3_PORT_A, 1,
  1043. &eeprom_data);
  1044. if (eeprom_data & eeprom_apme_mask)
  1045. adapter->eeprom_wol |= E1000_WUFC_MAG;
  1046. /* now that we have the eeprom settings, apply the special cases where
  1047. * the eeprom may be wrong or the board simply won't support wake on
  1048. * lan on a particular port */
  1049. switch (pdev->device) {
  1050. case E1000_DEV_ID_82575GB_QUAD_COPPER:
  1051. adapter->eeprom_wol = 0;
  1052. break;
  1053. case E1000_DEV_ID_82575EB_FIBER_SERDES:
  1054. case E1000_DEV_ID_82576_FIBER:
  1055. case E1000_DEV_ID_82576_SERDES:
  1056. /* Wake events only supported on port A for dual fiber
  1057. * regardless of eeprom setting */
  1058. if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1)
  1059. adapter->eeprom_wol = 0;
  1060. break;
  1061. case E1000_DEV_ID_82576_QUAD_COPPER:
  1062. /* if quad port adapter, disable WoL on all but port A */
  1063. if (global_quad_port_a != 0)
  1064. adapter->eeprom_wol = 0;
  1065. else
  1066. adapter->flags |= IGB_FLAG_QUAD_PORT_A;
  1067. /* Reset for multiple quad port adapters */
  1068. if (++global_quad_port_a == 4)
  1069. global_quad_port_a = 0;
  1070. break;
  1071. }
  1072. /* initialize the wol settings based on the eeprom settings */
  1073. adapter->wol = adapter->eeprom_wol;
  1074. /* reset the hardware with the new settings */
  1075. igb_reset(adapter);
  1076. /* let the f/w know that the h/w is now under the control of the
  1077. * driver. */
  1078. igb_get_hw_control(adapter);
  1079. /* tell the stack to leave us alone until igb_open() is called */
  1080. netif_carrier_off(netdev);
  1081. netif_stop_queue(netdev);
  1082. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  1083. for (i = 0; i < adapter->num_tx_queues; i++)
  1084. netif_stop_subqueue(netdev, i);
  1085. #endif
  1086. strcpy(netdev->name, "eth%d");
  1087. err = register_netdev(netdev);
  1088. if (err)
  1089. goto err_register;
  1090. #ifdef CONFIG_DCA
  1091. if ((adapter->flags & IGB_FLAG_HAS_DCA) &&
  1092. (dca_add_requester(&pdev->dev) == 0)) {
  1093. adapter->flags |= IGB_FLAG_DCA_ENABLED;
  1094. dev_info(&pdev->dev, "DCA enabled\n");
  1095. /* Always use CB2 mode, difference is masked
  1096. * in the CB driver. */
  1097. wr32(E1000_DCA_CTRL, 2);
  1098. igb_setup_dca(adapter);
  1099. }
  1100. #endif
  1101. dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");
  1102. /* print bus type/speed/width info */
  1103. dev_info(&pdev->dev,
  1104. "%s: (PCIe:%s:%s) %02x:%02x:%02x:%02x:%02x:%02x\n",
  1105. netdev->name,
  1106. ((hw->bus.speed == e1000_bus_speed_2500)
  1107. ? "2.5Gb/s" : "unknown"),
  1108. ((hw->bus.width == e1000_bus_width_pcie_x4)
  1109. ? "Width x4" : (hw->bus.width == e1000_bus_width_pcie_x1)
  1110. ? "Width x1" : "unknown"),
  1111. netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
  1112. netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
  1113. igb_read_part_num(hw, &part_num);
  1114. dev_info(&pdev->dev, "%s: PBA No: %06x-%03x\n", netdev->name,
  1115. (part_num >> 8), (part_num & 0xff));
  1116. dev_info(&pdev->dev,
  1117. "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
  1118. adapter->msix_entries ? "MSI-X" :
  1119. (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
  1120. adapter->num_rx_queues, adapter->num_tx_queues);
  1121. return 0;
  1122. err_register:
  1123. igb_release_hw_control(adapter);
  1124. err_eeprom:
  1125. if (!igb_check_reset_block(hw))
  1126. hw->phy.ops.reset_phy(hw);
  1127. if (hw->flash_address)
  1128. iounmap(hw->flash_address);
  1129. igb_remove_device(hw);
  1130. kfree(adapter->tx_ring);
  1131. kfree(adapter->rx_ring);
  1132. err_sw_init:
  1133. err_hw_init:
  1134. iounmap(hw->hw_addr);
  1135. err_ioremap:
  1136. free_netdev(netdev);
  1137. err_alloc_etherdev:
  1138. pci_release_selected_regions(pdev, bars);
  1139. err_pci_reg:
  1140. err_dma:
  1141. pci_disable_device(pdev);
  1142. return err;
  1143. }
  1144. /**
  1145. * igb_remove - Device Removal Routine
  1146. * @pdev: PCI device information struct
  1147. *
  1148. * igb_remove is called by the PCI subsystem to alert the driver
  1149. * that it should release a PCI device. The could be caused by a
  1150. * Hot-Plug event, or because the driver is going to be removed from
  1151. * memory.
  1152. **/
  1153. static void __devexit igb_remove(struct pci_dev *pdev)
  1154. {
  1155. struct net_device *netdev = pci_get_drvdata(pdev);
  1156. struct igb_adapter *adapter = netdev_priv(netdev);
  1157. struct e1000_hw *hw = &adapter->hw;
  1158. /* flush_scheduled work may reschedule our watchdog task, so
  1159. * explicitly disable watchdog tasks from being rescheduled */
  1160. set_bit(__IGB_DOWN, &adapter->state);
  1161. del_timer_sync(&adapter->watchdog_timer);
  1162. del_timer_sync(&adapter->phy_info_timer);
  1163. flush_scheduled_work();
  1164. #ifdef CONFIG_DCA
  1165. if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
  1166. dev_info(&pdev->dev, "DCA disabled\n");
  1167. dca_remove_requester(&pdev->dev);
  1168. adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
  1169. wr32(E1000_DCA_CTRL, 1);
  1170. }
  1171. #endif
  1172. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  1173. * would have already happened in close and is redundant. */
  1174. igb_release_hw_control(adapter);
  1175. unregister_netdev(netdev);
  1176. if (!igb_check_reset_block(&adapter->hw))
  1177. adapter->hw.phy.ops.reset_phy(&adapter->hw);
  1178. igb_remove_device(&adapter->hw);
  1179. igb_reset_interrupt_capability(adapter);
  1180. kfree(adapter->tx_ring);
  1181. kfree(adapter->rx_ring);
  1182. iounmap(adapter->hw.hw_addr);
  1183. if (adapter->hw.flash_address)
  1184. iounmap(adapter->hw.flash_address);
  1185. pci_release_selected_regions(pdev, adapter->bars);
  1186. free_netdev(netdev);
  1187. pci_disable_device(pdev);
  1188. }
  1189. /**
  1190. * igb_sw_init - Initialize general software structures (struct igb_adapter)
  1191. * @adapter: board private structure to initialize
  1192. *
  1193. * igb_sw_init initializes the Adapter private data structure.
  1194. * Fields are initialized based on PCI device information and
  1195. * OS network device settings (MTU size).
  1196. **/
  1197. static int __devinit igb_sw_init(struct igb_adapter *adapter)
  1198. {
  1199. struct e1000_hw *hw = &adapter->hw;
  1200. struct net_device *netdev = adapter->netdev;
  1201. struct pci_dev *pdev = adapter->pdev;
  1202. pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
  1203. adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
  1204. adapter->rx_ps_hdr_size = 0; /* disable packet split */
  1205. adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  1206. adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
  1207. /* Number of supported queues. */
  1208. /* Having more queues than CPUs doesn't make sense. */
  1209. adapter->num_rx_queues = min((u32)IGB_MAX_RX_QUEUES, (u32)num_online_cpus());
  1210. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  1211. adapter->num_tx_queues = min(IGB_MAX_TX_QUEUES, num_online_cpus());
  1212. #else
  1213. adapter->num_tx_queues = 1;
  1214. #endif /* CONFIG_NET_MULTI_QUEUE_DEVICE */
  1215. /* This call may decrease the number of queues depending on
  1216. * interrupt mode. */
  1217. igb_set_interrupt_capability(adapter);
  1218. if (igb_alloc_queues(adapter)) {
  1219. dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
  1220. return -ENOMEM;
  1221. }
  1222. /* Explicitly disable IRQ since the NIC can be in any state. */
  1223. igb_irq_disable(adapter);
  1224. set_bit(__IGB_DOWN, &adapter->state);
  1225. return 0;
  1226. }
  1227. /**
  1228. * igb_open - Called when a network interface is made active
  1229. * @netdev: network interface device structure
  1230. *
  1231. * Returns 0 on success, negative value on failure
  1232. *
  1233. * The open entry point is called when a network interface is made
  1234. * active by the system (IFF_UP). At this point all resources needed
  1235. * for transmit and receive operations are allocated, the interrupt
  1236. * handler is registered with the OS, the watchdog timer is started,
  1237. * and the stack is notified that the interface is ready.
  1238. **/
  1239. static int igb_open(struct net_device *netdev)
  1240. {
  1241. struct igb_adapter *adapter = netdev_priv(netdev);
  1242. struct e1000_hw *hw = &adapter->hw;
  1243. int err;
  1244. int i;
  1245. /* disallow open during test */
  1246. if (test_bit(__IGB_TESTING, &adapter->state))
  1247. return -EBUSY;
  1248. /* allocate transmit descriptors */
  1249. err = igb_setup_all_tx_resources(adapter);
  1250. if (err)
  1251. goto err_setup_tx;
  1252. /* allocate receive descriptors */
  1253. err = igb_setup_all_rx_resources(adapter);
  1254. if (err)
  1255. goto err_setup_rx;
  1256. /* e1000_power_up_phy(adapter); */
  1257. adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
  1258. if ((adapter->hw.mng_cookie.status &
  1259. E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
  1260. igb_update_mng_vlan(adapter);
  1261. /* before we allocate an interrupt, we must be ready to handle it.
  1262. * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
  1263. * as soon as we call pci_request_irq, so we have to setup our
  1264. * clean_rx handler before we do so. */
  1265. igb_configure(adapter);
  1266. err = igb_request_irq(adapter);
  1267. if (err)
  1268. goto err_req_irq;
  1269. /* From here on the code is the same as igb_up() */
  1270. clear_bit(__IGB_DOWN, &adapter->state);
  1271. for (i = 0; i < adapter->num_rx_queues; i++)
  1272. napi_enable(&adapter->rx_ring[i].napi);
  1273. /* Clear any pending interrupts. */
  1274. rd32(E1000_ICR);
  1275. igb_irq_enable(adapter);
  1276. /* Fire a link status change interrupt to start the watchdog. */
  1277. wr32(E1000_ICS, E1000_ICS_LSC);
  1278. return 0;
  1279. err_req_irq:
  1280. igb_release_hw_control(adapter);
  1281. /* e1000_power_down_phy(adapter); */
  1282. igb_free_all_rx_resources(adapter);
  1283. err_setup_rx:
  1284. igb_free_all_tx_resources(adapter);
  1285. err_setup_tx:
  1286. igb_reset(adapter);
  1287. return err;
  1288. }
  1289. /**
  1290. * igb_close - Disables a network interface
  1291. * @netdev: network interface device structure
  1292. *
  1293. * Returns 0, this is not allowed to fail
  1294. *
  1295. * The close entry point is called when an interface is de-activated
  1296. * by the OS. The hardware is still under the driver's control, but
  1297. * needs to be disabled. A global MAC reset is issued to stop the
  1298. * hardware, and all transmit and receive resources are freed.
  1299. **/
  1300. static int igb_close(struct net_device *netdev)
  1301. {
  1302. struct igb_adapter *adapter = netdev_priv(netdev);
  1303. WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
  1304. igb_down(adapter);
  1305. igb_free_irq(adapter);
  1306. igb_free_all_tx_resources(adapter);
  1307. igb_free_all_rx_resources(adapter);
  1308. /* kill manageability vlan ID if supported, but not if a vlan with
  1309. * the same ID is registered on the host OS (let 8021q kill it) */
  1310. if ((adapter->hw.mng_cookie.status &
  1311. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
  1312. !(adapter->vlgrp &&
  1313. vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
  1314. igb_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
  1315. return 0;
  1316. }
  1317. /**
  1318. * igb_setup_tx_resources - allocate Tx resources (Descriptors)
  1319. * @adapter: board private structure
  1320. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  1321. *
  1322. * Return 0 on success, negative on failure
  1323. **/
  1324. int igb_setup_tx_resources(struct igb_adapter *adapter,
  1325. struct igb_ring *tx_ring)
  1326. {
  1327. struct pci_dev *pdev = adapter->pdev;
  1328. int size;
  1329. size = sizeof(struct igb_buffer) * tx_ring->count;
  1330. tx_ring->buffer_info = vmalloc(size);
  1331. if (!tx_ring->buffer_info)
  1332. goto err;
  1333. memset(tx_ring->buffer_info, 0, size);
  1334. /* round up to nearest 4K */
  1335. tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc)
  1336. + sizeof(u32);
  1337. tx_ring->size = ALIGN(tx_ring->size, 4096);
  1338. tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
  1339. &tx_ring->dma);
  1340. if (!tx_ring->desc)
  1341. goto err;
  1342. tx_ring->adapter = adapter;
  1343. tx_ring->next_to_use = 0;
  1344. tx_ring->next_to_clean = 0;
  1345. return 0;
  1346. err:
  1347. vfree(tx_ring->buffer_info);
  1348. dev_err(&adapter->pdev->dev,
  1349. "Unable to allocate memory for the transmit descriptor ring\n");
  1350. return -ENOMEM;
  1351. }
  1352. /**
  1353. * igb_setup_all_tx_resources - wrapper to allocate Tx resources
  1354. * (Descriptors) for all queues
  1355. * @adapter: board private structure
  1356. *
  1357. * Return 0 on success, negative on failure
  1358. **/
  1359. static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
  1360. {
  1361. int i, err = 0;
  1362. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  1363. int r_idx;
  1364. #endif
  1365. for (i = 0; i < adapter->num_tx_queues; i++) {
  1366. err = igb_setup_tx_resources(adapter, &adapter->tx_ring[i]);
  1367. if (err) {
  1368. dev_err(&adapter->pdev->dev,
  1369. "Allocation for Tx Queue %u failed\n", i);
  1370. for (i--; i >= 0; i--)
  1371. igb_free_tx_resources(&adapter->tx_ring[i]);
  1372. break;
  1373. }
  1374. }
  1375. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  1376. for (i = 0; i < IGB_MAX_TX_QUEUES; i++) {
  1377. r_idx = i % adapter->num_tx_queues;
  1378. adapter->multi_tx_table[i] = &adapter->tx_ring[r_idx];
  1379. }
  1380. #endif
  1381. return err;
  1382. }
  1383. /**
  1384. * igb_configure_tx - Configure transmit Unit after Reset
  1385. * @adapter: board private structure
  1386. *
  1387. * Configure the Tx unit of the MAC after a reset.
  1388. **/
  1389. static void igb_configure_tx(struct igb_adapter *adapter)
  1390. {
  1391. u64 tdba, tdwba;
  1392. struct e1000_hw *hw = &adapter->hw;
  1393. u32 tctl;
  1394. u32 txdctl, txctrl;
  1395. int i;
  1396. for (i = 0; i < adapter->num_tx_queues; i++) {
  1397. struct igb_ring *ring = &(adapter->tx_ring[i]);
  1398. wr32(E1000_TDLEN(i),
  1399. ring->count * sizeof(struct e1000_tx_desc));
  1400. tdba = ring->dma;
  1401. wr32(E1000_TDBAL(i),
  1402. tdba & 0x00000000ffffffffULL);
  1403. wr32(E1000_TDBAH(i), tdba >> 32);
  1404. tdwba = ring->dma + ring->count * sizeof(struct e1000_tx_desc);
  1405. tdwba |= 1; /* enable head wb */
  1406. wr32(E1000_TDWBAL(i),
  1407. tdwba & 0x00000000ffffffffULL);
  1408. wr32(E1000_TDWBAH(i), tdwba >> 32);
  1409. ring->head = E1000_TDH(i);
  1410. ring->tail = E1000_TDT(i);
  1411. writel(0, hw->hw_addr + ring->tail);
  1412. writel(0, hw->hw_addr + ring->head);
  1413. txdctl = rd32(E1000_TXDCTL(i));
  1414. txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
  1415. wr32(E1000_TXDCTL(i), txdctl);
  1416. /* Turn off Relaxed Ordering on head write-backs. The
  1417. * writebacks MUST be delivered in order or it will
  1418. * completely screw up our bookeeping.
  1419. */
  1420. txctrl = rd32(E1000_DCA_TXCTRL(i));
  1421. txctrl &= ~E1000_DCA_TXCTRL_TX_WB_RO_EN;
  1422. wr32(E1000_DCA_TXCTRL(i), txctrl);
  1423. }
  1424. /* Use the default values for the Tx Inter Packet Gap (IPG) timer */
  1425. /* Program the Transmit Control Register */
  1426. tctl = rd32(E1000_TCTL);
  1427. tctl &= ~E1000_TCTL_CT;
  1428. tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
  1429. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
  1430. igb_config_collision_dist(hw);
  1431. /* Setup Transmit Descriptor Settings for eop descriptor */
  1432. adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_RS;
  1433. /* Enable transmits */
  1434. tctl |= E1000_TCTL_EN;
  1435. wr32(E1000_TCTL, tctl);
  1436. }
  1437. /**
  1438. * igb_setup_rx_resources - allocate Rx resources (Descriptors)
  1439. * @adapter: board private structure
  1440. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  1441. *
  1442. * Returns 0 on success, negative on failure
  1443. **/
  1444. int igb_setup_rx_resources(struct igb_adapter *adapter,
  1445. struct igb_ring *rx_ring)
  1446. {
  1447. struct pci_dev *pdev = adapter->pdev;
  1448. int size, desc_len;
  1449. size = sizeof(struct igb_buffer) * rx_ring->count;
  1450. rx_ring->buffer_info = vmalloc(size);
  1451. if (!rx_ring->buffer_info)
  1452. goto err;
  1453. memset(rx_ring->buffer_info, 0, size);
  1454. desc_len = sizeof(union e1000_adv_rx_desc);
  1455. /* Round up to nearest 4K */
  1456. rx_ring->size = rx_ring->count * desc_len;
  1457. rx_ring->size = ALIGN(rx_ring->size, 4096);
  1458. rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size,
  1459. &rx_ring->dma);
  1460. if (!rx_ring->desc)
  1461. goto err;
  1462. rx_ring->next_to_clean = 0;
  1463. rx_ring->next_to_use = 0;
  1464. rx_ring->adapter = adapter;
  1465. return 0;
  1466. err:
  1467. vfree(rx_ring->buffer_info);
  1468. dev_err(&adapter->pdev->dev, "Unable to allocate memory for "
  1469. "the receive descriptor ring\n");
  1470. return -ENOMEM;
  1471. }
  1472. /**
  1473. * igb_setup_all_rx_resources - wrapper to allocate Rx resources
  1474. * (Descriptors) for all queues
  1475. * @adapter: board private structure
  1476. *
  1477. * Return 0 on success, negative on failure
  1478. **/
  1479. static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
  1480. {
  1481. int i, err = 0;
  1482. for (i = 0; i < adapter->num_rx_queues; i++) {
  1483. err = igb_setup_rx_resources(adapter, &adapter->rx_ring[i]);
  1484. if (err) {
  1485. dev_err(&adapter->pdev->dev,
  1486. "Allocation for Rx Queue %u failed\n", i);
  1487. for (i--; i >= 0; i--)
  1488. igb_free_rx_resources(&adapter->rx_ring[i]);
  1489. break;
  1490. }
  1491. }
  1492. return err;
  1493. }
  1494. /**
  1495. * igb_setup_rctl - configure the receive control registers
  1496. * @adapter: Board private structure
  1497. **/
  1498. static void igb_setup_rctl(struct igb_adapter *adapter)
  1499. {
  1500. struct e1000_hw *hw = &adapter->hw;
  1501. u32 rctl;
  1502. u32 srrctl = 0;
  1503. int i;
  1504. rctl = rd32(E1000_RCTL);
  1505. rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
  1506. rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
  1507. E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
  1508. (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
  1509. /*
  1510. * enable stripping of CRC. It's unlikely this will break BMC
  1511. * redirection as it did with e1000. Newer features require
  1512. * that the HW strips the CRC.
  1513. */
  1514. rctl |= E1000_RCTL_SECRC;
  1515. rctl &= ~E1000_RCTL_SBP;
  1516. if (adapter->netdev->mtu <= ETH_DATA_LEN)
  1517. rctl &= ~E1000_RCTL_LPE;
  1518. else
  1519. rctl |= E1000_RCTL_LPE;
  1520. if (adapter->rx_buffer_len <= IGB_RXBUFFER_2048) {
  1521. /* Setup buffer sizes */
  1522. rctl &= ~E1000_RCTL_SZ_4096;
  1523. rctl |= E1000_RCTL_BSEX;
  1524. switch (adapter->rx_buffer_len) {
  1525. case IGB_RXBUFFER_256:
  1526. rctl |= E1000_RCTL_SZ_256;
  1527. rctl &= ~E1000_RCTL_BSEX;
  1528. break;
  1529. case IGB_RXBUFFER_512:
  1530. rctl |= E1000_RCTL_SZ_512;
  1531. rctl &= ~E1000_RCTL_BSEX;
  1532. break;
  1533. case IGB_RXBUFFER_1024:
  1534. rctl |= E1000_RCTL_SZ_1024;
  1535. rctl &= ~E1000_RCTL_BSEX;
  1536. break;
  1537. case IGB_RXBUFFER_2048:
  1538. default:
  1539. rctl |= E1000_RCTL_SZ_2048;
  1540. rctl &= ~E1000_RCTL_BSEX;
  1541. break;
  1542. }
  1543. } else {
  1544. rctl &= ~E1000_RCTL_BSEX;
  1545. srrctl = adapter->rx_buffer_len >> E1000_SRRCTL_BSIZEPKT_SHIFT;
  1546. }
  1547. /* 82575 and greater support packet-split where the protocol
  1548. * header is placed in skb->data and the packet data is
  1549. * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
  1550. * In the case of a non-split, skb->data is linearly filled,
  1551. * followed by the page buffers. Therefore, skb->data is
  1552. * sized to hold the largest protocol header.
  1553. */
  1554. /* allocations using alloc_page take too long for regular MTU
  1555. * so only enable packet split for jumbo frames */
  1556. if (rctl & E1000_RCTL_LPE) {
  1557. adapter->rx_ps_hdr_size = IGB_RXBUFFER_128;
  1558. srrctl |= adapter->rx_ps_hdr_size <<
  1559. E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
  1560. srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
  1561. } else {
  1562. adapter->rx_ps_hdr_size = 0;
  1563. srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
  1564. }
  1565. for (i = 0; i < adapter->num_rx_queues; i++)
  1566. wr32(E1000_SRRCTL(i), srrctl);
  1567. wr32(E1000_RCTL, rctl);
  1568. }
  1569. /**
  1570. * igb_configure_rx - Configure receive Unit after Reset
  1571. * @adapter: board private structure
  1572. *
  1573. * Configure the Rx unit of the MAC after a reset.
  1574. **/
  1575. static void igb_configure_rx(struct igb_adapter *adapter)
  1576. {
  1577. u64 rdba;
  1578. struct e1000_hw *hw = &adapter->hw;
  1579. u32 rctl, rxcsum;
  1580. u32 rxdctl;
  1581. int i;
  1582. /* disable receives while setting up the descriptors */
  1583. rctl = rd32(E1000_RCTL);
  1584. wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
  1585. wrfl();
  1586. mdelay(10);
  1587. if (adapter->itr_setting > 3)
  1588. wr32(E1000_ITR,
  1589. 1000000000 / (adapter->itr * 256));
  1590. /* Setup the HW Rx Head and Tail Descriptor Pointers and
  1591. * the Base and Length of the Rx Descriptor Ring */
  1592. for (i = 0; i < adapter->num_rx_queues; i++) {
  1593. struct igb_ring *ring = &(adapter->rx_ring[i]);
  1594. rdba = ring->dma;
  1595. wr32(E1000_RDBAL(i),
  1596. rdba & 0x00000000ffffffffULL);
  1597. wr32(E1000_RDBAH(i), rdba >> 32);
  1598. wr32(E1000_RDLEN(i),
  1599. ring->count * sizeof(union e1000_adv_rx_desc));
  1600. ring->head = E1000_RDH(i);
  1601. ring->tail = E1000_RDT(i);
  1602. writel(0, hw->hw_addr + ring->tail);
  1603. writel(0, hw->hw_addr + ring->head);
  1604. rxdctl = rd32(E1000_RXDCTL(i));
  1605. rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
  1606. rxdctl &= 0xFFF00000;
  1607. rxdctl |= IGB_RX_PTHRESH;
  1608. rxdctl |= IGB_RX_HTHRESH << 8;
  1609. rxdctl |= IGB_RX_WTHRESH << 16;
  1610. wr32(E1000_RXDCTL(i), rxdctl);
  1611. }
  1612. if (adapter->num_rx_queues > 1) {
  1613. u32 random[10];
  1614. u32 mrqc;
  1615. u32 j, shift;
  1616. union e1000_reta {
  1617. u32 dword;
  1618. u8 bytes[4];
  1619. } reta;
  1620. get_random_bytes(&random[0], 40);
  1621. if (hw->mac.type >= e1000_82576)
  1622. shift = 0;
  1623. else
  1624. shift = 6;
  1625. for (j = 0; j < (32 * 4); j++) {
  1626. reta.bytes[j & 3] =
  1627. (j % adapter->num_rx_queues) << shift;
  1628. if ((j & 3) == 3)
  1629. writel(reta.dword,
  1630. hw->hw_addr + E1000_RETA(0) + (j & ~3));
  1631. }
  1632. mrqc = E1000_MRQC_ENABLE_RSS_4Q;
  1633. /* Fill out hash function seeds */
  1634. for (j = 0; j < 10; j++)
  1635. array_wr32(E1000_RSSRK(0), j, random[j]);
  1636. mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
  1637. E1000_MRQC_RSS_FIELD_IPV4_TCP);
  1638. mrqc |= (E1000_MRQC_RSS_FIELD_IPV6 |
  1639. E1000_MRQC_RSS_FIELD_IPV6_TCP);
  1640. mrqc |= (E1000_MRQC_RSS_FIELD_IPV4_UDP |
  1641. E1000_MRQC_RSS_FIELD_IPV6_UDP);
  1642. mrqc |= (E1000_MRQC_RSS_FIELD_IPV6_UDP_EX |
  1643. E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
  1644. wr32(E1000_MRQC, mrqc);
  1645. /* Multiqueue and raw packet checksumming are mutually
  1646. * exclusive. Note that this not the same as TCP/IP
  1647. * checksumming, which works fine. */
  1648. rxcsum = rd32(E1000_RXCSUM);
  1649. rxcsum |= E1000_RXCSUM_PCSD;
  1650. wr32(E1000_RXCSUM, rxcsum);
  1651. } else {
  1652. /* Enable Receive Checksum Offload for TCP and UDP */
  1653. rxcsum = rd32(E1000_RXCSUM);
  1654. if (adapter->rx_csum) {
  1655. rxcsum |= E1000_RXCSUM_TUOFL;
  1656. /* Enable IPv4 payload checksum for UDP fragments
  1657. * Must be used in conjunction with packet-split. */
  1658. if (adapter->rx_ps_hdr_size)
  1659. rxcsum |= E1000_RXCSUM_IPPCSE;
  1660. } else {
  1661. rxcsum &= ~E1000_RXCSUM_TUOFL;
  1662. /* don't need to clear IPPCSE as it defaults to 0 */
  1663. }
  1664. wr32(E1000_RXCSUM, rxcsum);
  1665. }
  1666. if (adapter->vlgrp)
  1667. wr32(E1000_RLPML,
  1668. adapter->max_frame_size + VLAN_TAG_SIZE);
  1669. else
  1670. wr32(E1000_RLPML, adapter->max_frame_size);
  1671. /* Enable Receives */
  1672. wr32(E1000_RCTL, rctl);
  1673. }
  1674. /**
  1675. * igb_free_tx_resources - Free Tx Resources per Queue
  1676. * @adapter: board private structure
  1677. * @tx_ring: Tx descriptor ring for a specific queue
  1678. *
  1679. * Free all transmit software resources
  1680. **/
  1681. static void igb_free_tx_resources(struct igb_ring *tx_ring)
  1682. {
  1683. struct pci_dev *pdev = tx_ring->adapter->pdev;
  1684. igb_clean_tx_ring(tx_ring);
  1685. vfree(tx_ring->buffer_info);
  1686. tx_ring->buffer_info = NULL;
  1687. pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
  1688. tx_ring->desc = NULL;
  1689. }
  1690. /**
  1691. * igb_free_all_tx_resources - Free Tx Resources for All Queues
  1692. * @adapter: board private structure
  1693. *
  1694. * Free all transmit software resources
  1695. **/
  1696. static void igb_free_all_tx_resources(struct igb_adapter *adapter)
  1697. {
  1698. int i;
  1699. for (i = 0; i < adapter->num_tx_queues; i++)
  1700. igb_free_tx_resources(&adapter->tx_ring[i]);
  1701. }
  1702. static void igb_unmap_and_free_tx_resource(struct igb_adapter *adapter,
  1703. struct igb_buffer *buffer_info)
  1704. {
  1705. if (buffer_info->dma) {
  1706. pci_unmap_page(adapter->pdev,
  1707. buffer_info->dma,
  1708. buffer_info->length,
  1709. PCI_DMA_TODEVICE);
  1710. buffer_info->dma = 0;
  1711. }
  1712. if (buffer_info->skb) {
  1713. dev_kfree_skb_any(buffer_info->skb);
  1714. buffer_info->skb = NULL;
  1715. }
  1716. buffer_info->time_stamp = 0;
  1717. /* buffer_info must be completely set up in the transmit path */
  1718. }
  1719. /**
  1720. * igb_clean_tx_ring - Free Tx Buffers
  1721. * @adapter: board private structure
  1722. * @tx_ring: ring to be cleaned
  1723. **/
  1724. static void igb_clean_tx_ring(struct igb_ring *tx_ring)
  1725. {
  1726. struct igb_adapter *adapter = tx_ring->adapter;
  1727. struct igb_buffer *buffer_info;
  1728. unsigned long size;
  1729. unsigned int i;
  1730. if (!tx_ring->buffer_info)
  1731. return;
  1732. /* Free all the Tx ring sk_buffs */
  1733. for (i = 0; i < tx_ring->count; i++) {
  1734. buffer_info = &tx_ring->buffer_info[i];
  1735. igb_unmap_and_free_tx_resource(adapter, buffer_info);
  1736. }
  1737. size = sizeof(struct igb_buffer) * tx_ring->count;
  1738. memset(tx_ring->buffer_info, 0, size);
  1739. /* Zero out the descriptor ring */
  1740. memset(tx_ring->desc, 0, tx_ring->size);
  1741. tx_ring->next_to_use = 0;
  1742. tx_ring->next_to_clean = 0;
  1743. writel(0, adapter->hw.hw_addr + tx_ring->head);
  1744. writel(0, adapter->hw.hw_addr + tx_ring->tail);
  1745. }
  1746. /**
  1747. * igb_clean_all_tx_rings - Free Tx Buffers for all queues
  1748. * @adapter: board private structure
  1749. **/
  1750. static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
  1751. {
  1752. int i;
  1753. for (i = 0; i < adapter->num_tx_queues; i++)
  1754. igb_clean_tx_ring(&adapter->tx_ring[i]);
  1755. }
  1756. /**
  1757. * igb_free_rx_resources - Free Rx Resources
  1758. * @adapter: board private structure
  1759. * @rx_ring: ring to clean the resources from
  1760. *
  1761. * Free all receive software resources
  1762. **/
  1763. static void igb_free_rx_resources(struct igb_ring *rx_ring)
  1764. {
  1765. struct pci_dev *pdev = rx_ring->adapter->pdev;
  1766. igb_clean_rx_ring(rx_ring);
  1767. vfree(rx_ring->buffer_info);
  1768. rx_ring->buffer_info = NULL;
  1769. pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
  1770. rx_ring->desc = NULL;
  1771. }
  1772. /**
  1773. * igb_free_all_rx_resources - Free Rx Resources for All Queues
  1774. * @adapter: board private structure
  1775. *
  1776. * Free all receive software resources
  1777. **/
  1778. static void igb_free_all_rx_resources(struct igb_adapter *adapter)
  1779. {
  1780. int i;
  1781. for (i = 0; i < adapter->num_rx_queues; i++)
  1782. igb_free_rx_resources(&adapter->rx_ring[i]);
  1783. }
  1784. /**
  1785. * igb_clean_rx_ring - Free Rx Buffers per Queue
  1786. * @adapter: board private structure
  1787. * @rx_ring: ring to free buffers from
  1788. **/
  1789. static void igb_clean_rx_ring(struct igb_ring *rx_ring)
  1790. {
  1791. struct igb_adapter *adapter = rx_ring->adapter;
  1792. struct igb_buffer *buffer_info;
  1793. struct pci_dev *pdev = adapter->pdev;
  1794. unsigned long size;
  1795. unsigned int i;
  1796. if (!rx_ring->buffer_info)
  1797. return;
  1798. /* Free all the Rx ring sk_buffs */
  1799. for (i = 0; i < rx_ring->count; i++) {
  1800. buffer_info = &rx_ring->buffer_info[i];
  1801. if (buffer_info->dma) {
  1802. if (adapter->rx_ps_hdr_size)
  1803. pci_unmap_single(pdev, buffer_info->dma,
  1804. adapter->rx_ps_hdr_size,
  1805. PCI_DMA_FROMDEVICE);
  1806. else
  1807. pci_unmap_single(pdev, buffer_info->dma,
  1808. adapter->rx_buffer_len,
  1809. PCI_DMA_FROMDEVICE);
  1810. buffer_info->dma = 0;
  1811. }
  1812. if (buffer_info->skb) {
  1813. dev_kfree_skb(buffer_info->skb);
  1814. buffer_info->skb = NULL;
  1815. }
  1816. if (buffer_info->page) {
  1817. if (buffer_info->page_dma)
  1818. pci_unmap_page(pdev, buffer_info->page_dma,
  1819. PAGE_SIZE / 2,
  1820. PCI_DMA_FROMDEVICE);
  1821. put_page(buffer_info->page);
  1822. buffer_info->page = NULL;
  1823. buffer_info->page_dma = 0;
  1824. buffer_info->page_offset = 0;
  1825. }
  1826. }
  1827. size = sizeof(struct igb_buffer) * rx_ring->count;
  1828. memset(rx_ring->buffer_info, 0, size);
  1829. /* Zero out the descriptor ring */
  1830. memset(rx_ring->desc, 0, rx_ring->size);
  1831. rx_ring->next_to_clean = 0;
  1832. rx_ring->next_to_use = 0;
  1833. writel(0, adapter->hw.hw_addr + rx_ring->head);
  1834. writel(0, adapter->hw.hw_addr + rx_ring->tail);
  1835. }
  1836. /**
  1837. * igb_clean_all_rx_rings - Free Rx Buffers for all queues
  1838. * @adapter: board private structure
  1839. **/
  1840. static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
  1841. {
  1842. int i;
  1843. for (i = 0; i < adapter->num_rx_queues; i++)
  1844. igb_clean_rx_ring(&adapter->rx_ring[i]);
  1845. }
  1846. /**
  1847. * igb_set_mac - Change the Ethernet Address of the NIC
  1848. * @netdev: network interface device structure
  1849. * @p: pointer to an address structure
  1850. *
  1851. * Returns 0 on success, negative on failure
  1852. **/
  1853. static int igb_set_mac(struct net_device *netdev, void *p)
  1854. {
  1855. struct igb_adapter *adapter = netdev_priv(netdev);
  1856. struct sockaddr *addr = p;
  1857. if (!is_valid_ether_addr(addr->sa_data))
  1858. return -EADDRNOTAVAIL;
  1859. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  1860. memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
  1861. adapter->hw.mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
  1862. return 0;
  1863. }
  1864. /**
  1865. * igb_set_multi - Multicast and Promiscuous mode set
  1866. * @netdev: network interface device structure
  1867. *
  1868. * The set_multi entry point is called whenever the multicast address
  1869. * list or the network interface flags are updated. This routine is
  1870. * responsible for configuring the hardware for proper multicast,
  1871. * promiscuous mode, and all-multi behavior.
  1872. **/
  1873. static void igb_set_multi(struct net_device *netdev)
  1874. {
  1875. struct igb_adapter *adapter = netdev_priv(netdev);
  1876. struct e1000_hw *hw = &adapter->hw;
  1877. struct e1000_mac_info *mac = &hw->mac;
  1878. struct dev_mc_list *mc_ptr;
  1879. u8 *mta_list;
  1880. u32 rctl;
  1881. int i;
  1882. /* Check for Promiscuous and All Multicast modes */
  1883. rctl = rd32(E1000_RCTL);
  1884. if (netdev->flags & IFF_PROMISC)
  1885. rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
  1886. else if (netdev->flags & IFF_ALLMULTI) {
  1887. rctl |= E1000_RCTL_MPE;
  1888. rctl &= ~E1000_RCTL_UPE;
  1889. } else
  1890. rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
  1891. wr32(E1000_RCTL, rctl);
  1892. if (!netdev->mc_count) {
  1893. /* nothing to program, so clear mc list */
  1894. igb_update_mc_addr_list_82575(hw, NULL, 0, 1,
  1895. mac->rar_entry_count);
  1896. return;
  1897. }
  1898. mta_list = kzalloc(netdev->mc_count * 6, GFP_ATOMIC);
  1899. if (!mta_list)
  1900. return;
  1901. /* The shared function expects a packed array of only addresses. */
  1902. mc_ptr = netdev->mc_list;
  1903. for (i = 0; i < netdev->mc_count; i++) {
  1904. if (!mc_ptr)
  1905. break;
  1906. memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr, ETH_ALEN);
  1907. mc_ptr = mc_ptr->next;
  1908. }
  1909. igb_update_mc_addr_list_82575(hw, mta_list, i, 1,
  1910. mac->rar_entry_count);
  1911. kfree(mta_list);
  1912. }
  1913. /* Need to wait a few seconds after link up to get diagnostic information from
  1914. * the phy */
  1915. static void igb_update_phy_info(unsigned long data)
  1916. {
  1917. struct igb_adapter *adapter = (struct igb_adapter *) data;
  1918. if (adapter->hw.phy.ops.get_phy_info)
  1919. adapter->hw.phy.ops.get_phy_info(&adapter->hw);
  1920. }
  1921. /**
  1922. * igb_watchdog - Timer Call-back
  1923. * @data: pointer to adapter cast into an unsigned long
  1924. **/
  1925. static void igb_watchdog(unsigned long data)
  1926. {
  1927. struct igb_adapter *adapter = (struct igb_adapter *)data;
  1928. /* Do the rest outside of interrupt context */
  1929. schedule_work(&adapter->watchdog_task);
  1930. }
  1931. static void igb_watchdog_task(struct work_struct *work)
  1932. {
  1933. struct igb_adapter *adapter = container_of(work,
  1934. struct igb_adapter, watchdog_task);
  1935. struct e1000_hw *hw = &adapter->hw;
  1936. struct net_device *netdev = adapter->netdev;
  1937. struct igb_ring *tx_ring = adapter->tx_ring;
  1938. struct e1000_mac_info *mac = &adapter->hw.mac;
  1939. u32 link;
  1940. s32 ret_val;
  1941. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  1942. int i;
  1943. #endif
  1944. if ((netif_carrier_ok(netdev)) &&
  1945. (rd32(E1000_STATUS) & E1000_STATUS_LU))
  1946. goto link_up;
  1947. ret_val = hw->mac.ops.check_for_link(&adapter->hw);
  1948. if ((ret_val == E1000_ERR_PHY) &&
  1949. (hw->phy.type == e1000_phy_igp_3) &&
  1950. (rd32(E1000_CTRL) &
  1951. E1000_PHY_CTRL_GBE_DISABLE))
  1952. dev_info(&adapter->pdev->dev,
  1953. "Gigabit has been disabled, downgrading speed\n");
  1954. if ((hw->phy.media_type == e1000_media_type_internal_serdes) &&
  1955. !(rd32(E1000_TXCW) & E1000_TXCW_ANE))
  1956. link = mac->serdes_has_link;
  1957. else
  1958. link = rd32(E1000_STATUS) &
  1959. E1000_STATUS_LU;
  1960. if (link) {
  1961. if (!netif_carrier_ok(netdev)) {
  1962. u32 ctrl;
  1963. hw->mac.ops.get_speed_and_duplex(&adapter->hw,
  1964. &adapter->link_speed,
  1965. &adapter->link_duplex);
  1966. ctrl = rd32(E1000_CTRL);
  1967. dev_info(&adapter->pdev->dev,
  1968. "NIC Link is Up %d Mbps %s, "
  1969. "Flow Control: %s\n",
  1970. adapter->link_speed,
  1971. adapter->link_duplex == FULL_DUPLEX ?
  1972. "Full Duplex" : "Half Duplex",
  1973. ((ctrl & E1000_CTRL_TFCE) && (ctrl &
  1974. E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
  1975. E1000_CTRL_RFCE) ? "RX" : ((ctrl &
  1976. E1000_CTRL_TFCE) ? "TX" : "None")));
  1977. /* tweak tx_queue_len according to speed/duplex and
  1978. * adjust the timeout factor */
  1979. netdev->tx_queue_len = adapter->tx_queue_len;
  1980. adapter->tx_timeout_factor = 1;
  1981. switch (adapter->link_speed) {
  1982. case SPEED_10:
  1983. netdev->tx_queue_len = 10;
  1984. adapter->tx_timeout_factor = 14;
  1985. break;
  1986. case SPEED_100:
  1987. netdev->tx_queue_len = 100;
  1988. /* maybe add some timeout factor ? */
  1989. break;
  1990. }
  1991. netif_carrier_on(netdev);
  1992. netif_wake_queue(netdev);
  1993. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  1994. for (i = 0; i < adapter->num_tx_queues; i++)
  1995. netif_wake_subqueue(netdev, i);
  1996. #endif
  1997. if (!test_bit(__IGB_DOWN, &adapter->state))
  1998. mod_timer(&adapter->phy_info_timer,
  1999. round_jiffies(jiffies + 2 * HZ));
  2000. }
  2001. } else {
  2002. if (netif_carrier_ok(netdev)) {
  2003. adapter->link_speed = 0;
  2004. adapter->link_duplex = 0;
  2005. dev_info(&adapter->pdev->dev, "NIC Link is Down\n");
  2006. netif_carrier_off(netdev);
  2007. netif_stop_queue(netdev);
  2008. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  2009. for (i = 0; i < adapter->num_tx_queues; i++)
  2010. netif_stop_subqueue(netdev, i);
  2011. #endif
  2012. if (!test_bit(__IGB_DOWN, &adapter->state))
  2013. mod_timer(&adapter->phy_info_timer,
  2014. round_jiffies(jiffies + 2 * HZ));
  2015. }
  2016. }
  2017. link_up:
  2018. igb_update_stats(adapter);
  2019. mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
  2020. adapter->tpt_old = adapter->stats.tpt;
  2021. mac->collision_delta = adapter->stats.colc - adapter->colc_old;
  2022. adapter->colc_old = adapter->stats.colc;
  2023. adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
  2024. adapter->gorc_old = adapter->stats.gorc;
  2025. adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
  2026. adapter->gotc_old = adapter->stats.gotc;
  2027. igb_update_adaptive(&adapter->hw);
  2028. if (!netif_carrier_ok(netdev)) {
  2029. if (IGB_DESC_UNUSED(tx_ring) + 1 < tx_ring->count) {
  2030. /* We've lost link, so the controller stops DMA,
  2031. * but we've got queued Tx work that's never going
  2032. * to get done, so reset controller to flush Tx.
  2033. * (Do the reset outside of interrupt context). */
  2034. adapter->tx_timeout_count++;
  2035. schedule_work(&adapter->reset_task);
  2036. }
  2037. }
  2038. /* Cause software interrupt to ensure rx ring is cleaned */
  2039. wr32(E1000_ICS, E1000_ICS_RXDMT0);
  2040. /* Force detection of hung controller every watchdog period */
  2041. tx_ring->detect_tx_hung = true;
  2042. /* Reset the timer */
  2043. if (!test_bit(__IGB_DOWN, &adapter->state))
  2044. mod_timer(&adapter->watchdog_timer,
  2045. round_jiffies(jiffies + 2 * HZ));
  2046. }
  2047. enum latency_range {
  2048. lowest_latency = 0,
  2049. low_latency = 1,
  2050. bulk_latency = 2,
  2051. latency_invalid = 255
  2052. };
  2053. static void igb_lower_rx_eitr(struct igb_adapter *adapter,
  2054. struct igb_ring *rx_ring)
  2055. {
  2056. struct e1000_hw *hw = &adapter->hw;
  2057. int new_val;
  2058. new_val = rx_ring->itr_val / 2;
  2059. if (new_val < IGB_MIN_DYN_ITR)
  2060. new_val = IGB_MIN_DYN_ITR;
  2061. if (new_val != rx_ring->itr_val) {
  2062. rx_ring->itr_val = new_val;
  2063. wr32(rx_ring->itr_register,
  2064. 1000000000 / (new_val * 256));
  2065. }
  2066. }
  2067. static void igb_raise_rx_eitr(struct igb_adapter *adapter,
  2068. struct igb_ring *rx_ring)
  2069. {
  2070. struct e1000_hw *hw = &adapter->hw;
  2071. int new_val;
  2072. new_val = rx_ring->itr_val * 2;
  2073. if (new_val > IGB_MAX_DYN_ITR)
  2074. new_val = IGB_MAX_DYN_ITR;
  2075. if (new_val != rx_ring->itr_val) {
  2076. rx_ring->itr_val = new_val;
  2077. wr32(rx_ring->itr_register,
  2078. 1000000000 / (new_val * 256));
  2079. }
  2080. }
  2081. /**
  2082. * igb_update_itr - update the dynamic ITR value based on statistics
  2083. * Stores a new ITR value based on packets and byte
  2084. * counts during the last interrupt. The advantage of per interrupt
  2085. * computation is faster updates and more accurate ITR for the current
  2086. * traffic pattern. Constants in this function were computed
  2087. * based on theoretical maximum wire speed and thresholds were set based
  2088. * on testing data as well as attempting to minimize response time
  2089. * while increasing bulk throughput.
  2090. * this functionality is controlled by the InterruptThrottleRate module
  2091. * parameter (see igb_param.c)
  2092. * NOTE: These calculations are only valid when operating in a single-
  2093. * queue environment.
  2094. * @adapter: pointer to adapter
  2095. * @itr_setting: current adapter->itr
  2096. * @packets: the number of packets during this measurement interval
  2097. * @bytes: the number of bytes during this measurement interval
  2098. **/
  2099. static unsigned int igb_update_itr(struct igb_adapter *adapter, u16 itr_setting,
  2100. int packets, int bytes)
  2101. {
  2102. unsigned int retval = itr_setting;
  2103. if (packets == 0)
  2104. goto update_itr_done;
  2105. switch (itr_setting) {
  2106. case lowest_latency:
  2107. /* handle TSO and jumbo frames */
  2108. if (bytes/packets > 8000)
  2109. retval = bulk_latency;
  2110. else if ((packets < 5) && (bytes > 512))
  2111. retval = low_latency;
  2112. break;
  2113. case low_latency: /* 50 usec aka 20000 ints/s */
  2114. if (bytes > 10000) {
  2115. /* this if handles the TSO accounting */
  2116. if (bytes/packets > 8000) {
  2117. retval = bulk_latency;
  2118. } else if ((packets < 10) || ((bytes/packets) > 1200)) {
  2119. retval = bulk_latency;
  2120. } else if ((packets > 35)) {
  2121. retval = lowest_latency;
  2122. }
  2123. } else if (bytes/packets > 2000) {
  2124. retval = bulk_latency;
  2125. } else if (packets <= 2 && bytes < 512) {
  2126. retval = lowest_latency;
  2127. }
  2128. break;
  2129. case bulk_latency: /* 250 usec aka 4000 ints/s */
  2130. if (bytes > 25000) {
  2131. if (packets > 35)
  2132. retval = low_latency;
  2133. } else if (bytes < 6000) {
  2134. retval = low_latency;
  2135. }
  2136. break;
  2137. }
  2138. update_itr_done:
  2139. return retval;
  2140. }
  2141. static void igb_set_itr(struct igb_adapter *adapter, u16 itr_register,
  2142. int rx_only)
  2143. {
  2144. u16 current_itr;
  2145. u32 new_itr = adapter->itr;
  2146. /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
  2147. if (adapter->link_speed != SPEED_1000) {
  2148. current_itr = 0;
  2149. new_itr = 4000;
  2150. goto set_itr_now;
  2151. }
  2152. adapter->rx_itr = igb_update_itr(adapter,
  2153. adapter->rx_itr,
  2154. adapter->rx_ring->total_packets,
  2155. adapter->rx_ring->total_bytes);
  2156. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  2157. if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
  2158. adapter->rx_itr = low_latency;
  2159. if (!rx_only) {
  2160. adapter->tx_itr = igb_update_itr(adapter,
  2161. adapter->tx_itr,
  2162. adapter->tx_ring->total_packets,
  2163. adapter->tx_ring->total_bytes);
  2164. /* conservative mode (itr 3) eliminates the
  2165. * lowest_latency setting */
  2166. if (adapter->itr_setting == 3 &&
  2167. adapter->tx_itr == lowest_latency)
  2168. adapter->tx_itr = low_latency;
  2169. current_itr = max(adapter->rx_itr, adapter->tx_itr);
  2170. } else {
  2171. current_itr = adapter->rx_itr;
  2172. }
  2173. switch (current_itr) {
  2174. /* counts and packets in update_itr are dependent on these numbers */
  2175. case lowest_latency:
  2176. new_itr = 70000;
  2177. break;
  2178. case low_latency:
  2179. new_itr = 20000; /* aka hwitr = ~200 */
  2180. break;
  2181. case bulk_latency:
  2182. new_itr = 4000;
  2183. break;
  2184. default:
  2185. break;
  2186. }
  2187. set_itr_now:
  2188. if (new_itr != adapter->itr) {
  2189. /* this attempts to bias the interrupt rate towards Bulk
  2190. * by adding intermediate steps when interrupt rate is
  2191. * increasing */
  2192. new_itr = new_itr > adapter->itr ?
  2193. min(adapter->itr + (new_itr >> 2), new_itr) :
  2194. new_itr;
  2195. /* Don't write the value here; it resets the adapter's
  2196. * internal timer, and causes us to delay far longer than
  2197. * we should between interrupts. Instead, we write the ITR
  2198. * value at the beginning of the next interrupt so the timing
  2199. * ends up being correct.
  2200. */
  2201. adapter->itr = new_itr;
  2202. adapter->set_itr = 1;
  2203. }
  2204. return;
  2205. }
  2206. #define IGB_TX_FLAGS_CSUM 0x00000001
  2207. #define IGB_TX_FLAGS_VLAN 0x00000002
  2208. #define IGB_TX_FLAGS_TSO 0x00000004
  2209. #define IGB_TX_FLAGS_IPV4 0x00000008
  2210. #define IGB_TX_FLAGS_VLAN_MASK 0xffff0000
  2211. #define IGB_TX_FLAGS_VLAN_SHIFT 16
  2212. static inline int igb_tso_adv(struct igb_adapter *adapter,
  2213. struct igb_ring *tx_ring,
  2214. struct sk_buff *skb, u32 tx_flags, u8 *hdr_len)
  2215. {
  2216. struct e1000_adv_tx_context_desc *context_desc;
  2217. unsigned int i;
  2218. int err;
  2219. struct igb_buffer *buffer_info;
  2220. u32 info = 0, tu_cmd = 0;
  2221. u32 mss_l4len_idx, l4len;
  2222. *hdr_len = 0;
  2223. if (skb_header_cloned(skb)) {
  2224. err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  2225. if (err)
  2226. return err;
  2227. }
  2228. l4len = tcp_hdrlen(skb);
  2229. *hdr_len += l4len;
  2230. if (skb->protocol == htons(ETH_P_IP)) {
  2231. struct iphdr *iph = ip_hdr(skb);
  2232. iph->tot_len = 0;
  2233. iph->check = 0;
  2234. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  2235. iph->daddr, 0,
  2236. IPPROTO_TCP,
  2237. 0);
  2238. } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
  2239. ipv6_hdr(skb)->payload_len = 0;
  2240. tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  2241. &ipv6_hdr(skb)->daddr,
  2242. 0, IPPROTO_TCP, 0);
  2243. }
  2244. i = tx_ring->next_to_use;
  2245. buffer_info = &tx_ring->buffer_info[i];
  2246. context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i);
  2247. /* VLAN MACLEN IPLEN */
  2248. if (tx_flags & IGB_TX_FLAGS_VLAN)
  2249. info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK);
  2250. info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
  2251. *hdr_len += skb_network_offset(skb);
  2252. info |= skb_network_header_len(skb);
  2253. *hdr_len += skb_network_header_len(skb);
  2254. context_desc->vlan_macip_lens = cpu_to_le32(info);
  2255. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  2256. tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
  2257. if (skb->protocol == htons(ETH_P_IP))
  2258. tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
  2259. tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
  2260. context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
  2261. /* MSS L4LEN IDX */
  2262. mss_l4len_idx = (skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT);
  2263. mss_l4len_idx |= (l4len << E1000_ADVTXD_L4LEN_SHIFT);
  2264. /* Context index must be unique per ring. */
  2265. if (adapter->flags & IGB_FLAG_NEED_CTX_IDX)
  2266. mss_l4len_idx |= tx_ring->queue_index << 4;
  2267. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  2268. context_desc->seqnum_seed = 0;
  2269. buffer_info->time_stamp = jiffies;
  2270. buffer_info->dma = 0;
  2271. i++;
  2272. if (i == tx_ring->count)
  2273. i = 0;
  2274. tx_ring->next_to_use = i;
  2275. return true;
  2276. }
  2277. static inline bool igb_tx_csum_adv(struct igb_adapter *adapter,
  2278. struct igb_ring *tx_ring,
  2279. struct sk_buff *skb, u32 tx_flags)
  2280. {
  2281. struct e1000_adv_tx_context_desc *context_desc;
  2282. unsigned int i;
  2283. struct igb_buffer *buffer_info;
  2284. u32 info = 0, tu_cmd = 0;
  2285. if ((skb->ip_summed == CHECKSUM_PARTIAL) ||
  2286. (tx_flags & IGB_TX_FLAGS_VLAN)) {
  2287. i = tx_ring->next_to_use;
  2288. buffer_info = &tx_ring->buffer_info[i];
  2289. context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i);
  2290. if (tx_flags & IGB_TX_FLAGS_VLAN)
  2291. info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK);
  2292. info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
  2293. if (skb->ip_summed == CHECKSUM_PARTIAL)
  2294. info |= skb_network_header_len(skb);
  2295. context_desc->vlan_macip_lens = cpu_to_le32(info);
  2296. tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
  2297. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  2298. switch (skb->protocol) {
  2299. case __constant_htons(ETH_P_IP):
  2300. tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
  2301. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  2302. tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
  2303. break;
  2304. case __constant_htons(ETH_P_IPV6):
  2305. /* XXX what about other V6 headers?? */
  2306. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  2307. tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
  2308. break;
  2309. default:
  2310. if (unlikely(net_ratelimit()))
  2311. dev_warn(&adapter->pdev->dev,
  2312. "partial checksum but proto=%x!\n",
  2313. skb->protocol);
  2314. break;
  2315. }
  2316. }
  2317. context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
  2318. context_desc->seqnum_seed = 0;
  2319. if (adapter->flags & IGB_FLAG_NEED_CTX_IDX)
  2320. context_desc->mss_l4len_idx =
  2321. cpu_to_le32(tx_ring->queue_index << 4);
  2322. buffer_info->time_stamp = jiffies;
  2323. buffer_info->dma = 0;
  2324. i++;
  2325. if (i == tx_ring->count)
  2326. i = 0;
  2327. tx_ring->next_to_use = i;
  2328. return true;
  2329. }
  2330. return false;
  2331. }
  2332. #define IGB_MAX_TXD_PWR 16
  2333. #define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR)
  2334. static inline int igb_tx_map_adv(struct igb_adapter *adapter,
  2335. struct igb_ring *tx_ring,
  2336. struct sk_buff *skb)
  2337. {
  2338. struct igb_buffer *buffer_info;
  2339. unsigned int len = skb_headlen(skb);
  2340. unsigned int count = 0, i;
  2341. unsigned int f;
  2342. i = tx_ring->next_to_use;
  2343. buffer_info = &tx_ring->buffer_info[i];
  2344. BUG_ON(len >= IGB_MAX_DATA_PER_TXD);
  2345. buffer_info->length = len;
  2346. /* set time_stamp *before* dma to help avoid a possible race */
  2347. buffer_info->time_stamp = jiffies;
  2348. buffer_info->dma = pci_map_single(adapter->pdev, skb->data, len,
  2349. PCI_DMA_TODEVICE);
  2350. count++;
  2351. i++;
  2352. if (i == tx_ring->count)
  2353. i = 0;
  2354. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) {
  2355. struct skb_frag_struct *frag;
  2356. frag = &skb_shinfo(skb)->frags[f];
  2357. len = frag->size;
  2358. buffer_info = &tx_ring->buffer_info[i];
  2359. BUG_ON(len >= IGB_MAX_DATA_PER_TXD);
  2360. buffer_info->length = len;
  2361. buffer_info->time_stamp = jiffies;
  2362. buffer_info->dma = pci_map_page(adapter->pdev,
  2363. frag->page,
  2364. frag->page_offset,
  2365. len,
  2366. PCI_DMA_TODEVICE);
  2367. count++;
  2368. i++;
  2369. if (i == tx_ring->count)
  2370. i = 0;
  2371. }
  2372. i = (i == 0) ? tx_ring->count - 1 : i - 1;
  2373. tx_ring->buffer_info[i].skb = skb;
  2374. return count;
  2375. }
  2376. static inline void igb_tx_queue_adv(struct igb_adapter *adapter,
  2377. struct igb_ring *tx_ring,
  2378. int tx_flags, int count, u32 paylen,
  2379. u8 hdr_len)
  2380. {
  2381. union e1000_adv_tx_desc *tx_desc = NULL;
  2382. struct igb_buffer *buffer_info;
  2383. u32 olinfo_status = 0, cmd_type_len;
  2384. unsigned int i;
  2385. cmd_type_len = (E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS |
  2386. E1000_ADVTXD_DCMD_DEXT);
  2387. if (tx_flags & IGB_TX_FLAGS_VLAN)
  2388. cmd_type_len |= E1000_ADVTXD_DCMD_VLE;
  2389. if (tx_flags & IGB_TX_FLAGS_TSO) {
  2390. cmd_type_len |= E1000_ADVTXD_DCMD_TSE;
  2391. /* insert tcp checksum */
  2392. olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
  2393. /* insert ip checksum */
  2394. if (tx_flags & IGB_TX_FLAGS_IPV4)
  2395. olinfo_status |= E1000_TXD_POPTS_IXSM << 8;
  2396. } else if (tx_flags & IGB_TX_FLAGS_CSUM) {
  2397. olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
  2398. }
  2399. if ((adapter->flags & IGB_FLAG_NEED_CTX_IDX) &&
  2400. (tx_flags & (IGB_TX_FLAGS_CSUM | IGB_TX_FLAGS_TSO |
  2401. IGB_TX_FLAGS_VLAN)))
  2402. olinfo_status |= tx_ring->queue_index << 4;
  2403. olinfo_status |= ((paylen - hdr_len) << E1000_ADVTXD_PAYLEN_SHIFT);
  2404. i = tx_ring->next_to_use;
  2405. while (count--) {
  2406. buffer_info = &tx_ring->buffer_info[i];
  2407. tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
  2408. tx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
  2409. tx_desc->read.cmd_type_len =
  2410. cpu_to_le32(cmd_type_len | buffer_info->length);
  2411. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  2412. i++;
  2413. if (i == tx_ring->count)
  2414. i = 0;
  2415. }
  2416. tx_desc->read.cmd_type_len |= cpu_to_le32(adapter->txd_cmd);
  2417. /* Force memory writes to complete before letting h/w
  2418. * know there are new descriptors to fetch. (Only
  2419. * applicable for weak-ordered memory model archs,
  2420. * such as IA-64). */
  2421. wmb();
  2422. tx_ring->next_to_use = i;
  2423. writel(i, adapter->hw.hw_addr + tx_ring->tail);
  2424. /* we need this if more than one processor can write to our tail
  2425. * at a time, it syncronizes IO on IA64/Altix systems */
  2426. mmiowb();
  2427. }
  2428. static int __igb_maybe_stop_tx(struct net_device *netdev,
  2429. struct igb_ring *tx_ring, int size)
  2430. {
  2431. struct igb_adapter *adapter = netdev_priv(netdev);
  2432. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  2433. netif_stop_subqueue(netdev, tx_ring->queue_index);
  2434. #else
  2435. netif_stop_queue(netdev);
  2436. #endif
  2437. /* Herbert's original patch had:
  2438. * smp_mb__after_netif_stop_queue();
  2439. * but since that doesn't exist yet, just open code it. */
  2440. smp_mb();
  2441. /* We need to check again in a case another CPU has just
  2442. * made room available. */
  2443. if (IGB_DESC_UNUSED(tx_ring) < size)
  2444. return -EBUSY;
  2445. /* A reprieve! */
  2446. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  2447. netif_wake_subqueue(netdev, tx_ring->queue_index);
  2448. #else
  2449. netif_wake_queue(netdev);
  2450. #endif
  2451. ++adapter->restart_queue;
  2452. return 0;
  2453. }
  2454. static int igb_maybe_stop_tx(struct net_device *netdev,
  2455. struct igb_ring *tx_ring, int size)
  2456. {
  2457. if (IGB_DESC_UNUSED(tx_ring) >= size)
  2458. return 0;
  2459. return __igb_maybe_stop_tx(netdev, tx_ring, size);
  2460. }
  2461. #define TXD_USE_COUNT(S) (((S) >> (IGB_MAX_TXD_PWR)) + 1)
  2462. static int igb_xmit_frame_ring_adv(struct sk_buff *skb,
  2463. struct net_device *netdev,
  2464. struct igb_ring *tx_ring)
  2465. {
  2466. struct igb_adapter *adapter = netdev_priv(netdev);
  2467. unsigned int tx_flags = 0;
  2468. unsigned int len;
  2469. u8 hdr_len = 0;
  2470. int tso = 0;
  2471. len = skb_headlen(skb);
  2472. if (test_bit(__IGB_DOWN, &adapter->state)) {
  2473. dev_kfree_skb_any(skb);
  2474. return NETDEV_TX_OK;
  2475. }
  2476. if (skb->len <= 0) {
  2477. dev_kfree_skb_any(skb);
  2478. return NETDEV_TX_OK;
  2479. }
  2480. /* need: 1 descriptor per page,
  2481. * + 2 desc gap to keep tail from touching head,
  2482. * + 1 desc for skb->data,
  2483. * + 1 desc for context descriptor,
  2484. * otherwise try next time */
  2485. if (igb_maybe_stop_tx(netdev, tx_ring, skb_shinfo(skb)->nr_frags + 4)) {
  2486. /* this is a hard error */
  2487. return NETDEV_TX_BUSY;
  2488. }
  2489. if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
  2490. tx_flags |= IGB_TX_FLAGS_VLAN;
  2491. tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
  2492. }
  2493. if (skb->protocol == htons(ETH_P_IP))
  2494. tx_flags |= IGB_TX_FLAGS_IPV4;
  2495. tso = skb_is_gso(skb) ? igb_tso_adv(adapter, tx_ring, skb, tx_flags,
  2496. &hdr_len) : 0;
  2497. if (tso < 0) {
  2498. dev_kfree_skb_any(skb);
  2499. return NETDEV_TX_OK;
  2500. }
  2501. if (tso)
  2502. tx_flags |= IGB_TX_FLAGS_TSO;
  2503. else if (igb_tx_csum_adv(adapter, tx_ring, skb, tx_flags))
  2504. if (skb->ip_summed == CHECKSUM_PARTIAL)
  2505. tx_flags |= IGB_TX_FLAGS_CSUM;
  2506. igb_tx_queue_adv(adapter, tx_ring, tx_flags,
  2507. igb_tx_map_adv(adapter, tx_ring, skb),
  2508. skb->len, hdr_len);
  2509. netdev->trans_start = jiffies;
  2510. /* Make sure there is space in the ring for the next send. */
  2511. igb_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 4);
  2512. return NETDEV_TX_OK;
  2513. }
  2514. static int igb_xmit_frame_adv(struct sk_buff *skb, struct net_device *netdev)
  2515. {
  2516. struct igb_adapter *adapter = netdev_priv(netdev);
  2517. struct igb_ring *tx_ring;
  2518. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  2519. int r_idx = 0;
  2520. r_idx = skb->queue_mapping & (IGB_MAX_TX_QUEUES - 1);
  2521. tx_ring = adapter->multi_tx_table[r_idx];
  2522. #else
  2523. tx_ring = &adapter->tx_ring[0];
  2524. #endif
  2525. /* This goes back to the question of how to logically map a tx queue
  2526. * to a flow. Right now, performance is impacted slightly negatively
  2527. * if using multiple tx queues. If the stack breaks away from a
  2528. * single qdisc implementation, we can look at this again. */
  2529. return (igb_xmit_frame_ring_adv(skb, netdev, tx_ring));
  2530. }
  2531. /**
  2532. * igb_tx_timeout - Respond to a Tx Hang
  2533. * @netdev: network interface device structure
  2534. **/
  2535. static void igb_tx_timeout(struct net_device *netdev)
  2536. {
  2537. struct igb_adapter *adapter = netdev_priv(netdev);
  2538. struct e1000_hw *hw = &adapter->hw;
  2539. /* Do the reset outside of interrupt context */
  2540. adapter->tx_timeout_count++;
  2541. schedule_work(&adapter->reset_task);
  2542. wr32(E1000_EICS, adapter->eims_enable_mask &
  2543. ~(E1000_EIMS_TCP_TIMER | E1000_EIMS_OTHER));
  2544. }
  2545. static void igb_reset_task(struct work_struct *work)
  2546. {
  2547. struct igb_adapter *adapter;
  2548. adapter = container_of(work, struct igb_adapter, reset_task);
  2549. igb_reinit_locked(adapter);
  2550. }
  2551. /**
  2552. * igb_get_stats - Get System Network Statistics
  2553. * @netdev: network interface device structure
  2554. *
  2555. * Returns the address of the device statistics structure.
  2556. * The statistics are actually updated from the timer callback.
  2557. **/
  2558. static struct net_device_stats *
  2559. igb_get_stats(struct net_device *netdev)
  2560. {
  2561. struct igb_adapter *adapter = netdev_priv(netdev);
  2562. /* only return the current stats */
  2563. return &adapter->net_stats;
  2564. }
  2565. /**
  2566. * igb_change_mtu - Change the Maximum Transfer Unit
  2567. * @netdev: network interface device structure
  2568. * @new_mtu: new value for maximum frame size
  2569. *
  2570. * Returns 0 on success, negative on failure
  2571. **/
  2572. static int igb_change_mtu(struct net_device *netdev, int new_mtu)
  2573. {
  2574. struct igb_adapter *adapter = netdev_priv(netdev);
  2575. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  2576. if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) ||
  2577. (max_frame > MAX_JUMBO_FRAME_SIZE)) {
  2578. dev_err(&adapter->pdev->dev, "Invalid MTU setting\n");
  2579. return -EINVAL;
  2580. }
  2581. #define MAX_STD_JUMBO_FRAME_SIZE 9234
  2582. if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
  2583. dev_err(&adapter->pdev->dev, "MTU > 9216 not supported.\n");
  2584. return -EINVAL;
  2585. }
  2586. while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
  2587. msleep(1);
  2588. /* igb_down has a dependency on max_frame_size */
  2589. adapter->max_frame_size = max_frame;
  2590. if (netif_running(netdev))
  2591. igb_down(adapter);
  2592. /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
  2593. * means we reserve 2 more, this pushes us to allocate from the next
  2594. * larger slab size.
  2595. * i.e. RXBUFFER_2048 --> size-4096 slab
  2596. */
  2597. if (max_frame <= IGB_RXBUFFER_256)
  2598. adapter->rx_buffer_len = IGB_RXBUFFER_256;
  2599. else if (max_frame <= IGB_RXBUFFER_512)
  2600. adapter->rx_buffer_len = IGB_RXBUFFER_512;
  2601. else if (max_frame <= IGB_RXBUFFER_1024)
  2602. adapter->rx_buffer_len = IGB_RXBUFFER_1024;
  2603. else if (max_frame <= IGB_RXBUFFER_2048)
  2604. adapter->rx_buffer_len = IGB_RXBUFFER_2048;
  2605. else
  2606. #if (PAGE_SIZE / 2) > IGB_RXBUFFER_16384
  2607. adapter->rx_buffer_len = IGB_RXBUFFER_16384;
  2608. #else
  2609. adapter->rx_buffer_len = PAGE_SIZE / 2;
  2610. #endif
  2611. /* adjust allocation if LPE protects us, and we aren't using SBP */
  2612. if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
  2613. (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))
  2614. adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
  2615. dev_info(&adapter->pdev->dev, "changing MTU from %d to %d\n",
  2616. netdev->mtu, new_mtu);
  2617. netdev->mtu = new_mtu;
  2618. if (netif_running(netdev))
  2619. igb_up(adapter);
  2620. else
  2621. igb_reset(adapter);
  2622. clear_bit(__IGB_RESETTING, &adapter->state);
  2623. return 0;
  2624. }
  2625. /**
  2626. * igb_update_stats - Update the board statistics counters
  2627. * @adapter: board private structure
  2628. **/
  2629. void igb_update_stats(struct igb_adapter *adapter)
  2630. {
  2631. struct e1000_hw *hw = &adapter->hw;
  2632. struct pci_dev *pdev = adapter->pdev;
  2633. u16 phy_tmp;
  2634. #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
  2635. /*
  2636. * Prevent stats update while adapter is being reset, or if the pci
  2637. * connection is down.
  2638. */
  2639. if (adapter->link_speed == 0)
  2640. return;
  2641. if (pci_channel_offline(pdev))
  2642. return;
  2643. adapter->stats.crcerrs += rd32(E1000_CRCERRS);
  2644. adapter->stats.gprc += rd32(E1000_GPRC);
  2645. adapter->stats.gorc += rd32(E1000_GORCL);
  2646. rd32(E1000_GORCH); /* clear GORCL */
  2647. adapter->stats.bprc += rd32(E1000_BPRC);
  2648. adapter->stats.mprc += rd32(E1000_MPRC);
  2649. adapter->stats.roc += rd32(E1000_ROC);
  2650. adapter->stats.prc64 += rd32(E1000_PRC64);
  2651. adapter->stats.prc127 += rd32(E1000_PRC127);
  2652. adapter->stats.prc255 += rd32(E1000_PRC255);
  2653. adapter->stats.prc511 += rd32(E1000_PRC511);
  2654. adapter->stats.prc1023 += rd32(E1000_PRC1023);
  2655. adapter->stats.prc1522 += rd32(E1000_PRC1522);
  2656. adapter->stats.symerrs += rd32(E1000_SYMERRS);
  2657. adapter->stats.sec += rd32(E1000_SEC);
  2658. adapter->stats.mpc += rd32(E1000_MPC);
  2659. adapter->stats.scc += rd32(E1000_SCC);
  2660. adapter->stats.ecol += rd32(E1000_ECOL);
  2661. adapter->stats.mcc += rd32(E1000_MCC);
  2662. adapter->stats.latecol += rd32(E1000_LATECOL);
  2663. adapter->stats.dc += rd32(E1000_DC);
  2664. adapter->stats.rlec += rd32(E1000_RLEC);
  2665. adapter->stats.xonrxc += rd32(E1000_XONRXC);
  2666. adapter->stats.xontxc += rd32(E1000_XONTXC);
  2667. adapter->stats.xoffrxc += rd32(E1000_XOFFRXC);
  2668. adapter->stats.xofftxc += rd32(E1000_XOFFTXC);
  2669. adapter->stats.fcruc += rd32(E1000_FCRUC);
  2670. adapter->stats.gptc += rd32(E1000_GPTC);
  2671. adapter->stats.gotc += rd32(E1000_GOTCL);
  2672. rd32(E1000_GOTCH); /* clear GOTCL */
  2673. adapter->stats.rnbc += rd32(E1000_RNBC);
  2674. adapter->stats.ruc += rd32(E1000_RUC);
  2675. adapter->stats.rfc += rd32(E1000_RFC);
  2676. adapter->stats.rjc += rd32(E1000_RJC);
  2677. adapter->stats.tor += rd32(E1000_TORH);
  2678. adapter->stats.tot += rd32(E1000_TOTH);
  2679. adapter->stats.tpr += rd32(E1000_TPR);
  2680. adapter->stats.ptc64 += rd32(E1000_PTC64);
  2681. adapter->stats.ptc127 += rd32(E1000_PTC127);
  2682. adapter->stats.ptc255 += rd32(E1000_PTC255);
  2683. adapter->stats.ptc511 += rd32(E1000_PTC511);
  2684. adapter->stats.ptc1023 += rd32(E1000_PTC1023);
  2685. adapter->stats.ptc1522 += rd32(E1000_PTC1522);
  2686. adapter->stats.mptc += rd32(E1000_MPTC);
  2687. adapter->stats.bptc += rd32(E1000_BPTC);
  2688. /* used for adaptive IFS */
  2689. hw->mac.tx_packet_delta = rd32(E1000_TPT);
  2690. adapter->stats.tpt += hw->mac.tx_packet_delta;
  2691. hw->mac.collision_delta = rd32(E1000_COLC);
  2692. adapter->stats.colc += hw->mac.collision_delta;
  2693. adapter->stats.algnerrc += rd32(E1000_ALGNERRC);
  2694. adapter->stats.rxerrc += rd32(E1000_RXERRC);
  2695. adapter->stats.tncrs += rd32(E1000_TNCRS);
  2696. adapter->stats.tsctc += rd32(E1000_TSCTC);
  2697. adapter->stats.tsctfc += rd32(E1000_TSCTFC);
  2698. adapter->stats.iac += rd32(E1000_IAC);
  2699. adapter->stats.icrxoc += rd32(E1000_ICRXOC);
  2700. adapter->stats.icrxptc += rd32(E1000_ICRXPTC);
  2701. adapter->stats.icrxatc += rd32(E1000_ICRXATC);
  2702. adapter->stats.ictxptc += rd32(E1000_ICTXPTC);
  2703. adapter->stats.ictxatc += rd32(E1000_ICTXATC);
  2704. adapter->stats.ictxqec += rd32(E1000_ICTXQEC);
  2705. adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC);
  2706. adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC);
  2707. /* Fill out the OS statistics structure */
  2708. adapter->net_stats.multicast = adapter->stats.mprc;
  2709. adapter->net_stats.collisions = adapter->stats.colc;
  2710. /* Rx Errors */
  2711. /* RLEC on some newer hardware can be incorrect so build
  2712. * our own version based on RUC and ROC */
  2713. adapter->net_stats.rx_errors = adapter->stats.rxerrc +
  2714. adapter->stats.crcerrs + adapter->stats.algnerrc +
  2715. adapter->stats.ruc + adapter->stats.roc +
  2716. adapter->stats.cexterr;
  2717. adapter->net_stats.rx_length_errors = adapter->stats.ruc +
  2718. adapter->stats.roc;
  2719. adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
  2720. adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
  2721. adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
  2722. /* Tx Errors */
  2723. adapter->net_stats.tx_errors = adapter->stats.ecol +
  2724. adapter->stats.latecol;
  2725. adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
  2726. adapter->net_stats.tx_window_errors = adapter->stats.latecol;
  2727. adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
  2728. /* Tx Dropped needs to be maintained elsewhere */
  2729. /* Phy Stats */
  2730. if (hw->phy.media_type == e1000_media_type_copper) {
  2731. if ((adapter->link_speed == SPEED_1000) &&
  2732. (!hw->phy.ops.read_phy_reg(hw, PHY_1000T_STATUS,
  2733. &phy_tmp))) {
  2734. phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
  2735. adapter->phy_stats.idle_errors += phy_tmp;
  2736. }
  2737. }
  2738. /* Management Stats */
  2739. adapter->stats.mgptc += rd32(E1000_MGTPTC);
  2740. adapter->stats.mgprc += rd32(E1000_MGTPRC);
  2741. adapter->stats.mgpdc += rd32(E1000_MGTPDC);
  2742. }
  2743. static irqreturn_t igb_msix_other(int irq, void *data)
  2744. {
  2745. struct net_device *netdev = data;
  2746. struct igb_adapter *adapter = netdev_priv(netdev);
  2747. struct e1000_hw *hw = &adapter->hw;
  2748. u32 icr = rd32(E1000_ICR);
  2749. /* reading ICR causes bit 31 of EICR to be cleared */
  2750. if (!(icr & E1000_ICR_LSC))
  2751. goto no_link_interrupt;
  2752. hw->mac.get_link_status = 1;
  2753. /* guard against interrupt when we're going down */
  2754. if (!test_bit(__IGB_DOWN, &adapter->state))
  2755. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  2756. no_link_interrupt:
  2757. wr32(E1000_IMS, E1000_IMS_LSC);
  2758. wr32(E1000_EIMS, adapter->eims_other);
  2759. return IRQ_HANDLED;
  2760. }
  2761. static irqreturn_t igb_msix_tx(int irq, void *data)
  2762. {
  2763. struct igb_ring *tx_ring = data;
  2764. struct igb_adapter *adapter = tx_ring->adapter;
  2765. struct e1000_hw *hw = &adapter->hw;
  2766. if (!tx_ring->itr_val)
  2767. wr32(E1000_EIMC, tx_ring->eims_value);
  2768. #ifdef CONFIG_DCA
  2769. if (adapter->flags & IGB_FLAG_DCA_ENABLED)
  2770. igb_update_tx_dca(tx_ring);
  2771. #endif
  2772. tx_ring->total_bytes = 0;
  2773. tx_ring->total_packets = 0;
  2774. /* auto mask will automatically reenable the interrupt when we write
  2775. * EICS */
  2776. if (!igb_clean_tx_irq(tx_ring))
  2777. /* Ring was not completely cleaned, so fire another interrupt */
  2778. wr32(E1000_EICS, tx_ring->eims_value);
  2779. else
  2780. wr32(E1000_EIMS, tx_ring->eims_value);
  2781. return IRQ_HANDLED;
  2782. }
  2783. static irqreturn_t igb_msix_rx(int irq, void *data)
  2784. {
  2785. struct igb_ring *rx_ring = data;
  2786. struct igb_adapter *adapter = rx_ring->adapter;
  2787. struct e1000_hw *hw = &adapter->hw;
  2788. /* Write the ITR value calculated at the end of the
  2789. * previous interrupt.
  2790. */
  2791. if (adapter->set_itr) {
  2792. wr32(rx_ring->itr_register,
  2793. 1000000000 / (rx_ring->itr_val * 256));
  2794. adapter->set_itr = 0;
  2795. }
  2796. if (netif_rx_schedule_prep(adapter->netdev, &rx_ring->napi))
  2797. __netif_rx_schedule(adapter->netdev, &rx_ring->napi);
  2798. #ifdef CONFIG_DCA
  2799. if (adapter->flags & IGB_FLAG_DCA_ENABLED)
  2800. igb_update_rx_dca(rx_ring);
  2801. #endif
  2802. return IRQ_HANDLED;
  2803. }
  2804. #ifdef CONFIG_DCA
  2805. static void igb_update_rx_dca(struct igb_ring *rx_ring)
  2806. {
  2807. u32 dca_rxctrl;
  2808. struct igb_adapter *adapter = rx_ring->adapter;
  2809. struct e1000_hw *hw = &adapter->hw;
  2810. int cpu = get_cpu();
  2811. int q = rx_ring - adapter->rx_ring;
  2812. if (rx_ring->cpu != cpu) {
  2813. dca_rxctrl = rd32(E1000_DCA_RXCTRL(q));
  2814. if (hw->mac.type == e1000_82576) {
  2815. dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK_82576;
  2816. dca_rxctrl |= dca_get_tag(cpu) <<
  2817. E1000_DCA_RXCTRL_CPUID_SHIFT;
  2818. } else {
  2819. dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK;
  2820. dca_rxctrl |= dca_get_tag(cpu);
  2821. }
  2822. dca_rxctrl |= E1000_DCA_RXCTRL_DESC_DCA_EN;
  2823. dca_rxctrl |= E1000_DCA_RXCTRL_HEAD_DCA_EN;
  2824. dca_rxctrl |= E1000_DCA_RXCTRL_DATA_DCA_EN;
  2825. wr32(E1000_DCA_RXCTRL(q), dca_rxctrl);
  2826. rx_ring->cpu = cpu;
  2827. }
  2828. put_cpu();
  2829. }
  2830. static void igb_update_tx_dca(struct igb_ring *tx_ring)
  2831. {
  2832. u32 dca_txctrl;
  2833. struct igb_adapter *adapter = tx_ring->adapter;
  2834. struct e1000_hw *hw = &adapter->hw;
  2835. int cpu = get_cpu();
  2836. int q = tx_ring - adapter->tx_ring;
  2837. if (tx_ring->cpu != cpu) {
  2838. dca_txctrl = rd32(E1000_DCA_TXCTRL(q));
  2839. if (hw->mac.type == e1000_82576) {
  2840. dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK_82576;
  2841. dca_txctrl |= dca_get_tag(cpu) <<
  2842. E1000_DCA_TXCTRL_CPUID_SHIFT;
  2843. } else {
  2844. dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK;
  2845. dca_txctrl |= dca_get_tag(cpu);
  2846. }
  2847. dca_txctrl |= E1000_DCA_TXCTRL_DESC_DCA_EN;
  2848. wr32(E1000_DCA_TXCTRL(q), dca_txctrl);
  2849. tx_ring->cpu = cpu;
  2850. }
  2851. put_cpu();
  2852. }
  2853. static void igb_setup_dca(struct igb_adapter *adapter)
  2854. {
  2855. int i;
  2856. if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
  2857. return;
  2858. for (i = 0; i < adapter->num_tx_queues; i++) {
  2859. adapter->tx_ring[i].cpu = -1;
  2860. igb_update_tx_dca(&adapter->tx_ring[i]);
  2861. }
  2862. for (i = 0; i < adapter->num_rx_queues; i++) {
  2863. adapter->rx_ring[i].cpu = -1;
  2864. igb_update_rx_dca(&adapter->rx_ring[i]);
  2865. }
  2866. }
  2867. static int __igb_notify_dca(struct device *dev, void *data)
  2868. {
  2869. struct net_device *netdev = dev_get_drvdata(dev);
  2870. struct igb_adapter *adapter = netdev_priv(netdev);
  2871. struct e1000_hw *hw = &adapter->hw;
  2872. unsigned long event = *(unsigned long *)data;
  2873. if (!(adapter->flags & IGB_FLAG_HAS_DCA))
  2874. goto out;
  2875. switch (event) {
  2876. case DCA_PROVIDER_ADD:
  2877. /* if already enabled, don't do it again */
  2878. if (adapter->flags & IGB_FLAG_DCA_ENABLED)
  2879. break;
  2880. adapter->flags |= IGB_FLAG_DCA_ENABLED;
  2881. /* Always use CB2 mode, difference is masked
  2882. * in the CB driver. */
  2883. wr32(E1000_DCA_CTRL, 2);
  2884. if (dca_add_requester(dev) == 0) {
  2885. dev_info(&adapter->pdev->dev, "DCA enabled\n");
  2886. igb_setup_dca(adapter);
  2887. break;
  2888. }
  2889. /* Fall Through since DCA is disabled. */
  2890. case DCA_PROVIDER_REMOVE:
  2891. if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
  2892. /* without this a class_device is left
  2893. * hanging around in the sysfs model */
  2894. dca_remove_requester(dev);
  2895. dev_info(&adapter->pdev->dev, "DCA disabled\n");
  2896. adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
  2897. wr32(E1000_DCA_CTRL, 1);
  2898. }
  2899. break;
  2900. }
  2901. out:
  2902. return 0;
  2903. }
  2904. static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
  2905. void *p)
  2906. {
  2907. int ret_val;
  2908. ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
  2909. __igb_notify_dca);
  2910. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  2911. }
  2912. #endif /* CONFIG_DCA */
  2913. /**
  2914. * igb_intr_msi - Interrupt Handler
  2915. * @irq: interrupt number
  2916. * @data: pointer to a network interface device structure
  2917. **/
  2918. static irqreturn_t igb_intr_msi(int irq, void *data)
  2919. {
  2920. struct net_device *netdev = data;
  2921. struct igb_adapter *adapter = netdev_priv(netdev);
  2922. struct e1000_hw *hw = &adapter->hw;
  2923. /* read ICR disables interrupts using IAM */
  2924. u32 icr = rd32(E1000_ICR);
  2925. /* Write the ITR value calculated at the end of the
  2926. * previous interrupt.
  2927. */
  2928. if (adapter->set_itr) {
  2929. wr32(E1000_ITR, 1000000000 / (adapter->itr * 256));
  2930. adapter->set_itr = 0;
  2931. }
  2932. if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
  2933. hw->mac.get_link_status = 1;
  2934. if (!test_bit(__IGB_DOWN, &adapter->state))
  2935. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  2936. }
  2937. netif_rx_schedule(netdev, &adapter->rx_ring[0].napi);
  2938. return IRQ_HANDLED;
  2939. }
  2940. /**
  2941. * igb_intr - Interrupt Handler
  2942. * @irq: interrupt number
  2943. * @data: pointer to a network interface device structure
  2944. **/
  2945. static irqreturn_t igb_intr(int irq, void *data)
  2946. {
  2947. struct net_device *netdev = data;
  2948. struct igb_adapter *adapter = netdev_priv(netdev);
  2949. struct e1000_hw *hw = &adapter->hw;
  2950. /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
  2951. * need for the IMC write */
  2952. u32 icr = rd32(E1000_ICR);
  2953. u32 eicr = 0;
  2954. if (!icr)
  2955. return IRQ_NONE; /* Not our interrupt */
  2956. /* Write the ITR value calculated at the end of the
  2957. * previous interrupt.
  2958. */
  2959. if (adapter->set_itr) {
  2960. wr32(E1000_ITR, 1000000000 / (adapter->itr * 256));
  2961. adapter->set_itr = 0;
  2962. }
  2963. /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
  2964. * not set, then the adapter didn't send an interrupt */
  2965. if (!(icr & E1000_ICR_INT_ASSERTED))
  2966. return IRQ_NONE;
  2967. eicr = rd32(E1000_EICR);
  2968. if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
  2969. hw->mac.get_link_status = 1;
  2970. /* guard against interrupt when we're going down */
  2971. if (!test_bit(__IGB_DOWN, &adapter->state))
  2972. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  2973. }
  2974. netif_rx_schedule(netdev, &adapter->rx_ring[0].napi);
  2975. return IRQ_HANDLED;
  2976. }
  2977. /**
  2978. * igb_poll - NAPI Rx polling callback
  2979. * @napi: napi polling structure
  2980. * @budget: count of how many packets we should handle
  2981. **/
  2982. static int igb_poll(struct napi_struct *napi, int budget)
  2983. {
  2984. struct igb_ring *rx_ring = container_of(napi, struct igb_ring, napi);
  2985. struct igb_adapter *adapter = rx_ring->adapter;
  2986. struct net_device *netdev = adapter->netdev;
  2987. int tx_clean_complete, work_done = 0;
  2988. /* this poll routine only supports one tx and one rx queue */
  2989. #ifdef CONFIG_DCA
  2990. if (adapter->flags & IGB_FLAG_DCA_ENABLED)
  2991. igb_update_tx_dca(&adapter->tx_ring[0]);
  2992. #endif
  2993. tx_clean_complete = igb_clean_tx_irq(&adapter->tx_ring[0]);
  2994. #ifdef CONFIG_DCA
  2995. if (adapter->flags & IGB_FLAG_DCA_ENABLED)
  2996. igb_update_rx_dca(&adapter->rx_ring[0]);
  2997. #endif
  2998. igb_clean_rx_irq_adv(&adapter->rx_ring[0], &work_done, budget);
  2999. /* If no Tx and not enough Rx work done, exit the polling mode */
  3000. if ((tx_clean_complete && (work_done < budget)) ||
  3001. !netif_running(netdev)) {
  3002. if (adapter->itr_setting & 3)
  3003. igb_set_itr(adapter, E1000_ITR, false);
  3004. netif_rx_complete(netdev, napi);
  3005. if (!test_bit(__IGB_DOWN, &adapter->state))
  3006. igb_irq_enable(adapter);
  3007. return 0;
  3008. }
  3009. return 1;
  3010. }
  3011. static int igb_clean_rx_ring_msix(struct napi_struct *napi, int budget)
  3012. {
  3013. struct igb_ring *rx_ring = container_of(napi, struct igb_ring, napi);
  3014. struct igb_adapter *adapter = rx_ring->adapter;
  3015. struct e1000_hw *hw = &adapter->hw;
  3016. struct net_device *netdev = adapter->netdev;
  3017. int work_done = 0;
  3018. /* Keep link state information with original netdev */
  3019. if (!netif_carrier_ok(netdev))
  3020. goto quit_polling;
  3021. #ifdef CONFIG_DCA
  3022. if (adapter->flags & IGB_FLAG_DCA_ENABLED)
  3023. igb_update_rx_dca(rx_ring);
  3024. #endif
  3025. igb_clean_rx_irq_adv(rx_ring, &work_done, budget);
  3026. /* If not enough Rx work done, exit the polling mode */
  3027. if ((work_done == 0) || !netif_running(netdev)) {
  3028. quit_polling:
  3029. netif_rx_complete(netdev, napi);
  3030. wr32(E1000_EIMS, rx_ring->eims_value);
  3031. if ((adapter->itr_setting & 3) && !rx_ring->no_itr_adjust &&
  3032. (rx_ring->total_packets > IGB_DYN_ITR_PACKET_THRESHOLD)) {
  3033. int mean_size = rx_ring->total_bytes /
  3034. rx_ring->total_packets;
  3035. if (mean_size < IGB_DYN_ITR_LENGTH_LOW)
  3036. igb_raise_rx_eitr(adapter, rx_ring);
  3037. else if (mean_size > IGB_DYN_ITR_LENGTH_HIGH)
  3038. igb_lower_rx_eitr(adapter, rx_ring);
  3039. }
  3040. if (!test_bit(__IGB_DOWN, &adapter->state))
  3041. wr32(E1000_EIMS, rx_ring->eims_value);
  3042. return 0;
  3043. }
  3044. return 1;
  3045. }
  3046. static inline u32 get_head(struct igb_ring *tx_ring)
  3047. {
  3048. void *end = (struct e1000_tx_desc *)tx_ring->desc + tx_ring->count;
  3049. return le32_to_cpu(*(volatile __le32 *)end);
  3050. }
  3051. /**
  3052. * igb_clean_tx_irq - Reclaim resources after transmit completes
  3053. * @adapter: board private structure
  3054. * returns true if ring is completely cleaned
  3055. **/
  3056. static bool igb_clean_tx_irq(struct igb_ring *tx_ring)
  3057. {
  3058. struct igb_adapter *adapter = tx_ring->adapter;
  3059. struct e1000_hw *hw = &adapter->hw;
  3060. struct net_device *netdev = adapter->netdev;
  3061. struct e1000_tx_desc *tx_desc;
  3062. struct igb_buffer *buffer_info;
  3063. struct sk_buff *skb;
  3064. unsigned int i;
  3065. u32 head, oldhead;
  3066. unsigned int count = 0;
  3067. bool cleaned = false;
  3068. bool retval = true;
  3069. unsigned int total_bytes = 0, total_packets = 0;
  3070. rmb();
  3071. head = get_head(tx_ring);
  3072. i = tx_ring->next_to_clean;
  3073. while (1) {
  3074. while (i != head) {
  3075. cleaned = true;
  3076. tx_desc = E1000_TX_DESC(*tx_ring, i);
  3077. buffer_info = &tx_ring->buffer_info[i];
  3078. skb = buffer_info->skb;
  3079. if (skb) {
  3080. unsigned int segs, bytecount;
  3081. /* gso_segs is currently only valid for tcp */
  3082. segs = skb_shinfo(skb)->gso_segs ?: 1;
  3083. /* multiply data chunks by size of headers */
  3084. bytecount = ((segs - 1) * skb_headlen(skb)) +
  3085. skb->len;
  3086. total_packets += segs;
  3087. total_bytes += bytecount;
  3088. }
  3089. igb_unmap_and_free_tx_resource(adapter, buffer_info);
  3090. tx_desc->upper.data = 0;
  3091. i++;
  3092. if (i == tx_ring->count)
  3093. i = 0;
  3094. count++;
  3095. if (count == IGB_MAX_TX_CLEAN) {
  3096. retval = false;
  3097. goto done_cleaning;
  3098. }
  3099. }
  3100. oldhead = head;
  3101. rmb();
  3102. head = get_head(tx_ring);
  3103. if (head == oldhead)
  3104. goto done_cleaning;
  3105. } /* while (1) */
  3106. done_cleaning:
  3107. tx_ring->next_to_clean = i;
  3108. if (unlikely(cleaned &&
  3109. netif_carrier_ok(netdev) &&
  3110. IGB_DESC_UNUSED(tx_ring) >= IGB_TX_QUEUE_WAKE)) {
  3111. /* Make sure that anybody stopping the queue after this
  3112. * sees the new next_to_clean.
  3113. */
  3114. smp_mb();
  3115. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  3116. if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
  3117. !(test_bit(__IGB_DOWN, &adapter->state))) {
  3118. netif_wake_subqueue(netdev, tx_ring->queue_index);
  3119. ++adapter->restart_queue;
  3120. }
  3121. #else
  3122. if (netif_queue_stopped(netdev) &&
  3123. !(test_bit(__IGB_DOWN, &adapter->state))) {
  3124. netif_wake_queue(netdev);
  3125. ++adapter->restart_queue;
  3126. }
  3127. #endif
  3128. }
  3129. if (tx_ring->detect_tx_hung) {
  3130. /* Detect a transmit hang in hardware, this serializes the
  3131. * check with the clearing of time_stamp and movement of i */
  3132. tx_ring->detect_tx_hung = false;
  3133. if (tx_ring->buffer_info[i].time_stamp &&
  3134. time_after(jiffies, tx_ring->buffer_info[i].time_stamp +
  3135. (adapter->tx_timeout_factor * HZ))
  3136. && !(rd32(E1000_STATUS) &
  3137. E1000_STATUS_TXOFF)) {
  3138. tx_desc = E1000_TX_DESC(*tx_ring, i);
  3139. /* detected Tx unit hang */
  3140. dev_err(&adapter->pdev->dev,
  3141. "Detected Tx Unit Hang\n"
  3142. " Tx Queue <%d>\n"
  3143. " TDH <%x>\n"
  3144. " TDT <%x>\n"
  3145. " next_to_use <%x>\n"
  3146. " next_to_clean <%x>\n"
  3147. " head (WB) <%x>\n"
  3148. "buffer_info[next_to_clean]\n"
  3149. " time_stamp <%lx>\n"
  3150. " jiffies <%lx>\n"
  3151. " desc.status <%x>\n",
  3152. tx_ring->queue_index,
  3153. readl(adapter->hw.hw_addr + tx_ring->head),
  3154. readl(adapter->hw.hw_addr + tx_ring->tail),
  3155. tx_ring->next_to_use,
  3156. tx_ring->next_to_clean,
  3157. head,
  3158. tx_ring->buffer_info[i].time_stamp,
  3159. jiffies,
  3160. tx_desc->upper.fields.status);
  3161. #ifdef CONFIG_NETDEVICES_MULTIQUEUE
  3162. netif_stop_subqueue(netdev, tx_ring->queue_index);
  3163. #else
  3164. netif_stop_queue(netdev);
  3165. #endif
  3166. }
  3167. }
  3168. tx_ring->total_bytes += total_bytes;
  3169. tx_ring->total_packets += total_packets;
  3170. tx_ring->tx_stats.bytes += total_bytes;
  3171. tx_ring->tx_stats.packets += total_packets;
  3172. adapter->net_stats.tx_bytes += total_bytes;
  3173. adapter->net_stats.tx_packets += total_packets;
  3174. return retval;
  3175. }
  3176. /**
  3177. * igb_receive_skb - helper function to handle rx indications
  3178. * @adapter: board private structure
  3179. * @status: descriptor status field as written by hardware
  3180. * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
  3181. * @skb: pointer to sk_buff to be indicated to stack
  3182. **/
  3183. static void igb_receive_skb(struct igb_adapter *adapter, u8 status, __le16 vlan,
  3184. struct sk_buff *skb)
  3185. {
  3186. if (adapter->vlgrp && (status & E1000_RXD_STAT_VP))
  3187. vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
  3188. le16_to_cpu(vlan));
  3189. else
  3190. netif_receive_skb(skb);
  3191. }
  3192. static inline void igb_rx_checksum_adv(struct igb_adapter *adapter,
  3193. u32 status_err, struct sk_buff *skb)
  3194. {
  3195. skb->ip_summed = CHECKSUM_NONE;
  3196. /* Ignore Checksum bit is set or checksum is disabled through ethtool */
  3197. if ((status_err & E1000_RXD_STAT_IXSM) || !adapter->rx_csum)
  3198. return;
  3199. /* TCP/UDP checksum error bit is set */
  3200. if (status_err &
  3201. (E1000_RXDEXT_STATERR_TCPE | E1000_RXDEXT_STATERR_IPE)) {
  3202. /* let the stack verify checksum errors */
  3203. adapter->hw_csum_err++;
  3204. return;
  3205. }
  3206. /* It must be a TCP or UDP packet with a valid checksum */
  3207. if (status_err & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))
  3208. skb->ip_summed = CHECKSUM_UNNECESSARY;
  3209. adapter->hw_csum_good++;
  3210. }
  3211. static bool igb_clean_rx_irq_adv(struct igb_ring *rx_ring,
  3212. int *work_done, int budget)
  3213. {
  3214. struct igb_adapter *adapter = rx_ring->adapter;
  3215. struct net_device *netdev = adapter->netdev;
  3216. struct pci_dev *pdev = adapter->pdev;
  3217. union e1000_adv_rx_desc *rx_desc , *next_rxd;
  3218. struct igb_buffer *buffer_info , *next_buffer;
  3219. struct sk_buff *skb;
  3220. unsigned int i;
  3221. u32 length, hlen, staterr;
  3222. bool cleaned = false;
  3223. int cleaned_count = 0;
  3224. unsigned int total_bytes = 0, total_packets = 0;
  3225. i = rx_ring->next_to_clean;
  3226. rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
  3227. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  3228. while (staterr & E1000_RXD_STAT_DD) {
  3229. if (*work_done >= budget)
  3230. break;
  3231. (*work_done)++;
  3232. buffer_info = &rx_ring->buffer_info[i];
  3233. /* HW will not DMA in data larger than the given buffer, even
  3234. * if it parses the (NFS, of course) header to be larger. In
  3235. * that case, it fills the header buffer and spills the rest
  3236. * into the page.
  3237. */
  3238. hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info) &
  3239. E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT;
  3240. if (hlen > adapter->rx_ps_hdr_size)
  3241. hlen = adapter->rx_ps_hdr_size;
  3242. length = le16_to_cpu(rx_desc->wb.upper.length);
  3243. cleaned = true;
  3244. cleaned_count++;
  3245. skb = buffer_info->skb;
  3246. prefetch(skb->data - NET_IP_ALIGN);
  3247. buffer_info->skb = NULL;
  3248. if (!adapter->rx_ps_hdr_size) {
  3249. pci_unmap_single(pdev, buffer_info->dma,
  3250. adapter->rx_buffer_len +
  3251. NET_IP_ALIGN,
  3252. PCI_DMA_FROMDEVICE);
  3253. skb_put(skb, length);
  3254. goto send_up;
  3255. }
  3256. if (!skb_shinfo(skb)->nr_frags) {
  3257. pci_unmap_single(pdev, buffer_info->dma,
  3258. adapter->rx_ps_hdr_size +
  3259. NET_IP_ALIGN,
  3260. PCI_DMA_FROMDEVICE);
  3261. skb_put(skb, hlen);
  3262. }
  3263. if (length) {
  3264. pci_unmap_page(pdev, buffer_info->page_dma,
  3265. PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
  3266. buffer_info->page_dma = 0;
  3267. skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags++,
  3268. buffer_info->page,
  3269. buffer_info->page_offset,
  3270. length);
  3271. if ((adapter->rx_buffer_len > (PAGE_SIZE / 2)) ||
  3272. (page_count(buffer_info->page) != 1))
  3273. buffer_info->page = NULL;
  3274. else
  3275. get_page(buffer_info->page);
  3276. skb->len += length;
  3277. skb->data_len += length;
  3278. skb->truesize += length;
  3279. }
  3280. send_up:
  3281. i++;
  3282. if (i == rx_ring->count)
  3283. i = 0;
  3284. next_rxd = E1000_RX_DESC_ADV(*rx_ring, i);
  3285. prefetch(next_rxd);
  3286. next_buffer = &rx_ring->buffer_info[i];
  3287. if (!(staterr & E1000_RXD_STAT_EOP)) {
  3288. buffer_info->skb = xchg(&next_buffer->skb, skb);
  3289. buffer_info->dma = xchg(&next_buffer->dma, 0);
  3290. goto next_desc;
  3291. }
  3292. if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
  3293. dev_kfree_skb_irq(skb);
  3294. goto next_desc;
  3295. }
  3296. rx_ring->no_itr_adjust |= (staterr & E1000_RXD_STAT_DYNINT);
  3297. total_bytes += skb->len;
  3298. total_packets++;
  3299. igb_rx_checksum_adv(adapter, staterr, skb);
  3300. skb->protocol = eth_type_trans(skb, netdev);
  3301. igb_receive_skb(adapter, staterr, rx_desc->wb.upper.vlan, skb);
  3302. netdev->last_rx = jiffies;
  3303. next_desc:
  3304. rx_desc->wb.upper.status_error = 0;
  3305. /* return some buffers to hardware, one at a time is too slow */
  3306. if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
  3307. igb_alloc_rx_buffers_adv(rx_ring, cleaned_count);
  3308. cleaned_count = 0;
  3309. }
  3310. /* use prefetched values */
  3311. rx_desc = next_rxd;
  3312. buffer_info = next_buffer;
  3313. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  3314. }
  3315. rx_ring->next_to_clean = i;
  3316. cleaned_count = IGB_DESC_UNUSED(rx_ring);
  3317. if (cleaned_count)
  3318. igb_alloc_rx_buffers_adv(rx_ring, cleaned_count);
  3319. rx_ring->total_packets += total_packets;
  3320. rx_ring->total_bytes += total_bytes;
  3321. rx_ring->rx_stats.packets += total_packets;
  3322. rx_ring->rx_stats.bytes += total_bytes;
  3323. adapter->net_stats.rx_bytes += total_bytes;
  3324. adapter->net_stats.rx_packets += total_packets;
  3325. return cleaned;
  3326. }
  3327. /**
  3328. * igb_alloc_rx_buffers_adv - Replace used receive buffers; packet split
  3329. * @adapter: address of board private structure
  3330. **/
  3331. static void igb_alloc_rx_buffers_adv(struct igb_ring *rx_ring,
  3332. int cleaned_count)
  3333. {
  3334. struct igb_adapter *adapter = rx_ring->adapter;
  3335. struct net_device *netdev = adapter->netdev;
  3336. struct pci_dev *pdev = adapter->pdev;
  3337. union e1000_adv_rx_desc *rx_desc;
  3338. struct igb_buffer *buffer_info;
  3339. struct sk_buff *skb;
  3340. unsigned int i;
  3341. i = rx_ring->next_to_use;
  3342. buffer_info = &rx_ring->buffer_info[i];
  3343. while (cleaned_count--) {
  3344. rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
  3345. if (adapter->rx_ps_hdr_size && !buffer_info->page_dma) {
  3346. if (!buffer_info->page) {
  3347. buffer_info->page = alloc_page(GFP_ATOMIC);
  3348. if (!buffer_info->page) {
  3349. adapter->alloc_rx_buff_failed++;
  3350. goto no_buffers;
  3351. }
  3352. buffer_info->page_offset = 0;
  3353. } else {
  3354. buffer_info->page_offset ^= PAGE_SIZE / 2;
  3355. }
  3356. buffer_info->page_dma =
  3357. pci_map_page(pdev,
  3358. buffer_info->page,
  3359. buffer_info->page_offset,
  3360. PAGE_SIZE / 2,
  3361. PCI_DMA_FROMDEVICE);
  3362. }
  3363. if (!buffer_info->skb) {
  3364. int bufsz;
  3365. if (adapter->rx_ps_hdr_size)
  3366. bufsz = adapter->rx_ps_hdr_size;
  3367. else
  3368. bufsz = adapter->rx_buffer_len;
  3369. bufsz += NET_IP_ALIGN;
  3370. skb = netdev_alloc_skb(netdev, bufsz);
  3371. if (!skb) {
  3372. adapter->alloc_rx_buff_failed++;
  3373. goto no_buffers;
  3374. }
  3375. /* Make buffer alignment 2 beyond a 16 byte boundary
  3376. * this will result in a 16 byte aligned IP header after
  3377. * the 14 byte MAC header is removed
  3378. */
  3379. skb_reserve(skb, NET_IP_ALIGN);
  3380. buffer_info->skb = skb;
  3381. buffer_info->dma = pci_map_single(pdev, skb->data,
  3382. bufsz,
  3383. PCI_DMA_FROMDEVICE);
  3384. }
  3385. /* Refresh the desc even if buffer_addrs didn't change because
  3386. * each write-back erases this info. */
  3387. if (adapter->rx_ps_hdr_size) {
  3388. rx_desc->read.pkt_addr =
  3389. cpu_to_le64(buffer_info->page_dma);
  3390. rx_desc->read.hdr_addr = cpu_to_le64(buffer_info->dma);
  3391. } else {
  3392. rx_desc->read.pkt_addr =
  3393. cpu_to_le64(buffer_info->dma);
  3394. rx_desc->read.hdr_addr = 0;
  3395. }
  3396. i++;
  3397. if (i == rx_ring->count)
  3398. i = 0;
  3399. buffer_info = &rx_ring->buffer_info[i];
  3400. }
  3401. no_buffers:
  3402. if (rx_ring->next_to_use != i) {
  3403. rx_ring->next_to_use = i;
  3404. if (i == 0)
  3405. i = (rx_ring->count - 1);
  3406. else
  3407. i--;
  3408. /* Force memory writes to complete before letting h/w
  3409. * know there are new descriptors to fetch. (Only
  3410. * applicable for weak-ordered memory model archs,
  3411. * such as IA-64). */
  3412. wmb();
  3413. writel(i, adapter->hw.hw_addr + rx_ring->tail);
  3414. }
  3415. }
  3416. /**
  3417. * igb_mii_ioctl -
  3418. * @netdev:
  3419. * @ifreq:
  3420. * @cmd:
  3421. **/
  3422. static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  3423. {
  3424. struct igb_adapter *adapter = netdev_priv(netdev);
  3425. struct mii_ioctl_data *data = if_mii(ifr);
  3426. if (adapter->hw.phy.media_type != e1000_media_type_copper)
  3427. return -EOPNOTSUPP;
  3428. switch (cmd) {
  3429. case SIOCGMIIPHY:
  3430. data->phy_id = adapter->hw.phy.addr;
  3431. break;
  3432. case SIOCGMIIREG:
  3433. if (!capable(CAP_NET_ADMIN))
  3434. return -EPERM;
  3435. if (adapter->hw.phy.ops.read_phy_reg(&adapter->hw,
  3436. data->reg_num
  3437. & 0x1F, &data->val_out))
  3438. return -EIO;
  3439. break;
  3440. case SIOCSMIIREG:
  3441. default:
  3442. return -EOPNOTSUPP;
  3443. }
  3444. return 0;
  3445. }
  3446. /**
  3447. * igb_ioctl -
  3448. * @netdev:
  3449. * @ifreq:
  3450. * @cmd:
  3451. **/
  3452. static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  3453. {
  3454. switch (cmd) {
  3455. case SIOCGMIIPHY:
  3456. case SIOCGMIIREG:
  3457. case SIOCSMIIREG:
  3458. return igb_mii_ioctl(netdev, ifr, cmd);
  3459. default:
  3460. return -EOPNOTSUPP;
  3461. }
  3462. }
  3463. static void igb_vlan_rx_register(struct net_device *netdev,
  3464. struct vlan_group *grp)
  3465. {
  3466. struct igb_adapter *adapter = netdev_priv(netdev);
  3467. struct e1000_hw *hw = &adapter->hw;
  3468. u32 ctrl, rctl;
  3469. igb_irq_disable(adapter);
  3470. adapter->vlgrp = grp;
  3471. if (grp) {
  3472. /* enable VLAN tag insert/strip */
  3473. ctrl = rd32(E1000_CTRL);
  3474. ctrl |= E1000_CTRL_VME;
  3475. wr32(E1000_CTRL, ctrl);
  3476. /* enable VLAN receive filtering */
  3477. rctl = rd32(E1000_RCTL);
  3478. rctl |= E1000_RCTL_VFE;
  3479. rctl &= ~E1000_RCTL_CFIEN;
  3480. wr32(E1000_RCTL, rctl);
  3481. igb_update_mng_vlan(adapter);
  3482. wr32(E1000_RLPML,
  3483. adapter->max_frame_size + VLAN_TAG_SIZE);
  3484. } else {
  3485. /* disable VLAN tag insert/strip */
  3486. ctrl = rd32(E1000_CTRL);
  3487. ctrl &= ~E1000_CTRL_VME;
  3488. wr32(E1000_CTRL, ctrl);
  3489. /* disable VLAN filtering */
  3490. rctl = rd32(E1000_RCTL);
  3491. rctl &= ~E1000_RCTL_VFE;
  3492. wr32(E1000_RCTL, rctl);
  3493. if (adapter->mng_vlan_id != (u16)IGB_MNG_VLAN_NONE) {
  3494. igb_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
  3495. adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
  3496. }
  3497. wr32(E1000_RLPML,
  3498. adapter->max_frame_size);
  3499. }
  3500. if (!test_bit(__IGB_DOWN, &adapter->state))
  3501. igb_irq_enable(adapter);
  3502. }
  3503. static void igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  3504. {
  3505. struct igb_adapter *adapter = netdev_priv(netdev);
  3506. struct e1000_hw *hw = &adapter->hw;
  3507. u32 vfta, index;
  3508. if ((adapter->hw.mng_cookie.status &
  3509. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
  3510. (vid == adapter->mng_vlan_id))
  3511. return;
  3512. /* add VID to filter table */
  3513. index = (vid >> 5) & 0x7F;
  3514. vfta = array_rd32(E1000_VFTA, index);
  3515. vfta |= (1 << (vid & 0x1F));
  3516. igb_write_vfta(&adapter->hw, index, vfta);
  3517. }
  3518. static void igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  3519. {
  3520. struct igb_adapter *adapter = netdev_priv(netdev);
  3521. struct e1000_hw *hw = &adapter->hw;
  3522. u32 vfta, index;
  3523. igb_irq_disable(adapter);
  3524. vlan_group_set_device(adapter->vlgrp, vid, NULL);
  3525. if (!test_bit(__IGB_DOWN, &adapter->state))
  3526. igb_irq_enable(adapter);
  3527. if ((adapter->hw.mng_cookie.status &
  3528. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
  3529. (vid == adapter->mng_vlan_id)) {
  3530. /* release control to f/w */
  3531. igb_release_hw_control(adapter);
  3532. return;
  3533. }
  3534. /* remove VID from filter table */
  3535. index = (vid >> 5) & 0x7F;
  3536. vfta = array_rd32(E1000_VFTA, index);
  3537. vfta &= ~(1 << (vid & 0x1F));
  3538. igb_write_vfta(&adapter->hw, index, vfta);
  3539. }
  3540. static void igb_restore_vlan(struct igb_adapter *adapter)
  3541. {
  3542. igb_vlan_rx_register(adapter->netdev, adapter->vlgrp);
  3543. if (adapter->vlgrp) {
  3544. u16 vid;
  3545. for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
  3546. if (!vlan_group_get_device(adapter->vlgrp, vid))
  3547. continue;
  3548. igb_vlan_rx_add_vid(adapter->netdev, vid);
  3549. }
  3550. }
  3551. }
  3552. int igb_set_spd_dplx(struct igb_adapter *adapter, u16 spddplx)
  3553. {
  3554. struct e1000_mac_info *mac = &adapter->hw.mac;
  3555. mac->autoneg = 0;
  3556. /* Fiber NICs only allow 1000 gbps Full duplex */
  3557. if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
  3558. spddplx != (SPEED_1000 + DUPLEX_FULL)) {
  3559. dev_err(&adapter->pdev->dev,
  3560. "Unsupported Speed/Duplex configuration\n");
  3561. return -EINVAL;
  3562. }
  3563. switch (spddplx) {
  3564. case SPEED_10 + DUPLEX_HALF:
  3565. mac->forced_speed_duplex = ADVERTISE_10_HALF;
  3566. break;
  3567. case SPEED_10 + DUPLEX_FULL:
  3568. mac->forced_speed_duplex = ADVERTISE_10_FULL;
  3569. break;
  3570. case SPEED_100 + DUPLEX_HALF:
  3571. mac->forced_speed_duplex = ADVERTISE_100_HALF;
  3572. break;
  3573. case SPEED_100 + DUPLEX_FULL:
  3574. mac->forced_speed_duplex = ADVERTISE_100_FULL;
  3575. break;
  3576. case SPEED_1000 + DUPLEX_FULL:
  3577. mac->autoneg = 1;
  3578. adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
  3579. break;
  3580. case SPEED_1000 + DUPLEX_HALF: /* not supported */
  3581. default:
  3582. dev_err(&adapter->pdev->dev,
  3583. "Unsupported Speed/Duplex configuration\n");
  3584. return -EINVAL;
  3585. }
  3586. return 0;
  3587. }
  3588. static int igb_suspend(struct pci_dev *pdev, pm_message_t state)
  3589. {
  3590. struct net_device *netdev = pci_get_drvdata(pdev);
  3591. struct igb_adapter *adapter = netdev_priv(netdev);
  3592. struct e1000_hw *hw = &adapter->hw;
  3593. u32 ctrl, rctl, status;
  3594. u32 wufc = adapter->wol;
  3595. #ifdef CONFIG_PM
  3596. int retval = 0;
  3597. #endif
  3598. netif_device_detach(netdev);
  3599. if (netif_running(netdev)) {
  3600. WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
  3601. igb_down(adapter);
  3602. igb_free_irq(adapter);
  3603. }
  3604. #ifdef CONFIG_PM
  3605. retval = pci_save_state(pdev);
  3606. if (retval)
  3607. return retval;
  3608. #endif
  3609. status = rd32(E1000_STATUS);
  3610. if (status & E1000_STATUS_LU)
  3611. wufc &= ~E1000_WUFC_LNKC;
  3612. if (wufc) {
  3613. igb_setup_rctl(adapter);
  3614. igb_set_multi(netdev);
  3615. /* turn on all-multi mode if wake on multicast is enabled */
  3616. if (wufc & E1000_WUFC_MC) {
  3617. rctl = rd32(E1000_RCTL);
  3618. rctl |= E1000_RCTL_MPE;
  3619. wr32(E1000_RCTL, rctl);
  3620. }
  3621. ctrl = rd32(E1000_CTRL);
  3622. /* advertise wake from D3Cold */
  3623. #define E1000_CTRL_ADVD3WUC 0x00100000
  3624. /* phy power management enable */
  3625. #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
  3626. ctrl |= E1000_CTRL_ADVD3WUC;
  3627. wr32(E1000_CTRL, ctrl);
  3628. /* Allow time for pending master requests to run */
  3629. igb_disable_pcie_master(&adapter->hw);
  3630. wr32(E1000_WUC, E1000_WUC_PME_EN);
  3631. wr32(E1000_WUFC, wufc);
  3632. } else {
  3633. wr32(E1000_WUC, 0);
  3634. wr32(E1000_WUFC, 0);
  3635. }
  3636. /* make sure adapter isn't asleep if manageability/wol is enabled */
  3637. if (wufc || adapter->en_mng_pt) {
  3638. pci_enable_wake(pdev, PCI_D3hot, 1);
  3639. pci_enable_wake(pdev, PCI_D3cold, 1);
  3640. } else {
  3641. igb_shutdown_fiber_serdes_link_82575(hw);
  3642. pci_enable_wake(pdev, PCI_D3hot, 0);
  3643. pci_enable_wake(pdev, PCI_D3cold, 0);
  3644. }
  3645. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  3646. * would have already happened in close and is redundant. */
  3647. igb_release_hw_control(adapter);
  3648. pci_disable_device(pdev);
  3649. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  3650. return 0;
  3651. }
  3652. #ifdef CONFIG_PM
  3653. static int igb_resume(struct pci_dev *pdev)
  3654. {
  3655. struct net_device *netdev = pci_get_drvdata(pdev);
  3656. struct igb_adapter *adapter = netdev_priv(netdev);
  3657. struct e1000_hw *hw = &adapter->hw;
  3658. u32 err;
  3659. pci_set_power_state(pdev, PCI_D0);
  3660. pci_restore_state(pdev);
  3661. if (adapter->need_ioport)
  3662. err = pci_enable_device(pdev);
  3663. else
  3664. err = pci_enable_device_mem(pdev);
  3665. if (err) {
  3666. dev_err(&pdev->dev,
  3667. "igb: Cannot enable PCI device from suspend\n");
  3668. return err;
  3669. }
  3670. pci_set_master(pdev);
  3671. pci_enable_wake(pdev, PCI_D3hot, 0);
  3672. pci_enable_wake(pdev, PCI_D3cold, 0);
  3673. if (netif_running(netdev)) {
  3674. err = igb_request_irq(adapter);
  3675. if (err)
  3676. return err;
  3677. }
  3678. /* e1000_power_up_phy(adapter); */
  3679. igb_reset(adapter);
  3680. wr32(E1000_WUS, ~0);
  3681. igb_init_manageability(adapter);
  3682. if (netif_running(netdev))
  3683. igb_up(adapter);
  3684. netif_device_attach(netdev);
  3685. /* let the f/w know that the h/w is now under the control of the
  3686. * driver. */
  3687. igb_get_hw_control(adapter);
  3688. return 0;
  3689. }
  3690. #endif
  3691. static void igb_shutdown(struct pci_dev *pdev)
  3692. {
  3693. igb_suspend(pdev, PMSG_SUSPEND);
  3694. }
  3695. #ifdef CONFIG_NET_POLL_CONTROLLER
  3696. /*
  3697. * Polling 'interrupt' - used by things like netconsole to send skbs
  3698. * without having to re-enable interrupts. It's not called while
  3699. * the interrupt routine is executing.
  3700. */
  3701. static void igb_netpoll(struct net_device *netdev)
  3702. {
  3703. struct igb_adapter *adapter = netdev_priv(netdev);
  3704. int i;
  3705. int work_done = 0;
  3706. igb_irq_disable(adapter);
  3707. adapter->flags |= IGB_FLAG_IN_NETPOLL;
  3708. for (i = 0; i < adapter->num_tx_queues; i++)
  3709. igb_clean_tx_irq(&adapter->tx_ring[i]);
  3710. for (i = 0; i < adapter->num_rx_queues; i++)
  3711. igb_clean_rx_irq_adv(&adapter->rx_ring[i],
  3712. &work_done,
  3713. adapter->rx_ring[i].napi.weight);
  3714. adapter->flags &= ~IGB_FLAG_IN_NETPOLL;
  3715. igb_irq_enable(adapter);
  3716. }
  3717. #endif /* CONFIG_NET_POLL_CONTROLLER */
  3718. /**
  3719. * igb_io_error_detected - called when PCI error is detected
  3720. * @pdev: Pointer to PCI device
  3721. * @state: The current pci connection state
  3722. *
  3723. * This function is called after a PCI bus error affecting
  3724. * this device has been detected.
  3725. */
  3726. static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
  3727. pci_channel_state_t state)
  3728. {
  3729. struct net_device *netdev = pci_get_drvdata(pdev);
  3730. struct igb_adapter *adapter = netdev_priv(netdev);
  3731. netif_device_detach(netdev);
  3732. if (netif_running(netdev))
  3733. igb_down(adapter);
  3734. pci_disable_device(pdev);
  3735. /* Request a slot slot reset. */
  3736. return PCI_ERS_RESULT_NEED_RESET;
  3737. }
  3738. /**
  3739. * igb_io_slot_reset - called after the pci bus has been reset.
  3740. * @pdev: Pointer to PCI device
  3741. *
  3742. * Restart the card from scratch, as if from a cold-boot. Implementation
  3743. * resembles the first-half of the igb_resume routine.
  3744. */
  3745. static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
  3746. {
  3747. struct net_device *netdev = pci_get_drvdata(pdev);
  3748. struct igb_adapter *adapter = netdev_priv(netdev);
  3749. struct e1000_hw *hw = &adapter->hw;
  3750. int err;
  3751. if (adapter->need_ioport)
  3752. err = pci_enable_device(pdev);
  3753. else
  3754. err = pci_enable_device_mem(pdev);
  3755. if (err) {
  3756. dev_err(&pdev->dev,
  3757. "Cannot re-enable PCI device after reset.\n");
  3758. return PCI_ERS_RESULT_DISCONNECT;
  3759. }
  3760. pci_set_master(pdev);
  3761. pci_restore_state(pdev);
  3762. pci_enable_wake(pdev, PCI_D3hot, 0);
  3763. pci_enable_wake(pdev, PCI_D3cold, 0);
  3764. igb_reset(adapter);
  3765. wr32(E1000_WUS, ~0);
  3766. return PCI_ERS_RESULT_RECOVERED;
  3767. }
  3768. /**
  3769. * igb_io_resume - called when traffic can start flowing again.
  3770. * @pdev: Pointer to PCI device
  3771. *
  3772. * This callback is called when the error recovery driver tells us that
  3773. * its OK to resume normal operation. Implementation resembles the
  3774. * second-half of the igb_resume routine.
  3775. */
  3776. static void igb_io_resume(struct pci_dev *pdev)
  3777. {
  3778. struct net_device *netdev = pci_get_drvdata(pdev);
  3779. struct igb_adapter *adapter = netdev_priv(netdev);
  3780. igb_init_manageability(adapter);
  3781. if (netif_running(netdev)) {
  3782. if (igb_up(adapter)) {
  3783. dev_err(&pdev->dev, "igb_up failed after reset\n");
  3784. return;
  3785. }
  3786. }
  3787. netif_device_attach(netdev);
  3788. /* let the f/w know that the h/w is now under the control of the
  3789. * driver. */
  3790. igb_get_hw_control(adapter);
  3791. }
  3792. /* igb_main.c */