iavf_main.c 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 2013 - 2018 Intel Corporation. */
  3. #include "iavf.h"
  4. #include "iavf_prototype.h"
  5. #include "iavf_client.h"
  6. /* All iavf tracepoints are defined by the include below, which must
  7. * be included exactly once across the whole kernel with
  8. * CREATE_TRACE_POINTS defined
  9. */
  10. #define CREATE_TRACE_POINTS
  11. #include "iavf_trace.h"
  12. static int iavf_setup_all_tx_resources(struct iavf_adapter *adapter);
  13. static int iavf_setup_all_rx_resources(struct iavf_adapter *adapter);
  14. static int iavf_close(struct net_device *netdev);
  15. char iavf_driver_name[] = "iavf";
  16. static const char iavf_driver_string[] =
  17. "Intel(R) Ethernet Adaptive Virtual Function Network Driver";
  18. #define DRV_KERN "-k"
  19. #define DRV_VERSION_MAJOR 3
  20. #define DRV_VERSION_MINOR 2
  21. #define DRV_VERSION_BUILD 3
  22. #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
  23. __stringify(DRV_VERSION_MINOR) "." \
  24. __stringify(DRV_VERSION_BUILD) \
  25. DRV_KERN
  26. const char iavf_driver_version[] = DRV_VERSION;
  27. static const char iavf_copyright[] =
  28. "Copyright (c) 2013 - 2018 Intel Corporation.";
  29. /* iavf_pci_tbl - PCI Device ID Table
  30. *
  31. * Wildcard entries (PCI_ANY_ID) should come last
  32. * Last entry must be all 0s
  33. *
  34. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  35. * Class, Class Mask, private data (not used) }
  36. */
  37. static const struct pci_device_id iavf_pci_tbl[] = {
  38. {PCI_VDEVICE(INTEL, IAVF_DEV_ID_VF), 0},
  39. {PCI_VDEVICE(INTEL, IAVF_DEV_ID_VF_HV), 0},
  40. {PCI_VDEVICE(INTEL, IAVF_DEV_ID_X722_VF), 0},
  41. {PCI_VDEVICE(INTEL, IAVF_DEV_ID_ADAPTIVE_VF), 0},
  42. /* required last entry */
  43. {0, }
  44. };
  45. MODULE_DEVICE_TABLE(pci, iavf_pci_tbl);
  46. MODULE_ALIAS("i40evf");
  47. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  48. MODULE_DESCRIPTION("Intel(R) Ethernet Adaptive Virtual Function Network Driver");
  49. MODULE_LICENSE("GPL v2");
  50. MODULE_VERSION(DRV_VERSION);
  51. static struct workqueue_struct *iavf_wq;
  52. /**
  53. * iavf_allocate_dma_mem_d - OS specific memory alloc for shared code
  54. * @hw: pointer to the HW structure
  55. * @mem: ptr to mem struct to fill out
  56. * @size: size of memory requested
  57. * @alignment: what to align the allocation to
  58. **/
  59. iavf_status iavf_allocate_dma_mem_d(struct iavf_hw *hw,
  60. struct iavf_dma_mem *mem,
  61. u64 size, u32 alignment)
  62. {
  63. struct iavf_adapter *adapter = (struct iavf_adapter *)hw->back;
  64. if (!mem)
  65. return I40E_ERR_PARAM;
  66. mem->size = ALIGN(size, alignment);
  67. mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size,
  68. (dma_addr_t *)&mem->pa, GFP_KERNEL);
  69. if (mem->va)
  70. return 0;
  71. else
  72. return I40E_ERR_NO_MEMORY;
  73. }
  74. /**
  75. * iavf_free_dma_mem_d - OS specific memory free for shared code
  76. * @hw: pointer to the HW structure
  77. * @mem: ptr to mem struct to free
  78. **/
  79. iavf_status iavf_free_dma_mem_d(struct iavf_hw *hw, struct iavf_dma_mem *mem)
  80. {
  81. struct iavf_adapter *adapter = (struct iavf_adapter *)hw->back;
  82. if (!mem || !mem->va)
  83. return I40E_ERR_PARAM;
  84. dma_free_coherent(&adapter->pdev->dev, mem->size,
  85. mem->va, (dma_addr_t)mem->pa);
  86. return 0;
  87. }
  88. /**
  89. * iavf_allocate_virt_mem_d - OS specific memory alloc for shared code
  90. * @hw: pointer to the HW structure
  91. * @mem: ptr to mem struct to fill out
  92. * @size: size of memory requested
  93. **/
  94. iavf_status iavf_allocate_virt_mem_d(struct iavf_hw *hw,
  95. struct iavf_virt_mem *mem, u32 size)
  96. {
  97. if (!mem)
  98. return I40E_ERR_PARAM;
  99. mem->size = size;
  100. mem->va = kzalloc(size, GFP_KERNEL);
  101. if (mem->va)
  102. return 0;
  103. else
  104. return I40E_ERR_NO_MEMORY;
  105. }
  106. /**
  107. * iavf_free_virt_mem_d - OS specific memory free for shared code
  108. * @hw: pointer to the HW structure
  109. * @mem: ptr to mem struct to free
  110. **/
  111. iavf_status iavf_free_virt_mem_d(struct iavf_hw *hw, struct iavf_virt_mem *mem)
  112. {
  113. if (!mem)
  114. return I40E_ERR_PARAM;
  115. /* it's ok to kfree a NULL pointer */
  116. kfree(mem->va);
  117. return 0;
  118. }
  119. /**
  120. * iavf_debug_d - OS dependent version of debug printing
  121. * @hw: pointer to the HW structure
  122. * @mask: debug level mask
  123. * @fmt_str: printf-type format description
  124. **/
  125. void iavf_debug_d(void *hw, u32 mask, char *fmt_str, ...)
  126. {
  127. char buf[512];
  128. va_list argptr;
  129. if (!(mask & ((struct iavf_hw *)hw)->debug_mask))
  130. return;
  131. va_start(argptr, fmt_str);
  132. vsnprintf(buf, sizeof(buf), fmt_str, argptr);
  133. va_end(argptr);
  134. /* the debug string is already formatted with a newline */
  135. pr_info("%s", buf);
  136. }
  137. /**
  138. * iavf_schedule_reset - Set the flags and schedule a reset event
  139. * @adapter: board private structure
  140. **/
  141. void iavf_schedule_reset(struct iavf_adapter *adapter)
  142. {
  143. if (!(adapter->flags &
  144. (IAVF_FLAG_RESET_PENDING | IAVF_FLAG_RESET_NEEDED))) {
  145. adapter->flags |= IAVF_FLAG_RESET_NEEDED;
  146. schedule_work(&adapter->reset_task);
  147. }
  148. }
  149. /**
  150. * iavf_tx_timeout - Respond to a Tx Hang
  151. * @netdev: network interface device structure
  152. **/
  153. static void iavf_tx_timeout(struct net_device *netdev)
  154. {
  155. struct iavf_adapter *adapter = netdev_priv(netdev);
  156. adapter->tx_timeout_count++;
  157. iavf_schedule_reset(adapter);
  158. }
  159. /**
  160. * iavf_misc_irq_disable - Mask off interrupt generation on the NIC
  161. * @adapter: board private structure
  162. **/
  163. static void iavf_misc_irq_disable(struct iavf_adapter *adapter)
  164. {
  165. struct iavf_hw *hw = &adapter->hw;
  166. if (!adapter->msix_entries)
  167. return;
  168. wr32(hw, IAVF_VFINT_DYN_CTL01, 0);
  169. iavf_flush(hw);
  170. synchronize_irq(adapter->msix_entries[0].vector);
  171. }
  172. /**
  173. * iavf_misc_irq_enable - Enable default interrupt generation settings
  174. * @adapter: board private structure
  175. **/
  176. static void iavf_misc_irq_enable(struct iavf_adapter *adapter)
  177. {
  178. struct iavf_hw *hw = &adapter->hw;
  179. wr32(hw, IAVF_VFINT_DYN_CTL01, IAVF_VFINT_DYN_CTL01_INTENA_MASK |
  180. IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
  181. wr32(hw, IAVF_VFINT_ICR0_ENA1, IAVF_VFINT_ICR0_ENA1_ADMINQ_MASK);
  182. iavf_flush(hw);
  183. }
  184. /**
  185. * iavf_irq_disable - Mask off interrupt generation on the NIC
  186. * @adapter: board private structure
  187. **/
  188. static void iavf_irq_disable(struct iavf_adapter *adapter)
  189. {
  190. int i;
  191. struct iavf_hw *hw = &adapter->hw;
  192. if (!adapter->msix_entries)
  193. return;
  194. for (i = 1; i < adapter->num_msix_vectors; i++) {
  195. wr32(hw, IAVF_VFINT_DYN_CTLN1(i - 1), 0);
  196. synchronize_irq(adapter->msix_entries[i].vector);
  197. }
  198. iavf_flush(hw);
  199. }
  200. /**
  201. * iavf_irq_enable_queues - Enable interrupt for specified queues
  202. * @adapter: board private structure
  203. * @mask: bitmap of queues to enable
  204. **/
  205. void iavf_irq_enable_queues(struct iavf_adapter *adapter, u32 mask)
  206. {
  207. struct iavf_hw *hw = &adapter->hw;
  208. int i;
  209. for (i = 1; i < adapter->num_msix_vectors; i++) {
  210. if (mask & BIT(i - 1)) {
  211. wr32(hw, IAVF_VFINT_DYN_CTLN1(i - 1),
  212. IAVF_VFINT_DYN_CTLN1_INTENA_MASK |
  213. IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK);
  214. }
  215. }
  216. }
  217. /**
  218. * iavf_irq_enable - Enable default interrupt generation settings
  219. * @adapter: board private structure
  220. * @flush: boolean value whether to run rd32()
  221. **/
  222. void iavf_irq_enable(struct iavf_adapter *adapter, bool flush)
  223. {
  224. struct iavf_hw *hw = &adapter->hw;
  225. iavf_misc_irq_enable(adapter);
  226. iavf_irq_enable_queues(adapter, ~0);
  227. if (flush)
  228. iavf_flush(hw);
  229. }
  230. /**
  231. * iavf_msix_aq - Interrupt handler for vector 0
  232. * @irq: interrupt number
  233. * @data: pointer to netdev
  234. **/
  235. static irqreturn_t iavf_msix_aq(int irq, void *data)
  236. {
  237. struct net_device *netdev = data;
  238. struct iavf_adapter *adapter = netdev_priv(netdev);
  239. struct iavf_hw *hw = &adapter->hw;
  240. /* handle non-queue interrupts, these reads clear the registers */
  241. rd32(hw, IAVF_VFINT_ICR01);
  242. rd32(hw, IAVF_VFINT_ICR0_ENA1);
  243. /* schedule work on the private workqueue */
  244. schedule_work(&adapter->adminq_task);
  245. return IRQ_HANDLED;
  246. }
  247. /**
  248. * iavf_msix_clean_rings - MSIX mode Interrupt Handler
  249. * @irq: interrupt number
  250. * @data: pointer to a q_vector
  251. **/
  252. static irqreturn_t iavf_msix_clean_rings(int irq, void *data)
  253. {
  254. struct iavf_q_vector *q_vector = data;
  255. if (!q_vector->tx.ring && !q_vector->rx.ring)
  256. return IRQ_HANDLED;
  257. napi_schedule_irqoff(&q_vector->napi);
  258. return IRQ_HANDLED;
  259. }
  260. /**
  261. * iavf_map_vector_to_rxq - associate irqs with rx queues
  262. * @adapter: board private structure
  263. * @v_idx: interrupt number
  264. * @r_idx: queue number
  265. **/
  266. static void
  267. iavf_map_vector_to_rxq(struct iavf_adapter *adapter, int v_idx, int r_idx)
  268. {
  269. struct iavf_q_vector *q_vector = &adapter->q_vectors[v_idx];
  270. struct iavf_ring *rx_ring = &adapter->rx_rings[r_idx];
  271. struct iavf_hw *hw = &adapter->hw;
  272. rx_ring->q_vector = q_vector;
  273. rx_ring->next = q_vector->rx.ring;
  274. rx_ring->vsi = &adapter->vsi;
  275. q_vector->rx.ring = rx_ring;
  276. q_vector->rx.count++;
  277. q_vector->rx.next_update = jiffies + 1;
  278. q_vector->rx.target_itr = ITR_TO_REG(rx_ring->itr_setting);
  279. q_vector->ring_mask |= BIT(r_idx);
  280. wr32(hw, IAVF_VFINT_ITRN1(IAVF_RX_ITR, q_vector->reg_idx),
  281. q_vector->rx.current_itr);
  282. q_vector->rx.current_itr = q_vector->rx.target_itr;
  283. }
  284. /**
  285. * iavf_map_vector_to_txq - associate irqs with tx queues
  286. * @adapter: board private structure
  287. * @v_idx: interrupt number
  288. * @t_idx: queue number
  289. **/
  290. static void
  291. iavf_map_vector_to_txq(struct iavf_adapter *adapter, int v_idx, int t_idx)
  292. {
  293. struct iavf_q_vector *q_vector = &adapter->q_vectors[v_idx];
  294. struct iavf_ring *tx_ring = &adapter->tx_rings[t_idx];
  295. struct iavf_hw *hw = &adapter->hw;
  296. tx_ring->q_vector = q_vector;
  297. tx_ring->next = q_vector->tx.ring;
  298. tx_ring->vsi = &adapter->vsi;
  299. q_vector->tx.ring = tx_ring;
  300. q_vector->tx.count++;
  301. q_vector->tx.next_update = jiffies + 1;
  302. q_vector->tx.target_itr = ITR_TO_REG(tx_ring->itr_setting);
  303. q_vector->num_ringpairs++;
  304. wr32(hw, IAVF_VFINT_ITRN1(IAVF_TX_ITR, q_vector->reg_idx),
  305. q_vector->tx.target_itr);
  306. q_vector->tx.current_itr = q_vector->tx.target_itr;
  307. }
  308. /**
  309. * iavf_map_rings_to_vectors - Maps descriptor rings to vectors
  310. * @adapter: board private structure to initialize
  311. *
  312. * This function maps descriptor rings to the queue-specific vectors
  313. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  314. * one vector per ring/queue, but on a constrained vector budget, we
  315. * group the rings as "efficiently" as possible. You would add new
  316. * mapping configurations in here.
  317. **/
  318. static void iavf_map_rings_to_vectors(struct iavf_adapter *adapter)
  319. {
  320. int rings_remaining = adapter->num_active_queues;
  321. int ridx = 0, vidx = 0;
  322. int q_vectors;
  323. q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  324. for (; ridx < rings_remaining; ridx++) {
  325. iavf_map_vector_to_rxq(adapter, vidx, ridx);
  326. iavf_map_vector_to_txq(adapter, vidx, ridx);
  327. /* In the case where we have more queues than vectors, continue
  328. * round-robin on vectors until all queues are mapped.
  329. */
  330. if (++vidx >= q_vectors)
  331. vidx = 0;
  332. }
  333. adapter->aq_required |= IAVF_FLAG_AQ_MAP_VECTORS;
  334. }
  335. /**
  336. * iavf_irq_affinity_notify - Callback for affinity changes
  337. * @notify: context as to what irq was changed
  338. * @mask: the new affinity mask
  339. *
  340. * This is a callback function used by the irq_set_affinity_notifier function
  341. * so that we may register to receive changes to the irq affinity masks.
  342. **/
  343. static void iavf_irq_affinity_notify(struct irq_affinity_notify *notify,
  344. const cpumask_t *mask)
  345. {
  346. struct iavf_q_vector *q_vector =
  347. container_of(notify, struct iavf_q_vector, affinity_notify);
  348. cpumask_copy(&q_vector->affinity_mask, mask);
  349. }
  350. /**
  351. * iavf_irq_affinity_release - Callback for affinity notifier release
  352. * @ref: internal core kernel usage
  353. *
  354. * This is a callback function used by the irq_set_affinity_notifier function
  355. * to inform the current notification subscriber that they will no longer
  356. * receive notifications.
  357. **/
  358. static void iavf_irq_affinity_release(struct kref *ref) {}
  359. /**
  360. * iavf_request_traffic_irqs - Initialize MSI-X interrupts
  361. * @adapter: board private structure
  362. * @basename: device basename
  363. *
  364. * Allocates MSI-X vectors for tx and rx handling, and requests
  365. * interrupts from the kernel.
  366. **/
  367. static int
  368. iavf_request_traffic_irqs(struct iavf_adapter *adapter, char *basename)
  369. {
  370. unsigned int vector, q_vectors;
  371. unsigned int rx_int_idx = 0, tx_int_idx = 0;
  372. int irq_num, err;
  373. int cpu;
  374. iavf_irq_disable(adapter);
  375. /* Decrement for Other and TCP Timer vectors */
  376. q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  377. for (vector = 0; vector < q_vectors; vector++) {
  378. struct iavf_q_vector *q_vector = &adapter->q_vectors[vector];
  379. irq_num = adapter->msix_entries[vector + NONQ_VECS].vector;
  380. if (q_vector->tx.ring && q_vector->rx.ring) {
  381. snprintf(q_vector->name, sizeof(q_vector->name),
  382. "iavf-%s-TxRx-%d", basename, rx_int_idx++);
  383. tx_int_idx++;
  384. } else if (q_vector->rx.ring) {
  385. snprintf(q_vector->name, sizeof(q_vector->name),
  386. "iavf-%s-rx-%d", basename, rx_int_idx++);
  387. } else if (q_vector->tx.ring) {
  388. snprintf(q_vector->name, sizeof(q_vector->name),
  389. "iavf-%s-tx-%d", basename, tx_int_idx++);
  390. } else {
  391. /* skip this unused q_vector */
  392. continue;
  393. }
  394. err = request_irq(irq_num,
  395. iavf_msix_clean_rings,
  396. 0,
  397. q_vector->name,
  398. q_vector);
  399. if (err) {
  400. dev_info(&adapter->pdev->dev,
  401. "Request_irq failed, error: %d\n", err);
  402. goto free_queue_irqs;
  403. }
  404. /* register for affinity change notifications */
  405. q_vector->affinity_notify.notify = iavf_irq_affinity_notify;
  406. q_vector->affinity_notify.release =
  407. iavf_irq_affinity_release;
  408. irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
  409. /* Spread the IRQ affinity hints across online CPUs. Note that
  410. * get_cpu_mask returns a mask with a permanent lifetime so
  411. * it's safe to use as a hint for irq_set_affinity_hint.
  412. */
  413. cpu = cpumask_local_spread(q_vector->v_idx, -1);
  414. irq_set_affinity_hint(irq_num, get_cpu_mask(cpu));
  415. }
  416. return 0;
  417. free_queue_irqs:
  418. while (vector) {
  419. vector--;
  420. irq_num = adapter->msix_entries[vector + NONQ_VECS].vector;
  421. irq_set_affinity_notifier(irq_num, NULL);
  422. irq_set_affinity_hint(irq_num, NULL);
  423. free_irq(irq_num, &adapter->q_vectors[vector]);
  424. }
  425. return err;
  426. }
  427. /**
  428. * iavf_request_misc_irq - Initialize MSI-X interrupts
  429. * @adapter: board private structure
  430. *
  431. * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
  432. * vector is only for the admin queue, and stays active even when the netdev
  433. * is closed.
  434. **/
  435. static int iavf_request_misc_irq(struct iavf_adapter *adapter)
  436. {
  437. struct net_device *netdev = adapter->netdev;
  438. int err;
  439. snprintf(adapter->misc_vector_name,
  440. sizeof(adapter->misc_vector_name) - 1, "iavf-%s:mbx",
  441. dev_name(&adapter->pdev->dev));
  442. err = request_irq(adapter->msix_entries[0].vector,
  443. &iavf_msix_aq, 0,
  444. adapter->misc_vector_name, netdev);
  445. if (err) {
  446. dev_err(&adapter->pdev->dev,
  447. "request_irq for %s failed: %d\n",
  448. adapter->misc_vector_name, err);
  449. free_irq(adapter->msix_entries[0].vector, netdev);
  450. }
  451. return err;
  452. }
  453. /**
  454. * iavf_free_traffic_irqs - Free MSI-X interrupts
  455. * @adapter: board private structure
  456. *
  457. * Frees all MSI-X vectors other than 0.
  458. **/
  459. static void iavf_free_traffic_irqs(struct iavf_adapter *adapter)
  460. {
  461. int vector, irq_num, q_vectors;
  462. if (!adapter->msix_entries)
  463. return;
  464. q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  465. for (vector = 0; vector < q_vectors; vector++) {
  466. irq_num = adapter->msix_entries[vector + NONQ_VECS].vector;
  467. irq_set_affinity_notifier(irq_num, NULL);
  468. irq_set_affinity_hint(irq_num, NULL);
  469. free_irq(irq_num, &adapter->q_vectors[vector]);
  470. }
  471. }
  472. /**
  473. * iavf_free_misc_irq - Free MSI-X miscellaneous vector
  474. * @adapter: board private structure
  475. *
  476. * Frees MSI-X vector 0.
  477. **/
  478. static void iavf_free_misc_irq(struct iavf_adapter *adapter)
  479. {
  480. struct net_device *netdev = adapter->netdev;
  481. if (!adapter->msix_entries)
  482. return;
  483. free_irq(adapter->msix_entries[0].vector, netdev);
  484. }
  485. /**
  486. * iavf_configure_tx - Configure Transmit Unit after Reset
  487. * @adapter: board private structure
  488. *
  489. * Configure the Tx unit of the MAC after a reset.
  490. **/
  491. static void iavf_configure_tx(struct iavf_adapter *adapter)
  492. {
  493. struct iavf_hw *hw = &adapter->hw;
  494. int i;
  495. for (i = 0; i < adapter->num_active_queues; i++)
  496. adapter->tx_rings[i].tail = hw->hw_addr + IAVF_QTX_TAIL1(i);
  497. }
  498. /**
  499. * iavf_configure_rx - Configure Receive Unit after Reset
  500. * @adapter: board private structure
  501. *
  502. * Configure the Rx unit of the MAC after a reset.
  503. **/
  504. static void iavf_configure_rx(struct iavf_adapter *adapter)
  505. {
  506. unsigned int rx_buf_len = IAVF_RXBUFFER_2048;
  507. struct iavf_hw *hw = &adapter->hw;
  508. int i;
  509. /* Legacy Rx will always default to a 2048 buffer size. */
  510. #if (PAGE_SIZE < 8192)
  511. if (!(adapter->flags & IAVF_FLAG_LEGACY_RX)) {
  512. struct net_device *netdev = adapter->netdev;
  513. /* For jumbo frames on systems with 4K pages we have to use
  514. * an order 1 page, so we might as well increase the size
  515. * of our Rx buffer to make better use of the available space
  516. */
  517. rx_buf_len = IAVF_RXBUFFER_3072;
  518. /* We use a 1536 buffer size for configurations with
  519. * standard Ethernet mtu. On x86 this gives us enough room
  520. * for shared info and 192 bytes of padding.
  521. */
  522. if (!IAVF_2K_TOO_SMALL_WITH_PADDING &&
  523. (netdev->mtu <= ETH_DATA_LEN))
  524. rx_buf_len = IAVF_RXBUFFER_1536 - NET_IP_ALIGN;
  525. }
  526. #endif
  527. for (i = 0; i < adapter->num_active_queues; i++) {
  528. adapter->rx_rings[i].tail = hw->hw_addr + IAVF_QRX_TAIL1(i);
  529. adapter->rx_rings[i].rx_buf_len = rx_buf_len;
  530. if (adapter->flags & IAVF_FLAG_LEGACY_RX)
  531. clear_ring_build_skb_enabled(&adapter->rx_rings[i]);
  532. else
  533. set_ring_build_skb_enabled(&adapter->rx_rings[i]);
  534. }
  535. }
  536. /**
  537. * iavf_find_vlan - Search filter list for specific vlan filter
  538. * @adapter: board private structure
  539. * @vlan: vlan tag
  540. *
  541. * Returns ptr to the filter object or NULL. Must be called while holding the
  542. * mac_vlan_list_lock.
  543. **/
  544. static struct
  545. iavf_vlan_filter *iavf_find_vlan(struct iavf_adapter *adapter, u16 vlan)
  546. {
  547. struct iavf_vlan_filter *f;
  548. list_for_each_entry(f, &adapter->vlan_filter_list, list) {
  549. if (vlan == f->vlan)
  550. return f;
  551. }
  552. return NULL;
  553. }
  554. /**
  555. * iavf_add_vlan - Add a vlan filter to the list
  556. * @adapter: board private structure
  557. * @vlan: VLAN tag
  558. *
  559. * Returns ptr to the filter object or NULL when no memory available.
  560. **/
  561. static struct
  562. iavf_vlan_filter *iavf_add_vlan(struct iavf_adapter *adapter, u16 vlan)
  563. {
  564. struct iavf_vlan_filter *f = NULL;
  565. spin_lock_bh(&adapter->mac_vlan_list_lock);
  566. f = iavf_find_vlan(adapter, vlan);
  567. if (!f) {
  568. f = kzalloc(sizeof(*f), GFP_KERNEL);
  569. if (!f)
  570. goto clearout;
  571. f->vlan = vlan;
  572. INIT_LIST_HEAD(&f->list);
  573. list_add(&f->list, &adapter->vlan_filter_list);
  574. f->add = true;
  575. adapter->aq_required |= IAVF_FLAG_AQ_ADD_VLAN_FILTER;
  576. }
  577. clearout:
  578. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  579. return f;
  580. }
  581. /**
  582. * iavf_del_vlan - Remove a vlan filter from the list
  583. * @adapter: board private structure
  584. * @vlan: VLAN tag
  585. **/
  586. static void iavf_del_vlan(struct iavf_adapter *adapter, u16 vlan)
  587. {
  588. struct iavf_vlan_filter *f;
  589. spin_lock_bh(&adapter->mac_vlan_list_lock);
  590. f = iavf_find_vlan(adapter, vlan);
  591. if (f) {
  592. f->remove = true;
  593. adapter->aq_required |= IAVF_FLAG_AQ_DEL_VLAN_FILTER;
  594. }
  595. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  596. }
  597. /**
  598. * iavf_vlan_rx_add_vid - Add a VLAN filter to a device
  599. * @netdev: network device struct
  600. * @proto: unused protocol data
  601. * @vid: VLAN tag
  602. **/
  603. static int iavf_vlan_rx_add_vid(struct net_device *netdev,
  604. __always_unused __be16 proto, u16 vid)
  605. {
  606. struct iavf_adapter *adapter = netdev_priv(netdev);
  607. if (!VLAN_ALLOWED(adapter))
  608. return -EIO;
  609. if (iavf_add_vlan(adapter, vid) == NULL)
  610. return -ENOMEM;
  611. return 0;
  612. }
  613. /**
  614. * iavf_vlan_rx_kill_vid - Remove a VLAN filter from a device
  615. * @netdev: network device struct
  616. * @proto: unused protocol data
  617. * @vid: VLAN tag
  618. **/
  619. static int iavf_vlan_rx_kill_vid(struct net_device *netdev,
  620. __always_unused __be16 proto, u16 vid)
  621. {
  622. struct iavf_adapter *adapter = netdev_priv(netdev);
  623. if (VLAN_ALLOWED(adapter)) {
  624. iavf_del_vlan(adapter, vid);
  625. return 0;
  626. }
  627. return -EIO;
  628. }
  629. /**
  630. * iavf_find_filter - Search filter list for specific mac filter
  631. * @adapter: board private structure
  632. * @macaddr: the MAC address
  633. *
  634. * Returns ptr to the filter object or NULL. Must be called while holding the
  635. * mac_vlan_list_lock.
  636. **/
  637. static struct
  638. iavf_mac_filter *iavf_find_filter(struct iavf_adapter *adapter,
  639. const u8 *macaddr)
  640. {
  641. struct iavf_mac_filter *f;
  642. if (!macaddr)
  643. return NULL;
  644. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  645. if (ether_addr_equal(macaddr, f->macaddr))
  646. return f;
  647. }
  648. return NULL;
  649. }
  650. /**
  651. * iavf_add_filter - Add a mac filter to the filter list
  652. * @adapter: board private structure
  653. * @macaddr: the MAC address
  654. *
  655. * Returns ptr to the filter object or NULL when no memory available.
  656. **/
  657. static struct
  658. iavf_mac_filter *iavf_add_filter(struct iavf_adapter *adapter,
  659. const u8 *macaddr)
  660. {
  661. struct iavf_mac_filter *f;
  662. if (!macaddr)
  663. return NULL;
  664. f = iavf_find_filter(adapter, macaddr);
  665. if (!f) {
  666. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  667. if (!f)
  668. return f;
  669. ether_addr_copy(f->macaddr, macaddr);
  670. list_add_tail(&f->list, &adapter->mac_filter_list);
  671. f->add = true;
  672. adapter->aq_required |= IAVF_FLAG_AQ_ADD_MAC_FILTER;
  673. } else {
  674. f->remove = false;
  675. }
  676. return f;
  677. }
  678. /**
  679. * iavf_set_mac - NDO callback to set port mac address
  680. * @netdev: network interface device structure
  681. * @p: pointer to an address structure
  682. *
  683. * Returns 0 on success, negative on failure
  684. **/
  685. static int iavf_set_mac(struct net_device *netdev, void *p)
  686. {
  687. struct iavf_adapter *adapter = netdev_priv(netdev);
  688. struct iavf_hw *hw = &adapter->hw;
  689. struct iavf_mac_filter *f;
  690. struct sockaddr *addr = p;
  691. if (!is_valid_ether_addr(addr->sa_data))
  692. return -EADDRNOTAVAIL;
  693. if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
  694. return 0;
  695. if (adapter->flags & IAVF_FLAG_ADDR_SET_BY_PF)
  696. return -EPERM;
  697. spin_lock_bh(&adapter->mac_vlan_list_lock);
  698. f = iavf_find_filter(adapter, hw->mac.addr);
  699. if (f) {
  700. f->remove = true;
  701. adapter->aq_required |= IAVF_FLAG_AQ_DEL_MAC_FILTER;
  702. }
  703. f = iavf_add_filter(adapter, addr->sa_data);
  704. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  705. if (f) {
  706. ether_addr_copy(hw->mac.addr, addr->sa_data);
  707. ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
  708. }
  709. return (f == NULL) ? -ENOMEM : 0;
  710. }
  711. /**
  712. * iavf_addr_sync - Callback for dev_(mc|uc)_sync to add address
  713. * @netdev: the netdevice
  714. * @addr: address to add
  715. *
  716. * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
  717. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  718. */
  719. static int iavf_addr_sync(struct net_device *netdev, const u8 *addr)
  720. {
  721. struct iavf_adapter *adapter = netdev_priv(netdev);
  722. if (iavf_add_filter(adapter, addr))
  723. return 0;
  724. else
  725. return -ENOMEM;
  726. }
  727. /**
  728. * iavf_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
  729. * @netdev: the netdevice
  730. * @addr: address to add
  731. *
  732. * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
  733. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  734. */
  735. static int iavf_addr_unsync(struct net_device *netdev, const u8 *addr)
  736. {
  737. struct iavf_adapter *adapter = netdev_priv(netdev);
  738. struct iavf_mac_filter *f;
  739. /* Under some circumstances, we might receive a request to delete
  740. * our own device address from our uc list. Because we store the
  741. * device address in the VSI's MAC/VLAN filter list, we need to ignore
  742. * such requests and not delete our device address from this list.
  743. */
  744. if (ether_addr_equal(addr, netdev->dev_addr))
  745. return 0;
  746. f = iavf_find_filter(adapter, addr);
  747. if (f) {
  748. f->remove = true;
  749. adapter->aq_required |= IAVF_FLAG_AQ_DEL_MAC_FILTER;
  750. }
  751. return 0;
  752. }
  753. /**
  754. * iavf_set_rx_mode - NDO callback to set the netdev filters
  755. * @netdev: network interface device structure
  756. **/
  757. static void iavf_set_rx_mode(struct net_device *netdev)
  758. {
  759. struct iavf_adapter *adapter = netdev_priv(netdev);
  760. spin_lock_bh(&adapter->mac_vlan_list_lock);
  761. __dev_uc_sync(netdev, iavf_addr_sync, iavf_addr_unsync);
  762. __dev_mc_sync(netdev, iavf_addr_sync, iavf_addr_unsync);
  763. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  764. if (netdev->flags & IFF_PROMISC &&
  765. !(adapter->flags & IAVF_FLAG_PROMISC_ON))
  766. adapter->aq_required |= IAVF_FLAG_AQ_REQUEST_PROMISC;
  767. else if (!(netdev->flags & IFF_PROMISC) &&
  768. adapter->flags & IAVF_FLAG_PROMISC_ON)
  769. adapter->aq_required |= IAVF_FLAG_AQ_RELEASE_PROMISC;
  770. if (netdev->flags & IFF_ALLMULTI &&
  771. !(adapter->flags & IAVF_FLAG_ALLMULTI_ON))
  772. adapter->aq_required |= IAVF_FLAG_AQ_REQUEST_ALLMULTI;
  773. else if (!(netdev->flags & IFF_ALLMULTI) &&
  774. adapter->flags & IAVF_FLAG_ALLMULTI_ON)
  775. adapter->aq_required |= IAVF_FLAG_AQ_RELEASE_ALLMULTI;
  776. }
  777. /**
  778. * iavf_napi_enable_all - enable NAPI on all queue vectors
  779. * @adapter: board private structure
  780. **/
  781. static void iavf_napi_enable_all(struct iavf_adapter *adapter)
  782. {
  783. int q_idx;
  784. struct iavf_q_vector *q_vector;
  785. int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  786. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  787. struct napi_struct *napi;
  788. q_vector = &adapter->q_vectors[q_idx];
  789. napi = &q_vector->napi;
  790. napi_enable(napi);
  791. }
  792. }
  793. /**
  794. * iavf_napi_disable_all - disable NAPI on all queue vectors
  795. * @adapter: board private structure
  796. **/
  797. static void iavf_napi_disable_all(struct iavf_adapter *adapter)
  798. {
  799. int q_idx;
  800. struct iavf_q_vector *q_vector;
  801. int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  802. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  803. q_vector = &adapter->q_vectors[q_idx];
  804. napi_disable(&q_vector->napi);
  805. }
  806. }
  807. /**
  808. * iavf_configure - set up transmit and receive data structures
  809. * @adapter: board private structure
  810. **/
  811. static void iavf_configure(struct iavf_adapter *adapter)
  812. {
  813. struct net_device *netdev = adapter->netdev;
  814. int i;
  815. iavf_set_rx_mode(netdev);
  816. iavf_configure_tx(adapter);
  817. iavf_configure_rx(adapter);
  818. adapter->aq_required |= IAVF_FLAG_AQ_CONFIGURE_QUEUES;
  819. for (i = 0; i < adapter->num_active_queues; i++) {
  820. struct iavf_ring *ring = &adapter->rx_rings[i];
  821. iavf_alloc_rx_buffers(ring, IAVF_DESC_UNUSED(ring));
  822. }
  823. }
  824. /**
  825. * iavf_up_complete - Finish the last steps of bringing up a connection
  826. * @adapter: board private structure
  827. *
  828. * Expects to be called while holding the __IAVF_IN_CRITICAL_TASK bit lock.
  829. **/
  830. static void iavf_up_complete(struct iavf_adapter *adapter)
  831. {
  832. adapter->state = __IAVF_RUNNING;
  833. clear_bit(__IAVF_VSI_DOWN, adapter->vsi.state);
  834. iavf_napi_enable_all(adapter);
  835. adapter->aq_required |= IAVF_FLAG_AQ_ENABLE_QUEUES;
  836. if (CLIENT_ENABLED(adapter))
  837. adapter->flags |= IAVF_FLAG_CLIENT_NEEDS_OPEN;
  838. mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
  839. }
  840. /**
  841. * iavf_down - Shutdown the connection processing
  842. * @adapter: board private structure
  843. *
  844. * Expects to be called while holding the __IAVF_IN_CRITICAL_TASK bit lock.
  845. **/
  846. void iavf_down(struct iavf_adapter *adapter)
  847. {
  848. struct net_device *netdev = adapter->netdev;
  849. struct iavf_vlan_filter *vlf;
  850. struct iavf_mac_filter *f;
  851. struct iavf_cloud_filter *cf;
  852. if (adapter->state <= __IAVF_DOWN_PENDING)
  853. return;
  854. netif_carrier_off(netdev);
  855. netif_tx_disable(netdev);
  856. adapter->link_up = false;
  857. iavf_napi_disable_all(adapter);
  858. iavf_irq_disable(adapter);
  859. spin_lock_bh(&adapter->mac_vlan_list_lock);
  860. /* clear the sync flag on all filters */
  861. __dev_uc_unsync(adapter->netdev, NULL);
  862. __dev_mc_unsync(adapter->netdev, NULL);
  863. /* remove all MAC filters */
  864. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  865. f->remove = true;
  866. }
  867. /* remove all VLAN filters */
  868. list_for_each_entry(vlf, &adapter->vlan_filter_list, list) {
  869. vlf->remove = true;
  870. }
  871. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  872. /* remove all cloud filters */
  873. spin_lock_bh(&adapter->cloud_filter_list_lock);
  874. list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
  875. cf->del = true;
  876. }
  877. spin_unlock_bh(&adapter->cloud_filter_list_lock);
  878. if (!(adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) &&
  879. adapter->state != __IAVF_RESETTING) {
  880. /* cancel any current operation */
  881. adapter->current_op = VIRTCHNL_OP_UNKNOWN;
  882. /* Schedule operations to close down the HW. Don't wait
  883. * here for this to complete. The watchdog is still running
  884. * and it will take care of this.
  885. */
  886. adapter->aq_required = IAVF_FLAG_AQ_DEL_MAC_FILTER;
  887. adapter->aq_required |= IAVF_FLAG_AQ_DEL_VLAN_FILTER;
  888. adapter->aq_required |= IAVF_FLAG_AQ_DEL_CLOUD_FILTER;
  889. adapter->aq_required |= IAVF_FLAG_AQ_DISABLE_QUEUES;
  890. }
  891. mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
  892. }
  893. /**
  894. * iavf_acquire_msix_vectors - Setup the MSIX capability
  895. * @adapter: board private structure
  896. * @vectors: number of vectors to request
  897. *
  898. * Work with the OS to set up the MSIX vectors needed.
  899. *
  900. * Returns 0 on success, negative on failure
  901. **/
  902. static int
  903. iavf_acquire_msix_vectors(struct iavf_adapter *adapter, int vectors)
  904. {
  905. int err, vector_threshold;
  906. /* We'll want at least 3 (vector_threshold):
  907. * 0) Other (Admin Queue and link, mostly)
  908. * 1) TxQ[0] Cleanup
  909. * 2) RxQ[0] Cleanup
  910. */
  911. vector_threshold = MIN_MSIX_COUNT;
  912. /* The more we get, the more we will assign to Tx/Rx Cleanup
  913. * for the separate queues...where Rx Cleanup >= Tx Cleanup.
  914. * Right now, we simply care about how many we'll get; we'll
  915. * set them up later while requesting irq's.
  916. */
  917. err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
  918. vector_threshold, vectors);
  919. if (err < 0) {
  920. dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n");
  921. kfree(adapter->msix_entries);
  922. adapter->msix_entries = NULL;
  923. return err;
  924. }
  925. /* Adjust for only the vectors we'll use, which is minimum
  926. * of max_msix_q_vectors + NONQ_VECS, or the number of
  927. * vectors we were allocated.
  928. */
  929. adapter->num_msix_vectors = err;
  930. return 0;
  931. }
  932. /**
  933. * iavf_free_queues - Free memory for all rings
  934. * @adapter: board private structure to initialize
  935. *
  936. * Free all of the memory associated with queue pairs.
  937. **/
  938. static void iavf_free_queues(struct iavf_adapter *adapter)
  939. {
  940. if (!adapter->vsi_res)
  941. return;
  942. adapter->num_active_queues = 0;
  943. kfree(adapter->tx_rings);
  944. adapter->tx_rings = NULL;
  945. kfree(adapter->rx_rings);
  946. adapter->rx_rings = NULL;
  947. }
  948. /**
  949. * iavf_alloc_queues - Allocate memory for all rings
  950. * @adapter: board private structure to initialize
  951. *
  952. * We allocate one ring per queue at run-time since we don't know the
  953. * number of queues at compile-time. The polling_netdev array is
  954. * intended for Multiqueue, but should work fine with a single queue.
  955. **/
  956. static int iavf_alloc_queues(struct iavf_adapter *adapter)
  957. {
  958. int i, num_active_queues;
  959. /* If we're in reset reallocating queues we don't actually know yet for
  960. * certain the PF gave us the number of queues we asked for but we'll
  961. * assume it did. Once basic reset is finished we'll confirm once we
  962. * start negotiating config with PF.
  963. */
  964. if (adapter->num_req_queues)
  965. num_active_queues = adapter->num_req_queues;
  966. else if ((adapter->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADQ) &&
  967. adapter->num_tc)
  968. num_active_queues = adapter->ch_config.total_qps;
  969. else
  970. num_active_queues = min_t(int,
  971. adapter->vsi_res->num_queue_pairs,
  972. (int)(num_online_cpus()));
  973. adapter->tx_rings = kcalloc(num_active_queues,
  974. sizeof(struct iavf_ring), GFP_KERNEL);
  975. if (!adapter->tx_rings)
  976. goto err_out;
  977. adapter->rx_rings = kcalloc(num_active_queues,
  978. sizeof(struct iavf_ring), GFP_KERNEL);
  979. if (!adapter->rx_rings)
  980. goto err_out;
  981. for (i = 0; i < num_active_queues; i++) {
  982. struct iavf_ring *tx_ring;
  983. struct iavf_ring *rx_ring;
  984. tx_ring = &adapter->tx_rings[i];
  985. tx_ring->queue_index = i;
  986. tx_ring->netdev = adapter->netdev;
  987. tx_ring->dev = &adapter->pdev->dev;
  988. tx_ring->count = adapter->tx_desc_count;
  989. tx_ring->itr_setting = IAVF_ITR_TX_DEF;
  990. if (adapter->flags & IAVF_FLAG_WB_ON_ITR_CAPABLE)
  991. tx_ring->flags |= IAVF_TXR_FLAGS_WB_ON_ITR;
  992. rx_ring = &adapter->rx_rings[i];
  993. rx_ring->queue_index = i;
  994. rx_ring->netdev = adapter->netdev;
  995. rx_ring->dev = &adapter->pdev->dev;
  996. rx_ring->count = adapter->rx_desc_count;
  997. rx_ring->itr_setting = IAVF_ITR_RX_DEF;
  998. }
  999. adapter->num_active_queues = num_active_queues;
  1000. return 0;
  1001. err_out:
  1002. iavf_free_queues(adapter);
  1003. return -ENOMEM;
  1004. }
  1005. /**
  1006. * iavf_set_interrupt_capability - set MSI-X or FAIL if not supported
  1007. * @adapter: board private structure to initialize
  1008. *
  1009. * Attempt to configure the interrupts using the best available
  1010. * capabilities of the hardware and the kernel.
  1011. **/
  1012. static int iavf_set_interrupt_capability(struct iavf_adapter *adapter)
  1013. {
  1014. int vector, v_budget;
  1015. int pairs = 0;
  1016. int err = 0;
  1017. if (!adapter->vsi_res) {
  1018. err = -EIO;
  1019. goto out;
  1020. }
  1021. pairs = adapter->num_active_queues;
  1022. /* It's easy to be greedy for MSI-X vectors, but it really doesn't do
  1023. * us much good if we have more vectors than CPUs. However, we already
  1024. * limit the total number of queues by the number of CPUs so we do not
  1025. * need any further limiting here.
  1026. */
  1027. v_budget = min_t(int, pairs + NONQ_VECS,
  1028. (int)adapter->vf_res->max_vectors);
  1029. adapter->msix_entries = kcalloc(v_budget,
  1030. sizeof(struct msix_entry), GFP_KERNEL);
  1031. if (!adapter->msix_entries) {
  1032. err = -ENOMEM;
  1033. goto out;
  1034. }
  1035. for (vector = 0; vector < v_budget; vector++)
  1036. adapter->msix_entries[vector].entry = vector;
  1037. err = iavf_acquire_msix_vectors(adapter, v_budget);
  1038. out:
  1039. netif_set_real_num_rx_queues(adapter->netdev, pairs);
  1040. netif_set_real_num_tx_queues(adapter->netdev, pairs);
  1041. return err;
  1042. }
  1043. /**
  1044. * iavf_config_rss_aq - Configure RSS keys and lut by using AQ commands
  1045. * @adapter: board private structure
  1046. *
  1047. * Return 0 on success, negative on failure
  1048. **/
  1049. static int iavf_config_rss_aq(struct iavf_adapter *adapter)
  1050. {
  1051. struct i40e_aqc_get_set_rss_key_data *rss_key =
  1052. (struct i40e_aqc_get_set_rss_key_data *)adapter->rss_key;
  1053. struct iavf_hw *hw = &adapter->hw;
  1054. int ret = 0;
  1055. if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
  1056. /* bail because we already have a command pending */
  1057. dev_err(&adapter->pdev->dev, "Cannot configure RSS, command %d pending\n",
  1058. adapter->current_op);
  1059. return -EBUSY;
  1060. }
  1061. ret = iavf_aq_set_rss_key(hw, adapter->vsi.id, rss_key);
  1062. if (ret) {
  1063. dev_err(&adapter->pdev->dev, "Cannot set RSS key, err %s aq_err %s\n",
  1064. iavf_stat_str(hw, ret),
  1065. iavf_aq_str(hw, hw->aq.asq_last_status));
  1066. return ret;
  1067. }
  1068. ret = iavf_aq_set_rss_lut(hw, adapter->vsi.id, false,
  1069. adapter->rss_lut, adapter->rss_lut_size);
  1070. if (ret) {
  1071. dev_err(&adapter->pdev->dev, "Cannot set RSS lut, err %s aq_err %s\n",
  1072. iavf_stat_str(hw, ret),
  1073. iavf_aq_str(hw, hw->aq.asq_last_status));
  1074. }
  1075. return ret;
  1076. }
  1077. /**
  1078. * iavf_config_rss_reg - Configure RSS keys and lut by writing registers
  1079. * @adapter: board private structure
  1080. *
  1081. * Returns 0 on success, negative on failure
  1082. **/
  1083. static int iavf_config_rss_reg(struct iavf_adapter *adapter)
  1084. {
  1085. struct iavf_hw *hw = &adapter->hw;
  1086. u32 *dw;
  1087. u16 i;
  1088. dw = (u32 *)adapter->rss_key;
  1089. for (i = 0; i <= adapter->rss_key_size / 4; i++)
  1090. wr32(hw, IAVF_VFQF_HKEY(i), dw[i]);
  1091. dw = (u32 *)adapter->rss_lut;
  1092. for (i = 0; i <= adapter->rss_lut_size / 4; i++)
  1093. wr32(hw, IAVF_VFQF_HLUT(i), dw[i]);
  1094. iavf_flush(hw);
  1095. return 0;
  1096. }
  1097. /**
  1098. * iavf_config_rss - Configure RSS keys and lut
  1099. * @adapter: board private structure
  1100. *
  1101. * Returns 0 on success, negative on failure
  1102. **/
  1103. int iavf_config_rss(struct iavf_adapter *adapter)
  1104. {
  1105. if (RSS_PF(adapter)) {
  1106. adapter->aq_required |= IAVF_FLAG_AQ_SET_RSS_LUT |
  1107. IAVF_FLAG_AQ_SET_RSS_KEY;
  1108. return 0;
  1109. } else if (RSS_AQ(adapter)) {
  1110. return iavf_config_rss_aq(adapter);
  1111. } else {
  1112. return iavf_config_rss_reg(adapter);
  1113. }
  1114. }
  1115. /**
  1116. * iavf_fill_rss_lut - Fill the lut with default values
  1117. * @adapter: board private structure
  1118. **/
  1119. static void iavf_fill_rss_lut(struct iavf_adapter *adapter)
  1120. {
  1121. u16 i;
  1122. for (i = 0; i < adapter->rss_lut_size; i++)
  1123. adapter->rss_lut[i] = i % adapter->num_active_queues;
  1124. }
  1125. /**
  1126. * iavf_init_rss - Prepare for RSS
  1127. * @adapter: board private structure
  1128. *
  1129. * Return 0 on success, negative on failure
  1130. **/
  1131. static int iavf_init_rss(struct iavf_adapter *adapter)
  1132. {
  1133. struct iavf_hw *hw = &adapter->hw;
  1134. int ret;
  1135. if (!RSS_PF(adapter)) {
  1136. /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
  1137. if (adapter->vf_res->vf_cap_flags &
  1138. VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
  1139. adapter->hena = IAVF_DEFAULT_RSS_HENA_EXPANDED;
  1140. else
  1141. adapter->hena = IAVF_DEFAULT_RSS_HENA;
  1142. wr32(hw, IAVF_VFQF_HENA(0), (u32)adapter->hena);
  1143. wr32(hw, IAVF_VFQF_HENA(1), (u32)(adapter->hena >> 32));
  1144. }
  1145. iavf_fill_rss_lut(adapter);
  1146. netdev_rss_key_fill((void *)adapter->rss_key, adapter->rss_key_size);
  1147. ret = iavf_config_rss(adapter);
  1148. return ret;
  1149. }
  1150. /**
  1151. * iavf_alloc_q_vectors - Allocate memory for interrupt vectors
  1152. * @adapter: board private structure to initialize
  1153. *
  1154. * We allocate one q_vector per queue interrupt. If allocation fails we
  1155. * return -ENOMEM.
  1156. **/
  1157. static int iavf_alloc_q_vectors(struct iavf_adapter *adapter)
  1158. {
  1159. int q_idx = 0, num_q_vectors;
  1160. struct iavf_q_vector *q_vector;
  1161. num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  1162. adapter->q_vectors = kcalloc(num_q_vectors, sizeof(*q_vector),
  1163. GFP_KERNEL);
  1164. if (!adapter->q_vectors)
  1165. return -ENOMEM;
  1166. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  1167. q_vector = &adapter->q_vectors[q_idx];
  1168. q_vector->adapter = adapter;
  1169. q_vector->vsi = &adapter->vsi;
  1170. q_vector->v_idx = q_idx;
  1171. q_vector->reg_idx = q_idx;
  1172. cpumask_copy(&q_vector->affinity_mask, cpu_possible_mask);
  1173. netif_napi_add(adapter->netdev, &q_vector->napi,
  1174. iavf_napi_poll, NAPI_POLL_WEIGHT);
  1175. }
  1176. return 0;
  1177. }
  1178. /**
  1179. * iavf_free_q_vectors - Free memory allocated for interrupt vectors
  1180. * @adapter: board private structure to initialize
  1181. *
  1182. * This function frees the memory allocated to the q_vectors. In addition if
  1183. * NAPI is enabled it will delete any references to the NAPI struct prior
  1184. * to freeing the q_vector.
  1185. **/
  1186. static void iavf_free_q_vectors(struct iavf_adapter *adapter)
  1187. {
  1188. int q_idx, num_q_vectors;
  1189. int napi_vectors;
  1190. if (!adapter->q_vectors)
  1191. return;
  1192. num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
  1193. napi_vectors = adapter->num_active_queues;
  1194. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  1195. struct iavf_q_vector *q_vector = &adapter->q_vectors[q_idx];
  1196. if (q_idx < napi_vectors)
  1197. netif_napi_del(&q_vector->napi);
  1198. }
  1199. kfree(adapter->q_vectors);
  1200. adapter->q_vectors = NULL;
  1201. }
  1202. /**
  1203. * iavf_reset_interrupt_capability - Reset MSIX setup
  1204. * @adapter: board private structure
  1205. *
  1206. **/
  1207. void iavf_reset_interrupt_capability(struct iavf_adapter *adapter)
  1208. {
  1209. if (!adapter->msix_entries)
  1210. return;
  1211. pci_disable_msix(adapter->pdev);
  1212. kfree(adapter->msix_entries);
  1213. adapter->msix_entries = NULL;
  1214. }
  1215. /**
  1216. * iavf_init_interrupt_scheme - Determine if MSIX is supported and init
  1217. * @adapter: board private structure to initialize
  1218. *
  1219. **/
  1220. int iavf_init_interrupt_scheme(struct iavf_adapter *adapter)
  1221. {
  1222. int err;
  1223. err = iavf_alloc_queues(adapter);
  1224. if (err) {
  1225. dev_err(&adapter->pdev->dev,
  1226. "Unable to allocate memory for queues\n");
  1227. goto err_alloc_queues;
  1228. }
  1229. rtnl_lock();
  1230. err = iavf_set_interrupt_capability(adapter);
  1231. rtnl_unlock();
  1232. if (err) {
  1233. dev_err(&adapter->pdev->dev,
  1234. "Unable to setup interrupt capabilities\n");
  1235. goto err_set_interrupt;
  1236. }
  1237. err = iavf_alloc_q_vectors(adapter);
  1238. if (err) {
  1239. dev_err(&adapter->pdev->dev,
  1240. "Unable to allocate memory for queue vectors\n");
  1241. goto err_alloc_q_vectors;
  1242. }
  1243. /* If we've made it so far while ADq flag being ON, then we haven't
  1244. * bailed out anywhere in middle. And ADq isn't just enabled but actual
  1245. * resources have been allocated in the reset path.
  1246. * Now we can truly claim that ADq is enabled.
  1247. */
  1248. if ((adapter->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADQ) &&
  1249. adapter->num_tc)
  1250. dev_info(&adapter->pdev->dev, "ADq Enabled, %u TCs created",
  1251. adapter->num_tc);
  1252. dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u",
  1253. (adapter->num_active_queues > 1) ? "Enabled" : "Disabled",
  1254. adapter->num_active_queues);
  1255. return 0;
  1256. err_alloc_q_vectors:
  1257. iavf_reset_interrupt_capability(adapter);
  1258. err_set_interrupt:
  1259. iavf_free_queues(adapter);
  1260. err_alloc_queues:
  1261. return err;
  1262. }
  1263. /**
  1264. * iavf_free_rss - Free memory used by RSS structs
  1265. * @adapter: board private structure
  1266. **/
  1267. static void iavf_free_rss(struct iavf_adapter *adapter)
  1268. {
  1269. kfree(adapter->rss_key);
  1270. adapter->rss_key = NULL;
  1271. kfree(adapter->rss_lut);
  1272. adapter->rss_lut = NULL;
  1273. }
  1274. /**
  1275. * iavf_reinit_interrupt_scheme - Reallocate queues and vectors
  1276. * @adapter: board private structure
  1277. *
  1278. * Returns 0 on success, negative on failure
  1279. **/
  1280. static int iavf_reinit_interrupt_scheme(struct iavf_adapter *adapter)
  1281. {
  1282. struct net_device *netdev = adapter->netdev;
  1283. int err;
  1284. if (netif_running(netdev))
  1285. iavf_free_traffic_irqs(adapter);
  1286. iavf_free_misc_irq(adapter);
  1287. iavf_reset_interrupt_capability(adapter);
  1288. iavf_free_q_vectors(adapter);
  1289. iavf_free_queues(adapter);
  1290. err = iavf_init_interrupt_scheme(adapter);
  1291. if (err)
  1292. goto err;
  1293. netif_tx_stop_all_queues(netdev);
  1294. err = iavf_request_misc_irq(adapter);
  1295. if (err)
  1296. goto err;
  1297. set_bit(__IAVF_VSI_DOWN, adapter->vsi.state);
  1298. iavf_map_rings_to_vectors(adapter);
  1299. if (RSS_AQ(adapter))
  1300. adapter->aq_required |= IAVF_FLAG_AQ_CONFIGURE_RSS;
  1301. else
  1302. err = iavf_init_rss(adapter);
  1303. err:
  1304. return err;
  1305. }
  1306. /**
  1307. * iavf_watchdog_timer - Periodic call-back timer
  1308. * @data: pointer to adapter disguised as unsigned long
  1309. **/
  1310. static void iavf_watchdog_timer(struct timer_list *t)
  1311. {
  1312. struct iavf_adapter *adapter = from_timer(adapter, t,
  1313. watchdog_timer);
  1314. schedule_work(&adapter->watchdog_task);
  1315. /* timer will be rescheduled in watchdog task */
  1316. }
  1317. /**
  1318. * iavf_watchdog_task - Periodic call-back task
  1319. * @work: pointer to work_struct
  1320. **/
  1321. static void iavf_watchdog_task(struct work_struct *work)
  1322. {
  1323. struct iavf_adapter *adapter = container_of(work,
  1324. struct iavf_adapter,
  1325. watchdog_task);
  1326. struct iavf_hw *hw = &adapter->hw;
  1327. u32 reg_val;
  1328. if (test_and_set_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section))
  1329. goto restart_watchdog;
  1330. if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) {
  1331. reg_val = rd32(hw, IAVF_VFGEN_RSTAT) &
  1332. IAVF_VFGEN_RSTAT_VFR_STATE_MASK;
  1333. if ((reg_val == VIRTCHNL_VFR_VFACTIVE) ||
  1334. (reg_val == VIRTCHNL_VFR_COMPLETED)) {
  1335. /* A chance for redemption! */
  1336. dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n");
  1337. adapter->state = __IAVF_STARTUP;
  1338. adapter->flags &= ~IAVF_FLAG_PF_COMMS_FAILED;
  1339. schedule_delayed_work(&adapter->init_task, 10);
  1340. clear_bit(__IAVF_IN_CRITICAL_TASK,
  1341. &adapter->crit_section);
  1342. /* Don't reschedule the watchdog, since we've restarted
  1343. * the init task. When init_task contacts the PF and
  1344. * gets everything set up again, it'll restart the
  1345. * watchdog for us. Down, boy. Sit. Stay. Woof.
  1346. */
  1347. return;
  1348. }
  1349. adapter->aq_required = 0;
  1350. adapter->current_op = VIRTCHNL_OP_UNKNOWN;
  1351. goto watchdog_done;
  1352. }
  1353. if ((adapter->state < __IAVF_DOWN) ||
  1354. (adapter->flags & IAVF_FLAG_RESET_PENDING))
  1355. goto watchdog_done;
  1356. /* check for reset */
  1357. reg_val = rd32(hw, IAVF_VF_ARQLEN1) & IAVF_VF_ARQLEN1_ARQENABLE_MASK;
  1358. if (!(adapter->flags & IAVF_FLAG_RESET_PENDING) && !reg_val) {
  1359. adapter->state = __IAVF_RESETTING;
  1360. adapter->flags |= IAVF_FLAG_RESET_PENDING;
  1361. dev_err(&adapter->pdev->dev, "Hardware reset detected\n");
  1362. schedule_work(&adapter->reset_task);
  1363. adapter->aq_required = 0;
  1364. adapter->current_op = VIRTCHNL_OP_UNKNOWN;
  1365. goto watchdog_done;
  1366. }
  1367. /* Process admin queue tasks. After init, everything gets done
  1368. * here so we don't race on the admin queue.
  1369. */
  1370. if (adapter->current_op) {
  1371. if (!iavf_asq_done(hw)) {
  1372. dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n");
  1373. iavf_send_api_ver(adapter);
  1374. }
  1375. goto watchdog_done;
  1376. }
  1377. if (adapter->aq_required & IAVF_FLAG_AQ_GET_CONFIG) {
  1378. iavf_send_vf_config_msg(adapter);
  1379. goto watchdog_done;
  1380. }
  1381. if (adapter->aq_required & IAVF_FLAG_AQ_DISABLE_QUEUES) {
  1382. iavf_disable_queues(adapter);
  1383. goto watchdog_done;
  1384. }
  1385. if (adapter->aq_required & IAVF_FLAG_AQ_MAP_VECTORS) {
  1386. iavf_map_queues(adapter);
  1387. goto watchdog_done;
  1388. }
  1389. if (adapter->aq_required & IAVF_FLAG_AQ_ADD_MAC_FILTER) {
  1390. iavf_add_ether_addrs(adapter);
  1391. goto watchdog_done;
  1392. }
  1393. if (adapter->aq_required & IAVF_FLAG_AQ_ADD_VLAN_FILTER) {
  1394. iavf_add_vlans(adapter);
  1395. goto watchdog_done;
  1396. }
  1397. if (adapter->aq_required & IAVF_FLAG_AQ_DEL_MAC_FILTER) {
  1398. iavf_del_ether_addrs(adapter);
  1399. goto watchdog_done;
  1400. }
  1401. if (adapter->aq_required & IAVF_FLAG_AQ_DEL_VLAN_FILTER) {
  1402. iavf_del_vlans(adapter);
  1403. goto watchdog_done;
  1404. }
  1405. if (adapter->aq_required & IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING) {
  1406. iavf_enable_vlan_stripping(adapter);
  1407. goto watchdog_done;
  1408. }
  1409. if (adapter->aq_required & IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING) {
  1410. iavf_disable_vlan_stripping(adapter);
  1411. goto watchdog_done;
  1412. }
  1413. if (adapter->aq_required & IAVF_FLAG_AQ_CONFIGURE_QUEUES) {
  1414. iavf_configure_queues(adapter);
  1415. goto watchdog_done;
  1416. }
  1417. if (adapter->aq_required & IAVF_FLAG_AQ_ENABLE_QUEUES) {
  1418. iavf_enable_queues(adapter);
  1419. goto watchdog_done;
  1420. }
  1421. if (adapter->aq_required & IAVF_FLAG_AQ_CONFIGURE_RSS) {
  1422. /* This message goes straight to the firmware, not the
  1423. * PF, so we don't have to set current_op as we will
  1424. * not get a response through the ARQ.
  1425. */
  1426. iavf_init_rss(adapter);
  1427. adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_RSS;
  1428. goto watchdog_done;
  1429. }
  1430. if (adapter->aq_required & IAVF_FLAG_AQ_GET_HENA) {
  1431. iavf_get_hena(adapter);
  1432. goto watchdog_done;
  1433. }
  1434. if (adapter->aq_required & IAVF_FLAG_AQ_SET_HENA) {
  1435. iavf_set_hena(adapter);
  1436. goto watchdog_done;
  1437. }
  1438. if (adapter->aq_required & IAVF_FLAG_AQ_SET_RSS_KEY) {
  1439. iavf_set_rss_key(adapter);
  1440. goto watchdog_done;
  1441. }
  1442. if (adapter->aq_required & IAVF_FLAG_AQ_SET_RSS_LUT) {
  1443. iavf_set_rss_lut(adapter);
  1444. goto watchdog_done;
  1445. }
  1446. if (adapter->aq_required & IAVF_FLAG_AQ_REQUEST_PROMISC) {
  1447. iavf_set_promiscuous(adapter, FLAG_VF_UNICAST_PROMISC |
  1448. FLAG_VF_MULTICAST_PROMISC);
  1449. goto watchdog_done;
  1450. }
  1451. if (adapter->aq_required & IAVF_FLAG_AQ_REQUEST_ALLMULTI) {
  1452. iavf_set_promiscuous(adapter, FLAG_VF_MULTICAST_PROMISC);
  1453. goto watchdog_done;
  1454. }
  1455. if ((adapter->aq_required & IAVF_FLAG_AQ_RELEASE_PROMISC) &&
  1456. (adapter->aq_required & IAVF_FLAG_AQ_RELEASE_ALLMULTI)) {
  1457. iavf_set_promiscuous(adapter, 0);
  1458. goto watchdog_done;
  1459. }
  1460. if (adapter->aq_required & IAVF_FLAG_AQ_ENABLE_CHANNELS) {
  1461. iavf_enable_channels(adapter);
  1462. goto watchdog_done;
  1463. }
  1464. if (adapter->aq_required & IAVF_FLAG_AQ_DISABLE_CHANNELS) {
  1465. iavf_disable_channels(adapter);
  1466. goto watchdog_done;
  1467. }
  1468. if (adapter->aq_required & IAVF_FLAG_AQ_ADD_CLOUD_FILTER) {
  1469. iavf_add_cloud_filter(adapter);
  1470. goto watchdog_done;
  1471. }
  1472. if (adapter->aq_required & IAVF_FLAG_AQ_DEL_CLOUD_FILTER) {
  1473. iavf_del_cloud_filter(adapter);
  1474. goto watchdog_done;
  1475. }
  1476. schedule_delayed_work(&adapter->client_task, msecs_to_jiffies(5));
  1477. if (adapter->state == __IAVF_RUNNING)
  1478. iavf_request_stats(adapter);
  1479. watchdog_done:
  1480. if (adapter->state == __IAVF_RUNNING)
  1481. iavf_detect_recover_hung(&adapter->vsi);
  1482. clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section);
  1483. restart_watchdog:
  1484. if (adapter->state == __IAVF_REMOVE)
  1485. return;
  1486. if (adapter->aq_required)
  1487. mod_timer(&adapter->watchdog_timer,
  1488. jiffies + msecs_to_jiffies(20));
  1489. else
  1490. mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2));
  1491. schedule_work(&adapter->adminq_task);
  1492. }
  1493. static void iavf_disable_vf(struct iavf_adapter *adapter)
  1494. {
  1495. struct iavf_mac_filter *f, *ftmp;
  1496. struct iavf_vlan_filter *fv, *fvtmp;
  1497. struct iavf_cloud_filter *cf, *cftmp;
  1498. adapter->flags |= IAVF_FLAG_PF_COMMS_FAILED;
  1499. /* We don't use netif_running() because it may be true prior to
  1500. * ndo_open() returning, so we can't assume it means all our open
  1501. * tasks have finished, since we're not holding the rtnl_lock here.
  1502. */
  1503. if (adapter->state == __IAVF_RUNNING) {
  1504. set_bit(__IAVF_VSI_DOWN, adapter->vsi.state);
  1505. netif_carrier_off(adapter->netdev);
  1506. netif_tx_disable(adapter->netdev);
  1507. adapter->link_up = false;
  1508. iavf_napi_disable_all(adapter);
  1509. iavf_irq_disable(adapter);
  1510. iavf_free_traffic_irqs(adapter);
  1511. iavf_free_all_tx_resources(adapter);
  1512. iavf_free_all_rx_resources(adapter);
  1513. }
  1514. spin_lock_bh(&adapter->mac_vlan_list_lock);
  1515. /* Delete all of the filters */
  1516. list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
  1517. list_del(&f->list);
  1518. kfree(f);
  1519. }
  1520. list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list, list) {
  1521. list_del(&fv->list);
  1522. kfree(fv);
  1523. }
  1524. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  1525. spin_lock_bh(&adapter->cloud_filter_list_lock);
  1526. list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
  1527. list_del(&cf->list);
  1528. kfree(cf);
  1529. adapter->num_cloud_filters--;
  1530. }
  1531. spin_unlock_bh(&adapter->cloud_filter_list_lock);
  1532. iavf_free_misc_irq(adapter);
  1533. iavf_reset_interrupt_capability(adapter);
  1534. iavf_free_queues(adapter);
  1535. iavf_free_q_vectors(adapter);
  1536. kfree(adapter->vf_res);
  1537. iavf_shutdown_adminq(&adapter->hw);
  1538. adapter->netdev->flags &= ~IFF_UP;
  1539. clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section);
  1540. adapter->flags &= ~IAVF_FLAG_RESET_PENDING;
  1541. adapter->state = __IAVF_DOWN;
  1542. wake_up(&adapter->down_waitqueue);
  1543. dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n");
  1544. }
  1545. #define IAVF_RESET_WAIT_MS 10
  1546. #define IAVF_RESET_WAIT_COUNT 500
  1547. /**
  1548. * iavf_reset_task - Call-back task to handle hardware reset
  1549. * @work: pointer to work_struct
  1550. *
  1551. * During reset we need to shut down and reinitialize the admin queue
  1552. * before we can use it to communicate with the PF again. We also clear
  1553. * and reinit the rings because that context is lost as well.
  1554. **/
  1555. static void iavf_reset_task(struct work_struct *work)
  1556. {
  1557. struct iavf_adapter *adapter = container_of(work,
  1558. struct iavf_adapter,
  1559. reset_task);
  1560. struct virtchnl_vf_resource *vfres = adapter->vf_res;
  1561. struct net_device *netdev = adapter->netdev;
  1562. struct iavf_hw *hw = &adapter->hw;
  1563. struct iavf_vlan_filter *vlf;
  1564. struct iavf_cloud_filter *cf;
  1565. struct iavf_mac_filter *f;
  1566. u32 reg_val;
  1567. int i = 0, err;
  1568. bool running;
  1569. /* When device is being removed it doesn't make sense to run the reset
  1570. * task, just return in such a case.
  1571. */
  1572. if (test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section))
  1573. return;
  1574. while (test_and_set_bit(__IAVF_IN_CLIENT_TASK,
  1575. &adapter->crit_section))
  1576. usleep_range(500, 1000);
  1577. if (CLIENT_ENABLED(adapter)) {
  1578. adapter->flags &= ~(IAVF_FLAG_CLIENT_NEEDS_OPEN |
  1579. IAVF_FLAG_CLIENT_NEEDS_CLOSE |
  1580. IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS |
  1581. IAVF_FLAG_SERVICE_CLIENT_REQUESTED);
  1582. cancel_delayed_work_sync(&adapter->client_task);
  1583. iavf_notify_client_close(&adapter->vsi, true);
  1584. }
  1585. iavf_misc_irq_disable(adapter);
  1586. if (adapter->flags & IAVF_FLAG_RESET_NEEDED) {
  1587. adapter->flags &= ~IAVF_FLAG_RESET_NEEDED;
  1588. /* Restart the AQ here. If we have been reset but didn't
  1589. * detect it, or if the PF had to reinit, our AQ will be hosed.
  1590. */
  1591. iavf_shutdown_adminq(hw);
  1592. iavf_init_adminq(hw);
  1593. iavf_request_reset(adapter);
  1594. }
  1595. adapter->flags |= IAVF_FLAG_RESET_PENDING;
  1596. /* poll until we see the reset actually happen */
  1597. for (i = 0; i < IAVF_RESET_WAIT_COUNT; i++) {
  1598. reg_val = rd32(hw, IAVF_VF_ARQLEN1) &
  1599. IAVF_VF_ARQLEN1_ARQENABLE_MASK;
  1600. if (!reg_val)
  1601. break;
  1602. usleep_range(5000, 10000);
  1603. }
  1604. if (i == IAVF_RESET_WAIT_COUNT) {
  1605. dev_info(&adapter->pdev->dev, "Never saw reset\n");
  1606. goto continue_reset; /* act like the reset happened */
  1607. }
  1608. /* wait until the reset is complete and the PF is responding to us */
  1609. for (i = 0; i < IAVF_RESET_WAIT_COUNT; i++) {
  1610. /* sleep first to make sure a minimum wait time is met */
  1611. msleep(IAVF_RESET_WAIT_MS);
  1612. reg_val = rd32(hw, IAVF_VFGEN_RSTAT) &
  1613. IAVF_VFGEN_RSTAT_VFR_STATE_MASK;
  1614. if (reg_val == VIRTCHNL_VFR_VFACTIVE)
  1615. break;
  1616. }
  1617. pci_set_master(adapter->pdev);
  1618. if (i == IAVF_RESET_WAIT_COUNT) {
  1619. dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n",
  1620. reg_val);
  1621. iavf_disable_vf(adapter);
  1622. clear_bit(__IAVF_IN_CLIENT_TASK, &adapter->crit_section);
  1623. return; /* Do not attempt to reinit. It's dead, Jim. */
  1624. }
  1625. continue_reset:
  1626. /* We don't use netif_running() because it may be true prior to
  1627. * ndo_open() returning, so we can't assume it means all our open
  1628. * tasks have finished, since we're not holding the rtnl_lock here.
  1629. */
  1630. running = ((adapter->state == __IAVF_RUNNING) ||
  1631. (adapter->state == __IAVF_RESETTING));
  1632. if (running) {
  1633. netif_carrier_off(netdev);
  1634. netif_tx_stop_all_queues(netdev);
  1635. adapter->link_up = false;
  1636. iavf_napi_disable_all(adapter);
  1637. }
  1638. iavf_irq_disable(adapter);
  1639. adapter->state = __IAVF_RESETTING;
  1640. adapter->flags &= ~IAVF_FLAG_RESET_PENDING;
  1641. /* free the Tx/Rx rings and descriptors, might be better to just
  1642. * re-use them sometime in the future
  1643. */
  1644. iavf_free_all_rx_resources(adapter);
  1645. iavf_free_all_tx_resources(adapter);
  1646. adapter->flags |= IAVF_FLAG_QUEUES_DISABLED;
  1647. /* kill and reinit the admin queue */
  1648. iavf_shutdown_adminq(hw);
  1649. adapter->current_op = VIRTCHNL_OP_UNKNOWN;
  1650. err = iavf_init_adminq(hw);
  1651. if (err)
  1652. dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n",
  1653. err);
  1654. adapter->aq_required = 0;
  1655. if (adapter->flags & IAVF_FLAG_REINIT_ITR_NEEDED) {
  1656. err = iavf_reinit_interrupt_scheme(adapter);
  1657. if (err)
  1658. goto reset_err;
  1659. }
  1660. adapter->aq_required |= IAVF_FLAG_AQ_GET_CONFIG;
  1661. adapter->aq_required |= IAVF_FLAG_AQ_MAP_VECTORS;
  1662. spin_lock_bh(&adapter->mac_vlan_list_lock);
  1663. /* re-add all MAC filters */
  1664. list_for_each_entry(f, &adapter->mac_filter_list, list) {
  1665. f->add = true;
  1666. }
  1667. /* re-add all VLAN filters */
  1668. list_for_each_entry(vlf, &adapter->vlan_filter_list, list) {
  1669. vlf->add = true;
  1670. }
  1671. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  1672. /* check if TCs are running and re-add all cloud filters */
  1673. spin_lock_bh(&adapter->cloud_filter_list_lock);
  1674. if ((vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADQ) &&
  1675. adapter->num_tc) {
  1676. list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
  1677. cf->add = true;
  1678. }
  1679. }
  1680. spin_unlock_bh(&adapter->cloud_filter_list_lock);
  1681. adapter->aq_required |= IAVF_FLAG_AQ_ADD_MAC_FILTER;
  1682. adapter->aq_required |= IAVF_FLAG_AQ_ADD_VLAN_FILTER;
  1683. adapter->aq_required |= IAVF_FLAG_AQ_ADD_CLOUD_FILTER;
  1684. iavf_misc_irq_enable(adapter);
  1685. mod_timer(&adapter->watchdog_timer, jiffies + 2);
  1686. /* We were running when the reset started, so we need to restore some
  1687. * state here.
  1688. */
  1689. if (running) {
  1690. /* allocate transmit descriptors */
  1691. err = iavf_setup_all_tx_resources(adapter);
  1692. if (err)
  1693. goto reset_err;
  1694. /* allocate receive descriptors */
  1695. err = iavf_setup_all_rx_resources(adapter);
  1696. if (err)
  1697. goto reset_err;
  1698. if (adapter->flags & IAVF_FLAG_REINIT_ITR_NEEDED) {
  1699. err = iavf_request_traffic_irqs(adapter, netdev->name);
  1700. if (err)
  1701. goto reset_err;
  1702. adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
  1703. }
  1704. iavf_configure(adapter);
  1705. iavf_up_complete(adapter);
  1706. iavf_irq_enable(adapter, true);
  1707. } else {
  1708. adapter->state = __IAVF_DOWN;
  1709. wake_up(&adapter->down_waitqueue);
  1710. }
  1711. clear_bit(__IAVF_IN_CLIENT_TASK, &adapter->crit_section);
  1712. clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section);
  1713. return;
  1714. reset_err:
  1715. clear_bit(__IAVF_IN_CLIENT_TASK, &adapter->crit_section);
  1716. clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section);
  1717. dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
  1718. iavf_close(netdev);
  1719. }
  1720. /**
  1721. * iavf_adminq_task - worker thread to clean the admin queue
  1722. * @work: pointer to work_struct containing our data
  1723. **/
  1724. static void iavf_adminq_task(struct work_struct *work)
  1725. {
  1726. struct iavf_adapter *adapter =
  1727. container_of(work, struct iavf_adapter, adminq_task);
  1728. struct iavf_hw *hw = &adapter->hw;
  1729. struct i40e_arq_event_info event;
  1730. enum virtchnl_ops v_op;
  1731. iavf_status ret, v_ret;
  1732. u32 val, oldval;
  1733. u16 pending;
  1734. if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)
  1735. goto out;
  1736. event.buf_len = IAVF_MAX_AQ_BUF_SIZE;
  1737. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  1738. if (!event.msg_buf)
  1739. goto out;
  1740. do {
  1741. ret = iavf_clean_arq_element(hw, &event, &pending);
  1742. v_op = (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
  1743. v_ret = (iavf_status)le32_to_cpu(event.desc.cookie_low);
  1744. if (ret || !v_op)
  1745. break; /* No event to process or error cleaning ARQ */
  1746. iavf_virtchnl_completion(adapter, v_op, v_ret, event.msg_buf,
  1747. event.msg_len);
  1748. if (pending != 0)
  1749. memset(event.msg_buf, 0, IAVF_MAX_AQ_BUF_SIZE);
  1750. } while (pending);
  1751. if ((adapter->flags &
  1752. (IAVF_FLAG_RESET_PENDING | IAVF_FLAG_RESET_NEEDED)) ||
  1753. adapter->state == __IAVF_RESETTING)
  1754. goto freedom;
  1755. /* check for error indications */
  1756. val = rd32(hw, hw->aq.arq.len);
  1757. if (val == 0xdeadbeef) /* indicates device in reset */
  1758. goto freedom;
  1759. oldval = val;
  1760. if (val & IAVF_VF_ARQLEN1_ARQVFE_MASK) {
  1761. dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n");
  1762. val &= ~IAVF_VF_ARQLEN1_ARQVFE_MASK;
  1763. }
  1764. if (val & IAVF_VF_ARQLEN1_ARQOVFL_MASK) {
  1765. dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n");
  1766. val &= ~IAVF_VF_ARQLEN1_ARQOVFL_MASK;
  1767. }
  1768. if (val & IAVF_VF_ARQLEN1_ARQCRIT_MASK) {
  1769. dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n");
  1770. val &= ~IAVF_VF_ARQLEN1_ARQCRIT_MASK;
  1771. }
  1772. if (oldval != val)
  1773. wr32(hw, hw->aq.arq.len, val);
  1774. val = rd32(hw, hw->aq.asq.len);
  1775. oldval = val;
  1776. if (val & IAVF_VF_ATQLEN1_ATQVFE_MASK) {
  1777. dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n");
  1778. val &= ~IAVF_VF_ATQLEN1_ATQVFE_MASK;
  1779. }
  1780. if (val & IAVF_VF_ATQLEN1_ATQOVFL_MASK) {
  1781. dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n");
  1782. val &= ~IAVF_VF_ATQLEN1_ATQOVFL_MASK;
  1783. }
  1784. if (val & IAVF_VF_ATQLEN1_ATQCRIT_MASK) {
  1785. dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n");
  1786. val &= ~IAVF_VF_ATQLEN1_ATQCRIT_MASK;
  1787. }
  1788. if (oldval != val)
  1789. wr32(hw, hw->aq.asq.len, val);
  1790. freedom:
  1791. kfree(event.msg_buf);
  1792. out:
  1793. /* re-enable Admin queue interrupt cause */
  1794. iavf_misc_irq_enable(adapter);
  1795. }
  1796. /**
  1797. * iavf_client_task - worker thread to perform client work
  1798. * @work: pointer to work_struct containing our data
  1799. *
  1800. * This task handles client interactions. Because client calls can be
  1801. * reentrant, we can't handle them in the watchdog.
  1802. **/
  1803. static void iavf_client_task(struct work_struct *work)
  1804. {
  1805. struct iavf_adapter *adapter =
  1806. container_of(work, struct iavf_adapter, client_task.work);
  1807. /* If we can't get the client bit, just give up. We'll be rescheduled
  1808. * later.
  1809. */
  1810. if (test_and_set_bit(__IAVF_IN_CLIENT_TASK, &adapter->crit_section))
  1811. return;
  1812. if (adapter->flags & IAVF_FLAG_SERVICE_CLIENT_REQUESTED) {
  1813. iavf_client_subtask(adapter);
  1814. adapter->flags &= ~IAVF_FLAG_SERVICE_CLIENT_REQUESTED;
  1815. goto out;
  1816. }
  1817. if (adapter->flags & IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS) {
  1818. iavf_notify_client_l2_params(&adapter->vsi);
  1819. adapter->flags &= ~IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS;
  1820. goto out;
  1821. }
  1822. if (adapter->flags & IAVF_FLAG_CLIENT_NEEDS_CLOSE) {
  1823. iavf_notify_client_close(&adapter->vsi, false);
  1824. adapter->flags &= ~IAVF_FLAG_CLIENT_NEEDS_CLOSE;
  1825. goto out;
  1826. }
  1827. if (adapter->flags & IAVF_FLAG_CLIENT_NEEDS_OPEN) {
  1828. iavf_notify_client_open(&adapter->vsi);
  1829. adapter->flags &= ~IAVF_FLAG_CLIENT_NEEDS_OPEN;
  1830. }
  1831. out:
  1832. clear_bit(__IAVF_IN_CLIENT_TASK, &adapter->crit_section);
  1833. }
  1834. /**
  1835. * iavf_free_all_tx_resources - Free Tx Resources for All Queues
  1836. * @adapter: board private structure
  1837. *
  1838. * Free all transmit software resources
  1839. **/
  1840. void iavf_free_all_tx_resources(struct iavf_adapter *adapter)
  1841. {
  1842. int i;
  1843. if (!adapter->tx_rings)
  1844. return;
  1845. for (i = 0; i < adapter->num_active_queues; i++)
  1846. if (adapter->tx_rings[i].desc)
  1847. iavf_free_tx_resources(&adapter->tx_rings[i]);
  1848. }
  1849. /**
  1850. * iavf_setup_all_tx_resources - allocate all queues Tx resources
  1851. * @adapter: board private structure
  1852. *
  1853. * If this function returns with an error, then it's possible one or
  1854. * more of the rings is populated (while the rest are not). It is the
  1855. * callers duty to clean those orphaned rings.
  1856. *
  1857. * Return 0 on success, negative on failure
  1858. **/
  1859. static int iavf_setup_all_tx_resources(struct iavf_adapter *adapter)
  1860. {
  1861. int i, err = 0;
  1862. for (i = 0; i < adapter->num_active_queues; i++) {
  1863. adapter->tx_rings[i].count = adapter->tx_desc_count;
  1864. err = iavf_setup_tx_descriptors(&adapter->tx_rings[i]);
  1865. if (!err)
  1866. continue;
  1867. dev_err(&adapter->pdev->dev,
  1868. "Allocation for Tx Queue %u failed\n", i);
  1869. break;
  1870. }
  1871. return err;
  1872. }
  1873. /**
  1874. * iavf_setup_all_rx_resources - allocate all queues Rx resources
  1875. * @adapter: board private structure
  1876. *
  1877. * If this function returns with an error, then it's possible one or
  1878. * more of the rings is populated (while the rest are not). It is the
  1879. * callers duty to clean those orphaned rings.
  1880. *
  1881. * Return 0 on success, negative on failure
  1882. **/
  1883. static int iavf_setup_all_rx_resources(struct iavf_adapter *adapter)
  1884. {
  1885. int i, err = 0;
  1886. for (i = 0; i < adapter->num_active_queues; i++) {
  1887. adapter->rx_rings[i].count = adapter->rx_desc_count;
  1888. err = iavf_setup_rx_descriptors(&adapter->rx_rings[i]);
  1889. if (!err)
  1890. continue;
  1891. dev_err(&adapter->pdev->dev,
  1892. "Allocation for Rx Queue %u failed\n", i);
  1893. break;
  1894. }
  1895. return err;
  1896. }
  1897. /**
  1898. * iavf_free_all_rx_resources - Free Rx Resources for All Queues
  1899. * @adapter: board private structure
  1900. *
  1901. * Free all receive software resources
  1902. **/
  1903. void iavf_free_all_rx_resources(struct iavf_adapter *adapter)
  1904. {
  1905. int i;
  1906. if (!adapter->rx_rings)
  1907. return;
  1908. for (i = 0; i < adapter->num_active_queues; i++)
  1909. if (adapter->rx_rings[i].desc)
  1910. iavf_free_rx_resources(&adapter->rx_rings[i]);
  1911. }
  1912. /**
  1913. * iavf_validate_tx_bandwidth - validate the max Tx bandwidth
  1914. * @adapter: board private structure
  1915. * @max_tx_rate: max Tx bw for a tc
  1916. **/
  1917. static int iavf_validate_tx_bandwidth(struct iavf_adapter *adapter,
  1918. u64 max_tx_rate)
  1919. {
  1920. int speed = 0, ret = 0;
  1921. switch (adapter->link_speed) {
  1922. case I40E_LINK_SPEED_40GB:
  1923. speed = 40000;
  1924. break;
  1925. case I40E_LINK_SPEED_25GB:
  1926. speed = 25000;
  1927. break;
  1928. case I40E_LINK_SPEED_20GB:
  1929. speed = 20000;
  1930. break;
  1931. case I40E_LINK_SPEED_10GB:
  1932. speed = 10000;
  1933. break;
  1934. case I40E_LINK_SPEED_1GB:
  1935. speed = 1000;
  1936. break;
  1937. case I40E_LINK_SPEED_100MB:
  1938. speed = 100;
  1939. break;
  1940. default:
  1941. break;
  1942. }
  1943. if (max_tx_rate > speed) {
  1944. dev_err(&adapter->pdev->dev,
  1945. "Invalid tx rate specified\n");
  1946. ret = -EINVAL;
  1947. }
  1948. return ret;
  1949. }
  1950. /**
  1951. * iavf_validate_channel_config - validate queue mapping info
  1952. * @adapter: board private structure
  1953. * @mqprio_qopt: queue parameters
  1954. *
  1955. * This function validates if the config provided by the user to
  1956. * configure queue channels is valid or not. Returns 0 on a valid
  1957. * config.
  1958. **/
  1959. static int iavf_validate_ch_config(struct iavf_adapter *adapter,
  1960. struct tc_mqprio_qopt_offload *mqprio_qopt)
  1961. {
  1962. u64 total_max_rate = 0;
  1963. int i, num_qps = 0;
  1964. u64 tx_rate = 0;
  1965. int ret = 0;
  1966. if (mqprio_qopt->qopt.num_tc > IAVF_MAX_TRAFFIC_CLASS ||
  1967. mqprio_qopt->qopt.num_tc < 1)
  1968. return -EINVAL;
  1969. for (i = 0; i <= mqprio_qopt->qopt.num_tc - 1; i++) {
  1970. if (!mqprio_qopt->qopt.count[i] ||
  1971. mqprio_qopt->qopt.offset[i] != num_qps)
  1972. return -EINVAL;
  1973. if (mqprio_qopt->min_rate[i]) {
  1974. dev_err(&adapter->pdev->dev,
  1975. "Invalid min tx rate (greater than 0) specified\n");
  1976. return -EINVAL;
  1977. }
  1978. /*convert to Mbps */
  1979. tx_rate = div_u64(mqprio_qopt->max_rate[i],
  1980. IAVF_MBPS_DIVISOR);
  1981. total_max_rate += tx_rate;
  1982. num_qps += mqprio_qopt->qopt.count[i];
  1983. }
  1984. if (num_qps > IAVF_MAX_REQ_QUEUES)
  1985. return -EINVAL;
  1986. ret = iavf_validate_tx_bandwidth(adapter, total_max_rate);
  1987. return ret;
  1988. }
  1989. /**
  1990. * iavf_del_all_cloud_filters - delete all cloud filters
  1991. * on the traffic classes
  1992. **/
  1993. static void iavf_del_all_cloud_filters(struct iavf_adapter *adapter)
  1994. {
  1995. struct iavf_cloud_filter *cf, *cftmp;
  1996. spin_lock_bh(&adapter->cloud_filter_list_lock);
  1997. list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
  1998. list) {
  1999. list_del(&cf->list);
  2000. kfree(cf);
  2001. adapter->num_cloud_filters--;
  2002. }
  2003. spin_unlock_bh(&adapter->cloud_filter_list_lock);
  2004. }
  2005. /**
  2006. * __iavf_setup_tc - configure multiple traffic classes
  2007. * @netdev: network interface device structure
  2008. * @type_date: tc offload data
  2009. *
  2010. * This function processes the config information provided by the
  2011. * user to configure traffic classes/queue channels and packages the
  2012. * information to request the PF to setup traffic classes.
  2013. *
  2014. * Returns 0 on success.
  2015. **/
  2016. static int __iavf_setup_tc(struct net_device *netdev, void *type_data)
  2017. {
  2018. struct tc_mqprio_qopt_offload *mqprio_qopt = type_data;
  2019. struct iavf_adapter *adapter = netdev_priv(netdev);
  2020. struct virtchnl_vf_resource *vfres = adapter->vf_res;
  2021. u8 num_tc = 0, total_qps = 0;
  2022. int ret = 0, netdev_tc = 0;
  2023. u64 max_tx_rate;
  2024. u16 mode;
  2025. int i;
  2026. num_tc = mqprio_qopt->qopt.num_tc;
  2027. mode = mqprio_qopt->mode;
  2028. /* delete queue_channel */
  2029. if (!mqprio_qopt->qopt.hw) {
  2030. if (adapter->ch_config.state == __IAVF_TC_RUNNING) {
  2031. /* reset the tc configuration */
  2032. netdev_reset_tc(netdev);
  2033. adapter->num_tc = 0;
  2034. netif_tx_stop_all_queues(netdev);
  2035. netif_tx_disable(netdev);
  2036. iavf_del_all_cloud_filters(adapter);
  2037. adapter->aq_required = IAVF_FLAG_AQ_DISABLE_CHANNELS;
  2038. goto exit;
  2039. } else {
  2040. return -EINVAL;
  2041. }
  2042. }
  2043. /* add queue channel */
  2044. if (mode == TC_MQPRIO_MODE_CHANNEL) {
  2045. if (!(vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADQ)) {
  2046. dev_err(&adapter->pdev->dev, "ADq not supported\n");
  2047. return -EOPNOTSUPP;
  2048. }
  2049. if (adapter->ch_config.state != __IAVF_TC_INVALID) {
  2050. dev_err(&adapter->pdev->dev, "TC configuration already exists\n");
  2051. return -EINVAL;
  2052. }
  2053. ret = iavf_validate_ch_config(adapter, mqprio_qopt);
  2054. if (ret)
  2055. return ret;
  2056. /* Return if same TC config is requested */
  2057. if (adapter->num_tc == num_tc)
  2058. return 0;
  2059. adapter->num_tc = num_tc;
  2060. for (i = 0; i < IAVF_MAX_TRAFFIC_CLASS; i++) {
  2061. if (i < num_tc) {
  2062. adapter->ch_config.ch_info[i].count =
  2063. mqprio_qopt->qopt.count[i];
  2064. adapter->ch_config.ch_info[i].offset =
  2065. mqprio_qopt->qopt.offset[i];
  2066. total_qps += mqprio_qopt->qopt.count[i];
  2067. max_tx_rate = mqprio_qopt->max_rate[i];
  2068. /* convert to Mbps */
  2069. max_tx_rate = div_u64(max_tx_rate,
  2070. IAVF_MBPS_DIVISOR);
  2071. adapter->ch_config.ch_info[i].max_tx_rate =
  2072. max_tx_rate;
  2073. } else {
  2074. adapter->ch_config.ch_info[i].count = 1;
  2075. adapter->ch_config.ch_info[i].offset = 0;
  2076. }
  2077. }
  2078. adapter->ch_config.total_qps = total_qps;
  2079. netif_tx_stop_all_queues(netdev);
  2080. netif_tx_disable(netdev);
  2081. adapter->aq_required |= IAVF_FLAG_AQ_ENABLE_CHANNELS;
  2082. netdev_reset_tc(netdev);
  2083. /* Report the tc mapping up the stack */
  2084. netdev_set_num_tc(adapter->netdev, num_tc);
  2085. for (i = 0; i < IAVF_MAX_TRAFFIC_CLASS; i++) {
  2086. u16 qcount = mqprio_qopt->qopt.count[i];
  2087. u16 qoffset = mqprio_qopt->qopt.offset[i];
  2088. if (i < num_tc)
  2089. netdev_set_tc_queue(netdev, netdev_tc++, qcount,
  2090. qoffset);
  2091. }
  2092. }
  2093. exit:
  2094. return ret;
  2095. }
  2096. /**
  2097. * iavf_parse_cls_flower - Parse tc flower filters provided by kernel
  2098. * @adapter: board private structure
  2099. * @cls_flower: pointer to struct tc_cls_flower_offload
  2100. * @filter: pointer to cloud filter structure
  2101. */
  2102. static int iavf_parse_cls_flower(struct iavf_adapter *adapter,
  2103. struct tc_cls_flower_offload *f,
  2104. struct iavf_cloud_filter *filter)
  2105. {
  2106. u16 n_proto_mask = 0;
  2107. u16 n_proto_key = 0;
  2108. u8 field_flags = 0;
  2109. u16 addr_type = 0;
  2110. u16 n_proto = 0;
  2111. int i = 0;
  2112. struct virtchnl_filter *vf = &filter->f;
  2113. if (f->dissector->used_keys &
  2114. ~(BIT(FLOW_DISSECTOR_KEY_CONTROL) |
  2115. BIT(FLOW_DISSECTOR_KEY_BASIC) |
  2116. BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) |
  2117. BIT(FLOW_DISSECTOR_KEY_VLAN) |
  2118. BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
  2119. BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
  2120. BIT(FLOW_DISSECTOR_KEY_PORTS) |
  2121. BIT(FLOW_DISSECTOR_KEY_ENC_KEYID))) {
  2122. dev_err(&adapter->pdev->dev, "Unsupported key used: 0x%x\n",
  2123. f->dissector->used_keys);
  2124. return -EOPNOTSUPP;
  2125. }
  2126. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ENC_KEYID)) {
  2127. struct flow_dissector_key_keyid *mask =
  2128. skb_flow_dissector_target(f->dissector,
  2129. FLOW_DISSECTOR_KEY_ENC_KEYID,
  2130. f->mask);
  2131. if (mask->keyid != 0)
  2132. field_flags |= IAVF_CLOUD_FIELD_TEN_ID;
  2133. }
  2134. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_BASIC)) {
  2135. struct flow_dissector_key_basic *key =
  2136. skb_flow_dissector_target(f->dissector,
  2137. FLOW_DISSECTOR_KEY_BASIC,
  2138. f->key);
  2139. struct flow_dissector_key_basic *mask =
  2140. skb_flow_dissector_target(f->dissector,
  2141. FLOW_DISSECTOR_KEY_BASIC,
  2142. f->mask);
  2143. n_proto_key = ntohs(key->n_proto);
  2144. n_proto_mask = ntohs(mask->n_proto);
  2145. if (n_proto_key == ETH_P_ALL) {
  2146. n_proto_key = 0;
  2147. n_proto_mask = 0;
  2148. }
  2149. n_proto = n_proto_key & n_proto_mask;
  2150. if (n_proto != ETH_P_IP && n_proto != ETH_P_IPV6)
  2151. return -EINVAL;
  2152. if (n_proto == ETH_P_IPV6) {
  2153. /* specify flow type as TCP IPv6 */
  2154. vf->flow_type = VIRTCHNL_TCP_V6_FLOW;
  2155. }
  2156. if (key->ip_proto != IPPROTO_TCP) {
  2157. dev_info(&adapter->pdev->dev, "Only TCP transport is supported\n");
  2158. return -EINVAL;
  2159. }
  2160. }
  2161. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
  2162. struct flow_dissector_key_eth_addrs *key =
  2163. skb_flow_dissector_target(f->dissector,
  2164. FLOW_DISSECTOR_KEY_ETH_ADDRS,
  2165. f->key);
  2166. struct flow_dissector_key_eth_addrs *mask =
  2167. skb_flow_dissector_target(f->dissector,
  2168. FLOW_DISSECTOR_KEY_ETH_ADDRS,
  2169. f->mask);
  2170. /* use is_broadcast and is_zero to check for all 0xf or 0 */
  2171. if (!is_zero_ether_addr(mask->dst)) {
  2172. if (is_broadcast_ether_addr(mask->dst)) {
  2173. field_flags |= IAVF_CLOUD_FIELD_OMAC;
  2174. } else {
  2175. dev_err(&adapter->pdev->dev, "Bad ether dest mask %pM\n",
  2176. mask->dst);
  2177. return I40E_ERR_CONFIG;
  2178. }
  2179. }
  2180. if (!is_zero_ether_addr(mask->src)) {
  2181. if (is_broadcast_ether_addr(mask->src)) {
  2182. field_flags |= IAVF_CLOUD_FIELD_IMAC;
  2183. } else {
  2184. dev_err(&adapter->pdev->dev, "Bad ether src mask %pM\n",
  2185. mask->src);
  2186. return I40E_ERR_CONFIG;
  2187. }
  2188. }
  2189. if (!is_zero_ether_addr(key->dst))
  2190. if (is_valid_ether_addr(key->dst) ||
  2191. is_multicast_ether_addr(key->dst)) {
  2192. /* set the mask if a valid dst_mac address */
  2193. for (i = 0; i < ETH_ALEN; i++)
  2194. vf->mask.tcp_spec.dst_mac[i] |= 0xff;
  2195. ether_addr_copy(vf->data.tcp_spec.dst_mac,
  2196. key->dst);
  2197. }
  2198. if (!is_zero_ether_addr(key->src))
  2199. if (is_valid_ether_addr(key->src) ||
  2200. is_multicast_ether_addr(key->src)) {
  2201. /* set the mask if a valid dst_mac address */
  2202. for (i = 0; i < ETH_ALEN; i++)
  2203. vf->mask.tcp_spec.src_mac[i] |= 0xff;
  2204. ether_addr_copy(vf->data.tcp_spec.src_mac,
  2205. key->src);
  2206. }
  2207. }
  2208. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_VLAN)) {
  2209. struct flow_dissector_key_vlan *key =
  2210. skb_flow_dissector_target(f->dissector,
  2211. FLOW_DISSECTOR_KEY_VLAN,
  2212. f->key);
  2213. struct flow_dissector_key_vlan *mask =
  2214. skb_flow_dissector_target(f->dissector,
  2215. FLOW_DISSECTOR_KEY_VLAN,
  2216. f->mask);
  2217. if (mask->vlan_id) {
  2218. if (mask->vlan_id == VLAN_VID_MASK) {
  2219. field_flags |= IAVF_CLOUD_FIELD_IVLAN;
  2220. } else {
  2221. dev_err(&adapter->pdev->dev, "Bad vlan mask %u\n",
  2222. mask->vlan_id);
  2223. return I40E_ERR_CONFIG;
  2224. }
  2225. }
  2226. vf->mask.tcp_spec.vlan_id |= cpu_to_be16(0xffff);
  2227. vf->data.tcp_spec.vlan_id = cpu_to_be16(key->vlan_id);
  2228. }
  2229. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_CONTROL)) {
  2230. struct flow_dissector_key_control *key =
  2231. skb_flow_dissector_target(f->dissector,
  2232. FLOW_DISSECTOR_KEY_CONTROL,
  2233. f->key);
  2234. addr_type = key->addr_type;
  2235. }
  2236. if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
  2237. struct flow_dissector_key_ipv4_addrs *key =
  2238. skb_flow_dissector_target(f->dissector,
  2239. FLOW_DISSECTOR_KEY_IPV4_ADDRS,
  2240. f->key);
  2241. struct flow_dissector_key_ipv4_addrs *mask =
  2242. skb_flow_dissector_target(f->dissector,
  2243. FLOW_DISSECTOR_KEY_IPV4_ADDRS,
  2244. f->mask);
  2245. if (mask->dst) {
  2246. if (mask->dst == cpu_to_be32(0xffffffff)) {
  2247. field_flags |= IAVF_CLOUD_FIELD_IIP;
  2248. } else {
  2249. dev_err(&adapter->pdev->dev, "Bad ip dst mask 0x%08x\n",
  2250. be32_to_cpu(mask->dst));
  2251. return I40E_ERR_CONFIG;
  2252. }
  2253. }
  2254. if (mask->src) {
  2255. if (mask->src == cpu_to_be32(0xffffffff)) {
  2256. field_flags |= IAVF_CLOUD_FIELD_IIP;
  2257. } else {
  2258. dev_err(&adapter->pdev->dev, "Bad ip src mask 0x%08x\n",
  2259. be32_to_cpu(mask->dst));
  2260. return I40E_ERR_CONFIG;
  2261. }
  2262. }
  2263. if (field_flags & IAVF_CLOUD_FIELD_TEN_ID) {
  2264. dev_info(&adapter->pdev->dev, "Tenant id not allowed for ip filter\n");
  2265. return I40E_ERR_CONFIG;
  2266. }
  2267. if (key->dst) {
  2268. vf->mask.tcp_spec.dst_ip[0] |= cpu_to_be32(0xffffffff);
  2269. vf->data.tcp_spec.dst_ip[0] = key->dst;
  2270. }
  2271. if (key->src) {
  2272. vf->mask.tcp_spec.src_ip[0] |= cpu_to_be32(0xffffffff);
  2273. vf->data.tcp_spec.src_ip[0] = key->src;
  2274. }
  2275. }
  2276. if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
  2277. struct flow_dissector_key_ipv6_addrs *key =
  2278. skb_flow_dissector_target(f->dissector,
  2279. FLOW_DISSECTOR_KEY_IPV6_ADDRS,
  2280. f->key);
  2281. struct flow_dissector_key_ipv6_addrs *mask =
  2282. skb_flow_dissector_target(f->dissector,
  2283. FLOW_DISSECTOR_KEY_IPV6_ADDRS,
  2284. f->mask);
  2285. /* validate mask, make sure it is not IPV6_ADDR_ANY */
  2286. if (ipv6_addr_any(&mask->dst)) {
  2287. dev_err(&adapter->pdev->dev, "Bad ipv6 dst mask 0x%02x\n",
  2288. IPV6_ADDR_ANY);
  2289. return I40E_ERR_CONFIG;
  2290. }
  2291. /* src and dest IPv6 address should not be LOOPBACK
  2292. * (0:0:0:0:0:0:0:1) which can be represented as ::1
  2293. */
  2294. if (ipv6_addr_loopback(&key->dst) ||
  2295. ipv6_addr_loopback(&key->src)) {
  2296. dev_err(&adapter->pdev->dev,
  2297. "ipv6 addr should not be loopback\n");
  2298. return I40E_ERR_CONFIG;
  2299. }
  2300. if (!ipv6_addr_any(&mask->dst) || !ipv6_addr_any(&mask->src))
  2301. field_flags |= IAVF_CLOUD_FIELD_IIP;
  2302. for (i = 0; i < 4; i++)
  2303. vf->mask.tcp_spec.dst_ip[i] |= cpu_to_be32(0xffffffff);
  2304. memcpy(&vf->data.tcp_spec.dst_ip, &key->dst.s6_addr32,
  2305. sizeof(vf->data.tcp_spec.dst_ip));
  2306. for (i = 0; i < 4; i++)
  2307. vf->mask.tcp_spec.src_ip[i] |= cpu_to_be32(0xffffffff);
  2308. memcpy(&vf->data.tcp_spec.src_ip, &key->src.s6_addr32,
  2309. sizeof(vf->data.tcp_spec.src_ip));
  2310. }
  2311. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_PORTS)) {
  2312. struct flow_dissector_key_ports *key =
  2313. skb_flow_dissector_target(f->dissector,
  2314. FLOW_DISSECTOR_KEY_PORTS,
  2315. f->key);
  2316. struct flow_dissector_key_ports *mask =
  2317. skb_flow_dissector_target(f->dissector,
  2318. FLOW_DISSECTOR_KEY_PORTS,
  2319. f->mask);
  2320. if (mask->src) {
  2321. if (mask->src == cpu_to_be16(0xffff)) {
  2322. field_flags |= IAVF_CLOUD_FIELD_IIP;
  2323. } else {
  2324. dev_err(&adapter->pdev->dev, "Bad src port mask %u\n",
  2325. be16_to_cpu(mask->src));
  2326. return I40E_ERR_CONFIG;
  2327. }
  2328. }
  2329. if (mask->dst) {
  2330. if (mask->dst == cpu_to_be16(0xffff)) {
  2331. field_flags |= IAVF_CLOUD_FIELD_IIP;
  2332. } else {
  2333. dev_err(&adapter->pdev->dev, "Bad dst port mask %u\n",
  2334. be16_to_cpu(mask->dst));
  2335. return I40E_ERR_CONFIG;
  2336. }
  2337. }
  2338. if (key->dst) {
  2339. vf->mask.tcp_spec.dst_port |= cpu_to_be16(0xffff);
  2340. vf->data.tcp_spec.dst_port = key->dst;
  2341. }
  2342. if (key->src) {
  2343. vf->mask.tcp_spec.src_port |= cpu_to_be16(0xffff);
  2344. vf->data.tcp_spec.src_port = key->src;
  2345. }
  2346. }
  2347. vf->field_flags = field_flags;
  2348. return 0;
  2349. }
  2350. /**
  2351. * iavf_handle_tclass - Forward to a traffic class on the device
  2352. * @adapter: board private structure
  2353. * @tc: traffic class index on the device
  2354. * @filter: pointer to cloud filter structure
  2355. */
  2356. static int iavf_handle_tclass(struct iavf_adapter *adapter, u32 tc,
  2357. struct iavf_cloud_filter *filter)
  2358. {
  2359. if (tc == 0)
  2360. return 0;
  2361. if (tc < adapter->num_tc) {
  2362. if (!filter->f.data.tcp_spec.dst_port) {
  2363. dev_err(&adapter->pdev->dev,
  2364. "Specify destination port to redirect to traffic class other than TC0\n");
  2365. return -EINVAL;
  2366. }
  2367. }
  2368. /* redirect to a traffic class on the same device */
  2369. filter->f.action = VIRTCHNL_ACTION_TC_REDIRECT;
  2370. filter->f.action_meta = tc;
  2371. return 0;
  2372. }
  2373. /**
  2374. * iavf_configure_clsflower - Add tc flower filters
  2375. * @adapter: board private structure
  2376. * @cls_flower: Pointer to struct tc_cls_flower_offload
  2377. */
  2378. static int iavf_configure_clsflower(struct iavf_adapter *adapter,
  2379. struct tc_cls_flower_offload *cls_flower)
  2380. {
  2381. int tc = tc_classid_to_hwtc(adapter->netdev, cls_flower->classid);
  2382. struct iavf_cloud_filter *filter = NULL;
  2383. int err = -EINVAL, count = 50;
  2384. if (tc < 0) {
  2385. dev_err(&adapter->pdev->dev, "Invalid traffic class\n");
  2386. return -EINVAL;
  2387. }
  2388. filter = kzalloc(sizeof(*filter), GFP_KERNEL);
  2389. if (!filter)
  2390. return -ENOMEM;
  2391. while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK,
  2392. &adapter->crit_section)) {
  2393. if (--count == 0)
  2394. goto err;
  2395. udelay(1);
  2396. }
  2397. filter->cookie = cls_flower->cookie;
  2398. /* set the mask to all zeroes to begin with */
  2399. memset(&filter->f.mask.tcp_spec, 0, sizeof(struct virtchnl_l4_spec));
  2400. /* start out with flow type and eth type IPv4 to begin with */
  2401. filter->f.flow_type = VIRTCHNL_TCP_V4_FLOW;
  2402. err = iavf_parse_cls_flower(adapter, cls_flower, filter);
  2403. if (err < 0)
  2404. goto err;
  2405. err = iavf_handle_tclass(adapter, tc, filter);
  2406. if (err < 0)
  2407. goto err;
  2408. /* add filter to the list */
  2409. spin_lock_bh(&adapter->cloud_filter_list_lock);
  2410. list_add_tail(&filter->list, &adapter->cloud_filter_list);
  2411. adapter->num_cloud_filters++;
  2412. filter->add = true;
  2413. adapter->aq_required |= IAVF_FLAG_AQ_ADD_CLOUD_FILTER;
  2414. spin_unlock_bh(&adapter->cloud_filter_list_lock);
  2415. err:
  2416. if (err)
  2417. kfree(filter);
  2418. clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section);
  2419. return err;
  2420. }
  2421. /* iavf_find_cf - Find the cloud filter in the list
  2422. * @adapter: Board private structure
  2423. * @cookie: filter specific cookie
  2424. *
  2425. * Returns ptr to the filter object or NULL. Must be called while holding the
  2426. * cloud_filter_list_lock.
  2427. */
  2428. static struct iavf_cloud_filter *iavf_find_cf(struct iavf_adapter *adapter,
  2429. unsigned long *cookie)
  2430. {
  2431. struct iavf_cloud_filter *filter = NULL;
  2432. if (!cookie)
  2433. return NULL;
  2434. list_for_each_entry(filter, &adapter->cloud_filter_list, list) {
  2435. if (!memcmp(cookie, &filter->cookie, sizeof(filter->cookie)))
  2436. return filter;
  2437. }
  2438. return NULL;
  2439. }
  2440. /**
  2441. * iavf_delete_clsflower - Remove tc flower filters
  2442. * @adapter: board private structure
  2443. * @cls_flower: Pointer to struct tc_cls_flower_offload
  2444. */
  2445. static int iavf_delete_clsflower(struct iavf_adapter *adapter,
  2446. struct tc_cls_flower_offload *cls_flower)
  2447. {
  2448. struct iavf_cloud_filter *filter = NULL;
  2449. int err = 0;
  2450. spin_lock_bh(&adapter->cloud_filter_list_lock);
  2451. filter = iavf_find_cf(adapter, &cls_flower->cookie);
  2452. if (filter) {
  2453. filter->del = true;
  2454. adapter->aq_required |= IAVF_FLAG_AQ_DEL_CLOUD_FILTER;
  2455. } else {
  2456. err = -EINVAL;
  2457. }
  2458. spin_unlock_bh(&adapter->cloud_filter_list_lock);
  2459. return err;
  2460. }
  2461. /**
  2462. * iavf_setup_tc_cls_flower - flower classifier offloads
  2463. * @netdev: net device to configure
  2464. * @type_data: offload data
  2465. */
  2466. static int iavf_setup_tc_cls_flower(struct iavf_adapter *adapter,
  2467. struct tc_cls_flower_offload *cls_flower)
  2468. {
  2469. if (cls_flower->common.chain_index)
  2470. return -EOPNOTSUPP;
  2471. switch (cls_flower->command) {
  2472. case TC_CLSFLOWER_REPLACE:
  2473. return iavf_configure_clsflower(adapter, cls_flower);
  2474. case TC_CLSFLOWER_DESTROY:
  2475. return iavf_delete_clsflower(adapter, cls_flower);
  2476. case TC_CLSFLOWER_STATS:
  2477. return -EOPNOTSUPP;
  2478. default:
  2479. return -EOPNOTSUPP;
  2480. }
  2481. }
  2482. /**
  2483. * iavf_setup_tc_block_cb - block callback for tc
  2484. * @type: type of offload
  2485. * @type_data: offload data
  2486. * @cb_priv:
  2487. *
  2488. * This function is the block callback for traffic classes
  2489. **/
  2490. static int iavf_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
  2491. void *cb_priv)
  2492. {
  2493. switch (type) {
  2494. case TC_SETUP_CLSFLOWER:
  2495. return iavf_setup_tc_cls_flower(cb_priv, type_data);
  2496. default:
  2497. return -EOPNOTSUPP;
  2498. }
  2499. }
  2500. /**
  2501. * iavf_setup_tc_block - register callbacks for tc
  2502. * @netdev: network interface device structure
  2503. * @f: tc offload data
  2504. *
  2505. * This function registers block callbacks for tc
  2506. * offloads
  2507. **/
  2508. static int iavf_setup_tc_block(struct net_device *dev,
  2509. struct tc_block_offload *f)
  2510. {
  2511. struct iavf_adapter *adapter = netdev_priv(dev);
  2512. if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
  2513. return -EOPNOTSUPP;
  2514. switch (f->command) {
  2515. case TC_BLOCK_BIND:
  2516. return tcf_block_cb_register(f->block, iavf_setup_tc_block_cb,
  2517. adapter, adapter, f->extack);
  2518. case TC_BLOCK_UNBIND:
  2519. tcf_block_cb_unregister(f->block, iavf_setup_tc_block_cb,
  2520. adapter);
  2521. return 0;
  2522. default:
  2523. return -EOPNOTSUPP;
  2524. }
  2525. }
  2526. /**
  2527. * iavf_setup_tc - configure multiple traffic classes
  2528. * @netdev: network interface device structure
  2529. * @type: type of offload
  2530. * @type_date: tc offload data
  2531. *
  2532. * This function is the callback to ndo_setup_tc in the
  2533. * netdev_ops.
  2534. *
  2535. * Returns 0 on success
  2536. **/
  2537. static int iavf_setup_tc(struct net_device *netdev, enum tc_setup_type type,
  2538. void *type_data)
  2539. {
  2540. switch (type) {
  2541. case TC_SETUP_QDISC_MQPRIO:
  2542. return __iavf_setup_tc(netdev, type_data);
  2543. case TC_SETUP_BLOCK:
  2544. return iavf_setup_tc_block(netdev, type_data);
  2545. default:
  2546. return -EOPNOTSUPP;
  2547. }
  2548. }
  2549. /**
  2550. * iavf_open - Called when a network interface is made active
  2551. * @netdev: network interface device structure
  2552. *
  2553. * Returns 0 on success, negative value on failure
  2554. *
  2555. * The open entry point is called when a network interface is made
  2556. * active by the system (IFF_UP). At this point all resources needed
  2557. * for transmit and receive operations are allocated, the interrupt
  2558. * handler is registered with the OS, the watchdog timer is started,
  2559. * and the stack is notified that the interface is ready.
  2560. **/
  2561. static int iavf_open(struct net_device *netdev)
  2562. {
  2563. struct iavf_adapter *adapter = netdev_priv(netdev);
  2564. int err;
  2565. if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) {
  2566. dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
  2567. return -EIO;
  2568. }
  2569. while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK,
  2570. &adapter->crit_section))
  2571. usleep_range(500, 1000);
  2572. if (adapter->state != __IAVF_DOWN) {
  2573. err = -EBUSY;
  2574. goto err_unlock;
  2575. }
  2576. /* allocate transmit descriptors */
  2577. err = iavf_setup_all_tx_resources(adapter);
  2578. if (err)
  2579. goto err_setup_tx;
  2580. /* allocate receive descriptors */
  2581. err = iavf_setup_all_rx_resources(adapter);
  2582. if (err)
  2583. goto err_setup_rx;
  2584. /* clear any pending interrupts, may auto mask */
  2585. err = iavf_request_traffic_irqs(adapter, netdev->name);
  2586. if (err)
  2587. goto err_req_irq;
  2588. spin_lock_bh(&adapter->mac_vlan_list_lock);
  2589. iavf_add_filter(adapter, adapter->hw.mac.addr);
  2590. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  2591. iavf_configure(adapter);
  2592. iavf_up_complete(adapter);
  2593. iavf_irq_enable(adapter, true);
  2594. clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section);
  2595. return 0;
  2596. err_req_irq:
  2597. iavf_down(adapter);
  2598. iavf_free_traffic_irqs(adapter);
  2599. err_setup_rx:
  2600. iavf_free_all_rx_resources(adapter);
  2601. err_setup_tx:
  2602. iavf_free_all_tx_resources(adapter);
  2603. err_unlock:
  2604. clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section);
  2605. return err;
  2606. }
  2607. /**
  2608. * iavf_close - Disables a network interface
  2609. * @netdev: network interface device structure
  2610. *
  2611. * Returns 0, this is not allowed to fail
  2612. *
  2613. * The close entry point is called when an interface is de-activated
  2614. * by the OS. The hardware is still under the drivers control, but
  2615. * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
  2616. * are freed, along with all transmit and receive resources.
  2617. **/
  2618. static int iavf_close(struct net_device *netdev)
  2619. {
  2620. struct iavf_adapter *adapter = netdev_priv(netdev);
  2621. int status;
  2622. if (adapter->state <= __IAVF_DOWN_PENDING)
  2623. return 0;
  2624. while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK,
  2625. &adapter->crit_section))
  2626. usleep_range(500, 1000);
  2627. set_bit(__IAVF_VSI_DOWN, adapter->vsi.state);
  2628. if (CLIENT_ENABLED(adapter))
  2629. adapter->flags |= IAVF_FLAG_CLIENT_NEEDS_CLOSE;
  2630. iavf_down(adapter);
  2631. adapter->state = __IAVF_DOWN_PENDING;
  2632. iavf_free_traffic_irqs(adapter);
  2633. clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section);
  2634. /* We explicitly don't free resources here because the hardware is
  2635. * still active and can DMA into memory. Resources are cleared in
  2636. * iavf_virtchnl_completion() after we get confirmation from the PF
  2637. * driver that the rings have been stopped.
  2638. *
  2639. * Also, we wait for state to transition to __IAVF_DOWN before
  2640. * returning. State change occurs in iavf_virtchnl_completion() after
  2641. * VF resources are released (which occurs after PF driver processes and
  2642. * responds to admin queue commands).
  2643. */
  2644. status = wait_event_timeout(adapter->down_waitqueue,
  2645. adapter->state == __IAVF_DOWN,
  2646. msecs_to_jiffies(200));
  2647. if (!status)
  2648. netdev_warn(netdev, "Device resources not yet released\n");
  2649. return 0;
  2650. }
  2651. /**
  2652. * iavf_change_mtu - Change the Maximum Transfer Unit
  2653. * @netdev: network interface device structure
  2654. * @new_mtu: new value for maximum frame size
  2655. *
  2656. * Returns 0 on success, negative on failure
  2657. **/
  2658. static int iavf_change_mtu(struct net_device *netdev, int new_mtu)
  2659. {
  2660. struct iavf_adapter *adapter = netdev_priv(netdev);
  2661. netdev->mtu = new_mtu;
  2662. if (CLIENT_ENABLED(adapter)) {
  2663. iavf_notify_client_l2_params(&adapter->vsi);
  2664. adapter->flags |= IAVF_FLAG_SERVICE_CLIENT_REQUESTED;
  2665. }
  2666. adapter->flags |= IAVF_FLAG_RESET_NEEDED;
  2667. schedule_work(&adapter->reset_task);
  2668. return 0;
  2669. }
  2670. /**
  2671. * iavf_set_features - set the netdev feature flags
  2672. * @netdev: ptr to the netdev being adjusted
  2673. * @features: the feature set that the stack is suggesting
  2674. * Note: expects to be called while under rtnl_lock()
  2675. **/
  2676. static int iavf_set_features(struct net_device *netdev,
  2677. netdev_features_t features)
  2678. {
  2679. struct iavf_adapter *adapter = netdev_priv(netdev);
  2680. /* Don't allow changing VLAN_RX flag when adapter is not capable
  2681. * of VLAN offload
  2682. */
  2683. if (!VLAN_ALLOWED(adapter)) {
  2684. if ((netdev->features ^ features) & NETIF_F_HW_VLAN_CTAG_RX)
  2685. return -EINVAL;
  2686. } else if ((netdev->features ^ features) & NETIF_F_HW_VLAN_CTAG_RX) {
  2687. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  2688. adapter->aq_required |=
  2689. IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
  2690. else
  2691. adapter->aq_required |=
  2692. IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
  2693. }
  2694. return 0;
  2695. }
  2696. /**
  2697. * iavf_features_check - Validate encapsulated packet conforms to limits
  2698. * @skb: skb buff
  2699. * @dev: This physical port's netdev
  2700. * @features: Offload features that the stack believes apply
  2701. **/
  2702. static netdev_features_t iavf_features_check(struct sk_buff *skb,
  2703. struct net_device *dev,
  2704. netdev_features_t features)
  2705. {
  2706. size_t len;
  2707. /* No point in doing any of this if neither checksum nor GSO are
  2708. * being requested for this frame. We can rule out both by just
  2709. * checking for CHECKSUM_PARTIAL
  2710. */
  2711. if (skb->ip_summed != CHECKSUM_PARTIAL)
  2712. return features;
  2713. /* We cannot support GSO if the MSS is going to be less than
  2714. * 64 bytes. If it is then we need to drop support for GSO.
  2715. */
  2716. if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
  2717. features &= ~NETIF_F_GSO_MASK;
  2718. /* MACLEN can support at most 63 words */
  2719. len = skb_network_header(skb) - skb->data;
  2720. if (len & ~(63 * 2))
  2721. goto out_err;
  2722. /* IPLEN and EIPLEN can support at most 127 dwords */
  2723. len = skb_transport_header(skb) - skb_network_header(skb);
  2724. if (len & ~(127 * 4))
  2725. goto out_err;
  2726. if (skb->encapsulation) {
  2727. /* L4TUNLEN can support 127 words */
  2728. len = skb_inner_network_header(skb) - skb_transport_header(skb);
  2729. if (len & ~(127 * 2))
  2730. goto out_err;
  2731. /* IPLEN can support at most 127 dwords */
  2732. len = skb_inner_transport_header(skb) -
  2733. skb_inner_network_header(skb);
  2734. if (len & ~(127 * 4))
  2735. goto out_err;
  2736. }
  2737. /* No need to validate L4LEN as TCP is the only protocol with a
  2738. * a flexible value and we support all possible values supported
  2739. * by TCP, which is at most 15 dwords
  2740. */
  2741. return features;
  2742. out_err:
  2743. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  2744. }
  2745. /**
  2746. * iavf_fix_features - fix up the netdev feature bits
  2747. * @netdev: our net device
  2748. * @features: desired feature bits
  2749. *
  2750. * Returns fixed-up features bits
  2751. **/
  2752. static netdev_features_t iavf_fix_features(struct net_device *netdev,
  2753. netdev_features_t features)
  2754. {
  2755. struct iavf_adapter *adapter = netdev_priv(netdev);
  2756. if (!(adapter->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
  2757. features &= ~(NETIF_F_HW_VLAN_CTAG_TX |
  2758. NETIF_F_HW_VLAN_CTAG_RX |
  2759. NETIF_F_HW_VLAN_CTAG_FILTER);
  2760. return features;
  2761. }
  2762. static const struct net_device_ops iavf_netdev_ops = {
  2763. .ndo_open = iavf_open,
  2764. .ndo_stop = iavf_close,
  2765. .ndo_start_xmit = iavf_xmit_frame,
  2766. .ndo_set_rx_mode = iavf_set_rx_mode,
  2767. .ndo_validate_addr = eth_validate_addr,
  2768. .ndo_set_mac_address = iavf_set_mac,
  2769. .ndo_change_mtu = iavf_change_mtu,
  2770. .ndo_tx_timeout = iavf_tx_timeout,
  2771. .ndo_vlan_rx_add_vid = iavf_vlan_rx_add_vid,
  2772. .ndo_vlan_rx_kill_vid = iavf_vlan_rx_kill_vid,
  2773. .ndo_features_check = iavf_features_check,
  2774. .ndo_fix_features = iavf_fix_features,
  2775. .ndo_set_features = iavf_set_features,
  2776. .ndo_setup_tc = iavf_setup_tc,
  2777. };
  2778. /**
  2779. * iavf_check_reset_complete - check that VF reset is complete
  2780. * @hw: pointer to hw struct
  2781. *
  2782. * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
  2783. **/
  2784. static int iavf_check_reset_complete(struct iavf_hw *hw)
  2785. {
  2786. u32 rstat;
  2787. int i;
  2788. for (i = 0; i < 100; i++) {
  2789. rstat = rd32(hw, IAVF_VFGEN_RSTAT) &
  2790. IAVF_VFGEN_RSTAT_VFR_STATE_MASK;
  2791. if ((rstat == VIRTCHNL_VFR_VFACTIVE) ||
  2792. (rstat == VIRTCHNL_VFR_COMPLETED))
  2793. return 0;
  2794. usleep_range(10, 20);
  2795. }
  2796. return -EBUSY;
  2797. }
  2798. /**
  2799. * iavf_process_config - Process the config information we got from the PF
  2800. * @adapter: board private structure
  2801. *
  2802. * Verify that we have a valid config struct, and set up our netdev features
  2803. * and our VSI struct.
  2804. **/
  2805. int iavf_process_config(struct iavf_adapter *adapter)
  2806. {
  2807. struct virtchnl_vf_resource *vfres = adapter->vf_res;
  2808. int i, num_req_queues = adapter->num_req_queues;
  2809. struct net_device *netdev = adapter->netdev;
  2810. struct iavf_vsi *vsi = &adapter->vsi;
  2811. netdev_features_t hw_enc_features;
  2812. netdev_features_t hw_features;
  2813. /* got VF config message back from PF, now we can parse it */
  2814. for (i = 0; i < vfres->num_vsis; i++) {
  2815. if (vfres->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
  2816. adapter->vsi_res = &vfres->vsi_res[i];
  2817. }
  2818. if (!adapter->vsi_res) {
  2819. dev_err(&adapter->pdev->dev, "No LAN VSI found\n");
  2820. return -ENODEV;
  2821. }
  2822. if (num_req_queues &&
  2823. num_req_queues != adapter->vsi_res->num_queue_pairs) {
  2824. /* Problem. The PF gave us fewer queues than what we had
  2825. * negotiated in our request. Need a reset to see if we can't
  2826. * get back to a working state.
  2827. */
  2828. dev_err(&adapter->pdev->dev,
  2829. "Requested %d queues, but PF only gave us %d.\n",
  2830. num_req_queues,
  2831. adapter->vsi_res->num_queue_pairs);
  2832. adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
  2833. adapter->num_req_queues = adapter->vsi_res->num_queue_pairs;
  2834. iavf_schedule_reset(adapter);
  2835. return -ENODEV;
  2836. }
  2837. adapter->num_req_queues = 0;
  2838. hw_enc_features = NETIF_F_SG |
  2839. NETIF_F_IP_CSUM |
  2840. NETIF_F_IPV6_CSUM |
  2841. NETIF_F_HIGHDMA |
  2842. NETIF_F_SOFT_FEATURES |
  2843. NETIF_F_TSO |
  2844. NETIF_F_TSO_ECN |
  2845. NETIF_F_TSO6 |
  2846. NETIF_F_SCTP_CRC |
  2847. NETIF_F_RXHASH |
  2848. NETIF_F_RXCSUM |
  2849. 0;
  2850. /* advertise to stack only if offloads for encapsulated packets is
  2851. * supported
  2852. */
  2853. if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ENCAP) {
  2854. hw_enc_features |= NETIF_F_GSO_UDP_TUNNEL |
  2855. NETIF_F_GSO_GRE |
  2856. NETIF_F_GSO_GRE_CSUM |
  2857. NETIF_F_GSO_IPXIP4 |
  2858. NETIF_F_GSO_IPXIP6 |
  2859. NETIF_F_GSO_UDP_TUNNEL_CSUM |
  2860. NETIF_F_GSO_PARTIAL |
  2861. 0;
  2862. if (!(vfres->vf_cap_flags &
  2863. VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM))
  2864. netdev->gso_partial_features |=
  2865. NETIF_F_GSO_UDP_TUNNEL_CSUM;
  2866. netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
  2867. netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
  2868. netdev->hw_enc_features |= hw_enc_features;
  2869. }
  2870. /* record features VLANs can make use of */
  2871. netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID;
  2872. /* Write features and hw_features separately to avoid polluting
  2873. * with, or dropping, features that are set when we registered.
  2874. */
  2875. hw_features = hw_enc_features;
  2876. /* Enable VLAN features if supported */
  2877. if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN)
  2878. hw_features |= (NETIF_F_HW_VLAN_CTAG_TX |
  2879. NETIF_F_HW_VLAN_CTAG_RX);
  2880. /* Enable cloud filter if ADQ is supported */
  2881. if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADQ)
  2882. hw_features |= NETIF_F_HW_TC;
  2883. netdev->hw_features |= hw_features;
  2884. netdev->features |= hw_features;
  2885. if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN)
  2886. netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  2887. netdev->priv_flags |= IFF_UNICAST_FLT;
  2888. /* Do not turn on offloads when they are requested to be turned off.
  2889. * TSO needs minimum 576 bytes to work correctly.
  2890. */
  2891. if (netdev->wanted_features) {
  2892. if (!(netdev->wanted_features & NETIF_F_TSO) ||
  2893. netdev->mtu < 576)
  2894. netdev->features &= ~NETIF_F_TSO;
  2895. if (!(netdev->wanted_features & NETIF_F_TSO6) ||
  2896. netdev->mtu < 576)
  2897. netdev->features &= ~NETIF_F_TSO6;
  2898. if (!(netdev->wanted_features & NETIF_F_TSO_ECN))
  2899. netdev->features &= ~NETIF_F_TSO_ECN;
  2900. if (!(netdev->wanted_features & NETIF_F_GRO))
  2901. netdev->features &= ~NETIF_F_GRO;
  2902. if (!(netdev->wanted_features & NETIF_F_GSO))
  2903. netdev->features &= ~NETIF_F_GSO;
  2904. }
  2905. adapter->vsi.id = adapter->vsi_res->vsi_id;
  2906. adapter->vsi.back = adapter;
  2907. adapter->vsi.base_vector = 1;
  2908. adapter->vsi.work_limit = IAVF_DEFAULT_IRQ_WORK;
  2909. vsi->netdev = adapter->netdev;
  2910. vsi->qs_handle = adapter->vsi_res->qset_handle;
  2911. if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
  2912. adapter->rss_key_size = vfres->rss_key_size;
  2913. adapter->rss_lut_size = vfres->rss_lut_size;
  2914. } else {
  2915. adapter->rss_key_size = IAVF_HKEY_ARRAY_SIZE;
  2916. adapter->rss_lut_size = IAVF_HLUT_ARRAY_SIZE;
  2917. }
  2918. return 0;
  2919. }
  2920. /**
  2921. * iavf_init_task - worker thread to perform delayed initialization
  2922. * @work: pointer to work_struct containing our data
  2923. *
  2924. * This task completes the work that was begun in probe. Due to the nature
  2925. * of VF-PF communications, we may need to wait tens of milliseconds to get
  2926. * responses back from the PF. Rather than busy-wait in probe and bog down the
  2927. * whole system, we'll do it in a task so we can sleep.
  2928. * This task only runs during driver init. Once we've established
  2929. * communications with the PF driver and set up our netdev, the watchdog
  2930. * takes over.
  2931. **/
  2932. static void iavf_init_task(struct work_struct *work)
  2933. {
  2934. struct iavf_adapter *adapter = container_of(work,
  2935. struct iavf_adapter,
  2936. init_task.work);
  2937. struct net_device *netdev = adapter->netdev;
  2938. struct iavf_hw *hw = &adapter->hw;
  2939. struct pci_dev *pdev = adapter->pdev;
  2940. int err, bufsz;
  2941. switch (adapter->state) {
  2942. case __IAVF_STARTUP:
  2943. /* driver loaded, probe complete */
  2944. adapter->flags &= ~IAVF_FLAG_PF_COMMS_FAILED;
  2945. adapter->flags &= ~IAVF_FLAG_RESET_PENDING;
  2946. err = iavf_set_mac_type(hw);
  2947. if (err) {
  2948. dev_err(&pdev->dev, "Failed to set MAC type (%d)\n",
  2949. err);
  2950. goto err;
  2951. }
  2952. err = iavf_check_reset_complete(hw);
  2953. if (err) {
  2954. dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n",
  2955. err);
  2956. goto err;
  2957. }
  2958. hw->aq.num_arq_entries = IAVF_AQ_LEN;
  2959. hw->aq.num_asq_entries = IAVF_AQ_LEN;
  2960. hw->aq.arq_buf_size = IAVF_MAX_AQ_BUF_SIZE;
  2961. hw->aq.asq_buf_size = IAVF_MAX_AQ_BUF_SIZE;
  2962. err = iavf_init_adminq(hw);
  2963. if (err) {
  2964. dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n",
  2965. err);
  2966. goto err;
  2967. }
  2968. err = iavf_send_api_ver(adapter);
  2969. if (err) {
  2970. dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err);
  2971. iavf_shutdown_adminq(hw);
  2972. goto err;
  2973. }
  2974. adapter->state = __IAVF_INIT_VERSION_CHECK;
  2975. goto restart;
  2976. case __IAVF_INIT_VERSION_CHECK:
  2977. if (!iavf_asq_done(hw)) {
  2978. dev_err(&pdev->dev, "Admin queue command never completed\n");
  2979. iavf_shutdown_adminq(hw);
  2980. adapter->state = __IAVF_STARTUP;
  2981. goto err;
  2982. }
  2983. /* aq msg sent, awaiting reply */
  2984. err = iavf_verify_api_ver(adapter);
  2985. if (err) {
  2986. if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  2987. err = iavf_send_api_ver(adapter);
  2988. else
  2989. dev_err(&pdev->dev, "Unsupported PF API version %d.%d, expected %d.%d\n",
  2990. adapter->pf_version.major,
  2991. adapter->pf_version.minor,
  2992. VIRTCHNL_VERSION_MAJOR,
  2993. VIRTCHNL_VERSION_MINOR);
  2994. goto err;
  2995. }
  2996. err = iavf_send_vf_config_msg(adapter);
  2997. if (err) {
  2998. dev_err(&pdev->dev, "Unable to send config request (%d)\n",
  2999. err);
  3000. goto err;
  3001. }
  3002. adapter->state = __IAVF_INIT_GET_RESOURCES;
  3003. goto restart;
  3004. case __IAVF_INIT_GET_RESOURCES:
  3005. /* aq msg sent, awaiting reply */
  3006. if (!adapter->vf_res) {
  3007. bufsz = sizeof(struct virtchnl_vf_resource) +
  3008. (IAVF_MAX_VF_VSI *
  3009. sizeof(struct virtchnl_vsi_resource));
  3010. adapter->vf_res = kzalloc(bufsz, GFP_KERNEL);
  3011. if (!adapter->vf_res)
  3012. goto err;
  3013. }
  3014. err = iavf_get_vf_config(adapter);
  3015. if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
  3016. err = iavf_send_vf_config_msg(adapter);
  3017. goto err;
  3018. } else if (err == I40E_ERR_PARAM) {
  3019. /* We only get ERR_PARAM if the device is in a very bad
  3020. * state or if we've been disabled for previous bad
  3021. * behavior. Either way, we're done now.
  3022. */
  3023. iavf_shutdown_adminq(hw);
  3024. dev_err(&pdev->dev, "Unable to get VF config due to PF error condition, not retrying\n");
  3025. return;
  3026. }
  3027. if (err) {
  3028. dev_err(&pdev->dev, "Unable to get VF config (%d)\n",
  3029. err);
  3030. goto err_alloc;
  3031. }
  3032. adapter->state = __IAVF_INIT_SW;
  3033. break;
  3034. default:
  3035. goto err_alloc;
  3036. }
  3037. if (iavf_process_config(adapter))
  3038. goto err_alloc;
  3039. adapter->current_op = VIRTCHNL_OP_UNKNOWN;
  3040. adapter->flags |= IAVF_FLAG_RX_CSUM_ENABLED;
  3041. netdev->netdev_ops = &iavf_netdev_ops;
  3042. iavf_set_ethtool_ops(netdev);
  3043. netdev->watchdog_timeo = 5 * HZ;
  3044. /* MTU range: 68 - 9710 */
  3045. netdev->min_mtu = ETH_MIN_MTU;
  3046. netdev->max_mtu = IAVF_MAX_RXBUFFER - IAVF_PACKET_HDR_PAD;
  3047. if (!is_valid_ether_addr(adapter->hw.mac.addr)) {
  3048. dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n",
  3049. adapter->hw.mac.addr);
  3050. eth_hw_addr_random(netdev);
  3051. ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
  3052. } else {
  3053. adapter->flags |= IAVF_FLAG_ADDR_SET_BY_PF;
  3054. ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
  3055. ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr);
  3056. }
  3057. timer_setup(&adapter->watchdog_timer, iavf_watchdog_timer, 0);
  3058. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  3059. adapter->tx_desc_count = IAVF_DEFAULT_TXD;
  3060. adapter->rx_desc_count = IAVF_DEFAULT_RXD;
  3061. err = iavf_init_interrupt_scheme(adapter);
  3062. if (err)
  3063. goto err_sw_init;
  3064. iavf_map_rings_to_vectors(adapter);
  3065. if (adapter->vf_res->vf_cap_flags &
  3066. VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
  3067. adapter->flags |= IAVF_FLAG_WB_ON_ITR_CAPABLE;
  3068. err = iavf_request_misc_irq(adapter);
  3069. if (err)
  3070. goto err_sw_init;
  3071. netif_carrier_off(netdev);
  3072. adapter->link_up = false;
  3073. if (!adapter->netdev_registered) {
  3074. err = register_netdev(netdev);
  3075. if (err)
  3076. goto err_register;
  3077. }
  3078. adapter->netdev_registered = true;
  3079. netif_tx_stop_all_queues(netdev);
  3080. if (CLIENT_ALLOWED(adapter)) {
  3081. err = iavf_lan_add_device(adapter);
  3082. if (err)
  3083. dev_info(&pdev->dev, "Failed to add VF to client API service list: %d\n",
  3084. err);
  3085. }
  3086. dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr);
  3087. if (netdev->features & NETIF_F_GRO)
  3088. dev_info(&pdev->dev, "GRO is enabled\n");
  3089. adapter->state = __IAVF_DOWN;
  3090. set_bit(__IAVF_VSI_DOWN, adapter->vsi.state);
  3091. iavf_misc_irq_enable(adapter);
  3092. wake_up(&adapter->down_waitqueue);
  3093. adapter->rss_key = kzalloc(adapter->rss_key_size, GFP_KERNEL);
  3094. adapter->rss_lut = kzalloc(adapter->rss_lut_size, GFP_KERNEL);
  3095. if (!adapter->rss_key || !adapter->rss_lut)
  3096. goto err_mem;
  3097. if (RSS_AQ(adapter)) {
  3098. adapter->aq_required |= IAVF_FLAG_AQ_CONFIGURE_RSS;
  3099. mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
  3100. } else {
  3101. iavf_init_rss(adapter);
  3102. }
  3103. return;
  3104. restart:
  3105. schedule_delayed_work(&adapter->init_task, msecs_to_jiffies(30));
  3106. return;
  3107. err_mem:
  3108. iavf_free_rss(adapter);
  3109. err_register:
  3110. iavf_free_misc_irq(adapter);
  3111. err_sw_init:
  3112. iavf_reset_interrupt_capability(adapter);
  3113. err_alloc:
  3114. kfree(adapter->vf_res);
  3115. adapter->vf_res = NULL;
  3116. err:
  3117. /* Things went into the weeds, so try again later */
  3118. if (++adapter->aq_wait_count > IAVF_AQ_MAX_ERR) {
  3119. dev_err(&pdev->dev, "Failed to communicate with PF; waiting before retry\n");
  3120. adapter->flags |= IAVF_FLAG_PF_COMMS_FAILED;
  3121. iavf_shutdown_adminq(hw);
  3122. adapter->state = __IAVF_STARTUP;
  3123. schedule_delayed_work(&adapter->init_task, HZ * 5);
  3124. return;
  3125. }
  3126. schedule_delayed_work(&adapter->init_task, HZ);
  3127. }
  3128. /**
  3129. * iavf_shutdown - Shutdown the device in preparation for a reboot
  3130. * @pdev: pci device structure
  3131. **/
  3132. static void iavf_shutdown(struct pci_dev *pdev)
  3133. {
  3134. struct net_device *netdev = pci_get_drvdata(pdev);
  3135. struct iavf_adapter *adapter = netdev_priv(netdev);
  3136. netif_device_detach(netdev);
  3137. if (netif_running(netdev))
  3138. iavf_close(netdev);
  3139. /* Prevent the watchdog from running. */
  3140. adapter->state = __IAVF_REMOVE;
  3141. adapter->aq_required = 0;
  3142. #ifdef CONFIG_PM
  3143. pci_save_state(pdev);
  3144. #endif
  3145. pci_disable_device(pdev);
  3146. }
  3147. /**
  3148. * iavf_probe - Device Initialization Routine
  3149. * @pdev: PCI device information struct
  3150. * @ent: entry in iavf_pci_tbl
  3151. *
  3152. * Returns 0 on success, negative on failure
  3153. *
  3154. * iavf_probe initializes an adapter identified by a pci_dev structure.
  3155. * The OS initialization, configuring of the adapter private structure,
  3156. * and a hardware reset occur.
  3157. **/
  3158. static int iavf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  3159. {
  3160. struct net_device *netdev;
  3161. struct iavf_adapter *adapter = NULL;
  3162. struct iavf_hw *hw = NULL;
  3163. int err;
  3164. err = pci_enable_device(pdev);
  3165. if (err)
  3166. return err;
  3167. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  3168. if (err) {
  3169. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  3170. if (err) {
  3171. dev_err(&pdev->dev,
  3172. "DMA configuration failed: 0x%x\n", err);
  3173. goto err_dma;
  3174. }
  3175. }
  3176. err = pci_request_regions(pdev, iavf_driver_name);
  3177. if (err) {
  3178. dev_err(&pdev->dev,
  3179. "pci_request_regions failed 0x%x\n", err);
  3180. goto err_pci_reg;
  3181. }
  3182. pci_enable_pcie_error_reporting(pdev);
  3183. pci_set_master(pdev);
  3184. netdev = alloc_etherdev_mq(sizeof(struct iavf_adapter),
  3185. IAVF_MAX_REQ_QUEUES);
  3186. if (!netdev) {
  3187. err = -ENOMEM;
  3188. goto err_alloc_etherdev;
  3189. }
  3190. SET_NETDEV_DEV(netdev, &pdev->dev);
  3191. pci_set_drvdata(pdev, netdev);
  3192. adapter = netdev_priv(netdev);
  3193. adapter->netdev = netdev;
  3194. adapter->pdev = pdev;
  3195. hw = &adapter->hw;
  3196. hw->back = adapter;
  3197. adapter->msg_enable = BIT(DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
  3198. adapter->state = __IAVF_STARTUP;
  3199. /* Call save state here because it relies on the adapter struct. */
  3200. pci_save_state(pdev);
  3201. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  3202. pci_resource_len(pdev, 0));
  3203. if (!hw->hw_addr) {
  3204. err = -EIO;
  3205. goto err_ioremap;
  3206. }
  3207. hw->vendor_id = pdev->vendor;
  3208. hw->device_id = pdev->device;
  3209. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  3210. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  3211. hw->subsystem_device_id = pdev->subsystem_device;
  3212. hw->bus.device = PCI_SLOT(pdev->devfn);
  3213. hw->bus.func = PCI_FUNC(pdev->devfn);
  3214. hw->bus.bus_id = pdev->bus->number;
  3215. /* set up the locks for the AQ, do this only once in probe
  3216. * and destroy them only once in remove
  3217. */
  3218. mutex_init(&hw->aq.asq_mutex);
  3219. mutex_init(&hw->aq.arq_mutex);
  3220. spin_lock_init(&adapter->mac_vlan_list_lock);
  3221. spin_lock_init(&adapter->cloud_filter_list_lock);
  3222. INIT_LIST_HEAD(&adapter->mac_filter_list);
  3223. INIT_LIST_HEAD(&adapter->vlan_filter_list);
  3224. INIT_LIST_HEAD(&adapter->cloud_filter_list);
  3225. INIT_WORK(&adapter->reset_task, iavf_reset_task);
  3226. INIT_WORK(&adapter->adminq_task, iavf_adminq_task);
  3227. INIT_WORK(&adapter->watchdog_task, iavf_watchdog_task);
  3228. INIT_DELAYED_WORK(&adapter->client_task, iavf_client_task);
  3229. INIT_DELAYED_WORK(&adapter->init_task, iavf_init_task);
  3230. schedule_delayed_work(&adapter->init_task,
  3231. msecs_to_jiffies(5 * (pdev->devfn & 0x07)));
  3232. /* Setup the wait queue for indicating transition to down status */
  3233. init_waitqueue_head(&adapter->down_waitqueue);
  3234. return 0;
  3235. err_ioremap:
  3236. free_netdev(netdev);
  3237. err_alloc_etherdev:
  3238. pci_release_regions(pdev);
  3239. err_pci_reg:
  3240. err_dma:
  3241. pci_disable_device(pdev);
  3242. return err;
  3243. }
  3244. #ifdef CONFIG_PM
  3245. /**
  3246. * iavf_suspend - Power management suspend routine
  3247. * @pdev: PCI device information struct
  3248. * @state: unused
  3249. *
  3250. * Called when the system (VM) is entering sleep/suspend.
  3251. **/
  3252. static int iavf_suspend(struct pci_dev *pdev, pm_message_t state)
  3253. {
  3254. struct net_device *netdev = pci_get_drvdata(pdev);
  3255. struct iavf_adapter *adapter = netdev_priv(netdev);
  3256. int retval = 0;
  3257. netif_device_detach(netdev);
  3258. while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK,
  3259. &adapter->crit_section))
  3260. usleep_range(500, 1000);
  3261. if (netif_running(netdev)) {
  3262. rtnl_lock();
  3263. iavf_down(adapter);
  3264. rtnl_unlock();
  3265. }
  3266. iavf_free_misc_irq(adapter);
  3267. iavf_reset_interrupt_capability(adapter);
  3268. clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section);
  3269. retval = pci_save_state(pdev);
  3270. if (retval)
  3271. return retval;
  3272. pci_disable_device(pdev);
  3273. return 0;
  3274. }
  3275. /**
  3276. * iavf_resume - Power management resume routine
  3277. * @pdev: PCI device information struct
  3278. *
  3279. * Called when the system (VM) is resumed from sleep/suspend.
  3280. **/
  3281. static int iavf_resume(struct pci_dev *pdev)
  3282. {
  3283. struct iavf_adapter *adapter = pci_get_drvdata(pdev);
  3284. struct net_device *netdev = adapter->netdev;
  3285. u32 err;
  3286. pci_set_power_state(pdev, PCI_D0);
  3287. pci_restore_state(pdev);
  3288. /* pci_restore_state clears dev->state_saved so call
  3289. * pci_save_state to restore it.
  3290. */
  3291. pci_save_state(pdev);
  3292. err = pci_enable_device_mem(pdev);
  3293. if (err) {
  3294. dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
  3295. return err;
  3296. }
  3297. pci_set_master(pdev);
  3298. rtnl_lock();
  3299. err = iavf_set_interrupt_capability(adapter);
  3300. if (err) {
  3301. rtnl_unlock();
  3302. dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
  3303. return err;
  3304. }
  3305. err = iavf_request_misc_irq(adapter);
  3306. rtnl_unlock();
  3307. if (err) {
  3308. dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
  3309. return err;
  3310. }
  3311. schedule_work(&adapter->reset_task);
  3312. netif_device_attach(netdev);
  3313. return err;
  3314. }
  3315. #endif /* CONFIG_PM */
  3316. /**
  3317. * iavf_remove - Device Removal Routine
  3318. * @pdev: PCI device information struct
  3319. *
  3320. * iavf_remove is called by the PCI subsystem to alert the driver
  3321. * that it should release a PCI device. The could be caused by a
  3322. * Hot-Plug event, or because the driver is going to be removed from
  3323. * memory.
  3324. **/
  3325. static void iavf_remove(struct pci_dev *pdev)
  3326. {
  3327. struct net_device *netdev = pci_get_drvdata(pdev);
  3328. struct iavf_adapter *adapter = netdev_priv(netdev);
  3329. struct iavf_vlan_filter *vlf, *vlftmp;
  3330. struct iavf_mac_filter *f, *ftmp;
  3331. struct iavf_cloud_filter *cf, *cftmp;
  3332. struct iavf_hw *hw = &adapter->hw;
  3333. int err;
  3334. /* Indicate we are in remove and not to run reset_task */
  3335. set_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section);
  3336. cancel_delayed_work_sync(&adapter->init_task);
  3337. cancel_work_sync(&adapter->reset_task);
  3338. cancel_delayed_work_sync(&adapter->client_task);
  3339. if (adapter->netdev_registered) {
  3340. unregister_netdev(netdev);
  3341. adapter->netdev_registered = false;
  3342. }
  3343. if (CLIENT_ALLOWED(adapter)) {
  3344. err = iavf_lan_del_device(adapter);
  3345. if (err)
  3346. dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
  3347. err);
  3348. }
  3349. /* Shut down all the garbage mashers on the detention level */
  3350. adapter->state = __IAVF_REMOVE;
  3351. adapter->aq_required = 0;
  3352. adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
  3353. iavf_request_reset(adapter);
  3354. msleep(50);
  3355. /* If the FW isn't responding, kick it once, but only once. */
  3356. if (!iavf_asq_done(hw)) {
  3357. iavf_request_reset(adapter);
  3358. msleep(50);
  3359. }
  3360. iavf_free_all_tx_resources(adapter);
  3361. iavf_free_all_rx_resources(adapter);
  3362. iavf_misc_irq_disable(adapter);
  3363. iavf_free_misc_irq(adapter);
  3364. iavf_reset_interrupt_capability(adapter);
  3365. iavf_free_q_vectors(adapter);
  3366. if (adapter->watchdog_timer.function)
  3367. del_timer_sync(&adapter->watchdog_timer);
  3368. cancel_work_sync(&adapter->adminq_task);
  3369. iavf_free_rss(adapter);
  3370. if (hw->aq.asq.count)
  3371. iavf_shutdown_adminq(hw);
  3372. /* destroy the locks only once, here */
  3373. mutex_destroy(&hw->aq.arq_mutex);
  3374. mutex_destroy(&hw->aq.asq_mutex);
  3375. iounmap(hw->hw_addr);
  3376. pci_release_regions(pdev);
  3377. iavf_free_all_tx_resources(adapter);
  3378. iavf_free_all_rx_resources(adapter);
  3379. iavf_free_queues(adapter);
  3380. kfree(adapter->vf_res);
  3381. spin_lock_bh(&adapter->mac_vlan_list_lock);
  3382. /* If we got removed before an up/down sequence, we've got a filter
  3383. * hanging out there that we need to get rid of.
  3384. */
  3385. list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
  3386. list_del(&f->list);
  3387. kfree(f);
  3388. }
  3389. list_for_each_entry_safe(vlf, vlftmp, &adapter->vlan_filter_list,
  3390. list) {
  3391. list_del(&vlf->list);
  3392. kfree(vlf);
  3393. }
  3394. spin_unlock_bh(&adapter->mac_vlan_list_lock);
  3395. spin_lock_bh(&adapter->cloud_filter_list_lock);
  3396. list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
  3397. list_del(&cf->list);
  3398. kfree(cf);
  3399. }
  3400. spin_unlock_bh(&adapter->cloud_filter_list_lock);
  3401. free_netdev(netdev);
  3402. pci_disable_pcie_error_reporting(pdev);
  3403. pci_disable_device(pdev);
  3404. }
  3405. static struct pci_driver iavf_driver = {
  3406. .name = iavf_driver_name,
  3407. .id_table = iavf_pci_tbl,
  3408. .probe = iavf_probe,
  3409. .remove = iavf_remove,
  3410. #ifdef CONFIG_PM
  3411. .suspend = iavf_suspend,
  3412. .resume = iavf_resume,
  3413. #endif
  3414. .shutdown = iavf_shutdown,
  3415. };
  3416. /**
  3417. * iavf_init_module - Driver Registration Routine
  3418. *
  3419. * iavf_init_module is the first routine called when the driver is
  3420. * loaded. All it does is register with the PCI subsystem.
  3421. **/
  3422. static int __init iavf_init_module(void)
  3423. {
  3424. int ret;
  3425. pr_info("iavf: %s - version %s\n", iavf_driver_string,
  3426. iavf_driver_version);
  3427. pr_info("%s\n", iavf_copyright);
  3428. iavf_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1,
  3429. iavf_driver_name);
  3430. if (!iavf_wq) {
  3431. pr_err("%s: Failed to create workqueue\n", iavf_driver_name);
  3432. return -ENOMEM;
  3433. }
  3434. ret = pci_register_driver(&iavf_driver);
  3435. return ret;
  3436. }
  3437. module_init(iavf_init_module);
  3438. /**
  3439. * iavf_exit_module - Driver Exit Cleanup Routine
  3440. *
  3441. * iavf_exit_module is called just before the driver is removed
  3442. * from memory.
  3443. **/
  3444. static void __exit iavf_exit_module(void)
  3445. {
  3446. pci_unregister_driver(&iavf_driver);
  3447. destroy_workqueue(iavf_wq);
  3448. }
  3449. module_exit(iavf_exit_module);
  3450. /* iavf_main.c */