i40evf_main.c 76 KB

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