bnx2x_sp.c 152 KB

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