i40e_virtchnl_pf.c 85 KB

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