qed_dev.c 112 KB

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