bnx2x_sp.c 140 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333
  1. /* bnx2x_sp.c: Broadcom Everest network driver.
  2. *
  3. * Copyright 2011 Broadcom Corporation
  4. *
  5. * Unless you and Broadcom execute a separate written software license
  6. * agreement governing use of this software, this software is licensed to you
  7. * under the terms of the GNU General Public License version 2, available
  8. * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
  9. *
  10. * Notwithstanding the above, under no circumstances may you combine this
  11. * software in any way with any other Broadcom software provided under a
  12. * license other than the GPL, without Broadcom's express prior written
  13. * consent.
  14. *
  15. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  16. * Written by: Vladislav Zolotarov
  17. *
  18. */
  19. #include <linux/version.h>
  20. #include <linux/module.h>
  21. #include <linux/crc32.h>
  22. #include <linux/netdevice.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/crc32c.h>
  25. #include "bnx2x.h"
  26. #include "bnx2x_cmn.h"
  27. #include "bnx2x_sp.h"
  28. #define BNX2X_MAX_EMUL_MULTI 16
  29. /**** Exe Queue interfaces ****/
  30. /**
  31. * bnx2x_exe_queue_init - init the Exe Queue object
  32. *
  33. * @o: poiter to the object
  34. * @exe_len: length
  35. * @owner: poiter to the owner
  36. * @validate: validate function pointer
  37. * @optimize: optimize function pointer
  38. * @exec: execute function pointer
  39. * @get: get function pointer
  40. */
  41. static inline void bnx2x_exe_queue_init(struct bnx2x *bp,
  42. struct bnx2x_exe_queue_obj *o,
  43. int exe_len,
  44. union bnx2x_qable_obj *owner,
  45. exe_q_validate validate,
  46. exe_q_optimize optimize,
  47. exe_q_execute exec,
  48. exe_q_get get)
  49. {
  50. memset(o, 0, sizeof(*o));
  51. INIT_LIST_HEAD(&o->exe_queue);
  52. INIT_LIST_HEAD(&o->pending_comp);
  53. spin_lock_init(&o->lock);
  54. o->exe_chunk_len = exe_len;
  55. o->owner = owner;
  56. /* Owner specific callbacks */
  57. o->validate = validate;
  58. o->optimize = optimize;
  59. o->execute = exec;
  60. o->get = get;
  61. DP(BNX2X_MSG_SP, "Setup the execution queue with the chunk "
  62. "length of %d\n", exe_len);
  63. }
  64. static inline void bnx2x_exe_queue_free_elem(struct bnx2x *bp,
  65. struct bnx2x_exeq_elem *elem)
  66. {
  67. DP(BNX2X_MSG_SP, "Deleting an exe_queue element\n");
  68. kfree(elem);
  69. }
  70. static inline int bnx2x_exe_queue_length(struct bnx2x_exe_queue_obj *o)
  71. {
  72. struct bnx2x_exeq_elem *elem;
  73. int cnt = 0;
  74. spin_lock_bh(&o->lock);
  75. list_for_each_entry(elem, &o->exe_queue, link)
  76. cnt++;
  77. spin_unlock_bh(&o->lock);
  78. return cnt;
  79. }
  80. /**
  81. * bnx2x_exe_queue_add - add a new element to the execution queue
  82. *
  83. * @bp: driver handle
  84. * @o: queue
  85. * @cmd: new command to add
  86. * @restore: true - do not optimize the command
  87. *
  88. * If the element is optimized or is illegal, frees it.
  89. */
  90. static inline int bnx2x_exe_queue_add(struct bnx2x *bp,
  91. struct bnx2x_exe_queue_obj *o,
  92. struct bnx2x_exeq_elem *elem,
  93. bool restore)
  94. {
  95. int rc;
  96. spin_lock_bh(&o->lock);
  97. if (!restore) {
  98. /* Try to cancel this element queue */
  99. rc = o->optimize(bp, o->owner, elem);
  100. if (rc)
  101. goto free_and_exit;
  102. /* Check if this request is ok */
  103. rc = o->validate(bp, o->owner, elem);
  104. if (rc) {
  105. BNX2X_ERR("Preamble failed: %d\n", rc);
  106. goto free_and_exit;
  107. }
  108. }
  109. /* If so, add it to the execution queue */
  110. list_add_tail(&elem->link, &o->exe_queue);
  111. spin_unlock_bh(&o->lock);
  112. return 0;
  113. free_and_exit:
  114. bnx2x_exe_queue_free_elem(bp, elem);
  115. spin_unlock_bh(&o->lock);
  116. return rc;
  117. }
  118. static inline void __bnx2x_exe_queue_reset_pending(
  119. struct bnx2x *bp,
  120. struct bnx2x_exe_queue_obj *o)
  121. {
  122. struct bnx2x_exeq_elem *elem;
  123. while (!list_empty(&o->pending_comp)) {
  124. elem = list_first_entry(&o->pending_comp,
  125. struct bnx2x_exeq_elem, link);
  126. list_del(&elem->link);
  127. bnx2x_exe_queue_free_elem(bp, elem);
  128. }
  129. }
  130. static inline void bnx2x_exe_queue_reset_pending(struct bnx2x *bp,
  131. struct bnx2x_exe_queue_obj *o)
  132. {
  133. spin_lock_bh(&o->lock);
  134. __bnx2x_exe_queue_reset_pending(bp, o);
  135. spin_unlock_bh(&o->lock);
  136. }
  137. /**
  138. * bnx2x_exe_queue_step - execute one execution chunk atomically
  139. *
  140. * @bp: driver handle
  141. * @o: queue
  142. * @ramrod_flags: flags
  143. *
  144. * (Atomicy is ensured using the exe_queue->lock).
  145. */
  146. static inline int bnx2x_exe_queue_step(struct bnx2x *bp,
  147. struct bnx2x_exe_queue_obj *o,
  148. unsigned long *ramrod_flags)
  149. {
  150. struct bnx2x_exeq_elem *elem, spacer;
  151. int cur_len = 0, rc;
  152. memset(&spacer, 0, sizeof(spacer));
  153. spin_lock_bh(&o->lock);
  154. /*
  155. * Next step should not be performed until the current is finished,
  156. * unless a DRV_CLEAR_ONLY bit is set. In this case we just want to
  157. * properly clear object internals without sending any command to the FW
  158. * which also implies there won't be any completion to clear the
  159. * 'pending' list.
  160. */
  161. if (!list_empty(&o->pending_comp)) {
  162. if (test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags)) {
  163. DP(BNX2X_MSG_SP, "RAMROD_DRV_CLR_ONLY requested: "
  164. "resetting pending_comp\n");
  165. __bnx2x_exe_queue_reset_pending(bp, o);
  166. } else {
  167. spin_unlock_bh(&o->lock);
  168. return 1;
  169. }
  170. }
  171. /*
  172. * Run through the pending commands list and create a next
  173. * execution chunk.
  174. */
  175. while (!list_empty(&o->exe_queue)) {
  176. elem = list_first_entry(&o->exe_queue, struct bnx2x_exeq_elem,
  177. link);
  178. WARN_ON(!elem->cmd_len);
  179. if (cur_len + elem->cmd_len <= o->exe_chunk_len) {
  180. cur_len += elem->cmd_len;
  181. /*
  182. * Prevent from both lists being empty when moving an
  183. * element. This will allow the call of
  184. * bnx2x_exe_queue_empty() without locking.
  185. */
  186. list_add_tail(&spacer.link, &o->pending_comp);
  187. mb();
  188. list_del(&elem->link);
  189. list_add_tail(&elem->link, &o->pending_comp);
  190. list_del(&spacer.link);
  191. } else
  192. break;
  193. }
  194. /* Sanity check */
  195. if (!cur_len) {
  196. spin_unlock_bh(&o->lock);
  197. return 0;
  198. }
  199. rc = o->execute(bp, o->owner, &o->pending_comp, ramrod_flags);
  200. if (rc < 0)
  201. /*
  202. * In case of an error return the commands back to the queue
  203. * and reset the pending_comp.
  204. */
  205. list_splice_init(&o->pending_comp, &o->exe_queue);
  206. else if (!rc)
  207. /*
  208. * If zero is returned, means there are no outstanding pending
  209. * completions and we may dismiss the pending list.
  210. */
  211. __bnx2x_exe_queue_reset_pending(bp, o);
  212. spin_unlock_bh(&o->lock);
  213. return rc;
  214. }
  215. static inline bool bnx2x_exe_queue_empty(struct bnx2x_exe_queue_obj *o)
  216. {
  217. bool empty = list_empty(&o->exe_queue);
  218. /* Don't reorder!!! */
  219. mb();
  220. return empty && list_empty(&o->pending_comp);
  221. }
  222. static inline struct bnx2x_exeq_elem *bnx2x_exe_queue_alloc_elem(
  223. struct bnx2x *bp)
  224. {
  225. DP(BNX2X_MSG_SP, "Allocating a new exe_queue element\n");
  226. return kzalloc(sizeof(struct bnx2x_exeq_elem), GFP_ATOMIC);
  227. }
  228. /************************ raw_obj functions ***********************************/
  229. static bool bnx2x_raw_check_pending(struct bnx2x_raw_obj *o)
  230. {
  231. return !!test_bit(o->state, o->pstate);
  232. }
  233. static void bnx2x_raw_clear_pending(struct bnx2x_raw_obj *o)
  234. {
  235. smp_mb__before_clear_bit();
  236. clear_bit(o->state, o->pstate);
  237. smp_mb__after_clear_bit();
  238. }
  239. static void bnx2x_raw_set_pending(struct bnx2x_raw_obj *o)
  240. {
  241. smp_mb__before_clear_bit();
  242. set_bit(o->state, o->pstate);
  243. smp_mb__after_clear_bit();
  244. }
  245. /**
  246. * bnx2x_state_wait - wait until the given bit(state) is cleared
  247. *
  248. * @bp: device handle
  249. * @state: state which is to be cleared
  250. * @state_p: state buffer
  251. *
  252. */
  253. static inline int bnx2x_state_wait(struct bnx2x *bp, int state,
  254. unsigned long *pstate)
  255. {
  256. /* can take a while if any port is running */
  257. int cnt = 5000;
  258. if (CHIP_REV_IS_EMUL(bp))
  259. cnt *= 20;
  260. DP(BNX2X_MSG_SP, "waiting for state to become %d\n", state);
  261. might_sleep();
  262. while (cnt--) {
  263. if (!test_bit(state, pstate)) {
  264. #ifdef BNX2X_STOP_ON_ERROR
  265. DP(BNX2X_MSG_SP, "exit (cnt %d)\n", 5000 - cnt);
  266. #endif
  267. return 0;
  268. }
  269. usleep_range(1000, 1000);
  270. if (bp->panic)
  271. return -EIO;
  272. }
  273. /* timeout! */
  274. BNX2X_ERR("timeout waiting for state %d\n", state);
  275. #ifdef BNX2X_STOP_ON_ERROR
  276. bnx2x_panic();
  277. #endif
  278. return -EBUSY;
  279. }
  280. static int bnx2x_raw_wait(struct bnx2x *bp, struct bnx2x_raw_obj *raw)
  281. {
  282. return bnx2x_state_wait(bp, raw->state, raw->pstate);
  283. }
  284. /***************** Classification verbs: Set/Del MAC/VLAN/VLAN-MAC ************/
  285. /* credit handling callbacks */
  286. static bool bnx2x_get_cam_offset_mac(struct bnx2x_vlan_mac_obj *o, int *offset)
  287. {
  288. struct bnx2x_credit_pool_obj *mp = o->macs_pool;
  289. WARN_ON(!mp);
  290. return mp->get_entry(mp, offset);
  291. }
  292. static bool bnx2x_get_credit_mac(struct bnx2x_vlan_mac_obj *o)
  293. {
  294. struct bnx2x_credit_pool_obj *mp = o->macs_pool;
  295. WARN_ON(!mp);
  296. return mp->get(mp, 1);
  297. }
  298. static bool bnx2x_get_cam_offset_vlan(struct bnx2x_vlan_mac_obj *o, int *offset)
  299. {
  300. struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
  301. WARN_ON(!vp);
  302. return vp->get_entry(vp, offset);
  303. }
  304. static bool bnx2x_get_credit_vlan(struct bnx2x_vlan_mac_obj *o)
  305. {
  306. struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
  307. WARN_ON(!vp);
  308. return vp->get(vp, 1);
  309. }
  310. static bool bnx2x_get_credit_vlan_mac(struct bnx2x_vlan_mac_obj *o)
  311. {
  312. struct bnx2x_credit_pool_obj *mp = o->macs_pool;
  313. struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
  314. if (!mp->get(mp, 1))
  315. return false;
  316. if (!vp->get(vp, 1)) {
  317. mp->put(mp, 1);
  318. return false;
  319. }
  320. return true;
  321. }
  322. static bool bnx2x_put_cam_offset_mac(struct bnx2x_vlan_mac_obj *o, int offset)
  323. {
  324. struct bnx2x_credit_pool_obj *mp = o->macs_pool;
  325. return mp->put_entry(mp, offset);
  326. }
  327. static bool bnx2x_put_credit_mac(struct bnx2x_vlan_mac_obj *o)
  328. {
  329. struct bnx2x_credit_pool_obj *mp = o->macs_pool;
  330. return mp->put(mp, 1);
  331. }
  332. static bool bnx2x_put_cam_offset_vlan(struct bnx2x_vlan_mac_obj *o, int offset)
  333. {
  334. struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
  335. return vp->put_entry(vp, offset);
  336. }
  337. static bool bnx2x_put_credit_vlan(struct bnx2x_vlan_mac_obj *o)
  338. {
  339. struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
  340. return vp->put(vp, 1);
  341. }
  342. static bool bnx2x_put_credit_vlan_mac(struct bnx2x_vlan_mac_obj *o)
  343. {
  344. struct bnx2x_credit_pool_obj *mp = o->macs_pool;
  345. struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
  346. if (!mp->put(mp, 1))
  347. return false;
  348. if (!vp->put(vp, 1)) {
  349. mp->get(mp, 1);
  350. return false;
  351. }
  352. return true;
  353. }
  354. /* check_add() callbacks */
  355. static int bnx2x_check_mac_add(struct bnx2x_vlan_mac_obj *o,
  356. union bnx2x_classification_ramrod_data *data)
  357. {
  358. struct bnx2x_vlan_mac_registry_elem *pos;
  359. if (!is_valid_ether_addr(data->mac.mac))
  360. return -EINVAL;
  361. /* Check if a requested MAC already exists */
  362. list_for_each_entry(pos, &o->head, link)
  363. if (!memcmp(data->mac.mac, pos->u.mac.mac, ETH_ALEN))
  364. return -EEXIST;
  365. return 0;
  366. }
  367. static int bnx2x_check_vlan_add(struct bnx2x_vlan_mac_obj *o,
  368. union bnx2x_classification_ramrod_data *data)
  369. {
  370. struct bnx2x_vlan_mac_registry_elem *pos;
  371. list_for_each_entry(pos, &o->head, link)
  372. if (data->vlan.vlan == pos->u.vlan.vlan)
  373. return -EEXIST;
  374. return 0;
  375. }
  376. static int bnx2x_check_vlan_mac_add(struct bnx2x_vlan_mac_obj *o,
  377. union bnx2x_classification_ramrod_data *data)
  378. {
  379. struct bnx2x_vlan_mac_registry_elem *pos;
  380. list_for_each_entry(pos, &o->head, link)
  381. if ((data->vlan_mac.vlan == pos->u.vlan_mac.vlan) &&
  382. (!memcmp(data->vlan_mac.mac, pos->u.vlan_mac.mac,
  383. ETH_ALEN)))
  384. return -EEXIST;
  385. return 0;
  386. }
  387. /* check_del() callbacks */
  388. static struct bnx2x_vlan_mac_registry_elem *
  389. bnx2x_check_mac_del(struct bnx2x_vlan_mac_obj *o,
  390. union bnx2x_classification_ramrod_data *data)
  391. {
  392. struct bnx2x_vlan_mac_registry_elem *pos;
  393. list_for_each_entry(pos, &o->head, link)
  394. if (!memcmp(data->mac.mac, pos->u.mac.mac, ETH_ALEN))
  395. return pos;
  396. return NULL;
  397. }
  398. static struct bnx2x_vlan_mac_registry_elem *
  399. bnx2x_check_vlan_del(struct bnx2x_vlan_mac_obj *o,
  400. union bnx2x_classification_ramrod_data *data)
  401. {
  402. struct bnx2x_vlan_mac_registry_elem *pos;
  403. list_for_each_entry(pos, &o->head, link)
  404. if (data->vlan.vlan == pos->u.vlan.vlan)
  405. return pos;
  406. return NULL;
  407. }
  408. static struct bnx2x_vlan_mac_registry_elem *
  409. bnx2x_check_vlan_mac_del(struct bnx2x_vlan_mac_obj *o,
  410. union bnx2x_classification_ramrod_data *data)
  411. {
  412. struct bnx2x_vlan_mac_registry_elem *pos;
  413. list_for_each_entry(pos, &o->head, link)
  414. if ((data->vlan_mac.vlan == pos->u.vlan_mac.vlan) &&
  415. (!memcmp(data->vlan_mac.mac, pos->u.vlan_mac.mac,
  416. ETH_ALEN)))
  417. return pos;
  418. return NULL;
  419. }
  420. /* check_move() callback */
  421. static bool bnx2x_check_move(struct bnx2x_vlan_mac_obj *src_o,
  422. struct bnx2x_vlan_mac_obj *dst_o,
  423. union bnx2x_classification_ramrod_data *data)
  424. {
  425. struct bnx2x_vlan_mac_registry_elem *pos;
  426. int rc;
  427. /* Check if we can delete the requested configuration from the first
  428. * object.
  429. */
  430. pos = src_o->check_del(src_o, data);
  431. /* check if configuration can be added */
  432. rc = dst_o->check_add(dst_o, data);
  433. /* If this classification can not be added (is already set)
  434. * or can't be deleted - return an error.
  435. */
  436. if (rc || !pos)
  437. return false;
  438. return true;
  439. }
  440. static bool bnx2x_check_move_always_err(
  441. struct bnx2x_vlan_mac_obj *src_o,
  442. struct bnx2x_vlan_mac_obj *dst_o,
  443. union bnx2x_classification_ramrod_data *data)
  444. {
  445. return false;
  446. }
  447. static inline u8 bnx2x_vlan_mac_get_rx_tx_flag(struct bnx2x_vlan_mac_obj *o)
  448. {
  449. struct bnx2x_raw_obj *raw = &o->raw;
  450. u8 rx_tx_flag = 0;
  451. if ((raw->obj_type == BNX2X_OBJ_TYPE_TX) ||
  452. (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
  453. rx_tx_flag |= ETH_CLASSIFY_CMD_HEADER_TX_CMD;
  454. if ((raw->obj_type == BNX2X_OBJ_TYPE_RX) ||
  455. (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
  456. rx_tx_flag |= ETH_CLASSIFY_CMD_HEADER_RX_CMD;
  457. return rx_tx_flag;
  458. }
  459. /* LLH CAM line allocations */
  460. enum {
  461. LLH_CAM_ISCSI_ETH_LINE = 0,
  462. LLH_CAM_ETH_LINE,
  463. LLH_CAM_MAX_PF_LINE = NIG_REG_LLH1_FUNC_MEM_SIZE / 2
  464. };
  465. static inline void bnx2x_set_mac_in_nig(struct bnx2x *bp,
  466. bool add, unsigned char *dev_addr, int index)
  467. {
  468. u32 wb_data[2];
  469. u32 reg_offset = BP_PORT(bp) ? NIG_REG_LLH1_FUNC_MEM :
  470. NIG_REG_LLH0_FUNC_MEM;
  471. if (!IS_MF_SI(bp) || index > LLH_CAM_MAX_PF_LINE)
  472. return;
  473. DP(BNX2X_MSG_SP, "Going to %s LLH configuration at entry %d\n",
  474. (add ? "ADD" : "DELETE"), index);
  475. if (add) {
  476. /* LLH_FUNC_MEM is a u64 WB register */
  477. reg_offset += 8*index;
  478. wb_data[0] = ((dev_addr[2] << 24) | (dev_addr[3] << 16) |
  479. (dev_addr[4] << 8) | dev_addr[5]);
  480. wb_data[1] = ((dev_addr[0] << 8) | dev_addr[1]);
  481. REG_WR_DMAE(bp, reg_offset, wb_data, 2);
  482. }
  483. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_FUNC_MEM_ENABLE :
  484. NIG_REG_LLH0_FUNC_MEM_ENABLE) + 4*index, add);
  485. }
  486. /**
  487. * bnx2x_vlan_mac_set_cmd_hdr_e2 - set a header in a single classify ramrod
  488. *
  489. * @bp: device handle
  490. * @o: queue for which we want to configure this rule
  491. * @add: if true the command is an ADD command, DEL otherwise
  492. * @opcode: CLASSIFY_RULE_OPCODE_XXX
  493. * @hdr: pointer to a header to setup
  494. *
  495. */
  496. static inline void bnx2x_vlan_mac_set_cmd_hdr_e2(struct bnx2x *bp,
  497. struct bnx2x_vlan_mac_obj *o, bool add, int opcode,
  498. struct eth_classify_cmd_header *hdr)
  499. {
  500. struct bnx2x_raw_obj *raw = &o->raw;
  501. hdr->client_id = raw->cl_id;
  502. hdr->func_id = raw->func_id;
  503. /* Rx or/and Tx (internal switching) configuration ? */
  504. hdr->cmd_general_data |=
  505. bnx2x_vlan_mac_get_rx_tx_flag(o);
  506. if (add)
  507. hdr->cmd_general_data |= ETH_CLASSIFY_CMD_HEADER_IS_ADD;
  508. hdr->cmd_general_data |=
  509. (opcode << ETH_CLASSIFY_CMD_HEADER_OPCODE_SHIFT);
  510. }
  511. /**
  512. * bnx2x_vlan_mac_set_rdata_hdr_e2 - set the classify ramrod data header
  513. *
  514. * @cid: connection id
  515. * @type: BNX2X_FILTER_XXX_PENDING
  516. * @hdr: poiter to header to setup
  517. * @rule_cnt:
  518. *
  519. * currently we always configure one rule and echo field to contain a CID and an
  520. * opcode type.
  521. */
  522. static inline void bnx2x_vlan_mac_set_rdata_hdr_e2(u32 cid, int type,
  523. struct eth_classify_header *hdr, int rule_cnt)
  524. {
  525. hdr->echo = (cid & BNX2X_SWCID_MASK) | (type << BNX2X_SWCID_SHIFT);
  526. hdr->rule_cnt = (u8)rule_cnt;
  527. }
  528. /* hw_config() callbacks */
  529. static void bnx2x_set_one_mac_e2(struct bnx2x *bp,
  530. struct bnx2x_vlan_mac_obj *o,
  531. struct bnx2x_exeq_elem *elem, int rule_idx,
  532. int cam_offset)
  533. {
  534. struct bnx2x_raw_obj *raw = &o->raw;
  535. struct eth_classify_rules_ramrod_data *data =
  536. (struct eth_classify_rules_ramrod_data *)(raw->rdata);
  537. int rule_cnt = rule_idx + 1, cmd = elem->cmd_data.vlan_mac.cmd;
  538. union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
  539. bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
  540. unsigned long *vlan_mac_flags = &elem->cmd_data.vlan_mac.vlan_mac_flags;
  541. u8 *mac = elem->cmd_data.vlan_mac.u.mac.mac;
  542. /*
  543. * Set LLH CAM entry: currently only iSCSI and ETH macs are
  544. * relevant. In addition, current implementation is tuned for a
  545. * single ETH MAC.
  546. *
  547. * When multiple unicast ETH MACs PF configuration in switch
  548. * independent mode is required (NetQ, multiple netdev MACs,
  549. * etc.), consider better utilisation of 8 per function MAC
  550. * entries in the LLH register. There is also
  551. * NIG_REG_P[01]_LLH_FUNC_MEM2 registers that complete the
  552. * total number of CAM entries to 16.
  553. *
  554. * Currently we won't configure NIG for MACs other than a primary ETH
  555. * MAC and iSCSI L2 MAC.
  556. *
  557. * If this MAC is moving from one Queue to another, no need to change
  558. * NIG configuration.
  559. */
  560. if (cmd != BNX2X_VLAN_MAC_MOVE) {
  561. if (test_bit(BNX2X_ISCSI_ETH_MAC, vlan_mac_flags))
  562. bnx2x_set_mac_in_nig(bp, add, mac,
  563. LLH_CAM_ISCSI_ETH_LINE);
  564. else if (test_bit(BNX2X_ETH_MAC, vlan_mac_flags))
  565. bnx2x_set_mac_in_nig(bp, add, mac, LLH_CAM_ETH_LINE);
  566. }
  567. /* Reset the ramrod data buffer for the first rule */
  568. if (rule_idx == 0)
  569. memset(data, 0, sizeof(*data));
  570. /* Setup a command header */
  571. bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_MAC,
  572. &rule_entry->mac.header);
  573. DP(BNX2X_MSG_SP, "About to %s MAC "BNX2X_MAC_FMT" for "
  574. "Queue %d\n", (add ? "add" : "delete"),
  575. BNX2X_MAC_PRN_LIST(mac), raw->cl_id);
  576. /* Set a MAC itself */
  577. bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
  578. &rule_entry->mac.mac_mid,
  579. &rule_entry->mac.mac_lsb, mac);
  580. /* MOVE: Add a rule that will add this MAC to the target Queue */
  581. if (cmd == BNX2X_VLAN_MAC_MOVE) {
  582. rule_entry++;
  583. rule_cnt++;
  584. /* Setup ramrod data */
  585. bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
  586. elem->cmd_data.vlan_mac.target_obj,
  587. true, CLASSIFY_RULE_OPCODE_MAC,
  588. &rule_entry->mac.header);
  589. /* Set a MAC itself */
  590. bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
  591. &rule_entry->mac.mac_mid,
  592. &rule_entry->mac.mac_lsb, mac);
  593. }
  594. /* Set the ramrod data header */
  595. /* TODO: take this to the higher level in order to prevent multiple
  596. writing */
  597. bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
  598. rule_cnt);
  599. }
  600. /**
  601. * bnx2x_vlan_mac_set_rdata_hdr_e1x - set a header in a single classify ramrod
  602. *
  603. * @bp: device handle
  604. * @o: queue
  605. * @type:
  606. * @cam_offset: offset in cam memory
  607. * @hdr: pointer to a header to setup
  608. *
  609. * E1/E1H
  610. */
  611. static inline void bnx2x_vlan_mac_set_rdata_hdr_e1x(struct bnx2x *bp,
  612. struct bnx2x_vlan_mac_obj *o, int type, int cam_offset,
  613. struct mac_configuration_hdr *hdr)
  614. {
  615. struct bnx2x_raw_obj *r = &o->raw;
  616. hdr->length = 1;
  617. hdr->offset = (u8)cam_offset;
  618. hdr->client_id = 0xff;
  619. hdr->echo = ((r->cid & BNX2X_SWCID_MASK) | (type << BNX2X_SWCID_SHIFT));
  620. }
  621. static inline void bnx2x_vlan_mac_set_cfg_entry_e1x(struct bnx2x *bp,
  622. struct bnx2x_vlan_mac_obj *o, bool add, int opcode, u8 *mac,
  623. u16 vlan_id, struct mac_configuration_entry *cfg_entry)
  624. {
  625. struct bnx2x_raw_obj *r = &o->raw;
  626. u32 cl_bit_vec = (1 << r->cl_id);
  627. cfg_entry->clients_bit_vector = cpu_to_le32(cl_bit_vec);
  628. cfg_entry->pf_id = r->func_id;
  629. cfg_entry->vlan_id = cpu_to_le16(vlan_id);
  630. if (add) {
  631. SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
  632. T_ETH_MAC_COMMAND_SET);
  633. SET_FLAG(cfg_entry->flags,
  634. MAC_CONFIGURATION_ENTRY_VLAN_FILTERING_MODE, opcode);
  635. /* Set a MAC in a ramrod data */
  636. bnx2x_set_fw_mac_addr(&cfg_entry->msb_mac_addr,
  637. &cfg_entry->middle_mac_addr,
  638. &cfg_entry->lsb_mac_addr, mac);
  639. } else
  640. SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
  641. T_ETH_MAC_COMMAND_INVALIDATE);
  642. }
  643. static inline void bnx2x_vlan_mac_set_rdata_e1x(struct bnx2x *bp,
  644. struct bnx2x_vlan_mac_obj *o, int type, int cam_offset, bool add,
  645. u8 *mac, u16 vlan_id, int opcode, struct mac_configuration_cmd *config)
  646. {
  647. struct mac_configuration_entry *cfg_entry = &config->config_table[0];
  648. struct bnx2x_raw_obj *raw = &o->raw;
  649. bnx2x_vlan_mac_set_rdata_hdr_e1x(bp, o, type, cam_offset,
  650. &config->hdr);
  651. bnx2x_vlan_mac_set_cfg_entry_e1x(bp, o, add, opcode, mac, vlan_id,
  652. cfg_entry);
  653. DP(BNX2X_MSG_SP, "%s MAC "BNX2X_MAC_FMT" CLID %d CAM offset %d\n",
  654. (add ? "setting" : "clearing"),
  655. BNX2X_MAC_PRN_LIST(mac), raw->cl_id, cam_offset);
  656. }
  657. /**
  658. * bnx2x_set_one_mac_e1x - fill a single MAC rule ramrod data
  659. *
  660. * @bp: device handle
  661. * @o: bnx2x_vlan_mac_obj
  662. * @elem: bnx2x_exeq_elem
  663. * @rule_idx: rule_idx
  664. * @cam_offset: cam_offset
  665. */
  666. static void bnx2x_set_one_mac_e1x(struct bnx2x *bp,
  667. struct bnx2x_vlan_mac_obj *o,
  668. struct bnx2x_exeq_elem *elem, int rule_idx,
  669. int cam_offset)
  670. {
  671. struct bnx2x_raw_obj *raw = &o->raw;
  672. struct mac_configuration_cmd *config =
  673. (struct mac_configuration_cmd *)(raw->rdata);
  674. /*
  675. * 57710 and 57711 do not support MOVE command,
  676. * so it's either ADD or DEL
  677. */
  678. bool add = (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
  679. true : false;
  680. /* Reset the ramrod data buffer */
  681. memset(config, 0, sizeof(*config));
  682. bnx2x_vlan_mac_set_rdata_e1x(bp, o, BNX2X_FILTER_MAC_PENDING,
  683. cam_offset, add,
  684. elem->cmd_data.vlan_mac.u.mac.mac, 0,
  685. ETH_VLAN_FILTER_ANY_VLAN, config);
  686. }
  687. static void bnx2x_set_one_vlan_e2(struct bnx2x *bp,
  688. struct bnx2x_vlan_mac_obj *o,
  689. struct bnx2x_exeq_elem *elem, int rule_idx,
  690. int cam_offset)
  691. {
  692. struct bnx2x_raw_obj *raw = &o->raw;
  693. struct eth_classify_rules_ramrod_data *data =
  694. (struct eth_classify_rules_ramrod_data *)(raw->rdata);
  695. int rule_cnt = rule_idx + 1;
  696. union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
  697. int cmd = elem->cmd_data.vlan_mac.cmd;
  698. bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
  699. u16 vlan = elem->cmd_data.vlan_mac.u.vlan.vlan;
  700. /* Reset the ramrod data buffer for the first rule */
  701. if (rule_idx == 0)
  702. memset(data, 0, sizeof(*data));
  703. /* Set a rule header */
  704. bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_VLAN,
  705. &rule_entry->vlan.header);
  706. DP(BNX2X_MSG_SP, "About to %s VLAN %d\n", (add ? "add" : "delete"),
  707. vlan);
  708. /* Set a VLAN itself */
  709. rule_entry->vlan.vlan = cpu_to_le16(vlan);
  710. /* MOVE: Add a rule that will add this MAC to the target Queue */
  711. if (cmd == BNX2X_VLAN_MAC_MOVE) {
  712. rule_entry++;
  713. rule_cnt++;
  714. /* Setup ramrod data */
  715. bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
  716. elem->cmd_data.vlan_mac.target_obj,
  717. true, CLASSIFY_RULE_OPCODE_VLAN,
  718. &rule_entry->vlan.header);
  719. /* Set a VLAN itself */
  720. rule_entry->vlan.vlan = cpu_to_le16(vlan);
  721. }
  722. /* Set the ramrod data header */
  723. /* TODO: take this to the higher level in order to prevent multiple
  724. writing */
  725. bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
  726. rule_cnt);
  727. }
  728. static void bnx2x_set_one_vlan_mac_e2(struct bnx2x *bp,
  729. struct bnx2x_vlan_mac_obj *o,
  730. struct bnx2x_exeq_elem *elem,
  731. int rule_idx, int cam_offset)
  732. {
  733. struct bnx2x_raw_obj *raw = &o->raw;
  734. struct eth_classify_rules_ramrod_data *data =
  735. (struct eth_classify_rules_ramrod_data *)(raw->rdata);
  736. int rule_cnt = rule_idx + 1;
  737. union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
  738. int cmd = elem->cmd_data.vlan_mac.cmd;
  739. bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
  740. u16 vlan = elem->cmd_data.vlan_mac.u.vlan_mac.vlan;
  741. u8 *mac = elem->cmd_data.vlan_mac.u.vlan_mac.mac;
  742. /* Reset the ramrod data buffer for the first rule */
  743. if (rule_idx == 0)
  744. memset(data, 0, sizeof(*data));
  745. /* Set a rule header */
  746. bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_PAIR,
  747. &rule_entry->pair.header);
  748. /* Set VLAN and MAC themselvs */
  749. rule_entry->pair.vlan = cpu_to_le16(vlan);
  750. bnx2x_set_fw_mac_addr(&rule_entry->pair.mac_msb,
  751. &rule_entry->pair.mac_mid,
  752. &rule_entry->pair.mac_lsb, mac);
  753. /* MOVE: Add a rule that will add this MAC to the target Queue */
  754. if (cmd == BNX2X_VLAN_MAC_MOVE) {
  755. rule_entry++;
  756. rule_cnt++;
  757. /* Setup ramrod data */
  758. bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
  759. elem->cmd_data.vlan_mac.target_obj,
  760. true, CLASSIFY_RULE_OPCODE_PAIR,
  761. &rule_entry->pair.header);
  762. /* Set a VLAN itself */
  763. rule_entry->pair.vlan = cpu_to_le16(vlan);
  764. bnx2x_set_fw_mac_addr(&rule_entry->pair.mac_msb,
  765. &rule_entry->pair.mac_mid,
  766. &rule_entry->pair.mac_lsb, mac);
  767. }
  768. /* Set the ramrod data header */
  769. /* TODO: take this to the higher level in order to prevent multiple
  770. writing */
  771. bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
  772. rule_cnt);
  773. }
  774. /**
  775. * bnx2x_set_one_vlan_mac_e1h -
  776. *
  777. * @bp: device handle
  778. * @o: bnx2x_vlan_mac_obj
  779. * @elem: bnx2x_exeq_elem
  780. * @rule_idx: rule_idx
  781. * @cam_offset: cam_offset
  782. */
  783. static void bnx2x_set_one_vlan_mac_e1h(struct bnx2x *bp,
  784. struct bnx2x_vlan_mac_obj *o,
  785. struct bnx2x_exeq_elem *elem,
  786. int rule_idx, int cam_offset)
  787. {
  788. struct bnx2x_raw_obj *raw = &o->raw;
  789. struct mac_configuration_cmd *config =
  790. (struct mac_configuration_cmd *)(raw->rdata);
  791. /*
  792. * 57710 and 57711 do not support MOVE command,
  793. * so it's either ADD or DEL
  794. */
  795. bool add = (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
  796. true : false;
  797. /* Reset the ramrod data buffer */
  798. memset(config, 0, sizeof(*config));
  799. bnx2x_vlan_mac_set_rdata_e1x(bp, o, BNX2X_FILTER_VLAN_MAC_PENDING,
  800. cam_offset, add,
  801. elem->cmd_data.vlan_mac.u.vlan_mac.mac,
  802. elem->cmd_data.vlan_mac.u.vlan_mac.vlan,
  803. ETH_VLAN_FILTER_CLASSIFY, config);
  804. }
  805. #define list_next_entry(pos, member) \
  806. list_entry((pos)->member.next, typeof(*(pos)), member)
  807. /**
  808. * bnx2x_vlan_mac_restore - reconfigure next MAC/VLAN/VLAN-MAC element
  809. *
  810. * @bp: device handle
  811. * @p: command parameters
  812. * @ppos: pointer to the cooky
  813. *
  814. * reconfigure next MAC/VLAN/VLAN-MAC element from the
  815. * previously configured elements list.
  816. *
  817. * from command parameters only RAMROD_COMP_WAIT bit in ramrod_flags is taken
  818. * into an account
  819. *
  820. * pointer to the cooky - that should be given back in the next call to make
  821. * function handle the next element. If *ppos is set to NULL it will restart the
  822. * iterator. If returned *ppos == NULL this means that the last element has been
  823. * handled.
  824. *
  825. */
  826. static int bnx2x_vlan_mac_restore(struct bnx2x *bp,
  827. struct bnx2x_vlan_mac_ramrod_params *p,
  828. struct bnx2x_vlan_mac_registry_elem **ppos)
  829. {
  830. struct bnx2x_vlan_mac_registry_elem *pos;
  831. struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
  832. /* If list is empty - there is nothing to do here */
  833. if (list_empty(&o->head)) {
  834. *ppos = NULL;
  835. return 0;
  836. }
  837. /* make a step... */
  838. if (*ppos == NULL)
  839. *ppos = list_first_entry(&o->head,
  840. struct bnx2x_vlan_mac_registry_elem,
  841. link);
  842. else
  843. *ppos = list_next_entry(*ppos, link);
  844. pos = *ppos;
  845. /* If it's the last step - return NULL */
  846. if (list_is_last(&pos->link, &o->head))
  847. *ppos = NULL;
  848. /* Prepare a 'user_req' */
  849. memcpy(&p->user_req.u, &pos->u, sizeof(pos->u));
  850. /* Set the command */
  851. p->user_req.cmd = BNX2X_VLAN_MAC_ADD;
  852. /* Set vlan_mac_flags */
  853. p->user_req.vlan_mac_flags = pos->vlan_mac_flags;
  854. /* Set a restore bit */
  855. __set_bit(RAMROD_RESTORE, &p->ramrod_flags);
  856. return bnx2x_config_vlan_mac(bp, p);
  857. }
  858. /*
  859. * bnx2x_exeq_get_mac/bnx2x_exeq_get_vlan/bnx2x_exeq_get_vlan_mac return a
  860. * pointer to an element with a specific criteria and NULL if such an element
  861. * hasn't been found.
  862. */
  863. static struct bnx2x_exeq_elem *bnx2x_exeq_get_mac(
  864. struct bnx2x_exe_queue_obj *o,
  865. struct bnx2x_exeq_elem *elem)
  866. {
  867. struct bnx2x_exeq_elem *pos;
  868. struct bnx2x_mac_ramrod_data *data = &elem->cmd_data.vlan_mac.u.mac;
  869. /* Check pending for execution commands */
  870. list_for_each_entry(pos, &o->exe_queue, link)
  871. if (!memcmp(&pos->cmd_data.vlan_mac.u.mac, data,
  872. sizeof(*data)) &&
  873. (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
  874. return pos;
  875. return NULL;
  876. }
  877. static struct bnx2x_exeq_elem *bnx2x_exeq_get_vlan(
  878. struct bnx2x_exe_queue_obj *o,
  879. struct bnx2x_exeq_elem *elem)
  880. {
  881. struct bnx2x_exeq_elem *pos;
  882. struct bnx2x_vlan_ramrod_data *data = &elem->cmd_data.vlan_mac.u.vlan;
  883. /* Check pending for execution commands */
  884. list_for_each_entry(pos, &o->exe_queue, link)
  885. if (!memcmp(&pos->cmd_data.vlan_mac.u.vlan, data,
  886. sizeof(*data)) &&
  887. (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
  888. return pos;
  889. return NULL;
  890. }
  891. static struct bnx2x_exeq_elem *bnx2x_exeq_get_vlan_mac(
  892. struct bnx2x_exe_queue_obj *o,
  893. struct bnx2x_exeq_elem *elem)
  894. {
  895. struct bnx2x_exeq_elem *pos;
  896. struct bnx2x_vlan_mac_ramrod_data *data =
  897. &elem->cmd_data.vlan_mac.u.vlan_mac;
  898. /* Check pending for execution commands */
  899. list_for_each_entry(pos, &o->exe_queue, link)
  900. if (!memcmp(&pos->cmd_data.vlan_mac.u.vlan_mac, data,
  901. sizeof(*data)) &&
  902. (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
  903. return pos;
  904. return NULL;
  905. }
  906. /**
  907. * bnx2x_validate_vlan_mac_add - check if an ADD command can be executed
  908. *
  909. * @bp: device handle
  910. * @qo: bnx2x_qable_obj
  911. * @elem: bnx2x_exeq_elem
  912. *
  913. * Checks that the requested configuration can be added. If yes and if
  914. * requested, consume CAM credit.
  915. *
  916. * The 'validate' is run after the 'optimize'.
  917. *
  918. */
  919. static inline int bnx2x_validate_vlan_mac_add(struct bnx2x *bp,
  920. union bnx2x_qable_obj *qo,
  921. struct bnx2x_exeq_elem *elem)
  922. {
  923. struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
  924. struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
  925. int rc;
  926. /* Check the registry */
  927. rc = o->check_add(o, &elem->cmd_data.vlan_mac.u);
  928. if (rc) {
  929. DP(BNX2X_MSG_SP, "ADD command is not allowed considering "
  930. "current registry state\n");
  931. return rc;
  932. }
  933. /*
  934. * Check if there is a pending ADD command for this
  935. * MAC/VLAN/VLAN-MAC. Return an error if there is.
  936. */
  937. if (exeq->get(exeq, elem)) {
  938. DP(BNX2X_MSG_SP, "There is a pending ADD command already\n");
  939. return -EEXIST;
  940. }
  941. /*
  942. * TODO: Check the pending MOVE from other objects where this
  943. * object is a destination object.
  944. */
  945. /* Consume the credit if not requested not to */
  946. if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
  947. &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
  948. o->get_credit(o)))
  949. return -EINVAL;
  950. return 0;
  951. }
  952. /**
  953. * bnx2x_validate_vlan_mac_del - check if the DEL command can be executed
  954. *
  955. * @bp: device handle
  956. * @qo: quable object to check
  957. * @elem: element that needs to be deleted
  958. *
  959. * Checks that the requested configuration can be deleted. If yes and if
  960. * requested, returns a CAM credit.
  961. *
  962. * The 'validate' is run after the 'optimize'.
  963. */
  964. static inline int bnx2x_validate_vlan_mac_del(struct bnx2x *bp,
  965. union bnx2x_qable_obj *qo,
  966. struct bnx2x_exeq_elem *elem)
  967. {
  968. struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
  969. struct bnx2x_vlan_mac_registry_elem *pos;
  970. struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
  971. struct bnx2x_exeq_elem query_elem;
  972. /* If this classification can not be deleted (doesn't exist)
  973. * - return a BNX2X_EXIST.
  974. */
  975. pos = o->check_del(o, &elem->cmd_data.vlan_mac.u);
  976. if (!pos) {
  977. DP(BNX2X_MSG_SP, "DEL command is not allowed considering "
  978. "current registry state\n");
  979. return -EEXIST;
  980. }
  981. /*
  982. * Check if there are pending DEL or MOVE commands for this
  983. * MAC/VLAN/VLAN-MAC. Return an error if so.
  984. */
  985. memcpy(&query_elem, elem, sizeof(query_elem));
  986. /* Check for MOVE commands */
  987. query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_MOVE;
  988. if (exeq->get(exeq, &query_elem)) {
  989. BNX2X_ERR("There is a pending MOVE command already\n");
  990. return -EINVAL;
  991. }
  992. /* Check for DEL commands */
  993. if (exeq->get(exeq, elem)) {
  994. DP(BNX2X_MSG_SP, "There is a pending DEL command already\n");
  995. return -EEXIST;
  996. }
  997. /* Return the credit to the credit pool if not requested not to */
  998. if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
  999. &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
  1000. o->put_credit(o))) {
  1001. BNX2X_ERR("Failed to return a credit\n");
  1002. return -EINVAL;
  1003. }
  1004. return 0;
  1005. }
  1006. /**
  1007. * bnx2x_validate_vlan_mac_move - check if the MOVE command can be executed
  1008. *
  1009. * @bp: device handle
  1010. * @qo: quable object to check (source)
  1011. * @elem: element that needs to be moved
  1012. *
  1013. * Checks that the requested configuration can be moved. If yes and if
  1014. * requested, returns a CAM credit.
  1015. *
  1016. * The 'validate' is run after the 'optimize'.
  1017. */
  1018. static inline int bnx2x_validate_vlan_mac_move(struct bnx2x *bp,
  1019. union bnx2x_qable_obj *qo,
  1020. struct bnx2x_exeq_elem *elem)
  1021. {
  1022. struct bnx2x_vlan_mac_obj *src_o = &qo->vlan_mac;
  1023. struct bnx2x_vlan_mac_obj *dest_o = elem->cmd_data.vlan_mac.target_obj;
  1024. struct bnx2x_exeq_elem query_elem;
  1025. struct bnx2x_exe_queue_obj *src_exeq = &src_o->exe_queue;
  1026. struct bnx2x_exe_queue_obj *dest_exeq = &dest_o->exe_queue;
  1027. /*
  1028. * Check if we can perform this operation based on the current registry
  1029. * state.
  1030. */
  1031. if (!src_o->check_move(src_o, dest_o, &elem->cmd_data.vlan_mac.u)) {
  1032. DP(BNX2X_MSG_SP, "MOVE command is not allowed considering "
  1033. "current registry state\n");
  1034. return -EINVAL;
  1035. }
  1036. /*
  1037. * Check if there is an already pending DEL or MOVE command for the
  1038. * source object or ADD command for a destination object. Return an
  1039. * error if so.
  1040. */
  1041. memcpy(&query_elem, elem, sizeof(query_elem));
  1042. /* Check DEL on source */
  1043. query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL;
  1044. if (src_exeq->get(src_exeq, &query_elem)) {
  1045. BNX2X_ERR("There is a pending DEL command on the source "
  1046. "queue already\n");
  1047. return -EINVAL;
  1048. }
  1049. /* Check MOVE on source */
  1050. if (src_exeq->get(src_exeq, elem)) {
  1051. DP(BNX2X_MSG_SP, "There is a pending MOVE command already\n");
  1052. return -EEXIST;
  1053. }
  1054. /* Check ADD on destination */
  1055. query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD;
  1056. if (dest_exeq->get(dest_exeq, &query_elem)) {
  1057. BNX2X_ERR("There is a pending ADD command on the "
  1058. "destination queue already\n");
  1059. return -EINVAL;
  1060. }
  1061. /* Consume the credit if not requested not to */
  1062. if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT_DEST,
  1063. &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
  1064. dest_o->get_credit(dest_o)))
  1065. return -EINVAL;
  1066. if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
  1067. &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
  1068. src_o->put_credit(src_o))) {
  1069. /* return the credit taken from dest... */
  1070. dest_o->put_credit(dest_o);
  1071. return -EINVAL;
  1072. }
  1073. return 0;
  1074. }
  1075. static int bnx2x_validate_vlan_mac(struct bnx2x *bp,
  1076. union bnx2x_qable_obj *qo,
  1077. struct bnx2x_exeq_elem *elem)
  1078. {
  1079. switch (elem->cmd_data.vlan_mac.cmd) {
  1080. case BNX2X_VLAN_MAC_ADD:
  1081. return bnx2x_validate_vlan_mac_add(bp, qo, elem);
  1082. case BNX2X_VLAN_MAC_DEL:
  1083. return bnx2x_validate_vlan_mac_del(bp, qo, elem);
  1084. case BNX2X_VLAN_MAC_MOVE:
  1085. return bnx2x_validate_vlan_mac_move(bp, qo, elem);
  1086. default:
  1087. return -EINVAL;
  1088. }
  1089. }
  1090. /**
  1091. * bnx2x_wait_vlan_mac - passivly wait for 5 seconds until all work completes.
  1092. *
  1093. * @bp: device handle
  1094. * @o: bnx2x_vlan_mac_obj
  1095. *
  1096. */
  1097. static int bnx2x_wait_vlan_mac(struct bnx2x *bp,
  1098. struct bnx2x_vlan_mac_obj *o)
  1099. {
  1100. int cnt = 5000, rc;
  1101. struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
  1102. struct bnx2x_raw_obj *raw = &o->raw;
  1103. while (cnt--) {
  1104. /* Wait for the current command to complete */
  1105. rc = raw->wait_comp(bp, raw);
  1106. if (rc)
  1107. return rc;
  1108. /* Wait until there are no pending commands */
  1109. if (!bnx2x_exe_queue_empty(exeq))
  1110. usleep_range(1000, 1000);
  1111. else
  1112. return 0;
  1113. }
  1114. return -EBUSY;
  1115. }
  1116. /**
  1117. * bnx2x_complete_vlan_mac - complete one VLAN-MAC ramrod
  1118. *
  1119. * @bp: device handle
  1120. * @o: bnx2x_vlan_mac_obj
  1121. * @cqe:
  1122. * @cont: if true schedule next execution chunk
  1123. *
  1124. */
  1125. static int bnx2x_complete_vlan_mac(struct bnx2x *bp,
  1126. struct bnx2x_vlan_mac_obj *o,
  1127. union event_ring_elem *cqe,
  1128. unsigned long *ramrod_flags)
  1129. {
  1130. struct bnx2x_raw_obj *r = &o->raw;
  1131. int rc;
  1132. /* Reset pending list */
  1133. bnx2x_exe_queue_reset_pending(bp, &o->exe_queue);
  1134. /* Clear pending */
  1135. r->clear_pending(r);
  1136. /* If ramrod failed this is most likely a SW bug */
  1137. if (cqe->message.error)
  1138. return -EINVAL;
  1139. /* Run the next bulk of pending commands if requeted */
  1140. if (test_bit(RAMROD_CONT, ramrod_flags)) {
  1141. rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
  1142. if (rc < 0)
  1143. return rc;
  1144. }
  1145. /* If there is more work to do return PENDING */
  1146. if (!bnx2x_exe_queue_empty(&o->exe_queue))
  1147. return 1;
  1148. return 0;
  1149. }
  1150. /**
  1151. * bnx2x_optimize_vlan_mac - optimize ADD and DEL commands.
  1152. *
  1153. * @bp: device handle
  1154. * @o: bnx2x_qable_obj
  1155. * @elem: bnx2x_exeq_elem
  1156. */
  1157. static int bnx2x_optimize_vlan_mac(struct bnx2x *bp,
  1158. union bnx2x_qable_obj *qo,
  1159. struct bnx2x_exeq_elem *elem)
  1160. {
  1161. struct bnx2x_exeq_elem query, *pos;
  1162. struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
  1163. struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
  1164. memcpy(&query, elem, sizeof(query));
  1165. switch (elem->cmd_data.vlan_mac.cmd) {
  1166. case BNX2X_VLAN_MAC_ADD:
  1167. query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL;
  1168. break;
  1169. case BNX2X_VLAN_MAC_DEL:
  1170. query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD;
  1171. break;
  1172. default:
  1173. /* Don't handle anything other than ADD or DEL */
  1174. return 0;
  1175. }
  1176. /* If we found the appropriate element - delete it */
  1177. pos = exeq->get(exeq, &query);
  1178. if (pos) {
  1179. /* Return the credit of the optimized command */
  1180. if (!test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
  1181. &pos->cmd_data.vlan_mac.vlan_mac_flags)) {
  1182. if ((query.cmd_data.vlan_mac.cmd ==
  1183. BNX2X_VLAN_MAC_ADD) && !o->put_credit(o)) {
  1184. BNX2X_ERR("Failed to return the credit for the "
  1185. "optimized ADD command\n");
  1186. return -EINVAL;
  1187. } else if (!o->get_credit(o)) { /* VLAN_MAC_DEL */
  1188. BNX2X_ERR("Failed to recover the credit from "
  1189. "the optimized DEL command\n");
  1190. return -EINVAL;
  1191. }
  1192. }
  1193. DP(BNX2X_MSG_SP, "Optimizing %s command\n",
  1194. (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
  1195. "ADD" : "DEL");
  1196. list_del(&pos->link);
  1197. bnx2x_exe_queue_free_elem(bp, pos);
  1198. return 1;
  1199. }
  1200. return 0;
  1201. }
  1202. /**
  1203. * bnx2x_vlan_mac_get_registry_elem - prepare a registry element
  1204. *
  1205. * @bp: device handle
  1206. * @o:
  1207. * @elem:
  1208. * @restore:
  1209. * @re:
  1210. *
  1211. * prepare a registry element according to the current command request.
  1212. */
  1213. static inline int bnx2x_vlan_mac_get_registry_elem(
  1214. struct bnx2x *bp,
  1215. struct bnx2x_vlan_mac_obj *o,
  1216. struct bnx2x_exeq_elem *elem,
  1217. bool restore,
  1218. struct bnx2x_vlan_mac_registry_elem **re)
  1219. {
  1220. int cmd = elem->cmd_data.vlan_mac.cmd;
  1221. struct bnx2x_vlan_mac_registry_elem *reg_elem;
  1222. /* Allocate a new registry element if needed. */
  1223. if (!restore &&
  1224. ((cmd == BNX2X_VLAN_MAC_ADD) || (cmd == BNX2X_VLAN_MAC_MOVE))) {
  1225. reg_elem = kzalloc(sizeof(*reg_elem), GFP_ATOMIC);
  1226. if (!reg_elem)
  1227. return -ENOMEM;
  1228. /* Get a new CAM offset */
  1229. if (!o->get_cam_offset(o, &reg_elem->cam_offset)) {
  1230. /*
  1231. * This shell never happen, because we have checked the
  1232. * CAM availiability in the 'validate'.
  1233. */
  1234. WARN_ON(1);
  1235. kfree(reg_elem);
  1236. return -EINVAL;
  1237. }
  1238. DP(BNX2X_MSG_SP, "Got cam offset %d\n", reg_elem->cam_offset);
  1239. /* Set a VLAN-MAC data */
  1240. memcpy(&reg_elem->u, &elem->cmd_data.vlan_mac.u,
  1241. sizeof(reg_elem->u));
  1242. /* Copy the flags (needed for DEL and RESTORE flows) */
  1243. reg_elem->vlan_mac_flags =
  1244. elem->cmd_data.vlan_mac.vlan_mac_flags;
  1245. } else /* DEL, RESTORE */
  1246. reg_elem = o->check_del(o, &elem->cmd_data.vlan_mac.u);
  1247. *re = reg_elem;
  1248. return 0;
  1249. }
  1250. /**
  1251. * bnx2x_execute_vlan_mac - execute vlan mac command
  1252. *
  1253. * @bp: device handle
  1254. * @qo:
  1255. * @exe_chunk:
  1256. * @ramrod_flags:
  1257. *
  1258. * go and send a ramrod!
  1259. */
  1260. static int bnx2x_execute_vlan_mac(struct bnx2x *bp,
  1261. union bnx2x_qable_obj *qo,
  1262. struct list_head *exe_chunk,
  1263. unsigned long *ramrod_flags)
  1264. {
  1265. struct bnx2x_exeq_elem *elem;
  1266. struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac, *cam_obj;
  1267. struct bnx2x_raw_obj *r = &o->raw;
  1268. int rc, idx = 0;
  1269. bool restore = test_bit(RAMROD_RESTORE, ramrod_flags);
  1270. bool drv_only = test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags);
  1271. struct bnx2x_vlan_mac_registry_elem *reg_elem;
  1272. int cmd;
  1273. /*
  1274. * If DRIVER_ONLY execution is requested, cleanup a registry
  1275. * and exit. Otherwise send a ramrod to FW.
  1276. */
  1277. if (!drv_only) {
  1278. WARN_ON(r->check_pending(r));
  1279. /* Set pending */
  1280. r->set_pending(r);
  1281. /* Fill tha ramrod data */
  1282. list_for_each_entry(elem, exe_chunk, link) {
  1283. cmd = elem->cmd_data.vlan_mac.cmd;
  1284. /*
  1285. * We will add to the target object in MOVE command, so
  1286. * change the object for a CAM search.
  1287. */
  1288. if (cmd == BNX2X_VLAN_MAC_MOVE)
  1289. cam_obj = elem->cmd_data.vlan_mac.target_obj;
  1290. else
  1291. cam_obj = o;
  1292. rc = bnx2x_vlan_mac_get_registry_elem(bp, cam_obj,
  1293. elem, restore,
  1294. &reg_elem);
  1295. if (rc)
  1296. goto error_exit;
  1297. WARN_ON(!reg_elem);
  1298. /* Push a new entry into the registry */
  1299. if (!restore &&
  1300. ((cmd == BNX2X_VLAN_MAC_ADD) ||
  1301. (cmd == BNX2X_VLAN_MAC_MOVE)))
  1302. list_add(&reg_elem->link, &cam_obj->head);
  1303. /* Configure a single command in a ramrod data buffer */
  1304. o->set_one_rule(bp, o, elem, idx,
  1305. reg_elem->cam_offset);
  1306. /* MOVE command consumes 2 entries in the ramrod data */
  1307. if (cmd == BNX2X_VLAN_MAC_MOVE)
  1308. idx += 2;
  1309. else
  1310. idx++;
  1311. }
  1312. /* Commit the data writes towards the memory */
  1313. mb();
  1314. rc = bnx2x_sp_post(bp, o->ramrod_cmd, r->cid,
  1315. U64_HI(r->rdata_mapping),
  1316. U64_LO(r->rdata_mapping),
  1317. ETH_CONNECTION_TYPE);
  1318. if (rc)
  1319. goto error_exit;
  1320. }
  1321. /* Now, when we are done with the ramrod - clean up the registry */
  1322. list_for_each_entry(elem, exe_chunk, link) {
  1323. cmd = elem->cmd_data.vlan_mac.cmd;
  1324. if ((cmd == BNX2X_VLAN_MAC_DEL) ||
  1325. (cmd == BNX2X_VLAN_MAC_MOVE)) {
  1326. reg_elem = o->check_del(o, &elem->cmd_data.vlan_mac.u);
  1327. WARN_ON(!reg_elem);
  1328. o->put_cam_offset(o, reg_elem->cam_offset);
  1329. list_del(&reg_elem->link);
  1330. kfree(reg_elem);
  1331. }
  1332. }
  1333. if (!drv_only)
  1334. return 1;
  1335. else
  1336. return 0;
  1337. error_exit:
  1338. r->clear_pending(r);
  1339. /* Cleanup a registry in case of a failure */
  1340. list_for_each_entry(elem, exe_chunk, link) {
  1341. cmd = elem->cmd_data.vlan_mac.cmd;
  1342. if (cmd == BNX2X_VLAN_MAC_MOVE)
  1343. cam_obj = elem->cmd_data.vlan_mac.target_obj;
  1344. else
  1345. cam_obj = o;
  1346. /* Delete all newly added above entries */
  1347. if (!restore &&
  1348. ((cmd == BNX2X_VLAN_MAC_ADD) ||
  1349. (cmd == BNX2X_VLAN_MAC_MOVE))) {
  1350. reg_elem = o->check_del(cam_obj,
  1351. &elem->cmd_data.vlan_mac.u);
  1352. if (reg_elem) {
  1353. list_del(&reg_elem->link);
  1354. kfree(reg_elem);
  1355. }
  1356. }
  1357. }
  1358. return rc;
  1359. }
  1360. static inline int bnx2x_vlan_mac_push_new_cmd(
  1361. struct bnx2x *bp,
  1362. struct bnx2x_vlan_mac_ramrod_params *p)
  1363. {
  1364. struct bnx2x_exeq_elem *elem;
  1365. struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
  1366. bool restore = test_bit(RAMROD_RESTORE, &p->ramrod_flags);
  1367. /* Allocate the execution queue element */
  1368. elem = bnx2x_exe_queue_alloc_elem(bp);
  1369. if (!elem)
  1370. return -ENOMEM;
  1371. /* Set the command 'length' */
  1372. switch (p->user_req.cmd) {
  1373. case BNX2X_VLAN_MAC_MOVE:
  1374. elem->cmd_len = 2;
  1375. break;
  1376. default:
  1377. elem->cmd_len = 1;
  1378. }
  1379. /* Fill the object specific info */
  1380. memcpy(&elem->cmd_data.vlan_mac, &p->user_req, sizeof(p->user_req));
  1381. /* Try to add a new command to the pending list */
  1382. return bnx2x_exe_queue_add(bp, &o->exe_queue, elem, restore);
  1383. }
  1384. /**
  1385. * bnx2x_config_vlan_mac - configure VLAN/MAC/VLAN_MAC filtering rules.
  1386. *
  1387. * @bp: device handle
  1388. * @p:
  1389. *
  1390. */
  1391. int bnx2x_config_vlan_mac(
  1392. struct bnx2x *bp,
  1393. struct bnx2x_vlan_mac_ramrod_params *p)
  1394. {
  1395. int rc = 0;
  1396. struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
  1397. unsigned long *ramrod_flags = &p->ramrod_flags;
  1398. bool cont = test_bit(RAMROD_CONT, ramrod_flags);
  1399. struct bnx2x_raw_obj *raw = &o->raw;
  1400. /*
  1401. * Add new elements to the execution list for commands that require it.
  1402. */
  1403. if (!cont) {
  1404. rc = bnx2x_vlan_mac_push_new_cmd(bp, p);
  1405. if (rc)
  1406. return rc;
  1407. }
  1408. /*
  1409. * If nothing will be executed further in this iteration we want to
  1410. * return PENDING if there are pending commands
  1411. */
  1412. if (!bnx2x_exe_queue_empty(&o->exe_queue))
  1413. rc = 1;
  1414. /* Execute commands if required */
  1415. if (cont || test_bit(RAMROD_EXEC, ramrod_flags) ||
  1416. test_bit(RAMROD_COMP_WAIT, ramrod_flags)) {
  1417. rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
  1418. if (rc < 0)
  1419. return rc;
  1420. }
  1421. /*
  1422. * RAMROD_COMP_WAIT is a superset of RAMROD_EXEC. If it was set
  1423. * then user want to wait until the last command is done.
  1424. */
  1425. if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) {
  1426. /*
  1427. * Wait maximum for the current exe_queue length iterations plus
  1428. * one (for the current pending command).
  1429. */
  1430. int max_iterations = bnx2x_exe_queue_length(&o->exe_queue) + 1;
  1431. while (!bnx2x_exe_queue_empty(&o->exe_queue) &&
  1432. max_iterations--) {
  1433. /* Wait for the current command to complete */
  1434. rc = raw->wait_comp(bp, raw);
  1435. if (rc)
  1436. return rc;
  1437. /* Make a next step */
  1438. rc = bnx2x_exe_queue_step(bp, &o->exe_queue,
  1439. ramrod_flags);
  1440. if (rc < 0)
  1441. return rc;
  1442. }
  1443. return 0;
  1444. }
  1445. return rc;
  1446. }
  1447. /**
  1448. * bnx2x_vlan_mac_del_all - delete elements with given vlan_mac_flags spec
  1449. *
  1450. * @bp: device handle
  1451. * @o:
  1452. * @vlan_mac_flags:
  1453. * @ramrod_flags: execution flags to be used for this deletion
  1454. *
  1455. * if the last operation has completed successfully and there are no
  1456. * moreelements left, positive value if the last operation has completed
  1457. * successfully and there are more previously configured elements, negative
  1458. * value is current operation has failed.
  1459. */
  1460. static int bnx2x_vlan_mac_del_all(struct bnx2x *bp,
  1461. struct bnx2x_vlan_mac_obj *o,
  1462. unsigned long *vlan_mac_flags,
  1463. unsigned long *ramrod_flags)
  1464. {
  1465. struct bnx2x_vlan_mac_registry_elem *pos = NULL;
  1466. int rc = 0;
  1467. struct bnx2x_vlan_mac_ramrod_params p;
  1468. struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
  1469. struct bnx2x_exeq_elem *exeq_pos, *exeq_pos_n;
  1470. /* Clear pending commands first */
  1471. spin_lock_bh(&exeq->lock);
  1472. list_for_each_entry_safe(exeq_pos, exeq_pos_n, &exeq->exe_queue, link) {
  1473. if (exeq_pos->cmd_data.vlan_mac.vlan_mac_flags ==
  1474. *vlan_mac_flags)
  1475. list_del(&exeq_pos->link);
  1476. }
  1477. spin_unlock_bh(&exeq->lock);
  1478. /* Prepare a command request */
  1479. memset(&p, 0, sizeof(p));
  1480. p.vlan_mac_obj = o;
  1481. p.ramrod_flags = *ramrod_flags;
  1482. p.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  1483. /*
  1484. * Add all but the last VLAN-MAC to the execution queue without actually
  1485. * execution anything.
  1486. */
  1487. __clear_bit(RAMROD_COMP_WAIT, &p.ramrod_flags);
  1488. __clear_bit(RAMROD_EXEC, &p.ramrod_flags);
  1489. __clear_bit(RAMROD_CONT, &p.ramrod_flags);
  1490. list_for_each_entry(pos, &o->head, link) {
  1491. if (pos->vlan_mac_flags == *vlan_mac_flags) {
  1492. p.user_req.vlan_mac_flags = pos->vlan_mac_flags;
  1493. memcpy(&p.user_req.u, &pos->u, sizeof(pos->u));
  1494. rc = bnx2x_config_vlan_mac(bp, &p);
  1495. if (rc < 0) {
  1496. BNX2X_ERR("Failed to add a new DEL command\n");
  1497. return rc;
  1498. }
  1499. }
  1500. }
  1501. p.ramrod_flags = *ramrod_flags;
  1502. __set_bit(RAMROD_CONT, &p.ramrod_flags);
  1503. return bnx2x_config_vlan_mac(bp, &p);
  1504. }
  1505. static inline void bnx2x_init_raw_obj(struct bnx2x_raw_obj *raw, u8 cl_id,
  1506. u32 cid, u8 func_id, void *rdata, dma_addr_t rdata_mapping, int state,
  1507. unsigned long *pstate, bnx2x_obj_type type)
  1508. {
  1509. raw->func_id = func_id;
  1510. raw->cid = cid;
  1511. raw->cl_id = cl_id;
  1512. raw->rdata = rdata;
  1513. raw->rdata_mapping = rdata_mapping;
  1514. raw->state = state;
  1515. raw->pstate = pstate;
  1516. raw->obj_type = type;
  1517. raw->check_pending = bnx2x_raw_check_pending;
  1518. raw->clear_pending = bnx2x_raw_clear_pending;
  1519. raw->set_pending = bnx2x_raw_set_pending;
  1520. raw->wait_comp = bnx2x_raw_wait;
  1521. }
  1522. static inline void bnx2x_init_vlan_mac_common(struct bnx2x_vlan_mac_obj *o,
  1523. u8 cl_id, u32 cid, u8 func_id, void *rdata, dma_addr_t rdata_mapping,
  1524. int state, unsigned long *pstate, bnx2x_obj_type type,
  1525. struct bnx2x_credit_pool_obj *macs_pool,
  1526. struct bnx2x_credit_pool_obj *vlans_pool)
  1527. {
  1528. INIT_LIST_HEAD(&o->head);
  1529. o->macs_pool = macs_pool;
  1530. o->vlans_pool = vlans_pool;
  1531. o->delete_all = bnx2x_vlan_mac_del_all;
  1532. o->restore = bnx2x_vlan_mac_restore;
  1533. o->complete = bnx2x_complete_vlan_mac;
  1534. o->wait = bnx2x_wait_vlan_mac;
  1535. bnx2x_init_raw_obj(&o->raw, cl_id, cid, func_id, rdata, rdata_mapping,
  1536. state, pstate, type);
  1537. }
  1538. void bnx2x_init_mac_obj(struct bnx2x *bp,
  1539. struct bnx2x_vlan_mac_obj *mac_obj,
  1540. u8 cl_id, u32 cid, u8 func_id, void *rdata,
  1541. dma_addr_t rdata_mapping, int state,
  1542. unsigned long *pstate, bnx2x_obj_type type,
  1543. struct bnx2x_credit_pool_obj *macs_pool)
  1544. {
  1545. union bnx2x_qable_obj *qable_obj = (union bnx2x_qable_obj *)mac_obj;
  1546. bnx2x_init_vlan_mac_common(mac_obj, cl_id, cid, func_id, rdata,
  1547. rdata_mapping, state, pstate, type,
  1548. macs_pool, NULL);
  1549. /* CAM credit pool handling */
  1550. mac_obj->get_credit = bnx2x_get_credit_mac;
  1551. mac_obj->put_credit = bnx2x_put_credit_mac;
  1552. mac_obj->get_cam_offset = bnx2x_get_cam_offset_mac;
  1553. mac_obj->put_cam_offset = bnx2x_put_cam_offset_mac;
  1554. if (CHIP_IS_E1x(bp)) {
  1555. mac_obj->set_one_rule = bnx2x_set_one_mac_e1x;
  1556. mac_obj->check_del = bnx2x_check_mac_del;
  1557. mac_obj->check_add = bnx2x_check_mac_add;
  1558. mac_obj->check_move = bnx2x_check_move_always_err;
  1559. mac_obj->ramrod_cmd = RAMROD_CMD_ID_ETH_SET_MAC;
  1560. /* Exe Queue */
  1561. bnx2x_exe_queue_init(bp,
  1562. &mac_obj->exe_queue, 1, qable_obj,
  1563. bnx2x_validate_vlan_mac,
  1564. bnx2x_optimize_vlan_mac,
  1565. bnx2x_execute_vlan_mac,
  1566. bnx2x_exeq_get_mac);
  1567. } else {
  1568. mac_obj->set_one_rule = bnx2x_set_one_mac_e2;
  1569. mac_obj->check_del = bnx2x_check_mac_del;
  1570. mac_obj->check_add = bnx2x_check_mac_add;
  1571. mac_obj->check_move = bnx2x_check_move;
  1572. mac_obj->ramrod_cmd =
  1573. RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
  1574. /* Exe Queue */
  1575. bnx2x_exe_queue_init(bp,
  1576. &mac_obj->exe_queue, CLASSIFY_RULES_COUNT,
  1577. qable_obj, bnx2x_validate_vlan_mac,
  1578. bnx2x_optimize_vlan_mac,
  1579. bnx2x_execute_vlan_mac,
  1580. bnx2x_exeq_get_mac);
  1581. }
  1582. }
  1583. void bnx2x_init_vlan_obj(struct bnx2x *bp,
  1584. struct bnx2x_vlan_mac_obj *vlan_obj,
  1585. u8 cl_id, u32 cid, u8 func_id, void *rdata,
  1586. dma_addr_t rdata_mapping, int state,
  1587. unsigned long *pstate, bnx2x_obj_type type,
  1588. struct bnx2x_credit_pool_obj *vlans_pool)
  1589. {
  1590. union bnx2x_qable_obj *qable_obj = (union bnx2x_qable_obj *)vlan_obj;
  1591. bnx2x_init_vlan_mac_common(vlan_obj, cl_id, cid, func_id, rdata,
  1592. rdata_mapping, state, pstate, type, NULL,
  1593. vlans_pool);
  1594. vlan_obj->get_credit = bnx2x_get_credit_vlan;
  1595. vlan_obj->put_credit = bnx2x_put_credit_vlan;
  1596. vlan_obj->get_cam_offset = bnx2x_get_cam_offset_vlan;
  1597. vlan_obj->put_cam_offset = bnx2x_put_cam_offset_vlan;
  1598. if (CHIP_IS_E1x(bp)) {
  1599. BNX2X_ERR("Do not support chips others than E2 and newer\n");
  1600. BUG();
  1601. } else {
  1602. vlan_obj->set_one_rule = bnx2x_set_one_vlan_e2;
  1603. vlan_obj->check_del = bnx2x_check_vlan_del;
  1604. vlan_obj->check_add = bnx2x_check_vlan_add;
  1605. vlan_obj->check_move = bnx2x_check_move;
  1606. vlan_obj->ramrod_cmd =
  1607. RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
  1608. /* Exe Queue */
  1609. bnx2x_exe_queue_init(bp,
  1610. &vlan_obj->exe_queue, CLASSIFY_RULES_COUNT,
  1611. qable_obj, bnx2x_validate_vlan_mac,
  1612. bnx2x_optimize_vlan_mac,
  1613. bnx2x_execute_vlan_mac,
  1614. bnx2x_exeq_get_vlan);
  1615. }
  1616. }
  1617. void bnx2x_init_vlan_mac_obj(struct bnx2x *bp,
  1618. struct bnx2x_vlan_mac_obj *vlan_mac_obj,
  1619. u8 cl_id, u32 cid, u8 func_id, void *rdata,
  1620. dma_addr_t rdata_mapping, int state,
  1621. unsigned long *pstate, bnx2x_obj_type type,
  1622. struct bnx2x_credit_pool_obj *macs_pool,
  1623. struct bnx2x_credit_pool_obj *vlans_pool)
  1624. {
  1625. union bnx2x_qable_obj *qable_obj =
  1626. (union bnx2x_qable_obj *)vlan_mac_obj;
  1627. bnx2x_init_vlan_mac_common(vlan_mac_obj, cl_id, cid, func_id, rdata,
  1628. rdata_mapping, state, pstate, type,
  1629. macs_pool, vlans_pool);
  1630. /* CAM pool handling */
  1631. vlan_mac_obj->get_credit = bnx2x_get_credit_vlan_mac;
  1632. vlan_mac_obj->put_credit = bnx2x_put_credit_vlan_mac;
  1633. /*
  1634. * CAM offset is relevant for 57710 and 57711 chips only which have a
  1635. * single CAM for both MACs and VLAN-MAC pairs. So the offset
  1636. * will be taken from MACs' pool object only.
  1637. */
  1638. vlan_mac_obj->get_cam_offset = bnx2x_get_cam_offset_mac;
  1639. vlan_mac_obj->put_cam_offset = bnx2x_put_cam_offset_mac;
  1640. if (CHIP_IS_E1(bp)) {
  1641. BNX2X_ERR("Do not support chips others than E2\n");
  1642. BUG();
  1643. } else if (CHIP_IS_E1H(bp)) {
  1644. vlan_mac_obj->set_one_rule = bnx2x_set_one_vlan_mac_e1h;
  1645. vlan_mac_obj->check_del = bnx2x_check_vlan_mac_del;
  1646. vlan_mac_obj->check_add = bnx2x_check_vlan_mac_add;
  1647. vlan_mac_obj->check_move = bnx2x_check_move_always_err;
  1648. vlan_mac_obj->ramrod_cmd = RAMROD_CMD_ID_ETH_SET_MAC;
  1649. /* Exe Queue */
  1650. bnx2x_exe_queue_init(bp,
  1651. &vlan_mac_obj->exe_queue, 1, qable_obj,
  1652. bnx2x_validate_vlan_mac,
  1653. bnx2x_optimize_vlan_mac,
  1654. bnx2x_execute_vlan_mac,
  1655. bnx2x_exeq_get_vlan_mac);
  1656. } else {
  1657. vlan_mac_obj->set_one_rule = bnx2x_set_one_vlan_mac_e2;
  1658. vlan_mac_obj->check_del = bnx2x_check_vlan_mac_del;
  1659. vlan_mac_obj->check_add = bnx2x_check_vlan_mac_add;
  1660. vlan_mac_obj->check_move = bnx2x_check_move;
  1661. vlan_mac_obj->ramrod_cmd =
  1662. RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
  1663. /* Exe Queue */
  1664. bnx2x_exe_queue_init(bp,
  1665. &vlan_mac_obj->exe_queue,
  1666. CLASSIFY_RULES_COUNT,
  1667. qable_obj, bnx2x_validate_vlan_mac,
  1668. bnx2x_optimize_vlan_mac,
  1669. bnx2x_execute_vlan_mac,
  1670. bnx2x_exeq_get_vlan_mac);
  1671. }
  1672. }
  1673. /* RX_MODE verbs: DROP_ALL/ACCEPT_ALL/ACCEPT_ALL_MULTI/ACCEPT_ALL_VLAN/NORMAL */
  1674. static inline void __storm_memset_mac_filters(struct bnx2x *bp,
  1675. struct tstorm_eth_mac_filter_config *mac_filters,
  1676. u16 pf_id)
  1677. {
  1678. size_t size = sizeof(struct tstorm_eth_mac_filter_config);
  1679. u32 addr = BAR_TSTRORM_INTMEM +
  1680. TSTORM_MAC_FILTER_CONFIG_OFFSET(pf_id);
  1681. __storm_memset_struct(bp, addr, size, (u32 *)mac_filters);
  1682. }
  1683. static int bnx2x_set_rx_mode_e1x(struct bnx2x *bp,
  1684. struct bnx2x_rx_mode_ramrod_params *p)
  1685. {
  1686. /* update the bp MAC filter structure */
  1687. u32 mask = (1 << p->cl_id);
  1688. struct tstorm_eth_mac_filter_config *mac_filters =
  1689. (struct tstorm_eth_mac_filter_config *)p->rdata;
  1690. /* initial seeting is drop-all */
  1691. u8 drop_all_ucast = 1, drop_all_mcast = 1;
  1692. u8 accp_all_ucast = 0, accp_all_bcast = 0, accp_all_mcast = 0;
  1693. u8 unmatched_unicast = 0;
  1694. /* In e1x there we only take into account rx acceot flag since tx switching
  1695. * isn't enabled. */
  1696. if (test_bit(BNX2X_ACCEPT_UNICAST, &p->rx_accept_flags))
  1697. /* accept matched ucast */
  1698. drop_all_ucast = 0;
  1699. if (test_bit(BNX2X_ACCEPT_MULTICAST, &p->rx_accept_flags))
  1700. /* accept matched mcast */
  1701. drop_all_mcast = 0;
  1702. if (test_bit(BNX2X_ACCEPT_ALL_UNICAST, &p->rx_accept_flags)) {
  1703. /* accept all mcast */
  1704. drop_all_ucast = 0;
  1705. accp_all_ucast = 1;
  1706. }
  1707. if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST, &p->rx_accept_flags)) {
  1708. /* accept all mcast */
  1709. drop_all_mcast = 0;
  1710. accp_all_mcast = 1;
  1711. }
  1712. if (test_bit(BNX2X_ACCEPT_BROADCAST, &p->rx_accept_flags))
  1713. /* accept (all) bcast */
  1714. accp_all_bcast = 1;
  1715. if (test_bit(BNX2X_ACCEPT_UNMATCHED, &p->rx_accept_flags))
  1716. /* accept unmatched unicasts */
  1717. unmatched_unicast = 1;
  1718. mac_filters->ucast_drop_all = drop_all_ucast ?
  1719. mac_filters->ucast_drop_all | mask :
  1720. mac_filters->ucast_drop_all & ~mask;
  1721. mac_filters->mcast_drop_all = drop_all_mcast ?
  1722. mac_filters->mcast_drop_all | mask :
  1723. mac_filters->mcast_drop_all & ~mask;
  1724. mac_filters->ucast_accept_all = accp_all_ucast ?
  1725. mac_filters->ucast_accept_all | mask :
  1726. mac_filters->ucast_accept_all & ~mask;
  1727. mac_filters->mcast_accept_all = accp_all_mcast ?
  1728. mac_filters->mcast_accept_all | mask :
  1729. mac_filters->mcast_accept_all & ~mask;
  1730. mac_filters->bcast_accept_all = accp_all_bcast ?
  1731. mac_filters->bcast_accept_all | mask :
  1732. mac_filters->bcast_accept_all & ~mask;
  1733. mac_filters->unmatched_unicast = unmatched_unicast ?
  1734. mac_filters->unmatched_unicast | mask :
  1735. mac_filters->unmatched_unicast & ~mask;
  1736. DP(BNX2X_MSG_SP, "drop_ucast 0x%x\ndrop_mcast 0x%x\n accp_ucast 0x%x\n"
  1737. "accp_mcast 0x%x\naccp_bcast 0x%x\n",
  1738. mac_filters->ucast_drop_all,
  1739. mac_filters->mcast_drop_all,
  1740. mac_filters->ucast_accept_all,
  1741. mac_filters->mcast_accept_all,
  1742. mac_filters->bcast_accept_all);
  1743. /* write the MAC filter structure*/
  1744. __storm_memset_mac_filters(bp, mac_filters, p->func_id);
  1745. /* The operation is completed */
  1746. clear_bit(p->state, p->pstate);
  1747. smp_mb__after_clear_bit();
  1748. return 0;
  1749. }
  1750. /* Setup ramrod data */
  1751. static inline void bnx2x_rx_mode_set_rdata_hdr_e2(u32 cid,
  1752. struct eth_classify_header *hdr,
  1753. u8 rule_cnt)
  1754. {
  1755. hdr->echo = cid;
  1756. hdr->rule_cnt = rule_cnt;
  1757. }
  1758. static inline void bnx2x_rx_mode_set_cmd_state_e2(struct bnx2x *bp,
  1759. unsigned long accept_flags,
  1760. struct eth_filter_rules_cmd *cmd,
  1761. bool clear_accept_all)
  1762. {
  1763. u16 state;
  1764. /* start with 'drop-all' */
  1765. state = ETH_FILTER_RULES_CMD_UCAST_DROP_ALL |
  1766. ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
  1767. if (accept_flags) {
  1768. if (test_bit(BNX2X_ACCEPT_UNICAST, &accept_flags))
  1769. state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
  1770. if (test_bit(BNX2X_ACCEPT_MULTICAST, &accept_flags))
  1771. state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
  1772. if (test_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept_flags)) {
  1773. state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
  1774. state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
  1775. }
  1776. if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags)) {
  1777. state |= ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
  1778. state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
  1779. }
  1780. if (test_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags))
  1781. state |= ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
  1782. if (test_bit(BNX2X_ACCEPT_UNMATCHED, &accept_flags)) {
  1783. state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
  1784. state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
  1785. }
  1786. if (test_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags))
  1787. state |= ETH_FILTER_RULES_CMD_ACCEPT_ANY_VLAN;
  1788. }
  1789. /* Clear ACCEPT_ALL_XXX flags for FCoE L2 Queue */
  1790. if (clear_accept_all) {
  1791. state &= ~ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
  1792. state &= ~ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
  1793. state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
  1794. state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
  1795. }
  1796. cmd->state = cpu_to_le16(state);
  1797. }
  1798. static int bnx2x_set_rx_mode_e2(struct bnx2x *bp,
  1799. struct bnx2x_rx_mode_ramrod_params *p)
  1800. {
  1801. struct eth_filter_rules_ramrod_data *data = p->rdata;
  1802. int rc;
  1803. u8 rule_idx = 0;
  1804. /* Reset the ramrod data buffer */
  1805. memset(data, 0, sizeof(*data));
  1806. /* Setup ramrod data */
  1807. /* Tx (internal switching) */
  1808. if (test_bit(RAMROD_TX, &p->ramrod_flags)) {
  1809. data->rules[rule_idx].client_id = p->cl_id;
  1810. data->rules[rule_idx].func_id = p->func_id;
  1811. data->rules[rule_idx].cmd_general_data =
  1812. ETH_FILTER_RULES_CMD_TX_CMD;
  1813. bnx2x_rx_mode_set_cmd_state_e2(bp, p->tx_accept_flags,
  1814. &(data->rules[rule_idx++]), false);
  1815. }
  1816. /* Rx */
  1817. if (test_bit(RAMROD_RX, &p->ramrod_flags)) {
  1818. data->rules[rule_idx].client_id = p->cl_id;
  1819. data->rules[rule_idx].func_id = p->func_id;
  1820. data->rules[rule_idx].cmd_general_data =
  1821. ETH_FILTER_RULES_CMD_RX_CMD;
  1822. bnx2x_rx_mode_set_cmd_state_e2(bp, p->rx_accept_flags,
  1823. &(data->rules[rule_idx++]), false);
  1824. }
  1825. /*
  1826. * If FCoE Queue configuration has been requested configure the Rx and
  1827. * internal switching modes for this queue in separate rules.
  1828. *
  1829. * FCoE queue shell never be set to ACCEPT_ALL packets of any sort:
  1830. * MCAST_ALL, UCAST_ALL, BCAST_ALL and UNMATCHED.
  1831. */
  1832. if (test_bit(BNX2X_RX_MODE_FCOE_ETH, &p->rx_mode_flags)) {
  1833. /* Tx (internal switching) */
  1834. if (test_bit(RAMROD_TX, &p->ramrod_flags)) {
  1835. data->rules[rule_idx].client_id = bnx2x_fcoe(bp, cl_id);
  1836. data->rules[rule_idx].func_id = p->func_id;
  1837. data->rules[rule_idx].cmd_general_data =
  1838. ETH_FILTER_RULES_CMD_TX_CMD;
  1839. bnx2x_rx_mode_set_cmd_state_e2(bp, p->tx_accept_flags,
  1840. &(data->rules[rule_idx++]),
  1841. true);
  1842. }
  1843. /* Rx */
  1844. if (test_bit(RAMROD_RX, &p->ramrod_flags)) {
  1845. data->rules[rule_idx].client_id = bnx2x_fcoe(bp, cl_id);
  1846. data->rules[rule_idx].func_id = p->func_id;
  1847. data->rules[rule_idx].cmd_general_data =
  1848. ETH_FILTER_RULES_CMD_RX_CMD;
  1849. bnx2x_rx_mode_set_cmd_state_e2(bp, p->rx_accept_flags,
  1850. &(data->rules[rule_idx++]),
  1851. true);
  1852. }
  1853. }
  1854. /*
  1855. * Set the ramrod header (most importantly - number of rules to
  1856. * configure).
  1857. */
  1858. bnx2x_rx_mode_set_rdata_hdr_e2(p->cid, &data->header, rule_idx);
  1859. DP(BNX2X_MSG_SP, "About to configure %d rules, rx_accept_flags 0x%lx, "
  1860. "tx_accept_flags 0x%lx\n",
  1861. data->header.rule_cnt, p->rx_accept_flags,
  1862. p->tx_accept_flags);
  1863. /* Commit writes towards the memory before sending a ramrod */
  1864. mb();
  1865. /* Send a ramrod */
  1866. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_FILTER_RULES, p->cid,
  1867. U64_HI(p->rdata_mapping),
  1868. U64_LO(p->rdata_mapping),
  1869. ETH_CONNECTION_TYPE);
  1870. if (rc)
  1871. return rc;
  1872. /* Ramrod completion is pending */
  1873. return 1;
  1874. }
  1875. static int bnx2x_wait_rx_mode_comp_e2(struct bnx2x *bp,
  1876. struct bnx2x_rx_mode_ramrod_params *p)
  1877. {
  1878. return bnx2x_state_wait(bp, p->state, p->pstate);
  1879. }
  1880. static int bnx2x_empty_rx_mode_wait(struct bnx2x *bp,
  1881. struct bnx2x_rx_mode_ramrod_params *p)
  1882. {
  1883. /* Do nothing */
  1884. return 0;
  1885. }
  1886. int bnx2x_config_rx_mode(struct bnx2x *bp,
  1887. struct bnx2x_rx_mode_ramrod_params *p)
  1888. {
  1889. int rc;
  1890. /* Configure the new classification in the chip */
  1891. rc = p->rx_mode_obj->config_rx_mode(bp, p);
  1892. if (rc < 0)
  1893. return rc;
  1894. /* Wait for a ramrod completion if was requested */
  1895. if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) {
  1896. rc = p->rx_mode_obj->wait_comp(bp, p);
  1897. if (rc)
  1898. return rc;
  1899. }
  1900. return rc;
  1901. }
  1902. void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
  1903. struct bnx2x_rx_mode_obj *o)
  1904. {
  1905. if (CHIP_IS_E1x(bp)) {
  1906. o->wait_comp = bnx2x_empty_rx_mode_wait;
  1907. o->config_rx_mode = bnx2x_set_rx_mode_e1x;
  1908. } else {
  1909. o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
  1910. o->config_rx_mode = bnx2x_set_rx_mode_e2;
  1911. }
  1912. }
  1913. /********************* Multicast verbs: SET, CLEAR ****************************/
  1914. static inline u8 bnx2x_mcast_bin_from_mac(u8 *mac)
  1915. {
  1916. return (crc32c_le(0, mac, ETH_ALEN) >> 24) & 0xff;
  1917. }
  1918. struct bnx2x_mcast_mac_elem {
  1919. struct list_head link;
  1920. u8 mac[ETH_ALEN];
  1921. u8 pad[2]; /* For a natural alignment of the following buffer */
  1922. };
  1923. struct bnx2x_pending_mcast_cmd {
  1924. struct list_head link;
  1925. int type; /* BNX2X_MCAST_CMD_X */
  1926. union {
  1927. struct list_head macs_head;
  1928. u32 macs_num; /* Needed for DEL command */
  1929. int next_bin; /* Needed for RESTORE flow with aprox match */
  1930. } data;
  1931. bool done; /* set to true, when the command has been handled,
  1932. * practically used in 57712 handling only, where one pending
  1933. * command may be handled in a few operations. As long as for
  1934. * other chips every operation handling is completed in a
  1935. * single ramrod, there is no need to utilize this field.
  1936. */
  1937. };
  1938. static int bnx2x_mcast_wait(struct bnx2x *bp,
  1939. struct bnx2x_mcast_obj *o)
  1940. {
  1941. if (bnx2x_state_wait(bp, o->sched_state, o->raw.pstate) ||
  1942. o->raw.wait_comp(bp, &o->raw))
  1943. return -EBUSY;
  1944. return 0;
  1945. }
  1946. static int bnx2x_mcast_enqueue_cmd(struct bnx2x *bp,
  1947. struct bnx2x_mcast_obj *o,
  1948. struct bnx2x_mcast_ramrod_params *p,
  1949. int cmd)
  1950. {
  1951. int total_sz;
  1952. struct bnx2x_pending_mcast_cmd *new_cmd;
  1953. struct bnx2x_mcast_mac_elem *cur_mac = NULL;
  1954. struct bnx2x_mcast_list_elem *pos;
  1955. int macs_list_len = ((cmd == BNX2X_MCAST_CMD_ADD) ?
  1956. p->mcast_list_len : 0);
  1957. /* If the command is empty ("handle pending commands only"), break */
  1958. if (!p->mcast_list_len)
  1959. return 0;
  1960. total_sz = sizeof(*new_cmd) +
  1961. macs_list_len * sizeof(struct bnx2x_mcast_mac_elem);
  1962. /* Add mcast is called under spin_lock, thus calling with GFP_ATOMIC */
  1963. new_cmd = kzalloc(total_sz, GFP_ATOMIC);
  1964. if (!new_cmd)
  1965. return -ENOMEM;
  1966. DP(BNX2X_MSG_SP, "About to enqueue a new %d command. "
  1967. "macs_list_len=%d\n", cmd, macs_list_len);
  1968. INIT_LIST_HEAD(&new_cmd->data.macs_head);
  1969. new_cmd->type = cmd;
  1970. new_cmd->done = false;
  1971. switch (cmd) {
  1972. case BNX2X_MCAST_CMD_ADD:
  1973. cur_mac = (struct bnx2x_mcast_mac_elem *)
  1974. ((u8 *)new_cmd + sizeof(*new_cmd));
  1975. /* Push the MACs of the current command into the pendig command
  1976. * MACs list: FIFO
  1977. */
  1978. list_for_each_entry(pos, &p->mcast_list, link) {
  1979. memcpy(cur_mac->mac, pos->mac, ETH_ALEN);
  1980. list_add_tail(&cur_mac->link, &new_cmd->data.macs_head);
  1981. cur_mac++;
  1982. }
  1983. break;
  1984. case BNX2X_MCAST_CMD_DEL:
  1985. new_cmd->data.macs_num = p->mcast_list_len;
  1986. break;
  1987. case BNX2X_MCAST_CMD_RESTORE:
  1988. new_cmd->data.next_bin = 0;
  1989. break;
  1990. default:
  1991. BNX2X_ERR("Unknown command: %d\n", cmd);
  1992. return -EINVAL;
  1993. }
  1994. /* Push the new pending command to the tail of the pending list: FIFO */
  1995. list_add_tail(&new_cmd->link, &o->pending_cmds_head);
  1996. o->set_sched(o);
  1997. return 1;
  1998. }
  1999. /**
  2000. * bnx2x_mcast_get_next_bin - get the next set bin (index)
  2001. *
  2002. * @o:
  2003. * @last: index to start looking from (including)
  2004. *
  2005. * returns the next found (set) bin or a negative value if none is found.
  2006. */
  2007. static inline int bnx2x_mcast_get_next_bin(struct bnx2x_mcast_obj *o, int last)
  2008. {
  2009. int i, j, inner_start = last % BIT_VEC64_ELEM_SZ;
  2010. for (i = last / BIT_VEC64_ELEM_SZ; i < BNX2X_MCAST_VEC_SZ; i++) {
  2011. if (o->registry.aprox_match.vec[i])
  2012. for (j = inner_start; j < BIT_VEC64_ELEM_SZ; j++) {
  2013. int cur_bit = j + BIT_VEC64_ELEM_SZ * i;
  2014. if (BIT_VEC64_TEST_BIT(o->registry.aprox_match.
  2015. vec, cur_bit)) {
  2016. return cur_bit;
  2017. }
  2018. }
  2019. inner_start = 0;
  2020. }
  2021. /* None found */
  2022. return -1;
  2023. }
  2024. /**
  2025. * bnx2x_mcast_clear_first_bin - find the first set bin and clear it
  2026. *
  2027. * @o:
  2028. *
  2029. * returns the index of the found bin or -1 if none is found
  2030. */
  2031. static inline int bnx2x_mcast_clear_first_bin(struct bnx2x_mcast_obj *o)
  2032. {
  2033. int cur_bit = bnx2x_mcast_get_next_bin(o, 0);
  2034. if (cur_bit >= 0)
  2035. BIT_VEC64_CLEAR_BIT(o->registry.aprox_match.vec, cur_bit);
  2036. return cur_bit;
  2037. }
  2038. static inline u8 bnx2x_mcast_get_rx_tx_flag(struct bnx2x_mcast_obj *o)
  2039. {
  2040. struct bnx2x_raw_obj *raw = &o->raw;
  2041. u8 rx_tx_flag = 0;
  2042. if ((raw->obj_type == BNX2X_OBJ_TYPE_TX) ||
  2043. (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
  2044. rx_tx_flag |= ETH_MULTICAST_RULES_CMD_TX_CMD;
  2045. if ((raw->obj_type == BNX2X_OBJ_TYPE_RX) ||
  2046. (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
  2047. rx_tx_flag |= ETH_MULTICAST_RULES_CMD_RX_CMD;
  2048. return rx_tx_flag;
  2049. }
  2050. static void bnx2x_mcast_set_one_rule_e2(struct bnx2x *bp,
  2051. struct bnx2x_mcast_obj *o, int idx,
  2052. union bnx2x_mcast_config_data *cfg_data,
  2053. int cmd)
  2054. {
  2055. struct bnx2x_raw_obj *r = &o->raw;
  2056. struct eth_multicast_rules_ramrod_data *data =
  2057. (struct eth_multicast_rules_ramrod_data *)(r->rdata);
  2058. u8 func_id = r->func_id;
  2059. u8 rx_tx_add_flag = bnx2x_mcast_get_rx_tx_flag(o);
  2060. int bin;
  2061. if ((cmd == BNX2X_MCAST_CMD_ADD) || (cmd == BNX2X_MCAST_CMD_RESTORE))
  2062. rx_tx_add_flag |= ETH_MULTICAST_RULES_CMD_IS_ADD;
  2063. data->rules[idx].cmd_general_data |= rx_tx_add_flag;
  2064. /* Get a bin and update a bins' vector */
  2065. switch (cmd) {
  2066. case BNX2X_MCAST_CMD_ADD:
  2067. bin = bnx2x_mcast_bin_from_mac(cfg_data->mac);
  2068. BIT_VEC64_SET_BIT(o->registry.aprox_match.vec, bin);
  2069. break;
  2070. case BNX2X_MCAST_CMD_DEL:
  2071. /* If there were no more bins to clear
  2072. * (bnx2x_mcast_clear_first_bin() returns -1) then we would
  2073. * clear any (0xff) bin.
  2074. * See bnx2x_mcast_validate_e2() for explanation when it may
  2075. * happen.
  2076. */
  2077. bin = bnx2x_mcast_clear_first_bin(o);
  2078. break;
  2079. case BNX2X_MCAST_CMD_RESTORE:
  2080. bin = cfg_data->bin;
  2081. break;
  2082. default:
  2083. BNX2X_ERR("Unknown command: %d\n", cmd);
  2084. return;
  2085. }
  2086. DP(BNX2X_MSG_SP, "%s bin %d\n",
  2087. ((rx_tx_add_flag & ETH_MULTICAST_RULES_CMD_IS_ADD) ?
  2088. "Setting" : "Clearing"), bin);
  2089. data->rules[idx].bin_id = (u8)bin;
  2090. data->rules[idx].func_id = func_id;
  2091. data->rules[idx].engine_id = o->engine_id;
  2092. }
  2093. /**
  2094. * bnx2x_mcast_handle_restore_cmd_e2 - restore configuration from the registry
  2095. *
  2096. * @bp: device handle
  2097. * @o:
  2098. * @start_bin: index in the registry to start from (including)
  2099. * @rdata_idx: index in the ramrod data to start from
  2100. *
  2101. * returns last handled bin index or -1 if all bins have been handled
  2102. */
  2103. static inline int bnx2x_mcast_handle_restore_cmd_e2(
  2104. struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_bin,
  2105. int *rdata_idx)
  2106. {
  2107. int cur_bin, cnt = *rdata_idx;
  2108. union bnx2x_mcast_config_data cfg_data = {0};
  2109. /* go through the registry and configure the bins from it */
  2110. for (cur_bin = bnx2x_mcast_get_next_bin(o, start_bin); cur_bin >= 0;
  2111. cur_bin = bnx2x_mcast_get_next_bin(o, cur_bin + 1)) {
  2112. cfg_data.bin = (u8)cur_bin;
  2113. o->set_one_rule(bp, o, cnt, &cfg_data,
  2114. BNX2X_MCAST_CMD_RESTORE);
  2115. cnt++;
  2116. DP(BNX2X_MSG_SP, "About to configure a bin %d\n", cur_bin);
  2117. /* Break if we reached the maximum number
  2118. * of rules.
  2119. */
  2120. if (cnt >= o->max_cmd_len)
  2121. break;
  2122. }
  2123. *rdata_idx = cnt;
  2124. return cur_bin;
  2125. }
  2126. static inline void bnx2x_mcast_hdl_pending_add_e2(struct bnx2x *bp,
  2127. struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
  2128. int *line_idx)
  2129. {
  2130. struct bnx2x_mcast_mac_elem *pmac_pos, *pmac_pos_n;
  2131. int cnt = *line_idx;
  2132. union bnx2x_mcast_config_data cfg_data = {0};
  2133. list_for_each_entry_safe(pmac_pos, pmac_pos_n, &cmd_pos->data.macs_head,
  2134. link) {
  2135. cfg_data.mac = &pmac_pos->mac[0];
  2136. o->set_one_rule(bp, o, cnt, &cfg_data, cmd_pos->type);
  2137. cnt++;
  2138. DP(BNX2X_MSG_SP, "About to configure "BNX2X_MAC_FMT
  2139. " mcast MAC\n",
  2140. BNX2X_MAC_PRN_LIST(pmac_pos->mac));
  2141. list_del(&pmac_pos->link);
  2142. /* Break if we reached the maximum number
  2143. * of rules.
  2144. */
  2145. if (cnt >= o->max_cmd_len)
  2146. break;
  2147. }
  2148. *line_idx = cnt;
  2149. /* if no more MACs to configure - we are done */
  2150. if (list_empty(&cmd_pos->data.macs_head))
  2151. cmd_pos->done = true;
  2152. }
  2153. static inline void bnx2x_mcast_hdl_pending_del_e2(struct bnx2x *bp,
  2154. struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
  2155. int *line_idx)
  2156. {
  2157. int cnt = *line_idx;
  2158. while (cmd_pos->data.macs_num) {
  2159. o->set_one_rule(bp, o, cnt, NULL, cmd_pos->type);
  2160. cnt++;
  2161. cmd_pos->data.macs_num--;
  2162. DP(BNX2X_MSG_SP, "Deleting MAC. %d left,cnt is %d\n",
  2163. cmd_pos->data.macs_num, cnt);
  2164. /* Break if we reached the maximum
  2165. * number of rules.
  2166. */
  2167. if (cnt >= o->max_cmd_len)
  2168. break;
  2169. }
  2170. *line_idx = cnt;
  2171. /* If we cleared all bins - we are done */
  2172. if (!cmd_pos->data.macs_num)
  2173. cmd_pos->done = true;
  2174. }
  2175. static inline void bnx2x_mcast_hdl_pending_restore_e2(struct bnx2x *bp,
  2176. struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
  2177. int *line_idx)
  2178. {
  2179. cmd_pos->data.next_bin = o->hdl_restore(bp, o, cmd_pos->data.next_bin,
  2180. line_idx);
  2181. if (cmd_pos->data.next_bin < 0)
  2182. /* If o->set_restore returned -1 we are done */
  2183. cmd_pos->done = true;
  2184. else
  2185. /* Start from the next bin next time */
  2186. cmd_pos->data.next_bin++;
  2187. }
  2188. static inline int bnx2x_mcast_handle_pending_cmds_e2(struct bnx2x *bp,
  2189. struct bnx2x_mcast_ramrod_params *p)
  2190. {
  2191. struct bnx2x_pending_mcast_cmd *cmd_pos, *cmd_pos_n;
  2192. int cnt = 0;
  2193. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2194. list_for_each_entry_safe(cmd_pos, cmd_pos_n, &o->pending_cmds_head,
  2195. link) {
  2196. switch (cmd_pos->type) {
  2197. case BNX2X_MCAST_CMD_ADD:
  2198. bnx2x_mcast_hdl_pending_add_e2(bp, o, cmd_pos, &cnt);
  2199. break;
  2200. case BNX2X_MCAST_CMD_DEL:
  2201. bnx2x_mcast_hdl_pending_del_e2(bp, o, cmd_pos, &cnt);
  2202. break;
  2203. case BNX2X_MCAST_CMD_RESTORE:
  2204. bnx2x_mcast_hdl_pending_restore_e2(bp, o, cmd_pos,
  2205. &cnt);
  2206. break;
  2207. default:
  2208. BNX2X_ERR("Unknown command: %d\n", cmd_pos->type);
  2209. return -EINVAL;
  2210. }
  2211. /* If the command has been completed - remove it from the list
  2212. * and free the memory
  2213. */
  2214. if (cmd_pos->done) {
  2215. list_del(&cmd_pos->link);
  2216. kfree(cmd_pos);
  2217. }
  2218. /* Break if we reached the maximum number of rules */
  2219. if (cnt >= o->max_cmd_len)
  2220. break;
  2221. }
  2222. return cnt;
  2223. }
  2224. static inline void bnx2x_mcast_hdl_add(struct bnx2x *bp,
  2225. struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
  2226. int *line_idx)
  2227. {
  2228. struct bnx2x_mcast_list_elem *mlist_pos;
  2229. union bnx2x_mcast_config_data cfg_data = {0};
  2230. int cnt = *line_idx;
  2231. list_for_each_entry(mlist_pos, &p->mcast_list, link) {
  2232. cfg_data.mac = mlist_pos->mac;
  2233. o->set_one_rule(bp, o, cnt, &cfg_data, BNX2X_MCAST_CMD_ADD);
  2234. cnt++;
  2235. DP(BNX2X_MSG_SP, "About to configure "BNX2X_MAC_FMT
  2236. " mcast MAC\n",
  2237. BNX2X_MAC_PRN_LIST(mlist_pos->mac));
  2238. }
  2239. *line_idx = cnt;
  2240. }
  2241. static inline void bnx2x_mcast_hdl_del(struct bnx2x *bp,
  2242. struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
  2243. int *line_idx)
  2244. {
  2245. int cnt = *line_idx, i;
  2246. for (i = 0; i < p->mcast_list_len; i++) {
  2247. o->set_one_rule(bp, o, cnt, NULL, BNX2X_MCAST_CMD_DEL);
  2248. cnt++;
  2249. DP(BNX2X_MSG_SP, "Deleting MAC. %d left\n",
  2250. p->mcast_list_len - i - 1);
  2251. }
  2252. *line_idx = cnt;
  2253. }
  2254. /**
  2255. * bnx2x_mcast_handle_current_cmd -
  2256. *
  2257. * @bp: device handle
  2258. * @p:
  2259. * @cmd:
  2260. * @start_cnt: first line in the ramrod data that may be used
  2261. *
  2262. * This function is called iff there is enough place for the current command in
  2263. * the ramrod data.
  2264. * Returns number of lines filled in the ramrod data in total.
  2265. */
  2266. static inline int bnx2x_mcast_handle_current_cmd(struct bnx2x *bp,
  2267. struct bnx2x_mcast_ramrod_params *p, int cmd,
  2268. int start_cnt)
  2269. {
  2270. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2271. int cnt = start_cnt;
  2272. DP(BNX2X_MSG_SP, "p->mcast_list_len=%d\n", p->mcast_list_len);
  2273. switch (cmd) {
  2274. case BNX2X_MCAST_CMD_ADD:
  2275. bnx2x_mcast_hdl_add(bp, o, p, &cnt);
  2276. break;
  2277. case BNX2X_MCAST_CMD_DEL:
  2278. bnx2x_mcast_hdl_del(bp, o, p, &cnt);
  2279. break;
  2280. case BNX2X_MCAST_CMD_RESTORE:
  2281. o->hdl_restore(bp, o, 0, &cnt);
  2282. break;
  2283. default:
  2284. BNX2X_ERR("Unknown command: %d\n", cmd);
  2285. return -EINVAL;
  2286. }
  2287. /* The current command has been handled */
  2288. p->mcast_list_len = 0;
  2289. return cnt;
  2290. }
  2291. static int bnx2x_mcast_validate_e2(struct bnx2x *bp,
  2292. struct bnx2x_mcast_ramrod_params *p,
  2293. int cmd)
  2294. {
  2295. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2296. int reg_sz = o->get_registry_size(o);
  2297. switch (cmd) {
  2298. /* DEL command deletes all currently configured MACs */
  2299. case BNX2X_MCAST_CMD_DEL:
  2300. o->set_registry_size(o, 0);
  2301. /* Don't break */
  2302. /* RESTORE command will restore the entire multicast configuration */
  2303. case BNX2X_MCAST_CMD_RESTORE:
  2304. /* Here we set the approximate amount of work to do, which in
  2305. * fact may be only less as some MACs in postponed ADD
  2306. * command(s) scheduled before this command may fall into
  2307. * the same bin and the actual number of bins set in the
  2308. * registry would be less than we estimated here. See
  2309. * bnx2x_mcast_set_one_rule_e2() for further details.
  2310. */
  2311. p->mcast_list_len = reg_sz;
  2312. break;
  2313. case BNX2X_MCAST_CMD_ADD:
  2314. case BNX2X_MCAST_CMD_CONT:
  2315. /* Here we assume that all new MACs will fall into new bins.
  2316. * However we will correct the real registry size after we
  2317. * handle all pending commands.
  2318. */
  2319. o->set_registry_size(o, reg_sz + p->mcast_list_len);
  2320. break;
  2321. default:
  2322. BNX2X_ERR("Unknown command: %d\n", cmd);
  2323. return -EINVAL;
  2324. }
  2325. /* Increase the total number of MACs pending to be configured */
  2326. o->total_pending_num += p->mcast_list_len;
  2327. return 0;
  2328. }
  2329. static void bnx2x_mcast_revert_e2(struct bnx2x *bp,
  2330. struct bnx2x_mcast_ramrod_params *p,
  2331. int old_num_bins)
  2332. {
  2333. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2334. o->set_registry_size(o, old_num_bins);
  2335. o->total_pending_num -= p->mcast_list_len;
  2336. }
  2337. /**
  2338. * bnx2x_mcast_set_rdata_hdr_e2 - sets a header values
  2339. *
  2340. * @bp: device handle
  2341. * @p:
  2342. * @len: number of rules to handle
  2343. */
  2344. static inline void bnx2x_mcast_set_rdata_hdr_e2(struct bnx2x *bp,
  2345. struct bnx2x_mcast_ramrod_params *p,
  2346. u8 len)
  2347. {
  2348. struct bnx2x_raw_obj *r = &p->mcast_obj->raw;
  2349. struct eth_multicast_rules_ramrod_data *data =
  2350. (struct eth_multicast_rules_ramrod_data *)(r->rdata);
  2351. data->header.echo = ((r->cid & BNX2X_SWCID_MASK) |
  2352. (BNX2X_FILTER_MCAST_PENDING << BNX2X_SWCID_SHIFT));
  2353. data->header.rule_cnt = len;
  2354. }
  2355. /**
  2356. * bnx2x_mcast_refresh_registry_e2 - recalculate the actual number of set bins
  2357. *
  2358. * @bp: device handle
  2359. * @o:
  2360. *
  2361. * Recalculate the actual number of set bins in the registry using Brian
  2362. * Kernighan's algorithm: it's execution complexity is as a number of set bins.
  2363. *
  2364. * returns 0 for the compliance with bnx2x_mcast_refresh_registry_e1().
  2365. */
  2366. static inline int bnx2x_mcast_refresh_registry_e2(struct bnx2x *bp,
  2367. struct bnx2x_mcast_obj *o)
  2368. {
  2369. int i, cnt = 0;
  2370. u64 elem;
  2371. for (i = 0; i < BNX2X_MCAST_VEC_SZ; i++) {
  2372. elem = o->registry.aprox_match.vec[i];
  2373. for (; elem; cnt++)
  2374. elem &= elem - 1;
  2375. }
  2376. o->set_registry_size(o, cnt);
  2377. return 0;
  2378. }
  2379. static int bnx2x_mcast_setup_e2(struct bnx2x *bp,
  2380. struct bnx2x_mcast_ramrod_params *p,
  2381. int cmd)
  2382. {
  2383. struct bnx2x_raw_obj *raw = &p->mcast_obj->raw;
  2384. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2385. struct eth_multicast_rules_ramrod_data *data =
  2386. (struct eth_multicast_rules_ramrod_data *)(raw->rdata);
  2387. int cnt = 0, rc;
  2388. /* Reset the ramrod data buffer */
  2389. memset(data, 0, sizeof(*data));
  2390. cnt = bnx2x_mcast_handle_pending_cmds_e2(bp, p);
  2391. /* If there are no more pending commands - clear SCHEDULED state */
  2392. if (list_empty(&o->pending_cmds_head))
  2393. o->clear_sched(o);
  2394. /* The below may be true iff there was enough room in ramrod
  2395. * data for all pending commands and for the current
  2396. * command. Otherwise the current command would have been added
  2397. * to the pending commands and p->mcast_list_len would have been
  2398. * zeroed.
  2399. */
  2400. if (p->mcast_list_len > 0)
  2401. cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, cnt);
  2402. /* We've pulled out some MACs - update the total number of
  2403. * outstanding.
  2404. */
  2405. o->total_pending_num -= cnt;
  2406. /* send a ramrod */
  2407. WARN_ON(o->total_pending_num < 0);
  2408. WARN_ON(cnt > o->max_cmd_len);
  2409. bnx2x_mcast_set_rdata_hdr_e2(bp, p, (u8)cnt);
  2410. /* Update a registry size if there are no more pending operations.
  2411. *
  2412. * We don't want to change the value of the registry size if there are
  2413. * pending operations because we want it to always be equal to the
  2414. * exact or the approximate number (see bnx2x_mcast_validate_e2()) of
  2415. * set bins after the last requested operation in order to properly
  2416. * evaluate the size of the next DEL/RESTORE operation.
  2417. *
  2418. * Note that we update the registry itself during command(s) handling
  2419. * - see bnx2x_mcast_set_one_rule_e2(). That's because for 57712 we
  2420. * aggregate multiple commands (ADD/DEL/RESTORE) into one ramrod but
  2421. * with a limited amount of update commands (per MAC/bin) and we don't
  2422. * know in this scope what the actual state of bins configuration is
  2423. * going to be after this ramrod.
  2424. */
  2425. if (!o->total_pending_num)
  2426. bnx2x_mcast_refresh_registry_e2(bp, o);
  2427. /* Commit writes towards the memory before sending a ramrod */
  2428. mb();
  2429. /* If CLEAR_ONLY was requested - don't send a ramrod and clear
  2430. * RAMROD_PENDING status immediately.
  2431. */
  2432. if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
  2433. raw->clear_pending(raw);
  2434. return 0;
  2435. } else {
  2436. /* Send a ramrod */
  2437. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_MULTICAST_RULES,
  2438. raw->cid, U64_HI(raw->rdata_mapping),
  2439. U64_LO(raw->rdata_mapping),
  2440. ETH_CONNECTION_TYPE);
  2441. if (rc)
  2442. return rc;
  2443. /* Ramrod completion is pending */
  2444. return 1;
  2445. }
  2446. }
  2447. static int bnx2x_mcast_validate_e1h(struct bnx2x *bp,
  2448. struct bnx2x_mcast_ramrod_params *p,
  2449. int cmd)
  2450. {
  2451. /* Mark, that there is a work to do */
  2452. if ((cmd == BNX2X_MCAST_CMD_DEL) || (cmd == BNX2X_MCAST_CMD_RESTORE))
  2453. p->mcast_list_len = 1;
  2454. return 0;
  2455. }
  2456. static void bnx2x_mcast_revert_e1h(struct bnx2x *bp,
  2457. struct bnx2x_mcast_ramrod_params *p,
  2458. int old_num_bins)
  2459. {
  2460. /* Do nothing */
  2461. }
  2462. #define BNX2X_57711_SET_MC_FILTER(filter, bit) \
  2463. do { \
  2464. (filter)[(bit) >> 5] |= (1 << ((bit) & 0x1f)); \
  2465. } while (0)
  2466. static inline void bnx2x_mcast_hdl_add_e1h(struct bnx2x *bp,
  2467. struct bnx2x_mcast_obj *o,
  2468. struct bnx2x_mcast_ramrod_params *p,
  2469. u32 *mc_filter)
  2470. {
  2471. struct bnx2x_mcast_list_elem *mlist_pos;
  2472. int bit;
  2473. list_for_each_entry(mlist_pos, &p->mcast_list, link) {
  2474. bit = bnx2x_mcast_bin_from_mac(mlist_pos->mac);
  2475. BNX2X_57711_SET_MC_FILTER(mc_filter, bit);
  2476. DP(BNX2X_MSG_SP, "About to configure "
  2477. BNX2X_MAC_FMT" mcast MAC, bin %d\n",
  2478. BNX2X_MAC_PRN_LIST(mlist_pos->mac), bit);
  2479. /* bookkeeping... */
  2480. BIT_VEC64_SET_BIT(o->registry.aprox_match.vec,
  2481. bit);
  2482. }
  2483. }
  2484. static inline void bnx2x_mcast_hdl_restore_e1h(struct bnx2x *bp,
  2485. struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
  2486. u32 *mc_filter)
  2487. {
  2488. int bit;
  2489. for (bit = bnx2x_mcast_get_next_bin(o, 0);
  2490. bit >= 0;
  2491. bit = bnx2x_mcast_get_next_bin(o, bit + 1)) {
  2492. BNX2X_57711_SET_MC_FILTER(mc_filter, bit);
  2493. DP(BNX2X_MSG_SP, "About to set bin %d\n", bit);
  2494. }
  2495. }
  2496. /* On 57711 we write the multicast MACs' aproximate match
  2497. * table by directly into the TSTORM's internal RAM. So we don't
  2498. * really need to handle any tricks to make it work.
  2499. */
  2500. static int bnx2x_mcast_setup_e1h(struct bnx2x *bp,
  2501. struct bnx2x_mcast_ramrod_params *p,
  2502. int cmd)
  2503. {
  2504. int i;
  2505. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2506. struct bnx2x_raw_obj *r = &o->raw;
  2507. /* If CLEAR_ONLY has been requested - clear the registry
  2508. * and clear a pending bit.
  2509. */
  2510. if (!test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
  2511. u32 mc_filter[MC_HASH_SIZE] = {0};
  2512. /* Set the multicast filter bits before writing it into
  2513. * the internal memory.
  2514. */
  2515. switch (cmd) {
  2516. case BNX2X_MCAST_CMD_ADD:
  2517. bnx2x_mcast_hdl_add_e1h(bp, o, p, mc_filter);
  2518. break;
  2519. case BNX2X_MCAST_CMD_DEL:
  2520. DP(BNX2X_MSG_SP, "Invalidating multicast "
  2521. "MACs configuration\n");
  2522. /* clear the registry */
  2523. memset(o->registry.aprox_match.vec, 0,
  2524. sizeof(o->registry.aprox_match.vec));
  2525. break;
  2526. case BNX2X_MCAST_CMD_RESTORE:
  2527. bnx2x_mcast_hdl_restore_e1h(bp, o, p, mc_filter);
  2528. break;
  2529. default:
  2530. BNX2X_ERR("Unknown command: %d\n", cmd);
  2531. return -EINVAL;
  2532. }
  2533. /* Set the mcast filter in the internal memory */
  2534. for (i = 0; i < MC_HASH_SIZE; i++)
  2535. REG_WR(bp, MC_HASH_OFFSET(bp, i), mc_filter[i]);
  2536. } else
  2537. /* clear the registry */
  2538. memset(o->registry.aprox_match.vec, 0,
  2539. sizeof(o->registry.aprox_match.vec));
  2540. /* We are done */
  2541. r->clear_pending(r);
  2542. return 0;
  2543. }
  2544. static int bnx2x_mcast_validate_e1(struct bnx2x *bp,
  2545. struct bnx2x_mcast_ramrod_params *p,
  2546. int cmd)
  2547. {
  2548. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2549. int reg_sz = o->get_registry_size(o);
  2550. switch (cmd) {
  2551. /* DEL command deletes all currently configured MACs */
  2552. case BNX2X_MCAST_CMD_DEL:
  2553. o->set_registry_size(o, 0);
  2554. /* Don't break */
  2555. /* RESTORE command will restore the entire multicast configuration */
  2556. case BNX2X_MCAST_CMD_RESTORE:
  2557. p->mcast_list_len = reg_sz;
  2558. DP(BNX2X_MSG_SP, "Command %d, p->mcast_list_len=%d\n",
  2559. cmd, p->mcast_list_len);
  2560. break;
  2561. case BNX2X_MCAST_CMD_ADD:
  2562. case BNX2X_MCAST_CMD_CONT:
  2563. /* Multicast MACs on 57710 are configured as unicast MACs and
  2564. * there is only a limited number of CAM entries for that
  2565. * matter.
  2566. */
  2567. if (p->mcast_list_len > o->max_cmd_len) {
  2568. BNX2X_ERR("Can't configure more than %d multicast MACs"
  2569. "on 57710\n", o->max_cmd_len);
  2570. return -EINVAL;
  2571. }
  2572. /* Every configured MAC should be cleared if DEL command is
  2573. * called. Only the last ADD command is relevant as long as
  2574. * every ADD commands overrides the previous configuration.
  2575. */
  2576. DP(BNX2X_MSG_SP, "p->mcast_list_len=%d\n", p->mcast_list_len);
  2577. if (p->mcast_list_len > 0)
  2578. o->set_registry_size(o, p->mcast_list_len);
  2579. break;
  2580. default:
  2581. BNX2X_ERR("Unknown command: %d\n", cmd);
  2582. return -EINVAL;
  2583. }
  2584. /* We want to ensure that commands are executed one by one for 57710.
  2585. * Therefore each none-empty command will consume o->max_cmd_len.
  2586. */
  2587. if (p->mcast_list_len)
  2588. o->total_pending_num += o->max_cmd_len;
  2589. return 0;
  2590. }
  2591. static void bnx2x_mcast_revert_e1(struct bnx2x *bp,
  2592. struct bnx2x_mcast_ramrod_params *p,
  2593. int old_num_macs)
  2594. {
  2595. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2596. o->set_registry_size(o, old_num_macs);
  2597. /* If current command hasn't been handled yet and we are
  2598. * here means that it's meant to be dropped and we have to
  2599. * update the number of outstandling MACs accordingly.
  2600. */
  2601. if (p->mcast_list_len)
  2602. o->total_pending_num -= o->max_cmd_len;
  2603. }
  2604. static void bnx2x_mcast_set_one_rule_e1(struct bnx2x *bp,
  2605. struct bnx2x_mcast_obj *o, int idx,
  2606. union bnx2x_mcast_config_data *cfg_data,
  2607. int cmd)
  2608. {
  2609. struct bnx2x_raw_obj *r = &o->raw;
  2610. struct mac_configuration_cmd *data =
  2611. (struct mac_configuration_cmd *)(r->rdata);
  2612. /* copy mac */
  2613. if ((cmd == BNX2X_MCAST_CMD_ADD) || (cmd == BNX2X_MCAST_CMD_RESTORE)) {
  2614. bnx2x_set_fw_mac_addr(&data->config_table[idx].msb_mac_addr,
  2615. &data->config_table[idx].middle_mac_addr,
  2616. &data->config_table[idx].lsb_mac_addr,
  2617. cfg_data->mac);
  2618. data->config_table[idx].vlan_id = 0;
  2619. data->config_table[idx].pf_id = r->func_id;
  2620. data->config_table[idx].clients_bit_vector =
  2621. cpu_to_le32(1 << r->cl_id);
  2622. SET_FLAG(data->config_table[idx].flags,
  2623. MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
  2624. T_ETH_MAC_COMMAND_SET);
  2625. }
  2626. }
  2627. /**
  2628. * bnx2x_mcast_set_rdata_hdr_e1 - set header values in mac_configuration_cmd
  2629. *
  2630. * @bp: device handle
  2631. * @p:
  2632. * @len: number of rules to handle
  2633. */
  2634. static inline void bnx2x_mcast_set_rdata_hdr_e1(struct bnx2x *bp,
  2635. struct bnx2x_mcast_ramrod_params *p,
  2636. u8 len)
  2637. {
  2638. struct bnx2x_raw_obj *r = &p->mcast_obj->raw;
  2639. struct mac_configuration_cmd *data =
  2640. (struct mac_configuration_cmd *)(r->rdata);
  2641. u8 offset = (CHIP_REV_IS_SLOW(bp) ?
  2642. BNX2X_MAX_EMUL_MULTI*(1 + r->func_id) :
  2643. BNX2X_MAX_MULTICAST*(1 + r->func_id));
  2644. data->hdr.offset = offset;
  2645. data->hdr.client_id = 0xff;
  2646. data->hdr.echo = ((r->cid & BNX2X_SWCID_MASK) |
  2647. (BNX2X_FILTER_MCAST_PENDING << BNX2X_SWCID_SHIFT));
  2648. data->hdr.length = len;
  2649. }
  2650. /**
  2651. * bnx2x_mcast_handle_restore_cmd_e1 - restore command for 57710
  2652. *
  2653. * @bp: device handle
  2654. * @o:
  2655. * @start_idx: index in the registry to start from
  2656. * @rdata_idx: index in the ramrod data to start from
  2657. *
  2658. * restore command for 57710 is like all other commands - always a stand alone
  2659. * command - start_idx and rdata_idx will always be 0. This function will always
  2660. * succeed.
  2661. * returns -1 to comply with 57712 variant.
  2662. */
  2663. static inline int bnx2x_mcast_handle_restore_cmd_e1(
  2664. struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_idx,
  2665. int *rdata_idx)
  2666. {
  2667. struct bnx2x_mcast_mac_elem *elem;
  2668. int i = 0;
  2669. union bnx2x_mcast_config_data cfg_data = {0};
  2670. /* go through the registry and configure the MACs from it. */
  2671. list_for_each_entry(elem, &o->registry.exact_match.macs, link) {
  2672. cfg_data.mac = &elem->mac[0];
  2673. o->set_one_rule(bp, o, i, &cfg_data, BNX2X_MCAST_CMD_RESTORE);
  2674. i++;
  2675. DP(BNX2X_MSG_SP, "About to configure "BNX2X_MAC_FMT
  2676. " mcast MAC\n",
  2677. BNX2X_MAC_PRN_LIST(cfg_data.mac));
  2678. }
  2679. *rdata_idx = i;
  2680. return -1;
  2681. }
  2682. static inline int bnx2x_mcast_handle_pending_cmds_e1(
  2683. struct bnx2x *bp, struct bnx2x_mcast_ramrod_params *p)
  2684. {
  2685. struct bnx2x_pending_mcast_cmd *cmd_pos;
  2686. struct bnx2x_mcast_mac_elem *pmac_pos;
  2687. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2688. union bnx2x_mcast_config_data cfg_data = {0};
  2689. int cnt = 0;
  2690. /* If nothing to be done - return */
  2691. if (list_empty(&o->pending_cmds_head))
  2692. return 0;
  2693. /* Handle the first command */
  2694. cmd_pos = list_first_entry(&o->pending_cmds_head,
  2695. struct bnx2x_pending_mcast_cmd, link);
  2696. switch (cmd_pos->type) {
  2697. case BNX2X_MCAST_CMD_ADD:
  2698. list_for_each_entry(pmac_pos, &cmd_pos->data.macs_head, link) {
  2699. cfg_data.mac = &pmac_pos->mac[0];
  2700. o->set_one_rule(bp, o, cnt, &cfg_data, cmd_pos->type);
  2701. cnt++;
  2702. DP(BNX2X_MSG_SP, "About to configure "BNX2X_MAC_FMT
  2703. " mcast MAC\n",
  2704. BNX2X_MAC_PRN_LIST(pmac_pos->mac));
  2705. }
  2706. break;
  2707. case BNX2X_MCAST_CMD_DEL:
  2708. cnt = cmd_pos->data.macs_num;
  2709. DP(BNX2X_MSG_SP, "About to delete %d multicast MACs\n", cnt);
  2710. break;
  2711. case BNX2X_MCAST_CMD_RESTORE:
  2712. o->hdl_restore(bp, o, 0, &cnt);
  2713. break;
  2714. default:
  2715. BNX2X_ERR("Unknown command: %d\n", cmd_pos->type);
  2716. return -EINVAL;
  2717. }
  2718. list_del(&cmd_pos->link);
  2719. kfree(cmd_pos);
  2720. return cnt;
  2721. }
  2722. /**
  2723. * bnx2x_get_fw_mac_addr - revert the bnx2x_set_fw_mac_addr().
  2724. *
  2725. * @fw_hi:
  2726. * @fw_mid:
  2727. * @fw_lo:
  2728. * @mac:
  2729. */
  2730. static inline void bnx2x_get_fw_mac_addr(__le16 *fw_hi, __le16 *fw_mid,
  2731. __le16 *fw_lo, u8 *mac)
  2732. {
  2733. mac[1] = ((u8 *)fw_hi)[0];
  2734. mac[0] = ((u8 *)fw_hi)[1];
  2735. mac[3] = ((u8 *)fw_mid)[0];
  2736. mac[2] = ((u8 *)fw_mid)[1];
  2737. mac[5] = ((u8 *)fw_lo)[0];
  2738. mac[4] = ((u8 *)fw_lo)[1];
  2739. }
  2740. /**
  2741. * bnx2x_mcast_refresh_registry_e1 -
  2742. *
  2743. * @bp: device handle
  2744. * @cnt:
  2745. *
  2746. * Check the ramrod data first entry flag to see if it's a DELETE or ADD command
  2747. * and update the registry correspondingly: if ADD - allocate a memory and add
  2748. * the entries to the registry (list), if DELETE - clear the registry and free
  2749. * the memory.
  2750. */
  2751. static inline int bnx2x_mcast_refresh_registry_e1(struct bnx2x *bp,
  2752. struct bnx2x_mcast_obj *o)
  2753. {
  2754. struct bnx2x_raw_obj *raw = &o->raw;
  2755. struct bnx2x_mcast_mac_elem *elem;
  2756. struct mac_configuration_cmd *data =
  2757. (struct mac_configuration_cmd *)(raw->rdata);
  2758. /* If first entry contains a SET bit - the command was ADD,
  2759. * otherwise - DEL_ALL
  2760. */
  2761. if (GET_FLAG(data->config_table[0].flags,
  2762. MAC_CONFIGURATION_ENTRY_ACTION_TYPE)) {
  2763. int i, len = data->hdr.length;
  2764. /* Break if it was a RESTORE command */
  2765. if (!list_empty(&o->registry.exact_match.macs))
  2766. return 0;
  2767. elem = kzalloc(sizeof(*elem)*len, GFP_ATOMIC);
  2768. if (!elem) {
  2769. BNX2X_ERR("Failed to allocate registry memory\n");
  2770. return -ENOMEM;
  2771. }
  2772. for (i = 0; i < len; i++, elem++) {
  2773. bnx2x_get_fw_mac_addr(
  2774. &data->config_table[i].msb_mac_addr,
  2775. &data->config_table[i].middle_mac_addr,
  2776. &data->config_table[i].lsb_mac_addr,
  2777. elem->mac);
  2778. DP(BNX2X_MSG_SP, "Adding registry entry for ["
  2779. BNX2X_MAC_FMT"]\n",
  2780. BNX2X_MAC_PRN_LIST(elem->mac));
  2781. list_add_tail(&elem->link,
  2782. &o->registry.exact_match.macs);
  2783. }
  2784. } else {
  2785. elem = list_first_entry(&o->registry.exact_match.macs,
  2786. struct bnx2x_mcast_mac_elem, link);
  2787. DP(BNX2X_MSG_SP, "Deleting a registry\n");
  2788. kfree(elem);
  2789. INIT_LIST_HEAD(&o->registry.exact_match.macs);
  2790. }
  2791. return 0;
  2792. }
  2793. static int bnx2x_mcast_setup_e1(struct bnx2x *bp,
  2794. struct bnx2x_mcast_ramrod_params *p,
  2795. int cmd)
  2796. {
  2797. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2798. struct bnx2x_raw_obj *raw = &o->raw;
  2799. struct mac_configuration_cmd *data =
  2800. (struct mac_configuration_cmd *)(raw->rdata);
  2801. int cnt = 0, i, rc;
  2802. /* Reset the ramrod data buffer */
  2803. memset(data, 0, sizeof(*data));
  2804. /* First set all entries as invalid */
  2805. for (i = 0; i < o->max_cmd_len ; i++)
  2806. SET_FLAG(data->config_table[i].flags,
  2807. MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
  2808. T_ETH_MAC_COMMAND_INVALIDATE);
  2809. /* Handle pending commands first */
  2810. cnt = bnx2x_mcast_handle_pending_cmds_e1(bp, p);
  2811. /* If there are no more pending commands - clear SCHEDULED state */
  2812. if (list_empty(&o->pending_cmds_head))
  2813. o->clear_sched(o);
  2814. /* The below may be true iff there were no pending commands */
  2815. if (!cnt)
  2816. cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, 0);
  2817. /* For 57710 every command has o->max_cmd_len length to ensure that
  2818. * commands are done one at a time.
  2819. */
  2820. o->total_pending_num -= o->max_cmd_len;
  2821. /* send a ramrod */
  2822. WARN_ON(cnt > o->max_cmd_len);
  2823. /* Set ramrod header (in particular, a number of entries to update) */
  2824. bnx2x_mcast_set_rdata_hdr_e1(bp, p, (u8)cnt);
  2825. /* update a registry: we need the registry contents to be always up
  2826. * to date in order to be able to execute a RESTORE opcode. Here
  2827. * we use the fact that for 57710 we sent one command at a time
  2828. * hence we may take the registry update out of the command handling
  2829. * and do it in a simpler way here.
  2830. */
  2831. rc = bnx2x_mcast_refresh_registry_e1(bp, o);
  2832. if (rc)
  2833. return rc;
  2834. /* Commit writes towards the memory before sending a ramrod */
  2835. mb();
  2836. /* If CLEAR_ONLY was requested - don't send a ramrod and clear
  2837. * RAMROD_PENDING status immediately.
  2838. */
  2839. if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
  2840. raw->clear_pending(raw);
  2841. return 0;
  2842. } else {
  2843. /* Send a ramrod */
  2844. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, raw->cid,
  2845. U64_HI(raw->rdata_mapping),
  2846. U64_LO(raw->rdata_mapping),
  2847. ETH_CONNECTION_TYPE);
  2848. if (rc)
  2849. return rc;
  2850. /* Ramrod completion is pending */
  2851. return 1;
  2852. }
  2853. }
  2854. static int bnx2x_mcast_get_registry_size_exact(struct bnx2x_mcast_obj *o)
  2855. {
  2856. return o->registry.exact_match.num_macs_set;
  2857. }
  2858. static int bnx2x_mcast_get_registry_size_aprox(struct bnx2x_mcast_obj *o)
  2859. {
  2860. return o->registry.aprox_match.num_bins_set;
  2861. }
  2862. static void bnx2x_mcast_set_registry_size_exact(struct bnx2x_mcast_obj *o,
  2863. int n)
  2864. {
  2865. o->registry.exact_match.num_macs_set = n;
  2866. }
  2867. static void bnx2x_mcast_set_registry_size_aprox(struct bnx2x_mcast_obj *o,
  2868. int n)
  2869. {
  2870. o->registry.aprox_match.num_bins_set = n;
  2871. }
  2872. int bnx2x_config_mcast(struct bnx2x *bp,
  2873. struct bnx2x_mcast_ramrod_params *p,
  2874. int cmd)
  2875. {
  2876. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2877. struct bnx2x_raw_obj *r = &o->raw;
  2878. int rc = 0, old_reg_size;
  2879. /* This is needed to recover number of currently configured mcast macs
  2880. * in case of failure.
  2881. */
  2882. old_reg_size = o->get_registry_size(o);
  2883. /* Do some calculations and checks */
  2884. rc = o->validate(bp, p, cmd);
  2885. if (rc)
  2886. return rc;
  2887. /* Return if there is no work to do */
  2888. if ((!p->mcast_list_len) && (!o->check_sched(o)))
  2889. return 0;
  2890. DP(BNX2X_MSG_SP, "o->total_pending_num=%d p->mcast_list_len=%d "
  2891. "o->max_cmd_len=%d\n", o->total_pending_num,
  2892. p->mcast_list_len, o->max_cmd_len);
  2893. /* Enqueue the current command to the pending list if we can't complete
  2894. * it in the current iteration
  2895. */
  2896. if (r->check_pending(r) ||
  2897. ((o->max_cmd_len > 0) && (o->total_pending_num > o->max_cmd_len))) {
  2898. rc = o->enqueue_cmd(bp, p->mcast_obj, p, cmd);
  2899. if (rc < 0)
  2900. goto error_exit1;
  2901. /* As long as the current command is in a command list we
  2902. * don't need to handle it separately.
  2903. */
  2904. p->mcast_list_len = 0;
  2905. }
  2906. if (!r->check_pending(r)) {
  2907. /* Set 'pending' state */
  2908. r->set_pending(r);
  2909. /* Configure the new classification in the chip */
  2910. rc = o->config_mcast(bp, p, cmd);
  2911. if (rc < 0)
  2912. goto error_exit2;
  2913. /* Wait for a ramrod completion if was requested */
  2914. if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags))
  2915. rc = o->wait_comp(bp, o);
  2916. }
  2917. return rc;
  2918. error_exit2:
  2919. r->clear_pending(r);
  2920. error_exit1:
  2921. o->revert(bp, p, old_reg_size);
  2922. return rc;
  2923. }
  2924. static void bnx2x_mcast_clear_sched(struct bnx2x_mcast_obj *o)
  2925. {
  2926. smp_mb__before_clear_bit();
  2927. clear_bit(o->sched_state, o->raw.pstate);
  2928. smp_mb__after_clear_bit();
  2929. }
  2930. static void bnx2x_mcast_set_sched(struct bnx2x_mcast_obj *o)
  2931. {
  2932. smp_mb__before_clear_bit();
  2933. set_bit(o->sched_state, o->raw.pstate);
  2934. smp_mb__after_clear_bit();
  2935. }
  2936. static bool bnx2x_mcast_check_sched(struct bnx2x_mcast_obj *o)
  2937. {
  2938. return !!test_bit(o->sched_state, o->raw.pstate);
  2939. }
  2940. static bool bnx2x_mcast_check_pending(struct bnx2x_mcast_obj *o)
  2941. {
  2942. return o->raw.check_pending(&o->raw) || o->check_sched(o);
  2943. }
  2944. void bnx2x_init_mcast_obj(struct bnx2x *bp,
  2945. struct bnx2x_mcast_obj *mcast_obj,
  2946. u8 mcast_cl_id, u32 mcast_cid, u8 func_id,
  2947. u8 engine_id, void *rdata, dma_addr_t rdata_mapping,
  2948. int state, unsigned long *pstate, bnx2x_obj_type type)
  2949. {
  2950. memset(mcast_obj, 0, sizeof(*mcast_obj));
  2951. bnx2x_init_raw_obj(&mcast_obj->raw, mcast_cl_id, mcast_cid, func_id,
  2952. rdata, rdata_mapping, state, pstate, type);
  2953. mcast_obj->engine_id = engine_id;
  2954. INIT_LIST_HEAD(&mcast_obj->pending_cmds_head);
  2955. mcast_obj->sched_state = BNX2X_FILTER_MCAST_SCHED;
  2956. mcast_obj->check_sched = bnx2x_mcast_check_sched;
  2957. mcast_obj->set_sched = bnx2x_mcast_set_sched;
  2958. mcast_obj->clear_sched = bnx2x_mcast_clear_sched;
  2959. if (CHIP_IS_E1(bp)) {
  2960. mcast_obj->config_mcast = bnx2x_mcast_setup_e1;
  2961. mcast_obj->enqueue_cmd = bnx2x_mcast_enqueue_cmd;
  2962. mcast_obj->hdl_restore =
  2963. bnx2x_mcast_handle_restore_cmd_e1;
  2964. mcast_obj->check_pending = bnx2x_mcast_check_pending;
  2965. if (CHIP_REV_IS_SLOW(bp))
  2966. mcast_obj->max_cmd_len = BNX2X_MAX_EMUL_MULTI;
  2967. else
  2968. mcast_obj->max_cmd_len = BNX2X_MAX_MULTICAST;
  2969. mcast_obj->wait_comp = bnx2x_mcast_wait;
  2970. mcast_obj->set_one_rule = bnx2x_mcast_set_one_rule_e1;
  2971. mcast_obj->validate = bnx2x_mcast_validate_e1;
  2972. mcast_obj->revert = bnx2x_mcast_revert_e1;
  2973. mcast_obj->get_registry_size =
  2974. bnx2x_mcast_get_registry_size_exact;
  2975. mcast_obj->set_registry_size =
  2976. bnx2x_mcast_set_registry_size_exact;
  2977. /* 57710 is the only chip that uses the exact match for mcast
  2978. * at the moment.
  2979. */
  2980. INIT_LIST_HEAD(&mcast_obj->registry.exact_match.macs);
  2981. } else if (CHIP_IS_E1H(bp)) {
  2982. mcast_obj->config_mcast = bnx2x_mcast_setup_e1h;
  2983. mcast_obj->enqueue_cmd = NULL;
  2984. mcast_obj->hdl_restore = NULL;
  2985. mcast_obj->check_pending = bnx2x_mcast_check_pending;
  2986. /* 57711 doesn't send a ramrod, so it has unlimited credit
  2987. * for one command.
  2988. */
  2989. mcast_obj->max_cmd_len = -1;
  2990. mcast_obj->wait_comp = bnx2x_mcast_wait;
  2991. mcast_obj->set_one_rule = NULL;
  2992. mcast_obj->validate = bnx2x_mcast_validate_e1h;
  2993. mcast_obj->revert = bnx2x_mcast_revert_e1h;
  2994. mcast_obj->get_registry_size =
  2995. bnx2x_mcast_get_registry_size_aprox;
  2996. mcast_obj->set_registry_size =
  2997. bnx2x_mcast_set_registry_size_aprox;
  2998. } else {
  2999. mcast_obj->config_mcast = bnx2x_mcast_setup_e2;
  3000. mcast_obj->enqueue_cmd = bnx2x_mcast_enqueue_cmd;
  3001. mcast_obj->hdl_restore =
  3002. bnx2x_mcast_handle_restore_cmd_e2;
  3003. mcast_obj->check_pending = bnx2x_mcast_check_pending;
  3004. /* TODO: There should be a proper HSI define for this number!!!
  3005. */
  3006. mcast_obj->max_cmd_len = 16;
  3007. mcast_obj->wait_comp = bnx2x_mcast_wait;
  3008. mcast_obj->set_one_rule = bnx2x_mcast_set_one_rule_e2;
  3009. mcast_obj->validate = bnx2x_mcast_validate_e2;
  3010. mcast_obj->revert = bnx2x_mcast_revert_e2;
  3011. mcast_obj->get_registry_size =
  3012. bnx2x_mcast_get_registry_size_aprox;
  3013. mcast_obj->set_registry_size =
  3014. bnx2x_mcast_set_registry_size_aprox;
  3015. }
  3016. }
  3017. /*************************** Credit handling **********************************/
  3018. /**
  3019. * atomic_add_ifless - add if the result is less than a given value.
  3020. *
  3021. * @v: pointer of type atomic_t
  3022. * @a: the amount to add to v...
  3023. * @u: ...if (v + a) is less than u.
  3024. *
  3025. * returns true if (v + a) was less than u, and false otherwise.
  3026. *
  3027. */
  3028. static inline bool __atomic_add_ifless(atomic_t *v, int a, int u)
  3029. {
  3030. int c, old;
  3031. c = atomic_read(v);
  3032. for (;;) {
  3033. if (unlikely(c + a >= u))
  3034. return false;
  3035. old = atomic_cmpxchg((v), c, c + a);
  3036. if (likely(old == c))
  3037. break;
  3038. c = old;
  3039. }
  3040. return true;
  3041. }
  3042. /**
  3043. * atomic_dec_ifmoe - dec if the result is more or equal than a given value.
  3044. *
  3045. * @v: pointer of type atomic_t
  3046. * @a: the amount to dec from v...
  3047. * @u: ...if (v - a) is more or equal than u.
  3048. *
  3049. * returns true if (v - a) was more or equal than u, and false
  3050. * otherwise.
  3051. */
  3052. static inline bool __atomic_dec_ifmoe(atomic_t *v, int a, int u)
  3053. {
  3054. int c, old;
  3055. c = atomic_read(v);
  3056. for (;;) {
  3057. if (unlikely(c - a < u))
  3058. return false;
  3059. old = atomic_cmpxchg((v), c, c - a);
  3060. if (likely(old == c))
  3061. break;
  3062. c = old;
  3063. }
  3064. return true;
  3065. }
  3066. static bool bnx2x_credit_pool_get(struct bnx2x_credit_pool_obj *o, int cnt)
  3067. {
  3068. bool rc;
  3069. smp_mb();
  3070. rc = __atomic_dec_ifmoe(&o->credit, cnt, 0);
  3071. smp_mb();
  3072. return rc;
  3073. }
  3074. static bool bnx2x_credit_pool_put(struct bnx2x_credit_pool_obj *o, int cnt)
  3075. {
  3076. bool rc;
  3077. smp_mb();
  3078. /* Don't let to refill if credit + cnt > pool_sz */
  3079. rc = __atomic_add_ifless(&o->credit, cnt, o->pool_sz + 1);
  3080. smp_mb();
  3081. return rc;
  3082. }
  3083. static int bnx2x_credit_pool_check(struct bnx2x_credit_pool_obj *o)
  3084. {
  3085. int cur_credit;
  3086. smp_mb();
  3087. cur_credit = atomic_read(&o->credit);
  3088. return cur_credit;
  3089. }
  3090. static bool bnx2x_credit_pool_always_true(struct bnx2x_credit_pool_obj *o,
  3091. int cnt)
  3092. {
  3093. return true;
  3094. }
  3095. static bool bnx2x_credit_pool_get_entry(
  3096. struct bnx2x_credit_pool_obj *o,
  3097. int *offset)
  3098. {
  3099. int idx, vec, i;
  3100. *offset = -1;
  3101. /* Find "internal cam-offset" then add to base for this object... */
  3102. for (vec = 0; vec < BNX2X_POOL_VEC_SIZE; vec++) {
  3103. /* Skip the current vector if there are no free entries in it */
  3104. if (!o->pool_mirror[vec])
  3105. continue;
  3106. /* If we've got here we are going to find a free entry */
  3107. for (idx = vec * BNX2X_POOL_VEC_SIZE, i = 0;
  3108. i < BIT_VEC64_ELEM_SZ; idx++, i++)
  3109. if (BIT_VEC64_TEST_BIT(o->pool_mirror, idx)) {
  3110. /* Got one!! */
  3111. BIT_VEC64_CLEAR_BIT(o->pool_mirror, idx);
  3112. *offset = o->base_pool_offset + idx;
  3113. return true;
  3114. }
  3115. }
  3116. return false;
  3117. }
  3118. static bool bnx2x_credit_pool_put_entry(
  3119. struct bnx2x_credit_pool_obj *o,
  3120. int offset)
  3121. {
  3122. if (offset < o->base_pool_offset)
  3123. return false;
  3124. offset -= o->base_pool_offset;
  3125. if (offset >= o->pool_sz)
  3126. return false;
  3127. /* Return the entry to the pool */
  3128. BIT_VEC64_SET_BIT(o->pool_mirror, offset);
  3129. return true;
  3130. }
  3131. static bool bnx2x_credit_pool_put_entry_always_true(
  3132. struct bnx2x_credit_pool_obj *o,
  3133. int offset)
  3134. {
  3135. return true;
  3136. }
  3137. static bool bnx2x_credit_pool_get_entry_always_true(
  3138. struct bnx2x_credit_pool_obj *o,
  3139. int *offset)
  3140. {
  3141. *offset = -1;
  3142. return true;
  3143. }
  3144. /**
  3145. * bnx2x_init_credit_pool - initialize credit pool internals.
  3146. *
  3147. * @p:
  3148. * @base: Base entry in the CAM to use.
  3149. * @credit: pool size.
  3150. *
  3151. * If base is negative no CAM entries handling will be performed.
  3152. * If credit is negative pool operations will always succeed (unlimited pool).
  3153. *
  3154. */
  3155. static inline void bnx2x_init_credit_pool(struct bnx2x_credit_pool_obj *p,
  3156. int base, int credit)
  3157. {
  3158. /* Zero the object first */
  3159. memset(p, 0, sizeof(*p));
  3160. /* Set the table to all 1s */
  3161. memset(&p->pool_mirror, 0xff, sizeof(p->pool_mirror));
  3162. /* Init a pool as full */
  3163. atomic_set(&p->credit, credit);
  3164. /* The total poll size */
  3165. p->pool_sz = credit;
  3166. p->base_pool_offset = base;
  3167. /* Commit the change */
  3168. smp_mb();
  3169. p->check = bnx2x_credit_pool_check;
  3170. /* if pool credit is negative - disable the checks */
  3171. if (credit >= 0) {
  3172. p->put = bnx2x_credit_pool_put;
  3173. p->get = bnx2x_credit_pool_get;
  3174. p->put_entry = bnx2x_credit_pool_put_entry;
  3175. p->get_entry = bnx2x_credit_pool_get_entry;
  3176. } else {
  3177. p->put = bnx2x_credit_pool_always_true;
  3178. p->get = bnx2x_credit_pool_always_true;
  3179. p->put_entry = bnx2x_credit_pool_put_entry_always_true;
  3180. p->get_entry = bnx2x_credit_pool_get_entry_always_true;
  3181. }
  3182. /* If base is negative - disable entries handling */
  3183. if (base < 0) {
  3184. p->put_entry = bnx2x_credit_pool_put_entry_always_true;
  3185. p->get_entry = bnx2x_credit_pool_get_entry_always_true;
  3186. }
  3187. }
  3188. void bnx2x_init_mac_credit_pool(struct bnx2x *bp,
  3189. struct bnx2x_credit_pool_obj *p, u8 func_id,
  3190. u8 func_num)
  3191. {
  3192. /* TODO: this will be defined in consts as well... */
  3193. #define BNX2X_CAM_SIZE_EMUL 5
  3194. int cam_sz;
  3195. if (CHIP_IS_E1(bp)) {
  3196. /* In E1, Multicast is saved in cam... */
  3197. if (!CHIP_REV_IS_SLOW(bp))
  3198. cam_sz = (MAX_MAC_CREDIT_E1 / 2) - BNX2X_MAX_MULTICAST;
  3199. else
  3200. cam_sz = BNX2X_CAM_SIZE_EMUL - BNX2X_MAX_EMUL_MULTI;
  3201. bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
  3202. } else if (CHIP_IS_E1H(bp)) {
  3203. /* CAM credit is equaly divided between all active functions
  3204. * on the PORT!.
  3205. */
  3206. if ((func_num > 0)) {
  3207. if (!CHIP_REV_IS_SLOW(bp))
  3208. cam_sz = (MAX_MAC_CREDIT_E1H / (2*func_num));
  3209. else
  3210. cam_sz = BNX2X_CAM_SIZE_EMUL;
  3211. bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
  3212. } else {
  3213. /* this should never happen! Block MAC operations. */
  3214. bnx2x_init_credit_pool(p, 0, 0);
  3215. }
  3216. } else {
  3217. /*
  3218. * CAM credit is equaly divided between all active functions
  3219. * on the PATH.
  3220. */
  3221. if ((func_num > 0)) {
  3222. if (!CHIP_REV_IS_SLOW(bp))
  3223. cam_sz = (MAX_MAC_CREDIT_E2 / func_num);
  3224. else
  3225. cam_sz = BNX2X_CAM_SIZE_EMUL;
  3226. /*
  3227. * No need for CAM entries handling for 57712 and
  3228. * newer.
  3229. */
  3230. bnx2x_init_credit_pool(p, -1, cam_sz);
  3231. } else {
  3232. /* this should never happen! Block MAC operations. */
  3233. bnx2x_init_credit_pool(p, 0, 0);
  3234. }
  3235. }
  3236. }
  3237. void bnx2x_init_vlan_credit_pool(struct bnx2x *bp,
  3238. struct bnx2x_credit_pool_obj *p,
  3239. u8 func_id,
  3240. u8 func_num)
  3241. {
  3242. if (CHIP_IS_E1x(bp)) {
  3243. /*
  3244. * There is no VLAN credit in HW on 57710 and 57711 only
  3245. * MAC / MAC-VLAN can be set
  3246. */
  3247. bnx2x_init_credit_pool(p, 0, -1);
  3248. } else {
  3249. /*
  3250. * CAM credit is equaly divided between all active functions
  3251. * on the PATH.
  3252. */
  3253. if (func_num > 0) {
  3254. int credit = MAX_VLAN_CREDIT_E2 / func_num;
  3255. bnx2x_init_credit_pool(p, func_id * credit, credit);
  3256. } else
  3257. /* this should never happen! Block VLAN operations. */
  3258. bnx2x_init_credit_pool(p, 0, 0);
  3259. }
  3260. }
  3261. /****************** RSS Configuration ******************/
  3262. /**
  3263. * bnx2x_debug_print_ind_table - prints the indirection table configuration.
  3264. *
  3265. * @bp: driver hanlde
  3266. * @p: pointer to rss configuration
  3267. *
  3268. * Prints it when NETIF_MSG_IFUP debug level is configured.
  3269. */
  3270. static inline void bnx2x_debug_print_ind_table(struct bnx2x *bp,
  3271. struct bnx2x_config_rss_params *p)
  3272. {
  3273. int i;
  3274. DP(BNX2X_MSG_SP, "Setting indirection table to:\n");
  3275. DP(BNX2X_MSG_SP, "0x0000: ");
  3276. for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++) {
  3277. DP_CONT(BNX2X_MSG_SP, "0x%02x ", p->ind_table[i]);
  3278. /* Print 4 bytes in a line */
  3279. if ((i + 1 < T_ETH_INDIRECTION_TABLE_SIZE) &&
  3280. (((i + 1) & 0x3) == 0)) {
  3281. DP_CONT(BNX2X_MSG_SP, "\n");
  3282. DP(BNX2X_MSG_SP, "0x%04x: ", i + 1);
  3283. }
  3284. }
  3285. DP_CONT(BNX2X_MSG_SP, "\n");
  3286. }
  3287. /**
  3288. * bnx2x_setup_rss - configure RSS
  3289. *
  3290. * @bp: device handle
  3291. * @p: rss configuration
  3292. *
  3293. * sends on UPDATE ramrod for that matter.
  3294. */
  3295. static int bnx2x_setup_rss(struct bnx2x *bp,
  3296. struct bnx2x_config_rss_params *p)
  3297. {
  3298. struct bnx2x_rss_config_obj *o = p->rss_obj;
  3299. struct bnx2x_raw_obj *r = &o->raw;
  3300. struct eth_rss_update_ramrod_data *data =
  3301. (struct eth_rss_update_ramrod_data *)(r->rdata);
  3302. u8 rss_mode = 0;
  3303. int rc;
  3304. memset(data, 0, sizeof(*data));
  3305. DP(BNX2X_MSG_SP, "Configuring RSS\n");
  3306. /* Set an echo field */
  3307. data->echo = (r->cid & BNX2X_SWCID_MASK) |
  3308. (r->state << BNX2X_SWCID_SHIFT);
  3309. /* RSS mode */
  3310. if (test_bit(BNX2X_RSS_MODE_DISABLED, &p->rss_flags))
  3311. rss_mode = ETH_RSS_MODE_DISABLED;
  3312. else if (test_bit(BNX2X_RSS_MODE_REGULAR, &p->rss_flags))
  3313. rss_mode = ETH_RSS_MODE_REGULAR;
  3314. else if (test_bit(BNX2X_RSS_MODE_VLAN_PRI, &p->rss_flags))
  3315. rss_mode = ETH_RSS_MODE_VLAN_PRI;
  3316. else if (test_bit(BNX2X_RSS_MODE_E1HOV_PRI, &p->rss_flags))
  3317. rss_mode = ETH_RSS_MODE_E1HOV_PRI;
  3318. else if (test_bit(BNX2X_RSS_MODE_IP_DSCP, &p->rss_flags))
  3319. rss_mode = ETH_RSS_MODE_IP_DSCP;
  3320. data->rss_mode = rss_mode;
  3321. DP(BNX2X_MSG_SP, "rss_mode=%d\n", rss_mode);
  3322. /* RSS capabilities */
  3323. if (test_bit(BNX2X_RSS_IPV4, &p->rss_flags))
  3324. data->capabilities |=
  3325. ETH_RSS_UPDATE_RAMROD_DATA_IPV4_CAPABILITY;
  3326. if (test_bit(BNX2X_RSS_IPV4_TCP, &p->rss_flags))
  3327. data->capabilities |=
  3328. ETH_RSS_UPDATE_RAMROD_DATA_IPV4_TCP_CAPABILITY;
  3329. if (test_bit(BNX2X_RSS_IPV6, &p->rss_flags))
  3330. data->capabilities |=
  3331. ETH_RSS_UPDATE_RAMROD_DATA_IPV6_CAPABILITY;
  3332. if (test_bit(BNX2X_RSS_IPV6_TCP, &p->rss_flags))
  3333. data->capabilities |=
  3334. ETH_RSS_UPDATE_RAMROD_DATA_IPV6_TCP_CAPABILITY;
  3335. /* Hashing mask */
  3336. data->rss_result_mask = p->rss_result_mask;
  3337. /* RSS engine ID */
  3338. data->rss_engine_id = o->engine_id;
  3339. DP(BNX2X_MSG_SP, "rss_engine_id=%d\n", data->rss_engine_id);
  3340. /* Indirection table */
  3341. memcpy(data->indirection_table, p->ind_table,
  3342. T_ETH_INDIRECTION_TABLE_SIZE);
  3343. /* Remember the last configuration */
  3344. memcpy(o->ind_table, p->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
  3345. /* Print the indirection table */
  3346. if (netif_msg_ifup(bp))
  3347. bnx2x_debug_print_ind_table(bp, p);
  3348. /* RSS keys */
  3349. if (test_bit(BNX2X_RSS_SET_SRCH, &p->rss_flags)) {
  3350. memcpy(&data->rss_key[0], &p->rss_key[0],
  3351. sizeof(data->rss_key));
  3352. data->capabilities |= ETH_RSS_UPDATE_RAMROD_DATA_UPDATE_RSS_KEY;
  3353. }
  3354. /* Commit writes towards the memory before sending a ramrod */
  3355. mb();
  3356. /* Send a ramrod */
  3357. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_RSS_UPDATE, r->cid,
  3358. U64_HI(r->rdata_mapping),
  3359. U64_LO(r->rdata_mapping),
  3360. ETH_CONNECTION_TYPE);
  3361. if (rc < 0)
  3362. return rc;
  3363. return 1;
  3364. }
  3365. void bnx2x_get_rss_ind_table(struct bnx2x_rss_config_obj *rss_obj,
  3366. u8 *ind_table)
  3367. {
  3368. memcpy(ind_table, rss_obj->ind_table, sizeof(rss_obj->ind_table));
  3369. }
  3370. int bnx2x_config_rss(struct bnx2x *bp,
  3371. struct bnx2x_config_rss_params *p)
  3372. {
  3373. int rc;
  3374. struct bnx2x_rss_config_obj *o = p->rss_obj;
  3375. struct bnx2x_raw_obj *r = &o->raw;
  3376. /* Do nothing if only driver cleanup was requested */
  3377. if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags))
  3378. return 0;
  3379. r->set_pending(r);
  3380. rc = o->config_rss(bp, p);
  3381. if (rc < 0) {
  3382. r->clear_pending(r);
  3383. return rc;
  3384. }
  3385. if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags))
  3386. rc = r->wait_comp(bp, r);
  3387. return rc;
  3388. }
  3389. void bnx2x_init_rss_config_obj(struct bnx2x *bp,
  3390. struct bnx2x_rss_config_obj *rss_obj,
  3391. u8 cl_id, u32 cid, u8 func_id, u8 engine_id,
  3392. void *rdata, dma_addr_t rdata_mapping,
  3393. int state, unsigned long *pstate,
  3394. bnx2x_obj_type type)
  3395. {
  3396. bnx2x_init_raw_obj(&rss_obj->raw, cl_id, cid, func_id, rdata,
  3397. rdata_mapping, state, pstate, type);
  3398. rss_obj->engine_id = engine_id;
  3399. rss_obj->config_rss = bnx2x_setup_rss;
  3400. }
  3401. /********************** Queue state object ***********************************/
  3402. /**
  3403. * bnx2x_queue_state_change - perform Queue state change transition
  3404. *
  3405. * @bp: device handle
  3406. * @params: parameters to perform the transition
  3407. *
  3408. * returns 0 in case of successfully completed transition, negative error
  3409. * code in case of failure, positive (EBUSY) value if there is a completion
  3410. * to that is still pending (possible only if RAMROD_COMP_WAIT is
  3411. * not set in params->ramrod_flags for asynchronous commands).
  3412. *
  3413. */
  3414. int bnx2x_queue_state_change(struct bnx2x *bp,
  3415. struct bnx2x_queue_state_params *params)
  3416. {
  3417. struct bnx2x_queue_sp_obj *o = params->q_obj;
  3418. int rc, pending_bit;
  3419. unsigned long *pending = &o->pending;
  3420. /* Check that the requested transition is legal */
  3421. if (o->check_transition(bp, o, params))
  3422. return -EINVAL;
  3423. /* Set "pending" bit */
  3424. pending_bit = o->set_pending(o, params);
  3425. /* Don't send a command if only driver cleanup was requested */
  3426. if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags))
  3427. o->complete_cmd(bp, o, pending_bit);
  3428. else {
  3429. /* Send a ramrod */
  3430. rc = o->send_cmd(bp, params);
  3431. if (rc) {
  3432. o->next_state = BNX2X_Q_STATE_MAX;
  3433. clear_bit(pending_bit, pending);
  3434. smp_mb__after_clear_bit();
  3435. return rc;
  3436. }
  3437. if (test_bit(RAMROD_COMP_WAIT, &params->ramrod_flags)) {
  3438. rc = o->wait_comp(bp, o, pending_bit);
  3439. if (rc)
  3440. return rc;
  3441. return 0;
  3442. }
  3443. }
  3444. return !!test_bit(pending_bit, pending);
  3445. }
  3446. static int bnx2x_queue_set_pending(struct bnx2x_queue_sp_obj *obj,
  3447. struct bnx2x_queue_state_params *params)
  3448. {
  3449. enum bnx2x_queue_cmd cmd = params->cmd, bit;
  3450. /* ACTIVATE and DEACTIVATE commands are implemented on top of
  3451. * UPDATE command.
  3452. */
  3453. if ((cmd == BNX2X_Q_CMD_ACTIVATE) ||
  3454. (cmd == BNX2X_Q_CMD_DEACTIVATE))
  3455. bit = BNX2X_Q_CMD_UPDATE;
  3456. else
  3457. bit = cmd;
  3458. set_bit(bit, &obj->pending);
  3459. return bit;
  3460. }
  3461. static int bnx2x_queue_wait_comp(struct bnx2x *bp,
  3462. struct bnx2x_queue_sp_obj *o,
  3463. enum bnx2x_queue_cmd cmd)
  3464. {
  3465. return bnx2x_state_wait(bp, cmd, &o->pending);
  3466. }
  3467. /**
  3468. * bnx2x_queue_comp_cmd - complete the state change command.
  3469. *
  3470. * @bp: device handle
  3471. * @o:
  3472. * @cmd:
  3473. *
  3474. * Checks that the arrived completion is expected.
  3475. */
  3476. static int bnx2x_queue_comp_cmd(struct bnx2x *bp,
  3477. struct bnx2x_queue_sp_obj *o,
  3478. enum bnx2x_queue_cmd cmd)
  3479. {
  3480. unsigned long cur_pending = o->pending;
  3481. if (!test_and_clear_bit(cmd, &cur_pending)) {
  3482. BNX2X_ERR("Bad MC reply %d for queue %d in state %d "
  3483. "pending 0x%lx, next_state %d\n", cmd, o->cid,
  3484. o->state, cur_pending, o->next_state);
  3485. return -EINVAL;
  3486. }
  3487. DP(BNX2X_MSG_SP, "Completing command %d for queue %d, "
  3488. "setting state to %d\n", cmd, o->cid, o->next_state);
  3489. o->state = o->next_state;
  3490. o->next_state = BNX2X_Q_STATE_MAX;
  3491. /* It's important that o->state and o->next_state are
  3492. * updated before o->pending.
  3493. */
  3494. wmb();
  3495. clear_bit(cmd, &o->pending);
  3496. smp_mb__after_clear_bit();
  3497. return 0;
  3498. }
  3499. static void bnx2x_q_fill_setup_data_e2(struct bnx2x *bp,
  3500. struct bnx2x_queue_state_params *cmd_params,
  3501. struct client_init_ramrod_data *data)
  3502. {
  3503. struct bnx2x_queue_setup_params *params = &cmd_params->params.setup;
  3504. /* Rx data */
  3505. /* IPv6 TPA supported for E2 and above only */
  3506. data->rx.tpa_en |= test_bit(BNX2X_Q_FLG_TPA, &params->flags) *
  3507. CLIENT_INIT_RX_DATA_TPA_EN_IPV6;
  3508. }
  3509. static void bnx2x_q_fill_setup_data_cmn(struct bnx2x *bp,
  3510. struct bnx2x_queue_state_params *cmd_params,
  3511. struct client_init_ramrod_data *data)
  3512. {
  3513. struct bnx2x_queue_sp_obj *o = cmd_params->q_obj;
  3514. struct bnx2x_queue_setup_params *params = &cmd_params->params.setup;
  3515. /* general */
  3516. data->general.client_id = o->cl_id;
  3517. if (test_bit(BNX2X_Q_FLG_STATS, &params->flags)) {
  3518. data->general.statistics_counter_id =
  3519. params->gen_params.stat_id;
  3520. data->general.statistics_en_flg = 1;
  3521. data->general.statistics_zero_flg =
  3522. test_bit(BNX2X_Q_FLG_ZERO_STATS, &params->flags);
  3523. } else
  3524. data->general.statistics_counter_id =
  3525. DISABLE_STATISTIC_COUNTER_ID_VALUE;
  3526. data->general.is_fcoe_flg = test_bit(BNX2X_Q_FLG_FCOE, &params->flags);
  3527. data->general.activate_flg = test_bit(BNX2X_Q_FLG_ACTIVE,
  3528. &params->flags);
  3529. data->general.sp_client_id = params->gen_params.spcl_id;
  3530. data->general.mtu = cpu_to_le16(params->gen_params.mtu);
  3531. data->general.func_id = o->func_id;
  3532. data->general.cos = params->txq_params.cos;
  3533. data->general.traffic_type =
  3534. test_bit(BNX2X_Q_FLG_FCOE, &params->flags) ?
  3535. LLFC_TRAFFIC_TYPE_FCOE : LLFC_TRAFFIC_TYPE_NW;
  3536. /* Rx data */
  3537. data->rx.tpa_en = test_bit(BNX2X_Q_FLG_TPA, &params->flags) *
  3538. CLIENT_INIT_RX_DATA_TPA_EN_IPV4;
  3539. data->rx.vmqueue_mode_en_flg = 0;
  3540. data->rx.cache_line_alignment_log_size =
  3541. params->rxq_params.cache_line_log;
  3542. data->rx.enable_dynamic_hc =
  3543. test_bit(BNX2X_Q_FLG_DHC, &params->flags);
  3544. data->rx.max_sges_for_packet = params->rxq_params.max_sges_pkt;
  3545. data->rx.client_qzone_id = params->rxq_params.cl_qzone_id;
  3546. data->rx.max_agg_size = cpu_to_le16(params->rxq_params.tpa_agg_sz);
  3547. /* Always start in DROP_ALL mode */
  3548. data->rx.state = cpu_to_le16(CLIENT_INIT_RX_DATA_UCAST_DROP_ALL |
  3549. CLIENT_INIT_RX_DATA_MCAST_DROP_ALL);
  3550. /* We don't set drop flags */
  3551. data->rx.drop_ip_cs_err_flg = 0;
  3552. data->rx.drop_tcp_cs_err_flg = 0;
  3553. data->rx.drop_ttl0_flg = 0;
  3554. data->rx.drop_udp_cs_err_flg = 0;
  3555. data->rx.inner_vlan_removal_enable_flg =
  3556. test_bit(BNX2X_Q_FLG_VLAN, &params->flags);
  3557. data->rx.outer_vlan_removal_enable_flg =
  3558. test_bit(BNX2X_Q_FLG_OV, &params->flags);
  3559. data->rx.status_block_id = params->rxq_params.fw_sb_id;
  3560. data->rx.rx_sb_index_number = params->rxq_params.sb_cq_index;
  3561. data->rx.max_tpa_queues = params->rxq_params.max_tpa_queues;
  3562. data->rx.max_bytes_on_bd = cpu_to_le16(params->rxq_params.buf_sz);
  3563. data->rx.sge_buff_size = cpu_to_le16(params->rxq_params.sge_buf_sz);
  3564. data->rx.bd_page_base.lo =
  3565. cpu_to_le32(U64_LO(params->rxq_params.dscr_map));
  3566. data->rx.bd_page_base.hi =
  3567. cpu_to_le32(U64_HI(params->rxq_params.dscr_map));
  3568. data->rx.sge_page_base.lo =
  3569. cpu_to_le32(U64_LO(params->rxq_params.sge_map));
  3570. data->rx.sge_page_base.hi =
  3571. cpu_to_le32(U64_HI(params->rxq_params.sge_map));
  3572. data->rx.cqe_page_base.lo =
  3573. cpu_to_le32(U64_LO(params->rxq_params.rcq_map));
  3574. data->rx.cqe_page_base.hi =
  3575. cpu_to_le32(U64_HI(params->rxq_params.rcq_map));
  3576. data->rx.is_leading_rss = test_bit(BNX2X_Q_FLG_LEADING_RSS,
  3577. &params->flags);
  3578. if (test_bit(BNX2X_Q_FLG_MCAST, &params->flags)) {
  3579. data->rx.approx_mcast_engine_id = o->func_id;
  3580. data->rx.is_approx_mcast = 1;
  3581. }
  3582. data->rx.rss_engine_id = params->rxq_params.rss_engine_id;
  3583. /* flow control data */
  3584. data->rx.cqe_pause_thr_low = cpu_to_le16(params->pause.rcq_th_lo);
  3585. data->rx.cqe_pause_thr_high = cpu_to_le16(params->pause.rcq_th_hi);
  3586. data->rx.bd_pause_thr_low = cpu_to_le16(params->pause.bd_th_lo);
  3587. data->rx.bd_pause_thr_high = cpu_to_le16(params->pause.bd_th_hi);
  3588. data->rx.sge_pause_thr_low = cpu_to_le16(params->pause.sge_th_lo);
  3589. data->rx.sge_pause_thr_high = cpu_to_le16(params->pause.sge_th_hi);
  3590. data->rx.rx_cos_mask = cpu_to_le16(params->pause.pri_map);
  3591. /* silent vlan removal */
  3592. data->rx.silent_vlan_removal_flg =
  3593. test_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &params->flags);
  3594. data->rx.silent_vlan_value =
  3595. cpu_to_le16(params->rxq_params.silent_removal_value);
  3596. data->rx.silent_vlan_mask =
  3597. cpu_to_le16(params->rxq_params.silent_removal_mask);
  3598. /* Tx data */
  3599. data->tx.enforce_security_flg =
  3600. test_bit(BNX2X_Q_FLG_TX_SEC, &params->flags);
  3601. data->tx.default_vlan =
  3602. cpu_to_le16(params->txq_params.default_vlan);
  3603. data->tx.default_vlan_flg =
  3604. test_bit(BNX2X_Q_FLG_DEF_VLAN, &params->flags);
  3605. data->tx.tx_switching_flg =
  3606. test_bit(BNX2X_Q_FLG_TX_SWITCH, &params->flags);
  3607. data->tx.anti_spoofing_flg =
  3608. test_bit(BNX2X_Q_FLG_ANTI_SPOOF, &params->flags);
  3609. data->tx.tx_status_block_id = params->txq_params.fw_sb_id;
  3610. data->tx.tx_sb_index_number = params->txq_params.sb_cq_index;
  3611. data->tx.tss_leading_client_id = params->txq_params.tss_leading_cl_id;
  3612. data->tx.tx_bd_page_base.lo =
  3613. cpu_to_le32(U64_LO(params->txq_params.dscr_map));
  3614. data->tx.tx_bd_page_base.hi =
  3615. cpu_to_le32(U64_HI(params->txq_params.dscr_map));
  3616. /* Don't configure any Tx switching mode during queue SETUP */
  3617. data->tx.state = 0;
  3618. }
  3619. /**
  3620. * bnx2x_q_init - init HW/FW queue
  3621. *
  3622. * @bp: device handle
  3623. * @params:
  3624. *
  3625. * HW/FW initial Queue configuration:
  3626. * - HC: Rx and Tx
  3627. * - CDU context validation
  3628. *
  3629. */
  3630. static inline int bnx2x_q_init(struct bnx2x *bp,
  3631. struct bnx2x_queue_state_params *params)
  3632. {
  3633. struct bnx2x_queue_sp_obj *o = params->q_obj;
  3634. struct bnx2x_queue_init_params *init = &params->params.init;
  3635. u16 hc_usec;
  3636. /* Tx HC configuration */
  3637. if (test_bit(BNX2X_Q_TYPE_HAS_TX, &o->type) &&
  3638. test_bit(BNX2X_Q_FLG_HC, &init->tx.flags)) {
  3639. hc_usec = init->tx.hc_rate ? 1000000 / init->tx.hc_rate : 0;
  3640. bnx2x_update_coalesce_sb_index(bp, init->tx.fw_sb_id,
  3641. init->tx.sb_cq_index,
  3642. !test_bit(BNX2X_Q_FLG_HC_EN, &init->tx.flags),
  3643. hc_usec);
  3644. }
  3645. /* Rx HC configuration */
  3646. if (test_bit(BNX2X_Q_TYPE_HAS_RX, &o->type) &&
  3647. test_bit(BNX2X_Q_FLG_HC, &init->rx.flags)) {
  3648. hc_usec = init->rx.hc_rate ? 1000000 / init->rx.hc_rate : 0;
  3649. bnx2x_update_coalesce_sb_index(bp, init->rx.fw_sb_id,
  3650. init->rx.sb_cq_index,
  3651. !test_bit(BNX2X_Q_FLG_HC_EN, &init->rx.flags),
  3652. hc_usec);
  3653. }
  3654. /* Set CDU context validation values */
  3655. bnx2x_set_ctx_validation(bp, init->cxt, o->cid);
  3656. /* As no ramrod is sent, complete the command immediately */
  3657. o->complete_cmd(bp, o, BNX2X_Q_CMD_INIT);
  3658. mmiowb();
  3659. smp_mb();
  3660. return 0;
  3661. }
  3662. static inline int bnx2x_q_send_setup_e1x(struct bnx2x *bp,
  3663. struct bnx2x_queue_state_params *params)
  3664. {
  3665. struct bnx2x_queue_sp_obj *o = params->q_obj;
  3666. struct client_init_ramrod_data *rdata =
  3667. (struct client_init_ramrod_data *)o->rdata;
  3668. dma_addr_t data_mapping = o->rdata_mapping;
  3669. int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
  3670. /* Clear the ramrod data */
  3671. memset(rdata, 0, sizeof(*rdata));
  3672. /* Fill the ramrod data */
  3673. bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
  3674. mb();
  3675. return bnx2x_sp_post(bp, ramrod, o->cid, U64_HI(data_mapping),
  3676. U64_LO(data_mapping), ETH_CONNECTION_TYPE);
  3677. }
  3678. static inline int bnx2x_q_send_setup_e2(struct bnx2x *bp,
  3679. struct bnx2x_queue_state_params *params)
  3680. {
  3681. struct bnx2x_queue_sp_obj *o = params->q_obj;
  3682. struct client_init_ramrod_data *rdata =
  3683. (struct client_init_ramrod_data *)o->rdata;
  3684. dma_addr_t data_mapping = o->rdata_mapping;
  3685. int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
  3686. /* Clear the ramrod data */
  3687. memset(rdata, 0, sizeof(*rdata));
  3688. /* Fill the ramrod data */
  3689. bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
  3690. bnx2x_q_fill_setup_data_e2(bp, params, rdata);
  3691. mb();
  3692. return bnx2x_sp_post(bp, ramrod, o->cid, U64_HI(data_mapping),
  3693. U64_LO(data_mapping), ETH_CONNECTION_TYPE);
  3694. }
  3695. static void bnx2x_q_fill_update_data(struct bnx2x *bp,
  3696. struct bnx2x_queue_sp_obj *obj,
  3697. struct bnx2x_queue_update_params *params,
  3698. struct client_update_ramrod_data *data)
  3699. {
  3700. /* Client ID of the client to update */
  3701. data->client_id = obj->cl_id;
  3702. /* Function ID of the client to update */
  3703. data->func_id = obj->func_id;
  3704. /* Default VLAN value */
  3705. data->default_vlan = cpu_to_le16(params->def_vlan);
  3706. /* Inner VLAN stripping */
  3707. data->inner_vlan_removal_enable_flg =
  3708. test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM, &params->update_flags);
  3709. data->inner_vlan_removal_change_flg =
  3710. test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM_CHNG,
  3711. &params->update_flags);
  3712. /* Outer VLAN sripping */
  3713. data->outer_vlan_removal_enable_flg =
  3714. test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM, &params->update_flags);
  3715. data->outer_vlan_removal_change_flg =
  3716. test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM_CHNG,
  3717. &params->update_flags);
  3718. /* Drop packets that have source MAC that doesn't belong to this
  3719. * Queue.
  3720. */
  3721. data->anti_spoofing_enable_flg =
  3722. test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF, &params->update_flags);
  3723. data->anti_spoofing_change_flg =
  3724. test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF_CHNG, &params->update_flags);
  3725. /* Activate/Deactivate */
  3726. data->activate_flg =
  3727. test_bit(BNX2X_Q_UPDATE_ACTIVATE, &params->update_flags);
  3728. data->activate_change_flg =
  3729. test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &params->update_flags);
  3730. /* Enable default VLAN */
  3731. data->default_vlan_enable_flg =
  3732. test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN, &params->update_flags);
  3733. data->default_vlan_change_flg =
  3734. test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN_CHNG,
  3735. &params->update_flags);
  3736. /* silent vlan removal */
  3737. data->silent_vlan_change_flg =
  3738. test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  3739. &params->update_flags);
  3740. data->silent_vlan_removal_flg =
  3741. test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM, &params->update_flags);
  3742. data->silent_vlan_value = cpu_to_le16(params->silent_removal_value);
  3743. data->silent_vlan_mask = cpu_to_le16(params->silent_removal_mask);
  3744. }
  3745. static inline int bnx2x_q_send_update(struct bnx2x *bp,
  3746. struct bnx2x_queue_state_params *params)
  3747. {
  3748. struct bnx2x_queue_sp_obj *o = params->q_obj;
  3749. struct client_update_ramrod_data *rdata =
  3750. (struct client_update_ramrod_data *)o->rdata;
  3751. dma_addr_t data_mapping = o->rdata_mapping;
  3752. /* Clear the ramrod data */
  3753. memset(rdata, 0, sizeof(*rdata));
  3754. /* Fill the ramrod data */
  3755. bnx2x_q_fill_update_data(bp, o, &params->params.update, rdata);
  3756. mb();
  3757. return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_UPDATE, o->cid,
  3758. U64_HI(data_mapping),
  3759. U64_LO(data_mapping), ETH_CONNECTION_TYPE);
  3760. }
  3761. /**
  3762. * bnx2x_q_send_deactivate - send DEACTIVATE command
  3763. *
  3764. * @bp: device handle
  3765. * @params:
  3766. *
  3767. * implemented using the UPDATE command.
  3768. */
  3769. static inline int bnx2x_q_send_deactivate(struct bnx2x *bp,
  3770. struct bnx2x_queue_state_params *params)
  3771. {
  3772. struct bnx2x_queue_update_params *update = &params->params.update;
  3773. memset(update, 0, sizeof(*update));
  3774. __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &update->update_flags);
  3775. return bnx2x_q_send_update(bp, params);
  3776. }
  3777. /**
  3778. * bnx2x_q_send_activate - send ACTIVATE command
  3779. *
  3780. * @bp: device handle
  3781. * @params:
  3782. *
  3783. * implemented using the UPDATE command.
  3784. */
  3785. static inline int bnx2x_q_send_activate(struct bnx2x *bp,
  3786. struct bnx2x_queue_state_params *params)
  3787. {
  3788. struct bnx2x_queue_update_params *update = &params->params.update;
  3789. memset(update, 0, sizeof(*update));
  3790. __set_bit(BNX2X_Q_UPDATE_ACTIVATE, &update->update_flags);
  3791. __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &update->update_flags);
  3792. return bnx2x_q_send_update(bp, params);
  3793. }
  3794. static inline int bnx2x_q_send_update_tpa(struct bnx2x *bp,
  3795. struct bnx2x_queue_state_params *params)
  3796. {
  3797. /* TODO: Not implemented yet. */
  3798. return -1;
  3799. }
  3800. static inline int bnx2x_q_send_halt(struct bnx2x *bp,
  3801. struct bnx2x_queue_state_params *params)
  3802. {
  3803. struct bnx2x_queue_sp_obj *o = params->q_obj;
  3804. return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, o->cid, 0, o->cl_id,
  3805. ETH_CONNECTION_TYPE);
  3806. }
  3807. static inline int bnx2x_q_send_cfc_del(struct bnx2x *bp,
  3808. struct bnx2x_queue_state_params *params)
  3809. {
  3810. struct bnx2x_queue_sp_obj *o = params->q_obj;
  3811. return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_CFC_DEL, o->cid, 0, 0,
  3812. NONE_CONNECTION_TYPE);
  3813. }
  3814. static inline int bnx2x_q_send_terminate(struct bnx2x *bp,
  3815. struct bnx2x_queue_state_params *params)
  3816. {
  3817. struct bnx2x_queue_sp_obj *o = params->q_obj;
  3818. return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_TERMINATE, o->cid, 0, 0,
  3819. ETH_CONNECTION_TYPE);
  3820. }
  3821. static inline int bnx2x_q_send_empty(struct bnx2x *bp,
  3822. struct bnx2x_queue_state_params *params)
  3823. {
  3824. struct bnx2x_queue_sp_obj *o = params->q_obj;
  3825. return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_EMPTY, o->cid, 0, 0,
  3826. ETH_CONNECTION_TYPE);
  3827. }
  3828. static inline int bnx2x_queue_send_cmd_cmn(struct bnx2x *bp,
  3829. struct bnx2x_queue_state_params *params)
  3830. {
  3831. switch (params->cmd) {
  3832. case BNX2X_Q_CMD_INIT:
  3833. return bnx2x_q_init(bp, params);
  3834. case BNX2X_Q_CMD_DEACTIVATE:
  3835. return bnx2x_q_send_deactivate(bp, params);
  3836. case BNX2X_Q_CMD_ACTIVATE:
  3837. return bnx2x_q_send_activate(bp, params);
  3838. case BNX2X_Q_CMD_UPDATE:
  3839. return bnx2x_q_send_update(bp, params);
  3840. case BNX2X_Q_CMD_UPDATE_TPA:
  3841. return bnx2x_q_send_update_tpa(bp, params);
  3842. case BNX2X_Q_CMD_HALT:
  3843. return bnx2x_q_send_halt(bp, params);
  3844. case BNX2X_Q_CMD_CFC_DEL:
  3845. return bnx2x_q_send_cfc_del(bp, params);
  3846. case BNX2X_Q_CMD_TERMINATE:
  3847. return bnx2x_q_send_terminate(bp, params);
  3848. case BNX2X_Q_CMD_EMPTY:
  3849. return bnx2x_q_send_empty(bp, params);
  3850. default:
  3851. BNX2X_ERR("Unknown command: %d\n", params->cmd);
  3852. return -EINVAL;
  3853. }
  3854. }
  3855. static int bnx2x_queue_send_cmd_e1x(struct bnx2x *bp,
  3856. struct bnx2x_queue_state_params *params)
  3857. {
  3858. switch (params->cmd) {
  3859. case BNX2X_Q_CMD_SETUP:
  3860. return bnx2x_q_send_setup_e1x(bp, params);
  3861. case BNX2X_Q_CMD_INIT:
  3862. case BNX2X_Q_CMD_DEACTIVATE:
  3863. case BNX2X_Q_CMD_ACTIVATE:
  3864. case BNX2X_Q_CMD_UPDATE:
  3865. case BNX2X_Q_CMD_UPDATE_TPA:
  3866. case BNX2X_Q_CMD_HALT:
  3867. case BNX2X_Q_CMD_CFC_DEL:
  3868. case BNX2X_Q_CMD_TERMINATE:
  3869. case BNX2X_Q_CMD_EMPTY:
  3870. return bnx2x_queue_send_cmd_cmn(bp, params);
  3871. default:
  3872. BNX2X_ERR("Unknown command: %d\n", params->cmd);
  3873. return -EINVAL;
  3874. }
  3875. }
  3876. static int bnx2x_queue_send_cmd_e2(struct bnx2x *bp,
  3877. struct bnx2x_queue_state_params *params)
  3878. {
  3879. switch (params->cmd) {
  3880. case BNX2X_Q_CMD_SETUP:
  3881. return bnx2x_q_send_setup_e2(bp, params);
  3882. case BNX2X_Q_CMD_INIT:
  3883. case BNX2X_Q_CMD_DEACTIVATE:
  3884. case BNX2X_Q_CMD_ACTIVATE:
  3885. case BNX2X_Q_CMD_UPDATE:
  3886. case BNX2X_Q_CMD_UPDATE_TPA:
  3887. case BNX2X_Q_CMD_HALT:
  3888. case BNX2X_Q_CMD_CFC_DEL:
  3889. case BNX2X_Q_CMD_TERMINATE:
  3890. case BNX2X_Q_CMD_EMPTY:
  3891. return bnx2x_queue_send_cmd_cmn(bp, params);
  3892. default:
  3893. BNX2X_ERR("Unknown command: %d\n", params->cmd);
  3894. return -EINVAL;
  3895. }
  3896. }
  3897. /**
  3898. * bnx2x_queue_chk_transition - check state machine of a regular Queue
  3899. *
  3900. * @bp: device handle
  3901. * @o:
  3902. * @params:
  3903. *
  3904. * (not Forwarding)
  3905. * It both checks if the requested command is legal in a current
  3906. * state and, if it's legal, sets a `next_state' in the object
  3907. * that will be used in the completion flow to set the `state'
  3908. * of the object.
  3909. *
  3910. * returns 0 if a requested command is a legal transition,
  3911. * -EINVAL otherwise.
  3912. */
  3913. static int bnx2x_queue_chk_transition(struct bnx2x *bp,
  3914. struct bnx2x_queue_sp_obj *o,
  3915. struct bnx2x_queue_state_params *params)
  3916. {
  3917. enum bnx2x_q_state state = o->state, next_state = BNX2X_Q_STATE_MAX;
  3918. enum bnx2x_queue_cmd cmd = params->cmd;
  3919. switch (state) {
  3920. case BNX2X_Q_STATE_RESET:
  3921. if (cmd == BNX2X_Q_CMD_INIT)
  3922. next_state = BNX2X_Q_STATE_INITIALIZED;
  3923. break;
  3924. case BNX2X_Q_STATE_INITIALIZED:
  3925. if (cmd == BNX2X_Q_CMD_SETUP) {
  3926. if (test_bit(BNX2X_Q_FLG_ACTIVE,
  3927. &params->params.setup.flags))
  3928. next_state = BNX2X_Q_STATE_ACTIVE;
  3929. else
  3930. next_state = BNX2X_Q_STATE_INACTIVE;
  3931. }
  3932. break;
  3933. case BNX2X_Q_STATE_ACTIVE:
  3934. if (cmd == BNX2X_Q_CMD_DEACTIVATE)
  3935. next_state = BNX2X_Q_STATE_INACTIVE;
  3936. else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
  3937. (cmd == BNX2X_Q_CMD_UPDATE_TPA))
  3938. next_state = BNX2X_Q_STATE_ACTIVE;
  3939. else if (cmd == BNX2X_Q_CMD_HALT)
  3940. next_state = BNX2X_Q_STATE_STOPPED;
  3941. else if (cmd == BNX2X_Q_CMD_UPDATE) {
  3942. struct bnx2x_queue_update_params *update_params =
  3943. &params->params.update;
  3944. /* If "active" state change is requested, update the
  3945. * state accordingly.
  3946. */
  3947. if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
  3948. &update_params->update_flags) &&
  3949. !test_bit(BNX2X_Q_UPDATE_ACTIVATE,
  3950. &update_params->update_flags))
  3951. next_state = BNX2X_Q_STATE_INACTIVE;
  3952. else
  3953. next_state = BNX2X_Q_STATE_ACTIVE;
  3954. }
  3955. break;
  3956. case BNX2X_Q_STATE_INACTIVE:
  3957. if (cmd == BNX2X_Q_CMD_ACTIVATE)
  3958. next_state = BNX2X_Q_STATE_ACTIVE;
  3959. else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
  3960. (cmd == BNX2X_Q_CMD_UPDATE_TPA))
  3961. next_state = BNX2X_Q_STATE_INACTIVE;
  3962. else if (cmd == BNX2X_Q_CMD_HALT)
  3963. next_state = BNX2X_Q_STATE_STOPPED;
  3964. else if (cmd == BNX2X_Q_CMD_UPDATE) {
  3965. struct bnx2x_queue_update_params *update_params =
  3966. &params->params.update;
  3967. /* If "active" state change is requested, update the
  3968. * state accordingly.
  3969. */
  3970. if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
  3971. &update_params->update_flags) &&
  3972. test_bit(BNX2X_Q_UPDATE_ACTIVATE,
  3973. &update_params->update_flags))
  3974. next_state = BNX2X_Q_STATE_ACTIVE;
  3975. else
  3976. next_state = BNX2X_Q_STATE_INACTIVE;
  3977. }
  3978. break;
  3979. case BNX2X_Q_STATE_STOPPED:
  3980. if (cmd == BNX2X_Q_CMD_TERMINATE)
  3981. next_state = BNX2X_Q_STATE_TERMINATED;
  3982. break;
  3983. case BNX2X_Q_STATE_TERMINATED:
  3984. if (cmd == BNX2X_Q_CMD_CFC_DEL)
  3985. next_state = BNX2X_Q_STATE_RESET;
  3986. break;
  3987. default:
  3988. BNX2X_ERR("Illegal state: %d\n", state);
  3989. }
  3990. /* Transition is assured */
  3991. if (next_state != BNX2X_Q_STATE_MAX) {
  3992. DP(BNX2X_MSG_SP, "Good state transition: %d(%d)->%d\n",
  3993. state, cmd, next_state);
  3994. o->next_state = next_state;
  3995. return 0;
  3996. }
  3997. DP(BNX2X_MSG_SP, "Bad state transition request: %d %d\n", state, cmd);
  3998. return -EINVAL;
  3999. }
  4000. void bnx2x_init_queue_obj(struct bnx2x *bp,
  4001. struct bnx2x_queue_sp_obj *obj,
  4002. u8 cl_id, u32 cid, u8 func_id, void *rdata,
  4003. dma_addr_t rdata_mapping, unsigned long type)
  4004. {
  4005. memset(obj, 0, sizeof(*obj));
  4006. obj->cid = cid;
  4007. obj->cl_id = cl_id;
  4008. obj->func_id = func_id;
  4009. obj->rdata = rdata;
  4010. obj->rdata_mapping = rdata_mapping;
  4011. obj->type = type;
  4012. obj->next_state = BNX2X_Q_STATE_MAX;
  4013. if (CHIP_IS_E1x(bp))
  4014. obj->send_cmd = bnx2x_queue_send_cmd_e1x;
  4015. else
  4016. obj->send_cmd = bnx2x_queue_send_cmd_e2;
  4017. obj->check_transition = bnx2x_queue_chk_transition;
  4018. obj->complete_cmd = bnx2x_queue_comp_cmd;
  4019. obj->wait_comp = bnx2x_queue_wait_comp;
  4020. obj->set_pending = bnx2x_queue_set_pending;
  4021. }
  4022. /********************** Function state object *********************************/
  4023. static int bnx2x_func_wait_comp(struct bnx2x *bp,
  4024. struct bnx2x_func_sp_obj *o,
  4025. enum bnx2x_func_cmd cmd)
  4026. {
  4027. return bnx2x_state_wait(bp, cmd, &o->pending);
  4028. }
  4029. /**
  4030. * bnx2x_func_state_change_comp - complete the state machine transition
  4031. *
  4032. * @bp: device handle
  4033. * @o:
  4034. * @cmd:
  4035. *
  4036. * Called on state change transition. Completes the state
  4037. * machine transition only - no HW interaction.
  4038. */
  4039. static inline int bnx2x_func_state_change_comp(struct bnx2x *bp,
  4040. struct bnx2x_func_sp_obj *o,
  4041. enum bnx2x_func_cmd cmd)
  4042. {
  4043. unsigned long cur_pending = o->pending;
  4044. if (!test_and_clear_bit(cmd, &cur_pending)) {
  4045. BNX2X_ERR("Bad MC reply %d for func %d in state %d "
  4046. "pending 0x%lx, next_state %d\n", cmd, BP_FUNC(bp),
  4047. o->state, cur_pending, o->next_state);
  4048. return -EINVAL;
  4049. }
  4050. DP(BNX2X_MSG_SP, "Completing command %d for func %d, setting state to "
  4051. "%d\n", cmd, BP_FUNC(bp), o->next_state);
  4052. o->state = o->next_state;
  4053. o->next_state = BNX2X_F_STATE_MAX;
  4054. /* It's important that o->state and o->next_state are
  4055. * updated before o->pending.
  4056. */
  4057. wmb();
  4058. clear_bit(cmd, &o->pending);
  4059. smp_mb__after_clear_bit();
  4060. return 0;
  4061. }
  4062. /**
  4063. * bnx2x_func_comp_cmd - complete the state change command
  4064. *
  4065. * @bp: device handle
  4066. * @o:
  4067. * @cmd:
  4068. *
  4069. * Checks that the arrived completion is expected.
  4070. */
  4071. static int bnx2x_func_comp_cmd(struct bnx2x *bp,
  4072. struct bnx2x_func_sp_obj *o,
  4073. enum bnx2x_func_cmd cmd)
  4074. {
  4075. /* Complete the state machine part first, check if it's a
  4076. * legal completion.
  4077. */
  4078. int rc = bnx2x_func_state_change_comp(bp, o, cmd);
  4079. return rc;
  4080. }
  4081. /**
  4082. * bnx2x_func_chk_transition - perform function state machine transition
  4083. *
  4084. * @bp: device handle
  4085. * @o:
  4086. * @params:
  4087. *
  4088. * It both checks if the requested command is legal in a current
  4089. * state and, if it's legal, sets a `next_state' in the object
  4090. * that will be used in the completion flow to set the `state'
  4091. * of the object.
  4092. *
  4093. * returns 0 if a requested command is a legal transition,
  4094. * -EINVAL otherwise.
  4095. */
  4096. static int bnx2x_func_chk_transition(struct bnx2x *bp,
  4097. struct bnx2x_func_sp_obj *o,
  4098. struct bnx2x_func_state_params *params)
  4099. {
  4100. enum bnx2x_func_state state = o->state, next_state = BNX2X_F_STATE_MAX;
  4101. enum bnx2x_func_cmd cmd = params->cmd;
  4102. switch (state) {
  4103. case BNX2X_F_STATE_RESET:
  4104. if (cmd == BNX2X_F_CMD_HW_INIT)
  4105. next_state = BNX2X_F_STATE_INITIALIZED;
  4106. break;
  4107. case BNX2X_F_STATE_INITIALIZED:
  4108. if (cmd == BNX2X_F_CMD_START)
  4109. next_state = BNX2X_F_STATE_STARTED;
  4110. else if (cmd == BNX2X_F_CMD_HW_RESET)
  4111. next_state = BNX2X_F_STATE_RESET;
  4112. break;
  4113. case BNX2X_F_STATE_STARTED:
  4114. if (cmd == BNX2X_F_CMD_STOP)
  4115. next_state = BNX2X_F_STATE_INITIALIZED;
  4116. break;
  4117. default:
  4118. BNX2X_ERR("Unknown state: %d\n", state);
  4119. }
  4120. /* Transition is assured */
  4121. if (next_state != BNX2X_F_STATE_MAX) {
  4122. DP(BNX2X_MSG_SP, "Good function state transition: %d(%d)->%d\n",
  4123. state, cmd, next_state);
  4124. o->next_state = next_state;
  4125. return 0;
  4126. }
  4127. DP(BNX2X_MSG_SP, "Bad function state transition request: %d %d\n",
  4128. state, cmd);
  4129. return -EINVAL;
  4130. }
  4131. /**
  4132. * bnx2x_func_init_func - performs HW init at function stage
  4133. *
  4134. * @bp: device handle
  4135. * @drv:
  4136. *
  4137. * Init HW when the current phase is
  4138. * FW_MSG_CODE_DRV_LOAD_FUNCTION: initialize only FUNCTION-only
  4139. * HW blocks.
  4140. */
  4141. static inline int bnx2x_func_init_func(struct bnx2x *bp,
  4142. const struct bnx2x_func_sp_drv_ops *drv)
  4143. {
  4144. return drv->init_hw_func(bp);
  4145. }
  4146. /**
  4147. * bnx2x_func_init_port - performs HW init at port stage
  4148. *
  4149. * @bp: device handle
  4150. * @drv:
  4151. *
  4152. * Init HW when the current phase is
  4153. * FW_MSG_CODE_DRV_LOAD_PORT: initialize PORT-only and
  4154. * FUNCTION-only HW blocks.
  4155. *
  4156. */
  4157. static inline int bnx2x_func_init_port(struct bnx2x *bp,
  4158. const struct bnx2x_func_sp_drv_ops *drv)
  4159. {
  4160. int rc = drv->init_hw_port(bp);
  4161. if (rc)
  4162. return rc;
  4163. return bnx2x_func_init_func(bp, drv);
  4164. }
  4165. /**
  4166. * bnx2x_func_init_cmn_chip - performs HW init at chip-common stage
  4167. *
  4168. * @bp: device handle
  4169. * @drv:
  4170. *
  4171. * Init HW when the current phase is
  4172. * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON_CHIP,
  4173. * PORT-only and FUNCTION-only HW blocks.
  4174. */
  4175. static inline int bnx2x_func_init_cmn_chip(struct bnx2x *bp,
  4176. const struct bnx2x_func_sp_drv_ops *drv)
  4177. {
  4178. int rc = drv->init_hw_cmn_chip(bp);
  4179. if (rc)
  4180. return rc;
  4181. return bnx2x_func_init_port(bp, drv);
  4182. }
  4183. /**
  4184. * bnx2x_func_init_cmn - performs HW init at common stage
  4185. *
  4186. * @bp: device handle
  4187. * @drv:
  4188. *
  4189. * Init HW when the current phase is
  4190. * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON,
  4191. * PORT-only and FUNCTION-only HW blocks.
  4192. */
  4193. static inline int bnx2x_func_init_cmn(struct bnx2x *bp,
  4194. const struct bnx2x_func_sp_drv_ops *drv)
  4195. {
  4196. int rc = drv->init_hw_cmn(bp);
  4197. if (rc)
  4198. return rc;
  4199. return bnx2x_func_init_port(bp, drv);
  4200. }
  4201. static int bnx2x_func_hw_init(struct bnx2x *bp,
  4202. struct bnx2x_func_state_params *params)
  4203. {
  4204. u32 load_code = params->params.hw_init.load_phase;
  4205. struct bnx2x_func_sp_obj *o = params->f_obj;
  4206. const struct bnx2x_func_sp_drv_ops *drv = o->drv;
  4207. int rc = 0;
  4208. DP(BNX2X_MSG_SP, "function %d load_code %x\n",
  4209. BP_ABS_FUNC(bp), load_code);
  4210. /* Prepare buffers for unzipping the FW */
  4211. rc = drv->gunzip_init(bp);
  4212. if (rc)
  4213. return rc;
  4214. /* Prepare FW */
  4215. rc = drv->init_fw(bp);
  4216. if (rc) {
  4217. BNX2X_ERR("Error loading firmware\n");
  4218. goto fw_init_err;
  4219. }
  4220. /* Handle the beginning of COMMON_XXX pases separatelly... */
  4221. switch (load_code) {
  4222. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4223. rc = bnx2x_func_init_cmn_chip(bp, drv);
  4224. if (rc)
  4225. goto init_hw_err;
  4226. break;
  4227. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4228. rc = bnx2x_func_init_cmn(bp, drv);
  4229. if (rc)
  4230. goto init_hw_err;
  4231. break;
  4232. case FW_MSG_CODE_DRV_LOAD_PORT:
  4233. rc = bnx2x_func_init_port(bp, drv);
  4234. if (rc)
  4235. goto init_hw_err;
  4236. break;
  4237. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4238. rc = bnx2x_func_init_func(bp, drv);
  4239. if (rc)
  4240. goto init_hw_err;
  4241. break;
  4242. default:
  4243. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4244. rc = -EINVAL;
  4245. }
  4246. init_hw_err:
  4247. drv->release_fw(bp);
  4248. fw_init_err:
  4249. drv->gunzip_end(bp);
  4250. /* In case of success, complete the comand immediatelly: no ramrods
  4251. * have been sent.
  4252. */
  4253. if (!rc)
  4254. o->complete_cmd(bp, o, BNX2X_F_CMD_HW_INIT);
  4255. return rc;
  4256. }
  4257. /**
  4258. * bnx2x_func_reset_func - reset HW at function stage
  4259. *
  4260. * @bp: device handle
  4261. * @drv:
  4262. *
  4263. * Reset HW at FW_MSG_CODE_DRV_UNLOAD_FUNCTION stage: reset only
  4264. * FUNCTION-only HW blocks.
  4265. */
  4266. static inline void bnx2x_func_reset_func(struct bnx2x *bp,
  4267. const struct bnx2x_func_sp_drv_ops *drv)
  4268. {
  4269. drv->reset_hw_func(bp);
  4270. }
  4271. /**
  4272. * bnx2x_func_reset_port - reser HW at port stage
  4273. *
  4274. * @bp: device handle
  4275. * @drv:
  4276. *
  4277. * Reset HW at FW_MSG_CODE_DRV_UNLOAD_PORT stage: reset
  4278. * FUNCTION-only and PORT-only HW blocks.
  4279. *
  4280. * !!!IMPORTANT!!!
  4281. *
  4282. * It's important to call reset_port before reset_func() as the last thing
  4283. * reset_func does is pf_disable() thus disabling PGLUE_B, which
  4284. * makes impossible any DMAE transactions.
  4285. */
  4286. static inline void bnx2x_func_reset_port(struct bnx2x *bp,
  4287. const struct bnx2x_func_sp_drv_ops *drv)
  4288. {
  4289. drv->reset_hw_port(bp);
  4290. bnx2x_func_reset_func(bp, drv);
  4291. }
  4292. /**
  4293. * bnx2x_func_reset_cmn - reser HW at common stage
  4294. *
  4295. * @bp: device handle
  4296. * @drv:
  4297. *
  4298. * Reset HW at FW_MSG_CODE_DRV_UNLOAD_COMMON and
  4299. * FW_MSG_CODE_DRV_UNLOAD_COMMON_CHIP stages: reset COMMON,
  4300. * COMMON_CHIP, FUNCTION-only and PORT-only HW blocks.
  4301. */
  4302. static inline void bnx2x_func_reset_cmn(struct bnx2x *bp,
  4303. const struct bnx2x_func_sp_drv_ops *drv)
  4304. {
  4305. bnx2x_func_reset_port(bp, drv);
  4306. drv->reset_hw_cmn(bp);
  4307. }
  4308. static inline int bnx2x_func_hw_reset(struct bnx2x *bp,
  4309. struct bnx2x_func_state_params *params)
  4310. {
  4311. u32 reset_phase = params->params.hw_reset.reset_phase;
  4312. struct bnx2x_func_sp_obj *o = params->f_obj;
  4313. const struct bnx2x_func_sp_drv_ops *drv = o->drv;
  4314. DP(BNX2X_MSG_SP, "function %d reset_phase %x\n", BP_ABS_FUNC(bp),
  4315. reset_phase);
  4316. switch (reset_phase) {
  4317. case FW_MSG_CODE_DRV_UNLOAD_COMMON:
  4318. bnx2x_func_reset_cmn(bp, drv);
  4319. break;
  4320. case FW_MSG_CODE_DRV_UNLOAD_PORT:
  4321. bnx2x_func_reset_port(bp, drv);
  4322. break;
  4323. case FW_MSG_CODE_DRV_UNLOAD_FUNCTION:
  4324. bnx2x_func_reset_func(bp, drv);
  4325. break;
  4326. default:
  4327. BNX2X_ERR("Unknown reset_phase (0x%x) from MCP\n",
  4328. reset_phase);
  4329. break;
  4330. }
  4331. /* Complete the comand immediatelly: no ramrods have been sent. */
  4332. o->complete_cmd(bp, o, BNX2X_F_CMD_HW_RESET);
  4333. return 0;
  4334. }
  4335. static inline int bnx2x_func_send_start(struct bnx2x *bp,
  4336. struct bnx2x_func_state_params *params)
  4337. {
  4338. struct bnx2x_func_sp_obj *o = params->f_obj;
  4339. struct function_start_data *rdata =
  4340. (struct function_start_data *)o->rdata;
  4341. dma_addr_t data_mapping = o->rdata_mapping;
  4342. struct bnx2x_func_start_params *start_params = &params->params.start;
  4343. memset(rdata, 0, sizeof(*rdata));
  4344. /* Fill the ramrod data with provided parameters */
  4345. rdata->function_mode = cpu_to_le16(start_params->mf_mode);
  4346. rdata->sd_vlan_tag = start_params->sd_vlan_tag;
  4347. rdata->path_id = BP_PATH(bp);
  4348. rdata->network_cos_mode = start_params->network_cos_mode;
  4349. mb();
  4350. return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_START, 0,
  4351. U64_HI(data_mapping),
  4352. U64_LO(data_mapping), NONE_CONNECTION_TYPE);
  4353. }
  4354. static inline int bnx2x_func_send_stop(struct bnx2x *bp,
  4355. struct bnx2x_func_state_params *params)
  4356. {
  4357. return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_STOP, 0, 0, 0,
  4358. NONE_CONNECTION_TYPE);
  4359. }
  4360. static int bnx2x_func_send_cmd(struct bnx2x *bp,
  4361. struct bnx2x_func_state_params *params)
  4362. {
  4363. switch (params->cmd) {
  4364. case BNX2X_F_CMD_HW_INIT:
  4365. return bnx2x_func_hw_init(bp, params);
  4366. case BNX2X_F_CMD_START:
  4367. return bnx2x_func_send_start(bp, params);
  4368. case BNX2X_F_CMD_STOP:
  4369. return bnx2x_func_send_stop(bp, params);
  4370. case BNX2X_F_CMD_HW_RESET:
  4371. return bnx2x_func_hw_reset(bp, params);
  4372. default:
  4373. BNX2X_ERR("Unknown command: %d\n", params->cmd);
  4374. return -EINVAL;
  4375. }
  4376. }
  4377. void bnx2x_init_func_obj(struct bnx2x *bp,
  4378. struct bnx2x_func_sp_obj *obj,
  4379. void *rdata, dma_addr_t rdata_mapping,
  4380. struct bnx2x_func_sp_drv_ops *drv_iface)
  4381. {
  4382. memset(obj, 0, sizeof(*obj));
  4383. mutex_init(&obj->one_pending_mutex);
  4384. obj->rdata = rdata;
  4385. obj->rdata_mapping = rdata_mapping;
  4386. obj->send_cmd = bnx2x_func_send_cmd;
  4387. obj->check_transition = bnx2x_func_chk_transition;
  4388. obj->complete_cmd = bnx2x_func_comp_cmd;
  4389. obj->wait_comp = bnx2x_func_wait_comp;
  4390. obj->drv = drv_iface;
  4391. }
  4392. /**
  4393. * bnx2x_func_state_change - perform Function state change transition
  4394. *
  4395. * @bp: device handle
  4396. * @params: parameters to perform the transaction
  4397. *
  4398. * returns 0 in case of successfully completed transition,
  4399. * negative error code in case of failure, positive
  4400. * (EBUSY) value if there is a completion to that is
  4401. * still pending (possible only if RAMROD_COMP_WAIT is
  4402. * not set in params->ramrod_flags for asynchronous
  4403. * commands).
  4404. */
  4405. int bnx2x_func_state_change(struct bnx2x *bp,
  4406. struct bnx2x_func_state_params *params)
  4407. {
  4408. struct bnx2x_func_sp_obj *o = params->f_obj;
  4409. int rc;
  4410. enum bnx2x_func_cmd cmd = params->cmd;
  4411. unsigned long *pending = &o->pending;
  4412. mutex_lock(&o->one_pending_mutex);
  4413. /* Check that the requested transition is legal */
  4414. if (o->check_transition(bp, o, params)) {
  4415. mutex_unlock(&o->one_pending_mutex);
  4416. return -EINVAL;
  4417. }
  4418. /* Set "pending" bit */
  4419. set_bit(cmd, pending);
  4420. /* Don't send a command if only driver cleanup was requested */
  4421. if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags)) {
  4422. bnx2x_func_state_change_comp(bp, o, cmd);
  4423. mutex_unlock(&o->one_pending_mutex);
  4424. } else {
  4425. /* Send a ramrod */
  4426. rc = o->send_cmd(bp, params);
  4427. mutex_unlock(&o->one_pending_mutex);
  4428. if (rc) {
  4429. o->next_state = BNX2X_F_STATE_MAX;
  4430. clear_bit(cmd, pending);
  4431. smp_mb__after_clear_bit();
  4432. return rc;
  4433. }
  4434. if (test_bit(RAMROD_COMP_WAIT, &params->ramrod_flags)) {
  4435. rc = o->wait_comp(bp, o, cmd);
  4436. if (rc)
  4437. return rc;
  4438. return 0;
  4439. }
  4440. }
  4441. return !!test_bit(cmd, pending);
  4442. }