i40e_virtchnl_pf.c 84 KB

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