qed_dev.c 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305
  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_rdma.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. static u32 qed_hw_bar_size(struct qed_hwfn *p_hwfn,
  69. struct qed_ptt *p_ptt, enum BAR_ID bar_id)
  70. {
  71. u32 bar_reg = (bar_id == BAR_ID_0 ?
  72. PGLUE_B_REG_PF_BAR0_SIZE : PGLUE_B_REG_PF_BAR1_SIZE);
  73. u32 val;
  74. if (IS_VF(p_hwfn->cdev))
  75. return qed_vf_hw_bar_size(p_hwfn, bar_id);
  76. val = qed_rd(p_hwfn, p_ptt, bar_reg);
  77. if (val)
  78. return 1 << (val + 15);
  79. /* Old MFW initialized above registered only conditionally */
  80. if (p_hwfn->cdev->num_hwfns > 1) {
  81. DP_INFO(p_hwfn,
  82. "BAR size not configured. Assuming BAR size of 256kB for GRC and 512kB for DB\n");
  83. return BAR_ID_0 ? 256 * 1024 : 512 * 1024;
  84. } else {
  85. DP_INFO(p_hwfn,
  86. "BAR size not configured. Assuming BAR size of 512kB for GRC and 512kB for DB\n");
  87. return 512 * 1024;
  88. }
  89. }
  90. void qed_init_dp(struct qed_dev *cdev, u32 dp_module, u8 dp_level)
  91. {
  92. u32 i;
  93. cdev->dp_level = dp_level;
  94. cdev->dp_module = dp_module;
  95. for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
  96. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  97. p_hwfn->dp_level = dp_level;
  98. p_hwfn->dp_module = dp_module;
  99. }
  100. }
  101. void qed_init_struct(struct qed_dev *cdev)
  102. {
  103. u8 i;
  104. for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
  105. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  106. p_hwfn->cdev = cdev;
  107. p_hwfn->my_id = i;
  108. p_hwfn->b_active = false;
  109. mutex_init(&p_hwfn->dmae_info.mutex);
  110. }
  111. /* hwfn 0 is always active */
  112. cdev->hwfns[0].b_active = true;
  113. /* set the default cache alignment to 128 */
  114. cdev->cache_shift = 7;
  115. }
  116. static void qed_qm_info_free(struct qed_hwfn *p_hwfn)
  117. {
  118. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  119. kfree(qm_info->qm_pq_params);
  120. qm_info->qm_pq_params = NULL;
  121. kfree(qm_info->qm_vport_params);
  122. qm_info->qm_vport_params = NULL;
  123. kfree(qm_info->qm_port_params);
  124. qm_info->qm_port_params = NULL;
  125. kfree(qm_info->wfq_data);
  126. qm_info->wfq_data = NULL;
  127. }
  128. void qed_resc_free(struct qed_dev *cdev)
  129. {
  130. int i;
  131. if (IS_VF(cdev)) {
  132. for_each_hwfn(cdev, i)
  133. qed_l2_free(&cdev->hwfns[i]);
  134. return;
  135. }
  136. kfree(cdev->fw_data);
  137. cdev->fw_data = NULL;
  138. kfree(cdev->reset_stats);
  139. cdev->reset_stats = NULL;
  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);
  146. qed_consq_free(p_hwfn);
  147. qed_int_free(p_hwfn);
  148. #ifdef CONFIG_QED_LL2
  149. qed_ll2_free(p_hwfn);
  150. #endif
  151. if (p_hwfn->hw_info.personality == QED_PCI_FCOE)
  152. qed_fcoe_free(p_hwfn);
  153. if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
  154. qed_iscsi_free(p_hwfn);
  155. qed_ooo_free(p_hwfn);
  156. }
  157. qed_iov_free(p_hwfn);
  158. qed_l2_free(p_hwfn);
  159. qed_dmae_info_free(p_hwfn);
  160. qed_dcbx_info_free(p_hwfn);
  161. }
  162. }
  163. /******************** QM initialization *******************/
  164. #define ACTIVE_TCS_BMAP 0x9f
  165. #define ACTIVE_TCS_BMAP_4PORT_K2 0xf
  166. /* determines the physical queue flags for a given PF. */
  167. static u32 qed_get_pq_flags(struct qed_hwfn *p_hwfn)
  168. {
  169. u32 flags;
  170. /* common flags */
  171. flags = PQ_FLAGS_LB;
  172. /* feature flags */
  173. if (IS_QED_SRIOV(p_hwfn->cdev))
  174. flags |= PQ_FLAGS_VFS;
  175. /* protocol flags */
  176. switch (p_hwfn->hw_info.personality) {
  177. case QED_PCI_ETH:
  178. flags |= PQ_FLAGS_MCOS;
  179. break;
  180. case QED_PCI_FCOE:
  181. flags |= PQ_FLAGS_OFLD;
  182. break;
  183. case QED_PCI_ISCSI:
  184. flags |= PQ_FLAGS_ACK | PQ_FLAGS_OOO | PQ_FLAGS_OFLD;
  185. break;
  186. case QED_PCI_ETH_ROCE:
  187. flags |= PQ_FLAGS_MCOS | PQ_FLAGS_OFLD | PQ_FLAGS_LLT;
  188. break;
  189. case QED_PCI_ETH_IWARP:
  190. flags |= PQ_FLAGS_MCOS | PQ_FLAGS_ACK | PQ_FLAGS_OOO |
  191. PQ_FLAGS_OFLD;
  192. break;
  193. default:
  194. DP_ERR(p_hwfn,
  195. "unknown personality %d\n", p_hwfn->hw_info.personality);
  196. return 0;
  197. }
  198. return flags;
  199. }
  200. /* Getters for resource amounts necessary for qm initialization */
  201. u8 qed_init_qm_get_num_tcs(struct qed_hwfn *p_hwfn)
  202. {
  203. return p_hwfn->hw_info.num_hw_tc;
  204. }
  205. u16 qed_init_qm_get_num_vfs(struct qed_hwfn *p_hwfn)
  206. {
  207. return IS_QED_SRIOV(p_hwfn->cdev) ?
  208. p_hwfn->cdev->p_iov_info->total_vfs : 0;
  209. }
  210. #define NUM_DEFAULT_RLS 1
  211. u16 qed_init_qm_get_num_pf_rls(struct qed_hwfn *p_hwfn)
  212. {
  213. u16 num_pf_rls, num_vfs = qed_init_qm_get_num_vfs(p_hwfn);
  214. /* num RLs can't exceed resource amount of rls or vports */
  215. num_pf_rls = (u16) min_t(u32, RESC_NUM(p_hwfn, QED_RL),
  216. RESC_NUM(p_hwfn, QED_VPORT));
  217. /* Make sure after we reserve there's something left */
  218. if (num_pf_rls < num_vfs + NUM_DEFAULT_RLS)
  219. return 0;
  220. /* subtract rls necessary for VFs and one default one for the PF */
  221. num_pf_rls -= num_vfs + NUM_DEFAULT_RLS;
  222. return num_pf_rls;
  223. }
  224. u16 qed_init_qm_get_num_vports(struct qed_hwfn *p_hwfn)
  225. {
  226. u32 pq_flags = qed_get_pq_flags(p_hwfn);
  227. /* all pqs share the same vport, except for vfs and pf_rl pqs */
  228. return (!!(PQ_FLAGS_RLS & pq_flags)) *
  229. qed_init_qm_get_num_pf_rls(p_hwfn) +
  230. (!!(PQ_FLAGS_VFS & pq_flags)) *
  231. qed_init_qm_get_num_vfs(p_hwfn) + 1;
  232. }
  233. /* calc amount of PQs according to the requested flags */
  234. u16 qed_init_qm_get_num_pqs(struct qed_hwfn *p_hwfn)
  235. {
  236. u32 pq_flags = qed_get_pq_flags(p_hwfn);
  237. return (!!(PQ_FLAGS_RLS & pq_flags)) *
  238. qed_init_qm_get_num_pf_rls(p_hwfn) +
  239. (!!(PQ_FLAGS_MCOS & pq_flags)) *
  240. qed_init_qm_get_num_tcs(p_hwfn) +
  241. (!!(PQ_FLAGS_LB & pq_flags)) + (!!(PQ_FLAGS_OOO & pq_flags)) +
  242. (!!(PQ_FLAGS_ACK & pq_flags)) + (!!(PQ_FLAGS_OFLD & pq_flags)) +
  243. (!!(PQ_FLAGS_LLT & pq_flags)) +
  244. (!!(PQ_FLAGS_VFS & pq_flags)) * qed_init_qm_get_num_vfs(p_hwfn);
  245. }
  246. /* initialize the top level QM params */
  247. static void qed_init_qm_params(struct qed_hwfn *p_hwfn)
  248. {
  249. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  250. bool four_port;
  251. /* pq and vport bases for this PF */
  252. qm_info->start_pq = (u16) RESC_START(p_hwfn, QED_PQ);
  253. qm_info->start_vport = (u8) RESC_START(p_hwfn, QED_VPORT);
  254. /* rate limiting and weighted fair queueing are always enabled */
  255. qm_info->vport_rl_en = true;
  256. qm_info->vport_wfq_en = true;
  257. /* TC config is different for AH 4 port */
  258. four_port = p_hwfn->cdev->num_ports_in_engine == MAX_NUM_PORTS_K2;
  259. /* in AH 4 port we have fewer TCs per port */
  260. qm_info->max_phys_tcs_per_port = four_port ? NUM_PHYS_TCS_4PORT_K2 :
  261. NUM_OF_PHYS_TCS;
  262. /* unless MFW indicated otherwise, ooo_tc == 3 for
  263. * AH 4-port and 4 otherwise.
  264. */
  265. if (!qm_info->ooo_tc)
  266. qm_info->ooo_tc = four_port ? DCBX_TCP_OOO_K2_4PORT_TC :
  267. DCBX_TCP_OOO_TC;
  268. }
  269. /* initialize qm vport params */
  270. static void qed_init_qm_vport_params(struct qed_hwfn *p_hwfn)
  271. {
  272. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  273. u8 i;
  274. /* all vports participate in weighted fair queueing */
  275. for (i = 0; i < qed_init_qm_get_num_vports(p_hwfn); i++)
  276. qm_info->qm_vport_params[i].vport_wfq = 1;
  277. }
  278. /* initialize qm port params */
  279. static void qed_init_qm_port_params(struct qed_hwfn *p_hwfn)
  280. {
  281. /* Initialize qm port parameters */
  282. u8 i, active_phys_tcs, num_ports = p_hwfn->cdev->num_ports_in_engine;
  283. /* indicate how ooo and high pri traffic is dealt with */
  284. active_phys_tcs = num_ports == MAX_NUM_PORTS_K2 ?
  285. ACTIVE_TCS_BMAP_4PORT_K2 :
  286. ACTIVE_TCS_BMAP;
  287. for (i = 0; i < num_ports; i++) {
  288. struct init_qm_port_params *p_qm_port =
  289. &p_hwfn->qm_info.qm_port_params[i];
  290. p_qm_port->active = 1;
  291. p_qm_port->active_phys_tcs = active_phys_tcs;
  292. p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports;
  293. p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
  294. }
  295. }
  296. /* Reset the params which must be reset for qm init. QM init may be called as
  297. * a result of flows other than driver load (e.g. dcbx renegotiation). Other
  298. * params may be affected by the init but would simply recalculate to the same
  299. * values. The allocations made for QM init, ports, vports, pqs and vfqs are not
  300. * affected as these amounts stay the same.
  301. */
  302. static void qed_init_qm_reset_params(struct qed_hwfn *p_hwfn)
  303. {
  304. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  305. qm_info->num_pqs = 0;
  306. qm_info->num_vports = 0;
  307. qm_info->num_pf_rls = 0;
  308. qm_info->num_vf_pqs = 0;
  309. qm_info->first_vf_pq = 0;
  310. qm_info->first_mcos_pq = 0;
  311. qm_info->first_rl_pq = 0;
  312. }
  313. static void qed_init_qm_advance_vport(struct qed_hwfn *p_hwfn)
  314. {
  315. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  316. qm_info->num_vports++;
  317. if (qm_info->num_vports > qed_init_qm_get_num_vports(p_hwfn))
  318. DP_ERR(p_hwfn,
  319. "vport overflow! qm_info->num_vports %d, qm_init_get_num_vports() %d\n",
  320. qm_info->num_vports, qed_init_qm_get_num_vports(p_hwfn));
  321. }
  322. /* initialize a single pq and manage qm_info resources accounting.
  323. * The pq_init_flags param determines whether the PQ is rate limited
  324. * (for VF or PF) and whether a new vport is allocated to the pq or not
  325. * (i.e. vport will be shared).
  326. */
  327. /* flags for pq init */
  328. #define PQ_INIT_SHARE_VPORT (1 << 0)
  329. #define PQ_INIT_PF_RL (1 << 1)
  330. #define PQ_INIT_VF_RL (1 << 2)
  331. /* defines for pq init */
  332. #define PQ_INIT_DEFAULT_WRR_GROUP 1
  333. #define PQ_INIT_DEFAULT_TC 0
  334. #define PQ_INIT_OFLD_TC (p_hwfn->hw_info.offload_tc)
  335. static void qed_init_qm_pq(struct qed_hwfn *p_hwfn,
  336. struct qed_qm_info *qm_info,
  337. u8 tc, u32 pq_init_flags)
  338. {
  339. u16 pq_idx = qm_info->num_pqs, max_pq = qed_init_qm_get_num_pqs(p_hwfn);
  340. if (pq_idx > max_pq)
  341. DP_ERR(p_hwfn,
  342. "pq overflow! pq %d, max pq %d\n", pq_idx, max_pq);
  343. /* init pq params */
  344. qm_info->qm_pq_params[pq_idx].port_id = p_hwfn->port_id;
  345. qm_info->qm_pq_params[pq_idx].vport_id = qm_info->start_vport +
  346. qm_info->num_vports;
  347. qm_info->qm_pq_params[pq_idx].tc_id = tc;
  348. qm_info->qm_pq_params[pq_idx].wrr_group = PQ_INIT_DEFAULT_WRR_GROUP;
  349. qm_info->qm_pq_params[pq_idx].rl_valid =
  350. (pq_init_flags & PQ_INIT_PF_RL || pq_init_flags & PQ_INIT_VF_RL);
  351. /* qm params accounting */
  352. qm_info->num_pqs++;
  353. if (!(pq_init_flags & PQ_INIT_SHARE_VPORT))
  354. qm_info->num_vports++;
  355. if (pq_init_flags & PQ_INIT_PF_RL)
  356. qm_info->num_pf_rls++;
  357. if (qm_info->num_vports > qed_init_qm_get_num_vports(p_hwfn))
  358. DP_ERR(p_hwfn,
  359. "vport overflow! qm_info->num_vports %d, qm_init_get_num_vports() %d\n",
  360. qm_info->num_vports, qed_init_qm_get_num_vports(p_hwfn));
  361. if (qm_info->num_pf_rls > qed_init_qm_get_num_pf_rls(p_hwfn))
  362. DP_ERR(p_hwfn,
  363. "rl overflow! qm_info->num_pf_rls %d, qm_init_get_num_pf_rls() %d\n",
  364. qm_info->num_pf_rls, qed_init_qm_get_num_pf_rls(p_hwfn));
  365. }
  366. /* get pq index according to PQ_FLAGS */
  367. static u16 *qed_init_qm_get_idx_from_flags(struct qed_hwfn *p_hwfn,
  368. u32 pq_flags)
  369. {
  370. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  371. /* Can't have multiple flags set here */
  372. if (bitmap_weight((unsigned long *)&pq_flags, sizeof(pq_flags)) > 1)
  373. goto err;
  374. switch (pq_flags) {
  375. case PQ_FLAGS_RLS:
  376. return &qm_info->first_rl_pq;
  377. case PQ_FLAGS_MCOS:
  378. return &qm_info->first_mcos_pq;
  379. case PQ_FLAGS_LB:
  380. return &qm_info->pure_lb_pq;
  381. case PQ_FLAGS_OOO:
  382. return &qm_info->ooo_pq;
  383. case PQ_FLAGS_ACK:
  384. return &qm_info->pure_ack_pq;
  385. case PQ_FLAGS_OFLD:
  386. return &qm_info->offload_pq;
  387. case PQ_FLAGS_LLT:
  388. return &qm_info->low_latency_pq;
  389. case PQ_FLAGS_VFS:
  390. return &qm_info->first_vf_pq;
  391. default:
  392. goto err;
  393. }
  394. err:
  395. DP_ERR(p_hwfn, "BAD pq flags %d\n", pq_flags);
  396. return NULL;
  397. }
  398. /* save pq index in qm info */
  399. static void qed_init_qm_set_idx(struct qed_hwfn *p_hwfn,
  400. u32 pq_flags, u16 pq_val)
  401. {
  402. u16 *base_pq_idx = qed_init_qm_get_idx_from_flags(p_hwfn, pq_flags);
  403. *base_pq_idx = p_hwfn->qm_info.start_pq + pq_val;
  404. }
  405. /* get tx pq index, with the PQ TX base already set (ready for context init) */
  406. u16 qed_get_cm_pq_idx(struct qed_hwfn *p_hwfn, u32 pq_flags)
  407. {
  408. u16 *base_pq_idx = qed_init_qm_get_idx_from_flags(p_hwfn, pq_flags);
  409. return *base_pq_idx + CM_TX_PQ_BASE;
  410. }
  411. u16 qed_get_cm_pq_idx_mcos(struct qed_hwfn *p_hwfn, u8 tc)
  412. {
  413. u8 max_tc = qed_init_qm_get_num_tcs(p_hwfn);
  414. if (tc > max_tc)
  415. DP_ERR(p_hwfn, "tc %d must be smaller than %d\n", tc, max_tc);
  416. return qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_MCOS) + tc;
  417. }
  418. u16 qed_get_cm_pq_idx_vf(struct qed_hwfn *p_hwfn, u16 vf)
  419. {
  420. u16 max_vf = qed_init_qm_get_num_vfs(p_hwfn);
  421. if (vf > max_vf)
  422. DP_ERR(p_hwfn, "vf %d must be smaller than %d\n", vf, max_vf);
  423. return qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_VFS) + vf;
  424. }
  425. u16 qed_get_cm_pq_idx_rl(struct qed_hwfn *p_hwfn, u8 rl)
  426. {
  427. u16 max_rl = qed_init_qm_get_num_pf_rls(p_hwfn);
  428. if (rl > max_rl)
  429. DP_ERR(p_hwfn, "rl %d must be smaller than %d\n", rl, max_rl);
  430. return qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_RLS) + rl;
  431. }
  432. /* Functions for creating specific types of pqs */
  433. static void qed_init_qm_lb_pq(struct qed_hwfn *p_hwfn)
  434. {
  435. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  436. if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_LB))
  437. return;
  438. qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_LB, qm_info->num_pqs);
  439. qed_init_qm_pq(p_hwfn, qm_info, PURE_LB_TC, PQ_INIT_SHARE_VPORT);
  440. }
  441. static void qed_init_qm_ooo_pq(struct qed_hwfn *p_hwfn)
  442. {
  443. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  444. if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_OOO))
  445. return;
  446. qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_OOO, qm_info->num_pqs);
  447. qed_init_qm_pq(p_hwfn, qm_info, qm_info->ooo_tc, PQ_INIT_SHARE_VPORT);
  448. }
  449. static void qed_init_qm_pure_ack_pq(struct qed_hwfn *p_hwfn)
  450. {
  451. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  452. if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_ACK))
  453. return;
  454. qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_ACK, qm_info->num_pqs);
  455. qed_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
  456. }
  457. static void qed_init_qm_offload_pq(struct qed_hwfn *p_hwfn)
  458. {
  459. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  460. if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_OFLD))
  461. return;
  462. qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_OFLD, qm_info->num_pqs);
  463. qed_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
  464. }
  465. static void qed_init_qm_low_latency_pq(struct qed_hwfn *p_hwfn)
  466. {
  467. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  468. if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_LLT))
  469. return;
  470. qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_LLT, qm_info->num_pqs);
  471. qed_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
  472. }
  473. static void qed_init_qm_mcos_pqs(struct qed_hwfn *p_hwfn)
  474. {
  475. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  476. u8 tc_idx;
  477. if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_MCOS))
  478. return;
  479. qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_MCOS, qm_info->num_pqs);
  480. for (tc_idx = 0; tc_idx < qed_init_qm_get_num_tcs(p_hwfn); tc_idx++)
  481. qed_init_qm_pq(p_hwfn, qm_info, tc_idx, PQ_INIT_SHARE_VPORT);
  482. }
  483. static void qed_init_qm_vf_pqs(struct qed_hwfn *p_hwfn)
  484. {
  485. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  486. u16 vf_idx, num_vfs = qed_init_qm_get_num_vfs(p_hwfn);
  487. if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_VFS))
  488. return;
  489. qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_VFS, qm_info->num_pqs);
  490. qm_info->num_vf_pqs = num_vfs;
  491. for (vf_idx = 0; vf_idx < num_vfs; vf_idx++)
  492. qed_init_qm_pq(p_hwfn,
  493. qm_info, PQ_INIT_DEFAULT_TC, PQ_INIT_VF_RL);
  494. }
  495. static void qed_init_qm_rl_pqs(struct qed_hwfn *p_hwfn)
  496. {
  497. u16 pf_rls_idx, num_pf_rls = qed_init_qm_get_num_pf_rls(p_hwfn);
  498. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  499. if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_RLS))
  500. return;
  501. qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_RLS, qm_info->num_pqs);
  502. for (pf_rls_idx = 0; pf_rls_idx < num_pf_rls; pf_rls_idx++)
  503. qed_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_PF_RL);
  504. }
  505. static void qed_init_qm_pq_params(struct qed_hwfn *p_hwfn)
  506. {
  507. /* rate limited pqs, must come first (FW assumption) */
  508. qed_init_qm_rl_pqs(p_hwfn);
  509. /* pqs for multi cos */
  510. qed_init_qm_mcos_pqs(p_hwfn);
  511. /* pure loopback pq */
  512. qed_init_qm_lb_pq(p_hwfn);
  513. /* out of order pq */
  514. qed_init_qm_ooo_pq(p_hwfn);
  515. /* pure ack pq */
  516. qed_init_qm_pure_ack_pq(p_hwfn);
  517. /* pq for offloaded protocol */
  518. qed_init_qm_offload_pq(p_hwfn);
  519. /* low latency pq */
  520. qed_init_qm_low_latency_pq(p_hwfn);
  521. /* done sharing vports */
  522. qed_init_qm_advance_vport(p_hwfn);
  523. /* pqs for vfs */
  524. qed_init_qm_vf_pqs(p_hwfn);
  525. }
  526. /* compare values of getters against resources amounts */
  527. static int qed_init_qm_sanity(struct qed_hwfn *p_hwfn)
  528. {
  529. if (qed_init_qm_get_num_vports(p_hwfn) > RESC_NUM(p_hwfn, QED_VPORT)) {
  530. DP_ERR(p_hwfn, "requested amount of vports exceeds resource\n");
  531. return -EINVAL;
  532. }
  533. if (qed_init_qm_get_num_pqs(p_hwfn) > RESC_NUM(p_hwfn, QED_PQ)) {
  534. DP_ERR(p_hwfn, "requested amount of pqs exceeds resource\n");
  535. return -EINVAL;
  536. }
  537. return 0;
  538. }
  539. static void qed_dp_init_qm_params(struct qed_hwfn *p_hwfn)
  540. {
  541. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  542. struct init_qm_vport_params *vport;
  543. struct init_qm_port_params *port;
  544. struct init_qm_pq_params *pq;
  545. int i, tc;
  546. /* top level params */
  547. DP_VERBOSE(p_hwfn,
  548. NETIF_MSG_HW,
  549. "qm init top level params: start_pq %d, start_vport %d, pure_lb_pq %d, offload_pq %d, pure_ack_pq %d\n",
  550. qm_info->start_pq,
  551. qm_info->start_vport,
  552. qm_info->pure_lb_pq,
  553. qm_info->offload_pq, qm_info->pure_ack_pq);
  554. DP_VERBOSE(p_hwfn,
  555. NETIF_MSG_HW,
  556. "ooo_pq %d, first_vf_pq %d, num_pqs %d, num_vf_pqs %d, num_vports %d, max_phys_tcs_per_port %d\n",
  557. qm_info->ooo_pq,
  558. qm_info->first_vf_pq,
  559. qm_info->num_pqs,
  560. qm_info->num_vf_pqs,
  561. qm_info->num_vports, qm_info->max_phys_tcs_per_port);
  562. DP_VERBOSE(p_hwfn,
  563. NETIF_MSG_HW,
  564. "pf_rl_en %d, pf_wfq_en %d, vport_rl_en %d, vport_wfq_en %d, pf_wfq %d, pf_rl %d, num_pf_rls %d, pq_flags %x\n",
  565. qm_info->pf_rl_en,
  566. qm_info->pf_wfq_en,
  567. qm_info->vport_rl_en,
  568. qm_info->vport_wfq_en,
  569. qm_info->pf_wfq,
  570. qm_info->pf_rl,
  571. qm_info->num_pf_rls, qed_get_pq_flags(p_hwfn));
  572. /* port table */
  573. for (i = 0; i < p_hwfn->cdev->num_ports_in_engine; i++) {
  574. port = &(qm_info->qm_port_params[i]);
  575. DP_VERBOSE(p_hwfn,
  576. NETIF_MSG_HW,
  577. "port idx %d, active %d, active_phys_tcs %d, num_pbf_cmd_lines %d, num_btb_blocks %d, reserved %d\n",
  578. i,
  579. port->active,
  580. port->active_phys_tcs,
  581. port->num_pbf_cmd_lines,
  582. port->num_btb_blocks, port->reserved);
  583. }
  584. /* vport table */
  585. for (i = 0; i < qm_info->num_vports; i++) {
  586. vport = &(qm_info->qm_vport_params[i]);
  587. DP_VERBOSE(p_hwfn,
  588. NETIF_MSG_HW,
  589. "vport idx %d, vport_rl %d, wfq %d, first_tx_pq_id [ ",
  590. qm_info->start_vport + i,
  591. vport->vport_rl, vport->vport_wfq);
  592. for (tc = 0; tc < NUM_OF_TCS; tc++)
  593. DP_VERBOSE(p_hwfn,
  594. NETIF_MSG_HW,
  595. "%d ", vport->first_tx_pq_id[tc]);
  596. DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "]\n");
  597. }
  598. /* pq table */
  599. for (i = 0; i < qm_info->num_pqs; i++) {
  600. pq = &(qm_info->qm_pq_params[i]);
  601. DP_VERBOSE(p_hwfn,
  602. NETIF_MSG_HW,
  603. "pq idx %d, port %d, vport_id %d, tc %d, wrr_grp %d, rl_valid %d\n",
  604. qm_info->start_pq + i,
  605. pq->port_id,
  606. pq->vport_id,
  607. pq->tc_id, pq->wrr_group, pq->rl_valid);
  608. }
  609. }
  610. static void qed_init_qm_info(struct qed_hwfn *p_hwfn)
  611. {
  612. /* reset params required for init run */
  613. qed_init_qm_reset_params(p_hwfn);
  614. /* init QM top level params */
  615. qed_init_qm_params(p_hwfn);
  616. /* init QM port params */
  617. qed_init_qm_port_params(p_hwfn);
  618. /* init QM vport params */
  619. qed_init_qm_vport_params(p_hwfn);
  620. /* init QM physical queue params */
  621. qed_init_qm_pq_params(p_hwfn);
  622. /* display all that init */
  623. qed_dp_init_qm_params(p_hwfn);
  624. }
  625. /* This function reconfigures the QM pf on the fly.
  626. * For this purpose we:
  627. * 1. reconfigure the QM database
  628. * 2. set new values to runtime array
  629. * 3. send an sdm_qm_cmd through the rbc interface to stop the QM
  630. * 4. activate init tool in QM_PF stage
  631. * 5. send an sdm_qm_cmd through rbc interface to release the QM
  632. */
  633. int qed_qm_reconf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  634. {
  635. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  636. bool b_rc;
  637. int rc;
  638. /* initialize qed's qm data structure */
  639. qed_init_qm_info(p_hwfn);
  640. /* stop PF's qm queues */
  641. spin_lock_bh(&qm_lock);
  642. b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, false, true,
  643. qm_info->start_pq, qm_info->num_pqs);
  644. spin_unlock_bh(&qm_lock);
  645. if (!b_rc)
  646. return -EINVAL;
  647. /* clear the QM_PF runtime phase leftovers from previous init */
  648. qed_init_clear_rt_data(p_hwfn);
  649. /* prepare QM portion of runtime array */
  650. qed_qm_init_pf(p_hwfn, p_ptt, false);
  651. /* activate init tool on runtime array */
  652. rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, p_hwfn->rel_pf_id,
  653. p_hwfn->hw_info.hw_mode);
  654. if (rc)
  655. return rc;
  656. /* start PF's qm queues */
  657. spin_lock_bh(&qm_lock);
  658. b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, true, true,
  659. qm_info->start_pq, qm_info->num_pqs);
  660. spin_unlock_bh(&qm_lock);
  661. if (!b_rc)
  662. return -EINVAL;
  663. return 0;
  664. }
  665. static int qed_alloc_qm_data(struct qed_hwfn *p_hwfn)
  666. {
  667. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  668. int rc;
  669. rc = qed_init_qm_sanity(p_hwfn);
  670. if (rc)
  671. goto alloc_err;
  672. qm_info->qm_pq_params = kcalloc(qed_init_qm_get_num_pqs(p_hwfn),
  673. sizeof(*qm_info->qm_pq_params),
  674. GFP_KERNEL);
  675. if (!qm_info->qm_pq_params)
  676. goto alloc_err;
  677. qm_info->qm_vport_params = kcalloc(qed_init_qm_get_num_vports(p_hwfn),
  678. sizeof(*qm_info->qm_vport_params),
  679. GFP_KERNEL);
  680. if (!qm_info->qm_vport_params)
  681. goto alloc_err;
  682. qm_info->qm_port_params = kcalloc(p_hwfn->cdev->num_ports_in_engine,
  683. sizeof(*qm_info->qm_port_params),
  684. GFP_KERNEL);
  685. if (!qm_info->qm_port_params)
  686. goto alloc_err;
  687. qm_info->wfq_data = kcalloc(qed_init_qm_get_num_vports(p_hwfn),
  688. sizeof(*qm_info->wfq_data),
  689. GFP_KERNEL);
  690. if (!qm_info->wfq_data)
  691. goto alloc_err;
  692. return 0;
  693. alloc_err:
  694. DP_NOTICE(p_hwfn, "Failed to allocate memory for QM params\n");
  695. qed_qm_info_free(p_hwfn);
  696. return -ENOMEM;
  697. }
  698. int qed_resc_alloc(struct qed_dev *cdev)
  699. {
  700. u32 rdma_tasks, excess_tasks;
  701. u32 line_count;
  702. int i, rc = 0;
  703. if (IS_VF(cdev)) {
  704. for_each_hwfn(cdev, i) {
  705. rc = qed_l2_alloc(&cdev->hwfns[i]);
  706. if (rc)
  707. return rc;
  708. }
  709. return rc;
  710. }
  711. cdev->fw_data = kzalloc(sizeof(*cdev->fw_data), GFP_KERNEL);
  712. if (!cdev->fw_data)
  713. return -ENOMEM;
  714. for_each_hwfn(cdev, i) {
  715. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  716. u32 n_eqes, num_cons;
  717. /* First allocate the context manager structure */
  718. rc = qed_cxt_mngr_alloc(p_hwfn);
  719. if (rc)
  720. goto alloc_err;
  721. /* Set the HW cid/tid numbers (in the contest manager)
  722. * Must be done prior to any further computations.
  723. */
  724. rc = qed_cxt_set_pf_params(p_hwfn, RDMA_MAX_TIDS);
  725. if (rc)
  726. goto alloc_err;
  727. rc = qed_alloc_qm_data(p_hwfn);
  728. if (rc)
  729. goto alloc_err;
  730. /* init qm info */
  731. qed_init_qm_info(p_hwfn);
  732. /* Compute the ILT client partition */
  733. rc = qed_cxt_cfg_ilt_compute(p_hwfn, &line_count);
  734. if (rc) {
  735. DP_NOTICE(p_hwfn,
  736. "too many ILT lines; re-computing with less lines\n");
  737. /* In case there are not enough ILT lines we reduce the
  738. * number of RDMA tasks and re-compute.
  739. */
  740. excess_tasks =
  741. qed_cxt_cfg_ilt_compute_excess(p_hwfn, line_count);
  742. if (!excess_tasks)
  743. goto alloc_err;
  744. rdma_tasks = RDMA_MAX_TIDS - excess_tasks;
  745. rc = qed_cxt_set_pf_params(p_hwfn, rdma_tasks);
  746. if (rc)
  747. goto alloc_err;
  748. rc = qed_cxt_cfg_ilt_compute(p_hwfn, &line_count);
  749. if (rc) {
  750. DP_ERR(p_hwfn,
  751. "failed ILT compute. Requested too many lines: %u\n",
  752. line_count);
  753. goto alloc_err;
  754. }
  755. }
  756. /* CID map / ILT shadow table / T2
  757. * The talbes sizes are determined by the computations above
  758. */
  759. rc = qed_cxt_tables_alloc(p_hwfn);
  760. if (rc)
  761. goto alloc_err;
  762. /* SPQ, must follow ILT because initializes SPQ context */
  763. rc = qed_spq_alloc(p_hwfn);
  764. if (rc)
  765. goto alloc_err;
  766. /* SP status block allocation */
  767. p_hwfn->p_dpc_ptt = qed_get_reserved_ptt(p_hwfn,
  768. RESERVED_PTT_DPC);
  769. rc = qed_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
  770. if (rc)
  771. goto alloc_err;
  772. rc = qed_iov_alloc(p_hwfn);
  773. if (rc)
  774. goto alloc_err;
  775. /* EQ */
  776. n_eqes = qed_chain_get_capacity(&p_hwfn->p_spq->chain);
  777. if (QED_IS_RDMA_PERSONALITY(p_hwfn)) {
  778. enum protocol_type rdma_proto;
  779. if (QED_IS_ROCE_PERSONALITY(p_hwfn))
  780. rdma_proto = PROTOCOLID_ROCE;
  781. else
  782. rdma_proto = PROTOCOLID_IWARP;
  783. num_cons = qed_cxt_get_proto_cid_count(p_hwfn,
  784. rdma_proto,
  785. NULL) * 2;
  786. n_eqes += num_cons + 2 * MAX_NUM_VFS_BB;
  787. } else if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
  788. num_cons =
  789. qed_cxt_get_proto_cid_count(p_hwfn,
  790. PROTOCOLID_ISCSI,
  791. NULL);
  792. n_eqes += 2 * num_cons;
  793. }
  794. if (n_eqes > 0xFFFF) {
  795. DP_ERR(p_hwfn,
  796. "Cannot allocate 0x%x EQ elements. The maximum of a u16 chain is 0x%x\n",
  797. n_eqes, 0xFFFF);
  798. goto alloc_no_mem;
  799. }
  800. rc = qed_eq_alloc(p_hwfn, (u16) n_eqes);
  801. if (rc)
  802. goto alloc_err;
  803. rc = qed_consq_alloc(p_hwfn);
  804. if (rc)
  805. goto alloc_err;
  806. rc = qed_l2_alloc(p_hwfn);
  807. if (rc)
  808. goto alloc_err;
  809. #ifdef CONFIG_QED_LL2
  810. if (p_hwfn->using_ll2) {
  811. rc = qed_ll2_alloc(p_hwfn);
  812. if (rc)
  813. goto alloc_err;
  814. }
  815. #endif
  816. if (p_hwfn->hw_info.personality == QED_PCI_FCOE) {
  817. rc = qed_fcoe_alloc(p_hwfn);
  818. if (rc)
  819. goto alloc_err;
  820. }
  821. if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
  822. rc = qed_iscsi_alloc(p_hwfn);
  823. if (rc)
  824. goto alloc_err;
  825. rc = qed_ooo_alloc(p_hwfn);
  826. if (rc)
  827. goto alloc_err;
  828. }
  829. /* DMA info initialization */
  830. rc = qed_dmae_info_alloc(p_hwfn);
  831. if (rc)
  832. goto alloc_err;
  833. /* DCBX initialization */
  834. rc = qed_dcbx_info_alloc(p_hwfn);
  835. if (rc)
  836. goto alloc_err;
  837. }
  838. cdev->reset_stats = kzalloc(sizeof(*cdev->reset_stats), GFP_KERNEL);
  839. if (!cdev->reset_stats)
  840. goto alloc_no_mem;
  841. return 0;
  842. alloc_no_mem:
  843. rc = -ENOMEM;
  844. alloc_err:
  845. qed_resc_free(cdev);
  846. return rc;
  847. }
  848. void qed_resc_setup(struct qed_dev *cdev)
  849. {
  850. int i;
  851. if (IS_VF(cdev)) {
  852. for_each_hwfn(cdev, i)
  853. qed_l2_setup(&cdev->hwfns[i]);
  854. return;
  855. }
  856. for_each_hwfn(cdev, i) {
  857. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  858. qed_cxt_mngr_setup(p_hwfn);
  859. qed_spq_setup(p_hwfn);
  860. qed_eq_setup(p_hwfn);
  861. qed_consq_setup(p_hwfn);
  862. /* Read shadow of current MFW mailbox */
  863. qed_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
  864. memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
  865. p_hwfn->mcp_info->mfw_mb_cur,
  866. p_hwfn->mcp_info->mfw_mb_length);
  867. qed_int_setup(p_hwfn, p_hwfn->p_main_ptt);
  868. qed_l2_setup(p_hwfn);
  869. qed_iov_setup(p_hwfn);
  870. #ifdef CONFIG_QED_LL2
  871. if (p_hwfn->using_ll2)
  872. qed_ll2_setup(p_hwfn);
  873. #endif
  874. if (p_hwfn->hw_info.personality == QED_PCI_FCOE)
  875. qed_fcoe_setup(p_hwfn);
  876. if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
  877. qed_iscsi_setup(p_hwfn);
  878. qed_ooo_setup(p_hwfn);
  879. }
  880. }
  881. }
  882. #define FINAL_CLEANUP_POLL_CNT (100)
  883. #define FINAL_CLEANUP_POLL_TIME (10)
  884. int qed_final_cleanup(struct qed_hwfn *p_hwfn,
  885. struct qed_ptt *p_ptt, u16 id, bool is_vf)
  886. {
  887. u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
  888. int rc = -EBUSY;
  889. addr = GTT_BAR0_MAP_REG_USDM_RAM +
  890. USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn->rel_pf_id);
  891. if (is_vf)
  892. id += 0x10;
  893. command |= X_FINAL_CLEANUP_AGG_INT <<
  894. SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT;
  895. command |= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT;
  896. command |= id << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT;
  897. command |= SDM_COMP_TYPE_AGG_INT << SDM_OP_GEN_COMP_TYPE_SHIFT;
  898. /* Make sure notification is not set before initiating final cleanup */
  899. if (REG_RD(p_hwfn, addr)) {
  900. DP_NOTICE(p_hwfn,
  901. "Unexpected; Found final cleanup notification before initiating final cleanup\n");
  902. REG_WR(p_hwfn, addr, 0);
  903. }
  904. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  905. "Sending final cleanup for PFVF[%d] [Command %08x]\n",
  906. id, command);
  907. qed_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command);
  908. /* Poll until completion */
  909. while (!REG_RD(p_hwfn, addr) && count--)
  910. msleep(FINAL_CLEANUP_POLL_TIME);
  911. if (REG_RD(p_hwfn, addr))
  912. rc = 0;
  913. else
  914. DP_NOTICE(p_hwfn,
  915. "Failed to receive FW final cleanup notification\n");
  916. /* Cleanup afterwards */
  917. REG_WR(p_hwfn, addr, 0);
  918. return rc;
  919. }
  920. static int qed_calc_hw_mode(struct qed_hwfn *p_hwfn)
  921. {
  922. int hw_mode = 0;
  923. if (QED_IS_BB_B0(p_hwfn->cdev)) {
  924. hw_mode |= 1 << MODE_BB;
  925. } else if (QED_IS_AH(p_hwfn->cdev)) {
  926. hw_mode |= 1 << MODE_K2;
  927. } else {
  928. DP_NOTICE(p_hwfn, "Unknown chip type %#x\n",
  929. p_hwfn->cdev->type);
  930. return -EINVAL;
  931. }
  932. switch (p_hwfn->cdev->num_ports_in_engine) {
  933. case 1:
  934. hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
  935. break;
  936. case 2:
  937. hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
  938. break;
  939. case 4:
  940. hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
  941. break;
  942. default:
  943. DP_NOTICE(p_hwfn, "num_ports_in_engine = %d not supported\n",
  944. p_hwfn->cdev->num_ports_in_engine);
  945. return -EINVAL;
  946. }
  947. if (test_bit(QED_MF_OVLAN_CLSS, &p_hwfn->cdev->mf_bits))
  948. hw_mode |= 1 << MODE_MF_SD;
  949. else
  950. hw_mode |= 1 << MODE_MF_SI;
  951. hw_mode |= 1 << MODE_ASIC;
  952. if (p_hwfn->cdev->num_hwfns > 1)
  953. hw_mode |= 1 << MODE_100G;
  954. p_hwfn->hw_info.hw_mode = hw_mode;
  955. DP_VERBOSE(p_hwfn, (NETIF_MSG_PROBE | NETIF_MSG_IFUP),
  956. "Configuring function for hw_mode: 0x%08x\n",
  957. p_hwfn->hw_info.hw_mode);
  958. return 0;
  959. }
  960. /* Init run time data for all PFs on an engine. */
  961. static void qed_init_cau_rt_data(struct qed_dev *cdev)
  962. {
  963. u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
  964. int i, igu_sb_id;
  965. for_each_hwfn(cdev, i) {
  966. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  967. struct qed_igu_info *p_igu_info;
  968. struct qed_igu_block *p_block;
  969. struct cau_sb_entry sb_entry;
  970. p_igu_info = p_hwfn->hw_info.p_igu_info;
  971. for (igu_sb_id = 0;
  972. igu_sb_id < QED_MAPPING_MEMORY_SIZE(cdev); igu_sb_id++) {
  973. p_block = &p_igu_info->entry[igu_sb_id];
  974. if (!p_block->is_pf)
  975. continue;
  976. qed_init_cau_sb_entry(p_hwfn, &sb_entry,
  977. p_block->function_id, 0, 0);
  978. STORE_RT_REG_AGG(p_hwfn, offset + igu_sb_id * 2,
  979. sb_entry);
  980. }
  981. }
  982. }
  983. static void qed_init_cache_line_size(struct qed_hwfn *p_hwfn,
  984. struct qed_ptt *p_ptt)
  985. {
  986. u32 val, wr_mbs, cache_line_size;
  987. val = qed_rd(p_hwfn, p_ptt, PSWRQ2_REG_WR_MBS0);
  988. switch (val) {
  989. case 0:
  990. wr_mbs = 128;
  991. break;
  992. case 1:
  993. wr_mbs = 256;
  994. break;
  995. case 2:
  996. wr_mbs = 512;
  997. break;
  998. default:
  999. DP_INFO(p_hwfn,
  1000. "Unexpected value of PSWRQ2_REG_WR_MBS0 [0x%x]. Avoid configuring PGLUE_B_REG_CACHE_LINE_SIZE.\n",
  1001. val);
  1002. return;
  1003. }
  1004. cache_line_size = min_t(u32, L1_CACHE_BYTES, wr_mbs);
  1005. switch (cache_line_size) {
  1006. case 32:
  1007. val = 0;
  1008. break;
  1009. case 64:
  1010. val = 1;
  1011. break;
  1012. case 128:
  1013. val = 2;
  1014. break;
  1015. case 256:
  1016. val = 3;
  1017. break;
  1018. default:
  1019. DP_INFO(p_hwfn,
  1020. "Unexpected value of cache line size [0x%x]. Avoid configuring PGLUE_B_REG_CACHE_LINE_SIZE.\n",
  1021. cache_line_size);
  1022. }
  1023. if (L1_CACHE_BYTES > wr_mbs)
  1024. DP_INFO(p_hwfn,
  1025. "The cache line size for padding is suboptimal for performance [OS cache line size 0x%x, wr mbs 0x%x]\n",
  1026. L1_CACHE_BYTES, wr_mbs);
  1027. STORE_RT_REG(p_hwfn, PGLUE_REG_B_CACHE_LINE_SIZE_RT_OFFSET, val);
  1028. if (val > 0) {
  1029. STORE_RT_REG(p_hwfn, PSWRQ2_REG_DRAM_ALIGN_WR_RT_OFFSET, val);
  1030. STORE_RT_REG(p_hwfn, PSWRQ2_REG_DRAM_ALIGN_RD_RT_OFFSET, val);
  1031. }
  1032. }
  1033. static int qed_hw_init_common(struct qed_hwfn *p_hwfn,
  1034. struct qed_ptt *p_ptt, int hw_mode)
  1035. {
  1036. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  1037. struct qed_qm_common_rt_init_params params;
  1038. struct qed_dev *cdev = p_hwfn->cdev;
  1039. u8 vf_id, max_num_vfs;
  1040. u16 num_pfs, pf_id;
  1041. u32 concrete_fid;
  1042. int rc = 0;
  1043. qed_init_cau_rt_data(cdev);
  1044. /* Program GTT windows */
  1045. qed_gtt_init(p_hwfn);
  1046. if (p_hwfn->mcp_info) {
  1047. if (p_hwfn->mcp_info->func_info.bandwidth_max)
  1048. qm_info->pf_rl_en = true;
  1049. if (p_hwfn->mcp_info->func_info.bandwidth_min)
  1050. qm_info->pf_wfq_en = true;
  1051. }
  1052. memset(&params, 0, sizeof(params));
  1053. params.max_ports_per_engine = p_hwfn->cdev->num_ports_in_engine;
  1054. params.max_phys_tcs_per_port = qm_info->max_phys_tcs_per_port;
  1055. params.pf_rl_en = qm_info->pf_rl_en;
  1056. params.pf_wfq_en = qm_info->pf_wfq_en;
  1057. params.vport_rl_en = qm_info->vport_rl_en;
  1058. params.vport_wfq_en = qm_info->vport_wfq_en;
  1059. params.port_params = qm_info->qm_port_params;
  1060. qed_qm_common_rt_init(p_hwfn, &params);
  1061. qed_cxt_hw_init_common(p_hwfn);
  1062. qed_init_cache_line_size(p_hwfn, p_ptt);
  1063. rc = qed_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode);
  1064. if (rc)
  1065. return rc;
  1066. qed_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
  1067. qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
  1068. if (QED_IS_BB(p_hwfn->cdev)) {
  1069. num_pfs = NUM_OF_ENG_PFS(p_hwfn->cdev);
  1070. for (pf_id = 0; pf_id < num_pfs; pf_id++) {
  1071. qed_fid_pretend(p_hwfn, p_ptt, pf_id);
  1072. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
  1073. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
  1074. }
  1075. /* pretend to original PF */
  1076. qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
  1077. }
  1078. max_num_vfs = QED_IS_AH(cdev) ? MAX_NUM_VFS_K2 : MAX_NUM_VFS_BB;
  1079. for (vf_id = 0; vf_id < max_num_vfs; vf_id++) {
  1080. concrete_fid = qed_vfid_to_concrete(p_hwfn, vf_id);
  1081. qed_fid_pretend(p_hwfn, p_ptt, (u16) concrete_fid);
  1082. qed_wr(p_hwfn, p_ptt, CCFC_REG_STRONG_ENABLE_VF, 0x1);
  1083. qed_wr(p_hwfn, p_ptt, CCFC_REG_WEAK_ENABLE_VF, 0x0);
  1084. qed_wr(p_hwfn, p_ptt, TCFC_REG_STRONG_ENABLE_VF, 0x1);
  1085. qed_wr(p_hwfn, p_ptt, TCFC_REG_WEAK_ENABLE_VF, 0x0);
  1086. }
  1087. /* pretend to original PF */
  1088. qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
  1089. return rc;
  1090. }
  1091. static int
  1092. qed_hw_init_dpi_size(struct qed_hwfn *p_hwfn,
  1093. struct qed_ptt *p_ptt, u32 pwm_region_size, u32 n_cpus)
  1094. {
  1095. u32 dpi_bit_shift, dpi_count, dpi_page_size;
  1096. u32 min_dpis;
  1097. u32 n_wids;
  1098. /* Calculate DPI size */
  1099. n_wids = max_t(u32, QED_MIN_WIDS, n_cpus);
  1100. dpi_page_size = QED_WID_SIZE * roundup_pow_of_two(n_wids);
  1101. dpi_page_size = (dpi_page_size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
  1102. dpi_bit_shift = ilog2(dpi_page_size / 4096);
  1103. dpi_count = pwm_region_size / dpi_page_size;
  1104. min_dpis = p_hwfn->pf_params.rdma_pf_params.min_dpis;
  1105. min_dpis = max_t(u32, QED_MIN_DPIS, min_dpis);
  1106. p_hwfn->dpi_size = dpi_page_size;
  1107. p_hwfn->dpi_count = dpi_count;
  1108. qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_DPI_BIT_SHIFT, dpi_bit_shift);
  1109. if (dpi_count < min_dpis)
  1110. return -EINVAL;
  1111. return 0;
  1112. }
  1113. enum QED_ROCE_EDPM_MODE {
  1114. QED_ROCE_EDPM_MODE_ENABLE = 0,
  1115. QED_ROCE_EDPM_MODE_FORCE_ON = 1,
  1116. QED_ROCE_EDPM_MODE_DISABLE = 2,
  1117. };
  1118. static int
  1119. qed_hw_init_pf_doorbell_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  1120. {
  1121. u32 pwm_regsize, norm_regsize;
  1122. u32 non_pwm_conn, min_addr_reg1;
  1123. u32 db_bar_size, n_cpus = 1;
  1124. u32 roce_edpm_mode;
  1125. u32 pf_dems_shift;
  1126. int rc = 0;
  1127. u8 cond;
  1128. db_bar_size = qed_hw_bar_size(p_hwfn, p_ptt, BAR_ID_1);
  1129. if (p_hwfn->cdev->num_hwfns > 1)
  1130. db_bar_size /= 2;
  1131. /* Calculate doorbell regions */
  1132. non_pwm_conn = qed_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_CORE) +
  1133. qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_CORE,
  1134. NULL) +
  1135. qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH,
  1136. NULL);
  1137. norm_regsize = roundup(QED_PF_DEMS_SIZE * non_pwm_conn, PAGE_SIZE);
  1138. min_addr_reg1 = norm_regsize / 4096;
  1139. pwm_regsize = db_bar_size - norm_regsize;
  1140. /* Check that the normal and PWM sizes are valid */
  1141. if (db_bar_size < norm_regsize) {
  1142. DP_ERR(p_hwfn->cdev,
  1143. "Doorbell BAR size 0x%x is too small (normal region is 0x%0x )\n",
  1144. db_bar_size, norm_regsize);
  1145. return -EINVAL;
  1146. }
  1147. if (pwm_regsize < QED_MIN_PWM_REGION) {
  1148. DP_ERR(p_hwfn->cdev,
  1149. "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",
  1150. pwm_regsize,
  1151. QED_MIN_PWM_REGION, db_bar_size, norm_regsize);
  1152. return -EINVAL;
  1153. }
  1154. /* Calculate number of DPIs */
  1155. roce_edpm_mode = p_hwfn->pf_params.rdma_pf_params.roce_edpm_mode;
  1156. if ((roce_edpm_mode == QED_ROCE_EDPM_MODE_ENABLE) ||
  1157. ((roce_edpm_mode == QED_ROCE_EDPM_MODE_FORCE_ON))) {
  1158. /* Either EDPM is mandatory, or we are attempting to allocate a
  1159. * WID per CPU.
  1160. */
  1161. n_cpus = num_present_cpus();
  1162. rc = qed_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
  1163. }
  1164. cond = (rc && (roce_edpm_mode == QED_ROCE_EDPM_MODE_ENABLE)) ||
  1165. (roce_edpm_mode == QED_ROCE_EDPM_MODE_DISABLE);
  1166. if (cond || p_hwfn->dcbx_no_edpm) {
  1167. /* Either EDPM is disabled from user configuration, or it is
  1168. * disabled via DCBx, or it is not mandatory and we failed to
  1169. * allocated a WID per CPU.
  1170. */
  1171. n_cpus = 1;
  1172. rc = qed_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
  1173. if (cond)
  1174. qed_rdma_dpm_bar(p_hwfn, p_ptt);
  1175. }
  1176. p_hwfn->wid_count = (u16) n_cpus;
  1177. DP_INFO(p_hwfn,
  1178. "doorbell bar: normal_region_size=%d, pwm_region_size=%d, dpi_size=%d, dpi_count=%d, roce_edpm=%s\n",
  1179. norm_regsize,
  1180. pwm_regsize,
  1181. p_hwfn->dpi_size,
  1182. p_hwfn->dpi_count,
  1183. ((p_hwfn->dcbx_no_edpm) || (p_hwfn->db_bar_no_edpm)) ?
  1184. "disabled" : "enabled");
  1185. if (rc) {
  1186. DP_ERR(p_hwfn,
  1187. "Failed to allocate enough DPIs. Allocated %d but the current minimum is %d.\n",
  1188. p_hwfn->dpi_count,
  1189. p_hwfn->pf_params.rdma_pf_params.min_dpis);
  1190. return -EINVAL;
  1191. }
  1192. p_hwfn->dpi_start_offset = norm_regsize;
  1193. /* DEMS size is configured log2 of DWORDs, hence the division by 4 */
  1194. pf_dems_shift = ilog2(QED_PF_DEMS_SIZE / 4);
  1195. qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_ICID_BIT_SHIFT_NORM, pf_dems_shift);
  1196. qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_MIN_ADDR_REG1, min_addr_reg1);
  1197. return 0;
  1198. }
  1199. static int qed_hw_init_port(struct qed_hwfn *p_hwfn,
  1200. struct qed_ptt *p_ptt, int hw_mode)
  1201. {
  1202. int rc = 0;
  1203. rc = qed_init_run(p_hwfn, p_ptt, PHASE_PORT, p_hwfn->port_id, hw_mode);
  1204. if (rc)
  1205. return rc;
  1206. qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_MASTER_WRITE_PAD_ENABLE, 0);
  1207. return 0;
  1208. }
  1209. static int qed_hw_init_pf(struct qed_hwfn *p_hwfn,
  1210. struct qed_ptt *p_ptt,
  1211. struct qed_tunnel_info *p_tunn,
  1212. int hw_mode,
  1213. bool b_hw_start,
  1214. enum qed_int_mode int_mode,
  1215. bool allow_npar_tx_switch)
  1216. {
  1217. u8 rel_pf_id = p_hwfn->rel_pf_id;
  1218. int rc = 0;
  1219. if (p_hwfn->mcp_info) {
  1220. struct qed_mcp_function_info *p_info;
  1221. p_info = &p_hwfn->mcp_info->func_info;
  1222. if (p_info->bandwidth_min)
  1223. p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
  1224. /* Update rate limit once we'll actually have a link */
  1225. p_hwfn->qm_info.pf_rl = 100000;
  1226. }
  1227. qed_cxt_hw_init_pf(p_hwfn, p_ptt);
  1228. qed_int_igu_init_rt(p_hwfn);
  1229. /* Set VLAN in NIG if needed */
  1230. if (hw_mode & BIT(MODE_MF_SD)) {
  1231. DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "Configuring LLH_FUNC_TAG\n");
  1232. STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
  1233. STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
  1234. p_hwfn->hw_info.ovlan);
  1235. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  1236. "Configuring LLH_FUNC_FILTER_HDR_SEL\n");
  1237. STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_FILTER_HDR_SEL_RT_OFFSET,
  1238. 1);
  1239. }
  1240. /* Enable classification by MAC if needed */
  1241. if (hw_mode & BIT(MODE_MF_SI)) {
  1242. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  1243. "Configuring TAGMAC_CLS_TYPE\n");
  1244. STORE_RT_REG(p_hwfn,
  1245. NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET, 1);
  1246. }
  1247. /* Protocol Configuration */
  1248. STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET,
  1249. (p_hwfn->hw_info.personality == QED_PCI_ISCSI) ? 1 : 0);
  1250. STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET,
  1251. (p_hwfn->hw_info.personality == QED_PCI_FCOE) ? 1 : 0);
  1252. STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0);
  1253. /* Cleanup chip from previous driver if such remains exist */
  1254. rc = qed_final_cleanup(p_hwfn, p_ptt, rel_pf_id, false);
  1255. if (rc)
  1256. return rc;
  1257. /* Sanity check before the PF init sequence that uses DMAE */
  1258. rc = qed_dmae_sanity(p_hwfn, p_ptt, "pf_phase");
  1259. if (rc)
  1260. return rc;
  1261. /* PF Init sequence */
  1262. rc = qed_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
  1263. if (rc)
  1264. return rc;
  1265. /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
  1266. rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
  1267. if (rc)
  1268. return rc;
  1269. /* Pure runtime initializations - directly to the HW */
  1270. qed_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
  1271. rc = qed_hw_init_pf_doorbell_bar(p_hwfn, p_ptt);
  1272. if (rc)
  1273. return rc;
  1274. if (b_hw_start) {
  1275. /* enable interrupts */
  1276. qed_int_igu_enable(p_hwfn, p_ptt, int_mode);
  1277. /* send function start command */
  1278. rc = qed_sp_pf_start(p_hwfn, p_ptt, p_tunn,
  1279. allow_npar_tx_switch);
  1280. if (rc) {
  1281. DP_NOTICE(p_hwfn, "Function start ramrod failed\n");
  1282. return rc;
  1283. }
  1284. if (p_hwfn->hw_info.personality == QED_PCI_FCOE) {
  1285. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1, BIT(2));
  1286. qed_wr(p_hwfn, p_ptt,
  1287. PRS_REG_PKT_LEN_STAT_TAGS_NOT_COUNTED_FIRST,
  1288. 0x100);
  1289. }
  1290. }
  1291. return rc;
  1292. }
  1293. static int qed_change_pci_hwfn(struct qed_hwfn *p_hwfn,
  1294. struct qed_ptt *p_ptt,
  1295. u8 enable)
  1296. {
  1297. u32 delay_idx = 0, val, set_val = enable ? 1 : 0;
  1298. /* Change PF in PXP */
  1299. qed_wr(p_hwfn, p_ptt,
  1300. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
  1301. /* wait until value is set - try for 1 second every 50us */
  1302. for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
  1303. val = qed_rd(p_hwfn, p_ptt,
  1304. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1305. if (val == set_val)
  1306. break;
  1307. usleep_range(50, 60);
  1308. }
  1309. if (val != set_val) {
  1310. DP_NOTICE(p_hwfn,
  1311. "PFID_ENABLE_MASTER wasn't changed after a second\n");
  1312. return -EAGAIN;
  1313. }
  1314. return 0;
  1315. }
  1316. static void qed_reset_mb_shadow(struct qed_hwfn *p_hwfn,
  1317. struct qed_ptt *p_main_ptt)
  1318. {
  1319. /* Read shadow of current MFW mailbox */
  1320. qed_mcp_read_mb(p_hwfn, p_main_ptt);
  1321. memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
  1322. p_hwfn->mcp_info->mfw_mb_cur, p_hwfn->mcp_info->mfw_mb_length);
  1323. }
  1324. static void
  1325. qed_fill_load_req_params(struct qed_load_req_params *p_load_req,
  1326. struct qed_drv_load_params *p_drv_load)
  1327. {
  1328. memset(p_load_req, 0, sizeof(*p_load_req));
  1329. p_load_req->drv_role = p_drv_load->is_crash_kernel ?
  1330. QED_DRV_ROLE_KDUMP : QED_DRV_ROLE_OS;
  1331. p_load_req->timeout_val = p_drv_load->mfw_timeout_val;
  1332. p_load_req->avoid_eng_reset = p_drv_load->avoid_eng_reset;
  1333. p_load_req->override_force_load = p_drv_load->override_force_load;
  1334. }
  1335. static int qed_vf_start(struct qed_hwfn *p_hwfn,
  1336. struct qed_hw_init_params *p_params)
  1337. {
  1338. if (p_params->p_tunn) {
  1339. qed_vf_set_vf_start_tunn_update_param(p_params->p_tunn);
  1340. qed_vf_pf_tunnel_param_update(p_hwfn, p_params->p_tunn);
  1341. }
  1342. p_hwfn->b_int_enabled = true;
  1343. return 0;
  1344. }
  1345. int qed_hw_init(struct qed_dev *cdev, struct qed_hw_init_params *p_params)
  1346. {
  1347. struct qed_load_req_params load_req_params;
  1348. u32 load_code, param, drv_mb_param;
  1349. bool b_default_mtu = true;
  1350. struct qed_hwfn *p_hwfn;
  1351. int rc = 0, mfw_rc, i;
  1352. u16 ether_type;
  1353. if ((p_params->int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) {
  1354. DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n");
  1355. return -EINVAL;
  1356. }
  1357. if (IS_PF(cdev)) {
  1358. rc = qed_init_fw_data(cdev, p_params->bin_fw_data);
  1359. if (rc)
  1360. return rc;
  1361. }
  1362. for_each_hwfn(cdev, i) {
  1363. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  1364. /* If management didn't provide a default, set one of our own */
  1365. if (!p_hwfn->hw_info.mtu) {
  1366. p_hwfn->hw_info.mtu = 1500;
  1367. b_default_mtu = false;
  1368. }
  1369. if (IS_VF(cdev)) {
  1370. qed_vf_start(p_hwfn, p_params);
  1371. continue;
  1372. }
  1373. /* Enable DMAE in PXP */
  1374. rc = qed_change_pci_hwfn(p_hwfn, p_hwfn->p_main_ptt, true);
  1375. rc = qed_calc_hw_mode(p_hwfn);
  1376. if (rc)
  1377. return rc;
  1378. if (IS_PF(cdev) && (test_bit(QED_MF_8021Q_TAGGING,
  1379. &cdev->mf_bits) ||
  1380. test_bit(QED_MF_8021AD_TAGGING,
  1381. &cdev->mf_bits))) {
  1382. if (test_bit(QED_MF_8021Q_TAGGING, &cdev->mf_bits))
  1383. ether_type = ETH_P_8021Q;
  1384. else
  1385. ether_type = ETH_P_8021AD;
  1386. STORE_RT_REG(p_hwfn, PRS_REG_TAG_ETHERTYPE_0_RT_OFFSET,
  1387. ether_type);
  1388. STORE_RT_REG(p_hwfn, NIG_REG_TAG_ETHERTYPE_0_RT_OFFSET,
  1389. ether_type);
  1390. STORE_RT_REG(p_hwfn, PBF_REG_TAG_ETHERTYPE_0_RT_OFFSET,
  1391. ether_type);
  1392. STORE_RT_REG(p_hwfn, DORQ_REG_TAG1_ETHERTYPE_RT_OFFSET,
  1393. ether_type);
  1394. }
  1395. qed_fill_load_req_params(&load_req_params,
  1396. p_params->p_drv_load_params);
  1397. rc = qed_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt,
  1398. &load_req_params);
  1399. if (rc) {
  1400. DP_NOTICE(p_hwfn, "Failed sending a LOAD_REQ command\n");
  1401. return rc;
  1402. }
  1403. load_code = load_req_params.load_code;
  1404. DP_VERBOSE(p_hwfn, QED_MSG_SP,
  1405. "Load request was sent. Load code: 0x%x\n",
  1406. load_code);
  1407. qed_mcp_set_capabilities(p_hwfn, p_hwfn->p_main_ptt);
  1408. qed_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
  1409. p_hwfn->first_on_engine = (load_code ==
  1410. FW_MSG_CODE_DRV_LOAD_ENGINE);
  1411. switch (load_code) {
  1412. case FW_MSG_CODE_DRV_LOAD_ENGINE:
  1413. rc = qed_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
  1414. p_hwfn->hw_info.hw_mode);
  1415. if (rc)
  1416. break;
  1417. /* Fall into */
  1418. case FW_MSG_CODE_DRV_LOAD_PORT:
  1419. rc = qed_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
  1420. p_hwfn->hw_info.hw_mode);
  1421. if (rc)
  1422. break;
  1423. /* Fall into */
  1424. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  1425. rc = qed_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
  1426. p_params->p_tunn,
  1427. p_hwfn->hw_info.hw_mode,
  1428. p_params->b_hw_start,
  1429. p_params->int_mode,
  1430. p_params->allow_npar_tx_switch);
  1431. break;
  1432. default:
  1433. DP_NOTICE(p_hwfn,
  1434. "Unexpected load code [0x%08x]", load_code);
  1435. rc = -EINVAL;
  1436. break;
  1437. }
  1438. if (rc)
  1439. DP_NOTICE(p_hwfn,
  1440. "init phase failed for loadcode 0x%x (rc %d)\n",
  1441. load_code, rc);
  1442. /* ACK mfw regardless of success or failure of initialization */
  1443. mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
  1444. DRV_MSG_CODE_LOAD_DONE,
  1445. 0, &load_code, &param);
  1446. if (rc)
  1447. return rc;
  1448. if (mfw_rc) {
  1449. DP_NOTICE(p_hwfn, "Failed sending LOAD_DONE command\n");
  1450. return mfw_rc;
  1451. }
  1452. /* Check if there is a DID mismatch between nvm-cfg/efuse */
  1453. if (param & FW_MB_PARAM_LOAD_DONE_DID_EFUSE_ERROR)
  1454. DP_NOTICE(p_hwfn,
  1455. "warning: device configuration is not supported on this board type. The device may not function as expected.\n");
  1456. /* send DCBX attention request command */
  1457. DP_VERBOSE(p_hwfn,
  1458. QED_MSG_DCB,
  1459. "sending phony dcbx set command to trigger DCBx attention handling\n");
  1460. mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
  1461. DRV_MSG_CODE_SET_DCBX,
  1462. 1 << DRV_MB_PARAM_DCBX_NOTIFY_SHIFT,
  1463. &load_code, &param);
  1464. if (mfw_rc) {
  1465. DP_NOTICE(p_hwfn,
  1466. "Failed to send DCBX attention request\n");
  1467. return mfw_rc;
  1468. }
  1469. p_hwfn->hw_init_done = true;
  1470. }
  1471. if (IS_PF(cdev)) {
  1472. p_hwfn = QED_LEADING_HWFN(cdev);
  1473. drv_mb_param = STORM_FW_VERSION;
  1474. rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
  1475. DRV_MSG_CODE_OV_UPDATE_STORM_FW_VER,
  1476. drv_mb_param, &load_code, &param);
  1477. if (rc)
  1478. DP_INFO(p_hwfn, "Failed to update firmware version\n");
  1479. if (!b_default_mtu) {
  1480. rc = qed_mcp_ov_update_mtu(p_hwfn, p_hwfn->p_main_ptt,
  1481. p_hwfn->hw_info.mtu);
  1482. if (rc)
  1483. DP_INFO(p_hwfn,
  1484. "Failed to update default mtu\n");
  1485. }
  1486. rc = qed_mcp_ov_update_driver_state(p_hwfn,
  1487. p_hwfn->p_main_ptt,
  1488. QED_OV_DRIVER_STATE_DISABLED);
  1489. if (rc)
  1490. DP_INFO(p_hwfn, "Failed to update driver state\n");
  1491. rc = qed_mcp_ov_update_eswitch(p_hwfn, p_hwfn->p_main_ptt,
  1492. QED_OV_ESWITCH_VEB);
  1493. if (rc)
  1494. DP_INFO(p_hwfn, "Failed to update eswitch mode\n");
  1495. }
  1496. return 0;
  1497. }
  1498. #define QED_HW_STOP_RETRY_LIMIT (10)
  1499. static void qed_hw_timers_stop(struct qed_dev *cdev,
  1500. struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  1501. {
  1502. int i;
  1503. /* close timers */
  1504. qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
  1505. qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
  1506. for (i = 0; i < QED_HW_STOP_RETRY_LIMIT; i++) {
  1507. if ((!qed_rd(p_hwfn, p_ptt,
  1508. TM_REG_PF_SCAN_ACTIVE_CONN)) &&
  1509. (!qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK)))
  1510. break;
  1511. /* Dependent on number of connection/tasks, possibly
  1512. * 1ms sleep is required between polls
  1513. */
  1514. usleep_range(1000, 2000);
  1515. }
  1516. if (i < QED_HW_STOP_RETRY_LIMIT)
  1517. return;
  1518. DP_NOTICE(p_hwfn,
  1519. "Timers linear scans are not over [Connection %02x Tasks %02x]\n",
  1520. (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_CONN),
  1521. (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK));
  1522. }
  1523. void qed_hw_timers_stop_all(struct qed_dev *cdev)
  1524. {
  1525. int j;
  1526. for_each_hwfn(cdev, j) {
  1527. struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
  1528. struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
  1529. qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
  1530. }
  1531. }
  1532. int qed_hw_stop(struct qed_dev *cdev)
  1533. {
  1534. struct qed_hwfn *p_hwfn;
  1535. struct qed_ptt *p_ptt;
  1536. int rc, rc2 = 0;
  1537. int j;
  1538. for_each_hwfn(cdev, j) {
  1539. p_hwfn = &cdev->hwfns[j];
  1540. p_ptt = p_hwfn->p_main_ptt;
  1541. DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Stopping hw/fw\n");
  1542. if (IS_VF(cdev)) {
  1543. qed_vf_pf_int_cleanup(p_hwfn);
  1544. rc = qed_vf_pf_reset(p_hwfn);
  1545. if (rc) {
  1546. DP_NOTICE(p_hwfn,
  1547. "qed_vf_pf_reset failed. rc = %d.\n",
  1548. rc);
  1549. rc2 = -EINVAL;
  1550. }
  1551. continue;
  1552. }
  1553. /* mark the hw as uninitialized... */
  1554. p_hwfn->hw_init_done = false;
  1555. /* Send unload command to MCP */
  1556. rc = qed_mcp_unload_req(p_hwfn, p_ptt);
  1557. if (rc) {
  1558. DP_NOTICE(p_hwfn,
  1559. "Failed sending a UNLOAD_REQ command. rc = %d.\n",
  1560. rc);
  1561. rc2 = -EINVAL;
  1562. }
  1563. qed_slowpath_irq_sync(p_hwfn);
  1564. /* After this point no MFW attentions are expected, e.g. prevent
  1565. * race between pf stop and dcbx pf update.
  1566. */
  1567. rc = qed_sp_pf_stop(p_hwfn);
  1568. if (rc) {
  1569. DP_NOTICE(p_hwfn,
  1570. "Failed to close PF against FW [rc = %d]. Continue to stop HW to prevent illegal host access by the device.\n",
  1571. rc);
  1572. rc2 = -EINVAL;
  1573. }
  1574. qed_wr(p_hwfn, p_ptt,
  1575. NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
  1576. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
  1577. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
  1578. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
  1579. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
  1580. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
  1581. qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
  1582. /* Disable Attention Generation */
  1583. qed_int_igu_disable_int(p_hwfn, p_ptt);
  1584. qed_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
  1585. qed_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
  1586. qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
  1587. /* Need to wait 1ms to guarantee SBs are cleared */
  1588. usleep_range(1000, 2000);
  1589. /* Disable PF in HW blocks */
  1590. qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_DB_ENABLE, 0);
  1591. qed_wr(p_hwfn, p_ptt, QM_REG_PF_EN, 0);
  1592. qed_mcp_unload_done(p_hwfn, p_ptt);
  1593. if (rc) {
  1594. DP_NOTICE(p_hwfn,
  1595. "Failed sending a UNLOAD_DONE command. rc = %d.\n",
  1596. rc);
  1597. rc2 = -EINVAL;
  1598. }
  1599. }
  1600. if (IS_PF(cdev)) {
  1601. p_hwfn = QED_LEADING_HWFN(cdev);
  1602. p_ptt = QED_LEADING_HWFN(cdev)->p_main_ptt;
  1603. /* Disable DMAE in PXP - in CMT, this should only be done for
  1604. * first hw-function, and only after all transactions have
  1605. * stopped for all active hw-functions.
  1606. */
  1607. rc = qed_change_pci_hwfn(p_hwfn, p_ptt, false);
  1608. if (rc) {
  1609. DP_NOTICE(p_hwfn,
  1610. "qed_change_pci_hwfn failed. rc = %d.\n", rc);
  1611. rc2 = -EINVAL;
  1612. }
  1613. }
  1614. return rc2;
  1615. }
  1616. int qed_hw_stop_fastpath(struct qed_dev *cdev)
  1617. {
  1618. int j;
  1619. for_each_hwfn(cdev, j) {
  1620. struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
  1621. struct qed_ptt *p_ptt;
  1622. if (IS_VF(cdev)) {
  1623. qed_vf_pf_int_cleanup(p_hwfn);
  1624. continue;
  1625. }
  1626. p_ptt = qed_ptt_acquire(p_hwfn);
  1627. if (!p_ptt)
  1628. return -EAGAIN;
  1629. DP_VERBOSE(p_hwfn,
  1630. NETIF_MSG_IFDOWN, "Shutting down the fastpath\n");
  1631. qed_wr(p_hwfn, p_ptt,
  1632. NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
  1633. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
  1634. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
  1635. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
  1636. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
  1637. qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
  1638. qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false);
  1639. /* Need to wait 1ms to guarantee SBs are cleared */
  1640. usleep_range(1000, 2000);
  1641. qed_ptt_release(p_hwfn, p_ptt);
  1642. }
  1643. return 0;
  1644. }
  1645. int qed_hw_start_fastpath(struct qed_hwfn *p_hwfn)
  1646. {
  1647. struct qed_ptt *p_ptt;
  1648. if (IS_VF(p_hwfn->cdev))
  1649. return 0;
  1650. p_ptt = qed_ptt_acquire(p_hwfn);
  1651. if (!p_ptt)
  1652. return -EAGAIN;
  1653. /* If roce info is allocated it means roce is initialized and should
  1654. * be enabled in searcher.
  1655. */
  1656. if (p_hwfn->p_rdma_info &&
  1657. p_hwfn->b_rdma_enabled_in_prs)
  1658. qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 0x1);
  1659. /* Re-open incoming traffic */
  1660. qed_wr(p_hwfn, p_ptt, NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0);
  1661. qed_ptt_release(p_hwfn, p_ptt);
  1662. return 0;
  1663. }
  1664. /* Free hwfn memory and resources acquired in hw_hwfn_prepare */
  1665. static void qed_hw_hwfn_free(struct qed_hwfn *p_hwfn)
  1666. {
  1667. qed_ptt_pool_free(p_hwfn);
  1668. kfree(p_hwfn->hw_info.p_igu_info);
  1669. p_hwfn->hw_info.p_igu_info = NULL;
  1670. }
  1671. /* Setup bar access */
  1672. static void qed_hw_hwfn_prepare(struct qed_hwfn *p_hwfn)
  1673. {
  1674. /* clear indirect access */
  1675. if (QED_IS_AH(p_hwfn->cdev)) {
  1676. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1677. PGLUE_B_REG_PGL_ADDR_E8_F0_K2, 0);
  1678. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1679. PGLUE_B_REG_PGL_ADDR_EC_F0_K2, 0);
  1680. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1681. PGLUE_B_REG_PGL_ADDR_F0_F0_K2, 0);
  1682. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1683. PGLUE_B_REG_PGL_ADDR_F4_F0_K2, 0);
  1684. } else {
  1685. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1686. PGLUE_B_REG_PGL_ADDR_88_F0_BB, 0);
  1687. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1688. PGLUE_B_REG_PGL_ADDR_8C_F0_BB, 0);
  1689. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1690. PGLUE_B_REG_PGL_ADDR_90_F0_BB, 0);
  1691. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1692. PGLUE_B_REG_PGL_ADDR_94_F0_BB, 0);
  1693. }
  1694. /* Clean Previous errors if such exist */
  1695. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1696. PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR, 1 << p_hwfn->abs_pf_id);
  1697. /* enable internal target-read */
  1698. qed_wr(p_hwfn, p_hwfn->p_main_ptt,
  1699. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1700. }
  1701. static void get_function_id(struct qed_hwfn *p_hwfn)
  1702. {
  1703. /* ME Register */
  1704. p_hwfn->hw_info.opaque_fid = (u16) REG_RD(p_hwfn,
  1705. PXP_PF_ME_OPAQUE_ADDR);
  1706. p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
  1707. p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
  1708. p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
  1709. PXP_CONCRETE_FID_PFID);
  1710. p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
  1711. PXP_CONCRETE_FID_PORT);
  1712. DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
  1713. "Read ME register: Concrete 0x%08x Opaque 0x%04x\n",
  1714. p_hwfn->hw_info.concrete_fid, p_hwfn->hw_info.opaque_fid);
  1715. }
  1716. static void qed_hw_set_feat(struct qed_hwfn *p_hwfn)
  1717. {
  1718. u32 *feat_num = p_hwfn->hw_info.feat_num;
  1719. struct qed_sb_cnt_info sb_cnt;
  1720. u32 non_l2_sbs = 0;
  1721. memset(&sb_cnt, 0, sizeof(sb_cnt));
  1722. qed_int_get_num_sbs(p_hwfn, &sb_cnt);
  1723. if (IS_ENABLED(CONFIG_QED_RDMA) &&
  1724. QED_IS_RDMA_PERSONALITY(p_hwfn)) {
  1725. /* Roce CNQ each requires: 1 status block + 1 CNQ. We divide
  1726. * the status blocks equally between L2 / RoCE but with
  1727. * consideration as to how many l2 queues / cnqs we have.
  1728. */
  1729. feat_num[QED_RDMA_CNQ] =
  1730. min_t(u32, sb_cnt.cnt / 2,
  1731. RESC_NUM(p_hwfn, QED_RDMA_CNQ_RAM));
  1732. non_l2_sbs = feat_num[QED_RDMA_CNQ];
  1733. }
  1734. if (QED_IS_L2_PERSONALITY(p_hwfn)) {
  1735. /* Start by allocating VF queues, then PF's */
  1736. feat_num[QED_VF_L2_QUE] = min_t(u32,
  1737. RESC_NUM(p_hwfn, QED_L2_QUEUE),
  1738. sb_cnt.iov_cnt);
  1739. feat_num[QED_PF_L2_QUE] = min_t(u32,
  1740. sb_cnt.cnt - non_l2_sbs,
  1741. RESC_NUM(p_hwfn,
  1742. QED_L2_QUEUE) -
  1743. FEAT_NUM(p_hwfn,
  1744. QED_VF_L2_QUE));
  1745. }
  1746. if (QED_IS_FCOE_PERSONALITY(p_hwfn))
  1747. feat_num[QED_FCOE_CQ] = min_t(u32, sb_cnt.cnt,
  1748. RESC_NUM(p_hwfn,
  1749. QED_CMDQS_CQS));
  1750. if (QED_IS_ISCSI_PERSONALITY(p_hwfn))
  1751. feat_num[QED_ISCSI_CQ] = min_t(u32, sb_cnt.cnt,
  1752. RESC_NUM(p_hwfn,
  1753. QED_CMDQS_CQS));
  1754. DP_VERBOSE(p_hwfn,
  1755. NETIF_MSG_PROBE,
  1756. "#PF_L2_QUEUES=%d VF_L2_QUEUES=%d #ROCE_CNQ=%d FCOE_CQ=%d ISCSI_CQ=%d #SBS=%d\n",
  1757. (int)FEAT_NUM(p_hwfn, QED_PF_L2_QUE),
  1758. (int)FEAT_NUM(p_hwfn, QED_VF_L2_QUE),
  1759. (int)FEAT_NUM(p_hwfn, QED_RDMA_CNQ),
  1760. (int)FEAT_NUM(p_hwfn, QED_FCOE_CQ),
  1761. (int)FEAT_NUM(p_hwfn, QED_ISCSI_CQ),
  1762. (int)sb_cnt.cnt);
  1763. }
  1764. const char *qed_hw_get_resc_name(enum qed_resources res_id)
  1765. {
  1766. switch (res_id) {
  1767. case QED_L2_QUEUE:
  1768. return "L2_QUEUE";
  1769. case QED_VPORT:
  1770. return "VPORT";
  1771. case QED_RSS_ENG:
  1772. return "RSS_ENG";
  1773. case QED_PQ:
  1774. return "PQ";
  1775. case QED_RL:
  1776. return "RL";
  1777. case QED_MAC:
  1778. return "MAC";
  1779. case QED_VLAN:
  1780. return "VLAN";
  1781. case QED_RDMA_CNQ_RAM:
  1782. return "RDMA_CNQ_RAM";
  1783. case QED_ILT:
  1784. return "ILT";
  1785. case QED_LL2_QUEUE:
  1786. return "LL2_QUEUE";
  1787. case QED_CMDQS_CQS:
  1788. return "CMDQS_CQS";
  1789. case QED_RDMA_STATS_QUEUE:
  1790. return "RDMA_STATS_QUEUE";
  1791. case QED_BDQ:
  1792. return "BDQ";
  1793. case QED_SB:
  1794. return "SB";
  1795. default:
  1796. return "UNKNOWN_RESOURCE";
  1797. }
  1798. }
  1799. static int
  1800. __qed_hw_set_soft_resc_size(struct qed_hwfn *p_hwfn,
  1801. struct qed_ptt *p_ptt,
  1802. enum qed_resources res_id,
  1803. u32 resc_max_val, u32 *p_mcp_resp)
  1804. {
  1805. int rc;
  1806. rc = qed_mcp_set_resc_max_val(p_hwfn, p_ptt, res_id,
  1807. resc_max_val, p_mcp_resp);
  1808. if (rc) {
  1809. DP_NOTICE(p_hwfn,
  1810. "MFW response failure for a max value setting of resource %d [%s]\n",
  1811. res_id, qed_hw_get_resc_name(res_id));
  1812. return rc;
  1813. }
  1814. if (*p_mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK)
  1815. DP_INFO(p_hwfn,
  1816. "Failed to set the max value of resource %d [%s]. mcp_resp = 0x%08x.\n",
  1817. res_id, qed_hw_get_resc_name(res_id), *p_mcp_resp);
  1818. return 0;
  1819. }
  1820. static int
  1821. qed_hw_set_soft_resc_size(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  1822. {
  1823. bool b_ah = QED_IS_AH(p_hwfn->cdev);
  1824. u32 resc_max_val, mcp_resp;
  1825. u8 res_id;
  1826. int rc;
  1827. for (res_id = 0; res_id < QED_MAX_RESC; res_id++) {
  1828. switch (res_id) {
  1829. case QED_LL2_QUEUE:
  1830. resc_max_val = MAX_NUM_LL2_RX_QUEUES;
  1831. break;
  1832. case QED_RDMA_CNQ_RAM:
  1833. /* No need for a case for QED_CMDQS_CQS since
  1834. * CNQ/CMDQS are the same resource.
  1835. */
  1836. resc_max_val = NUM_OF_GLOBAL_QUEUES;
  1837. break;
  1838. case QED_RDMA_STATS_QUEUE:
  1839. resc_max_val = b_ah ? RDMA_NUM_STATISTIC_COUNTERS_K2
  1840. : RDMA_NUM_STATISTIC_COUNTERS_BB;
  1841. break;
  1842. case QED_BDQ:
  1843. resc_max_val = BDQ_NUM_RESOURCES;
  1844. break;
  1845. default:
  1846. continue;
  1847. }
  1848. rc = __qed_hw_set_soft_resc_size(p_hwfn, p_ptt, res_id,
  1849. resc_max_val, &mcp_resp);
  1850. if (rc)
  1851. return rc;
  1852. /* There's no point to continue to the next resource if the
  1853. * command is not supported by the MFW.
  1854. * We do continue if the command is supported but the resource
  1855. * is unknown to the MFW. Such a resource will be later
  1856. * configured with the default allocation values.
  1857. */
  1858. if (mcp_resp == FW_MSG_CODE_UNSUPPORTED)
  1859. return -EINVAL;
  1860. }
  1861. return 0;
  1862. }
  1863. static
  1864. int qed_hw_get_dflt_resc(struct qed_hwfn *p_hwfn,
  1865. enum qed_resources res_id,
  1866. u32 *p_resc_num, u32 *p_resc_start)
  1867. {
  1868. u8 num_funcs = p_hwfn->num_funcs_on_engine;
  1869. bool b_ah = QED_IS_AH(p_hwfn->cdev);
  1870. switch (res_id) {
  1871. case QED_L2_QUEUE:
  1872. *p_resc_num = (b_ah ? MAX_NUM_L2_QUEUES_K2 :
  1873. MAX_NUM_L2_QUEUES_BB) / num_funcs;
  1874. break;
  1875. case QED_VPORT:
  1876. *p_resc_num = (b_ah ? MAX_NUM_VPORTS_K2 :
  1877. MAX_NUM_VPORTS_BB) / num_funcs;
  1878. break;
  1879. case QED_RSS_ENG:
  1880. *p_resc_num = (b_ah ? ETH_RSS_ENGINE_NUM_K2 :
  1881. ETH_RSS_ENGINE_NUM_BB) / num_funcs;
  1882. break;
  1883. case QED_PQ:
  1884. *p_resc_num = (b_ah ? MAX_QM_TX_QUEUES_K2 :
  1885. MAX_QM_TX_QUEUES_BB) / num_funcs;
  1886. *p_resc_num &= ~0x7; /* The granularity of the PQs is 8 */
  1887. break;
  1888. case QED_RL:
  1889. *p_resc_num = MAX_QM_GLOBAL_RLS / num_funcs;
  1890. break;
  1891. case QED_MAC:
  1892. case QED_VLAN:
  1893. /* Each VFC resource can accommodate both a MAC and a VLAN */
  1894. *p_resc_num = ETH_NUM_MAC_FILTERS / num_funcs;
  1895. break;
  1896. case QED_ILT:
  1897. *p_resc_num = (b_ah ? PXP_NUM_ILT_RECORDS_K2 :
  1898. PXP_NUM_ILT_RECORDS_BB) / num_funcs;
  1899. break;
  1900. case QED_LL2_QUEUE:
  1901. *p_resc_num = MAX_NUM_LL2_RX_QUEUES / num_funcs;
  1902. break;
  1903. case QED_RDMA_CNQ_RAM:
  1904. case QED_CMDQS_CQS:
  1905. /* CNQ/CMDQS are the same resource */
  1906. *p_resc_num = NUM_OF_GLOBAL_QUEUES / num_funcs;
  1907. break;
  1908. case QED_RDMA_STATS_QUEUE:
  1909. *p_resc_num = (b_ah ? RDMA_NUM_STATISTIC_COUNTERS_K2 :
  1910. RDMA_NUM_STATISTIC_COUNTERS_BB) / num_funcs;
  1911. break;
  1912. case QED_BDQ:
  1913. if (p_hwfn->hw_info.personality != QED_PCI_ISCSI &&
  1914. p_hwfn->hw_info.personality != QED_PCI_FCOE)
  1915. *p_resc_num = 0;
  1916. else
  1917. *p_resc_num = 1;
  1918. break;
  1919. case QED_SB:
  1920. /* Since we want its value to reflect whether MFW supports
  1921. * the new scheme, have a default of 0.
  1922. */
  1923. *p_resc_num = 0;
  1924. break;
  1925. default:
  1926. return -EINVAL;
  1927. }
  1928. switch (res_id) {
  1929. case QED_BDQ:
  1930. if (!*p_resc_num)
  1931. *p_resc_start = 0;
  1932. else if (p_hwfn->cdev->num_ports_in_engine == 4)
  1933. *p_resc_start = p_hwfn->port_id;
  1934. else if (p_hwfn->hw_info.personality == QED_PCI_ISCSI)
  1935. *p_resc_start = p_hwfn->port_id;
  1936. else if (p_hwfn->hw_info.personality == QED_PCI_FCOE)
  1937. *p_resc_start = p_hwfn->port_id + 2;
  1938. break;
  1939. default:
  1940. *p_resc_start = *p_resc_num * p_hwfn->enabled_func_idx;
  1941. break;
  1942. }
  1943. return 0;
  1944. }
  1945. static int __qed_hw_set_resc_info(struct qed_hwfn *p_hwfn,
  1946. enum qed_resources res_id)
  1947. {
  1948. u32 dflt_resc_num = 0, dflt_resc_start = 0;
  1949. u32 mcp_resp, *p_resc_num, *p_resc_start;
  1950. int rc;
  1951. p_resc_num = &RESC_NUM(p_hwfn, res_id);
  1952. p_resc_start = &RESC_START(p_hwfn, res_id);
  1953. rc = qed_hw_get_dflt_resc(p_hwfn, res_id, &dflt_resc_num,
  1954. &dflt_resc_start);
  1955. if (rc) {
  1956. DP_ERR(p_hwfn,
  1957. "Failed to get default amount for resource %d [%s]\n",
  1958. res_id, qed_hw_get_resc_name(res_id));
  1959. return rc;
  1960. }
  1961. rc = qed_mcp_get_resc_info(p_hwfn, p_hwfn->p_main_ptt, res_id,
  1962. &mcp_resp, p_resc_num, p_resc_start);
  1963. if (rc) {
  1964. DP_NOTICE(p_hwfn,
  1965. "MFW response failure for an allocation request for resource %d [%s]\n",
  1966. res_id, qed_hw_get_resc_name(res_id));
  1967. return rc;
  1968. }
  1969. /* Default driver values are applied in the following cases:
  1970. * - The resource allocation MB command is not supported by the MFW
  1971. * - There is an internal error in the MFW while processing the request
  1972. * - The resource ID is unknown to the MFW
  1973. */
  1974. if (mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK) {
  1975. DP_INFO(p_hwfn,
  1976. "Failed to receive allocation info for resource %d [%s]. mcp_resp = 0x%x. Applying default values [%d,%d].\n",
  1977. res_id,
  1978. qed_hw_get_resc_name(res_id),
  1979. mcp_resp, dflt_resc_num, dflt_resc_start);
  1980. *p_resc_num = dflt_resc_num;
  1981. *p_resc_start = dflt_resc_start;
  1982. goto out;
  1983. }
  1984. out:
  1985. /* PQs have to divide by 8 [that's the HW granularity].
  1986. * Reduce number so it would fit.
  1987. */
  1988. if ((res_id == QED_PQ) && ((*p_resc_num % 8) || (*p_resc_start % 8))) {
  1989. DP_INFO(p_hwfn,
  1990. "PQs need to align by 8; Number %08x --> %08x, Start %08x --> %08x\n",
  1991. *p_resc_num,
  1992. (*p_resc_num) & ~0x7,
  1993. *p_resc_start, (*p_resc_start) & ~0x7);
  1994. *p_resc_num &= ~0x7;
  1995. *p_resc_start &= ~0x7;
  1996. }
  1997. return 0;
  1998. }
  1999. static int qed_hw_set_resc_info(struct qed_hwfn *p_hwfn)
  2000. {
  2001. int rc;
  2002. u8 res_id;
  2003. for (res_id = 0; res_id < QED_MAX_RESC; res_id++) {
  2004. rc = __qed_hw_set_resc_info(p_hwfn, res_id);
  2005. if (rc)
  2006. return rc;
  2007. }
  2008. return 0;
  2009. }
  2010. static int qed_hw_get_resc(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  2011. {
  2012. struct qed_resc_unlock_params resc_unlock_params;
  2013. struct qed_resc_lock_params resc_lock_params;
  2014. bool b_ah = QED_IS_AH(p_hwfn->cdev);
  2015. u8 res_id;
  2016. int rc;
  2017. /* Setting the max values of the soft resources and the following
  2018. * resources allocation queries should be atomic. Since several PFs can
  2019. * run in parallel - a resource lock is needed.
  2020. * If either the resource lock or resource set value commands are not
  2021. * supported - skip the the max values setting, release the lock if
  2022. * needed, and proceed to the queries. Other failures, including a
  2023. * failure to acquire the lock, will cause this function to fail.
  2024. */
  2025. qed_mcp_resc_lock_default_init(&resc_lock_params, &resc_unlock_params,
  2026. QED_RESC_LOCK_RESC_ALLOC, false);
  2027. rc = qed_mcp_resc_lock(p_hwfn, p_ptt, &resc_lock_params);
  2028. if (rc && rc != -EINVAL) {
  2029. return rc;
  2030. } else if (rc == -EINVAL) {
  2031. DP_INFO(p_hwfn,
  2032. "Skip the max values setting of the soft resources since the resource lock is not supported by the MFW\n");
  2033. } else if (!rc && !resc_lock_params.b_granted) {
  2034. DP_NOTICE(p_hwfn,
  2035. "Failed to acquire the resource lock for the resource allocation commands\n");
  2036. return -EBUSY;
  2037. } else {
  2038. rc = qed_hw_set_soft_resc_size(p_hwfn, p_ptt);
  2039. if (rc && rc != -EINVAL) {
  2040. DP_NOTICE(p_hwfn,
  2041. "Failed to set the max values of the soft resources\n");
  2042. goto unlock_and_exit;
  2043. } else if (rc == -EINVAL) {
  2044. DP_INFO(p_hwfn,
  2045. "Skip the max values setting of the soft resources since it is not supported by the MFW\n");
  2046. rc = qed_mcp_resc_unlock(p_hwfn, p_ptt,
  2047. &resc_unlock_params);
  2048. if (rc)
  2049. DP_INFO(p_hwfn,
  2050. "Failed to release the resource lock for the resource allocation commands\n");
  2051. }
  2052. }
  2053. rc = qed_hw_set_resc_info(p_hwfn);
  2054. if (rc)
  2055. goto unlock_and_exit;
  2056. if (resc_lock_params.b_granted && !resc_unlock_params.b_released) {
  2057. rc = qed_mcp_resc_unlock(p_hwfn, p_ptt, &resc_unlock_params);
  2058. if (rc)
  2059. DP_INFO(p_hwfn,
  2060. "Failed to release the resource lock for the resource allocation commands\n");
  2061. }
  2062. /* Sanity for ILT */
  2063. if ((b_ah && (RESC_END(p_hwfn, QED_ILT) > PXP_NUM_ILT_RECORDS_K2)) ||
  2064. (!b_ah && (RESC_END(p_hwfn, QED_ILT) > PXP_NUM_ILT_RECORDS_BB))) {
  2065. DP_NOTICE(p_hwfn, "Can't assign ILT pages [%08x,...,%08x]\n",
  2066. RESC_START(p_hwfn, QED_ILT),
  2067. RESC_END(p_hwfn, QED_ILT) - 1);
  2068. return -EINVAL;
  2069. }
  2070. /* This will also learn the number of SBs from MFW */
  2071. if (qed_int_igu_reset_cam(p_hwfn, p_ptt))
  2072. return -EINVAL;
  2073. qed_hw_set_feat(p_hwfn);
  2074. for (res_id = 0; res_id < QED_MAX_RESC; res_id++)
  2075. DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE, "%s = %d start = %d\n",
  2076. qed_hw_get_resc_name(res_id),
  2077. RESC_NUM(p_hwfn, res_id),
  2078. RESC_START(p_hwfn, res_id));
  2079. return 0;
  2080. unlock_and_exit:
  2081. if (resc_lock_params.b_granted && !resc_unlock_params.b_released)
  2082. qed_mcp_resc_unlock(p_hwfn, p_ptt, &resc_unlock_params);
  2083. return rc;
  2084. }
  2085. static int qed_hw_get_nvm_info(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  2086. {
  2087. u32 port_cfg_addr, link_temp, nvm_cfg_addr, device_capabilities;
  2088. u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg;
  2089. struct qed_mcp_link_capabilities *p_caps;
  2090. struct qed_mcp_link_params *link;
  2091. /* Read global nvm_cfg address */
  2092. nvm_cfg_addr = qed_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
  2093. /* Verify MCP has initialized it */
  2094. if (!nvm_cfg_addr) {
  2095. DP_NOTICE(p_hwfn, "Shared memory not initialized\n");
  2096. return -EINVAL;
  2097. }
  2098. /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
  2099. nvm_cfg1_offset = qed_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
  2100. addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  2101. offsetof(struct nvm_cfg1, glob) +
  2102. offsetof(struct nvm_cfg1_glob, core_cfg);
  2103. core_cfg = qed_rd(p_hwfn, p_ptt, addr);
  2104. switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
  2105. NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
  2106. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_2X40G:
  2107. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X40G;
  2108. break;
  2109. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X50G:
  2110. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X50G;
  2111. break;
  2112. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_1X100G:
  2113. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X100G;
  2114. break;
  2115. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X10G_F:
  2116. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_F;
  2117. break;
  2118. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X10G_E:
  2119. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_E;
  2120. break;
  2121. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X20G:
  2122. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X20G;
  2123. break;
  2124. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X40G:
  2125. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X40G;
  2126. break;
  2127. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X25G:
  2128. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X25G;
  2129. break;
  2130. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X10G:
  2131. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X10G;
  2132. break;
  2133. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X25G:
  2134. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X25G;
  2135. break;
  2136. case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X25G:
  2137. p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X25G;
  2138. break;
  2139. default:
  2140. DP_NOTICE(p_hwfn, "Unknown port mode in 0x%08x\n", core_cfg);
  2141. break;
  2142. }
  2143. /* Read default link configuration */
  2144. link = &p_hwfn->mcp_info->link_input;
  2145. p_caps = &p_hwfn->mcp_info->link_capabilities;
  2146. port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  2147. offsetof(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
  2148. link_temp = qed_rd(p_hwfn, p_ptt,
  2149. port_cfg_addr +
  2150. offsetof(struct nvm_cfg1_port, speed_cap_mask));
  2151. link_temp &= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
  2152. link->speed.advertised_speeds = link_temp;
  2153. link_temp = link->speed.advertised_speeds;
  2154. p_hwfn->mcp_info->link_capabilities.speed_capabilities = link_temp;
  2155. link_temp = qed_rd(p_hwfn, p_ptt,
  2156. port_cfg_addr +
  2157. offsetof(struct nvm_cfg1_port, link_settings));
  2158. switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
  2159. NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
  2160. case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
  2161. link->speed.autoneg = true;
  2162. break;
  2163. case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
  2164. link->speed.forced_speed = 1000;
  2165. break;
  2166. case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
  2167. link->speed.forced_speed = 10000;
  2168. break;
  2169. case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
  2170. link->speed.forced_speed = 25000;
  2171. break;
  2172. case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
  2173. link->speed.forced_speed = 40000;
  2174. break;
  2175. case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
  2176. link->speed.forced_speed = 50000;
  2177. break;
  2178. case NVM_CFG1_PORT_DRV_LINK_SPEED_BB_100G:
  2179. link->speed.forced_speed = 100000;
  2180. break;
  2181. default:
  2182. DP_NOTICE(p_hwfn, "Unknown Speed in 0x%08x\n", link_temp);
  2183. }
  2184. p_hwfn->mcp_info->link_capabilities.default_speed_autoneg =
  2185. link->speed.autoneg;
  2186. link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
  2187. link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
  2188. link->pause.autoneg = !!(link_temp &
  2189. NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
  2190. link->pause.forced_rx = !!(link_temp &
  2191. NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
  2192. link->pause.forced_tx = !!(link_temp &
  2193. NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
  2194. link->loopback_mode = 0;
  2195. if (p_hwfn->mcp_info->capabilities & FW_MB_PARAM_FEATURE_SUPPORT_EEE) {
  2196. link_temp = qed_rd(p_hwfn, p_ptt, port_cfg_addr +
  2197. offsetof(struct nvm_cfg1_port, ext_phy));
  2198. link_temp &= NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_MASK;
  2199. link_temp >>= NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_OFFSET;
  2200. p_caps->default_eee = QED_MCP_EEE_ENABLED;
  2201. link->eee.enable = true;
  2202. switch (link_temp) {
  2203. case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_DISABLED:
  2204. p_caps->default_eee = QED_MCP_EEE_DISABLED;
  2205. link->eee.enable = false;
  2206. break;
  2207. case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_BALANCED:
  2208. p_caps->eee_lpi_timer = EEE_TX_TIMER_USEC_BALANCED_TIME;
  2209. break;
  2210. case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_AGGRESSIVE:
  2211. p_caps->eee_lpi_timer =
  2212. EEE_TX_TIMER_USEC_AGGRESSIVE_TIME;
  2213. break;
  2214. case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_LOW_LATENCY:
  2215. p_caps->eee_lpi_timer = EEE_TX_TIMER_USEC_LATENCY_TIME;
  2216. break;
  2217. }
  2218. link->eee.tx_lpi_timer = p_caps->eee_lpi_timer;
  2219. link->eee.tx_lpi_enable = link->eee.enable;
  2220. link->eee.adv_caps = QED_EEE_1G_ADV | QED_EEE_10G_ADV;
  2221. } else {
  2222. p_caps->default_eee = QED_MCP_EEE_UNSUPPORTED;
  2223. }
  2224. DP_VERBOSE(p_hwfn,
  2225. NETIF_MSG_LINK,
  2226. "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x EEE: %02x [%08x usec]\n",
  2227. link->speed.forced_speed,
  2228. link->speed.advertised_speeds,
  2229. link->speed.autoneg,
  2230. link->pause.autoneg,
  2231. p_caps->default_eee, p_caps->eee_lpi_timer);
  2232. if (IS_LEAD_HWFN(p_hwfn)) {
  2233. struct qed_dev *cdev = p_hwfn->cdev;
  2234. /* Read Multi-function information from shmem */
  2235. addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  2236. offsetof(struct nvm_cfg1, glob) +
  2237. offsetof(struct nvm_cfg1_glob, generic_cont0);
  2238. generic_cont0 = qed_rd(p_hwfn, p_ptt, addr);
  2239. mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
  2240. NVM_CFG1_GLOB_MF_MODE_OFFSET;
  2241. switch (mf_mode) {
  2242. case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
  2243. cdev->mf_bits = BIT(QED_MF_OVLAN_CLSS);
  2244. break;
  2245. case NVM_CFG1_GLOB_MF_MODE_UFP:
  2246. cdev->mf_bits = BIT(QED_MF_OVLAN_CLSS) |
  2247. BIT(QED_MF_LLH_PROTO_CLSS) |
  2248. BIT(QED_MF_UFP_SPECIFIC) |
  2249. BIT(QED_MF_8021Q_TAGGING);
  2250. break;
  2251. case NVM_CFG1_GLOB_MF_MODE_BD:
  2252. cdev->mf_bits = BIT(QED_MF_OVLAN_CLSS) |
  2253. BIT(QED_MF_LLH_PROTO_CLSS) |
  2254. BIT(QED_MF_8021AD_TAGGING);
  2255. break;
  2256. case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
  2257. cdev->mf_bits = BIT(QED_MF_LLH_MAC_CLSS) |
  2258. BIT(QED_MF_LLH_PROTO_CLSS) |
  2259. BIT(QED_MF_LL2_NON_UNICAST) |
  2260. BIT(QED_MF_INTER_PF_SWITCH);
  2261. break;
  2262. case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
  2263. cdev->mf_bits = BIT(QED_MF_LLH_MAC_CLSS) |
  2264. BIT(QED_MF_LLH_PROTO_CLSS) |
  2265. BIT(QED_MF_LL2_NON_UNICAST);
  2266. if (QED_IS_BB(p_hwfn->cdev))
  2267. cdev->mf_bits |= BIT(QED_MF_NEED_DEF_PF);
  2268. break;
  2269. }
  2270. DP_INFO(p_hwfn, "Multi function mode is 0x%lx\n",
  2271. cdev->mf_bits);
  2272. }
  2273. DP_INFO(p_hwfn, "Multi function mode is 0x%lx\n",
  2274. p_hwfn->cdev->mf_bits);
  2275. /* Read device capabilities information from shmem */
  2276. addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
  2277. offsetof(struct nvm_cfg1, glob) +
  2278. offsetof(struct nvm_cfg1_glob, device_capabilities);
  2279. device_capabilities = qed_rd(p_hwfn, p_ptt, addr);
  2280. if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET)
  2281. __set_bit(QED_DEV_CAP_ETH,
  2282. &p_hwfn->hw_info.device_capabilities);
  2283. if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_FCOE)
  2284. __set_bit(QED_DEV_CAP_FCOE,
  2285. &p_hwfn->hw_info.device_capabilities);
  2286. if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ISCSI)
  2287. __set_bit(QED_DEV_CAP_ISCSI,
  2288. &p_hwfn->hw_info.device_capabilities);
  2289. if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ROCE)
  2290. __set_bit(QED_DEV_CAP_ROCE,
  2291. &p_hwfn->hw_info.device_capabilities);
  2292. return qed_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
  2293. }
  2294. static void qed_get_num_funcs(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  2295. {
  2296. u8 num_funcs, enabled_func_idx = p_hwfn->rel_pf_id;
  2297. u32 reg_function_hide, tmp, eng_mask, low_pfs_mask;
  2298. struct qed_dev *cdev = p_hwfn->cdev;
  2299. num_funcs = QED_IS_AH(cdev) ? MAX_NUM_PFS_K2 : MAX_NUM_PFS_BB;
  2300. /* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values
  2301. * in the other bits are selected.
  2302. * Bits 1-15 are for functions 1-15, respectively, and their value is
  2303. * '0' only for enabled functions (function 0 always exists and
  2304. * enabled).
  2305. * In case of CMT, only the "even" functions are enabled, and thus the
  2306. * number of functions for both hwfns is learnt from the same bits.
  2307. */
  2308. reg_function_hide = qed_rd(p_hwfn, p_ptt, MISCS_REG_FUNCTION_HIDE);
  2309. if (reg_function_hide & 0x1) {
  2310. if (QED_IS_BB(cdev)) {
  2311. if (QED_PATH_ID(p_hwfn) && cdev->num_hwfns == 1) {
  2312. num_funcs = 0;
  2313. eng_mask = 0xaaaa;
  2314. } else {
  2315. num_funcs = 1;
  2316. eng_mask = 0x5554;
  2317. }
  2318. } else {
  2319. num_funcs = 1;
  2320. eng_mask = 0xfffe;
  2321. }
  2322. /* Get the number of the enabled functions on the engine */
  2323. tmp = (reg_function_hide ^ 0xffffffff) & eng_mask;
  2324. while (tmp) {
  2325. if (tmp & 0x1)
  2326. num_funcs++;
  2327. tmp >>= 0x1;
  2328. }
  2329. /* Get the PF index within the enabled functions */
  2330. low_pfs_mask = (0x1 << p_hwfn->abs_pf_id) - 1;
  2331. tmp = reg_function_hide & eng_mask & low_pfs_mask;
  2332. while (tmp) {
  2333. if (tmp & 0x1)
  2334. enabled_func_idx--;
  2335. tmp >>= 0x1;
  2336. }
  2337. }
  2338. p_hwfn->num_funcs_on_engine = num_funcs;
  2339. p_hwfn->enabled_func_idx = enabled_func_idx;
  2340. DP_VERBOSE(p_hwfn,
  2341. NETIF_MSG_PROBE,
  2342. "PF [rel_id %d, abs_id %d] occupies index %d within the %d enabled functions on the engine\n",
  2343. p_hwfn->rel_pf_id,
  2344. p_hwfn->abs_pf_id,
  2345. p_hwfn->enabled_func_idx, p_hwfn->num_funcs_on_engine);
  2346. }
  2347. static void qed_hw_info_port_num_bb(struct qed_hwfn *p_hwfn,
  2348. struct qed_ptt *p_ptt)
  2349. {
  2350. u32 port_mode;
  2351. port_mode = qed_rd(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB);
  2352. if (port_mode < 3) {
  2353. p_hwfn->cdev->num_ports_in_engine = 1;
  2354. } else if (port_mode <= 5) {
  2355. p_hwfn->cdev->num_ports_in_engine = 2;
  2356. } else {
  2357. DP_NOTICE(p_hwfn, "PORT MODE: %d not supported\n",
  2358. p_hwfn->cdev->num_ports_in_engine);
  2359. /* Default num_ports_in_engine to something */
  2360. p_hwfn->cdev->num_ports_in_engine = 1;
  2361. }
  2362. }
  2363. static void qed_hw_info_port_num_ah(struct qed_hwfn *p_hwfn,
  2364. struct qed_ptt *p_ptt)
  2365. {
  2366. u32 port;
  2367. int i;
  2368. p_hwfn->cdev->num_ports_in_engine = 0;
  2369. for (i = 0; i < MAX_NUM_PORTS_K2; i++) {
  2370. port = qed_rd(p_hwfn, p_ptt,
  2371. CNIG_REG_NIG_PORT0_CONF_K2 + (i * 4));
  2372. if (port & 1)
  2373. p_hwfn->cdev->num_ports_in_engine++;
  2374. }
  2375. if (!p_hwfn->cdev->num_ports_in_engine) {
  2376. DP_NOTICE(p_hwfn, "All NIG ports are inactive\n");
  2377. /* Default num_ports_in_engine to something */
  2378. p_hwfn->cdev->num_ports_in_engine = 1;
  2379. }
  2380. }
  2381. static void qed_hw_info_port_num(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  2382. {
  2383. if (QED_IS_BB(p_hwfn->cdev))
  2384. qed_hw_info_port_num_bb(p_hwfn, p_ptt);
  2385. else
  2386. qed_hw_info_port_num_ah(p_hwfn, p_ptt);
  2387. }
  2388. static void qed_get_eee_caps(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  2389. {
  2390. struct qed_mcp_link_capabilities *p_caps;
  2391. u32 eee_status;
  2392. p_caps = &p_hwfn->mcp_info->link_capabilities;
  2393. if (p_caps->default_eee == QED_MCP_EEE_UNSUPPORTED)
  2394. return;
  2395. p_caps->eee_speed_caps = 0;
  2396. eee_status = qed_rd(p_hwfn, p_ptt, p_hwfn->mcp_info->port_addr +
  2397. offsetof(struct public_port, eee_status));
  2398. eee_status = (eee_status & EEE_SUPPORTED_SPEED_MASK) >>
  2399. EEE_SUPPORTED_SPEED_OFFSET;
  2400. if (eee_status & EEE_1G_SUPPORTED)
  2401. p_caps->eee_speed_caps |= QED_EEE_1G_ADV;
  2402. if (eee_status & EEE_10G_ADV)
  2403. p_caps->eee_speed_caps |= QED_EEE_10G_ADV;
  2404. }
  2405. static int
  2406. qed_get_hw_info(struct qed_hwfn *p_hwfn,
  2407. struct qed_ptt *p_ptt,
  2408. enum qed_pci_personality personality)
  2409. {
  2410. int rc;
  2411. /* Since all information is common, only first hwfns should do this */
  2412. if (IS_LEAD_HWFN(p_hwfn)) {
  2413. rc = qed_iov_hw_info(p_hwfn);
  2414. if (rc)
  2415. return rc;
  2416. }
  2417. qed_hw_info_port_num(p_hwfn, p_ptt);
  2418. qed_mcp_get_capabilities(p_hwfn, p_ptt);
  2419. qed_hw_get_nvm_info(p_hwfn, p_ptt);
  2420. rc = qed_int_igu_read_cam(p_hwfn, p_ptt);
  2421. if (rc)
  2422. return rc;
  2423. if (qed_mcp_is_init(p_hwfn))
  2424. ether_addr_copy(p_hwfn->hw_info.hw_mac_addr,
  2425. p_hwfn->mcp_info->func_info.mac);
  2426. else
  2427. eth_random_addr(p_hwfn->hw_info.hw_mac_addr);
  2428. if (qed_mcp_is_init(p_hwfn)) {
  2429. if (p_hwfn->mcp_info->func_info.ovlan != QED_MCP_VLAN_UNSET)
  2430. p_hwfn->hw_info.ovlan =
  2431. p_hwfn->mcp_info->func_info.ovlan;
  2432. qed_mcp_cmd_port_init(p_hwfn, p_ptt);
  2433. qed_get_eee_caps(p_hwfn, p_ptt);
  2434. qed_mcp_read_ufp_config(p_hwfn, p_ptt);
  2435. }
  2436. if (qed_mcp_is_init(p_hwfn)) {
  2437. enum qed_pci_personality protocol;
  2438. protocol = p_hwfn->mcp_info->func_info.protocol;
  2439. p_hwfn->hw_info.personality = protocol;
  2440. }
  2441. p_hwfn->hw_info.num_hw_tc = NUM_PHYS_TCS_4PORT_K2;
  2442. p_hwfn->hw_info.num_active_tc = 1;
  2443. qed_get_num_funcs(p_hwfn, p_ptt);
  2444. if (qed_mcp_is_init(p_hwfn))
  2445. p_hwfn->hw_info.mtu = p_hwfn->mcp_info->func_info.mtu;
  2446. return qed_hw_get_resc(p_hwfn, p_ptt);
  2447. }
  2448. static int qed_get_dev_info(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  2449. {
  2450. struct qed_dev *cdev = p_hwfn->cdev;
  2451. u16 device_id_mask;
  2452. u32 tmp;
  2453. /* Read Vendor Id / Device Id */
  2454. pci_read_config_word(cdev->pdev, PCI_VENDOR_ID, &cdev->vendor_id);
  2455. pci_read_config_word(cdev->pdev, PCI_DEVICE_ID, &cdev->device_id);
  2456. /* Determine type */
  2457. device_id_mask = cdev->device_id & QED_DEV_ID_MASK;
  2458. switch (device_id_mask) {
  2459. case QED_DEV_ID_MASK_BB:
  2460. cdev->type = QED_DEV_TYPE_BB;
  2461. break;
  2462. case QED_DEV_ID_MASK_AH:
  2463. cdev->type = QED_DEV_TYPE_AH;
  2464. break;
  2465. default:
  2466. DP_NOTICE(p_hwfn, "Unknown device id 0x%x\n", cdev->device_id);
  2467. return -EBUSY;
  2468. }
  2469. cdev->chip_num = (u16)qed_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_NUM);
  2470. cdev->chip_rev = (u16)qed_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_REV);
  2471. MASK_FIELD(CHIP_REV, cdev->chip_rev);
  2472. /* Learn number of HW-functions */
  2473. tmp = qed_rd(p_hwfn, p_ptt, MISCS_REG_CMT_ENABLED_FOR_PAIR);
  2474. if (tmp & (1 << p_hwfn->rel_pf_id)) {
  2475. DP_NOTICE(cdev->hwfns, "device in CMT mode\n");
  2476. cdev->num_hwfns = 2;
  2477. } else {
  2478. cdev->num_hwfns = 1;
  2479. }
  2480. cdev->chip_bond_id = qed_rd(p_hwfn, p_ptt,
  2481. MISCS_REG_CHIP_TEST_REG) >> 4;
  2482. MASK_FIELD(CHIP_BOND_ID, cdev->chip_bond_id);
  2483. cdev->chip_metal = (u16)qed_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_METAL);
  2484. MASK_FIELD(CHIP_METAL, cdev->chip_metal);
  2485. DP_INFO(cdev->hwfns,
  2486. "Chip details - %s %c%d, Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
  2487. QED_IS_BB(cdev) ? "BB" : "AH",
  2488. 'A' + cdev->chip_rev,
  2489. (int)cdev->chip_metal,
  2490. cdev->chip_num, cdev->chip_rev,
  2491. cdev->chip_bond_id, cdev->chip_metal);
  2492. return 0;
  2493. }
  2494. static void qed_nvm_info_free(struct qed_hwfn *p_hwfn)
  2495. {
  2496. kfree(p_hwfn->nvm_info.image_att);
  2497. p_hwfn->nvm_info.image_att = NULL;
  2498. }
  2499. static int qed_hw_prepare_single(struct qed_hwfn *p_hwfn,
  2500. void __iomem *p_regview,
  2501. void __iomem *p_doorbells,
  2502. enum qed_pci_personality personality)
  2503. {
  2504. int rc = 0;
  2505. /* Split PCI bars evenly between hwfns */
  2506. p_hwfn->regview = p_regview;
  2507. p_hwfn->doorbells = p_doorbells;
  2508. if (IS_VF(p_hwfn->cdev))
  2509. return qed_vf_hw_prepare(p_hwfn);
  2510. /* Validate that chip access is feasible */
  2511. if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
  2512. DP_ERR(p_hwfn,
  2513. "Reading the ME register returns all Fs; Preventing further chip access\n");
  2514. return -EINVAL;
  2515. }
  2516. get_function_id(p_hwfn);
  2517. /* Allocate PTT pool */
  2518. rc = qed_ptt_pool_alloc(p_hwfn);
  2519. if (rc)
  2520. goto err0;
  2521. /* Allocate the main PTT */
  2522. p_hwfn->p_main_ptt = qed_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
  2523. /* First hwfn learns basic information, e.g., number of hwfns */
  2524. if (!p_hwfn->my_id) {
  2525. rc = qed_get_dev_info(p_hwfn, p_hwfn->p_main_ptt);
  2526. if (rc)
  2527. goto err1;
  2528. }
  2529. qed_hw_hwfn_prepare(p_hwfn);
  2530. /* Initialize MCP structure */
  2531. rc = qed_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
  2532. if (rc) {
  2533. DP_NOTICE(p_hwfn, "Failed initializing mcp command\n");
  2534. goto err1;
  2535. }
  2536. /* Read the device configuration information from the HW and SHMEM */
  2537. rc = qed_get_hw_info(p_hwfn, p_hwfn->p_main_ptt, personality);
  2538. if (rc) {
  2539. DP_NOTICE(p_hwfn, "Failed to get HW information\n");
  2540. goto err2;
  2541. }
  2542. /* Sending a mailbox to the MFW should be done after qed_get_hw_info()
  2543. * is called as it sets the ports number in an engine.
  2544. */
  2545. if (IS_LEAD_HWFN(p_hwfn)) {
  2546. rc = qed_mcp_initiate_pf_flr(p_hwfn, p_hwfn->p_main_ptt);
  2547. if (rc)
  2548. DP_NOTICE(p_hwfn, "Failed to initiate PF FLR\n");
  2549. }
  2550. /* NVRAM info initialization and population */
  2551. if (IS_LEAD_HWFN(p_hwfn)) {
  2552. rc = qed_mcp_nvm_info_populate(p_hwfn);
  2553. if (rc) {
  2554. DP_NOTICE(p_hwfn,
  2555. "Failed to populate nvm info shadow\n");
  2556. goto err2;
  2557. }
  2558. }
  2559. /* Allocate the init RT array and initialize the init-ops engine */
  2560. rc = qed_init_alloc(p_hwfn);
  2561. if (rc)
  2562. goto err3;
  2563. return rc;
  2564. err3:
  2565. if (IS_LEAD_HWFN(p_hwfn))
  2566. qed_nvm_info_free(p_hwfn);
  2567. err2:
  2568. if (IS_LEAD_HWFN(p_hwfn))
  2569. qed_iov_free_hw_info(p_hwfn->cdev);
  2570. qed_mcp_free(p_hwfn);
  2571. err1:
  2572. qed_hw_hwfn_free(p_hwfn);
  2573. err0:
  2574. return rc;
  2575. }
  2576. int qed_hw_prepare(struct qed_dev *cdev,
  2577. int personality)
  2578. {
  2579. struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
  2580. int rc;
  2581. /* Store the precompiled init data ptrs */
  2582. if (IS_PF(cdev))
  2583. qed_init_iro_array(cdev);
  2584. /* Initialize the first hwfn - will learn number of hwfns */
  2585. rc = qed_hw_prepare_single(p_hwfn,
  2586. cdev->regview,
  2587. cdev->doorbells, personality);
  2588. if (rc)
  2589. return rc;
  2590. personality = p_hwfn->hw_info.personality;
  2591. /* Initialize the rest of the hwfns */
  2592. if (cdev->num_hwfns > 1) {
  2593. void __iomem *p_regview, *p_doorbell;
  2594. u8 __iomem *addr;
  2595. /* adjust bar offset for second engine */
  2596. addr = cdev->regview +
  2597. qed_hw_bar_size(p_hwfn, p_hwfn->p_main_ptt,
  2598. BAR_ID_0) / 2;
  2599. p_regview = addr;
  2600. addr = cdev->doorbells +
  2601. qed_hw_bar_size(p_hwfn, p_hwfn->p_main_ptt,
  2602. BAR_ID_1) / 2;
  2603. p_doorbell = addr;
  2604. /* prepare second hw function */
  2605. rc = qed_hw_prepare_single(&cdev->hwfns[1], p_regview,
  2606. p_doorbell, personality);
  2607. /* in case of error, need to free the previously
  2608. * initiliazed hwfn 0.
  2609. */
  2610. if (rc) {
  2611. if (IS_PF(cdev)) {
  2612. qed_init_free(p_hwfn);
  2613. qed_nvm_info_free(p_hwfn);
  2614. qed_mcp_free(p_hwfn);
  2615. qed_hw_hwfn_free(p_hwfn);
  2616. }
  2617. }
  2618. }
  2619. return rc;
  2620. }
  2621. void qed_hw_remove(struct qed_dev *cdev)
  2622. {
  2623. struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
  2624. int i;
  2625. if (IS_PF(cdev))
  2626. qed_mcp_ov_update_driver_state(p_hwfn, p_hwfn->p_main_ptt,
  2627. QED_OV_DRIVER_STATE_NOT_LOADED);
  2628. for_each_hwfn(cdev, i) {
  2629. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  2630. if (IS_VF(cdev)) {
  2631. qed_vf_pf_release(p_hwfn);
  2632. continue;
  2633. }
  2634. qed_init_free(p_hwfn);
  2635. qed_hw_hwfn_free(p_hwfn);
  2636. qed_mcp_free(p_hwfn);
  2637. }
  2638. qed_iov_free_hw_info(cdev);
  2639. qed_nvm_info_free(p_hwfn);
  2640. }
  2641. static void qed_chain_free_next_ptr(struct qed_dev *cdev,
  2642. struct qed_chain *p_chain)
  2643. {
  2644. void *p_virt = p_chain->p_virt_addr, *p_virt_next = NULL;
  2645. dma_addr_t p_phys = p_chain->p_phys_addr, p_phys_next = 0;
  2646. struct qed_chain_next *p_next;
  2647. u32 size, i;
  2648. if (!p_virt)
  2649. return;
  2650. size = p_chain->elem_size * p_chain->usable_per_page;
  2651. for (i = 0; i < p_chain->page_cnt; i++) {
  2652. if (!p_virt)
  2653. break;
  2654. p_next = (struct qed_chain_next *)((u8 *)p_virt + size);
  2655. p_virt_next = p_next->next_virt;
  2656. p_phys_next = HILO_DMA_REGPAIR(p_next->next_phys);
  2657. dma_free_coherent(&cdev->pdev->dev,
  2658. QED_CHAIN_PAGE_SIZE, p_virt, p_phys);
  2659. p_virt = p_virt_next;
  2660. p_phys = p_phys_next;
  2661. }
  2662. }
  2663. static void qed_chain_free_single(struct qed_dev *cdev,
  2664. struct qed_chain *p_chain)
  2665. {
  2666. if (!p_chain->p_virt_addr)
  2667. return;
  2668. dma_free_coherent(&cdev->pdev->dev,
  2669. QED_CHAIN_PAGE_SIZE,
  2670. p_chain->p_virt_addr, p_chain->p_phys_addr);
  2671. }
  2672. static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *p_chain)
  2673. {
  2674. void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl;
  2675. u32 page_cnt = p_chain->page_cnt, i, pbl_size;
  2676. u8 *p_pbl_virt = p_chain->pbl_sp.p_virt_table;
  2677. if (!pp_virt_addr_tbl)
  2678. return;
  2679. if (!p_pbl_virt)
  2680. goto out;
  2681. for (i = 0; i < page_cnt; i++) {
  2682. if (!pp_virt_addr_tbl[i])
  2683. break;
  2684. dma_free_coherent(&cdev->pdev->dev,
  2685. QED_CHAIN_PAGE_SIZE,
  2686. pp_virt_addr_tbl[i],
  2687. *(dma_addr_t *)p_pbl_virt);
  2688. p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
  2689. }
  2690. pbl_size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
  2691. if (!p_chain->b_external_pbl)
  2692. dma_free_coherent(&cdev->pdev->dev,
  2693. pbl_size,
  2694. p_chain->pbl_sp.p_virt_table,
  2695. p_chain->pbl_sp.p_phys_table);
  2696. out:
  2697. vfree(p_chain->pbl.pp_virt_addr_tbl);
  2698. p_chain->pbl.pp_virt_addr_tbl = NULL;
  2699. }
  2700. void qed_chain_free(struct qed_dev *cdev, struct qed_chain *p_chain)
  2701. {
  2702. switch (p_chain->mode) {
  2703. case QED_CHAIN_MODE_NEXT_PTR:
  2704. qed_chain_free_next_ptr(cdev, p_chain);
  2705. break;
  2706. case QED_CHAIN_MODE_SINGLE:
  2707. qed_chain_free_single(cdev, p_chain);
  2708. break;
  2709. case QED_CHAIN_MODE_PBL:
  2710. qed_chain_free_pbl(cdev, p_chain);
  2711. break;
  2712. }
  2713. }
  2714. static int
  2715. qed_chain_alloc_sanity_check(struct qed_dev *cdev,
  2716. enum qed_chain_cnt_type cnt_type,
  2717. size_t elem_size, u32 page_cnt)
  2718. {
  2719. u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
  2720. /* The actual chain size can be larger than the maximal possible value
  2721. * after rounding up the requested elements number to pages, and after
  2722. * taking into acount the unusuable elements (next-ptr elements).
  2723. * The size of a "u16" chain can be (U16_MAX + 1) since the chain
  2724. * size/capacity fields are of a u32 type.
  2725. */
  2726. if ((cnt_type == QED_CHAIN_CNT_TYPE_U16 &&
  2727. chain_size > ((u32)U16_MAX + 1)) ||
  2728. (cnt_type == QED_CHAIN_CNT_TYPE_U32 && chain_size > U32_MAX)) {
  2729. DP_NOTICE(cdev,
  2730. "The actual chain size (0x%llx) is larger than the maximal possible value\n",
  2731. chain_size);
  2732. return -EINVAL;
  2733. }
  2734. return 0;
  2735. }
  2736. static int
  2737. qed_chain_alloc_next_ptr(struct qed_dev *cdev, struct qed_chain *p_chain)
  2738. {
  2739. void *p_virt = NULL, *p_virt_prev = NULL;
  2740. dma_addr_t p_phys = 0;
  2741. u32 i;
  2742. for (i = 0; i < p_chain->page_cnt; i++) {
  2743. p_virt = dma_alloc_coherent(&cdev->pdev->dev,
  2744. QED_CHAIN_PAGE_SIZE,
  2745. &p_phys, GFP_KERNEL);
  2746. if (!p_virt)
  2747. return -ENOMEM;
  2748. if (i == 0) {
  2749. qed_chain_init_mem(p_chain, p_virt, p_phys);
  2750. qed_chain_reset(p_chain);
  2751. } else {
  2752. qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
  2753. p_virt, p_phys);
  2754. }
  2755. p_virt_prev = p_virt;
  2756. }
  2757. /* Last page's next element should point to the beginning of the
  2758. * chain.
  2759. */
  2760. qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
  2761. p_chain->p_virt_addr,
  2762. p_chain->p_phys_addr);
  2763. return 0;
  2764. }
  2765. static int
  2766. qed_chain_alloc_single(struct qed_dev *cdev, struct qed_chain *p_chain)
  2767. {
  2768. dma_addr_t p_phys = 0;
  2769. void *p_virt = NULL;
  2770. p_virt = dma_alloc_coherent(&cdev->pdev->dev,
  2771. QED_CHAIN_PAGE_SIZE, &p_phys, GFP_KERNEL);
  2772. if (!p_virt)
  2773. return -ENOMEM;
  2774. qed_chain_init_mem(p_chain, p_virt, p_phys);
  2775. qed_chain_reset(p_chain);
  2776. return 0;
  2777. }
  2778. static int
  2779. qed_chain_alloc_pbl(struct qed_dev *cdev,
  2780. struct qed_chain *p_chain,
  2781. struct qed_chain_ext_pbl *ext_pbl)
  2782. {
  2783. u32 page_cnt = p_chain->page_cnt, size, i;
  2784. dma_addr_t p_phys = 0, p_pbl_phys = 0;
  2785. void **pp_virt_addr_tbl = NULL;
  2786. u8 *p_pbl_virt = NULL;
  2787. void *p_virt = NULL;
  2788. size = page_cnt * sizeof(*pp_virt_addr_tbl);
  2789. pp_virt_addr_tbl = vzalloc(size);
  2790. if (!pp_virt_addr_tbl)
  2791. return -ENOMEM;
  2792. /* The allocation of the PBL table is done with its full size, since it
  2793. * is expected to be successive.
  2794. * qed_chain_init_pbl_mem() is called even in a case of an allocation
  2795. * failure, since pp_virt_addr_tbl was previously allocated, and it
  2796. * should be saved to allow its freeing during the error flow.
  2797. */
  2798. size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
  2799. if (!ext_pbl) {
  2800. p_pbl_virt = dma_alloc_coherent(&cdev->pdev->dev,
  2801. size, &p_pbl_phys, GFP_KERNEL);
  2802. } else {
  2803. p_pbl_virt = ext_pbl->p_pbl_virt;
  2804. p_pbl_phys = ext_pbl->p_pbl_phys;
  2805. p_chain->b_external_pbl = true;
  2806. }
  2807. qed_chain_init_pbl_mem(p_chain, p_pbl_virt, p_pbl_phys,
  2808. pp_virt_addr_tbl);
  2809. if (!p_pbl_virt)
  2810. return -ENOMEM;
  2811. for (i = 0; i < page_cnt; i++) {
  2812. p_virt = dma_alloc_coherent(&cdev->pdev->dev,
  2813. QED_CHAIN_PAGE_SIZE,
  2814. &p_phys, GFP_KERNEL);
  2815. if (!p_virt)
  2816. return -ENOMEM;
  2817. if (i == 0) {
  2818. qed_chain_init_mem(p_chain, p_virt, p_phys);
  2819. qed_chain_reset(p_chain);
  2820. }
  2821. /* Fill the PBL table with the physical address of the page */
  2822. *(dma_addr_t *)p_pbl_virt = p_phys;
  2823. /* Keep the virtual address of the page */
  2824. p_chain->pbl.pp_virt_addr_tbl[i] = p_virt;
  2825. p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
  2826. }
  2827. return 0;
  2828. }
  2829. int qed_chain_alloc(struct qed_dev *cdev,
  2830. enum qed_chain_use_mode intended_use,
  2831. enum qed_chain_mode mode,
  2832. enum qed_chain_cnt_type cnt_type,
  2833. u32 num_elems,
  2834. size_t elem_size,
  2835. struct qed_chain *p_chain,
  2836. struct qed_chain_ext_pbl *ext_pbl)
  2837. {
  2838. u32 page_cnt;
  2839. int rc = 0;
  2840. if (mode == QED_CHAIN_MODE_SINGLE)
  2841. page_cnt = 1;
  2842. else
  2843. page_cnt = QED_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
  2844. rc = qed_chain_alloc_sanity_check(cdev, cnt_type, elem_size, page_cnt);
  2845. if (rc) {
  2846. DP_NOTICE(cdev,
  2847. "Cannot allocate a chain with the given arguments:\n");
  2848. DP_NOTICE(cdev,
  2849. "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu]\n",
  2850. intended_use, mode, cnt_type, num_elems, elem_size);
  2851. return rc;
  2852. }
  2853. qed_chain_init_params(p_chain, page_cnt, (u8) elem_size, intended_use,
  2854. mode, cnt_type);
  2855. switch (mode) {
  2856. case QED_CHAIN_MODE_NEXT_PTR:
  2857. rc = qed_chain_alloc_next_ptr(cdev, p_chain);
  2858. break;
  2859. case QED_CHAIN_MODE_SINGLE:
  2860. rc = qed_chain_alloc_single(cdev, p_chain);
  2861. break;
  2862. case QED_CHAIN_MODE_PBL:
  2863. rc = qed_chain_alloc_pbl(cdev, p_chain, ext_pbl);
  2864. break;
  2865. }
  2866. if (rc)
  2867. goto nomem;
  2868. return 0;
  2869. nomem:
  2870. qed_chain_free(cdev, p_chain);
  2871. return rc;
  2872. }
  2873. int qed_fw_l2_queue(struct qed_hwfn *p_hwfn, u16 src_id, u16 *dst_id)
  2874. {
  2875. if (src_id >= RESC_NUM(p_hwfn, QED_L2_QUEUE)) {
  2876. u16 min, max;
  2877. min = (u16) RESC_START(p_hwfn, QED_L2_QUEUE);
  2878. max = min + RESC_NUM(p_hwfn, QED_L2_QUEUE);
  2879. DP_NOTICE(p_hwfn,
  2880. "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
  2881. src_id, min, max);
  2882. return -EINVAL;
  2883. }
  2884. *dst_id = RESC_START(p_hwfn, QED_L2_QUEUE) + src_id;
  2885. return 0;
  2886. }
  2887. int qed_fw_vport(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id)
  2888. {
  2889. if (src_id >= RESC_NUM(p_hwfn, QED_VPORT)) {
  2890. u8 min, max;
  2891. min = (u8)RESC_START(p_hwfn, QED_VPORT);
  2892. max = min + RESC_NUM(p_hwfn, QED_VPORT);
  2893. DP_NOTICE(p_hwfn,
  2894. "vport id [%d] is not valid, available indices [%d - %d]\n",
  2895. src_id, min, max);
  2896. return -EINVAL;
  2897. }
  2898. *dst_id = RESC_START(p_hwfn, QED_VPORT) + src_id;
  2899. return 0;
  2900. }
  2901. int qed_fw_rss_eng(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id)
  2902. {
  2903. if (src_id >= RESC_NUM(p_hwfn, QED_RSS_ENG)) {
  2904. u8 min, max;
  2905. min = (u8)RESC_START(p_hwfn, QED_RSS_ENG);
  2906. max = min + RESC_NUM(p_hwfn, QED_RSS_ENG);
  2907. DP_NOTICE(p_hwfn,
  2908. "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
  2909. src_id, min, max);
  2910. return -EINVAL;
  2911. }
  2912. *dst_id = RESC_START(p_hwfn, QED_RSS_ENG) + src_id;
  2913. return 0;
  2914. }
  2915. static void qed_llh_mac_to_filter(u32 *p_high, u32 *p_low,
  2916. u8 *p_filter)
  2917. {
  2918. *p_high = p_filter[1] | (p_filter[0] << 8);
  2919. *p_low = p_filter[5] | (p_filter[4] << 8) |
  2920. (p_filter[3] << 16) | (p_filter[2] << 24);
  2921. }
  2922. int qed_llh_add_mac_filter(struct qed_hwfn *p_hwfn,
  2923. struct qed_ptt *p_ptt, u8 *p_filter)
  2924. {
  2925. u32 high = 0, low = 0, en;
  2926. int i;
  2927. if (!test_bit(QED_MF_LLH_MAC_CLSS, &p_hwfn->cdev->mf_bits))
  2928. return 0;
  2929. qed_llh_mac_to_filter(&high, &low, p_filter);
  2930. /* Find a free entry and utilize it */
  2931. for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
  2932. en = qed_rd(p_hwfn, p_ptt,
  2933. NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32));
  2934. if (en)
  2935. continue;
  2936. qed_wr(p_hwfn, p_ptt,
  2937. NIG_REG_LLH_FUNC_FILTER_VALUE +
  2938. 2 * i * sizeof(u32), low);
  2939. qed_wr(p_hwfn, p_ptt,
  2940. NIG_REG_LLH_FUNC_FILTER_VALUE +
  2941. (2 * i + 1) * sizeof(u32), high);
  2942. qed_wr(p_hwfn, p_ptt,
  2943. NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 0);
  2944. qed_wr(p_hwfn, p_ptt,
  2945. NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
  2946. i * sizeof(u32), 0);
  2947. qed_wr(p_hwfn, p_ptt,
  2948. NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1);
  2949. break;
  2950. }
  2951. if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) {
  2952. DP_NOTICE(p_hwfn,
  2953. "Failed to find an empty LLH filter to utilize\n");
  2954. return -EINVAL;
  2955. }
  2956. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  2957. "mac: %pM is added at %d\n",
  2958. p_filter, i);
  2959. return 0;
  2960. }
  2961. void qed_llh_remove_mac_filter(struct qed_hwfn *p_hwfn,
  2962. struct qed_ptt *p_ptt, u8 *p_filter)
  2963. {
  2964. u32 high = 0, low = 0;
  2965. int i;
  2966. if (!test_bit(QED_MF_LLH_MAC_CLSS, &p_hwfn->cdev->mf_bits))
  2967. return;
  2968. qed_llh_mac_to_filter(&high, &low, p_filter);
  2969. /* Find the entry and clean it */
  2970. for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
  2971. if (qed_rd(p_hwfn, p_ptt,
  2972. NIG_REG_LLH_FUNC_FILTER_VALUE +
  2973. 2 * i * sizeof(u32)) != low)
  2974. continue;
  2975. if (qed_rd(p_hwfn, p_ptt,
  2976. NIG_REG_LLH_FUNC_FILTER_VALUE +
  2977. (2 * i + 1) * sizeof(u32)) != high)
  2978. continue;
  2979. qed_wr(p_hwfn, p_ptt,
  2980. NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
  2981. qed_wr(p_hwfn, p_ptt,
  2982. NIG_REG_LLH_FUNC_FILTER_VALUE + 2 * i * sizeof(u32), 0);
  2983. qed_wr(p_hwfn, p_ptt,
  2984. NIG_REG_LLH_FUNC_FILTER_VALUE +
  2985. (2 * i + 1) * sizeof(u32), 0);
  2986. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  2987. "mac: %pM is removed from %d\n",
  2988. p_filter, i);
  2989. break;
  2990. }
  2991. if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
  2992. DP_NOTICE(p_hwfn, "Tried to remove a non-configured filter\n");
  2993. }
  2994. int
  2995. qed_llh_add_protocol_filter(struct qed_hwfn *p_hwfn,
  2996. struct qed_ptt *p_ptt,
  2997. u16 source_port_or_eth_type,
  2998. u16 dest_port, enum qed_llh_port_filter_type_t type)
  2999. {
  3000. u32 high = 0, low = 0, en;
  3001. int i;
  3002. if (!test_bit(QED_MF_LLH_PROTO_CLSS, &p_hwfn->cdev->mf_bits))
  3003. return 0;
  3004. switch (type) {
  3005. case QED_LLH_FILTER_ETHERTYPE:
  3006. high = source_port_or_eth_type;
  3007. break;
  3008. case QED_LLH_FILTER_TCP_SRC_PORT:
  3009. case QED_LLH_FILTER_UDP_SRC_PORT:
  3010. low = source_port_or_eth_type << 16;
  3011. break;
  3012. case QED_LLH_FILTER_TCP_DEST_PORT:
  3013. case QED_LLH_FILTER_UDP_DEST_PORT:
  3014. low = dest_port;
  3015. break;
  3016. case QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
  3017. case QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
  3018. low = (source_port_or_eth_type << 16) | dest_port;
  3019. break;
  3020. default:
  3021. DP_NOTICE(p_hwfn,
  3022. "Non valid LLH protocol filter type %d\n", type);
  3023. return -EINVAL;
  3024. }
  3025. /* Find a free entry and utilize it */
  3026. for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
  3027. en = qed_rd(p_hwfn, p_ptt,
  3028. NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32));
  3029. if (en)
  3030. continue;
  3031. qed_wr(p_hwfn, p_ptt,
  3032. NIG_REG_LLH_FUNC_FILTER_VALUE +
  3033. 2 * i * sizeof(u32), low);
  3034. qed_wr(p_hwfn, p_ptt,
  3035. NIG_REG_LLH_FUNC_FILTER_VALUE +
  3036. (2 * i + 1) * sizeof(u32), high);
  3037. qed_wr(p_hwfn, p_ptt,
  3038. NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 1);
  3039. qed_wr(p_hwfn, p_ptt,
  3040. NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
  3041. i * sizeof(u32), 1 << type);
  3042. qed_wr(p_hwfn, p_ptt,
  3043. NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1);
  3044. break;
  3045. }
  3046. if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) {
  3047. DP_NOTICE(p_hwfn,
  3048. "Failed to find an empty LLH filter to utilize\n");
  3049. return -EINVAL;
  3050. }
  3051. switch (type) {
  3052. case QED_LLH_FILTER_ETHERTYPE:
  3053. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  3054. "ETH type %x is added at %d\n",
  3055. source_port_or_eth_type, i);
  3056. break;
  3057. case QED_LLH_FILTER_TCP_SRC_PORT:
  3058. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  3059. "TCP src port %x is added at %d\n",
  3060. source_port_or_eth_type, i);
  3061. break;
  3062. case QED_LLH_FILTER_UDP_SRC_PORT:
  3063. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  3064. "UDP src port %x is added at %d\n",
  3065. source_port_or_eth_type, i);
  3066. break;
  3067. case QED_LLH_FILTER_TCP_DEST_PORT:
  3068. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  3069. "TCP dst port %x is added at %d\n", dest_port, i);
  3070. break;
  3071. case QED_LLH_FILTER_UDP_DEST_PORT:
  3072. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  3073. "UDP dst port %x is added at %d\n", dest_port, i);
  3074. break;
  3075. case QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
  3076. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  3077. "TCP src/dst ports %x/%x are added at %d\n",
  3078. source_port_or_eth_type, dest_port, i);
  3079. break;
  3080. case QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
  3081. DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
  3082. "UDP src/dst ports %x/%x are added at %d\n",
  3083. source_port_or_eth_type, dest_port, i);
  3084. break;
  3085. }
  3086. return 0;
  3087. }
  3088. void
  3089. qed_llh_remove_protocol_filter(struct qed_hwfn *p_hwfn,
  3090. struct qed_ptt *p_ptt,
  3091. u16 source_port_or_eth_type,
  3092. u16 dest_port,
  3093. enum qed_llh_port_filter_type_t type)
  3094. {
  3095. u32 high = 0, low = 0;
  3096. int i;
  3097. if (!test_bit(QED_MF_LLH_PROTO_CLSS, &p_hwfn->cdev->mf_bits))
  3098. return;
  3099. switch (type) {
  3100. case QED_LLH_FILTER_ETHERTYPE:
  3101. high = source_port_or_eth_type;
  3102. break;
  3103. case QED_LLH_FILTER_TCP_SRC_PORT:
  3104. case QED_LLH_FILTER_UDP_SRC_PORT:
  3105. low = source_port_or_eth_type << 16;
  3106. break;
  3107. case QED_LLH_FILTER_TCP_DEST_PORT:
  3108. case QED_LLH_FILTER_UDP_DEST_PORT:
  3109. low = dest_port;
  3110. break;
  3111. case QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
  3112. case QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
  3113. low = (source_port_or_eth_type << 16) | dest_port;
  3114. break;
  3115. default:
  3116. DP_NOTICE(p_hwfn,
  3117. "Non valid LLH protocol filter type %d\n", type);
  3118. return;
  3119. }
  3120. for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
  3121. if (!qed_rd(p_hwfn, p_ptt,
  3122. NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32)))
  3123. continue;
  3124. if (!qed_rd(p_hwfn, p_ptt,
  3125. NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32)))
  3126. continue;
  3127. if (!(qed_rd(p_hwfn, p_ptt,
  3128. NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
  3129. i * sizeof(u32)) & BIT(type)))
  3130. continue;
  3131. if (qed_rd(p_hwfn, p_ptt,
  3132. NIG_REG_LLH_FUNC_FILTER_VALUE +
  3133. 2 * i * sizeof(u32)) != low)
  3134. continue;
  3135. if (qed_rd(p_hwfn, p_ptt,
  3136. NIG_REG_LLH_FUNC_FILTER_VALUE +
  3137. (2 * i + 1) * sizeof(u32)) != high)
  3138. continue;
  3139. qed_wr(p_hwfn, p_ptt,
  3140. NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
  3141. qed_wr(p_hwfn, p_ptt,
  3142. NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 0);
  3143. qed_wr(p_hwfn, p_ptt,
  3144. NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
  3145. i * sizeof(u32), 0);
  3146. qed_wr(p_hwfn, p_ptt,
  3147. NIG_REG_LLH_FUNC_FILTER_VALUE + 2 * i * sizeof(u32), 0);
  3148. qed_wr(p_hwfn, p_ptt,
  3149. NIG_REG_LLH_FUNC_FILTER_VALUE +
  3150. (2 * i + 1) * sizeof(u32), 0);
  3151. break;
  3152. }
  3153. if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
  3154. DP_NOTICE(p_hwfn, "Tried to remove a non-configured filter\n");
  3155. }
  3156. static int qed_set_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  3157. u32 hw_addr, void *p_eth_qzone,
  3158. size_t eth_qzone_size, u8 timeset)
  3159. {
  3160. struct coalescing_timeset *p_coal_timeset;
  3161. if (p_hwfn->cdev->int_coalescing_mode != QED_COAL_MODE_ENABLE) {
  3162. DP_NOTICE(p_hwfn, "Coalescing configuration not enabled\n");
  3163. return -EINVAL;
  3164. }
  3165. p_coal_timeset = p_eth_qzone;
  3166. memset(p_eth_qzone, 0, eth_qzone_size);
  3167. SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_TIMESET, timeset);
  3168. SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_VALID, 1);
  3169. qed_memcpy_to(p_hwfn, p_ptt, hw_addr, p_eth_qzone, eth_qzone_size);
  3170. return 0;
  3171. }
  3172. int qed_set_queue_coalesce(u16 rx_coal, u16 tx_coal, void *p_handle)
  3173. {
  3174. struct qed_queue_cid *p_cid = p_handle;
  3175. struct qed_hwfn *p_hwfn;
  3176. struct qed_ptt *p_ptt;
  3177. int rc = 0;
  3178. p_hwfn = p_cid->p_owner;
  3179. if (IS_VF(p_hwfn->cdev))
  3180. return qed_vf_pf_set_coalesce(p_hwfn, rx_coal, tx_coal, p_cid);
  3181. p_ptt = qed_ptt_acquire(p_hwfn);
  3182. if (!p_ptt)
  3183. return -EAGAIN;
  3184. if (rx_coal) {
  3185. rc = qed_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
  3186. if (rc)
  3187. goto out;
  3188. p_hwfn->cdev->rx_coalesce_usecs = rx_coal;
  3189. }
  3190. if (tx_coal) {
  3191. rc = qed_set_txq_coalesce(p_hwfn, p_ptt, tx_coal, p_cid);
  3192. if (rc)
  3193. goto out;
  3194. p_hwfn->cdev->tx_coalesce_usecs = tx_coal;
  3195. }
  3196. out:
  3197. qed_ptt_release(p_hwfn, p_ptt);
  3198. return rc;
  3199. }
  3200. int qed_set_rxq_coalesce(struct qed_hwfn *p_hwfn,
  3201. struct qed_ptt *p_ptt,
  3202. u16 coalesce, struct qed_queue_cid *p_cid)
  3203. {
  3204. struct ustorm_eth_queue_zone eth_qzone;
  3205. u8 timeset, timer_res;
  3206. u32 address;
  3207. int rc;
  3208. /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
  3209. if (coalesce <= 0x7F) {
  3210. timer_res = 0;
  3211. } else if (coalesce <= 0xFF) {
  3212. timer_res = 1;
  3213. } else if (coalesce <= 0x1FF) {
  3214. timer_res = 2;
  3215. } else {
  3216. DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
  3217. return -EINVAL;
  3218. }
  3219. timeset = (u8)(coalesce >> timer_res);
  3220. rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res,
  3221. p_cid->sb_igu_id, false);
  3222. if (rc)
  3223. goto out;
  3224. address = BAR0_MAP_REG_USDM_RAM +
  3225. USTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
  3226. rc = qed_set_coalesce(p_hwfn, p_ptt, address, &eth_qzone,
  3227. sizeof(struct ustorm_eth_queue_zone), timeset);
  3228. if (rc)
  3229. goto out;
  3230. out:
  3231. return rc;
  3232. }
  3233. int qed_set_txq_coalesce(struct qed_hwfn *p_hwfn,
  3234. struct qed_ptt *p_ptt,
  3235. u16 coalesce, struct qed_queue_cid *p_cid)
  3236. {
  3237. struct xstorm_eth_queue_zone eth_qzone;
  3238. u8 timeset, timer_res;
  3239. u32 address;
  3240. int rc;
  3241. /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
  3242. if (coalesce <= 0x7F) {
  3243. timer_res = 0;
  3244. } else if (coalesce <= 0xFF) {
  3245. timer_res = 1;
  3246. } else if (coalesce <= 0x1FF) {
  3247. timer_res = 2;
  3248. } else {
  3249. DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
  3250. return -EINVAL;
  3251. }
  3252. timeset = (u8)(coalesce >> timer_res);
  3253. rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res,
  3254. p_cid->sb_igu_id, true);
  3255. if (rc)
  3256. goto out;
  3257. address = BAR0_MAP_REG_XSDM_RAM +
  3258. XSTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
  3259. rc = qed_set_coalesce(p_hwfn, p_ptt, address, &eth_qzone,
  3260. sizeof(struct xstorm_eth_queue_zone), timeset);
  3261. out:
  3262. return rc;
  3263. }
  3264. /* Calculate final WFQ values for all vports and configure them.
  3265. * After this configuration each vport will have
  3266. * approx min rate = min_pf_rate * (vport_wfq / QED_WFQ_UNIT)
  3267. */
  3268. static void qed_configure_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
  3269. struct qed_ptt *p_ptt,
  3270. u32 min_pf_rate)
  3271. {
  3272. struct init_qm_vport_params *vport_params;
  3273. int i;
  3274. vport_params = p_hwfn->qm_info.qm_vport_params;
  3275. for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
  3276. u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
  3277. vport_params[i].vport_wfq = (wfq_speed * QED_WFQ_UNIT) /
  3278. min_pf_rate;
  3279. qed_init_vport_wfq(p_hwfn, p_ptt,
  3280. vport_params[i].first_tx_pq_id,
  3281. vport_params[i].vport_wfq);
  3282. }
  3283. }
  3284. static void qed_init_wfq_default_param(struct qed_hwfn *p_hwfn,
  3285. u32 min_pf_rate)
  3286. {
  3287. int i;
  3288. for (i = 0; i < p_hwfn->qm_info.num_vports; i++)
  3289. p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1;
  3290. }
  3291. static void qed_disable_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
  3292. struct qed_ptt *p_ptt,
  3293. u32 min_pf_rate)
  3294. {
  3295. struct init_qm_vport_params *vport_params;
  3296. int i;
  3297. vport_params = p_hwfn->qm_info.qm_vport_params;
  3298. for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
  3299. qed_init_wfq_default_param(p_hwfn, min_pf_rate);
  3300. qed_init_vport_wfq(p_hwfn, p_ptt,
  3301. vport_params[i].first_tx_pq_id,
  3302. vport_params[i].vport_wfq);
  3303. }
  3304. }
  3305. /* This function performs several validations for WFQ
  3306. * configuration and required min rate for a given vport
  3307. * 1. req_rate must be greater than one percent of min_pf_rate.
  3308. * 2. req_rate should not cause other vports [not configured for WFQ explicitly]
  3309. * rates to get less than one percent of min_pf_rate.
  3310. * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate.
  3311. */
  3312. static int qed_init_wfq_param(struct qed_hwfn *p_hwfn,
  3313. u16 vport_id, u32 req_rate, u32 min_pf_rate)
  3314. {
  3315. u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0;
  3316. int non_requested_count = 0, req_count = 0, i, num_vports;
  3317. num_vports = p_hwfn->qm_info.num_vports;
  3318. /* Accounting for the vports which are configured for WFQ explicitly */
  3319. for (i = 0; i < num_vports; i++) {
  3320. u32 tmp_speed;
  3321. if ((i != vport_id) &&
  3322. p_hwfn->qm_info.wfq_data[i].configured) {
  3323. req_count++;
  3324. tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
  3325. total_req_min_rate += tmp_speed;
  3326. }
  3327. }
  3328. /* Include current vport data as well */
  3329. req_count++;
  3330. total_req_min_rate += req_rate;
  3331. non_requested_count = num_vports - req_count;
  3332. if (req_rate < min_pf_rate / QED_WFQ_UNIT) {
  3333. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  3334. "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
  3335. vport_id, req_rate, min_pf_rate);
  3336. return -EINVAL;
  3337. }
  3338. if (num_vports > QED_WFQ_UNIT) {
  3339. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  3340. "Number of vports is greater than %d\n",
  3341. QED_WFQ_UNIT);
  3342. return -EINVAL;
  3343. }
  3344. if (total_req_min_rate > min_pf_rate) {
  3345. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  3346. "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
  3347. total_req_min_rate, min_pf_rate);
  3348. return -EINVAL;
  3349. }
  3350. total_left_rate = min_pf_rate - total_req_min_rate;
  3351. left_rate_per_vp = total_left_rate / non_requested_count;
  3352. if (left_rate_per_vp < min_pf_rate / QED_WFQ_UNIT) {
  3353. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  3354. "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
  3355. left_rate_per_vp, min_pf_rate);
  3356. return -EINVAL;
  3357. }
  3358. p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate;
  3359. p_hwfn->qm_info.wfq_data[vport_id].configured = true;
  3360. for (i = 0; i < num_vports; i++) {
  3361. if (p_hwfn->qm_info.wfq_data[i].configured)
  3362. continue;
  3363. p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp;
  3364. }
  3365. return 0;
  3366. }
  3367. static int __qed_configure_vport_wfq(struct qed_hwfn *p_hwfn,
  3368. struct qed_ptt *p_ptt, u16 vp_id, u32 rate)
  3369. {
  3370. struct qed_mcp_link_state *p_link;
  3371. int rc = 0;
  3372. p_link = &p_hwfn->cdev->hwfns[0].mcp_info->link_output;
  3373. if (!p_link->min_pf_rate) {
  3374. p_hwfn->qm_info.wfq_data[vp_id].min_speed = rate;
  3375. p_hwfn->qm_info.wfq_data[vp_id].configured = true;
  3376. return rc;
  3377. }
  3378. rc = qed_init_wfq_param(p_hwfn, vp_id, rate, p_link->min_pf_rate);
  3379. if (!rc)
  3380. qed_configure_wfq_for_all_vports(p_hwfn, p_ptt,
  3381. p_link->min_pf_rate);
  3382. else
  3383. DP_NOTICE(p_hwfn,
  3384. "Validation failed while configuring min rate\n");
  3385. return rc;
  3386. }
  3387. static int __qed_configure_vp_wfq_on_link_change(struct qed_hwfn *p_hwfn,
  3388. struct qed_ptt *p_ptt,
  3389. u32 min_pf_rate)
  3390. {
  3391. bool use_wfq = false;
  3392. int rc = 0;
  3393. u16 i;
  3394. /* Validate all pre configured vports for wfq */
  3395. for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
  3396. u32 rate;
  3397. if (!p_hwfn->qm_info.wfq_data[i].configured)
  3398. continue;
  3399. rate = p_hwfn->qm_info.wfq_data[i].min_speed;
  3400. use_wfq = true;
  3401. rc = qed_init_wfq_param(p_hwfn, i, rate, min_pf_rate);
  3402. if (rc) {
  3403. DP_NOTICE(p_hwfn,
  3404. "WFQ validation failed while configuring min rate\n");
  3405. break;
  3406. }
  3407. }
  3408. if (!rc && use_wfq)
  3409. qed_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
  3410. else
  3411. qed_disable_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
  3412. return rc;
  3413. }
  3414. /* Main API for qed clients to configure vport min rate.
  3415. * vp_id - vport id in PF Range[0 - (total_num_vports_per_pf - 1)]
  3416. * rate - Speed in Mbps needs to be assigned to a given vport.
  3417. */
  3418. int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate)
  3419. {
  3420. int i, rc = -EINVAL;
  3421. /* Currently not supported; Might change in future */
  3422. if (cdev->num_hwfns > 1) {
  3423. DP_NOTICE(cdev,
  3424. "WFQ configuration is not supported for this device\n");
  3425. return rc;
  3426. }
  3427. for_each_hwfn(cdev, i) {
  3428. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  3429. struct qed_ptt *p_ptt;
  3430. p_ptt = qed_ptt_acquire(p_hwfn);
  3431. if (!p_ptt)
  3432. return -EBUSY;
  3433. rc = __qed_configure_vport_wfq(p_hwfn, p_ptt, vp_id, rate);
  3434. if (rc) {
  3435. qed_ptt_release(p_hwfn, p_ptt);
  3436. return rc;
  3437. }
  3438. qed_ptt_release(p_hwfn, p_ptt);
  3439. }
  3440. return rc;
  3441. }
  3442. /* API to configure WFQ from mcp link change */
  3443. void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev,
  3444. struct qed_ptt *p_ptt, u32 min_pf_rate)
  3445. {
  3446. int i;
  3447. if (cdev->num_hwfns > 1) {
  3448. DP_VERBOSE(cdev,
  3449. NETIF_MSG_LINK,
  3450. "WFQ configuration is not supported for this device\n");
  3451. return;
  3452. }
  3453. for_each_hwfn(cdev, i) {
  3454. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  3455. __qed_configure_vp_wfq_on_link_change(p_hwfn, p_ptt,
  3456. min_pf_rate);
  3457. }
  3458. }
  3459. int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
  3460. struct qed_ptt *p_ptt,
  3461. struct qed_mcp_link_state *p_link,
  3462. u8 max_bw)
  3463. {
  3464. int rc = 0;
  3465. p_hwfn->mcp_info->func_info.bandwidth_max = max_bw;
  3466. if (!p_link->line_speed && (max_bw != 100))
  3467. return rc;
  3468. p_link->speed = (p_link->line_speed * max_bw) / 100;
  3469. p_hwfn->qm_info.pf_rl = p_link->speed;
  3470. /* Since the limiter also affects Tx-switched traffic, we don't want it
  3471. * to limit such traffic in case there's no actual limit.
  3472. * In that case, set limit to imaginary high boundary.
  3473. */
  3474. if (max_bw == 100)
  3475. p_hwfn->qm_info.pf_rl = 100000;
  3476. rc = qed_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
  3477. p_hwfn->qm_info.pf_rl);
  3478. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  3479. "Configured MAX bandwidth to be %08x Mb/sec\n",
  3480. p_link->speed);
  3481. return rc;
  3482. }
  3483. /* Main API to configure PF max bandwidth where bw range is [1 - 100] */
  3484. int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw)
  3485. {
  3486. int i, rc = -EINVAL;
  3487. if (max_bw < 1 || max_bw > 100) {
  3488. DP_NOTICE(cdev, "PF max bw valid range is [1-100]\n");
  3489. return rc;
  3490. }
  3491. for_each_hwfn(cdev, i) {
  3492. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  3493. struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
  3494. struct qed_mcp_link_state *p_link;
  3495. struct qed_ptt *p_ptt;
  3496. p_link = &p_lead->mcp_info->link_output;
  3497. p_ptt = qed_ptt_acquire(p_hwfn);
  3498. if (!p_ptt)
  3499. return -EBUSY;
  3500. rc = __qed_configure_pf_max_bandwidth(p_hwfn, p_ptt,
  3501. p_link, max_bw);
  3502. qed_ptt_release(p_hwfn, p_ptt);
  3503. if (rc)
  3504. break;
  3505. }
  3506. return rc;
  3507. }
  3508. int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
  3509. struct qed_ptt *p_ptt,
  3510. struct qed_mcp_link_state *p_link,
  3511. u8 min_bw)
  3512. {
  3513. int rc = 0;
  3514. p_hwfn->mcp_info->func_info.bandwidth_min = min_bw;
  3515. p_hwfn->qm_info.pf_wfq = min_bw;
  3516. if (!p_link->line_speed)
  3517. return rc;
  3518. p_link->min_pf_rate = (p_link->line_speed * min_bw) / 100;
  3519. rc = qed_init_pf_wfq(p_hwfn, p_ptt, p_hwfn->rel_pf_id, min_bw);
  3520. DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
  3521. "Configured MIN bandwidth to be %d Mb/sec\n",
  3522. p_link->min_pf_rate);
  3523. return rc;
  3524. }
  3525. /* Main API to configure PF min bandwidth where bw range is [1-100] */
  3526. int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw)
  3527. {
  3528. int i, rc = -EINVAL;
  3529. if (min_bw < 1 || min_bw > 100) {
  3530. DP_NOTICE(cdev, "PF min bw valid range is [1-100]\n");
  3531. return rc;
  3532. }
  3533. for_each_hwfn(cdev, i) {
  3534. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  3535. struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
  3536. struct qed_mcp_link_state *p_link;
  3537. struct qed_ptt *p_ptt;
  3538. p_link = &p_lead->mcp_info->link_output;
  3539. p_ptt = qed_ptt_acquire(p_hwfn);
  3540. if (!p_ptt)
  3541. return -EBUSY;
  3542. rc = __qed_configure_pf_min_bandwidth(p_hwfn, p_ptt,
  3543. p_link, min_bw);
  3544. if (rc) {
  3545. qed_ptt_release(p_hwfn, p_ptt);
  3546. return rc;
  3547. }
  3548. if (p_link->min_pf_rate) {
  3549. u32 min_rate = p_link->min_pf_rate;
  3550. rc = __qed_configure_vp_wfq_on_link_change(p_hwfn,
  3551. p_ptt,
  3552. min_rate);
  3553. }
  3554. qed_ptt_release(p_hwfn, p_ptt);
  3555. }
  3556. return rc;
  3557. }
  3558. void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  3559. {
  3560. struct qed_mcp_link_state *p_link;
  3561. p_link = &p_hwfn->mcp_info->link_output;
  3562. if (p_link->min_pf_rate)
  3563. qed_disable_wfq_for_all_vports(p_hwfn, p_ptt,
  3564. p_link->min_pf_rate);
  3565. memset(p_hwfn->qm_info.wfq_data, 0,
  3566. sizeof(*p_hwfn->qm_info.wfq_data) * p_hwfn->qm_info.num_vports);
  3567. }
  3568. int qed_device_num_engines(struct qed_dev *cdev)
  3569. {
  3570. return QED_IS_BB(cdev) ? 2 : 1;
  3571. }
  3572. static int qed_device_num_ports(struct qed_dev *cdev)
  3573. {
  3574. /* in CMT always only one port */
  3575. if (cdev->num_hwfns > 1)
  3576. return 1;
  3577. return cdev->num_ports_in_engine * qed_device_num_engines(cdev);
  3578. }
  3579. int qed_device_get_port_id(struct qed_dev *cdev)
  3580. {
  3581. return (QED_LEADING_HWFN(cdev)->abs_pf_id) % qed_device_num_ports(cdev);
  3582. }
  3583. void qed_set_fw_mac_addr(__le16 *fw_msb,
  3584. __le16 *fw_mid, __le16 *fw_lsb, u8 *mac)
  3585. {
  3586. ((u8 *)fw_msb)[0] = mac[1];
  3587. ((u8 *)fw_msb)[1] = mac[0];
  3588. ((u8 *)fw_mid)[0] = mac[3];
  3589. ((u8 *)fw_mid)[1] = mac[2];
  3590. ((u8 *)fw_lsb)[0] = mac[5];
  3591. ((u8 *)fw_lsb)[1] = mac[4];
  3592. }