i40evf_main.c 76 KB

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