i40e_virtchnl_pf.c 85 KB

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