bnx2x_sriov.c 86 KB

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