ixgbevf_main.c 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435
  1. /*******************************************************************************
  2. Intel 82599 Virtual Function driver
  3. Copyright(c) 1999 - 2012 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. /******************************************************************************
  21. Copyright (c)2006 - 2007 Myricom, Inc. for some LRO specific code
  22. ******************************************************************************/
  23. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  24. #include <linux/types.h>
  25. #include <linux/bitops.h>
  26. #include <linux/module.h>
  27. #include <linux/pci.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/vmalloc.h>
  30. #include <linux/string.h>
  31. #include <linux/in.h>
  32. #include <linux/ip.h>
  33. #include <linux/tcp.h>
  34. #include <linux/sctp.h>
  35. #include <linux/ipv6.h>
  36. #include <linux/slab.h>
  37. #include <net/checksum.h>
  38. #include <net/ip6_checksum.h>
  39. #include <linux/ethtool.h>
  40. #include <linux/if.h>
  41. #include <linux/if_vlan.h>
  42. #include <linux/prefetch.h>
  43. #include "ixgbevf.h"
  44. const char ixgbevf_driver_name[] = "ixgbevf";
  45. static const char ixgbevf_driver_string[] =
  46. "Intel(R) 10 Gigabit PCI Express Virtual Function Network Driver";
  47. #define DRV_VERSION "2.6.0-k"
  48. const char ixgbevf_driver_version[] = DRV_VERSION;
  49. static char ixgbevf_copyright[] =
  50. "Copyright (c) 2009 - 2012 Intel Corporation.";
  51. static const struct ixgbevf_info *ixgbevf_info_tbl[] = {
  52. [board_82599_vf] = &ixgbevf_82599_vf_info,
  53. [board_X540_vf] = &ixgbevf_X540_vf_info,
  54. };
  55. /* ixgbevf_pci_tbl - PCI Device ID Table
  56. *
  57. * Wildcard entries (PCI_ANY_ID) should come last
  58. * Last entry must be all 0s
  59. *
  60. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  61. * Class, Class Mask, private data (not used) }
  62. */
  63. static struct pci_device_id ixgbevf_pci_tbl[] = {
  64. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF),
  65. board_82599_vf},
  66. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF),
  67. board_X540_vf},
  68. /* required last entry */
  69. {0, }
  70. };
  71. MODULE_DEVICE_TABLE(pci, ixgbevf_pci_tbl);
  72. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  73. MODULE_DESCRIPTION("Intel(R) 82599 Virtual Function Driver");
  74. MODULE_LICENSE("GPL");
  75. MODULE_VERSION(DRV_VERSION);
  76. #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
  77. static int debug = -1;
  78. module_param(debug, int, 0);
  79. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  80. /* forward decls */
  81. static void ixgbevf_set_itr(struct ixgbevf_q_vector *q_vector);
  82. static inline void ixgbevf_release_rx_desc(struct ixgbe_hw *hw,
  83. struct ixgbevf_ring *rx_ring,
  84. u32 val)
  85. {
  86. /*
  87. * Force memory writes to complete before letting h/w
  88. * know there are new descriptors to fetch. (Only
  89. * applicable for weak-ordered memory model archs,
  90. * such as IA-64).
  91. */
  92. wmb();
  93. IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rx_ring->reg_idx), val);
  94. }
  95. /**
  96. * ixgbevf_set_ivar - set IVAR registers - maps interrupt causes to vectors
  97. * @adapter: pointer to adapter struct
  98. * @direction: 0 for Rx, 1 for Tx, -1 for other causes
  99. * @queue: queue to map the corresponding interrupt to
  100. * @msix_vector: the vector to map to the corresponding queue
  101. *
  102. */
  103. static void ixgbevf_set_ivar(struct ixgbevf_adapter *adapter, s8 direction,
  104. u8 queue, u8 msix_vector)
  105. {
  106. u32 ivar, index;
  107. struct ixgbe_hw *hw = &adapter->hw;
  108. if (direction == -1) {
  109. /* other causes */
  110. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  111. ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
  112. ivar &= ~0xFF;
  113. ivar |= msix_vector;
  114. IXGBE_WRITE_REG(hw, IXGBE_VTIVAR_MISC, ivar);
  115. } else {
  116. /* tx or rx causes */
  117. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  118. index = ((16 * (queue & 1)) + (8 * direction));
  119. ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR(queue >> 1));
  120. ivar &= ~(0xFF << index);
  121. ivar |= (msix_vector << index);
  122. IXGBE_WRITE_REG(hw, IXGBE_VTIVAR(queue >> 1), ivar);
  123. }
  124. }
  125. static void ixgbevf_unmap_and_free_tx_resource(struct ixgbevf_ring *tx_ring,
  126. struct ixgbevf_tx_buffer
  127. *tx_buffer_info)
  128. {
  129. if (tx_buffer_info->dma) {
  130. if (tx_buffer_info->mapped_as_page)
  131. dma_unmap_page(tx_ring->dev,
  132. tx_buffer_info->dma,
  133. tx_buffer_info->length,
  134. DMA_TO_DEVICE);
  135. else
  136. dma_unmap_single(tx_ring->dev,
  137. tx_buffer_info->dma,
  138. tx_buffer_info->length,
  139. DMA_TO_DEVICE);
  140. tx_buffer_info->dma = 0;
  141. }
  142. if (tx_buffer_info->skb) {
  143. dev_kfree_skb_any(tx_buffer_info->skb);
  144. tx_buffer_info->skb = NULL;
  145. }
  146. tx_buffer_info->time_stamp = 0;
  147. /* tx_buffer_info must be completely set up in the transmit path */
  148. }
  149. #define IXGBE_MAX_TXD_PWR 14
  150. #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
  151. /* Tx Descriptors needed, worst case */
  152. #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IXGBE_MAX_DATA_PER_TXD)
  153. #define DESC_NEEDED (MAX_SKB_FRAGS + 4)
  154. static void ixgbevf_tx_timeout(struct net_device *netdev);
  155. /**
  156. * ixgbevf_clean_tx_irq - Reclaim resources after transmit completes
  157. * @q_vector: board private structure
  158. * @tx_ring: tx ring to clean
  159. **/
  160. static bool ixgbevf_clean_tx_irq(struct ixgbevf_q_vector *q_vector,
  161. struct ixgbevf_ring *tx_ring)
  162. {
  163. struct ixgbevf_adapter *adapter = q_vector->adapter;
  164. union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
  165. struct ixgbevf_tx_buffer *tx_buffer_info;
  166. unsigned int i, eop, count = 0;
  167. unsigned int total_bytes = 0, total_packets = 0;
  168. if (test_bit(__IXGBEVF_DOWN, &adapter->state))
  169. return true;
  170. i = tx_ring->next_to_clean;
  171. eop = tx_ring->tx_buffer_info[i].next_to_watch;
  172. eop_desc = IXGBEVF_TX_DESC(tx_ring, eop);
  173. while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
  174. (count < tx_ring->count)) {
  175. bool cleaned = false;
  176. rmb(); /* read buffer_info after eop_desc */
  177. /* eop could change between read and DD-check */
  178. if (unlikely(eop != tx_ring->tx_buffer_info[i].next_to_watch))
  179. goto cont_loop;
  180. for ( ; !cleaned; count++) {
  181. struct sk_buff *skb;
  182. tx_desc = IXGBEVF_TX_DESC(tx_ring, i);
  183. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  184. cleaned = (i == eop);
  185. skb = tx_buffer_info->skb;
  186. if (cleaned && skb) {
  187. unsigned int segs, bytecount;
  188. /* gso_segs is currently only valid for tcp */
  189. segs = skb_shinfo(skb)->gso_segs ?: 1;
  190. /* multiply data chunks by size of headers */
  191. bytecount = ((segs - 1) * skb_headlen(skb)) +
  192. skb->len;
  193. total_packets += segs;
  194. total_bytes += bytecount;
  195. }
  196. ixgbevf_unmap_and_free_tx_resource(tx_ring,
  197. tx_buffer_info);
  198. tx_desc->wb.status = 0;
  199. i++;
  200. if (i == tx_ring->count)
  201. i = 0;
  202. }
  203. cont_loop:
  204. eop = tx_ring->tx_buffer_info[i].next_to_watch;
  205. eop_desc = IXGBEVF_TX_DESC(tx_ring, eop);
  206. }
  207. tx_ring->next_to_clean = i;
  208. #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
  209. if (unlikely(count && netif_carrier_ok(tx_ring->netdev) &&
  210. (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
  211. /* Make sure that anybody stopping the queue after this
  212. * sees the new next_to_clean.
  213. */
  214. smp_mb();
  215. if (__netif_subqueue_stopped(tx_ring->netdev,
  216. tx_ring->queue_index) &&
  217. !test_bit(__IXGBEVF_DOWN, &adapter->state)) {
  218. netif_wake_subqueue(tx_ring->netdev,
  219. tx_ring->queue_index);
  220. ++adapter->restart_queue;
  221. }
  222. }
  223. u64_stats_update_begin(&tx_ring->syncp);
  224. tx_ring->total_bytes += total_bytes;
  225. tx_ring->total_packets += total_packets;
  226. u64_stats_update_end(&tx_ring->syncp);
  227. q_vector->tx.total_bytes += total_bytes;
  228. q_vector->tx.total_packets += total_packets;
  229. return count < tx_ring->count;
  230. }
  231. /**
  232. * ixgbevf_receive_skb - Send a completed packet up the stack
  233. * @q_vector: structure containing interrupt and ring information
  234. * @skb: packet to send up
  235. * @status: hardware indication of status of receive
  236. * @rx_desc: rx descriptor
  237. **/
  238. static void ixgbevf_receive_skb(struct ixgbevf_q_vector *q_vector,
  239. struct sk_buff *skb, u8 status,
  240. union ixgbe_adv_rx_desc *rx_desc)
  241. {
  242. struct ixgbevf_adapter *adapter = q_vector->adapter;
  243. bool is_vlan = (status & IXGBE_RXD_STAT_VP);
  244. u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
  245. if (is_vlan && test_bit(tag & VLAN_VID_MASK, adapter->active_vlans))
  246. __vlan_hwaccel_put_tag(skb, tag);
  247. napi_gro_receive(&q_vector->napi, skb);
  248. }
  249. /**
  250. * ixgbevf_rx_checksum - indicate in skb if hw indicated a good cksum
  251. * @adapter: address of board private structure
  252. * @status_err: hardware indication of status of receive
  253. * @skb: skb currently being received and modified
  254. **/
  255. static inline void ixgbevf_rx_checksum(struct ixgbevf_adapter *adapter,
  256. struct ixgbevf_ring *ring,
  257. u32 status_err, struct sk_buff *skb)
  258. {
  259. skb_checksum_none_assert(skb);
  260. /* Rx csum disabled */
  261. if (!(ring->netdev->features & NETIF_F_RXCSUM))
  262. return;
  263. /* if IP and error */
  264. if ((status_err & IXGBE_RXD_STAT_IPCS) &&
  265. (status_err & IXGBE_RXDADV_ERR_IPE)) {
  266. adapter->hw_csum_rx_error++;
  267. return;
  268. }
  269. if (!(status_err & IXGBE_RXD_STAT_L4CS))
  270. return;
  271. if (status_err & IXGBE_RXDADV_ERR_TCPE) {
  272. adapter->hw_csum_rx_error++;
  273. return;
  274. }
  275. /* It must be a TCP or UDP packet with a valid checksum */
  276. skb->ip_summed = CHECKSUM_UNNECESSARY;
  277. adapter->hw_csum_rx_good++;
  278. }
  279. /**
  280. * ixgbevf_alloc_rx_buffers - Replace used receive buffers; packet split
  281. * @adapter: address of board private structure
  282. **/
  283. static void ixgbevf_alloc_rx_buffers(struct ixgbevf_adapter *adapter,
  284. struct ixgbevf_ring *rx_ring,
  285. int cleaned_count)
  286. {
  287. struct pci_dev *pdev = adapter->pdev;
  288. union ixgbe_adv_rx_desc *rx_desc;
  289. struct ixgbevf_rx_buffer *bi;
  290. struct sk_buff *skb;
  291. unsigned int i = rx_ring->next_to_use;
  292. bi = &rx_ring->rx_buffer_info[i];
  293. while (cleaned_count--) {
  294. rx_desc = IXGBEVF_RX_DESC(rx_ring, i);
  295. skb = bi->skb;
  296. if (!skb) {
  297. skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
  298. rx_ring->rx_buf_len);
  299. if (!skb) {
  300. adapter->alloc_rx_buff_failed++;
  301. goto no_buffers;
  302. }
  303. bi->skb = skb;
  304. }
  305. if (!bi->dma) {
  306. bi->dma = dma_map_single(&pdev->dev, skb->data,
  307. rx_ring->rx_buf_len,
  308. DMA_FROM_DEVICE);
  309. }
  310. rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
  311. i++;
  312. if (i == rx_ring->count)
  313. i = 0;
  314. bi = &rx_ring->rx_buffer_info[i];
  315. }
  316. no_buffers:
  317. if (rx_ring->next_to_use != i) {
  318. rx_ring->next_to_use = i;
  319. ixgbevf_release_rx_desc(&adapter->hw, rx_ring, i);
  320. }
  321. }
  322. static inline void ixgbevf_irq_enable_queues(struct ixgbevf_adapter *adapter,
  323. u32 qmask)
  324. {
  325. struct ixgbe_hw *hw = &adapter->hw;
  326. IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, qmask);
  327. }
  328. static bool ixgbevf_clean_rx_irq(struct ixgbevf_q_vector *q_vector,
  329. struct ixgbevf_ring *rx_ring,
  330. int budget)
  331. {
  332. struct ixgbevf_adapter *adapter = q_vector->adapter;
  333. struct pci_dev *pdev = adapter->pdev;
  334. union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
  335. struct ixgbevf_rx_buffer *rx_buffer_info, *next_buffer;
  336. struct sk_buff *skb;
  337. unsigned int i;
  338. u32 len, staterr;
  339. int cleaned_count = 0;
  340. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  341. i = rx_ring->next_to_clean;
  342. rx_desc = IXGBEVF_RX_DESC(rx_ring, i);
  343. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  344. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  345. while (staterr & IXGBE_RXD_STAT_DD) {
  346. if (!budget)
  347. break;
  348. budget--;
  349. rmb(); /* read descriptor and rx_buffer_info after status DD */
  350. len = le16_to_cpu(rx_desc->wb.upper.length);
  351. skb = rx_buffer_info->skb;
  352. prefetch(skb->data - NET_IP_ALIGN);
  353. rx_buffer_info->skb = NULL;
  354. if (rx_buffer_info->dma) {
  355. dma_unmap_single(&pdev->dev, rx_buffer_info->dma,
  356. rx_ring->rx_buf_len,
  357. DMA_FROM_DEVICE);
  358. rx_buffer_info->dma = 0;
  359. skb_put(skb, len);
  360. }
  361. i++;
  362. if (i == rx_ring->count)
  363. i = 0;
  364. next_rxd = IXGBEVF_RX_DESC(rx_ring, i);
  365. prefetch(next_rxd);
  366. cleaned_count++;
  367. next_buffer = &rx_ring->rx_buffer_info[i];
  368. if (!(staterr & IXGBE_RXD_STAT_EOP)) {
  369. skb->next = next_buffer->skb;
  370. IXGBE_CB(skb->next)->prev = skb;
  371. adapter->non_eop_descs++;
  372. goto next_desc;
  373. }
  374. /* we should not be chaining buffers, if we did drop the skb */
  375. if (IXGBE_CB(skb)->prev) {
  376. do {
  377. struct sk_buff *this = skb;
  378. skb = IXGBE_CB(skb)->prev;
  379. dev_kfree_skb(this);
  380. } while (skb);
  381. goto next_desc;
  382. }
  383. /* ERR_MASK will only have valid bits if EOP set */
  384. if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) {
  385. dev_kfree_skb_irq(skb);
  386. goto next_desc;
  387. }
  388. ixgbevf_rx_checksum(adapter, rx_ring, staterr, skb);
  389. /* probably a little skewed due to removing CRC */
  390. total_rx_bytes += skb->len;
  391. total_rx_packets++;
  392. /*
  393. * Work around issue of some types of VM to VM loop back
  394. * packets not getting split correctly
  395. */
  396. if (staterr & IXGBE_RXD_STAT_LB) {
  397. u32 header_fixup_len = skb_headlen(skb);
  398. if (header_fixup_len < 14)
  399. skb_push(skb, header_fixup_len);
  400. }
  401. skb->protocol = eth_type_trans(skb, rx_ring->netdev);
  402. ixgbevf_receive_skb(q_vector, skb, staterr, rx_desc);
  403. next_desc:
  404. rx_desc->wb.upper.status_error = 0;
  405. /* return some buffers to hardware, one at a time is too slow */
  406. if (cleaned_count >= IXGBEVF_RX_BUFFER_WRITE) {
  407. ixgbevf_alloc_rx_buffers(adapter, rx_ring,
  408. cleaned_count);
  409. cleaned_count = 0;
  410. }
  411. /* use prefetched values */
  412. rx_desc = next_rxd;
  413. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  414. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  415. }
  416. rx_ring->next_to_clean = i;
  417. cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
  418. if (cleaned_count)
  419. ixgbevf_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
  420. u64_stats_update_begin(&rx_ring->syncp);
  421. rx_ring->total_packets += total_rx_packets;
  422. rx_ring->total_bytes += total_rx_bytes;
  423. u64_stats_update_end(&rx_ring->syncp);
  424. q_vector->rx.total_packets += total_rx_packets;
  425. q_vector->rx.total_bytes += total_rx_bytes;
  426. return !!budget;
  427. }
  428. /**
  429. * ixgbevf_poll - NAPI polling calback
  430. * @napi: napi struct with our devices info in it
  431. * @budget: amount of work driver is allowed to do this pass, in packets
  432. *
  433. * This function will clean more than one or more rings associated with a
  434. * q_vector.
  435. **/
  436. static int ixgbevf_poll(struct napi_struct *napi, int budget)
  437. {
  438. struct ixgbevf_q_vector *q_vector =
  439. container_of(napi, struct ixgbevf_q_vector, napi);
  440. struct ixgbevf_adapter *adapter = q_vector->adapter;
  441. struct ixgbevf_ring *ring;
  442. int per_ring_budget;
  443. bool clean_complete = true;
  444. ixgbevf_for_each_ring(ring, q_vector->tx)
  445. clean_complete &= ixgbevf_clean_tx_irq(q_vector, ring);
  446. /* attempt to distribute budget to each queue fairly, but don't allow
  447. * the budget to go below 1 because we'll exit polling */
  448. if (q_vector->rx.count > 1)
  449. per_ring_budget = max(budget/q_vector->rx.count, 1);
  450. else
  451. per_ring_budget = budget;
  452. ixgbevf_for_each_ring(ring, q_vector->rx)
  453. clean_complete &= ixgbevf_clean_rx_irq(q_vector, ring,
  454. per_ring_budget);
  455. /* If all work not completed, return budget and keep polling */
  456. if (!clean_complete)
  457. return budget;
  458. /* all work done, exit the polling mode */
  459. napi_complete(napi);
  460. if (adapter->rx_itr_setting & 1)
  461. ixgbevf_set_itr(q_vector);
  462. if (!test_bit(__IXGBEVF_DOWN, &adapter->state))
  463. ixgbevf_irq_enable_queues(adapter,
  464. 1 << q_vector->v_idx);
  465. return 0;
  466. }
  467. /**
  468. * ixgbevf_write_eitr - write VTEITR register in hardware specific way
  469. * @q_vector: structure containing interrupt and ring information
  470. */
  471. static void ixgbevf_write_eitr(struct ixgbevf_q_vector *q_vector)
  472. {
  473. struct ixgbevf_adapter *adapter = q_vector->adapter;
  474. struct ixgbe_hw *hw = &adapter->hw;
  475. int v_idx = q_vector->v_idx;
  476. u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
  477. /*
  478. * set the WDIS bit to not clear the timer bits and cause an
  479. * immediate assertion of the interrupt
  480. */
  481. itr_reg |= IXGBE_EITR_CNT_WDIS;
  482. IXGBE_WRITE_REG(hw, IXGBE_VTEITR(v_idx), itr_reg);
  483. }
  484. /**
  485. * ixgbevf_configure_msix - Configure MSI-X hardware
  486. * @adapter: board private structure
  487. *
  488. * ixgbevf_configure_msix sets up the hardware to properly generate MSI-X
  489. * interrupts.
  490. **/
  491. static void ixgbevf_configure_msix(struct ixgbevf_adapter *adapter)
  492. {
  493. struct ixgbevf_q_vector *q_vector;
  494. int q_vectors, v_idx;
  495. q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  496. adapter->eims_enable_mask = 0;
  497. /*
  498. * Populate the IVAR table and set the ITR values to the
  499. * corresponding register.
  500. */
  501. for (v_idx = 0; v_idx < q_vectors; v_idx++) {
  502. struct ixgbevf_ring *ring;
  503. q_vector = adapter->q_vector[v_idx];
  504. ixgbevf_for_each_ring(ring, q_vector->rx)
  505. ixgbevf_set_ivar(adapter, 0, ring->reg_idx, v_idx);
  506. ixgbevf_for_each_ring(ring, q_vector->tx)
  507. ixgbevf_set_ivar(adapter, 1, ring->reg_idx, v_idx);
  508. if (q_vector->tx.ring && !q_vector->rx.ring) {
  509. /* tx only vector */
  510. if (adapter->tx_itr_setting == 1)
  511. q_vector->itr = IXGBE_10K_ITR;
  512. else
  513. q_vector->itr = adapter->tx_itr_setting;
  514. } else {
  515. /* rx or rx/tx vector */
  516. if (adapter->rx_itr_setting == 1)
  517. q_vector->itr = IXGBE_20K_ITR;
  518. else
  519. q_vector->itr = adapter->rx_itr_setting;
  520. }
  521. /* add q_vector eims value to global eims_enable_mask */
  522. adapter->eims_enable_mask |= 1 << v_idx;
  523. ixgbevf_write_eitr(q_vector);
  524. }
  525. ixgbevf_set_ivar(adapter, -1, 1, v_idx);
  526. /* setup eims_other and add value to global eims_enable_mask */
  527. adapter->eims_other = 1 << v_idx;
  528. adapter->eims_enable_mask |= adapter->eims_other;
  529. }
  530. enum latency_range {
  531. lowest_latency = 0,
  532. low_latency = 1,
  533. bulk_latency = 2,
  534. latency_invalid = 255
  535. };
  536. /**
  537. * ixgbevf_update_itr - update the dynamic ITR value based on statistics
  538. * @q_vector: structure containing interrupt and ring information
  539. * @ring_container: structure containing ring performance data
  540. *
  541. * Stores a new ITR value based on packets and byte
  542. * counts during the last interrupt. The advantage of per interrupt
  543. * computation is faster updates and more accurate ITR for the current
  544. * traffic pattern. Constants in this function were computed
  545. * based on theoretical maximum wire speed and thresholds were set based
  546. * on testing data as well as attempting to minimize response time
  547. * while increasing bulk throughput.
  548. **/
  549. static void ixgbevf_update_itr(struct ixgbevf_q_vector *q_vector,
  550. struct ixgbevf_ring_container *ring_container)
  551. {
  552. int bytes = ring_container->total_bytes;
  553. int packets = ring_container->total_packets;
  554. u32 timepassed_us;
  555. u64 bytes_perint;
  556. u8 itr_setting = ring_container->itr;
  557. if (packets == 0)
  558. return;
  559. /* simple throttlerate management
  560. * 0-20MB/s lowest (100000 ints/s)
  561. * 20-100MB/s low (20000 ints/s)
  562. * 100-1249MB/s bulk (8000 ints/s)
  563. */
  564. /* what was last interrupt timeslice? */
  565. timepassed_us = q_vector->itr >> 2;
  566. bytes_perint = bytes / timepassed_us; /* bytes/usec */
  567. switch (itr_setting) {
  568. case lowest_latency:
  569. if (bytes_perint > 10)
  570. itr_setting = low_latency;
  571. break;
  572. case low_latency:
  573. if (bytes_perint > 20)
  574. itr_setting = bulk_latency;
  575. else if (bytes_perint <= 10)
  576. itr_setting = lowest_latency;
  577. break;
  578. case bulk_latency:
  579. if (bytes_perint <= 20)
  580. itr_setting = low_latency;
  581. break;
  582. }
  583. /* clear work counters since we have the values we need */
  584. ring_container->total_bytes = 0;
  585. ring_container->total_packets = 0;
  586. /* write updated itr to ring container */
  587. ring_container->itr = itr_setting;
  588. }
  589. static void ixgbevf_set_itr(struct ixgbevf_q_vector *q_vector)
  590. {
  591. u32 new_itr = q_vector->itr;
  592. u8 current_itr;
  593. ixgbevf_update_itr(q_vector, &q_vector->tx);
  594. ixgbevf_update_itr(q_vector, &q_vector->rx);
  595. current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
  596. switch (current_itr) {
  597. /* counts and packets in update_itr are dependent on these numbers */
  598. case lowest_latency:
  599. new_itr = IXGBE_100K_ITR;
  600. break;
  601. case low_latency:
  602. new_itr = IXGBE_20K_ITR;
  603. break;
  604. case bulk_latency:
  605. default:
  606. new_itr = IXGBE_8K_ITR;
  607. break;
  608. }
  609. if (new_itr != q_vector->itr) {
  610. /* do an exponential smoothing */
  611. new_itr = (10 * new_itr * q_vector->itr) /
  612. ((9 * new_itr) + q_vector->itr);
  613. /* save the algorithm value here */
  614. q_vector->itr = new_itr;
  615. ixgbevf_write_eitr(q_vector);
  616. }
  617. }
  618. static irqreturn_t ixgbevf_msix_other(int irq, void *data)
  619. {
  620. struct ixgbevf_adapter *adapter = data;
  621. struct ixgbe_hw *hw = &adapter->hw;
  622. hw->mac.get_link_status = 1;
  623. if (!test_bit(__IXGBEVF_DOWN, &adapter->state))
  624. mod_timer(&adapter->watchdog_timer, jiffies);
  625. IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, adapter->eims_other);
  626. return IRQ_HANDLED;
  627. }
  628. /**
  629. * ixgbevf_msix_clean_rings - single unshared vector rx clean (all queues)
  630. * @irq: unused
  631. * @data: pointer to our q_vector struct for this interrupt vector
  632. **/
  633. static irqreturn_t ixgbevf_msix_clean_rings(int irq, void *data)
  634. {
  635. struct ixgbevf_q_vector *q_vector = data;
  636. /* EIAM disabled interrupts (on this vector) for us */
  637. if (q_vector->rx.ring || q_vector->tx.ring)
  638. napi_schedule(&q_vector->napi);
  639. return IRQ_HANDLED;
  640. }
  641. static inline void map_vector_to_rxq(struct ixgbevf_adapter *a, int v_idx,
  642. int r_idx)
  643. {
  644. struct ixgbevf_q_vector *q_vector = a->q_vector[v_idx];
  645. a->rx_ring[r_idx].next = q_vector->rx.ring;
  646. q_vector->rx.ring = &a->rx_ring[r_idx];
  647. q_vector->rx.count++;
  648. }
  649. static inline void map_vector_to_txq(struct ixgbevf_adapter *a, int v_idx,
  650. int t_idx)
  651. {
  652. struct ixgbevf_q_vector *q_vector = a->q_vector[v_idx];
  653. a->tx_ring[t_idx].next = q_vector->tx.ring;
  654. q_vector->tx.ring = &a->tx_ring[t_idx];
  655. q_vector->tx.count++;
  656. }
  657. /**
  658. * ixgbevf_map_rings_to_vectors - Maps descriptor rings to vectors
  659. * @adapter: board private structure to initialize
  660. *
  661. * This function maps descriptor rings to the queue-specific vectors
  662. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  663. * one vector per ring/queue, but on a constrained vector budget, we
  664. * group the rings as "efficiently" as possible. You would add new
  665. * mapping configurations in here.
  666. **/
  667. static int ixgbevf_map_rings_to_vectors(struct ixgbevf_adapter *adapter)
  668. {
  669. int q_vectors;
  670. int v_start = 0;
  671. int rxr_idx = 0, txr_idx = 0;
  672. int rxr_remaining = adapter->num_rx_queues;
  673. int txr_remaining = adapter->num_tx_queues;
  674. int i, j;
  675. int rqpv, tqpv;
  676. int err = 0;
  677. q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  678. /*
  679. * The ideal configuration...
  680. * We have enough vectors to map one per queue.
  681. */
  682. if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
  683. for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
  684. map_vector_to_rxq(adapter, v_start, rxr_idx);
  685. for (; txr_idx < txr_remaining; v_start++, txr_idx++)
  686. map_vector_to_txq(adapter, v_start, txr_idx);
  687. goto out;
  688. }
  689. /*
  690. * If we don't have enough vectors for a 1-to-1
  691. * mapping, we'll have to group them so there are
  692. * multiple queues per vector.
  693. */
  694. /* Re-adjusting *qpv takes care of the remainder. */
  695. for (i = v_start; i < q_vectors; i++) {
  696. rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
  697. for (j = 0; j < rqpv; j++) {
  698. map_vector_to_rxq(adapter, i, rxr_idx);
  699. rxr_idx++;
  700. rxr_remaining--;
  701. }
  702. }
  703. for (i = v_start; i < q_vectors; i++) {
  704. tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
  705. for (j = 0; j < tqpv; j++) {
  706. map_vector_to_txq(adapter, i, txr_idx);
  707. txr_idx++;
  708. txr_remaining--;
  709. }
  710. }
  711. out:
  712. return err;
  713. }
  714. /**
  715. * ixgbevf_request_msix_irqs - Initialize MSI-X interrupts
  716. * @adapter: board private structure
  717. *
  718. * ixgbevf_request_msix_irqs allocates MSI-X vectors and requests
  719. * interrupts from the kernel.
  720. **/
  721. static int ixgbevf_request_msix_irqs(struct ixgbevf_adapter *adapter)
  722. {
  723. struct net_device *netdev = adapter->netdev;
  724. int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  725. int vector, err;
  726. int ri = 0, ti = 0;
  727. for (vector = 0; vector < q_vectors; vector++) {
  728. struct ixgbevf_q_vector *q_vector = adapter->q_vector[vector];
  729. struct msix_entry *entry = &adapter->msix_entries[vector];
  730. if (q_vector->tx.ring && q_vector->rx.ring) {
  731. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  732. "%s-%s-%d", netdev->name, "TxRx", ri++);
  733. ti++;
  734. } else if (q_vector->rx.ring) {
  735. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  736. "%s-%s-%d", netdev->name, "rx", ri++);
  737. } else if (q_vector->tx.ring) {
  738. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  739. "%s-%s-%d", netdev->name, "tx", ti++);
  740. } else {
  741. /* skip this unused q_vector */
  742. continue;
  743. }
  744. err = request_irq(entry->vector, &ixgbevf_msix_clean_rings, 0,
  745. q_vector->name, q_vector);
  746. if (err) {
  747. hw_dbg(&adapter->hw,
  748. "request_irq failed for MSIX interrupt "
  749. "Error: %d\n", err);
  750. goto free_queue_irqs;
  751. }
  752. }
  753. err = request_irq(adapter->msix_entries[vector].vector,
  754. &ixgbevf_msix_other, 0, netdev->name, adapter);
  755. if (err) {
  756. hw_dbg(&adapter->hw,
  757. "request_irq for msix_other failed: %d\n", err);
  758. goto free_queue_irqs;
  759. }
  760. return 0;
  761. free_queue_irqs:
  762. while (vector) {
  763. vector--;
  764. free_irq(adapter->msix_entries[vector].vector,
  765. adapter->q_vector[vector]);
  766. }
  767. pci_disable_msix(adapter->pdev);
  768. kfree(adapter->msix_entries);
  769. adapter->msix_entries = NULL;
  770. return err;
  771. }
  772. static inline void ixgbevf_reset_q_vectors(struct ixgbevf_adapter *adapter)
  773. {
  774. int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  775. for (i = 0; i < q_vectors; i++) {
  776. struct ixgbevf_q_vector *q_vector = adapter->q_vector[i];
  777. q_vector->rx.ring = NULL;
  778. q_vector->tx.ring = NULL;
  779. q_vector->rx.count = 0;
  780. q_vector->tx.count = 0;
  781. }
  782. }
  783. /**
  784. * ixgbevf_request_irq - initialize interrupts
  785. * @adapter: board private structure
  786. *
  787. * Attempts to configure interrupts using the best available
  788. * capabilities of the hardware and kernel.
  789. **/
  790. static int ixgbevf_request_irq(struct ixgbevf_adapter *adapter)
  791. {
  792. int err = 0;
  793. err = ixgbevf_request_msix_irqs(adapter);
  794. if (err)
  795. hw_dbg(&adapter->hw,
  796. "request_irq failed, Error %d\n", err);
  797. return err;
  798. }
  799. static void ixgbevf_free_irq(struct ixgbevf_adapter *adapter)
  800. {
  801. int i, q_vectors;
  802. q_vectors = adapter->num_msix_vectors;
  803. i = q_vectors - 1;
  804. free_irq(adapter->msix_entries[i].vector, adapter);
  805. i--;
  806. for (; i >= 0; i--) {
  807. /* free only the irqs that were actually requested */
  808. if (!adapter->q_vector[i]->rx.ring &&
  809. !adapter->q_vector[i]->tx.ring)
  810. continue;
  811. free_irq(adapter->msix_entries[i].vector,
  812. adapter->q_vector[i]);
  813. }
  814. ixgbevf_reset_q_vectors(adapter);
  815. }
  816. /**
  817. * ixgbevf_irq_disable - Mask off interrupt generation on the NIC
  818. * @adapter: board private structure
  819. **/
  820. static inline void ixgbevf_irq_disable(struct ixgbevf_adapter *adapter)
  821. {
  822. struct ixgbe_hw *hw = &adapter->hw;
  823. int i;
  824. IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, 0);
  825. IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, ~0);
  826. IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, 0);
  827. IXGBE_WRITE_FLUSH(hw);
  828. for (i = 0; i < adapter->num_msix_vectors; i++)
  829. synchronize_irq(adapter->msix_entries[i].vector);
  830. }
  831. /**
  832. * ixgbevf_irq_enable - Enable default interrupt generation settings
  833. * @adapter: board private structure
  834. **/
  835. static inline void ixgbevf_irq_enable(struct ixgbevf_adapter *adapter)
  836. {
  837. struct ixgbe_hw *hw = &adapter->hw;
  838. IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, adapter->eims_enable_mask);
  839. IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, adapter->eims_enable_mask);
  840. IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, adapter->eims_enable_mask);
  841. }
  842. /**
  843. * ixgbevf_configure_tx - Configure 82599 VF Transmit Unit after Reset
  844. * @adapter: board private structure
  845. *
  846. * Configure the Tx unit of the MAC after a reset.
  847. **/
  848. static void ixgbevf_configure_tx(struct ixgbevf_adapter *adapter)
  849. {
  850. u64 tdba;
  851. struct ixgbe_hw *hw = &adapter->hw;
  852. u32 i, j, tdlen, txctrl;
  853. /* Setup the HW Tx Head and Tail descriptor pointers */
  854. for (i = 0; i < adapter->num_tx_queues; i++) {
  855. struct ixgbevf_ring *ring = &adapter->tx_ring[i];
  856. j = ring->reg_idx;
  857. tdba = ring->dma;
  858. tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
  859. IXGBE_WRITE_REG(hw, IXGBE_VFTDBAL(j),
  860. (tdba & DMA_BIT_MASK(32)));
  861. IXGBE_WRITE_REG(hw, IXGBE_VFTDBAH(j), (tdba >> 32));
  862. IXGBE_WRITE_REG(hw, IXGBE_VFTDLEN(j), tdlen);
  863. IXGBE_WRITE_REG(hw, IXGBE_VFTDH(j), 0);
  864. IXGBE_WRITE_REG(hw, IXGBE_VFTDT(j), 0);
  865. adapter->tx_ring[i].head = IXGBE_VFTDH(j);
  866. adapter->tx_ring[i].tail = IXGBE_VFTDT(j);
  867. /* Disable Tx Head Writeback RO bit, since this hoses
  868. * bookkeeping if things aren't delivered in order.
  869. */
  870. txctrl = IXGBE_READ_REG(hw, IXGBE_VFDCA_TXCTRL(j));
  871. txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
  872. IXGBE_WRITE_REG(hw, IXGBE_VFDCA_TXCTRL(j), txctrl);
  873. }
  874. }
  875. #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
  876. static void ixgbevf_configure_srrctl(struct ixgbevf_adapter *adapter, int index)
  877. {
  878. struct ixgbevf_ring *rx_ring;
  879. struct ixgbe_hw *hw = &adapter->hw;
  880. u32 srrctl;
  881. rx_ring = &adapter->rx_ring[index];
  882. srrctl = IXGBE_SRRCTL_DROP_EN;
  883. srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
  884. srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
  885. IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  886. IXGBE_WRITE_REG(hw, IXGBE_VFSRRCTL(index), srrctl);
  887. }
  888. static void ixgbevf_set_rx_buffer_len(struct ixgbevf_adapter *adapter)
  889. {
  890. struct ixgbe_hw *hw = &adapter->hw;
  891. struct net_device *netdev = adapter->netdev;
  892. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  893. int i;
  894. u16 rx_buf_len;
  895. /* notify the PF of our intent to use this size of frame */
  896. ixgbevf_rlpml_set_vf(hw, max_frame);
  897. /* PF will allow an extra 4 bytes past for vlan tagged frames */
  898. max_frame += VLAN_HLEN;
  899. /*
  900. * Make best use of allocation by using all but 1K of a
  901. * power of 2 allocation that will be used for skb->head.
  902. */
  903. if ((hw->mac.type == ixgbe_mac_X540_vf) &&
  904. (max_frame <= MAXIMUM_ETHERNET_VLAN_SIZE))
  905. rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
  906. else if (max_frame <= IXGBEVF_RXBUFFER_3K)
  907. rx_buf_len = IXGBEVF_RXBUFFER_3K;
  908. else if (max_frame <= IXGBEVF_RXBUFFER_7K)
  909. rx_buf_len = IXGBEVF_RXBUFFER_7K;
  910. else if (max_frame <= IXGBEVF_RXBUFFER_15K)
  911. rx_buf_len = IXGBEVF_RXBUFFER_15K;
  912. else
  913. rx_buf_len = IXGBEVF_MAX_RXBUFFER;
  914. for (i = 0; i < adapter->num_rx_queues; i++)
  915. adapter->rx_ring[i].rx_buf_len = rx_buf_len;
  916. }
  917. /**
  918. * ixgbevf_configure_rx - Configure 82599 VF Receive Unit after Reset
  919. * @adapter: board private structure
  920. *
  921. * Configure the Rx unit of the MAC after a reset.
  922. **/
  923. static void ixgbevf_configure_rx(struct ixgbevf_adapter *adapter)
  924. {
  925. u64 rdba;
  926. struct ixgbe_hw *hw = &adapter->hw;
  927. int i, j;
  928. u32 rdlen;
  929. /* PSRTYPE must be initialized in 82599 */
  930. IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, 0);
  931. /* set_rx_buffer_len must be called before ring initialization */
  932. ixgbevf_set_rx_buffer_len(adapter);
  933. rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
  934. /* Setup the HW Rx Head and Tail Descriptor Pointers and
  935. * the Base and Length of the Rx Descriptor Ring */
  936. for (i = 0; i < adapter->num_rx_queues; i++) {
  937. rdba = adapter->rx_ring[i].dma;
  938. j = adapter->rx_ring[i].reg_idx;
  939. IXGBE_WRITE_REG(hw, IXGBE_VFRDBAL(j),
  940. (rdba & DMA_BIT_MASK(32)));
  941. IXGBE_WRITE_REG(hw, IXGBE_VFRDBAH(j), (rdba >> 32));
  942. IXGBE_WRITE_REG(hw, IXGBE_VFRDLEN(j), rdlen);
  943. IXGBE_WRITE_REG(hw, IXGBE_VFRDH(j), 0);
  944. IXGBE_WRITE_REG(hw, IXGBE_VFRDT(j), 0);
  945. adapter->rx_ring[i].head = IXGBE_VFRDH(j);
  946. adapter->rx_ring[i].tail = IXGBE_VFRDT(j);
  947. ixgbevf_configure_srrctl(adapter, j);
  948. }
  949. }
  950. static int ixgbevf_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  951. {
  952. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  953. struct ixgbe_hw *hw = &adapter->hw;
  954. int err;
  955. if (!hw->mac.ops.set_vfta)
  956. return -EOPNOTSUPP;
  957. spin_lock(&adapter->mbx_lock);
  958. /* add VID to filter table */
  959. err = hw->mac.ops.set_vfta(hw, vid, 0, true);
  960. spin_unlock(&adapter->mbx_lock);
  961. /* translate error return types so error makes sense */
  962. if (err == IXGBE_ERR_MBX)
  963. return -EIO;
  964. if (err == IXGBE_ERR_INVALID_ARGUMENT)
  965. return -EACCES;
  966. set_bit(vid, adapter->active_vlans);
  967. return err;
  968. }
  969. static int ixgbevf_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  970. {
  971. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  972. struct ixgbe_hw *hw = &adapter->hw;
  973. int err = -EOPNOTSUPP;
  974. spin_lock(&adapter->mbx_lock);
  975. /* remove VID from filter table */
  976. if (hw->mac.ops.set_vfta)
  977. err = hw->mac.ops.set_vfta(hw, vid, 0, false);
  978. spin_unlock(&adapter->mbx_lock);
  979. clear_bit(vid, adapter->active_vlans);
  980. return err;
  981. }
  982. static void ixgbevf_restore_vlan(struct ixgbevf_adapter *adapter)
  983. {
  984. u16 vid;
  985. for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
  986. ixgbevf_vlan_rx_add_vid(adapter->netdev, vid);
  987. }
  988. static int ixgbevf_write_uc_addr_list(struct net_device *netdev)
  989. {
  990. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  991. struct ixgbe_hw *hw = &adapter->hw;
  992. int count = 0;
  993. if ((netdev_uc_count(netdev)) > 10) {
  994. pr_err("Too many unicast filters - No Space\n");
  995. return -ENOSPC;
  996. }
  997. if (!netdev_uc_empty(netdev)) {
  998. struct netdev_hw_addr *ha;
  999. netdev_for_each_uc_addr(ha, netdev) {
  1000. hw->mac.ops.set_uc_addr(hw, ++count, ha->addr);
  1001. udelay(200);
  1002. }
  1003. } else {
  1004. /*
  1005. * If the list is empty then send message to PF driver to
  1006. * clear all macvlans on this VF.
  1007. */
  1008. hw->mac.ops.set_uc_addr(hw, 0, NULL);
  1009. }
  1010. return count;
  1011. }
  1012. /**
  1013. * ixgbevf_set_rx_mode - Multicast set
  1014. * @netdev: network interface device structure
  1015. *
  1016. * The set_rx_method entry point is called whenever the multicast address
  1017. * list or the network interface flags are updated. This routine is
  1018. * responsible for configuring the hardware for proper multicast mode.
  1019. **/
  1020. static void ixgbevf_set_rx_mode(struct net_device *netdev)
  1021. {
  1022. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  1023. struct ixgbe_hw *hw = &adapter->hw;
  1024. spin_lock(&adapter->mbx_lock);
  1025. /* reprogram multicast list */
  1026. if (hw->mac.ops.update_mc_addr_list)
  1027. hw->mac.ops.update_mc_addr_list(hw, netdev);
  1028. ixgbevf_write_uc_addr_list(netdev);
  1029. spin_unlock(&adapter->mbx_lock);
  1030. }
  1031. static void ixgbevf_napi_enable_all(struct ixgbevf_adapter *adapter)
  1032. {
  1033. int q_idx;
  1034. struct ixgbevf_q_vector *q_vector;
  1035. int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1036. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  1037. q_vector = adapter->q_vector[q_idx];
  1038. napi_enable(&q_vector->napi);
  1039. }
  1040. }
  1041. static void ixgbevf_napi_disable_all(struct ixgbevf_adapter *adapter)
  1042. {
  1043. int q_idx;
  1044. struct ixgbevf_q_vector *q_vector;
  1045. int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1046. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  1047. q_vector = adapter->q_vector[q_idx];
  1048. napi_disable(&q_vector->napi);
  1049. }
  1050. }
  1051. static void ixgbevf_configure(struct ixgbevf_adapter *adapter)
  1052. {
  1053. struct net_device *netdev = adapter->netdev;
  1054. int i;
  1055. ixgbevf_set_rx_mode(netdev);
  1056. ixgbevf_restore_vlan(adapter);
  1057. ixgbevf_configure_tx(adapter);
  1058. ixgbevf_configure_rx(adapter);
  1059. for (i = 0; i < adapter->num_rx_queues; i++) {
  1060. struct ixgbevf_ring *ring = &adapter->rx_ring[i];
  1061. ixgbevf_alloc_rx_buffers(adapter, ring,
  1062. IXGBE_DESC_UNUSED(ring));
  1063. }
  1064. }
  1065. #define IXGBE_MAX_RX_DESC_POLL 10
  1066. static inline void ixgbevf_rx_desc_queue_enable(struct ixgbevf_adapter *adapter,
  1067. int rxr)
  1068. {
  1069. struct ixgbe_hw *hw = &adapter->hw;
  1070. int j = adapter->rx_ring[rxr].reg_idx;
  1071. int k;
  1072. for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
  1073. if (IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
  1074. break;
  1075. else
  1076. msleep(1);
  1077. }
  1078. if (k >= IXGBE_MAX_RX_DESC_POLL) {
  1079. hw_dbg(hw, "RXDCTL.ENABLE on Rx queue %d "
  1080. "not set within the polling period\n", rxr);
  1081. }
  1082. ixgbevf_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
  1083. (adapter->rx_ring[rxr].count - 1));
  1084. }
  1085. static void ixgbevf_save_reset_stats(struct ixgbevf_adapter *adapter)
  1086. {
  1087. /* Only save pre-reset stats if there are some */
  1088. if (adapter->stats.vfgprc || adapter->stats.vfgptc) {
  1089. adapter->stats.saved_reset_vfgprc += adapter->stats.vfgprc -
  1090. adapter->stats.base_vfgprc;
  1091. adapter->stats.saved_reset_vfgptc += adapter->stats.vfgptc -
  1092. adapter->stats.base_vfgptc;
  1093. adapter->stats.saved_reset_vfgorc += adapter->stats.vfgorc -
  1094. adapter->stats.base_vfgorc;
  1095. adapter->stats.saved_reset_vfgotc += adapter->stats.vfgotc -
  1096. adapter->stats.base_vfgotc;
  1097. adapter->stats.saved_reset_vfmprc += adapter->stats.vfmprc -
  1098. adapter->stats.base_vfmprc;
  1099. }
  1100. }
  1101. static void ixgbevf_init_last_counter_stats(struct ixgbevf_adapter *adapter)
  1102. {
  1103. struct ixgbe_hw *hw = &adapter->hw;
  1104. adapter->stats.last_vfgprc = IXGBE_READ_REG(hw, IXGBE_VFGPRC);
  1105. adapter->stats.last_vfgorc = IXGBE_READ_REG(hw, IXGBE_VFGORC_LSB);
  1106. adapter->stats.last_vfgorc |=
  1107. (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGORC_MSB))) << 32);
  1108. adapter->stats.last_vfgptc = IXGBE_READ_REG(hw, IXGBE_VFGPTC);
  1109. adapter->stats.last_vfgotc = IXGBE_READ_REG(hw, IXGBE_VFGOTC_LSB);
  1110. adapter->stats.last_vfgotc |=
  1111. (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGOTC_MSB))) << 32);
  1112. adapter->stats.last_vfmprc = IXGBE_READ_REG(hw, IXGBE_VFMPRC);
  1113. adapter->stats.base_vfgprc = adapter->stats.last_vfgprc;
  1114. adapter->stats.base_vfgorc = adapter->stats.last_vfgorc;
  1115. adapter->stats.base_vfgptc = adapter->stats.last_vfgptc;
  1116. adapter->stats.base_vfgotc = adapter->stats.last_vfgotc;
  1117. adapter->stats.base_vfmprc = adapter->stats.last_vfmprc;
  1118. }
  1119. static void ixgbevf_negotiate_api(struct ixgbevf_adapter *adapter)
  1120. {
  1121. struct ixgbe_hw *hw = &adapter->hw;
  1122. int api[] = { ixgbe_mbox_api_10,
  1123. ixgbe_mbox_api_unknown };
  1124. int err = 0, idx = 0;
  1125. spin_lock(&adapter->mbx_lock);
  1126. while (api[idx] != ixgbe_mbox_api_unknown) {
  1127. err = ixgbevf_negotiate_api_version(hw, api[idx]);
  1128. if (!err)
  1129. break;
  1130. idx++;
  1131. }
  1132. spin_unlock(&adapter->mbx_lock);
  1133. }
  1134. static void ixgbevf_up_complete(struct ixgbevf_adapter *adapter)
  1135. {
  1136. struct net_device *netdev = adapter->netdev;
  1137. struct ixgbe_hw *hw = &adapter->hw;
  1138. int i, j = 0;
  1139. int num_rx_rings = adapter->num_rx_queues;
  1140. u32 txdctl, rxdctl;
  1141. for (i = 0; i < adapter->num_tx_queues; i++) {
  1142. j = adapter->tx_ring[i].reg_idx;
  1143. txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j));
  1144. /* enable WTHRESH=8 descriptors, to encourage burst writeback */
  1145. txdctl |= (8 << 16);
  1146. IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j), txdctl);
  1147. }
  1148. for (i = 0; i < adapter->num_tx_queues; i++) {
  1149. j = adapter->tx_ring[i].reg_idx;
  1150. txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j));
  1151. txdctl |= IXGBE_TXDCTL_ENABLE;
  1152. IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j), txdctl);
  1153. }
  1154. for (i = 0; i < num_rx_rings; i++) {
  1155. j = adapter->rx_ring[i].reg_idx;
  1156. rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(j));
  1157. rxdctl |= IXGBE_RXDCTL_ENABLE | IXGBE_RXDCTL_VME;
  1158. if (hw->mac.type == ixgbe_mac_X540_vf) {
  1159. rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
  1160. rxdctl |= ((netdev->mtu + ETH_HLEN + ETH_FCS_LEN) |
  1161. IXGBE_RXDCTL_RLPML_EN);
  1162. }
  1163. IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(j), rxdctl);
  1164. ixgbevf_rx_desc_queue_enable(adapter, i);
  1165. }
  1166. ixgbevf_configure_msix(adapter);
  1167. spin_lock(&adapter->mbx_lock);
  1168. if (hw->mac.ops.set_rar) {
  1169. if (is_valid_ether_addr(hw->mac.addr))
  1170. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
  1171. else
  1172. hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0);
  1173. }
  1174. spin_unlock(&adapter->mbx_lock);
  1175. clear_bit(__IXGBEVF_DOWN, &adapter->state);
  1176. ixgbevf_napi_enable_all(adapter);
  1177. /* enable transmits */
  1178. netif_tx_start_all_queues(netdev);
  1179. ixgbevf_save_reset_stats(adapter);
  1180. ixgbevf_init_last_counter_stats(adapter);
  1181. hw->mac.get_link_status = 1;
  1182. mod_timer(&adapter->watchdog_timer, jiffies);
  1183. }
  1184. void ixgbevf_up(struct ixgbevf_adapter *adapter)
  1185. {
  1186. struct ixgbe_hw *hw = &adapter->hw;
  1187. ixgbevf_negotiate_api(adapter);
  1188. ixgbevf_configure(adapter);
  1189. ixgbevf_up_complete(adapter);
  1190. /* clear any pending interrupts, may auto mask */
  1191. IXGBE_READ_REG(hw, IXGBE_VTEICR);
  1192. ixgbevf_irq_enable(adapter);
  1193. }
  1194. /**
  1195. * ixgbevf_clean_rx_ring - Free Rx Buffers per Queue
  1196. * @adapter: board private structure
  1197. * @rx_ring: ring to free buffers from
  1198. **/
  1199. static void ixgbevf_clean_rx_ring(struct ixgbevf_adapter *adapter,
  1200. struct ixgbevf_ring *rx_ring)
  1201. {
  1202. struct pci_dev *pdev = adapter->pdev;
  1203. unsigned long size;
  1204. unsigned int i;
  1205. if (!rx_ring->rx_buffer_info)
  1206. return;
  1207. /* Free all the Rx ring sk_buffs */
  1208. for (i = 0; i < rx_ring->count; i++) {
  1209. struct ixgbevf_rx_buffer *rx_buffer_info;
  1210. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  1211. if (rx_buffer_info->dma) {
  1212. dma_unmap_single(&pdev->dev, rx_buffer_info->dma,
  1213. rx_ring->rx_buf_len,
  1214. DMA_FROM_DEVICE);
  1215. rx_buffer_info->dma = 0;
  1216. }
  1217. if (rx_buffer_info->skb) {
  1218. struct sk_buff *skb = rx_buffer_info->skb;
  1219. rx_buffer_info->skb = NULL;
  1220. do {
  1221. struct sk_buff *this = skb;
  1222. skb = IXGBE_CB(skb)->prev;
  1223. dev_kfree_skb(this);
  1224. } while (skb);
  1225. }
  1226. }
  1227. size = sizeof(struct ixgbevf_rx_buffer) * rx_ring->count;
  1228. memset(rx_ring->rx_buffer_info, 0, size);
  1229. /* Zero out the descriptor ring */
  1230. memset(rx_ring->desc, 0, rx_ring->size);
  1231. rx_ring->next_to_clean = 0;
  1232. rx_ring->next_to_use = 0;
  1233. if (rx_ring->head)
  1234. writel(0, adapter->hw.hw_addr + rx_ring->head);
  1235. if (rx_ring->tail)
  1236. writel(0, adapter->hw.hw_addr + rx_ring->tail);
  1237. }
  1238. /**
  1239. * ixgbevf_clean_tx_ring - Free Tx Buffers
  1240. * @adapter: board private structure
  1241. * @tx_ring: ring to be cleaned
  1242. **/
  1243. static void ixgbevf_clean_tx_ring(struct ixgbevf_adapter *adapter,
  1244. struct ixgbevf_ring *tx_ring)
  1245. {
  1246. struct ixgbevf_tx_buffer *tx_buffer_info;
  1247. unsigned long size;
  1248. unsigned int i;
  1249. if (!tx_ring->tx_buffer_info)
  1250. return;
  1251. /* Free all the Tx ring sk_buffs */
  1252. for (i = 0; i < tx_ring->count; i++) {
  1253. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  1254. ixgbevf_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
  1255. }
  1256. size = sizeof(struct ixgbevf_tx_buffer) * tx_ring->count;
  1257. memset(tx_ring->tx_buffer_info, 0, size);
  1258. memset(tx_ring->desc, 0, tx_ring->size);
  1259. tx_ring->next_to_use = 0;
  1260. tx_ring->next_to_clean = 0;
  1261. if (tx_ring->head)
  1262. writel(0, adapter->hw.hw_addr + tx_ring->head);
  1263. if (tx_ring->tail)
  1264. writel(0, adapter->hw.hw_addr + tx_ring->tail);
  1265. }
  1266. /**
  1267. * ixgbevf_clean_all_rx_rings - Free Rx Buffers for all queues
  1268. * @adapter: board private structure
  1269. **/
  1270. static void ixgbevf_clean_all_rx_rings(struct ixgbevf_adapter *adapter)
  1271. {
  1272. int i;
  1273. for (i = 0; i < adapter->num_rx_queues; i++)
  1274. ixgbevf_clean_rx_ring(adapter, &adapter->rx_ring[i]);
  1275. }
  1276. /**
  1277. * ixgbevf_clean_all_tx_rings - Free Tx Buffers for all queues
  1278. * @adapter: board private structure
  1279. **/
  1280. static void ixgbevf_clean_all_tx_rings(struct ixgbevf_adapter *adapter)
  1281. {
  1282. int i;
  1283. for (i = 0; i < adapter->num_tx_queues; i++)
  1284. ixgbevf_clean_tx_ring(adapter, &adapter->tx_ring[i]);
  1285. }
  1286. void ixgbevf_down(struct ixgbevf_adapter *adapter)
  1287. {
  1288. struct net_device *netdev = adapter->netdev;
  1289. struct ixgbe_hw *hw = &adapter->hw;
  1290. u32 txdctl;
  1291. int i, j;
  1292. /* signal that we are down to the interrupt handler */
  1293. set_bit(__IXGBEVF_DOWN, &adapter->state);
  1294. /* disable receives */
  1295. netif_tx_disable(netdev);
  1296. msleep(10);
  1297. netif_tx_stop_all_queues(netdev);
  1298. ixgbevf_irq_disable(adapter);
  1299. ixgbevf_napi_disable_all(adapter);
  1300. del_timer_sync(&adapter->watchdog_timer);
  1301. /* can't call flush scheduled work here because it can deadlock
  1302. * if linkwatch_event tries to acquire the rtnl_lock which we are
  1303. * holding */
  1304. while (adapter->flags & IXGBE_FLAG_IN_WATCHDOG_TASK)
  1305. msleep(1);
  1306. /* disable transmits in the hardware now that interrupts are off */
  1307. for (i = 0; i < adapter->num_tx_queues; i++) {
  1308. j = adapter->tx_ring[i].reg_idx;
  1309. txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j));
  1310. IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j),
  1311. (txdctl & ~IXGBE_TXDCTL_ENABLE));
  1312. }
  1313. netif_carrier_off(netdev);
  1314. if (!pci_channel_offline(adapter->pdev))
  1315. ixgbevf_reset(adapter);
  1316. ixgbevf_clean_all_tx_rings(adapter);
  1317. ixgbevf_clean_all_rx_rings(adapter);
  1318. }
  1319. void ixgbevf_reinit_locked(struct ixgbevf_adapter *adapter)
  1320. {
  1321. WARN_ON(in_interrupt());
  1322. while (test_and_set_bit(__IXGBEVF_RESETTING, &adapter->state))
  1323. msleep(1);
  1324. /*
  1325. * Check if PF is up before re-init. If not then skip until
  1326. * later when the PF is up and ready to service requests from
  1327. * the VF via mailbox. If the VF is up and running then the
  1328. * watchdog task will continue to schedule reset tasks until
  1329. * the PF is up and running.
  1330. */
  1331. ixgbevf_down(adapter);
  1332. ixgbevf_up(adapter);
  1333. clear_bit(__IXGBEVF_RESETTING, &adapter->state);
  1334. }
  1335. void ixgbevf_reset(struct ixgbevf_adapter *adapter)
  1336. {
  1337. struct ixgbe_hw *hw = &adapter->hw;
  1338. struct net_device *netdev = adapter->netdev;
  1339. spin_lock(&adapter->mbx_lock);
  1340. if (hw->mac.ops.reset_hw(hw))
  1341. hw_dbg(hw, "PF still resetting\n");
  1342. else
  1343. hw->mac.ops.init_hw(hw);
  1344. spin_unlock(&adapter->mbx_lock);
  1345. if (is_valid_ether_addr(adapter->hw.mac.addr)) {
  1346. memcpy(netdev->dev_addr, adapter->hw.mac.addr,
  1347. netdev->addr_len);
  1348. memcpy(netdev->perm_addr, adapter->hw.mac.addr,
  1349. netdev->addr_len);
  1350. }
  1351. }
  1352. static void ixgbevf_acquire_msix_vectors(struct ixgbevf_adapter *adapter,
  1353. int vectors)
  1354. {
  1355. int err, vector_threshold;
  1356. /* We'll want at least 2 (vector_threshold):
  1357. * 1) TxQ[0] + RxQ[0] handler
  1358. * 2) Other (Link Status Change, etc.)
  1359. */
  1360. vector_threshold = MIN_MSIX_COUNT;
  1361. /* The more we get, the more we will assign to Tx/Rx Cleanup
  1362. * for the separate queues...where Rx Cleanup >= Tx Cleanup.
  1363. * Right now, we simply care about how many we'll get; we'll
  1364. * set them up later while requesting irq's.
  1365. */
  1366. while (vectors >= vector_threshold) {
  1367. err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
  1368. vectors);
  1369. if (!err) /* Success in acquiring all requested vectors. */
  1370. break;
  1371. else if (err < 0)
  1372. vectors = 0; /* Nasty failure, quit now */
  1373. else /* err == number of vectors we should try again with */
  1374. vectors = err;
  1375. }
  1376. if (vectors < vector_threshold) {
  1377. /* Can't allocate enough MSI-X interrupts? Oh well.
  1378. * This just means we'll go with either a single MSI
  1379. * vector or fall back to legacy interrupts.
  1380. */
  1381. hw_dbg(&adapter->hw,
  1382. "Unable to allocate MSI-X interrupts\n");
  1383. kfree(adapter->msix_entries);
  1384. adapter->msix_entries = NULL;
  1385. } else {
  1386. /*
  1387. * Adjust for only the vectors we'll use, which is minimum
  1388. * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
  1389. * vectors we were allocated.
  1390. */
  1391. adapter->num_msix_vectors = vectors;
  1392. }
  1393. }
  1394. /**
  1395. * ixgbevf_set_num_queues - Allocate queues for device, feature dependent
  1396. * @adapter: board private structure to initialize
  1397. *
  1398. * This is the top level queue allocation routine. The order here is very
  1399. * important, starting with the "most" number of features turned on at once,
  1400. * and ending with the smallest set of features. This way large combinations
  1401. * can be allocated if they're turned on, and smaller combinations are the
  1402. * fallthrough conditions.
  1403. *
  1404. **/
  1405. static void ixgbevf_set_num_queues(struct ixgbevf_adapter *adapter)
  1406. {
  1407. /* Start with base case */
  1408. adapter->num_rx_queues = 1;
  1409. adapter->num_tx_queues = 1;
  1410. }
  1411. /**
  1412. * ixgbevf_alloc_queues - Allocate memory for all rings
  1413. * @adapter: board private structure to initialize
  1414. *
  1415. * We allocate one ring per queue at run-time since we don't know the
  1416. * number of queues at compile-time. The polling_netdev array is
  1417. * intended for Multiqueue, but should work fine with a single queue.
  1418. **/
  1419. static int ixgbevf_alloc_queues(struct ixgbevf_adapter *adapter)
  1420. {
  1421. int i;
  1422. adapter->tx_ring = kcalloc(adapter->num_tx_queues,
  1423. sizeof(struct ixgbevf_ring), GFP_KERNEL);
  1424. if (!adapter->tx_ring)
  1425. goto err_tx_ring_allocation;
  1426. adapter->rx_ring = kcalloc(adapter->num_rx_queues,
  1427. sizeof(struct ixgbevf_ring), GFP_KERNEL);
  1428. if (!adapter->rx_ring)
  1429. goto err_rx_ring_allocation;
  1430. for (i = 0; i < adapter->num_tx_queues; i++) {
  1431. adapter->tx_ring[i].count = adapter->tx_ring_count;
  1432. adapter->tx_ring[i].queue_index = i;
  1433. adapter->tx_ring[i].reg_idx = i;
  1434. adapter->tx_ring[i].dev = &adapter->pdev->dev;
  1435. adapter->tx_ring[i].netdev = adapter->netdev;
  1436. }
  1437. for (i = 0; i < adapter->num_rx_queues; i++) {
  1438. adapter->rx_ring[i].count = adapter->rx_ring_count;
  1439. adapter->rx_ring[i].queue_index = i;
  1440. adapter->rx_ring[i].reg_idx = i;
  1441. adapter->rx_ring[i].dev = &adapter->pdev->dev;
  1442. adapter->rx_ring[i].netdev = adapter->netdev;
  1443. }
  1444. return 0;
  1445. err_rx_ring_allocation:
  1446. kfree(adapter->tx_ring);
  1447. err_tx_ring_allocation:
  1448. return -ENOMEM;
  1449. }
  1450. /**
  1451. * ixgbevf_set_interrupt_capability - set MSI-X or FAIL if not supported
  1452. * @adapter: board private structure to initialize
  1453. *
  1454. * Attempt to configure the interrupts using the best available
  1455. * capabilities of the hardware and the kernel.
  1456. **/
  1457. static int ixgbevf_set_interrupt_capability(struct ixgbevf_adapter *adapter)
  1458. {
  1459. int err = 0;
  1460. int vector, v_budget;
  1461. /*
  1462. * It's easy to be greedy for MSI-X vectors, but it really
  1463. * doesn't do us much good if we have a lot more vectors
  1464. * than CPU's. So let's be conservative and only ask for
  1465. * (roughly) the same number of vectors as there are CPU's.
  1466. * The default is to use pairs of vectors.
  1467. */
  1468. v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues);
  1469. v_budget = min_t(int, v_budget, num_online_cpus());
  1470. v_budget += NON_Q_VECTORS;
  1471. /* A failure in MSI-X entry allocation isn't fatal, but it does
  1472. * mean we disable MSI-X capabilities of the adapter. */
  1473. adapter->msix_entries = kcalloc(v_budget,
  1474. sizeof(struct msix_entry), GFP_KERNEL);
  1475. if (!adapter->msix_entries) {
  1476. err = -ENOMEM;
  1477. goto out;
  1478. }
  1479. for (vector = 0; vector < v_budget; vector++)
  1480. adapter->msix_entries[vector].entry = vector;
  1481. ixgbevf_acquire_msix_vectors(adapter, v_budget);
  1482. out:
  1483. return err;
  1484. }
  1485. /**
  1486. * ixgbevf_alloc_q_vectors - Allocate memory for interrupt vectors
  1487. * @adapter: board private structure to initialize
  1488. *
  1489. * We allocate one q_vector per queue interrupt. If allocation fails we
  1490. * return -ENOMEM.
  1491. **/
  1492. static int ixgbevf_alloc_q_vectors(struct ixgbevf_adapter *adapter)
  1493. {
  1494. int q_idx, num_q_vectors;
  1495. struct ixgbevf_q_vector *q_vector;
  1496. num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1497. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  1498. q_vector = kzalloc(sizeof(struct ixgbevf_q_vector), GFP_KERNEL);
  1499. if (!q_vector)
  1500. goto err_out;
  1501. q_vector->adapter = adapter;
  1502. q_vector->v_idx = q_idx;
  1503. netif_napi_add(adapter->netdev, &q_vector->napi,
  1504. ixgbevf_poll, 64);
  1505. adapter->q_vector[q_idx] = q_vector;
  1506. }
  1507. return 0;
  1508. err_out:
  1509. while (q_idx) {
  1510. q_idx--;
  1511. q_vector = adapter->q_vector[q_idx];
  1512. netif_napi_del(&q_vector->napi);
  1513. kfree(q_vector);
  1514. adapter->q_vector[q_idx] = NULL;
  1515. }
  1516. return -ENOMEM;
  1517. }
  1518. /**
  1519. * ixgbevf_free_q_vectors - Free memory allocated for interrupt vectors
  1520. * @adapter: board private structure to initialize
  1521. *
  1522. * This function frees the memory allocated to the q_vectors. In addition if
  1523. * NAPI is enabled it will delete any references to the NAPI struct prior
  1524. * to freeing the q_vector.
  1525. **/
  1526. static void ixgbevf_free_q_vectors(struct ixgbevf_adapter *adapter)
  1527. {
  1528. int q_idx, num_q_vectors;
  1529. int napi_vectors;
  1530. num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1531. napi_vectors = adapter->num_rx_queues;
  1532. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  1533. struct ixgbevf_q_vector *q_vector = adapter->q_vector[q_idx];
  1534. adapter->q_vector[q_idx] = NULL;
  1535. if (q_idx < napi_vectors)
  1536. netif_napi_del(&q_vector->napi);
  1537. kfree(q_vector);
  1538. }
  1539. }
  1540. /**
  1541. * ixgbevf_reset_interrupt_capability - Reset MSIX setup
  1542. * @adapter: board private structure
  1543. *
  1544. **/
  1545. static void ixgbevf_reset_interrupt_capability(struct ixgbevf_adapter *adapter)
  1546. {
  1547. pci_disable_msix(adapter->pdev);
  1548. kfree(adapter->msix_entries);
  1549. adapter->msix_entries = NULL;
  1550. }
  1551. /**
  1552. * ixgbevf_init_interrupt_scheme - Determine if MSIX is supported and init
  1553. * @adapter: board private structure to initialize
  1554. *
  1555. **/
  1556. static int ixgbevf_init_interrupt_scheme(struct ixgbevf_adapter *adapter)
  1557. {
  1558. int err;
  1559. /* Number of supported queues */
  1560. ixgbevf_set_num_queues(adapter);
  1561. err = ixgbevf_set_interrupt_capability(adapter);
  1562. if (err) {
  1563. hw_dbg(&adapter->hw,
  1564. "Unable to setup interrupt capabilities\n");
  1565. goto err_set_interrupt;
  1566. }
  1567. err = ixgbevf_alloc_q_vectors(adapter);
  1568. if (err) {
  1569. hw_dbg(&adapter->hw, "Unable to allocate memory for queue "
  1570. "vectors\n");
  1571. goto err_alloc_q_vectors;
  1572. }
  1573. err = ixgbevf_alloc_queues(adapter);
  1574. if (err) {
  1575. pr_err("Unable to allocate memory for queues\n");
  1576. goto err_alloc_queues;
  1577. }
  1578. hw_dbg(&adapter->hw, "Multiqueue %s: Rx Queue count = %u, "
  1579. "Tx Queue count = %u\n",
  1580. (adapter->num_rx_queues > 1) ? "Enabled" :
  1581. "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
  1582. set_bit(__IXGBEVF_DOWN, &adapter->state);
  1583. return 0;
  1584. err_alloc_queues:
  1585. ixgbevf_free_q_vectors(adapter);
  1586. err_alloc_q_vectors:
  1587. ixgbevf_reset_interrupt_capability(adapter);
  1588. err_set_interrupt:
  1589. return err;
  1590. }
  1591. /**
  1592. * ixgbevf_clear_interrupt_scheme - Clear the current interrupt scheme settings
  1593. * @adapter: board private structure to clear interrupt scheme on
  1594. *
  1595. * We go through and clear interrupt specific resources and reset the structure
  1596. * to pre-load conditions
  1597. **/
  1598. static void ixgbevf_clear_interrupt_scheme(struct ixgbevf_adapter *adapter)
  1599. {
  1600. adapter->num_tx_queues = 0;
  1601. adapter->num_rx_queues = 0;
  1602. ixgbevf_free_q_vectors(adapter);
  1603. ixgbevf_reset_interrupt_capability(adapter);
  1604. }
  1605. /**
  1606. * ixgbevf_sw_init - Initialize general software structures
  1607. * (struct ixgbevf_adapter)
  1608. * @adapter: board private structure to initialize
  1609. *
  1610. * ixgbevf_sw_init initializes the Adapter private data structure.
  1611. * Fields are initialized based on PCI device information and
  1612. * OS network device settings (MTU size).
  1613. **/
  1614. static int __devinit ixgbevf_sw_init(struct ixgbevf_adapter *adapter)
  1615. {
  1616. struct ixgbe_hw *hw = &adapter->hw;
  1617. struct pci_dev *pdev = adapter->pdev;
  1618. int err;
  1619. /* PCI config space info */
  1620. hw->vendor_id = pdev->vendor;
  1621. hw->device_id = pdev->device;
  1622. hw->revision_id = pdev->revision;
  1623. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  1624. hw->subsystem_device_id = pdev->subsystem_device;
  1625. hw->mbx.ops.init_params(hw);
  1626. hw->mac.max_tx_queues = MAX_TX_QUEUES;
  1627. hw->mac.max_rx_queues = MAX_RX_QUEUES;
  1628. err = hw->mac.ops.reset_hw(hw);
  1629. if (err) {
  1630. dev_info(&pdev->dev,
  1631. "PF still in reset state, assigning new address\n");
  1632. eth_hw_addr_random(adapter->netdev);
  1633. memcpy(adapter->hw.mac.addr, adapter->netdev->dev_addr,
  1634. adapter->netdev->addr_len);
  1635. } else {
  1636. err = hw->mac.ops.init_hw(hw);
  1637. if (err) {
  1638. pr_err("init_shared_code failed: %d\n", err);
  1639. goto out;
  1640. }
  1641. memcpy(adapter->netdev->dev_addr, adapter->hw.mac.addr,
  1642. adapter->netdev->addr_len);
  1643. }
  1644. /* lock to protect mailbox accesses */
  1645. spin_lock_init(&adapter->mbx_lock);
  1646. /* Enable dynamic interrupt throttling rates */
  1647. adapter->rx_itr_setting = 1;
  1648. adapter->tx_itr_setting = 1;
  1649. /* set default ring sizes */
  1650. adapter->tx_ring_count = IXGBEVF_DEFAULT_TXD;
  1651. adapter->rx_ring_count = IXGBEVF_DEFAULT_RXD;
  1652. set_bit(__IXGBEVF_DOWN, &adapter->state);
  1653. return 0;
  1654. out:
  1655. return err;
  1656. }
  1657. #define UPDATE_VF_COUNTER_32bit(reg, last_counter, counter) \
  1658. { \
  1659. u32 current_counter = IXGBE_READ_REG(hw, reg); \
  1660. if (current_counter < last_counter) \
  1661. counter += 0x100000000LL; \
  1662. last_counter = current_counter; \
  1663. counter &= 0xFFFFFFFF00000000LL; \
  1664. counter |= current_counter; \
  1665. }
  1666. #define UPDATE_VF_COUNTER_36bit(reg_lsb, reg_msb, last_counter, counter) \
  1667. { \
  1668. u64 current_counter_lsb = IXGBE_READ_REG(hw, reg_lsb); \
  1669. u64 current_counter_msb = IXGBE_READ_REG(hw, reg_msb); \
  1670. u64 current_counter = (current_counter_msb << 32) | \
  1671. current_counter_lsb; \
  1672. if (current_counter < last_counter) \
  1673. counter += 0x1000000000LL; \
  1674. last_counter = current_counter; \
  1675. counter &= 0xFFFFFFF000000000LL; \
  1676. counter |= current_counter; \
  1677. }
  1678. /**
  1679. * ixgbevf_update_stats - Update the board statistics counters.
  1680. * @adapter: board private structure
  1681. **/
  1682. void ixgbevf_update_stats(struct ixgbevf_adapter *adapter)
  1683. {
  1684. struct ixgbe_hw *hw = &adapter->hw;
  1685. UPDATE_VF_COUNTER_32bit(IXGBE_VFGPRC, adapter->stats.last_vfgprc,
  1686. adapter->stats.vfgprc);
  1687. UPDATE_VF_COUNTER_32bit(IXGBE_VFGPTC, adapter->stats.last_vfgptc,
  1688. adapter->stats.vfgptc);
  1689. UPDATE_VF_COUNTER_36bit(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB,
  1690. adapter->stats.last_vfgorc,
  1691. adapter->stats.vfgorc);
  1692. UPDATE_VF_COUNTER_36bit(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB,
  1693. adapter->stats.last_vfgotc,
  1694. adapter->stats.vfgotc);
  1695. UPDATE_VF_COUNTER_32bit(IXGBE_VFMPRC, adapter->stats.last_vfmprc,
  1696. adapter->stats.vfmprc);
  1697. }
  1698. /**
  1699. * ixgbevf_watchdog - Timer Call-back
  1700. * @data: pointer to adapter cast into an unsigned long
  1701. **/
  1702. static void ixgbevf_watchdog(unsigned long data)
  1703. {
  1704. struct ixgbevf_adapter *adapter = (struct ixgbevf_adapter *)data;
  1705. struct ixgbe_hw *hw = &adapter->hw;
  1706. u32 eics = 0;
  1707. int i;
  1708. /*
  1709. * Do the watchdog outside of interrupt context due to the lovely
  1710. * delays that some of the newer hardware requires
  1711. */
  1712. if (test_bit(__IXGBEVF_DOWN, &adapter->state))
  1713. goto watchdog_short_circuit;
  1714. /* get one bit for every active tx/rx interrupt vector */
  1715. for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
  1716. struct ixgbevf_q_vector *qv = adapter->q_vector[i];
  1717. if (qv->rx.ring || qv->tx.ring)
  1718. eics |= 1 << i;
  1719. }
  1720. IXGBE_WRITE_REG(hw, IXGBE_VTEICS, eics);
  1721. watchdog_short_circuit:
  1722. schedule_work(&adapter->watchdog_task);
  1723. }
  1724. /**
  1725. * ixgbevf_tx_timeout - Respond to a Tx Hang
  1726. * @netdev: network interface device structure
  1727. **/
  1728. static void ixgbevf_tx_timeout(struct net_device *netdev)
  1729. {
  1730. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  1731. /* Do the reset outside of interrupt context */
  1732. schedule_work(&adapter->reset_task);
  1733. }
  1734. static void ixgbevf_reset_task(struct work_struct *work)
  1735. {
  1736. struct ixgbevf_adapter *adapter;
  1737. adapter = container_of(work, struct ixgbevf_adapter, reset_task);
  1738. /* If we're already down or resetting, just bail */
  1739. if (test_bit(__IXGBEVF_DOWN, &adapter->state) ||
  1740. test_bit(__IXGBEVF_RESETTING, &adapter->state))
  1741. return;
  1742. adapter->tx_timeout_count++;
  1743. ixgbevf_reinit_locked(adapter);
  1744. }
  1745. /**
  1746. * ixgbevf_watchdog_task - worker thread to bring link up
  1747. * @work: pointer to work_struct containing our data
  1748. **/
  1749. static void ixgbevf_watchdog_task(struct work_struct *work)
  1750. {
  1751. struct ixgbevf_adapter *adapter = container_of(work,
  1752. struct ixgbevf_adapter,
  1753. watchdog_task);
  1754. struct net_device *netdev = adapter->netdev;
  1755. struct ixgbe_hw *hw = &adapter->hw;
  1756. u32 link_speed = adapter->link_speed;
  1757. bool link_up = adapter->link_up;
  1758. adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
  1759. /*
  1760. * Always check the link on the watchdog because we have
  1761. * no LSC interrupt
  1762. */
  1763. if (hw->mac.ops.check_link) {
  1764. s32 need_reset;
  1765. spin_lock(&adapter->mbx_lock);
  1766. need_reset = hw->mac.ops.check_link(hw, &link_speed,
  1767. &link_up, false);
  1768. spin_unlock(&adapter->mbx_lock);
  1769. if (need_reset) {
  1770. adapter->link_up = link_up;
  1771. adapter->link_speed = link_speed;
  1772. netif_carrier_off(netdev);
  1773. netif_tx_stop_all_queues(netdev);
  1774. schedule_work(&adapter->reset_task);
  1775. goto pf_has_reset;
  1776. }
  1777. } else {
  1778. /* always assume link is up, if no check link
  1779. * function */
  1780. link_speed = IXGBE_LINK_SPEED_10GB_FULL;
  1781. link_up = true;
  1782. }
  1783. adapter->link_up = link_up;
  1784. adapter->link_speed = link_speed;
  1785. if (link_up) {
  1786. if (!netif_carrier_ok(netdev)) {
  1787. hw_dbg(&adapter->hw, "NIC Link is Up, %u Gbps\n",
  1788. (link_speed == IXGBE_LINK_SPEED_10GB_FULL) ?
  1789. 10 : 1);
  1790. netif_carrier_on(netdev);
  1791. netif_tx_wake_all_queues(netdev);
  1792. }
  1793. } else {
  1794. adapter->link_up = false;
  1795. adapter->link_speed = 0;
  1796. if (netif_carrier_ok(netdev)) {
  1797. hw_dbg(&adapter->hw, "NIC Link is Down\n");
  1798. netif_carrier_off(netdev);
  1799. netif_tx_stop_all_queues(netdev);
  1800. }
  1801. }
  1802. ixgbevf_update_stats(adapter);
  1803. pf_has_reset:
  1804. /* Reset the timer */
  1805. if (!test_bit(__IXGBEVF_DOWN, &adapter->state))
  1806. mod_timer(&adapter->watchdog_timer,
  1807. round_jiffies(jiffies + (2 * HZ)));
  1808. adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
  1809. }
  1810. /**
  1811. * ixgbevf_free_tx_resources - Free Tx Resources per Queue
  1812. * @adapter: board private structure
  1813. * @tx_ring: Tx descriptor ring for a specific queue
  1814. *
  1815. * Free all transmit software resources
  1816. **/
  1817. void ixgbevf_free_tx_resources(struct ixgbevf_adapter *adapter,
  1818. struct ixgbevf_ring *tx_ring)
  1819. {
  1820. struct pci_dev *pdev = adapter->pdev;
  1821. ixgbevf_clean_tx_ring(adapter, tx_ring);
  1822. vfree(tx_ring->tx_buffer_info);
  1823. tx_ring->tx_buffer_info = NULL;
  1824. dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
  1825. tx_ring->dma);
  1826. tx_ring->desc = NULL;
  1827. }
  1828. /**
  1829. * ixgbevf_free_all_tx_resources - Free Tx Resources for All Queues
  1830. * @adapter: board private structure
  1831. *
  1832. * Free all transmit software resources
  1833. **/
  1834. static void ixgbevf_free_all_tx_resources(struct ixgbevf_adapter *adapter)
  1835. {
  1836. int i;
  1837. for (i = 0; i < adapter->num_tx_queues; i++)
  1838. if (adapter->tx_ring[i].desc)
  1839. ixgbevf_free_tx_resources(adapter,
  1840. &adapter->tx_ring[i]);
  1841. }
  1842. /**
  1843. * ixgbevf_setup_tx_resources - allocate Tx resources (Descriptors)
  1844. * @adapter: board private structure
  1845. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  1846. *
  1847. * Return 0 on success, negative on failure
  1848. **/
  1849. int ixgbevf_setup_tx_resources(struct ixgbevf_adapter *adapter,
  1850. struct ixgbevf_ring *tx_ring)
  1851. {
  1852. struct pci_dev *pdev = adapter->pdev;
  1853. int size;
  1854. size = sizeof(struct ixgbevf_tx_buffer) * tx_ring->count;
  1855. tx_ring->tx_buffer_info = vzalloc(size);
  1856. if (!tx_ring->tx_buffer_info)
  1857. goto err;
  1858. /* round up to nearest 4K */
  1859. tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
  1860. tx_ring->size = ALIGN(tx_ring->size, 4096);
  1861. tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
  1862. &tx_ring->dma, GFP_KERNEL);
  1863. if (!tx_ring->desc)
  1864. goto err;
  1865. tx_ring->next_to_use = 0;
  1866. tx_ring->next_to_clean = 0;
  1867. return 0;
  1868. err:
  1869. vfree(tx_ring->tx_buffer_info);
  1870. tx_ring->tx_buffer_info = NULL;
  1871. hw_dbg(&adapter->hw, "Unable to allocate memory for the transmit "
  1872. "descriptor ring\n");
  1873. return -ENOMEM;
  1874. }
  1875. /**
  1876. * ixgbevf_setup_all_tx_resources - allocate all queues Tx resources
  1877. * @adapter: board private structure
  1878. *
  1879. * If this function returns with an error, then it's possible one or
  1880. * more of the rings is populated (while the rest are not). It is the
  1881. * callers duty to clean those orphaned rings.
  1882. *
  1883. * Return 0 on success, negative on failure
  1884. **/
  1885. static int ixgbevf_setup_all_tx_resources(struct ixgbevf_adapter *adapter)
  1886. {
  1887. int i, err = 0;
  1888. for (i = 0; i < adapter->num_tx_queues; i++) {
  1889. err = ixgbevf_setup_tx_resources(adapter, &adapter->tx_ring[i]);
  1890. if (!err)
  1891. continue;
  1892. hw_dbg(&adapter->hw,
  1893. "Allocation for Tx Queue %u failed\n", i);
  1894. break;
  1895. }
  1896. return err;
  1897. }
  1898. /**
  1899. * ixgbevf_setup_rx_resources - allocate Rx resources (Descriptors)
  1900. * @adapter: board private structure
  1901. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  1902. *
  1903. * Returns 0 on success, negative on failure
  1904. **/
  1905. int ixgbevf_setup_rx_resources(struct ixgbevf_adapter *adapter,
  1906. struct ixgbevf_ring *rx_ring)
  1907. {
  1908. struct pci_dev *pdev = adapter->pdev;
  1909. int size;
  1910. size = sizeof(struct ixgbevf_rx_buffer) * rx_ring->count;
  1911. rx_ring->rx_buffer_info = vzalloc(size);
  1912. if (!rx_ring->rx_buffer_info)
  1913. goto alloc_failed;
  1914. /* Round up to nearest 4K */
  1915. rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
  1916. rx_ring->size = ALIGN(rx_ring->size, 4096);
  1917. rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
  1918. &rx_ring->dma, GFP_KERNEL);
  1919. if (!rx_ring->desc) {
  1920. hw_dbg(&adapter->hw,
  1921. "Unable to allocate memory for "
  1922. "the receive descriptor ring\n");
  1923. vfree(rx_ring->rx_buffer_info);
  1924. rx_ring->rx_buffer_info = NULL;
  1925. goto alloc_failed;
  1926. }
  1927. rx_ring->next_to_clean = 0;
  1928. rx_ring->next_to_use = 0;
  1929. return 0;
  1930. alloc_failed:
  1931. return -ENOMEM;
  1932. }
  1933. /**
  1934. * ixgbevf_setup_all_rx_resources - allocate all queues Rx resources
  1935. * @adapter: board private structure
  1936. *
  1937. * If this function returns with an error, then it's possible one or
  1938. * more of the rings is populated (while the rest are not). It is the
  1939. * callers duty to clean those orphaned rings.
  1940. *
  1941. * Return 0 on success, negative on failure
  1942. **/
  1943. static int ixgbevf_setup_all_rx_resources(struct ixgbevf_adapter *adapter)
  1944. {
  1945. int i, err = 0;
  1946. for (i = 0; i < adapter->num_rx_queues; i++) {
  1947. err = ixgbevf_setup_rx_resources(adapter, &adapter->rx_ring[i]);
  1948. if (!err)
  1949. continue;
  1950. hw_dbg(&adapter->hw,
  1951. "Allocation for Rx Queue %u failed\n", i);
  1952. break;
  1953. }
  1954. return err;
  1955. }
  1956. /**
  1957. * ixgbevf_free_rx_resources - Free Rx Resources
  1958. * @adapter: board private structure
  1959. * @rx_ring: ring to clean the resources from
  1960. *
  1961. * Free all receive software resources
  1962. **/
  1963. void ixgbevf_free_rx_resources(struct ixgbevf_adapter *adapter,
  1964. struct ixgbevf_ring *rx_ring)
  1965. {
  1966. struct pci_dev *pdev = adapter->pdev;
  1967. ixgbevf_clean_rx_ring(adapter, rx_ring);
  1968. vfree(rx_ring->rx_buffer_info);
  1969. rx_ring->rx_buffer_info = NULL;
  1970. dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
  1971. rx_ring->dma);
  1972. rx_ring->desc = NULL;
  1973. }
  1974. /**
  1975. * ixgbevf_free_all_rx_resources - Free Rx Resources for All Queues
  1976. * @adapter: board private structure
  1977. *
  1978. * Free all receive software resources
  1979. **/
  1980. static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter *adapter)
  1981. {
  1982. int i;
  1983. for (i = 0; i < adapter->num_rx_queues; i++)
  1984. if (adapter->rx_ring[i].desc)
  1985. ixgbevf_free_rx_resources(adapter,
  1986. &adapter->rx_ring[i]);
  1987. }
  1988. /**
  1989. * ixgbevf_open - Called when a network interface is made active
  1990. * @netdev: network interface device structure
  1991. *
  1992. * Returns 0 on success, negative value on failure
  1993. *
  1994. * The open entry point is called when a network interface is made
  1995. * active by the system (IFF_UP). At this point all resources needed
  1996. * for transmit and receive operations are allocated, the interrupt
  1997. * handler is registered with the OS, the watchdog timer is started,
  1998. * and the stack is notified that the interface is ready.
  1999. **/
  2000. static int ixgbevf_open(struct net_device *netdev)
  2001. {
  2002. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2003. struct ixgbe_hw *hw = &adapter->hw;
  2004. int err;
  2005. /* disallow open during test */
  2006. if (test_bit(__IXGBEVF_TESTING, &adapter->state))
  2007. return -EBUSY;
  2008. if (hw->adapter_stopped) {
  2009. ixgbevf_reset(adapter);
  2010. /* if adapter is still stopped then PF isn't up and
  2011. * the vf can't start. */
  2012. if (hw->adapter_stopped) {
  2013. err = IXGBE_ERR_MBX;
  2014. pr_err("Unable to start - perhaps the PF Driver isn't "
  2015. "up yet\n");
  2016. goto err_setup_reset;
  2017. }
  2018. }
  2019. ixgbevf_negotiate_api(adapter);
  2020. /* allocate transmit descriptors */
  2021. err = ixgbevf_setup_all_tx_resources(adapter);
  2022. if (err)
  2023. goto err_setup_tx;
  2024. /* allocate receive descriptors */
  2025. err = ixgbevf_setup_all_rx_resources(adapter);
  2026. if (err)
  2027. goto err_setup_rx;
  2028. ixgbevf_configure(adapter);
  2029. /*
  2030. * Map the Tx/Rx rings to the vectors we were allotted.
  2031. * if request_irq will be called in this function map_rings
  2032. * must be called *before* up_complete
  2033. */
  2034. ixgbevf_map_rings_to_vectors(adapter);
  2035. ixgbevf_up_complete(adapter);
  2036. /* clear any pending interrupts, may auto mask */
  2037. IXGBE_READ_REG(hw, IXGBE_VTEICR);
  2038. err = ixgbevf_request_irq(adapter);
  2039. if (err)
  2040. goto err_req_irq;
  2041. ixgbevf_irq_enable(adapter);
  2042. return 0;
  2043. err_req_irq:
  2044. ixgbevf_down(adapter);
  2045. ixgbevf_free_irq(adapter);
  2046. err_setup_rx:
  2047. ixgbevf_free_all_rx_resources(adapter);
  2048. err_setup_tx:
  2049. ixgbevf_free_all_tx_resources(adapter);
  2050. ixgbevf_reset(adapter);
  2051. err_setup_reset:
  2052. return err;
  2053. }
  2054. /**
  2055. * ixgbevf_close - Disables a network interface
  2056. * @netdev: network interface device structure
  2057. *
  2058. * Returns 0, this is not allowed to fail
  2059. *
  2060. * The close entry point is called when an interface is de-activated
  2061. * by the OS. The hardware is still under the drivers control, but
  2062. * needs to be disabled. A global MAC reset is issued to stop the
  2063. * hardware, and all transmit and receive resources are freed.
  2064. **/
  2065. static int ixgbevf_close(struct net_device *netdev)
  2066. {
  2067. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2068. ixgbevf_down(adapter);
  2069. ixgbevf_free_irq(adapter);
  2070. ixgbevf_free_all_tx_resources(adapter);
  2071. ixgbevf_free_all_rx_resources(adapter);
  2072. return 0;
  2073. }
  2074. static void ixgbevf_tx_ctxtdesc(struct ixgbevf_ring *tx_ring,
  2075. u32 vlan_macip_lens, u32 type_tucmd,
  2076. u32 mss_l4len_idx)
  2077. {
  2078. struct ixgbe_adv_tx_context_desc *context_desc;
  2079. u16 i = tx_ring->next_to_use;
  2080. context_desc = IXGBEVF_TX_CTXTDESC(tx_ring, i);
  2081. i++;
  2082. tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
  2083. /* set bits to identify this as an advanced context descriptor */
  2084. type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
  2085. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  2086. context_desc->seqnum_seed = 0;
  2087. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
  2088. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  2089. }
  2090. static int ixgbevf_tso(struct ixgbevf_ring *tx_ring,
  2091. struct sk_buff *skb, u32 tx_flags, u8 *hdr_len)
  2092. {
  2093. u32 vlan_macip_lens, type_tucmd;
  2094. u32 mss_l4len_idx, l4len;
  2095. if (!skb_is_gso(skb))
  2096. return 0;
  2097. if (skb_header_cloned(skb)) {
  2098. int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  2099. if (err)
  2100. return err;
  2101. }
  2102. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  2103. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
  2104. if (skb->protocol == htons(ETH_P_IP)) {
  2105. struct iphdr *iph = ip_hdr(skb);
  2106. iph->tot_len = 0;
  2107. iph->check = 0;
  2108. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  2109. iph->daddr, 0,
  2110. IPPROTO_TCP,
  2111. 0);
  2112. type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
  2113. } else if (skb_is_gso_v6(skb)) {
  2114. ipv6_hdr(skb)->payload_len = 0;
  2115. tcp_hdr(skb)->check =
  2116. ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  2117. &ipv6_hdr(skb)->daddr,
  2118. 0, IPPROTO_TCP, 0);
  2119. }
  2120. /* compute header lengths */
  2121. l4len = tcp_hdrlen(skb);
  2122. *hdr_len += l4len;
  2123. *hdr_len = skb_transport_offset(skb) + l4len;
  2124. /* mss_l4len_id: use 1 as index for TSO */
  2125. mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
  2126. mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
  2127. mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
  2128. /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
  2129. vlan_macip_lens = skb_network_header_len(skb);
  2130. vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
  2131. vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  2132. ixgbevf_tx_ctxtdesc(tx_ring, vlan_macip_lens,
  2133. type_tucmd, mss_l4len_idx);
  2134. return 1;
  2135. }
  2136. static bool ixgbevf_tx_csum(struct ixgbevf_ring *tx_ring,
  2137. struct sk_buff *skb, u32 tx_flags)
  2138. {
  2139. u32 vlan_macip_lens = 0;
  2140. u32 mss_l4len_idx = 0;
  2141. u32 type_tucmd = 0;
  2142. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  2143. u8 l4_hdr = 0;
  2144. switch (skb->protocol) {
  2145. case __constant_htons(ETH_P_IP):
  2146. vlan_macip_lens |= skb_network_header_len(skb);
  2147. type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
  2148. l4_hdr = ip_hdr(skb)->protocol;
  2149. break;
  2150. case __constant_htons(ETH_P_IPV6):
  2151. vlan_macip_lens |= skb_network_header_len(skb);
  2152. l4_hdr = ipv6_hdr(skb)->nexthdr;
  2153. break;
  2154. default:
  2155. if (unlikely(net_ratelimit())) {
  2156. dev_warn(tx_ring->dev,
  2157. "partial checksum but proto=%x!\n",
  2158. skb->protocol);
  2159. }
  2160. break;
  2161. }
  2162. switch (l4_hdr) {
  2163. case IPPROTO_TCP:
  2164. type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
  2165. mss_l4len_idx = tcp_hdrlen(skb) <<
  2166. IXGBE_ADVTXD_L4LEN_SHIFT;
  2167. break;
  2168. case IPPROTO_SCTP:
  2169. type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  2170. mss_l4len_idx = sizeof(struct sctphdr) <<
  2171. IXGBE_ADVTXD_L4LEN_SHIFT;
  2172. break;
  2173. case IPPROTO_UDP:
  2174. mss_l4len_idx = sizeof(struct udphdr) <<
  2175. IXGBE_ADVTXD_L4LEN_SHIFT;
  2176. break;
  2177. default:
  2178. if (unlikely(net_ratelimit())) {
  2179. dev_warn(tx_ring->dev,
  2180. "partial checksum but l4 proto=%x!\n",
  2181. l4_hdr);
  2182. }
  2183. break;
  2184. }
  2185. }
  2186. /* vlan_macip_lens: MACLEN, VLAN tag */
  2187. vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
  2188. vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  2189. ixgbevf_tx_ctxtdesc(tx_ring, vlan_macip_lens,
  2190. type_tucmd, mss_l4len_idx);
  2191. return (skb->ip_summed == CHECKSUM_PARTIAL);
  2192. }
  2193. static int ixgbevf_tx_map(struct ixgbevf_ring *tx_ring,
  2194. struct sk_buff *skb, u32 tx_flags,
  2195. unsigned int first)
  2196. {
  2197. struct ixgbevf_tx_buffer *tx_buffer_info;
  2198. unsigned int len;
  2199. unsigned int total = skb->len;
  2200. unsigned int offset = 0, size;
  2201. int count = 0;
  2202. unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
  2203. unsigned int f;
  2204. int i;
  2205. i = tx_ring->next_to_use;
  2206. len = min(skb_headlen(skb), total);
  2207. while (len) {
  2208. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  2209. size = min(len, (unsigned int)IXGBE_MAX_DATA_PER_TXD);
  2210. tx_buffer_info->length = size;
  2211. tx_buffer_info->mapped_as_page = false;
  2212. tx_buffer_info->dma = dma_map_single(tx_ring->dev,
  2213. skb->data + offset,
  2214. size, DMA_TO_DEVICE);
  2215. if (dma_mapping_error(tx_ring->dev, tx_buffer_info->dma))
  2216. goto dma_error;
  2217. tx_buffer_info->next_to_watch = i;
  2218. len -= size;
  2219. total -= size;
  2220. offset += size;
  2221. count++;
  2222. i++;
  2223. if (i == tx_ring->count)
  2224. i = 0;
  2225. }
  2226. for (f = 0; f < nr_frags; f++) {
  2227. const struct skb_frag_struct *frag;
  2228. frag = &skb_shinfo(skb)->frags[f];
  2229. len = min((unsigned int)skb_frag_size(frag), total);
  2230. offset = 0;
  2231. while (len) {
  2232. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  2233. size = min(len, (unsigned int)IXGBE_MAX_DATA_PER_TXD);
  2234. tx_buffer_info->length = size;
  2235. tx_buffer_info->dma =
  2236. skb_frag_dma_map(tx_ring->dev, frag,
  2237. offset, size, DMA_TO_DEVICE);
  2238. tx_buffer_info->mapped_as_page = true;
  2239. if (dma_mapping_error(tx_ring->dev,
  2240. tx_buffer_info->dma))
  2241. goto dma_error;
  2242. tx_buffer_info->next_to_watch = i;
  2243. len -= size;
  2244. total -= size;
  2245. offset += size;
  2246. count++;
  2247. i++;
  2248. if (i == tx_ring->count)
  2249. i = 0;
  2250. }
  2251. if (total == 0)
  2252. break;
  2253. }
  2254. if (i == 0)
  2255. i = tx_ring->count - 1;
  2256. else
  2257. i = i - 1;
  2258. tx_ring->tx_buffer_info[i].skb = skb;
  2259. tx_ring->tx_buffer_info[first].next_to_watch = i;
  2260. tx_ring->tx_buffer_info[first].time_stamp = jiffies;
  2261. return count;
  2262. dma_error:
  2263. dev_err(tx_ring->dev, "TX DMA map failed\n");
  2264. /* clear timestamp and dma mappings for failed tx_buffer_info map */
  2265. tx_buffer_info->dma = 0;
  2266. tx_buffer_info->next_to_watch = 0;
  2267. count--;
  2268. /* clear timestamp and dma mappings for remaining portion of packet */
  2269. while (count >= 0) {
  2270. count--;
  2271. i--;
  2272. if (i < 0)
  2273. i += tx_ring->count;
  2274. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  2275. ixgbevf_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
  2276. }
  2277. return count;
  2278. }
  2279. static void ixgbevf_tx_queue(struct ixgbevf_ring *tx_ring, int tx_flags,
  2280. int count, u32 paylen, u8 hdr_len)
  2281. {
  2282. union ixgbe_adv_tx_desc *tx_desc = NULL;
  2283. struct ixgbevf_tx_buffer *tx_buffer_info;
  2284. u32 olinfo_status = 0, cmd_type_len = 0;
  2285. unsigned int i;
  2286. u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
  2287. cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
  2288. cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
  2289. if (tx_flags & IXGBE_TX_FLAGS_VLAN)
  2290. cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
  2291. if (tx_flags & IXGBE_TX_FLAGS_CSUM)
  2292. olinfo_status |= IXGBE_ADVTXD_POPTS_TXSM;
  2293. if (tx_flags & IXGBE_TX_FLAGS_TSO) {
  2294. cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
  2295. /* use index 1 context for tso */
  2296. olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
  2297. if (tx_flags & IXGBE_TX_FLAGS_IPV4)
  2298. olinfo_status |= IXGBE_ADVTXD_POPTS_IXSM;
  2299. }
  2300. /*
  2301. * Check Context must be set if Tx switch is enabled, which it
  2302. * always is for case where virtual functions are running
  2303. */
  2304. olinfo_status |= IXGBE_ADVTXD_CC;
  2305. olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
  2306. i = tx_ring->next_to_use;
  2307. while (count--) {
  2308. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  2309. tx_desc = IXGBEVF_TX_DESC(tx_ring, i);
  2310. tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
  2311. tx_desc->read.cmd_type_len =
  2312. cpu_to_le32(cmd_type_len | tx_buffer_info->length);
  2313. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  2314. i++;
  2315. if (i == tx_ring->count)
  2316. i = 0;
  2317. }
  2318. tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
  2319. tx_ring->next_to_use = i;
  2320. }
  2321. static int __ixgbevf_maybe_stop_tx(struct ixgbevf_ring *tx_ring, int size)
  2322. {
  2323. struct ixgbevf_adapter *adapter = netdev_priv(tx_ring->netdev);
  2324. netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
  2325. /* Herbert's original patch had:
  2326. * smp_mb__after_netif_stop_queue();
  2327. * but since that doesn't exist yet, just open code it. */
  2328. smp_mb();
  2329. /* We need to check again in a case another CPU has just
  2330. * made room available. */
  2331. if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
  2332. return -EBUSY;
  2333. /* A reprieve! - use start_queue because it doesn't call schedule */
  2334. netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
  2335. ++adapter->restart_queue;
  2336. return 0;
  2337. }
  2338. static int ixgbevf_maybe_stop_tx(struct ixgbevf_ring *tx_ring, int size)
  2339. {
  2340. if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
  2341. return 0;
  2342. return __ixgbevf_maybe_stop_tx(tx_ring, size);
  2343. }
  2344. static int ixgbevf_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
  2345. {
  2346. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2347. struct ixgbevf_ring *tx_ring;
  2348. unsigned int first;
  2349. unsigned int tx_flags = 0;
  2350. u8 hdr_len = 0;
  2351. int r_idx = 0, tso;
  2352. u16 count = TXD_USE_COUNT(skb_headlen(skb));
  2353. #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
  2354. unsigned short f;
  2355. #endif
  2356. tx_ring = &adapter->tx_ring[r_idx];
  2357. /*
  2358. * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
  2359. * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
  2360. * + 2 desc gap to keep tail from touching head,
  2361. * + 1 desc for context descriptor,
  2362. * otherwise try next time
  2363. */
  2364. #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
  2365. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
  2366. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
  2367. #else
  2368. count += skb_shinfo(skb)->nr_frags;
  2369. #endif
  2370. if (ixgbevf_maybe_stop_tx(tx_ring, count + 3)) {
  2371. adapter->tx_busy++;
  2372. return NETDEV_TX_BUSY;
  2373. }
  2374. if (vlan_tx_tag_present(skb)) {
  2375. tx_flags |= vlan_tx_tag_get(skb);
  2376. tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
  2377. tx_flags |= IXGBE_TX_FLAGS_VLAN;
  2378. }
  2379. first = tx_ring->next_to_use;
  2380. if (skb->protocol == htons(ETH_P_IP))
  2381. tx_flags |= IXGBE_TX_FLAGS_IPV4;
  2382. tso = ixgbevf_tso(tx_ring, skb, tx_flags, &hdr_len);
  2383. if (tso < 0) {
  2384. dev_kfree_skb_any(skb);
  2385. return NETDEV_TX_OK;
  2386. }
  2387. if (tso)
  2388. tx_flags |= IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_CSUM;
  2389. else if (ixgbevf_tx_csum(tx_ring, skb, tx_flags))
  2390. tx_flags |= IXGBE_TX_FLAGS_CSUM;
  2391. ixgbevf_tx_queue(tx_ring, tx_flags,
  2392. ixgbevf_tx_map(tx_ring, skb, tx_flags, first),
  2393. skb->len, hdr_len);
  2394. /*
  2395. * Force memory writes to complete before letting h/w
  2396. * know there are new descriptors to fetch. (Only
  2397. * applicable for weak-ordered memory model archs,
  2398. * such as IA-64).
  2399. */
  2400. wmb();
  2401. writel(tx_ring->next_to_use, adapter->hw.hw_addr + tx_ring->tail);
  2402. ixgbevf_maybe_stop_tx(tx_ring, DESC_NEEDED);
  2403. return NETDEV_TX_OK;
  2404. }
  2405. /**
  2406. * ixgbevf_set_mac - Change the Ethernet Address of the NIC
  2407. * @netdev: network interface device structure
  2408. * @p: pointer to an address structure
  2409. *
  2410. * Returns 0 on success, negative on failure
  2411. **/
  2412. static int ixgbevf_set_mac(struct net_device *netdev, void *p)
  2413. {
  2414. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2415. struct ixgbe_hw *hw = &adapter->hw;
  2416. struct sockaddr *addr = p;
  2417. if (!is_valid_ether_addr(addr->sa_data))
  2418. return -EADDRNOTAVAIL;
  2419. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  2420. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  2421. spin_lock(&adapter->mbx_lock);
  2422. if (hw->mac.ops.set_rar)
  2423. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
  2424. spin_unlock(&adapter->mbx_lock);
  2425. return 0;
  2426. }
  2427. /**
  2428. * ixgbevf_change_mtu - Change the Maximum Transfer Unit
  2429. * @netdev: network interface device structure
  2430. * @new_mtu: new value for maximum frame size
  2431. *
  2432. * Returns 0 on success, negative on failure
  2433. **/
  2434. static int ixgbevf_change_mtu(struct net_device *netdev, int new_mtu)
  2435. {
  2436. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2437. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  2438. int max_possible_frame = MAXIMUM_ETHERNET_VLAN_SIZE;
  2439. if (adapter->hw.mac.type == ixgbe_mac_X540_vf)
  2440. max_possible_frame = IXGBE_MAX_JUMBO_FRAME_SIZE;
  2441. /* MTU < 68 is an error and causes problems on some kernels */
  2442. if ((new_mtu < 68) || (max_frame > max_possible_frame))
  2443. return -EINVAL;
  2444. hw_dbg(&adapter->hw, "changing MTU from %d to %d\n",
  2445. netdev->mtu, new_mtu);
  2446. /* must set new MTU before calling down or up */
  2447. netdev->mtu = new_mtu;
  2448. if (netif_running(netdev))
  2449. ixgbevf_reinit_locked(adapter);
  2450. return 0;
  2451. }
  2452. static int ixgbevf_suspend(struct pci_dev *pdev, pm_message_t state)
  2453. {
  2454. struct net_device *netdev = pci_get_drvdata(pdev);
  2455. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2456. #ifdef CONFIG_PM
  2457. int retval = 0;
  2458. #endif
  2459. netif_device_detach(netdev);
  2460. if (netif_running(netdev)) {
  2461. rtnl_lock();
  2462. ixgbevf_down(adapter);
  2463. ixgbevf_free_irq(adapter);
  2464. ixgbevf_free_all_tx_resources(adapter);
  2465. ixgbevf_free_all_rx_resources(adapter);
  2466. rtnl_unlock();
  2467. }
  2468. ixgbevf_clear_interrupt_scheme(adapter);
  2469. #ifdef CONFIG_PM
  2470. retval = pci_save_state(pdev);
  2471. if (retval)
  2472. return retval;
  2473. #endif
  2474. pci_disable_device(pdev);
  2475. return 0;
  2476. }
  2477. #ifdef CONFIG_PM
  2478. static int ixgbevf_resume(struct pci_dev *pdev)
  2479. {
  2480. struct ixgbevf_adapter *adapter = pci_get_drvdata(pdev);
  2481. struct net_device *netdev = adapter->netdev;
  2482. u32 err;
  2483. pci_set_power_state(pdev, PCI_D0);
  2484. pci_restore_state(pdev);
  2485. /*
  2486. * pci_restore_state clears dev->state_saved so call
  2487. * pci_save_state to restore it.
  2488. */
  2489. pci_save_state(pdev);
  2490. err = pci_enable_device_mem(pdev);
  2491. if (err) {
  2492. dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
  2493. return err;
  2494. }
  2495. pci_set_master(pdev);
  2496. rtnl_lock();
  2497. err = ixgbevf_init_interrupt_scheme(adapter);
  2498. rtnl_unlock();
  2499. if (err) {
  2500. dev_err(&pdev->dev, "Cannot initialize interrupts\n");
  2501. return err;
  2502. }
  2503. ixgbevf_reset(adapter);
  2504. if (netif_running(netdev)) {
  2505. err = ixgbevf_open(netdev);
  2506. if (err)
  2507. return err;
  2508. }
  2509. netif_device_attach(netdev);
  2510. return err;
  2511. }
  2512. #endif /* CONFIG_PM */
  2513. static void ixgbevf_shutdown(struct pci_dev *pdev)
  2514. {
  2515. ixgbevf_suspend(pdev, PMSG_SUSPEND);
  2516. }
  2517. static struct rtnl_link_stats64 *ixgbevf_get_stats(struct net_device *netdev,
  2518. struct rtnl_link_stats64 *stats)
  2519. {
  2520. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2521. unsigned int start;
  2522. u64 bytes, packets;
  2523. const struct ixgbevf_ring *ring;
  2524. int i;
  2525. ixgbevf_update_stats(adapter);
  2526. stats->multicast = adapter->stats.vfmprc - adapter->stats.base_vfmprc;
  2527. for (i = 0; i < adapter->num_rx_queues; i++) {
  2528. ring = &adapter->rx_ring[i];
  2529. do {
  2530. start = u64_stats_fetch_begin_bh(&ring->syncp);
  2531. bytes = ring->total_bytes;
  2532. packets = ring->total_packets;
  2533. } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
  2534. stats->rx_bytes += bytes;
  2535. stats->rx_packets += packets;
  2536. }
  2537. for (i = 0; i < adapter->num_tx_queues; i++) {
  2538. ring = &adapter->tx_ring[i];
  2539. do {
  2540. start = u64_stats_fetch_begin_bh(&ring->syncp);
  2541. bytes = ring->total_bytes;
  2542. packets = ring->total_packets;
  2543. } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
  2544. stats->tx_bytes += bytes;
  2545. stats->tx_packets += packets;
  2546. }
  2547. return stats;
  2548. }
  2549. static const struct net_device_ops ixgbevf_netdev_ops = {
  2550. .ndo_open = ixgbevf_open,
  2551. .ndo_stop = ixgbevf_close,
  2552. .ndo_start_xmit = ixgbevf_xmit_frame,
  2553. .ndo_set_rx_mode = ixgbevf_set_rx_mode,
  2554. .ndo_get_stats64 = ixgbevf_get_stats,
  2555. .ndo_validate_addr = eth_validate_addr,
  2556. .ndo_set_mac_address = ixgbevf_set_mac,
  2557. .ndo_change_mtu = ixgbevf_change_mtu,
  2558. .ndo_tx_timeout = ixgbevf_tx_timeout,
  2559. .ndo_vlan_rx_add_vid = ixgbevf_vlan_rx_add_vid,
  2560. .ndo_vlan_rx_kill_vid = ixgbevf_vlan_rx_kill_vid,
  2561. };
  2562. static void ixgbevf_assign_netdev_ops(struct net_device *dev)
  2563. {
  2564. dev->netdev_ops = &ixgbevf_netdev_ops;
  2565. ixgbevf_set_ethtool_ops(dev);
  2566. dev->watchdog_timeo = 5 * HZ;
  2567. }
  2568. /**
  2569. * ixgbevf_probe - Device Initialization Routine
  2570. * @pdev: PCI device information struct
  2571. * @ent: entry in ixgbevf_pci_tbl
  2572. *
  2573. * Returns 0 on success, negative on failure
  2574. *
  2575. * ixgbevf_probe initializes an adapter identified by a pci_dev structure.
  2576. * The OS initialization, configuring of the adapter private structure,
  2577. * and a hardware reset occur.
  2578. **/
  2579. static int __devinit ixgbevf_probe(struct pci_dev *pdev,
  2580. const struct pci_device_id *ent)
  2581. {
  2582. struct net_device *netdev;
  2583. struct ixgbevf_adapter *adapter = NULL;
  2584. struct ixgbe_hw *hw = NULL;
  2585. const struct ixgbevf_info *ii = ixgbevf_info_tbl[ent->driver_data];
  2586. static int cards_found;
  2587. int err, pci_using_dac;
  2588. err = pci_enable_device(pdev);
  2589. if (err)
  2590. return err;
  2591. if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
  2592. !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
  2593. pci_using_dac = 1;
  2594. } else {
  2595. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  2596. if (err) {
  2597. err = dma_set_coherent_mask(&pdev->dev,
  2598. DMA_BIT_MASK(32));
  2599. if (err) {
  2600. dev_err(&pdev->dev, "No usable DMA "
  2601. "configuration, aborting\n");
  2602. goto err_dma;
  2603. }
  2604. }
  2605. pci_using_dac = 0;
  2606. }
  2607. err = pci_request_regions(pdev, ixgbevf_driver_name);
  2608. if (err) {
  2609. dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
  2610. goto err_pci_reg;
  2611. }
  2612. pci_set_master(pdev);
  2613. netdev = alloc_etherdev_mq(sizeof(struct ixgbevf_adapter),
  2614. MAX_TX_QUEUES);
  2615. if (!netdev) {
  2616. err = -ENOMEM;
  2617. goto err_alloc_etherdev;
  2618. }
  2619. SET_NETDEV_DEV(netdev, &pdev->dev);
  2620. pci_set_drvdata(pdev, netdev);
  2621. adapter = netdev_priv(netdev);
  2622. adapter->netdev = netdev;
  2623. adapter->pdev = pdev;
  2624. hw = &adapter->hw;
  2625. hw->back = adapter;
  2626. adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
  2627. /*
  2628. * call save state here in standalone driver because it relies on
  2629. * adapter struct to exist, and needs to call netdev_priv
  2630. */
  2631. pci_save_state(pdev);
  2632. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  2633. pci_resource_len(pdev, 0));
  2634. if (!hw->hw_addr) {
  2635. err = -EIO;
  2636. goto err_ioremap;
  2637. }
  2638. ixgbevf_assign_netdev_ops(netdev);
  2639. adapter->bd_number = cards_found;
  2640. /* Setup hw api */
  2641. memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
  2642. hw->mac.type = ii->mac;
  2643. memcpy(&hw->mbx.ops, &ixgbevf_mbx_ops,
  2644. sizeof(struct ixgbe_mbx_operations));
  2645. /* setup the private structure */
  2646. err = ixgbevf_sw_init(adapter);
  2647. if (err)
  2648. goto err_sw_init;
  2649. /* The HW MAC address was set and/or determined in sw_init */
  2650. memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
  2651. if (!is_valid_ether_addr(netdev->dev_addr)) {
  2652. pr_err("invalid MAC address\n");
  2653. err = -EIO;
  2654. goto err_sw_init;
  2655. }
  2656. netdev->hw_features = NETIF_F_SG |
  2657. NETIF_F_IP_CSUM |
  2658. NETIF_F_IPV6_CSUM |
  2659. NETIF_F_TSO |
  2660. NETIF_F_TSO6 |
  2661. NETIF_F_RXCSUM;
  2662. netdev->features = netdev->hw_features |
  2663. NETIF_F_HW_VLAN_TX |
  2664. NETIF_F_HW_VLAN_RX |
  2665. NETIF_F_HW_VLAN_FILTER;
  2666. netdev->vlan_features |= NETIF_F_TSO;
  2667. netdev->vlan_features |= NETIF_F_TSO6;
  2668. netdev->vlan_features |= NETIF_F_IP_CSUM;
  2669. netdev->vlan_features |= NETIF_F_IPV6_CSUM;
  2670. netdev->vlan_features |= NETIF_F_SG;
  2671. if (pci_using_dac)
  2672. netdev->features |= NETIF_F_HIGHDMA;
  2673. netdev->priv_flags |= IFF_UNICAST_FLT;
  2674. init_timer(&adapter->watchdog_timer);
  2675. adapter->watchdog_timer.function = ixgbevf_watchdog;
  2676. adapter->watchdog_timer.data = (unsigned long)adapter;
  2677. INIT_WORK(&adapter->reset_task, ixgbevf_reset_task);
  2678. INIT_WORK(&adapter->watchdog_task, ixgbevf_watchdog_task);
  2679. err = ixgbevf_init_interrupt_scheme(adapter);
  2680. if (err)
  2681. goto err_sw_init;
  2682. /* pick up the PCI bus settings for reporting later */
  2683. if (hw->mac.ops.get_bus_info)
  2684. hw->mac.ops.get_bus_info(hw);
  2685. strcpy(netdev->name, "eth%d");
  2686. err = register_netdev(netdev);
  2687. if (err)
  2688. goto err_register;
  2689. netif_carrier_off(netdev);
  2690. ixgbevf_init_last_counter_stats(adapter);
  2691. /* print the MAC address */
  2692. hw_dbg(hw, "%pM\n", netdev->dev_addr);
  2693. hw_dbg(hw, "MAC: %d\n", hw->mac.type);
  2694. hw_dbg(hw, "Intel(R) 82599 Virtual Function\n");
  2695. cards_found++;
  2696. return 0;
  2697. err_register:
  2698. ixgbevf_clear_interrupt_scheme(adapter);
  2699. err_sw_init:
  2700. ixgbevf_reset_interrupt_capability(adapter);
  2701. iounmap(hw->hw_addr);
  2702. err_ioremap:
  2703. free_netdev(netdev);
  2704. err_alloc_etherdev:
  2705. pci_release_regions(pdev);
  2706. err_pci_reg:
  2707. err_dma:
  2708. pci_disable_device(pdev);
  2709. return err;
  2710. }
  2711. /**
  2712. * ixgbevf_remove - Device Removal Routine
  2713. * @pdev: PCI device information struct
  2714. *
  2715. * ixgbevf_remove is called by the PCI subsystem to alert the driver
  2716. * that it should release a PCI device. The could be caused by a
  2717. * Hot-Plug event, or because the driver is going to be removed from
  2718. * memory.
  2719. **/
  2720. static void __devexit ixgbevf_remove(struct pci_dev *pdev)
  2721. {
  2722. struct net_device *netdev = pci_get_drvdata(pdev);
  2723. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2724. set_bit(__IXGBEVF_DOWN, &adapter->state);
  2725. del_timer_sync(&adapter->watchdog_timer);
  2726. cancel_work_sync(&adapter->reset_task);
  2727. cancel_work_sync(&adapter->watchdog_task);
  2728. if (netdev->reg_state == NETREG_REGISTERED)
  2729. unregister_netdev(netdev);
  2730. ixgbevf_clear_interrupt_scheme(adapter);
  2731. ixgbevf_reset_interrupt_capability(adapter);
  2732. iounmap(adapter->hw.hw_addr);
  2733. pci_release_regions(pdev);
  2734. hw_dbg(&adapter->hw, "Remove complete\n");
  2735. kfree(adapter->tx_ring);
  2736. kfree(adapter->rx_ring);
  2737. free_netdev(netdev);
  2738. pci_disable_device(pdev);
  2739. }
  2740. /**
  2741. * ixgbevf_io_error_detected - called when PCI error is detected
  2742. * @pdev: Pointer to PCI device
  2743. * @state: The current pci connection state
  2744. *
  2745. * This function is called after a PCI bus error affecting
  2746. * this device has been detected.
  2747. */
  2748. static pci_ers_result_t ixgbevf_io_error_detected(struct pci_dev *pdev,
  2749. pci_channel_state_t state)
  2750. {
  2751. struct net_device *netdev = pci_get_drvdata(pdev);
  2752. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2753. netif_device_detach(netdev);
  2754. if (state == pci_channel_io_perm_failure)
  2755. return PCI_ERS_RESULT_DISCONNECT;
  2756. if (netif_running(netdev))
  2757. ixgbevf_down(adapter);
  2758. pci_disable_device(pdev);
  2759. /* Request a slot slot reset. */
  2760. return PCI_ERS_RESULT_NEED_RESET;
  2761. }
  2762. /**
  2763. * ixgbevf_io_slot_reset - called after the pci bus has been reset.
  2764. * @pdev: Pointer to PCI device
  2765. *
  2766. * Restart the card from scratch, as if from a cold-boot. Implementation
  2767. * resembles the first-half of the ixgbevf_resume routine.
  2768. */
  2769. static pci_ers_result_t ixgbevf_io_slot_reset(struct pci_dev *pdev)
  2770. {
  2771. struct net_device *netdev = pci_get_drvdata(pdev);
  2772. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2773. if (pci_enable_device_mem(pdev)) {
  2774. dev_err(&pdev->dev,
  2775. "Cannot re-enable PCI device after reset.\n");
  2776. return PCI_ERS_RESULT_DISCONNECT;
  2777. }
  2778. pci_set_master(pdev);
  2779. ixgbevf_reset(adapter);
  2780. return PCI_ERS_RESULT_RECOVERED;
  2781. }
  2782. /**
  2783. * ixgbevf_io_resume - called when traffic can start flowing again.
  2784. * @pdev: Pointer to PCI device
  2785. *
  2786. * This callback is called when the error recovery driver tells us that
  2787. * its OK to resume normal operation. Implementation resembles the
  2788. * second-half of the ixgbevf_resume routine.
  2789. */
  2790. static void ixgbevf_io_resume(struct pci_dev *pdev)
  2791. {
  2792. struct net_device *netdev = pci_get_drvdata(pdev);
  2793. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2794. if (netif_running(netdev))
  2795. ixgbevf_up(adapter);
  2796. netif_device_attach(netdev);
  2797. }
  2798. /* PCI Error Recovery (ERS) */
  2799. static struct pci_error_handlers ixgbevf_err_handler = {
  2800. .error_detected = ixgbevf_io_error_detected,
  2801. .slot_reset = ixgbevf_io_slot_reset,
  2802. .resume = ixgbevf_io_resume,
  2803. };
  2804. static struct pci_driver ixgbevf_driver = {
  2805. .name = ixgbevf_driver_name,
  2806. .id_table = ixgbevf_pci_tbl,
  2807. .probe = ixgbevf_probe,
  2808. .remove = __devexit_p(ixgbevf_remove),
  2809. #ifdef CONFIG_PM
  2810. /* Power Management Hooks */
  2811. .suspend = ixgbevf_suspend,
  2812. .resume = ixgbevf_resume,
  2813. #endif
  2814. .shutdown = ixgbevf_shutdown,
  2815. .err_handler = &ixgbevf_err_handler
  2816. };
  2817. /**
  2818. * ixgbevf_init_module - Driver Registration Routine
  2819. *
  2820. * ixgbevf_init_module is the first routine called when the driver is
  2821. * loaded. All it does is register with the PCI subsystem.
  2822. **/
  2823. static int __init ixgbevf_init_module(void)
  2824. {
  2825. int ret;
  2826. pr_info("%s - version %s\n", ixgbevf_driver_string,
  2827. ixgbevf_driver_version);
  2828. pr_info("%s\n", ixgbevf_copyright);
  2829. ret = pci_register_driver(&ixgbevf_driver);
  2830. return ret;
  2831. }
  2832. module_init(ixgbevf_init_module);
  2833. /**
  2834. * ixgbevf_exit_module - Driver Exit Cleanup Routine
  2835. *
  2836. * ixgbevf_exit_module is called just before the driver is removed
  2837. * from memory.
  2838. **/
  2839. static void __exit ixgbevf_exit_module(void)
  2840. {
  2841. pci_unregister_driver(&ixgbevf_driver);
  2842. }
  2843. #ifdef DEBUG
  2844. /**
  2845. * ixgbevf_get_hw_dev_name - return device name string
  2846. * used by hardware layer to print debugging information
  2847. **/
  2848. char *ixgbevf_get_hw_dev_name(struct ixgbe_hw *hw)
  2849. {
  2850. struct ixgbevf_adapter *adapter = hw->back;
  2851. return adapter->netdev->name;
  2852. }
  2853. #endif
  2854. module_exit(ixgbevf_exit_module);
  2855. /* ixgbevf_main.c */