i40evf_main.c 78 KB

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