i40e_virtchnl_pf.c 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2016 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. #include "i40e.h"
  27. /*********************notification routines***********************/
  28. /**
  29. * i40e_vc_vf_broadcast
  30. * @pf: pointer to the PF structure
  31. * @opcode: operation code
  32. * @retval: return value
  33. * @msg: pointer to the msg buffer
  34. * @msglen: msg length
  35. *
  36. * send a message to all VFs on a given PF
  37. **/
  38. static void i40e_vc_vf_broadcast(struct i40e_pf *pf,
  39. enum i40e_virtchnl_ops v_opcode,
  40. i40e_status v_retval, u8 *msg,
  41. u16 msglen)
  42. {
  43. struct i40e_hw *hw = &pf->hw;
  44. struct i40e_vf *vf = pf->vf;
  45. int i;
  46. for (i = 0; i < pf->num_alloc_vfs; i++, vf++) {
  47. int abs_vf_id = vf->vf_id + (int)hw->func_caps.vf_base_id;
  48. /* Not all vfs are enabled so skip the ones that are not */
  49. if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
  50. !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
  51. continue;
  52. /* Ignore return value on purpose - a given VF may fail, but
  53. * we need to keep going and send to all of them
  54. */
  55. i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
  56. msg, msglen, NULL);
  57. }
  58. }
  59. /**
  60. * i40e_vc_notify_vf_link_state
  61. * @vf: pointer to the VF structure
  62. *
  63. * send a link status message to a single VF
  64. **/
  65. static void i40e_vc_notify_vf_link_state(struct i40e_vf *vf)
  66. {
  67. struct i40e_virtchnl_pf_event pfe;
  68. struct i40e_pf *pf = vf->pf;
  69. struct i40e_hw *hw = &pf->hw;
  70. struct i40e_link_status *ls = &pf->hw.phy.link_info;
  71. int abs_vf_id = vf->vf_id + (int)hw->func_caps.vf_base_id;
  72. pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
  73. pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
  74. if (vf->link_forced) {
  75. pfe.event_data.link_event.link_status = vf->link_up;
  76. pfe.event_data.link_event.link_speed =
  77. (vf->link_up ? I40E_LINK_SPEED_40GB : 0);
  78. } else {
  79. pfe.event_data.link_event.link_status =
  80. ls->link_info & I40E_AQ_LINK_UP;
  81. pfe.event_data.link_event.link_speed = ls->link_speed;
  82. }
  83. i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
  84. 0, (u8 *)&pfe, sizeof(pfe), NULL);
  85. }
  86. /**
  87. * i40e_vc_notify_link_state
  88. * @pf: pointer to the PF structure
  89. *
  90. * send a link status message to all VFs on a given PF
  91. **/
  92. void i40e_vc_notify_link_state(struct i40e_pf *pf)
  93. {
  94. int i;
  95. for (i = 0; i < pf->num_alloc_vfs; i++)
  96. i40e_vc_notify_vf_link_state(&pf->vf[i]);
  97. }
  98. /**
  99. * i40e_vc_notify_reset
  100. * @pf: pointer to the PF structure
  101. *
  102. * indicate a pending reset to all VFs on a given PF
  103. **/
  104. void i40e_vc_notify_reset(struct i40e_pf *pf)
  105. {
  106. struct i40e_virtchnl_pf_event pfe;
  107. pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
  108. pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
  109. i40e_vc_vf_broadcast(pf, I40E_VIRTCHNL_OP_EVENT, 0,
  110. (u8 *)&pfe, sizeof(struct i40e_virtchnl_pf_event));
  111. }
  112. /**
  113. * i40e_vc_notify_vf_reset
  114. * @vf: pointer to the VF structure
  115. *
  116. * indicate a pending reset to the given VF
  117. **/
  118. void i40e_vc_notify_vf_reset(struct i40e_vf *vf)
  119. {
  120. struct i40e_virtchnl_pf_event pfe;
  121. int abs_vf_id;
  122. /* validate the request */
  123. if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
  124. return;
  125. /* verify if the VF is in either init or active before proceeding */
  126. if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states) &&
  127. !test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
  128. return;
  129. abs_vf_id = vf->vf_id + (int)vf->pf->hw.func_caps.vf_base_id;
  130. pfe.event = I40E_VIRTCHNL_EVENT_RESET_IMPENDING;
  131. pfe.severity = I40E_PF_EVENT_SEVERITY_CERTAIN_DOOM;
  132. i40e_aq_send_msg_to_vf(&vf->pf->hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
  133. 0, (u8 *)&pfe,
  134. sizeof(struct i40e_virtchnl_pf_event), NULL);
  135. }
  136. /***********************misc routines*****************************/
  137. /**
  138. * i40e_vc_disable_vf
  139. * @pf: pointer to the PF info
  140. * @vf: pointer to the VF info
  141. *
  142. * Disable the VF through a SW reset
  143. **/
  144. static inline void i40e_vc_disable_vf(struct i40e_pf *pf, struct i40e_vf *vf)
  145. {
  146. i40e_vc_notify_vf_reset(vf);
  147. i40e_reset_vf(vf, false);
  148. }
  149. /**
  150. * i40e_vc_isvalid_vsi_id
  151. * @vf: pointer to the VF info
  152. * @vsi_id: VF relative VSI id
  153. *
  154. * check for the valid VSI id
  155. **/
  156. static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf *vf, u16 vsi_id)
  157. {
  158. struct i40e_pf *pf = vf->pf;
  159. struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
  160. return (vsi && (vsi->vf_id == vf->vf_id));
  161. }
  162. /**
  163. * i40e_vc_isvalid_queue_id
  164. * @vf: pointer to the VF info
  165. * @vsi_id: vsi id
  166. * @qid: vsi relative queue id
  167. *
  168. * check for the valid queue id
  169. **/
  170. static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf *vf, u16 vsi_id,
  171. u8 qid)
  172. {
  173. struct i40e_pf *pf = vf->pf;
  174. struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
  175. return (vsi && (qid < vsi->alloc_queue_pairs));
  176. }
  177. /**
  178. * i40e_vc_isvalid_vector_id
  179. * @vf: pointer to the VF info
  180. * @vector_id: VF relative vector id
  181. *
  182. * check for the valid vector id
  183. **/
  184. static inline bool i40e_vc_isvalid_vector_id(struct i40e_vf *vf, u8 vector_id)
  185. {
  186. struct i40e_pf *pf = vf->pf;
  187. return vector_id < pf->hw.func_caps.num_msix_vectors_vf;
  188. }
  189. /***********************vf resource mgmt routines*****************/
  190. /**
  191. * i40e_vc_get_pf_queue_id
  192. * @vf: pointer to the VF info
  193. * @vsi_id: id of VSI as provided by the FW
  194. * @vsi_queue_id: vsi relative queue id
  195. *
  196. * return PF relative queue id
  197. **/
  198. static u16 i40e_vc_get_pf_queue_id(struct i40e_vf *vf, u16 vsi_id,
  199. u8 vsi_queue_id)
  200. {
  201. struct i40e_pf *pf = vf->pf;
  202. struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
  203. u16 pf_queue_id = I40E_QUEUE_END_OF_LIST;
  204. if (!vsi)
  205. return pf_queue_id;
  206. if (le16_to_cpu(vsi->info.mapping_flags) &
  207. I40E_AQ_VSI_QUE_MAP_NONCONTIG)
  208. pf_queue_id =
  209. le16_to_cpu(vsi->info.queue_mapping[vsi_queue_id]);
  210. else
  211. pf_queue_id = le16_to_cpu(vsi->info.queue_mapping[0]) +
  212. vsi_queue_id;
  213. return pf_queue_id;
  214. }
  215. /**
  216. * i40e_config_irq_link_list
  217. * @vf: pointer to the VF info
  218. * @vsi_id: id of VSI as given by the FW
  219. * @vecmap: irq map info
  220. *
  221. * configure irq link list from the map
  222. **/
  223. static void i40e_config_irq_link_list(struct i40e_vf *vf, u16 vsi_id,
  224. struct i40e_virtchnl_vector_map *vecmap)
  225. {
  226. unsigned long linklistmap = 0, tempmap;
  227. struct i40e_pf *pf = vf->pf;
  228. struct i40e_hw *hw = &pf->hw;
  229. u16 vsi_queue_id, pf_queue_id;
  230. enum i40e_queue_type qtype;
  231. u16 next_q, vector_id;
  232. u32 reg, reg_idx;
  233. u16 itr_idx = 0;
  234. vector_id = vecmap->vector_id;
  235. /* setup the head */
  236. if (0 == vector_id)
  237. reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
  238. else
  239. reg_idx = I40E_VPINT_LNKLSTN(
  240. ((pf->hw.func_caps.num_msix_vectors_vf - 1) * vf->vf_id) +
  241. (vector_id - 1));
  242. if (vecmap->rxq_map == 0 && vecmap->txq_map == 0) {
  243. /* Special case - No queues mapped on this vector */
  244. wr32(hw, reg_idx, I40E_VPINT_LNKLST0_FIRSTQ_INDX_MASK);
  245. goto irq_list_done;
  246. }
  247. tempmap = vecmap->rxq_map;
  248. for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
  249. linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
  250. vsi_queue_id));
  251. }
  252. tempmap = vecmap->txq_map;
  253. for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
  254. linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
  255. vsi_queue_id + 1));
  256. }
  257. next_q = find_first_bit(&linklistmap,
  258. (I40E_MAX_VSI_QP *
  259. I40E_VIRTCHNL_SUPPORTED_QTYPES));
  260. vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES;
  261. qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES;
  262. pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
  263. reg = ((qtype << I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT) | pf_queue_id);
  264. wr32(hw, reg_idx, reg);
  265. while (next_q < (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
  266. switch (qtype) {
  267. case I40E_QUEUE_TYPE_RX:
  268. reg_idx = I40E_QINT_RQCTL(pf_queue_id);
  269. itr_idx = vecmap->rxitr_idx;
  270. break;
  271. case I40E_QUEUE_TYPE_TX:
  272. reg_idx = I40E_QINT_TQCTL(pf_queue_id);
  273. itr_idx = vecmap->txitr_idx;
  274. break;
  275. default:
  276. break;
  277. }
  278. next_q = find_next_bit(&linklistmap,
  279. (I40E_MAX_VSI_QP *
  280. I40E_VIRTCHNL_SUPPORTED_QTYPES),
  281. next_q + 1);
  282. if (next_q <
  283. (I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES)) {
  284. vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES;
  285. qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES;
  286. pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id,
  287. vsi_queue_id);
  288. } else {
  289. pf_queue_id = I40E_QUEUE_END_OF_LIST;
  290. qtype = 0;
  291. }
  292. /* format for the RQCTL & TQCTL regs is same */
  293. reg = (vector_id) |
  294. (qtype << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
  295. (pf_queue_id << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
  296. BIT(I40E_QINT_RQCTL_CAUSE_ENA_SHIFT) |
  297. (itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT);
  298. wr32(hw, reg_idx, reg);
  299. }
  300. /* if the vf is running in polling mode and using interrupt zero,
  301. * need to disable auto-mask on enabling zero interrupt for VFs.
  302. */
  303. if ((vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING) &&
  304. (vector_id == 0)) {
  305. reg = rd32(hw, I40E_GLINT_CTL);
  306. if (!(reg & I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK)) {
  307. reg |= I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
  308. wr32(hw, I40E_GLINT_CTL, reg);
  309. }
  310. }
  311. irq_list_done:
  312. i40e_flush(hw);
  313. }
  314. /**
  315. * i40e_release_iwarp_qvlist
  316. * @vf: pointer to the VF.
  317. *
  318. **/
  319. static void i40e_release_iwarp_qvlist(struct i40e_vf *vf)
  320. {
  321. struct i40e_pf *pf = vf->pf;
  322. struct i40e_virtchnl_iwarp_qvlist_info *qvlist_info = vf->qvlist_info;
  323. u32 msix_vf;
  324. u32 i;
  325. if (!vf->qvlist_info)
  326. return;
  327. msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
  328. for (i = 0; i < qvlist_info->num_vectors; i++) {
  329. struct i40e_virtchnl_iwarp_qv_info *qv_info;
  330. u32 next_q_index, next_q_type;
  331. struct i40e_hw *hw = &pf->hw;
  332. u32 v_idx, reg_idx, reg;
  333. qv_info = &qvlist_info->qv_info[i];
  334. if (!qv_info)
  335. continue;
  336. v_idx = qv_info->v_idx;
  337. if (qv_info->ceq_idx != I40E_QUEUE_INVALID_IDX) {
  338. /* Figure out the queue after CEQ and make that the
  339. * first queue.
  340. */
  341. reg_idx = (msix_vf - 1) * vf->vf_id + qv_info->ceq_idx;
  342. reg = rd32(hw, I40E_VPINT_CEQCTL(reg_idx));
  343. next_q_index = (reg & I40E_VPINT_CEQCTL_NEXTQ_INDX_MASK)
  344. >> I40E_VPINT_CEQCTL_NEXTQ_INDX_SHIFT;
  345. next_q_type = (reg & I40E_VPINT_CEQCTL_NEXTQ_TYPE_MASK)
  346. >> I40E_VPINT_CEQCTL_NEXTQ_TYPE_SHIFT;
  347. reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
  348. reg = (next_q_index &
  349. I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) |
  350. (next_q_type <<
  351. I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
  352. wr32(hw, I40E_VPINT_LNKLSTN(reg_idx), reg);
  353. }
  354. }
  355. kfree(vf->qvlist_info);
  356. vf->qvlist_info = NULL;
  357. }
  358. /**
  359. * i40e_config_iwarp_qvlist
  360. * @vf: pointer to the VF info
  361. * @qvlist_info: queue and vector list
  362. *
  363. * Return 0 on success or < 0 on error
  364. **/
  365. static int i40e_config_iwarp_qvlist(struct i40e_vf *vf,
  366. struct i40e_virtchnl_iwarp_qvlist_info *qvlist_info)
  367. {
  368. struct i40e_pf *pf = vf->pf;
  369. struct i40e_hw *hw = &pf->hw;
  370. struct i40e_virtchnl_iwarp_qv_info *qv_info;
  371. u32 v_idx, i, reg_idx, reg;
  372. u32 next_q_idx, next_q_type;
  373. u32 msix_vf, size;
  374. size = sizeof(struct i40e_virtchnl_iwarp_qvlist_info) +
  375. (sizeof(struct i40e_virtchnl_iwarp_qv_info) *
  376. (qvlist_info->num_vectors - 1));
  377. vf->qvlist_info = kzalloc(size, GFP_KERNEL);
  378. vf->qvlist_info->num_vectors = qvlist_info->num_vectors;
  379. msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
  380. for (i = 0; i < qvlist_info->num_vectors; i++) {
  381. qv_info = &qvlist_info->qv_info[i];
  382. if (!qv_info)
  383. continue;
  384. v_idx = qv_info->v_idx;
  385. /* Validate vector id belongs to this vf */
  386. if (!i40e_vc_isvalid_vector_id(vf, v_idx))
  387. goto err;
  388. vf->qvlist_info->qv_info[i] = *qv_info;
  389. reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
  390. /* We might be sharing the interrupt, so get the first queue
  391. * index and type, push it down the list by adding the new
  392. * queue on top. Also link it with the new queue in CEQCTL.
  393. */
  394. reg = rd32(hw, I40E_VPINT_LNKLSTN(reg_idx));
  395. next_q_idx = ((reg & I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) >>
  396. I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT);
  397. next_q_type = ((reg & I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK) >>
  398. I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
  399. if (qv_info->ceq_idx != I40E_QUEUE_INVALID_IDX) {
  400. reg_idx = (msix_vf - 1) * vf->vf_id + qv_info->ceq_idx;
  401. reg = (I40E_VPINT_CEQCTL_CAUSE_ENA_MASK |
  402. (v_idx << I40E_VPINT_CEQCTL_MSIX_INDX_SHIFT) |
  403. (qv_info->itr_idx << I40E_VPINT_CEQCTL_ITR_INDX_SHIFT) |
  404. (next_q_type << I40E_VPINT_CEQCTL_NEXTQ_TYPE_SHIFT) |
  405. (next_q_idx << I40E_VPINT_CEQCTL_NEXTQ_INDX_SHIFT));
  406. wr32(hw, I40E_VPINT_CEQCTL(reg_idx), reg);
  407. reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
  408. reg = (qv_info->ceq_idx &
  409. I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) |
  410. (I40E_QUEUE_TYPE_PE_CEQ <<
  411. I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
  412. wr32(hw, I40E_VPINT_LNKLSTN(reg_idx), reg);
  413. }
  414. if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
  415. reg = (I40E_VPINT_AEQCTL_CAUSE_ENA_MASK |
  416. (v_idx << I40E_VPINT_AEQCTL_MSIX_INDX_SHIFT) |
  417. (qv_info->itr_idx << I40E_VPINT_AEQCTL_ITR_INDX_SHIFT));
  418. wr32(hw, I40E_VPINT_AEQCTL(vf->vf_id), reg);
  419. }
  420. }
  421. return 0;
  422. err:
  423. kfree(vf->qvlist_info);
  424. vf->qvlist_info = NULL;
  425. return -EINVAL;
  426. }
  427. /**
  428. * i40e_config_vsi_tx_queue
  429. * @vf: pointer to the VF info
  430. * @vsi_id: id of VSI as provided by the FW
  431. * @vsi_queue_id: vsi relative queue index
  432. * @info: config. info
  433. *
  434. * configure tx queue
  435. **/
  436. static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_id,
  437. u16 vsi_queue_id,
  438. struct i40e_virtchnl_txq_info *info)
  439. {
  440. struct i40e_pf *pf = vf->pf;
  441. struct i40e_hw *hw = &pf->hw;
  442. struct i40e_hmc_obj_txq tx_ctx;
  443. struct i40e_vsi *vsi;
  444. u16 pf_queue_id;
  445. u32 qtx_ctl;
  446. int ret = 0;
  447. if (!i40e_vc_isvalid_vsi_id(vf, info->vsi_id)) {
  448. ret = -ENOENT;
  449. goto error_context;
  450. }
  451. pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
  452. vsi = i40e_find_vsi_from_id(pf, vsi_id);
  453. if (!vsi) {
  454. ret = -ENOENT;
  455. goto error_context;
  456. }
  457. /* clear the context structure first */
  458. memset(&tx_ctx, 0, sizeof(struct i40e_hmc_obj_txq));
  459. /* only set the required fields */
  460. tx_ctx.base = info->dma_ring_addr / 128;
  461. tx_ctx.qlen = info->ring_len;
  462. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]);
  463. tx_ctx.rdylist_act = 0;
  464. tx_ctx.head_wb_ena = info->headwb_enabled;
  465. tx_ctx.head_wb_addr = info->dma_headwb_addr;
  466. /* clear the context in the HMC */
  467. ret = i40e_clear_lan_tx_queue_context(hw, pf_queue_id);
  468. if (ret) {
  469. dev_err(&pf->pdev->dev,
  470. "Failed to clear VF LAN Tx queue context %d, error: %d\n",
  471. pf_queue_id, ret);
  472. ret = -ENOENT;
  473. goto error_context;
  474. }
  475. /* set the context in the HMC */
  476. ret = i40e_set_lan_tx_queue_context(hw, pf_queue_id, &tx_ctx);
  477. if (ret) {
  478. dev_err(&pf->pdev->dev,
  479. "Failed to set VF LAN Tx queue context %d error: %d\n",
  480. pf_queue_id, ret);
  481. ret = -ENOENT;
  482. goto error_context;
  483. }
  484. /* associate this queue with the PCI VF function */
  485. qtx_ctl = I40E_QTX_CTL_VF_QUEUE;
  486. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT)
  487. & I40E_QTX_CTL_PF_INDX_MASK);
  488. qtx_ctl |= (((vf->vf_id + hw->func_caps.vf_base_id)
  489. << I40E_QTX_CTL_VFVM_INDX_SHIFT)
  490. & I40E_QTX_CTL_VFVM_INDX_MASK);
  491. wr32(hw, I40E_QTX_CTL(pf_queue_id), qtx_ctl);
  492. i40e_flush(hw);
  493. error_context:
  494. return ret;
  495. }
  496. /**
  497. * i40e_config_vsi_rx_queue
  498. * @vf: pointer to the VF info
  499. * @vsi_id: id of VSI as provided by the FW
  500. * @vsi_queue_id: vsi relative queue index
  501. * @info: config. info
  502. *
  503. * configure rx queue
  504. **/
  505. static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id,
  506. u16 vsi_queue_id,
  507. struct i40e_virtchnl_rxq_info *info)
  508. {
  509. struct i40e_pf *pf = vf->pf;
  510. struct i40e_hw *hw = &pf->hw;
  511. struct i40e_hmc_obj_rxq rx_ctx;
  512. u16 pf_queue_id;
  513. int ret = 0;
  514. pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
  515. /* clear the context structure first */
  516. memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
  517. /* only set the required fields */
  518. rx_ctx.base = info->dma_ring_addr / 128;
  519. rx_ctx.qlen = info->ring_len;
  520. if (info->splithdr_enabled) {
  521. rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
  522. I40E_RX_SPLIT_IP |
  523. I40E_RX_SPLIT_TCP_UDP |
  524. I40E_RX_SPLIT_SCTP;
  525. /* header length validation */
  526. if (info->hdr_size > ((2 * 1024) - 64)) {
  527. ret = -EINVAL;
  528. goto error_param;
  529. }
  530. rx_ctx.hbuff = info->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT;
  531. /* set split mode 10b */
  532. rx_ctx.dtype = I40E_RX_DTYPE_HEADER_SPLIT;
  533. }
  534. /* databuffer length validation */
  535. if (info->databuffer_size > ((16 * 1024) - 128)) {
  536. ret = -EINVAL;
  537. goto error_param;
  538. }
  539. rx_ctx.dbuff = info->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT;
  540. /* max pkt. length validation */
  541. if (info->max_pkt_size >= (16 * 1024) || info->max_pkt_size < 64) {
  542. ret = -EINVAL;
  543. goto error_param;
  544. }
  545. rx_ctx.rxmax = info->max_pkt_size;
  546. /* enable 32bytes desc always */
  547. rx_ctx.dsize = 1;
  548. /* default values */
  549. rx_ctx.lrxqthresh = 2;
  550. rx_ctx.crcstrip = 1;
  551. rx_ctx.prefena = 1;
  552. rx_ctx.l2tsel = 1;
  553. /* clear the context in the HMC */
  554. ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id);
  555. if (ret) {
  556. dev_err(&pf->pdev->dev,
  557. "Failed to clear VF LAN Rx queue context %d, error: %d\n",
  558. pf_queue_id, ret);
  559. ret = -ENOENT;
  560. goto error_param;
  561. }
  562. /* set the context in the HMC */
  563. ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx);
  564. if (ret) {
  565. dev_err(&pf->pdev->dev,
  566. "Failed to set VF LAN Rx queue context %d error: %d\n",
  567. pf_queue_id, ret);
  568. ret = -ENOENT;
  569. goto error_param;
  570. }
  571. error_param:
  572. return ret;
  573. }
  574. /**
  575. * i40e_alloc_vsi_res
  576. * @vf: pointer to the VF info
  577. * @type: type of VSI to allocate
  578. *
  579. * alloc VF vsi context & resources
  580. **/
  581. static int i40e_alloc_vsi_res(struct i40e_vf *vf, enum i40e_vsi_type type)
  582. {
  583. struct i40e_mac_filter *f = NULL;
  584. struct i40e_pf *pf = vf->pf;
  585. struct i40e_vsi *vsi;
  586. int ret = 0;
  587. vsi = i40e_vsi_setup(pf, type, pf->vsi[pf->lan_vsi]->seid, vf->vf_id);
  588. if (!vsi) {
  589. dev_err(&pf->pdev->dev,
  590. "add vsi failed for VF %d, aq_err %d\n",
  591. vf->vf_id, pf->hw.aq.asq_last_status);
  592. ret = -ENOENT;
  593. goto error_alloc_vsi_res;
  594. }
  595. if (type == I40E_VSI_SRIOV) {
  596. u64 hena = i40e_pf_get_default_rss_hena(pf);
  597. u8 broadcast[ETH_ALEN];
  598. vf->lan_vsi_idx = vsi->idx;
  599. vf->lan_vsi_id = vsi->id;
  600. /* If the port VLAN has been configured and then the
  601. * VF driver was removed then the VSI port VLAN
  602. * configuration was destroyed. Check if there is
  603. * a port VLAN and restore the VSI configuration if
  604. * needed.
  605. */
  606. if (vf->port_vlan_id)
  607. i40e_vsi_add_pvid(vsi, vf->port_vlan_id);
  608. spin_lock_bh(&vsi->mac_filter_hash_lock);
  609. if (is_valid_ether_addr(vf->default_lan_addr.addr)) {
  610. f = i40e_add_mac_filter(vsi,
  611. vf->default_lan_addr.addr);
  612. if (!f)
  613. dev_info(&pf->pdev->dev,
  614. "Could not add MAC filter %pM for VF %d\n",
  615. vf->default_lan_addr.addr, vf->vf_id);
  616. }
  617. eth_broadcast_addr(broadcast);
  618. f = i40e_add_mac_filter(vsi, broadcast);
  619. if (!f)
  620. dev_info(&pf->pdev->dev,
  621. "Could not allocate VF broadcast filter\n");
  622. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  623. wr32(&pf->hw, I40E_VFQF_HENA1(0, vf->vf_id), (u32)hena);
  624. wr32(&pf->hw, I40E_VFQF_HENA1(1, vf->vf_id), (u32)(hena >> 32));
  625. }
  626. /* program mac filter */
  627. ret = i40e_sync_vsi_filters(vsi);
  628. if (ret)
  629. dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
  630. /* Set VF bandwidth if specified */
  631. if (vf->tx_rate) {
  632. ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
  633. vf->tx_rate / 50, 0, NULL);
  634. if (ret)
  635. dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
  636. vf->vf_id, ret);
  637. }
  638. error_alloc_vsi_res:
  639. return ret;
  640. }
  641. /**
  642. * i40e_enable_vf_mappings
  643. * @vf: pointer to the VF info
  644. *
  645. * enable VF mappings
  646. **/
  647. static void i40e_enable_vf_mappings(struct i40e_vf *vf)
  648. {
  649. struct i40e_pf *pf = vf->pf;
  650. struct i40e_hw *hw = &pf->hw;
  651. u32 reg, total_queue_pairs = 0;
  652. int j;
  653. /* Tell the hardware we're using noncontiguous mapping. HW requires
  654. * that VF queues be mapped using this method, even when they are
  655. * contiguous in real life
  656. */
  657. i40e_write_rx_ctl(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id),
  658. I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
  659. /* enable VF vplan_qtable mappings */
  660. reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK;
  661. wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg);
  662. /* map PF queues to VF queues */
  663. for (j = 0; j < pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; j++) {
  664. u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, j);
  665. reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK);
  666. wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg);
  667. total_queue_pairs++;
  668. }
  669. /* map PF queues to VSI */
  670. for (j = 0; j < 7; j++) {
  671. if (j * 2 >= pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs) {
  672. reg = 0x07FF07FF; /* unused */
  673. } else {
  674. u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
  675. j * 2);
  676. reg = qid;
  677. qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
  678. (j * 2) + 1);
  679. reg |= qid << 16;
  680. }
  681. i40e_write_rx_ctl(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id),
  682. reg);
  683. }
  684. i40e_flush(hw);
  685. }
  686. /**
  687. * i40e_disable_vf_mappings
  688. * @vf: pointer to the VF info
  689. *
  690. * disable VF mappings
  691. **/
  692. static void i40e_disable_vf_mappings(struct i40e_vf *vf)
  693. {
  694. struct i40e_pf *pf = vf->pf;
  695. struct i40e_hw *hw = &pf->hw;
  696. int i;
  697. /* disable qp mappings */
  698. wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0);
  699. for (i = 0; i < I40E_MAX_VSI_QP; i++)
  700. wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id),
  701. I40E_QUEUE_END_OF_LIST);
  702. i40e_flush(hw);
  703. }
  704. /**
  705. * i40e_free_vf_res
  706. * @vf: pointer to the VF info
  707. *
  708. * free VF resources
  709. **/
  710. static void i40e_free_vf_res(struct i40e_vf *vf)
  711. {
  712. struct i40e_pf *pf = vf->pf;
  713. struct i40e_hw *hw = &pf->hw;
  714. u32 reg_idx, reg;
  715. int i, msix_vf;
  716. /* Start by disabling VF's configuration API to prevent the OS from
  717. * accessing the VF's VSI after it's freed / invalidated.
  718. */
  719. clear_bit(I40E_VF_STAT_INIT, &vf->vf_states);
  720. /* free vsi & disconnect it from the parent uplink */
  721. if (vf->lan_vsi_idx) {
  722. i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]);
  723. vf->lan_vsi_idx = 0;
  724. vf->lan_vsi_id = 0;
  725. vf->num_mac = 0;
  726. }
  727. msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
  728. /* disable interrupts so the VF starts in a known state */
  729. for (i = 0; i < msix_vf; i++) {
  730. /* format is same for both registers */
  731. if (0 == i)
  732. reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id);
  733. else
  734. reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
  735. (vf->vf_id))
  736. + (i - 1));
  737. wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
  738. i40e_flush(hw);
  739. }
  740. /* clear the irq settings */
  741. for (i = 0; i < msix_vf; i++) {
  742. /* format is same for both registers */
  743. if (0 == i)
  744. reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
  745. else
  746. reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
  747. (vf->vf_id))
  748. + (i - 1));
  749. reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
  750. I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
  751. wr32(hw, reg_idx, reg);
  752. i40e_flush(hw);
  753. }
  754. /* reset some of the state variables keeping track of the resources */
  755. vf->num_queue_pairs = 0;
  756. vf->vf_states = 0;
  757. }
  758. /**
  759. * i40e_alloc_vf_res
  760. * @vf: pointer to the VF info
  761. *
  762. * allocate VF resources
  763. **/
  764. static int i40e_alloc_vf_res(struct i40e_vf *vf)
  765. {
  766. struct i40e_pf *pf = vf->pf;
  767. int total_queue_pairs = 0;
  768. int ret;
  769. /* allocate hw vsi context & associated resources */
  770. ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV);
  771. if (ret)
  772. goto error_alloc;
  773. total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
  774. if (vf->trusted)
  775. set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
  776. else
  777. clear_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
  778. /* store the total qps number for the runtime
  779. * VF req validation
  780. */
  781. vf->num_queue_pairs = total_queue_pairs;
  782. /* VF is now completely initialized */
  783. set_bit(I40E_VF_STAT_INIT, &vf->vf_states);
  784. error_alloc:
  785. if (ret)
  786. i40e_free_vf_res(vf);
  787. return ret;
  788. }
  789. #define VF_DEVICE_STATUS 0xAA
  790. #define VF_TRANS_PENDING_MASK 0x20
  791. /**
  792. * i40e_quiesce_vf_pci
  793. * @vf: pointer to the VF structure
  794. *
  795. * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
  796. * if the transactions never clear.
  797. **/
  798. static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
  799. {
  800. struct i40e_pf *pf = vf->pf;
  801. struct i40e_hw *hw = &pf->hw;
  802. int vf_abs_id, i;
  803. u32 reg;
  804. vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id;
  805. wr32(hw, I40E_PF_PCI_CIAA,
  806. VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
  807. for (i = 0; i < 100; i++) {
  808. reg = rd32(hw, I40E_PF_PCI_CIAD);
  809. if ((reg & VF_TRANS_PENDING_MASK) == 0)
  810. return 0;
  811. udelay(1);
  812. }
  813. return -EIO;
  814. }
  815. /**
  816. * i40e_reset_vf
  817. * @vf: pointer to the VF structure
  818. * @flr: VFLR was issued or not
  819. *
  820. * reset the VF
  821. **/
  822. void i40e_reset_vf(struct i40e_vf *vf, bool flr)
  823. {
  824. struct i40e_pf *pf = vf->pf;
  825. struct i40e_hw *hw = &pf->hw;
  826. u32 reg, reg_idx, bit_idx;
  827. bool rsd = false;
  828. int i;
  829. if (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
  830. return;
  831. /* warn the VF */
  832. clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
  833. /* Disable VF's configuration API during reset. The flag is re-enabled
  834. * in i40e_alloc_vf_res(), when it's safe again to access VF's VSI.
  835. * It's normally disabled in i40e_free_vf_res(), but it's safer
  836. * to do it earlier to give some time to finish to any VF config
  837. * functions that may still be running at this point.
  838. */
  839. clear_bit(I40E_VF_STAT_INIT, &vf->vf_states);
  840. /* In the case of a VFLR, the HW has already reset the VF and we
  841. * just need to clean up, so don't hit the VFRTRIG register.
  842. */
  843. if (!flr) {
  844. /* reset VF using VPGEN_VFRTRIG reg */
  845. reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
  846. reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
  847. wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
  848. i40e_flush(hw);
  849. }
  850. /* clear the VFLR bit in GLGEN_VFLRSTAT */
  851. reg_idx = (hw->func_caps.vf_base_id + vf->vf_id) / 32;
  852. bit_idx = (hw->func_caps.vf_base_id + vf->vf_id) % 32;
  853. wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
  854. i40e_flush(hw);
  855. if (i40e_quiesce_vf_pci(vf))
  856. dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
  857. vf->vf_id);
  858. /* poll VPGEN_VFRSTAT reg to make sure
  859. * that reset is complete
  860. */
  861. for (i = 0; i < 10; i++) {
  862. /* VF reset requires driver to first reset the VF and then
  863. * poll the status register to make sure that the reset
  864. * completed successfully. Due to internal HW FIFO flushes,
  865. * we must wait 10ms before the register will be valid.
  866. */
  867. usleep_range(10000, 20000);
  868. reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
  869. if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
  870. rsd = true;
  871. break;
  872. }
  873. }
  874. if (flr)
  875. usleep_range(10000, 20000);
  876. if (!rsd)
  877. dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
  878. vf->vf_id);
  879. /* On initial reset, we won't have any queues */
  880. if (vf->lan_vsi_idx == 0)
  881. goto complete_reset;
  882. i40e_vsi_stop_rings(pf->vsi[vf->lan_vsi_idx]);
  883. complete_reset:
  884. /* free VF resources to begin resetting the VSI state */
  885. i40e_free_vf_res(vf);
  886. /* Enable hardware by clearing the reset bit in the VPGEN_VFRTRIG reg.
  887. * By doing this we allow HW to access VF memory at any point. If we
  888. * did it any sooner, HW could access memory while it was being freed
  889. * in i40e_free_vf_res(), causing an IOMMU fault.
  890. *
  891. * On the other hand, this needs to be done ASAP, because the VF driver
  892. * is waiting for this to happen and may report a timeout. It's
  893. * harmless, but it gets logged into Guest OS kernel log, so best avoid
  894. * it.
  895. */
  896. reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
  897. reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
  898. wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
  899. /* reallocate VF resources to finish resetting the VSI state */
  900. if (!i40e_alloc_vf_res(vf)) {
  901. int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
  902. i40e_enable_vf_mappings(vf);
  903. set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
  904. clear_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
  905. /* Do not notify the client during VF init */
  906. if (vf->pf->num_alloc_vfs)
  907. i40e_notify_client_of_vf_reset(pf, abs_vf_id);
  908. vf->num_vlan = 0;
  909. }
  910. /* Tell the VF driver the reset is done. This needs to be done only
  911. * after VF has been fully initialized, because the VF driver may
  912. * request resources immediately after setting this flag.
  913. */
  914. wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE);
  915. i40e_flush(hw);
  916. clear_bit(__I40E_VF_DISABLE, &pf->state);
  917. }
  918. /**
  919. * i40e_free_vfs
  920. * @pf: pointer to the PF structure
  921. *
  922. * free VF resources
  923. **/
  924. void i40e_free_vfs(struct i40e_pf *pf)
  925. {
  926. struct i40e_hw *hw = &pf->hw;
  927. u32 reg_idx, bit_idx;
  928. int i, tmp, vf_id;
  929. if (!pf->vf)
  930. return;
  931. while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
  932. usleep_range(1000, 2000);
  933. i40e_notify_client_of_vf_enable(pf, 0);
  934. for (i = 0; i < pf->num_alloc_vfs; i++)
  935. if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
  936. i40e_vsi_stop_rings(pf->vsi[pf->vf[i].lan_vsi_idx]);
  937. /* Disable IOV before freeing resources. This lets any VF drivers
  938. * running in the host get themselves cleaned up before we yank
  939. * the carpet out from underneath their feet.
  940. */
  941. if (!pci_vfs_assigned(pf->pdev))
  942. pci_disable_sriov(pf->pdev);
  943. else
  944. dev_warn(&pf->pdev->dev, "VFs are assigned - not disabling SR-IOV\n");
  945. msleep(20); /* let any messages in transit get finished up */
  946. /* free up VF resources */
  947. tmp = pf->num_alloc_vfs;
  948. pf->num_alloc_vfs = 0;
  949. for (i = 0; i < tmp; i++) {
  950. if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
  951. i40e_free_vf_res(&pf->vf[i]);
  952. /* disable qp mappings */
  953. i40e_disable_vf_mappings(&pf->vf[i]);
  954. }
  955. kfree(pf->vf);
  956. pf->vf = NULL;
  957. /* This check is for when the driver is unloaded while VFs are
  958. * assigned. Setting the number of VFs to 0 through sysfs is caught
  959. * before this function ever gets called.
  960. */
  961. if (!pci_vfs_assigned(pf->pdev)) {
  962. /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
  963. * work correctly when SR-IOV gets re-enabled.
  964. */
  965. for (vf_id = 0; vf_id < tmp; vf_id++) {
  966. reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
  967. bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
  968. wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
  969. }
  970. }
  971. clear_bit(__I40E_VF_DISABLE, &pf->state);
  972. }
  973. #ifdef CONFIG_PCI_IOV
  974. /**
  975. * i40e_alloc_vfs
  976. * @pf: pointer to the PF structure
  977. * @num_alloc_vfs: number of VFs to allocate
  978. *
  979. * allocate VF resources
  980. **/
  981. int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
  982. {
  983. struct i40e_vf *vfs;
  984. int i, ret = 0;
  985. /* Disable interrupt 0 so we don't try to handle the VFLR. */
  986. i40e_irq_dynamic_disable_icr0(pf);
  987. /* Check to see if we're just allocating resources for extant VFs */
  988. if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
  989. ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
  990. if (ret) {
  991. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  992. pf->num_alloc_vfs = 0;
  993. goto err_iov;
  994. }
  995. }
  996. /* allocate memory */
  997. vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
  998. if (!vfs) {
  999. ret = -ENOMEM;
  1000. goto err_alloc;
  1001. }
  1002. pf->vf = vfs;
  1003. /* apply default profile */
  1004. for (i = 0; i < num_alloc_vfs; i++) {
  1005. vfs[i].pf = pf;
  1006. vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
  1007. vfs[i].vf_id = i;
  1008. /* assign default capabilities */
  1009. set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
  1010. vfs[i].spoofchk = true;
  1011. /* VF resources get allocated during reset */
  1012. i40e_reset_vf(&vfs[i], false);
  1013. }
  1014. pf->num_alloc_vfs = num_alloc_vfs;
  1015. i40e_notify_client_of_vf_enable(pf, num_alloc_vfs);
  1016. err_alloc:
  1017. if (ret)
  1018. i40e_free_vfs(pf);
  1019. err_iov:
  1020. /* Re-enable interrupt 0. */
  1021. i40e_irq_dynamic_enable_icr0(pf, false);
  1022. return ret;
  1023. }
  1024. #endif
  1025. /**
  1026. * i40e_pci_sriov_enable
  1027. * @pdev: pointer to a pci_dev structure
  1028. * @num_vfs: number of VFs to allocate
  1029. *
  1030. * Enable or change the number of VFs
  1031. **/
  1032. static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
  1033. {
  1034. #ifdef CONFIG_PCI_IOV
  1035. struct i40e_pf *pf = pci_get_drvdata(pdev);
  1036. int pre_existing_vfs = pci_num_vf(pdev);
  1037. int err = 0;
  1038. if (test_bit(__I40E_TESTING, &pf->state)) {
  1039. dev_warn(&pdev->dev,
  1040. "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
  1041. err = -EPERM;
  1042. goto err_out;
  1043. }
  1044. if (pre_existing_vfs && pre_existing_vfs != num_vfs)
  1045. i40e_free_vfs(pf);
  1046. else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
  1047. goto out;
  1048. if (num_vfs > pf->num_req_vfs) {
  1049. dev_warn(&pdev->dev, "Unable to enable %d VFs. Limited to %d VFs due to device resource constraints.\n",
  1050. num_vfs, pf->num_req_vfs);
  1051. err = -EPERM;
  1052. goto err_out;
  1053. }
  1054. dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
  1055. err = i40e_alloc_vfs(pf, num_vfs);
  1056. if (err) {
  1057. dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
  1058. goto err_out;
  1059. }
  1060. out:
  1061. return num_vfs;
  1062. err_out:
  1063. return err;
  1064. #endif
  1065. return 0;
  1066. }
  1067. /**
  1068. * i40e_pci_sriov_configure
  1069. * @pdev: pointer to a pci_dev structure
  1070. * @num_vfs: number of VFs to allocate
  1071. *
  1072. * Enable or change the number of VFs. Called when the user updates the number
  1073. * of VFs in sysfs.
  1074. **/
  1075. int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
  1076. {
  1077. struct i40e_pf *pf = pci_get_drvdata(pdev);
  1078. if (num_vfs) {
  1079. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  1080. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  1081. i40e_do_reset_safe(pf,
  1082. BIT_ULL(__I40E_PF_RESET_REQUESTED));
  1083. }
  1084. return i40e_pci_sriov_enable(pdev, num_vfs);
  1085. }
  1086. if (!pci_vfs_assigned(pf->pdev)) {
  1087. i40e_free_vfs(pf);
  1088. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  1089. i40e_do_reset_safe(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  1090. } else {
  1091. dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
  1092. return -EINVAL;
  1093. }
  1094. return 0;
  1095. }
  1096. /***********************virtual channel routines******************/
  1097. /**
  1098. * i40e_vc_send_msg_to_vf
  1099. * @vf: pointer to the VF info
  1100. * @v_opcode: virtual channel opcode
  1101. * @v_retval: virtual channel return value
  1102. * @msg: pointer to the msg buffer
  1103. * @msglen: msg length
  1104. *
  1105. * send msg to VF
  1106. **/
  1107. static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
  1108. u32 v_retval, u8 *msg, u16 msglen)
  1109. {
  1110. struct i40e_pf *pf;
  1111. struct i40e_hw *hw;
  1112. int abs_vf_id;
  1113. i40e_status aq_ret;
  1114. /* validate the request */
  1115. if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
  1116. return -EINVAL;
  1117. pf = vf->pf;
  1118. hw = &pf->hw;
  1119. abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
  1120. /* single place to detect unsuccessful return values */
  1121. if (v_retval) {
  1122. vf->num_invalid_msgs++;
  1123. dev_info(&pf->pdev->dev, "VF %d failed opcode %d, retval: %d\n",
  1124. vf->vf_id, v_opcode, v_retval);
  1125. if (vf->num_invalid_msgs >
  1126. I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
  1127. dev_err(&pf->pdev->dev,
  1128. "Number of invalid messages exceeded for VF %d\n",
  1129. vf->vf_id);
  1130. dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
  1131. set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
  1132. }
  1133. } else {
  1134. vf->num_valid_msgs++;
  1135. /* reset the invalid counter, if a valid message is received. */
  1136. vf->num_invalid_msgs = 0;
  1137. }
  1138. aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
  1139. msg, msglen, NULL);
  1140. if (aq_ret) {
  1141. dev_info(&pf->pdev->dev,
  1142. "Unable to send the message to VF %d aq_err %d\n",
  1143. vf->vf_id, pf->hw.aq.asq_last_status);
  1144. return -EIO;
  1145. }
  1146. return 0;
  1147. }
  1148. /**
  1149. * i40e_vc_send_resp_to_vf
  1150. * @vf: pointer to the VF info
  1151. * @opcode: operation code
  1152. * @retval: return value
  1153. *
  1154. * send resp msg to VF
  1155. **/
  1156. static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
  1157. enum i40e_virtchnl_ops opcode,
  1158. i40e_status retval)
  1159. {
  1160. return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
  1161. }
  1162. /**
  1163. * i40e_vc_get_version_msg
  1164. * @vf: pointer to the VF info
  1165. *
  1166. * called from the VF to request the API version used by the PF
  1167. **/
  1168. static int i40e_vc_get_version_msg(struct i40e_vf *vf, u8 *msg)
  1169. {
  1170. struct i40e_virtchnl_version_info info = {
  1171. I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR
  1172. };
  1173. vf->vf_ver = *(struct i40e_virtchnl_version_info *)msg;
  1174. /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
  1175. if (VF_IS_V10(vf))
  1176. info.minor = I40E_VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
  1177. return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
  1178. I40E_SUCCESS, (u8 *)&info,
  1179. sizeof(struct
  1180. i40e_virtchnl_version_info));
  1181. }
  1182. /**
  1183. * i40e_vc_get_vf_resources_msg
  1184. * @vf: pointer to the VF info
  1185. * @msg: pointer to the msg buffer
  1186. * @msglen: msg length
  1187. *
  1188. * called from the VF to request its resources
  1189. **/
  1190. static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)
  1191. {
  1192. struct i40e_virtchnl_vf_resource *vfres = NULL;
  1193. struct i40e_pf *pf = vf->pf;
  1194. i40e_status aq_ret = 0;
  1195. struct i40e_vsi *vsi;
  1196. int num_vsis = 1;
  1197. int len = 0;
  1198. int ret;
  1199. if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
  1200. aq_ret = I40E_ERR_PARAM;
  1201. goto err;
  1202. }
  1203. len = (sizeof(struct i40e_virtchnl_vf_resource) +
  1204. sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis);
  1205. vfres = kzalloc(len, GFP_KERNEL);
  1206. if (!vfres) {
  1207. aq_ret = I40E_ERR_NO_MEMORY;
  1208. len = 0;
  1209. goto err;
  1210. }
  1211. if (VF_IS_V11(vf))
  1212. vf->driver_caps = *(u32 *)msg;
  1213. else
  1214. vf->driver_caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
  1215. I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG |
  1216. I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
  1217. vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2;
  1218. vsi = pf->vsi[vf->lan_vsi_idx];
  1219. if (!vsi->info.pvid)
  1220. vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
  1221. if (i40e_vf_client_capable(pf, vf->vf_id) &&
  1222. (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_IWARP)) {
  1223. vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_IWARP;
  1224. set_bit(I40E_VF_STAT_IWARPENA, &vf->vf_states);
  1225. }
  1226. if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_PF) {
  1227. vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RSS_PF;
  1228. } else {
  1229. if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) &&
  1230. (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ))
  1231. vfres->vf_offload_flags |=
  1232. I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ;
  1233. else
  1234. vfres->vf_offload_flags |=
  1235. I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG;
  1236. }
  1237. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) {
  1238. if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
  1239. vfres->vf_offload_flags |=
  1240. I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
  1241. }
  1242. if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING) {
  1243. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  1244. dev_err(&pf->pdev->dev,
  1245. "VF %d requested polling mode: this feature is supported only when the device is running in single function per port (SFP) mode\n",
  1246. vf->vf_id);
  1247. ret = I40E_ERR_PARAM;
  1248. goto err;
  1249. }
  1250. vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING;
  1251. }
  1252. if (pf->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) {
  1253. if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
  1254. vfres->vf_offload_flags |=
  1255. I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
  1256. }
  1257. vfres->num_vsis = num_vsis;
  1258. vfres->num_queue_pairs = vf->num_queue_pairs;
  1259. vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
  1260. vfres->rss_key_size = I40E_HKEY_ARRAY_SIZE;
  1261. vfres->rss_lut_size = I40E_VF_HLUT_ARRAY_SIZE;
  1262. if (vf->lan_vsi_idx) {
  1263. vfres->vsi_res[0].vsi_id = vf->lan_vsi_id;
  1264. vfres->vsi_res[0].vsi_type = I40E_VSI_SRIOV;
  1265. vfres->vsi_res[0].num_queue_pairs = vsi->alloc_queue_pairs;
  1266. /* VFs only use TC 0 */
  1267. vfres->vsi_res[0].qset_handle
  1268. = le16_to_cpu(vsi->info.qs_handle[0]);
  1269. ether_addr_copy(vfres->vsi_res[0].default_mac_addr,
  1270. vf->default_lan_addr.addr);
  1271. }
  1272. set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
  1273. err:
  1274. /* send the response back to the VF */
  1275. ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
  1276. aq_ret, (u8 *)vfres, len);
  1277. kfree(vfres);
  1278. return ret;
  1279. }
  1280. /**
  1281. * i40e_vc_reset_vf_msg
  1282. * @vf: pointer to the VF info
  1283. * @msg: pointer to the msg buffer
  1284. * @msglen: msg length
  1285. *
  1286. * called from the VF to reset itself,
  1287. * unlike other virtchnl messages, PF driver
  1288. * doesn't send the response back to the VF
  1289. **/
  1290. static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
  1291. {
  1292. if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
  1293. i40e_reset_vf(vf, false);
  1294. }
  1295. /**
  1296. * i40e_getnum_vf_vsi_vlan_filters
  1297. * @vsi: pointer to the vsi
  1298. *
  1299. * called to get the number of VLANs offloaded on this VF
  1300. **/
  1301. static inline int i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi *vsi)
  1302. {
  1303. struct i40e_mac_filter *f;
  1304. int num_vlans = 0, bkt;
  1305. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  1306. if (f->vlan >= 0 && f->vlan <= I40E_MAX_VLANID)
  1307. num_vlans++;
  1308. }
  1309. return num_vlans;
  1310. }
  1311. /**
  1312. * i40e_vc_config_promiscuous_mode_msg
  1313. * @vf: pointer to the VF info
  1314. * @msg: pointer to the msg buffer
  1315. * @msglen: msg length
  1316. *
  1317. * called from the VF to configure the promiscuous mode of
  1318. * VF vsis
  1319. **/
  1320. static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
  1321. u8 *msg, u16 msglen)
  1322. {
  1323. struct i40e_virtchnl_promisc_info *info =
  1324. (struct i40e_virtchnl_promisc_info *)msg;
  1325. struct i40e_pf *pf = vf->pf;
  1326. struct i40e_hw *hw = &pf->hw;
  1327. struct i40e_mac_filter *f;
  1328. i40e_status aq_ret = 0;
  1329. bool allmulti = false;
  1330. struct i40e_vsi *vsi;
  1331. bool alluni = false;
  1332. int aq_err = 0;
  1333. int bkt;
  1334. vsi = i40e_find_vsi_from_id(pf, info->vsi_id);
  1335. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  1336. !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
  1337. !vsi) {
  1338. aq_ret = I40E_ERR_PARAM;
  1339. goto error_param;
  1340. }
  1341. if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
  1342. dev_err(&pf->pdev->dev,
  1343. "Unprivileged VF %d is attempting to configure promiscuous mode\n",
  1344. vf->vf_id);
  1345. /* Lie to the VF on purpose. */
  1346. aq_ret = 0;
  1347. goto error_param;
  1348. }
  1349. /* Multicast promiscuous handling*/
  1350. if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
  1351. allmulti = true;
  1352. if (vf->port_vlan_id) {
  1353. aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw, vsi->seid,
  1354. allmulti,
  1355. vf->port_vlan_id,
  1356. NULL);
  1357. } else if (i40e_getnum_vf_vsi_vlan_filters(vsi)) {
  1358. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  1359. if (f->vlan < 0 || f->vlan > I40E_MAX_VLANID)
  1360. continue;
  1361. aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw,
  1362. vsi->seid,
  1363. allmulti,
  1364. f->vlan,
  1365. NULL);
  1366. aq_err = pf->hw.aq.asq_last_status;
  1367. if (aq_ret) {
  1368. dev_err(&pf->pdev->dev,
  1369. "Could not add VLAN %d to multicast promiscuous domain err %s aq_err %s\n",
  1370. f->vlan,
  1371. i40e_stat_str(&pf->hw, aq_ret),
  1372. i40e_aq_str(&pf->hw, aq_err));
  1373. break;
  1374. }
  1375. }
  1376. } else {
  1377. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
  1378. allmulti, NULL);
  1379. aq_err = pf->hw.aq.asq_last_status;
  1380. if (aq_ret) {
  1381. dev_err(&pf->pdev->dev,
  1382. "VF %d failed to set multicast promiscuous mode err %s aq_err %s\n",
  1383. vf->vf_id,
  1384. i40e_stat_str(&pf->hw, aq_ret),
  1385. i40e_aq_str(&pf->hw, aq_err));
  1386. goto error_param;
  1387. }
  1388. }
  1389. if (!aq_ret) {
  1390. dev_info(&pf->pdev->dev,
  1391. "VF %d successfully set multicast promiscuous mode\n",
  1392. vf->vf_id);
  1393. if (allmulti)
  1394. set_bit(I40E_VF_STAT_MC_PROMISC, &vf->vf_states);
  1395. else
  1396. clear_bit(I40E_VF_STAT_MC_PROMISC, &vf->vf_states);
  1397. }
  1398. if (info->flags & I40E_FLAG_VF_UNICAST_PROMISC)
  1399. alluni = true;
  1400. if (vf->port_vlan_id) {
  1401. aq_ret = i40e_aq_set_vsi_uc_promisc_on_vlan(hw, vsi->seid,
  1402. alluni,
  1403. vf->port_vlan_id,
  1404. NULL);
  1405. } else if (i40e_getnum_vf_vsi_vlan_filters(vsi)) {
  1406. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  1407. aq_ret = 0;
  1408. if (f->vlan >= 0 && f->vlan <= I40E_MAX_VLANID) {
  1409. aq_ret =
  1410. i40e_aq_set_vsi_uc_promisc_on_vlan(hw,
  1411. vsi->seid,
  1412. alluni,
  1413. f->vlan,
  1414. NULL);
  1415. aq_err = pf->hw.aq.asq_last_status;
  1416. }
  1417. if (aq_ret)
  1418. dev_err(&pf->pdev->dev,
  1419. "Could not add VLAN %d to Unicast promiscuous domain err %s aq_err %s\n",
  1420. f->vlan,
  1421. i40e_stat_str(&pf->hw, aq_ret),
  1422. i40e_aq_str(&pf->hw, aq_err));
  1423. }
  1424. } else {
  1425. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
  1426. allmulti, NULL,
  1427. true);
  1428. aq_err = pf->hw.aq.asq_last_status;
  1429. if (aq_ret) {
  1430. dev_err(&pf->pdev->dev,
  1431. "VF %d failed to set unicast promiscuous mode %8.8x err %s aq_err %s\n",
  1432. vf->vf_id, info->flags,
  1433. i40e_stat_str(&pf->hw, aq_ret),
  1434. i40e_aq_str(&pf->hw, aq_err));
  1435. goto error_param;
  1436. }
  1437. }
  1438. if (!aq_ret) {
  1439. dev_info(&pf->pdev->dev,
  1440. "VF %d successfully set unicast promiscuous mode\n",
  1441. vf->vf_id);
  1442. if (alluni)
  1443. set_bit(I40E_VF_STAT_UC_PROMISC, &vf->vf_states);
  1444. else
  1445. clear_bit(I40E_VF_STAT_UC_PROMISC, &vf->vf_states);
  1446. }
  1447. error_param:
  1448. /* send the response to the VF */
  1449. return i40e_vc_send_resp_to_vf(vf,
  1450. I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
  1451. aq_ret);
  1452. }
  1453. /**
  1454. * i40e_vc_config_queues_msg
  1455. * @vf: pointer to the VF info
  1456. * @msg: pointer to the msg buffer
  1457. * @msglen: msg length
  1458. *
  1459. * called from the VF to configure the rx/tx
  1460. * queues
  1461. **/
  1462. static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1463. {
  1464. struct i40e_virtchnl_vsi_queue_config_info *qci =
  1465. (struct i40e_virtchnl_vsi_queue_config_info *)msg;
  1466. struct i40e_virtchnl_queue_pair_info *qpi;
  1467. struct i40e_pf *pf = vf->pf;
  1468. u16 vsi_id, vsi_queue_id;
  1469. i40e_status aq_ret = 0;
  1470. int i;
  1471. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
  1472. aq_ret = I40E_ERR_PARAM;
  1473. goto error_param;
  1474. }
  1475. vsi_id = qci->vsi_id;
  1476. if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1477. aq_ret = I40E_ERR_PARAM;
  1478. goto error_param;
  1479. }
  1480. for (i = 0; i < qci->num_queue_pairs; i++) {
  1481. qpi = &qci->qpair[i];
  1482. vsi_queue_id = qpi->txq.queue_id;
  1483. if ((qpi->txq.vsi_id != vsi_id) ||
  1484. (qpi->rxq.vsi_id != vsi_id) ||
  1485. (qpi->rxq.queue_id != vsi_queue_id) ||
  1486. !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
  1487. aq_ret = I40E_ERR_PARAM;
  1488. goto error_param;
  1489. }
  1490. if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
  1491. &qpi->rxq) ||
  1492. i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
  1493. &qpi->txq)) {
  1494. aq_ret = I40E_ERR_PARAM;
  1495. goto error_param;
  1496. }
  1497. }
  1498. /* set vsi num_queue_pairs in use to num configured by VF */
  1499. pf->vsi[vf->lan_vsi_idx]->num_queue_pairs = qci->num_queue_pairs;
  1500. error_param:
  1501. /* send the response to the VF */
  1502. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
  1503. aq_ret);
  1504. }
  1505. /**
  1506. * i40e_vc_config_irq_map_msg
  1507. * @vf: pointer to the VF info
  1508. * @msg: pointer to the msg buffer
  1509. * @msglen: msg length
  1510. *
  1511. * called from the VF to configure the irq to
  1512. * queue map
  1513. **/
  1514. static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1515. {
  1516. struct i40e_virtchnl_irq_map_info *irqmap_info =
  1517. (struct i40e_virtchnl_irq_map_info *)msg;
  1518. struct i40e_virtchnl_vector_map *map;
  1519. u16 vsi_id, vsi_queue_id, vector_id;
  1520. i40e_status aq_ret = 0;
  1521. unsigned long tempmap;
  1522. int i;
  1523. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
  1524. aq_ret = I40E_ERR_PARAM;
  1525. goto error_param;
  1526. }
  1527. for (i = 0; i < irqmap_info->num_vectors; i++) {
  1528. map = &irqmap_info->vecmap[i];
  1529. vector_id = map->vector_id;
  1530. vsi_id = map->vsi_id;
  1531. /* validate msg params */
  1532. if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
  1533. !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1534. aq_ret = I40E_ERR_PARAM;
  1535. goto error_param;
  1536. }
  1537. /* lookout for the invalid queue index */
  1538. tempmap = map->rxq_map;
  1539. for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
  1540. if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
  1541. vsi_queue_id)) {
  1542. aq_ret = I40E_ERR_PARAM;
  1543. goto error_param;
  1544. }
  1545. }
  1546. tempmap = map->txq_map;
  1547. for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
  1548. if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
  1549. vsi_queue_id)) {
  1550. aq_ret = I40E_ERR_PARAM;
  1551. goto error_param;
  1552. }
  1553. }
  1554. i40e_config_irq_link_list(vf, vsi_id, map);
  1555. }
  1556. error_param:
  1557. /* send the response to the VF */
  1558. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
  1559. aq_ret);
  1560. }
  1561. /**
  1562. * i40e_vc_enable_queues_msg
  1563. * @vf: pointer to the VF info
  1564. * @msg: pointer to the msg buffer
  1565. * @msglen: msg length
  1566. *
  1567. * called from the VF to enable all or specific queue(s)
  1568. **/
  1569. static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1570. {
  1571. struct i40e_virtchnl_queue_select *vqs =
  1572. (struct i40e_virtchnl_queue_select *)msg;
  1573. struct i40e_pf *pf = vf->pf;
  1574. u16 vsi_id = vqs->vsi_id;
  1575. i40e_status aq_ret = 0;
  1576. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
  1577. aq_ret = I40E_ERR_PARAM;
  1578. goto error_param;
  1579. }
  1580. if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1581. aq_ret = I40E_ERR_PARAM;
  1582. goto error_param;
  1583. }
  1584. if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
  1585. aq_ret = I40E_ERR_PARAM;
  1586. goto error_param;
  1587. }
  1588. if (i40e_vsi_start_rings(pf->vsi[vf->lan_vsi_idx]))
  1589. aq_ret = I40E_ERR_TIMEOUT;
  1590. error_param:
  1591. /* send the response to the VF */
  1592. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
  1593. aq_ret);
  1594. }
  1595. /**
  1596. * i40e_vc_disable_queues_msg
  1597. * @vf: pointer to the VF info
  1598. * @msg: pointer to the msg buffer
  1599. * @msglen: msg length
  1600. *
  1601. * called from the VF to disable all or specific
  1602. * queue(s)
  1603. **/
  1604. static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1605. {
  1606. struct i40e_virtchnl_queue_select *vqs =
  1607. (struct i40e_virtchnl_queue_select *)msg;
  1608. struct i40e_pf *pf = vf->pf;
  1609. i40e_status aq_ret = 0;
  1610. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
  1611. aq_ret = I40E_ERR_PARAM;
  1612. goto error_param;
  1613. }
  1614. if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
  1615. aq_ret = I40E_ERR_PARAM;
  1616. goto error_param;
  1617. }
  1618. if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
  1619. aq_ret = I40E_ERR_PARAM;
  1620. goto error_param;
  1621. }
  1622. i40e_vsi_stop_rings(pf->vsi[vf->lan_vsi_idx]);
  1623. error_param:
  1624. /* send the response to the VF */
  1625. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
  1626. aq_ret);
  1627. }
  1628. /**
  1629. * i40e_vc_get_stats_msg
  1630. * @vf: pointer to the VF info
  1631. * @msg: pointer to the msg buffer
  1632. * @msglen: msg length
  1633. *
  1634. * called from the VF to get vsi stats
  1635. **/
  1636. static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1637. {
  1638. struct i40e_virtchnl_queue_select *vqs =
  1639. (struct i40e_virtchnl_queue_select *)msg;
  1640. struct i40e_pf *pf = vf->pf;
  1641. struct i40e_eth_stats stats;
  1642. i40e_status aq_ret = 0;
  1643. struct i40e_vsi *vsi;
  1644. memset(&stats, 0, sizeof(struct i40e_eth_stats));
  1645. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
  1646. aq_ret = I40E_ERR_PARAM;
  1647. goto error_param;
  1648. }
  1649. if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
  1650. aq_ret = I40E_ERR_PARAM;
  1651. goto error_param;
  1652. }
  1653. vsi = pf->vsi[vf->lan_vsi_idx];
  1654. if (!vsi) {
  1655. aq_ret = I40E_ERR_PARAM;
  1656. goto error_param;
  1657. }
  1658. i40e_update_eth_stats(vsi);
  1659. stats = vsi->eth_stats;
  1660. error_param:
  1661. /* send the response back to the VF */
  1662. return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret,
  1663. (u8 *)&stats, sizeof(stats));
  1664. }
  1665. /* If the VF is not trusted restrict the number of MAC/VLAN it can program */
  1666. #define I40E_VC_MAX_MAC_ADDR_PER_VF 12
  1667. #define I40E_VC_MAX_VLAN_PER_VF 8
  1668. /**
  1669. * i40e_check_vf_permission
  1670. * @vf: pointer to the VF info
  1671. * @macaddr: pointer to the MAC Address being checked
  1672. *
  1673. * Check if the VF has permission to add or delete unicast MAC address
  1674. * filters and return error code -EPERM if not. Then check if the
  1675. * address filter requested is broadcast or zero and if so return
  1676. * an invalid MAC address error code.
  1677. **/
  1678. static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr)
  1679. {
  1680. struct i40e_pf *pf = vf->pf;
  1681. int ret = 0;
  1682. if (is_broadcast_ether_addr(macaddr) ||
  1683. is_zero_ether_addr(macaddr)) {
  1684. dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr);
  1685. ret = I40E_ERR_INVALID_MAC_ADDR;
  1686. } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) &&
  1687. !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) &&
  1688. !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) {
  1689. /* If the host VMM administrator has set the VF MAC address
  1690. * administratively via the ndo_set_vf_mac command then deny
  1691. * permission to the VF to add or delete unicast MAC addresses.
  1692. * Unless the VF is privileged and then it can do whatever.
  1693. * The VF may request to set the MAC address filter already
  1694. * assigned to it so do not return an error in that case.
  1695. */
  1696. dev_err(&pf->pdev->dev,
  1697. "VF attempting to override administratively set MAC address, reload the VF driver to resume normal operation\n");
  1698. ret = -EPERM;
  1699. } else if ((vf->num_mac >= I40E_VC_MAX_MAC_ADDR_PER_VF) &&
  1700. !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
  1701. dev_err(&pf->pdev->dev,
  1702. "VF is not trusted, switch the VF to trusted to add more functionality\n");
  1703. ret = -EPERM;
  1704. }
  1705. return ret;
  1706. }
  1707. /**
  1708. * i40e_vc_add_mac_addr_msg
  1709. * @vf: pointer to the VF info
  1710. * @msg: pointer to the msg buffer
  1711. * @msglen: msg length
  1712. *
  1713. * add guest mac address filter
  1714. **/
  1715. static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1716. {
  1717. struct i40e_virtchnl_ether_addr_list *al =
  1718. (struct i40e_virtchnl_ether_addr_list *)msg;
  1719. struct i40e_pf *pf = vf->pf;
  1720. struct i40e_vsi *vsi = NULL;
  1721. u16 vsi_id = al->vsi_id;
  1722. i40e_status ret = 0;
  1723. int i;
  1724. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  1725. !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1726. ret = I40E_ERR_PARAM;
  1727. goto error_param;
  1728. }
  1729. for (i = 0; i < al->num_elements; i++) {
  1730. ret = i40e_check_vf_permission(vf, al->list[i].addr);
  1731. if (ret)
  1732. goto error_param;
  1733. }
  1734. vsi = pf->vsi[vf->lan_vsi_idx];
  1735. /* Lock once, because all function inside for loop accesses VSI's
  1736. * MAC filter list which needs to be protected using same lock.
  1737. */
  1738. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1739. /* add new addresses to the list */
  1740. for (i = 0; i < al->num_elements; i++) {
  1741. struct i40e_mac_filter *f;
  1742. f = i40e_find_mac(vsi, al->list[i].addr);
  1743. if (!f)
  1744. f = i40e_add_mac_filter(vsi, al->list[i].addr);
  1745. if (!f) {
  1746. dev_err(&pf->pdev->dev,
  1747. "Unable to add MAC filter %pM for VF %d\n",
  1748. al->list[i].addr, vf->vf_id);
  1749. ret = I40E_ERR_PARAM;
  1750. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1751. goto error_param;
  1752. } else {
  1753. vf->num_mac++;
  1754. }
  1755. }
  1756. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1757. /* program the updated filter list */
  1758. ret = i40e_sync_vsi_filters(vsi);
  1759. if (ret)
  1760. dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
  1761. vf->vf_id, ret);
  1762. error_param:
  1763. /* send the response to the VF */
  1764. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
  1765. ret);
  1766. }
  1767. /**
  1768. * i40e_vc_del_mac_addr_msg
  1769. * @vf: pointer to the VF info
  1770. * @msg: pointer to the msg buffer
  1771. * @msglen: msg length
  1772. *
  1773. * remove guest mac address filter
  1774. **/
  1775. static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1776. {
  1777. struct i40e_virtchnl_ether_addr_list *al =
  1778. (struct i40e_virtchnl_ether_addr_list *)msg;
  1779. struct i40e_pf *pf = vf->pf;
  1780. struct i40e_vsi *vsi = NULL;
  1781. u16 vsi_id = al->vsi_id;
  1782. i40e_status ret = 0;
  1783. int i;
  1784. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  1785. !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1786. ret = I40E_ERR_PARAM;
  1787. goto error_param;
  1788. }
  1789. for (i = 0; i < al->num_elements; i++) {
  1790. if (is_broadcast_ether_addr(al->list[i].addr) ||
  1791. is_zero_ether_addr(al->list[i].addr)) {
  1792. dev_err(&pf->pdev->dev, "Invalid MAC addr %pM for VF %d\n",
  1793. al->list[i].addr, vf->vf_id);
  1794. ret = I40E_ERR_INVALID_MAC_ADDR;
  1795. goto error_param;
  1796. }
  1797. }
  1798. vsi = pf->vsi[vf->lan_vsi_idx];
  1799. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1800. /* delete addresses from the list */
  1801. for (i = 0; i < al->num_elements; i++)
  1802. if (i40e_del_mac_filter(vsi, al->list[i].addr)) {
  1803. ret = I40E_ERR_INVALID_MAC_ADDR;
  1804. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1805. goto error_param;
  1806. } else {
  1807. vf->num_mac--;
  1808. }
  1809. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1810. /* program the updated filter list */
  1811. ret = i40e_sync_vsi_filters(vsi);
  1812. if (ret)
  1813. dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
  1814. vf->vf_id, ret);
  1815. error_param:
  1816. /* send the response to the VF */
  1817. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
  1818. ret);
  1819. }
  1820. /**
  1821. * i40e_vc_add_vlan_msg
  1822. * @vf: pointer to the VF info
  1823. * @msg: pointer to the msg buffer
  1824. * @msglen: msg length
  1825. *
  1826. * program guest vlan id
  1827. **/
  1828. static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1829. {
  1830. struct i40e_virtchnl_vlan_filter_list *vfl =
  1831. (struct i40e_virtchnl_vlan_filter_list *)msg;
  1832. struct i40e_pf *pf = vf->pf;
  1833. struct i40e_vsi *vsi = NULL;
  1834. u16 vsi_id = vfl->vsi_id;
  1835. i40e_status aq_ret = 0;
  1836. int i;
  1837. if ((vf->num_vlan >= I40E_VC_MAX_VLAN_PER_VF) &&
  1838. !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
  1839. dev_err(&pf->pdev->dev,
  1840. "VF is not trusted, switch the VF to trusted to add more VLAN addresses\n");
  1841. goto error_param;
  1842. }
  1843. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  1844. !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1845. aq_ret = I40E_ERR_PARAM;
  1846. goto error_param;
  1847. }
  1848. for (i = 0; i < vfl->num_elements; i++) {
  1849. if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
  1850. aq_ret = I40E_ERR_PARAM;
  1851. dev_err(&pf->pdev->dev,
  1852. "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
  1853. goto error_param;
  1854. }
  1855. }
  1856. vsi = pf->vsi[vf->lan_vsi_idx];
  1857. if (vsi->info.pvid) {
  1858. aq_ret = I40E_ERR_PARAM;
  1859. goto error_param;
  1860. }
  1861. i40e_vlan_stripping_enable(vsi);
  1862. for (i = 0; i < vfl->num_elements; i++) {
  1863. /* add new VLAN filter */
  1864. int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
  1865. if (!ret)
  1866. vf->num_vlan++;
  1867. if (test_bit(I40E_VF_STAT_UC_PROMISC, &vf->vf_states))
  1868. i40e_aq_set_vsi_uc_promisc_on_vlan(&pf->hw, vsi->seid,
  1869. true,
  1870. vfl->vlan_id[i],
  1871. NULL);
  1872. if (test_bit(I40E_VF_STAT_MC_PROMISC, &vf->vf_states))
  1873. i40e_aq_set_vsi_mc_promisc_on_vlan(&pf->hw, vsi->seid,
  1874. true,
  1875. vfl->vlan_id[i],
  1876. NULL);
  1877. if (ret)
  1878. dev_err(&pf->pdev->dev,
  1879. "Unable to add VLAN filter %d for VF %d, error %d\n",
  1880. vfl->vlan_id[i], vf->vf_id, ret);
  1881. }
  1882. error_param:
  1883. /* send the response to the VF */
  1884. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret);
  1885. }
  1886. /**
  1887. * i40e_vc_remove_vlan_msg
  1888. * @vf: pointer to the VF info
  1889. * @msg: pointer to the msg buffer
  1890. * @msglen: msg length
  1891. *
  1892. * remove programmed guest vlan id
  1893. **/
  1894. static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1895. {
  1896. struct i40e_virtchnl_vlan_filter_list *vfl =
  1897. (struct i40e_virtchnl_vlan_filter_list *)msg;
  1898. struct i40e_pf *pf = vf->pf;
  1899. struct i40e_vsi *vsi = NULL;
  1900. u16 vsi_id = vfl->vsi_id;
  1901. i40e_status aq_ret = 0;
  1902. int i;
  1903. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  1904. !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1905. aq_ret = I40E_ERR_PARAM;
  1906. goto error_param;
  1907. }
  1908. for (i = 0; i < vfl->num_elements; i++) {
  1909. if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
  1910. aq_ret = I40E_ERR_PARAM;
  1911. goto error_param;
  1912. }
  1913. }
  1914. vsi = pf->vsi[vf->lan_vsi_idx];
  1915. if (vsi->info.pvid) {
  1916. aq_ret = I40E_ERR_PARAM;
  1917. goto error_param;
  1918. }
  1919. for (i = 0; i < vfl->num_elements; i++) {
  1920. i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
  1921. vf->num_vlan--;
  1922. if (test_bit(I40E_VF_STAT_UC_PROMISC, &vf->vf_states))
  1923. i40e_aq_set_vsi_uc_promisc_on_vlan(&pf->hw, vsi->seid,
  1924. false,
  1925. vfl->vlan_id[i],
  1926. NULL);
  1927. if (test_bit(I40E_VF_STAT_MC_PROMISC, &vf->vf_states))
  1928. i40e_aq_set_vsi_mc_promisc_on_vlan(&pf->hw, vsi->seid,
  1929. false,
  1930. vfl->vlan_id[i],
  1931. NULL);
  1932. }
  1933. error_param:
  1934. /* send the response to the VF */
  1935. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret);
  1936. }
  1937. /**
  1938. * i40e_vc_iwarp_msg
  1939. * @vf: pointer to the VF info
  1940. * @msg: pointer to the msg buffer
  1941. * @msglen: msg length
  1942. *
  1943. * called from the VF for the iwarp msgs
  1944. **/
  1945. static int i40e_vc_iwarp_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1946. {
  1947. struct i40e_pf *pf = vf->pf;
  1948. int abs_vf_id = vf->vf_id + pf->hw.func_caps.vf_base_id;
  1949. i40e_status aq_ret = 0;
  1950. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  1951. !test_bit(I40E_VF_STAT_IWARPENA, &vf->vf_states)) {
  1952. aq_ret = I40E_ERR_PARAM;
  1953. goto error_param;
  1954. }
  1955. i40e_notify_client_of_vf_msg(pf->vsi[pf->lan_vsi], abs_vf_id,
  1956. msg, msglen);
  1957. error_param:
  1958. /* send the response to the VF */
  1959. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_IWARP,
  1960. aq_ret);
  1961. }
  1962. /**
  1963. * i40e_vc_iwarp_qvmap_msg
  1964. * @vf: pointer to the VF info
  1965. * @msg: pointer to the msg buffer
  1966. * @msglen: msg length
  1967. * @config: config qvmap or release it
  1968. *
  1969. * called from the VF for the iwarp msgs
  1970. **/
  1971. static int i40e_vc_iwarp_qvmap_msg(struct i40e_vf *vf, u8 *msg, u16 msglen,
  1972. bool config)
  1973. {
  1974. struct i40e_virtchnl_iwarp_qvlist_info *qvlist_info =
  1975. (struct i40e_virtchnl_iwarp_qvlist_info *)msg;
  1976. i40e_status aq_ret = 0;
  1977. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  1978. !test_bit(I40E_VF_STAT_IWARPENA, &vf->vf_states)) {
  1979. aq_ret = I40E_ERR_PARAM;
  1980. goto error_param;
  1981. }
  1982. if (config) {
  1983. if (i40e_config_iwarp_qvlist(vf, qvlist_info))
  1984. aq_ret = I40E_ERR_PARAM;
  1985. } else {
  1986. i40e_release_iwarp_qvlist(vf);
  1987. }
  1988. error_param:
  1989. /* send the response to the VF */
  1990. return i40e_vc_send_resp_to_vf(vf,
  1991. config ? I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP :
  1992. I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP,
  1993. aq_ret);
  1994. }
  1995. /**
  1996. * i40e_vc_config_rss_key
  1997. * @vf: pointer to the VF info
  1998. * @msg: pointer to the msg buffer
  1999. * @msglen: msg length
  2000. *
  2001. * Configure the VF's RSS key
  2002. **/
  2003. static int i40e_vc_config_rss_key(struct i40e_vf *vf, u8 *msg, u16 msglen)
  2004. {
  2005. struct i40e_virtchnl_rss_key *vrk =
  2006. (struct i40e_virtchnl_rss_key *)msg;
  2007. struct i40e_pf *pf = vf->pf;
  2008. struct i40e_vsi *vsi = NULL;
  2009. u16 vsi_id = vrk->vsi_id;
  2010. i40e_status aq_ret = 0;
  2011. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  2012. !i40e_vc_isvalid_vsi_id(vf, vsi_id) ||
  2013. (vrk->key_len != I40E_HKEY_ARRAY_SIZE)) {
  2014. aq_ret = I40E_ERR_PARAM;
  2015. goto err;
  2016. }
  2017. vsi = pf->vsi[vf->lan_vsi_idx];
  2018. aq_ret = i40e_config_rss(vsi, vrk->key, NULL, 0);
  2019. err:
  2020. /* send the response to the VF */
  2021. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_RSS_KEY,
  2022. aq_ret);
  2023. }
  2024. /**
  2025. * i40e_vc_config_rss_lut
  2026. * @vf: pointer to the VF info
  2027. * @msg: pointer to the msg buffer
  2028. * @msglen: msg length
  2029. *
  2030. * Configure the VF's RSS LUT
  2031. **/
  2032. static int i40e_vc_config_rss_lut(struct i40e_vf *vf, u8 *msg, u16 msglen)
  2033. {
  2034. struct i40e_virtchnl_rss_lut *vrl =
  2035. (struct i40e_virtchnl_rss_lut *)msg;
  2036. struct i40e_pf *pf = vf->pf;
  2037. struct i40e_vsi *vsi = NULL;
  2038. u16 vsi_id = vrl->vsi_id;
  2039. i40e_status aq_ret = 0;
  2040. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  2041. !i40e_vc_isvalid_vsi_id(vf, vsi_id) ||
  2042. (vrl->lut_entries != I40E_VF_HLUT_ARRAY_SIZE)) {
  2043. aq_ret = I40E_ERR_PARAM;
  2044. goto err;
  2045. }
  2046. vsi = pf->vsi[vf->lan_vsi_idx];
  2047. aq_ret = i40e_config_rss(vsi, NULL, vrl->lut, I40E_VF_HLUT_ARRAY_SIZE);
  2048. /* send the response to the VF */
  2049. err:
  2050. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_RSS_LUT,
  2051. aq_ret);
  2052. }
  2053. /**
  2054. * i40e_vc_get_rss_hena
  2055. * @vf: pointer to the VF info
  2056. * @msg: pointer to the msg buffer
  2057. * @msglen: msg length
  2058. *
  2059. * Return the RSS HENA bits allowed by the hardware
  2060. **/
  2061. static int i40e_vc_get_rss_hena(struct i40e_vf *vf, u8 *msg, u16 msglen)
  2062. {
  2063. struct i40e_virtchnl_rss_hena *vrh = NULL;
  2064. struct i40e_pf *pf = vf->pf;
  2065. i40e_status aq_ret = 0;
  2066. int len = 0;
  2067. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
  2068. aq_ret = I40E_ERR_PARAM;
  2069. goto err;
  2070. }
  2071. len = sizeof(struct i40e_virtchnl_rss_hena);
  2072. vrh = kzalloc(len, GFP_KERNEL);
  2073. if (!vrh) {
  2074. aq_ret = I40E_ERR_NO_MEMORY;
  2075. len = 0;
  2076. goto err;
  2077. }
  2078. vrh->hena = i40e_pf_get_default_rss_hena(pf);
  2079. err:
  2080. /* send the response back to the VF */
  2081. aq_ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS,
  2082. aq_ret, (u8 *)vrh, len);
  2083. kfree(vrh);
  2084. return aq_ret;
  2085. }
  2086. /**
  2087. * i40e_vc_set_rss_hena
  2088. * @vf: pointer to the VF info
  2089. * @msg: pointer to the msg buffer
  2090. * @msglen: msg length
  2091. *
  2092. * Set the RSS HENA bits for the VF
  2093. **/
  2094. static int i40e_vc_set_rss_hena(struct i40e_vf *vf, u8 *msg, u16 msglen)
  2095. {
  2096. struct i40e_virtchnl_rss_hena *vrh =
  2097. (struct i40e_virtchnl_rss_hena *)msg;
  2098. struct i40e_pf *pf = vf->pf;
  2099. struct i40e_hw *hw = &pf->hw;
  2100. i40e_status aq_ret = 0;
  2101. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
  2102. aq_ret = I40E_ERR_PARAM;
  2103. goto err;
  2104. }
  2105. i40e_write_rx_ctl(hw, I40E_VFQF_HENA1(0, vf->vf_id), (u32)vrh->hena);
  2106. i40e_write_rx_ctl(hw, I40E_VFQF_HENA1(1, vf->vf_id),
  2107. (u32)(vrh->hena >> 32));
  2108. /* send the response to the VF */
  2109. err:
  2110. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_SET_RSS_HENA,
  2111. aq_ret);
  2112. }
  2113. /**
  2114. * i40e_vc_validate_vf_msg
  2115. * @vf: pointer to the VF info
  2116. * @msg: pointer to the msg buffer
  2117. * @msglen: msg length
  2118. * @msghndl: msg handle
  2119. *
  2120. * validate msg
  2121. **/
  2122. static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
  2123. u32 v_retval, u8 *msg, u16 msglen)
  2124. {
  2125. bool err_msg_format = false;
  2126. int valid_len = 0;
  2127. /* Check if VF is disabled. */
  2128. if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states))
  2129. return I40E_ERR_PARAM;
  2130. /* Validate message length. */
  2131. switch (v_opcode) {
  2132. case I40E_VIRTCHNL_OP_VERSION:
  2133. valid_len = sizeof(struct i40e_virtchnl_version_info);
  2134. break;
  2135. case I40E_VIRTCHNL_OP_RESET_VF:
  2136. break;
  2137. case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
  2138. if (VF_IS_V11(vf))
  2139. valid_len = sizeof(u32);
  2140. break;
  2141. case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE:
  2142. valid_len = sizeof(struct i40e_virtchnl_txq_info);
  2143. break;
  2144. case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE:
  2145. valid_len = sizeof(struct i40e_virtchnl_rxq_info);
  2146. break;
  2147. case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
  2148. valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info);
  2149. if (msglen >= valid_len) {
  2150. struct i40e_virtchnl_vsi_queue_config_info *vqc =
  2151. (struct i40e_virtchnl_vsi_queue_config_info *)msg;
  2152. valid_len += (vqc->num_queue_pairs *
  2153. sizeof(struct
  2154. i40e_virtchnl_queue_pair_info));
  2155. if (vqc->num_queue_pairs == 0)
  2156. err_msg_format = true;
  2157. }
  2158. break;
  2159. case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
  2160. valid_len = sizeof(struct i40e_virtchnl_irq_map_info);
  2161. if (msglen >= valid_len) {
  2162. struct i40e_virtchnl_irq_map_info *vimi =
  2163. (struct i40e_virtchnl_irq_map_info *)msg;
  2164. valid_len += (vimi->num_vectors *
  2165. sizeof(struct i40e_virtchnl_vector_map));
  2166. if (vimi->num_vectors == 0)
  2167. err_msg_format = true;
  2168. }
  2169. break;
  2170. case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
  2171. case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
  2172. valid_len = sizeof(struct i40e_virtchnl_queue_select);
  2173. break;
  2174. case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
  2175. case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
  2176. valid_len = sizeof(struct i40e_virtchnl_ether_addr_list);
  2177. if (msglen >= valid_len) {
  2178. struct i40e_virtchnl_ether_addr_list *veal =
  2179. (struct i40e_virtchnl_ether_addr_list *)msg;
  2180. valid_len += veal->num_elements *
  2181. sizeof(struct i40e_virtchnl_ether_addr);
  2182. if (veal->num_elements == 0)
  2183. err_msg_format = true;
  2184. }
  2185. break;
  2186. case I40E_VIRTCHNL_OP_ADD_VLAN:
  2187. case I40E_VIRTCHNL_OP_DEL_VLAN:
  2188. valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list);
  2189. if (msglen >= valid_len) {
  2190. struct i40e_virtchnl_vlan_filter_list *vfl =
  2191. (struct i40e_virtchnl_vlan_filter_list *)msg;
  2192. valid_len += vfl->num_elements * sizeof(u16);
  2193. if (vfl->num_elements == 0)
  2194. err_msg_format = true;
  2195. }
  2196. break;
  2197. case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
  2198. valid_len = sizeof(struct i40e_virtchnl_promisc_info);
  2199. break;
  2200. case I40E_VIRTCHNL_OP_GET_STATS:
  2201. valid_len = sizeof(struct i40e_virtchnl_queue_select);
  2202. break;
  2203. case I40E_VIRTCHNL_OP_IWARP:
  2204. /* These messages are opaque to us and will be validated in
  2205. * the RDMA client code. We just need to check for nonzero
  2206. * length. The firmware will enforce max length restrictions.
  2207. */
  2208. if (msglen)
  2209. valid_len = msglen;
  2210. else
  2211. err_msg_format = true;
  2212. break;
  2213. case I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
  2214. valid_len = 0;
  2215. break;
  2216. case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
  2217. valid_len = sizeof(struct i40e_virtchnl_iwarp_qvlist_info);
  2218. if (msglen >= valid_len) {
  2219. struct i40e_virtchnl_iwarp_qvlist_info *qv =
  2220. (struct i40e_virtchnl_iwarp_qvlist_info *)msg;
  2221. if (qv->num_vectors == 0) {
  2222. err_msg_format = true;
  2223. break;
  2224. }
  2225. valid_len += ((qv->num_vectors - 1) *
  2226. sizeof(struct i40e_virtchnl_iwarp_qv_info));
  2227. }
  2228. break;
  2229. case I40E_VIRTCHNL_OP_CONFIG_RSS_KEY:
  2230. valid_len = sizeof(struct i40e_virtchnl_rss_key);
  2231. if (msglen >= valid_len) {
  2232. struct i40e_virtchnl_rss_key *vrk =
  2233. (struct i40e_virtchnl_rss_key *)msg;
  2234. if (vrk->key_len != I40E_HKEY_ARRAY_SIZE) {
  2235. err_msg_format = true;
  2236. break;
  2237. }
  2238. valid_len += vrk->key_len - 1;
  2239. }
  2240. break;
  2241. case I40E_VIRTCHNL_OP_CONFIG_RSS_LUT:
  2242. valid_len = sizeof(struct i40e_virtchnl_rss_lut);
  2243. if (msglen >= valid_len) {
  2244. struct i40e_virtchnl_rss_lut *vrl =
  2245. (struct i40e_virtchnl_rss_lut *)msg;
  2246. if (vrl->lut_entries != I40E_VF_HLUT_ARRAY_SIZE) {
  2247. err_msg_format = true;
  2248. break;
  2249. }
  2250. valid_len += vrl->lut_entries - 1;
  2251. }
  2252. break;
  2253. case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS:
  2254. break;
  2255. case I40E_VIRTCHNL_OP_SET_RSS_HENA:
  2256. valid_len = sizeof(struct i40e_virtchnl_rss_hena);
  2257. break;
  2258. /* These are always errors coming from the VF. */
  2259. case I40E_VIRTCHNL_OP_EVENT:
  2260. case I40E_VIRTCHNL_OP_UNKNOWN:
  2261. default:
  2262. return -EPERM;
  2263. }
  2264. /* few more checks */
  2265. if ((valid_len != msglen) || (err_msg_format)) {
  2266. i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
  2267. return -EINVAL;
  2268. } else {
  2269. return 0;
  2270. }
  2271. }
  2272. /**
  2273. * i40e_vc_process_vf_msg
  2274. * @pf: pointer to the PF structure
  2275. * @vf_id: source VF id
  2276. * @msg: pointer to the msg buffer
  2277. * @msglen: msg length
  2278. * @msghndl: msg handle
  2279. *
  2280. * called from the common aeq/arq handler to
  2281. * process request from VF
  2282. **/
  2283. int i40e_vc_process_vf_msg(struct i40e_pf *pf, s16 vf_id, u32 v_opcode,
  2284. u32 v_retval, u8 *msg, u16 msglen)
  2285. {
  2286. struct i40e_hw *hw = &pf->hw;
  2287. int local_vf_id = vf_id - (s16)hw->func_caps.vf_base_id;
  2288. struct i40e_vf *vf;
  2289. int ret;
  2290. pf->vf_aq_requests++;
  2291. if (local_vf_id >= pf->num_alloc_vfs)
  2292. return -EINVAL;
  2293. vf = &(pf->vf[local_vf_id]);
  2294. /* perform basic checks on the msg */
  2295. ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen);
  2296. if (ret) {
  2297. dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n",
  2298. local_vf_id, v_opcode, msglen);
  2299. return ret;
  2300. }
  2301. switch (v_opcode) {
  2302. case I40E_VIRTCHNL_OP_VERSION:
  2303. ret = i40e_vc_get_version_msg(vf, msg);
  2304. break;
  2305. case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
  2306. ret = i40e_vc_get_vf_resources_msg(vf, msg);
  2307. break;
  2308. case I40E_VIRTCHNL_OP_RESET_VF:
  2309. i40e_vc_reset_vf_msg(vf);
  2310. ret = 0;
  2311. break;
  2312. case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
  2313. ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
  2314. break;
  2315. case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
  2316. ret = i40e_vc_config_queues_msg(vf, msg, msglen);
  2317. break;
  2318. case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
  2319. ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
  2320. break;
  2321. case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
  2322. ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
  2323. i40e_vc_notify_vf_link_state(vf);
  2324. break;
  2325. case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
  2326. ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
  2327. break;
  2328. case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
  2329. ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
  2330. break;
  2331. case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
  2332. ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
  2333. break;
  2334. case I40E_VIRTCHNL_OP_ADD_VLAN:
  2335. ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
  2336. break;
  2337. case I40E_VIRTCHNL_OP_DEL_VLAN:
  2338. ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
  2339. break;
  2340. case I40E_VIRTCHNL_OP_GET_STATS:
  2341. ret = i40e_vc_get_stats_msg(vf, msg, msglen);
  2342. break;
  2343. case I40E_VIRTCHNL_OP_IWARP:
  2344. ret = i40e_vc_iwarp_msg(vf, msg, msglen);
  2345. break;
  2346. case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
  2347. ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, true);
  2348. break;
  2349. case I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
  2350. ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, false);
  2351. break;
  2352. case I40E_VIRTCHNL_OP_CONFIG_RSS_KEY:
  2353. ret = i40e_vc_config_rss_key(vf, msg, msglen);
  2354. break;
  2355. case I40E_VIRTCHNL_OP_CONFIG_RSS_LUT:
  2356. ret = i40e_vc_config_rss_lut(vf, msg, msglen);
  2357. break;
  2358. case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS:
  2359. ret = i40e_vc_get_rss_hena(vf, msg, msglen);
  2360. break;
  2361. case I40E_VIRTCHNL_OP_SET_RSS_HENA:
  2362. ret = i40e_vc_set_rss_hena(vf, msg, msglen);
  2363. break;
  2364. case I40E_VIRTCHNL_OP_UNKNOWN:
  2365. default:
  2366. dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n",
  2367. v_opcode, local_vf_id);
  2368. ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
  2369. I40E_ERR_NOT_IMPLEMENTED);
  2370. break;
  2371. }
  2372. return ret;
  2373. }
  2374. /**
  2375. * i40e_vc_process_vflr_event
  2376. * @pf: pointer to the PF structure
  2377. *
  2378. * called from the vlfr irq handler to
  2379. * free up VF resources and state variables
  2380. **/
  2381. int i40e_vc_process_vflr_event(struct i40e_pf *pf)
  2382. {
  2383. struct i40e_hw *hw = &pf->hw;
  2384. u32 reg, reg_idx, bit_idx;
  2385. struct i40e_vf *vf;
  2386. int vf_id;
  2387. if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
  2388. return 0;
  2389. /* Re-enable the VFLR interrupt cause here, before looking for which
  2390. * VF got reset. Otherwise, if another VF gets a reset while the
  2391. * first one is being processed, that interrupt will be lost, and
  2392. * that VF will be stuck in reset forever.
  2393. */
  2394. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  2395. reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
  2396. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  2397. i40e_flush(hw);
  2398. clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
  2399. for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
  2400. reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
  2401. bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
  2402. /* read GLGEN_VFLRSTAT register to find out the flr VFs */
  2403. vf = &pf->vf[vf_id];
  2404. reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
  2405. if (reg & BIT(bit_idx))
  2406. /* i40e_reset_vf will clear the bit in GLGEN_VFLRSTAT */
  2407. i40e_reset_vf(vf, true);
  2408. }
  2409. return 0;
  2410. }
  2411. /**
  2412. * i40e_ndo_set_vf_mac
  2413. * @netdev: network interface device structure
  2414. * @vf_id: VF identifier
  2415. * @mac: mac address
  2416. *
  2417. * program VF mac address
  2418. **/
  2419. int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
  2420. {
  2421. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2422. struct i40e_vsi *vsi = np->vsi;
  2423. struct i40e_pf *pf = vsi->back;
  2424. struct i40e_mac_filter *f;
  2425. struct i40e_vf *vf;
  2426. int ret = 0;
  2427. int bkt;
  2428. /* validate the request */
  2429. if (vf_id >= pf->num_alloc_vfs) {
  2430. dev_err(&pf->pdev->dev,
  2431. "Invalid VF Identifier %d\n", vf_id);
  2432. ret = -EINVAL;
  2433. goto error_param;
  2434. }
  2435. vf = &(pf->vf[vf_id]);
  2436. vsi = pf->vsi[vf->lan_vsi_idx];
  2437. if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
  2438. dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
  2439. vf_id);
  2440. ret = -EAGAIN;
  2441. goto error_param;
  2442. }
  2443. if (is_multicast_ether_addr(mac)) {
  2444. dev_err(&pf->pdev->dev,
  2445. "Invalid Ethernet address %pM for VF %d\n", mac, vf_id);
  2446. ret = -EINVAL;
  2447. goto error_param;
  2448. }
  2449. /* Lock once because below invoked function add/del_filter requires
  2450. * mac_filter_hash_lock to be held
  2451. */
  2452. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2453. /* delete the temporary mac address */
  2454. if (!is_zero_ether_addr(vf->default_lan_addr.addr))
  2455. i40e_del_mac_filter(vsi, vf->default_lan_addr.addr);
  2456. /* Delete all the filters for this VSI - we're going to kill it
  2457. * anyway.
  2458. */
  2459. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist)
  2460. __i40e_del_filter(vsi, f);
  2461. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2462. dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id);
  2463. /* program mac filter */
  2464. if (i40e_sync_vsi_filters(vsi)) {
  2465. dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
  2466. ret = -EIO;
  2467. goto error_param;
  2468. }
  2469. ether_addr_copy(vf->default_lan_addr.addr, mac);
  2470. vf->pf_set_mac = true;
  2471. /* Force the VF driver stop so it has to reload with new MAC address */
  2472. i40e_vc_disable_vf(pf, vf);
  2473. dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
  2474. error_param:
  2475. return ret;
  2476. }
  2477. /**
  2478. * i40e_ndo_set_vf_port_vlan
  2479. * @netdev: network interface device structure
  2480. * @vf_id: VF identifier
  2481. * @vlan_id: mac address
  2482. * @qos: priority setting
  2483. * @vlan_proto: vlan protocol
  2484. *
  2485. * program VF vlan id and/or qos
  2486. **/
  2487. int i40e_ndo_set_vf_port_vlan(struct net_device *netdev, int vf_id,
  2488. u16 vlan_id, u8 qos, __be16 vlan_proto)
  2489. {
  2490. u16 vlanprio = vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT);
  2491. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2492. struct i40e_pf *pf = np->vsi->back;
  2493. struct i40e_vsi *vsi;
  2494. struct i40e_vf *vf;
  2495. int ret = 0;
  2496. /* validate the request */
  2497. if (vf_id >= pf->num_alloc_vfs) {
  2498. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
  2499. ret = -EINVAL;
  2500. goto error_pvid;
  2501. }
  2502. if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
  2503. dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
  2504. ret = -EINVAL;
  2505. goto error_pvid;
  2506. }
  2507. if (vlan_proto != htons(ETH_P_8021Q)) {
  2508. dev_err(&pf->pdev->dev, "VF VLAN protocol is not supported\n");
  2509. ret = -EPROTONOSUPPORT;
  2510. goto error_pvid;
  2511. }
  2512. vf = &(pf->vf[vf_id]);
  2513. vsi = pf->vsi[vf->lan_vsi_idx];
  2514. if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
  2515. dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
  2516. vf_id);
  2517. ret = -EAGAIN;
  2518. goto error_pvid;
  2519. }
  2520. if (le16_to_cpu(vsi->info.pvid) == vlanprio)
  2521. /* duplicate request, so just return success */
  2522. goto error_pvid;
  2523. /* Locked once because multiple functions below iterate list */
  2524. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2525. if (le16_to_cpu(vsi->info.pvid) == 0 && i40e_is_vsi_in_vlan(vsi)) {
  2526. dev_err(&pf->pdev->dev,
  2527. "VF %d has already configured VLAN filters and the administrator is requesting a port VLAN override.\nPlease unload and reload the VF driver for this change to take effect.\n",
  2528. vf_id);
  2529. /* Administrator Error - knock the VF offline until he does
  2530. * the right thing by reconfiguring his network correctly
  2531. * and then reloading the VF driver.
  2532. */
  2533. i40e_vc_disable_vf(pf, vf);
  2534. /* During reset the VF got a new VSI, so refresh the pointer. */
  2535. vsi = pf->vsi[vf->lan_vsi_idx];
  2536. }
  2537. /* Check for condition where there was already a port VLAN ID
  2538. * filter set and now it is being deleted by setting it to zero.
  2539. * Additionally check for the condition where there was a port
  2540. * VLAN but now there is a new and different port VLAN being set.
  2541. * Before deleting all the old VLAN filters we must add new ones
  2542. * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
  2543. * MAC addresses deleted.
  2544. */
  2545. if ((!(vlan_id || qos) ||
  2546. vlanprio != le16_to_cpu(vsi->info.pvid)) &&
  2547. vsi->info.pvid) {
  2548. ret = i40e_add_vlan_all_mac(vsi, I40E_VLAN_ANY);
  2549. if (ret) {
  2550. dev_info(&vsi->back->pdev->dev,
  2551. "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
  2552. vsi->back->hw.aq.asq_last_status);
  2553. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2554. goto error_pvid;
  2555. }
  2556. }
  2557. if (vsi->info.pvid) {
  2558. /* remove all filters on the old VLAN */
  2559. i40e_rm_vlan_all_mac(vsi, (le16_to_cpu(vsi->info.pvid) &
  2560. VLAN_VID_MASK));
  2561. }
  2562. if (vlan_id || qos)
  2563. ret = i40e_vsi_add_pvid(vsi, vlanprio);
  2564. else
  2565. i40e_vsi_remove_pvid(vsi);
  2566. if (vlan_id) {
  2567. dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
  2568. vlan_id, qos, vf_id);
  2569. /* add new VLAN filter for each MAC */
  2570. ret = i40e_add_vlan_all_mac(vsi, vlan_id);
  2571. if (ret) {
  2572. dev_info(&vsi->back->pdev->dev,
  2573. "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
  2574. vsi->back->hw.aq.asq_last_status);
  2575. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2576. goto error_pvid;
  2577. }
  2578. /* remove the previously added non-VLAN MAC filters */
  2579. i40e_rm_vlan_all_mac(vsi, I40E_VLAN_ANY);
  2580. }
  2581. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2582. /* Schedule the worker thread to take care of applying changes */
  2583. i40e_service_event_schedule(vsi->back);
  2584. if (ret) {
  2585. dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
  2586. goto error_pvid;
  2587. }
  2588. /* The Port VLAN needs to be saved across resets the same as the
  2589. * default LAN MAC address.
  2590. */
  2591. vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
  2592. ret = 0;
  2593. error_pvid:
  2594. return ret;
  2595. }
  2596. #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
  2597. #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
  2598. /**
  2599. * i40e_ndo_set_vf_bw
  2600. * @netdev: network interface device structure
  2601. * @vf_id: VF identifier
  2602. * @tx_rate: Tx rate
  2603. *
  2604. * configure VF Tx rate
  2605. **/
  2606. int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
  2607. int max_tx_rate)
  2608. {
  2609. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2610. struct i40e_pf *pf = np->vsi->back;
  2611. struct i40e_vsi *vsi;
  2612. struct i40e_vf *vf;
  2613. int speed = 0;
  2614. int ret = 0;
  2615. /* validate the request */
  2616. if (vf_id >= pf->num_alloc_vfs) {
  2617. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
  2618. ret = -EINVAL;
  2619. goto error;
  2620. }
  2621. if (min_tx_rate) {
  2622. dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
  2623. min_tx_rate, vf_id);
  2624. return -EINVAL;
  2625. }
  2626. vf = &(pf->vf[vf_id]);
  2627. vsi = pf->vsi[vf->lan_vsi_idx];
  2628. if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
  2629. dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
  2630. vf_id);
  2631. ret = -EAGAIN;
  2632. goto error;
  2633. }
  2634. switch (pf->hw.phy.link_info.link_speed) {
  2635. case I40E_LINK_SPEED_40GB:
  2636. speed = 40000;
  2637. break;
  2638. case I40E_LINK_SPEED_25GB:
  2639. speed = 25000;
  2640. break;
  2641. case I40E_LINK_SPEED_20GB:
  2642. speed = 20000;
  2643. break;
  2644. case I40E_LINK_SPEED_10GB:
  2645. speed = 10000;
  2646. break;
  2647. case I40E_LINK_SPEED_1GB:
  2648. speed = 1000;
  2649. break;
  2650. default:
  2651. break;
  2652. }
  2653. if (max_tx_rate > speed) {
  2654. dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for VF %d.\n",
  2655. max_tx_rate, vf->vf_id);
  2656. ret = -EINVAL;
  2657. goto error;
  2658. }
  2659. if ((max_tx_rate < 50) && (max_tx_rate > 0)) {
  2660. dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
  2661. max_tx_rate = 50;
  2662. }
  2663. /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
  2664. ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
  2665. max_tx_rate / I40E_BW_CREDIT_DIVISOR,
  2666. I40E_MAX_BW_INACTIVE_ACCUM, NULL);
  2667. if (ret) {
  2668. dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n",
  2669. ret);
  2670. ret = -EIO;
  2671. goto error;
  2672. }
  2673. vf->tx_rate = max_tx_rate;
  2674. error:
  2675. return ret;
  2676. }
  2677. /**
  2678. * i40e_ndo_get_vf_config
  2679. * @netdev: network interface device structure
  2680. * @vf_id: VF identifier
  2681. * @ivi: VF configuration structure
  2682. *
  2683. * return VF configuration
  2684. **/
  2685. int i40e_ndo_get_vf_config(struct net_device *netdev,
  2686. int vf_id, struct ifla_vf_info *ivi)
  2687. {
  2688. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2689. struct i40e_vsi *vsi = np->vsi;
  2690. struct i40e_pf *pf = vsi->back;
  2691. struct i40e_vf *vf;
  2692. int ret = 0;
  2693. /* validate the request */
  2694. if (vf_id >= pf->num_alloc_vfs) {
  2695. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
  2696. ret = -EINVAL;
  2697. goto error_param;
  2698. }
  2699. vf = &(pf->vf[vf_id]);
  2700. /* first vsi is always the LAN vsi */
  2701. vsi = pf->vsi[vf->lan_vsi_idx];
  2702. if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
  2703. dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
  2704. vf_id);
  2705. ret = -EAGAIN;
  2706. goto error_param;
  2707. }
  2708. ivi->vf = vf_id;
  2709. ether_addr_copy(ivi->mac, vf->default_lan_addr.addr);
  2710. ivi->max_tx_rate = vf->tx_rate;
  2711. ivi->min_tx_rate = 0;
  2712. ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
  2713. ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
  2714. I40E_VLAN_PRIORITY_SHIFT;
  2715. if (vf->link_forced == false)
  2716. ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
  2717. else if (vf->link_up == true)
  2718. ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
  2719. else
  2720. ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
  2721. ivi->spoofchk = vf->spoofchk;
  2722. ivi->trusted = vf->trusted;
  2723. ret = 0;
  2724. error_param:
  2725. return ret;
  2726. }
  2727. /**
  2728. * i40e_ndo_set_vf_link_state
  2729. * @netdev: network interface device structure
  2730. * @vf_id: VF identifier
  2731. * @link: required link state
  2732. *
  2733. * Set the link state of a specified VF, regardless of physical link state
  2734. **/
  2735. int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
  2736. {
  2737. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2738. struct i40e_pf *pf = np->vsi->back;
  2739. struct i40e_virtchnl_pf_event pfe;
  2740. struct i40e_hw *hw = &pf->hw;
  2741. struct i40e_vf *vf;
  2742. int abs_vf_id;
  2743. int ret = 0;
  2744. /* validate the request */
  2745. if (vf_id >= pf->num_alloc_vfs) {
  2746. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
  2747. ret = -EINVAL;
  2748. goto error_out;
  2749. }
  2750. vf = &pf->vf[vf_id];
  2751. abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
  2752. pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
  2753. pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
  2754. switch (link) {
  2755. case IFLA_VF_LINK_STATE_AUTO:
  2756. vf->link_forced = false;
  2757. pfe.event_data.link_event.link_status =
  2758. pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
  2759. pfe.event_data.link_event.link_speed =
  2760. pf->hw.phy.link_info.link_speed;
  2761. break;
  2762. case IFLA_VF_LINK_STATE_ENABLE:
  2763. vf->link_forced = true;
  2764. vf->link_up = true;
  2765. pfe.event_data.link_event.link_status = true;
  2766. pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
  2767. break;
  2768. case IFLA_VF_LINK_STATE_DISABLE:
  2769. vf->link_forced = true;
  2770. vf->link_up = false;
  2771. pfe.event_data.link_event.link_status = false;
  2772. pfe.event_data.link_event.link_speed = 0;
  2773. break;
  2774. default:
  2775. ret = -EINVAL;
  2776. goto error_out;
  2777. }
  2778. /* Notify the VF of its new link state */
  2779. i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
  2780. 0, (u8 *)&pfe, sizeof(pfe), NULL);
  2781. error_out:
  2782. return ret;
  2783. }
  2784. /**
  2785. * i40e_ndo_set_vf_spoofchk
  2786. * @netdev: network interface device structure
  2787. * @vf_id: VF identifier
  2788. * @enable: flag to enable or disable feature
  2789. *
  2790. * Enable or disable VF spoof checking
  2791. **/
  2792. int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
  2793. {
  2794. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2795. struct i40e_vsi *vsi = np->vsi;
  2796. struct i40e_pf *pf = vsi->back;
  2797. struct i40e_vsi_context ctxt;
  2798. struct i40e_hw *hw = &pf->hw;
  2799. struct i40e_vf *vf;
  2800. int ret = 0;
  2801. /* validate the request */
  2802. if (vf_id >= pf->num_alloc_vfs) {
  2803. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
  2804. ret = -EINVAL;
  2805. goto out;
  2806. }
  2807. vf = &(pf->vf[vf_id]);
  2808. if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
  2809. dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
  2810. vf_id);
  2811. ret = -EAGAIN;
  2812. goto out;
  2813. }
  2814. if (enable == vf->spoofchk)
  2815. goto out;
  2816. vf->spoofchk = enable;
  2817. memset(&ctxt, 0, sizeof(ctxt));
  2818. ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid;
  2819. ctxt.pf_num = pf->hw.pf_id;
  2820. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
  2821. if (enable)
  2822. ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
  2823. I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
  2824. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  2825. if (ret) {
  2826. dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",
  2827. ret);
  2828. ret = -EIO;
  2829. }
  2830. out:
  2831. return ret;
  2832. }
  2833. /**
  2834. * i40e_ndo_set_vf_trust
  2835. * @netdev: network interface device structure of the pf
  2836. * @vf_id: VF identifier
  2837. * @setting: trust setting
  2838. *
  2839. * Enable or disable VF trust setting
  2840. **/
  2841. int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting)
  2842. {
  2843. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2844. struct i40e_pf *pf = np->vsi->back;
  2845. struct i40e_vf *vf;
  2846. int ret = 0;
  2847. /* validate the request */
  2848. if (vf_id >= pf->num_alloc_vfs) {
  2849. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
  2850. return -EINVAL;
  2851. }
  2852. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  2853. dev_err(&pf->pdev->dev, "Trusted VF not supported in MFP mode.\n");
  2854. return -EINVAL;
  2855. }
  2856. vf = &pf->vf[vf_id];
  2857. if (!vf)
  2858. return -EINVAL;
  2859. if (setting == vf->trusted)
  2860. goto out;
  2861. vf->trusted = setting;
  2862. i40e_vc_notify_vf_reset(vf);
  2863. i40e_reset_vf(vf, false);
  2864. dev_info(&pf->pdev->dev, "VF %u is now %strusted\n",
  2865. vf_id, setting ? "" : "un");
  2866. out:
  2867. return ret;
  2868. }