qed_dev.c 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143
  1. /* QLogic qed NIC Driver
  2. * Copyright (c) 2015 QLogic Corporation
  3. *
  4. * This software is available under the terms of the GNU General Public License
  5. * (GPL) Version 2, available from the file COPYING in the main directory of
  6. * this source tree.
  7. */
  8. #include <linux/types.h>
  9. #include <asm/byteorder.h>
  10. #include <linux/io.h>
  11. #include <linux/delay.h>
  12. #include <linux/dma-mapping.h>
  13. #include <linux/errno.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mutex.h>
  16. #include <linux/pci.h>
  17. #include <linux/slab.h>
  18. #include <linux/string.h>
  19. #include <linux/vmalloc.h>
  20. #include <linux/etherdevice.h>
  21. #include <linux/qed/qed_chain.h>
  22. #include <linux/qed/qed_if.h>
  23. #include "qed.h"
  24. #include "qed_cxt.h"
  25. #include "qed_dcbx.h"
  26. #include "qed_dev_api.h"
  27. #include "qed_hsi.h"
  28. #include "qed_hw.h"
  29. #include "qed_init_ops.h"
  30. #include "qed_int.h"
  31. #include "qed_iscsi.h"
  32. #include "qed_ll2.h"
  33. #include "qed_mcp.h"
  34. #include "qed_ooo.h"
  35. #include "qed_reg_addr.h"
  36. #include "qed_sp.h"
  37. #include "qed_sriov.h"
  38. #include "qed_vf.h"
  39. #include "qed_roce.h"
  40. static DEFINE_SPINLOCK(qm_lock);
  41. #define QED_MIN_DPIS (4)
  42. #define QED_MIN_PWM_REGION (QED_WID_SIZE * QED_MIN_DPIS)
  43. /* API common to all protocols */
  44. enum BAR_ID {
  45. BAR_ID_0, /* used for GRC */
  46. BAR_ID_1 /* Used for doorbells */
  47. };
  48. static u32 qed_hw_bar_size(struct qed_hwfn *p_hwfn, enum BAR_ID bar_id)
  49. {
  50. u32 bar_reg = (bar_id == BAR_ID_0 ?
  51. PGLUE_B_REG_PF_BAR0_SIZE : PGLUE_B_REG_PF_BAR1_SIZE);
  52. u32 val;
  53. if (IS_VF(p_hwfn->cdev))
  54. return 1 << 17;
  55. val = qed_rd(p_hwfn, p_hwfn->p_main_ptt, bar_reg);
  56. if (val)
  57. return 1 << (val + 15);
  58. /* Old MFW initialized above registered only conditionally */
  59. if (p_hwfn->cdev->num_hwfns > 1) {
  60. DP_INFO(p_hwfn,
  61. "BAR size not configured. Assuming BAR size of 256kB for GRC and 512kB for DB\n");
  62. return BAR_ID_0 ? 256 * 1024 : 512 * 1024;
  63. } else {
  64. DP_INFO(p_hwfn,
  65. "BAR size not configured. Assuming BAR size of 512kB for GRC and 512kB for DB\n");
  66. return 512 * 1024;
  67. }
  68. }
  69. void qed_init_dp(struct qed_dev *cdev, u32 dp_module, u8 dp_level)
  70. {
  71. u32 i;
  72. cdev->dp_level = dp_level;
  73. cdev->dp_module = dp_module;
  74. for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
  75. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  76. p_hwfn->dp_level = dp_level;
  77. p_hwfn->dp_module = dp_module;
  78. }
  79. }
  80. void qed_init_struct(struct qed_dev *cdev)
  81. {
  82. u8 i;
  83. for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
  84. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  85. p_hwfn->cdev = cdev;
  86. p_hwfn->my_id = i;
  87. p_hwfn->b_active = false;
  88. mutex_init(&p_hwfn->dmae_info.mutex);
  89. }
  90. /* hwfn 0 is always active */
  91. cdev->hwfns[0].b_active = true;
  92. /* set the default cache alignment to 128 */
  93. cdev->cache_shift = 7;
  94. }
  95. static void qed_qm_info_free(struct qed_hwfn *p_hwfn)
  96. {
  97. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  98. kfree(qm_info->qm_pq_params);
  99. qm_info->qm_pq_params = NULL;
  100. kfree(qm_info->qm_vport_params);
  101. qm_info->qm_vport_params = NULL;
  102. kfree(qm_info->qm_port_params);
  103. qm_info->qm_port_params = NULL;
  104. kfree(qm_info->wfq_data);
  105. qm_info->wfq_data = NULL;
  106. }
  107. void qed_resc_free(struct qed_dev *cdev)
  108. {
  109. int i;
  110. if (IS_VF(cdev))
  111. return;
  112. kfree(cdev->fw_data);
  113. cdev->fw_data = NULL;
  114. kfree(cdev->reset_stats);
  115. for_each_hwfn(cdev, i) {
  116. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  117. qed_cxt_mngr_free(p_hwfn);
  118. qed_qm_info_free(p_hwfn);
  119. qed_spq_free(p_hwfn);
  120. qed_eq_free(p_hwfn, p_hwfn->p_eq);
  121. qed_consq_free(p_hwfn, p_hwfn->p_consq);
  122. qed_int_free(p_hwfn);
  123. #ifdef CONFIG_QED_LL2
  124. qed_ll2_free(p_hwfn, p_hwfn->p_ll2_info);
  125. #endif
  126. if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
  127. qed_iscsi_free(p_hwfn, p_hwfn->p_iscsi_info);
  128. qed_ooo_free(p_hwfn, p_hwfn->p_ooo_info);
  129. }
  130. qed_iov_free(p_hwfn);
  131. qed_dmae_info_free(p_hwfn);
  132. qed_dcbx_info_free(p_hwfn, p_hwfn->p_dcbx_info);
  133. }
  134. }
  135. static int qed_init_qm_info(struct qed_hwfn *p_hwfn, bool b_sleepable)
  136. {
  137. u8 num_vports, vf_offset = 0, i, vport_id, num_ports, curr_queue = 0;
  138. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  139. struct init_qm_port_params *p_qm_port;
  140. bool init_rdma_offload_pq = false;
  141. bool init_pure_ack_pq = false;
  142. bool init_ooo_pq = false;
  143. u16 num_pqs, multi_cos_tcs = 1;
  144. u8 pf_wfq = qm_info->pf_wfq;
  145. u32 pf_rl = qm_info->pf_rl;
  146. u16 num_pf_rls = 0;
  147. u16 num_vfs = 0;
  148. #ifdef CONFIG_QED_SRIOV
  149. if (p_hwfn->cdev->p_iov_info)
  150. num_vfs = p_hwfn->cdev->p_iov_info->total_vfs;
  151. #endif
  152. memset(qm_info, 0, sizeof(*qm_info));
  153. num_pqs = multi_cos_tcs + num_vfs + 1; /* The '1' is for pure-LB */
  154. num_vports = (u8)RESC_NUM(p_hwfn, QED_VPORT);
  155. if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) {
  156. num_pqs++; /* for RoCE queue */
  157. init_rdma_offload_pq = true;
  158. /* we subtract num_vfs because each require a rate limiter,
  159. * and one default rate limiter
  160. */
  161. if (p_hwfn->pf_params.rdma_pf_params.enable_dcqcn)
  162. num_pf_rls = RESC_NUM(p_hwfn, QED_RL) - num_vfs - 1;
  163. num_pqs += num_pf_rls;
  164. qm_info->num_pf_rls = (u8) num_pf_rls;
  165. }
  166. if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
  167. num_pqs += 2; /* for iSCSI pure-ACK / OOO queue */
  168. init_pure_ack_pq = true;
  169. init_ooo_pq = true;
  170. }
  171. /* Sanity checking that setup requires legal number of resources */
  172. if (num_pqs > RESC_NUM(p_hwfn, QED_PQ)) {
  173. DP_ERR(p_hwfn,
  174. "Need too many Physical queues - 0x%04x when only %04x are available\n",
  175. num_pqs, RESC_NUM(p_hwfn, QED_PQ));
  176. return -EINVAL;
  177. }
  178. /* PQs will be arranged as follows: First per-TC PQ then pure-LB quete.
  179. */
  180. qm_info->qm_pq_params = kcalloc(num_pqs,
  181. sizeof(struct init_qm_pq_params),
  182. b_sleepable ? GFP_KERNEL : GFP_ATOMIC);
  183. if (!qm_info->qm_pq_params)
  184. goto alloc_err;
  185. qm_info->qm_vport_params = kcalloc(num_vports,
  186. sizeof(struct init_qm_vport_params),
  187. b_sleepable ? GFP_KERNEL
  188. : GFP_ATOMIC);
  189. if (!qm_info->qm_vport_params)
  190. goto alloc_err;
  191. qm_info->qm_port_params = kcalloc(MAX_NUM_PORTS,
  192. sizeof(struct init_qm_port_params),
  193. b_sleepable ? GFP_KERNEL
  194. : GFP_ATOMIC);
  195. if (!qm_info->qm_port_params)
  196. goto alloc_err;
  197. qm_info->wfq_data = kcalloc(num_vports, sizeof(struct qed_wfq_data),
  198. b_sleepable ? GFP_KERNEL : GFP_ATOMIC);
  199. if (!qm_info->wfq_data)
  200. goto alloc_err;
  201. vport_id = (u8)RESC_START(p_hwfn, QED_VPORT);
  202. /* First init rate limited queues */
  203. for (curr_queue = 0; curr_queue < num_pf_rls; curr_queue++) {
  204. qm_info->qm_pq_params[curr_queue].vport_id = vport_id++;
  205. qm_info->qm_pq_params[curr_queue].tc_id =
  206. p_hwfn->hw_info.non_offload_tc;
  207. qm_info->qm_pq_params[curr_queue].wrr_group = 1;
  208. qm_info->qm_pq_params[curr_queue].rl_valid = 1;
  209. }
  210. /* First init per-TC PQs */
  211. for (i = 0; i < multi_cos_tcs; i++) {
  212. struct init_qm_pq_params *params =
  213. &qm_info->qm_pq_params[curr_queue++];
  214. if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE ||
  215. p_hwfn->hw_info.personality == QED_PCI_ETH) {
  216. params->vport_id = vport_id;
  217. params->tc_id = p_hwfn->hw_info.non_offload_tc;
  218. params->wrr_group = 1;
  219. } else {
  220. params->vport_id = vport_id;
  221. params->tc_id = p_hwfn->hw_info.offload_tc;
  222. params->wrr_group = 1;
  223. }
  224. }
  225. /* Then init pure-LB PQ */
  226. qm_info->pure_lb_pq = curr_queue;
  227. qm_info->qm_pq_params[curr_queue].vport_id =
  228. (u8) RESC_START(p_hwfn, QED_VPORT);
  229. qm_info->qm_pq_params[curr_queue].tc_id = PURE_LB_TC;
  230. qm_info->qm_pq_params[curr_queue].wrr_group = 1;
  231. curr_queue++;
  232. qm_info->offload_pq = 0;
  233. if (init_rdma_offload_pq) {
  234. qm_info->offload_pq = curr_queue;
  235. qm_info->qm_pq_params[curr_queue].vport_id = vport_id;
  236. qm_info->qm_pq_params[curr_queue].tc_id =
  237. p_hwfn->hw_info.offload_tc;
  238. qm_info->qm_pq_params[curr_queue].wrr_group = 1;
  239. curr_queue++;
  240. }
  241. if (init_pure_ack_pq) {
  242. qm_info->pure_ack_pq = curr_queue;
  243. qm_info->qm_pq_params[curr_queue].vport_id = vport_id;
  244. qm_info->qm_pq_params[curr_queue].tc_id =
  245. p_hwfn->hw_info.offload_tc;
  246. qm_info->qm_pq_params[curr_queue].wrr_group = 1;
  247. curr_queue++;
  248. }
  249. if (init_ooo_pq) {
  250. qm_info->ooo_pq = curr_queue;
  251. qm_info->qm_pq_params[curr_queue].vport_id = vport_id;
  252. qm_info->qm_pq_params[curr_queue].tc_id = DCBX_ISCSI_OOO_TC;
  253. qm_info->qm_pq_params[curr_queue].wrr_group = 1;
  254. curr_queue++;
  255. }
  256. /* Then init per-VF PQs */
  257. vf_offset = curr_queue;
  258. for (i = 0; i < num_vfs; i++) {
  259. /* First vport is used by the PF */
  260. qm_info->qm_pq_params[curr_queue].vport_id = vport_id + i + 1;
  261. qm_info->qm_pq_params[curr_queue].tc_id =
  262. p_hwfn->hw_info.non_offload_tc;
  263. qm_info->qm_pq_params[curr_queue].wrr_group = 1;
  264. qm_info->qm_pq_params[curr_queue].rl_valid = 1;
  265. curr_queue++;
  266. }
  267. qm_info->vf_queues_offset = vf_offset;
  268. qm_info->num_pqs = num_pqs;
  269. qm_info->num_vports = num_vports;
  270. /* Initialize qm port parameters */
  271. num_ports = p_hwfn->cdev->num_ports_in_engines;
  272. for (i = 0; i < num_ports; i++) {
  273. p_qm_port = &qm_info->qm_port_params[i];
  274. p_qm_port->active = 1;
  275. if (num_ports == 4)
  276. p_qm_port->active_phys_tcs = 0x7;
  277. else
  278. p_qm_port->active_phys_tcs = 0x9f;
  279. p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports;
  280. p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
  281. }
  282. qm_info->max_phys_tcs_per_port = NUM_OF_PHYS_TCS;
  283. qm_info->start_pq = (u16)RESC_START(p_hwfn, QED_PQ);
  284. qm_info->num_vf_pqs = num_vfs;
  285. qm_info->start_vport = (u8) RESC_START(p_hwfn, QED_VPORT);
  286. for (i = 0; i < qm_info->num_vports; i++)
  287. qm_info->qm_vport_params[i].vport_wfq = 1;
  288. qm_info->vport_rl_en = 1;
  289. qm_info->vport_wfq_en = 1;
  290. qm_info->pf_rl = pf_rl;
  291. qm_info->pf_wfq = pf_wfq;
  292. return 0;
  293. alloc_err:
  294. qed_qm_info_free(p_hwfn);
  295. return -ENOMEM;
  296. }
  297. /* This function reconfigures the QM pf on the fly.
  298. * For this purpose we:
  299. * 1. reconfigure the QM database
  300. * 2. set new values to runtime arrat
  301. * 3. send an sdm_qm_cmd through the rbc interface to stop the QM
  302. * 4. activate init tool in QM_PF stage
  303. * 5. send an sdm_qm_cmd through rbc interface to release the QM
  304. */
  305. int qed_qm_reconf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  306. {
  307. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  308. bool b_rc;
  309. int rc;
  310. /* qm_info is allocated in qed_init_qm_info() which is already called
  311. * from qed_resc_alloc() or previous call of qed_qm_reconf().
  312. * The allocated size may change each init, so we free it before next
  313. * allocation.
  314. */
  315. qed_qm_info_free(p_hwfn);
  316. /* initialize qed's qm data structure */
  317. rc = qed_init_qm_info(p_hwfn, false);
  318. if (rc)
  319. return rc;
  320. /* stop PF's qm queues */
  321. spin_lock_bh(&qm_lock);
  322. b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, false, true,
  323. qm_info->start_pq, qm_info->num_pqs);
  324. spin_unlock_bh(&qm_lock);
  325. if (!b_rc)
  326. return -EINVAL;
  327. /* clear the QM_PF runtime phase leftovers from previous init */
  328. qed_init_clear_rt_data(p_hwfn);
  329. /* prepare QM portion of runtime array */
  330. qed_qm_init_pf(p_hwfn);
  331. /* activate init tool on runtime array */
  332. rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, p_hwfn->rel_pf_id,
  333. p_hwfn->hw_info.hw_mode);
  334. if (rc)
  335. return rc;
  336. /* start PF's qm queues */
  337. spin_lock_bh(&qm_lock);
  338. b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, true, true,
  339. qm_info->start_pq, qm_info->num_pqs);
  340. spin_unlock_bh(&qm_lock);
  341. if (!b_rc)
  342. return -EINVAL;
  343. return 0;
  344. }
  345. int qed_resc_alloc(struct qed_dev *cdev)
  346. {
  347. struct qed_iscsi_info *p_iscsi_info;
  348. struct qed_ooo_info *p_ooo_info;
  349. #ifdef CONFIG_QED_LL2
  350. struct qed_ll2_info *p_ll2_info;
  351. #endif
  352. struct qed_consq *p_consq;
  353. struct qed_eq *p_eq;
  354. int i, rc = 0;
  355. if (IS_VF(cdev))
  356. return rc;
  357. cdev->fw_data = kzalloc(sizeof(*cdev->fw_data), GFP_KERNEL);
  358. if (!cdev->fw_data)
  359. return -ENOMEM;
  360. for_each_hwfn(cdev, i) {
  361. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  362. u32 n_eqes, num_cons;
  363. /* First allocate the context manager structure */
  364. rc = qed_cxt_mngr_alloc(p_hwfn);
  365. if (rc)
  366. goto alloc_err;
  367. /* Set the HW cid/tid numbers (in the contest manager)
  368. * Must be done prior to any further computations.
  369. */
  370. rc = qed_cxt_set_pf_params(p_hwfn);
  371. if (rc)
  372. goto alloc_err;
  373. /* Prepare and process QM requirements */
  374. rc = qed_init_qm_info(p_hwfn, true);
  375. if (rc)
  376. goto alloc_err;
  377. /* Compute the ILT client partition */
  378. rc = qed_cxt_cfg_ilt_compute(p_hwfn);
  379. if (rc)
  380. goto alloc_err;
  381. /* CID map / ILT shadow table / T2
  382. * The talbes sizes are determined by the computations above
  383. */
  384. rc = qed_cxt_tables_alloc(p_hwfn);
  385. if (rc)
  386. goto alloc_err;
  387. /* SPQ, must follow ILT because initializes SPQ context */
  388. rc = qed_spq_alloc(p_hwfn);
  389. if (rc)
  390. goto alloc_err;
  391. /* SP status block allocation */
  392. p_hwfn->p_dpc_ptt = qed_get_reserved_ptt(p_hwfn,
  393. RESERVED_PTT_DPC);
  394. rc = qed_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
  395. if (rc)
  396. goto alloc_err;
  397. rc = qed_iov_alloc(p_hwfn);
  398. if (rc)
  399. goto alloc_err;
  400. /* EQ */
  401. n_eqes = qed_chain_get_capacity(&p_hwfn->p_spq->chain);
  402. if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) {
  403. num_cons = qed_cxt_get_proto_cid_count(p_hwfn,
  404. PROTOCOLID_ROCE,
  405. NULL) * 2;
  406. n_eqes += num_cons + 2 * MAX_NUM_VFS_BB;
  407. } else if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
  408. num_cons =
  409. qed_cxt_get_proto_cid_count(p_hwfn,
  410. PROTOCOLID_ISCSI,
  411. NULL);
  412. n_eqes += 2 * num_cons;
  413. }
  414. if (n_eqes > 0xFFFF) {
  415. DP_ERR(p_hwfn,
  416. "Cannot allocate 0x%x EQ elements. The maximum of a u16 chain is 0x%x\n",
  417. n_eqes, 0xFFFF);
  418. rc = -EINVAL;
  419. goto alloc_err;
  420. }
  421. p_eq = qed_eq_alloc(p_hwfn, (u16) n_eqes);
  422. if (!p_eq)
  423. goto alloc_no_mem;
  424. p_hwfn->p_eq = p_eq;
  425. p_consq = qed_consq_alloc(p_hwfn);
  426. if (!p_consq)
  427. goto alloc_no_mem;
  428. p_hwfn->p_consq = p_consq;
  429. #ifdef CONFIG_QED_LL2
  430. if (p_hwfn->using_ll2) {
  431. p_ll2_info = qed_ll2_alloc(p_hwfn);
  432. if (!p_ll2_info)
  433. goto alloc_no_mem;
  434. p_hwfn->p_ll2_info = p_ll2_info;
  435. }
  436. #endif
  437. if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
  438. p_iscsi_info = qed_iscsi_alloc(p_hwfn);
  439. if (!p_iscsi_info)
  440. goto alloc_no_mem;
  441. p_hwfn->p_iscsi_info = p_iscsi_info;
  442. p_ooo_info = qed_ooo_alloc(p_hwfn);
  443. if (!p_ooo_info)
  444. goto alloc_no_mem;
  445. p_hwfn->p_ooo_info = p_ooo_info;
  446. }
  447. /* DMA info initialization */
  448. rc = qed_dmae_info_alloc(p_hwfn);
  449. if (rc)
  450. goto alloc_err;
  451. /* DCBX initialization */
  452. rc = qed_dcbx_info_alloc(p_hwfn);
  453. if (rc)
  454. goto alloc_err;
  455. }
  456. cdev->reset_stats = kzalloc(sizeof(*cdev->reset_stats), GFP_KERNEL);
  457. if (!cdev->reset_stats)
  458. goto alloc_no_mem;
  459. return 0;
  460. alloc_no_mem:
  461. rc = -ENOMEM;
  462. alloc_err:
  463. qed_resc_free(cdev);
  464. return rc;
  465. }
  466. void qed_resc_setup(struct qed_dev *cdev)
  467. {
  468. int i;
  469. if (IS_VF(cdev))
  470. return;
  471. for_each_hwfn(cdev, i) {
  472. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  473. qed_cxt_mngr_setup(p_hwfn);
  474. qed_spq_setup(p_hwfn);
  475. qed_eq_setup(p_hwfn, p_hwfn->p_eq);
  476. qed_consq_setup(p_hwfn, p_hwfn->p_consq);
  477. /* Read shadow of current MFW mailbox */
  478. qed_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
  479. memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
  480. p_hwfn->mcp_info->mfw_mb_cur,
  481. p_hwfn->mcp_info->mfw_mb_length);
  482. qed_int_setup(p_hwfn, p_hwfn->p_main_ptt);
  483. qed_iov_setup(p_hwfn, p_hwfn->p_main_ptt);
  484. #ifdef CONFIG_QED_LL2
  485. if (p_hwfn->using_ll2)
  486. qed_ll2_setup(p_hwfn, p_hwfn->p_ll2_info);
  487. #endif
  488. if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
  489. qed_iscsi_setup(p_hwfn, p_hwfn->p_iscsi_info);
  490. qed_ooo_setup(p_hwfn, p_hwfn->p_ooo_info);
  491. }
  492. }
  493. }
  494. #define FINAL_CLEANUP_POLL_CNT (100)
  495. #define FINAL_CLEANUP_POLL_TIME (10)
  496. int qed_final_cleanup(struct qed_hwfn *p_hwfn,
  497. struct qed_ptt *p_ptt, u16 id, bool is_vf)
  498. {
  499. u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
  500. int rc = -EBUSY;
  501. addr = GTT_BAR0_MAP_REG_USDM_RAM +
  502. USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn->rel_pf_id);
  503. if (is_vf)
  504. id += 0x10;
  505. command |= X_FINAL_CLEANUP_AGG_INT <<
  506. SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT;
  507. command |= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT;
  508. command |= id << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT;
  509. command |= SDM_COMP_TYPE_AGG_INT << SDM_OP_GEN_COMP_TYPE_SHIFT;
  510. /* Make sure notification is not set before initiating final cleanup */
  511. if (REG_RD(p_hwfn, addr)) {
  512. DP_NOTICE(p_hwfn,
  513. "Unexpected; Found final cleanup notification before initiating final cleanup\n");
  514. REG_WR(p_hwfn, addr, 0);
  515. }
  516. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  517. "Sending final cleanup for PFVF[%d] [Command %08x\n]",
  518. id, command);
  519. qed_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command);
  520. /* Poll until completion */
  521. while (!REG_RD(p_hwfn, addr) && count--)
  522. msleep(FINAL_CLEANUP_POLL_TIME);
  523. if (REG_RD(p_hwfn, addr))
  524. rc = 0;
  525. else
  526. DP_NOTICE(p_hwfn,
  527. "Failed to receive FW final cleanup notification\n");
  528. /* Cleanup afterwards */
  529. REG_WR(p_hwfn, addr, 0);
  530. return rc;
  531. }
  532. static void qed_calc_hw_mode(struct qed_hwfn *p_hwfn)
  533. {
  534. int hw_mode = 0;
  535. hw_mode = (1 << MODE_BB_B0);
  536. switch (p_hwfn->cdev->num_ports_in_engines) {
  537. case 1:
  538. hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
  539. break;
  540. case 2:
  541. hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
  542. break;
  543. case 4:
  544. hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
  545. break;
  546. default:
  547. DP_NOTICE(p_hwfn, "num_ports_in_engine = %d not supported\n",
  548. p_hwfn->cdev->num_ports_in_engines);
  549. return;
  550. }
  551. switch (p_hwfn->cdev->mf_mode) {
  552. case QED_MF_DEFAULT:
  553. case QED_MF_NPAR:
  554. hw_mode |= 1 << MODE_MF_SI;
  555. break;
  556. case QED_MF_OVLAN:
  557. hw_mode |= 1 << MODE_MF_SD;
  558. break;
  559. default:
  560. DP_NOTICE(p_hwfn, "Unsupported MF mode, init as DEFAULT\n");
  561. hw_mode |= 1 << MODE_MF_SI;
  562. }
  563. hw_mode |= 1 << MODE_ASIC;
  564. if (p_hwfn->cdev->num_hwfns > 1)
  565. hw_mode |= 1 << MODE_100G;
  566. p_hwfn->hw_info.hw_mode = hw_mode;
  567. DP_VERBOSE(p_hwfn, (NETIF_MSG_PROBE | NETIF_MSG_IFUP),
  568. "Configuring function for hw_mode: 0x%08x\n",
  569. p_hwfn->hw_info.hw_mode);
  570. }
  571. /* Init run time data for all PFs on an engine. */
  572. static void qed_init_cau_rt_data(struct qed_dev *cdev)
  573. {
  574. u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
  575. int i, sb_id;
  576. for_each_hwfn(cdev, i) {
  577. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  578. struct qed_igu_info *p_igu_info;
  579. struct qed_igu_block *p_block;
  580. struct cau_sb_entry sb_entry;
  581. p_igu_info = p_hwfn->hw_info.p_igu_info;
  582. for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(cdev);
  583. sb_id++) {
  584. p_block = &p_igu_info->igu_map.igu_blocks[sb_id];
  585. if (!p_block->is_pf)
  586. continue;
  587. qed_init_cau_sb_entry(p_hwfn, &sb_entry,
  588. p_block->function_id, 0, 0);
  589. STORE_RT_REG_AGG(p_hwfn, offset + sb_id * 2, sb_entry);
  590. }
  591. }
  592. }
  593. static int qed_hw_init_common(struct qed_hwfn *p_hwfn,
  594. struct qed_ptt *p_ptt, int hw_mode)
  595. {
  596. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  597. struct qed_qm_common_rt_init_params params;
  598. struct qed_dev *cdev = p_hwfn->cdev;
  599. u16 num_pfs, pf_id;
  600. u32 concrete_fid;
  601. int rc = 0;
  602. u8 vf_id;
  603. qed_init_cau_rt_data(cdev);
  604. /* Program GTT windows */
  605. qed_gtt_init(p_hwfn);
  606. if (p_hwfn->mcp_info) {
  607. if (p_hwfn->mcp_info->func_info.bandwidth_max)
  608. qm_info->pf_rl_en = 1;
  609. if (p_hwfn->mcp_info->func_info.bandwidth_min)
  610. qm_info->pf_wfq_en = 1;
  611. }
  612. memset(&params, 0, sizeof(params));
  613. params.max_ports_per_engine = p_hwfn->cdev->num_ports_in_engines;
  614. params.max_phys_tcs_per_port = qm_info->max_phys_tcs_per_port;
  615. params.pf_rl_en = qm_info->pf_rl_en;
  616. params.pf_wfq_en = qm_info->pf_wfq_en;
  617. params.vport_rl_en = qm_info->vport_rl_en;
  618. params.vport_wfq_en = qm_info->vport_wfq_en;
  619. params.port_params = qm_info->qm_port_params;
  620. qed_qm_common_rt_init(p_hwfn, &params);
  621. qed_cxt_hw_init_common(p_hwfn);
  622. /* Close gate from NIG to BRB/Storm; By default they are open, but
  623. * we close them to prevent NIG from passing data to reset blocks.
  624. * Should have been done in the ENGINE phase, but init-tool lacks
  625. * proper port-pretend capabilities.
  626. */
  627. qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
  628. qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
  629. qed_port_pretend(p_hwfn, p_ptt, p_hwfn->port_id ^ 1);
  630. qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
  631. qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
  632. qed_port_unpretend(p_hwfn, p_ptt);
  633. rc = qed_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode);
  634. if (rc)
  635. return rc;
  636. qed_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
  637. qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
  638. if (QED_IS_BB(p_hwfn->cdev)) {
  639. num_pfs = NUM_OF_ENG_PFS(p_hwfn->cdev);
  640. for (pf_id = 0; pf_id < num_pfs; pf_id++) {
  641. qed_fid_pretend(p_hwfn, p_ptt, pf_id);
  642. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
  643. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
  644. }
  645. /* pretend to original PF */
  646. qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
  647. }
  648. for (vf_id = 0; vf_id < MAX_NUM_VFS_BB; vf_id++) {
  649. concrete_fid = qed_vfid_to_concrete(p_hwfn, vf_id);
  650. qed_fid_pretend(p_hwfn, p_ptt, (u16) concrete_fid);
  651. qed_wr(p_hwfn, p_ptt, CCFC_REG_STRONG_ENABLE_VF, 0x1);
  652. qed_wr(p_hwfn, p_ptt, CCFC_REG_WEAK_ENABLE_VF, 0x0);
  653. qed_wr(p_hwfn, p_ptt, TCFC_REG_STRONG_ENABLE_VF, 0x1);
  654. qed_wr(p_hwfn, p_ptt, TCFC_REG_WEAK_ENABLE_VF, 0x0);
  655. }
  656. /* pretend to original PF */
  657. qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
  658. return rc;
  659. }
  660. static int
  661. qed_hw_init_dpi_size(struct qed_hwfn *p_hwfn,
  662. struct qed_ptt *p_ptt, u32 pwm_region_size, u32 n_cpus)
  663. {
  664. u32 dpi_page_size_1, dpi_page_size_2, dpi_page_size;
  665. u32 dpi_bit_shift, dpi_count;
  666. u32 min_dpis;
  667. /* Calculate DPI size */
  668. dpi_page_size_1 = QED_WID_SIZE * n_cpus;
  669. dpi_page_size_2 = max_t(u32, QED_WID_SIZE, PAGE_SIZE);
  670. dpi_page_size = max_t(u32, dpi_page_size_1, dpi_page_size_2);
  671. dpi_page_size = roundup_pow_of_two(dpi_page_size);
  672. dpi_bit_shift = ilog2(dpi_page_size / 4096);
  673. dpi_count = pwm_region_size / dpi_page_size;
  674. min_dpis = p_hwfn->pf_params.rdma_pf_params.min_dpis;
  675. min_dpis = max_t(u32, QED_MIN_DPIS, min_dpis);
  676. p_hwfn->dpi_size = dpi_page_size;
  677. p_hwfn->dpi_count = dpi_count;
  678. qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_DPI_BIT_SHIFT, dpi_bit_shift);
  679. if (dpi_count < min_dpis)
  680. return -EINVAL;
  681. return 0;
  682. }
  683. enum QED_ROCE_EDPM_MODE {
  684. QED_ROCE_EDPM_MODE_ENABLE = 0,
  685. QED_ROCE_EDPM_MODE_FORCE_ON = 1,
  686. QED_ROCE_EDPM_MODE_DISABLE = 2,
  687. };
  688. static int
  689. qed_hw_init_pf_doorbell_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  690. {
  691. u32 pwm_regsize, norm_regsize;
  692. u32 non_pwm_conn, min_addr_reg1;
  693. u32 db_bar_size, n_cpus;
  694. u32 roce_edpm_mode;
  695. u32 pf_dems_shift;
  696. int rc = 0;
  697. u8 cond;
  698. db_bar_size = qed_hw_bar_size(p_hwfn, BAR_ID_1);
  699. if (p_hwfn->cdev->num_hwfns > 1)
  700. db_bar_size /= 2;
  701. /* Calculate doorbell regions */
  702. non_pwm_conn = qed_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_CORE) +
  703. qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_CORE,
  704. NULL) +
  705. qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH,
  706. NULL);
  707. norm_regsize = roundup(QED_PF_DEMS_SIZE * non_pwm_conn, 4096);
  708. min_addr_reg1 = norm_regsize / 4096;
  709. pwm_regsize = db_bar_size - norm_regsize;
  710. /* Check that the normal and PWM sizes are valid */
  711. if (db_bar_size < norm_regsize) {
  712. DP_ERR(p_hwfn->cdev,
  713. "Doorbell BAR size 0x%x is too small (normal region is 0x%0x )\n",
  714. db_bar_size, norm_regsize);
  715. return -EINVAL;
  716. }
  717. if (pwm_regsize < QED_MIN_PWM_REGION) {
  718. DP_ERR(p_hwfn->cdev,
  719. "PWM region size 0x%0x is too small. Should be at least 0x%0x (Doorbell BAR size is 0x%x and normal region size is 0x%0x)\n",
  720. pwm_regsize,
  721. QED_MIN_PWM_REGION, db_bar_size, norm_regsize);
  722. return -EINVAL;
  723. }
  724. /* Calculate number of DPIs */
  725. roce_edpm_mode = p_hwfn->pf_params.rdma_pf_params.roce_edpm_mode;
  726. if ((roce_edpm_mode == QED_ROCE_EDPM_MODE_ENABLE) ||
  727. ((roce_edpm_mode == QED_ROCE_EDPM_MODE_FORCE_ON))) {
  728. /* Either EDPM is mandatory, or we are attempting to allocate a
  729. * WID per CPU.
  730. */
  731. n_cpus = num_active_cpus();
  732. rc = qed_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
  733. }
  734. cond = (rc && (roce_edpm_mode == QED_ROCE_EDPM_MODE_ENABLE)) ||
  735. (roce_edpm_mode == QED_ROCE_EDPM_MODE_DISABLE);
  736. if (cond || p_hwfn->dcbx_no_edpm) {
  737. /* Either EDPM is disabled from user configuration, or it is
  738. * disabled via DCBx, or it is not mandatory and we failed to
  739. * allocated a WID per CPU.
  740. */
  741. n_cpus = 1;
  742. rc = qed_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
  743. if (cond)
  744. qed_rdma_dpm_bar(p_hwfn, p_ptt);
  745. }
  746. DP_INFO(p_hwfn,
  747. "doorbell bar: normal_region_size=%d, pwm_region_size=%d, dpi_size=%d, dpi_count=%d, roce_edpm=%s\n",
  748. norm_regsize,
  749. pwm_regsize,
  750. p_hwfn->dpi_size,
  751. p_hwfn->dpi_count,
  752. ((p_hwfn->dcbx_no_edpm) || (p_hwfn->db_bar_no_edpm)) ?
  753. "disabled" : "enabled");
  754. if (rc) {
  755. DP_ERR(p_hwfn,
  756. "Failed to allocate enough DPIs. Allocated %d but the current minimum is %d.\n",
  757. p_hwfn->dpi_count,
  758. p_hwfn->pf_params.rdma_pf_params.min_dpis);
  759. return -EINVAL;
  760. }
  761. p_hwfn->dpi_start_offset = norm_regsize;
  762. /* DEMS size is configured log2 of DWORDs, hence the division by 4 */
  763. pf_dems_shift = ilog2(QED_PF_DEMS_SIZE / 4);
  764. qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_ICID_BIT_SHIFT_NORM, pf_dems_shift);
  765. qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_MIN_ADDR_REG1, min_addr_reg1);
  766. return 0;
  767. }
  768. static int qed_hw_init_port(struct qed_hwfn *p_hwfn,
  769. struct qed_ptt *p_ptt, int hw_mode)
  770. {
  771. return qed_init_run(p_hwfn, p_ptt, PHASE_PORT,
  772. p_hwfn->port_id, hw_mode);
  773. }
  774. static int qed_hw_init_pf(struct qed_hwfn *p_hwfn,
  775. struct qed_ptt *p_ptt,
  776. struct qed_tunn_start_params *p_tunn,
  777. int hw_mode,
  778. bool b_hw_start,
  779. enum qed_int_mode int_mode,
  780. bool allow_npar_tx_switch)
  781. {
  782. u8 rel_pf_id = p_hwfn->rel_pf_id;
  783. int rc = 0;
  784. if (p_hwfn->mcp_info) {
  785. struct qed_mcp_function_info *p_info;
  786. p_info = &p_hwfn->mcp_info->func_info;
  787. if (p_info->bandwidth_min)
  788. p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
  789. /* Update rate limit once we'll actually have a link */
  790. p_hwfn->qm_info.pf_rl = 100000;
  791. }
  792. qed_cxt_hw_init_pf(p_hwfn);
  793. qed_int_igu_init_rt(p_hwfn);
  794. /* Set VLAN in NIG if needed */
  795. if (hw_mode & BIT(MODE_MF_SD)) {
  796. DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "Configuring LLH_FUNC_TAG\n");
  797. STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
  798. STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
  799. p_hwfn->hw_info.ovlan);
  800. }
  801. /* Enable classification by MAC if needed */
  802. if (hw_mode & BIT(MODE_MF_SI)) {
  803. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  804. "Configuring TAGMAC_CLS_TYPE\n");
  805. STORE_RT_REG(p_hwfn,
  806. NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET, 1);
  807. }
  808. /* Protocl Configuration */
  809. STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET,
  810. (p_hwfn->hw_info.personality == QED_PCI_ISCSI) ? 1 : 0);
  811. STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET, 0);
  812. STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0);
  813. /* Cleanup chip from previous driver if such remains exist */
  814. rc = qed_final_cleanup(p_hwfn, p_ptt, rel_pf_id, false);
  815. if (rc)
  816. return rc;
  817. /* PF Init sequence */
  818. rc = qed_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
  819. if (rc)
  820. return rc;
  821. /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
  822. rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
  823. if (rc)
  824. return rc;
  825. /* Pure runtime initializations - directly to the HW */
  826. qed_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
  827. rc = qed_hw_init_pf_doorbell_bar(p_hwfn, p_ptt);
  828. if (rc)
  829. return rc;
  830. if (b_hw_start) {
  831. /* enable interrupts */
  832. qed_int_igu_enable(p_hwfn, p_ptt, int_mode);
  833. /* send function start command */
  834. rc = qed_sp_pf_start(p_hwfn, p_tunn, p_hwfn->cdev->mf_mode,
  835. allow_npar_tx_switch);
  836. if (rc)
  837. DP_NOTICE(p_hwfn, "Function start ramrod failed\n");
  838. }
  839. return rc;
  840. }
  841. static int qed_change_pci_hwfn(struct qed_hwfn *p_hwfn,
  842. struct qed_ptt *p_ptt,
  843. u8 enable)
  844. {
  845. u32 delay_idx = 0, val, set_val = enable ? 1 : 0;
  846. /* Change PF in PXP */
  847. qed_wr(p_hwfn, p_ptt,
  848. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
  849. /* wait until value is set - try for 1 second every 50us */
  850. for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
  851. val = qed_rd(p_hwfn, p_ptt,
  852. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  853. if (val == set_val)
  854. break;
  855. usleep_range(50, 60);
  856. }
  857. if (val != set_val) {
  858. DP_NOTICE(p_hwfn,
  859. "PFID_ENABLE_MASTER wasn't changed after a second\n");
  860. return -EAGAIN;
  861. }
  862. return 0;
  863. }
  864. static void qed_reset_mb_shadow(struct qed_hwfn *p_hwfn,
  865. struct qed_ptt *p_main_ptt)
  866. {
  867. /* Read shadow of current MFW mailbox */
  868. qed_mcp_read_mb(p_hwfn, p_main_ptt);
  869. memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
  870. p_hwfn->mcp_info->mfw_mb_cur, p_hwfn->mcp_info->mfw_mb_length);
  871. }
  872. int qed_hw_init(struct qed_dev *cdev,
  873. struct qed_tunn_start_params *p_tunn,
  874. bool b_hw_start,
  875. enum qed_int_mode int_mode,
  876. bool allow_npar_tx_switch,
  877. const u8 *bin_fw_data)
  878. {
  879. u32 load_code, param, drv_mb_param;
  880. bool b_default_mtu = true;
  881. struct qed_hwfn *p_hwfn;
  882. int rc = 0, mfw_rc, i;
  883. if ((int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) {
  884. DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n");
  885. return -EINVAL;
  886. }
  887. if (IS_PF(cdev)) {
  888. rc = qed_init_fw_data(cdev, bin_fw_data);
  889. if (rc)
  890. return rc;
  891. }
  892. for_each_hwfn(cdev, i) {
  893. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  894. /* If management didn't provide a default, set one of our own */
  895. if (!p_hwfn->hw_info.mtu) {
  896. p_hwfn->hw_info.mtu = 1500;
  897. b_default_mtu = false;
  898. }
  899. if (IS_VF(cdev)) {
  900. p_hwfn->b_int_enabled = 1;
  901. continue;
  902. }
  903. /* Enable DMAE in PXP */
  904. rc = qed_change_pci_hwfn(p_hwfn, p_hwfn->p_main_ptt, true);
  905. qed_calc_hw_mode(p_hwfn);
  906. rc = qed_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt, &load_code);
  907. if (rc) {
  908. DP_NOTICE(p_hwfn, "Failed sending LOAD_REQ command\n");
  909. return rc;
  910. }
  911. qed_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
  912. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  913. "Load request was sent. Resp:0x%x, Load code: 0x%x\n",
  914. rc, load_code);
  915. p_hwfn->first_on_engine = (load_code ==
  916. FW_MSG_CODE_DRV_LOAD_ENGINE);
  917. switch (load_code) {
  918. case FW_MSG_CODE_DRV_LOAD_ENGINE:
  919. rc = qed_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
  920. p_hwfn->hw_info.hw_mode);
  921. if (rc)
  922. break;
  923. /* Fall into */
  924. case FW_MSG_CODE_DRV_LOAD_PORT:
  925. rc = qed_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
  926. p_hwfn->hw_info.hw_mode);
  927. if (rc)
  928. break;
  929. /* Fall into */
  930. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  931. rc = qed_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
  932. p_tunn, p_hwfn->hw_info.hw_mode,
  933. b_hw_start, int_mode,
  934. allow_npar_tx_switch);
  935. break;
  936. default:
  937. rc = -EINVAL;
  938. break;
  939. }
  940. if (rc)
  941. DP_NOTICE(p_hwfn,
  942. "init phase failed for loadcode 0x%x (rc %d)\n",
  943. load_code, rc);
  944. /* ACK mfw regardless of success or failure of initialization */
  945. mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
  946. DRV_MSG_CODE_LOAD_DONE,
  947. 0, &load_code, &param);
  948. if (rc)
  949. return rc;
  950. if (mfw_rc) {
  951. DP_NOTICE(p_hwfn, "Failed sending LOAD_DONE command\n");
  952. return mfw_rc;
  953. }
  954. /* send DCBX attention request command */
  955. DP_VERBOSE(p_hwfn,
  956. QED_MSG_DCB,
  957. "sending phony dcbx set command to trigger DCBx attention handling\n");
  958. mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
  959. DRV_MSG_CODE_SET_DCBX,
  960. 1 << DRV_MB_PARAM_DCBX_NOTIFY_SHIFT,
  961. &load_code, &param);
  962. if (mfw_rc) {
  963. DP_NOTICE(p_hwfn,
  964. "Failed to send DCBX attention request\n");
  965. return mfw_rc;
  966. }
  967. p_hwfn->hw_init_done = true;
  968. }
  969. if (IS_PF(cdev)) {
  970. p_hwfn = QED_LEADING_HWFN(cdev);
  971. drv_mb_param = (FW_MAJOR_VERSION << 24) |
  972. (FW_MINOR_VERSION << 16) |
  973. (FW_REVISION_VERSION << 8) |
  974. (FW_ENGINEERING_VERSION);
  975. rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
  976. DRV_MSG_CODE_OV_UPDATE_STORM_FW_VER,
  977. drv_mb_param, &load_code, &param);
  978. if (rc)
  979. DP_INFO(p_hwfn, "Failed to update firmware version\n");
  980. if (!b_default_mtu) {
  981. rc = qed_mcp_ov_update_mtu(p_hwfn, p_hwfn->p_main_ptt,
  982. p_hwfn->hw_info.mtu);
  983. if (rc)
  984. DP_INFO(p_hwfn,
  985. "Failed to update default mtu\n");
  986. }
  987. rc = qed_mcp_ov_update_driver_state(p_hwfn,
  988. p_hwfn->p_main_ptt,
  989. QED_OV_DRIVER_STATE_DISABLED);
  990. if (rc)
  991. DP_INFO(p_hwfn, "Failed to update driver state\n");
  992. rc = qed_mcp_ov_update_eswitch(p_hwfn, p_hwfn->p_main_ptt,
  993. QED_OV_ESWITCH_VEB);
  994. if (rc)
  995. DP_INFO(p_hwfn, "Failed to update eswitch mode\n");
  996. }
  997. return 0;
  998. }
  999. #define QED_HW_STOP_RETRY_LIMIT (10)
  1000. static void qed_hw_timers_stop(struct qed_dev *cdev,
  1001. struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  1002. {
  1003. int i;
  1004. /* close timers */
  1005. qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
  1006. qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
  1007. for (i = 0; i < QED_HW_STOP_RETRY_LIMIT; i++) {
  1008. if ((!qed_rd(p_hwfn, p_ptt,
  1009. TM_REG_PF_SCAN_ACTIVE_CONN)) &&
  1010. (!qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK)))
  1011. break;
  1012. /* Dependent on number of connection/tasks, possibly
  1013. * 1ms sleep is required between polls
  1014. */
  1015. usleep_range(1000, 2000);
  1016. }
  1017. if (i < QED_HW_STOP_RETRY_LIMIT)
  1018. return;
  1019. DP_NOTICE(p_hwfn,
  1020. "Timers linear scans are not over [Connection %02x Tasks %02x]\n",
  1021. (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_CONN),
  1022. (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK));
  1023. }
  1024. void qed_hw_timers_stop_all(struct qed_dev *cdev)
  1025. {
  1026. int j;
  1027. for_each_hwfn(cdev, j) {
  1028. struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
  1029. struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
  1030. qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
  1031. }
  1032. }
  1033. int qed_hw_stop(struct qed_dev *cdev)
  1034. {
  1035. int rc = 0, t_rc;
  1036. int j;
  1037. for_each_hwfn(cdev, j) {
  1038. struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
  1039. struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
  1040. DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Stopping hw/fw\n");
  1041. if (IS_VF(cdev)) {
  1042. qed_vf_pf_int_cleanup(p_hwfn);
  1043. continue;
  1044. }
  1045. /* mark the hw as uninitialized... */
  1046. p_hwfn->hw_init_done = false;
  1047. rc = qed_sp_pf_stop(p_hwfn);
  1048. if (rc)
  1049. DP_NOTICE(p_hwfn,
  1050. "Failed to close PF against FW. Continue to stop HW to prevent illegal host access by the device\n");
  1051. qed_wr(p_hwfn, p_ptt,
  1052. NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
  1053. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
  1054. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
  1055. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
  1056. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
  1057. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
  1058. qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
  1059. /* Disable Attention Generation */
  1060. qed_int_igu_disable_int(p_hwfn, p_ptt);
  1061. qed_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
  1062. qed_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
  1063. qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
  1064. /* Need to wait 1ms to guarantee SBs are cleared */
  1065. usleep_range(1000, 2000);
  1066. }
  1067. if (IS_PF(cdev)) {
  1068. /* Disable DMAE in PXP - in CMT, this should only be done for
  1069. * first hw-function, and only after all transactions have
  1070. * stopped for all active hw-functions.
  1071. */
  1072. t_rc = qed_change_pci_hwfn(&cdev->hwfns[0],
  1073. cdev->hwfns[0].p_main_ptt, false);
  1074. if (t_rc != 0)
  1075. rc = t_rc;
  1076. }
  1077. return rc;
  1078. }
  1079. void qed_hw_stop_fastpath(struct qed_dev *cdev)
  1080. {
  1081. int j;
  1082. for_each_hwfn(cdev, j) {
  1083. struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
  1084. struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
  1085. if (IS_VF(cdev)) {
  1086. qed_vf_pf_int_cleanup(p_hwfn);
  1087. continue;
  1088. }
  1089. DP_VERBOSE(p_hwfn,
  1090. NETIF_MSG_IFDOWN, "Shutting down the fastpath\n");
  1091. qed_wr(p_hwfn, p_ptt,
  1092. NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
  1093. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
  1094. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
  1095. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
  1096. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
  1097. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
  1098. qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false);
  1099. /* Need to wait 1ms to guarantee SBs are cleared */
  1100. usleep_range(1000, 2000);
  1101. }
  1102. }
  1103. void qed_hw_start_fastpath(struct qed_hwfn *p_hwfn)
  1104. {
  1105. if (IS_VF(p_hwfn->cdev))
  1106. return;
  1107. /* Re-open incoming traffic */
  1108. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1109. NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0);
  1110. }
  1111. static int qed_reg_assert(struct qed_hwfn *p_hwfn,
  1112. struct qed_ptt *p_ptt, u32 reg, bool expected)
  1113. {
  1114. u32 assert_val = qed_rd(p_hwfn, p_ptt, reg);
  1115. if (assert_val != expected) {
  1116. DP_NOTICE(p_hwfn, "Value at address 0x%08x != 0x%08x\n",
  1117. reg, expected);
  1118. return -EINVAL;
  1119. }
  1120. return 0;
  1121. }
  1122. int qed_hw_reset(struct qed_dev *cdev)
  1123. {
  1124. int rc = 0;
  1125. u32 unload_resp, unload_param;
  1126. u32 wol_param;
  1127. int i;
  1128. switch (cdev->wol_config) {
  1129. case QED_OV_WOL_DISABLED:
  1130. wol_param = DRV_MB_PARAM_UNLOAD_WOL_DISABLED;
  1131. break;
  1132. case QED_OV_WOL_ENABLED:
  1133. wol_param = DRV_MB_PARAM_UNLOAD_WOL_ENABLED;
  1134. break;
  1135. default:
  1136. DP_NOTICE(cdev,
  1137. "Unknown WoL configuration %02x\n", cdev->wol_config);
  1138. /* Fallthrough */
  1139. case QED_OV_WOL_DEFAULT:
  1140. wol_param = DRV_MB_PARAM_UNLOAD_WOL_MCP;
  1141. }
  1142. for_each_hwfn(cdev, i) {
  1143. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1144. if (IS_VF(cdev)) {
  1145. rc = qed_vf_pf_reset(p_hwfn);
  1146. if (rc)
  1147. return rc;
  1148. continue;
  1149. }
  1150. DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Resetting hw/fw\n");
  1151. /* Check for incorrect states */
  1152. qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
  1153. QM_REG_USG_CNT_PF_TX, 0);
  1154. qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
  1155. QM_REG_USG_CNT_PF_OTHER, 0);
  1156. /* Disable PF in HW blocks */
  1157. qed_wr(p_hwfn, p_hwfn->p_main_ptt, DORQ_REG_PF_DB_ENABLE, 0);
  1158. qed_wr(p_hwfn, p_hwfn->p_main_ptt, QM_REG_PF_EN, 0);
  1159. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1160. TCFC_REG_STRONG_ENABLE_PF, 0);
  1161. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1162. CCFC_REG_STRONG_ENABLE_PF, 0);
  1163. /* Send unload command to MCP */
  1164. rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
  1165. DRV_MSG_CODE_UNLOAD_REQ, wol_param,
  1166. &unload_resp, &unload_param);
  1167. if (rc) {
  1168. DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_REQ failed\n");
  1169. unload_resp = FW_MSG_CODE_DRV_UNLOAD_ENGINE;
  1170. }
  1171. rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
  1172. DRV_MSG_CODE_UNLOAD_DONE,
  1173. 0, &unload_resp, &unload_param);
  1174. if (rc) {
  1175. DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_DONE failed\n");
  1176. return rc;
  1177. }
  1178. }
  1179. return rc;
  1180. }
  1181. /* Free hwfn memory and resources acquired in hw_hwfn_prepare */
  1182. static void qed_hw_hwfn_free(struct qed_hwfn *p_hwfn)
  1183. {
  1184. qed_ptt_pool_free(p_hwfn);
  1185. kfree(p_hwfn->hw_info.p_igu_info);
  1186. }
  1187. /* Setup bar access */
  1188. static void qed_hw_hwfn_prepare(struct qed_hwfn *p_hwfn)
  1189. {
  1190. /* clear indirect access */
  1191. qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_88_F0, 0);
  1192. qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_8C_F0, 0);
  1193. qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_90_F0, 0);
  1194. qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_94_F0, 0);
  1195. /* Clean Previous errors if such exist */
  1196. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1197. PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR, 1 << p_hwfn->abs_pf_id);
  1198. /* enable internal target-read */
  1199. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1200. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1201. }
  1202. static void get_function_id(struct qed_hwfn *p_hwfn)
  1203. {
  1204. /* ME Register */
  1205. p_hwfn->hw_info.opaque_fid = (u16) REG_RD(p_hwfn,
  1206. PXP_PF_ME_OPAQUE_ADDR);
  1207. p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
  1208. p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
  1209. p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
  1210. PXP_CONCRETE_FID_PFID);
  1211. p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
  1212. PXP_CONCRETE_FID_PORT);
  1213. DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
  1214. "Read ME register: Concrete 0x%08x Opaque 0x%04x\n",
  1215. p_hwfn->hw_info.concrete_fid, p_hwfn->hw_info.opaque_fid);
  1216. }
  1217. static void qed_hw_set_feat(struct qed_hwfn *p_hwfn)
  1218. {
  1219. u32 *feat_num = p_hwfn->hw_info.feat_num;
  1220. struct qed_sb_cnt_info sb_cnt_info;
  1221. int num_features = 1;
  1222. if (IS_ENABLED(CONFIG_QED_RDMA) &&
  1223. p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) {
  1224. /* Roce CNQ each requires: 1 status block + 1 CNQ. We divide
  1225. * the status blocks equally between L2 / RoCE but with
  1226. * consideration as to how many l2 queues / cnqs we have.
  1227. */
  1228. num_features++;
  1229. feat_num[QED_RDMA_CNQ] =
  1230. min_t(u32, RESC_NUM(p_hwfn, QED_SB) / num_features,
  1231. RESC_NUM(p_hwfn, QED_RDMA_CNQ_RAM));
  1232. }
  1233. feat_num[QED_PF_L2_QUE] = min_t(u32, RESC_NUM(p_hwfn, QED_SB) /
  1234. num_features,
  1235. RESC_NUM(p_hwfn, QED_L2_QUEUE));
  1236. memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
  1237. qed_int_get_num_sbs(p_hwfn, &sb_cnt_info);
  1238. feat_num[QED_VF_L2_QUE] =
  1239. min_t(u32,
  1240. RESC_NUM(p_hwfn, QED_L2_QUEUE) -
  1241. FEAT_NUM(p_hwfn, QED_PF_L2_QUE), sb_cnt_info.sb_iov_cnt);
  1242. DP_VERBOSE(p_hwfn,
  1243. NETIF_MSG_PROBE,
  1244. "#PF_L2_QUEUES=%d VF_L2_QUEUES=%d #ROCE_CNQ=%d #SBS=%d num_features=%d\n",
  1245. (int)FEAT_NUM(p_hwfn, QED_PF_L2_QUE),
  1246. (int)FEAT_NUM(p_hwfn, QED_VF_L2_QUE),
  1247. (int)FEAT_NUM(p_hwfn, QED_RDMA_CNQ),
  1248. RESC_NUM(p_hwfn, QED_SB), num_features);
  1249. }
  1250. static enum resource_id_enum qed_hw_get_mfw_res_id(enum qed_resources res_id)
  1251. {
  1252. enum resource_id_enum mfw_res_id = RESOURCE_NUM_INVALID;
  1253. switch (res_id) {
  1254. case QED_SB:
  1255. mfw_res_id = RESOURCE_NUM_SB_E;
  1256. break;
  1257. case QED_L2_QUEUE:
  1258. mfw_res_id = RESOURCE_NUM_L2_QUEUE_E;
  1259. break;
  1260. case QED_VPORT:
  1261. mfw_res_id = RESOURCE_NUM_VPORT_E;
  1262. break;
  1263. case QED_RSS_ENG:
  1264. mfw_res_id = RESOURCE_NUM_RSS_ENGINES_E;
  1265. break;
  1266. case QED_PQ:
  1267. mfw_res_id = RESOURCE_NUM_PQ_E;
  1268. break;
  1269. case QED_RL:
  1270. mfw_res_id = RESOURCE_NUM_RL_E;
  1271. break;
  1272. case QED_MAC:
  1273. case QED_VLAN:
  1274. /* Each VFC resource can accommodate both a MAC and a VLAN */
  1275. mfw_res_id = RESOURCE_VFC_FILTER_E;
  1276. break;
  1277. case QED_ILT:
  1278. mfw_res_id = RESOURCE_ILT_E;
  1279. break;
  1280. case QED_LL2_QUEUE:
  1281. mfw_res_id = RESOURCE_LL2_QUEUE_E;
  1282. break;
  1283. case QED_RDMA_CNQ_RAM:
  1284. case QED_CMDQS_CQS:
  1285. /* CNQ/CMDQS are the same resource */
  1286. mfw_res_id = RESOURCE_CQS_E;
  1287. break;
  1288. case QED_RDMA_STATS_QUEUE:
  1289. mfw_res_id = RESOURCE_RDMA_STATS_QUEUE_E;
  1290. break;
  1291. default:
  1292. break;
  1293. }
  1294. return mfw_res_id;
  1295. }
  1296. static u32 qed_hw_get_dflt_resc_num(struct qed_hwfn *p_hwfn,
  1297. enum qed_resources res_id)
  1298. {
  1299. u8 num_funcs = p_hwfn->num_funcs_on_engine;
  1300. struct qed_sb_cnt_info sb_cnt_info;
  1301. u32 dflt_resc_num = 0;
  1302. switch (res_id) {
  1303. case QED_SB:
  1304. memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
  1305. qed_int_get_num_sbs(p_hwfn, &sb_cnt_info);
  1306. dflt_resc_num = sb_cnt_info.sb_cnt;
  1307. break;
  1308. case QED_L2_QUEUE:
  1309. dflt_resc_num = MAX_NUM_L2_QUEUES_BB / num_funcs;
  1310. break;
  1311. case QED_VPORT:
  1312. dflt_resc_num = MAX_NUM_VPORTS_BB / num_funcs;
  1313. break;
  1314. case QED_RSS_ENG:
  1315. dflt_resc_num = ETH_RSS_ENGINE_NUM_BB / num_funcs;
  1316. break;
  1317. case QED_PQ:
  1318. /* The granularity of the PQs is 8 */
  1319. dflt_resc_num = MAX_QM_TX_QUEUES_BB / num_funcs;
  1320. dflt_resc_num &= ~0x7;
  1321. break;
  1322. case QED_RL:
  1323. dflt_resc_num = MAX_QM_GLOBAL_RLS / num_funcs;
  1324. break;
  1325. case QED_MAC:
  1326. case QED_VLAN:
  1327. /* Each VFC resource can accommodate both a MAC and a VLAN */
  1328. dflt_resc_num = ETH_NUM_MAC_FILTERS / num_funcs;
  1329. break;
  1330. case QED_ILT:
  1331. dflt_resc_num = PXP_NUM_ILT_RECORDS_BB / num_funcs;
  1332. break;
  1333. case QED_LL2_QUEUE:
  1334. dflt_resc_num = MAX_NUM_LL2_RX_QUEUES / num_funcs;
  1335. break;
  1336. case QED_RDMA_CNQ_RAM:
  1337. case QED_CMDQS_CQS:
  1338. /* CNQ/CMDQS are the same resource */
  1339. dflt_resc_num = NUM_OF_CMDQS_CQS / num_funcs;
  1340. break;
  1341. case QED_RDMA_STATS_QUEUE:
  1342. dflt_resc_num = RDMA_NUM_STATISTIC_COUNTERS_BB / num_funcs;
  1343. break;
  1344. default:
  1345. break;
  1346. }
  1347. return dflt_resc_num;
  1348. }
  1349. static const char *qed_hw_get_resc_name(enum qed_resources res_id)
  1350. {
  1351. switch (res_id) {
  1352. case QED_SB:
  1353. return "SB";
  1354. case QED_L2_QUEUE:
  1355. return "L2_QUEUE";
  1356. case QED_VPORT:
  1357. return "VPORT";
  1358. case QED_RSS_ENG:
  1359. return "RSS_ENG";
  1360. case QED_PQ:
  1361. return "PQ";
  1362. case QED_RL:
  1363. return "RL";
  1364. case QED_MAC:
  1365. return "MAC";
  1366. case QED_VLAN:
  1367. return "VLAN";
  1368. case QED_RDMA_CNQ_RAM:
  1369. return "RDMA_CNQ_RAM";
  1370. case QED_ILT:
  1371. return "ILT";
  1372. case QED_LL2_QUEUE:
  1373. return "LL2_QUEUE";
  1374. case QED_CMDQS_CQS:
  1375. return "CMDQS_CQS";
  1376. case QED_RDMA_STATS_QUEUE:
  1377. return "RDMA_STATS_QUEUE";
  1378. default:
  1379. return "UNKNOWN_RESOURCE";
  1380. }
  1381. }
  1382. static int qed_hw_set_resc_info(struct qed_hwfn *p_hwfn,
  1383. enum qed_resources res_id)
  1384. {
  1385. u32 dflt_resc_num = 0, dflt_resc_start = 0, mcp_resp, mcp_param;
  1386. u32 *p_resc_num, *p_resc_start;
  1387. struct resource_info resc_info;
  1388. int rc;
  1389. p_resc_num = &RESC_NUM(p_hwfn, res_id);
  1390. p_resc_start = &RESC_START(p_hwfn, res_id);
  1391. /* Default values assumes that each function received equal share */
  1392. dflt_resc_num = qed_hw_get_dflt_resc_num(p_hwfn, res_id);
  1393. if (!dflt_resc_num) {
  1394. DP_ERR(p_hwfn,
  1395. "Failed to get default amount for resource %d [%s]\n",
  1396. res_id, qed_hw_get_resc_name(res_id));
  1397. return -EINVAL;
  1398. }
  1399. dflt_resc_start = dflt_resc_num * p_hwfn->enabled_func_idx;
  1400. memset(&resc_info, 0, sizeof(resc_info));
  1401. resc_info.res_id = qed_hw_get_mfw_res_id(res_id);
  1402. if (resc_info.res_id == RESOURCE_NUM_INVALID) {
  1403. DP_ERR(p_hwfn,
  1404. "Failed to match resource %d [%s] with the MFW resources\n",
  1405. res_id, qed_hw_get_resc_name(res_id));
  1406. return -EINVAL;
  1407. }
  1408. rc = qed_mcp_get_resc_info(p_hwfn, p_hwfn->p_main_ptt, &resc_info,
  1409. &mcp_resp, &mcp_param);
  1410. if (rc) {
  1411. DP_NOTICE(p_hwfn,
  1412. "MFW response failure for an allocation request for resource %d [%s]\n",
  1413. res_id, qed_hw_get_resc_name(res_id));
  1414. return rc;
  1415. }
  1416. /* Default driver values are applied in the following cases:
  1417. * - The resource allocation MB command is not supported by the MFW
  1418. * - There is an internal error in the MFW while processing the request
  1419. * - The resource ID is unknown to the MFW
  1420. */
  1421. if (mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK &&
  1422. mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_DEPRECATED) {
  1423. DP_NOTICE(p_hwfn,
  1424. "Resource %d [%s]: No allocation info was received [mcp_resp 0x%x]. Applying default values [num %d, start %d].\n",
  1425. res_id,
  1426. qed_hw_get_resc_name(res_id),
  1427. mcp_resp, dflt_resc_num, dflt_resc_start);
  1428. *p_resc_num = dflt_resc_num;
  1429. *p_resc_start = dflt_resc_start;
  1430. goto out;
  1431. }
  1432. /* Special handling for status blocks; Would be revised in future */
  1433. if (res_id == QED_SB) {
  1434. resc_info.size -= 1;
  1435. resc_info.offset -= p_hwfn->enabled_func_idx;
  1436. }
  1437. *p_resc_num = resc_info.size;
  1438. *p_resc_start = resc_info.offset;
  1439. out:
  1440. /* PQs have to divide by 8 [that's the HW granularity].
  1441. * Reduce number so it would fit.
  1442. */
  1443. if ((res_id == QED_PQ) && ((*p_resc_num % 8) || (*p_resc_start % 8))) {
  1444. DP_INFO(p_hwfn,
  1445. "PQs need to align by 8; Number %08x --> %08x, Start %08x --> %08x\n",
  1446. *p_resc_num,
  1447. (*p_resc_num) & ~0x7,
  1448. *p_resc_start, (*p_resc_start) & ~0x7);
  1449. *p_resc_num &= ~0x7;
  1450. *p_resc_start &= ~0x7;
  1451. }
  1452. return 0;
  1453. }
  1454. static int qed_hw_get_resc(struct qed_hwfn *p_hwfn)
  1455. {
  1456. u8 res_id;
  1457. int rc;
  1458. for (res_id = 0; res_id < QED_MAX_RESC; res_id++) {
  1459. rc = qed_hw_set_resc_info(p_hwfn, res_id);
  1460. if (rc)
  1461. return rc;
  1462. }
  1463. /* Sanity for ILT */
  1464. if ((RESC_END(p_hwfn, QED_ILT) > PXP_NUM_ILT_RECORDS_BB)) {
  1465. DP_NOTICE(p_hwfn, "Can't assign ILT pages [%08x,...,%08x]\n",
  1466. RESC_START(p_hwfn, QED_ILT),
  1467. RESC_END(p_hwfn, QED_ILT) - 1);
  1468. return -EINVAL;
  1469. }
  1470. qed_hw_set_feat(p_hwfn);
  1471. DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
  1472. "The numbers for each resource are:\n");
  1473. for (res_id = 0; res_id < QED_MAX_RESC; res_id++)
  1474. DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE, "%s = %d start = %d\n",
  1475. qed_hw_get_resc_name(res_id),
  1476. RESC_NUM(p_hwfn, res_id),
  1477. RESC_START(p_hwfn, res_id));
  1478. return 0;
  1479. }
  1480. static int qed_hw_get_nvm_info(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  1481. {
  1482. u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg;
  1483. u32 port_cfg_addr, link_temp, nvm_cfg_addr, device_capabilities;
  1484. struct qed_mcp_link_params *link;
  1485. /* Read global nvm_cfg address */
  1486. nvm_cfg_addr = qed_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
  1487. /* Verify MCP has initialized it */
  1488. if (!nvm_cfg_addr) {
  1489. DP_NOTICE(p_hwfn, "Shared memory not initialized\n");
  1490. return -EINVAL;
  1491. }
  1492. /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
  1493. nvm_cfg1_offset = qed_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
  1494. addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  1495. offsetof(struct nvm_cfg1, glob) +
  1496. offsetof(struct nvm_cfg1_glob, core_cfg);
  1497. core_cfg = qed_rd(p_hwfn, p_ptt, addr);
  1498. switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
  1499. NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
  1500. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_2X40G:
  1501. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X40G;
  1502. break;
  1503. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X50G:
  1504. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X50G;
  1505. break;
  1506. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_1X100G:
  1507. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X100G;
  1508. break;
  1509. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X10G_F:
  1510. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_F;
  1511. break;
  1512. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X10G_E:
  1513. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_E;
  1514. break;
  1515. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X20G:
  1516. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X20G;
  1517. break;
  1518. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X40G:
  1519. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X40G;
  1520. break;
  1521. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X25G:
  1522. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X25G;
  1523. break;
  1524. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X25G:
  1525. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X25G;
  1526. break;
  1527. default:
  1528. DP_NOTICE(p_hwfn, "Unknown port mode in 0x%08x\n", core_cfg);
  1529. break;
  1530. }
  1531. /* Read default link configuration */
  1532. link = &p_hwfn->mcp_info->link_input;
  1533. port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  1534. offsetof(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
  1535. link_temp = qed_rd(p_hwfn, p_ptt,
  1536. port_cfg_addr +
  1537. offsetof(struct nvm_cfg1_port, speed_cap_mask));
  1538. link_temp &= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
  1539. link->speed.advertised_speeds = link_temp;
  1540. link_temp = link->speed.advertised_speeds;
  1541. p_hwfn->mcp_info->link_capabilities.speed_capabilities = link_temp;
  1542. link_temp = qed_rd(p_hwfn, p_ptt,
  1543. port_cfg_addr +
  1544. offsetof(struct nvm_cfg1_port, link_settings));
  1545. switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
  1546. NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
  1547. case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
  1548. link->speed.autoneg = true;
  1549. break;
  1550. case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
  1551. link->speed.forced_speed = 1000;
  1552. break;
  1553. case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
  1554. link->speed.forced_speed = 10000;
  1555. break;
  1556. case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
  1557. link->speed.forced_speed = 25000;
  1558. break;
  1559. case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
  1560. link->speed.forced_speed = 40000;
  1561. break;
  1562. case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
  1563. link->speed.forced_speed = 50000;
  1564. break;
  1565. case NVM_CFG1_PORT_DRV_LINK_SPEED_BB_100G:
  1566. link->speed.forced_speed = 100000;
  1567. break;
  1568. default:
  1569. DP_NOTICE(p_hwfn, "Unknown Speed in 0x%08x\n", link_temp);
  1570. }
  1571. link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
  1572. link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
  1573. link->pause.autoneg = !!(link_temp &
  1574. NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
  1575. link->pause.forced_rx = !!(link_temp &
  1576. NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
  1577. link->pause.forced_tx = !!(link_temp &
  1578. NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
  1579. link->loopback_mode = 0;
  1580. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  1581. "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x\n",
  1582. link->speed.forced_speed, link->speed.advertised_speeds,
  1583. link->speed.autoneg, link->pause.autoneg);
  1584. /* Read Multi-function information from shmem */
  1585. addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  1586. offsetof(struct nvm_cfg1, glob) +
  1587. offsetof(struct nvm_cfg1_glob, generic_cont0);
  1588. generic_cont0 = qed_rd(p_hwfn, p_ptt, addr);
  1589. mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
  1590. NVM_CFG1_GLOB_MF_MODE_OFFSET;
  1591. switch (mf_mode) {
  1592. case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
  1593. p_hwfn->cdev->mf_mode = QED_MF_OVLAN;
  1594. break;
  1595. case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
  1596. p_hwfn->cdev->mf_mode = QED_MF_NPAR;
  1597. break;
  1598. case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
  1599. p_hwfn->cdev->mf_mode = QED_MF_DEFAULT;
  1600. break;
  1601. }
  1602. DP_INFO(p_hwfn, "Multi function mode is %08x\n",
  1603. p_hwfn->cdev->mf_mode);
  1604. /* Read Multi-function information from shmem */
  1605. addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  1606. offsetof(struct nvm_cfg1, glob) +
  1607. offsetof(struct nvm_cfg1_glob, device_capabilities);
  1608. device_capabilities = qed_rd(p_hwfn, p_ptt, addr);
  1609. if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET)
  1610. __set_bit(QED_DEV_CAP_ETH,
  1611. &p_hwfn->hw_info.device_capabilities);
  1612. if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ISCSI)
  1613. __set_bit(QED_DEV_CAP_ISCSI,
  1614. &p_hwfn->hw_info.device_capabilities);
  1615. if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ROCE)
  1616. __set_bit(QED_DEV_CAP_ROCE,
  1617. &p_hwfn->hw_info.device_capabilities);
  1618. return qed_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
  1619. }
  1620. static void qed_get_num_funcs(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  1621. {
  1622. u8 num_funcs, enabled_func_idx = p_hwfn->rel_pf_id;
  1623. u32 reg_function_hide, tmp, eng_mask, low_pfs_mask;
  1624. num_funcs = MAX_NUM_PFS_BB;
  1625. /* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values
  1626. * in the other bits are selected.
  1627. * Bits 1-15 are for functions 1-15, respectively, and their value is
  1628. * '0' only for enabled functions (function 0 always exists and
  1629. * enabled).
  1630. * In case of CMT, only the "even" functions are enabled, and thus the
  1631. * number of functions for both hwfns is learnt from the same bits.
  1632. */
  1633. reg_function_hide = qed_rd(p_hwfn, p_ptt, MISCS_REG_FUNCTION_HIDE);
  1634. if (reg_function_hide & 0x1) {
  1635. if (QED_PATH_ID(p_hwfn) && p_hwfn->cdev->num_hwfns == 1) {
  1636. num_funcs = 0;
  1637. eng_mask = 0xaaaa;
  1638. } else {
  1639. num_funcs = 1;
  1640. eng_mask = 0x5554;
  1641. }
  1642. /* Get the number of the enabled functions on the engine */
  1643. tmp = (reg_function_hide ^ 0xffffffff) & eng_mask;
  1644. while (tmp) {
  1645. if (tmp & 0x1)
  1646. num_funcs++;
  1647. tmp >>= 0x1;
  1648. }
  1649. /* Get the PF index within the enabled functions */
  1650. low_pfs_mask = (0x1 << p_hwfn->abs_pf_id) - 1;
  1651. tmp = reg_function_hide & eng_mask & low_pfs_mask;
  1652. while (tmp) {
  1653. if (tmp & 0x1)
  1654. enabled_func_idx--;
  1655. tmp >>= 0x1;
  1656. }
  1657. }
  1658. p_hwfn->num_funcs_on_engine = num_funcs;
  1659. p_hwfn->enabled_func_idx = enabled_func_idx;
  1660. DP_VERBOSE(p_hwfn,
  1661. NETIF_MSG_PROBE,
  1662. "PF [rel_id %d, abs_id %d] occupies index %d within the %d enabled functions on the engine\n",
  1663. p_hwfn->rel_pf_id,
  1664. p_hwfn->abs_pf_id,
  1665. p_hwfn->enabled_func_idx, p_hwfn->num_funcs_on_engine);
  1666. }
  1667. static int
  1668. qed_get_hw_info(struct qed_hwfn *p_hwfn,
  1669. struct qed_ptt *p_ptt,
  1670. enum qed_pci_personality personality)
  1671. {
  1672. u32 port_mode;
  1673. int rc;
  1674. /* Since all information is common, only first hwfns should do this */
  1675. if (IS_LEAD_HWFN(p_hwfn)) {
  1676. rc = qed_iov_hw_info(p_hwfn);
  1677. if (rc)
  1678. return rc;
  1679. }
  1680. /* Read the port mode */
  1681. port_mode = qed_rd(p_hwfn, p_ptt,
  1682. CNIG_REG_NW_PORT_MODE_BB_B0);
  1683. if (port_mode < 3) {
  1684. p_hwfn->cdev->num_ports_in_engines = 1;
  1685. } else if (port_mode <= 5) {
  1686. p_hwfn->cdev->num_ports_in_engines = 2;
  1687. } else {
  1688. DP_NOTICE(p_hwfn, "PORT MODE: %d not supported\n",
  1689. p_hwfn->cdev->num_ports_in_engines);
  1690. /* Default num_ports_in_engines to something */
  1691. p_hwfn->cdev->num_ports_in_engines = 1;
  1692. }
  1693. qed_hw_get_nvm_info(p_hwfn, p_ptt);
  1694. rc = qed_int_igu_read_cam(p_hwfn, p_ptt);
  1695. if (rc)
  1696. return rc;
  1697. if (qed_mcp_is_init(p_hwfn))
  1698. ether_addr_copy(p_hwfn->hw_info.hw_mac_addr,
  1699. p_hwfn->mcp_info->func_info.mac);
  1700. else
  1701. eth_random_addr(p_hwfn->hw_info.hw_mac_addr);
  1702. if (qed_mcp_is_init(p_hwfn)) {
  1703. if (p_hwfn->mcp_info->func_info.ovlan != QED_MCP_VLAN_UNSET)
  1704. p_hwfn->hw_info.ovlan =
  1705. p_hwfn->mcp_info->func_info.ovlan;
  1706. qed_mcp_cmd_port_init(p_hwfn, p_ptt);
  1707. }
  1708. if (qed_mcp_is_init(p_hwfn)) {
  1709. enum qed_pci_personality protocol;
  1710. protocol = p_hwfn->mcp_info->func_info.protocol;
  1711. p_hwfn->hw_info.personality = protocol;
  1712. }
  1713. qed_get_num_funcs(p_hwfn, p_ptt);
  1714. if (qed_mcp_is_init(p_hwfn))
  1715. p_hwfn->hw_info.mtu = p_hwfn->mcp_info->func_info.mtu;
  1716. return qed_hw_get_resc(p_hwfn);
  1717. }
  1718. static int qed_get_dev_info(struct qed_dev *cdev)
  1719. {
  1720. struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
  1721. u32 tmp;
  1722. /* Read Vendor Id / Device Id */
  1723. pci_read_config_word(cdev->pdev, PCI_VENDOR_ID, &cdev->vendor_id);
  1724. pci_read_config_word(cdev->pdev, PCI_DEVICE_ID, &cdev->device_id);
  1725. cdev->chip_num = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt,
  1726. MISCS_REG_CHIP_NUM);
  1727. cdev->chip_rev = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt,
  1728. MISCS_REG_CHIP_REV);
  1729. MASK_FIELD(CHIP_REV, cdev->chip_rev);
  1730. cdev->type = QED_DEV_TYPE_BB;
  1731. /* Learn number of HW-functions */
  1732. tmp = qed_rd(p_hwfn, p_hwfn->p_main_ptt,
  1733. MISCS_REG_CMT_ENABLED_FOR_PAIR);
  1734. if (tmp & (1 << p_hwfn->rel_pf_id)) {
  1735. DP_NOTICE(cdev->hwfns, "device in CMT mode\n");
  1736. cdev->num_hwfns = 2;
  1737. } else {
  1738. cdev->num_hwfns = 1;
  1739. }
  1740. cdev->chip_bond_id = qed_rd(p_hwfn, p_hwfn->p_main_ptt,
  1741. MISCS_REG_CHIP_TEST_REG) >> 4;
  1742. MASK_FIELD(CHIP_BOND_ID, cdev->chip_bond_id);
  1743. cdev->chip_metal = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt,
  1744. MISCS_REG_CHIP_METAL);
  1745. MASK_FIELD(CHIP_METAL, cdev->chip_metal);
  1746. DP_INFO(cdev->hwfns,
  1747. "Chip details - Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
  1748. cdev->chip_num, cdev->chip_rev,
  1749. cdev->chip_bond_id, cdev->chip_metal);
  1750. if (QED_IS_BB(cdev) && CHIP_REV_IS_A0(cdev)) {
  1751. DP_NOTICE(cdev->hwfns,
  1752. "The chip type/rev (BB A0) is not supported!\n");
  1753. return -EINVAL;
  1754. }
  1755. return 0;
  1756. }
  1757. static int qed_hw_prepare_single(struct qed_hwfn *p_hwfn,
  1758. void __iomem *p_regview,
  1759. void __iomem *p_doorbells,
  1760. enum qed_pci_personality personality)
  1761. {
  1762. int rc = 0;
  1763. /* Split PCI bars evenly between hwfns */
  1764. p_hwfn->regview = p_regview;
  1765. p_hwfn->doorbells = p_doorbells;
  1766. if (IS_VF(p_hwfn->cdev))
  1767. return qed_vf_hw_prepare(p_hwfn);
  1768. /* Validate that chip access is feasible */
  1769. if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
  1770. DP_ERR(p_hwfn,
  1771. "Reading the ME register returns all Fs; Preventing further chip access\n");
  1772. return -EINVAL;
  1773. }
  1774. get_function_id(p_hwfn);
  1775. /* Allocate PTT pool */
  1776. rc = qed_ptt_pool_alloc(p_hwfn);
  1777. if (rc)
  1778. goto err0;
  1779. /* Allocate the main PTT */
  1780. p_hwfn->p_main_ptt = qed_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
  1781. /* First hwfn learns basic information, e.g., number of hwfns */
  1782. if (!p_hwfn->my_id) {
  1783. rc = qed_get_dev_info(p_hwfn->cdev);
  1784. if (rc)
  1785. goto err1;
  1786. }
  1787. qed_hw_hwfn_prepare(p_hwfn);
  1788. /* Initialize MCP structure */
  1789. rc = qed_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
  1790. if (rc) {
  1791. DP_NOTICE(p_hwfn, "Failed initializing mcp command\n");
  1792. goto err1;
  1793. }
  1794. /* Read the device configuration information from the HW and SHMEM */
  1795. rc = qed_get_hw_info(p_hwfn, p_hwfn->p_main_ptt, personality);
  1796. if (rc) {
  1797. DP_NOTICE(p_hwfn, "Failed to get HW information\n");
  1798. goto err2;
  1799. }
  1800. /* Allocate the init RT array and initialize the init-ops engine */
  1801. rc = qed_init_alloc(p_hwfn);
  1802. if (rc)
  1803. goto err2;
  1804. return rc;
  1805. err2:
  1806. if (IS_LEAD_HWFN(p_hwfn))
  1807. qed_iov_free_hw_info(p_hwfn->cdev);
  1808. qed_mcp_free(p_hwfn);
  1809. err1:
  1810. qed_hw_hwfn_free(p_hwfn);
  1811. err0:
  1812. return rc;
  1813. }
  1814. int qed_hw_prepare(struct qed_dev *cdev,
  1815. int personality)
  1816. {
  1817. struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
  1818. int rc;
  1819. /* Store the precompiled init data ptrs */
  1820. if (IS_PF(cdev))
  1821. qed_init_iro_array(cdev);
  1822. /* Initialize the first hwfn - will learn number of hwfns */
  1823. rc = qed_hw_prepare_single(p_hwfn,
  1824. cdev->regview,
  1825. cdev->doorbells, personality);
  1826. if (rc)
  1827. return rc;
  1828. personality = p_hwfn->hw_info.personality;
  1829. /* Initialize the rest of the hwfns */
  1830. if (cdev->num_hwfns > 1) {
  1831. void __iomem *p_regview, *p_doorbell;
  1832. u8 __iomem *addr;
  1833. /* adjust bar offset for second engine */
  1834. addr = cdev->regview + qed_hw_bar_size(p_hwfn, BAR_ID_0) / 2;
  1835. p_regview = addr;
  1836. /* adjust doorbell bar offset for second engine */
  1837. addr = cdev->doorbells + qed_hw_bar_size(p_hwfn, BAR_ID_1) / 2;
  1838. p_doorbell = addr;
  1839. /* prepare second hw function */
  1840. rc = qed_hw_prepare_single(&cdev->hwfns[1], p_regview,
  1841. p_doorbell, personality);
  1842. /* in case of error, need to free the previously
  1843. * initiliazed hwfn 0.
  1844. */
  1845. if (rc) {
  1846. if (IS_PF(cdev)) {
  1847. qed_init_free(p_hwfn);
  1848. qed_mcp_free(p_hwfn);
  1849. qed_hw_hwfn_free(p_hwfn);
  1850. }
  1851. }
  1852. }
  1853. return rc;
  1854. }
  1855. void qed_hw_remove(struct qed_dev *cdev)
  1856. {
  1857. struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
  1858. int i;
  1859. if (IS_PF(cdev))
  1860. qed_mcp_ov_update_driver_state(p_hwfn, p_hwfn->p_main_ptt,
  1861. QED_OV_DRIVER_STATE_NOT_LOADED);
  1862. for_each_hwfn(cdev, i) {
  1863. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1864. if (IS_VF(cdev)) {
  1865. qed_vf_pf_release(p_hwfn);
  1866. continue;
  1867. }
  1868. qed_init_free(p_hwfn);
  1869. qed_hw_hwfn_free(p_hwfn);
  1870. qed_mcp_free(p_hwfn);
  1871. }
  1872. qed_iov_free_hw_info(cdev);
  1873. }
  1874. static void qed_chain_free_next_ptr(struct qed_dev *cdev,
  1875. struct qed_chain *p_chain)
  1876. {
  1877. void *p_virt = p_chain->p_virt_addr, *p_virt_next = NULL;
  1878. dma_addr_t p_phys = p_chain->p_phys_addr, p_phys_next = 0;
  1879. struct qed_chain_next *p_next;
  1880. u32 size, i;
  1881. if (!p_virt)
  1882. return;
  1883. size = p_chain->elem_size * p_chain->usable_per_page;
  1884. for (i = 0; i < p_chain->page_cnt; i++) {
  1885. if (!p_virt)
  1886. break;
  1887. p_next = (struct qed_chain_next *)((u8 *)p_virt + size);
  1888. p_virt_next = p_next->next_virt;
  1889. p_phys_next = HILO_DMA_REGPAIR(p_next->next_phys);
  1890. dma_free_coherent(&cdev->pdev->dev,
  1891. QED_CHAIN_PAGE_SIZE, p_virt, p_phys);
  1892. p_virt = p_virt_next;
  1893. p_phys = p_phys_next;
  1894. }
  1895. }
  1896. static void qed_chain_free_single(struct qed_dev *cdev,
  1897. struct qed_chain *p_chain)
  1898. {
  1899. if (!p_chain->p_virt_addr)
  1900. return;
  1901. dma_free_coherent(&cdev->pdev->dev,
  1902. QED_CHAIN_PAGE_SIZE,
  1903. p_chain->p_virt_addr, p_chain->p_phys_addr);
  1904. }
  1905. static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *p_chain)
  1906. {
  1907. void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl;
  1908. u32 page_cnt = p_chain->page_cnt, i, pbl_size;
  1909. u8 *p_pbl_virt = p_chain->pbl_sp.p_virt_table;
  1910. if (!pp_virt_addr_tbl)
  1911. return;
  1912. if (!p_pbl_virt)
  1913. goto out;
  1914. for (i = 0; i < page_cnt; i++) {
  1915. if (!pp_virt_addr_tbl[i])
  1916. break;
  1917. dma_free_coherent(&cdev->pdev->dev,
  1918. QED_CHAIN_PAGE_SIZE,
  1919. pp_virt_addr_tbl[i],
  1920. *(dma_addr_t *)p_pbl_virt);
  1921. p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
  1922. }
  1923. pbl_size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
  1924. dma_free_coherent(&cdev->pdev->dev,
  1925. pbl_size,
  1926. p_chain->pbl_sp.p_virt_table,
  1927. p_chain->pbl_sp.p_phys_table);
  1928. out:
  1929. vfree(p_chain->pbl.pp_virt_addr_tbl);
  1930. }
  1931. void qed_chain_free(struct qed_dev *cdev, struct qed_chain *p_chain)
  1932. {
  1933. switch (p_chain->mode) {
  1934. case QED_CHAIN_MODE_NEXT_PTR:
  1935. qed_chain_free_next_ptr(cdev, p_chain);
  1936. break;
  1937. case QED_CHAIN_MODE_SINGLE:
  1938. qed_chain_free_single(cdev, p_chain);
  1939. break;
  1940. case QED_CHAIN_MODE_PBL:
  1941. qed_chain_free_pbl(cdev, p_chain);
  1942. break;
  1943. }
  1944. }
  1945. static int
  1946. qed_chain_alloc_sanity_check(struct qed_dev *cdev,
  1947. enum qed_chain_cnt_type cnt_type,
  1948. size_t elem_size, u32 page_cnt)
  1949. {
  1950. u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
  1951. /* The actual chain size can be larger than the maximal possible value
  1952. * after rounding up the requested elements number to pages, and after
  1953. * taking into acount the unusuable elements (next-ptr elements).
  1954. * The size of a "u16" chain can be (U16_MAX + 1) since the chain
  1955. * size/capacity fields are of a u32 type.
  1956. */
  1957. if ((cnt_type == QED_CHAIN_CNT_TYPE_U16 &&
  1958. chain_size > 0x10000) ||
  1959. (cnt_type == QED_CHAIN_CNT_TYPE_U32 &&
  1960. chain_size > 0x100000000ULL)) {
  1961. DP_NOTICE(cdev,
  1962. "The actual chain size (0x%llx) is larger than the maximal possible value\n",
  1963. chain_size);
  1964. return -EINVAL;
  1965. }
  1966. return 0;
  1967. }
  1968. static int
  1969. qed_chain_alloc_next_ptr(struct qed_dev *cdev, struct qed_chain *p_chain)
  1970. {
  1971. void *p_virt = NULL, *p_virt_prev = NULL;
  1972. dma_addr_t p_phys = 0;
  1973. u32 i;
  1974. for (i = 0; i < p_chain->page_cnt; i++) {
  1975. p_virt = dma_alloc_coherent(&cdev->pdev->dev,
  1976. QED_CHAIN_PAGE_SIZE,
  1977. &p_phys, GFP_KERNEL);
  1978. if (!p_virt)
  1979. return -ENOMEM;
  1980. if (i == 0) {
  1981. qed_chain_init_mem(p_chain, p_virt, p_phys);
  1982. qed_chain_reset(p_chain);
  1983. } else {
  1984. qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
  1985. p_virt, p_phys);
  1986. }
  1987. p_virt_prev = p_virt;
  1988. }
  1989. /* Last page's next element should point to the beginning of the
  1990. * chain.
  1991. */
  1992. qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
  1993. p_chain->p_virt_addr,
  1994. p_chain->p_phys_addr);
  1995. return 0;
  1996. }
  1997. static int
  1998. qed_chain_alloc_single(struct qed_dev *cdev, struct qed_chain *p_chain)
  1999. {
  2000. dma_addr_t p_phys = 0;
  2001. void *p_virt = NULL;
  2002. p_virt = dma_alloc_coherent(&cdev->pdev->dev,
  2003. QED_CHAIN_PAGE_SIZE, &p_phys, GFP_KERNEL);
  2004. if (!p_virt)
  2005. return -ENOMEM;
  2006. qed_chain_init_mem(p_chain, p_virt, p_phys);
  2007. qed_chain_reset(p_chain);
  2008. return 0;
  2009. }
  2010. static int qed_chain_alloc_pbl(struct qed_dev *cdev, struct qed_chain *p_chain)
  2011. {
  2012. u32 page_cnt = p_chain->page_cnt, size, i;
  2013. dma_addr_t p_phys = 0, p_pbl_phys = 0;
  2014. void **pp_virt_addr_tbl = NULL;
  2015. u8 *p_pbl_virt = NULL;
  2016. void *p_virt = NULL;
  2017. size = page_cnt * sizeof(*pp_virt_addr_tbl);
  2018. pp_virt_addr_tbl = vzalloc(size);
  2019. if (!pp_virt_addr_tbl)
  2020. return -ENOMEM;
  2021. /* The allocation of the PBL table is done with its full size, since it
  2022. * is expected to be successive.
  2023. * qed_chain_init_pbl_mem() is called even in a case of an allocation
  2024. * failure, since pp_virt_addr_tbl was previously allocated, and it
  2025. * should be saved to allow its freeing during the error flow.
  2026. */
  2027. size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
  2028. p_pbl_virt = dma_alloc_coherent(&cdev->pdev->dev,
  2029. size, &p_pbl_phys, GFP_KERNEL);
  2030. qed_chain_init_pbl_mem(p_chain, p_pbl_virt, p_pbl_phys,
  2031. pp_virt_addr_tbl);
  2032. if (!p_pbl_virt)
  2033. return -ENOMEM;
  2034. for (i = 0; i < page_cnt; i++) {
  2035. p_virt = dma_alloc_coherent(&cdev->pdev->dev,
  2036. QED_CHAIN_PAGE_SIZE,
  2037. &p_phys, GFP_KERNEL);
  2038. if (!p_virt)
  2039. return -ENOMEM;
  2040. if (i == 0) {
  2041. qed_chain_init_mem(p_chain, p_virt, p_phys);
  2042. qed_chain_reset(p_chain);
  2043. }
  2044. /* Fill the PBL table with the physical address of the page */
  2045. *(dma_addr_t *)p_pbl_virt = p_phys;
  2046. /* Keep the virtual address of the page */
  2047. p_chain->pbl.pp_virt_addr_tbl[i] = p_virt;
  2048. p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
  2049. }
  2050. return 0;
  2051. }
  2052. int qed_chain_alloc(struct qed_dev *cdev,
  2053. enum qed_chain_use_mode intended_use,
  2054. enum qed_chain_mode mode,
  2055. enum qed_chain_cnt_type cnt_type,
  2056. u32 num_elems, size_t elem_size, struct qed_chain *p_chain)
  2057. {
  2058. u32 page_cnt;
  2059. int rc = 0;
  2060. if (mode == QED_CHAIN_MODE_SINGLE)
  2061. page_cnt = 1;
  2062. else
  2063. page_cnt = QED_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
  2064. rc = qed_chain_alloc_sanity_check(cdev, cnt_type, elem_size, page_cnt);
  2065. if (rc) {
  2066. DP_NOTICE(cdev,
  2067. "Cannot allocate a chain with the given arguments:\n");
  2068. DP_NOTICE(cdev,
  2069. "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu]\n",
  2070. intended_use, mode, cnt_type, num_elems, elem_size);
  2071. return rc;
  2072. }
  2073. qed_chain_init_params(p_chain, page_cnt, (u8) elem_size, intended_use,
  2074. mode, cnt_type);
  2075. switch (mode) {
  2076. case QED_CHAIN_MODE_NEXT_PTR:
  2077. rc = qed_chain_alloc_next_ptr(cdev, p_chain);
  2078. break;
  2079. case QED_CHAIN_MODE_SINGLE:
  2080. rc = qed_chain_alloc_single(cdev, p_chain);
  2081. break;
  2082. case QED_CHAIN_MODE_PBL:
  2083. rc = qed_chain_alloc_pbl(cdev, p_chain);
  2084. break;
  2085. }
  2086. if (rc)
  2087. goto nomem;
  2088. return 0;
  2089. nomem:
  2090. qed_chain_free(cdev, p_chain);
  2091. return rc;
  2092. }
  2093. int qed_fw_l2_queue(struct qed_hwfn *p_hwfn, u16 src_id, u16 *dst_id)
  2094. {
  2095. if (src_id >= RESC_NUM(p_hwfn, QED_L2_QUEUE)) {
  2096. u16 min, max;
  2097. min = (u16) RESC_START(p_hwfn, QED_L2_QUEUE);
  2098. max = min + RESC_NUM(p_hwfn, QED_L2_QUEUE);
  2099. DP_NOTICE(p_hwfn,
  2100. "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
  2101. src_id, min, max);
  2102. return -EINVAL;
  2103. }
  2104. *dst_id = RESC_START(p_hwfn, QED_L2_QUEUE) + src_id;
  2105. return 0;
  2106. }
  2107. int qed_fw_vport(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id)
  2108. {
  2109. if (src_id >= RESC_NUM(p_hwfn, QED_VPORT)) {
  2110. u8 min, max;
  2111. min = (u8)RESC_START(p_hwfn, QED_VPORT);
  2112. max = min + RESC_NUM(p_hwfn, QED_VPORT);
  2113. DP_NOTICE(p_hwfn,
  2114. "vport id [%d] is not valid, available indices [%d - %d]\n",
  2115. src_id, min, max);
  2116. return -EINVAL;
  2117. }
  2118. *dst_id = RESC_START(p_hwfn, QED_VPORT) + src_id;
  2119. return 0;
  2120. }
  2121. int qed_fw_rss_eng(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id)
  2122. {
  2123. if (src_id >= RESC_NUM(p_hwfn, QED_RSS_ENG)) {
  2124. u8 min, max;
  2125. min = (u8)RESC_START(p_hwfn, QED_RSS_ENG);
  2126. max = min + RESC_NUM(p_hwfn, QED_RSS_ENG);
  2127. DP_NOTICE(p_hwfn,
  2128. "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
  2129. src_id, min, max);
  2130. return -EINVAL;
  2131. }
  2132. *dst_id = RESC_START(p_hwfn, QED_RSS_ENG) + src_id;
  2133. return 0;
  2134. }
  2135. static void qed_llh_mac_to_filter(u32 *p_high, u32 *p_low,
  2136. u8 *p_filter)
  2137. {
  2138. *p_high = p_filter[1] | (p_filter[0] << 8);
  2139. *p_low = p_filter[5] | (p_filter[4] << 8) |
  2140. (p_filter[3] << 16) | (p_filter[2] << 24);
  2141. }
  2142. int qed_llh_add_mac_filter(struct qed_hwfn *p_hwfn,
  2143. struct qed_ptt *p_ptt, u8 *p_filter)
  2144. {
  2145. u32 high = 0, low = 0, en;
  2146. int i;
  2147. if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
  2148. return 0;
  2149. qed_llh_mac_to_filter(&high, &low, p_filter);
  2150. /* Find a free entry and utilize it */
  2151. for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
  2152. en = qed_rd(p_hwfn, p_ptt,
  2153. NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32));
  2154. if (en)
  2155. continue;
  2156. qed_wr(p_hwfn, p_ptt,
  2157. NIG_REG_LLH_FUNC_FILTER_VALUE +
  2158. 2 * i * sizeof(u32), low);
  2159. qed_wr(p_hwfn, p_ptt,
  2160. NIG_REG_LLH_FUNC_FILTER_VALUE +
  2161. (2 * i + 1) * sizeof(u32), high);
  2162. qed_wr(p_hwfn, p_ptt,
  2163. NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 0);
  2164. qed_wr(p_hwfn, p_ptt,
  2165. NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
  2166. i * sizeof(u32), 0);
  2167. qed_wr(p_hwfn, p_ptt,
  2168. NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1);
  2169. break;
  2170. }
  2171. if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) {
  2172. DP_NOTICE(p_hwfn,
  2173. "Failed to find an empty LLH filter to utilize\n");
  2174. return -EINVAL;
  2175. }
  2176. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  2177. "mac: %pM is added at %d\n",
  2178. p_filter, i);
  2179. return 0;
  2180. }
  2181. void qed_llh_remove_mac_filter(struct qed_hwfn *p_hwfn,
  2182. struct qed_ptt *p_ptt, u8 *p_filter)
  2183. {
  2184. u32 high = 0, low = 0;
  2185. int i;
  2186. if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
  2187. return;
  2188. qed_llh_mac_to_filter(&high, &low, p_filter);
  2189. /* Find the entry and clean it */
  2190. for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
  2191. if (qed_rd(p_hwfn, p_ptt,
  2192. NIG_REG_LLH_FUNC_FILTER_VALUE +
  2193. 2 * i * sizeof(u32)) != low)
  2194. continue;
  2195. if (qed_rd(p_hwfn, p_ptt,
  2196. NIG_REG_LLH_FUNC_FILTER_VALUE +
  2197. (2 * i + 1) * sizeof(u32)) != high)
  2198. continue;
  2199. qed_wr(p_hwfn, p_ptt,
  2200. NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
  2201. qed_wr(p_hwfn, p_ptt,
  2202. NIG_REG_LLH_FUNC_FILTER_VALUE + 2 * i * sizeof(u32), 0);
  2203. qed_wr(p_hwfn, p_ptt,
  2204. NIG_REG_LLH_FUNC_FILTER_VALUE +
  2205. (2 * i + 1) * sizeof(u32), 0);
  2206. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  2207. "mac: %pM is removed from %d\n",
  2208. p_filter, i);
  2209. break;
  2210. }
  2211. if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
  2212. DP_NOTICE(p_hwfn, "Tried to remove a non-configured filter\n");
  2213. }
  2214. static int qed_set_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  2215. u32 hw_addr, void *p_eth_qzone,
  2216. size_t eth_qzone_size, u8 timeset)
  2217. {
  2218. struct coalescing_timeset *p_coal_timeset;
  2219. if (p_hwfn->cdev->int_coalescing_mode != QED_COAL_MODE_ENABLE) {
  2220. DP_NOTICE(p_hwfn, "Coalescing configuration not enabled\n");
  2221. return -EINVAL;
  2222. }
  2223. p_coal_timeset = p_eth_qzone;
  2224. memset(p_coal_timeset, 0, eth_qzone_size);
  2225. SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_TIMESET, timeset);
  2226. SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_VALID, 1);
  2227. qed_memcpy_to(p_hwfn, p_ptt, hw_addr, p_eth_qzone, eth_qzone_size);
  2228. return 0;
  2229. }
  2230. int qed_set_rxq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  2231. u16 coalesce, u8 qid, u16 sb_id)
  2232. {
  2233. struct ustorm_eth_queue_zone eth_qzone;
  2234. u8 timeset, timer_res;
  2235. u16 fw_qid = 0;
  2236. u32 address;
  2237. int rc;
  2238. /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
  2239. if (coalesce <= 0x7F) {
  2240. timer_res = 0;
  2241. } else if (coalesce <= 0xFF) {
  2242. timer_res = 1;
  2243. } else if (coalesce <= 0x1FF) {
  2244. timer_res = 2;
  2245. } else {
  2246. DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
  2247. return -EINVAL;
  2248. }
  2249. timeset = (u8)(coalesce >> timer_res);
  2250. rc = qed_fw_l2_queue(p_hwfn, (u16)qid, &fw_qid);
  2251. if (rc)
  2252. return rc;
  2253. rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res, sb_id, false);
  2254. if (rc)
  2255. goto out;
  2256. address = BAR0_MAP_REG_USDM_RAM + USTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid);
  2257. rc = qed_set_coalesce(p_hwfn, p_ptt, address, &eth_qzone,
  2258. sizeof(struct ustorm_eth_queue_zone), timeset);
  2259. if (rc)
  2260. goto out;
  2261. p_hwfn->cdev->rx_coalesce_usecs = coalesce;
  2262. out:
  2263. return rc;
  2264. }
  2265. int qed_set_txq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  2266. u16 coalesce, u8 qid, u16 sb_id)
  2267. {
  2268. struct xstorm_eth_queue_zone eth_qzone;
  2269. u8 timeset, timer_res;
  2270. u16 fw_qid = 0;
  2271. u32 address;
  2272. int rc;
  2273. /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
  2274. if (coalesce <= 0x7F) {
  2275. timer_res = 0;
  2276. } else if (coalesce <= 0xFF) {
  2277. timer_res = 1;
  2278. } else if (coalesce <= 0x1FF) {
  2279. timer_res = 2;
  2280. } else {
  2281. DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
  2282. return -EINVAL;
  2283. }
  2284. timeset = (u8)(coalesce >> timer_res);
  2285. rc = qed_fw_l2_queue(p_hwfn, (u16)qid, &fw_qid);
  2286. if (rc)
  2287. return rc;
  2288. rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res, sb_id, true);
  2289. if (rc)
  2290. goto out;
  2291. address = BAR0_MAP_REG_XSDM_RAM + XSTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid);
  2292. rc = qed_set_coalesce(p_hwfn, p_ptt, address, &eth_qzone,
  2293. sizeof(struct xstorm_eth_queue_zone), timeset);
  2294. if (rc)
  2295. goto out;
  2296. p_hwfn->cdev->tx_coalesce_usecs = coalesce;
  2297. out:
  2298. return rc;
  2299. }
  2300. /* Calculate final WFQ values for all vports and configure them.
  2301. * After this configuration each vport will have
  2302. * approx min rate = min_pf_rate * (vport_wfq / QED_WFQ_UNIT)
  2303. */
  2304. static void qed_configure_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
  2305. struct qed_ptt *p_ptt,
  2306. u32 min_pf_rate)
  2307. {
  2308. struct init_qm_vport_params *vport_params;
  2309. int i;
  2310. vport_params = p_hwfn->qm_info.qm_vport_params;
  2311. for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
  2312. u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
  2313. vport_params[i].vport_wfq = (wfq_speed * QED_WFQ_UNIT) /
  2314. min_pf_rate;
  2315. qed_init_vport_wfq(p_hwfn, p_ptt,
  2316. vport_params[i].first_tx_pq_id,
  2317. vport_params[i].vport_wfq);
  2318. }
  2319. }
  2320. static void qed_init_wfq_default_param(struct qed_hwfn *p_hwfn,
  2321. u32 min_pf_rate)
  2322. {
  2323. int i;
  2324. for (i = 0; i < p_hwfn->qm_info.num_vports; i++)
  2325. p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1;
  2326. }
  2327. static void qed_disable_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
  2328. struct qed_ptt *p_ptt,
  2329. u32 min_pf_rate)
  2330. {
  2331. struct init_qm_vport_params *vport_params;
  2332. int i;
  2333. vport_params = p_hwfn->qm_info.qm_vport_params;
  2334. for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
  2335. qed_init_wfq_default_param(p_hwfn, min_pf_rate);
  2336. qed_init_vport_wfq(p_hwfn, p_ptt,
  2337. vport_params[i].first_tx_pq_id,
  2338. vport_params[i].vport_wfq);
  2339. }
  2340. }
  2341. /* This function performs several validations for WFQ
  2342. * configuration and required min rate for a given vport
  2343. * 1. req_rate must be greater than one percent of min_pf_rate.
  2344. * 2. req_rate should not cause other vports [not configured for WFQ explicitly]
  2345. * rates to get less than one percent of min_pf_rate.
  2346. * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate.
  2347. */
  2348. static int qed_init_wfq_param(struct qed_hwfn *p_hwfn,
  2349. u16 vport_id, u32 req_rate, u32 min_pf_rate)
  2350. {
  2351. u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0;
  2352. int non_requested_count = 0, req_count = 0, i, num_vports;
  2353. num_vports = p_hwfn->qm_info.num_vports;
  2354. /* Accounting for the vports which are configured for WFQ explicitly */
  2355. for (i = 0; i < num_vports; i++) {
  2356. u32 tmp_speed;
  2357. if ((i != vport_id) &&
  2358. p_hwfn->qm_info.wfq_data[i].configured) {
  2359. req_count++;
  2360. tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
  2361. total_req_min_rate += tmp_speed;
  2362. }
  2363. }
  2364. /* Include current vport data as well */
  2365. req_count++;
  2366. total_req_min_rate += req_rate;
  2367. non_requested_count = num_vports - req_count;
  2368. if (req_rate < min_pf_rate / QED_WFQ_UNIT) {
  2369. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  2370. "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
  2371. vport_id, req_rate, min_pf_rate);
  2372. return -EINVAL;
  2373. }
  2374. if (num_vports > QED_WFQ_UNIT) {
  2375. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  2376. "Number of vports is greater than %d\n",
  2377. QED_WFQ_UNIT);
  2378. return -EINVAL;
  2379. }
  2380. if (total_req_min_rate > min_pf_rate) {
  2381. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  2382. "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
  2383. total_req_min_rate, min_pf_rate);
  2384. return -EINVAL;
  2385. }
  2386. total_left_rate = min_pf_rate - total_req_min_rate;
  2387. left_rate_per_vp = total_left_rate / non_requested_count;
  2388. if (left_rate_per_vp < min_pf_rate / QED_WFQ_UNIT) {
  2389. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  2390. "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
  2391. left_rate_per_vp, min_pf_rate);
  2392. return -EINVAL;
  2393. }
  2394. p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate;
  2395. p_hwfn->qm_info.wfq_data[vport_id].configured = true;
  2396. for (i = 0; i < num_vports; i++) {
  2397. if (p_hwfn->qm_info.wfq_data[i].configured)
  2398. continue;
  2399. p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp;
  2400. }
  2401. return 0;
  2402. }
  2403. static int __qed_configure_vport_wfq(struct qed_hwfn *p_hwfn,
  2404. struct qed_ptt *p_ptt, u16 vp_id, u32 rate)
  2405. {
  2406. struct qed_mcp_link_state *p_link;
  2407. int rc = 0;
  2408. p_link = &p_hwfn->cdev->hwfns[0].mcp_info->link_output;
  2409. if (!p_link->min_pf_rate) {
  2410. p_hwfn->qm_info.wfq_data[vp_id].min_speed = rate;
  2411. p_hwfn->qm_info.wfq_data[vp_id].configured = true;
  2412. return rc;
  2413. }
  2414. rc = qed_init_wfq_param(p_hwfn, vp_id, rate, p_link->min_pf_rate);
  2415. if (!rc)
  2416. qed_configure_wfq_for_all_vports(p_hwfn, p_ptt,
  2417. p_link->min_pf_rate);
  2418. else
  2419. DP_NOTICE(p_hwfn,
  2420. "Validation failed while configuring min rate\n");
  2421. return rc;
  2422. }
  2423. static int __qed_configure_vp_wfq_on_link_change(struct qed_hwfn *p_hwfn,
  2424. struct qed_ptt *p_ptt,
  2425. u32 min_pf_rate)
  2426. {
  2427. bool use_wfq = false;
  2428. int rc = 0;
  2429. u16 i;
  2430. /* Validate all pre configured vports for wfq */
  2431. for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
  2432. u32 rate;
  2433. if (!p_hwfn->qm_info.wfq_data[i].configured)
  2434. continue;
  2435. rate = p_hwfn->qm_info.wfq_data[i].min_speed;
  2436. use_wfq = true;
  2437. rc = qed_init_wfq_param(p_hwfn, i, rate, min_pf_rate);
  2438. if (rc) {
  2439. DP_NOTICE(p_hwfn,
  2440. "WFQ validation failed while configuring min rate\n");
  2441. break;
  2442. }
  2443. }
  2444. if (!rc && use_wfq)
  2445. qed_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
  2446. else
  2447. qed_disable_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
  2448. return rc;
  2449. }
  2450. /* Main API for qed clients to configure vport min rate.
  2451. * vp_id - vport id in PF Range[0 - (total_num_vports_per_pf - 1)]
  2452. * rate - Speed in Mbps needs to be assigned to a given vport.
  2453. */
  2454. int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate)
  2455. {
  2456. int i, rc = -EINVAL;
  2457. /* Currently not supported; Might change in future */
  2458. if (cdev->num_hwfns > 1) {
  2459. DP_NOTICE(cdev,
  2460. "WFQ configuration is not supported for this device\n");
  2461. return rc;
  2462. }
  2463. for_each_hwfn(cdev, i) {
  2464. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  2465. struct qed_ptt *p_ptt;
  2466. p_ptt = qed_ptt_acquire(p_hwfn);
  2467. if (!p_ptt)
  2468. return -EBUSY;
  2469. rc = __qed_configure_vport_wfq(p_hwfn, p_ptt, vp_id, rate);
  2470. if (rc) {
  2471. qed_ptt_release(p_hwfn, p_ptt);
  2472. return rc;
  2473. }
  2474. qed_ptt_release(p_hwfn, p_ptt);
  2475. }
  2476. return rc;
  2477. }
  2478. /* API to configure WFQ from mcp link change */
  2479. void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev, u32 min_pf_rate)
  2480. {
  2481. int i;
  2482. if (cdev->num_hwfns > 1) {
  2483. DP_VERBOSE(cdev,
  2484. NETIF_MSG_LINK,
  2485. "WFQ configuration is not supported for this device\n");
  2486. return;
  2487. }
  2488. for_each_hwfn(cdev, i) {
  2489. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  2490. __qed_configure_vp_wfq_on_link_change(p_hwfn,
  2491. p_hwfn->p_dpc_ptt,
  2492. min_pf_rate);
  2493. }
  2494. }
  2495. int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
  2496. struct qed_ptt *p_ptt,
  2497. struct qed_mcp_link_state *p_link,
  2498. u8 max_bw)
  2499. {
  2500. int rc = 0;
  2501. p_hwfn->mcp_info->func_info.bandwidth_max = max_bw;
  2502. if (!p_link->line_speed && (max_bw != 100))
  2503. return rc;
  2504. p_link->speed = (p_link->line_speed * max_bw) / 100;
  2505. p_hwfn->qm_info.pf_rl = p_link->speed;
  2506. /* Since the limiter also affects Tx-switched traffic, we don't want it
  2507. * to limit such traffic in case there's no actual limit.
  2508. * In that case, set limit to imaginary high boundary.
  2509. */
  2510. if (max_bw == 100)
  2511. p_hwfn->qm_info.pf_rl = 100000;
  2512. rc = qed_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
  2513. p_hwfn->qm_info.pf_rl);
  2514. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  2515. "Configured MAX bandwidth to be %08x Mb/sec\n",
  2516. p_link->speed);
  2517. return rc;
  2518. }
  2519. /* Main API to configure PF max bandwidth where bw range is [1 - 100] */
  2520. int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw)
  2521. {
  2522. int i, rc = -EINVAL;
  2523. if (max_bw < 1 || max_bw > 100) {
  2524. DP_NOTICE(cdev, "PF max bw valid range is [1-100]\n");
  2525. return rc;
  2526. }
  2527. for_each_hwfn(cdev, i) {
  2528. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  2529. struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
  2530. struct qed_mcp_link_state *p_link;
  2531. struct qed_ptt *p_ptt;
  2532. p_link = &p_lead->mcp_info->link_output;
  2533. p_ptt = qed_ptt_acquire(p_hwfn);
  2534. if (!p_ptt)
  2535. return -EBUSY;
  2536. rc = __qed_configure_pf_max_bandwidth(p_hwfn, p_ptt,
  2537. p_link, max_bw);
  2538. qed_ptt_release(p_hwfn, p_ptt);
  2539. if (rc)
  2540. break;
  2541. }
  2542. return rc;
  2543. }
  2544. int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
  2545. struct qed_ptt *p_ptt,
  2546. struct qed_mcp_link_state *p_link,
  2547. u8 min_bw)
  2548. {
  2549. int rc = 0;
  2550. p_hwfn->mcp_info->func_info.bandwidth_min = min_bw;
  2551. p_hwfn->qm_info.pf_wfq = min_bw;
  2552. if (!p_link->line_speed)
  2553. return rc;
  2554. p_link->min_pf_rate = (p_link->line_speed * min_bw) / 100;
  2555. rc = qed_init_pf_wfq(p_hwfn, p_ptt, p_hwfn->rel_pf_id, min_bw);
  2556. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  2557. "Configured MIN bandwidth to be %d Mb/sec\n",
  2558. p_link->min_pf_rate);
  2559. return rc;
  2560. }
  2561. /* Main API to configure PF min bandwidth where bw range is [1-100] */
  2562. int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw)
  2563. {
  2564. int i, rc = -EINVAL;
  2565. if (min_bw < 1 || min_bw > 100) {
  2566. DP_NOTICE(cdev, "PF min bw valid range is [1-100]\n");
  2567. return rc;
  2568. }
  2569. for_each_hwfn(cdev, i) {
  2570. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  2571. struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
  2572. struct qed_mcp_link_state *p_link;
  2573. struct qed_ptt *p_ptt;
  2574. p_link = &p_lead->mcp_info->link_output;
  2575. p_ptt = qed_ptt_acquire(p_hwfn);
  2576. if (!p_ptt)
  2577. return -EBUSY;
  2578. rc = __qed_configure_pf_min_bandwidth(p_hwfn, p_ptt,
  2579. p_link, min_bw);
  2580. if (rc) {
  2581. qed_ptt_release(p_hwfn, p_ptt);
  2582. return rc;
  2583. }
  2584. if (p_link->min_pf_rate) {
  2585. u32 min_rate = p_link->min_pf_rate;
  2586. rc = __qed_configure_vp_wfq_on_link_change(p_hwfn,
  2587. p_ptt,
  2588. min_rate);
  2589. }
  2590. qed_ptt_release(p_hwfn, p_ptt);
  2591. }
  2592. return rc;
  2593. }
  2594. void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  2595. {
  2596. struct qed_mcp_link_state *p_link;
  2597. p_link = &p_hwfn->mcp_info->link_output;
  2598. if (p_link->min_pf_rate)
  2599. qed_disable_wfq_for_all_vports(p_hwfn, p_ptt,
  2600. p_link->min_pf_rate);
  2601. memset(p_hwfn->qm_info.wfq_data, 0,
  2602. sizeof(*p_hwfn->qm_info.wfq_data) * p_hwfn->qm_info.num_vports);
  2603. }