i40e_virtchnl_pf.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766
  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 + 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 + 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 + 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. pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
  448. vsi = i40e_find_vsi_from_id(pf, vsi_id);
  449. /* clear the context structure first */
  450. memset(&tx_ctx, 0, sizeof(struct i40e_hmc_obj_txq));
  451. /* only set the required fields */
  452. tx_ctx.base = info->dma_ring_addr / 128;
  453. tx_ctx.qlen = info->ring_len;
  454. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]);
  455. tx_ctx.rdylist_act = 0;
  456. tx_ctx.head_wb_ena = info->headwb_enabled;
  457. tx_ctx.head_wb_addr = info->dma_headwb_addr;
  458. /* clear the context in the HMC */
  459. ret = i40e_clear_lan_tx_queue_context(hw, pf_queue_id);
  460. if (ret) {
  461. dev_err(&pf->pdev->dev,
  462. "Failed to clear VF LAN Tx queue context %d, error: %d\n",
  463. pf_queue_id, ret);
  464. ret = -ENOENT;
  465. goto error_context;
  466. }
  467. /* set the context in the HMC */
  468. ret = i40e_set_lan_tx_queue_context(hw, pf_queue_id, &tx_ctx);
  469. if (ret) {
  470. dev_err(&pf->pdev->dev,
  471. "Failed to set VF LAN Tx queue context %d error: %d\n",
  472. pf_queue_id, ret);
  473. ret = -ENOENT;
  474. goto error_context;
  475. }
  476. /* associate this queue with the PCI VF function */
  477. qtx_ctl = I40E_QTX_CTL_VF_QUEUE;
  478. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT)
  479. & I40E_QTX_CTL_PF_INDX_MASK);
  480. qtx_ctl |= (((vf->vf_id + hw->func_caps.vf_base_id)
  481. << I40E_QTX_CTL_VFVM_INDX_SHIFT)
  482. & I40E_QTX_CTL_VFVM_INDX_MASK);
  483. wr32(hw, I40E_QTX_CTL(pf_queue_id), qtx_ctl);
  484. i40e_flush(hw);
  485. error_context:
  486. return ret;
  487. }
  488. /**
  489. * i40e_config_vsi_rx_queue
  490. * @vf: pointer to the VF info
  491. * @vsi_id: id of VSI as provided by the FW
  492. * @vsi_queue_id: vsi relative queue index
  493. * @info: config. info
  494. *
  495. * configure rx queue
  496. **/
  497. static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id,
  498. u16 vsi_queue_id,
  499. struct i40e_virtchnl_rxq_info *info)
  500. {
  501. struct i40e_pf *pf = vf->pf;
  502. struct i40e_hw *hw = &pf->hw;
  503. struct i40e_hmc_obj_rxq rx_ctx;
  504. u16 pf_queue_id;
  505. int ret = 0;
  506. pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
  507. /* clear the context structure first */
  508. memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
  509. /* only set the required fields */
  510. rx_ctx.base = info->dma_ring_addr / 128;
  511. rx_ctx.qlen = info->ring_len;
  512. if (info->splithdr_enabled) {
  513. rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
  514. I40E_RX_SPLIT_IP |
  515. I40E_RX_SPLIT_TCP_UDP |
  516. I40E_RX_SPLIT_SCTP;
  517. /* header length validation */
  518. if (info->hdr_size > ((2 * 1024) - 64)) {
  519. ret = -EINVAL;
  520. goto error_param;
  521. }
  522. rx_ctx.hbuff = info->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT;
  523. /* set splitalways mode 10b */
  524. rx_ctx.dtype = I40E_RX_DTYPE_HEADER_SPLIT;
  525. }
  526. /* databuffer length validation */
  527. if (info->databuffer_size > ((16 * 1024) - 128)) {
  528. ret = -EINVAL;
  529. goto error_param;
  530. }
  531. rx_ctx.dbuff = info->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT;
  532. /* max pkt. length validation */
  533. if (info->max_pkt_size >= (16 * 1024) || info->max_pkt_size < 64) {
  534. ret = -EINVAL;
  535. goto error_param;
  536. }
  537. rx_ctx.rxmax = info->max_pkt_size;
  538. /* enable 32bytes desc always */
  539. rx_ctx.dsize = 1;
  540. /* default values */
  541. rx_ctx.lrxqthresh = 2;
  542. rx_ctx.crcstrip = 1;
  543. rx_ctx.prefena = 1;
  544. rx_ctx.l2tsel = 1;
  545. /* clear the context in the HMC */
  546. ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id);
  547. if (ret) {
  548. dev_err(&pf->pdev->dev,
  549. "Failed to clear VF LAN Rx queue context %d, error: %d\n",
  550. pf_queue_id, ret);
  551. ret = -ENOENT;
  552. goto error_param;
  553. }
  554. /* set the context in the HMC */
  555. ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx);
  556. if (ret) {
  557. dev_err(&pf->pdev->dev,
  558. "Failed to set VF LAN Rx queue context %d error: %d\n",
  559. pf_queue_id, ret);
  560. ret = -ENOENT;
  561. goto error_param;
  562. }
  563. error_param:
  564. return ret;
  565. }
  566. /**
  567. * i40e_alloc_vsi_res
  568. * @vf: pointer to the VF info
  569. * @type: type of VSI to allocate
  570. *
  571. * alloc VF vsi context & resources
  572. **/
  573. static int i40e_alloc_vsi_res(struct i40e_vf *vf, enum i40e_vsi_type type)
  574. {
  575. struct i40e_mac_filter *f = NULL;
  576. struct i40e_pf *pf = vf->pf;
  577. struct i40e_vsi *vsi;
  578. int ret = 0;
  579. vsi = i40e_vsi_setup(pf, type, pf->vsi[pf->lan_vsi]->seid, vf->vf_id);
  580. if (!vsi) {
  581. dev_err(&pf->pdev->dev,
  582. "add vsi failed for VF %d, aq_err %d\n",
  583. vf->vf_id, pf->hw.aq.asq_last_status);
  584. ret = -ENOENT;
  585. goto error_alloc_vsi_res;
  586. }
  587. if (type == I40E_VSI_SRIOV) {
  588. u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  589. vf->lan_vsi_idx = vsi->idx;
  590. vf->lan_vsi_id = vsi->id;
  591. /* If the port VLAN has been configured and then the
  592. * VF driver was removed then the VSI port VLAN
  593. * configuration was destroyed. Check if there is
  594. * a port VLAN and restore the VSI configuration if
  595. * needed.
  596. */
  597. if (vf->port_vlan_id)
  598. i40e_vsi_add_pvid(vsi, vf->port_vlan_id);
  599. spin_lock_bh(&vsi->mac_filter_list_lock);
  600. if (is_valid_ether_addr(vf->default_lan_addr.addr)) {
  601. f = i40e_add_filter(vsi, vf->default_lan_addr.addr,
  602. vf->port_vlan_id ? vf->port_vlan_id : -1,
  603. true, false);
  604. if (!f)
  605. dev_info(&pf->pdev->dev,
  606. "Could not add MAC filter %pM for VF %d\n",
  607. vf->default_lan_addr.addr, vf->vf_id);
  608. }
  609. f = i40e_add_filter(vsi, brdcast,
  610. vf->port_vlan_id ? vf->port_vlan_id : -1,
  611. true, false);
  612. if (!f)
  613. dev_info(&pf->pdev->dev,
  614. "Could not allocate VF broadcast filter\n");
  615. spin_unlock_bh(&vsi->mac_filter_list_lock);
  616. }
  617. /* program mac filter */
  618. ret = i40e_sync_vsi_filters(vsi);
  619. if (ret)
  620. dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
  621. /* Set VF bandwidth if specified */
  622. if (vf->tx_rate) {
  623. ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
  624. vf->tx_rate / 50, 0, NULL);
  625. if (ret)
  626. dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
  627. vf->vf_id, ret);
  628. }
  629. error_alloc_vsi_res:
  630. return ret;
  631. }
  632. /**
  633. * i40e_enable_vf_mappings
  634. * @vf: pointer to the VF info
  635. *
  636. * enable VF mappings
  637. **/
  638. static void i40e_enable_vf_mappings(struct i40e_vf *vf)
  639. {
  640. struct i40e_pf *pf = vf->pf;
  641. struct i40e_hw *hw = &pf->hw;
  642. u32 reg, total_queue_pairs = 0;
  643. int j;
  644. /* Tell the hardware we're using noncontiguous mapping. HW requires
  645. * that VF queues be mapped using this method, even when they are
  646. * contiguous in real life
  647. */
  648. i40e_write_rx_ctl(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id),
  649. I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
  650. /* enable VF vplan_qtable mappings */
  651. reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK;
  652. wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg);
  653. /* map PF queues to VF queues */
  654. for (j = 0; j < pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs; j++) {
  655. u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id, j);
  656. reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK);
  657. wr32(hw, I40E_VPLAN_QTABLE(total_queue_pairs, vf->vf_id), reg);
  658. total_queue_pairs++;
  659. }
  660. /* map PF queues to VSI */
  661. for (j = 0; j < 7; j++) {
  662. if (j * 2 >= pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs) {
  663. reg = 0x07FF07FF; /* unused */
  664. } else {
  665. u16 qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
  666. j * 2);
  667. reg = qid;
  668. qid = i40e_vc_get_pf_queue_id(vf, vf->lan_vsi_id,
  669. (j * 2) + 1);
  670. reg |= qid << 16;
  671. }
  672. i40e_write_rx_ctl(hw, I40E_VSILAN_QTABLE(j, vf->lan_vsi_id),
  673. reg);
  674. }
  675. i40e_flush(hw);
  676. }
  677. /**
  678. * i40e_disable_vf_mappings
  679. * @vf: pointer to the VF info
  680. *
  681. * disable VF mappings
  682. **/
  683. static void i40e_disable_vf_mappings(struct i40e_vf *vf)
  684. {
  685. struct i40e_pf *pf = vf->pf;
  686. struct i40e_hw *hw = &pf->hw;
  687. int i;
  688. /* disable qp mappings */
  689. wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0);
  690. for (i = 0; i < I40E_MAX_VSI_QP; i++)
  691. wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id),
  692. I40E_QUEUE_END_OF_LIST);
  693. i40e_flush(hw);
  694. }
  695. /**
  696. * i40e_free_vf_res
  697. * @vf: pointer to the VF info
  698. *
  699. * free VF resources
  700. **/
  701. static void i40e_free_vf_res(struct i40e_vf *vf)
  702. {
  703. struct i40e_pf *pf = vf->pf;
  704. struct i40e_hw *hw = &pf->hw;
  705. u32 reg_idx, reg;
  706. int i, msix_vf;
  707. /* free vsi & disconnect it from the parent uplink */
  708. if (vf->lan_vsi_idx) {
  709. i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]);
  710. vf->lan_vsi_idx = 0;
  711. vf->lan_vsi_id = 0;
  712. }
  713. msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
  714. /* disable interrupts so the VF starts in a known state */
  715. for (i = 0; i < msix_vf; i++) {
  716. /* format is same for both registers */
  717. if (0 == i)
  718. reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id);
  719. else
  720. reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
  721. (vf->vf_id))
  722. + (i - 1));
  723. wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
  724. i40e_flush(hw);
  725. }
  726. /* clear the irq settings */
  727. for (i = 0; i < msix_vf; i++) {
  728. /* format is same for both registers */
  729. if (0 == i)
  730. reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
  731. else
  732. reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
  733. (vf->vf_id))
  734. + (i - 1));
  735. reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
  736. I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
  737. wr32(hw, reg_idx, reg);
  738. i40e_flush(hw);
  739. }
  740. /* reset some of the state varibles keeping
  741. * track of the resources
  742. */
  743. vf->num_queue_pairs = 0;
  744. vf->vf_states = 0;
  745. clear_bit(I40E_VF_STAT_INIT, &vf->vf_states);
  746. }
  747. /**
  748. * i40e_alloc_vf_res
  749. * @vf: pointer to the VF info
  750. *
  751. * allocate VF resources
  752. **/
  753. static int i40e_alloc_vf_res(struct i40e_vf *vf)
  754. {
  755. struct i40e_pf *pf = vf->pf;
  756. int total_queue_pairs = 0;
  757. int ret;
  758. /* allocate hw vsi context & associated resources */
  759. ret = i40e_alloc_vsi_res(vf, I40E_VSI_SRIOV);
  760. if (ret)
  761. goto error_alloc;
  762. total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
  763. set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
  764. /* store the total qps number for the runtime
  765. * VF req validation
  766. */
  767. vf->num_queue_pairs = total_queue_pairs;
  768. /* VF is now completely initialized */
  769. set_bit(I40E_VF_STAT_INIT, &vf->vf_states);
  770. error_alloc:
  771. if (ret)
  772. i40e_free_vf_res(vf);
  773. return ret;
  774. }
  775. #define VF_DEVICE_STATUS 0xAA
  776. #define VF_TRANS_PENDING_MASK 0x20
  777. /**
  778. * i40e_quiesce_vf_pci
  779. * @vf: pointer to the VF structure
  780. *
  781. * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
  782. * if the transactions never clear.
  783. **/
  784. static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
  785. {
  786. struct i40e_pf *pf = vf->pf;
  787. struct i40e_hw *hw = &pf->hw;
  788. int vf_abs_id, i;
  789. u32 reg;
  790. vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id;
  791. wr32(hw, I40E_PF_PCI_CIAA,
  792. VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
  793. for (i = 0; i < 100; i++) {
  794. reg = rd32(hw, I40E_PF_PCI_CIAD);
  795. if ((reg & VF_TRANS_PENDING_MASK) == 0)
  796. return 0;
  797. udelay(1);
  798. }
  799. return -EIO;
  800. }
  801. /**
  802. * i40e_reset_vf
  803. * @vf: pointer to the VF structure
  804. * @flr: VFLR was issued or not
  805. *
  806. * reset the VF
  807. **/
  808. void i40e_reset_vf(struct i40e_vf *vf, bool flr)
  809. {
  810. struct i40e_pf *pf = vf->pf;
  811. struct i40e_hw *hw = &pf->hw;
  812. u32 reg, reg_idx, bit_idx;
  813. bool rsd = false;
  814. int i;
  815. if (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
  816. return;
  817. /* warn the VF */
  818. clear_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
  819. /* In the case of a VFLR, the HW has already reset the VF and we
  820. * just need to clean up, so don't hit the VFRTRIG register.
  821. */
  822. if (!flr) {
  823. /* reset VF using VPGEN_VFRTRIG reg */
  824. reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
  825. reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
  826. wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
  827. i40e_flush(hw);
  828. }
  829. if (i40e_quiesce_vf_pci(vf))
  830. dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
  831. vf->vf_id);
  832. /* poll VPGEN_VFRSTAT reg to make sure
  833. * that reset is complete
  834. */
  835. for (i = 0; i < 10; i++) {
  836. /* VF reset requires driver to first reset the VF and then
  837. * poll the status register to make sure that the reset
  838. * completed successfully. Due to internal HW FIFO flushes,
  839. * we must wait 10ms before the register will be valid.
  840. */
  841. usleep_range(10000, 20000);
  842. reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
  843. if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
  844. rsd = true;
  845. break;
  846. }
  847. }
  848. if (flr)
  849. usleep_range(10000, 20000);
  850. if (!rsd)
  851. dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
  852. vf->vf_id);
  853. wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_COMPLETED);
  854. /* clear the reset bit in the VPGEN_VFRTRIG reg */
  855. reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
  856. reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
  857. wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
  858. /* On initial reset, we won't have any queues */
  859. if (vf->lan_vsi_idx == 0)
  860. goto complete_reset;
  861. i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false);
  862. complete_reset:
  863. /* reallocate VF resources to reset the VSI state */
  864. i40e_free_vf_res(vf);
  865. if (!i40e_alloc_vf_res(vf)) {
  866. int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
  867. i40e_enable_vf_mappings(vf);
  868. set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
  869. clear_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
  870. i40e_notify_client_of_vf_reset(pf, abs_vf_id);
  871. }
  872. /* tell the VF the reset is done */
  873. wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), I40E_VFR_VFACTIVE);
  874. /* clear the VFLR bit in GLGEN_VFLRSTAT */
  875. reg_idx = (hw->func_caps.vf_base_id + vf->vf_id) / 32;
  876. bit_idx = (hw->func_caps.vf_base_id + vf->vf_id) % 32;
  877. wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
  878. i40e_flush(hw);
  879. clear_bit(__I40E_VF_DISABLE, &pf->state);
  880. }
  881. /**
  882. * i40e_free_vfs
  883. * @pf: pointer to the PF structure
  884. *
  885. * free VF resources
  886. **/
  887. void i40e_free_vfs(struct i40e_pf *pf)
  888. {
  889. struct i40e_hw *hw = &pf->hw;
  890. u32 reg_idx, bit_idx;
  891. int i, tmp, vf_id;
  892. if (!pf->vf)
  893. return;
  894. while (test_and_set_bit(__I40E_VF_DISABLE, &pf->state))
  895. usleep_range(1000, 2000);
  896. i40e_notify_client_of_vf_enable(pf, 0);
  897. for (i = 0; i < pf->num_alloc_vfs; i++)
  898. if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
  899. i40e_vsi_control_rings(pf->vsi[pf->vf[i].lan_vsi_idx],
  900. false);
  901. /* Disable IOV before freeing resources. This lets any VF drivers
  902. * running in the host get themselves cleaned up before we yank
  903. * the carpet out from underneath their feet.
  904. */
  905. if (!pci_vfs_assigned(pf->pdev))
  906. pci_disable_sriov(pf->pdev);
  907. else
  908. dev_warn(&pf->pdev->dev, "VFs are assigned - not disabling SR-IOV\n");
  909. msleep(20); /* let any messages in transit get finished up */
  910. /* free up VF resources */
  911. tmp = pf->num_alloc_vfs;
  912. pf->num_alloc_vfs = 0;
  913. for (i = 0; i < tmp; i++) {
  914. if (test_bit(I40E_VF_STAT_INIT, &pf->vf[i].vf_states))
  915. i40e_free_vf_res(&pf->vf[i]);
  916. /* disable qp mappings */
  917. i40e_disable_vf_mappings(&pf->vf[i]);
  918. }
  919. kfree(pf->vf);
  920. pf->vf = NULL;
  921. /* This check is for when the driver is unloaded while VFs are
  922. * assigned. Setting the number of VFs to 0 through sysfs is caught
  923. * before this function ever gets called.
  924. */
  925. if (!pci_vfs_assigned(pf->pdev)) {
  926. /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
  927. * work correctly when SR-IOV gets re-enabled.
  928. */
  929. for (vf_id = 0; vf_id < tmp; vf_id++) {
  930. reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
  931. bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
  932. wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
  933. }
  934. }
  935. clear_bit(__I40E_VF_DISABLE, &pf->state);
  936. }
  937. #ifdef CONFIG_PCI_IOV
  938. /**
  939. * i40e_alloc_vfs
  940. * @pf: pointer to the PF structure
  941. * @num_alloc_vfs: number of VFs to allocate
  942. *
  943. * allocate VF resources
  944. **/
  945. int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
  946. {
  947. struct i40e_vf *vfs;
  948. int i, ret = 0;
  949. /* Disable interrupt 0 so we don't try to handle the VFLR. */
  950. i40e_irq_dynamic_disable_icr0(pf);
  951. /* Check to see if we're just allocating resources for extant VFs */
  952. if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
  953. ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
  954. if (ret) {
  955. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  956. pf->num_alloc_vfs = 0;
  957. goto err_iov;
  958. }
  959. }
  960. i40e_notify_client_of_vf_enable(pf, num_alloc_vfs);
  961. /* allocate memory */
  962. vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
  963. if (!vfs) {
  964. ret = -ENOMEM;
  965. goto err_alloc;
  966. }
  967. pf->vf = vfs;
  968. /* apply default profile */
  969. for (i = 0; i < num_alloc_vfs; i++) {
  970. vfs[i].pf = pf;
  971. vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
  972. vfs[i].vf_id = i;
  973. /* assign default capabilities */
  974. set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
  975. vfs[i].spoofchk = true;
  976. /* VF resources get allocated during reset */
  977. i40e_reset_vf(&vfs[i], false);
  978. }
  979. pf->num_alloc_vfs = num_alloc_vfs;
  980. err_alloc:
  981. if (ret)
  982. i40e_free_vfs(pf);
  983. err_iov:
  984. /* Re-enable interrupt 0. */
  985. i40e_irq_dynamic_enable_icr0(pf, false);
  986. return ret;
  987. }
  988. #endif
  989. /**
  990. * i40e_pci_sriov_enable
  991. * @pdev: pointer to a pci_dev structure
  992. * @num_vfs: number of VFs to allocate
  993. *
  994. * Enable or change the number of VFs
  995. **/
  996. static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
  997. {
  998. #ifdef CONFIG_PCI_IOV
  999. struct i40e_pf *pf = pci_get_drvdata(pdev);
  1000. int pre_existing_vfs = pci_num_vf(pdev);
  1001. int err = 0;
  1002. if (test_bit(__I40E_TESTING, &pf->state)) {
  1003. dev_warn(&pdev->dev,
  1004. "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
  1005. err = -EPERM;
  1006. goto err_out;
  1007. }
  1008. if (pre_existing_vfs && pre_existing_vfs != num_vfs)
  1009. i40e_free_vfs(pf);
  1010. else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
  1011. goto out;
  1012. if (num_vfs > pf->num_req_vfs) {
  1013. dev_warn(&pdev->dev, "Unable to enable %d VFs. Limited to %d VFs due to device resource constraints.\n",
  1014. num_vfs, pf->num_req_vfs);
  1015. err = -EPERM;
  1016. goto err_out;
  1017. }
  1018. dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
  1019. err = i40e_alloc_vfs(pf, num_vfs);
  1020. if (err) {
  1021. dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
  1022. goto err_out;
  1023. }
  1024. out:
  1025. return num_vfs;
  1026. err_out:
  1027. return err;
  1028. #endif
  1029. return 0;
  1030. }
  1031. /**
  1032. * i40e_pci_sriov_configure
  1033. * @pdev: pointer to a pci_dev structure
  1034. * @num_vfs: number of VFs to allocate
  1035. *
  1036. * Enable or change the number of VFs. Called when the user updates the number
  1037. * of VFs in sysfs.
  1038. **/
  1039. int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
  1040. {
  1041. struct i40e_pf *pf = pci_get_drvdata(pdev);
  1042. if (num_vfs) {
  1043. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  1044. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  1045. i40e_do_reset_safe(pf,
  1046. BIT_ULL(__I40E_PF_RESET_REQUESTED));
  1047. }
  1048. return i40e_pci_sriov_enable(pdev, num_vfs);
  1049. }
  1050. if (!pci_vfs_assigned(pf->pdev)) {
  1051. i40e_free_vfs(pf);
  1052. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  1053. i40e_do_reset_safe(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  1054. } else {
  1055. dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
  1056. return -EINVAL;
  1057. }
  1058. return 0;
  1059. }
  1060. /***********************virtual channel routines******************/
  1061. /**
  1062. * i40e_vc_send_msg_to_vf
  1063. * @vf: pointer to the VF info
  1064. * @v_opcode: virtual channel opcode
  1065. * @v_retval: virtual channel return value
  1066. * @msg: pointer to the msg buffer
  1067. * @msglen: msg length
  1068. *
  1069. * send msg to VF
  1070. **/
  1071. static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
  1072. u32 v_retval, u8 *msg, u16 msglen)
  1073. {
  1074. struct i40e_pf *pf;
  1075. struct i40e_hw *hw;
  1076. int abs_vf_id;
  1077. i40e_status aq_ret;
  1078. /* validate the request */
  1079. if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
  1080. return -EINVAL;
  1081. pf = vf->pf;
  1082. hw = &pf->hw;
  1083. abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
  1084. /* single place to detect unsuccessful return values */
  1085. if (v_retval) {
  1086. vf->num_invalid_msgs++;
  1087. dev_err(&pf->pdev->dev, "VF %d failed opcode %d, error: %d\n",
  1088. vf->vf_id, v_opcode, v_retval);
  1089. if (vf->num_invalid_msgs >
  1090. I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
  1091. dev_err(&pf->pdev->dev,
  1092. "Number of invalid messages exceeded for VF %d\n",
  1093. vf->vf_id);
  1094. dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
  1095. set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
  1096. }
  1097. } else {
  1098. vf->num_valid_msgs++;
  1099. /* reset the invalid counter, if a valid message is received. */
  1100. vf->num_invalid_msgs = 0;
  1101. }
  1102. aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
  1103. msg, msglen, NULL);
  1104. if (aq_ret) {
  1105. dev_err(&pf->pdev->dev,
  1106. "Unable to send the message to VF %d aq_err %d\n",
  1107. vf->vf_id, pf->hw.aq.asq_last_status);
  1108. return -EIO;
  1109. }
  1110. return 0;
  1111. }
  1112. /**
  1113. * i40e_vc_send_resp_to_vf
  1114. * @vf: pointer to the VF info
  1115. * @opcode: operation code
  1116. * @retval: return value
  1117. *
  1118. * send resp msg to VF
  1119. **/
  1120. static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
  1121. enum i40e_virtchnl_ops opcode,
  1122. i40e_status retval)
  1123. {
  1124. return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
  1125. }
  1126. /**
  1127. * i40e_vc_get_version_msg
  1128. * @vf: pointer to the VF info
  1129. *
  1130. * called from the VF to request the API version used by the PF
  1131. **/
  1132. static int i40e_vc_get_version_msg(struct i40e_vf *vf, u8 *msg)
  1133. {
  1134. struct i40e_virtchnl_version_info info = {
  1135. I40E_VIRTCHNL_VERSION_MAJOR, I40E_VIRTCHNL_VERSION_MINOR
  1136. };
  1137. vf->vf_ver = *(struct i40e_virtchnl_version_info *)msg;
  1138. /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
  1139. if (VF_IS_V10(vf))
  1140. info.minor = I40E_VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
  1141. return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_VERSION,
  1142. I40E_SUCCESS, (u8 *)&info,
  1143. sizeof(struct
  1144. i40e_virtchnl_version_info));
  1145. }
  1146. /**
  1147. * i40e_vc_get_vf_resources_msg
  1148. * @vf: pointer to the VF info
  1149. * @msg: pointer to the msg buffer
  1150. * @msglen: msg length
  1151. *
  1152. * called from the VF to request its resources
  1153. **/
  1154. static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)
  1155. {
  1156. struct i40e_virtchnl_vf_resource *vfres = NULL;
  1157. struct i40e_pf *pf = vf->pf;
  1158. i40e_status aq_ret = 0;
  1159. struct i40e_vsi *vsi;
  1160. int num_vsis = 1;
  1161. int len = 0;
  1162. int ret;
  1163. if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
  1164. aq_ret = I40E_ERR_PARAM;
  1165. goto err;
  1166. }
  1167. len = (sizeof(struct i40e_virtchnl_vf_resource) +
  1168. sizeof(struct i40e_virtchnl_vsi_resource) * num_vsis);
  1169. vfres = kzalloc(len, GFP_KERNEL);
  1170. if (!vfres) {
  1171. aq_ret = I40E_ERR_NO_MEMORY;
  1172. len = 0;
  1173. goto err;
  1174. }
  1175. if (VF_IS_V11(vf))
  1176. vf->driver_caps = *(u32 *)msg;
  1177. else
  1178. vf->driver_caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
  1179. I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG |
  1180. I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
  1181. vfres->vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2;
  1182. vsi = pf->vsi[vf->lan_vsi_idx];
  1183. if (!vsi->info.pvid)
  1184. vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
  1185. if (i40e_vf_client_capable(pf, vf->vf_id, I40E_CLIENT_IWARP) &&
  1186. (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_IWARP)) {
  1187. vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_IWARP;
  1188. set_bit(I40E_VF_STAT_IWARPENA, &vf->vf_states);
  1189. }
  1190. if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
  1191. if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ)
  1192. vfres->vf_offload_flags |=
  1193. I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ;
  1194. } else {
  1195. vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG;
  1196. }
  1197. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) {
  1198. if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
  1199. vfres->vf_offload_flags |=
  1200. I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
  1201. }
  1202. if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING)
  1203. vfres->vf_offload_flags |= I40E_VIRTCHNL_VF_OFFLOAD_RX_POLLING;
  1204. if (pf->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) {
  1205. if (vf->driver_caps & I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
  1206. vfres->vf_offload_flags |=
  1207. I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
  1208. }
  1209. vfres->num_vsis = num_vsis;
  1210. vfres->num_queue_pairs = vf->num_queue_pairs;
  1211. vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
  1212. if (vf->lan_vsi_idx) {
  1213. vfres->vsi_res[0].vsi_id = vf->lan_vsi_id;
  1214. vfres->vsi_res[0].vsi_type = I40E_VSI_SRIOV;
  1215. vfres->vsi_res[0].num_queue_pairs = vsi->alloc_queue_pairs;
  1216. /* VFs only use TC 0 */
  1217. vfres->vsi_res[0].qset_handle
  1218. = le16_to_cpu(vsi->info.qs_handle[0]);
  1219. ether_addr_copy(vfres->vsi_res[0].default_mac_addr,
  1220. vf->default_lan_addr.addr);
  1221. }
  1222. set_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states);
  1223. err:
  1224. /* send the response back to the VF */
  1225. ret = i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
  1226. aq_ret, (u8 *)vfres, len);
  1227. kfree(vfres);
  1228. return ret;
  1229. }
  1230. /**
  1231. * i40e_vc_reset_vf_msg
  1232. * @vf: pointer to the VF info
  1233. * @msg: pointer to the msg buffer
  1234. * @msglen: msg length
  1235. *
  1236. * called from the VF to reset itself,
  1237. * unlike other virtchnl messages, PF driver
  1238. * doesn't send the response back to the VF
  1239. **/
  1240. static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
  1241. {
  1242. if (test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states))
  1243. i40e_reset_vf(vf, false);
  1244. }
  1245. /**
  1246. * i40e_vc_config_promiscuous_mode_msg
  1247. * @vf: pointer to the VF info
  1248. * @msg: pointer to the msg buffer
  1249. * @msglen: msg length
  1250. *
  1251. * called from the VF to configure the promiscuous mode of
  1252. * VF vsis
  1253. **/
  1254. static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
  1255. u8 *msg, u16 msglen)
  1256. {
  1257. struct i40e_virtchnl_promisc_info *info =
  1258. (struct i40e_virtchnl_promisc_info *)msg;
  1259. struct i40e_pf *pf = vf->pf;
  1260. struct i40e_hw *hw = &pf->hw;
  1261. struct i40e_vsi *vsi;
  1262. bool allmulti = false;
  1263. i40e_status aq_ret;
  1264. vsi = i40e_find_vsi_from_id(pf, info->vsi_id);
  1265. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  1266. !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
  1267. !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
  1268. (vsi->type != I40E_VSI_FCOE)) {
  1269. aq_ret = I40E_ERR_PARAM;
  1270. goto error_param;
  1271. }
  1272. if (info->flags & I40E_FLAG_VF_MULTICAST_PROMISC)
  1273. allmulti = true;
  1274. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
  1275. allmulti, NULL);
  1276. error_param:
  1277. /* send the response to the VF */
  1278. return i40e_vc_send_resp_to_vf(vf,
  1279. I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
  1280. aq_ret);
  1281. }
  1282. /**
  1283. * i40e_vc_config_queues_msg
  1284. * @vf: pointer to the VF info
  1285. * @msg: pointer to the msg buffer
  1286. * @msglen: msg length
  1287. *
  1288. * called from the VF to configure the rx/tx
  1289. * queues
  1290. **/
  1291. static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1292. {
  1293. struct i40e_virtchnl_vsi_queue_config_info *qci =
  1294. (struct i40e_virtchnl_vsi_queue_config_info *)msg;
  1295. struct i40e_virtchnl_queue_pair_info *qpi;
  1296. struct i40e_pf *pf = vf->pf;
  1297. u16 vsi_id, vsi_queue_id;
  1298. i40e_status aq_ret = 0;
  1299. int i;
  1300. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
  1301. aq_ret = I40E_ERR_PARAM;
  1302. goto error_param;
  1303. }
  1304. vsi_id = qci->vsi_id;
  1305. if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1306. aq_ret = I40E_ERR_PARAM;
  1307. goto error_param;
  1308. }
  1309. for (i = 0; i < qci->num_queue_pairs; i++) {
  1310. qpi = &qci->qpair[i];
  1311. vsi_queue_id = qpi->txq.queue_id;
  1312. if ((qpi->txq.vsi_id != vsi_id) ||
  1313. (qpi->rxq.vsi_id != vsi_id) ||
  1314. (qpi->rxq.queue_id != vsi_queue_id) ||
  1315. !i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
  1316. aq_ret = I40E_ERR_PARAM;
  1317. goto error_param;
  1318. }
  1319. if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
  1320. &qpi->rxq) ||
  1321. i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
  1322. &qpi->txq)) {
  1323. aq_ret = I40E_ERR_PARAM;
  1324. goto error_param;
  1325. }
  1326. }
  1327. /* set vsi num_queue_pairs in use to num configured by VF */
  1328. pf->vsi[vf->lan_vsi_idx]->num_queue_pairs = qci->num_queue_pairs;
  1329. error_param:
  1330. /* send the response to the VF */
  1331. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
  1332. aq_ret);
  1333. }
  1334. /**
  1335. * i40e_vc_config_irq_map_msg
  1336. * @vf: pointer to the VF info
  1337. * @msg: pointer to the msg buffer
  1338. * @msglen: msg length
  1339. *
  1340. * called from the VF to configure the irq to
  1341. * queue map
  1342. **/
  1343. static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1344. {
  1345. struct i40e_virtchnl_irq_map_info *irqmap_info =
  1346. (struct i40e_virtchnl_irq_map_info *)msg;
  1347. struct i40e_virtchnl_vector_map *map;
  1348. u16 vsi_id, vsi_queue_id, vector_id;
  1349. i40e_status aq_ret = 0;
  1350. unsigned long tempmap;
  1351. int i;
  1352. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
  1353. aq_ret = I40E_ERR_PARAM;
  1354. goto error_param;
  1355. }
  1356. for (i = 0; i < irqmap_info->num_vectors; i++) {
  1357. map = &irqmap_info->vecmap[i];
  1358. vector_id = map->vector_id;
  1359. vsi_id = map->vsi_id;
  1360. /* validate msg params */
  1361. if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
  1362. !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1363. aq_ret = I40E_ERR_PARAM;
  1364. goto error_param;
  1365. }
  1366. /* lookout for the invalid queue index */
  1367. tempmap = map->rxq_map;
  1368. for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
  1369. if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
  1370. vsi_queue_id)) {
  1371. aq_ret = I40E_ERR_PARAM;
  1372. goto error_param;
  1373. }
  1374. }
  1375. tempmap = map->txq_map;
  1376. for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
  1377. if (!i40e_vc_isvalid_queue_id(vf, vsi_id,
  1378. vsi_queue_id)) {
  1379. aq_ret = I40E_ERR_PARAM;
  1380. goto error_param;
  1381. }
  1382. }
  1383. i40e_config_irq_link_list(vf, vsi_id, map);
  1384. }
  1385. error_param:
  1386. /* send the response to the VF */
  1387. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
  1388. aq_ret);
  1389. }
  1390. /**
  1391. * i40e_vc_enable_queues_msg
  1392. * @vf: pointer to the VF info
  1393. * @msg: pointer to the msg buffer
  1394. * @msglen: msg length
  1395. *
  1396. * called from the VF to enable all or specific queue(s)
  1397. **/
  1398. static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1399. {
  1400. struct i40e_virtchnl_queue_select *vqs =
  1401. (struct i40e_virtchnl_queue_select *)msg;
  1402. struct i40e_pf *pf = vf->pf;
  1403. u16 vsi_id = vqs->vsi_id;
  1404. i40e_status aq_ret = 0;
  1405. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
  1406. aq_ret = I40E_ERR_PARAM;
  1407. goto error_param;
  1408. }
  1409. if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1410. aq_ret = I40E_ERR_PARAM;
  1411. goto error_param;
  1412. }
  1413. if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
  1414. aq_ret = I40E_ERR_PARAM;
  1415. goto error_param;
  1416. }
  1417. if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], true))
  1418. aq_ret = I40E_ERR_TIMEOUT;
  1419. error_param:
  1420. /* send the response to the VF */
  1421. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
  1422. aq_ret);
  1423. }
  1424. /**
  1425. * i40e_vc_disable_queues_msg
  1426. * @vf: pointer to the VF info
  1427. * @msg: pointer to the msg buffer
  1428. * @msglen: msg length
  1429. *
  1430. * called from the VF to disable all or specific
  1431. * queue(s)
  1432. **/
  1433. static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1434. {
  1435. struct i40e_virtchnl_queue_select *vqs =
  1436. (struct i40e_virtchnl_queue_select *)msg;
  1437. struct i40e_pf *pf = vf->pf;
  1438. i40e_status aq_ret = 0;
  1439. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
  1440. aq_ret = I40E_ERR_PARAM;
  1441. goto error_param;
  1442. }
  1443. if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
  1444. aq_ret = I40E_ERR_PARAM;
  1445. goto error_param;
  1446. }
  1447. if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
  1448. aq_ret = I40E_ERR_PARAM;
  1449. goto error_param;
  1450. }
  1451. if (i40e_vsi_control_rings(pf->vsi[vf->lan_vsi_idx], false))
  1452. aq_ret = I40E_ERR_TIMEOUT;
  1453. error_param:
  1454. /* send the response to the VF */
  1455. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
  1456. aq_ret);
  1457. }
  1458. /**
  1459. * i40e_vc_get_stats_msg
  1460. * @vf: pointer to the VF info
  1461. * @msg: pointer to the msg buffer
  1462. * @msglen: msg length
  1463. *
  1464. * called from the VF to get vsi stats
  1465. **/
  1466. static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1467. {
  1468. struct i40e_virtchnl_queue_select *vqs =
  1469. (struct i40e_virtchnl_queue_select *)msg;
  1470. struct i40e_pf *pf = vf->pf;
  1471. struct i40e_eth_stats stats;
  1472. i40e_status aq_ret = 0;
  1473. struct i40e_vsi *vsi;
  1474. memset(&stats, 0, sizeof(struct i40e_eth_stats));
  1475. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states)) {
  1476. aq_ret = I40E_ERR_PARAM;
  1477. goto error_param;
  1478. }
  1479. if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
  1480. aq_ret = I40E_ERR_PARAM;
  1481. goto error_param;
  1482. }
  1483. vsi = pf->vsi[vf->lan_vsi_idx];
  1484. if (!vsi) {
  1485. aq_ret = I40E_ERR_PARAM;
  1486. goto error_param;
  1487. }
  1488. i40e_update_eth_stats(vsi);
  1489. stats = vsi->eth_stats;
  1490. error_param:
  1491. /* send the response back to the VF */
  1492. return i40e_vc_send_msg_to_vf(vf, I40E_VIRTCHNL_OP_GET_STATS, aq_ret,
  1493. (u8 *)&stats, sizeof(stats));
  1494. }
  1495. /**
  1496. * i40e_check_vf_permission
  1497. * @vf: pointer to the VF info
  1498. * @macaddr: pointer to the MAC Address being checked
  1499. *
  1500. * Check if the VF has permission to add or delete unicast MAC address
  1501. * filters and return error code -EPERM if not. Then check if the
  1502. * address filter requested is broadcast or zero and if so return
  1503. * an invalid MAC address error code.
  1504. **/
  1505. static inline int i40e_check_vf_permission(struct i40e_vf *vf, u8 *macaddr)
  1506. {
  1507. struct i40e_pf *pf = vf->pf;
  1508. int ret = 0;
  1509. if (is_broadcast_ether_addr(macaddr) ||
  1510. is_zero_ether_addr(macaddr)) {
  1511. dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n", macaddr);
  1512. ret = I40E_ERR_INVALID_MAC_ADDR;
  1513. } else if (vf->pf_set_mac && !is_multicast_ether_addr(macaddr) &&
  1514. !ether_addr_equal(macaddr, vf->default_lan_addr.addr)) {
  1515. /* If the host VMM administrator has set the VF MAC address
  1516. * administratively via the ndo_set_vf_mac command then deny
  1517. * permission to the VF to add or delete unicast MAC addresses.
  1518. * The VF may request to set the MAC address filter already
  1519. * assigned to it so do not return an error in that case.
  1520. */
  1521. dev_err(&pf->pdev->dev,
  1522. "VF attempting to override administratively set MAC address\nPlease reload the VF driver to resume normal operation\n");
  1523. ret = -EPERM;
  1524. }
  1525. return ret;
  1526. }
  1527. /**
  1528. * i40e_vc_add_mac_addr_msg
  1529. * @vf: pointer to the VF info
  1530. * @msg: pointer to the msg buffer
  1531. * @msglen: msg length
  1532. *
  1533. * add guest mac address filter
  1534. **/
  1535. static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1536. {
  1537. struct i40e_virtchnl_ether_addr_list *al =
  1538. (struct i40e_virtchnl_ether_addr_list *)msg;
  1539. struct i40e_pf *pf = vf->pf;
  1540. struct i40e_vsi *vsi = NULL;
  1541. u16 vsi_id = al->vsi_id;
  1542. i40e_status ret = 0;
  1543. int i;
  1544. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  1545. !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
  1546. !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1547. ret = I40E_ERR_PARAM;
  1548. goto error_param;
  1549. }
  1550. for (i = 0; i < al->num_elements; i++) {
  1551. ret = i40e_check_vf_permission(vf, al->list[i].addr);
  1552. if (ret)
  1553. goto error_param;
  1554. }
  1555. vsi = pf->vsi[vf->lan_vsi_idx];
  1556. /* Lock once, because all function inside for loop accesses VSI's
  1557. * MAC filter list which needs to be protected using same lock.
  1558. */
  1559. spin_lock_bh(&vsi->mac_filter_list_lock);
  1560. /* add new addresses to the list */
  1561. for (i = 0; i < al->num_elements; i++) {
  1562. struct i40e_mac_filter *f;
  1563. f = i40e_find_mac(vsi, al->list[i].addr, true, false);
  1564. if (!f) {
  1565. if (i40e_is_vsi_in_vlan(vsi))
  1566. f = i40e_put_mac_in_vlan(vsi, al->list[i].addr,
  1567. true, false);
  1568. else
  1569. f = i40e_add_filter(vsi, al->list[i].addr, -1,
  1570. true, false);
  1571. }
  1572. if (!f) {
  1573. dev_err(&pf->pdev->dev,
  1574. "Unable to add MAC filter %pM for VF %d\n",
  1575. al->list[i].addr, vf->vf_id);
  1576. ret = I40E_ERR_PARAM;
  1577. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1578. goto error_param;
  1579. }
  1580. }
  1581. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1582. /* program the updated filter list */
  1583. ret = i40e_sync_vsi_filters(vsi);
  1584. if (ret)
  1585. dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
  1586. vf->vf_id, ret);
  1587. error_param:
  1588. /* send the response to the VF */
  1589. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
  1590. ret);
  1591. }
  1592. /**
  1593. * i40e_vc_del_mac_addr_msg
  1594. * @vf: pointer to the VF info
  1595. * @msg: pointer to the msg buffer
  1596. * @msglen: msg length
  1597. *
  1598. * remove guest mac address filter
  1599. **/
  1600. static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1601. {
  1602. struct i40e_virtchnl_ether_addr_list *al =
  1603. (struct i40e_virtchnl_ether_addr_list *)msg;
  1604. struct i40e_pf *pf = vf->pf;
  1605. struct i40e_vsi *vsi = NULL;
  1606. u16 vsi_id = al->vsi_id;
  1607. i40e_status ret = 0;
  1608. int i;
  1609. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  1610. !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
  1611. !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1612. ret = I40E_ERR_PARAM;
  1613. goto error_param;
  1614. }
  1615. for (i = 0; i < al->num_elements; i++) {
  1616. if (is_broadcast_ether_addr(al->list[i].addr) ||
  1617. is_zero_ether_addr(al->list[i].addr)) {
  1618. dev_err(&pf->pdev->dev, "Invalid MAC addr %pM for VF %d\n",
  1619. al->list[i].addr, vf->vf_id);
  1620. ret = I40E_ERR_INVALID_MAC_ADDR;
  1621. goto error_param;
  1622. }
  1623. }
  1624. vsi = pf->vsi[vf->lan_vsi_idx];
  1625. spin_lock_bh(&vsi->mac_filter_list_lock);
  1626. /* delete addresses from the list */
  1627. for (i = 0; i < al->num_elements; i++)
  1628. if (i40e_del_mac_all_vlan(vsi, al->list[i].addr, true, false)) {
  1629. ret = I40E_ERR_INVALID_MAC_ADDR;
  1630. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1631. goto error_param;
  1632. }
  1633. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1634. /* program the updated filter list */
  1635. ret = i40e_sync_vsi_filters(vsi);
  1636. if (ret)
  1637. dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
  1638. vf->vf_id, ret);
  1639. error_param:
  1640. /* send the response to the VF */
  1641. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
  1642. ret);
  1643. }
  1644. /**
  1645. * i40e_vc_add_vlan_msg
  1646. * @vf: pointer to the VF info
  1647. * @msg: pointer to the msg buffer
  1648. * @msglen: msg length
  1649. *
  1650. * program guest vlan id
  1651. **/
  1652. static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1653. {
  1654. struct i40e_virtchnl_vlan_filter_list *vfl =
  1655. (struct i40e_virtchnl_vlan_filter_list *)msg;
  1656. struct i40e_pf *pf = vf->pf;
  1657. struct i40e_vsi *vsi = NULL;
  1658. u16 vsi_id = vfl->vsi_id;
  1659. i40e_status aq_ret = 0;
  1660. int i;
  1661. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  1662. !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
  1663. !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1664. aq_ret = I40E_ERR_PARAM;
  1665. goto error_param;
  1666. }
  1667. for (i = 0; i < vfl->num_elements; i++) {
  1668. if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
  1669. aq_ret = I40E_ERR_PARAM;
  1670. dev_err(&pf->pdev->dev,
  1671. "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
  1672. goto error_param;
  1673. }
  1674. }
  1675. vsi = pf->vsi[vf->lan_vsi_idx];
  1676. if (vsi->info.pvid) {
  1677. aq_ret = I40E_ERR_PARAM;
  1678. goto error_param;
  1679. }
  1680. i40e_vlan_stripping_enable(vsi);
  1681. for (i = 0; i < vfl->num_elements; i++) {
  1682. /* add new VLAN filter */
  1683. int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
  1684. if (ret)
  1685. dev_err(&pf->pdev->dev,
  1686. "Unable to add VLAN filter %d for VF %d, error %d\n",
  1687. vfl->vlan_id[i], vf->vf_id, ret);
  1688. }
  1689. error_param:
  1690. /* send the response to the VF */
  1691. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_ADD_VLAN, aq_ret);
  1692. }
  1693. /**
  1694. * i40e_vc_remove_vlan_msg
  1695. * @vf: pointer to the VF info
  1696. * @msg: pointer to the msg buffer
  1697. * @msglen: msg length
  1698. *
  1699. * remove programmed guest vlan id
  1700. **/
  1701. static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1702. {
  1703. struct i40e_virtchnl_vlan_filter_list *vfl =
  1704. (struct i40e_virtchnl_vlan_filter_list *)msg;
  1705. struct i40e_pf *pf = vf->pf;
  1706. struct i40e_vsi *vsi = NULL;
  1707. u16 vsi_id = vfl->vsi_id;
  1708. i40e_status aq_ret = 0;
  1709. int i;
  1710. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  1711. !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) ||
  1712. !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1713. aq_ret = I40E_ERR_PARAM;
  1714. goto error_param;
  1715. }
  1716. for (i = 0; i < vfl->num_elements; i++) {
  1717. if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
  1718. aq_ret = I40E_ERR_PARAM;
  1719. goto error_param;
  1720. }
  1721. }
  1722. vsi = pf->vsi[vf->lan_vsi_idx];
  1723. if (vsi->info.pvid) {
  1724. aq_ret = I40E_ERR_PARAM;
  1725. goto error_param;
  1726. }
  1727. for (i = 0; i < vfl->num_elements; i++) {
  1728. int ret = i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
  1729. if (ret)
  1730. dev_err(&pf->pdev->dev,
  1731. "Unable to delete VLAN filter %d for VF %d, error %d\n",
  1732. vfl->vlan_id[i], vf->vf_id, ret);
  1733. }
  1734. error_param:
  1735. /* send the response to the VF */
  1736. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_DEL_VLAN, aq_ret);
  1737. }
  1738. /**
  1739. * i40e_vc_iwarp_msg
  1740. * @vf: pointer to the VF info
  1741. * @msg: pointer to the msg buffer
  1742. * @msglen: msg length
  1743. *
  1744. * called from the VF for the iwarp msgs
  1745. **/
  1746. static int i40e_vc_iwarp_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1747. {
  1748. struct i40e_pf *pf = vf->pf;
  1749. int abs_vf_id = vf->vf_id + pf->hw.func_caps.vf_base_id;
  1750. i40e_status aq_ret = 0;
  1751. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  1752. !test_bit(I40E_VF_STAT_IWARPENA, &vf->vf_states)) {
  1753. aq_ret = I40E_ERR_PARAM;
  1754. goto error_param;
  1755. }
  1756. i40e_notify_client_of_vf_msg(pf->vsi[pf->lan_vsi], abs_vf_id,
  1757. msg, msglen);
  1758. error_param:
  1759. /* send the response to the VF */
  1760. return i40e_vc_send_resp_to_vf(vf, I40E_VIRTCHNL_OP_IWARP,
  1761. aq_ret);
  1762. }
  1763. /**
  1764. * i40e_vc_iwarp_qvmap_msg
  1765. * @vf: pointer to the VF info
  1766. * @msg: pointer to the msg buffer
  1767. * @msglen: msg length
  1768. * @config: config qvmap or release it
  1769. *
  1770. * called from the VF for the iwarp msgs
  1771. **/
  1772. static int i40e_vc_iwarp_qvmap_msg(struct i40e_vf *vf, u8 *msg, u16 msglen,
  1773. bool config)
  1774. {
  1775. struct i40e_virtchnl_iwarp_qvlist_info *qvlist_info =
  1776. (struct i40e_virtchnl_iwarp_qvlist_info *)msg;
  1777. i40e_status aq_ret = 0;
  1778. if (!test_bit(I40E_VF_STAT_ACTIVE, &vf->vf_states) ||
  1779. !test_bit(I40E_VF_STAT_IWARPENA, &vf->vf_states)) {
  1780. aq_ret = I40E_ERR_PARAM;
  1781. goto error_param;
  1782. }
  1783. if (config) {
  1784. if (i40e_config_iwarp_qvlist(vf, qvlist_info))
  1785. aq_ret = I40E_ERR_PARAM;
  1786. } else {
  1787. i40e_release_iwarp_qvlist(vf);
  1788. }
  1789. error_param:
  1790. /* send the response to the VF */
  1791. return i40e_vc_send_resp_to_vf(vf,
  1792. config ? I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP :
  1793. I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP,
  1794. aq_ret);
  1795. }
  1796. /**
  1797. * i40e_vc_validate_vf_msg
  1798. * @vf: pointer to the VF info
  1799. * @msg: pointer to the msg buffer
  1800. * @msglen: msg length
  1801. * @msghndl: msg handle
  1802. *
  1803. * validate msg
  1804. **/
  1805. static int i40e_vc_validate_vf_msg(struct i40e_vf *vf, u32 v_opcode,
  1806. u32 v_retval, u8 *msg, u16 msglen)
  1807. {
  1808. bool err_msg_format = false;
  1809. int valid_len;
  1810. /* Check if VF is disabled. */
  1811. if (test_bit(I40E_VF_STAT_DISABLED, &vf->vf_states))
  1812. return I40E_ERR_PARAM;
  1813. /* Validate message length. */
  1814. switch (v_opcode) {
  1815. case I40E_VIRTCHNL_OP_VERSION:
  1816. valid_len = sizeof(struct i40e_virtchnl_version_info);
  1817. break;
  1818. case I40E_VIRTCHNL_OP_RESET_VF:
  1819. valid_len = 0;
  1820. break;
  1821. case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
  1822. if (VF_IS_V11(vf))
  1823. valid_len = sizeof(u32);
  1824. else
  1825. valid_len = 0;
  1826. break;
  1827. case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE:
  1828. valid_len = sizeof(struct i40e_virtchnl_txq_info);
  1829. break;
  1830. case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE:
  1831. valid_len = sizeof(struct i40e_virtchnl_rxq_info);
  1832. break;
  1833. case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
  1834. valid_len = sizeof(struct i40e_virtchnl_vsi_queue_config_info);
  1835. if (msglen >= valid_len) {
  1836. struct i40e_virtchnl_vsi_queue_config_info *vqc =
  1837. (struct i40e_virtchnl_vsi_queue_config_info *)msg;
  1838. valid_len += (vqc->num_queue_pairs *
  1839. sizeof(struct
  1840. i40e_virtchnl_queue_pair_info));
  1841. if (vqc->num_queue_pairs == 0)
  1842. err_msg_format = true;
  1843. }
  1844. break;
  1845. case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
  1846. valid_len = sizeof(struct i40e_virtchnl_irq_map_info);
  1847. if (msglen >= valid_len) {
  1848. struct i40e_virtchnl_irq_map_info *vimi =
  1849. (struct i40e_virtchnl_irq_map_info *)msg;
  1850. valid_len += (vimi->num_vectors *
  1851. sizeof(struct i40e_virtchnl_vector_map));
  1852. if (vimi->num_vectors == 0)
  1853. err_msg_format = true;
  1854. }
  1855. break;
  1856. case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
  1857. case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
  1858. valid_len = sizeof(struct i40e_virtchnl_queue_select);
  1859. break;
  1860. case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
  1861. case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
  1862. valid_len = sizeof(struct i40e_virtchnl_ether_addr_list);
  1863. if (msglen >= valid_len) {
  1864. struct i40e_virtchnl_ether_addr_list *veal =
  1865. (struct i40e_virtchnl_ether_addr_list *)msg;
  1866. valid_len += veal->num_elements *
  1867. sizeof(struct i40e_virtchnl_ether_addr);
  1868. if (veal->num_elements == 0)
  1869. err_msg_format = true;
  1870. }
  1871. break;
  1872. case I40E_VIRTCHNL_OP_ADD_VLAN:
  1873. case I40E_VIRTCHNL_OP_DEL_VLAN:
  1874. valid_len = sizeof(struct i40e_virtchnl_vlan_filter_list);
  1875. if (msglen >= valid_len) {
  1876. struct i40e_virtchnl_vlan_filter_list *vfl =
  1877. (struct i40e_virtchnl_vlan_filter_list *)msg;
  1878. valid_len += vfl->num_elements * sizeof(u16);
  1879. if (vfl->num_elements == 0)
  1880. err_msg_format = true;
  1881. }
  1882. break;
  1883. case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
  1884. valid_len = sizeof(struct i40e_virtchnl_promisc_info);
  1885. break;
  1886. case I40E_VIRTCHNL_OP_GET_STATS:
  1887. valid_len = sizeof(struct i40e_virtchnl_queue_select);
  1888. break;
  1889. case I40E_VIRTCHNL_OP_IWARP:
  1890. /* These messages are opaque to us and will be validated in
  1891. * the RDMA client code. We just need to check for nonzero
  1892. * length. The firmware will enforce max length restrictions.
  1893. */
  1894. if (msglen)
  1895. valid_len = msglen;
  1896. else
  1897. err_msg_format = true;
  1898. break;
  1899. case I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
  1900. valid_len = 0;
  1901. break;
  1902. case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
  1903. valid_len = sizeof(struct i40e_virtchnl_iwarp_qvlist_info);
  1904. if (msglen >= valid_len) {
  1905. struct i40e_virtchnl_iwarp_qvlist_info *qv =
  1906. (struct i40e_virtchnl_iwarp_qvlist_info *)msg;
  1907. if (qv->num_vectors == 0) {
  1908. err_msg_format = true;
  1909. break;
  1910. }
  1911. valid_len += ((qv->num_vectors - 1) *
  1912. sizeof(struct i40e_virtchnl_iwarp_qv_info));
  1913. }
  1914. break;
  1915. /* These are always errors coming from the VF. */
  1916. case I40E_VIRTCHNL_OP_EVENT:
  1917. case I40E_VIRTCHNL_OP_UNKNOWN:
  1918. default:
  1919. return -EPERM;
  1920. }
  1921. /* few more checks */
  1922. if ((valid_len != msglen) || (err_msg_format)) {
  1923. i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
  1924. return -EINVAL;
  1925. } else {
  1926. return 0;
  1927. }
  1928. }
  1929. /**
  1930. * i40e_vc_process_vf_msg
  1931. * @pf: pointer to the PF structure
  1932. * @vf_id: source VF id
  1933. * @msg: pointer to the msg buffer
  1934. * @msglen: msg length
  1935. * @msghndl: msg handle
  1936. *
  1937. * called from the common aeq/arq handler to
  1938. * process request from VF
  1939. **/
  1940. int i40e_vc_process_vf_msg(struct i40e_pf *pf, u16 vf_id, u32 v_opcode,
  1941. u32 v_retval, u8 *msg, u16 msglen)
  1942. {
  1943. struct i40e_hw *hw = &pf->hw;
  1944. unsigned int local_vf_id = vf_id - hw->func_caps.vf_base_id;
  1945. struct i40e_vf *vf;
  1946. int ret;
  1947. pf->vf_aq_requests++;
  1948. if (local_vf_id >= pf->num_alloc_vfs)
  1949. return -EINVAL;
  1950. vf = &(pf->vf[local_vf_id]);
  1951. /* perform basic checks on the msg */
  1952. ret = i40e_vc_validate_vf_msg(vf, v_opcode, v_retval, msg, msglen);
  1953. if (ret) {
  1954. dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n",
  1955. local_vf_id, v_opcode, msglen);
  1956. return ret;
  1957. }
  1958. switch (v_opcode) {
  1959. case I40E_VIRTCHNL_OP_VERSION:
  1960. ret = i40e_vc_get_version_msg(vf, msg);
  1961. break;
  1962. case I40E_VIRTCHNL_OP_GET_VF_RESOURCES:
  1963. ret = i40e_vc_get_vf_resources_msg(vf, msg);
  1964. break;
  1965. case I40E_VIRTCHNL_OP_RESET_VF:
  1966. i40e_vc_reset_vf_msg(vf);
  1967. ret = 0;
  1968. break;
  1969. case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
  1970. ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
  1971. break;
  1972. case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
  1973. ret = i40e_vc_config_queues_msg(vf, msg, msglen);
  1974. break;
  1975. case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
  1976. ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
  1977. break;
  1978. case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
  1979. ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
  1980. i40e_vc_notify_vf_link_state(vf);
  1981. break;
  1982. case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
  1983. ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
  1984. break;
  1985. case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
  1986. ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
  1987. break;
  1988. case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
  1989. ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
  1990. break;
  1991. case I40E_VIRTCHNL_OP_ADD_VLAN:
  1992. ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
  1993. break;
  1994. case I40E_VIRTCHNL_OP_DEL_VLAN:
  1995. ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
  1996. break;
  1997. case I40E_VIRTCHNL_OP_GET_STATS:
  1998. ret = i40e_vc_get_stats_msg(vf, msg, msglen);
  1999. break;
  2000. case I40E_VIRTCHNL_OP_IWARP:
  2001. ret = i40e_vc_iwarp_msg(vf, msg, msglen);
  2002. break;
  2003. case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
  2004. ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, true);
  2005. break;
  2006. case I40E_VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
  2007. ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, false);
  2008. break;
  2009. case I40E_VIRTCHNL_OP_UNKNOWN:
  2010. default:
  2011. dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n",
  2012. v_opcode, local_vf_id);
  2013. ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
  2014. I40E_ERR_NOT_IMPLEMENTED);
  2015. break;
  2016. }
  2017. return ret;
  2018. }
  2019. /**
  2020. * i40e_vc_process_vflr_event
  2021. * @pf: pointer to the PF structure
  2022. *
  2023. * called from the vlfr irq handler to
  2024. * free up VF resources and state variables
  2025. **/
  2026. int i40e_vc_process_vflr_event(struct i40e_pf *pf)
  2027. {
  2028. u32 reg, reg_idx, bit_idx, vf_id;
  2029. struct i40e_hw *hw = &pf->hw;
  2030. struct i40e_vf *vf;
  2031. if (!test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
  2032. return 0;
  2033. /* Re-enable the VFLR interrupt cause here, before looking for which
  2034. * VF got reset. Otherwise, if another VF gets a reset while the
  2035. * first one is being processed, that interrupt will be lost, and
  2036. * that VF will be stuck in reset forever.
  2037. */
  2038. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  2039. reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
  2040. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  2041. i40e_flush(hw);
  2042. clear_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
  2043. for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
  2044. reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
  2045. bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
  2046. /* read GLGEN_VFLRSTAT register to find out the flr VFs */
  2047. vf = &pf->vf[vf_id];
  2048. reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
  2049. if (reg & BIT(bit_idx)) {
  2050. /* i40e_reset_vf will clear the bit in GLGEN_VFLRSTAT */
  2051. if (!test_bit(__I40E_DOWN, &pf->state))
  2052. i40e_reset_vf(vf, true);
  2053. }
  2054. }
  2055. return 0;
  2056. }
  2057. /**
  2058. * i40e_ndo_set_vf_mac
  2059. * @netdev: network interface device structure
  2060. * @vf_id: VF identifier
  2061. * @mac: mac address
  2062. *
  2063. * program VF mac address
  2064. **/
  2065. int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
  2066. {
  2067. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2068. struct i40e_vsi *vsi = np->vsi;
  2069. struct i40e_pf *pf = vsi->back;
  2070. struct i40e_mac_filter *f;
  2071. struct i40e_vf *vf;
  2072. int ret = 0;
  2073. /* validate the request */
  2074. if (vf_id >= pf->num_alloc_vfs) {
  2075. dev_err(&pf->pdev->dev,
  2076. "Invalid VF Identifier %d\n", vf_id);
  2077. ret = -EINVAL;
  2078. goto error_param;
  2079. }
  2080. vf = &(pf->vf[vf_id]);
  2081. vsi = pf->vsi[vf->lan_vsi_idx];
  2082. if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
  2083. dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
  2084. vf_id);
  2085. ret = -EAGAIN;
  2086. goto error_param;
  2087. }
  2088. if (is_multicast_ether_addr(mac)) {
  2089. dev_err(&pf->pdev->dev,
  2090. "Invalid Ethernet address %pM for VF %d\n", mac, vf_id);
  2091. ret = -EINVAL;
  2092. goto error_param;
  2093. }
  2094. /* Lock once because below invoked function add/del_filter requires
  2095. * mac_filter_list_lock to be held
  2096. */
  2097. spin_lock_bh(&vsi->mac_filter_list_lock);
  2098. /* delete the temporary mac address */
  2099. if (!is_zero_ether_addr(vf->default_lan_addr.addr))
  2100. i40e_del_filter(vsi, vf->default_lan_addr.addr,
  2101. vf->port_vlan_id ? vf->port_vlan_id : -1,
  2102. true, false);
  2103. /* Delete all the filters for this VSI - we're going to kill it
  2104. * anyway.
  2105. */
  2106. list_for_each_entry(f, &vsi->mac_filter_list, list)
  2107. i40e_del_filter(vsi, f->macaddr, f->vlan, true, false);
  2108. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2109. dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n", mac, vf_id);
  2110. /* program mac filter */
  2111. if (i40e_sync_vsi_filters(vsi)) {
  2112. dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
  2113. ret = -EIO;
  2114. goto error_param;
  2115. }
  2116. ether_addr_copy(vf->default_lan_addr.addr, mac);
  2117. vf->pf_set_mac = true;
  2118. /* Force the VF driver stop so it has to reload with new MAC address */
  2119. i40e_vc_disable_vf(pf, vf);
  2120. dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
  2121. error_param:
  2122. return ret;
  2123. }
  2124. /**
  2125. * i40e_ndo_set_vf_port_vlan
  2126. * @netdev: network interface device structure
  2127. * @vf_id: VF identifier
  2128. * @vlan_id: mac address
  2129. * @qos: priority setting
  2130. *
  2131. * program VF vlan id and/or qos
  2132. **/
  2133. int i40e_ndo_set_vf_port_vlan(struct net_device *netdev,
  2134. int vf_id, u16 vlan_id, u8 qos)
  2135. {
  2136. u16 vlanprio = vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT);
  2137. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2138. struct i40e_pf *pf = np->vsi->back;
  2139. bool is_vsi_in_vlan = false;
  2140. struct i40e_vsi *vsi;
  2141. struct i40e_vf *vf;
  2142. int ret = 0;
  2143. /* validate the request */
  2144. if (vf_id >= pf->num_alloc_vfs) {
  2145. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
  2146. ret = -EINVAL;
  2147. goto error_pvid;
  2148. }
  2149. if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
  2150. dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
  2151. ret = -EINVAL;
  2152. goto error_pvid;
  2153. }
  2154. vf = &(pf->vf[vf_id]);
  2155. vsi = pf->vsi[vf->lan_vsi_idx];
  2156. if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
  2157. dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
  2158. vf_id);
  2159. ret = -EAGAIN;
  2160. goto error_pvid;
  2161. }
  2162. if (le16_to_cpu(vsi->info.pvid) == vlanprio)
  2163. /* duplicate request, so just return success */
  2164. goto error_pvid;
  2165. spin_lock_bh(&vsi->mac_filter_list_lock);
  2166. is_vsi_in_vlan = i40e_is_vsi_in_vlan(vsi);
  2167. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2168. if (le16_to_cpu(vsi->info.pvid) == 0 && is_vsi_in_vlan) {
  2169. dev_err(&pf->pdev->dev,
  2170. "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",
  2171. vf_id);
  2172. /* Administrator Error - knock the VF offline until he does
  2173. * the right thing by reconfiguring his network correctly
  2174. * and then reloading the VF driver.
  2175. */
  2176. i40e_vc_disable_vf(pf, vf);
  2177. /* During reset the VF got a new VSI, so refresh the pointer. */
  2178. vsi = pf->vsi[vf->lan_vsi_idx];
  2179. }
  2180. /* Check for condition where there was already a port VLAN ID
  2181. * filter set and now it is being deleted by setting it to zero.
  2182. * Additionally check for the condition where there was a port
  2183. * VLAN but now there is a new and different port VLAN being set.
  2184. * Before deleting all the old VLAN filters we must add new ones
  2185. * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
  2186. * MAC addresses deleted.
  2187. */
  2188. if ((!(vlan_id || qos) ||
  2189. vlanprio != le16_to_cpu(vsi->info.pvid)) &&
  2190. vsi->info.pvid)
  2191. ret = i40e_vsi_add_vlan(vsi, I40E_VLAN_ANY);
  2192. if (vsi->info.pvid) {
  2193. /* kill old VLAN */
  2194. ret = i40e_vsi_kill_vlan(vsi, (le16_to_cpu(vsi->info.pvid) &
  2195. VLAN_VID_MASK));
  2196. if (ret) {
  2197. dev_info(&vsi->back->pdev->dev,
  2198. "remove VLAN failed, ret=%d, aq_err=%d\n",
  2199. ret, pf->hw.aq.asq_last_status);
  2200. }
  2201. }
  2202. if (vlan_id || qos)
  2203. ret = i40e_vsi_add_pvid(vsi, vlanprio);
  2204. else
  2205. i40e_vsi_remove_pvid(vsi);
  2206. if (vlan_id) {
  2207. dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
  2208. vlan_id, qos, vf_id);
  2209. /* add new VLAN filter */
  2210. ret = i40e_vsi_add_vlan(vsi, vlan_id);
  2211. if (ret) {
  2212. dev_info(&vsi->back->pdev->dev,
  2213. "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
  2214. vsi->back->hw.aq.asq_last_status);
  2215. goto error_pvid;
  2216. }
  2217. /* Kill non-vlan MAC filters - ignore error return since
  2218. * there might not be any non-vlan MAC filters.
  2219. */
  2220. i40e_vsi_kill_vlan(vsi, I40E_VLAN_ANY);
  2221. }
  2222. if (ret) {
  2223. dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
  2224. goto error_pvid;
  2225. }
  2226. /* The Port VLAN needs to be saved across resets the same as the
  2227. * default LAN MAC address.
  2228. */
  2229. vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
  2230. ret = 0;
  2231. error_pvid:
  2232. return ret;
  2233. }
  2234. #define I40E_BW_CREDIT_DIVISOR 50 /* 50Mbps per BW credit */
  2235. #define I40E_MAX_BW_INACTIVE_ACCUM 4 /* device can accumulate 4 credits max */
  2236. /**
  2237. * i40e_ndo_set_vf_bw
  2238. * @netdev: network interface device structure
  2239. * @vf_id: VF identifier
  2240. * @tx_rate: Tx rate
  2241. *
  2242. * configure VF Tx rate
  2243. **/
  2244. int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
  2245. int max_tx_rate)
  2246. {
  2247. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2248. struct i40e_pf *pf = np->vsi->back;
  2249. struct i40e_vsi *vsi;
  2250. struct i40e_vf *vf;
  2251. int speed = 0;
  2252. int ret = 0;
  2253. /* validate the request */
  2254. if (vf_id >= pf->num_alloc_vfs) {
  2255. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
  2256. ret = -EINVAL;
  2257. goto error;
  2258. }
  2259. if (min_tx_rate) {
  2260. dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
  2261. min_tx_rate, vf_id);
  2262. return -EINVAL;
  2263. }
  2264. vf = &(pf->vf[vf_id]);
  2265. vsi = pf->vsi[vf->lan_vsi_idx];
  2266. if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
  2267. dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
  2268. vf_id);
  2269. ret = -EAGAIN;
  2270. goto error;
  2271. }
  2272. switch (pf->hw.phy.link_info.link_speed) {
  2273. case I40E_LINK_SPEED_40GB:
  2274. speed = 40000;
  2275. break;
  2276. case I40E_LINK_SPEED_20GB:
  2277. speed = 20000;
  2278. break;
  2279. case I40E_LINK_SPEED_10GB:
  2280. speed = 10000;
  2281. break;
  2282. case I40E_LINK_SPEED_1GB:
  2283. speed = 1000;
  2284. break;
  2285. default:
  2286. break;
  2287. }
  2288. if (max_tx_rate > speed) {
  2289. dev_err(&pf->pdev->dev, "Invalid max tx rate %d specified for VF %d.",
  2290. max_tx_rate, vf->vf_id);
  2291. ret = -EINVAL;
  2292. goto error;
  2293. }
  2294. if ((max_tx_rate < 50) && (max_tx_rate > 0)) {
  2295. dev_warn(&pf->pdev->dev, "Setting max Tx rate to minimum usable value of 50Mbps.\n");
  2296. max_tx_rate = 50;
  2297. }
  2298. /* Tx rate credits are in values of 50Mbps, 0 is disabled*/
  2299. ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
  2300. max_tx_rate / I40E_BW_CREDIT_DIVISOR,
  2301. I40E_MAX_BW_INACTIVE_ACCUM, NULL);
  2302. if (ret) {
  2303. dev_err(&pf->pdev->dev, "Unable to set max tx rate, error code %d.\n",
  2304. ret);
  2305. ret = -EIO;
  2306. goto error;
  2307. }
  2308. vf->tx_rate = max_tx_rate;
  2309. error:
  2310. return ret;
  2311. }
  2312. /**
  2313. * i40e_ndo_get_vf_config
  2314. * @netdev: network interface device structure
  2315. * @vf_id: VF identifier
  2316. * @ivi: VF configuration structure
  2317. *
  2318. * return VF configuration
  2319. **/
  2320. int i40e_ndo_get_vf_config(struct net_device *netdev,
  2321. int vf_id, struct ifla_vf_info *ivi)
  2322. {
  2323. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2324. struct i40e_vsi *vsi = np->vsi;
  2325. struct i40e_pf *pf = vsi->back;
  2326. struct i40e_vf *vf;
  2327. int ret = 0;
  2328. /* validate the request */
  2329. if (vf_id >= pf->num_alloc_vfs) {
  2330. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
  2331. ret = -EINVAL;
  2332. goto error_param;
  2333. }
  2334. vf = &(pf->vf[vf_id]);
  2335. /* first vsi is always the LAN vsi */
  2336. vsi = pf->vsi[vf->lan_vsi_idx];
  2337. if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
  2338. dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
  2339. vf_id);
  2340. ret = -EAGAIN;
  2341. goto error_param;
  2342. }
  2343. ivi->vf = vf_id;
  2344. ether_addr_copy(ivi->mac, vf->default_lan_addr.addr);
  2345. ivi->max_tx_rate = vf->tx_rate;
  2346. ivi->min_tx_rate = 0;
  2347. ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
  2348. ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
  2349. I40E_VLAN_PRIORITY_SHIFT;
  2350. if (vf->link_forced == false)
  2351. ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
  2352. else if (vf->link_up == true)
  2353. ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
  2354. else
  2355. ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
  2356. ivi->spoofchk = vf->spoofchk;
  2357. ret = 0;
  2358. error_param:
  2359. return ret;
  2360. }
  2361. /**
  2362. * i40e_ndo_set_vf_link_state
  2363. * @netdev: network interface device structure
  2364. * @vf_id: VF identifier
  2365. * @link: required link state
  2366. *
  2367. * Set the link state of a specified VF, regardless of physical link state
  2368. **/
  2369. int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
  2370. {
  2371. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2372. struct i40e_pf *pf = np->vsi->back;
  2373. struct i40e_virtchnl_pf_event pfe;
  2374. struct i40e_hw *hw = &pf->hw;
  2375. struct i40e_vf *vf;
  2376. int abs_vf_id;
  2377. int ret = 0;
  2378. /* validate the request */
  2379. if (vf_id >= pf->num_alloc_vfs) {
  2380. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
  2381. ret = -EINVAL;
  2382. goto error_out;
  2383. }
  2384. vf = &pf->vf[vf_id];
  2385. abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
  2386. pfe.event = I40E_VIRTCHNL_EVENT_LINK_CHANGE;
  2387. pfe.severity = I40E_PF_EVENT_SEVERITY_INFO;
  2388. switch (link) {
  2389. case IFLA_VF_LINK_STATE_AUTO:
  2390. vf->link_forced = false;
  2391. pfe.event_data.link_event.link_status =
  2392. pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
  2393. pfe.event_data.link_event.link_speed =
  2394. pf->hw.phy.link_info.link_speed;
  2395. break;
  2396. case IFLA_VF_LINK_STATE_ENABLE:
  2397. vf->link_forced = true;
  2398. vf->link_up = true;
  2399. pfe.event_data.link_event.link_status = true;
  2400. pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
  2401. break;
  2402. case IFLA_VF_LINK_STATE_DISABLE:
  2403. vf->link_forced = true;
  2404. vf->link_up = false;
  2405. pfe.event_data.link_event.link_status = false;
  2406. pfe.event_data.link_event.link_speed = 0;
  2407. break;
  2408. default:
  2409. ret = -EINVAL;
  2410. goto error_out;
  2411. }
  2412. /* Notify the VF of its new link state */
  2413. i40e_aq_send_msg_to_vf(hw, abs_vf_id, I40E_VIRTCHNL_OP_EVENT,
  2414. 0, (u8 *)&pfe, sizeof(pfe), NULL);
  2415. error_out:
  2416. return ret;
  2417. }
  2418. /**
  2419. * i40e_ndo_set_vf_spoofchk
  2420. * @netdev: network interface device structure
  2421. * @vf_id: VF identifier
  2422. * @enable: flag to enable or disable feature
  2423. *
  2424. * Enable or disable VF spoof checking
  2425. **/
  2426. int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
  2427. {
  2428. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2429. struct i40e_vsi *vsi = np->vsi;
  2430. struct i40e_pf *pf = vsi->back;
  2431. struct i40e_vsi_context ctxt;
  2432. struct i40e_hw *hw = &pf->hw;
  2433. struct i40e_vf *vf;
  2434. int ret = 0;
  2435. /* validate the request */
  2436. if (vf_id >= pf->num_alloc_vfs) {
  2437. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
  2438. ret = -EINVAL;
  2439. goto out;
  2440. }
  2441. vf = &(pf->vf[vf_id]);
  2442. if (!test_bit(I40E_VF_STAT_INIT, &vf->vf_states)) {
  2443. dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
  2444. vf_id);
  2445. ret = -EAGAIN;
  2446. goto out;
  2447. }
  2448. if (enable == vf->spoofchk)
  2449. goto out;
  2450. vf->spoofchk = enable;
  2451. memset(&ctxt, 0, sizeof(ctxt));
  2452. ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid;
  2453. ctxt.pf_num = pf->hw.pf_id;
  2454. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
  2455. if (enable)
  2456. ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
  2457. I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
  2458. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  2459. if (ret) {
  2460. dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",
  2461. ret);
  2462. ret = -EIO;
  2463. }
  2464. out:
  2465. return ret;
  2466. }