i40e_virtchnl_pf.c 84 KB

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