i40evf_main.c 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861
  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 int i40evf_up_complete(struct i40evf_adapter *adapter)
  874. {
  875. adapter->state = __I40EVF_RUNNING;
  876. clear_bit(__I40E_DOWN, &adapter->vsi.state);
  877. i40evf_napi_enable_all(adapter);
  878. adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
  879. mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
  880. return 0;
  881. }
  882. /**
  883. * i40e_down - Shutdown the connection processing
  884. * @adapter: board private structure
  885. **/
  886. void i40evf_down(struct i40evf_adapter *adapter)
  887. {
  888. struct net_device *netdev = adapter->netdev;
  889. struct i40evf_mac_filter *f;
  890. if (adapter->state <= __I40EVF_DOWN_PENDING)
  891. return;
  892. while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
  893. &adapter->crit_section))
  894. usleep_range(500, 1000);
  895. netif_carrier_off(netdev);
  896. netif_tx_disable(netdev);
  897. i40evf_napi_disable_all(adapter);
  898. i40evf_irq_disable(adapter);
  899. /* remove all MAC filters */
  900. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  901. f->remove = true;
  902. }
  903. /* remove all VLAN filters */
  904. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  905. f->remove = true;
  906. }
  907. if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) &&
  908. adapter->state != __I40EVF_RESETTING) {
  909. /* cancel any current operation */
  910. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  911. /* Schedule operations to close down the HW. Don't wait
  912. * here for this to complete. The watchdog is still running
  913. * and it will take care of this.
  914. */
  915. adapter->aq_required = I40EVF_FLAG_AQ_DEL_MAC_FILTER;
  916. adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
  917. adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
  918. }
  919. clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
  920. }
  921. /**
  922. * i40evf_acquire_msix_vectors - Setup the MSIX capability
  923. * @adapter: board private structure
  924. * @vectors: number of vectors to request
  925. *
  926. * Work with the OS to set up the MSIX vectors needed.
  927. *
  928. * Returns 0 on success, negative on failure
  929. **/
  930. static int
  931. i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors)
  932. {
  933. int err, vector_threshold;
  934. /* We'll want at least 3 (vector_threshold):
  935. * 0) Other (Admin Queue and link, mostly)
  936. * 1) TxQ[0] Cleanup
  937. * 2) RxQ[0] Cleanup
  938. */
  939. vector_threshold = MIN_MSIX_COUNT;
  940. /* The more we get, the more we will assign to Tx/Rx Cleanup
  941. * for the separate queues...where Rx Cleanup >= Tx Cleanup.
  942. * Right now, we simply care about how many we'll get; we'll
  943. * set them up later while requesting irq's.
  944. */
  945. err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
  946. vector_threshold, vectors);
  947. if (err < 0) {
  948. dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n");
  949. kfree(adapter->msix_entries);
  950. adapter->msix_entries = NULL;
  951. return err;
  952. }
  953. /* Adjust for only the vectors we'll use, which is minimum
  954. * of max_msix_q_vectors + NONQ_VECS, or the number of
  955. * vectors we were allocated.
  956. */
  957. adapter->num_msix_vectors = err;
  958. return 0;
  959. }
  960. /**
  961. * i40evf_free_queues - Free memory for all rings
  962. * @adapter: board private structure to initialize
  963. *
  964. * Free all of the memory associated with queue pairs.
  965. **/
  966. static void i40evf_free_queues(struct i40evf_adapter *adapter)
  967. {
  968. if (!adapter->vsi_res)
  969. return;
  970. kfree(adapter->tx_rings);
  971. adapter->tx_rings = NULL;
  972. kfree(adapter->rx_rings);
  973. adapter->rx_rings = NULL;
  974. }
  975. /**
  976. * i40evf_alloc_queues - Allocate memory for all rings
  977. * @adapter: board private structure to initialize
  978. *
  979. * We allocate one ring per queue at run-time since we don't know the
  980. * number of queues at compile-time. The polling_netdev array is
  981. * intended for Multiqueue, but should work fine with a single queue.
  982. **/
  983. static int i40evf_alloc_queues(struct i40evf_adapter *adapter)
  984. {
  985. int i;
  986. adapter->tx_rings = kcalloc(adapter->num_active_queues,
  987. sizeof(struct i40e_ring), GFP_KERNEL);
  988. if (!adapter->tx_rings)
  989. goto err_out;
  990. adapter->rx_rings = kcalloc(adapter->num_active_queues,
  991. sizeof(struct i40e_ring), GFP_KERNEL);
  992. if (!adapter->rx_rings)
  993. goto err_out;
  994. for (i = 0; i < adapter->num_active_queues; i++) {
  995. struct i40e_ring *tx_ring;
  996. struct i40e_ring *rx_ring;
  997. tx_ring = &adapter->tx_rings[i];
  998. tx_ring->queue_index = i;
  999. tx_ring->netdev = adapter->netdev;
  1000. tx_ring->dev = &adapter->pdev->dev;
  1001. tx_ring->count = adapter->tx_desc_count;
  1002. if (adapter->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
  1003. tx_ring->flags |= I40E_TXR_FLAGS_WB_ON_ITR;
  1004. rx_ring = &adapter->rx_rings[i];
  1005. rx_ring->queue_index = i;
  1006. rx_ring->netdev = adapter->netdev;
  1007. rx_ring->dev = &adapter->pdev->dev;
  1008. rx_ring->count = adapter->rx_desc_count;
  1009. }
  1010. return 0;
  1011. err_out:
  1012. i40evf_free_queues(adapter);
  1013. return -ENOMEM;
  1014. }
  1015. /**
  1016. * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
  1017. * @adapter: board private structure to initialize
  1018. *
  1019. * Attempt to configure the interrupts using the best available
  1020. * capabilities of the hardware and the kernel.
  1021. **/
  1022. static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter)
  1023. {
  1024. int vector, v_budget;
  1025. int pairs = 0;
  1026. int err = 0;
  1027. if (!adapter->vsi_res) {
  1028. err = -EIO;
  1029. goto out;
  1030. }
  1031. pairs = adapter->num_active_queues;
  1032. /* It's easy to be greedy for MSI-X vectors, but it really
  1033. * doesn't do us much good if we have a lot more vectors
  1034. * than CPU's. So let's be conservative and only ask for
  1035. * (roughly) twice the number of vectors as there are CPU's.
  1036. */
  1037. v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS;
  1038. v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors);
  1039. adapter->msix_entries = kcalloc(v_budget,
  1040. sizeof(struct msix_entry), GFP_KERNEL);
  1041. if (!adapter->msix_entries) {
  1042. err = -ENOMEM;
  1043. goto out;
  1044. }
  1045. for (vector = 0; vector < v_budget; vector++)
  1046. adapter->msix_entries[vector].entry = vector;
  1047. err = i40evf_acquire_msix_vectors(adapter, v_budget);
  1048. out:
  1049. netif_set_real_num_rx_queues(adapter->netdev, pairs);
  1050. netif_set_real_num_tx_queues(adapter->netdev, pairs);
  1051. return err;
  1052. }
  1053. /**
  1054. * i40e_config_rss_aq - Configure RSS keys and lut by using AQ commands
  1055. * @adapter: board private structure
  1056. *
  1057. * Return 0 on success, negative on failure
  1058. **/
  1059. static int i40evf_config_rss_aq(struct i40evf_adapter *adapter)
  1060. {
  1061. struct i40e_aqc_get_set_rss_key_data *rss_key =
  1062. (struct i40e_aqc_get_set_rss_key_data *)adapter->rss_key;
  1063. struct i40e_hw *hw = &adapter->hw;
  1064. int ret = 0;
  1065. if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
  1066. /* bail because we already have a command pending */
  1067. dev_err(&adapter->pdev->dev, "Cannot configure RSS, command %d pending\n",
  1068. adapter->current_op);
  1069. return -EBUSY;
  1070. }
  1071. ret = i40evf_aq_set_rss_key(hw, adapter->vsi.id, rss_key);
  1072. if (ret) {
  1073. dev_err(&adapter->pdev->dev, "Cannot set RSS key, err %s aq_err %s\n",
  1074. i40evf_stat_str(hw, ret),
  1075. i40evf_aq_str(hw, hw->aq.asq_last_status));
  1076. return ret;
  1077. }
  1078. ret = i40evf_aq_set_rss_lut(hw, adapter->vsi.id, false,
  1079. adapter->rss_lut, adapter->rss_lut_size);
  1080. if (ret) {
  1081. dev_err(&adapter->pdev->dev, "Cannot set RSS lut, err %s aq_err %s\n",
  1082. i40evf_stat_str(hw, ret),
  1083. i40evf_aq_str(hw, hw->aq.asq_last_status));
  1084. }
  1085. return ret;
  1086. }
  1087. /**
  1088. * i40evf_config_rss_reg - Configure RSS keys and lut by writing registers
  1089. * @adapter: board private structure
  1090. *
  1091. * Returns 0 on success, negative on failure
  1092. **/
  1093. static int i40evf_config_rss_reg(struct i40evf_adapter *adapter)
  1094. {
  1095. struct i40e_hw *hw = &adapter->hw;
  1096. u32 *dw;
  1097. u16 i;
  1098. dw = (u32 *)adapter->rss_key;
  1099. for (i = 0; i <= adapter->rss_key_size / 4; i++)
  1100. wr32(hw, I40E_VFQF_HKEY(i), dw[i]);
  1101. dw = (u32 *)adapter->rss_lut;
  1102. for (i = 0; i <= adapter->rss_lut_size / 4; i++)
  1103. wr32(hw, I40E_VFQF_HLUT(i), dw[i]);
  1104. i40e_flush(hw);
  1105. return 0;
  1106. }
  1107. /**
  1108. * i40evf_config_rss - Configure RSS keys and lut
  1109. * @adapter: board private structure
  1110. *
  1111. * Returns 0 on success, negative on failure
  1112. **/
  1113. int i40evf_config_rss(struct i40evf_adapter *adapter)
  1114. {
  1115. if (RSS_PF(adapter)) {
  1116. adapter->aq_required |= I40EVF_FLAG_AQ_SET_RSS_LUT |
  1117. I40EVF_FLAG_AQ_SET_RSS_KEY;
  1118. return 0;
  1119. } else if (RSS_AQ(adapter)) {
  1120. return i40evf_config_rss_aq(adapter);
  1121. } else {
  1122. return i40evf_config_rss_reg(adapter);
  1123. }
  1124. }
  1125. /**
  1126. * i40evf_fill_rss_lut - Fill the lut with default values
  1127. * @adapter: board private structure
  1128. **/
  1129. static void i40evf_fill_rss_lut(struct i40evf_adapter *adapter)
  1130. {
  1131. u16 i;
  1132. for (i = 0; i < adapter->rss_lut_size; i++)
  1133. adapter->rss_lut[i] = i % adapter->num_active_queues;
  1134. }
  1135. /**
  1136. * i40evf_init_rss - Prepare for RSS
  1137. * @adapter: board private structure
  1138. *
  1139. * Return 0 on success, negative on failure
  1140. **/
  1141. static int i40evf_init_rss(struct i40evf_adapter *adapter)
  1142. {
  1143. struct i40e_hw *hw = &adapter->hw;
  1144. int ret;
  1145. if (!RSS_PF(adapter)) {
  1146. /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
  1147. if (adapter->vf_res->vf_offload_flags &
  1148. I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
  1149. adapter->hena = I40E_DEFAULT_RSS_HENA_EXPANDED;
  1150. else
  1151. adapter->hena = I40E_DEFAULT_RSS_HENA;
  1152. wr32(hw, I40E_VFQF_HENA(0), (u32)adapter->hena);
  1153. wr32(hw, I40E_VFQF_HENA(1), (u32)(adapter->hena >> 32));
  1154. }
  1155. i40evf_fill_rss_lut(adapter);
  1156. netdev_rss_key_fill((void *)adapter->rss_key, adapter->rss_key_size);
  1157. ret = i40evf_config_rss(adapter);
  1158. return ret;
  1159. }
  1160. /**
  1161. * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
  1162. * @adapter: board private structure to initialize
  1163. *
  1164. * We allocate one q_vector per queue interrupt. If allocation fails we
  1165. * return -ENOMEM.
  1166. **/
  1167. static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter)
  1168. {
  1169. int q_idx = 0, num_q_vectors;
  1170. struct i40e_q_vector *q_vector;
  1171. num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  1172. adapter->q_vectors = kcalloc(num_q_vectors, sizeof(*q_vector),
  1173. GFP_KERNEL);
  1174. if (!adapter->q_vectors)
  1175. return -ENOMEM;
  1176. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  1177. q_vector = &adapter->q_vectors[q_idx];
  1178. q_vector->adapter = adapter;
  1179. q_vector->vsi = &adapter->vsi;
  1180. q_vector->v_idx = q_idx;
  1181. netif_napi_add(adapter->netdev, &q_vector->napi,
  1182. i40evf_napi_poll, NAPI_POLL_WEIGHT);
  1183. }
  1184. return 0;
  1185. }
  1186. /**
  1187. * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
  1188. * @adapter: board private structure to initialize
  1189. *
  1190. * This function frees the memory allocated to the q_vectors. In addition if
  1191. * NAPI is enabled it will delete any references to the NAPI struct prior
  1192. * to freeing the q_vector.
  1193. **/
  1194. static void i40evf_free_q_vectors(struct i40evf_adapter *adapter)
  1195. {
  1196. int q_idx, num_q_vectors;
  1197. int napi_vectors;
  1198. num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  1199. napi_vectors = adapter->num_active_queues;
  1200. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  1201. struct i40e_q_vector *q_vector = &adapter->q_vectors[q_idx];
  1202. if (q_idx < napi_vectors)
  1203. netif_napi_del(&q_vector->napi);
  1204. }
  1205. kfree(adapter->q_vectors);
  1206. }
  1207. /**
  1208. * i40evf_reset_interrupt_capability - Reset MSIX setup
  1209. * @adapter: board private structure
  1210. *
  1211. **/
  1212. void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter)
  1213. {
  1214. pci_disable_msix(adapter->pdev);
  1215. kfree(adapter->msix_entries);
  1216. adapter->msix_entries = NULL;
  1217. }
  1218. /**
  1219. * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
  1220. * @adapter: board private structure to initialize
  1221. *
  1222. **/
  1223. int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter)
  1224. {
  1225. int err;
  1226. 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. i40evf_napi_disable_all(adapter);
  1503. i40evf_irq_disable(adapter);
  1504. i40evf_free_traffic_irqs(adapter);
  1505. i40evf_free_all_tx_resources(adapter);
  1506. i40evf_free_all_rx_resources(adapter);
  1507. }
  1508. /* Delete all of the filters, both MAC and VLAN. */
  1509. list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list,
  1510. list) {
  1511. list_del(&f->list);
  1512. kfree(f);
  1513. }
  1514. list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list,
  1515. list) {
  1516. list_del(&fv->list);
  1517. kfree(fv);
  1518. }
  1519. i40evf_free_misc_irq(adapter);
  1520. i40evf_reset_interrupt_capability(adapter);
  1521. i40evf_free_queues(adapter);
  1522. i40evf_free_q_vectors(adapter);
  1523. kfree(adapter->vf_res);
  1524. i40evf_shutdown_adminq(hw);
  1525. adapter->netdev->flags &= ~IFF_UP;
  1526. clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
  1527. adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
  1528. adapter->state = __I40EVF_DOWN;
  1529. dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n");
  1530. return; /* Do not attempt to reinit. It's dead, Jim. */
  1531. }
  1532. continue_reset:
  1533. if (netif_running(adapter->netdev)) {
  1534. netif_carrier_off(netdev);
  1535. netif_tx_stop_all_queues(netdev);
  1536. i40evf_napi_disable_all(adapter);
  1537. }
  1538. i40evf_irq_disable(adapter);
  1539. adapter->state = __I40EVF_RESETTING;
  1540. adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
  1541. /* free the Tx/Rx rings and descriptors, might be better to just
  1542. * re-use them sometime in the future
  1543. */
  1544. i40evf_free_all_rx_resources(adapter);
  1545. i40evf_free_all_tx_resources(adapter);
  1546. /* kill and reinit the admin queue */
  1547. if (i40evf_shutdown_adminq(hw))
  1548. dev_warn(&adapter->pdev->dev, "Failed to shut down adminq\n");
  1549. adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
  1550. err = i40evf_init_adminq(hw);
  1551. if (err)
  1552. dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n",
  1553. err);
  1554. adapter->aq_required = I40EVF_FLAG_AQ_GET_CONFIG;
  1555. adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
  1556. /* re-add all MAC filters */
  1557. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  1558. f->add = true;
  1559. }
  1560. /* re-add all VLAN filters */
  1561. list_for_each_entry(vlf, &adapter->vlan_filter_list, list) {
  1562. vlf->add = true;
  1563. }
  1564. adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
  1565. adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
  1566. clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
  1567. i40evf_misc_irq_enable(adapter);
  1568. mod_timer(&adapter->watchdog_timer, jiffies + 2);
  1569. if (netif_running(adapter->netdev)) {
  1570. /* allocate transmit descriptors */
  1571. err = i40evf_setup_all_tx_resources(adapter);
  1572. if (err)
  1573. goto reset_err;
  1574. /* allocate receive descriptors */
  1575. err = i40evf_setup_all_rx_resources(adapter);
  1576. if (err)
  1577. goto reset_err;
  1578. i40evf_configure(adapter);
  1579. err = i40evf_up_complete(adapter);
  1580. if (err)
  1581. goto reset_err;
  1582. i40evf_irq_enable(adapter, true);
  1583. } else {
  1584. adapter->state = __I40EVF_DOWN;
  1585. }
  1586. return;
  1587. reset_err:
  1588. dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
  1589. i40evf_close(adapter->netdev);
  1590. }
  1591. /**
  1592. * i40evf_adminq_task - worker thread to clean the admin queue
  1593. * @work: pointer to work_struct containing our data
  1594. **/
  1595. static void i40evf_adminq_task(struct work_struct *work)
  1596. {
  1597. struct i40evf_adapter *adapter =
  1598. container_of(work, struct i40evf_adapter, adminq_task);
  1599. struct i40e_hw *hw = &adapter->hw;
  1600. struct i40e_arq_event_info event;
  1601. struct i40e_virtchnl_msg *v_msg;
  1602. i40e_status ret;
  1603. u32 val, oldval;
  1604. u16 pending;
  1605. if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
  1606. goto out;
  1607. event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
  1608. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  1609. if (!event.msg_buf)
  1610. goto out;
  1611. v_msg = (struct i40e_virtchnl_msg *)&event.desc;
  1612. do {
  1613. ret = i40evf_clean_arq_element(hw, &event, &pending);
  1614. if (ret || !v_msg->v_opcode)
  1615. break; /* No event to process or error cleaning ARQ */
  1616. i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
  1617. v_msg->v_retval, event.msg_buf,
  1618. event.msg_len);
  1619. if (pending != 0)
  1620. memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
  1621. } while (pending);
  1622. if ((adapter->flags &
  1623. (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED)) ||
  1624. adapter->state == __I40EVF_RESETTING)
  1625. goto freedom;
  1626. /* check for error indications */
  1627. val = rd32(hw, hw->aq.arq.len);
  1628. if (val == 0xdeadbeef) /* indicates device in reset */
  1629. goto freedom;
  1630. oldval = val;
  1631. if (val & I40E_VF_ARQLEN1_ARQVFE_MASK) {
  1632. dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n");
  1633. val &= ~I40E_VF_ARQLEN1_ARQVFE_MASK;
  1634. }
  1635. if (val & I40E_VF_ARQLEN1_ARQOVFL_MASK) {
  1636. dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n");
  1637. val &= ~I40E_VF_ARQLEN1_ARQOVFL_MASK;
  1638. }
  1639. if (val & I40E_VF_ARQLEN1_ARQCRIT_MASK) {
  1640. dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n");
  1641. val &= ~I40E_VF_ARQLEN1_ARQCRIT_MASK;
  1642. }
  1643. if (oldval != val)
  1644. wr32(hw, hw->aq.arq.len, val);
  1645. val = rd32(hw, hw->aq.asq.len);
  1646. oldval = val;
  1647. if (val & I40E_VF_ATQLEN1_ATQVFE_MASK) {
  1648. dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n");
  1649. val &= ~I40E_VF_ATQLEN1_ATQVFE_MASK;
  1650. }
  1651. if (val & I40E_VF_ATQLEN1_ATQOVFL_MASK) {
  1652. dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n");
  1653. val &= ~I40E_VF_ATQLEN1_ATQOVFL_MASK;
  1654. }
  1655. if (val & I40E_VF_ATQLEN1_ATQCRIT_MASK) {
  1656. dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n");
  1657. val &= ~I40E_VF_ATQLEN1_ATQCRIT_MASK;
  1658. }
  1659. if (oldval != val)
  1660. wr32(hw, hw->aq.asq.len, val);
  1661. freedom:
  1662. kfree(event.msg_buf);
  1663. out:
  1664. /* re-enable Admin queue interrupt cause */
  1665. i40evf_misc_irq_enable(adapter);
  1666. }
  1667. /**
  1668. * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
  1669. * @adapter: board private structure
  1670. *
  1671. * Free all transmit software resources
  1672. **/
  1673. void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter)
  1674. {
  1675. int i;
  1676. if (!adapter->tx_rings)
  1677. return;
  1678. for (i = 0; i < adapter->num_active_queues; i++)
  1679. if (adapter->tx_rings[i].desc)
  1680. i40evf_free_tx_resources(&adapter->tx_rings[i]);
  1681. }
  1682. /**
  1683. * i40evf_setup_all_tx_resources - allocate all queues Tx resources
  1684. * @adapter: board private structure
  1685. *
  1686. * If this function returns with an error, then it's possible one or
  1687. * more of the rings is populated (while the rest are not). It is the
  1688. * callers duty to clean those orphaned rings.
  1689. *
  1690. * Return 0 on success, negative on failure
  1691. **/
  1692. static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
  1693. {
  1694. int i, err = 0;
  1695. for (i = 0; i < adapter->num_active_queues; i++) {
  1696. adapter->tx_rings[i].count = adapter->tx_desc_count;
  1697. err = i40evf_setup_tx_descriptors(&adapter->tx_rings[i]);
  1698. if (!err)
  1699. continue;
  1700. dev_err(&adapter->pdev->dev,
  1701. "Allocation for Tx Queue %u failed\n", i);
  1702. break;
  1703. }
  1704. return err;
  1705. }
  1706. /**
  1707. * i40evf_setup_all_rx_resources - allocate all queues Rx resources
  1708. * @adapter: board private structure
  1709. *
  1710. * If this function returns with an error, then it's possible one or
  1711. * more of the rings is populated (while the rest are not). It is the
  1712. * callers duty to clean those orphaned rings.
  1713. *
  1714. * Return 0 on success, negative on failure
  1715. **/
  1716. static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
  1717. {
  1718. int i, err = 0;
  1719. for (i = 0; i < adapter->num_active_queues; i++) {
  1720. adapter->rx_rings[i].count = adapter->rx_desc_count;
  1721. err = i40evf_setup_rx_descriptors(&adapter->rx_rings[i]);
  1722. if (!err)
  1723. continue;
  1724. dev_err(&adapter->pdev->dev,
  1725. "Allocation for Rx Queue %u failed\n", i);
  1726. break;
  1727. }
  1728. return err;
  1729. }
  1730. /**
  1731. * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
  1732. * @adapter: board private structure
  1733. *
  1734. * Free all receive software resources
  1735. **/
  1736. void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter)
  1737. {
  1738. int i;
  1739. if (!adapter->rx_rings)
  1740. return;
  1741. for (i = 0; i < adapter->num_active_queues; i++)
  1742. if (adapter->rx_rings[i].desc)
  1743. i40evf_free_rx_resources(&adapter->rx_rings[i]);
  1744. }
  1745. /**
  1746. * i40evf_open - Called when a network interface is made active
  1747. * @netdev: network interface device structure
  1748. *
  1749. * Returns 0 on success, negative value on failure
  1750. *
  1751. * The open entry point is called when a network interface is made
  1752. * active by the system (IFF_UP). At this point all resources needed
  1753. * for transmit and receive operations are allocated, the interrupt
  1754. * handler is registered with the OS, the watchdog timer is started,
  1755. * and the stack is notified that the interface is ready.
  1756. **/
  1757. static int i40evf_open(struct net_device *netdev)
  1758. {
  1759. struct i40evf_adapter *adapter = netdev_priv(netdev);
  1760. int err;
  1761. if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
  1762. dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
  1763. return -EIO;
  1764. }
  1765. if (adapter->state != __I40EVF_DOWN)
  1766. return -EBUSY;
  1767. /* allocate transmit descriptors */
  1768. err = i40evf_setup_all_tx_resources(adapter);
  1769. if (err)
  1770. goto err_setup_tx;
  1771. /* allocate receive descriptors */
  1772. err = i40evf_setup_all_rx_resources(adapter);
  1773. if (err)
  1774. goto err_setup_rx;
  1775. /* clear any pending interrupts, may auto mask */
  1776. err = i40evf_request_traffic_irqs(adapter, netdev->name);
  1777. if (err)
  1778. goto err_req_irq;
  1779. i40evf_add_filter(adapter, adapter->hw.mac.addr);
  1780. i40evf_configure(adapter);
  1781. err = i40evf_up_complete(adapter);
  1782. if (err)
  1783. goto err_req_irq;
  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. if (!adapter->netdev_registered) {
  2136. err = register_netdev(netdev);
  2137. if (err)
  2138. goto err_register;
  2139. }
  2140. adapter->netdev_registered = true;
  2141. netif_tx_stop_all_queues(netdev);
  2142. dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr);
  2143. if (netdev->features & NETIF_F_GRO)
  2144. dev_info(&pdev->dev, "GRO is enabled\n");
  2145. adapter->state = __I40EVF_DOWN;
  2146. set_bit(__I40E_DOWN, &adapter->vsi.state);
  2147. i40evf_misc_irq_enable(adapter);
  2148. adapter->rss_key = kzalloc(adapter->rss_key_size, GFP_KERNEL);
  2149. adapter->rss_lut = kzalloc(adapter->rss_lut_size, GFP_KERNEL);
  2150. if (!adapter->rss_key || !adapter->rss_lut)
  2151. goto err_mem;
  2152. if (RSS_AQ(adapter)) {
  2153. adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_RSS;
  2154. mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
  2155. } else {
  2156. i40evf_init_rss(adapter);
  2157. }
  2158. return;
  2159. restart:
  2160. schedule_delayed_work(&adapter->init_task, msecs_to_jiffies(30));
  2161. return;
  2162. err_mem:
  2163. i40evf_free_rss(adapter);
  2164. err_register:
  2165. i40evf_free_misc_irq(adapter);
  2166. err_sw_init:
  2167. i40evf_reset_interrupt_capability(adapter);
  2168. err_alloc:
  2169. kfree(adapter->vf_res);
  2170. adapter->vf_res = NULL;
  2171. err:
  2172. /* Things went into the weeds, so try again later */
  2173. if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) {
  2174. dev_err(&pdev->dev, "Failed to communicate with PF; waiting before retry\n");
  2175. adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
  2176. i40evf_shutdown_adminq(hw);
  2177. adapter->state = __I40EVF_STARTUP;
  2178. schedule_delayed_work(&adapter->init_task, HZ * 5);
  2179. return;
  2180. }
  2181. schedule_delayed_work(&adapter->init_task, HZ);
  2182. }
  2183. /**
  2184. * i40evf_shutdown - Shutdown the device in preparation for a reboot
  2185. * @pdev: pci device structure
  2186. **/
  2187. static void i40evf_shutdown(struct pci_dev *pdev)
  2188. {
  2189. struct net_device *netdev = pci_get_drvdata(pdev);
  2190. struct i40evf_adapter *adapter = netdev_priv(netdev);
  2191. netif_device_detach(netdev);
  2192. if (netif_running(netdev))
  2193. i40evf_close(netdev);
  2194. /* Prevent the watchdog from running. */
  2195. adapter->state = __I40EVF_REMOVE;
  2196. adapter->aq_required = 0;
  2197. #ifdef CONFIG_PM
  2198. pci_save_state(pdev);
  2199. #endif
  2200. pci_disable_device(pdev);
  2201. }
  2202. /**
  2203. * i40evf_probe - Device Initialization Routine
  2204. * @pdev: PCI device information struct
  2205. * @ent: entry in i40evf_pci_tbl
  2206. *
  2207. * Returns 0 on success, negative on failure
  2208. *
  2209. * i40evf_probe initializes an adapter identified by a pci_dev structure.
  2210. * The OS initialization, configuring of the adapter private structure,
  2211. * and a hardware reset occur.
  2212. **/
  2213. static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  2214. {
  2215. struct net_device *netdev;
  2216. struct i40evf_adapter *adapter = NULL;
  2217. struct i40e_hw *hw = NULL;
  2218. int err;
  2219. err = pci_enable_device(pdev);
  2220. if (err)
  2221. return err;
  2222. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  2223. if (err) {
  2224. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  2225. if (err) {
  2226. dev_err(&pdev->dev,
  2227. "DMA configuration failed: 0x%x\n", err);
  2228. goto err_dma;
  2229. }
  2230. }
  2231. err = pci_request_regions(pdev, i40evf_driver_name);
  2232. if (err) {
  2233. dev_err(&pdev->dev,
  2234. "pci_request_regions failed 0x%x\n", err);
  2235. goto err_pci_reg;
  2236. }
  2237. pci_enable_pcie_error_reporting(pdev);
  2238. pci_set_master(pdev);
  2239. netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter), MAX_QUEUES);
  2240. if (!netdev) {
  2241. err = -ENOMEM;
  2242. goto err_alloc_etherdev;
  2243. }
  2244. SET_NETDEV_DEV(netdev, &pdev->dev);
  2245. pci_set_drvdata(pdev, netdev);
  2246. adapter = netdev_priv(netdev);
  2247. adapter->netdev = netdev;
  2248. adapter->pdev = pdev;
  2249. hw = &adapter->hw;
  2250. hw->back = adapter;
  2251. adapter->msg_enable = BIT(DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
  2252. adapter->state = __I40EVF_STARTUP;
  2253. /* Call save state here because it relies on the adapter struct. */
  2254. pci_save_state(pdev);
  2255. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  2256. pci_resource_len(pdev, 0));
  2257. if (!hw->hw_addr) {
  2258. err = -EIO;
  2259. goto err_ioremap;
  2260. }
  2261. hw->vendor_id = pdev->vendor;
  2262. hw->device_id = pdev->device;
  2263. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  2264. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  2265. hw->subsystem_device_id = pdev->subsystem_device;
  2266. hw->bus.device = PCI_SLOT(pdev->devfn);
  2267. hw->bus.func = PCI_FUNC(pdev->devfn);
  2268. /* set up the locks for the AQ, do this only once in probe
  2269. * and destroy them only once in remove
  2270. */
  2271. mutex_init(&hw->aq.asq_mutex);
  2272. mutex_init(&hw->aq.arq_mutex);
  2273. INIT_LIST_HEAD(&adapter->mac_filter_list);
  2274. INIT_LIST_HEAD(&adapter->vlan_filter_list);
  2275. INIT_WORK(&adapter->reset_task, i40evf_reset_task);
  2276. INIT_WORK(&adapter->adminq_task, i40evf_adminq_task);
  2277. INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task);
  2278. INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task);
  2279. schedule_delayed_work(&adapter->init_task,
  2280. msecs_to_jiffies(5 * (pdev->devfn & 0x07)));
  2281. return 0;
  2282. err_ioremap:
  2283. free_netdev(netdev);
  2284. err_alloc_etherdev:
  2285. pci_release_regions(pdev);
  2286. err_pci_reg:
  2287. err_dma:
  2288. pci_disable_device(pdev);
  2289. return err;
  2290. }
  2291. #ifdef CONFIG_PM
  2292. /**
  2293. * i40evf_suspend - Power management suspend routine
  2294. * @pdev: PCI device information struct
  2295. * @state: unused
  2296. *
  2297. * Called when the system (VM) is entering sleep/suspend.
  2298. **/
  2299. static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state)
  2300. {
  2301. struct net_device *netdev = pci_get_drvdata(pdev);
  2302. struct i40evf_adapter *adapter = netdev_priv(netdev);
  2303. int retval = 0;
  2304. netif_device_detach(netdev);
  2305. if (netif_running(netdev)) {
  2306. rtnl_lock();
  2307. i40evf_down(adapter);
  2308. rtnl_unlock();
  2309. }
  2310. i40evf_free_misc_irq(adapter);
  2311. i40evf_reset_interrupt_capability(adapter);
  2312. retval = pci_save_state(pdev);
  2313. if (retval)
  2314. return retval;
  2315. pci_disable_device(pdev);
  2316. return 0;
  2317. }
  2318. /**
  2319. * i40evf_resume - Power management resume routine
  2320. * @pdev: PCI device information struct
  2321. *
  2322. * Called when the system (VM) is resumed from sleep/suspend.
  2323. **/
  2324. static int i40evf_resume(struct pci_dev *pdev)
  2325. {
  2326. struct i40evf_adapter *adapter = pci_get_drvdata(pdev);
  2327. struct net_device *netdev = adapter->netdev;
  2328. u32 err;
  2329. pci_set_power_state(pdev, PCI_D0);
  2330. pci_restore_state(pdev);
  2331. /* pci_restore_state clears dev->state_saved so call
  2332. * pci_save_state to restore it.
  2333. */
  2334. pci_save_state(pdev);
  2335. err = pci_enable_device_mem(pdev);
  2336. if (err) {
  2337. dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
  2338. return err;
  2339. }
  2340. pci_set_master(pdev);
  2341. rtnl_lock();
  2342. err = i40evf_set_interrupt_capability(adapter);
  2343. if (err) {
  2344. rtnl_unlock();
  2345. dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
  2346. return err;
  2347. }
  2348. err = i40evf_request_misc_irq(adapter);
  2349. rtnl_unlock();
  2350. if (err) {
  2351. dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
  2352. return err;
  2353. }
  2354. schedule_work(&adapter->reset_task);
  2355. netif_device_attach(netdev);
  2356. return err;
  2357. }
  2358. #endif /* CONFIG_PM */
  2359. /**
  2360. * i40evf_remove - Device Removal Routine
  2361. * @pdev: PCI device information struct
  2362. *
  2363. * i40evf_remove is called by the PCI subsystem to alert the driver
  2364. * that it should release a PCI device. The could be caused by a
  2365. * Hot-Plug event, or because the driver is going to be removed from
  2366. * memory.
  2367. **/
  2368. static void i40evf_remove(struct pci_dev *pdev)
  2369. {
  2370. struct net_device *netdev = pci_get_drvdata(pdev);
  2371. struct i40evf_adapter *adapter = netdev_priv(netdev);
  2372. struct i40evf_mac_filter *f, *ftmp;
  2373. struct i40e_hw *hw = &adapter->hw;
  2374. cancel_delayed_work_sync(&adapter->init_task);
  2375. cancel_work_sync(&adapter->reset_task);
  2376. if (adapter->netdev_registered) {
  2377. unregister_netdev(netdev);
  2378. adapter->netdev_registered = false;
  2379. }
  2380. /* Shut down all the garbage mashers on the detention level */
  2381. adapter->state = __I40EVF_REMOVE;
  2382. adapter->aq_required = 0;
  2383. i40evf_request_reset(adapter);
  2384. msleep(50);
  2385. /* If the FW isn't responding, kick it once, but only once. */
  2386. if (!i40evf_asq_done(hw)) {
  2387. i40evf_request_reset(adapter);
  2388. msleep(50);
  2389. }
  2390. if (adapter->msix_entries) {
  2391. i40evf_misc_irq_disable(adapter);
  2392. i40evf_free_misc_irq(adapter);
  2393. i40evf_reset_interrupt_capability(adapter);
  2394. i40evf_free_q_vectors(adapter);
  2395. }
  2396. if (adapter->watchdog_timer.function)
  2397. del_timer_sync(&adapter->watchdog_timer);
  2398. flush_scheduled_work();
  2399. i40evf_free_rss(adapter);
  2400. if (hw->aq.asq.count)
  2401. i40evf_shutdown_adminq(hw);
  2402. /* destroy the locks only once, here */
  2403. mutex_destroy(&hw->aq.arq_mutex);
  2404. mutex_destroy(&hw->aq.asq_mutex);
  2405. iounmap(hw->hw_addr);
  2406. pci_release_regions(pdev);
  2407. i40evf_free_all_tx_resources(adapter);
  2408. i40evf_free_all_rx_resources(adapter);
  2409. i40evf_free_queues(adapter);
  2410. kfree(adapter->vf_res);
  2411. /* If we got removed before an up/down sequence, we've got a filter
  2412. * hanging out there that we need to get rid of.
  2413. */
  2414. list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
  2415. list_del(&f->list);
  2416. kfree(f);
  2417. }
  2418. list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
  2419. list_del(&f->list);
  2420. kfree(f);
  2421. }
  2422. free_netdev(netdev);
  2423. pci_disable_pcie_error_reporting(pdev);
  2424. pci_disable_device(pdev);
  2425. }
  2426. static struct pci_driver i40evf_driver = {
  2427. .name = i40evf_driver_name,
  2428. .id_table = i40evf_pci_tbl,
  2429. .probe = i40evf_probe,
  2430. .remove = i40evf_remove,
  2431. #ifdef CONFIG_PM
  2432. .suspend = i40evf_suspend,
  2433. .resume = i40evf_resume,
  2434. #endif
  2435. .shutdown = i40evf_shutdown,
  2436. };
  2437. /**
  2438. * i40e_init_module - Driver Registration Routine
  2439. *
  2440. * i40e_init_module is the first routine called when the driver is
  2441. * loaded. All it does is register with the PCI subsystem.
  2442. **/
  2443. static int __init i40evf_init_module(void)
  2444. {
  2445. int ret;
  2446. pr_info("i40evf: %s - version %s\n", i40evf_driver_string,
  2447. i40evf_driver_version);
  2448. pr_info("%s\n", i40evf_copyright);
  2449. i40evf_wq = create_singlethread_workqueue(i40evf_driver_name);
  2450. if (!i40evf_wq) {
  2451. pr_err("%s: Failed to create workqueue\n", i40evf_driver_name);
  2452. return -ENOMEM;
  2453. }
  2454. ret = pci_register_driver(&i40evf_driver);
  2455. return ret;
  2456. }
  2457. module_init(i40evf_init_module);
  2458. /**
  2459. * i40e_exit_module - Driver Exit Cleanup Routine
  2460. *
  2461. * i40e_exit_module is called just before the driver is removed
  2462. * from memory.
  2463. **/
  2464. static void __exit i40evf_exit_module(void)
  2465. {
  2466. pci_unregister_driver(&i40evf_driver);
  2467. destroy_workqueue(i40evf_wq);
  2468. }
  2469. module_exit(i40evf_exit_module);
  2470. /* i40evf_main.c */