i40evf_main.c 76 KB

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