i40e_virtchnl_pf.c 75 KB

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