igb_main.c 121 KB

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