i40evf_main.c 77 KB

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