qed_dev.c 107 KB

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