qed_dev.c 88 KB

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