igb_main.c 122 KB

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