i40evf_main.c 78 KB

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