i40evf_main.c 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
  4. * Copyright(c) 2013 - 2015 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. #include "i40evf.h"
  27. #include "i40e_prototype.h"
  28. static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter);
  29. static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter);
  30. static int i40evf_close(struct net_device *netdev);
  31. char i40evf_driver_name[] = "i40evf";
  32. static const char i40evf_driver_string[] =
  33. "Intel(R) XL710/X710 Virtual Function Network Driver";
  34. #define DRV_VERSION "1.4.1"
  35. const char i40evf_driver_version[] = DRV_VERSION;
  36. static const char i40evf_copyright[] =
  37. "Copyright (c) 2013 - 2015 Intel Corporation.";
  38. /* i40evf_pci_tbl - PCI Device ID Table
  39. *
  40. * Wildcard entries (PCI_ANY_ID) should come last
  41. * Last entry must be all 0s
  42. *
  43. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  44. * Class, Class Mask, private data (not used) }
  45. */
  46. static const struct pci_device_id i40evf_pci_tbl[] = {
  47. {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0},
  48. {PCI_VDEVICE(INTEL, I40E_DEV_ID_X722_VF), 0},
  49. /* required last entry */
  50. {0, }
  51. };
  52. MODULE_DEVICE_TABLE(pci, i40evf_pci_tbl);
  53. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  54. MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
  55. MODULE_LICENSE("GPL");
  56. MODULE_VERSION(DRV_VERSION);
  57. /**
  58. * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code
  59. * @hw: pointer to the HW structure
  60. * @mem: ptr to mem struct to fill out
  61. * @size: size of memory requested
  62. * @alignment: what to align the allocation to
  63. **/
  64. i40e_status i40evf_allocate_dma_mem_d(struct i40e_hw *hw,
  65. struct i40e_dma_mem *mem,
  66. u64 size, u32 alignment)
  67. {
  68. struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
  69. if (!mem)
  70. return I40E_ERR_PARAM;
  71. mem->size = ALIGN(size, alignment);
  72. mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size,
  73. (dma_addr_t *)&mem->pa, GFP_KERNEL);
  74. if (mem->va)
  75. return 0;
  76. else
  77. return I40E_ERR_NO_MEMORY;
  78. }
  79. /**
  80. * i40evf_free_dma_mem_d - OS specific memory free for shared code
  81. * @hw: pointer to the HW structure
  82. * @mem: ptr to mem struct to free
  83. **/
  84. i40e_status i40evf_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
  85. {
  86. struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
  87. if (!mem || !mem->va)
  88. return I40E_ERR_PARAM;
  89. dma_free_coherent(&adapter->pdev->dev, mem->size,
  90. mem->va, (dma_addr_t)mem->pa);
  91. return 0;
  92. }
  93. /**
  94. * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code
  95. * @hw: pointer to the HW structure
  96. * @mem: ptr to mem struct to fill out
  97. * @size: size of memory requested
  98. **/
  99. i40e_status i40evf_allocate_virt_mem_d(struct i40e_hw *hw,
  100. struct i40e_virt_mem *mem, u32 size)
  101. {
  102. if (!mem)
  103. return I40E_ERR_PARAM;
  104. mem->size = size;
  105. mem->va = kzalloc(size, GFP_KERNEL);
  106. if (mem->va)
  107. return 0;
  108. else
  109. return I40E_ERR_NO_MEMORY;
  110. }
  111. /**
  112. * i40evf_free_virt_mem_d - OS specific memory free for shared code
  113. * @hw: pointer to the HW structure
  114. * @mem: ptr to mem struct to free
  115. **/
  116. i40e_status i40evf_free_virt_mem_d(struct i40e_hw *hw,
  117. struct i40e_virt_mem *mem)
  118. {
  119. if (!mem)
  120. return I40E_ERR_PARAM;
  121. /* it's ok to kfree a NULL pointer */
  122. kfree(mem->va);
  123. return 0;
  124. }
  125. /**
  126. * i40evf_debug_d - OS dependent version of debug printing
  127. * @hw: pointer to the HW structure
  128. * @mask: debug level mask
  129. * @fmt_str: printf-type format description
  130. **/
  131. void i40evf_debug_d(void *hw, u32 mask, char *fmt_str, ...)
  132. {
  133. char buf[512];
  134. va_list argptr;
  135. if (!(mask & ((struct i40e_hw *)hw)->debug_mask))
  136. return;
  137. va_start(argptr, fmt_str);
  138. vsnprintf(buf, sizeof(buf), fmt_str, argptr);
  139. va_end(argptr);
  140. /* the debug string is already formatted with a newline */
  141. pr_info("%s", buf);
  142. }
  143. /**
  144. * i40evf_tx_timeout - Respond to a Tx Hang
  145. * @netdev: network interface device structure
  146. **/
  147. static void i40evf_tx_timeout(struct net_device *netdev)
  148. {
  149. struct i40evf_adapter *adapter = netdev_priv(netdev);
  150. adapter->tx_timeout_count++;
  151. if (!(adapter->flags & (I40EVF_FLAG_RESET_PENDING |
  152. I40EVF_FLAG_RESET_NEEDED))) {
  153. adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
  154. schedule_work(&adapter->reset_task);
  155. }
  156. }
  157. /**
  158. * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
  159. * @adapter: board private structure
  160. **/
  161. static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter)
  162. {
  163. struct i40e_hw *hw = &adapter->hw;
  164. wr32(hw, I40E_VFINT_DYN_CTL01, 0);
  165. /* read flush */
  166. rd32(hw, I40E_VFGEN_RSTAT);
  167. synchronize_irq(adapter->msix_entries[0].vector);
  168. }
  169. /**
  170. * i40evf_misc_irq_enable - Enable default interrupt generation settings
  171. * @adapter: board private structure
  172. **/
  173. static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter)
  174. {
  175. struct i40e_hw *hw = &adapter->hw;
  176. wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK |
  177. I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
  178. wr32(hw, I40E_VFINT_ICR0_ENA1, I40E_VFINT_ICR0_ENA1_ADMINQ_MASK);
  179. /* read flush */
  180. rd32(hw, I40E_VFGEN_RSTAT);
  181. }
  182. /**
  183. * i40evf_irq_disable - Mask off interrupt generation on the NIC
  184. * @adapter: board private structure
  185. **/
  186. static void i40evf_irq_disable(struct i40evf_adapter *adapter)
  187. {
  188. int i;
  189. struct i40e_hw *hw = &adapter->hw;
  190. if (!adapter->msix_entries)
  191. return;
  192. for (i = 1; i < adapter->num_msix_vectors; i++) {
  193. wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), 0);
  194. synchronize_irq(adapter->msix_entries[i].vector);
  195. }
  196. /* read flush */
  197. rd32(hw, I40E_VFGEN_RSTAT);
  198. }
  199. /**
  200. * i40evf_irq_enable_queues - Enable interrupt for specified queues
  201. * @adapter: board private structure
  202. * @mask: bitmap of queues to enable
  203. **/
  204. void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask)
  205. {
  206. struct i40e_hw *hw = &adapter->hw;
  207. int i;
  208. for (i = 1; i < adapter->num_msix_vectors; i++) {
  209. if (mask & BIT(i - 1)) {
  210. wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1),
  211. I40E_VFINT_DYN_CTLN1_INTENA_MASK |
  212. I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
  213. I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK);
  214. }
  215. }
  216. }
  217. /**
  218. * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
  219. * @adapter: board private structure
  220. * @mask: bitmap of vectors to trigger
  221. **/
  222. static void i40evf_fire_sw_int(struct i40evf_adapter *adapter, u32 mask)
  223. {
  224. struct i40e_hw *hw = &adapter->hw;
  225. int i;
  226. uint32_t dyn_ctl;
  227. if (mask & 1) {
  228. dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTL01);
  229. dyn_ctl |= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK |
  230. I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
  231. I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK;
  232. wr32(hw, I40E_VFINT_DYN_CTL01, dyn_ctl);
  233. }
  234. for (i = 1; i < adapter->num_msix_vectors; i++) {
  235. if (mask & BIT(i)) {
  236. dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTLN1(i - 1));
  237. dyn_ctl |= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK |
  238. I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
  239. I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK;
  240. wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), dyn_ctl);
  241. }
  242. }
  243. }
  244. /**
  245. * i40evf_irq_enable - Enable default interrupt generation settings
  246. * @adapter: board private structure
  247. * @flush: boolean value whether to run rd32()
  248. **/
  249. void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush)
  250. {
  251. struct i40e_hw *hw = &adapter->hw;
  252. i40evf_misc_irq_enable(adapter);
  253. i40evf_irq_enable_queues(adapter, ~0);
  254. if (flush)
  255. rd32(hw, I40E_VFGEN_RSTAT);
  256. }
  257. /**
  258. * i40evf_msix_aq - Interrupt handler for vector 0
  259. * @irq: interrupt number
  260. * @data: pointer to netdev
  261. **/
  262. static irqreturn_t i40evf_msix_aq(int irq, void *data)
  263. {
  264. struct net_device *netdev = data;
  265. struct i40evf_adapter *adapter = netdev_priv(netdev);
  266. struct i40e_hw *hw = &adapter->hw;
  267. u32 val;
  268. /* handle non-queue interrupts, these reads clear the registers */
  269. val = rd32(hw, I40E_VFINT_ICR01);
  270. val = rd32(hw, I40E_VFINT_ICR0_ENA1);
  271. val = rd32(hw, I40E_VFINT_DYN_CTL01) |
  272. I40E_VFINT_DYN_CTL01_CLEARPBA_MASK;
  273. wr32(hw, I40E_VFINT_DYN_CTL01, val);
  274. /* schedule work on the private workqueue */
  275. schedule_work(&adapter->adminq_task);
  276. return IRQ_HANDLED;
  277. }
  278. /**
  279. * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
  280. * @irq: interrupt number
  281. * @data: pointer to a q_vector
  282. **/
  283. static irqreturn_t i40evf_msix_clean_rings(int irq, void *data)
  284. {
  285. struct i40e_q_vector *q_vector = data;
  286. if (!q_vector->tx.ring && !q_vector->rx.ring)
  287. return IRQ_HANDLED;
  288. napi_schedule_irqoff(&q_vector->napi);
  289. return IRQ_HANDLED;
  290. }
  291. /**
  292. * i40evf_map_vector_to_rxq - associate irqs with rx queues
  293. * @adapter: board private structure
  294. * @v_idx: interrupt number
  295. * @r_idx: queue number
  296. **/
  297. static void
  298. i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx)
  299. {
  300. struct i40e_q_vector *q_vector = &adapter->q_vectors[v_idx];
  301. struct i40e_ring *rx_ring = &adapter->rx_rings[r_idx];
  302. rx_ring->q_vector = q_vector;
  303. rx_ring->next = q_vector->rx.ring;
  304. rx_ring->vsi = &adapter->vsi;
  305. q_vector->rx.ring = rx_ring;
  306. q_vector->rx.count++;
  307. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  308. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  309. }
  310. /**
  311. * i40evf_map_vector_to_txq - associate irqs with tx queues
  312. * @adapter: board private structure
  313. * @v_idx: interrupt number
  314. * @t_idx: queue number
  315. **/
  316. static void
  317. i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx)
  318. {
  319. struct i40e_q_vector *q_vector = &adapter->q_vectors[v_idx];
  320. struct i40e_ring *tx_ring = &adapter->tx_rings[t_idx];
  321. tx_ring->q_vector = q_vector;
  322. tx_ring->next = q_vector->tx.ring;
  323. tx_ring->vsi = &adapter->vsi;
  324. q_vector->tx.ring = tx_ring;
  325. q_vector->tx.count++;
  326. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  327. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  328. q_vector->num_ringpairs++;
  329. q_vector->ring_mask |= BIT(t_idx);
  330. }
  331. /**
  332. * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
  333. * @adapter: board private structure to initialize
  334. *
  335. * This function maps descriptor rings to the queue-specific vectors
  336. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  337. * one vector per ring/queue, but on a constrained vector budget, we
  338. * group the rings as "efficiently" as possible. You would add new
  339. * mapping configurations in here.
  340. **/
  341. static int i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter)
  342. {
  343. int q_vectors;
  344. int v_start = 0;
  345. int rxr_idx = 0, txr_idx = 0;
  346. int rxr_remaining = adapter->num_active_queues;
  347. int txr_remaining = adapter->num_active_queues;
  348. int i, j;
  349. int rqpv, tqpv;
  350. int err = 0;
  351. q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  352. /* The ideal configuration...
  353. * We have enough vectors to map one per queue.
  354. */
  355. if (q_vectors >= (rxr_remaining * 2)) {
  356. for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
  357. i40evf_map_vector_to_rxq(adapter, v_start, rxr_idx);
  358. for (; txr_idx < txr_remaining; v_start++, txr_idx++)
  359. i40evf_map_vector_to_txq(adapter, v_start, txr_idx);
  360. goto out;
  361. }
  362. /* If we don't have enough vectors for a 1-to-1
  363. * mapping, we'll have to group them so there are
  364. * multiple queues per vector.
  365. * Re-adjusting *qpv takes care of the remainder.
  366. */
  367. for (i = v_start; i < q_vectors; i++) {
  368. rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
  369. for (j = 0; j < rqpv; j++) {
  370. i40evf_map_vector_to_rxq(adapter, i, rxr_idx);
  371. rxr_idx++;
  372. rxr_remaining--;
  373. }
  374. }
  375. for (i = v_start; i < q_vectors; i++) {
  376. tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
  377. for (j = 0; j < tqpv; j++) {
  378. i40evf_map_vector_to_txq(adapter, i, txr_idx);
  379. txr_idx++;
  380. txr_remaining--;
  381. }
  382. }
  383. out:
  384. adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
  385. return err;
  386. }
  387. #ifdef CONFIG_NET_POLL_CONTROLLER
  388. /**
  389. * i40evf_netpoll - A Polling 'interrupt' handler
  390. * @netdev: network interface device structure
  391. *
  392. * This is used by netconsole to send skbs without having to re-enable
  393. * interrupts. It's not called while the normal interrupt routine is executing.
  394. **/
  395. static void i40evf_netpoll(struct net_device *netdev)
  396. {
  397. struct i40evf_adapter *adapter = netdev_priv(netdev);
  398. int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  399. int i;
  400. /* if interface is down do nothing */
  401. if (test_bit(__I40E_DOWN, &adapter->vsi.state))
  402. return;
  403. for (i = 0; i < q_vectors; i++)
  404. i40evf_msix_clean_rings(0, &adapter->q_vectors[i]);
  405. }
  406. #endif
  407. /**
  408. * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
  409. * @adapter: board private structure
  410. *
  411. * Allocates MSI-X vectors for tx and rx handling, and requests
  412. * interrupts from the kernel.
  413. **/
  414. static int
  415. i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename)
  416. {
  417. int vector, err, q_vectors;
  418. int rx_int_idx = 0, tx_int_idx = 0;
  419. i40evf_irq_disable(adapter);
  420. /* Decrement for Other and TCP Timer vectors */
  421. q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  422. for (vector = 0; vector < q_vectors; vector++) {
  423. struct i40e_q_vector *q_vector = &adapter->q_vectors[vector];
  424. if (q_vector->tx.ring && q_vector->rx.ring) {
  425. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  426. "i40evf-%s-%s-%d", basename,
  427. "TxRx", rx_int_idx++);
  428. tx_int_idx++;
  429. } else if (q_vector->rx.ring) {
  430. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  431. "i40evf-%s-%s-%d", basename,
  432. "rx", rx_int_idx++);
  433. } else if (q_vector->tx.ring) {
  434. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  435. "i40evf-%s-%s-%d", basename,
  436. "tx", tx_int_idx++);
  437. } else {
  438. /* skip this unused q_vector */
  439. continue;
  440. }
  441. err = request_irq(
  442. adapter->msix_entries[vector + NONQ_VECS].vector,
  443. i40evf_msix_clean_rings,
  444. 0,
  445. q_vector->name,
  446. q_vector);
  447. if (err) {
  448. dev_info(&adapter->pdev->dev,
  449. "Request_irq failed, error: %d\n", err);
  450. goto free_queue_irqs;
  451. }
  452. /* assign the mask for this irq */
  453. irq_set_affinity_hint(
  454. adapter->msix_entries[vector + NONQ_VECS].vector,
  455. q_vector->affinity_mask);
  456. }
  457. return 0;
  458. free_queue_irqs:
  459. while (vector) {
  460. vector--;
  461. irq_set_affinity_hint(
  462. adapter->msix_entries[vector + NONQ_VECS].vector,
  463. NULL);
  464. free_irq(adapter->msix_entries[vector + NONQ_VECS].vector,
  465. &adapter->q_vectors[vector]);
  466. }
  467. return err;
  468. }
  469. /**
  470. * i40evf_request_misc_irq - Initialize MSI-X interrupts
  471. * @adapter: board private structure
  472. *
  473. * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
  474. * vector is only for the admin queue, and stays active even when the netdev
  475. * is closed.
  476. **/
  477. static int i40evf_request_misc_irq(struct i40evf_adapter *adapter)
  478. {
  479. struct net_device *netdev = adapter->netdev;
  480. int err;
  481. snprintf(adapter->misc_vector_name,
  482. sizeof(adapter->misc_vector_name) - 1, "i40evf-%s:mbx",
  483. dev_name(&adapter->pdev->dev));
  484. err = request_irq(adapter->msix_entries[0].vector,
  485. &i40evf_msix_aq, 0,
  486. adapter->misc_vector_name, netdev);
  487. if (err) {
  488. dev_err(&adapter->pdev->dev,
  489. "request_irq for %s failed: %d\n",
  490. adapter->misc_vector_name, err);
  491. free_irq(adapter->msix_entries[0].vector, netdev);
  492. }
  493. return err;
  494. }
  495. /**
  496. * i40evf_free_traffic_irqs - Free MSI-X interrupts
  497. * @adapter: board private structure
  498. *
  499. * Frees all MSI-X vectors other than 0.
  500. **/
  501. static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter)
  502. {
  503. int i;
  504. int q_vectors;
  505. q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  506. for (i = 0; i < q_vectors; i++) {
  507. irq_set_affinity_hint(adapter->msix_entries[i+1].vector,
  508. NULL);
  509. free_irq(adapter->msix_entries[i+1].vector,
  510. &adapter->q_vectors[i]);
  511. }
  512. }
  513. /**
  514. * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
  515. * @adapter: board private structure
  516. *
  517. * Frees MSI-X vector 0.
  518. **/
  519. static void i40evf_free_misc_irq(struct i40evf_adapter *adapter)
  520. {
  521. struct net_device *netdev = adapter->netdev;
  522. free_irq(adapter->msix_entries[0].vector, netdev);
  523. }
  524. /**
  525. * i40evf_configure_tx - Configure Transmit Unit after Reset
  526. * @adapter: board private structure
  527. *
  528. * Configure the Tx unit of the MAC after a reset.
  529. **/
  530. static void i40evf_configure_tx(struct i40evf_adapter *adapter)
  531. {
  532. struct i40e_hw *hw = &adapter->hw;
  533. int i;
  534. for (i = 0; i < adapter->num_active_queues; i++)
  535. adapter->tx_rings[i].tail = hw->hw_addr + I40E_QTX_TAIL1(i);
  536. }
  537. /**
  538. * i40evf_configure_rx - Configure Receive Unit after Reset
  539. * @adapter: board private structure
  540. *
  541. * Configure the Rx unit of the MAC after a reset.
  542. **/
  543. static void i40evf_configure_rx(struct i40evf_adapter *adapter)
  544. {
  545. struct i40e_hw *hw = &adapter->hw;
  546. struct net_device *netdev = adapter->netdev;
  547. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  548. int i;
  549. int rx_buf_len;
  550. adapter->flags &= ~I40EVF_FLAG_RX_PS_CAPABLE;
  551. adapter->flags |= I40EVF_FLAG_RX_1BUF_CAPABLE;
  552. /* Decide whether to use packet split mode or not */
  553. if (netdev->mtu > ETH_DATA_LEN) {
  554. if (adapter->flags & I40EVF_FLAG_RX_PS_CAPABLE)
  555. adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
  556. else
  557. adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
  558. } else {
  559. if (adapter->flags & I40EVF_FLAG_RX_1BUF_CAPABLE)
  560. adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
  561. else
  562. adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
  563. }
  564. /* Set the RX buffer length according to the mode */
  565. if (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED) {
  566. rx_buf_len = I40E_RX_HDR_SIZE;
  567. } else {
  568. if (netdev->mtu <= ETH_DATA_LEN)
  569. rx_buf_len = I40EVF_RXBUFFER_2048;
  570. else
  571. rx_buf_len = ALIGN(max_frame, 1024);
  572. }
  573. for (i = 0; i < adapter->num_active_queues; i++) {
  574. adapter->rx_rings[i].tail = hw->hw_addr + I40E_QRX_TAIL1(i);
  575. adapter->rx_rings[i].rx_buf_len = rx_buf_len;
  576. }
  577. }
  578. /**
  579. * i40evf_find_vlan - Search filter list for specific vlan filter
  580. * @adapter: board private structure
  581. * @vlan: vlan tag
  582. *
  583. * Returns ptr to the filter object or NULL
  584. **/
  585. static struct
  586. i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan)
  587. {
  588. struct i40evf_vlan_filter *f;
  589. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  590. if (vlan == f->vlan)
  591. return f;
  592. }
  593. return NULL;
  594. }
  595. /**
  596. * i40evf_add_vlan - Add a vlan filter to the list
  597. * @adapter: board private structure
  598. * @vlan: VLAN tag
  599. *
  600. * Returns ptr to the filter object or NULL when no memory available.
  601. **/
  602. static struct
  603. i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan)
  604. {
  605. struct i40evf_vlan_filter *f = NULL;
  606. int count = 50;
  607. while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
  608. &adapter->crit_section)) {
  609. udelay(1);
  610. if (--count == 0)
  611. goto out;
  612. }
  613. f = i40evf_find_vlan(adapter, vlan);
  614. if (!f) {
  615. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  616. if (!f)
  617. goto clearout;
  618. f->vlan = vlan;
  619. INIT_LIST_HEAD(&f->list);
  620. list_add(&f->list, &adapter->vlan_filter_list);
  621. f->add = true;
  622. adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  623. }
  624. clearout:
  625. clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
  626. out:
  627. return f;
  628. }
  629. /**
  630. * i40evf_del_vlan - Remove a vlan filter from the list
  631. * @adapter: board private structure
  632. * @vlan: VLAN tag
  633. **/
  634. static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan)
  635. {
  636. struct i40evf_vlan_filter *f;
  637. int count = 50;
  638. while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
  639. &adapter->crit_section)) {
  640. udelay(1);
  641. if (--count == 0)
  642. return;
  643. }
  644. f = i40evf_find_vlan(adapter, vlan);
  645. if (f) {
  646. f->remove = true;
  647. adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  648. }
  649. clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
  650. }
  651. /**
  652. * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
  653. * @netdev: network device struct
  654. * @vid: VLAN tag
  655. **/
  656. static int i40evf_vlan_rx_add_vid(struct net_device *netdev,
  657. __always_unused __be16 proto, u16 vid)
  658. {
  659. struct i40evf_adapter *adapter = netdev_priv(netdev);
  660. if (!VLAN_ALLOWED(adapter))
  661. return -EIO;
  662. if (i40evf_add_vlan(adapter, vid) == NULL)
  663. return -ENOMEM;
  664. return 0;
  665. }
  666. /**
  667. * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
  668. * @netdev: network device struct
  669. * @vid: VLAN tag
  670. **/
  671. static int i40evf_vlan_rx_kill_vid(struct net_device *netdev,
  672. __always_unused __be16 proto, u16 vid)
  673. {
  674. struct i40evf_adapter *adapter = netdev_priv(netdev);
  675. if (VLAN_ALLOWED(adapter)) {
  676. i40evf_del_vlan(adapter, vid);
  677. return 0;
  678. }
  679. return -EIO;
  680. }
  681. /**
  682. * i40evf_find_filter - Search filter list for specific mac filter
  683. * @adapter: board private structure
  684. * @macaddr: the MAC address
  685. *
  686. * Returns ptr to the filter object or NULL
  687. **/
  688. static struct
  689. i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter,
  690. u8 *macaddr)
  691. {
  692. struct i40evf_mac_filter *f;
  693. if (!macaddr)
  694. return NULL;
  695. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  696. if (ether_addr_equal(macaddr, f->macaddr))
  697. return f;
  698. }
  699. return NULL;
  700. }
  701. /**
  702. * i40e_add_filter - Add a mac filter to the filter list
  703. * @adapter: board private structure
  704. * @macaddr: the MAC address
  705. *
  706. * Returns ptr to the filter object or NULL when no memory available.
  707. **/
  708. static struct
  709. i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter,
  710. u8 *macaddr)
  711. {
  712. struct i40evf_mac_filter *f;
  713. int count = 50;
  714. if (!macaddr)
  715. return NULL;
  716. while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
  717. &adapter->crit_section)) {
  718. udelay(1);
  719. if (--count == 0)
  720. return NULL;
  721. }
  722. f = i40evf_find_filter(adapter, macaddr);
  723. if (!f) {
  724. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  725. if (!f) {
  726. clear_bit(__I40EVF_IN_CRITICAL_TASK,
  727. &adapter->crit_section);
  728. return NULL;
  729. }
  730. ether_addr_copy(f->macaddr, macaddr);
  731. list_add(&f->list, &adapter->mac_filter_list);
  732. f->add = true;
  733. adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  734. }
  735. clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
  736. return f;
  737. }
  738. /**
  739. * i40evf_set_mac - NDO callback to set port mac address
  740. * @netdev: network interface device structure
  741. * @p: pointer to an address structure
  742. *
  743. * Returns 0 on success, negative on failure
  744. **/
  745. static int i40evf_set_mac(struct net_device *netdev, void *p)
  746. {
  747. struct i40evf_adapter *adapter = netdev_priv(netdev);
  748. struct i40e_hw *hw = &adapter->hw;
  749. struct i40evf_mac_filter *f;
  750. struct sockaddr *addr = p;
  751. if (!is_valid_ether_addr(addr->sa_data))
  752. return -EADDRNOTAVAIL;
  753. if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
  754. return 0;
  755. if (adapter->flags & I40EVF_FLAG_ADDR_SET_BY_PF)
  756. return -EPERM;
  757. f = i40evf_find_filter(adapter, hw->mac.addr);
  758. if (f) {
  759. f->remove = true;
  760. adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  761. }
  762. f = i40evf_add_filter(adapter, addr->sa_data);
  763. if (f) {
  764. ether_addr_copy(hw->mac.addr, addr->sa_data);
  765. ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
  766. }
  767. return (f == NULL) ? -ENOMEM : 0;
  768. }
  769. /**
  770. * i40evf_set_rx_mode - NDO callback to set the netdev filters
  771. * @netdev: network interface device structure
  772. **/
  773. static void i40evf_set_rx_mode(struct net_device *netdev)
  774. {
  775. struct i40evf_adapter *adapter = netdev_priv(netdev);
  776. struct i40evf_mac_filter *f, *ftmp;
  777. struct netdev_hw_addr *uca;
  778. struct netdev_hw_addr *mca;
  779. struct netdev_hw_addr *ha;
  780. int count = 50;
  781. /* add addr if not already in the filter list */
  782. netdev_for_each_uc_addr(uca, netdev) {
  783. i40evf_add_filter(adapter, uca->addr);
  784. }
  785. netdev_for_each_mc_addr(mca, netdev) {
  786. i40evf_add_filter(adapter, mca->addr);
  787. }
  788. while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
  789. &adapter->crit_section)) {
  790. udelay(1);
  791. if (--count == 0) {
  792. dev_err(&adapter->pdev->dev,
  793. "Failed to get lock in %s\n", __func__);
  794. return;
  795. }
  796. }
  797. /* remove filter if not in netdev list */
  798. list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
  799. netdev_for_each_mc_addr(mca, netdev)
  800. if (ether_addr_equal(mca->addr, f->macaddr))
  801. goto bottom_of_search_loop;
  802. netdev_for_each_uc_addr(uca, netdev)
  803. if (ether_addr_equal(uca->addr, f->macaddr))
  804. goto bottom_of_search_loop;
  805. for_each_dev_addr(netdev, ha)
  806. if (ether_addr_equal(ha->addr, f->macaddr))
  807. goto bottom_of_search_loop;
  808. if (ether_addr_equal(f->macaddr, adapter->hw.mac.addr))
  809. goto bottom_of_search_loop;
  810. /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
  811. f->remove = true;
  812. adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  813. bottom_of_search_loop:
  814. continue;
  815. }
  816. clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
  817. }
  818. /**
  819. * i40evf_napi_enable_all - enable NAPI on all queue vectors
  820. * @adapter: board private structure
  821. **/
  822. static void i40evf_napi_enable_all(struct i40evf_adapter *adapter)
  823. {
  824. int q_idx;
  825. struct i40e_q_vector *q_vector;
  826. int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  827. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  828. struct napi_struct *napi;
  829. q_vector = &adapter->q_vectors[q_idx];
  830. napi = &q_vector->napi;
  831. napi_enable(napi);
  832. }
  833. }
  834. /**
  835. * i40evf_napi_disable_all - disable NAPI on all queue vectors
  836. * @adapter: board private structure
  837. **/
  838. static void i40evf_napi_disable_all(struct i40evf_adapter *adapter)
  839. {
  840. int q_idx;
  841. struct i40e_q_vector *q_vector;
  842. int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  843. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  844. q_vector = &adapter->q_vectors[q_idx];
  845. napi_disable(&q_vector->napi);
  846. }
  847. }
  848. /**
  849. * i40evf_configure - set up transmit and receive data structures
  850. * @adapter: board private structure
  851. **/
  852. static void i40evf_configure(struct i40evf_adapter *adapter)
  853. {
  854. struct net_device *netdev = adapter->netdev;
  855. int i;
  856. i40evf_set_rx_mode(netdev);
  857. i40evf_configure_tx(adapter);
  858. i40evf_configure_rx(adapter);
  859. adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
  860. for (i = 0; i < adapter->num_active_queues; i++) {
  861. struct i40e_ring *ring = &adapter->rx_rings[i];
  862. i40evf_alloc_rx_buffers_1buf(ring, ring->count);
  863. ring->next_to_use = ring->count - 1;
  864. writel(ring->next_to_use, ring->tail);
  865. }
  866. }
  867. /**
  868. * i40evf_up_complete - Finish the last steps of bringing up a connection
  869. * @adapter: board private structure
  870. **/
  871. static int i40evf_up_complete(struct i40evf_adapter *adapter)
  872. {
  873. adapter->state = __I40EVF_RUNNING;
  874. clear_bit(__I40E_DOWN, &adapter->vsi.state);
  875. i40evf_napi_enable_all(adapter);
  876. adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
  877. mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
  878. return 0;
  879. }
  880. /**
  881. * i40e_down - Shutdown the connection processing
  882. * @adapter: board private structure
  883. **/
  884. void i40evf_down(struct i40evf_adapter *adapter)
  885. {
  886. struct net_device *netdev = adapter->netdev;
  887. struct i40evf_mac_filter *f;
  888. if (adapter->state == __I40EVF_DOWN)
  889. return;
  890. while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
  891. &adapter->crit_section))
  892. usleep_range(500, 1000);
  893. netif_carrier_off(netdev);
  894. netif_tx_disable(netdev);
  895. i40evf_napi_disable_all(adapter);
  896. i40evf_irq_disable(adapter);
  897. /* remove all MAC filters */
  898. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  899. f->remove = true;
  900. }
  901. /* remove all VLAN filters */
  902. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  903. f->remove = true;
  904. }
  905. if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) &&
  906. adapter->state != __I40EVF_RESETTING) {
  907. /* cancel any current operation */
  908. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  909. /* Schedule operations to close down the HW. Don't wait
  910. * here for this to complete. The watchdog is still running
  911. * and it will take care of this.
  912. */
  913. adapter->aq_required = I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  914. adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  915. adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
  916. }
  917. clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
  918. }
  919. /**
  920. * i40evf_acquire_msix_vectors - Setup the MSIX capability
  921. * @adapter: board private structure
  922. * @vectors: number of vectors to request
  923. *
  924. * Work with the OS to set up the MSIX vectors needed.
  925. *
  926. * Returns 0 on success, negative on failure
  927. **/
  928. static int
  929. i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors)
  930. {
  931. int err, vector_threshold;
  932. /* We'll want at least 3 (vector_threshold):
  933. * 0) Other (Admin Queue and link, mostly)
  934. * 1) TxQ[0] Cleanup
  935. * 2) RxQ[0] Cleanup
  936. */
  937. vector_threshold = MIN_MSIX_COUNT;
  938. /* The more we get, the more we will assign to Tx/Rx Cleanup
  939. * for the separate queues...where Rx Cleanup >= Tx Cleanup.
  940. * Right now, we simply care about how many we'll get; we'll
  941. * set them up later while requesting irq's.
  942. */
  943. err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
  944. vector_threshold, vectors);
  945. if (err < 0) {
  946. dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n");
  947. kfree(adapter->msix_entries);
  948. adapter->msix_entries = NULL;
  949. return err;
  950. }
  951. /* Adjust for only the vectors we'll use, which is minimum
  952. * of max_msix_q_vectors + NONQ_VECS, or the number of
  953. * vectors we were allocated.
  954. */
  955. adapter->num_msix_vectors = err;
  956. return 0;
  957. }
  958. /**
  959. * i40evf_free_queues - Free memory for all rings
  960. * @adapter: board private structure to initialize
  961. *
  962. * Free all of the memory associated with queue pairs.
  963. **/
  964. static void i40evf_free_queues(struct i40evf_adapter *adapter)
  965. {
  966. if (!adapter->vsi_res)
  967. return;
  968. kfree(adapter->tx_rings);
  969. kfree(adapter->rx_rings);
  970. }
  971. /**
  972. * i40evf_alloc_queues - Allocate memory for all rings
  973. * @adapter: board private structure to initialize
  974. *
  975. * We allocate one ring per queue at run-time since we don't know the
  976. * number of queues at compile-time. The polling_netdev array is
  977. * intended for Multiqueue, but should work fine with a single queue.
  978. **/
  979. static int i40evf_alloc_queues(struct i40evf_adapter *adapter)
  980. {
  981. int i;
  982. adapter->tx_rings = kcalloc(adapter->num_active_queues,
  983. sizeof(struct i40e_ring), GFP_KERNEL);
  984. if (!adapter->tx_rings)
  985. goto err_out;
  986. adapter->rx_rings = kcalloc(adapter->num_active_queues,
  987. sizeof(struct i40e_ring), GFP_KERNEL);
  988. if (!adapter->rx_rings)
  989. goto err_out;
  990. for (i = 0; i < adapter->num_active_queues; i++) {
  991. struct i40e_ring *tx_ring;
  992. struct i40e_ring *rx_ring;
  993. tx_ring = &adapter->tx_rings[i];
  994. tx_ring->queue_index = i;
  995. tx_ring->netdev = adapter->netdev;
  996. tx_ring->dev = &adapter->pdev->dev;
  997. tx_ring->count = adapter->tx_desc_count;
  998. if (adapter->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
  999. tx_ring->flags |= I40E_TXR_FLAGS_WB_ON_ITR;
  1000. rx_ring = &adapter->rx_rings[i];
  1001. rx_ring->queue_index = i;
  1002. rx_ring->netdev = adapter->netdev;
  1003. rx_ring->dev = &adapter->pdev->dev;
  1004. rx_ring->count = adapter->rx_desc_count;
  1005. }
  1006. return 0;
  1007. err_out:
  1008. i40evf_free_queues(adapter);
  1009. return -ENOMEM;
  1010. }
  1011. /**
  1012. * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
  1013. * @adapter: board private structure to initialize
  1014. *
  1015. * Attempt to configure the interrupts using the best available
  1016. * capabilities of the hardware and the kernel.
  1017. **/
  1018. static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter)
  1019. {
  1020. int vector, v_budget;
  1021. int pairs = 0;
  1022. int err = 0;
  1023. if (!adapter->vsi_res) {
  1024. err = -EIO;
  1025. goto out;
  1026. }
  1027. pairs = adapter->num_active_queues;
  1028. /* It's easy to be greedy for MSI-X vectors, but it really
  1029. * doesn't do us much good if we have a lot more vectors
  1030. * than CPU's. So let's be conservative and only ask for
  1031. * (roughly) twice the number of vectors as there are CPU's.
  1032. */
  1033. v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS;
  1034. v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors);
  1035. adapter->msix_entries = kcalloc(v_budget,
  1036. sizeof(struct msix_entry), GFP_KERNEL);
  1037. if (!adapter->msix_entries) {
  1038. err = -ENOMEM;
  1039. goto out;
  1040. }
  1041. for (vector = 0; vector < v_budget; vector++)
  1042. adapter->msix_entries[vector].entry = vector;
  1043. err = i40evf_acquire_msix_vectors(adapter, v_budget);
  1044. out:
  1045. netif_set_real_num_rx_queues(adapter->netdev, pairs);
  1046. netif_set_real_num_tx_queues(adapter->netdev, pairs);
  1047. return err;
  1048. }
  1049. /**
  1050. * i40e_config_rss_aq - Prepare for RSS using AQ commands
  1051. * @vsi: vsi structure
  1052. * @seed: RSS hash seed
  1053. * @lut: Lookup table
  1054. * @lut_size: Lookup table size
  1055. *
  1056. * Return 0 on success, negative on failure
  1057. **/
  1058. static int i40evf_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  1059. u8 *lut, u16 lut_size)
  1060. {
  1061. struct i40evf_adapter *adapter = vsi->back;
  1062. struct i40e_hw *hw = &adapter->hw;
  1063. int ret = 0;
  1064. if (!vsi->id)
  1065. return -EINVAL;
  1066. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  1067. /* bail because we already have a command pending */
  1068. dev_err(&adapter->pdev->dev, "Cannot confiure RSS, command %d pending\n",
  1069. adapter->current_op);
  1070. return -EBUSY;
  1071. }
  1072. if (seed) {
  1073. struct i40e_aqc_get_set_rss_key_data *rss_key =
  1074. (struct i40e_aqc_get_set_rss_key_data *)seed;
  1075. ret = i40evf_aq_set_rss_key(hw, vsi->id, rss_key);
  1076. if (ret) {
  1077. dev_err(&adapter->pdev->dev, "Cannot set RSS key, err %s aq_err %s\n",
  1078. i40evf_stat_str(hw, ret),
  1079. i40evf_aq_str(hw, hw->aq.asq_last_status));
  1080. return ret;
  1081. }
  1082. }
  1083. if (lut) {
  1084. ret = i40evf_aq_set_rss_lut(hw, vsi->id, false, lut, lut_size);
  1085. if (ret) {
  1086. dev_err(&adapter->pdev->dev,
  1087. "Cannot set RSS lut, err %s aq_err %s\n",
  1088. i40evf_stat_str(hw, ret),
  1089. i40evf_aq_str(hw, hw->aq.asq_last_status));
  1090. return ret;
  1091. }
  1092. }
  1093. return ret;
  1094. }
  1095. /**
  1096. * i40evf_config_rss_reg - Configure RSS keys and lut by writing registers
  1097. * @vsi: Pointer to vsi structure
  1098. * @seed: RSS hash seed
  1099. * @lut: Lookup table
  1100. * @lut_size: Lookup table size
  1101. *
  1102. * Returns 0 on success, negative on failure
  1103. **/
  1104. static int i40evf_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
  1105. const u8 *lut, u16 lut_size)
  1106. {
  1107. struct i40evf_adapter *adapter = vsi->back;
  1108. struct i40e_hw *hw = &adapter->hw;
  1109. u16 i;
  1110. if (seed) {
  1111. u32 *seed_dw = (u32 *)seed;
  1112. for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
  1113. wr32(hw, I40E_VFQF_HKEY(i), seed_dw[i]);
  1114. }
  1115. if (lut) {
  1116. u32 *lut_dw = (u32 *)lut;
  1117. if (lut_size != I40EVF_HLUT_ARRAY_SIZE)
  1118. return -EINVAL;
  1119. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  1120. wr32(hw, I40E_VFQF_HLUT(i), lut_dw[i]);
  1121. }
  1122. i40e_flush(hw);
  1123. return 0;
  1124. }
  1125. /**
  1126. * * i40evf_get_rss_aq - Get RSS keys and lut by using AQ commands
  1127. * @vsi: Pointer to vsi structure
  1128. * @seed: RSS hash seed
  1129. * @lut: Lookup table
  1130. * @lut_size: Lookup table size
  1131. *
  1132. * Return 0 on success, negative on failure
  1133. **/
  1134. static int i40evf_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  1135. u8 *lut, u16 lut_size)
  1136. {
  1137. struct i40evf_adapter *adapter = vsi->back;
  1138. struct i40e_hw *hw = &adapter->hw;
  1139. int ret = 0;
  1140. if (seed) {
  1141. ret = i40evf_aq_get_rss_key(hw, vsi->id,
  1142. (struct i40e_aqc_get_set_rss_key_data *)seed);
  1143. if (ret) {
  1144. dev_err(&adapter->pdev->dev,
  1145. "Cannot get RSS key, err %s aq_err %s\n",
  1146. i40evf_stat_str(hw, ret),
  1147. i40evf_aq_str(hw, hw->aq.asq_last_status));
  1148. return ret;
  1149. }
  1150. }
  1151. if (lut) {
  1152. ret = i40evf_aq_get_rss_lut(hw, vsi->id, seed, lut, lut_size);
  1153. if (ret) {
  1154. dev_err(&adapter->pdev->dev,
  1155. "Cannot get RSS lut, err %s aq_err %s\n",
  1156. i40evf_stat_str(hw, ret),
  1157. i40evf_aq_str(hw, hw->aq.asq_last_status));
  1158. return ret;
  1159. }
  1160. }
  1161. return ret;
  1162. }
  1163. /**
  1164. * * i40evf_get_rss_reg - Get RSS keys and lut by reading registers
  1165. * @vsi: Pointer to vsi structure
  1166. * @seed: RSS hash seed
  1167. * @lut: Lookup table
  1168. * @lut_size: Lookup table size
  1169. *
  1170. * Returns 0 on success, negative on failure
  1171. **/
  1172. static int i40evf_get_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
  1173. const u8 *lut, u16 lut_size)
  1174. {
  1175. struct i40evf_adapter *adapter = vsi->back;
  1176. struct i40e_hw *hw = &adapter->hw;
  1177. u16 i;
  1178. if (seed) {
  1179. u32 *seed_dw = (u32 *)seed;
  1180. for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
  1181. seed_dw[i] = rd32(hw, I40E_VFQF_HKEY(i));
  1182. }
  1183. if (lut) {
  1184. u32 *lut_dw = (u32 *)lut;
  1185. if (lut_size != I40EVF_HLUT_ARRAY_SIZE)
  1186. return -EINVAL;
  1187. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  1188. lut_dw[i] = rd32(hw, I40E_VFQF_HLUT(i));
  1189. }
  1190. return 0;
  1191. }
  1192. /**
  1193. * i40evf_config_rss - Configure RSS keys and lut
  1194. * @vsi: Pointer to vsi structure
  1195. * @seed: RSS hash seed
  1196. * @lut: Lookup table
  1197. * @lut_size: Lookup table size
  1198. *
  1199. * Returns 0 on success, negative on failure
  1200. **/
  1201. int i40evf_config_rss(struct i40e_vsi *vsi, const u8 *seed,
  1202. u8 *lut, u16 lut_size)
  1203. {
  1204. struct i40evf_adapter *adapter = vsi->back;
  1205. if (RSS_AQ(adapter))
  1206. return i40evf_config_rss_aq(vsi, seed, lut, lut_size);
  1207. else
  1208. return i40evf_config_rss_reg(vsi, seed, lut, lut_size);
  1209. }
  1210. /**
  1211. * i40evf_get_rss - Get RSS keys and lut
  1212. * @vsi: Pointer to vsi structure
  1213. * @seed: RSS hash seed
  1214. * @lut: Lookup table
  1215. * @lut_size: Lookup table size
  1216. *
  1217. * Returns 0 on success, negative on failure
  1218. **/
  1219. int i40evf_get_rss(struct i40e_vsi *vsi, const u8 *seed, u8 *lut, u16 lut_size)
  1220. {
  1221. struct i40evf_adapter *adapter = vsi->back;
  1222. if (RSS_AQ(adapter))
  1223. return i40evf_get_rss_aq(vsi, seed, lut, lut_size);
  1224. else
  1225. return i40evf_get_rss_reg(vsi, seed, lut, lut_size);
  1226. }
  1227. /**
  1228. * i40evf_fill_rss_lut - Fill the lut with default values
  1229. * @lut: Lookup table to be filled with
  1230. * @rss_table_size: Lookup table size
  1231. * @rss_size: Range of queue number for hashing
  1232. **/
  1233. static void i40evf_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
  1234. {
  1235. u16 i;
  1236. for (i = 0; i < rss_table_size; i++)
  1237. lut[i] = i % rss_size;
  1238. }
  1239. /**
  1240. * i40evf_init_rss - Prepare for RSS
  1241. * @adapter: board private structure
  1242. *
  1243. * Return 0 on success, negative on failure
  1244. **/
  1245. static int i40evf_init_rss(struct i40evf_adapter *adapter)
  1246. {
  1247. struct i40e_vsi *vsi = &adapter->vsi;
  1248. struct i40e_hw *hw = &adapter->hw;
  1249. u8 seed[I40EVF_HKEY_ARRAY_SIZE];
  1250. u64 hena;
  1251. u8 *lut;
  1252. int ret;
  1253. /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
  1254. hena = I40E_DEFAULT_RSS_HENA;
  1255. wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
  1256. wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
  1257. lut = kzalloc(I40EVF_HLUT_ARRAY_SIZE, GFP_KERNEL);
  1258. if (!lut)
  1259. return -ENOMEM;
  1260. /* Use user configured lut if there is one, otherwise use default */
  1261. if (vsi->rss_lut_user)
  1262. memcpy(lut, vsi->rss_lut_user, I40EVF_HLUT_ARRAY_SIZE);
  1263. else
  1264. i40evf_fill_rss_lut(lut, I40EVF_HLUT_ARRAY_SIZE,
  1265. adapter->num_active_queues);
  1266. /* Use user configured hash key if there is one, otherwise
  1267. * user default.
  1268. */
  1269. if (vsi->rss_hkey_user)
  1270. memcpy(seed, vsi->rss_hkey_user, I40EVF_HKEY_ARRAY_SIZE);
  1271. else
  1272. netdev_rss_key_fill((void *)seed, I40EVF_HKEY_ARRAY_SIZE);
  1273. ret = i40evf_config_rss(vsi, seed, lut, I40EVF_HLUT_ARRAY_SIZE);
  1274. kfree(lut);
  1275. return ret;
  1276. }
  1277. /**
  1278. * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
  1279. * @adapter: board private structure to initialize
  1280. *
  1281. * We allocate one q_vector per queue interrupt. If allocation fails we
  1282. * return -ENOMEM.
  1283. **/
  1284. static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter)
  1285. {
  1286. int q_idx = 0, num_q_vectors;
  1287. struct i40e_q_vector *q_vector;
  1288. num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  1289. adapter->q_vectors = kcalloc(num_q_vectors, sizeof(*q_vector),
  1290. GFP_KERNEL);
  1291. if (!adapter->q_vectors)
  1292. goto err_out;
  1293. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  1294. q_vector = &adapter->q_vectors[q_idx];
  1295. q_vector->adapter = adapter;
  1296. q_vector->vsi = &adapter->vsi;
  1297. q_vector->v_idx = q_idx;
  1298. netif_napi_add(adapter->netdev, &q_vector->napi,
  1299. i40evf_napi_poll, NAPI_POLL_WEIGHT);
  1300. }
  1301. return 0;
  1302. err_out:
  1303. while (q_idx) {
  1304. q_idx--;
  1305. q_vector = &adapter->q_vectors[q_idx];
  1306. netif_napi_del(&q_vector->napi);
  1307. }
  1308. kfree(adapter->q_vectors);
  1309. return -ENOMEM;
  1310. }
  1311. /**
  1312. * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
  1313. * @adapter: board private structure to initialize
  1314. *
  1315. * This function frees the memory allocated to the q_vectors. In addition if
  1316. * NAPI is enabled it will delete any references to the NAPI struct prior
  1317. * to freeing the q_vector.
  1318. **/
  1319. static void i40evf_free_q_vectors(struct i40evf_adapter *adapter)
  1320. {
  1321. int q_idx, num_q_vectors;
  1322. int napi_vectors;
  1323. num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  1324. napi_vectors = adapter->num_active_queues;
  1325. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  1326. struct i40e_q_vector *q_vector = &adapter->q_vectors[q_idx];
  1327. if (q_idx < napi_vectors)
  1328. netif_napi_del(&q_vector->napi);
  1329. }
  1330. kfree(adapter->q_vectors);
  1331. }
  1332. /**
  1333. * i40evf_reset_interrupt_capability - Reset MSIX setup
  1334. * @adapter: board private structure
  1335. *
  1336. **/
  1337. void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter)
  1338. {
  1339. pci_disable_msix(adapter->pdev);
  1340. kfree(adapter->msix_entries);
  1341. adapter->msix_entries = NULL;
  1342. }
  1343. /**
  1344. * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
  1345. * @adapter: board private structure to initialize
  1346. *
  1347. **/
  1348. int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter)
  1349. {
  1350. int err;
  1351. err = i40evf_set_interrupt_capability(adapter);
  1352. if (err) {
  1353. dev_err(&adapter->pdev->dev,
  1354. "Unable to setup interrupt capabilities\n");
  1355. goto err_set_interrupt;
  1356. }
  1357. err = i40evf_alloc_q_vectors(adapter);
  1358. if (err) {
  1359. dev_err(&adapter->pdev->dev,
  1360. "Unable to allocate memory for queue vectors\n");
  1361. goto err_alloc_q_vectors;
  1362. }
  1363. err = i40evf_alloc_queues(adapter);
  1364. if (err) {
  1365. dev_err(&adapter->pdev->dev,
  1366. "Unable to allocate memory for queues\n");
  1367. goto err_alloc_queues;
  1368. }
  1369. dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u",
  1370. (adapter->num_active_queues > 1) ? "Enabled" : "Disabled",
  1371. adapter->num_active_queues);
  1372. return 0;
  1373. err_alloc_queues:
  1374. i40evf_free_q_vectors(adapter);
  1375. err_alloc_q_vectors:
  1376. i40evf_reset_interrupt_capability(adapter);
  1377. err_set_interrupt:
  1378. return err;
  1379. }
  1380. /**
  1381. * i40evf_clear_rss_config_user - Clear user configurations of RSS
  1382. * @vsi: Pointer to VSI structure
  1383. **/
  1384. static void i40evf_clear_rss_config_user(struct i40e_vsi *vsi)
  1385. {
  1386. if (!vsi)
  1387. return;
  1388. kfree(vsi->rss_hkey_user);
  1389. vsi->rss_hkey_user = NULL;
  1390. kfree(vsi->rss_lut_user);
  1391. vsi->rss_lut_user = NULL;
  1392. }
  1393. /**
  1394. * i40evf_watchdog_timer - Periodic call-back timer
  1395. * @data: pointer to adapter disguised as unsigned long
  1396. **/
  1397. static void i40evf_watchdog_timer(unsigned long data)
  1398. {
  1399. struct i40evf_adapter *adapter = (struct i40evf_adapter *)data;
  1400. schedule_work(&adapter->watchdog_task);
  1401. /* timer will be rescheduled in watchdog task */
  1402. }
  1403. /**
  1404. * i40evf_watchdog_task - Periodic call-back task
  1405. * @work: pointer to work_struct
  1406. **/
  1407. static void i40evf_watchdog_task(struct work_struct *work)
  1408. {
  1409. struct i40evf_adapter *adapter = container_of(work,
  1410. struct i40evf_adapter,
  1411. watchdog_task);
  1412. struct i40e_hw *hw = &adapter->hw;
  1413. u32 reg_val;
  1414. if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section))
  1415. goto restart_watchdog;
  1416. if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
  1417. reg_val = rd32(hw, I40E_VFGEN_RSTAT) &
  1418. I40E_VFGEN_RSTAT_VFR_STATE_MASK;
  1419. if ((reg_val == I40E_VFR_VFACTIVE) ||
  1420. (reg_val == I40E_VFR_COMPLETED)) {
  1421. /* A chance for redemption! */
  1422. dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n");
  1423. adapter->state = __I40EVF_STARTUP;
  1424. adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
  1425. schedule_delayed_work(&adapter->init_task, 10);
  1426. clear_bit(__I40EVF_IN_CRITICAL_TASK,
  1427. &adapter->crit_section);
  1428. /* Don't reschedule the watchdog, since we've restarted
  1429. * the init task. When init_task contacts the PF and
  1430. * gets everything set up again, it'll restart the
  1431. * watchdog for us. Down, boy. Sit. Stay. Woof.
  1432. */
  1433. return;
  1434. }
  1435. adapter->aq_required = 0;
  1436. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  1437. goto watchdog_done;
  1438. }
  1439. if ((adapter->state < __I40EVF_DOWN) ||
  1440. (adapter->flags & I40EVF_FLAG_RESET_PENDING))
  1441. goto watchdog_done;
  1442. /* check for reset */
  1443. reg_val = rd32(hw, I40E_VF_ARQLEN1) & I40E_VF_ARQLEN1_ARQENABLE_MASK;
  1444. if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) && !reg_val) {
  1445. adapter->state = __I40EVF_RESETTING;
  1446. adapter->flags |= I40EVF_FLAG_RESET_PENDING;
  1447. dev_err(&adapter->pdev->dev, "Hardware reset detected\n");
  1448. schedule_work(&adapter->reset_task);
  1449. adapter->aq_required = 0;
  1450. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  1451. goto watchdog_done;
  1452. }
  1453. /* Process admin queue tasks. After init, everything gets done
  1454. * here so we don't race on the admin queue.
  1455. */
  1456. if (adapter->current_op) {
  1457. if (!i40evf_asq_done(hw)) {
  1458. dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n");
  1459. i40evf_send_api_ver(adapter);
  1460. }
  1461. goto watchdog_done;
  1462. }
  1463. if (adapter->aq_required & I40EVF_FLAG_AQ_GET_CONFIG) {
  1464. i40evf_send_vf_config_msg(adapter);
  1465. goto watchdog_done;
  1466. }
  1467. if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) {
  1468. i40evf_disable_queues(adapter);
  1469. goto watchdog_done;
  1470. }
  1471. if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) {
  1472. i40evf_map_queues(adapter);
  1473. goto watchdog_done;
  1474. }
  1475. if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) {
  1476. i40evf_add_ether_addrs(adapter);
  1477. goto watchdog_done;
  1478. }
  1479. if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) {
  1480. i40evf_add_vlans(adapter);
  1481. goto watchdog_done;
  1482. }
  1483. if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) {
  1484. i40evf_del_ether_addrs(adapter);
  1485. goto watchdog_done;
  1486. }
  1487. if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) {
  1488. i40evf_del_vlans(adapter);
  1489. goto watchdog_done;
  1490. }
  1491. if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) {
  1492. i40evf_configure_queues(adapter);
  1493. goto watchdog_done;
  1494. }
  1495. if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) {
  1496. i40evf_enable_queues(adapter);
  1497. goto watchdog_done;
  1498. }
  1499. if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_RSS) {
  1500. /* This message goes straight to the firmware, not the
  1501. * PF, so we don't have to set current_op as we will
  1502. * not get a response through the ARQ.
  1503. */
  1504. i40evf_init_rss(adapter);
  1505. adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_RSS;
  1506. goto watchdog_done;
  1507. }
  1508. if (adapter->state == __I40EVF_RUNNING)
  1509. i40evf_request_stats(adapter);
  1510. watchdog_done:
  1511. if (adapter->state == __I40EVF_RUNNING) {
  1512. i40evf_irq_enable_queues(adapter, ~0);
  1513. i40evf_fire_sw_int(adapter, 0xFF);
  1514. } else {
  1515. i40evf_fire_sw_int(adapter, 0x1);
  1516. }
  1517. clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
  1518. restart_watchdog:
  1519. if (adapter->state == __I40EVF_REMOVE)
  1520. return;
  1521. if (adapter->aq_required)
  1522. mod_timer(&adapter->watchdog_timer,
  1523. jiffies + msecs_to_jiffies(20));
  1524. else
  1525. mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2));
  1526. schedule_work(&adapter->adminq_task);
  1527. }
  1528. #define I40EVF_RESET_WAIT_MS 10
  1529. #define I40EVF_RESET_WAIT_COUNT 500
  1530. /**
  1531. * i40evf_reset_task - Call-back task to handle hardware reset
  1532. * @work: pointer to work_struct
  1533. *
  1534. * During reset we need to shut down and reinitialize the admin queue
  1535. * before we can use it to communicate with the PF again. We also clear
  1536. * and reinit the rings because that context is lost as well.
  1537. **/
  1538. static void i40evf_reset_task(struct work_struct *work)
  1539. {
  1540. struct i40evf_adapter *adapter = container_of(work,
  1541. struct i40evf_adapter,
  1542. reset_task);
  1543. struct net_device *netdev = adapter->netdev;
  1544. struct i40e_hw *hw = &adapter->hw;
  1545. struct i40evf_vlan_filter *vlf;
  1546. struct i40evf_mac_filter *f;
  1547. u32 reg_val;
  1548. int i = 0, err;
  1549. while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
  1550. &adapter->crit_section))
  1551. usleep_range(500, 1000);
  1552. i40evf_misc_irq_disable(adapter);
  1553. if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) {
  1554. adapter->flags &= ~I40EVF_FLAG_RESET_NEEDED;
  1555. /* Restart the AQ here. If we have been reset but didn't
  1556. * detect it, or if the PF had to reinit, our AQ will be hosed.
  1557. */
  1558. i40evf_shutdown_adminq(hw);
  1559. i40evf_init_adminq(hw);
  1560. i40evf_request_reset(adapter);
  1561. }
  1562. adapter->flags |= I40EVF_FLAG_RESET_PENDING;
  1563. /* poll until we see the reset actually happen */
  1564. for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
  1565. reg_val = rd32(hw, I40E_VF_ARQLEN1) &
  1566. I40E_VF_ARQLEN1_ARQENABLE_MASK;
  1567. if (!reg_val)
  1568. break;
  1569. usleep_range(5000, 10000);
  1570. }
  1571. if (i == I40EVF_RESET_WAIT_COUNT) {
  1572. dev_info(&adapter->pdev->dev, "Never saw reset\n");
  1573. goto continue_reset; /* act like the reset happened */
  1574. }
  1575. /* wait until the reset is complete and the PF is responding to us */
  1576. for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
  1577. reg_val = rd32(hw, I40E_VFGEN_RSTAT) &
  1578. I40E_VFGEN_RSTAT_VFR_STATE_MASK;
  1579. if (reg_val == I40E_VFR_VFACTIVE)
  1580. break;
  1581. msleep(I40EVF_RESET_WAIT_MS);
  1582. }
  1583. /* extra wait to make sure minimum wait is met */
  1584. msleep(I40EVF_RESET_WAIT_MS);
  1585. if (i == I40EVF_RESET_WAIT_COUNT) {
  1586. struct i40evf_mac_filter *ftmp;
  1587. struct i40evf_vlan_filter *fv, *fvtmp;
  1588. /* reset never finished */
  1589. dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n",
  1590. reg_val);
  1591. adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
  1592. if (netif_running(adapter->netdev)) {
  1593. set_bit(__I40E_DOWN, &adapter->vsi.state);
  1594. netif_carrier_off(netdev);
  1595. netif_tx_disable(netdev);
  1596. i40evf_napi_disable_all(adapter);
  1597. i40evf_irq_disable(adapter);
  1598. i40evf_free_traffic_irqs(adapter);
  1599. i40evf_free_all_tx_resources(adapter);
  1600. i40evf_free_all_rx_resources(adapter);
  1601. }
  1602. /* Delete all of the filters, both MAC and VLAN. */
  1603. list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list,
  1604. list) {
  1605. list_del(&f->list);
  1606. kfree(f);
  1607. }
  1608. list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list,
  1609. list) {
  1610. list_del(&fv->list);
  1611. kfree(fv);
  1612. }
  1613. i40evf_free_misc_irq(adapter);
  1614. i40evf_reset_interrupt_capability(adapter);
  1615. i40evf_free_queues(adapter);
  1616. i40evf_free_q_vectors(adapter);
  1617. kfree(adapter->vf_res);
  1618. i40evf_shutdown_adminq(hw);
  1619. adapter->netdev->flags &= ~IFF_UP;
  1620. clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
  1621. adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
  1622. dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n");
  1623. return; /* Do not attempt to reinit. It's dead, Jim. */
  1624. }
  1625. continue_reset:
  1626. if (netif_running(adapter->netdev)) {
  1627. netif_carrier_off(netdev);
  1628. netif_tx_stop_all_queues(netdev);
  1629. i40evf_napi_disable_all(adapter);
  1630. }
  1631. i40evf_irq_disable(adapter);
  1632. adapter->state = __I40EVF_RESETTING;
  1633. adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
  1634. /* free the Tx/Rx rings and descriptors, might be better to just
  1635. * re-use them sometime in the future
  1636. */
  1637. i40evf_free_all_rx_resources(adapter);
  1638. i40evf_free_all_tx_resources(adapter);
  1639. /* kill and reinit the admin queue */
  1640. if (i40evf_shutdown_adminq(hw))
  1641. dev_warn(&adapter->pdev->dev, "Failed to shut down adminq\n");
  1642. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  1643. err = i40evf_init_adminq(hw);
  1644. if (err)
  1645. dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n",
  1646. err);
  1647. adapter->aq_required = I40EVF_FLAG_AQ_GET_CONFIG;
  1648. adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
  1649. /* re-add all MAC filters */
  1650. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  1651. f->add = true;
  1652. }
  1653. /* re-add all VLAN filters */
  1654. list_for_each_entry(vlf, &adapter->vlan_filter_list, list) {
  1655. vlf->add = true;
  1656. }
  1657. adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  1658. adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  1659. clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
  1660. i40evf_misc_irq_enable(adapter);
  1661. mod_timer(&adapter->watchdog_timer, jiffies + 2);
  1662. if (netif_running(adapter->netdev)) {
  1663. /* allocate transmit descriptors */
  1664. err = i40evf_setup_all_tx_resources(adapter);
  1665. if (err)
  1666. goto reset_err;
  1667. /* allocate receive descriptors */
  1668. err = i40evf_setup_all_rx_resources(adapter);
  1669. if (err)
  1670. goto reset_err;
  1671. i40evf_configure(adapter);
  1672. err = i40evf_up_complete(adapter);
  1673. if (err)
  1674. goto reset_err;
  1675. i40evf_irq_enable(adapter, true);
  1676. } else {
  1677. adapter->state = __I40EVF_DOWN;
  1678. }
  1679. return;
  1680. reset_err:
  1681. dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
  1682. i40evf_close(adapter->netdev);
  1683. }
  1684. /**
  1685. * i40evf_adminq_task - worker thread to clean the admin queue
  1686. * @work: pointer to work_struct containing our data
  1687. **/
  1688. static void i40evf_adminq_task(struct work_struct *work)
  1689. {
  1690. struct i40evf_adapter *adapter =
  1691. container_of(work, struct i40evf_adapter, adminq_task);
  1692. struct i40e_hw *hw = &adapter->hw;
  1693. struct i40e_arq_event_info event;
  1694. struct i40e_virtchnl_msg *v_msg;
  1695. i40e_status ret;
  1696. u32 val, oldval;
  1697. u16 pending;
  1698. if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
  1699. goto out;
  1700. event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
  1701. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  1702. if (!event.msg_buf)
  1703. goto out;
  1704. v_msg = (struct i40e_virtchnl_msg *)&event.desc;
  1705. do {
  1706. ret = i40evf_clean_arq_element(hw, &event, &pending);
  1707. if (ret || !v_msg->v_opcode)
  1708. break; /* No event to process or error cleaning ARQ */
  1709. i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
  1710. v_msg->v_retval, event.msg_buf,
  1711. event.msg_len);
  1712. if (pending != 0)
  1713. memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
  1714. } while (pending);
  1715. if ((adapter->flags &
  1716. (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED)) ||
  1717. adapter->state == __I40EVF_RESETTING)
  1718. goto freedom;
  1719. /* check for error indications */
  1720. val = rd32(hw, hw->aq.arq.len);
  1721. oldval = val;
  1722. if (val & I40E_VF_ARQLEN1_ARQVFE_MASK) {
  1723. dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n");
  1724. val &= ~I40E_VF_ARQLEN1_ARQVFE_MASK;
  1725. }
  1726. if (val & I40E_VF_ARQLEN1_ARQOVFL_MASK) {
  1727. dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n");
  1728. val &= ~I40E_VF_ARQLEN1_ARQOVFL_MASK;
  1729. }
  1730. if (val & I40E_VF_ARQLEN1_ARQCRIT_MASK) {
  1731. dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n");
  1732. val &= ~I40E_VF_ARQLEN1_ARQCRIT_MASK;
  1733. }
  1734. if (oldval != val)
  1735. wr32(hw, hw->aq.arq.len, val);
  1736. val = rd32(hw, hw->aq.asq.len);
  1737. oldval = val;
  1738. if (val & I40E_VF_ATQLEN1_ATQVFE_MASK) {
  1739. dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n");
  1740. val &= ~I40E_VF_ATQLEN1_ATQVFE_MASK;
  1741. }
  1742. if (val & I40E_VF_ATQLEN1_ATQOVFL_MASK) {
  1743. dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n");
  1744. val &= ~I40E_VF_ATQLEN1_ATQOVFL_MASK;
  1745. }
  1746. if (val & I40E_VF_ATQLEN1_ATQCRIT_MASK) {
  1747. dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n");
  1748. val &= ~I40E_VF_ATQLEN1_ATQCRIT_MASK;
  1749. }
  1750. if (oldval != val)
  1751. wr32(hw, hw->aq.asq.len, val);
  1752. freedom:
  1753. kfree(event.msg_buf);
  1754. out:
  1755. /* re-enable Admin queue interrupt cause */
  1756. i40evf_misc_irq_enable(adapter);
  1757. }
  1758. /**
  1759. * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
  1760. * @adapter: board private structure
  1761. *
  1762. * Free all transmit software resources
  1763. **/
  1764. void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter)
  1765. {
  1766. int i;
  1767. for (i = 0; i < adapter->num_active_queues; i++)
  1768. if (adapter->tx_rings[i].desc)
  1769. i40evf_free_tx_resources(&adapter->tx_rings[i]);
  1770. }
  1771. /**
  1772. * i40evf_setup_all_tx_resources - allocate all queues Tx resources
  1773. * @adapter: board private structure
  1774. *
  1775. * If this function returns with an error, then it's possible one or
  1776. * more of the rings is populated (while the rest are not). It is the
  1777. * callers duty to clean those orphaned rings.
  1778. *
  1779. * Return 0 on success, negative on failure
  1780. **/
  1781. static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
  1782. {
  1783. int i, err = 0;
  1784. for (i = 0; i < adapter->num_active_queues; i++) {
  1785. adapter->tx_rings[i].count = adapter->tx_desc_count;
  1786. err = i40evf_setup_tx_descriptors(&adapter->tx_rings[i]);
  1787. if (!err)
  1788. continue;
  1789. dev_err(&adapter->pdev->dev,
  1790. "Allocation for Tx Queue %u failed\n", i);
  1791. break;
  1792. }
  1793. return err;
  1794. }
  1795. /**
  1796. * i40evf_setup_all_rx_resources - allocate all queues Rx resources
  1797. * @adapter: board private structure
  1798. *
  1799. * If this function returns with an error, then it's possible one or
  1800. * more of the rings is populated (while the rest are not). It is the
  1801. * callers duty to clean those orphaned rings.
  1802. *
  1803. * Return 0 on success, negative on failure
  1804. **/
  1805. static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
  1806. {
  1807. int i, err = 0;
  1808. for (i = 0; i < adapter->num_active_queues; i++) {
  1809. adapter->rx_rings[i].count = adapter->rx_desc_count;
  1810. err = i40evf_setup_rx_descriptors(&adapter->rx_rings[i]);
  1811. if (!err)
  1812. continue;
  1813. dev_err(&adapter->pdev->dev,
  1814. "Allocation for Rx Queue %u failed\n", i);
  1815. break;
  1816. }
  1817. return err;
  1818. }
  1819. /**
  1820. * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
  1821. * @adapter: board private structure
  1822. *
  1823. * Free all receive software resources
  1824. **/
  1825. void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter)
  1826. {
  1827. int i;
  1828. for (i = 0; i < adapter->num_active_queues; i++)
  1829. if (adapter->rx_rings[i].desc)
  1830. i40evf_free_rx_resources(&adapter->rx_rings[i]);
  1831. }
  1832. /**
  1833. * i40evf_open - Called when a network interface is made active
  1834. * @netdev: network interface device structure
  1835. *
  1836. * Returns 0 on success, negative value on failure
  1837. *
  1838. * The open entry point is called when a network interface is made
  1839. * active by the system (IFF_UP). At this point all resources needed
  1840. * for transmit and receive operations are allocated, the interrupt
  1841. * handler is registered with the OS, the watchdog timer is started,
  1842. * and the stack is notified that the interface is ready.
  1843. **/
  1844. static int i40evf_open(struct net_device *netdev)
  1845. {
  1846. struct i40evf_adapter *adapter = netdev_priv(netdev);
  1847. int err;
  1848. if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
  1849. dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
  1850. return -EIO;
  1851. }
  1852. if (adapter->state != __I40EVF_DOWN || adapter->aq_required)
  1853. return -EBUSY;
  1854. /* allocate transmit descriptors */
  1855. err = i40evf_setup_all_tx_resources(adapter);
  1856. if (err)
  1857. goto err_setup_tx;
  1858. /* allocate receive descriptors */
  1859. err = i40evf_setup_all_rx_resources(adapter);
  1860. if (err)
  1861. goto err_setup_rx;
  1862. /* clear any pending interrupts, may auto mask */
  1863. err = i40evf_request_traffic_irqs(adapter, netdev->name);
  1864. if (err)
  1865. goto err_req_irq;
  1866. i40evf_add_filter(adapter, adapter->hw.mac.addr);
  1867. i40evf_configure(adapter);
  1868. err = i40evf_up_complete(adapter);
  1869. if (err)
  1870. goto err_req_irq;
  1871. i40evf_irq_enable(adapter, true);
  1872. return 0;
  1873. err_req_irq:
  1874. i40evf_down(adapter);
  1875. i40evf_free_traffic_irqs(adapter);
  1876. err_setup_rx:
  1877. i40evf_free_all_rx_resources(adapter);
  1878. err_setup_tx:
  1879. i40evf_free_all_tx_resources(adapter);
  1880. return err;
  1881. }
  1882. /**
  1883. * i40evf_close - Disables a network interface
  1884. * @netdev: network interface device structure
  1885. *
  1886. * Returns 0, this is not allowed to fail
  1887. *
  1888. * The close entry point is called when an interface is de-activated
  1889. * by the OS. The hardware is still under the drivers control, but
  1890. * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
  1891. * are freed, along with all transmit and receive resources.
  1892. **/
  1893. static int i40evf_close(struct net_device *netdev)
  1894. {
  1895. struct i40evf_adapter *adapter = netdev_priv(netdev);
  1896. if (adapter->state <= __I40EVF_DOWN)
  1897. return 0;
  1898. set_bit(__I40E_DOWN, &adapter->vsi.state);
  1899. i40evf_down(adapter);
  1900. adapter->state = __I40EVF_DOWN;
  1901. i40evf_free_traffic_irqs(adapter);
  1902. return 0;
  1903. }
  1904. /**
  1905. * i40evf_get_stats - Get System Network Statistics
  1906. * @netdev: network interface device structure
  1907. *
  1908. * Returns the address of the device statistics structure.
  1909. * The statistics are actually updated from the timer callback.
  1910. **/
  1911. static struct net_device_stats *i40evf_get_stats(struct net_device *netdev)
  1912. {
  1913. struct i40evf_adapter *adapter = netdev_priv(netdev);
  1914. /* only return the current stats */
  1915. return &adapter->net_stats;
  1916. }
  1917. /**
  1918. * i40evf_change_mtu - Change the Maximum Transfer Unit
  1919. * @netdev: network interface device structure
  1920. * @new_mtu: new value for maximum frame size
  1921. *
  1922. * Returns 0 on success, negative on failure
  1923. **/
  1924. static int i40evf_change_mtu(struct net_device *netdev, int new_mtu)
  1925. {
  1926. struct i40evf_adapter *adapter = netdev_priv(netdev);
  1927. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  1928. if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
  1929. return -EINVAL;
  1930. netdev->mtu = new_mtu;
  1931. adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
  1932. schedule_work(&adapter->reset_task);
  1933. return 0;
  1934. }
  1935. static const struct net_device_ops i40evf_netdev_ops = {
  1936. .ndo_open = i40evf_open,
  1937. .ndo_stop = i40evf_close,
  1938. .ndo_start_xmit = i40evf_xmit_frame,
  1939. .ndo_get_stats = i40evf_get_stats,
  1940. .ndo_set_rx_mode = i40evf_set_rx_mode,
  1941. .ndo_validate_addr = eth_validate_addr,
  1942. .ndo_set_mac_address = i40evf_set_mac,
  1943. .ndo_change_mtu = i40evf_change_mtu,
  1944. .ndo_tx_timeout = i40evf_tx_timeout,
  1945. .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid,
  1946. .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid,
  1947. #ifdef CONFIG_NET_POLL_CONTROLLER
  1948. .ndo_poll_controller = i40evf_netpoll,
  1949. #endif
  1950. };
  1951. /**
  1952. * i40evf_check_reset_complete - check that VF reset is complete
  1953. * @hw: pointer to hw struct
  1954. *
  1955. * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
  1956. **/
  1957. static int i40evf_check_reset_complete(struct i40e_hw *hw)
  1958. {
  1959. u32 rstat;
  1960. int i;
  1961. for (i = 0; i < 100; i++) {
  1962. rstat = rd32(hw, I40E_VFGEN_RSTAT) &
  1963. I40E_VFGEN_RSTAT_VFR_STATE_MASK;
  1964. if ((rstat == I40E_VFR_VFACTIVE) ||
  1965. (rstat == I40E_VFR_COMPLETED))
  1966. return 0;
  1967. usleep_range(10, 20);
  1968. }
  1969. return -EBUSY;
  1970. }
  1971. /**
  1972. * i40evf_process_config - Process the config information we got from the PF
  1973. * @adapter: board private structure
  1974. *
  1975. * Verify that we have a valid config struct, and set up our netdev features
  1976. * and our VSI struct.
  1977. **/
  1978. int i40evf_process_config(struct i40evf_adapter *adapter)
  1979. {
  1980. struct net_device *netdev = adapter->netdev;
  1981. int i;
  1982. /* got VF config message back from PF, now we can parse it */
  1983. for (i = 0; i < adapter->vf_res->num_vsis; i++) {
  1984. if (adapter->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
  1985. adapter->vsi_res = &adapter->vf_res->vsi_res[i];
  1986. }
  1987. if (!adapter->vsi_res) {
  1988. dev_err(&adapter->pdev->dev, "No LAN VSI found\n");
  1989. return -ENODEV;
  1990. }
  1991. if (adapter->vf_res->vf_offload_flags
  1992. & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) {
  1993. netdev->vlan_features = netdev->features &
  1994. ~(NETIF_F_HW_VLAN_CTAG_TX |
  1995. NETIF_F_HW_VLAN_CTAG_RX |
  1996. NETIF_F_HW_VLAN_CTAG_FILTER);
  1997. netdev->features |= NETIF_F_HW_VLAN_CTAG_TX |
  1998. NETIF_F_HW_VLAN_CTAG_RX |
  1999. NETIF_F_HW_VLAN_CTAG_FILTER;
  2000. }
  2001. netdev->features |= NETIF_F_HIGHDMA |
  2002. NETIF_F_SG |
  2003. NETIF_F_IP_CSUM |
  2004. NETIF_F_SCTP_CSUM |
  2005. NETIF_F_IPV6_CSUM |
  2006. NETIF_F_TSO |
  2007. NETIF_F_TSO6 |
  2008. NETIF_F_RXCSUM |
  2009. NETIF_F_GRO;
  2010. /* copy netdev features into list of user selectable features */
  2011. netdev->hw_features |= netdev->features;
  2012. netdev->hw_features &= ~NETIF_F_RXCSUM;
  2013. adapter->vsi.id = adapter->vsi_res->vsi_id;
  2014. adapter->vsi.back = adapter;
  2015. adapter->vsi.base_vector = 1;
  2016. adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK;
  2017. adapter->vsi.rx_itr_setting = (I40E_ITR_DYNAMIC |
  2018. ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
  2019. adapter->vsi.tx_itr_setting = (I40E_ITR_DYNAMIC |
  2020. ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
  2021. adapter->vsi.netdev = adapter->netdev;
  2022. adapter->vsi.qs_handle = adapter->vsi_res->qset_handle;
  2023. return 0;
  2024. }
  2025. /**
  2026. * i40evf_init_task - worker thread to perform delayed initialization
  2027. * @work: pointer to work_struct containing our data
  2028. *
  2029. * This task completes the work that was begun in probe. Due to the nature
  2030. * of VF-PF communications, we may need to wait tens of milliseconds to get
  2031. * responses back from the PF. Rather than busy-wait in probe and bog down the
  2032. * whole system, we'll do it in a task so we can sleep.
  2033. * This task only runs during driver init. Once we've established
  2034. * communications with the PF driver and set up our netdev, the watchdog
  2035. * takes over.
  2036. **/
  2037. static void i40evf_init_task(struct work_struct *work)
  2038. {
  2039. struct i40evf_adapter *adapter = container_of(work,
  2040. struct i40evf_adapter,
  2041. init_task.work);
  2042. struct net_device *netdev = adapter->netdev;
  2043. struct i40e_hw *hw = &adapter->hw;
  2044. struct pci_dev *pdev = adapter->pdev;
  2045. int err, bufsz;
  2046. switch (adapter->state) {
  2047. case __I40EVF_STARTUP:
  2048. /* driver loaded, probe complete */
  2049. adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
  2050. adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
  2051. err = i40e_set_mac_type(hw);
  2052. if (err) {
  2053. dev_err(&pdev->dev, "Failed to set MAC type (%d)\n",
  2054. err);
  2055. goto err;
  2056. }
  2057. err = i40evf_check_reset_complete(hw);
  2058. if (err) {
  2059. dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n",
  2060. err);
  2061. goto err;
  2062. }
  2063. hw->aq.num_arq_entries = I40EVF_AQ_LEN;
  2064. hw->aq.num_asq_entries = I40EVF_AQ_LEN;
  2065. hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
  2066. hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
  2067. err = i40evf_init_adminq(hw);
  2068. if (err) {
  2069. dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n",
  2070. err);
  2071. goto err;
  2072. }
  2073. err = i40evf_send_api_ver(adapter);
  2074. if (err) {
  2075. dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err);
  2076. i40evf_shutdown_adminq(hw);
  2077. goto err;
  2078. }
  2079. adapter->state = __I40EVF_INIT_VERSION_CHECK;
  2080. goto restart;
  2081. case __I40EVF_INIT_VERSION_CHECK:
  2082. if (!i40evf_asq_done(hw)) {
  2083. dev_err(&pdev->dev, "Admin queue command never completed\n");
  2084. i40evf_shutdown_adminq(hw);
  2085. adapter->state = __I40EVF_STARTUP;
  2086. goto err;
  2087. }
  2088. /* aq msg sent, awaiting reply */
  2089. err = i40evf_verify_api_ver(adapter);
  2090. if (err) {
  2091. if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  2092. err = i40evf_send_api_ver(adapter);
  2093. else
  2094. dev_err(&pdev->dev, "Unsupported PF API version %d.%d, expected %d.%d\n",
  2095. adapter->pf_version.major,
  2096. adapter->pf_version.minor,
  2097. I40E_VIRTCHNL_VERSION_MAJOR,
  2098. I40E_VIRTCHNL_VERSION_MINOR);
  2099. goto err;
  2100. }
  2101. err = i40evf_send_vf_config_msg(adapter);
  2102. if (err) {
  2103. dev_err(&pdev->dev, "Unable to send config request (%d)\n",
  2104. err);
  2105. goto err;
  2106. }
  2107. adapter->state = __I40EVF_INIT_GET_RESOURCES;
  2108. goto restart;
  2109. case __I40EVF_INIT_GET_RESOURCES:
  2110. /* aq msg sent, awaiting reply */
  2111. if (!adapter->vf_res) {
  2112. bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
  2113. (I40E_MAX_VF_VSI *
  2114. sizeof(struct i40e_virtchnl_vsi_resource));
  2115. adapter->vf_res = kzalloc(bufsz, GFP_KERNEL);
  2116. if (!adapter->vf_res)
  2117. goto err;
  2118. }
  2119. err = i40evf_get_vf_config(adapter);
  2120. if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
  2121. err = i40evf_send_vf_config_msg(adapter);
  2122. goto err;
  2123. } else if (err == I40E_ERR_PARAM) {
  2124. /* We only get ERR_PARAM if the device is in a very bad
  2125. * state or if we've been disabled for previous bad
  2126. * behavior. Either way, we're done now.
  2127. */
  2128. i40evf_shutdown_adminq(hw);
  2129. dev_err(&pdev->dev, "Unable to get VF config due to PF error condition, not retrying\n");
  2130. return;
  2131. }
  2132. if (err) {
  2133. dev_err(&pdev->dev, "Unable to get VF config (%d)\n",
  2134. err);
  2135. goto err_alloc;
  2136. }
  2137. adapter->state = __I40EVF_INIT_SW;
  2138. break;
  2139. default:
  2140. goto err_alloc;
  2141. }
  2142. if (i40evf_process_config(adapter))
  2143. goto err_alloc;
  2144. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  2145. adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED;
  2146. netdev->netdev_ops = &i40evf_netdev_ops;
  2147. i40evf_set_ethtool_ops(netdev);
  2148. netdev->watchdog_timeo = 5 * HZ;
  2149. if (!is_valid_ether_addr(adapter->hw.mac.addr)) {
  2150. dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n",
  2151. adapter->hw.mac.addr);
  2152. eth_hw_addr_random(netdev);
  2153. ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
  2154. } else {
  2155. adapter->flags |= I40EVF_FLAG_ADDR_SET_BY_PF;
  2156. ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
  2157. ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr);
  2158. }
  2159. init_timer(&adapter->watchdog_timer);
  2160. adapter->watchdog_timer.function = &i40evf_watchdog_timer;
  2161. adapter->watchdog_timer.data = (unsigned long)adapter;
  2162. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  2163. adapter->num_active_queues = min_t(int,
  2164. adapter->vsi_res->num_queue_pairs,
  2165. (int)(num_online_cpus()));
  2166. adapter->tx_desc_count = I40EVF_DEFAULT_TXD;
  2167. adapter->rx_desc_count = I40EVF_DEFAULT_RXD;
  2168. err = i40evf_init_interrupt_scheme(adapter);
  2169. if (err)
  2170. goto err_sw_init;
  2171. i40evf_map_rings_to_vectors(adapter);
  2172. if (adapter->vf_res->vf_offload_flags &
  2173. I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
  2174. adapter->flags |= I40EVF_FLAG_WB_ON_ITR_CAPABLE;
  2175. if (!RSS_AQ(adapter))
  2176. i40evf_init_rss(adapter);
  2177. err = i40evf_request_misc_irq(adapter);
  2178. if (err)
  2179. goto err_sw_init;
  2180. netif_carrier_off(netdev);
  2181. if (!adapter->netdev_registered) {
  2182. err = register_netdev(netdev);
  2183. if (err)
  2184. goto err_register;
  2185. }
  2186. adapter->netdev_registered = true;
  2187. netif_tx_stop_all_queues(netdev);
  2188. dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr);
  2189. if (netdev->features & NETIF_F_GRO)
  2190. dev_info(&pdev->dev, "GRO is enabled\n");
  2191. adapter->state = __I40EVF_DOWN;
  2192. set_bit(__I40E_DOWN, &adapter->vsi.state);
  2193. i40evf_misc_irq_enable(adapter);
  2194. if (RSS_AQ(adapter)) {
  2195. adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_RSS;
  2196. mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
  2197. } else {
  2198. i40evf_init_rss(adapter);
  2199. }
  2200. return;
  2201. restart:
  2202. schedule_delayed_work(&adapter->init_task, msecs_to_jiffies(30));
  2203. return;
  2204. err_register:
  2205. i40evf_free_misc_irq(adapter);
  2206. err_sw_init:
  2207. i40evf_reset_interrupt_capability(adapter);
  2208. err_alloc:
  2209. kfree(adapter->vf_res);
  2210. adapter->vf_res = NULL;
  2211. err:
  2212. /* Things went into the weeds, so try again later */
  2213. if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) {
  2214. dev_err(&pdev->dev, "Failed to communicate with PF; waiting before retry\n");
  2215. adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
  2216. i40evf_shutdown_adminq(hw);
  2217. adapter->state = __I40EVF_STARTUP;
  2218. schedule_delayed_work(&adapter->init_task, HZ * 5);
  2219. return;
  2220. }
  2221. schedule_delayed_work(&adapter->init_task, HZ);
  2222. }
  2223. /**
  2224. * i40evf_shutdown - Shutdown the device in preparation for a reboot
  2225. * @pdev: pci device structure
  2226. **/
  2227. static void i40evf_shutdown(struct pci_dev *pdev)
  2228. {
  2229. struct net_device *netdev = pci_get_drvdata(pdev);
  2230. struct i40evf_adapter *adapter = netdev_priv(netdev);
  2231. netif_device_detach(netdev);
  2232. if (netif_running(netdev))
  2233. i40evf_close(netdev);
  2234. /* Prevent the watchdog from running. */
  2235. adapter->state = __I40EVF_REMOVE;
  2236. adapter->aq_required = 0;
  2237. #ifdef CONFIG_PM
  2238. pci_save_state(pdev);
  2239. #endif
  2240. pci_disable_device(pdev);
  2241. }
  2242. /**
  2243. * i40evf_probe - Device Initialization Routine
  2244. * @pdev: PCI device information struct
  2245. * @ent: entry in i40evf_pci_tbl
  2246. *
  2247. * Returns 0 on success, negative on failure
  2248. *
  2249. * i40evf_probe initializes an adapter identified by a pci_dev structure.
  2250. * The OS initialization, configuring of the adapter private structure,
  2251. * and a hardware reset occur.
  2252. **/
  2253. static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  2254. {
  2255. struct net_device *netdev;
  2256. struct i40evf_adapter *adapter = NULL;
  2257. struct i40e_hw *hw = NULL;
  2258. int err;
  2259. err = pci_enable_device(pdev);
  2260. if (err)
  2261. return err;
  2262. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  2263. if (err) {
  2264. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  2265. if (err) {
  2266. dev_err(&pdev->dev,
  2267. "DMA configuration failed: 0x%x\n", err);
  2268. goto err_dma;
  2269. }
  2270. }
  2271. err = pci_request_regions(pdev, i40evf_driver_name);
  2272. if (err) {
  2273. dev_err(&pdev->dev,
  2274. "pci_request_regions failed 0x%x\n", err);
  2275. goto err_pci_reg;
  2276. }
  2277. pci_enable_pcie_error_reporting(pdev);
  2278. pci_set_master(pdev);
  2279. netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter), MAX_QUEUES);
  2280. if (!netdev) {
  2281. err = -ENOMEM;
  2282. goto err_alloc_etherdev;
  2283. }
  2284. SET_NETDEV_DEV(netdev, &pdev->dev);
  2285. pci_set_drvdata(pdev, netdev);
  2286. adapter = netdev_priv(netdev);
  2287. adapter->netdev = netdev;
  2288. adapter->pdev = pdev;
  2289. hw = &adapter->hw;
  2290. hw->back = adapter;
  2291. adapter->msg_enable = BIT(DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
  2292. adapter->state = __I40EVF_STARTUP;
  2293. /* Call save state here because it relies on the adapter struct. */
  2294. pci_save_state(pdev);
  2295. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  2296. pci_resource_len(pdev, 0));
  2297. if (!hw->hw_addr) {
  2298. err = -EIO;
  2299. goto err_ioremap;
  2300. }
  2301. hw->vendor_id = pdev->vendor;
  2302. hw->device_id = pdev->device;
  2303. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  2304. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  2305. hw->subsystem_device_id = pdev->subsystem_device;
  2306. hw->bus.device = PCI_SLOT(pdev->devfn);
  2307. hw->bus.func = PCI_FUNC(pdev->devfn);
  2308. INIT_LIST_HEAD(&adapter->mac_filter_list);
  2309. INIT_LIST_HEAD(&adapter->vlan_filter_list);
  2310. INIT_WORK(&adapter->reset_task, i40evf_reset_task);
  2311. INIT_WORK(&adapter->adminq_task, i40evf_adminq_task);
  2312. INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task);
  2313. INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task);
  2314. schedule_delayed_work(&adapter->init_task,
  2315. msecs_to_jiffies(5 * (pdev->devfn & 0x07)));
  2316. return 0;
  2317. err_ioremap:
  2318. free_netdev(netdev);
  2319. err_alloc_etherdev:
  2320. pci_release_regions(pdev);
  2321. err_pci_reg:
  2322. err_dma:
  2323. pci_disable_device(pdev);
  2324. return err;
  2325. }
  2326. #ifdef CONFIG_PM
  2327. /**
  2328. * i40evf_suspend - Power management suspend routine
  2329. * @pdev: PCI device information struct
  2330. * @state: unused
  2331. *
  2332. * Called when the system (VM) is entering sleep/suspend.
  2333. **/
  2334. static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state)
  2335. {
  2336. struct net_device *netdev = pci_get_drvdata(pdev);
  2337. struct i40evf_adapter *adapter = netdev_priv(netdev);
  2338. int retval = 0;
  2339. netif_device_detach(netdev);
  2340. if (netif_running(netdev)) {
  2341. rtnl_lock();
  2342. i40evf_down(adapter);
  2343. rtnl_unlock();
  2344. }
  2345. i40evf_free_misc_irq(adapter);
  2346. i40evf_reset_interrupt_capability(adapter);
  2347. retval = pci_save_state(pdev);
  2348. if (retval)
  2349. return retval;
  2350. pci_disable_device(pdev);
  2351. return 0;
  2352. }
  2353. /**
  2354. * i40evf_resume - Power management resume routine
  2355. * @pdev: PCI device information struct
  2356. *
  2357. * Called when the system (VM) is resumed from sleep/suspend.
  2358. **/
  2359. static int i40evf_resume(struct pci_dev *pdev)
  2360. {
  2361. struct i40evf_adapter *adapter = pci_get_drvdata(pdev);
  2362. struct net_device *netdev = adapter->netdev;
  2363. u32 err;
  2364. pci_set_power_state(pdev, PCI_D0);
  2365. pci_restore_state(pdev);
  2366. /* pci_restore_state clears dev->state_saved so call
  2367. * pci_save_state to restore it.
  2368. */
  2369. pci_save_state(pdev);
  2370. err = pci_enable_device_mem(pdev);
  2371. if (err) {
  2372. dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
  2373. return err;
  2374. }
  2375. pci_set_master(pdev);
  2376. rtnl_lock();
  2377. err = i40evf_set_interrupt_capability(adapter);
  2378. if (err) {
  2379. rtnl_unlock();
  2380. dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
  2381. return err;
  2382. }
  2383. err = i40evf_request_misc_irq(adapter);
  2384. rtnl_unlock();
  2385. if (err) {
  2386. dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
  2387. return err;
  2388. }
  2389. schedule_work(&adapter->reset_task);
  2390. netif_device_attach(netdev);
  2391. return err;
  2392. }
  2393. #endif /* CONFIG_PM */
  2394. /**
  2395. * i40evf_remove - Device Removal Routine
  2396. * @pdev: PCI device information struct
  2397. *
  2398. * i40evf_remove is called by the PCI subsystem to alert the driver
  2399. * that it should release a PCI device. The could be caused by a
  2400. * Hot-Plug event, or because the driver is going to be removed from
  2401. * memory.
  2402. **/
  2403. static void i40evf_remove(struct pci_dev *pdev)
  2404. {
  2405. struct net_device *netdev = pci_get_drvdata(pdev);
  2406. struct i40evf_adapter *adapter = netdev_priv(netdev);
  2407. struct i40evf_mac_filter *f, *ftmp;
  2408. struct i40e_hw *hw = &adapter->hw;
  2409. cancel_delayed_work_sync(&adapter->init_task);
  2410. cancel_work_sync(&adapter->reset_task);
  2411. if (adapter->netdev_registered) {
  2412. unregister_netdev(netdev);
  2413. adapter->netdev_registered = false;
  2414. }
  2415. /* Shut down all the garbage mashers on the detention level */
  2416. adapter->state = __I40EVF_REMOVE;
  2417. adapter->aq_required = 0;
  2418. i40evf_request_reset(adapter);
  2419. msleep(20);
  2420. /* If the FW isn't responding, kick it once, but only once. */
  2421. if (!i40evf_asq_done(hw)) {
  2422. i40evf_request_reset(adapter);
  2423. msleep(20);
  2424. }
  2425. if (adapter->msix_entries) {
  2426. i40evf_misc_irq_disable(adapter);
  2427. i40evf_free_misc_irq(adapter);
  2428. i40evf_reset_interrupt_capability(adapter);
  2429. i40evf_free_q_vectors(adapter);
  2430. }
  2431. if (adapter->watchdog_timer.function)
  2432. del_timer_sync(&adapter->watchdog_timer);
  2433. flush_scheduled_work();
  2434. /* Clear user configurations for RSS */
  2435. i40evf_clear_rss_config_user(&adapter->vsi);
  2436. if (hw->aq.asq.count)
  2437. i40evf_shutdown_adminq(hw);
  2438. iounmap(hw->hw_addr);
  2439. pci_release_regions(pdev);
  2440. i40evf_free_all_tx_resources(adapter);
  2441. i40evf_free_all_rx_resources(adapter);
  2442. i40evf_free_queues(adapter);
  2443. kfree(adapter->vf_res);
  2444. /* If we got removed before an up/down sequence, we've got a filter
  2445. * hanging out there that we need to get rid of.
  2446. */
  2447. list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
  2448. list_del(&f->list);
  2449. kfree(f);
  2450. }
  2451. list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
  2452. list_del(&f->list);
  2453. kfree(f);
  2454. }
  2455. free_netdev(netdev);
  2456. pci_disable_pcie_error_reporting(pdev);
  2457. pci_disable_device(pdev);
  2458. }
  2459. static struct pci_driver i40evf_driver = {
  2460. .name = i40evf_driver_name,
  2461. .id_table = i40evf_pci_tbl,
  2462. .probe = i40evf_probe,
  2463. .remove = i40evf_remove,
  2464. #ifdef CONFIG_PM
  2465. .suspend = i40evf_suspend,
  2466. .resume = i40evf_resume,
  2467. #endif
  2468. .shutdown = i40evf_shutdown,
  2469. };
  2470. /**
  2471. * i40e_init_module - Driver Registration Routine
  2472. *
  2473. * i40e_init_module is the first routine called when the driver is
  2474. * loaded. All it does is register with the PCI subsystem.
  2475. **/
  2476. static int __init i40evf_init_module(void)
  2477. {
  2478. int ret;
  2479. pr_info("i40evf: %s - version %s\n", i40evf_driver_string,
  2480. i40evf_driver_version);
  2481. pr_info("%s\n", i40evf_copyright);
  2482. ret = pci_register_driver(&i40evf_driver);
  2483. return ret;
  2484. }
  2485. module_init(i40evf_init_module);
  2486. /**
  2487. * i40e_exit_module - Driver Exit Cleanup Routine
  2488. *
  2489. * i40e_exit_module is called just before the driver is removed
  2490. * from memory.
  2491. **/
  2492. static void __exit i40evf_exit_module(void)
  2493. {
  2494. pci_unregister_driver(&i40evf_driver);
  2495. }
  2496. module_exit(i40evf_exit_module);
  2497. /* i40evf_main.c */