bnx2x_sriov.c 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140
  1. /* bnx2x_sriov.c: Broadcom Everest network driver.
  2. *
  3. * Copyright 2009-2013 Broadcom Corporation
  4. *
  5. * Unless you and Broadcom execute a separate written software license
  6. * agreement governing use of this software, this software is licensed to you
  7. * under the terms of the GNU General Public License version 2, available
  8. * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
  9. *
  10. * Notwithstanding the above, under no circumstances may you combine this
  11. * software in any way with any other Broadcom software provided under a
  12. * license other than the GPL, without Broadcom's express prior written
  13. * consent.
  14. *
  15. * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
  16. * Written by: Shmulik Ravid
  17. * Ariel Elior <ariel.elior@qlogic.com>
  18. *
  19. */
  20. #include "bnx2x.h"
  21. #include "bnx2x_init.h"
  22. #include "bnx2x_cmn.h"
  23. #include "bnx2x_sp.h"
  24. #include <linux/crc32.h>
  25. #include <linux/if_vlan.h>
  26. static int bnx2x_vf_op_prep(struct bnx2x *bp, int vfidx,
  27. struct bnx2x_virtf **vf,
  28. struct pf_vf_bulletin_content **bulletin,
  29. bool test_queue);
  30. /* General service functions */
  31. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  32. u16 pf_id)
  33. {
  34. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  35. pf_id);
  36. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  37. pf_id);
  38. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  39. pf_id);
  40. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  41. pf_id);
  42. }
  43. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  44. u8 enable)
  45. {
  46. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  47. enable);
  48. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  49. enable);
  50. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  51. enable);
  52. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  53. enable);
  54. }
  55. int bnx2x_vf_idx_by_abs_fid(struct bnx2x *bp, u16 abs_vfid)
  56. {
  57. int idx;
  58. for_each_vf(bp, idx)
  59. if (bnx2x_vf(bp, idx, abs_vfid) == abs_vfid)
  60. break;
  61. return idx;
  62. }
  63. static
  64. struct bnx2x_virtf *bnx2x_vf_by_abs_fid(struct bnx2x *bp, u16 abs_vfid)
  65. {
  66. u16 idx = (u16)bnx2x_vf_idx_by_abs_fid(bp, abs_vfid);
  67. return (idx < BNX2X_NR_VIRTFN(bp)) ? BP_VF(bp, idx) : NULL;
  68. }
  69. static void bnx2x_vf_igu_ack_sb(struct bnx2x *bp, struct bnx2x_virtf *vf,
  70. u8 igu_sb_id, u8 segment, u16 index, u8 op,
  71. u8 update)
  72. {
  73. /* acking a VF sb through the PF - use the GRC */
  74. u32 ctl;
  75. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  76. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  77. u32 func_encode = vf->abs_vfid;
  78. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + igu_sb_id;
  79. struct igu_regular cmd_data = {0};
  80. cmd_data.sb_id_and_flags =
  81. ((index << IGU_REGULAR_SB_INDEX_SHIFT) |
  82. (segment << IGU_REGULAR_SEGMENT_ACCESS_SHIFT) |
  83. (update << IGU_REGULAR_BUPDATE_SHIFT) |
  84. (op << IGU_REGULAR_ENABLE_INT_SHIFT));
  85. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  86. func_encode << IGU_CTRL_REG_FID_SHIFT |
  87. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  88. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  89. cmd_data.sb_id_and_flags, igu_addr_data);
  90. REG_WR(bp, igu_addr_data, cmd_data.sb_id_and_flags);
  91. mmiowb();
  92. barrier();
  93. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  94. ctl, igu_addr_ctl);
  95. REG_WR(bp, igu_addr_ctl, ctl);
  96. mmiowb();
  97. barrier();
  98. }
  99. static bool bnx2x_validate_vf_sp_objs(struct bnx2x *bp,
  100. struct bnx2x_virtf *vf,
  101. bool print_err)
  102. {
  103. if (!bnx2x_leading_vfq(vf, sp_initialized)) {
  104. if (print_err)
  105. BNX2X_ERR("Slowpath objects not yet initialized!\n");
  106. else
  107. DP(BNX2X_MSG_IOV, "Slowpath objects not yet initialized!\n");
  108. return false;
  109. }
  110. return true;
  111. }
  112. /* VFOP operations states */
  113. void bnx2x_vfop_qctor_dump_tx(struct bnx2x *bp, struct bnx2x_virtf *vf,
  114. struct bnx2x_queue_init_params *init_params,
  115. struct bnx2x_queue_setup_params *setup_params,
  116. u16 q_idx, u16 sb_idx)
  117. {
  118. DP(BNX2X_MSG_IOV,
  119. "VF[%d] Q_SETUP: txq[%d]-- vfsb=%d, sb-index=%d, hc-rate=%d, flags=0x%lx, traffic-type=%d",
  120. vf->abs_vfid,
  121. q_idx,
  122. sb_idx,
  123. init_params->tx.sb_cq_index,
  124. init_params->tx.hc_rate,
  125. setup_params->flags,
  126. setup_params->txq_params.traffic_type);
  127. }
  128. void bnx2x_vfop_qctor_dump_rx(struct bnx2x *bp, struct bnx2x_virtf *vf,
  129. struct bnx2x_queue_init_params *init_params,
  130. struct bnx2x_queue_setup_params *setup_params,
  131. u16 q_idx, u16 sb_idx)
  132. {
  133. struct bnx2x_rxq_setup_params *rxq_params = &setup_params->rxq_params;
  134. DP(BNX2X_MSG_IOV, "VF[%d] Q_SETUP: rxq[%d]-- vfsb=%d, sb-index=%d, hc-rate=%d, mtu=%d, buf-size=%d\n"
  135. "sge-size=%d, max_sge_pkt=%d, tpa-agg-size=%d, flags=0x%lx, drop-flags=0x%x, cache-log=%d\n",
  136. vf->abs_vfid,
  137. q_idx,
  138. sb_idx,
  139. init_params->rx.sb_cq_index,
  140. init_params->rx.hc_rate,
  141. setup_params->gen_params.mtu,
  142. rxq_params->buf_sz,
  143. rxq_params->sge_buf_sz,
  144. rxq_params->max_sges_pkt,
  145. rxq_params->tpa_agg_sz,
  146. setup_params->flags,
  147. rxq_params->drop_flags,
  148. rxq_params->cache_line_log);
  149. }
  150. void bnx2x_vfop_qctor_prep(struct bnx2x *bp,
  151. struct bnx2x_virtf *vf,
  152. struct bnx2x_vf_queue *q,
  153. struct bnx2x_vf_queue_construct_params *p,
  154. unsigned long q_type)
  155. {
  156. struct bnx2x_queue_init_params *init_p = &p->qstate.params.init;
  157. struct bnx2x_queue_setup_params *setup_p = &p->prep_qsetup;
  158. /* INIT */
  159. /* Enable host coalescing in the transition to INIT state */
  160. if (test_bit(BNX2X_Q_FLG_HC, &init_p->rx.flags))
  161. __set_bit(BNX2X_Q_FLG_HC_EN, &init_p->rx.flags);
  162. if (test_bit(BNX2X_Q_FLG_HC, &init_p->tx.flags))
  163. __set_bit(BNX2X_Q_FLG_HC_EN, &init_p->tx.flags);
  164. /* FW SB ID */
  165. init_p->rx.fw_sb_id = vf_igu_sb(vf, q->sb_idx);
  166. init_p->tx.fw_sb_id = vf_igu_sb(vf, q->sb_idx);
  167. /* context */
  168. init_p->cxts[0] = q->cxt;
  169. /* SETUP */
  170. /* Setup-op general parameters */
  171. setup_p->gen_params.spcl_id = vf->sp_cl_id;
  172. setup_p->gen_params.stat_id = vfq_stat_id(vf, q);
  173. setup_p->gen_params.fp_hsi = vf->fp_hsi;
  174. /* Setup-op pause params:
  175. * Nothing to do, the pause thresholds are set by default to 0 which
  176. * effectively turns off the feature for this queue. We don't want
  177. * one queue (VF) to interfering with another queue (another VF)
  178. */
  179. if (vf->cfg_flags & VF_CFG_FW_FC)
  180. BNX2X_ERR("No support for pause to VFs (abs_vfid: %d)\n",
  181. vf->abs_vfid);
  182. /* Setup-op flags:
  183. * collect statistics, zero statistics, local-switching, security,
  184. * OV for Flex10, RSS and MCAST for leading
  185. */
  186. if (test_bit(BNX2X_Q_FLG_STATS, &setup_p->flags))
  187. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &setup_p->flags);
  188. /* for VFs, enable tx switching, bd coherency, and mac address
  189. * anti-spoofing
  190. */
  191. __set_bit(BNX2X_Q_FLG_TX_SWITCH, &setup_p->flags);
  192. __set_bit(BNX2X_Q_FLG_TX_SEC, &setup_p->flags);
  193. __set_bit(BNX2X_Q_FLG_ANTI_SPOOF, &setup_p->flags);
  194. /* Setup-op rx parameters */
  195. if (test_bit(BNX2X_Q_TYPE_HAS_RX, &q_type)) {
  196. struct bnx2x_rxq_setup_params *rxq_p = &setup_p->rxq_params;
  197. rxq_p->cl_qzone_id = vfq_qzone_id(vf, q);
  198. rxq_p->fw_sb_id = vf_igu_sb(vf, q->sb_idx);
  199. rxq_p->rss_engine_id = FW_VF_HANDLE(vf->abs_vfid);
  200. if (test_bit(BNX2X_Q_FLG_TPA, &setup_p->flags))
  201. rxq_p->max_tpa_queues = BNX2X_VF_MAX_TPA_AGG_QUEUES;
  202. }
  203. /* Setup-op tx parameters */
  204. if (test_bit(BNX2X_Q_TYPE_HAS_TX, &q_type)) {
  205. setup_p->txq_params.tss_leading_cl_id = vf->leading_rss;
  206. setup_p->txq_params.fw_sb_id = vf_igu_sb(vf, q->sb_idx);
  207. }
  208. }
  209. static int bnx2x_vf_queue_create(struct bnx2x *bp,
  210. struct bnx2x_virtf *vf, int qid,
  211. struct bnx2x_vf_queue_construct_params *qctor)
  212. {
  213. struct bnx2x_queue_state_params *q_params;
  214. int rc = 0;
  215. DP(BNX2X_MSG_IOV, "vf[%d:%d]\n", vf->abs_vfid, qid);
  216. /* Prepare ramrod information */
  217. q_params = &qctor->qstate;
  218. q_params->q_obj = &bnx2x_vfq(vf, qid, sp_obj);
  219. set_bit(RAMROD_COMP_WAIT, &q_params->ramrod_flags);
  220. if (bnx2x_get_q_logical_state(bp, q_params->q_obj) ==
  221. BNX2X_Q_LOGICAL_STATE_ACTIVE) {
  222. DP(BNX2X_MSG_IOV, "queue was already up. Aborting gracefully\n");
  223. goto out;
  224. }
  225. /* Run Queue 'construction' ramrods */
  226. q_params->cmd = BNX2X_Q_CMD_INIT;
  227. rc = bnx2x_queue_state_change(bp, q_params);
  228. if (rc)
  229. goto out;
  230. memcpy(&q_params->params.setup, &qctor->prep_qsetup,
  231. sizeof(struct bnx2x_queue_setup_params));
  232. q_params->cmd = BNX2X_Q_CMD_SETUP;
  233. rc = bnx2x_queue_state_change(bp, q_params);
  234. if (rc)
  235. goto out;
  236. /* enable interrupts */
  237. bnx2x_vf_igu_ack_sb(bp, vf, vf_igu_sb(vf, bnx2x_vfq(vf, qid, sb_idx)),
  238. USTORM_ID, 0, IGU_INT_ENABLE, 0);
  239. out:
  240. return rc;
  241. }
  242. static int bnx2x_vf_queue_destroy(struct bnx2x *bp, struct bnx2x_virtf *vf,
  243. int qid)
  244. {
  245. enum bnx2x_queue_cmd cmds[] = {BNX2X_Q_CMD_HALT,
  246. BNX2X_Q_CMD_TERMINATE,
  247. BNX2X_Q_CMD_CFC_DEL};
  248. struct bnx2x_queue_state_params q_params;
  249. int rc, i;
  250. DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid);
  251. /* Prepare ramrod information */
  252. memset(&q_params, 0, sizeof(struct bnx2x_queue_state_params));
  253. q_params.q_obj = &bnx2x_vfq(vf, qid, sp_obj);
  254. set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  255. if (bnx2x_get_q_logical_state(bp, q_params.q_obj) ==
  256. BNX2X_Q_LOGICAL_STATE_STOPPED) {
  257. DP(BNX2X_MSG_IOV, "queue was already stopped. Aborting gracefully\n");
  258. goto out;
  259. }
  260. /* Run Queue 'destruction' ramrods */
  261. for (i = 0; i < ARRAY_SIZE(cmds); i++) {
  262. q_params.cmd = cmds[i];
  263. rc = bnx2x_queue_state_change(bp, &q_params);
  264. if (rc) {
  265. BNX2X_ERR("Failed to run Queue command %d\n", cmds[i]);
  266. return rc;
  267. }
  268. }
  269. out:
  270. /* Clean Context */
  271. if (bnx2x_vfq(vf, qid, cxt)) {
  272. bnx2x_vfq(vf, qid, cxt)->ustorm_ag_context.cdu_usage = 0;
  273. bnx2x_vfq(vf, qid, cxt)->xstorm_ag_context.cdu_reserved = 0;
  274. }
  275. return 0;
  276. }
  277. static void
  278. bnx2x_vf_set_igu_info(struct bnx2x *bp, u8 igu_sb_id, u8 abs_vfid)
  279. {
  280. struct bnx2x_virtf *vf = bnx2x_vf_by_abs_fid(bp, abs_vfid);
  281. if (vf) {
  282. /* the first igu entry belonging to VFs of this PF */
  283. if (!BP_VFDB(bp)->first_vf_igu_entry)
  284. BP_VFDB(bp)->first_vf_igu_entry = igu_sb_id;
  285. /* the first igu entry belonging to this VF */
  286. if (!vf_sb_count(vf))
  287. vf->igu_base_id = igu_sb_id;
  288. ++vf_sb_count(vf);
  289. ++vf->sb_count;
  290. }
  291. BP_VFDB(bp)->vf_sbs_pool++;
  292. }
  293. static inline void bnx2x_vf_vlan_credit(struct bnx2x *bp,
  294. struct bnx2x_vlan_mac_obj *obj,
  295. atomic_t *counter)
  296. {
  297. struct list_head *pos;
  298. int read_lock;
  299. int cnt = 0;
  300. read_lock = bnx2x_vlan_mac_h_read_lock(bp, obj);
  301. if (read_lock)
  302. DP(BNX2X_MSG_SP, "Failed to take vlan mac read head; continuing anyway\n");
  303. list_for_each(pos, &obj->head)
  304. cnt++;
  305. if (!read_lock)
  306. bnx2x_vlan_mac_h_read_unlock(bp, obj);
  307. atomic_set(counter, cnt);
  308. }
  309. static int bnx2x_vf_vlan_mac_clear(struct bnx2x *bp, struct bnx2x_virtf *vf,
  310. int qid, bool drv_only, bool mac)
  311. {
  312. struct bnx2x_vlan_mac_ramrod_params ramrod;
  313. int rc;
  314. DP(BNX2X_MSG_IOV, "vf[%d] - deleting all %s\n", vf->abs_vfid,
  315. mac ? "MACs" : "VLANs");
  316. /* Prepare ramrod params */
  317. memset(&ramrod, 0, sizeof(struct bnx2x_vlan_mac_ramrod_params));
  318. if (mac) {
  319. set_bit(BNX2X_ETH_MAC, &ramrod.user_req.vlan_mac_flags);
  320. ramrod.vlan_mac_obj = &bnx2x_vfq(vf, qid, mac_obj);
  321. } else {
  322. set_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
  323. &ramrod.user_req.vlan_mac_flags);
  324. ramrod.vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_obj);
  325. }
  326. ramrod.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  327. set_bit(RAMROD_EXEC, &ramrod.ramrod_flags);
  328. if (drv_only)
  329. set_bit(RAMROD_DRV_CLR_ONLY, &ramrod.ramrod_flags);
  330. else
  331. set_bit(RAMROD_COMP_WAIT, &ramrod.ramrod_flags);
  332. /* Start deleting */
  333. rc = ramrod.vlan_mac_obj->delete_all(bp,
  334. ramrod.vlan_mac_obj,
  335. &ramrod.user_req.vlan_mac_flags,
  336. &ramrod.ramrod_flags);
  337. if (rc) {
  338. BNX2X_ERR("Failed to delete all %s\n",
  339. mac ? "MACs" : "VLANs");
  340. return rc;
  341. }
  342. /* Clear the vlan counters */
  343. if (!mac)
  344. atomic_set(&bnx2x_vfq(vf, qid, vlan_count), 0);
  345. return 0;
  346. }
  347. static int bnx2x_vf_mac_vlan_config(struct bnx2x *bp,
  348. struct bnx2x_virtf *vf, int qid,
  349. struct bnx2x_vf_mac_vlan_filter *filter,
  350. bool drv_only)
  351. {
  352. struct bnx2x_vlan_mac_ramrod_params ramrod;
  353. int rc;
  354. DP(BNX2X_MSG_IOV, "vf[%d] - %s a %s filter\n",
  355. vf->abs_vfid, filter->add ? "Adding" : "Deleting",
  356. filter->type == BNX2X_VF_FILTER_MAC ? "MAC" : "VLAN");
  357. /* Prepare ramrod params */
  358. memset(&ramrod, 0, sizeof(struct bnx2x_vlan_mac_ramrod_params));
  359. if (filter->type == BNX2X_VF_FILTER_VLAN) {
  360. set_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
  361. &ramrod.user_req.vlan_mac_flags);
  362. ramrod.vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_obj);
  363. ramrod.user_req.u.vlan.vlan = filter->vid;
  364. } else {
  365. set_bit(BNX2X_ETH_MAC, &ramrod.user_req.vlan_mac_flags);
  366. ramrod.vlan_mac_obj = &bnx2x_vfq(vf, qid, mac_obj);
  367. memcpy(&ramrod.user_req.u.mac.mac, filter->mac, ETH_ALEN);
  368. }
  369. ramrod.user_req.cmd = filter->add ? BNX2X_VLAN_MAC_ADD :
  370. BNX2X_VLAN_MAC_DEL;
  371. /* Verify there are available vlan credits */
  372. if (filter->add && filter->type == BNX2X_VF_FILTER_VLAN &&
  373. (atomic_read(&bnx2x_vfq(vf, qid, vlan_count)) >=
  374. vf_vlan_rules_cnt(vf))) {
  375. BNX2X_ERR("No credits for vlan [%d >= %d]\n",
  376. atomic_read(&bnx2x_vfq(vf, qid, vlan_count)),
  377. vf_vlan_rules_cnt(vf));
  378. return -ENOMEM;
  379. }
  380. set_bit(RAMROD_EXEC, &ramrod.ramrod_flags);
  381. if (drv_only)
  382. set_bit(RAMROD_DRV_CLR_ONLY, &ramrod.ramrod_flags);
  383. else
  384. set_bit(RAMROD_COMP_WAIT, &ramrod.ramrod_flags);
  385. /* Add/Remove the filter */
  386. rc = bnx2x_config_vlan_mac(bp, &ramrod);
  387. if (rc && rc != -EEXIST) {
  388. BNX2X_ERR("Failed to %s %s\n",
  389. filter->add ? "add" : "delete",
  390. filter->type == BNX2X_VF_FILTER_MAC ? "MAC" :
  391. "VLAN");
  392. return rc;
  393. }
  394. /* Update the vlan counters */
  395. if (filter->type == BNX2X_VF_FILTER_VLAN)
  396. bnx2x_vf_vlan_credit(bp, ramrod.vlan_mac_obj,
  397. &bnx2x_vfq(vf, qid, vlan_count));
  398. return 0;
  399. }
  400. int bnx2x_vf_mac_vlan_config_list(struct bnx2x *bp, struct bnx2x_virtf *vf,
  401. struct bnx2x_vf_mac_vlan_filters *filters,
  402. int qid, bool drv_only)
  403. {
  404. int rc = 0, i;
  405. DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid);
  406. if (!bnx2x_validate_vf_sp_objs(bp, vf, true))
  407. return -EINVAL;
  408. /* Prepare ramrod params */
  409. for (i = 0; i < filters->count; i++) {
  410. rc = bnx2x_vf_mac_vlan_config(bp, vf, qid,
  411. &filters->filters[i], drv_only);
  412. if (rc)
  413. break;
  414. }
  415. /* Rollback if needed */
  416. if (i != filters->count) {
  417. BNX2X_ERR("Managed only %d/%d filters - rolling back\n",
  418. i, filters->count + 1);
  419. while (--i >= 0) {
  420. filters->filters[i].add = !filters->filters[i].add;
  421. bnx2x_vf_mac_vlan_config(bp, vf, qid,
  422. &filters->filters[i],
  423. drv_only);
  424. }
  425. }
  426. /* It's our responsibility to free the filters */
  427. kfree(filters);
  428. return rc;
  429. }
  430. int bnx2x_vf_queue_setup(struct bnx2x *bp, struct bnx2x_virtf *vf, int qid,
  431. struct bnx2x_vf_queue_construct_params *qctor)
  432. {
  433. int rc;
  434. DP(BNX2X_MSG_IOV, "vf[%d:%d]\n", vf->abs_vfid, qid);
  435. rc = bnx2x_vf_queue_create(bp, vf, qid, qctor);
  436. if (rc)
  437. goto op_err;
  438. /* Configure vlan0 for leading queue */
  439. if (!qid) {
  440. struct bnx2x_vf_mac_vlan_filter filter;
  441. memset(&filter, 0, sizeof(struct bnx2x_vf_mac_vlan_filter));
  442. filter.type = BNX2X_VF_FILTER_VLAN;
  443. filter.add = true;
  444. filter.vid = 0;
  445. rc = bnx2x_vf_mac_vlan_config(bp, vf, qid, &filter, false);
  446. if (rc)
  447. goto op_err;
  448. }
  449. /* Schedule the configuration of any pending vlan filters */
  450. vf->cfg_flags |= VF_CFG_VLAN;
  451. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  452. BNX2X_MSG_IOV);
  453. return 0;
  454. op_err:
  455. BNX2X_ERR("QSETUP[%d:%d] error: rc %d\n", vf->abs_vfid, qid, rc);
  456. return rc;
  457. }
  458. static int bnx2x_vf_queue_flr(struct bnx2x *bp, struct bnx2x_virtf *vf,
  459. int qid)
  460. {
  461. int rc;
  462. DP(BNX2X_MSG_IOV, "vf[%d:%d]\n", vf->abs_vfid, qid);
  463. /* If needed, clean the filtering data base */
  464. if ((qid == LEADING_IDX) &&
  465. bnx2x_validate_vf_sp_objs(bp, vf, false)) {
  466. rc = bnx2x_vf_vlan_mac_clear(bp, vf, qid, true, false);
  467. if (rc)
  468. goto op_err;
  469. rc = bnx2x_vf_vlan_mac_clear(bp, vf, qid, true, true);
  470. if (rc)
  471. goto op_err;
  472. }
  473. /* Terminate queue */
  474. if (bnx2x_vfq(vf, qid, sp_obj).state != BNX2X_Q_STATE_RESET) {
  475. struct bnx2x_queue_state_params qstate;
  476. memset(&qstate, 0, sizeof(struct bnx2x_queue_state_params));
  477. qstate.q_obj = &bnx2x_vfq(vf, qid, sp_obj);
  478. qstate.q_obj->state = BNX2X_Q_STATE_STOPPED;
  479. qstate.cmd = BNX2X_Q_CMD_TERMINATE;
  480. set_bit(RAMROD_COMP_WAIT, &qstate.ramrod_flags);
  481. rc = bnx2x_queue_state_change(bp, &qstate);
  482. if (rc)
  483. goto op_err;
  484. }
  485. return 0;
  486. op_err:
  487. BNX2X_ERR("vf[%d:%d] error: rc %d\n", vf->abs_vfid, qid, rc);
  488. return rc;
  489. }
  490. int bnx2x_vf_mcast(struct bnx2x *bp, struct bnx2x_virtf *vf,
  491. bnx2x_mac_addr_t *mcasts, int mc_num, bool drv_only)
  492. {
  493. struct bnx2x_mcast_list_elem *mc = NULL;
  494. struct bnx2x_mcast_ramrod_params mcast;
  495. int rc, i;
  496. DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid);
  497. /* Prepare Multicast command */
  498. memset(&mcast, 0, sizeof(struct bnx2x_mcast_ramrod_params));
  499. mcast.mcast_obj = &vf->mcast_obj;
  500. if (drv_only)
  501. set_bit(RAMROD_DRV_CLR_ONLY, &mcast.ramrod_flags);
  502. else
  503. set_bit(RAMROD_COMP_WAIT, &mcast.ramrod_flags);
  504. if (mc_num) {
  505. mc = kzalloc(mc_num * sizeof(struct bnx2x_mcast_list_elem),
  506. GFP_KERNEL);
  507. if (!mc) {
  508. BNX2X_ERR("Cannot Configure multicasts due to lack of memory\n");
  509. return -ENOMEM;
  510. }
  511. }
  512. /* clear existing mcasts */
  513. mcast.mcast_list_len = vf->mcast_list_len;
  514. vf->mcast_list_len = mc_num;
  515. rc = bnx2x_config_mcast(bp, &mcast, BNX2X_MCAST_CMD_DEL);
  516. if (rc) {
  517. BNX2X_ERR("Failed to remove multicasts\n");
  518. kfree(mc);
  519. return rc;
  520. }
  521. /* update mcast list on the ramrod params */
  522. if (mc_num) {
  523. INIT_LIST_HEAD(&mcast.mcast_list);
  524. for (i = 0; i < mc_num; i++) {
  525. mc[i].mac = mcasts[i];
  526. list_add_tail(&mc[i].link,
  527. &mcast.mcast_list);
  528. }
  529. /* add new mcasts */
  530. mcast.mcast_list_len = mc_num;
  531. rc = bnx2x_config_mcast(bp, &mcast, BNX2X_MCAST_CMD_ADD);
  532. if (rc)
  533. BNX2X_ERR("Faled to add multicasts\n");
  534. kfree(mc);
  535. }
  536. return rc;
  537. }
  538. static void bnx2x_vf_prep_rx_mode(struct bnx2x *bp, u8 qid,
  539. struct bnx2x_rx_mode_ramrod_params *ramrod,
  540. struct bnx2x_virtf *vf,
  541. unsigned long accept_flags)
  542. {
  543. struct bnx2x_vf_queue *vfq = vfq_get(vf, qid);
  544. memset(ramrod, 0, sizeof(*ramrod));
  545. ramrod->cid = vfq->cid;
  546. ramrod->cl_id = vfq_cl_id(vf, vfq);
  547. ramrod->rx_mode_obj = &bp->rx_mode_obj;
  548. ramrod->func_id = FW_VF_HANDLE(vf->abs_vfid);
  549. ramrod->rx_accept_flags = accept_flags;
  550. ramrod->tx_accept_flags = accept_flags;
  551. ramrod->pstate = &vf->filter_state;
  552. ramrod->state = BNX2X_FILTER_RX_MODE_PENDING;
  553. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &vf->filter_state);
  554. set_bit(RAMROD_RX, &ramrod->ramrod_flags);
  555. set_bit(RAMROD_TX, &ramrod->ramrod_flags);
  556. ramrod->rdata = bnx2x_vf_sp(bp, vf, rx_mode_rdata.e2);
  557. ramrod->rdata_mapping = bnx2x_vf_sp_map(bp, vf, rx_mode_rdata.e2);
  558. }
  559. int bnx2x_vf_rxmode(struct bnx2x *bp, struct bnx2x_virtf *vf,
  560. int qid, unsigned long accept_flags)
  561. {
  562. struct bnx2x_rx_mode_ramrod_params ramrod;
  563. DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid);
  564. bnx2x_vf_prep_rx_mode(bp, qid, &ramrod, vf, accept_flags);
  565. set_bit(RAMROD_COMP_WAIT, &ramrod.ramrod_flags);
  566. vfq_get(vf, qid)->accept_flags = ramrod.rx_accept_flags;
  567. return bnx2x_config_rx_mode(bp, &ramrod);
  568. }
  569. int bnx2x_vf_queue_teardown(struct bnx2x *bp, struct bnx2x_virtf *vf, int qid)
  570. {
  571. int rc;
  572. DP(BNX2X_MSG_IOV, "vf[%d:%d]\n", vf->abs_vfid, qid);
  573. /* Remove all classification configuration for leading queue */
  574. if (qid == LEADING_IDX) {
  575. rc = bnx2x_vf_rxmode(bp, vf, qid, 0);
  576. if (rc)
  577. goto op_err;
  578. /* Remove filtering if feasible */
  579. if (bnx2x_validate_vf_sp_objs(bp, vf, true)) {
  580. rc = bnx2x_vf_vlan_mac_clear(bp, vf, qid,
  581. false, false);
  582. if (rc)
  583. goto op_err;
  584. rc = bnx2x_vf_vlan_mac_clear(bp, vf, qid,
  585. false, true);
  586. if (rc)
  587. goto op_err;
  588. rc = bnx2x_vf_mcast(bp, vf, NULL, 0, false);
  589. if (rc)
  590. goto op_err;
  591. }
  592. }
  593. /* Destroy queue */
  594. rc = bnx2x_vf_queue_destroy(bp, vf, qid);
  595. if (rc)
  596. goto op_err;
  597. return rc;
  598. op_err:
  599. BNX2X_ERR("vf[%d:%d] error: rc %d\n",
  600. vf->abs_vfid, qid, rc);
  601. return rc;
  602. }
  603. /* VF enable primitives
  604. * when pretend is required the caller is responsible
  605. * for calling pretend prior to calling these routines
  606. */
  607. /* internal vf enable - until vf is enabled internally all transactions
  608. * are blocked. This routine should always be called last with pretend.
  609. */
  610. static void bnx2x_vf_enable_internal(struct bnx2x *bp, u8 enable)
  611. {
  612. REG_WR(bp, PGLUE_B_REG_INTERNAL_VFID_ENABLE, enable ? 1 : 0);
  613. }
  614. /* clears vf error in all semi blocks */
  615. static void bnx2x_vf_semi_clear_err(struct bnx2x *bp, u8 abs_vfid)
  616. {
  617. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, abs_vfid);
  618. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, abs_vfid);
  619. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, abs_vfid);
  620. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, abs_vfid);
  621. }
  622. static void bnx2x_vf_pglue_clear_err(struct bnx2x *bp, u8 abs_vfid)
  623. {
  624. u32 was_err_group = (2 * BP_PATH(bp) + abs_vfid) >> 5;
  625. u32 was_err_reg = 0;
  626. switch (was_err_group) {
  627. case 0:
  628. was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR;
  629. break;
  630. case 1:
  631. was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_63_32_CLR;
  632. break;
  633. case 2:
  634. was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_95_64_CLR;
  635. break;
  636. case 3:
  637. was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_127_96_CLR;
  638. break;
  639. }
  640. REG_WR(bp, was_err_reg, 1 << (abs_vfid & 0x1f));
  641. }
  642. static void bnx2x_vf_igu_reset(struct bnx2x *bp, struct bnx2x_virtf *vf)
  643. {
  644. int i;
  645. u32 val;
  646. /* Set VF masks and configuration - pretend */
  647. bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
  648. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  649. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  650. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  651. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  652. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  653. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  654. val = REG_RD(bp, IGU_REG_VF_CONFIGURATION);
  655. val |= (IGU_VF_CONF_FUNC_EN | IGU_VF_CONF_MSI_MSIX_EN);
  656. if (vf->cfg_flags & VF_CFG_INT_SIMD)
  657. val |= IGU_VF_CONF_SINGLE_ISR_EN;
  658. val &= ~IGU_VF_CONF_PARENT_MASK;
  659. val |= (BP_ABS_FUNC(bp) >> 1) << IGU_VF_CONF_PARENT_SHIFT;
  660. REG_WR(bp, IGU_REG_VF_CONFIGURATION, val);
  661. DP(BNX2X_MSG_IOV,
  662. "value in IGU_REG_VF_CONFIGURATION of vf %d after write is 0x%08x\n",
  663. vf->abs_vfid, val);
  664. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  665. /* iterate over all queues, clear sb consumer */
  666. for (i = 0; i < vf_sb_count(vf); i++) {
  667. u8 igu_sb_id = vf_igu_sb(vf, i);
  668. /* zero prod memory */
  669. REG_WR(bp, IGU_REG_PROD_CONS_MEMORY + igu_sb_id * 4, 0);
  670. /* clear sb state machine */
  671. bnx2x_igu_clear_sb_gen(bp, vf->abs_vfid, igu_sb_id,
  672. false /* VF */);
  673. /* disable + update */
  674. bnx2x_vf_igu_ack_sb(bp, vf, igu_sb_id, USTORM_ID, 0,
  675. IGU_INT_DISABLE, 1);
  676. }
  677. }
  678. void bnx2x_vf_enable_access(struct bnx2x *bp, u8 abs_vfid)
  679. {
  680. /* set the VF-PF association in the FW */
  681. storm_memset_vf_to_pf(bp, FW_VF_HANDLE(abs_vfid), BP_FUNC(bp));
  682. storm_memset_func_en(bp, FW_VF_HANDLE(abs_vfid), 1);
  683. /* clear vf errors*/
  684. bnx2x_vf_semi_clear_err(bp, abs_vfid);
  685. bnx2x_vf_pglue_clear_err(bp, abs_vfid);
  686. /* internal vf-enable - pretend */
  687. bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, abs_vfid));
  688. DP(BNX2X_MSG_IOV, "enabling internal access for vf %x\n", abs_vfid);
  689. bnx2x_vf_enable_internal(bp, true);
  690. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  691. }
  692. static void bnx2x_vf_enable_traffic(struct bnx2x *bp, struct bnx2x_virtf *vf)
  693. {
  694. /* Reset vf in IGU interrupts are still disabled */
  695. bnx2x_vf_igu_reset(bp, vf);
  696. /* pretend to enable the vf with the PBF */
  697. bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
  698. REG_WR(bp, PBF_REG_DISABLE_VF, 0);
  699. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  700. }
  701. static u8 bnx2x_vf_is_pcie_pending(struct bnx2x *bp, u8 abs_vfid)
  702. {
  703. struct pci_dev *dev;
  704. struct bnx2x_virtf *vf = bnx2x_vf_by_abs_fid(bp, abs_vfid);
  705. if (!vf)
  706. return false;
  707. dev = pci_get_bus_and_slot(vf->bus, vf->devfn);
  708. if (dev)
  709. return bnx2x_is_pcie_pending(dev);
  710. return false;
  711. }
  712. int bnx2x_vf_flr_clnup_epilog(struct bnx2x *bp, u8 abs_vfid)
  713. {
  714. /* Verify no pending pci transactions */
  715. if (bnx2x_vf_is_pcie_pending(bp, abs_vfid))
  716. BNX2X_ERR("PCIE Transactions still pending\n");
  717. return 0;
  718. }
  719. static void bnx2x_iov_re_set_vlan_filters(struct bnx2x *bp,
  720. struct bnx2x_virtf *vf,
  721. int new)
  722. {
  723. int num = vf_vlan_rules_cnt(vf);
  724. int diff = new - num;
  725. bool rc = true;
  726. DP(BNX2X_MSG_IOV, "vf[%d] - %d vlan filter credits [previously %d]\n",
  727. vf->abs_vfid, new, num);
  728. if (diff > 0)
  729. rc = bp->vlans_pool.get(&bp->vlans_pool, diff);
  730. else if (diff < 0)
  731. rc = bp->vlans_pool.put(&bp->vlans_pool, -diff);
  732. if (rc)
  733. vf_vlan_rules_cnt(vf) = new;
  734. else
  735. DP(BNX2X_MSG_IOV, "vf[%d] - Failed to configure vlan filter credits change\n",
  736. vf->abs_vfid);
  737. }
  738. /* must be called after the number of PF queues and the number of VFs are
  739. * both known
  740. */
  741. static void
  742. bnx2x_iov_static_resc(struct bnx2x *bp, struct bnx2x_virtf *vf)
  743. {
  744. struct vf_pf_resc_request *resc = &vf->alloc_resc;
  745. u16 vlan_count = 0;
  746. /* will be set only during VF-ACQUIRE */
  747. resc->num_rxqs = 0;
  748. resc->num_txqs = 0;
  749. /* no credit calculations for macs (just yet) */
  750. resc->num_mac_filters = 1;
  751. /* divvy up vlan rules */
  752. bnx2x_iov_re_set_vlan_filters(bp, vf, 0);
  753. vlan_count = bp->vlans_pool.check(&bp->vlans_pool);
  754. vlan_count = 1 << ilog2(vlan_count);
  755. bnx2x_iov_re_set_vlan_filters(bp, vf,
  756. vlan_count / BNX2X_NR_VIRTFN(bp));
  757. /* no real limitation */
  758. resc->num_mc_filters = 0;
  759. /* num_sbs already set */
  760. resc->num_sbs = vf->sb_count;
  761. }
  762. /* FLR routines: */
  763. static void bnx2x_vf_free_resc(struct bnx2x *bp, struct bnx2x_virtf *vf)
  764. {
  765. /* reset the state variables */
  766. bnx2x_iov_static_resc(bp, vf);
  767. vf->state = VF_FREE;
  768. }
  769. static void bnx2x_vf_flr_clnup_hw(struct bnx2x *bp, struct bnx2x_virtf *vf)
  770. {
  771. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  772. /* DQ usage counter */
  773. bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
  774. bnx2x_flr_clnup_poll_hw_counter(bp, DORQ_REG_VF_USAGE_CNT,
  775. "DQ VF usage counter timed out",
  776. poll_cnt);
  777. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  778. /* FW cleanup command - poll for the results */
  779. if (bnx2x_send_final_clnup(bp, (u8)FW_VF_HANDLE(vf->abs_vfid),
  780. poll_cnt))
  781. BNX2X_ERR("VF[%d] Final cleanup timed-out\n", vf->abs_vfid);
  782. /* verify TX hw is flushed */
  783. bnx2x_tx_hw_flushed(bp, poll_cnt);
  784. }
  785. static void bnx2x_vf_flr(struct bnx2x *bp, struct bnx2x_virtf *vf)
  786. {
  787. int rc, i;
  788. DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid);
  789. /* the cleanup operations are valid if and only if the VF
  790. * was first acquired.
  791. */
  792. for (i = 0; i < vf_rxq_count(vf); i++) {
  793. rc = bnx2x_vf_queue_flr(bp, vf, i);
  794. if (rc)
  795. goto out;
  796. }
  797. /* remove multicasts */
  798. bnx2x_vf_mcast(bp, vf, NULL, 0, true);
  799. /* dispatch final cleanup and wait for HW queues to flush */
  800. bnx2x_vf_flr_clnup_hw(bp, vf);
  801. /* release VF resources */
  802. bnx2x_vf_free_resc(bp, vf);
  803. /* re-open the mailbox */
  804. bnx2x_vf_enable_mbx(bp, vf->abs_vfid);
  805. return;
  806. out:
  807. BNX2X_ERR("vf[%d:%d] failed flr: rc %d\n",
  808. vf->abs_vfid, i, rc);
  809. }
  810. static void bnx2x_vf_flr_clnup(struct bnx2x *bp)
  811. {
  812. struct bnx2x_virtf *vf;
  813. int i;
  814. for (i = 0; i < BNX2X_NR_VIRTFN(bp); i++) {
  815. /* VF should be RESET & in FLR cleanup states */
  816. if (bnx2x_vf(bp, i, state) != VF_RESET ||
  817. !bnx2x_vf(bp, i, flr_clnup_stage))
  818. continue;
  819. DP(BNX2X_MSG_IOV, "next vf to cleanup: %d. Num of vfs: %d\n",
  820. i, BNX2X_NR_VIRTFN(bp));
  821. vf = BP_VF(bp, i);
  822. /* lock the vf pf channel */
  823. bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_FLR);
  824. /* invoke the VF FLR SM */
  825. bnx2x_vf_flr(bp, vf);
  826. /* mark the VF to be ACKED and continue */
  827. vf->flr_clnup_stage = false;
  828. bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_FLR);
  829. }
  830. /* Acknowledge the handled VFs.
  831. * we are acknowledge all the vfs which an flr was requested for, even
  832. * if amongst them there are such that we never opened, since the mcp
  833. * will interrupt us immediately again if we only ack some of the bits,
  834. * resulting in an endless loop. This can happen for example in KVM
  835. * where an 'all ones' flr request is sometimes given by hyper visor
  836. */
  837. DP(BNX2X_MSG_MCP, "DRV_STATUS_VF_DISABLED ACK for vfs 0x%x 0x%x\n",
  838. bp->vfdb->flrd_vfs[0], bp->vfdb->flrd_vfs[1]);
  839. for (i = 0; i < FLRD_VFS_DWORDS; i++)
  840. SHMEM2_WR(bp, drv_ack_vf_disabled[BP_FW_MB_IDX(bp)][i],
  841. bp->vfdb->flrd_vfs[i]);
  842. bnx2x_fw_command(bp, DRV_MSG_CODE_VF_DISABLED_DONE, 0);
  843. /* clear the acked bits - better yet if the MCP implemented
  844. * write to clear semantics
  845. */
  846. for (i = 0; i < FLRD_VFS_DWORDS; i++)
  847. SHMEM2_WR(bp, drv_ack_vf_disabled[BP_FW_MB_IDX(bp)][i], 0);
  848. }
  849. void bnx2x_vf_handle_flr_event(struct bnx2x *bp)
  850. {
  851. int i;
  852. /* Read FLR'd VFs */
  853. for (i = 0; i < FLRD_VFS_DWORDS; i++)
  854. bp->vfdb->flrd_vfs[i] = SHMEM2_RD(bp, mcp_vf_disabled[i]);
  855. DP(BNX2X_MSG_MCP,
  856. "DRV_STATUS_VF_DISABLED received for vfs 0x%x 0x%x\n",
  857. bp->vfdb->flrd_vfs[0], bp->vfdb->flrd_vfs[1]);
  858. for_each_vf(bp, i) {
  859. struct bnx2x_virtf *vf = BP_VF(bp, i);
  860. u32 reset = 0;
  861. if (vf->abs_vfid < 32)
  862. reset = bp->vfdb->flrd_vfs[0] & (1 << vf->abs_vfid);
  863. else
  864. reset = bp->vfdb->flrd_vfs[1] &
  865. (1 << (vf->abs_vfid - 32));
  866. if (reset) {
  867. /* set as reset and ready for cleanup */
  868. vf->state = VF_RESET;
  869. vf->flr_clnup_stage = true;
  870. DP(BNX2X_MSG_IOV,
  871. "Initiating Final cleanup for VF %d\n",
  872. vf->abs_vfid);
  873. }
  874. }
  875. /* do the FLR cleanup for all marked VFs*/
  876. bnx2x_vf_flr_clnup(bp);
  877. }
  878. /* IOV global initialization routines */
  879. void bnx2x_iov_init_dq(struct bnx2x *bp)
  880. {
  881. if (!IS_SRIOV(bp))
  882. return;
  883. /* Set the DQ such that the CID reflect the abs_vfid */
  884. REG_WR(bp, DORQ_REG_VF_NORM_VF_BASE, 0);
  885. REG_WR(bp, DORQ_REG_MAX_RVFID_SIZE, ilog2(BNX2X_MAX_NUM_OF_VFS));
  886. /* Set VFs starting CID. If its > 0 the preceding CIDs are belong to
  887. * the PF L2 queues
  888. */
  889. REG_WR(bp, DORQ_REG_VF_NORM_CID_BASE, BNX2X_FIRST_VF_CID);
  890. /* The VF window size is the log2 of the max number of CIDs per VF */
  891. REG_WR(bp, DORQ_REG_VF_NORM_CID_WND_SIZE, BNX2X_VF_CID_WND);
  892. /* The VF doorbell size 0 - *B, 4 - 128B. We set it here to match
  893. * the Pf doorbell size although the 2 are independent.
  894. */
  895. REG_WR(bp, DORQ_REG_VF_NORM_CID_OFST, 3);
  896. /* No security checks for now -
  897. * configure single rule (out of 16) mask = 0x1, value = 0x0,
  898. * CID range 0 - 0x1ffff
  899. */
  900. REG_WR(bp, DORQ_REG_VF_TYPE_MASK_0, 1);
  901. REG_WR(bp, DORQ_REG_VF_TYPE_VALUE_0, 0);
  902. REG_WR(bp, DORQ_REG_VF_TYPE_MIN_MCID_0, 0);
  903. REG_WR(bp, DORQ_REG_VF_TYPE_MAX_MCID_0, 0x1ffff);
  904. /* set the VF doorbell threshold. This threshold represents the amount
  905. * of doorbells allowed in the main DORQ fifo for a specific VF.
  906. */
  907. REG_WR(bp, DORQ_REG_VF_USAGE_CT_LIMIT, 64);
  908. }
  909. void bnx2x_iov_init_dmae(struct bnx2x *bp)
  910. {
  911. if (pci_find_ext_capability(bp->pdev, PCI_EXT_CAP_ID_SRIOV))
  912. REG_WR(bp, DMAE_REG_BACKWARD_COMP_EN, 0);
  913. }
  914. static int bnx2x_vf_bus(struct bnx2x *bp, int vfid)
  915. {
  916. struct pci_dev *dev = bp->pdev;
  917. struct bnx2x_sriov *iov = &bp->vfdb->sriov;
  918. return dev->bus->number + ((dev->devfn + iov->offset +
  919. iov->stride * vfid) >> 8);
  920. }
  921. static int bnx2x_vf_devfn(struct bnx2x *bp, int vfid)
  922. {
  923. struct pci_dev *dev = bp->pdev;
  924. struct bnx2x_sriov *iov = &bp->vfdb->sriov;
  925. return (dev->devfn + iov->offset + iov->stride * vfid) & 0xff;
  926. }
  927. static void bnx2x_vf_set_bars(struct bnx2x *bp, struct bnx2x_virtf *vf)
  928. {
  929. int i, n;
  930. struct pci_dev *dev = bp->pdev;
  931. struct bnx2x_sriov *iov = &bp->vfdb->sriov;
  932. for (i = 0, n = 0; i < PCI_SRIOV_NUM_BARS; i += 2, n++) {
  933. u64 start = pci_resource_start(dev, PCI_IOV_RESOURCES + i);
  934. u32 size = pci_resource_len(dev, PCI_IOV_RESOURCES + i);
  935. size /= iov->total;
  936. vf->bars[n].bar = start + size * vf->abs_vfid;
  937. vf->bars[n].size = size;
  938. }
  939. }
  940. static int bnx2x_ari_enabled(struct pci_dev *dev)
  941. {
  942. return dev->bus->self && dev->bus->self->ari_enabled;
  943. }
  944. static int
  945. bnx2x_get_vf_igu_cam_info(struct bnx2x *bp)
  946. {
  947. int sb_id;
  948. u32 val;
  949. u8 fid, current_pf = 0;
  950. /* IGU in normal mode - read CAM */
  951. for (sb_id = 0; sb_id < IGU_REG_MAPPING_MEMORY_SIZE; sb_id++) {
  952. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + sb_id * 4);
  953. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  954. continue;
  955. fid = GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID);
  956. if (fid & IGU_FID_ENCODE_IS_PF)
  957. current_pf = fid & IGU_FID_PF_NUM_MASK;
  958. else if (current_pf == BP_FUNC(bp))
  959. bnx2x_vf_set_igu_info(bp, sb_id,
  960. (fid & IGU_FID_VF_NUM_MASK));
  961. DP(BNX2X_MSG_IOV, "%s[%d], igu_sb_id=%d, msix=%d\n",
  962. ((fid & IGU_FID_ENCODE_IS_PF) ? "PF" : "VF"),
  963. ((fid & IGU_FID_ENCODE_IS_PF) ? (fid & IGU_FID_PF_NUM_MASK) :
  964. (fid & IGU_FID_VF_NUM_MASK)), sb_id,
  965. GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR));
  966. }
  967. DP(BNX2X_MSG_IOV, "vf_sbs_pool is %d\n", BP_VFDB(bp)->vf_sbs_pool);
  968. return BP_VFDB(bp)->vf_sbs_pool;
  969. }
  970. static void __bnx2x_iov_free_vfdb(struct bnx2x *bp)
  971. {
  972. if (bp->vfdb) {
  973. kfree(bp->vfdb->vfqs);
  974. kfree(bp->vfdb->vfs);
  975. kfree(bp->vfdb);
  976. }
  977. bp->vfdb = NULL;
  978. }
  979. static int bnx2x_sriov_pci_cfg_info(struct bnx2x *bp, struct bnx2x_sriov *iov)
  980. {
  981. int pos;
  982. struct pci_dev *dev = bp->pdev;
  983. pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV);
  984. if (!pos) {
  985. BNX2X_ERR("failed to find SRIOV capability in device\n");
  986. return -ENODEV;
  987. }
  988. iov->pos = pos;
  989. DP(BNX2X_MSG_IOV, "sriov ext pos %d\n", pos);
  990. pci_read_config_word(dev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
  991. pci_read_config_word(dev, pos + PCI_SRIOV_TOTAL_VF, &iov->total);
  992. pci_read_config_word(dev, pos + PCI_SRIOV_INITIAL_VF, &iov->initial);
  993. pci_read_config_word(dev, pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
  994. pci_read_config_word(dev, pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
  995. pci_read_config_dword(dev, pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
  996. pci_read_config_dword(dev, pos + PCI_SRIOV_CAP, &iov->cap);
  997. pci_read_config_byte(dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
  998. return 0;
  999. }
  1000. static int bnx2x_sriov_info(struct bnx2x *bp, struct bnx2x_sriov *iov)
  1001. {
  1002. u32 val;
  1003. /* read the SRIOV capability structure
  1004. * The fields can be read via configuration read or
  1005. * directly from the device (starting at offset PCICFG_OFFSET)
  1006. */
  1007. if (bnx2x_sriov_pci_cfg_info(bp, iov))
  1008. return -ENODEV;
  1009. /* get the number of SRIOV bars */
  1010. iov->nres = 0;
  1011. /* read the first_vfid */
  1012. val = REG_RD(bp, PCICFG_OFFSET + GRC_CONFIG_REG_PF_INIT_VF);
  1013. iov->first_vf_in_pf = ((val & GRC_CR_PF_INIT_VF_PF_FIRST_VF_NUM_MASK)
  1014. * 8) - (BNX2X_MAX_NUM_OF_VFS * BP_PATH(bp));
  1015. DP(BNX2X_MSG_IOV,
  1016. "IOV info[%d]: first vf %d, nres %d, cap 0x%x, ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d, stride %d, page size 0x%x\n",
  1017. BP_FUNC(bp),
  1018. iov->first_vf_in_pf, iov->nres, iov->cap, iov->ctrl, iov->total,
  1019. iov->initial, iov->nr_virtfn, iov->offset, iov->stride, iov->pgsz);
  1020. return 0;
  1021. }
  1022. /* must be called after PF bars are mapped */
  1023. int bnx2x_iov_init_one(struct bnx2x *bp, int int_mode_param,
  1024. int num_vfs_param)
  1025. {
  1026. int err, i;
  1027. struct bnx2x_sriov *iov;
  1028. struct pci_dev *dev = bp->pdev;
  1029. bp->vfdb = NULL;
  1030. /* verify is pf */
  1031. if (IS_VF(bp))
  1032. return 0;
  1033. /* verify sriov capability is present in configuration space */
  1034. if (!pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV))
  1035. return 0;
  1036. /* verify chip revision */
  1037. if (CHIP_IS_E1x(bp))
  1038. return 0;
  1039. /* check if SRIOV support is turned off */
  1040. if (!num_vfs_param)
  1041. return 0;
  1042. /* SRIOV assumes that num of PF CIDs < BNX2X_FIRST_VF_CID */
  1043. if (BNX2X_L2_MAX_CID(bp) >= BNX2X_FIRST_VF_CID) {
  1044. BNX2X_ERR("PF cids %d are overspilling into vf space (starts at %d). Abort SRIOV\n",
  1045. BNX2X_L2_MAX_CID(bp), BNX2X_FIRST_VF_CID);
  1046. return 0;
  1047. }
  1048. /* SRIOV can be enabled only with MSIX */
  1049. if (int_mode_param == BNX2X_INT_MODE_MSI ||
  1050. int_mode_param == BNX2X_INT_MODE_INTX) {
  1051. BNX2X_ERR("Forced MSI/INTx mode is incompatible with SRIOV\n");
  1052. return 0;
  1053. }
  1054. err = -EIO;
  1055. /* verify ari is enabled */
  1056. if (!bnx2x_ari_enabled(bp->pdev)) {
  1057. BNX2X_ERR("ARI not supported (check pci bridge ARI forwarding), SRIOV can not be enabled\n");
  1058. return 0;
  1059. }
  1060. /* verify igu is in normal mode */
  1061. if (CHIP_INT_MODE_IS_BC(bp)) {
  1062. BNX2X_ERR("IGU not normal mode, SRIOV can not be enabled\n");
  1063. return 0;
  1064. }
  1065. /* allocate the vfs database */
  1066. bp->vfdb = kzalloc(sizeof(*(bp->vfdb)), GFP_KERNEL);
  1067. if (!bp->vfdb) {
  1068. BNX2X_ERR("failed to allocate vf database\n");
  1069. err = -ENOMEM;
  1070. goto failed;
  1071. }
  1072. /* get the sriov info - Linux already collected all the pertinent
  1073. * information, however the sriov structure is for the private use
  1074. * of the pci module. Also we want this information regardless
  1075. * of the hyper-visor.
  1076. */
  1077. iov = &(bp->vfdb->sriov);
  1078. err = bnx2x_sriov_info(bp, iov);
  1079. if (err)
  1080. goto failed;
  1081. /* SR-IOV capability was enabled but there are no VFs*/
  1082. if (iov->total == 0)
  1083. goto failed;
  1084. iov->nr_virtfn = min_t(u16, iov->total, num_vfs_param);
  1085. DP(BNX2X_MSG_IOV, "num_vfs_param was %d, nr_virtfn was %d\n",
  1086. num_vfs_param, iov->nr_virtfn);
  1087. /* allocate the vf array */
  1088. bp->vfdb->vfs = kzalloc(sizeof(struct bnx2x_virtf) *
  1089. BNX2X_NR_VIRTFN(bp), GFP_KERNEL);
  1090. if (!bp->vfdb->vfs) {
  1091. BNX2X_ERR("failed to allocate vf array\n");
  1092. err = -ENOMEM;
  1093. goto failed;
  1094. }
  1095. /* Initial VF init - index and abs_vfid - nr_virtfn must be set */
  1096. for_each_vf(bp, i) {
  1097. bnx2x_vf(bp, i, index) = i;
  1098. bnx2x_vf(bp, i, abs_vfid) = iov->first_vf_in_pf + i;
  1099. bnx2x_vf(bp, i, state) = VF_FREE;
  1100. mutex_init(&bnx2x_vf(bp, i, op_mutex));
  1101. bnx2x_vf(bp, i, op_current) = CHANNEL_TLV_NONE;
  1102. }
  1103. /* re-read the IGU CAM for VFs - index and abs_vfid must be set */
  1104. if (!bnx2x_get_vf_igu_cam_info(bp)) {
  1105. BNX2X_ERR("No entries in IGU CAM for vfs\n");
  1106. err = -EINVAL;
  1107. goto failed;
  1108. }
  1109. /* allocate the queue arrays for all VFs */
  1110. bp->vfdb->vfqs = kzalloc(
  1111. BNX2X_MAX_NUM_VF_QUEUES * sizeof(struct bnx2x_vf_queue),
  1112. GFP_KERNEL);
  1113. if (!bp->vfdb->vfqs) {
  1114. BNX2X_ERR("failed to allocate vf queue array\n");
  1115. err = -ENOMEM;
  1116. goto failed;
  1117. }
  1118. /* Prepare the VFs event synchronization mechanism */
  1119. mutex_init(&bp->vfdb->event_mutex);
  1120. mutex_init(&bp->vfdb->bulletin_mutex);
  1121. return 0;
  1122. failed:
  1123. DP(BNX2X_MSG_IOV, "Failed err=%d\n", err);
  1124. __bnx2x_iov_free_vfdb(bp);
  1125. return err;
  1126. }
  1127. void bnx2x_iov_remove_one(struct bnx2x *bp)
  1128. {
  1129. int vf_idx;
  1130. /* if SRIOV is not enabled there's nothing to do */
  1131. if (!IS_SRIOV(bp))
  1132. return;
  1133. bnx2x_disable_sriov(bp);
  1134. /* disable access to all VFs */
  1135. for (vf_idx = 0; vf_idx < bp->vfdb->sriov.total; vf_idx++) {
  1136. bnx2x_pretend_func(bp,
  1137. HW_VF_HANDLE(bp,
  1138. bp->vfdb->sriov.first_vf_in_pf +
  1139. vf_idx));
  1140. DP(BNX2X_MSG_IOV, "disabling internal access for vf %d\n",
  1141. bp->vfdb->sriov.first_vf_in_pf + vf_idx);
  1142. bnx2x_vf_enable_internal(bp, 0);
  1143. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  1144. }
  1145. /* free vf database */
  1146. __bnx2x_iov_free_vfdb(bp);
  1147. }
  1148. void bnx2x_iov_free_mem(struct bnx2x *bp)
  1149. {
  1150. int i;
  1151. if (!IS_SRIOV(bp))
  1152. return;
  1153. /* free vfs hw contexts */
  1154. for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
  1155. struct hw_dma *cxt = &bp->vfdb->context[i];
  1156. BNX2X_PCI_FREE(cxt->addr, cxt->mapping, cxt->size);
  1157. }
  1158. BNX2X_PCI_FREE(BP_VFDB(bp)->sp_dma.addr,
  1159. BP_VFDB(bp)->sp_dma.mapping,
  1160. BP_VFDB(bp)->sp_dma.size);
  1161. BNX2X_PCI_FREE(BP_VF_MBX_DMA(bp)->addr,
  1162. BP_VF_MBX_DMA(bp)->mapping,
  1163. BP_VF_MBX_DMA(bp)->size);
  1164. BNX2X_PCI_FREE(BP_VF_BULLETIN_DMA(bp)->addr,
  1165. BP_VF_BULLETIN_DMA(bp)->mapping,
  1166. BP_VF_BULLETIN_DMA(bp)->size);
  1167. }
  1168. int bnx2x_iov_alloc_mem(struct bnx2x *bp)
  1169. {
  1170. size_t tot_size;
  1171. int i, rc = 0;
  1172. if (!IS_SRIOV(bp))
  1173. return rc;
  1174. /* allocate vfs hw contexts */
  1175. tot_size = (BP_VFDB(bp)->sriov.first_vf_in_pf + BNX2X_NR_VIRTFN(bp)) *
  1176. BNX2X_CIDS_PER_VF * sizeof(union cdu_context);
  1177. for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
  1178. struct hw_dma *cxt = BP_VF_CXT_PAGE(bp, i);
  1179. cxt->size = min_t(size_t, tot_size, CDU_ILT_PAGE_SZ);
  1180. if (cxt->size) {
  1181. cxt->addr = BNX2X_PCI_ALLOC(&cxt->mapping, cxt->size);
  1182. if (!cxt->addr)
  1183. goto alloc_mem_err;
  1184. } else {
  1185. cxt->addr = NULL;
  1186. cxt->mapping = 0;
  1187. }
  1188. tot_size -= cxt->size;
  1189. }
  1190. /* allocate vfs ramrods dma memory - client_init and set_mac */
  1191. tot_size = BNX2X_NR_VIRTFN(bp) * sizeof(struct bnx2x_vf_sp);
  1192. BP_VFDB(bp)->sp_dma.addr = BNX2X_PCI_ALLOC(&BP_VFDB(bp)->sp_dma.mapping,
  1193. tot_size);
  1194. if (!BP_VFDB(bp)->sp_dma.addr)
  1195. goto alloc_mem_err;
  1196. BP_VFDB(bp)->sp_dma.size = tot_size;
  1197. /* allocate mailboxes */
  1198. tot_size = BNX2X_NR_VIRTFN(bp) * MBX_MSG_ALIGNED_SIZE;
  1199. BP_VF_MBX_DMA(bp)->addr = BNX2X_PCI_ALLOC(&BP_VF_MBX_DMA(bp)->mapping,
  1200. tot_size);
  1201. if (!BP_VF_MBX_DMA(bp)->addr)
  1202. goto alloc_mem_err;
  1203. BP_VF_MBX_DMA(bp)->size = tot_size;
  1204. /* allocate local bulletin boards */
  1205. tot_size = BNX2X_NR_VIRTFN(bp) * BULLETIN_CONTENT_SIZE;
  1206. BP_VF_BULLETIN_DMA(bp)->addr = BNX2X_PCI_ALLOC(&BP_VF_BULLETIN_DMA(bp)->mapping,
  1207. tot_size);
  1208. if (!BP_VF_BULLETIN_DMA(bp)->addr)
  1209. goto alloc_mem_err;
  1210. BP_VF_BULLETIN_DMA(bp)->size = tot_size;
  1211. return 0;
  1212. alloc_mem_err:
  1213. return -ENOMEM;
  1214. }
  1215. static void bnx2x_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1216. struct bnx2x_vf_queue *q)
  1217. {
  1218. u8 cl_id = vfq_cl_id(vf, q);
  1219. u8 func_id = FW_VF_HANDLE(vf->abs_vfid);
  1220. unsigned long q_type = 0;
  1221. set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  1222. set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  1223. /* Queue State object */
  1224. bnx2x_init_queue_obj(bp, &q->sp_obj,
  1225. cl_id, &q->cid, 1, func_id,
  1226. bnx2x_vf_sp(bp, vf, q_data),
  1227. bnx2x_vf_sp_map(bp, vf, q_data),
  1228. q_type);
  1229. /* sp indication is set only when vlan/mac/etc. are initialized */
  1230. q->sp_initialized = false;
  1231. DP(BNX2X_MSG_IOV,
  1232. "initialized vf %d's queue object. func id set to %d. cid set to 0x%x\n",
  1233. vf->abs_vfid, q->sp_obj.func_id, q->cid);
  1234. }
  1235. static int bnx2x_max_speed_cap(struct bnx2x *bp)
  1236. {
  1237. u32 supported = bp->port.supported[bnx2x_get_link_cfg_idx(bp)];
  1238. if (supported &
  1239. (SUPPORTED_20000baseMLD2_Full | SUPPORTED_20000baseKR2_Full))
  1240. return 20000;
  1241. return 10000; /* assume lowest supported speed is 10G */
  1242. }
  1243. int bnx2x_iov_link_update_vf(struct bnx2x *bp, int idx)
  1244. {
  1245. struct bnx2x_link_report_data *state = &bp->last_reported_link;
  1246. struct pf_vf_bulletin_content *bulletin;
  1247. struct bnx2x_virtf *vf;
  1248. bool update = true;
  1249. int rc = 0;
  1250. /* sanity and init */
  1251. rc = bnx2x_vf_op_prep(bp, idx, &vf, &bulletin, false);
  1252. if (rc)
  1253. return rc;
  1254. mutex_lock(&bp->vfdb->bulletin_mutex);
  1255. if (vf->link_cfg == IFLA_VF_LINK_STATE_AUTO) {
  1256. bulletin->valid_bitmap |= 1 << LINK_VALID;
  1257. bulletin->link_speed = state->line_speed;
  1258. bulletin->link_flags = 0;
  1259. if (test_bit(BNX2X_LINK_REPORT_LINK_DOWN,
  1260. &state->link_report_flags))
  1261. bulletin->link_flags |= VFPF_LINK_REPORT_LINK_DOWN;
  1262. if (test_bit(BNX2X_LINK_REPORT_FD,
  1263. &state->link_report_flags))
  1264. bulletin->link_flags |= VFPF_LINK_REPORT_FULL_DUPLEX;
  1265. if (test_bit(BNX2X_LINK_REPORT_RX_FC_ON,
  1266. &state->link_report_flags))
  1267. bulletin->link_flags |= VFPF_LINK_REPORT_RX_FC_ON;
  1268. if (test_bit(BNX2X_LINK_REPORT_TX_FC_ON,
  1269. &state->link_report_flags))
  1270. bulletin->link_flags |= VFPF_LINK_REPORT_TX_FC_ON;
  1271. } else if (vf->link_cfg == IFLA_VF_LINK_STATE_DISABLE &&
  1272. !(bulletin->link_flags & VFPF_LINK_REPORT_LINK_DOWN)) {
  1273. bulletin->valid_bitmap |= 1 << LINK_VALID;
  1274. bulletin->link_flags |= VFPF_LINK_REPORT_LINK_DOWN;
  1275. } else if (vf->link_cfg == IFLA_VF_LINK_STATE_ENABLE &&
  1276. (bulletin->link_flags & VFPF_LINK_REPORT_LINK_DOWN)) {
  1277. bulletin->valid_bitmap |= 1 << LINK_VALID;
  1278. bulletin->link_speed = bnx2x_max_speed_cap(bp);
  1279. bulletin->link_flags &= ~VFPF_LINK_REPORT_LINK_DOWN;
  1280. } else {
  1281. update = false;
  1282. }
  1283. if (update) {
  1284. DP(NETIF_MSG_LINK | BNX2X_MSG_IOV,
  1285. "vf %d mode %u speed %d flags %x\n", idx,
  1286. vf->link_cfg, bulletin->link_speed, bulletin->link_flags);
  1287. /* Post update on VF's bulletin board */
  1288. rc = bnx2x_post_vf_bulletin(bp, idx);
  1289. if (rc) {
  1290. BNX2X_ERR("failed to update VF[%d] bulletin\n", idx);
  1291. goto out;
  1292. }
  1293. }
  1294. out:
  1295. mutex_unlock(&bp->vfdb->bulletin_mutex);
  1296. return rc;
  1297. }
  1298. int bnx2x_set_vf_link_state(struct net_device *dev, int idx, int link_state)
  1299. {
  1300. struct bnx2x *bp = netdev_priv(dev);
  1301. struct bnx2x_virtf *vf = BP_VF(bp, idx);
  1302. if (!vf)
  1303. return -EINVAL;
  1304. if (vf->link_cfg == link_state)
  1305. return 0; /* nothing todo */
  1306. vf->link_cfg = link_state;
  1307. return bnx2x_iov_link_update_vf(bp, idx);
  1308. }
  1309. void bnx2x_iov_link_update(struct bnx2x *bp)
  1310. {
  1311. int vfid;
  1312. if (!IS_SRIOV(bp))
  1313. return;
  1314. for_each_vf(bp, vfid)
  1315. bnx2x_iov_link_update_vf(bp, vfid);
  1316. }
  1317. /* called by bnx2x_nic_load */
  1318. int bnx2x_iov_nic_init(struct bnx2x *bp)
  1319. {
  1320. int vfid;
  1321. if (!IS_SRIOV(bp)) {
  1322. DP(BNX2X_MSG_IOV, "vfdb was not allocated\n");
  1323. return 0;
  1324. }
  1325. DP(BNX2X_MSG_IOV, "num of vfs: %d\n", (bp)->vfdb->sriov.nr_virtfn);
  1326. /* let FLR complete ... */
  1327. msleep(100);
  1328. /* initialize vf database */
  1329. for_each_vf(bp, vfid) {
  1330. struct bnx2x_virtf *vf = BP_VF(bp, vfid);
  1331. int base_vf_cid = (BP_VFDB(bp)->sriov.first_vf_in_pf + vfid) *
  1332. BNX2X_CIDS_PER_VF;
  1333. union cdu_context *base_cxt = (union cdu_context *)
  1334. BP_VF_CXT_PAGE(bp, base_vf_cid/ILT_PAGE_CIDS)->addr +
  1335. (base_vf_cid & (ILT_PAGE_CIDS-1));
  1336. DP(BNX2X_MSG_IOV,
  1337. "VF[%d] Max IGU SBs: %d, base vf cid 0x%x, base cid 0x%x, base cxt %p\n",
  1338. vf->abs_vfid, vf_sb_count(vf), base_vf_cid,
  1339. BNX2X_FIRST_VF_CID + base_vf_cid, base_cxt);
  1340. /* init statically provisioned resources */
  1341. bnx2x_iov_static_resc(bp, vf);
  1342. /* queues are initialized during VF-ACQUIRE */
  1343. vf->filter_state = 0;
  1344. vf->sp_cl_id = bnx2x_fp(bp, 0, cl_id);
  1345. /* init mcast object - This object will be re-initialized
  1346. * during VF-ACQUIRE with the proper cl_id and cid.
  1347. * It needs to be initialized here so that it can be safely
  1348. * handled by a subsequent FLR flow.
  1349. */
  1350. vf->mcast_list_len = 0;
  1351. bnx2x_init_mcast_obj(bp, &vf->mcast_obj, 0xFF,
  1352. 0xFF, 0xFF, 0xFF,
  1353. bnx2x_vf_sp(bp, vf, mcast_rdata),
  1354. bnx2x_vf_sp_map(bp, vf, mcast_rdata),
  1355. BNX2X_FILTER_MCAST_PENDING,
  1356. &vf->filter_state,
  1357. BNX2X_OBJ_TYPE_RX_TX);
  1358. /* set the mailbox message addresses */
  1359. BP_VF_MBX(bp, vfid)->msg = (struct bnx2x_vf_mbx_msg *)
  1360. (((u8 *)BP_VF_MBX_DMA(bp)->addr) + vfid *
  1361. MBX_MSG_ALIGNED_SIZE);
  1362. BP_VF_MBX(bp, vfid)->msg_mapping = BP_VF_MBX_DMA(bp)->mapping +
  1363. vfid * MBX_MSG_ALIGNED_SIZE;
  1364. /* Enable vf mailbox */
  1365. bnx2x_vf_enable_mbx(bp, vf->abs_vfid);
  1366. }
  1367. /* Final VF init */
  1368. for_each_vf(bp, vfid) {
  1369. struct bnx2x_virtf *vf = BP_VF(bp, vfid);
  1370. /* fill in the BDF and bars */
  1371. vf->bus = bnx2x_vf_bus(bp, vfid);
  1372. vf->devfn = bnx2x_vf_devfn(bp, vfid);
  1373. bnx2x_vf_set_bars(bp, vf);
  1374. DP(BNX2X_MSG_IOV,
  1375. "VF info[%d]: bus 0x%x, devfn 0x%x, bar0 [0x%x, %d], bar1 [0x%x, %d], bar2 [0x%x, %d]\n",
  1376. vf->abs_vfid, vf->bus, vf->devfn,
  1377. (unsigned)vf->bars[0].bar, vf->bars[0].size,
  1378. (unsigned)vf->bars[1].bar, vf->bars[1].size,
  1379. (unsigned)vf->bars[2].bar, vf->bars[2].size);
  1380. }
  1381. return 0;
  1382. }
  1383. /* called by bnx2x_chip_cleanup */
  1384. int bnx2x_iov_chip_cleanup(struct bnx2x *bp)
  1385. {
  1386. int i;
  1387. if (!IS_SRIOV(bp))
  1388. return 0;
  1389. /* release all the VFs */
  1390. for_each_vf(bp, i)
  1391. bnx2x_vf_release(bp, BP_VF(bp, i));
  1392. return 0;
  1393. }
  1394. /* called by bnx2x_init_hw_func, returns the next ilt line */
  1395. int bnx2x_iov_init_ilt(struct bnx2x *bp, u16 line)
  1396. {
  1397. int i;
  1398. struct bnx2x_ilt *ilt = BP_ILT(bp);
  1399. if (!IS_SRIOV(bp))
  1400. return line;
  1401. /* set vfs ilt lines */
  1402. for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
  1403. struct hw_dma *hw_cxt = BP_VF_CXT_PAGE(bp, i);
  1404. ilt->lines[line+i].page = hw_cxt->addr;
  1405. ilt->lines[line+i].page_mapping = hw_cxt->mapping;
  1406. ilt->lines[line+i].size = hw_cxt->size; /* doesn't matter */
  1407. }
  1408. return line + i;
  1409. }
  1410. static u8 bnx2x_iov_is_vf_cid(struct bnx2x *bp, u16 cid)
  1411. {
  1412. return ((cid >= BNX2X_FIRST_VF_CID) &&
  1413. ((cid - BNX2X_FIRST_VF_CID) < BNX2X_VF_CIDS));
  1414. }
  1415. static
  1416. void bnx2x_vf_handle_classification_eqe(struct bnx2x *bp,
  1417. struct bnx2x_vf_queue *vfq,
  1418. union event_ring_elem *elem)
  1419. {
  1420. unsigned long ramrod_flags = 0;
  1421. int rc = 0;
  1422. /* Always push next commands out, don't wait here */
  1423. set_bit(RAMROD_CONT, &ramrod_flags);
  1424. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  1425. case BNX2X_FILTER_MAC_PENDING:
  1426. rc = vfq->mac_obj.complete(bp, &vfq->mac_obj, elem,
  1427. &ramrod_flags);
  1428. break;
  1429. case BNX2X_FILTER_VLAN_PENDING:
  1430. rc = vfq->vlan_obj.complete(bp, &vfq->vlan_obj, elem,
  1431. &ramrod_flags);
  1432. break;
  1433. default:
  1434. BNX2X_ERR("Unsupported classification command: %d\n",
  1435. elem->message.data.eth_event.echo);
  1436. return;
  1437. }
  1438. if (rc < 0)
  1439. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  1440. else if (rc > 0)
  1441. DP(BNX2X_MSG_IOV, "Scheduled next pending commands...\n");
  1442. }
  1443. static
  1444. void bnx2x_vf_handle_mcast_eqe(struct bnx2x *bp,
  1445. struct bnx2x_virtf *vf)
  1446. {
  1447. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  1448. int rc;
  1449. rparam.mcast_obj = &vf->mcast_obj;
  1450. vf->mcast_obj.raw.clear_pending(&vf->mcast_obj.raw);
  1451. /* If there are pending mcast commands - send them */
  1452. if (vf->mcast_obj.check_pending(&vf->mcast_obj)) {
  1453. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  1454. if (rc < 0)
  1455. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  1456. rc);
  1457. }
  1458. }
  1459. static
  1460. void bnx2x_vf_handle_filters_eqe(struct bnx2x *bp,
  1461. struct bnx2x_virtf *vf)
  1462. {
  1463. smp_mb__before_atomic();
  1464. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &vf->filter_state);
  1465. smp_mb__after_atomic();
  1466. }
  1467. static void bnx2x_vf_handle_rss_update_eqe(struct bnx2x *bp,
  1468. struct bnx2x_virtf *vf)
  1469. {
  1470. vf->rss_conf_obj.raw.clear_pending(&vf->rss_conf_obj.raw);
  1471. }
  1472. int bnx2x_iov_eq_sp_event(struct bnx2x *bp, union event_ring_elem *elem)
  1473. {
  1474. struct bnx2x_virtf *vf;
  1475. int qidx = 0, abs_vfid;
  1476. u8 opcode;
  1477. u16 cid = 0xffff;
  1478. if (!IS_SRIOV(bp))
  1479. return 1;
  1480. /* first get the cid - the only events we handle here are cfc-delete
  1481. * and set-mac completion
  1482. */
  1483. opcode = elem->message.opcode;
  1484. switch (opcode) {
  1485. case EVENT_RING_OPCODE_CFC_DEL:
  1486. cid = SW_CID((__force __le32)
  1487. elem->message.data.cfc_del_event.cid);
  1488. DP(BNX2X_MSG_IOV, "checking cfc-del comp cid=%d\n", cid);
  1489. break;
  1490. case EVENT_RING_OPCODE_CLASSIFICATION_RULES:
  1491. case EVENT_RING_OPCODE_MULTICAST_RULES:
  1492. case EVENT_RING_OPCODE_FILTERS_RULES:
  1493. case EVENT_RING_OPCODE_RSS_UPDATE_RULES:
  1494. cid = (elem->message.data.eth_event.echo &
  1495. BNX2X_SWCID_MASK);
  1496. DP(BNX2X_MSG_IOV, "checking filtering comp cid=%d\n", cid);
  1497. break;
  1498. case EVENT_RING_OPCODE_VF_FLR:
  1499. abs_vfid = elem->message.data.vf_flr_event.vf_id;
  1500. DP(BNX2X_MSG_IOV, "Got VF FLR notification abs_vfid=%d\n",
  1501. abs_vfid);
  1502. goto get_vf;
  1503. case EVENT_RING_OPCODE_MALICIOUS_VF:
  1504. abs_vfid = elem->message.data.malicious_vf_event.vf_id;
  1505. BNX2X_ERR("Got VF MALICIOUS notification abs_vfid=%d err_id=0x%x\n",
  1506. abs_vfid,
  1507. elem->message.data.malicious_vf_event.err_id);
  1508. goto get_vf;
  1509. default:
  1510. return 1;
  1511. }
  1512. /* check if the cid is the VF range */
  1513. if (!bnx2x_iov_is_vf_cid(bp, cid)) {
  1514. DP(BNX2X_MSG_IOV, "cid is outside vf range: %d\n", cid);
  1515. return 1;
  1516. }
  1517. /* extract vf and rxq index from vf_cid - relies on the following:
  1518. * 1. vfid on cid reflects the true abs_vfid
  1519. * 2. The max number of VFs (per path) is 64
  1520. */
  1521. qidx = cid & ((1 << BNX2X_VF_CID_WND)-1);
  1522. abs_vfid = (cid >> BNX2X_VF_CID_WND) & (BNX2X_MAX_NUM_OF_VFS-1);
  1523. get_vf:
  1524. vf = bnx2x_vf_by_abs_fid(bp, abs_vfid);
  1525. if (!vf) {
  1526. BNX2X_ERR("EQ completion for unknown VF, cid %d, abs_vfid %d\n",
  1527. cid, abs_vfid);
  1528. return 0;
  1529. }
  1530. switch (opcode) {
  1531. case EVENT_RING_OPCODE_CFC_DEL:
  1532. DP(BNX2X_MSG_IOV, "got VF [%d:%d] cfc delete ramrod\n",
  1533. vf->abs_vfid, qidx);
  1534. vfq_get(vf, qidx)->sp_obj.complete_cmd(bp,
  1535. &vfq_get(vf,
  1536. qidx)->sp_obj,
  1537. BNX2X_Q_CMD_CFC_DEL);
  1538. break;
  1539. case EVENT_RING_OPCODE_CLASSIFICATION_RULES:
  1540. DP(BNX2X_MSG_IOV, "got VF [%d:%d] set mac/vlan ramrod\n",
  1541. vf->abs_vfid, qidx);
  1542. bnx2x_vf_handle_classification_eqe(bp, vfq_get(vf, qidx), elem);
  1543. break;
  1544. case EVENT_RING_OPCODE_MULTICAST_RULES:
  1545. DP(BNX2X_MSG_IOV, "got VF [%d:%d] set mcast ramrod\n",
  1546. vf->abs_vfid, qidx);
  1547. bnx2x_vf_handle_mcast_eqe(bp, vf);
  1548. break;
  1549. case EVENT_RING_OPCODE_FILTERS_RULES:
  1550. DP(BNX2X_MSG_IOV, "got VF [%d:%d] set rx-mode ramrod\n",
  1551. vf->abs_vfid, qidx);
  1552. bnx2x_vf_handle_filters_eqe(bp, vf);
  1553. break;
  1554. case EVENT_RING_OPCODE_RSS_UPDATE_RULES:
  1555. DP(BNX2X_MSG_IOV, "got VF [%d:%d] RSS update ramrod\n",
  1556. vf->abs_vfid, qidx);
  1557. bnx2x_vf_handle_rss_update_eqe(bp, vf);
  1558. case EVENT_RING_OPCODE_VF_FLR:
  1559. case EVENT_RING_OPCODE_MALICIOUS_VF:
  1560. /* Do nothing for now */
  1561. return 0;
  1562. }
  1563. return 0;
  1564. }
  1565. static struct bnx2x_virtf *bnx2x_vf_by_cid(struct bnx2x *bp, int vf_cid)
  1566. {
  1567. /* extract the vf from vf_cid - relies on the following:
  1568. * 1. vfid on cid reflects the true abs_vfid
  1569. * 2. The max number of VFs (per path) is 64
  1570. */
  1571. int abs_vfid = (vf_cid >> BNX2X_VF_CID_WND) & (BNX2X_MAX_NUM_OF_VFS-1);
  1572. return bnx2x_vf_by_abs_fid(bp, abs_vfid);
  1573. }
  1574. void bnx2x_iov_set_queue_sp_obj(struct bnx2x *bp, int vf_cid,
  1575. struct bnx2x_queue_sp_obj **q_obj)
  1576. {
  1577. struct bnx2x_virtf *vf;
  1578. if (!IS_SRIOV(bp))
  1579. return;
  1580. vf = bnx2x_vf_by_cid(bp, vf_cid);
  1581. if (vf) {
  1582. /* extract queue index from vf_cid - relies on the following:
  1583. * 1. vfid on cid reflects the true abs_vfid
  1584. * 2. The max number of VFs (per path) is 64
  1585. */
  1586. int q_index = vf_cid & ((1 << BNX2X_VF_CID_WND)-1);
  1587. *q_obj = &bnx2x_vfq(vf, q_index, sp_obj);
  1588. } else {
  1589. BNX2X_ERR("No vf matching cid %d\n", vf_cid);
  1590. }
  1591. }
  1592. void bnx2x_iov_adjust_stats_req(struct bnx2x *bp)
  1593. {
  1594. int i;
  1595. int first_queue_query_index, num_queues_req;
  1596. dma_addr_t cur_data_offset;
  1597. struct stats_query_entry *cur_query_entry;
  1598. u8 stats_count = 0;
  1599. bool is_fcoe = false;
  1600. if (!IS_SRIOV(bp))
  1601. return;
  1602. if (!NO_FCOE(bp))
  1603. is_fcoe = true;
  1604. /* fcoe adds one global request and one queue request */
  1605. num_queues_req = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe;
  1606. first_queue_query_index = BNX2X_FIRST_QUEUE_QUERY_IDX -
  1607. (is_fcoe ? 0 : 1);
  1608. DP_AND((BNX2X_MSG_IOV | BNX2X_MSG_STATS),
  1609. "BNX2X_NUM_ETH_QUEUES %d, is_fcoe %d, first_queue_query_index %d => determined the last non virtual statistics query index is %d. Will add queries on top of that\n",
  1610. BNX2X_NUM_ETH_QUEUES(bp), is_fcoe, first_queue_query_index,
  1611. first_queue_query_index + num_queues_req);
  1612. cur_data_offset = bp->fw_stats_data_mapping +
  1613. offsetof(struct bnx2x_fw_stats_data, queue_stats) +
  1614. num_queues_req * sizeof(struct per_queue_stats);
  1615. cur_query_entry = &bp->fw_stats_req->
  1616. query[first_queue_query_index + num_queues_req];
  1617. for_each_vf(bp, i) {
  1618. int j;
  1619. struct bnx2x_virtf *vf = BP_VF(bp, i);
  1620. if (vf->state != VF_ENABLED) {
  1621. DP_AND((BNX2X_MSG_IOV | BNX2X_MSG_STATS),
  1622. "vf %d not enabled so no stats for it\n",
  1623. vf->abs_vfid);
  1624. continue;
  1625. }
  1626. DP(BNX2X_MSG_IOV, "add addresses for vf %d\n", vf->abs_vfid);
  1627. for_each_vfq(vf, j) {
  1628. struct bnx2x_vf_queue *rxq = vfq_get(vf, j);
  1629. dma_addr_t q_stats_addr =
  1630. vf->fw_stat_map + j * vf->stats_stride;
  1631. /* collect stats fro active queues only */
  1632. if (bnx2x_get_q_logical_state(bp, &rxq->sp_obj) ==
  1633. BNX2X_Q_LOGICAL_STATE_STOPPED)
  1634. continue;
  1635. /* create stats query entry for this queue */
  1636. cur_query_entry->kind = STATS_TYPE_QUEUE;
  1637. cur_query_entry->index = vfq_stat_id(vf, rxq);
  1638. cur_query_entry->funcID =
  1639. cpu_to_le16(FW_VF_HANDLE(vf->abs_vfid));
  1640. cur_query_entry->address.hi =
  1641. cpu_to_le32(U64_HI(q_stats_addr));
  1642. cur_query_entry->address.lo =
  1643. cpu_to_le32(U64_LO(q_stats_addr));
  1644. DP(BNX2X_MSG_IOV,
  1645. "added address %x %x for vf %d queue %d client %d\n",
  1646. cur_query_entry->address.hi,
  1647. cur_query_entry->address.lo, cur_query_entry->funcID,
  1648. j, cur_query_entry->index);
  1649. cur_query_entry++;
  1650. cur_data_offset += sizeof(struct per_queue_stats);
  1651. stats_count++;
  1652. /* all stats are coalesced to the leading queue */
  1653. if (vf->cfg_flags & VF_CFG_STATS_COALESCE)
  1654. break;
  1655. }
  1656. }
  1657. bp->fw_stats_req->hdr.cmd_num = bp->fw_stats_num + stats_count;
  1658. }
  1659. /* VF API helpers */
  1660. static void bnx2x_vf_qtbl_set_q(struct bnx2x *bp, u8 abs_vfid, u8 qid,
  1661. u8 enable)
  1662. {
  1663. u32 reg = PXP_REG_HST_ZONE_PERMISSION_TABLE + qid * 4;
  1664. u32 val = enable ? (abs_vfid | (1 << 6)) : 0;
  1665. REG_WR(bp, reg, val);
  1666. }
  1667. static void bnx2x_vf_clr_qtbl(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1668. {
  1669. int i;
  1670. for_each_vfq(vf, i)
  1671. bnx2x_vf_qtbl_set_q(bp, vf->abs_vfid,
  1672. vfq_qzone_id(vf, vfq_get(vf, i)), false);
  1673. }
  1674. static void bnx2x_vf_igu_disable(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1675. {
  1676. u32 val;
  1677. /* clear the VF configuration - pretend */
  1678. bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
  1679. val = REG_RD(bp, IGU_REG_VF_CONFIGURATION);
  1680. val &= ~(IGU_VF_CONF_MSI_MSIX_EN | IGU_VF_CONF_SINGLE_ISR_EN |
  1681. IGU_VF_CONF_FUNC_EN | IGU_VF_CONF_PARENT_MASK);
  1682. REG_WR(bp, IGU_REG_VF_CONFIGURATION, val);
  1683. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  1684. }
  1685. u8 bnx2x_vf_max_queue_cnt(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1686. {
  1687. return min_t(u8, min_t(u8, vf_sb_count(vf), BNX2X_CIDS_PER_VF),
  1688. BNX2X_VF_MAX_QUEUES);
  1689. }
  1690. static
  1691. int bnx2x_vf_chk_avail_resc(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1692. struct vf_pf_resc_request *req_resc)
  1693. {
  1694. u8 rxq_cnt = vf_rxq_count(vf) ? : bnx2x_vf_max_queue_cnt(bp, vf);
  1695. u8 txq_cnt = vf_txq_count(vf) ? : bnx2x_vf_max_queue_cnt(bp, vf);
  1696. /* Save a vlan filter for the Hypervisor */
  1697. return ((req_resc->num_rxqs <= rxq_cnt) &&
  1698. (req_resc->num_txqs <= txq_cnt) &&
  1699. (req_resc->num_sbs <= vf_sb_count(vf)) &&
  1700. (req_resc->num_mac_filters <= vf_mac_rules_cnt(vf)) &&
  1701. (req_resc->num_vlan_filters <= vf_vlan_rules_visible_cnt(vf)));
  1702. }
  1703. /* CORE VF API */
  1704. int bnx2x_vf_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1705. struct vf_pf_resc_request *resc)
  1706. {
  1707. int base_vf_cid = (BP_VFDB(bp)->sriov.first_vf_in_pf + vf->index) *
  1708. BNX2X_CIDS_PER_VF;
  1709. union cdu_context *base_cxt = (union cdu_context *)
  1710. BP_VF_CXT_PAGE(bp, base_vf_cid/ILT_PAGE_CIDS)->addr +
  1711. (base_vf_cid & (ILT_PAGE_CIDS-1));
  1712. int i;
  1713. /* if state is 'acquired' the VF was not released or FLR'd, in
  1714. * this case the returned resources match the acquired already
  1715. * acquired resources. Verify that the requested numbers do
  1716. * not exceed the already acquired numbers.
  1717. */
  1718. if (vf->state == VF_ACQUIRED) {
  1719. DP(BNX2X_MSG_IOV, "VF[%d] Trying to re-acquire resources (VF was not released or FLR'd)\n",
  1720. vf->abs_vfid);
  1721. if (!bnx2x_vf_chk_avail_resc(bp, vf, resc)) {
  1722. BNX2X_ERR("VF[%d] When re-acquiring resources, requested numbers must be <= then previously acquired numbers\n",
  1723. vf->abs_vfid);
  1724. return -EINVAL;
  1725. }
  1726. return 0;
  1727. }
  1728. /* Otherwise vf state must be 'free' or 'reset' */
  1729. if (vf->state != VF_FREE && vf->state != VF_RESET) {
  1730. BNX2X_ERR("VF[%d] Can not acquire a VF with state %d\n",
  1731. vf->abs_vfid, vf->state);
  1732. return -EINVAL;
  1733. }
  1734. /* static allocation:
  1735. * the global maximum number are fixed per VF. Fail the request if
  1736. * requested number exceed these globals
  1737. */
  1738. if (!bnx2x_vf_chk_avail_resc(bp, vf, resc)) {
  1739. DP(BNX2X_MSG_IOV,
  1740. "cannot fulfill vf resource request. Placing maximal available values in response\n");
  1741. /* set the max resource in the vf */
  1742. return -ENOMEM;
  1743. }
  1744. /* Set resources counters - 0 request means max available */
  1745. vf_sb_count(vf) = resc->num_sbs;
  1746. vf_rxq_count(vf) = resc->num_rxqs ? : bnx2x_vf_max_queue_cnt(bp, vf);
  1747. vf_txq_count(vf) = resc->num_txqs ? : bnx2x_vf_max_queue_cnt(bp, vf);
  1748. if (resc->num_mac_filters)
  1749. vf_mac_rules_cnt(vf) = resc->num_mac_filters;
  1750. /* Add an additional vlan filter credit for the hypervisor */
  1751. bnx2x_iov_re_set_vlan_filters(bp, vf, resc->num_vlan_filters + 1);
  1752. DP(BNX2X_MSG_IOV,
  1753. "Fulfilling vf request: sb count %d, tx_count %d, rx_count %d, mac_rules_count %d, vlan_rules_count %d\n",
  1754. vf_sb_count(vf), vf_rxq_count(vf),
  1755. vf_txq_count(vf), vf_mac_rules_cnt(vf),
  1756. vf_vlan_rules_visible_cnt(vf));
  1757. /* Initialize the queues */
  1758. if (!vf->vfqs) {
  1759. DP(BNX2X_MSG_IOV, "vf->vfqs was not allocated\n");
  1760. return -EINVAL;
  1761. }
  1762. for_each_vfq(vf, i) {
  1763. struct bnx2x_vf_queue *q = vfq_get(vf, i);
  1764. if (!q) {
  1765. BNX2X_ERR("q number %d was not allocated\n", i);
  1766. return -EINVAL;
  1767. }
  1768. q->index = i;
  1769. q->cxt = &((base_cxt + i)->eth);
  1770. q->cid = BNX2X_FIRST_VF_CID + base_vf_cid + i;
  1771. DP(BNX2X_MSG_IOV, "VFQ[%d:%d]: index %d, cid 0x%x, cxt %p\n",
  1772. vf->abs_vfid, i, q->index, q->cid, q->cxt);
  1773. /* init SP objects */
  1774. bnx2x_vfq_init(bp, vf, q);
  1775. }
  1776. vf->state = VF_ACQUIRED;
  1777. return 0;
  1778. }
  1779. int bnx2x_vf_init(struct bnx2x *bp, struct bnx2x_virtf *vf, dma_addr_t *sb_map)
  1780. {
  1781. struct bnx2x_func_init_params func_init = {0};
  1782. u16 flags = 0;
  1783. int i;
  1784. /* the sb resources are initialized at this point, do the
  1785. * FW/HW initializations
  1786. */
  1787. for_each_vf_sb(vf, i)
  1788. bnx2x_init_sb(bp, (dma_addr_t)sb_map[i], vf->abs_vfid, true,
  1789. vf_igu_sb(vf, i), vf_igu_sb(vf, i));
  1790. /* Sanity checks */
  1791. if (vf->state != VF_ACQUIRED) {
  1792. DP(BNX2X_MSG_IOV, "VF[%d] is not in VF_ACQUIRED, but %d\n",
  1793. vf->abs_vfid, vf->state);
  1794. return -EINVAL;
  1795. }
  1796. /* let FLR complete ... */
  1797. msleep(100);
  1798. /* FLR cleanup epilogue */
  1799. if (bnx2x_vf_flr_clnup_epilog(bp, vf->abs_vfid))
  1800. return -EBUSY;
  1801. /* reset IGU VF statistics: MSIX */
  1802. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + vf->abs_vfid * 4 , 0);
  1803. /* vf init */
  1804. if (vf->cfg_flags & VF_CFG_STATS)
  1805. flags |= (FUNC_FLG_STATS | FUNC_FLG_SPQ);
  1806. if (vf->cfg_flags & VF_CFG_TPA)
  1807. flags |= FUNC_FLG_TPA;
  1808. if (is_vf_multi(vf))
  1809. flags |= FUNC_FLG_RSS;
  1810. /* function setup */
  1811. func_init.func_flgs = flags;
  1812. func_init.pf_id = BP_FUNC(bp);
  1813. func_init.func_id = FW_VF_HANDLE(vf->abs_vfid);
  1814. func_init.fw_stat_map = vf->fw_stat_map;
  1815. func_init.spq_map = vf->spq_map;
  1816. func_init.spq_prod = 0;
  1817. bnx2x_func_init(bp, &func_init);
  1818. /* Enable the vf */
  1819. bnx2x_vf_enable_access(bp, vf->abs_vfid);
  1820. bnx2x_vf_enable_traffic(bp, vf);
  1821. /* queue protection table */
  1822. for_each_vfq(vf, i)
  1823. bnx2x_vf_qtbl_set_q(bp, vf->abs_vfid,
  1824. vfq_qzone_id(vf, vfq_get(vf, i)), true);
  1825. vf->state = VF_ENABLED;
  1826. /* update vf bulletin board */
  1827. bnx2x_post_vf_bulletin(bp, vf->index);
  1828. return 0;
  1829. }
  1830. struct set_vf_state_cookie {
  1831. struct bnx2x_virtf *vf;
  1832. u8 state;
  1833. };
  1834. static void bnx2x_set_vf_state(void *cookie)
  1835. {
  1836. struct set_vf_state_cookie *p = (struct set_vf_state_cookie *)cookie;
  1837. p->vf->state = p->state;
  1838. }
  1839. int bnx2x_vf_close(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1840. {
  1841. int rc = 0, i;
  1842. DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid);
  1843. /* Close all queues */
  1844. for (i = 0; i < vf_rxq_count(vf); i++) {
  1845. rc = bnx2x_vf_queue_teardown(bp, vf, i);
  1846. if (rc)
  1847. goto op_err;
  1848. }
  1849. /* disable the interrupts */
  1850. DP(BNX2X_MSG_IOV, "disabling igu\n");
  1851. bnx2x_vf_igu_disable(bp, vf);
  1852. /* disable the VF */
  1853. DP(BNX2X_MSG_IOV, "clearing qtbl\n");
  1854. bnx2x_vf_clr_qtbl(bp, vf);
  1855. /* need to make sure there are no outstanding stats ramrods which may
  1856. * cause the device to access the VF's stats buffer which it will free
  1857. * as soon as we return from the close flow.
  1858. */
  1859. {
  1860. struct set_vf_state_cookie cookie;
  1861. cookie.vf = vf;
  1862. cookie.state = VF_ACQUIRED;
  1863. rc = bnx2x_stats_safe_exec(bp, bnx2x_set_vf_state, &cookie);
  1864. if (rc)
  1865. goto op_err;
  1866. }
  1867. DP(BNX2X_MSG_IOV, "set state to acquired\n");
  1868. return 0;
  1869. op_err:
  1870. BNX2X_ERR("vf[%d] CLOSE error: rc %d\n", vf->abs_vfid, rc);
  1871. return rc;
  1872. }
  1873. /* VF release can be called either: 1. The VF was acquired but
  1874. * not enabled 2. the vf was enabled or in the process of being
  1875. * enabled
  1876. */
  1877. int bnx2x_vf_free(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1878. {
  1879. int rc;
  1880. DP(BNX2X_MSG_IOV, "VF[%d] STATE: %s\n", vf->abs_vfid,
  1881. vf->state == VF_FREE ? "Free" :
  1882. vf->state == VF_ACQUIRED ? "Acquired" :
  1883. vf->state == VF_ENABLED ? "Enabled" :
  1884. vf->state == VF_RESET ? "Reset" :
  1885. "Unknown");
  1886. switch (vf->state) {
  1887. case VF_ENABLED:
  1888. rc = bnx2x_vf_close(bp, vf);
  1889. if (rc)
  1890. goto op_err;
  1891. /* Fallthrough to release resources */
  1892. case VF_ACQUIRED:
  1893. DP(BNX2X_MSG_IOV, "about to free resources\n");
  1894. bnx2x_vf_free_resc(bp, vf);
  1895. break;
  1896. case VF_FREE:
  1897. case VF_RESET:
  1898. default:
  1899. break;
  1900. }
  1901. return 0;
  1902. op_err:
  1903. BNX2X_ERR("VF[%d] RELEASE error: rc %d\n", vf->abs_vfid, rc);
  1904. return rc;
  1905. }
  1906. int bnx2x_vf_rss_update(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1907. struct bnx2x_config_rss_params *rss)
  1908. {
  1909. DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid);
  1910. set_bit(RAMROD_COMP_WAIT, &rss->ramrod_flags);
  1911. return bnx2x_config_rss(bp, rss);
  1912. }
  1913. int bnx2x_vf_tpa_update(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1914. struct vfpf_tpa_tlv *tlv,
  1915. struct bnx2x_queue_update_tpa_params *params)
  1916. {
  1917. aligned_u64 *sge_addr = tlv->tpa_client_info.sge_addr;
  1918. struct bnx2x_queue_state_params qstate;
  1919. int qid, rc = 0;
  1920. DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid);
  1921. /* Set ramrod params */
  1922. memset(&qstate, 0, sizeof(struct bnx2x_queue_state_params));
  1923. memcpy(&qstate.params.update_tpa, params,
  1924. sizeof(struct bnx2x_queue_update_tpa_params));
  1925. qstate.cmd = BNX2X_Q_CMD_UPDATE_TPA;
  1926. set_bit(RAMROD_COMP_WAIT, &qstate.ramrod_flags);
  1927. for (qid = 0; qid < vf_rxq_count(vf); qid++) {
  1928. qstate.q_obj = &bnx2x_vfq(vf, qid, sp_obj);
  1929. qstate.params.update_tpa.sge_map = sge_addr[qid];
  1930. DP(BNX2X_MSG_IOV, "sge_addr[%d:%d] %08x:%08x\n",
  1931. vf->abs_vfid, qid, U64_HI(sge_addr[qid]),
  1932. U64_LO(sge_addr[qid]));
  1933. rc = bnx2x_queue_state_change(bp, &qstate);
  1934. if (rc) {
  1935. BNX2X_ERR("Failed to configure sge_addr %08x:%08x for [%d:%d]\n",
  1936. U64_HI(sge_addr[qid]), U64_LO(sge_addr[qid]),
  1937. vf->abs_vfid, qid);
  1938. return rc;
  1939. }
  1940. }
  1941. return rc;
  1942. }
  1943. /* VF release ~ VF close + VF release-resources
  1944. * Release is the ultimate SW shutdown and is called whenever an
  1945. * irrecoverable error is encountered.
  1946. */
  1947. int bnx2x_vf_release(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1948. {
  1949. int rc;
  1950. DP(BNX2X_MSG_IOV, "PF releasing vf %d\n", vf->abs_vfid);
  1951. bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_RELEASE_VF);
  1952. rc = bnx2x_vf_free(bp, vf);
  1953. if (rc)
  1954. WARN(rc,
  1955. "VF[%d] Failed to allocate resources for release op- rc=%d\n",
  1956. vf->abs_vfid, rc);
  1957. bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_RELEASE_VF);
  1958. return rc;
  1959. }
  1960. void bnx2x_lock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1961. enum channel_tlvs tlv)
  1962. {
  1963. /* we don't lock the channel for unsupported tlvs */
  1964. if (!bnx2x_tlv_supported(tlv)) {
  1965. BNX2X_ERR("attempting to lock with unsupported tlv. Aborting\n");
  1966. return;
  1967. }
  1968. /* lock the channel */
  1969. mutex_lock(&vf->op_mutex);
  1970. /* record the locking op */
  1971. vf->op_current = tlv;
  1972. /* log the lock */
  1973. DP(BNX2X_MSG_IOV, "VF[%d]: vf pf channel locked by %d\n",
  1974. vf->abs_vfid, tlv);
  1975. }
  1976. void bnx2x_unlock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1977. enum channel_tlvs expected_tlv)
  1978. {
  1979. enum channel_tlvs current_tlv;
  1980. if (!vf) {
  1981. BNX2X_ERR("VF was %p\n", vf);
  1982. return;
  1983. }
  1984. current_tlv = vf->op_current;
  1985. /* we don't unlock the channel for unsupported tlvs */
  1986. if (!bnx2x_tlv_supported(expected_tlv))
  1987. return;
  1988. WARN(expected_tlv != vf->op_current,
  1989. "lock mismatch: expected %d found %d", expected_tlv,
  1990. vf->op_current);
  1991. /* record the locking op */
  1992. vf->op_current = CHANNEL_TLV_NONE;
  1993. /* lock the channel */
  1994. mutex_unlock(&vf->op_mutex);
  1995. /* log the unlock */
  1996. DP(BNX2X_MSG_IOV, "VF[%d]: vf pf channel unlocked by %d\n",
  1997. vf->abs_vfid, current_tlv);
  1998. }
  1999. static int bnx2x_set_pf_tx_switching(struct bnx2x *bp, bool enable)
  2000. {
  2001. struct bnx2x_queue_state_params q_params;
  2002. u32 prev_flags;
  2003. int i, rc;
  2004. /* Verify changes are needed and record current Tx switching state */
  2005. prev_flags = bp->flags;
  2006. if (enable)
  2007. bp->flags |= TX_SWITCHING;
  2008. else
  2009. bp->flags &= ~TX_SWITCHING;
  2010. if (prev_flags == bp->flags)
  2011. return 0;
  2012. /* Verify state enables the sending of queue ramrods */
  2013. if ((bp->state != BNX2X_STATE_OPEN) ||
  2014. (bnx2x_get_q_logical_state(bp,
  2015. &bnx2x_sp_obj(bp, &bp->fp[0]).q_obj) !=
  2016. BNX2X_Q_LOGICAL_STATE_ACTIVE))
  2017. return 0;
  2018. /* send q. update ramrod to configure Tx switching */
  2019. memset(&q_params, 0, sizeof(q_params));
  2020. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  2021. q_params.cmd = BNX2X_Q_CMD_UPDATE;
  2022. __set_bit(BNX2X_Q_UPDATE_TX_SWITCHING_CHNG,
  2023. &q_params.params.update.update_flags);
  2024. if (enable)
  2025. __set_bit(BNX2X_Q_UPDATE_TX_SWITCHING,
  2026. &q_params.params.update.update_flags);
  2027. else
  2028. __clear_bit(BNX2X_Q_UPDATE_TX_SWITCHING,
  2029. &q_params.params.update.update_flags);
  2030. /* send the ramrod on all the queues of the PF */
  2031. for_each_eth_queue(bp, i) {
  2032. struct bnx2x_fastpath *fp = &bp->fp[i];
  2033. /* Set the appropriate Queue object */
  2034. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  2035. /* Update the Queue state */
  2036. rc = bnx2x_queue_state_change(bp, &q_params);
  2037. if (rc) {
  2038. BNX2X_ERR("Failed to configure Tx switching\n");
  2039. return rc;
  2040. }
  2041. }
  2042. DP(BNX2X_MSG_IOV, "%s Tx Switching\n", enable ? "Enabled" : "Disabled");
  2043. return 0;
  2044. }
  2045. int bnx2x_sriov_configure(struct pci_dev *dev, int num_vfs_param)
  2046. {
  2047. struct bnx2x *bp = netdev_priv(pci_get_drvdata(dev));
  2048. if (!IS_SRIOV(bp)) {
  2049. BNX2X_ERR("failed to configure SR-IOV since vfdb was not allocated. Check dmesg for errors in probe stage\n");
  2050. return -EINVAL;
  2051. }
  2052. DP(BNX2X_MSG_IOV, "bnx2x_sriov_configure called with %d, BNX2X_NR_VIRTFN(bp) was %d\n",
  2053. num_vfs_param, BNX2X_NR_VIRTFN(bp));
  2054. /* HW channel is only operational when PF is up */
  2055. if (bp->state != BNX2X_STATE_OPEN) {
  2056. BNX2X_ERR("VF num configuration via sysfs not supported while PF is down\n");
  2057. return -EINVAL;
  2058. }
  2059. /* we are always bound by the total_vfs in the configuration space */
  2060. if (num_vfs_param > BNX2X_NR_VIRTFN(bp)) {
  2061. BNX2X_ERR("truncating requested number of VFs (%d) down to maximum allowed (%d)\n",
  2062. num_vfs_param, BNX2X_NR_VIRTFN(bp));
  2063. num_vfs_param = BNX2X_NR_VIRTFN(bp);
  2064. }
  2065. bp->requested_nr_virtfn = num_vfs_param;
  2066. if (num_vfs_param == 0) {
  2067. bnx2x_set_pf_tx_switching(bp, false);
  2068. bnx2x_disable_sriov(bp);
  2069. return 0;
  2070. } else {
  2071. return bnx2x_enable_sriov(bp);
  2072. }
  2073. }
  2074. #define IGU_ENTRY_SIZE 4
  2075. int bnx2x_enable_sriov(struct bnx2x *bp)
  2076. {
  2077. int rc = 0, req_vfs = bp->requested_nr_virtfn;
  2078. int vf_idx, sb_idx, vfq_idx, qcount, first_vf;
  2079. u32 igu_entry, address;
  2080. u16 num_vf_queues;
  2081. if (req_vfs == 0)
  2082. return 0;
  2083. first_vf = bp->vfdb->sriov.first_vf_in_pf;
  2084. /* statically distribute vf sb pool between VFs */
  2085. num_vf_queues = min_t(u16, BNX2X_VF_MAX_QUEUES,
  2086. BP_VFDB(bp)->vf_sbs_pool / req_vfs);
  2087. /* zero previous values learned from igu cam */
  2088. for (vf_idx = 0; vf_idx < req_vfs; vf_idx++) {
  2089. struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
  2090. vf->sb_count = 0;
  2091. vf_sb_count(BP_VF(bp, vf_idx)) = 0;
  2092. }
  2093. bp->vfdb->vf_sbs_pool = 0;
  2094. /* prepare IGU cam */
  2095. sb_idx = BP_VFDB(bp)->first_vf_igu_entry;
  2096. address = IGU_REG_MAPPING_MEMORY + sb_idx * IGU_ENTRY_SIZE;
  2097. for (vf_idx = first_vf; vf_idx < first_vf + req_vfs; vf_idx++) {
  2098. for (vfq_idx = 0; vfq_idx < num_vf_queues; vfq_idx++) {
  2099. igu_entry = vf_idx << IGU_REG_MAPPING_MEMORY_FID_SHIFT |
  2100. vfq_idx << IGU_REG_MAPPING_MEMORY_VECTOR_SHIFT |
  2101. IGU_REG_MAPPING_MEMORY_VALID;
  2102. DP(BNX2X_MSG_IOV, "assigning sb %d to vf %d\n",
  2103. sb_idx, vf_idx);
  2104. REG_WR(bp, address, igu_entry);
  2105. sb_idx++;
  2106. address += IGU_ENTRY_SIZE;
  2107. }
  2108. }
  2109. /* Reinitialize vf database according to igu cam */
  2110. bnx2x_get_vf_igu_cam_info(bp);
  2111. DP(BNX2X_MSG_IOV, "vf_sbs_pool %d, num_vf_queues %d\n",
  2112. BP_VFDB(bp)->vf_sbs_pool, num_vf_queues);
  2113. qcount = 0;
  2114. for_each_vf(bp, vf_idx) {
  2115. struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
  2116. /* set local queue arrays */
  2117. vf->vfqs = &bp->vfdb->vfqs[qcount];
  2118. qcount += vf_sb_count(vf);
  2119. bnx2x_iov_static_resc(bp, vf);
  2120. }
  2121. /* prepare msix vectors in VF configuration space - the value in the
  2122. * PCI configuration space should be the index of the last entry,
  2123. * namely one less than the actual size of the table
  2124. */
  2125. for (vf_idx = first_vf; vf_idx < first_vf + req_vfs; vf_idx++) {
  2126. bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf_idx));
  2127. REG_WR(bp, PCICFG_OFFSET + GRC_CONFIG_REG_VF_MSIX_CONTROL,
  2128. num_vf_queues - 1);
  2129. DP(BNX2X_MSG_IOV, "set msix vec num in VF %d cfg space to %d\n",
  2130. vf_idx, num_vf_queues - 1);
  2131. }
  2132. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  2133. /* enable sriov. This will probe all the VFs, and consequentially cause
  2134. * the "acquire" messages to appear on the VF PF channel.
  2135. */
  2136. DP(BNX2X_MSG_IOV, "about to call enable sriov\n");
  2137. bnx2x_disable_sriov(bp);
  2138. rc = bnx2x_set_pf_tx_switching(bp, true);
  2139. if (rc)
  2140. return rc;
  2141. rc = pci_enable_sriov(bp->pdev, req_vfs);
  2142. if (rc) {
  2143. BNX2X_ERR("pci_enable_sriov failed with %d\n", rc);
  2144. return rc;
  2145. }
  2146. DP(BNX2X_MSG_IOV, "sriov enabled (%d vfs)\n", req_vfs);
  2147. return req_vfs;
  2148. }
  2149. void bnx2x_pf_set_vfs_vlan(struct bnx2x *bp)
  2150. {
  2151. int vfidx;
  2152. struct pf_vf_bulletin_content *bulletin;
  2153. DP(BNX2X_MSG_IOV, "configuring vlan for VFs from sp-task\n");
  2154. for_each_vf(bp, vfidx) {
  2155. bulletin = BP_VF_BULLETIN(bp, vfidx);
  2156. if (BP_VF(bp, vfidx)->cfg_flags & VF_CFG_VLAN)
  2157. bnx2x_set_vf_vlan(bp->dev, vfidx, bulletin->vlan, 0);
  2158. }
  2159. }
  2160. void bnx2x_disable_sriov(struct bnx2x *bp)
  2161. {
  2162. if (pci_vfs_assigned(bp->pdev)) {
  2163. DP(BNX2X_MSG_IOV,
  2164. "Unloading driver while VFs are assigned - VFs will not be deallocated\n");
  2165. return;
  2166. }
  2167. pci_disable_sriov(bp->pdev);
  2168. }
  2169. static int bnx2x_vf_op_prep(struct bnx2x *bp, int vfidx,
  2170. struct bnx2x_virtf **vf,
  2171. struct pf_vf_bulletin_content **bulletin,
  2172. bool test_queue)
  2173. {
  2174. if (bp->state != BNX2X_STATE_OPEN) {
  2175. BNX2X_ERR("PF is down - can't utilize iov-related functionality\n");
  2176. return -EINVAL;
  2177. }
  2178. if (!IS_SRIOV(bp)) {
  2179. BNX2X_ERR("sriov is disabled - can't utilize iov-related functionality\n");
  2180. return -EINVAL;
  2181. }
  2182. if (vfidx >= BNX2X_NR_VIRTFN(bp)) {
  2183. BNX2X_ERR("VF is uninitialized - can't utilize iov-related functionality. vfidx was %d BNX2X_NR_VIRTFN was %d\n",
  2184. vfidx, BNX2X_NR_VIRTFN(bp));
  2185. return -EINVAL;
  2186. }
  2187. /* init members */
  2188. *vf = BP_VF(bp, vfidx);
  2189. *bulletin = BP_VF_BULLETIN(bp, vfidx);
  2190. if (!*vf) {
  2191. BNX2X_ERR("Unable to get VF structure for vfidx %d\n", vfidx);
  2192. return -EINVAL;
  2193. }
  2194. if (test_queue && !(*vf)->vfqs) {
  2195. BNX2X_ERR("vfqs struct is null. Was this invoked before dynamically enabling SR-IOV? vfidx was %d\n",
  2196. vfidx);
  2197. return -EINVAL;
  2198. }
  2199. if (!*bulletin) {
  2200. BNX2X_ERR("Bulletin Board struct is null for vfidx %d\n",
  2201. vfidx);
  2202. return -EINVAL;
  2203. }
  2204. return 0;
  2205. }
  2206. int bnx2x_get_vf_config(struct net_device *dev, int vfidx,
  2207. struct ifla_vf_info *ivi)
  2208. {
  2209. struct bnx2x *bp = netdev_priv(dev);
  2210. struct bnx2x_virtf *vf = NULL;
  2211. struct pf_vf_bulletin_content *bulletin = NULL;
  2212. struct bnx2x_vlan_mac_obj *mac_obj;
  2213. struct bnx2x_vlan_mac_obj *vlan_obj;
  2214. int rc;
  2215. /* sanity and init */
  2216. rc = bnx2x_vf_op_prep(bp, vfidx, &vf, &bulletin, true);
  2217. if (rc)
  2218. return rc;
  2219. mac_obj = &bnx2x_leading_vfq(vf, mac_obj);
  2220. vlan_obj = &bnx2x_leading_vfq(vf, vlan_obj);
  2221. if (!mac_obj || !vlan_obj) {
  2222. BNX2X_ERR("VF partially initialized\n");
  2223. return -EINVAL;
  2224. }
  2225. ivi->vf = vfidx;
  2226. ivi->qos = 0;
  2227. ivi->max_tx_rate = 10000; /* always 10G. TBA take from link struct */
  2228. ivi->min_tx_rate = 0;
  2229. ivi->spoofchk = 1; /*always enabled */
  2230. if (vf->state == VF_ENABLED) {
  2231. /* mac and vlan are in vlan_mac objects */
  2232. if (bnx2x_validate_vf_sp_objs(bp, vf, false)) {
  2233. mac_obj->get_n_elements(bp, mac_obj, 1, (u8 *)&ivi->mac,
  2234. 0, ETH_ALEN);
  2235. vlan_obj->get_n_elements(bp, vlan_obj, 1,
  2236. (u8 *)&ivi->vlan, 0,
  2237. VLAN_HLEN);
  2238. }
  2239. } else {
  2240. mutex_lock(&bp->vfdb->bulletin_mutex);
  2241. /* mac */
  2242. if (bulletin->valid_bitmap & (1 << MAC_ADDR_VALID))
  2243. /* mac configured by ndo so its in bulletin board */
  2244. memcpy(&ivi->mac, bulletin->mac, ETH_ALEN);
  2245. else
  2246. /* function has not been loaded yet. Show mac as 0s */
  2247. eth_zero_addr(ivi->mac);
  2248. /* vlan */
  2249. if (bulletin->valid_bitmap & (1 << VLAN_VALID))
  2250. /* vlan configured by ndo so its in bulletin board */
  2251. memcpy(&ivi->vlan, &bulletin->vlan, VLAN_HLEN);
  2252. else
  2253. /* function has not been loaded yet. Show vlans as 0s */
  2254. memset(&ivi->vlan, 0, VLAN_HLEN);
  2255. mutex_unlock(&bp->vfdb->bulletin_mutex);
  2256. }
  2257. return 0;
  2258. }
  2259. /* New mac for VF. Consider these cases:
  2260. * 1. VF hasn't been acquired yet - save the mac in local bulletin board and
  2261. * supply at acquire.
  2262. * 2. VF has already been acquired but has not yet initialized - store in local
  2263. * bulletin board. mac will be posted on VF bulletin board after VF init. VF
  2264. * will configure this mac when it is ready.
  2265. * 3. VF has already initialized but has not yet setup a queue - post the new
  2266. * mac on VF's bulletin board right now. VF will configure this mac when it
  2267. * is ready.
  2268. * 4. VF has already set a queue - delete any macs already configured for this
  2269. * queue and manually config the new mac.
  2270. * In any event, once this function has been called refuse any attempts by the
  2271. * VF to configure any mac for itself except for this mac. In case of a race
  2272. * where the VF fails to see the new post on its bulletin board before sending a
  2273. * mac configuration request, the PF will simply fail the request and VF can try
  2274. * again after consulting its bulletin board.
  2275. */
  2276. int bnx2x_set_vf_mac(struct net_device *dev, int vfidx, u8 *mac)
  2277. {
  2278. struct bnx2x *bp = netdev_priv(dev);
  2279. int rc, q_logical_state;
  2280. struct bnx2x_virtf *vf = NULL;
  2281. struct pf_vf_bulletin_content *bulletin = NULL;
  2282. if (!is_valid_ether_addr(mac)) {
  2283. BNX2X_ERR("mac address invalid\n");
  2284. return -EINVAL;
  2285. }
  2286. /* sanity and init */
  2287. rc = bnx2x_vf_op_prep(bp, vfidx, &vf, &bulletin, true);
  2288. if (rc)
  2289. return rc;
  2290. mutex_lock(&bp->vfdb->bulletin_mutex);
  2291. /* update PF's copy of the VF's bulletin. Will no longer accept mac
  2292. * configuration requests from vf unless match this mac
  2293. */
  2294. bulletin->valid_bitmap |= 1 << MAC_ADDR_VALID;
  2295. memcpy(bulletin->mac, mac, ETH_ALEN);
  2296. /* Post update on VF's bulletin board */
  2297. rc = bnx2x_post_vf_bulletin(bp, vfidx);
  2298. /* release lock before checking return code */
  2299. mutex_unlock(&bp->vfdb->bulletin_mutex);
  2300. if (rc) {
  2301. BNX2X_ERR("failed to update VF[%d] bulletin\n", vfidx);
  2302. return rc;
  2303. }
  2304. q_logical_state =
  2305. bnx2x_get_q_logical_state(bp, &bnx2x_leading_vfq(vf, sp_obj));
  2306. if (vf->state == VF_ENABLED &&
  2307. q_logical_state == BNX2X_Q_LOGICAL_STATE_ACTIVE) {
  2308. /* configure the mac in device on this vf's queue */
  2309. unsigned long ramrod_flags = 0;
  2310. struct bnx2x_vlan_mac_obj *mac_obj;
  2311. /* User should be able to see failure reason in system logs */
  2312. if (!bnx2x_validate_vf_sp_objs(bp, vf, true))
  2313. return -EINVAL;
  2314. /* must lock vfpf channel to protect against vf flows */
  2315. bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_MAC);
  2316. /* remove existing eth macs */
  2317. mac_obj = &bnx2x_leading_vfq(vf, mac_obj);
  2318. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_ETH_MAC, true);
  2319. if (rc) {
  2320. BNX2X_ERR("failed to delete eth macs\n");
  2321. rc = -EINVAL;
  2322. goto out;
  2323. }
  2324. /* remove existing uc list macs */
  2325. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, true);
  2326. if (rc) {
  2327. BNX2X_ERR("failed to delete uc_list macs\n");
  2328. rc = -EINVAL;
  2329. goto out;
  2330. }
  2331. /* configure the new mac to device */
  2332. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  2333. bnx2x_set_mac_one(bp, (u8 *)&bulletin->mac, mac_obj, true,
  2334. BNX2X_ETH_MAC, &ramrod_flags);
  2335. out:
  2336. bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_MAC);
  2337. }
  2338. return rc;
  2339. }
  2340. int bnx2x_set_vf_vlan(struct net_device *dev, int vfidx, u16 vlan, u8 qos)
  2341. {
  2342. struct bnx2x_queue_state_params q_params = {NULL};
  2343. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  2344. struct bnx2x_queue_update_params *update_params;
  2345. struct pf_vf_bulletin_content *bulletin = NULL;
  2346. struct bnx2x_rx_mode_ramrod_params rx_ramrod;
  2347. struct bnx2x *bp = netdev_priv(dev);
  2348. struct bnx2x_vlan_mac_obj *vlan_obj;
  2349. unsigned long vlan_mac_flags = 0;
  2350. unsigned long ramrod_flags = 0;
  2351. struct bnx2x_virtf *vf = NULL;
  2352. unsigned long accept_flags;
  2353. int rc;
  2354. if (vlan > 4095) {
  2355. BNX2X_ERR("illegal vlan value %d\n", vlan);
  2356. return -EINVAL;
  2357. }
  2358. DP(BNX2X_MSG_IOV, "configuring VF %d with VLAN %d qos %d\n",
  2359. vfidx, vlan, 0);
  2360. /* sanity and init */
  2361. rc = bnx2x_vf_op_prep(bp, vfidx, &vf, &bulletin, true);
  2362. if (rc)
  2363. return rc;
  2364. /* update PF's copy of the VF's bulletin. No point in posting the vlan
  2365. * to the VF since it doesn't have anything to do with it. But it useful
  2366. * to store it here in case the VF is not up yet and we can only
  2367. * configure the vlan later when it does. Treat vlan id 0 as remove the
  2368. * Host tag.
  2369. */
  2370. mutex_lock(&bp->vfdb->bulletin_mutex);
  2371. if (vlan > 0)
  2372. bulletin->valid_bitmap |= 1 << VLAN_VALID;
  2373. else
  2374. bulletin->valid_bitmap &= ~(1 << VLAN_VALID);
  2375. bulletin->vlan = vlan;
  2376. mutex_unlock(&bp->vfdb->bulletin_mutex);
  2377. /* is vf initialized and queue set up? */
  2378. if (vf->state != VF_ENABLED ||
  2379. bnx2x_get_q_logical_state(bp, &bnx2x_leading_vfq(vf, sp_obj)) !=
  2380. BNX2X_Q_LOGICAL_STATE_ACTIVE)
  2381. return rc;
  2382. /* User should be able to see error in system logs */
  2383. if (!bnx2x_validate_vf_sp_objs(bp, vf, true))
  2384. return -EINVAL;
  2385. /* must lock vfpf channel to protect against vf flows */
  2386. bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_VLAN);
  2387. /* remove existing vlans */
  2388. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  2389. vlan_obj = &bnx2x_leading_vfq(vf, vlan_obj);
  2390. rc = vlan_obj->delete_all(bp, vlan_obj, &vlan_mac_flags,
  2391. &ramrod_flags);
  2392. if (rc) {
  2393. BNX2X_ERR("failed to delete vlans\n");
  2394. rc = -EINVAL;
  2395. goto out;
  2396. }
  2397. /* need to remove/add the VF's accept_any_vlan bit */
  2398. accept_flags = bnx2x_leading_vfq(vf, accept_flags);
  2399. if (vlan)
  2400. clear_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  2401. else
  2402. set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  2403. bnx2x_vf_prep_rx_mode(bp, LEADING_IDX, &rx_ramrod, vf,
  2404. accept_flags);
  2405. bnx2x_leading_vfq(vf, accept_flags) = accept_flags;
  2406. bnx2x_config_rx_mode(bp, &rx_ramrod);
  2407. /* configure the new vlan to device */
  2408. memset(&ramrod_param, 0, sizeof(ramrod_param));
  2409. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  2410. ramrod_param.vlan_mac_obj = vlan_obj;
  2411. ramrod_param.ramrod_flags = ramrod_flags;
  2412. set_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
  2413. &ramrod_param.user_req.vlan_mac_flags);
  2414. ramrod_param.user_req.u.vlan.vlan = vlan;
  2415. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  2416. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  2417. if (rc) {
  2418. BNX2X_ERR("failed to configure vlan\n");
  2419. rc = -EINVAL;
  2420. goto out;
  2421. }
  2422. /* send queue update ramrod to configure default vlan and silent
  2423. * vlan removal
  2424. */
  2425. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  2426. q_params.cmd = BNX2X_Q_CMD_UPDATE;
  2427. q_params.q_obj = &bnx2x_leading_vfq(vf, sp_obj);
  2428. update_params = &q_params.params.update;
  2429. __set_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN_CHNG,
  2430. &update_params->update_flags);
  2431. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  2432. &update_params->update_flags);
  2433. if (vlan == 0) {
  2434. /* if vlan is 0 then we want to leave the VF traffic
  2435. * untagged, and leave the incoming traffic untouched
  2436. * (i.e. do not remove any vlan tags).
  2437. */
  2438. __clear_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN,
  2439. &update_params->update_flags);
  2440. __clear_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  2441. &update_params->update_flags);
  2442. } else {
  2443. /* configure default vlan to vf queue and set silent
  2444. * vlan removal (the vf remains unaware of this vlan).
  2445. */
  2446. __set_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN,
  2447. &update_params->update_flags);
  2448. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  2449. &update_params->update_flags);
  2450. update_params->def_vlan = vlan;
  2451. update_params->silent_removal_value =
  2452. vlan & VLAN_VID_MASK;
  2453. update_params->silent_removal_mask = VLAN_VID_MASK;
  2454. }
  2455. /* Update the Queue state */
  2456. rc = bnx2x_queue_state_change(bp, &q_params);
  2457. if (rc) {
  2458. BNX2X_ERR("Failed to configure default VLAN\n");
  2459. goto out;
  2460. }
  2461. /* clear the flag indicating that this VF needs its vlan
  2462. * (will only be set if the HV configured the Vlan before vf was
  2463. * up and we were called because the VF came up later
  2464. */
  2465. out:
  2466. vf->cfg_flags &= ~VF_CFG_VLAN;
  2467. bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_VLAN);
  2468. return rc;
  2469. }
  2470. /* crc is the first field in the bulletin board. Compute the crc over the
  2471. * entire bulletin board excluding the crc field itself. Use the length field
  2472. * as the Bulletin Board was posted by a PF with possibly a different version
  2473. * from the vf which will sample it. Therefore, the length is computed by the
  2474. * PF and then used blindly by the VF.
  2475. */
  2476. u32 bnx2x_crc_vf_bulletin(struct pf_vf_bulletin_content *bulletin)
  2477. {
  2478. return crc32(BULLETIN_CRC_SEED,
  2479. ((u8 *)bulletin) + sizeof(bulletin->crc),
  2480. bulletin->length - sizeof(bulletin->crc));
  2481. }
  2482. /* Check for new posts on the bulletin board */
  2483. enum sample_bulletin_result bnx2x_sample_bulletin(struct bnx2x *bp)
  2484. {
  2485. struct pf_vf_bulletin_content *bulletin;
  2486. int attempts;
  2487. /* sampling structure in mid post may result with corrupted data
  2488. * validate crc to ensure coherency.
  2489. */
  2490. for (attempts = 0; attempts < BULLETIN_ATTEMPTS; attempts++) {
  2491. u32 crc;
  2492. /* sample the bulletin board */
  2493. memcpy(&bp->shadow_bulletin, bp->pf2vf_bulletin,
  2494. sizeof(union pf_vf_bulletin));
  2495. crc = bnx2x_crc_vf_bulletin(&bp->shadow_bulletin.content);
  2496. if (bp->shadow_bulletin.content.crc == crc)
  2497. break;
  2498. BNX2X_ERR("bad crc on bulletin board. Contained %x computed %x\n",
  2499. bp->shadow_bulletin.content.crc, crc);
  2500. }
  2501. if (attempts >= BULLETIN_ATTEMPTS) {
  2502. BNX2X_ERR("pf to vf bulletin board crc was wrong %d consecutive times. Aborting\n",
  2503. attempts);
  2504. return PFVF_BULLETIN_CRC_ERR;
  2505. }
  2506. bulletin = &bp->shadow_bulletin.content;
  2507. /* bulletin board hasn't changed since last sample */
  2508. if (bp->old_bulletin.version == bulletin->version)
  2509. return PFVF_BULLETIN_UNCHANGED;
  2510. /* the mac address in bulletin board is valid and is new */
  2511. if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID &&
  2512. !ether_addr_equal(bulletin->mac, bp->old_bulletin.mac)) {
  2513. /* update new mac to net device */
  2514. memcpy(bp->dev->dev_addr, bulletin->mac, ETH_ALEN);
  2515. }
  2516. if (bulletin->valid_bitmap & (1 << LINK_VALID)) {
  2517. DP(BNX2X_MSG_IOV, "link update speed %d flags %x\n",
  2518. bulletin->link_speed, bulletin->link_flags);
  2519. bp->vf_link_vars.line_speed = bulletin->link_speed;
  2520. bp->vf_link_vars.link_report_flags = 0;
  2521. /* Link is down */
  2522. if (bulletin->link_flags & VFPF_LINK_REPORT_LINK_DOWN)
  2523. __set_bit(BNX2X_LINK_REPORT_LINK_DOWN,
  2524. &bp->vf_link_vars.link_report_flags);
  2525. /* Full DUPLEX */
  2526. if (bulletin->link_flags & VFPF_LINK_REPORT_FULL_DUPLEX)
  2527. __set_bit(BNX2X_LINK_REPORT_FD,
  2528. &bp->vf_link_vars.link_report_flags);
  2529. /* Rx Flow Control is ON */
  2530. if (bulletin->link_flags & VFPF_LINK_REPORT_RX_FC_ON)
  2531. __set_bit(BNX2X_LINK_REPORT_RX_FC_ON,
  2532. &bp->vf_link_vars.link_report_flags);
  2533. /* Tx Flow Control is ON */
  2534. if (bulletin->link_flags & VFPF_LINK_REPORT_TX_FC_ON)
  2535. __set_bit(BNX2X_LINK_REPORT_TX_FC_ON,
  2536. &bp->vf_link_vars.link_report_flags);
  2537. __bnx2x_link_report(bp);
  2538. }
  2539. /* copy new bulletin board to bp */
  2540. memcpy(&bp->old_bulletin, bulletin,
  2541. sizeof(struct pf_vf_bulletin_content));
  2542. return PFVF_BULLETIN_UPDATED;
  2543. }
  2544. void bnx2x_timer_sriov(struct bnx2x *bp)
  2545. {
  2546. bnx2x_sample_bulletin(bp);
  2547. /* if channel is down we need to self destruct */
  2548. if (bp->old_bulletin.valid_bitmap & 1 << CHANNEL_DOWN)
  2549. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  2550. BNX2X_MSG_IOV);
  2551. }
  2552. void __iomem *bnx2x_vf_doorbells(struct bnx2x *bp)
  2553. {
  2554. /* vf doorbells are embedded within the regview */
  2555. return bp->regview + PXP_VF_ADDR_DB_START;
  2556. }
  2557. void bnx2x_vf_pci_dealloc(struct bnx2x *bp)
  2558. {
  2559. BNX2X_PCI_FREE(bp->vf2pf_mbox, bp->vf2pf_mbox_mapping,
  2560. sizeof(struct bnx2x_vf_mbx_msg));
  2561. BNX2X_PCI_FREE(bp->vf2pf_mbox, bp->pf2vf_bulletin_mapping,
  2562. sizeof(union pf_vf_bulletin));
  2563. }
  2564. int bnx2x_vf_pci_alloc(struct bnx2x *bp)
  2565. {
  2566. mutex_init(&bp->vf2pf_mutex);
  2567. /* allocate vf2pf mailbox for vf to pf channel */
  2568. bp->vf2pf_mbox = BNX2X_PCI_ALLOC(&bp->vf2pf_mbox_mapping,
  2569. sizeof(struct bnx2x_vf_mbx_msg));
  2570. if (!bp->vf2pf_mbox)
  2571. goto alloc_mem_err;
  2572. /* allocate pf 2 vf bulletin board */
  2573. bp->pf2vf_bulletin = BNX2X_PCI_ALLOC(&bp->pf2vf_bulletin_mapping,
  2574. sizeof(union pf_vf_bulletin));
  2575. if (!bp->pf2vf_bulletin)
  2576. goto alloc_mem_err;
  2577. bnx2x_vf_bulletin_finalize(&bp->pf2vf_bulletin->content, true);
  2578. return 0;
  2579. alloc_mem_err:
  2580. bnx2x_vf_pci_dealloc(bp);
  2581. return -ENOMEM;
  2582. }
  2583. void bnx2x_iov_channel_down(struct bnx2x *bp)
  2584. {
  2585. int vf_idx;
  2586. struct pf_vf_bulletin_content *bulletin;
  2587. if (!IS_SRIOV(bp))
  2588. return;
  2589. for_each_vf(bp, vf_idx) {
  2590. /* locate this VFs bulletin board and update the channel down
  2591. * bit
  2592. */
  2593. bulletin = BP_VF_BULLETIN(bp, vf_idx);
  2594. bulletin->valid_bitmap |= 1 << CHANNEL_DOWN;
  2595. /* update vf bulletin board */
  2596. bnx2x_post_vf_bulletin(bp, vf_idx);
  2597. }
  2598. }
  2599. void bnx2x_iov_task(struct work_struct *work)
  2600. {
  2601. struct bnx2x *bp = container_of(work, struct bnx2x, iov_task.work);
  2602. if (!netif_running(bp->dev))
  2603. return;
  2604. if (test_and_clear_bit(BNX2X_IOV_HANDLE_FLR,
  2605. &bp->iov_task_state))
  2606. bnx2x_vf_handle_flr_event(bp);
  2607. if (test_and_clear_bit(BNX2X_IOV_HANDLE_VF_MSG,
  2608. &bp->iov_task_state))
  2609. bnx2x_vf_mbx(bp);
  2610. }
  2611. void bnx2x_schedule_iov_task(struct bnx2x *bp, enum bnx2x_iov_flag flag)
  2612. {
  2613. smp_mb__before_atomic();
  2614. set_bit(flag, &bp->iov_task_state);
  2615. smp_mb__after_atomic();
  2616. DP(BNX2X_MSG_IOV, "Scheduling iov task [Flag: %d]\n", flag);
  2617. queue_delayed_work(bnx2x_iov_wq, &bp->iov_task, 0);
  2618. }