qed_dev.c 111 KB

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