qed_dev.c 70 KB

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