qed_dev.c 107 KB

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