i40evf_main.c 76 KB

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